From 52781f2a7d4c63990c2484b267614450f80c5591 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 24 Mar 2015 16:57:23 +0100 Subject: Make versioned OpenGL functions working with the subclass pattern QOpenGLFunctions allows both deriving from it and getting an instance via QOpenGLContext::functions(). Unsurprisingly a large number of users attempt to use the versioned function wrappers in the same way. Unfortunately this approach was not that well supported. Besides some potential base class exporting issues the real blocker for QOpenGLWidget - or any versionfunction subclass whose associated context changes during its lifetime - is that the functions instances could only be initialized once. Unlike instances retrieved via QOpenGLContext::versionFunctions(), instances created "manually" were not deinitialized upon the destruction of the associated context because context did not know about them. A pattern like initializeOpenGLFunctions(); delete context; create new context and make it current initializeOpenGLFunctions(); is working fine in QOpenGLFunctions-derived classes but not with the versioned ones. To overcome this, start registering such instances to the context too. QOpenGLContext::destroy() can then reset the internal state so a subsequent initializeOpenGLFunctions() will reinitialize properly instead of bailing out mistakenly thinking that everything is ready to use. Task-number: QTBUG-45199 Change-Id: Ia1420bcccb33c51508698b7a1b036c7544a66e74 Reviewed-by: Sean Harmer --- src/gui/kernel/qopenglcontext.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'src/gui/kernel/qopenglcontext.cpp') diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp index 90c54c4039..7fc9cceb60 100644 --- a/src/gui/kernel/qopenglcontext.cpp +++ b/src/gui/kernel/qopenglcontext.cpp @@ -636,12 +636,21 @@ void QOpenGLContext::destroy() d->platformGLContext = 0; delete d->functions; d->functions = 0; + + foreach (QAbstractOpenGLFunctions *func, d->externalVersionFunctions) { + QAbstractOpenGLFunctionsPrivate *func_d = QAbstractOpenGLFunctionsPrivate::get(func); + func_d->owningContext = 0; + func_d->initialized = false; + } + d->externalVersionFunctions.clear(); qDeleteAll(d->versionFunctions); d->versionFunctions.clear(); qDeleteAll(d->versionFunctionsBackend); d->versionFunctionsBackend.clear(); + delete d->textureFunctions; d->textureFunctions = 0; + d->nativeHandle = QVariant(); } @@ -719,7 +728,7 @@ QOpenGLFunctions *QOpenGLContext::functions() const 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() + initialization by calling QAbstractOpenGLFunctions::initializeOpenGLFunctions() afterwards. Usually one would use the template version of this function to automatically @@ -1257,6 +1266,24 @@ void QOpenGLContext::removeFunctionsBackend(const QOpenGLVersionStatus &v) d->versionFunctionsBackend.remove(v); } +/*! + \internal + */ +void QOpenGLContext::insertExternalFunctions(QAbstractOpenGLFunctions *f) +{ + Q_D(QOpenGLContext); + d->externalVersionFunctions.insert(f); +} + +/*! + \internal + */ +void QOpenGLContext::removeExternalFunctions(QAbstractOpenGLFunctions *f) +{ + Q_D(QOpenGLContext); + d->externalVersionFunctions.remove(f); +} + /*! \internal */ -- cgit v1.2.3