lin
2025-08-14 dae8bad597b6607a449b32bf76c523423f7720ed
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
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
#ifndef _TCUTEXTURE_HPP
#define _TCUTEXTURE_HPP
/*-------------------------------------------------------------------------
 * drawElements Quality Program Tester Core
 * ----------------------------------------
 *
 * Copyright 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *//*!
 * \file
 * \brief Reference Texture Implementation.
 *//*--------------------------------------------------------------------*/
 
#include "tcuDefs.hpp"
#include "tcuVector.hpp"
#include "rrGenericVector.hpp"
#include "deArrayBuffer.hpp"
 
#include <vector>
#include <ostream>
 
namespace tcu
{
 
/*--------------------------------------------------------------------*//*!
 * \brief Texture format
 *//*--------------------------------------------------------------------*/
class TextureFormat
{
public:
   enum ChannelOrder
   {
       R = 0,
       A,
       I,
       L,
       LA,
       RG,
       RA,
       RGB,
       RGBA,
       ARGB,
       BGR,
       BGRA,
 
       sR,
       sRG,
       sRGB,
       sRGBA,
       sBGR,
       sBGRA,
 
       D,
       S,
       DS,
 
       CHANNELORDER_LAST
   };
 
   enum ChannelType
   {
       SNORM_INT8 = 0,
       SNORM_INT16,
       SNORM_INT32,
       UNORM_INT8,
       UNORM_INT16,
       UNORM_INT24,
       UNORM_INT32,
       UNORM_BYTE_44,
       UNORM_SHORT_565,
       UNORM_SHORT_555,
       UNORM_SHORT_4444,
       UNORM_SHORT_5551,
       UNORM_SHORT_1555,
       UNORM_INT_101010,
       SNORM_INT_1010102_REV,
       UNORM_INT_1010102_REV,
       UNSIGNED_BYTE_44,
       UNSIGNED_SHORT_565,
       UNSIGNED_SHORT_4444,
       UNSIGNED_SHORT_5551,
       SIGNED_INT_1010102_REV,
       UNSIGNED_INT_1010102_REV,
       UNSIGNED_INT_11F_11F_10F_REV,
       UNSIGNED_INT_999_E5_REV,
       UNSIGNED_INT_16_8_8,
       UNSIGNED_INT_24_8,
       UNSIGNED_INT_24_8_REV,
       SIGNED_INT8,
       SIGNED_INT16,
       SIGNED_INT32,
       UNSIGNED_INT8,
       UNSIGNED_INT16,
       UNSIGNED_INT24,
       UNSIGNED_INT32,
       HALF_FLOAT,
       FLOAT,
       FLOAT64,
       FLOAT_UNSIGNED_INT_24_8_REV,
 
       UNORM_SHORT_10,
       UNORM_SHORT_12,
 
       CHANNELTYPE_LAST
   };
 
   ChannelOrder    order;
   ChannelType        type;
 
   TextureFormat (ChannelOrder order_, ChannelType type_)
       : order    (order_)
       , type    (type_)
   {
   }
 
   TextureFormat (void)
       : order    (CHANNELORDER_LAST)
       , type    (CHANNELTYPE_LAST)
   {
   }
 
   int getPixelSize (void) const; //!< Deprecated, use tcu::getPixelSize(fmt)
 
   bool operator== (const TextureFormat& other) const { return !(*this != other); }
   bool operator!= (const TextureFormat& other) const
   {
       return (order != other.order || type != other.type);
   }
} DE_WARN_UNUSED_TYPE;
 
bool    isValid                (TextureFormat format);
int        getPixelSize        (TextureFormat format);
int        getNumUsedChannels    (TextureFormat::ChannelOrder order);
int        getChannelSize        (TextureFormat::ChannelType type);
 
/*--------------------------------------------------------------------*//*!
 * \brief Texture swizzle
 *//*--------------------------------------------------------------------*/
struct TextureSwizzle
{
   enum Channel
   {
       // \note CHANNEL_N must equal int N
       CHANNEL_0 = 0,
       CHANNEL_1,
       CHANNEL_2,
       CHANNEL_3,
 
       CHANNEL_ZERO,
       CHANNEL_ONE,
 
       CHANNEL_LAST
   };
 
   Channel components[4];
};
 
//! get the swizzle used to expand texture data with a given channel order to RGBA form
const TextureSwizzle& getChannelReadSwizzle        (TextureFormat::ChannelOrder order);
 
//! get the swizzle used to narrow RGBA form data to native texture data with a given channel order
const TextureSwizzle& getChannelWriteSwizzle    (TextureFormat::ChannelOrder order);
 
/*--------------------------------------------------------------------*//*!
 * \brief Sampling parameters
 *//*--------------------------------------------------------------------*/
class Sampler
{
public:
   enum WrapMode
   {
       CLAMP_TO_EDGE = 0,    //! Clamp to edge
       CLAMP_TO_BORDER,    //! Use border color at edge
       REPEAT_GL,            //! Repeat with OpenGL semantics
       REPEAT_CL,            //! Repeat with OpenCL semantics
       MIRRORED_REPEAT_GL,    //! Mirrored repeat with OpenGL semantics
       MIRRORED_REPEAT_CL, //! Mirrored repeat with OpenCL semantics
       MIRRORED_ONCE,        //! Mirrored once in negative directions
 
       WRAPMODE_LAST
   };
 
   enum FilterMode
   {
       NEAREST = 0,
       LINEAR,
 
       NEAREST_MIPMAP_NEAREST,
       NEAREST_MIPMAP_LINEAR,
       LINEAR_MIPMAP_NEAREST,
       LINEAR_MIPMAP_LINEAR,
 
       FILTERMODE_LAST
   };
 
   enum ReductionMode
   {
       WEIGHTED_AVERAGE = 0,
       MIN,
       MAX,
 
       REDUCTIONMODE_LAST
   };
 
   enum CompareMode
   {
       COMPAREMODE_NONE = 0,
       COMPAREMODE_LESS,
       COMPAREMODE_LESS_OR_EQUAL,
       COMPAREMODE_GREATER,
       COMPAREMODE_GREATER_OR_EQUAL,
       COMPAREMODE_EQUAL,
       COMPAREMODE_NOT_EQUAL,
       COMPAREMODE_ALWAYS,
       COMPAREMODE_NEVER,
 
       COMPAREMODE_LAST
   };
 
   enum DepthStencilMode
   {
       MODE_DEPTH = 0,
       MODE_STENCIL,
 
       MODE_LAST
   };
 
   // Wrap control
   WrapMode            wrapS;
   WrapMode            wrapT;
   WrapMode            wrapR;
 
   // Minifcation & magnification
   FilterMode            minFilter;
   FilterMode            magFilter;
 
   // min/max filtering reduction
   ReductionMode        reductionMode;
 
   float                lodThreshold;        // lod <= lodThreshold ? magnified : minified
 
   // Coordinate normalization
   bool                normalizedCoords;
 
   // Shadow comparison
   CompareMode            compare;
   int                    compareChannel;
 
   // Border color.
   // \note It is setter's responsibility to guarantee that the values are representable
   //       in sampled texture's internal format.
   // \note It is setter's responsibility to guarantee that the format is compatible with the
   //       sampled texture's internal format. Otherwise results are undefined.
   rr::GenericVec4        borderColor;
 
   // Seamless cube map filtering
   bool                seamlessCubeMap;
 
   // Depth stencil mode
   DepthStencilMode    depthStencilMode;
 
   Sampler (WrapMode            wrapS_,
            WrapMode            wrapT_,
            WrapMode            wrapR_,
            FilterMode            minFilter_,
            FilterMode            magFilter_,
            float                lodThreshold_        = 0.0f,
            bool                normalizedCoords_    = true,
            CompareMode        compare_            = COMPAREMODE_NONE,
            int                compareChannel_        = 0,
            const Vec4&        borderColor_        = Vec4(0.0f, 0.0f, 0.0f, 0.0f),
            bool                seamlessCubeMap_    = false,
            DepthStencilMode    depthStencilMode_    = MODE_DEPTH,
            ReductionMode        reductionMode_        = WEIGHTED_AVERAGE)
       : wrapS                (wrapS_)
       , wrapT                (wrapT_)
       , wrapR                (wrapR_)
       , minFilter            (minFilter_)
       , magFilter            (magFilter_)
       , reductionMode        (reductionMode_)
       , lodThreshold        (lodThreshold_)
       , normalizedCoords    (normalizedCoords_)
       , compare            (compare_)
       , compareChannel    (compareChannel_)
       , borderColor        (borderColor_)
       , seamlessCubeMap    (seamlessCubeMap_)
       , depthStencilMode    (depthStencilMode_)
   {
   }
 
   Sampler (void)
       : wrapS                (WRAPMODE_LAST)
       , wrapT                (WRAPMODE_LAST)
       , wrapR                (WRAPMODE_LAST)
       , minFilter            (FILTERMODE_LAST)
       , magFilter            (FILTERMODE_LAST)
       , reductionMode        (REDUCTIONMODE_LAST)
       , lodThreshold        (0.0f)
       , normalizedCoords    (true)
       , compare            (COMPAREMODE_NONE)
       , compareChannel    (0)
       , borderColor        (Vec4(0.0f, 0.0f, 0.0f, 0.0f))
       , seamlessCubeMap    (false)
       , depthStencilMode    (MODE_DEPTH)
   {
   }
} DE_WARN_UNUSED_TYPE;
 
// Calculate pitches for pixel data with no padding.
IVec3 calculatePackedPitch (const TextureFormat& format, const IVec3& size);
 
class TextureLevel;
 
/*--------------------------------------------------------------------*//*!
 * \brief Read-only pixel data access
 *
 * ConstPixelBufferAccess encapsulates pixel data pointer along with
 * format and layout information. It can be used for read-only access
 * to arbitrary pixel buffers.
 *
 * Access objects are like iterators or pointers. They can be passed around
 * as values and are valid as long as the storage doesn't change.
 *//*--------------------------------------------------------------------*/
class ConstPixelBufferAccess
{
public:
                           ConstPixelBufferAccess        (void);
                           ConstPixelBufferAccess        (const TextureLevel& level);
                           ConstPixelBufferAccess        (const TextureFormat& format, int width, int height, int depth, const void* data);
                           ConstPixelBufferAccess        (const TextureFormat& format, const IVec3& size, const void* data);
                           ConstPixelBufferAccess        (const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, const void* data);
                           ConstPixelBufferAccess        (const TextureFormat& format, const IVec3& size, const IVec3& pitch, const void* data);
 
   const TextureFormat&    getFormat                    (void) const    { return m_format;                    }
   const IVec3&            getSize                        (void) const    { return m_size;                    }
   int                        getWidth                    (void) const    { return m_size.x();                }
   int                        getHeight                    (void) const    { return m_size.y();                }
   int                        getDepth                    (void) const    { return m_size.z();                }
   int                        getPixelPitch                (void) const    { return m_pitch.x();                }
   int                        getRowPitch                    (void) const    { return m_pitch.y();                }
   int                        getSlicePitch                (void) const    { return m_pitch.z();                }
   const IVec3&            getPitch                    (void) const    { return m_pitch;                    }
 
   const void*                getDataPtr                    (void) const    { return m_data;                    }
   const void*                getPixelPtr                    (int x, int y, int z = 0) const { return (const deUint8*)m_data + x * m_pitch.x() + y * m_pitch.y() + z * m_pitch.z(); }
 
   Vec4                    getPixel                    (int x, int y, int z = 0) const;
   IVec4                    getPixelInt                    (int x, int y, int z = 0) const;
   UVec4                    getPixelUint                (int x, int y, int z = 0) const { return getPixelInt(x, y, z).cast<deUint32>(); }
 
   template<typename T>
   Vector<T, 4>            getPixelT                    (int x, int y, int z = 0) const;
 
   float                    getPixDepth                    (int x, int y, int z = 0) const;
   int                        getPixStencil                (int x, int y, int z = 0) const;
 
   Vec4                    sample1D                    (const Sampler& sampler, Sampler::FilterMode filter, float s, int level) const;
   Vec4                    sample2D                    (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, int depth) const;
   Vec4                    sample3D                    (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, float r) const;
 
   Vec4                    sample1DOffset                (const Sampler& sampler, Sampler::FilterMode filter, float s, const IVec2& offset) const;
   Vec4                    sample2DOffset                (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, const IVec3& offset) const;
   Vec4                    sample3DOffset                (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, float r, const IVec3& offset) const;
 
   float                    sample1DCompare                (const Sampler& sampler, Sampler::FilterMode filter, float ref, float s, const IVec2& offset) const;
   float                    sample2DCompare                (const Sampler& sampler, Sampler::FilterMode filter, float ref, float s, float t, const IVec3& offset) const;
 
protected:
   TextureFormat            m_format;
   IVec3                    m_size;
   IVec3                    m_pitch;    //!< (pixelPitch, rowPitch, slicePitch)
   mutable void*            m_data;
} DE_WARN_UNUSED_TYPE;
 
/*--------------------------------------------------------------------*//*!
 * \brief Read-write pixel data access
 *
 * This class extends read-only access object by providing write functionality.
 *
 * \note PixelBufferAccess may not have any data members nor add any
 *         virtual functions. It must be possible to reinterpret_cast<>
 *         PixelBufferAccess to ConstPixelBufferAccess.
 *//*--------------------------------------------------------------------*/
class PixelBufferAccess : public ConstPixelBufferAccess
{
public:
                       PixelBufferAccess    (void) {}
                       PixelBufferAccess    (TextureLevel& level);
                       PixelBufferAccess    (const TextureFormat& format, int width, int height, int depth, void* data);
                       PixelBufferAccess    (const TextureFormat& format, const IVec3& size, void* data);
                       PixelBufferAccess    (const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, void* data);
                       PixelBufferAccess    (const TextureFormat& format, const IVec3& size, const IVec3& pitch, void* data);
 
   void*                getDataPtr            (void) const { return m_data; }
   void*                getPixelPtr            (int x, int y, int z = 0) const { return (deUint8*)m_data + x * m_pitch.x() + y * m_pitch.y() + z * m_pitch.z(); }
 
   void                setPixel            (const tcu::Vec4& color, int x, int y, int z = 0) const;
   void                setPixel            (const tcu::IVec4& color, int x, int y, int z = 0) const;
   void                setPixel            (const tcu::UVec4& color, int x, int y, int z = 0) const { setPixel(color.cast<int>(), x, y, z); }
 
   void                setPixDepth            (float depth, int x, int y, int z = 0) const;
   void                setPixStencil        (int stencil, int x, int y, int z = 0) const;
} DE_WARN_UNUSED_TYPE;
 
/*--------------------------------------------------------------------*//*!
 * \brief Generic pixel data container
 *
 * This container supports all valid TextureFormat combinations and
 * both 2D and 3D textures. To read or manipulate data access object must
 * be queried using getAccess().
 *//*--------------------------------------------------------------------*/
class TextureLevel
{
public:
                               TextureLevel        (void);
                               TextureLevel        (const TextureFormat& format);
                               TextureLevel        (const TextureFormat& format, int width, int height, int depth = 1);
                               ~TextureLevel        (void);
 
   const IVec3&                getSize                (void) const    { return m_size;        }
   int                            getWidth            (void) const    { return m_size.x();    }
   int                            getHeight            (void) const    { return m_size.y();    }
   int                            getDepth            (void) const    { return m_size.z();    }
   bool                        isEmpty                (void) const    { return m_size.x() * m_size.y() * m_size.z() == 0; }
   const TextureFormat            getFormat            (void) const    { return m_format;    }
 
   void                        setStorage            (const TextureFormat& format, int width, int heigth, int depth = 1);
   void                        setSize                (int width, int height, int depth = 1);
 
   PixelBufferAccess            getAccess            (void)            { return isEmpty() ? PixelBufferAccess() : PixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr());            }
   ConstPixelBufferAccess        getAccess            (void) const    { return isEmpty() ? ConstPixelBufferAccess() : ConstPixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr());    }
 
private:
   void*                        getPtr                (void)            { return m_data.getPtr(); }
   const void*                    getPtr                (void) const    { return m_data.getPtr(); }
 
   TextureFormat                m_format;
   IVec3                        m_size;
   de::ArrayBuffer<deUint8>    m_data;
 
   friend class ConstPixelBufferAccess;
} DE_WARN_UNUSED_TYPE;
 
Vec4    sampleLevelArray1D                (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, int level, float lod);
Vec4    sampleLevelArray2D                (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, int depth, float lod);
Vec4    sampleLevelArray3D                (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float r, float lod);
 
Vec4    sampleLevelArray1DOffset        (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float lod, const IVec2& offset);
Vec4    sampleLevelArray2DOffset        (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float lod, const IVec3& offset);
Vec4    sampleLevelArray3DOffset        (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset);
 
float    sampleLevelArray1DCompare        (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float ref, float s, float lod, const IVec2& offset);
float    sampleLevelArray2DCompare        (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float ref, float s, float t, float lod, const IVec3& offset);
 
Vec4    gatherArray2DOffsets            (const ConstPixelBufferAccess& src, const Sampler& sampler, float s, float t, int depth, int componentNdx, const IVec2 (&offsets)[4]);
Vec4    gatherArray2DOffsetsCompare        (const ConstPixelBufferAccess& src, const Sampler& sampler, float ref, float s, float t, int depth, const IVec2 (&offsets)[4]);
 
enum CubeFace
{
   CUBEFACE_NEGATIVE_X = 0,
   CUBEFACE_POSITIVE_X,
   CUBEFACE_NEGATIVE_Y,
   CUBEFACE_POSITIVE_Y,
   CUBEFACE_NEGATIVE_Z,
   CUBEFACE_POSITIVE_Z,
 
   CUBEFACE_LAST
};
 
/*--------------------------------------------------------------------*//*!
 * \brief Coordinates projected onto cube face.
 *//*--------------------------------------------------------------------*/
template<typename T>
struct CubeFaceCoords
{
   CubeFace        face;
   T                s;
   T                t;
 
                   CubeFaceCoords        (CubeFace face_, T s_, T t_) : face(face_), s(s_), t(t_) {}
                   CubeFaceCoords        (CubeFace face_, const Vector<T, 2>& c) : face(face_), s(c.x()), t(c.y()) {}
} DE_WARN_UNUSED_TYPE;
 
typedef CubeFaceCoords<float>    CubeFaceFloatCoords;
typedef CubeFaceCoords<int>        CubeFaceIntCoords;
 
CubeFace                selectCubeFace            (const Vec3& coords);
Vec2                    projectToFace            (CubeFace face, const Vec3& coords);
CubeFaceFloatCoords        getCubeFaceCoords        (const Vec3& coords);
CubeFaceIntCoords        remapCubeEdgeCoords        (const CubeFaceIntCoords& coords, int size);
 
/*--------------------------------------------------------------------*//*!
 * \brief 1D Texture View
 *//*--------------------------------------------------------------------*/
class Texture1DView
{
public:
                                   Texture1DView        (int numLevels, const ConstPixelBufferAccess* levels);
 
   int                                getNumLevels        (void) const    { return m_numLevels;                                        }
   int                                getWidth            (void) const    { return m_numLevels > 0 ? m_levels[0].getWidth()    : 0;    }
   const ConstPixelBufferAccess&    getLevel            (int ndx) const    { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];    }
   const ConstPixelBufferAccess*    getLevels            (void) const    { return m_levels;                                            }
 
   Vec4                            sample                (const Sampler& sampler, float s, float lod) const;
   Vec4                            sampleOffset        (const Sampler& sampler, float s, float lod, deInt32 offset) const;
   float                            sampleCompare        (const Sampler& sampler, float ref, float s, float lod) const;
   float                            sampleCompareOffset    (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const;
 
protected:
   int                                m_numLevels;
   const ConstPixelBufferAccess*    m_levels;
} DE_WARN_UNUSED_TYPE;
 
inline Texture1DView::Texture1DView (int numLevels, const ConstPixelBufferAccess* levels)
   : m_numLevels    (numLevels)
   , m_levels        (levels)
{
   DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
}
 
inline Vec4 Texture1DView::sample (const Sampler& sampler, float s, float lod) const
{
   return sampleLevelArray1D(m_levels, m_numLevels, sampler, s, 0 /* depth */, lod);
}
 
inline Vec4 Texture1DView::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
{
   return sampleLevelArray1DOffset(m_levels, m_numLevels, sampler, s, lod, IVec2(offset, 0));
}
 
inline float Texture1DView::sampleCompare (const Sampler& sampler, float ref, float s, float lod) const
{
   return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(0, 0));
}
 
inline float Texture1DView::sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const
{
   return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(offset, 0));
}
 
/*--------------------------------------------------------------------*//*!
 * \brief 2D Texture View
 *//*--------------------------------------------------------------------*/
class Texture2DView
{
public:
                                   Texture2DView        (int numLevels, const ConstPixelBufferAccess* levels);
 
   int                                getNumLevels        (void) const    { return m_numLevels;                                        }
   int                                getWidth            (void) const    { return m_numLevels > 0 ? m_levels[0].getWidth()    : 0;    }
   int                                getHeight            (void) const    { return m_numLevels > 0 ? m_levels[0].getHeight()    : 0;    }
   const ConstPixelBufferAccess&    getLevel            (int ndx) const    { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];    }
   const ConstPixelBufferAccess*    getLevels            (void) const    { return m_levels;                                            }
 
   Vec4                            sample                (const Sampler& sampler, float s, float t, float lod) const;
   Vec4                            sampleOffset        (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
   float                            sampleCompare        (const Sampler& sampler, float ref, float s, float t, float lod) const;
   float                            sampleCompareOffset    (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
 
   Vec4                            gatherOffsets        (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
   Vec4                            gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
 
protected:
   int                                m_numLevels;
   const ConstPixelBufferAccess*    m_levels;
} DE_WARN_UNUSED_TYPE;
 
inline Texture2DView::Texture2DView (int numLevels, const ConstPixelBufferAccess* levels)
   : m_numLevels    (numLevels)
   , m_levels        (levels)
{
   DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
}
 
inline Vec4 Texture2DView::sample (const Sampler& sampler, float s, float t, float lod) const
{
   return sampleLevelArray2D(m_levels, m_numLevels, sampler, s, t, 0 /* depth */, lod);
}
 
inline Vec4 Texture2DView::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
{
   return sampleLevelArray2DOffset(m_levels, m_numLevels, sampler, s, t, lod, IVec3(offset.x(), offset.y(), 0));
}
 
inline float Texture2DView::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
{
   return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(0, 0, 0));
}
 
inline float Texture2DView::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
{
   return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(offset.x(), offset.y(), 0));
}
 
inline Vec4 Texture2DView::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
{
   return gatherArray2DOffsets(m_levels[0], sampler, s, t, 0, componentNdx, offsets);
}
 
inline Vec4 Texture2DView::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
{
   return gatherArray2DOffsetsCompare(m_levels[0], sampler, ref, s, t, 0, offsets);
}
 
/*--------------------------------------------------------------------*//*!
 * \brief Base class for textures that have single mip-map pyramid
 *//*--------------------------------------------------------------------*/
class TextureLevelPyramid
{
public:
                                   TextureLevelPyramid    (const TextureFormat& format, int numLevels);
                                   TextureLevelPyramid    (const TextureLevelPyramid& other);
                                   ~TextureLevelPyramid(void);
 
   const TextureFormat&            getFormat            (void) const            { return m_format;                    }
   int                                getNumLevels        (void) const            { return (int)m_access.size();        }
 
   bool                            isLevelEmpty        (int levelNdx) const    { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[(size_t)levelNdx].empty();    }
   const ConstPixelBufferAccess&    getLevel            (int levelNdx) const    { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_access[(size_t)levelNdx];            }
   const PixelBufferAccess&        getLevel            (int levelNdx)            { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_access[(size_t)levelNdx];            }
 
   const ConstPixelBufferAccess*    getLevels            (void) const            { return &m_access[0];                }
   const PixelBufferAccess*        getLevels            (void)                    { return &m_access[0];                }
 
   void                            allocLevel            (int levelNdx, int width, int height, int depth);
   void                            clearLevel            (int levelNdx);
 
   TextureLevelPyramid&            operator=            (const TextureLevelPyramid& other);
 
private:
   typedef de::ArrayBuffer<deUint8> LevelData;
 
   TextureFormat                    m_format;
   std::vector<LevelData>            m_data;
   std::vector<PixelBufferAccess>    m_access;
} DE_WARN_UNUSED_TYPE;
 
/*--------------------------------------------------------------------*//*!
 * \brief 1D Texture reference implementation
 *//*--------------------------------------------------------------------*/
class Texture1D : private TextureLevelPyramid
{
public:
                                   Texture1D            (const TextureFormat& format, int width);
                                   Texture1D            (const Texture1D& other);
                                   ~Texture1D            (void);
 
   int                                getWidth            (void) const    { return m_width;    }
   const Texture1DView&            getView                (void) const    { return m_view;    }
 
   void                            allocLevel            (int levelNdx);
 
   // Sampling
   Vec4                            sample                (const Sampler& sampler, float s, float lod) const;
   Vec4                            sampleOffset        (const Sampler& sampler, float s, float lod, deInt32 offset) const;
   float                            sampleCompare        (const Sampler& sampler, float ref, float s, float lod) const;
   float                            sampleCompareOffset    (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const;
 
   using TextureLevelPyramid::getFormat;
   using TextureLevelPyramid::getNumLevels;
   using TextureLevelPyramid::getLevel;
   using TextureLevelPyramid::clearLevel;
   using TextureLevelPyramid::isLevelEmpty;
 
   Texture1D&                        operator=            (const Texture1D& other);
 
   operator Texture1DView (void) const { return m_view; }
 
private:
   int                                m_width;
   Texture1DView                    m_view;
} DE_WARN_UNUSED_TYPE;
 
inline Vec4 Texture1D::sample (const Sampler& sampler, float s, float lod) const
{
   return m_view.sample(sampler, s, lod);
}
 
inline Vec4 Texture1D::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
{
   return m_view.sampleOffset(sampler, s, lod, offset);
}
 
inline float Texture1D::sampleCompare (const Sampler& sampler, float ref, float s, float lod) const
{
   return m_view.sampleCompare(sampler, ref, s, lod);
}
 
inline float Texture1D::sampleCompareOffset    (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const
{
   return m_view.sampleCompareOffset(sampler, ref, s, lod, offset);
}
 
/*--------------------------------------------------------------------*//*!
 * \brief 2D Texture reference implementation
 *//*--------------------------------------------------------------------*/
class Texture2D : private TextureLevelPyramid
{
public:
                                   Texture2D            (const TextureFormat& format, int width, int height);
                                   Texture2D            (const TextureFormat& format, int width, int height, int mipmaps);
                                   Texture2D            (const Texture2D& other);
                                   ~Texture2D            (void);
 
   int                                getWidth            (void) const    { return m_width;    }
   int                                getHeight            (void) const    { return m_height;    }
   const Texture2DView&            getView                (void) const    { return m_view;    }
 
   void                            allocLevel            (int levelNdx);
 
   // Sampling
   Vec4                            sample                (const Sampler& sampler, float s, float t, float lod) const;
   Vec4                            sampleOffset        (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
   float                            sampleCompare        (const Sampler& sampler, float ref, float s, float t, float lod) const;
   float                            sampleCompareOffset    (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
 
   Vec4                            gatherOffsets        (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
   Vec4                            gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
 
   using TextureLevelPyramid::getFormat;
   using TextureLevelPyramid::getNumLevels;
   using TextureLevelPyramid::getLevel;
   using TextureLevelPyramid::clearLevel;
   using TextureLevelPyramid::isLevelEmpty;
 
   Texture2D&                        operator=            (const Texture2D& other);
 
   operator Texture2DView (void) const { return m_view; }
 
private:
   int                                m_width;
   int                                m_height;
   Texture2DView                    m_view;
} DE_WARN_UNUSED_TYPE;
 
inline Vec4 Texture2D::sample (const Sampler& sampler, float s, float t, float lod) const
{
   return m_view.sample(sampler, s, t, lod);
}
 
inline Vec4 Texture2D::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
{
   return m_view.sampleOffset(sampler, s, t, lod, offset);
}
 
inline float Texture2D::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
{
   return m_view.sampleCompare(sampler, ref, s, t, lod);
}
 
inline float Texture2D::sampleCompareOffset    (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
{
   return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
}
 
inline Vec4 Texture2D::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
{
   return m_view.gatherOffsets(sampler, s, t, componentNdx, offsets);
}
 
inline Vec4 Texture2D::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
{
   return m_view.gatherOffsetsCompare(sampler, ref, s, t, offsets);
}
 
/*--------------------------------------------------------------------*//*!
 * \brief Cube Map Texture View
 *//*--------------------------------------------------------------------*/
class TextureCubeView
{
public:
                                   TextureCubeView        (void);
                                   TextureCubeView        (int numLevels, const ConstPixelBufferAccess* const (&levels)[CUBEFACE_LAST]);
 
   int                                getNumLevels        (void) const    { return m_numLevels;                                        }
   int                                getSize                (void) const    { return m_numLevels > 0 ? m_levels[0][0].getWidth() : 0;    }
   const ConstPixelBufferAccess&    getLevelFace        (int ndx, CubeFace face) const    { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[face][ndx];    }
   const ConstPixelBufferAccess*    getFaceLevels        (CubeFace face) const            { return m_levels[face];                    }
 
   Vec4                            sample                (const Sampler& sampler, float s, float t, float p, float lod) const;
   float                            sampleCompare        (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
 
   Vec4                            gather                (const Sampler& sampler, float s, float t, float r, int componentNdx) const;
   Vec4                            gatherCompare        (const Sampler& sampler, float ref, float s, float t, float r) const;
 
protected:
   int                                m_numLevels;
   const ConstPixelBufferAccess*    m_levels[CUBEFACE_LAST];
} DE_WARN_UNUSED_TYPE;
 
/*--------------------------------------------------------------------*//*!
 * \brief Cube Map Texture reference implementation
 *//*--------------------------------------------------------------------*/
class TextureCube
{
public:
                                   TextureCube            (const TextureFormat& format, int size);
                                   TextureCube            (const TextureCube& other);
                                   ~TextureCube        (void);
 
   const TextureFormat&            getFormat            (void) const    { return m_format;    }
   int                                getSize                (void) const    { return m_size;    }
 
   int                                getNumLevels        (void) const                    { return (int)m_access[0].size();    }
   const ConstPixelBufferAccess&    getLevelFace        (int ndx, CubeFace face) const    { DE_ASSERT(de::inBounds(ndx, 0, getNumLevels())); return m_access[face][(size_t)ndx];    }
   const PixelBufferAccess&        getLevelFace        (int ndx, CubeFace face)        { DE_ASSERT(de::inBounds(ndx, 0, getNumLevels())); return m_access[face][(size_t)ndx];    }
 
   void                            allocLevel            (CubeFace face, int levelNdx);
   void                            clearLevel            (CubeFace face, int levelNdx);
   bool                            isLevelEmpty        (CubeFace face, int levelNdx) const    { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[face][(size_t)levelNdx].empty();    }
 
   Vec4                            sample                (const Sampler& sampler, float s, float t, float p, float lod) const;
   float                            sampleCompare        (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
 
   Vec4                            gather                (const Sampler& sampler, float s, float t, float r, int componentNdx) const;
   Vec4                            gatherCompare        (const Sampler& sampler, float ref, float s, float t, float r) const;
 
   TextureCube&                    operator=            (const TextureCube& other);
 
   operator TextureCubeView (void) const { return m_view; }
 
private:
   typedef de::ArrayBuffer<deUint8> LevelData;
 
   TextureFormat                    m_format;
   int                                m_size;
   std::vector<LevelData>            m_data[CUBEFACE_LAST];
   std::vector<PixelBufferAccess>    m_access[CUBEFACE_LAST];
   TextureCubeView                    m_view;
} DE_WARN_UNUSED_TYPE;
 
inline Vec4 TextureCube::sample (const Sampler& sampler, float s, float t, float p, float lod) const
{
   return m_view.sample(sampler, s, t, p, lod);
}
 
inline float TextureCube::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
{
   return m_view.sampleCompare(sampler, ref, s, t, r, lod);
}
 
inline Vec4 TextureCube::gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const
{
   return m_view.gather(sampler, s, t, r, componentNdx);
}
 
inline Vec4 TextureCube::gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const
{
   return m_view.gatherCompare(sampler, ref, s, t, r);
}
 
/*--------------------------------------------------------------------*//*!
 * \brief 1D Array Texture View
 *//*--------------------------------------------------------------------*/
class Texture1DArrayView
{
public:
                                   Texture1DArrayView    (int numLevels, const ConstPixelBufferAccess* levels);
 
   int                                getWidth            (void) const    { return m_numLevels > 0 ? m_levels[0].getWidth()    : 0;    }
   int                                getNumLayers        (void) const    { return m_numLevels > 0 ? m_levels[0].getHeight()    : 0;    }
   int                                getNumLevels        (void) const    { return m_numLevels;                                        }
   const ConstPixelBufferAccess&    getLevel            (int ndx) const    { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];    }
   const ConstPixelBufferAccess*    getLevels            (void) const    { return m_levels;                                            }
 
   Vec4                            sample                (const Sampler& sampler, float s, float t, float lod) const;
   Vec4                            sampleOffset        (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
   float                            sampleCompare        (const Sampler& sampler, float ref, float s, float t, float lod) const;
   float                            sampleCompareOffset    (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
 
protected:
   int                                selectLayer            (float r) const;
 
   int                                m_numLevels;
   const ConstPixelBufferAccess*    m_levels;
} DE_WARN_UNUSED_TYPE;
 
/*--------------------------------------------------------------------*//*!
 * \brief 2D Array Texture View
 *//*--------------------------------------------------------------------*/
class Texture2DArrayView
{
public:
                                   Texture2DArrayView    (int numLevels, const ConstPixelBufferAccess* levels);
 
   int                                getWidth            (void) const    { return m_numLevels > 0 ? m_levels[0].getWidth()    : 0;    }
   int                                getHeight            (void) const    { return m_numLevels > 0 ? m_levels[0].getHeight()    : 0;    }
   int                                getNumLayers        (void) const    { return m_numLevels > 0 ? m_levels[0].getDepth()    : 0;    }
   int                                getNumLevels        (void) const    { return m_numLevels;                                        }
   const ConstPixelBufferAccess&    getLevel            (int ndx) const    { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];    }
   const ConstPixelBufferAccess*    getLevels            (void) const    { return m_levels;                                            }
 
   Vec4                            sample                (const Sampler& sampler, float s, float t, float r, float lod) const;
   Vec4                            sampleOffset        (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
   float                            sampleCompare        (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
   float                            sampleCompareOffset    (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
 
   Vec4                            gatherOffsets        (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
   Vec4                            gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
 
protected:
   int                                selectLayer            (float r) const;
 
   int                                m_numLevels;
   const ConstPixelBufferAccess*    m_levels;
} DE_WARN_UNUSED_TYPE;
 
/*--------------------------------------------------------------------*//*!
 * \brief 1D Array Texture reference implementation
 *//*--------------------------------------------------------------------*/
class Texture1DArray : private TextureLevelPyramid
{
public:
                                   Texture1DArray        (const TextureFormat& format, int width, int numLayers);
                                   Texture1DArray        (const Texture1DArray& other);
                                   ~Texture1DArray        (void);
 
   int                                getWidth            (void) const    { return m_width;        }
   int                                getNumLayers        (void) const    { return m_numLayers;    }
 
   void                            allocLevel            (int levelNdx);
 
   using TextureLevelPyramid::getFormat;
   using TextureLevelPyramid::getNumLevels;
   using TextureLevelPyramid::getLevel;
   using TextureLevelPyramid::clearLevel;
   using TextureLevelPyramid::isLevelEmpty;
 
   Vec4                            sample                (const Sampler& sampler, float s, float t, float lod) const;
   Vec4                            sampleOffset        (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
   float                            sampleCompare        (const Sampler& sampler, float ref, float s, float t, float lod) const;
   float                            sampleCompareOffset    (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
 
   Texture1DArray&                    operator=            (const Texture1DArray& other);
 
   operator Texture1DArrayView (void) const { return m_view; }
 
private:
   int                                m_width;
   int                                m_numLayers;
   Texture1DArrayView                m_view;
} DE_WARN_UNUSED_TYPE;
 
inline Vec4 Texture1DArray::sample (const Sampler& sampler, float s, float t, float lod) const
{
   return m_view.sample(sampler, s, t, lod);
}
 
inline Vec4 Texture1DArray::sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const
{
   return m_view.sampleOffset(sampler, s, t, lod, offset);
}
 
inline float Texture1DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
{
   return m_view.sampleCompare(sampler, ref, s, t, lod);
}
 
inline float Texture1DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const
{
   return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
}
 
/*--------------------------------------------------------------------*//*!
 * \brief 2D Array Texture reference implementation
 *//*--------------------------------------------------------------------*/
class Texture2DArray : private TextureLevelPyramid
{
public:
                                   Texture2DArray        (const TextureFormat& format, int width, int height, int numLayers);
                                   Texture2DArray        (const Texture2DArray& other);
                                   ~Texture2DArray        (void);
 
   int                                getWidth            (void) const    { return m_width;        }
   int                                getHeight            (void) const    { return m_height;        }
   int                                getNumLayers        (void) const    { return m_numLayers;    }
 
   void                            allocLevel            (int levelNdx);
 
   using TextureLevelPyramid::getFormat;
   using TextureLevelPyramid::getNumLevels;
   using TextureLevelPyramid::getLevel;
   using TextureLevelPyramid::clearLevel;
   using TextureLevelPyramid::isLevelEmpty;
 
   Vec4                            sample                (const Sampler& sampler, float s, float t, float r, float lod) const;
   Vec4                            sampleOffset        (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
   float                            sampleCompare        (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
   float                            sampleCompareOffset    (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
 
   Vec4                            gatherOffsets        (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
   Vec4                            gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
 
   Texture2DArray&                    operator=            (const Texture2DArray& other);
 
   operator Texture2DArrayView (void) const { return m_view; }
 
private:
   int                                m_width;
   int                                m_height;
   int                                m_numLayers;
   Texture2DArrayView                m_view;
} DE_WARN_UNUSED_TYPE;
 
inline Vec4 Texture2DArray::sample (const Sampler& sampler, float s, float t, float r, float lod) const
{
   return m_view.sample(sampler, s, t, r, lod);
}
 
inline Vec4 Texture2DArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const
{
   return m_view.sampleOffset(sampler, s, t, r, lod, offset);
}
 
inline float Texture2DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
{
   return m_view.sampleCompare(sampler, ref, s, t, r, lod);
}
 
inline float Texture2DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const
{
   return m_view.sampleCompareOffset(sampler, ref, s, t, r, lod, offset);
}
 
inline Vec4 Texture2DArray::gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const
{
   return m_view.gatherOffsets(sampler, s, t, r, componentNdx, offsets);
}
 
inline Vec4 Texture2DArray::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const
{
   return m_view.gatherOffsetsCompare(sampler, ref, s, t, r, offsets);
}
 
/*--------------------------------------------------------------------*//*!
 * \brief 3D Texture View
 *//*--------------------------------------------------------------------*/
class Texture3DView
{
public:
                                   Texture3DView        (int numLevels, const ConstPixelBufferAccess* levels);
 
   int                                getWidth            (void) const    { return m_numLevels > 0 ? m_levels[0].getWidth()    : 0;    }
   int                                getHeight            (void) const    { return m_numLevels > 0 ? m_levels[0].getHeight()    : 0;    }
   int                                getDepth            (void) const    { return m_numLevels > 0 ? m_levels[0].getDepth()    : 0;    }
   int                                getNumLevels        (void) const    { return m_numLevels;                                        }
   const ConstPixelBufferAccess&    getLevel            (int ndx) const    { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];    }
   const ConstPixelBufferAccess*    getLevels            (void) const    { return m_levels;                                            }
 
   Vec4                            sample                (const Sampler& sampler, float s, float t, float r, float lod) const;
   Vec4                            sampleOffset        (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
 
protected:
   int                                m_numLevels;
   const ConstPixelBufferAccess*    m_levels;
} DE_WARN_UNUSED_TYPE;
 
inline Vec4 Texture3DView::sample (const Sampler& sampler, float s, float t, float r, float lod) const
{
   return sampleLevelArray3D(m_levels, m_numLevels, sampler, s, t, r, lod);
}
 
inline Vec4 Texture3DView::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
{
   return sampleLevelArray3DOffset(m_levels, m_numLevels, sampler, s, t, r, lod, offset);
}
 
/*--------------------------------------------------------------------*//*!
 * \brief 3D Texture reference implementation
 *//*--------------------------------------------------------------------*/
class Texture3D : private TextureLevelPyramid
{
public:
                                   Texture3D            (const TextureFormat& format, int width, int height, int depth);
                                   Texture3D            (const Texture3D& other);
                                   ~Texture3D            (void);
 
   int                                getWidth            (void) const    { return m_width;    }
   int                                getHeight            (void) const    { return m_height;    }
   int                                getDepth            (void) const    { return m_depth;    }
 
   void                            allocLevel            (int levelNdx);
 
   using TextureLevelPyramid::getFormat;
   using TextureLevelPyramid::getNumLevels;
   using TextureLevelPyramid::getLevel;
   using TextureLevelPyramid::clearLevel;
   using TextureLevelPyramid::isLevelEmpty;
 
   Vec4                            sample                (const Sampler& sampler, float s, float t, float r, float lod) const;
   Vec4                            sampleOffset        (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
 
   Texture3D&                        operator=            (const Texture3D& other);
 
   operator Texture3DView (void) const { return m_view; }
 
private:
   int                                m_width;
   int                                m_height;
   int                                m_depth;
   Texture3DView                    m_view;
} DE_WARN_UNUSED_TYPE;
 
inline Vec4 Texture3D::sample (const Sampler& sampler, float s, float t, float r, float lod) const
{
   return m_view.sample(sampler, s, t, r, lod);
}
 
inline Vec4 Texture3D::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
{
   return m_view.sampleOffset(sampler, s, t, r, lod, offset);
}
 
/*--------------------------------------------------------------------*//*!
 * \brief Cube Map Array Texture View
 *//*--------------------------------------------------------------------*/
class TextureCubeArrayView
{
public:
                                   TextureCubeArrayView    (int numLevels, const ConstPixelBufferAccess* levels);
 
   int                                getSize                    (void) const    { return m_numLevels > 0 ? m_levels[0].getWidth()    : 0;    }
   int                                getDepth                (void) const    { return m_numLevels > 0 ? m_levels[0].getDepth()    : 0;    }
   int                                getNumLayers            (void) const    { return getDepth()    / 6;    }
   int                                getNumLevels            (void) const    { return m_numLevels;                                        }
   const ConstPixelBufferAccess&    getLevel                (int ndx) const    { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];    }
   const ConstPixelBufferAccess*    getLevels                (void) const    { return m_levels;                                            }
 
   Vec4                            sample                    (const Sampler& sampler, float s, float t, float r, float q, float lod) const;
   Vec4                            sampleOffset            (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
   float                            sampleCompare            (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
   float                            sampleCompareOffset        (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
 
protected:
   int                                selectLayer                (float q) const;
 
   int                                m_numLevels;
   const ConstPixelBufferAccess*    m_levels;
} DE_WARN_UNUSED_TYPE;
 
/*--------------------------------------------------------------------*//*!
 * \brief Cube Map Array Texture reference implementation
 *//*--------------------------------------------------------------------*/
class TextureCubeArray : private TextureLevelPyramid
{
public:
                                   TextureCubeArray    (const TextureFormat& format, int size, int depth);
                                   TextureCubeArray    (const TextureCubeArray& other);
                                   ~TextureCubeArray    (void);
 
   int                                getSize                (void) const    { return m_size;    }
   int                                getDepth            (void) const    { return m_depth;    }
 
   void                            allocLevel            (int levelNdx);
 
   using TextureLevelPyramid::getFormat;
   using TextureLevelPyramid::getNumLevels;
   using TextureLevelPyramid::getLevel;
   using TextureLevelPyramid::clearLevel;
   using TextureLevelPyramid::isLevelEmpty;
 
   Vec4                            sample                (const Sampler& sampler, float s, float t, float r, float q, float lod) const;
   Vec4                            sampleOffset        (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
   float                            sampleCompare        (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
   float                            sampleCompareOffset    (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
 
   TextureCubeArray&                operator=            (const TextureCubeArray& other);
 
   operator TextureCubeArrayView (void) const { return m_view; }
 
private:
   int                                m_size;
   int                                m_depth;
   TextureCubeArrayView            m_view;
} DE_WARN_UNUSED_TYPE;
 
inline Vec4 TextureCubeArray::sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const
{
   return m_view.sample(sampler, s, t, r, q, lod);
}
 
inline Vec4 TextureCubeArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const
{
   return m_view.sampleOffset(sampler, s, t, r, q, lod, offset);
}
 
inline float TextureCubeArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const
{
   return m_view.sampleCompare(sampler, ref, s, t, r, q, lod);
}
 
inline float TextureCubeArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const
{
   return m_view.sampleCompareOffset(sampler, ref, s, t, r, q, lod, offset);
}
 
// Stream operators.
std::ostream&        operator<<        (std::ostream& str, TextureFormat::ChannelOrder order);
std::ostream&        operator<<        (std::ostream& str, TextureFormat::ChannelType type);
std::ostream&        operator<<        (std::ostream& str, TextureFormat format);
std::ostream&        operator<<        (std::ostream& str, CubeFace face);
std::ostream&        operator<<        (std::ostream& str, const ConstPixelBufferAccess& access);
 
} // tcu
 
#endif // _TCUTEXTURE_HPP