summaryrefslogtreecommitdiffstats
path: root/tests/manual
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2017-06-21 10:01:55 +0200
committerPaul Lemire <paul.lemire@kdab.com>2017-07-17 09:28:56 +0000
commitd82620680292f40af522317bf360e48b4e1c7990 (patch)
tree7fc47be80369f2d7d18b6158925521e6dcf53d2e /tests/manual
parentdc744a54ae6f2a58ff3f0e4b12ec336bcb1bf2d0 (diff)
RenderCapture: read back from the correct framebuffer
Up until now, RenderCapture would read back from the back buffer. In cases where it's used within a RenderTargetSelector, it should instead read back from the ColorAttachment0 of the framebuffer. Later on we might allow to specify the ColorAttachment. Change-Id: I9ca94333184338b2fdb79c5c2668d5929ac8d405 Task-number: QTBUG-61547 Reviewed-by: Kevin Ottens <kevin.ottens@kdab.com>
Diffstat (limited to 'tests/manual')
-rw-r--r--tests/manual/manual.pro3
-rw-r--r--tests/manual/rendercapture-qml-fbo/CaptureScene.qml210
-rw-r--r--tests/manual/rendercapture-qml-fbo/main.cpp75
-rw-r--r--tests/manual/rendercapture-qml-fbo/main.qml136
-rw-r--r--tests/manual/rendercapture-qml-fbo/qml.qrc6
-rw-r--r--tests/manual/rendercapture-qml-fbo/rendercapture-qml-fbo.pro18
-rw-r--r--tests/manual/rendercapture-qml-fbo/rendercaptureprovider.h85
7 files changed, 532 insertions, 1 deletions
diff --git a/tests/manual/manual.pro b/tests/manual/manual.pro
index fa7b016f9..7eedbe05e 100644
--- a/tests/manual/manual.pro
+++ b/tests/manual/manual.pro
@@ -47,7 +47,8 @@ SUBDIRS += \
distancefieldtext \
mesh-morphing \
anim-viewer \
- animation-keyframe-programmatic
+ animation-keyframe-programmatic \
+ rendercapture-qml-fbo
qtHaveModule(widgets): {
SUBDIRS += \
diff --git a/tests/manual/rendercapture-qml-fbo/CaptureScene.qml b/tests/manual/rendercapture-qml-fbo/CaptureScene.qml
new file mode 100644
index 000000000..9c6cb1431
--- /dev/null
+++ b/tests/manual/rendercapture-qml-fbo/CaptureScene.qml
@@ -0,0 +1,210 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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.2 as QQ2
+import Qt3D.Core 2.0
+import Qt3D.Render 2.1
+import Qt3D.Input 2.0
+import Qt3D.Extras 2.0
+
+Entity {
+ id: sceneRoot
+
+ function requestRenderCapture()
+ {
+ return renderCapture.requestCapture()
+ }
+
+ Camera {
+ id: camera
+ projectionType: CameraLens.PerspectiveProjection
+ fieldOfView: 45
+ aspectRatio: 1
+ nearPlane : 0.1
+ farPlane : 1000.0
+ position: Qt.vector3d(100.0, 100.0, 20.0)
+ upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
+ viewCenter: Qt.vector3d(0.0, 0.0, -8.0)
+ }
+
+ Camera {
+ id: camera2
+ projectionType: CameraLens.PerspectiveProjection
+ fieldOfView: 15
+ aspectRatio: 1
+ nearPlane : 0.1
+ farPlane : 1000.0
+ position: Qt.vector3d( 0.0, 0.0, -40.0 )
+ upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
+ viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
+ }
+
+ OrbitCameraController {
+ camera: camera
+ }
+
+ components: [
+ RenderSettings {
+ activeFrameGraph: RenderSurfaceSelector {
+ Viewport {
+ normalizedRect: Qt.rect(0, 0, 1, 1)
+
+ // Clear Back Buffer
+ ClearBuffers {
+ buffers: ClearBuffers.ColorDepthBuffer
+ clearColor: Qt.rgba(0, 0.5, 1, 1)
+ NoDraw { }
+ }
+
+ // Render to back buffer
+ CameraSelector {
+ camera: camera
+ }
+
+ // FBO
+ RenderTargetSelector {
+ target: RenderTarget {
+ attachments: [
+ RenderTargetOutput {
+ attachmentPoint: RenderTargetOutput.Color0
+ texture: Texture2D {
+ id: colorTexture
+ width: 400
+ height: 400
+ format: Texture.RGBAFormat
+ generateMipMaps: false
+ magnificationFilter: Texture.Linear
+ minificationFilter: Texture.Linear
+ wrapMode {
+ x: WrapMode.ClampToEdge
+ y: WrapMode.ClampToEdge
+ }
+ }
+ }
+ ]
+ }
+ // Clear FBO
+ ClearBuffers {
+ buffers: ClearBuffers.ColorDepthBuffer
+ clearColor: Qt.rgba(0, 0.5, 0.5, 1)
+ NoDraw { }
+ }
+
+ // Render into FBO
+ CameraSelector {
+ camera: camera
+ // Render Capture
+ RenderCapture {
+ id: renderCapture
+ }
+ }
+ }
+ }
+ }
+ },
+ // Event Source will be set by the Qt3DQuickWindow
+ InputSettings { }
+ ]
+
+ PhongMaterial {
+ id: material
+ }
+
+ TorusMesh {
+ id: torusMesh
+ radius: 5
+ minorRadius: 1
+ rings: 100
+ slices: 20
+ }
+
+ Transform {
+ id: torusTransform
+ scale3D: Qt.vector3d(1.5, 1, 0.5)
+ rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 45)
+ }
+
+ Entity {
+ id: torusEntity
+ components: [ torusMesh, material, torusTransform ]
+ }
+
+ SphereMesh {
+ id: sphereMesh
+ radius: 3
+ }
+
+ Transform {
+ id: sphereTransform
+ property real userAngle: 0.0
+ matrix: {
+ var m = Qt.matrix4x4();
+ m.rotate(userAngle, Qt.vector3d(0, 1, 0));
+ m.translate(Qt.vector3d(20, 0, 0));
+ return m;
+ }
+ }
+
+ QQ2.NumberAnimation {
+ target: sphereTransform
+ property: "userAngle"
+ duration: 10000
+ from: 0
+ to: 360
+
+ loops: QQ2.Animation.Infinite
+ running: true
+ }
+
+ Entity {
+ id: sphereEntity
+ components: [ sphereMesh, material, sphereTransform ]
+ }
+}
diff --git a/tests/manual/rendercapture-qml-fbo/main.cpp b/tests/manual/rendercapture-qml-fbo/main.cpp
new file mode 100644
index 000000000..5c581c88e
--- /dev/null
+++ b/tests/manual/rendercapture-qml-fbo/main.cpp
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
+** 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 <QQuickItem>
+#include <QQuickView>
+#include <Qt3DQuick/QQmlAspectEngine>
+#include <QGuiApplication>
+#include <QQmlEngine>
+#include <QQmlContext>
+#include "rendercaptureprovider.h"
+
+
+int main(int argc, char* argv[])
+{
+ QGuiApplication app(argc, argv);
+ QQuickView view;
+ RenderCaptureProvider *provider = new RenderCaptureProvider;
+ qmlRegisterType<RenderCaptureProvider>("Extras", 1, 0, "RenderCaptureProvider");
+
+ view.engine()->rootContext()->setContextProperty("_renderCaptureProvider", provider);
+ view.engine()->addImageProvider("rendercapture", provider);
+
+ view.setSource(QUrl("qrc:/main.qml"));
+ view.show();
+
+ return app.exec();
+}
diff --git a/tests/manual/rendercapture-qml-fbo/main.qml b/tests/manual/rendercapture-qml-fbo/main.qml
new file mode 100644
index 000000000..49ccbf7ea
--- /dev/null
+++ b/tests/manual/rendercapture-qml-fbo/main.qml
@@ -0,0 +1,136 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
+** 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.2
+import QtQuick.Layouts 1.3
+import QtQuick.Controls 2.0
+import Qt3D.Render 2.1
+import QtQuick.Scene3D 2.0
+
+Item {
+
+ width: 1250
+ height: 700
+
+ RowLayout {
+ anchors.fill: parent
+ anchors.margins: 10
+
+ Rectangle {
+ id: background
+ width: 600
+ height: 600
+
+ color: "blue"
+
+ Scene3D {
+ id: scene3d
+ anchors.fill: parent
+ multisample: msacheckbox.checked
+
+ aspects: ["input", "logic"]
+
+ CaptureScene {
+ id: scene
+ }
+ }
+ }
+
+ ColumnLayout {
+
+ Button {
+ id: button
+ anchors.top: parent.top
+ text: "Render Capture"
+
+ property var reply
+ property bool continuous : checkbox.checked
+ property int cid: 1
+
+ function doRenderCapture()
+ {
+ reply = scene.requestRenderCapture()
+ reply.completeChanged.connect(onRenderCaptureComplete)
+ }
+
+ function onRenderCaptureComplete()
+ {
+ _renderCaptureProvider.updateImage(reply)
+ image.source = "image://rendercapture/" + cid
+ reply.saveImage("capture.png")
+ cid++
+ if (continuous === true)
+ doRenderCapture()
+ }
+
+ onClicked: doRenderCapture()
+ }
+ RowLayout {
+ CheckBox {
+ id: checkbox
+ text: "continuous"
+ }
+ CheckBox {
+ id: msacheckbox
+ text: "multisample"
+ }
+ }
+ Image {
+ id: image
+ cache: false
+ source: "image://rendercapture/0"
+ Layout.maximumWidth: 600
+ Layout.minimumWidth: 600
+ Layout.maximumHeight: 600
+ Layout.minimumHeight: 600
+ }
+ }
+ }
+}
diff --git a/tests/manual/rendercapture-qml-fbo/qml.qrc b/tests/manual/rendercapture-qml-fbo/qml.qrc
new file mode 100644
index 000000000..310d6dfe3
--- /dev/null
+++ b/tests/manual/rendercapture-qml-fbo/qml.qrc
@@ -0,0 +1,6 @@
+<RCC>
+ <qresource prefix="/">
+ <file>main.qml</file>
+ <file>CaptureScene.qml</file>
+ </qresource>
+</RCC>
diff --git a/tests/manual/rendercapture-qml-fbo/rendercapture-qml-fbo.pro b/tests/manual/rendercapture-qml-fbo/rendercapture-qml-fbo.pro
new file mode 100644
index 000000000..bea0fc867
--- /dev/null
+++ b/tests/manual/rendercapture-qml-fbo/rendercapture-qml-fbo.pro
@@ -0,0 +1,18 @@
+!include( ../manual.pri ) {
+ error( "Couldn't find the manual.pri file!" )
+}
+
+QT += 3dcore 3drender 3dinput 3dextras 3dquick 3dlogic qml quick 3dquickextras
+
+SOURCES += \
+ main.cpp
+
+DISTFILES += \
+ main.qml
+
+RESOURCES += \
+ qml.qrc
+
+HEADERS += \
+ rendercaptureprovider.h
+
diff --git a/tests/manual/rendercapture-qml-fbo/rendercaptureprovider.h b/tests/manual/rendercapture-qml-fbo/rendercaptureprovider.h
new file mode 100644
index 000000000..d04dbd276
--- /dev/null
+++ b/tests/manual/rendercapture-qml-fbo/rendercaptureprovider.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
+** 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$
+**
+****************************************************************************/
+
+#ifndef RENDERCAPTUREPROVIDER_H
+#define RENDERCAPTUREPROVIDER_H
+
+#include <QtQuick/QQuickImageProvider>
+#include <Qt3DRender/QRenderCapture>
+
+class RenderCaptureProvider : public QObject, public QQuickImageProvider
+{
+ Q_OBJECT
+public:
+ RenderCaptureProvider()
+ : QObject(), QQuickImageProvider(Image)
+ {
+ m_image = QImage(10,10, QImage::Format_ARGB32);
+ m_image.fill(QColor("blue").rgba());
+ }
+
+ Q_INVOKABLE void updateImage(Qt3DRender::QRenderCaptureReply *reply)
+ {
+ m_image = reply->image();
+ }
+
+ virtual QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize)
+ {
+ Q_UNUSED(id)
+ Q_UNUSED(requestedSize)
+ *size = m_image.size();
+ return m_image;
+ }
+
+private:
+ QImage m_image;
+};
+
+#endif