• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program OpenGL ES Utilities
3  * ------------------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Texture format utilities.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "gluTextureUtil.hpp"
25 #include "gluRenderContext.hpp"
26 #include "gluContextInfo.hpp"
27 #include "gluTexture.hpp"
28 #include "tcuTextureUtil.hpp"
29 #include "tcuFormatUtil.hpp"
30 #include "glwEnums.hpp"
31 
32 namespace glu
33 {
34 
35 using std::string;
36 
37 /*--------------------------------------------------------------------*//*!
38  * \brief Map tcu::TextureFormat to GL pixel transfer format.
39  *
40  * Maps generic texture format description to GL pixel transfer format.
41  * If no mapping is found, throws tcu::InternalError.
42  *
43  * \param texFormat Generic texture format.
44  * \return GL pixel transfer format.
45  *//*--------------------------------------------------------------------*/
getTransferFormat(tcu::TextureFormat texFormat)46 TransferFormat getTransferFormat (tcu::TextureFormat texFormat)
47 {
48 	using tcu::TextureFormat;
49 
50 	deUint32	format	= GL_NONE;
51 	deUint32	type	= GL_NONE;
52 	bool		isInt	= false;
53 
54 	switch (texFormat.type)
55 	{
56 		case TextureFormat::SIGNED_INT8:
57 		case TextureFormat::SIGNED_INT16:
58 		case TextureFormat::SIGNED_INT32:
59 		case TextureFormat::UNSIGNED_INT8:
60 		case TextureFormat::UNSIGNED_INT16:
61 		case TextureFormat::UNSIGNED_INT32:
62 		case TextureFormat::UNSIGNED_INT_1010102_REV:
63 			isInt = true;
64 			break;
65 
66 		default:
67 			isInt = false;
68 			break;
69 	}
70 
71 	switch (texFormat.order)
72 	{
73 		case TextureFormat::A:		format = GL_ALPHA;								break;
74 		case TextureFormat::L:		format = GL_LUMINANCE;							break;
75 		case TextureFormat::LA:		format = GL_LUMINANCE_ALPHA;					break;
76 		case TextureFormat::R:		format = isInt ? GL_RED_INTEGER		: GL_RED;	break;
77 		case TextureFormat::RG:		format = isInt ? GL_RG_INTEGER		: GL_RG;	break;
78 		case TextureFormat::RGB:	format = isInt ? GL_RGB_INTEGER		: GL_RGB;	break;
79 		case TextureFormat::RGBA:	format = isInt ? GL_RGBA_INTEGER	: GL_RGBA;	break;
80 		case TextureFormat::sR:		format = GL_RED;								break;
81 		case TextureFormat::sRG:	format = GL_RG;									break;
82 		case TextureFormat::sRGB:	format = GL_RGB;								break;
83 		case TextureFormat::sRGBA:	format = GL_RGBA;								break;
84 		case TextureFormat::D:		format = GL_DEPTH_COMPONENT;					break;
85 		case TextureFormat::DS:		format = GL_DEPTH_STENCIL;						break;
86 		case TextureFormat::S:		format = GL_STENCIL_INDEX;						break;
87 
88 		case TextureFormat::BGRA:
89 			DE_ASSERT(!isInt);
90 			format = GL_BGRA;
91 			break;
92 
93 		default:
94 			DE_ASSERT(false);
95 	}
96 
97 	switch (texFormat.type)
98 	{
99 		case TextureFormat::SNORM_INT8:						type = GL_BYTE;								break;
100 		case TextureFormat::SNORM_INT16:					type = GL_SHORT;							break;
101 		case TextureFormat::UNORM_INT8:						type = GL_UNSIGNED_BYTE;					break;
102 		case TextureFormat::UNORM_INT16:					type = GL_UNSIGNED_SHORT;					break;
103 		case TextureFormat::UNORM_SHORT_565:				type = GL_UNSIGNED_SHORT_5_6_5;				break;
104 		case TextureFormat::UNORM_SHORT_4444:				type = GL_UNSIGNED_SHORT_4_4_4_4;			break;
105 		case TextureFormat::UNORM_SHORT_5551:				type = GL_UNSIGNED_SHORT_5_5_5_1;			break;
106 		case TextureFormat::SIGNED_INT8:					type = GL_BYTE;								break;
107 		case TextureFormat::SIGNED_INT16:					type = GL_SHORT;							break;
108 		case TextureFormat::SIGNED_INT32:					type = GL_INT;								break;
109 		case TextureFormat::UNSIGNED_INT8:					type = GL_UNSIGNED_BYTE;					break;
110 		case TextureFormat::UNSIGNED_INT16:					type = GL_UNSIGNED_SHORT;					break;
111 		case TextureFormat::UNSIGNED_INT32:					type = GL_UNSIGNED_INT;						break;
112 		case TextureFormat::FLOAT:							type = GL_FLOAT;							break;
113 		case TextureFormat::UNORM_INT_101010:				type = GL_UNSIGNED_INT_2_10_10_10_REV;		break;
114 		case TextureFormat::UNORM_INT_1010102_REV:			type = GL_UNSIGNED_INT_2_10_10_10_REV;		break;
115 		case TextureFormat::UNSIGNED_INT_1010102_REV:		type = GL_UNSIGNED_INT_2_10_10_10_REV;		break;
116 		case TextureFormat::UNSIGNED_INT_11F_11F_10F_REV:	type = GL_UNSIGNED_INT_10F_11F_11F_REV;		break;
117 		case TextureFormat::UNSIGNED_INT_999_E5_REV:		type = GL_UNSIGNED_INT_5_9_9_9_REV;			break;
118 		case TextureFormat::HALF_FLOAT:						type = GL_HALF_FLOAT;						break;
119 		case TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV:	type = GL_FLOAT_32_UNSIGNED_INT_24_8_REV;	break;
120 		case TextureFormat::UNSIGNED_INT_24_8:				type = texFormat.order == TextureFormat::D
121 																 ? GL_UNSIGNED_INT
122 																 : GL_UNSIGNED_INT_24_8;				break;
123 
124 		default:
125 			throw tcu::InternalError("Can't map texture format to GL transfer format");
126 	}
127 
128 	return TransferFormat(format, type);
129 }
130 
131 /*--------------------------------------------------------------------*//*!
132  * \brief Map tcu::TextureFormat to GL internal sized format.
133  *
134  * Maps generic texture format description to GL internal format.
135  * If no mapping is found, throws tcu::InternalError.
136  *
137  * \param texFormat Generic texture format.
138  * \return GL sized internal format.
139  *//*--------------------------------------------------------------------*/
getInternalFormat(tcu::TextureFormat texFormat)140 deUint32 getInternalFormat (tcu::TextureFormat texFormat)
141 {
142 	DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELORDER_LAST < (1<<16));
143 	DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELTYPE_LAST < (1<<16));
144 
145 #define PACK_FMT(ORDER, TYPE) ((int(ORDER) << 16) | int(TYPE))
146 #define FMT_CASE(ORDER, TYPE) PACK_FMT(tcu::TextureFormat::ORDER, tcu::TextureFormat::TYPE)
147 
148 	switch (PACK_FMT(texFormat.order, texFormat.type))
149 	{
150 		case FMT_CASE(RGBA,		UNORM_SHORT_5551):				return GL_RGB5_A1;
151 		case FMT_CASE(RGBA,		UNORM_SHORT_4444):				return GL_RGBA4;
152 		case FMT_CASE(RGB,		UNORM_SHORT_565):				return GL_RGB565;
153 		case FMT_CASE(D,		UNORM_INT16):					return GL_DEPTH_COMPONENT16;
154 		case FMT_CASE(S,		UNSIGNED_INT8):					return GL_STENCIL_INDEX8;
155 
156 		case FMT_CASE(RGBA,		FLOAT):							return GL_RGBA32F;
157 		case FMT_CASE(RGBA,		SIGNED_INT32):					return GL_RGBA32I;
158 		case FMT_CASE(RGBA,		UNSIGNED_INT32):				return GL_RGBA32UI;
159 		case FMT_CASE(RGBA,		UNORM_INT16):					return GL_RGBA16;
160 		case FMT_CASE(RGBA,		SNORM_INT16):					return GL_RGBA16_SNORM;
161 		case FMT_CASE(RGBA,		HALF_FLOAT):					return GL_RGBA16F;
162 		case FMT_CASE(RGBA,		SIGNED_INT16):					return GL_RGBA16I;
163 		case FMT_CASE(RGBA,		UNSIGNED_INT16):				return GL_RGBA16UI;
164 		case FMT_CASE(RGBA,		UNORM_INT8):					return GL_RGBA8;
165 		case FMT_CASE(RGBA,		SIGNED_INT8):					return GL_RGBA8I;
166 		case FMT_CASE(RGBA,		UNSIGNED_INT8):					return GL_RGBA8UI;
167 		case FMT_CASE(sRGBA,	UNORM_INT8):					return GL_SRGB8_ALPHA8;
168 		case FMT_CASE(RGBA,		UNORM_INT_1010102_REV):			return GL_RGB10_A2;
169 		case FMT_CASE(RGBA,		UNSIGNED_INT_1010102_REV):		return GL_RGB10_A2UI;
170 		case FMT_CASE(RGBA,		SNORM_INT8):					return GL_RGBA8_SNORM;
171 
172 		case FMT_CASE(RGB,		UNORM_INT8):					return GL_RGB8;
173 		case FMT_CASE(RGB,		UNSIGNED_INT_11F_11F_10F_REV):	return GL_R11F_G11F_B10F;
174 		case FMT_CASE(RGB,		FLOAT):							return GL_RGB32F;
175 		case FMT_CASE(RGB,		SIGNED_INT32):					return GL_RGB32I;
176 		case FMT_CASE(RGB,		UNSIGNED_INT32):				return GL_RGB32UI;
177 		case FMT_CASE(RGB,		UNORM_INT16):					return GL_RGB16;
178 		case FMT_CASE(RGB,		SNORM_INT16):					return GL_RGB16_SNORM;
179 		case FMT_CASE(RGB,		HALF_FLOAT):					return GL_RGB16F;
180 		case FMT_CASE(RGB,		SIGNED_INT16):					return GL_RGB16I;
181 		case FMT_CASE(RGB,		UNSIGNED_INT16):				return GL_RGB16UI;
182 		case FMT_CASE(RGB,		SNORM_INT8):					return GL_RGB8_SNORM;
183 		case FMT_CASE(RGB,		SIGNED_INT8):					return GL_RGB8I;
184 		case FMT_CASE(RGB,		UNSIGNED_INT8):					return GL_RGB8UI;
185 		case FMT_CASE(sRGB,		UNORM_INT8):					return GL_SRGB8;
186 		case FMT_CASE(RGB,		UNSIGNED_INT_999_E5_REV):		return GL_RGB9_E5;
187 		case FMT_CASE(RGB,		UNORM_INT_1010102_REV):			return GL_RGB10;
188 
189 		case FMT_CASE(RG,		FLOAT):							return GL_RG32F;
190 		case FMT_CASE(RG,		SIGNED_INT32):					return GL_RG32I;
191 		case FMT_CASE(RG,		UNSIGNED_INT32):				return GL_RG32UI;
192 		case FMT_CASE(RG,		UNORM_INT16):					return GL_RG16;
193 		case FMT_CASE(RG,		SNORM_INT16):					return GL_RG16_SNORM;
194 		case FMT_CASE(RG,		HALF_FLOAT):					return GL_RG16F;
195 		case FMT_CASE(RG,		SIGNED_INT16):					return GL_RG16I;
196 		case FMT_CASE(RG,		UNSIGNED_INT16):				return GL_RG16UI;
197 		case FMT_CASE(RG,		UNORM_INT8):					return GL_RG8;
198 		case FMT_CASE(RG,		SIGNED_INT8):					return GL_RG8I;
199 		case FMT_CASE(RG,		UNSIGNED_INT8):					return GL_RG8UI;
200 		case FMT_CASE(RG,		SNORM_INT8):					return GL_RG8_SNORM;
201 		case FMT_CASE(sRG,		UNORM_INT8):					return GL_SRG8_EXT;
202 
203 		case FMT_CASE(R,		FLOAT):							return GL_R32F;
204 		case FMT_CASE(R,		SIGNED_INT32):					return GL_R32I;
205 		case FMT_CASE(R,		UNSIGNED_INT32):				return GL_R32UI;
206 		case FMT_CASE(R,		UNORM_INT16):					return GL_R16;
207 		case FMT_CASE(R,		SNORM_INT16):					return GL_R16_SNORM;
208 		case FMT_CASE(R,		HALF_FLOAT):					return GL_R16F;
209 		case FMT_CASE(R,		SIGNED_INT16):					return GL_R16I;
210 		case FMT_CASE(R,		UNSIGNED_INT16):				return GL_R16UI;
211 		case FMT_CASE(R,		UNORM_INT8):					return GL_R8;
212 		case FMT_CASE(R,		SIGNED_INT8):					return GL_R8I;
213 		case FMT_CASE(R,		UNSIGNED_INT8):					return GL_R8UI;
214 		case FMT_CASE(R,		SNORM_INT8):					return GL_R8_SNORM;
215 		case FMT_CASE(sR,		UNORM_INT8):					return GL_SR8_EXT;
216 
217 		case FMT_CASE(D,		FLOAT):							return GL_DEPTH_COMPONENT32F;
218 		case FMT_CASE(D,		UNSIGNED_INT_24_8):				return GL_DEPTH_COMPONENT24;
219 		case FMT_CASE(D,		UNSIGNED_INT32):				return GL_DEPTH_COMPONENT32;
220 		case FMT_CASE(DS,		FLOAT_UNSIGNED_INT_24_8_REV):	return GL_DEPTH32F_STENCIL8;
221 		case FMT_CASE(DS,		UNSIGNED_INT_24_8):				return GL_DEPTH24_STENCIL8;
222 
223 		default:
224 			throw tcu::InternalError("Can't map texture format to GL internal format");
225 	}
226 }
227 
228 /*--------------------------------------------------------------------*//*!
229  * \brief Map generic compressed format to GL compressed format enum.
230  *
231  * Maps generic compressed format to GL compressed format enum value.
232  * If no mapping is found, throws tcu::InternalError.
233  *
234  * \param format Generic compressed format.
235  * \return GL compressed texture format.
236  *//*--------------------------------------------------------------------*/
getGLFormat(tcu::CompressedTexFormat format)237 deUint32 getGLFormat (tcu::CompressedTexFormat format)
238 {
239 	switch (format)
240 	{
241 		case tcu::COMPRESSEDTEXFORMAT_ETC1_RGB8:						return GL_ETC1_RGB8_OES;
242 		case tcu::COMPRESSEDTEXFORMAT_EAC_R11:							return GL_COMPRESSED_R11_EAC;
243 		case tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_R11:					return GL_COMPRESSED_SIGNED_R11_EAC;
244 		case tcu::COMPRESSEDTEXFORMAT_EAC_RG11:							return GL_COMPRESSED_RG11_EAC;
245 		case tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_RG11:					return GL_COMPRESSED_SIGNED_RG11_EAC;
246 		case tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8:						return GL_COMPRESSED_RGB8_ETC2;
247 		case tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8:						return GL_COMPRESSED_SRGB8_ETC2;
248 		case tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1:	return GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
249 		case tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1:	return GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
250 		case tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_RGBA8:					return GL_COMPRESSED_RGBA8_ETC2_EAC;
251 		case tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_SRGB8_ALPHA8:			return GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
252 
253 		case tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_RGBA:					return GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
254 		case tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_RGBA:					return GL_COMPRESSED_RGBA_ASTC_5x4_KHR;
255 		case tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_RGBA:					return GL_COMPRESSED_RGBA_ASTC_5x5_KHR;
256 		case tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_RGBA:					return GL_COMPRESSED_RGBA_ASTC_6x5_KHR;
257 		case tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_RGBA:					return GL_COMPRESSED_RGBA_ASTC_6x6_KHR;
258 		case tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_RGBA:					return GL_COMPRESSED_RGBA_ASTC_8x5_KHR;
259 		case tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_RGBA:					return GL_COMPRESSED_RGBA_ASTC_8x6_KHR;
260 		case tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_RGBA:					return GL_COMPRESSED_RGBA_ASTC_8x8_KHR;
261 		case tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_RGBA:					return GL_COMPRESSED_RGBA_ASTC_10x5_KHR;
262 		case tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_RGBA:					return GL_COMPRESSED_RGBA_ASTC_10x6_KHR;
263 		case tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_RGBA:					return GL_COMPRESSED_RGBA_ASTC_10x8_KHR;
264 		case tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_RGBA:					return GL_COMPRESSED_RGBA_ASTC_10x10_KHR;
265 		case tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_RGBA:					return GL_COMPRESSED_RGBA_ASTC_12x10_KHR;
266 		case tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_RGBA:					return GL_COMPRESSED_RGBA_ASTC_12x12_KHR;
267 		case tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_SRGB8_ALPHA8:			return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
268 		case tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_SRGB8_ALPHA8:			return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
269 		case tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_SRGB8_ALPHA8:			return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
270 		case tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_SRGB8_ALPHA8:			return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
271 		case tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_SRGB8_ALPHA8:			return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
272 		case tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_SRGB8_ALPHA8:			return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
273 		case tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_SRGB8_ALPHA8:			return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
274 		case tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_SRGB8_ALPHA8:			return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
275 		case tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_SRGB8_ALPHA8:			return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
276 		case tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_SRGB8_ALPHA8:			return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
277 		case tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_SRGB8_ALPHA8:			return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
278 		case tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_SRGB8_ALPHA8:			return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
279 		case tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_SRGB8_ALPHA8:			return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
280 		case tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_SRGB8_ALPHA8:			return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
281 
282 		default:
283 			throw tcu::InternalError("Can't map compressed format to GL format");
284 	}
285 }
286 
287 /*--------------------------------------------------------------------*//*!
288  * \brief Map compressed GL format to generic compressed format.
289  *
290  * Maps compressed GL format to generic compressed format.
291  * If no mapping is found, throws tcu::InternalError.
292  *
293  * \param GL compressed texture format.
294  * \return format Generic compressed format.
295  *//*--------------------------------------------------------------------*/
mapGLCompressedTexFormat(deUint32 format)296 tcu::CompressedTexFormat mapGLCompressedTexFormat (deUint32 format)
297 {
298 	switch (format)
299 	{
300 		case GL_ETC1_RGB8_OES:								return tcu::COMPRESSEDTEXFORMAT_ETC1_RGB8;
301 		case GL_COMPRESSED_R11_EAC:							return tcu::COMPRESSEDTEXFORMAT_EAC_R11;
302 		case GL_COMPRESSED_SIGNED_R11_EAC:					return tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_R11;
303 		case GL_COMPRESSED_RG11_EAC:						return tcu::COMPRESSEDTEXFORMAT_EAC_RG11;
304 		case GL_COMPRESSED_SIGNED_RG11_EAC:					return tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_RG11;
305 		case GL_COMPRESSED_RGB8_ETC2:						return tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8;
306 		case GL_COMPRESSED_SRGB8_ETC2:						return tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8;
307 		case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:	return tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1;
308 		case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:	return tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1;
309 		case GL_COMPRESSED_RGBA8_ETC2_EAC:					return tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_RGBA8;
310 		case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:			return tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_SRGB8_ALPHA8;
311 
312 		case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:				return tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_RGBA;
313 		case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:				return tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_RGBA;
314 		case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:				return tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_RGBA;
315 		case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:				return tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_RGBA;
316 		case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:				return tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_RGBA;
317 		case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:				return tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_RGBA;
318 		case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:				return tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_RGBA;
319 		case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:				return tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_RGBA;
320 		case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:				return tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_RGBA;
321 		case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:				return tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_RGBA;
322 		case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:				return tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_RGBA;
323 		case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:				return tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_RGBA;
324 		case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:				return tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_RGBA;
325 		case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:				return tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_RGBA;
326 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:		return tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_SRGB8_ALPHA8;
327 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:		return tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_SRGB8_ALPHA8;
328 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:		return tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_SRGB8_ALPHA8;
329 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:		return tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_SRGB8_ALPHA8;
330 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:		return tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_SRGB8_ALPHA8;
331 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:		return tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_SRGB8_ALPHA8;
332 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:		return tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_SRGB8_ALPHA8;
333 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:		return tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_SRGB8_ALPHA8;
334 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:		return tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_SRGB8_ALPHA8;
335 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:		return tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_SRGB8_ALPHA8;
336 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:		return tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_SRGB8_ALPHA8;
337 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:		return tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_SRGB8_ALPHA8;
338 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:		return tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_SRGB8_ALPHA8;
339 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:		return tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_SRGB8_ALPHA8;
340 
341 		default:
342 			throw tcu::InternalError("Can't map compressed GL format to compressed format");
343 	}
344 }
345 
isCompressedFormat(deUint32 internalFormat)346 bool isCompressedFormat (deUint32 internalFormat)
347 {
348 	switch (internalFormat)
349 	{
350 		case GL_ETC1_RGB8_OES:
351 		case GL_COMPRESSED_R11_EAC:
352 		case GL_COMPRESSED_SIGNED_R11_EAC:
353 		case GL_COMPRESSED_RG11_EAC:
354 		case GL_COMPRESSED_SIGNED_RG11_EAC:
355 		case GL_COMPRESSED_RGB8_ETC2:
356 		case GL_COMPRESSED_SRGB8_ETC2:
357 		case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
358 		case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
359 		case GL_COMPRESSED_RGBA8_ETC2_EAC:
360 		case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
361 		case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
362 		case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
363 		case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
364 		case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:
365 		case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:
366 		case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:
367 		case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:
368 		case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:
369 		case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:
370 		case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:
371 		case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:
372 		case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:
373 		case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:
374 		case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:
375 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
376 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
377 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
378 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
379 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
380 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
381 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
382 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
383 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
384 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
385 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
386 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
387 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
388 		case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
389 			return true;
390 
391 		default:
392 			return false;
393 	}
394 }
395 
mapGLChannelType(deUint32 dataType,bool normalized)396 static tcu::TextureFormat::ChannelType mapGLChannelType (deUint32 dataType, bool normalized)
397 {
398 	// \note Normalized bit is ignored where it doesn't apply.
399 	using tcu::TextureFormat;
400 
401 	switch (dataType)
402 	{
403 		case GL_UNSIGNED_BYTE:					return normalized ? TextureFormat::UNORM_INT8	: TextureFormat::UNSIGNED_INT8;
404 		case GL_BYTE:							return normalized ? TextureFormat::SNORM_INT8	: TextureFormat::SIGNED_INT8;
405 		case GL_UNSIGNED_SHORT:					return normalized ? TextureFormat::UNORM_INT16	: TextureFormat::UNSIGNED_INT16;
406 		case GL_SHORT:							return normalized ? TextureFormat::SNORM_INT16	: TextureFormat::SIGNED_INT16;
407 		case GL_UNSIGNED_INT:					return normalized ? TextureFormat::UNORM_INT32	: TextureFormat::UNSIGNED_INT32;
408 		case GL_INT:							return normalized ? TextureFormat::SNORM_INT32	: TextureFormat::SIGNED_INT32;
409 		case GL_FLOAT:							return TextureFormat::FLOAT;
410 		case GL_UNSIGNED_SHORT_4_4_4_4:			return TextureFormat::UNORM_SHORT_4444;
411 		case GL_UNSIGNED_SHORT_5_5_5_1:			return TextureFormat::UNORM_SHORT_5551;
412 		case GL_UNSIGNED_SHORT_5_6_5:			return TextureFormat::UNORM_SHORT_565;
413 		case GL_HALF_FLOAT:						return TextureFormat::HALF_FLOAT;
414 		case GL_UNSIGNED_INT_2_10_10_10_REV:	return normalized ? TextureFormat::UNORM_INT_1010102_REV : TextureFormat::UNSIGNED_INT_1010102_REV;
415 		case GL_UNSIGNED_INT_10F_11F_11F_REV:	return TextureFormat::UNSIGNED_INT_11F_11F_10F_REV;
416 		case GL_UNSIGNED_INT_24_8:				return TextureFormat::UNSIGNED_INT_24_8;
417 		case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:	return TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV;
418 		case GL_UNSIGNED_INT_5_9_9_9_REV:		return TextureFormat::UNSIGNED_INT_999_E5_REV;
419 
420 		// GL_OES_texture_half_float
421 		case GL_HALF_FLOAT_OES:					return TextureFormat::HALF_FLOAT;
422 
423 		default:
424 			DE_ASSERT(false);
425 			return TextureFormat::CHANNELTYPE_LAST;
426 	}
427 }
428 
429 /*--------------------------------------------------------------------*//*!
430  * \brief Map GL pixel transfer format to tcu::TextureFormat.
431  *
432  * If no mapping is found, throws tcu::InternalError.
433  *
434  * \param format	GL pixel format.
435  * \param dataType	GL data type.
436  * \return Generic texture format.
437  *//*--------------------------------------------------------------------*/
mapGLTransferFormat(deUint32 format,deUint32 dataType)438 tcu::TextureFormat mapGLTransferFormat (deUint32 format, deUint32 dataType)
439 {
440 	using tcu::TextureFormat;
441 	switch (format)
442 	{
443 		case GL_ALPHA:				return TextureFormat(TextureFormat::A,		mapGLChannelType(dataType, true));
444 		case GL_LUMINANCE:			return TextureFormat(TextureFormat::L,		mapGLChannelType(dataType, true));
445 		case GL_LUMINANCE_ALPHA:	return TextureFormat(TextureFormat::LA,		mapGLChannelType(dataType, true));
446 		case GL_RGB:				return TextureFormat(TextureFormat::RGB,	mapGLChannelType(dataType, true));
447 		case GL_RGBA:				return TextureFormat(TextureFormat::RGBA,	mapGLChannelType(dataType, true));
448 		case GL_BGRA:				return TextureFormat(TextureFormat::BGRA,	mapGLChannelType(dataType, true));
449 		case GL_RG:					return TextureFormat(TextureFormat::RG,		mapGLChannelType(dataType, true));
450 		case GL_RED:				return TextureFormat(TextureFormat::R,		mapGLChannelType(dataType, true));
451 		case GL_RGBA_INTEGER:		return TextureFormat(TextureFormat::RGBA,	mapGLChannelType(dataType, false));
452 		case GL_RGB_INTEGER:		return TextureFormat(TextureFormat::RGB,	mapGLChannelType(dataType, false));
453 		case GL_RG_INTEGER:			return TextureFormat(TextureFormat::RG,		mapGLChannelType(dataType, false));
454 		case GL_RED_INTEGER:		return TextureFormat(TextureFormat::R,		mapGLChannelType(dataType, false));
455 
456 		case GL_DEPTH_COMPONENT:	return TextureFormat(TextureFormat::D,		mapGLChannelType(dataType, true));
457 		case GL_DEPTH_STENCIL:		return TextureFormat(TextureFormat::DS,		mapGLChannelType(dataType, true));
458 
459 		default:
460 			throw tcu::InternalError(string("Can't map GL pixel format (") + tcu::toHex(format).toString() + ", " + tcu::toHex(dataType).toString() + ") to texture format");
461 	}
462 }
463 
464 /*--------------------------------------------------------------------*//*!
465  * \brief Map GL internal texture format to tcu::TextureFormat.
466  *
467  * If no mapping is found, throws tcu::InternalError.
468  *
469  * \param internalFormat Sized internal format.
470  * \return Generic texture format.
471  *//*--------------------------------------------------------------------*/
mapGLInternalFormat(deUint32 internalFormat)472 tcu::TextureFormat mapGLInternalFormat (deUint32 internalFormat)
473 {
474 	using tcu::TextureFormat;
475 	switch (internalFormat)
476 	{
477 		case GL_RGB5_A1:			return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNORM_SHORT_5551);
478 		case GL_RGBA4:				return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNORM_SHORT_4444);
479 		case GL_RGB565:				return TextureFormat(TextureFormat::RGB,	TextureFormat::UNORM_SHORT_565);
480 		case GL_DEPTH_COMPONENT16:	return TextureFormat(TextureFormat::D,		TextureFormat::UNORM_INT16);
481 		case GL_STENCIL_INDEX8:		return TextureFormat(TextureFormat::S,		TextureFormat::UNSIGNED_INT8);
482 
483 		case GL_RGBA32F:			return TextureFormat(TextureFormat::RGBA,	TextureFormat::FLOAT);
484 		case GL_RGBA32I:			return TextureFormat(TextureFormat::RGBA,	TextureFormat::SIGNED_INT32);
485 		case GL_RGBA32UI:			return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNSIGNED_INT32);
486 		case GL_RGBA16:				return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNORM_INT16);
487 		case GL_RGBA16_SNORM:		return TextureFormat(TextureFormat::RGBA,	TextureFormat::SNORM_INT16);
488 		case GL_RGBA16F:			return TextureFormat(TextureFormat::RGBA,	TextureFormat::HALF_FLOAT);
489 		case GL_RGBA16I:			return TextureFormat(TextureFormat::RGBA,	TextureFormat::SIGNED_INT16);
490 		case GL_RGBA16UI:			return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNSIGNED_INT16);
491 		case GL_RGBA8:				return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNORM_INT8);
492 		case GL_RGBA8I:				return TextureFormat(TextureFormat::RGBA,	TextureFormat::SIGNED_INT8);
493 		case GL_RGBA8UI:			return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNSIGNED_INT8);
494 		case GL_SRGB8_ALPHA8:		return TextureFormat(TextureFormat::sRGBA,	TextureFormat::UNORM_INT8);
495 		case GL_RGB10_A2:			return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNORM_INT_1010102_REV);
496 		case GL_RGB10_A2UI:			return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNSIGNED_INT_1010102_REV);
497 		case GL_RGBA8_SNORM:		return TextureFormat(TextureFormat::RGBA,	TextureFormat::SNORM_INT8);
498 
499 		case GL_RGB8:				return TextureFormat(TextureFormat::RGB,	TextureFormat::UNORM_INT8);
500 		case GL_R11F_G11F_B10F:		return TextureFormat(TextureFormat::RGB,	TextureFormat::UNSIGNED_INT_11F_11F_10F_REV);
501 		case GL_RGB32F:				return TextureFormat(TextureFormat::RGB,	TextureFormat::FLOAT);
502 		case GL_RGB32I:				return TextureFormat(TextureFormat::RGB,	TextureFormat::SIGNED_INT32);
503 		case GL_RGB32UI:			return TextureFormat(TextureFormat::RGB,	TextureFormat::UNSIGNED_INT32);
504 		case GL_RGB16:				return TextureFormat(TextureFormat::RGB,	TextureFormat::UNORM_INT16);
505 		case GL_RGB16_SNORM:		return TextureFormat(TextureFormat::RGB,	TextureFormat::SNORM_INT16);
506 		case GL_RGB16F:				return TextureFormat(TextureFormat::RGB,	TextureFormat::HALF_FLOAT);
507 		case GL_RGB16I:				return TextureFormat(TextureFormat::RGB,	TextureFormat::SIGNED_INT16);
508 		case GL_RGB16UI:			return TextureFormat(TextureFormat::RGB,	TextureFormat::UNSIGNED_INT16);
509 		case GL_RGB8_SNORM:			return TextureFormat(TextureFormat::RGB,	TextureFormat::SNORM_INT8);
510 		case GL_RGB8I:				return TextureFormat(TextureFormat::RGB,	TextureFormat::SIGNED_INT8);
511 		case GL_RGB8UI:				return TextureFormat(TextureFormat::RGB,	TextureFormat::UNSIGNED_INT8);
512 		case GL_SRGB8:				return TextureFormat(TextureFormat::sRGB,	TextureFormat::UNORM_INT8);
513 		case GL_RGB9_E5:			return TextureFormat(TextureFormat::RGB,	TextureFormat::UNSIGNED_INT_999_E5_REV);
514 		case GL_RGB10:				return TextureFormat(TextureFormat::RGB,	TextureFormat::UNORM_INT_1010102_REV);
515 
516 		case GL_RG32F:				return TextureFormat(TextureFormat::RG,		TextureFormat::FLOAT);
517 		case GL_RG32I:				return TextureFormat(TextureFormat::RG,		TextureFormat::SIGNED_INT32);
518 		case GL_RG32UI:				return TextureFormat(TextureFormat::RG,		TextureFormat::UNSIGNED_INT32);
519 		case GL_RG16:				return TextureFormat(TextureFormat::RG,		TextureFormat::UNORM_INT16);
520 		case GL_RG16_SNORM:			return TextureFormat(TextureFormat::RG,		TextureFormat::SNORM_INT16);
521 		case GL_RG16F:				return TextureFormat(TextureFormat::RG,		TextureFormat::HALF_FLOAT);
522 		case GL_RG16I:				return TextureFormat(TextureFormat::RG,		TextureFormat::SIGNED_INT16);
523 		case GL_RG16UI:				return TextureFormat(TextureFormat::RG,		TextureFormat::UNSIGNED_INT16);
524 		case GL_RG8:				return TextureFormat(TextureFormat::RG,		TextureFormat::UNORM_INT8);
525 		case GL_RG8I:				return TextureFormat(TextureFormat::RG,		TextureFormat::SIGNED_INT8);
526 		case GL_RG8UI:				return TextureFormat(TextureFormat::RG,		TextureFormat::UNSIGNED_INT8);
527 		case GL_RG8_SNORM:			return TextureFormat(TextureFormat::RG,		TextureFormat::SNORM_INT8);
528 		case GL_SRG8_EXT:			return TextureFormat(TextureFormat::sRG,	TextureFormat::UNORM_INT8);
529 
530 		case GL_R32F:				return TextureFormat(TextureFormat::R,		TextureFormat::FLOAT);
531 		case GL_R32I:				return TextureFormat(TextureFormat::R,		TextureFormat::SIGNED_INT32);
532 		case GL_R32UI:				return TextureFormat(TextureFormat::R,		TextureFormat::UNSIGNED_INT32);
533 		case GL_R16:				return TextureFormat(TextureFormat::R,		TextureFormat::UNORM_INT16);
534 		case GL_R16_SNORM:			return TextureFormat(TextureFormat::R,		TextureFormat::SNORM_INT16);
535 		case GL_R16F:				return TextureFormat(TextureFormat::R,		TextureFormat::HALF_FLOAT);
536 		case GL_R16I:				return TextureFormat(TextureFormat::R,		TextureFormat::SIGNED_INT16);
537 		case GL_R16UI:				return TextureFormat(TextureFormat::R,		TextureFormat::UNSIGNED_INT16);
538 		case GL_R8:					return TextureFormat(TextureFormat::R,		TextureFormat::UNORM_INT8);
539 		case GL_R8I:				return TextureFormat(TextureFormat::R,		TextureFormat::SIGNED_INT8);
540 		case GL_R8UI:				return TextureFormat(TextureFormat::R,		TextureFormat::UNSIGNED_INT8);
541 		case GL_R8_SNORM:			return TextureFormat(TextureFormat::R,		TextureFormat::SNORM_INT8);
542 		case GL_SR8_EXT:			return TextureFormat(TextureFormat::sR,		TextureFormat::UNORM_INT8);
543 
544 		case GL_DEPTH_COMPONENT32F:	return TextureFormat(TextureFormat::D,		TextureFormat::FLOAT);
545 		case GL_DEPTH_COMPONENT24:	return TextureFormat(TextureFormat::D,		TextureFormat::UNSIGNED_INT_24_8);
546 		case GL_DEPTH_COMPONENT32:	return TextureFormat(TextureFormat::D,		TextureFormat::UNSIGNED_INT32);
547 		case GL_DEPTH32F_STENCIL8:	return TextureFormat(TextureFormat::DS,		TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV);
548 		case GL_DEPTH24_STENCIL8:	return TextureFormat(TextureFormat::DS,		TextureFormat::UNSIGNED_INT_24_8);
549 
550 		default:
551 			throw tcu::InternalError(string("Can't map GL sized internal format (") + tcu::toHex(internalFormat).toString() + ") to texture format");
552 	}
553 }
554 
isGLInternalColorFormatFilterable(deUint32 format)555 bool isGLInternalColorFormatFilterable (deUint32 format)
556 {
557 	switch (format)
558 	{
559 		case GL_R8:
560 		case GL_R8_SNORM:
561 		case GL_RG8:
562 		case GL_RG8_SNORM:
563 		case GL_RGB8:
564 		case GL_RGB8_SNORM:
565 		case GL_RGB565:
566 		case GL_RGBA4:
567 		case GL_RGB5_A1:
568 		case GL_RGBA8:
569 		case GL_RGBA8_SNORM:
570 		case GL_RGB10_A2:
571 		case GL_SR8_EXT:
572 		case GL_SRG8_EXT:
573 		case GL_SRGB8:
574 		case GL_SRGB8_ALPHA8:
575 		case GL_R16F:
576 		case GL_RG16F:
577 		case GL_RGB16F:
578 		case GL_RGBA16F:
579 		case GL_R11F_G11F_B10F:
580 		case GL_RGB9_E5:
581 			return true;
582 
583 		case GL_RGB10_A2UI:
584 		case GL_R32F:
585 		case GL_RG32F:
586 		case GL_RGB32F:
587 		case GL_RGBA32F:
588 		case GL_R8I:
589 		case GL_R8UI:
590 		case GL_R16I:
591 		case GL_R16UI:
592 		case GL_R32I:
593 		case GL_R32UI:
594 		case GL_RG8I:
595 		case GL_RG8UI:
596 		case GL_RG16I:
597 		case GL_RG16UI:
598 		case GL_RG32I:
599 		case GL_RG32UI:
600 		case GL_RGB8I:
601 		case GL_RGB8UI:
602 		case GL_RGB16I:
603 		case GL_RGB16UI:
604 		case GL_RGB32I:
605 		case GL_RGB32UI:
606 		case GL_RGBA8I:
607 		case GL_RGBA8UI:
608 		case GL_RGBA16I:
609 		case GL_RGBA16UI:
610 		case GL_RGBA32I:
611 		case GL_RGBA32UI:
612 			return false;
613 
614 		default:
615 			DE_ASSERT(false);
616 			return false;
617 	}
618 }
619 
mapGLWrapMode(deUint32 wrapMode)620 static inline tcu::Sampler::WrapMode mapGLWrapMode (deUint32 wrapMode)
621 {
622 	switch (wrapMode)
623 	{
624 		case GL_CLAMP_TO_EDGE:		return tcu::Sampler::CLAMP_TO_EDGE;
625 		case GL_CLAMP_TO_BORDER:	return tcu::Sampler::CLAMP_TO_BORDER;
626 		case GL_REPEAT:				return tcu::Sampler::REPEAT_GL;
627 		case GL_MIRRORED_REPEAT:	return tcu::Sampler::MIRRORED_REPEAT_GL;
628 		default:
629 			throw tcu::InternalError("Can't map GL wrap mode " + tcu::toHex(wrapMode).toString());
630 	}
631 }
632 
mapGLMinFilterMode(deUint32 filterMode)633 static inline tcu::Sampler::FilterMode mapGLMinFilterMode (deUint32 filterMode)
634 {
635 	switch (filterMode)
636 	{
637 		case GL_NEAREST:				return tcu::Sampler::NEAREST;
638 		case GL_LINEAR:					return tcu::Sampler::LINEAR;
639 		case GL_NEAREST_MIPMAP_NEAREST:	return tcu::Sampler::NEAREST_MIPMAP_NEAREST;
640 		case GL_NEAREST_MIPMAP_LINEAR:	return tcu::Sampler::NEAREST_MIPMAP_LINEAR;
641 		case GL_LINEAR_MIPMAP_NEAREST:	return tcu::Sampler::LINEAR_MIPMAP_NEAREST;
642 		case GL_LINEAR_MIPMAP_LINEAR:	return tcu::Sampler::LINEAR_MIPMAP_LINEAR;
643 		default:
644 			throw tcu::InternalError("Can't map GL min filter mode" + tcu::toHex(filterMode).toString());
645 	}
646 }
647 
mapGLMagFilterMode(deUint32 filterMode)648 static inline tcu::Sampler::FilterMode mapGLMagFilterMode (deUint32 filterMode)
649 {
650 	switch (filterMode)
651 	{
652 		case GL_NEAREST:				return tcu::Sampler::NEAREST;
653 		case GL_LINEAR:					return tcu::Sampler::LINEAR;
654 		default:
655 			throw tcu::InternalError("Can't map GL mag filter mode" + tcu::toHex(filterMode).toString());
656 	}
657 }
658 
659 /*--------------------------------------------------------------------*//*!
660  * \brief Map GL sampler parameters to tcu::Sampler.
661  *
662  * If no mapping is found, throws tcu::InternalError.
663  *
664  * \param wrapS		S-component wrap mode
665  * \param minFilter	Minification filter mode
666  * \param magFilter	Magnification filter mode
667  * \return Sampler description.
668  *//*--------------------------------------------------------------------*/
mapGLSampler(deUint32 wrapS,deUint32 minFilter,deUint32 magFilter)669 tcu::Sampler mapGLSampler (deUint32 wrapS, deUint32 minFilter, deUint32 magFilter)
670 {
671 	return mapGLSampler(wrapS, wrapS, wrapS, minFilter, magFilter);
672 }
673 
674 
675 /*--------------------------------------------------------------------*//*!
676  * \brief Map GL sampler parameters to tcu::Sampler.
677  *
678  * If no mapping is found, throws tcu::InternalError.
679  *
680  * \param wrapS		S-component wrap mode
681  * \param wrapT		T-component wrap mode
682  * \param minFilter	Minification filter mode
683  * \param magFilter	Magnification filter mode
684  * \return Sampler description.
685  *//*--------------------------------------------------------------------*/
mapGLSampler(deUint32 wrapS,deUint32 wrapT,deUint32 minFilter,deUint32 magFilter)686 tcu::Sampler mapGLSampler (deUint32 wrapS, deUint32 wrapT, deUint32 minFilter, deUint32 magFilter)
687 {
688 	return mapGLSampler(wrapS, wrapT, wrapS, minFilter, magFilter);
689 }
690 
691 /*--------------------------------------------------------------------*//*!
692  * \brief Map GL sampler parameters to tcu::Sampler.
693  *
694  * If no mapping is found, throws tcu::InternalError.
695  *
696  * \param wrapS		S-component wrap mode
697  * \param wrapT		T-component wrap mode
698  * \param wrapR		R-component wrap mode
699  * \param minFilter	Minification filter mode
700  * \param magFilter	Magnification filter mode
701  * \return Sampler description.
702  *//*--------------------------------------------------------------------*/
mapGLSampler(deUint32 wrapS,deUint32 wrapT,deUint32 wrapR,deUint32 minFilter,deUint32 magFilter)703 tcu::Sampler mapGLSampler (deUint32 wrapS, deUint32 wrapT, deUint32 wrapR, deUint32 minFilter, deUint32 magFilter)
704 {
705 	return tcu::Sampler(mapGLWrapMode(wrapS), mapGLWrapMode(wrapT), mapGLWrapMode(wrapR),
706 						mapGLMinFilterMode(minFilter), mapGLMagFilterMode(magFilter),
707 						0.0f /* lod threshold */,
708 						true /* normalized coords */,
709 						tcu::Sampler::COMPAREMODE_NONE /* no compare */,
710 						0 /* compare channel */,
711 						tcu::Vec4(0.0f) /* border color, not used */);
712 }
713 
714 /*--------------------------------------------------------------------*//*!
715  * \brief Map GL compare function to tcu::Sampler::CompareMode.
716  *
717  * If no mapping is found, throws tcu::InternalError.
718  *
719  * \param mode GL compare mode
720  * \return Compare mode
721  *//*--------------------------------------------------------------------*/
mapGLCompareFunc(deUint32 mode)722 tcu::Sampler::CompareMode mapGLCompareFunc (deUint32 mode)
723 {
724 	switch (mode)
725 	{
726 		case GL_LESS:		return tcu::Sampler::COMPAREMODE_LESS;
727 		case GL_LEQUAL:		return tcu::Sampler::COMPAREMODE_LESS_OR_EQUAL;
728 		case GL_GREATER:	return tcu::Sampler::COMPAREMODE_GREATER;
729 		case GL_GEQUAL:		return tcu::Sampler::COMPAREMODE_GREATER_OR_EQUAL;
730 		case GL_EQUAL:		return tcu::Sampler::COMPAREMODE_EQUAL;
731 		case GL_NOTEQUAL:	return tcu::Sampler::COMPAREMODE_NOT_EQUAL;
732 		case GL_ALWAYS:		return tcu::Sampler::COMPAREMODE_ALWAYS;
733 		case GL_NEVER:		return tcu::Sampler::COMPAREMODE_NEVER;
734 		default:
735 			throw tcu::InternalError("Can't map GL compare mode " + tcu::toHex(mode).toString());
736 	}
737 }
738 
739 /*--------------------------------------------------------------------*//*!
740  * \brief Get GL wrap mode.
741  *
742  * If no mapping is found, throws tcu::InternalError.
743  *
744  * \param wrapMode Wrap mode
745  * \return GL wrap mode
746  *//*--------------------------------------------------------------------*/
getGLWrapMode(tcu::Sampler::WrapMode wrapMode)747 deUint32 getGLWrapMode (tcu::Sampler::WrapMode wrapMode)
748 {
749 	DE_ASSERT(wrapMode != tcu::Sampler::WRAPMODE_LAST);
750 	switch (wrapMode)
751 	{
752 		case tcu::Sampler::CLAMP_TO_EDGE:		return GL_CLAMP_TO_EDGE;
753 		case tcu::Sampler::CLAMP_TO_BORDER:		return GL_CLAMP_TO_BORDER;
754 		case tcu::Sampler::REPEAT_GL:			return GL_REPEAT;
755 		case tcu::Sampler::MIRRORED_REPEAT_GL:	return GL_MIRRORED_REPEAT;
756 		default:
757 			throw tcu::InternalError("Can't map wrap mode");
758 	}
759 }
760 
761 /*--------------------------------------------------------------------*//*!
762  * \brief Get GL filter mode.
763  *
764  * If no mapping is found, throws tcu::InternalError.
765  *
766  * \param filterMode Filter mode
767  * \return GL filter mode
768  *//*--------------------------------------------------------------------*/
getGLFilterMode(tcu::Sampler::FilterMode filterMode)769 deUint32 getGLFilterMode (tcu::Sampler::FilterMode filterMode)
770 {
771 	DE_ASSERT(filterMode != tcu::Sampler::FILTERMODE_LAST);
772 	switch (filterMode)
773 	{
774 		case tcu::Sampler::NEAREST:					return GL_NEAREST;
775 		case tcu::Sampler::LINEAR:					return GL_LINEAR;
776 		case tcu::Sampler::NEAREST_MIPMAP_NEAREST:	return GL_NEAREST_MIPMAP_NEAREST;
777 		case tcu::Sampler::NEAREST_MIPMAP_LINEAR:	return GL_NEAREST_MIPMAP_LINEAR;
778 		case tcu::Sampler::LINEAR_MIPMAP_NEAREST:	return GL_LINEAR_MIPMAP_NEAREST;
779 		case tcu::Sampler::LINEAR_MIPMAP_LINEAR:	return GL_LINEAR_MIPMAP_LINEAR;
780 		default:
781 			throw tcu::InternalError("Can't map filter mode");
782 	}
783 }
784 
785 /*--------------------------------------------------------------------*//*!
786  * \brief Get GL compare mode.
787  *
788  * If no mapping is found, throws tcu::InternalError.
789  *
790  * \param compareMode Compare mode
791  * \return GL compare mode
792  *//*--------------------------------------------------------------------*/
getGLCompareFunc(tcu::Sampler::CompareMode compareMode)793 deUint32 getGLCompareFunc (tcu::Sampler::CompareMode compareMode)
794 {
795 	DE_ASSERT(compareMode != tcu::Sampler::COMPAREMODE_NONE);
796 	switch (compareMode)
797 	{
798 		case tcu::Sampler::COMPAREMODE_NONE:				return GL_NONE;
799 		case tcu::Sampler::COMPAREMODE_LESS:				return GL_LESS;
800 		case tcu::Sampler::COMPAREMODE_LESS_OR_EQUAL:		return GL_LEQUAL;
801 		case tcu::Sampler::COMPAREMODE_GREATER:				return GL_GREATER;
802 		case tcu::Sampler::COMPAREMODE_GREATER_OR_EQUAL:	return GL_GEQUAL;
803 		case tcu::Sampler::COMPAREMODE_EQUAL:				return GL_EQUAL;
804 		case tcu::Sampler::COMPAREMODE_NOT_EQUAL:			return GL_NOTEQUAL;
805 		case tcu::Sampler::COMPAREMODE_ALWAYS:				return GL_ALWAYS;
806 		case tcu::Sampler::COMPAREMODE_NEVER:				return GL_NEVER;
807 		default:
808 			throw tcu::InternalError("Can't map compare mode");
809 	}
810 }
811 
812 /*--------------------------------------------------------------------*//*!
813  * \brief Get GL cube face.
814  *
815  * If no mapping is found, throws tcu::InternalError.
816  *
817  * \param face Cube face
818  * \return GL cube face
819  *//*--------------------------------------------------------------------*/
getGLCubeFace(tcu::CubeFace face)820 deUint32 getGLCubeFace (tcu::CubeFace face)
821 {
822 	DE_ASSERT(face != tcu::CUBEFACE_LAST);
823 	switch (face)
824 	{
825 		case tcu::CUBEFACE_NEGATIVE_X:	return GL_TEXTURE_CUBE_MAP_NEGATIVE_X;
826 		case tcu::CUBEFACE_POSITIVE_X:	return GL_TEXTURE_CUBE_MAP_POSITIVE_X;
827 		case tcu::CUBEFACE_NEGATIVE_Y:	return GL_TEXTURE_CUBE_MAP_NEGATIVE_Y;
828 		case tcu::CUBEFACE_POSITIVE_Y:	return GL_TEXTURE_CUBE_MAP_POSITIVE_Y;
829 		case tcu::CUBEFACE_NEGATIVE_Z:	return GL_TEXTURE_CUBE_MAP_NEGATIVE_Z;
830 		case tcu::CUBEFACE_POSITIVE_Z:	return GL_TEXTURE_CUBE_MAP_POSITIVE_Z;
831 		default:
832 			throw tcu::InternalError("Can't map cube face");
833 	}
834 }
835 
getCubeFaceFromGL(deUint32 face)836 tcu::CubeFace getCubeFaceFromGL (deUint32 face)
837 {
838 	switch (face)
839 	{
840 		case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:	return tcu::CUBEFACE_NEGATIVE_X;
841 		case GL_TEXTURE_CUBE_MAP_POSITIVE_X:	return tcu::CUBEFACE_POSITIVE_X;
842 		case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:	return tcu::CUBEFACE_NEGATIVE_Y;
843 		case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:	return tcu::CUBEFACE_POSITIVE_Y;
844 		case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:	return tcu::CUBEFACE_NEGATIVE_Z;
845 		case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:	return tcu::CUBEFACE_POSITIVE_Z;
846 		default:
847 			throw tcu::InternalError("Can't map cube face");
848 	}
849 }
850 
851 /*--------------------------------------------------------------------*//*!
852  * \brief Get GLSL sampler type for texture format.
853  *
854  * If no mapping is found, glu::TYPE_LAST is returned.
855  *
856  * \param format Texture format
857  * \return GLSL 1D sampler type for format
858  *//*--------------------------------------------------------------------*/
getSampler1DType(tcu::TextureFormat format)859 DataType getSampler1DType (tcu::TextureFormat format)
860 {
861 	using tcu::TextureFormat;
862 
863 	if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
864 		return TYPE_SAMPLER_1D;
865 
866 	if (format.order == TextureFormat::S)
867 		return TYPE_LAST;
868 
869 	switch (tcu::getTextureChannelClass(format.type))
870 	{
871 		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
872 		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
873 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
874 			return glu::TYPE_SAMPLER_1D;
875 
876 		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
877 			return glu::TYPE_INT_SAMPLER_1D;
878 
879 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
880 			return glu::TYPE_UINT_SAMPLER_1D;
881 
882 		default:
883 			return glu::TYPE_LAST;
884 	}
885 }
886 
887 /*--------------------------------------------------------------------*//*!
888  * \brief Get GLSL sampler type for texture format.
889  *
890  * If no mapping is found, glu::TYPE_LAST is returned.
891  *
892  * \param format Texture format
893  * \return GLSL 2D sampler type for format
894  *//*--------------------------------------------------------------------*/
getSampler2DType(tcu::TextureFormat format)895 DataType getSampler2DType (tcu::TextureFormat format)
896 {
897 	using tcu::TextureFormat;
898 
899 	if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
900 		return TYPE_SAMPLER_2D;
901 
902 	if (format.order == TextureFormat::S)
903 		return TYPE_LAST;
904 
905 	switch (tcu::getTextureChannelClass(format.type))
906 	{
907 		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
908 		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
909 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
910 			return glu::TYPE_SAMPLER_2D;
911 
912 		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
913 			return glu::TYPE_INT_SAMPLER_2D;
914 
915 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
916 			return glu::TYPE_UINT_SAMPLER_2D;
917 
918 		default:
919 			return glu::TYPE_LAST;
920 	}
921 }
922 
923 /*--------------------------------------------------------------------*//*!
924  * \brief Get GLSL sampler type for texture format.
925  *
926  * If no mapping is found, glu::TYPE_LAST is returned.
927  *
928  * \param format Texture format
929  * \return GLSL cube map sampler type for format
930  *//*--------------------------------------------------------------------*/
getSamplerCubeType(tcu::TextureFormat format)931 DataType getSamplerCubeType (tcu::TextureFormat format)
932 {
933 	using tcu::TextureFormat;
934 
935 	if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
936 		return TYPE_SAMPLER_CUBE;
937 
938 	if (format.order == TextureFormat::S)
939 		return TYPE_LAST;
940 
941 	switch (tcu::getTextureChannelClass(format.type))
942 	{
943 		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
944 		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
945 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
946 			return glu::TYPE_SAMPLER_CUBE;
947 
948 		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
949 			return glu::TYPE_INT_SAMPLER_CUBE;
950 
951 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
952 			return glu::TYPE_UINT_SAMPLER_CUBE;
953 
954 		default:
955 			return glu::TYPE_LAST;
956 	}
957 }
958 
959 /*--------------------------------------------------------------------*//*!
960  * \brief Get GLSL sampler type for texture format.
961  *
962  * If no mapping is found, glu::TYPE_LAST is returned.
963  *
964  * \param format Texture format
965  * \return GLSL 1D array sampler type for format
966  *//*--------------------------------------------------------------------*/
getSampler1DArrayType(tcu::TextureFormat format)967 DataType getSampler1DArrayType (tcu::TextureFormat format)
968 {
969 	using tcu::TextureFormat;
970 
971 	if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
972 		return TYPE_SAMPLER_1D_ARRAY;
973 
974 	if (format.order == TextureFormat::S)
975 		return TYPE_LAST;
976 
977 	switch (tcu::getTextureChannelClass(format.type))
978 	{
979 		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
980 		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
981 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
982 			return glu::TYPE_SAMPLER_1D_ARRAY;
983 
984 		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
985 			return glu::TYPE_INT_SAMPLER_1D_ARRAY;
986 
987 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
988 			return glu::TYPE_UINT_SAMPLER_1D_ARRAY;
989 
990 		default:
991 			return glu::TYPE_LAST;
992 	}
993 }
994 
995 /*--------------------------------------------------------------------*//*!
996  * \brief Get GLSL sampler type for texture format.
997  *
998  * If no mapping is found, glu::TYPE_LAST is returned.
999  *
1000  * \param format Texture format
1001  * \return GLSL 2D array sampler type for format
1002  *//*--------------------------------------------------------------------*/
getSampler2DArrayType(tcu::TextureFormat format)1003 DataType getSampler2DArrayType (tcu::TextureFormat format)
1004 {
1005 	using tcu::TextureFormat;
1006 
1007 	if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
1008 		return TYPE_SAMPLER_2D_ARRAY;
1009 
1010 	if (format.order == TextureFormat::S)
1011 		return TYPE_LAST;
1012 
1013 	switch (tcu::getTextureChannelClass(format.type))
1014 	{
1015 		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1016 		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1017 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1018 			return glu::TYPE_SAMPLER_2D_ARRAY;
1019 
1020 		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1021 			return glu::TYPE_INT_SAMPLER_2D_ARRAY;
1022 
1023 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1024 			return glu::TYPE_UINT_SAMPLER_2D_ARRAY;
1025 
1026 		default:
1027 			return glu::TYPE_LAST;
1028 	}
1029 }
1030 
1031 /*--------------------------------------------------------------------*//*!
1032  * \brief Get GLSL sampler type for texture format.
1033  *
1034  * If no mapping is found, glu::TYPE_LAST is returned.
1035  *
1036  * \param format Texture format
1037  * \return GLSL 3D sampler type for format
1038  *//*--------------------------------------------------------------------*/
getSampler3DType(tcu::TextureFormat format)1039 DataType getSampler3DType (tcu::TextureFormat format)
1040 {
1041 	using tcu::TextureFormat;
1042 
1043 	if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
1044 		return TYPE_SAMPLER_3D;
1045 
1046 	if (format.order == TextureFormat::S)
1047 		return TYPE_LAST;
1048 
1049 	switch (tcu::getTextureChannelClass(format.type))
1050 	{
1051 		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1052 		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1053 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1054 			return glu::TYPE_SAMPLER_3D;
1055 
1056 		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1057 			return glu::TYPE_INT_SAMPLER_3D;
1058 
1059 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1060 			return glu::TYPE_UINT_SAMPLER_3D;
1061 
1062 		default:
1063 			return glu::TYPE_LAST;
1064 	}
1065 }
1066 
1067 /*--------------------------------------------------------------------*//*!
1068  * \brief Get GLSL sampler type for texture format.
1069  *
1070  * If no mapping is found, glu::TYPE_LAST is returned.
1071  *
1072  * \param format Texture format
1073  * \return GLSL cube map array sampler type for format
1074  *//*--------------------------------------------------------------------*/
getSamplerCubeArrayType(tcu::TextureFormat format)1075 DataType getSamplerCubeArrayType (tcu::TextureFormat format)
1076 {
1077 	using tcu::TextureFormat;
1078 
1079 	if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
1080 		return TYPE_SAMPLER_CUBE_ARRAY;
1081 
1082 	if (format.order == TextureFormat::S)
1083 		return TYPE_LAST;
1084 
1085 	switch (tcu::getTextureChannelClass(format.type))
1086 	{
1087 		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1088 		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1089 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1090 			return glu::TYPE_SAMPLER_CUBE_ARRAY;
1091 
1092 		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1093 			return glu::TYPE_INT_SAMPLER_CUBE_ARRAY;
1094 
1095 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1096 			return glu::TYPE_UINT_SAMPLER_CUBE_ARRAY;
1097 
1098 		default:
1099 			return glu::TYPE_LAST;
1100 	}
1101 }
1102 
1103 enum RenderableType
1104 {
1105 	RENDERABLE_COLOR	= (1<<0),
1106 	RENDERABLE_DEPTH	= (1<<1),
1107 	RENDERABLE_STENCIL	= (1<<2)
1108 };
1109 
getRenderableBitsES3(const ContextInfo & contextInfo,deUint32 internalFormat)1110 static deUint32 getRenderableBitsES3 (const ContextInfo& contextInfo, deUint32 internalFormat)
1111 {
1112 	switch (internalFormat)
1113 	{
1114 		// Color-renderable formats
1115 		case GL_RGBA32I:
1116 		case GL_RGBA32UI:
1117 		case GL_RGBA16I:
1118 		case GL_RGBA16UI:
1119 		case GL_RGBA8:
1120 		case GL_RGBA8I:
1121 		case GL_RGBA8UI:
1122 		case GL_SRGB8_ALPHA8:
1123 		case GL_RGB10_A2:
1124 		case GL_RGB10_A2UI:
1125 		case GL_RGBA4:
1126 		case GL_RGB5_A1:
1127 		case GL_RGB8:
1128 		case GL_RGB565:
1129 		case GL_RG32I:
1130 		case GL_RG32UI:
1131 		case GL_RG16I:
1132 		case GL_RG16UI:
1133 		case GL_RG8:
1134 		case GL_RG8I:
1135 		case GL_RG8UI:
1136 		case GL_R32I:
1137 		case GL_R32UI:
1138 		case GL_R16I:
1139 		case GL_R16UI:
1140 		case GL_R8:
1141 		case GL_R8I:
1142 		case GL_R8UI:
1143 			return RENDERABLE_COLOR;
1144 
1145 		// GL_EXT_color_buffer_float
1146 		case GL_RGBA32F:
1147 		case GL_R11F_G11F_B10F:
1148 		case GL_RG32F:
1149 		case GL_R32F:
1150 			if (contextInfo.isExtensionSupported("GL_EXT_color_buffer_float"))
1151 				return RENDERABLE_COLOR;
1152 			else
1153 				return 0;
1154 
1155 		// GL_EXT_color_buffer_float / GL_EXT_color_buffer_half_float
1156 		case GL_RGBA16F:
1157 		case GL_RG16F:
1158 		case GL_R16F:
1159 			if (contextInfo.isExtensionSupported("GL_EXT_color_buffer_float") ||
1160 				contextInfo.isExtensionSupported("GL_EXT_color_buffer_half_float"))
1161 				return RENDERABLE_COLOR;
1162 			else
1163 				return 0;
1164 
1165 		// Depth formats
1166 		case GL_DEPTH_COMPONENT32F:
1167 		case GL_DEPTH_COMPONENT24:
1168 		case GL_DEPTH_COMPONENT16:
1169 			return RENDERABLE_DEPTH;
1170 
1171 		// Depth+stencil formats
1172 		case GL_DEPTH32F_STENCIL8:
1173 		case GL_DEPTH24_STENCIL8:
1174 			return RENDERABLE_DEPTH|RENDERABLE_STENCIL;
1175 
1176 		// Stencil formats
1177 		case GL_STENCIL_INDEX8:
1178 			return RENDERABLE_STENCIL;
1179 
1180 		default:
1181 			return 0;
1182 	}
1183 }
1184 
1185 /*--------------------------------------------------------------------*//*!
1186  * \brief Check if sized internal format is color-renderable.
1187  * \note Works currently only on ES3 context.
1188  *//*--------------------------------------------------------------------*/
isSizedFormatColorRenderable(const RenderContext & renderCtx,const ContextInfo & contextInfo,deUint32 sizedFormat)1189 bool isSizedFormatColorRenderable (const RenderContext& renderCtx, const ContextInfo& contextInfo, deUint32 sizedFormat)
1190 {
1191 	deUint32 renderable = 0;
1192 
1193 	if (renderCtx.getType().getAPI() == ApiType::es(3,0))
1194 		renderable = getRenderableBitsES3(contextInfo, sizedFormat);
1195 	else
1196 		throw tcu::InternalError("Context type not supported in query");
1197 
1198 	return (renderable & RENDERABLE_COLOR) != 0;
1199 }
1200 
getDefaultGatherOffsets(void)1201 const tcu::IVec2 (&getDefaultGatherOffsets (void))[4]
1202 {
1203 	static const tcu::IVec2 s_defaultOffsets[4] =
1204 	{
1205 		tcu::IVec2(0, 1),
1206 		tcu::IVec2(1, 1),
1207 		tcu::IVec2(1, 0),
1208 		tcu::IVec2(0, 0),
1209 	};
1210 	return s_defaultOffsets;
1211 }
1212 
1213 tcu::PixelBufferAccess getTextureBufferEffectiveRefTexture (TextureBuffer& buffer, int maxTextureBufferSize)
1214 {
1215 	DE_ASSERT(maxTextureBufferSize > 0);
1216 
1217 	const tcu::PixelBufferAccess& fullAccess = buffer.getFullRefTexture();
1218 
1219 	return tcu::PixelBufferAccess(fullAccess.getFormat(),
1220 								  tcu::IVec3(de::min(fullAccess.getWidth(), maxTextureBufferSize), 1, 1),
1221 								  fullAccess.getPitch(),
1222 								  fullAccess.getDataPtr());
1223 }
1224 
getTextureBufferEffectiveRefTexture(const TextureBuffer & buffer,int maxTextureBufferSize)1225 tcu::ConstPixelBufferAccess getTextureBufferEffectiveRefTexture (const TextureBuffer& buffer, int maxTextureBufferSize)
1226 {
1227 	return getTextureBufferEffectiveRefTexture(const_cast<TextureBuffer&>(buffer), maxTextureBufferSize);
1228 }
1229 
1230 } // glu
1231