Is there any way to prevent the shader compiler from removing a uniform/attribute which it detects as not being used? I occassionally comment out parts of my shader for testing, but this causes problems in the rest of my program because suddenly certain names no longer exist (thus causing lookup errors, and errors when trying to set the value).
Is there any way to prevent the shader compiler from removing a uniform/attribute which
Share
No, but it’s not strictly necessary, depending on how you wrote your code.
The
glUniform*functions will happily take a uniform location of -1. And if you’re using program_pack420 and explicit_attrib_location, you can put your attribute indices, fragment shader outputs, UBO bindings, and texture unit bindings all in the shader. So you don’t have to query for active attributes, outputs, uniform blocks, or samplers.Note that we also have ARB_explicit_uniform_location in GL 4.3. So you can specify them in the shader, and they won’t be optimized out.
The only reason you would encounter this is if you were not giving OpenGL attribute indices yourself, either with explicit_attrib_location or with calls
glBindAttribLocationpre-linking. That’s terrible coding, and you shouldn’t have been doing it that way.Always tell OpenGL what your attribute locations are. You should never be querying them unless you’re writing a shader introspection tool.