Sign in to follow this  
DrPowers

Using VBOs for dynamic vertex arrays

Recommended Posts

I'm trying to render an array of colored points. I'd like to use VBOs so that the memory exists on the graphics card. Another requirement is that I will have to be able to change several of the points in the array every time I call Draw(). Would I have to call glBufferDataARB() each time I change the values in the Vertex array? Or is there a faster way?

Share this post


Link to post
Share on other sites
Check out this whitepaper from nVidia. It has tons of info about VBOs and it also lays out some "best practices". Now, to answer your question, yes you can use VBOs for dynamic data. When you call BufferData the last parameter is a hint to the driver which helps it decide where the data will actually be stored. If you never change the data, you use STATIC_DRAW. If you change the data often, but it will likely be rendered several times between updates, you can use DYNAMIC_DRAW. If you change the data every frame before drawing, you would use STREAM_DRAW. With STATIC_DRAW, there is a good chance the data will be on the GPU, but you don't know for sure, again the driver decides. With DYNAMIC_DRAW and STREAM_DRAW the data could go to AGP memory or even system memory. It should still be fast because the driver may be able to do some slick streaming and caching with the data behind the scenes. An important thing to do if you are updating your VBO often (and this is in the whitepaper) is to call BufferData with the new size of the data you are passing (second paramter), and then a 0 (NULL) for the data pointer (third parameter). Then call BufferSubData right after that with the actual data pointer. The problem is, the GPU may still be drawing from the old buffer, and if you just call BufferData with a pointer to your new data, you will stall the pipeline. By passing NULL, the driver can allocate a new area of memory for your updated data to go to. Meanwhile it can keep rendering from the old buffer without stalling. Then it will clean up the old buffer automatically when it is done rendering. HTH.

Share this post


Link to post
Share on other sites

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