aboutsummaryrefslogtreecommitdiffstats
path: root/tests/manual/extensions/textureprovider/Main.qml
blob: ada11551fe02ba5e120eeef1aed4bf67a964ee5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

import QtQuick
import QtQuick.Window
import QtQuick.Controls
import QtQuick.Layouts

import QtQuick3D
import QtQuick3DTest.Extensions.TextureProvider

Window {
    id: window
    width: 800
    height: 600
    visible: true
    title: qsTr("Texture provider")

    View3D {
        id: view
        anchors.left: settings.right
        anchors.right: parent.right
        height: parent.height

        property int api: GraphicsInfo.api
        property bool yIsPointingUpInTextures: view.api === GraphicsInfo.OpenGL
        property real apiFactor: yIsPointingUpInTextures ? 1.0 : 0.0
        property real apiFactorFlip: 1.0 - apiFactor

        extensions: [ RenderExtension {
                id: renderer
            } ]

        Texture {
            id: rendererTexture
            textureProvider: renderer
            flipV: !view.yIsPointingUpInTextures // ignored by custom mat. and postproc. effects
        }

        camera: PerspectiveCamera {
            z: 600
        }

        DirectionalLight {

        }

        Model {
            visible: principledMaterialOption.checked
            source: "#Cube"
            materials: [ PrincipledMaterial {
                baseColorMap: rendererTexture
            } ]

            SequentialAnimation on eulerRotation.y {
                running: animateCb.checked
                NumberAnimation { from: 0; to: 360; duration: 4000 }
                loops: -1
            }
        }

        environment: SceneEnvironment {
            id: env
            effects: []
        }

        Effect {
            id: simpleEffect
            property TextureInput extensionTexture: TextureInput {
                enabled: textureInputEnableCb.checked
                texture: rendererTexture
            }
            property real apiFactor: view.apiFactor
            property real apiFactorFlip: view.apiFactorFlip
            passes: Pass {
               shaders: Shader {
                   stage: Shader.Fragment
                   shader: "effects/effect.frag"
               }
            }
        }

        Model {
            visible: customMaterialShadedOption.checked
            source: "#Cube"
            scale: Qt.vector3d(2, 2, 2)
            materials: CustomMaterial {
                fragmentShader: "materials/shaded_custommaterial.frag"
                property TextureInput extensionTexture: TextureInput {
                    enabled: textureInputEnableCb.checked
                    texture: rendererTexture
                }
                property real apiFactor: view.apiFactor
                property real apiFactorFlip: view.apiFactorFlip
            }
            SequentialAnimation on eulerRotation.y {
                running: animateCb.checked
                NumberAnimation { from: 0; to: 360; duration: 4000 }
                loops: -1
            }
        }

        Model {
            visible: customMaterialUnshadedOption.checked
            source: "#Cube"
            scale: Qt.vector3d(3, 3, 3)
            materials: CustomMaterial {
                shadingMode:  CustomMaterial.Unshaded
                vertexShader: "materials/unshaded_custommaterial.vert"
                fragmentShader: "materials/unshaded_custommaterial.frag"
                property TextureInput extensionTexture: TextureInput {
                    enabled: textureInputEnableCb.checked
                    texture: rendererTexture
                }
                property real apiFactor: view.apiFactor
                property real apiFactorFlip: view.apiFactorFlip
            }
            SequentialAnimation on eulerRotation.y {
                running: animateCb.checked
                NumberAnimation { from: 0; to: 360; duration: 4000 }
                loops: -1
            }
        }
    }

    Rectangle {
        id: settings
        anchors.left: parent.left
        anchors.top: parent.top
        implicitWidth: 350
        implicitHeight: 210
        anchors.margins: 10
        opacity: 0.6
        color: "gray"
        ColumnLayout {
            RadioButton {
                id: principledMaterialOption
                text: "PrincipledMaterial (baseColorMap)"
                checked: true
            }

            RadioButton {
                id: customMaterialShadedOption
                text: "Shaded custom material"
            }

            RadioButton {
                id: customMaterialUnshadedOption
                text: "Unshaded custom material (linear, no tonemap)"
            }

            RadioButton {
                id: effectOption
                text: "Post-processing effect"
                onCheckedChanged: {
                    if (checked)
                        env.effects.push(simpleEffect);
                    else
                        env.effects = [];
                }
            }
            CheckBox {
                id: textureInputEnableCb
                text: "TextureInput enabled"
                checked: true
            }
            CheckBox {
                id: animateCb
                text: "Animate"
                checked: false
            }

            Button {
                text: "Release resources"
                onClicked: window.releaseResources()
            }
        }
    }
}