PDA

View Full Version : dynamic geometry and VBOs



jframosr
11-04-2004, 07:50 AM
Hi folks!
Hello, I am getting crazy with VBO...so my problem is the following:

My mesh is composed of 'n' triangle strips and these strips change 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<n;i++ {
...
glDrawElements GL_TRIANGLE_STRIP, size_strip[i], GL_UNSIGNED_INT, this->vStrips[i] ;
...
}

But I think my perfomance will improve if I only upload the strips that change, and not every strip every time.

How can I do this?

Thanks in advance.
F.

rgpc
11-04-2004, 05:31 PM
Pardon my ignorance but what does the code sample you supplied have to do with VBO? Your calling DrawElements() and passing it a pointer to your array of Indices.

A VBO call is more like...


glBindBufferARB ( GL_ELEMENT_ARRAY_BUFFER_ARB, VBO_IndicesBufferID );
glDrawElements ( GL_TRIANGLE_STRIP, size_strip[i], GL_UNSIGNED_SHORT, BUFFER_OFFSET(0) );To update the VBO Indices you bind the buffer, then map the buffer, then upload the new indices. If you don't want to do this every frame, then you don't. If you only want to do the strips that have changed, then you only do those strips...

jwatte
11-04-2004, 07:53 PM
If strips use the same modelview matrix and material (i e, you can DrawElements() right after each other without changing state) then you're likely to get better performance from using a triangle list rather than a triangle strip. The reason is that the per-call overhead to start a new primitive is pretty hefty, whereas a vertex cache hit (very common in triangle lists) is almost free (except for the extra 4 bytes across the bus).

That being said, DrawElements() isn't the best way to submit geometry. DrawRangeElements() is an improvements, for starters. After that, actually using VBO will probably add additional helpage.

Adrian
11-04-2004, 11:19 PM
Originally posted by jwatte:
If strips use the same modelview matrix and material (i e, you can DrawElements() right after each other without changing state) then you're likely to get better performance from using a triangle list rather than a triangle strip. The reason is that the per-call overhead to start a new primitive is pretty hefty, whereas a vertex cache hit (very common in triangle lists) is almost free (except for the extra 4 bytes across the bus).I found the fastest method in that situation was to pass the indexes through NVTriStrip, setting the primitive restart flag (if available) and making a single triangle strip draw call using VAR/VBO. There was a big difference in performance in my app compared with using triangle lists.

jframosr
11-05-2004, 01:04 AM
Thanks for your responses...I think I have not explained very well my problem.

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, &amp;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<TOTALSTRIPS;i++) {
...
glDrawElements(GL_TRIANGLE_STRIP, size_strip[i], GL_UNSIGNED_INT, this->vStrips[i]) ;
...
} 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.
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.

gmeed
11-05-2004, 06:18 AM
Do you want to store your indices in a VBO? The spec has examples of how to do this. Take a look at the parts about GL_ELEMENT_ARRAY_BUFFER_ARB.