PDA

View Full Version : Transform feedback buffer



HappyZappy
09-16-2010, 05:02 AM
Hi

I am new to OpenGL, Could anyone please let me know, how I can read or draw the transform feedback buffer.

First I am using GL_RASTERIZER_DISCARD not to draw on screen and after that once I'll get the output in a transform feedback buffer, drawing the whole buffer. But I am not able to get anything on screen nor any GL error. Could please let me know is there anything wrong here?


I've written the code -

main()
{
:
:
// setup shader
nResult |= ShaderInit(&shader_object);

nResult |= LoadTransformfeedbackShaders(&shader_object, vshader,fshader, 2, varyings,GL_INTERLEAVED_ATTRIBS);

nResult |= ShaderBindAttribLocation(shader_object, 0, "in_Position");
nResult |= ShaderBindAttribLocation(shader_object, 1, "in_Color");
//linking the shader
nResult |= LinkShader(&shader_object);
nResult |= ShaderGetUniformLocation(shader_object, "MVPmatrix", &uniform_loc);

nResult |= EnableShader(&shader_object);

glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);

// pass values into shader
glUniformMatrix4fv(uniform_loc, 1, GL_FALSE, MVP);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_TRUE, 0, vertex_data);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_TRUE, 0, color_data);

glUseProgram(shader_object.psId);

//Generating the query to get the written primitives
glGenQueries(1,&uiquery);

glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRIT TEN,uiquery);
//glBeginQuery(GL_PRIMITIVES_GENERATED,uiquery);

glEnable(GL_RASTERIZER_DISCARD);

glBeginTransformFeedback(GL_TRIANGLES);

glDrawArrays(GL_TRIANGLES,0,3);

glEndTransformFeedback();

glDisable(GL_RASTERIZER_DISCARD);

glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTE N);
//glEndQuery(GL_PRIMITIVES_GENERATED);

glGetQueryObjectiv(uiquery,GL_QUERY_RESULT,&icount );

tdkPrintf("%d Primitives written.",icount);
if (icount != 0)
{
glBindBuffer(GL_ARRAY_BUFFER,gVarForThisTestGroup. uixfb);
glDrawArrays(GL_TRIANGLES,0,icount);

}

// remove and deleteing shader object
:
:

}

LoadTransformfeedbackShaders(........)
{

//compiling and linking the vertex and fragment shader
:
:
:
//seting varying variables
glTransformFeedbackVaryings(pTdkShader->psId,count,varyings,GL_INTERLEAVED_ATTRIBS);

// linking the shaders
:
:
:
}

I am writing as varyings like -
char *varyings[]={"normals","gl_position"};

How to get access of both the arrays?

Thanks.

P.S. I am getting primitives written count = 1.

DmitryM
09-16-2010, 09:19 AM
I don't see where you call 'glBindBufferBase'. This function points transform feedback to the destination buffers, that you can use after as any other buffer objects.

Note: this is *not* a right forum section for you. Post on the beginners forum, please.