Login  Register

Re: glVertexAttribPointer and BindBuffer

Posted by elect on May 21, 2016; 12:58pm
URL: https://forum.jogamp.org/glVertexAttribPointer-and-BindBuffer-tp4036732p4036737.html

DearDaniel wrote
When I add it to my code, error occurs but it didn't mentioned anything about the error.
What's the error?

DearDaniel wrote
Also, as a follow up question, what is the difference between unbinding and without unbinding?
OpenGL is a state machine.

When you execute a drawing command, such as glDrawElements then it will executed the program bound at that moment, it will draw to the framebuffer bound at that moment, it will use the vertex array bound at that moment and so on.

Unbinding is a way to reset that current pointer resource, setting it somehow to a null, although the driver and OpenGL implementation have some default specifications for cases when there is nothing bound.

However, unbinding it costs as much as binding in terms of performances, so in general if you want to crazy optimize your code, you shouldn't unbind resources.

But be aware that this is a double edge sword, it might be dangerous and introduce bugs. Take for example this case that happened to me:
- you init vbo, ibo and vao of object A, but you leave vao A bound
- after that, you init vbo, ibo and vao of object B, but when you need to upload the indices, you have to bound first the ibo of object B to gl_element_array_buffer.
- since vao A is still bound, then you will modify its status -> crash/bug when you will try to render A

So, better start first with a safe approach and then later optimize