Transform feedback code bug, help please
I seem to have hit a wall with my toy should-be-simple first TF program. Really appreciate if someone can help find the bug. What I want to do is draw two points (which are actually the same) and output their world coords (should be same, of course) to the TF buffer. That's it, just to see TF working.
The plan is to do two passes in the same drawing routine. The first pass outputs to the TF buffer, while the second pass draws. Relevant part of the main, VS and FS are below.
Bug: As you can see from the FS code, the way I test if the TF buffer is written correctly is by fetching the corresponding "texel" and checking its distance with what I calculate by hand to be correct (to avoid testing float equality with 0, if the distance is less than 0.001 I specify a particular color). The first point which presumably should be from texelFetch(TFBuffer, 0) comes out correct but the second point (identical to the first) from texelFetch(TFBuffer,1) does not.
Any suggestions as to what I am doing wrong would be highly appreciated.
glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, 1024, NULL, GL_DYNAMIC_COPY);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, TFBuffer);
glTransformFeedbackVaryings(programId, 1, varyings, GL_INTERLEAVED_ATTRIBS);
glTexBuffer(GL_TEXTURE_BUFFER, GL_RGB32F, TFBuffer);
// TF pass
some MV transforms
glDrawArrays(GL_POINTS, 0, 2); // Two identical points!
// Drawing pass.
same MV transforms
glDrawArrays(GL_POINTS, 0, 2); // Same two points.
out vec4 center; // Varying
center = modelViewMat * coords;
gl_Position = projMat * modelViewMat * coords;
uniform samplerBuffer TFBuffer;
v0 = texelFetch(TFBuffer, 0).xyz;
v1 = texelFetch(TFBuffer, 1).xyz;
d = distance(v0, vec3(10.0f, 0.0f, -15.0f) );
if ( d < 0.001f) colorsOut = vec4(0.0f, 0.0f, 1.0f, 1.0f);