which state change is more efficient?

Started by
1 comment, last by GreenToad 19 years, 8 months ago
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.
Advertisement
perhaps
elem->draw(x,y);

draw( int x, int y )
glVertex2f( .. + x,
etc
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.

This topic is closed to new replies.

Advertisement