PDA

View Full Version : OpenGL error handling idea



starman
06-18-2003, 07:01 AM
I haven't thought this out very well, but has anyone tried wrapping OpenGL calls and adding conditionally compiled error checking? The general idea is that you could compile with a debug switch if you were having problems but couldn't pinpoint the GL error. It would take a little time to set up, but you could create a header file that contained all of the OpenGL calls wrapped something like this:

void _glTranslatef(float x, float y, float z)
{
glTranslatef(x, y, z);

#ifdef DEBUG_OPENGL
// check GL errors here
#endif
}

You could compile out the obvious performance hit of the error checking, and if you're compiling with a C++ compiler the wrapper function itself should be inlined, so you shouldn't see a performance hit.

Hmmm...you might even be able to do this with a Perl script that parses the OpenGL header file and generates your wrapper header file automagically.

Is this a stupid idea? What would be the drawbacks?

[This message has been edited by starman (edited 06-18-2003).]

starman
06-18-2003, 07:10 AM
Another way to do it would be to create a namespace:

#include "opengl.h"

namespace Graphics {
void glTranslatef(float x, float y, float z)
{
::glTranslatef(x, y, z);
#ifdef DEBUG_OPENGL
// error checking code
#endif
}
}

Then your application wouldn't have to include opengl.h, just your header file. A "using namespace Graphics;" would then import the function names into the global namespace and your code would like like a normal OpenGL application. I'm not near my compiler, so I don't know if that would work like I want or not.

This would also work if you wanted to add trace information in the wrapper function. I've almost talked myself into this - somebody stop me! ;-)


[This message has been edited by starman (edited 06-18-2003).]

[This message has been edited by starman (edited 06-18-2003).]