• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _TCUTEXTURE_HPP
2 #define _TCUTEXTURE_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program Tester Core
5  * ----------------------------------------
6  *
7  * Copyright 2014 The Android Open Source Project
8  *
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
21  *//*!
22  * \file
23  * \brief Reference Texture Implementation.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "tcuDefs.hpp"
27 #include "tcuVector.hpp"
28 #include "rrGenericVector.hpp"
29 #include "deArrayBuffer.hpp"
30 
31 #include <vector>
32 #include <ostream>
33 
34 namespace tcu
35 {
36 
37 /*--------------------------------------------------------------------*//*!
38  * \brief Texture format
39  *//*--------------------------------------------------------------------*/
40 class TextureFormat
41 {
42 public:
43 	enum ChannelOrder
44 	{
45 		R = 0,
46 		A,
47 		I,
48 		L,
49 		LA,
50 		RG,
51 		RA,
52 		RGB,
53 		RGBA,
54 		ARGB,
55 		ABGR,
56 		BGR,
57 		BGRA,
58 
59 		sR,
60 		sRG,
61 		sRGB,
62 		sRGBA,
63 		sBGR,
64 		sBGRA,
65 
66 		D,
67 		S,
68 		DS,
69 
70 		CHANNELORDER_LAST
71 	};
72 
73 	enum ChannelType
74 	{
75 		SNORM_INT8 = 0,
76 		SNORM_INT16,
77 		SNORM_INT32,
78 		UNORM_INT8,
79 		UNORM_INT16,
80 		UNORM_INT24,
81 		UNORM_INT32,
82 		UNORM_BYTE_44,
83 		UNORM_SHORT_565,
84 		UNORM_SHORT_555,
85 		UNORM_SHORT_4444,
86 		UNORM_SHORT_5551,
87 		UNORM_SHORT_1555,
88 		UNORM_INT_101010,
89 		SNORM_INT_1010102_REV,
90 		UNORM_INT_1010102_REV,
91 		UNSIGNED_BYTE_44,
92 		UNSIGNED_SHORT_565,
93 		UNSIGNED_SHORT_4444,
94 		UNSIGNED_SHORT_5551,
95 		SIGNED_INT_1010102_REV,
96 		UNSIGNED_INT_1010102_REV,
97 		UNSIGNED_INT_11F_11F_10F_REV,
98 		UNSIGNED_INT_999_E5_REV,
99 		UNSIGNED_INT_16_8_8,
100 		UNSIGNED_INT_24_8,
101 		UNSIGNED_INT_24_8_REV,
102 		SIGNED_INT8,
103 		SIGNED_INT16,
104 		SIGNED_INT32,
105 		SIGNED_INT64,
106 		UNSIGNED_INT8,
107 		UNSIGNED_INT16,
108 		UNSIGNED_INT24,
109 		UNSIGNED_INT32,
110 		UNSIGNED_INT64,
111 		HALF_FLOAT,
112 		FLOAT,
113 		FLOAT64,
114 		FLOAT_UNSIGNED_INT_24_8_REV,
115 
116 		UNORM_SHORT_10,
117 		UNORM_SHORT_12,
118 
119 		USCALED_INT8,
120 		USCALED_INT16,
121 		SSCALED_INT8,
122 		SSCALED_INT16,
123 		USCALED_INT_1010102_REV,
124 		SSCALED_INT_1010102_REV,
125 
126 		CHANNELTYPE_LAST
127 	};
128 
129 	ChannelOrder	order;
130 	ChannelType		type;
131 
TextureFormat(ChannelOrder order_,ChannelType type_)132 	TextureFormat (ChannelOrder order_, ChannelType type_)
133 		: order	(order_)
134 		, type	(type_)
135 	{
136 	}
137 
TextureFormat(void)138 	TextureFormat (void)
139 		: order	(CHANNELORDER_LAST)
140 		, type	(CHANNELTYPE_LAST)
141 	{
142 	}
143 
144 	int getPixelSize (void) const; //!< Deprecated, use tcu::getPixelSize(fmt)
145 
operator ==(const TextureFormat & other) const146 	bool operator== (const TextureFormat& other) const { return !(*this != other); }
operator !=(const TextureFormat & other) const147 	bool operator!= (const TextureFormat& other) const
148 	{
149 		return (order != other.order || type != other.type);
150 	}
151 } DE_WARN_UNUSED_TYPE;
152 
153 bool	isValid				(TextureFormat format);
154 int		getPixelSize		(TextureFormat format);
155 int		getNumUsedChannels	(TextureFormat::ChannelOrder order);
156 int		getChannelSize		(TextureFormat::ChannelType type);
157 
158 /*--------------------------------------------------------------------*//*!
159  * \brief Texture swizzle
160  *//*--------------------------------------------------------------------*/
161 struct TextureSwizzle
162 {
163 	enum Channel
164 	{
165 		// \note CHANNEL_N must equal int N
166 		CHANNEL_0 = 0,
167 		CHANNEL_1,
168 		CHANNEL_2,
169 		CHANNEL_3,
170 
171 		CHANNEL_ZERO,
172 		CHANNEL_ONE,
173 
174 		CHANNEL_LAST
175 	};
176 
177 	Channel components[4];
178 };
179 
180 //! get the swizzle used to expand texture data with a given channel order to RGBA form
181 const TextureSwizzle& getChannelReadSwizzle		(TextureFormat::ChannelOrder order);
182 
183 //! get the swizzle used to narrow RGBA form data to native texture data with a given channel order
184 const TextureSwizzle& getChannelWriteSwizzle	(TextureFormat::ChannelOrder order);
185 
186 /*--------------------------------------------------------------------*//*!
187  * \brief Sampling parameters
188  *//*--------------------------------------------------------------------*/
189 class Sampler
190 {
191 public:
192 	enum WrapMode
193 	{
194 		CLAMP_TO_EDGE = 0,	//! Clamp to edge
195 		CLAMP_TO_BORDER,	//! Use border color at edge
196 		REPEAT_GL,			//! Repeat with OpenGL semantics
197 		REPEAT_CL,			//! Repeat with OpenCL semantics
198 		MIRRORED_REPEAT_GL,	//! Mirrored repeat with OpenGL semantics
199 		MIRRORED_REPEAT_CL, //! Mirrored repeat with OpenCL semantics
200 		MIRRORED_ONCE,		//! Mirrored once in negative directions
201 
202 		WRAPMODE_LAST
203 	};
204 
205 	enum FilterMode
206 	{
207 		NEAREST = 0,
208 		LINEAR,
209 		CUBIC,
210 
211 		NEAREST_MIPMAP_NEAREST,
212 		NEAREST_MIPMAP_LINEAR,
213 		LINEAR_MIPMAP_NEAREST,
214 		LINEAR_MIPMAP_LINEAR,
215 		CUBIC_MIPMAP_NEAREST,
216 		CUBIC_MIPMAP_LINEAR,
217 
218 		FILTERMODE_LAST
219 	};
220 
221 	enum ReductionMode
222 	{
223 		WEIGHTED_AVERAGE = 0,
224 		MIN,
225 		MAX,
226 
227 		REDUCTIONMODE_LAST
228 	};
229 
230 	enum CompareMode
231 	{
232 		COMPAREMODE_NONE = 0,
233 		COMPAREMODE_LESS,
234 		COMPAREMODE_LESS_OR_EQUAL,
235 		COMPAREMODE_GREATER,
236 		COMPAREMODE_GREATER_OR_EQUAL,
237 		COMPAREMODE_EQUAL,
238 		COMPAREMODE_NOT_EQUAL,
239 		COMPAREMODE_ALWAYS,
240 		COMPAREMODE_NEVER,
241 
242 		COMPAREMODE_LAST
243 	};
244 
245 	enum DepthStencilMode
246 	{
247 		MODE_DEPTH = 0,
248 		MODE_STENCIL,
249 
250 		MODE_LAST
251 	};
252 
253 	// Wrap control
254 	WrapMode			wrapS;
255 	WrapMode			wrapT;
256 	WrapMode			wrapR;
257 
258 	// Minifcation & magnification
259 	FilterMode			minFilter;
260 	FilterMode			magFilter;
261 
262 	// min/max filtering reduction
263 	ReductionMode		reductionMode;
264 
265 	float				lodThreshold;		// lod <= lodThreshold ? magnified : minified
266 
267 	// Coordinate normalization
268 	bool				normalizedCoords;
269 
270 	// Shadow comparison
271 	CompareMode			compare;
272 	int					compareChannel;
273 
274 	// Border color.
275 	// \note It is setter's responsibility to guarantee that the values are representable
276 	//       in sampled texture's internal format.
277 	// \note It is setter's responsibility to guarantee that the format is compatible with the
278 	//       sampled texture's internal format. Otherwise results are undefined.
279 	rr::GenericVec4		borderColor;
280 
281 	// Seamless cube map filtering
282 	bool				seamlessCubeMap;
283 
284 	// Depth stencil mode
285 	DepthStencilMode	depthStencilMode;
286 
Sampler(WrapMode wrapS_,WrapMode wrapT_,WrapMode wrapR_,FilterMode minFilter_,FilterMode magFilter_,float lodThreshold_=0.0f,bool normalizedCoords_=true,CompareMode compare_=COMPAREMODE_NONE,int compareChannel_=0,const Vec4 & borderColor_=Vec4 (0.0f,0.0f,0.0f,0.0f),bool seamlessCubeMap_=false,DepthStencilMode depthStencilMode_=MODE_DEPTH,ReductionMode reductionMode_=WEIGHTED_AVERAGE)287 	Sampler (WrapMode			wrapS_,
288 			 WrapMode			wrapT_,
289 			 WrapMode			wrapR_,
290 			 FilterMode			minFilter_,
291 			 FilterMode			magFilter_,
292 			 float				lodThreshold_		= 0.0f,
293 			 bool				normalizedCoords_	= true,
294 			 CompareMode		compare_			= COMPAREMODE_NONE,
295 			 int				compareChannel_		= 0,
296 			 const Vec4&		borderColor_		= Vec4(0.0f, 0.0f, 0.0f, 0.0f),
297 			 bool				seamlessCubeMap_	= false,
298 			 DepthStencilMode	depthStencilMode_	= MODE_DEPTH,
299 			 ReductionMode		reductionMode_		= WEIGHTED_AVERAGE)
300 		: wrapS				(wrapS_)
301 		, wrapT				(wrapT_)
302 		, wrapR				(wrapR_)
303 		, minFilter			(minFilter_)
304 		, magFilter			(magFilter_)
305 		, reductionMode		(reductionMode_)
306 		, lodThreshold		(lodThreshold_)
307 		, normalizedCoords	(normalizedCoords_)
308 		, compare			(compare_)
309 		, compareChannel	(compareChannel_)
310 		, borderColor		(borderColor_)
311 		, seamlessCubeMap	(seamlessCubeMap_)
312 		, depthStencilMode	(depthStencilMode_)
313 	{
314 	}
315 
Sampler(void)316 	Sampler (void)
317 		: wrapS				(WRAPMODE_LAST)
318 		, wrapT				(WRAPMODE_LAST)
319 		, wrapR				(WRAPMODE_LAST)
320 		, minFilter			(FILTERMODE_LAST)
321 		, magFilter			(FILTERMODE_LAST)
322 		, reductionMode		(REDUCTIONMODE_LAST)
323 		, lodThreshold		(0.0f)
324 		, normalizedCoords	(true)
325 		, compare			(COMPAREMODE_NONE)
326 		, compareChannel	(0)
327 		, borderColor		(Vec4(0.0f, 0.0f, 0.0f, 0.0f))
328 		, seamlessCubeMap	(false)
329 		, depthStencilMode	(MODE_DEPTH)
330 	{
331 	}
332 } DE_WARN_UNUSED_TYPE;
333 
334 // Calculate pitches for pixel data with no padding.
335 IVec3 calculatePackedPitch (const TextureFormat& format, const IVec3& size);
336 
337 class TextureLevel;
338 
339 /*--------------------------------------------------------------------*//*!
340  * \brief Read-only pixel data access
341  *
342  * ConstPixelBufferAccess encapsulates pixel data pointer along with
343  * format and layout information. It can be used for read-only access
344  * to arbitrary pixel buffers.
345  *
346  * Access objects are like iterators or pointers. They can be passed around
347  * as values and are valid as long as the storage doesn't change.
348  *//*--------------------------------------------------------------------*/
349 class ConstPixelBufferAccess
350 {
351 public:
352 							ConstPixelBufferAccess		(void);
353 							ConstPixelBufferAccess		(const TextureLevel& level);
354 							ConstPixelBufferAccess		(const TextureFormat& format, int width, int height, int depth, const void* data);
355 							ConstPixelBufferAccess		(const TextureFormat& format, const IVec3& size, const void* data);
356 							ConstPixelBufferAccess		(const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, const void* data);
357 							ConstPixelBufferAccess		(const TextureFormat& format, const IVec3& size, const IVec3& pitch, const void* data);
358 							ConstPixelBufferAccess		(const TextureFormat& format, const IVec3& size, const IVec3& pitch, const IVec3& divider, const void* data);
359 
getFormat(void) const360 	const TextureFormat&	getFormat					(void) const	{ return m_format;					}
getSize(void) const361 	const IVec3&			getSize						(void) const	{ return m_size;					}
getWidth(void) const362 	int						getWidth					(void) const	{ return m_size.x();				}
getHeight(void) const363 	int						getHeight					(void) const	{ return m_size.y();				}
getDepth(void) const364 	int						getDepth					(void) const	{ return m_size.z();				}
getPixelPitch(void) const365 	int						getPixelPitch				(void) const	{ return m_pitch.x();				}
getRowPitch(void) const366 	int						getRowPitch					(void) const	{ return m_pitch.y();				}
getSlicePitch(void) const367 	int						getSlicePitch				(void) const	{ return m_pitch.z();				}
getPitch(void) const368 	const IVec3&			getPitch					(void) const	{ return m_pitch;					}
getDivider(void) const369 	const IVec3&			getDivider					(void) const	{ return m_divider;					}
370 
getDataPtr(void) const371 	const void*				getDataPtr					(void) const	{ return m_data;					}
getPixelPtr(int x,int y,int z=0) const372 	const void*				getPixelPtr					(int x, int y, int z = 0) const { return (const deUint8*)m_data + (x/m_divider.x()) * m_pitch.x() + (y/m_divider.y()) * m_pitch.y() + (z/m_divider.z()) * m_pitch.z(); }
373 
374 	Vec4					getPixel					(int x, int y, int z = 0) const;
375 	IVec4					getPixelInt					(int x, int y, int z = 0) const;
getPixelUint(int x,int y,int z=0) const376 	UVec4					getPixelUint				(int x, int y, int z = 0) const { return getPixelInt(x, y, z).cast<deUint32>(); }
377 	I64Vec4					getPixelInt64				(int x, int y, int z = 0) const;
getPixelUint64(int x,int y,int z=0) const378 	U64Vec4					getPixelUint64				(int x, int y, int z = 0) const { return getPixelInt64(x, y, z).cast<deUint64>(); }
379 
380 	template<typename T>
381 	Vector<T, 4>			getPixelT					(int x, int y, int z = 0) const;
382 
383 	float					getPixDepth					(int x, int y, int z = 0) const;
384 	int						getPixStencil				(int x, int y, int z = 0) const;
385 
386 	Vec4					sample1D					(const Sampler& sampler, Sampler::FilterMode filter, float s, int level) const;
387 	Vec4					sample2D					(const Sampler& sampler, Sampler::FilterMode filter, float s, float t, int depth) const;
388 	Vec4					sample3D					(const Sampler& sampler, Sampler::FilterMode filter, float s, float t, float r) const;
389 
390 	Vec4					sample1DOffset				(const Sampler& sampler, Sampler::FilterMode filter, float s, const IVec2& offset) const;
391 	Vec4					sample2DOffset				(const Sampler& sampler, Sampler::FilterMode filter, float s, float t, const IVec3& offset) const;
392 	Vec4					sample3DOffset				(const Sampler& sampler, Sampler::FilterMode filter, float s, float t, float r, const IVec3& offset) const;
393 
394 	float					sample1DCompare				(const Sampler& sampler, Sampler::FilterMode filter, float ref, float s, const IVec2& offset) const;
395 	float					sample2DCompare				(const Sampler& sampler, Sampler::FilterMode filter, float ref, float s, float t, const IVec3& offset) const;
396 
397 protected:
398 	TextureFormat			m_format;
399 	IVec3					m_size;
400 	IVec3					m_pitch;	//!< (pixelPitch, rowPitch, slicePitch)
401 	IVec3					m_divider;
402 	mutable void*			m_data;
403 } DE_WARN_UNUSED_TYPE;
404 
405 /*--------------------------------------------------------------------*//*!
406  * \brief Read-write pixel data access
407  *
408  * This class extends read-only access object by providing write functionality.
409  *
410  * \note PixelBufferAccess may not have any data members nor add any
411  *		 virtual functions. It must be possible to reinterpret_cast<>
412  *		 PixelBufferAccess to ConstPixelBufferAccess.
413  *//*--------------------------------------------------------------------*/
414 class PixelBufferAccess : public ConstPixelBufferAccess
415 {
416 public:
PixelBufferAccess(void)417 						PixelBufferAccess	(void) {}
418 						PixelBufferAccess	(TextureLevel& level);
419 						PixelBufferAccess	(const TextureFormat& format, int width, int height, int depth, void* data);
420 						PixelBufferAccess	(const TextureFormat& format, const IVec3& size, void* data);
421 						PixelBufferAccess	(const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, void* data);
422 						PixelBufferAccess	(const TextureFormat& format, const IVec3& size, const IVec3& pitch, void* data);
423 						PixelBufferAccess	(const TextureFormat& format, const IVec3& size, const IVec3& pitch, const IVec3& block, void* data);
424 
getDataPtr(void) const425 	void*				getDataPtr			(void) const { return m_data; }
getPixelPtr(int x,int y,int z=0) const426 	void*				getPixelPtr			(int x, int y, int z = 0) const { return (deUint8*)m_data + (x/m_divider.x()) * m_pitch.x() + (y/m_divider.y()) * m_pitch.y() + (z/m_divider.z()) * m_pitch.z(); }
427 
428 	void				setPixel			(const tcu::Vec4& color, int x, int y, int z = 0) const;
429 	void				setPixel			(const tcu::IVec4& color, int x, int y, int z = 0) const;
setPixel(const tcu::UVec4 & color,int x,int y,int z=0) const430 	void				setPixel			(const tcu::UVec4& color, int x, int y, int z = 0) const { setPixel(color.cast<int>(), x, y, z); }
431 
432 	void				setPixDepth			(float depth, int x, int y, int z = 0) const;
433 	void				setPixStencil		(int stencil, int x, int y, int z = 0) const;
434 } DE_WARN_UNUSED_TYPE;
435 
436 /*--------------------------------------------------------------------*//*!
437  * \brief Generic pixel data container
438  *
439  * This container supports all valid TextureFormat combinations and
440  * both 2D and 3D textures. To read or manipulate data access object must
441  * be queried using getAccess().
442  *//*--------------------------------------------------------------------*/
443 class TextureLevel
444 {
445 public:
446 								TextureLevel		(void);
447 								TextureLevel		(const TextureFormat& format);
448 								TextureLevel		(const TextureFormat& format, int width, int height, int depth = 1);
449 								~TextureLevel		(void);
450 
getSize(void) const451 	const IVec3&				getSize				(void) const	{ return m_size;		}
getWidth(void) const452 	int							getWidth			(void) const	{ return m_size.x();	}
getHeight(void) const453 	int							getHeight			(void) const	{ return m_size.y();	}
getDepth(void) const454 	int							getDepth			(void) const	{ return m_size.z();	}
isEmpty(void) const455 	bool						isEmpty				(void) const	{ return m_size.x() * m_size.y() * m_size.z() == 0; }
getFormat(void) const456 	const TextureFormat			getFormat			(void) const	{ return m_format;	}
457 
458 	void						setStorage			(const TextureFormat& format, int width, int heigth, int depth = 1);
459 	void						setSize				(int width, int height, int depth = 1);
460 
getAccess(void)461 	PixelBufferAccess			getAccess			(void)			{ return isEmpty() ? PixelBufferAccess() : PixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr());			}
getAccess(void) const462 	ConstPixelBufferAccess		getAccess			(void) const	{ return isEmpty() ? ConstPixelBufferAccess() : ConstPixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr());	}
463 
464 private:
getPtr(void)465 	void*						getPtr				(void)			{ return m_data.getPtr(); }
getPtr(void) const466 	const void*					getPtr				(void) const	{ return m_data.getPtr(); }
467 
468 	TextureFormat				m_format;
469 	IVec3						m_size;
470 	de::ArrayBuffer<deUint8>	m_data;
471 
472 	friend class ConstPixelBufferAccess;
473 } DE_WARN_UNUSED_TYPE;
474 
475 Vec4	sampleLevelArray1D				(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, int level, float lod);
476 Vec4	sampleLevelArray2D				(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, int depth, float lod, bool es2 = false);
477 Vec4	sampleLevelArray3D				(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float r, float lod);
478 
479 Vec4	sampleLevelArray1DOffset		(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float lod, const IVec2& offset);
480 Vec4	sampleLevelArray2DOffset		(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float lod, const IVec3& offset, bool es2 = false);
481 Vec4	sampleLevelArray3DOffset		(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset);
482 
483 float	sampleLevelArray1DCompare		(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float ref, float s, float lod, const IVec2& offset);
484 float	sampleLevelArray2DCompare		(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float ref, float s, float t, float lod, const IVec3& offset);
485 
486 Vec4	gatherArray2DOffsets			(const ConstPixelBufferAccess& src, const Sampler& sampler, float s, float t, int depth, int componentNdx, const IVec2 (&offsets)[4]);
487 Vec4	gatherArray2DOffsetsCompare		(const ConstPixelBufferAccess& src, const Sampler& sampler, float ref, float s, float t, int depth, const IVec2 (&offsets)[4]);
488 
489 enum CubeFace
490 {
491 	CUBEFACE_NEGATIVE_X = 0,
492 	CUBEFACE_POSITIVE_X,
493 	CUBEFACE_NEGATIVE_Y,
494 	CUBEFACE_POSITIVE_Y,
495 	CUBEFACE_NEGATIVE_Z,
496 	CUBEFACE_POSITIVE_Z,
497 
498 	CUBEFACE_LAST
499 };
500 
501 /*--------------------------------------------------------------------*//*!
502  * \brief Coordinates projected onto cube face.
503  *//*--------------------------------------------------------------------*/
504 template<typename T>
505 struct CubeFaceCoords
506 {
507 	CubeFace		face;
508 	T				s;
509 	T				t;
510 
CubeFaceCoordstcu::CubeFaceCoords511 					CubeFaceCoords		(CubeFace face_, T s_, T t_) : face(face_), s(s_), t(t_) {}
CubeFaceCoordstcu::CubeFaceCoords512 					CubeFaceCoords		(CubeFace face_, const Vector<T, 2>& c) : face(face_), s(c.x()), t(c.y()) {}
513 } DE_WARN_UNUSED_TYPE;
514 
515 typedef CubeFaceCoords<float>	CubeFaceFloatCoords;
516 typedef CubeFaceCoords<int>		CubeFaceIntCoords;
517 
518 CubeFace				selectCubeFace			(const Vec3& coords);
519 Vec2					projectToFace			(CubeFace face, const Vec3& coords);
520 CubeFaceFloatCoords		getCubeFaceCoords		(const Vec3& coords);
521 CubeFaceIntCoords		remapCubeEdgeCoords		(const CubeFaceIntCoords& coords, int size);
522 
523 /*--------------------------------------------------------------------*//*!
524  * \brief 2D Texture View
525  *//*--------------------------------------------------------------------*/
526 class Texture2DView
527 {
528 public:
529 									Texture2DView		(int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false);
530 
getNumLevels(void) const531 	int								getNumLevels		(void) const	{ return m_numLevels;										}
getWidth(void) const532 	int								getWidth			(void) const	{ return m_numLevels > 0 ? m_levels[0].getWidth()	: 0;	}
getHeight(void) const533 	int								getHeight			(void) const	{ return m_numLevels > 0 ? m_levels[0].getHeight()	: 0;	}
getLevel(int ndx) const534 	const ConstPixelBufferAccess&	getLevel			(int ndx) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];	}
getLevels(void) const535 	const ConstPixelBufferAccess*	getLevels			(void) const	{ return m_levels;											}
isES2(void) const536 	bool								isES2					(void) const	{ return m_es2;												}
537 
538 	Vec4							sample				(const Sampler& sampler, float s, float t, float lod) const;
539 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
540 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float lod) const;
541 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
542 
543 	Vec4							gatherOffsets		(const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
544 	Vec4							gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
545 
546 protected:
547 	int								m_numLevels;
548 	const ConstPixelBufferAccess*	m_levels;
549 	bool								m_es2;
550 } DE_WARN_UNUSED_TYPE;
551 
Texture2DView(int numLevels,const ConstPixelBufferAccess * levels,bool es2)552 inline Texture2DView::Texture2DView (int numLevels, const ConstPixelBufferAccess* levels, bool es2)
553 	: m_numLevels	(numLevels)
554 	, m_levels		(levels)
555 	, m_es2			(es2)
556 {
557 	DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
558 }
559 
sample(const Sampler & sampler,float s,float t,float lod) const560 inline Vec4 Texture2DView::sample (const Sampler& sampler, float s, float t, float lod) const
561 {
562 	return sampleLevelArray2D(m_levels, m_numLevels, sampler, s, t, 0 /* depth */, lod, m_es2);
563 }
564 
sampleOffset(const Sampler & sampler,float s,float t,float lod,const IVec2 & offset) const565 inline Vec4 Texture2DView::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
566 {
567 	return sampleLevelArray2DOffset(m_levels, m_numLevels, sampler, s, t, lod, IVec3(offset.x(), offset.y(), 0));
568 }
569 
sampleCompare(const Sampler & sampler,float ref,float s,float t,float lod) const570 inline float Texture2DView::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
571 {
572 	return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(0, 0, 0));
573 }
574 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float lod,const IVec2 & offset) const575 inline float Texture2DView::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
576 {
577 	return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(offset.x(), offset.y(), 0));
578 }
579 
gatherOffsets(const Sampler & sampler,float s,float t,int componentNdx,const IVec2 (& offsets)[4]) const580 inline Vec4 Texture2DView::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
581 {
582 	return gatherArray2DOffsets(m_levels[0], sampler, s, t, 0, componentNdx, offsets);
583 }
584 
gatherOffsetsCompare(const Sampler & sampler,float ref,float s,float t,const IVec2 (& offsets)[4]) const585 inline Vec4 Texture2DView::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
586 {
587 	return gatherArray2DOffsetsCompare(m_levels[0], sampler, ref, s, t, 0, offsets);
588 }
589 
590 /*--------------------------------------------------------------------*//*!
591  * \brief Base class for textures that have single mip-map pyramid
592  *//*--------------------------------------------------------------------*/
593 class TextureLevelPyramid
594 {
595 public:
596 									TextureLevelPyramid	(const TextureFormat& format, int numLevels);
597 									TextureLevelPyramid	(const TextureLevelPyramid& other);
598 									~TextureLevelPyramid(void);
599 
getFormat(void) const600 	const TextureFormat&			getFormat			(void) const			{ return m_format;					}
getNumLevels(void) const601 	int								getNumLevels		(void) const			{ return (int)m_access.size();		}
602 
isLevelEmpty(int levelNdx) const603 	bool							isLevelEmpty		(int levelNdx) const	{ DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[(size_t)levelNdx].empty();	}
getLevel(int levelNdx) const604 	const ConstPixelBufferAccess&	getLevel			(int levelNdx) const	{ DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_access[(size_t)levelNdx];			}
getLevel(int levelNdx)605 	const PixelBufferAccess&		getLevel			(int levelNdx)			{ DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_access[(size_t)levelNdx];			}
606 
getLevels(void) const607 	const ConstPixelBufferAccess*	getLevels			(void) const			{ return &m_access[0];				}
getLevels(void)608 	const PixelBufferAccess*		getLevels			(void)					{ return &m_access[0];				}
609 
610 	void							allocLevel			(int levelNdx, int width, int height, int depth);
611 	void							clearLevel			(int levelNdx);
612 
613 	TextureLevelPyramid&			operator=			(const TextureLevelPyramid& other);
614 
615 private:
616 	typedef de::ArrayBuffer<deUint8> LevelData;
617 
618 	TextureFormat					m_format;
619 	std::vector<LevelData>			m_data;
620 	std::vector<PixelBufferAccess>	m_access;
621 } DE_WARN_UNUSED_TYPE;
622 
623 /*--------------------------------------------------------------------*//*!
624  * \brief 2D Texture reference implementation
625  *//*--------------------------------------------------------------------*/
626 class Texture2D : private TextureLevelPyramid
627 {
628 public:
629 						Texture2D		(const TextureFormat& format, int width, int height, bool es2 = false);
630 						Texture2D		(const TextureFormat& format, int width, int height, int mipmaps);
631 						Texture2D		(const Texture2D& other);
632 						~Texture2D		(void);
633 
getWidth(void) const634 	int					getWidth		(void) const	{ return m_width;	}
getHeight(void) const635 	int					getHeight		(void) const	{ return m_height;	}
getView(void) const636 	const Texture2DView&			getView			(void) const	{ return m_view;	}
isYUVTextureUsed(void) const637 	bool					isYUVTextureUsed	(void) const	{ return m_yuvTextureUsed;}
638 	void					allocLevel		(int levelNdx);
639 
640 	// Sampling
641 	Vec4					sample			(const Sampler& sampler, float s, float t, float lod) const;
642 	Vec4					sampleOffset		(const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
643 	float					sampleCompare		(const Sampler& sampler, float ref, float s, float t, float lod) const;
644 	float					sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
645 
646 	Vec4					gatherOffsets		(const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
647 	Vec4					gatherOffsetsCompare	(const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
648 
649 	using TextureLevelPyramid::getFormat;
650 	using TextureLevelPyramid::getNumLevels;
651 	using TextureLevelPyramid::getLevel;
652 	using TextureLevelPyramid::clearLevel;
653 	using TextureLevelPyramid::isLevelEmpty;
654 
655 	Texture2D&						operator=			(const Texture2D& other);
656 	//whether this is a yuv format texture tests
657 	bool							m_yuvTextureUsed;
operator Texture2DView(void) const658 	operator Texture2DView (void) const { return m_view; }
659 
660 private:
661 	int							m_width;
662 	int							m_height;
663 	Texture2DView						m_view;
664 } DE_WARN_UNUSED_TYPE;
665 
sample(const Sampler & sampler,float s,float t,float lod) const666 inline Vec4 Texture2D::sample (const Sampler& sampler, float s, float t, float lod) const
667 {
668 	return m_view.sample(sampler, s, t, lod);
669 }
670 
sampleOffset(const Sampler & sampler,float s,float t,float lod,const IVec2 & offset) const671 inline Vec4 Texture2D::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
672 {
673 	return m_view.sampleOffset(sampler, s, t, lod, offset);
674 }
675 
sampleCompare(const Sampler & sampler,float ref,float s,float t,float lod) const676 inline float Texture2D::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
677 {
678 	return m_view.sampleCompare(sampler, ref, s, t, lod);
679 }
680 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float lod,const IVec2 & offset) const681 inline float Texture2D::sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
682 {
683 	return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
684 }
685 
gatherOffsets(const Sampler & sampler,float s,float t,int componentNdx,const IVec2 (& offsets)[4]) const686 inline Vec4 Texture2D::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
687 {
688 	return m_view.gatherOffsets(sampler, s, t, componentNdx, offsets);
689 }
690 
gatherOffsetsCompare(const Sampler & sampler,float ref,float s,float t,const IVec2 (& offsets)[4]) const691 inline Vec4 Texture2D::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
692 {
693 	return m_view.gatherOffsetsCompare(sampler, ref, s, t, offsets);
694 }
695 
696 /*--------------------------------------------------------------------*//*!
697  * \brief Cube Map Texture View
698  *//*--------------------------------------------------------------------*/
699 class TextureCubeView
700 {
701 public:
702 									TextureCubeView		(void);
703 									TextureCubeView		(int numLevels, const ConstPixelBufferAccess* const (&levels)[CUBEFACE_LAST], bool es2 = false);
704 
getNumLevels(void) const705 	int								getNumLevels		(void) const	{ return m_numLevels;										}
isES2(void) const706 	bool								isES2					(void) const	{ return m_es2;												}
getSize(void) const707 	int								getSize				(void) const	{ return m_numLevels > 0 ? m_levels[0][0].getWidth() : 0;	}
getLevelFace(int ndx,CubeFace face) const708 	const ConstPixelBufferAccess&	getLevelFace		(int ndx, CubeFace face) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[face][ndx];	}
getFaceLevels(CubeFace face) const709 	const ConstPixelBufferAccess*	getFaceLevels		(CubeFace face) const			{ return m_levels[face];					}
710 
711 	Vec4							sample				(const Sampler& sampler, float s, float t, float p, float lod) const;
712 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
713 
714 	Vec4							gather				(const Sampler& sampler, float s, float t, float r, int componentNdx) const;
715 	Vec4							gatherCompare		(const Sampler& sampler, float ref, float s, float t, float r) const;
716 
717 protected:
718 	int								m_numLevels;
719 	const ConstPixelBufferAccess*	m_levels[CUBEFACE_LAST];
720 	bool								m_es2;
721 } DE_WARN_UNUSED_TYPE;
722 
723 /*--------------------------------------------------------------------*//*!
724  * \brief Cube Map Texture reference implementation
725  *//*--------------------------------------------------------------------*/
726 class TextureCube
727 {
728 public:
729 									TextureCube			(const TextureFormat& format, int size, bool es2 = false);
730 									TextureCube			(const TextureCube& other);
731 									~TextureCube		(void);
732 
getFormat(void) const733 	const TextureFormat&			getFormat			(void) const	{ return m_format;	}
getSize(void) const734 	int								getSize				(void) const	{ return m_size;	}
getView(void) const735 	const TextureCubeView&		getView				(void) const	{ return m_view;	}
736 
getNumLevels(void) const737 	int								getNumLevels		(void) const					{ return (int)m_access[0].size();	}
getLevelFace(int ndx,CubeFace face) const738 	const ConstPixelBufferAccess&	getLevelFace		(int ndx, CubeFace face) const	{ DE_ASSERT(de::inBounds(ndx, 0, getNumLevels())); return m_access[face][(size_t)ndx];	}
getLevelFace(int ndx,CubeFace face)739 	const PixelBufferAccess&		getLevelFace		(int ndx, CubeFace face)		{ DE_ASSERT(de::inBounds(ndx, 0, getNumLevels())); return m_access[face][(size_t)ndx];	}
740 
741 	void							allocLevel			(CubeFace face, int levelNdx);
742 	void							clearLevel			(CubeFace face, int levelNdx);
isLevelEmpty(CubeFace face,int levelNdx) const743 	bool							isLevelEmpty		(CubeFace face, int levelNdx) const	{ DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[face][(size_t)levelNdx].empty();	}
744 
745 	Vec4							sample				(const Sampler& sampler, float s, float t, float p, float lod) const;
746 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
747 
748 	Vec4							gather				(const Sampler& sampler, float s, float t, float r, int componentNdx) const;
749 	Vec4							gatherCompare		(const Sampler& sampler, float ref, float s, float t, float r) const;
750 
751 	TextureCube&					operator=			(const TextureCube& other);
752 
operator TextureCubeView(void) const753 	operator TextureCubeView (void) const { return m_view; }
754 
755 private:
756 	typedef de::ArrayBuffer<deUint8> LevelData;
757 
758 	TextureFormat					m_format;
759 	int								m_size;
760 	std::vector<LevelData>			m_data[CUBEFACE_LAST];
761 	std::vector<PixelBufferAccess>	m_access[CUBEFACE_LAST];
762 	TextureCubeView					m_view;
763 } DE_WARN_UNUSED_TYPE;
764 
sample(const Sampler & sampler,float s,float t,float p,float lod) const765 inline Vec4 TextureCube::sample (const Sampler& sampler, float s, float t, float p, float lod) const
766 {
767 	return m_view.sample(sampler, s, t, p, lod);
768 }
769 
sampleCompare(const Sampler & sampler,float ref,float s,float t,float r,float lod) const770 inline float TextureCube::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
771 {
772 	return m_view.sampleCompare(sampler, ref, s, t, r, lod);
773 }
774 
gather(const Sampler & sampler,float s,float t,float r,int componentNdx) const775 inline Vec4 TextureCube::gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const
776 {
777 	return m_view.gather(sampler, s, t, r, componentNdx);
778 }
779 
gatherCompare(const Sampler & sampler,float ref,float s,float t,float r) const780 inline Vec4 TextureCube::gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const
781 {
782 	return m_view.gatherCompare(sampler, ref, s, t, r);
783 }
784 
785 /*--------------------------------------------------------------------*//*!
786  * \brief 1D Texture View
787  *//*--------------------------------------------------------------------*/
788 class Texture1DView
789 {
790 public:
791 									Texture1DView		(int numLevels, const ConstPixelBufferAccess* levels, bool es2);
792 
getNumLevels(void) const793 	int								getNumLevels		(void) const	{ return m_numLevels;										}
getWidth(void) const794 	int								getWidth			(void) const	{ return m_numLevels > 0 ? m_levels[0].getWidth()	: 0;	}
getLevel(int ndx) const795 	const ConstPixelBufferAccess&	getLevel			(int ndx) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];	}
getLevels(void) const796 	const ConstPixelBufferAccess*	getLevels			(void) const	{ return m_levels;											}
isES2(void) const797 	bool								isES2					(void) const	{ return false;												}
798 
799 	Vec4							sample				(const Sampler& sampler, float s, float lod) const;
800 	Vec4							sampleOffset		(const Sampler& sampler, float s, float lod, deInt32 offset) const;
801 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float lod) const;
802 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const;
803 
804 protected:
805 	int								m_numLevels;
806 	const ConstPixelBufferAccess*	m_levels;
807 } DE_WARN_UNUSED_TYPE;
808 
Texture1DView(int numLevels,const ConstPixelBufferAccess * levels,bool es2 DE_UNUSED_ATTR=false)809 inline Texture1DView::Texture1DView (int numLevels, const ConstPixelBufferAccess* levels, bool es2 DE_UNUSED_ATTR = false)
810 	: m_numLevels	(numLevels)
811 	, m_levels		(levels)
812 {
813 	DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
814 }
815 
sample(const Sampler & sampler,float s,float lod) const816 inline Vec4 Texture1DView::sample (const Sampler& sampler, float s, float lod) const
817 {
818 	return sampleLevelArray1D(m_levels, m_numLevels, sampler, s, 0 /* depth */, lod);
819 }
820 
sampleOffset(const Sampler & sampler,float s,float lod,deInt32 offset) const821 inline Vec4 Texture1DView::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
822 {
823 	return sampleLevelArray1DOffset(m_levels, m_numLevels, sampler, s, lod, IVec2(offset, 0));
824 }
825 
sampleCompare(const Sampler & sampler,float ref,float s,float lod) const826 inline float Texture1DView::sampleCompare (const Sampler& sampler, float ref, float s, float lod) const
827 {
828 	return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(0, 0));
829 }
830 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float lod,deInt32 offset) const831 inline float Texture1DView::sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const
832 {
833 	return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(offset, 0));
834 }
835 
836 /*--------------------------------------------------------------------*//*!
837  * \brief 1D Texture reference implementation
838  *//*--------------------------------------------------------------------*/
839 class Texture1D : private TextureLevelPyramid
840 {
841 public:
842 									Texture1D			(const TextureFormat& format, int width);
843 									Texture1D			(const Texture1D& other);
844 									~Texture1D			(void);
845 
getWidth(void) const846 	int								getWidth			(void) const	{ return m_width;	}
getView(void) const847 	const Texture1DView&			getView				(void) const	{ return m_view;	}
848 
849 	void							allocLevel			(int levelNdx);
850 
851 	// Sampling
852 	Vec4							sample				(const Sampler& sampler, float s, float lod) const;
853 	Vec4							sampleOffset		(const Sampler& sampler, float s, float lod, deInt32 offset) const;
854 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float lod) const;
855 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const;
856 
857 	using TextureLevelPyramid::getFormat;
858 	using TextureLevelPyramid::getNumLevels;
859 	using TextureLevelPyramid::getLevel;
860 	using TextureLevelPyramid::clearLevel;
861 	using TextureLevelPyramid::isLevelEmpty;
862 
863 	Texture1D&						operator=			(const Texture1D& other);
864 
operator Texture1DView(void) const865 	operator Texture1DView (void) const { return m_view; }
866 
867 private:
868 	int								m_width;
869 	Texture1DView					m_view;
870 } DE_WARN_UNUSED_TYPE;
871 
sample(const Sampler & sampler,float s,float lod) const872 inline Vec4 Texture1D::sample (const Sampler& sampler, float s, float lod) const
873 {
874 	return m_view.sample(sampler, s, lod);
875 }
876 
sampleOffset(const Sampler & sampler,float s,float lod,deInt32 offset) const877 inline Vec4 Texture1D::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
878 {
879 	return m_view.sampleOffset(sampler, s, lod, offset);
880 }
881 
sampleCompare(const Sampler & sampler,float ref,float s,float lod) const882 inline float Texture1D::sampleCompare (const Sampler& sampler, float ref, float s, float lod) const
883 {
884 	return m_view.sampleCompare(sampler, ref, s, lod);
885 }
886 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float lod,deInt32 offset) const887 inline float Texture1D::sampleCompareOffset	(const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const
888 {
889 	return m_view.sampleCompareOffset(sampler, ref, s, lod, offset);
890 }
891 
892 /*--------------------------------------------------------------------*//*!
893  * \brief 1D Array Texture View
894  *//*--------------------------------------------------------------------*/
895 class Texture1DArrayView
896 {
897 public:
898 									Texture1DArrayView	(int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false);
899 
getWidth(void) const900 	int								getWidth			(void) const	{ return m_numLevels > 0 ? m_levels[0].getWidth()	: 0;	}
getNumLayers(void) const901 	int								getNumLayers		(void) const	{ return m_numLevels > 0 ? m_levels[0].getHeight()	: 0;	}
getNumLevels(void) const902 	int								getNumLevels		(void) const	{ return m_numLevels;										}
getLevel(int ndx) const903 	const ConstPixelBufferAccess&	getLevel			(int ndx) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];	}
getLevels(void) const904 	const ConstPixelBufferAccess*	getLevels			(void) const	{ return m_levels;											}
isES2(void) const905 	bool								isES2						(void) const	{ return false;												}
906 
907 	Vec4							sample				(const Sampler& sampler, float s, float t, float lod) const;
908 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
909 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float lod) const;
910 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
911 
912 protected:
913 	int								selectLayer			(float r) const;
914 
915 	int								m_numLevels;
916 	const ConstPixelBufferAccess*	m_levels;
917 } DE_WARN_UNUSED_TYPE;
918 
919 /*--------------------------------------------------------------------*//*!
920  * \brief 1D Array Texture reference implementation
921  *//*--------------------------------------------------------------------*/
922 class Texture1DArray : private TextureLevelPyramid
923 {
924 public:
925 									Texture1DArray		(const TextureFormat& format, int width, int numLayers);
926 									Texture1DArray		(const Texture1DArray& other);
927 									~Texture1DArray		(void);
928 
getWidth(void) const929 	int								getWidth			(void) const	{ return m_width;		}
getNumLayers(void) const930 	int								getNumLayers		(void) const	{ return m_numLayers;	}
931 
932 	void							allocLevel			(int levelNdx);
933 
934 	using TextureLevelPyramid::getFormat;
935 	using TextureLevelPyramid::getNumLevels;
936 	using TextureLevelPyramid::getLevel;
937 	using TextureLevelPyramid::clearLevel;
938 	using TextureLevelPyramid::isLevelEmpty;
939 
940 	Vec4							sample				(const Sampler& sampler, float s, float t, float lod) const;
941 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
942 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float lod) const;
943 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
944 
945 	Texture1DArray&					operator=			(const Texture1DArray& other);
946 
operator Texture1DArrayView(void) const947 	operator Texture1DArrayView (void) const { return m_view; }
948 
949 private:
950 	int								m_width;
951 	int								m_numLayers;
952 	Texture1DArrayView				m_view;
953 } DE_WARN_UNUSED_TYPE;
954 
sample(const Sampler & sampler,float s,float t,float lod) const955 inline Vec4 Texture1DArray::sample (const Sampler& sampler, float s, float t, float lod) const
956 {
957 	return m_view.sample(sampler, s, t, lod);
958 }
959 
sampleOffset(const Sampler & sampler,float s,float t,float lod,deInt32 offset) const960 inline Vec4 Texture1DArray::sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const
961 {
962 	return m_view.sampleOffset(sampler, s, t, lod, offset);
963 }
964 
sampleCompare(const Sampler & sampler,float ref,float s,float t,float lod) const965 inline float Texture1DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
966 {
967 	return m_view.sampleCompare(sampler, ref, s, t, lod);
968 }
969 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float lod,deInt32 offset) const970 inline float Texture1DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const
971 {
972 	return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
973 }
974 
975 /*--------------------------------------------------------------------*//*!
976  * \brief 2D Array Texture View
977  *//*--------------------------------------------------------------------*/
978 class Texture2DArrayView
979 {
980 public:
981 									Texture2DArrayView	(int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false);
982 
getWidth(void) const983 	int								getWidth			(void) const	{ return m_numLevels > 0 ? m_levels[0].getWidth()	: 0;	}
getHeight(void) const984 	int								getHeight			(void) const	{ return m_numLevels > 0 ? m_levels[0].getHeight()	: 0;	}
getNumLayers(void) const985 	int								getNumLayers		(void) const	{ return m_numLevels > 0 ? m_levels[0].getDepth()	: 0;	}
getNumLevels(void) const986 	int								getNumLevels		(void) const	{ return m_numLevels;										}
getLevel(int ndx) const987 	const ConstPixelBufferAccess&	getLevel			(int ndx) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];	}
getLevels(void) const988 	const ConstPixelBufferAccess*	getLevels			(void) const	{ return m_levels;											}
isES2(void) const989 	bool								isES2						(void) const	{ return false;												}
990 
991 	Vec4							sample				(const Sampler& sampler, float s, float t, float r, float lod) const;
992 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
993 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
994 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
995 
996 	Vec4							gatherOffsets		(const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
997 	Vec4							gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
998 
999 protected:
1000 	int								selectLayer			(float r) const;
1001 
1002 	int								m_numLevels;
1003 	const ConstPixelBufferAccess*	m_levels;
1004 } DE_WARN_UNUSED_TYPE;
1005 
1006 /*--------------------------------------------------------------------*//*!
1007  * \brief 2D Array Texture reference implementation
1008  *//*--------------------------------------------------------------------*/
1009 class Texture2DArray : private TextureLevelPyramid
1010 {
1011 public:
1012 									Texture2DArray		(const TextureFormat& format, int width, int height, int numLayers);
1013 									Texture2DArray		(const Texture2DArray& other);
1014 									~Texture2DArray		(void);
1015 
getWidth(void) const1016 	int								getWidth			(void) const	{ return m_width;		}
getHeight(void) const1017 	int								getHeight			(void) const	{ return m_height;		}
getNumLayers(void) const1018 	int								getNumLayers		(void) const	{ return m_numLayers;	}
1019 
1020 	void							allocLevel			(int levelNdx);
1021 
1022 	using TextureLevelPyramid::getFormat;
1023 	using TextureLevelPyramid::getNumLevels;
1024 	using TextureLevelPyramid::getLevel;
1025 	using TextureLevelPyramid::clearLevel;
1026 	using TextureLevelPyramid::isLevelEmpty;
1027 
1028 	Vec4							sample				(const Sampler& sampler, float s, float t, float r, float lod) const;
1029 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
1030 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
1031 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
1032 
1033 	Vec4							gatherOffsets		(const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
1034 	Vec4							gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
1035 
1036 	Texture2DArray&					operator=			(const Texture2DArray& other);
1037 
operator Texture2DArrayView(void) const1038 	operator Texture2DArrayView (void) const { return m_view; }
1039 
1040 private:
1041 	int								m_width;
1042 	int								m_height;
1043 	int								m_numLayers;
1044 	Texture2DArrayView				m_view;
1045 } DE_WARN_UNUSED_TYPE;
1046 
sample(const Sampler & sampler,float s,float t,float r,float lod) const1047 inline Vec4 Texture2DArray::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1048 {
1049 	return m_view.sample(sampler, s, t, r, lod);
1050 }
1051 
sampleOffset(const Sampler & sampler,float s,float t,float r,float lod,const IVec2 & offset) const1052 inline Vec4 Texture2DArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const
1053 {
1054 	return m_view.sampleOffset(sampler, s, t, r, lod, offset);
1055 }
1056 
sampleCompare(const Sampler & sampler,float ref,float s,float t,float r,float lod) const1057 inline float Texture2DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
1058 {
1059 	return m_view.sampleCompare(sampler, ref, s, t, r, lod);
1060 }
1061 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float r,float lod,const IVec2 & offset) const1062 inline float Texture2DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const
1063 {
1064 	return m_view.sampleCompareOffset(sampler, ref, s, t, r, lod, offset);
1065 }
1066 
gatherOffsets(const Sampler & sampler,float s,float t,float r,int componentNdx,const IVec2 (& offsets)[4]) const1067 inline Vec4 Texture2DArray::gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const
1068 {
1069 	return m_view.gatherOffsets(sampler, s, t, r, componentNdx, offsets);
1070 }
1071 
gatherOffsetsCompare(const Sampler & sampler,float ref,float s,float t,float r,const IVec2 (& offsets)[4]) const1072 inline Vec4 Texture2DArray::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const
1073 {
1074 	return m_view.gatherOffsetsCompare(sampler, ref, s, t, r, offsets);
1075 }
1076 
1077 /*--------------------------------------------------------------------*//*!
1078  * \brief 3D Texture View
1079  *//*--------------------------------------------------------------------*/
1080 class Texture3DView
1081 {
1082 public:
1083 									Texture3DView		(int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false);
1084 
getWidth(void) const1085 	int								getWidth			(void) const	{ return m_numLevels > 0 ? m_levels[0].getWidth()	: 0;	}
getHeight(void) const1086 	int								getHeight			(void) const	{ return m_numLevels > 0 ? m_levels[0].getHeight()	: 0;	}
getDepth(void) const1087 	int								getDepth			(void) const	{ return m_numLevels > 0 ? m_levels[0].getDepth()	: 0;	}
getNumLevels(void) const1088 	int								getNumLevels		(void) const	{ return m_numLevels;										}
getLevel(int ndx) const1089 	const ConstPixelBufferAccess&	getLevel			(int ndx) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];	}
getLevels(void) const1090 	const ConstPixelBufferAccess*	getLevels			(void) const	{ return m_levels;											}
isES2(void) const1091 	bool								isES2						(void) const	{ return false;												}
1092 
1093 	Vec4							sample				(const Sampler& sampler, float s, float t, float r, float lod) const;
1094 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
1095 
1096 protected:
1097 	int								m_numLevels;
1098 	const ConstPixelBufferAccess*	m_levels;
1099 } DE_WARN_UNUSED_TYPE;
1100 
sample(const Sampler & sampler,float s,float t,float r,float lod) const1101 inline Vec4 Texture3DView::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1102 {
1103 	return sampleLevelArray3D(m_levels, m_numLevels, sampler, s, t, r, lod);
1104 }
1105 
sampleOffset(const Sampler & sampler,float s,float t,float r,float lod,const IVec3 & offset) const1106 inline Vec4 Texture3DView::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
1107 {
1108 	return sampleLevelArray3DOffset(m_levels, m_numLevels, sampler, s, t, r, lod, offset);
1109 }
1110 
1111 /*--------------------------------------------------------------------*//*!
1112  * \brief 3D Texture reference implementation
1113  *//*--------------------------------------------------------------------*/
1114 class Texture3D : private TextureLevelPyramid
1115 {
1116 public:
1117 									Texture3D			(const TextureFormat& format, int width, int height, int depth);
1118 									Texture3D			(const Texture3D& other);
1119 									~Texture3D			(void);
1120 
getWidth(void) const1121 	int								getWidth			(void) const	{ return m_width;	}
getHeight(void) const1122 	int								getHeight			(void) const	{ return m_height;	}
getDepth(void) const1123 	int								getDepth			(void) const	{ return m_depth;	}
1124 
1125 	void							allocLevel			(int levelNdx);
1126 
1127 	using TextureLevelPyramid::getFormat;
1128 	using TextureLevelPyramid::getNumLevels;
1129 	using TextureLevelPyramid::getLevel;
1130 	using TextureLevelPyramid::clearLevel;
1131 	using TextureLevelPyramid::isLevelEmpty;
1132 
1133 	Vec4							sample				(const Sampler& sampler, float s, float t, float r, float lod) const;
1134 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
1135 
1136 	Texture3D&						operator=			(const Texture3D& other);
1137 
operator Texture3DView(void) const1138 	operator Texture3DView (void) const { return m_view; }
1139 
1140 private:
1141 	int								m_width;
1142 	int								m_height;
1143 	int								m_depth;
1144 	Texture3DView					m_view;
1145 } DE_WARN_UNUSED_TYPE;
1146 
sample(const Sampler & sampler,float s,float t,float r,float lod) const1147 inline Vec4 Texture3D::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1148 {
1149 	return m_view.sample(sampler, s, t, r, lod);
1150 }
1151 
sampleOffset(const Sampler & sampler,float s,float t,float r,float lod,const IVec3 & offset) const1152 inline Vec4 Texture3D::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
1153 {
1154 	return m_view.sampleOffset(sampler, s, t, r, lod, offset);
1155 }
1156 
1157 /*--------------------------------------------------------------------*//*!
1158  * \brief Cube Map Array Texture View
1159  *//*--------------------------------------------------------------------*/
1160 class TextureCubeArrayView
1161 {
1162 public:
1163 									TextureCubeArrayView	(int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false);
1164 
getSize(void) const1165 	int								getSize					(void) const	{ return m_numLevels > 0 ? m_levels[0].getWidth()	: 0;	}
getDepth(void) const1166 	int								getDepth				(void) const	{ return m_numLevels > 0 ? m_levels[0].getDepth()	: 0;	}
getNumLayers(void) const1167 	int								getNumLayers			(void) const	{ return getDepth()	/ 6;	}
getNumLevels(void) const1168 	int								getNumLevels			(void) const	{ return m_numLevels;										}
getLevel(int ndx) const1169 	const ConstPixelBufferAccess&	getLevel				(int ndx) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];	}
getLevels(void) const1170 	const ConstPixelBufferAccess*	getLevels				(void) const	{ return m_levels;											}
isES2(void) const1171 	bool									isES2						(void) const	{ return false;												}
1172 
1173 	Vec4							sample					(const Sampler& sampler, float s, float t, float r, float q, float lod) const;
1174 	Vec4							sampleOffset			(const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1175 	float							sampleCompare			(const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
1176 	float							sampleCompareOffset		(const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1177 
1178 protected:
1179 	int								selectLayer				(float q) const;
1180 
1181 	int								m_numLevels;
1182 	const ConstPixelBufferAccess*	m_levels;
1183 } DE_WARN_UNUSED_TYPE;
1184 
1185 /*--------------------------------------------------------------------*//*!
1186  * \brief Cube Map Array Texture reference implementation
1187  *//*--------------------------------------------------------------------*/
1188 class TextureCubeArray : private TextureLevelPyramid
1189 {
1190 public:
1191 									TextureCubeArray	(const TextureFormat& format, int size, int depth);
1192 									TextureCubeArray	(const TextureCubeArray& other);
1193 									~TextureCubeArray	(void);
1194 
getSize(void) const1195 	int								getSize				(void) const	{ return m_size;	}
getDepth(void) const1196 	int								getDepth			(void) const	{ return m_depth;	}
1197 
1198 	void							allocLevel			(int levelNdx);
1199 
1200 	using TextureLevelPyramid::getFormat;
1201 	using TextureLevelPyramid::getNumLevels;
1202 	using TextureLevelPyramid::getLevel;
1203 	using TextureLevelPyramid::clearLevel;
1204 	using TextureLevelPyramid::isLevelEmpty;
1205 
1206 	Vec4							sample				(const Sampler& sampler, float s, float t, float r, float q, float lod) const;
1207 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1208 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
1209 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1210 
1211 	TextureCubeArray&				operator=			(const TextureCubeArray& other);
1212 
operator TextureCubeArrayView(void) const1213 	operator TextureCubeArrayView (void) const { return m_view; }
1214 
1215 private:
1216 	int								m_size;
1217 	int								m_depth;
1218 	TextureCubeArrayView			m_view;
1219 } DE_WARN_UNUSED_TYPE;
1220 
sample(const Sampler & sampler,float s,float t,float r,float q,float lod) const1221 inline Vec4 TextureCubeArray::sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const
1222 {
1223 	return m_view.sample(sampler, s, t, r, q, lod);
1224 }
1225 
sampleOffset(const Sampler & sampler,float s,float t,float r,float q,float lod,const IVec2 & offset) const1226 inline Vec4 TextureCubeArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const
1227 {
1228 	return m_view.sampleOffset(sampler, s, t, r, q, lod, offset);
1229 }
1230 
sampleCompare(const Sampler & sampler,float ref,float s,float t,float r,float q,float lod) const1231 inline float TextureCubeArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const
1232 {
1233 	return m_view.sampleCompare(sampler, ref, s, t, r, q, lod);
1234 }
1235 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float r,float q,float lod,const IVec2 & offset) const1236 inline float TextureCubeArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const
1237 {
1238 	return m_view.sampleCompareOffset(sampler, ref, s, t, r, q, lod, offset);
1239 }
1240 
1241 // Stream operators.
1242 std::ostream&		operator<<		(std::ostream& str, TextureFormat::ChannelOrder order);
1243 std::ostream&		operator<<		(std::ostream& str, TextureFormat::ChannelType type);
1244 std::ostream&		operator<<		(std::ostream& str, TextureFormat format);
1245 std::ostream&		operator<<		(std::ostream& str, CubeFace face);
1246 std::ostream&		operator<<		(std::ostream& str, const ConstPixelBufferAccess& access);
1247 
1248 } // tcu
1249 
1250 #endif // _TCUTEXTURE_HPP
1251