protongun's picture

OpenTK Debug Assembly Doesn't Throw Exceptions for Shader Compilation and Linking Errors

From what I understand, the debug version calls GL.GetError() after every GL command, and if an error is returned, OpenTK throws an exception.

However, shader compilation and linking errors are not thrown as exceptions, probably because they are not reported by GL.GetError() but rather by GL.GetShaderInfoLog() and GL.GetProgramInfoLog().

Am I doing something wrong or does OpenTK just not check the shader logs and throw exceptions?


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Frassle's picture

OpenTK does not check the shader logs automatically.

protongun's picture

Wouldn't it be a good idea to add that check to the debug version?

the Fiddler's picture

Maybe. This would require support for function-specific patching in the binding generator, which is doable but would add complexity. There are no plans to implement something like this currently, but if someone comes up with a patch that is not too terrible to maintain then I wouldn't be opposed.

However, my feeling is that shader compilation failure would be better handled either one level higher, in your graphics engine, or one level lower, using apitrace. OpenTK is simply a bridge between C# and the OpenGL driver - its purpose is to transfer your commands with as little overhead as possible, but otherwise get out of your way.

Frassle's picture

As Fiddler said it requires calling 3 OpenGL functions to compile and check for errors (CompileShader, GetShader(CompilerStatus), GetShaderInfoLog). Which is more overhead and means changing the binding generator to special case CompileShader methods to write out the relevant code (really painful in the current binder, a bit easier in my Silk binder).

You could always write you own wrapper for CompilerShader (eg F#)

    let compileShader shader = 
        let status = GL.GetShader(shader, ShaderParameter.CompileStatus)
        if status = 0 then
            failwith (GL.GetShaderInfoLog(shader))