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 3 of 3

Thread: transform feedback buffer - drawing from it and printing from it

  1. #1
    Intern Contributor
    Join Date
    Oct 2012
    Posts
    53

    transform feedback buffer - drawing from it and printing from it

    Hi

    I seem to be able to draw from my transform feedback buffer but i cannot seem to print legit values from the buffer (i only seem to get zeros). also, what's strange is that when i try to check the number of primitves written out, i seem to be getting 0. If I can attach the transform feedback buffer to the GL_ARRAY_BUFFER and sucessfully draw it, then shouldn't the number of primitives written out using glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRIT TEN,one_query); return a non-zero value and shouldn't i be getting non-zero values from my buffer when i print it?

    Below are the relevant portion of my code

    Code cpp:
    GLuint tfbo,one_query,result;
    GLfloat *printableData;
    GLuint vao;
     
    void renderScene(void) {
     
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
        glLoadIdentity();
        gluLookAt(0.0,0.0,5.0, 
                  0.0,0.0,-1.0,
                  0.0f,1.0f,0.0f);
     
        glLightfv(GL_LIGHT0, GL_POSITION, lpos);
        glRotatef(a,0,1,1);
     
        createTransformFeedback();
     
        glBindVertexArray(vao); //this has data that i can use to draw out successfully
        glEnable(GL_RASTERIZER_DISCARD);
        glGenQueries(1,&one_query);
        glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN,one_query);
     
     
        glBeginTransformFeedback(GL_TRIANGLES);
     
        glDrawArraysInstanced(GL_TRIANGLES, 0, 4, 40);
     
        glEndTransformFeedback();
     
        glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
        glGetQueryObjectuiv(one_query,GL_QUERY_RESULT,&result);
     
        glDisable(GL_RASTERIZER_DISCARD);
     
     
        //draws out from the transfer feedback buffer - THIS DRAWS WHEN UNCOMMENTED!!!!!
        //glBindBuffer(GL_ARRAY_BUFFER,0);
        //glBindBuffer(GL_ARRAY_BUFFER,tfbo);
        //glDrawArraysInstanced(GL_TRIANGLES, 0, 4,12);
     
     
        printBuffer();
        printf("query result%d\n",result);
     
     
        a+=0.1;
     
        glutSwapBuffers();
    }
     
     
    void createTransformFeedback(){
        //create the buffer that will store the tranform feedback data
        glGenBuffers(1,&tfbo);
        glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER,tfbo);
        glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER,sizeof(float)*16,NULL,GL_DYNAMIC_COPY);
     
     
        //associated output from vertex shader to the transform feedback buffer
        static const char* tf_varyings[]={"outpos"};
        glTransformFeedbackVaryings(p,1,tf_varyings,GL_INTERLEAVED_ATTRIBS);
        glLinkProgram(p);
    }
     
    void printBuffer(){
     
            printableData=(float *)malloc(16*sizeof(float));
        glBindBuffer(GL_ARRAY_BUFFER,0);
        glBindBuffer(GL_ARRAY_BUFFER,tfbo);
     
        printableData=(GLfloat *)glMapBuffer(GL_ARRAY_BUFFER,GL_READ_ONLY);
        if(printableData!=(GLfloat *) NULL){
            for(int i=0;i<16;i++)
                printf("x y z : %0.2f %0.2f %0.2f\n ",printableData[i+2],printableData[2*i+2],printableData[3*i+2]);
        }
        glUnmapBuffer(GL_ARRAY_BUFFER);
    }

    Inside main function,
    glutDisplayFunc(renderScene);


    I seem to get these print out results

    Code :
     x y z : 0.00 0.00 0.00
     x y z : 0.00 0.00 0.00
     x y z : 0.00 0.00 0.00
     x y z : 0.00 0.00 0.00
     x y z : 0.00 0.00 0.00
     x y z : 0.00 0.00 0.00
     x y z : 0.00 0.00 0.00
     x y z : 0.00 0.00 0.00
     x y z : 0.00 0.00 0.00
     x y z : 0.00 0.00 0.00
     x y z : 0.00 0.00 0.00
     x y z : 0.00 0.00 0.00
     x y z : 0.00 0.00 0.00
     x y z : 0.00 0.00 0.00
     x y z : 0.00 0.00 0.00
     x y z : 0.00 0.00 0.00
     query result0
    Last edited by Dark Photon; 10-28-2012 at 10:12 AM.

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,220
    Please use [ code ] ... [ /code ] or [ highlight=cpp ] ... [ /highlight ] tags (without quotes) to mark your source code -- keeps the indentation and makes it more readable. I've inserted them for you.

    Also, check for GL errors with glGetError. For instance, call a function like this:

    Code cpp:
    void check( const char header[] )
    {
      bool found = false;
      int  err;
     
      while ( ( err = glGetError() ) != GL_NO_ERROR )
      {
        fprintf( stderr, "GL ERROR at %s: %s\n", header, gluErrorString(err) );
        found = true;
      }
     
      if ( found )
        exit(1);
    }
    Last edited by Dark Photon; 10-28-2012 at 10:18 AM.

  3. #3
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    456
    This bit of code:
    Code :
    //draws out from the transfer feedback buffer - THIS DRAWS WHEN UNCOMMENTED!!!!!
    //glBindBuffer(GL_ARRAY_BUFFER,0);
    //glBindBuffer(GL_ARRAY_BUFFER,tfbo);
    //glDrawArraysInstanced(GL_TRIANGLES, 0, 4,12);
    won't be drawing using data from tfbo, because changing GL_ARRAY_BUFFER by itself doesn't change where the vertex data is pulled from, it requires a glVertexAttribPointer call or changing the current VAO to do that. The triangles drawn will probably still be coming from your original data.

Tags for this Thread

Posting Permissions

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