Skip to content

Instantly share code, notes, and snippets.

@wenchy
Created January 6, 2016 07:06
Show Gist options
  • Save wenchy/d1748d836b4b0b8d246e to your computer and use it in GitHub Desktop.
Save wenchy/d1748d836b4b0b8d246e to your computer and use it in GitHub Desktop.

Revisions

  1. wenchy created this gist Jan 6, 2016.
    21 changes: 21 additions & 0 deletions Vertex Array Object (VAO).md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    VAOs act similarly to VBOs and textures with regard to how they are bound. Having a single VAO bound for the entire length of your program will yield no performance benefits because you might as well just be rendering without VAOs at all. In fact it may be slower depending on how the implementation intercepts vertex attribute settings as they're being drawn.

    The point of a VAO is to run all the methods necessary to draw an object once during initialization and cut out all the extra method call overhead during the main loop. The point is to have multiple VAOs and switch between them when drawing.

    In terms of best practice, here's how you should organize your code:

    ```
    initialization:
    for each batch
    generate, store, and bind a VAO
    bind all the buffers needed for a draw call
    unbind the VAO
    main loop/whenever you render:
    for each batch
    bind VAO
    glDrawArrays(...); or glDrawElements(...); etc.
    unbind VAO
    ```

    This avoids the mess of binding/unbinding buffers and passing all the settings for each vertex attribute and replaces it with just a single method call, binding a VAO.