summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntti Määttä <antti.maatta@qt.io>2016-10-28 15:05:31 +0300
committerAntti Määttä <antti.maatta@qt.io>2017-01-26 12:08:16 +0000
commit313fc68719093f992c9e114420e72abfcc189c89 (patch)
treea549049aedd7c46dc0803e68705befc46af69a03
parent57a25953d4cba3c3a5262edf8f6094d746d24748 (diff)
Add video texture example
Change-Id: Ifaaaaf038f7b311c9c537bfb0b6ca2117296f1ce Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io> Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--tests/manual/manual.pro3
-rw-r--r--tests/manual/video-texture-qml/PlaneMaterial.qml117
-rw-r--r--tests/manual/video-texture-qml/main.cpp53
-rw-r--r--tests/manual/video-texture-qml/main.qml147
-rw-r--r--tests/manual/video-texture-qml/video-texture-qml.pro21
-rw-r--r--tests/manual/video-texture-qml/video-texture-qml.qrc6
6 files changed, 346 insertions, 1 deletions
diff --git a/tests/manual/manual.pro b/tests/manual/manual.pro
index 9eedd74a6..a535e18f0 100644
--- a/tests/manual/manual.pro
+++ b/tests/manual/manual.pro
@@ -36,7 +36,8 @@ SUBDIRS += \
additional-attributes-qml \
dynamic-model-loader-qml \
render-qml-to-texture \
- render-qml-to-texture-qml
+ render-qml-to-texture-qml \
+ video-texture-qml
qtHaveModule(widgets): {
SUBDIRS += \
diff --git a/tests/manual/video-texture-qml/PlaneMaterial.qml b/tests/manual/video-texture-qml/PlaneMaterial.qml
new file mode 100644
index 000000000..6c65de9b3
--- /dev/null
+++ b/tests/manual/video-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/video-texture-qml/main.cpp b/tests/manual/video-texture-qml/main.cpp
new file mode 100644
index 000000000..5146d5939
--- /dev/null
+++ b/tests/manual/video-texture-qml/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** 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 <Qt3DQuick/QQmlAspectEngine>
+#include <QGuiApplication>
+#include <QQmlEngine>
+#include <QQmlContext>
+#include <Qt3DQuickExtras/Qt3DQuickWindow>
+
+int main(int argc, char* argv[])
+{
+ QGuiApplication app(argc, argv);
+ Qt3DExtras::Quick::Qt3DQuickWindow view;
+
+ view.engine()->qmlEngine()->rootContext()->setContextProperty("_window", &view);
+ view.setSource(QUrl("qrc:/main.qml"));
+ view.show();
+
+ return app.exec();
+}
diff --git a/tests/manual/video-texture-qml/main.qml b/tests/manual/video-texture-qml/main.qml
new file mode 100644
index 000000000..c7d0b47ec
--- /dev/null
+++ b/tests/manual/video-texture-qml/main.qml
@@ -0,0 +1,147 @@
+/****************************************************************************
+**
+** 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.2 as QQ2
+import QtQuick.Window 2.0 as QW2
+import Qt3D.Extras 2.0
+import QtMultimedia 5.6 as QMM
+import QtQuick.Dialogs 1.0
+
+Entity {
+ id: sceneRoot
+
+ Camera {
+ id: camera
+ projectionType: CameraLens.PerspectiveProjection
+ fieldOfView: 45
+ aspectRatio: _window.width / _window.height
+ nearPlane : 0.1
+ farPlane : 1000.0
+ position: Qt.vector3d( 0.0, 0.0, 3.0 )
+ upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
+ viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
+ }
+
+ Scene2D {
+ 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
+ }
+ }
+ }
+ QQ2.Rectangle {
+ width: 400
+ height: 300
+ color: "green"
+
+ QMM.MediaPlayer {
+ id: player
+ autoPlay: false
+ loops: QMM.MediaPlayer.Infinite
+ }
+
+ QMM.VideoOutput {
+ id: videoOutput
+ source: player
+ anchors.fill: parent
+ }
+ }
+ }
+
+ FirstPersonCameraController {
+ camera: camera
+ }
+
+ components: [
+ RenderSettings {
+ activeFrameGraph:
+ ForwardRenderer {
+ camera: camera
+ }
+ },
+ InputSettings {}
+ ]
+
+ CuboidMesh {
+ id: mesh
+ }
+
+ Entity {
+ id: entity
+
+ property Transform transform: Transform {
+ scale: 1
+ translation: Qt.vector3d(0,0,0)
+ }
+
+ property Material material: PlaneMaterial {
+ texture: offscreenTexture
+ }
+
+ components: [mesh, material, transform]
+ }
+
+ FileDialog {
+ id: fileDialog
+ title: "Please choose a video"
+ folder: shortcuts.home
+ onAccepted: {
+ visible = false
+ player.source = fileDialog.fileUrl
+ player.play()
+ }
+ onRejected: {
+ Qt.quit()
+ }
+ QQ2.Component.onCompleted: {
+ visible = true
+ }
+ }
+}
diff --git a/tests/manual/video-texture-qml/video-texture-qml.pro b/tests/manual/video-texture-qml/video-texture-qml.pro
new file mode 100644
index 000000000..713ef8cfe
--- /dev/null
+++ b/tests/manual/video-texture-qml/video-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 += 3dquickextras 3dcore 3drender 3dinput 3dquick qml quick 3dquickrender
+
+SOURCES += main.cpp
+
+RESOURCES += \
+ video-texture-qml.qrc
+
+OTHER_FILES += \
+ main.qml
+
+DISTFILES += \
+ PlaneMaterial.qml
+
diff --git a/tests/manual/video-texture-qml/video-texture-qml.qrc b/tests/manual/video-texture-qml/video-texture-qml.qrc
new file mode 100644
index 000000000..6b2a1aef6
--- /dev/null
+++ b/tests/manual/video-texture-qml/video-texture-qml.qrc
@@ -0,0 +1,6 @@
+<RCC>
+ <qresource prefix="/">
+ <file>main.qml</file>
+ <file>PlaneMaterial.qml</file>
+ </qresource>
+</RCC>