Jump to content
  • Advertisement
Sign in to follow this  
Doublefris

OpenGL OpenGL and texture units

This topic is 1521 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!