Jump to content
  • Advertisement
Sign in to follow this  
donguow

Transform feedback buffer

This topic is 2504 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all,

I run into a problem when using Transform feedback buffer. Hope someone here can help me to figure it out.

Data structure:
[source]struct Vertex
{
GLfloat x, y, z; // position
};
struct Index
{
GLuint idx1, idx2, idx3;// The index of three vertices
// that make up the triangle
};[/source]

Relevant variables:

[source]GLuint vbo[2]; // two VBOs
GLuint tfvbo; // transform feedback buffer
GLuint query;
int nVerts; // number of vertices
int nIdxs; // number of triangles
Vertex vertices[1000000]; // the array of vertices that form the mesh
Index indices[1000000]; // and the array of indices[/source]

And here is how I used VBOs to draw the model:
[source]void setupVBO(void)
{
glGenBuffers(2, vbo);
// Vertex VBO
glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
glVertexPointer(3, GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(0));
//glNormalPointer(GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(12));
glBufferData(GL_ARRAY_BUFFER, nVerts * sizeof(Vertex), vertices, GL_STATIC_DRAW);
//glBindBuffer(GL_ARRAY_BUFFER, 0);
// Index VBO
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo[1]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, nIdxs * sizeof(Index), indices, GL_STATIC_DRAW);
//glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
// Transform feedback buffer
glGenBuffers(1, &tfvbo);
glBindBuffer(GL_ARRAY_BUFFER, tfvbo);
glBufferData(GL_ARRAY_BUFFER, nIdxs * 3 * sizeof(Vertex), 0, GL_STATIC_DRAW);
}

void drawVBO(void)
{
// Bind VBOs to be used
glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo[1]);

// Enable client state
glEnableClientState(GL_VERTEX_ARRAY);

glVertexPointer(3, GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(0));

glColor3ub(128, 128, 128);

// Draw VBOs
glDrawElements(GL_TRIANGLES, nIdxs * 3, GL_UNSIGNED_INT, indices);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);

// Disable client state
glDisableClientState(GL_VERTEX_ARRAY);
}

void render(void)
{
// Clear buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

// Save the initial ModelView matrix before modifying ModelView matrix
glPushMatrix();

// Transform camera
glTranslatef(0, 0, cameraDistance);
glRotatef(cameraAngleX, 1, 0, 0); // pitch
glRotatef(cameraAngleY, 0, 1, 0); // heading

// Transform feedback settings
GLint attribs[] = {GL_POSITION, 4, 0}; // vertex positions are selected to be stored
glTransformFeedbackAttribsNV(1, attribs, GL_SEPARATE_ATTRIBS_NV);
glBindBufferBaseNV(GL_TRANSFORM_FEEDBACK_BUFFER_NV, 0, tfvbo);
glBeginTransformFeedbackNV(GL_TRIANGLES);
glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN_NV, query);
glEnable(GL_RASTERIZER_DISCARD_NV); // disable rasterization

drawVBO();

glDisable(GL_RASTERIZER_DISCARD_NV); //re-enable rasterization
glEndQuery(query);
glEndTransformFeedbackNV();


//Redraw the model from transform feedback buffer
glBindBuffer(GL_ARRAY_BUFFER, tfvbo);
// Enable client state
glEnableClientState(GL_VERTEX_ARRAY);
//glEnableClientState(GL_NORMAL_ARRAY);

glVertexPointer(3, GL_FLOAT, sizeof(Vertex), BUFFER_OFFSET(0));

glDrawArrays(GL_TRIANGLES, 0, 3 * nIdxs);

// Disable client state
glDisableClientState(GL_VERTEX_ARRAY);

glPopMatrix();
glutSwapBuffers();
}
[/source]

The problem is when I try to redraw the model by using transform feedback buffer, its display looks pretty weird. Can someone help me to understand this?

Thanks in advance,
Dong

Share this post


Link to post
Share on other sites
Advertisement
Hi!

Frankly, I’ve never used the Nvidia extensions for transform feedback in combination with fixed function.
I’ve seen you specified your output like this:
GLint attribs[] = {GL_POSITION, 4, 0};
Does this mean the transform feedback appends the w-coordinate as well?
You only want xyz in your resulting buffer, right?
So, perhaps change that to:
GLint attribs[] = {GL_POSITION, 3, 0};

Could you tell us what you mean with weird?
Maybe attach a picture so we can get an impression. That would be nice. smile.png
Have you tried to render just the first triangle? Does it look good?

Cheers!

Share this post


Link to post
Share on other sites
Thanks Tsus,

Yep. It works now but the display is a little bit distorted :). I will try to figure it out and let you know soon

Cheers

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!