I have to draw a buffer that holds a couple thousand vertices. I am using a vbo to store the data.
I know I will have to update the VBO many times - but only in small parts at a time.
So I am wondering what the best method to doing so is:
- Split VBO up into smaller VBOs (that hold like 300 verts) and then update individual VBOs with 1 call?
- One big VBO and use lots of
glBufferSubData()
calls? - Use
glMapBuffer()
and one big VBO?
There is another option, which is a bit like option 3 - use one big VBO (probably with
GL_STREAM_DRAW
mode) that is reset each frame (by callingglBufferData
with aNULL
buffer pointer and the same size each time) thenglMapBuffer
-ed right away. The buffer is left mapped as it is filled in, then unmapped just before drawing. Repeat.The call to
glBufferData
tells OpenGL that the old buffer contents aren't needed, so theglMapBuffer
doesn't have to potentially wait to ensure the GPU is finished with by the GPU.This approach seems to be the one officially sanctioned by the
vertex_buffer_object
extension. See the "Vertex arrays using a mapped buffer object" example:http://www.opengl.org/registry/specs/ARB/vertex_buffer_object.txt
This suggests that OpenGL (or the driver?) will be watching for this sort of behaviour, and (when spotted) arrange things so that it is performed efficiently.
If think that glBufferData or glMapBuffer are the better solution if your buffer is small.
100000 * sizeof(float) * 3 ~= 1MB
. There should be no problem with that.