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_WRITTEN,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
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
",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
",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
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