Improve handling of OpenGL errors

This makes it possible to use the GetError code from GlContext when debugging OpenGL errors in other parts of the code. This PR conflicts with #373. Please merge the one you like better, then I'll update the other one.
Nice!