I'm trying to figure out the best way to pick informations rendered using shaders. A window manager buffer (the window) is used for outputting rendering. On user event I should pick the geometry rendered. Using gluPick is easy, but I'm trying to pick using only shaders.
Flexibility of shaders doesn'y aid me to find a correct solution. I've found the following solutions:
- Rendering using the system provided buffer (indeed using colors). Use glScissor to limit the rendering on a certain region and use glReadPixels for fetching colors, mapped with geometry identifiers
- Rendering using a separate framebuffer object. Renderbuffer formats need to defined. Maybe can I use plain integers for putting names?
- Rendering using a framebuffer object, both for rendering and picking. An additionally renderbuffer object containing rendered names.
It seems that the second solution is the best, since doesn't alterate the window buffers and it's possible to define a custom way to specify geometry names.
Any suggestion?
P.S:
Since in a fragment shader i declare an array of vec4 for defining the fragment data, how I could setup a framebuffer holding an render buffer having only the R component, stored in a sized integer internal format?
Is it possible to link a fragment shader output variable with a specific attached render buffer?