I've been resuscitating an old game I wrote in C; at the same time, I've been involved in a major refactoring effort for a client, which resulted in me rereading Michael Feathers' excellent book, Working Effectively with Legacy Code. Inspired by Feathers, I decided I would like to try to get 95%+ code coverage before I made any major changes to it.
I'm planning to write more about testing and games, but today I wanted to just announce one little aid to this process.
There's a fair bit of OpenGL code involving shaders that needs to be
tested. A great solution to this problem is using Mesa's software
renderer (OSMesa). Although it has its own bugs, it does also help to
rule out driver-specific problems in the code, which is one of the big
nightmares of writing OpenGL code. (Oh, and always set MESA_DEBUG
in
your environment when running your tests!)
The problem is that I use GLEW to deal with setting up extensions appropriately, and it doesn't play well with OSMesa. Searching the web, I see that a number of people have had this problem; indeed, chromium even have their own patched version of GLEW with OSMesa support. None of the solutions I found online worked well for me, though, so I contributed my own 80% solution (sorry Olin) which can be found on github:
This adds a linux-osmesa
system definition that can be used to test
GLEW-using code with OSMesa. The extensions used by my own code are
relatively conservative so I wouldn't be surprised if more modern code
does not work in this case, but hopefully this will help someone else
out there.