I have a question regarding the interplay between transform feedback and geometry shaders.
(And, of course, I’d be happy the hear about alternative approaches.)
On every triangle that gets rendered (I don’t need to consider others), I want to check a (simple) geometric condition.
To do that, I wrote a geometry shader (GS).
After the test, the GS outputs the triangle unmodified.
(I already checked that the performance hit by this additional shader is negligible on a modern NVidia card.)
AFAIK, the output of the GS can, in addition to being rendered, be stored in a transform feedback buffer (TFB).
That’s perfect.
However, I would like to store only those triangles in the TFB that pass the geometric test.
(After the frame, I would like to read back the TFB on the CPU side.)
Does anyone know whether this is possible?
Something like a KILL statement in the GS? except that it should apply only to the TFB, the triangle should still be rendered.
As a fallback, I thought about the following work-around:
I store all triangles in the TFB, together with a flag that contains the outcome of the geometric test.
After the frame, I perform a sort of a prefix sum using a CUDA program on the TFB that leaves only those triangles that have the flag set.
The question here is whether it is possible to make the TFB (which is AFAIK just a VBO) available to a CUDA program, and how much time that switch would cost.
I have also just seen the slides from the Siggraph 2011 OpenGL BOF, which talk about a concept called “Images” which can be written to be shaders.
Unfortunately, I don’t know anything detailed about them.
The question here is, if the above approaches are not feasible: would such “images” be a solution to my problem? If so, could some kind soul point me to a tutorial or similar that would help me to understand exactly how they work?
Thanks a million in advance for all kinds of insights, pointers, suggestions, etc.
Best regards,
Gabriel.