Jump to content
  • Advertisement
Sign in to follow this  
ktw6675

OpenGL which state change is more efficient?

This topic is 5143 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm rolling my own OpenGL gui (please don't tell me to find an existing one, I'm doing it to learn ;) and I'm currently having each element have it's own "local" coordinates using gl matrices:
virtual void draw() {
  for ( GuiElementContainer::iterator i = children.begin();
	i!=children.end();
	i++)
  {
    glPushMatrix();
    GuiElement* elem = (*i);
    glTranslatef(elem->rect.x,elem->rect.y,0);
    elem->draw();
    glPopMatrix();
  }
}

This is so a call from an element's draw function to (0,0) will be at (0,0) "locally" for that element, but it may be anywhere on the screen. I know these push/pop matrix calls all over the place might be expensive though...is there an alternative I can try? I was thinking maybe glViewport but I'm not sure how that would work.

Share this post


Link to post
Share on other sites
Advertisement
glPush and Pop calls are really not that expensive at all, and as far as I know they are what you are supposed to be using for that kind of thing. If you are really concerned what kind of performance hit they incurr, comment out the push and pop calls one of these times and you'll see you have nothing to worry about. You should focus on bigger worries like render state sorting, frustum culling, and all of that good stuff. Pushing and popping OGL matrices like that is not at all a big deal as far as performance goes.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!