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);
143 /*--------------------------------------------------------------------*//*!
144 * \brief Texture swizzle
145 *//*--------------------------------------------------------------------*/
146 struct TextureSwizzle
150 // \note CHANNEL_N must equal int N
162 Channel components[4];
165 //! get the swizzle used to expand texture data with a given channel order to RGBA form
166 const TextureSwizzle& getChannelReadSwizzle (TextureFormat::ChannelOrder order);
168 //! get the swizzle used to narrow RGBA form data to native texture data with a given channel order
169 const TextureSwizzle& getChannelWriteSwizzle (TextureFormat::ChannelOrder order);
171 /*--------------------------------------------------------------------*//*!
172 * \brief Sampling parameters
173 *//*--------------------------------------------------------------------*/
179 CLAMP_TO_EDGE = 0, //! Clamp to edge
180 CLAMP_TO_BORDER, //! Use border color at edge
181 REPEAT_GL, //! Repeat with OpenGL semantics
182 REPEAT_CL, //! Repeat with OpenCL semantics
183 MIRRORED_REPEAT_GL, //! Mirrored repeat with OpenGL semantics
184 MIRRORED_REPEAT_CL, //! Mirrored repeat with OpenCL semantics
185 MIRRORED_ONCE, //! Mirrored once in negative directions
195 NEAREST_MIPMAP_NEAREST,
196 NEAREST_MIPMAP_LINEAR,
197 LINEAR_MIPMAP_NEAREST,
198 LINEAR_MIPMAP_LINEAR,
205 COMPAREMODE_NONE = 0,
207 COMPAREMODE_LESS_OR_EQUAL,
209 COMPAREMODE_GREATER_OR_EQUAL,
211 COMPAREMODE_NOT_EQUAL,
218 enum DepthStencilMode
231 // Minifcation & magnification
232 FilterMode minFilter;
233 FilterMode magFilter;
234 float lodThreshold; // lod <= lodThreshold ? magnified : minified
236 // Coordinate normalization
237 bool normalizedCoords;
244 // \note It is setter's responsibility to guarantee that the values are representable
245 // in sampled texture's internal format.
246 // \note It is setter's responsibility to guarantee that the format is compatible with the
247 // sampled texture's internal format. Otherwise results are undefined.
248 rr::GenericVec4 borderColor;
250 // Seamless cube map filtering
251 bool seamlessCubeMap;
253 // Depth stencil mode
254 DepthStencilMode depthStencilMode;
256 Sampler (WrapMode wrapS_,
259 FilterMode minFilter_,
260 FilterMode magFilter_,
261 float lodThreshold_ = 0.0f,
262 bool normalizedCoords_ = true,
263 CompareMode compare_ = COMPAREMODE_NONE,
264 int compareChannel_ = 0,
265 const Vec4& borderColor_ = Vec4(0.0f, 0.0f, 0.0f, 0.0f),
266 bool seamlessCubeMap_ = false,
267 DepthStencilMode depthStencilMode_ = MODE_DEPTH)
271 , minFilter (minFilter_)
272 , magFilter (magFilter_)
273 , lodThreshold (lodThreshold_)
274 , normalizedCoords (normalizedCoords_)
276 , compareChannel (compareChannel_)
277 , borderColor (borderColor_)
278 , seamlessCubeMap (seamlessCubeMap_)
279 , depthStencilMode (depthStencilMode_)
284 : wrapS (WRAPMODE_LAST)
285 , wrapT (WRAPMODE_LAST)
286 , wrapR (WRAPMODE_LAST)
287 , minFilter (FILTERMODE_LAST)
288 , magFilter (FILTERMODE_LAST)
289 , lodThreshold (0.0f)
290 , normalizedCoords (true)
291 , compare (COMPAREMODE_NONE)
293 , borderColor (Vec4(0.0f, 0.0f, 0.0f, 0.0f))
294 , seamlessCubeMap (false)
295 , depthStencilMode (MODE_DEPTH)
298 } DE_WARN_UNUSED_TYPE;
300 // Calculate pitches for pixel data with no padding.
301 IVec3 calculatePackedPitch (const TextureFormat& format, const IVec3& size);
305 /*--------------------------------------------------------------------*//*!
306 * \brief Read-only pixel data access
308 * ConstPixelBufferAccess encapsulates pixel data pointer along with
309 * format and layout information. It can be used for read-only access
310 * to arbitrary pixel buffers.
312 * Access objects are like iterators or pointers. They can be passed around
313 * as values and are valid as long as the storage doesn't change.
314 *//*--------------------------------------------------------------------*/
315 class ConstPixelBufferAccess
318 ConstPixelBufferAccess (void);
319 ConstPixelBufferAccess (const TextureLevel& level);
320 ConstPixelBufferAccess (const TextureFormat& format, int width, int height, int depth, const void* data);
321 ConstPixelBufferAccess (const TextureFormat& format, const IVec3& size, const void* data);
322 ConstPixelBufferAccess (const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, const void* data);
323 ConstPixelBufferAccess (const TextureFormat& format, const IVec3& size, const IVec3& pitch, const void* data);
325 const TextureFormat& getFormat (void) const { return m_format; }
326 const IVec3& getSize (void) const { return m_size; }
327 int getWidth (void) const { return m_size.x(); }
328 int getHeight (void) const { return m_size.y(); }
329 int getDepth (void) const { return m_size.z(); }
330 int getPixelPitch (void) const { return m_pitch.x(); }
331 int getRowPitch (void) const { return m_pitch.y(); }
332 int getSlicePitch (void) const { return m_pitch.z(); }
333 const IVec3& getPitch (void) const { return m_pitch; }
335 const void* getDataPtr (void) const { return m_data; }
336 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(); }
338 Vec4 getPixel (int x, int y, int z = 0) const;
339 IVec4 getPixelInt (int x, int y, int z = 0) const;
340 UVec4 getPixelUint (int x, int y, int z = 0) const { return getPixelInt(x, y, z).cast<deUint32>(); }
343 Vector<T, 4> getPixelT (int x, int y, int z = 0) const;
345 float getPixDepth (int x, int y, int z = 0) const;
346 int getPixStencil (int x, int y, int z = 0) const;
348 Vec4 sample1D (const Sampler& sampler, Sampler::FilterMode filter, float s, int level) const;
349 Vec4 sample2D (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, int depth) const;
350 Vec4 sample3D (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, float r) const;
352 Vec4 sample1DOffset (const Sampler& sampler, Sampler::FilterMode filter, float s, const IVec2& offset) const;
353 Vec4 sample2DOffset (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, const IVec3& offset) const;
354 Vec4 sample3DOffset (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, float r, const IVec3& offset) const;
356 float sample1DCompare (const Sampler& sampler, Sampler::FilterMode filter, float ref, float s, const IVec2& offset) const;
357 float sample2DCompare (const Sampler& sampler, Sampler::FilterMode filter, float ref, float s, float t, const IVec3& offset) const;
360 TextureFormat m_format;
362 IVec3 m_pitch; //!< (pixelPitch, rowPitch, slicePitch)
363 mutable void* m_data;
364 } DE_WARN_UNUSED_TYPE;
366 /*--------------------------------------------------------------------*//*!
367 * \brief Read-write pixel data access
369 * This class extends read-only access object by providing write functionality.
371 * \note PixelBufferAccess may not have any data members nor add any
372 * virtual functions. It must be possible to reinterpret_cast<>
373 * PixelBufferAccess to ConstPixelBufferAccess.
374 *//*--------------------------------------------------------------------*/
375 class PixelBufferAccess : public ConstPixelBufferAccess
378 PixelBufferAccess (void) {}
379 PixelBufferAccess (TextureLevel& level);
380 PixelBufferAccess (const TextureFormat& format, int width, int height, int depth, void* data);
381 PixelBufferAccess (const TextureFormat& format, const IVec3& size, void* data);
382 PixelBufferAccess (const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, void* data);
383 PixelBufferAccess (const TextureFormat& format, const IVec3& size, const IVec3& pitch, void* data);
385 void* getDataPtr (void) const { return m_data; }
386 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(); }
388 void setPixel (const tcu::Vec4& color, int x, int y, int z = 0) const;
389 void setPixel (const tcu::IVec4& color, int x, int y, int z = 0) const;
390 void setPixel (const tcu::UVec4& color, int x, int y, int z = 0) const { setPixel(color.cast<int>(), x, y, z); }
392 void setPixDepth (float depth, int x, int y, int z = 0) const;
393 void setPixStencil (int stencil, int x, int y, int z = 0) const;
394 } DE_WARN_UNUSED_TYPE;
396 /*--------------------------------------------------------------------*//*!
397 * \brief Generic pixel data container
399 * This container supports all valid TextureFormat combinations and
400 * both 2D and 3D textures. To read or manipulate data access object must
401 * be queried using getAccess().
402 *//*--------------------------------------------------------------------*/
407 TextureLevel (const TextureFormat& format);
408 TextureLevel (const TextureFormat& format, int width, int height, int depth = 1);
409 ~TextureLevel (void);
411 const IVec3& getSize (void) const { return m_size; }
412 int getWidth (void) const { return m_size.x(); }
413 int getHeight (void) const { return m_size.y(); }
414 int getDepth (void) const { return m_size.z(); }
415 bool isEmpty (void) const { return m_size.x() * m_size.y() * m_size.z() == 0; }
416 const TextureFormat getFormat (void) const { return m_format; }
418 void setStorage (const TextureFormat& format, int width, int heigth, int depth = 1);
419 void setSize (int width, int height, int depth = 1);
421 PixelBufferAccess getAccess (void) { return isEmpty() ? PixelBufferAccess() : PixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr()); }
422 ConstPixelBufferAccess getAccess (void) const { return isEmpty() ? ConstPixelBufferAccess() : ConstPixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr()); }
425 void* getPtr (void) { return m_data.getPtr(); }
426 const void* getPtr (void) const { return m_data.getPtr(); }
428 TextureFormat m_format;
430 de::ArrayBuffer<deUint8> m_data;
432 friend class ConstPixelBufferAccess;
433 } DE_WARN_UNUSED_TYPE;
435 Vec4 sampleLevelArray1D (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, int level, float lod);
436 Vec4 sampleLevelArray2D (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, int depth, float lod);
437 Vec4 sampleLevelArray3D (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float r, float lod);
439 Vec4 sampleLevelArray1DOffset (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float lod, const IVec2& offset);
440 Vec4 sampleLevelArray2DOffset (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float lod, const IVec3& offset);
441 Vec4 sampleLevelArray3DOffset (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset);
443 float sampleLevelArray1DCompare (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float ref, float s, float lod, const IVec2& offset);
444 float sampleLevelArray2DCompare (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float ref, float s, float t, float lod, const IVec3& offset);
446 Vec4 gatherArray2DOffsets (const ConstPixelBufferAccess& src, const Sampler& sampler, float s, float t, int depth, int componentNdx, const IVec2 (&offsets)[4]);
447 Vec4 gatherArray2DOffsetsCompare (const ConstPixelBufferAccess& src, const Sampler& sampler, float ref, float s, float t, int depth, const IVec2 (&offsets)[4]);
451 CUBEFACE_NEGATIVE_X = 0,
461 /*--------------------------------------------------------------------*//*!
462 * \brief Coordinates projected onto cube face.
463 *//*--------------------------------------------------------------------*/
465 struct CubeFaceCoords
471 CubeFaceCoords (CubeFace face_, T s_, T t_) : face(face_), s(s_), t(t_) {}
472 CubeFaceCoords (CubeFace face_, const Vector<T, 2>& c) : face(face_), s(c.x()), t(c.y()) {}
473 } DE_WARN_UNUSED_TYPE;
475 typedef CubeFaceCoords<float> CubeFaceFloatCoords;
476 typedef CubeFaceCoords<int> CubeFaceIntCoords;
478 CubeFace selectCubeFace (const Vec3& coords);
479 Vec2 projectToFace (CubeFace face, const Vec3& coords);
480 CubeFaceFloatCoords getCubeFaceCoords (const Vec3& coords);
481 CubeFaceIntCoords remapCubeEdgeCoords (const CubeFaceIntCoords& coords, int size);
483 /*--------------------------------------------------------------------*//*!
484 * \brief 1D Texture View
485 *//*--------------------------------------------------------------------*/
489 Texture1DView (int numLevels, const ConstPixelBufferAccess* levels);
491 int getNumLevels (void) const { return m_numLevels; }
492 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
493 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
494 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
496 Vec4 sample (const Sampler& sampler, float s, float lod) const;
497 Vec4 sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const;
498 float sampleCompare (const Sampler& sampler, float ref, float s, float lod) const;
499 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const;
503 const ConstPixelBufferAccess* m_levels;
504 } DE_WARN_UNUSED_TYPE;
506 inline Texture1DView::Texture1DView (int numLevels, const ConstPixelBufferAccess* levels)
507 : m_numLevels (numLevels)
510 DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
513 inline Vec4 Texture1DView::sample (const Sampler& sampler, float s, float lod) const
515 return sampleLevelArray1D(m_levels, m_numLevels, sampler, s, 0 /* depth */, lod);
518 inline Vec4 Texture1DView::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
520 return sampleLevelArray1DOffset(m_levels, m_numLevels, sampler, s, lod, IVec2(offset, 0));
523 inline float Texture1DView::sampleCompare (const Sampler& sampler, float ref, float s, float lod) const
525 return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(0, 0));
528 inline float Texture1DView::sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const
530 return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(offset, 0));
533 /*--------------------------------------------------------------------*//*!
534 * \brief 2D Texture View
535 *//*--------------------------------------------------------------------*/
539 Texture2DView (int numLevels, const ConstPixelBufferAccess* levels);
541 int getNumLevels (void) const { return m_numLevels; }
542 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
543 int getHeight (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
544 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
545 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
547 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
548 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
549 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
550 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
552 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
553 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
557 const ConstPixelBufferAccess* m_levels;
558 } DE_WARN_UNUSED_TYPE;
560 inline Texture2DView::Texture2DView (int numLevels, const ConstPixelBufferAccess* levels)
561 : m_numLevels (numLevels)
564 DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
567 inline Vec4 Texture2DView::sample (const Sampler& sampler, float s, float t, float lod) const
569 return sampleLevelArray2D(m_levels, m_numLevels, sampler, s, t, 0 /* depth */, lod);
572 inline Vec4 Texture2DView::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
574 return sampleLevelArray2DOffset(m_levels, m_numLevels, sampler, s, t, lod, IVec3(offset.x(), offset.y(), 0));
577 inline float Texture2DView::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
579 return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(0, 0, 0));
582 inline float Texture2DView::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
584 return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(offset.x(), offset.y(), 0));
587 inline Vec4 Texture2DView::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
589 return gatherArray2DOffsets(m_levels[0], sampler, s, t, 0, componentNdx, offsets);
592 inline Vec4 Texture2DView::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
594 return gatherArray2DOffsetsCompare(m_levels[0], sampler, ref, s, t, 0, offsets);
597 /*--------------------------------------------------------------------*//*!
598 * \brief Base class for textures that have single mip-map pyramid
599 *//*--------------------------------------------------------------------*/
600 class TextureLevelPyramid
603 TextureLevelPyramid (const TextureFormat& format, int numLevels);
604 TextureLevelPyramid (const TextureLevelPyramid& other);
605 ~TextureLevelPyramid(void);
607 const TextureFormat& getFormat (void) const { return m_format; }
608 int getNumLevels (void) const { return (int)m_access.size(); }
610 bool isLevelEmpty (int levelNdx) const { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[(size_t)levelNdx].empty(); }
611 const ConstPixelBufferAccess& getLevel (int levelNdx) const { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_access[(size_t)levelNdx]; }
612 const PixelBufferAccess& getLevel (int levelNdx) { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_access[(size_t)levelNdx]; }
614 const ConstPixelBufferAccess* getLevels (void) const { return &m_access[0]; }
615 const PixelBufferAccess* getLevels (void) { return &m_access[0]; }
617 void allocLevel (int levelNdx, int width, int height, int depth);
618 void clearLevel (int levelNdx);
620 TextureLevelPyramid& operator= (const TextureLevelPyramid& other);
623 typedef de::ArrayBuffer<deUint8> LevelData;
625 TextureFormat m_format;
626 std::vector<LevelData> m_data;
627 std::vector<PixelBufferAccess> m_access;
628 } DE_WARN_UNUSED_TYPE;
630 /*--------------------------------------------------------------------*//*!
631 * \brief 1D Texture reference implementation
632 *//*--------------------------------------------------------------------*/
633 class Texture1D : private TextureLevelPyramid
636 Texture1D (const TextureFormat& format, int width);
637 Texture1D (const Texture1D& other);
640 int getWidth (void) const { return m_width; }
641 const Texture1DView& getView (void) const { return m_view; }
643 void allocLevel (int levelNdx);
646 Vec4 sample (const Sampler& sampler, float s, float lod) const;
647 Vec4 sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const;
649 using TextureLevelPyramid::getFormat;
650 using TextureLevelPyramid::getNumLevels;
651 using TextureLevelPyramid::getLevel;
652 using TextureLevelPyramid::clearLevel;
653 using TextureLevelPyramid::isLevelEmpty;
655 Texture1D& operator= (const Texture1D& other);
657 operator Texture1DView (void) const { return m_view; }
661 Texture1DView m_view;
662 } DE_WARN_UNUSED_TYPE;
664 inline Vec4 Texture1D::sample (const Sampler& sampler, float s, float lod) const
666 return m_view.sample(sampler, s, lod);
669 inline Vec4 Texture1D::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
671 return m_view.sampleOffset(sampler, s, lod, offset);
674 /*--------------------------------------------------------------------*//*!
675 * \brief 2D Texture reference implementation
676 *//*--------------------------------------------------------------------*/
677 class Texture2D : private TextureLevelPyramid
680 Texture2D (const TextureFormat& format, int width, int height);
681 Texture2D (const Texture2D& other);
684 int getWidth (void) const { return m_width; }
685 int getHeight (void) const { return m_height; }
686 const Texture2DView& getView (void) const { return m_view; }
688 void allocLevel (int levelNdx);
691 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
692 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
693 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
694 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
696 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
697 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
699 using TextureLevelPyramid::getFormat;
700 using TextureLevelPyramid::getNumLevels;
701 using TextureLevelPyramid::getLevel;
702 using TextureLevelPyramid::clearLevel;
703 using TextureLevelPyramid::isLevelEmpty;
705 Texture2D& operator= (const Texture2D& other);
707 operator Texture2DView (void) const { return m_view; }
712 Texture2DView m_view;
713 } DE_WARN_UNUSED_TYPE;
715 inline Vec4 Texture2D::sample (const Sampler& sampler, float s, float t, float lod) const
717 return m_view.sample(sampler, s, t, lod);
720 inline Vec4 Texture2D::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
722 return m_view.sampleOffset(sampler, s, t, lod, offset);
725 inline float Texture2D::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
727 return m_view.sampleCompare(sampler, ref, s, t, lod);
730 inline float Texture2D::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
732 return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
735 inline Vec4 Texture2D::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
737 return m_view.gatherOffsets(sampler, s, t, componentNdx, offsets);
740 inline Vec4 Texture2D::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
742 return m_view.gatherOffsetsCompare(sampler, ref, s, t, offsets);
745 /*--------------------------------------------------------------------*//*!
746 * \brief Cube Map Texture View
747 *//*--------------------------------------------------------------------*/
748 class TextureCubeView
751 TextureCubeView (void);
752 TextureCubeView (int numLevels, const ConstPixelBufferAccess* const (&levels)[CUBEFACE_LAST]);
754 int getNumLevels (void) const { return m_numLevels; }
755 int getSize (void) const { return m_numLevels > 0 ? m_levels[0][0].getWidth() : 0; }
756 const ConstPixelBufferAccess& getLevelFace (int ndx, CubeFace face) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[face][ndx]; }
757 const ConstPixelBufferAccess* getFaceLevels (CubeFace face) const { return m_levels[face]; }
759 Vec4 sample (const Sampler& sampler, float s, float t, float p, float lod) const;
760 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
762 Vec4 gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const;
763 Vec4 gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const;
767 const ConstPixelBufferAccess* m_levels[CUBEFACE_LAST];
768 } DE_WARN_UNUSED_TYPE;
770 /*--------------------------------------------------------------------*//*!
771 * \brief Cube Map Texture reference implementation
772 *//*--------------------------------------------------------------------*/
776 TextureCube (const TextureFormat& format, int size);
777 TextureCube (const TextureCube& other);
780 const TextureFormat& getFormat (void) const { return m_format; }
781 int getSize (void) const { return m_size; }
783 int getNumLevels (void) const { return (int)m_access[0].size(); }
784 const ConstPixelBufferAccess& getLevelFace (int ndx, CubeFace face) const { DE_ASSERT(de::inBounds(ndx, 0, getNumLevels())); return m_access[face][(size_t)ndx]; }
785 const PixelBufferAccess& getLevelFace (int ndx, CubeFace face) { DE_ASSERT(de::inBounds(ndx, 0, getNumLevels())); return m_access[face][(size_t)ndx]; }
787 void allocLevel (CubeFace face, int levelNdx);
788 void clearLevel (CubeFace face, int levelNdx);
789 bool isLevelEmpty (CubeFace face, int levelNdx) const { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[face][(size_t)levelNdx].empty(); }
791 Vec4 sample (const Sampler& sampler, float s, float t, float p, float lod) const;
792 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
794 Vec4 gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const;
795 Vec4 gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const;
797 TextureCube& operator= (const TextureCube& other);
799 operator TextureCubeView (void) const { return m_view; }
802 typedef de::ArrayBuffer<deUint8> LevelData;
804 TextureFormat m_format;
806 std::vector<LevelData> m_data[CUBEFACE_LAST];
807 std::vector<PixelBufferAccess> m_access[CUBEFACE_LAST];
808 TextureCubeView m_view;
809 } DE_WARN_UNUSED_TYPE;
811 inline Vec4 TextureCube::sample (const Sampler& sampler, float s, float t, float p, float lod) const
813 return m_view.sample(sampler, s, t, p, lod);
816 inline float TextureCube::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
818 return m_view.sampleCompare(sampler, ref, s, t, r, lod);
821 inline Vec4 TextureCube::gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const
823 return m_view.gather(sampler, s, t, r, componentNdx);
826 inline Vec4 TextureCube::gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const
828 return m_view.gatherCompare(sampler, ref, s, t, r);
831 /*--------------------------------------------------------------------*//*!
832 * \brief 1D Array Texture View
833 *//*--------------------------------------------------------------------*/
834 class Texture1DArrayView
837 Texture1DArrayView (int numLevels, const ConstPixelBufferAccess* levels);
839 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
840 int getNumLayers (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
841 int getNumLevels (void) const { return m_numLevels; }
842 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
843 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
845 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
846 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
847 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
848 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
851 int selectLayer (float r) const;
854 const ConstPixelBufferAccess* m_levels;
855 } DE_WARN_UNUSED_TYPE;
857 /*--------------------------------------------------------------------*//*!
858 * \brief 2D Array Texture View
859 *//*--------------------------------------------------------------------*/
860 class Texture2DArrayView
863 Texture2DArrayView (int numLevels, const ConstPixelBufferAccess* levels);
865 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
866 int getHeight (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
867 int getNumLayers (void) const { return m_numLevels > 0 ? m_levels[0].getDepth() : 0; }
868 int getNumLevels (void) const { return m_numLevels; }
869 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
870 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
872 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
873 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
874 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
875 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
877 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
878 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
881 int selectLayer (float r) const;
884 const ConstPixelBufferAccess* m_levels;
885 } DE_WARN_UNUSED_TYPE;
887 /*--------------------------------------------------------------------*//*!
888 * \brief 1D Array Texture reference implementation
889 *//*--------------------------------------------------------------------*/
890 class Texture1DArray : private TextureLevelPyramid
893 Texture1DArray (const TextureFormat& format, int width, int numLayers);
894 Texture1DArray (const Texture1DArray& other);
895 ~Texture1DArray (void);
897 int getWidth (void) const { return m_width; }
898 int getNumLayers (void) const { return m_numLayers; }
900 void allocLevel (int levelNdx);
902 using TextureLevelPyramid::getFormat;
903 using TextureLevelPyramid::getNumLevels;
904 using TextureLevelPyramid::getLevel;
905 using TextureLevelPyramid::clearLevel;
906 using TextureLevelPyramid::isLevelEmpty;
908 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
909 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
910 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
911 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
913 Texture1DArray& operator= (const Texture1DArray& other);
915 operator Texture1DArrayView (void) const { return m_view; }
920 Texture1DArrayView m_view;
921 } DE_WARN_UNUSED_TYPE;
923 inline Vec4 Texture1DArray::sample (const Sampler& sampler, float s, float t, float lod) const
925 return m_view.sample(sampler, s, t, lod);
928 inline Vec4 Texture1DArray::sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const
930 return m_view.sampleOffset(sampler, s, t, lod, offset);
933 inline float Texture1DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
935 return m_view.sampleCompare(sampler, ref, s, t, lod);
938 inline float Texture1DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const
940 return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
943 /*--------------------------------------------------------------------*//*!
944 * \brief 2D Array Texture reference implementation
945 *//*--------------------------------------------------------------------*/
946 class Texture2DArray : private TextureLevelPyramid
949 Texture2DArray (const TextureFormat& format, int width, int height, int numLayers);
950 Texture2DArray (const Texture2DArray& other);
951 ~Texture2DArray (void);
953 int getWidth (void) const { return m_width; }
954 int getHeight (void) const { return m_height; }
955 int getNumLayers (void) const { return m_numLayers; }
957 void allocLevel (int levelNdx);
959 using TextureLevelPyramid::getFormat;
960 using TextureLevelPyramid::getNumLevels;
961 using TextureLevelPyramid::getLevel;
962 using TextureLevelPyramid::clearLevel;
963 using TextureLevelPyramid::isLevelEmpty;
965 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
966 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
967 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
968 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
970 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
971 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
973 Texture2DArray& operator= (const Texture2DArray& other);
975 operator Texture2DArrayView (void) const { return m_view; }
981 Texture2DArrayView m_view;
982 } DE_WARN_UNUSED_TYPE;
984 inline Vec4 Texture2DArray::sample (const Sampler& sampler, float s, float t, float r, float lod) const
986 return m_view.sample(sampler, s, t, r, lod);
989 inline Vec4 Texture2DArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const
991 return m_view.sampleOffset(sampler, s, t, r, lod, offset);
994 inline float Texture2DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
996 return m_view.sampleCompare(sampler, ref, s, t, r, lod);
999 inline float Texture2DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const
1001 return m_view.sampleCompareOffset(sampler, ref, s, t, r, lod, offset);
1004 inline Vec4 Texture2DArray::gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const
1006 return m_view.gatherOffsets(sampler, s, t, r, componentNdx, offsets);
1009 inline Vec4 Texture2DArray::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const
1011 return m_view.gatherOffsetsCompare(sampler, ref, s, t, r, offsets);
1014 /*--------------------------------------------------------------------*//*!
1015 * \brief 3D Texture View
1016 *//*--------------------------------------------------------------------*/
1020 Texture3DView (int numLevels, const ConstPixelBufferAccess* levels);
1022 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
1023 int getHeight (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
1024 int getDepth (void) const { return m_numLevels > 0 ? m_levels[0].getDepth() : 0; }
1025 int getNumLevels (void) const { return m_numLevels; }
1026 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
1027 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
1029 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
1030 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
1034 const ConstPixelBufferAccess* m_levels;
1035 } DE_WARN_UNUSED_TYPE;
1037 inline Vec4 Texture3DView::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1039 return sampleLevelArray3D(m_levels, m_numLevels, sampler, s, t, r, lod);
1042 inline Vec4 Texture3DView::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
1044 return sampleLevelArray3DOffset(m_levels, m_numLevels, sampler, s, t, r, lod, offset);
1047 /*--------------------------------------------------------------------*//*!
1048 * \brief 3D Texture reference implementation
1049 *//*--------------------------------------------------------------------*/
1050 class Texture3D : private TextureLevelPyramid
1053 Texture3D (const TextureFormat& format, int width, int height, int depth);
1054 Texture3D (const Texture3D& other);
1057 int getWidth (void) const { return m_width; }
1058 int getHeight (void) const { return m_height; }
1059 int getDepth (void) const { return m_depth; }
1061 void allocLevel (int levelNdx);
1063 using TextureLevelPyramid::getFormat;
1064 using TextureLevelPyramid::getNumLevels;
1065 using TextureLevelPyramid::getLevel;
1066 using TextureLevelPyramid::clearLevel;
1067 using TextureLevelPyramid::isLevelEmpty;
1069 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
1070 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
1072 Texture3D& operator= (const Texture3D& other);
1074 operator Texture3DView (void) const { return m_view; }
1080 Texture3DView m_view;
1081 } DE_WARN_UNUSED_TYPE;
1083 inline Vec4 Texture3D::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1085 return m_view.sample(sampler, s, t, r, lod);
1088 inline Vec4 Texture3D::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
1090 return m_view.sampleOffset(sampler, s, t, r, lod, offset);
1093 /*--------------------------------------------------------------------*//*!
1094 * \brief Cube Map Array Texture View
1095 *//*--------------------------------------------------------------------*/
1096 class TextureCubeArrayView
1099 TextureCubeArrayView (int numLevels, const ConstPixelBufferAccess* levels);
1101 int getSize (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
1102 int getDepth (void) const { return m_numLevels > 0 ? m_levels[0].getDepth() : 0; }
1103 int getNumLayers (void) const { return getDepth() / 6; }
1104 int getNumLevels (void) const { return m_numLevels; }
1105 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
1106 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
1108 Vec4 sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const;
1109 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1110 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
1111 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1114 int selectLayer (float q) const;
1117 const ConstPixelBufferAccess* m_levels;
1118 } DE_WARN_UNUSED_TYPE;
1120 /*--------------------------------------------------------------------*//*!
1121 * \brief Cube Map Array Texture reference implementation
1122 *//*--------------------------------------------------------------------*/
1123 class TextureCubeArray : private TextureLevelPyramid
1126 TextureCubeArray (const TextureFormat& format, int size, int depth);
1127 TextureCubeArray (const TextureCubeArray& other);
1128 ~TextureCubeArray (void);
1130 int getSize (void) const { return m_size; }
1131 int getDepth (void) const { return m_depth; }
1133 void allocLevel (int levelNdx);
1135 using TextureLevelPyramid::getFormat;
1136 using TextureLevelPyramid::getNumLevels;
1137 using TextureLevelPyramid::getLevel;
1138 using TextureLevelPyramid::clearLevel;
1139 using TextureLevelPyramid::isLevelEmpty;
1141 Vec4 sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const;
1142 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1143 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
1144 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1146 TextureCubeArray& operator= (const TextureCubeArray& other);
1148 operator TextureCubeArrayView (void) const { return m_view; }
1153 TextureCubeArrayView m_view;
1154 } DE_WARN_UNUSED_TYPE;
1156 inline Vec4 TextureCubeArray::sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const
1158 return m_view.sample(sampler, s, t, r, q, lod);
1161 inline Vec4 TextureCubeArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const
1163 return m_view.sampleOffset(sampler, s, t, r, q, lod, offset);
1166 inline float TextureCubeArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const
1168 return m_view.sampleCompare(sampler, ref, s, t, r, q, lod);
1171 inline float TextureCubeArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const
1173 return m_view.sampleCompareOffset(sampler, ref, s, t, r, q, lod, offset);
1176 // Stream operators.
1177 std::ostream& operator<< (std::ostream& str, TextureFormat::ChannelOrder order);
1178 std::ostream& operator<< (std::ostream& str, TextureFormat::ChannelType type);
1179 std::ostream& operator<< (std::ostream& str, TextureFormat format);
1180 std::ostream& operator<< (std::ostream& str, CubeFace face);
1181 std::ostream& operator<< (std::ostream& str, const ConstPixelBufferAccess& access);
1185 #endif // _TCUTEXTURE_HPP