summaryrefslogtreecommitdiffstats
path: root/src/render/materialsystem/qshaderimage.cpp
blob: 7ab9e25e009fe258d7f26527ff97335a546e6855 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
/****************************************************************************
**
** Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB).
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt3D module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qshaderimage.h"
#include "qshaderimage_p.h"
#include <Qt3DRender/qabstracttexture.h>

QT_BEGIN_NAMESPACE

namespace Qt3DRender {

QShaderImagePrivate::QShaderImagePrivate()
    : Qt3DCore::QNodePrivate()
    , m_texture(nullptr)
    , m_mipLevel(0)
    , m_layer(0)
    , m_access(QShaderImage::ReadWrite)
    , m_format(QShaderImage::Automatic)
    , m_layered(false)
{
}

QShaderImagePrivate::~QShaderImagePrivate()
{
}

/*!
    \qmltype ShaderImage
    \instantiates Qt3DRender::QShaderImage
    \inqmlmodule Qt3D.Render
    \since 5.14
    \brief Provides Image access to shader programs.

    To make the content of textures available for read and write operations in
    a shader, they need to exposed as ShaderImage. Textures can be composed of
    several mip levels, layers and faces. Additionally declaring a ShaderImage
    allows specifying which level, layer or face of the texture content we want
    to access.

    ShaderImage has to be assigned as a Parameter's value and reference a valid
    Qt3D.Render.AbstractTexture to work properly.

    If the referenced texture is a one-dimensional array, two-dimensional array,
    three-dimensional, cube map, cube map array, or two-dimensional multisample
    array texture, it is possible to bind either the entire texture level or a
    single layer or face of the texture level. This can be controlled with the
    \l layered property.

    Support for ShaderImage is only supported with OpenGL 4 and partially with
    OpenGL ES 3.1 and 3.2.

    OpenGL 4 supports the following image types:
    \table
    \header
       \li GLSL Type
       \li OpenGL Type Enum
       \li Texture Type
    \row
       \li image1D
       \li GL_IMAGE_1D
       \li Texture1D
    \row
       \li image2D
       \li GL_IMAGE_2D
       \li Texture2D
    \row
       \li image3D
       \li GL_IMAGE_3D
       \li Texture3D
    \row
       \li image2DRect
       \li GL_IMAGE_2D_RECT
       \li TextureRectangle
    \row
       \li imageCube
       \li GL_IMAGE_CUBE
       \li TextureCubeMap
    \row
       \li imageBuffer
       \li GL_IMAGE_BUFFER
       \li TextureBuffer
    \row
       \li image1DArray
       \li GL_IMAGE_1D_ARRAY
       \li Texture1DArray
    \row
       \li image2DArray
       \li GL_IMAGE_2D_ARRAY
       \li Texture2DArray
    \row
       \li imageCubeArray
       \li GL_IMAGE_CUBE_MAP_ARRAY
       \li TextureCubeMapArray
    \row
       \li image2DMS
       \li GL_IMAGE_2D_MULTISAMPLE
       \li Texture2DMultisample
    \row
       \li image2DMSArray
       \li GL_IMAGE_2D_MULTISAMPLE_ARRAY
       \li Texture2DMultisampleArray
    \row
       \li iimage1D
       \li GL_INT_IMAGE_1D
       \li Texture1D
    \row
       \li iimage2D
       \li GL_INT_IMAGE_2D
       \li Texture2D
    \row
       \li iimage3D
       \li GL_INT_IMAGE_3D
       \li Texture3D
    \row
       \li iimage2DRect
       \li GL_INT_IMAGE_2D_RECT
       \li TextureRectangle
    \row
       \li iimageCube
       \li GL_INT_IMAGE_CUBE
       \li TextureCubeMap
    \row
       \li iimageBuffer
       \li GL_INT_IMAGE_BUFFER
       \li TextureBuffer
    \row
       \li iimage1DArray
       \li GL_INT_IMAGE_1D_ARRAY
       \li Texture1DArray
    \row
       \li iimage2DArray
       \li GL_INT_IMAGE_2D_ARRAY
       \li Texture2DArray
    \row
       \li iimageCubeArray
       \li GL_INT_IMAGE_CUBE_MAP_ARRAY
       \li TextureCubeMapArray
    \row
       \li iimage2DMS
       \li GL_INT_IMAGE_2D_MULTISAMPLE
       \li Texture2DMultisample
    \row
       \li iimage2DMSArray
       \li GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY
       \li Texture2DMultisampleArray
    \row
       \li uimage1D
       \li GL_UNSIGNED_INT_IMAGE_1D
       \li Texture1D
    \row
       \li uimage2D
       \li GL_UNSIGNED_INT_IMAGE_2D
       \li Texture2D
    \row
       \li uimage3D
       \li GL_UNSIGNED_INT_IMAGE_3D
       \li Texture3D
    \row
       \li uimage2DRect
       \li GL_UNSIGNED_INT_IMAGE_2D_RECT
       \li TextureRectangle
    \row
       \li uimageCube
       \li GL_UNSIGNED_INT_IMAGE_CUBE
       \li TextureCubeMap
    \row
       \li uimageBuffer
       \li GL_UNSIGNED_INT_IMAGE_BUFFER
       \li TextureBuffer
    \row
       \li uimage1DArray
       \li GL_UNSIGNED_INT_IMAGE_1D_ARRAY
       \li Texture1DArray
    \row
       \li uimage2DArray
       \li GL_UNSIGNED_INT_IMAGE_2D_ARRAY
       \li Texture2DArray
    \row
       \li uimageCubeArray
       \li GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY
       \li TextureCubeMapArray
    \row
       \li uimage2DMS
       \li GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE
       \li Texture2DMultisample
    \row
       \li uimage2DMSArray
       \li GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY
       \li Texture2DMultisampleArray
    \endtable

    OpenGL ES 3.1 supports the following image types:
    \table
    \header
       \li GLSL Type
       \li OpenGL Type Enum
       \li Texture Type
    \row
       \li image2D
       \li GL_IMAGE_2D
       \li Texture2D
    \row
       \li image3D
       \li GL_IMAGE_3D
       \li Texture3D
    \row
       \li imageCube
       \li GL_IMAGE_CUBE
       \li TextureCubeMap
    \row
       \li image2DArray
       \li GL_IMAGE_2D_ARRAY
       \li Texture2DArray
    \row
       \li iimage2D
       \li GL_INT_IMAGE_2D
       \li Texture2D
    \row
       \li iimage3D
       \li GL_INT_IMAGE_3D
       \li Texture3D
    \row
       \li iimageCube
       \li GL_INT_IMAGE_CUBE
       \li TextureCubeMap
    \row
       \li iimage2DArray
       \li GL_INT_IMAGE_2D_ARRAY
       \li Texture2DArray
    \row
       \li uimage2D
       \li GL_UNSIGNED_INT_IMAGE_2D
       \li Texture2D
    \row
       \li uimage3D
       \li GL_UNSIGNED_INT_IMAGE_3D
       \li Texture3D
    \row
       \li uimageCube
       \li GL_UNSIGNED_INT_IMAGE_CUBE
       \li TextureCubeMap
    \row
       \li uimage2DArray
       \li GL_UNSIGNED_INT_IMAGE_2D_ARRAY
       \li Texture2DArray
    \endtable

    OpenGL ES 3.2 supports all of the OpenGL ES 3.1 image types as well as the
    following:
    \table
    \header
       \li GLSL Type
       \li OpenGL Type Enum
       \li Texture Type
    \row
       \li imageBuffer
       \li GL_IMAGE_BUFFER
       \li TextureBuffer
    \row
       \li imageCubeArray
       \li GL_IMAGE_CUBE_MAP_ARRAY
       \li TextureCubeMapArray
    \row
       \li iimageBuffer
       \li GL_IMAGE_BUFFER
       \li TextureBuffer
    \row
       \li iimageCubeArray
       \li GL_INT_IMAGE_CUBE_MAP_ARRAY
       \li TextureCubeMapArray
    \row
       \li uimageBuffer
       \li GL_UNSIGNED_INT_IMAGE_BUFFER
       \li TextureBuffer
    \row
       \li uimageCubeArray
       \li GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY
       \li TextureCubeMapArray
    \endtable

    Expected use would look like:

    \badcode

    import Qt3D.Render 2.14

    Entity {
    ...
        Texture2D {
            id: tex2D
            ...
        }

        Material {
            parameters: Parameter {
                name: "imageUniformName"
                value: ShaderImage {
                    texture: tex2D
                }
            }
            ...
        }
     ...
    }
    \endcode
 */

/*!
    \qmlproperty int Qt3D.Render::ShaderImage::mipLevel

    Holds which mipLevel out of the referenced texture should be used for the
    ShaderImage.

    The default value is 0.
 */

/*!
    \qmlproperty int Qt3D.Render::ShaderImage::layer

    Holds which layer out of the referenced texture should be used for the
    ShaderImage. This property does nothing if \a layered is set to true or if
    the reference texture's type isn't compatible with layers.

    \note When the referenced texture is of type cube map or cube map array and
    \a ĺayered is set to false, the face and layer are retrieved in the
    following manner:
    \badcode
    cubeMapLayer = layer / 6
    cubeMapFace = layer - (cubeMapLayer * 6)
    \endcode

    The default value is 0.
 */

/*!
 * \qmlproperty bool Qt3D.Render::ShaderImage::layered

    If set to true, if the referenced texture is a one-dimensional array,
    two-dimensional array, three-dimensional, cube map, cube map array, or
    two-dimensional multisample array texture, the entire level will be bound
    for all layers. If set to false, only the single layer specified by the \a
    layer property will be bound.

    The default value is \c false.
 */

/*!
    \qmlproperty enumeration Qt3D.Render::ShaderImage::access

    Specifies the type of access we want to allow from our shader instances to
    the image. If a shader tries to write or read from an image that has
    incompatible access, the behavior is undefined.

    \value ShaderImage.ReadOnly
           Read-only access.
    \value ShaderImage.WriteOnly
           Write-only access.
    \value ShaderImage.ReadWrite
           Read-write access.

    The default value is ShaderImage.ReadWrite.
 */

/*!
    \qmlproperty enumeration Qt3D.Render::ShaderImage::format

    Specifies the image format, which is essentially important when storing values
    in the ShaderImage from a shader.

    The format doesn't have to be the same as the referenced texture's format.
    It however has to be compatible (matching in size but not necessarily by
    class type). For instance a texture of format R32F (size 32bits, class
    1x32) could be used with an image of format RGBA8I (size 32bits, class
    4x8). Table 8.27 of the
    \l{https://www.khronos.org/registry/OpenGL/specs/gl/glspec45.core.pdf}{OpenGL specifications}
    shows the size and class for all supported image formats.

    By default Qt3D will try to set the image format to match that of the
    referenced texture.

    The default value is ShaderImage.Automatic.
 */

/*!
    \class Qt3DRender::QShaderImage
    \inmodule Qt3DRender
    \since 5.14
    \brief Provides Image access to shader programs.

    To make the content of textures available for read and write operations in
    a shader, they need to exposed as QShaderImage. Textures can be composed of
    several mip levels, layers and faces. Additionally declaring a QShaderImage
    allows specifying which level, layer or face of the texture content we want
    to access.

    QShaderImage has to be assigned as a QParameter's value and reference a valid
    Qt3DRender::QAbstractTexture to work properly.

    If the referenced texture is a one-dimensional array, two-dimensional array,
    three-dimensional, cube map, cube map array, or two-dimensional multisample
    array texture, it is possible to bind either the entire texture level or a
    single layer or face of the texture level. This can be controlled with the
    \l layered property.

    Support for QShaderImage is only supported with OpenGL 4 and partially with
    OpenGL ES 3.1 and 3.2.

    OpenGL 4 supports the following image types:
    \table
    \header
       \li GLSL Type
       \li OpenGL Type Enum
       \li Texture Type
    \row
       \li image1D
       \li GL_IMAGE_1D
       \li QTexture1D
    \row
       \li image2D
       \li GL_IMAGE_2D
       \li QTexture2D
    \row
       \li image3D
       \li GL_IMAGE_3D
       \li QTexture3D
    \row
       \li image2DRect
       \li GL_IMAGE_2D_RECT
       \li QTextureRectangle
    \row
       \li imageCube
       \li GL_IMAGE_CUBE
       \li QTextureCubeMap
    \row
       \li imageBuffer
       \li GL_IMAGE_BUFFER
       \li QTextureBuffer
    \row
       \li image1DArray
       \li GL_IMAGE_1D_ARRAY
       \li QTexture1DArray
    \row
       \li image2DArray
       \li GL_IMAGE_2D_ARRAY
       \li QTexture2DArray
    \row
       \li imageCubeArray
       \li GL_IMAGE_CUBE_MAP_ARRAY
       \li QTextureCubeMapArray
    \row
       \li image2DMS
       \li GL_IMAGE_2D_MULTISAMPLE
       \li QTexture2DMultisample
    \row
       \li image2DMSArray
       \li GL_IMAGE_2D_MULTISAMPLE_ARRAY
       \li QTexture2DMultisampleArray
    \row
       \li iimage1D
       \li GL_INT_IMAGE_1D
       \li QTexture1D
    \row
       \li iimage2D
       \li GL_INT_IMAGE_2D
       \li QTexture2D
    \row
       \li iimage3D
       \li GL_INT_IMAGE_3D
       \li QTexture3D
    \row
       \li iimage2DRect
       \li GL_INT_IMAGE_2D_RECT
       \li QTextureRectangle
    \row
       \li iimageCube
       \li GL_INT_IMAGE_CUBE
       \li QTextureCubeMap
    \row
       \li iimageBuffer
       \li GL_INT_IMAGE_BUFFER
       \li QTextureBuffer
    \row
       \li iimage1DArray
       \li GL_INT_IMAGE_1D_ARRAY
       \li QTexture1DArray
    \row
       \li iimage2DArray
       \li GL_INT_IMAGE_2D_ARRAY
       \li QTexture2DArray
    \row
       \li iimageCubeArray
       \li GL_INT_IMAGE_CUBE_MAP_ARRAY
       \li QTextureCubeMapArray
    \row
       \li iimage2DMS
       \li GL_INT_IMAGE_2D_MULTISAMPLE
       \li QTexture2DMultisample
    \row
       \li iimage2DMSArray
       \li GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY
       \li QTexture2DMultisampleArray
    \row
       \li uimage1D
       \li GL_UNSIGNED_INT_IMAGE_1D
       \li QTexture1D
    \row
       \li uimage2D
       \li GL_UNSIGNED_INT_IMAGE_2D
       \li QTexture2D
    \row
       \li uimage3D
       \li GL_UNSIGNED_INT_IMAGE_3D
       \li QTexture3D
    \row
       \li uimage2DRect
       \li GL_UNSIGNED_INT_IMAGE_2D_RECT
       \li QTextureRectangle
    \row
       \li uimageCube
       \li GL_UNSIGNED_INT_IMAGE_CUBE
       \li QTextureCubeMap
    \row
       \li uimageBuffer
       \li GL_UNSIGNED_INT_IMAGE_BUFFER
       \li QTextureBuffer
    \row
       \li uimage1DArray
       \li GL_UNSIGNED_INT_IMAGE_1D_ARRAY
       \li QTexture1DArray
    \row
       \li uimage2DArray
       \li GL_UNSIGNED_INT_IMAGE_2D_ARRAY
       \li QTexture2DArray
    \row
       \li uimageCubeArray
       \li GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY
       \li QTextureCubeMapArray
    \row
       \li uimage2DMS
       \li GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE
       \li QTexture2DMultisample
    \row
       \li uimage2DMSArray
       \li GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY
       \li QTexture2DMultisampleArray
    \endtable

    OpenGL ES 3.1 supports the following image types:
    \table
    \header
       \li GLSL Type
       \li OpenGL Type Enum
       \li Texture Type
    \row
       \li image2D
       \li GL_IMAGE_2D
       \li QTexture2D
    \row
       \li image3D
       \li GL_IMAGE_3D
       \li QTexture3D
    \row
       \li imageCube
       \li GL_IMAGE_CUBE
       \li QTextureCubeMap
    \row
       \li image2DArray
       \li GL_IMAGE_2D_ARRAY
       \li QTexture2DArray
    \row
       \li iimage2D
       \li GL_INT_IMAGE_2D
       \li QTexture2D
    \row
       \li iimage3D
       \li GL_INT_IMAGE_3D
       \li QTexture3D
    \row
       \li iimageCube
       \li GL_INT_IMAGE_CUBE
       \li QTextureCubeMap
    \row
       \li iimage2DArray
       \li GL_INT_IMAGE_2D_ARRAY
       \li QTexture2DArray
    \row
       \li uimage2D
       \li GL_UNSIGNED_INT_IMAGE_2D
       \li QTexture2D
    \row
       \li uimage3D
       \li GL_UNSIGNED_INT_IMAGE_3D
       \li QTexture3D
    \row
       \li uimageCube
       \li GL_UNSIGNED_INT_IMAGE_CUBE
       \li QTextureCubeMap
    \row
       \li uimage2DArray
       \li GL_UNSIGNED_INT_IMAGE_2D_ARRAY
       \li QTexture2DArray
    \endtable

    OpenGL ES 3.2 supports all of the OpenGL ES 3.1 image types as well as the
    following:
    \table
    \header
       \li GLSL Type
       \li OpenGL Type Enum
       \li Texture Type
    \row
       \li imageBuffer
       \li GL_IMAGE_BUFFER
       \li QTextureBuffer
    \row
       \li imageCubeArray
       \li GL_IMAGE_CUBE_MAP_ARRAY
       \li QTextureCubeMapArray
    \row
       \li iimageBuffer
       \li GL_IMAGE_BUFFER
       \li QTextureBuffer
    \row
       \li iimageCubeArray
       \li GL_INT_IMAGE_CUBE_MAP_ARRAY
       \li QTextureCubeMapArray
    \row
       \li uimageBuffer
       \li GL_UNSIGNED_INT_IMAGE_BUFFER
       \li QTextureBuffer
    \row
       \li uimageCubeArray
       \li GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY
       \li QTextureCubeMapArray
    \endtable

    Expected use would look like:

    \badcode
    Qt3DRender::QTexture2D *tex2D = new Qt3DRender::QTexture2D();
    ...
    Qt3DRender::QMaterial *material = new Qt3DRender::QMaterial();
    ...
    Qt3DRender::QParameter *imageParameter = new Qt3DRender::QParameter();
    Qt3DRender::QShaderImage *shaderImage = new Qt3DRender::QShaderImage();

    shaderImage->setTexture(tex2D);

    imageParameter->setName("imageUniformName");
    imageParameter->setValue(QVariant::fromValue(shaderImage));

    material->addParameter(imageParamenter);
    \endcode
 */

/*!
    \property Qt3DRender::QShaderImage::mipLevel

    Holds which mipLevel out of the referenced texture should be used for the
    QShaderImage.

    The default value is 0.
*/

/*!
    \property Qt3DRender::QShaderImage::layer

    Holds which layer out of the referenced texture should be used for the
    QShaderImage. This property does nothing if \a layered is set to true or if the
    reference texture's type isn't compatible with layers.

    \note When the referenced texture is of type cube map or cube map array and
    \a ĺayered is set to false, the face and layer are retrieved in the
    following manner:
    \badcode
    cubeMapLayer = layer / 6
    cubeMapFace = layer - (cubeMapLayer * 6)
    \endcode

    The default value is 0.
 */

/*!
 * \property Qt3DRender::QShaderImage::layered

    If set to true, if the referenced texture is a one-dimensional array,
    two-dimensional array, three-dimensional, cube map, cube map array, or
    two-dimensional multisample array texture, the entire level will be bound
    for all layers. If set to false, only the single layer specified by the \a
    layer property will be bound.

    The default value is \c false.
 */

/*!
    \property Qt3DRender::QShaderImage::access

    Specifies the type of access we want to allow from our shader instances to
    the image. If a shader tries to write or read from an image that has
    incompatible access, the behavior is undefined.

    The default value is QShaderImage::ReadWrite.
 */

/*!
    \property Qt3DRender::QShaderImage::format

    Specifies the image format, which is essentially important when storing values
    in the Image from a shader.

    The format doesn't have to be the same as the referenced texture's format.
    It however has to be compatible (matching in size but not necessarily by
    class type). For instance a texture of format R32F (size 32bits, class
    1x32) could be used with an image of format RGBA8I (size 32bits, class
    4x8). Table 8.27 of the
    \l{https://www.khronos.org/registry/OpenGL/specs/gl/glspec45.core.pdf}{OpenGL specifications}
    shows the size and class for all supported Image formats.

    By default Qt3D will try to set the image format to match that of the
    referenced texture.

    The default value is QShaderImage::Automatic.
 */

/*!
    \enum Qt3DRender::QShaderImage::Access

    \value ReadOnly
           Image will only be read from in shaders
    \value WriteOnly
           Image will only be written into from shaders
    \value ReadWrite
           Image will only be read and written into from shaders
*/

/*!
    \enum Qt3DRender::QShaderImage::ImageFormat

    This list describes all possible image formats

    \value NoFormat
          GL_NONE
    \value Automatic
          Qt 3D will try to determine the format automatically based on
          the referenced texture.
    \value R8_UNorm
          GL_R8 (GLSL type r8, supported by OpenGL 4.2+)
    \value RG8_UNorm
          GL_RG8 (GLSL type rg8, supported by OpenGL 4.2+)
    \value RGBA8_UNorm
          GL_RGBA8 (GLSL type rgba8, supported by OpenGL 4.2+, OpenGL ES 3.1+)
    \value R16_UNorm
          GL_R16 (GLSL type r16, supported by OpenGL 4.2+)
    \value RG16_UNorm
          GL_RG16 (GLSL type rg16, supported by OpenGL 4.2+)
    \value RGBA16_UNorm
          GL_RGBA16 (GLSL type rgba16, supported by OpenGL 4.2+)
    \value R8_SNorm
          GL_R8_SNORM (GLSL type r8_snorm, supported by OpenGL 4.2+)
    \value RG8_SNorm
          GL_RG8_SNORM (GLSL type rg8_snorm, supported by OpenGL 4.2+)
    \value RGBA8_SNorm
          GL_RGBA8_SNORM (GLSL type rgba8_snorm, supported by OpenGL 4.2+, OpenGL ES 3.1+)
    \value R16_SNorm
          GL_R16_SNORM (GLSL type r16_snorm, supported by OpenGL 4.2+)
    \value RG16_SNorm
          GL_RG16_SNORM (GLSL type rg16_snorm, supported by OpenGL 4.2+)
    \value RGBA16_SNorm
          GL_RGBA16_SNORM (GLSL type rgba16_snorm, supported by OpenGL 4.2+)
    \value R8U
          GL_R8UI (GLSL type r8ui, supported by OpenGL 4.2+)
    \value RG8U
          GL_RG8UI (GLSL type rg8ui, supported by OpenGL 4.2+)
    \value RGBA8U
          GL_RGBA8UI (GLSL type rgba8ui, supported by OpenGL 4.2+, OpenGL ES 3.1+)
    \value R16U
          GL_R16UI (GLSL type r16ui, supported by OpenGL 4.2+)
    \value RG16U
          GL_RG16UI (GLSL type rg16ui, supported by OpenGL 4.2+)
    \value RGBA16U
          GL_RGBA16UI (GLSL type rgba16ui, supported by OpenGL 4.2+, OpenGL ES 3.1+)
    \value R32U
          GL_R32UI (GLSL type r32ui, supported by OpenGL 4.2+, OpenGL ES 3.1)
    \value RG32U
          GL_RG32UI (GLSL type rg32ui, supported by OpenGL 4.2+)
    \value RGBA32U
          GL_RGBA32UI (GLSL type rgba32ui, supported by OpenGL 4.2+, OpenGL ES 3.1+)
    \value R8I
          GL_R8I (GLSL type r8i, supported by OpenGL 4.2+)
    \value RG8I
          GL_RG8I (GLSL type rg8i, supported by OpenGL 4.2+)
    \value RGBA8I
          GL_RGBA8I (GLSL type rgba8i, supported by OpenGL 4.2+, OpenGL ES 3.1+)
    \value R16I
          GL_R16I (GLSL type r16i, supported by OpenGL 4.2+)
    \value RG16I
          GL_RG16I (GLSL type rg16i, supported by OpenGL 4.2+)
    \value RGBA16I
          GL_RGBA16I (GLSL type rgba16i, supported by OpenGL 4.2+, OpenGL ES 3.1)
    \value R32I
          GL_R32I (GLSL type r32i, supported by OpenGL 4.2+, OpenGL ES 3.1+)
    \value RG32I
          GL_RG32I (GLSL type rg32i, supported by OpenGL 4.2+)
    \value RGBA32I
          GL_RGBA32I (GLSL type rgba32i, supported by OpenGL 4.2+, OpenGL ES 3.1+)
    \value R16F
          GL_R16F (GLSL type r16f, supported by OpenGL 4.2+)
    \value RG16F
          GL_RG16F (GLSL type rg16f, supported by OpenGL 4.2+)
    \value RGBA16F
          GL_RGBA16F (GLSL type rgba16f, supported by OpenGL 4.2+, OpenGL ES 3.1+)
    \value R32F
          GL_R32F (GLSL type r32f, supported by OpenGL 4.2+, OpenGL ES 3.1+)
    \value RG32F
          GL_RG32F (GLSL type rg32f, supported by OpenGL 4.2+)
    \value RGBA32F
          GL_RGBA32F (GLSL type rgba32f, supported by OpenGL 4.2+, OpenGL ES 3.1+)
    \value RG11B10F
          GL_R11F_G11F_B10F (GLSL type r11f_g11f_b10f, supported by OpenGL 4.2+)
    \value RGB10A2
          GL_RGB10_A2 (GLSL type rgb10_a2, supported by OpenGL 4.2+)
    \value RGB10A2U
          GL_RGB10_A2UI (GLSL type rgb10_a2ui, supported by OpenGL 4.2+)
*/


QShaderImage::QShaderImage(Qt3DCore::QNode *parent)
    : Qt3DCore::QNode(*new QShaderImagePrivate, parent)
{
}

QShaderImage::~QShaderImage()
{

}

QAbstractTexture *QShaderImage::texture() const
{
    Q_D(const QShaderImage);
    return d->m_texture;
}

bool QShaderImage::layered() const
{
    Q_D(const QShaderImage);
    return d->m_layered;
}

int QShaderImage::mipLevel() const
{
    Q_D(const QShaderImage);
    return d->m_mipLevel;
}

int QShaderImage::layer() const
{
    Q_D(const QShaderImage);
    return d->m_layer;
}

QShaderImage::Access QShaderImage::access() const
{
    Q_D(const QShaderImage);
    return d->m_access;
}

QShaderImage::ImageFormat QShaderImage::format() const
{
    Q_D(const QShaderImage);
    return d->m_format;
}

void QShaderImage::setTexture(QAbstractTexture *texture)
{
    Q_D(QShaderImage);
    if (texture == d->m_texture)
        return;

    if (d->m_texture)
        d->unregisterDestructionHelper(d->m_texture);

    if (texture && !texture->parent())
        texture->setParent(this);

    d->m_texture = texture;

    if (d->m_texture)
        d->registerDestructionHelper(d->m_texture, &QShaderImage::setTexture, d->m_texture);

    Q_EMIT textureChanged(texture);
}

void QShaderImage::setLayered(bool layered)
{
    Q_D(QShaderImage);
    if (layered == d->m_layered)
        return;
    d->m_layered = layered;
    Q_EMIT layeredChanged(layered);
}

void QShaderImage::setMipLevel(int mipLevel)
{
    Q_D(QShaderImage);
    if (mipLevel == d->m_mipLevel)
        return;
    d->m_mipLevel = mipLevel;
    Q_EMIT mipLevelChanged(mipLevel);
}

void QShaderImage::setLayer(int layer)
{
    Q_D(QShaderImage);
    if (layer == d->m_layer)
        return;
    d->m_layer = layer;
    Q_EMIT layerChanged(layer);
}

void QShaderImage::setAccess(QShaderImage::Access access)
{
    Q_D(QShaderImage);
    if (access == d->m_access)
        return;
    d->m_access = access;
    Q_EMIT accessChanged(access);
}

void QShaderImage::setFormat(QShaderImage::ImageFormat format)
{
    Q_D(QShaderImage);
    if (format == d->m_format)
        return;
    d->m_format = format;
    Q_EMIT formatChanged(format);
}

Qt3DCore::QNodeCreatedChangeBasePtr Qt3DRender::QShaderImage::createNodeCreationChange() const
{
    auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QShaderImageData>::create(this);
    QShaderImageData &data = creationChange->data;
    Q_D(const QShaderImage);
    data.textureId = Qt3DCore::qIdForNode(d->m_texture);
    data.layer = d->m_layer;
    data.mipLevel = d->m_mipLevel;
    data.access = d->m_access;
    data.format = d->m_format;
    data.layered = d->m_layered;
    return creationChange;

}

} // namespace Qt3DRender

QT_END_NAMESPACE