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