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 
isCoreTextureTarget(const glu::ContextType & contextType,glw::GLenum target)445 static bool isCoreTextureTarget (const glu::ContextType& contextType, glw::GLenum target)
446 {
447 	if (contextSupports(contextType, glu::ApiType::es(3,1)))
448 		return es31::isCoreTextureTarget(target);
449 	else if (contextSupports(contextType, glu::ApiType::es(3,0)))
450 		return es30::isCoreTextureTarget(target);
451 	else
452 	{
453 		DE_ASSERT(false);
454 		return DE_NULL;
455 	}
456 }
457 
isCoreTextureParam(const glu::ContextType & contextType,glw::GLenum pname)458 static bool isCoreTextureParam (const glu::ContextType& contextType, glw::GLenum pname)
459 {
460 	if (contextSupports(contextType, glu::ApiType::es(3,1)))
461 		return es31::isCoreTextureParam(pname);
462 	else if (contextSupports(contextType, glu::ApiType::es(3,0)))
463 		return es30::isCoreTextureParam(pname);
464 	else
465 	{
466 		DE_ASSERT(false);
467 		return DE_NULL;
468 	}
469 }
470 
isCoreQuery(const glu::ContextType & contextType,QueryType query)471 static bool isCoreQuery (const glu::ContextType& contextType, QueryType query)
472 {
473 	if (contextSupports(contextType, glu::ApiType::es(3,1)))
474 		return es31::isCoreQuery(query);
475 	else if (contextSupports(contextType, glu::ApiType::es(3,0)))
476 		return es30::isCoreQuery(query);
477 	else
478 	{
479 		DE_ASSERT(false);
480 		return DE_NULL;
481 	}
482 }
483 
isCoreTester(const glu::ContextType & contextType,TesterType tester)484 static bool isCoreTester (const glu::ContextType& contextType, TesterType tester)
485 {
486 	if (contextSupports(contextType, glu::ApiType::es(3,1)))
487 		return es31::isCoreTester(tester);
488 	else if (contextSupports(contextType, glu::ApiType::es(3,0)))
489 		return es30::isCoreTester(tester);
490 	else
491 	{
492 		DE_ASSERT(false);
493 		return DE_NULL;
494 	}
495 }
496 
getTextureTargetExtension(const glu::ContextType & contextType,glw::GLenum target)497 static RequiredExtensions getTextureTargetExtension (const glu::ContextType& contextType, glw::GLenum target)
498 {
499 	DE_ASSERT(!isCoreTextureTarget(contextType, target));
500 
501 	if (contextSupports(contextType, glu::ApiType::es(3,1)))
502 		return es31::getTextureTargetExtension(target);
503 	else if (contextSupports(contextType, glu::ApiType::es(3,0)))
504 		return es30::getTextureTargetExtension(target);
505 	else
506 	{
507 		DE_ASSERT(false);
508 		return RequiredExtensions();
509 	}
510 }
511 
getTextureParamExtension(const glu::ContextType & contextType,glw::GLenum pname)512 static RequiredExtensions getTextureParamExtension (const glu::ContextType& contextType, glw::GLenum pname)
513 {
514 	DE_ASSERT(!isCoreTextureParam(contextType, pname));
515 
516 	if (contextSupports(contextType, glu::ApiType::es(3,1)))
517 		return es31::getTextureParamExtension(pname);
518 	else if (contextSupports(contextType, glu::ApiType::es(3,0)))
519 		return es30::getTextureParamExtension(pname);
520 	else
521 	{
522 		DE_ASSERT(false);
523 		return RequiredExtensions();
524 	}
525 }
526 
getQueryExtension(const glu::ContextType & contextType,QueryType query)527 static RequiredExtensions getQueryExtension (const glu::ContextType& contextType, QueryType query)
528 {
529 	DE_ASSERT(!isCoreQuery(contextType, query));
530 
531 	if (contextSupports(contextType, glu::ApiType::es(3,1)))
532 		return es31::getQueryExtension(query);
533 	else if (contextSupports(contextType, glu::ApiType::es(3,0)))
534 		return es30::getQueryExtension(query);
535 	else
536 	{
537 		DE_ASSERT(false);
538 		return RequiredExtensions();
539 	}
540 }
541 
getTesterExtension(const glu::ContextType & contextType,TesterType tester)542 static RequiredExtensions getTesterExtension (const glu::ContextType& contextType, TesterType tester)
543 {
544 	DE_ASSERT(!isCoreTester(contextType, tester));
545 
546 	if (contextSupports(contextType, glu::ApiType::es(3,1)))
547 		return es31::getTesterExtension(tester);
548 	else if (contextSupports(contextType, glu::ApiType::es(3,0)))
549 		return es30::getTesterExtension(tester);
550 	else
551 	{
552 		DE_ASSERT(false);
553 		return RequiredExtensions();
554 	}
555 }
556 
557 class TextureTest : public tcu::TestCase
558 {
559 public:
560 						TextureTest	(tcu::TestContext&			testCtx,
561 									 const glu::RenderContext&	renderCtx,
562 									 const char*				name,
563 									 const char*				desc,
564 									 glw::GLenum				target,
565 									 TesterType					tester,
566 									 QueryType					type);
567 
568 	void				init		(void);
569 	IterateResult		iterate		(void);
570 
571 	virtual void		test		(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const = 0;
572 
573 protected:
574 	const glu::RenderContext&	m_renderCtx;
575 	const glw::GLenum			m_target;
576 	const glw::GLenum			m_pname;
577 	const TesterType			m_tester;
578 	const QueryType				m_type;
579 };
580 
TextureTest(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,TesterType tester,QueryType type)581 TextureTest::TextureTest (tcu::TestContext&			testCtx,
582 						  const glu::RenderContext&	renderCtx,
583 						  const char*				name,
584 						  const char*				desc,
585 						  glw::GLenum				target,
586 						  TesterType				tester,
587 						  QueryType					type)
588 	: TestCase		(testCtx, name, desc)
589 	, m_renderCtx	(renderCtx)
590 	, m_target		(target)
591 	, m_pname		(mapTesterToPname(tester))
592 	, m_tester		(tester)
593 	, m_type		(type)
594 {
595 }
596 
init(void)597 void TextureTest::init (void)
598 {
599 	const de::UniquePtr<glu::ContextInfo>	ctxInfo		(glu::ContextInfo::create(m_renderCtx));
600 	RequiredExtensions						extensions;
601 
602 	// target
603 	if (!isCoreTextureTarget(m_renderCtx.getType(), m_target))
604 		extensions.add(getTextureTargetExtension(m_renderCtx.getType(), m_target));
605 
606 	// param
607 	if (!isCoreTextureParam(m_renderCtx.getType(), m_pname))
608 		extensions.add(getTextureParamExtension(m_renderCtx.getType(), m_pname));
609 
610 	// query
611 	if (!isCoreQuery(m_renderCtx.getType(), m_type))
612 		extensions.add(getQueryExtension(m_renderCtx.getType(), m_type));
613 
614 	// test type
615 	if (!isCoreTester(m_renderCtx.getType(), m_tester))
616 		extensions.add(getTesterExtension(m_renderCtx.getType(), m_tester));
617 
618 	extensions.check(*ctxInfo);
619 }
620 
iterate(void)621 TextureTest::IterateResult TextureTest::iterate (void)
622 {
623 	glu::CallLogWrapper		gl		(m_renderCtx.getFunctions(), m_testCtx.getLog());
624 	tcu::ResultCollector	result	(m_testCtx.getLog(), " // ERROR: ");
625 
626 	gl.enableLogging(true);
627 	test(gl, result);
628 
629 	result.setTestContextResult(m_testCtx);
630 	return STOP;
631 }
632 
633 class IsTextureCase : public tcu::TestCase
634 {
635 public:
636 								IsTextureCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target);
637 
638 	void						init			(void);
639 	IterateResult				iterate			(void);
640 
641 protected:
642 	const glu::RenderContext&	m_renderCtx;
643 	const glw::GLenum			m_target;
644 };
645 
IsTextureCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target)646 IsTextureCase::IsTextureCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target)
647 	: tcu::TestCase	(testCtx, name, desc)
648 	, m_renderCtx	(renderCtx)
649 	, m_target		(target)
650 {
651 }
652 
init(void)653 void IsTextureCase::init (void)
654 {
655 	const de::UniquePtr<glu::ContextInfo>	ctxInfo		(glu::ContextInfo::create(m_renderCtx));
656 	RequiredExtensions						extensions;
657 
658 	// target
659 	if (!isCoreTextureTarget(m_renderCtx.getType(), m_target))
660 		extensions.add(getTextureTargetExtension(m_renderCtx.getType(), m_target));
661 
662 	extensions.check(*ctxInfo);
663 }
664 
iterate(void)665 IsTextureCase::IterateResult IsTextureCase::iterate (void)
666 {
667 	glu::CallLogWrapper		gl			(m_renderCtx.getFunctions(), m_testCtx.getLog());
668 	tcu::ResultCollector	result		(m_testCtx.getLog(), " // ERROR: ");
669 	glw::GLuint				textureId	= 0;
670 
671 	gl.enableLogging(true);
672 
673 	gl.glGenTextures(1, &textureId);
674 	gl.glBindTexture(m_target, textureId);
675 	GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glBindTexture");
676 
677 	verifyStateObjectBoolean(result, gl, textureId, true, QUERY_ISTEXTURE);
678 
679 	gl.glDeleteTextures(1, &textureId);
680 	GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glDeleteTextures");
681 
682 	verifyStateObjectBoolean(result, gl, textureId, false, QUERY_ISTEXTURE);
683 
684 	result.setTestContextResult(m_testCtx);
685 	return STOP;
686 }
687 
688 class DepthStencilModeCase : public TextureTest
689 {
690 public:
691 			DepthStencilModeCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type);
692 	void	test					(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
693 };
694 
DepthStencilModeCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,TesterType tester,QueryType type)695 DepthStencilModeCase::DepthStencilModeCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type)
696 	: TextureTest(testCtx, renderCtx, name, desc, target, tester, type)
697 {
698 }
699 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const700 void DepthStencilModeCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
701 {
702 	const bool		isPureCase	= isPureIntTester(m_tester) || isPureUintTester(m_tester);
703 	glu::Texture	texture		(m_renderCtx);
704 
705 	gl.glBindTexture(m_target, *texture);
706 	GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "bind");
707 
708 	if (!isPureCase)
709 	{
710 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
711 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_DEPTH_COMPONENT, m_type);
712 	}
713 
714 	if (!isPureCase)
715 	{
716 		const tcu::ScopedLogSection	section				(m_testCtx.getLog(), "Toggle", "Toggle");
717 		const glw::GLint			depthComponentInt	= GL_DEPTH_COMPONENT;
718 		const glw::GLfloat			depthComponentFloat	= (glw::GLfloat)GL_DEPTH_COMPONENT;
719 
720 		gl.glTexParameteri(m_target, m_pname, GL_STENCIL_INDEX);
721 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "set state");
722 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_STENCIL_INDEX, m_type);
723 
724 		gl.glTexParameteriv(m_target, m_pname, &depthComponentInt);
725 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "set state");
726 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_DEPTH_COMPONENT, m_type);
727 
728 		gl.glTexParameterf(m_target, m_pname, GL_STENCIL_INDEX);
729 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "set state");
730 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_STENCIL_INDEX, m_type);
731 
732 		gl.glTexParameterfv(m_target, m_pname, &depthComponentFloat);
733 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "set state");
734 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_DEPTH_COMPONENT, m_type);
735 	}
736 
737 	if (isPureIntTester(m_tester))
738 	{
739 		const glw::GLint depthComponent	= GL_DEPTH_COMPONENT;
740 		const glw::GLint stencilIndex	= GL_STENCIL_INDEX;
741 
742 		gl.glTexParameterIiv(m_target, m_pname, &stencilIndex);
743 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIiv");
744 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_STENCIL_INDEX, m_type);
745 
746 		gl.glTexParameterIiv(m_target, m_pname, &depthComponent);
747 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIiv");
748 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_DEPTH_COMPONENT, m_type);
749 	}
750 
751 	if (isPureUintTester(m_tester))
752 	{
753 		const glw::GLuint depthComponent	= GL_DEPTH_COMPONENT;
754 		const glw::GLuint stencilIndex	= GL_STENCIL_INDEX;
755 
756 		gl.glTexParameterIuiv(m_target, m_pname, &stencilIndex);
757 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIuiv");
758 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_STENCIL_INDEX, m_type);
759 
760 		gl.glTexParameterIuiv(m_target, m_pname, &depthComponent);
761 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIuiv");
762 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_DEPTH_COMPONENT, m_type);
763 	}
764 }
765 
766 class TextureSRGBDecodeCase : public TextureTest
767 {
768 public:
769 			TextureSRGBDecodeCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type);
770 	void	test					(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
771 };
772 
TextureSRGBDecodeCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,TesterType tester,QueryType type)773 TextureSRGBDecodeCase::TextureSRGBDecodeCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type)
774 	: TextureTest(testCtx, renderCtx, name, desc, target, tester, type)
775 {
776 }
777 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const778 void TextureSRGBDecodeCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
779 {
780 	const bool		isPureCase	= isPureIntTester(m_tester) || isPureUintTester(m_tester);
781 	glu::Texture	texture		(m_renderCtx);
782 
783 	gl.glBindTexture(m_target, *texture);
784 	GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "bind");
785 
786 	if (!isPureCase)
787 	{
788 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
789 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_DECODE_EXT, m_type);
790 	}
791 
792 	if (!isPureCase)
793 	{
794 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Toggle", "Toggle");
795 		const glw::GLint			decodeInt		= GL_DECODE_EXT;
796 		const glw::GLfloat			decodeFloat		= (glw::GLfloat)GL_DECODE_EXT;
797 
798 		gl.glTexParameteri(m_target, m_pname, GL_SKIP_DECODE_EXT);
799 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "set state");
800 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_SKIP_DECODE_EXT, m_type);
801 
802 		gl.glTexParameteriv(m_target, m_pname, &decodeInt);
803 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "set state");
804 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_DECODE_EXT, m_type);
805 
806 		gl.glTexParameterf(m_target, m_pname, GL_SKIP_DECODE_EXT);
807 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "set state");
808 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_SKIP_DECODE_EXT, m_type);
809 
810 		gl.glTexParameterfv(m_target, m_pname, &decodeFloat);
811 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "set state");
812 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_DECODE_EXT, m_type);
813 	}
814 
815 	if (isPureIntTester(m_tester))
816 	{
817 		const glw::GLint skipDecode	= GL_SKIP_DECODE_EXT;
818 		const glw::GLint decode		= GL_DECODE_EXT;
819 
820 		gl.glTexParameterIiv(m_target, m_pname, &skipDecode);
821 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIiv");
822 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_SKIP_DECODE_EXT, m_type);
823 
824 		gl.glTexParameterIiv(m_target, m_pname, &decode);
825 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIiv");
826 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_DECODE_EXT, m_type);
827 	}
828 
829 	if (isPureUintTester(m_tester))
830 	{
831 		const glw::GLuint skipDecode	= GL_SKIP_DECODE_EXT;
832 		const glw::GLuint decode		= GL_DECODE_EXT;
833 
834 		gl.glTexParameterIuiv(m_target, m_pname, &skipDecode);
835 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIuiv");
836 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_SKIP_DECODE_EXT, m_type);
837 
838 		gl.glTexParameterIuiv(m_target, m_pname, &decode);
839 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIuiv");
840 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_DECODE_EXT, m_type);
841 	}
842 }
843 
844 class TextureSwizzleCase : public TextureTest
845 {
846 public:
847 			TextureSwizzleCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type);
848 	void	test				(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
849 };
850 
TextureSwizzleCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,TesterType tester,QueryType type)851 TextureSwizzleCase::TextureSwizzleCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type)
852 	: TextureTest(testCtx, renderCtx, name, desc, target, tester, type)
853 {
854 }
855 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const856 void TextureSwizzleCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
857 {
858 	const bool	isPureCase		= isPureIntTester(m_tester) || isPureUintTester(m_tester);
859 	const int	initialValue	= (m_pname == GL_TEXTURE_SWIZZLE_R) ? (GL_RED) :
860 								  (m_pname == GL_TEXTURE_SWIZZLE_G) ? (GL_GREEN) :
861 								  (m_pname == GL_TEXTURE_SWIZZLE_B) ? (GL_BLUE) :
862 								  (m_pname == GL_TEXTURE_SWIZZLE_A) ? (GL_ALPHA) :
863 								  (-1);
864 
865 	if (!isPureCase)
866 	{
867 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
868 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, initialValue, m_type);
869 	}
870 
871 	{
872 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
873 		const GLenum				swizzleValues[]	= {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA, GL_ZERO, GL_ONE};
874 
875 		if (isPureCase)
876 		{
877 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(swizzleValues); ++ndx)
878 			{
879 				if (isPureIntTester(m_tester))
880 				{
881 					const glw::GLint value = (glw::GLint)swizzleValues[ndx];
882 					gl.glTexParameterIiv(m_target, m_pname, &value);
883 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIiv");
884 				}
885 				else
886 				{
887 					DE_ASSERT(isPureUintTester(m_tester));
888 
889 					const glw::GLuint value = swizzleValues[ndx];
890 					gl.glTexParameterIuiv(m_target, m_pname, &value);
891 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIuiv");
892 				}
893 
894 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, swizzleValues[ndx], m_type);
895 			}
896 		}
897 		else
898 		{
899 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(swizzleValues); ++ndx)
900 			{
901 				gl.glTexParameteri(m_target, m_pname, swizzleValues[ndx]);
902 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameteri");
903 
904 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, swizzleValues[ndx], m_type);
905 			}
906 
907 			//check unit conversions with float
908 
909 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(swizzleValues); ++ndx)
910 			{
911 				gl.glTexParameterf(m_target, m_pname, (GLfloat)swizzleValues[ndx]);
912 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterf");
913 
914 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, swizzleValues[ndx], m_type);
915 			}
916 		}
917 	}
918 }
919 
920 class TextureWrapCase : public TextureTest
921 {
922 public:
923 			TextureWrapCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type);
924 	void	test			(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
925 };
926 
TextureWrapCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,TesterType tester,QueryType type)927 TextureWrapCase::TextureWrapCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type)
928 	: TextureTest(testCtx, renderCtx, name, desc, target, tester, type)
929 {
930 }
931 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const932 void TextureWrapCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
933 {
934 	const bool isPureCase = isPureIntTester(m_tester) || isPureUintTester(m_tester);
935 
936 	if (!isPureCase)
937 	{
938 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
939 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_REPEAT, m_type);
940 	}
941 
942 	{
943 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
944 		const GLenum				wrapValues[]	= {GL_CLAMP_TO_EDGE, GL_REPEAT, GL_MIRRORED_REPEAT};
945 
946 		if (isPureCase)
947 		{
948 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(wrapValues); ++ndx)
949 			{
950 				if (isPureIntTester(m_tester))
951 				{
952 					const glw::GLint value = (glw::GLint)wrapValues[ndx];
953 					gl.glTexParameterIiv(m_target, m_pname, &value);
954 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIiv");
955 				}
956 				else
957 				{
958 					DE_ASSERT(isPureUintTester(m_tester));
959 
960 					const glw::GLuint value = wrapValues[ndx];
961 					gl.glTexParameterIuiv(m_target, m_pname, &value);
962 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIuiv");
963 				}
964 
965 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, wrapValues[ndx], m_type);
966 			}
967 		}
968 		else
969 		{
970 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(wrapValues); ++ndx)
971 			{
972 				gl.glTexParameteri(m_target, m_pname, wrapValues[ndx]);
973 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameteri");
974 
975 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, wrapValues[ndx], m_type);
976 			}
977 
978 			//check unit conversions with float
979 
980 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(wrapValues); ++ndx)
981 			{
982 				gl.glTexParameterf(m_target, m_pname, (GLfloat)wrapValues[ndx]);
983 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterf");
984 
985 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, wrapValues[ndx], m_type);
986 			}
987 		}
988 	}
989 }
990 
991 class TextureFilterCase : public TextureTest
992 {
993 public:
994 			TextureFilterCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type);
995 	void	test				(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
996 };
997 
TextureFilterCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,TesterType tester,QueryType type)998 TextureFilterCase::TextureFilterCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type)
999 	: TextureTest(testCtx, renderCtx, name, desc, target, tester, type)
1000 {
1001 }
1002 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const1003 void TextureFilterCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
1004 {
1005 	const bool			isPureCase	= isPureIntTester(m_tester) || isPureUintTester(m_tester);
1006 	const glw::GLenum	initial		= (m_pname == GL_TEXTURE_MAG_FILTER) ? (GL_LINEAR)
1007 									: (m_pname == GL_TEXTURE_MIN_FILTER) ? (GL_NEAREST_MIPMAP_LINEAR)
1008 									: (0);
1009 
1010 	if (!isPureCase)
1011 	{
1012 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
1013 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, initial, m_type);
1014 	}
1015 
1016 	{
1017 		const tcu::ScopedLogSection	section		(m_testCtx.getLog(), "Set", "Set");
1018 		std::vector<GLenum>			values;
1019 
1020 		values.push_back(GL_NEAREST);
1021 		values.push_back(GL_LINEAR);
1022 		if (m_pname == GL_TEXTURE_MIN_FILTER)
1023 		{
1024 			values.push_back(GL_NEAREST_MIPMAP_NEAREST);
1025 			values.push_back(GL_NEAREST_MIPMAP_LINEAR);
1026 			values.push_back(GL_LINEAR_MIPMAP_NEAREST);
1027 			values.push_back(GL_LINEAR_MIPMAP_LINEAR);
1028 		}
1029 
1030 		if (isPureCase)
1031 		{
1032 			for (int ndx = 0; ndx < (int)values.size(); ++ndx)
1033 			{
1034 				if (isPureIntTester(m_tester))
1035 				{
1036 					const glw::GLint value = (glw::GLint)values[ndx];
1037 					gl.glTexParameterIiv(m_target, m_pname, &value);
1038 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIiv");
1039 				}
1040 				else
1041 				{
1042 					DE_ASSERT(isPureUintTester(m_tester));
1043 
1044 					const glw::GLuint value = values[ndx];
1045 					gl.glTexParameterIuiv(m_target, m_pname, &value);
1046 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIuiv");
1047 				}
1048 
1049 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, values[ndx], m_type);
1050 			}
1051 		}
1052 		else
1053 		{
1054 			for (int ndx = 0; ndx < (int)values.size(); ++ndx)
1055 			{
1056 				gl.glTexParameteri(m_target, m_pname, values[ndx]);
1057 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameteri");
1058 
1059 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, values[ndx], m_type);
1060 			}
1061 
1062 			//check unit conversions with float
1063 
1064 			for (int ndx = 0; ndx < (int)values.size(); ++ndx)
1065 			{
1066 				gl.glTexParameterf(m_target, m_pname, (GLfloat)values[ndx]);
1067 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterf");
1068 
1069 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, values[ndx], m_type);
1070 			}
1071 		}
1072 	}
1073 }
1074 
1075 class TextureLODCase : public TextureTest
1076 {
1077 public:
1078 			TextureLODCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type);
1079 	void	test			(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
1080 };
1081 
TextureLODCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,TesterType tester,QueryType type)1082 TextureLODCase::TextureLODCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type)
1083 	: TextureTest(testCtx, renderCtx, name, desc, target, tester, type)
1084 {
1085 }
1086 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const1087 void TextureLODCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
1088 {
1089 	const bool	isPureCase		= isPureIntTester(m_tester) || isPureUintTester(m_tester);
1090 	const int	initialValue 	= (m_pname == GL_TEXTURE_MIN_LOD) ? (-1000)
1091 								: (m_pname == GL_TEXTURE_MAX_LOD) ? (1000)
1092 								: (-1);
1093 
1094 	if ((querySupportsSigned(m_type) || initialValue >= 0) && !isPureCase)
1095 	{
1096 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
1097 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, initialValue, m_type);
1098 	}
1099 
1100 	{
1101 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
1102 		const int					numIterations	= 20;
1103 		de::Random					rnd				(0xabcdef);
1104 
1105 		if (isPureCase)
1106 		{
1107 			if (isPureIntTester(m_tester))
1108 			{
1109 				for (int ndx = 0; ndx < numIterations; ++ndx)
1110 				{
1111 					const GLint ref = rnd.getInt(-1000, 1000);
1112 
1113 					gl.glTexParameterIiv(m_target, m_pname, &ref);
1114 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIiv");
1115 
1116 					verifyStateTextureParamFloat(result, gl, m_target, m_pname, (float)ref, m_type);
1117 				}
1118 			}
1119 			else
1120 			{
1121 				DE_ASSERT(isPureUintTester(m_tester));
1122 
1123 				for (int ndx = 0; ndx < numIterations; ++ndx)
1124 				{
1125 					const GLuint ref = (glw::GLuint)rnd.getInt(0, 1000);
1126 
1127 					gl.glTexParameterIuiv(m_target, m_pname, &ref);
1128 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIuiv");
1129 
1130 					verifyStateTextureParamFloat(result, gl, m_target, m_pname, (float)ref, m_type);
1131 				}
1132 			}
1133 		}
1134 		else
1135 		{
1136 			const int minLimit = (querySupportsSigned(m_type)) ? (-1000) : (0);
1137 
1138 			for (int ndx = 0; ndx < numIterations; ++ndx)
1139 			{
1140 				const GLfloat ref = rnd.getFloat((float)minLimit, 1000.f);
1141 
1142 				gl.glTexParameterf(m_target, m_pname, ref);
1143 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterf");
1144 
1145 				verifyStateTextureParamFloat(result, gl, m_target, m_pname, ref, m_type);
1146 			}
1147 
1148 			// check unit conversions with int
1149 
1150 			for (int ndx = 0; ndx < numIterations; ++ndx)
1151 			{
1152 				const GLint ref = rnd.getInt(minLimit, 1000);
1153 
1154 				gl.glTexParameteri(m_target, m_pname, ref);
1155 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameteri");
1156 
1157 				verifyStateTextureParamFloat(result, gl, m_target, m_pname, (float)ref, m_type);
1158 			}
1159 		}
1160 	}
1161 }
1162 
1163 class TextureLevelCase : public TextureTest
1164 {
1165 public:
1166 			TextureLevelCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type);
1167 	void	test				(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
1168 };
1169 
TextureLevelCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,TesterType tester,QueryType type)1170 TextureLevelCase::TextureLevelCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type)
1171 	: TextureTest(testCtx, renderCtx, name, desc, target, tester, type)
1172 {
1173 }
1174 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const1175 void TextureLevelCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
1176 {
1177 	const bool	isPureCase		= isPureIntTester(m_tester) || isPureUintTester(m_tester);
1178 	const int	initialValue	= (m_pname == GL_TEXTURE_BASE_LEVEL) ? (0)
1179 								: (m_pname == GL_TEXTURE_MAX_LEVEL)	? (1000)
1180 								: (-1);
1181 
1182 	if (!isPureCase)
1183 	{
1184 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
1185 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, initialValue, m_type);
1186 	}
1187 
1188 	if (m_target == GL_TEXTURE_2D_MULTISAMPLE		||
1189 		m_target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)
1190 	{
1191 		// only 0 allowed
1192 		{
1193 			const tcu::ScopedLogSection section(m_testCtx.getLog(), "Set", "Set");
1194 
1195 			gl.glTexParameteri(m_target, m_pname, 0);
1196 			GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameteri");
1197 			verifyStateTextureParamInteger(result, gl, m_target, m_pname, 0, m_type);
1198 
1199 			gl.glTexParameterf(m_target, m_pname, 0.0f);
1200 			GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterf");
1201 			verifyStateTextureParamInteger(result, gl, m_target, m_pname, 0, m_type);
1202 		}
1203 	}
1204 	else
1205 	{
1206 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
1207 		const int					numIterations	= 20;
1208 		de::Random					rnd				(0xabcdef);
1209 
1210 		if (isPureCase)
1211 		{
1212 			for (int ndx = 0; ndx < numIterations; ++ndx)
1213 			{
1214 				const GLint		ref		= rnd.getInt(0, 64000);
1215 				const GLuint	uRef	= (glw::GLuint)ref;
1216 
1217 				if (isPureIntTester(m_tester))
1218 				{
1219 					gl.glTexParameterIiv(m_target, m_pname, &ref);
1220 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIiv");
1221 				}
1222 				else
1223 				{
1224 					DE_ASSERT(isPureUintTester(m_tester));
1225 					gl.glTexParameterIuiv(m_target, m_pname, &uRef);
1226 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIuiv");
1227 				}
1228 
1229 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, ref, m_type);
1230 			}
1231 		}
1232 		else
1233 		{
1234 			for (int ndx = 0; ndx < numIterations; ++ndx)
1235 			{
1236 				const GLint ref = rnd.getInt(0, 64000);
1237 
1238 				gl.glTexParameteri(m_target, m_pname, ref);
1239 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameteri");
1240 
1241 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, ref, m_type);
1242 			}
1243 
1244 			// check unit conversions with float
1245 
1246 			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
1247 
1248 			const int numConversionIterations = 30;
1249 			for (int ndx = 0; ndx < numConversionIterations; ++ndx)
1250 			{
1251 				const GLint ref = rnd.getInt(1, 64000);
1252 
1253 				for (int offsetNdx = 0; offsetNdx < DE_LENGTH_OF_ARRAY(nonSignificantOffsets); ++offsetNdx)
1254 				{
1255 					gl.glTexParameterf(m_target, m_pname, ((GLfloat)ref) + nonSignificantOffsets[offsetNdx]);
1256 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterf");
1257 
1258 					verifyStateTextureParamInteger(result, gl, m_target, m_pname, ref, m_type);
1259 				}
1260 			}
1261 		}
1262 	}
1263 }
1264 
1265 class TextureCompareModeCase : public TextureTest
1266 {
1267 public:
1268 			TextureCompareModeCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type);
1269 	void	test					(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
1270 };
1271 
TextureCompareModeCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,TesterType tester,QueryType type)1272 TextureCompareModeCase::TextureCompareModeCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type)
1273 	: TextureTest(testCtx, renderCtx, name, desc, target, tester, type)
1274 {
1275 }
1276 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const1277 void TextureCompareModeCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
1278 {
1279 	const bool isPureCase = isPureIntTester(m_tester) || isPureUintTester(m_tester);
1280 
1281 	if (!isPureCase)
1282 	{
1283 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
1284 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_NONE, m_type);
1285 	}
1286 
1287 	{
1288 		const tcu::ScopedLogSection	section		(m_testCtx.getLog(), "Set", "Set");
1289 		const GLenum				modes[]		= {GL_COMPARE_REF_TO_TEXTURE, GL_NONE};
1290 
1291 		if (isPureCase)
1292 		{
1293 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(modes); ++ndx)
1294 			{
1295 				if (isPureIntTester(m_tester))
1296 				{
1297 					const glw::GLint value = (glw::GLint)modes[ndx];
1298 					gl.glTexParameterIiv(m_target, m_pname, &value);
1299 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIiv");
1300 				}
1301 				else
1302 				{
1303 					DE_ASSERT(isPureUintTester(m_tester));
1304 
1305 					const glw::GLuint value = modes[ndx];
1306 					gl.glTexParameterIuiv(m_target, m_pname, &value);
1307 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIuiv");
1308 				}
1309 
1310 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, modes[ndx], m_type);
1311 			}
1312 		}
1313 		else
1314 		{
1315 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(modes); ++ndx)
1316 			{
1317 				gl.glTexParameteri(m_target, m_pname, modes[ndx]);
1318 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameteri");
1319 
1320 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, modes[ndx], m_type);
1321 			}
1322 
1323 			//check unit conversions with float
1324 
1325 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(modes); ++ndx)
1326 			{
1327 				gl.glTexParameterf(m_target, m_pname, (GLfloat)modes[ndx]);
1328 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterf");
1329 
1330 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, modes[ndx], m_type);
1331 			}
1332 		}
1333 	}
1334 }
1335 
1336 class TextureCompareFuncCase : public TextureTest
1337 {
1338 public:
1339 			TextureCompareFuncCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type);
1340 	void	test					(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
1341 };
1342 
TextureCompareFuncCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,TesterType tester,QueryType type)1343 TextureCompareFuncCase::TextureCompareFuncCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type)
1344 	: TextureTest(testCtx, renderCtx, name, desc, target, tester, type)
1345 {
1346 }
1347 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const1348 void TextureCompareFuncCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
1349 {
1350 	const bool isPureCase = isPureIntTester(m_tester) || isPureUintTester(m_tester);
1351 
1352 	if (!isPureCase)
1353 	{
1354 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
1355 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_LEQUAL, m_type);
1356 	}
1357 
1358 	{
1359 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
1360 		const GLenum				compareFuncs[]	= {GL_LEQUAL, GL_GEQUAL, GL_LESS, GL_GREATER, GL_EQUAL, GL_NOTEQUAL, GL_ALWAYS, GL_NEVER};
1361 
1362 		if (isPureCase)
1363 		{
1364 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(compareFuncs); ++ndx)
1365 			{
1366 				if (isPureIntTester(m_tester))
1367 				{
1368 					const glw::GLint value = (glw::GLint)compareFuncs[ndx];
1369 					gl.glTexParameterIiv(m_target, m_pname, &value);
1370 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIiv");
1371 				}
1372 				else
1373 				{
1374 					DE_ASSERT(isPureUintTester(m_tester));
1375 
1376 					const glw::GLuint value = compareFuncs[ndx];
1377 					gl.glTexParameterIuiv(m_target, m_pname, &value);
1378 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIuiv");
1379 				}
1380 
1381 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, compareFuncs[ndx], m_type);
1382 			}
1383 		}
1384 		else
1385 		{
1386 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(compareFuncs); ++ndx)
1387 			{
1388 				gl.glTexParameteri(m_target, m_pname, compareFuncs[ndx]);
1389 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameteri");
1390 
1391 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, compareFuncs[ndx], m_type);
1392 			}
1393 
1394 			//check unit conversions with float
1395 
1396 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(compareFuncs); ++ndx)
1397 			{
1398 				gl.glTexParameterf(m_target, m_pname, (GLfloat)compareFuncs[ndx]);
1399 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterf");
1400 
1401 				verifyStateTextureParamInteger(result, gl, m_target, m_pname, compareFuncs[ndx], m_type);
1402 			}
1403 		}
1404 	}
1405 }
1406 
1407 class TextureImmutableLevelsCase : public TextureTest
1408 {
1409 public:
1410 			TextureImmutableLevelsCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, QueryType type);
1411 	void	test						(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
1412 };
1413 
TextureImmutableLevelsCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,QueryType type)1414 TextureImmutableLevelsCase::TextureImmutableLevelsCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, QueryType type)
1415 	: TextureTest(testCtx, renderCtx, name, desc, target, TESTER_TEXTURE_IMMUTABLE_LEVELS, type)
1416 {
1417 }
1418 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const1419 void TextureImmutableLevelsCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
1420 {
1421 	{
1422 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
1423 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, 0, m_type);
1424 	}
1425 
1426 	if (m_target == GL_TEXTURE_2D_MULTISAMPLE		||
1427 		m_target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)
1428 	{
1429 		// no levels
1430 		const tcu::ScopedLogSection	section		(m_testCtx.getLog(), "Level", "Level");
1431 		GLuint						textureID	= 0;
1432 
1433 		gl.glGenTextures(1, &textureID);
1434 		gl.glBindTexture(m_target, textureID);
1435 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glBindTexture");
1436 
1437 		if (m_target == GL_TEXTURE_2D_MULTISAMPLE)
1438 			gl.glTexStorage2DMultisample(m_target, 2, GL_RGB8, 64, 64, GL_FALSE);
1439 		else if (m_target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)
1440 			gl.glTexStorage3DMultisample(m_target, 2, GL_RGB8, 64, 64, 2, GL_FALSE);
1441 		else
1442 			DE_ASSERT(false);
1443 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexStorage");
1444 
1445 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, 1, m_type);
1446 
1447 		gl.glDeleteTextures(1, &textureID);
1448 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glDeleteTextures");
1449 	}
1450 	else
1451 	{
1452 		for (int level = 1; level <= 7; ++level)
1453 		{
1454 			const tcu::ScopedLogSection	section		(m_testCtx.getLog(), "Levels", "Levels = " + de::toString(level));
1455 			GLuint						textureID	= 0;
1456 
1457 			gl.glGenTextures(1, &textureID);
1458 			gl.glBindTexture(m_target, textureID);
1459 			GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glBindTexture");
1460 
1461 			if (m_target == GL_TEXTURE_2D || m_target == GL_TEXTURE_CUBE_MAP)
1462 				gl.glTexStorage2D(m_target, level, GL_RGB8, 64, 64);
1463 			else if (m_target == GL_TEXTURE_2D_ARRAY || m_target == GL_TEXTURE_3D)
1464 				gl.glTexStorage3D(m_target, level, GL_RGB8, 64, 64, 64);
1465 			else if (m_target == GL_TEXTURE_CUBE_MAP_ARRAY)
1466 				gl.glTexStorage3D(m_target, level, GL_RGB8, 64, 64, 6 * 2);
1467 			else
1468 				DE_ASSERT(false);
1469 			GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexStorage");
1470 
1471 			verifyStateTextureParamInteger(result, gl, m_target, m_pname, level, m_type);
1472 
1473 			gl.glDeleteTextures(1, &textureID);
1474 			GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glDeleteTextures");
1475 		}
1476 	}
1477 }
1478 
1479 class TextureImmutableFormatCase : public TextureTest
1480 {
1481 public:
1482 			TextureImmutableFormatCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, QueryType type);
1483 	void	test						(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
1484 };
1485 
TextureImmutableFormatCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,QueryType type)1486 TextureImmutableFormatCase::TextureImmutableFormatCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, QueryType type)
1487 	: TextureTest(testCtx, renderCtx, name, desc, target, TESTER_TEXTURE_IMMUTABLE_FORMAT, type)
1488 {
1489 }
1490 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const1491 void TextureImmutableFormatCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
1492 {
1493 	{
1494 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
1495 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, 0, m_type);
1496 	}
1497 
1498 	{
1499 		const tcu::ScopedLogSection	subsection	(m_testCtx.getLog(), "Immutable", "Immutable");
1500 		GLuint						textureID	= 0;
1501 
1502 		gl.glGenTextures(1, &textureID);
1503 		gl.glBindTexture(m_target, textureID);
1504 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glBindTexture");
1505 
1506 		switch (m_target)
1507 		{
1508 			case GL_TEXTURE_2D:
1509 			case GL_TEXTURE_CUBE_MAP:
1510 			{
1511 				gl.glTexStorage2D(m_target, 1, GL_RGBA8, 32, 32);
1512 				break;
1513 			}
1514 			case GL_TEXTURE_2D_ARRAY:
1515 			case GL_TEXTURE_3D:
1516 			{
1517 				gl.glTexStorage3D(m_target, 1, GL_RGBA8, 32, 32, 8);
1518 				break;
1519 			}
1520 			case GL_TEXTURE_2D_MULTISAMPLE:
1521 			{
1522 				gl.glTexStorage2DMultisample(m_target, 2, GL_RGB8, 64, 64, GL_FALSE);
1523 				break;
1524 			}
1525 			case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
1526 			{
1527 				gl.glTexStorage3DMultisample(m_target, 2, GL_RGB8, 64, 64, 2, GL_FALSE);
1528 				break;
1529 			}
1530 			case GL_TEXTURE_CUBE_MAP_ARRAY:
1531 			{
1532 				gl.glTexStorage3D(m_target, 1, GL_RGBA8, 32, 32, 6 * 2);
1533 				break;
1534 			}
1535 			default:
1536 				DE_ASSERT(false);
1537 		}
1538 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "setup texture");
1539 
1540 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, 1, m_type);
1541 
1542 		gl.glDeleteTextures(1, &textureID);
1543 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glDeleteTextures");
1544 	}
1545 
1546 	// no mutable
1547 	if (m_target == GL_TEXTURE_2D_MULTISAMPLE ||
1548 		m_target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)
1549 		return;
1550 
1551 	// test mutable
1552 	{
1553 		const tcu::ScopedLogSection	subsection		(m_testCtx.getLog(), "Mutable", "Mutable");
1554 		GLuint						textureID		= 0;
1555 
1556 		gl.glGenTextures(1, &textureID);
1557 		gl.glBindTexture(m_target, textureID);
1558 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glBindTexture");
1559 
1560 		switch (m_target)
1561 		{
1562 			case GL_TEXTURE_2D:
1563 			{
1564 				gl.glTexImage2D(m_target, 0, GL_RGBA8, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
1565 				break;
1566 			}
1567 			case GL_TEXTURE_CUBE_MAP:
1568 			{
1569 				gl.glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA8, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
1570 				break;
1571 			}
1572 			case GL_TEXTURE_2D_ARRAY:
1573 			case GL_TEXTURE_3D:
1574 			{
1575 				gl.glTexImage3D(m_target, 0, GL_RGBA8, 32, 32, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
1576 				break;
1577 			}
1578 			case GL_TEXTURE_CUBE_MAP_ARRAY:
1579 			{
1580 				gl.glTexImage3D(m_target, 0, GL_RGBA8, 32, 32, 6 * 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
1581 				break;
1582 			}
1583 			default:
1584 				DE_ASSERT(false);
1585 		}
1586 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "setup texture");
1587 
1588 		verifyStateTextureParamInteger(result, gl, m_target, m_pname, 0, m_type);
1589 
1590 		gl.glDeleteTextures(1, &textureID);
1591 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glDeleteTextures");
1592 	}
1593 }
1594 
1595 class TextureWrapClampToBorderCase : public TextureTest
1596 {
1597 public:
1598 			TextureWrapClampToBorderCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type);
1599 	void	test							(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
1600 };
1601 
TextureWrapClampToBorderCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,TesterType tester,QueryType type)1602 TextureWrapClampToBorderCase::TextureWrapClampToBorderCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, TesterType tester, QueryType type)
1603 	: TextureTest(testCtx, renderCtx, name, desc, target, tester, type)
1604 {
1605 }
1606 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const1607 void TextureWrapClampToBorderCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
1608 {
1609 	gl.glTexParameteri(m_target, m_pname, GL_CLAMP_TO_BORDER_EXT);
1610 	GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameteri");
1611 	verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_CLAMP_TO_BORDER_EXT, m_type);
1612 
1613 	gl.glTexParameteri(m_target, m_pname, GL_REPEAT);
1614 	GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameteri");
1615 
1616 	gl.glTexParameterf(m_target, m_pname, (GLfloat)GL_CLAMP_TO_BORDER_EXT);
1617 	GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterf");
1618 
1619 	verifyStateTextureParamInteger(result, gl, m_target, m_pname, GL_CLAMP_TO_BORDER_EXT, m_type);
1620 }
1621 
1622 class TextureBorderColorCase : public TextureTest
1623 {
1624 public:
1625 			TextureBorderColorCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, glw::GLenum target, QueryType type);
1626 	void	test					(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
1627 };
1628 
TextureBorderColorCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,glw::GLenum target,QueryType type)1629 TextureBorderColorCase::TextureBorderColorCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, glw::GLenum target, QueryType type)
1630 	: TextureTest(testCtx, renderCtx, name, desc, target, TESTER_TEXTURE_BORDER_COLOR, type)
1631 {
1632 }
1633 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const1634 void TextureBorderColorCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
1635 {
1636 	// border color is undefined if queried with pure type and was not set to pure value
1637 	if (m_type == QUERY_TEXTURE_PARAM_INTEGER_VEC4 || m_type == QUERY_TEXTURE_PARAM_FLOAT_VEC4)
1638 	{
1639 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
1640 		verifyStateTextureParamFloatVec4(result, gl, m_target, m_pname, tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), m_type);
1641 	}
1642 
1643 	if (m_type == QUERY_TEXTURE_PARAM_PURE_INTEGER_VEC4)
1644 	{
1645 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
1646 		const tcu::IVec4			color			(0x7FFFFFFF, -2, 3, -128);
1647 
1648 		gl.glTexParameterIiv(m_target, m_pname, color.getPtr());
1649 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIiv");
1650 
1651 		verifyStateTextureParamIntegerVec4(result, gl, m_target, m_pname, color, m_type);
1652 	}
1653 	else if (m_type == QUERY_TEXTURE_PARAM_PURE_UNSIGNED_INTEGER_VEC4)
1654 	{
1655 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
1656 		const tcu::UVec4			color			(0x8000000ul, 2, 3, 128);
1657 
1658 		gl.glTexParameterIuiv(m_target, m_pname, color.getPtr());
1659 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterIuiv");
1660 
1661 		verifyStateTextureParamUnsignedIntegerVec4(result, gl, m_target, m_pname, color, m_type);
1662 	}
1663 	else
1664 	{
1665 		DE_ASSERT(m_type == QUERY_TEXTURE_PARAM_INTEGER_VEC4 || m_type == QUERY_TEXTURE_PARAM_FLOAT_VEC4);
1666 
1667 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
1668 		const tcu::Vec4				color			(0.25f, 1.0f, 0.0f, 0.77f);
1669 		const tcu::IVec4			icolor			(0x8000000ul, 0x7FFFFFFF, 0, 0x0FFFFFFF);
1670 
1671 		gl.glTexParameterfv(m_target, m_pname, color.getPtr());
1672 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameterfv");
1673 
1674 		verifyStateTextureParamFloatVec4(result, gl, m_target, m_pname, color, m_type);
1675 
1676 		gl.glTexParameteriv(m_target, m_pname, icolor.getPtr());
1677 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glTexParameteriv");
1678 
1679 		verifyStateTextureParamNormalizedI32Vec4(result, gl, m_target, m_pname, icolor, m_type);
1680 	}
1681 }
1682 
1683 class SamplerTest : public tcu::TestCase
1684 {
1685 public:
1686 						SamplerTest	(tcu::TestContext&			testCtx,
1687 									 const glu::RenderContext&	renderCtx,
1688 									 const char*				name,
1689 									 const char*				desc,
1690 									 TesterType					tester,
1691 									 QueryType					type);
1692 
1693 	void				init		(void);
1694 	IterateResult		iterate		(void);
1695 
1696 	virtual void		test		(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const = 0;
1697 
1698 protected:
1699 	const glu::RenderContext&	m_renderCtx;
1700 	const glw::GLenum			m_pname;
1701 	const TesterType			m_tester;
1702 	const QueryType				m_type;
1703 	glw::GLuint					m_target;
1704 };
1705 
SamplerTest(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,TesterType tester,QueryType type)1706 SamplerTest::SamplerTest (tcu::TestContext&			testCtx,
1707 						  const glu::RenderContext&	renderCtx,
1708 						  const char*				name,
1709 						  const char*				desc,
1710 						  TesterType				tester,
1711 						  QueryType					type)
1712 	: TestCase		(testCtx, name, desc)
1713 	, m_renderCtx	(renderCtx)
1714 	, m_pname		(mapTesterToPname(tester))
1715 	, m_tester		(tester)
1716 	, m_type		(type)
1717 	, m_target		(0)
1718 {
1719 }
1720 
init(void)1721 void SamplerTest::init (void)
1722 {
1723 	const de::UniquePtr<glu::ContextInfo>	ctxInfo		(glu::ContextInfo::create(m_renderCtx));
1724 	RequiredExtensions						extensions;
1725 
1726 	// param
1727 	if (!isCoreTextureParam(m_renderCtx.getType(), m_pname))
1728 		extensions.add(getTextureParamExtension(m_renderCtx.getType(), m_pname));
1729 
1730 	// query
1731 	if (!isCoreQuery(m_renderCtx.getType(), m_type))
1732 		extensions.add(getQueryExtension(m_renderCtx.getType(), m_type));
1733 
1734 	// test type
1735 	if (!isCoreTester(m_renderCtx.getType(), m_tester))
1736 		extensions.add(getTesterExtension(m_renderCtx.getType(), m_tester));
1737 
1738 	extensions.check(*ctxInfo);
1739 }
1740 
iterate(void)1741 SamplerTest::IterateResult SamplerTest::iterate (void)
1742 {
1743 	glu::CallLogWrapper		gl		(m_renderCtx.getFunctions(), m_testCtx.getLog());
1744 	tcu::ResultCollector	result	(m_testCtx.getLog(), " // ERROR: ");
1745 	glu::Sampler			sampler	(m_renderCtx);
1746 
1747 	gl.enableLogging(true);
1748 
1749 	m_target = *sampler;
1750 	test(gl, result);
1751 	m_target = 0;
1752 
1753 	result.setTestContextResult(m_testCtx);
1754 	return STOP;
1755 }
1756 
1757 class SamplerWrapCase : public SamplerTest
1758 {
1759 public:
1760 			SamplerWrapCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, TesterType tester, QueryType type);
1761 	void	test			(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
1762 };
1763 
SamplerWrapCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,TesterType tester,QueryType type)1764 SamplerWrapCase::SamplerWrapCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, TesterType tester, QueryType type)
1765 	: SamplerTest(testCtx, renderCtx, name, desc, tester, type)
1766 {
1767 }
1768 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const1769 void SamplerWrapCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
1770 {
1771 	const bool isPureCase = isPureIntTester(m_tester) || isPureUintTester(m_tester);
1772 
1773 	if (!isPureCase)
1774 	{
1775 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
1776 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_REPEAT, m_type);
1777 	}
1778 
1779 	{
1780 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
1781 		const GLenum				wrapValues[]	= {GL_CLAMP_TO_EDGE, GL_REPEAT, GL_MIRRORED_REPEAT};
1782 
1783 		if (isPureCase)
1784 		{
1785 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(wrapValues); ++ndx)
1786 			{
1787 				if (isPureIntTester(m_tester))
1788 				{
1789 					const glw::GLint value = (glw::GLint)wrapValues[ndx];
1790 					gl.glSamplerParameterIiv(m_target, m_pname, &value);
1791 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIiv");
1792 				}
1793 				else
1794 				{
1795 					DE_ASSERT(isPureUintTester(m_tester));
1796 
1797 					const glw::GLuint value = wrapValues[ndx];
1798 					gl.glSamplerParameterIuiv(m_target, m_pname, &value);
1799 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIuiv");
1800 				}
1801 
1802 				verifyStateSamplerParamInteger(result, gl, m_target, m_pname, wrapValues[ndx], m_type);
1803 			}
1804 		}
1805 		else
1806 		{
1807 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(wrapValues); ++ndx)
1808 			{
1809 				gl.glSamplerParameteri(m_target, m_pname, wrapValues[ndx]);
1810 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameteri");
1811 
1812 				verifyStateSamplerParamInteger(result, gl, m_target, m_pname, wrapValues[ndx], m_type);
1813 			}
1814 
1815 			//check unit conversions with float
1816 
1817 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(wrapValues); ++ndx)
1818 			{
1819 				gl.glSamplerParameterf(m_target, m_pname, (GLfloat)wrapValues[ndx]);
1820 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterf");
1821 
1822 				verifyStateSamplerParamInteger(result, gl, m_target, m_pname, wrapValues[ndx], m_type);
1823 			}
1824 		}
1825 	}
1826 }
1827 
1828 class SamplerFilterCase : public SamplerTest
1829 {
1830 public:
1831 			SamplerFilterCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, TesterType tester, QueryType type);
1832 	void	test				(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
1833 };
1834 
SamplerFilterCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,TesterType tester,QueryType type)1835 SamplerFilterCase::SamplerFilterCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, TesterType tester, QueryType type)
1836 	: SamplerTest(testCtx, renderCtx, name, desc, tester, type)
1837 {
1838 }
1839 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const1840 void SamplerFilterCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
1841 {
1842 	const bool			isPureCase	= isPureIntTester(m_tester) || isPureUintTester(m_tester);
1843 	const glw::GLenum	initial		= (m_pname == GL_TEXTURE_MAG_FILTER) ? (GL_LINEAR)
1844 									: (m_pname == GL_TEXTURE_MIN_FILTER) ? (GL_NEAREST_MIPMAP_LINEAR)
1845 									: (0);
1846 
1847 	if (!isPureCase)
1848 	{
1849 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
1850 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, initial, m_type);
1851 	}
1852 
1853 	{
1854 		const tcu::ScopedLogSection	section		(m_testCtx.getLog(), "Set", "Set");
1855 		std::vector<GLenum>			values;
1856 
1857 		values.push_back(GL_NEAREST);
1858 		values.push_back(GL_LINEAR);
1859 		if (m_pname == GL_TEXTURE_MIN_FILTER)
1860 		{
1861 			values.push_back(GL_NEAREST_MIPMAP_NEAREST);
1862 			values.push_back(GL_NEAREST_MIPMAP_LINEAR);
1863 			values.push_back(GL_LINEAR_MIPMAP_NEAREST);
1864 			values.push_back(GL_LINEAR_MIPMAP_LINEAR);
1865 		}
1866 
1867 		if (isPureCase)
1868 		{
1869 			for (int ndx = 0; ndx < (int)values.size(); ++ndx)
1870 			{
1871 				if (isPureIntTester(m_tester))
1872 				{
1873 					const glw::GLint value = (glw::GLint)values[ndx];
1874 					gl.glSamplerParameterIiv(m_target, m_pname, &value);
1875 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIiv");
1876 				}
1877 				else
1878 				{
1879 					DE_ASSERT(isPureUintTester(m_tester));
1880 
1881 					const glw::GLuint value = values[ndx];
1882 					gl.glSamplerParameterIuiv(m_target, m_pname, &value);
1883 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIuiv");
1884 				}
1885 
1886 				verifyStateSamplerParamInteger(result, gl, m_target, m_pname, values[ndx], m_type);
1887 			}
1888 		}
1889 		else
1890 		{
1891 			for (int ndx = 0; ndx < (int)values.size(); ++ndx)
1892 			{
1893 				gl.glSamplerParameteri(m_target, m_pname, values[ndx]);
1894 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameteri");
1895 
1896 				verifyStateSamplerParamInteger(result, gl, m_target, m_pname, values[ndx], m_type);
1897 			}
1898 
1899 			//check unit conversions with float
1900 
1901 			for (int ndx = 0; ndx < (int)values.size(); ++ndx)
1902 			{
1903 				gl.glSamplerParameterf(m_target, m_pname, (GLfloat)values[ndx]);
1904 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterf");
1905 
1906 				verifyStateSamplerParamInteger(result, gl, m_target, m_pname, values[ndx], m_type);
1907 			}
1908 		}
1909 	}
1910 }
1911 
1912 class SamplerLODCase : public SamplerTest
1913 {
1914 public:
1915 			SamplerLODCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, TesterType tester, QueryType type);
1916 	void	test			(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
1917 };
1918 
SamplerLODCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,TesterType tester,QueryType type)1919 SamplerLODCase::SamplerLODCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, TesterType tester, QueryType type)
1920 	: SamplerTest(testCtx, renderCtx, name, desc, tester, type)
1921 {
1922 }
1923 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const1924 void SamplerLODCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
1925 {
1926 	const bool	isPureCase		= isPureIntTester(m_tester) || isPureUintTester(m_tester);
1927 	const int	initialValue 	= (m_pname == GL_TEXTURE_MIN_LOD) ? (-1000)
1928 								: (m_pname == GL_TEXTURE_MAX_LOD) ? (1000)
1929 								: (-1);
1930 
1931 	if ((querySupportsSigned(m_type) || initialValue >= 0) && !isPureCase)
1932 	{
1933 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
1934 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, initialValue, m_type);
1935 	}
1936 
1937 	{
1938 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
1939 		const int					numIterations	= 20;
1940 		de::Random					rnd				(0xabcdef);
1941 
1942 		if (isPureCase)
1943 		{
1944 			if (isPureIntTester(m_tester))
1945 			{
1946 				for (int ndx = 0; ndx < numIterations; ++ndx)
1947 				{
1948 					const GLint ref = rnd.getInt(-1000, 1000);
1949 
1950 					gl.glSamplerParameterIiv(m_target, m_pname, &ref);
1951 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIiv");
1952 
1953 					verifyStateSamplerParamFloat(result, gl, m_target, m_pname, (float)ref, m_type);
1954 				}
1955 			}
1956 			else
1957 			{
1958 				DE_ASSERT(isPureUintTester(m_tester));
1959 
1960 				for (int ndx = 0; ndx < numIterations; ++ndx)
1961 				{
1962 					const GLuint ref = (glw::GLuint)rnd.getInt(0, 1000);
1963 
1964 					gl.glSamplerParameterIuiv(m_target, m_pname, &ref);
1965 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIuiv");
1966 
1967 					verifyStateSamplerParamFloat(result, gl, m_target, m_pname, (float)ref, m_type);
1968 				}
1969 			}
1970 		}
1971 		else
1972 		{
1973 			const int minLimit = (querySupportsSigned(m_type)) ? (-1000) : (0);
1974 
1975 			for (int ndx = 0; ndx < numIterations; ++ndx)
1976 			{
1977 				const GLfloat ref = rnd.getFloat((float)minLimit, 1000.f);
1978 
1979 				gl.glSamplerParameterf(m_target, m_pname, ref);
1980 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterf");
1981 
1982 				verifyStateSamplerParamFloat(result, gl, m_target, m_pname, ref, m_type);
1983 			}
1984 
1985 			// check unit conversions with int
1986 
1987 			for (int ndx = 0; ndx < numIterations; ++ndx)
1988 			{
1989 				const GLint ref = rnd.getInt(minLimit, 1000);
1990 
1991 				gl.glSamplerParameteri(m_target, m_pname, ref);
1992 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameteri");
1993 
1994 				verifyStateSamplerParamFloat(result, gl, m_target, m_pname, (float)ref, m_type);
1995 			}
1996 		}
1997 	}
1998 }
1999 
2000 class SamplerCompareModeCase : public SamplerTest
2001 {
2002 public:
2003 			SamplerCompareModeCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, TesterType tester, QueryType type);
2004 	void	test					(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
2005 };
2006 
SamplerCompareModeCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,TesterType tester,QueryType type)2007 SamplerCompareModeCase::SamplerCompareModeCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, TesterType tester, QueryType type)
2008 	: SamplerTest(testCtx, renderCtx, name, desc, tester, type)
2009 {
2010 }
2011 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const2012 void SamplerCompareModeCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
2013 {
2014 	const bool isPureCase = isPureIntTester(m_tester) || isPureUintTester(m_tester);
2015 
2016 	if (!isPureCase)
2017 	{
2018 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
2019 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_NONE, m_type);
2020 	}
2021 
2022 	{
2023 		const tcu::ScopedLogSection	section		(m_testCtx.getLog(), "Set", "Set");
2024 		const GLenum				modes[]		= {GL_COMPARE_REF_TO_TEXTURE, GL_NONE};
2025 
2026 		if (isPureCase)
2027 		{
2028 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(modes); ++ndx)
2029 			{
2030 				if (isPureIntTester(m_tester))
2031 				{
2032 					const glw::GLint value = (glw::GLint)modes[ndx];
2033 					gl.glSamplerParameterIiv(m_target, m_pname, &value);
2034 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIiv");
2035 				}
2036 				else
2037 				{
2038 					DE_ASSERT(isPureUintTester(m_tester));
2039 
2040 					const glw::GLuint value = modes[ndx];
2041 					gl.glSamplerParameterIuiv(m_target, m_pname, &value);
2042 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIuiv");
2043 				}
2044 
2045 				verifyStateSamplerParamInteger(result, gl, m_target, m_pname, modes[ndx], m_type);
2046 			}
2047 		}
2048 		else
2049 		{
2050 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(modes); ++ndx)
2051 			{
2052 				gl.glSamplerParameteri(m_target, m_pname, modes[ndx]);
2053 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameteri");
2054 
2055 				verifyStateSamplerParamInteger(result, gl, m_target, m_pname, modes[ndx], m_type);
2056 			}
2057 
2058 			//check unit conversions with float
2059 
2060 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(modes); ++ndx)
2061 			{
2062 				gl.glSamplerParameterf(m_target, m_pname, (GLfloat)modes[ndx]);
2063 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterf");
2064 
2065 				verifyStateSamplerParamInteger(result, gl, m_target, m_pname, modes[ndx], m_type);
2066 			}
2067 		}
2068 	}
2069 }
2070 
2071 class SamplerCompareFuncCase : public SamplerTest
2072 {
2073 public:
2074 			SamplerCompareFuncCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, TesterType tester, QueryType type);
2075 	void	test					(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
2076 };
2077 
SamplerCompareFuncCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,TesterType tester,QueryType type)2078 SamplerCompareFuncCase::SamplerCompareFuncCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, TesterType tester, QueryType type)
2079 	: SamplerTest(testCtx, renderCtx, name, desc, tester, type)
2080 {
2081 }
2082 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const2083 void SamplerCompareFuncCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
2084 {
2085 	const bool isPureCase = isPureIntTester(m_tester) || isPureUintTester(m_tester);
2086 
2087 	if (!isPureCase)
2088 	{
2089 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
2090 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_LEQUAL, m_type);
2091 	}
2092 
2093 	{
2094 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
2095 		const GLenum				compareFuncs[]	= {GL_LEQUAL, GL_GEQUAL, GL_LESS, GL_GREATER, GL_EQUAL, GL_NOTEQUAL, GL_ALWAYS, GL_NEVER};
2096 
2097 		if (isPureCase)
2098 		{
2099 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(compareFuncs); ++ndx)
2100 			{
2101 				if (isPureIntTester(m_tester))
2102 				{
2103 					const glw::GLint value = (glw::GLint)compareFuncs[ndx];
2104 					gl.glSamplerParameterIiv(m_target, m_pname, &value);
2105 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIiv");
2106 				}
2107 				else
2108 				{
2109 					DE_ASSERT(isPureUintTester(m_tester));
2110 
2111 					const glw::GLuint value = compareFuncs[ndx];
2112 					gl.glSamplerParameterIuiv(m_target, m_pname, &value);
2113 					GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIuiv");
2114 				}
2115 
2116 				verifyStateSamplerParamInteger(result, gl, m_target, m_pname, compareFuncs[ndx], m_type);
2117 			}
2118 		}
2119 		else
2120 		{
2121 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(compareFuncs); ++ndx)
2122 			{
2123 				gl.glSamplerParameteri(m_target, m_pname, compareFuncs[ndx]);
2124 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameteri");
2125 
2126 				verifyStateSamplerParamInteger(result, gl, m_target, m_pname, compareFuncs[ndx], m_type);
2127 			}
2128 
2129 			//check unit conversions with float
2130 
2131 			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(compareFuncs); ++ndx)
2132 			{
2133 				gl.glSamplerParameterf(m_target, m_pname, (GLfloat)compareFuncs[ndx]);
2134 				GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterf");
2135 
2136 				verifyStateSamplerParamInteger(result, gl, m_target, m_pname, compareFuncs[ndx], m_type);
2137 			}
2138 		}
2139 	}
2140 }
2141 
2142 class SamplerWrapClampToBorderCase : public SamplerTest
2143 {
2144 public:
2145 			SamplerWrapClampToBorderCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, TesterType tester, QueryType type);
2146 	void	test							(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
2147 };
2148 
SamplerWrapClampToBorderCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,TesterType tester,QueryType type)2149 SamplerWrapClampToBorderCase::SamplerWrapClampToBorderCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, TesterType tester, QueryType type)
2150 	: SamplerTest(testCtx, renderCtx, name, desc, tester, type)
2151 {
2152 }
2153 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const2154 void SamplerWrapClampToBorderCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
2155 {
2156 	gl.glSamplerParameteri(m_target, m_pname, GL_CLAMP_TO_BORDER_EXT);
2157 	GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameteri");
2158 	verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_CLAMP_TO_BORDER_EXT, m_type);
2159 
2160 	gl.glSamplerParameteri(m_target, m_pname, GL_REPEAT);
2161 	GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameteri");
2162 
2163 	gl.glSamplerParameterf(m_target, m_pname, (GLfloat)GL_CLAMP_TO_BORDER_EXT);
2164 	GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterf");
2165 
2166 	verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_CLAMP_TO_BORDER_EXT, m_type);
2167 }
2168 
2169 class SamplerSRGBDecodeCase : public SamplerTest
2170 {
2171 public:
2172 			SamplerSRGBDecodeCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, TesterType tester, QueryType type);
2173 	void	test					(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
2174 };
2175 
SamplerSRGBDecodeCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,TesterType tester,QueryType type)2176 SamplerSRGBDecodeCase::SamplerSRGBDecodeCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, TesterType tester, QueryType type)
2177 	: SamplerTest(testCtx, renderCtx, name, desc, tester, type)
2178 {
2179 }
2180 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const2181 void SamplerSRGBDecodeCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
2182 {
2183 	const bool isPureCase = isPureIntTester(m_tester) || isPureUintTester(m_tester);
2184 
2185 	if (!isPureCase)
2186 	{
2187 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
2188 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_DECODE_EXT, m_type);
2189 	}
2190 
2191 	{
2192 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Toggle", "Toggle");
2193 		const glw::GLint			decodeInt		= GL_DECODE_EXT;
2194 		const glw::GLfloat			decodeFloat		= (glw::GLfloat)GL_DECODE_EXT;
2195 
2196 		gl.glSamplerParameteri(m_target, m_pname, GL_SKIP_DECODE_EXT);
2197 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "set state");
2198 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_SKIP_DECODE_EXT, m_type);
2199 
2200 		gl.glSamplerParameteriv(m_target, m_pname, &decodeInt);
2201 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "set state");
2202 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_DECODE_EXT, m_type);
2203 
2204 		gl.glSamplerParameterf(m_target, m_pname, GL_SKIP_DECODE_EXT);
2205 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "set state");
2206 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_SKIP_DECODE_EXT, m_type);
2207 
2208 		gl.glSamplerParameterfv(m_target, m_pname, &decodeFloat);
2209 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "set state");
2210 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_DECODE_EXT, m_type);
2211 	}
2212 
2213 	if (isPureIntTester(m_tester))
2214 	{
2215 		const glw::GLint skipDecode	= GL_SKIP_DECODE_EXT;
2216 		const glw::GLint decode		= GL_DECODE_EXT;
2217 
2218 		gl.glSamplerParameterIiv(m_target, m_pname, &skipDecode);
2219 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIiv");
2220 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_SKIP_DECODE_EXT, m_type);
2221 
2222 		gl.glSamplerParameterIiv(m_target, m_pname, &decode);
2223 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIiv");
2224 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_DECODE_EXT, m_type);
2225 	}
2226 
2227 	if (isPureUintTester(m_tester))
2228 	{
2229 		const glw::GLuint skipDecode	= GL_SKIP_DECODE_EXT;
2230 		const glw::GLuint decode		= GL_DECODE_EXT;
2231 
2232 		gl.glSamplerParameterIuiv(m_target, m_pname, &skipDecode);
2233 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIuiv");
2234 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_SKIP_DECODE_EXT, m_type);
2235 
2236 		gl.glSamplerParameterIuiv(m_target, m_pname, &decode);
2237 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIuiv");
2238 		verifyStateSamplerParamInteger(result, gl, m_target, m_pname, GL_DECODE_EXT, m_type);
2239 	}
2240 }
2241 
2242 class SamplerBorderColorCase : public SamplerTest
2243 {
2244 public:
2245 			SamplerBorderColorCase	(tcu::TestContext& testCtx, const glu::RenderContext& renderContext, const char* name, const char* desc, QueryType type);
2246 	void	test					(glu::CallLogWrapper& gl, tcu::ResultCollector& result) const;
2247 };
2248 
SamplerBorderColorCase(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const char * name,const char * desc,QueryType type)2249 SamplerBorderColorCase::SamplerBorderColorCase (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const char* name, const char* desc, QueryType type)
2250 	: SamplerTest(testCtx, renderCtx, name, desc, TESTER_TEXTURE_BORDER_COLOR, type)
2251 {
2252 	DE_ASSERT(m_type == QUERY_SAMPLER_PARAM_INTEGER_VEC4					||
2253 			  m_type == QUERY_SAMPLER_PARAM_FLOAT_VEC4						||
2254 			  m_type == QUERY_SAMPLER_PARAM_PURE_INTEGER_VEC4				||
2255 			  m_type == QUERY_SAMPLER_PARAM_PURE_UNSIGNED_INTEGER_VEC4);
2256 }
2257 
test(glu::CallLogWrapper & gl,tcu::ResultCollector & result) const2258 void SamplerBorderColorCase::test (glu::CallLogWrapper& gl, tcu::ResultCollector& result) const
2259 {
2260 	// border color is undefined if queried with pure type and was not set to pure value
2261 	if (m_type == QUERY_SAMPLER_PARAM_INTEGER_VEC4 || m_type == QUERY_SAMPLER_PARAM_FLOAT_VEC4)
2262 	{
2263 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
2264 		verifyStateSamplerParamFloatVec4(result, gl, m_target, m_pname, tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), m_type);
2265 	}
2266 
2267 	if (m_type == QUERY_SAMPLER_PARAM_PURE_INTEGER_VEC4)
2268 	{
2269 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
2270 		const tcu::IVec4			color			(0x7FFFFFFF, -2, 3, -128);
2271 
2272 		gl.glSamplerParameterIiv(m_target, m_pname, color.getPtr());
2273 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIiv");
2274 
2275 		verifyStateSamplerParamIntegerVec4(result, gl, m_target, m_pname, color, m_type);
2276 	}
2277 	else if (m_type == QUERY_SAMPLER_PARAM_PURE_UNSIGNED_INTEGER_VEC4)
2278 	{
2279 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
2280 		const tcu::UVec4			color			(0x8000000ul, 2, 3, 128);
2281 
2282 		gl.glSamplerParameterIuiv(m_target, m_pname, color.getPtr());
2283 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterIuiv");
2284 
2285 		verifyStateSamplerParamUnsignedIntegerVec4(result, gl, m_target, m_pname, color, m_type);
2286 	}
2287 	else
2288 	{
2289 		DE_ASSERT(m_type == QUERY_SAMPLER_PARAM_INTEGER_VEC4 || m_type == QUERY_SAMPLER_PARAM_FLOAT_VEC4);
2290 
2291 		const tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Set", "Set");
2292 		const tcu::Vec4				color			(0.25f, 1.0f, 0.0f, 0.77f);
2293 		const tcu::IVec4			icolor			(0x8000000ul, 0x7FFFFFFF, 0, 0x0FFFFFFF);
2294 
2295 		gl.glSamplerParameterfv(m_target, m_pname, color.getPtr());
2296 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameterfv");
2297 
2298 		verifyStateSamplerParamFloatVec4(result, gl, m_target, m_pname, color, m_type);
2299 
2300 		gl.glSamplerParameteriv(m_target, m_pname, icolor.getPtr());
2301 		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glSamplerParameteriv");
2302 
2303 		verifyStateSamplerParamNormalizedI32Vec4(result, gl, m_target, m_pname, icolor, m_type);
2304 	}
2305 }
2306 
2307 } // anonymous
2308 
isLegalTesterForTarget(glw::GLenum target,TesterType tester)2309 bool isLegalTesterForTarget (glw::GLenum target, TesterType tester)
2310 {
2311 	// no 3d filtering on 2d targets
2312 	if ((tester == TESTER_TEXTURE_WRAP_R || tester == TESTER_TEXTURE_WRAP_R_CLAMP_TO_BORDER) &&  target != GL_TEXTURE_3D)
2313 		return false;
2314 
2315 	// no sampling on multisample
2316 	if (isMultisampleTarget(target) && isSamplerStateTester(tester))
2317 		return false;
2318 
2319 	// no states in buffer
2320 	if (target == GL_TEXTURE_BUFFER)
2321 		return false;
2322 
2323 	return true;
2324 }
2325 
isMultisampleTarget(glw::GLenum target)2326 bool isMultisampleTarget (glw::GLenum target)
2327 {
2328 	return	target == GL_TEXTURE_2D_MULTISAMPLE			||
2329 			target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
2330 }
2331 
isSamplerStateTester(TesterType tester)2332 bool isSamplerStateTester (TesterType tester)
2333 {
2334 	return	tester == TESTER_TEXTURE_WRAP_S					||
2335 			tester == TESTER_TEXTURE_WRAP_T					||
2336 			tester == TESTER_TEXTURE_WRAP_R					||
2337 			tester == TESTER_TEXTURE_MAG_FILTER				||
2338 			tester == TESTER_TEXTURE_MIN_FILTER				||
2339 			tester == TESTER_TEXTURE_MIN_LOD				||
2340 			tester == TESTER_TEXTURE_MAX_LOD				||
2341 			tester == TESTER_TEXTURE_COMPARE_MODE			||
2342 			tester == TESTER_TEXTURE_COMPARE_FUNC			||
2343 			tester == TESTER_TEXTURE_SRGB_DECODE_EXT		||
2344 			tester == TESTER_TEXTURE_BORDER_COLOR			||
2345 			tester == TESTER_TEXTURE_WRAP_S_CLAMP_TO_BORDER	||
2346 			tester == TESTER_TEXTURE_WRAP_T_CLAMP_TO_BORDER	||
2347 			tester == TESTER_TEXTURE_WRAP_R_CLAMP_TO_BORDER;
2348 }
2349 
createIsTextureTest(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const std::string & name,const std::string & description,glw::GLenum target)2350 tcu::TestCase* createIsTextureTest (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const std::string& name, const std::string& description, glw::GLenum target)
2351 {
2352 	return new IsTextureCase(testCtx, renderCtx, name.c_str(), description.c_str(), target);
2353 }
2354 
createTexParamTest(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const std::string & name,const std::string & description,QueryType queryType,glw::GLenum target,TesterType tester)2355 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)
2356 {
2357 	if (isMultisampleTarget(target) && isSamplerStateTester(tester))
2358 	{
2359 		DE_ASSERT(!"Multisample textures have no sampler state");
2360 		return DE_NULL;
2361 	}
2362 	if (target == GL_TEXTURE_BUFFER)
2363 	{
2364 		DE_ASSERT(!"Buffer textures have no texture state");
2365 		return DE_NULL;
2366 	}
2367 	if (target != GL_TEXTURE_3D && mapTesterToPname(tester) == GL_TEXTURE_WRAP_R)
2368 	{
2369 		DE_ASSERT(!"Only 3D textures have wrap r filter");
2370 		return DE_NULL;
2371 	}
2372 
2373 #define CASE_ALL_SETTERS(X) case X: case X ## _SET_PURE_INT: case X ## _SET_PURE_UINT
2374 
2375 	switch (tester)
2376 	{
2377 		CASE_ALL_SETTERS(TESTER_TEXTURE_SWIZZLE_R):
2378 		CASE_ALL_SETTERS(TESTER_TEXTURE_SWIZZLE_G):
2379 		CASE_ALL_SETTERS(TESTER_TEXTURE_SWIZZLE_B):
2380 		CASE_ALL_SETTERS(TESTER_TEXTURE_SWIZZLE_A):
2381 			return new TextureSwizzleCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, tester, queryType);
2382 
2383 		CASE_ALL_SETTERS(TESTER_TEXTURE_WRAP_S):
2384 		CASE_ALL_SETTERS(TESTER_TEXTURE_WRAP_T):
2385 		CASE_ALL_SETTERS(TESTER_TEXTURE_WRAP_R):
2386 			return new TextureWrapCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, tester, queryType);
2387 
2388 		CASE_ALL_SETTERS(TESTER_TEXTURE_MAG_FILTER):
2389 		CASE_ALL_SETTERS(TESTER_TEXTURE_MIN_FILTER):
2390 			return new TextureFilterCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, tester, queryType);
2391 
2392 		CASE_ALL_SETTERS(TESTER_TEXTURE_MIN_LOD):
2393 		CASE_ALL_SETTERS(TESTER_TEXTURE_MAX_LOD):
2394 			return new TextureLODCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, tester, queryType);
2395 
2396 		CASE_ALL_SETTERS(TESTER_TEXTURE_BASE_LEVEL):
2397 		CASE_ALL_SETTERS(TESTER_TEXTURE_MAX_LEVEL):
2398 			return new TextureLevelCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, tester, queryType);
2399 
2400 		CASE_ALL_SETTERS(TESTER_TEXTURE_COMPARE_MODE):
2401 			return new TextureCompareModeCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, tester, queryType);
2402 
2403 		CASE_ALL_SETTERS(TESTER_TEXTURE_COMPARE_FUNC):
2404 			return new TextureCompareFuncCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, tester, queryType);
2405 
2406 		case TESTER_TEXTURE_IMMUTABLE_LEVELS:
2407 			return new TextureImmutableLevelsCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, queryType);
2408 
2409 		case TESTER_TEXTURE_IMMUTABLE_FORMAT:
2410 			return new TextureImmutableFormatCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, queryType);
2411 
2412 		case TESTER_TEXTURE_WRAP_S_CLAMP_TO_BORDER:
2413 		case TESTER_TEXTURE_WRAP_T_CLAMP_TO_BORDER:
2414 		case TESTER_TEXTURE_WRAP_R_CLAMP_TO_BORDER:
2415 			return new TextureWrapClampToBorderCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, tester, queryType);
2416 
2417 		CASE_ALL_SETTERS(TESTER_DEPTH_STENCIL_TEXTURE_MODE):
2418 			return new DepthStencilModeCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, tester, queryType);
2419 
2420 		CASE_ALL_SETTERS(TESTER_TEXTURE_SRGB_DECODE_EXT):
2421 			return new TextureSRGBDecodeCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, tester, queryType);
2422 
2423 		case TESTER_TEXTURE_BORDER_COLOR:
2424 			return new TextureBorderColorCase(testCtx, renderCtx, name.c_str(), description.c_str(), target, queryType);
2425 
2426 		default:
2427 			break;
2428 	}
2429 
2430 #undef CASE_ALL_SETTERS
2431 
2432 	DE_ASSERT(false);
2433 	return DE_NULL;
2434 }
2435 
createSamplerParamTest(tcu::TestContext & testCtx,const glu::RenderContext & renderCtx,const std::string & name,const std::string & description,StateQueryUtil::QueryType queryType,TesterType tester)2436 tcu::TestCase* createSamplerParamTest (tcu::TestContext& testCtx, const glu::RenderContext& renderCtx, const std::string& name, const std::string& description, StateQueryUtil::QueryType queryType, TesterType tester)
2437 {
2438 #define CASE_ALL_SETTERS(X) case X: case X ## _SET_PURE_INT: case X ## _SET_PURE_UINT
2439 
2440 	switch (tester)
2441 	{
2442 		CASE_ALL_SETTERS(TESTER_TEXTURE_WRAP_S):
2443 		CASE_ALL_SETTERS(TESTER_TEXTURE_WRAP_T):
2444 		CASE_ALL_SETTERS(TESTER_TEXTURE_WRAP_R):
2445 			return new SamplerWrapCase(testCtx, renderCtx, name.c_str(), description.c_str(), tester, queryType);
2446 
2447 		CASE_ALL_SETTERS(TESTER_TEXTURE_MAG_FILTER):
2448 		CASE_ALL_SETTERS(TESTER_TEXTURE_MIN_FILTER):
2449 			return new SamplerFilterCase(testCtx, renderCtx, name.c_str(), description.c_str(), tester, queryType);
2450 
2451 		CASE_ALL_SETTERS(TESTER_TEXTURE_MIN_LOD):
2452 		CASE_ALL_SETTERS(TESTER_TEXTURE_MAX_LOD):
2453 			return new SamplerLODCase(testCtx, renderCtx, name.c_str(), description.c_str(), tester, queryType);
2454 
2455 		CASE_ALL_SETTERS(TESTER_TEXTURE_COMPARE_MODE):
2456 			return new SamplerCompareModeCase(testCtx, renderCtx, name.c_str(), description.c_str(), tester, queryType);
2457 
2458 		CASE_ALL_SETTERS(TESTER_TEXTURE_COMPARE_FUNC):
2459 			return new SamplerCompareFuncCase(testCtx, renderCtx, name.c_str(), description.c_str(), tester, queryType);
2460 
2461 		case TESTER_TEXTURE_WRAP_S_CLAMP_TO_BORDER:
2462 		case TESTER_TEXTURE_WRAP_T_CLAMP_TO_BORDER:
2463 		case TESTER_TEXTURE_WRAP_R_CLAMP_TO_BORDER:
2464 			return new SamplerWrapClampToBorderCase(testCtx, renderCtx, name.c_str(), description.c_str(), tester, queryType);
2465 
2466 		CASE_ALL_SETTERS(TESTER_TEXTURE_SRGB_DECODE_EXT):
2467 			return new SamplerSRGBDecodeCase(testCtx, renderCtx, name.c_str(), description.c_str(), tester, queryType);
2468 
2469 		case TESTER_TEXTURE_BORDER_COLOR:
2470 			return new SamplerBorderColorCase(testCtx, renderCtx, name.c_str(), description.c_str(), queryType);
2471 
2472 		default:
2473 			break;
2474 	}
2475 
2476 #undef CASE_ALL_SETTERS
2477 
2478 	DE_ASSERT(false);
2479 	return DE_NULL;
2480 }
2481 
2482 } // TextureStateQueryTests
2483 } // gls
2484 } // deqp
2485