Not exactly what you're asking for, but this is extracted from my code:
Laurens.
#ifdef OPENGL_DEBUG
void APIENTRY DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar * message, const void* userParam) {
printf("0x % X: %s\n", id, message);
}
#endif
class EnableGLDebugCallback : public osg::GraphicsOperation
{
public:
EnableGLDebugCallback() :
GraphicsOperation("EnableGLDebug", true),
_dirty(true) { }
virtual void operator () (osg::GraphicsContext* context) {
if (_dirty) {
#ifdef OPENGL_DEBUG
if (osg::isGLExtensionSupported(contextID, "GL_KHR_debug")) {
//PFNGLDEBUGMESSAGECALLBACKPROC
PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback = (PFNGLDEBUGMESSAGECALLBACKPROC)wglGetProcAddress("glDebugMessageCallback");
PFNGLDEBUGMESSAGECONTROLPROC glDebugMessageControl = (PFNGLDEBUGMESSAGECONTROLPROC)wglGetProcAddress("glDebugMessageControl");
glDebugMessageCallback(DebugCallback, NULL);
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, 0, GL_TRUE);
glEnable(GL_DEBUG_OUTPUT);
//glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
}
#endif
_dirty = false;
}
}
protected:
bool _dirty;
};
};
in main thread:
osg::GraphicsContext *gc = _viewer->getCamera()->getGraphicsContext();
if (gc) {
gc->add(new EnableGLDebugCallback());
OSGRC_DEBUG("EnableGLDebugCallback installed" << std::endl);
}