I've been writing some code to check if a texture, buffer, or shader is currently bound, and avoid binding it twice if it is.
if (lastShaderBound != shaderName) {
lastShaderBound = shaderName);
glUseProgram(shaderName);
}
However, there's a potential pitfall; if any of these objects are deleted while bound, OpenGL will implicitly unbind them and allow their GLuint name to be reused. This could result in my "state" of what's bound diverging from OpenGL's, (unless I try to duplicate this behavior, which is fairly complex).
I'm wondering if any of this is even necessary? If OpenGL is smart enough to unbind deleted buffers, perhaps it's already doing what I'm trying to do, or perhaps it's not the binding calls that are expensive in the first place?
Should I just freely bind things without worrying about the same thing being bound multiple times in a row?