diff options
author | Paul Wicking <paul.wicking@qt.io> | 2020-08-25 16:32:24 +0200 |
---|---|---|
committer | Paul Wicking <paul.wicking@qt.io> | 2020-08-28 12:25:34 +0200 |
commit | ef5b4a98911b6f43acf15d06cbbf84df53f749e9 (patch) | |
tree | 8e687ee1c75fcd3fedcaeced14b988915acdc02d /src/gui | |
parent | ea70c3c9f9abf17a0daddd9a61f41d3c39a4c152 (diff) |
Doc: Compile OpenGL snippets
Fix minor issues (e.g. whitespace, missing semi-colon) in passing.
Change-Id: I022ac0382ae1068a75246964c37532e7e15417b0
Done-with: Nico Vertriest <nico.vertriest@qt.io>
Task-number: QTBUG-81486
Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
Diffstat (limited to 'src/gui')
4 files changed, 146 insertions, 81 deletions
diff --git a/src/gui/doc/snippets/code/code.pro b/src/gui/doc/snippets/code/code.pro index 2e5e58f7ee..a5498f38a3 100644 --- a/src/gui/doc/snippets/code/code.pro +++ b/src/gui/doc/snippets/code/code.pro @@ -21,4 +21,7 @@ SOURCES = \ src_gui_kernel_qguiapplication_x11.cpp \ src_gui_kernel_qkeysequence.cpp \ src_gui_kernel_qshortcutmap.cpp \ - src_gui_math3d_qquaternion.cpp + src_gui_math3d_qquaternion.cpp \ + src_gui_opengl_qopenglbuffer.cpp \ + src_gui_opengl_qopengldebug.cpp \ + src_gui_opengl_qopenglfunctions.cpp diff --git a/src/gui/doc/snippets/code/src_gui_opengl_qopenglbuffer.cpp b/src/gui/doc/snippets/code/src_gui_opengl_qopenglbuffer.cpp index 57dc909598..bd768b1ed7 100644 --- a/src/gui/doc/snippets/code/src_gui_opengl_qopenglbuffer.cpp +++ b/src/gui/doc/snippets/code/src_gui_opengl_qopenglbuffer.cpp @@ -47,14 +47,22 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include <QtOpenGL/QOpenGLBuffer> + +namespace src_gui_opengl_qopenglbuffer { +void wrapper() { //! [0] - QOpenGLBuffer buffer1(QOpenGLBuffer::IndexBuffer); - buffer1.create(); +QOpenGLBuffer buffer1(QOpenGLBuffer::IndexBuffer); +buffer1.create(); - QOpenGLBuffer buffer2 = buffer1; +QOpenGLBuffer buffer2 = buffer1; //! [0] + //! [1] - QOpenGLBuffer::release(QOpenGLBuffer::VertexBuffer); +QOpenGLBuffer::release(QOpenGLBuffer::VertexBuffer); //! [1] + +} // wrapper +} // src_gui_opengl_qopenglbuffer diff --git a/src/gui/doc/snippets/code/src_gui_opengl_qopengldebug.cpp b/src/gui/doc/snippets/code/src_gui_opengl_qopengldebug.cpp index e82447a174..241450c23a 100644 --- a/src/gui/doc/snippets/code/src_gui_opengl_qopengldebug.cpp +++ b/src/gui/doc/snippets/code/src_gui_opengl_qopengldebug.cpp @@ -47,54 +47,87 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include <QOpenGLContext> +#include <QSurfaceFormat> +#include <QWidget> +#include <QtOpenGL/QOpenGLDebugLogger> + +namespace src_gui_opengl_qopengldebug { +struct LogHandler : public QObject +{ + Q_OBJECT +public slots: + static bool handleLoggedMessage() { return true; }; +}; +struct SnippetWrapper : public QObject +{ + Q_OBJECT + void wrapper1(LogHandler *receiver); + const QWidget *receiver; +}; + +void wrapper0() { //! [0] - GLenum error = GL_NO_ERROR; - do { - error = glGetError(); - if (error != GL_NO_ERROR) - // handle the error - } while (error != GL_NO_ERROR); +GLenum error = GL_NO_ERROR; +do { + error = glGetError(); + if (error != GL_NO_ERROR) { + // handle the error + } +} while (error != GL_NO_ERROR); //! [0] + //! [1] - QSurfaceFormat format; - // asks for a OpenGL 3.2 debug context using the Core profile - format.setMajorVersion(3); - format.setMinorVersion(2); - format.setProfile(QSurfaceFormat::CoreProfile); - format.setOption(QSurfaceFormat::DebugContext); - - QOpenGLContext *context = new QOpenGLContext; - context->setFormat(format); - context->create(); +QSurfaceFormat format; +// asks for a OpenGL 3.2 debug context using the Core profile +format.setMajorVersion(3); +format.setMinorVersion(2); +format.setProfile(QSurfaceFormat::CoreProfile); +format.setOption(QSurfaceFormat::DebugContext); + +QOpenGLContext *context = new QOpenGLContext; +context->setFormat(format); +context->create(); //! [1] +} // wrapper0 + + +void SnippetWrapper::wrapper1(LogHandler *receiver) { //! [2] - QOpenGLContext *ctx = QOpenGLContext::currentContext(); - QOpenGLDebugLogger *logger = new QOpenGLDebugLogger(this); +QOpenGLContext *ctx = QOpenGLContext::currentContext(); +QOpenGLDebugLogger *logger = new QOpenGLDebugLogger(this); - logger->initialize(); // initializes in the current context, i.e. ctx +logger->initialize(); // initializes in the current context, i.e. ctx //! [2] + //! [3] - ctx->hasExtension(QByteArrayLiteral("GL_KHR_debug")) +ctx->hasExtension(QByteArrayLiteral("GL_KHR_debug")); //! [3] + //! [4] - const QList<QOpenGLDebugMessage> messages = logger->loggedMessages(); - for (const QOpenGLDebugMessage &message : messages) - qDebug() << message; +const QList<QOpenGLDebugMessage> messages = logger->loggedMessages(); +for (const QOpenGLDebugMessage &message : messages) + qDebug() << message; //! [4] + //! [5] - connect(logger, &QOpenGLDebugLogger::messageLogged, receiver, &LogHandler::handleLoggedMessage); - logger->startLogging(); +connect(logger, &QOpenGLDebugLogger::messageLogged, receiver, &LogHandler::handleLoggedMessage); +logger->startLogging(); //! [5] + //! [6] - QOpenGLDebugMessage message = - QOpenGLDebugMessage::createApplicationMessage(QStringLiteral("Custom message")); +QOpenGLDebugMessage message = + QOpenGLDebugMessage::createApplicationMessage(QStringLiteral("Custom message")); - logger->logMessage(message); +logger->logMessage(message); //! [6] + +} // SnippetWrapper::wrapper1 +} // src_gui_opengl_qopengldebug diff --git a/src/gui/doc/snippets/code/src_gui_opengl_qopenglfunctions.cpp b/src/gui/doc/snippets/code/src_gui_opengl_qopenglfunctions.cpp index e4255107d3..946e3caef5 100644 --- a/src/gui/doc/snippets/code/src_gui_opengl_qopenglfunctions.cpp +++ b/src/gui/doc/snippets/code/src_gui_opengl_qopenglfunctions.cpp @@ -47,66 +47,87 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include <QOpenGLFunctions> +#include <QtOpenGL/QOpenGLWindow> + +#include <QSurface> +#include <QWidget> +#include <QWindow> + +namespace src_gui_opengl_qopenglfunctions { //! [0] - class MyGLWindow : public QWindow, protected QOpenGLFunctions - { - Q_OBJECT - public: - explicit MyGLWindow(QScreen *screen = nullptr); - - protected: - void initializeGL(); - void paintGL(); - - QOpenGLContext *m_context; - }; - - MyGLWindow(QScreen *screen) - : QWindow(screen), QOpenGLWidget(parent) - { - setSurfaceType(OpenGLSurface); - create(); - - // Create an OpenGL context - m_context = new QOpenGLContext; - m_context->create(); - - // Setup scene and render it - initializeGL(); - paintGL(); - } - - void MyGLWindow::initializeGL() - { - m_context->makeCurrent(this); - initializeOpenGLFunctions(); - } +class MyGLWindow : public QWindow, protected QOpenGLFunctions +{ + Q_OBJECT +public: + explicit MyGLWindow(QScreen *screen = nullptr); + +protected: + void initializeGL(); + void paintGL(); + + QOpenGLContext *m_context; +}; + +MyGLWindow::MyGLWindow(QScreen *screen) + : QWindow(screen) +{ + setSurfaceType(OpenGLSurface); + create(); + + // Create an OpenGL context + m_context = new QOpenGLContext; + m_context->create(); + + // Setup scene and render it + initializeGL(); + paintGL(); +}; + +void MyGLWindow::initializeGL() +{ + m_context->makeCurrent(this); + initializeOpenGLFunctions(); +} //! [0] + +int textureId = 0; + //! [1] - void MyGLWindow::paintGL() - { - m_context->makeCurrent(this); - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, textureId); - ... - m_context->swapBuffers(this); - m_context->doneCurrent(); - } +void MyGLWindow::paintGL() +{ + m_context->makeCurrent(this); + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, textureId); + // ... + m_context->swapBuffers(this); + m_context->doneCurrent(); +} //! [1] + +void wrapper0() { //! [2] - QOpenGLFunctions glFuncs(QOpenGLContext::currentContext()); - glFuncs.glActiveTexture(GL_TEXTURE1); +QOpenGLFunctions glFuncs(QOpenGLContext::currentContext()); +glFuncs.glActiveTexture(GL_TEXTURE1); //! [2] +} // wrapper0 + +void wrapper1() { //! [3] - QOpenGLFunctions *glFuncs = QOpenGLContext::currentContext()->functions(); - glFuncs->glActiveTexture(GL_TEXTURE1); +QOpenGLFunctions *glFuncs = QOpenGLContext::currentContext()->functions(); +glFuncs->glActiveTexture(GL_TEXTURE1); //! [3] + //! [4] - QOpenGLFunctions funcs(QOpenGLContext::currentContext()); - bool npot = funcs.hasOpenGLFeature(QOpenGLFunctions::NPOTTextures); +QOpenGLFunctions funcs(QOpenGLContext::currentContext()); +bool npot = funcs.hasOpenGLFeature(QOpenGLFunctions::NPOTTextures); //! [4] + +Q_UNUSED(npot); +} // wrapper1 +} // src_gui_opengl_qopenglfunctions |