From b4128d0f7dfe6fd5752c4ec3ecb03775ffda5949 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 26 Mar 2014 16:54:36 +0100 Subject: Use an offscreen surface in VAO cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid failing the makeCurrent() on iOS that does not currently support using a window with different contexts. Change-Id: I2e10ad7e382161625a78518d02ad94edaff591ca Reviewed-by: Sean Harmer Reviewed-by: Tor Arne Vestbø --- src/gui/opengl/qopenglvertexarrayobject.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/gui/opengl/qopenglvertexarrayobject.cpp b/src/gui/opengl/qopenglvertexarrayobject.cpp index 22ca35a8c3..9dfd5b2a6f 100644 --- a/src/gui/opengl/qopenglvertexarrayobject.cpp +++ b/src/gui/opengl/qopenglvertexarrayobject.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -359,9 +360,17 @@ QOpenGLVertexArrayObject::~QOpenGLVertexArrayObject() Q_D(QOpenGLVertexArrayObject); QOpenGLContext *oldContext = 0; + QScopedPointer offscreenSurface; if (d->context && ctx && d->context != ctx) { oldContext = ctx; - if (d->context->makeCurrent(oldContext->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"); -- cgit v1.2.3