Mon, 20 Jun 2022 19:49:56 +0300
Add an option to log opengl messages
#include "debug.h" QString sourceToString(const QOpenGLDebugMessage::Source source) { switch (source) { case QOpenGLDebugMessage::InvalidSource: return QObject::tr("invalid"); case QOpenGLDebugMessage::APISource: return QObject::tr("API"); case QOpenGLDebugMessage::WindowSystemSource: return QObject::tr("window system"); case QOpenGLDebugMessage::ShaderCompilerSource: return QObject::tr("shader compiler"); case QOpenGLDebugMessage::ThirdPartySource: return QObject::tr("third party"); case QOpenGLDebugMessage::ApplicationSource: return QObject::tr("application"); case QOpenGLDebugMessage::OtherSource: return QObject::tr("other"); case QOpenGLDebugMessage::AnySource: return QObject::tr("any"); } return ""; } QString typeToString(const QOpenGLDebugMessage::Type type) { switch (type) { case QOpenGLDebugMessage::ErrorType: return QObject::tr("error"); case QOpenGLDebugMessage::DeprecatedBehaviorType: return QObject::tr("deprecated behavior"); case QOpenGLDebugMessage::UndefinedBehaviorType: return QObject::tr("undefined behavior"); case QOpenGLDebugMessage::PortabilityType: return QObject::tr("portability"); case QOpenGLDebugMessage::PerformanceType: return QObject::tr("performance"); case QOpenGLDebugMessage::MarkerType: return QObject::tr("marker"); case QOpenGLDebugMessage::GroupPushType: return QObject::tr("push group"); case QOpenGLDebugMessage::GroupPopType: return QObject::tr("pop group"); case QOpenGLDebugMessage::OtherType: return QObject::tr("other"); case QOpenGLDebugMessage::InvalidType: return QObject::tr("invalid"); case QOpenGLDebugMessage::AnyType: return QObject::tr("any"); } return ""; } QString severityToString(const QOpenGLDebugMessage::Severity severity) { switch (severity) { case QOpenGLDebugMessage::HighSeverity: return QObject::tr("high"); case QOpenGLDebugMessage::MediumSeverity: return QObject::tr("medium"); case QOpenGLDebugMessage::LowSeverity: return QObject::tr("low"); case QOpenGLDebugMessage::NotificationSeverity: return QObject::tr("notification"); case QOpenGLDebugMessage::InvalidSeverity: return QObject::tr("invalid"); case QOpenGLDebugMessage::AnySeverity: return QObject::tr("any"); } return ""; } constexpr Message::Type severityToMessageType(const QOpenGLDebugMessage::Severity severity) { switch (severity) { case QOpenGLDebugMessage::HighSeverity: return Message::Error; case QOpenGLDebugMessage::MediumSeverity: return Message::Warning; default: return Message::Info; } } Message debugMessageToString(const QOpenGLDebugMessage& glmessage) { QString text; QTextStream stream{&text}; stream << QObject::tr("OpenGL debug message [%1]").arg(glmessage.id()) << "\n"; stream << QObject::tr("Source: %1\n").arg(sourceToString(glmessage.source())); stream << QObject::tr("Type: %1\n").arg(typeToString(glmessage.type())); stream << QObject::tr("Severity: %1\n").arg(severityToString(glmessage.severity())); stream << glmessage.message(); return Message{ .time = QDateTime::currentDateTime(), .type = severityToMessageType(glmessage.severity()), .text = text, }; }