I’m trying (and failing) to update a VBO of indices via transform feedback. This index VBO is used to connect points within another VBO of positions.
I’m having a hard time figuring out the correct way to bind and update the index VBO. Here’s what I have so far (just the update and draw functions).
void IndexTransformFeedbackApp::update()
{
gl::ScopedState stateScope( GL_RASTERIZER_DISCARD, true );
// UPDATE POSITIONS --------------------------------------------------------
// This works great so far
{
gl::ScopedGlslProg glslScope( mPointUpdateGlsl );
gl::ScopedVao vaoScope( mVao[mSourceIndex] );
gl::bindBufferBase( GL_TRANSFORM_FEEDBACK_BUFFER, 0, mPositions[mDestinationIndex] );
gl::bindBufferBase( GL_TRANSFORM_FEEDBACK_BUFFER, 1, mVelocities[mDestinationIndex] );
// We begin Transform Feedback, using the same primitive that
// we're "drawing". Using points for the particle system.
gl::beginTransformFeedback( GL_POINTS );
gl::drawArrays( GL_POINTS, 0, POINT_NUM );
gl::endTransformFeedback();
mPositionTexture = gl::BufferTexture::create( mPositions[mDestinationIndex], GL_RGBA32F );
}
// UPDATE INDICES ----------------------------------------------------------
// This is where I'm running into issues
if( mLineUpdateGlsl ){
gl::ScopedGlslProg glslScope( mLineUpdateGlsl );
gl::ScopedVao vaoScope( mLineVao[mSourceIndex] );
// TODO: bind to mPositionTexture
gl::bindBufferBase( GL_TRANSFORM_FEEDBACK_BUFFER, 0, mLineIndices[mDestinationIndex] );
gl::beginTransformFeedback( GL_POINTS );
gl::drawArrays( GL_POINTS, 0, POINT_NUM * POINT_NUM );
gl::endTransformFeedback();
}
std::swap( mSourceIndex, mDestinationIndex );
}
void IndexTransformFeedbackApp::draw()
{
gl::ScopedMatrices scpMatrx;
gl::setMatrices( mCam );
gl::clear( Color( 0, 0, 0 ) );
{
gl::ScopedBlendAdditive scpAdd;
gl::enableAdditiveBlending();
gl::setDefaultShaderVars();
// draw points
mPointBatch[mSourceIndex]->drawInstanced( POINT_NUM );
// draw lines
mLineBatch[mSourceIndex]->draw();
}
}
When you run this, the points (spheres) update and draw correctly. The lines just blink, which tells me that it’s swapping between a buffer that has the indices defined and the nulled buffer.
Any thoughts or any more info needed to help figure this out?
A more complete code snippet can be found here:
Thanks.