Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing a VBO in an existing VAO

I have a VAO with VBOs for various vertex attributes: vertex positions, vertex normals, and the element array VBO (all STATIC_DRAW), such that rendering an instance simply requires:

glBindVertexArray(vao);
glDrawElements(GL_TRIANGLES, <count>, <type>, 0);

However, I want to draw multiple instances of an object (I'm restricted to the OS X GL 3.2 core profile BTW) with different vertex texture (s,t) coordinates for each instance. The texcoord VBOs use the STREAM_DRAW hint (although I might get away with DYNAMIC_DRAW).

Is it more efficient to bind the VAO, bind the current texcoord VBO, and set the attribute pointer via glVertexAttribPointer, finalize the VAO with glBindVertexArray(0) and draw the new instance with different texture coordinates? Or does the cost of updating a VAO make this a poor approach? What about updating the texcoord VBO with glBufferSubData in a bound VAO?

I'd really appreciate some feedback before benchmarking separate approaches, since the wrong choice will result in significant refactoring.

like image 344
Brett Hale Avatar asked Aug 30 '12 14:08

Brett Hale


People also ask

Does VAO bind VBO?

VBO's are only added to the state of the VAO when that VAO is bound. So any previously bound VBO's will not alter the state of the VAO that you are going to bind. The state of a bound VAO can be changed with the following calls: glEnableVertexAttribArray.

What is VAO and VBO?

A VBO is a buffer of memory which the gpu can access. That's all it is. A VAO is an object that stores vertex bindings. This means that when you call glVertexAttribPointer and friends to describe your vertex format that format information gets stored into the currently bound VAO.


1 Answers

Simply create multiple VAO. vertex array objects are lightweight, and they are used to setup vertex arrays all at once...

A VBO can be bound to multiple VAO, making your life easier and faster.

If you want, at some point, another attribute configuration, throw away the old VAO and create a new one.

like image 103
Luca Avatar answered Oct 05 '22 22:10

Luca