Hello,
I've recently started to implemented the OpenGL4-renderer for my game engine. I've been using DirectX9 and 11 so far, and I've been used to binding textures/samplers globally to the device, and share them between shaders. Now it happens to be in my design that the texture bind commands are executed before actually binding the shader (that would be a bit more to explain, lets just say that for a good reason). Now in OpenGL this is a problem, since from what I understand I'd have to bind the shader program in order to set the sampler to the correct uniform location:
In my render queue, under normal circumstances these two command blocks
glUseProgram(shader);
....
glActiveTexture(GL_TEXTURE0 + slot);
glBindTexture(GL_TEXTURE_2D, m_texture);
glUniform1i(slot, slot); // I'm already requiring the samplers to be at the first uniform locations not to make things even more complicated -.-
would be executed in reverse order, so the sampler would be bound to the wrong shader program. I could of course safe the currently bound shader and textures, and whenever a shader is switched bind them again, but this appears rather dirty and unnatural and would require a few precautions on my side. Is there any native way to avoid this? I've read about uniform buffers, but they seem not to work with samplers (thats just great), any other ideas?