diff options
author | Liang Qi <liang.qi@qt.io> | 2017-01-26 00:37:14 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2017-01-26 00:37:14 +0000 |
commit | 398a7e736cb42ac42f0887989585b1121b7e6e62 (patch) | |
tree | 916854b706b9b057fa1483f76dd48998a8aa28a0 /src/gui/opengl | |
parent | 4d3a35f63788fa5ff7a11a5bb7bd6176bd2ac70e (diff) | |
parent | 318b58562ae89453fb98e8145cd0440e14ba60b0 (diff) |
Merge "Merge remote-tracking branch 'origin/5.8' into dev" into refs/staging/dev
Diffstat (limited to 'src/gui/opengl')
-rw-r--r-- | src/gui/opengl/qopengl.cpp | 22 | ||||
-rw-r--r-- | src/gui/opengl/qopenglfunctions.cpp | 5 | ||||
-rw-r--r-- | src/gui/opengl/qopenglversionfunctions.cpp | 18 | ||||
-rw-r--r-- | src/gui/opengl/qopenglvertexarrayobject.cpp | 94 |
4 files changed, 72 insertions, 67 deletions
diff --git a/src/gui/opengl/qopengl.cpp b/src/gui/opengl/qopengl.cpp index e61473cb7b..7e663d48bb 100644 --- a/src/gui/opengl/qopengl.cpp +++ b/src/gui/opengl/qopengl.cpp @@ -65,6 +65,10 @@ typedef const GLubyte * (QOPENGLF_APIENTRYP qt_glGetStringi)(GLenum, GLuint); QOpenGLExtensionMatcher::QOpenGLExtensionMatcher() { QOpenGLContext *ctx = QOpenGLContext::currentContext(); + if (!ctx) { + qWarning("QOpenGLExtensionMatcher::QOpenGLExtensionMatcher: No context"); + return; + } QOpenGLFunctions *funcs = ctx->functions(); const char *extensionStr = 0; @@ -80,19 +84,17 @@ QOpenGLExtensionMatcher::QOpenGLExtensionMatcher() // clear error state while (funcs->glGetError()) {} - if (ctx) { - qt_glGetStringi glGetStringi = (qt_glGetStringi)ctx->getProcAddress("glGetStringi"); + qt_glGetStringi glGetStringi = (qt_glGetStringi)ctx->getProcAddress("glGetStringi"); - if (!glGetStringi) - return; + if (!glGetStringi) + return; - GLint numExtensions = 0; - funcs->glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions); + GLint numExtensions = 0; + funcs->glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions); - for (int i = 0; i < numExtensions; ++i) { - const char *str = reinterpret_cast<const char *>(glGetStringi(GL_EXTENSIONS, i)); - m_extensions.insert(str); - } + for (int i = 0; i < numExtensions; ++i) { + const char *str = reinterpret_cast<const char *>(glGetStringi(GL_EXTENSIONS, i)); + m_extensions.insert(str); } #endif // QT_OPENGL_3 } diff --git a/src/gui/opengl/qopenglfunctions.cpp b/src/gui/opengl/qopenglfunctions.cpp index e4e7c6d1b5..ad8b19a2bc 100644 --- a/src/gui/opengl/qopenglfunctions.cpp +++ b/src/gui/opengl/qopenglfunctions.cpp @@ -2196,9 +2196,10 @@ QOpenGLFunctionsPrivate::QOpenGLFunctionsPrivate(QOpenGLContext *c) #ifndef QT_OPENGL_ES_2 // setup fallbacks in case some methods couldn't get resolved - if (!f.ClearDepthf) + bool es = QOpenGLContext::currentContext()->isOpenGLES(); + if (!f.ClearDepthf || !es) f.ClearDepthf = qopenglfSpecialClearDepthf; - if (!f.DepthRangef) + if (!f.DepthRangef || !es) f.DepthRangef = qopenglfSpecialDepthRangef; if (!f.GetShaderPrecisionFormat) f.GetShaderPrecisionFormat = qopenglfSpecialGetShaderPrecisionFormat; diff --git a/src/gui/opengl/qopenglversionfunctions.cpp b/src/gui/opengl/qopenglversionfunctions.cpp index 54df2e5734..a3d3bb6bd1 100644 --- a/src/gui/opengl/qopenglversionfunctions.cpp +++ b/src/gui/opengl/qopenglversionfunctions.cpp @@ -74,15 +74,21 @@ QOpenGLVersionFunctionsStorage::QOpenGLVersionFunctionsStorage() QOpenGLVersionFunctionsStorage::~QOpenGLVersionFunctionsStorage() { +#ifndef QT_OPENGL_ES if (backends) { - for (int i = 0; i < QOpenGLVersionFunctionsBackend::OpenGLVersionBackendCount; ++i) { - if (backends[i] && !--backends[i]->refs) { - // deleting the base class is ok, as the derived classes don't have a destructor - delete backends[i]; - } - } + + int i = 0; + +#define DELETE_BACKEND(X) \ + if (backends[i] && !--backends[i]->refs) \ + delete static_cast<QOpenGLFunctions_##X##Backend*>(backends[i]); \ + ++i; + + QT_OPENGL_VERSIONS(DELETE_BACKEND) +#undef DELETE_BACKEND delete[] backends; } +#endif } QOpenGLVersionFunctionsBackend *QOpenGLVersionFunctionsStorage::backend(QOpenGLContext *context, QOpenGLVersionFunctionsBackend::Version v) diff --git a/src/gui/opengl/qopenglvertexarrayobject.cpp b/src/gui/opengl/qopenglvertexarrayobject.cpp index babe52aa83..0262538250 100644 --- a/src/gui/opengl/qopenglvertexarrayobject.cpp +++ b/src/gui/opengl/qopenglvertexarrayobject.cpp @@ -197,33 +197,59 @@ void QOpenGLVertexArrayObjectPrivate::destroy() { Q_Q(QOpenGLVertexArrayObject); + QOpenGLContext *ctx = QOpenGLContext::currentContext(); + QOpenGLContext *oldContext = 0; + QSurface *oldContextSurface = 0; + QScopedPointer<QOffscreenSurface> offscreenSurface; + if (context && context != ctx) { + oldContext = ctx; + oldContextSurface = ctx ? ctx->surface() : 0; + // Cannot just make the current surface current again with another context. + // The format may be incompatible and some platforms (iOS) may impose + // restrictions on using a window with different contexts. Create an + // offscreen surface (a pbuffer or a hidden window) instead to be safe. + offscreenSurface.reset(new QOffscreenSurface); + offscreenSurface->setFormat(context->format()); + offscreenSurface->create(); + if (context->makeCurrent(offscreenSurface.data())) { + ctx = context; + } else { + qWarning("QOpenGLVertexArrayObject::destroy() failed to make VAO's context current"); + ctx = 0; + } + } + if (context) { QObject::disconnect(context, SIGNAL(aboutToBeDestroyed()), q, SLOT(_q_contextAboutToBeDestroyed())); context = 0; } - if (!vao) - return; - - switch (vaoFuncsType) { + if (vao) { + switch (vaoFuncsType) { #ifndef QT_OPENGL_ES_2 - case Core_3_2: - vaoFuncs.core_3_2->glDeleteVertexArrays(1, &vao); - break; - case Core_3_0: - vaoFuncs.core_3_0->glDeleteVertexArrays(1, &vao); - break; + case Core_3_2: + vaoFuncs.core_3_2->glDeleteVertexArrays(1, &vao); + break; + case Core_3_0: + vaoFuncs.core_3_0->glDeleteVertexArrays(1, &vao); + break; #endif - case ARB: - case APPLE: - case OES: - vaoFuncs.helper->glDeleteVertexArrays(1, &vao); - break; - default: - break; + case ARB: + case APPLE: + case OES: + vaoFuncs.helper->glDeleteVertexArrays(1, &vao); + break; + default: + break; + } + + vao = 0; } - vao = 0; + if (oldContext && oldContextSurface) { + if (!oldContext->makeCurrent(oldContextSurface)) + qWarning("QOpenGLVertexArrayObject::destroy() failed to restore current context"); + } } /*! @@ -354,37 +380,7 @@ QOpenGLVertexArrayObject::QOpenGLVertexArrayObject(QOpenGLVertexArrayObjectPriva */ QOpenGLVertexArrayObject::~QOpenGLVertexArrayObject() { - QOpenGLContext* ctx = QOpenGLContext::currentContext(); - - Q_D(QOpenGLVertexArrayObject); - QOpenGLContext *oldContext = 0; - QSurface *oldContextSurface = 0; - QScopedPointer<QOffscreenSurface> offscreenSurface; - if (d->context && ctx && d->context != ctx) { - oldContext = ctx; - oldContextSurface = ctx->surface(); - // Cannot just make the current surface current again with another context. - // The format may be incompatible and some platforms (iOS) may impose - // restrictions on using a window with different contexts. Create an - // offscreen surface (a pbuffer or a hidden window) instead to be safe. - offscreenSurface.reset(new QOffscreenSurface); - offscreenSurface->setFormat(d->context->format()); - offscreenSurface->create(); - if (d->context->makeCurrent(offscreenSurface.data())) { - ctx = d->context; - } else { - qWarning("QOpenGLVertexArrayObject::~QOpenGLVertexArrayObject() failed to make VAO's context current"); - ctx = 0; - } - } - - if (ctx) - destroy(); - - if (oldContext) { - if (!oldContext->makeCurrent(oldContextSurface)) - qWarning("QOpenGLVertexArrayObject::~QOpenGLVertexArrayObject() failed to restore current context"); - } + destroy(); } /*! |