Transform Feedback with LINE_STRIP

Hi all,

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();

But what to do with glGetVaryingLocationNV?

Hopefully someone can help me out…

Thanks

This should tell you everything you need to know:

http://opengl.org/registry/specs/NV/transform_feedback.txt

Note that you cannot use GL_LINE_STRIP in the begin feedback function - instead you use GL_LINES. You can still render a line strip though.

You’ll probably want something like this to initialize things:

 
int locations[] =
{
    glGetVaryingLocationNV(shader, "gl_Position");
};

glTransformFeedbackVaryingsNV(shader, 1, locations, GL_SEPARATE_ATTRIBS_NV);

Then, you’ll want to bind a VBO to feedback location 0 to capture the data:

glBindBufferBaseNV(GL_TRANSFORM_FEEDBACK_BUFFER_NV, 0, destination_vbo);

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?

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.

Ah yes… I see. I was wondering if we needed a seperate variable for each vertex emitted. That would have been very inflexible and redundant.

I’ll be trying this first thing in the morning!

I appreciate your clear and fast response.

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?)