glBufferSubData vs glMapBuffer

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?

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.

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 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.