diff --git a/include/Engine/Rendering/ImGuiRenderPass.h b/include/Engine/Rendering/ImGuiRenderPass.h index 1ca443e9..e9d359ba 100644 --- a/include/Engine/Rendering/ImGuiRenderPass.h +++ b/include/Engine/Rendering/ImGuiRenderPass.h @@ -1,6 +1,7 @@ #include #include "../OpenGL.h" #include "IRenderer.h" +#include "RenderState.h" #include "../Core/EventBroker.h" #include "../Core/EMousePress.h" #include "../Core/EMouseRelease.h" @@ -10,6 +11,22 @@ #include "../Core/EKeyUp.h" #include "../Core/EKeyboardChar.h" +class ImGuiRenderState : public RenderState +{ +public: + ImGuiRenderState() + : RenderState() + { + BindFramebuffer(0); + Enable(GL_BLEND); + BlendEquation(GL_FUNC_ADD); + BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + Disable(GL_CULL_FACE); + Disable(GL_DEPTH_TEST); + Enable(GL_SCISSOR_TEST); + } +}; + class ImGuiRenderPass { public: diff --git a/src/Engine/Rendering/ImGuiRenderPass.cpp b/src/Engine/Rendering/ImGuiRenderPass.cpp index f2147ea8..96f987d9 100644 --- a/src/Engine/Rendering/ImGuiRenderPass.cpp +++ b/src/Engine/Rendering/ImGuiRenderPass.cpp @@ -69,29 +69,8 @@ void ImGuiRenderPass::Draw() ImDrawData* draw_data = ImGui::GetDrawData(); - // Backup GL state - GLint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, &last_program); - GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); - GLint last_array_buffer; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer); - GLint last_element_array_buffer; glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &last_element_array_buffer); - GLint last_vertex_array; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array); - GLint last_blend_src; glGetIntegerv(GL_BLEND_SRC, &last_blend_src); - GLint last_blend_dst; glGetIntegerv(GL_BLEND_DST, &last_blend_dst); - GLint last_blend_equation_rgb; glGetIntegerv(GL_BLEND_EQUATION_RGB, &last_blend_equation_rgb); - GLint last_blend_equation_alpha; glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &last_blend_equation_alpha); - GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport); - GLboolean last_enable_blend = glIsEnabled(GL_BLEND); - GLboolean last_enable_cull_face = glIsEnabled(GL_CULL_FACE); - GLboolean last_enable_depth_test = glIsEnabled(GL_DEPTH_TEST); - GLboolean last_enable_scissor_test = glIsEnabled(GL_SCISSOR_TEST); - - // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled - glEnable(GL_BLEND); - glBlendEquation(GL_FUNC_ADD); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glDisable(GL_CULL_FACE); - glDisable(GL_DEPTH_TEST); - glEnable(GL_SCISSOR_TEST); + // Set up render state + ImGuiRenderState state; glActiveTexture(GL_TEXTURE0); // Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays) @@ -134,20 +113,6 @@ void ImGuiRenderPass::Draw() } } - // Restore modified GL state - glUseProgram(last_program); - glBindTexture(GL_TEXTURE_2D, last_texture); - glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, last_element_array_buffer); - glBindVertexArray(last_vertex_array); - glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha); - glBlendFunc(last_blend_src, last_blend_dst); - 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_scissor_test) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST); - glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]); - // Start next frame newFrame(); }