Debian Codegraph @

tests/manual/additional-attributes-qml/main.qml

raw
1 // Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 import QtQuick 2.2 as QQ2
5 import Qt3D.Core 2.0
6 import Qt3D.Render 2.0
7 import Qt3D.Input 2.0
8 import Qt3D.Extras 2.0
9
10 Entity {
11 id: sceneRoot
12
13 Camera {
14 id: camera
15 projectionType: CameraLens.PerspectiveProjection
16 fieldOfView: 45
17 aspectRatio: 16/9
18 nearPlane : 0.1
19 farPlane : 1000.0
20 position: Qt.vector3d( 0.0, 0.0, -40.0 )
21 upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
22 viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
23 }
24
25 OrbitCameraController {
26 camera: camera
27 }
28
29 components: [
30 RenderSettings {
31 activeFrameGraph: ForwardRenderer {
32 clearColor: Qt.rgba(0, 0.5, 1, 1)
33 camera: camera
34 }
35 },
36 // Event Source will be set by the Qt3DQuickWindow
37 InputSettings { }
38 ]
39
40 readonly property Buffer translationBuffer: Buffer {
41 data: {
42 var array = new Float32Array(20 * 3)
43 for (var i = 0; i < 20; ++i) {
44 var j = i * 3;
45 array[j] = i * 4.0;
46 array[j + 1] = 0.0;
47 array[j + 2] = 0.0;
48 }
49 return array;
50 }
51 }
52
53 readonly property Material instancedMaterial: Material {
54 effect: Effect {
55 techniques: Technique {
56 filterKeys: FilterKey { name: "renderingStyle"; value: "forward" }
57
58 graphicsApiFilter {
59 api: GraphicsApiFilter.OpenGL
60 majorVersion: 3
61 minorVersion: 2
62 profile: GraphicsApiFilter.CoreProfile
63 }
64
65 renderPasses: RenderPass {
66 shaderProgram: ShaderProgram {
67 vertexShaderCode: "
68 #version 150
69 in vec3 vertexPosition;
70 in vec3 translation;
71 uniform mat4 mvp;
72
73 void main()
74 {
75 gl_Position = mvp * vec4(vertexPosition + translation, 1.0);
76 }
77 "
78
79 fragmentShaderCode: "
80 #version 150
81
82 out vec4 fragColor;
83
84 void main()
85 {
86 fragColor = vec4(1.0, 0.0, 0.0, 1.0);
87 }
88 "
89 }
90 }
91 }
92 }
93 }
94
95 GeometryRenderer {
96 id: torusMesh
97 instanceCount: 20
98 geometry: torusGeometry
99 }
100
101 TorusGeometry {
102 id: torusGeometry
103 minorRadius: 0.5
104 attributes: [
105 Attribute {
106 attributeType: Attribute.VertexAttribute
107 vertexBaseType: Attribute.Float
108 vertexSize: 3
109 byteStride: 3 * 4 // vector3d
110 byteOffset: 0
111 divisor: 1 // One translation per instance
112 name: "translation"
113 buffer: translationBuffer
114 }
115 ]
116 }
117
118 // Doesn't work
119 // TorusMesh {
120 // id: torusMesh
121 // geometry.attributes: [
122 // Attribute {
123 // attributeType: Attribute.VertexAttribute
124 // vertexBaseType: Attribute.Float
125 // vertexSize: 3
126 // byteStride: 3 * 4 // vector3d
127 // byteOffset: 0
128 // divisor: 1 // One translation per instance
129 // name: "translation"
130 // buffer: translationBuffer
131 // }
132 // ]
133 // }
134
135 Transform {
136 id: torusTransform
137 rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 45)
138 }
139
140 Entity {
141 id: torusEntity
142 components: [ torusMesh, instancedMaterial, torusTransform ]
143 }
144 }