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 
378 	template<typename T>
379 	Vector<T, 4>			getPixelT					(int x, int y, int z = 0) const;
380 
381 	float					getPixDepth					(int x, int y, int z = 0) const;
382 	int						getPixStencil				(int x, int y, int z = 0) const;
383 
384 	Vec4					sample1D					(const Sampler& sampler, Sampler::FilterMode filter, float s, int level) const;
385 	Vec4					sample2D					(const Sampler& sampler, Sampler::FilterMode filter, float s, float t, int depth) const;
386 	Vec4					sample3D					(const Sampler& sampler, Sampler::FilterMode filter, float s, float t, float r) const;
387 
388 	Vec4					sample1DOffset				(const Sampler& sampler, Sampler::FilterMode filter, float s, const IVec2& offset) const;
389 	Vec4					sample2DOffset				(const Sampler& sampler, Sampler::FilterMode filter, float s, float t, const IVec3& offset) const;
390 	Vec4					sample3DOffset				(const Sampler& sampler, Sampler::FilterMode filter, float s, float t, float r, const IVec3& offset) const;
391 
392 	float					sample1DCompare				(const Sampler& sampler, Sampler::FilterMode filter, float ref, float s, const IVec2& offset) const;
393 	float					sample2DCompare				(const Sampler& sampler, Sampler::FilterMode filter, float ref, float s, float t, const IVec3& offset) const;
394 
395 protected:
396 	TextureFormat			m_format;
397 	IVec3					m_size;
398 	IVec3					m_pitch;	//!< (pixelPitch, rowPitch, slicePitch)
399 	IVec3					m_divider;
400 	mutable void*			m_data;
401 } DE_WARN_UNUSED_TYPE;
402 
403 /*--------------------------------------------------------------------*//*!
404  * \brief Read-write pixel data access
405  *
406  * This class extends read-only access object by providing write functionality.
407  *
408  * \note PixelBufferAccess may not have any data members nor add any
409  *		 virtual functions. It must be possible to reinterpret_cast<>
410  *		 PixelBufferAccess to ConstPixelBufferAccess.
411  *//*--------------------------------------------------------------------*/
412 class PixelBufferAccess : public ConstPixelBufferAccess
413 {
414 public:
PixelBufferAccess(void)415 						PixelBufferAccess	(void) {}
416 						PixelBufferAccess	(TextureLevel& level);
417 						PixelBufferAccess	(const TextureFormat& format, int width, int height, int depth, void* data);
418 						PixelBufferAccess	(const TextureFormat& format, const IVec3& size, void* data);
419 						PixelBufferAccess	(const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, void* data);
420 						PixelBufferAccess	(const TextureFormat& format, const IVec3& size, const IVec3& pitch, void* data);
421 						PixelBufferAccess	(const TextureFormat& format, const IVec3& size, const IVec3& pitch, const IVec3& block, void* data);
422 
getDataPtr(void) const423 	void*				getDataPtr			(void) const { return m_data; }
getPixelPtr(int x,int y,int z=0) const424 	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(); }
425 
426 	void				setPixel			(const tcu::Vec4& color, int x, int y, int z = 0) const;
427 	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) const428 	void				setPixel			(const tcu::UVec4& color, int x, int y, int z = 0) const { setPixel(color.cast<int>(), x, y, z); }
429 
430 	void				setPixDepth			(float depth, int x, int y, int z = 0) const;
431 	void				setPixStencil		(int stencil, int x, int y, int z = 0) const;
432 } DE_WARN_UNUSED_TYPE;
433 
434 /*--------------------------------------------------------------------*//*!
435  * \brief Generic pixel data container
436  *
437  * This container supports all valid TextureFormat combinations and
438  * both 2D and 3D textures. To read or manipulate data access object must
439  * be queried using getAccess().
440  *//*--------------------------------------------------------------------*/
441 class TextureLevel
442 {
443 public:
444 								TextureLevel		(void);
445 								TextureLevel		(const TextureFormat& format);
446 								TextureLevel		(const TextureFormat& format, int width, int height, int depth = 1);
447 								~TextureLevel		(void);
448 
getSize(void) const449 	const IVec3&				getSize				(void) const	{ return m_size;		}
getWidth(void) const450 	int							getWidth			(void) const	{ return m_size.x();	}
getHeight(void) const451 	int							getHeight			(void) const	{ return m_size.y();	}
getDepth(void) const452 	int							getDepth			(void) const	{ return m_size.z();	}
isEmpty(void) const453 	bool						isEmpty				(void) const	{ return m_size.x() * m_size.y() * m_size.z() == 0; }
getFormat(void) const454 	const TextureFormat			getFormat			(void) const	{ return m_format;	}
455 
456 	void						setStorage			(const TextureFormat& format, int width, int heigth, int depth = 1);
457 	void						setSize				(int width, int height, int depth = 1);
458 
getAccess(void)459 	PixelBufferAccess			getAccess			(void)			{ return isEmpty() ? PixelBufferAccess() : PixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr());			}
getAccess(void) const460 	ConstPixelBufferAccess		getAccess			(void) const	{ return isEmpty() ? ConstPixelBufferAccess() : ConstPixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr());	}
461 
462 private:
getPtr(void)463 	void*						getPtr				(void)			{ return m_data.getPtr(); }
getPtr(void) const464 	const void*					getPtr				(void) const	{ return m_data.getPtr(); }
465 
466 	TextureFormat				m_format;
467 	IVec3						m_size;
468 	de::ArrayBuffer<deUint8>	m_data;
469 
470 	friend class ConstPixelBufferAccess;
471 } DE_WARN_UNUSED_TYPE;
472 
473 Vec4	sampleLevelArray1D				(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, int level, float lod);
474 Vec4	sampleLevelArray2D				(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, int depth, float lod, bool es2 = false);
475 Vec4	sampleLevelArray3D				(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float r, float lod);
476 
477 Vec4	sampleLevelArray1DOffset		(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float lod, const IVec2& offset);
478 Vec4	sampleLevelArray2DOffset		(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float lod, const IVec3& offset, bool es2 = false);
479 Vec4	sampleLevelArray3DOffset		(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset);
480 
481 float	sampleLevelArray1DCompare		(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float ref, float s, float lod, const IVec2& offset);
482 float	sampleLevelArray2DCompare		(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float ref, float s, float t, float lod, const IVec3& offset);
483 
484 Vec4	gatherArray2DOffsets			(const ConstPixelBufferAccess& src, const Sampler& sampler, float s, float t, int depth, int componentNdx, const IVec2 (&offsets)[4]);
485 Vec4	gatherArray2DOffsetsCompare		(const ConstPixelBufferAccess& src, const Sampler& sampler, float ref, float s, float t, int depth, const IVec2 (&offsets)[4]);
486 
487 enum CubeFace
488 {
489 	CUBEFACE_NEGATIVE_X = 0,
490 	CUBEFACE_POSITIVE_X,
491 	CUBEFACE_NEGATIVE_Y,
492 	CUBEFACE_POSITIVE_Y,
493 	CUBEFACE_NEGATIVE_Z,
494 	CUBEFACE_POSITIVE_Z,
495 
496 	CUBEFACE_LAST
497 };
498 
499 /*--------------------------------------------------------------------*//*!
500  * \brief Coordinates projected onto cube face.
501  *//*--------------------------------------------------------------------*/
502 template<typename T>
503 struct CubeFaceCoords
504 {
505 	CubeFace		face;
506 	T				s;
507 	T				t;
508 
CubeFaceCoordstcu::CubeFaceCoords509 					CubeFaceCoords		(CubeFace face_, T s_, T t_) : face(face_), s(s_), t(t_) {}
CubeFaceCoordstcu::CubeFaceCoords510 					CubeFaceCoords		(CubeFace face_, const Vector<T, 2>& c) : face(face_), s(c.x()), t(c.y()) {}
511 } DE_WARN_UNUSED_TYPE;
512 
513 typedef CubeFaceCoords<float>	CubeFaceFloatCoords;
514 typedef CubeFaceCoords<int>		CubeFaceIntCoords;
515 
516 CubeFace				selectCubeFace			(const Vec3& coords);
517 Vec2					projectToFace			(CubeFace face, const Vec3& coords);
518 CubeFaceFloatCoords		getCubeFaceCoords		(const Vec3& coords);
519 CubeFaceIntCoords		remapCubeEdgeCoords		(const CubeFaceIntCoords& coords, int size);
520 
521 /*--------------------------------------------------------------------*//*!
522  * \brief 1D Texture View
523  *//*--------------------------------------------------------------------*/
524 class Texture1DView
525 {
526 public:
527 									Texture1DView		(int numLevels, const ConstPixelBufferAccess* levels, bool es2);
528 
getNumLevels(void) const529 	int								getNumLevels		(void) const	{ return m_numLevels;										}
getWidth(void) const530 	int								getWidth			(void) const	{ return m_numLevels > 0 ? m_levels[0].getWidth()	: 0;	}
getLevel(int ndx) const531 	const ConstPixelBufferAccess&	getLevel			(int ndx) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];	}
getLevels(void) const532 	const ConstPixelBufferAccess*	getLevels			(void) const	{ return m_levels;											}
isES2(void) const533 	bool								isES2					(void) const	{ return false;												}
534 
535 	Vec4							sample				(const Sampler& sampler, float s, float lod) const;
536 	Vec4							sampleOffset		(const Sampler& sampler, float s, float lod, deInt32 offset) const;
537 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float lod) const;
538 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const;
539 
540 protected:
541 	int								m_numLevels;
542 	const ConstPixelBufferAccess*	m_levels;
543 } DE_WARN_UNUSED_TYPE;
544 
Texture1DView(int numLevels,const ConstPixelBufferAccess * levels,bool es2 DE_UNUSED_ATTR=false)545 inline Texture1DView::Texture1DView (int numLevels, const ConstPixelBufferAccess* levels, bool es2 DE_UNUSED_ATTR = false)
546 	: m_numLevels	(numLevels)
547 	, m_levels		(levels)
548 {
549 	DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
550 }
551 
sample(const Sampler & sampler,float s,float lod) const552 inline Vec4 Texture1DView::sample (const Sampler& sampler, float s, float lod) const
553 {
554 	return sampleLevelArray1D(m_levels, m_numLevels, sampler, s, 0 /* depth */, lod);
555 }
556 
sampleOffset(const Sampler & sampler,float s,float lod,deInt32 offset) const557 inline Vec4 Texture1DView::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
558 {
559 	return sampleLevelArray1DOffset(m_levels, m_numLevels, sampler, s, lod, IVec2(offset, 0));
560 }
561 
sampleCompare(const Sampler & sampler,float ref,float s,float lod) const562 inline float Texture1DView::sampleCompare (const Sampler& sampler, float ref, float s, float lod) const
563 {
564 	return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(0, 0));
565 }
566 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float lod,deInt32 offset) const567 inline float Texture1DView::sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const
568 {
569 	return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(offset, 0));
570 }
571 
572 /*--------------------------------------------------------------------*//*!
573  * \brief 2D Texture View
574  *//*--------------------------------------------------------------------*/
575 class Texture2DView
576 {
577 public:
578 									Texture2DView		(int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false);
579 
getNumLevels(void) const580 	int								getNumLevels		(void) const	{ return m_numLevels;										}
getWidth(void) const581 	int								getWidth			(void) const	{ return m_numLevels > 0 ? m_levels[0].getWidth()	: 0;	}
getHeight(void) const582 	int								getHeight			(void) const	{ return m_numLevels > 0 ? m_levels[0].getHeight()	: 0;	}
getLevel(int ndx) const583 	const ConstPixelBufferAccess&	getLevel			(int ndx) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];	}
getLevels(void) const584 	const ConstPixelBufferAccess*	getLevels			(void) const	{ return m_levels;											}
isES2(void) const585 	bool								isES2					(void) const	{ return m_es2;												}
586 
587 	Vec4							sample				(const Sampler& sampler, float s, float t, float lod) const;
588 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
589 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float lod) const;
590 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
591 
592 	Vec4							gatherOffsets		(const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
593 	Vec4							gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
594 
595 protected:
596 	int								m_numLevels;
597 	const ConstPixelBufferAccess*	m_levels;
598 	bool								m_es2;
599 } DE_WARN_UNUSED_TYPE;
600 
Texture2DView(int numLevels,const ConstPixelBufferAccess * levels,bool es2)601 inline Texture2DView::Texture2DView (int numLevels, const ConstPixelBufferAccess* levels, bool es2)
602 	: m_numLevels	(numLevels)
603 	, m_levels		(levels)
604 	, m_es2			(es2)
605 {
606 	DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
607 }
608 
sample(const Sampler & sampler,float s,float t,float lod) const609 inline Vec4 Texture2DView::sample (const Sampler& sampler, float s, float t, float lod) const
610 {
611 	return sampleLevelArray2D(m_levels, m_numLevels, sampler, s, t, 0 /* depth */, lod, m_es2);
612 }
613 
sampleOffset(const Sampler & sampler,float s,float t,float lod,const IVec2 & offset) const614 inline Vec4 Texture2DView::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
615 {
616 	return sampleLevelArray2DOffset(m_levels, m_numLevels, sampler, s, t, lod, IVec3(offset.x(), offset.y(), 0));
617 }
618 
sampleCompare(const Sampler & sampler,float ref,float s,float t,float lod) const619 inline float Texture2DView::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
620 {
621 	return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(0, 0, 0));
622 }
623 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float lod,const IVec2 & offset) const624 inline float Texture2DView::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
625 {
626 	return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(offset.x(), offset.y(), 0));
627 }
628 
gatherOffsets(const Sampler & sampler,float s,float t,int componentNdx,const IVec2 (& offsets)[4]) const629 inline Vec4 Texture2DView::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
630 {
631 	return gatherArray2DOffsets(m_levels[0], sampler, s, t, 0, componentNdx, offsets);
632 }
633 
gatherOffsetsCompare(const Sampler & sampler,float ref,float s,float t,const IVec2 (& offsets)[4]) const634 inline Vec4 Texture2DView::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
635 {
636 	return gatherArray2DOffsetsCompare(m_levels[0], sampler, ref, s, t, 0, offsets);
637 }
638 
639 /*--------------------------------------------------------------------*//*!
640  * \brief Base class for textures that have single mip-map pyramid
641  *//*--------------------------------------------------------------------*/
642 class TextureLevelPyramid
643 {
644 public:
645 									TextureLevelPyramid	(const TextureFormat& format, int numLevels);
646 									TextureLevelPyramid	(const TextureLevelPyramid& other);
647 									~TextureLevelPyramid(void);
648 
getFormat(void) const649 	const TextureFormat&			getFormat			(void) const			{ return m_format;					}
getNumLevels(void) const650 	int								getNumLevels		(void) const			{ return (int)m_access.size();		}
651 
isLevelEmpty(int levelNdx) const652 	bool							isLevelEmpty		(int levelNdx) const	{ DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[(size_t)levelNdx].empty();	}
getLevel(int levelNdx) const653 	const ConstPixelBufferAccess&	getLevel			(int levelNdx) const	{ DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_access[(size_t)levelNdx];			}
getLevel(int levelNdx)654 	const PixelBufferAccess&		getLevel			(int levelNdx)			{ DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_access[(size_t)levelNdx];			}
655 
getLevels(void) const656 	const ConstPixelBufferAccess*	getLevels			(void) const			{ return &m_access[0];				}
getLevels(void)657 	const PixelBufferAccess*		getLevels			(void)					{ return &m_access[0];				}
658 
659 	void							allocLevel			(int levelNdx, int width, int height, int depth);
660 	void							clearLevel			(int levelNdx);
661 
662 	TextureLevelPyramid&			operator=			(const TextureLevelPyramid& other);
663 
664 private:
665 	typedef de::ArrayBuffer<deUint8> LevelData;
666 
667 	TextureFormat					m_format;
668 	std::vector<LevelData>			m_data;
669 	std::vector<PixelBufferAccess>	m_access;
670 } DE_WARN_UNUSED_TYPE;
671 
672 /*--------------------------------------------------------------------*//*!
673  * \brief 1D Texture reference implementation
674  *//*--------------------------------------------------------------------*/
675 class Texture1D : private TextureLevelPyramid
676 {
677 public:
678 									Texture1D			(const TextureFormat& format, int width);
679 									Texture1D			(const Texture1D& other);
680 									~Texture1D			(void);
681 
getWidth(void) const682 	int								getWidth			(void) const	{ return m_width;	}
getView(void) const683 	const Texture1DView&			getView				(void) const	{ return m_view;	}
684 
685 	void							allocLevel			(int levelNdx);
686 
687 	// Sampling
688 	Vec4							sample				(const Sampler& sampler, float s, float lod) const;
689 	Vec4							sampleOffset		(const Sampler& sampler, float s, float lod, deInt32 offset) const;
690 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float lod) const;
691 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const;
692 
693 	using TextureLevelPyramid::getFormat;
694 	using TextureLevelPyramid::getNumLevels;
695 	using TextureLevelPyramid::getLevel;
696 	using TextureLevelPyramid::clearLevel;
697 	using TextureLevelPyramid::isLevelEmpty;
698 
699 	Texture1D&						operator=			(const Texture1D& other);
700 
operator Texture1DView(void) const701 	operator Texture1DView (void) const { return m_view; }
702 
703 private:
704 	int								m_width;
705 	Texture1DView					m_view;
706 } DE_WARN_UNUSED_TYPE;
707 
sample(const Sampler & sampler,float s,float lod) const708 inline Vec4 Texture1D::sample (const Sampler& sampler, float s, float lod) const
709 {
710 	return m_view.sample(sampler, s, lod);
711 }
712 
sampleOffset(const Sampler & sampler,float s,float lod,deInt32 offset) const713 inline Vec4 Texture1D::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
714 {
715 	return m_view.sampleOffset(sampler, s, lod, offset);
716 }
717 
sampleCompare(const Sampler & sampler,float ref,float s,float lod) const718 inline float Texture1D::sampleCompare (const Sampler& sampler, float ref, float s, float lod) const
719 {
720 	return m_view.sampleCompare(sampler, ref, s, lod);
721 }
722 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float lod,deInt32 offset) const723 inline float Texture1D::sampleCompareOffset	(const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const
724 {
725 	return m_view.sampleCompareOffset(sampler, ref, s, lod, offset);
726 }
727 
728 /*--------------------------------------------------------------------*//*!
729  * \brief 2D Texture reference implementation
730  *//*--------------------------------------------------------------------*/
731 class Texture2D : private TextureLevelPyramid
732 {
733 public:
734 									Texture2D			(const TextureFormat& format, int width, int height, bool es2 = false);
735 									Texture2D			(const TextureFormat& format, int width, int height, int mipmaps);
736 									Texture2D			(const Texture2D& other);
737 									~Texture2D			(void);
738 
getWidth(void) const739 	int								getWidth			(void) const	{ return m_width;	}
getHeight(void) const740 	int								getHeight			(void) const	{ return m_height;	}
getView(void) const741 	const Texture2DView&			getView				(void) const	{ return m_view;	}
742 
743 	void							allocLevel			(int levelNdx);
744 
745 	// Sampling
746 	Vec4							sample				(const Sampler& sampler, float s, float t, float lod) const;
747 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
748 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float lod) const;
749 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
750 
751 	Vec4							gatherOffsets		(const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
752 	Vec4							gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
753 
754 	using TextureLevelPyramid::getFormat;
755 	using TextureLevelPyramid::getNumLevels;
756 	using TextureLevelPyramid::getLevel;
757 	using TextureLevelPyramid::clearLevel;
758 	using TextureLevelPyramid::isLevelEmpty;
759 
760 	Texture2D&						operator=			(const Texture2D& other);
761 
operator Texture2DView(void) const762 	operator Texture2DView (void) const { return m_view; }
763 
764 private:
765 	int								m_width;
766 	int								m_height;
767 	Texture2DView					m_view;
768 } DE_WARN_UNUSED_TYPE;
769 
sample(const Sampler & sampler,float s,float t,float lod) const770 inline Vec4 Texture2D::sample (const Sampler& sampler, float s, float t, float lod) const
771 {
772 	return m_view.sample(sampler, s, t, lod);
773 }
774 
sampleOffset(const Sampler & sampler,float s,float t,float lod,const IVec2 & offset) const775 inline Vec4 Texture2D::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
776 {
777 	return m_view.sampleOffset(sampler, s, t, lod, offset);
778 }
779 
sampleCompare(const Sampler & sampler,float ref,float s,float t,float lod) const780 inline float Texture2D::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
781 {
782 	return m_view.sampleCompare(sampler, ref, s, t, lod);
783 }
784 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float lod,const IVec2 & offset) const785 inline float Texture2D::sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
786 {
787 	return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
788 }
789 
gatherOffsets(const Sampler & sampler,float s,float t,int componentNdx,const IVec2 (& offsets)[4]) const790 inline Vec4 Texture2D::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
791 {
792 	return m_view.gatherOffsets(sampler, s, t, componentNdx, offsets);
793 }
794 
gatherOffsetsCompare(const Sampler & sampler,float ref,float s,float t,const IVec2 (& offsets)[4]) const795 inline Vec4 Texture2D::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
796 {
797 	return m_view.gatherOffsetsCompare(sampler, ref, s, t, offsets);
798 }
799 
800 /*--------------------------------------------------------------------*//*!
801  * \brief Cube Map Texture View
802  *//*--------------------------------------------------------------------*/
803 class TextureCubeView
804 {
805 public:
806 									TextureCubeView		(void);
807 									TextureCubeView		(int numLevels, const ConstPixelBufferAccess* const (&levels)[CUBEFACE_LAST], bool es2 = false);
808 
getNumLevels(void) const809 	int								getNumLevels		(void) const	{ return m_numLevels;										}
isES2(void) const810 	bool								isES2					(void) const	{ return m_es2;												}
getSize(void) const811 	int								getSize				(void) const	{ return m_numLevels > 0 ? m_levels[0][0].getWidth() : 0;	}
getLevelFace(int ndx,CubeFace face) const812 	const ConstPixelBufferAccess&	getLevelFace		(int ndx, CubeFace face) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[face][ndx];	}
getFaceLevels(CubeFace face) const813 	const ConstPixelBufferAccess*	getFaceLevels		(CubeFace face) const			{ return m_levels[face];					}
814 
815 	Vec4							sample				(const Sampler& sampler, float s, float t, float p, float lod) const;
816 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
817 
818 	Vec4							gather				(const Sampler& sampler, float s, float t, float r, int componentNdx) const;
819 	Vec4							gatherCompare		(const Sampler& sampler, float ref, float s, float t, float r) const;
820 
821 protected:
822 	int								m_numLevels;
823 	const ConstPixelBufferAccess*	m_levels[CUBEFACE_LAST];
824 	bool								m_es2;
825 } DE_WARN_UNUSED_TYPE;
826 
827 /*--------------------------------------------------------------------*//*!
828  * \brief Cube Map Texture reference implementation
829  *//*--------------------------------------------------------------------*/
830 class TextureCube
831 {
832 public:
833 									TextureCube			(const TextureFormat& format, int size, bool es2 = false);
834 									TextureCube			(const TextureCube& other);
835 									~TextureCube		(void);
836 
getFormat(void) const837 	const TextureFormat&			getFormat			(void) const	{ return m_format;	}
getSize(void) const838 	int								getSize				(void) const	{ return m_size;	}
getView(void) const839 	const TextureCubeView&		getView				(void) const	{ return m_view;	}
840 
getNumLevels(void) const841 	int								getNumLevels		(void) const					{ return (int)m_access[0].size();	}
getLevelFace(int ndx,CubeFace face) const842 	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)843 	const PixelBufferAccess&		getLevelFace		(int ndx, CubeFace face)		{ DE_ASSERT(de::inBounds(ndx, 0, getNumLevels())); return m_access[face][(size_t)ndx];	}
844 
845 	void							allocLevel			(CubeFace face, int levelNdx);
846 	void							clearLevel			(CubeFace face, int levelNdx);
isLevelEmpty(CubeFace face,int levelNdx) const847 	bool							isLevelEmpty		(CubeFace face, int levelNdx) const	{ DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[face][(size_t)levelNdx].empty();	}
848 
849 	Vec4							sample				(const Sampler& sampler, float s, float t, float p, float lod) const;
850 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
851 
852 	Vec4							gather				(const Sampler& sampler, float s, float t, float r, int componentNdx) const;
853 	Vec4							gatherCompare		(const Sampler& sampler, float ref, float s, float t, float r) const;
854 
855 	TextureCube&					operator=			(const TextureCube& other);
856 
operator TextureCubeView(void) const857 	operator TextureCubeView (void) const { return m_view; }
858 
859 private:
860 	typedef de::ArrayBuffer<deUint8> LevelData;
861 
862 	TextureFormat					m_format;
863 	int								m_size;
864 	std::vector<LevelData>			m_data[CUBEFACE_LAST];
865 	std::vector<PixelBufferAccess>	m_access[CUBEFACE_LAST];
866 	TextureCubeView					m_view;
867 } DE_WARN_UNUSED_TYPE;
868 
sample(const Sampler & sampler,float s,float t,float p,float lod) const869 inline Vec4 TextureCube::sample (const Sampler& sampler, float s, float t, float p, float lod) const
870 {
871 	return m_view.sample(sampler, s, t, p, lod);
872 }
873 
sampleCompare(const Sampler & sampler,float ref,float s,float t,float r,float lod) const874 inline float TextureCube::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
875 {
876 	return m_view.sampleCompare(sampler, ref, s, t, r, lod);
877 }
878 
gather(const Sampler & sampler,float s,float t,float r,int componentNdx) const879 inline Vec4 TextureCube::gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const
880 {
881 	return m_view.gather(sampler, s, t, r, componentNdx);
882 }
883 
gatherCompare(const Sampler & sampler,float ref,float s,float t,float r) const884 inline Vec4 TextureCube::gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const
885 {
886 	return m_view.gatherCompare(sampler, ref, s, t, r);
887 }
888 
889 /*--------------------------------------------------------------------*//*!
890  * \brief 1D Array Texture View
891  *//*--------------------------------------------------------------------*/
892 class Texture1DArrayView
893 {
894 public:
895 									Texture1DArrayView	(int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false);
896 
getWidth(void) const897 	int								getWidth			(void) const	{ return m_numLevels > 0 ? m_levels[0].getWidth()	: 0;	}
getNumLayers(void) const898 	int								getNumLayers		(void) const	{ return m_numLevels > 0 ? m_levels[0].getHeight()	: 0;	}
getNumLevels(void) const899 	int								getNumLevels		(void) const	{ return m_numLevels;										}
getLevel(int ndx) const900 	const ConstPixelBufferAccess&	getLevel			(int ndx) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];	}
getLevels(void) const901 	const ConstPixelBufferAccess*	getLevels			(void) const	{ return m_levels;											}
isES2(void) const902 	bool								isES2						(void) const	{ return false;												}
903 
904 	Vec4							sample				(const Sampler& sampler, float s, float t, float lod) const;
905 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
906 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float lod) const;
907 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
908 
909 protected:
910 	int								selectLayer			(float r) const;
911 
912 	int								m_numLevels;
913 	const ConstPixelBufferAccess*	m_levels;
914 } DE_WARN_UNUSED_TYPE;
915 
916 /*--------------------------------------------------------------------*//*!
917  * \brief 2D Array Texture View
918  *//*--------------------------------------------------------------------*/
919 class Texture2DArrayView
920 {
921 public:
922 									Texture2DArrayView	(int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false);
923 
getWidth(void) const924 	int								getWidth			(void) const	{ return m_numLevels > 0 ? m_levels[0].getWidth()	: 0;	}
getHeight(void) const925 	int								getHeight			(void) const	{ return m_numLevels > 0 ? m_levels[0].getHeight()	: 0;	}
getNumLayers(void) const926 	int								getNumLayers		(void) const	{ return m_numLevels > 0 ? m_levels[0].getDepth()	: 0;	}
getNumLevels(void) const927 	int								getNumLevels		(void) const	{ return m_numLevels;										}
getLevel(int ndx) const928 	const ConstPixelBufferAccess&	getLevel			(int ndx) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];	}
getLevels(void) const929 	const ConstPixelBufferAccess*	getLevels			(void) const	{ return m_levels;											}
isES2(void) const930 	bool								isES2						(void) const	{ return false;												}
931 
932 	Vec4							sample				(const Sampler& sampler, float s, float t, float r, float lod) const;
933 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
934 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
935 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
936 
937 	Vec4							gatherOffsets		(const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
938 	Vec4							gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
939 
940 protected:
941 	int								selectLayer			(float r) const;
942 
943 	int								m_numLevels;
944 	const ConstPixelBufferAccess*	m_levels;
945 } DE_WARN_UNUSED_TYPE;
946 
947 /*--------------------------------------------------------------------*//*!
948  * \brief 1D Array Texture reference implementation
949  *//*--------------------------------------------------------------------*/
950 class Texture1DArray : private TextureLevelPyramid
951 {
952 public:
953 									Texture1DArray		(const TextureFormat& format, int width, int numLayers);
954 									Texture1DArray		(const Texture1DArray& other);
955 									~Texture1DArray		(void);
956 
getWidth(void) const957 	int								getWidth			(void) const	{ return m_width;		}
getNumLayers(void) const958 	int								getNumLayers		(void) const	{ return m_numLayers;	}
959 
960 	void							allocLevel			(int levelNdx);
961 
962 	using TextureLevelPyramid::getFormat;
963 	using TextureLevelPyramid::getNumLevels;
964 	using TextureLevelPyramid::getLevel;
965 	using TextureLevelPyramid::clearLevel;
966 	using TextureLevelPyramid::isLevelEmpty;
967 
968 	Vec4							sample				(const Sampler& sampler, float s, float t, float lod) const;
969 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
970 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float lod) const;
971 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
972 
973 	Texture1DArray&					operator=			(const Texture1DArray& other);
974 
operator Texture1DArrayView(void) const975 	operator Texture1DArrayView (void) const { return m_view; }
976 
977 private:
978 	int								m_width;
979 	int								m_numLayers;
980 	Texture1DArrayView				m_view;
981 } DE_WARN_UNUSED_TYPE;
982 
sample(const Sampler & sampler,float s,float t,float lod) const983 inline Vec4 Texture1DArray::sample (const Sampler& sampler, float s, float t, float lod) const
984 {
985 	return m_view.sample(sampler, s, t, lod);
986 }
987 
sampleOffset(const Sampler & sampler,float s,float t,float lod,deInt32 offset) const988 inline Vec4 Texture1DArray::sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const
989 {
990 	return m_view.sampleOffset(sampler, s, t, lod, offset);
991 }
992 
sampleCompare(const Sampler & sampler,float ref,float s,float t,float lod) const993 inline float Texture1DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
994 {
995 	return m_view.sampleCompare(sampler, ref, s, t, lod);
996 }
997 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float lod,deInt32 offset) const998 inline float Texture1DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const
999 {
1000 	return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
1001 }
1002 
1003 /*--------------------------------------------------------------------*//*!
1004  * \brief 2D Array Texture reference implementation
1005  *//*--------------------------------------------------------------------*/
1006 class Texture2DArray : private TextureLevelPyramid
1007 {
1008 public:
1009 									Texture2DArray		(const TextureFormat& format, int width, int height, int numLayers);
1010 									Texture2DArray		(const Texture2DArray& other);
1011 									~Texture2DArray		(void);
1012 
getWidth(void) const1013 	int								getWidth			(void) const	{ return m_width;		}
getHeight(void) const1014 	int								getHeight			(void) const	{ return m_height;		}
getNumLayers(void) const1015 	int								getNumLayers		(void) const	{ return m_numLayers;	}
1016 
1017 	void							allocLevel			(int levelNdx);
1018 
1019 	using TextureLevelPyramid::getFormat;
1020 	using TextureLevelPyramid::getNumLevels;
1021 	using TextureLevelPyramid::getLevel;
1022 	using TextureLevelPyramid::clearLevel;
1023 	using TextureLevelPyramid::isLevelEmpty;
1024 
1025 	Vec4							sample				(const Sampler& sampler, float s, float t, float r, float lod) const;
1026 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
1027 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
1028 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
1029 
1030 	Vec4							gatherOffsets		(const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
1031 	Vec4							gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
1032 
1033 	Texture2DArray&					operator=			(const Texture2DArray& other);
1034 
operator Texture2DArrayView(void) const1035 	operator Texture2DArrayView (void) const { return m_view; }
1036 
1037 private:
1038 	int								m_width;
1039 	int								m_height;
1040 	int								m_numLayers;
1041 	Texture2DArrayView				m_view;
1042 } DE_WARN_UNUSED_TYPE;
1043 
sample(const Sampler & sampler,float s,float t,float r,float lod) const1044 inline Vec4 Texture2DArray::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1045 {
1046 	return m_view.sample(sampler, s, t, r, lod);
1047 }
1048 
sampleOffset(const Sampler & sampler,float s,float t,float r,float lod,const IVec2 & offset) const1049 inline Vec4 Texture2DArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const
1050 {
1051 	return m_view.sampleOffset(sampler, s, t, r, lod, offset);
1052 }
1053 
sampleCompare(const Sampler & sampler,float ref,float s,float t,float r,float lod) const1054 inline float Texture2DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
1055 {
1056 	return m_view.sampleCompare(sampler, ref, s, t, r, lod);
1057 }
1058 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float r,float lod,const IVec2 & offset) const1059 inline float Texture2DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const
1060 {
1061 	return m_view.sampleCompareOffset(sampler, ref, s, t, r, lod, offset);
1062 }
1063 
gatherOffsets(const Sampler & sampler,float s,float t,float r,int componentNdx,const IVec2 (& offsets)[4]) const1064 inline Vec4 Texture2DArray::gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const
1065 {
1066 	return m_view.gatherOffsets(sampler, s, t, r, componentNdx, offsets);
1067 }
1068 
gatherOffsetsCompare(const Sampler & sampler,float ref,float s,float t,float r,const IVec2 (& offsets)[4]) const1069 inline Vec4 Texture2DArray::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const
1070 {
1071 	return m_view.gatherOffsetsCompare(sampler, ref, s, t, r, offsets);
1072 }
1073 
1074 /*--------------------------------------------------------------------*//*!
1075  * \brief 3D Texture View
1076  *//*--------------------------------------------------------------------*/
1077 class Texture3DView
1078 {
1079 public:
1080 									Texture3DView		(int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false);
1081 
getWidth(void) const1082 	int								getWidth			(void) const	{ return m_numLevels > 0 ? m_levels[0].getWidth()	: 0;	}
getHeight(void) const1083 	int								getHeight			(void) const	{ return m_numLevels > 0 ? m_levels[0].getHeight()	: 0;	}
getDepth(void) const1084 	int								getDepth			(void) const	{ return m_numLevels > 0 ? m_levels[0].getDepth()	: 0;	}
getNumLevels(void) const1085 	int								getNumLevels		(void) const	{ return m_numLevels;										}
getLevel(int ndx) const1086 	const ConstPixelBufferAccess&	getLevel			(int ndx) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];	}
getLevels(void) const1087 	const ConstPixelBufferAccess*	getLevels			(void) const	{ return m_levels;											}
isES2(void) const1088 	bool								isES2						(void) const	{ return false;												}
1089 
1090 	Vec4							sample				(const Sampler& sampler, float s, float t, float r, float lod) const;
1091 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
1092 
1093 protected:
1094 	int								m_numLevels;
1095 	const ConstPixelBufferAccess*	m_levels;
1096 } DE_WARN_UNUSED_TYPE;
1097 
sample(const Sampler & sampler,float s,float t,float r,float lod) const1098 inline Vec4 Texture3DView::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1099 {
1100 	return sampleLevelArray3D(m_levels, m_numLevels, sampler, s, t, r, lod);
1101 }
1102 
sampleOffset(const Sampler & sampler,float s,float t,float r,float lod,const IVec3 & offset) const1103 inline Vec4 Texture3DView::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
1104 {
1105 	return sampleLevelArray3DOffset(m_levels, m_numLevels, sampler, s, t, r, lod, offset);
1106 }
1107 
1108 /*--------------------------------------------------------------------*//*!
1109  * \brief 3D Texture reference implementation
1110  *//*--------------------------------------------------------------------*/
1111 class Texture3D : private TextureLevelPyramid
1112 {
1113 public:
1114 									Texture3D			(const TextureFormat& format, int width, int height, int depth);
1115 									Texture3D			(const Texture3D& other);
1116 									~Texture3D			(void);
1117 
getWidth(void) const1118 	int								getWidth			(void) const	{ return m_width;	}
getHeight(void) const1119 	int								getHeight			(void) const	{ return m_height;	}
getDepth(void) const1120 	int								getDepth			(void) const	{ return m_depth;	}
1121 
1122 	void							allocLevel			(int levelNdx);
1123 
1124 	using TextureLevelPyramid::getFormat;
1125 	using TextureLevelPyramid::getNumLevels;
1126 	using TextureLevelPyramid::getLevel;
1127 	using TextureLevelPyramid::clearLevel;
1128 	using TextureLevelPyramid::isLevelEmpty;
1129 
1130 	Vec4							sample				(const Sampler& sampler, float s, float t, float r, float lod) const;
1131 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
1132 
1133 	Texture3D&						operator=			(const Texture3D& other);
1134 
operator Texture3DView(void) const1135 	operator Texture3DView (void) const { return m_view; }
1136 
1137 private:
1138 	int								m_width;
1139 	int								m_height;
1140 	int								m_depth;
1141 	Texture3DView					m_view;
1142 } DE_WARN_UNUSED_TYPE;
1143 
sample(const Sampler & sampler,float s,float t,float r,float lod) const1144 inline Vec4 Texture3D::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1145 {
1146 	return m_view.sample(sampler, s, t, r, lod);
1147 }
1148 
sampleOffset(const Sampler & sampler,float s,float t,float r,float lod,const IVec3 & offset) const1149 inline Vec4 Texture3D::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
1150 {
1151 	return m_view.sampleOffset(sampler, s, t, r, lod, offset);
1152 }
1153 
1154 /*--------------------------------------------------------------------*//*!
1155  * \brief Cube Map Array Texture View
1156  *//*--------------------------------------------------------------------*/
1157 class TextureCubeArrayView
1158 {
1159 public:
1160 									TextureCubeArrayView	(int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false);
1161 
getSize(void) const1162 	int								getSize					(void) const	{ return m_numLevels > 0 ? m_levels[0].getWidth()	: 0;	}
getDepth(void) const1163 	int								getDepth				(void) const	{ return m_numLevels > 0 ? m_levels[0].getDepth()	: 0;	}
getNumLayers(void) const1164 	int								getNumLayers			(void) const	{ return getDepth()	/ 6;	}
getNumLevels(void) const1165 	int								getNumLevels			(void) const	{ return m_numLevels;										}
getLevel(int ndx) const1166 	const ConstPixelBufferAccess&	getLevel				(int ndx) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];	}
getLevels(void) const1167 	const ConstPixelBufferAccess*	getLevels				(void) const	{ return m_levels;											}
isES2(void) const1168 	bool									isES2						(void) const	{ return false;												}
1169 
1170 	Vec4							sample					(const Sampler& sampler, float s, float t, float r, float q, float lod) const;
1171 	Vec4							sampleOffset			(const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1172 	float							sampleCompare			(const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
1173 	float							sampleCompareOffset		(const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1174 
1175 protected:
1176 	int								selectLayer				(float q) const;
1177 
1178 	int								m_numLevels;
1179 	const ConstPixelBufferAccess*	m_levels;
1180 } DE_WARN_UNUSED_TYPE;
1181 
1182 /*--------------------------------------------------------------------*//*!
1183  * \brief Cube Map Array Texture reference implementation
1184  *//*--------------------------------------------------------------------*/
1185 class TextureCubeArray : private TextureLevelPyramid
1186 {
1187 public:
1188 									TextureCubeArray	(const TextureFormat& format, int size, int depth);
1189 									TextureCubeArray	(const TextureCubeArray& other);
1190 									~TextureCubeArray	(void);
1191 
getSize(void) const1192 	int								getSize				(void) const	{ return m_size;	}
getDepth(void) const1193 	int								getDepth			(void) const	{ return m_depth;	}
1194 
1195 	void							allocLevel			(int levelNdx);
1196 
1197 	using TextureLevelPyramid::getFormat;
1198 	using TextureLevelPyramid::getNumLevels;
1199 	using TextureLevelPyramid::getLevel;
1200 	using TextureLevelPyramid::clearLevel;
1201 	using TextureLevelPyramid::isLevelEmpty;
1202 
1203 	Vec4							sample				(const Sampler& sampler, float s, float t, float r, float q, float lod) const;
1204 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1205 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
1206 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1207 
1208 	TextureCubeArray&				operator=			(const TextureCubeArray& other);
1209 
operator TextureCubeArrayView(void) const1210 	operator TextureCubeArrayView (void) const { return m_view; }
1211 
1212 private:
1213 	int								m_size;
1214 	int								m_depth;
1215 	TextureCubeArrayView			m_view;
1216 } DE_WARN_UNUSED_TYPE;
1217 
sample(const Sampler & sampler,float s,float t,float r,float q,float lod) const1218 inline Vec4 TextureCubeArray::sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const
1219 {
1220 	return m_view.sample(sampler, s, t, r, q, lod);
1221 }
1222 
sampleOffset(const Sampler & sampler,float s,float t,float r,float q,float lod,const IVec2 & offset) const1223 inline Vec4 TextureCubeArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const
1224 {
1225 	return m_view.sampleOffset(sampler, s, t, r, q, lod, offset);
1226 }
1227 
sampleCompare(const Sampler & sampler,float ref,float s,float t,float r,float q,float lod) const1228 inline float TextureCubeArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const
1229 {
1230 	return m_view.sampleCompare(sampler, ref, s, t, r, q, lod);
1231 }
1232 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float r,float q,float lod,const IVec2 & offset) const1233 inline float TextureCubeArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const
1234 {
1235 	return m_view.sampleCompareOffset(sampler, ref, s, t, r, q, lod, offset);
1236 }
1237 
1238 // Stream operators.
1239 std::ostream&		operator<<		(std::ostream& str, TextureFormat::ChannelOrder order);
1240 std::ostream&		operator<<		(std::ostream& str, TextureFormat::ChannelType type);
1241 std::ostream&		operator<<		(std::ostream& str, TextureFormat format);
1242 std::ostream&		operator<<		(std::ostream& str, CubeFace face);
1243 std::ostream&		operator<<		(std::ostream& str, const ConstPixelBufferAccess& access);
1244 
1245 } // tcu
1246 
1247 #endif // _TCUTEXTURE_HPP
1248