Using TextureRef for submitting the scene render to ImGui::Image()
parent
d6ac057ce9
commit
69471bba84
|
@ -114,7 +114,18 @@ void ImGui_ImplGlfwGL3_RenderDrawLists(ImDrawData* draw_data)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
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);
|
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));
|
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);
|
glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,16 @@
|
||||||
|
|
||||||
struct GLFWwindow;
|
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 bool ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks);
|
||||||
IMGUI_API void ImGui_ImplGlfwGL3_Shutdown();
|
IMGUI_API void ImGui_ImplGlfwGL3_Shutdown();
|
||||||
IMGUI_API void ImGui_ImplGlfwGL3_NewFrame();
|
IMGUI_API void ImGui_ImplGlfwGL3_NewFrame();
|
||||||
|
|
|
@ -517,11 +517,10 @@ void Renderer::RenderGui() {
|
||||||
if (ImGui::BeginDock("Scene")) {
|
if (ImGui::BeginDock("Scene")) {
|
||||||
ImGui::Checkbox("Draw Depth", &mSettings->DrawDepth);
|
ImGui::Checkbox("Draw Depth", &mSettings->DrawDepth);
|
||||||
|
|
||||||
GLuint texture;
|
|
||||||
if (mSettings->DrawDepth) {
|
if (mSettings->DrawDepth) {
|
||||||
texture = mRenderTarget.mLinearizedDepthTexture;
|
mRenderTextureRef.mTextureIdPtr = &mRenderTarget.mLinearizedDepthTexture;
|
||||||
} else {
|
} else {
|
||||||
texture = mRenderTarget.mColorTexture;
|
mRenderTextureRef.mTextureIdPtr = &mRenderTarget.mColorTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::Text("Scene");
|
ImGui::Text("Scene");
|
||||||
|
@ -529,7 +528,8 @@ void Renderer::RenderGui() {
|
||||||
mSceneAreaWidth = content_avail.x;
|
mSceneAreaWidth = content_avail.x;
|
||||||
mSceneAreaHeight = content_avail.y;
|
mSceneAreaHeight = content_avail.y;
|
||||||
|
|
||||||
ImGui::Image((void*) texture,
|
mRenderTextureRef.magic = (GLuint)0xbadface;
|
||||||
|
ImGui::Image((void*) &mRenderTextureRef,
|
||||||
content_avail,
|
content_avail,
|
||||||
ImVec2(0.0f, 1.0f),
|
ImVec2(0.0f, 1.0f),
|
||||||
ImVec2(1.0f, 0.0f)
|
ImVec2(1.0f, 0.0f)
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
#include "math_types.h"
|
#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 <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 "Globals.h"
|
||||||
#include "RenderUtils.h"
|
#include "RenderUtils.h"
|
||||||
|
@ -125,6 +127,7 @@ struct Renderer {
|
||||||
GLuint muDefaultColor;
|
GLuint muDefaultColor;
|
||||||
|
|
||||||
RenderTarget mRenderTarget;
|
RenderTarget mRenderTarget;
|
||||||
|
GLTextureRef mRenderTextureRef = { (int)0xbadface };
|
||||||
|
|
||||||
GLuint mRenderQuadVertexArrayId;
|
GLuint mRenderQuadVertexArrayId;
|
||||||
GLuint mRenderQuadVertexBufferId;
|
GLuint mRenderQuadVertexBufferId;
|
||||||
|
|
Loading…
Reference in New Issue