Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating vertex data in a VBO (glBufferSubData vs glMapBuffer)

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)

like image 340
Mark Ingram Avatar asked Sep 03 '12 08:09

Mark Ingram


People also ask

What does glMapBuffer do?

glMapBuffer maps to the client's address space the entire data store of the buffer object currently bound to target . The data can then be directly read and/or written relative to the returned pointer, depending on the specified access policy.

How do I update my VBO?

The simplest method of updating VBO is copying again new data into the bound VBO with glBufferData() or glBufferSubData(). For this case, your application should have a valid vertex array all the time in your application.

What are OpenGL buffers?

Buffer Objects are OpenGL Objects that store an array of unformatted memory allocated by the OpenGL context (AKA the GPU). These can be used to store vertex data, pixel data retrieved from images or the framebuffer, and a variety of other things.


1 Answers

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/ )

like image 89
Calvin1602 Avatar answered Sep 24 '22 15:09

Calvin1602