Using TextureRef for submitting the scene render to ImGui::Image()

simple_math_single_header
Martin Felis 2018-03-09 16:16:39 +01:00
parent d6ac057ce9
commit 69471bba84
4 changed files with 30 additions and 6 deletions

View File

@ -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);
}

View File

@ -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();

View File

@ -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)

View File

@ -8,6 +8,8 @@
#include "math_types.h"
#include <GL/gl3w.h> // 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;