Add a flag to ImTextureID that disables alpha test

This commit is contained in:
Dr. Chat 2016-02-16 16:43:12 -06:00
parent 65d1ea0250
commit a8dfd6a21a
5 changed files with 26 additions and 1 deletions

View File

@ -270,6 +270,16 @@ void GLImmediateDrawer::End() {
}
}
void GLImmediateDrawer::EnableAlphaTest(bool enable) {
if (enable) {
glEnablei(GL_BLEND, 0);
glBlendEquationi(0, GL_FUNC_ADD);
glBlendFunci(0, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
} else {
glDisablei(GL_BLEND, 0);
}
}
} // namespace gl
} // namespace ui
} // namespace xe

View File

@ -37,6 +37,8 @@ class GLImmediateDrawer : public ImmediateDrawer {
void EndDrawBatch() override;
void End() override;
void EnableAlphaTest(bool enable);
private:
void InitializeShaders();

View File

@ -203,11 +203,16 @@ void ImGuiDrawer::RenderDrawLists(ImDrawData* data) {
for (int j = 0; j < cmd_list->CmdBuffer.size(); ++j) {
const auto& cmd = cmd_list->CmdBuffer[j];
if (reinterpret_cast<uintptr_t>(cmd.TextureId) & kIgnoreAlpha) {
drawer->EnableAlphaTest(false);
}
ImmediateDraw draw;
draw.primitive_type = ImmediatePrimitiveType::kTriangles;
draw.count = cmd.ElemCount;
draw.index_offset = index_offset;
draw.texture_handle = reinterpret_cast<uintptr_t>(cmd.TextureId);
draw.texture_handle =
reinterpret_cast<uintptr_t>(cmd.TextureId) & 0xFFFFFFFF;
draw.scissor = true;
draw.scissor_rect[0] = static_cast<int>(cmd.ClipRect.x);
draw.scissor_rect[1] = static_cast<int>(height - cmd.ClipRect.w);
@ -215,6 +220,10 @@ void ImGuiDrawer::RenderDrawLists(ImDrawData* data) {
draw.scissor_rect[3] = static_cast<int>(cmd.ClipRect.w - cmd.ClipRect.y);
drawer->Draw(draw);
if (reinterpret_cast<uintptr_t>(cmd.TextureId) & kIgnoreAlpha) {
drawer->EnableAlphaTest(true);
}
index_offset += cmd.ElemCount;
}

View File

@ -35,6 +35,8 @@ class ImGuiDrawer : public WindowListener {
ImGuiIO& GetIO();
static const uint64_t kIgnoreAlpha = (1ull << 32);
protected:
void Initialize();
void SetupFont();

View File

@ -113,6 +113,8 @@ class ImmediateDrawer {
// Ends drawing in immediate mode and flushes contents.
virtual void End() = 0;
virtual void EnableAlphaTest(bool enable) = 0;
protected:
ImmediateDrawer(GraphicsContext* graphics_context)
: graphics_context_(graphics_context) {}