1 | // Copyright (C) 2013 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QOPENGLDEBUG_H |
5 | #define QOPENGLDEBUG_H |
6 | |
7 | #include <QtOpenGL/qtopenglglobal.h> |
8 | |
9 | #ifndef QT_NO_OPENGL |
10 | |
11 | #include <QtCore/qshareddata.h> |
12 | #include <QtCore/qflags.h> |
13 | #include <QtCore/qlist.h> |
14 | #include <QtCore/qmetatype.h> |
15 | #include <QtCore/qdebug.h> |
16 | #include <QtGui/qopenglcontext.h> |
17 | |
18 | #if defined(Q_QDOC) |
19 | #undef GLuint |
20 | typedef unsigned int GLuint; |
21 | #endif |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | class QOpenGLDebugLogger; |
26 | class QOpenGLDebugLoggerPrivate; |
27 | class QOpenGLDebugMessagePrivate; |
28 | |
29 | class Q_OPENGL_EXPORT QOpenGLDebugMessage |
30 | { |
31 | public: |
32 | enum Source { |
33 | InvalidSource = 0x00000000, |
34 | APISource = 0x00000001, |
35 | WindowSystemSource = 0x00000002, |
36 | ShaderCompilerSource = 0x00000004, |
37 | ThirdPartySource = 0x00000008, |
38 | ApplicationSource = 0x00000010, |
39 | OtherSource = 0x00000020, |
40 | LastSource = OtherSource, // private API |
41 | AnySource = 0xffffffff |
42 | }; |
43 | Q_DECLARE_FLAGS(Sources, Source) |
44 | |
45 | enum Type { |
46 | InvalidType = 0x00000000, |
47 | ErrorType = 0x00000001, |
48 | DeprecatedBehaviorType = 0x00000002, |
49 | UndefinedBehaviorType = 0x00000004, |
50 | PortabilityType = 0x00000008, |
51 | PerformanceType = 0x00000010, |
52 | OtherType = 0x00000020, |
53 | MarkerType = 0x00000040, |
54 | GroupPushType = 0x00000080, |
55 | GroupPopType = 0x00000100, |
56 | LastType = GroupPopType, // private API |
57 | AnyType = 0xffffffff |
58 | }; |
59 | Q_DECLARE_FLAGS(Types, Type) |
60 | |
61 | enum Severity { |
62 | InvalidSeverity = 0x00000000, |
63 | HighSeverity = 0x00000001, |
64 | MediumSeverity = 0x00000002, |
65 | LowSeverity = 0x00000004, |
66 | NotificationSeverity = 0x00000008, |
67 | LastSeverity = NotificationSeverity, // private API |
68 | AnySeverity = 0xffffffff |
69 | }; |
70 | Q_DECLARE_FLAGS(Severities, Severity) |
71 | |
72 | QOpenGLDebugMessage(); |
73 | QOpenGLDebugMessage(const QOpenGLDebugMessage &debugMessage); |
74 | |
75 | QOpenGLDebugMessage &operator=(const QOpenGLDebugMessage &debugMessage); |
76 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QOpenGLDebugMessage) |
77 | ~QOpenGLDebugMessage(); |
78 | |
79 | void swap(QOpenGLDebugMessage &other) noexcept { d.swap(other&: other.d); } |
80 | |
81 | Source source() const; |
82 | Type type() const; |
83 | Severity severity() const; |
84 | GLuint id() const; |
85 | QString message() const; |
86 | |
87 | static QOpenGLDebugMessage createApplicationMessage(const QString &text, |
88 | GLuint id = 0, |
89 | Severity severity = NotificationSeverity, |
90 | Type type = OtherType); |
91 | static QOpenGLDebugMessage createThirdPartyMessage(const QString &text, |
92 | GLuint id = 0, |
93 | Severity severity = NotificationSeverity, |
94 | Type type = OtherType); |
95 | |
96 | bool operator==(const QOpenGLDebugMessage &debugMessage) const; |
97 | inline bool operator!=(const QOpenGLDebugMessage &debugMessage) const { return !operator==(debugMessage); } |
98 | |
99 | private: |
100 | friend class QOpenGLDebugLogger; |
101 | friend class QOpenGLDebugLoggerPrivate; |
102 | QSharedDataPointer<QOpenGLDebugMessagePrivate> d; |
103 | }; |
104 | |
105 | Q_DECLARE_SHARED(QOpenGLDebugMessage) |
106 | Q_DECLARE_OPERATORS_FOR_FLAGS(QOpenGLDebugMessage::Sources) |
107 | Q_DECLARE_OPERATORS_FOR_FLAGS(QOpenGLDebugMessage::Types) |
108 | Q_DECLARE_OPERATORS_FOR_FLAGS(QOpenGLDebugMessage::Severities) |
109 | |
110 | #ifndef QT_NO_DEBUG_STREAM |
111 | Q_OPENGL_EXPORT QDebug operator<<(QDebug debug, const QOpenGLDebugMessage &message); |
112 | Q_OPENGL_EXPORT QDebug operator<<(QDebug debug, QOpenGLDebugMessage::Source source); |
113 | Q_OPENGL_EXPORT QDebug operator<<(QDebug debug, QOpenGLDebugMessage::Type type); |
114 | Q_OPENGL_EXPORT QDebug operator<<(QDebug debug, QOpenGLDebugMessage::Severity severity); |
115 | #endif |
116 | |
117 | class QOpenGLDebugLoggerPrivate; |
118 | |
119 | class Q_OPENGL_EXPORT QOpenGLDebugLogger : public QObject |
120 | { |
121 | Q_OBJECT |
122 | Q_PROPERTY(LoggingMode loggingMode READ loggingMode) |
123 | |
124 | public: |
125 | enum LoggingMode { |
126 | AsynchronousLogging, |
127 | SynchronousLogging |
128 | }; |
129 | Q_ENUM(LoggingMode) |
130 | |
131 | explicit QOpenGLDebugLogger(QObject *parent = nullptr); |
132 | ~QOpenGLDebugLogger(); |
133 | |
134 | bool initialize(); |
135 | |
136 | bool isLogging() const; |
137 | LoggingMode loggingMode() const; |
138 | |
139 | qint64 maximumMessageLength() const; |
140 | |
141 | void pushGroup(const QString &name, |
142 | GLuint id = 0, |
143 | QOpenGLDebugMessage::Source source = QOpenGLDebugMessage::ApplicationSource); |
144 | void popGroup(); |
145 | |
146 | void enableMessages(QOpenGLDebugMessage::Sources sources = QOpenGLDebugMessage::AnySource, |
147 | QOpenGLDebugMessage::Types types = QOpenGLDebugMessage::AnyType, |
148 | QOpenGLDebugMessage::Severities severities = QOpenGLDebugMessage::AnySeverity); |
149 | |
150 | void enableMessages(const QList<GLuint> &ids, |
151 | QOpenGLDebugMessage::Sources sources = QOpenGLDebugMessage::AnySource, |
152 | QOpenGLDebugMessage::Types types = QOpenGLDebugMessage::AnyType); |
153 | |
154 | void disableMessages(QOpenGLDebugMessage::Sources sources = QOpenGLDebugMessage::AnySource, |
155 | QOpenGLDebugMessage::Types types = QOpenGLDebugMessage::AnyType, |
156 | QOpenGLDebugMessage::Severities severities = QOpenGLDebugMessage::AnySeverity); |
157 | |
158 | void disableMessages(const QList<GLuint> &ids, |
159 | QOpenGLDebugMessage::Sources sources = QOpenGLDebugMessage::AnySource, |
160 | QOpenGLDebugMessage::Types types = QOpenGLDebugMessage::AnyType); |
161 | |
162 | QList<QOpenGLDebugMessage> loggedMessages() const; |
163 | |
164 | public Q_SLOTS: |
165 | void logMessage(const QOpenGLDebugMessage &debugMessage); |
166 | void startLogging(LoggingMode loggingMode = AsynchronousLogging); |
167 | void stopLogging(); |
168 | |
169 | Q_SIGNALS: |
170 | void messageLogged(const QOpenGLDebugMessage &debugMessage); |
171 | |
172 | private: |
173 | Q_DISABLE_COPY(QOpenGLDebugLogger) |
174 | Q_DECLARE_PRIVATE(QOpenGLDebugLogger) |
175 | Q_PRIVATE_SLOT(d_func(), void _q_contextAboutToBeDestroyed()) |
176 | }; |
177 | |
178 | QT_END_NAMESPACE |
179 | |
180 | QT_DECL_METATYPE_EXTERN(QOpenGLDebugMessage, Q_OPENGL_EXPORT) |
181 | |
182 | #endif // QT_NO_OPENGL |
183 | |
184 | #endif // QOPENGLDEBUG_H |
185 | |