2
votes

I want to transform data from geometry shaders to feedback buffer,so I set the names of variables like this:

char *Varying[] = {"lColor","lPos","gl_NextBuffer","rColor","rPos"};

then bind two buffers vbos[2] to transformFeedback object Tfb,vbos[0] to bind point 0, and vbos[1] to bind point 2:

glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, vbos[0]);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 2, vbos[1]);

and set stream number like this:

layout(stream=0) out vec4 lColor;
layout(stream=0) out vec4 lPos;

layout(stream = 2) out rVert
{
    vec4 rColor;
    vec4 rPos;
};

So I thought lColor and lPos are transformed to vbos[0],rColor and rPos are transformed to vbos[1],but nothing came out,unless I change vbos[1] to bind point 1,and stream number of rvert to 1.

I think there is three variables about indexes for binding geometry shader output and feedback buffers,first is index in glBindBufferBase(target,index,id),second is sequences of names in glTransformFeedbackVaryings(program,count,names,buffermode),third is stream number of variables in geometry shader,what is the relationship of these three parameters? And I found that no matter what parameters I set the glDrawTransformFeedbackStream ,picture didn't change,Why?

1
Until now,from my test,there can't be any empty bind point of feedback object.If a feedback buffer is bound to index 0,next feedback buffer must be bound to index 1.But I still don't understand the relationship between stream index and bind index of glBindBufferBase.Chris

1 Answers

1
votes

The geometry shader layout qualifier stream has no direct relationship to the TF buffer binding index assignment. There is one caveat here: variables from two different streams can't be assigned to the same buffer binding index. But aside from that, the two have no relationship.

In geometry shader transform feedback, streams are written independently of each other. When you output a vertex/primitive, you say which stream the GS invocation is writing. Only the output variables assigned to that stream are written, and the system keeps track of how much stuff has been written to each stream.

But how the output variables map to feedback buffers is entirely separate (aside from the aforementioned caveat).

In your example, glTransformFeedbackVaryings with {"lColor","lPos","gl_NextBuffer","rColor","rPos"} does the following. It starts with buffer index 0. It assigns lColor and lPos to buffer index 0. gl_NextBuffer causes the system to increment the value of the current buffer index. That value is 0, so incrementing it makes it 1. It then assigns rColor and rPos to buffer 1.

That's why your code doesn't work.

You can skip buffer indices in the TF buffer bindings. To do that, you have to use gl_NextBuffer twice, since each use increments the current buffer index.

Or if your GL version is high enough, you can just assign the buffer bindings and offsets directly in your shader:

layout(stream=0, xfb_offset = 0, xfb_buffer = 0) out vec4 lColor;
layout(stream=0, xfb_offset = 16, xfb_buffer = 0) out vec4 lPos;

layout(stream = 2, xfb_offset = 0, xfb_buffer = 2) out rVert
{
    vec4 rColor;
    vec4 rPos;
};