summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2019-07-05 09:06:35 +0200
committerPaul Lemire <paul.lemire@kdab.com>2019-08-07 12:08:32 +0200
commit6631bf0983250e1a86cb9d27628c44b6e607609b (patch)
tree5ea8ee81d2119df25b0f2a87532f7d7d2dcf03a8 /tests
parentda2c94c13c163922467e6d88e19442fc12aea523 (diff)
Make Scene3D rendering use the Manual Qt3D drive mode
This now makes Scene3D rendering fully synchronous and blocking: - All Qt3D jobs have to be executed before we can render the GL commands This makes the blocking mode that could be activated with SCENE3D_BLOCKING_RENDERMODE the default behavior now and therefore we could remove references to it in the code. This now means that Qt3D and QtQuick will be rendering at the same refresh rate, which in most cases won't be noticeable and will ensure that content from Qt3D scenes matches content from QtQuick scenes. The only downside is if the Qt3D rendering takes longer than the time expected by QtQuick, the whole QtQuick rendering will be slowed down. Previously the QtQuick rendering might have still run at 60fps while the Qt3D rendering at a lower fps. Now the QtQuick fps would be the same as the Qt3D fps. That being said, the old behavior also meant that if Qt3D didn't catch up, the delay between QtQuick and Qt3D would only increase frame after frame. This change allow to simplify the internals by making Scene3D and regular Qt3D use the same code paths internally. Please note that Scene3D relies on QQuickWindow::afterAnimating being called each frame. When using a QQuickRenderControl this means you might have to call it manually as part of your rendering code. Task-number: QTBUG-72385 Change-Id: I887daf6df632e296a892b844e738a67e973fee7f Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/render/commons/testrenderer.h2
-rw-r--r--tests/manual/manual.pro3
-rw-r--r--tests/manual/scene3d-in-sync/main.cpp66
-rw-r--r--tests/manual/scene3d-in-sync/main.qml174
-rw-r--r--tests/manual/scene3d-in-sync/scene3d-in-sync.pro10
-rw-r--r--tests/manual/scene3d-in-sync/scene3d-in-sync.qrc5
6 files changed, 258 insertions, 2 deletions
diff --git a/tests/auto/render/commons/testrenderer.h b/tests/auto/render/commons/testrenderer.h
index 124e30492..c4c1ed92b 100644
--- a/tests/auto/render/commons/testrenderer.h
+++ b/tests/auto/render/commons/testrenderer.h
@@ -52,7 +52,7 @@ public:
void shutdown() override {}
void releaseGraphicsResources() override {}
void render() override {}
- void doRender(bool scene3dBlocking = false) override { Q_UNUSED(scene3dBlocking); }
+ void doRender() override {}
void cleanGraphicsResources() override {}
bool isRunning() const override { return true; }
bool shouldRender() override { return true; }
diff --git a/tests/manual/manual.pro b/tests/manual/manual.pro
index 07f7f9132..644c9ecf9 100644
--- a/tests/manual/manual.pro
+++ b/tests/manual/manual.pro
@@ -65,7 +65,8 @@ SUBDIRS += \
raster-qml \
qtbug-72236 \
qtbug-76766 \
- shader-image-qml
+ shader-image-qml \
+ scene3d-in-sync
qtHaveModule(multimedia): {
SUBDIRS += \
diff --git a/tests/manual/scene3d-in-sync/main.cpp b/tests/manual/scene3d-in-sync/main.cpp
new file mode 100644
index 000000000..8886263f4
--- /dev/null
+++ b/tests/manual/scene3d-in-sync/main.cpp
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QGuiApplication>
+#include <QQuickView>
+
+int main(int argc, char **argv)
+{
+ QGuiApplication app(argc, argv);
+
+ QQuickView view;
+
+ view.resize(500, 500);
+ view.setResizeMode(QQuickView::SizeRootObjectToView);
+ view.setSource(QUrl("qrc:/main.qml"));
+ view.show();
+
+ return app.exec();
+}
diff --git a/tests/manual/scene3d-in-sync/main.qml b/tests/manual/scene3d-in-sync/main.qml
new file mode 100644
index 000000000..31d4096a7
--- /dev/null
+++ b/tests/manual/scene3d-in-sync/main.qml
@@ -0,0 +1,174 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import Qt3D.Core 2.9
+import Qt3D.Render 2.9
+import Qt3D.Input 2.0
+import Qt3D.Extras 2.9
+import QtQuick.Scene3D 2.0
+
+Item {
+ id: root
+ property int _trackingPosition : 0
+ readonly property int squareSize: 100
+
+ Timer {
+ running: true
+ interval: 16
+ repeat: true
+ onTriggered: {
+ _trackingPosition += 1
+ if ((_trackingPosition + squareSize) >= root.width)
+ _trackingPosition = 0
+ }
+ }
+
+ // Scene3D + Qt3D content
+ Scene3D {
+ id: sceneThreeD
+ readonly property double halfWidth: width * 0.5
+
+ focus: true
+ anchors.fill: parent
+ // anchors.margins: -15
+ // Make sure to define the input aspect if we want to handle inputs
+ aspects: ["render", "input"]
+ multisample: false
+
+ Entity { // Root
+ id: sceneRoot
+ components: [
+ RenderSettings {
+ activeFrameGraph: ForwardRenderer {
+ id: forwardRenderer
+ camera: planeCamera
+ clearColor: "yellow"
+ }
+ },
+ // Event Source is the Scene3D in that case
+ InputSettings { }
+ ]
+
+ Camera {
+ id: planeCamera
+ left: -sceneThreeD.halfWidth
+ right: sceneThreeD.halfWidth
+ bottom: -(sceneThreeD.height * 0.5)
+ top: (sceneThreeD.height * 0.5)
+ nearPlane: -100
+ farPlane: 100
+ projectionType: CameraLens.OrthographicProjection
+ position: Qt.vector3d(0, 0, 10)
+ viewCenter: Qt.vector3d(0, 0, 0)
+ }
+
+ Entity {
+ id: trackingCube
+ components: [
+ CuboidMesh {
+ xExtent: 100
+ yExtent: 100
+ zExtent: 2
+ },
+
+ PhongMaterial {
+ diffuse: "orange"
+ ambient: "orange"
+ },
+
+ Transform {
+ translation: Qt.vector3d(-sceneThreeD.halfWidth + squareSize * 0.5 + _trackingPosition, -50, 0)
+ }
+ ]
+ }
+ }
+ }
+
+ // QtQuick Content
+ Rectangle {
+ id: qtQuickTracer
+ x: _trackingPosition
+ onXChanged: {
+ console.info("Tracking position is now:" + _trackingPosition);
+ }
+
+ y: root.height * 0.5 - height
+ width: squareSize; height: squareSize
+ color: "red"
+ //transformOrigin: Item.Center
+ Text {
+ color: "white"
+ text: "Rendered with QtQuick"
+ anchors.fill: parent
+ horizontalAlignment: Text.AlignHCenter
+ verticalAlignment: Text.AlignVCenter
+ wrapMode: Text.WrapAnywhere
+ }
+
+ Text {
+ color: "white"
+ text: "Rendered with Qt3D"
+ width: parent.width
+ height: parent.height
+ anchors.top: parent.bottom
+ horizontalAlignment: Text.AlignHCenter
+ verticalAlignment: Text.AlignVCenter
+ wrapMode: Text.WrapAnywhere
+ }
+
+ Rectangle {
+ width: 1
+ height: 200
+ x: 100
+ color: "black"
+ }
+ }
+}
diff --git a/tests/manual/scene3d-in-sync/scene3d-in-sync.pro b/tests/manual/scene3d-in-sync/scene3d-in-sync.pro
new file mode 100644
index 000000000..521bf2a44
--- /dev/null
+++ b/tests/manual/scene3d-in-sync/scene3d-in-sync.pro
@@ -0,0 +1,10 @@
+QT += qml quick 3dinput
+
+SOURCES += \
+ main.cpp
+
+OTHER_FILES += \
+ main.qml
+
+RESOURCES += \
+ scene3d-in-sync.qrc
diff --git a/tests/manual/scene3d-in-sync/scene3d-in-sync.qrc b/tests/manual/scene3d-in-sync/scene3d-in-sync.qrc
new file mode 100644
index 000000000..5f6483ac3
--- /dev/null
+++ b/tests/manual/scene3d-in-sync/scene3d-in-sync.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/">
+ <file>main.qml</file>
+ </qresource>
+</RCC>