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 | #include "qabstracttexture.h" |
5 | #include "qabstracttexture_p.h" |
6 | #include <Qt3DRender/qabstracttextureimage.h> |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | |
11 | namespace Qt3DRender { |
12 | |
13 | using namespace Qt3DCore; |
14 | |
15 | QAbstractTexturePrivate::QAbstractTexturePrivate() |
16 | : QNodePrivate() |
17 | , m_target(QAbstractTexture::Target2D) |
18 | , m_format(QAbstractTexture::Automatic) |
19 | , m_width(1) |
20 | , m_height(1) |
21 | , m_depth(1) |
22 | , m_autoMipMap(false) |
23 | , m_minFilter(QAbstractTexture::Nearest) |
24 | , m_magFilter(QAbstractTexture::Nearest) |
25 | , m_status(QAbstractTexture::None) |
26 | , m_maximumAnisotropy(1.0f) |
27 | , m_comparisonFunction(QAbstractTexture::CompareLessEqual) |
28 | , m_comparisonMode(QAbstractTexture::CompareNone) |
29 | , m_layers(1) |
30 | , m_samples(1) |
31 | , m_mipmapLevels(1) |
32 | , m_sharedTextureId(-1) |
33 | , m_handleType(QAbstractTexture::NoHandle) |
34 | , m_handle(QVariant()) |
35 | { |
36 | } |
37 | |
38 | QTextureGeneratorPtr QAbstractTexturePrivate::dataFunctor() const |
39 | { |
40 | return m_dataFunctor; |
41 | } |
42 | |
43 | void QAbstractTexturePrivate::setDataFunctor(const QTextureGeneratorPtr &generator) |
44 | { |
45 | if (generator != m_dataFunctor) { |
46 | m_dataFunctor = generator; |
47 | update(); |
48 | } |
49 | } |
50 | |
51 | void QAbstractTexturePrivate::setStatus(QAbstractTexture::Status status) |
52 | { |
53 | Q_Q(QAbstractTexture); |
54 | if (m_status != status) { |
55 | m_status = status; |
56 | const bool blocked = q->blockNotifications(block: true); |
57 | q->statusChanged(status); |
58 | q->blockNotifications(block: blocked); |
59 | } |
60 | } |
61 | |
62 | void QAbstractTexturePrivate::setHandle(const QVariant &handle) |
63 | { |
64 | Q_Q(QAbstractTexture); |
65 | if (m_handle != handle) { |
66 | m_handle = handle; |
67 | const bool blocked = q->blockNotifications(block: true); |
68 | emit q->handleChanged(handle); |
69 | q->blockNotifications(block: blocked); |
70 | } |
71 | } |
72 | |
73 | void QAbstractTexturePrivate::setHandleType(QAbstractTexture::HandleType type) |
74 | { |
75 | Q_Q(QAbstractTexture); |
76 | if (m_handleType != type) { |
77 | m_handleType = type; |
78 | const bool blocked = q->blockNotifications(block: true); |
79 | emit q->handleTypeChanged(handleType: type); |
80 | q->blockNotifications(block: blocked); |
81 | } |
82 | } |
83 | |
84 | /*! |
85 | \class Qt3DRender::QAbstractTexture |
86 | \inmodule Qt3DRender |
87 | \since 5.5 |
88 | \brief A base class to be used to provide textures. |
89 | |
90 | The QAbstractTexture class shouldn't be used directly but rather through |
91 | one of its subclasses. Each subclass implements a given texture target (2D, |
92 | 2DArray, 3D, CubeMap ...) Each subclass provides a set of functors for each |
93 | layer, cube map face and mipmap level. In turn the backend uses those |
94 | functor to properly fill a corresponding OpenGL texture with data. It is |
95 | expected the functor does as minimal processing as possible so as not |
96 | to slow down textures generation and upload. If the content of a texture is |
97 | the result of a slow procedural generation process, it is recommended not |
98 | to implement this directly in a functor. |
99 | |
100 | All textures are unique. If you instantiate twice the same texture this |
101 | will create 2 identical textures on the GPU, no sharing will take place. |
102 | */ |
103 | |
104 | /*! |
105 | \qmltype AbstractTexture |
106 | \nativetype Qt3DRender::QAbstractTexture |
107 | \inqmlmodule Qt3D.Render |
108 | \since 5.5 |
109 | \brief A base class to be used to provide textures. |
110 | |
111 | The AbstractTexture class shouldn't be used directly but rather through one |
112 | of its subclasses. Each subclass implements a given texture target (2D, |
113 | 2DArray, 3D, CubeMap ...) Each subclass provides a set of functors for each |
114 | layer, cube map face and mipmap level. In turn the backend uses those |
115 | functor to properly fill a corresponding OpenGL texture with data. It is |
116 | expected the functor does as minimal processing as possible so as not to |
117 | slow down textures generation and upload. If the content of a texture is |
118 | the result of a slow procedural generation process, it is recommended not |
119 | to implement this directly in a functor. |
120 | |
121 | All textures are unique. If you instantiate twice the same texture this |
122 | will create 2 identical textures on the GPU, no sharing will take place. |
123 | */ |
124 | |
125 | /*! |
126 | \enum Qt3DRender::QAbstractTexture::CubeMapFace |
127 | |
128 | This enum identifies the faces of a cube map texture |
129 | \value CubeMapPositiveX Specify the positive X face of a cube map |
130 | \value CubeMapNegativeX Specify the negative X face of a cube map |
131 | \value CubeMapPositiveY Specify the positive Y face of a cube map |
132 | \value CubeMapNegativeY Specify the negative Y face of a cube map |
133 | \value CubeMapPositiveZ Specify the positive Z face of a cube map |
134 | \value CubeMapNegativeZ Specify the negative Z face of a cube map |
135 | \value AllFaces Specify all the faces of a cube map |
136 | |
137 | \note AllFaces should only be used when a behavior needs to be applied to |
138 | all the faces of a cubemap. This is the case for example when using a cube |
139 | map as a texture attachment. Using AllFaces in the attachment specfication |
140 | would result in all faces being bound to the attachment point. On the other |
141 | hand, if a specific face is specified, the attachment would only be using |
142 | the specified face. |
143 | */ |
144 | |
145 | /*! |
146 | \enum Qt3DRender::QAbstractTexture::TextureFormat |
147 | |
148 | This list describes all possible texture formats |
149 | |
150 | \value NoFormat |
151 | GL_NONE |
152 | \value Automatic |
153 | automatically_determines_format |
154 | \value R8_UNorm |
155 | GL_R8 |
156 | \value RG8_UNorm |
157 | GL_RG8 |
158 | \value RGB8_UNorm |
159 | GL_RGB8 |
160 | \value RGBA8_UNorm |
161 | GL_RGBA8 |
162 | \value R16_UNorm |
163 | GL_R16 |
164 | \value RG16_UNorm |
165 | GL_RG16 |
166 | \value RGB16_UNorm |
167 | GL_RGB16 |
168 | \value RGBA16_UNorm |
169 | GL_RGBA16 |
170 | \value R8_SNorm |
171 | GL_R8_SNORM |
172 | \value RG8_SNorm |
173 | GL_RG8_SNORM |
174 | \value RGB8_SNorm |
175 | GL_RGB8_SNORM |
176 | \value RGBA8_SNorm |
177 | GL_RGBA8_SNORM |
178 | \value R16_SNorm |
179 | GL_R16_SNORM |
180 | \value RG16_SNorm |
181 | GL_RG16_SNORM |
182 | \value RGB16_SNorm |
183 | GL_RGB16_SNORM |
184 | \value RGBA16_SNorm |
185 | GL_RGBA16_SNORM |
186 | \value R8U |
187 | GL_R8UI |
188 | \value RG8U |
189 | GL_RG8UI |
190 | \value RGB8U |
191 | GL_RGB8UI |
192 | \value RGBA8U |
193 | GL_RGBA8UI |
194 | \value R16U |
195 | GL_R16UI |
196 | \value RG16U |
197 | GL_RG16UI |
198 | \value RGB16U |
199 | GL_RGB16UI |
200 | \value RGBA16U |
201 | GL_RGBA16UI |
202 | \value R32U |
203 | GL_R32UI |
204 | \value RG32U |
205 | GL_RG32UI |
206 | \value RGB32U |
207 | GL_RGB32UI |
208 | \value RGBA32U |
209 | GL_RGBA32UI |
210 | \value R8I |
211 | GL_R8I |
212 | \value RG8I |
213 | GL_RG8I |
214 | \value RGB8I |
215 | GL_RGB8I |
216 | \value RGBA8I |
217 | GL_RGBA8I |
218 | \value R16I |
219 | GL_R16I |
220 | \value RG16I |
221 | GL_RG16I |
222 | \value RGB16I |
223 | GL_RGB16I |
224 | \value RGBA16I |
225 | GL_RGBA16I |
226 | \value R32I |
227 | GL_R32I |
228 | \value RG32I |
229 | GL_RG32I |
230 | \value RGB32I |
231 | GL_RGB32I |
232 | \value RGBA32I |
233 | GL_RGBA32I |
234 | \value R16F |
235 | GL_R16F |
236 | \value RG16F |
237 | GL_RG16F |
238 | \value RGB16F |
239 | GL_RGB16F |
240 | \value RGBA16F |
241 | GL_RGBA16F |
242 | \value R32F |
243 | GL_R32F |
244 | \value RG32F |
245 | GL_RG32F |
246 | \value RGB32F |
247 | GL_RGB32F |
248 | \value RGBA32F |
249 | GL_RGBA32F |
250 | \value RGB9E5 |
251 | GL_RGB9_E5 |
252 | \value RG11B10F |
253 | GL_R11F_G11F_B10F |
254 | \value RG3B2 |
255 | GL_R3_G3_B2 |
256 | \value R5G6B5 |
257 | GL_RGB565 |
258 | \value RGB5A1 |
259 | GL_RGB5_A1 |
260 | \value RGBA4 |
261 | GL_RGBA4 |
262 | \value RGB10A2 |
263 | GL_RGB10_A2 |
264 | \value RGB10A2U |
265 | GL_RGB10_A2UI |
266 | \value D16 |
267 | GL_DEPTH_COMPONENT16 |
268 | \value D24 |
269 | GL_DEPTH_COMPONENT24 |
270 | \value D24S8 |
271 | GL_DEPTH24_STENCIL8 |
272 | \value D32 |
273 | GL_DEPTH_COMPONENT32 |
274 | \value D32F |
275 | GL_DEPTH_COMPONENT32F |
276 | \value D32FS8X24 |
277 | GL_DEPTH32F_STENCIL8 |
278 | \value RGB_DXT1 |
279 | GL_COMPRESSED_RGB_S3TC_DXT1_EXT |
280 | \value RGBA_DXT1 |
281 | GL_COMPRESSED_RGBA_S3TC_DXT1_EXT |
282 | \value RGBA_DXT3 |
283 | GL_COMPRESSED_RGBA_S3TC_DXT3_EXT |
284 | \value RGBA_DXT5 |
285 | GL_COMPRESSED_RGBA_S3TC_DXT5_EXT |
286 | \value R_ATI1N_UNorm |
287 | GL_COMPRESSED_RED_RGTC1 |
288 | \value R_ATI1N_SNorm |
289 | GL_COMPRESSED_SIGNED_RED_RGTC1 |
290 | \value RG_ATI2N_UNorm |
291 | GL_COMPRESSED_RG_RGTC2 |
292 | \value RG_ATI2N_SNorm |
293 | GL_COMPRESSED_SIGNED_RG_RGTC2 |
294 | \value RGB_BP_UNSIGNED_FLOAT |
295 | GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB |
296 | \value RGB_BP_SIGNED_FLOAT |
297 | GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB |
298 | \value RGB_BP_UNorm |
299 | GL_COMPRESSED_RGBA_BPTC_UNORM_ARB |
300 | \value R11_EAC_UNorm |
301 | GL_COMPRESSED_R11_EAC |
302 | \value R11_EAC_SNorm |
303 | GL_COMPRESSED_SIGNED_R11_EAC |
304 | \value RG11_EAC_UNorm |
305 | GL_COMPRESSED_RG11_EAC |
306 | \value RG11_EAC_SNorm |
307 | GL_COMPRESSED_SIGNED_RG11_EAC |
308 | \value RGB8_ETC2 |
309 | GL_COMPRESSED_RGB8_ETC2 |
310 | \value SRGB8_ETC2 |
311 | GL_COMPRESSED_SRGB8_ETC2 |
312 | \value RGB8_PunchThrough_Alpha1_ETC2 |
313 | GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 |
314 | \value SRGB8_PunchThrough_Alpha1_ETC2 |
315 | GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 |
316 | \value RGBA8_ETC2_EAC |
317 | GL_COMPRESSED_RGBA8_ETC2_EAC |
318 | \value SRGB8_Alpha8_ETC2_EAC |
319 | GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC |
320 | \value RGB8_ETC1 |
321 | GL_ETC1_RGB8_OES |
322 | \value SRGB8 |
323 | GL_SRGB8 |
324 | \value SRGB8_Alpha8 |
325 | GL_SRGB8_ALPHA8 |
326 | \value SRGB_DXT1 |
327 | GL_COMPRESSED_SRGB_S3TC_DXT1_EXT |
328 | \value SRGB_Alpha_DXT1 |
329 | GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT |
330 | \value SRGB_Alpha_DXT3 |
331 | GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT |
332 | \value SRGB_Alpha_DXT5 |
333 | GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT |
334 | \value SRGB_BP_UNorm |
335 | GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB |
336 | \value DepthFormat |
337 | GL_DEPTH_COMPONENT |
338 | \value AlphaFormat |
339 | GL_ALPHA |
340 | \value RGBFormat |
341 | GL_RGB |
342 | \value RGBAFormat |
343 | GL_RGBA |
344 | \value LuminanceFormat |
345 | GL_LUMINANCE |
346 | \value LuminanceAlphaFormat |
347 | 0x190A |
348 | */ |
349 | |
350 | /*! |
351 | * The constructor creates a new QAbstractTexture::QAbstractTexture |
352 | * instance with the specified \a parent. |
353 | */ |
354 | QAbstractTexture::QAbstractTexture(QNode *parent) |
355 | : QNode(*new QAbstractTexturePrivate, parent) |
356 | { |
357 | } |
358 | |
359 | /*! |
360 | * The constructor creates a new QAbstractTexture::QAbstractTexture |
361 | * instance with the specified \a target and \a parent. |
362 | */ |
363 | QAbstractTexture::QAbstractTexture(Target target, QNode *parent) |
364 | : QNode(*new QAbstractTexturePrivate, parent) |
365 | { |
366 | d_func()->m_target = target; |
367 | } |
368 | |
369 | /*! \internal */ |
370 | QAbstractTexture::~QAbstractTexture() |
371 | { |
372 | } |
373 | |
374 | /*! \internal */ |
375 | QAbstractTexture::QAbstractTexture(QAbstractTexturePrivate &dd, QNode *parent) |
376 | : QNode(dd, parent) |
377 | { |
378 | } |
379 | |
380 | /*! |
381 | Sets the size of the texture provider to width \a w, height \a h and depth \a d. |
382 | */ |
383 | void QAbstractTexture::setSize(int w, int h, int d) |
384 | { |
385 | setWidth(w); |
386 | setHeight(h); |
387 | setDepth(d); |
388 | } |
389 | |
390 | /*! |
391 | \property Qt3DRender::QAbstractTexture::width |
392 | |
393 | Holds the width of the texture provider. |
394 | */ |
395 | /*! |
396 | \qmlproperty int Qt3D.Render::AbstractTexture::width |
397 | |
398 | Holds the width of the texture provider. |
399 | */ |
400 | |
401 | /*! |
402 | Set the width of the texture provider to \a width. |
403 | */ |
404 | void QAbstractTexture::setWidth(int width) |
405 | { |
406 | Q_D(QAbstractTexture); |
407 | if (d->m_width != width) { |
408 | d->m_width = width; |
409 | emit widthChanged(width); |
410 | } |
411 | } |
412 | |
413 | /*! |
414 | \property Qt3DRender::QAbstractTexture::height |
415 | |
416 | Holds the height of the texture provider. |
417 | */ |
418 | /*! |
419 | \qmlproperty int Qt3D.Render::AbstractTexture::height |
420 | |
421 | Holds the height of the texture provider. |
422 | */ |
423 | /*! |
424 | Set the height to \a height. |
425 | */ |
426 | void QAbstractTexture::setHeight(int height) |
427 | { |
428 | Q_D(QAbstractTexture); |
429 | if (d->m_height != height) { |
430 | d->m_height = height; |
431 | emit heightChanged(height); |
432 | } |
433 | } |
434 | |
435 | /*! |
436 | \property Qt3DRender::QAbstractTexture::depth |
437 | |
438 | Holds the depth of the texture provider. |
439 | */ |
440 | /*! |
441 | \qmlproperty int Qt3D.Render::AbstractTexture::depth |
442 | |
443 | Holds the depth of the texture provider. |
444 | */ |
445 | /*! |
446 | Set the depth of the texture to \a depth. |
447 | */ |
448 | void QAbstractTexture::setDepth(int depth) |
449 | { |
450 | Q_D(QAbstractTexture); |
451 | if (d->m_depth != depth) { |
452 | d->m_depth = depth; |
453 | emit depthChanged(depth); |
454 | } |
455 | } |
456 | |
457 | /*! |
458 | * Returns the width of the texture |
459 | */ |
460 | int QAbstractTexture::width() const |
461 | { |
462 | Q_D(const QAbstractTexture); |
463 | return d->m_width; |
464 | } |
465 | |
466 | /*! |
467 | * Returns the height of the texture |
468 | */ |
469 | int QAbstractTexture::height() const |
470 | { |
471 | Q_D(const QAbstractTexture); |
472 | return d->m_height; |
473 | } |
474 | |
475 | /*! |
476 | * Returns the depth of the texture |
477 | */ |
478 | int QAbstractTexture::depth() const |
479 | { |
480 | Q_D(const QAbstractTexture); |
481 | return d->m_depth; |
482 | } |
483 | |
484 | /*! |
485 | \property Qt3DRender::QAbstractTexture::layers |
486 | |
487 | Holds the maximum layer count of the texture provider. By default, the |
488 | maximum layer count is 1. |
489 | |
490 | \note this has a meaning only for texture providers that have 3D or |
491 | array target formats. |
492 | */ |
493 | /*! |
494 | \qmlproperty int Qt3D.Render::AbstractTexture::layers |
495 | |
496 | Holds the maximum layer count of the texture provider. By default, the |
497 | maximum layer count is 1. |
498 | |
499 | \note this has a meaning only for texture providers that have 3D or |
500 | array target formats. |
501 | */ |
502 | /*! |
503 | Set the maximum layer count to \a layers. |
504 | */ |
505 | void QAbstractTexture::setLayers(int layers) |
506 | { |
507 | Q_D(QAbstractTexture); |
508 | if (d->m_layers != layers) { |
509 | d->m_layers = layers; |
510 | emit layersChanged(layers); |
511 | } |
512 | } |
513 | |
514 | /*! |
515 | Returns the maximum number of layers for the texture provider. |
516 | |
517 | \note this has a meaning only for texture providers that have 3D or |
518 | array target formats. |
519 | */ |
520 | int QAbstractTexture::layers() const |
521 | { |
522 | Q_D(const QAbstractTexture); |
523 | return d->m_layers; |
524 | } |
525 | |
526 | /*! |
527 | \property Qt3DRender::QAbstractTexture::samples |
528 | |
529 | Holds the number of samples per texel for the texture provider. |
530 | By default, the number of samples is 1. |
531 | |
532 | \note this has a meaning only for texture providers that have multisample |
533 | formats. |
534 | */ |
535 | /*! |
536 | \qmlproperty int Qt3D.Render::AbstractTexture::samples |
537 | |
538 | Holds the number of samples per texel for the texture provider. |
539 | By default, the number of samples is 1. |
540 | |
541 | \note this has a meaning only for texture providers that have multisample |
542 | formats. |
543 | */ |
544 | /*! |
545 | Set the number of samples per texel to \a samples. |
546 | */ |
547 | void QAbstractTexture::setSamples(int samples) |
548 | { |
549 | Q_D(QAbstractTexture); |
550 | if (d->m_samples != samples) { |
551 | d->m_samples = samples; |
552 | emit samplesChanged(samples); |
553 | } |
554 | } |
555 | |
556 | void QAbstractTexture::setMipLevels(int mipLevels) |
557 | { |
558 | Q_D(QAbstractTexture); |
559 | if (d->m_mipmapLevels != mipLevels) { |
560 | d->m_mipmapLevels = mipLevels; |
561 | emit mipLevelsChanged(mipLevels); |
562 | } |
563 | } |
564 | |
565 | /*! |
566 | Returns the number of samples per texel for the texture provider. |
567 | |
568 | \note this has a meaning only for texture providers that have multisample |
569 | formats. |
570 | */ |
571 | int QAbstractTexture::samples() const |
572 | { |
573 | Q_D(const QAbstractTexture); |
574 | return d->m_samples; |
575 | } |
576 | |
577 | /*! |
578 | \property Qt3DRender::QAbstractTexture::mipLevels |
579 | |
580 | Holds the mipmap levels of the texture provider. |
581 | */ |
582 | int QAbstractTexture::mipLevels() const |
583 | { |
584 | Q_D(const QAbstractTexture); |
585 | return d->m_mipmapLevels; |
586 | } |
587 | |
588 | /*! |
589 | \property Qt3DRender::QAbstractTexture::format |
590 | |
591 | Holds the format of the texture provider. |
592 | */ |
593 | /*! |
594 | \qmlproperty TextureFormat Qt3D.Render::AbstractTexture::format |
595 | |
596 | Holds the format of the texture provider. |
597 | */ |
598 | /*! |
599 | Set the texture format to \a format. |
600 | */ |
601 | void QAbstractTexture::setFormat(TextureFormat format) |
602 | { |
603 | Q_D(QAbstractTexture); |
604 | if (d->m_format != format) { |
605 | d->m_format = format; |
606 | emit formatChanged(format); |
607 | } |
608 | } |
609 | |
610 | /*! |
611 | Returns the texture provider's format. |
612 | */ |
613 | QAbstractTexture::TextureFormat QAbstractTexture::format() const |
614 | { |
615 | Q_D(const QAbstractTexture); |
616 | return d->m_format; |
617 | } |
618 | |
619 | /*! |
620 | \property Qt3DRender::QAbstractTexture::status readonly |
621 | |
622 | Holds the current status of the texture provider. |
623 | */ |
624 | /*! |
625 | \qmlproperty Status Qt3D.Render::AbstractTexture::status readonly |
626 | |
627 | Holds the current status of the texture provider. |
628 | */ |
629 | |
630 | /*! |
631 | \enum Qt3DRender::QAbstractTexture::Status |
632 | |
633 | Contains the status of the texture provider. |
634 | |
635 | \value None |
636 | \value Loading |
637 | \value Ready |
638 | \value Error |
639 | */ |
640 | /*! |
641 | Set the status of the texture provider to the specified \a status. |
642 | */ |
643 | void QAbstractTexture::setStatus(Status status) |
644 | { |
645 | Q_D(QAbstractTexture); |
646 | if (status != d->m_status) { |
647 | d->m_status = status; |
648 | const bool blocked = blockNotifications(block: true); |
649 | emit statusChanged(status); |
650 | blockNotifications(block: blocked); |
651 | } |
652 | } |
653 | |
654 | /*! |
655 | * \internal |
656 | */ |
657 | void QAbstractTexture::setHandle(const QVariant &handle) |
658 | { |
659 | Q_D(QAbstractTexture); |
660 | if (d->m_handle != handle) { |
661 | d->m_handle = handle; |
662 | const bool blocked = blockNotifications(block: true); |
663 | emit handleChanged(handle); |
664 | blockNotifications(block: blocked); |
665 | } |
666 | } |
667 | |
668 | /*! |
669 | * \internal |
670 | */ |
671 | void QAbstractTexture::setHandleType(QAbstractTexture::HandleType type) |
672 | { |
673 | Q_D(QAbstractTexture); |
674 | if (d->m_handleType != type) { |
675 | d->m_handleType = type; |
676 | const bool blocked = blockNotifications(block: true); |
677 | emit handleTypeChanged(handleType: type); |
678 | blockNotifications(block: blocked); |
679 | } |
680 | } |
681 | |
682 | /*! |
683 | * Returns the current status of the texture provider. |
684 | */ |
685 | QAbstractTexture::Status QAbstractTexture::status() const |
686 | { |
687 | Q_D(const QAbstractTexture); |
688 | return d->m_status; |
689 | } |
690 | |
691 | /*! |
692 | \property Qt3DRender::QAbstractTexture::target readonly |
693 | |
694 | Holds the target format of the texture provider. |
695 | |
696 | \note The target format can only be set once. |
697 | */ |
698 | /*! |
699 | \qmlproperty Target Qt3D.Render::AbstractTexture::target readonly |
700 | |
701 | Holds the target format of the texture provider. |
702 | |
703 | \note The target format can only be set once. |
704 | */ |
705 | /*! |
706 | \enum Qt3DRender::QAbstractTexture::Target |
707 | |
708 | \value TargetAutomatic |
709 | Target will be determined by the Qt3D engine |
710 | \value Target1D |
711 | GL_TEXTURE_1D |
712 | \value Target1DArray |
713 | GL_TEXTURE_1D_ARRAY |
714 | \value Target2D |
715 | GL_TEXTURE_2D |
716 | \value Target2DArray |
717 | GL_TEXTURE_2D_ARRAY |
718 | \value Target3D |
719 | GL_TEXTURE_3D |
720 | \value TargetCubeMap |
721 | GL_TEXTURE_CUBE_MAP |
722 | \value TargetCubeMapArray |
723 | GL_TEXTURE_CUBE_MAP_ARRAY |
724 | \value Target2DMultisample |
725 | GL_TEXTURE_2D_MULTISAMPLE |
726 | \value Target2DMultisampleArray |
727 | GL_TEXTURE_2D_MULTISAMPLE_ARRAY |
728 | \value TargetRectangle |
729 | GL_TEXTURE_RECTANGLE |
730 | \value TargetBuffer |
731 | GL_TEXTURE_BUFFER |
732 | */ |
733 | |
734 | /*! |
735 | Returns the target format of the texture provider. |
736 | */ |
737 | QAbstractTexture::Target QAbstractTexture::target() const |
738 | { |
739 | Q_D(const QAbstractTexture); |
740 | return d->m_target; |
741 | } |
742 | |
743 | /*! |
744 | Adds a new Qt3DCore::QAbstractTextureImage \a textureImage to the texture provider. |
745 | |
746 | \note Qt3DRender::QAbstractTextureImage should never be shared between multiple |
747 | Qt3DRender::QAbstractTexture instances. |
748 | */ |
749 | void QAbstractTexture::addTextureImage(QAbstractTextureImage *textureImage) |
750 | { |
751 | Q_ASSERT(textureImage); |
752 | Q_D(QAbstractTexture); |
753 | if (!d->m_textureImages.contains(t: textureImage)) { |
754 | d->m_textureImages.append(t: textureImage); |
755 | |
756 | // Ensures proper bookkeeping |
757 | d->registerDestructionHelper(node: textureImage, func: &QAbstractTexture::removeTextureImage, d->m_textureImages); |
758 | |
759 | // We need to add it as a child of the current node if it has been declared inline |
760 | // Or not previously added as a child of the current node so that |
761 | // 1) The backend gets notified about it's creation |
762 | // 2) When the current node is destroyed, it gets destroyed as well |
763 | if (!textureImage->parent()) |
764 | textureImage->setParent(this); |
765 | |
766 | d->update(); |
767 | } |
768 | } |
769 | |
770 | /*! |
771 | Removes a Qt3DCore::QAbstractTextureImage \a textureImage from the texture provider. |
772 | */ |
773 | void QAbstractTexture::removeTextureImage(QAbstractTextureImage *textureImage) |
774 | { |
775 | Q_ASSERT(textureImage); |
776 | Q_D(QAbstractTexture); |
777 | if (!d->m_textureImages.removeOne(t: textureImage)) |
778 | return; |
779 | d->update(); |
780 | // Remove bookkeeping connection |
781 | d->unregisterDestructionHelper(node: textureImage); |
782 | } |
783 | |
784 | /*! |
785 | Returns a list of pointers to QAbstractTextureImage objects contained in |
786 | the texture provider. |
787 | */ |
788 | QList<QAbstractTextureImage *> QAbstractTexture::textureImages() const |
789 | { |
790 | Q_D(const QAbstractTexture); |
791 | return d->m_textureImages; |
792 | } |
793 | |
794 | /*! |
795 | \property Qt3DRender::QAbstractTexture::generateMipMaps |
796 | |
797 | Holds whether the texture provider should auto generate mipmaps. |
798 | */ |
799 | /*! |
800 | \qmlproperty bool Qt3D.Render::AbstractTexture::generateMipMaps |
801 | |
802 | Holds whether the texture provider should auto generate mipmaps. |
803 | */ |
804 | /*! |
805 | Boolean parameter \a gen sets a flag indicating whether the |
806 | texture provider should generate mipmaps or not. |
807 | */ |
808 | void QAbstractTexture::setGenerateMipMaps(bool gen) |
809 | { |
810 | Q_D(QAbstractTexture); |
811 | if (d->m_autoMipMap != gen) { |
812 | d->m_autoMipMap = gen; |
813 | emit generateMipMapsChanged(generateMipMaps: gen); |
814 | } |
815 | } |
816 | |
817 | bool QAbstractTexture::generateMipMaps() const |
818 | { |
819 | Q_D(const QAbstractTexture); |
820 | return d->m_autoMipMap; |
821 | } |
822 | |
823 | /*! |
824 | \property Qt3DRender::QAbstractTexture::minificationFilter |
825 | |
826 | Holds the minification filter of the texture provider. |
827 | */ |
828 | /*! |
829 | \qmlproperty Filter Qt3D.Render::AbstractTexture::minificationFilter |
830 | |
831 | Holds the minification filter of the texture provider. |
832 | */ |
833 | /*! |
834 | Set the minification filter to the specified value \a f. |
835 | */ |
836 | void QAbstractTexture::setMinificationFilter(Filter f) |
837 | { |
838 | Q_D(QAbstractTexture); |
839 | if (d->m_minFilter != f) { |
840 | d->m_minFilter = f; |
841 | emit minificationFilterChanged(minificationFilter: f); |
842 | } |
843 | } |
844 | /*! |
845 | \enum Qt3DRender::QAbstractTexture::Filter |
846 | |
847 | Holds the filter type of the texture provider. |
848 | |
849 | \value Nearest |
850 | GL_NEAREST |
851 | \value Linear |
852 | GL_LINEAR |
853 | \value NearestMipMapNearest |
854 | GL_NEAREST_MIPMAP_NEAREST |
855 | \value NearestMipMapLinear |
856 | GL_NEAREST_MIPMAP_LINEAR |
857 | \value LinearMipMapNearest |
858 | GL_LINEAR_MIPMAP_NEAREST |
859 | \value LinearMipMapLinear |
860 | GL_LINEAR_MIPMAP_LINEAR |
861 | */ |
862 | /*! |
863 | \property Qt3DRender::QAbstractTexture::magnificationFilter |
864 | |
865 | Holds the magnification filter of the texture provider. |
866 | */ |
867 | /*! |
868 | \qmlproperty Filter Qt3D.Render::AbstractTexture::magnificationFilter |
869 | |
870 | Holds the magnification filter of the texture provider. |
871 | */ |
872 | /*! |
873 | Set the magnification filter to \a f. |
874 | */ |
875 | void QAbstractTexture::setMagnificationFilter(Filter f) |
876 | { |
877 | Q_D(QAbstractTexture); |
878 | if (d->m_magFilter != f) { |
879 | d->m_magFilter = f; |
880 | emit magnificationFilterChanged(magnificationFilter: f); |
881 | } |
882 | } |
883 | |
884 | QAbstractTexture::Filter QAbstractTexture::minificationFilter() const |
885 | { |
886 | Q_D(const QAbstractTexture); |
887 | return d->m_minFilter; |
888 | } |
889 | |
890 | QAbstractTexture::Filter QAbstractTexture::magnificationFilter() const |
891 | { |
892 | Q_D(const QAbstractTexture); |
893 | return d->m_magFilter; |
894 | } |
895 | |
896 | /*! |
897 | \property Qt3DRender::QAbstractTexture::wrapMode |
898 | |
899 | Holds the wrap mode of the texture provider. |
900 | */ |
901 | /*! |
902 | \qmlproperty QTextureWrapMode Qt3D.Render::AbstractTexture::wrapMode |
903 | |
904 | Holds the wrap mode of the texture provider. |
905 | */ |
906 | /*! |
907 | Set the wrapmode to the value specified in \a wrapMode. |
908 | */ |
909 | void QAbstractTexture::setWrapMode(const QTextureWrapMode &wrapMode) |
910 | { |
911 | Q_D(QAbstractTexture); |
912 | if (d->m_wrapMode.x() != wrapMode.x()) { |
913 | d->m_wrapMode.setX(wrapMode.x()); |
914 | d->update(); |
915 | } |
916 | if (d->m_wrapMode.y() != wrapMode.y()) { |
917 | d->m_wrapMode.setY(wrapMode.y()); |
918 | d->update(); |
919 | } |
920 | if (d->m_wrapMode.z() != wrapMode.z()) { |
921 | d->m_wrapMode.setZ(wrapMode.z()); |
922 | d->update(); |
923 | } |
924 | } |
925 | |
926 | QTextureWrapMode *QAbstractTexture::wrapMode() |
927 | { |
928 | Q_D(QAbstractTexture); |
929 | return &d->m_wrapMode; |
930 | } |
931 | |
932 | /*! |
933 | \property Qt3DRender::QAbstractTexture::maximumAnisotropy |
934 | |
935 | Holds the maximum anisotropy of the texture provider. |
936 | */ |
937 | /*! |
938 | \qmlproperty bool Qt3D.Render::AbstractTexture::maximumAnisotropy |
939 | |
940 | Holds the maximum anisotropy of the texture provider. |
941 | */ |
942 | /*! |
943 | Sets the maximum anisotropy to \a anisotropy. |
944 | */ |
945 | void QAbstractTexture::setMaximumAnisotropy(float anisotropy) |
946 | { |
947 | Q_D(QAbstractTexture); |
948 | if (!qFuzzyCompare(p1: d->m_maximumAnisotropy, p2: anisotropy)) { |
949 | d->m_maximumAnisotropy = anisotropy; |
950 | emit maximumAnisotropyChanged(maximumAnisotropy: anisotropy); |
951 | } |
952 | } |
953 | |
954 | /*! |
955 | * Returns the current maximum anisotropy |
956 | */ |
957 | float QAbstractTexture::maximumAnisotropy() const |
958 | { |
959 | Q_D(const QAbstractTexture); |
960 | return d->m_maximumAnisotropy; |
961 | } |
962 | |
963 | /*! |
964 | \property Qt3DRender::QAbstractTexture::comparisonFunction |
965 | |
966 | Holds the comparison function of the texture provider. |
967 | */ |
968 | /*! |
969 | \qmlproperty ComparisonFunction Qt3D.Render::AbstractTexture::ComparisonFunction |
970 | |
971 | Holds the comparison function of the texture provider. |
972 | */ |
973 | /*! |
974 | Set the comparison function to \a function. |
975 | */ |
976 | void QAbstractTexture::setComparisonFunction(QAbstractTexture::ComparisonFunction function) |
977 | { |
978 | Q_D(QAbstractTexture); |
979 | if (d->m_comparisonFunction != function) { |
980 | d->m_comparisonFunction = function; |
981 | emit comparisonFunctionChanged(comparisonFunction: function); |
982 | } |
983 | } |
984 | |
985 | /*! |
986 | * Returns the current comparison function. |
987 | */ |
988 | QAbstractTexture::ComparisonFunction QAbstractTexture::comparisonFunction() const |
989 | { |
990 | Q_D(const QAbstractTexture); |
991 | return d->m_comparisonFunction; |
992 | } |
993 | |
994 | /*! |
995 | \property Qt3DRender::QAbstractTexture::comparisonMode |
996 | |
997 | Holds the comparison mode of the texture provider. |
998 | */ |
999 | |
1000 | /*! |
1001 | \qmlproperty ComparisonMode Qt3D.Render::AbstractTexture::ComparisonMode |
1002 | |
1003 | Holds the comparison mode of the texture provider. |
1004 | */ |
1005 | /*! |
1006 | Set the comparison mode to \a mode. |
1007 | */ |
1008 | void QAbstractTexture::setComparisonMode(QAbstractTexture::ComparisonMode mode) |
1009 | { |
1010 | Q_D(QAbstractTexture); |
1011 | if (d->m_comparisonMode != mode) { |
1012 | d->m_comparisonMode = mode; |
1013 | emit comparisonModeChanged(comparisonMode: mode); |
1014 | } |
1015 | } |
1016 | |
1017 | /*! |
1018 | * Returns the current comparison mode. |
1019 | */ |
1020 | QAbstractTexture::ComparisonMode QAbstractTexture::comparisonMode() const |
1021 | { |
1022 | Q_D(const QAbstractTexture); |
1023 | return d->m_comparisonMode; |
1024 | } |
1025 | |
1026 | /*! |
1027 | * \property Qt3DRender::QAbstractTexture::handleType |
1028 | * |
1029 | * Holds the current texture handle type. |
1030 | */ |
1031 | |
1032 | /*! |
1033 | * \qmlproperty enumeration AbstractTexture::handleType |
1034 | * |
1035 | * Holds the current texture handle type. |
1036 | * |
1037 | * \value AbstractTexture.NoHandle |
1038 | * \value AbstractTexture.OpenGLTextureId |
1039 | */ |
1040 | |
1041 | /*! |
1042 | * \return the current texture handle type. |
1043 | * \since 5.13 |
1044 | */ |
1045 | QAbstractTexture::HandleType QAbstractTexture::handleType() const |
1046 | { |
1047 | Q_D(const QAbstractTexture); |
1048 | return d->m_handleType; |
1049 | } |
1050 | |
1051 | /*! |
1052 | * \property Qt3DRender::QAbstractTexture::handle |
1053 | * |
1054 | * Holds the current texture handle, if Qt 3D is using the OpenGL renderer, |
1055 | * handle is a texture id integer. |
1056 | */ |
1057 | |
1058 | /*! |
1059 | * \qmlproperty var AbstractTexture::handle |
1060 | * |
1061 | * Holds the current texture handle, if Qt 3D is using the OpenGL renderer, |
1062 | * handle is a texture id integer. |
1063 | */ |
1064 | |
1065 | /*! |
1066 | * \return the current texture handle, if Qt 3D is using the OpenGL renderer, |
1067 | * handle is a texture id integer. |
1068 | * |
1069 | * \since 5.13 |
1070 | */ |
1071 | QVariant QAbstractTexture::handle() const |
1072 | { |
1073 | Q_D(const QAbstractTexture); |
1074 | return d->m_handle; |
1075 | } |
1076 | |
1077 | /*! |
1078 | * Updates a sub region of the texture, defined by \a update, without having |
1079 | * to change the data generator or rely on adding or removing texture images. |
1080 | * \since 5.14 |
1081 | */ |
1082 | void QAbstractTexture::updateData(const QTextureDataUpdate &update) |
1083 | { |
1084 | Q_D(QAbstractTexture); |
1085 | |
1086 | d->m_pendingDataUpdates.push_back(t: update); |
1087 | d->update(); |
1088 | } |
1089 | |
1090 | } // namespace Qt3DRender |
1091 | |
1092 | QT_END_NAMESPACE |
1093 | |
1094 | #include "moc_qabstracttexture.cpp" |
1095 | |