PDA

View Full Version : Question on VAO/VBOs



allenmoatallen
01-22-2013, 06:39 AM
Since the VAO needs to be completely setup during initialization, what is the best way to feed new vertex data to the GPU? Is it better to recreate the VAO and VBO or to simply pass new vertex and texture data to the VBO?

thokra
01-22-2013, 07:50 AM
A VAO does not hold any data. You simply update your VBO once the VAO is bound. The VAO remains completely untouched by updates to the VBO's data store.

allenmoatallen
01-22-2013, 08:08 AM
Correct. If I have a function named fillVertexArray(), would all I need to do is bind the VBO, call glBufferData() and then unbind? Or is there a step missing?

thokra
01-22-2013, 08:25 AM
When using vertex array objects you have to be certain that

a) you either update the buffer which is bound by the currently bound VAO
b) or you update the buffer while no VAO is bound at all, thus not altering the bindings of the currently bound VAO
c) or you you switch VAOs before updating the buffer you want

Action a) is preferable. Why? Because binding and unbinding costs time and if you can determine that a buffer needs to be updated shortly before you render from the currently bound buffer (and thus VAO), you don't need to switch either of them.

allenmoatallen
01-22-2013, 09:23 AM
When using vertex array objects you have to be certain that

a) you either update the buffer which is bound by the currently bound VAO
b) or you update the buffer while no VAO is bound at all, thus not altering the bindings of the currently bound VAO
c) or you you switch VAOs before updating the buffer you want

Action a) is preferable. Why? Because binding and unbinding costs time and if you can determine that a buffer needs to be updated shortly before you render from the currently bound buffer (and thus VAO), you don't need to switch either of them.

A) should work because right now I only have one VAO and one VBO. I wanted to reuse them for each object getting drawn but wasn't sure if that was the best practice. If I can simply update the buffer only as needed then great!

thokra
01-22-2013, 10:53 AM
IMHO, that is the way to go. The fewer unnecessary changes the better. However, buffer sizes should probably not exceed a few MB. Test various sizes until you reach max performance.

allenmoatallen
01-22-2013, 11:22 AM
And just to make sure I have the correct understanding... in my data update function should I be using glBufferData() or look into the glMapBuffer() calls? I thought all I needed was a glBufferData() but that doesn't seem to carry over to the actual rendering. I must be missing something...

rakeshthp
01-24-2013, 01:21 AM
How about glBufferSubData..??