What tips or tricks do you have when it comes to making the OpenGL more efficient?
closed as too broad by bummzack, MichaelHouse♦ Aug 4 '13 at 23:55
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
Use VBO rather than glStart()/glEnd(). This saves cycles in transferring the data to the GPU's memory.
The standard tip of profile, profile, profile applies just as well here, although the tools are slightly different.
gDEBugger is great at helping you see exactly what's going on under the hood. It's expensive, though.
These are from Apple's documentation references on OpenGL but every little bit helps right? ;)
(This last one is a sample application)
There are also a very large number of videos available on the subject (Also from Apple) that talk about OpenGL extensions. Some of them are OS X specific, but a few others are more generalized and could most likely be applied to Windows and Linux.
You can find the videos here. You do require iTunes and an Apple account to view them however (but they are free! :D)
Well, it really, really depends on what you're planning to do, but here are the basics:
Your CPU is very precious while your GPU is a hungry beast. Offset as much as you can to the GPU. Nowadays you can do this with excellent libraries like OpenCL, CUDA and Thrust.
Do your lighting in a shader. Not only will this help retain your sanity, but it allows you to very cool things like toon shaders and deferred lighting.
Particles suck. Even when using OpenGL point sprites.
Minimize your state changes. On a lot of platforms, each state change potentially flushes the pipeline. It's much better to batch similar items together and change state once.
Simple one liner that applies back face culling. This is excellent for trimming down polygon count. Also look into Frustum/Occlusion culling for reducing poly counts.
Another thing to look into is SIMD for your vectors and quaternions (mostly used in camera rotations). If you don't want to mess with ASM then check out libSIMD which is a great library for handling SIMD in C.
Don't use glGet* when you can access local variables, e.g.:
- Don't query textures size from OpenGL, store them on loading in variables
- Don't query line widths / points sizes from OpenGL when you can store the changes in your application
These calls are really slow
Move unused stuff outside of glBegin - glEnd clause (be it glColor or glNormal or anything else) if it does not changes inside. OpenGL is a state machine, it uses the last value.
Minimize OpenGL commands is the key. So you must batch all drawing commands. For 2d games, it is a good idea to use Altas Texture and draw all sprites sharing the same texture in one opengl command.
Batch, batch, batch!! (Ab)use the GPU to render as much as possible in each draw call. Games are mostly limited by the amount of state changes, not so much by the amount of triangles.