Updating vertex data in a VBO (glBufferSubData vs glMapBuffer)

Mark Ingram picture Mark Ingram · Sep 3, 2012 · Viewed 12.4k times · Source

I want to update an object's list of vertices after a VBO has been created. I've seen both glBufferSubData and glMapBuffer and they both appear to do similar things, which means I'm now unsure which one to use.

My pseudo workflow is:

Create object
Begin vertex update (calls glBufferData with data = nullptr)
Update object's vertices
End vertex update (takes the updated vertices and either calls glBufferSubData or glMapBuffer)

Answer

Calvin1602 picture Calvin1602 · Sep 3, 2012

Both work.

If you intend to update the vertices often (every frame or so), I recommend avoiding glBufferSubData, which requires one more memcpy in the driver. glMapBuffer/glMapBufferRange usually gets you more perf.

If you update only rarely, glBufferSubData will do fine.

See also chapter 28 of OpenGL Insights ( free : http://openglinsights.com/ )