Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: get the currently bound VAO?

Hybrid View

  1. #1
    Intern Newbie
    Join Date
    Nov 2010
    Posts
    40

    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

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    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

  3. #3
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    450
    Code :
    glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &current_vao);

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128
    Why don't you keep track of the currently bound VAO yourself?

    Code :
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •