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 ABGR,
56 BGR,
57 BGRA,
58
59 sR,
60 sRG,
61 sRGB,
62 sRGBA,
63 sBGR,
64 sBGRA,
65
66 D,
67 S,
68 DS,
69
70 CHANNELORDER_LAST
71 };
72
73 enum ChannelType
74 {
75 SNORM_INT8 = 0,
76 SNORM_INT16,
77 SNORM_INT32,
78 UNORM_INT8,
79 UNORM_INT16,
80 UNORM_INT24,
81 UNORM_INT32,
82 UNORM_BYTE_44,
83 UNORM_SHORT_565,
84 UNORM_SHORT_555,
85 UNORM_SHORT_4444,
86 UNORM_SHORT_5551,
87 UNORM_SHORT_1555,
88 UNORM_INT_101010,
89 SNORM_INT_1010102_REV,
90 UNORM_INT_1010102_REV,
91 UNSIGNED_BYTE_44,
92 UNSIGNED_SHORT_565,
93 UNSIGNED_SHORT_4444,
94 UNSIGNED_SHORT_5551,
95 SIGNED_INT_1010102_REV,
96 UNSIGNED_INT_1010102_REV,
97 UNSIGNED_INT_11F_11F_10F_REV,
98 UNSIGNED_INT_999_E5_REV,
99 UNSIGNED_INT_16_8_8,
100 UNSIGNED_INT_24_8,
101 UNSIGNED_INT_24_8_REV,
102 SIGNED_INT8,
103 SIGNED_INT16,
104 SIGNED_INT32,
105 SIGNED_INT64,
106 UNSIGNED_INT8,
107 UNSIGNED_INT16,
108 UNSIGNED_INT24,
109 UNSIGNED_INT32,
110 UNSIGNED_INT64,
111 HALF_FLOAT,
112 FLOAT,
113 FLOAT64,
114 FLOAT_UNSIGNED_INT_24_8_REV,
115
116 UNORM_SHORT_10,
117 UNORM_SHORT_12,
118
119 USCALED_INT8,
120 USCALED_INT16,
121 SSCALED_INT8,
122 SSCALED_INT16,
123 USCALED_INT_1010102_REV,
124 SSCALED_INT_1010102_REV,
125
126 CHANNELTYPE_LAST
127 };
128
129 ChannelOrder order;
130 ChannelType type;
131
TextureFormat(ChannelOrder order_,ChannelType type_)132 TextureFormat (ChannelOrder order_, ChannelType type_)
133 : order (order_)
134 , type (type_)
135 {
136 }
137
TextureFormat(void)138 TextureFormat (void)
139 : order (CHANNELORDER_LAST)
140 , type (CHANNELTYPE_LAST)
141 {
142 }
143
144 int getPixelSize (void) const; //!< Deprecated, use tcu::getPixelSize(fmt)
145
operator ==(const TextureFormat & other) const146 bool operator== (const TextureFormat& other) const { return !(*this != other); }
operator !=(const TextureFormat & other) const147 bool operator!= (const TextureFormat& other) const
148 {
149 return (order != other.order || type != other.type);
150 }
151 } DE_WARN_UNUSED_TYPE;
152
153 bool isValid (TextureFormat format);
154 int getPixelSize (TextureFormat format);
155 int getNumUsedChannels (TextureFormat::ChannelOrder order);
156 int getChannelSize (TextureFormat::ChannelType type);
157
158 /*--------------------------------------------------------------------*//*!
159 * \brief Texture swizzle
160 *//*--------------------------------------------------------------------*/
161 struct TextureSwizzle
162 {
163 enum Channel
164 {
165 // \note CHANNEL_N must equal int N
166 CHANNEL_0 = 0,
167 CHANNEL_1,
168 CHANNEL_2,
169 CHANNEL_3,
170
171 CHANNEL_ZERO,
172 CHANNEL_ONE,
173
174 CHANNEL_LAST
175 };
176
177 Channel components[4];
178 };
179
180 //! get the swizzle used to expand texture data with a given channel order to RGBA form
181 const TextureSwizzle& getChannelReadSwizzle (TextureFormat::ChannelOrder order);
182
183 //! get the swizzle used to narrow RGBA form data to native texture data with a given channel order
184 const TextureSwizzle& getChannelWriteSwizzle (TextureFormat::ChannelOrder order);
185
186 /*--------------------------------------------------------------------*//*!
187 * \brief Sampling parameters
188 *//*--------------------------------------------------------------------*/
189 class Sampler
190 {
191 public:
192 enum WrapMode
193 {
194 CLAMP_TO_EDGE = 0, //! Clamp to edge
195 CLAMP_TO_BORDER, //! Use border color at edge
196 REPEAT_GL, //! Repeat with OpenGL semantics
197 REPEAT_CL, //! Repeat with OpenCL semantics
198 MIRRORED_REPEAT_GL, //! Mirrored repeat with OpenGL semantics
199 MIRRORED_REPEAT_CL, //! Mirrored repeat with OpenCL semantics
200 MIRRORED_ONCE, //! Mirrored once in negative directions
201
202 WRAPMODE_LAST
203 };
204
205 enum FilterMode
206 {
207 NEAREST = 0,
208 LINEAR,
209 CUBIC,
210
211 NEAREST_MIPMAP_NEAREST,
212 NEAREST_MIPMAP_LINEAR,
213 LINEAR_MIPMAP_NEAREST,
214 LINEAR_MIPMAP_LINEAR,
215 CUBIC_MIPMAP_NEAREST,
216 CUBIC_MIPMAP_LINEAR,
217
218 FILTERMODE_LAST
219 };
220
221 enum ReductionMode
222 {
223 WEIGHTED_AVERAGE = 0,
224 MIN,
225 MAX,
226
227 REDUCTIONMODE_LAST
228 };
229
230 enum CompareMode
231 {
232 COMPAREMODE_NONE = 0,
233 COMPAREMODE_LESS,
234 COMPAREMODE_LESS_OR_EQUAL,
235 COMPAREMODE_GREATER,
236 COMPAREMODE_GREATER_OR_EQUAL,
237 COMPAREMODE_EQUAL,
238 COMPAREMODE_NOT_EQUAL,
239 COMPAREMODE_ALWAYS,
240 COMPAREMODE_NEVER,
241
242 COMPAREMODE_LAST
243 };
244
245 enum DepthStencilMode
246 {
247 MODE_DEPTH = 0,
248 MODE_STENCIL,
249
250 MODE_LAST
251 };
252
253 // Wrap control
254 WrapMode wrapS;
255 WrapMode wrapT;
256 WrapMode wrapR;
257
258 // Minifcation & magnification
259 FilterMode minFilter;
260 FilterMode magFilter;
261
262 // min/max filtering reduction
263 ReductionMode reductionMode;
264
265 float lodThreshold; // lod <= lodThreshold ? magnified : minified
266
267 // Coordinate normalization
268 bool normalizedCoords;
269
270 // Shadow comparison
271 CompareMode compare;
272 int compareChannel;
273
274 // Border color.
275 // \note It is setter's responsibility to guarantee that the values are representable
276 // in sampled texture's internal format.
277 // \note It is setter's responsibility to guarantee that the format is compatible with the
278 // sampled texture's internal format. Otherwise results are undefined.
279 rr::GenericVec4 borderColor;
280
281 // Seamless cube map filtering
282 bool seamlessCubeMap;
283
284 // Depth stencil mode
285 DepthStencilMode depthStencilMode;
286
Sampler(WrapMode wrapS_,WrapMode wrapT_,WrapMode wrapR_,FilterMode minFilter_,FilterMode magFilter_,float lodThreshold_=0.0f,bool normalizedCoords_=true,CompareMode compare_=COMPAREMODE_NONE,int compareChannel_=0,const Vec4 & borderColor_=Vec4 (0.0f,0.0f,0.0f,0.0f),bool seamlessCubeMap_=false,DepthStencilMode depthStencilMode_=MODE_DEPTH,ReductionMode reductionMode_=WEIGHTED_AVERAGE)287 Sampler (WrapMode wrapS_,
288 WrapMode wrapT_,
289 WrapMode wrapR_,
290 FilterMode minFilter_,
291 FilterMode magFilter_,
292 float lodThreshold_ = 0.0f,
293 bool normalizedCoords_ = true,
294 CompareMode compare_ = COMPAREMODE_NONE,
295 int compareChannel_ = 0,
296 const Vec4& borderColor_ = Vec4(0.0f, 0.0f, 0.0f, 0.0f),
297 bool seamlessCubeMap_ = false,
298 DepthStencilMode depthStencilMode_ = MODE_DEPTH,
299 ReductionMode reductionMode_ = WEIGHTED_AVERAGE)
300 : wrapS (wrapS_)
301 , wrapT (wrapT_)
302 , wrapR (wrapR_)
303 , minFilter (minFilter_)
304 , magFilter (magFilter_)
305 , reductionMode (reductionMode_)
306 , lodThreshold (lodThreshold_)
307 , normalizedCoords (normalizedCoords_)
308 , compare (compare_)
309 , compareChannel (compareChannel_)
310 , borderColor (borderColor_)
311 , seamlessCubeMap (seamlessCubeMap_)
312 , depthStencilMode (depthStencilMode_)
313 {
314 }
315
Sampler(void)316 Sampler (void)
317 : wrapS (WRAPMODE_LAST)
318 , wrapT (WRAPMODE_LAST)
319 , wrapR (WRAPMODE_LAST)
320 , minFilter (FILTERMODE_LAST)
321 , magFilter (FILTERMODE_LAST)
322 , reductionMode (REDUCTIONMODE_LAST)
323 , lodThreshold (0.0f)
324 , normalizedCoords (true)
325 , compare (COMPAREMODE_NONE)
326 , compareChannel (0)
327 , borderColor (Vec4(0.0f, 0.0f, 0.0f, 0.0f))
328 , seamlessCubeMap (false)
329 , depthStencilMode (MODE_DEPTH)
330 {
331 }
332 } DE_WARN_UNUSED_TYPE;
333
334 // Calculate pitches for pixel data with no padding.
335 IVec3 calculatePackedPitch (const TextureFormat& format, const IVec3& size);
336
337 deBool isSamplerMipmapModeLinear (tcu::Sampler::FilterMode filterMode);
338
339 class TextureLevel;
340
341 /*--------------------------------------------------------------------*//*!
342 * \brief Read-only pixel data access
343 *
344 * ConstPixelBufferAccess encapsulates pixel data pointer along with
345 * format and layout information. It can be used for read-only access
346 * to arbitrary pixel buffers.
347 *
348 * Access objects are like iterators or pointers. They can be passed around
349 * as values and are valid as long as the storage doesn't change.
350 *//*--------------------------------------------------------------------*/
351 class ConstPixelBufferAccess
352 {
353 public:
354 ConstPixelBufferAccess (void);
355 ConstPixelBufferAccess (const TextureLevel& level);
356 ConstPixelBufferAccess (const TextureFormat& format, int width, int height, int depth, const void* data);
357 ConstPixelBufferAccess (const TextureFormat& format, const IVec3& size, const void* data);
358 ConstPixelBufferAccess (const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, const void* data);
359 ConstPixelBufferAccess (const TextureFormat& format, const IVec3& size, const IVec3& pitch, const void* data);
360 ConstPixelBufferAccess (const TextureFormat& format, const IVec3& size, const IVec3& pitch, const IVec3& divider, const void* data);
361
getFormat(void) const362 const TextureFormat& getFormat (void) const { return m_format; }
getSize(void) const363 const IVec3& getSize (void) const { return m_size; }
getWidth(void) const364 int getWidth (void) const { return m_size.x(); }
getHeight(void) const365 int getHeight (void) const { return m_size.y(); }
getDepth(void) const366 int getDepth (void) const { return m_size.z(); }
getPixelPitch(void) const367 int getPixelPitch (void) const { return m_pitch.x(); }
getRowPitch(void) const368 int getRowPitch (void) const { return m_pitch.y(); }
getSlicePitch(void) const369 int getSlicePitch (void) const { return m_pitch.z(); }
getPitch(void) const370 const IVec3& getPitch (void) const { return m_pitch; }
getDivider(void) const371 const IVec3& getDivider (void) const { return m_divider; }
372
getDataPtr(void) const373 const void* getDataPtr (void) const { return m_data; }
getPixelPtr(int x,int y,int z=0) const374 const void* getPixelPtr (int x, int y, int z = 0) const { return (const deUint8*)m_data + (x/m_divider.x()) * m_pitch.x() + (y/m_divider.y()) * m_pitch.y() + (z/m_divider.z()) * m_pitch.z(); }
375
376 Vec4 getPixel (int x, int y, int z = 0) const;
377 IVec4 getPixelInt (int x, int y, int z = 0) const;
getPixelUint(int x,int y,int z=0) const378 UVec4 getPixelUint (int x, int y, int z = 0) const { return getPixelInt(x, y, z).cast<deUint32>(); }
379 I64Vec4 getPixelInt64 (int x, int y, int z = 0) const;
getPixelUint64(int x,int y,int z=0) const380 U64Vec4 getPixelUint64 (int x, int y, int z = 0) const { return getPixelInt64(x, y, z).cast<deUint64>(); }
381
382 template<typename T>
383 Vector<T, 4> getPixelT (int x, int y, int z = 0) const;
384
385 float getPixDepth (int x, int y, int z = 0) const;
386 int getPixStencil (int x, int y, int z = 0) const;
387
388 Vec4 sample1D (const Sampler& sampler, Sampler::FilterMode filter, float s, int level) const;
389 Vec4 sample2D (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, int depth) const;
390 Vec4 sample3D (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, float r) const;
391
392 Vec4 sample1DOffset (const Sampler& sampler, Sampler::FilterMode filter, float s, const IVec2& offset) const;
393 Vec4 sample2DOffset (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, const IVec3& offset) const;
394 Vec4 sample3DOffset (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, float r, const IVec3& offset) const;
395
396 float sample1DCompare (const Sampler& sampler, Sampler::FilterMode filter, float ref, float s, const IVec2& offset) const;
397 float sample2DCompare (const Sampler& sampler, Sampler::FilterMode filter, float ref, float s, float t, const IVec3& offset) const;
398
399 protected:
400 TextureFormat m_format;
401 IVec3 m_size;
402 IVec3 m_pitch; //!< (pixelPitch, rowPitch, slicePitch)
403 IVec3 m_divider;
404 mutable void* m_data;
405 } DE_WARN_UNUSED_TYPE;
406
407 /*--------------------------------------------------------------------*//*!
408 * \brief Read-write pixel data access
409 *
410 * This class extends read-only access object by providing write functionality.
411 *
412 * \note PixelBufferAccess may not have any data members nor add any
413 * virtual functions. It must be possible to reinterpret_cast<>
414 * PixelBufferAccess to ConstPixelBufferAccess.
415 *//*--------------------------------------------------------------------*/
416 class PixelBufferAccess : public ConstPixelBufferAccess
417 {
418 public:
PixelBufferAccess(void)419 PixelBufferAccess (void) {}
420 PixelBufferAccess (TextureLevel& level);
421 PixelBufferAccess (const TextureFormat& format, int width, int height, int depth, void* data);
422 PixelBufferAccess (const TextureFormat& format, const IVec3& size, void* data);
423 PixelBufferAccess (const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, void* data);
424 PixelBufferAccess (const TextureFormat& format, const IVec3& size, const IVec3& pitch, void* data);
425 PixelBufferAccess (const TextureFormat& format, const IVec3& size, const IVec3& pitch, const IVec3& block, void* data);
426
getDataPtr(void) const427 void* getDataPtr (void) const { return m_data; }
getPixelPtr(int x,int y,int z=0) const428 void* getPixelPtr (int x, int y, int z = 0) const { return (deUint8*)m_data + (x/m_divider.x()) * m_pitch.x() + (y/m_divider.y()) * m_pitch.y() + (z/m_divider.z()) * m_pitch.z(); }
429
430 void setPixel (const tcu::Vec4& color, int x, int y, int z = 0) const;
431 void setPixel (const tcu::IVec4& color, int x, int y, int z = 0) const;
setPixel(const tcu::UVec4 & color,int x,int y,int z=0) const432 void setPixel (const tcu::UVec4& color, int x, int y, int z = 0) const { setPixel(color.cast<int>(), x, y, z); }
433
434 void setPixDepth (float depth, int x, int y, int z = 0) const;
435 void setPixStencil (int stencil, int x, int y, int z = 0) const;
436 } DE_WARN_UNUSED_TYPE;
437
438 /*--------------------------------------------------------------------*//*!
439 * \brief Generic pixel data container
440 *
441 * This container supports all valid TextureFormat combinations and
442 * both 2D and 3D textures. To read or manipulate data access object must
443 * be queried using getAccess().
444 *//*--------------------------------------------------------------------*/
445 class TextureLevel
446 {
447 public:
448 TextureLevel (void);
449 TextureLevel (const TextureFormat& format);
450 TextureLevel (const TextureFormat& format, int width, int height, int depth = 1);
451 ~TextureLevel (void);
452
getSize(void) const453 const IVec3& getSize (void) const { return m_size; }
getWidth(void) const454 int getWidth (void) const { return m_size.x(); }
getHeight(void) const455 int getHeight (void) const { return m_size.y(); }
getDepth(void) const456 int getDepth (void) const { return m_size.z(); }
isEmpty(void) const457 bool isEmpty (void) const { return m_size.x() * m_size.y() * m_size.z() == 0; }
getFormat(void) const458 const TextureFormat getFormat (void) const { return m_format; }
459
460 void setStorage (const TextureFormat& format, int width, int heigth, int depth = 1);
461 void setSize (int width, int height, int depth = 1);
462
getAccess(void)463 PixelBufferAccess getAccess (void) { return isEmpty() ? PixelBufferAccess() : PixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr()); }
getAccess(void) const464 ConstPixelBufferAccess getAccess (void) const { return isEmpty() ? ConstPixelBufferAccess() : ConstPixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr()); }
465
466 private:
getPtr(void)467 void* getPtr (void) { return m_data.getPtr(); }
getPtr(void) const468 const void* getPtr (void) const { return m_data.getPtr(); }
469
470 TextureFormat m_format;
471 IVec3 m_size;
472 de::ArrayBuffer<deUint8> m_data;
473
474 friend class ConstPixelBufferAccess;
475 } DE_WARN_UNUSED_TYPE;
476
477 /*--------------------------------------------------------------------*//*!
478 * \brief VK_EXT_image_view_min_lod
479 *//*--------------------------------------------------------------------*/
480 enum ImageViewMinLodMode
481 {
482 IMAGEVIEWMINLODMODE_PREFERRED, //!< use image view min lod as-is
483 IMAGEVIEWMINLODMODE_ALTERNATIVE, //!< use floor of image view min lod, as in 'Image Level(s) Selection' in VK spec (v 1.3.206)
484 };
485
486 struct ImageViewMinLod
487 {
488 float value;
489 ImageViewMinLodMode mode;
490 };
491
492 struct ImageViewMinLodParams
493 {
494 int baseLevel;
495 ImageViewMinLod minLod;
496 bool intTexCoord;
497 };
498
499 Vec4 sampleLevelArray1D (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, int level, float lod);
500 Vec4 sampleLevelArray2D (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, int depth, float lod, bool es2 = false, ImageViewMinLodParams *minLodParams = DE_NULL);
501 Vec4 sampleLevelArray3D (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float r, float lod, ImageViewMinLodParams *minLodParams = DE_NULL);
502
503 Vec4 sampleLevelArray1DOffset (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float lod, const IVec2& offset);
504 Vec4 sampleLevelArray2DOffset (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float lod, const IVec3& offset, bool es2 = false, ImageViewMinLodParams *minLodParams = DE_NULL);
505 Vec4 sampleLevelArray3DOffset (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset, ImageViewMinLodParams *minLodParams = DE_NULL);
506
507 float sampleLevelArray1DCompare (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float ref, float s, float lod, const IVec2& offset);
508 float sampleLevelArray2DCompare (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float ref, float s, float t, float lod, const IVec3& offset);
509
510 Vec4 gatherArray2DOffsets (const ConstPixelBufferAccess& src, const Sampler& sampler, float s, float t, int depth, int componentNdx, const IVec2 (&offsets)[4]);
511 Vec4 gatherArray2DOffsetsCompare (const ConstPixelBufferAccess& src, const Sampler& sampler, float ref, float s, float t, int depth, const IVec2 (&offsets)[4]);
512
513 enum CubeFace
514 {
515 CUBEFACE_NEGATIVE_X = 0,
516 CUBEFACE_POSITIVE_X,
517 CUBEFACE_NEGATIVE_Y,
518 CUBEFACE_POSITIVE_Y,
519 CUBEFACE_NEGATIVE_Z,
520 CUBEFACE_POSITIVE_Z,
521
522 CUBEFACE_LAST
523 };
524
525 /*--------------------------------------------------------------------*//*!
526 * \brief Coordinates projected onto cube face.
527 *//*--------------------------------------------------------------------*/
528 template<typename T>
529 struct CubeFaceCoords
530 {
531 CubeFace face;
532 T s;
533 T t;
534
CubeFaceCoordstcu::CubeFaceCoords535 CubeFaceCoords (CubeFace face_, T s_, T t_) : face(face_), s(s_), t(t_) {}
CubeFaceCoordstcu::CubeFaceCoords536 CubeFaceCoords (CubeFace face_, const Vector<T, 2>& c) : face(face_), s(c.x()), t(c.y()) {}
537 } DE_WARN_UNUSED_TYPE;
538
539 typedef CubeFaceCoords<float> CubeFaceFloatCoords;
540 typedef CubeFaceCoords<int> CubeFaceIntCoords;
541
542 CubeFace selectCubeFace (const Vec3& coords);
543 Vec2 projectToFace (CubeFace face, const Vec3& coords);
544 CubeFaceFloatCoords getCubeFaceCoords (const Vec3& coords);
545 CubeFaceIntCoords remapCubeEdgeCoords (const CubeFaceIntCoords& coords, int size);
546
547 /*--------------------------------------------------------------------*//*!
548 * \brief 2D Texture View
549 *//*--------------------------------------------------------------------*/
550 class Texture2DView
551 {
552 public:
553 Texture2DView (int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false, ImageViewMinLodParams* minLodParams = DE_NULL);
554
getNumLevels(void) const555 int getNumLevels (void) const { return m_numLevels; }
getWidth(void) const556 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
getHeight(void) const557 int getHeight (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
getLevel(int ndx) const558 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
getLevels(void) const559 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
isES2(void) const560 bool isES2 (void) const { return m_es2; }
561
562 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
563 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
564 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
565 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
566
567 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
568 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
569
getImageViewMinLodParams(void) const570 ImageViewMinLodParams* getImageViewMinLodParams (void) const { return m_minLodParams; }
571
572 protected:
573 int m_numLevels;
574 const ConstPixelBufferAccess* m_levels;
575 bool m_es2;
576 struct ImageViewMinLodParams* m_minLodParams;
577 } DE_WARN_UNUSED_TYPE;
578
Texture2DView(int numLevels,const ConstPixelBufferAccess * levels,bool es2,ImageViewMinLodParams * minLodParams)579 inline Texture2DView::Texture2DView (int numLevels, const ConstPixelBufferAccess* levels, bool es2, ImageViewMinLodParams* minLodParams)
580 : m_numLevels (numLevels)
581 , m_levels (levels)
582 , m_es2 (es2)
583 , m_minLodParams (minLodParams)
584 {
585 DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
586 }
587
sample(const Sampler & sampler,float s,float t,float lod) const588 inline Vec4 Texture2DView::sample (const Sampler& sampler, float s, float t, float lod) const
589 {
590 return sampleLevelArray2D(m_levels, m_numLevels, sampler, s, t, 0 /* depth */, lod, m_es2, m_minLodParams);
591 }
592
sampleOffset(const Sampler & sampler,float s,float t,float lod,const IVec2 & offset) const593 inline Vec4 Texture2DView::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
594 {
595 return sampleLevelArray2DOffset(m_levels, m_numLevels, sampler, s, t, lod, IVec3(offset.x(), offset.y(), 0));
596 }
597
sampleCompare(const Sampler & sampler,float ref,float s,float t,float lod) const598 inline float Texture2DView::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
599 {
600 return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(0, 0, 0));
601 }
602
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float lod,const IVec2 & offset) const603 inline float Texture2DView::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
604 {
605 return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(offset.x(), offset.y(), 0));
606 }
607
gatherOffsets(const Sampler & sampler,float s,float t,int componentNdx,const IVec2 (& offsets)[4]) const608 inline Vec4 Texture2DView::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
609 {
610 return gatherArray2DOffsets(m_levels[0], sampler, s, t, 0, componentNdx, offsets);
611 }
612
gatherOffsetsCompare(const Sampler & sampler,float ref,float s,float t,const IVec2 (& offsets)[4]) const613 inline Vec4 Texture2DView::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
614 {
615 return gatherArray2DOffsetsCompare(m_levels[0], sampler, ref, s, t, 0, offsets);
616 }
617
618 /*--------------------------------------------------------------------*//*!
619 * \brief Base class for textures that have single mip-map pyramid
620 *//*--------------------------------------------------------------------*/
621 class TextureLevelPyramid
622 {
623 public:
624 TextureLevelPyramid (const TextureFormat& format, int numLevels);
625 TextureLevelPyramid (const TextureLevelPyramid& other);
626 ~TextureLevelPyramid(void);
627
getFormat(void) const628 const TextureFormat& getFormat (void) const { return m_format; }
getNumLevels(void) const629 int getNumLevels (void) const { return (int)m_access.size(); }
630
isLevelEmpty(int levelNdx) const631 bool isLevelEmpty (int levelNdx) const { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[(size_t)levelNdx].empty(); }
getLevel(int levelNdx) const632 const ConstPixelBufferAccess& getLevel (int levelNdx) const { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_access[(size_t)levelNdx]; }
getLevel(int levelNdx)633 const PixelBufferAccess& getLevel (int levelNdx) { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_access[(size_t)levelNdx]; }
634
getLevels(void) const635 const ConstPixelBufferAccess* getLevels (void) const { return &m_access[0]; }
getLevels(void)636 const PixelBufferAccess* getLevels (void) { return &m_access[0]; }
637
638 void allocLevel (int levelNdx, int width, int height, int depth);
639 void clearLevel (int levelNdx);
640
641 TextureLevelPyramid& operator= (const TextureLevelPyramid& other);
642
643 private:
644 typedef de::ArrayBuffer<deUint8> LevelData;
645
646 TextureFormat m_format;
647 std::vector<LevelData> m_data;
648 std::vector<PixelBufferAccess> m_access;
649 } DE_WARN_UNUSED_TYPE;
650
651 /*--------------------------------------------------------------------*//*!
652 * \brief 2D Texture reference implementation
653 *//*--------------------------------------------------------------------*/
654 class Texture2D : private TextureLevelPyramid
655 {
656 public:
657 Texture2D (const TextureFormat& format, int width, int height, bool es2 = false);
658 Texture2D (const TextureFormat& format, int width, int height, int mipmaps);
659 Texture2D (const Texture2D& other);
660 ~Texture2D (void);
661
getWidth(void) const662 int getWidth (void) const { return m_width; }
getHeight(void) const663 int getHeight (void) const { return m_height; }
getView(void) const664 const Texture2DView& getView (void) const { return m_view; }
isYUVTextureUsed(void) const665 bool isYUVTextureUsed (void) const { return m_yuvTextureUsed;}
666 void allocLevel (int levelNdx);
667
668 // Sampling
669 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
670 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
671 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
672 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
673
674 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
675 Vec4 gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
676
677 using TextureLevelPyramid::getFormat;
678 using TextureLevelPyramid::getNumLevels;
679 using TextureLevelPyramid::getLevel;
680 using TextureLevelPyramid::clearLevel;
681 using TextureLevelPyramid::isLevelEmpty;
682
683 Texture2D& operator= (const Texture2D& other);
684 //whether this is a yuv format texture tests
685 bool m_yuvTextureUsed;
operator Texture2DView(void) const686 operator Texture2DView (void) const { return m_view; }
687
688 private:
689 int m_width;
690 int m_height;
691 Texture2DView m_view;
692 } DE_WARN_UNUSED_TYPE;
693
sample(const Sampler & sampler,float s,float t,float lod) const694 inline Vec4 Texture2D::sample (const Sampler& sampler, float s, float t, float lod) const
695 {
696 return m_view.sample(sampler, s, t, lod);
697 }
698
sampleOffset(const Sampler & sampler,float s,float t,float lod,const IVec2 & offset) const699 inline Vec4 Texture2D::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
700 {
701 return m_view.sampleOffset(sampler, s, t, lod, offset);
702 }
703
sampleCompare(const Sampler & sampler,float ref,float s,float t,float lod) const704 inline float Texture2D::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
705 {
706 return m_view.sampleCompare(sampler, ref, s, t, lod);
707 }
708
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float lod,const IVec2 & offset) const709 inline float Texture2D::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
710 {
711 return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
712 }
713
gatherOffsets(const Sampler & sampler,float s,float t,int componentNdx,const IVec2 (& offsets)[4]) const714 inline Vec4 Texture2D::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
715 {
716 return m_view.gatherOffsets(sampler, s, t, componentNdx, offsets);
717 }
718
gatherOffsetsCompare(const Sampler & sampler,float ref,float s,float t,const IVec2 (& offsets)[4]) const719 inline Vec4 Texture2D::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
720 {
721 return m_view.gatherOffsetsCompare(sampler, ref, s, t, offsets);
722 }
723
724 /*--------------------------------------------------------------------*//*!
725 * \brief Cube Map Texture View
726 *//*--------------------------------------------------------------------*/
727 class TextureCubeView
728 {
729 public:
730 TextureCubeView (void);
731 TextureCubeView (int numLevels, const ConstPixelBufferAccess* const (&levels)[CUBEFACE_LAST], bool es2 = false, ImageViewMinLodParams* minLodParams = DE_NULL);
732
getNumLevels(void) const733 int getNumLevels (void) const { return m_numLevels; }
isES2(void) const734 bool isES2 (void) const { return m_es2; }
getSize(void) const735 int getSize (void) const { return m_numLevels > 0 ? m_levels[0][0].getWidth() : 0; }
getLevelFace(int ndx,CubeFace face) const736 const ConstPixelBufferAccess& getLevelFace (int ndx, CubeFace face) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[face][ndx]; }
getFaceLevels(CubeFace face) const737 const ConstPixelBufferAccess* getFaceLevels (CubeFace face) const { return m_levels[face]; }
738
739 Vec4 sample (const Sampler& sampler, float s, float t, float p, float lod) const;
740 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
741
742 Vec4 gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const;
743 Vec4 gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const;
744
getImageViewMinLodParams(void) const745 ImageViewMinLodParams* getImageViewMinLodParams (void) const { return m_minLodParams; }
746
747 protected:
748 int m_numLevels;
749 const ConstPixelBufferAccess* m_levels[CUBEFACE_LAST];
750 bool m_es2;
751 ImageViewMinLodParams* m_minLodParams;
752 } DE_WARN_UNUSED_TYPE;
753
754 /*--------------------------------------------------------------------*//*!
755 * \brief Cube Map Texture reference implementation
756 *//*--------------------------------------------------------------------*/
757 class TextureCube
758 {
759 public:
760 TextureCube (const TextureFormat& format, int size, bool es2 = false);
761 TextureCube (const TextureCube& other);
762 ~TextureCube (void);
763
getFormat(void) const764 const TextureFormat& getFormat (void) const { return m_format; }
getSize(void) const765 int getSize (void) const { return m_size; }
getView(void) const766 const TextureCubeView& getView (void) const { return m_view; }
767
getNumLevels(void) const768 int getNumLevels (void) const { return (int)m_access[0].size(); }
getLevelFace(int ndx,CubeFace face) const769 const ConstPixelBufferAccess& getLevelFace (int ndx, CubeFace face) const { DE_ASSERT(de::inBounds(ndx, 0, getNumLevels())); return m_access[face][(size_t)ndx]; }
getLevelFace(int ndx,CubeFace face)770 const PixelBufferAccess& getLevelFace (int ndx, CubeFace face) { DE_ASSERT(de::inBounds(ndx, 0, getNumLevels())); return m_access[face][(size_t)ndx]; }
771
772 void allocLevel (CubeFace face, int levelNdx);
773 void clearLevel (CubeFace face, int levelNdx);
isLevelEmpty(CubeFace face,int levelNdx) const774 bool isLevelEmpty (CubeFace face, int levelNdx) const { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[face][(size_t)levelNdx].empty(); }
775
776 Vec4 sample (const Sampler& sampler, float s, float t, float p, float lod) const;
777 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
778
779 Vec4 gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const;
780 Vec4 gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const;
781
782 TextureCube& operator= (const TextureCube& other);
783
operator TextureCubeView(void) const784 operator TextureCubeView (void) const { return m_view; }
785
786 private:
787 typedef de::ArrayBuffer<deUint8> LevelData;
788
789 TextureFormat m_format;
790 int m_size;
791 std::vector<LevelData> m_data[CUBEFACE_LAST];
792 std::vector<PixelBufferAccess> m_access[CUBEFACE_LAST];
793 TextureCubeView m_view;
794 } DE_WARN_UNUSED_TYPE;
795
sample(const Sampler & sampler,float s,float t,float p,float lod) const796 inline Vec4 TextureCube::sample (const Sampler& sampler, float s, float t, float p, float lod) const
797 {
798 return m_view.sample(sampler, s, t, p, lod);
799 }
800
sampleCompare(const Sampler & sampler,float ref,float s,float t,float r,float lod) const801 inline float TextureCube::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
802 {
803 return m_view.sampleCompare(sampler, ref, s, t, r, lod);
804 }
805
gather(const Sampler & sampler,float s,float t,float r,int componentNdx) const806 inline Vec4 TextureCube::gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const
807 {
808 return m_view.gather(sampler, s, t, r, componentNdx);
809 }
810
gatherCompare(const Sampler & sampler,float ref,float s,float t,float r) const811 inline Vec4 TextureCube::gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const
812 {
813 return m_view.gatherCompare(sampler, ref, s, t, r);
814 }
815
816 /*--------------------------------------------------------------------*//*!
817 * \brief 1D Texture View
818 *//*--------------------------------------------------------------------*/
819 class Texture1DView
820 {
821 public:
822 Texture1DView (int numLevels, const ConstPixelBufferAccess* levels, bool es2, ImageViewMinLodParams* minLodParams);
823
getNumLevels(void) const824 int getNumLevels (void) const { return m_numLevels; }
getWidth(void) const825 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
getLevel(int ndx) const826 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
getLevels(void) const827 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
isES2(void) const828 bool isES2 (void) const { return false; }
829
830 Vec4 sample (const Sampler& sampler, float s, float lod) const;
831 Vec4 sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const;
832 float sampleCompare (const Sampler& sampler, float ref, float s, float lod) const;
833 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const;
834
getImageViewMinLodParams(void) const835 ImageViewMinLodParams* getImageViewMinLodParams (void) const { return DE_NULL; }
836
837 protected:
838 int m_numLevels;
839 const ConstPixelBufferAccess* m_levels;
840 } DE_WARN_UNUSED_TYPE;
841
Texture1DView(int numLevels,const ConstPixelBufferAccess * levels,bool es2 DE_UNUSED_ATTR=false,ImageViewMinLodParams * minLodParams DE_UNUSED_ATTR=DE_NULL)842 inline Texture1DView::Texture1DView (int numLevels, const ConstPixelBufferAccess* levels, bool es2 DE_UNUSED_ATTR = false, ImageViewMinLodParams* minLodParams DE_UNUSED_ATTR = DE_NULL)
843 : m_numLevels (numLevels)
844 , m_levels (levels)
845 {
846 DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
847 }
848
sample(const Sampler & sampler,float s,float lod) const849 inline Vec4 Texture1DView::sample (const Sampler& sampler, float s, float lod) const
850 {
851 return sampleLevelArray1D(m_levels, m_numLevels, sampler, s, 0 /* depth */, lod);
852 }
853
sampleOffset(const Sampler & sampler,float s,float lod,deInt32 offset) const854 inline Vec4 Texture1DView::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
855 {
856 return sampleLevelArray1DOffset(m_levels, m_numLevels, sampler, s, lod, IVec2(offset, 0));
857 }
858
sampleCompare(const Sampler & sampler,float ref,float s,float lod) const859 inline float Texture1DView::sampleCompare (const Sampler& sampler, float ref, float s, float lod) const
860 {
861 return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(0, 0));
862 }
863
sampleCompareOffset(const Sampler & sampler,float ref,float s,float lod,deInt32 offset) const864 inline float Texture1DView::sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const
865 {
866 return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(offset, 0));
867 }
868
869 /*--------------------------------------------------------------------*//*!
870 * \brief 1D Texture reference implementation
871 *//*--------------------------------------------------------------------*/
872 class Texture1D : private TextureLevelPyramid
873 {
874 public:
875 Texture1D (const TextureFormat& format, int width);
876 Texture1D (const Texture1D& other);
877 ~Texture1D (void);
878
getWidth(void) const879 int getWidth (void) const { return m_width; }
getView(void) const880 const Texture1DView& getView (void) const { return m_view; }
881
882 void allocLevel (int levelNdx);
883
884 // Sampling
885 Vec4 sample (const Sampler& sampler, float s, float lod) const;
886 Vec4 sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const;
887 float sampleCompare (const Sampler& sampler, float ref, float s, float lod) const;
888 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const;
889
890 using TextureLevelPyramid::getFormat;
891 using TextureLevelPyramid::getNumLevels;
892 using TextureLevelPyramid::getLevel;
893 using TextureLevelPyramid::clearLevel;
894 using TextureLevelPyramid::isLevelEmpty;
895
896 Texture1D& operator= (const Texture1D& other);
897
operator Texture1DView(void) const898 operator Texture1DView (void) const { return m_view; }
899
900 private:
901 int m_width;
902 Texture1DView m_view;
903 } DE_WARN_UNUSED_TYPE;
904
sample(const Sampler & sampler,float s,float lod) const905 inline Vec4 Texture1D::sample (const Sampler& sampler, float s, float lod) const
906 {
907 return m_view.sample(sampler, s, lod);
908 }
909
sampleOffset(const Sampler & sampler,float s,float lod,deInt32 offset) const910 inline Vec4 Texture1D::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
911 {
912 return m_view.sampleOffset(sampler, s, lod, offset);
913 }
914
sampleCompare(const Sampler & sampler,float ref,float s,float lod) const915 inline float Texture1D::sampleCompare (const Sampler& sampler, float ref, float s, float lod) const
916 {
917 return m_view.sampleCompare(sampler, ref, s, lod);
918 }
919
sampleCompareOffset(const Sampler & sampler,float ref,float s,float lod,deInt32 offset) const920 inline float Texture1D::sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const
921 {
922 return m_view.sampleCompareOffset(sampler, ref, s, lod, offset);
923 }
924
925 /*--------------------------------------------------------------------*//*!
926 * \brief 1D Array Texture View
927 *//*--------------------------------------------------------------------*/
928 class Texture1DArrayView
929 {
930 public:
931 Texture1DArrayView (int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false, ImageViewMinLodParams* minLodParams = DE_NULL);
932
getWidth(void) const933 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
getNumLayers(void) const934 int getNumLayers (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
getNumLevels(void) const935 int getNumLevels (void) const { return m_numLevels; }
getLevel(int ndx) const936 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
getLevels(void) const937 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
isES2(void) const938 bool isES2 (void) const { return false; }
939
940 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
941 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
942 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
943 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
944
getImageViewMinLodParams(void) const945 ImageViewMinLodParams* getImageViewMinLodParams (void) const { return DE_NULL; }
946
947 protected:
948 int selectLayer (float r) const;
949
950 int m_numLevels;
951 const ConstPixelBufferAccess* m_levels;
952 } DE_WARN_UNUSED_TYPE;
953
954 /*--------------------------------------------------------------------*//*!
955 * \brief 1D Array Texture reference implementation
956 *//*--------------------------------------------------------------------*/
957 class Texture1DArray : private TextureLevelPyramid
958 {
959 public:
960 Texture1DArray (const TextureFormat& format, int width, int numLayers);
961 Texture1DArray (const Texture1DArray& other);
962 ~Texture1DArray (void);
963
getWidth(void) const964 int getWidth (void) const { return m_width; }
getNumLayers(void) const965 int getNumLayers (void) const { return m_numLayers; }
966
967 void allocLevel (int levelNdx);
968
969 using TextureLevelPyramid::getFormat;
970 using TextureLevelPyramid::getNumLevels;
971 using TextureLevelPyramid::getLevel;
972 using TextureLevelPyramid::clearLevel;
973 using TextureLevelPyramid::isLevelEmpty;
974
975 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
976 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
977 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
978 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
979
980 Texture1DArray& operator= (const Texture1DArray& other);
981
operator Texture1DArrayView(void) const982 operator Texture1DArrayView (void) const { return m_view; }
983
984 private:
985 int m_width;
986 int m_numLayers;
987 Texture1DArrayView m_view;
988 } DE_WARN_UNUSED_TYPE;
989
sample(const Sampler & sampler,float s,float t,float lod) const990 inline Vec4 Texture1DArray::sample (const Sampler& sampler, float s, float t, float lod) const
991 {
992 return m_view.sample(sampler, s, t, lod);
993 }
994
sampleOffset(const Sampler & sampler,float s,float t,float lod,deInt32 offset) const995 inline Vec4 Texture1DArray::sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const
996 {
997 return m_view.sampleOffset(sampler, s, t, lod, offset);
998 }
999
sampleCompare(const Sampler & sampler,float ref,float s,float t,float lod) const1000 inline float Texture1DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
1001 {
1002 return m_view.sampleCompare(sampler, ref, s, t, lod);
1003 }
1004
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float lod,deInt32 offset) const1005 inline float Texture1DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const
1006 {
1007 return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
1008 }
1009
1010 /*--------------------------------------------------------------------*//*!
1011 * \brief 2D Array Texture View
1012 *//*--------------------------------------------------------------------*/
1013 class Texture2DArrayView
1014 {
1015 public:
1016 Texture2DArrayView (int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false, ImageViewMinLodParams* minLodParams = DE_NULL);
1017
getWidth(void) const1018 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
getHeight(void) const1019 int getHeight (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
getNumLayers(void) const1020 int getNumLayers (void) const { return m_numLevels > 0 ? m_levels[0].getDepth() : 0; }
getNumLevels(void) const1021 int getNumLevels (void) const { return m_numLevels; }
getLevel(int ndx) const1022 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
getLevels(void) const1023 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
isES2(void) const1024 bool isES2 (void) const { return false; }
1025
1026 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
1027 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
1028 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
1029 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
1030
1031 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
1032 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
1033
getImageViewMinLodParams(void) const1034 ImageViewMinLodParams* getImageViewMinLodParams (void) const { return DE_NULL; }
1035
1036 protected:
1037 int selectLayer (float r) const;
1038
1039 int m_numLevels;
1040 const ConstPixelBufferAccess* m_levels;
1041 } DE_WARN_UNUSED_TYPE;
1042
1043 /*--------------------------------------------------------------------*//*!
1044 * \brief 2D Array Texture reference implementation
1045 *//*--------------------------------------------------------------------*/
1046 class Texture2DArray : private TextureLevelPyramid
1047 {
1048 public:
1049 Texture2DArray (const TextureFormat& format, int width, int height, int numLayers);
1050 Texture2DArray (const Texture2DArray& other);
1051 ~Texture2DArray (void);
1052
getWidth(void) const1053 int getWidth (void) const { return m_width; }
getHeight(void) const1054 int getHeight (void) const { return m_height; }
getNumLayers(void) const1055 int getNumLayers (void) const { return m_numLayers; }
1056
1057 void allocLevel (int levelNdx);
1058
1059 using TextureLevelPyramid::getFormat;
1060 using TextureLevelPyramid::getNumLevels;
1061 using TextureLevelPyramid::getLevel;
1062 using TextureLevelPyramid::clearLevel;
1063 using TextureLevelPyramid::isLevelEmpty;
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 IVec2& offset) const;
1067 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
1068 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
1069
1070 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
1071 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
1072
1073 Texture2DArray& operator= (const Texture2DArray& other);
1074
operator Texture2DArrayView(void) const1075 operator Texture2DArrayView (void) const { return m_view; }
1076
1077 private:
1078 int m_width;
1079 int m_height;
1080 int m_numLayers;
1081 Texture2DArrayView m_view;
1082 } DE_WARN_UNUSED_TYPE;
1083
sample(const Sampler & sampler,float s,float t,float r,float lod) const1084 inline Vec4 Texture2DArray::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
sampleOffset(const Sampler & sampler,float s,float t,float r,float lod,const IVec2 & offset) const1089 inline Vec4 Texture2DArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const
1090 {
1091 return m_view.sampleOffset(sampler, s, t, r, lod, offset);
1092 }
1093
sampleCompare(const Sampler & sampler,float ref,float s,float t,float r,float lod) const1094 inline float Texture2DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
1095 {
1096 return m_view.sampleCompare(sampler, ref, s, t, r, lod);
1097 }
1098
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float r,float lod,const IVec2 & offset) const1099 inline float Texture2DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const
1100 {
1101 return m_view.sampleCompareOffset(sampler, ref, s, t, r, lod, offset);
1102 }
1103
gatherOffsets(const Sampler & sampler,float s,float t,float r,int componentNdx,const IVec2 (& offsets)[4]) const1104 inline Vec4 Texture2DArray::gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const
1105 {
1106 return m_view.gatherOffsets(sampler, s, t, r, componentNdx, offsets);
1107 }
1108
gatherOffsetsCompare(const Sampler & sampler,float ref,float s,float t,float r,const IVec2 (& offsets)[4]) const1109 inline Vec4 Texture2DArray::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const
1110 {
1111 return m_view.gatherOffsetsCompare(sampler, ref, s, t, r, offsets);
1112 }
1113
1114 /*--------------------------------------------------------------------*//*!
1115 * \brief 3D Texture View
1116 *//*--------------------------------------------------------------------*/
1117 class Texture3DView
1118 {
1119 public:
1120 Texture3DView (int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false, ImageViewMinLodParams* minLodParams = DE_NULL);
1121
getWidth(void) const1122 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
getHeight(void) const1123 int getHeight (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
getDepth(void) const1124 int getDepth (void) const { return m_numLevels > 0 ? m_levels[0].getDepth() : 0; }
getNumLevels(void) const1125 int getNumLevels (void) const { return m_numLevels; }
getLevel(int ndx) const1126 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
getLevels(void) const1127 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
isES2(void) const1128 bool isES2 (void) const { return m_es2; }
1129
1130 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
1131 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
1132
getImageViewMinLodParams(void) const1133 ImageViewMinLodParams* getImageViewMinLodParams (void) const { return m_minLodParams; }
1134
1135 protected:
1136 int m_numLevels;
1137 const ConstPixelBufferAccess* m_levels;
1138 bool m_es2;
1139 ImageViewMinLodParams* m_minLodParams;
1140
1141 } DE_WARN_UNUSED_TYPE;
1142
sample(const Sampler & sampler,float s,float t,float r,float lod) const1143 inline Vec4 Texture3DView::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1144 {
1145 return sampleLevelArray3D(m_levels, m_numLevels, sampler, s, t, r, lod, m_minLodParams);
1146 }
1147
sampleOffset(const Sampler & sampler,float s,float t,float r,float lod,const IVec3 & offset) const1148 inline Vec4 Texture3DView::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
1149 {
1150 return sampleLevelArray3DOffset(m_levels, m_numLevels, sampler, s, t, r, lod, offset, m_minLodParams);
1151 }
1152
1153 /*--------------------------------------------------------------------*//*!
1154 * \brief 3D Texture reference implementation
1155 *//*--------------------------------------------------------------------*/
1156 class Texture3D : private TextureLevelPyramid
1157 {
1158 public:
1159 Texture3D (const TextureFormat& format, int width, int height, int depth);
1160 Texture3D (const Texture3D& other);
1161 ~Texture3D (void);
1162
getWidth(void) const1163 int getWidth (void) const { return m_width; }
getHeight(void) const1164 int getHeight (void) const { return m_height; }
getDepth(void) const1165 int getDepth (void) const { return m_depth; }
1166
1167 void allocLevel (int levelNdx);
1168
1169 using TextureLevelPyramid::getFormat;
1170 using TextureLevelPyramid::getNumLevels;
1171 using TextureLevelPyramid::getLevel;
1172 using TextureLevelPyramid::clearLevel;
1173 using TextureLevelPyramid::isLevelEmpty;
1174
1175 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
1176 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
1177
1178 Texture3D& operator= (const Texture3D& other);
1179
operator Texture3DView(void) const1180 operator Texture3DView (void) const { return m_view; }
1181
1182 private:
1183 int m_width;
1184 int m_height;
1185 int m_depth;
1186 Texture3DView m_view;
1187 } DE_WARN_UNUSED_TYPE;
1188
sample(const Sampler & sampler,float s,float t,float r,float lod) const1189 inline Vec4 Texture3D::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1190 {
1191 return m_view.sample(sampler, s, t, r, lod);
1192 }
1193
sampleOffset(const Sampler & sampler,float s,float t,float r,float lod,const IVec3 & offset) const1194 inline Vec4 Texture3D::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
1195 {
1196 return m_view.sampleOffset(sampler, s, t, r, lod, offset);
1197 }
1198
1199 /*--------------------------------------------------------------------*//*!
1200 * \brief Cube Map Array Texture View
1201 *//*--------------------------------------------------------------------*/
1202 class TextureCubeArrayView
1203 {
1204 public:
1205 TextureCubeArrayView (int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false, ImageViewMinLodParams* minLodParams = DE_NULL);
1206
getSize(void) const1207 int getSize (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
getDepth(void) const1208 int getDepth (void) const { return m_numLevels > 0 ? m_levels[0].getDepth() : 0; }
getNumLayers(void) const1209 int getNumLayers (void) const { return getDepth() / 6; }
getNumLevels(void) const1210 int getNumLevels (void) const { return m_numLevels; }
getLevel(int ndx) const1211 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
getLevels(void) const1212 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
isES2(void) const1213 bool isES2 (void) const { return false; }
1214
1215 Vec4 sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const;
1216 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1217 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
1218 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1219
getImageViewMinLodParams(void) const1220 ImageViewMinLodParams* getImageViewMinLodParams (void) const { return DE_NULL; }
1221
1222
1223 protected:
1224 int selectLayer (float q) const;
1225
1226 int m_numLevels;
1227 const ConstPixelBufferAccess* m_levels;
1228 } DE_WARN_UNUSED_TYPE;
1229
1230 /*--------------------------------------------------------------------*//*!
1231 * \brief Cube Map Array Texture reference implementation
1232 *//*--------------------------------------------------------------------*/
1233 class TextureCubeArray : private TextureLevelPyramid
1234 {
1235 public:
1236 TextureCubeArray (const TextureFormat& format, int size, int depth);
1237 TextureCubeArray (const TextureCubeArray& other);
1238 ~TextureCubeArray (void);
1239
getSize(void) const1240 int getSize (void) const { return m_size; }
getDepth(void) const1241 int getDepth (void) const { return m_depth; }
1242
1243 void allocLevel (int levelNdx);
1244
1245 using TextureLevelPyramid::getFormat;
1246 using TextureLevelPyramid::getNumLevels;
1247 using TextureLevelPyramid::getLevel;
1248 using TextureLevelPyramid::clearLevel;
1249 using TextureLevelPyramid::isLevelEmpty;
1250
1251 Vec4 sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const;
1252 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1253 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
1254 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1255
1256 TextureCubeArray& operator= (const TextureCubeArray& other);
1257
operator TextureCubeArrayView(void) const1258 operator TextureCubeArrayView (void) const { return m_view; }
1259
1260 private:
1261 int m_size;
1262 int m_depth;
1263 TextureCubeArrayView m_view;
1264 } DE_WARN_UNUSED_TYPE;
1265
sample(const Sampler & sampler,float s,float t,float r,float q,float lod) const1266 inline Vec4 TextureCubeArray::sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const
1267 {
1268 return m_view.sample(sampler, s, t, r, q, lod);
1269 }
1270
sampleOffset(const Sampler & sampler,float s,float t,float r,float q,float lod,const IVec2 & offset) const1271 inline Vec4 TextureCubeArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const
1272 {
1273 return m_view.sampleOffset(sampler, s, t, r, q, lod, offset);
1274 }
1275
sampleCompare(const Sampler & sampler,float ref,float s,float t,float r,float q,float lod) const1276 inline float TextureCubeArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const
1277 {
1278 return m_view.sampleCompare(sampler, ref, s, t, r, q, lod);
1279 }
1280
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float r,float q,float lod,const IVec2 & offset) const1281 inline float TextureCubeArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const
1282 {
1283 return m_view.sampleCompareOffset(sampler, ref, s, t, r, q, lod, offset);
1284 }
1285
1286 // Stream operators.
1287 std::ostream& operator<< (std::ostream& str, TextureFormat::ChannelOrder order);
1288 std::ostream& operator<< (std::ostream& str, TextureFormat::ChannelType type);
1289 std::ostream& operator<< (std::ostream& str, TextureFormat format);
1290 std::ostream& operator<< (std::ostream& str, CubeFace face);
1291 std::ostream& operator<< (std::ostream& str, const ConstPixelBufferAccess& access);
1292
1293 } // tcu
1294
1295 #endif // _TCUTEXTURE_HPP
1296