zzattack's picture

OSMesa context

In my quest to get an opengl context on my x11-less freebsd box that needed some simple off-screen renders I fought against OpenTK and soon enough it gave in.
I used OSMesa [1], [2] for this and would gladly contribute a patch [3] but I still feel too many hacks are involved. Here are the things I did:

- Added a class MesaContext : GraphicsContextBase which has some DllImports to osmesa.dll. On Mono this requires a dllmap entry to libOSMesa32.so.
- The MakeCurrent overload requires a BitmapWindowInfo : WindowInfo which contains a reference to a BitmapData which in turn points to an already-allocated bitmap area.
- Added method CreateMesaContext to GraphicsContext which instantiates a new MesaContext, much like DummyGLContext.
- Changed GraphicsContext.CurrentContext to enumerate available contexts checking IsCurrent on each.

My main 'issue' with this approach is that RunningOnWindows, RunningOnOSX and RunningOnX11 are all false, resulting in the default PlatformFactory becoming an UnsupportedPlatform. This is troublesome because GraphicsContext contains a static method GetCurrentContext() that relies on a platform-dependent feature that is able to return the current context which may be unavailable when using mesa. My suggestion is to check the default platform, if this is an unsupported one we can go through the member available_contexts and return the first for which IsCurrent returns true.

[1] http://www.koders.com/c/fid029413E4122A1BBD53F391FB6B935C3C74F7BF7B.aspx...
[2] http://mesa3d.sourceforge.net/osmesa.html
[3] http://files.zzattack.org/patch/mesa_contexts.patch