From 5b460080fba5faa053b6dc0a39ac4c0b9794295c Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Thu, 12 Feb 2015 16:46:55 +0100 Subject: QOpenGLContext: expose the shared global context We're documenting that this context exists, therefore applications are allowed to assume that it exists. For the same reason, we should expose it as public API -- an application should be allowed to upload GL objects before creating or showing QOpenGLWidgets that use them. Change-Id: Iedbba7cd393018d93833fd2a6b02cce0639a89b4 Reviewed-by: Sean Harmer Reviewed-by: Laszlo Agocs --- src/gui/kernel/qopenglcontext.cpp | 25 +++++++++++++++++++++++++ src/gui/kernel/qopenglcontext.h | 1 + 2 files changed, 26 insertions(+) (limited to 'src') diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp index b52fcfe796..90c54c4039 100644 --- a/src/gui/kernel/qopenglcontext.cpp +++ b/src/gui/kernel/qopenglcontext.cpp @@ -1204,6 +1204,31 @@ bool QOpenGLContext::supportsThreadedOpenGL() return QGuiApplicationPrivate::instance()->platformIntegration()->hasCapability(QPlatformIntegration::ThreadedOpenGL); } +/*! + \since 5.5 + + Returns the application-wide shared OpenGL context, if present. + Otherwise, returns a null pointer. + + This is useful if you need to upload OpenGL objects (buffers, textures, + etc.) before creating or showing a QOpenGLWidget or QQuickWidget. + + \note You must set the Qt::AA_ShareOpenGLContexts flag on QGuiApplication + before creating the QGuiApplication object, otherwise Qt may not create a + global shared context. + + \warning Do not attempt to make the context returned by this function + current on any surface. Instead, you can create a new context which shares + with the global one, and then make the new context current. + + \sa Qt::AA_ShareOpenGLContexts, setShareContext(), makeCurrent() +*/ +QOpenGLContext *QOpenGLContext::globalShareContext() +{ + Q_ASSERT(qGuiApp); + return qt_gl_global_share_context(); +} + /*! \internal */ diff --git a/src/gui/kernel/qopenglcontext.h b/src/gui/kernel/qopenglcontext.h index 4d5ee08a1b..30a9bc3ad9 100644 --- a/src/gui/kernel/qopenglcontext.h +++ b/src/gui/kernel/qopenglcontext.h @@ -199,6 +199,7 @@ public: bool isOpenGLES() const; static bool supportsThreadedOpenGL(); + static QOpenGLContext *globalShareContext(); Q_SIGNALS: void aboutToBeDestroyed(); -- cgit v1.2.3