diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2017-04-03 16:31:29 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2017-04-03 22:22:03 +0000 |
commit | 6265a4fbe2db88c779148906d584e9f29671b905 (patch) | |
tree | 1d2e2ddb1af14969692de4ba8511eb2208c4f928 | |
parent | d4008780481454d7a2be8815062e841b1043147b (diff) |
Fix Scene3D initialization in QQuickWidget
Scene3D can now be used inside a QQuickWidget. There are some
remaining problems, most notably an assert when exiting, but at
least the scene shows up now.
Task-number: QTBUG-52132
Change-Id: Ifc05d859711f5f42342e111c1d7cbea7ba373552
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r-- | src/quick3d/imports/scene3d/scene3ditem.cpp | 22 | ||||
-rw-r--r-- | src/quick3d/imports/scene3d/scene3ditem_p.h | 3 |
2 files changed, 23 insertions, 2 deletions
diff --git a/src/quick3d/imports/scene3d/scene3ditem.cpp b/src/quick3d/imports/scene3d/scene3ditem.cpp index a156b9ef3..6c285e133 100644 --- a/src/quick3d/imports/scene3d/scene3ditem.cpp +++ b/src/quick3d/imports/scene3d/scene3ditem.cpp @@ -47,7 +47,11 @@ #include <Qt3DRender/QRenderAspect> #include <Qt3DRender/qcamera.h> #include <Qt3DRender/qrendersurfaceselector.h> + +#include <QtGui/qguiapplication.h> +#include <QtGui/qoffscreensurface.h> #include <QtQuick/qquickwindow.h> +#include <QtQuick/qquickrendercontrol.h> #include <Qt3DRender/private/qrendersurfaceselector_p.h> #include <scene3dcleaner_p.h> @@ -201,8 +205,22 @@ void Scene3DItem::setWindowSurface(QObject *rootObject) // Set the item's window surface if it appears // the surface wasn't set on the surfaceSelector - if (surfaceSelector && !surfaceSelector->surface()) - surfaceSelector->setSurface(this->window()); + if (surfaceSelector && !surfaceSelector->surface()) { + // We may not have a real, exposed QQuickWindow when the Quick rendering + // is redirected via QQuickRenderControl (f.ex. QQuickWidget). + if (QWindow *rw = QQuickRenderControl::renderWindowFor(this->window())) { + // rw is the top-level window that is backed by a native window. Do + // not use that though since we must not clash with e.g. the widget + // backingstore compositor in the gui thread. + m_dummySurface = new QOffscreenSurface; + m_dummySurface->setParent(qGuiApp); // parent to something suitably long-living + m_dummySurface->setFormat(rw->format()); + m_dummySurface->create(); + surfaceSelector->setSurface(m_dummySurface); + } else { + surfaceSelector->setSurface(this->window()); + } + } } void Scene3DItem::setItemArea(const QSize &area) diff --git a/src/quick3d/imports/scene3d/scene3ditem_p.h b/src/quick3d/imports/scene3d/scene3ditem_p.h index f3d452d3d..eb14645c3 100644 --- a/src/quick3d/imports/scene3d/scene3ditem_p.h +++ b/src/quick3d/imports/scene3d/scene3ditem_p.h @@ -56,6 +56,8 @@ QT_BEGIN_NAMESPACE +class QOffscreenSurface; + namespace Qt3DCore { class QAspectEngine; class QEntity; @@ -131,6 +133,7 @@ private: QPointer<Qt3DRender::QCamera> m_camera; CameraAspectRatioMode m_cameraAspectRatioMode; + QOffscreenSurface *m_dummySurface; }; } // Qt3DRender |