summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qopenglcontext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/kernel/qopenglcontext.cpp')
-rw-r--r--src/gui/kernel/qopenglcontext.cpp63
1 files changed, 49 insertions, 14 deletions
diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp
index 99c13257a3..02781f4aa0 100644
--- a/src/gui/kernel/qopenglcontext.cpp
+++ b/src/gui/kernel/qopenglcontext.cpp
@@ -42,7 +42,7 @@ static QOpenGLContext *global_share_context = nullptr;
#ifndef QT_NO_DEBUG
QHash<QOpenGLContext *, bool> QOpenGLContextPrivate::makeCurrentTracker;
-QMutex QOpenGLContextPrivate::makeCurrentTrackerMutex;
+Q_CONSTINIT QMutex QOpenGLContextPrivate::makeCurrentTrackerMutex;
#endif
/*!
@@ -69,6 +69,7 @@ QOpenGLContext *qt_gl_global_share_context()
/*!
\class QOpenGLContext
+ \ingroup painting-3D
\inmodule QtGui
\since 5.0
\brief The QOpenGLContext class represents a native OpenGL context, enabling
@@ -137,6 +138,22 @@ QOpenGLContext *qt_gl_global_share_context()
application is portable between different platforms. However, if you use
QOpenGLFunctions::glBindFramebuffer(), this is done automatically for you.
+ \warning WebAssembly
+
+ We recommend that only one QOpenGLContext is made current with a QSurface,
+ for the entire lifetime of the QSurface. Should more than once context be used,
+ it is important to understand that multiple QOpenGLContext instances may be
+ backed by the same native context underneath with the WebAssembly platform.
+ Therefore, calling makeCurrent() with the same QSurface on two QOpenGLContext
+ objects may not switch to a different native context in the second call. As
+ a result, any OpenGL state changes done after the second makeCurrent() may
+ alter the state of the first QOpenGLContext as well, as they are all backed
+ by the same native context.
+
+ \note This means that when targeting WebAssembly with existing OpenGL-based
+ Qt code, some porting may be required to cater to these limitations.
+
+
\sa QOpenGLFunctions, QOpenGLBuffer, QOpenGLShaderProgram, QOpenGLFramebufferObject
*/
@@ -362,10 +379,6 @@ bool QOpenGLContext::create()
QOpenGLContextPrivate::~QOpenGLContextPrivate()
{
- //do not delete the QOpenGLContext handle here as it is deleted in
- //QWidgetPrivate::deleteTLSysExtra()
-
- delete versionFunctions;
}
void QOpenGLContextPrivate::adopt(QPlatformOpenGLContext *context)
@@ -403,30 +416,47 @@ void QOpenGLContextPrivate::adopt(QPlatformOpenGLContext *context)
void QOpenGLContext::destroy()
{
Q_D(QOpenGLContext);
+
+ // Notify that the native context and the QPlatformOpenGLContext are going
+ // to go away.
if (d->platformGLContext)
emit aboutToBeDestroyed();
- if (QOpenGLContext::currentContext() == this)
- doneCurrent();
- if (d->shareGroup)
- d->shareGroup->d_func()->removeContext(this);
- d->shareGroup = nullptr;
- delete d->platformGLContext;
- d->platformGLContext = nullptr;
- delete d->functions;
- d->functions = nullptr;
+ // Invoke callbacks for helpers and invalidate.
if (d->textureFunctionsDestroyCallback) {
d->textureFunctionsDestroyCallback();
d->textureFunctionsDestroyCallback = nullptr;
}
d->textureFunctions = nullptr;
+ delete d->versionFunctions;
+ d->versionFunctions = nullptr;
+
if (d->vaoHelperDestroyCallback) {
Q_ASSERT(d->vaoHelper);
d->vaoHelperDestroyCallback(d->vaoHelper);
d->vaoHelperDestroyCallback = nullptr;
}
d->vaoHelper = nullptr;
+
+ // Tear down function wrappers.
+ delete d->versionFunctions;
+ d->versionFunctions = nullptr;
+
+ delete d->functions;
+ d->functions = nullptr;
+
+ // Clean up and destroy the native context machinery.
+ if (QOpenGLContext::currentContext() == this)
+ doneCurrent();
+
+ if (d->shareGroup)
+ d->shareGroup->d_func()->removeContext(this);
+
+ d->shareGroup = nullptr;
+
+ delete d->platformGLContext;
+ d->platformGLContext = nullptr;
}
/*!
@@ -438,6 +468,11 @@ void QOpenGLContext::destroy()
If you wish to make the context current in order to do clean-up, make sure
to only connect to the signal using a direct connection.
+
+ \note In Qt for Python, this signal will not be received when emitted
+ from the destructor of QOpenGLWidget or QOpenGLWindow due to the Python
+ instance already being destroyed. We recommend doing cleanups
+ in QWidget::hideEvent() instead.
*/
/*!