Transform Feedback problem

Hi,
I’m trying to implemented transform feedback but I’m getting no data to output buffer. I’m using only Vertex and Pixel shader (no geometry so far). Al I want is to get gl_Position. Basically I use as input VBO with N GL_POINTS. For now I just want to get all positions from my input buffer to my output buffer, but unfortunately my output buffer is empty. Does anybody have a clue why?

Vertex shader:

void main()
{	
  gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;
}

Init of buffers:

//initialize INPUT buffer
glGenBuffers(1, &vboBuffID_1); 
glBindBuffer(GL_ARRAY_BUFFER, vboBuffID_1);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLuint)*numOfParticles*3, vboBuff_1, GL_STATIC_DRAW);

//initialize OUTPUT buffer
glGenBuffers(1, &vboBuffID_2); 
glBindBuffer(GL_ARRAY_BUFFER, vboBuffID_2);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLuint)*numOfParticles*3, 0, GL_STATIC_DRAW);

//init transform feedback variables and query
int loc[] = { glGetVaryingLocationNV(glslRain, "gl_Position")};
glTransformFeedbackVaryingsNV(glslRain, 1, loc, GL_SEPARATE_ATTRIBS_NV);
glGenQueries(1, &query);

render:

glUseProgram(glslRain);
glBindBufferBaseNV(GL_TRANSFORM_FEEDBACK_BUFFER_NV, 0, vboBuffID_2);

glBeginTransformFeedbackNV(GL_POINTS);
glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN_NV, query);

glBindBuffer(GL_ARRAY_BUFFER, vboBuffID_1);
glVertexPointer(3, GL_FLOAT, 0, NULL);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_POINTS, 0, numOfParticles);

// clean up transform feedback, retrieve count of processed particles
glEndTransformFeedbackNV();
glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN_NV);
glGetQueryObjectuiv(query, GL_QUERY_RESULT, &numOfParticles);

// clean up
glDisableClientState(GL_VERTEX_ARRAY);  // disable vertex arrays

cout << "sizeOf:" << *vboBuff_2/sizeof(GLfloat);

Interesting is that variable numOfParticles is 1000 before this call:

glGetQueryObjectuiv(query, GL_QUERY_RESULT, &numOfParticles);

right after that the value is 750. (if I change it to 100 I will get 75)… why is that?

You need to inform the shader about the transform feedback varyings prior linking it. In GL 3.x you glTransformFeedbackVaryings and then you link.

You need to bind the VBO your rendering from before glBeginTransformFeedback

Transform feedback tutorial

Actually, this is required only for core/arb versions of the feature. NV extension doesnt need relink.

OP, you provide space for 3 uints per vertex, but gl_Position has 4 components.

thank you very much so far, but still no luck.

the thing is that I can not see connection/link in my code between my output buffer (vboBuff_2) and my output bufferID (vboBuffID_2).

what am I missing here?

so did some progress. With following I am getting and drawing received vertices:

added at the end of redraw()

    glTranslatef(-1.0, -1.5, 0.0);
    glEnableClientState( GL_VERTEX_ARRAY );
    glBindBuffer( GL_ARRAY_BUFFER, vboBuffID_2 );
    glVertexPointer( 4, GL_FLOAT, 0, 0 );												
    glDrawArrays(GL_POINTS, 0, numOfParticles);
    glDisableClientState( GL_VERTEX_ARRAY );

Please can you help with this?
I’m trying to port this (simple transform feedback) to Mac OS X (everything was working fine under Linux/Ubuntu) but in Mac OS X I’m getting following seg-fault at line glDrawArrays(GL_POINTS, 0, numOfParticles):

The inferior stopped because it received a signal from the Operating System.

Signal name :
EXC_BAD_ACCESS
Signal meaning :
Could not access memory

Here is the code:

        glBindBuffer(GL_ARRAY_BUFFER, vboBuffID_1);
        glBufferData(GL_ARRAY_BUFFER, sizeof(GLuint)*numOfParticles*3, vboBuff_1, GL_DYNAMIC_DRAW_ARB);

        glVertexPointer(3, GL_FLOAT, 0, NULL);
        glEnableClientState(GL_VERTEX_ARRAY);
        glBeginTransformFeedbackEXT(GL_POINTS);
        glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN_EXT, query);
        glDrawArrays(GL_POINTS, 0, numOfParticles);
        // clean up transform feedback, retrieve count of processed particles
        glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN_EXT);
        glEndTransformFeedbackEXT();

vboBuff_1 is defined as dynamic array of GLfloat. When I comment lines related to transform feedbac I can see that the points are displayed correctly.

figured it out - the order of commands was not correct. Here is the correct one:

  1. compile + attach shader
  2. get varying variables from shader - glTransformFeedbackVaryingsEXT()
  3. link shader program
  4. create, bind VBO
  5. setup transform_feedback - glBindBufferBaseEXT
  6. then for in redraw() just use the same as is in the previous post