-
Notifications
You must be signed in to change notification settings - Fork 103
Lua VBO and VAO
Read excellent intro here: https://learnopengl.com/Getting-started/Hello-Triangle
TLDR: it's a modern and most performant way of loading geometry attributes like position, color, normal vector, texture coordinates, etc to GPU for rendering.
VBO is simply an array of interleaved data. Interleaved means that data of different types go one after another forming an element. After the first element comes second element structured in the same way, etc. See:
Two main types of VBO are vertex buffer and index buffer. Vertex buffer holds vertex data, index buffer holds indices used to form triangles. One canonical example is rectangle. Rectangles have 4 vertices, but since GPU draws with triangles, rectangle needs to broken down into triangles. In this case triangles are specified as list of indices referencing vertex buffer to render the rectangle: P.S. Note the use of index buffer is optional, you can skip it, but you will have to duplicate vertex data instead to produce the same two triangles, which is often not desired, especially if you have big geometry.
One additional more advanced type of VBO is instance buffer. Unlike vertex VBO, which defines per-vertex data, instance VBO defines per instance (per shape) data. For example you might want to draw exactly the same complex shape N times in N different places, this is where instancing makes sense. You can read more here: https://learnopengl.com/Advanced-OpenGL/Instancing
As said in BAR105 spring instancing is done by means of instance buffer (alternative implementations are possible by out of scope of this basic tutorial): Here in the example we use instance buffer to offset instances of rectangle in screen space, other possibilities exist too: rotate, re-color, etc.
VAO serves as glue to tie together various VBOs above, description of their type, description of what each individual attribute inside each VBO means: name, size, type, etc. VAO allows one to define attributes completely flexible. Usually you want something like position, color, texture coordinates, but you can absolutely skip each one and supply whatever information you need. Below the schematic of what VAO is to VBOs: