Search code examples
c++openglgraphicsvbovao

Do I need to call glEnableVertexAttribArray if I use VAOs?


I understood that VAOs can store bindings to VBOs and index VBOs (both GL_ARRAY_BUFFER and GL_ELEMENT_ARRAY_BUFFER), but now I have a question:

void render()
{
    ..Set up textures, uniforms..

    glBindVertexArray(vaoId)); // This also binds VBOs and indices VBOs 
    automatically (if it was properly set up)

    glEnableVertexAttribArray(0); // Do I need this?
    glEnableVertexAttribArray(1); // Do I need this?
    glEnableVertexAttribArray(2); // Do I need this?

    glDrawElements(GL_TRIANGLES, indices_N, GL_UNSIGNED_BYTE, 0);

    .. cleanup..
}

Do I still need to call glEnableVertexAttribArray even if I already bound a VAO properly set up?


Solution

  • This is not necessary. You should have already called glEnableVertexAttribArray during the VAO setup so they get enabled automatically when the VAO gets bound.