Sign in to follow this  

dynamic VBO geometry

This topic is 4661 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, 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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 4661 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this