Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it better glBufferSubData or glMapBuffer

Tags:

opengl

In order to update my uniform buffer objects I use glBufferSubData. Is it faster to use glBufferSubData or glMapBuffer with glUnmapBuffer?

like image 278
zeb Avatar asked Aug 26 '15 09:08

zeb


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.

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.

How to use glmapbuffer with OpenGL?

Show activity on this post. The good thing about glMapBuffer is that you dont need to copy the data first in an array and then use glBufferSubData to fill the opengl buffer. With glMapBuffer, you can copy the data directly to part of memory which opengl will fetch to GPU when it is necessary.

Is there a glbuffersubdataarb() function?

nVidia mentions that it could have one if you call glBufferSubDataARB () when the GPU is already working on the area. But in your case, I think you are good.

Is it bad to write to two different buffers at once?

As a consequence there could be a loss of performance. if you use BufferSubData, then there is a synchronization so that you don’t write over a buffer already being used. however, if that is the first time you write to this buffer, there is no synchronization required, so your two API calls should not be that bad. AMD Fellow.


1 Answers

The good thing about glMapBuffer is that you dont need to copy the data first in an array and then use glBufferSubData to fill the opengl buffer. With glMapBuffer, you can copy the data directly to part of memory which opengl will fetch to GPU when it is necessary. From my point of view, there glMapBuffer should be faster when you want to fill a big buffer which is going to be updated frequently. Also, how you are copying the data into the buffer between glMapBuffer and glUnmapBuffer is also important.

If show us the code which you are using the glMapBuffer and how big is the data, then we can judge easier. Anyway, in the end measurements can show you which one is better.

UPDATE: OpenGL Insight Asynchronous Buffer Transfer Chapter. In this chapter, the implicit synchronization of glMapBuffer and glSubBufferData functions may be interesting for you.

like image 101
mmostajab Avatar answered Oct 18 '22 23:10

mmostajab