is glPushAttrib still expensive?

Sage
Posts: 1,199
Joined: 2004.10
Post: #1
All

I recently started using glPushAttrib/glPopAttrib to clean up some of the state changes for my engine, after spending a couple days tracking down a really, *really* subtle error that was causing my menus to sporadically lose ( and sporadically regain ) alpha blending. That was a serious hair-puller. I had reason to believe at first it was a memory smasher bug ( since I didn't notice the bug until after implementing a c++ system to complement Objective-C's autorelease mechanism)... anyway I spent a whole afternoon with MallocDebug and friends trying to track it down before I was able to determine it was just a state change issue.

Anyway, glPushAttrib makes everything so much easier... but googling for performance implications shows that -- at least in the old days -- glPushAttrib was pretty expensive.

Is it still? I don't see any performance hit for using it, but I'm only using it in a few spots at the moment. I'd like to move over to it more liberally, but I'd like to know from those who know if this is a good idea.
Quote this message in a reply
Moderator
Posts: 365
Joined: 2002.04
Post: #2
I couldn't tell you exactly how expensive it is, but there are a couple of rules-of-thumb you might want to bear in mind:
  • The less separate GL functions you call, the less function call overhead you'll incur. Therefore, if you can do the same amount of work in less function calls, it'll be more efficient.
  • You shouldn't push or pop any more state than you actually need to. Work out exactly which group(s) of attributes that you're interested in instead of pushing everything at once.
However, you should probably work out how much more or less expensive it is by profiling rather than guessing.

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
Post Reply