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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
use super::DepthTestFunction;
use std::{cell::RefCell, mem};
const DEPTH_STATE_MAGIC: u32 = 0xDEADBEEF;
#[derive(Debug, Clone, Copy)]
struct DepthStateProps {
pub magic: u32,
pub test_enabled: bool,
pub test_function: DepthTestFunction,
pub write_enabled: bool,
pub range_near: f32,
pub range_far: f32,
}
#[repr(C)]
#[derive(Debug, Clone)] // PartialEq, Eq, Hash
pub struct DepthState {
props: RefCell<DepthStateProps>,
}
impl DepthState {
// depth_state_init:
// @state: A #DepthState struct
//
// Initializes the members of @state to their default values.
//
// You should never pass an un initialized #DepthState structure
// to pipeline_set_depth_state().
//
// Since: 2.0
// Stability: Unstable
pub fn init(&self) {
let mut props = self.props.borrow_mut();
props.magic = DEPTH_STATE_MAGIC;
// The same as the GL defaults
props.test_enabled = false;
props.write_enabled = true;
props.test_function = DepthTestFunction::Less;
props.range_near = 0.0;
props.range_far = 1.0;
}
// depth_state_set_test_enabled:
// @state: A #DepthState struct
// @enable: The enable state you want
//
// Enables or disables depth testing according to the value of
// @enable.
//
// If depth testing is enable then the #DepthTestFunction set
// using depth_state_set_test_fn() us used to evaluate
// the depth value of incoming fragments against the corresponding
// value stored in the current depth buffer, and if the test passes
// then the fragments depth value is used to update the depth buffer.
// (unless you have disabled depth writing via
// depth_state_set_write_enabled())
//
// By default depth testing is disabled.
//
// NB: this won't directly affect the state of the GPU. You have
// to then set the state on a #Pipeline using
// pipeline_set_depth_state()
//
// Since: 2.0
// Stability: Unstable
pub fn set_test_enabled(&self, enable: bool) {
let mut props = self.props.borrow_mut();
props.test_enabled = enable;
}
// depth_state_get_test_enabled:
// @state: A #DepthState struct
//
// Gets the current depth test enabled state as previously set by
// depth_state_set_test_enabled().
//
// Returns: The pipeline's current depth test enabled state.
// Since: 2.0
// Stability: Unstable
pub fn test_enabled(&self) -> bool {
let props = self.props.borrow();
props.test_enabled
}
// depth_state_set_write_enabled:
// @state: A #DepthState struct
// @enable: The enable state you want
//
// Enables or disables depth buffer writing according to the value of
// @enable. Normally when depth testing is enabled and the comparison
// between a fragment's depth value and the corresponding depth buffer
// value passes then the fragment's depth is written to the depth
// buffer unless writing is disabled here.
//
// By default depth writing is enabled
//
// NB: this won't directly affect the state of the GPU. You have
// to then set the state on a #Pipeline using
// pipeline_set_depth_state()
//
// Since: 2.0
// Stability: Unstable
pub fn set_write_enabled(&self, enable: bool) {
let mut props = self.props.borrow_mut();
props.write_enabled = enable;
}
// depth_state_get_write_enabled:
// @state: A #DepthState struct
//
// Gets the depth writing enable state as set by the corresponding
// depth_state_set_write_enabled().
//
// Returns: The current depth writing enable state
// Since: 2.0
// Stability: Unstable
pub fn write_enabled(&self) -> bool {
let props = self.props.borrow();
props.write_enabled
}
// // depth_state_set_test_function:
// // @state: A #DepthState struct
// // @function: The #DepthTestFunction to set
// //
// // Sets the #DepthTestFunction used to compare the depth value of
// // an incoming fragment against the corresponding value in the current
// // depth buffer.
// //
// // By default the depth test fn is %DEPTH_TEST_FUNCTION_LESS
// //
// // NB: this won't directly affect the state of the GPU. You have
// // to then set the state on a #Pipeline using
// // pipeline_set_depth_state()
// //
// // Since: 2.0
// // Stability: Unstable
// pub fn set_test_fn (&self, DepthTestFunction function);
// // depth_state_get_test_function:
// // @state: A #DepthState struct
// //
// // Gets the current depth test enable state as previously set via
// // depth_state_set_test_enabled().
// //
// // Returns: The current depth test enable state.
// // Since: 2.0
// // Stability: Unstable
// pub fn test_fn(&self) -> DepthTestFunction {
// }
// depth_state_set_range:
// @state: A #DepthState object
// @near_val: The near component of the desired depth range which will be
// clamped to the range [0, 1]
// @far_val: The far component of the desired depth range which will be
// clamped to the range [0, 1]
//
// Sets the range to map depth values in normalized device coordinates
// to before writing out to a depth buffer.
//
// After your geometry has be transformed, clipped and had perspective
// division applied placing it in normalized device
// coordinates all depth values between the near and far z clipping
// planes are in the range -1 to 1. Before writing any depth value to
// the depth buffer though the value is mapped into the range [0, 1].
//
// With this fn you can change the range which depth values are
// mapped too although the range must still lye within the range [0,
// 1].
//
// If your driver does not support this feature (for example you are
// using GLES 1 drivers) then if you don't use the default range
// values you will get an error reported when calling
// pipeline_set_depth_state (). You can check ahead of time for
// the %FEATURE_ID_DEPTH_RANGE feature with
// has_feature() to know if this fn will succeed.
//
// By default normalized device coordinate depth values are mapped to
// the full range of depth buffer values, [0, 1].
//
// NB: this won't directly affect the state of the GPU. You have
// to then set the state on a #Pipeline using
// pipeline_set_depth_state().
//
// Since: 2.0
// Stability: Unstable
pub fn set_range(&self, near_val: f32, far_val: f32) {
let mut props = self.props.borrow_mut();
props.range_near = near_val;
props.range_far = far_val;
}
// depth_state_get_range:
// @state: A #DepthState object
// @near_val: A pointer to store the near component of the depth range
// @far_val: A pointer to store the far component of the depth range
//
// Gets the current range to which normalized depth values are mapped
// before writing to the depth buffer. This corresponds to the range
// set with depth_state_set_range().
//
// Since: 2.0
// Stability: Unstable
pub fn range(&self) -> (f32, f32) {
let props = self.props.borrow();
(props.range_near, props.range_far)
}
}