Are calls to glEnable/glDisable expensive?

Started by
4 comments, last by Pierrick 16 years, 9 months ago
For example to render my bitmap fonts correctly I have to disable lighting and textures and then re-enable them when I'm finished, is this a normal thing to have to do or should I be worried about making a lot of calls like this? Is this a ridiculous thing to be worried about?
Advertisement
heh.. you really shouldn't worry :)

finish your game/engine or whatever and then worry about function calls, and I bet in 99.999% of the cases it's your own functions you should worry about :)
You are switching opengl state when you do that so it could be expensive. How much is hard to say without benchmarking it. Like ggp83 says though, don't worry about it too much.

If you do worry anyway, a good idea would be to makes sure you do all text rendering at the same time. Then you only have to switch state before and after all text rendering, instead of for each rendered text.
Like the posters above have said, first make it run, then make it run fast. Chances are, your font engine will not be the bottleneck.
It's only a problem if you do it MANY times and you CPU and drivers are slow.
In general, the less calls to GL the better. And it depends very much on the actual call. glBindTexture is expensive, glUseProgram, etc...
glEnable and glDisable are less expensive
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
profile your application with C/C++ profiler to find its bottlenecks. Then you'll know to improve your code. The results can be really impressive.

/P.

This topic is closed to new replies.

Advertisement