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;
651 using TextureLevelPyramid::getFormat;
652 using TextureLevelPyramid::getNumLevels;
653 using TextureLevelPyramid::getLevel;
654 using TextureLevelPyramid::clearLevel;
655 using TextureLevelPyramid::isLevelEmpty;
657 Texture1D& operator= (const Texture1D& other);
659 operator Texture1DView (void) const { return m_view; }
663 Texture1DView m_view;
664 } DE_WARN_UNUSED_TYPE;
666 inline Vec4 Texture1D::sample (const Sampler& sampler, float s, float lod) const
668 return m_view.sample(sampler, s, lod);
671 inline Vec4 Texture1D::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
673 return m_view.sampleOffset(sampler, s, lod, offset);
676 /*--------------------------------------------------------------------*//*!
677 * \brief 2D Texture reference implementation
678 *//*--------------------------------------------------------------------*/
679 class Texture2D : private TextureLevelPyramid
682 Texture2D (const TextureFormat& format, int width, int height);
683 Texture2D (const Texture2D& other);
686 int getWidth (void) const { return m_width; }
687 int getHeight (void) const { return m_height; }
688 const Texture2DView& getView (void) const { return m_view; }
690 void allocLevel (int levelNdx);
693 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
694 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
695 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
696 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
698 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
699 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
701 using TextureLevelPyramid::getFormat;
702 using TextureLevelPyramid::getNumLevels;
703 using TextureLevelPyramid::getLevel;
704 using TextureLevelPyramid::clearLevel;
705 using TextureLevelPyramid::isLevelEmpty;
707 Texture2D& operator= (const Texture2D& other);
709 operator Texture2DView (void) const { return m_view; }
714 Texture2DView m_view;
715 } DE_WARN_UNUSED_TYPE;
717 inline Vec4 Texture2D::sample (const Sampler& sampler, float s, float t, float lod) const
719 return m_view.sample(sampler, s, t, lod);
722 inline Vec4 Texture2D::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
724 return m_view.sampleOffset(sampler, s, t, lod, offset);
727 inline float Texture2D::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
729 return m_view.sampleCompare(sampler, ref, s, t, lod);
732 inline float Texture2D::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
734 return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
737 inline Vec4 Texture2D::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
739 return m_view.gatherOffsets(sampler, s, t, componentNdx, offsets);
742 inline Vec4 Texture2D::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
744 return m_view.gatherOffsetsCompare(sampler, ref, s, t, offsets);
747 /*--------------------------------------------------------------------*//*!
748 * \brief Cube Map Texture View
749 *//*--------------------------------------------------------------------*/
750 class TextureCubeView
753 TextureCubeView (void);
754 TextureCubeView (int numLevels, const ConstPixelBufferAccess* const (&levels)[CUBEFACE_LAST]);
756 int getNumLevels (void) const { return m_numLevels; }
757 int getSize (void) const { return m_numLevels > 0 ? m_levels[0][0].getWidth() : 0; }
758 const ConstPixelBufferAccess& getLevelFace (int ndx, CubeFace face) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[face][ndx]; }
759 const ConstPixelBufferAccess* getFaceLevels (CubeFace face) const { return m_levels[face]; }
761 Vec4 sample (const Sampler& sampler, float s, float t, float p, float lod) const;
762 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
764 Vec4 gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const;
765 Vec4 gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const;
769 const ConstPixelBufferAccess* m_levels[CUBEFACE_LAST];
770 } DE_WARN_UNUSED_TYPE;
772 /*--------------------------------------------------------------------*//*!
773 * \brief Cube Map Texture reference implementation
774 *//*--------------------------------------------------------------------*/
778 TextureCube (const TextureFormat& format, int size);
779 TextureCube (const TextureCube& other);
782 const TextureFormat& getFormat (void) const { return m_format; }
783 int getSize (void) const { return m_size; }
785 int getNumLevels (void) const { return (int)m_access[0].size(); }
786 const ConstPixelBufferAccess& getLevelFace (int ndx, CubeFace face) const { DE_ASSERT(de::inBounds(ndx, 0, getNumLevels())); return m_access[face][(size_t)ndx]; }
787 const PixelBufferAccess& getLevelFace (int ndx, CubeFace face) { DE_ASSERT(de::inBounds(ndx, 0, getNumLevels())); return m_access[face][(size_t)ndx]; }
789 void allocLevel (CubeFace face, int levelNdx);
790 void clearLevel (CubeFace face, int levelNdx);
791 bool isLevelEmpty (CubeFace face, int levelNdx) const { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[face][(size_t)levelNdx].empty(); }
793 Vec4 sample (const Sampler& sampler, float s, float t, float p, float lod) const;
794 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
796 Vec4 gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const;
797 Vec4 gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const;
799 TextureCube& operator= (const TextureCube& other);
801 operator TextureCubeView (void) const { return m_view; }
804 typedef de::ArrayBuffer<deUint8> LevelData;
806 TextureFormat m_format;
808 std::vector<LevelData> m_data[CUBEFACE_LAST];
809 std::vector<PixelBufferAccess> m_access[CUBEFACE_LAST];
810 TextureCubeView m_view;
811 } DE_WARN_UNUSED_TYPE;
813 inline Vec4 TextureCube::sample (const Sampler& sampler, float s, float t, float p, float lod) const
815 return m_view.sample(sampler, s, t, p, lod);
818 inline float TextureCube::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
820 return m_view.sampleCompare(sampler, ref, s, t, r, lod);
823 inline Vec4 TextureCube::gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const
825 return m_view.gather(sampler, s, t, r, componentNdx);
828 inline Vec4 TextureCube::gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const
830 return m_view.gatherCompare(sampler, ref, s, t, r);
833 /*--------------------------------------------------------------------*//*!
834 * \brief 1D Array Texture View
835 *//*--------------------------------------------------------------------*/
836 class Texture1DArrayView
839 Texture1DArrayView (int numLevels, const ConstPixelBufferAccess* levels);
841 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
842 int getNumLayers (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
843 int getNumLevels (void) const { return m_numLevels; }
844 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
845 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
847 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
848 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
849 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
850 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
853 int selectLayer (float r) const;
856 const ConstPixelBufferAccess* m_levels;
857 } DE_WARN_UNUSED_TYPE;
859 /*--------------------------------------------------------------------*//*!
860 * \brief 2D Array Texture View
861 *//*--------------------------------------------------------------------*/
862 class Texture2DArrayView
865 Texture2DArrayView (int numLevels, const ConstPixelBufferAccess* levels);
867 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
868 int getHeight (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
869 int getNumLayers (void) const { return m_numLevels > 0 ? m_levels[0].getDepth() : 0; }
870 int getNumLevels (void) const { return m_numLevels; }
871 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
872 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
874 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
875 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
876 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
877 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
879 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
880 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
883 int selectLayer (float r) const;
886 const ConstPixelBufferAccess* m_levels;
887 } DE_WARN_UNUSED_TYPE;
889 /*--------------------------------------------------------------------*//*!
890 * \brief 1D Array Texture reference implementation
891 *//*--------------------------------------------------------------------*/
892 class Texture1DArray : private TextureLevelPyramid
895 Texture1DArray (const TextureFormat& format, int width, int numLayers);
896 Texture1DArray (const Texture1DArray& other);
897 ~Texture1DArray (void);
899 int getWidth (void) const { return m_width; }
900 int getNumLayers (void) const { return m_numLayers; }
902 void allocLevel (int levelNdx);
904 using TextureLevelPyramid::getFormat;
905 using TextureLevelPyramid::getNumLevels;
906 using TextureLevelPyramid::getLevel;
907 using TextureLevelPyramid::clearLevel;
908 using TextureLevelPyramid::isLevelEmpty;
910 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
911 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
912 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
913 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
915 Texture1DArray& operator= (const Texture1DArray& other);
917 operator Texture1DArrayView (void) const { return m_view; }
922 Texture1DArrayView m_view;
923 } DE_WARN_UNUSED_TYPE;
925 inline Vec4 Texture1DArray::sample (const Sampler& sampler, float s, float t, float lod) const
927 return m_view.sample(sampler, s, t, lod);
930 inline Vec4 Texture1DArray::sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const
932 return m_view.sampleOffset(sampler, s, t, lod, offset);
935 inline float Texture1DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
937 return m_view.sampleCompare(sampler, ref, s, t, lod);
940 inline float Texture1DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const
942 return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
945 /*--------------------------------------------------------------------*//*!
946 * \brief 2D Array Texture reference implementation
947 *//*--------------------------------------------------------------------*/
948 class Texture2DArray : private TextureLevelPyramid
951 Texture2DArray (const TextureFormat& format, int width, int height, int numLayers);
952 Texture2DArray (const Texture2DArray& other);
953 ~Texture2DArray (void);
955 int getWidth (void) const { return m_width; }
956 int getHeight (void) const { return m_height; }
957 int getNumLayers (void) const { return m_numLayers; }
959 void allocLevel (int levelNdx);
961 using TextureLevelPyramid::getFormat;
962 using TextureLevelPyramid::getNumLevels;
963 using TextureLevelPyramid::getLevel;
964 using TextureLevelPyramid::clearLevel;
965 using TextureLevelPyramid::isLevelEmpty;
967 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
968 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
969 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
970 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
972 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
973 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
975 Texture2DArray& operator= (const Texture2DArray& other);
977 operator Texture2DArrayView (void) const { return m_view; }
983 Texture2DArrayView m_view;
984 } DE_WARN_UNUSED_TYPE;
986 inline Vec4 Texture2DArray::sample (const Sampler& sampler, float s, float t, float r, float lod) const
988 return m_view.sample(sampler, s, t, r, lod);
991 inline Vec4 Texture2DArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const
993 return m_view.sampleOffset(sampler, s, t, r, lod, offset);
996 inline float Texture2DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
998 return m_view.sampleCompare(sampler, ref, s, t, r, lod);
1001 inline float Texture2DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const
1003 return m_view.sampleCompareOffset(sampler, ref, s, t, r, lod, offset);
1006 inline Vec4 Texture2DArray::gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const
1008 return m_view.gatherOffsets(sampler, s, t, r, componentNdx, offsets);
1011 inline Vec4 Texture2DArray::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const
1013 return m_view.gatherOffsetsCompare(sampler, ref, s, t, r, offsets);
1016 /*--------------------------------------------------------------------*//*!
1017 * \brief 3D Texture View
1018 *//*--------------------------------------------------------------------*/
1022 Texture3DView (int numLevels, const ConstPixelBufferAccess* levels);
1024 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
1025 int getHeight (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
1026 int getDepth (void) const { return m_numLevels > 0 ? m_levels[0].getDepth() : 0; }
1027 int getNumLevels (void) const { return m_numLevels; }
1028 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
1029 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
1031 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
1032 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
1036 const ConstPixelBufferAccess* m_levels;
1037 } DE_WARN_UNUSED_TYPE;
1039 inline Vec4 Texture3DView::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1041 return sampleLevelArray3D(m_levels, m_numLevels, sampler, s, t, r, lod);
1044 inline Vec4 Texture3DView::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
1046 return sampleLevelArray3DOffset(m_levels, m_numLevels, sampler, s, t, r, lod, offset);
1049 /*--------------------------------------------------------------------*//*!
1050 * \brief 3D Texture reference implementation
1051 *//*--------------------------------------------------------------------*/
1052 class Texture3D : private TextureLevelPyramid
1055 Texture3D (const TextureFormat& format, int width, int height, int depth);
1056 Texture3D (const Texture3D& other);
1059 int getWidth (void) const { return m_width; }
1060 int getHeight (void) const { return m_height; }
1061 int getDepth (void) const { return m_depth; }
1063 void allocLevel (int levelNdx);
1065 using TextureLevelPyramid::getFormat;
1066 using TextureLevelPyramid::getNumLevels;
1067 using TextureLevelPyramid::getLevel;
1068 using TextureLevelPyramid::clearLevel;
1069 using TextureLevelPyramid::isLevelEmpty;
1071 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
1072 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
1074 Texture3D& operator= (const Texture3D& other);
1076 operator Texture3DView (void) const { return m_view; }
1082 Texture3DView m_view;
1083 } DE_WARN_UNUSED_TYPE;
1085 inline Vec4 Texture3D::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1087 return m_view.sample(sampler, s, t, r, lod);
1090 inline Vec4 Texture3D::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
1092 return m_view.sampleOffset(sampler, s, t, r, lod, offset);
1095 /*--------------------------------------------------------------------*//*!
1096 * \brief Cube Map Array Texture View
1097 *//*--------------------------------------------------------------------*/
1098 class TextureCubeArrayView
1101 TextureCubeArrayView (int numLevels, const ConstPixelBufferAccess* levels);
1103 int getSize (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
1104 int getDepth (void) const { return m_numLevels > 0 ? m_levels[0].getDepth() : 0; }
1105 int getNumLayers (void) const { return getDepth() / 6; }
1106 int getNumLevels (void) const { return m_numLevels; }
1107 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
1108 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
1110 Vec4 sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const;
1111 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1112 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
1113 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1116 int selectLayer (float q) const;
1119 const ConstPixelBufferAccess* m_levels;
1120 } DE_WARN_UNUSED_TYPE;
1122 /*--------------------------------------------------------------------*//*!
1123 * \brief Cube Map Array Texture reference implementation
1124 *//*--------------------------------------------------------------------*/
1125 class TextureCubeArray : private TextureLevelPyramid
1128 TextureCubeArray (const TextureFormat& format, int size, int depth);
1129 TextureCubeArray (const TextureCubeArray& other);
1130 ~TextureCubeArray (void);
1132 int getSize (void) const { return m_size; }
1133 int getDepth (void) const { return m_depth; }
1135 void allocLevel (int levelNdx);
1137 using TextureLevelPyramid::getFormat;
1138 using TextureLevelPyramid::getNumLevels;
1139 using TextureLevelPyramid::getLevel;
1140 using TextureLevelPyramid::clearLevel;
1141 using TextureLevelPyramid::isLevelEmpty;
1143 Vec4 sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const;
1144 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1145 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
1146 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1148 TextureCubeArray& operator= (const TextureCubeArray& other);
1150 operator TextureCubeArrayView (void) const { return m_view; }
1155 TextureCubeArrayView m_view;
1156 } DE_WARN_UNUSED_TYPE;
1158 inline Vec4 TextureCubeArray::sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const
1160 return m_view.sample(sampler, s, t, r, q, lod);
1163 inline Vec4 TextureCubeArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const
1165 return m_view.sampleOffset(sampler, s, t, r, q, lod, offset);
1168 inline float TextureCubeArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const
1170 return m_view.sampleCompare(sampler, ref, s, t, r, q, lod);
1173 inline float TextureCubeArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const
1175 return m_view.sampleCompareOffset(sampler, ref, s, t, r, q, lod, offset);
1178 // Stream operators.
1179 std::ostream& operator<< (std::ostream& str, TextureFormat::ChannelOrder order);
1180 std::ostream& operator<< (std::ostream& str, TextureFormat::ChannelType type);
1181 std::ostream& operator<< (std::ostream& str, TextureFormat format);
1182 std::ostream& operator<< (std::ostream& str, CubeFace face);
1183 std::ostream& operator<< (std::ostream& str, const ConstPixelBufferAccess& access);
1187 #endif // _TCUTEXTURE_HPP