get the currently bound VAO?

Hello,

Is there any way to get the currently-bound vertex array object? I have some code where I am going to bind a VAO, but when the function finished I want to re-bind whatever VAO was active when I entered.

Thanks
Bob

I am not sure if there is but it can be more efficient to keep this type of information for your self rather then asking the driver since you don’t how much logic is going to be executed to get the info

glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &current_vao);

Why don’t you keep track of the currently bound VAO yourself?


struct BufferBindings
{
  GLuint previous;
  GLuint current;
};

// INIT - not a good variable name !
BufferBindings b = {0, 0}

// bind initial VAO somewhere
glBindVertexArray(vao0);
b.current = vao0;

// at some point, bind another VAO and save previous state
glBindVertexArray(vao1);
b.previous = b.current;
b.current = vao0;

// do stuff with vao1 here and afterwards reset state

glBindVertexArray(b.previous);
b.current = b.previous;
b.previous = 0;

This is extremely simple and only allows a maximum of two VAOs. I you want more, use a stack or similar data structure.