How do I read back multiple transform feedback buffers when using GL_SEPARATE_ATTRIBS instead of just one like with GL_INTERLEAVED_ATTRIBS? In this example I set up two buffers and setup them for transform feedback.
//gen,bind,buffer GL_ARRAY_BUFFER buffer0
//gen,bind,buffer GL_ARRAY_BUFFER buffer1
//gen,bind GL_TRANSFORM_FEEDBACK feedback
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buffer0);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 1, buffer1);
const GLchar* _varyings[] = { "pos", "color" };
glTransformFeedbackVaryings(program, 2, _varyings, GL_SEPARATE_ATTRIBS);
glLinkProgram(program);
//bind VAO and draw with TF enabled
glBeginTransformFeedback(GL_TRIANGLES);
glDrawArrays(GL_TRIANGLES, 0, numberOfVertices);
glEndTransformFeedback();
With a single buffer and GL_INTERLEAVED_ATTRIBS
I am able to read back a single buffer by calling glGetBufferSubData
on GL_TRANSFORM_FEEDBACK_BUFFER
:
std::vector<float> fb;
fb.resize(3*numberOfVertices);
glGetBufferSubData(GL_TRANSFORM_FEEDBACK_BUFFER, 0, fb.size() * sizeof(float), fb.data());
However, how do I tell OpenGL that I want to read back both buffers buffer0
and buffer1
indexed (0,1)
with glBindBufferBase
of GL_TRANSFORM_FEEDBACK_BUFFER
?
All tutorials I have found always simplify this to a single buffer with GL_INTERLEAVED_ATTRIBS
and just explain that it is possible to use separate buffers to match the TF output according to the VAO input layout or simply don't read back buffer data at all.
There was no example available for the specific question asked as reading back multiple buffers with transform feedback is not different from reading back multiple buffers in general. You bind the buffer - you read it. The transform feedback object and it's buffer bases only tell OpenGL how it should store the captured output.