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);
144 /*--------------------------------------------------------------------*//*!
145 * \brief Texture swizzle
146 *//*--------------------------------------------------------------------*/
147 struct TextureSwizzle
151 // \note CHANNEL_N must equal int N
163 Channel components[4];
166 //! get the swizzle used to expand texture data with a given channel order to RGBA form
167 const TextureSwizzle& getChannelReadSwizzle (TextureFormat::ChannelOrder order);
169 //! get the swizzle used to narrow RGBA form data to native texture data with a given channel order
170 const TextureSwizzle& getChannelWriteSwizzle (TextureFormat::ChannelOrder order);
172 /*--------------------------------------------------------------------*//*!
173 * \brief Sampling parameters
174 *//*--------------------------------------------------------------------*/
180 CLAMP_TO_EDGE = 0, //! Clamp to edge
181 CLAMP_TO_BORDER, //! Use border color at edge
182 REPEAT_GL, //! Repeat with OpenGL semantics
183 REPEAT_CL, //! Repeat with OpenCL semantics
184 MIRRORED_REPEAT_GL, //! Mirrored repeat with OpenGL semantics
185 MIRRORED_REPEAT_CL, //! Mirrored repeat with OpenCL semantics
186 MIRRORED_ONCE, //! Mirrored once in negative directions
196 NEAREST_MIPMAP_NEAREST,
197 NEAREST_MIPMAP_LINEAR,
198 LINEAR_MIPMAP_NEAREST,
199 LINEAR_MIPMAP_LINEAR,
206 COMPAREMODE_NONE = 0,
208 COMPAREMODE_LESS_OR_EQUAL,
210 COMPAREMODE_GREATER_OR_EQUAL,
212 COMPAREMODE_NOT_EQUAL,
219 enum DepthStencilMode
232 // Minifcation & magnification
233 FilterMode minFilter;
234 FilterMode magFilter;
235 float lodThreshold; // lod <= lodThreshold ? magnified : minified
237 // Coordinate normalization
238 bool normalizedCoords;
245 // \note It is setter's responsibility to guarantee that the values are representable
246 // in sampled texture's internal format.
247 // \note It is setter's responsibility to guarantee that the format is compatible with the
248 // sampled texture's internal format. Otherwise results are undefined.
249 rr::GenericVec4 borderColor;
251 // Seamless cube map filtering
252 bool seamlessCubeMap;
254 // Depth stencil mode
255 DepthStencilMode depthStencilMode;
257 Sampler (WrapMode wrapS_,
260 FilterMode minFilter_,
261 FilterMode magFilter_,
262 float lodThreshold_ = 0.0f,
263 bool normalizedCoords_ = true,
264 CompareMode compare_ = COMPAREMODE_NONE,
265 int compareChannel_ = 0,
266 const Vec4& borderColor_ = Vec4(0.0f, 0.0f, 0.0f, 0.0f),
267 bool seamlessCubeMap_ = false,
268 DepthStencilMode depthStencilMode_ = MODE_DEPTH)
272 , minFilter (minFilter_)
273 , magFilter (magFilter_)
274 , lodThreshold (lodThreshold_)
275 , normalizedCoords (normalizedCoords_)
277 , compareChannel (compareChannel_)
278 , borderColor (borderColor_)
279 , seamlessCubeMap (seamlessCubeMap_)
280 , depthStencilMode (depthStencilMode_)
285 : wrapS (WRAPMODE_LAST)
286 , wrapT (WRAPMODE_LAST)
287 , wrapR (WRAPMODE_LAST)
288 , minFilter (FILTERMODE_LAST)
289 , magFilter (FILTERMODE_LAST)
290 , lodThreshold (0.0f)
291 , normalizedCoords (true)
292 , compare (COMPAREMODE_NONE)
294 , borderColor (Vec4(0.0f, 0.0f, 0.0f, 0.0f))
295 , seamlessCubeMap (false)
296 , depthStencilMode (MODE_DEPTH)
299 } DE_WARN_UNUSED_TYPE;
301 // Calculate pitches for pixel data with no padding.
302 IVec3 calculatePackedPitch (const TextureFormat& format, const IVec3& size);
306 /*--------------------------------------------------------------------*//*!
307 * \brief Read-only pixel data access
309 * ConstPixelBufferAccess encapsulates pixel data pointer along with
310 * format and layout information. It can be used for read-only access
311 * to arbitrary pixel buffers.
313 * Access objects are like iterators or pointers. They can be passed around
314 * as values and are valid as long as the storage doesn't change.
315 *//*--------------------------------------------------------------------*/
316 class ConstPixelBufferAccess
319 ConstPixelBufferAccess (void);
320 ConstPixelBufferAccess (const TextureLevel& level);
321 ConstPixelBufferAccess (const TextureFormat& format, int width, int height, int depth, const void* data);
322 ConstPixelBufferAccess (const TextureFormat& format, const IVec3& size, const void* data);
323 ConstPixelBufferAccess (const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, const void* data);
324 ConstPixelBufferAccess (const TextureFormat& format, const IVec3& size, const IVec3& pitch, const void* data);
326 const TextureFormat& getFormat (void) const { return m_format; }
327 const IVec3& getSize (void) const { return m_size; }
328 int getWidth (void) const { return m_size.x(); }
329 int getHeight (void) const { return m_size.y(); }
330 int getDepth (void) const { return m_size.z(); }
331 int getPixelPitch (void) const { return m_pitch.x(); }
332 int getRowPitch (void) const { return m_pitch.y(); }
333 int getSlicePitch (void) const { return m_pitch.z(); }
334 const IVec3& getPitch (void) const { return m_pitch; }
336 const void* getDataPtr (void) const { return m_data; }
337 const void* getPixelPtr (int x, int y, int z = 0) const { return (const deUint8*)m_data + x * m_pitch.x() + y * m_pitch.y() + z * m_pitch.z(); }
339 Vec4 getPixel (int x, int y, int z = 0) const;
340 IVec4 getPixelInt (int x, int y, int z = 0) const;
341 UVec4 getPixelUint (int x, int y, int z = 0) const { return getPixelInt(x, y, z).cast<deUint32>(); }
344 Vector<T, 4> getPixelT (int x, int y, int z = 0) const;
346 float getPixDepth (int x, int y, int z = 0) const;
347 int getPixStencil (int x, int y, int z = 0) const;
349 Vec4 sample1D (const Sampler& sampler, Sampler::FilterMode filter, float s, int level) const;
350 Vec4 sample2D (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, int depth) const;
351 Vec4 sample3D (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, float r) const;
353 Vec4 sample1DOffset (const Sampler& sampler, Sampler::FilterMode filter, float s, const IVec2& offset) const;
354 Vec4 sample2DOffset (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, const IVec3& offset) const;
355 Vec4 sample3DOffset (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, float r, const IVec3& offset) const;
357 float sample1DCompare (const Sampler& sampler, Sampler::FilterMode filter, float ref, float s, const IVec2& offset) const;
358 float sample2DCompare (const Sampler& sampler, Sampler::FilterMode filter, float ref, float s, float t, const IVec3& offset) const;
361 TextureFormat m_format;
363 IVec3 m_pitch; //!< (pixelPitch, rowPitch, slicePitch)
364 mutable void* m_data;
365 } DE_WARN_UNUSED_TYPE;
367 /*--------------------------------------------------------------------*//*!
368 * \brief Read-write pixel data access
370 * This class extends read-only access object by providing write functionality.
372 * \note PixelBufferAccess may not have any data members nor add any
373 * virtual functions. It must be possible to reinterpret_cast<>
374 * PixelBufferAccess to ConstPixelBufferAccess.
375 *//*--------------------------------------------------------------------*/
376 class PixelBufferAccess : public ConstPixelBufferAccess
379 PixelBufferAccess (void) {}
380 PixelBufferAccess (TextureLevel& level);
381 PixelBufferAccess (const TextureFormat& format, int width, int height, int depth, void* data);
382 PixelBufferAccess (const TextureFormat& format, const IVec3& size, void* data);
383 PixelBufferAccess (const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, void* data);
384 PixelBufferAccess (const TextureFormat& format, const IVec3& size, const IVec3& pitch, void* data);
386 void* getDataPtr (void) const { return m_data; }
387 void* getPixelPtr (int x, int y, int z = 0) const { return (deUint8*)m_data + x * m_pitch.x() + y * m_pitch.y() + z * m_pitch.z(); }
389 void setPixel (const tcu::Vec4& color, int x, int y, int z = 0) const;
390 void setPixel (const tcu::IVec4& color, int x, int y, int z = 0) const;
391 void setPixel (const tcu::UVec4& color, int x, int y, int z = 0) const { setPixel(color.cast<int>(), x, y, z); }
393 void setPixDepth (float depth, int x, int y, int z = 0) const;
394 void setPixStencil (int stencil, int x, int y, int z = 0) const;
395 } DE_WARN_UNUSED_TYPE;
397 /*--------------------------------------------------------------------*//*!
398 * \brief Generic pixel data container
400 * This container supports all valid TextureFormat combinations and
401 * both 2D and 3D textures. To read or manipulate data access object must
402 * be queried using getAccess().
403 *//*--------------------------------------------------------------------*/
408 TextureLevel (const TextureFormat& format);
409 TextureLevel (const TextureFormat& format, int width, int height, int depth = 1);
410 ~TextureLevel (void);
412 const IVec3& getSize (void) const { return m_size; }
413 int getWidth (void) const { return m_size.x(); }
414 int getHeight (void) const { return m_size.y(); }
415 int getDepth (void) const { return m_size.z(); }
416 bool isEmpty (void) const { return m_size.x() * m_size.y() * m_size.z() == 0; }
417 const TextureFormat getFormat (void) const { return m_format; }
419 void setStorage (const TextureFormat& format, int width, int heigth, int depth = 1);
420 void setSize (int width, int height, int depth = 1);
422 PixelBufferAccess getAccess (void) { return isEmpty() ? PixelBufferAccess() : PixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr()); }
423 ConstPixelBufferAccess getAccess (void) const { return isEmpty() ? ConstPixelBufferAccess() : ConstPixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr()); }
426 void* getPtr (void) { return m_data.getPtr(); }
427 const void* getPtr (void) const { return m_data.getPtr(); }
429 TextureFormat m_format;
431 de::ArrayBuffer<deUint8> m_data;
433 friend class ConstPixelBufferAccess;
434 } DE_WARN_UNUSED_TYPE;
436 Vec4 sampleLevelArray1D (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, int level, float lod);
437 Vec4 sampleLevelArray2D (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, int depth, float lod);
438 Vec4 sampleLevelArray3D (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float r, float lod);
440 Vec4 sampleLevelArray1DOffset (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float lod, const IVec2& offset);
441 Vec4 sampleLevelArray2DOffset (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float lod, const IVec3& offset);
442 Vec4 sampleLevelArray3DOffset (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset);
444 float sampleLevelArray1DCompare (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float ref, float s, float lod, const IVec2& offset);
445 float sampleLevelArray2DCompare (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float ref, float s, float t, float lod, const IVec3& offset);
447 Vec4 gatherArray2DOffsets (const ConstPixelBufferAccess& src, const Sampler& sampler, float s, float t, int depth, int componentNdx, const IVec2 (&offsets)[4]);
448 Vec4 gatherArray2DOffsetsCompare (const ConstPixelBufferAccess& src, const Sampler& sampler, float ref, float s, float t, int depth, const IVec2 (&offsets)[4]);
452 CUBEFACE_NEGATIVE_X = 0,
462 /*--------------------------------------------------------------------*//*!
463 * \brief Coordinates projected onto cube face.
464 *//*--------------------------------------------------------------------*/
466 struct CubeFaceCoords
472 CubeFaceCoords (CubeFace face_, T s_, T t_) : face(face_), s(s_), t(t_) {}
473 CubeFaceCoords (CubeFace face_, const Vector<T, 2>& c) : face(face_), s(c.x()), t(c.y()) {}
474 } DE_WARN_UNUSED_TYPE;
476 typedef CubeFaceCoords<float> CubeFaceFloatCoords;
477 typedef CubeFaceCoords<int> CubeFaceIntCoords;
479 CubeFace selectCubeFace (const Vec3& coords);
480 Vec2 projectToFace (CubeFace face, const Vec3& coords);
481 CubeFaceFloatCoords getCubeFaceCoords (const Vec3& coords);
482 CubeFaceIntCoords remapCubeEdgeCoords (const CubeFaceIntCoords& coords, int size);
484 /*--------------------------------------------------------------------*//*!
485 * \brief 1D Texture View
486 *//*--------------------------------------------------------------------*/
490 Texture1DView (int numLevels, const ConstPixelBufferAccess* levels);
492 int getNumLevels (void) const { return m_numLevels; }
493 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
494 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
495 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
497 Vec4 sample (const Sampler& sampler, float s, float lod) const;
498 Vec4 sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const;
499 float sampleCompare (const Sampler& sampler, float ref, float s, float lod) const;
500 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const;
504 const ConstPixelBufferAccess* m_levels;
505 } DE_WARN_UNUSED_TYPE;
507 inline Texture1DView::Texture1DView (int numLevels, const ConstPixelBufferAccess* levels)
508 : m_numLevels (numLevels)
511 DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
514 inline Vec4 Texture1DView::sample (const Sampler& sampler, float s, float lod) const
516 return sampleLevelArray1D(m_levels, m_numLevels, sampler, s, 0 /* depth */, lod);
519 inline Vec4 Texture1DView::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
521 return sampleLevelArray1DOffset(m_levels, m_numLevels, sampler, s, lod, IVec2(offset, 0));
524 inline float Texture1DView::sampleCompare (const Sampler& sampler, float ref, float s, float lod) const
526 return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(0, 0));
529 inline float Texture1DView::sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const
531 return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(offset, 0));
534 /*--------------------------------------------------------------------*//*!
535 * \brief 2D Texture View
536 *//*--------------------------------------------------------------------*/
540 Texture2DView (int numLevels, const ConstPixelBufferAccess* levels);
542 int getNumLevels (void) const { return m_numLevels; }
543 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
544 int getHeight (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
545 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
546 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
548 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
549 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
550 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
551 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
553 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
554 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
558 const ConstPixelBufferAccess* m_levels;
559 } DE_WARN_UNUSED_TYPE;
561 inline Texture2DView::Texture2DView (int numLevels, const ConstPixelBufferAccess* levels)
562 : m_numLevels (numLevels)
565 DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
568 inline Vec4 Texture2DView::sample (const Sampler& sampler, float s, float t, float lod) const
570 return sampleLevelArray2D(m_levels, m_numLevels, sampler, s, t, 0 /* depth */, lod);
573 inline Vec4 Texture2DView::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
575 return sampleLevelArray2DOffset(m_levels, m_numLevels, sampler, s, t, lod, IVec3(offset.x(), offset.y(), 0));
578 inline float Texture2DView::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
580 return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(0, 0, 0));
583 inline float Texture2DView::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
585 return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(offset.x(), offset.y(), 0));
588 inline Vec4 Texture2DView::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
590 return gatherArray2DOffsets(m_levels[0], sampler, s, t, 0, componentNdx, offsets);
593 inline Vec4 Texture2DView::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
595 return gatherArray2DOffsetsCompare(m_levels[0], sampler, ref, s, t, 0, offsets);
598 /*--------------------------------------------------------------------*//*!
599 * \brief Base class for textures that have single mip-map pyramid
600 *//*--------------------------------------------------------------------*/
601 class TextureLevelPyramid
604 TextureLevelPyramid (const TextureFormat& format, int numLevels);
605 TextureLevelPyramid (const TextureLevelPyramid& other);
606 ~TextureLevelPyramid(void);
608 const TextureFormat& getFormat (void) const { return m_format; }
609 int getNumLevels (void) const { return (int)m_access.size(); }
611 bool isLevelEmpty (int levelNdx) const { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[(size_t)levelNdx].empty(); }
612 const ConstPixelBufferAccess& getLevel (int levelNdx) const { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_access[(size_t)levelNdx]; }
613 const PixelBufferAccess& getLevel (int levelNdx) { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_access[(size_t)levelNdx]; }
615 const ConstPixelBufferAccess* getLevels (void) const { return &m_access[0]; }
616 const PixelBufferAccess* getLevels (void) { return &m_access[0]; }
618 void allocLevel (int levelNdx, int width, int height, int depth);
619 void clearLevel (int levelNdx);
621 TextureLevelPyramid& operator= (const TextureLevelPyramid& other);
624 typedef de::ArrayBuffer<deUint8> LevelData;
626 TextureFormat m_format;
627 std::vector<LevelData> m_data;
628 std::vector<PixelBufferAccess> m_access;
629 } DE_WARN_UNUSED_TYPE;
631 /*--------------------------------------------------------------------*//*!
632 * \brief 1D Texture reference implementation
633 *//*--------------------------------------------------------------------*/
634 class Texture1D : private TextureLevelPyramid
637 Texture1D (const TextureFormat& format, int width);
638 Texture1D (const Texture1D& other);
641 int getWidth (void) const { return m_width; }
642 const Texture1DView& getView (void) const { return m_view; }
644 void allocLevel (int levelNdx);
647 Vec4 sample (const Sampler& sampler, float s, float lod) const;
648 Vec4 sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const;
650 using TextureLevelPyramid::getFormat;
651 using TextureLevelPyramid::getNumLevels;
652 using TextureLevelPyramid::getLevel;
653 using TextureLevelPyramid::clearLevel;
654 using TextureLevelPyramid::isLevelEmpty;
656 Texture1D& operator= (const Texture1D& other);
658 operator Texture1DView (void) const { return m_view; }
662 Texture1DView m_view;
663 } DE_WARN_UNUSED_TYPE;
665 inline Vec4 Texture1D::sample (const Sampler& sampler, float s, float lod) const
667 return m_view.sample(sampler, s, lod);
670 inline Vec4 Texture1D::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
672 return m_view.sampleOffset(sampler, s, lod, offset);
675 /*--------------------------------------------------------------------*//*!
676 * \brief 2D Texture reference implementation
677 *//*--------------------------------------------------------------------*/
678 class Texture2D : private TextureLevelPyramid
681 Texture2D (const TextureFormat& format, int width, int height);
682 Texture2D (const Texture2D& other);
685 int getWidth (void) const { return m_width; }
686 int getHeight (void) const { return m_height; }
687 const Texture2DView& getView (void) const { return m_view; }
689 void allocLevel (int levelNdx);
692 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
693 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
694 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
695 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
697 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
698 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
700 using TextureLevelPyramid::getFormat;
701 using TextureLevelPyramid::getNumLevels;
702 using TextureLevelPyramid::getLevel;
703 using TextureLevelPyramid::clearLevel;
704 using TextureLevelPyramid::isLevelEmpty;
706 Texture2D& operator= (const Texture2D& other);
708 operator Texture2DView (void) const { return m_view; }
713 Texture2DView m_view;
714 } DE_WARN_UNUSED_TYPE;
716 inline Vec4 Texture2D::sample (const Sampler& sampler, float s, float t, float lod) const
718 return m_view.sample(sampler, s, t, lod);
721 inline Vec4 Texture2D::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
723 return m_view.sampleOffset(sampler, s, t, lod, offset);
726 inline float Texture2D::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
728 return m_view.sampleCompare(sampler, ref, s, t, lod);
731 inline float Texture2D::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
733 return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
736 inline Vec4 Texture2D::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
738 return m_view.gatherOffsets(sampler, s, t, componentNdx, offsets);
741 inline Vec4 Texture2D::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
743 return m_view.gatherOffsetsCompare(sampler, ref, s, t, offsets);
746 /*--------------------------------------------------------------------*//*!
747 * \brief Cube Map Texture View
748 *//*--------------------------------------------------------------------*/
749 class TextureCubeView
752 TextureCubeView (void);
753 TextureCubeView (int numLevels, const ConstPixelBufferAccess* const (&levels)[CUBEFACE_LAST]);
755 int getNumLevels (void) const { return m_numLevels; }
756 int getSize (void) const { return m_numLevels > 0 ? m_levels[0][0].getWidth() : 0; }
757 const ConstPixelBufferAccess& getLevelFace (int ndx, CubeFace face) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[face][ndx]; }
758 const ConstPixelBufferAccess* getFaceLevels (CubeFace face) const { return m_levels[face]; }
760 Vec4 sample (const Sampler& sampler, float s, float t, float p, float lod) const;
761 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
763 Vec4 gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const;
764 Vec4 gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const;
768 const ConstPixelBufferAccess* m_levels[CUBEFACE_LAST];
769 } DE_WARN_UNUSED_TYPE;
771 /*--------------------------------------------------------------------*//*!
772 * \brief Cube Map Texture reference implementation
773 *//*--------------------------------------------------------------------*/
777 TextureCube (const TextureFormat& format, int size);
778 TextureCube (const TextureCube& other);
781 const TextureFormat& getFormat (void) const { return m_format; }
782 int getSize (void) const { return m_size; }
784 int getNumLevels (void) const { return (int)m_access[0].size(); }
785 const ConstPixelBufferAccess& getLevelFace (int ndx, CubeFace face) const { DE_ASSERT(de::inBounds(ndx, 0, getNumLevels())); return m_access[face][(size_t)ndx]; }
786 const PixelBufferAccess& getLevelFace (int ndx, CubeFace face) { DE_ASSERT(de::inBounds(ndx, 0, getNumLevels())); return m_access[face][(size_t)ndx]; }
788 void allocLevel (CubeFace face, int levelNdx);
789 void clearLevel (CubeFace face, int levelNdx);
790 bool isLevelEmpty (CubeFace face, int levelNdx) const { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[face][(size_t)levelNdx].empty(); }
792 Vec4 sample (const Sampler& sampler, float s, float t, float p, float lod) const;
793 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
795 Vec4 gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const;
796 Vec4 gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const;
798 TextureCube& operator= (const TextureCube& other);
800 operator TextureCubeView (void) const { return m_view; }
803 typedef de::ArrayBuffer<deUint8> LevelData;
805 TextureFormat m_format;
807 std::vector<LevelData> m_data[CUBEFACE_LAST];
808 std::vector<PixelBufferAccess> m_access[CUBEFACE_LAST];
809 TextureCubeView m_view;
810 } DE_WARN_UNUSED_TYPE;
812 inline Vec4 TextureCube::sample (const Sampler& sampler, float s, float t, float p, float lod) const
814 return m_view.sample(sampler, s, t, p, lod);
817 inline float TextureCube::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
819 return m_view.sampleCompare(sampler, ref, s, t, r, lod);
822 inline Vec4 TextureCube::gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const
824 return m_view.gather(sampler, s, t, r, componentNdx);
827 inline Vec4 TextureCube::gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const
829 return m_view.gatherCompare(sampler, ref, s, t, r);
832 /*--------------------------------------------------------------------*//*!
833 * \brief 1D Array Texture View
834 *//*--------------------------------------------------------------------*/
835 class Texture1DArrayView
838 Texture1DArrayView (int numLevels, const ConstPixelBufferAccess* levels);
840 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
841 int getNumLayers (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
842 int getNumLevels (void) const { return m_numLevels; }
843 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
844 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
846 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
847 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
848 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
849 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
852 int selectLayer (float r) const;
855 const ConstPixelBufferAccess* m_levels;
856 } DE_WARN_UNUSED_TYPE;
858 /*--------------------------------------------------------------------*//*!
859 * \brief 2D Array Texture View
860 *//*--------------------------------------------------------------------*/
861 class Texture2DArrayView
864 Texture2DArrayView (int numLevels, const ConstPixelBufferAccess* levels);
866 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
867 int getHeight (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
868 int getNumLayers (void) const { return m_numLevels > 0 ? m_levels[0].getDepth() : 0; }
869 int getNumLevels (void) const { return m_numLevels; }
870 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
871 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
873 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
874 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
875 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
876 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
878 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
879 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
882 int selectLayer (float r) const;
885 const ConstPixelBufferAccess* m_levels;
886 } DE_WARN_UNUSED_TYPE;
888 /*--------------------------------------------------------------------*//*!
889 * \brief 1D Array Texture reference implementation
890 *//*--------------------------------------------------------------------*/
891 class Texture1DArray : private TextureLevelPyramid
894 Texture1DArray (const TextureFormat& format, int width, int numLayers);
895 Texture1DArray (const Texture1DArray& other);
896 ~Texture1DArray (void);
898 int getWidth (void) const { return m_width; }
899 int getNumLayers (void) const { return m_numLayers; }
901 void allocLevel (int levelNdx);
903 using TextureLevelPyramid::getFormat;
904 using TextureLevelPyramid::getNumLevels;
905 using TextureLevelPyramid::getLevel;
906 using TextureLevelPyramid::clearLevel;
907 using TextureLevelPyramid::isLevelEmpty;
909 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
910 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
911 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
912 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
914 Texture1DArray& operator= (const Texture1DArray& other);
916 operator Texture1DArrayView (void) const { return m_view; }
921 Texture1DArrayView m_view;
922 } DE_WARN_UNUSED_TYPE;
924 inline Vec4 Texture1DArray::sample (const Sampler& sampler, float s, float t, float lod) const
926 return m_view.sample(sampler, s, t, lod);
929 inline Vec4 Texture1DArray::sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const
931 return m_view.sampleOffset(sampler, s, t, lod, offset);
934 inline float Texture1DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
936 return m_view.sampleCompare(sampler, ref, s, t, lod);
939 inline float Texture1DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const
941 return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
944 /*--------------------------------------------------------------------*//*!
945 * \brief 2D Array Texture reference implementation
946 *//*--------------------------------------------------------------------*/
947 class Texture2DArray : private TextureLevelPyramid
950 Texture2DArray (const TextureFormat& format, int width, int height, int numLayers);
951 Texture2DArray (const Texture2DArray& other);
952 ~Texture2DArray (void);
954 int getWidth (void) const { return m_width; }
955 int getHeight (void) const { return m_height; }
956 int getNumLayers (void) const { return m_numLayers; }
958 void allocLevel (int levelNdx);
960 using TextureLevelPyramid::getFormat;
961 using TextureLevelPyramid::getNumLevels;
962 using TextureLevelPyramid::getLevel;
963 using TextureLevelPyramid::clearLevel;
964 using TextureLevelPyramid::isLevelEmpty;
966 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
967 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
968 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
969 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
971 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
972 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
974 Texture2DArray& operator= (const Texture2DArray& other);
976 operator Texture2DArrayView (void) const { return m_view; }
982 Texture2DArrayView m_view;
983 } DE_WARN_UNUSED_TYPE;
985 inline Vec4 Texture2DArray::sample (const Sampler& sampler, float s, float t, float r, float lod) const
987 return m_view.sample(sampler, s, t, r, lod);
990 inline Vec4 Texture2DArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const
992 return m_view.sampleOffset(sampler, s, t, r, lod, offset);
995 inline float Texture2DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
997 return m_view.sampleCompare(sampler, ref, s, t, r, lod);
1000 inline float Texture2DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const
1002 return m_view.sampleCompareOffset(sampler, ref, s, t, r, lod, offset);
1005 inline Vec4 Texture2DArray::gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const
1007 return m_view.gatherOffsets(sampler, s, t, r, componentNdx, offsets);
1010 inline Vec4 Texture2DArray::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const
1012 return m_view.gatherOffsetsCompare(sampler, ref, s, t, r, offsets);
1015 /*--------------------------------------------------------------------*//*!
1016 * \brief 3D Texture View
1017 *//*--------------------------------------------------------------------*/
1021 Texture3DView (int numLevels, const ConstPixelBufferAccess* levels);
1023 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
1024 int getHeight (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
1025 int getDepth (void) const { return m_numLevels > 0 ? m_levels[0].getDepth() : 0; }
1026 int getNumLevels (void) const { return m_numLevels; }
1027 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
1028 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
1030 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
1031 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
1035 const ConstPixelBufferAccess* m_levels;
1036 } DE_WARN_UNUSED_TYPE;
1038 inline Vec4 Texture3DView::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1040 return sampleLevelArray3D(m_levels, m_numLevels, sampler, s, t, r, lod);
1043 inline Vec4 Texture3DView::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
1045 return sampleLevelArray3DOffset(m_levels, m_numLevels, sampler, s, t, r, lod, offset);
1048 /*--------------------------------------------------------------------*//*!
1049 * \brief 3D Texture reference implementation
1050 *//*--------------------------------------------------------------------*/
1051 class Texture3D : private TextureLevelPyramid
1054 Texture3D (const TextureFormat& format, int width, int height, int depth);
1055 Texture3D (const Texture3D& other);
1058 int getWidth (void) const { return m_width; }
1059 int getHeight (void) const { return m_height; }
1060 int getDepth (void) const { return m_depth; }
1062 void allocLevel (int levelNdx);
1064 using TextureLevelPyramid::getFormat;
1065 using TextureLevelPyramid::getNumLevels;
1066 using TextureLevelPyramid::getLevel;
1067 using TextureLevelPyramid::clearLevel;
1068 using TextureLevelPyramid::isLevelEmpty;
1070 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
1071 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
1073 Texture3D& operator= (const Texture3D& other);
1075 operator Texture3DView (void) const { return m_view; }
1081 Texture3DView m_view;
1082 } DE_WARN_UNUSED_TYPE;
1084 inline Vec4 Texture3D::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1086 return m_view.sample(sampler, s, t, r, lod);
1089 inline Vec4 Texture3D::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
1091 return m_view.sampleOffset(sampler, s, t, r, lod, offset);
1094 /*--------------------------------------------------------------------*//*!
1095 * \brief Cube Map Array Texture View
1096 *//*--------------------------------------------------------------------*/
1097 class TextureCubeArrayView
1100 TextureCubeArrayView (int numLevels, const ConstPixelBufferAccess* levels);
1102 int getSize (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
1103 int getDepth (void) const { return m_numLevels > 0 ? m_levels[0].getDepth() : 0; }
1104 int getNumLayers (void) const { return getDepth() / 6; }
1105 int getNumLevels (void) const { return m_numLevels; }
1106 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
1107 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
1109 Vec4 sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const;
1110 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1111 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
1112 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1115 int selectLayer (float q) const;
1118 const ConstPixelBufferAccess* m_levels;
1119 } DE_WARN_UNUSED_TYPE;
1121 /*--------------------------------------------------------------------*//*!
1122 * \brief Cube Map Array Texture reference implementation
1123 *//*--------------------------------------------------------------------*/
1124 class TextureCubeArray : private TextureLevelPyramid
1127 TextureCubeArray (const TextureFormat& format, int size, int depth);
1128 TextureCubeArray (const TextureCubeArray& other);
1129 ~TextureCubeArray (void);
1131 int getSize (void) const { return m_size; }
1132 int getDepth (void) const { return m_depth; }
1134 void allocLevel (int levelNdx);
1136 using TextureLevelPyramid::getFormat;
1137 using TextureLevelPyramid::getNumLevels;
1138 using TextureLevelPyramid::getLevel;
1139 using TextureLevelPyramid::clearLevel;
1140 using TextureLevelPyramid::isLevelEmpty;
1142 Vec4 sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const;
1143 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1144 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
1145 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1147 TextureCubeArray& operator= (const TextureCubeArray& other);
1149 operator TextureCubeArrayView (void) const { return m_view; }
1154 TextureCubeArrayView m_view;
1155 } DE_WARN_UNUSED_TYPE;
1157 inline Vec4 TextureCubeArray::sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const
1159 return m_view.sample(sampler, s, t, r, q, lod);
1162 inline Vec4 TextureCubeArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const
1164 return m_view.sampleOffset(sampler, s, t, r, q, lod, offset);
1167 inline float TextureCubeArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const
1169 return m_view.sampleCompare(sampler, ref, s, t, r, q, lod);
1172 inline float TextureCubeArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const
1174 return m_view.sampleCompareOffset(sampler, ref, s, t, r, q, lod, offset);
1177 // Stream operators.
1178 std::ostream& operator<< (std::ostream& str, TextureFormat::ChannelOrder order);
1179 std::ostream& operator<< (std::ostream& str, TextureFormat::ChannelType type);
1180 std::ostream& operator<< (std::ostream& str, TextureFormat format);
1181 std::ostream& operator<< (std::ostream& str, CubeFace face);
1182 std::ostream& operator<< (std::ostream& str, const ConstPixelBufferAccess& access);
1186 #endif // _TCUTEXTURE_HPP