the Fiddler's picture

The Open Toolkit library 0.9.6

This release introduces:

  1. Automatic OpenGL error checking
  2. Generics for improved type-safety in the OpenGL bindings
  3. Bug fixes related to OpenGL 3.0 contexts on Linux
  4. Improved documentation in OpenTK.Graphics
  5. A new EFX example ("EFX: Reverb").

This release contains potentially breaking changes. Please read the release notes and known issues before upgrading.


Comment viewing options

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

I meant either 'bitmap' or 'bitmap_ptr'. I see now how that would confuse you ;)

edit: The pointer cases where it is 'paramname' without '_ptr' is my own doing I think, I was just trying to strip it off and see what would happen as I wrote the previous post.

Thanks for the hint, will try that (once I figure out how to check of a Parameter is a plain old pointer, the generator is quite a piece of "interesting code" hehe)

the Fiddler's picture

Damn, I'm ashamed of myself for this thing. It's the first piece of C# code I ever wrote and it shows! The amazing thing is that it works. I've thought to design a new, simpler tool, but the effort is just not worth it in the end.

Edit: I think there is an 'IsPointer' property in the Parameter (or Type) class.

Edit 2: The '*_ptr' names are simple textual substitutions for parameters with 'WrapperType.[Generic|Array|Reference]Parameter'.

Hint: Check the Function.CreateBody() method. It is the place to add additional debugging code.

Edit 3: Better open an issue to track this enhancement.

Inertia's picture

How about adding a simple bool condition that allows the Assert to be toggled on and off? Why I'm suggesting this is that some code does rely on a reliable result when calling GetError and if the Debug.Assert clears the error status, code will not work in debug builds but only in release builds.

....or let me rephrase that, does anyone know a better way to detect available texture formats than creating a dummy texture, call TexImage with desired format and then call GetError to see whether the attempt failed? In that situation an OpenTK debug build would report success on all formats.

the Fiddler's picture

You have a point there.

Right now, I'd suggest using a release build of OpenTK - there's little point in a debug version with debugging turned off. The larger issue is being able to enable/disable automatic error checking at runtime, without incurring overhead when the checks are disabled.

Two nice things with such an approach:

  • You'd be able to use the same OpenTK.dll in your debug and release builds.
  • The debug build of OpenTK return to its original purpose (debugging OpenTK itself, not your code ;) ).

There is a solution that gets as half-way there: since OpenTK routes all OpenGL calls through delegates, we can use Delegate.Combine to add a pre- and post-condition to each delegate call. This works brilliantly for everything other than functions with return values (the post-condition would swallow the real return value.)

Another approach would be to generate debugging stubs with Reflection/Reflection.Emit and reroute the delegates to call the stubs instead of the actual OpenGL functions. However, that could get complicated quickly and I'd rather avoid that.

Any other ideas?

Inertia's picture

Debug.Assert( DoAsserts && GL.GetError() == ErrorCode.NoError );

...and pray compiler optimizations recognize that the 2nd condition is irrelevant and does not have to be evaluated when DoAsserts==false? :P

It's a minor issue, but at least some note in documentation would be nice so people don't get even more complications when debugging a problem.

the Fiddler's picture

Fair enough, I'll add this feature. However I still wonder why use the debug dll if you'll turn off debugging anyway? :)

Inertia's picture
void Init()
  // code where intercepted GL.GetErrors pose no problem...
  foreach( Graphics.TextureInternalFormat tif in MyDesiredTextureFormats )
     // see whether formats are available, Debug.Assert won't swallow GL.GetErrors
  // more code etc.

This should give the exact same result regardless whether debug or release build. I believe Texture formats are the only situation where this is applicable (shader's compile&link-status can be queried) as you can not draw conclusions by supported extensions alone.

Like I said: a minor issue. But it would be good if this is written down in the documentation somewhere.