ffgl_glium/
validate_gl.rs

1//! Validate the state of the OpenGL context.
2
3pub struct TextureType {
4    pub target: u32,
5    pub binding: u32,
6}
7
8pub const TEXTURE_TYPES: [TextureType; 2] = [
9    TextureType {
10        target: gl::TEXTURE_1D,
11        binding: gl::TEXTURE_BINDING_1D,
12    },
13    TextureType {
14        target: gl::TEXTURE_2D,
15        binding: gl::TEXTURE_BINDING_2D,
16    },
17    // Add other texture types here...
18];
19
20pub unsafe fn gl_reset(frame_data: &ffgl_core::ffi::ffgl2::ProcessOpenGLStructTag) {
21    let mut gl_int = 0;
22    gl::UseProgram(0);
23
24    let mut num_samplers = 0;
25    gl::GetIntegerv(gl::MAX_TEXTURE_IMAGE_UNITS, &mut num_samplers);
26
27    for texture_type in TEXTURE_TYPES.iter() {
28        for sampler in 0..num_samplers {
29            gl::ActiveTexture(gl::TEXTURE0 + sampler as u32);
30            // Check if textures are unbound for the current texture unit.
31            gl::GetIntegerv(texture_type.binding, &mut gl_int);
32            // gl::BindTexture(texture_type.target, 0);
33        }
34    }
35
36    gl::ActiveTexture(gl::TEXTURE0);
37
38    gl::BindBuffer(gl::ARRAY_BUFFER, 0);
39    gl::BindBuffer(gl::VERTEX_BINDING_BUFFER, 0);
40    gl::BindVertexArray(0);
41    gl::Disable(gl::BLEND);
42
43    gl::BlendFunc(gl::ONE, gl::ZERO);
44
45    // gl::BindVertexBuffer(0, 0, 0, 0);
46
47    // gl::VertexArrayElementBuffer(vaobj, buffer)
48    // gl::BindTextureUnit(0, 0);
49    gl::BindFramebuffer(gl::FRAMEBUFFER, frame_data.HostFBO);
50}
51
52pub unsafe fn validate_viewport(viewport: &[i32; 4]) {
53    let scissor_enabled = gl::IsEnabled(gl::SCISSOR_TEST);
54    assert_eq!(scissor_enabled, gl::FALSE, "SCISSOR_TEST is enabled");
55
56    let mut dims: [i32; 4] = [0; 4];
57    gl::GetIntegerv(gl::VIEWPORT, &mut dims[0]);
58    assert_eq!(&dims, viewport, "VIEWPORT wrong value: {dims:?}");
59}