Skip to content

Commit

Permalink
Refactor|Renderer|Client: Use GLState for blending parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Dec 23, 2015
1 parent 3122eb8 commit 1ba7609
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 45 deletions.
6 changes: 3 additions & 3 deletions doomsday/apps/client/src/gl/gl_main.cpp
Expand Up @@ -370,7 +370,7 @@ void GL_Init2DState()
.setDepthTest(false)
.apply();

glDisable(GL_TEXTURE_1D);
//glDisable(GL_TEXTURE_1D);
glDisable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_CUBE_MAP);

Expand All @@ -397,13 +397,13 @@ void GL_Init2DState()
glFogfv(GL_FOG_COLOR, fogParams.fogColor);
}

void GL_SwitchTo3DState(dd_bool push_state, viewport_t const *port, viewdata_t const *viewData)
void GL_SwitchTo3DState(dd_bool pushState, viewport_t const *port, viewdata_t const *viewData)
{
DENG2_ASSERT(port && viewData);
DENG_ASSERT_IN_MAIN_THREAD();
DENG_ASSERT_GL_CONTEXT_ACTIVE();

if(push_state)
if(pushState)
{
// Push the 2D matrices on the stack.
glMatrixMode(GL_PROJECTION);
Expand Down
6 changes: 3 additions & 3 deletions doomsday/apps/client/src/gl/sys_opengl.cpp
Expand Up @@ -303,7 +303,7 @@ void Sys_GLConfigureDefaultState(void)
.setDepthTest(false)
.setDepthFunc(de::gl::Less);

glDisable(GL_TEXTURE_1D);
//glDisable(GL_TEXTURE_1D);
glDisable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_CUBE_MAP);

Expand Down Expand Up @@ -340,8 +340,8 @@ void Sys_GLConfigureDefaultState(void)
#endif

// Alpha blending is a go!
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glEnable(GL_BLEND);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glEnable(GL_ALPHA_TEST);
//glAlphaFunc(GL_GREATER, 0);

Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/render/fx/postprocessing.cpp
Expand Up @@ -207,7 +207,7 @@ DENG2_PIMPL(PostProcessing)

//glEnable(GL_ALPHA_TEST);
glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
//glEnable(GL_BLEND);
}
};

Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/render/fx/resize.cpp
Expand Up @@ -159,7 +159,7 @@ DENG2_PIMPL(Resize)

//glEnable(GL_ALPHA_TEST);
glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
//glEnable(GL_BLEND);
}
};

Expand Down
64 changes: 34 additions & 30 deletions doomsday/apps/client/src/render/rend_main.cpp
Expand Up @@ -3818,7 +3818,7 @@ static void pushGLStateForPass(DrawMode mode, TexUnitMap &texUnitMap)
glEnable(GL_FOG);
}
// All of the surfaces are opaque.
glDisable(GL_BLEND);
GLState::current().setBlend(false).apply();
break;

case DM_LIGHT_MOD_TEXTURE:
Expand Down Expand Up @@ -3848,7 +3848,7 @@ static void pushGLStateForPass(DrawMode mode, TexUnitMap &texUnitMap)
glEnable(GL_FOG);
}
// All of the surfaces are opaque.
glDisable(GL_BLEND);
GLState::current().setBlend(false).apply();
break;

case DM_FIRST_LIGHT:
Expand All @@ -3861,7 +3861,7 @@ static void pushGLStateForPass(DrawMode mode, TexUnitMap &texUnitMap)
GLState::current().setDepthTest(true).apply();
GLState::current().setDepthFunc(gl::Less).apply();
// All of the surfaces are opaque.
glDisable(GL_BLEND);
GLState::current().setBlend(false).apply();
break;

case DM_BLENDED_FIRST_LIGHT:
Expand All @@ -3875,8 +3875,8 @@ static void pushGLStateForPass(DrawMode mode, TexUnitMap &texUnitMap)
GLState::current().setDepthTest(true).apply();
GLState::current().setDepthFunc(gl::LessOrEqual).apply();
// All of the surfaces are opaque.
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
GLState::current().setBlend(true).apply();
GLState::current().setBlendFunc(gl::One, gl::One).apply();
break;

case DM_WITHOUT_TEXTURE:
Expand All @@ -3887,7 +3887,7 @@ static void pushGLStateForPass(DrawMode mode, TexUnitMap &texUnitMap)
GLState::current().setDepthTest(true).apply();
GLState::current().setDepthFunc(gl::Less).apply();
// All of the surfaces are opaque.
glDisable(GL_BLEND);
GLState::current().setBlend(false).apply();
break;

case DM_LIGHTS:
Expand All @@ -3906,7 +3906,7 @@ static void pushGLStateForPass(DrawMode mode, TexUnitMap &texUnitMap)
glFogfv(GL_FOG_COLOR, black);
}

glEnable(GL_BLEND);
GLState::current().setBlend(true).apply();
GL_BlendMode(BM_ADD);
break;

Expand All @@ -3922,8 +3922,9 @@ static void pushGLStateForPass(DrawMode mode, TexUnitMap &texUnitMap)
GLState::current().setDepthFunc(gl::LessOrEqual).apply();

// All of the surfaces are opaque.
glEnable(GL_BLEND);
glBlendFunc(GL_DST_COLOR, GL_ZERO);
GLState::current().setBlend(true).apply();
//glBlendFunc(GL_DST_COLOR, GL_ZERO);
GLState::current().setBlendFunc(gl::DestColor, gl::Zero).apply();
break;

case DM_UNBLENDED_TEXTURE_AND_DETAIL:
Expand All @@ -3935,7 +3936,7 @@ static void pushGLStateForPass(DrawMode mode, TexUnitMap &texUnitMap)
GLState::current().setDepthFunc(gl::Less).apply();

// All of the surfaces are opaque.
glDisable(GL_BLEND);
GLState::current().setBlend(false).apply();
// Fog is allowed.
if(fogParams.usingFog)
{
Expand All @@ -3952,8 +3953,9 @@ static void pushGLStateForPass(DrawMode mode, TexUnitMap &texUnitMap)
GLState::current().setDepthFunc(gl::LessOrEqual).apply();

// All of the surfaces are opaque.
glEnable(GL_BLEND);
glBlendFunc(GL_DST_COLOR, GL_ZERO);
GLState::current().setBlend(true).apply();
//glBlendFunc(GL_DST_COLOR, GL_ZERO);
GLState::current().setBlendFunc(gl::DestColor, gl::Zero).apply();
break;

case DM_ALL_DETAILS:
Expand All @@ -3966,8 +3968,9 @@ static void pushGLStateForPass(DrawMode mode, TexUnitMap &texUnitMap)
GLState::current().setDepthFunc(gl::LessOrEqual).apply();

// All of the surfaces are opaque.
glEnable(GL_BLEND);
glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
GLState::current().setBlend(true).apply();
//glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
GLState::current().setBlendFunc(gl::DestColor, gl::SrcColor).apply();
// Use fog to fade the details, if fog is enabled.
if(fogParams.usingFog)
{
Expand All @@ -3988,8 +3991,9 @@ static void pushGLStateForPass(DrawMode mode, TexUnitMap &texUnitMap)
GLState::current().setDepthFunc(gl::LessOrEqual).apply();

// All of the surfaces are opaque.
glEnable(GL_BLEND);
glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
GLState::current().setBlend(true).apply();
//glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
GLState::current().setBlendFunc(gl::DestColor, gl::SrcColor).apply();
// Use fog to fade the details, if fog is enabled.
if(fogParams.usingFog)
{
Expand All @@ -4015,7 +4019,7 @@ static void pushGLStateForPass(DrawMode mode, TexUnitMap &texUnitMap)
glEnable(GL_FOG);
glFogfv(GL_FOG_COLOR, fogParams.fogColor);
}
glEnable(GL_BLEND);
GLState::current().setBlend(true).apply();
GL_BlendMode(BM_NORMAL);
break;

Expand All @@ -4034,7 +4038,7 @@ static void pushGLStateForPass(DrawMode mode, TexUnitMap &texUnitMap)
glEnable(GL_FOG);
glFogfv(GL_FOG_COLOR, black);
}
glEnable(GL_BLEND);
GLState::current().setBlend(true).apply();
GL_BlendMode(BM_ADD); // Purely additive.
break;

Expand All @@ -4054,7 +4058,7 @@ static void pushGLStateForPass(DrawMode mode, TexUnitMap &texUnitMap)
glEnable(GL_FOG);
glFogfv(GL_FOG_COLOR, black);
}
glEnable(GL_BLEND);
GLState::current().setBlend(true).apply();
GL_BlendMode(BM_ADD); // Purely additive.
break;

Expand Down Expand Up @@ -4085,7 +4089,7 @@ static void popGLStateForPass(DrawMode mode)
{
glDisable(GL_FOG);
}
glEnable(GL_BLEND);
GLState::current().setBlend(true).apply();
break;

case DM_LIGHT_MOD_TEXTURE:
Expand All @@ -4098,28 +4102,28 @@ static void popGLStateForPass(DrawMode mode)
{
glDisable(GL_FOG);
}
glEnable(GL_BLEND);
GLState::current().setBlend(true).apply();
break;

case DM_FIRST_LIGHT:
GL_ModulateTexture(1);
GLState::current().setAlphaTest(true).apply();
GLState::current().setDepthTest(false).apply();
glEnable(GL_BLEND);
GLState::current().setBlend(true).apply();
break;

case DM_BLENDED_FIRST_LIGHT:
GL_ModulateTexture(1);
GLState::current().setDepthTest(false).apply();
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GLState::current().setBlendFunc(gl::SrcAlpha, gl::OneMinusSrcAlpha).apply();
break;

case DM_WITHOUT_TEXTURE:
GL_SelectTexUnits(1);
GL_ModulateTexture(1);
GLState::current().setAlphaTest(true).apply();
GLState::current().setDepthTest(false).apply();
glEnable(GL_BLEND);
GLState::current().setBlend(true).apply();
break;

case DM_LIGHTS:
Expand All @@ -4136,13 +4140,13 @@ static void popGLStateForPass(DrawMode mode)
case DM_BLENDED_MOD_TEXTURE:
GLState::current().setAlphaTest(true).apply();
GLState::current().setDepthTest(false).apply();
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GLState::current().setBlendFunc(gl::SrcAlpha, gl::OneMinusSrcAlpha).apply();
break;

case DM_UNBLENDED_TEXTURE_AND_DETAIL:
GLState::current().setAlphaTest(true).apply();
GLState::current().setDepthTest(false).apply();
glEnable(GL_BLEND);
GLState::current().setBlend(true).apply();
if(fogParams.usingFog)
{
glDisable(GL_FOG);
Expand All @@ -4152,14 +4156,14 @@ static void popGLStateForPass(DrawMode mode)
case DM_UNBLENDED_MOD_TEXTURE_AND_DETAIL:
GLState::current().setAlphaTest(true).apply();
GLState::current().setDepthTest(false).apply();
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GLState::current().setBlendFunc(gl::SrcAlpha, gl::OneMinusSrcAlpha).apply();
break;

case DM_ALL_DETAILS:
GL_ModulateTexture(1);
GLState::current().setAlphaTest(true).apply();
GLState::current().setDepthTest(false).apply();
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GLState::current().setBlendFunc(gl::SrcAlpha, gl::OneMinusSrcAlpha).apply();
if(fogParams.usingFog)
{
glDisable(GL_FOG);
Expand All @@ -4171,7 +4175,7 @@ static void popGLStateForPass(DrawMode mode)
GL_ModulateTexture(1);
GLState::current().setAlphaTest(true).apply();
GLState::current().setDepthTest(false).apply();
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GLState::current().setBlendFunc(gl::SrcAlpha, gl::OneMinusSrcAlpha).apply();
if(fogParams.usingFog)
{
glDisable(GL_FOG);
Expand Down Expand Up @@ -4575,7 +4579,7 @@ static void drawAllLists(Map &map)
glDisable(GL_TEXTURE_2D);

// The draw lists do not modify these states -ds
glEnable(GL_BLEND);
GLState::current().setBlend(true).apply();
GLState::current().setDepthWrite(true).apply();
GLState::current().setDepthTest(true).apply();
GLState::current().setDepthFunc(gl::Less).apply();
Expand Down
6 changes: 4 additions & 2 deletions doomsday/apps/client/src/ui/infine/finalepagewidget.cpp
Expand Up @@ -134,14 +134,16 @@ void FinalePageWidget::draw() const
}
else
{
glDisable(GL_BLEND);
//glDisable(GL_BLEND);
GLState::current().setBlend(false).apply();
}

GL_DrawRectf2TextureColor(0, 0, SCREENWIDTH, SCREENHEIGHT, 64, 64,
topColor, topAlpha, bottomColor, bottomAlpha);

GL_SetNoTexture();
glEnable(GL_BLEND);
//glEnable(GL_BLEND);
GLState::current().setBlend(true).apply();
}
}

Expand Down
9 changes: 7 additions & 2 deletions doomsday/apps/client/src/ui/ui_main.cpp
Expand Up @@ -21,6 +21,7 @@
#include "ui/ui_main.h"

#include <cmath>
#include <de/GLState>
#include <doomsday/console/cmd.h>
#include <doomsday/filesys/fs_util.h>
#include "clientapp.h"
Expand Down Expand Up @@ -363,14 +364,17 @@ void UI_DrawDDBackground(Point2Raw const &origin, Size2Raw const &dimensions, fl
GL_BindTexture(&ms.texture(MTU_PRIMARY));
*/

GLState::push();

glDisable(GL_TEXTURE_2D);
if(alpha < 1.0)
{
GL_BlendMode(BM_NORMAL);
}
else
{
glDisable(GL_BLEND);
//glDisable(GL_BLEND);
GLState::current().setBlend(false).apply();
}

glColor4f(0, 0, 0, alpha);
Expand All @@ -390,7 +394,8 @@ void UI_DrawDDBackground(Point2Raw const &origin, Size2Raw const &dimensions, fl
glVertex2f(0, origin.y + dimensions.height);
glEnd();

glEnable(GL_BLEND);
//glEnable(GL_BLEND);
GLState::pop().apply();
glDisable(GL_TEXTURE_2D);
}

Expand Down
9 changes: 6 additions & 3 deletions doomsday/apps/client/src/ui/widgets/busywidget.cpp
Expand Up @@ -135,8 +135,11 @@ void BusyWidget::drawContent()
if(d->haveTransitionFrame())
{
//glDisable(GL_ALPHA_TEST); /// @todo get rid of these
GLState::push().setAlphaTest(false).apply();
glDisable(GL_BLEND);
//glDisable(GL_BLEND);
GLState::push()
.setAlphaTest(false)
.setBlend(false)
.apply();
glEnable(GL_TEXTURE_2D);

// Draw the texture.
Expand All @@ -149,7 +152,7 @@ void BusyWidget::drawContent()
GLState::pop().apply();

//glEnable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
//glEnable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
}
}
Expand Down

0 comments on commit 1ba7609

Please sign in to comment.