Skip to content

Commit

Permalink
Renderer: Cleanup
Browse files Browse the repository at this point in the history
Now that drawing is handled in specific places, it is unnecessary to
apply GLState changes all the time.
  • Loading branch information
skyjake committed Apr 24, 2017
1 parent 193d26d commit 72ac96f
Show file tree
Hide file tree
Showing 27 changed files with 253 additions and 313 deletions.
13 changes: 4 additions & 9 deletions doomsday/apps/client/src/gl/dgl_common.cpp
Expand Up @@ -491,7 +491,7 @@ DENG_EXTERN_C void DGL_SetScissor(RectRaw const *rect)
rect->size.width, rect->size.height),
Rectanglei::fromSize(game.rule().recti().size()));

GLState::current().setNormalizedScissor(norm).apply();
GLState::current().setNormalizedScissor(norm);
}

#undef DGL_SetScissor2
Expand Down Expand Up @@ -730,9 +730,6 @@ void DGL_PushState(void)
void DGL_PopState(void)
{
GLState::pop();

// Make sure the restored state is immediately in effect.
GLState::current().apply();
}

#undef DGL_Enable
Expand Down Expand Up @@ -810,7 +807,7 @@ void DGL_Disable(int cap)
break;

case DGL_SCISSOR_TEST:
GLState::current().clearScissor().apply();
GLState::current().clearScissor();
break;

case DGL_LINE_SMOOTH:
Expand All @@ -834,8 +831,7 @@ void DGL_BlendOp(int op)
{
GLState::current().setBlendOp(op == DGL_SUBTRACT ? gl::Subtract :
op == DGL_REVERSE_SUBTRACT ? gl::ReverseSubtract :
gl::Add)
.apply();
gl::Add);
}

#undef DGL_BlendFunc
Expand All @@ -862,8 +858,7 @@ void DGL_BlendFunc(int param1, int param2)
param2 == DGL_ONE_MINUS_SRC_ALPHA ? gl::OneMinusSrcAlpha :
param2 == DGL_DST_ALPHA ? gl::DestAlpha :
param2 == DGL_ONE_MINUS_DST_ALPHA ? gl::OneMinusDestAlpha :
gl::Zero)
.apply();
gl::Zero);
}

#undef DGL_BlendMode
Expand Down
3 changes: 3 additions & 0 deletions doomsday/apps/client/src/gl/dgl_draw.cpp
Expand Up @@ -288,6 +288,9 @@ struct DGLDrawState
glUnbindArrays();
}
gl->shader.endUse();

// Buffers are single-use.
gl->buffer.clear();
}
};

Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/gl/gl_draw.cpp
Expand Up @@ -393,7 +393,7 @@ DENG_EXTERN_C void GL_EndBorderedProjection(dgl_borderedprojectionstate_t* bp)
DENG_ASSERT_IN_MAIN_THREAD();
DENG_ASSERT_GL_CONTEXT_ACTIVE();

GLState::pop().apply();
GLState::pop();

DGL_MatrixMode(DGL_MODELVIEW);
DGL_PopMatrix();
Expand Down
33 changes: 11 additions & 22 deletions doomsday/apps/client/src/gl/gl_main.cpp
Expand Up @@ -352,8 +352,7 @@ void GL_Init2DState()
// Here we configure the OpenGL state and set the projection matrix.
GLState::current()
.setCull(gl::None)
.setDepthTest(false)
.apply();
.setDepthTest(false);

//glDisable(GL_TEXTURE_1D);
DGL_Disable(DGL_TEXTURE_2D);
Expand Down Expand Up @@ -508,62 +507,52 @@ void GL_BlendMode(blendmode_t mode)
{
case BM_ZEROALPHA:
GLState::current().setBlendOp(gl::Add)
.setBlendFunc(gl::One, gl::Zero)
.apply();
.setBlendFunc(gl::One, gl::Zero);
break;

case BM_ADD:
GLState::current().setBlendOp(gl::Add)
.setBlendFunc(gl::SrcAlpha, gl::One)
.apply();
.setBlendFunc(gl::SrcAlpha, gl::One);
break;

case BM_DARK:
GLState::current().setBlendOp(gl::Add)
.setBlendFunc(gl::DestColor, gl::OneMinusSrcAlpha)
.apply();
.setBlendFunc(gl::DestColor, gl::OneMinusSrcAlpha);
break;

case BM_SUBTRACT:
GLState::current().setBlendOp(gl::Subtract)
.setBlendFunc(gl::One, gl::SrcAlpha)
.apply();
.setBlendFunc(gl::One, gl::SrcAlpha);
break;

case BM_ALPHA_SUBTRACT:
GLState::current().setBlendOp(gl::Subtract)
.setBlendFunc(gl::SrcAlpha, gl::One)
.apply();
.setBlendFunc(gl::SrcAlpha, gl::One);
break;

case BM_REVERSE_SUBTRACT:
GLState::current().setBlendOp(gl::ReverseSubtract)
.setBlendFunc(gl::SrcAlpha, gl::One)
.apply();
.setBlendFunc(gl::SrcAlpha, gl::One);
break;

case BM_MUL:
GLState::current().setBlendOp(gl::Add)
.setBlendFunc(gl::Zero, gl::SrcColor)
.apply();
.setBlendFunc(gl::Zero, gl::SrcColor);
break;

case BM_INVERSE:
GLState::current().setBlendOp(gl::Add)
.setBlendFunc(gl::OneMinusDestColor, gl::OneMinusSrcColor)
.apply();
.setBlendFunc(gl::OneMinusDestColor, gl::OneMinusSrcColor);
break;

case BM_INVERSE_MUL:
GLState::current().setBlendOp(gl::Add)
.setBlendFunc(gl::Zero, gl::OneMinusSrcColor)
.apply();
.setBlendFunc(gl::Zero, gl::OneMinusSrcColor);
break;

default:
GLState::current().setBlendOp(gl::Add)
.setBlendFunc(gl::SrcAlpha, gl::OneMinusSrcAlpha)
.apply();
.setBlendFunc(gl::SrcAlpha, gl::OneMinusSrcAlpha);
break;
}
}
Expand Down
3 changes: 1 addition & 2 deletions doomsday/apps/client/src/gl/sys_opengl.cpp
Expand Up @@ -294,8 +294,7 @@ void Sys_GLConfigureDefaultState(void)

// Configure the default GLState (bottom of the stack).
de::GLState::current()
.setBlendFunc(de::gl::SrcAlpha, de::gl::OneMinusSrcAlpha)
.apply();
.setBlendFunc(de::gl::SrcAlpha, de::gl::OneMinusSrcAlpha);
}

static de::String omitGLPrefix(de::String str)
Expand Down
9 changes: 4 additions & 5 deletions doomsday/apps/client/src/render/billboard.cpp
Expand Up @@ -560,7 +560,7 @@ void Rend_DrawSprite(vissprite_t const &spr)
!(parm.blendMode == BM_NORMAL || parm.blendMode == BM_ZEROALPHA))
{
restoreZ = true;
GLState::current().setDepthWrite(false).apply();
GLState::current().setDepthWrite(false);
}

dgl_vertex_t vs[4], *v = vs;
Expand Down Expand Up @@ -607,8 +607,7 @@ void Rend_DrawSprite(vissprite_t const &spr)
// Draw the vlight vectors, for debug.
GLState::push()
.setDepthTest(false)
.setCull(gl::None)
.apply();
.setCull(gl::None);

DGL_MatrixMode(DGL_MODELVIEW);
DGL_PushMatrix();
Expand All @@ -628,7 +627,7 @@ void Rend_DrawSprite(vissprite_t const &spr)
DGL_MatrixMode(DGL_MODELVIEW);
DGL_PopMatrix();

GLState::pop().apply();
GLState::pop();
}

// Need to restore the original modelview matrix?
Expand All @@ -646,7 +645,7 @@ void Rend_DrawSprite(vissprite_t const &spr)
// Enable Z-writing again?
if(restoreZ)
{
GLState::current().setDepthWrite(true).apply();
GLState::current().setDepthWrite(true);
}
}

Expand Down
5 changes: 2 additions & 3 deletions doomsday/apps/client/src/render/cameralensfx.cpp
Expand Up @@ -116,8 +116,7 @@ void LensFx_Draw(int playerNum)

// Now that we've resolved multisampling, further rendering must be done without it.
GLState::push()
.setTarget(player.viewCompositor().gameView().resolvedFramebuffer())
.apply();
.setTarget(player.viewCompositor().gameView().resolvedFramebuffer());

auto const &effects = player.fxStack().effects;

Expand Down Expand Up @@ -145,7 +144,7 @@ void LensFx_Draw(int playerNum)
effects.at(i)->endFrame();
}

GLState::pop().apply();
GLState::pop();
}

void LensFx_MarkLightVisibleInFrame(IPointLightSource const &lightSource)
Expand Down
3 changes: 1 addition & 2 deletions doomsday/apps/client/src/render/fx/bloom.cpp
Expand Up @@ -138,8 +138,7 @@ DENG2_PIMPL(Bloom)
break;
}


GLState::pop().apply();
GLState::pop();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/render/fx/lensflares.cpp
Expand Up @@ -550,7 +550,7 @@ void LensFlares::draw()

d->drawable.draw();

GLState::pop().apply();
GLState::pop();
}

void LensFlares::consoleRegister()
Expand Down
4 changes: 2 additions & 2 deletions doomsday/apps/client/src/render/modelrenderer.cpp
Expand Up @@ -285,7 +285,7 @@ void ModelRenderer::render(vissprite_t const &spr)
// Draw the model using the current animation state.
GLState::push().setCull(p.model->cull);
d->draw(p);
GLState::pop().apply();
GLState::pop();
}

void ModelRenderer::render(vispsprite_t const &pspr, mobj_t const *playerMobj)
Expand All @@ -312,7 +312,7 @@ void ModelRenderer::render(vispsprite_t const &pspr, mobj_t const *playerMobj)

GLState::push().setCull(p.model->cull);
d->draw(p);
GLState::pop().apply();
GLState::pop();
}

//---------------------------------------------------------------------------------------
Expand Down
6 changes: 2 additions & 4 deletions doomsday/apps/client/src/render/rend_font.cpp
Expand Up @@ -825,8 +825,7 @@ static void drawFlash(Point2Raw const *origin, Size2Raw const *size, bool bright
gl::ClampToEdge, gl::ClampToEdge);

GLState::current().setBlendFunc(bright? gl::SrcAlpha : gl::Zero,
bright? gl::One : gl::OneMinusSrcAlpha)
.apply();
bright? gl::One : gl::OneMinusSrcAlpha);

DGL_Begin(DGL_QUADS);
DGL_TexCoord2f(0, 0, 0);
Expand All @@ -839,8 +838,7 @@ static void drawFlash(Point2Raw const *origin, Size2Raw const *size, bool bright
DGL_Vertex2f(x, y + h);
DGL_End();

GLState::current().setBlendFunc(gl::SrcAlpha, gl::OneMinusSrcAlpha)
.apply();
GLState::current().setBlendFunc(gl::SrcAlpha, gl::OneMinusSrcAlpha);
}

/**
Expand Down
6 changes: 2 additions & 4 deletions doomsday/apps/client/src/render/rend_halo.cpp
Expand Up @@ -102,17 +102,15 @@ void H_SetupState(bool dosetup)
{
GLState::current()
.setDepthWrite(false)
.setDepthTest(false)
.apply();
.setDepthTest(false);
GL_BlendMode(BM_ADD);
}
else
{
GL_BlendMode(BM_NORMAL);
GLState::current()
.setDepthWrite(true)
.setDepthTest(true)
.apply();
.setDepthTest(true);
}
}

Expand Down

0 comments on commit 72ac96f

Please sign in to comment.