diff options
Diffstat (limited to 'src/gui/opengl/qopenglfunctions.cpp')
-rw-r--r-- | src/gui/opengl/qopenglfunctions.cpp | 63 |
1 files changed, 5 insertions, 58 deletions
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 */ |