Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: Transform Feedback problem

  1. #1

    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:
    Code :
    void main()
    {	
      gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;
    }

    Init of buffers:
    Code :
    //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:
    Code :
    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, &amp;numOfParticles);

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

  2. #2
    Intern Contributor Godlike's Avatar
    Join Date
    May 2004
    Location
    Greece
    Posts
    70

    Re: Transform Feedback problem

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

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Feb 2006
    Location
    Sweden
    Posts
    744

    Re: Transform Feedback problem

    You need to bind the VBO your rendering from before glBeginTransformFeedback

    Transform feedback tutorial

  4. #4
    Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    268

    Re: Transform Feedback problem

    Quote Originally Posted by Godlike
    You need to inform the shader about the transform feedback varyings _prior_ linking it. In GL 3.x you glTransformFeedbackVaryings and then you link.
    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.

  5. #5

    Re: Transform Feedback problem

    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?

  6. #6

    Re: Transform Feedback problem

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

    added at the end of redraw()

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

  7. #7

    Re: Transform Feedback problem

    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:
    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.

  8. #8

    Re: Transform Feedback problem

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •