• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program OpenGL (ES) Module
3  * -----------------------------------------------
4  *
5  * Copyright 2015 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 State Query tests.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "glsTextureStateQueryTests.hpp"
25 #include "gluStrUtil.hpp"
26 #include "gluObjectWrapper.hpp"
27 #include "gluCallLogWrapper.hpp"
28 #include "gluContextInfo.hpp"
29 #include "gluTextureUtil.hpp"
30 #include "glwEnums.hpp"
31 #include "deUniquePtr.hpp"
32 #include "deRandom.hpp"
33 #include "deStringUtil.hpp"
34 
35 namespace deqp
36 {
37 namespace gls
38 {
39 namespace TextureStateQueryTests
40 {
41 namespace
42 {
43 
44 using namespace glw;
45 using namespace gls::StateQueryUtil;
46 
mapTesterToPname(TesterType tester)47 static glw::GLenum mapTesterToPname (TesterType tester)
48 {
49 
50 #define CASE_ALL_SETTERS(X) case X: case X ## _SET_PURE_INT: case X ## _SET_PURE_UINT
51 
52 	switch (tester)
53 	{
54 		CASE_ALL_SETTERS(TESTER_TEXTURE_SWIZZLE_R):				return GL_TEXTURE_SWIZZLE_R;
55 		CASE_ALL_SETTERS(TESTER_TEXTURE_SWIZZLE_G):				return GL_TEXTURE_SWIZZLE_G;
56 		CASE_ALL_SETTERS(TESTER_TEXTURE_SWIZZLE_B):				return GL_TEXTURE_SWIZZLE_B;
57 		CASE_ALL_SETTERS(TESTER_TEXTURE_SWIZZLE_A):				return GL_TEXTURE_SWIZZLE_A;
58 
59 		CASE_ALL_SETTERS(TESTER_TEXTURE_WRAP_S):
60 		case TESTER_TEXTURE_WRAP_S_CLAMP_TO_BORDER:				return GL_TEXTURE_WRAP_S;
61 
62 		CASE_ALL_SETTERS(TESTER_TEXTURE_WRAP_T):
63 		case TESTER_TEXTURE_WRAP_T_CLAMP_TO_BORDER:				return GL_TEXTURE_WRAP_T;
64 
65 		CASE_ALL_SETTERS(TESTER_TEXTURE_WRAP_R):
66 		case TESTER_TEXTURE_WRAP_R_CLAMP_TO_BORDER:				return GL_TEXTURE_WRAP_R;
67 
68 		CASE_ALL_SETTERS(TESTER_TEXTURE_MAG_FILTER):			return GL_TEXTURE_MAG_FILTER;
69 		CASE_ALL_SETTERS(TESTER_TEXTURE_MIN_FILTER):			return GL_TEXTURE_MIN_FILTER;
70 		CASE_ALL_SETTERS(TESTER_TEXTURE_MIN_LOD):				return GL_TEXTURE_MIN_LOD;
71 		CASE_ALL_SETTERS(TESTER_TEXTURE_MAX_LOD):				return GL_TEXTURE_MAX_LOD;
72 		CASE_ALL_SETTERS(TESTER_TEXTURE_BASE_LEVEL):			return GL_TEXTURE_BASE_LEVEL;
73 		CASE_ALL_SETTERS(TESTER_TEXTURE_MAX_LEVEL):				return GL_TEXTURE_MAX_LEVEL;
74 		CASE_ALL_SETTERS(TESTER_TEXTURE_COMPARE_MODE):			return GL_TEXTURE_COMPARE_MODE;
75 		CASE_ALL_SETTERS(TESTER_TEXTURE_COMPARE_FUNC):			return GL_TEXTURE_COMPARE_FUNC;
76 		case TESTER_TEXTURE_IMMUTABLE_LEVELS:					return GL_TEXTURE_IMMUTABLE_LEVELS;
77 		case TESTER_TEXTURE_IMMUTABLE_FORMAT:					return GL_TEXTURE_IMMUTABLE_FORMAT;
78 		CASE_ALL_SETTERS(TESTER_DEPTH_STENCIL_TEXTURE_MODE):	return GL_DEPTH_STENCIL_TEXTURE_MODE;
79 		CASE_ALL_SETTERS(TESTER_TEXTURE_SRGB_DECODE_EXT):		return GL_TEXTURE_SRGB_DECODE_EXT;
80 		case TESTER_TEXTURE_BORDER_COLOR:						return GL_TEXTURE_BORDER_COLOR;
81 
82 		default:
83 			DE_ASSERT(false);
84 			return -1;
85 	}
86 
87 #undef CASE_PURE_SETTERS
88 }
89 
querySupportsSigned(QueryType type)90 static bool querySupportsSigned (QueryType type)
91 {
92 	return	type != QUERY_TEXTURE_PARAM_PURE_UNSIGNED_INTEGER &&
93 			type != QUERY_SAMPLER_PARAM_PURE_UNSIGNED_INTEGER;
94 }
95 
isPureIntTester(TesterType tester)96 static bool isPureIntTester (TesterType tester)
97 {
98 #define HANDLE_ALL_SETTERS(X) \
99 		case X: \
100 		case X ## _SET_PURE_UINT: return false; \
101 		case X ## _SET_PURE_INT: return true;
102 
103 	switch (tester)
104 	{
105 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_SWIZZLE_R)
106 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_SWIZZLE_G)
107 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_SWIZZLE_B)
108 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_SWIZZLE_A)
109 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_WRAP_S)
110 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_WRAP_T)
111 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_WRAP_R)
112 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_MAG_FILTER)
113 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_MIN_FILTER)
114 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_MIN_LOD)
115 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_MAX_LOD)
116 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_BASE_LEVEL)
117 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_MAX_LEVEL)
118 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_COMPARE_MODE)
119 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_COMPARE_FUNC)
120 		HANDLE_ALL_SETTERS(TESTER_DEPTH_STENCIL_TEXTURE_MODE)
121 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_SRGB_DECODE_EXT)
122 
123 		case TESTER_TEXTURE_IMMUTABLE_LEVELS:
124 		case TESTER_TEXTURE_IMMUTABLE_FORMAT:
125 		case TESTER_TEXTURE_WRAP_S_CLAMP_TO_BORDER:
126 		case TESTER_TEXTURE_WRAP_T_CLAMP_TO_BORDER:
127 		case TESTER_TEXTURE_WRAP_R_CLAMP_TO_BORDER:
128 		case TESTER_TEXTURE_BORDER_COLOR:
129 			return false;
130 
131 		default:
132 			DE_ASSERT(false);
133 			return false;
134 	}
135 
136 #undef HANDLE_ALL_SETTERS
137 }
138 
isPureUintTester(TesterType tester)139 static bool isPureUintTester (TesterType tester)
140 {
141 #define HANDLE_ALL_SETTERS(X) \
142 		case X: \
143 		case X ## _SET_PURE_INT: return false; \
144 		case X ## _SET_PURE_UINT: return true;
145 
146 	switch (tester)
147 	{
148 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_SWIZZLE_R)
149 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_SWIZZLE_G)
150 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_SWIZZLE_B)
151 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_SWIZZLE_A)
152 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_WRAP_S)
153 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_WRAP_T)
154 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_WRAP_R)
155 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_MAG_FILTER)
156 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_MIN_FILTER)
157 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_MIN_LOD)
158 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_MAX_LOD)
159 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_BASE_LEVEL)
160 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_MAX_LEVEL)
161 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_COMPARE_MODE)
162 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_COMPARE_FUNC)
163 		HANDLE_ALL_SETTERS(TESTER_DEPTH_STENCIL_TEXTURE_MODE)
164 		HANDLE_ALL_SETTERS(TESTER_TEXTURE_SRGB_DECODE_EXT)
165 
166 		case TESTER_TEXTURE_IMMUTABLE_LEVELS:
167 		case TESTER_TEXTURE_IMMUTABLE_FORMAT:
168 		case TESTER_TEXTURE_WRAP_S_CLAMP_TO_BORDER:
169 		case TESTER_TEXTURE_WRAP_T_CLAMP_TO_BORDER:
170 		case TESTER_TEXTURE_WRAP_R_CLAMP_TO_BORDER:
171 		case TESTER_TEXTURE_BORDER_COLOR:
172 			return false;
173 
174 		default:
175 			DE_ASSERT(false);
176 			return false;
177 	}
178 
179 #undef HANDLE_ALL_SETTERS
180 }
181 
182 class RequiredExtensions
183 {
184 public:
RequiredExtensions(void)185 								RequiredExtensions	(void)									{ }
RequiredExtensions(const char * ext)186 	explicit					RequiredExtensions	(const char* ext)						{ add(ext);				}
RequiredExtensions(const char * extA,const char * extB)187 								RequiredExtensions	(const char* extA, const char* extB)	{ add(extA); add(extB);	}
188 
189 	void						add					(const char* ext);
190 	void						add					(const RequiredExtensions& other);
191 	void						check				(const glu::ContextInfo&) const;
192 
193 private:
194 	std::vector<const char*>	m_extensions;
195 };
196 
add(const char * ext)197 void RequiredExtensions::add (const char* ext)
198 {
199 	for (int ndx = 0; ndx < (int)m_extensions.size(); ++ndx)
200 		if (deStringEqual(m_extensions[ndx], ext) == DE_TRUE)
201 			return;
202 	m_extensions.push_back(ext);
203 }
204 
add(const RequiredExtensions & other)205 void RequiredExtensions::add (const RequiredExtensions& other)
206 {
207 	for (int ndx = 0; ndx < (int)other.m_extensions.size(); ++ndx)
208 		add(other.m_extensions[ndx]);
209 }
210 
check(const glu::ContextInfo & ctxInfo) const211 void RequiredExtensions::check (const glu::ContextInfo& ctxInfo) const
212 {
213 	std::vector<const char*> failedExtensions;
214 
215 	for (int ndx = 0; ndx < (int)m_extensions.size(); ++ndx)
216 		if (!ctxInfo.isExtensionSupported(m_extensions[ndx]))
217 			failedExtensions.push_back(m_extensions[ndx]);
218 
219 	if (!failedExtensions.empty())
220 	{
221 		std::ostringstream buf;
222 		buf << "Test requires extension: ";
223 
224 		for (int ndx = 0; ndx < (int)failedExtensions.size(); ++ndx)
225 		{
226 			if (ndx)
227 				buf << ", ";
228 			buf << failedExtensions[ndx];
229 		}
230 
231 		throw tcu::NotSupportedError(buf.str());
232 	}
233 }
234 
235 namespace es30
236 {
237 
isCoreTextureTarget(glw::GLenum target)238 static bool isCoreTextureTarget (glw::GLenum target)
239 {
240 	return	target == GL_TEXTURE_2D			||
241 			target == GL_TEXTURE_3D			||
242 			target == GL_TEXTURE_2D_ARRAY	||
243 			target == GL_TEXTURE_CUBE_MAP;
244 }
245 
getTextureTargetExtension(glw::GLenum target)246 static RequiredExtensions getTextureTargetExtension (glw::GLenum target)
247 {
248 	DE_UNREF(target);
249 	DE_ASSERT(false);
250 	return RequiredExtensions();
251 }
252 
isCoreTextureParam(glw::GLenum pname)253 static bool isCoreTextureParam (glw::GLenum pname)
254 {
255 	return	pname == GL_TEXTURE_BASE_LEVEL			||
256 			pname == GL_TEXTURE_COMPARE_MODE		||
257 			pname == GL_TEXTURE_COMPARE_FUNC		||
258 			pname == GL_TEXTURE_MAG_FILTER			||
259 			pname == GL_TEXTURE_MAX_LEVEL			||
260 			pname == GL_TEXTURE_MAX_LOD				||
261 			pname == GL_TEXTURE_MIN_FILTER			||
262 			pname == GL_TEXTURE_MIN_LOD				||
263 			pname == GL_TEXTURE_SWIZZLE_R			||
264 			pname == GL_TEXTURE_SWIZZLE_G			||
265 			pname == GL_TEXTURE_SWIZZLE_B			||
266 			pname == GL_TEXTURE_SWIZZLE_A			||
267 			pname == GL_TEXTURE_WRAP_S				||
268 			pname == GL_TEXTURE_WRAP_T				||
269 			pname == GL_TEXTURE_WRAP_R				||
270 			pname == GL_TEXTURE_IMMUTABLE_FORMAT	||
271 			pname == GL_TEXTURE_IMMUTABLE_LEVELS;
272 }
273 
getTextureParamExtension(glw::GLenum pname)274 static RequiredExtensions getTextureParamExtension (glw::GLenum pname)
275 {
276 	DE_UNREF(pname);
277 	DE_ASSERT(false);
278 	return RequiredExtensions();
279 }
280 
isCoreQuery(QueryType query)281 static bool isCoreQuery (QueryType query)
282 {
283 	return	query == QUERY_TEXTURE_PARAM_INTEGER		||
284 			query == QUERY_TEXTURE_PARAM_FLOAT			||
285 			query == QUERY_TEXTURE_PARAM_INTEGER_VEC4	||
286 			query == QUERY_TEXTURE_PARAM_FLOAT_VEC4		||
287 			query == QUERY_SAMPLER_PARAM_INTEGER		||
288 			query == QUERY_SAMPLER_PARAM_FLOAT			||
289 			query == QUERY_SAMPLER_PARAM_INTEGER_VEC4	||
290 			query == QUERY_SAMPLER_PARAM_FLOAT_VEC4;
291 }
292 
getQueryExtension(QueryType query)293 static RequiredExtensions getQueryExtension (QueryType query)
294 {
295 	DE_UNREF(query);
296 	DE_ASSERT(false);
297 	return RequiredExtensions();
298 }
299 
isCoreTester(TesterType tester)300 static bool isCoreTester (TesterType tester)
301 {
302 	return	tester == TESTER_TEXTURE_SWIZZLE_R			||
303 			tester == TESTER_TEXTURE_SWIZZLE_G			||
304 			tester == TESTER_TEXTURE_SWIZZLE_B			||
305 			tester == TESTER_TEXTURE_SWIZZLE_A			||
306 			tester == TESTER_TEXTURE_WRAP_S				||
307 			tester == TESTER_TEXTURE_WRAP_T				||
308 			tester == TESTER_TEXTURE_WRAP_R				||
309 			tester == TESTER_TEXTURE_MAG_FILTER			||
310 			tester == TESTER_TEXTURE_MIN_FILTER			||
311 			tester == TESTER_TEXTURE_MIN_LOD			||
312 			tester == TESTER_TEXTURE_MAX_LOD			||
313 			tester == TESTER_TEXTURE_BASE_LEVEL			||
314 			tester == TESTER_TEXTURE_MAX_LEVEL			||
315 			tester == TESTER_TEXTURE_COMPARE_MODE		||
316 			tester == TESTER_TEXTURE_COMPARE_FUNC		||
317 			tester == TESTER_TEXTURE_IMMUTABLE_LEVELS	||
318 			tester == TESTER_TEXTURE_IMMUTABLE_FORMAT;
319 }
320 
getTesterExtension(TesterType tester)321 static RequiredExtensions getTesterExtension (TesterType tester)
322 {
323 	DE_UNREF(tester);
324 	DE_ASSERT(false);
325 	return RequiredExtensions();
326 }
327 
328 } // es30
329 
330 namespace es31
331 {
332 
isCoreTextureTarget(glw::GLenum target)333 static bool isCoreTextureTarget (glw::GLenum target)
334 {
335 	return	es30::isCoreTextureTarget(target) ||
336 			target == GL_TEXTURE_2D_MULTISAMPLE;
337 }
338 
getTextureTargetExtension(glw::GLenum target)339 static RequiredExtensions getTextureTargetExtension (glw::GLenum target)
340 {
341 	switch (target)
342 	{
343 		case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:	return RequiredExtensions("GL_OES_texture_storage_multisample_2d_array");
344 		case GL_TEXTURE_BUFFER:					return RequiredExtensions("GL_EXT_texture_buffer");
345 		case GL_TEXTURE_CUBE_MAP_ARRAY:			return RequiredExtensions("GL_EXT_texture_cube_map_array");
346 		default:
347 			DE_ASSERT(false);
348 			return RequiredExtensions();
349 	}
350 }
351 
isCoreTextureParam(glw::GLenum pname)352 static bool isCoreTextureParam (glw::GLenum pname)
353 {
354 	return	es30::isCoreTextureParam(pname) ||
355 			pname == GL_DEPTH_STENCIL_TEXTURE_MODE;
356 }
357 
getTextureParamExtension(glw::GLenum pname)358 static RequiredExtensions getTextureParamExtension (glw::GLenum pname)
359 {
360 	switch (pname)
361 	{
362 		case GL_TEXTURE_SRGB_DECODE_EXT:	return RequiredExtensions("GL_EXT_texture_sRGB_decode");
363 		case GL_TEXTURE_BORDER_COLOR:		return RequiredExtensions("GL_EXT_texture_border_clamp");
364 		default:
365 			DE_ASSERT(false);
366 			return RequiredExtensions();
367 	}
368 }
369 
isCoreQuery(QueryType query)370 static bool isCoreQuery (QueryType query)
371 {
372 	return es30::isCoreQuery(query);
373 }
374 
getQueryExtension(QueryType query)375 static RequiredExtensions getQueryExtension (QueryType query)
376 {
377 	switch (query)
378 	{
379 		case QUERY_TEXTURE_PARAM_PURE_INTEGER:
380 		case QUERY_TEXTURE_PARAM_PURE_UNSIGNED_INTEGER:
381 		case QUERY_TEXTURE_PARAM_PURE_INTEGER_VEC4:
382 		case QUERY_TEXTURE_PARAM_PURE_UNSIGNED_INTEGER_VEC4:
383 		case QUERY_SAMPLER_PARAM_PURE_INTEGER:
384 		case QUERY_SAMPLER_PARAM_PURE_UNSIGNED_INTEGER:
385 		case QUERY_SAMPLER_PARAM_PURE_INTEGER_VEC4:
386 		case QUERY_SAMPLER_PARAM_PURE_UNSIGNED_INTEGER_VEC4:
387 			return RequiredExtensions("GL_EXT_texture_border_clamp");
388 
389 		default:
390 			DE_ASSERT(false);
391 			return RequiredExtensions();
392 	}
393 }
394 
isCoreTester(TesterType tester)395 static bool isCoreTester (TesterType tester)
396 {
397 	return	es30::isCoreTester(tester)							||
398 			tester == TESTER_DEPTH_STENCIL_TEXTURE_MODE;
399 }
400 
getTesterExtension(TesterType tester)401 static RequiredExtensions getTesterExtension (TesterType tester)
402 {
403 #define CASE_PURE_SETTERS(X) case X ## _SET_PURE_INT: case X ## _SET_PURE_UINT
404 
405 	switch (tester)
406 	{
407 		CASE_PURE_SETTERS(TESTER_TEXTURE_SWIZZLE_R):
408 		CASE_PURE_SETTERS(TESTER_TEXTURE_SWIZZLE_G):
409 		CASE_PURE_SETTERS(TESTER_TEXTURE_SWIZZLE_B):
410 		CASE_PURE_SETTERS(TESTER_TEXTURE_SWIZZLE_A):
411 		CASE_PURE_SETTERS(TESTER_TEXTURE_WRAP_S):
412 		CASE_PURE_SETTERS(TESTER_TEXTURE_WRAP_T):
413 		CASE_PURE_SETTERS(TESTER_TEXTURE_WRAP_R):
414 		CASE_PURE_SETTERS(TESTER_TEXTURE_MAG_FILTER):
415 		CASE_PURE_SETTERS(TESTER_TEXTURE_MIN_FILTER):
416 		CASE_PURE_SETTERS(TESTER_TEXTURE_MIN_LOD):
417 		CASE_PURE_SETTERS(TESTER_TEXTURE_MAX_LOD):
418 		CASE_PURE_SETTERS(TESTER_TEXTURE_BASE_LEVEL):
419 		CASE_PURE_SETTERS(TESTER_TEXTURE_MAX_LEVEL):
420 		CASE_PURE_SETTERS(TESTER_TEXTURE_COMPARE_MODE):
421 		CASE_PURE_SETTERS(TESTER_TEXTURE_COMPARE_FUNC):
422 		CASE_PURE_SETTERS(TESTER_DEPTH_STENCIL_TEXTURE_MODE):
423 		case TESTER_TEXTURE_WRAP_S_CLAMP_TO_BORDER:
424 		case TESTER_TEXTURE_WRAP_T_CLAMP_TO_BORDER:
425 		case TESTER_TEXTURE_WRAP_R_CLAMP_TO_BORDER:
426 		case TESTER_TEXTURE_BORDER_COLOR:
427 			return RequiredExtensions("GL_EXT_texture_border_clamp");
428 
429 		case TESTER_TEXTURE_SRGB_DECODE_EXT:
430 			return RequiredExtensions("GL_EXT_texture_sRGB_decode");
431 
432 		CASE_PURE_SETTERS(TESTER_TEXTURE_SRGB_DECODE_EXT):
433 			return RequiredExtensions("GL_EXT_texture_sRGB_decode", "GL_EXT_texture_border_clamp");
434 
435 		default:
436 			DE_ASSERT(false);
437 			return RequiredExtensions();
438 	}
439 
440 #undef CASE_PURE_SETTERS
441 }
442 
443 } // es31
444 
445 namespace es32
446 {
447 
isCoreTextureTarget(glw::GLenum target)448 static bool isCoreTextureTarget (glw::GLenum target)
449 {
450 	return	es31::isCoreTextureTarget(target)			||
451 			target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY	||
452 			target == GL_TEXTURE_BUFFER					||
453 			target == GL_TEXTURE_CUBE_MAP_ARRAY;
454 }
455 
getTextureTargetExtension(glw::GLenum target)456 static RequiredExtensions getTextureTargetExtension (glw::GLenum target)
457 {
458 	DE_UNREF(target);
459 	DE_ASSERT(false);
460 	return RequiredExtensions();
461 }
462 
isCoreTextureParam(glw::GLenum pname)463 static bool isCoreTextureParam (glw::GLenum pname)
464 {
465 	return	es31::isCoreTextureParam(pname)		||
466 			pname == GL_TEXTURE_BORDER_COLOR;
467 }
468 
getTextureParamExtension(glw::GLenum pname)469 static RequiredExtensions getTextureParamExtension (glw::GLenum pname)
470 {
471 	switch (pname)
472 	{
473 		case GL_TEXTURE_SRGB_DECODE_EXT:	return RequiredExtensions("GL_EXT_texture_sRGB_decode");
474 		default:
475 			DE_ASSERT(false);
476 			return RequiredExtensions();
477 	}
478 }
479 
isCoreQuery(QueryType query)480 static bool isCoreQuery (QueryType query)
481 {
482 	return	es31::isCoreQuery(query)								||
483 			query == QUERY_TEXTURE_PARAM_PURE_INTEGER				||
484 			query == QUERY_TEXTURE_PARAM_PURE_INTEGER				||
485 			query == QUERY_TEXTURE_PARAM_PURE_UNSIGNED_INTEGER		||
486 			query == QUERY_TEXTURE_PARAM_PURE_INTEGER_VEC4			||
487 			query == QUERY_TEXTURE_PARAM_PURE_UNSIGNED_INTEGER_VEC4	||
488 			query == QUERY_SAMPLER_PARAM_PURE_INTEGER				||
489 			query == QUERY_SAMPLER_PARAM_PURE_UNSIGNED_INTEGER		||
490 			query == QUERY_SAMPLER_PARAM_PURE_INTEGER_VEC4			||
491 			query == QUERY_SAMPLER_PARAM_PURE_UNSIGNED_INTEGER_VEC4;
492 }
493 
getQueryExtension(QueryType query)494 static RequiredExtensions getQueryExtension (QueryType query)
495 {
496 	DE_UNREF(query);
497 	DE_ASSERT(false);
498 	return RequiredExtensions();
499 }
500 
isCoreTester(TesterType tester)501 static bool isCoreTester (TesterType tester)
502 {
503 #define COMPARE_PURE_SETTERS(TESTER, X) ((TESTER) == X ## _SET_PURE_INT) || ((TESTER) == X ## _SET_PURE_UINT)
504 
505 	return	es31::isCoreTester(tester)										||
506 			COMPARE_PURE_SETTERS(tester, TESTER_TEXTURE_SWIZZLE_R)			||
507 			COMPARE_PURE_SETTERS(tester, TESTER_TEXTURE_SWIZZLE_G)			||
508 			COMPARE_PURE_SETTERS(tester, TESTER_TEXTURE_SWIZZLE_B)			||
509 			COMPARE_PURE_SETTERS(tester, TESTER_TEXTURE_SWIZZLE_A)			||
510 			COMPARE_PURE_SETTERS(tester, TESTER_TEXTURE_WRAP_S)				||
511 			COMPARE_PURE_SETTERS(tester, TESTER_TEXTURE_WRAP_T)				||
512 			COMPARE_PURE_SETTERS(tester, TESTER_TEXTURE_WRAP_R)				||
513 			COMPARE_PURE_SETTERS(tester, TESTER_TEXTURE_MAG_FILTER)			||
514 			COMPARE_PURE_SETTERS(tester, TESTER_TEXTURE_MIN_FILTER)			||
515 			COMPARE_PURE_SETTERS(tester, TESTER_TEXTURE_MIN_LOD)			||
516 			COMPARE_PURE_SETTERS(tester, TESTER_TEXTURE_MAX_LOD)			||
517 			COMPARE_PURE_SETTERS(tester, TESTER_TEXTURE_BASE_LEVEL)			||
518 			COMPARE_PURE_SETTERS(tester, TESTER_TEXTURE_MAX_LEVEL)			||
519 			COMPARE_PURE_SETTERS(tester, TESTER_TEXTURE_COMPARE_MODE)		||
520 			COMPARE_PURE_SETTERS(tester, TESTER_TEXTURE_COMPARE_FUNC)		||
521 			COMPARE_PURE_SETTERS(tester, TESTER_DEPTH_STENCIL_TEXTURE_MODE)	||
522 			tester == TESTER_TEXTURE_WRAP_S_CLAMP_TO_BORDER					||
523 			tester == TESTER_TEXTURE_WRAP_T_CLAMP_TO_BORDER					||
524 			tester == TESTER_TEXTURE_WRAP_R_CLAMP_TO_BORDER					||
525 			tester == TESTER_TEXTURE_BORDER_COLOR;
526 
527 #undef COMPARE_PURE_SETTERS
528 }
529 
getTesterExtension(TesterType tester)530 static RequiredExtensions getTesterExtension (TesterType tester)
531 {
532 #define CASE_PURE_SETTERS(X) case X ## _SET_PURE_INT: case X ## _SET_PURE_UINT
533 
534 	switch (tester)
535 	{
536 		CASE_PURE_SETTERS(TESTER_TEXTURE_SRGB_DECODE_EXT):
537 		case TESTER_TEXTURE_SRGB_DECODE_EXT:
538 			return RequiredExtensions("GL_EXT_texture_sRGB_decode");
539 
540 		default:
541 			DE_ASSERT(false);
542 			return RequiredExtensions();
543 	}
544 
545 #undef CASE_PURE_SETTERS
546 }
547 
548 } // es32
549 
550 namespace gl45
551 {
552 
isCoreTextureTarget(glw::GLenum target)553 static bool isCoreTextureTarget (glw::GLenum target)
554 {
555 	return es31::isCoreTextureTarget(target);
556 }
557 
getTextureTargetExtension(glw::GLenum target)558 static RequiredExtensions getTextureTargetExtension (glw::GLenum target)
559 {
560 	DE_UNREF(target);
561 	return RequiredExtensions();
562 }
563 
isCoreTextureParam(glw::GLenum pname)564 static bool isCoreTextureParam (glw::GLenum pname)
565 {
566 	return es31::isCoreTextureParam(pname);
567 }
568 
getTextureParamExtension(glw::GLenum pname)569 static RequiredExtensions getTextureParamExtension (glw::GLenum pname)
570 {
571 	DE_UNREF(pname);
572 	return RequiredExtensions();
573 }
574 
isCoreQuery(QueryType query)575 static bool isCoreQuery (QueryType query)
576 {
577 	return es31::isCoreQuery(query);
578 }
579 
getQueryExtension(QueryType query)580 static RequiredExtensions getQueryExtension (QueryType query)
581 {
582 	DE_UNREF(query);
583 	return RequiredExtensions();
584 }
585 
isCoreTester(TesterType tester)586 static bool isCoreTester (TesterType tester)
587 {
588 	return es31::isCoreTester(tester);
589 }
590 
getTesterExtension(TesterType tester)591 static RequiredExtensions getTesterExtension (TesterType tester)
592 {
593 	DE_UNREF(tester);
594 	return RequiredExtensions();
595 }
596 
597 } // gl45
598 
isCoreTextureTarget(const glu::ContextType & contextType,glw::GLenum target)599 static bool isCoreTextureTarget (const glu::ContextType& contextType, glw::GLenum target)
600 {
601 	if (contextSupports(contextType, glu::ApiType::core(4,5)))
602 		return gl45::isCoreTextureTarget(target);
603 	else if (contextSupports(contextType, glu::ApiType::es(3,2)))
604 		return es32::isCoreTextureTarget(target);
605 	else if (contextSupports(contextType, glu::ApiType::es(3,1)))
606 		return es31::isCoreTextureTarget(target);
607 	else if (contextSupports(contextType, glu::ApiType::es(3,0)))
608 		return es30::isCoreTextureTarget(target);
609 	else
610 	{
611 		DE_ASSERT(false);
612 		return DE_NULL;
613 	}
614 }
615 
isCoreTextureParam(const glu::ContextType & contextType,glw::GLenum pname)616 static bool isCoreTextureParam (const glu::ContextType& contextType, glw::GLenum pname)
617 {
618 	if (contextSupports(contextType, glu::ApiType::core(4,5)))
619 		return gl45::isCoreTextureParam(pname);
620 	else if (contextSupports(contextType, glu::ApiType::es(3,2)))
621 		return es32::isCoreTextureParam(pname);
622 	else if (contextSupports(contextType, glu::ApiType::es(3,1)))
623 		return es31::isCoreTextureParam(pname);
624 	else if (contextSupports(contextType, glu::ApiType::es(3,0)))
625 		return es30::isCoreTextureParam(pname);
626 	else
627 	{
628 		DE_ASSERT(false);
629 		return DE_NULL;
630 	}
631 }
632 
isCoreQuery(const glu::ContextType & contextType,QueryType query)633 static bool isCoreQuery (const glu::ContextType& contextType, QueryType query)
634 {
635 	if (contextSupports(contextType, glu::ApiType::core(4,5)))
636 		return gl45::isCoreQuery(query);
637 	else if (contextSupports(contextType, glu::ApiType::es(3,2)))
638 		return es32::isCoreQuery(query);
639 	else if (contextSupports(contextType, glu::ApiType::es(3,1)))
640 		return es31::isCoreQuery(query);
641 	else if (contextSupports(contextType, glu::ApiType::es(3,0)))
642 		return es30::isCoreQuery(query);
643 	else
644 	{
645 		DE_ASSERT(false);
646 		return DE_NULL;
647 	}
648 }
649 
isCoreTester(const glu::ContextType & contextType,TesterType tester)650 static bool isCoreTester (const glu::ContextType& contextType, TesterType tester)
651 {
652 	if (contextSupports(contextType, glu::ApiType::core(4,5)))
653 		return gl45::isCoreTester(tester);
654 	else if (contextSupports(contextType, glu::ApiType::es(3,2)))
655 		return es32::isCoreTester(tester);
656 	else if (contextSupports(contextType, glu::ApiType::es(3,1)))
657 		return es31::isCoreTester(tester);
658 	else if (contextSupports(contextType, glu::ApiType::es(3,0)))
659 		return es30::isCoreTester(tester);
660 	else
661 	{
662 		DE_ASSERT(false);
663 		return DE_NULL;
664 	}
665 }
666 
getTextureTargetExtension(const glu::ContextType & contextType,glw::GLenum target)667 static RequiredExtensions getTextureTargetExtension (const glu::ContextType& contextType, glw::GLenum target)
668 {
669 	DE_ASSERT(!isCoreTextureTarget(contextType, target));
670 
671 	if (contextSupports(contextType, glu::ApiType::core(4,5)))
672 		return gl45::getTextureTargetExtension(target);
673 	else if (contextSupports(contextType, glu::ApiType::es(3,2)))
674 		return es32::getTextureTargetExtension(target);
675 	else if (contextSupports(contextType, glu::ApiType::es(3,1)))
676 		return es31::getTextureTargetExtension(target);
677 	else if (contextSupports(contextType, glu::ApiType::es(3,0)))
678 		return es30::getTextureTargetExtension(target);
679 	else
680 	{
681 		DE_ASSERT(false);
682 		return RequiredExtensions();
683 	}
684 }
685 
getTextureParamExtension(const glu::ContextType & contextType,glw::GLenum pname)686 static RequiredExtensions getTextureParamExtension (const glu::ContextType& contextType, glw::GLenum pname)
687 {
688 	DE_ASSERT(!isCoreTextureParam(contextType, pname));
689 
690 	if (contextSupports(contextType, glu::ApiType::core(4,5)))
691 		return gl45::getTextureParamExtension(pname);
692 	else if (contextSupports(contextType, glu::ApiType::es(3,2)))
693 		return es32::getTextureParamExtension(pname);
694 	else if (contextSupports(contextType, glu::ApiType::es(3,1)))
695 		return es31::getTextureParamExtension(pname);
696 	else if (contextSupports(contextType, glu::ApiType::es(3,0)))
697 		return es30::getTextureParamExtension(pname);
698 	else
699 	{
700 		DE_ASSERT(false);
701 		return RequiredExtensions();
702 	}
703 }
704 
getQueryExtension(const glu::ContextType & contextType,QueryType query)705 static RequiredExtensions getQueryExtension (const glu::ContextType& contextType, QueryType query)
706 {
707 	DE_ASSERT(!isCoreQuery(contextType, query));
708 
709 	if (contextSupports(contextType, glu::ApiType::core(4,5)))
710 		return gl45::getQueryExtension(query);
711 	else if (contextSupports(contextType, glu::ApiType::es(3,2)))
712 		return es32::getQueryExtension(query);
713 	else if (contextSupports(contextType, glu::ApiType::es(3,1)))
714 		return es31::getQueryExtension(query);
715 	else if (contextSupports(contextType, glu::ApiType::es(3,0)))
716 		return es30::getQueryExtension(query);
717 	else
718 	{
719 		DE_ASSERT(false);
720 		return RequiredExtensions();
721 	}
722 }
723 
getTesterExtension(const glu::ContextType & contextType,TesterType tester)724 static RequiredExtensions getTesterExtension (const glu::ContextType& contextType, TesterType tester)
725 {
726 	DE_ASSERT(!isCoreTester(contextType, tester));
727 
728 	if (contextSupports(contextType, glu::ApiType::core(4,5)))
729 		return gl45::getTesterExtension(tester);
730 	else if (contextSupports(contextType, glu::ApiType::es(3,2)))
731 		return es32::getTesterExtension(tester);
732 	else if (contextSupports(contextType, glu::ApiType::es(3,1)))
733 		return es31::getTesterExtension(tester);
734 	else if (contextSupports(contextType, glu::ApiType::es(3,0)))
735 		return es30::getTesterExtension(tester);
736 	else
737 	{
738 		DE_ASSERT(false);
739 		return RequiredExtensions();
740 	}
741 }
742 
743 class TextureTest : public tcu::TestCase
744 {
745 public:
746 						TextureTest	(tcu::TestContext&			testCtx,
747 									 const glu::RenderContext&	renderCtx,
748 									 const char*				name,
749 									 const char*				desc,
750 									 glw::GLenum				target,
751 									 TesterType					tester,
752 									 QueryType					type);
753 
754 	void				init		(void);
755 	IterateResult		iterate		(void);
756 
757 	virtual void		test		(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const = 0;
758 
759 protected:
760 	const glu::RenderContext&	m_renderCtx;
761 	const glw::GLenum			m_target;
762 	const glw::GLenum			m_pname;
763 	const TesterType			m_tester;
764 	const QueryType				m_type;
765 };
766 
TextureTest(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,TesterType tester,QueryType type)767 TextureTest::TextureTest (tcu::TestContext&			testCtx,
768 						  const glu::RenderContext&	renderCtx,
769 						  const char*				name,
770 						  const char*				desc,
771 						  glw::GLenum				target,
772 						  TesterType				tester,
773 						  QueryType					type)
774 	: TestCase		(testCtx, name, desc)
775 	, m_renderCtx	(renderCtx)
776 	, m_target		(target)
777 	, m_pname		(mapTesterToPname(tester))
778 	, m_tester		(tester)
779 	, m_type		(type)
780 {
781 }
782 
init(void)783 void TextureTest::init (void)
784 {
785 	const de::UniquePtr<glu::ContextInfo>	ctxInfo		(glu::ContextInfo::create(m_renderCtx));
786 	RequiredExtensions						extensions;
787 
788 	// target
789 	if (!isCoreTextureTarget(m_renderCtx.getType(), m_target))
790 		extensions.add(getTextureTargetExtension(m_renderCtx.getType(), m_target));
791 
792 	// param
793 	if (!isCoreTextureParam(m_renderCtx.getType(), m_pname))
794 		extensions.add(getTextureParamExtension(m_renderCtx.getType(), m_pname));
795 
796 	// query
797 	if (!isCoreQuery(m_renderCtx.getType(), m_type))
798 		extensions.add(getQueryExtension(m_renderCtx.getType(), m_type));
799 
800 	// test type
801 	if (!isCoreTester(m_renderCtx.getType(), m_tester))
802 		extensions.add(getTesterExtension(m_renderCtx.getType(), m_tester));
803 
804 	extensions.check(*ctxInfo);
805 }
806 
iterate(void)807 TextureTest::IterateResult TextureTest::iterate (void)
808 {
809 	glu::CallLogWrapper		gl		(m_renderCtx.getFunctions(), m_testCtx.getLog());
810 	tcu::ResultCollector	result	(m_testCtx.getLog(), " // ERROR: ");
811 
812 	gl.enableLogging(true);
813 	test(gl, result);
814 
815 	result.setTestContextResult(m_testCtx);
816 	return STOP;
817 }
818 
819 class IsTextureCase : public tcu::TestCase
820 {
821 public:
822 								IsTextureCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target);
823 
824 	void						init			(void);
825 	IterateResult				iterate			(void);
826 
827 protected:
828 	const glu::RenderContext&	m_renderCtx;
829 	const glw::GLenum			m_target;
830 };
831 
IsTextureCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target)832 IsTextureCase::IsTextureCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target)
833 	: tcu::TestCase	(testCtx, name, desc)
834 	, m_renderCtx	(renderCtx)
835 	, m_target		(target)
836 {
837 }
838 
init(void)839 void IsTextureCase::init (void)
840 {
841 	const de::UniquePtr<glu::ContextInfo>	ctxInfo		(glu::ContextInfo::create(m_renderCtx));
842 	RequiredExtensions						extensions;
843 
844 	// target
845 	if (!isCoreTextureTarget(m_renderCtx.getType(), m_target))
846 		extensions.add(getTextureTargetExtension(m_renderCtx.getType(), m_target));
847 
848 	extensions.check(*ctxInfo);
849 }
850 
iterate(void)851 IsTextureCase::IterateResult IsTextureCase::iterate (void)
852 {
853 	glu::CallLogWrapper		gl			(m_renderCtx.getFunctions(), m_testCtx.getLog());
854 	tcu::ResultCollector	result		(m_testCtx.getLog(), " // ERROR: ");
855 	glw::GLuint				textureId	= 0;
856 
857 	gl.enableLogging(true);
858 
859 	gl.glGenTextures(1, &textureId);
860 	gl.glBindTexture(m_target, textureId);
861 	GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glBindTexture");
862 
863 	verifyStateObjectBoolean(result, gl, textureId, true, QUERY_ISTEXTURE);
864 
865 	gl.glDeleteTextures(1, &textureId);
866 	GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glDeleteTextures");
867 
868 	verifyStateObjectBoolean(result, gl, textureId, false, QUERY_ISTEXTURE);
869 
870 	result.setTestContextResult(m_testCtx);
871 	return STOP;
872 }
873 
874 class DepthStencilModeCase : public TextureTest
875 {
876 public:
877 			DepthStencilModeCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type);
878 	void	test					(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
879 };
880 
DepthStencilModeCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,TesterType tester,QueryType type)881 DepthStencilModeCase::DepthStencilModeCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type)
882 	: TextureTest(testCtx, renderCtx, name, desc, target, tester, type)
883 {
884 }
885 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const886 void DepthStencilModeCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
887 {
888 	const bool		isPureCase	= isPureIntTester(m_tester) || isPureUintTester(m_tester);
889 	glu::Texture	texture		(m_renderCtx);
890 
891 	gl.glBindTexture(m_target, *texture);
892 	GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "bind");
893 
894 	if (!isPureCase)
895 	{
896 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
897 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_DEPTH_COMPONENT, m_type);
898 	}
899 
900 	if (!isPureCase)
901 	{
902 		const tcu::ScopedLogSection	section				(m_testCtx.getLog(), "Toggle", "Toggle");
903 		const glw::GLint			depthComponentInt	= GL_DEPTH_COMPONENT;
904 		const glw::GLfloat			depthComponentFloat	= (glw::GLfloat)GL_DEPTH_COMPONENT;
905 
906 		gl.glTexParameteri(m_target, m_pname, GL_STENCIL_INDEX);
907 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "set state");
908 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_STENCIL_INDEX, m_type);
909 
910 		gl.glTexParameteriv(m_target, m_pname, &depthComponentInt);
911 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "set state");
912 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_DEPTH_COMPONENT, m_type);
913 
914 		gl.glTexParameterf(m_target, m_pname, GL_STENCIL_INDEX);
915 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "set state");
916 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_STENCIL_INDEX, m_type);
917 
918 		gl.glTexParameterfv(m_target, m_pname, &depthComponentFloat);
919 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "set state");
920 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_DEPTH_COMPONENT, m_type);
921 	}
922 
923 	if (isPureIntTester(m_tester))
924 	{
925 		const glw::GLint depthComponent	= GL_DEPTH_COMPONENT;
926 		const glw::GLint stencilIndex	= GL_STENCIL_INDEX;
927 
928 		gl.glTexParameterIiv(m_target, m_pname, &stencilIndex);
929 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIiv");
930 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_STENCIL_INDEX, m_type);
931 
932 		gl.glTexParameterIiv(m_target, m_pname, &depthComponent);
933 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIiv");
934 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_DEPTH_COMPONENT, m_type);
935 	}
936 
937 	if (isPureUintTester(m_tester))
938 	{
939 		const glw::GLuint depthComponent	= GL_DEPTH_COMPONENT;
940 		const glw::GLuint stencilIndex	= GL_STENCIL_INDEX;
941 
942 		gl.glTexParameterIuiv(m_target, m_pname, &stencilIndex);
943 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIuiv");
944 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_STENCIL_INDEX, m_type);
945 
946 		gl.glTexParameterIuiv(m_target, m_pname, &depthComponent);
947 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIuiv");
948 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_DEPTH_COMPONENT, m_type);
949 	}
950 }
951 
952 class TextureSRGBDecodeCase : public TextureTest
953 {
954 public:
955 			TextureSRGBDecodeCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type);
956 	void	test					(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
957 };
958 
TextureSRGBDecodeCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,TesterType tester,QueryType type)959 TextureSRGBDecodeCase::TextureSRGBDecodeCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type)
960 	: TextureTest(testCtx, renderCtx, name, desc, target, tester, type)
961 {
962 }
963 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const964 void TextureSRGBDecodeCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
965 {
966 	const bool		isPureCase	= isPureIntTester(m_tester) || isPureUintTester(m_tester);
967 	glu::Texture	texture		(m_renderCtx);
968 
969 	gl.glBindTexture(m_target, *texture);
970 	GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "bind");
971 
972 	if (!isPureCase)
973 	{
974 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
975 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_DECODE_EXT, m_type);
976 	}
977 
978 	if (!isPureCase)
979 	{
980 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Toggle", "Toggle");
981 		const glw::GLint			decodeInt		= GL_DECODE_EXT;
982 		const glw::GLfloat			decodeFloat		= (glw::GLfloat)GL_DECODE_EXT;
983 
984 		gl.glTexParameteri(m_target, m_pname, GL_SKIP_DECODE_EXT);
985 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "set state");
986 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_SKIP_DECODE_EXT, m_type);
987 
988 		gl.glTexParameteriv(m_target, m_pname, &decodeInt);
989 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "set state");
990 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_DECODE_EXT, m_type);
991 
992 		gl.glTexParameterf(m_target, m_pname, GL_SKIP_DECODE_EXT);
993 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "set state");
994 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_SKIP_DECODE_EXT, m_type);
995 
996 		gl.glTexParameterfv(m_target, m_pname, &decodeFloat);
997 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "set state");
998 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_DECODE_EXT, m_type);
999 	}
1000 
1001 	if (isPureIntTester(m_tester))
1002 	{
1003 		const glw::GLint skipDecode	= GL_SKIP_DECODE_EXT;
1004 		const glw::GLint decode		= GL_DECODE_EXT;
1005 
1006 		gl.glTexParameterIiv(m_target, m_pname, &skipDecode);
1007 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIiv");
1008 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_SKIP_DECODE_EXT, m_type);
1009 
1010 		gl.glTexParameterIiv(m_target, m_pname, &decode);
1011 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIiv");
1012 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_DECODE_EXT, m_type);
1013 	}
1014 
1015 	if (isPureUintTester(m_tester))
1016 	{
1017 		const glw::GLuint skipDecode	= GL_SKIP_DECODE_EXT;
1018 		const glw::GLuint decode		= GL_DECODE_EXT;
1019 
1020 		gl.glTexParameterIuiv(m_target, m_pname, &skipDecode);
1021 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIuiv");
1022 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_SKIP_DECODE_EXT, m_type);
1023 
1024 		gl.glTexParameterIuiv(m_target, m_pname, &decode);
1025 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIuiv");
1026 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_DECODE_EXT, m_type);
1027 	}
1028 }
1029 
1030 class TextureSwizzleCase : public TextureTest
1031 {
1032 public:
1033 			TextureSwizzleCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type);
1034 	void	test				(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
1035 };
1036 
TextureSwizzleCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,TesterType tester,QueryType type)1037 TextureSwizzleCase::TextureSwizzleCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type)
1038 	: TextureTest(testCtx, renderCtx, name, desc, target, tester, type)
1039 {
1040 }
1041 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const1042 void TextureSwizzleCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
1043 {
1044 	const bool	isPureCase		= isPureIntTester(m_tester) || isPureUintTester(m_tester);
1045 	const int	initialValue	= (m_pname == GL_TEXTURE_SWIZZLE_R) ? (GL_RED) :
1046 								  (m_pname == GL_TEXTURE_SWIZZLE_G) ? (GL_GREEN) :
1047 								  (m_pname == GL_TEXTURE_SWIZZLE_B) ? (GL_BLUE) :
1048 								  (m_pname == GL_TEXTURE_SWIZZLE_A) ? (GL_ALPHA) :
1049 								  (-1);
1050 
1051 	if (!isPureCase)
1052 	{
1053 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
1054 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, initialValue, m_type);
1055 	}
1056 
1057 	{
1058 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
1059 		const GLenum				swizzleValues[]	= {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA, GL_ZERO, GL_ONE};
1060 
1061 		if (isPureCase)
1062 		{
1063 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(swizzleValues); ++ndx)
1064 			{
1065 				if (isPureIntTester(m_tester))
1066 				{
1067 					const glw::GLint value = (glw::GLint)swizzleValues[ndx];
1068 					gl.glTexParameterIiv(m_target, m_pname, &value);
1069 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIiv");
1070 				}
1071 				else
1072 				{
1073 					DE_ASSERT(isPureUintTester(m_tester));
1074 
1075 					const glw::GLuint value = swizzleValues[ndx];
1076 					gl.glTexParameterIuiv(m_target, m_pname, &value);
1077 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIuiv");
1078 				}
1079 
1080 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, swizzleValues[ndx], m_type);
1081 			}
1082 		}
1083 		else
1084 		{
1085 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(swizzleValues); ++ndx)
1086 			{
1087 				gl.glTexParameteri(m_target, m_pname, swizzleValues[ndx]);
1088 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameteri");
1089 
1090 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, swizzleValues[ndx], m_type);
1091 			}
1092 
1093 			//check unit conversions with float
1094 
1095 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(swizzleValues); ++ndx)
1096 			{
1097 				gl.glTexParameterf(m_target, m_pname, (GLfloat)swizzleValues[ndx]);
1098 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterf");
1099 
1100 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, swizzleValues[ndx], m_type);
1101 			}
1102 		}
1103 	}
1104 }
1105 
1106 class TextureWrapCase : public TextureTest
1107 {
1108 public:
1109 			TextureWrapCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type);
1110 	void	test			(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
1111 };
1112 
TextureWrapCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,TesterType tester,QueryType type)1113 TextureWrapCase::TextureWrapCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type)
1114 	: TextureTest(testCtx, renderCtx, name, desc, target, tester, type)
1115 {
1116 }
1117 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const1118 void TextureWrapCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
1119 {
1120 	const bool isPureCase = isPureIntTester(m_tester) || isPureUintTester(m_tester);
1121 
1122 	if (!isPureCase)
1123 	{
1124 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
1125 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_REPEAT, m_type);
1126 	}
1127 
1128 	{
1129 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
1130 		const GLenum				wrapValues[]	= {GL_CLAMP_TO_EDGE, GL_REPEAT, GL_MIRRORED_REPEAT};
1131 
1132 		if (isPureCase)
1133 		{
1134 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(wrapValues); ++ndx)
1135 			{
1136 				if (isPureIntTester(m_tester))
1137 				{
1138 					const glw::GLint value = (glw::GLint)wrapValues[ndx];
1139 					gl.glTexParameterIiv(m_target, m_pname, &value);
1140 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIiv");
1141 				}
1142 				else
1143 				{
1144 					DE_ASSERT(isPureUintTester(m_tester));
1145 
1146 					const glw::GLuint value = wrapValues[ndx];
1147 					gl.glTexParameterIuiv(m_target, m_pname, &value);
1148 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIuiv");
1149 				}
1150 
1151 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, wrapValues[ndx], m_type);
1152 			}
1153 		}
1154 		else
1155 		{
1156 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(wrapValues); ++ndx)
1157 			{
1158 				gl.glTexParameteri(m_target, m_pname, wrapValues[ndx]);
1159 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameteri");
1160 
1161 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, wrapValues[ndx], m_type);
1162 			}
1163 
1164 			//check unit conversions with float
1165 
1166 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(wrapValues); ++ndx)
1167 			{
1168 				gl.glTexParameterf(m_target, m_pname, (GLfloat)wrapValues[ndx]);
1169 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterf");
1170 
1171 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, wrapValues[ndx], m_type);
1172 			}
1173 		}
1174 	}
1175 }
1176 
1177 class TextureFilterCase : public TextureTest
1178 {
1179 public:
1180 			TextureFilterCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type);
1181 	void	test				(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
1182 };
1183 
TextureFilterCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,TesterType tester,QueryType type)1184 TextureFilterCase::TextureFilterCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type)
1185 	: TextureTest(testCtx, renderCtx, name, desc, target, tester, type)
1186 {
1187 }
1188 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const1189 void TextureFilterCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
1190 {
1191 	const bool			isPureCase	= isPureIntTester(m_tester) || isPureUintTester(m_tester);
1192 	const glw::GLenum	initial		= (m_pname == GL_TEXTURE_MAG_FILTER) ? (GL_LINEAR)
1193 									: (m_pname == GL_TEXTURE_MIN_FILTER) ? (GL_NEAREST_MIPMAP_LINEAR)
1194 									: (0);
1195 
1196 	if (!isPureCase)
1197 	{
1198 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
1199 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, initial, m_type);
1200 	}
1201 
1202 	{
1203 		const tcu::ScopedLogSection	section		(m_testCtx.getLog(), "Set", "Set");
1204 		std::vector<GLenum>			values;
1205 
1206 		values.push_back(GL_NEAREST);
1207 		values.push_back(GL_LINEAR);
1208 		if (m_pname == GL_TEXTURE_MIN_FILTER)
1209 		{
1210 			values.push_back(GL_NEAREST_MIPMAP_NEAREST);
1211 			values.push_back(GL_NEAREST_MIPMAP_LINEAR);
1212 			values.push_back(GL_LINEAR_MIPMAP_NEAREST);
1213 			values.push_back(GL_LINEAR_MIPMAP_LINEAR);
1214 		}
1215 
1216 		if (isPureCase)
1217 		{
1218 			for (int ndx = 0; ndx < (int)values.size(); ++ndx)
1219 			{
1220 				if (isPureIntTester(m_tester))
1221 				{
1222 					const glw::GLint value = (glw::GLint)values[ndx];
1223 					gl.glTexParameterIiv(m_target, m_pname, &value);
1224 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIiv");
1225 				}
1226 				else
1227 				{
1228 					DE_ASSERT(isPureUintTester(m_tester));
1229 
1230 					const glw::GLuint value = values[ndx];
1231 					gl.glTexParameterIuiv(m_target, m_pname, &value);
1232 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIuiv");
1233 				}
1234 
1235 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, values[ndx], m_type);
1236 			}
1237 		}
1238 		else
1239 		{
1240 			for (int ndx = 0; ndx < (int)values.size(); ++ndx)
1241 			{
1242 				gl.glTexParameteri(m_target, m_pname, values[ndx]);
1243 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameteri");
1244 
1245 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, values[ndx], m_type);
1246 			}
1247 
1248 			//check unit conversions with float
1249 
1250 			for (int ndx = 0; ndx < (int)values.size(); ++ndx)
1251 			{
1252 				gl.glTexParameterf(m_target, m_pname, (GLfloat)values[ndx]);
1253 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterf");
1254 
1255 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, values[ndx], m_type);
1256 			}
1257 		}
1258 	}
1259 }
1260 
1261 class TextureLODCase : public TextureTest
1262 {
1263 public:
1264 			TextureLODCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type);
1265 	void	test			(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
1266 };
1267 
TextureLODCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,TesterType tester,QueryType type)1268 TextureLODCase::TextureLODCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type)
1269 	: TextureTest(testCtx, renderCtx, name, desc, target, tester, type)
1270 {
1271 }
1272 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const1273 void TextureLODCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
1274 {
1275 	const bool	isPureCase		= isPureIntTester(m_tester) || isPureUintTester(m_tester);
1276 	const int	initialValue	= (m_pname == GL_TEXTURE_MIN_LOD) ? (-1000)
1277 								: (m_pname == GL_TEXTURE_MAX_LOD) ? (1000)
1278 								: (-1);
1279 
1280 	if ((querySupportsSigned(m_type) || initialValue >= 0) && !isPureCase)
1281 	{
1282 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
1283 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, initialValue, m_type);
1284 	}
1285 
1286 	{
1287 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
1288 		const int					numIterations	= 20;
1289 		de::Random					rnd				(0xabcdef);
1290 
1291 		if (isPureCase)
1292 		{
1293 			if (isPureIntTester(m_tester))
1294 			{
1295 				for (int ndx = 0; ndx < numIterations; ++ndx)
1296 				{
1297 					const GLint ref = rnd.getInt(-1000, 1000);
1298 
1299 					gl.glTexParameterIiv(m_target, m_pname, &ref);
1300 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIiv");
1301 
1302 					verifyStateTextureParamFloat(result, gl, m_target, m_pname, (float)ref, m_type);
1303 				}
1304 			}
1305 			else
1306 			{
1307 				DE_ASSERT(isPureUintTester(m_tester));
1308 
1309 				for (int ndx = 0; ndx < numIterations; ++ndx)
1310 				{
1311 					const GLuint ref = (glw::GLuint)rnd.getInt(0, 1000);
1312 
1313 					gl.glTexParameterIuiv(m_target, m_pname, &ref);
1314 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIuiv");
1315 
1316 					verifyStateTextureParamFloat(result, gl, m_target, m_pname, (float)ref, m_type);
1317 				}
1318 			}
1319 		}
1320 		else
1321 		{
1322 			const int minLimit = (querySupportsSigned(m_type)) ? (-1000) : (0);
1323 
1324 			for (int ndx = 0; ndx < numIterations; ++ndx)
1325 			{
1326 				const GLfloat ref = rnd.getFloat((float)minLimit, 1000.f);
1327 
1328 				gl.glTexParameterf(m_target, m_pname, ref);
1329 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterf");
1330 
1331 				verifyStateTextureParamFloat(result, gl, m_target, m_pname, ref, m_type);
1332 			}
1333 
1334 			// check unit conversions with int
1335 
1336 			for (int ndx = 0; ndx < numIterations; ++ndx)
1337 			{
1338 				const GLint ref = rnd.getInt(minLimit, 1000);
1339 
1340 				gl.glTexParameteri(m_target, m_pname, ref);
1341 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameteri");
1342 
1343 				verifyStateTextureParamFloat(result, gl, m_target, m_pname, (float)ref, m_type);
1344 			}
1345 		}
1346 	}
1347 }
1348 
1349 class TextureLevelCase : public TextureTest
1350 {
1351 public:
1352 			TextureLevelCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type);
1353 	void	test				(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
1354 };
1355 
TextureLevelCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,TesterType tester,QueryType type)1356 TextureLevelCase::TextureLevelCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type)
1357 	: TextureTest(testCtx, renderCtx, name, desc, target, tester, type)
1358 {
1359 }
1360 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const1361 void TextureLevelCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
1362 {
1363 	const bool	isPureCase		= isPureIntTester(m_tester) || isPureUintTester(m_tester);
1364 	const int	initialValue	= (m_pname == GL_TEXTURE_BASE_LEVEL) ? (0)
1365 								: (m_pname == GL_TEXTURE_MAX_LEVEL)	? (1000)
1366 								: (-1);
1367 
1368 	if (!isPureCase)
1369 	{
1370 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
1371 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, initialValue, m_type);
1372 	}
1373 
1374 	if (m_target == GL_TEXTURE_2D_MULTISAMPLE		||
1375 		m_target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)
1376 	{
1377 		// only 0 allowed
1378 		{
1379 			const tcu::ScopedLogSection section(m_testCtx.getLog(), "Set", "Set");
1380 
1381 			gl.glTexParameteri(m_target, m_pname, 0);
1382 			GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameteri");
1383 			verifyStateTextureParamInteger(result, gl, m_target, m_pname, 0, m_type);
1384 
1385 			gl.glTexParameterf(m_target, m_pname, 0.0f);
1386 			GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterf");
1387 			verifyStateTextureParamInteger(result, gl, m_target, m_pname, 0, m_type);
1388 		}
1389 	}
1390 	else
1391 	{
1392 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
1393 		const int					numIterations	= 20;
1394 		de::Random					rnd				(0xabcdef);
1395 
1396 		if (isPureCase)
1397 		{
1398 			for (int ndx = 0; ndx < numIterations; ++ndx)
1399 			{
1400 				const GLint		ref		= rnd.getInt(0, 64000);
1401 				const GLuint	uRef	= (glw::GLuint)ref;
1402 
1403 				if (isPureIntTester(m_tester))
1404 				{
1405 					gl.glTexParameterIiv(m_target, m_pname, &ref);
1406 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIiv");
1407 				}
1408 				else
1409 				{
1410 					DE_ASSERT(isPureUintTester(m_tester));
1411 					gl.glTexParameterIuiv(m_target, m_pname, &uRef);
1412 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIuiv");
1413 				}
1414 
1415 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, ref, m_type);
1416 			}
1417 		}
1418 		else
1419 		{
1420 			for (int ndx = 0; ndx < numIterations; ++ndx)
1421 			{
1422 				const GLint ref = rnd.getInt(0, 64000);
1423 
1424 				gl.glTexParameteri(m_target, m_pname, ref);
1425 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameteri");
1426 
1427 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, ref, m_type);
1428 			}
1429 
1430 			// check unit conversions with float
1431 
1432 			const float nonSignificantOffsets[] = {-0.45f, -0.25f, 0, 0.45f}; // offsets O so that for any integers z in Z, o in O roundToClosestInt(z+o)==z
1433 
1434 			const int numConversionIterations = 30;
1435 			for (int ndx = 0; ndx < numConversionIterations; ++ndx)
1436 			{
1437 				const GLint ref = rnd.getInt(1, 64000);
1438 
1439 				for (int offsetNdx = 0; offsetNdx < DE_LENGTH_OF_ARRAY(nonSignificantOffsets); ++offsetNdx)
1440 				{
1441 					gl.glTexParameterf(m_target, m_pname, ((GLfloat)ref) + nonSignificantOffsets[offsetNdx]);
1442 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterf");
1443 
1444 					verifyStateTextureParamInteger(result, gl, m_target, m_pname, ref, m_type);
1445 				}
1446 			}
1447 		}
1448 	}
1449 }
1450 
1451 class TextureCompareModeCase : public TextureTest
1452 {
1453 public:
1454 			TextureCompareModeCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type);
1455 	void	test					(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
1456 };
1457 
TextureCompareModeCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,TesterType tester,QueryType type)1458 TextureCompareModeCase::TextureCompareModeCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type)
1459 	: TextureTest(testCtx, renderCtx, name, desc, target, tester, type)
1460 {
1461 }
1462 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const1463 void TextureCompareModeCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
1464 {
1465 	const bool isPureCase = isPureIntTester(m_tester) || isPureUintTester(m_tester);
1466 
1467 	if (!isPureCase)
1468 	{
1469 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
1470 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_NONE, m_type);
1471 	}
1472 
1473 	{
1474 		const tcu::ScopedLogSection	section		(m_testCtx.getLog(), "Set", "Set");
1475 		const GLenum				modes[]		= {GL_COMPARE_REF_TO_TEXTURE, GL_NONE};
1476 
1477 		if (isPureCase)
1478 		{
1479 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(modes); ++ndx)
1480 			{
1481 				if (isPureIntTester(m_tester))
1482 				{
1483 					const glw::GLint value = (glw::GLint)modes[ndx];
1484 					gl.glTexParameterIiv(m_target, m_pname, &value);
1485 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIiv");
1486 				}
1487 				else
1488 				{
1489 					DE_ASSERT(isPureUintTester(m_tester));
1490 
1491 					const glw::GLuint value = modes[ndx];
1492 					gl.glTexParameterIuiv(m_target, m_pname, &value);
1493 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIuiv");
1494 				}
1495 
1496 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, modes[ndx], m_type);
1497 			}
1498 		}
1499 		else
1500 		{
1501 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(modes); ++ndx)
1502 			{
1503 				gl.glTexParameteri(m_target, m_pname, modes[ndx]);
1504 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameteri");
1505 
1506 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, modes[ndx], m_type);
1507 			}
1508 
1509 			//check unit conversions with float
1510 
1511 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(modes); ++ndx)
1512 			{
1513 				gl.glTexParameterf(m_target, m_pname, (GLfloat)modes[ndx]);
1514 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterf");
1515 
1516 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, modes[ndx], m_type);
1517 			}
1518 		}
1519 	}
1520 }
1521 
1522 class TextureCompareFuncCase : public TextureTest
1523 {
1524 public:
1525 			TextureCompareFuncCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type);
1526 	void	test					(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
1527 };
1528 
TextureCompareFuncCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,TesterType tester,QueryType type)1529 TextureCompareFuncCase::TextureCompareFuncCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type)
1530 	: TextureTest(testCtx, renderCtx, name, desc, target, tester, type)
1531 {
1532 }
1533 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const1534 void TextureCompareFuncCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
1535 {
1536 	const bool isPureCase = isPureIntTester(m_tester) || isPureUintTester(m_tester);
1537 
1538 	if (!isPureCase)
1539 	{
1540 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
1541 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_LEQUAL, m_type);
1542 	}
1543 
1544 	{
1545 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
1546 		const GLenum				compareFuncs[]	= {GL_LEQUAL, GL_GEQUAL, GL_LESS, GL_GREATER, GL_EQUAL, GL_NOTEQUAL, GL_ALWAYS, GL_NEVER};
1547 
1548 		if (isPureCase)
1549 		{
1550 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(compareFuncs); ++ndx)
1551 			{
1552 				if (isPureIntTester(m_tester))
1553 				{
1554 					const glw::GLint value = (glw::GLint)compareFuncs[ndx];
1555 					gl.glTexParameterIiv(m_target, m_pname, &value);
1556 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIiv");
1557 				}
1558 				else
1559 				{
1560 					DE_ASSERT(isPureUintTester(m_tester));
1561 
1562 					const glw::GLuint value = compareFuncs[ndx];
1563 					gl.glTexParameterIuiv(m_target, m_pname, &value);
1564 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIuiv");
1565 				}
1566 
1567 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, compareFuncs[ndx], m_type);
1568 			}
1569 		}
1570 		else
1571 		{
1572 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(compareFuncs); ++ndx)
1573 			{
1574 				gl.glTexParameteri(m_target, m_pname, compareFuncs[ndx]);
1575 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameteri");
1576 
1577 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, compareFuncs[ndx], m_type);
1578 			}
1579 
1580 			//check unit conversions with float
1581 
1582 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(compareFuncs); ++ndx)
1583 			{
1584 				gl.glTexParameterf(m_target, m_pname, (GLfloat)compareFuncs[ndx]);
1585 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterf");
1586 
1587 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, compareFuncs[ndx], m_type);
1588 			}
1589 		}
1590 	}
1591 }
1592 
1593 class TextureImmutableLevelsCase : public TextureTest
1594 {
1595 public:
1596 			TextureImmutableLevelsCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, QueryType type);
1597 	void	test						(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
1598 };
1599 
TextureImmutableLevelsCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,QueryType type)1600 TextureImmutableLevelsCase::TextureImmutableLevelsCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, QueryType type)
1601 	: TextureTest(testCtx, renderCtx, name, desc, target, TESTER_TEXTURE_IMMUTABLE_LEVELS, type)
1602 {
1603 }
1604 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const1605 void TextureImmutableLevelsCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
1606 {
1607 	{
1608 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
1609 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, 0, m_type);
1610 	}
1611 
1612 	if (m_target == GL_TEXTURE_2D_MULTISAMPLE		||
1613 		m_target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)
1614 	{
1615 		// no levels
1616 		const tcu::ScopedLogSection	section		(m_testCtx.getLog(), "Level", "Level");
1617 		GLuint						textureID	= 0;
1618 
1619 		gl.glGenTextures(1, &textureID);
1620 		gl.glBindTexture(m_target, textureID);
1621 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glBindTexture");
1622 
1623 		if (m_target == GL_TEXTURE_2D_MULTISAMPLE)
1624 			gl.glTexStorage2DMultisample(m_target, 2, GL_RGB8, 64, 64, GL_FALSE);
1625 		else if (m_target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)
1626 			gl.glTexStorage3DMultisample(m_target, 2, GL_RGB8, 64, 64, 2, GL_FALSE);
1627 		else
1628 			DE_ASSERT(false);
1629 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexStorage");
1630 
1631 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, 1, m_type);
1632 
1633 		gl.glDeleteTextures(1, &textureID);
1634 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glDeleteTextures");
1635 	}
1636 	else
1637 	{
1638 		for (int level = 1; level <= 7; ++level)
1639 		{
1640 			const tcu::ScopedLogSection	section		(m_testCtx.getLog(), "Levels", "Levels = " + de::toString(level));
1641 			GLuint						textureID	= 0;
1642 
1643 			gl.glGenTextures(1, &textureID);
1644 			gl.glBindTexture(m_target, textureID);
1645 			GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glBindTexture");
1646 
1647 			if (m_target == GL_TEXTURE_2D || m_target == GL_TEXTURE_CUBE_MAP)
1648 				gl.glTexStorage2D(m_target, level, GL_RGB8, 64, 64);
1649 			else if (m_target == GL_TEXTURE_2D_ARRAY || m_target == GL_TEXTURE_3D)
1650 				gl.glTexStorage3D(m_target, level, GL_RGB8, 64, 64, 64);
1651 			else if (m_target == GL_TEXTURE_CUBE_MAP_ARRAY)
1652 				gl.glTexStorage3D(m_target, level, GL_RGB8, 64, 64, 6 * 2);
1653 			else
1654 				DE_ASSERT(false);
1655 			GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexStorage");
1656 
1657 			verifyStateTextureParamInteger(result, gl, m_target, m_pname, level, m_type);
1658 
1659 			gl.glDeleteTextures(1, &textureID);
1660 			GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glDeleteTextures");
1661 		}
1662 	}
1663 }
1664 
1665 class TextureImmutableFormatCase : public TextureTest
1666 {
1667 public:
1668 			TextureImmutableFormatCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, QueryType type);
1669 	void	test						(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
1670 };
1671 
TextureImmutableFormatCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,QueryType type)1672 TextureImmutableFormatCase::TextureImmutableFormatCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, QueryType type)
1673 	: TextureTest(testCtx, renderCtx, name, desc, target, TESTER_TEXTURE_IMMUTABLE_FORMAT, type)
1674 {
1675 }
1676 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const1677 void TextureImmutableFormatCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
1678 {
1679 	{
1680 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
1681 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, 0, m_type);
1682 	}
1683 
1684 	{
1685 		const tcu::ScopedLogSection	subsection	(m_testCtx.getLog(), "Immutable", "Immutable");
1686 		GLuint						textureID	= 0;
1687 
1688 		gl.glGenTextures(1, &textureID);
1689 		gl.glBindTexture(m_target, textureID);
1690 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glBindTexture");
1691 
1692 		switch (m_target)
1693 		{
1694 			case GL_TEXTURE_2D:
1695 			case GL_TEXTURE_CUBE_MAP:
1696 			{
1697 				gl.glTexStorage2D(m_target, 1, GL_RGBA8, 32, 32);
1698 				break;
1699 			}
1700 			case GL_TEXTURE_2D_ARRAY:
1701 			case GL_TEXTURE_3D:
1702 			{
1703 				gl.glTexStorage3D(m_target, 1, GL_RGBA8, 32, 32, 8);
1704 				break;
1705 			}
1706 			case GL_TEXTURE_2D_MULTISAMPLE:
1707 			{
1708 				gl.glTexStorage2DMultisample(m_target, 2, GL_RGB8, 64, 64, GL_FALSE);
1709 				break;
1710 			}
1711 			case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
1712 			{
1713 				gl.glTexStorage3DMultisample(m_target, 2, GL_RGB8, 64, 64, 2, GL_FALSE);
1714 				break;
1715 			}
1716 			case GL_TEXTURE_CUBE_MAP_ARRAY:
1717 			{
1718 				gl.glTexStorage3D(m_target, 1, GL_RGBA8, 32, 32, 6 * 2);
1719 				break;
1720 			}
1721 			default:
1722 				DE_ASSERT(false);
1723 		}
1724 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "setup texture");
1725 
1726 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, 1, m_type);
1727 
1728 		gl.glDeleteTextures(1, &textureID);
1729 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glDeleteTextures");
1730 	}
1731 
1732 	// no mutable
1733 	if (m_target == GL_TEXTURE_2D_MULTISAMPLE ||
1734 		m_target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)
1735 		return;
1736 
1737 	// test mutable
1738 	{
1739 		const tcu::ScopedLogSection	subsection		(m_testCtx.getLog(), "Mutable", "Mutable");
1740 		GLuint						textureID		= 0;
1741 
1742 		gl.glGenTextures(1, &textureID);
1743 		gl.glBindTexture(m_target, textureID);
1744 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glBindTexture");
1745 
1746 		switch (m_target)
1747 		{
1748 			case GL_TEXTURE_2D:
1749 			{
1750 				gl.glTexImage2D(m_target, 0, GL_RGBA8, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
1751 				break;
1752 			}
1753 			case GL_TEXTURE_CUBE_MAP:
1754 			{
1755 				gl.glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA8, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
1756 				break;
1757 			}
1758 			case GL_TEXTURE_2D_ARRAY:
1759 			case GL_TEXTURE_3D:
1760 			{
1761 				gl.glTexImage3D(m_target, 0, GL_RGBA8, 32, 32, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
1762 				break;
1763 			}
1764 			case GL_TEXTURE_CUBE_MAP_ARRAY:
1765 			{
1766 				gl.glTexImage3D(m_target, 0, GL_RGBA8, 32, 32, 6 * 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
1767 				break;
1768 			}
1769 			default:
1770 				DE_ASSERT(false);
1771 		}
1772 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "setup texture");
1773 
1774 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, 0, m_type);
1775 
1776 		gl.glDeleteTextures(1, &textureID);
1777 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glDeleteTextures");
1778 	}
1779 }
1780 
1781 class TextureWrapClampToBorderCase : public TextureTest
1782 {
1783 public:
1784 			TextureWrapClampToBorderCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type);
1785 	void	test							(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
1786 };
1787 
TextureWrapClampToBorderCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,TesterType tester,QueryType type)1788 TextureWrapClampToBorderCase::TextureWrapClampToBorderCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type)
1789 	: TextureTest(testCtx, renderCtx, name, desc, target, tester, type)
1790 {
1791 }
1792 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const1793 void TextureWrapClampToBorderCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
1794 {
1795 	gl.glTexParameteri(m_target, m_pname, GL_CLAMP_TO_BORDER_EXT);
1796 	GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameteri");
1797 	verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_CLAMP_TO_BORDER_EXT, m_type);
1798 
1799 	gl.glTexParameteri(m_target, m_pname, GL_REPEAT);
1800 	GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameteri");
1801 
1802 	gl.glTexParameterf(m_target, m_pname, (GLfloat)GL_CLAMP_TO_BORDER_EXT);
1803 	GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterf");
1804 
1805 	verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_CLAMP_TO_BORDER_EXT, m_type);
1806 }
1807 
1808 class TextureBorderColorCase : public TextureTest
1809 {
1810 public:
1811 			TextureBorderColorCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, QueryType type);
1812 	void	test					(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
1813 };
1814 
TextureBorderColorCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,QueryType type)1815 TextureBorderColorCase::TextureBorderColorCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, QueryType type)
1816 	: TextureTest(testCtx, renderCtx, name, desc, target, TESTER_TEXTURE_BORDER_COLOR, type)
1817 {
1818 }
1819 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const1820 void TextureBorderColorCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
1821 {
1822 	// border color is undefined if queried with pure type and was not set to pure value
1823 	if (m_type == QUERY_TEXTURE_PARAM_INTEGER_VEC4 || m_type == QUERY_TEXTURE_PARAM_FLOAT_VEC4)
1824 	{
1825 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
1826 		verifyStateTextureParamFloatVec4(result, gl, m_target, m_pname, tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), m_type);
1827 	}
1828 
1829 	if (m_type == QUERY_TEXTURE_PARAM_PURE_INTEGER_VEC4)
1830 	{
1831 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
1832 		const tcu::IVec4			color			(0x7FFFFFFF, -2, 3, -128);
1833 
1834 		gl.glTexParameterIiv(m_target, m_pname, color.getPtr());
1835 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIiv");
1836 
1837 		verifyStateTextureParamIntegerVec4(result, gl, m_target, m_pname, color, m_type);
1838 	}
1839 	else if (m_type == QUERY_TEXTURE_PARAM_PURE_UNSIGNED_INTEGER_VEC4)
1840 	{
1841 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
1842 		const tcu::UVec4			color			(0x8000000ul, 2, 3, 128);
1843 
1844 		gl.glTexParameterIuiv(m_target, m_pname, color.getPtr());
1845 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIuiv");
1846 
1847 		verifyStateTextureParamUnsignedIntegerVec4(result, gl, m_target, m_pname, color, m_type);
1848 	}
1849 	else
1850 	{
1851 		DE_ASSERT(m_type == QUERY_TEXTURE_PARAM_INTEGER_VEC4 || m_type == QUERY_TEXTURE_PARAM_FLOAT_VEC4);
1852 
1853 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
1854 		const tcu::Vec4				color			(0.25f, 1.0f, 0.0f, 0.77f);
1855 		const tcu::IVec4			icolor			(0x8000000ul, 0x7FFFFFFF, 0, 0x0FFFFFFF);
1856 
1857 		gl.glTexParameterfv(m_target, m_pname, color.getPtr());
1858 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterfv");
1859 
1860 		verifyStateTextureParamFloatVec4(result, gl, m_target, m_pname, color, m_type);
1861 
1862 		gl.glTexParameteriv(m_target, m_pname, icolor.getPtr());
1863 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameteriv");
1864 
1865 		verifyStateTextureParamNormalizedI32Vec4(result, gl, m_target, m_pname, icolor, m_type);
1866 	}
1867 }
1868 
1869 class SamplerTest : public tcu::TestCase
1870 {
1871 public:
1872 						SamplerTest	(tcu::TestContext&			testCtx,
1873 									 const glu::RenderContext&	renderCtx,
1874 									 const char*				name,
1875 									 const char*				desc,
1876 									 TesterType					tester,
1877 									 QueryType					type);
1878 
1879 	void				init		(void);
1880 	IterateResult		iterate		(void);
1881 
1882 	virtual void		test		(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const = 0;
1883 
1884 protected:
1885 	const glu::RenderContext&	m_renderCtx;
1886 	const glw::GLenum			m_pname;
1887 	const TesterType			m_tester;
1888 	const QueryType				m_type;
1889 	glw::GLuint					m_target;
1890 };
1891 
SamplerTest(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,TesterType tester,QueryType type)1892 SamplerTest::SamplerTest (tcu::TestContext&			testCtx,
1893 						  const glu::RenderContext&	renderCtx,
1894 						  const char*				name,
1895 						  const char*				desc,
1896 						  TesterType				tester,
1897 						  QueryType					type)
1898 	: TestCase		(testCtx, name, desc)
1899 	, m_renderCtx	(renderCtx)
1900 	, m_pname		(mapTesterToPname(tester))
1901 	, m_tester		(tester)
1902 	, m_type		(type)
1903 	, m_target		(0)
1904 {
1905 }
1906 
init(void)1907 void SamplerTest::init (void)
1908 {
1909 	const de::UniquePtr<glu::ContextInfo>	ctxInfo		(glu::ContextInfo::create(m_renderCtx));
1910 	RequiredExtensions						extensions;
1911 
1912 	// param
1913 	if (!isCoreTextureParam(m_renderCtx.getType(), m_pname))
1914 		extensions.add(getTextureParamExtension(m_renderCtx.getType(), m_pname));
1915 
1916 	// query
1917 	if (!isCoreQuery(m_renderCtx.getType(), m_type))
1918 		extensions.add(getQueryExtension(m_renderCtx.getType(), m_type));
1919 
1920 	// test type
1921 	if (!isCoreTester(m_renderCtx.getType(), m_tester))
1922 		extensions.add(getTesterExtension(m_renderCtx.getType(), m_tester));
1923 
1924 	extensions.check(*ctxInfo);
1925 }
1926 
iterate(void)1927 SamplerTest::IterateResult SamplerTest::iterate (void)
1928 {
1929 	glu::CallLogWrapper		gl		(m_renderCtx.getFunctions(), m_testCtx.getLog());
1930 	tcu::ResultCollector	result	(m_testCtx.getLog(), " // ERROR: ");
1931 	glu::Sampler			sampler	(m_renderCtx);
1932 
1933 	gl.enableLogging(true);
1934 
1935 	m_target = *sampler;
1936 	test(gl, result);
1937 	m_target = 0;
1938 
1939 	result.setTestContextResult(m_testCtx);
1940 	return STOP;
1941 }
1942 
1943 class SamplerWrapCase : public SamplerTest
1944 {
1945 public:
1946 			SamplerWrapCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, TesterType tester, QueryType type);
1947 	void	test			(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
1948 };
1949 
SamplerWrapCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,TesterType tester,QueryType type)1950 SamplerWrapCase::SamplerWrapCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, TesterType tester, QueryType type)
1951 	: SamplerTest(testCtx, renderCtx, name, desc, tester, type)
1952 {
1953 }
1954 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const1955 void SamplerWrapCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
1956 {
1957 	const bool isPureCase = isPureIntTester(m_tester) || isPureUintTester(m_tester);
1958 
1959 	if (!isPureCase)
1960 	{
1961 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
1962 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_REPEAT, m_type);
1963 	}
1964 
1965 	{
1966 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
1967 		const GLenum				wrapValues[]	= {GL_CLAMP_TO_EDGE, GL_REPEAT, GL_MIRRORED_REPEAT};
1968 
1969 		if (isPureCase)
1970 		{
1971 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(wrapValues); ++ndx)
1972 			{
1973 				if (isPureIntTester(m_tester))
1974 				{
1975 					const glw::GLint value = (glw::GLint)wrapValues[ndx];
1976 					gl.glSamplerParameterIiv(m_target, m_pname, &value);
1977 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIiv");
1978 				}
1979 				else
1980 				{
1981 					DE_ASSERT(isPureUintTester(m_tester));
1982 
1983 					const glw::GLuint value = wrapValues[ndx];
1984 					gl.glSamplerParameterIuiv(m_target, m_pname, &value);
1985 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIuiv");
1986 				}
1987 
1988 				verifyStateSamplerParamInteger(result, gl, m_target, m_pname, wrapValues[ndx], m_type);
1989 			}
1990 		}
1991 		else
1992 		{
1993 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(wrapValues); ++ndx)
1994 			{
1995 				gl.glSamplerParameteri(m_target, m_pname, wrapValues[ndx]);
1996 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameteri");
1997 
1998 				verifyStateSamplerParamInteger(result, gl, m_target, m_pname, wrapValues[ndx], m_type);
1999 			}
2000 
2001 			//check unit conversions with float
2002 
2003 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(wrapValues); ++ndx)
2004 			{
2005 				gl.glSamplerParameterf(m_target, m_pname, (GLfloat)wrapValues[ndx]);
2006 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterf");
2007 
2008 				verifyStateSamplerParamInteger(result, gl, m_target, m_pname, wrapValues[ndx], m_type);
2009 			}
2010 		}
2011 	}
2012 }
2013 
2014 class SamplerFilterCase : public SamplerTest
2015 {
2016 public:
2017 			SamplerFilterCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, TesterType tester, QueryType type);
2018 	void	test				(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
2019 };
2020 
SamplerFilterCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,TesterType tester,QueryType type)2021 SamplerFilterCase::SamplerFilterCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, TesterType tester, QueryType type)
2022 	: SamplerTest(testCtx, renderCtx, name, desc, tester, type)
2023 {
2024 }
2025 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const2026 void SamplerFilterCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
2027 {
2028 	const bool			isPureCase	= isPureIntTester(m_tester) || isPureUintTester(m_tester);
2029 	const glw::GLenum	initial		= (m_pname == GL_TEXTURE_MAG_FILTER) ? (GL_LINEAR)
2030 									: (m_pname == GL_TEXTURE_MIN_FILTER) ? (GL_NEAREST_MIPMAP_LINEAR)
2031 									: (0);
2032 
2033 	if (!isPureCase)
2034 	{
2035 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
2036 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, initial, m_type);
2037 	}
2038 
2039 	{
2040 		const tcu::ScopedLogSection	section		(m_testCtx.getLog(), "Set", "Set");
2041 		std::vector<GLenum>			values;
2042 
2043 		values.push_back(GL_NEAREST);
2044 		values.push_back(GL_LINEAR);
2045 		if (m_pname == GL_TEXTURE_MIN_FILTER)
2046 		{
2047 			values.push_back(GL_NEAREST_MIPMAP_NEAREST);
2048 			values.push_back(GL_NEAREST_MIPMAP_LINEAR);
2049 			values.push_back(GL_LINEAR_MIPMAP_NEAREST);
2050 			values.push_back(GL_LINEAR_MIPMAP_LINEAR);
2051 		}
2052 
2053 		if (isPureCase)
2054 		{
2055 			for (int ndx = 0; ndx < (int)values.size(); ++ndx)
2056 			{
2057 				if (isPureIntTester(m_tester))
2058 				{
2059 					const glw::GLint value = (glw::GLint)values[ndx];
2060 					gl.glSamplerParameterIiv(m_target, m_pname, &value);
2061 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIiv");
2062 				}
2063 				else
2064 				{
2065 					DE_ASSERT(isPureUintTester(m_tester));
2066 
2067 					const glw::GLuint value = values[ndx];
2068 					gl.glSamplerParameterIuiv(m_target, m_pname, &value);
2069 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIuiv");
2070 				}
2071 
2072 				verifyStateSamplerParamInteger(result, gl, m_target, m_pname, values[ndx], m_type);
2073 			}
2074 		}
2075 		else
2076 		{
2077 			for (int ndx = 0; ndx < (int)values.size(); ++ndx)
2078 			{
2079 				gl.glSamplerParameteri(m_target, m_pname, values[ndx]);
2080 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameteri");
2081 
2082 				verifyStateSamplerParamInteger(result, gl, m_target, m_pname, values[ndx], m_type);
2083 			}
2084 
2085 			//check unit conversions with float
2086 
2087 			for (int ndx = 0; ndx < (int)values.size(); ++ndx)
2088 			{
2089 				gl.glSamplerParameterf(m_target, m_pname, (GLfloat)values[ndx]);
2090 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterf");
2091 
2092 				verifyStateSamplerParamInteger(result, gl, m_target, m_pname, values[ndx], m_type);
2093 			}
2094 		}
2095 	}
2096 }
2097 
2098 class SamplerLODCase : public SamplerTest
2099 {
2100 public:
2101 			SamplerLODCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, TesterType tester, QueryType type);
2102 	void	test			(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
2103 };
2104 
SamplerLODCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,TesterType tester,QueryType type)2105 SamplerLODCase::SamplerLODCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, TesterType tester, QueryType type)
2106 	: SamplerTest(testCtx, renderCtx, name, desc, tester, type)
2107 {
2108 }
2109 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const2110 void SamplerLODCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
2111 {
2112 	const bool	isPureCase		= isPureIntTester(m_tester) || isPureUintTester(m_tester);
2113 	const int	initialValue	= (m_pname == GL_TEXTURE_MIN_LOD) ? (-1000)
2114 								: (m_pname == GL_TEXTURE_MAX_LOD) ? (1000)
2115 								: (-1);
2116 
2117 	if ((querySupportsSigned(m_type) || initialValue >= 0) && !isPureCase)
2118 	{
2119 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
2120 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, initialValue, m_type);
2121 	}
2122 
2123 	{
2124 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
2125 		const int					numIterations	= 20;
2126 		de::Random					rnd				(0xabcdef);
2127 
2128 		if (isPureCase)
2129 		{
2130 			if (isPureIntTester(m_tester))
2131 			{
2132 				for (int ndx = 0; ndx < numIterations; ++ndx)
2133 				{
2134 					const GLint ref = rnd.getInt(-1000, 1000);
2135 
2136 					gl.glSamplerParameterIiv(m_target, m_pname, &ref);
2137 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIiv");
2138 
2139 					verifyStateSamplerParamFloat(result, gl, m_target, m_pname, (float)ref, m_type);
2140 				}
2141 			}
2142 			else
2143 			{
2144 				DE_ASSERT(isPureUintTester(m_tester));
2145 
2146 				for (int ndx = 0; ndx < numIterations; ++ndx)
2147 				{
2148 					const GLuint ref = (glw::GLuint)rnd.getInt(0, 1000);
2149 
2150 					gl.glSamplerParameterIuiv(m_target, m_pname, &ref);
2151 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIuiv");
2152 
2153 					verifyStateSamplerParamFloat(result, gl, m_target, m_pname, (float)ref, m_type);
2154 				}
2155 			}
2156 		}
2157 		else
2158 		{
2159 			const int minLimit = (querySupportsSigned(m_type)) ? (-1000) : (0);
2160 
2161 			for (int ndx = 0; ndx < numIterations; ++ndx)
2162 			{
2163 				const GLfloat ref = rnd.getFloat((float)minLimit, 1000.f);
2164 
2165 				gl.glSamplerParameterf(m_target, m_pname, ref);
2166 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterf");
2167 
2168 				verifyStateSamplerParamFloat(result, gl, m_target, m_pname, ref, m_type);
2169 			}
2170 
2171 			// check unit conversions with int
2172 
2173 			for (int ndx = 0; ndx < numIterations; ++ndx)
2174 			{
2175 				const GLint ref = rnd.getInt(minLimit, 1000);
2176 
2177 				gl.glSamplerParameteri(m_target, m_pname, ref);
2178 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameteri");
2179 
2180 				verifyStateSamplerParamFloat(result, gl, m_target, m_pname, (float)ref, m_type);
2181 			}
2182 		}
2183 	}
2184 }
2185 
2186 class SamplerCompareModeCase : public SamplerTest
2187 {
2188 public:
2189 			SamplerCompareModeCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, TesterType tester, QueryType type);
2190 	void	test					(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
2191 };
2192 
SamplerCompareModeCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,TesterType tester,QueryType type)2193 SamplerCompareModeCase::SamplerCompareModeCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, TesterType tester, QueryType type)
2194 	: SamplerTest(testCtx, renderCtx, name, desc, tester, type)
2195 {
2196 }
2197 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const2198 void SamplerCompareModeCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
2199 {
2200 	const bool isPureCase = isPureIntTester(m_tester) || isPureUintTester(m_tester);
2201 
2202 	if (!isPureCase)
2203 	{
2204 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
2205 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_NONE, m_type);
2206 	}
2207 
2208 	{
2209 		const tcu::ScopedLogSection	section		(m_testCtx.getLog(), "Set", "Set");
2210 		const GLenum				modes[]		= {GL_COMPARE_REF_TO_TEXTURE, GL_NONE};
2211 
2212 		if (isPureCase)
2213 		{
2214 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(modes); ++ndx)
2215 			{
2216 				if (isPureIntTester(m_tester))
2217 				{
2218 					const glw::GLint value = (glw::GLint)modes[ndx];
2219 					gl.glSamplerParameterIiv(m_target, m_pname, &value);
2220 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIiv");
2221 				}
2222 				else
2223 				{
2224 					DE_ASSERT(isPureUintTester(m_tester));
2225 
2226 					const glw::GLuint value = modes[ndx];
2227 					gl.glSamplerParameterIuiv(m_target, m_pname, &value);
2228 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIuiv");
2229 				}
2230 
2231 				verifyStateSamplerParamInteger(result, gl, m_target, m_pname, modes[ndx], m_type);
2232 			}
2233 		}
2234 		else
2235 		{
2236 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(modes); ++ndx)
2237 			{
2238 				gl.glSamplerParameteri(m_target, m_pname, modes[ndx]);
2239 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameteri");
2240 
2241 				verifyStateSamplerParamInteger(result, gl, m_target, m_pname, modes[ndx], m_type);
2242 			}
2243 
2244 			//check unit conversions with float
2245 
2246 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(modes); ++ndx)
2247 			{
2248 				gl.glSamplerParameterf(m_target, m_pname, (GLfloat)modes[ndx]);
2249 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterf");
2250 
2251 				verifyStateSamplerParamInteger(result, gl, m_target, m_pname, modes[ndx], m_type);
2252 			}
2253 		}
2254 	}
2255 }
2256 
2257 class SamplerCompareFuncCase : public SamplerTest
2258 {
2259 public:
2260 			SamplerCompareFuncCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, TesterType tester, QueryType type);
2261 	void	test					(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
2262 };
2263 
SamplerCompareFuncCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,TesterType tester,QueryType type)2264 SamplerCompareFuncCase::SamplerCompareFuncCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, TesterType tester, QueryType type)
2265 	: SamplerTest(testCtx, renderCtx, name, desc, tester, type)
2266 {
2267 }
2268 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const2269 void SamplerCompareFuncCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
2270 {
2271 	const bool isPureCase = isPureIntTester(m_tester) || isPureUintTester(m_tester);
2272 
2273 	if (!isPureCase)
2274 	{
2275 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
2276 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_LEQUAL, m_type);
2277 	}
2278 
2279 	{
2280 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
2281 		const GLenum				compareFuncs[]	= {GL_LEQUAL, GL_GEQUAL, GL_LESS, GL_GREATER, GL_EQUAL, GL_NOTEQUAL, GL_ALWAYS, GL_NEVER};
2282 
2283 		if (isPureCase)
2284 		{
2285 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(compareFuncs); ++ndx)
2286 			{
2287 				if (isPureIntTester(m_tester))
2288 				{
2289 					const glw::GLint value = (glw::GLint)compareFuncs[ndx];
2290 					gl.glSamplerParameterIiv(m_target, m_pname, &value);
2291 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIiv");
2292 				}
2293 				else
2294 				{
2295 					DE_ASSERT(isPureUintTester(m_tester));
2296 
2297 					const glw::GLuint value = compareFuncs[ndx];
2298 					gl.glSamplerParameterIuiv(m_target, m_pname, &value);
2299 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIuiv");
2300 				}
2301 
2302 				verifyStateSamplerParamInteger(result, gl, m_target, m_pname, compareFuncs[ndx], m_type);
2303 			}
2304 		}
2305 		else
2306 		{
2307 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(compareFuncs); ++ndx)
2308 			{
2309 				gl.glSamplerParameteri(m_target, m_pname, compareFuncs[ndx]);
2310 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameteri");
2311 
2312 				verifyStateSamplerParamInteger(result, gl, m_target, m_pname, compareFuncs[ndx], m_type);
2313 			}
2314 
2315 			//check unit conversions with float
2316 
2317 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(compareFuncs); ++ndx)
2318 			{
2319 				gl.glSamplerParameterf(m_target, m_pname, (GLfloat)compareFuncs[ndx]);
2320 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterf");
2321 
2322 				verifyStateSamplerParamInteger(result, gl, m_target, m_pname, compareFuncs[ndx], m_type);
2323 			}
2324 		}
2325 	}
2326 }
2327 
2328 class SamplerWrapClampToBorderCase : public SamplerTest
2329 {
2330 public:
2331 			SamplerWrapClampToBorderCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, TesterType tester, QueryType type);
2332 	void	test							(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
2333 };
2334 
SamplerWrapClampToBorderCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,TesterType tester,QueryType type)2335 SamplerWrapClampToBorderCase::SamplerWrapClampToBorderCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, TesterType tester, QueryType type)
2336 	: SamplerTest(testCtx, renderCtx, name, desc, tester, type)
2337 {
2338 }
2339 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const2340 void SamplerWrapClampToBorderCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
2341 {
2342 	gl.glSamplerParameteri(m_target, m_pname, GL_CLAMP_TO_BORDER_EXT);
2343 	GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameteri");
2344 	verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_CLAMP_TO_BORDER_EXT, m_type);
2345 
2346 	gl.glSamplerParameteri(m_target, m_pname, GL_REPEAT);
2347 	GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameteri");
2348 
2349 	gl.glSamplerParameterf(m_target, m_pname, (GLfloat)GL_CLAMP_TO_BORDER_EXT);
2350 	GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterf");
2351 
2352 	verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_CLAMP_TO_BORDER_EXT, m_type);
2353 }
2354 
2355 class SamplerSRGBDecodeCase : public SamplerTest
2356 {
2357 public:
2358 			SamplerSRGBDecodeCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, TesterType tester, QueryType type);
2359 	void	test					(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
2360 };
2361 
SamplerSRGBDecodeCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,TesterType tester,QueryType type)2362 SamplerSRGBDecodeCase::SamplerSRGBDecodeCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, TesterType tester, QueryType type)
2363 	: SamplerTest(testCtx, renderCtx, name, desc, tester, type)
2364 {
2365 }
2366 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const2367 void SamplerSRGBDecodeCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
2368 {
2369 	const bool isPureCase = isPureIntTester(m_tester) || isPureUintTester(m_tester);
2370 
2371 	if (!isPureCase)
2372 	{
2373 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
2374 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_DECODE_EXT, m_type);
2375 	}
2376 
2377 	{
2378 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Toggle", "Toggle");
2379 		const glw::GLint			decodeInt		= GL_DECODE_EXT;
2380 		const glw::GLfloat			decodeFloat		= (glw::GLfloat)GL_DECODE_EXT;
2381 
2382 		gl.glSamplerParameteri(m_target, m_pname, GL_SKIP_DECODE_EXT);
2383 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "set state");
2384 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_SKIP_DECODE_EXT, m_type);
2385 
2386 		gl.glSamplerParameteriv(m_target, m_pname, &decodeInt);
2387 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "set state");
2388 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_DECODE_EXT, m_type);
2389 
2390 		gl.glSamplerParameterf(m_target, m_pname, GL_SKIP_DECODE_EXT);
2391 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "set state");
2392 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_SKIP_DECODE_EXT, m_type);
2393 
2394 		gl.glSamplerParameterfv(m_target, m_pname, &decodeFloat);
2395 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "set state");
2396 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_DECODE_EXT, m_type);
2397 	}
2398 
2399 	if (isPureIntTester(m_tester))
2400 	{
2401 		const glw::GLint skipDecode	= GL_SKIP_DECODE_EXT;
2402 		const glw::GLint decode		= GL_DECODE_EXT;
2403 
2404 		gl.glSamplerParameterIiv(m_target, m_pname, &skipDecode);
2405 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIiv");
2406 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_SKIP_DECODE_EXT, m_type);
2407 
2408 		gl.glSamplerParameterIiv(m_target, m_pname, &decode);
2409 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIiv");
2410 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_DECODE_EXT, m_type);
2411 	}
2412 
2413 	if (isPureUintTester(m_tester))
2414 	{
2415 		const glw::GLuint skipDecode	= GL_SKIP_DECODE_EXT;
2416 		const glw::GLuint decode		= GL_DECODE_EXT;
2417 
2418 		gl.glSamplerParameterIuiv(m_target, m_pname, &skipDecode);
2419 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIuiv");
2420 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_SKIP_DECODE_EXT, m_type);
2421 
2422 		gl.glSamplerParameterIuiv(m_target, m_pname, &decode);
2423 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIuiv");
2424 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_DECODE_EXT, m_type);
2425 	}
2426 }
2427 
2428 class SamplerBorderColorCase : public SamplerTest
2429 {
2430 public:
2431 			SamplerBorderColorCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, QueryType type);
2432 	void	test					(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
2433 };
2434 
SamplerBorderColorCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,QueryType type)2435 SamplerBorderColorCase::SamplerBorderColorCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, QueryType type)
2436 	: SamplerTest(testCtx, renderCtx, name, desc, TESTER_TEXTURE_BORDER_COLOR, type)
2437 {
2438 	DE_ASSERT(m_type == QUERY_SAMPLER_PARAM_INTEGER_VEC4					||
2439 			  m_type == QUERY_SAMPLER_PARAM_FLOAT_VEC4						||
2440 			  m_type == QUERY_SAMPLER_PARAM_PURE_INTEGER_VEC4				||
2441 			  m_type == QUERY_SAMPLER_PARAM_PURE_UNSIGNED_INTEGER_VEC4);
2442 }
2443 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const2444 void SamplerBorderColorCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
2445 {
2446 	// border color is undefined if queried with pure type and was not set to pure value
2447 	if (m_type == QUERY_SAMPLER_PARAM_INTEGER_VEC4 || m_type == QUERY_SAMPLER_PARAM_FLOAT_VEC4)
2448 	{
2449 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
2450 		verifyStateSamplerParamFloatVec4(result, gl, m_target, m_pname, tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), m_type);
2451 	}
2452 
2453 	if (m_type == QUERY_SAMPLER_PARAM_PURE_INTEGER_VEC4)
2454 	{
2455 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
2456 		const tcu::IVec4			color			(0x7FFFFFFF, -2, 3, -128);
2457 
2458 		gl.glSamplerParameterIiv(m_target, m_pname, color.getPtr());
2459 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIiv");
2460 
2461 		verifyStateSamplerParamIntegerVec4(result, gl, m_target, m_pname, color, m_type);
2462 	}
2463 	else if (m_type == QUERY_SAMPLER_PARAM_PURE_UNSIGNED_INTEGER_VEC4)
2464 	{
2465 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
2466 		const tcu::UVec4			color			(0x8000000ul, 2, 3, 128);
2467 
2468 		gl.glSamplerParameterIuiv(m_target, m_pname, color.getPtr());
2469 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIuiv");
2470 
2471 		verifyStateSamplerParamUnsignedIntegerVec4(result, gl, m_target, m_pname, color, m_type);
2472 	}
2473 	else
2474 	{
2475 		DE_ASSERT(m_type == QUERY_SAMPLER_PARAM_INTEGER_VEC4 || m_type == QUERY_SAMPLER_PARAM_FLOAT_VEC4);
2476 
2477 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
2478 		const tcu::Vec4				color			(0.25f, 1.0f, 0.0f, 0.77f);
2479 		const tcu::IVec4			icolor			(0x8000000ul, 0x7FFFFFFF, 0, 0x0FFFFFFF);
2480 
2481 		gl.glSamplerParameterfv(m_target, m_pname, color.getPtr());
2482 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterfv");
2483 
2484 		verifyStateSamplerParamFloatVec4(result, gl, m_target, m_pname, color, m_type);
2485 
2486 		gl.glSamplerParameteriv(m_target, m_pname, icolor.getPtr());
2487 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameteriv");
2488 
2489 		verifyStateSamplerParamNormalizedI32Vec4(result, gl, m_target, m_pname, icolor, m_type);
2490 	}
2491 }
2492 
2493 } // anonymous
2494 
isLegalTesterForTarget(glw::GLenum target,TesterType tester)2495 bool isLegalTesterForTarget (glw::GLenum target, TesterType tester)
2496 {
2497 	// no 3d filtering on 2d targets
2498 	if ((tester == TESTER_TEXTURE_WRAP_R || tester == TESTER_TEXTURE_WRAP_R_CLAMP_TO_BORDER) &&  target != GL_TEXTURE_3D)
2499 		return false;
2500 
2501 	// no sampling on multisample
2502 	if (isMultisampleTarget(target) && isSamplerStateTester(tester))
2503 		return false;
2504 
2505 	// no states in buffer
2506 	if (target == GL_TEXTURE_BUFFER)
2507 		return false;
2508 
2509 	return true;
2510 }
2511 
isMultisampleTarget(glw::GLenum target)2512 bool isMultisampleTarget (glw::GLenum target)
2513 {
2514 	return	target == GL_TEXTURE_2D_MULTISAMPLE			||
2515 			target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
2516 }
2517 
isSamplerStateTester(TesterType tester)2518 bool isSamplerStateTester (TesterType tester)
2519 {
2520 	return	tester == TESTER_TEXTURE_WRAP_S					||
2521 			tester == TESTER_TEXTURE_WRAP_T					||
2522 			tester == TESTER_TEXTURE_WRAP_R					||
2523 			tester == TESTER_TEXTURE_MAG_FILTER				||
2524 			tester == TESTER_TEXTURE_MIN_FILTER				||
2525 			tester == TESTER_TEXTURE_MIN_LOD				||
2526 			tester == TESTER_TEXTURE_MAX_LOD				||
2527 			tester == TESTER_TEXTURE_COMPARE_MODE			||
2528 			tester == TESTER_TEXTURE_COMPARE_FUNC			||
2529 			tester == TESTER_TEXTURE_SRGB_DECODE_EXT		||
2530 			tester == TESTER_TEXTURE_BORDER_COLOR			||
2531 			tester == TESTER_TEXTURE_WRAP_S_CLAMP_TO_BORDER	||
2532 			tester == TESTER_TEXTURE_WRAP_T_CLAMP_TO_BORDER	||
2533 			tester == TESTER_TEXTURE_WRAP_R_CLAMP_TO_BORDER;
2534 }
2535 
createIsTextureTest(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const std::string & name,const std::string & description,glw::GLenum target)2536 tcu::TestCase* createIsTextureTest (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const std::string& name, const std::string& description, glw::GLenum target)
2537 {
2538 	return new IsTextureCase(testCtx, renderCtx, name.c_str(), description.c_str(), target);
2539 }
2540 
createTexParamTest(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const std::string & name,const std::string & description,QueryType queryType,glw::GLenum target,TesterType tester)2541 tcu::TestCase* createTexParamTest (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const std::string& name, const std::string& description, QueryType queryType, glw::GLenum target, TesterType tester)
2542 {
2543 	if (isMultisampleTarget(target) && isSamplerStateTester(tester))
2544 	{
2545 		DE_FATAL("Multisample textures have no sampler state");
2546 		return DE_NULL;
2547 	}
2548 	if (target == GL_TEXTURE_BUFFER)
2549 	{
2550 		DE_FATAL("Buffer textures have no texture state");
2551 		return DE_NULL;
2552 	}
2553 	if (target != GL_TEXTURE_3D && mapTesterToPname(tester) == GL_TEXTURE_WRAP_R)
2554 	{
2555 		DE_FATAL("Only 3D textures have wrap r filter");
2556 		return DE_NULL;
2557 	}
2558 
2559 #define CASE_ALL_SETTERS(X) case X: case X ## _SET_PURE_INT: case X ## _SET_PURE_UINT
2560 
2561 	switch (tester)
2562 	{
2563 		CASE_ALL_SETTERS(TESTER_TEXTURE_SWIZZLE_R):
2564 		CASE_ALL_SETTERS(TESTER_TEXTURE_SWIZZLE_G):
2565 		CASE_ALL_SETTERS(TESTER_TEXTURE_SWIZZLE_B):
2566 		CASE_ALL_SETTERS(TESTER_TEXTURE_SWIZZLE_A):
2567 			return new TextureSwizzleCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, tester, queryType);
2568 
2569 		CASE_ALL_SETTERS(TESTER_TEXTURE_WRAP_S):
2570 		CASE_ALL_SETTERS(TESTER_TEXTURE_WRAP_T):
2571 		CASE_ALL_SETTERS(TESTER_TEXTURE_WRAP_R):
2572 			return new TextureWrapCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, tester, queryType);
2573 
2574 		CASE_ALL_SETTERS(TESTER_TEXTURE_MAG_FILTER):
2575 		CASE_ALL_SETTERS(TESTER_TEXTURE_MIN_FILTER):
2576 			return new TextureFilterCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, tester, queryType);
2577 
2578 		CASE_ALL_SETTERS(TESTER_TEXTURE_MIN_LOD):
2579 		CASE_ALL_SETTERS(TESTER_TEXTURE_MAX_LOD):
2580 			return new TextureLODCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, tester, queryType);
2581 
2582 		CASE_ALL_SETTERS(TESTER_TEXTURE_BASE_LEVEL):
2583 		CASE_ALL_SETTERS(TESTER_TEXTURE_MAX_LEVEL):
2584 			return new TextureLevelCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, tester, queryType);
2585 
2586 		CASE_ALL_SETTERS(TESTER_TEXTURE_COMPARE_MODE):
2587 			return new TextureCompareModeCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, tester, queryType);
2588 
2589 		CASE_ALL_SETTERS(TESTER_TEXTURE_COMPARE_FUNC):
2590 			return new TextureCompareFuncCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, tester, queryType);
2591 
2592 		case TESTER_TEXTURE_IMMUTABLE_LEVELS:
2593 			return new TextureImmutableLevelsCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, queryType);
2594 
2595 		case TESTER_TEXTURE_IMMUTABLE_FORMAT:
2596 			return new TextureImmutableFormatCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, queryType);
2597 
2598 		case TESTER_TEXTURE_WRAP_S_CLAMP_TO_BORDER:
2599 		case TESTER_TEXTURE_WRAP_T_CLAMP_TO_BORDER:
2600 		case TESTER_TEXTURE_WRAP_R_CLAMP_TO_BORDER:
2601 			return new TextureWrapClampToBorderCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, tester, queryType);
2602 
2603 		CASE_ALL_SETTERS(TESTER_DEPTH_STENCIL_TEXTURE_MODE):
2604 			return new DepthStencilModeCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, tester, queryType);
2605 
2606 		CASE_ALL_SETTERS(TESTER_TEXTURE_SRGB_DECODE_EXT):
2607 			return new TextureSRGBDecodeCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, tester, queryType);
2608 
2609 		case TESTER_TEXTURE_BORDER_COLOR:
2610 			return new TextureBorderColorCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, queryType);
2611 
2612 		default:
2613 			break;
2614 	}
2615 
2616 #undef CASE_ALL_SETTERS
2617 
2618 	DE_ASSERT(false);
2619 	return DE_NULL;
2620 }
2621 
createSamplerParamTest(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const std::string & name,const std::string & description,StateQueryUtil::QueryType queryType,TesterType tester)2622 tcu::TestCase* createSamplerParamTest (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const std::string& name, const std::string& description, StateQueryUtil::QueryType queryType, TesterType tester)
2623 {
2624 #define CASE_ALL_SETTERS(X) case X: case X ## _SET_PURE_INT: case X ## _SET_PURE_UINT
2625 
2626 	switch (tester)
2627 	{
2628 		CASE_ALL_SETTERS(TESTER_TEXTURE_WRAP_S):
2629 		CASE_ALL_SETTERS(TESTER_TEXTURE_WRAP_T):
2630 		CASE_ALL_SETTERS(TESTER_TEXTURE_WRAP_R):
2631 			return new SamplerWrapCase(testCtx, renderCtx, name.c_str(), description.c_str(), tester, queryType);
2632 
2633 		CASE_ALL_SETTERS(TESTER_TEXTURE_MAG_FILTER):
2634 		CASE_ALL_SETTERS(TESTER_TEXTURE_MIN_FILTER):
2635 			return new SamplerFilterCase(testCtx, renderCtx, name.c_str(), description.c_str(), tester, queryType);
2636 
2637 		CASE_ALL_SETTERS(TESTER_TEXTURE_MIN_LOD):
2638 		CASE_ALL_SETTERS(TESTER_TEXTURE_MAX_LOD):
2639 			return new SamplerLODCase(testCtx, renderCtx, name.c_str(), description.c_str(), tester, queryType);
2640 
2641 		CASE_ALL_SETTERS(TESTER_TEXTURE_COMPARE_MODE):
2642 			return new SamplerCompareModeCase(testCtx, renderCtx, name.c_str(), description.c_str(), tester, queryType);
2643 
2644 		CASE_ALL_SETTERS(TESTER_TEXTURE_COMPARE_FUNC):
2645 			return new SamplerCompareFuncCase(testCtx, renderCtx, name.c_str(), description.c_str(), tester, queryType);
2646 
2647 		case TESTER_TEXTURE_WRAP_S_CLAMP_TO_BORDER:
2648 		case TESTER_TEXTURE_WRAP_T_CLAMP_TO_BORDER:
2649 		case TESTER_TEXTURE_WRAP_R_CLAMP_TO_BORDER:
2650 			return new SamplerWrapClampToBorderCase(testCtx, renderCtx, name.c_str(), description.c_str(), tester, queryType);
2651 
2652 		CASE_ALL_SETTERS(TESTER_TEXTURE_SRGB_DECODE_EXT):
2653 			return new SamplerSRGBDecodeCase(testCtx, renderCtx, name.c_str(), description.c_str(), tester, queryType);
2654 
2655 		case TESTER_TEXTURE_BORDER_COLOR:
2656 			return new SamplerBorderColorCase(testCtx, renderCtx, name.c_str(), description.c_str(), queryType);
2657 
2658 		default:
2659 			break;
2660 	}
2661 
2662 #undef CASE_ALL_SETTERS
2663 
2664 	DE_ASSERT(false);
2665 	return DE_NULL;
2666 }
2667 
2668 } // TextureStateQueryTests
2669 } // gls
2670 } // deqp
2671