The OpenGL docs for glUseProgram
claim that calling it with an argument of zero will cause the results of shader execution to be undefined
.
However, after a little searching I've seen a couple examples of people using glUseProgram
to uninstall the current shader program.
Is this behavior reliable? If not, then what exactly does glUseProgram(0)
do?
glUseProgram
means that the given program object is the current program that will be used for things that use programs (glUniform
, rendering commands, etc). 0 is a lot like NULL
for OpenGL objects. It represents not an object (for most objects). Therefore, glUseProgram(0)
means that no program is current, and therefore no program will be used for things that use programs.
If you attempt to call the glUniform
functions when no program is current, they will fail with an error. If you attempt to render when no program is current, one of two things will happen. In OpenGL 3.1+, core profile, you will get undefined behavior, because core OpenGL must render with a program. In compatibility profiles or version 3.0 or less, you will get fixed-function rendering.
Contrary to a lot of answers here and elsewhere, glUseProgram(0)
does not revert to fixed-function mode. It is not safe to use it this way. You can use it to set the rendering state to an invalid program object, but if it's still bound to this when rendering occurs, the behaviour is undefined.
From the doc:
"If program is zero, then the current rendering state refers to an invalid program object and the results of shader execution are
undefined
"
Therefore the results are entirely specific to OS, driver and graphics card. In many cases it appears to revert to fixed-function mode, but this is not defined by the spec and should not be relied upon. It could just as easily keep the last shader, render garbage, or cause a segfault (I've seen this happen).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With