What tips or tricks do you have when it comes to making the OpenGL more efficient?
|
|
Use VBO rather than glStart()/glEnd(). This saves cycles in transferring the data to the GPU's memory. |
|||||||||||||
|
|
These are from Apple's documentation references on OpenGL but every little bit helps right? ;) OpenGL Performance Optimization : The Basics (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) |
||||
|
|
|
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. |
|||||
|
|
Well, it really, really depends on what you're planning to do, but here are the basics:
|
||||
|
|
|
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. |
||||
|
|
|
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. |
||||
|
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.:
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. |
||||
|
|
|
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. |
||||
|
|