Move EnableDepthTest functionality into a bool alpha_blend var on ImmediateDraw.

This commit is contained in:
Dr. Chat 2016-02-16 18:24:37 -06:00
parent e77af94c7c
commit 253e164753
4 changed files with 14 additions and 22 deletions

View File

@ -228,6 +228,14 @@ void GLImmediateDrawer::Draw(const ImmediateDraw& draw) {
glDisable(GL_SCISSOR_TEST); glDisable(GL_SCISSOR_TEST);
} }
if (draw.alpha_blend) {
glEnablei(GL_BLEND, 0);
glBlendEquationi(0, GL_FUNC_ADD);
glBlendFunci(0, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
} else {
glDisablei(GL_BLEND, 0);
}
if (draw.texture_handle) { if (draw.texture_handle) {
glBindTextureUnit(0, static_cast<GLuint>(draw.texture_handle)); glBindTextureUnit(0, static_cast<GLuint>(draw.texture_handle));
} else { } else {
@ -270,16 +278,6 @@ 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 gl
} // namespace ui } // namespace ui
} // namespace xe } // namespace xe

View File

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

View File

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

View File

@ -87,6 +87,9 @@ struct ImmediateDraw {
bool scissor = false; bool scissor = false;
// Scissoring region in framebuffer pixels as (x, y, w, h). // Scissoring region in framebuffer pixels as (x, y, w, h).
int scissor_rect[4] = {0}; int scissor_rect[4] = {0};
// Blends this draw with the background depending on its alpha (if true).
bool alpha_blend = true;
}; };
class ImmediateDrawer { class ImmediateDrawer {
@ -113,8 +116,6 @@ class ImmediateDrawer {
// Ends drawing in immediate mode and flushes contents. // Ends drawing in immediate mode and flushes contents.
virtual void End() = 0; virtual void End() = 0;
virtual void EnableAlphaTest(bool enable) = 0;
protected: protected:
ImmediateDrawer(GraphicsContext* graphics_context) ImmediateDrawer(GraphicsContext* graphics_context)
: graphics_context_(graphics_context) {} : graphics_context_(graphics_context) {}