OpenGL 3 support for Libwm

After getting Libwm in release shape last week, I started adding new features for future releases. I finally got to the stuff I originally started the Libwm project for, OpenGL 3 support (and new pixel formats, etc).

I added OpenGL 3 support using GLX/WGL_ARB_create_context and create_context_profile. The coding went smoothly but I had some driver-related issues and problems finding suitable pixel formats. However, now the support is there and you can get an OpenGL 3 context set up.

However, I was not entirely satisfied. The problem is that it’s impossible to determine what features are supported by the underlying OpenGL implementation. Selecting suitable pixel formats is particularly annoying. You can’t tell beforehand whether or not a pixel format can be used with hardware accelerated OpenGL.

On Windows, I get a Microsoft GDI OpenGL 1.1 context if I select a pixel format that the Nvidia implementation cannot handle (like one with a 16 bit depth buffer). On OSX/GLX 1.2/Intel GMA I can’t tell if a pixel format will support direct rendering or not. The best solution is to try a pixel format and see if it fails to provide a context. Detecting failures on Xlib is hard too, Xlib calls an error handler function in case of failure. The error handling is asynchronous and it’s impossible to tell what went wrong. You can detect the request type (glXCreateContextAttribsARB) but if there are many different contexts set up at the same time (either in parallel or quickly in a sequence), you can’t really tell which of the requests failed. The error handlers do know the sequence number of the failed request but you don’t have a number to compare it to (you can’t get the sequence number of the create context request you send).

It seems like the best portable alternative is to write a launcher application/script that uses a simple libwm-based probe application that queries available confiugrations and checks what can be supported. If the probe application fails then try another one. Once a suitable configuration (a pixel format, direct/indirect rendering, OpenGL context version) has been found, the launcher script/app starts the actual application. It’s pretty much a hack but I couldn’t come up with a better solution given the limitations of the underlying platform API’s.

I’d really like to get support for multisampling done soon, it’s only a small addition to the pixel format setup. A slightly bigger change is supporting floating point and packed float pixel formats. Getting that done needs a bit of a change to pixel format context setup architecture, which is why I’d want it done rather sooner than later. Currently the floating point pixel formats are available only for off-screen PBuffers and Pixmaps which are not yet supported by Libwm, but it can’t hurt to have the functions ready for future floating point on-screen rendering or the addition of off-screen support to Libwm.

I’ll be very busy for the rest of the month, so not a lot of progress can be expected, but hopefully I have some coding time too.

Leave a comment