What are VBO and VAO?

VBO - It stands for Vertex Buffer Object. For example, we want to draw triangles. We create float array which contains position data of the three vertices. OpenGL can not use this data directly from CPU. We have store this data in GPU to use it. We will use VBO for uploading vertex data to GPU. We can think VBO as array in GPU like float array which we created in CPU side. For detailed information from Vertex Specification - OpenGL Wiki (khronos.org)

We can create vbo for vertex position data, and also we can create another vbo for vertex color data. But also, we can create just one vbo for both data.

VAO - It stands for Vertex Array Object. OpenGL could not know how to use the data from vbo. We have to explain this data what is it to OpenGL. So, we will do this describing operation with attribute pointers. However, we will have to do this every time when we use it. As a solution we can cache this attributes via VAO at once. So we don't need describe the data anymore in the source code. You can take a look this article also: Tutorial2: VAOs, VBOs, Vertex and Fragment Shaders (C / SDL) - OpenGL Wiki (khronos.org)

VBO and VAO
Creating VAO and VBO Step by Step:
  1. Create vertices float array to draw something.
  2. Define vbo and vao interger typed variables.
  3. Create VAO using GenVertexArrays(1, vao). (We will just use one vao)
  4. Bind this vao using BindVertexArray(vao). After this command, the vao was activated in OpenGL global state.
  5. Create VBO using GenBuffers(1, vbo). Because we have just one vbo to use it currently.
  6. Bind this vbo to ArrayBuffer using BindBuffer(BufferTarget.ArrayBuffer, vbo). We activated vbo in short. After that we can load data(vertices) to the vbo. 
  7. Copy the data to vbo using BufferData(BufferTarget.ArrayBuffer, sizeof(float) * vertices.Length, vertices, BufferUsageHint.StaticDraw).
  8. Now we are going configure attributes. These attributes have index from 0 to 15. 0. index is about position. We will just set one attribute for now:
    1. EnableVertexAttribArray(0)
    2. VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 0, 0)
  9. Unbind vbo using BindBuffer(BufferTarget.ArrayBuffer, 0);
  10. Unbind vao using BindVertexArray(0);

No comments:

Post a Comment