Narek
Narek

Reputation: 39881

VBO usage has no sense if I update the vertex array data on each update

I understand VBO as a cache in GPU memory that is very fast and can store vertex array data. Now before each draw GPU should find out what should it draw and for that before you should set vertex array data using, for example, glVertexAttribPointer. Now it should copy the values to GPU. In order not to copy each time you specify a memory that should be used each time. But what if on each update I should change VBO, i.e. should again copy from CPU to GPU. What is the difference then?

Upvotes: 0

Views: 161

Answers (2)

derhass
derhass

Reputation: 45322

The transfer from host memory to VRAM (if such a thing actually exsits) is only one aspect of VBOs. The VBO does not have to reside in VRAM. The GL implementation will decide the location based on the hints you give it, and some second-guessing based on the observed access pattern. For a buffer which is updated per frame, it is highly likely that it will never be allocated in VRAM, but in the GART area in host memory, which is just mapped to the GPUs address space.

You should be aware that modern GL implementations are multithreaded and operate highly asynchronous. Drawing without VBOs has some serious implications. As the client memory is totally out of the GL's control, it must have taken care of the data before the drawing function can return (since you may modify that memory right after). So it either has to wait until the draw call is finished (implicit synchronization which is very bad for overall performance), or it has to make another copy of the data to be able to return early and handle the draw call later.

Using buffer objects actually eliminates such extra copies. This is especially true if you work with mapped buffers in the first place. No matter if you load your data from file or computate them on the fly or whatever, you can directly store it in a mapped buffer instead of ordinary client memory.

Upvotes: 3

MuertoExcobito
MuertoExcobito

Reputation: 10039

With client buffers (no VBOs), memory is copied on demand from the vertex/index buffers to the GPU each time a draw call is made. With VBOs, the memory can be transferred from CPU in multiple ways, each with consequences for performance (due to synchronization), and memory (due to potential multi-buffering).

If you only ever make one draw call, using the entire buffer in the draw, and update the entire buffer each frame using a synchronized update, such as glBufferData, then likely the driver will perform identical operations to perform the commands, and the results will be identical. Although, this isn't guaranteed.

You should read this article on buffer streaming, which explains the different methods of updating buffers, none of which are available without VBOs. These update methods may provide more efficient streaming, if you can utilize them.

Upvotes: 1

Related Questions