1 #ifndef _TCUTEXTURE_HPP
2 #define _TCUTEXTURE_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program Tester Core
5 * ----------------------------------------
7 * Copyright 2014 The Android Open Source Project
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * \brief Reference Texture Implementation.
24 *//*--------------------------------------------------------------------*/
26 #include "tcuDefs.hpp"
27 #include "tcuVector.hpp"
28 #include "rrGenericVector.hpp"
29 #include "deArrayBuffer.hpp"
37 /*--------------------------------------------------------------------*//*!
38 * \brief Texture format
39 *//*--------------------------------------------------------------------*/
88 SNORM_INT_1010102_REV,
89 UNORM_INT_1010102_REV,
94 SIGNED_INT_1010102_REV,
95 UNSIGNED_INT_1010102_REV,
96 UNSIGNED_INT_11F_11F_10F_REV,
97 UNSIGNED_INT_999_E5_REV,
100 UNSIGNED_INT_24_8_REV,
111 FLOAT_UNSIGNED_INT_24_8_REV,
119 TextureFormat (ChannelOrder order_, ChannelType type_)
126 : order (CHANNELORDER_LAST)
127 , type (CHANNELTYPE_LAST)
131 int getPixelSize (void) const; //!< Deprecated, use tcu::getPixelSize(fmt)
133 bool operator== (const TextureFormat& other) const { return !(*this != other); }
134 bool operator!= (const TextureFormat& other) const
136 return (order != other.order || type != other.type);
138 } DE_WARN_UNUSED_TYPE;
140 bool isValid (TextureFormat format);
141 int getPixelSize (TextureFormat format);
142 int getNumUsedChannels (TextureFormat::ChannelOrder order);
143 int getChannelSize (TextureFormat::ChannelType type);
145 /*--------------------------------------------------------------------*//*!
146 * \brief Texture swizzle
147 *//*--------------------------------------------------------------------*/
148 struct TextureSwizzle
152 // \note CHANNEL_N must equal int N
164 Channel components[4];
167 //! get the swizzle used to expand texture data with a given channel order to RGBA form
168 const TextureSwizzle& getChannelReadSwizzle (TextureFormat::ChannelOrder order);
170 //! get the swizzle used to narrow RGBA form data to native texture data with a given channel order
171 const TextureSwizzle& getChannelWriteSwizzle (TextureFormat::ChannelOrder order);
173 /*--------------------------------------------------------------------*//*!
174 * \brief Sampling parameters
175 *//*--------------------------------------------------------------------*/
181 CLAMP_TO_EDGE = 0, //! Clamp to edge
182 CLAMP_TO_BORDER, //! Use border color at edge
183 REPEAT_GL, //! Repeat with OpenGL semantics
184 REPEAT_CL, //! Repeat with OpenCL semantics
185 MIRRORED_REPEAT_GL, //! Mirrored repeat with OpenGL semantics
186 MIRRORED_REPEAT_CL, //! Mirrored repeat with OpenCL semantics
187 MIRRORED_ONCE, //! Mirrored once in negative directions
197 NEAREST_MIPMAP_NEAREST,
198 NEAREST_MIPMAP_LINEAR,
199 LINEAR_MIPMAP_NEAREST,
200 LINEAR_MIPMAP_LINEAR,
207 COMPAREMODE_NONE = 0,
209 COMPAREMODE_LESS_OR_EQUAL,
211 COMPAREMODE_GREATER_OR_EQUAL,
213 COMPAREMODE_NOT_EQUAL,
220 enum DepthStencilMode
233 // Minifcation & magnification
234 FilterMode minFilter;
235 FilterMode magFilter;
236 float lodThreshold; // lod <= lodThreshold ? magnified : minified
238 // Coordinate normalization
239 bool normalizedCoords;
246 // \note It is setter's responsibility to guarantee that the values are representable
247 // in sampled texture's internal format.
248 // \note It is setter's responsibility to guarantee that the format is compatible with the
249 // sampled texture's internal format. Otherwise results are undefined.
250 rr::GenericVec4 borderColor;
252 // Seamless cube map filtering
253 bool seamlessCubeMap;
255 // Depth stencil mode
256 DepthStencilMode depthStencilMode;
258 Sampler (WrapMode wrapS_,
261 FilterMode minFilter_,
262 FilterMode magFilter_,
263 float lodThreshold_ = 0.0f,
264 bool normalizedCoords_ = true,
265 CompareMode compare_ = COMPAREMODE_NONE,
266 int compareChannel_ = 0,
267 const Vec4& borderColor_ = Vec4(0.0f, 0.0f, 0.0f, 0.0f),
268 bool seamlessCubeMap_ = false,
269 DepthStencilMode depthStencilMode_ = MODE_DEPTH)
273 , minFilter (minFilter_)
274 , magFilter (magFilter_)
275 , lodThreshold (lodThreshold_)
276 , normalizedCoords (normalizedCoords_)
278 , compareChannel (compareChannel_)
279 , borderColor (borderColor_)
280 , seamlessCubeMap (seamlessCubeMap_)
281 , depthStencilMode (depthStencilMode_)
286 : wrapS (WRAPMODE_LAST)
287 , wrapT (WRAPMODE_LAST)
288 , wrapR (WRAPMODE_LAST)
289 , minFilter (FILTERMODE_LAST)
290 , magFilter (FILTERMODE_LAST)
291 , lodThreshold (0.0f)
292 , normalizedCoords (true)
293 , compare (COMPAREMODE_NONE)
295 , borderColor (Vec4(0.0f, 0.0f, 0.0f, 0.0f))
296 , seamlessCubeMap (false)
297 , depthStencilMode (MODE_DEPTH)
300 } DE_WARN_UNUSED_TYPE;
302 // Calculate pitches for pixel data with no padding.
303 IVec3 calculatePackedPitch (const TextureFormat& format, const IVec3& size);
307 /*--------------------------------------------------------------------*//*!
308 * \brief Read-only pixel data access
310 * ConstPixelBufferAccess encapsulates pixel data pointer along with
311 * format and layout information. It can be used for read-only access
312 * to arbitrary pixel buffers.
314 * Access objects are like iterators or pointers. They can be passed around
315 * as values and are valid as long as the storage doesn't change.
316 *//*--------------------------------------------------------------------*/
317 class ConstPixelBufferAccess
320 ConstPixelBufferAccess (void);
321 ConstPixelBufferAccess (const TextureLevel& level);
322 ConstPixelBufferAccess (const TextureFormat& format, int width, int height, int depth, const void* data);
323 ConstPixelBufferAccess (const TextureFormat& format, const IVec3& size, const void* data);
324 ConstPixelBufferAccess (const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, const void* data);
325 ConstPixelBufferAccess (const TextureFormat& format, const IVec3& size, const IVec3& pitch, const void* data);
327 const TextureFormat& getFormat (void) const { return m_format; }
328 const IVec3& getSize (void) const { return m_size; }
329 int getWidth (void) const { return m_size.x(); }
330 int getHeight (void) const { return m_size.y(); }
331 int getDepth (void) const { return m_size.z(); }
332 int getPixelPitch (void) const { return m_pitch.x(); }
333 int getRowPitch (void) const { return m_pitch.y(); }
334 int getSlicePitch (void) const { return m_pitch.z(); }
335 const IVec3& getPitch (void) const { return m_pitch; }
337 const void* getDataPtr (void) const { return m_data; }
338 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(); }
340 Vec4 getPixel (int x, int y, int z = 0) const;
341 IVec4 getPixelInt (int x, int y, int z = 0) const;
342 UVec4 getPixelUint (int x, int y, int z = 0) const { return getPixelInt(x, y, z).cast<deUint32>(); }
345 Vector<T, 4> getPixelT (int x, int y, int z = 0) const;
347 float getPixDepth (int x, int y, int z = 0) const;
348 int getPixStencil (int x, int y, int z = 0) const;
350 Vec4 sample1D (const Sampler& sampler, Sampler::FilterMode filter, float s, int level) const;
351 Vec4 sample2D (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, int depth) const;
352 Vec4 sample3D (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, float r) const;
354 Vec4 sample1DOffset (const Sampler& sampler, Sampler::FilterMode filter, float s, const IVec2& offset) const;
355 Vec4 sample2DOffset (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, const IVec3& offset) const;
356 Vec4 sample3DOffset (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, float r, const IVec3& offset) const;
358 float sample1DCompare (const Sampler& sampler, Sampler::FilterMode filter, float ref, float s, const IVec2& offset) const;
359 float sample2DCompare (const Sampler& sampler, Sampler::FilterMode filter, float ref, float s, float t, const IVec3& offset) const;
362 TextureFormat m_format;
364 IVec3 m_pitch; //!< (pixelPitch, rowPitch, slicePitch)
365 mutable void* m_data;
366 } DE_WARN_UNUSED_TYPE;
368 /*--------------------------------------------------------------------*//*!
369 * \brief Read-write pixel data access
371 * This class extends read-only access object by providing write functionality.
373 * \note PixelBufferAccess may not have any data members nor add any
374 * virtual functions. It must be possible to reinterpret_cast<>
375 * PixelBufferAccess to ConstPixelBufferAccess.
376 *//*--------------------------------------------------------------------*/
377 class PixelBufferAccess : public ConstPixelBufferAccess
380 PixelBufferAccess (void) {}
381 PixelBufferAccess (TextureLevel& level);
382 PixelBufferAccess (const TextureFormat& format, int width, int height, int depth, void* data);
383 PixelBufferAccess (const TextureFormat& format, const IVec3& size, void* data);
384 PixelBufferAccess (const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, void* data);
385 PixelBufferAccess (const TextureFormat& format, const IVec3& size, const IVec3& pitch, void* data);
387 void* getDataPtr (void) const { return m_data; }
388 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(); }
390 void setPixel (const tcu::Vec4& color, int x, int y, int z = 0) const;
391 void setPixel (const tcu::IVec4& color, int x, int y, int z = 0) const;
392 void setPixel (const tcu::UVec4& color, int x, int y, int z = 0) const { setPixel(color.cast<int>(), x, y, z); }
394 void setPixDepth (float depth, int x, int y, int z = 0) const;
395 void setPixStencil (int stencil, int x, int y, int z = 0) const;
396 } DE_WARN_UNUSED_TYPE;
398 /*--------------------------------------------------------------------*//*!
399 * \brief Generic pixel data container
401 * This container supports all valid TextureFormat combinations and
402 * both 2D and 3D textures. To read or manipulate data access object must
403 * be queried using getAccess().
404 *//*--------------------------------------------------------------------*/
409 TextureLevel (const TextureFormat& format);
410 TextureLevel (const TextureFormat& format, int width, int height, int depth = 1);
411 ~TextureLevel (void);
413 const IVec3& getSize (void) const { return m_size; }
414 int getWidth (void) const { return m_size.x(); }
415 int getHeight (void) const { return m_size.y(); }
416 int getDepth (void) const { return m_size.z(); }
417 bool isEmpty (void) const { return m_size.x() * m_size.y() * m_size.z() == 0; }
418 const TextureFormat getFormat (void) const { return m_format; }
420 void setStorage (const TextureFormat& format, int width, int heigth, int depth = 1);
421 void setSize (int width, int height, int depth = 1);
423 PixelBufferAccess getAccess (void) { return isEmpty() ? PixelBufferAccess() : PixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr()); }
424 ConstPixelBufferAccess getAccess (void) const { return isEmpty() ? ConstPixelBufferAccess() : ConstPixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr()); }
427 void* getPtr (void) { return m_data.getPtr(); }
428 const void* getPtr (void) const { return m_data.getPtr(); }
430 TextureFormat m_format;
432 de::ArrayBuffer<deUint8> m_data;
434 friend class ConstPixelBufferAccess;
435 } DE_WARN_UNUSED_TYPE;
437 Vec4 sampleLevelArray1D (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, int level, float lod);
438 Vec4 sampleLevelArray2D (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, int depth, float lod);
439 Vec4 sampleLevelArray3D (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float r, float lod);
441 Vec4 sampleLevelArray1DOffset (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float lod, const IVec2& offset);
442 Vec4 sampleLevelArray2DOffset (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float lod, const IVec3& offset);
443 Vec4 sampleLevelArray3DOffset (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset);
445 float sampleLevelArray1DCompare (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float ref, float s, float lod, const IVec2& offset);
446 float sampleLevelArray2DCompare (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float ref, float s, float t, float lod, const IVec3& offset);
448 Vec4 gatherArray2DOffsets (const ConstPixelBufferAccess& src, const Sampler& sampler, float s, float t, int depth, int componentNdx, const IVec2 (&offsets)[4]);
449 Vec4 gatherArray2DOffsetsCompare (const ConstPixelBufferAccess& src, const Sampler& sampler, float ref, float s, float t, int depth, const IVec2 (&offsets)[4]);
453 CUBEFACE_NEGATIVE_X = 0,
463 /*--------------------------------------------------------------------*//*!
464 * \brief Coordinates projected onto cube face.
465 *//*--------------------------------------------------------------------*/
467 struct CubeFaceCoords
473 CubeFaceCoords (CubeFace face_, T s_, T t_) : face(face_), s(s_), t(t_) {}
474 CubeFaceCoords (CubeFace face_, const Vector<T, 2>& c) : face(face_), s(c.x()), t(c.y()) {}
475 } DE_WARN_UNUSED_TYPE;
477 typedef CubeFaceCoords<float> CubeFaceFloatCoords;
478 typedef CubeFaceCoords<int> CubeFaceIntCoords;
480 CubeFace selectCubeFace (const Vec3& coords);
481 Vec2 projectToFace (CubeFace face, const Vec3& coords);
482 CubeFaceFloatCoords getCubeFaceCoords (const Vec3& coords);
483 CubeFaceIntCoords remapCubeEdgeCoords (const CubeFaceIntCoords& coords, int size);
485 /*--------------------------------------------------------------------*//*!
486 * \brief 1D Texture View
487 *//*--------------------------------------------------------------------*/
491 Texture1DView (int numLevels, const ConstPixelBufferAccess* levels);
493 int getNumLevels (void) const { return m_numLevels; }
494 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
495 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
496 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
498 Vec4 sample (const Sampler& sampler, float s, float lod) const;
499 Vec4 sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const;
500 float sampleCompare (const Sampler& sampler, float ref, float s, float lod) const;
501 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const;
505 const ConstPixelBufferAccess* m_levels;
506 } DE_WARN_UNUSED_TYPE;
508 inline Texture1DView::Texture1DView (int numLevels, const ConstPixelBufferAccess* levels)
509 : m_numLevels (numLevels)
512 DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
515 inline Vec4 Texture1DView::sample (const Sampler& sampler, float s, float lod) const
517 return sampleLevelArray1D(m_levels, m_numLevels, sampler, s, 0 /* depth */, lod);
520 inline Vec4 Texture1DView::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
522 return sampleLevelArray1DOffset(m_levels, m_numLevels, sampler, s, lod, IVec2(offset, 0));
525 inline float Texture1DView::sampleCompare (const Sampler& sampler, float ref, float s, float lod) const
527 return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(0, 0));
530 inline float Texture1DView::sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const
532 return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(offset, 0));
535 /*--------------------------------------------------------------------*//*!
536 * \brief 2D Texture View
537 *//*--------------------------------------------------------------------*/
541 Texture2DView (int numLevels, const ConstPixelBufferAccess* levels);
543 int getNumLevels (void) const { return m_numLevels; }
544 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
545 int getHeight (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
546 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
547 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
549 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
550 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
551 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
552 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
554 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
555 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
559 const ConstPixelBufferAccess* m_levels;
560 } DE_WARN_UNUSED_TYPE;
562 inline Texture2DView::Texture2DView (int numLevels, const ConstPixelBufferAccess* levels)
563 : m_numLevels (numLevels)
566 DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
569 inline Vec4 Texture2DView::sample (const Sampler& sampler, float s, float t, float lod) const
571 return sampleLevelArray2D(m_levels, m_numLevels, sampler, s, t, 0 /* depth */, lod);
574 inline Vec4 Texture2DView::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
576 return sampleLevelArray2DOffset(m_levels, m_numLevels, sampler, s, t, lod, IVec3(offset.x(), offset.y(), 0));
579 inline float Texture2DView::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
581 return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(0, 0, 0));
584 inline float Texture2DView::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
586 return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(offset.x(), offset.y(), 0));
589 inline Vec4 Texture2DView::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
591 return gatherArray2DOffsets(m_levels[0], sampler, s, t, 0, componentNdx, offsets);
594 inline Vec4 Texture2DView::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
596 return gatherArray2DOffsetsCompare(m_levels[0], sampler, ref, s, t, 0, offsets);
599 /*--------------------------------------------------------------------*//*!
600 * \brief Base class for textures that have single mip-map pyramid
601 *//*--------------------------------------------------------------------*/
602 class TextureLevelPyramid
605 TextureLevelPyramid (const TextureFormat& format, int numLevels);
606 TextureLevelPyramid (const TextureLevelPyramid& other);
607 ~TextureLevelPyramid(void);
609 const TextureFormat& getFormat (void) const { return m_format; }
610 int getNumLevels (void) const { return (int)m_access.size(); }
612 bool isLevelEmpty (int levelNdx) const { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[(size_t)levelNdx].empty(); }
613 const ConstPixelBufferAccess& getLevel (int levelNdx) const { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_access[(size_t)levelNdx]; }
614 const PixelBufferAccess& getLevel (int levelNdx) { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_access[(size_t)levelNdx]; }
616 const ConstPixelBufferAccess* getLevels (void) const { return &m_access[0]; }
617 const PixelBufferAccess* getLevels (void) { return &m_access[0]; }
619 void allocLevel (int levelNdx, int width, int height, int depth);
620 void clearLevel (int levelNdx);
622 TextureLevelPyramid& operator= (const TextureLevelPyramid& other);
625 typedef de::ArrayBuffer<deUint8> LevelData;
627 TextureFormat m_format;
628 std::vector<LevelData> m_data;
629 std::vector<PixelBufferAccess> m_access;
630 } DE_WARN_UNUSED_TYPE;
632 /*--------------------------------------------------------------------*//*!
633 * \brief 1D Texture reference implementation
634 *//*--------------------------------------------------------------------*/
635 class Texture1D : private TextureLevelPyramid
638 Texture1D (const TextureFormat& format, int width);
639 Texture1D (const Texture1D& other);
642 int getWidth (void) const { return m_width; }
643 const Texture1DView& getView (void) const { return m_view; }
645 void allocLevel (int levelNdx);
648 Vec4 sample (const Sampler& sampler, float s, float lod) const;
649 Vec4 sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const;
650 float sampleCompare (const Sampler& sampler, float ref, float s, float lod) const;
651 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const;
653 using TextureLevelPyramid::getFormat;
654 using TextureLevelPyramid::getNumLevels;
655 using TextureLevelPyramid::getLevel;
656 using TextureLevelPyramid::clearLevel;
657 using TextureLevelPyramid::isLevelEmpty;
659 Texture1D& operator= (const Texture1D& other);
661 operator Texture1DView (void) const { return m_view; }
665 Texture1DView m_view;
666 } DE_WARN_UNUSED_TYPE;
668 inline Vec4 Texture1D::sample (const Sampler& sampler, float s, float lod) const
670 return m_view.sample(sampler, s, lod);
673 inline Vec4 Texture1D::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
675 return m_view.sampleOffset(sampler, s, lod, offset);
678 inline float Texture1D::sampleCompare (const Sampler& sampler, float ref, float s, float lod) const
680 return m_view.sampleCompare(sampler, ref, s, lod);
683 inline float Texture1D::sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const
685 return m_view.sampleCompareOffset(sampler, ref, s, lod, offset);
688 /*--------------------------------------------------------------------*//*!
689 * \brief 2D Texture reference implementation
690 *//*--------------------------------------------------------------------*/
691 class Texture2D : private TextureLevelPyramid
694 Texture2D (const TextureFormat& format, int width, int height);
695 Texture2D (const Texture2D& other);
698 int getWidth (void) const { return m_width; }
699 int getHeight (void) const { return m_height; }
700 const Texture2DView& getView (void) const { return m_view; }
702 void allocLevel (int levelNdx);
705 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
706 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
707 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
708 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
710 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
711 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
713 using TextureLevelPyramid::getFormat;
714 using TextureLevelPyramid::getNumLevels;
715 using TextureLevelPyramid::getLevel;
716 using TextureLevelPyramid::clearLevel;
717 using TextureLevelPyramid::isLevelEmpty;
719 Texture2D& operator= (const Texture2D& other);
721 operator Texture2DView (void) const { return m_view; }
726 Texture2DView m_view;
727 } DE_WARN_UNUSED_TYPE;
729 inline Vec4 Texture2D::sample (const Sampler& sampler, float s, float t, float lod) const
731 return m_view.sample(sampler, s, t, lod);
734 inline Vec4 Texture2D::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
736 return m_view.sampleOffset(sampler, s, t, lod, offset);
739 inline float Texture2D::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
741 return m_view.sampleCompare(sampler, ref, s, t, lod);
744 inline float Texture2D::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
746 return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
749 inline Vec4 Texture2D::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
751 return m_view.gatherOffsets(sampler, s, t, componentNdx, offsets);
754 inline Vec4 Texture2D::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
756 return m_view.gatherOffsetsCompare(sampler, ref, s, t, offsets);
759 /*--------------------------------------------------------------------*//*!
760 * \brief Cube Map Texture View
761 *//*--------------------------------------------------------------------*/
762 class TextureCubeView
765 TextureCubeView (void);
766 TextureCubeView (int numLevels, const ConstPixelBufferAccess* const (&levels)[CUBEFACE_LAST]);
768 int getNumLevels (void) const { return m_numLevels; }
769 int getSize (void) const { return m_numLevels > 0 ? m_levels[0][0].getWidth() : 0; }
770 const ConstPixelBufferAccess& getLevelFace (int ndx, CubeFace face) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[face][ndx]; }
771 const ConstPixelBufferAccess* getFaceLevels (CubeFace face) const { return m_levels[face]; }
773 Vec4 sample (const Sampler& sampler, float s, float t, float p, float lod) const;
774 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
776 Vec4 gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const;
777 Vec4 gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const;
781 const ConstPixelBufferAccess* m_levels[CUBEFACE_LAST];
782 } DE_WARN_UNUSED_TYPE;
784 /*--------------------------------------------------------------------*//*!
785 * \brief Cube Map Texture reference implementation
786 *//*--------------------------------------------------------------------*/
790 TextureCube (const TextureFormat& format, int size);
791 TextureCube (const TextureCube& other);
794 const TextureFormat& getFormat (void) const { return m_format; }
795 int getSize (void) const { return m_size; }
797 int getNumLevels (void) const { return (int)m_access[0].size(); }
798 const ConstPixelBufferAccess& getLevelFace (int ndx, CubeFace face) const { DE_ASSERT(de::inBounds(ndx, 0, getNumLevels())); return m_access[face][(size_t)ndx]; }
799 const PixelBufferAccess& getLevelFace (int ndx, CubeFace face) { DE_ASSERT(de::inBounds(ndx, 0, getNumLevels())); return m_access[face][(size_t)ndx]; }
801 void allocLevel (CubeFace face, int levelNdx);
802 void clearLevel (CubeFace face, int levelNdx);
803 bool isLevelEmpty (CubeFace face, int levelNdx) const { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[face][(size_t)levelNdx].empty(); }
805 Vec4 sample (const Sampler& sampler, float s, float t, float p, float lod) const;
806 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
808 Vec4 gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const;
809 Vec4 gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const;
811 TextureCube& operator= (const TextureCube& other);
813 operator TextureCubeView (void) const { return m_view; }
816 typedef de::ArrayBuffer<deUint8> LevelData;
818 TextureFormat m_format;
820 std::vector<LevelData> m_data[CUBEFACE_LAST];
821 std::vector<PixelBufferAccess> m_access[CUBEFACE_LAST];
822 TextureCubeView m_view;
823 } DE_WARN_UNUSED_TYPE;
825 inline Vec4 TextureCube::sample (const Sampler& sampler, float s, float t, float p, float lod) const
827 return m_view.sample(sampler, s, t, p, lod);
830 inline float TextureCube::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
832 return m_view.sampleCompare(sampler, ref, s, t, r, lod);
835 inline Vec4 TextureCube::gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const
837 return m_view.gather(sampler, s, t, r, componentNdx);
840 inline Vec4 TextureCube::gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const
842 return m_view.gatherCompare(sampler, ref, s, t, r);
845 /*--------------------------------------------------------------------*//*!
846 * \brief 1D Array Texture View
847 *//*--------------------------------------------------------------------*/
848 class Texture1DArrayView
851 Texture1DArrayView (int numLevels, const ConstPixelBufferAccess* levels);
853 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
854 int getNumLayers (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
855 int getNumLevels (void) const { return m_numLevels; }
856 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
857 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
859 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
860 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
861 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
862 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
865 int selectLayer (float r) const;
868 const ConstPixelBufferAccess* m_levels;
869 } DE_WARN_UNUSED_TYPE;
871 /*--------------------------------------------------------------------*//*!
872 * \brief 2D Array Texture View
873 *//*--------------------------------------------------------------------*/
874 class Texture2DArrayView
877 Texture2DArrayView (int numLevels, const ConstPixelBufferAccess* levels);
879 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
880 int getHeight (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
881 int getNumLayers (void) const { return m_numLevels > 0 ? m_levels[0].getDepth() : 0; }
882 int getNumLevels (void) const { return m_numLevels; }
883 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
884 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
886 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
887 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
888 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
889 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
891 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
892 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
895 int selectLayer (float r) const;
898 const ConstPixelBufferAccess* m_levels;
899 } DE_WARN_UNUSED_TYPE;
901 /*--------------------------------------------------------------------*//*!
902 * \brief 1D Array Texture reference implementation
903 *//*--------------------------------------------------------------------*/
904 class Texture1DArray : private TextureLevelPyramid
907 Texture1DArray (const TextureFormat& format, int width, int numLayers);
908 Texture1DArray (const Texture1DArray& other);
909 ~Texture1DArray (void);
911 int getWidth (void) const { return m_width; }
912 int getNumLayers (void) const { return m_numLayers; }
914 void allocLevel (int levelNdx);
916 using TextureLevelPyramid::getFormat;
917 using TextureLevelPyramid::getNumLevels;
918 using TextureLevelPyramid::getLevel;
919 using TextureLevelPyramid::clearLevel;
920 using TextureLevelPyramid::isLevelEmpty;
922 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
923 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
924 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
925 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
927 Texture1DArray& operator= (const Texture1DArray& other);
929 operator Texture1DArrayView (void) const { return m_view; }
934 Texture1DArrayView m_view;
935 } DE_WARN_UNUSED_TYPE;
937 inline Vec4 Texture1DArray::sample (const Sampler& sampler, float s, float t, float lod) const
939 return m_view.sample(sampler, s, t, lod);
942 inline Vec4 Texture1DArray::sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const
944 return m_view.sampleOffset(sampler, s, t, lod, offset);
947 inline float Texture1DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
949 return m_view.sampleCompare(sampler, ref, s, t, lod);
952 inline float Texture1DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const
954 return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
957 /*--------------------------------------------------------------------*//*!
958 * \brief 2D Array Texture reference implementation
959 *//*--------------------------------------------------------------------*/
960 class Texture2DArray : private TextureLevelPyramid
963 Texture2DArray (const TextureFormat& format, int width, int height, int numLayers);
964 Texture2DArray (const Texture2DArray& other);
965 ~Texture2DArray (void);
967 int getWidth (void) const { return m_width; }
968 int getHeight (void) const { return m_height; }
969 int getNumLayers (void) const { return m_numLayers; }
971 void allocLevel (int levelNdx);
973 using TextureLevelPyramid::getFormat;
974 using TextureLevelPyramid::getNumLevels;
975 using TextureLevelPyramid::getLevel;
976 using TextureLevelPyramid::clearLevel;
977 using TextureLevelPyramid::isLevelEmpty;
979 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
980 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
981 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
982 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
984 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
985 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
987 Texture2DArray& operator= (const Texture2DArray& other);
989 operator Texture2DArrayView (void) const { return m_view; }
995 Texture2DArrayView m_view;
996 } DE_WARN_UNUSED_TYPE;
998 inline Vec4 Texture2DArray::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1000 return m_view.sample(sampler, s, t, r, lod);
1003 inline Vec4 Texture2DArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const
1005 return m_view.sampleOffset(sampler, s, t, r, lod, offset);
1008 inline float Texture2DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
1010 return m_view.sampleCompare(sampler, ref, s, t, r, lod);
1013 inline float Texture2DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const
1015 return m_view.sampleCompareOffset(sampler, ref, s, t, r, lod, offset);
1018 inline Vec4 Texture2DArray::gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const
1020 return m_view.gatherOffsets(sampler, s, t, r, componentNdx, offsets);
1023 inline Vec4 Texture2DArray::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const
1025 return m_view.gatherOffsetsCompare(sampler, ref, s, t, r, offsets);
1028 /*--------------------------------------------------------------------*//*!
1029 * \brief 3D Texture View
1030 *//*--------------------------------------------------------------------*/
1034 Texture3DView (int numLevels, const ConstPixelBufferAccess* levels);
1036 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
1037 int getHeight (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
1038 int getDepth (void) const { return m_numLevels > 0 ? m_levels[0].getDepth() : 0; }
1039 int getNumLevels (void) const { return m_numLevels; }
1040 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
1041 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
1043 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
1044 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
1048 const ConstPixelBufferAccess* m_levels;
1049 } DE_WARN_UNUSED_TYPE;
1051 inline Vec4 Texture3DView::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1053 return sampleLevelArray3D(m_levels, m_numLevels, sampler, s, t, r, lod);
1056 inline Vec4 Texture3DView::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
1058 return sampleLevelArray3DOffset(m_levels, m_numLevels, sampler, s, t, r, lod, offset);
1061 /*--------------------------------------------------------------------*//*!
1062 * \brief 3D Texture reference implementation
1063 *//*--------------------------------------------------------------------*/
1064 class Texture3D : private TextureLevelPyramid
1067 Texture3D (const TextureFormat& format, int width, int height, int depth);
1068 Texture3D (const Texture3D& other);
1071 int getWidth (void) const { return m_width; }
1072 int getHeight (void) const { return m_height; }
1073 int getDepth (void) const { return m_depth; }
1075 void allocLevel (int levelNdx);
1077 using TextureLevelPyramid::getFormat;
1078 using TextureLevelPyramid::getNumLevels;
1079 using TextureLevelPyramid::getLevel;
1080 using TextureLevelPyramid::clearLevel;
1081 using TextureLevelPyramid::isLevelEmpty;
1083 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
1084 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
1086 Texture3D& operator= (const Texture3D& other);
1088 operator Texture3DView (void) const { return m_view; }
1094 Texture3DView m_view;
1095 } DE_WARN_UNUSED_TYPE;
1097 inline Vec4 Texture3D::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1099 return m_view.sample(sampler, s, t, r, lod);
1102 inline Vec4 Texture3D::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
1104 return m_view.sampleOffset(sampler, s, t, r, lod, offset);
1107 /*--------------------------------------------------------------------*//*!
1108 * \brief Cube Map Array Texture View
1109 *//*--------------------------------------------------------------------*/
1110 class TextureCubeArrayView
1113 TextureCubeArrayView (int numLevels, const ConstPixelBufferAccess* levels);
1115 int getSize (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
1116 int getDepth (void) const { return m_numLevels > 0 ? m_levels[0].getDepth() : 0; }
1117 int getNumLayers (void) const { return getDepth() / 6; }
1118 int getNumLevels (void) const { return m_numLevels; }
1119 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
1120 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
1122 Vec4 sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const;
1123 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1124 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
1125 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1128 int selectLayer (float q) const;
1131 const ConstPixelBufferAccess* m_levels;
1132 } DE_WARN_UNUSED_TYPE;
1134 /*--------------------------------------------------------------------*//*!
1135 * \brief Cube Map Array Texture reference implementation
1136 *//*--------------------------------------------------------------------*/
1137 class TextureCubeArray : private TextureLevelPyramid
1140 TextureCubeArray (const TextureFormat& format, int size, int depth);
1141 TextureCubeArray (const TextureCubeArray& other);
1142 ~TextureCubeArray (void);
1144 int getSize (void) const { return m_size; }
1145 int getDepth (void) const { return m_depth; }
1147 void allocLevel (int levelNdx);
1149 using TextureLevelPyramid::getFormat;
1150 using TextureLevelPyramid::getNumLevels;
1151 using TextureLevelPyramid::getLevel;
1152 using TextureLevelPyramid::clearLevel;
1153 using TextureLevelPyramid::isLevelEmpty;
1155 Vec4 sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const;
1156 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1157 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
1158 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1160 TextureCubeArray& operator= (const TextureCubeArray& other);
1162 operator TextureCubeArrayView (void) const { return m_view; }
1167 TextureCubeArrayView m_view;
1168 } DE_WARN_UNUSED_TYPE;
1170 inline Vec4 TextureCubeArray::sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const
1172 return m_view.sample(sampler, s, t, r, q, lod);
1175 inline Vec4 TextureCubeArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const
1177 return m_view.sampleOffset(sampler, s, t, r, q, lod, offset);
1180 inline float TextureCubeArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const
1182 return m_view.sampleCompare(sampler, ref, s, t, r, q, lod);
1185 inline float TextureCubeArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const
1187 return m_view.sampleCompareOffset(sampler, ref, s, t, r, q, lod, offset);
1190 // Stream operators.
1191 std::ostream& operator<< (std::ostream& str, TextureFormat::ChannelOrder order);
1192 std::ostream& operator<< (std::ostream& str, TextureFormat::ChannelType type);
1193 std::ostream& operator<< (std::ostream& str, TextureFormat format);
1194 std::ostream& operator<< (std::ostream& str, CubeFace face);
1195 std::ostream& operator<< (std::ostream& str, const ConstPixelBufferAccess& access);
1199 #endif // _TCUTEXTURE_HPP