Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Performance question

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2001
    Location
    Milwaukee WI 53211
    Posts
    29

    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.

  2. #2
    Junior Member Regular Contributor
    Join Date
    Dec 2001
    Location
    Belmont, CA, USA
    Posts
    216

    Re: Performance question

    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.

  3. #3
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,969

    Re: Performance question

    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).]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •