From e432787ad0b760b887bfbcde1a397acc9adfb6c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 27 Mar 2014 16:41:56 +0100 Subject: [PATCH] iOS: Share default-FBO for windows between contexts in a share-group The current implementation of QOpenGLContext sharing assumes that the contexts form a tree and that leaf-nodes are destroyed before their parents. We build on this assumption and keep track of the default FBOs for windows in the root context of the tree. This allows two shared contexts to both makeCurrent() on the same window surface without resulting in two FBOs being set up (which doesn't work on iOS due to the CEAGLLayer already being tied to another render-buffer). Change-Id: Ib9f8c597effe488480fe99e10846be22c257f490 Reviewed-by: Laszlo Agocs --- src/plugins/platforms/ios/qioscontext.mm | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/plugins/platforms/ios/qioscontext.mm b/src/plugins/platforms/ios/qioscontext.mm index 1ea040308f..ddee52196a 100644 --- a/src/plugins/platforms/ios/qioscontext.mm +++ b/src/plugins/platforms/ios/qioscontext.mm @@ -140,17 +140,22 @@ void QIOSContext::swapBuffers(QPlatformSurface *surface) if (surface->surface()->surfaceClass() == QSurface::Offscreen) return; // Nothing to do - Q_ASSERT(surface->surface()->surfaceClass() == QSurface::Window); - QIOSWindow *window = static_cast(surface); - Q_ASSERT(m_framebufferObjects.contains(window)); + FramebufferObject &framebufferObject = backingFramebufferObjectFor(surface); [EAGLContext setCurrentContext:m_eaglContext]; - glBindRenderbuffer(GL_RENDERBUFFER, m_framebufferObjects[window].colorRenderbuffer); + glBindRenderbuffer(GL_RENDERBUFFER, framebufferObject.colorRenderbuffer); [m_eaglContext presentRenderbuffer:GL_RENDERBUFFER]; } QIOSContext::FramebufferObject &QIOSContext::backingFramebufferObjectFor(QPlatformSurface *surface) const { + // We keep track of default-FBOs in the root context of a share-group. This assumes + // that the contexts form a tree, where leaf nodes are always destroyed before their + // parents. If that assumption (based on the current implementation) doesn't hold we + // should probably use QOpenGLMultiGroupSharedResource to track the shared default-FBOs. + if (m_sharedContext) + return m_sharedContext->backingFramebufferObjectFor(surface); + Q_ASSERT(surface && surface->surface()->surfaceClass() == QSurface::Window); QIOSWindow *window = static_cast(surface);