1/****************************************************************************
2**
3** Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qshaderimage.h"
41#include "qshaderimage_p.h"
42#include <Qt3DRender/qabstracttexture.h>
43
44QT_BEGIN_NAMESPACE
45
46namespace Qt3DRender {
47
48QShaderImagePrivate::QShaderImagePrivate()
49 : Qt3DCore::QNodePrivate()
50 , m_texture(nullptr)
51 , m_mipLevel(0)
52 , m_layer(0)
53 , m_access(QShaderImage::ReadWrite)
54 , m_format(QShaderImage::Automatic)
55 , m_layered(false)
56{
57}
58
59QShaderImagePrivate::~QShaderImagePrivate()
60{
61}
62
63/*!
64 \qmltype ShaderImage
65 \instantiates Qt3DRender::QShaderImage
66 \inqmlmodule Qt3D.Render
67 \since 5.14
68 \brief Provides Image access to shader programs
69
70 To make the content of textures available for read and write operations in
71 a shader, they need to exposed as ShaderImage. Textures can be composed of
72 several mip levels, layers and faces. Additionally declaring a ShaderImage
73 allows specifying which level, layer or face of the texture content we want
74 to access.
75
76 ShaderImage has to be assigned as a Parameter's value and reference a valid
77 Qt3D.Render.AbstractTexture to work properly.
78
79 If the referenced texture is a one-dimensional array, two-dimensional array,
80 three-dimensional, cube map, cube map array, or two-dimensional multisample
81 array texture, it is possible to bind either the entire texture level or a
82 single layer or face of the texture level. This can be controlled with the
83 \l layered property.
84
85 Support for ShaderImage is only supported with OpenGL 4 and partially with
86 OpenGL ES 3.1 and 3.2.
87
88 OpenGL 4 supports the following image types:
89 \table
90 \header
91 \li GLSL Type
92 \li OpenGL Type Enum
93 \li Texture Type
94 \row
95 \li image1D
96 \li GL_IMAGE_1D
97 \li Texture1D
98 \row
99 \li image2D
100 \li GL_IMAGE_2D
101 \li Texture2D
102 \row
103 \li image3D
104 \li GL_IMAGE_3D
105 \li Texture3D
106 \row
107 \li image2DRect
108 \li GL_IMAGE_2D_RECT
109 \li TextureRectangle
110 \row
111 \li imageCube
112 \li GL_IMAGE_CUBE
113 \li TextureCubeMap
114 \row
115 \li imageBuffer
116 \li GL_IMAGE_BUFFER
117 \li TextureBuffer
118 \row
119 \li image1DArray
120 \li GL_IMAGE_1D_ARRAY
121 \li Texture1DArray
122 \row
123 \li image2DArray
124 \li GL_IMAGE_2D_ARRAY
125 \li Texture2DArray
126 \row
127 \li imageCubeArray
128 \li GL_IMAGE_CUBE_MAP_ARRAY
129 \li TextureCubeMapArray
130 \row
131 \li image2DMS
132 \li GL_IMAGE_2D_MULTISAMPLE
133 \li Texture2DMultisample
134 \row
135 \li image2DMSArray
136 \li GL_IMAGE_2D_MULTISAMPLE_ARRAY
137 \li Texture2DMultisampleArray
138 \row
139 \li iimage1D
140 \li GL_INT_IMAGE_1D
141 \li Texture1D
142 \row
143 \li iimage2D
144 \li GL_INT_IMAGE_2D
145 \li Texture2D
146 \row
147 \li iimage3D
148 \li GL_INT_IMAGE_3D
149 \li Texture3D
150 \row
151 \li iimage2DRect
152 \li GL_INT_IMAGE_2D_RECT
153 \li TextureRectangle
154 \row
155 \li iimageCube
156 \li GL_INT_IMAGE_CUBE
157 \li TextureCubeMap
158 \row
159 \li iimageBuffer
160 \li GL_INT_IMAGE_BUFFER
161 \li TextureBuffer
162 \row
163 \li iimage1DArray
164 \li GL_INT_IMAGE_1D_ARRAY
165 \li Texture1DArray
166 \row
167 \li iimage2DArray
168 \li GL_INT_IMAGE_2D_ARRAY
169 \li Texture2DArray
170 \row
171 \li iimageCubeArray
172 \li GL_INT_IMAGE_CUBE_MAP_ARRAY
173 \li TextureCubeMapArray
174 \row
175 \li iimage2DMS
176 \li GL_INT_IMAGE_2D_MULTISAMPLE
177 \li Texture2DMultisample
178 \row
179 \li iimage2DMSArray
180 \li GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY
181 \li Texture2DMultisampleArray
182 \row
183 \li uimage1D
184 \li GL_UNSIGNED_INT_IMAGE_1D
185 \li Texture1D
186 \row
187 \li uimage2D
188 \li GL_UNSIGNED_INT_IMAGE_2D
189 \li Texture2D
190 \row
191 \li uimage3D
192 \li GL_UNSIGNED_INT_IMAGE_3D
193 \li Texture3D
194 \row
195 \li uimage2DRect
196 \li GL_UNSIGNED_INT_IMAGE_2D_RECT
197 \li TextureRectangle
198 \row
199 \li uimageCube
200 \li GL_UNSIGNED_INT_IMAGE_CUBE
201 \li TextureCubeMap
202 \row
203 \li uimageBuffer
204 \li GL_UNSIGNED_INT_IMAGE_BUFFER
205 \li TextureBuffer
206 \row
207 \li uimage1DArray
208 \li GL_UNSIGNED_INT_IMAGE_1D_ARRAY
209 \li Texture1DArray
210 \row
211 \li uimage2DArray
212 \li GL_UNSIGNED_INT_IMAGE_2D_ARRAY
213 \li Texture2DArray
214 \row
215 \li uimageCubeArray
216 \li GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY
217 \li TextureCubeMapArray
218 \row
219 \li uimage2DMS
220 \li GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE
221 \li Texture2DMultisample
222 \row
223 \li uimage2DMSArray
224 \li GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY
225 \li Texture2DMultisampleArray
226 \endtable
227
228 OpenGL ES 3.1 supports the following image types:
229 \table
230 \header
231 \li GLSL Type
232 \li OpenGL Type Enum
233 \li Texture Type
234 \row
235 \li image2D
236 \li GL_IMAGE_2D
237 \li Texture2D
238 \row
239 \li image3D
240 \li GL_IMAGE_3D
241 \li Texture3D
242 \row
243 \li imageCube
244 \li GL_IMAGE_CUBE
245 \li TextureCubeMap
246 \row
247 \li image2DArray
248 \li GL_IMAGE_2D_ARRAY
249 \li Texture2DArray
250 \row
251 \li iimage2D
252 \li GL_INT_IMAGE_2D
253 \li Texture2D
254 \row
255 \li iimage3D
256 \li GL_INT_IMAGE_3D
257 \li Texture3D
258 \row
259 \li iimageCube
260 \li GL_INT_IMAGE_CUBE
261 \li TextureCubeMap
262 \row
263 \li iimage2DArray
264 \li GL_INT_IMAGE_2D_ARRAY
265 \li Texture2DArray
266 \row
267 \li uimage2D
268 \li GL_UNSIGNED_INT_IMAGE_2D
269 \li Texture2D
270 \row
271 \li uimage3D
272 \li GL_UNSIGNED_INT_IMAGE_3D
273 \li Texture3D
274 \row
275 \li uimageCube
276 \li GL_UNSIGNED_INT_IMAGE_CUBE
277 \li TextureCubeMap
278 \row
279 \li uimage2DArray
280 \li GL_UNSIGNED_INT_IMAGE_2D_ARRAY
281 \li Texture2DArray
282 \endtable
283
284 OpenGL ES 3.2 supports all of the OpenGL ES 3.1 image types as well as the
285 following:
286 \table
287 \header
288 \li GLSL Type
289 \li OpenGL Type Enum
290 \li Texture Type
291 \row
292 \li imageBuffer
293 \li GL_IMAGE_BUFFER
294 \li TextureBuffer
295 \row
296 \li imageCubeArray
297 \li GL_IMAGE_CUBE_MAP_ARRAY
298 \li TextureCubeMapArray
299 \row
300 \li iimageBuffer
301 \li GL_IMAGE_BUFFER
302 \li TextureBuffer
303 \row
304 \li iimageCubeArray
305 \li GL_INT_IMAGE_CUBE_MAP_ARRAY
306 \li TextureCubeMapArray
307 \row
308 \li uimageBuffer
309 \li GL_UNSIGNED_INT_IMAGE_BUFFER
310 \li TextureBuffer
311 \row
312 \li uimageCubeArray
313 \li GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY
314 \li TextureCubeMapArray
315 \endlist
316
317 Expected use would look like:
318
319 \badcode
320
321 import Qt3D.Render 2.14
322
323 Entity {
324 ...
325 Texture2D {
326 id: tex2D
327 ...
328 }
329
330 Material {
331 parameters: Parameter {
332 name: "imageUniformName"
333 value: ShaderImage {
334 texture: tex2D
335 }
336 }
337 ...
338 }
339 ...
340 }
341 \endcode
342 */
343
344/*!
345 \qmlproperty Qt3DRender::QShaderImage::mipLevel
346
347 Holds which mipLevel out of the referenced texture should be used for the
348 ShaderImage.
349
350 \default 0
351 */
352
353/*!
354 \qmlproperty Qt3DRender::QShaderImage::layer
355
356 Holds which layer out of the referenced texture should be used for the
357 ShaderImage. This property does nothing if \a layered is set to true or if
358 the reference texture's type isn't compatible with layers.
359
360 \note When the referenced texture is of type cube map or cube map array and
361 \a ─║ayered is set to false, the face and layer are retrieved in the
362 following manner:
363 \badcode
364 cubeMapLayer = layer / 6
365 cubeMapFace = layer - (cubeMapLayer * 6)
366 \endcode
367
368 \default 0
369 */
370
371/*!
372 * \qmlproperty Qt3DRender::QShaderImage::layered
373
374 If set to true, if the referenced texture is a one-dimensional array,
375 two-dimensional array, three-dimensional, cube map, cube map array, or
376 two-dimensional multisample array texture, the entire level will be bound
377 for all layers. If set to false, only the single layer specified by the \a
378 layer property will be bound.
379
380 \default false
381 */
382
383/*!
384 \qmlproperty Qt3DRender::QShaderImage::access
385
386 Specifies the type of access we want to allow from our shader instances to
387 the image. If a shader tries to write or read from an image that has
388 incompatible access, the behavior is undefined.
389
390 \default ShaderImage.ReadWrite
391 */
392
393/*!
394 \qmlproperty Qt3DRender::QShaderImage::format
395
396 Specifies the image format, which is essentially important when storing values
397 in the ShaderImage from a shader.
398
399 The format doesn't have to be the same as the referenced texture's format.
400 It however has to be compatible (matching in size but not necessarily by
401 class type). For instance a texture of format R32F (size 32bits, class
402 1x32) could be used with an image of format RGBA8I (size 32bits, class
403 4x8). Table 8.27 of the \l {OpenG specifications}
404 {https://www.khronos.org/registry/OpenGL/specs/gl/glspec45.core.pdf}
405 shows the size and class for all supported image formats.
406
407 By default Qt3D will try to set the image format to match that of the
408 referenced texture.
409
410 \default ShaderImage.Automatic
411 */
412
413/*!
414 \class Qt3DRender::QShaderImage
415 \inmodule Qt3DRender
416 \since 5.14
417 \brief Provides Image access to shader programs
418
419 To make the content of textures available for read and write operations in
420 a shader, they need to exposed as QShaderImage. Textures can be composed of
421 several mip levels, layers and faces. Additionally declaring a QShaderImage
422 allows specifying which level, layer or face of the texture content we want
423 to access.
424
425 QShaderImage has to be assigned as a QParameter's value and reference a valid
426 Qt3DRender::QAbstractTexture to work properly.
427
428 If the referenced texture is a one-dimensional array, two-dimensional array,
429 three-dimensional, cube map, cube map array, or two-dimensional multisample
430 array texture, it is possible to bind either the entire texture level or a
431 single layer or face of the texture level. This can be controlled with the
432 \l layered property.
433
434 Support for QShaderImage is only supported with OpenGL 4 and partially with
435 OpenGL ES 3.1 and 3.2.
436
437 OpenGL 4 supports the following image types:
438 \table
439 \header
440 \li GLSL Type
441 \li OpenGL Type Enum
442 \li Texture Type
443 \row
444 \li image1D
445 \li GL_IMAGE_1D
446 \li QTexture1D
447 \row
448 \li image2D
449 \li GL_IMAGE_2D
450 \li QTexture2D
451 \row
452 \li image3D
453 \li GL_IMAGE_3D
454 \li QTexture3D
455 \row
456 \li image2DRect
457 \li GL_IMAGE_2D_RECT
458 \li QTextureRectangle
459 \row
460 \li imageCube
461 \li GL_IMAGE_CUBE
462 \li QTextureCubeMap
463 \row
464 \li imageBuffer
465 \li GL_IMAGE_BUFFER
466 \li QTextureBuffer
467 \row
468 \li image1DArray
469 \li GL_IMAGE_1D_ARRAY
470 \li QTexture1DArray
471 \row
472 \li image2DArray
473 \li GL_IMAGE_2D_ARRAY
474 \li QTexture2DArray
475 \row
476 \li imageCubeArray
477 \li GL_IMAGE_CUBE_MAP_ARRAY
478 \li QTextureCubeMapArray
479 \row
480 \li image2DMS
481 \li GL_IMAGE_2D_MULTISAMPLE
482 \li QTexture2DMultisample
483 \row
484 \li image2DMSArray
485 \li GL_IMAGE_2D_MULTISAMPLE_ARRAY
486 \li QTexture2DMultisampleArray
487 \row
488 \li iimage1D
489 \li GL_INT_IMAGE_1D
490 \li QTexture1D
491 \row
492 \li iimage2D
493 \li GL_INT_IMAGE_2D
494 \li QTexture2D
495 \row
496 \li iimage3D
497 \li GL_INT_IMAGE_3D
498 \li QTexture3D
499 \row
500 \li iimage2DRect
501 \li GL_INT_IMAGE_2D_RECT
502 \li QTextureRectangle
503 \row
504 \li iimageCube
505 \li GL_INT_IMAGE_CUBE
506 \li QTextureCubeMap
507 \row
508 \li iimageBuffer
509 \li GL_INT_IMAGE_BUFFER
510 \li QTextureBuffer
511 \row
512 \li iimage1DArray
513 \li GL_INT_IMAGE_1D_ARRAY
514 \li QTexture1DArray
515 \row
516 \li iimage2DArray
517 \li GL_INT_IMAGE_2D_ARRAY
518 \li QTexture2DArray
519 \row
520 \li iimageCubeArray
521 \li GL_INT_IMAGE_CUBE_MAP_ARRAY
522 \li QTextureCubeMapArray
523 \row
524 \li iimage2DMS
525 \li GL_INT_IMAGE_2D_MULTISAMPLE
526 \li QTexture2DMultisample
527 \row
528 \li iimage2DMSArray
529 \li GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY
530 \li QTexture2DMultisampleArray
531 \row
532 \li uimage1D
533 \li GL_UNSIGNED_INT_IMAGE_1D
534 \li QTexture1D
535 \row
536 \li uimage2D
537 \li GL_UNSIGNED_INT_IMAGE_2D
538 \li QTexture2D
539 \row
540 \li uimage3D
541 \li GL_UNSIGNED_INT_IMAGE_3D
542 \li QTexture3D
543 \row
544 \li uimage2DRect
545 \li GL_UNSIGNED_INT_IMAGE_2D_RECT
546 \li QTextureRectangle
547 \row
548 \li uimageCube
549 \li GL_UNSIGNED_INT_IMAGE_CUBE
550 \li QTextureCubeMap
551 \row
552 \li uimageBuffer
553 \li GL_UNSIGNED_INT_IMAGE_BUFFER
554 \li QTextureBuffer
555 \row
556 \li uimage1DArray
557 \li GL_UNSIGNED_INT_IMAGE_1D_ARRAY
558 \li QTexture1DArray
559 \row
560 \li uimage2DArray
561 \li GL_UNSIGNED_INT_IMAGE_2D_ARRAY
562 \li QTexture2DArray
563 \row
564 \li uimageCubeArray
565 \li GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY
566 \li QTextureCubeMapArray
567 \row
568 \li uimage2DMS
569 \li GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE
570 \li QTexture2DMultisample
571 \row
572 \li uimage2DMSArray
573 \li GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY
574 \li QTexture2DMultisampleArray
575 \endtable
576
577 OpenGL ES 3.1 supports the following image types:
578 \table
579 \header
580 \li GLSL Type
581 \li OpenGL Type Enum
582 \li Texture Type
583 \row
584 \li image2D
585 \li GL_IMAGE_2D
586 \li QTexture2D
587 \row
588 \li image3D
589 \li GL_IMAGE_3D
590 \li QTexture3D
591 \row
592 \li imageCube
593 \li GL_IMAGE_CUBE
594 \li QTextureCubeMap
595 \row
596 \li image2DArray
597 \li GL_IMAGE_2D_ARRAY
598 \li QTexture2DArray
599 \row
600 \li iimage2D
601 \li GL_INT_IMAGE_2D
602 \li QTexture2D
603 \row
604 \li iimage3D
605 \li GL_INT_IMAGE_3D
606 \li QTexture3D
607 \row
608 \li iimageCube
609 \li GL_INT_IMAGE_CUBE
610 \li QTextureCubeMap
611 \row
612 \li iimage2DArray
613 \li GL_INT_IMAGE_2D_ARRAY
614 \li QTexture2DArray
615 \row
616 \li uimage2D
617 \li GL_UNSIGNED_INT_IMAGE_2D
618 \li QTexture2D
619 \row
620 \li uimage3D
621 \li GL_UNSIGNED_INT_IMAGE_3D
622 \li QTexture3D
623 \row
624 \li uimageCube
625 \li GL_UNSIGNED_INT_IMAGE_CUBE
626 \li QTextureCubeMap
627 \row
628 \li uimage2DArray
629 \li GL_UNSIGNED_INT_IMAGE_2D_ARRAY
630 \li QTexture2DArray
631 \endtable
632
633 OpenGL ES 3.2 supports all of the OpenGL ES 3.1 image types as well as the
634 following:
635 \table
636 \header
637 \li GLSL Type
638 \li OpenGL Type Enum
639 \li Texture Type
640 \row
641 \li imageBuffer
642 \li GL_IMAGE_BUFFER
643 \li QTextureBuffer
644 \row
645 \li imageCubeArray
646 \li GL_IMAGE_CUBE_MAP_ARRAY
647 \li QTextureCubeMapArray
648 \row
649 \li iimageBuffer
650 \li GL_IMAGE_BUFFER
651 \li QTextureBuffer
652 \row
653 \li iimageCubeArray
654 \li GL_INT_IMAGE_CUBE_MAP_ARRAY
655 \li QTextureCubeMapArray
656 \row
657 \li uimageBuffer
658 \li GL_UNSIGNED_INT_IMAGE_BUFFER
659 \li QTextureBuffer
660 \row
661 \li uimageCubeArray
662 \li GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY
663 \li QTextureCubeMapArray
664 \endtable
665
666 Expected use would look like:
667
668 \badcode
669 Qt3DRender::QTexture2D *tex2D = new Qt3DRender::QTexture2D();
670 ...
671 Qt3DRender::QMaterial *material = new Qt3DRender::QMaterial();
672 ...
673 Qt3DRender::QParameter *imageParameter = new Qt3DRender::QParameter();
674 Qt3DRender::QShaderImage *shaderImage = new Qt3DRender::QShaderImage();
675
676 shaderImage->setTexture(tex2D);
677
678 imageParameter->setName("imageUniformName");
679 imageParameter->setValue(QVariant::fromValue(shaderImage));
680
681 material->addParameter(imageParamenter);
682 \endcode
683 */
684
685/*!
686 \property Qt3DRender::QShaderImage::mipLevel
687
688 Holds which mipLevel out of the referenced texture should be used for the
689 QShaderImage.
690
691 \default 0
692 */
693
694/*!
695 \property Qt3DRender::QShaderImage::layer
696
697 Holds which layer out of the referenced texture should be used for the
698 QShaderImage. This property does nothing if \a layered is set to true or if the
699 reference texture's type isn't compatible with layers.
700
701 \note When the referenced texture is of type cube map or cube map array and
702 \a ─║ayered is set to false, the face and layer are retrieved in the
703 following manner:
704 \badcode
705 cubeMapLayer = layer / 6
706 cubeMapFace = layer - (cubeMapLayer * 6)
707 \endcode
708
709 \default 0
710 */
711
712/*!
713 * \property Qt3DRender::QShaderImage::layered
714
715 If set to true, if the referenced texture is a one-dimensional array,
716 two-dimensional array, three-dimensional, cube map, cube map array, or
717 two-dimensional multisample array texture, the entire level will be bound
718 for all layers. If set to false, only the single layer specified by the \a
719 layer property will be bound.
720
721 \default false
722 */
723
724/*!
725 \property Qt3DRender::QShaderImage::access
726
727 Specifies the type of access we want to allow from our shader instances to
728 the image. If a shader tries to write or read from an image that has
729 incompatible access, the behavior is undefined.
730
731 \defaut QShaderImage::ReadWrite
732 */
733
734/*!
735 \property Qt3DRender::QShaderImage::format
736
737 Specifies the image format, which is essentially important when storing values
738 in the Image from a shader.
739
740 The format doesn't have to be the same as the referenced texture's format.
741 It however has to be compatible (matching in size but not necessarily by
742 class type). For instance a texture of format R32F (size 32bits, class
743 1x32) could be used with an image of format RGBA8I (size 32bits, class
744 4x8). Table 8.27 of the \l {OpenG specifications}
745 {https://www.khronos.org/registry/OpenGL/specs/gl/glspec45.core.pdf}
746 shows the size and class for all supported Image formats.
747
748 By default Qt3D will try to set the image format to match that of the
749 referenced texture.
750
751 \default QShaderImage::Automatic
752 */
753
754/*!
755 \enum Qt3DRender::QShaderImage::Access
756
757 \value ReadOnly
758 Image will only be read from in shaders
759 \value WriteOnly
760 Image will only be written into from shaders
761 \value ReadWrite
762 Image will only be read and written into from shaders
763*/
764
765/*!
766 \enum Qt3DRender::QShaderImage::ImageFormat
767
768 This list describes all possible image formats
769
770 \value NoFormat
771 GL_NONE
772 \value Automatic
773 Qt 3D will try to determine the format automatically based on
774 the referenced texture.
775 \value R8_UNorm
776 GL_R8 (GLSL type r8, supported by OpenGL 4.2+)
777 \value RG8_UNorm
778 GL_RG8 (GLSL type rg8, supported by OpenGL 4.2+)
779 \value RGBA8_UNorm
780 GL_RGBA8 (GLSL type rgba8, supported by OpenGL 4.2+, OpenGL ES 3.1+)
781 \value R16_UNorm
782 GL_R16 (GLSL type r16, supported by OpenGL 4.2+)
783 \value RG16_UNorm
784 GL_RG16 (GLSL type rg16, supported by OpenGL 4.2+)
785 \value RGBA16_UNorm
786 GL_RGBA16 (GLSL type rgba16, supported by OpenGL 4.2+)
787 \value R8_SNorm
788 GL_R8_SNORM (GLSL type r8_snorm, supported by OpenGL 4.2+)
789 \value RG8_SNorm
790 GL_RG8_SNORM (GLSL type rg8_snorm, supported by OpenGL 4.2+)
791 \value RGBA8_SNorm
792 GL_RGBA8_SNORM (GLSL type rgba8_snorm, supported by OpenGL 4.2+, OpenGL ES 3.1+)
793 \value R16_SNorm
794 GL_R16_SNORM (GLSL type r16_snorm, supported by OpenGL 4.2+)
795 \value RG16_SNorm
796 GL_RG16_SNORM (GLSL type rg16_snorm, supported by OpenGL 4.2+)
797 \value RGBA16_SNorm
798 GL_RGBA16_SNORM (GLSL type rgba16_snorm, supported by OpenGL 4.2+)
799 \value R8U
800 GL_R8UI (GLSL type r8ui, supported by OpenGL 4.2+)
801 \value RG8U
802 GL_RG8UI (GLSL type rg8ui, supported by OpenGL 4.2+)
803 \value RGBA8U
804 GL_RGBA8UI (GLSL type rgba8ui, supported by OpenGL 4.2+, OpenGL ES 3.1+)
805 \value R16U
806 GL_R16UI (GLSL type r16ui, supported by OpenGL 4.2+)
807 \value RG16U
808 GL_RG16UI (GLSL type rg16ui, supported by OpenGL 4.2+)
809 \value RGBA16U
810 GL_RGBA16UI (GLSL type rgba16ui, supported by OpenGL 4.2+, OpenGL ES 3.1+)
811 \value R32U
812 GL_R32UI (GLSL type r32ui, supported by OpenGL 4.2+, OpenGL ES 3.1)
813 \value RG32U
814 GL_RG32UI (GLSL type rg32ui, supported by OpenGL 4.2+)
815 \value RGBA32U
816 GL_RGBA32UI (GLSL type rgba32ui, supported by OpenGL 4.2+, OpenGL ES 3.1+)
817 \value R8I
818 GL_R8I (GLSL type r8i, supported by OpenGL 4.2+)
819 \value RG8I
820 GL_RG8I (GLSL type rg8i, supported by OpenGL 4.2+)
821 \value RGBA8I
822 GL_RGBA8I (GLSL type rgba8i, supported by OpenGL 4.2+, OpenGL ES 3.1+)
823 \value R16I
824 GL_R16I (GLSL type r16i, supported by OpenGL 4.2+)
825 \value RG16I
826 GL_RG16I (GLSL type rg16i, supported by OpenGL 4.2+)
827 \value RGBA16I
828 GL_RGBA16I (GLSL type rgba16i, supported by OpenGL 4.2+, OpenGL ES 3.1)
829 \value R32I
830 GL_R32I (GLSL type r32i, supported by OpenGL 4.2+, OpenGL ES 3.1+)
831 \value RG32I
832 GL_RG32I (GLSL type rg32i, supported by OpenGL 4.2+)
833 \value RGBA32I
834 GL_RGBA32I (GLSL type rgba32i, supported by OpenGL 4.2+, OpenGL ES 3.1+)
835 \value R16F
836 GL_R16F (GLSL type r16f, supported by OpenGL 4.2+)
837 \value RG16F
838 GL_RG16F (GLSL type rg16f, supported by OpenGL 4.2+)
839 \value RGBA16F
840 GL_RGBA16F (GLSL type rgba16f, supported by OpenGL 4.2+, OpenGL ES 3.1+)
841 \value R32F
842 GL_R32F (GLSL type r32f, supported by OpenGL 4.2+, OpenGL ES 3.1+)
843 \value RG32F
844 GL_RG32F (GLSL type rg32f, supported by OpenGL 4.2+)
845 \value RGBA32F
846 GL_RGBA32F (GLSL type rgba32f, supported by OpenGL 4.2+, OpenGL ES 3.1+)
847 \value RG11B10F
848 GL_R11F_G11F_B10F (GLSL type r11f_g11f_b10f, supported by OpenGL 4.2+)
849 \value RGB10A2
850 GL_RGB10_A2 (GLSL type rgb10_a2, supported by OpenGL 4.2+)
851 \value RGB10A2U
852 GL_RGB10_A2UI (GLSL type rgb10_a2ui, supported by OpenGL 4.2+)
853*/
854
855
856QShaderImage::QShaderImage(Qt3DCore::QNode *parent)
857 : Qt3DCore::QNode(*new QShaderImagePrivate, parent)
858{
859}
860
861QShaderImage::~QShaderImage()
862{
863
864}
865
866QAbstractTexture *QShaderImage::texture() const
867{
868 Q_D(const QShaderImage);
869 return d->m_texture;
870}
871
872bool QShaderImage::layered() const
873{
874 Q_D(const QShaderImage);
875 return d->m_layered;
876}
877
878int QShaderImage::mipLevel() const
879{
880 Q_D(const QShaderImage);
881 return d->m_mipLevel;
882}
883
884int QShaderImage::layer() const
885{
886 Q_D(const QShaderImage);
887 return d->m_layer;
888}
889
890QShaderImage::Access QShaderImage::access() const
891{
892 Q_D(const QShaderImage);
893 return d->m_access;
894}
895
896QShaderImage::ImageFormat QShaderImage::format() const
897{
898 Q_D(const QShaderImage);
899 return d->m_format;
900}
901
902void QShaderImage::setTexture(QAbstractTexture *texture)
903{
904 Q_D(QShaderImage);
905 if (texture == d->m_texture)
906 return;
907
908 if (d->m_texture)
909 d->unregisterDestructionHelper(d->m_texture);
910
911 if (texture && !texture->parent())
912 texture->setParent(this);
913
914 d->m_texture = texture;
915
916 if (d->m_texture)
917 d->registerDestructionHelper(d->m_texture, &QShaderImage::setTexture, d->m_texture);
918
919 Q_EMIT textureChanged(texture);
920}
921
922void QShaderImage::setLayered(bool layered)
923{
924 Q_D(QShaderImage);
925 if (layered == d->m_layered)
926 return;
927 d->m_layered = layered;
928 Q_EMIT layeredChanged(layered);
929}
930
931void QShaderImage::setMipLevel(int mipLevel)
932{
933 Q_D(QShaderImage);
934 if (mipLevel == d->m_mipLevel)
935 return;
936 d->m_mipLevel = mipLevel;
937 Q_EMIT mipLevelChanged(mipLevel);
938}
939
940void QShaderImage::setLayer(int layer)
941{
942 Q_D(QShaderImage);
943 if (layer == d->m_layer)
944 return;
945 d->m_layer = layer;
946 Q_EMIT layerChanged(layer);
947}
948
949void QShaderImage::setAccess(QShaderImage::Access access)
950{
951 Q_D(QShaderImage);
952 if (access == d->m_access)
953 return;
954 d->m_access = access;
955 Q_EMIT accessChanged(access);
956}
957
958void QShaderImage::setFormat(QShaderImage::ImageFormat format)
959{
960 Q_D(QShaderImage);
961 if (format == d->m_format)
962 return;
963 d->m_format = format;
964 Q_EMIT formatChanged(format);
965}
966
967Qt3DCore::QNodeCreatedChangeBasePtr Qt3DRender::QShaderImage::createNodeCreationChange() const
968{
969 auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QShaderImageData>::create(this);
970 QShaderImageData &data = creationChange->data;
971 Q_D(const QShaderImage);
972 data.textureId = Qt3DCore::qIdForNode(d->m_texture);
973 data.layer = d->m_layer;
974 data.mipLevel = d->m_mipLevel;
975 data.access = d->m_access;
976 data.format = d->m_format;
977 data.layered = d->m_layered;
978 return creationChange;
979
980}
981
982} // namespace Qt3DRender
983
984QT_END_NAMESPACE
985