JTalton's picture

GL_SELECT Performance

This is sort of a follow up the the forum topic Selection/Picking.

When using the GL.RenderMode(RenderingMode.Select) the selection is hardware accelerated, but vendors intentionally degrade the performance for consumer level cards. The is because high end modeling applications use this rendering mode for selection and the hardware vendors want to be able to charge more for a "workstation" graphics card.

Both ATI and NVidia have this issue and getting different driver versions will enable full acceleration on consumer cards. Of course then you can't use the latest drivers which is not a good thing. There are also some posts about "changing" your consumer level card so that it looks like a workstation card and can use the latest workstation drivers.

As for selection in OpenGL 3.0, that is a good question. Some sort of hardware selection of primitives will be supported whether it is GL_SELECT or some programmable shader that outputs to a buffer. If anyone has more information on this I would love to hear about it.

So for selection we have three options:

  1. GL_SELECT - Hardware accelerated but degraded performance through drivers for consumer level cards.
  2. Software - Write you own algorithms to determine hit testing and selection.
  3. Color Picking - Where each primitive is given a unique color, drawn into a buffer, and the buffer is checked for it's color.

GL_SELECT and Software allow selection of objects even if they are behind another object. Color picking only knows the color of the object that is at the front of the buffer.

There are two types of color picking.

  1. Viewport where all the visible primitives can be selected from a N by N area.
  2. FBO where you create a single pixel FBO thus allowing you to select only one item.

The FBO approach has the added benefit that it takes very little fill rate and thus may be very fast.

I do have a worry about the color picking method since if aliasing is enabled it would cause pixels at the edges of primitives to blend and give a different color which would give inaccurate results for selection.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Hangar's picture

I once did a fairly complex color picking implementation. It was 2D, so vastly simpler, but I did learn a few things. Note I learned all of this by just messing around, so there's probably a better way to do it.

1. You'll need custom ids for your objects unless you already have a system of ids where each less than 2^24. Or you can use additional buffers if you have them (like the alpha buffer).

2. Objects should know how to render themselves two ways: when in normal mode and when in color picking mode, using some global state to decide which mode is active. This way, rendering for color picking uses the same code as normal rendering.

3. If an object isn't selectable, don't render it in selection mode.

4. You can use primitives that only render in selection mode, like a large sphere to allow you to select a small or odd-shaped object.

5. Do not use alpha blending, but you can use the alpha test. For example, if alpha is less than 20%, register it as not selected.

6. If your textures have a lot of transparency, you can create corresponding white textures with similar alpha to get pixel perfect selection. You can lower the resolution on the textures to save memory. (These can be created ahead of time.)

7. Don't worry about multiple layers of objects. If an object is in front and is selectable, it should be what's selected because that's what the user sees on top. Alternately, you can order things by using an alpha buffer and the alpha test (or stencil buffer and stencil test if not used, etc).

8. I've never used the FBO, but I did use the scissor test to narrow it down to 1 pixel.