PDA

View Full Version : glBufferSubData vs glMapBuffer



debonair
11-20-2013, 05:21 PM
I have code in which i am rendering for thousands of frames, and in each frame I am updating vertex data. In this case which would be the best way to update buffer data? which one is faster and how?

Dark Photon
11-21-2013, 05:42 AM
As always, it's going to depend on your drivers. That said, a streaming buffer object approach can be very fast. For details, see this (http://www.opengl.org/wiki/Buffer_Object_Streaming).

mhagain
11-21-2013, 08:35 AM
It's also going to depend on whether or not you're using them to update the full buffer, or just a portion of the buffer. If you're just updating a portion of the buffer, there are several problems with raw glMapBuffer (i.e. without "Range"), including the fact that you can't specify that you're going to write to an area of the buffer that is not currently in use for drawing, and you can't specify how much of the buffer you're going to write to, so the driver must assume the worst. This typically means that it will always block until pending commands complete, and will always need to flush the entire mapped buffer back to hardware on an unmap.

These are discussed in the "overview" section of the GL_ARB_map_buffer_range (http://www.opengl.org/registry/specs/ARB/map_buffer_range.txt) extension documentation.

Technically glBufferData (..., NULL, ...) before a glMapBuffer (without "Range") call should orphan the buffer so that it can be safely mapped without these issues, but as others have found, that doesn't quite work (http://www.stevestreeting.com/2007/03/16/glmapbuffer-how-i-mock-thee/).