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