Browse Source

GL: deduplicate & simplify DebugOutput::setCallback() internals.

The previous callback pointer was needed just to disambiguate, so it can
be a bool; the user pointer can be set from the caller already instead
of being done in each variant again.
pull/499/head
Vladimír Vondruš 3 years ago
parent
commit
475a74887c
  1. 25
      src/Magnum/GL/DebugOutput.cpp
  2. 6
      src/Magnum/GL/DebugOutput.h
  3. 2
      src/Magnum/GL/Implementation/DebugState.h

25
src/Magnum/GL/DebugOutput.cpp

@ -145,7 +145,8 @@ Int DebugOutput::maxMessageLength() {
}
void DebugOutput::setCallback(const Callback callback, const void* userParam) {
Context::current().state().debug.callbackImplementation(callback, userParam);
Context::current().state().debug.messageCallback.userParam = userParam;
Context::current().state().debug.callbackImplementation(callback);
}
void DebugOutput::setDefaultCallback() {
@ -172,38 +173,38 @@ void DebugOutput::controlImplementationKhrES(const GLenum source, const GLenum t
}
#endif
void DebugOutput::callbackImplementationNoOp(Callback, const void*) {}
void DebugOutput::callbackImplementationNoOp(Callback) {}
#ifndef MAGNUM_TARGET_GLES2
void DebugOutput::callbackImplementationKhrDesktopES32(const Callback callback, const void* userParam) {
void DebugOutput::callbackImplementationKhrDesktopES32(const Callback callback) {
/* Replace the callback */
const Callback original = Context::current().state().debug.messageCallback.callback;
const bool setPreviously = !!Context::current().state().debug.messageCallback.callback;
Context::current().state().debug.messageCallback.callback = callback;
Context::current().state().debug.messageCallback.userParam = userParam;
/* Adding callback */
if(!original && callback)
if(!setPreviously && callback)
glDebugMessageCallback(callbackWrapper, &Context::current().state().debug.messageCallback);
/* Deleting callback */
else if(original && !callback)
else if(setPreviously && !callback)
glDebugMessageCallback(nullptr, nullptr);
}
#endif
#ifdef MAGNUM_TARGET_GLES
void DebugOutput::callbackImplementationKhrES(const Callback callback, const void* userParam) {
void DebugOutput::callbackImplementationKhrES(const Callback callback) {
/* Replace the callback */
const Callback original = Context::current().state().debug.messageCallback.callback;
const bool setPreviously = !!Context::current().state().debug.messageCallback.callback;
Context::current().state().debug.messageCallback.callback = callback;
Context::current().state().debug.messageCallback.userParam = userParam;
/* Adding callback */
if(!original && callback)
if(!setPreviously && callback)
glDebugMessageCallbackKHR(callbackWrapper, &Context::current().state().debug.messageCallback);
/* Deleting callback */
else if(original && !callback)
else if(setPreviously && !callback)
glDebugMessageCallbackKHR(nullptr, nullptr);
}
#endif

6
src/Magnum/GL/DebugOutput.h

@ -422,12 +422,12 @@ class MAGNUM_GL_EXPORT DebugOutput {
static MAGNUM_GL_LOCAL void controlImplementationKhrES(GLenum source, GLenum type, GLenum severity, std::initializer_list<UnsignedInt> ids, bool enabled);
#endif
static MAGNUM_GL_LOCAL void callbackImplementationNoOp(Callback, const void*);
static MAGNUM_GL_LOCAL void callbackImplementationNoOp(Callback callback);
#ifndef MAGNUM_TARGET_GLES2
static MAGNUM_GL_LOCAL void callbackImplementationKhrDesktopES32(Callback callback, const void* userParam);
static MAGNUM_GL_LOCAL void callbackImplementationKhrDesktopES32(Callback callback);
#endif
#ifdef MAGNUM_TARGET_GLES
static MAGNUM_GL_LOCAL void callbackImplementationKhrES(Callback callback, const void* userParam);
static MAGNUM_GL_LOCAL void callbackImplementationKhrES(Callback callback);
#endif
};

2
src/Magnum/GL/Implementation/DebugState.h

@ -42,7 +42,7 @@ struct DebugState {
void(*messageInsertImplementation)(DebugMessage::Source, DebugMessage::Type, UnsignedInt, DebugOutput::Severity, Containers::ArrayView<const char>);
void(*controlImplementation)(GLenum, GLenum, GLenum, std::initializer_list<UnsignedInt>, bool);
void(*callbackImplementation)(DebugOutput::Callback, const void*);
void(*callbackImplementation)(DebugOutput::Callback);
void(*pushGroupImplementation)(DebugGroup::Source, UnsignedInt, Containers::ArrayView<const char>);
void(*popGroupImplementation)();

Loading…
Cancel
Save