I’d like to do the following:
Provide a geometry shader with a seed point (vertex location). The geometry shader creates a line strip, which I would like to feedback to a buffer.
How do I set up transform feedback to accept the line strip, and how do I set the linestrip into a varying variable?!
So in the shader I’d guess something like
vec4 linestrip[10] for each vertex location?
And for the feedback my first guess would be:
glBeginTransformFeedbackNV(GL_LINE_STRIP);
Render();
glEndTransformFeedbackNV();
I have seen the spec, but some things remain unclear. For instance I want the line strip to consist of, for instance, 20 segments, which implies that we need to return 19 vertices. How to put this in a varying variable in the geometry shader?
Originally posted by ropel:
[b] Thank you for the quick reply.
I have seen the spec, but some things remain unclear. For instance I want the line strip to consist of, for instance, 20 segments, which implies that we need to return 19 vertices. How to put this in a varying variable in the geometry shader? [/b]
If I understand correctly, you are wanting to emit n line segments from the GS as a line strip. This means that you will need to emit n+1 vertices.
If this is the case, you simply do something like the following in the GS:
void main()
{
gl_Position = vertex 0 position
EmitVertex();
gl_Position = vertex 1 position
EmitVertex();
...
gl_Position = vertex n position
EmitVertex();
EndPrimitive();
}
Of course, you could also use a for loop to emit them, and store the positions as a constant array.
So I have got things going, thanks to the good comments. But it really is extremely slow!
Currently I feedback around 1.600.000 primitives, which takes more than half a minute.
I am comparing results with a direct approach, where I render line segments every frame, with an off-line approach where I first render the line segments to a VBO using transform feedback.
On average I only gain 5 FPS, whereas I have to wait very long for the line segments to generate.
Is this correct? Are there any other solutions?
(For instance generating the line segments CPU side?)