Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
src_gui_opengl_qopengldebug.cpp
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3#include <QOpenGLContext>
4#include <QSurfaceFormat>
5#include <QWidget>
6#include <QtOpenGL/QOpenGLDebugLogger>
7
9struct LogHandler : public QObject
10{
12public slots:
13 static bool handleLoggedMessage() { return true; };
14};
15struct SnippetWrapper : public QObject
16{
18 void wrapper1(LogHandler *receiver);
20};
21
22void wrapper0() {
23
24//! [0]
25GLenum error = GL_NO_ERROR;
26do {
27 error = glGetError();
28 if (error != GL_NO_ERROR) {
29 // handle the error
30 }
31} while (error != GL_NO_ERROR);
32//! [0]
33
34
35//! [1]
36QSurfaceFormat format;
37// asks for a OpenGL 3.2 debug context using the Core profile
38format.setMajorVersion(3);
39format.setMinorVersion(2);
40format.setProfile(QSurfaceFormat::CoreProfile);
41format.setOption(QSurfaceFormat::DebugContext);
42
43QOpenGLContext *context = new QOpenGLContext;
44context->setFormat(format);
45context->create();
46//! [1]
47
48} // wrapper0
49
50
52//! [2]
53QOpenGLContext *ctx = QOpenGLContext::currentContext();
54QOpenGLDebugLogger *logger = new QOpenGLDebugLogger(this);
55
56logger->initialize(); // initializes in the current context, i.e. ctx
57//! [2]
58
59
60//! [3]
61ctx->hasExtension(QByteArrayLiteral("GL_KHR_debug"));
62//! [3]
63
64
65//! [4]
66const QList<QOpenGLDebugMessage> messages = logger->loggedMessages();
67for (const QOpenGLDebugMessage &message : messages)
68 qDebug() << message;
69//! [4]
70
71
72//! [5]
73connect(logger, &QOpenGLDebugLogger::messageLogged, receiver, &LogHandler::handleLoggedMessage);
74logger->startLogging();
75//! [5]
76
77
78//! [6]
79QOpenGLDebugMessage message =
80 QOpenGLDebugMessage::createApplicationMessage(QStringLiteral("Custom message"));
81
82logger->logMessage(message);
83//! [6]
84
85} // SnippetWrapper::wrapper1
86} // src_gui_opengl_qopengldebug