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