Are there any negative effects of calling glCompileShader multiple times using the same shader id?

51 Views Asked by At

I am creating some classes to interface with OpenGL. One of them is GLSLShader. I want to glCreateShader in the contructor and call glCompileShader in a separate function called compile. So I wondered, if I call glCompileShader multiple times, would that cause a memory leak or any negative effects?

1

There are 1 best solutions below

0
Nicol Bolas On

Calling glCompileShader on a shader object will perform compilation based on the strings currently in that shader, functionally replacing the shader's useful contents. If you compile a shader, don't change the strings, and then compile it again, nothing meaningful should happen.

However, most programs don't do this, so in terms of actual OpenGL implementations, this is code that rarely gets tested. So it is possible that this is more than a no-op. It could rerun shader compilation rather than doing nothing. It might even leak memory if there's a bug in the implementation.

In general, this should never come up. The only reason to compile a shader is if you have set the shader's strings. That is, the sequence of operations is always "set strings, compile", in that order. If you don't do the former, there's no reason to do the latter.

So don't let people do it. Your compile function should be given the string(s) to compile as parameters.