src/gl/debug.cpp

Mon, 27 Jun 2022 23:58:04 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Mon, 27 Jun 2022 23:58:04 +0300
changeset 278
304386ff96a4
parent 264
76a025db4948
permissions
-rw-r--r--

Make editing tools disabled until a document is selected

#include "src/gl/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, ").arg(sourceToString(glmessage.source()));
	stream << QObject::tr("type: %1, ").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,
	};
}

mercurial