PDA

View Full Version : get the currently bound VAO?



bsabiston
12-18-2012, 01:23 PM
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

tonyo_au
12-18-2012, 04:34 PM
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

Dan Bartlett
12-18-2012, 06:45 PM
glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &current_vao);

thokra
12-19-2012, 01:45 AM
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.