Question when number of vao more that one

I have two vertex array objects. I defined as follows:

GLuint vao[2]
glGenVertexArrays(2, vao);

// binds the first object to be drawn
glBindVertexArray(vao[0]);

//binds the second object to be drawn
glBindVertexArray(vao[1]);

My question is, is it okay to define two vertex array objects like these for drawing two objects?

Because when I use the following syntax with glGenVertexArrays(1, vao) instead of glGenVertexArrays(2, vao), it gives the same result, but I associate two objects with two indices (0, 1) of the vertex array objects…

glGenVertexArrays(1, vao);

// binds the first object to be drawn
glBindVertexArray(vao[0]);

//binds the second object to be drawn
glBindVertexArray(vao[1]);

Can anyone explain me why?
Thanks in advance.

If vao is a global variable, it will be initialized to {0, 0}. So therefore “glGenVertexArrays(1, vao);” will generate a VAO in vao[0], but vao[1] will be left at 0, which is specified as the default VAO and which is valid to modify and use outside of core contexts.

You would probably see it blowing up spectacularly if you added a third VAO, but with only two, your “glBindVertexArray(vao[1])” call remains valid if the value of vao[1] is 0.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.