Skip to content


[Graphics] Add OpenGL error detection to the new calli-based bindings #26

thefiddler opened this Issue · 7 comments

2 participants


Debug versions of OpenTK used to detect and convert OpenGL errors into exceptions. This functionality is missing from the new calli-based bindings.

This requires the following modifications to the Generator.Rewrite project.

  • Wrap all OpenGL and OpenGL ES entry point, excluding GL.GetError(), with:
using (new ErrorHelper(GraphicsContext.CurrentContext))
  // calli
  • Add the following code to GL.Begin():
GraphicsContext.ErrorChecking = false;
  • Add the following code to GL.End():
GraphicsContext.ErrorChecking = true;

This functionality is very useful when testing OpenTK applications, so it would be nice to implement in the new bindings. This only affects debug builds, so performance of release builds is not impacted.


Postponing to 1.2


Started making some progress on this in my fork, very hardcoded at the moment but wraps around OpenGL calls.


Awesome, thanks for looking into this!

The previous implementation used the following hard-coded rules:
1. Every call is surrounded by using (new ErrorHelper(GraphicsContext.CurrentContext)) { /* actual call */ }
2. GL.GetError() is not surrounded, as that would cause infinite recursion.
3. GL.Begin() sets GraphicsContext.CurrentContext.ErrorChecking = false; before the OpenGL call.
4. GL.End() sets GraphicsContext.CurrentContext.ErrorChecking = true; after the OpenGL call.

The reason for 3 and 4 is that it is an error to call GL.GetError() inside a begin-end region, so ErrorChecking = false temporarily turns off error checking.

The original generated code is available here (warning, large file).


Would like someone to just double check the code, it probably needs a cleanup but it's functional.

Also should I rewrite history before pull request?


Please rebase against opentk/develop before issuing the PR. I'll double check the code to make sure it works as expected on .Net and Mono.


OK, I'm going to make some final tidy ups and get to to work for other namespaces not just OpenTK.OpenGL then I'll submit the pull request.


This is now merged.

@thefiddler thefiddler closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.