Skip to content

Commit

Permalink
optimization on draw(), using DEFAULT_UPDATE_FREQUENCY
Browse files Browse the repository at this point in the history
  • Loading branch information
brucelane committed Nov 14, 2014
1 parent cbf40f0 commit f5ace74
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions src/UIController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,44 +150,47 @@ void UIController::drawBackground()

void UIController::draw()
{
if ( !mVisible )
if (!mVisible)
return;

// save state
gl::pushMatrices();
glPushAttrib( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_LINE_BIT | GL_CURRENT_BIT );

// disable depth read (otherwise any 3d drawing done after this will be obscured by the FBO; not exactly sure why)
gl::disableDepthRead();
// save state
gl::pushMatrices();
glPushAttrib(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_LINE_BIT | GL_CURRENT_BIT);

// start drawing to the Fbo
mFbo.bindFramebuffer();
// disable depth read (otherwise any 3d drawing done after this will be obscured by the FBO; not exactly sure why)
gl::disableDepthRead();

gl::lineWidth( toPixels( 2.0f ) );
gl::enable( GL_LINE_SMOOTH );
gl::enableAlphaBlending();
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
// optimization
if (getElapsedFrames() % DEFAULT_UPDATE_FREQUENCY == 0) {

// clear and set viewport and matrices
gl::clear( ColorA( 0.0f, 0.0f, 0.0f, 0.0f ) );
gl::setViewport( toPixels( mBounds + mPosition ) );
gl::setMatricesWindow( toPixels( mBounds.getSize() ), false);
// start drawing to the Fbo
mFbo.bindFramebuffer();

// draw backing panel
gl::color( mPanelColor );
gl::drawSolidRect( toPixels( mBounds ) );
gl::lineWidth(toPixels(2.0f));
gl::enable(GL_LINE_SMOOTH);
gl::enableAlphaBlending();
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

// draw the background
drawBackground();
// clear and set viewport and matrices
gl::clear(ColorA(0.0f, 0.0f, 0.0f, 0.0f));
gl::setViewport(toPixels(mBounds + mPosition));
gl::setMatricesWindow(toPixels(mBounds.getSize()), false);

// draw elements
for (unsigned int i = 0; i < mUIElements.size(); i++) {
mUIElements[i]->draw();
}
// draw backing panel
gl::color(mPanelColor);
gl::drawSolidRect(toPixels(mBounds));

// finish drawing to the Fbo
mFbo.unbindFramebuffer();
// draw the background
drawBackground();

// draw elements
for (unsigned int i = 0; i < mUIElements.size(); i++) {
mUIElements[i]->draw();
}

// finish drawing to the Fbo
mFbo.unbindFramebuffer();
}
// reset the matrices and blending
gl::setViewport( toPixels( getWindow()->getBounds() ) );
gl::setMatricesWindow( toPixels( getWindow()->getSize() ) );
Expand Down

0 comments on commit f5ace74

Please sign in to comment.