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>bb10
parent
ea70c3c9f9
commit
ef5b4a9891
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
//! [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();
|
||||
//! [1]
|
||||
|
||||
//! [2]
|
||||
QOpenGLContext *ctx = QOpenGLContext::currentContext();
|
||||
QOpenGLDebugLogger *logger = new QOpenGLDebugLogger(this);
|
||||
} // wrapper0
|
||||
|
||||
logger->initialize(); // initializes in the current context, i.e. ctx
|
||||
|
||||
void SnippetWrapper::wrapper1(LogHandler *receiver) {
|
||||
//! [2]
|
||||
QOpenGLContext *ctx = QOpenGLContext::currentContext();
|
||||
QOpenGLDebugLogger *logger = new QOpenGLDebugLogger(this);
|
||||
|
||||
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"));
|
||||
|
||||
logger->logMessage(message);
|
||||
//! [6]
|
||||
QOpenGLDebugMessage message =
|
||||
QOpenGLDebugMessage::createApplicationMessage(QStringLiteral("Custom message"));
|
||||
|
||||
logger->logMessage(message);
|
||||
//! [6]
|
||||
|
||||
} // SnippetWrapper::wrapper1
|
||||
} // src_gui_opengl_qopengldebug
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
class MyGLWindow : public QWindow, protected QOpenGLFunctions
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MyGLWindow(QScreen *screen = nullptr);
|
||||
|
||||
protected:
|
||||
void initializeGL();
|
||||
void paintGL();
|
||||
protected:
|
||||
void initializeGL();
|
||||
void paintGL();
|
||||
|
||||
QOpenGLContext *m_context;
|
||||
};
|
||||
QOpenGLContext *m_context;
|
||||
};
|
||||
|
||||
MyGLWindow(QScreen *screen)
|
||||
: QWindow(screen), QOpenGLWidget(parent)
|
||||
{
|
||||
setSurfaceType(OpenGLSurface);
|
||||
create();
|
||||
MyGLWindow::MyGLWindow(QScreen *screen)
|
||||
: QWindow(screen)
|
||||
{
|
||||
setSurfaceType(OpenGLSurface);
|
||||
create();
|
||||
|
||||
// Create an OpenGL context
|
||||
m_context = new QOpenGLContext;
|
||||
m_context->create();
|
||||
// Create an OpenGL context
|
||||
m_context = new QOpenGLContext;
|
||||
m_context->create();
|
||||
|
||||
// Setup scene and render it
|
||||
initializeGL();
|
||||
paintGL();
|
||||
}
|
||||
// Setup scene and render it
|
||||
initializeGL();
|
||||
paintGL();
|
||||
};
|
||||
|
||||
void MyGLWindow::initializeGL()
|
||||
{
|
||||
m_context->makeCurrent(this);
|
||||
initializeOpenGLFunctions();
|
||||
}
|
||||
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]
|
||||
|
||||
//! [2]
|
||||
QOpenGLFunctions glFuncs(QOpenGLContext::currentContext());
|
||||
glFuncs.glActiveTexture(GL_TEXTURE1);
|
||||
//! [2]
|
||||
|
||||
void wrapper0() {
|
||||
//! [2]
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue