Debian Codegraph @

tests/manual/nodetypes_ng/ShaderEffect.qml

raw
1 /****************************************************************************
2 **
3 ** Copyright (C) 2019 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the demonstration applications 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
51 // Use QtQuick 2.8 to get GraphicsInfo and others
52 import QtQuick 2.8
53
54 Item {
55 Rectangle {
56 color: "gray"
57 anchors.margins: 10
58 anchors.fill: parent
59 Image {
60 id: image1
61 source: "qrc:/qt.png"
62 }
63 ShaderEffectSource {
64 id: effectSource1
65 sourceItem: image1
66 hideSource: true
67 }
68 ShaderEffect { // wobble
69 id: eff
70 width: image1.width
71 height: image1.height
72 anchors.centerIn: parent
73
74 property variant source: effectSource1
75 property real amplitude: 0.04 * 0.2
76 property real frequency: 20
77 property real time: 0
78
79 NumberAnimation on time { loops: Animation.Infinite; from: 0; to: Math.PI * 2; duration: 600 }
80
81 vertexShader: GraphicsInfo.shaderType === GraphicsInfo.GLSL ? "qrc:/wobble_legacy_gl.vert" : "qrc:/wobble.vert.qsb"
82 fragmentShader: GraphicsInfo.shaderType === GraphicsInfo.GLSL ? "qrc:/wobble_legacy_gl.frag" : "qrc:/wobble.frag.qsb"
83 }
84
85 Image {
86 id: image2
87 source: "qrc:/face-smile.png"
88 }
89 ShaderEffectSource {
90 id: effectSource2
91 sourceItem: image2
92 hideSource: true
93 }
94 ShaderEffect { // dropshadow
95 id: eff2
96 width: image2.width
97 height: image2.height
98 scale: 2
99 x: 40
100 y: 40
101
102 property variant source: effectSource2
103
104 property variant shadow: ShaderEffectSource {
105 sourceItem: ShaderEffect {
106 width: eff2.width
107 height: eff2.height
108 property variant delta: Qt.size(0.0, 1.0 / height)
109 property variant source: ShaderEffectSource {
110 sourceItem: ShaderEffect {
111 id: innerEff
112 width: eff2.width
113 height: eff2.height
114 property variant delta: Qt.size(1.0 / width, 0.0)
115 property variant source: effectSource2
116 fragmentShader: GraphicsInfo.shaderType === GraphicsInfo.GLSL ? "qrc:/shadow_pass1_legacy_gl.frag" : "qrc:/shadow_pass1.frag.qsb"
117 }
118 }
119 fragmentShader: GraphicsInfo.shaderType === GraphicsInfo.GLSL ? "qrc:/shadow_pass1_legacy_gl.frag" : "qrc:/shadow_pass1.frag.qsb"
120 }
121 }
122 property real angle: 0
123 property variant offset: Qt.point(5.0 * Math.cos(angle), 5.0 * Math.sin(angle))
124 NumberAnimation on angle { loops: Animation.Infinite; from: 0; to: Math.PI * 2; duration: 6000 }
125 property variant delta: Qt.size(offset.x / width, offset.y / height)
126 property real darkness: 0.5
127 fragmentShader: GraphicsInfo.shaderType === GraphicsInfo.GLSL ? "qrc:/shadow_pass2_legacy_gl.frag" : "qrc:/shadow_pass2.frag.qsb"
128 }
129
130 Column {
131 anchors.bottom: parent.bottom
132 Text {
133 color: "yellow"
134 font.pointSize: 24
135 text: {
136 if (GraphicsInfo.api === GraphicsInfo.OpenGL)
137 "OpenGL";
138 else if (GraphicsInfo.api === GraphicsInfo.Software)
139 "Software";
140 else if (GraphicsInfo.api === GraphicsInfo.Direct3D12)
141 "D3D12";
142 else if (GraphicsInfo.api === GraphicsInfo.OpenVG)
143 "OpenVG";
144 else if (GraphicsInfo.api === GraphicsInfo.OpenGLRhi)
145 "OpenGL via QRhi";
146 else if (GraphicsInfo.api === GraphicsInfo.Direct3D11Rhi)
147 "D3D11 via QRhi";
148 else if (GraphicsInfo.api === GraphicsInfo.VulkanRhi)
149 "Vulkan via QRhi";
150 else if (GraphicsInfo.api === GraphicsInfo.MetalRhi)
151 "Metal via QRhi";
152 else if (GraphicsInfo.api === GraphicsInfo.Null)
153 "Null via QRhi";
154 else
155 "Unknown API";
156 }
157 }
158 Text {
159 color: "yellow"
160 font.pointSize: 24
161 text: "Shader effect is " + (GraphicsInfo.shaderType === GraphicsInfo.HLSL
162 ? "HLSL" : (GraphicsInfo.shaderType === GraphicsInfo.GLSL
163 ? "GLSL" : (GraphicsInfo.shaderType === GraphicsInfo.RhiShader
164 ? "QRhiShader" : "UNKNOWN"))) + " based";
165 }
166 Text {
167 text: GraphicsInfo.shaderType + " " + GraphicsInfo.shaderCompilationType + " " + GraphicsInfo.shaderSourceType
168 }
169 Text {
170 //text: eff.status + " " + eff.log
171 }
172 }
173 }
174 }