1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2013 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtOpenGL module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QOPENGLDEBUG_H |
41 | #define QOPENGLDEBUG_H |
42 | |
43 | #include <QtOpenGL/qtopenglglobal.h> |
44 | |
45 | #ifndef QT_NO_OPENGL |
46 | |
47 | #include <QtCore/qshareddata.h> |
48 | #include <QtCore/qflags.h> |
49 | #include <QtCore/qlist.h> |
50 | #include <QtCore/qmetatype.h> |
51 | #include <QtCore/qdebug.h> |
52 | #include <QtGui/qopenglcontext.h> |
53 | |
54 | #if defined(Q_CLANG_QDOC) |
55 | #undef GLuint |
56 | typedef unsigned int GLuint; |
57 | #endif |
58 | |
59 | QT_BEGIN_NAMESPACE |
60 | |
61 | class QOpenGLDebugLogger; |
62 | class QOpenGLDebugLoggerPrivate; |
63 | class QOpenGLDebugMessagePrivate; |
64 | |
65 | class Q_OPENGL_EXPORT QOpenGLDebugMessage |
66 | { |
67 | public: |
68 | enum Source { |
69 | InvalidSource = 0x00000000, |
70 | APISource = 0x00000001, |
71 | WindowSystemSource = 0x00000002, |
72 | ShaderCompilerSource = 0x00000004, |
73 | ThirdPartySource = 0x00000008, |
74 | ApplicationSource = 0x00000010, |
75 | OtherSource = 0x00000020, |
76 | LastSource = OtherSource, // private API |
77 | AnySource = 0xffffffff |
78 | }; |
79 | Q_DECLARE_FLAGS(Sources, Source) |
80 | |
81 | enum Type { |
82 | InvalidType = 0x00000000, |
83 | ErrorType = 0x00000001, |
84 | DeprecatedBehaviorType = 0x00000002, |
85 | UndefinedBehaviorType = 0x00000004, |
86 | PortabilityType = 0x00000008, |
87 | PerformanceType = 0x00000010, |
88 | OtherType = 0x00000020, |
89 | MarkerType = 0x00000040, |
90 | GroupPushType = 0x00000080, |
91 | GroupPopType = 0x00000100, |
92 | LastType = GroupPopType, // private API |
93 | AnyType = 0xffffffff |
94 | }; |
95 | Q_DECLARE_FLAGS(Types, Type) |
96 | |
97 | enum Severity { |
98 | InvalidSeverity = 0x00000000, |
99 | HighSeverity = 0x00000001, |
100 | MediumSeverity = 0x00000002, |
101 | LowSeverity = 0x00000004, |
102 | NotificationSeverity = 0x00000008, |
103 | LastSeverity = NotificationSeverity, // private API |
104 | AnySeverity = 0xffffffff |
105 | }; |
106 | Q_DECLARE_FLAGS(Severities, Severity) |
107 | |
108 | QOpenGLDebugMessage(); |
109 | QOpenGLDebugMessage(const QOpenGLDebugMessage &debugMessage); |
110 | |
111 | QOpenGLDebugMessage &operator=(const QOpenGLDebugMessage &debugMessage); |
112 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QOpenGLDebugMessage) |
113 | ~QOpenGLDebugMessage(); |
114 | |
115 | void swap(QOpenGLDebugMessage &other) noexcept { qSwap(d, other.d); } |
116 | |
117 | Source source() const; |
118 | Type type() const; |
119 | Severity severity() const; |
120 | GLuint id() const; |
121 | QString message() const; |
122 | |
123 | static QOpenGLDebugMessage createApplicationMessage(const QString &text, |
124 | GLuint id = 0, |
125 | Severity severity = NotificationSeverity, |
126 | Type type = OtherType); |
127 | static QOpenGLDebugMessage createThirdPartyMessage(const QString &text, |
128 | GLuint id = 0, |
129 | Severity severity = NotificationSeverity, |
130 | Type type = OtherType); |
131 | |
132 | bool operator==(const QOpenGLDebugMessage &debugMessage) const; |
133 | inline bool operator!=(const QOpenGLDebugMessage &debugMessage) const { return !operator==(debugMessage); } |
134 | |
135 | private: |
136 | friend class QOpenGLDebugLogger; |
137 | friend class QOpenGLDebugLoggerPrivate; |
138 | QSharedDataPointer<QOpenGLDebugMessagePrivate> d; |
139 | }; |
140 | |
141 | Q_DECLARE_SHARED(QOpenGLDebugMessage) |
142 | Q_DECLARE_OPERATORS_FOR_FLAGS(QOpenGLDebugMessage::Sources) |
143 | Q_DECLARE_OPERATORS_FOR_FLAGS(QOpenGLDebugMessage::Types) |
144 | Q_DECLARE_OPERATORS_FOR_FLAGS(QOpenGLDebugMessage::Severities) |
145 | |
146 | #ifndef QT_NO_DEBUG_STREAM |
147 | Q_OPENGL_EXPORT QDebug operator<<(QDebug debug, const QOpenGLDebugMessage &message); |
148 | Q_OPENGL_EXPORT QDebug operator<<(QDebug debug, QOpenGLDebugMessage::Source source); |
149 | Q_OPENGL_EXPORT QDebug operator<<(QDebug debug, QOpenGLDebugMessage::Type type); |
150 | Q_OPENGL_EXPORT QDebug operator<<(QDebug debug, QOpenGLDebugMessage::Severity severity); |
151 | #endif |
152 | |
153 | class QOpenGLDebugLoggerPrivate; |
154 | |
155 | class Q_OPENGL_EXPORT QOpenGLDebugLogger : public QObject |
156 | { |
157 | Q_OBJECT |
158 | Q_PROPERTY(LoggingMode loggingMode READ loggingMode) |
159 | |
160 | public: |
161 | enum LoggingMode { |
162 | AsynchronousLogging, |
163 | SynchronousLogging |
164 | }; |
165 | Q_ENUM(LoggingMode) |
166 | |
167 | explicit QOpenGLDebugLogger(QObject *parent = nullptr); |
168 | ~QOpenGLDebugLogger(); |
169 | |
170 | bool initialize(); |
171 | |
172 | bool isLogging() const; |
173 | LoggingMode loggingMode() const; |
174 | |
175 | qint64 maximumMessageLength() const; |
176 | |
177 | void pushGroup(const QString &name, |
178 | GLuint id = 0, |
179 | QOpenGLDebugMessage::Source source = QOpenGLDebugMessage::ApplicationSource); |
180 | void popGroup(); |
181 | |
182 | void enableMessages(QOpenGLDebugMessage::Sources sources = QOpenGLDebugMessage::AnySource, |
183 | QOpenGLDebugMessage::Types types = QOpenGLDebugMessage::AnyType, |
184 | QOpenGLDebugMessage::Severities severities = QOpenGLDebugMessage::AnySeverity); |
185 | |
186 | void enableMessages(const QList<GLuint> &ids, |
187 | QOpenGLDebugMessage::Sources sources = QOpenGLDebugMessage::AnySource, |
188 | QOpenGLDebugMessage::Types types = QOpenGLDebugMessage::AnyType); |
189 | |
190 | void disableMessages(QOpenGLDebugMessage::Sources sources = QOpenGLDebugMessage::AnySource, |
191 | QOpenGLDebugMessage::Types types = QOpenGLDebugMessage::AnyType, |
192 | QOpenGLDebugMessage::Severities severities = QOpenGLDebugMessage::AnySeverity); |
193 | |
194 | void disableMessages(const QList<GLuint> &ids, |
195 | QOpenGLDebugMessage::Sources sources = QOpenGLDebugMessage::AnySource, |
196 | QOpenGLDebugMessage::Types types = QOpenGLDebugMessage::AnyType); |
197 | |
198 | QList<QOpenGLDebugMessage> loggedMessages() const; |
199 | |
200 | public Q_SLOTS: |
201 | void logMessage(const QOpenGLDebugMessage &debugMessage); |
202 | void startLogging(LoggingMode loggingMode = AsynchronousLogging); |
203 | void stopLogging(); |
204 | |
205 | Q_SIGNALS: |
206 | void messageLogged(const QOpenGLDebugMessage &debugMessage); |
207 | |
208 | private: |
209 | Q_DISABLE_COPY(QOpenGLDebugLogger) |
210 | Q_DECLARE_PRIVATE(QOpenGLDebugLogger) |
211 | Q_PRIVATE_SLOT(d_func(), void _q_contextAboutToBeDestroyed()) |
212 | }; |
213 | |
214 | QT_END_NAMESPACE |
215 | |
216 | Q_DECLARE_METATYPE(QOpenGLDebugMessage) |
217 | |
218 | #endif // QT_NO_OPENGL |
219 | |
220 | #endif // QOPENGLDEBUG_H |
221 | |