Jump to content
  • Advertisement
Sign in to follow this  
Hybrid666

dynamic VBO geometry

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

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
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

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!