VBOs with dynamic meshes

Started by
16 comments, last by _the_phantom_ 19 years, 2 months ago
I don't plan on using this kind of mesh in my game but my map editor will have to use dynamic meshes due to user will be changing variables all the time. Does VBO support this kind of super dynamic mesh style? If so what would be different about the setup of the VBO vs. a static mesh? I have a static VBO setup but never done a dynamic one. Thanks for the help or any ideas that might help solve this issue.
Advertisement
setup like normal, but change the flag to whatever indicates you are going to be writing to it and drawing from it but not reading from it (although, you might be able to get away with static still)

When updating the VBO invalidate the data first by calling the data buffering function with a NULL pointer and then updating the whole buffer, this avoids sync issues.
Yes, You tell opengl you will be useing it as a Dynamic mesh that will be changed many times, you just reupload it with glBufferSubDataARB(...);

Quote:From OpenGL® Extension Registry
DYNAMIC_DRAW_ARB The data store contents will be respecified
repeatedly by the application, and used many
times as the source for GL (drawing) commands.
"I seek knowledge and to help those who also seek it"
Thanks all I will give it a try soon and see how it works out.
Quote:Original post by _the_phantom_
setup like normal, but change the flag to whatever indicates you are going to be writing to it and drawing from it but not reading from it (although, you might be able to get away with static still)

When updating the VBO invalidate the data first by calling the data buffering function with a NULL pointer and then updating the whole buffer, this avoids sync issues.


You mean like this?
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, object_size, NULL);
you dont want to subbuffer, you'll want to use the normal data buffer command, as you'll be invalidating the whole thing, not just a bit of it.
And the data reload want to be the normal buffering as well, as again you are refilling the whole buffer, not part of it.
Subbuffer probably also has to perform some sync checks, and while the overhead will be small to non-existant it still makes sense to avoid it when you can
Quote:Original post by _the_phantom_
you dont want to subbuffer, you'll want to use the normal data buffer command, as you'll be invalidating the whole thing, not just a bit of it.
And the data reload want to be the normal buffering as well, as again you are refilling the whole buffer, not part of it.
Subbuffer probably also has to perform some sync checks, and while the overhead will be small to non-existant it still makes sense to avoid it when you can


Ok I think I am going to get around to this tonight. You mean use BufferDataARB() instead of BufferSubDataARB()? So do I need to delete the old buffer every frame or just call
glBindBufferARB(GL_ARRAY_BUFFER_ARB, NULL);


To invalidate the buffer and then call

glBufferDataARB(GL_ARRAY_BUFFER_ARB, object_size, terrain, GL_DYNAMIC_DRAW_ARB);


to reupload the buffer data again? So I don't need to delete the buffer every frame unless I was going to change the size of the buffer correct?
You do not need to delete the old buffer by giving it a NULL pointer, but it is advisable to do so because it allows the driver to allocate new memory for you if needed, since it might still be using your old buffer. (The D3D docs mention that this kind of buffer lock discard may help prevent DMA stalls.) BufferData itself allows the driver to make some optimizations; BufferSubData forces synchronization, which is generally not a good thing. You don't need to delete the buffer every frame, just when you're changing something.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
your code should look like this
glBufferDataARB(GL_ARRAY_BUFFER_ARB, object_size, NULL, GL_DYNAMIC_DRAW_ARB);glBufferDataARB(GL_ARRAY_BUFFER_ARB, object_size, terrain, GL_DYNAMIC_DRAW_ARB);


in your orignal you were trying to bind a null buffer [wink]
(which is how you move from VBO to standard VA mode)
Quote:Original post by _the_phantom_
your code should look like this
*** Source Snippet Removed ***

in your orignal you were trying to bind a null buffer [wink]
(which is how you move from VBO to standard VA mode)


So I am correct in saying that I need to call those two functions one right after another every frame if I plan on updating my array of terrain information. And this will update the buffer with new data. So to make a buffer larger or smaller you would need to delete it and make a new one correct? or you can resize the buffer dynamically based on your needs after you make an initial buffer....

This topic is closed to new replies.

Advertisement