glGet calls - the silent (performance) killer

While profiling Blender today, I was shocked to discover that it uses glGet calls all over the place, even in functions that are called a lot.

Such calls should be avoided, because they can absolutely ruin performance. Worse yet, Blender seems to abuse this mechanism as a storage for things like the current drawing color.

Unfortunately, this isn’t mentioned in the OpenGL docs, it’s just one of these things you have to know, likely by stumbling upon it because your application scales unexpectedly badly.

Therefore coders, be you warned, avoid the temptations of glGet! Store your own state, for performance sake!

I think (maybe?) they managed to optimize them a bit since siggraph '97…

Blender still uses OpenGL 1.x anyway. This will change in 2.7/2.8 as Ton stated in his “future of blender” on the blog.
It’ll take time to rework all this and modernize it, but I think by then these calls will be removed :wink:
on the other hand, just because something isn’t documented, why shouldn’t it be used if it worked for years :smiley:
(just kidding! Please don’t shoot!)

No, they did not, they’re as slow as ever. Granted, the source is old, but I wanted one that more or less explains why it is slow, not that it is slow. If you want to convince yourself that these calls are slow, you can either use them yourself or look at the dozens of forums posts online of people having the same experience.

That’s not really accurate. Blender uses features from OpenGL 1.x to 3.x, depending on what you do. Parts of Blender are more or less as fast as it gets, already, as far as OpenGL is concerned. However, I’m fairly sure these glGet calls are the main culprit for UI widgets scaling so badly.
Also, using deprecated OpenGL functions is not by itself a performance concern, getting rid of them will not by itself improve performance.