mirror of https://github.com/mosra/magnum.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
394 lines
14 KiB
394 lines
14 KiB
|
11 years ago
|
/*
|
||
|
|
This file is part of Magnum.
|
||
|
|
|
||
|
8 years ago
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
|
||
|
11 years ago
|
Vladimír Vondruš <mosra@centrum.cz>
|
||
|
|
|
||
|
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||
|
|
copy of this software and associated documentation files (the "Software"),
|
||
|
|
to deal in the Software without restriction, including without limitation
|
||
|
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||
|
|
and/or sell copies of the Software, and to permit persons to whom the
|
||
|
|
Software is furnished to do so, subject to the following conditions:
|
||
|
|
|
||
|
|
The above copyright notice and this permission notice shall be included
|
||
|
|
in all copies or substantial portions of the Software.
|
||
|
|
|
||
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||
|
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||
|
|
DEALINGS IN THE SOFTWARE.
|
||
|
|
*/
|
||
|
|
|
||
|
|
#include "DebugOutput.h"
|
||
|
|
|
||
|
11 years ago
|
#ifndef MAGNUM_TARGET_WEBGL
|
||
|
11 years ago
|
#include <Corrade/Utility/Assert.h>
|
||
|
11 years ago
|
#include <Corrade/Utility/Debug.h>
|
||
|
11 years ago
|
|
||
|
8 years ago
|
#include "Magnum/GL/Context.h"
|
||
|
|
#include "Magnum/GL/Extensions.h"
|
||
|
|
#include "Magnum/GL/Implementation/State.h"
|
||
|
|
#include "Magnum/GL/Implementation/DebugState.h"
|
||
|
11 years ago
|
|
||
|
|
namespace Magnum {
|
||
|
|
|
||
|
|
namespace {
|
||
|
|
|
||
|
|
void
|
||
|
|
#ifdef CORRADE_TARGET_WINDOWS
|
||
|
|
APIENTRY
|
||
|
|
#endif
|
||
|
|
callbackWrapper(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam) {
|
||
|
10 years ago
|
Context::current().state().debug->messageCallback(DebugOutput::Source(source), DebugOutput::Type(type), id, DebugOutput::Severity(severity), std::string{message, std::size_t(length)}, userParam);
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
|
void defaultCallback(const DebugOutput::Source source, const DebugOutput::Type type, const UnsignedInt id, const DebugOutput::Severity severity, const std::string& string, const void*) {
|
||
|
11 years ago
|
Debug output;
|
||
|
|
output << "Debug output:";
|
||
|
|
|
||
|
11 years ago
|
switch(severity) {
|
||
|
|
case DebugOutput::Severity::High:
|
||
|
11 years ago
|
output << "high severity"; break;
|
||
|
11 years ago
|
|
||
|
|
case DebugOutput::Severity::Medium:
|
||
|
11 years ago
|
output << "medium severity"; break;
|
||
|
|
|
||
|
11 years ago
|
case DebugOutput::Severity::Low:
|
||
|
11 years ago
|
output << "low severity"; break;
|
||
|
|
|
||
|
|
case DebugOutput::Severity::Notification: ;
|
||
|
|
}
|
||
|
11 years ago
|
|
||
|
11 years ago
|
switch(source) {
|
||
|
|
case DebugOutput::Source::Api:
|
||
|
|
output << "API"; break;
|
||
|
|
case DebugOutput::Source::WindowSystem:
|
||
|
|
output << "window system"; break;
|
||
|
|
case DebugOutput::Source::ShaderCompiler:
|
||
|
|
output << "shader compiler"; break;
|
||
|
|
case DebugOutput::Source::ThirdParty:
|
||
|
|
output << "third party"; break;
|
||
|
|
case DebugOutput::Source::Application:
|
||
|
|
output << "application"; break;
|
||
|
|
|
||
|
|
case DebugOutput::Source::Other: ;
|
||
|
11 years ago
|
}
|
||
|
11 years ago
|
|
||
|
|
switch(type) {
|
||
|
|
case DebugOutput::Type::Error:
|
||
|
|
output << "error"; break;
|
||
|
|
case DebugOutput::Type::DeprecatedBehavior:
|
||
|
|
output << "deprecated behavior note"; break;
|
||
|
|
case DebugOutput::Type::UndefinedBehavior:
|
||
|
|
output << "undefined behavior note"; break;
|
||
|
|
case DebugOutput::Type::Portability:
|
||
|
|
output << "portability note"; break;
|
||
|
|
case DebugOutput::Type::Performance:
|
||
|
|
output << "performance note"; break;
|
||
|
|
case DebugOutput::Type::Marker:
|
||
|
|
output << "marker"; break;
|
||
|
|
case DebugOutput::Type::PushGroup:
|
||
|
|
output << "debug group enter"; break;
|
||
|
|
case DebugOutput::Type::PopGroup:
|
||
|
|
output << "debug group leave"; break;
|
||
|
|
|
||
|
|
case DebugOutput::Type::Other: ;
|
||
|
|
}
|
||
|
|
|
||
|
8 years ago
|
output << "(" << Debug::nospace << id << Debug::nospace << "):" << string;
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
Int DebugOutput::maxLoggedMessages() {
|
||
|
10 years ago
|
if(!Context::current().isExtensionSupported<Extensions::GL::KHR::debug>())
|
||
|
11 years ago
|
return 0;
|
||
|
|
|
||
|
10 years ago
|
GLint& value = Context::current().state().debug->maxLoggedMessages;
|
||
|
11 years ago
|
|
||
|
|
if(value == 0) {
|
||
|
8 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
11 years ago
|
glGetIntegerv(GL_MAX_DEBUG_LOGGED_MESSAGES, &value);
|
||
|
|
#else
|
||
|
|
glGetIntegerv(GL_MAX_DEBUG_LOGGED_MESSAGES_KHR, &value);
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
|
return value;
|
||
|
|
}
|
||
|
|
|
||
|
|
Int DebugOutput::maxMessageLength() {
|
||
|
10 years ago
|
if(!Context::current().isExtensionSupported<Extensions::GL::KHR::debug>())
|
||
|
11 years ago
|
return 0;
|
||
|
|
|
||
|
10 years ago
|
GLint& value = Context::current().state().debug->maxMessageLength;
|
||
|
11 years ago
|
|
||
|
|
if(value == 0) {
|
||
|
8 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
11 years ago
|
glGetIntegerv(GL_MAX_DEBUG_MESSAGE_LENGTH, &value);
|
||
|
|
#else
|
||
|
|
glGetIntegerv(GL_MAX_DEBUG_MESSAGE_LENGTH_KHR, &value);
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
|
return value;
|
||
|
|
}
|
||
|
|
|
||
|
|
void DebugOutput::setCallback(const Callback callback, const void* userParam) {
|
||
|
10 years ago
|
Context::current().state().debug->callbackImplementation(callback, userParam);
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
|
void DebugOutput::setDefaultCallback() {
|
||
|
|
setCallback(defaultCallback, nullptr);
|
||
|
|
}
|
||
|
|
|
||
|
|
void DebugOutput::setEnabledInternal(const GLenum source, const GLenum type, const GLenum severity, const std::initializer_list<UnsignedInt> ids, const bool enabled) {
|
||
|
10 years ago
|
Context::current().state().debug->controlImplementation(source, type, severity, ids, enabled);
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
|
void DebugOutput::controlImplementationNoOp(GLenum, GLenum, GLenum, std::initializer_list<UnsignedInt>, bool) {}
|
||
|
|
|
||
|
8 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
|
void DebugOutput::controlImplementationKhrDesktopES32(const GLenum source, const GLenum type, const GLenum severity, const std::initializer_list<UnsignedInt> ids, const bool enabled) {
|
||
|
|
glDebugMessageControl(source, type, severity, ids.size(), ids.begin(), enabled);
|
||
|
11 years ago
|
}
|
||
|
8 years ago
|
#endif
|
||
|
|
|
||
|
|
#ifdef MAGNUM_TARGET_GLES
|
||
|
|
void DebugOutput::controlImplementationKhrES(const GLenum source, const GLenum type, const GLenum severity, const std::initializer_list<UnsignedInt> ids, const bool enabled) {
|
||
|
|
glDebugMessageControlKHR(source, type, severity, ids.size(), ids.begin(), enabled);
|
||
|
|
}
|
||
|
|
#endif
|
||
|
11 years ago
|
|
||
|
|
void DebugOutput::callbackImplementationNoOp(Callback, const void*) {}
|
||
|
|
|
||
|
8 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
|
void DebugOutput::callbackImplementationKhrDesktopES32(const Callback callback, const void* userParam) {
|
||
|
11 years ago
|
/* Replace the callback */
|
||
|
10 years ago
|
const Callback original = Context::current().state().debug->messageCallback;
|
||
|
|
Context::current().state().debug->messageCallback = callback;
|
||
|
11 years ago
|
|
||
|
|
/* Adding callback */
|
||
|
8 years ago
|
if(!original && callback)
|
||
|
|
glDebugMessageCallback(callbackWrapper, userParam);
|
||
|
11 years ago
|
|
||
|
|
/* Deleting callback */
|
||
|
8 years ago
|
else if(original && !callback)
|
||
|
|
glDebugMessageCallback(nullptr, nullptr);
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef MAGNUM_TARGET_GLES
|
||
|
|
void DebugOutput::callbackImplementationKhrES(const Callback callback, const void* userParam) {
|
||
|
|
/* Replace the callback */
|
||
|
|
const Callback original = Context::current().state().debug->messageCallback;
|
||
|
|
Context::current().state().debug->messageCallback = callback;
|
||
|
|
|
||
|
|
/* Adding callback */
|
||
|
|
if(!original && callback)
|
||
|
|
glDebugMessageCallbackKHR(callbackWrapper, userParam);
|
||
|
|
|
||
|
|
/* Deleting callback */
|
||
|
|
else if(original && !callback)
|
||
|
|
glDebugMessageCallbackKHR(nullptr, nullptr);
|
||
|
11 years ago
|
}
|
||
|
8 years ago
|
#endif
|
||
|
11 years ago
|
|
||
|
|
#ifndef DOXYGEN_GENERATING_OUTPUT
|
||
|
11 years ago
|
Debug& operator<<(Debug& debug, const DebugOutput::Source value) {
|
||
|
11 years ago
|
switch(value) {
|
||
|
10 years ago
|
/* LCOV_EXCL_START */
|
||
|
11 years ago
|
#define _c(value) case DebugOutput::Source::value: return debug << "DebugOutput::Source::" #value;
|
||
|
|
_c(Api)
|
||
|
|
_c(WindowSystem)
|
||
|
|
_c(ShaderCompiler)
|
||
|
|
_c(ThirdParty)
|
||
|
|
_c(Application)
|
||
|
|
_c(Other)
|
||
|
|
#undef _c
|
||
|
10 years ago
|
/* LCOV_EXCL_STOP */
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
10 years ago
|
return debug << "DebugOutput::Source(" << Debug::nospace << reinterpret_cast<void*>(GLenum(value)) << Debug::nospace << ")";
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
11 years ago
|
Debug& operator<<(Debug& debug, const DebugOutput::Type value) {
|
||
|
11 years ago
|
switch(value) {
|
||
|
10 years ago
|
/* LCOV_EXCL_START */
|
||
|
11 years ago
|
#define _c(value) case DebugOutput::Type::value: return debug << "DebugOutput::Type::" #value;
|
||
|
|
_c(Error)
|
||
|
|
_c(DeprecatedBehavior)
|
||
|
|
_c(UndefinedBehavior)
|
||
|
|
_c(Portability)
|
||
|
|
_c(Performance)
|
||
|
|
_c(Marker)
|
||
|
|
_c(PushGroup)
|
||
|
|
_c(PopGroup)
|
||
|
|
_c(Other)
|
||
|
|
#undef _c
|
||
|
10 years ago
|
/* LCOV_EXCL_STOP */
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
10 years ago
|
return debug << "DebugOutput::Type(" << Debug::nospace << reinterpret_cast<void*>(GLenum(value)) << Debug::nospace << ")";
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
11 years ago
|
Debug& operator<<(Debug& debug, const DebugOutput::Severity value) {
|
||
|
11 years ago
|
switch(value) {
|
||
|
|
#define _c(value) case DebugOutput::Severity::value: return debug << "DebugOutput::Severity::" #value;
|
||
|
|
_c(High)
|
||
|
|
_c(Medium)
|
||
|
|
_c(Low)
|
||
|
|
_c(Notification)
|
||
|
|
#undef _c
|
||
|
|
}
|
||
|
|
|
||
|
10 years ago
|
return debug << "DebugOutput::Severity(" << Debug::nospace << reinterpret_cast<void*>(GLenum(value)) << Debug::nospace << ")";
|
||
|
11 years ago
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
11 years ago
|
void DebugMessage::insertInternal(const Source source, const Type type, const UnsignedInt id, const DebugOutput::Severity severity, const Containers::ArrayView<const char> string) {
|
||
|
10 years ago
|
Context::current().state().debug->messageInsertImplementation(source, type, id, severity, string);
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
11 years ago
|
void DebugMessage::insertImplementationNoOp(Source, Type, UnsignedInt, DebugOutput::Severity, const Containers::ArrayView<const char>) {}
|
||
|
11 years ago
|
|
||
|
8 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
|
void DebugMessage::insertImplementationKhrDesktopES32(const Source source, const Type type, const UnsignedInt id, const DebugOutput::Severity severity, const Containers::ArrayView<const char> string) {
|
||
|
|
glDebugMessageInsert(GLenum(source), GLenum(type), id, GLenum(severity), string.size(), string.data());
|
||
|
11 years ago
|
}
|
||
|
8 years ago
|
#endif
|
||
|
|
|
||
|
|
#ifdef MAGNUM_TARGET_GLES
|
||
|
|
void DebugMessage::insertImplementationKhrES(const Source source, const Type type, const UnsignedInt id, const DebugOutput::Severity severity, const Containers::ArrayView<const char> string) {
|
||
|
|
glDebugMessageInsertKHR(GLenum(source), GLenum(type), id, GLenum(severity), string.size(), string.data());
|
||
|
|
}
|
||
|
|
#endif
|
||
|
11 years ago
|
|
||
|
11 years ago
|
void DebugMessage::insertImplementationExt(Source, Type, UnsignedInt, DebugOutput::Severity, const Containers::ArrayView<const char> string) {
|
||
|
11 years ago
|
glInsertEventMarkerEXT(string.size(), string.data());
|
||
|
|
}
|
||
|
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
11 years ago
|
void DebugMessage::insertImplementationGremedy(Source, Type, UnsignedInt, DebugOutput::Severity, const Containers::ArrayView<const char> string) {
|
||
|
11 years ago
|
glStringMarkerGREMEDY(string.size(), string.data());
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifndef DOXYGEN_GENERATING_OUTPUT
|
||
|
11 years ago
|
Debug& operator<<(Debug& debug, const DebugMessage::Source value) {
|
||
|
11 years ago
|
switch(value) {
|
||
|
10 years ago
|
/* LCOV_EXCL_START */
|
||
|
11 years ago
|
#define _c(value) case DebugMessage::Source::value: return debug << "DebugMessage::Source::" #value;
|
||
|
|
_c(ThirdParty)
|
||
|
|
_c(Application)
|
||
|
|
#undef _c
|
||
|
10 years ago
|
/* LCOV_EXCL_STOP */
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
10 years ago
|
return debug << "DebugMessage::Source(" << Debug::nospace << reinterpret_cast<void*>(GLenum(value)) << Debug::nospace << ")";
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
11 years ago
|
Debug& operator<<(Debug& debug, const DebugMessage::Type value) {
|
||
|
11 years ago
|
switch(value) {
|
||
|
|
#define _c(value) case DebugMessage::Type::value: return debug << "DebugMessage::Type::" #value;
|
||
|
|
_c(Error)
|
||
|
|
_c(DeprecatedBehavior)
|
||
|
|
_c(UndefinedBehavior)
|
||
|
|
_c(Portability)
|
||
|
|
_c(Performance)
|
||
|
|
_c(Other)
|
||
|
|
_c(Marker)
|
||
|
|
#undef _c
|
||
|
|
}
|
||
|
|
|
||
|
10 years ago
|
return debug << "DebugMessage::Type(" << Debug::nospace << reinterpret_cast<void*>(GLenum(value)) << Debug::nospace << ")";
|
||
|
11 years ago
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
Int DebugGroup::maxStackDepth() {
|
||
|
10 years ago
|
if(!Context::current().isExtensionSupported<Extensions::GL::KHR::debug>())
|
||
|
11 years ago
|
return 0;
|
||
|
|
|
||
|
10 years ago
|
GLint& value = Context::current().state().debug->maxStackDepth;
|
||
|
11 years ago
|
|
||
|
|
if(value == 0) {
|
||
|
8 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
11 years ago
|
glGetIntegerv(GL_MAX_DEBUG_GROUP_STACK_DEPTH, &value);
|
||
|
|
#else
|
||
|
|
glGetIntegerv(GL_MAX_DEBUG_GROUP_STACK_DEPTH_KHR, &value);
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
|
return value;
|
||
|
|
}
|
||
|
|
|
||
|
11 years ago
|
void DebugGroup::pushInternal(const Source source, const UnsignedInt id, const Containers::ArrayView<const char> message) {
|
||
|
11 years ago
|
CORRADE_ASSERT(!_active, "DebugGroup::push(): group is already active", );
|
||
|
10 years ago
|
Context::current().state().debug->pushGroupImplementation(source, id, message);
|
||
|
11 years ago
|
_active = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
void DebugGroup::pop() {
|
||
|
|
CORRADE_ASSERT(_active, "DebugGroup::pop(): group is not active", );
|
||
|
10 years ago
|
Context::current().state().debug->popGroupImplementation();
|
||
|
11 years ago
|
_active = false;
|
||
|
|
}
|
||
|
|
|
||
|
11 years ago
|
void DebugGroup::pushImplementationNoOp(Source, UnsignedInt, Containers::ArrayView<const char>) {}
|
||
|
11 years ago
|
|
||
|
8 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
|
void DebugGroup::pushImplementationKhrDesktopES32(const Source source, const UnsignedInt id, const Containers::ArrayView<const char> message) {
|
||
|
|
glPushDebugGroup(GLenum(source), id, message.size(), message.data());
|
||
|
11 years ago
|
}
|
||
|
8 years ago
|
#endif
|
||
|
|
|
||
|
|
#ifdef MAGNUM_TARGET_GLES
|
||
|
|
void DebugGroup::pushImplementationKhrES(const Source source, const UnsignedInt id, const Containers::ArrayView<const char> message) {
|
||
|
|
glPushDebugGroupKHR(GLenum(source), id, message.size(), message.data());
|
||
|
|
}
|
||
|
|
#endif
|
||
|
11 years ago
|
|
||
|
11 years ago
|
void DebugGroup::pushImplementationExt(Source, UnsignedInt, const Containers::ArrayView<const char> message) {
|
||
|
11 years ago
|
glPushGroupMarkerEXT(message.size(), message.data());
|
||
|
|
}
|
||
|
|
|
||
|
|
void DebugGroup::popImplementationNoOp() {}
|
||
|
|
|
||
|
8 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
|
void DebugGroup::popImplementationKhrDesktopES32() {
|
||
|
11 years ago
|
glPopDebugGroup();
|
||
|
8 years ago
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef MAGNUM_TARGET_GLES
|
||
|
|
void DebugGroup::popImplementationKhrES() {
|
||
|
9 years ago
|
glPopDebugGroupKHR();
|
||
|
11 years ago
|
}
|
||
|
8 years ago
|
#endif
|
||
|
11 years ago
|
|
||
|
|
void DebugGroup::popImplementationExt() {
|
||
|
|
glPopGroupMarkerEXT();
|
||
|
|
}
|
||
|
|
|
||
|
|
#ifndef DOXYGEN_GENERATING_OUTPUT
|
||
|
11 years ago
|
Debug& operator<<(Debug& debug, const DebugGroup::Source value) {
|
||
|
11 years ago
|
switch(value) {
|
||
|
10 years ago
|
/* LCOV_EXCL_START */
|
||
|
11 years ago
|
#define _c(value) case DebugGroup::Source::value: return debug << "DebugGroup::Source::" #value;
|
||
|
|
_c(ThirdParty)
|
||
|
|
_c(Application)
|
||
|
|
#undef _c
|
||
|
10 years ago
|
/* LCOV_EXCL_STOP */
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
10 years ago
|
return debug << "DebugGroup::Source(" << Debug::nospace << reinterpret_cast<void*>(GLenum(value)) << Debug::nospace << ")";
|
||
|
11 years ago
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
}
|
||
|
11 years ago
|
#endif
|