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.cpp66
1 files changed, 34 insertions, 32 deletions
diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp
index 638eb1d12f..ab71434c13 100644
--- a/src/gui/kernel/qopenglcontext.cpp
+++ b/src/gui/kernel/qopenglcontext.cpp
@@ -56,8 +56,6 @@
#include <private/qopenglextensions_p.h>
#include <private/qopenglversionfunctionsfactory_p.h>
-#include <private/qopengltexturehelper_p.h>
-
#include <QDebug>
#ifndef QT_OPENGL_ES_2
@@ -223,7 +221,7 @@ class QGuiGLThreadContext
{
public:
QGuiGLThreadContext()
- : context(0)
+ : context(nullptr)
{
}
~QGuiGLThreadContext() {
@@ -234,7 +232,7 @@ public:
};
Q_GLOBAL_STATIC(QThreadStorage<QGuiGLThreadContext *>, qwindow_context_storage);
-static QOpenGLContext *global_share_context = 0;
+static QOpenGLContext *global_share_context = nullptr;
#ifndef QT_NO_DEBUG
QHash<QOpenGLContext *, bool> QOpenGLContextPrivate::makeCurrentTracker;
@@ -347,7 +345,7 @@ QOpenGLContext *QOpenGLContextPrivate::setCurrentContext(QOpenGLContext *context
if (!threadContext) {
if (!QThread::currentThread()) {
qWarning("No QTLS available. currentContext won't work");
- return 0;
+ return nullptr;
}
threadContext = new QGuiGLThreadContext;
qwindow_context_storage()->setLocalData(threadContext);
@@ -372,10 +370,10 @@ int QOpenGLContextPrivate::maxTextureSize()
GLint size;
GLint next = 64;
- funcs->glTexImage2D(proxy, 0, GL_RGBA, next, next, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
+ funcs->glTexImage2D(proxy, 0, GL_RGBA, next, next, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
- QOpenGLFunctions_1_0 *gl1funcs = 0;
- QOpenGLFunctions_3_2_Core *gl3funcs = 0;
+ QOpenGLFunctions_1_0 *gl1funcs = nullptr;
+ QOpenGLFunctions_3_2_Core *gl3funcs = nullptr;
if (q->format().profile() == QSurfaceFormat::CoreProfile)
gl3funcs = q->versionFunctions<QOpenGLFunctions_3_2_Core>();
@@ -398,7 +396,7 @@ int QOpenGLContextPrivate::maxTextureSize()
if (next > max_texture_size)
break;
- funcs->glTexImage2D(proxy, 0, GL_RGBA, next, next, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
+ funcs->glTexImage2D(proxy, 0, GL_RGBA, next, next, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
if (gl1funcs)
gl1funcs->glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &next);
else
@@ -455,7 +453,7 @@ QPlatformOpenGLContext *QOpenGLContext::shareHandle() const
Q_D(const QOpenGLContext);
if (d->shareContext)
return d->shareContext->handle();
- return 0;
+ return nullptr;
}
/*!
@@ -517,8 +515,8 @@ void QOpenGLContextPrivate::_q_screenDestroyed(QObject *object)
{
Q_Q(QOpenGLContext);
if (object == static_cast<QObject *>(screen)) {
- screen = 0;
- q->setScreen(0);
+ screen = nullptr;
+ q->setScreen(nullptr);
}
}
@@ -615,7 +613,7 @@ bool QOpenGLContext::create()
d->platformGLContext->setContext(this);
d->platformGLContext->initialize();
if (!d->platformGLContext->isSharing())
- d->shareContext = 0;
+ d->shareContext = nullptr;
d->shareGroup = d->shareContext ? d->shareContext->shareGroup() : new QOpenGLContextGroup;
d->shareGroup->d_func()->addContext(this);
return isValid();
@@ -649,23 +647,26 @@ void QOpenGLContext::destroy()
doneCurrent();
if (d->shareGroup)
d->shareGroup->d_func()->removeContext(this);
- d->shareGroup = 0;
+ d->shareGroup = nullptr;
delete d->platformGLContext;
- d->platformGLContext = 0;
+ d->platformGLContext = nullptr;
delete d->functions;
- d->functions = 0;
+ d->functions = nullptr;
for (QAbstractOpenGLFunctions *func : qAsConst(d->externalVersionFunctions)) {
QAbstractOpenGLFunctionsPrivate *func_d = QAbstractOpenGLFunctionsPrivate::get(func);
- func_d->owningContext = 0;
+ func_d->owningContext = nullptr;
func_d->initialized = false;
}
d->externalVersionFunctions.clear();
qDeleteAll(d->versionFunctions);
d->versionFunctions.clear();
- delete d->textureFunctions;
- d->textureFunctions = 0;
+ if (d->textureFunctionsDestroyCallback) {
+ d->textureFunctionsDestroyCallback();
+ d->textureFunctionsDestroyCallback = nullptr;
+ }
+ d->textureFunctions = nullptr;
d->nativeHandle = QVariant();
}
@@ -823,7 +824,7 @@ QAbstractOpenGLFunctions *QOpenGLContext::versionFunctions(const QOpenGLVersionP
#ifndef QT_OPENGL_ES_2
if (isOpenGLES()) {
qWarning("versionFunctions: Not supported on OpenGL ES");
- return 0;
+ return nullptr;
}
#endif // QT_OPENGL_ES_2
@@ -838,16 +839,16 @@ QAbstractOpenGLFunctions *QOpenGLContext::versionFunctions(const QOpenGLVersionP
// Check that context is compatible with requested version
const QPair<int, int> v = qMakePair(f.majorVersion(), f.minorVersion());
if (v < vp.version())
- return 0;
+ return nullptr;
// If this context only offers core profile functions then we can't create
// function objects for legacy or compatibility profile requests
if (((vp.hasProfiles() && vp.profile() != QSurfaceFormat::CoreProfile) || vp.isLegacyVersion())
&& f.profile() == QSurfaceFormat::CoreProfile)
- return 0;
+ return nullptr;
// Create object if suitable one not cached
- QAbstractOpenGLFunctions* funcs = 0;
+ QAbstractOpenGLFunctions* funcs = nullptr;
auto it = d->versionFunctions.constFind(vp);
if (it == d->versionFunctions.constEnd()) {
funcs = QOpenGLVersionFunctionsFactory::create(vp);
@@ -1022,7 +1023,7 @@ bool QOpenGLContext::makeCurrent(QSurface *surface)
|| qstrncmp(rendererString, "Adreno 6xx", 8) == 0 // Same as above but without the '(TM)'
|| qstrcmp(rendererString, "GC800 core") == 0
|| qstrcmp(rendererString, "GC1000 core") == 0
- || strstr(rendererString, "GC2000") != 0
+ || strstr(rendererString, "GC2000") != nullptr
|| qstrcmp(rendererString, "Immersion.16") == 0;
}
needsWorkaroundSet = true;
@@ -1053,9 +1054,9 @@ void QOpenGLContext::doneCurrent()
d->shareGroup->d_func()->deletePendingResources(this);
d->platformGLContext->doneCurrent();
- QOpenGLContextPrivate::setCurrentContext(0);
+ QOpenGLContextPrivate::setCurrentContext(nullptr);
- d->surface = 0;
+ d->surface = nullptr;
}
/*!
@@ -1224,8 +1225,8 @@ void QOpenGLContext::deleteQGLContext()
Q_D(QOpenGLContext);
if (d->qGLContextDeleteFunction && d->qGLContextHandle) {
d->qGLContextDeleteFunction(d->qGLContextHandle);
- d->qGLContextDeleteFunction = 0;
- d->qGLContextHandle = 0;
+ d->qGLContextDeleteFunction = nullptr;
+ d->qGLContextHandle = nullptr;
}
}
@@ -1252,7 +1253,7 @@ void *QOpenGLContext::openGLModuleHandle()
Q_ASSERT(ni);
return ni->nativeResourceForIntegration(QByteArrayLiteral("glhandle"));
#else
- return 0;
+ return nullptr;
#endif
}
@@ -1388,10 +1389,11 @@ QOpenGLTextureHelper* QOpenGLContext::textureFunctions() const
/*!
\internal
*/
-void QOpenGLContext::setTextureFunctions(QOpenGLTextureHelper* textureFuncs)
+void QOpenGLContext::setTextureFunctions(QOpenGLTextureHelper* textureFuncs, std::function<void()> destroyCallback)
{
Q_D(QOpenGLContext);
d->textureFunctions = textureFuncs;
+ d->textureFunctionsDestroyCallback = destroyCallback;
}
/*!
@@ -1438,7 +1440,7 @@ QList<QOpenGLContext *> QOpenGLContextGroup::shares() const
QOpenGLContextGroup *QOpenGLContextGroup::currentContextGroup()
{
QOpenGLContext *current = QOpenGLContext::currentContext();
- return current ? current->shareGroup() : 0;
+ return current ? current->shareGroup() : nullptr;
}
void QOpenGLContextGroupPrivate::addContext(QOpenGLContext *ctx)
@@ -1491,7 +1493,7 @@ void QOpenGLContextGroupPrivate::cleanup()
while (it != end) {
(*it)->invalidateResource();
- (*it)->m_group = 0;
+ (*it)->m_group = nullptr;
++it;
}