summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2016-01-19 13:50:54 +0000
committerSean Harmer <sean.harmer@kdab.com>2016-01-19 14:35:38 +0000
commit704dca53b4575622127dc5351c4f88cc97e497b5 (patch)
treec709c31931cde739da8e0bb2eee42251390ab475 /src
parentb9aded78adcbeac6579d4dbbb5591558f7bc705f (diff)
Automatically set the render surface on a Scene3D item
Change-Id: Iebf8f8d681461a050a240777c7d6b602ba85ef06 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/quick3d/imports/scene3d/scene3ditem.cpp39
-rw-r--r--src/quick3d/imports/scene3d/scene3ditem_p.h1
2 files changed, 39 insertions, 1 deletions
diff --git a/src/quick3d/imports/scene3d/scene3ditem.cpp b/src/quick3d/imports/scene3d/scene3ditem.cpp
index 4166b1ddf..8f356bda4 100644
--- a/src/quick3d/imports/scene3d/scene3ditem.cpp
+++ b/src/quick3d/imports/scene3d/scene3ditem.cpp
@@ -41,9 +41,14 @@
#include "scene3dsgnode_p.h"
#include <Qt3DCore/QAspectEngine>
+#include <Qt3DCore/qentity.h>
#include <Qt3DRender/QRenderAspect>
+#include <Qt3DRender/qframegraph.h>
+#include <Qt3DRender/qrendersurfaceselector.h>
#include <Qt3DInput/QInputAspect>
+#include <QtQuick/qquickwindow.h>
+
QT_BEGIN_NAMESPACE
namespace Qt3DRender {
@@ -133,8 +138,40 @@ void Scene3DItem::setEntity(Qt3DCore::QEntity *entity)
void Scene3DItem::applyRootEntityChange()
{
- if (m_aspectEngine->rootEntity() != m_entity)
+ if (m_aspectEngine->rootEntity() != m_entity) {
m_aspectEngine->setRootEntity(m_entity);
+
+ // Set the render surface
+ if (m_entity)
+ setWindowSurface(m_entity);
+ }
+}
+
+void Scene3DItem::setWindowSurface(QObject *rootObject)
+{
+ // Find surface selector in framegraph and set ourselves up as the
+ // render surface there
+ Qt3DRender::QFrameGraph *frameGraphComponent
+ = rootObject->findChild<Qt3DRender::QFrameGraph *>();
+ if (!frameGraphComponent) {
+ qWarning() << "No frame graph component found";
+ return;
+ }
+
+ Qt3DCore::QNode *frameGraphRoot = frameGraphComponent->activeFrameGraph();
+ if (!frameGraphRoot) {
+ qWarning() << "No active frame graph found";
+ return;
+ }
+
+ Qt3DRender::QRenderSurfaceSelector *surfaceSelector
+ = frameGraphRoot->findChild<Qt3DRender::QRenderSurfaceSelector *>();
+ if (!surfaceSelector) {
+ qWarning() << "No render surface selector found in frame graph";
+ return;
+ }
+
+ surfaceSelector->setWindow(this->window());
}
/*!
diff --git a/src/quick3d/imports/scene3d/scene3ditem_p.h b/src/quick3d/imports/scene3d/scene3ditem_p.h
index edb0b7b00..bb078d6b8 100644
--- a/src/quick3d/imports/scene3d/scene3ditem_p.h
+++ b/src/quick3d/imports/scene3d/scene3ditem_p.h
@@ -94,6 +94,7 @@ private Q_SLOTS:
private:
QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *nodeData) Q_DECL_OVERRIDE;
+ void setWindowSurface(QObject *rootObject);
QStringList m_aspects;
Qt3DCore::QEntity *m_entity;