I’m working on trying to save transform feedback output into a pair of uniform buffers and I keep getting
“The specified operation is invalid for the current OpenGL state”
after beginning the transform feedback.
Basically, I’m trying to convert the flocking example from superbible #5 to OpenGL ES 3.
Here is the setup:
GLuint positionBlockIndex = glGetUniformBlockIndex(flockingUpdateProgram, "PositionBlock");
GLuint velocityBlockIndex = glGetUniformBlockIndex(flockingUpdateProgram, "VelocityBlock");
GLint positionBlockSize,velocityBlockSize;
glGetActiveUniformBlockiv( flockingUpdateProgram, positionBlockIndex, GL_UNIFORM_BLOCK_DATA_SIZE, &positionBlockSize );
glGetActiveUniformBlockiv( flockingUpdateProgram, velocityBlockIndex, GL_UNIFORM_BLOCK_DATA_SIZE, &velocityBlockSize );
// Set up UBOs
for (i = 0; i < 2; i++)
{
glUniformBlockBinding(flockingUpdateProgram, positionBlockIndex, 0);
glBindBufferBase(GL_UNIFORM_BUFFER,0,position_ubo[i]);
glBufferData(GL_UNIFORM_BUFFER, positionBlockSize, NULL, GL_DYNAMIC_DRAW);
glUniformBlockBinding(flockingUpdateProgram, velocityBlockIndex, 1);
glBindBufferBase(GL_UNIFORM_BUFFER,1,velocity_ubo[i]);
glBufferData(GL_UNIFORM_BUFFER, velocityBlockSize, NULL, GL_DYNAMIC_DRAW);
}
Here is the render call:
// Depending on whether we're rendering an even or odd frame...
if (frame_index & 1)
{
// Read from second set of buffers (c)
glBindBufferBase(GL_UNIFORM_BUFFER,1, velocity_ubo[1]);
glBindBufferBase(GL_UNIFORM_BUFFER,0, position_ubo[1]);
glBindVertexArray(update_vao[1]);
// Write to first
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, flock_position[0]);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 1, flock_velocity[0]);
}
else
{
// Read from first set of buffers (a)
glBindBufferBase(GL_UNIFORM_BUFFER,1, velocity_ubo[0]);
glBindBufferBase(GL_UNIFORM_BUFFER,0, position_ubo[0]);
glBindVertexArray(update_vao[0]);
// Write to second
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, flock_position[1]);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 1, flock_velocity[1]);
}
// Turn off rasterization for the simulation pass (no fragment shader)
glEnable(GL_RASTERIZER_DISCARD);
// Press record...
glBeginTransformFeedback(GL_POINTS);
// Draw
glDrawArrays(GL_POINTS, 0, flock_size);// **ERROR HERE**
// Press stop...
glEndTransformFeedback();
// Turn rasterization back on
glDisable(GL_RASTERIZER_DISCARD);