mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 18:45:54 -05:00
Added ImGui image flags.
This commit is contained in:
parent
f1bba419b7
commit
44eacd0859
2 changed files with 77 additions and 20 deletions
|
@ -208,20 +208,65 @@ bool imguiMouseOverArea();
|
||||||
|
|
||||||
namespace ImGui
|
namespace ImGui
|
||||||
{
|
{
|
||||||
|
#define IMGUI_FLAGS_NONE UINT16_C(0x0000)
|
||||||
|
#define IMGUI_FLAGS_ALPHA_BLEND UINT16_C(0x0001)
|
||||||
|
|
||||||
// Helper function for passing bgfx::TextureHandle to ImGui::Image.
|
// 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) )
|
inline void Image(bgfx::TextureHandle _handle
|
||||||
|
, uint16_t _flags
|
||||||
|
, const ImVec2& _size
|
||||||
|
, const ImVec2& _uv0 = ImVec2(0.0f, 0.0f)
|
||||||
|
, const ImVec2& _uv1 = ImVec2(1.0f, 1.0f)
|
||||||
|
, const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f)
|
||||||
|
, const ImVec4& _borderCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
union { bgfx::TextureHandle handle; ImTextureID ptr; } texture;
|
union { struct { uint16_t flags; bgfx::TextureHandle handle; } s; ImTextureID ptr; } texture;
|
||||||
texture.handle = _handle;
|
texture.s.flags = _flags;
|
||||||
Image(texture.ptr, _size, _uv0, _uv1, _tint_col, _border_col);
|
texture.s.handle = _handle;
|
||||||
|
Image(texture.ptr, _size, _uv0, _uv1, _tintCol, _borderCol);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function for passing bgfx::TextureHandle to ImGui::Image.
|
||||||
|
inline void Image(bgfx::TextureHandle _handle
|
||||||
|
, const ImVec2& _size
|
||||||
|
, const ImVec2& _uv0 = ImVec2(0.0f, 0.0f)
|
||||||
|
, const ImVec2& _uv1 = ImVec2(1.0f, 1.0f)
|
||||||
|
, const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f)
|
||||||
|
, const ImVec4& _borderCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Image(_handle, IMGUI_FLAGS_ALPHA_BLEND, _size, _uv0, _uv1, _tintCol, _borderCol);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function for passing bgfx::TextureHandle to ImGui::ImageButton.
|
// Helper function for passing bgfx::TextureHandle to ImGui::ImageButton.
|
||||||
inline bool ImageButton(bgfx::TextureHandle _handle, const ImVec2& _size, const ImVec2& _uv0 = ImVec2(0,0), const ImVec2& _uv1 = ImVec2(1,1), int _frame_padding = -1, const ImVec4& _bg_col = ImVec4(0,0,0,0), const ImVec4& _tint_col = ImVec4(1,1,1,1))
|
inline bool ImageButton(bgfx::TextureHandle _handle
|
||||||
|
, uint16_t _flags
|
||||||
|
, const ImVec2& _size
|
||||||
|
, const ImVec2& _uv0 = ImVec2(0.0f, 0.0f)
|
||||||
|
, const ImVec2& _uv1 = ImVec2(1.0f, 1.0f)
|
||||||
|
, int _framePadding = -1
|
||||||
|
, const ImVec4& _bgCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f)
|
||||||
|
, const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
union { bgfx::TextureHandle handle; ImTextureID ptr; } texture;
|
union { struct { uint16_t flags; bgfx::TextureHandle handle; } s; ImTextureID ptr; } texture;
|
||||||
texture.handle = _handle;
|
texture.s.flags = _flags;
|
||||||
return ImageButton(texture.ptr, _size, _uv0, _uv1, _frame_padding, _bg_col, _tint_col);
|
texture.s.handle = _handle;
|
||||||
|
return ImageButton(texture.ptr, _size, _uv0, _uv1, _framePadding, _bgCol, _tintCol);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function for passing bgfx::TextureHandle to ImGui::ImageButton.
|
||||||
|
inline bool ImageButton(bgfx::TextureHandle _handle
|
||||||
|
, const ImVec2& _size
|
||||||
|
, const ImVec2& _uv0 = ImVec2(0.0f, 0.0f)
|
||||||
|
, const ImVec2& _uv1 = ImVec2(1.0f, 1.0f)
|
||||||
|
, int _framePadding = -1
|
||||||
|
, const ImVec4& _bgCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f)
|
||||||
|
, const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return ImageButton(_handle, IMGUI_FLAGS_ALPHA_BLEND, _size, _uv0, _uv1, _framePadding, _bgCol, _tintCol);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ImGui
|
} // namespace ImGui
|
||||||
|
|
|
@ -320,25 +320,37 @@ struct OcornutImguiContext
|
||||||
}
|
}
|
||||||
else if (0 != cmd->ElemCount)
|
else if (0 != cmd->ElemCount)
|
||||||
{
|
{
|
||||||
bgfx::setState(0
|
uint64_t state = 0
|
||||||
| BGFX_STATE_RGB_WRITE
|
| BGFX_STATE_RGB_WRITE
|
||||||
| BGFX_STATE_ALPHA_WRITE
|
| BGFX_STATE_ALPHA_WRITE
|
||||||
| BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA)
|
| BGFX_STATE_MSAA
|
||||||
| BGFX_STATE_MSAA
|
;
|
||||||
);
|
|
||||||
|
bgfx::TextureHandle th = m_texture;
|
||||||
|
|
||||||
|
if (NULL != cmd->TextureId)
|
||||||
|
{
|
||||||
|
union { ImTextureID ptr; struct { uint16_t flags; bgfx::TextureHandle handle; } s; } texture = { cmd->TextureId };
|
||||||
|
state |= 0 != (IMGUI_FLAGS_ALPHA_BLEND & texture.s.flags)
|
||||||
|
? BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA)
|
||||||
|
: BGFX_STATE_NONE
|
||||||
|
;
|
||||||
|
th = texture.s.handle;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
state |= BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA);
|
||||||
|
}
|
||||||
|
|
||||||
const uint16_t xx = uint16_t(bx::fmax(cmd->ClipRect.x, 0.0f) );
|
const uint16_t xx = uint16_t(bx::fmax(cmd->ClipRect.x, 0.0f) );
|
||||||
const uint16_t yy = uint16_t(bx::fmax(cmd->ClipRect.y, 0.0f) );
|
const uint16_t yy = uint16_t(bx::fmax(cmd->ClipRect.y, 0.0f) );
|
||||||
bgfx::setScissor(xx, yy
|
bgfx::setScissor(xx, yy
|
||||||
, uint16_t(bx::fmin(cmd->ClipRect.z, 65535.0f)-xx)
|
, uint16_t(bx::fmin(cmd->ClipRect.z, 65535.0f)-xx)
|
||||||
, uint16_t(bx::fmin(cmd->ClipRect.w, 65535.0f)-yy)
|
, uint16_t(bx::fmin(cmd->ClipRect.w, 65535.0f)-yy)
|
||||||
);
|
);
|
||||||
union { void* ptr; bgfx::TextureHandle handle; } texture = { cmd->TextureId };
|
|
||||||
|
|
||||||
bgfx::setTexture(0, s_tex, 0 != texture.handle.idx
|
|
||||||
? texture.handle
|
|
||||||
: m_texture
|
|
||||||
);
|
|
||||||
|
|
||||||
|
bgfx::setState(state);
|
||||||
|
bgfx::setTexture(0, s_tex, th);
|
||||||
bgfx::setVertexBuffer(&tvb, 0, numVertices);
|
bgfx::setVertexBuffer(&tvb, 0, numVertices);
|
||||||
bgfx::setIndexBuffer(&tib, offset, cmd->ElemCount);
|
bgfx::setIndexBuffer(&tib, offset, cmd->ElemCount);
|
||||||
bgfx::submit(m_viewId, m_program);
|
bgfx::submit(m_viewId, m_program);
|
||||||
|
|
Loading…
Reference in a new issue