src/gl/debug.cpp

Wed, 22 Jun 2022 23:32:34 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Wed, 22 Jun 2022 23:32:34 +0300
changeset 257
afdab56e8210
parent 239
74ce5ac84f25
child 264
76a025db4948
permissions
-rw-r--r--

Fix appearance of ColorButton

237
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
1 #include "debug.h"
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
2
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
3 QString sourceToString(const QOpenGLDebugMessage::Source source)
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
4 {
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
5 switch (source) {
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
6 case QOpenGLDebugMessage::InvalidSource:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
7 return QObject::tr("invalid");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
8 case QOpenGLDebugMessage::APISource:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
9 return QObject::tr("API");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
10 case QOpenGLDebugMessage::WindowSystemSource:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
11 return QObject::tr("window system");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
12 case QOpenGLDebugMessage::ShaderCompilerSource:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
13 return QObject::tr("shader compiler");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
14 case QOpenGLDebugMessage::ThirdPartySource:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
15 return QObject::tr("third party");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
16 case QOpenGLDebugMessage::ApplicationSource:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
17 return QObject::tr("application");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
18 case QOpenGLDebugMessage::OtherSource:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
19 return QObject::tr("other");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
20 case QOpenGLDebugMessage::AnySource:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
21 return QObject::tr("any");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
22 }
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
23 return "";
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
24 }
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
25
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
26 QString typeToString(const QOpenGLDebugMessage::Type type)
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
27 {
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
28 switch (type) {
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
29 case QOpenGLDebugMessage::ErrorType:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
30 return QObject::tr("error");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
31 case QOpenGLDebugMessage::DeprecatedBehaviorType:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
32 return QObject::tr("deprecated behavior");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
33 case QOpenGLDebugMessage::UndefinedBehaviorType:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
34 return QObject::tr("undefined behavior");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
35 case QOpenGLDebugMessage::PortabilityType:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
36 return QObject::tr("portability");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
37 case QOpenGLDebugMessage::PerformanceType:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
38 return QObject::tr("performance");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
39 case QOpenGLDebugMessage::MarkerType:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
40 return QObject::tr("marker");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
41 case QOpenGLDebugMessage::GroupPushType:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
42 return QObject::tr("push group");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
43 case QOpenGLDebugMessage::GroupPopType:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
44 return QObject::tr("pop group");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
45 case QOpenGLDebugMessage::OtherType:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
46 return QObject::tr("other");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
47 case QOpenGLDebugMessage::InvalidType:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
48 return QObject::tr("invalid");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
49 case QOpenGLDebugMessage::AnyType:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
50 return QObject::tr("any");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
51 }
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
52 return "";
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
53 }
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
54
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
55 QString severityToString(const QOpenGLDebugMessage::Severity severity)
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
56 {
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
57 switch (severity) {
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
58 case QOpenGLDebugMessage::HighSeverity:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
59 return QObject::tr("high");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
60 case QOpenGLDebugMessage::MediumSeverity:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
61 return QObject::tr("medium");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
62 case QOpenGLDebugMessage::LowSeverity:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
63 return QObject::tr("low");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
64 case QOpenGLDebugMessage::NotificationSeverity:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
65 return QObject::tr("notification");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
66 case QOpenGLDebugMessage::InvalidSeverity:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
67 return QObject::tr("invalid");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
68 case QOpenGLDebugMessage::AnySeverity:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
69 return QObject::tr("any");
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
70 }
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
71 return "";
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
72 }
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
73
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
74 constexpr Message::Type severityToMessageType(const QOpenGLDebugMessage::Severity severity)
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
75 {
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
76 switch (severity) {
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
77 case QOpenGLDebugMessage::HighSeverity:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
78 return Message::Error;
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
79 case QOpenGLDebugMessage::MediumSeverity:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
80 return Message::Warning;
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
81 default:
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
82 return Message::Info;
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
83 }
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
84 }
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
85
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
86 Message debugMessageToString(const QOpenGLDebugMessage& glmessage)
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
87 {
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
88 QString text;
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
89 QTextStream stream{&text};
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
90 stream << QObject::tr("OpenGL debug message [%1]").arg(glmessage.id()) << "\n";
239
74ce5ac84f25 removed some newlines
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
91 stream << QObject::tr("Source: %1, ").arg(sourceToString(glmessage.source()));
74ce5ac84f25 removed some newlines
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
92 stream << QObject::tr("type: %1, ").arg(typeToString(glmessage.type()));
74ce5ac84f25 removed some newlines
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
93 stream << QObject::tr("severity: %1\n").arg(severityToString(glmessage.severity()));
237
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
94 stream << glmessage.message();
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
95 return Message{
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
96 .time = QDateTime::currentDateTime(),
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
97 .type = severityToMessageType(glmessage.severity()),
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
98 .text = text,
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
99 };
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
100 }

mercurial