summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntti Määttä <antti.maatta@qt.io>2016-05-31 15:22:15 +0300
committerAntti Määttä <antti.maatta@qt.io>2017-01-26 12:08:02 +0000
commit5fb7611e5fac37739668d657642f5efd52797d96 (patch)
treebc2b2f3c42da4bf51771c70b7de45226c37293e0
parentdcd5756f3870d9aed7f73c338cc8715d5fe35297 (diff)
downloadqt3d-5fb7611e5fac37739668d657642f5efd52797d96.tar.gz
Render QML to texture examples
Adds tests for the RenderQmlToTexture. Task-number: QTBUG-51656 Change-Id: Ice18b308b85bc522ac5cdb37894d360438b8b3ac Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io> Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--tests/manual/manual.pro4
-rw-r--r--tests/manual/render-qml-to-texture-qml/PlaneMaterial.qml117
-rw-r--r--tests/manual/render-qml-to-texture-qml/main.cpp65
-rw-r--r--tests/manual/render-qml-to-texture-qml/main.qml133
-rw-r--r--tests/manual/render-qml-to-texture-qml/render-qml-to-texture-qml.pro21
-rw-r--r--tests/manual/render-qml-to-texture-qml/render-qml-to-texture-qml.qrc6
-rw-r--r--tests/manual/render-qml-to-texture/OffscreenGui.qml131
-rw-r--r--tests/manual/render-qml-to-texture/TextRectangle.qml86
-rw-r--r--tests/manual/render-qml-to-texture/main.cpp125
-rw-r--r--tests/manual/render-qml-to-texture/planematerial.cpp119
-rw-r--r--tests/manual/render-qml-to-texture/planematerial.h59
-rw-r--r--tests/manual/render-qml-to-texture/render-qml-to-texture.pri8
-rw-r--r--tests/manual/render-qml-to-texture/render-qml-to-texture.pro21
-rw-r--r--tests/manual/render-qml-to-texture/render-qml-to-texture.qrc10
-rw-r--r--tests/manual/render-qml-to-texture/shaders/es2/texturing.frag16
-rw-r--r--tests/manual/render-qml-to-texture/shaders/es2/texturing.vert26
-rw-r--r--tests/manual/render-qml-to-texture/shaders/gl3/texturing.frag16
-rw-r--r--tests/manual/render-qml-to-texture/shaders/gl3/texturing.vert25
18 files changed, 987 insertions, 1 deletions
diff --git a/tests/manual/manual.pro b/tests/manual/manual.pro
index bfb95bfc2..9eedd74a6 100644
--- a/tests/manual/manual.pro
+++ b/tests/manual/manual.pro
@@ -34,7 +34,9 @@ SUBDIRS += \
transparency-qml-scene3d \
rendercapture-qml \
additional-attributes-qml \
- dynamic-model-loader-qml
+ dynamic-model-loader-qml \
+ render-qml-to-texture \
+ render-qml-to-texture-qml
qtHaveModule(widgets): {
SUBDIRS += \
diff --git a/tests/manual/render-qml-to-texture-qml/PlaneMaterial.qml b/tests/manual/render-qml-to-texture-qml/PlaneMaterial.qml
new file mode 100644
index 000000000..6c65de9b3
--- /dev/null
+++ b/tests/manual/render-qml-to-texture-qml/PlaneMaterial.qml
@@ -0,0 +1,117 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import Qt3D.Core 2.0
+import Qt3D.Render 2.0
+
+Material {
+
+ property Texture2D texture
+ property vector2d textureScale: Qt.vector2d(1,-1)
+ property vector2d textureBias: Qt.vector2d(0, 1)
+
+ parameters: [
+ Parameter { name: "surfaceTexture"; value: texture },
+ Parameter { name: "texCoordScale"; value: textureScale },
+ Parameter { name: "texCoordBias"; value: textureBias }
+ ]
+
+ effect: Effect {
+ FilterKey {
+ id: forward
+ name: "renderingStyle"
+ value: "forward"
+ }
+
+ ShaderProgram {
+ id: gl2Es2Shader
+ vertexShaderCode: loadSource("qrc:/shaders/es2/texturing.vert")
+ fragmentShaderCode: loadSource("qrc:/shaders/es2/texturing.frag")
+ }
+
+ ShaderProgram {
+ id: gl3Shader
+ vertexShaderCode: loadSource("qrc:/shaders/gl3/texturing.vert")
+ fragmentShaderCode: loadSource("qrc:/shaders/gl3/texturing.frag")
+ }
+ techniques: [
+ // OpenGL 3.1
+ Technique {
+ filterKeys: [ forward ]
+ graphicsApiFilter {
+ api: GraphicsApiFilter.OpenGL
+ profile: GraphicsApiFilter.CoreProfile
+ majorVersion: 3
+ minorVersion: 1
+ }
+
+ renderPasses: RenderPass {
+ shaderProgram: gl3Shader
+ }
+ },
+
+ // OpenGL 2.1
+ Technique {
+ filterKeys: [ forward ]
+ graphicsApiFilter {
+ api: GraphicsApiFilter.OpenGL
+ profile: GraphicsApiFilter.NoProfile
+ majorVersion: 2
+ minorVersion: 0
+ }
+
+ renderPasses: RenderPass {
+ shaderProgram: gl2Es2Shader
+ }
+ },
+
+ // OpenGL ES 2
+ Technique {
+ filterKeys: [ forward ]
+ graphicsApiFilter {
+ api: GraphicsApiFilter.OpenGLES
+ profile: GraphicsApiFilter.NoProfile
+ majorVersion: 2
+ minorVersion: 0
+ }
+ renderPasses: RenderPass {
+ shaderProgram: gl2Es2Shader
+ }
+ }
+ ]
+ }
+}
diff --git a/tests/manual/render-qml-to-texture-qml/main.cpp b/tests/manual/render-qml-to-texture-qml/main.cpp
new file mode 100644
index 000000000..ac85cbe46
--- /dev/null
+++ b/tests/manual/render-qml-to-texture-qml/main.cpp
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QGuiApplication>
+
+#include <QtQuick/QQuickView>
+#include <Qt3DQuick/QQmlAspectEngine>
+#include <QQmlContext>
+#include <QOpenGLContext>
+
+int main(int argc, char *argv[])
+{
+ QGuiApplication app(argc, argv);
+
+ QSurfaceFormat format;
+ if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
+ format.setVersion(3, 2);
+ format.setProfile(QSurfaceFormat::CoreProfile);
+ }
+ format.setDepthBufferSize(24);
+ format.setStencilBufferSize(8);
+ format.setSamples(4);
+
+ QQuickView view;
+ view.setFormat(format);
+ view.setResizeMode(QQuickView::SizeRootObjectToView);
+ view.setSource(QUrl("qrc:/main.qml"));
+ view.setColor("#000000");
+ view.show();
+
+ return app.exec();
+}
diff --git a/tests/manual/render-qml-to-texture-qml/main.qml b/tests/manual/render-qml-to-texture-qml/main.qml
new file mode 100644
index 000000000..1551065c8
--- /dev/null
+++ b/tests/manual/render-qml-to-texture-qml/main.qml
@@ -0,0 +1,133 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import Qt3D.Core 2.0
+import Qt3D.Render 2.0
+import Qt3D.Input 2.0
+import QtQuick 2.0 as QQ2
+import QtQuick.Scene3D 2.0
+import QtQuick.Window 2.0 as QW2
+import Qt3D.Extras 2.0
+
+
+QQ2.Item {
+ width: 1024
+ height: 768
+
+ Scene3D {
+ id: scene
+ anchors.fill: parent
+
+ aspects: ["input"]
+
+ Entity {
+ id: sceneRoot
+
+ Camera {
+ id: camera
+ projectionType: CameraLens.PerspectiveProjection
+ fieldOfView: 45
+ aspectRatio: scene.width / scene.height
+ nearPlane : 0.1
+ farPlane : 1000.0
+ position: Qt.vector3d( 0.0, 0.0, 6.0 )
+ upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
+ viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
+ }
+
+ Scene2D {
+ id: qmlTexture
+ source: "qrc:/OffscreenGui.qml"
+ renderOnce: false
+ output: RenderTargetOutput {
+ attachmentPoint: RenderTargetOutput.Color0
+ texture: Texture2D {
+ id: offscreenTexture
+ width: 1024
+ height: 1024
+ format: Texture.RGBA8_UNorm
+ generateMipMaps: false
+ magnificationFilter: Texture.Linear
+ minificationFilter: Texture.Linear
+ wrapMode {
+ x: WrapMode.ClampToEdge
+ y: WrapMode.ClampToEdge
+ }
+ }
+ }
+ onLoadedChanged: {
+ console.log("qmlTexture loaded:" + loaded)
+ }
+ }
+
+ FirstPersonCameraController {
+ camera: camera
+ }
+
+ components: [
+ RenderSettings {
+ activeFrameGraph:
+ ForwardRenderer {
+ camera: camera
+ }
+ },
+ InputSettings {}
+ ]
+
+ PlaneMesh {
+ id: planeMesh
+ width: 4
+ height: 4
+ }
+
+ Entity {
+ id: plane1
+
+ property Transform transform: Transform {
+ scale: 1
+ translation: Qt.vector3d(0,0,0)
+ rotation: fromAxisAndAngle(Qt.vector3d(1,0,0), 90)
+ }
+
+ property Material material: PlaneMaterial {
+ texture: offscreenTexture
+ }
+
+ components: [planeMesh, material, transform]
+ }
+ }
+ }
+}
diff --git a/tests/manual/render-qml-to-texture-qml/render-qml-to-texture-qml.pro b/tests/manual/render-qml-to-texture-qml/render-qml-to-texture-qml.pro
new file mode 100644
index 000000000..402378f87
--- /dev/null
+++ b/tests/manual/render-qml-to-texture-qml/render-qml-to-texture-qml.pro
@@ -0,0 +1,21 @@
+!include( ../manual.pri ) {
+ error( "Couldn't find the manual.pri file!" )
+}
+
+!include ( ../render-qml-to-texture/render-qml-to-texture.pri ) {
+ error( "Couldn't find the render-qml-to-texture.pri file!")
+}
+
+QT += 3dextras 3dcore 3drender 3dinput 3dquick qml quick 3dquickrender
+
+SOURCES += main.cpp
+
+RESOURCES += \
+ render-qml-to-texture-qml.qrc
+
+OTHER_FILES += \
+ main.qml
+
+DISTFILES += \
+ PlaneMaterial.qml \
+
diff --git a/tests/manual/render-qml-to-texture-qml/render-qml-to-texture-qml.qrc b/tests/manual/render-qml-to-texture-qml/render-qml-to-texture-qml.qrc
new file mode 100644
index 000000000..6b2a1aef6
--- /dev/null
+++ b/tests/manual/render-qml-to-texture-qml/render-qml-to-texture-qml.qrc
@@ -0,0 +1,6 @@
+<RCC>
+ <qresource prefix="/">
+ <file>main.qml</file>
+ <file>PlaneMaterial.qml</file>
+ </qresource>
+</RCC>
diff --git a/tests/manual/render-qml-to-texture/OffscreenGui.qml b/tests/manual/render-qml-to-texture/OffscreenGui.qml
new file mode 100644
index 000000000..2e18a1e7a
--- /dev/null
+++ b/tests/manual/render-qml-to-texture/OffscreenGui.qml
@@ -0,0 +1,131 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import QtQuick.Controls 1.2
+import QtQuick.Controls.Styles 1.3
+
+Item {
+ width: 1024
+ height: 1024
+
+ TextRectangle {
+ id: textRect
+ }
+
+ Rectangle {
+ id: rect
+ x: 0
+ y: 0
+ width: 200
+ height: 200
+ color: "red"
+
+ ColorAnimation {
+ target: rect
+ loops: Animation.Infinite
+ property: "color"
+ from: "blue"
+ to: "green"
+ duration: 2000
+ running: true
+ }
+ }
+
+ Rectangle {
+ id: rect2
+ width: 300
+ height: 100
+ anchors.right: parent.right
+ anchors.bottom: parent.bottom
+ color: "red"
+
+ ColorAnimation {
+ target: rect2
+ loops: Animation.Infinite
+ property: "color"
+ from: "red"
+ to: "white"
+ duration: 2000
+ running: true
+ }
+ }
+
+ Button {
+ id: button
+ width: 100
+ height: 80
+ anchors.top: rect.bottom
+ anchors.left: parent.left
+ text: "button"
+ scale: 2.0
+ }
+ CheckBox {
+ id: checkbox
+ width: 200
+ height: 180
+ scale: 2.0
+ text: "checkbox"
+ checked: true
+ anchors.top: parent.top
+ anchors.right: parent.right
+
+ Timer {
+ interval: 1000
+ repeat: true
+ running: true
+ onTriggered: {
+ checkbox.checked = !checkbox.checked;
+ }
+ }
+ }
+ Slider {
+ anchors.bottom: parent.bottom
+ anchors.left: parent.left
+ width: 400
+ value: 0.0
+ minimumValue: 0
+ maximumValue: 1
+
+ PropertyAnimation on value {
+ loops: Animation.Infinite
+ duration: 3000
+ from: 0.0
+ to: 1.0
+ running: true
+ }
+ }
+}
diff --git a/tests/manual/render-qml-to-texture/TextRectangle.qml b/tests/manual/render-qml-to-texture/TextRectangle.qml
new file mode 100644
index 000000000..b47fa965b
--- /dev/null
+++ b/tests/manual/render-qml-to-texture/TextRectangle.qml
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+
+Rectangle {
+ id: rectangle
+ property string myText: "The quick brown fox jumps over the lazy dog."
+ x: 352
+ y: 272
+ width: 320
+ height: 480
+ color: "steelblue"
+
+ FontLoader { id: fixedFont; name: "Courier" }
+
+ Column {
+ anchors { fill: parent; leftMargin: 10; rightMargin: 10; topMargin: 10 }
+ spacing: 15
+
+ Text {
+ text: rectangle.myText
+ color: "lightsteelblue"
+ width: parent.width
+ wrapMode: Text.WordWrap
+ font.family: "Times"
+ font.pixelSize: 20
+ }
+ Text {
+ text: rectangle.myText
+ color: "lightsteelblue"
+ width: parent.width
+ wrapMode: Text.WordWrap
+ horizontalAlignment: Text.AlignHCenter
+ font { family: "Times"; pixelSize: 20; capitalization: Font.AllUppercase }
+ }
+ Text {
+ text: rectangle.myText
+ color: "lightsteelblue"
+ width: parent.width
+ horizontalAlignment: Text.AlignRight
+ wrapMode: Text.WordWrap
+ font { family: fixedFont.name; pixelSize: 20; weight: Font.Bold; capitalization: Font.AllLowercase }
+ }
+ Text {
+ text: rectangle.myText
+ color: "lightsteelblue"
+ width: parent.width
+ wrapMode: Text.WordWrap
+ font { family: fixedFont.name; pixelSize: 20; italic: true; capitalization: Font.SmallCaps }
+ }
+ }
+}
diff --git a/tests/manual/render-qml-to-texture/main.cpp b/tests/manual/render-qml-to-texture/main.cpp
new file mode 100644
index 000000000..609da2ebe
--- /dev/null
+++ b/tests/manual/render-qml-to-texture/main.cpp
@@ -0,0 +1,125 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QGuiApplication>
+#include <QAnimationDriver>
+#include <QPropertyAnimation>
+
+#include <Qt3DCore/QEntity>
+#include <Qt3DCore/QAspectEngine>
+#include <Qt3DCore/QTransform>
+#include <Qt3DRender/QCamera>
+
+#include <Qt3DInput/QInputAspect>
+
+#include <Qt3DRender/QRenderAspect>
+#include <Qt3DRender/QEffect>
+#include <Qt3DRender/QMaterial>
+#include <Qt3DExtras/QForwardRenderer>
+#include <Qt3DQuickRender/QScene2D>
+#include <Qt3DExtras/QPlaneMesh>
+#include <Qt3DRender/QTextureWrapMode>
+#include <Qt3DRender/QClearBuffers>
+#include <Qt3DRender/QTexture>
+
+#include "qt3dwindow.h"
+#include "qfirstpersoncameracontroller.h"
+#include "planematerial.h"
+
+int main(int argc, char *argv[])
+{
+ QGuiApplication app(argc, argv);
+
+ Qt3DExtras::Qt3DWindow view;
+
+ // Scene Root
+ Qt3DCore::QEntity *sceneRoot = new Qt3DCore::QEntity();
+
+ // Scene Camera
+ Qt3DRender::QCamera *basicCamera = view.camera();
+ basicCamera->setProjectionType(Qt3DRender::QCameraLens::PerspectiveProjection);
+ basicCamera->setAspectRatio(view.width() / view.height());
+ basicCamera->setUpVector(QVector3D(0.0f, 1.0f, 0.0f));
+ basicCamera->setPosition(QVector3D(0.0f, 0.0f, 6.0f));
+ basicCamera->setViewCenter(QVector3D(0.0f, 0.0f, 0.0f));
+ basicCamera->setNearPlane(0.1f);
+ basicCamera->setFarPlane(1000.0f);
+ basicCamera->setFieldOfView(45.0f);
+
+ // For camera controls
+ Qt3DExtras::QFirstPersonCameraController *camController = new Qt3DExtras::QFirstPersonCameraController(sceneRoot);
+ camController->setCamera(basicCamera);
+
+ Qt3DRender::QFrameGraphNode* frameGraphNode = view.activeFrameGraph();
+ while (frameGraphNode->childNodes().size() > 0)
+ frameGraphNode = (Qt3DRender::QFrameGraphNode*)frameGraphNode->childNodes().at(0);
+ view.defaultFrameGraph()->setClearColor(QColor::fromRgbF(1.0f, 1.0f, 1.0f));
+ Qt3DRender::Quick::QScene2D* qmlTextureRenderer = new Qt3DRender::Quick::QScene2D(frameGraphNode);
+
+ Qt3DRender::QTexture2D* offscreenTexture = new Qt3DRender::QTexture2D(qmlTextureRenderer);
+ offscreenTexture->setSize(1024, 1024);
+ offscreenTexture->setFormat(Qt3DRender::QAbstractTexture::RGBA8_UNorm);
+ offscreenTexture->setGenerateMipMaps(true);
+ offscreenTexture->setMagnificationFilter(Qt3DRender::QAbstractTexture::Linear);
+ offscreenTexture->setMinificationFilter(Qt3DRender::QAbstractTexture::Linear);
+ offscreenTexture->setWrapMode(Qt3DRender::QTextureWrapMode(Qt3DRender::QTextureWrapMode::ClampToEdge, offscreenTexture));
+
+ Qt3DRender::QRenderTargetOutput *output = new Qt3DRender::QRenderTargetOutput(qmlTextureRenderer);
+ output->setAttachmentPoint(Qt3DRender::QRenderTargetOutput::Color0);
+ output->setTexture(offscreenTexture);
+
+ qmlTextureRenderer->setOutput(output);
+ qmlTextureRenderer->setSource(QUrl(QStringLiteral("qrc:/OffscreenGui.qml")));
+// qmlTextureRenderer->setRenderOnce(true);
+
+ Qt3DCore::QEntity* planeEntity = new Qt3DCore::QEntity(sceneRoot);
+ Qt3DExtras::QPlaneMesh* planeMesh = new Qt3DExtras::QPlaneMesh(planeEntity);
+ planeMesh->setWidth(4);
+ planeMesh->setHeight(4);
+ planeEntity->addComponent(planeMesh);
+
+ PlaneMaterial* material = new PlaneMaterial(offscreenTexture, planeEntity);
+ planeEntity->addComponent(material);
+
+ Qt3DCore::QTransform* transform = new Qt3DCore::QTransform(planeEntity);
+ transform->setRotation(QQuaternion::fromAxisAndAngle(1,0,0,90));
+ planeEntity->addComponent(transform);
+
+ view.setRootEntity(sceneRoot);
+ view.show();
+
+ return app.exec();
+}
diff --git a/tests/manual/render-qml-to-texture/planematerial.cpp b/tests/manual/render-qml-to-texture/planematerial.cpp
new file mode 100644
index 000000000..e3886a296
--- /dev/null
+++ b/tests/manual/render-qml-to-texture/planematerial.cpp
@@ -0,0 +1,119 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <Qt3DRender/QParameter>
+#include <Qt3DRender/QEffect>
+#include <Qt3DRender/QTechnique>
+#include <Qt3DRender/QAbstractTexture>
+#include <Qt3DRender/QShaderProgram>
+#include <Qt3DRender/QRenderPass>
+#include <Qt3DRender/QBlendEquation>
+#include <Qt3DRender/QBlendEquationArguments>
+#include <Qt3DRender/QFilterKey>
+#include <Qt3DRender/QGraphicsApiFilter>
+#include <QColor>
+#include <QVector2D>
+#include <QUrl>
+
+#include "planematerial.h"
+
+PlaneMaterial::PlaneMaterial(Qt3DRender::QAbstractTexture *texture, Qt3DCore::QNode *parent)
+ : QMaterial(parent)
+ , m_texture(texture)
+ , m_effect(new Qt3DRender::QEffect(this))
+{
+ setEffect(m_effect);
+
+ m_texCoordScaleParam = new Qt3DRender::QParameter(QStringLiteral("texCoordScale"), QVector2D(1.0f, -1.0f));
+ m_texCoordBiasParam = new Qt3DRender::QParameter(QStringLiteral("texCoordBias"), QVector2D(0.0f, 1.0f));
+ m_textureParam = new Qt3DRender::QParameter(QStringLiteral("surfaceTexture"), m_texture);
+
+ m_effect->addParameter(m_texCoordScaleParam);
+ m_effect->addParameter(m_texCoordBiasParam);
+ m_effect->addParameter(m_textureParam);
+
+ m_filter = new Qt3DRender::QFilterKey(this);
+ m_filter->setName(QStringLiteral("renderingStyle"));
+ m_filter->setValue(QStringLiteral("forward"));
+
+ m_techniqueGLES = new Qt3DRender::QTechnique(m_effect);
+ m_techniqueGL3 = new Qt3DRender::QTechnique(m_effect);
+ m_techniqueGL2 = new Qt3DRender::QTechnique(m_effect);
+
+ m_techniqueGLES->addFilterKey(m_filter);
+ m_techniqueGL3->addFilterKey(m_filter);
+ m_techniqueGL2->addFilterKey(m_filter);
+
+ m_effect->addTechnique(m_techniqueGLES);
+ m_effect->addTechnique(m_techniqueGL3);
+ m_effect->addTechnique(m_techniqueGL2);
+
+ m_programGLES = new Qt3DRender::QShaderProgram(m_effect);
+ m_programGLES->setVertexShaderCode(Qt3DRender::QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/texturing.vert"))));
+ m_programGLES->setFragmentShaderCode(Qt3DRender::QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/texturing.frag"))));
+
+ m_programGL3 = new Qt3DRender::QShaderProgram(m_effect);
+ m_programGL3->setVertexShaderCode(Qt3DRender::QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/texturing.vert"))));
+ m_programGL3->setFragmentShaderCode(Qt3DRender::QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/texturing.frag"))));
+
+ m_renderPassGLES = new Qt3DRender::QRenderPass(m_effect);
+ m_renderPassGL3 = new Qt3DRender::QRenderPass(m_effect);
+ m_renderPassGL2 = new Qt3DRender::QRenderPass(m_effect);
+
+ m_renderPassGLES->setShaderProgram(m_programGLES);
+ m_renderPassGL3->setShaderProgram(m_programGL3);
+ m_renderPassGL2->setShaderProgram(m_programGL3);
+
+ m_techniqueGL2->addRenderPass(m_renderPassGL2);
+ m_techniqueGLES->addRenderPass(m_renderPassGLES);
+ m_techniqueGL3->addRenderPass(m_renderPassGL3);
+
+ m_techniqueGLES->graphicsApiFilter()->setApi(Qt3DRender::QGraphicsApiFilter::OpenGLES);
+ m_techniqueGLES->graphicsApiFilter()->setMajorVersion(2);
+ m_techniqueGLES->graphicsApiFilter()->setMinorVersion(0);
+ m_techniqueGLES->graphicsApiFilter()->setProfile(Qt3DRender::QGraphicsApiFilter::NoProfile);
+
+ m_techniqueGL2->graphicsApiFilter()->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL);
+ m_techniqueGL2->graphicsApiFilter()->setMajorVersion(2);
+ m_techniqueGL2->graphicsApiFilter()->setMinorVersion(0);
+ m_techniqueGL2->graphicsApiFilter()->setProfile(Qt3DRender::QGraphicsApiFilter::NoProfile);
+
+ m_techniqueGL3->graphicsApiFilter()->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL);
+ m_techniqueGL3->graphicsApiFilter()->setMajorVersion(3);
+ m_techniqueGL3->graphicsApiFilter()->setMinorVersion(1);
+ m_techniqueGL3->graphicsApiFilter()->setProfile(Qt3DRender::QGraphicsApiFilter::CoreProfile);
+}
+
diff --git a/tests/manual/render-qml-to-texture/planematerial.h b/tests/manual/render-qml-to-texture/planematerial.h
new file mode 100644
index 000000000..8de7a19c9
--- /dev/null
+++ b/tests/manual/render-qml-to-texture/planematerial.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PLANEMATERIAL_H
+#define PLANEMATERIAL_H
+
+#include <Qt3DRender/QMaterial>
+#include <Qt3DRender/QFilterKey>
+#include <Qt3DRender/QTechnique>
+#include <Qt3DRender/QMaterial>
+
+class PlaneMaterial : public Qt3DRender::QMaterial
+{
+public:
+ explicit PlaneMaterial(Qt3DRender::QAbstractTexture *texture, Qt3DCore::QNode *parent = nullptr);
+private:
+ Qt3DRender::QEffect *m_effect;
+ Qt3DRender::QAbstractTexture *m_texture;
+ Qt3DRender::QParameter *m_textureParam, *m_texCoordScaleParam, *m_texCoordBiasParam;
+ Qt3DRender::QFilterKey *m_filter;
+ Qt3DRender::QTechnique *m_techniqueGLES, *m_techniqueGL3, *m_techniqueGL2;
+ Qt3DRender::QShaderProgram *m_programGLES, *m_programGL3;
+ Qt3DRender::QRenderPass *m_renderPassGLES, *m_renderPassGL3, *m_renderPassGL2;
+};
+
+#endif // PLANEMATERIAL_H
diff --git a/tests/manual/render-qml-to-texture/render-qml-to-texture.pri b/tests/manual/render-qml-to-texture/render-qml-to-texture.pri
new file mode 100644
index 000000000..c0685debc
--- /dev/null
+++ b/tests/manual/render-qml-to-texture/render-qml-to-texture.pri
@@ -0,0 +1,8 @@
+SOURCES += \
+ ../render-qml-to-texture/keyframeanimation.cpp
+
+RESOURCES += \
+ ../render-qml-to-texture/render-qml-to-texture.qrc
+
+HEADERS += \
+ ../render-qml-to-texture/keyframeanimation.h
diff --git a/tests/manual/render-qml-to-texture/render-qml-to-texture.pro b/tests/manual/render-qml-to-texture/render-qml-to-texture.pro
new file mode 100644
index 000000000..e98e62654
--- /dev/null
+++ b/tests/manual/render-qml-to-texture/render-qml-to-texture.pro
@@ -0,0 +1,21 @@
+!include( ../manual.pri ) {
+ error( "Couldn't find the manual.pri file!" )
+}
+
+QT += 3dextras 3dcore 3drender 3dinput 3dquick qml quick 3dquickrender
+
+SOURCES += main.cpp \
+ planematerial.cpp
+
+RESOURCES += \
+ render-qml-to-texture.qrc
+
+OTHER_FILES += \
+ main.qml
+
+DISTFILES += \
+ OffscreenGui.qml \
+ TextRectangle.qml
+
+HEADERS += \
+ planematerial.h
diff --git a/tests/manual/render-qml-to-texture/render-qml-to-texture.qrc b/tests/manual/render-qml-to-texture/render-qml-to-texture.qrc
new file mode 100644
index 000000000..792a74b70
--- /dev/null
+++ b/tests/manual/render-qml-to-texture/render-qml-to-texture.qrc
@@ -0,0 +1,10 @@
+<RCC>
+ <qresource prefix="/">
+ <file>shaders/es2/texturing.frag</file>
+ <file>shaders/es2/texturing.vert</file>
+ <file>shaders/gl3/texturing.frag</file>
+ <file>shaders/gl3/texturing.vert</file>
+ <file>OffscreenGui.qml</file>
+ <file>TextRectangle.qml</file>
+ </qresource>
+</RCC>
diff --git a/tests/manual/render-qml-to-texture/shaders/es2/texturing.frag b/tests/manual/render-qml-to-texture/shaders/es2/texturing.frag
new file mode 100644
index 000000000..b651bd5ed
--- /dev/null
+++ b/tests/manual/render-qml-to-texture/shaders/es2/texturing.frag
@@ -0,0 +1,16 @@
+#define FP highp
+
+uniform FP vec3 eyePosition;
+
+uniform sampler2D surfaceTexture;
+
+varying FP vec3 worldPosition;
+varying FP vec3 worldNormal;
+varying FP vec2 texCoord;
+
+
+
+void main()
+{
+ gl_FragColor = texture2D(surfaceTexture, texCoord);
+}
diff --git a/tests/manual/render-qml-to-texture/shaders/es2/texturing.vert b/tests/manual/render-qml-to-texture/shaders/es2/texturing.vert
new file mode 100644
index 000000000..cfbd338d2
--- /dev/null
+++ b/tests/manual/render-qml-to-texture/shaders/es2/texturing.vert
@@ -0,0 +1,26 @@
+
+
+attribute vec3 vertexPosition;
+attribute vec3 vertexNormal;
+attribute vec2 vertexTexCoord;
+
+varying vec3 worldPosition;
+varying vec3 worldNormal;
+varying vec2 texCoord;
+
+uniform mat4 modelMatrix;
+uniform mat3 modelNormalMatrix;
+uniform mat4 mvp;
+
+uniform vec2 texCoordScale;
+uniform vec2 texCoordBias;
+
+void main()
+{
+ texCoord = vertexTexCoord * texCoordScale + texCoordBias;
+ worldNormal = normalize(modelNormalMatrix * vertexNormal);
+ worldPosition = vec3(modelMatrix * vec4(vertexPosition, 1.0));
+
+ gl_Position = mvp * vec4(vertexPosition, 1.0);
+}
+
diff --git a/tests/manual/render-qml-to-texture/shaders/gl3/texturing.frag b/tests/manual/render-qml-to-texture/shaders/gl3/texturing.frag
new file mode 100644
index 000000000..b051dc254
--- /dev/null
+++ b/tests/manual/render-qml-to-texture/shaders/gl3/texturing.frag
@@ -0,0 +1,16 @@
+#version 150 core
+
+uniform vec3 eyePosition;
+
+uniform sampler2D surfaceTexture;
+
+in vec3 worldPosition;
+in vec3 worldNormal;
+in vec2 texCoord;
+
+out vec4 fragColor;
+
+void main()
+{
+ fragColor = texture(surfaceTexture, texCoord);
+}
diff --git a/tests/manual/render-qml-to-texture/shaders/gl3/texturing.vert b/tests/manual/render-qml-to-texture/shaders/gl3/texturing.vert
new file mode 100644
index 000000000..2b8a08b0a
--- /dev/null
+++ b/tests/manual/render-qml-to-texture/shaders/gl3/texturing.vert
@@ -0,0 +1,25 @@
+#version 150 core
+
+in vec3 vertexPosition;
+in vec3 vertexNormal;
+in vec2 vertexTexCoord;
+
+out vec3 worldPosition;
+out vec3 worldNormal;
+out vec2 texCoord;
+
+uniform mat4 modelMatrix;
+uniform mat3 modelNormalMatrix;
+uniform mat4 mvp;
+
+uniform vec2 texCoordScale;
+uniform vec2 texCoordBias;
+
+void main()
+{
+ texCoord = vertexTexCoord * texCoordScale + texCoordBias;
+ worldNormal = normalize(modelNormalMatrix * vertexNormal);
+ worldPosition = vec3(modelMatrix * vec4(vertexPosition, 1.0));
+
+ gl_Position = mvp * vec4(vertexPosition, 1.0);
+}