OpenGL is an evolving specification. As time goes on, programming practices that were acceptable in the past are replaced by techniques that work much better. There are several functions in the OpenGL specification that you should watch for when you profile your application. If you are using any of these OpenGL functions in your application, make sure that you really need to use them, and that you are using them correctly.
Avoid glBegin because it signals that you are using immediate mode. Unless you are drawing a simple shape or creating a small prototype, immediate mode is typically not an optimal technique for using OpenGL.
glFinish forces your application to wait until all OpenGL commands in the pipeline have executed on the graphics card.
glFlush is typically not needed because flushing is usually handled by other calls, such as CGLFlushDrawable. The function glFlush flushes at the macro level, an expensive operation. Flushing calls provided by the Mac OS X interfaces (AGL, CGL, Cocoa OpenGL classes) act at a microlevel to give finer control over flushing and, as a result, much better performance.
glTexImage and related calls. Check to see if you are using this function to redefine the texture each frame. If so, change your code to define the texture outside frame rendering. If your data changes, you can instead use a data replacement technique, such as pixel buffer objects, or call glTexSubImage to specify the image again. Keep in mind that you can call glTexSubImage to specify the entire image again (maintaining the current texture parameters), and it will be a less expensive call than glTexImage. You should call glTexImage only if you must specify a larger image.
Any form of glGet or glIs. Getting state values slows your application. Unless your application is a “middle ware” application, you shouldn’t need to retrieve state values. During development, however, it’s quite common to call glGetError. When your application is ready to go into production, make sure that your remove glGetError calls and any other state getting and checking functions. As an alternative during development, you can look for errors by setting OpenGL Profiler to break on errors.
glPushAttrib or glPopAttrib. You should keep track of OpenGL state instead of using the server attribute stack.
The function glDrawPixels is a convenience function that, under the hood, uses screen-aligned textured quads. If you use screen-aligned textured quads directly, you’ll save the overhead of calling glDrawPixels. Make sure that when you use textured quads that you also use appropriate texture filtering.
If you are calling glReadPixels, you should also be using pixel buffer objects.
glProgramLocalParameter and glProgramEnvParameter calls. These calls, defined by the GL_ARB_vertex_program extension, load only one parameter at a time. It’s more efficient to use glProgramLocalParameters and glProgramEnvParameters, defined by the GL_EXT_gpu_program_parameters extension, which loads multiple parameters.
Last updated: 2008-02-08