Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquick3dtexturedatafrontend.cpp
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5
7#include <QSize>
8
10
11/*!
12 \qmltype ProceduralTextureData
13 \inqmlmodule QtQuick3D.Helpers
14 \inherits TextureData
15 \brief Allows creation and population of TextureData from QML.
16 \since 6.6
17
18 ProceduralTextureData is a helper type that allows creation of TextureData from QML.
19 The TextureData component is Abstract, and is usually created from C++. With
20 ProceduralTextureData, it is possible to populate a TextureData from QML.
21
22 \qml
23 ProceduralTextureData {
24 id: dynamicTextureData
25 property color color1: "red"
26 property color color2: "black"
27 width: 32
28 height: 32
29 hasTransparency: false
30 format: TextureData.RGBA8
31 textureData: generateTextureData(color1, color2)
32
33 function generateTextureData(newColor1: color, newColor2 : color) : ArrayBuffer {
34 let dataBuffer = new ArrayBuffer(width * height * 4)
35 let data = new Uint8Array(dataBuffer)
36 // Create a checkered pattern using newColor1 and newColor2
37 for (let x = 0; x < width; x++) {
38 for (let y = 0; y < height; y++) {
39 let index = (x + y * width) * 4
40 let color = (x % 2 === y % 2) ? newColor1 : newColor2
41 data[index + 0] = color.r * 255
42 data[index + 1] = color.g * 255
43 data[index + 2] = color.b * 255
44 data[index + 3] = 255
45 }
46 }
47 return dataBuffer
48 }
49 }
50 \endqml
51
52 In the above code snippet, the function generateTextureData is used to generate a
53 checkerboard pattern using the two colors color1 and color2. By filling an
54 ArrayBuffer with the generated data, the textureData property of the TextureData
55 is populated.
56*/
57
58/*!
59 \qmlproperty int ProceduralTextureData::width
60
61 This property holds the width of the texture data in pixels.
62 \default 0
63
64*/
65
66/*!
67 \qmlproperty int ProceduralTextureData::height
68
69 This property holds the height of the texture data in pixels.
70 \default 0
71*/
72
73/*!
74 \qmlproperty int ProceduralTextureData::depth
75
76 This property holds the depth of the texture data in pixels.
77 \default 0
78 Setting the depth above 0 means that the texture is handled as a 3D texture.
79*/
80
81/*!
82 \qmlproperty bool ProceduralTextureData::hasTransparency
83
84 This property holds whether the texture data has transparency.
85*/
86
87/*!
88 \qmlproperty enumeration ProceduralTextureData::format
89
90 This property holds the format of the texture data.
91
92 \default TextureData.RGBA8
93
94 \value TexureData.None The color format is not defined
95 \value TexureData.RGBA8 The color format is considered as 8-bit integer in R, G, B and alpha channels.
96 \value TexureData.RGBA16F The color format is considered as 16-bit float in R,G,B and alpha channels.
97 \value TexureData.RGBA32F The color format is considered as 32-bit float in R, G, B and alpha channels.
98 \value TexureData.RGBE8 The color format is considered as 8-bit mantissa in the R, G, and B channels and 8-bit shared exponent.
99 \value TexureData.R8 The color format is considered as 8-bit integer in R channel.
100 \value TexureData.R16 The color format is considered as 16-bit integer in R channel.
101 \value TexureData.R16F The color format is considered as 16-bit float in R channel.
102 \value TexureData.R32F The color format is considered as 32-bit float R channel.
103 \value TexureData.BC1 The color format is considered as BC1 compressed format with R, G, B, and alpha channels.
104 \value TexureData.BC2 The color format is considered as BC2 compressed format with R, G, B, and alpha channels.
105 \value TexureData.BC3 The color format is considered as BC3 compressed format with R, G, B, and alpha channels.
106 \value TexureData.BC4 The color format is considered as BC4 compressed format with one color channel.
107 \value TexureData.BC5 The color format is considered as BC5 compressed format with two color channels.
108 \value TexureData.BC6H The color format is considered as BC6H compressed format with three high dynamic range color channels.
109 \value TexureData.BC7 The color format is considered as BC7 compressed format with R, G, B, and alpha channels.
110 \value TexureData.DXT1_RGBA The color format is considered as DXT1 compressed format with R, G, B and alpha channels.
111 \value TexureData.DXT1_RGB The color format is considered as DXT1 compressed format with R, G and B channels.
112 \value TexureData.DXT3_RGBA The color format is considered as DXT3 compressed format with R, G, B and alpha channels.
113 \value TexureData.DXT5_RGBA The color format is considered as DXT5 compressed format with R, G, B and alpha channels.
114 \value TexureData.ETC2_RGB8 The color format is considered as ETC2 compressed format for RGB888 data
115 \value TexureData.ETC2_RGB8A1 The color format is considered as ETC2 compressed format for RGBA data where alpha is 1-bit.
116 \value TexureData.ETC2_RGBA8 The color format is considered as ETC2 compressed format with RGBA8888 data.
117 \value TexureData.ASTC_4x4 The color format is considered as ASTC compressed format with 4x4 block footprint.
118 \value TexureData.ASTC_5x4 The color format is considered as ASTC compressed format with 5x4 block footprint.
119 \value TexureData.ASTC_5x5 The color format is considered as ASTC compressed format with 5x5 block footprint.
120 \value TexureData.ASTC_6x5 The color format is considered as ASTC compressed format with 6x5 block footprint.
121 \value TexureData.ASTC_6x6 The color format is considered as ASTC compressed format with 6x6 block footprint.
122 \value TexureData.ASTC_8x5 The color format is considered as ASTC compressed format with 8x5 block footprint.
123 \value TexureData.ASTC_8x6 The color format is considered as ASTC compressed format with 8x6 block footprint.
124 \value TexureData.ASTC_8x8 The color format is considered as ASTC compressed format with 8x8 block footprint.
125 \value TexureData.ASTC_10x5 The color format is considered as ASTC compressed format with 10x5 block footprint.
126 \value TexureData.ASTC_10x6 The color format is considered as ASTC compressed format with 10x6 block footprint.
127 \value TexureData.ASTC_10x8 The color format is considered as ASTC compressed format with 10x8 block footprint.
128 \value TexureData.ASTC_10x10 The color format is considered as ASTC compressed format with 10x10 block footprint.
129 \value TexureData.ASTC_12x10 The color format is considered as ASTC compressed format with 12x10 block footprint.
130 \value TexureData.ASTC_12x12 The color format is considered as ASTC compressed format with 12x12 block footprint.
131
132 \note With the exception of \c TexureData.RGBA8, not every format is supported at runtime as this
133 depends on which backend is being used as well which hardware is being used.
134
135 \note \c TexureData.RGBE is internally represented as an \c TexureData.RGBA8 but is interpreted as described when used
136 as a lightProbe or skybox texture.
137
138 \note Using the value \c TexureData.None will assume the default value of \c TexureData.RGBA8
139*/
140
141/*!
142 \qmlproperty ArrayBuffer ProceduralTextureData::textureData
143
144 This property holds the texture data.
145*/
146
147QQuick3DTextureDataFrontend::QQuick3DTextureDataFrontend()
148{
149
150}
151
152
153QQuick3DTextureData::Format QQuick3DTextureDataFrontend::format() const
154{
155 return QQuick3DTextureData::format();
156}
157
158void QQuick3DTextureDataFrontend::setFormat(const QQuick3DTextureData::Format &newFormat)
159{
160 if (newFormat == QQuick3DTextureData::format())
161 return;
162
163 QQuick3DTextureData::setFormat(newFormat);
164
165 Q_EMIT formatChanged();
166}
167
168int QQuick3DTextureDataFrontend::depth() const
169{
170 return QQuick3DTextureData::depth();
171}
172
173void QQuick3DTextureDataFrontend::setDepth(int newDepth)
174{
175 if (newDepth == QQuick3DTextureData::depth())
176 return;
177
178
179 QQuick3DTextureData::setDepth(newDepth);
180
181 Q_EMIT depthChanged();
182}
183
184bool QQuick3DTextureDataFrontend::hasTransparency() const
185{
186 return QQuick3DTextureData::hasTransparency();
187}
188
189void QQuick3DTextureDataFrontend::setHasTransparency(bool newHasTransparency)
190{
191 if (newHasTransparency == QQuick3DTextureData::hasTransparency())
192 return;
193
194 QQuick3DTextureData::setHasTransparency(newHasTransparency);
195
196 Q_EMIT hasTransparencyChanged();
197}
198
199QByteArray QQuick3DTextureDataFrontend::textureData() const
200{
201 return QQuick3DTextureData::textureData();
202}
203
204void QQuick3DTextureDataFrontend::setTextureData(const QByteArray &newTextureData)
205{
206 QQuick3DTextureData::setTextureData(newTextureData);
207 Q_EMIT textureDataChanged();
208}
209
210int QQuick3DTextureDataFrontend::width() const
211{
212 return QQuick3DTextureData::size().width();
213}
214
215void QQuick3DTextureDataFrontend::setWidth(int newWidth)
216{
217 const auto size = QQuick3DTextureData::size();
218
219 if (size.width() == newWidth)
220 return;
221
222 QQuick3DTextureData::setSize(QSize(newWidth, size.height()));
223
224 Q_EMIT widthChanged();
225}
226
227int QQuick3DTextureDataFrontend::height() const
228{
229 return QQuick3DTextureData::size().height();
230}
231
232void QQuick3DTextureDataFrontend::setHeight(int newHeight)
233{
234 const auto size = QQuick3DTextureData::size();
235
236 if (size.height() == newHeight)
237 return;
238
239 QQuick3DTextureData::setSize(QSize(size.width(), newHeight));
240
241 Q_EMIT heightChanged();
242}
243
244QT_END_NAMESPACE
Combined button and popup list for selecting options.