Transform feedback buffer!!!
I am making a little particle system using transform feedback buffer and I am coming across a strange issue.
so in the below update function I swap my transform and draw buffer and this works totally fine for my first two buffers but when trying to swap the velocity one I always get an error message saying that “a transform feedback buffer is also bound to a non transform buffer”. I fix the error by essentially reassigning velocityTSVBO to a whole new empty buffer but I don’t understand why this is not working for the last buffer. You can see the update function and the render loop below. Thanks.
UPDATE FUNCTION:
let update = function(){
now = Date.now();
if(now - then > 16.6){
then = now;
VBO = TSVBO;
TSVBO = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER,TSVBO);
gl.bufferData(gl.ARRAY_BUFFER,16*nparticles,gl.STATIC_READ);
lifeVBO = lifeTSVBO;
lifeTSVBO = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER,lifeTSVBO);
gl.bufferData(gl.ARRAY_BUFFER,4*nparticles,gl.STATIC_READ);
velocityVBO = velocityTSVBO;
velocityTSVBO = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER,velocityTSVBO);
gl.bufferData(gl.ARRAY_BUFFER,12*nparticles,gl.STATIC_READ);
}
render();
}
RENDERLOOP:
let render = function(){
gl.viewport(0,0,canvas.width,canvas.height);
gl.clearColor(1,1,1,1);
gl.enable(gl.DEPTH_TEST);
gl.enable(gl.BLEND);
gl.blendFunc(gl.ONE,gl.ZERO);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.useProgram(TSProgram);
gl.bindBuffer(gl.ARRAY_BUFFER,VBO);
gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0,4,gl.FLOAT,false,0,0);
gl.bindBuffer(gl.ARRAY_BUFFER,lifeVBO);
gl.enableVertexAttribArray(6);
gl.vertexAttribPointer(6,1,gl.FLOAT,false,0,0);
gl.bindBuffer(gl.ARRAY_BUFFER,velocityVBO);
gl.enableVertexAttribArray(3);
gl.vertexAttribPointer(3,3,gl.FLOAT,false,0,0);
gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER,0,TSVBO);
gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER,1,lifeTSVBO);
gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER,2,velocityTSVBO);
gl.beginTransformFeedback(gl.POINTS);
gl.drawArrays(gl.POINTS,0,nparticles);
gl.endTransformFeedback();
gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 0, null);
gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 1, null);
gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 2, null);
gl.useProgram(program);
gl.bindBuffer(gl.ARRAY_BUFFER,TSVBO);
gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0,4,gl.FLOAT,false,0,0);
gl.bindBuffer(gl.ARRAY_BUFFER,colourVBO);
gl.enableVertexAttribArray(3);
gl.vertexAttribPointer(3,3,gl.FLOAT,false,0,0);
gl.drawArrays(gl.POINTS,0,nparticles);
requestAnimationFrame(update);
}