OpenGL and texture units

Started by
2 comments, last by Doublefris 9 years, 6 months ago

When using multiple textures in my application, for framebuffers but also just samplers, should I bind them to different texture units? Like, a new texture could check which texture units are available and bind itself to one that is available, or is this unnecessary? Or maybe, since we are only allowed to have one texture target per texture unit, it's better to reserve certain textures for FBO uses and other for sampling? Please tell me how do you handle this, and does it make a difference efficiency wise or organizing your engine.

Advertisement

You bind a texture to a texture image unit in order to make it available to your active shader for sampling. You're going to have far more textures running around then you are going to have texture units. Like any state change you should do it no more than is absolutely necessary, which is why you batch your draw calls. Texture arrays and bindless textures will allow you to access more textures simultaneously while also decreasing the amount of state change.

it's better to reserve certain textures for FBO uses and other for sampling?
I'm not an expert but that's what I do.

TUs from 0 to 7 are for textures. 8 and on are for FBO attachments. This can be changed rather easily (defined in two places, one for shaders, other for the program, I'll have it defined in a single place someday). Limit is in the amount of textures bound per stage, not the texture unit number you use (although you can't use any TU number you want).

I don't claim its the best way to handle things though. You can come up with a system that dynamically binds whatever a shader program needs on the fly. I'm just saying I prefer convention over configuration, just to keep things simple.

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

it's better to reserve certain textures for FBO uses and other for sampling?

I'm not an expert but that's what I do.

TUs from 0 to 7 are for textures. 8 and on are for FBO attachments. This can be changed rather easily (defined in two places, one for shaders, other for the program, I'll have it defined in a single place someday). Limit is in the amount of textures bound per stage, not the texture unit number you use (although you can't use any TU number you want).

I don't claim its the best way to handle things though. You can come up with a system that dynamically binds whatever a shader program needs on the fly. I'm just saying I prefer convention over configuration, just to keep things simple.
What do you mean by 'per stage'? Lets say I am using 8 units for texture samplers like you, this means I can have for instance 2 samplers in my vertex shader and 6 samplers in my fragment shader?

This topic is closed to new replies.

Advertisement