From e706260793990defe37abf3abb95bfc6aa28d2a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Thu, 23 Apr 2015 17:14:29 -0700 Subject: [PATCH] Added texture handle passing to ocornut-imgui. --- examples/common/imgui/imgui.h | 12 ++++++++++++ examples/common/imgui/ocornut_imgui.cpp | 8 +++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/examples/common/imgui/imgui.h b/examples/common/imgui/imgui.h index 87d744be..cb062231 100644 --- a/examples/common/imgui/imgui.h +++ b/examples/common/imgui/imgui.h @@ -204,4 +204,16 @@ bool imguiCube(bgfx::TextureHandle _cubemap, float _lod = 0.0f, ImguiCubemap::En float imguiGetTextLength(const char* _text, ImguiFontHandle _handle); bool imguiMouseOverArea(); +namespace ImGui +{ + // Helper function for passing bgfx::TextureHandle to ImGui::Image. + inline void Image(bgfx::TextureHandle _handle, const ImVec2& _size, const ImVec2& _uv0 = ImVec2(0, 0), const ImVec2& _uv1 = ImVec2(1, 1), const ImVec4& _tint_col = ImVec4(1, 1, 1, 1), const ImVec4& _border_col = ImVec4(0, 0, 0, 0)) + { + union { bgfx::TextureHandle handle; ImTextureID ptr; } texture; + texture.handle = _handle; + Image(texture.ptr, _size, _uv0, _uv1, _tint_col, _border_col); + } + +} // namespace ImGui + #endif // IMGUI_H_HEADER_GUARD diff --git a/examples/common/imgui/ocornut_imgui.cpp b/examples/common/imgui/ocornut_imgui.cpp index 2ab657f7..368d503a 100644 --- a/examples/common/imgui/ocornut_imgui.cpp +++ b/examples/common/imgui/ocornut_imgui.cpp @@ -72,7 +72,13 @@ struct OcornutImguiContext , uint16_t(pcmd->clip_rect.z-pcmd->clip_rect.x) , uint16_t(pcmd->clip_rect.w-pcmd->clip_rect.y) ); - bgfx::setTexture(0, s_tex, m_texture); + union { void* ptr; bgfx::TextureHandle handle; } texture = { pcmd->texture_id }; + + bgfx::setTexture(0, s_tex, 0 != texture.handle.idx + ? texture.handle + : m_texture + ); + bgfx::setVertexBuffer(&tvb, vtx_offset, pcmd->vtx_count); bgfx::setProgram(m_program); bgfx::submit(m_viewId);