So recently, I am following the cherno series about opengl and I love it. But there is a minor question that I’m wondering, why would I want to unbinding buffers and vao after init them? and then must rebinding the vao? why wouldnt i just draw it right the way? What is the purpose of unbidning? Also, I found a question on stackoverflow where the top answer stated that unbinding is nonsense. So at the end of the day, What is the purpose of unbinding? Because He didnt dive too far about unbinding in the video?
You don’t need to unbind buffers or VAOs. But as a program gets more complex, restoring state to its default value once you’ve finished doing whatever required changing the state makes it less likely you’ll have problems because some piece of state doesn’t have the value you assumed it did.
When calling draw functions (glDrawElements
etc), you need to have a VAO bound (in 3.x and later core profile). So you should bind the appropriate VAO before calling a draw function. Assuming that the one you created during initialisation is still bound will only work if you only have a single VAO. In non-trivial programs, you’ll have multiple VAOs and you’ll need to explicitly bind the correct VAO before each draw call.
So leaving a VAO bound at the end of initialisation doesn’t help you and risks making it harder to debug mistakes. E.g. if you try to modify a VAO but forget to actually bind it, you should get an error. But if you left one bound, you’ll just end up modifying some VAO which probably wasn’t the one you intended.