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.cpp117
1 files changed, 67 insertions, 50 deletions
diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp
index bdbd18f771..02781f4aa0 100644
--- a/src/gui/kernel/qopenglcontext.cpp
+++ b/src/gui/kernel/qopenglcontext.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <qpa/qplatformopenglcontext.h>
#include <qpa/qplatformintegration.h>
@@ -78,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
/*!
@@ -105,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
@@ -173,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
*/
@@ -396,6 +377,10 @@ bool QOpenGLContext::create()
return isValid();
}
+QOpenGLContextPrivate::~QOpenGLContextPrivate()
+{
+}
+
void QOpenGLContextPrivate::adopt(QPlatformOpenGLContext *context)
{
Q_Q(QOpenGLContext);
@@ -431,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;
}
/*!
@@ -466,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.
*/
/*!
@@ -1031,6 +1038,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);
@@ -1172,6 +1182,10 @@ void QOpenGLSharedResource::free()
\inmodule QtGui
*/
+
+QOpenGLSharedResourceGuard::~QOpenGLSharedResourceGuard()
+ = default;
+
void QOpenGLSharedResourceGuard::freeResource(QOpenGLContext *context)
{
if (m_id) {
@@ -1271,6 +1285,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)
{
@@ -1335,6 +1352,6 @@ void *QOpenGLContext::resolveInterface(const char *name, int revision) const
return nullptr;
}
-#include "moc_qopenglcontext.cpp"
-
QT_END_NAMESPACE
+
+#include "moc_qopenglcontext.cpp"