Transform feedback buffer!

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);

	

}

From the OpenGL 4.6 Spec:

My question fundamentally is why swapping velocityVBO and velocityTSVBO in the update function won’t work? The only way I can get this running is by setting velocityTSVBO to a whole new empty buffer. Swapping the buffers works just fine for the other two nuggets I have

We can only guess. But I’d assume that you’re leaving one them bound. E.g. I note that your render function only ever enables attribute arrays, but never disables them (so the attribute array with index 6 is enabled for the second draw call although it presumably doesn’t use it). It’s not clear from the spec that disabling the attribute array to which a buffer is bound is sufficient; you may have to unbind it (e.g. by calling glVertexAttribPointer while buffer zero is bound to GL_ARRAY_BUFFER).