Added texture handle passing to ocornut-imgui.

This commit is contained in:
Branimir Karadžić 2015-04-23 17:14:29 -07:00
parent 44304315b5
commit e706260793
2 changed files with 19 additions and 1 deletions

View file

@ -204,4 +204,16 @@ bool imguiCube(bgfx::TextureHandle _cubemap, float _lod = 0.0f, ImguiCubemap::En
float imguiGetTextLength(const char* _text, ImguiFontHandle _handle); float imguiGetTextLength(const char* _text, ImguiFontHandle _handle);
bool imguiMouseOverArea(); 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 #endif // IMGUI_H_HEADER_GUARD

View file

@ -72,7 +72,13 @@ struct OcornutImguiContext
, uint16_t(pcmd->clip_rect.z-pcmd->clip_rect.x) , uint16_t(pcmd->clip_rect.z-pcmd->clip_rect.x)
, uint16_t(pcmd->clip_rect.w-pcmd->clip_rect.y) , 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::setVertexBuffer(&tvb, vtx_offset, pcmd->vtx_count);
bgfx::setProgram(m_program); bgfx::setProgram(m_program);
bgfx::submit(m_viewId); bgfx::submit(m_viewId);