diff options
author | Paul Olav Tvete <paul.tvete@digia.com> | 2014-03-06 14:25:08 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-07 12:20:24 +0100 |
commit | 9fc17c08e5635cf112c6194e6c24af2a9c7caf00 (patch) | |
tree | 94dd2471df3d878e0237e2733ae0a726163f19c9 | |
parent | 6e5caf0431f63a8b67b4d787ba02d8684dbaa856 (diff) |
QQuickWidget: make sure to use the proper GL format
We cannot be sure that the toplevel widget has the correct GL format,
and we do not want to force depth and stencil buffers on surfaces that
do not need them. Therefore, we have to create an offscreen surface for
the FBO.
Change-Id: I7dfc3a6f84bf79125f3ab811a204972e95e245a3
Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
-rw-r--r-- | src/quickwidgets/qquickwidget.cpp | 31 | ||||
-rw-r--r-- | src/quickwidgets/qquickwidget_p.h | 2 |
2 files changed, 14 insertions, 19 deletions
diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index 147762c66f..cc8c616d26 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -54,6 +54,7 @@ #include <QtQml/qqmlengine.h> #include <private/qqmlengine_p.h> #include <QtCore/qbasictimer.h> +#include <QtGui/QOffscreenSurface> QT_BEGIN_NAMESPACE @@ -96,12 +97,16 @@ QQuickWidgetPrivate::QQuickWidgetPrivate() offscreenWindow = new QQuickWindow(renderControl); offscreenWindow->setTitle(QString::fromLatin1("Offscreen")); // Do not call create() on offscreenWindow. + offscreenSurface = new QOffscreenSurface; + offscreenSurface->setFormat(offscreenWindow->requestedFormat()); + offscreenSurface->create(); } QQuickWidgetPrivate::~QQuickWidgetPrivate() { if (QQmlDebugService::isDebuggingEnabled()) QQmlInspectorService::instance()->removeView(q_func()); + delete offscreenSurface; delete offscreenWindow; delete renderControl; delete fbo; @@ -156,8 +161,8 @@ void QQuickWidgetPrivate::renderSceneGraph() return; } - Q_ASSERT(q->window()->windowHandle()->handle()); - context->makeCurrent(q->window()->windowHandle()); + Q_ASSERT(offscreenSurface); + context->makeCurrent(offscreenSurface); renderControl->polishItems(); renderControl->sync(); renderControl->render(); @@ -495,21 +500,11 @@ QSize QQuickWidgetPrivate::rootObjectSize() const void QQuickWidgetPrivate::createContext() { - Q_Q(QQuickWidget); if (context) return; context = new QOpenGLContext; - - QSurfaceFormat format = q->window()->windowHandle()->requestedFormat(); - QSGRenderContext *renderContext = QQuickWindowPrivate::get(offscreenWindow)->context; - // Depth, stencil, etc. must be set like a QQuickWindow would do. - QSurfaceFormat sgFormat = renderContext->sceneGraphContext()->defaultSurfaceFormat(); - format.setDepthBufferSize(qMax(format.depthBufferSize(), sgFormat.depthBufferSize())); - format.setStencilBufferSize(qMax(format.stencilBufferSize(), sgFormat.stencilBufferSize())); - format.setAlphaBufferSize(qMax(format.alphaBufferSize(), sgFormat.alphaBufferSize())); - format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); - context->setFormat(format); + context->setFormat(offscreenWindow->requestedFormat()); if (QSGContext::sharedOpenGLContext()) context->setShareContext(QSGContext::sharedOpenGLContext()); // ??? is this correct @@ -517,10 +512,10 @@ void QQuickWidgetPrivate::createContext() qWarning("QQuickWidget: failed to create OpenGL context"); delete context; context = 0; + return; } - Q_ASSERT(q->window()->windowHandle()->handle()); - if (context->makeCurrent(q->window()->windowHandle())) + if (context->makeCurrent(offscreenSurface)) renderControl->initialize(context); else qWarning("QQuickWidget: failed to make window surface current"); @@ -544,8 +539,7 @@ void QQuickWidget::createFramebufferObject() context->create(); } - Q_ASSERT(window()->windowHandle()->handle()); - context->makeCurrent(window()->windowHandle()); + context->makeCurrent(d->offscreenSurface); d->fbo = new QOpenGLFramebufferObject(size()); d->fbo->setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); d->offscreenWindow->setRenderTarget(d->fbo); @@ -715,8 +709,7 @@ void QQuickWidget::resizeEvent(QResizeEvent *e) return; } - Q_ASSERT(window()->windowHandle()->handle()); - context->makeCurrent(window()->windowHandle()); + context->makeCurrent(d->offscreenSurface); d->renderControl->render(); glFlush(); context->doneCurrent(); diff --git a/src/quickwidgets/qquickwidget_p.h b/src/quickwidgets/qquickwidget_p.h index 01f7c3ac91..c75e5f08ad 100644 --- a/src/quickwidgets/qquickwidget_p.h +++ b/src/quickwidgets/qquickwidget_p.h @@ -63,6 +63,7 @@ class QQuickItem; class QQmlComponent; class QQuickRenderControl; class QOpenGLContext; +class QOffscreenSurface; class QQuickWidgetPrivate : public QWidgetPrivate, @@ -99,6 +100,7 @@ public: QQmlComponent *component; QBasicTimer resizetimer; QQuickWindow *offscreenWindow; + QOffscreenSurface *offscreenSurface; QQuickRenderControl *renderControl; QOpenGLFramebufferObject *fbo; QOpenGLContext *context; |