diff options
-rw-r--r-- | src/corelib/global/qnamespace.h | 1 | ||||
-rw-r--r-- | src/corelib/global/qnamespace.qdoc | 7 | ||||
-rw-r--r-- | src/gui/kernel/qopenglcontext.cpp | 15 |
3 files changed, 20 insertions, 3 deletions
diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index 68c469db49..268f555c25 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -503,6 +503,7 @@ public: AA_UseStyleSheetPropagationInWidgetStyles = 22, // ### Qt 6: remove me AA_DontUseNativeDialogs = 23, AA_SynthesizeMouseForUnhandledTabletEvents = 24, + AA_DontCheckOpenGLContextThreadAffinity = 25, // Add new attributes before this line AA_AttributeCount diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index 86a62fd60c..f028cff6e4 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -234,6 +234,13 @@ set to true won't use the native dialogs provided by the platform. This value has been added in Qt 5.7. + \value AA_DontCheckOpenGLContextThreadAffinity When making a context + current using QOpenGLContext, do not check that the + \l{QObject#Thread Affinity}{QObject thread affinity} + of the QOpenGLContext object is the same thread calling + \l{QOpenGLContext::makeCurrent}{makeCurrent()}. This value has been + added in Qt 5.8. + The following values are obsolete: \value AA_ImmediateWidgetCreation This attribute is no longer fully diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp index 59bf2bb065..19464eeca3 100644 --- a/src/gui/kernel/qopenglcontext.cpp +++ b/src/gui/kernel/qopenglcontext.cpp @@ -940,13 +940,20 @@ GLuint QOpenGLContext::defaultFramebufferObject() const If \a surface is 0 this is equivalent to calling doneCurrent(). - Do not call this function from a different thread than the one the + Avoid calling this function from a different thread than the one the QOpenGLContext instance lives in. If you wish to use QOpenGLContext from a different thread you should first call make sure it's not current in the current thread, by calling doneCurrent() if necessary. Then call moveToThread(otherThread) before using it in the other thread. - \sa functions(), doneCurrent() + By default Qt employs a check that enforces the above condition on the + thread affinity. It is still possible to disable this check by setting the + \c{Qt::AA_DontCheckOpenGLContextThreadAffinity} application attribute. Be + sure to understand the consequences of using QObjects from outside + the thread they live in, as explained in the + \l{QObject#Thread Affinity}{QObject thread affinity} documentation. + + \sa functions(), doneCurrent(), Qt::AA_DontCheckOpenGLContextThreadAffinity */ bool QOpenGLContext::makeCurrent(QSurface *surface) { @@ -954,8 +961,10 @@ bool QOpenGLContext::makeCurrent(QSurface *surface) if (!isValid()) return false; - if (Q_UNLIKELY(thread() != QThread::currentThread())) + if (Q_UNLIKELY(!qApp->testAttribute(Qt::AA_DontCheckOpenGLContextThreadAffinity) + && thread() != QThread::currentThread())) { qFatal("Cannot make QOpenGLContext current in a different thread"); + } if (!surface) { doneCurrent(); |