summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-02-06 12:39:05 +0100
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2015-02-07 20:29:30 +0000
commit4d19c3a35461a2cfe3caa076e262188cc8d5128b (patch)
tree1d8db184b5c1c7c81260db96a1971ada134aa1fd /src/gui/kernel
parentb8aeb4a256a6906f82255b7a60268870cca7dd00 (diff)
Avoid the initializeOpenGLFunctions() call after versionFunctions()
Try making it compatible with QOpenGLContext::functions() which returns an already initialized QOpenGLFunctions. Unfortunately we cannot make them 100% compatible because functions() conveniently requires that the context (or a sharing context) is current. versionFunctions() has no such requirement and we cannot safely introduce it anymore. What we can do is to state that as long as the context is the current one, the initializeOpenGLFunctions() call can be omitted. If another context (or no context) is current, the call will still be needed, like it is today. Also, we require that the exact same context is current. Sharing does not count since the exact behavior of sharing contexts with different versions is unknown. [ChangeLog][QtGui] initializeOpenGLFunctions() no longer needs to be called when querying a versioned function wrapper object via QOpenGLContext::versionFunctions(). Change-Id: I0b4d1ae1f780da3f5dec9fc8dc67255c13faab6e Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/qopenglcontext.cpp29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp
index 8cfb4154c1..ff7e654648 100644
--- a/src/gui/kernel/qopenglcontext.cpp
+++ b/src/gui/kernel/qopenglcontext.cpp
@@ -370,13 +370,10 @@ int QOpenGLContextPrivate::maxTextureSize()
QOpenGLFunctions_1_0 *gl1funcs = 0;
QOpenGLFunctions_3_2_Core *gl3funcs = 0;
- if (q->format().profile() == QSurfaceFormat::CoreProfile) {
+ if (q->format().profile() == QSurfaceFormat::CoreProfile)
gl3funcs = q->versionFunctions<QOpenGLFunctions_3_2_Core>();
- gl3funcs->initializeOpenGLFunctions();
- } else {
+ else
gl1funcs = q->versionFunctions<QOpenGLFunctions_1_0>();
- gl1funcs->initializeOpenGLFunctions();
- }
Q_ASSERT(gl1funcs || gl3funcs);
@@ -718,9 +715,12 @@ QOpenGLFunctions *QOpenGLContext::functions() const
\overload versionFunctions()
Returns a pointer to an object that provides access to all functions for
- the version and profile of this context. Before using any of the functions
- they must be initialized by calling QAbstractOpenGLFunctions::initializeOpenGLFunctions()
- with this context being the current context.
+ the version and profile of this context. There is no need to call
+ QAbstractOpenGLFunctions::initializeOpenGLFunctions() as long as this context
+ is current. It is also possible to call this function when the context is not
+ current, but in that case it is the caller's responsibility to ensure proper
+ intiialization by calling QAbstractOpenGLFunctions::initializeOpenGLFunctions()
+ afterwards.
Usually one would use the template version of this function to automatically
have the result cast to the correct type.
@@ -732,7 +732,6 @@ QOpenGLFunctions *QOpenGLContext::functions() const
qWarning() << "Could not obtain required OpenGL context version";
exit(1);
}
- funcs->initializeOpenGLFunctions();
\endcode
It is possible to request a functions object for a different version and profile
@@ -762,9 +761,12 @@ QOpenGLFunctions *QOpenGLContext::functions() const
/*!
Returns a pointer to an object that provides access to all functions for the
- \a versionProfile of this context. Before using any of the functions they must
- be initialized by calling QAbstractOpenGLFunctions::initializeOpenGLFunctions()
- with this context being the current context.
+ \a versionProfile of this context. There is no need to call
+ QAbstractOpenGLFunctions::initializeOpenGLFunctions() as long as this context
+ is current. It is also possible to call this function when the context is not
+ current, but in that case it is the caller's responsibility to ensure proper
+ initialization by calling QAbstractOpenGLFunctions::initializeOpenGLFunctions()
+ afterwards.
Usually one would use the template version of this function to automatically
have the result cast to the correct type.
@@ -809,6 +811,9 @@ QAbstractOpenGLFunctions *QOpenGLContext::versionFunctions(const QOpenGLVersionP
funcs = d->versionFunctions.value(vp);
}
+ if (funcs && QOpenGLContext::currentContext() == this)
+ funcs->initializeOpenGLFunctions();
+
return funcs;
}