Reputation: 734
I have been learning OpenGL by myself, and some concepts in OpenGL confuses me.
I understand that VBO is the buffer resides on the server side for undescribed data, VAO is the description of the VBO, and Program is the shader rendering pipeline used to display meshes to the screen.
what keeps confusing me is the relationship between all three of them, as I can see, after VBO is created and filled, VAO is the generated for program attributes specification. does that mean each time when we bind a VAO we have to use certain program ahead? please correct me if this is not correct. and some brief introduction about interactive between these OpenGL concepts would be great.
thanks
Upvotes: 1
Views: 1888
Reputation: 474266
does that mean each time when we bind a VAO we have to use certain program ahead
The VAO describes (among other things) the format of vertex data. As a part of that format, it describes which data goes to which vertex attributes. It does this by assigning attributes "locations".
Your vertex shader has a number of user-defined input variables. These inputs are each assigned a "location".
When you render, the vertex format specifies which VS inputs are filled in, based on the locations that match. Therefore, you don't have to restrict your usage of a VAO to a specific VS. But, you must use a VAO with a compatible program. One which has inputs that match the format's locations.
If your VAO specifies that attribute locations 0, 1, and 4 will be filled with floating point data, then any VS's you use with that VAO must be compatible with that. It technically doesn't have to actually use locations 0, 1, or 4, but if it does, it must use floating-point input values. Any unused locations provided by the format will effectively be ignored (though they will almost certainly still be read from the buffer).
If the VAO puts floating-point data in attributes 0, 1, and 4, but the VS expects unsigned integer data in attribute 1, then you have a problem.
Upvotes: 7