diff options
author | Tor Arne Vestbø <tor.arne.vestbo@digia.com> | 2014-03-26 15:58:15 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-27 17:51:21 +0100 |
commit | 2654fdb346ef740ecc2591edc7af860c08455548 (patch) | |
tree | 3008b2cd3dc8d6f8973167e1688c70dc50382d66 /src/plugins/platforms/ios/qioscontext.mm | |
parent | 98e90f700a22bf7f139e4993cc96fa91f1183131 (diff) |
iOS: Check FBO status and return failure from QIOSContext::makeCurrent()
The Khronos documentation for glCheckFramebufferStatus recommends calling
the function to see if the framebuffer is complete prior to rendering.
We now give more info to clients that call makeCurrent(), by storing the
state of the default FBO and returning that, instead of always returning
true and leaving the clients vulnerable to calling OpenGL functions on a
non-complete FBO.
Change-Id: Ia99c21f811ac799b350f07e73b2ae4b173d71120
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
Diffstat (limited to 'src/plugins/platforms/ios/qioscontext.mm')
-rw-r--r-- | src/plugins/platforms/ios/qioscontext.mm | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/src/plugins/platforms/ios/qioscontext.mm b/src/plugins/platforms/ios/qioscontext.mm index 7310d2904f..a35b4f164c 100644 --- a/src/plugins/platforms/ios/qioscontext.mm +++ b/src/plugins/platforms/ios/qioscontext.mm @@ -94,14 +94,33 @@ QSurfaceFormat QIOSContext::format() const return m_format; } +#define QT_IOS_GL_STATUS_CASE(val) case val: return QLatin1Literal(#val) + +static QString fboStatusString(GLenum status) +{ + switch (status) { + QT_IOS_GL_STATUS_CASE(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT); + QT_IOS_GL_STATUS_CASE(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS); + QT_IOS_GL_STATUS_CASE(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT); + QT_IOS_GL_STATUS_CASE(GL_FRAMEBUFFER_UNSUPPORTED); + default: + return QString(QStringLiteral("unknown status: %x")).arg(status); + } +} + bool QIOSContext::makeCurrent(QPlatformSurface *surface) { Q_ASSERT(surface && surface->surface()->surfaceType() == QSurface::OpenGLSurface); [EAGLContext setCurrentContext:m_eaglContext]; - glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebufferObject(surface)); + FramebufferObject &framebufferObject = backingFramebufferObjectFor(surface); + + // We bind the default FBO even if it's incomplete, so that clients who + // call glCheckFramebufferStatus as a result of this function returning + // false will get a matching error code. + glBindFramebuffer(GL_FRAMEBUFFER, framebufferObject.handle); - return true; + return framebufferObject.isComplete; } void QIOSContext::doneCurrent() @@ -121,7 +140,7 @@ void QIOSContext::swapBuffers(QPlatformSurface *surface) [m_eaglContext presentRenderbuffer:GL_RENDERBUFFER]; } -GLuint QIOSContext::defaultFramebufferObject(QPlatformSurface *surface) const +QIOSContext::FramebufferObject &QIOSContext::backingFramebufferObjectFor(QPlatformSurface *surface) const { Q_ASSERT(surface && surface->surface()->surfaceClass() == QSurface::Window); QIOSWindow *window = static_cast<QIOSWindow *>(surface); @@ -181,11 +200,20 @@ GLuint QIOSContext::defaultFramebufferObject(QPlatformSurface *surface) const framebufferObject.renderbufferWidth, framebufferObject.renderbufferHeight); } - if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) - NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER)); + framebufferObject.isComplete = glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE; + + if (!framebufferObject.isComplete) { + qWarning("QIOSContext failed to make complete framebuffer object (%s)", + qPrintable(fboStatusString(glCheckFramebufferStatus(GL_FRAMEBUFFER)))); + } } - return framebufferObject.handle; + return framebufferObject; +} + +GLuint QIOSContext::defaultFramebufferObject(QPlatformSurface *surface) const +{ + return backingFramebufferObjectFor(surface).handle; } void QIOSContext::windowDestroyed(QObject *object) |