Skip to main content
GameDev.net gamedev.net
🔒 Locked

Indices and Vertex Buffer Objects

Started by jframosr Nov 4, 2004 at 8:41 AM 5 replies 750+ views
Original Post
jframosr
jframosr
Hi folks! I am getting crazy with VBO...so my problem is the following: My mesh is composed of 'n' triangle strips and my mesh changes in some cases in my application, so right now, I always upload the indices to my triangle strips in this way, in the display function: for (i=0;i, GL_UNSIGNED_INT, this->vStrips); ... } But I think my perfomance will improve if I only upload the strips that change and not every strip every time. Thanks in advance. F.
DANNER
DANNER
You're correct. The best policy is to change only what you need to when you need to. Associate a "dirty" flag with each strip and set it whenever it needs to be updated.
DANNER
DANNER
Also, note that you can put your indicies into a buffer object. I'm guessing that your indicies are unlikely to change much (unless your mesh is changing as well). This can increase your performance as well.
jframosr
jframosr
Thanks for your reply.

I already have flags to control what strip changes and what not.

The application will manage arbitrary meshes with level of detail, so my indices will change very much, although between levels of detail only a few srips will be modified, thus...

Must i use a buffer object for each strip?
Will be it better than use my currently approach?
How do I implement it to be dynamic?

thanks in advance
F.
DANNER
DANNER
Quote:
Original post by jframosr
Thanks for your reply.

I already have flags to control what strip changes and what not.

The application will manage arbitrary meshes with level of detail, so my indices will change very much, although between levels of detail only a few srips will be modified, thus...

Must i use a buffer object for each strip?
Will be it better than use my currently approach?
How do I implement it to be dynamic?

thanks in advance
F.

As a rule of thumb, If it's likely that the mesh will change each time you draw with the buffer you're probably better off not using a VBO for the verts.

When you use a VBO, you're basically telling the driver that you want the verts in fast graphics memory (like on board memory). It slow to transfer verts between system memory and graphics memory, but it's faster to render with graphics memory. So generraly you want to put stuff in a VBO that gonna stay in graphics memory for a long time and drawn with very little change. The exact balance of when to use a VBO and what you should set the usage flag of a VBO to, depends on your data set and the hardware you're targeting.
jframosr
jframosr
I think I have not explained very well my problem.

The vertices never changes, only changes the strips depending on the LOD that you demand, so Vertices are static data and indices to strips are dynamic.

Take a look my little code please:


------------------------------------------------------
// .1. only once at inicilization

//variable declaration
GLuint vertex_buf;
int size = TOTALVERTS * 3 * sizeof(float);
float *vertices=new float[TOTALVERTS*3];


glGenBuffersARB(1, &vertex_buf);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertex_buf);

//Fill vertices
...

//upload data
glBufferDataARB(GL_ARRAY_BUFFER_ARB, size, vertices, GL_STATIC_DRAW_ARB);

delete [] vertices;

// uses ARB_VBO
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertex_buf);
glVertexPointer(3, GL_FLOAT, 0,0);
// activate vertex array
glEnableClientState(GL_VERTEX_ARRAY);

---------------------------------------------------------
// .2. Render Loop

for (i=0;i...
glDrawElements(GL_TRIANGLE_STRIP, size_strip, GL_UNSIGNED_INT, this->vStrips) ;
...
}

So I use VBO only with my vertices, which are static data, but, on the other side, strips are changing as long as the applicaction change the level of detail, thus, the indices are dynamic, but I dont know how to implement it with VBO :(, right now I always upload every index of every strip with DrawElements.
Of course, my intention is to draw every strip, but only upload those which change. (I already have some 'dirty' flags to know which strips change between lod)

Could you help me please.

thanks in advance.F.

zedzeek
zedzeek
look into element_buffer (explained in the VBO spec), it works with the indexs of drawelements (u might wanna use drawrangeelements as well)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.