This patch replaces occlusion queries when picking (but keeps existing occlusion queries for border select).
Suggested by Ton, checks the depth buffer each draw and keeps 2 buffers, one for depth and another for id's so we can keep track of which ID draws into each pixel, then calculate a depth-sorted hit-list.
This isn't going to be efficient for large buffers but luckily for picking we don't need to read from a large buffer.
To test this patch enable "Occlusion Queries" in the preferences, border select behavior uses still uses "Occlusion Queries", picking (GPU_SELECT_DEPTH_SORT_NEAREST & GPU_SELECT_DEPTH_SORT_ALL) uses only the depth buffer.
- Selection performance on my system (NVIDIA) doesn't seem very different (a little slower than occlusion queries).
- Bones with X-Ray don't work properly, see: T46043 (can look into a fix if this is otherwise acceptable to merge).
- Selection passes GPU_SELECT_NEAREST_FIRST_PASS, GPU_SELECT_NEAREST_SECOND_PASS are now only used for manipulator picking.
- How much do we want to emulate GL_SELECT?, current occlusion queries for example only fill in the ID field of the selection buffer: the first 3 [number, znear, zfar, ] fields are dummy values. If we're not using GL_SELECT we could drop attempting to follow it's conventions.
- Is this method going to be used long term if we can use shaders as @Mike Erwin (merwin) suggests.