diff --git a/3rdparty/imgui/examples/opengl3_example/imgui_impl_glfw_gl3.cpp b/3rdparty/imgui/examples/opengl3_example/imgui_impl_glfw_gl3.cpp index cd652c0..7ce8e2d 100644 --- a/3rdparty/imgui/examples/opengl3_example/imgui_impl_glfw_gl3.cpp +++ b/3rdparty/imgui/examples/opengl3_example/imgui_impl_glfw_gl3.cpp @@ -114,7 +114,18 @@ void ImGui_ImplGlfwGL3_RenderDrawLists(ImDrawData* draw_data) } else { - glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId); + intptr_t ptr = (intptr_t)pcmd->TextureId; + + // MOD START (martin), 2018-03-09: support texture references that point to an address of a texture id + if (ptr > 1024 * 1024) + { + GLTextureRef* texture_ref = (GLTextureRef*)pcmd->TextureId; + GLuint* texture_ptr = (GLuint*) texture_ref->mTextureIdPtr; + glBindTexture(GL_TEXTURE_2D, *texture_ptr); + } else { + glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId); + } + // MOD END (martin), 2018-03-09: support texture references that point to an address of a texture id glScissor((int)pcmd->ClipRect.x, (int)(fb_height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y)); glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset); } diff --git a/3rdparty/imgui/examples/opengl3_example/imgui_impl_glfw_gl3.h b/3rdparty/imgui/examples/opengl3_example/imgui_impl_glfw_gl3.h index 6b4101f..ed07f31 100644 --- a/3rdparty/imgui/examples/opengl3_example/imgui_impl_glfw_gl3.h +++ b/3rdparty/imgui/examples/opengl3_example/imgui_impl_glfw_gl3.h @@ -13,6 +13,16 @@ struct GLFWwindow; +// MOD START (martin), 2018-03-09: support texture references that point to an address of a texture id +union GLTextureRef { + int mTextureId; + struct { + int magic; + unsigned int* mTextureIdPtr; + }; +}; +// MOD END (martin), 2018-03-09: support texture references that point to an address of a texture id + IMGUI_API bool ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks); IMGUI_API void ImGui_ImplGlfwGL3_Shutdown(); IMGUI_API void ImGui_ImplGlfwGL3_NewFrame(); diff --git a/src/modules/RenderModule.cc b/src/modules/RenderModule.cc index 0c50120..ce490be 100644 --- a/src/modules/RenderModule.cc +++ b/src/modules/RenderModule.cc @@ -517,19 +517,19 @@ void Renderer::RenderGui() { if (ImGui::BeginDock("Scene")) { ImGui::Checkbox("Draw Depth", &mSettings->DrawDepth); - GLuint texture; if (mSettings->DrawDepth) { - texture = mRenderTarget.mLinearizedDepthTexture; + mRenderTextureRef.mTextureIdPtr = &mRenderTarget.mLinearizedDepthTexture; } else { - texture = mRenderTarget.mColorTexture; + mRenderTextureRef.mTextureIdPtr = &mRenderTarget.mColorTexture; } ImGui::Text("Scene"); const ImVec2 content_avail = ImGui::GetContentRegionAvail(); mSceneAreaWidth = content_avail.x; mSceneAreaHeight = content_avail.y; - - ImGui::Image((void*) texture, + + mRenderTextureRef.magic = (GLuint)0xbadface; + ImGui::Image((void*) &mRenderTextureRef, content_avail, ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f) diff --git a/src/modules/RenderModule.h b/src/modules/RenderModule.h index 93f2e64..9be65db 100644 --- a/src/modules/RenderModule.h +++ b/src/modules/RenderModule.h @@ -8,6 +8,8 @@ #include "math_types.h" #include // This example is using gl3w to access OpenGL functions (because it is small). You may use glew/glad/glLoadGen/etc. whatever already works for you. +#include "imgui.h" +#include "imgui_impl_glfw_gl3.h" #include "Globals.h" #include "RenderUtils.h" @@ -125,6 +127,7 @@ struct Renderer { GLuint muDefaultColor; RenderTarget mRenderTarget; + GLTextureRef mRenderTextureRef = { (int)0xbadface }; GLuint mRenderQuadVertexArrayId; GLuint mRenderQuadVertexBufferId;