I’m writing an engine in OpenGL 3.2+. A renderable object has a mesh (a.k.a VAO) and a couple materials (a.k.a Shaders and Programs). All the renderables are stored in a render queue, which sorts the rendering process on materials and meshes in such a way that the least OpenGL bind calls are needed.
However, sometimes it binds objects which are already bound, my question is: does OpenGL automatically detect when you’re trying to bind an object which is already bound and does it skip all the expensive operations, or do you have to implement a system to detect if an object is bound already yourself?
If OpenGL does not detect this, is it likely faster to fetch the object name through glGet* and compare against the object you’re trying to bind or to just keep track of the currently bound object yourself?
I don’t believe specification requires to perform such checks, but every major implementation does. However, if you decide to do it yourself – why not just store values yourself? glGet have no particular interest here. Btw, material and shader are not the same things.