1/**************************************************************************** 2** 3** Copyright (C) 2017 The Qt Company Ltd. 4** Contact: https://www.qt.io/licensing/ 5** 6** This file is part of the examples of the Qt Toolkit. 7** 8** $QT_BEGIN_LICENSE:BSD$ 9** Commercial License Usage 10** Licensees holding valid commercial Qt licenses may use this file in 11** accordance with the commercial license agreement provided with the 12** Software or, alternatively, in accordance with the terms contained in 13** a written agreement between you and The Qt Company. For licensing terms 14** and conditions see https://www.qt.io/terms-conditions. For further 15** information use the contact form at https://www.qt.io/contact-us. 16** 17** BSD License Usage 18** Alternatively, you may use this file under the terms of the BSD license 19** as follows: 20** 21** "Redistribution and use in source and binary forms, with or without 22** modification, are permitted provided that the following conditions are 23** met: 24** * Redistributions of source code must retain the above copyright 25** notice, this list of conditions and the following disclaimer. 26** * Redistributions in binary form must reproduce the above copyright 27** notice, this list of conditions and the following disclaimer in 28** the documentation and/or other materials provided with the 29** distribution. 30** * Neither the name of The Qt Company Ltd nor the names of its 31** contributors may be used to endorse or promote products derived 32** from this software without specific prior written permission. 33** 34** 35** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46** 47** $QT_END_LICENSE$ 48** 49****************************************************************************/ 50 51import QtQuick 2.0 52 53import SceneGraphRendering 1.0 54 55Item { 56 width: 400 57 height: 400 58 59 // The checkers background 60 ShaderEffect { 61 id: tileBackground 62 anchors.fill: parent 63 64 property real tileSize: 16 65 property color color1: Qt.rgba(0.9, 0.9, 0.9, 1); 66 property color color2: Qt.rgba(0.85, 0.85, 0.85, 1); 67 68 property size pixelSize: Qt.size(width / tileSize, height / tileSize); 69 70 fragmentShader: 71 " 72 uniform lowp vec4 color1; 73 uniform lowp vec4 color2; 74 uniform highp vec2 pixelSize; 75 varying highp vec2 qt_TexCoord0; 76 void main() { 77 highp vec2 tc = sign(sin(3.14159265358979323846 * qt_TexCoord0 * pixelSize)); 78 if (tc.x != tc.y) 79 gl_FragColor = color1; 80 else 81 gl_FragColor = color2; 82 } 83 " 84 } 85 86 Renderer { 87 id: renderer 88 anchors.fill: parent 89 anchors.margins: 10 90 91 // The transform is just to show something interesting.. 92 transform: [ 93 Rotation { id: rotation; axis.x: 0; axis.z: 0; axis.y: 1; angle: 0; origin.x: renderer.width / 2; origin.y: renderer.height / 2; }, 94 Translate { id: txOut; x: -renderer.width / 2; y: -renderer.height / 2 }, 95 Scale { id: scale; }, 96 Translate { id: txIn; x: renderer.width / 2; y: renderer.height / 2 } 97 ] 98 99 Behavior on opacity { NumberAnimation { duration: 500 } } 100 opacity: 0 101 Component.onCompleted: renderer.opacity = 1; 102 } 103 104 // Just to show something interesting 105 SequentialAnimation { 106 PauseAnimation { duration: 5000 } 107 ParallelAnimation { 108 NumberAnimation { target: scale; property: "xScale"; to: 0.6; duration: 1000; easing.type: Easing.InOutBack } 109 NumberAnimation { target: scale; property: "yScale"; to: 0.6; duration: 1000; easing.type: Easing.InOutBack } 110 } 111 NumberAnimation { target: rotation; property: "angle"; to: 80; duration: 1000; easing.type: Easing.InOutCubic } 112 NumberAnimation { target: rotation; property: "angle"; to: -80; duration: 1000; easing.type: Easing.InOutCubic } 113 NumberAnimation { target: rotation; property: "angle"; to: 0; duration: 1000; easing.type: Easing.InOutCubic } 114 NumberAnimation { target: renderer; property: "opacity"; to: 0.5; duration: 1000; easing.type: Easing.InOutCubic } 115 PauseAnimation { duration: 1000 } 116 NumberAnimation { target: renderer; property: "opacity"; to: 0.8; duration: 1000; easing.type: Easing.InOutCubic } 117 ParallelAnimation { 118 NumberAnimation { target: scale; property: "xScale"; to: 1; duration: 1000; easing.type: Easing.InOutBack } 119 NumberAnimation { target: scale; property: "yScale"; to: 1; duration: 1000; easing.type: Easing.InOutBack } 120 } 121 running: true 122 loops: Animation.Infinite 123 } 124 125 Rectangle { 126 id: labelFrame 127 anchors.margins: -10 128 radius: 5 129 color: "white" 130 border.color: "black" 131 opacity: 0.8 132 anchors.fill: label 133 } 134 135 Text { 136 id: label 137 anchors.bottom: renderer.bottom 138 anchors.left: renderer.left 139 anchors.right: renderer.right 140 anchors.margins: 20 141 wrapMode: Text.WordWrap 142 text: "The blue rectangle with the vintage 'Q' is an FBO, rendered by the application in a dedicated background thread. The background thread juggles two FBOs, one that is being rendered to and one for displaying. The texture to display is posted to the scene graph and displayed using a QSGSimpleTextureNode." 143 } 144 145 146} 147