1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
use crate::{
blending::{Blending, BlendingMode},
depth_stencil::{Comparison, StencilOperations, StencilTest, Write},
face_culling::FaceCulling,
scissor::ScissorRegion,
};
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct RenderState {
blending: Option<BlendingMode>,
depth_test: Option<Comparison>,
depth_write: Write,
stencil_test: Option<StencilTest>,
stencil_operations: StencilOperations,
face_culling: Option<FaceCulling>,
scissor: Option<ScissorRegion>,
}
impl RenderState {
pub fn set_blending<B>(self, blending: B) -> Self
where
B: Into<Option<Blending>>,
{
RenderState {
blending: blending.into().map(|x| x.into()),
..self
}
}
pub fn set_blending_separate(self, blending_rgb: Blending, blending_alpha: Blending) -> Self {
RenderState {
blending: Some(BlendingMode::Separate {
rgb: blending_rgb,
alpha: blending_alpha,
}),
..self
}
}
pub fn blending(&self) -> Option<BlendingMode> {
self.blending
}
pub fn set_depth_test<D>(self, depth_test: D) -> Self
where
D: Into<Option<Comparison>>,
{
let depth_test = depth_test.into();
RenderState { depth_test, ..self }
}
pub fn depth_test(&self) -> Option<Comparison> {
self.depth_test
}
pub fn set_depth_write(self, depth_write: Write) -> Self {
RenderState {
depth_write,
..self
}
}
pub fn depth_write(&self) -> Write {
self.depth_write
}
pub fn set_stencil_test(self, stencil_test: impl Into<Option<StencilTest>>) -> Self {
let stencil_test = stencil_test.into();
RenderState {
stencil_test,
..self
}
}
pub fn stencil_test(&self) -> Option<&StencilTest> {
self.stencil_test.as_ref()
}
pub fn set_stencil_operations(self, stencil_operations: StencilOperations) -> Self {
RenderState {
stencil_operations,
..self
}
}
pub fn stencil_operations(&self) -> &StencilOperations {
&self.stencil_operations
}
pub fn set_face_culling<FC>(self, face_culling: FC) -> Self
where
FC: Into<Option<FaceCulling>>,
{
RenderState {
face_culling: face_culling.into(),
..self
}
}
pub fn face_culling(&self) -> Option<FaceCulling> {
self.face_culling
}
pub fn set_scissor<SR>(self, scissor: SR) -> Self
where
SR: Into<Option<ScissorRegion>>,
{
RenderState {
scissor: scissor.into(),
..self
}
}
pub fn scissor(&self) -> &Option<ScissorRegion> {
&self.scissor
}
}
impl Default for RenderState {
fn default() -> Self {
RenderState {
blending: None,
depth_test: Some(Comparison::Less),
depth_write: Write::On,
stencil_test: None,
stencil_operations: StencilOperations::default(),
face_culling: None,
scissor: None,
}
}
}