summaryrefslogtreecommitdiffstats
path: root/src/gui/opengl
diff options
context:
space:
mode:
authorCristian Maureira-Fredes <cristian.maureira-fredes@qt.io>2018-09-03 14:02:13 +0200
committerCristian Maureira-Fredes <cristian.maureira-fredes@qt.io>2018-10-15 10:55:18 +0000
commit1f6bfc220774e9407fe88916843b76ed103cff72 (patch)
tree8d6157d5b974e6045d75a716f8eb0db4daefa35f /src/gui/opengl
parent02a214442781bf112c1cc85d2470c6fcec8ed207 (diff)
Doc: Move literal code block to a separate file
We need to override this snippet for the documentation we generate for Qt for Python, and it is easier to have it on a separate file. Task-number: PYSIDE-801 Task-number: PYSIDE-691 Change-Id: Ideb5b6af25024279f167137d3b65660bb9c96a7e Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
Diffstat (limited to 'src/gui/opengl')
-rw-r--r--src/gui/opengl/qopenglbuffer.cpp11
-rw-r--r--src/gui/opengl/qopengldebug.cpp65
-rw-r--r--src/gui/opengl/qopenglfunctions.cpp63
3 files changed, 14 insertions, 125 deletions
diff --git a/src/gui/opengl/qopenglbuffer.cpp b/src/gui/opengl/qopenglbuffer.cpp
index 000494244d..537097c09f 100644
--- a/src/gui/opengl/qopenglbuffer.cpp
+++ b/src/gui/opengl/qopenglbuffer.cpp
@@ -63,12 +63,7 @@ QT_BEGIN_NAMESPACE
QOpenGLBuffer objects can be copied around as a reference to the
underlying OpenGL buffer object:
- \code
- QOpenGLBuffer buffer1(QOpenGLBuffer::IndexBuffer);
- buffer1.create();
-
- QOpenGLBuffer buffer2 = buffer1;
- \endcode
+ \snippet code/src_gui_opengl_qopenglbuffer.cpp 0
QOpenGLBuffer performs a shallow copy when objects are copied in this
manner, but does not implement copy-on-write semantics. The original
@@ -484,9 +479,7 @@ void QOpenGLBuffer::release()
been bound to the context but wants to make sure that it
is released.
- \code
- QOpenGLBuffer::release(QOpenGLBuffer::VertexBuffer);
- \endcode
+ \snippet code/src_gui_opengl_qopenglbuffer.cpp 1
*/
void QOpenGLBuffer::release(QOpenGLBuffer::Type type)
{
diff --git a/src/gui/opengl/qopengldebug.cpp b/src/gui/opengl/qopengldebug.cpp
index 7072db5af4..2e628a2bd5 100644
--- a/src/gui/opengl/qopengldebug.cpp
+++ b/src/gui/opengl/qopengldebug.cpp
@@ -89,16 +89,7 @@ QT_BEGIN_NAMESPACE
call. Moreover, OpenGL errors stack up, therefore glGetError should always
be used in a loop like this:
- \code
-
- GLenum error = GL_NO_ERROR;
- do {
- error = glGetError();
- if (error != GL_NO_ERROR)
- // handle the error
- } while (error != GL_NO_ERROR);
-
- \endcode
+ \snippet code/src_gui_opengl_qopengldebug.cpp 0
If you try to clear the error stack, make sure not just keep going until
GL_NO_ERROR is returned but also break on GL_CONTEXT_LOST as that error
@@ -125,20 +116,7 @@ QT_BEGIN_NAMESPACE
to create a debug context from Qt, you must set the QSurfaceFormat::DebugContext
format option on the QSurfaceFormat used to create the QOpenGLContext object:
- \code
-
- 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();
-
- \endcode
+ \snippet code/src_gui_opengl_qopengldebug.cpp 1
Note that requesting a 3.2 OpenGL Core Profile is just for the example's
purposes; this class is not tied to any specific OpenGL or OpenGL ES
@@ -152,24 +130,13 @@ QT_BEGIN_NAMESPACE
object), and like the other OpenGL functions in Qt you \e{must} initialize
it before usage by calling initialize() whilst there is a current OpenGL context:
- \code
-
- QOpenGLContext *ctx = QOpenGLContext::currentContext();
- QOpenGLDebugLogger *logger = new QOpenGLDebugLogger(this);
-
- logger->initialize(); // initializes in the current context, i.e. ctx
-
- \endcode
+ \snippet code/src_gui_opengl_qopengldebug.cpp 2
Note that the \c{GL_KHR_debug} extension \e{must} be available in the context
in order to access the messages logged by OpenGL. You can check the
presence of this extension by calling:
- \code
-
- ctx->hasExtension(QByteArrayLiteral("GL_KHR_debug"))
-
- \endcode
+ \snippet code/src_gui_opengl_qopengldebug.cpp 3
where \c{ctx} is a valid QOpenGLContext. If the extension is not available,
initialize() will return false.
@@ -179,13 +146,7 @@ QT_BEGIN_NAMESPACE
OpenGL implementations keep an internal log of debug messages. Messages
stored in this log can be retrieved by using the loggedMessages() function:
- \code
-
- const QList<QOpenGLDebugMessage> messages = logger->loggedMessages();
- for (const QOpenGLDebugMessage &message : messages)
- qDebug() << message;
-
- \endcode
+ \snippet code/src_gui_opengl_qopengldebug.cpp 4
The internal log has a limited size; when it fills up, older messages will
get discarded to make room for the new incoming messages. When you call
@@ -203,12 +164,7 @@ QT_BEGIN_NAMESPACE
you need to connect a suitable slot to the messageLogged() signal, and
start logging by calling startLogging():
- \code
-
- connect(logger, &QOpenGLDebugLogger::messageLogged, receiver, &LogHandler::handleLoggedMessage);
- logger->startLogging();
-
- \endcode
+ \snippet code/src_gui_opengl_qopengldebug.cpp 5
Similarly, logging can be disabled at any time by calling the stopLogging()
function.
@@ -259,14 +215,7 @@ QT_BEGIN_NAMESPACE
\l{QOpenGLDebugMessage::}{createThirdPartyMessage()}, and then inserting it
into the log by calling logMessage():
- \code
-
- QOpenGLDebugMessage message =
- QOpenGLDebugMessage::createApplicationMessage(QStringLiteral("Custom message"));
-
- logger->logMessage(message);
-
- \endcode
+ \snippet code/src_gui_opengl_qopengldebug.cpp 6
Note that OpenGL implementations have a vendor-specific limit to the length
of the messages that can be inserted in the debug log. You can retrieve
diff --git a/src/gui/opengl/qopenglfunctions.cpp b/src/gui/opengl/qopenglfunctions.cpp
index 4f48604a88..b4ff21f3fd 100644
--- a/src/gui/opengl/qopenglfunctions.cpp
+++ b/src/gui/opengl/qopenglfunctions.cpp
@@ -90,65 +90,18 @@ void CLASS::init(QOpenGLContext *context) \
that need it. The recommended way to use QOpenGLFunctions is by
direct inheritance:
- \code
- class MyGLWindow : public QWindow, protected QOpenGLFunctions
- {
- Q_OBJECT
- public:
- MyGLWindow(QScreen *screen = 0);
-
- 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();
- }
- \endcode
+ \snippet code/src_gui_opengl_qopenglfunctions.cpp 0
The \c{paintGL()} function can then use any of the OpenGL ES 2.0
functions without explicit resolution, such as glActiveTexture()
in the following example:
- \code
- void MyGLWindow::paintGL()
- {
- m_context->makeCurrent(this);
- glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D, textureId);
- ...
- m_context->swapBuffers(this);
- m_context->doneCurrent();
- }
- \endcode
+ \snippet code/src_gui_opengl_qopenglfunctions.cpp 1
QOpenGLFunctions can also be used directly for ad-hoc invocation
of OpenGL ES 2.0 functions on all platforms:
- \code
- QOpenGLFunctions glFuncs(QOpenGLContext::currentContext());
- glFuncs.glActiveTexture(GL_TEXTURE1);
- \endcode
+ \snippet code/src_gui_opengl_qopenglfunctions.cpp 2
An alternative approach is to query the context's associated
QOpenGLFunctions instance. This is somewhat faster than the previous
@@ -157,10 +110,7 @@ void CLASS::init(QOpenGLContext *context) \
resolving happens only once for a given context, regardless of the number of
QOpenGLFunctions instances initialized for it.
- \code
- QOpenGLFunctions *glFuncs = QOpenGLContext::currentContext()->functions();
- glFuncs->glActiveTexture(GL_TEXTURE1);
- \endcode
+ \snippet code/src_gui_opengl_qopenglfunctions.cpp 3
QOpenGLFunctions provides wrappers for all OpenGL ES 2.0
functions, including the common subset of OpenGL 1.x and ES
@@ -175,10 +125,7 @@ void CLASS::init(QOpenGLContext *context) \
feature. For example, the following checks if non power of two
textures are available:
- \code
- QOpenGLFunctions funcs(QOpenGLContext::currentContext());
- bool npot = funcs.hasOpenGLFeature(QOpenGLFunctions::NPOTTextures);
- \endcode
+ \snippet code/src_gui_opengl_qopenglfunctions.cpp 4
\sa QOpenGLContext, QSurfaceFormat
*/