From 1d7689052643ad0d5586b636934b22a37432d9e8 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 8 Nov 2015 22:52:25 +0000 Subject: [PATCH] Examples: OpenGL3: Implement ImGui_ImplGlfwGL3_InvalidateDeviceObjects() like other examples. --- .../opengl3_example/imgui_impl_glfw_gl3.cpp | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/examples/opengl3_example/imgui_impl_glfw_gl3.cpp b/examples/opengl3_example/imgui_impl_glfw_gl3.cpp index 68085659..8e3ae119 100644 --- a/examples/opengl3_example/imgui_impl_glfw_gl3.cpp +++ b/examples/opengl3_example/imgui_impl_glfw_gl3.cpp @@ -262,6 +262,32 @@ bool ImGui_ImplGlfwGL3_CreateDeviceObjects() return true; } +void ImGui_ImplGlfwGL3_InvalidateDeviceObjects() +{ + if (g_VaoHandle) glDeleteVertexArrays(1, &g_VaoHandle); + if (g_VboHandle) glDeleteBuffers(1, &g_VboHandle); + if (g_ElementsHandle) glDeleteBuffers(1, &g_ElementsHandle); + g_VaoHandle = g_VboHandle = g_ElementsHandle = 0; + + glDetachShader(g_ShaderHandle, g_VertHandle); + glDeleteShader(g_VertHandle); + g_VertHandle = 0; + + glDetachShader(g_ShaderHandle, g_FragHandle); + glDeleteShader(g_FragHandle); + g_FragHandle = 0; + + glDeleteProgram(g_ShaderHandle); + g_ShaderHandle = 0; + + if (g_FontTexture) + { + glDeleteTextures(1, &g_FontTexture); + ImGui::GetIO().Fonts->TexID = 0; + g_FontTexture = 0; + } +} + bool ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks) { g_Window = window; @@ -307,28 +333,7 @@ bool ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks) void ImGui_ImplGlfwGL3_Shutdown() { - if (g_VaoHandle) glDeleteVertexArrays(1, &g_VaoHandle); - if (g_VboHandle) glDeleteBuffers(1, &g_VboHandle); - if (g_ElementsHandle) glDeleteBuffers(1, &g_ElementsHandle); - g_VaoHandle = g_VboHandle = g_ElementsHandle = 0; - - glDetachShader(g_ShaderHandle, g_VertHandle); - glDeleteShader(g_VertHandle); - g_VertHandle = 0; - - glDetachShader(g_ShaderHandle, g_FragHandle); - glDeleteShader(g_FragHandle); - g_FragHandle = 0; - - glDeleteProgram(g_ShaderHandle); - g_ShaderHandle = 0; - - if (g_FontTexture) - { - glDeleteTextures(1, &g_FontTexture); - ImGui::GetIO().Fonts->TexID = 0; - g_FontTexture = 0; - } + ImGui_ImplGlfwGL3_InvalidateDeviceObjects(); ImGui::Shutdown(); }