diff options
author | Paul Lemire <paul.lemire.ecortex@kdab.com> | 2014-10-31 11:35:45 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2014-11-14 17:44:32 +0100 |
commit | 80540edee66a1822146c35c22a02cfaa1edd34e8 (patch) | |
tree | b1853d44cf183414f87cd160058d11be561ff476 | |
parent | 1ce287c11d139ae32c0b593c482c8e826473f7a0 (diff) |
Qt3D::Window simplified
The Qt3D::Window doesn't contain the QAspectEngine anymore. This will allow
to to pass any kind of surface to the QAspectEngine.
We could still have a wrapper like QQuickView around the QQmlAspectEngine if
needed but if it weren't for the camera controller that we need to keep a
little longer, a simple QWindow could be used in every example.
All examples were updated.
Change-Id: I4921df0df6f1066cd409ea886faf41d7e8834ef6
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
24 files changed, 205 insertions, 240 deletions
diff --git a/examples/assimp/main.cpp b/examples/assimp/main.cpp index b2b18e508..4a73f8821 100644 --- a/examples/assimp/main.cpp +++ b/examples/assimp/main.cpp @@ -54,8 +54,15 @@ int main(int argc, char* argv[]) initializeAssetResources("../exampleresources/example-assets.qrb"); Qt3D::Quick::QuickWindow view; - view.registerAspect(new Qt3D::QRenderAspect()); - view.setSource(QUrl("qrc:/main.qml")); + Qt3D::Quick::QQmlAspectEngine engine; + + engine.aspectEngine()->registerAspect(new Qt3D::QRenderAspect()); + QVariantMap data; + data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); + data.insert(QStringLiteral("window"), QVariant::fromValue(&view)); + engine.aspectEngine()->setData(data); + engine.aspectEngine()->initialize(); + engine.setSource(QUrl("qrc:/main.qml")); view.show(); return app.exec(); diff --git a/examples/bigmodel-qml/main.cpp b/examples/bigmodel-qml/main.cpp index 74b70db1d..e7baa1bf2 100644 --- a/examples/bigmodel-qml/main.cpp +++ b/examples/bigmodel-qml/main.cpp @@ -62,13 +62,16 @@ int main(int argc, char* argv[]) } Qt3D::Quick::QuickWindow view; - view.registerAspect(new Qt3D::QRenderAspect()); - // There should be some synchronising mechanism to make sure - // the source is set after alll aspects have been completely initialized - // Otherwise we might encounter cases where an Aspect's QML elements have - // not yet been registered - view.engine()->rootContext()->setContextProperty("_meshFileNames", meshFileNames); - view.setSource(QUrl("qrc:/main.qml")); + Qt3D::Quick::QQmlAspectEngine engine; + + engine.aspectEngine()->registerAspect(new Qt3D::QRenderAspect()); + engine.qmlEngine()->rootContext()->setContextProperty("_meshFileNames", meshFileNames); + QVariantMap data; + data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); + data.insert(QStringLiteral("window"), QVariant::fromValue(&view)); + engine.aspectEngine()->setData(data); + engine.aspectEngine()->initialize(); + engine.setSource(QUrl("qrc:/main.qml")); view.show(); return app.exec(); diff --git a/examples/bigscene-cpp/main.cpp b/examples/bigscene-cpp/main.cpp index add87a242..e22e4c511 100644 --- a/examples/bigscene-cpp/main.cpp +++ b/examples/bigscene-cpp/main.cpp @@ -48,6 +48,7 @@ #include <Qt3DCore/QTranslateTransform> #include <Qt3DCore/QRotateTransform> #include <Qt3DCore/QScaleTransform> +#include <Qt3DCore/qaspectengine.h> #include <Qt3DRenderer/QViewport> #include <Qt3DRenderer/QFrameGraph> #include <Qt3DRenderer/QClearBuffer> @@ -64,8 +65,13 @@ int main(int ac, char **av) QGuiApplication app(ac, av); Window view; - view.registerAspect(new QRenderAspect()); - + Qt3D::QAspectEngine engine; + engine.registerAspect(new Qt3D::QRenderAspect()); + engine.initialize(); + QVariantMap data; + data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); + data.insert(QStringLiteral("window"), QVariant::fromValue(&view)); + engine.setData(data); QEntity *root = new QEntity(); // Camera @@ -136,7 +142,7 @@ int main(int ac, char **av) e->setParent(root); } - view.setRootEntity(root); + engine.setRootEntity(root); view.show(); return app.exec(); } diff --git a/examples/cpp_example/main.cpp b/examples/cpp_example/main.cpp index 22c1218b9..e36a93513 100644 --- a/examples/cpp_example/main.cpp +++ b/examples/cpp_example/main.cpp @@ -47,6 +47,7 @@ #include <Qt3DCore/qcamera.h> #include <Qt3DCore/qentity.h> #include <Qt3DCore/qcameralens.h> +#include <Qt3DCore/qaspectengine.h> #include <Qt3DRenderer/qtorusmesh.h> #include <Qt3DRenderer/qmesh.h> @@ -78,7 +79,13 @@ int main(int ac, char **av) initializeAssetResources("../exampleresources/example-assets.qrb"); Qt3D::Window view; - view.registerAspect(new Qt3D::QRenderAspect()); + Qt3D::QAspectEngine engine; + engine.registerAspect(new Qt3D::QRenderAspect()); + engine.initialize(); + QVariantMap data; + data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); + data.insert(QStringLiteral("window"), QVariant::fromValue(&view)); + engine.setData(data); // Root entity Qt3D::QEntity *rootEntity = new Qt3D::QEntity(); @@ -148,7 +155,8 @@ int main(int ac, char **av) rootEntity->addComponent(frameGraph); // Set root object of the scene - view.setRootEntity(rootEntity); + engine.setRootEntity(rootEntity); + // Show window view.show(); return app.exec(); diff --git a/examples/cylinder-cpp/main.cpp b/examples/cylinder-cpp/main.cpp index 20800f389..39469c2af 100644 --- a/examples/cylinder-cpp/main.cpp +++ b/examples/cylinder-cpp/main.cpp @@ -58,6 +58,7 @@ #include <Qt3DCore/qrotatetransform.h> #include <Qt3DCore/qlookattransform.h> #include <Qt3DCore/qtransform.h> +#include <Qt3DCore/qaspectengine.h> #include <Qt3DRenderer/qcameraselector.h> #include <Qt3DRenderer/qrenderpassfilter.h> @@ -72,7 +73,13 @@ int main(int argc, char **argv) QGuiApplication app(argc, argv); Qt3D::Window view; - view.registerAspect(new Qt3D::QRenderAspect()); + Qt3D::QAspectEngine engine; + engine.registerAspect(new Qt3D::QRenderAspect()); + engine.initialize(); + QVariantMap data; + data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); + data.insert(QStringLiteral("window"), QVariant::fromValue(&view)); + engine.setData(data); // Root entity Qt3D::QEntity *rootEntity = new Qt3D::QEntity(); @@ -132,7 +139,8 @@ int main(int argc, char **argv) rootEntity->addComponent(frameGraph); // Set root object of the scene - view.setRootEntity(rootEntity); + engine.setRootEntity(rootEntity); + // Show window view.show(); return app.exec(); diff --git a/examples/cylinder-qml/main.cpp b/examples/cylinder-qml/main.cpp index 9e80a8936..bee96cb2f 100644 --- a/examples/cylinder-qml/main.cpp +++ b/examples/cylinder-qml/main.cpp @@ -51,12 +51,16 @@ int main(int argc, char* argv[]) QGuiApplication app(argc, argv); Qt3D::Quick::QuickWindow view; - view.registerAspect(new Qt3D::QRenderAspect()); - // There should be some synchronising mechanism to make sure - // the source is set after alll aspects have been completely initialized - // Otherwise we might encounter cases where an Aspect's QML elements have - // not yet been registered - view.setSource(QUrl("qrc:/main.qml")); + Qt3D::Quick::QQmlAspectEngine engine; + + engine.aspectEngine()->registerAspect(new Qt3D::QRenderAspect()); + + QVariantMap data; + data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); + data.insert(QStringLiteral("window"), QVariant::fromValue(&view)); + engine.aspectEngine()->setData(data); + engine.aspectEngine()->initialize(); + engine.setSource(QUrl("qrc:/main.qml")); view.show(); return app.exec(); diff --git a/examples/deferred-renderer-cpp/main.cpp b/examples/deferred-renderer-cpp/main.cpp index 0d0c065b9..bc446ae8f 100644 --- a/examples/deferred-renderer-cpp/main.cpp +++ b/examples/deferred-renderer-cpp/main.cpp @@ -55,6 +55,7 @@ #include <Qt3DCore/QRotateTransform> #include <Qt3DCore/QTranslateTransform> #include <Qt3DRenderer/QPointLight> +#include <Qt3DCore/qaspectengine.h> #include <QGuiApplication> @@ -68,7 +69,13 @@ int main(int ac, char **av) QGuiApplication app(ac, av); Qt3D::Window view; - view.registerAspect(new Qt3D::QRenderAspect()); + Qt3D::QAspectEngine engine; + engine.registerAspect(new Qt3D::QRenderAspect()); + engine.initialize(); + QVariantMap data; + data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); + data.insert(QStringLiteral("window"), QVariant::fromValue(&view)); + engine.setData(data); // Root entity Qt3D::QEntity *rootEntity = new Qt3D::QEntity(); @@ -185,7 +192,8 @@ int main(int ac, char **av) screenQuad->addComponent(planeMesh); // Set root object of the scene - view.setRootEntity(rootEntity); + engine.setRootEntity(rootEntity); + // Show window view.show(); return app.exec(); diff --git a/examples/deferred-renderer-qml/main.cpp b/examples/deferred-renderer-qml/main.cpp index 41fe13fab..0408188e9 100644 --- a/examples/deferred-renderer-qml/main.cpp +++ b/examples/deferred-renderer-qml/main.cpp @@ -55,8 +55,15 @@ int main(int argc, char* argv[]) initializeAssetResources("../exampleresources/example-assets.qrb"); Qt3D::Quick::QuickWindow view; - view.registerAspect(new Qt3D::QRenderAspect()); - view.setSource(QUrl("qrc:/main.qml")); + Qt3D::Quick::QQmlAspectEngine engine; + + engine.aspectEngine()->registerAspect(new Qt3D::QRenderAspect()); + engine.aspectEngine()->initialize(); + QVariantMap data; + data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); + data.insert(QStringLiteral("window"), QVariant::fromValue(&view)); + engine.aspectEngine()->setData(data); + engine.setSource(QUrl("qrc:/main.qml")); view.show(); return app.exec(); diff --git a/examples/gltf/main.cpp b/examples/gltf/main.cpp index 2a464daaa..c80add25e 100644 --- a/examples/gltf/main.cpp +++ b/examples/gltf/main.cpp @@ -53,8 +53,17 @@ int main(int argc, char* argv[]) initializeAssetResources("../exampleresources/example-assets.qrb"); Qt3D::Quick::QuickWindow view; - view.registerAspect(new Qt3D::QRenderAspect()); - view.setSource(QUrl("qrc:/main.qml")); + Qt3D::Quick::QQmlAspectEngine engine; + + engine.aspectEngine()->registerAspect(new Qt3D::QRenderAspect()); + + QVariantMap data; + data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); + data.insert(QStringLiteral("window"), QVariant::fromValue(&view)); + engine.aspectEngine()->setData(data); + engine.aspectEngine()->initialize(); + + engine.setSource(QUrl("qrc:/main.qml")); view.show(); return app.exec(); diff --git a/examples/materials/main.cpp b/examples/materials/main.cpp index ed1b0afd0..068b475f0 100644 --- a/examples/materials/main.cpp +++ b/examples/materials/main.cpp @@ -54,16 +54,18 @@ int main(int argc, char* argv[]) initializeAssetResources("../exampleresources/example-assets.qrb"); Qt3D::Quick::QuickWindow view; - view.registerAspect(new Qt3D::QRenderAspect); + Qt3D::Quick::QQmlAspectEngine engine; - // Expose the window as a context property so we can set the aspect ratio - view.engine()->rootContext()->setContextProperty("_window", &view); + engine.aspectEngine()->registerAspect(new Qt3D::QRenderAspect()); + engine.aspectEngine()->initialize(); + QVariantMap data; + data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); + data.insert(QStringLiteral("window"), QVariant::fromValue(&view)); - // There should be some synchronising mechanism to make sure - // the source is set after all aspects have been completely initialized - // Otherwise we might encounter cases where an Aspect's QML elements have - // not yet been registered - view.setSource(QUrl("qrc:/main.qml")); + engine.aspectEngine()->setData(data); + // Expose the window as a context property so we can set the aspect ratio + engine.qmlEngine()->rootContext()->setContextProperty("_window", &view); + engine.setSource(QUrl("qrc:/main.qml")); view.show(); return app.exec(); diff --git a/examples/multiviewport/main.cpp b/examples/multiviewport/main.cpp index 3da7c22b4..0d003cdb8 100644 --- a/examples/multiviewport/main.cpp +++ b/examples/multiviewport/main.cpp @@ -49,12 +49,18 @@ int main(int ac, char **av) { QGuiApplication app(ac, av); - Qt3D::Quick::QuickWindow win; + Qt3D::Quick::QuickWindow view; + Qt3D::Quick::QQmlAspectEngine engine; initializeAssetResources("../exampleresources/example-assets.qrb"); - win.registerAspect(new Qt3D::QRenderAspect); - win.setSource(QUrl("qrc:/main.qml")); - win.show(); + engine.aspectEngine()->registerAspect(new Qt3D::QRenderAspect); + QVariantMap data; + data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); + data.insert(QStringLiteral("window"), QVariant::fromValue(&view)); + engine.aspectEngine()->setData(data); + engine.aspectEngine()->initialize(); + engine.setSource(QUrl("qrc:/main.qml")); + view.show(); return app.exec(); } diff --git a/examples/playground-qml/main.cpp b/examples/playground-qml/main.cpp index b81c83642..4c3f46a11 100644 --- a/examples/playground-qml/main.cpp +++ b/examples/playground-qml/main.cpp @@ -54,12 +54,15 @@ int main(int argc, char* argv[]) initializeAssetResources("../exampleresources/example-assets.qrb"); Qt3D::Quick::QuickWindow view; - view.registerAspect(new Qt3D::QRenderAspect()); - // There should be some synchronising mechanism to make sure - // the source is set after alll aspects have been completely initialized - // Otherwise we might encounter cases where an Aspect's QML elements have - // not yet been registered - view.setSource(QUrl("qrc:/main.qml")); + Qt3D::Quick::QQmlAspectEngine engine; + + engine.aspectEngine()->registerAspect(new Qt3D::QRenderAspect()); + QVariantMap data; + data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); + data.insert(QStringLiteral("window"), QVariant::fromValue(&view)); + engine.aspectEngine()->setData(data); + engine.aspectEngine()->initialize(); + engine.setSource(QUrl("qrc:/main.qml")); view.show(); return app.exec(); diff --git a/examples/rollerball/main.cpp b/examples/rollerball/main.cpp index c991411ad..f8efd86cf 100644 --- a/examples/rollerball/main.cpp +++ b/examples/rollerball/main.cpp @@ -55,17 +55,24 @@ int main(int argc, char* argv[]) initializeAssetResources("../exampleresources/example-assets.qrb"); Qt3D::Quick::QuickWindow view; - view.registerAspect(new Qt3D::QRenderAspect()); - view.registerAspect(new Qt3D::BulletPhysicsAspect()); + Qt3D::Quick::QQmlAspectEngine engine; + + engine.aspectEngine()->registerAspect(new Qt3D::QRenderAspect()); + engine.aspectEngine()->registerAspect(new Qt3D::BulletPhysicsAspect()); + QVariantMap data; + data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); + data.insert(QStringLiteral("window"), QVariant::fromValue(&view)); + engine.aspectEngine()->setData(data); + engine.aspectEngine()->initialize(); // Expose the window as a context property so we can set the aspect ratio - view.engine()->rootContext()->setContextProperty("_window", &view); + engine.qmlEngine()->rootContext()->setContextProperty("_window", &view); // There should be some synchronising mechanism to make sure // the source is set after all aspects have been completely initialized // Otherwise we might encounter cases where an Aspect's QML elements have // not yet been registered - view.setSource(QUrl("qrc:/main.qml")); + engine.setSource(QUrl("qrc:/main.qml")); view.show(); return app.exec(); diff --git a/examples/shadow-map-qml/main.cpp b/examples/shadow-map-qml/main.cpp index 175ee0be9..2e70ba22b 100644 --- a/examples/shadow-map-qml/main.cpp +++ b/examples/shadow-map-qml/main.cpp @@ -55,13 +55,19 @@ int main(int argc, char* argv[]) initializeAssetResources("../exampleresources/example-assets.qrb"); Qt3D::Quick::QuickWindow view; - view.registerAspect(new Qt3D::QRenderAspect()); + Qt3D::Quick::QQmlAspectEngine engine; - view.show(); view.resize(1600, 800); + engine.aspectEngine()->registerAspect(new Qt3D::QRenderAspect()); + engine.aspectEngine()->initialize(); + QVariantMap data; + data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); + data.insert(QStringLiteral("window"), QVariant::fromValue(&view)); + engine.aspectEngine()->setData(data); + engine.qmlEngine()->rootContext()->setContextProperty("_window", &view); + engine.setSource(QUrl("qrc:/main.qml")); - view.engine()->rootContext()->setContextProperty("_window", &view); - view.setSource(QUrl("qrc:/main.qml")); + view.show(); return app.exec(); } diff --git a/examples/simple-cpp/main.cpp b/examples/simple-cpp/main.cpp index 3bd32f720..940f62d23 100644 --- a/examples/simple-cpp/main.cpp +++ b/examples/simple-cpp/main.cpp @@ -50,6 +50,7 @@ #include <Qt3DCore/QScaleTransform> #include <Qt3DCore/QRotateTransform> #include <Qt3DCore/QTranslateTransform> +#include <Qt3DCore/qaspectengine.h> #include <Qt3DRenderer/QRenderAspect> #include <Qt3DRenderer/QFrameGraph> @@ -70,8 +71,13 @@ int main(int argc, char* argv[]) QGuiApplication app(argc, argv); Qt3D::Window view; - view.registerAspect(new Qt3D::QRenderAspect()); - + Qt3D::QAspectEngine engine; + engine.registerAspect(new Qt3D::QRenderAspect()); + engine.initialize(); + QVariantMap data; + data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); + data.insert(QStringLiteral("window"), QVariant::fromValue(&view)); + engine.setData(data); // Root entity Qt3D::QEntity *rootEntity = new Qt3D::QEntity(); @@ -165,7 +171,7 @@ int main(int argc, char* argv[]) rootEntity->addComponent(frameGraph); - view.setRootEntity(rootEntity); + engine.setRootEntity(rootEntity); view.show(); return app.exec(); diff --git a/examples/simple-qml/main.cpp b/examples/simple-qml/main.cpp index 6083519c1..a9d5d101d 100644 --- a/examples/simple-qml/main.cpp +++ b/examples/simple-qml/main.cpp @@ -49,9 +49,16 @@ int main(int argc, char* argv[]) QGuiApplication app(argc, argv); Qt3D::Quick::QuickWindow view; - view.registerAspect(new Qt3D::QRenderAspect()); + Qt3D::Quick::QQmlAspectEngine engine; + + engine.aspectEngine()->registerAspect(new Qt3D::QRenderAspect()); + engine.aspectEngine()->initialize(); + QVariantMap data; + data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); + data.insert(QStringLiteral("window"), QVariant::fromValue(&view)); + engine.aspectEngine()->setData(data); + engine.setSource(QUrl("qrc:/main.qml")); - view.setSource(QUrl("qrc:/main.qml")); view.show(); return app.exec(); diff --git a/examples/tessellation-modes/main.cpp b/examples/tessellation-modes/main.cpp index 8eb2950cb..93c006e02 100644 --- a/examples/tessellation-modes/main.cpp +++ b/examples/tessellation-modes/main.cpp @@ -56,19 +56,26 @@ int main(int argc, char* argv[]) initializeAssetResources("../exampleresources/example-assets.qrb"); Qt3D::Quick::QuickWindow view; - view.registerAspect(new Qt3D::QRenderAspect()); + Qt3D::Quick::QQmlAspectEngine engine; + engine.aspectEngine()->registerAspect(new Qt3D::QRenderAspect()); + + QVariantMap data; + data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); + data.insert(QStringLiteral("window"), QVariant::fromValue(&view)); + engine.aspectEngine()->setData(data); + engine.aspectEngine()->initialize(); // Register our custom types qmlRegisterType<TessellatedQuadMesh>("Qt3D.Examples", 1, 0, "TessellatedQuadMesh"); // Expose the window as a context property so we can set the aspect ratio - view.engine()->rootContext()->setContextProperty("_window", &view); + engine.qmlEngine()->rootContext()->setContextProperty("_window", &view); // There should be some synchronising mechanism to make sure // the source is set after all aspects have been completely initialized // Otherwise we might encounter cases where an Aspect's QML elements have // not yet been registered - view.setSource(QUrl("qrc:/main.qml")); + engine.setSource(QUrl("qrc:/main.qml")); view.show(); return app.exec(); diff --git a/examples/torus-cpp/main.cpp b/examples/torus-cpp/main.cpp index 98b457c78..1944a8433 100644 --- a/examples/torus-cpp/main.cpp +++ b/examples/torus-cpp/main.cpp @@ -59,6 +59,7 @@ #include <Qt3DCore/qrotatetransform.h> #include <Qt3DCore/qlookattransform.h> #include <Qt3DCore/qtransform.h> +#include <Qt3DCore/qaspectengine.h> #include <Qt3DRenderer/qcameraselector.h> #include <Qt3DRenderer/qrenderpassfilter.h> @@ -73,7 +74,13 @@ int main(int argc, char **argv) QGuiApplication app(argc, argv); Qt3D::Window view; - view.registerAspect(new Qt3D::QRenderAspect()); + Qt3D::QAspectEngine engine; + engine.registerAspect(new Qt3D::QRenderAspect()); + engine.initialize(); + QVariantMap data; + data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); + data.insert(QStringLiteral("window"), QVariant::fromValue(&view)); + engine.setData(data); // Root entity Qt3D::QEntity *rootEntity = new Qt3D::QEntity(); @@ -132,7 +139,8 @@ int main(int argc, char **argv) rootEntity->addComponent(frameGraph); // Set root object of the scene - view.setRootEntity(rootEntity); + engine.setRootEntity(rootEntity); + // Show window view.show(); return app.exec(); diff --git a/examples/torus-qml/main.cpp b/examples/torus-qml/main.cpp index 9e80a8936..30ce9b65e 100644 --- a/examples/torus-qml/main.cpp +++ b/examples/torus-qml/main.cpp @@ -51,12 +51,15 @@ int main(int argc, char* argv[]) QGuiApplication app(argc, argv); Qt3D::Quick::QuickWindow view; - view.registerAspect(new Qt3D::QRenderAspect()); - // There should be some synchronising mechanism to make sure - // the source is set after alll aspects have been completely initialized - // Otherwise we might encounter cases where an Aspect's QML elements have - // not yet been registered - view.setSource(QUrl("qrc:/main.qml")); + Qt3D::Quick::QQmlAspectEngine engine; + + engine.aspectEngine()->registerAspect(new Qt3D::QRenderAspect()); + QVariantMap data; + data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); + data.insert(QStringLiteral("window"), QVariant::fromValue(&view)); + engine.aspectEngine()->setData(data); + engine.aspectEngine()->initialize(); + engine.setSource(QUrl("qrc:/main.qml")); view.show(); return app.exec(); diff --git a/examples/wireframe/main.cpp b/examples/wireframe/main.cpp index 435ab09dd..71d792ac9 100644 --- a/examples/wireframe/main.cpp +++ b/examples/wireframe/main.cpp @@ -54,16 +54,19 @@ int main(int argc, char* argv[]) initializeAssetResources("../exampleresources/example-assets.qrb"); Qt3D::Quick::QuickWindow view; - view.registerAspect(new Qt3D::QRenderAspect()); + Qt3D::Quick::QQmlAspectEngine engine; + + engine.aspectEngine()->registerAspect(new Qt3D::QRenderAspect()); // Expose the window as a context property so we can set the aspect ratio - view.engine()->rootContext()->setContextProperty("_window", &view); + engine.qmlEngine()->rootContext()->setContextProperty("_window", &view); + QVariantMap data; + data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); + data.insert(QStringLiteral("window"), QVariant::fromValue(&view)); + engine.aspectEngine()->setData(data); + engine.aspectEngine()->initialize(); + engine.setSource(QUrl("qrc:/main.qml")); - // There should be some synchronising mechanism to make sure - // the source is set after all aspects have been completely initialized - // Otherwise we might encounter cases where an Aspect's QML elements have - // not yet been registered - view.setSource(QUrl("qrc:/main.qml")); view.show(); return app.exec(); diff --git a/src/core/window.cpp b/src/core/window.cpp index 68f6cceae..5baaf3a49 100644 --- a/src/core/window.cpp +++ b/src/core/window.cpp @@ -59,9 +59,8 @@ namespace Qt3D { Window::Window(QScreen *screen) : QWindow(screen) - , m_aspectEngine(new QAspectEngine(this)) - , m_camera(NULL) - , m_controller(NULL) + , m_camera(Q_NULLPTR) + , m_controller(new CameraController()) { setSurfaceType(QSurface::OpenGLSurface); @@ -76,12 +75,6 @@ Window::Window(QScreen *screen) setFormat(format); create(); - m_aspectEngine->initialize(); - QVariantMap data; - data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(this))); - data.insert(QStringLiteral("window"), QVariant::fromValue(this)); - m_aspectEngine->setData(data); - m_controller = new CameraController(); m_updateTimer = new QTimer(this); @@ -91,16 +84,6 @@ Window::Window(QScreen *screen) Window::~Window() { - m_aspectEngine->shutdown(); - delete m_aspectEngine; -} - -/*! - * Registers an Aspect module to the AspectEngine; - */ -void Window::registerAspect(QAbstractAspect *aspect) -{ - m_aspectEngine->registerAspect(aspect); } void Window::onUpdate() @@ -108,32 +91,19 @@ void Window::onUpdate() m_controller->update(1.0 / 60.0); } -void Window::setRootEntity(QEntity *root) -{ - m_aspectEngine->setRootEntity(root); - - // Hook up controller input to camera - // TODO: Do this more generically as we may want keyboard ot control an Entity etc - // What happens if there is no camera - // What happens if at some point the camera is added but not directly when the scene is created ? - // eg scene file provided and camera tree node created after parsing ? - // What happens if there are multiple cameras in the scene ? - if (m_camera) { - qCDebug(Nodes) << "found a camera in the scene"; - m_controller->setCamera(m_camera); - m_updateTimer->start(); - } -} - void Window::resizeEvent( QResizeEvent* e ) { Q_UNUSED( e ); - } void Window::setCamera(QCamera *camera) { m_camera = camera; + if (m_camera) { + qCDebug(Nodes) << "found a camera in the scene"; + m_controller->setCamera(m_camera); + m_updateTimer->start(); + } } void Window::keyPressEvent( QKeyEvent* e ) diff --git a/src/core/window.h b/src/core/window.h index 9bc12b6f3..a7edfee01 100644 --- a/src/core/window.h +++ b/src/core/window.h @@ -66,10 +66,7 @@ public: explicit Window(QScreen *screen = 0); ~Window(); - void setRootEntity(QEntity *root); - - void registerAspect(QAbstractAspect *aspect); - virtual void setCamera(QCamera *camera); + void setCamera(QCamera *camera); protected: virtual void keyPressEvent(QKeyEvent *e); @@ -85,7 +82,6 @@ private Q_SLOTS: void onUpdate(); protected: - QAspectEngine *m_aspectEngine; QCamera* m_camera; // temporary, borrowed from training material diff --git a/src/quick3d/quick3d/quickwindow.cpp b/src/quick3d/quick3d/quickwindow.cpp index d7c55f111..574dea235 100644 --- a/src/quick3d/quick3d/quickwindow.cpp +++ b/src/quick3d/quick3d/quickwindow.cpp @@ -40,15 +40,8 @@ ****************************************************************************/ #include "quickwindow.h" -#include <Qt3DCore/qaspectengine.h> -#include <Qt3DCore/qentity.h> -#include <Qt3DCore/cameracontroller.h> - -#include <QQmlComponent> -#include <QQmlContext> -#include <QDebug> -#include <QTimer> +#include <Qt3DCore/cameracontroller.h> QT_BEGIN_NAMESPACE @@ -60,7 +53,6 @@ QuickWindow *QuickWindow::m_instance = Q_NULLPTR; QuickWindow::QuickWindow(QScreen *screen) : Window(screen) - , m_engine(new QQmlEngine) { // HACKED TO BE ABLE TO ASSIGN CAMERA TO CONTROLLER @@ -68,103 +60,11 @@ QuickWindow::QuickWindow(QScreen *screen) QuickWindow::m_instance = this; } -QuickWindow::~QuickWindow() -{ -} - -QuickWindow::Status QuickWindow::status() const -{ - if (!m_engine) - return Error; - - if (!m_component) - return Null; - - return Status(m_component->status()); -} - -void QuickWindow::setSource(const QUrl& source) -{ - if (!m_engine) { - qWarning() << "Window: invalid qml engine."; - return; - } - - // If the engine already has a scene object tree, tidy up first - if (m_aspectEngine->rootEntity()) - m_aspectEngine->setRootEntity(Q_NULLPTR); - - if (m_component) - m_component = QSharedPointer<QQmlComponent>(); - - if (!source.isEmpty()) { - m_component = QSharedPointer<QQmlComponent>(new QQmlComponent(m_engine.data(), source, this)); - if (!m_component->isLoading()) { - continueExecute(); - } else { - QObject::connect(m_component.data(), SIGNAL(statusChanged(QQmlComponent::Status)), - this, SLOT(continueExecute())); - } - } -} - -void QuickWindow::setCamera(QCamera *camera) -{ - Window::setCamera(camera); - if (m_camera) { - m_controller->setCamera(m_camera); - m_updateTimer->start(); - } -} - QuickWindow *QuickWindow::getInstance() { return QuickWindow::m_instance; } -QQmlEngine *QuickWindow::engine() const -{ - return m_engine.data(); -} - -void QuickWindow::continueExecute() -{ - qDebug() << Q_FUNC_INFO; - - QObject::disconnect(m_component.data(), SIGNAL(statusChanged(QQmlComponent::Status)), - this, SLOT(continueExecute())); - - if (m_component->isError()) { - QList<QQmlError> errorList = m_component->errors(); - Q_FOREACH ( const QQmlError& error, errorList ) { - QMessageLogger(error.url().toString().toLatin1().constData(), error.line(), 0).warning() - << error; - } - emit statusChanged(status()); - return; - } - - QObject* obj = m_component->create(); - - if (m_component->isError()) { - QList<QQmlError> errorList = m_component->errors(); - Q_FOREACH ( const QQmlError& error, errorList ) { - QMessageLogger(error.url().toString().toLatin1().constData(), error.line(), 0).warning() - << error; - } - emit statusChanged(status()); - return; - } - - QEntity *rootEntity = qobject_cast<QEntity *>(obj); - if (rootEntity) - setRootEntity(rootEntity); - else - delete obj; - - emit statusChanged(status()); -} - } // Quick } // Qt3D diff --git a/src/quick3d/quick3d/quickwindow.h b/src/quick3d/quick3d/quickwindow.h index 926a5e521..e666316f0 100644 --- a/src/quick3d/quick3d/quickwindow.h +++ b/src/quick3d/quick3d/quickwindow.h @@ -46,14 +46,13 @@ #include <QQmlEngine> #include <Qt3DQuick/qt3dquick_global.h> +#include <Qt3DQuick/qqmlaspectengine.h> #include <Qt3DCore/window.h> QT_BEGIN_NAMESPACE namespace Qt3D { -class QAspectEngine; - namespace Quick { class Quick3DConfiguration; @@ -62,29 +61,11 @@ class QT3DQUICKSHARED_EXPORT QuickWindow : public Qt3D::Window { Q_OBJECT public: - enum Status { Null, Ready, Loading, Error }; - explicit QuickWindow(QScreen *screen = 0); - ~QuickWindow(); - Status status() const; - void setSource(const QUrl& url); - - void setCamera(QCamera *camera); static QuickWindow *getInstance(); - QQmlEngine *engine() const; - -Q_SIGNALS: - void statusChanged(Status); - -private Q_SLOTS: - void continueExecute(); - private: - QScopedPointer<QQmlEngine> m_engine; - QSharedPointer<QQmlComponent> m_component; - static QuickWindow *m_instance; }; |