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 		BGR,
56 		BGRA,
57 
58 		sR,
59 		sRG,
60 		sRGB,
61 		sRGBA,
62 		sBGR,
63 		sBGRA,
64 
65 		D,
66 		S,
67 		DS,
68 
69 		CHANNELORDER_LAST
70 	};
71 
72 	enum ChannelType
73 	{
74 		SNORM_INT8 = 0,
75 		SNORM_INT16,
76 		SNORM_INT32,
77 		UNORM_INT8,
78 		UNORM_INT16,
79 		UNORM_INT24,
80 		UNORM_INT32,
81 		UNORM_BYTE_44,
82 		UNORM_SHORT_565,
83 		UNORM_SHORT_555,
84 		UNORM_SHORT_4444,
85 		UNORM_SHORT_5551,
86 		UNORM_SHORT_1555,
87 		UNORM_INT_101010,
88 		SNORM_INT_1010102_REV,
89 		UNORM_INT_1010102_REV,
90 		UNSIGNED_BYTE_44,
91 		UNSIGNED_SHORT_565,
92 		UNSIGNED_SHORT_4444,
93 		UNSIGNED_SHORT_5551,
94 		SIGNED_INT_1010102_REV,
95 		UNSIGNED_INT_1010102_REV,
96 		UNSIGNED_INT_11F_11F_10F_REV,
97 		UNSIGNED_INT_999_E5_REV,
98 		UNSIGNED_INT_16_8_8,
99 		UNSIGNED_INT_24_8,
100 		UNSIGNED_INT_24_8_REV,
101 		SIGNED_INT8,
102 		SIGNED_INT16,
103 		SIGNED_INT32,
104 		SIGNED_INT64,
105 		UNSIGNED_INT8,
106 		UNSIGNED_INT16,
107 		UNSIGNED_INT24,
108 		UNSIGNED_INT32,
109 		UNSIGNED_INT64,
110 		HALF_FLOAT,
111 		FLOAT,
112 		FLOAT64,
113 		FLOAT_UNSIGNED_INT_24_8_REV,
114 
115 		UNORM_SHORT_10,
116 		UNORM_SHORT_12,
117 
118 		USCALED_INT8,
119 		USCALED_INT16,
120 		SSCALED_INT8,
121 		SSCALED_INT16,
122 		USCALED_INT_1010102_REV,
123 		SSCALED_INT_1010102_REV,
124 
125 		CHANNELTYPE_LAST
126 	};
127 
128 	ChannelOrder	order;
129 	ChannelType		type;
130 
TextureFormat(ChannelOrder order_,ChannelType type_)131 	TextureFormat (ChannelOrder order_, ChannelType type_)
132 		: order	(order_)
133 		, type	(type_)
134 	{
135 	}
136 
TextureFormat(void)137 	TextureFormat (void)
138 		: order	(CHANNELORDER_LAST)
139 		, type	(CHANNELTYPE_LAST)
140 	{
141 	}
142 
143 	int getPixelSize (void) const; //!< Deprecated, use tcu::getPixelSize(fmt)
144 
operator ==(const TextureFormat & other) const145 	bool operator== (const TextureFormat& other) const { return !(*this != other); }
operator !=(const TextureFormat & other) const146 	bool operator!= (const TextureFormat& other) const
147 	{
148 		return (order != other.order || type != other.type);
149 	}
150 } DE_WARN_UNUSED_TYPE;
151 
152 bool	isValid				(TextureFormat format);
153 int		getPixelSize		(TextureFormat format);
154 int		getNumUsedChannels	(TextureFormat::ChannelOrder order);
155 int		getChannelSize		(TextureFormat::ChannelType type);
156 
157 /*--------------------------------------------------------------------*//*!
158  * \brief Texture swizzle
159  *//*--------------------------------------------------------------------*/
160 struct TextureSwizzle
161 {
162 	enum Channel
163 	{
164 		// \note CHANNEL_N must equal int N
165 		CHANNEL_0 = 0,
166 		CHANNEL_1,
167 		CHANNEL_2,
168 		CHANNEL_3,
169 
170 		CHANNEL_ZERO,
171 		CHANNEL_ONE,
172 
173 		CHANNEL_LAST
174 	};
175 
176 	Channel components[4];
177 };
178 
179 //! get the swizzle used to expand texture data with a given channel order to RGBA form
180 const TextureSwizzle& getChannelReadSwizzle		(TextureFormat::ChannelOrder order);
181 
182 //! get the swizzle used to narrow RGBA form data to native texture data with a given channel order
183 const TextureSwizzle& getChannelWriteSwizzle	(TextureFormat::ChannelOrder order);
184 
185 /*--------------------------------------------------------------------*//*!
186  * \brief Sampling parameters
187  *//*--------------------------------------------------------------------*/
188 class Sampler
189 {
190 public:
191 	enum WrapMode
192 	{
193 		CLAMP_TO_EDGE = 0,	//! Clamp to edge
194 		CLAMP_TO_BORDER,	//! Use border color at edge
195 		REPEAT_GL,			//! Repeat with OpenGL semantics
196 		REPEAT_CL,			//! Repeat with OpenCL semantics
197 		MIRRORED_REPEAT_GL,	//! Mirrored repeat with OpenGL semantics
198 		MIRRORED_REPEAT_CL, //! Mirrored repeat with OpenCL semantics
199 		MIRRORED_ONCE,		//! Mirrored once in negative directions
200 
201 		WRAPMODE_LAST
202 	};
203 
204 	enum FilterMode
205 	{
206 		NEAREST = 0,
207 		LINEAR,
208 		CUBIC,
209 
210 		NEAREST_MIPMAP_NEAREST,
211 		NEAREST_MIPMAP_LINEAR,
212 		LINEAR_MIPMAP_NEAREST,
213 		LINEAR_MIPMAP_LINEAR,
214 		CUBIC_MIPMAP_NEAREST,
215 		CUBIC_MIPMAP_LINEAR,
216 
217 		FILTERMODE_LAST
218 	};
219 
220 	enum ReductionMode
221 	{
222 		WEIGHTED_AVERAGE = 0,
223 		MIN,
224 		MAX,
225 
226 		REDUCTIONMODE_LAST
227 	};
228 
229 	enum CompareMode
230 	{
231 		COMPAREMODE_NONE = 0,
232 		COMPAREMODE_LESS,
233 		COMPAREMODE_LESS_OR_EQUAL,
234 		COMPAREMODE_GREATER,
235 		COMPAREMODE_GREATER_OR_EQUAL,
236 		COMPAREMODE_EQUAL,
237 		COMPAREMODE_NOT_EQUAL,
238 		COMPAREMODE_ALWAYS,
239 		COMPAREMODE_NEVER,
240 
241 		COMPAREMODE_LAST
242 	};
243 
244 	enum DepthStencilMode
245 	{
246 		MODE_DEPTH = 0,
247 		MODE_STENCIL,
248 
249 		MODE_LAST
250 	};
251 
252 	// Wrap control
253 	WrapMode			wrapS;
254 	WrapMode			wrapT;
255 	WrapMode			wrapR;
256 
257 	// Minifcation & magnification
258 	FilterMode			minFilter;
259 	FilterMode			magFilter;
260 
261 	// min/max filtering reduction
262 	ReductionMode		reductionMode;
263 
264 	float				lodThreshold;		// lod <= lodThreshold ? magnified : minified
265 
266 	// Coordinate normalization
267 	bool				normalizedCoords;
268 
269 	// Shadow comparison
270 	CompareMode			compare;
271 	int					compareChannel;
272 
273 	// Border color.
274 	// \note It is setter's responsibility to guarantee that the values are representable
275 	//       in sampled texture's internal format.
276 	// \note It is setter's responsibility to guarantee that the format is compatible with the
277 	//       sampled texture's internal format. Otherwise results are undefined.
278 	rr::GenericVec4		borderColor;
279 
280 	// Seamless cube map filtering
281 	bool				seamlessCubeMap;
282 
283 	// Depth stencil mode
284 	DepthStencilMode	depthStencilMode;
285 
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)286 	Sampler (WrapMode			wrapS_,
287 			 WrapMode			wrapT_,
288 			 WrapMode			wrapR_,
289 			 FilterMode			minFilter_,
290 			 FilterMode			magFilter_,
291 			 float				lodThreshold_		= 0.0f,
292 			 bool				normalizedCoords_	= true,
293 			 CompareMode		compare_			= COMPAREMODE_NONE,
294 			 int				compareChannel_		= 0,
295 			 const Vec4&		borderColor_		= Vec4(0.0f, 0.0f, 0.0f, 0.0f),
296 			 bool				seamlessCubeMap_	= false,
297 			 DepthStencilMode	depthStencilMode_	= MODE_DEPTH,
298 			 ReductionMode		reductionMode_		= WEIGHTED_AVERAGE)
299 		: wrapS				(wrapS_)
300 		, wrapT				(wrapT_)
301 		, wrapR				(wrapR_)
302 		, minFilter			(minFilter_)
303 		, magFilter			(magFilter_)
304 		, reductionMode		(reductionMode_)
305 		, lodThreshold		(lodThreshold_)
306 		, normalizedCoords	(normalizedCoords_)
307 		, compare			(compare_)
308 		, compareChannel	(compareChannel_)
309 		, borderColor		(borderColor_)
310 		, seamlessCubeMap	(seamlessCubeMap_)
311 		, depthStencilMode	(depthStencilMode_)
312 	{
313 	}
314 
Sampler(void)315 	Sampler (void)
316 		: wrapS				(WRAPMODE_LAST)
317 		, wrapT				(WRAPMODE_LAST)
318 		, wrapR				(WRAPMODE_LAST)
319 		, minFilter			(FILTERMODE_LAST)
320 		, magFilter			(FILTERMODE_LAST)
321 		, reductionMode		(REDUCTIONMODE_LAST)
322 		, lodThreshold		(0.0f)
323 		, normalizedCoords	(true)
324 		, compare			(COMPAREMODE_NONE)
325 		, compareChannel	(0)
326 		, borderColor		(Vec4(0.0f, 0.0f, 0.0f, 0.0f))
327 		, seamlessCubeMap	(false)
328 		, depthStencilMode	(MODE_DEPTH)
329 	{
330 	}
331 } DE_WARN_UNUSED_TYPE;
332 
333 // Calculate pitches for pixel data with no padding.
334 IVec3 calculatePackedPitch (const TextureFormat& format, const IVec3& size);
335 
336 class TextureLevel;
337 
338 /*--------------------------------------------------------------------*//*!
339  * \brief Read-only pixel data access
340  *
341  * ConstPixelBufferAccess encapsulates pixel data pointer along with
342  * format and layout information. It can be used for read-only access
343  * to arbitrary pixel buffers.
344  *
345  * Access objects are like iterators or pointers. They can be passed around
346  * as values and are valid as long as the storage doesn't change.
347  *//*--------------------------------------------------------------------*/
348 class ConstPixelBufferAccess
349 {
350 public:
351 							ConstPixelBufferAccess		(void);
352 							ConstPixelBufferAccess		(const TextureLevel& level);
353 							ConstPixelBufferAccess		(const TextureFormat& format, int width, int height, int depth, const void* data);
354 							ConstPixelBufferAccess		(const TextureFormat& format, const IVec3& size, const void* data);
355 							ConstPixelBufferAccess		(const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, const void* data);
356 							ConstPixelBufferAccess		(const TextureFormat& format, const IVec3& size, const IVec3& pitch, const void* data);
357 							ConstPixelBufferAccess		(const TextureFormat& format, const IVec3& size, const IVec3& pitch, const IVec3& divider, const void* data);
358 
getFormat(void) const359 	const TextureFormat&	getFormat					(void) const	{ return m_format;					}
getSize(void) const360 	const IVec3&			getSize						(void) const	{ return m_size;					}
getWidth(void) const361 	int						getWidth					(void) const	{ return m_size.x();				}
getHeight(void) const362 	int						getHeight					(void) const	{ return m_size.y();				}
getDepth(void) const363 	int						getDepth					(void) const	{ return m_size.z();				}
getPixelPitch(void) const364 	int						getPixelPitch				(void) const	{ return m_pitch.x();				}
getRowPitch(void) const365 	int						getRowPitch					(void) const	{ return m_pitch.y();				}
getSlicePitch(void) const366 	int						getSlicePitch				(void) const	{ return m_pitch.z();				}
getPitch(void) const367 	const IVec3&			getPitch					(void) const	{ return m_pitch;					}
getDivider(void) const368 	const IVec3&			getDivider					(void) const	{ return m_divider;					}
369 
getDataPtr(void) const370 	const void*				getDataPtr					(void) const	{ return m_data;					}
getPixelPtr(int x,int y,int z=0) const371 	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(); }
372 
373 	Vec4					getPixel					(int x, int y, int z = 0) const;
374 	IVec4					getPixelInt					(int x, int y, int z = 0) const;
getPixelUint(int x,int y,int z=0) const375 	UVec4					getPixelUint				(int x, int y, int z = 0) const { return getPixelInt(x, y, z).cast<deUint32>(); }
376 
377 	template<typename T>
378 	Vector<T, 4>			getPixelT					(int x, int y, int z = 0) const;
379 
380 	float					getPixDepth					(int x, int y, int z = 0) const;
381 	int						getPixStencil				(int x, int y, int z = 0) const;
382 
383 	Vec4					sample1D					(const Sampler& sampler, Sampler::FilterMode filter, float s, int level) const;
384 	Vec4					sample2D					(const Sampler& sampler, Sampler::FilterMode filter, float s, float t, int depth) const;
385 	Vec4					sample3D					(const Sampler& sampler, Sampler::FilterMode filter, float s, float t, float r) const;
386 
387 	Vec4					sample1DOffset				(const Sampler& sampler, Sampler::FilterMode filter, float s, const IVec2& offset) const;
388 	Vec4					sample2DOffset				(const Sampler& sampler, Sampler::FilterMode filter, float s, float t, const IVec3& offset) const;
389 	Vec4					sample3DOffset				(const Sampler& sampler, Sampler::FilterMode filter, float s, float t, float r, const IVec3& offset) const;
390 
391 	float					sample1DCompare				(const Sampler& sampler, Sampler::FilterMode filter, float ref, float s, const IVec2& offset) const;
392 	float					sample2DCompare				(const Sampler& sampler, Sampler::FilterMode filter, float ref, float s, float t, const IVec3& offset) const;
393 
394 protected:
395 	TextureFormat			m_format;
396 	IVec3					m_size;
397 	IVec3					m_pitch;	//!< (pixelPitch, rowPitch, slicePitch)
398 	IVec3					m_divider;
399 	mutable void*			m_data;
400 } DE_WARN_UNUSED_TYPE;
401 
402 /*--------------------------------------------------------------------*//*!
403  * \brief Read-write pixel data access
404  *
405  * This class extends read-only access object by providing write functionality.
406  *
407  * \note PixelBufferAccess may not have any data members nor add any
408  *		 virtual functions. It must be possible to reinterpret_cast<>
409  *		 PixelBufferAccess to ConstPixelBufferAccess.
410  *//*--------------------------------------------------------------------*/
411 class PixelBufferAccess : public ConstPixelBufferAccess
412 {
413 public:
PixelBufferAccess(void)414 						PixelBufferAccess	(void) {}
415 						PixelBufferAccess	(TextureLevel& level);
416 						PixelBufferAccess	(const TextureFormat& format, int width, int height, int depth, void* data);
417 						PixelBufferAccess	(const TextureFormat& format, const IVec3& size, void* data);
418 						PixelBufferAccess	(const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, void* data);
419 						PixelBufferAccess	(const TextureFormat& format, const IVec3& size, const IVec3& pitch, void* data);
420 						PixelBufferAccess	(const TextureFormat& format, const IVec3& size, const IVec3& pitch, const IVec3& block, void* data);
421 
getDataPtr(void) const422 	void*				getDataPtr			(void) const { return m_data; }
getPixelPtr(int x,int y,int z=0) const423 	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(); }
424 
425 	void				setPixel			(const tcu::Vec4& color, int x, int y, int z = 0) const;
426 	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) const427 	void				setPixel			(const tcu::UVec4& color, int x, int y, int z = 0) const { setPixel(color.cast<int>(), x, y, z); }
428 
429 	void				setPixDepth			(float depth, int x, int y, int z = 0) const;
430 	void				setPixStencil		(int stencil, int x, int y, int z = 0) const;
431 } DE_WARN_UNUSED_TYPE;
432 
433 /*--------------------------------------------------------------------*//*!
434  * \brief Generic pixel data container
435  *
436  * This container supports all valid TextureFormat combinations and
437  * both 2D and 3D textures. To read or manipulate data access object must
438  * be queried using getAccess().
439  *//*--------------------------------------------------------------------*/
440 class TextureLevel
441 {
442 public:
443 								TextureLevel		(void);
444 								TextureLevel		(const TextureFormat& format);
445 								TextureLevel		(const TextureFormat& format, int width, int height, int depth = 1);
446 								~TextureLevel		(void);
447 
getSize(void) const448 	const IVec3&				getSize				(void) const	{ return m_size;		}
getWidth(void) const449 	int							getWidth			(void) const	{ return m_size.x();	}
getHeight(void) const450 	int							getHeight			(void) const	{ return m_size.y();	}
getDepth(void) const451 	int							getDepth			(void) const	{ return m_size.z();	}
isEmpty(void) const452 	bool						isEmpty				(void) const	{ return m_size.x() * m_size.y() * m_size.z() == 0; }
getFormat(void) const453 	const TextureFormat			getFormat			(void) const	{ return m_format;	}
454 
455 	void						setStorage			(const TextureFormat& format, int width, int heigth, int depth = 1);
456 	void						setSize				(int width, int height, int depth = 1);
457 
getAccess(void)458 	PixelBufferAccess			getAccess			(void)			{ return isEmpty() ? PixelBufferAccess() : PixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr());			}
getAccess(void) const459 	ConstPixelBufferAccess		getAccess			(void) const	{ return isEmpty() ? ConstPixelBufferAccess() : ConstPixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr());	}
460 
461 private:
getPtr(void)462 	void*						getPtr				(void)			{ return m_data.getPtr(); }
getPtr(void) const463 	const void*					getPtr				(void) const	{ return m_data.getPtr(); }
464 
465 	TextureFormat				m_format;
466 	IVec3						m_size;
467 	de::ArrayBuffer<deUint8>	m_data;
468 
469 	friend class ConstPixelBufferAccess;
470 } DE_WARN_UNUSED_TYPE;
471 
472 Vec4	sampleLevelArray1D				(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, int level, float lod);
473 Vec4	sampleLevelArray2D				(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, int depth, float lod, bool es2 = false);
474 Vec4	sampleLevelArray3D				(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float r, float lod);
475 
476 Vec4	sampleLevelArray1DOffset		(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float lod, const IVec2& offset);
477 Vec4	sampleLevelArray2DOffset		(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float lod, const IVec3& offset, bool es2 = false);
478 Vec4	sampleLevelArray3DOffset		(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset);
479 
480 float	sampleLevelArray1DCompare		(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float ref, float s, float lod, const IVec2& offset);
481 float	sampleLevelArray2DCompare		(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float ref, float s, float t, float lod, const IVec3& offset);
482 
483 Vec4	gatherArray2DOffsets			(const ConstPixelBufferAccess& src, const Sampler& sampler, float s, float t, int depth, int componentNdx, const IVec2 (&offsets)[4]);
484 Vec4	gatherArray2DOffsetsCompare		(const ConstPixelBufferAccess& src, const Sampler& sampler, float ref, float s, float t, int depth, const IVec2 (&offsets)[4]);
485 
486 enum CubeFace
487 {
488 	CUBEFACE_NEGATIVE_X = 0,
489 	CUBEFACE_POSITIVE_X,
490 	CUBEFACE_NEGATIVE_Y,
491 	CUBEFACE_POSITIVE_Y,
492 	CUBEFACE_NEGATIVE_Z,
493 	CUBEFACE_POSITIVE_Z,
494 
495 	CUBEFACE_LAST
496 };
497 
498 /*--------------------------------------------------------------------*//*!
499  * \brief Coordinates projected onto cube face.
500  *//*--------------------------------------------------------------------*/
501 template<typename T>
502 struct CubeFaceCoords
503 {
504 	CubeFace		face;
505 	T				s;
506 	T				t;
507 
CubeFaceCoordstcu::CubeFaceCoords508 					CubeFaceCoords		(CubeFace face_, T s_, T t_) : face(face_), s(s_), t(t_) {}
CubeFaceCoordstcu::CubeFaceCoords509 					CubeFaceCoords		(CubeFace face_, const Vector<T, 2>& c) : face(face_), s(c.x()), t(c.y()) {}
510 } DE_WARN_UNUSED_TYPE;
511 
512 typedef CubeFaceCoords<float>	CubeFaceFloatCoords;
513 typedef CubeFaceCoords<int>		CubeFaceIntCoords;
514 
515 CubeFace				selectCubeFace			(const Vec3& coords);
516 Vec2					projectToFace			(CubeFace face, const Vec3& coords);
517 CubeFaceFloatCoords		getCubeFaceCoords		(const Vec3& coords);
518 CubeFaceIntCoords		remapCubeEdgeCoords		(const CubeFaceIntCoords& coords, int size);
519 
520 /*--------------------------------------------------------------------*//*!
521  * \brief 1D Texture View
522  *//*--------------------------------------------------------------------*/
523 class Texture1DView
524 {
525 public:
526 									Texture1DView		(int numLevels, const ConstPixelBufferAccess* levels, bool es2);
527 
getNumLevels(void) const528 	int								getNumLevels		(void) const	{ return m_numLevels;										}
getWidth(void) const529 	int								getWidth			(void) const	{ return m_numLevels > 0 ? m_levels[0].getWidth()	: 0;	}
getLevel(int ndx) const530 	const ConstPixelBufferAccess&	getLevel			(int ndx) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];	}
getLevels(void) const531 	const ConstPixelBufferAccess*	getLevels			(void) const	{ return m_levels;											}
isES2(void) const532 	bool								isES2					(void) const	{ return false;												}
533 
534 	Vec4							sample				(const Sampler& sampler, float s, float lod) const;
535 	Vec4							sampleOffset		(const Sampler& sampler, float s, float lod, deInt32 offset) const;
536 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float lod) const;
537 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const;
538 
539 protected:
540 	int								m_numLevels;
541 	const ConstPixelBufferAccess*	m_levels;
542 } DE_WARN_UNUSED_TYPE;
543 
Texture1DView(int numLevels,const ConstPixelBufferAccess * levels,bool es2 DE_UNUSED_ATTR=false)544 inline Texture1DView::Texture1DView (int numLevels, const ConstPixelBufferAccess* levels, bool es2 DE_UNUSED_ATTR = false)
545 	: m_numLevels	(numLevels)
546 	, m_levels		(levels)
547 {
548 	DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
549 }
550 
sample(const Sampler & sampler,float s,float lod) const551 inline Vec4 Texture1DView::sample (const Sampler& sampler, float s, float lod) const
552 {
553 	return sampleLevelArray1D(m_levels, m_numLevels, sampler, s, 0 /* depth */, lod);
554 }
555 
sampleOffset(const Sampler & sampler,float s,float lod,deInt32 offset) const556 inline Vec4 Texture1DView::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
557 {
558 	return sampleLevelArray1DOffset(m_levels, m_numLevels, sampler, s, lod, IVec2(offset, 0));
559 }
560 
sampleCompare(const Sampler & sampler,float ref,float s,float lod) const561 inline float Texture1DView::sampleCompare (const Sampler& sampler, float ref, float s, float lod) const
562 {
563 	return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(0, 0));
564 }
565 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float lod,deInt32 offset) const566 inline float Texture1DView::sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const
567 {
568 	return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(offset, 0));
569 }
570 
571 /*--------------------------------------------------------------------*//*!
572  * \brief 2D Texture View
573  *//*--------------------------------------------------------------------*/
574 class Texture2DView
575 {
576 public:
577 									Texture2DView		(int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false);
578 
getNumLevels(void) const579 	int								getNumLevels		(void) const	{ return m_numLevels;										}
getWidth(void) const580 	int								getWidth			(void) const	{ return m_numLevels > 0 ? m_levels[0].getWidth()	: 0;	}
getHeight(void) const581 	int								getHeight			(void) const	{ return m_numLevels > 0 ? m_levels[0].getHeight()	: 0;	}
getLevel(int ndx) const582 	const ConstPixelBufferAccess&	getLevel			(int ndx) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];	}
getLevels(void) const583 	const ConstPixelBufferAccess*	getLevels			(void) const	{ return m_levels;											}
isES2(void) const584 	bool								isES2					(void) const	{ return m_es2;												}
585 
586 	Vec4							sample				(const Sampler& sampler, float s, float t, float lod) const;
587 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
588 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float lod) const;
589 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
590 
591 	Vec4							gatherOffsets		(const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
592 	Vec4							gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
593 
594 protected:
595 	int								m_numLevels;
596 	const ConstPixelBufferAccess*	m_levels;
597 	bool								m_es2;
598 } DE_WARN_UNUSED_TYPE;
599 
Texture2DView(int numLevels,const ConstPixelBufferAccess * levels,bool es2)600 inline Texture2DView::Texture2DView (int numLevels, const ConstPixelBufferAccess* levels, bool es2)
601 	: m_numLevels	(numLevels)
602 	, m_levels		(levels)
603 	, m_es2			(es2)
604 {
605 	DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
606 }
607 
sample(const Sampler & sampler,float s,float t,float lod) const608 inline Vec4 Texture2DView::sample (const Sampler& sampler, float s, float t, float lod) const
609 {
610 	return sampleLevelArray2D(m_levels, m_numLevels, sampler, s, t, 0 /* depth */, lod, m_es2);
611 }
612 
sampleOffset(const Sampler & sampler,float s,float t,float lod,const IVec2 & offset) const613 inline Vec4 Texture2DView::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
614 {
615 	return sampleLevelArray2DOffset(m_levels, m_numLevels, sampler, s, t, lod, IVec3(offset.x(), offset.y(), 0));
616 }
617 
sampleCompare(const Sampler & sampler,float ref,float s,float t,float lod) const618 inline float Texture2DView::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
619 {
620 	return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(0, 0, 0));
621 }
622 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float lod,const IVec2 & offset) const623 inline float Texture2DView::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
624 {
625 	return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(offset.x(), offset.y(), 0));
626 }
627 
gatherOffsets(const Sampler & sampler,float s,float t,int componentNdx,const IVec2 (& offsets)[4]) const628 inline Vec4 Texture2DView::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
629 {
630 	return gatherArray2DOffsets(m_levels[0], sampler, s, t, 0, componentNdx, offsets);
631 }
632 
gatherOffsetsCompare(const Sampler & sampler,float ref,float s,float t,const IVec2 (& offsets)[4]) const633 inline Vec4 Texture2DView::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
634 {
635 	return gatherArray2DOffsetsCompare(m_levels[0], sampler, ref, s, t, 0, offsets);
636 }
637 
638 /*--------------------------------------------------------------------*//*!
639  * \brief Base class for textures that have single mip-map pyramid
640  *//*--------------------------------------------------------------------*/
641 class TextureLevelPyramid
642 {
643 public:
644 									TextureLevelPyramid	(const TextureFormat& format, int numLevels);
645 									TextureLevelPyramid	(const TextureLevelPyramid& other);
646 									~TextureLevelPyramid(void);
647 
getFormat(void) const648 	const TextureFormat&			getFormat			(void) const			{ return m_format;					}
getNumLevels(void) const649 	int								getNumLevels		(void) const			{ return (int)m_access.size();		}
650 
isLevelEmpty(int levelNdx) const651 	bool							isLevelEmpty		(int levelNdx) const	{ DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[(size_t)levelNdx].empty();	}
getLevel(int levelNdx) const652 	const ConstPixelBufferAccess&	getLevel			(int levelNdx) const	{ DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_access[(size_t)levelNdx];			}
getLevel(int levelNdx)653 	const PixelBufferAccess&		getLevel			(int levelNdx)			{ DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_access[(size_t)levelNdx];			}
654 
getLevels(void) const655 	const ConstPixelBufferAccess*	getLevels			(void) const			{ return &m_access[0];				}
getLevels(void)656 	const PixelBufferAccess*		getLevels			(void)					{ return &m_access[0];				}
657 
658 	void							allocLevel			(int levelNdx, int width, int height, int depth);
659 	void							clearLevel			(int levelNdx);
660 
661 	TextureLevelPyramid&			operator=			(const TextureLevelPyramid& other);
662 
663 private:
664 	typedef de::ArrayBuffer<deUint8> LevelData;
665 
666 	TextureFormat					m_format;
667 	std::vector<LevelData>			m_data;
668 	std::vector<PixelBufferAccess>	m_access;
669 } DE_WARN_UNUSED_TYPE;
670 
671 /*--------------------------------------------------------------------*//*!
672  * \brief 1D Texture reference implementation
673  *//*--------------------------------------------------------------------*/
674 class Texture1D : private TextureLevelPyramid
675 {
676 public:
677 									Texture1D			(const TextureFormat& format, int width);
678 									Texture1D			(const Texture1D& other);
679 									~Texture1D			(void);
680 
getWidth(void) const681 	int								getWidth			(void) const	{ return m_width;	}
getView(void) const682 	const Texture1DView&			getView				(void) const	{ return m_view;	}
683 
684 	void							allocLevel			(int levelNdx);
685 
686 	// Sampling
687 	Vec4							sample				(const Sampler& sampler, float s, float lod) const;
688 	Vec4							sampleOffset		(const Sampler& sampler, float s, float lod, deInt32 offset) const;
689 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float lod) const;
690 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const;
691 
692 	using TextureLevelPyramid::getFormat;
693 	using TextureLevelPyramid::getNumLevels;
694 	using TextureLevelPyramid::getLevel;
695 	using TextureLevelPyramid::clearLevel;
696 	using TextureLevelPyramid::isLevelEmpty;
697 
698 	Texture1D&						operator=			(const Texture1D& other);
699 
operator Texture1DView(void) const700 	operator Texture1DView (void) const { return m_view; }
701 
702 private:
703 	int								m_width;
704 	Texture1DView					m_view;
705 } DE_WARN_UNUSED_TYPE;
706 
sample(const Sampler & sampler,float s,float lod) const707 inline Vec4 Texture1D::sample (const Sampler& sampler, float s, float lod) const
708 {
709 	return m_view.sample(sampler, s, lod);
710 }
711 
sampleOffset(const Sampler & sampler,float s,float lod,deInt32 offset) const712 inline Vec4 Texture1D::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
713 {
714 	return m_view.sampleOffset(sampler, s, lod, offset);
715 }
716 
sampleCompare(const Sampler & sampler,float ref,float s,float lod) const717 inline float Texture1D::sampleCompare (const Sampler& sampler, float ref, float s, float lod) const
718 {
719 	return m_view.sampleCompare(sampler, ref, s, lod);
720 }
721 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float lod,deInt32 offset) const722 inline float Texture1D::sampleCompareOffset	(const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const
723 {
724 	return m_view.sampleCompareOffset(sampler, ref, s, lod, offset);
725 }
726 
727 /*--------------------------------------------------------------------*//*!
728  * \brief 2D Texture reference implementation
729  *//*--------------------------------------------------------------------*/
730 class Texture2D : private TextureLevelPyramid
731 {
732 public:
733 									Texture2D			(const TextureFormat& format, int width, int height, bool es2 = false);
734 									Texture2D			(const TextureFormat& format, int width, int height, int mipmaps);
735 									Texture2D			(const Texture2D& other);
736 									~Texture2D			(void);
737 
getWidth(void) const738 	int								getWidth			(void) const	{ return m_width;	}
getHeight(void) const739 	int								getHeight			(void) const	{ return m_height;	}
getView(void) const740 	const Texture2DView&			getView				(void) const	{ return m_view;	}
741 
742 	void							allocLevel			(int levelNdx);
743 
744 	// Sampling
745 	Vec4							sample				(const Sampler& sampler, float s, float t, float lod) const;
746 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
747 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float lod) const;
748 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
749 
750 	Vec4							gatherOffsets		(const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
751 	Vec4							gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
752 
753 	using TextureLevelPyramid::getFormat;
754 	using TextureLevelPyramid::getNumLevels;
755 	using TextureLevelPyramid::getLevel;
756 	using TextureLevelPyramid::clearLevel;
757 	using TextureLevelPyramid::isLevelEmpty;
758 
759 	Texture2D&						operator=			(const Texture2D& other);
760 
operator Texture2DView(void) const761 	operator Texture2DView (void) const { return m_view; }
762 
763 private:
764 	int								m_width;
765 	int								m_height;
766 	Texture2DView					m_view;
767 } DE_WARN_UNUSED_TYPE;
768 
sample(const Sampler & sampler,float s,float t,float lod) const769 inline Vec4 Texture2D::sample (const Sampler& sampler, float s, float t, float lod) const
770 {
771 	return m_view.sample(sampler, s, t, lod);
772 }
773 
sampleOffset(const Sampler & sampler,float s,float t,float lod,const IVec2 & offset) const774 inline Vec4 Texture2D::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
775 {
776 	return m_view.sampleOffset(sampler, s, t, lod, offset);
777 }
778 
sampleCompare(const Sampler & sampler,float ref,float s,float t,float lod) const779 inline float Texture2D::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
780 {
781 	return m_view.sampleCompare(sampler, ref, s, t, lod);
782 }
783 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float lod,const IVec2 & offset) const784 inline float Texture2D::sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
785 {
786 	return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
787 }
788 
gatherOffsets(const Sampler & sampler,float s,float t,int componentNdx,const IVec2 (& offsets)[4]) const789 inline Vec4 Texture2D::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
790 {
791 	return m_view.gatherOffsets(sampler, s, t, componentNdx, offsets);
792 }
793 
gatherOffsetsCompare(const Sampler & sampler,float ref,float s,float t,const IVec2 (& offsets)[4]) const794 inline Vec4 Texture2D::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
795 {
796 	return m_view.gatherOffsetsCompare(sampler, ref, s, t, offsets);
797 }
798 
799 /*--------------------------------------------------------------------*//*!
800  * \brief Cube Map Texture View
801  *//*--------------------------------------------------------------------*/
802 class TextureCubeView
803 {
804 public:
805 									TextureCubeView		(void);
806 									TextureCubeView		(int numLevels, const ConstPixelBufferAccess* const (&levels)[CUBEFACE_LAST], bool es2 = false);
807 
getNumLevels(void) const808 	int								getNumLevels		(void) const	{ return m_numLevels;										}
isES2(void) const809 	bool								isES2					(void) const	{ return m_es2;												}
getSize(void) const810 	int								getSize				(void) const	{ return m_numLevels > 0 ? m_levels[0][0].getWidth() : 0;	}
getLevelFace(int ndx,CubeFace face) const811 	const ConstPixelBufferAccess&	getLevelFace		(int ndx, CubeFace face) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[face][ndx];	}
getFaceLevels(CubeFace face) const812 	const ConstPixelBufferAccess*	getFaceLevels		(CubeFace face) const			{ return m_levels[face];					}
813 
814 	Vec4							sample				(const Sampler& sampler, float s, float t, float p, float lod) const;
815 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
816 
817 	Vec4							gather				(const Sampler& sampler, float s, float t, float r, int componentNdx) const;
818 	Vec4							gatherCompare		(const Sampler& sampler, float ref, float s, float t, float r) const;
819 
820 protected:
821 	int								m_numLevels;
822 	const ConstPixelBufferAccess*	m_levels[CUBEFACE_LAST];
823 	bool								m_es2;
824 } DE_WARN_UNUSED_TYPE;
825 
826 /*--------------------------------------------------------------------*//*!
827  * \brief Cube Map Texture reference implementation
828  *//*--------------------------------------------------------------------*/
829 class TextureCube
830 {
831 public:
832 									TextureCube			(const TextureFormat& format, int size, bool es2 = false);
833 									TextureCube			(const TextureCube& other);
834 									~TextureCube		(void);
835 
getFormat(void) const836 	const TextureFormat&			getFormat			(void) const	{ return m_format;	}
getSize(void) const837 	int								getSize				(void) const	{ return m_size;	}
getView(void) const838 	const TextureCubeView&		getView				(void) const	{ return m_view;	}
839 
getNumLevels(void) const840 	int								getNumLevels		(void) const					{ return (int)m_access[0].size();	}
getLevelFace(int ndx,CubeFace face) const841 	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)842 	const PixelBufferAccess&		getLevelFace		(int ndx, CubeFace face)		{ DE_ASSERT(de::inBounds(ndx, 0, getNumLevels())); return m_access[face][(size_t)ndx];	}
843 
844 	void							allocLevel			(CubeFace face, int levelNdx);
845 	void							clearLevel			(CubeFace face, int levelNdx);
isLevelEmpty(CubeFace face,int levelNdx) const846 	bool							isLevelEmpty		(CubeFace face, int levelNdx) const	{ DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[face][(size_t)levelNdx].empty();	}
847 
848 	Vec4							sample				(const Sampler& sampler, float s, float t, float p, float lod) const;
849 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
850 
851 	Vec4							gather				(const Sampler& sampler, float s, float t, float r, int componentNdx) const;
852 	Vec4							gatherCompare		(const Sampler& sampler, float ref, float s, float t, float r) const;
853 
854 	TextureCube&					operator=			(const TextureCube& other);
855 
operator TextureCubeView(void) const856 	operator TextureCubeView (void) const { return m_view; }
857 
858 private:
859 	typedef de::ArrayBuffer<deUint8> LevelData;
860 
861 	TextureFormat					m_format;
862 	int								m_size;
863 	std::vector<LevelData>			m_data[CUBEFACE_LAST];
864 	std::vector<PixelBufferAccess>	m_access[CUBEFACE_LAST];
865 	TextureCubeView					m_view;
866 } DE_WARN_UNUSED_TYPE;
867 
sample(const Sampler & sampler,float s,float t,float p,float lod) const868 inline Vec4 TextureCube::sample (const Sampler& sampler, float s, float t, float p, float lod) const
869 {
870 	return m_view.sample(sampler, s, t, p, lod);
871 }
872 
sampleCompare(const Sampler & sampler,float ref,float s,float t,float r,float lod) const873 inline float TextureCube::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
874 {
875 	return m_view.sampleCompare(sampler, ref, s, t, r, lod);
876 }
877 
gather(const Sampler & sampler,float s,float t,float r,int componentNdx) const878 inline Vec4 TextureCube::gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const
879 {
880 	return m_view.gather(sampler, s, t, r, componentNdx);
881 }
882 
gatherCompare(const Sampler & sampler,float ref,float s,float t,float r) const883 inline Vec4 TextureCube::gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const
884 {
885 	return m_view.gatherCompare(sampler, ref, s, t, r);
886 }
887 
888 /*--------------------------------------------------------------------*//*!
889  * \brief 1D Array Texture View
890  *//*--------------------------------------------------------------------*/
891 class Texture1DArrayView
892 {
893 public:
894 									Texture1DArrayView	(int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false);
895 
getWidth(void) const896 	int								getWidth			(void) const	{ return m_numLevels > 0 ? m_levels[0].getWidth()	: 0;	}
getNumLayers(void) const897 	int								getNumLayers		(void) const	{ return m_numLevels > 0 ? m_levels[0].getHeight()	: 0;	}
getNumLevels(void) const898 	int								getNumLevels		(void) const	{ return m_numLevels;										}
getLevel(int ndx) const899 	const ConstPixelBufferAccess&	getLevel			(int ndx) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];	}
getLevels(void) const900 	const ConstPixelBufferAccess*	getLevels			(void) const	{ return m_levels;											}
isES2(void) const901 	bool								isES2						(void) const	{ return false;												}
902 
903 	Vec4							sample				(const Sampler& sampler, float s, float t, float lod) const;
904 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
905 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float lod) const;
906 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
907 
908 protected:
909 	int								selectLayer			(float r) const;
910 
911 	int								m_numLevels;
912 	const ConstPixelBufferAccess*	m_levels;
913 } DE_WARN_UNUSED_TYPE;
914 
915 /*--------------------------------------------------------------------*//*!
916  * \brief 2D Array Texture View
917  *//*--------------------------------------------------------------------*/
918 class Texture2DArrayView
919 {
920 public:
921 									Texture2DArrayView	(int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false);
922 
getWidth(void) const923 	int								getWidth			(void) const	{ return m_numLevels > 0 ? m_levels[0].getWidth()	: 0;	}
getHeight(void) const924 	int								getHeight			(void) const	{ return m_numLevels > 0 ? m_levels[0].getHeight()	: 0;	}
getNumLayers(void) const925 	int								getNumLayers		(void) const	{ return m_numLevels > 0 ? m_levels[0].getDepth()	: 0;	}
getNumLevels(void) const926 	int								getNumLevels		(void) const	{ return m_numLevels;										}
getLevel(int ndx) const927 	const ConstPixelBufferAccess&	getLevel			(int ndx) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];	}
getLevels(void) const928 	const ConstPixelBufferAccess*	getLevels			(void) const	{ return m_levels;											}
isES2(void) const929 	bool								isES2						(void) const	{ return false;												}
930 
931 	Vec4							sample				(const Sampler& sampler, float s, float t, float r, float lod) const;
932 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
933 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
934 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
935 
936 	Vec4							gatherOffsets		(const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
937 	Vec4							gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
938 
939 protected:
940 	int								selectLayer			(float r) const;
941 
942 	int								m_numLevels;
943 	const ConstPixelBufferAccess*	m_levels;
944 } DE_WARN_UNUSED_TYPE;
945 
946 /*--------------------------------------------------------------------*//*!
947  * \brief 1D Array Texture reference implementation
948  *//*--------------------------------------------------------------------*/
949 class Texture1DArray : private TextureLevelPyramid
950 {
951 public:
952 									Texture1DArray		(const TextureFormat& format, int width, int numLayers);
953 									Texture1DArray		(const Texture1DArray& other);
954 									~Texture1DArray		(void);
955 
getWidth(void) const956 	int								getWidth			(void) const	{ return m_width;		}
getNumLayers(void) const957 	int								getNumLayers		(void) const	{ return m_numLayers;	}
958 
959 	void							allocLevel			(int levelNdx);
960 
961 	using TextureLevelPyramid::getFormat;
962 	using TextureLevelPyramid::getNumLevels;
963 	using TextureLevelPyramid::getLevel;
964 	using TextureLevelPyramid::clearLevel;
965 	using TextureLevelPyramid::isLevelEmpty;
966 
967 	Vec4							sample				(const Sampler& sampler, float s, float t, float lod) const;
968 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
969 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float lod) const;
970 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
971 
972 	Texture1DArray&					operator=			(const Texture1DArray& other);
973 
operator Texture1DArrayView(void) const974 	operator Texture1DArrayView (void) const { return m_view; }
975 
976 private:
977 	int								m_width;
978 	int								m_numLayers;
979 	Texture1DArrayView				m_view;
980 } DE_WARN_UNUSED_TYPE;
981 
sample(const Sampler & sampler,float s,float t,float lod) const982 inline Vec4 Texture1DArray::sample (const Sampler& sampler, float s, float t, float lod) const
983 {
984 	return m_view.sample(sampler, s, t, lod);
985 }
986 
sampleOffset(const Sampler & sampler,float s,float t,float lod,deInt32 offset) const987 inline Vec4 Texture1DArray::sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const
988 {
989 	return m_view.sampleOffset(sampler, s, t, lod, offset);
990 }
991 
sampleCompare(const Sampler & sampler,float ref,float s,float t,float lod) const992 inline float Texture1DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
993 {
994 	return m_view.sampleCompare(sampler, ref, s, t, lod);
995 }
996 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float lod,deInt32 offset) const997 inline float Texture1DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const
998 {
999 	return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
1000 }
1001 
1002 /*--------------------------------------------------------------------*//*!
1003  * \brief 2D Array Texture reference implementation
1004  *//*--------------------------------------------------------------------*/
1005 class Texture2DArray : private TextureLevelPyramid
1006 {
1007 public:
1008 									Texture2DArray		(const TextureFormat& format, int width, int height, int numLayers);
1009 									Texture2DArray		(const Texture2DArray& other);
1010 									~Texture2DArray		(void);
1011 
getWidth(void) const1012 	int								getWidth			(void) const	{ return m_width;		}
getHeight(void) const1013 	int								getHeight			(void) const	{ return m_height;		}
getNumLayers(void) const1014 	int								getNumLayers		(void) const	{ return m_numLayers;	}
1015 
1016 	void							allocLevel			(int levelNdx);
1017 
1018 	using TextureLevelPyramid::getFormat;
1019 	using TextureLevelPyramid::getNumLevels;
1020 	using TextureLevelPyramid::getLevel;
1021 	using TextureLevelPyramid::clearLevel;
1022 	using TextureLevelPyramid::isLevelEmpty;
1023 
1024 	Vec4							sample				(const Sampler& sampler, float s, float t, float r, float lod) const;
1025 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
1026 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
1027 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
1028 
1029 	Vec4							gatherOffsets		(const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
1030 	Vec4							gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
1031 
1032 	Texture2DArray&					operator=			(const Texture2DArray& other);
1033 
operator Texture2DArrayView(void) const1034 	operator Texture2DArrayView (void) const { return m_view; }
1035 
1036 private:
1037 	int								m_width;
1038 	int								m_height;
1039 	int								m_numLayers;
1040 	Texture2DArrayView				m_view;
1041 } DE_WARN_UNUSED_TYPE;
1042 
sample(const Sampler & sampler,float s,float t,float r,float lod) const1043 inline Vec4 Texture2DArray::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1044 {
1045 	return m_view.sample(sampler, s, t, r, lod);
1046 }
1047 
sampleOffset(const Sampler & sampler,float s,float t,float r,float lod,const IVec2 & offset) const1048 inline Vec4 Texture2DArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const
1049 {
1050 	return m_view.sampleOffset(sampler, s, t, r, lod, offset);
1051 }
1052 
sampleCompare(const Sampler & sampler,float ref,float s,float t,float r,float lod) const1053 inline float Texture2DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
1054 {
1055 	return m_view.sampleCompare(sampler, ref, s, t, r, lod);
1056 }
1057 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float r,float lod,const IVec2 & offset) const1058 inline float Texture2DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const
1059 {
1060 	return m_view.sampleCompareOffset(sampler, ref, s, t, r, lod, offset);
1061 }
1062 
gatherOffsets(const Sampler & sampler,float s,float t,float r,int componentNdx,const IVec2 (& offsets)[4]) const1063 inline Vec4 Texture2DArray::gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const
1064 {
1065 	return m_view.gatherOffsets(sampler, s, t, r, componentNdx, offsets);
1066 }
1067 
gatherOffsetsCompare(const Sampler & sampler,float ref,float s,float t,float r,const IVec2 (& offsets)[4]) const1068 inline Vec4 Texture2DArray::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const
1069 {
1070 	return m_view.gatherOffsetsCompare(sampler, ref, s, t, r, offsets);
1071 }
1072 
1073 /*--------------------------------------------------------------------*//*!
1074  * \brief 3D Texture View
1075  *//*--------------------------------------------------------------------*/
1076 class Texture3DView
1077 {
1078 public:
1079 									Texture3DView		(int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false);
1080 
getWidth(void) const1081 	int								getWidth			(void) const	{ return m_numLevels > 0 ? m_levels[0].getWidth()	: 0;	}
getHeight(void) const1082 	int								getHeight			(void) const	{ return m_numLevels > 0 ? m_levels[0].getHeight()	: 0;	}
getDepth(void) const1083 	int								getDepth			(void) const	{ return m_numLevels > 0 ? m_levels[0].getDepth()	: 0;	}
getNumLevels(void) const1084 	int								getNumLevels		(void) const	{ return m_numLevels;										}
getLevel(int ndx) const1085 	const ConstPixelBufferAccess&	getLevel			(int ndx) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];	}
getLevels(void) const1086 	const ConstPixelBufferAccess*	getLevels			(void) const	{ return m_levels;											}
isES2(void) const1087 	bool								isES2						(void) const	{ return false;												}
1088 
1089 	Vec4							sample				(const Sampler& sampler, float s, float t, float r, float lod) const;
1090 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
1091 
1092 protected:
1093 	int								m_numLevels;
1094 	const ConstPixelBufferAccess*	m_levels;
1095 } DE_WARN_UNUSED_TYPE;
1096 
sample(const Sampler & sampler,float s,float t,float r,float lod) const1097 inline Vec4 Texture3DView::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1098 {
1099 	return sampleLevelArray3D(m_levels, m_numLevels, sampler, s, t, r, lod);
1100 }
1101 
sampleOffset(const Sampler & sampler,float s,float t,float r,float lod,const IVec3 & offset) const1102 inline Vec4 Texture3DView::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
1103 {
1104 	return sampleLevelArray3DOffset(m_levels, m_numLevels, sampler, s, t, r, lod, offset);
1105 }
1106 
1107 /*--------------------------------------------------------------------*//*!
1108  * \brief 3D Texture reference implementation
1109  *//*--------------------------------------------------------------------*/
1110 class Texture3D : private TextureLevelPyramid
1111 {
1112 public:
1113 									Texture3D			(const TextureFormat& format, int width, int height, int depth);
1114 									Texture3D			(const Texture3D& other);
1115 									~Texture3D			(void);
1116 
getWidth(void) const1117 	int								getWidth			(void) const	{ return m_width;	}
getHeight(void) const1118 	int								getHeight			(void) const	{ return m_height;	}
getDepth(void) const1119 	int								getDepth			(void) const	{ return m_depth;	}
1120 
1121 	void							allocLevel			(int levelNdx);
1122 
1123 	using TextureLevelPyramid::getFormat;
1124 	using TextureLevelPyramid::getNumLevels;
1125 	using TextureLevelPyramid::getLevel;
1126 	using TextureLevelPyramid::clearLevel;
1127 	using TextureLevelPyramid::isLevelEmpty;
1128 
1129 	Vec4							sample				(const Sampler& sampler, float s, float t, float r, float lod) const;
1130 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
1131 
1132 	Texture3D&						operator=			(const Texture3D& other);
1133 
operator Texture3DView(void) const1134 	operator Texture3DView (void) const { return m_view; }
1135 
1136 private:
1137 	int								m_width;
1138 	int								m_height;
1139 	int								m_depth;
1140 	Texture3DView					m_view;
1141 } DE_WARN_UNUSED_TYPE;
1142 
sample(const Sampler & sampler,float s,float t,float r,float lod) const1143 inline Vec4 Texture3D::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1144 {
1145 	return m_view.sample(sampler, s, t, r, lod);
1146 }
1147 
sampleOffset(const Sampler & sampler,float s,float t,float r,float lod,const IVec3 & offset) const1148 inline Vec4 Texture3D::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
1149 {
1150 	return m_view.sampleOffset(sampler, s, t, r, lod, offset);
1151 }
1152 
1153 /*--------------------------------------------------------------------*//*!
1154  * \brief Cube Map Array Texture View
1155  *//*--------------------------------------------------------------------*/
1156 class TextureCubeArrayView
1157 {
1158 public:
1159 									TextureCubeArrayView	(int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false);
1160 
getSize(void) const1161 	int								getSize					(void) const	{ return m_numLevels > 0 ? m_levels[0].getWidth()	: 0;	}
getDepth(void) const1162 	int								getDepth				(void) const	{ return m_numLevels > 0 ? m_levels[0].getDepth()	: 0;	}
getNumLayers(void) const1163 	int								getNumLayers			(void) const	{ return getDepth()	/ 6;	}
getNumLevels(void) const1164 	int								getNumLevels			(void) const	{ return m_numLevels;										}
getLevel(int ndx) const1165 	const ConstPixelBufferAccess&	getLevel				(int ndx) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];	}
getLevels(void) const1166 	const ConstPixelBufferAccess*	getLevels				(void) const	{ return m_levels;											}
isES2(void) const1167 	bool									isES2						(void) const	{ return false;												}
1168 
1169 	Vec4							sample					(const Sampler& sampler, float s, float t, float r, float q, float lod) const;
1170 	Vec4							sampleOffset			(const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1171 	float							sampleCompare			(const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
1172 	float							sampleCompareOffset		(const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1173 
1174 protected:
1175 	int								selectLayer				(float q) const;
1176 
1177 	int								m_numLevels;
1178 	const ConstPixelBufferAccess*	m_levels;
1179 } DE_WARN_UNUSED_TYPE;
1180 
1181 /*--------------------------------------------------------------------*//*!
1182  * \brief Cube Map Array Texture reference implementation
1183  *//*--------------------------------------------------------------------*/
1184 class TextureCubeArray : private TextureLevelPyramid
1185 {
1186 public:
1187 									TextureCubeArray	(const TextureFormat& format, int size, int depth);
1188 									TextureCubeArray	(const TextureCubeArray& other);
1189 									~TextureCubeArray	(void);
1190 
getSize(void) const1191 	int								getSize				(void) const	{ return m_size;	}
getDepth(void) const1192 	int								getDepth			(void) const	{ return m_depth;	}
1193 
1194 	void							allocLevel			(int levelNdx);
1195 
1196 	using TextureLevelPyramid::getFormat;
1197 	using TextureLevelPyramid::getNumLevels;
1198 	using TextureLevelPyramid::getLevel;
1199 	using TextureLevelPyramid::clearLevel;
1200 	using TextureLevelPyramid::isLevelEmpty;
1201 
1202 	Vec4							sample				(const Sampler& sampler, float s, float t, float r, float q, float lod) const;
1203 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1204 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
1205 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1206 
1207 	TextureCubeArray&				operator=			(const TextureCubeArray& other);
1208 
operator TextureCubeArrayView(void) const1209 	operator TextureCubeArrayView (void) const { return m_view; }
1210 
1211 private:
1212 	int								m_size;
1213 	int								m_depth;
1214 	TextureCubeArrayView			m_view;
1215 } DE_WARN_UNUSED_TYPE;
1216 
sample(const Sampler & sampler,float s,float t,float r,float q,float lod) const1217 inline Vec4 TextureCubeArray::sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const
1218 {
1219 	return m_view.sample(sampler, s, t, r, q, lod);
1220 }
1221 
sampleOffset(const Sampler & sampler,float s,float t,float r,float q,float lod,const IVec2 & offset) const1222 inline Vec4 TextureCubeArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const
1223 {
1224 	return m_view.sampleOffset(sampler, s, t, r, q, lod, offset);
1225 }
1226 
sampleCompare(const Sampler & sampler,float ref,float s,float t,float r,float q,float lod) const1227 inline float TextureCubeArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const
1228 {
1229 	return m_view.sampleCompare(sampler, ref, s, t, r, q, lod);
1230 }
1231 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float r,float q,float lod,const IVec2 & offset) const1232 inline float TextureCubeArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const
1233 {
1234 	return m_view.sampleCompareOffset(sampler, ref, s, t, r, q, lod, offset);
1235 }
1236 
1237 // Stream operators.
1238 std::ostream&		operator<<		(std::ostream& str, TextureFormat::ChannelOrder order);
1239 std::ostream&		operator<<		(std::ostream& str, TextureFormat::ChannelType type);
1240 std::ostream&		operator<<		(std::ostream& str, TextureFormat format);
1241 std::ostream&		operator<<		(std::ostream& str, CubeFace face);
1242 std::ostream&		operator<<		(std::ostream& str, const ConstPixelBufferAccess& access);
1243 
1244 } // tcu
1245 
1246 #endif // _TCUTEXTURE_HPP
1247