iOS: Add support for offscreen GL surfaces without using hidden windows
There's no need to create a hidden window to get a surface on iOS, as the platform supports FBOs. Note that defaultFramebufferObject() returns 0 in the case of offscreen surfaces, which is technically not a valid FBO on iOS due to the indirect rendering, but binding and rendering to the zero-FBO seems to be no-ops, so clients may safely call eg glBindFramebuffer(GL_FRAMEBUFFER, ctx->defaultFramebufferObject()) to restore the default FBO after drawing to its own FBO. Change-Id: I2e67f5d69c0698562052f5ac1df0bbfaa3337148 Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com> Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
This commit is contained in:
parent
c0701f3789
commit
fb3577039c
@ -113,6 +113,11 @@ bool QIOSContext::makeCurrent(QPlatformSurface *surface)
|
||||
Q_ASSERT(surface && surface->surface()->surfaceType() == QSurface::OpenGLSurface);
|
||||
|
||||
[EAGLContext setCurrentContext:m_eaglContext];
|
||||
|
||||
// For offscreen surfaces we don't prepare a default FBO
|
||||
if (surface->surface()->surfaceClass() == QSurface::Offscreen)
|
||||
return true;
|
||||
|
||||
FramebufferObject &framebufferObject = backingFramebufferObjectFor(surface);
|
||||
|
||||
// We bind the default FBO even if it's incomplete, so that clients who
|
||||
@ -131,6 +136,10 @@ void QIOSContext::doneCurrent()
|
||||
void QIOSContext::swapBuffers(QPlatformSurface *surface)
|
||||
{
|
||||
Q_ASSERT(surface && surface->surface()->surfaceType() == QSurface::OpenGLSurface);
|
||||
|
||||
if (surface->surface()->surfaceClass() == QSurface::Offscreen)
|
||||
return; // Nothing to do
|
||||
|
||||
Q_ASSERT(surface->surface()->surfaceClass() == QSurface::Window);
|
||||
QIOSWindow *window = static_cast<QIOSWindow *>(surface);
|
||||
Q_ASSERT(m_framebufferObjects.contains(window));
|
||||
@ -213,6 +222,13 @@ QIOSContext::FramebufferObject &QIOSContext::backingFramebufferObjectFor(QPlatfo
|
||||
|
||||
GLuint QIOSContext::defaultFramebufferObject(QPlatformSurface *surface) const
|
||||
{
|
||||
if (surface->surface()->surfaceClass() == QSurface::Offscreen) {
|
||||
// Binding and rendering to the zero-FBO on iOS seems to be
|
||||
// no-ops, so we can safely return 0 here, even if it's not
|
||||
// really a valid FBO on iOS.
|
||||
return 0;
|
||||
}
|
||||
|
||||
return backingFramebufferObjectFor(surface).handle;
|
||||
}
|
||||
|
||||
|
@ -64,6 +64,7 @@ public:
|
||||
QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const;
|
||||
|
||||
QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const;
|
||||
QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const Q_DECL_OVERRIDE;
|
||||
|
||||
QPlatformFontDatabase *fontDatabase() const;
|
||||
QPlatformClipboard *clipboard() const;
|
||||
|
@ -51,6 +51,8 @@
|
||||
#include "qiostheme.h"
|
||||
#include "qiosservices.h"
|
||||
|
||||
#include <qpa/qplatformoffscreensurface.h>
|
||||
|
||||
#include <QtPlatformSupport/private/qcoretextfontdatabase_p.h>
|
||||
#include <QtPlatformSupport/private/qmacmime_p.h>
|
||||
#include <QDir>
|
||||
@ -144,6 +146,11 @@ QPlatformOpenGLContext *QIOSIntegration::createPlatformOpenGLContext(QOpenGLCont
|
||||
return new QIOSContext(context);
|
||||
}
|
||||
|
||||
QPlatformOffscreenSurface *QIOSIntegration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const
|
||||
{
|
||||
return new QPlatformOffscreenSurface(surface);
|
||||
}
|
||||
|
||||
QAbstractEventDispatcher *QIOSIntegration::createEventDispatcher() const
|
||||
{
|
||||
if (isQtApplication())
|
||||
|
Loading…
Reference in New Issue
Block a user