A vertex array object (VAO) keeps vertex-attribute configuration and buffer bindings together. OpenGL uses this state to manage different attribute layouts for shader programs. section 7.4.4
Create a VAO with glGenVertexArrays and delete it with glDeleteVertexArrays. To configure a triangle, bind its vertex buffer object (VBO) and the VAO, describe attribute 0 as two floats with glVertexAttribPointer, then enable the attribute. Bindings are implicit state, so keep them brief and reset them to 0 to avoid invisible side effects. section 7.4.4 section 7.4.5
Listing 7.12 An abstract object
var vao: c_uint = undefined; c.glGenVertexArrays(1, &vao); #1 defer c.glDeleteVertexArrays(1, &vao); #2
The minimal Zig snippet creates a VAO and schedules its deletion. section 7.4.4
Listing 7.14 Explaining our vertices to the VAO
{ #1
c.glBindBuffer(c.GL_ARRAY_BUFFER, triangle_vbo); #2
defer c.glBindBuffer(c.GL_ARRAY_BUFFER, 0); #2
c.glBindVertexArray(vao); #3
defer c.glBindVertexArray(0); #3
c.glVertexAttribPointer(
0, #4
2, #5
c.GL_FLOAT, #6
c.GL_FALSE, #7
2 * @sizeOf(f32), #8
@ptrFromInt(0), #9
);
c.glEnableVertexAttribArray(0); #10
}
The triangle setup binds a VBO and VAO, defines an attribute, and enables it. section 7.4.5
