I have a scene. Sometimes I draw untextured, coloured, semi-transparent triangles, sometimes I texture them, and I draw a lot of both in a fairly interleaved manner.
In a fixed function pipeline the difference would be if I had set the GL_TEXTURE_2D
to be 0 or a texture handle. My codebase is being migrated from FFP to OpenGLES 2, so these bindings to 0 already exist everywhere they are needed. My ambition is for my generic OpenGL code to run on both OpenGL 1.x and OpenGLES 2. So I'm looking for shaders that are a cut-down FFP imitation.
How can an OpenGLES 2 shader know if the Sampler2D
is set to 0 or has a valid texture?
My reasoning is that an if-statement that all fragments take the same branch is much cheaper than switching program pretty much every other statement as I alternate between textured ops and fixed-colour ops.
If I add a uniform then I have to go visit my code and each time I bind a texture I'll have to add a call to set the uniform flag. I have a large codebase that I have to ensure I am strictly setting it appropriately.
If I introduce a opaque white 1x1 texture this is like the uniform - I have to go everywhere in the code base ensuring I am binding it instead of binding to 0 to get colour-only primatives.
So I'd much prefer an approach where the sampler is interrogated in a shader. Is this possible?