dynamic VBO geometry

Started by
3 comments, last by Hybrid666 19 years, 1 month ago
hi, simple question really, i've quite happily got static VBO stuff working... but i need dynamic vertex data.. ( normals/tex coords etc can stay static i think.. but i guess once i can make one bit dynamic i could make any bit dynamic.. but thats for later ;) ) i looked at GL_DYNAMIC_DRAW_ARB and GL_STREAM_DRAW_ARB but can't find any examples that i can fully get my head around.. at the moment im calling glDeleteBuffersARB and then recreating (glBufferDataARB etc) every frame for 'dynamic' VBO's using GL_STATIC_DRAW_ARB, but i know this isn't the right way to be doing things.. and is slow! in it's simplest form i create my vertex VBO in a one-off function: glGenBuffersARB(1, &vboID); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboID); glBufferDataARB(GL_ARRAY_BUFFER_ARB, numVerts*sizeof(VERTEX), vertexArray, GL_STATIC_DRAW_ARB); and draw using render loop: glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboID); glVertexPointer(3, GL_FLOAT, 0, (char*)null); glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_INT, indexArray); any help on how to allow me to manipulate my vertices would be much appreciated! :) Hybrid
Advertisement
If you only want to replace part of the buffer than glSubDataBuffer() is the call you want (glMapBuffer can be used as well in a situation where you are generating the data on the fly it could be faster).

However, this can lead to sync issues with a buffer still being used when you update it so it could be easier to scrub the data and start the buffer again, however for this you dont want to glDeleteBuffers() as again you can take a sync hit.

To get around this both NV and ATI recommend that you do the following when refilling a buffer;

- Bind the buffer
- Call glDataBuffer() with the address of the data set to NULL
- Then call glDataBuffer() with the address of your real data.

The first call tells the driver that you no longer care about the data linked with that VBO Id and as such it is free to scrub it when its done with it. The second call can cause the creation of a new clean bit of memory for the new data to be placed into and then sent to the card, avoiding sync issues.
hi, cheers for advice, code now looks like this:


initialise:

glGenBuffersARB(1, &vboID);


render:

glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboID);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, 0, NULL, GL_STATIC_DRAW_ARB);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, numVerts*sizeof(VERTEX), vertArray, GL_STATIC_DRAW_ARB);
glVertexPointer(3, GL_FLOAT, 0, (char8*)null);


does that seem right? (it works, but is it the best way as far as u can tell?)
and am i right using GL_STATIC_DRAW_ARB in both my calls?

cheers, Hybrid
yeah, that looks right to me.
and yes, you've got the right token there as its set to mean 'data is given once and used many times', as such the drivers stand a pretty good chance of shoving it into video ram for you
great stuff thanks! :D

This topic is closed to new replies.

Advertisement