Transform feedback in OF 0.9.0 – looping feedback

Following up with the last post answering the question I was asked several times – to keep updating the same attribute, e.g. vertex positions with transform feedback, you can use ping-pong technique to create a sort of feedback loop. Prepare two Buffer Objects, or ofBufferObjects for each shader attribute you want to update with feedback transform, then swap them every frame so that the updated buffer becomes the next input while the other becomes the next receiver of the output.

See the code snippets below. The complete example is on GitHub.

.h file
int currentAttributeBuffer = 0;
ofBufferObject positionBuffers[2];

.cpp
int feedbackTargetBuffer = 1 - currentAttributeBuffer;
vbo.setVertexBuffer(positionBuffers[currentAttributeBuffer], 4, 0); // Set one of the ofBufferObject as an attribute for the vertex shader
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, positionBuffers[feedbackTargetBuffer].getId()); // Set the other ofBuffer as the target of the transform feedback
currentAttributeBuffer = feedbackTargetBuffer;

Related Posts with Thumbnails

Leave a Reply

You must be logged in to post a comment.