Performance question

Hello,

I am curious about which of the following choices is better for performance in regards to billboarding. I can either globally enable alpha testing for my entire app and have alpha testing be performed even on polys that I know are going to pass the test regardless. But I have noticed that the framerate drops a good enough percentage to cause me to be reluctant whenever I make a call to glEnable() in my drawing routines. Should I just alpha test the special polys that I want to have billboarded, or just alpha test everything? Is it general practice to avoid calls to GL state alterting commands like glEnable/disable during drawing? I have seen a lot of sample OpenGL apps make calls to glEnable/disable during drawing. Thanks for the info.

Hard to say. The performance hit from alpha testing depends on the number of pixels you draw, the hit from changing states depends on how often you change states. Generally, changing states is worse, but the only way to know for sure about any particular case is to profile it.

Yes you want to avoid both. You want to avoid extra state that causes overhead and you want to avoid changing state a lot. Just to make things interesting not all cards perform the same. With some alpha testing is free with others it costs a lot and with some it depends on the reference value. If that wasn’t bad enough just enabling and disabling the test costs different ammounts on different cards and this is in no way related to the cost of performing the fragment test. This is true for many types of state, are you having fun yet?

One decent compromise is to minimize the state changes by drawing objects with the same state together. It’s called state sorting. Alpha wants to be sorted for zbuffer/blend aesthetic reasons anyway so for alpha the decision to draw together after opaque geometry is a particularly easy one to make.

Summary, draw all your billboards last and have a single call to enable alpha testing before you draw them and a single call to disable testing after they are drawn.

Stuff like transformation matrices may make the decision harder because you have to replicate some of the matrix work. In this situation you are trading alpha test state changes for matrix operation overhead. This is a classic state sort tradeoff issue and the answer can be different depending on the OpenGL implementation.

There are many other similar state issues and tradeoffs that have no black & white answers but creative compromises as solutions.

[This message has been edited by dorbie (edited 06-01-2002).]