summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qopenglcontext.cpp
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2016-04-08 12:38:00 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2016-05-02 11:52:00 +0000
commitea97a43175bde48c6cbaf643988b286099c1667b (patch)
treeaec36ef6bd57470a12330d4a1b73795ce4df393e /src/gui/kernel/qopenglcontext.cpp
parentf40dbe0d0b54ce83d2168e82905cf4f75059a841 (diff)
QOpenGLContext: add a way to disable the thread affinity check
The problem of the check is that it makes Qt non compliant with OpenGL thread affinity semantics. One is allowed to make a GL context current on any thread, without the Qt-specific idea of moving the QOpenGLContext to that thread first. Moreover, the move is plain impossible if the user needs to handle the context to 3rd party code which assumes the context to have GL semantics. Add an application flag to disable that. Change-Id: I55ca02ee62f8cc171a9a1bddef5331ad0949c061 Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
Diffstat (limited to 'src/gui/kernel/qopenglcontext.cpp')
-rw-r--r--src/gui/kernel/qopenglcontext.cpp15
1 files changed, 12 insertions, 3 deletions
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();