Sign in to follow this  

[GLSL] Detecting if a sampler is set or not

This topic is 2846 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

Is there a way to tell from within the shader if a given sampler is set or not? Alternatively, can I specify the color value that is returned when a sampler is not bound in a shader? I'd rather not have to either write two shaders or bind a small single-color texture to do this.

Share this post


Link to post
Share on other sites
textureSize() ?

In any case, it's sub-optimal stuff to do the decision-making in the shader. And besides, what would you do in the case when there are other, valid textures bound to the sampler-units (0..31) ? If your cpu code doesn't change them, there will potentially be garbage: your C++ code won't be changing gl_texture1, but the shader will be seeing the previous drawcall's value for the sampler.
So, wise-up the cpu code.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ashaman73
I never encounter any option to check if a sampler is bound or not. But why don't you use an uniform to control your shader code instead of checking if a texture is bound ?


I actually hadn't thought of this. It's still not quite what I want, because it still requires data redundancy (both the uniform value and the texture index bound to the texture unit need to be kept in sync), but it's a possibility, thanks!

Quote:
In any case, it's sub-optimal stuff to do the decision-making in the shader. And besides, what would you do in the case when there are other, valid textures bound to the sampler-units (0..31) ? If your cpu code doesn't change them, there will potentially be garbage: your C++ code won't be changing gl_texture1, but the shader will be seeing the previous drawcall's value for the sampler.
So, wise-up the cpu code.


Yeah, I'd rather not do it in the shader. I think you misunderstand my intent, though. I'm aware that there could be garbage in the sampler units, what I want is to be able to *clear* a texture unit (glBindTexture(GL_TEXTURE_2D, 0)) and have the sampler return something like solid white so that a blank texture stage is effectively a no-op, similar to what you get with the fixed functionality pipe. Now I can do things like say "this model doesn't have a diffuse map" and still have the shader work. Otherwise I need to duplicate state (which stages are bound to textures) with a uniform, or duplicate the shader without that sampler and make a shader state change.


Share this post


Link to post
Share on other sites

This topic is 2846 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this