PDA

View Full Version : Transform Feedback problem



miroslav_karpis
05-18-2011, 01:21 AM
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_WRIT TEN_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_WRITTE N_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?

Godlike
05-18-2011, 03:56 AM
You need to inform the shader about the transform feedback varyings _prior_ linking it. In GL 3.x you glTransformFeedbackVaryings and then you link.

zeoverlord
05-18-2011, 03:58 AM
You need to bind the VBO your rendering from before glBeginTransformFeedback

Transform feedback tutorial (http://www.flashbang.se/archives/326)

kyle_
05-18-2011, 12:29 PM
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.

miroslav_karpis
05-18-2011, 03:47 PM
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?

miroslav_karpis
05-18-2011, 04:22 PM
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 );

miroslav_karpis
06-07-2011, 08:22 PM
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_WRIT TEN_EXT, query);
glDrawArrays(GL_POINTS, 0, numOfParticles);
// clean up transform feedback, retrieve count of processed particles
glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTE N_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.

miroslav_karpis
06-09-2011, 09:36 PM
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