GLState: Remove 'BlendNone' mode in favor of disabling blending alltogether

This commit is contained in:
Jonas Kulla 2014-07-20 13:17:12 +02:00
parent 7ce747d34d
commit 27b7815f52
6 changed files with 30 additions and 23 deletions

View File

@ -166,9 +166,9 @@ struct BitmapPrivate
void blitQuad(Quad &quad) void blitQuad(Quad &quad)
{ {
glState.blendMode.pushSet(BlendNone); glState.blend.pushSet(false);
quad.draw(); quad.draw();
glState.blendMode.pop(); glState.blend.pop();
} }
void fillRect(const IntRect &rect, void fillRect(const IntRect &rect,
@ -540,7 +540,7 @@ void Bitmap::blur()
BlurShader::HPass &pass1 = shader.pass1; BlurShader::HPass &pass1 = shader.pass1;
BlurShader::VPass &pass2 = shader.pass2; BlurShader::VPass &pass2 = shader.pass2;
glState.blendMode.pushSet(BlendNone); glState.blend.pushSet(false);
glState.viewport.pushSet(IntRect(0, 0, width(), height())); glState.viewport.pushSet(IntRect(0, 0, width(), height()));
TEX::bind(p->gl.tex); TEX::bind(p->gl.tex);
@ -562,7 +562,7 @@ void Bitmap::blur()
quad.draw(); quad.draw();
glState.viewport.pop(); glState.viewport.pop();
glState.blendMode.pop(); glState.blend.pop();
shState->texPool().release(auxTex); shState->texPool().release(auxTex);
@ -959,11 +959,8 @@ void Bitmap::drawText(const IntRect &rect, const char *str, int align)
p->bindFBO(); p->bindFBO();
p->pushSetViewport(shader); p->pushSetViewport(shader);
glState.blendMode.pushSet(BlendNone); p->blitQuad(quad);
quad.draw();
glState.blendMode.pop();
p->popViewport(); p->popViewport();
} }

View File

@ -31,8 +31,6 @@ struct SDL_Color;
enum BlendType enum BlendType
{ {
BlendNone = -1, /* Only internal use */
BlendNormal = 0, BlendNormal = 0,
BlendAddition = 1, BlendAddition = 1,
BlendSubstraction = 2 BlendSubstraction = 2

View File

@ -26,6 +26,11 @@
#include <SDL_rect.h> #include <SDL_rect.h>
static void applyBool(GLenum state, bool mode)
{
mode ? gl.Enable(state) : gl.Disable(state);
}
void GLClearColor::apply(const Vec4 &value) void GLClearColor::apply(const Vec4 &value)
{ {
gl.ClearColor(value.x, value.y, value.z, value.w); 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) 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) void GLBlendMode::apply(const BlendType &value)
{ {
switch (value) switch (value)
{ {
case BlendNone :
gl.BlendEquation(GL_FUNC_ADD);
gl.BlendFunc(GL_ONE, GL_ZERO);
break;
case BlendNormal : case BlendNormal :
gl.BlendEquation(GL_FUNC_ADD); gl.BlendEquation(GL_FUNC_ADD);
gl.BlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 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) void GLViewport::apply(const IntRect &value)
{ {
gl.Viewport(value.x, value.y, value.w, value.h); gl.Viewport(value.x, value.y, value.w, value.h);
@ -102,11 +107,11 @@ GLState::Caps::Caps()
GLState::GLState() GLState::GLState()
{ {
gl.Enable(GL_BLEND);
gl.Disable(GL_DEPTH_TEST); gl.Disable(GL_DEPTH_TEST);
clearColor.init(Vec4(0, 0, 0, 1)); clearColor.init(Vec4(0, 0, 0, 1));
blendMode.init(BlendNormal); blendMode.init(BlendNormal);
blend.init(true);
scissorTest.init(false); scissorTest.init(false);
scissorBox.init(IntRect(0, 0, 640, 480)); scissorBox.init(IntRect(0, 0, 640, 480));
program.init(0); program.init(0);

View File

@ -95,6 +95,11 @@ class GLBlendMode : public GLProperty<BlendType>
void apply(const BlendType &value); void apply(const BlendType &value);
}; };
class GLBlend : public GLProperty<bool>
{
void apply(const bool &value);
};
class GLViewport : public GLProperty<IntRect> class GLViewport : public GLProperty<IntRect>
{ {
void apply(const IntRect &value); void apply(const IntRect &value);
@ -113,6 +118,7 @@ public:
GLScissorBox scissorBox; GLScissorBox scissorBox;
GLScissorTest scissorTest; GLScissorTest scissorTest;
GLBlendMode blendMode; GLBlendMode blendMode;
GLBlend blend;
GLViewport viewport; GLViewport viewport;
GLProgram program; GLProgram program;

View File

@ -180,11 +180,11 @@ public:
TEX::bind(pp.backBuffer().tex); TEX::bind(pp.backBuffer().tex);
glState.blendMode.pushSet(BlendNone); glState.blend.pushSet(false);
screenQuad.draw(); screenQuad.draw();
glState.blendMode.pop(); glState.blend.pop();
} }
#ifdef RGSS2 #ifdef RGSS2
@ -627,7 +627,7 @@ void Graphics::transition(int duration,
shader.setTexSize(p->scRes); shader.setTexSize(p->scRes);
} }
glState.blendMode.pushSet(BlendNone); glState.blend.pushSet(false);
for (int i = 0; i < duration; ++i) for (int i = 0; i < duration; ++i)
{ {
@ -670,7 +670,7 @@ void Graphics::transition(int duration,
p->swapGLBuffer(); p->swapGLBuffer();
} }
glState.blendMode.pop(); glState.blend.pop();
delete transMap; delete transMap;

View File

@ -435,12 +435,13 @@ struct WindowPrivate
/* We need to blit the background without blending, /* We need to blit the background without blending,
* because we want to retain its correct alpha value. * because we want to retain its correct alpha value.
* Otherwise it would be mutliplied by the backgrounds 0 alpha */ * Otherwise it would be mutliplied by the backgrounds 0 alpha */
glState.blendMode.pushSet(BlendNone); glState.blend.pushSet(false);
baseQuadArray.draw(0, backgroundVert.count); baseQuadArray.draw(0, backgroundVert.count);
/* Now draw the rest (ie. the frame) with blending */ /* 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); baseQuadArray.draw(backgroundVert.count, baseQuadArray.count()-backgroundVert.count);