1 | // Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QT3DRENDER_QABSTRACTTEXTURE_H |
5 | #define QT3DRENDER_QABSTRACTTEXTURE_H |
6 | |
7 | #include <Qt3DRender/qtextureimagedata.h> |
8 | #include <Qt3DRender/qtexturewrapmode.h> |
9 | #include <Qt3DRender/qt3drender_global.h> |
10 | #include <Qt3DCore/qnode.h> |
11 | #include <QtCore/QVariant> |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | namespace Qt3DRender { |
16 | |
17 | class QAbstractTexturePrivate; |
18 | class QAbstractTextureImage; |
19 | class QTextureDataUpdate; |
20 | |
21 | class Q_3DRENDERSHARED_EXPORT QAbstractTexture : public Qt3DCore::QNode |
22 | { |
23 | Q_OBJECT |
24 | Q_PROPERTY(Target target READ target CONSTANT) |
25 | Q_PROPERTY(TextureFormat format READ format WRITE setFormat NOTIFY formatChanged) |
26 | Q_PROPERTY(bool generateMipMaps READ generateMipMaps WRITE setGenerateMipMaps NOTIFY generateMipMapsChanged) |
27 | Q_PROPERTY(Qt3DRender::QTextureWrapMode *wrapMode READ wrapMode CONSTANT) |
28 | Q_PROPERTY(Status status READ status NOTIFY statusChanged) |
29 | Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged) |
30 | Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged) |
31 | Q_PROPERTY(int depth READ depth WRITE setDepth NOTIFY depthChanged) |
32 | Q_PROPERTY(int mipLevels READ mipLevels WRITE setMipLevels NOTIFY mipLevelsChanged) |
33 | Q_PROPERTY(Filter magnificationFilter READ magnificationFilter WRITE setMagnificationFilter NOTIFY magnificationFilterChanged) |
34 | Q_PROPERTY(Filter minificationFilter READ minificationFilter WRITE setMinificationFilter NOTIFY minificationFilterChanged) |
35 | Q_PROPERTY(float maximumAnisotropy READ maximumAnisotropy WRITE setMaximumAnisotropy NOTIFY maximumAnisotropyChanged) |
36 | Q_PROPERTY(ComparisonFunction comparisonFunction READ comparisonFunction WRITE setComparisonFunction NOTIFY comparisonFunctionChanged) |
37 | Q_PROPERTY(ComparisonMode comparisonMode READ comparisonMode WRITE setComparisonMode NOTIFY comparisonModeChanged) |
38 | Q_PROPERTY(int layers READ layers WRITE setLayers NOTIFY layersChanged) |
39 | Q_PROPERTY(int samples READ samples WRITE setSamples NOTIFY samplesChanged) |
40 | Q_PROPERTY(HandleType handleType READ handleType NOTIFY handleTypeChanged REVISION 13) |
41 | Q_PROPERTY(QVariant handle READ handle NOTIFY handleChanged REVISION 13) |
42 | |
43 | public: |
44 | |
45 | enum Status { |
46 | None = 0, |
47 | Loading, |
48 | Ready, |
49 | Error |
50 | }; |
51 | Q_ENUM(Status) // LCOV_EXCL_LINE |
52 | |
53 | enum Target { |
54 | TargetAutomatic = 0, // Target will be determined by the Qt3D engine |
55 | Target1D = 0x0DE0, // GL_TEXTURE_1D |
56 | Target1DArray = 0x8C18, // GL_TEXTURE_1D_ARRAY |
57 | Target2D = 0x0DE1, // GL_TEXTURE_2D |
58 | Target2DArray = 0x8C1A, // GL_TEXTURE_2D_ARRAY |
59 | Target3D = 0x806F, // GL_TEXTURE_3D |
60 | TargetCubeMap = 0x8513, // GL_TEXTURE_CUBE_MAP |
61 | TargetCubeMapArray = 0x9009, // GL_TEXTURE_CUBE_MAP_ARRAY |
62 | Target2DMultisample = 0x9100, // GL_TEXTURE_2D_MULTISAMPLE |
63 | Target2DMultisampleArray = 0x9102, // GL_TEXTURE_2D_MULTISAMPLE_ARRAY |
64 | TargetRectangle = 0x84F5, // GL_TEXTURE_RECTANGLE |
65 | TargetBuffer = 0x8C2A // GL_TEXTURE_BUFFER |
66 | }; |
67 | Q_ENUM(Target) // LCOV_EXCL_LINE |
68 | |
69 | enum TextureFormat { |
70 | NoFormat = 0, // GL_NONE |
71 | Automatic = 1, // The Qt3D engine automatically determines the best format |
72 | |
73 | // Unsigned normalized formats |
74 | R8_UNorm = 0x8229, // GL_R8 |
75 | RG8_UNorm = 0x822B, // GL_RG8 |
76 | RGB8_UNorm = 0x8051, // GL_RGB8 |
77 | RGBA8_UNorm = 0x8058, // GL_RGBA8 |
78 | |
79 | R16_UNorm = 0x822A, // GL_R16 |
80 | RG16_UNorm = 0x822C, // GL_RG16 |
81 | RGB16_UNorm = 0x8054, // GL_RGB16 |
82 | RGBA16_UNorm = 0x805B, // GL_RGBA16 |
83 | |
84 | // Signed normalized formats |
85 | R8_SNorm = 0x8F94, // GL_R8_SNORM |
86 | RG8_SNorm = 0x8F95, // GL_RG8_SNORM |
87 | RGB8_SNorm = 0x8F96, // GL_RGB8_SNORM |
88 | RGBA8_SNorm = 0x8F97, // GL_RGBA8_SNORM |
89 | |
90 | R16_SNorm = 0x8F98, // GL_R16_SNORM |
91 | RG16_SNorm = 0x8F99, // GL_RG16_SNORM |
92 | RGB16_SNorm = 0x8F9A, // GL_RGB16_SNORM |
93 | RGBA16_SNorm = 0x8F9B, // GL_RGBA16_SNORM |
94 | |
95 | // Unsigned integer formats |
96 | R8U = 0x8232, // GL_R8UI |
97 | RG8U = 0x8238, // GL_RG8UI |
98 | RGB8U = 0x8D7D, // GL_RGB8UI |
99 | RGBA8U = 0x8D7C, // GL_RGBA8UI |
100 | |
101 | R16U = 0x8234, // GL_R16UI |
102 | RG16U = 0x823A, // GL_RG16UI |
103 | RGB16U = 0x8D77, // GL_RGB16UI |
104 | RGBA16U = 0x8D76, // GL_RGBA16UI |
105 | |
106 | R32U = 0x8236, // GL_R32UI |
107 | RG32U = 0x823C, // GL_RG32UI |
108 | RGB32U = 0x8D71, // GL_RGB32UI |
109 | RGBA32U = 0x8D70, // GL_RGBA32UI |
110 | |
111 | // Signed integer formats |
112 | R8I = 0x8231, // GL_R8I |
113 | RG8I = 0x8237, // GL_RG8I |
114 | RGB8I = 0x8D8F, // GL_RGB8I |
115 | RGBA8I = 0x8D8E, // GL_RGBA8I |
116 | |
117 | R16I = 0x8233, // GL_R16I |
118 | RG16I = 0x8239, // GL_RG16I |
119 | RGB16I = 0x8D89, // GL_RGB16I |
120 | RGBA16I = 0x8D88, // GL_RGBA16I |
121 | |
122 | R32I = 0x8235, // GL_R32I |
123 | RG32I = 0x823B, // GL_RG32I |
124 | RGB32I = 0x8D83, // GL_RGB32I |
125 | RGBA32I = 0x8D82, // GL_RGBA32I |
126 | |
127 | // Floating point formats |
128 | R16F = 0x822D, // GL_R16F |
129 | RG16F = 0x822F, // GL_RG16F |
130 | RGB16F = 0x881B, // GL_RGB16F |
131 | RGBA16F = 0x881A, // GL_RGBA16F |
132 | |
133 | R32F = 0x822E, // GL_R32F |
134 | RG32F = 0x8230, // GL_RG32F |
135 | RGB32F = 0x8815, // GL_RGB32F |
136 | RGBA32F = 0x8814, // GL_RGBA32F |
137 | |
138 | // Packed formats |
139 | RGB9E5 = 0x8C3D, // GL_RGB9_E5 |
140 | RG11B10F = 0x8C3A, // GL_R11F_G11F_B10F |
141 | RG3B2 = 0x2A10, // GL_R3_G3_B2 |
142 | R5G6B5 = 0x8D62, // GL_RGB565 |
143 | RGB5A1 = 0x8057, // GL_RGB5_A1 |
144 | RGBA4 = 0x8056, // GL_RGBA4 |
145 | RGB10A2 = 0x8059, // GL_RGB10_A2 |
146 | RGB10A2U = 0x906F, // GL_RGB10_A2UI |
147 | |
148 | // Depth formats |
149 | D16 = 0x81A5, // GL_DEPTH_COMPONENT16 |
150 | D24 = 0x81A6, // GL_DEPTH_COMPONENT24 |
151 | D24S8 = 0x88F0, // GL_DEPTH24_STENCIL8 |
152 | D32 = 0x81A7, // GL_DEPTH_COMPONENT32 |
153 | D32F = 0x8CAC, // GL_DEPTH_COMPONENT32F |
154 | D32FS8X24 = 0x8CAD, // GL_DEPTH32F_STENCIL8 |
155 | |
156 | // Compressed formats |
157 | RGB_DXT1 = 0x83F0, // GL_COMPRESSED_RGB_S3TC_DXT1_EXT |
158 | RGBA_DXT1 = 0x83F1, // GL_COMPRESSED_RGBA_S3TC_DXT1_EXT |
159 | RGBA_DXT3 = 0x83F2, // GL_COMPRESSED_RGBA_S3TC_DXT3_EXT |
160 | RGBA_DXT5 = 0x83F3, // GL_COMPRESSED_RGBA_S3TC_DXT5_EXT |
161 | R_ATI1N_UNorm = 0x8DBB, // GL_COMPRESSED_RED_RGTC1 |
162 | R_ATI1N_SNorm = 0x8DBC, // GL_COMPRESSED_SIGNED_RED_RGTC1 |
163 | RG_ATI2N_UNorm = 0x8DBD, // GL_COMPRESSED_RG_RGTC2 |
164 | RG_ATI2N_SNorm = 0x8DBE, // GL_COMPRESSED_SIGNED_RG_RGTC2 |
165 | RGB_BP_UNSIGNED_FLOAT = 0x8E8F, // GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB |
166 | RGB_BP_SIGNED_FLOAT = 0x8E8E, // GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB |
167 | RGB_BP_UNorm = 0x8E8C, // GL_COMPRESSED_RGBA_BPTC_UNORM_ARB |
168 | R11_EAC_UNorm = 0x9270, // GL_COMPRESSED_R11_EAC |
169 | R11_EAC_SNorm = 0x9271, // GL_COMPRESSED_SIGNED_R11_EAC |
170 | RG11_EAC_UNorm = 0x9272, // GL_COMPRESSED_RG11_EAC |
171 | RG11_EAC_SNorm = 0x9273, // GL_COMPRESSED_SIGNED_RG11_EAC |
172 | RGB8_ETC2 = 0x9274, // GL_COMPRESSED_RGB8_ETC2 |
173 | SRGB8_ETC2 = 0x9275, // GL_COMPRESSED_SRGB8_ETC2 |
174 | RGB8_PunchThrough_Alpha1_ETC2 = 0x9276, // GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 |
175 | SRGB8_PunchThrough_Alpha1_ETC2 = 0x9277, // GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 |
176 | RGBA8_ETC2_EAC = 0x9278, // GL_COMPRESSED_RGBA8_ETC2_EAC |
177 | SRGB8_Alpha8_ETC2_EAC = 0x9279, // GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC |
178 | RGB8_ETC1 = 0x8D64, // GL_ETC1_RGB8_OES |
179 | |
180 | // sRGB formats |
181 | SRGB8 = 0x8C41, // GL_SRGB8 |
182 | SRGB8_Alpha8 = 0x8C43, // GL_SRGB8_ALPHA8 |
183 | SRGB_DXT1 = 0x8C4C, // GL_COMPRESSED_SRGB_S3TC_DXT1_EXT |
184 | SRGB_Alpha_DXT1 = 0x8C4D, // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT |
185 | SRGB_Alpha_DXT3 = 0x8C4E, // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT |
186 | SRGB_Alpha_DXT5 = 0x8C4F, // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT |
187 | SRGB_BP_UNorm = 0x8E8D, // GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB |
188 | |
189 | // ES 2 formats |
190 | DepthFormat = 0x1902, // GL_DEPTH_COMPONENT |
191 | AlphaFormat = 0x1906, // GL_ALPHA |
192 | RGBFormat = 0x1907, // GL_RGB |
193 | RGBAFormat = 0x1908, // GL_RGBA |
194 | LuminanceFormat = 0x1909, // GL_LUMINANCE |
195 | LuminanceAlphaFormat = 0x190A |
196 | }; |
197 | Q_ENUM(TextureFormat) // LCOV_EXCL_LINE |
198 | |
199 | enum Filter { |
200 | Nearest = 0x2600, // GL_NEAREST |
201 | Linear = 0x2601, // GL_LINEAR |
202 | NearestMipMapNearest = 0x2700, // GL_NEAREST_MIPMAP_NEAREST |
203 | NearestMipMapLinear = 0x2702, // GL_NEAREST_MIPMAP_LINEAR |
204 | LinearMipMapNearest = 0x2701, // GL_LINEAR_MIPMAP_NEAREST |
205 | LinearMipMapLinear = 0x2703 // GL_LINEAR_MIPMAP_LINEAR |
206 | }; |
207 | Q_ENUM(Filter) // LCOV_EXCL_LINE |
208 | |
209 | enum CubeMapFace { |
210 | CubeMapPositiveX = 0x8515, // GL_TEXTURE_CUBE_MAP_POSITIVE_X |
211 | CubeMapNegativeX = 0x8516, // GL_TEXTURE_CUBE_MAP_NEGATIVE_X |
212 | CubeMapPositiveY = 0x8517, // GL_TEXTURE_CUBE_MAP_POSITIVE_Y |
213 | CubeMapNegativeY = 0x8518, // GL_TEXTURE_CUBE_MAP_NEGATIVE_Y |
214 | CubeMapPositiveZ = 0x8519, // GL_TEXTURE_CUBE_MAP_POSITIVE_Z |
215 | CubeMapNegativeZ = 0x851A, // GL_TEXTURE_CUBE_MAP_NEGATIVE_Z |
216 | AllFaces |
217 | }; |
218 | Q_ENUM(CubeMapFace) // LCOV_EXCL_LINE |
219 | |
220 | enum ComparisonFunction { |
221 | CompareLessEqual = 0x0203, // GL_LEQUAL |
222 | CompareGreaterEqual = 0x0206, // GL_GEQUAL |
223 | CompareLess = 0x0201, // GL_LESS |
224 | CompareGreater = 0x0204, // GL_GREATER |
225 | CompareEqual = 0x0202, // GL_EQUAL |
226 | CommpareNotEqual = 0x0205, // GL_NOTEQUAL |
227 | CompareAlways = 0x0207, // GL_ALWAYS |
228 | CompareNever = 0x0200 // GL_NEVER |
229 | }; |
230 | Q_ENUM(ComparisonFunction) // LCOV_EXCL_LINE |
231 | |
232 | enum ComparisonMode { |
233 | CompareRefToTexture = 0x884E, // GL_COMPARE_REF_TO_TEXTURE |
234 | CompareNone = 0x0000 // GL_NONE |
235 | }; |
236 | Q_ENUM(ComparisonMode) // LCOV_EXCL_LINE |
237 | |
238 | enum HandleType { |
239 | NoHandle, |
240 | OpenGLTextureId, |
241 | RHITextureId |
242 | }; |
243 | Q_ENUM(HandleType) // LCOV_EXCL_LINE |
244 | |
245 | ~QAbstractTexture(); |
246 | |
247 | Target target() const; |
248 | |
249 | TextureFormat format() const; |
250 | bool generateMipMaps() const; |
251 | |
252 | Status status() const; |
253 | |
254 | void addTextureImage(QAbstractTextureImage *textureImage); |
255 | void removeTextureImage(QAbstractTextureImage *textureImage); |
256 | QList<QAbstractTextureImage *> textureImages() const; |
257 | |
258 | // sampler data - in the future proxy to a Sampler helper |
259 | void setWrapMode(const QTextureWrapMode &wrapMode); |
260 | QTextureWrapMode *wrapMode(); |
261 | |
262 | void setSize(int width, int height=1, int depth=1); |
263 | |
264 | Filter minificationFilter() const; |
265 | Filter magnificationFilter() const; |
266 | float maximumAnisotropy() const; |
267 | ComparisonFunction comparisonFunction() const; |
268 | ComparisonMode comparisonMode() const; |
269 | int width() const; |
270 | int height() const; |
271 | int depth() const; |
272 | int layers() const; |
273 | int samples() const; |
274 | int mipLevels() const; |
275 | HandleType handleType() const; |
276 | QVariant handle() const; |
277 | |
278 | Q_INVOKABLE void updateData(const QTextureDataUpdate &update); |
279 | |
280 | |
281 | public Q_SLOTS: |
282 | void setFormat(TextureFormat format); |
283 | void setGenerateMipMaps(bool gen); |
284 | void setWidth(int width); |
285 | void setHeight(int height); |
286 | void setDepth(int depth); |
287 | void setMinificationFilter(Filter f); |
288 | void setMagnificationFilter(Filter f); |
289 | void setMaximumAnisotropy(float anisotropy); |
290 | void setComparisonFunction(ComparisonFunction function); |
291 | void setComparisonMode(ComparisonMode mode); |
292 | void setLayers(int layers); |
293 | void setSamples(int samples); |
294 | void setMipLevels(int mipLevels); |
295 | |
296 | Q_SIGNALS: |
297 | void formatChanged(TextureFormat format); |
298 | void statusChanged(Status status); |
299 | void generateMipMapsChanged(bool generateMipMaps); |
300 | void widthChanged(int width); |
301 | void heightChanged(int height); |
302 | void depthChanged(int depth); |
303 | void magnificationFilterChanged(Filter magnificationFilter); |
304 | void minificationFilterChanged(Filter minificationFilter); |
305 | void maximumAnisotropyChanged(float maximumAnisotropy); |
306 | void comparisonFunctionChanged(ComparisonFunction comparisonFunction); |
307 | void comparisonModeChanged(ComparisonMode comparisonMode); |
308 | void layersChanged(int layers); |
309 | void samplesChanged(int samples); |
310 | Q_REVISION(13) void handleTypeChanged(HandleType handleType); |
311 | Q_REVISION(13) void handleChanged(QVariant handle); |
312 | void mipLevelsChanged(int mipLevels); |
313 | |
314 | protected: |
315 | explicit QAbstractTexture(Qt3DCore::QNode *parent = nullptr); |
316 | explicit QAbstractTexture(Target target, Qt3DCore::QNode *parent = nullptr); |
317 | explicit QAbstractTexture(QAbstractTexturePrivate &dd, Qt3DCore::QNode *parent = nullptr); |
318 | |
319 | // TO DO Qt6, should be on private class |
320 | void setStatus(Status status); |
321 | void setHandle(const QVariant &handle); |
322 | void setHandleType(HandleType type); |
323 | |
324 | private: |
325 | Q_DECLARE_PRIVATE(QAbstractTexture) |
326 | }; |
327 | |
328 | } // namespace Qt3DRender |
329 | |
330 | QT_END_NAMESPACE |
331 | |
332 | Q_DECLARE_METATYPE(Qt3DRender::QAbstractTexture *) // LCOV_EXCL_LINE |
333 | |
334 | #endif // QT3DRENDER_QABSTRACTTEXTURE_H |
335 | |