• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _TCUTEXTURE_HPP
2 #define _TCUTEXTURE_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program Tester Core
5  * ----------------------------------------
6  *
7  * Copyright 2014 The Android Open Source Project
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief Reference Texture Implementation.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "tcuDefs.hpp"
27 #include "tcuVector.hpp"
28 #include "rrGenericVector.hpp"
29 #include "deArrayBuffer.hpp"
30 
31 #include <vector>
32 #include <ostream>
33 
34 namespace tcu
35 {
36 
37 /*--------------------------------------------------------------------*//*!
38  * \brief Texture format
39  *//*--------------------------------------------------------------------*/
40 class TextureFormat
41 {
42 public:
43 	enum ChannelOrder
44 	{
45 		R = 0,
46 		A,
47 		I,
48 		L,
49 		LA,
50 		RG,
51 		RA,
52 		RGB,
53 		RGBA,
54 		ARGB,
55 		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 
209 		NEAREST_MIPMAP_NEAREST,
210 		NEAREST_MIPMAP_LINEAR,
211 		LINEAR_MIPMAP_NEAREST,
212 		LINEAR_MIPMAP_LINEAR,
213 
214 		FILTERMODE_LAST
215 	};
216 
217 	enum ReductionMode
218 	{
219 		WEIGHTED_AVERAGE = 0,
220 		MIN,
221 		MAX,
222 
223 		REDUCTIONMODE_LAST
224 	};
225 
226 	enum CompareMode
227 	{
228 		COMPAREMODE_NONE = 0,
229 		COMPAREMODE_LESS,
230 		COMPAREMODE_LESS_OR_EQUAL,
231 		COMPAREMODE_GREATER,
232 		COMPAREMODE_GREATER_OR_EQUAL,
233 		COMPAREMODE_EQUAL,
234 		COMPAREMODE_NOT_EQUAL,
235 		COMPAREMODE_ALWAYS,
236 		COMPAREMODE_NEVER,
237 
238 		COMPAREMODE_LAST
239 	};
240 
241 	enum DepthStencilMode
242 	{
243 		MODE_DEPTH = 0,
244 		MODE_STENCIL,
245 
246 		MODE_LAST
247 	};
248 
249 	// Wrap control
250 	WrapMode			wrapS;
251 	WrapMode			wrapT;
252 	WrapMode			wrapR;
253 
254 	// Minifcation & magnification
255 	FilterMode			minFilter;
256 	FilterMode			magFilter;
257 
258 	// min/max filtering reduction
259 	ReductionMode		reductionMode;
260 
261 	float				lodThreshold;		// lod <= lodThreshold ? magnified : minified
262 
263 	// Coordinate normalization
264 	bool				normalizedCoords;
265 
266 	// Shadow comparison
267 	CompareMode			compare;
268 	int					compareChannel;
269 
270 	// Border color.
271 	// \note It is setter's responsibility to guarantee that the values are representable
272 	//       in sampled texture's internal format.
273 	// \note It is setter's responsibility to guarantee that the format is compatible with the
274 	//       sampled texture's internal format. Otherwise results are undefined.
275 	rr::GenericVec4		borderColor;
276 
277 	// Seamless cube map filtering
278 	bool				seamlessCubeMap;
279 
280 	// Depth stencil mode
281 	DepthStencilMode	depthStencilMode;
282 
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)283 	Sampler (WrapMode			wrapS_,
284 			 WrapMode			wrapT_,
285 			 WrapMode			wrapR_,
286 			 FilterMode			minFilter_,
287 			 FilterMode			magFilter_,
288 			 float				lodThreshold_		= 0.0f,
289 			 bool				normalizedCoords_	= true,
290 			 CompareMode		compare_			= COMPAREMODE_NONE,
291 			 int				compareChannel_		= 0,
292 			 const Vec4&		borderColor_		= Vec4(0.0f, 0.0f, 0.0f, 0.0f),
293 			 bool				seamlessCubeMap_	= false,
294 			 DepthStencilMode	depthStencilMode_	= MODE_DEPTH,
295 			 ReductionMode		reductionMode_		= WEIGHTED_AVERAGE)
296 		: wrapS				(wrapS_)
297 		, wrapT				(wrapT_)
298 		, wrapR				(wrapR_)
299 		, minFilter			(minFilter_)
300 		, magFilter			(magFilter_)
301 		, reductionMode		(reductionMode_)
302 		, lodThreshold		(lodThreshold_)
303 		, normalizedCoords	(normalizedCoords_)
304 		, compare			(compare_)
305 		, compareChannel	(compareChannel_)
306 		, borderColor		(borderColor_)
307 		, seamlessCubeMap	(seamlessCubeMap_)
308 		, depthStencilMode	(depthStencilMode_)
309 	{
310 	}
311 
Sampler(void)312 	Sampler (void)
313 		: wrapS				(WRAPMODE_LAST)
314 		, wrapT				(WRAPMODE_LAST)
315 		, wrapR				(WRAPMODE_LAST)
316 		, minFilter			(FILTERMODE_LAST)
317 		, magFilter			(FILTERMODE_LAST)
318 		, reductionMode		(REDUCTIONMODE_LAST)
319 		, lodThreshold		(0.0f)
320 		, normalizedCoords	(true)
321 		, compare			(COMPAREMODE_NONE)
322 		, compareChannel	(0)
323 		, borderColor		(Vec4(0.0f, 0.0f, 0.0f, 0.0f))
324 		, seamlessCubeMap	(false)
325 		, depthStencilMode	(MODE_DEPTH)
326 	{
327 	}
328 } DE_WARN_UNUSED_TYPE;
329 
330 // Calculate pitches for pixel data with no padding.
331 IVec3 calculatePackedPitch (const TextureFormat& format, const IVec3& size);
332 
333 class TextureLevel;
334 
335 /*--------------------------------------------------------------------*//*!
336  * \brief Read-only pixel data access
337  *
338  * ConstPixelBufferAccess encapsulates pixel data pointer along with
339  * format and layout information. It can be used for read-only access
340  * to arbitrary pixel buffers.
341  *
342  * Access objects are like iterators or pointers. They can be passed around
343  * as values and are valid as long as the storage doesn't change.
344  *//*--------------------------------------------------------------------*/
345 class ConstPixelBufferAccess
346 {
347 public:
348 							ConstPixelBufferAccess		(void);
349 							ConstPixelBufferAccess		(const TextureLevel& level);
350 							ConstPixelBufferAccess		(const TextureFormat& format, int width, int height, int depth, const void* data);
351 							ConstPixelBufferAccess		(const TextureFormat& format, const IVec3& size, const void* data);
352 							ConstPixelBufferAccess		(const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, const void* data);
353 							ConstPixelBufferAccess		(const TextureFormat& format, const IVec3& size, const IVec3& pitch, const void* data);
354 							ConstPixelBufferAccess		(const TextureFormat& format, const IVec3& size, const IVec3& pitch, const IVec3& divider, const void* data);
355 
getFormat(void) const356 	const TextureFormat&	getFormat					(void) const	{ return m_format;					}
getSize(void) const357 	const IVec3&			getSize						(void) const	{ return m_size;					}
getWidth(void) const358 	int						getWidth					(void) const	{ return m_size.x();				}
getHeight(void) const359 	int						getHeight					(void) const	{ return m_size.y();				}
getDepth(void) const360 	int						getDepth					(void) const	{ return m_size.z();				}
getPixelPitch(void) const361 	int						getPixelPitch				(void) const	{ return m_pitch.x();				}
getRowPitch(void) const362 	int						getRowPitch					(void) const	{ return m_pitch.y();				}
getSlicePitch(void) const363 	int						getSlicePitch				(void) const	{ return m_pitch.z();				}
getPitch(void) const364 	const IVec3&			getPitch					(void) const	{ return m_pitch;					}
getDivider(void) const365 	const IVec3&			getDivider					(void) const	{ return m_divider;					}
366 
getDataPtr(void) const367 	const void*				getDataPtr					(void) const	{ return m_data;					}
getPixelPtr(int x,int y,int z=0) const368 	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(); }
369 
370 	Vec4					getPixel					(int x, int y, int z = 0) const;
371 	IVec4					getPixelInt					(int x, int y, int z = 0) const;
getPixelUint(int x,int y,int z=0) const372 	UVec4					getPixelUint				(int x, int y, int z = 0) const { return getPixelInt(x, y, z).cast<deUint32>(); }
373 
374 	template<typename T>
375 	Vector<T, 4>			getPixelT					(int x, int y, int z = 0) const;
376 
377 	float					getPixDepth					(int x, int y, int z = 0) const;
378 	int						getPixStencil				(int x, int y, int z = 0) const;
379 
380 	Vec4					sample1D					(const Sampler& sampler, Sampler::FilterMode filter, float s, int level) const;
381 	Vec4					sample2D					(const Sampler& sampler, Sampler::FilterMode filter, float s, float t, int depth) const;
382 	Vec4					sample3D					(const Sampler& sampler, Sampler::FilterMode filter, float s, float t, float r) const;
383 
384 	Vec4					sample1DOffset				(const Sampler& sampler, Sampler::FilterMode filter, float s, const IVec2& offset) const;
385 	Vec4					sample2DOffset				(const Sampler& sampler, Sampler::FilterMode filter, float s, float t, const IVec3& offset) const;
386 	Vec4					sample3DOffset				(const Sampler& sampler, Sampler::FilterMode filter, float s, float t, float r, const IVec3& offset) const;
387 
388 	float					sample1DCompare				(const Sampler& sampler, Sampler::FilterMode filter, float ref, float s, const IVec2& offset) const;
389 	float					sample2DCompare				(const Sampler& sampler, Sampler::FilterMode filter, float ref, float s, float t, const IVec3& offset) const;
390 
391 protected:
392 	TextureFormat			m_format;
393 	IVec3					m_size;
394 	IVec3					m_pitch;	//!< (pixelPitch, rowPitch, slicePitch)
395 	IVec3					m_divider;
396 	mutable void*			m_data;
397 } DE_WARN_UNUSED_TYPE;
398 
399 /*--------------------------------------------------------------------*//*!
400  * \brief Read-write pixel data access
401  *
402  * This class extends read-only access object by providing write functionality.
403  *
404  * \note PixelBufferAccess may not have any data members nor add any
405  *		 virtual functions. It must be possible to reinterpret_cast<>
406  *		 PixelBufferAccess to ConstPixelBufferAccess.
407  *//*--------------------------------------------------------------------*/
408 class PixelBufferAccess : public ConstPixelBufferAccess
409 {
410 public:
PixelBufferAccess(void)411 						PixelBufferAccess	(void) {}
412 						PixelBufferAccess	(TextureLevel& level);
413 						PixelBufferAccess	(const TextureFormat& format, int width, int height, int depth, void* data);
414 						PixelBufferAccess	(const TextureFormat& format, const IVec3& size, void* data);
415 						PixelBufferAccess	(const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, void* data);
416 						PixelBufferAccess	(const TextureFormat& format, const IVec3& size, const IVec3& pitch, void* data);
417 						PixelBufferAccess	(const TextureFormat& format, const IVec3& size, const IVec3& pitch, const IVec3& block, void* data);
418 
getDataPtr(void) const419 	void*				getDataPtr			(void) const { return m_data; }
getPixelPtr(int x,int y,int z=0) const420 	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(); }
421 
422 	void				setPixel			(const tcu::Vec4& color, int x, int y, int z = 0) const;
423 	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) const424 	void				setPixel			(const tcu::UVec4& color, int x, int y, int z = 0) const { setPixel(color.cast<int>(), x, y, z); }
425 
426 	void				setPixDepth			(float depth, int x, int y, int z = 0) const;
427 	void				setPixStencil		(int stencil, int x, int y, int z = 0) const;
428 } DE_WARN_UNUSED_TYPE;
429 
430 /*--------------------------------------------------------------------*//*!
431  * \brief Generic pixel data container
432  *
433  * This container supports all valid TextureFormat combinations and
434  * both 2D and 3D textures. To read or manipulate data access object must
435  * be queried using getAccess().
436  *//*--------------------------------------------------------------------*/
437 class TextureLevel
438 {
439 public:
440 								TextureLevel		(void);
441 								TextureLevel		(const TextureFormat& format);
442 								TextureLevel		(const TextureFormat& format, int width, int height, int depth = 1);
443 								~TextureLevel		(void);
444 
getSize(void) const445 	const IVec3&				getSize				(void) const	{ return m_size;		}
getWidth(void) const446 	int							getWidth			(void) const	{ return m_size.x();	}
getHeight(void) const447 	int							getHeight			(void) const	{ return m_size.y();	}
getDepth(void) const448 	int							getDepth			(void) const	{ return m_size.z();	}
isEmpty(void) const449 	bool						isEmpty				(void) const	{ return m_size.x() * m_size.y() * m_size.z() == 0; }
getFormat(void) const450 	const TextureFormat			getFormat			(void) const	{ return m_format;	}
451 
452 	void						setStorage			(const TextureFormat& format, int width, int heigth, int depth = 1);
453 	void						setSize				(int width, int height, int depth = 1);
454 
getAccess(void)455 	PixelBufferAccess			getAccess			(void)			{ return isEmpty() ? PixelBufferAccess() : PixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr());			}
getAccess(void) const456 	ConstPixelBufferAccess		getAccess			(void) const	{ return isEmpty() ? ConstPixelBufferAccess() : ConstPixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr());	}
457 
458 private:
getPtr(void)459 	void*						getPtr				(void)			{ return m_data.getPtr(); }
getPtr(void) const460 	const void*					getPtr				(void) const	{ return m_data.getPtr(); }
461 
462 	TextureFormat				m_format;
463 	IVec3						m_size;
464 	de::ArrayBuffer<deUint8>	m_data;
465 
466 	friend class ConstPixelBufferAccess;
467 } DE_WARN_UNUSED_TYPE;
468 
469 Vec4	sampleLevelArray1D				(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, int level, float lod);
470 Vec4	sampleLevelArray2D				(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, int depth, float lod);
471 Vec4	sampleLevelArray3D				(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float r, float lod);
472 
473 Vec4	sampleLevelArray1DOffset		(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float lod, const IVec2& offset);
474 Vec4	sampleLevelArray2DOffset		(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float lod, const IVec3& offset);
475 Vec4	sampleLevelArray3DOffset		(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset);
476 
477 float	sampleLevelArray1DCompare		(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float ref, float s, float lod, const IVec2& offset);
478 float	sampleLevelArray2DCompare		(const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float ref, float s, float t, float lod, const IVec3& offset);
479 
480 Vec4	gatherArray2DOffsets			(const ConstPixelBufferAccess& src, const Sampler& sampler, float s, float t, int depth, int componentNdx, const IVec2 (&offsets)[4]);
481 Vec4	gatherArray2DOffsetsCompare		(const ConstPixelBufferAccess& src, const Sampler& sampler, float ref, float s, float t, int depth, const IVec2 (&offsets)[4]);
482 
483 enum CubeFace
484 {
485 	CUBEFACE_NEGATIVE_X = 0,
486 	CUBEFACE_POSITIVE_X,
487 	CUBEFACE_NEGATIVE_Y,
488 	CUBEFACE_POSITIVE_Y,
489 	CUBEFACE_NEGATIVE_Z,
490 	CUBEFACE_POSITIVE_Z,
491 
492 	CUBEFACE_LAST
493 };
494 
495 /*--------------------------------------------------------------------*//*!
496  * \brief Coordinates projected onto cube face.
497  *//*--------------------------------------------------------------------*/
498 template<typename T>
499 struct CubeFaceCoords
500 {
501 	CubeFace		face;
502 	T				s;
503 	T				t;
504 
CubeFaceCoordstcu::CubeFaceCoords505 					CubeFaceCoords		(CubeFace face_, T s_, T t_) : face(face_), s(s_), t(t_) {}
CubeFaceCoordstcu::CubeFaceCoords506 					CubeFaceCoords		(CubeFace face_, const Vector<T, 2>& c) : face(face_), s(c.x()), t(c.y()) {}
507 } DE_WARN_UNUSED_TYPE;
508 
509 typedef CubeFaceCoords<float>	CubeFaceFloatCoords;
510 typedef CubeFaceCoords<int>		CubeFaceIntCoords;
511 
512 CubeFace				selectCubeFace			(const Vec3& coords);
513 Vec2					projectToFace			(CubeFace face, const Vec3& coords);
514 CubeFaceFloatCoords		getCubeFaceCoords		(const Vec3& coords);
515 CubeFaceIntCoords		remapCubeEdgeCoords		(const CubeFaceIntCoords& coords, int size);
516 
517 /*--------------------------------------------------------------------*//*!
518  * \brief 1D Texture View
519  *//*--------------------------------------------------------------------*/
520 class Texture1DView
521 {
522 public:
523 									Texture1DView		(int numLevels, const ConstPixelBufferAccess* levels);
524 
getNumLevels(void) const525 	int								getNumLevels		(void) const	{ return m_numLevels;										}
getWidth(void) const526 	int								getWidth			(void) const	{ return m_numLevels > 0 ? m_levels[0].getWidth()	: 0;	}
getLevel(int ndx) const527 	const ConstPixelBufferAccess&	getLevel			(int ndx) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];	}
getLevels(void) const528 	const ConstPixelBufferAccess*	getLevels			(void) const	{ return m_levels;											}
529 
530 	Vec4							sample				(const Sampler& sampler, float s, float lod) const;
531 	Vec4							sampleOffset		(const Sampler& sampler, float s, float lod, deInt32 offset) const;
532 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float lod) const;
533 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const;
534 
535 protected:
536 	int								m_numLevels;
537 	const ConstPixelBufferAccess*	m_levels;
538 } DE_WARN_UNUSED_TYPE;
539 
Texture1DView(int numLevels,const ConstPixelBufferAccess * levels)540 inline Texture1DView::Texture1DView (int numLevels, const ConstPixelBufferAccess* levels)
541 	: m_numLevels	(numLevels)
542 	, m_levels		(levels)
543 {
544 	DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
545 }
546 
sample(const Sampler & sampler,float s,float lod) const547 inline Vec4 Texture1DView::sample (const Sampler& sampler, float s, float lod) const
548 {
549 	return sampleLevelArray1D(m_levels, m_numLevels, sampler, s, 0 /* depth */, lod);
550 }
551 
sampleOffset(const Sampler & sampler,float s,float lod,deInt32 offset) const552 inline Vec4 Texture1DView::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
553 {
554 	return sampleLevelArray1DOffset(m_levels, m_numLevels, sampler, s, lod, IVec2(offset, 0));
555 }
556 
sampleCompare(const Sampler & sampler,float ref,float s,float lod) const557 inline float Texture1DView::sampleCompare (const Sampler& sampler, float ref, float s, float lod) const
558 {
559 	return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(0, 0));
560 }
561 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float lod,deInt32 offset) const562 inline float Texture1DView::sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const
563 {
564 	return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(offset, 0));
565 }
566 
567 /*--------------------------------------------------------------------*//*!
568  * \brief 2D Texture View
569  *//*--------------------------------------------------------------------*/
570 class Texture2DView
571 {
572 public:
573 									Texture2DView		(int numLevels, const ConstPixelBufferAccess* levels);
574 
getNumLevels(void) const575 	int								getNumLevels		(void) const	{ return m_numLevels;										}
getWidth(void) const576 	int								getWidth			(void) const	{ return m_numLevels > 0 ? m_levels[0].getWidth()	: 0;	}
getHeight(void) const577 	int								getHeight			(void) const	{ return m_numLevels > 0 ? m_levels[0].getHeight()	: 0;	}
getLevel(int ndx) const578 	const ConstPixelBufferAccess&	getLevel			(int ndx) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];	}
getLevels(void) const579 	const ConstPixelBufferAccess*	getLevels			(void) const	{ return m_levels;											}
580 
581 	Vec4							sample				(const Sampler& sampler, float s, float t, float lod) const;
582 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
583 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float lod) const;
584 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
585 
586 	Vec4							gatherOffsets		(const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
587 	Vec4							gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
588 
589 protected:
590 	int								m_numLevels;
591 	const ConstPixelBufferAccess*	m_levels;
592 } DE_WARN_UNUSED_TYPE;
593 
Texture2DView(int numLevels,const ConstPixelBufferAccess * levels)594 inline Texture2DView::Texture2DView (int numLevels, const ConstPixelBufferAccess* levels)
595 	: m_numLevels	(numLevels)
596 	, m_levels		(levels)
597 {
598 	DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
599 }
600 
sample(const Sampler & sampler,float s,float t,float lod) const601 inline Vec4 Texture2DView::sample (const Sampler& sampler, float s, float t, float lod) const
602 {
603 	return sampleLevelArray2D(m_levels, m_numLevels, sampler, s, t, 0 /* depth */, lod);
604 }
605 
sampleOffset(const Sampler & sampler,float s,float t,float lod,const IVec2 & offset) const606 inline Vec4 Texture2DView::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
607 {
608 	return sampleLevelArray2DOffset(m_levels, m_numLevels, sampler, s, t, lod, IVec3(offset.x(), offset.y(), 0));
609 }
610 
sampleCompare(const Sampler & sampler,float ref,float s,float t,float lod) const611 inline float Texture2DView::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
612 {
613 	return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(0, 0, 0));
614 }
615 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float lod,const IVec2 & offset) const616 inline float Texture2DView::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
617 {
618 	return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(offset.x(), offset.y(), 0));
619 }
620 
gatherOffsets(const Sampler & sampler,float s,float t,int componentNdx,const IVec2 (& offsets)[4]) const621 inline Vec4 Texture2DView::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
622 {
623 	return gatherArray2DOffsets(m_levels[0], sampler, s, t, 0, componentNdx, offsets);
624 }
625 
gatherOffsetsCompare(const Sampler & sampler,float ref,float s,float t,const IVec2 (& offsets)[4]) const626 inline Vec4 Texture2DView::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
627 {
628 	return gatherArray2DOffsetsCompare(m_levels[0], sampler, ref, s, t, 0, offsets);
629 }
630 
631 /*--------------------------------------------------------------------*//*!
632  * \brief Base class for textures that have single mip-map pyramid
633  *//*--------------------------------------------------------------------*/
634 class TextureLevelPyramid
635 {
636 public:
637 									TextureLevelPyramid	(const TextureFormat& format, int numLevels);
638 									TextureLevelPyramid	(const TextureLevelPyramid& other);
639 									~TextureLevelPyramid(void);
640 
getFormat(void) const641 	const TextureFormat&			getFormat			(void) const			{ return m_format;					}
getNumLevels(void) const642 	int								getNumLevels		(void) const			{ return (int)m_access.size();		}
643 
isLevelEmpty(int levelNdx) const644 	bool							isLevelEmpty		(int levelNdx) const	{ DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[(size_t)levelNdx].empty();	}
getLevel(int levelNdx) const645 	const ConstPixelBufferAccess&	getLevel			(int levelNdx) const	{ DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_access[(size_t)levelNdx];			}
getLevel(int levelNdx)646 	const PixelBufferAccess&		getLevel			(int levelNdx)			{ DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_access[(size_t)levelNdx];			}
647 
getLevels(void) const648 	const ConstPixelBufferAccess*	getLevels			(void) const			{ return &m_access[0];				}
getLevels(void)649 	const PixelBufferAccess*		getLevels			(void)					{ return &m_access[0];				}
650 
651 	void							allocLevel			(int levelNdx, int width, int height, int depth);
652 	void							clearLevel			(int levelNdx);
653 
654 	TextureLevelPyramid&			operator=			(const TextureLevelPyramid& other);
655 
656 private:
657 	typedef de::ArrayBuffer<deUint8> LevelData;
658 
659 	TextureFormat					m_format;
660 	std::vector<LevelData>			m_data;
661 	std::vector<PixelBufferAccess>	m_access;
662 } DE_WARN_UNUSED_TYPE;
663 
664 /*--------------------------------------------------------------------*//*!
665  * \brief 1D Texture reference implementation
666  *//*--------------------------------------------------------------------*/
667 class Texture1D : private TextureLevelPyramid
668 {
669 public:
670 									Texture1D			(const TextureFormat& format, int width);
671 									Texture1D			(const Texture1D& other);
672 									~Texture1D			(void);
673 
getWidth(void) const674 	int								getWidth			(void) const	{ return m_width;	}
getView(void) const675 	const Texture1DView&			getView				(void) const	{ return m_view;	}
676 
677 	void							allocLevel			(int levelNdx);
678 
679 	// Sampling
680 	Vec4							sample				(const Sampler& sampler, float s, float lod) const;
681 	Vec4							sampleOffset		(const Sampler& sampler, float s, float lod, deInt32 offset) const;
682 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float lod) const;
683 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const;
684 
685 	using TextureLevelPyramid::getFormat;
686 	using TextureLevelPyramid::getNumLevels;
687 	using TextureLevelPyramid::getLevel;
688 	using TextureLevelPyramid::clearLevel;
689 	using TextureLevelPyramid::isLevelEmpty;
690 
691 	Texture1D&						operator=			(const Texture1D& other);
692 
operator Texture1DView(void) const693 	operator Texture1DView (void) const { return m_view; }
694 
695 private:
696 	int								m_width;
697 	Texture1DView					m_view;
698 } DE_WARN_UNUSED_TYPE;
699 
sample(const Sampler & sampler,float s,float lod) const700 inline Vec4 Texture1D::sample (const Sampler& sampler, float s, float lod) const
701 {
702 	return m_view.sample(sampler, s, lod);
703 }
704 
sampleOffset(const Sampler & sampler,float s,float lod,deInt32 offset) const705 inline Vec4 Texture1D::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
706 {
707 	return m_view.sampleOffset(sampler, s, lod, offset);
708 }
709 
sampleCompare(const Sampler & sampler,float ref,float s,float lod) const710 inline float Texture1D::sampleCompare (const Sampler& sampler, float ref, float s, float lod) const
711 {
712 	return m_view.sampleCompare(sampler, ref, s, lod);
713 }
714 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float lod,deInt32 offset) const715 inline float Texture1D::sampleCompareOffset	(const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const
716 {
717 	return m_view.sampleCompareOffset(sampler, ref, s, lod, offset);
718 }
719 
720 /*--------------------------------------------------------------------*//*!
721  * \brief 2D Texture reference implementation
722  *//*--------------------------------------------------------------------*/
723 class Texture2D : private TextureLevelPyramid
724 {
725 public:
726 									Texture2D			(const TextureFormat& format, int width, int height);
727 									Texture2D			(const TextureFormat& format, int width, int height, int mipmaps);
728 									Texture2D			(const Texture2D& other);
729 									~Texture2D			(void);
730 
getWidth(void) const731 	int								getWidth			(void) const	{ return m_width;	}
getHeight(void) const732 	int								getHeight			(void) const	{ return m_height;	}
getView(void) const733 	const Texture2DView&			getView				(void) const	{ return m_view;	}
734 
735 	void							allocLevel			(int levelNdx);
736 
737 	// Sampling
738 	Vec4							sample				(const Sampler& sampler, float s, float t, float lod) const;
739 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
740 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float lod) const;
741 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
742 
743 	Vec4							gatherOffsets		(const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
744 	Vec4							gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
745 
746 	using TextureLevelPyramid::getFormat;
747 	using TextureLevelPyramid::getNumLevels;
748 	using TextureLevelPyramid::getLevel;
749 	using TextureLevelPyramid::clearLevel;
750 	using TextureLevelPyramid::isLevelEmpty;
751 
752 	Texture2D&						operator=			(const Texture2D& other);
753 
operator Texture2DView(void) const754 	operator Texture2DView (void) const { return m_view; }
755 
756 private:
757 	int								m_width;
758 	int								m_height;
759 	Texture2DView					m_view;
760 } DE_WARN_UNUSED_TYPE;
761 
sample(const Sampler & sampler,float s,float t,float lod) const762 inline Vec4 Texture2D::sample (const Sampler& sampler, float s, float t, float lod) const
763 {
764 	return m_view.sample(sampler, s, t, lod);
765 }
766 
sampleOffset(const Sampler & sampler,float s,float t,float lod,const IVec2 & offset) const767 inline Vec4 Texture2D::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
768 {
769 	return m_view.sampleOffset(sampler, s, t, lod, offset);
770 }
771 
sampleCompare(const Sampler & sampler,float ref,float s,float t,float lod) const772 inline float Texture2D::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
773 {
774 	return m_view.sampleCompare(sampler, ref, s, t, lod);
775 }
776 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float lod,const IVec2 & offset) const777 inline float Texture2D::sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
778 {
779 	return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
780 }
781 
gatherOffsets(const Sampler & sampler,float s,float t,int componentNdx,const IVec2 (& offsets)[4]) const782 inline Vec4 Texture2D::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
783 {
784 	return m_view.gatherOffsets(sampler, s, t, componentNdx, offsets);
785 }
786 
gatherOffsetsCompare(const Sampler & sampler,float ref,float s,float t,const IVec2 (& offsets)[4]) const787 inline Vec4 Texture2D::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
788 {
789 	return m_view.gatherOffsetsCompare(sampler, ref, s, t, offsets);
790 }
791 
792 /*--------------------------------------------------------------------*//*!
793  * \brief Cube Map Texture View
794  *//*--------------------------------------------------------------------*/
795 class TextureCubeView
796 {
797 public:
798 									TextureCubeView		(void);
799 									TextureCubeView		(int numLevels, const ConstPixelBufferAccess* const (&levels)[CUBEFACE_LAST]);
800 
getNumLevels(void) const801 	int								getNumLevels		(void) const	{ return m_numLevels;										}
getSize(void) const802 	int								getSize				(void) const	{ return m_numLevels > 0 ? m_levels[0][0].getWidth() : 0;	}
getLevelFace(int ndx,CubeFace face) const803 	const ConstPixelBufferAccess&	getLevelFace		(int ndx, CubeFace face) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[face][ndx];	}
getFaceLevels(CubeFace face) const804 	const ConstPixelBufferAccess*	getFaceLevels		(CubeFace face) const			{ return m_levels[face];					}
805 
806 	Vec4							sample				(const Sampler& sampler, float s, float t, float p, float lod) const;
807 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
808 
809 	Vec4							gather				(const Sampler& sampler, float s, float t, float r, int componentNdx) const;
810 	Vec4							gatherCompare		(const Sampler& sampler, float ref, float s, float t, float r) const;
811 
812 protected:
813 	int								m_numLevels;
814 	const ConstPixelBufferAccess*	m_levels[CUBEFACE_LAST];
815 } DE_WARN_UNUSED_TYPE;
816 
817 /*--------------------------------------------------------------------*//*!
818  * \brief Cube Map Texture reference implementation
819  *//*--------------------------------------------------------------------*/
820 class TextureCube
821 {
822 public:
823 									TextureCube			(const TextureFormat& format, int size);
824 									TextureCube			(const TextureCube& other);
825 									~TextureCube		(void);
826 
getFormat(void) const827 	const TextureFormat&			getFormat			(void) const	{ return m_format;	}
getSize(void) const828 	int								getSize				(void) const	{ return m_size;	}
829 
getNumLevels(void) const830 	int								getNumLevels		(void) const					{ return (int)m_access[0].size();	}
getLevelFace(int ndx,CubeFace face) const831 	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)832 	const PixelBufferAccess&		getLevelFace		(int ndx, CubeFace face)		{ DE_ASSERT(de::inBounds(ndx, 0, getNumLevels())); return m_access[face][(size_t)ndx];	}
833 
834 	void							allocLevel			(CubeFace face, int levelNdx);
835 	void							clearLevel			(CubeFace face, int levelNdx);
isLevelEmpty(CubeFace face,int levelNdx) const836 	bool							isLevelEmpty		(CubeFace face, int levelNdx) const	{ DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[face][(size_t)levelNdx].empty();	}
837 
838 	Vec4							sample				(const Sampler& sampler, float s, float t, float p, float lod) const;
839 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
840 
841 	Vec4							gather				(const Sampler& sampler, float s, float t, float r, int componentNdx) const;
842 	Vec4							gatherCompare		(const Sampler& sampler, float ref, float s, float t, float r) const;
843 
844 	TextureCube&					operator=			(const TextureCube& other);
845 
operator TextureCubeView(void) const846 	operator TextureCubeView (void) const { return m_view; }
847 
848 private:
849 	typedef de::ArrayBuffer<deUint8> LevelData;
850 
851 	TextureFormat					m_format;
852 	int								m_size;
853 	std::vector<LevelData>			m_data[CUBEFACE_LAST];
854 	std::vector<PixelBufferAccess>	m_access[CUBEFACE_LAST];
855 	TextureCubeView					m_view;
856 } DE_WARN_UNUSED_TYPE;
857 
sample(const Sampler & sampler,float s,float t,float p,float lod) const858 inline Vec4 TextureCube::sample (const Sampler& sampler, float s, float t, float p, float lod) const
859 {
860 	return m_view.sample(sampler, s, t, p, lod);
861 }
862 
sampleCompare(const Sampler & sampler,float ref,float s,float t,float r,float lod) const863 inline float TextureCube::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
864 {
865 	return m_view.sampleCompare(sampler, ref, s, t, r, lod);
866 }
867 
gather(const Sampler & sampler,float s,float t,float r,int componentNdx) const868 inline Vec4 TextureCube::gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const
869 {
870 	return m_view.gather(sampler, s, t, r, componentNdx);
871 }
872 
gatherCompare(const Sampler & sampler,float ref,float s,float t,float r) const873 inline Vec4 TextureCube::gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const
874 {
875 	return m_view.gatherCompare(sampler, ref, s, t, r);
876 }
877 
878 /*--------------------------------------------------------------------*//*!
879  * \brief 1D Array Texture View
880  *//*--------------------------------------------------------------------*/
881 class Texture1DArrayView
882 {
883 public:
884 									Texture1DArrayView	(int numLevels, const ConstPixelBufferAccess* levels);
885 
getWidth(void) const886 	int								getWidth			(void) const	{ return m_numLevels > 0 ? m_levels[0].getWidth()	: 0;	}
getNumLayers(void) const887 	int								getNumLayers		(void) const	{ return m_numLevels > 0 ? m_levels[0].getHeight()	: 0;	}
getNumLevels(void) const888 	int								getNumLevels		(void) const	{ return m_numLevels;										}
getLevel(int ndx) const889 	const ConstPixelBufferAccess&	getLevel			(int ndx) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];	}
getLevels(void) const890 	const ConstPixelBufferAccess*	getLevels			(void) const	{ return m_levels;											}
891 
892 	Vec4							sample				(const Sampler& sampler, float s, float t, float lod) const;
893 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
894 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float lod) const;
895 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
896 
897 protected:
898 	int								selectLayer			(float r) const;
899 
900 	int								m_numLevels;
901 	const ConstPixelBufferAccess*	m_levels;
902 } DE_WARN_UNUSED_TYPE;
903 
904 /*--------------------------------------------------------------------*//*!
905  * \brief 2D Array Texture View
906  *//*--------------------------------------------------------------------*/
907 class Texture2DArrayView
908 {
909 public:
910 									Texture2DArrayView	(int numLevels, const ConstPixelBufferAccess* levels);
911 
getWidth(void) const912 	int								getWidth			(void) const	{ return m_numLevels > 0 ? m_levels[0].getWidth()	: 0;	}
getHeight(void) const913 	int								getHeight			(void) const	{ return m_numLevels > 0 ? m_levels[0].getHeight()	: 0;	}
getNumLayers(void) const914 	int								getNumLayers		(void) const	{ return m_numLevels > 0 ? m_levels[0].getDepth()	: 0;	}
getNumLevels(void) const915 	int								getNumLevels		(void) const	{ return m_numLevels;										}
getLevel(int ndx) const916 	const ConstPixelBufferAccess&	getLevel			(int ndx) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];	}
getLevels(void) const917 	const ConstPixelBufferAccess*	getLevels			(void) const	{ return m_levels;											}
918 
919 	Vec4							sample				(const Sampler& sampler, float s, float t, float r, float lod) const;
920 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
921 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
922 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
923 
924 	Vec4							gatherOffsets		(const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
925 	Vec4							gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
926 
927 protected:
928 	int								selectLayer			(float r) const;
929 
930 	int								m_numLevels;
931 	const ConstPixelBufferAccess*	m_levels;
932 } DE_WARN_UNUSED_TYPE;
933 
934 /*--------------------------------------------------------------------*//*!
935  * \brief 1D Array Texture reference implementation
936  *//*--------------------------------------------------------------------*/
937 class Texture1DArray : private TextureLevelPyramid
938 {
939 public:
940 									Texture1DArray		(const TextureFormat& format, int width, int numLayers);
941 									Texture1DArray		(const Texture1DArray& other);
942 									~Texture1DArray		(void);
943 
getWidth(void) const944 	int								getWidth			(void) const	{ return m_width;		}
getNumLayers(void) const945 	int								getNumLayers		(void) const	{ return m_numLayers;	}
946 
947 	void							allocLevel			(int levelNdx);
948 
949 	using TextureLevelPyramid::getFormat;
950 	using TextureLevelPyramid::getNumLevels;
951 	using TextureLevelPyramid::getLevel;
952 	using TextureLevelPyramid::clearLevel;
953 	using TextureLevelPyramid::isLevelEmpty;
954 
955 	Vec4							sample				(const Sampler& sampler, float s, float t, float lod) const;
956 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
957 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float lod) const;
958 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
959 
960 	Texture1DArray&					operator=			(const Texture1DArray& other);
961 
operator Texture1DArrayView(void) const962 	operator Texture1DArrayView (void) const { return m_view; }
963 
964 private:
965 	int								m_width;
966 	int								m_numLayers;
967 	Texture1DArrayView				m_view;
968 } DE_WARN_UNUSED_TYPE;
969 
sample(const Sampler & sampler,float s,float t,float lod) const970 inline Vec4 Texture1DArray::sample (const Sampler& sampler, float s, float t, float lod) const
971 {
972 	return m_view.sample(sampler, s, t, lod);
973 }
974 
sampleOffset(const Sampler & sampler,float s,float t,float lod,deInt32 offset) const975 inline Vec4 Texture1DArray::sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const
976 {
977 	return m_view.sampleOffset(sampler, s, t, lod, offset);
978 }
979 
sampleCompare(const Sampler & sampler,float ref,float s,float t,float lod) const980 inline float Texture1DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
981 {
982 	return m_view.sampleCompare(sampler, ref, s, t, lod);
983 }
984 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float lod,deInt32 offset) const985 inline float Texture1DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const
986 {
987 	return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
988 }
989 
990 /*--------------------------------------------------------------------*//*!
991  * \brief 2D Array Texture reference implementation
992  *//*--------------------------------------------------------------------*/
993 class Texture2DArray : private TextureLevelPyramid
994 {
995 public:
996 									Texture2DArray		(const TextureFormat& format, int width, int height, int numLayers);
997 									Texture2DArray		(const Texture2DArray& other);
998 									~Texture2DArray		(void);
999 
getWidth(void) const1000 	int								getWidth			(void) const	{ return m_width;		}
getHeight(void) const1001 	int								getHeight			(void) const	{ return m_height;		}
getNumLayers(void) const1002 	int								getNumLayers		(void) const	{ return m_numLayers;	}
1003 
1004 	void							allocLevel			(int levelNdx);
1005 
1006 	using TextureLevelPyramid::getFormat;
1007 	using TextureLevelPyramid::getNumLevels;
1008 	using TextureLevelPyramid::getLevel;
1009 	using TextureLevelPyramid::clearLevel;
1010 	using TextureLevelPyramid::isLevelEmpty;
1011 
1012 	Vec4							sample				(const Sampler& sampler, float s, float t, float r, float lod) const;
1013 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
1014 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
1015 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
1016 
1017 	Vec4							gatherOffsets		(const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
1018 	Vec4							gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
1019 
1020 	Texture2DArray&					operator=			(const Texture2DArray& other);
1021 
operator Texture2DArrayView(void) const1022 	operator Texture2DArrayView (void) const { return m_view; }
1023 
1024 private:
1025 	int								m_width;
1026 	int								m_height;
1027 	int								m_numLayers;
1028 	Texture2DArrayView				m_view;
1029 } DE_WARN_UNUSED_TYPE;
1030 
sample(const Sampler & sampler,float s,float t,float r,float lod) const1031 inline Vec4 Texture2DArray::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1032 {
1033 	return m_view.sample(sampler, s, t, r, lod);
1034 }
1035 
sampleOffset(const Sampler & sampler,float s,float t,float r,float lod,const IVec2 & offset) const1036 inline Vec4 Texture2DArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const
1037 {
1038 	return m_view.sampleOffset(sampler, s, t, r, lod, offset);
1039 }
1040 
sampleCompare(const Sampler & sampler,float ref,float s,float t,float r,float lod) const1041 inline float Texture2DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
1042 {
1043 	return m_view.sampleCompare(sampler, ref, s, t, r, lod);
1044 }
1045 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float r,float lod,const IVec2 & offset) const1046 inline float Texture2DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const
1047 {
1048 	return m_view.sampleCompareOffset(sampler, ref, s, t, r, lod, offset);
1049 }
1050 
gatherOffsets(const Sampler & sampler,float s,float t,float r,int componentNdx,const IVec2 (& offsets)[4]) const1051 inline Vec4 Texture2DArray::gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const
1052 {
1053 	return m_view.gatherOffsets(sampler, s, t, r, componentNdx, offsets);
1054 }
1055 
gatherOffsetsCompare(const Sampler & sampler,float ref,float s,float t,float r,const IVec2 (& offsets)[4]) const1056 inline Vec4 Texture2DArray::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const
1057 {
1058 	return m_view.gatherOffsetsCompare(sampler, ref, s, t, r, offsets);
1059 }
1060 
1061 /*--------------------------------------------------------------------*//*!
1062  * \brief 3D Texture View
1063  *//*--------------------------------------------------------------------*/
1064 class Texture3DView
1065 {
1066 public:
1067 									Texture3DView		(int numLevels, const ConstPixelBufferAccess* levels);
1068 
getWidth(void) const1069 	int								getWidth			(void) const	{ return m_numLevels > 0 ? m_levels[0].getWidth()	: 0;	}
getHeight(void) const1070 	int								getHeight			(void) const	{ return m_numLevels > 0 ? m_levels[0].getHeight()	: 0;	}
getDepth(void) const1071 	int								getDepth			(void) const	{ return m_numLevels > 0 ? m_levels[0].getDepth()	: 0;	}
getNumLevels(void) const1072 	int								getNumLevels		(void) const	{ return m_numLevels;										}
getLevel(int ndx) const1073 	const ConstPixelBufferAccess&	getLevel			(int ndx) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];	}
getLevels(void) const1074 	const ConstPixelBufferAccess*	getLevels			(void) const	{ return m_levels;											}
1075 
1076 	Vec4							sample				(const Sampler& sampler, float s, float t, float r, float lod) const;
1077 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
1078 
1079 protected:
1080 	int								m_numLevels;
1081 	const ConstPixelBufferAccess*	m_levels;
1082 } DE_WARN_UNUSED_TYPE;
1083 
sample(const Sampler & sampler,float s,float t,float r,float lod) const1084 inline Vec4 Texture3DView::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1085 {
1086 	return sampleLevelArray3D(m_levels, m_numLevels, sampler, s, t, r, lod);
1087 }
1088 
sampleOffset(const Sampler & sampler,float s,float t,float r,float lod,const IVec3 & offset) const1089 inline Vec4 Texture3DView::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
1090 {
1091 	return sampleLevelArray3DOffset(m_levels, m_numLevels, sampler, s, t, r, lod, offset);
1092 }
1093 
1094 /*--------------------------------------------------------------------*//*!
1095  * \brief 3D Texture reference implementation
1096  *//*--------------------------------------------------------------------*/
1097 class Texture3D : private TextureLevelPyramid
1098 {
1099 public:
1100 									Texture3D			(const TextureFormat& format, int width, int height, int depth);
1101 									Texture3D			(const Texture3D& other);
1102 									~Texture3D			(void);
1103 
getWidth(void) const1104 	int								getWidth			(void) const	{ return m_width;	}
getHeight(void) const1105 	int								getHeight			(void) const	{ return m_height;	}
getDepth(void) const1106 	int								getDepth			(void) const	{ return m_depth;	}
1107 
1108 	void							allocLevel			(int levelNdx);
1109 
1110 	using TextureLevelPyramid::getFormat;
1111 	using TextureLevelPyramid::getNumLevels;
1112 	using TextureLevelPyramid::getLevel;
1113 	using TextureLevelPyramid::clearLevel;
1114 	using TextureLevelPyramid::isLevelEmpty;
1115 
1116 	Vec4							sample				(const Sampler& sampler, float s, float t, float r, float lod) const;
1117 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
1118 
1119 	Texture3D&						operator=			(const Texture3D& other);
1120 
operator Texture3DView(void) const1121 	operator Texture3DView (void) const { return m_view; }
1122 
1123 private:
1124 	int								m_width;
1125 	int								m_height;
1126 	int								m_depth;
1127 	Texture3DView					m_view;
1128 } DE_WARN_UNUSED_TYPE;
1129 
sample(const Sampler & sampler,float s,float t,float r,float lod) const1130 inline Vec4 Texture3D::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1131 {
1132 	return m_view.sample(sampler, s, t, r, lod);
1133 }
1134 
sampleOffset(const Sampler & sampler,float s,float t,float r,float lod,const IVec3 & offset) const1135 inline Vec4 Texture3D::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
1136 {
1137 	return m_view.sampleOffset(sampler, s, t, r, lod, offset);
1138 }
1139 
1140 /*--------------------------------------------------------------------*//*!
1141  * \brief Cube Map Array Texture View
1142  *//*--------------------------------------------------------------------*/
1143 class TextureCubeArrayView
1144 {
1145 public:
1146 									TextureCubeArrayView	(int numLevels, const ConstPixelBufferAccess* levels);
1147 
getSize(void) const1148 	int								getSize					(void) const	{ return m_numLevels > 0 ? m_levels[0].getWidth()	: 0;	}
getDepth(void) const1149 	int								getDepth				(void) const	{ return m_numLevels > 0 ? m_levels[0].getDepth()	: 0;	}
getNumLayers(void) const1150 	int								getNumLayers			(void) const	{ return getDepth()	/ 6;	}
getNumLevels(void) const1151 	int								getNumLevels			(void) const	{ return m_numLevels;										}
getLevel(int ndx) const1152 	const ConstPixelBufferAccess&	getLevel				(int ndx) const	{ DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx];	}
getLevels(void) const1153 	const ConstPixelBufferAccess*	getLevels				(void) const	{ return m_levels;											}
1154 
1155 	Vec4							sample					(const Sampler& sampler, float s, float t, float r, float q, float lod) const;
1156 	Vec4							sampleOffset			(const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1157 	float							sampleCompare			(const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
1158 	float							sampleCompareOffset		(const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1159 
1160 protected:
1161 	int								selectLayer				(float q) const;
1162 
1163 	int								m_numLevels;
1164 	const ConstPixelBufferAccess*	m_levels;
1165 } DE_WARN_UNUSED_TYPE;
1166 
1167 /*--------------------------------------------------------------------*//*!
1168  * \brief Cube Map Array Texture reference implementation
1169  *//*--------------------------------------------------------------------*/
1170 class TextureCubeArray : private TextureLevelPyramid
1171 {
1172 public:
1173 									TextureCubeArray	(const TextureFormat& format, int size, int depth);
1174 									TextureCubeArray	(const TextureCubeArray& other);
1175 									~TextureCubeArray	(void);
1176 
getSize(void) const1177 	int								getSize				(void) const	{ return m_size;	}
getDepth(void) const1178 	int								getDepth			(void) const	{ return m_depth;	}
1179 
1180 	void							allocLevel			(int levelNdx);
1181 
1182 	using TextureLevelPyramid::getFormat;
1183 	using TextureLevelPyramid::getNumLevels;
1184 	using TextureLevelPyramid::getLevel;
1185 	using TextureLevelPyramid::clearLevel;
1186 	using TextureLevelPyramid::isLevelEmpty;
1187 
1188 	Vec4							sample				(const Sampler& sampler, float s, float t, float r, float q, float lod) const;
1189 	Vec4							sampleOffset		(const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1190 	float							sampleCompare		(const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
1191 	float							sampleCompareOffset	(const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1192 
1193 	TextureCubeArray&				operator=			(const TextureCubeArray& other);
1194 
operator TextureCubeArrayView(void) const1195 	operator TextureCubeArrayView (void) const { return m_view; }
1196 
1197 private:
1198 	int								m_size;
1199 	int								m_depth;
1200 	TextureCubeArrayView			m_view;
1201 } DE_WARN_UNUSED_TYPE;
1202 
sample(const Sampler & sampler,float s,float t,float r,float q,float lod) const1203 inline Vec4 TextureCubeArray::sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const
1204 {
1205 	return m_view.sample(sampler, s, t, r, q, lod);
1206 }
1207 
sampleOffset(const Sampler & sampler,float s,float t,float r,float q,float lod,const IVec2 & offset) const1208 inline Vec4 TextureCubeArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const
1209 {
1210 	return m_view.sampleOffset(sampler, s, t, r, q, lod, offset);
1211 }
1212 
sampleCompare(const Sampler & sampler,float ref,float s,float t,float r,float q,float lod) const1213 inline float TextureCubeArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const
1214 {
1215 	return m_view.sampleCompare(sampler, ref, s, t, r, q, lod);
1216 }
1217 
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float r,float q,float lod,const IVec2 & offset) const1218 inline float TextureCubeArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const
1219 {
1220 	return m_view.sampleCompareOffset(sampler, ref, s, t, r, q, lod, offset);
1221 }
1222 
1223 // Stream operators.
1224 std::ostream&		operator<<		(std::ostream& str, TextureFormat::ChannelOrder order);
1225 std::ostream&		operator<<		(std::ostream& str, TextureFormat::ChannelType type);
1226 std::ostream&		operator<<		(std::ostream& str, TextureFormat format);
1227 std::ostream&		operator<<		(std::ostream& str, CubeFace face);
1228 std::ostream&		operator<<		(std::ostream& str, const ConstPixelBufferAccess& access);
1229 
1230 } // tcu
1231 
1232 #endif // _TCUTEXTURE_HPP
1233