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

source code of qt3d/src/render/texture/qabstracttexture.cpp