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 Handle;
use gl;
use std::default::Default;
/// Represents the current OpenGL state.
///
/// The current state is passed to each function and can be freely updated.
pub struct GLState {
/// Whether GL_BLEND is enabled
pub enabled_blend: bool,
/// Whether GL_CULL_FACE is enabled
pub enabled_cull_face: bool,
/// Whether GL_DEBUG_OUTPUT is enabled. None means "unknown".
pub enabled_debug_output: Option<bool>,
/// Whether GL_DEBUG_OUTPUT_SYNCHRONOUS is enabled
pub enabled_debug_output_synchronous: bool,
/// Whether GL_DEPTH_TEST is enabled
pub enabled_depth_test: bool,
/// Whether GL_DITHER is enabled
pub enabled_dither: bool,
/// Whether GL_FRAMEBUFFER_SRGB is enabled
pub enabled_framebuffer_srgb: bool,
/// Whether GL_MULTISAMPLE is enabled
pub enabled_multisample: bool,
/// Whether GL_POLYGON_OFFSET_FILL is enabled
pub enabled_polygon_offset_fill: bool,
/// Whether GL_RASTERIZER_DISCARD is enabled
pub enabled_rasterizer_discard: bool,
/// Whether GL_SAMPLE_ALPHA_TO_COVERAGE is enabled
pub enabled_sample_alpha_to_coverage: bool,
/// Whether GL_SAMPLE_COVERAGE is enabled
pub enabled_sample_coverage: bool,
/// Whether GL_SCISSOR_TEST is enabled
pub enabled_scissor_test: bool,
/// Whether GL_STENCIL_TEST is enabled
pub enabled_stencil_test: bool,
// The latest value passed to `glUseProgram`.
pub program: Handle,
// The latest value passed to `glBindVertexArray`.
pub vertex_array: gl::types::GLuint,
// The latest value passed to `glClearColor`.
pub clear_color: (gl::types::GLclampf, gl::types::GLclampf,
gl::types::GLclampf, gl::types::GLclampf),
// The latest value passed to `glClearDepthf`.
pub clear_depth: gl::types::GLclampf,
// The latest value passed to `glClearStencil`.
pub clear_stencil: gl::types::GLint,
/// The latest buffer bound to `GL_ARRAY_BUFFER`.
pub array_buffer_binding: gl::types::GLuint,
/// The latest buffer bound to `GL_PIXEL_PACK_BUFFER`.
pub pixel_pack_buffer_binding: gl::types::GLuint,
/// The latest buffer bound to `GL_PIXEL_UNPACK_BUFFER`.
pub pixel_unpack_buffer_binding: gl::types::GLuint,
/// The latest buffer bound to `GL_UNIFORM_BUFFER`.
pub uniform_buffer_binding: gl::types::GLuint,
/// The latest buffer bound to `GL_READ_FRAMEBUFFER`.
pub read_framebuffer: gl::types::GLuint,
/// The latest buffer bound to `GL_DRAW_FRAMEBUFFER`.
pub draw_framebuffer: gl::types::GLuint,
/// The latest values passed to `glReadBuffer` with the default framebuffer.
/// `None` means "unknown".
pub default_framebuffer_read: Option<gl::types::GLenum>,
/// The latest render buffer bound with `glBindRenderbuffer`.
pub renderbuffer: gl::types::GLuint,
/// The latest values passed to `glBlendEquation`.
pub blend_equation: gl::types::GLenum,
/// The latest values passed to `glBlendFunc`.
pub blend_func: (gl::types::GLenum, gl::types::GLenum),
/// The latest value passed to `glDepthFunc`.
pub depth_func: gl::types::GLenum,
/// The latest value passed to `glDepthMask`.
pub depth_mask: bool,
/// The latest values passed to `glDepthRange`.
pub depth_range: (f32, f32),
/// The latest values passed to `glStencilFuncSeparate` with face `GL_FRONT`.
pub stencil_func_front: (gl::types::GLenum, gl::types::GLint, gl::types::GLuint),
/// The latest values passed to `glStencilFuncSeparate` with face `GL_BACK`.
pub stencil_func_back: (gl::types::GLenum, gl::types::GLint, gl::types::GLuint),
/// The latest value passed to `glStencilMaskSeparate` with face `GL_FRONT`.
pub stencil_mask_front: gl::types::GLuint,
/// The latest value passed to `glStencilMaskSeparate` with face `GL_BACK`.
pub stencil_mask_back: gl::types::GLuint,
/// The latest values passed to `glStencilOpSeparate` with face `GL_FRONT`.
pub stencil_op_front: (gl::types::GLenum, gl::types::GLenum, gl::types::GLenum),
/// The latest values passed to `glStencilOpSeparate` with face `GL_BACK`.
pub stencil_op_back: (gl::types::GLenum, gl::types::GLenum, gl::types::GLenum),
/// The latest values passed to `glViewport`. `None` means unknown.
pub viewport: Option<(gl::types::GLint, gl::types::GLint,
gl::types::GLsizei, gl::types::GLsizei)>,
/// The latest values passed to `glScissor`. `None` means unknown.
pub scissor: Option<(gl::types::GLint, gl::types::GLint,
gl::types::GLsizei, gl::types::GLsizei)>,
/// The latest value passed to `glLineWidth`.
pub line_width: gl::types::GLfloat,
/// The latest value passed to `glPointSize`.
pub point_size: gl::types::GLfloat,
/// The latest value passed to `glCullFace`.
pub cull_face: gl::types::GLenum,
/// The latest value passed to `glPolygonMode`.
pub polygon_mode: gl::types::GLenum,
/// The latest value passed to `glPixelStore` with `GL_UNPACK_ALIGNMENT`.
pub pixel_store_unpack_alignment: gl::types::GLint,
/// The latest value passed to `glPixelStore` with `GL_PACK_ALIGNMENT`.
pub pixel_store_pack_alignment: gl::types::GLint,
/// The latest value passed to `glPatchParameter` with `GL_PATCH_VERTICES`.
pub patch_patch_vertices: gl::types::GLint,
/// The latest value passed to `glActiveTexture`.
pub active_texture: gl::types::GLenum,
}
impl Default for GLState {
fn default() -> GLState {
GLState {
enabled_blend: false,
enabled_cull_face: false,
enabled_debug_output: None,
enabled_debug_output_synchronous: false,
enabled_depth_test: false,
enabled_dither: false,
enabled_framebuffer_srgb: false,
enabled_multisample: true,
enabled_polygon_offset_fill: false,
enabled_rasterizer_discard: false,
enabled_sample_alpha_to_coverage: false,
enabled_sample_coverage: false,
enabled_scissor_test: false,
enabled_stencil_test: false,
program: Handle::Id(0),
vertex_array: 0,
clear_color: (0.0, 0.0, 0.0, 0.0),
clear_depth: 1.0,
clear_stencil: 0,
array_buffer_binding: 0,
pixel_pack_buffer_binding: 0,
pixel_unpack_buffer_binding: 0,
uniform_buffer_binding: 0,
read_framebuffer: 0,
draw_framebuffer: 0,
default_framebuffer_read: None,
renderbuffer: 0,
depth_func: gl::LESS,
depth_mask: true,
depth_range: (0.0, 1.0),
stencil_func_front: (gl::ALWAYS, 0, 0xffffffff),
stencil_func_back: (gl::ALWAYS, 0, 0xffffffff),
stencil_mask_front: 0xffffffff,
stencil_mask_back: 0xffffffff,
stencil_op_front: (gl::KEEP, gl::KEEP, gl::KEEP),
stencil_op_back: (gl::KEEP, gl::KEEP, gl::KEEP),
blend_equation: gl::FUNC_ADD,
blend_func: (gl::ONE, gl::ZERO),
viewport: None,
scissor: None,
line_width: 1.0,
point_size: 1.0,
cull_face: gl::BACK,
polygon_mode: gl::FILL,
pixel_store_unpack_alignment: 4,
pixel_store_pack_alignment: 4,
patch_patch_vertices: 3,
active_texture: gl::TEXTURE0,
}
}
}