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,
113 FLOAT_UNSIGNED_INT_24_8_REV,
124 TextureFormat (ChannelOrder order_, ChannelType type_)
131 : order (CHANNELORDER_LAST)
132 , type (CHANNELTYPE_LAST)
136 int getPixelSize (void) const; //!< Deprecated, use tcu::getPixelSize(fmt)
138 bool operator== (const TextureFormat& other) const { return !(*this != other); }
139 bool operator!= (const TextureFormat& other) const
141 return (order != other.order || type != other.type);
143 } DE_WARN_UNUSED_TYPE;
145 bool isValid (TextureFormat format);
146 int getPixelSize (TextureFormat format);
147 int getNumUsedChannels (TextureFormat::ChannelOrder order);
148 int getChannelSize (TextureFormat::ChannelType type);
150 /*--------------------------------------------------------------------*//*!
151 * \brief Texture swizzle
152 *//*--------------------------------------------------------------------*/
153 struct TextureSwizzle
157 // \note CHANNEL_N must equal int N
169 Channel components[4];
172 //! get the swizzle used to expand texture data with a given channel order to RGBA form
173 const TextureSwizzle& getChannelReadSwizzle (TextureFormat::ChannelOrder order);
175 //! get the swizzle used to narrow RGBA form data to native texture data with a given channel order
176 const TextureSwizzle& getChannelWriteSwizzle (TextureFormat::ChannelOrder order);
178 /*--------------------------------------------------------------------*//*!
179 * \brief Sampling parameters
180 *//*--------------------------------------------------------------------*/
186 CLAMP_TO_EDGE = 0, //! Clamp to edge
187 CLAMP_TO_BORDER, //! Use border color at edge
188 REPEAT_GL, //! Repeat with OpenGL semantics
189 REPEAT_CL, //! Repeat with OpenCL semantics
190 MIRRORED_REPEAT_GL, //! Mirrored repeat with OpenGL semantics
191 MIRRORED_REPEAT_CL, //! Mirrored repeat with OpenCL semantics
192 MIRRORED_ONCE, //! Mirrored once in negative directions
202 NEAREST_MIPMAP_NEAREST,
203 NEAREST_MIPMAP_LINEAR,
204 LINEAR_MIPMAP_NEAREST,
205 LINEAR_MIPMAP_LINEAR,
212 WEIGHTED_AVERAGE = 0,
221 COMPAREMODE_NONE = 0,
223 COMPAREMODE_LESS_OR_EQUAL,
225 COMPAREMODE_GREATER_OR_EQUAL,
227 COMPAREMODE_NOT_EQUAL,
234 enum DepthStencilMode
247 // Minifcation & magnification
248 FilterMode minFilter;
249 FilterMode magFilter;
251 // min/max filtering reduction
252 ReductionMode reductionMode;
254 float lodThreshold; // lod <= lodThreshold ? magnified : minified
256 // Coordinate normalization
257 bool normalizedCoords;
264 // \note It is setter's responsibility to guarantee that the values are representable
265 // in sampled texture's internal format.
266 // \note It is setter's responsibility to guarantee that the format is compatible with the
267 // sampled texture's internal format. Otherwise results are undefined.
268 rr::GenericVec4 borderColor;
270 // Seamless cube map filtering
271 bool seamlessCubeMap;
273 // Depth stencil mode
274 DepthStencilMode depthStencilMode;
276 Sampler (WrapMode wrapS_,
279 FilterMode minFilter_,
280 FilterMode magFilter_,
281 float lodThreshold_ = 0.0f,
282 bool normalizedCoords_ = true,
283 CompareMode compare_ = COMPAREMODE_NONE,
284 int compareChannel_ = 0,
285 const Vec4& borderColor_ = Vec4(0.0f, 0.0f, 0.0f, 0.0f),
286 bool seamlessCubeMap_ = false,
287 DepthStencilMode depthStencilMode_ = MODE_DEPTH,
288 ReductionMode reductionMode_ = WEIGHTED_AVERAGE)
292 , minFilter (minFilter_)
293 , magFilter (magFilter_)
294 , reductionMode (reductionMode_)
295 , lodThreshold (lodThreshold_)
296 , normalizedCoords (normalizedCoords_)
298 , compareChannel (compareChannel_)
299 , borderColor (borderColor_)
300 , seamlessCubeMap (seamlessCubeMap_)
301 , depthStencilMode (depthStencilMode_)
306 : wrapS (WRAPMODE_LAST)
307 , wrapT (WRAPMODE_LAST)
308 , wrapR (WRAPMODE_LAST)
309 , minFilter (FILTERMODE_LAST)
310 , magFilter (FILTERMODE_LAST)
311 , reductionMode (REDUCTIONMODE_LAST)
312 , lodThreshold (0.0f)
313 , normalizedCoords (true)
314 , compare (COMPAREMODE_NONE)
316 , borderColor (Vec4(0.0f, 0.0f, 0.0f, 0.0f))
317 , seamlessCubeMap (false)
318 , depthStencilMode (MODE_DEPTH)
321 } DE_WARN_UNUSED_TYPE;
323 // Calculate pitches for pixel data with no padding.
324 IVec3 calculatePackedPitch (const TextureFormat& format, const IVec3& size);
328 /*--------------------------------------------------------------------*//*!
329 * \brief Read-only pixel data access
331 * ConstPixelBufferAccess encapsulates pixel data pointer along with
332 * format and layout information. It can be used for read-only access
333 * to arbitrary pixel buffers.
335 * Access objects are like iterators or pointers. They can be passed around
336 * as values and are valid as long as the storage doesn't change.
337 *//*--------------------------------------------------------------------*/
338 class ConstPixelBufferAccess
341 ConstPixelBufferAccess (void);
342 ConstPixelBufferAccess (const TextureLevel& level);
343 ConstPixelBufferAccess (const TextureFormat& format, int width, int height, int depth, const void* data);
344 ConstPixelBufferAccess (const TextureFormat& format, const IVec3& size, const void* data);
345 ConstPixelBufferAccess (const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, const void* data);
346 ConstPixelBufferAccess (const TextureFormat& format, const IVec3& size, const IVec3& pitch, const void* data);
348 const TextureFormat& getFormat (void) const { return m_format; }
349 const IVec3& getSize (void) const { return m_size; }
350 int getWidth (void) const { return m_size.x(); }
351 int getHeight (void) const { return m_size.y(); }
352 int getDepth (void) const { return m_size.z(); }
353 int getPixelPitch (void) const { return m_pitch.x(); }
354 int getRowPitch (void) const { return m_pitch.y(); }
355 int getSlicePitch (void) const { return m_pitch.z(); }
356 const IVec3& getPitch (void) const { return m_pitch; }
358 const void* getDataPtr (void) const { return m_data; }
359 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(); }
361 Vec4 getPixel (int x, int y, int z = 0) const;
362 IVec4 getPixelInt (int x, int y, int z = 0) const;
363 UVec4 getPixelUint (int x, int y, int z = 0) const { return getPixelInt(x, y, z).cast<deUint32>(); }
366 Vector<T, 4> getPixelT (int x, int y, int z = 0) const;
368 float getPixDepth (int x, int y, int z = 0) const;
369 int getPixStencil (int x, int y, int z = 0) const;
371 Vec4 sample1D (const Sampler& sampler, Sampler::FilterMode filter, float s, int level) const;
372 Vec4 sample2D (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, int depth) const;
373 Vec4 sample3D (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, float r) const;
375 Vec4 sample1DOffset (const Sampler& sampler, Sampler::FilterMode filter, float s, const IVec2& offset) const;
376 Vec4 sample2DOffset (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, const IVec3& offset) const;
377 Vec4 sample3DOffset (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, float r, const IVec3& offset) const;
379 float sample1DCompare (const Sampler& sampler, Sampler::FilterMode filter, float ref, float s, const IVec2& offset) const;
380 float sample2DCompare (const Sampler& sampler, Sampler::FilterMode filter, float ref, float s, float t, const IVec3& offset) const;
383 TextureFormat m_format;
385 IVec3 m_pitch; //!< (pixelPitch, rowPitch, slicePitch)
386 mutable void* m_data;
387 } DE_WARN_UNUSED_TYPE;
389 /*--------------------------------------------------------------------*//*!
390 * \brief Read-write pixel data access
392 * This class extends read-only access object by providing write functionality.
394 * \note PixelBufferAccess may not have any data members nor add any
395 * virtual functions. It must be possible to reinterpret_cast<>
396 * PixelBufferAccess to ConstPixelBufferAccess.
397 *//*--------------------------------------------------------------------*/
398 class PixelBufferAccess : public ConstPixelBufferAccess
401 PixelBufferAccess (void) {}
402 PixelBufferAccess (TextureLevel& level);
403 PixelBufferAccess (const TextureFormat& format, int width, int height, int depth, void* data);
404 PixelBufferAccess (const TextureFormat& format, const IVec3& size, void* data);
405 PixelBufferAccess (const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, void* data);
406 PixelBufferAccess (const TextureFormat& format, const IVec3& size, const IVec3& pitch, void* data);
408 void* getDataPtr (void) const { return m_data; }
409 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(); }
411 void setPixel (const tcu::Vec4& color, int x, int y, int z = 0) const;
412 void setPixel (const tcu::IVec4& color, int x, int y, int z = 0) const;
413 void setPixel (const tcu::UVec4& color, int x, int y, int z = 0) const { setPixel(color.cast<int>(), x, y, z); }
415 void setPixDepth (float depth, int x, int y, int z = 0) const;
416 void setPixStencil (int stencil, int x, int y, int z = 0) const;
417 } DE_WARN_UNUSED_TYPE;
419 /*--------------------------------------------------------------------*//*!
420 * \brief Generic pixel data container
422 * This container supports all valid TextureFormat combinations and
423 * both 2D and 3D textures. To read or manipulate data access object must
424 * be queried using getAccess().
425 *//*--------------------------------------------------------------------*/
430 TextureLevel (const TextureFormat& format);
431 TextureLevel (const TextureFormat& format, int width, int height, int depth = 1);
432 ~TextureLevel (void);
434 const IVec3& getSize (void) const { return m_size; }
435 int getWidth (void) const { return m_size.x(); }
436 int getHeight (void) const { return m_size.y(); }
437 int getDepth (void) const { return m_size.z(); }
438 bool isEmpty (void) const { return m_size.x() * m_size.y() * m_size.z() == 0; }
439 const TextureFormat getFormat (void) const { return m_format; }
441 void setStorage (const TextureFormat& format, int width, int heigth, int depth = 1);
442 void setSize (int width, int height, int depth = 1);
444 PixelBufferAccess getAccess (void) { return isEmpty() ? PixelBufferAccess() : PixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr()); }
445 ConstPixelBufferAccess getAccess (void) const { return isEmpty() ? ConstPixelBufferAccess() : ConstPixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr()); }
448 void* getPtr (void) { return m_data.getPtr(); }
449 const void* getPtr (void) const { return m_data.getPtr(); }
451 TextureFormat m_format;
453 de::ArrayBuffer<deUint8> m_data;
455 friend class ConstPixelBufferAccess;
456 } DE_WARN_UNUSED_TYPE;
458 Vec4 sampleLevelArray1D (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, int level, float lod);
459 Vec4 sampleLevelArray2D (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, int depth, float lod);
460 Vec4 sampleLevelArray3D (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float r, float lod);
462 Vec4 sampleLevelArray1DOffset (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float lod, const IVec2& offset);
463 Vec4 sampleLevelArray2DOffset (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float lod, const IVec3& offset);
464 Vec4 sampleLevelArray3DOffset (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset);
466 float sampleLevelArray1DCompare (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float ref, float s, float lod, const IVec2& offset);
467 float sampleLevelArray2DCompare (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float ref, float s, float t, float lod, const IVec3& offset);
469 Vec4 gatherArray2DOffsets (const ConstPixelBufferAccess& src, const Sampler& sampler, float s, float t, int depth, int componentNdx, const IVec2 (&offsets)[4]);
470 Vec4 gatherArray2DOffsetsCompare (const ConstPixelBufferAccess& src, const Sampler& sampler, float ref, float s, float t, int depth, const IVec2 (&offsets)[4]);
474 CUBEFACE_NEGATIVE_X = 0,
484 /*--------------------------------------------------------------------*//*!
485 * \brief Coordinates projected onto cube face.
486 *//*--------------------------------------------------------------------*/
488 struct CubeFaceCoords
494 CubeFaceCoords (CubeFace face_, T s_, T t_) : face(face_), s(s_), t(t_) {}
495 CubeFaceCoords (CubeFace face_, const Vector<T, 2>& c) : face(face_), s(c.x()), t(c.y()) {}
496 } DE_WARN_UNUSED_TYPE;
498 typedef CubeFaceCoords<float> CubeFaceFloatCoords;
499 typedef CubeFaceCoords<int> CubeFaceIntCoords;
501 CubeFace selectCubeFace (const Vec3& coords);
502 Vec2 projectToFace (CubeFace face, const Vec3& coords);
503 CubeFaceFloatCoords getCubeFaceCoords (const Vec3& coords);
504 CubeFaceIntCoords remapCubeEdgeCoords (const CubeFaceIntCoords& coords, int size);
506 /*--------------------------------------------------------------------*//*!
507 * \brief 1D Texture View
508 *//*--------------------------------------------------------------------*/
512 Texture1DView (int numLevels, const ConstPixelBufferAccess* levels);
514 int getNumLevels (void) const { return m_numLevels; }
515 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
516 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
517 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
519 Vec4 sample (const Sampler& sampler, float s, float lod) const;
520 Vec4 sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const;
521 float sampleCompare (const Sampler& sampler, float ref, float s, float lod) const;
522 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const;
526 const ConstPixelBufferAccess* m_levels;
527 } DE_WARN_UNUSED_TYPE;
529 inline Texture1DView::Texture1DView (int numLevels, const ConstPixelBufferAccess* levels)
530 : m_numLevels (numLevels)
533 DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
536 inline Vec4 Texture1DView::sample (const Sampler& sampler, float s, float lod) const
538 return sampleLevelArray1D(m_levels, m_numLevels, sampler, s, 0 /* depth */, lod);
541 inline Vec4 Texture1DView::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
543 return sampleLevelArray1DOffset(m_levels, m_numLevels, sampler, s, lod, IVec2(offset, 0));
546 inline float Texture1DView::sampleCompare (const Sampler& sampler, float ref, float s, float lod) const
548 return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(0, 0));
551 inline float Texture1DView::sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const
553 return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(offset, 0));
556 /*--------------------------------------------------------------------*//*!
557 * \brief 2D Texture View
558 *//*--------------------------------------------------------------------*/
562 Texture2DView (int numLevels, const ConstPixelBufferAccess* levels);
564 int getNumLevels (void) const { return m_numLevels; }
565 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
566 int getHeight (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
567 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
568 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
570 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
571 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
572 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
573 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
575 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
576 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
580 const ConstPixelBufferAccess* m_levels;
581 } DE_WARN_UNUSED_TYPE;
583 inline Texture2DView::Texture2DView (int numLevels, const ConstPixelBufferAccess* levels)
584 : m_numLevels (numLevels)
587 DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
590 inline Vec4 Texture2DView::sample (const Sampler& sampler, float s, float t, float lod) const
592 return sampleLevelArray2D(m_levels, m_numLevels, sampler, s, t, 0 /* depth */, lod);
595 inline Vec4 Texture2DView::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
597 return sampleLevelArray2DOffset(m_levels, m_numLevels, sampler, s, t, lod, IVec3(offset.x(), offset.y(), 0));
600 inline float Texture2DView::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
602 return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(0, 0, 0));
605 inline float Texture2DView::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
607 return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(offset.x(), offset.y(), 0));
610 inline Vec4 Texture2DView::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
612 return gatherArray2DOffsets(m_levels[0], sampler, s, t, 0, componentNdx, offsets);
615 inline Vec4 Texture2DView::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
617 return gatherArray2DOffsetsCompare(m_levels[0], sampler, ref, s, t, 0, offsets);
620 /*--------------------------------------------------------------------*//*!
621 * \brief Base class for textures that have single mip-map pyramid
622 *//*--------------------------------------------------------------------*/
623 class TextureLevelPyramid
626 TextureLevelPyramid (const TextureFormat& format, int numLevels);
627 TextureLevelPyramid (const TextureLevelPyramid& other);
628 ~TextureLevelPyramid(void);
630 const TextureFormat& getFormat (void) const { return m_format; }
631 int getNumLevels (void) const { return (int)m_access.size(); }
633 bool isLevelEmpty (int levelNdx) const { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[(size_t)levelNdx].empty(); }
634 const ConstPixelBufferAccess& getLevel (int levelNdx) const { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_access[(size_t)levelNdx]; }
635 const PixelBufferAccess& getLevel (int levelNdx) { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_access[(size_t)levelNdx]; }
637 const ConstPixelBufferAccess* getLevels (void) const { return &m_access[0]; }
638 const PixelBufferAccess* getLevels (void) { return &m_access[0]; }
640 void allocLevel (int levelNdx, int width, int height, int depth);
641 void clearLevel (int levelNdx);
643 TextureLevelPyramid& operator= (const TextureLevelPyramid& other);
646 typedef de::ArrayBuffer<deUint8> LevelData;
648 TextureFormat m_format;
649 std::vector<LevelData> m_data;
650 std::vector<PixelBufferAccess> m_access;
651 } DE_WARN_UNUSED_TYPE;
653 /*--------------------------------------------------------------------*//*!
654 * \brief 1D Texture reference implementation
655 *//*--------------------------------------------------------------------*/
656 class Texture1D : private TextureLevelPyramid
659 Texture1D (const TextureFormat& format, int width);
660 Texture1D (const Texture1D& other);
663 int getWidth (void) const { return m_width; }
664 const Texture1DView& getView (void) const { return m_view; }
666 void allocLevel (int levelNdx);
669 Vec4 sample (const Sampler& sampler, float s, float lod) const;
670 Vec4 sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const;
671 float sampleCompare (const Sampler& sampler, float ref, float s, float lod) const;
672 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const;
674 using TextureLevelPyramid::getFormat;
675 using TextureLevelPyramid::getNumLevels;
676 using TextureLevelPyramid::getLevel;
677 using TextureLevelPyramid::clearLevel;
678 using TextureLevelPyramid::isLevelEmpty;
680 Texture1D& operator= (const Texture1D& other);
682 operator Texture1DView (void) const { return m_view; }
686 Texture1DView m_view;
687 } DE_WARN_UNUSED_TYPE;
689 inline Vec4 Texture1D::sample (const Sampler& sampler, float s, float lod) const
691 return m_view.sample(sampler, s, lod);
694 inline Vec4 Texture1D::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
696 return m_view.sampleOffset(sampler, s, lod, offset);
699 inline float Texture1D::sampleCompare (const Sampler& sampler, float ref, float s, float lod) const
701 return m_view.sampleCompare(sampler, ref, s, lod);
704 inline float Texture1D::sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const
706 return m_view.sampleCompareOffset(sampler, ref, s, lod, offset);
709 /*--------------------------------------------------------------------*//*!
710 * \brief 2D Texture reference implementation
711 *//*--------------------------------------------------------------------*/
712 class Texture2D : private TextureLevelPyramid
715 Texture2D (const TextureFormat& format, int width, int height);
716 Texture2D (const TextureFormat& format, int width, int height, int mipmaps);
717 Texture2D (const Texture2D& other);
720 int getWidth (void) const { return m_width; }
721 int getHeight (void) const { return m_height; }
722 const Texture2DView& getView (void) const { return m_view; }
724 void allocLevel (int levelNdx);
727 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
728 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
729 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
730 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
732 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
733 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
735 using TextureLevelPyramid::getFormat;
736 using TextureLevelPyramid::getNumLevels;
737 using TextureLevelPyramid::getLevel;
738 using TextureLevelPyramid::clearLevel;
739 using TextureLevelPyramid::isLevelEmpty;
741 Texture2D& operator= (const Texture2D& other);
743 operator Texture2DView (void) const { return m_view; }
748 Texture2DView m_view;
749 } DE_WARN_UNUSED_TYPE;
751 inline Vec4 Texture2D::sample (const Sampler& sampler, float s, float t, float lod) const
753 return m_view.sample(sampler, s, t, lod);
756 inline Vec4 Texture2D::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
758 return m_view.sampleOffset(sampler, s, t, lod, offset);
761 inline float Texture2D::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
763 return m_view.sampleCompare(sampler, ref, s, t, lod);
766 inline float Texture2D::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
768 return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
771 inline Vec4 Texture2D::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
773 return m_view.gatherOffsets(sampler, s, t, componentNdx, offsets);
776 inline Vec4 Texture2D::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
778 return m_view.gatherOffsetsCompare(sampler, ref, s, t, offsets);
781 /*--------------------------------------------------------------------*//*!
782 * \brief Cube Map Texture View
783 *//*--------------------------------------------------------------------*/
784 class TextureCubeView
787 TextureCubeView (void);
788 TextureCubeView (int numLevels, const ConstPixelBufferAccess* const (&levels)[CUBEFACE_LAST]);
790 int getNumLevels (void) const { return m_numLevels; }
791 int getSize (void) const { return m_numLevels > 0 ? m_levels[0][0].getWidth() : 0; }
792 const ConstPixelBufferAccess& getLevelFace (int ndx, CubeFace face) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[face][ndx]; }
793 const ConstPixelBufferAccess* getFaceLevels (CubeFace face) const { return m_levels[face]; }
795 Vec4 sample (const Sampler& sampler, float s, float t, float p, float lod) const;
796 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
798 Vec4 gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const;
799 Vec4 gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const;
803 const ConstPixelBufferAccess* m_levels[CUBEFACE_LAST];
804 } DE_WARN_UNUSED_TYPE;
806 /*--------------------------------------------------------------------*//*!
807 * \brief Cube Map Texture reference implementation
808 *//*--------------------------------------------------------------------*/
812 TextureCube (const TextureFormat& format, int size);
813 TextureCube (const TextureCube& other);
816 const TextureFormat& getFormat (void) const { return m_format; }
817 int getSize (void) const { return m_size; }
819 int getNumLevels (void) const { return (int)m_access[0].size(); }
820 const ConstPixelBufferAccess& getLevelFace (int ndx, CubeFace face) const { DE_ASSERT(de::inBounds(ndx, 0, getNumLevels())); return m_access[face][(size_t)ndx]; }
821 const PixelBufferAccess& getLevelFace (int ndx, CubeFace face) { DE_ASSERT(de::inBounds(ndx, 0, getNumLevels())); return m_access[face][(size_t)ndx]; }
823 void allocLevel (CubeFace face, int levelNdx);
824 void clearLevel (CubeFace face, int levelNdx);
825 bool isLevelEmpty (CubeFace face, int levelNdx) const { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[face][(size_t)levelNdx].empty(); }
827 Vec4 sample (const Sampler& sampler, float s, float t, float p, float lod) const;
828 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
830 Vec4 gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const;
831 Vec4 gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const;
833 TextureCube& operator= (const TextureCube& other);
835 operator TextureCubeView (void) const { return m_view; }
838 typedef de::ArrayBuffer<deUint8> LevelData;
840 TextureFormat m_format;
842 std::vector<LevelData> m_data[CUBEFACE_LAST];
843 std::vector<PixelBufferAccess> m_access[CUBEFACE_LAST];
844 TextureCubeView m_view;
845 } DE_WARN_UNUSED_TYPE;
847 inline Vec4 TextureCube::sample (const Sampler& sampler, float s, float t, float p, float lod) const
849 return m_view.sample(sampler, s, t, p, lod);
852 inline float TextureCube::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
854 return m_view.sampleCompare(sampler, ref, s, t, r, lod);
857 inline Vec4 TextureCube::gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const
859 return m_view.gather(sampler, s, t, r, componentNdx);
862 inline Vec4 TextureCube::gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const
864 return m_view.gatherCompare(sampler, ref, s, t, r);
867 /*--------------------------------------------------------------------*//*!
868 * \brief 1D Array Texture View
869 *//*--------------------------------------------------------------------*/
870 class Texture1DArrayView
873 Texture1DArrayView (int numLevels, const ConstPixelBufferAccess* levels);
875 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
876 int getNumLayers (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
877 int getNumLevels (void) const { return m_numLevels; }
878 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
879 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
881 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
882 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
883 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
884 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
887 int selectLayer (float r) const;
890 const ConstPixelBufferAccess* m_levels;
891 } DE_WARN_UNUSED_TYPE;
893 /*--------------------------------------------------------------------*//*!
894 * \brief 2D Array Texture View
895 *//*--------------------------------------------------------------------*/
896 class Texture2DArrayView
899 Texture2DArrayView (int numLevels, const ConstPixelBufferAccess* levels);
901 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
902 int getHeight (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
903 int getNumLayers (void) const { return m_numLevels > 0 ? m_levels[0].getDepth() : 0; }
904 int getNumLevels (void) const { return m_numLevels; }
905 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
906 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
908 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
909 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
910 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
911 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
913 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
914 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
917 int selectLayer (float r) const;
920 const ConstPixelBufferAccess* m_levels;
921 } DE_WARN_UNUSED_TYPE;
923 /*--------------------------------------------------------------------*//*!
924 * \brief 1D Array Texture reference implementation
925 *//*--------------------------------------------------------------------*/
926 class Texture1DArray : private TextureLevelPyramid
929 Texture1DArray (const TextureFormat& format, int width, int numLayers);
930 Texture1DArray (const Texture1DArray& other);
931 ~Texture1DArray (void);
933 int getWidth (void) const { return m_width; }
934 int getNumLayers (void) const { return m_numLayers; }
936 void allocLevel (int levelNdx);
938 using TextureLevelPyramid::getFormat;
939 using TextureLevelPyramid::getNumLevels;
940 using TextureLevelPyramid::getLevel;
941 using TextureLevelPyramid::clearLevel;
942 using TextureLevelPyramid::isLevelEmpty;
944 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
945 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
946 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
947 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
949 Texture1DArray& operator= (const Texture1DArray& other);
951 operator Texture1DArrayView (void) const { return m_view; }
956 Texture1DArrayView m_view;
957 } DE_WARN_UNUSED_TYPE;
959 inline Vec4 Texture1DArray::sample (const Sampler& sampler, float s, float t, float lod) const
961 return m_view.sample(sampler, s, t, lod);
964 inline Vec4 Texture1DArray::sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const
966 return m_view.sampleOffset(sampler, s, t, lod, offset);
969 inline float Texture1DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
971 return m_view.sampleCompare(sampler, ref, s, t, lod);
974 inline float Texture1DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const
976 return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
979 /*--------------------------------------------------------------------*//*!
980 * \brief 2D Array Texture reference implementation
981 *//*--------------------------------------------------------------------*/
982 class Texture2DArray : private TextureLevelPyramid
985 Texture2DArray (const TextureFormat& format, int width, int height, int numLayers);
986 Texture2DArray (const Texture2DArray& other);
987 ~Texture2DArray (void);
989 int getWidth (void) const { return m_width; }
990 int getHeight (void) const { return m_height; }
991 int getNumLayers (void) const { return m_numLayers; }
993 void allocLevel (int levelNdx);
995 using TextureLevelPyramid::getFormat;
996 using TextureLevelPyramid::getNumLevels;
997 using TextureLevelPyramid::getLevel;
998 using TextureLevelPyramid::clearLevel;
999 using TextureLevelPyramid::isLevelEmpty;
1001 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
1002 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
1003 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
1004 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
1006 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
1007 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
1009 Texture2DArray& operator= (const Texture2DArray& other);
1011 operator Texture2DArrayView (void) const { return m_view; }
1017 Texture2DArrayView m_view;
1018 } DE_WARN_UNUSED_TYPE;
1020 inline Vec4 Texture2DArray::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1022 return m_view.sample(sampler, s, t, r, lod);
1025 inline Vec4 Texture2DArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const
1027 return m_view.sampleOffset(sampler, s, t, r, lod, offset);
1030 inline float Texture2DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
1032 return m_view.sampleCompare(sampler, ref, s, t, r, lod);
1035 inline float Texture2DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const
1037 return m_view.sampleCompareOffset(sampler, ref, s, t, r, lod, offset);
1040 inline Vec4 Texture2DArray::gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const
1042 return m_view.gatherOffsets(sampler, s, t, r, componentNdx, offsets);
1045 inline Vec4 Texture2DArray::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const
1047 return m_view.gatherOffsetsCompare(sampler, ref, s, t, r, offsets);
1050 /*--------------------------------------------------------------------*//*!
1051 * \brief 3D Texture View
1052 *//*--------------------------------------------------------------------*/
1056 Texture3DView (int numLevels, const ConstPixelBufferAccess* levels);
1058 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
1059 int getHeight (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
1060 int getDepth (void) const { return m_numLevels > 0 ? m_levels[0].getDepth() : 0; }
1061 int getNumLevels (void) const { return m_numLevels; }
1062 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
1063 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
1065 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
1066 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
1070 const ConstPixelBufferAccess* m_levels;
1071 } DE_WARN_UNUSED_TYPE;
1073 inline Vec4 Texture3DView::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1075 return sampleLevelArray3D(m_levels, m_numLevels, sampler, s, t, r, lod);
1078 inline Vec4 Texture3DView::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
1080 return sampleLevelArray3DOffset(m_levels, m_numLevels, sampler, s, t, r, lod, offset);
1083 /*--------------------------------------------------------------------*//*!
1084 * \brief 3D Texture reference implementation
1085 *//*--------------------------------------------------------------------*/
1086 class Texture3D : private TextureLevelPyramid
1089 Texture3D (const TextureFormat& format, int width, int height, int depth);
1090 Texture3D (const Texture3D& other);
1093 int getWidth (void) const { return m_width; }
1094 int getHeight (void) const { return m_height; }
1095 int getDepth (void) const { return m_depth; }
1097 void allocLevel (int levelNdx);
1099 using TextureLevelPyramid::getFormat;
1100 using TextureLevelPyramid::getNumLevels;
1101 using TextureLevelPyramid::getLevel;
1102 using TextureLevelPyramid::clearLevel;
1103 using TextureLevelPyramid::isLevelEmpty;
1105 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
1106 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
1108 Texture3D& operator= (const Texture3D& other);
1110 operator Texture3DView (void) const { return m_view; }
1116 Texture3DView m_view;
1117 } DE_WARN_UNUSED_TYPE;
1119 inline Vec4 Texture3D::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1121 return m_view.sample(sampler, s, t, r, lod);
1124 inline Vec4 Texture3D::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
1126 return m_view.sampleOffset(sampler, s, t, r, lod, offset);
1129 /*--------------------------------------------------------------------*//*!
1130 * \brief Cube Map Array Texture View
1131 *//*--------------------------------------------------------------------*/
1132 class TextureCubeArrayView
1135 TextureCubeArrayView (int numLevels, const ConstPixelBufferAccess* levels);
1137 int getSize (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
1138 int getDepth (void) const { return m_numLevels > 0 ? m_levels[0].getDepth() : 0; }
1139 int getNumLayers (void) const { return getDepth() / 6; }
1140 int getNumLevels (void) const { return m_numLevels; }
1141 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
1142 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
1144 Vec4 sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const;
1145 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1146 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
1147 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1150 int selectLayer (float q) const;
1153 const ConstPixelBufferAccess* m_levels;
1154 } DE_WARN_UNUSED_TYPE;
1156 /*--------------------------------------------------------------------*//*!
1157 * \brief Cube Map Array Texture reference implementation
1158 *//*--------------------------------------------------------------------*/
1159 class TextureCubeArray : private TextureLevelPyramid
1162 TextureCubeArray (const TextureFormat& format, int size, int depth);
1163 TextureCubeArray (const TextureCubeArray& other);
1164 ~TextureCubeArray (void);
1166 int getSize (void) const { return m_size; }
1167 int getDepth (void) const { return m_depth; }
1169 void allocLevel (int levelNdx);
1171 using TextureLevelPyramid::getFormat;
1172 using TextureLevelPyramid::getNumLevels;
1173 using TextureLevelPyramid::getLevel;
1174 using TextureLevelPyramid::clearLevel;
1175 using TextureLevelPyramid::isLevelEmpty;
1177 Vec4 sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const;
1178 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1179 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
1180 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1182 TextureCubeArray& operator= (const TextureCubeArray& other);
1184 operator TextureCubeArrayView (void) const { return m_view; }
1189 TextureCubeArrayView m_view;
1190 } DE_WARN_UNUSED_TYPE;
1192 inline Vec4 TextureCubeArray::sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const
1194 return m_view.sample(sampler, s, t, r, q, lod);
1197 inline Vec4 TextureCubeArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const
1199 return m_view.sampleOffset(sampler, s, t, r, q, lod, offset);
1202 inline float TextureCubeArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const
1204 return m_view.sampleCompare(sampler, ref, s, t, r, q, lod);
1207 inline float TextureCubeArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const
1209 return m_view.sampleCompareOffset(sampler, ref, s, t, r, q, lod, offset);
1212 // Stream operators.
1213 std::ostream& operator<< (std::ostream& str, TextureFormat::ChannelOrder order);
1214 std::ostream& operator<< (std::ostream& str, TextureFormat::ChannelType type);
1215 std::ostream& operator<< (std::ostream& str, TextureFormat format);
1216 std::ostream& operator<< (std::ostream& str, CubeFace face);
1217 std::ostream& operator<< (std::ostream& str, const ConstPixelBufferAccess& access);
1221 #endif // _TCUTEXTURE_HPP