Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor|libgui: Streamlined GLState's interface somewhat
  • Loading branch information
skyjake committed Apr 23, 2013
1 parent 2362049 commit 8f9e4cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
9 changes: 7 additions & 2 deletions doomsday/libgui/include/de/gui/glstate.h
Expand Up @@ -119,6 +119,11 @@ class LIBGUI_PUBLIC GLState
void apply() const;

public:
/**
* Returns the current topmost state on the GL state stack.
*/
static GLState &top();

/**
* Pushes a copy of the current state onto the current thread's GL state
* stack.
Expand All @@ -137,14 +142,14 @@ class LIBGUI_PUBLIC GLState
*
* @param state State to push. Ownership taken.
*/
static void pushState(GLState *state);
static void push(GLState *state);

/**
* Removes the topmost state off of the current thread's stack.
*
* @return State instance. Ownership given to caller.
*/
static GLState *takeState();
static GLState *take();

private:
DENG2_PRIVATE(d)
Expand Down
17 changes: 10 additions & 7 deletions doomsday/libgui/src/glstate.cpp
Expand Up @@ -315,27 +315,30 @@ void GLState::apply() const
}
}

GLState &GLState::push()
GLState &GLState::top()
{
DENG2_ASSERT(!stack.isEmpty());
return *stack.last();
}

GLState &GLState::push()
{
// Duplicate the topmost state.
GLState *top = new GLState(*stack.last());
pushState(top);
return *top;
push(new GLState(top()));
return top();
}

void GLState::pop()
{
delete takeState();
delete take();
}

void GLState::pushState(GLState *state)
void GLState::push(GLState *state)
{
stack.append(state);
}

GLState *GLState::takeState()
GLState *GLState::take()
{
DENG2_ASSERT(stack.size() > 1);
return stack.takeLast();
Expand Down

0 comments on commit 8f9e4cc

Please sign in to comment.