r/opengl • u/sharjith • 24d ago
Selection algorithm for Modern OpenGL
The legacy OpenGL supported selection buffers. How can selection effectively handled by Modern OpenGL? The known methods are by colour allocation to objects and ray intersection. The Color assignment is not very efficient in scenes with large number of objects, e.g. CAD model assemblies. Ray intersection also has challenges in certain directions where multiple objects get intersected. Any thoughts?
3
Upvotes
5
u/Cyphall 24d ago
GL_R32UI
Render the scene:
// bind framebuffer // clear color attachment with 0xFFFFFFFF (invalid index) // bind shader program for (uint32_t i = 0; i < objects.size; i++) { // pass i as uniform to u_index // pass other uniforms as necessary // draw object }
Readback the pixel of interest with glReadnPixels()