Skip to content

Commit

Permalink
Refactor|GL|libgui: Renamed GLState::top() to GLState::current()
Browse files Browse the repository at this point in the history
“top” and “pop” are too easy to confuse.
  • Loading branch information
skyjake committed Dec 2, 2013
1 parent 90f87a9 commit c89604c
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 88 deletions.
56 changes: 28 additions & 28 deletions doomsday/client/src/gl/dgl_common.cpp
Expand Up @@ -371,7 +371,7 @@ DENG_EXTERN_C void DGL_SetScissor(RectRaw const *rect)
DENG_ASSERT_IN_MAIN_THREAD();
DENG_ASSERT_GL_CONTEXT_ACTIVE();

GLState::top().setNormalizedScissor(
GLState::current().setNormalizedScissor(
ClientWindow::main().game().normalizedRect(
Rectanglei(rect->origin.x, rect->origin.y,
rect->size.width, rect->size.height))).apply();
Expand Down Expand Up @@ -403,7 +403,7 @@ boolean DGL_GetIntegerv(int name, int *v)

case DGL_SCISSOR_TEST:
//glGetIntegerv(GL_SCISSOR_TEST, (GLint*) v);
*(GLint *) v = GLState::top().scissor();
*(GLint *) v = GLState::current().scissor();
break;

case DGL_FOG:
Expand Down Expand Up @@ -573,7 +573,7 @@ void DGL_PopState(void)
GLState::pop();

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

#undef DGL_Enable
Expand Down Expand Up @@ -633,7 +633,7 @@ void DGL_Disable(int cap)

case DGL_SCISSOR_TEST:
//glDisable(GL_SCISSOR_TEST);
GLState::top().clearScissor().apply();
GLState::current().clearScissor().apply();
break;

case DGL_LINE_SMOOTH:
Expand All @@ -652,10 +652,10 @@ void DGL_Disable(int cap)
#undef DGL_BlendOp
void DGL_BlendOp(int op)
{
GLState::top().setBlendOp(op == DGL_SUBTRACT ? gl::Subtract :
op == DGL_REVERSE_SUBTRACT ? gl::ReverseSubtract :
gl::Add)
.apply();
GLState::current().setBlendOp(op == DGL_SUBTRACT ? gl::Subtract :
op == DGL_REVERSE_SUBTRACT ? gl::ReverseSubtract :
gl::Add)
.apply();
}

#undef DGL_BlendFunc
Expand All @@ -664,26 +664,26 @@ void DGL_BlendFunc(int param1, int param2)
DENG_ASSERT_IN_MAIN_THREAD();
DENG_ASSERT_GL_CONTEXT_ACTIVE();

GLState::top().setBlendFunc(param1 == DGL_ZERO ? gl::Zero :
param1 == DGL_ONE ? gl::One :
param1 == DGL_DST_COLOR ? gl::DestColor :
param1 == DGL_ONE_MINUS_DST_COLOR ? gl::OneMinusDestColor :
param1 == DGL_SRC_ALPHA ? gl::SrcAlpha :
param1 == DGL_ONE_MINUS_SRC_ALPHA ? gl::OneMinusSrcAlpha :
param1 == DGL_DST_ALPHA ? gl::DestAlpha :
param1 == DGL_ONE_MINUS_DST_ALPHA ? gl::OneMinusDestAlpha :
gl::Zero
,
param2 == DGL_ZERO ? gl::Zero :
param2 == DGL_ONE ? gl::One :
param2 == DGL_SRC_COLOR ? gl::SrcColor :
param2 == DGL_ONE_MINUS_SRC_COLOR ? gl::OneMinusSrcColor :
param2 == DGL_SRC_ALPHA ? gl::SrcAlpha :
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();
GLState::current().setBlendFunc(param1 == DGL_ZERO ? gl::Zero :
param1 == DGL_ONE ? gl::One :
param1 == DGL_DST_COLOR ? gl::DestColor :
param1 == DGL_ONE_MINUS_DST_COLOR ? gl::OneMinusDestColor :
param1 == DGL_SRC_ALPHA ? gl::SrcAlpha :
param1 == DGL_ONE_MINUS_SRC_ALPHA ? gl::OneMinusSrcAlpha :
param1 == DGL_DST_ALPHA ? gl::DestAlpha :
param1 == DGL_ONE_MINUS_DST_ALPHA ? gl::OneMinusDestAlpha :
gl::Zero
,
param2 == DGL_ZERO ? gl::Zero :
param2 == DGL_ONE ? gl::One :
param2 == DGL_SRC_COLOR ? gl::SrcColor :
param2 == DGL_ONE_MINUS_SRC_COLOR ? gl::OneMinusSrcColor :
param2 == DGL_SRC_ALPHA ? gl::SrcAlpha :
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();
}

#undef DGL_BlendMode
Expand Down
60 changes: 30 additions & 30 deletions doomsday/client/src/gl/gl_main.cpp
Expand Up @@ -719,63 +719,63 @@ void GL_BlendMode(blendmode_t mode)
switch(mode)
{
case BM_ZEROALPHA:
GLState::top().setBlendOp(gl::Add)
.setBlendFunc(gl::One, gl::Zero)
.apply();
GLState::current().setBlendOp(gl::Add)
.setBlendFunc(gl::One, gl::Zero)
.apply();
break;

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

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

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

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

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

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

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

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

default:
GLState::top().setBlendOp(gl::Add)
.setBlendFunc(gl::SrcAlpha, gl::OneMinusSrcAlpha)
.apply();
GLState::current().setBlendOp(gl::Add)
.setBlendFunc(gl::SrcAlpha, gl::OneMinusSrcAlpha)
.apply();
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/gl/sys_opengl.cpp
Expand Up @@ -597,7 +597,7 @@ void Sys_GLConfigureDefaultState(void)
glHint(GL_TEXTURE_COMPRESSION_HINT, GL_NICEST);

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

/**
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/fx/lensflares.cpp
Expand Up @@ -492,7 +492,7 @@ void LensFlares::draw()
d->uMvpMatrix = GL_GetProjectionMatrix() * Rend_GetModelViewMatrix(console());

// Depth information is required for occlusion.
GLTarget &target = GLState::top().target();
GLTarget &target = GLState::current().target();
GLTexture *depthTex = target.attachedTexture(GLTarget::Depth);
/**
* @todo Handle the situation when depth information is not available in the target.
Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/src/render/rend_font.cpp
Expand Up @@ -808,9 +808,9 @@ static void drawFlash(Point2Raw const *origin, Size2Raw const *size, bool bright
GL_BindTextureUnmanaged(GL_PrepareLSTexture(LST_DYNAMIC),
gl::ClampToEdge, gl::ClampToEdge);

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

glBegin(GL_QUADS);
glTexCoord2f(0, 0);
Expand All @@ -823,8 +823,8 @@ static void drawFlash(Point2Raw const *origin, Size2Raw const *size, bool bright
glVertex2f(x, y + h);
glEnd();

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

/**
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/ui/clientwindow.cpp
Expand Up @@ -647,7 +647,7 @@ void ClientWindow::canvasGLReady(Canvas &canvas)
d->gameUI->enable();

// Configure a viewport immediately.
GLState::top().setViewport(Rectangleui(0, 0, canvas.width(), canvas.height())).apply();
GLState::current().setViewport(Rectangleui(0, 0, canvas.width(), canvas.height())).apply();

LOG_DEBUG("GameWidget enabled");

Expand Down Expand Up @@ -698,7 +698,7 @@ void ClientWindow::canvasGLResized(Canvas &canvas)
Canvas::Size size = canvas.size();
LOG_TRACE("Canvas resized to ") << size.asText();

GLState::top().setViewport(Rectangleui(0, 0, size.x, size.y));
GLState::current().setViewport(Rectangleui(0, 0, size.x, size.y));

d->updateRootSize();
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/ui/widgets/busywidget.cpp
Expand Up @@ -125,7 +125,7 @@ void BusyWidget::drawContent()

if(!d->transitionTex.isNull())
{
GLState::top().apply();
GLState::current().apply();

glDisable(GL_ALPHA_TEST); /// @todo get rid of these
glDisable(GL_BLEND);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/ui/widgets/compositorwidget.cpp
Expand Up @@ -74,7 +74,7 @@ DENG_GUI_PIMPL(CompositorWidget)
}

Buffer *buf = buffers[nextBufIndex];
Vector2ui const size = GLState::top().target().size();
Vector2ui const size = GLState::current().target().size();
//qDebug() << "compositor" << nextBufIndex << "should be" << size.asText();
if(buf->texture.size() != size)
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/ui/widgets/documentwidget.cpp
Expand Up @@ -244,7 +244,7 @@ public Font::RichFormat::IStyle
uColor = Vector4f(1, 1, 1, self.visibleOpacity());

// Update the scissor for the text.
clippedTextState = GLState::top();
clippedTextState = GLState::current();
clippedTextState.setNormalizedScissor(self.normalizedContentRect());

drawable.draw();
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/ui/widgets/gamewidget.cpp
Expand Up @@ -120,7 +120,7 @@ GameWidget::GameWidget(String const &name)

void GameWidget::glApplyViewport(int x, int y, int width, int height)
{
GLState::top()
GLState::current()
.setNormalizedViewport(normalizedRect(Rectanglei(x, y, width, height)))
.apply();
}
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libgui/include/de/gui/glstate.h
Expand Up @@ -169,9 +169,9 @@ class LIBGUI_PUBLIC GLState
static void considerNativeStateUndefined();

/**
* Returns the current topmost state on the GL state stack.
* Returns the current (i.e., topmost) state on the GL state stack.
*/
static GLState &top();
static GLState &current();

/**
* Pushes a copy of the current state onto the current thread's GL state
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libgui/src/canvas.cpp
Expand Up @@ -449,7 +449,7 @@ void Canvas::notifyReady()
void Canvas::paintGL()
{
// Make sure any changes to the state stack become effective.
GLState::top().apply();
GLState::current().apply();

DENG2_FOR_AUDIENCE(GLDraw, i) i->canvasGLDraw(*this);
}
Expand Down
6 changes: 3 additions & 3 deletions doomsday/libgui/src/drawable.cpp
Expand Up @@ -476,7 +476,7 @@ void Drawable::draw() const
GLState const *currentState = 0;

// Make sure the GL state on the top of the stack is in effect.
GLState::top().apply();
GLState::current().apply();

DENG2_FOR_EACH_CONST(Instance::Buffers, i, d->buffers)
{
Expand All @@ -503,7 +503,7 @@ void Drawable::draw() const
{
// Use the current state from the stack.
currentState = 0;
GLState::top().apply();
GLState::current().apply();
}

// Ready to draw.
Expand All @@ -518,7 +518,7 @@ void Drawable::draw() const
if(currentState)
{
// We messed with the state; restore to what the stack says is current.
GLState::top().apply();
GLState::current().apply();
}
}

Expand Down
8 changes: 4 additions & 4 deletions doomsday/libgui/src/glstate.cpp
Expand Up @@ -607,7 +607,7 @@ void GLState::considerNativeStateUndefined()
currentTarget = 0;
}

GLState &GLState::top()
GLState &GLState::current()
{
DENG2_ASSERT(!stack.isEmpty());
return *stack.last();
Expand All @@ -616,14 +616,14 @@ GLState &GLState::top()
GLState &GLState::push()
{
// Duplicate the topmost state.
push(new GLState(top()));
return top();
push(new GLState(current()));
return current();
}

GLState &GLState::pop()
{
delete take();
return top();
return current();
}

void GLState::push(GLState *state)
Expand Down
8 changes: 4 additions & 4 deletions doomsday/libgui/src/gltarget.cpp
Expand Up @@ -417,7 +417,7 @@ QImage GLTarget::toImage() const
glReadPixels(0, 0, imgSize.x, imgSize.y, GL_BGRA, GL_UNSIGNED_BYTE,
(GLvoid *) img.constBits());
// Restore the stack's target.
GLState::top().target().glBind();
GLState::current().target().glBind();
return img;
}
return QImage();
Expand All @@ -440,7 +440,7 @@ void GLTarget::clear(Flags const &attachments)
(which & Depth? GL_DEPTH_BUFFER_BIT : 0) |
(which & Stencil? GL_STENCIL_BUFFER_BIT : 0));

GLState::top().target().glBind();
GLState::current().target().glBind();
}

void GLTarget::resize(Size const &size)
Expand All @@ -454,7 +454,7 @@ void GLTarget::resize(Size const &size)
d->texture->setUndefinedImage(size, d->texture->imageFormat());
}
d->resizeRenderBuffers(size);
GLState::top().target().glBind();
GLState::current().target().glBind();
}

GLTexture *GLTarget::attachedTexture(Flags const &attachment) const
Expand Down Expand Up @@ -487,7 +487,7 @@ void GLTarget::setActiveRect(Rectangleui const &rect, bool applyGLState)
{
// Forcibly update viewport and scissor (and other GL state).
GLState::considerNativeStateUndefined();
GLState::top().apply();
GLState::current().apply();
}
}

Expand Down

0 comments on commit c89604c

Please sign in to comment.