I have a shader that has something like a dozen color/texture pairs. All the textures are optional. I am trying to figure out, how to implement this, without the need to recompile the shader. So I have:
I don’t want to use #ifdefs for the texture2D lookup. So when there is a texture, I set the diffuseColor to black. I’m wondering, if the opposite variant is working properly - to disable texturing and expect texture2D to return black. Sometimes I get weird results, but can’t tell if this is the cause of the problem or I’ve messed something else … Is the texture2D defined when texturing is disabled, i.e.
to disable texturing and expect texture2D to return black.
Sampling from a texture unit to which nothing is bound either returns white or undefined values; I don’t remember which, but black isn’t what you’ll get.
Is the texture2D defined when texturing is disabled, i.e.
That code doesn’t disable texturing. The glEnable/Disable calls for texture types only matters for fixed-function rendering. It means nothing for GLSL. You “disable” texturing by binding nothing to that texture unit.
Or is there a better way to do this?
The possible solutions are:
1: Have multiple shaders.
2: Use #defines
3: Use a uniform to tell whether to sample from the texture or not.
#3 is probably not the best, since you’ll be putting your texture function in non-uniform code. And that won’t work unless you use textureGrad.
Thank you for the quick reply. I’m wandering, if I can just create a black texture and use it when real texturing is not necessary… But this will take a texture slot, so probably not a good idea either…
I assume a non-bound texture counts as not complete, but the spec should really state something about it. I guess you could bind an incomplete texture to follow the spec, or a small (2x2 or so) black texture.
Nope, all textures start as 0x0 (incomplete) according to state tables. Unless there is some exception to 0 textures, which i wouldnt be surprised, as they are special anyways.