What does glUseProgram(0) do?

后端 未结 4 1049
暖寄归人
暖寄归人 2021-02-05 08:51

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

4条回答
  •  耶瑟儿~
    2021-02-05 09:09

    Contrary to a lot of answers here and elsewhere, glUseProgram(0) is not safe. 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.

    This may be useful to help avoid using the wrong program by mistake, but you should not use it to mean "use fixed-function mode". In most cases this is what happens, but it is not defined by the spec and should not be relied upon.

    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. However, it could just as easily keep the last shader, render garbage, or cause a segfault (I've seen this happen).

提交回复
热议问题