title: When is What bound to a VAO?
body: <p>I've been learning OpenGL for three days and I can get stuff done but I feel like copy pasting without knowing what I'm doing. I seriously think I lack basic understanding about when is exactly <em>what</em> (VBO, attributes, ...) bound to a Vertex Array Object (VAO), and haven't found any resources that clarify these aspects in detail.</p>
  
  <p>In particular, these are some of my issues. If I create a VAO:</p>
  
  <pre><code>GLuint vao;
  glGenVertexArrays(1, &amp;vao);
  </code></pre>
  
  <p>can anything get bound to it before I bind the VAO? (if I create a VBO now, is it bound to the VAO?)</p>
  
  <pre><code>glBindVertexArray(vao);
  </code></pre>
  
  <p>After binding the VAO, if I create a VBO:</p>
  
  <pre><code>GLuint vbo;
  glGenBuffers(1, &amp;vbo);
  </code></pre>
  
  <p>is it bound to the VAO? Or does it happen when I bind it?</p>
  
  <pre><code>glBindVertexArray(vbo);
  </code></pre>
  
  <p>Or maybe when I copy something to it?</p>
  
  <p>If I get an attribute location:</p>
  
  <pre><code>att = glGetAttribLocation(program_id, "name");
  </code></pre>
  
  <p>is it bound to the VAO? Or does it happen after enabling it:</p>
  
  <pre><code>glEnableVertexAttribArray(att);
  </code></pre>
  
  <p>... or after setting it:</p>
  
  <pre><code>glVertexAttribPointer(att, ...);
  </code></pre>
  
  <p>?</p>
  
  <p>I guess EBOs behave just like VBOs, so I hope the same "rules" apply. </p>
  
  <p>Uniforms should behave like globals, so they shouldn't be affected by VAOs at all.</p>
  
  <p>Now, about unbinding:</p>
  
  <p>If I "bind" a VBO to a VAO, and then unbind the VBO, does it get detached from a VAO? </p>
  
  <p>If I have a VBO that is bound to multiple VAOs, what happens when I unbind that VBO?</p>
  
  <p>And about freeing resources:</p>
  
  <p>What happens when I delete an VBO? Does it get deleted from all the VAOs ? Or do they still have "dangling references" to that VBO?</p>
  
  <p>And about programs:</p>
  
  <p>IIUC I can reuse VBOs between programs. However, if VAOs bind attributes and VBOs, and attributes take a program parameter, can I reuse VAOs between programs? Why do attributes take a program parameter at all? </p>
  
  <p>And about debugging:</p>
  
  <p>Is there a way to pretty print the OpenGL state machine? I would like a way to know the programs that have been linked, with which shaders, which VAOs are there, which VBOs are bound to which VAOs, which attributes are bound to which VAOs and VBOs, have they been set? are they enabled? which uniforms are there... </p>
  
  <p>And about drawing calls:</p>
  
  <p>Suppose someone gives me a VAO, and I have to draw it. Is there a way to know if I should be calling  glDrawArrays or glDrawElements? Can I query somehow this information from a VAO? Maybe along with the sizes of my VBOs stored in there?</p>