// OpenGLState :: struct {
//     last_active_texture : GLenum;
//     last_program : GLuint;
//     last_texture : GLuint;
//     last_array_buffer : GLuint;

//     #if !#exists(IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY) {
//         // This is part of VAO on OpenGL 3.0+ and OpenGL ES 3.0+.
//         last_element_array_buffer : GLint;
//     }
//     #if #exists(IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY) {
//         last_vertex_array_object : GLuint;
//     }

//     #if #exists(IMGUI_IMPL_OPENGL_MAY_HAVE_POLYGON_MODE) {
//         last_polygon_mode : [2] GLint;
//     }

//     last_viewport : [4] GLint;
//     last_scissor_box : [4]GLint;
//     last_blend_src_rgb : GLenum;
//     last_blend_dst_rgb : GLenum;
//     last_blend_src_alpha : GLenum;
//     last_blend_dst_alpha : GLenum;
//     last_blend_equation_rgb : GLenum;
//     last_blend_equation_alpha : GLenum;

//     last_enable_blend : GLboolean;
//     last_enable_cull_face : GLboolean;
//     last_enable_depth_test : GLboolean;
//     last_enable_stencil_test : GLboolean;
//     last_enable_scissor_test : GLboolean;
// }

// save_opengl_state :: (using state: *OpenGLState) {

//     glGetIntegerv(GL_ACTIVE_TEXTURE, cast(*GLint) *last_active_texture);
//     glActiveTexture(GL_TEXTURE0);
//     glGetIntegerv(GL_CURRENT_PROGRAM, cast(*GLint) *last_program);
    
//     glGetIntegerv(GL_TEXTURE_BINDING_2D, cast(*GLint) *last_texture);

//     // #if #exists(IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER) {
//     //     last_sampler : GLuint;
//     //     if bd.GlVersion >= 330 || bd.GlProfileIsES3 {
//     //         glGetIntegerv(GL_SAMPLER_BINDING, cast(*GLint) *last_sampler);
//     //     } else {
//     //         last_sampler = 0;
//     //     }
//     // }

    
//     glGetIntegerv(GL_ARRAY_BUFFER_BINDING, cast(*GLint) *last_array_buffer);

//     #if !#exists(IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY) {
//         // This is part of VAO on OpenGL 3.0+ and OpenGL ES 3.0+.
//         glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, *last_element_array_buffer);

//         GetState(*last_vtx_attrib_state_pos, xx bd.AttribLocationVtxPos);
//         GetState(*last_vtx_attrib_state_uv, xx bd.AttribLocationVtxUV);
//         GetState(*last_vtx_attrib_state_colour, xx bd.AttribLocationVtxColor);
//     }
//     #if #exists(IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY) {
//         glGetIntegerv(GL_VERTEX_ARRAY_BINDING, cast(*GLint) *last_vertex_array_object);
//     }

//     #if #exists(IMGUI_IMPL_OPENGL_MAY_HAVE_POLYGON_MODE) {
//         if (bd.HasPolygonMode) {
//             glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode.data);
//         }
//     }
    
//     glGetIntegerv(GL_VIEWPORT, last_viewport.data);
//     glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box.data);
//     glGetIntegerv(GL_BLEND_SRC_RGB, cast(*GLint) *last_blend_src_rgb);
//     glGetIntegerv(GL_BLEND_DST_RGB, cast(*GLint) *last_blend_dst_rgb);
//     glGetIntegerv(GL_BLEND_SRC_ALPHA, cast(*GLint) *last_blend_src_alpha);
//     glGetIntegerv(GL_BLEND_DST_ALPHA, cast(*GLint) *last_blend_dst_alpha);
//     glGetIntegerv(GL_BLEND_EQUATION_RGB, cast(*GLint) *last_blend_equation_rgb);
//     glGetIntegerv(GL_BLEND_EQUATION_ALPHA, cast(*GLint) *last_blend_equation_alpha);

//     last_enable_blend = glIsEnabled(GL_BLEND);
//     last_enable_cull_face = glIsEnabled(GL_CULL_FACE);
//     last_enable_depth_test = glIsEnabled(GL_DEPTH_TEST);
//     last_enable_stencil_test = glIsEnabled(GL_STENCIL_TEST);
//     last_enable_scissor_test  = glIsEnabled(GL_SCISSOR_TEST);
//     // #if #exists (IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART) {
//     //     last_enable_primitive_restart : GLboolean = ifx (bd.GlVersion >= 310) then glIsEnabled(GL_PRIMITIVE_RESTART) else GL_FALSE;
//     // }
// }

// restore_opengl_state :: (using state: *OpenGLState) {
//     // This "glIsProgram()" check is required because if the program is "pending deletion" at the time of binding backup,
//     // it will have been deleted by now and will cause an OpenGL error. See #6220.
//     if last_program == 0 || glIsProgram(last_program) glUseProgram(last_program);
//     glBindTexture(GL_TEXTURE_2D, last_texture);
//     // #if #exists(IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER) {
//     //     if bd.GlVersion >= 330 || bd.GlProfileIsES3
//     //         glBindSampler(0, last_sampler);
//     // }
//     glActiveTexture(last_active_texture);
//     #if #exists(IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY) {
//         glBindVertexArray(last_vertex_array_object);
//     }
//     glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
//     #if !#exists(IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY) {
//         glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, xx last_element_array_buffer);
//         SetState(*last_vtx_attrib_state_pos, xx bd.AttribLocationVtxPos);
//         SetState(*last_vtx_attrib_state_uv, xx bd.AttribLocationVtxUV);
//         SetState(*last_vtx_attrib_state_colour, xx bd.AttribLocationVtxColor);
//     }
//     glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha);
//     glBlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha);
//     if last_enable_blend glEnable(GL_BLEND); else glDisable(GL_BLEND);
//     if last_enable_cull_face glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE);
//     if last_enable_depth_test glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST);
//     if last_enable_stencil_test glEnable(GL_STENCIL_TEST); else glDisable(GL_STENCIL_TEST);
//     if last_enable_scissor_test glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST);
//     // #if #exists(IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART) {
//     //     if bd.GlVersion >= 310 {
//     //         if last_enable_primitive_restart
//     //             glEnable(GL_PRIMITIVE_RESTART);
//     //         else
//     //             glDisable(GL_PRIMITIVE_RESTART);
//     //     }
//     // }

//     #if #exists(IMGUI_IMPL_OPENGL_MAY_HAVE_POLYGON_MODE) {
//         // Desktop OpenGL 3.0 and OpenGL 3.1 had separate polygon draw modes for front-facing and back-facing faces of polygons
//         if (bd.HasPolygonMode) {
//             if (bd.GlVersion <= 310 || bd.GlProfileIsCompat) {
//                 glPolygonMode(GL_FRONT, cast(GLenum) last_polygon_mode[0]);
//                 glPolygonMode(GL_BACK, cast(GLenum) last_polygon_mode[1]);
//             } else {
//                 glPolygonMode(GL_FRONT_AND_BACK, cast(GLenum) last_polygon_mode[0]);
//             }
//         }
//     } // IMGUI_IMPL_OPENGL_MAY_HAVE_POLYGON_MODE

//     glViewport(last_viewport[0], last_viewport[1], cast(GLsizei) last_viewport[2], cast(GLsizei) last_viewport[3]);
//     glScissor(last_scissor_box[0], last_scissor_box[1], cast(GLsizei) last_scissor_box[2], cast(GLsizei) last_scissor_box[3]);
// }
