From 27b7815f52b7527d98ff3ca128122408b4ab48fb Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Sun, 20 Jul 2014 13:17:12 +0200 Subject: [PATCH] GLState: Remove 'BlendNone' mode in favor of disabling blending alltogether --- src/bitmap.cpp | 13 +++++-------- src/etc.h | 2 -- src/glstate.cpp | 19 ++++++++++++------- src/glstate.h | 6 ++++++ src/graphics.cpp | 8 ++++---- src/window.cpp | 5 +++-- 6 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/bitmap.cpp b/src/bitmap.cpp index 7815114..cd10f01 100644 --- a/src/bitmap.cpp +++ b/src/bitmap.cpp @@ -166,9 +166,9 @@ struct BitmapPrivate void blitQuad(Quad &quad) { - glState.blendMode.pushSet(BlendNone); + glState.blend.pushSet(false); quad.draw(); - glState.blendMode.pop(); + glState.blend.pop(); } void fillRect(const IntRect &rect, @@ -540,7 +540,7 @@ void Bitmap::blur() BlurShader::HPass &pass1 = shader.pass1; BlurShader::VPass &pass2 = shader.pass2; - glState.blendMode.pushSet(BlendNone); + glState.blend.pushSet(false); glState.viewport.pushSet(IntRect(0, 0, width(), height())); TEX::bind(p->gl.tex); @@ -562,7 +562,7 @@ void Bitmap::blur() quad.draw(); glState.viewport.pop(); - glState.blendMode.pop(); + glState.blend.pop(); shState->texPool().release(auxTex); @@ -959,11 +959,8 @@ void Bitmap::drawText(const IntRect &rect, const char *str, int align) p->bindFBO(); p->pushSetViewport(shader); - glState.blendMode.pushSet(BlendNone); + p->blitQuad(quad); - quad.draw(); - - glState.blendMode.pop(); p->popViewport(); } diff --git a/src/etc.h b/src/etc.h index ff48a1f..04962fa 100644 --- a/src/etc.h +++ b/src/etc.h @@ -31,8 +31,6 @@ struct SDL_Color; enum BlendType { - BlendNone = -1, /* Only internal use */ - BlendNormal = 0, BlendAddition = 1, BlendSubstraction = 2 diff --git a/src/glstate.cpp b/src/glstate.cpp index af43198..613b55e 100644 --- a/src/glstate.cpp +++ b/src/glstate.cpp @@ -26,6 +26,11 @@ #include +static void applyBool(GLenum state, bool mode) +{ + mode ? gl.Enable(state) : gl.Disable(state); +} + void GLClearColor::apply(const Vec4 &value) { gl.ClearColor(value.x, value.y, value.z, value.w); @@ -52,18 +57,13 @@ void GLScissorBox::setIntersect(const IntRect &value) void GLScissorTest::apply(const bool &value) { - value ? gl.Enable(GL_SCISSOR_TEST) : gl.Disable(GL_SCISSOR_TEST); + applyBool(GL_SCISSOR_TEST, value); } void GLBlendMode::apply(const BlendType &value) { switch (value) { - case BlendNone : - gl.BlendEquation(GL_FUNC_ADD); - gl.BlendFunc(GL_ONE, GL_ZERO); - break; - case BlendNormal : gl.BlendEquation(GL_FUNC_ADD); gl.BlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, @@ -85,6 +85,11 @@ void GLBlendMode::apply(const BlendType &value) } } +void GLBlend::apply(const bool &value) +{ + applyBool(GL_BLEND, value); +} + void GLViewport::apply(const IntRect &value) { gl.Viewport(value.x, value.y, value.w, value.h); @@ -102,11 +107,11 @@ GLState::Caps::Caps() GLState::GLState() { - gl.Enable(GL_BLEND); gl.Disable(GL_DEPTH_TEST); clearColor.init(Vec4(0, 0, 0, 1)); blendMode.init(BlendNormal); + blend.init(true); scissorTest.init(false); scissorBox.init(IntRect(0, 0, 640, 480)); program.init(0); diff --git a/src/glstate.h b/src/glstate.h index 9f97fa1..8eb7fc0 100644 --- a/src/glstate.h +++ b/src/glstate.h @@ -95,6 +95,11 @@ class GLBlendMode : public GLProperty void apply(const BlendType &value); }; +class GLBlend : public GLProperty +{ + void apply(const bool &value); +}; + class GLViewport : public GLProperty { void apply(const IntRect &value); @@ -113,6 +118,7 @@ public: GLScissorBox scissorBox; GLScissorTest scissorTest; GLBlendMode blendMode; + GLBlend blend; GLViewport viewport; GLProgram program; diff --git a/src/graphics.cpp b/src/graphics.cpp index c158521..651af79 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -180,11 +180,11 @@ public: TEX::bind(pp.backBuffer().tex); - glState.blendMode.pushSet(BlendNone); + glState.blend.pushSet(false); screenQuad.draw(); - glState.blendMode.pop(); + glState.blend.pop(); } #ifdef RGSS2 @@ -627,7 +627,7 @@ void Graphics::transition(int duration, shader.setTexSize(p->scRes); } - glState.blendMode.pushSet(BlendNone); + glState.blend.pushSet(false); for (int i = 0; i < duration; ++i) { @@ -670,7 +670,7 @@ void Graphics::transition(int duration, p->swapGLBuffer(); } - glState.blendMode.pop(); + glState.blend.pop(); delete transMap; diff --git a/src/window.cpp b/src/window.cpp index 105ebef..344407e 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -435,12 +435,13 @@ struct WindowPrivate /* We need to blit the background without blending, * because we want to retain its correct alpha value. * Otherwise it would be mutliplied by the backgrounds 0 alpha */ - glState.blendMode.pushSet(BlendNone); + glState.blend.pushSet(false); baseQuadArray.draw(0, backgroundVert.count); /* Now draw the rest (ie. the frame) with blending */ - glState.blendMode.set(BlendNormal); + glState.blend.pop(); + glState.blendMode.pushSet(BlendNormal); baseQuadArray.draw(backgroundVert.count, baseQuadArray.count()-backgroundVert.count);