Merge gerrit/vulkan-cts-1.0.0 into gerrit/vulkan-cts-1.0.1
[platform/upstream/VK-GL-CTS.git] / framework / common / tcuTexture.hpp
1 #ifndef _TCUTEXTURE_HPP
2 #define _TCUTEXTURE_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program Tester Core
5  * ----------------------------------------
6  *
7  * Copyright 2014 The Android Open Source Project
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief Reference Texture Implementation.
24  *//*--------------------------------------------------------------------*/
25
26 #include "tcuDefs.hpp"
27 #include "tcuVector.hpp"
28 #include "rrGenericVector.hpp"
29 #include "deArrayBuffer.hpp"
30
31 #include <vector>
32 #include <ostream>
33
34 namespace tcu
35 {
36
37 /*--------------------------------------------------------------------*//*!
38  * \brief Texture format
39  *//*--------------------------------------------------------------------*/
40 class TextureFormat
41 {
42 public:
43         enum ChannelOrder
44         {
45                 R = 0,
46                 A,
47                 I,
48                 L,
49                 LA,
50                 RG,
51                 RA,
52                 RGB,
53                 RGBA,
54                 ARGB,
55                 BGR,
56                 BGRA,
57
58                 sR,
59                 sRG,
60                 sRGB,
61                 sRGBA,
62                 sBGR,
63                 sBGRA,
64
65                 D,
66                 S,
67                 DS,
68
69                 CHANNELORDER_LAST
70         };
71
72         enum ChannelType
73         {
74                 SNORM_INT8 = 0,
75                 SNORM_INT16,
76                 SNORM_INT32,
77                 UNORM_INT8,
78                 UNORM_INT16,
79                 UNORM_INT24,
80                 UNORM_INT32,
81                 UNORM_BYTE_44,
82                 UNORM_SHORT_565,
83                 UNORM_SHORT_555,
84                 UNORM_SHORT_4444,
85                 UNORM_SHORT_5551,
86                 UNORM_SHORT_1555,
87                 UNORM_INT_101010,
88                 SNORM_INT_1010102_REV,
89                 UNORM_INT_1010102_REV,
90                 UNSIGNED_BYTE_44,
91                 UNSIGNED_SHORT_565,
92                 UNSIGNED_SHORT_4444,
93                 UNSIGNED_SHORT_5551,
94                 SIGNED_INT_1010102_REV,
95                 UNSIGNED_INT_1010102_REV,
96                 UNSIGNED_INT_11F_11F_10F_REV,
97                 UNSIGNED_INT_999_E5_REV,
98                 UNSIGNED_INT_16_8_8,
99                 UNSIGNED_INT_24_8,
100                 UNSIGNED_INT_24_8_REV,
101                 SIGNED_INT8,
102                 SIGNED_INT16,
103                 SIGNED_INT32,
104                 UNSIGNED_INT8,
105                 UNSIGNED_INT16,
106                 UNSIGNED_INT24,
107                 UNSIGNED_INT32,
108                 HALF_FLOAT,
109                 FLOAT,
110                 FLOAT64,
111                 FLOAT_UNSIGNED_INT_24_8_REV,
112
113                 CHANNELTYPE_LAST
114         };
115
116         ChannelOrder    order;
117         ChannelType             type;
118
119         TextureFormat (ChannelOrder order_, ChannelType type_)
120                 : order (order_)
121                 , type  (type_)
122         {
123         }
124
125         TextureFormat (void)
126                 : order (CHANNELORDER_LAST)
127                 , type  (CHANNELTYPE_LAST)
128         {
129         }
130
131         int getPixelSize (void) const; //!< Deprecated, use tcu::getPixelSize(fmt)
132
133         bool operator== (const TextureFormat& other) const { return !(*this != other); }
134         bool operator!= (const TextureFormat& other) const
135         {
136                 return (order != other.order || type != other.type);
137         }
138 } DE_WARN_UNUSED_TYPE;
139
140 bool    isValid                         (TextureFormat format);
141 int             getPixelSize            (TextureFormat format);
142 int             getNumUsedChannels      (TextureFormat::ChannelOrder order);
143
144 /*--------------------------------------------------------------------*//*!
145  * \brief Texture swizzle
146  *//*--------------------------------------------------------------------*/
147 struct TextureSwizzle
148 {
149         enum Channel
150         {
151                 // \note CHANNEL_N must equal int N
152                 CHANNEL_0 = 0,
153                 CHANNEL_1,
154                 CHANNEL_2,
155                 CHANNEL_3,
156
157                 CHANNEL_ZERO,
158                 CHANNEL_ONE,
159
160                 CHANNEL_LAST
161         };
162
163         Channel components[4];
164 };
165
166 //! get the swizzle used to expand texture data with a given channel order to RGBA form
167 const TextureSwizzle& getChannelReadSwizzle             (TextureFormat::ChannelOrder order);
168
169 //! get the swizzle used to narrow RGBA form data to native texture data with a given channel order
170 const TextureSwizzle& getChannelWriteSwizzle    (TextureFormat::ChannelOrder order);
171
172 /*--------------------------------------------------------------------*//*!
173  * \brief Sampling parameters
174  *//*--------------------------------------------------------------------*/
175 class Sampler
176 {
177 public:
178         enum WrapMode
179         {
180                 CLAMP_TO_EDGE = 0,      //! Clamp to edge
181                 CLAMP_TO_BORDER,        //! Use border color at edge
182                 REPEAT_GL,                      //! Repeat with OpenGL semantics
183                 REPEAT_CL,                      //! Repeat with OpenCL semantics
184                 MIRRORED_REPEAT_GL,     //! Mirrored repeat with OpenGL semantics
185                 MIRRORED_REPEAT_CL, //! Mirrored repeat with OpenCL semantics
186                 MIRRORED_ONCE,          //! Mirrored once in negative directions
187
188                 WRAPMODE_LAST
189         };
190
191         enum FilterMode
192         {
193                 NEAREST = 0,
194                 LINEAR,
195
196                 NEAREST_MIPMAP_NEAREST,
197                 NEAREST_MIPMAP_LINEAR,
198                 LINEAR_MIPMAP_NEAREST,
199                 LINEAR_MIPMAP_LINEAR,
200
201                 FILTERMODE_LAST
202         };
203
204         enum CompareMode
205         {
206                 COMPAREMODE_NONE = 0,
207                 COMPAREMODE_LESS,
208                 COMPAREMODE_LESS_OR_EQUAL,
209                 COMPAREMODE_GREATER,
210                 COMPAREMODE_GREATER_OR_EQUAL,
211                 COMPAREMODE_EQUAL,
212                 COMPAREMODE_NOT_EQUAL,
213                 COMPAREMODE_ALWAYS,
214                 COMPAREMODE_NEVER,
215
216                 COMPAREMODE_LAST
217         };
218
219         enum DepthStencilMode
220         {
221                 MODE_DEPTH = 0,
222                 MODE_STENCIL,
223
224                 MODE_LAST
225         };
226
227         // Wrap control
228         WrapMode                        wrapS;
229         WrapMode                        wrapT;
230         WrapMode                        wrapR;
231
232         // Minifcation & magnification
233         FilterMode                      minFilter;
234         FilterMode                      magFilter;
235         float                           lodThreshold;           // lod <= lodThreshold ? magnified : minified
236
237         // Coordinate normalization
238         bool                            normalizedCoords;
239
240         // Shadow comparison
241         CompareMode                     compare;
242         int                                     compareChannel;
243
244         // Border color.
245         // \note It is setter's responsibility to guarantee that the values are representable
246         //       in sampled texture's internal format.
247         // \note It is setter's responsibility to guarantee that the format is compatible with the
248         //       sampled texture's internal format. Otherwise results are undefined.
249         rr::GenericVec4         borderColor;
250
251         // Seamless cube map filtering
252         bool                            seamlessCubeMap;
253
254         // Depth stencil mode
255         DepthStencilMode        depthStencilMode;
256
257         Sampler (WrapMode                       wrapS_,
258                          WrapMode                       wrapT_,
259                          WrapMode                       wrapR_,
260                          FilterMode                     minFilter_,
261                          FilterMode                     magFilter_,
262                          float                          lodThreshold_           = 0.0f,
263                          bool                           normalizedCoords_       = true,
264                          CompareMode            compare_                        = COMPAREMODE_NONE,
265                          int                            compareChannel_         = 0,
266                          const Vec4&            borderColor_            = Vec4(0.0f, 0.0f, 0.0f, 0.0f),
267                          bool                           seamlessCubeMap_        = false,
268                          DepthStencilMode       depthStencilMode_       = MODE_DEPTH)
269                 : wrapS                         (wrapS_)
270                 , wrapT                         (wrapT_)
271                 , wrapR                         (wrapR_)
272                 , minFilter                     (minFilter_)
273                 , magFilter                     (magFilter_)
274                 , lodThreshold          (lodThreshold_)
275                 , normalizedCoords      (normalizedCoords_)
276                 , compare                       (compare_)
277                 , compareChannel        (compareChannel_)
278                 , borderColor           (borderColor_)
279                 , seamlessCubeMap       (seamlessCubeMap_)
280                 , depthStencilMode      (depthStencilMode_)
281         {
282         }
283
284         Sampler (void)
285                 : wrapS                         (WRAPMODE_LAST)
286                 , wrapT                         (WRAPMODE_LAST)
287                 , wrapR                         (WRAPMODE_LAST)
288                 , minFilter                     (FILTERMODE_LAST)
289                 , magFilter                     (FILTERMODE_LAST)
290                 , lodThreshold          (0.0f)
291                 , normalizedCoords      (true)
292                 , compare                       (COMPAREMODE_NONE)
293                 , compareChannel        (0)
294                 , borderColor           (Vec4(0.0f, 0.0f, 0.0f, 0.0f))
295                 , seamlessCubeMap       (false)
296                 , depthStencilMode      (MODE_DEPTH)
297         {
298         }
299 } DE_WARN_UNUSED_TYPE;
300
301 // Calculate pitches for pixel data with no padding.
302 IVec3 calculatePackedPitch (const TextureFormat& format, const IVec3& size);
303
304 class TextureLevel;
305
306 /*--------------------------------------------------------------------*//*!
307  * \brief Read-only pixel data access
308  *
309  * ConstPixelBufferAccess encapsulates pixel data pointer along with
310  * format and layout information. It can be used for read-only access
311  * to arbitrary pixel buffers.
312  *
313  * Access objects are like iterators or pointers. They can be passed around
314  * as values and are valid as long as the storage doesn't change.
315  *//*--------------------------------------------------------------------*/
316 class ConstPixelBufferAccess
317 {
318 public:
319                                                         ConstPixelBufferAccess          (void);
320                                                         ConstPixelBufferAccess          (const TextureLevel& level);
321                                                         ConstPixelBufferAccess          (const TextureFormat& format, int width, int height, int depth, const void* data);
322                                                         ConstPixelBufferAccess          (const TextureFormat& format, const IVec3& size, const void* data);
323                                                         ConstPixelBufferAccess          (const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, const void* data);
324                                                         ConstPixelBufferAccess          (const TextureFormat& format, const IVec3& size, const IVec3& pitch, const void* data);
325
326         const TextureFormat&    getFormat                                       (void) const    { return m_format;                                      }
327         const IVec3&                    getSize                                         (void) const    { return m_size;                                        }
328         int                                             getWidth                                        (void) const    { return m_size.x();                            }
329         int                                             getHeight                                       (void) const    { return m_size.y();                            }
330         int                                             getDepth                                        (void) const    { return m_size.z();                            }
331         int                                             getPixelPitch                           (void) const    { return m_pitch.x();                           }
332         int                                             getRowPitch                                     (void) const    { return m_pitch.y();                           }
333         int                                             getSlicePitch                           (void) const    { return m_pitch.z();                           }
334         const IVec3&                    getPitch                                        (void) const    { return m_pitch;                                       }
335
336         const void*                             getDataPtr                                      (void) const    { return m_data;                                        }
337         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(); }
338
339         Vec4                                    getPixel                                        (int x, int y, int z = 0) const;
340         IVec4                                   getPixelInt                                     (int x, int y, int z = 0) const;
341         UVec4                                   getPixelUint                            (int x, int y, int z = 0) const { return getPixelInt(x, y, z).cast<deUint32>(); }
342
343         template<typename T>
344         Vector<T, 4>                    getPixelT                                       (int x, int y, int z = 0) const;
345
346         float                                   getPixDepth                                     (int x, int y, int z = 0) const;
347         int                                             getPixStencil                           (int x, int y, int z = 0) const;
348
349         Vec4                                    sample1D                                        (const Sampler& sampler, Sampler::FilterMode filter, float s, int level) const;
350         Vec4                                    sample2D                                        (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, int depth) const;
351         Vec4                                    sample3D                                        (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, float r) const;
352
353         Vec4                                    sample1DOffset                          (const Sampler& sampler, Sampler::FilterMode filter, float s, const IVec2& offset) const;
354         Vec4                                    sample2DOffset                          (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, const IVec3& offset) const;
355         Vec4                                    sample3DOffset                          (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, float r, const IVec3& offset) const;
356
357         float                                   sample1DCompare                         (const Sampler& sampler, Sampler::FilterMode filter, float ref, float s, const IVec2& offset) const;
358         float                                   sample2DCompare                         (const Sampler& sampler, Sampler::FilterMode filter, float ref, float s, float t, const IVec3& offset) const;
359
360 protected:
361         TextureFormat                   m_format;
362         IVec3                                   m_size;
363         IVec3                                   m_pitch;        //!< (pixelPitch, rowPitch, slicePitch)
364         mutable void*                   m_data;
365 } DE_WARN_UNUSED_TYPE;
366
367 /*--------------------------------------------------------------------*//*!
368  * \brief Read-write pixel data access
369  *
370  * This class extends read-only access object by providing write functionality.
371  *
372  * \note PixelBufferAccess may not have any data members nor add any
373  *               virtual functions. It must be possible to reinterpret_cast<>
374  *               PixelBufferAccess to ConstPixelBufferAccess.
375  *//*--------------------------------------------------------------------*/
376 class PixelBufferAccess : public ConstPixelBufferAccess
377 {
378 public:
379                                                 PixelBufferAccess       (void) {}
380                                                 PixelBufferAccess       (TextureLevel& level);
381                                                 PixelBufferAccess       (const TextureFormat& format, int width, int height, int depth, void* data);
382                                                 PixelBufferAccess       (const TextureFormat& format, const IVec3& size, void* data);
383                                                 PixelBufferAccess       (const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, void* data);
384                                                 PixelBufferAccess       (const TextureFormat& format, const IVec3& size, const IVec3& pitch, void* data);
385
386         void*                           getDataPtr                      (void) const { return m_data; }
387         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(); }
388
389         void                            setPixel                        (const tcu::Vec4& color, int x, int y, int z = 0) const;
390         void                            setPixel                        (const tcu::IVec4& color, int x, int y, int z = 0) const;
391         void                            setPixel                        (const tcu::UVec4& color, int x, int y, int z = 0) const { setPixel(color.cast<int>(), x, y, z); }
392
393         void                            setPixDepth                     (float depth, int x, int y, int z = 0) const;
394         void                            setPixStencil           (int stencil, int x, int y, int z = 0) const;
395 } DE_WARN_UNUSED_TYPE;
396
397 /*--------------------------------------------------------------------*//*!
398  * \brief Generic pixel data container
399  *
400  * This container supports all valid TextureFormat combinations and
401  * both 2D and 3D textures. To read or manipulate data access object must
402  * be queried using getAccess().
403  *//*--------------------------------------------------------------------*/
404 class TextureLevel
405 {
406 public:
407                                                                 TextureLevel            (void);
408                                                                 TextureLevel            (const TextureFormat& format);
409                                                                 TextureLevel            (const TextureFormat& format, int width, int height, int depth = 1);
410                                                                 ~TextureLevel           (void);
411
412         const IVec3&                            getSize                         (void) const    { return m_size;                }
413         int                                                     getWidth                        (void) const    { return m_size.x();    }
414         int                                                     getHeight                       (void) const    { return m_size.y();    }
415         int                                                     getDepth                        (void) const    { return m_size.z();    }
416         bool                                            isEmpty                         (void) const    { return m_size.x() * m_size.y() * m_size.z() == 0; }
417         const TextureFormat                     getFormat                       (void) const    { return m_format;      }
418
419         void                                            setStorage                      (const TextureFormat& format, int width, int heigth, int depth = 1);
420         void                                            setSize                         (int width, int height, int depth = 1);
421
422         PixelBufferAccess                       getAccess                       (void)                  { return isEmpty() ? PixelBufferAccess() : PixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr());                       }
423         ConstPixelBufferAccess          getAccess                       (void) const    { return isEmpty() ? ConstPixelBufferAccess() : ConstPixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr());     }
424
425 private:
426         void*                                           getPtr                          (void)                  { return m_data.getPtr(); }
427         const void*                                     getPtr                          (void) const    { return m_data.getPtr(); }
428
429         TextureFormat                           m_format;
430         IVec3                                           m_size;
431         de::ArrayBuffer<deUint8>        m_data;
432
433         friend class ConstPixelBufferAccess;
434 } DE_WARN_UNUSED_TYPE;
435
436 Vec4    sampleLevelArray1D                              (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, int level, float lod);
437 Vec4    sampleLevelArray2D                              (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, int depth, float lod);
438 Vec4    sampleLevelArray3D                              (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float r, float lod);
439
440 Vec4    sampleLevelArray1DOffset                (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float lod, const IVec2& offset);
441 Vec4    sampleLevelArray2DOffset                (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float lod, const IVec3& offset);
442 Vec4    sampleLevelArray3DOffset                (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset);
443
444 float   sampleLevelArray1DCompare               (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float ref, float s, float lod, const IVec2& offset);
445 float   sampleLevelArray2DCompare               (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float ref, float s, float t, float lod, const IVec3& offset);
446
447 Vec4    gatherArray2DOffsets                    (const ConstPixelBufferAccess& src, const Sampler& sampler, float s, float t, int depth, int componentNdx, const IVec2 (&offsets)[4]);
448 Vec4    gatherArray2DOffsetsCompare             (const ConstPixelBufferAccess& src, const Sampler& sampler, float ref, float s, float t, int depth, const IVec2 (&offsets)[4]);
449
450 enum CubeFace
451 {
452         CUBEFACE_NEGATIVE_X = 0,
453         CUBEFACE_POSITIVE_X,
454         CUBEFACE_NEGATIVE_Y,
455         CUBEFACE_POSITIVE_Y,
456         CUBEFACE_NEGATIVE_Z,
457         CUBEFACE_POSITIVE_Z,
458
459         CUBEFACE_LAST
460 };
461
462 /*--------------------------------------------------------------------*//*!
463  * \brief Coordinates projected onto cube face.
464  *//*--------------------------------------------------------------------*/
465 template<typename T>
466 struct CubeFaceCoords
467 {
468         CubeFace                face;
469         T                               s;
470         T                               t;
471
472                                         CubeFaceCoords          (CubeFace face_, T s_, T t_) : face(face_), s(s_), t(t_) {}
473                                         CubeFaceCoords          (CubeFace face_, const Vector<T, 2>& c) : face(face_), s(c.x()), t(c.y()) {}
474 } DE_WARN_UNUSED_TYPE;
475
476 typedef CubeFaceCoords<float>   CubeFaceFloatCoords;
477 typedef CubeFaceCoords<int>             CubeFaceIntCoords;
478
479 CubeFace                                selectCubeFace                  (const Vec3& coords);
480 Vec2                                    projectToFace                   (CubeFace face, const Vec3& coords);
481 CubeFaceFloatCoords             getCubeFaceCoords               (const Vec3& coords);
482 CubeFaceIntCoords               remapCubeEdgeCoords             (const CubeFaceIntCoords& coords, int size);
483
484 /*--------------------------------------------------------------------*//*!
485  * \brief 1D Texture View
486  *//*--------------------------------------------------------------------*/
487 class Texture1DView
488 {
489 public:
490                                                                         Texture1DView           (int numLevels, const ConstPixelBufferAccess* levels);
491
492         int                                                             getNumLevels            (void) const    { return m_numLevels;                                                                           }
493         int                                                             getWidth                        (void) const    { return m_numLevels > 0 ? m_levels[0].getWidth()       : 0;    }
494         const ConstPixelBufferAccess&   getLevel                        (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];   }
495         const ConstPixelBufferAccess*   getLevels                       (void) const    { return m_levels;                                                                                      }
496
497         Vec4                                                    sample                          (const Sampler& sampler, float s, float lod) const;
498         Vec4                                                    sampleOffset            (const Sampler& sampler, float s, float lod, deInt32 offset) const;
499         float                                                   sampleCompare           (const Sampler& sampler, float ref, float s, float lod) const;
500         float                                                   sampleCompareOffset     (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const;
501
502 protected:
503         int                                                             m_numLevels;
504         const ConstPixelBufferAccess*   m_levels;
505 } DE_WARN_UNUSED_TYPE;
506
507 inline Texture1DView::Texture1DView (int numLevels, const ConstPixelBufferAccess* levels)
508         : m_numLevels   (numLevels)
509         , m_levels              (levels)
510 {
511         DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
512 }
513
514 inline Vec4 Texture1DView::sample (const Sampler& sampler, float s, float lod) const
515 {
516         return sampleLevelArray1D(m_levels, m_numLevels, sampler, s, 0 /* depth */, lod);
517 }
518
519 inline Vec4 Texture1DView::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
520 {
521         return sampleLevelArray1DOffset(m_levels, m_numLevels, sampler, s, lod, IVec2(offset, 0));
522 }
523
524 inline float Texture1DView::sampleCompare (const Sampler& sampler, float ref, float s, float lod) const
525 {
526         return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(0, 0));
527 }
528
529 inline float Texture1DView::sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const
530 {
531         return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(offset, 0));
532 }
533
534 /*--------------------------------------------------------------------*//*!
535  * \brief 2D Texture View
536  *//*--------------------------------------------------------------------*/
537 class Texture2DView
538 {
539 public:
540                                                                         Texture2DView           (int numLevels, const ConstPixelBufferAccess* levels);
541
542         int                                                             getNumLevels            (void) const    { return m_numLevels;                                                                           }
543         int                                                             getWidth                        (void) const    { return m_numLevels > 0 ? m_levels[0].getWidth()       : 0;    }
544         int                                                             getHeight                       (void) const    { return m_numLevels > 0 ? m_levels[0].getHeight()      : 0;    }
545         const ConstPixelBufferAccess&   getLevel                        (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];   }
546         const ConstPixelBufferAccess*   getLevels                       (void) const    { return m_levels;                                                                                      }
547
548         Vec4                                                    sample                          (const Sampler& sampler, float s, float t, float lod) const;
549         Vec4                                                    sampleOffset            (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
550         float                                                   sampleCompare           (const Sampler& sampler, float ref, float s, float t, float lod) const;
551         float                                                   sampleCompareOffset     (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
552
553         Vec4                                                    gatherOffsets           (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
554         Vec4                                                    gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
555
556 protected:
557         int                                                             m_numLevels;
558         const ConstPixelBufferAccess*   m_levels;
559 } DE_WARN_UNUSED_TYPE;
560
561 inline Texture2DView::Texture2DView (int numLevels, const ConstPixelBufferAccess* levels)
562         : m_numLevels   (numLevels)
563         , m_levels              (levels)
564 {
565         DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
566 }
567
568 inline Vec4 Texture2DView::sample (const Sampler& sampler, float s, float t, float lod) const
569 {
570         return sampleLevelArray2D(m_levels, m_numLevels, sampler, s, t, 0 /* depth */, lod);
571 }
572
573 inline Vec4 Texture2DView::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
574 {
575         return sampleLevelArray2DOffset(m_levels, m_numLevels, sampler, s, t, lod, IVec3(offset.x(), offset.y(), 0));
576 }
577
578 inline float Texture2DView::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
579 {
580         return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(0, 0, 0));
581 }
582
583 inline float Texture2DView::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
584 {
585         return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(offset.x(), offset.y(), 0));
586 }
587
588 inline Vec4 Texture2DView::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
589 {
590         return gatherArray2DOffsets(m_levels[0], sampler, s, t, 0, componentNdx, offsets);
591 }
592
593 inline Vec4 Texture2DView::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
594 {
595         return gatherArray2DOffsetsCompare(m_levels[0], sampler, ref, s, t, 0, offsets);
596 }
597
598 /*--------------------------------------------------------------------*//*!
599  * \brief Base class for textures that have single mip-map pyramid
600  *//*--------------------------------------------------------------------*/
601 class TextureLevelPyramid
602 {
603 public:
604                                                                         TextureLevelPyramid     (const TextureFormat& format, int numLevels);
605                                                                         TextureLevelPyramid     (const TextureLevelPyramid& other);
606                                                                         ~TextureLevelPyramid(void);
607
608         const TextureFormat&                    getFormat                       (void) const                    { return m_format;                                      }
609         int                                                             getNumLevels            (void) const                    { return (int)m_access.size();          }
610
611         bool                                                    isLevelEmpty            (int levelNdx) const    { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[(size_t)levelNdx].empty();        }
612         const ConstPixelBufferAccess&   getLevel                        (int levelNdx) const    { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_access[(size_t)levelNdx];                      }
613         const PixelBufferAccess&                getLevel                        (int levelNdx)                  { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_access[(size_t)levelNdx];                      }
614
615         const ConstPixelBufferAccess*   getLevels                       (void) const                    { return &m_access[0];                          }
616         const PixelBufferAccess*                getLevels                       (void)                                  { return &m_access[0];                          }
617
618         void                                                    allocLevel                      (int levelNdx, int width, int height, int depth);
619         void                                                    clearLevel                      (int levelNdx);
620
621         TextureLevelPyramid&                    operator=                       (const TextureLevelPyramid& other);
622
623 private:
624         typedef de::ArrayBuffer<deUint8> LevelData;
625
626         TextureFormat                                   m_format;
627         std::vector<LevelData>                  m_data;
628         std::vector<PixelBufferAccess>  m_access;
629 } DE_WARN_UNUSED_TYPE;
630
631 /*--------------------------------------------------------------------*//*!
632  * \brief 1D Texture reference implementation
633  *//*--------------------------------------------------------------------*/
634 class Texture1D : private TextureLevelPyramid
635 {
636 public:
637                                                                         Texture1D                       (const TextureFormat& format, int width);
638                                                                         Texture1D                       (const Texture1D& other);
639                                                                         ~Texture1D                      (void);
640
641         int                                                             getWidth                        (void) const    { return m_width;       }
642         const Texture1DView&                    getView                         (void) const    { return m_view;        }
643
644         void                                                    allocLevel                      (int levelNdx);
645
646         // Sampling
647         Vec4                                                    sample                          (const Sampler& sampler, float s, float lod) const;
648         Vec4                                                    sampleOffset            (const Sampler& sampler, float s, float lod, deInt32 offset) const;
649
650         using TextureLevelPyramid::getFormat;
651         using TextureLevelPyramid::getNumLevels;
652         using TextureLevelPyramid::getLevel;
653         using TextureLevelPyramid::clearLevel;
654         using TextureLevelPyramid::isLevelEmpty;
655
656         Texture1D&                                              operator=                       (const Texture1D& other);
657
658         operator Texture1DView (void) const { return m_view; }
659
660 private:
661         int                                                             m_width;
662         Texture1DView                                   m_view;
663 } DE_WARN_UNUSED_TYPE;
664
665 inline Vec4 Texture1D::sample (const Sampler& sampler, float s, float lod) const
666 {
667         return m_view.sample(sampler, s, lod);
668 }
669
670 inline Vec4 Texture1D::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
671 {
672         return m_view.sampleOffset(sampler, s, lod, offset);
673 }
674
675 /*--------------------------------------------------------------------*//*!
676  * \brief 2D Texture reference implementation
677  *//*--------------------------------------------------------------------*/
678 class Texture2D : private TextureLevelPyramid
679 {
680 public:
681                                                                         Texture2D                       (const TextureFormat& format, int width, int height);
682                                                                         Texture2D                       (const Texture2D& other);
683                                                                         ~Texture2D                      (void);
684
685         int                                                             getWidth                        (void) const    { return m_width;       }
686         int                                                             getHeight                       (void) const    { return m_height;      }
687         const Texture2DView&                    getView                         (void) const    { return m_view;        }
688
689         void                                                    allocLevel                      (int levelNdx);
690
691         // Sampling
692         Vec4                                                    sample                          (const Sampler& sampler, float s, float t, float lod) const;
693         Vec4                                                    sampleOffset            (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
694         float                                                   sampleCompare           (const Sampler& sampler, float ref, float s, float t, float lod) const;
695         float                                                   sampleCompareOffset     (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
696
697         Vec4                                                    gatherOffsets           (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
698         Vec4                                                    gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
699
700         using TextureLevelPyramid::getFormat;
701         using TextureLevelPyramid::getNumLevels;
702         using TextureLevelPyramid::getLevel;
703         using TextureLevelPyramid::clearLevel;
704         using TextureLevelPyramid::isLevelEmpty;
705
706         Texture2D&                                              operator=                       (const Texture2D& other);
707
708         operator Texture2DView (void) const { return m_view; }
709
710 private:
711         int                                                             m_width;
712         int                                                             m_height;
713         Texture2DView                                   m_view;
714 } DE_WARN_UNUSED_TYPE;
715
716 inline Vec4 Texture2D::sample (const Sampler& sampler, float s, float t, float lod) const
717 {
718         return m_view.sample(sampler, s, t, lod);
719 }
720
721 inline Vec4 Texture2D::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
722 {
723         return m_view.sampleOffset(sampler, s, t, lod, offset);
724 }
725
726 inline float Texture2D::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
727 {
728         return m_view.sampleCompare(sampler, ref, s, t, lod);
729 }
730
731 inline float Texture2D::sampleCompareOffset     (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
732 {
733         return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
734 }
735
736 inline Vec4 Texture2D::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
737 {
738         return m_view.gatherOffsets(sampler, s, t, componentNdx, offsets);
739 }
740
741 inline Vec4 Texture2D::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
742 {
743         return m_view.gatherOffsetsCompare(sampler, ref, s, t, offsets);
744 }
745
746 /*--------------------------------------------------------------------*//*!
747  * \brief Cube Map Texture View
748  *//*--------------------------------------------------------------------*/
749 class TextureCubeView
750 {
751 public:
752                                                                         TextureCubeView         (void);
753                                                                         TextureCubeView         (int numLevels, const ConstPixelBufferAccess* const (&levels)[CUBEFACE_LAST]);
754
755         int                                                             getNumLevels            (void) const    { return m_numLevels;                                                                           }
756         int                                                             getSize                         (void) const    { return m_numLevels > 0 ? m_levels[0][0].getWidth() : 0;       }
757         const ConstPixelBufferAccess&   getLevelFace            (int ndx, CubeFace face) const  { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[face][ndx];     }
758         const ConstPixelBufferAccess*   getFaceLevels           (CubeFace face) const                   { return m_levels[face];                                        }
759
760         Vec4                                                    sample                          (const Sampler& sampler, float s, float t, float p, float lod) const;
761         float                                                   sampleCompare           (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
762
763         Vec4                                                    gather                          (const Sampler& sampler, float s, float t, float r, int componentNdx) const;
764         Vec4                                                    gatherCompare           (const Sampler& sampler, float ref, float s, float t, float r) const;
765
766 protected:
767         int                                                             m_numLevels;
768         const ConstPixelBufferAccess*   m_levels[CUBEFACE_LAST];
769 } DE_WARN_UNUSED_TYPE;
770
771 /*--------------------------------------------------------------------*//*!
772  * \brief Cube Map Texture reference implementation
773  *//*--------------------------------------------------------------------*/
774 class TextureCube
775 {
776 public:
777                                                                         TextureCube                     (const TextureFormat& format, int size);
778                                                                         TextureCube                     (const TextureCube& other);
779                                                                         ~TextureCube            (void);
780
781         const TextureFormat&                    getFormat                       (void) const    { return m_format;      }
782         int                                                             getSize                         (void) const    { return m_size;        }
783
784         int                                                             getNumLevels            (void) const                                    { return (int)m_access[0].size();       }
785         const ConstPixelBufferAccess&   getLevelFace            (int ndx, CubeFace face) const  { DE_ASSERT(de::inBounds(ndx, 0, getNumLevels())); return m_access[face][(size_t)ndx];  }
786         const PixelBufferAccess&                getLevelFace            (int ndx, CubeFace face)                { DE_ASSERT(de::inBounds(ndx, 0, getNumLevels())); return m_access[face][(size_t)ndx];  }
787
788         void                                                    allocLevel                      (CubeFace face, int levelNdx);
789         void                                                    clearLevel                      (CubeFace face, int levelNdx);
790         bool                                                    isLevelEmpty            (CubeFace face, int levelNdx) const     { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[face][(size_t)levelNdx].empty();  }
791
792         Vec4                                                    sample                          (const Sampler& sampler, float s, float t, float p, float lod) const;
793         float                                                   sampleCompare           (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
794
795         Vec4                                                    gather                          (const Sampler& sampler, float s, float t, float r, int componentNdx) const;
796         Vec4                                                    gatherCompare           (const Sampler& sampler, float ref, float s, float t, float r) const;
797
798         TextureCube&                                    operator=                       (const TextureCube& other);
799
800         operator TextureCubeView (void) const { return m_view; }
801
802 private:
803         typedef de::ArrayBuffer<deUint8> LevelData;
804
805         TextureFormat                                   m_format;
806         int                                                             m_size;
807         std::vector<LevelData>                  m_data[CUBEFACE_LAST];
808         std::vector<PixelBufferAccess>  m_access[CUBEFACE_LAST];
809         TextureCubeView                                 m_view;
810 } DE_WARN_UNUSED_TYPE;
811
812 inline Vec4 TextureCube::sample (const Sampler& sampler, float s, float t, float p, float lod) const
813 {
814         return m_view.sample(sampler, s, t, p, lod);
815 }
816
817 inline float TextureCube::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
818 {
819         return m_view.sampleCompare(sampler, ref, s, t, r, lod);
820 }
821
822 inline Vec4 TextureCube::gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const
823 {
824         return m_view.gather(sampler, s, t, r, componentNdx);
825 }
826
827 inline Vec4 TextureCube::gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const
828 {
829         return m_view.gatherCompare(sampler, ref, s, t, r);
830 }
831
832 /*--------------------------------------------------------------------*//*!
833  * \brief 1D Array Texture View
834  *//*--------------------------------------------------------------------*/
835 class Texture1DArrayView
836 {
837 public:
838                                                                         Texture1DArrayView      (int numLevels, const ConstPixelBufferAccess* levels);
839
840         int                                                             getWidth                        (void) const    { return m_numLevels > 0 ? m_levels[0].getWidth()       : 0;    }
841         int                                                             getNumLayers            (void) const    { return m_numLevels > 0 ? m_levels[0].getHeight()      : 0;    }
842         int                                                             getNumLevels            (void) const    { return m_numLevels;                                                                           }
843         const ConstPixelBufferAccess&   getLevel                        (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];   }
844         const ConstPixelBufferAccess*   getLevels                       (void) const    { return m_levels;                                                                                      }
845
846         Vec4                                                    sample                          (const Sampler& sampler, float s, float t, float lod) const;
847         Vec4                                                    sampleOffset            (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
848         float                                                   sampleCompare           (const Sampler& sampler, float ref, float s, float t, float lod) const;
849         float                                                   sampleCompareOffset     (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
850
851 protected:
852         int                                                             selectLayer                     (float r) const;
853
854         int                                                             m_numLevels;
855         const ConstPixelBufferAccess*   m_levels;
856 } DE_WARN_UNUSED_TYPE;
857
858 /*--------------------------------------------------------------------*//*!
859  * \brief 2D Array Texture View
860  *//*--------------------------------------------------------------------*/
861 class Texture2DArrayView
862 {
863 public:
864                                                                         Texture2DArrayView      (int numLevels, const ConstPixelBufferAccess* levels);
865
866         int                                                             getWidth                        (void) const    { return m_numLevels > 0 ? m_levels[0].getWidth()       : 0;    }
867         int                                                             getHeight                       (void) const    { return m_numLevels > 0 ? m_levels[0].getHeight()      : 0;    }
868         int                                                             getNumLayers            (void) const    { return m_numLevels > 0 ? m_levels[0].getDepth()       : 0;    }
869         int                                                             getNumLevels            (void) const    { return m_numLevels;                                                                           }
870         const ConstPixelBufferAccess&   getLevel                        (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];   }
871         const ConstPixelBufferAccess*   getLevels                       (void) const    { return m_levels;                                                                                      }
872
873         Vec4                                                    sample                          (const Sampler& sampler, float s, float t, float r, float lod) const;
874         Vec4                                                    sampleOffset            (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
875         float                                                   sampleCompare           (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
876         float                                                   sampleCompareOffset     (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
877
878         Vec4                                                    gatherOffsets           (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
879         Vec4                                                    gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
880
881 protected:
882         int                                                             selectLayer                     (float r) const;
883
884         int                                                             m_numLevels;
885         const ConstPixelBufferAccess*   m_levels;
886 } DE_WARN_UNUSED_TYPE;
887
888 /*--------------------------------------------------------------------*//*!
889  * \brief 1D Array Texture reference implementation
890  *//*--------------------------------------------------------------------*/
891 class Texture1DArray : private TextureLevelPyramid
892 {
893 public:
894                                                                         Texture1DArray          (const TextureFormat& format, int width, int numLayers);
895                                                                         Texture1DArray          (const Texture1DArray& other);
896                                                                         ~Texture1DArray         (void);
897
898         int                                                             getWidth                        (void) const    { return m_width;               }
899         int                                                             getNumLayers            (void) const    { return m_numLayers;   }
900
901         void                                                    allocLevel                      (int levelNdx);
902
903         using TextureLevelPyramid::getFormat;
904         using TextureLevelPyramid::getNumLevels;
905         using TextureLevelPyramid::getLevel;
906         using TextureLevelPyramid::clearLevel;
907         using TextureLevelPyramid::isLevelEmpty;
908
909         Vec4                                                    sample                          (const Sampler& sampler, float s, float t, float lod) const;
910         Vec4                                                    sampleOffset            (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
911         float                                                   sampleCompare           (const Sampler& sampler, float ref, float s, float t, float lod) const;
912         float                                                   sampleCompareOffset     (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
913
914         Texture1DArray&                                 operator=                       (const Texture1DArray& other);
915
916         operator Texture1DArrayView (void) const { return m_view; }
917
918 private:
919         int                                                             m_width;
920         int                                                             m_numLayers;
921         Texture1DArrayView                              m_view;
922 } DE_WARN_UNUSED_TYPE;
923
924 inline Vec4 Texture1DArray::sample (const Sampler& sampler, float s, float t, float lod) const
925 {
926         return m_view.sample(sampler, s, t, lod);
927 }
928
929 inline Vec4 Texture1DArray::sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const
930 {
931         return m_view.sampleOffset(sampler, s, t, lod, offset);
932 }
933
934 inline float Texture1DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
935 {
936         return m_view.sampleCompare(sampler, ref, s, t, lod);
937 }
938
939 inline float Texture1DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const
940 {
941         return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
942 }
943
944 /*--------------------------------------------------------------------*//*!
945  * \brief 2D Array Texture reference implementation
946  *//*--------------------------------------------------------------------*/
947 class Texture2DArray : private TextureLevelPyramid
948 {
949 public:
950                                                                         Texture2DArray          (const TextureFormat& format, int width, int height, int numLayers);
951                                                                         Texture2DArray          (const Texture2DArray& other);
952                                                                         ~Texture2DArray         (void);
953
954         int                                                             getWidth                        (void) const    { return m_width;               }
955         int                                                             getHeight                       (void) const    { return m_height;              }
956         int                                                             getNumLayers            (void) const    { return m_numLayers;   }
957
958         void                                                    allocLevel                      (int levelNdx);
959
960         using TextureLevelPyramid::getFormat;
961         using TextureLevelPyramid::getNumLevels;
962         using TextureLevelPyramid::getLevel;
963         using TextureLevelPyramid::clearLevel;
964         using TextureLevelPyramid::isLevelEmpty;
965
966         Vec4                                                    sample                          (const Sampler& sampler, float s, float t, float r, float lod) const;
967         Vec4                                                    sampleOffset            (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
968         float                                                   sampleCompare           (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
969         float                                                   sampleCompareOffset     (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
970
971         Vec4                                                    gatherOffsets           (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
972         Vec4                                                    gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
973
974         Texture2DArray&                                 operator=                       (const Texture2DArray& other);
975
976         operator Texture2DArrayView (void) const { return m_view; }
977
978 private:
979         int                                                             m_width;
980         int                                                             m_height;
981         int                                                             m_numLayers;
982         Texture2DArrayView                              m_view;
983 } DE_WARN_UNUSED_TYPE;
984
985 inline Vec4 Texture2DArray::sample (const Sampler& sampler, float s, float t, float r, float lod) const
986 {
987         return m_view.sample(sampler, s, t, r, lod);
988 }
989
990 inline Vec4 Texture2DArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const
991 {
992         return m_view.sampleOffset(sampler, s, t, r, lod, offset);
993 }
994
995 inline float Texture2DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
996 {
997         return m_view.sampleCompare(sampler, ref, s, t, r, lod);
998 }
999
1000 inline float Texture2DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const
1001 {
1002         return m_view.sampleCompareOffset(sampler, ref, s, t, r, lod, offset);
1003 }
1004
1005 inline Vec4 Texture2DArray::gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const
1006 {
1007         return m_view.gatherOffsets(sampler, s, t, r, componentNdx, offsets);
1008 }
1009
1010 inline Vec4 Texture2DArray::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const
1011 {
1012         return m_view.gatherOffsetsCompare(sampler, ref, s, t, r, offsets);
1013 }
1014
1015 /*--------------------------------------------------------------------*//*!
1016  * \brief 3D Texture View
1017  *//*--------------------------------------------------------------------*/
1018 class Texture3DView
1019 {
1020 public:
1021                                                                         Texture3DView           (int numLevels, const ConstPixelBufferAccess* levels);
1022
1023         int                                                             getWidth                        (void) const    { return m_numLevels > 0 ? m_levels[0].getWidth()       : 0;    }
1024         int                                                             getHeight                       (void) const    { return m_numLevels > 0 ? m_levels[0].getHeight()      : 0;    }
1025         int                                                             getDepth                        (void) const    { return m_numLevels > 0 ? m_levels[0].getDepth()       : 0;    }
1026         int                                                             getNumLevels            (void) const    { return m_numLevels;                                                                           }
1027         const ConstPixelBufferAccess&   getLevel                        (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];   }
1028         const ConstPixelBufferAccess*   getLevels                       (void) const    { return m_levels;                                                                                      }
1029
1030         Vec4                                                    sample                          (const Sampler& sampler, float s, float t, float r, float lod) const;
1031         Vec4                                                    sampleOffset            (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
1032
1033 protected:
1034         int                                                             m_numLevels;
1035         const ConstPixelBufferAccess*   m_levels;
1036 } DE_WARN_UNUSED_TYPE;
1037
1038 inline Vec4 Texture3DView::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1039 {
1040         return sampleLevelArray3D(m_levels, m_numLevels, sampler, s, t, r, lod);
1041 }
1042
1043 inline Vec4 Texture3DView::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
1044 {
1045         return sampleLevelArray3DOffset(m_levels, m_numLevels, sampler, s, t, r, lod, offset);
1046 }
1047
1048 /*--------------------------------------------------------------------*//*!
1049  * \brief 3D Texture reference implementation
1050  *//*--------------------------------------------------------------------*/
1051 class Texture3D : private TextureLevelPyramid
1052 {
1053 public:
1054                                                                         Texture3D                       (const TextureFormat& format, int width, int height, int depth);
1055                                                                         Texture3D                       (const Texture3D& other);
1056                                                                         ~Texture3D                      (void);
1057
1058         int                                                             getWidth                        (void) const    { return m_width;       }
1059         int                                                             getHeight                       (void) const    { return m_height;      }
1060         int                                                             getDepth                        (void) const    { return m_depth;       }
1061
1062         void                                                    allocLevel                      (int levelNdx);
1063
1064         using TextureLevelPyramid::getFormat;
1065         using TextureLevelPyramid::getNumLevels;
1066         using TextureLevelPyramid::getLevel;
1067         using TextureLevelPyramid::clearLevel;
1068         using TextureLevelPyramid::isLevelEmpty;
1069
1070         Vec4                                                    sample                          (const Sampler& sampler, float s, float t, float r, float lod) const;
1071         Vec4                                                    sampleOffset            (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
1072
1073         Texture3D&                                              operator=                       (const Texture3D& other);
1074
1075         operator Texture3DView (void) const { return m_view; }
1076
1077 private:
1078         int                                                             m_width;
1079         int                                                             m_height;
1080         int                                                             m_depth;
1081         Texture3DView                                   m_view;
1082 } DE_WARN_UNUSED_TYPE;
1083
1084 inline Vec4 Texture3D::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1085 {
1086         return m_view.sample(sampler, s, t, r, lod);
1087 }
1088
1089 inline Vec4 Texture3D::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
1090 {
1091         return m_view.sampleOffset(sampler, s, t, r, lod, offset);
1092 }
1093
1094 /*--------------------------------------------------------------------*//*!
1095  * \brief Cube Map Array Texture View
1096  *//*--------------------------------------------------------------------*/
1097 class TextureCubeArrayView
1098 {
1099 public:
1100                                                                         TextureCubeArrayView    (int numLevels, const ConstPixelBufferAccess* levels);
1101
1102         int                                                             getSize                                 (void) const    { return m_numLevels > 0 ? m_levels[0].getWidth()       : 0;    }
1103         int                                                             getDepth                                (void) const    { return m_numLevels > 0 ? m_levels[0].getDepth()       : 0;    }
1104         int                                                             getNumLayers                    (void) const    { return getDepth()     / 6;    }
1105         int                                                             getNumLevels                    (void) const    { return m_numLevels;                                                                           }
1106         const ConstPixelBufferAccess&   getLevel                                (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];   }
1107         const ConstPixelBufferAccess*   getLevels                               (void) const    { return m_levels;                                                                                      }
1108
1109         Vec4                                                    sample                                  (const Sampler& sampler, float s, float t, float r, float q, float lod) const;
1110         Vec4                                                    sampleOffset                    (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1111         float                                                   sampleCompare                   (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
1112         float                                                   sampleCompareOffset             (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1113
1114 protected:
1115         int                                                             selectLayer                             (float q) const;
1116
1117         int                                                             m_numLevels;
1118         const ConstPixelBufferAccess*   m_levels;
1119 } DE_WARN_UNUSED_TYPE;
1120
1121 /*--------------------------------------------------------------------*//*!
1122  * \brief Cube Map Array Texture reference implementation
1123  *//*--------------------------------------------------------------------*/
1124 class TextureCubeArray : private TextureLevelPyramid
1125 {
1126 public:
1127                                                                         TextureCubeArray        (const TextureFormat& format, int size, int depth);
1128                                                                         TextureCubeArray        (const TextureCubeArray& other);
1129                                                                         ~TextureCubeArray       (void);
1130
1131         int                                                             getSize                         (void) const    { return m_size;        }
1132         int                                                             getDepth                        (void) const    { return m_depth;       }
1133
1134         void                                                    allocLevel                      (int levelNdx);
1135
1136         using TextureLevelPyramid::getFormat;
1137         using TextureLevelPyramid::getNumLevels;
1138         using TextureLevelPyramid::getLevel;
1139         using TextureLevelPyramid::clearLevel;
1140         using TextureLevelPyramid::isLevelEmpty;
1141
1142         Vec4                                                    sample                          (const Sampler& sampler, float s, float t, float r, float q, float lod) const;
1143         Vec4                                                    sampleOffset            (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1144         float                                                   sampleCompare           (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
1145         float                                                   sampleCompareOffset     (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1146
1147         TextureCubeArray&                               operator=                       (const TextureCubeArray& other);
1148
1149         operator TextureCubeArrayView (void) const { return m_view; }
1150
1151 private:
1152         int                                                             m_size;
1153         int                                                             m_depth;
1154         TextureCubeArrayView                    m_view;
1155 } DE_WARN_UNUSED_TYPE;
1156
1157 inline Vec4 TextureCubeArray::sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const
1158 {
1159         return m_view.sample(sampler, s, t, r, q, lod);
1160 }
1161
1162 inline Vec4 TextureCubeArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const
1163 {
1164         return m_view.sampleOffset(sampler, s, t, r, q, lod, offset);
1165 }
1166
1167 inline float TextureCubeArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const
1168 {
1169         return m_view.sampleCompare(sampler, ref, s, t, r, q, lod);
1170 }
1171
1172 inline float TextureCubeArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const
1173 {
1174         return m_view.sampleCompareOffset(sampler, ref, s, t, r, q, lod, offset);
1175 }
1176
1177 // Stream operators.
1178 std::ostream&           operator<<              (std::ostream& str, TextureFormat::ChannelOrder order);
1179 std::ostream&           operator<<              (std::ostream& str, TextureFormat::ChannelType type);
1180 std::ostream&           operator<<              (std::ostream& str, TextureFormat format);
1181 std::ostream&           operator<<              (std::ostream& str, CubeFace face);
1182 std::ostream&           operator<<              (std::ostream& str, const ConstPixelBufferAccess& access);
1183
1184 } // tcu
1185
1186 #endif // _TCUTEXTURE_HPP