Sign in to follow this  

VBOs with dynamic meshes

This topic is 4702 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

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.

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
You'd call them in that order everytime you want to update the buffer, if thats every frame then yes you'd call it every frame.
You can put less data in than its size, but I dont know about more.
Logically, if the driver is reassigning the ID to a new buffer then it should be able to resize it to a larger size, but I cant say i've tried nor have I read anything about it, so just give it a go and see what happens [grin]

Share this post


Link to post
Share on other sites
hmm not working... I get the image but its all messed up now and is flickering.


glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_buffers[0]);

//update the vbo buffer with new terrain data
glBufferDataARB(GL_ARRAY_BUFFER_ARB, vbo_object_size, NULL, GL_DYNAMIC_DRAW_ARB);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, vbo_object_size, terrain, GL_DYNAMIC_DRAW_ARB);

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, nVertexStride, BUFFER_OFFSET(0));
glNormalPointer(GL_FLOAT, nVertexStride, BUFFER_OFFSET(nOffsetForNormals));



this is called every frame

Share this post


Link to post
Share on other sites
Do I need to enable the client states first?


glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);



then call the udpate functions? This makes no sense, my VBOs work fine until I try to call the update functions even I change the parameter to GL_DYNAMIC_DRAW_ARB from GL_STATIC_DRAW_ARB

Share this post


Link to post
Share on other sites
LOL I forgot I was using the same variable to determine object size for my element and array VBOs. And being static that was fine, so when I called the object_size variable again it was setup for elements and went nuts. So now I just have two seperate variables.

Share this post


Link to post
Share on other sites

This topic is 4702 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