Binding different targets to same unit?

Can I bind and use two textures on the same texture unit if they have different targets? For example, is it correct to do this?:
glActiveTexture(GL_TEXTURE0 + 5);
glBindTexture(GL_TEXTURE_2D, diffusemap);
glBindTexture(GL_TEXTURE_3D, envmap);

And then use both of them in the shader?

In other words, does each texture unit support one texture, or one texture per target?

Can I bind and use two textures on the same texture unit if they have different targets?

Unfortunately yes. But you shouldn’t bother because:

And then use both of them in the shader?

No, you cannot. You can bind them, but you cannot use them. That’s why it’s unfortunately that the API allows you to bind textures with different targets to the same texture unit.

If you try to do so (by setting two different samplers to the same texture unit), you will get a GL_INVALID_OPERATION error at rendering time.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.