I make something working but … I don’t understand!
What I would like to do it is something like:
A: Create a single vertex array object. (VAO)
B: Create several buffer objects. (BO)
C: Bind the VAO
D: Loop over all BOs by binding them as array buffer object and draw.
This results to crashes.
If I unbind a buffer object it just crashes … (even at creation stage!)
But I was expecting a feature that allow fast buffer bind not a calls wrapper.
I would like somting like this:
The point of VAO is to get rid of the overhead of calling the gl*Pointer calls when using buffer objects. So the VAO must naturally store the buffer objects that the pointers are bound to.
One pattern with VAO might be to create a limited set of (ring) buffers (with a correspondingly limited set of formats) - pretty common nowadays. You could, at least in theory, utilize a single VAO for the whole enchilada.
// Establish vertex array buffer and format
BindVertexArray(vao);
BindBuffer(VERTEX_ARRAY_BUFFER, vb);
VertexAttribPointer(0, …);
VertexAttribPointer(1, …);
VertexAttribPointer(2, …);
…
BindBuffer(0);
BindVertexArray(0);
// Then to draw…
BindVertexArray(vao);
DrawArrays(…);
BindVertexArray(0);
I’m not exactly sure what the ring buffer patter would look like in GL3, but the new buffer mapping API looks like a good candidate for some trial and error…
I believe the problem with your example code (first post) is that you’re not calling VertexAttribPointer after binding the VBO. Remember, VertexAttribPointer latches whatever is currently bound to ARRAY_BUFFER. i.e. it should be: