diff options
Diffstat (limited to 'src/gui/kernel/qopenglcontext.cpp')
-rw-r--r-- | src/gui/kernel/qopenglcontext.cpp | 76 |
1 files changed, 66 insertions, 10 deletions
diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp index 5849c7318e..dd41318f72 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 */ @@ -153,6 +170,9 @@ QOpenGLContext *QOpenGLContextPrivate::setCurrentContext(QOpenGLContext *context qWarning("No QTLS available. currentContext won't work"); return nullptr; } + if (!context) + return nullptr; + threadContext = new QGuiGLThreadContext; qwindow_context_storage()->setLocalData(threadContext); } @@ -360,6 +380,10 @@ bool QOpenGLContext::create() return isValid(); } +QOpenGLContextPrivate::~QOpenGLContextPrivate() +{ +} + void QOpenGLContextPrivate::adopt(QPlatformOpenGLContext *context) { Q_Q(QOpenGLContext); @@ -395,30 +419,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; } /*! @@ -430,6 +471,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. */ /*! @@ -995,6 +1041,9 @@ QOpenGLContextGroup *QOpenGLContextGroup::currentContextGroup() return current ? current->shareGroup() : nullptr; } +QOpenGLContextGroupPrivate::~QOpenGLContextGroupPrivate() + = default; + void QOpenGLContextGroupPrivate::addContext(QOpenGLContext *ctx) { const auto locker = qt_scoped_lock(m_mutex); @@ -1136,6 +1185,10 @@ void QOpenGLSharedResource::free() \inmodule QtGui */ + +QOpenGLSharedResourceGuard::~QOpenGLSharedResourceGuard() + = default; + void QOpenGLSharedResourceGuard::freeResource(QOpenGLContext *context) { if (m_id) { @@ -1235,6 +1288,9 @@ void QOpenGLMultiGroupSharedResource::cleanup(QOpenGLContextGroup *group, QOpenG m_groups.removeOne(group); } +QOpenGLContextVersionFunctionHelper::~QOpenGLContextVersionFunctionHelper() + = default; + #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug debug, const QOpenGLContext *ctx) { |