Fix emulated compressed format issues
[platform/upstream/VK-GL-CTS.git] / external / openglcts / modules / gl / gl4cDirectStateAccessTexturesTests.cpp
1 /*-------------------------------------------------------------------------
2  * OpenGL Conformance Test Suite
3  * -----------------------------
4  *
5  * Copyright (c) 2015-2016 The Khronos Group Inc.
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
22  */ /*-------------------------------------------------------------------*/
23
24 /**
25  */ /*!
26  * \file  gl4cDirectStateAccessTexturesTests.cpp
27  * \brief Conformance tests for the Direct State Access feature functionality (Texture access part).
28  */ /*-----------------------------------------------------------------------------------------------------------*/
29
30 /* Uncomment this if SubImageErrorsTest crashes during negative test of TextureSubImage (negative value width/height/depth passed to the function). */
31 /* #define TURN_OFF_SUB_IMAGE_ERRORS_TEST_OF_NEGATIVE_WIDTH_HEIGHT_OR_DEPTH */
32
33 /* Includes. */
34 #include "gl4cDirectStateAccessTests.hpp"
35
36 #include "deSharedPtr.hpp"
37
38 #include "gluContextInfo.hpp"
39 #include "gluDefs.hpp"
40 #include "gluPixelTransfer.hpp"
41 #include "gluStrUtil.hpp"
42
43 #include "tcuFuzzyImageCompare.hpp"
44 #include "tcuImageCompare.hpp"
45 #include "tcuRenderTarget.hpp"
46 #include "tcuSurface.hpp"
47 #include "tcuTestLog.hpp"
48
49 #include "glw.h"
50 #include "glwFunctions.hpp"
51
52 #include <algorithm>
53 #include <climits>
54 #include <set>
55 #include <sstream>
56 #include <stack>
57 #include <string>
58
59 namespace gl4cts
60 {
61 namespace DirectStateAccess
62 {
63 namespace Textures
64 {
65 /******************************** Creation Test Implementation   ********************************/
66
67 /** @brief Creation Test constructor.
68  *
69  *  @param [in] context     OpenGL context.
70  */
71 CreationTest::CreationTest(deqp::Context& context)
72         : deqp::TestCase(context, "textures_creation", "Texture Objects Creation Test")
73 {
74         /* Intentionally left blank. */
75 }
76
77 /** @brief Iterate Creation Test cases.
78  *
79  *  @return Iteration result.
80  */
81 tcu::TestNode::IterateResult CreationTest::iterate()
82 {
83         /* Shortcut for GL functionality. */
84         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
85
86         /* Get context setup. */
87         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
88         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
89
90         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
91         {
92                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
93
94                 return STOP;
95         }
96
97         /* Running tests. */
98         bool is_ok      = true;
99         bool is_error = false;
100
101         /* Textures' objects */
102         static const glw::GLenum texture_targets[] = { GL_TEXTURE_1D,
103                                                                                                    GL_TEXTURE_2D,
104                                                                                                    GL_TEXTURE_3D,
105                                                                                                    GL_TEXTURE_1D_ARRAY,
106                                                                                                    GL_TEXTURE_2D_ARRAY,
107                                                                                                    GL_TEXTURE_RECTANGLE,
108                                                                                                    GL_TEXTURE_CUBE_MAP,
109                                                                                                    GL_TEXTURE_CUBE_MAP_ARRAY,
110                                                                                                    GL_TEXTURE_BUFFER,
111                                                                                                    GL_TEXTURE_2D_MULTISAMPLE,
112                                                                                                    GL_TEXTURE_2D_MULTISAMPLE_ARRAY };
113         static const glw::GLuint texture_targets_count = sizeof(texture_targets) / sizeof(texture_targets[0]);
114         static const glw::GLuint textures_count            = 2;
115
116         glw::GLuint textures_legacy[textures_count]                                             = {};
117         glw::GLuint textures_dsa[texture_targets_count][textures_count] = {};
118
119         try
120         {
121                 /* Check legacy state creation. */
122                 gl.genTextures(textures_count, textures_legacy);
123                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
124
125                 for (glw::GLuint i = 0; i < textures_count; ++i)
126                 {
127                         if (gl.isTexture(textures_legacy[i]))
128                         {
129                                 is_ok = false;
130
131                                 /* Log. */
132                                 m_context.getTestContext().getLog()
133                                         << tcu::TestLog::Message
134                                         << "GenTextures has created default objects, but it should create only a names."
135                                         << tcu::TestLog::EndMessage;
136                         }
137                 }
138
139                 /* Check direct state creation. */
140                 for (glw::GLuint j = 0; j < texture_targets_count; ++j)
141                 {
142                         gl.createTextures(texture_targets[j], textures_count, textures_dsa[j]);
143                         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
144
145                         for (glw::GLuint i = 0; i < textures_count; ++i)
146                         {
147                                 if (!gl.isTexture(textures_dsa[j][i]))
148                                 {
149                                         is_ok = false;
150
151                                         /* Log. */
152                                         m_context.getTestContext().getLog()
153                                                 << tcu::TestLog::Message << "CreateTextures has not created default objects for target "
154                                                 << glu::getTextureTargetStr(texture_targets[j]) << "." << tcu::TestLog::EndMessage;
155                                 }
156                         }
157                 }
158         }
159         catch (...)
160         {
161                 is_ok   = false;
162                 is_error = true;
163         }
164
165         /* Cleanup. */
166         for (glw::GLuint i = 0; i < textures_count; ++i)
167         {
168                 if (textures_legacy[i])
169                 {
170                         gl.deleteTextures(1, &textures_legacy[i]);
171
172                         textures_legacy[i] = 0;
173                 }
174
175                 for (glw::GLuint j = 0; j < texture_targets_count; ++j)
176                 {
177                         if (textures_dsa[j][i])
178                         {
179                                 gl.deleteTextures(1, &textures_dsa[j][i]);
180
181                                 textures_dsa[j][i] = 0;
182                         }
183                 }
184         }
185
186         /* Errors clean up. */
187         while (gl.getError())
188                 ;
189
190         /* Result's setup. */
191         if (is_ok)
192         {
193                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
194         }
195         else
196         {
197                 if (is_error)
198                 {
199                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
200                 }
201                 else
202                 {
203                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
204                 }
205         }
206
207         return STOP;
208 }
209
210 /******************************** Reference Data Implementation   *****************************/
211
212 /** @brief Internal Format selector.
213  *
214  *  @tparam T      Type.
215  *  @tparam S      Size (# of components).
216  *  @tparam N      Is normalized.
217  *
218  *  @return Internal format.
219  */
220 template <>
221 glw::GLenum Reference::InternalFormat<glw::GLbyte, 1, false>()
222 {
223         return GL_R8I;
224 }
225
226 template <>
227 glw::GLenum Reference::InternalFormat<glw::GLbyte, 2, false>()
228 {
229         return GL_RG8I;
230 }
231
232 template <>
233 glw::GLenum Reference::InternalFormat<glw::GLbyte, 3, false>()
234 {
235         return GL_RGB8I;
236 }
237
238 template <>
239 glw::GLenum Reference::InternalFormat<glw::GLbyte, 4, false>()
240 {
241         return GL_RGBA8I;
242 }
243
244 template <>
245 glw::GLenum Reference::InternalFormat<glw::GLubyte, 1, false>()
246 {
247         return GL_R8UI;
248 }
249
250 template <>
251 glw::GLenum Reference::InternalFormat<glw::GLubyte, 2, false>()
252 {
253         return GL_RG8UI;
254 }
255
256 template <>
257 glw::GLenum Reference::InternalFormat<glw::GLubyte, 3, false>()
258 {
259         return GL_RGB8UI;
260 }
261
262 template <>
263 glw::GLenum Reference::InternalFormat<glw::GLubyte, 4, false>()
264 {
265         return GL_RGBA8UI;
266 }
267
268 template <>
269 glw::GLenum Reference::InternalFormat<glw::GLshort, 1, false>()
270 {
271         return GL_R16I;
272 }
273
274 template <>
275 glw::GLenum Reference::InternalFormat<glw::GLshort, 2, false>()
276 {
277         return GL_RG16I;
278 }
279
280 template <>
281 glw::GLenum Reference::InternalFormat<glw::GLshort, 3, false>()
282 {
283         return GL_RGB16I;
284 }
285
286 template <>
287 glw::GLenum Reference::InternalFormat<glw::GLshort, 4, false>()
288 {
289         return GL_RGBA16I;
290 }
291
292 template <>
293 glw::GLenum Reference::InternalFormat<glw::GLushort, 1, false>()
294 {
295         return GL_R16UI;
296 }
297
298 template <>
299 glw::GLenum Reference::InternalFormat<glw::GLushort, 2, false>()
300 {
301         return GL_RG16UI;
302 }
303
304 template <>
305 glw::GLenum Reference::InternalFormat<glw::GLushort, 3, false>()
306 {
307         return GL_RGB16UI;
308 }
309
310 template <>
311 glw::GLenum Reference::InternalFormat<glw::GLushort, 4, false>()
312 {
313         return GL_RGBA16UI;
314 }
315
316 template <>
317 glw::GLenum Reference::InternalFormat<glw::GLint, 1, false>()
318 {
319         return GL_R32I;
320 }
321
322 template <>
323 glw::GLenum Reference::InternalFormat<glw::GLint, 2, false>()
324 {
325         return GL_RG32I;
326 }
327
328 template <>
329 glw::GLenum Reference::InternalFormat<glw::GLint, 3, false>()
330 {
331         return GL_RGB32I;
332 }
333
334 template <>
335 glw::GLenum Reference::InternalFormat<glw::GLint, 4, false>()
336 {
337         return GL_RGBA32I;
338 }
339
340 template <>
341 glw::GLenum Reference::InternalFormat<glw::GLuint, 1, false>()
342 {
343         return GL_R32UI;
344 }
345
346 template <>
347 glw::GLenum Reference::InternalFormat<glw::GLuint, 2, false>()
348 {
349         return GL_RG32UI;
350 }
351
352 template <>
353 glw::GLenum Reference::InternalFormat<glw::GLuint, 3, false>()
354 {
355         return GL_RGB32UI;
356 }
357
358 template <>
359 glw::GLenum Reference::InternalFormat<glw::GLuint, 4, false>()
360 {
361         return GL_RGBA32UI;
362 }
363
364 template <>
365 glw::GLenum Reference::InternalFormat<glw::GLubyte, 1, true>()
366 {
367         return GL_R8;
368 }
369
370 template <>
371 glw::GLenum Reference::InternalFormat<glw::GLubyte, 2, true>()
372 {
373         return GL_RG8;
374 }
375
376 template <>
377 glw::GLenum Reference::InternalFormat<glw::GLubyte, 3, true>()
378 {
379         return GL_RGB8;
380 }
381
382 template <>
383 glw::GLenum Reference::InternalFormat<glw::GLubyte, 4, true>()
384 {
385         return GL_RGBA8;
386 }
387
388 template <>
389 glw::GLenum Reference::InternalFormat<glw::GLushort, 1, true>()
390 {
391         return GL_R16;
392 }
393
394 template <>
395 glw::GLenum Reference::InternalFormat<glw::GLushort, 2, true>()
396 {
397         return GL_RG16;
398 }
399
400 template <>
401 glw::GLenum Reference::InternalFormat<glw::GLushort, 3, true>()
402 {
403         return GL_RGB16;
404 }
405
406 template <>
407 glw::GLenum Reference::InternalFormat<glw::GLushort, 4, true>()
408 {
409         return GL_RGBA16;
410 }
411
412 template <>
413 glw::GLenum Reference::InternalFormat<glw::GLfloat, 1, true>()
414 {
415         return GL_R32F;
416 }
417
418 template <>
419 glw::GLenum Reference::InternalFormat<glw::GLfloat, 2, true>()
420 {
421         return GL_RG32F;
422 }
423
424 template <>
425 glw::GLenum Reference::InternalFormat<glw::GLfloat, 3, true>()
426 {
427         return GL_RGB32F;
428 }
429
430 template <>
431 glw::GLenum Reference::InternalFormat<glw::GLfloat, 4, true>()
432 {
433         return GL_RGBA32F;
434 }
435
436 /** @brief Format selector.
437  *
438  *  @tparam S      Size (# of components).
439  *  @tparam N      Is normalized.
440  *
441  *  @return format.
442  */
443 template <>
444 glw::GLenum Reference::Format<1, false>()
445 {
446         return GL_RED_INTEGER;
447 }
448
449 template <>
450 glw::GLenum Reference::Format<2, false>()
451 {
452         return GL_RG_INTEGER;
453 }
454
455 template <>
456 glw::GLenum Reference::Format<3, false>()
457 {
458         return GL_RGB_INTEGER;
459 }
460
461 template <>
462 glw::GLenum Reference::Format<4, false>()
463 {
464         return GL_RGBA_INTEGER;
465 }
466
467 template <>
468 glw::GLenum Reference::Format<1, true>()
469 {
470         return GL_RED;
471 }
472
473 template <>
474 glw::GLenum Reference::Format<2, true>()
475 {
476         return GL_RG;
477 }
478
479 template <>
480 glw::GLenum Reference::Format<3, true>()
481 {
482         return GL_RGB;
483 }
484
485 template <>
486 glw::GLenum Reference::Format<4, true>()
487 {
488         return GL_RGBA;
489 }
490
491 /** @brief Type selector.
492  *
493  *  @tparam T      Type.
494  *
495  *  @return Type.
496  */
497 template <>
498 glw::GLenum Reference::Type<glw::GLbyte>()
499 {
500         return GL_BYTE;
501 }
502
503 template <>
504 glw::GLenum Reference::Type<glw::GLubyte>()
505 {
506         return GL_UNSIGNED_BYTE;
507 }
508
509 template <>
510 glw::GLenum Reference::Type<glw::GLshort>()
511 {
512         return GL_SHORT;
513 }
514
515 template <>
516 glw::GLenum Reference::Type<glw::GLushort>()
517 {
518         return GL_UNSIGNED_SHORT;
519 }
520
521 template <>
522 glw::GLenum Reference::Type<glw::GLint>()
523 {
524         return GL_INT;
525 }
526
527 template <>
528 glw::GLenum Reference::Type<glw::GLuint>()
529 {
530         return GL_UNSIGNED_INT;
531 }
532
533 template <>
534 glw::GLenum Reference::Type<glw::GLfloat>()
535 {
536         return GL_FLOAT;
537 }
538
539 /** @brief Reference data selector.
540  *
541  *  @tparam T      Type.
542  *  @tparam N      Is normalized.
543  *
544  *  @return Reference data.
545  */
546
547 /* RGBA8I */
548 template <>
549 const glw::GLbyte* Reference::ReferenceData<glw::GLbyte, false>()
550 {
551         static const glw::GLbyte reference[s_reference_count] = {
552                 0,  -1,  2,  -3,  4,  -5,  6,  -7,  8,  -9,  10, -11, 12, -13, 14, -15, 16, -17, 18, -19, 20, -21, 22, -23,
553                 24, -25, 26, -27, 28, -29, 30, -31, 32, -33, 34, -35, 36, -37, 38, -39, 40, -41, 42, -43, 44, -45, 46, -47,
554                 48, -49, 50, -51, 52, -53, 54, -55, 56, -57, 58, -59, 60, -61, 62, -63, 64, -65, 66, -67, 68, -69, 70, -71,
555                 72, -73, 74, -75, 76, -77, 78, -79, 80, -81, 82, -83, 84, -85, 86, -87, 88, -89, 90, -91, 92, -93, 94, -95
556         };
557         return reference;
558 }
559
560 /* RGBA8UI */
561 template <>
562 const glw::GLubyte* Reference::ReferenceData<glw::GLubyte, false>()
563 {
564         static const glw::GLubyte reference[s_reference_count] = {
565                 0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
566                 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
567                 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
568                 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95
569         };
570         return reference;
571 }
572
573 /* RGBA16I */
574 template <>
575 const glw::GLshort* Reference::ReferenceData<glw::GLshort, false>()
576 {
577         static const glw::GLshort reference[s_reference_count] = {
578                 0,  -1,  2,  -3,  4,  -5,  6,  -7,  8,  -9,  10, -11, 12, -13, 14, -15, 16, -17, 18, -19, 20, -21, 22, -23,
579                 24, -25, 26, -27, 28, -29, 30, -31, 32, -33, 34, -35, 36, -37, 38, -39, 40, -41, 42, -43, 44, -45, 46, -47,
580                 48, -49, 50, -51, 52, -53, 54, -55, 56, -57, 58, -59, 60, -61, 62, -63, 64, -65, 66, -67, 68, -69, 70, -71,
581                 72, -73, 74, -75, 76, -77, 78, -79, 80, -81, 82, -83, 84, -85, 86, -87, 88, -89, 90, -91, 92, -93, 94, -95
582         };
583         return reference;
584 }
585
586 /* RGBA16UI */
587 template <>
588 const glw::GLushort* Reference::ReferenceData<glw::GLushort, false>()
589 {
590         static const glw::GLushort reference[s_reference_count] = {
591                 0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
592                 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
593                 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
594                 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95
595         };
596         return reference;
597 }
598
599 /* RGBA32I */
600 template <>
601 const glw::GLint* Reference::ReferenceData<glw::GLint, false>()
602 {
603         static const glw::GLint reference[s_reference_count] = {
604                 0,  -1,  2,  -3,  4,  -5,  6,  -7,  8,  -9,  10, -11, 12, -13, 14, -15, 16, -17, 18, -19, 20, -21, 22, -23,
605                 24, -25, 26, -27, 28, -29, 30, -31, 32, -33, 34, -35, 36, -37, 38, -39, 40, -41, 42, -43, 44, -45, 46, -47,
606                 48, -49, 50, -51, 52, -53, 54, -55, 56, -57, 58, -59, 60, -61, 62, -63, 64, -65, 66, -67, 68, -69, 70, -71,
607                 72, -73, 74, -75, 76, -77, 78, -79, 80, -81, 82, -83, 84, -85, 86, -87, 88, -89, 90, -91, 92, -93, 94, -95
608         };
609         return reference;
610 }
611
612 /* RGBA32UI */
613 template <>
614 const glw::GLuint* Reference::ReferenceData<glw::GLuint, false>()
615 {
616         static const glw::GLuint reference[s_reference_count] = {
617                 0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
618                 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
619                 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
620                 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95
621         };
622         return reference;
623 }
624
625 /* RGBA8 */
626 template <>
627 const glw::GLubyte* Reference::ReferenceData<glw::GLubyte, true>()
628 {
629         static const glw::GLubyte reference[s_reference_count] = {
630                 0,   2,   5,   8,   10,  13,  16,  18,  21,  24,  26,  29,  32,  34,  37,  40,  42,  45,  48,  51,
631                 53,  56,  59,  61,  64,  67,  69,  72,  75,  77,  80,  83,  85,  88,  91,  93,  96,  99,  102, 104,
632                 107, 110, 112, 115, 118, 120, 123, 126, 128, 131, 134, 136, 139, 142, 144, 147, 150, 153, 155, 158,
633                 161, 163, 166, 169, 171, 174, 177, 179, 182, 185, 187, 190, 193, 195, 198, 201, 204, 206, 209, 212,
634                 214, 217, 220, 222, 225, 228, 230, 233, 236, 238, 241, 244, 246, 249, 252, 255
635         };
636         return reference;
637 }
638
639 /* RGBA16 */
640 template <>
641 const glw::GLushort* Reference::ReferenceData<glw::GLushort, true>()
642 {
643         static const glw::GLushort reference[s_reference_count] = {
644                 0,       689,   1379,  2069,  2759,  3449,  4139,  4828,  5518,  6208,  6898,  7588,  8278,  8967,  9657,  10347,
645                 11037, 11727, 12417, 13107, 13796, 14486, 15176, 15866, 16556, 17246, 17935, 18625, 19315, 20005, 20695, 21385,
646                 22074, 22764, 23454, 24144, 24834, 25524, 26214, 26903, 27593, 28283, 28973, 29663, 30353, 31042, 31732, 32422,
647                 33112, 33802, 34492, 35181, 35871, 36561, 37251, 37941, 38631, 39321, 40010, 40700, 41390, 42080, 42770, 43460,
648                 44149, 44839, 45529, 46219, 46909, 47599, 48288, 48978, 49668, 50358, 51048, 51738, 52428, 53117, 53807, 54497,
649                 55187, 55877, 56567, 57256, 57946, 58636, 59326, 60016, 60706, 61395, 62085, 62775, 63465, 64155, 64845, 65535
650         };
651         return reference;
652 }
653
654 /* RGBA32F */
655 template <>
656 const glw::GLfloat* Reference::ReferenceData<glw::GLfloat, true>()
657 {
658         static const glw::GLfloat reference[s_reference_count] = {
659                 0.f,               0.0105263158f, 0.0210526316f, 0.0315789474f, 0.0421052632f, 0.0526315789f,
660                 0.0631578947f, 0.0736842105f, 0.0842105263f, 0.0947368421f, 0.1052631579f, 0.1157894737f,
661                 0.1263157895f, 0.1368421053f, 0.1473684211f, 0.1578947368f, 0.1684210526f, 0.1789473684f,
662                 0.1894736842f, 0.2f,              0.2105263158f, 0.2210526316f, 0.2315789474f, 0.2421052632f,
663                 0.2526315789f, 0.2631578947f, 0.2736842105f, 0.2842105263f, 0.2947368421f, 0.3052631579f,
664                 0.3157894737f, 0.3263157895f, 0.3368421053f, 0.3473684211f, 0.3578947368f, 0.3684210526f,
665                 0.3789473684f, 0.3894736842f, 0.4f,                      0.4105263158f, 0.4210526316f, 0.4315789474f,
666                 0.4421052632f, 0.4526315789f, 0.4631578947f, 0.4736842105f, 0.4842105263f, 0.4947368421f,
667                 0.5052631579f, 0.5157894737f, 0.5263157895f, 0.5368421053f, 0.5473684211f, 0.5578947368f,
668                 0.5684210526f, 0.5789473684f, 0.5894736842f, 0.6f,                      0.6105263158f, 0.6210526316f,
669                 0.6315789474f, 0.6421052632f, 0.6526315789f, 0.6631578947f, 0.6736842105f, 0.6842105263f,
670                 0.6947368421f, 0.7052631579f, 0.7157894737f, 0.7263157895f, 0.7368421053f, 0.7473684211f,
671                 0.7578947368f, 0.7684210526f, 0.7789473684f, 0.7894736842f, 0.8f,                  0.8105263158f,
672                 0.8210526316f, 0.8315789474f, 0.8421052632f, 0.8526315789f, 0.8631578947f, 0.8736842105f,
673                 0.8842105263f, 0.8947368421f, 0.9052631579f, 0.9157894737f, 0.9263157895f, 0.9368421053f,
674                 0.9473684211f, 0.9578947368f, 0.9684210526f, 0.9789473684f, 0.9894736842f, 1.f
675         };
676         return reference;
677 }
678
679 /* Total number of reference components. */
680 glw::GLuint Reference::ReferenceDataCount()
681 {
682         return s_reference_count;
683 }
684
685 /* Total number of reference size in basic machine units. */
686 template <typename T>
687 glw::GLuint Reference::ReferenceDataSize()
688 {
689         return Reference::ReferenceDataCount() * sizeof(T);
690 }
691
692 /** @brief Comparison function (for floats).
693  *
694  *  @param [in] a      First element.
695  *  @param [in] b      Second element.
696  *
697  *  @return Comparison result.
698  */
699 template <>
700 bool Reference::Compare<glw::GLfloat>(const glw::GLfloat a, const glw::GLfloat b)
701 {
702         if (de::abs(a - b) < 1.f / 256.f)
703         {
704                 return true;
705         }
706         return false;
707 }
708
709 /** @brief Comparison function (integer).
710  *
711  *  @param [in] a      First element.
712  *  @param [in] b      Second element.
713  *
714  *  @return Comparison result.
715  */
716 template <typename T>
717 bool Reference::Compare(const T a, const T b)
718 {
719         return a == b;
720 }
721
722 /******************************** Buffer Test Implementation   ********************************/
723
724 /** @brief Buffer Test constructor.
725  *
726  *  @tparam T      Type.
727  *  @tparam S      Size.
728  *  @tparam N      Is normalized.
729  *
730  *  @param [in] context     OpenGL context.
731  *  @param [in] name     Name of the test.
732  */
733 template <typename T, glw::GLint S, bool N>
734 BufferTest<T, S, N>::BufferTest(deqp::Context& context, const char* name)
735         : deqp::TestCase(context, name, "Texture Buffer Objects Test")
736         , m_fbo(0)
737         , m_rbo(0)
738         , m_po(0)
739         , m_to(0)
740         , m_bo(0)
741         , m_vao(0)
742 {
743         /* Intentionally left blank. */
744 }
745
746 /** @brief Count of reference data to be teted.
747  *
748  *  @return Count.
749  */
750 template <typename T, glw::GLint S, bool N>
751 glw::GLuint BufferTest<T, S, N>::TestReferenceDataCount()
752 {
753         return s_fbo_size_x * S;
754 }
755
756 /** @brief Size of reference data to be teted..
757  *
758  *  @return Size.
759  */
760 template <typename T, glw::GLint S, bool N>
761 glw::GLuint BufferTest<T, S, N>::TestReferenceDataSize()
762 {
763         return static_cast<glw::GLint>(TestReferenceDataCount() * sizeof(T));
764 }
765
766 /** @brief Create buffer textuew.
767  *
768  *  @param [in] use_range_version       Uses TextureBufferRange instead TextureBuffer.
769  *
770  *  @return True if succeded, false otherwise.
771  */
772 template <typename T, glw::GLint S, bool N>
773 bool BufferTest<T, S, N>::CreateBufferTexture(bool use_range_version)
774 {
775         /* Shortcut for GL functionality. */
776         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
777
778         /* Objects creation. */
779         gl.genTextures(1, &m_to);
780         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
781
782         gl.bindTexture(GL_TEXTURE_BUFFER, m_to);
783         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
784
785         gl.genBuffers(1, &m_bo);
786         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateBuffers has failed");
787
788         gl.bindBuffer(GL_TEXTURE_BUFFER, m_bo);
789         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
790
791         /* Data setup. */
792         if (use_range_version)
793         {
794                 glw::GLint alignment = 1;
795
796                 gl.getIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, &alignment);
797                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
798
799                 const glw::GLuint b_offset = alignment;
800                 const glw::GLuint b_size   = TestReferenceDataSize() + b_offset;
801
802                 gl.bufferData(GL_TEXTURE_BUFFER, b_size, NULL, GL_STATIC_DRAW);
803                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData has failed");
804
805                 gl.bufferSubData(GL_TEXTURE_BUFFER, b_offset, TestReferenceDataSize(), ReferenceData<T, N>());
806                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferSubdata has failed");
807
808                 gl.textureBufferRange(m_to, InternalFormat<T, S, N>(), m_bo, b_offset, TestReferenceDataSize());
809         }
810         else
811         {
812                 gl.bufferData(GL_TEXTURE_BUFFER, TestReferenceDataSize(), ReferenceData<T, N>(), GL_STATIC_DRAW);
813                 GLU_EXPECT_NO_ERROR(gl.getError(), "glNamedBufferData has failed");
814
815                 gl.textureBuffer(m_to, InternalFormat<T, S, N>(), m_bo);
816         }
817
818         /* Error checking. */
819         glw::GLenum error;
820
821         if (GL_NO_ERROR != (error = gl.getError()))
822         {
823                 /* Log. */
824                 m_context.getTestContext().getLog()
825                         << tcu::TestLog::Message << (use_range_version ? ("glTextureBufferRange") : ("glTextureBuffer"))
826                         << " unexpectedly generated error " << glu::getErrorStr(error) << " during test of internal format "
827                         << glu::getTextureFormatStr(InternalFormat<T, S, N>()) << "." << tcu::TestLog::EndMessage;
828
829                 CleanBufferTexture();
830
831                 return false;
832         }
833
834         return true;
835 }
836
837 /** @brief Function prepares framebuffer with internal format color attachment.
838  *         Viewport is set up. Content of the framebuffer is cleared.
839  *
840  *  @note The function may throw if unexpected error has occured.
841  *
842  *  @return if the framebuffer returned is supported
843  */
844 template <typename T, glw::GLint S, bool N>
845 bool BufferTest<T, S, N>::PrepareFramebuffer(const glw::GLenum internal_format)
846 {
847         /* Shortcut for GL functionality. */
848         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
849
850         /* Prepare framebuffer. */
851         gl.genFramebuffers(1, &m_fbo);
852         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
853
854         gl.genRenderbuffers(1, &m_rbo);
855         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
856
857         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
858         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
859
860         gl.bindRenderbuffer(GL_RENDERBUFFER, m_rbo);
861         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
862
863         gl.renderbufferStorage(GL_RENDERBUFFER, internal_format, s_fbo_size_x, s_fbo_size_y);
864         GLU_EXPECT_NO_ERROR(gl.getError(), "glRenderbufferStorage call failed.");
865
866         gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_rbo);
867         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
868
869         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
870         {
871                 if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_UNSUPPORTED)
872                         throw tcu::NotSupportedError("unsupported framebuffer configuration");
873                 else
874                         throw 0;
875         }
876
877         gl.viewport(0, 0, s_fbo_size_x, s_fbo_size_y);
878         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
879
880         /* Clear framebuffer's content. */
881         gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
882         GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
883
884         gl.clear(GL_COLOR_BUFFER_BIT);
885         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
886
887         return true;
888 }
889
890 /** @brief Create program.
891  *
892  *  @param [in] variable_declaration    Choose variable declaration of the fragment shader.
893  */
894 template <typename T, glw::GLint S, bool N>
895 void BufferTest<T, S, N>::PrepareProgram(const glw::GLchar* variable_declaration)
896 {
897         /* Shortcut for GL functionality */
898         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
899
900         struct Shader
901         {
902                 glw::GLchar const* source[3];
903                 glw::GLsizei const count;
904                 glw::GLenum const  type;
905                 glw::GLuint                id;
906         } shader[] = {
907                 { { s_vertex_shader, NULL, NULL }, 1, GL_VERTEX_SHADER, 0 },
908                 { { s_fragment_shader_head, variable_declaration, s_fragment_shader_tail }, 3, GL_FRAGMENT_SHADER, 0 }
909         };
910
911         glw::GLuint const shader_count = sizeof(shader) / sizeof(shader[0]);
912
913         try
914         {
915                 /* Create program. */
916                 m_po = gl.createProgram();
917                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateProgram call failed.");
918
919                 /* Shader compilation. */
920
921                 for (glw::GLuint i = 0; i < shader_count; ++i)
922                 {
923                         {
924                                 shader[i].id = gl.createShader(shader[i].type);
925
926                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateShader call failed.");
927
928                                 gl.attachShader(m_po, shader[i].id);
929
930                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glAttachShader call failed.");
931
932                                 gl.shaderSource(shader[i].id, shader[i].count, shader[i].source, NULL);
933
934                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource call failed.");
935
936                                 gl.compileShader(shader[i].id);
937
938                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader call failed.");
939
940                                 glw::GLint status = GL_FALSE;
941
942                                 gl.getShaderiv(shader[i].id, GL_COMPILE_STATUS, &status);
943                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
944
945                                 if (GL_FALSE == status)
946                                 {
947                                         glw::GLint log_size = 0;
948                                         gl.getShaderiv(shader[i].id, GL_INFO_LOG_LENGTH, &log_size);
949                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
950
951                                         glw::GLchar* log_text = new glw::GLchar[log_size];
952
953                                         gl.getShaderInfoLog(shader[i].id, log_size, NULL, &log_text[0]);
954
955                                         m_context.getTestContext().getLog()
956                                                 << tcu::TestLog::Message << "Shader compilation has failed.\n"
957                                                 << "Shader type: " << glu::getShaderTypeStr(shader[i].type) << "\n"
958                                                 << "Shader compilation error log:\n"
959                                                 << log_text << "\n"
960                                                 << "Shader source code:\n"
961                                                 << shader[i].source[0] << (shader[i].source[1] ? shader[i].source[1] : "")
962                                                 << (shader[i].source[2] ? shader[i].source[2] : "") << "\n"
963                                                 << tcu::TestLog::EndMessage;
964
965                                         delete[] log_text;
966
967                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog call failed.");
968
969                                         throw 0;
970                                 }
971                         }
972                 }
973
974                 /* Link. */
975                 gl.linkProgram(m_po);
976
977                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTransformFeedbackVaryings call failed.");
978
979                 glw::GLint status = GL_FALSE;
980
981                 gl.getProgramiv(m_po, GL_LINK_STATUS, &status);
982
983                 if (GL_TRUE == status)
984                 {
985                         for (glw::GLuint i = 0; i < shader_count; ++i)
986                         {
987                                 if (shader[i].id)
988                                 {
989                                         gl.detachShader(m_po, shader[i].id);
990
991                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glDetachShader call failed.");
992                                 }
993                         }
994                 }
995                 else
996                 {
997                         glw::GLint log_size = 0;
998
999                         gl.getProgramiv(m_po, GL_INFO_LOG_LENGTH, &log_size);
1000
1001                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv call failed.");
1002
1003                         glw::GLchar* log_text = new glw::GLchar[log_size];
1004
1005                         gl.getProgramInfoLog(m_po, log_size, NULL, &log_text[0]);
1006
1007                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "Program linkage has failed due to:\n"
1008                                                                                                 << log_text << "\n"
1009                                                                                                 << tcu::TestLog::EndMessage;
1010
1011                         delete[] log_text;
1012
1013                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramInfoLog call failed.");
1014
1015                         throw 0;
1016                 }
1017         }
1018         catch (...)
1019         {
1020                 if (m_po)
1021                 {
1022                         gl.deleteProgram(m_po);
1023
1024                         m_po = 0;
1025                 }
1026         }
1027
1028         for (glw::GLuint i = 0; i < shader_count; ++i)
1029         {
1030                 if (0 != shader[i].id)
1031                 {
1032                         gl.deleteShader(shader[i].id);
1033
1034                         shader[i].id = 0;
1035                 }
1036         }
1037
1038         if (0 == m_po)
1039         {
1040                 throw 0;
1041         }
1042 }
1043
1044 /** @brief Create VAO.
1045  */
1046 template <typename T, glw::GLint S, bool N>
1047 void BufferTest<T, S, N>::PrepareVertexArray()
1048 {
1049         /* Shortcut for GL functionality. */
1050         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1051
1052         gl.genVertexArrays(1, &m_vao);
1053         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays has failed");
1054
1055         gl.bindVertexArray(m_vao);
1056         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray has failed");
1057 }
1058
1059 /** @brief Test's draw function.
1060  */
1061 template <typename T, glw::GLint S, bool N>
1062 void BufferTest<T, S, N>::Draw()
1063 {
1064         /* Shortcut for GL functionality. */
1065         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1066
1067         gl.useProgram(m_po);
1068         GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed");
1069
1070         gl.activeTexture(GL_TEXTURE0);
1071         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
1072
1073         gl.bindTextureUnit(0, m_to);
1074         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
1075
1076         gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
1077         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed");
1078 }
1079
1080 /** @brief Compre results with the reference.
1081  *
1082  *  @return True if equal, false otherwise.
1083  */
1084 template <typename T, glw::GLint S, bool N>
1085 bool BufferTest<T, S, N>::Check()
1086 {
1087         /* Shortcut for GL functionality. */
1088         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1089
1090         /* Fetching data. */
1091         std::vector<T> result(TestReferenceDataCount());
1092
1093         gl.pixelStorei(GL_UNPACK_ALIGNMENT, sizeof(T));
1094         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
1095
1096         gl.pixelStorei(GL_PACK_ALIGNMENT, sizeof(T));
1097         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
1098
1099         gl.readnPixels(0, 0, s_fbo_size_x, s_fbo_size_y, Format<S, N>(), Type<T>(), TestReferenceDataSize(),
1100                                    (glw::GLvoid*)(&result[0]));
1101         GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels has failed");
1102
1103         /* Comparison. */
1104         bool is_ok = true;
1105
1106         for (glw::GLuint i = 0; i < TestReferenceDataCount(); ++i)
1107         {
1108                 if (!Compare<T>(result[i], ReferenceData<T, N>()[i]))
1109                 {
1110                         is_ok = false;
1111
1112                         break;
1113                 }
1114         }
1115
1116         return is_ok;
1117 }
1118
1119 /** @brief Test function.
1120  *
1121  *  @param [in] use_range_version   Uses TextureBufferRange instead TextureBuffer.
1122  *
1123  *  @return True if succeeded, false otherwise.
1124  */
1125 template <typename T, glw::GLint S, bool N>
1126 bool BufferTest<T, S, N>::Test(bool use_range_version)
1127 {
1128         /* Setup. */
1129         if (!PrepareFramebuffer(InternalFormat<T, S, N>()))
1130         {
1131                 /**
1132                  * If the framebuffer it not supported, means that the
1133                  * tested combination is unsupported for this driver,
1134                  * but allowed to be unsupported by OpenGL spec, so we
1135                  * just skip.
1136                  */
1137                 CleanFramebuffer();
1138                 CleanErrors();
1139
1140                 return true;
1141         }
1142
1143         if (!CreateBufferTexture(use_range_version))
1144         {
1145                 CleanFramebuffer();
1146                 CleanErrors();
1147
1148                 return false;
1149         }
1150
1151         /* Action. */
1152         Draw();
1153
1154         /* Compare results with reference. */
1155         bool result = Check();
1156
1157         /* Cleanup. */
1158         CleanFramebuffer();
1159         CleanBufferTexture();
1160         CleanErrors();
1161
1162         /* Pass result. */
1163         return result;
1164 }
1165
1166 /** @brief Clean GL objects
1167  */
1168 template <typename T, glw::GLint S, bool N>
1169 void BufferTest<T, S, N>::CleanBufferTexture()
1170 {
1171         /* Shortcut for GL functionality. */
1172         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1173
1174         /* Texture. */
1175         if (m_to)
1176         {
1177                 gl.deleteTextures(1, &m_to);
1178
1179                 m_to = 0;
1180         }
1181
1182         /* Texture buffer. */
1183         if (m_bo)
1184         {
1185                 gl.deleteBuffers(1, &m_bo);
1186
1187                 m_bo = 0;
1188         }
1189 }
1190
1191 /** @brief Clean GL objects
1192  */
1193 template <typename T, glw::GLint S, bool N>
1194 void BufferTest<T, S, N>::CleanFramebuffer()
1195 {
1196         /* Shortcut for GL functionality. */
1197         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1198
1199         /* Framebuffer. */
1200         if (m_fbo)
1201         {
1202                 gl.deleteFramebuffers(1, &m_fbo);
1203
1204                 m_fbo = 0;
1205         }
1206
1207         /* Renderbuffer. */
1208         if (m_rbo)
1209         {
1210                 gl.deleteRenderbuffers(1, &m_rbo);
1211
1212                 m_rbo = 0;
1213         }
1214 }
1215
1216 /** @brief Clean GL objects
1217  */
1218 template <typename T, glw::GLint S, bool N>
1219 void BufferTest<T, S, N>::CleanProgram()
1220 {
1221         /* Shortcut for GL functionality. */
1222         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1223
1224         /* Program. */
1225         if (m_po)
1226         {
1227                 gl.useProgram(0);
1228
1229                 gl.deleteProgram(m_po);
1230
1231                 m_po = 0;
1232         }
1233 }
1234
1235 /** @brief Clean errors.
1236  */
1237 template <typename T, glw::GLint S, bool N>
1238 void BufferTest<T, S, N>::CleanErrors()
1239 {
1240         /* Shortcut for GL functionality. */
1241         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1242
1243         /* Query all errors until GL_NO_ERROR occure. */
1244         while (GL_NO_ERROR != gl.getError())
1245                 ;
1246 }
1247
1248 /** @brief Clean GL objects
1249  */
1250 template <typename T, glw::GLint S, bool N>
1251 void BufferTest<T, S, N>::CleanVertexArray()
1252 {
1253         /* Shortcut for GL functionality. */
1254         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1255
1256         if (m_vao)
1257         {
1258                 gl.bindVertexArray(0);
1259
1260                 gl.deleteVertexArrays(1, &m_vao);
1261
1262                 m_vao = 0;
1263         }
1264 }
1265
1266 /** @brief Iterate Buffer Test cases.
1267  *
1268  *  @return Iteration result.
1269  */
1270 template <typename T, glw::GLint S, bool N>
1271 tcu::TestNode::IterateResult BufferTest<T, S, N>::iterate()
1272 {
1273         /* Shortcut for GL functionality. */
1274         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1275
1276         /* Get context setup. */
1277         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
1278         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
1279
1280         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
1281         {
1282                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
1283
1284                 return STOP;
1285         }
1286
1287         /* Running tests. */
1288         bool is_ok      = true;
1289         bool is_error = false;
1290
1291         try
1292         {
1293                 PrepareVertexArray();
1294
1295                 PrepareProgram(FragmentShaderDeclaration());
1296
1297                 for (glw::GLuint i = 0; i < 2; ++i)
1298                 {
1299                         bool use_range = (i == 1);
1300                         is_ok &= Test(use_range);
1301                         CleanErrors();
1302                 }
1303
1304                 CleanProgram();
1305         }
1306         catch (tcu::NotSupportedError e)
1307         {
1308                 throw e;
1309         }
1310         catch (...)
1311         {
1312                 is_ok   = false;
1313                 is_error = true;
1314         }
1315
1316         /* Cleanup. */
1317         CleanBufferTexture();
1318         CleanFramebuffer();
1319         CleanProgram();
1320         CleanErrors();
1321         CleanVertexArray();
1322
1323         /* Errors clean up. */
1324         while (gl.getError())
1325                 ;
1326
1327         /* Result's setup. */
1328         if (is_ok)
1329         {
1330                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1331         }
1332         else
1333         {
1334                 if (is_error)
1335                 {
1336                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
1337                 }
1338                 else
1339                 {
1340                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
1341                 }
1342         }
1343
1344         return STOP;
1345 }
1346
1347 /* Vertex shader source code. */
1348 template <typename T, glw::GLint S, bool N>
1349 const glw::GLchar* BufferTest<T, S, N>::s_vertex_shader = "#version 450\n"
1350                                                                                                                   "\n"
1351                                                                                                                   "void main()\n"
1352                                                                                                                   "{\n"
1353                                                                                                                   "    switch(gl_VertexID)\n"
1354                                                                                                                   "    {\n"
1355                                                                                                                   "        case 0:\n"
1356                                                                                                                   "            gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
1357                                                                                                                   "            break;\n"
1358                                                                                                                   "        case 1:\n"
1359                                                                                                                   "            gl_Position = vec4( 1.0, 1.0, 0.0, 1.0);\n"
1360                                                                                                                   "            break;\n"
1361                                                                                                                   "        case 2:\n"
1362                                                                                                                   "            gl_Position = vec4(-1.0,-1.0, 0.0, 1.0);\n"
1363                                                                                                                   "            break;\n"
1364                                                                                                                   "        case 3:\n"
1365                                                                                                                   "            gl_Position = vec4( 1.0,-1.0, 0.0, 1.0);\n"
1366                                                                                                                   "            break;\n"
1367                                                                                                                   "    }\n"
1368                                                                                                                   "}\n";
1369
1370 /* Fragment shader source program. */
1371 template <typename T, glw::GLint S, bool N>
1372 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_head = "#version 450\n"
1373                                                                                                                                  "\n"
1374                                                                                                                                  "layout(pixel_center_integer) in vec4 gl_FragCoord;\n"
1375                                                                                                                                  "\n";
1376
1377 template <typename T, glw::GLint S, bool N>
1378 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_fdecl_lowp = "uniform samplerBuffer texture_input;\n"
1379                                                                                                                                            "out     vec4          texture_output;\n";
1380
1381 template <typename T, glw::GLint S, bool N>
1382 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_idecl_lowp = "uniform isamplerBuffer texture_input;\n"
1383                                                                                                                                            "out     ivec4          texture_output;\n";
1384
1385 template <typename T, glw::GLint S, bool N>
1386 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_udecl_lowp = "uniform usamplerBuffer texture_input;\n"
1387                                                                                                                                            "out     uvec4          texture_output;\n";
1388
1389 template <typename T, glw::GLint S, bool N>
1390 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_fdecl_mediump = "uniform samplerBuffer texture_input;\n"
1391                                                                                                                                                   "out     vec4          texture_output;\n";
1392
1393 template <typename T, glw::GLint S, bool N>
1394 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_idecl_mediump = "uniform isamplerBuffer texture_input;\n"
1395                                                                                                                                                   "out     ivec4          texture_output;\n";
1396
1397 template <typename T, glw::GLint S, bool N>
1398 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_udecl_mediump = "uniform usamplerBuffer texture_input;\n"
1399                                                                                                                                                   "out     uvec4          texture_output;\n";
1400
1401 template <typename T, glw::GLint S, bool N>
1402 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_fdecl_highp = "uniform samplerBuffer texture_input;\n"
1403                                                                                                                                                 "out     vec4          texture_output;\n";
1404
1405 template <typename T, glw::GLint S, bool N>
1406 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_idecl_highp = "uniform isamplerBuffer texture_input;\n"
1407                                                                                                                                                 "out     ivec4          texture_output;\n";
1408
1409 template <typename T, glw::GLint S, bool N>
1410 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_udecl_highp = "uniform usamplerBuffer texture_input;\n"
1411                                                                                                                                                 "out     uvec4          texture_output;\n";
1412
1413 template <typename T, glw::GLint S, bool N>
1414 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_tail =
1415         "\n"
1416         "void main()\n"
1417         "{\n"
1418         "    texture_output = texelFetch(texture_input, int(gl_FragCoord.x));\n"
1419         "}\n";
1420
1421 template class BufferTest<glw::GLbyte, 1, false>;
1422 template class BufferTest<glw::GLbyte, 2, false>;
1423 template class BufferTest<glw::GLbyte, 4, false>;
1424
1425 template class BufferTest<glw::GLubyte, 1, false>;
1426 template class BufferTest<glw::GLubyte, 2, false>;
1427 template class BufferTest<glw::GLubyte, 4, false>;
1428 template class BufferTest<glw::GLubyte, 1, true>;
1429 template class BufferTest<glw::GLubyte, 2, true>;
1430 template class BufferTest<glw::GLubyte, 4, true>;
1431
1432 template class BufferTest<glw::GLshort, 1, false>;
1433 template class BufferTest<glw::GLshort, 2, false>;
1434 template class BufferTest<glw::GLshort, 4, false>;
1435
1436 template class BufferTest<glw::GLushort, 1, false>;
1437 template class BufferTest<glw::GLushort, 2, false>;
1438 template class BufferTest<glw::GLushort, 4, false>;
1439 template class BufferTest<glw::GLushort, 1, true>;
1440 template class BufferTest<glw::GLushort, 2, true>;
1441 template class BufferTest<glw::GLushort, 4, true>;
1442
1443 template class BufferTest<glw::GLint, 1, false>;
1444 template class BufferTest<glw::GLint, 2, false>;
1445 template class BufferTest<glw::GLint, 3, false>;
1446 template class BufferTest<glw::GLint, 4, false>;
1447
1448 template class BufferTest<glw::GLuint, 1, false>;
1449 template class BufferTest<glw::GLuint, 2, false>;
1450 template class BufferTest<glw::GLuint, 3, false>;
1451 template class BufferTest<glw::GLuint, 4, false>;
1452
1453 template class BufferTest<glw::GLfloat, 1, true>;
1454 template class BufferTest<glw::GLfloat, 2, true>;
1455 template class BufferTest<glw::GLfloat, 3, true>;
1456 template class BufferTest<glw::GLfloat, 4, true>;
1457
1458 /******************************** Storage and SubImage Test Implementation   ********************************/
1459
1460 /** @brief Storage Test constructor.
1461  *
1462  *  @param [in] context     OpenGL context.
1463  */
1464 StorageAndSubImageTest::StorageAndSubImageTest(deqp::Context& context)
1465         : deqp::TestCase(context, "textures_storage_and_subimage", "Texture Storage and SubImage Test")
1466         , m_fbo(0)
1467         , m_rbo(0)
1468         , m_po(0)
1469         , m_to(0)
1470         , m_vao(0)
1471 {
1472         /* Intentionally left blank. */
1473 }
1474
1475 /** @brief Count of reference data to be teted.
1476  *
1477  *  @tparam S      Size (# of components).
1478  *  @tparam D      Texture dimenisons.
1479  *
1480  *  @return Count.
1481  */
1482 template <glw::GLint S, glw::GLuint D>
1483 glw::GLuint StorageAndSubImageTest::TestReferenceDataCount()
1484 {
1485         return 2 /* 1D */ * ((D > 1) ? 3 : 1) /* 2D */ * ((D > 2) ? 4 : 1) /* 3D */ * S /* components */;
1486 }
1487
1488 /** @brief Size of reference data to be teted.
1489  *
1490  *  @tparam T      Type.
1491  *  @tparam S      Size (# of components).
1492  *  @tparam D      Texture dimenisons.
1493  *
1494  *  @return Size.
1495  */
1496 template <typename T, glw::GLint S, glw::GLuint D>
1497 glw::GLuint StorageAndSubImageTest::TestReferenceDataSize()
1498 {
1499         return static_cast<glw::GLint>(TestReferenceDataCount<S, D>() * sizeof(T));
1500 }
1501
1502 /** @brief Height, width or depth of reference data to be teted.
1503  *
1504  *  @tparam D      Texture dimenisons.
1505  *
1506  *  @return Height, width or depth.
1507  */
1508 template <>
1509 glw::GLuint StorageAndSubImageTest::TestReferenceDataHeight<2>()
1510 {
1511         return 3;
1512 }
1513
1514 template <>
1515 glw::GLuint StorageAndSubImageTest::TestReferenceDataHeight<3>()
1516 {
1517         return 3;
1518 }
1519
1520 template <>
1521 glw::GLuint StorageAndSubImageTest::TestReferenceDataDepth<3>()
1522 {
1523         return 4;
1524 }
1525
1526 template <glw::GLuint D>
1527 glw::GLuint                       StorageAndSubImageTest::TestReferenceDataWidth()
1528 {
1529         return 2;
1530 }
1531
1532 template <glw::GLuint D>
1533 glw::GLuint                       StorageAndSubImageTest::TestReferenceDataHeight()
1534 {
1535         return 1;
1536 }
1537
1538 template <glw::GLuint D>
1539 glw::GLuint                       StorageAndSubImageTest::TestReferenceDataDepth()
1540 {
1541         return 1;
1542 }
1543
1544 /** @brief Fragment shader declaration selector.
1545  *
1546  *  @tparam T      Type.
1547  *  @tparam N      Normalized flag.
1548  *  @tparam D      Texture dimenisons.
1549  *
1550  *  @return Frgment shader source code part.
1551  */
1552 template <>
1553 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLbyte, false, 1>()
1554 {
1555         return s_fragment_shader_1D_fdecl_lowp;
1556 }
1557
1558 template <>
1559 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLubyte, false, 1>()
1560 {
1561         return s_fragment_shader_1D_idecl_lowp;
1562 }
1563
1564 template <>
1565 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLshort, false, 1>()
1566 {
1567         return s_fragment_shader_1D_udecl_lowp;
1568 }
1569
1570 template <>
1571 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLushort, false, 1>()
1572 {
1573         return s_fragment_shader_1D_fdecl_mediump;
1574 }
1575
1576 template <>
1577 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLint, false, 1>()
1578 {
1579         return s_fragment_shader_1D_idecl_mediump;
1580 }
1581
1582 template <>
1583 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLuint, false, 1>()
1584 {
1585         return s_fragment_shader_1D_udecl_mediump;
1586 }
1587
1588 template <>
1589 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLubyte, true, 1>()
1590 {
1591         return s_fragment_shader_1D_fdecl_highp;
1592 }
1593
1594 template <>
1595 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLushort, true, 1>()
1596 {
1597         return s_fragment_shader_1D_idecl_highp;
1598 }
1599
1600 template <>
1601 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLfloat, true, 1>()
1602 {
1603         return s_fragment_shader_1D_udecl_highp;
1604 }
1605
1606 template <>
1607 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLbyte, false, 2>()
1608 {
1609         return s_fragment_shader_2D_fdecl_lowp;
1610 }
1611
1612 template <>
1613 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLubyte, false, 2>()
1614 {
1615         return s_fragment_shader_2D_idecl_lowp;
1616 }
1617
1618 template <>
1619 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLshort, false, 2>()
1620 {
1621         return s_fragment_shader_2D_udecl_lowp;
1622 }
1623
1624 template <>
1625 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLushort, false, 2>()
1626 {
1627         return s_fragment_shader_2D_fdecl_mediump;
1628 }
1629
1630 template <>
1631 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLint, false, 2>()
1632 {
1633         return s_fragment_shader_2D_idecl_mediump;
1634 }
1635
1636 template <>
1637 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLuint, false, 2>()
1638 {
1639         return s_fragment_shader_2D_udecl_mediump;
1640 }
1641
1642 template <>
1643 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLubyte, true, 2>()
1644 {
1645         return s_fragment_shader_2D_fdecl_highp;
1646 }
1647
1648 template <>
1649 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLushort, true, 2>()
1650 {
1651         return s_fragment_shader_2D_idecl_highp;
1652 }
1653
1654 template <>
1655 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLfloat, true, 2>()
1656 {
1657         return s_fragment_shader_2D_udecl_highp;
1658 }
1659
1660 template <>
1661 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLbyte, false, 3>()
1662 {
1663         return s_fragment_shader_3D_fdecl_lowp;
1664 }
1665
1666 template <>
1667 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLubyte, false, 3>()
1668 {
1669         return s_fragment_shader_3D_idecl_lowp;
1670 }
1671
1672 template <>
1673 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLshort, false, 3>()
1674 {
1675         return s_fragment_shader_3D_udecl_lowp;
1676 }
1677
1678 template <>
1679 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLushort, false, 3>()
1680 {
1681         return s_fragment_shader_3D_fdecl_mediump;
1682 }
1683
1684 template <>
1685 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLint, false, 3>()
1686 {
1687         return s_fragment_shader_3D_idecl_mediump;
1688 }
1689
1690 template <>
1691 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLuint, false, 3>()
1692 {
1693         return s_fragment_shader_3D_udecl_mediump;
1694 }
1695
1696 template <>
1697 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLubyte, true, 3>()
1698 {
1699         return s_fragment_shader_3D_fdecl_highp;
1700 }
1701
1702 template <>
1703 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLushort, true, 3>()
1704 {
1705         return s_fragment_shader_3D_idecl_highp;
1706 }
1707
1708 template <>
1709 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLfloat, true, 3>()
1710 {
1711         return s_fragment_shader_3D_udecl_highp;
1712 }
1713
1714 /** @brief Fragment shader tail selector.
1715  *
1716  *  @tparam D      Texture dimenisons.
1717  *
1718  *  @return Frgment shader source code part.
1719  */
1720 template <>
1721 const glw::GLchar* StorageAndSubImageTest::FragmentShaderTail<1>()
1722 {
1723         return s_fragment_shader_1D_tail;
1724 }
1725
1726 template <>
1727 const glw::GLchar* StorageAndSubImageTest::FragmentShaderTail<2>()
1728 {
1729         return s_fragment_shader_2D_tail;
1730 }
1731
1732 template <>
1733 const glw::GLchar* StorageAndSubImageTest::FragmentShaderTail<3>()
1734 {
1735         return s_fragment_shader_3D_tail;
1736 }
1737
1738 /** @brief Texture target selector.
1739  *
1740  *  @tparam D      Texture dimenisons.
1741  *
1742  *  @return Texture target.
1743  */
1744 template <>
1745 glw::GLenum StorageAndSubImageTest::TextureTarget<1>()
1746 {
1747         return GL_TEXTURE_1D;
1748 }
1749
1750 template <>
1751 glw::GLenum StorageAndSubImageTest::TextureTarget<2>()
1752 {
1753         return GL_TEXTURE_2D;
1754 }
1755
1756 template <>
1757 glw::GLenum StorageAndSubImageTest::TextureTarget<3>()
1758 {
1759         return GL_TEXTURE_3D;
1760 }
1761
1762 /** @brief TextureStorage* wrapper.
1763  *
1764  *  @tparam D      Texture dimenisons.
1765  *  @tparam I      Select between legacy/DSA way.
1766  *
1767  *  @return true if suuceed (in legacy always or throw), false otherwise.
1768  */
1769 template <>
1770 bool StorageAndSubImageTest::TextureStorage<1, true>(glw::GLenum target, glw::GLuint texture, glw::GLsizei levels,
1771                                                                                                          glw::GLenum internalformat, glw::GLsizei width,
1772                                                                                                          glw::GLsizei height, glw::GLsizei depth)
1773 {
1774         (void)texture;
1775         (void)height;
1776         (void)depth;
1777         /* Shortcut for GL functionality. */
1778         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1779
1780         /* Preparing storage. */
1781         gl.texStorage1D(target, levels, internalformat, width);
1782         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexStorage1D has failed");
1783
1784         /* TextureSubImage* (not TextureStorage*) is tested so here we only throw when error occurs. */
1785         return true;
1786 }
1787
1788 /** @brief TextureStorage* wrapper.
1789  *
1790  *  @tparam D      Texture dimenisons.
1791  *  @tparam I      Select between legacy/DSA way.
1792  *
1793  *  @return true if suuceed (in legacy always or throw), false otherwise.
1794  */
1795 template <>
1796 bool StorageAndSubImageTest::TextureStorage<2, true>(glw::GLenum target, glw::GLuint texture, glw::GLsizei levels,
1797                                                                                                          glw::GLenum internalformat, glw::GLsizei width,
1798                                                                                                          glw::GLsizei height, glw::GLsizei depth)
1799 {
1800         (void)texture;
1801         (void)depth;
1802         /* Shortcut for GL functionality. */
1803         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1804
1805         /* Preparing storage. */
1806         gl.texStorage2D(target, levels, internalformat, width, height);
1807         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexStorage2D has failed");
1808
1809         /* TextureSubImage* (not TextureStorage*) is tested so here we only throw when error occurs. */
1810         return true;
1811 }
1812
1813 /** @brief TextureStorage* wrapper.
1814  *
1815  *  @tparam D      Texture dimenisons.
1816  *  @tparam I      Select between legacy/DSA way.
1817  *
1818  *  @return true if suuceed (in legacy always or throw), false otherwise.
1819  */
1820 template <>
1821 bool StorageAndSubImageTest::TextureStorage<3, true>(glw::GLenum target, glw::GLuint texture, glw::GLsizei levels,
1822                                                                                                          glw::GLenum internalformat, glw::GLsizei width,
1823                                                                                                          glw::GLsizei height, glw::GLsizei depth)
1824 {
1825         (void)texture;
1826         /* Shortcut for GL functionality. */
1827         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1828
1829         /* Preparing storage. */
1830         gl.texStorage3D(target, levels, internalformat, width, height, depth);
1831         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexStorage3D has failed");
1832
1833         /* TextureSubImage* (not TextureStorage*) is tested so here we only throw when error occurs. */
1834         return true;
1835 }
1836
1837 /** @brief TextureStorage* wrapper.
1838  *
1839  *  @tparam D      Texture dimenisons.
1840  *  @tparam I      Select between legacy/DSA way.
1841  *
1842  *  @return true if suuceed (in legacy always or throw), false otherwise.
1843  */
1844 template <>
1845 bool StorageAndSubImageTest::TextureStorage<1, false>(glw::GLenum target, glw::GLuint texture, glw::GLsizei levels,
1846                                                                                                           glw::GLenum internalformat, glw::GLsizei width,
1847                                                                                                           glw::GLsizei height, glw::GLsizei depth)
1848 {
1849         (void)target;
1850         (void)height;
1851         (void)depth;
1852         /* Shortcut for GL functionality. */
1853         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1854
1855         /* Preparing storage. */
1856         gl.textureStorage1D(texture, levels, internalformat, width);
1857
1858         /* Error checking. */
1859         glw::GLenum error;
1860
1861         if (GL_NO_ERROR != (error = gl.getError()))
1862         {
1863                 /* Log. */
1864                 m_context.getTestContext().getLog()
1865                         << tcu::TestLog::Message << "glTextureStorage1D unexpectedly generated error " << glu::getErrorStr(error)
1866                         << " during test with levels " << levels << ", internal format " << internalformat << " and width " << width
1867                         << "." << tcu::TestLog::EndMessage;
1868
1869                 CleanTexture();
1870                 CleanErrors();
1871
1872                 return false;
1873         }
1874
1875         return true;
1876 }
1877
1878 /** @brief TextureStorage* wrapper.
1879  *
1880  *  @tparam D      Texture dimenisons.
1881  *  @tparam I      Select between legacy/DSA way.
1882  *
1883  *  @return true if suuceed (in legacy always or throw), false otherwise.
1884  */
1885 template <>
1886 bool StorageAndSubImageTest::TextureStorage<2, false>(glw::GLenum target, glw::GLuint texture, glw::GLsizei levels,
1887                                                                                                           glw::GLenum internalformat, glw::GLsizei width,
1888                                                                                                           glw::GLsizei height, glw::GLsizei depth)
1889 {
1890         (void)target;
1891         (void)depth;
1892         /* Shortcut for GL functionality. */
1893         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1894
1895         /* Preparing storage. */
1896         gl.textureStorage2D(texture, levels, internalformat, width, height);
1897
1898         /* Error checking. */
1899         glw::GLenum error;
1900
1901         if (GL_NO_ERROR != (error = gl.getError()))
1902         {
1903                 /* Log. */
1904                 m_context.getTestContext().getLog()
1905                         << tcu::TestLog::Message << "glTextureStorage2D unexpectedly generated error " << glu::getErrorStr(error)
1906                         << " during test with levels " << levels << ", internal format " << internalformat << ", width " << width
1907                         << " and height " << height << "." << tcu::TestLog::EndMessage;
1908
1909                 CleanTexture();
1910                 CleanErrors();
1911
1912                 return false;
1913         }
1914
1915         return true;
1916 }
1917
1918 /** @brief TextureStorage* wrapper.
1919  *
1920  *  @tparam D      Texture dimenisons.
1921  *  @tparam I      Select between legacy/DSA way.
1922  *
1923  *  @return true if suuceed (in legacy always or throw), false otherwise.
1924  */
1925 template <>
1926 bool StorageAndSubImageTest::TextureStorage<3, false>(glw::GLenum target, glw::GLuint texture, glw::GLsizei levels,
1927                                                                                                           glw::GLenum internalformat, glw::GLsizei width,
1928                                                                                                           glw::GLsizei height, glw::GLsizei depth)
1929 {
1930         (void)target;
1931         /* Shortcut for GL functionality. */
1932         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1933
1934         /* Preparing storage. */
1935         gl.textureStorage3D(texture, levels, internalformat, width, height, depth);
1936
1937         /* Error checking. */
1938         glw::GLenum error;
1939
1940         if (GL_NO_ERROR != (error = gl.getError()))
1941         {
1942                 /* Log. */
1943                 m_context.getTestContext().getLog()
1944                         << tcu::TestLog::Message << "glTextureStorage3D unexpectedly generated error " << glu::getErrorStr(error)
1945                         << " during test with levels " << levels << ", internal format " << glu::getTextureFormatStr(internalformat)
1946                         << ", width " << width << ", height " << height << " and depth " << depth << "."
1947                         << tcu::TestLog::EndMessage;
1948
1949                 CleanTexture();
1950                 CleanErrors();
1951
1952                 return false;
1953         }
1954
1955         return true;
1956 }
1957
1958 /** @brief TextureSubImage* wrapper.
1959  *
1960  *  @tparam D      Texture dimenisons.
1961  *  @tparam I      Select between legacy/DSA way.
1962  *
1963  *  @return true if suuceed (in legacy always or throw), false otherwise.
1964  */
1965 template <>
1966 bool StorageAndSubImageTest::TextureSubImage<1, false>(glw::GLenum target, glw::GLuint texture, glw::GLint level,
1967                                                                                                            glw::GLint internalformat, glw::GLsizei width,
1968                                                                                                            glw::GLsizei height, glw::GLsizei depth, glw::GLenum format,
1969                                                                                                            glw::GLenum type, const glw::GLvoid* data)
1970 {
1971         (void)texture;
1972         (void)internalformat;
1973         (void)height;
1974         (void)depth;
1975         /* Shortcut for GL functionality. */
1976         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1977
1978         /* Action. */
1979         gl.texSubImage1D(target, level, 0, width, format, type, data);
1980         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexSubImage1D has failed");
1981
1982         /* TextureStorage* (not TextureSubImage) is tested so here we only throw when error occurs. */
1983         return true;
1984 }
1985
1986 /** @brief TextureSubImage* wrapper.
1987  *
1988  *  @tparam D      Texture dimenisons.
1989  *  @tparam I      Select between legacy/DSA way.
1990  *
1991  *  @return true if suuceed (in legacy always or throw), false otherwise.
1992  */
1993 template <>
1994 bool StorageAndSubImageTest::TextureSubImage<2, false>(glw::GLenum target, glw::GLuint texture, glw::GLint level,
1995                                                                                                            glw::GLint internalformat, glw::GLsizei width,
1996                                                                                                            glw::GLsizei height, glw::GLsizei depth, glw::GLenum format,
1997                                                                                                            glw::GLenum type, const glw::GLvoid* data)
1998 {
1999         (void)texture;
2000         (void)internalformat;
2001         (void)depth;
2002         /* Shortcut for GL functionality. */
2003         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2004
2005         /* Action. */
2006         gl.texSubImage2D(target, level, 0, 0, width, height, format, type, data);
2007         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexSubImage2D has failed");
2008
2009         /* TextureStorage* (not TextureSubImage) is tested so here we only throw when error occurs. */
2010         return true;
2011 }
2012
2013 /** @brief TextureSubImage* wrapper.
2014  *
2015  *  @tparam D      Texture dimenisons.
2016  *  @tparam I      Select between legacy/DSA way.
2017  *
2018  *  @return true if suuceed (in legacy always or throw), false otherwise.
2019  */
2020 template <>
2021 bool StorageAndSubImageTest::TextureSubImage<3, false>(glw::GLenum target, glw::GLuint texture, glw::GLint level,
2022                                                                                                            glw::GLint internalformat, glw::GLsizei width,
2023                                                                                                            glw::GLsizei height, glw::GLsizei depth, glw::GLenum format,
2024                                                                                                            glw::GLenum type, const glw::GLvoid* data)
2025 {
2026         (void)texture;
2027         (void)internalformat;
2028         /* Shortcut for GL functionality. */
2029         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2030
2031         /* Action. */
2032         gl.texSubImage3D(target, level, 0, 0, 0, width, height, depth, format, type, data);
2033         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexSubImage3D has failed");
2034
2035         /* TextureStorage* (not TextureSubImage) is tested so here we only throw when error occurs. */
2036         return true;
2037 }
2038
2039 /** @brief TextureSubImage* wrapper.
2040  *
2041  *  @tparam D      Texture dimenisons.
2042  *  @tparam I      Select between legacy/DSA way.
2043  *
2044  *  @return true if suuceed (in legacy always or throw), false otherwise.
2045  */
2046 template <>
2047 bool StorageAndSubImageTest::TextureSubImage<1, true>(glw::GLenum target, glw::GLuint texture, glw::GLint level,
2048                                                                                                           glw::GLint internalformat, glw::GLsizei width,
2049                                                                                                           glw::GLsizei height, glw::GLsizei depth, glw::GLenum format,
2050                                                                                                           glw::GLenum type, const glw::GLvoid* data)
2051 {
2052         (void)target;
2053         (void)internalformat;
2054         (void)height;
2055         (void)depth;
2056         /* Shortcut for GL functionality. */
2057         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2058
2059         /* Action. */
2060         gl.textureSubImage1D(texture, level, 0, width, format, type, data);
2061
2062         /* Error checking. */
2063         glw::GLenum error;
2064
2065         if (GL_NO_ERROR != (error = gl.getError()))
2066         {
2067                 /* Log. */
2068                 m_context.getTestContext().getLog()
2069                         << tcu::TestLog::Message << "glTextureSubImage1D unexpectedly generated error " << glu::getErrorStr(error)
2070                         << " during test with level " << level << ", width " << width << ", format "
2071                         << glu::getTextureFormatStr(format) << " and type " << glu::getTypeStr(type) << "."
2072                         << tcu::TestLog::EndMessage;
2073
2074                 CleanTexture();
2075                 CleanErrors();
2076
2077                 return false;
2078         }
2079
2080         return true;
2081 }
2082
2083 /** @brief TextureSubImage* wrapper.
2084  *
2085  *  @tparam D      Texture dimenisons.
2086  *  @tparam I      Select between legacy/DSA way.
2087  *
2088  *  @return true if suuceed (in legacy always or throw), false otherwise.
2089  */
2090 template <>
2091 bool StorageAndSubImageTest::TextureSubImage<2, true>(glw::GLenum target, glw::GLuint texture, glw::GLint level,
2092                                                                                                           glw::GLint internalformat, glw::GLsizei width,
2093                                                                                                           glw::GLsizei height, glw::GLsizei depth, glw::GLenum format,
2094                                                                                                           glw::GLenum type, const glw::GLvoid* data)
2095 {
2096         (void)target;
2097         (void)internalformat;
2098         (void)depth;
2099         /* Shortcut for GL functionality. */
2100         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2101
2102         /* Action. */
2103         gl.textureSubImage2D(texture, level, 0, 0, width, height, format, type, data);
2104
2105         /* Error checking. */
2106         glw::GLenum error;
2107
2108         if (GL_NO_ERROR != (error = gl.getError()))
2109         {
2110                 /* Log. */
2111                 m_context.getTestContext().getLog()
2112                         << tcu::TestLog::Message << "glTextureSubImage2D unexpectedly generated error " << glu::getErrorStr(error)
2113                         << " during test with level " << level << ", width " << width << ", height " << height << ", format "
2114                         << glu::getTextureFormatStr(format) << " and type " << glu::getTypeStr(type) << "."
2115                         << tcu::TestLog::EndMessage;
2116
2117                 CleanTexture();
2118                 CleanErrors();
2119
2120                 return false;
2121         }
2122
2123         return true;
2124 }
2125
2126 /** @brief TextureSubImage* wrapper.
2127  *
2128  *  @tparam D      Texture dimenisons.
2129  *  @tparam I      Select between legacy/DSA way.
2130  *
2131  *  @return true if suuceed (in legacy always or throw), false otherwise.
2132  */
2133 template <>
2134 bool StorageAndSubImageTest::TextureSubImage<3, true>(glw::GLenum target, glw::GLuint texture, glw::GLint level,
2135                                                                                                           glw::GLint internalformat, glw::GLsizei width,
2136                                                                                                           glw::GLsizei height, glw::GLsizei depth, glw::GLenum format,
2137                                                                                                           glw::GLenum type, const glw::GLvoid* data)
2138 {
2139         (void)target;
2140         (void)internalformat;
2141         /* Shortcut for GL functionality. */
2142         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2143
2144         /* Action. */
2145         gl.textureSubImage3D(texture, level, 0, 0, 0, width, height, depth, format, type, data);
2146
2147         /* Error checking. */
2148         glw::GLenum error;
2149
2150         if (GL_NO_ERROR != (error = gl.getError()))
2151         {
2152                 /* Log. */
2153                 m_context.getTestContext().getLog()
2154                         << tcu::TestLog::Message << "glTextureSubImage3D unexpectedly generated error " << glu::getErrorStr(error)
2155                         << " during test with level " << level << ", width " << width << ", height " << height << ", depth "
2156                         << depth << ", format " << glu::getTextureFormatStr(format) << " and type " << glu::getTypeStr(type) << "."
2157                         << tcu::TestLog::EndMessage;
2158
2159                 CleanTexture();
2160                 CleanErrors();
2161
2162                 return false;
2163         }
2164
2165         return true;
2166 }
2167
2168 /** @brief Create texture.
2169  *
2170  *  @tparam T      Type.
2171  *  @tparam S      Size (# of components).
2172  *  @tparam N      Is normalized.
2173  *  @tparam D      Dimmensions.
2174  *  @tparam I      Test SubImage or Storage.
2175  *
2176  *  @return True if succeded, false otherwise.
2177  */
2178 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2179 bool StorageAndSubImageTest::CreateTexture()
2180 {
2181         /* Shortcut for GL functionality. */
2182         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2183
2184         /* Objects creation. */
2185         gl.genTextures(1, &m_to);
2186         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
2187
2188         gl.bindTexture(TextureTarget<D>(), m_to);
2189         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
2190
2191         /* Storage creation. */
2192         if (TextureStorage<D, I>(TextureTarget<D>(), m_to, 1, InternalFormat<T, S, N>(), TestReferenceDataWidth<D>(),
2193                                                          TestReferenceDataHeight<D>(), TestReferenceDataDepth<D>()))
2194         {
2195                 /* Data setup. */
2196                 if (TextureSubImage<D, I>(TextureTarget<D>(), m_to, 0, InternalFormat<T, S, N>(), TestReferenceDataWidth<D>(),
2197                                                                   TestReferenceDataHeight<D>(), TestReferenceDataDepth<D>(), Format<S, N>(), Type<T>(),
2198                                                                   ReferenceData<T, N>()))
2199                 {
2200                         glTexParameteri(TextureTarget<D>(), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2201                         glTexParameteri(TextureTarget<D>(), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2202                         return true;
2203                 }
2204         }
2205
2206         CleanTexture();
2207
2208         return false;
2209 }
2210
2211 /** @brief Compre results with the reference.
2212  *
2213  *  @tparam T      Type.
2214  *  @tparam S      Size (# of components).
2215  *  @tparam N      Is normalized.
2216  *
2217  *  @return True if equal, false otherwise.
2218  */
2219 template <typename T, glw::GLint S, bool N, glw::GLuint D>
2220 bool StorageAndSubImageTest::Check()
2221 {
2222         /* Shortcut for GL functionality. */
2223         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2224
2225         /* Fetching data. */
2226         std::vector<T> result(TestReferenceDataCount<S, D>());
2227
2228         gl.pixelStorei(GL_UNPACK_ALIGNMENT, sizeof(T));
2229         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
2230
2231         gl.pixelStorei(GL_PACK_ALIGNMENT, sizeof(T));
2232         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
2233
2234         glw::GLuint fbo_size_x = 0;
2235
2236         switch (D)
2237         {
2238         case 1:
2239                 fbo_size_x = 2;
2240                 break;
2241         case 2:
2242                 fbo_size_x = 2 * 3;
2243                 break;
2244         case 3:
2245                 fbo_size_x = 2 * 3 * 4;
2246                 break;
2247         default:
2248                 throw 0;
2249         }
2250
2251         gl.readnPixels(0, 0, fbo_size_x, 1, Format<S, N>(), Type<T>(), TestReferenceDataSize<T, S, D>(),
2252                                    (glw::GLvoid*)(&result[0]));
2253         GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels has failed");
2254
2255         /* Comparison. */
2256         for (glw::GLuint i = 0; i < TestReferenceDataCount<S, D>(); ++i)
2257         {
2258                 if (!Compare<T>(result[i], ReferenceData<T, N>()[i]))
2259                 {
2260                         return false;
2261                 }
2262         }
2263
2264         return true;
2265 }
2266
2267 /** @brief Test case function.
2268  *
2269  *  @tparam T       Type.
2270  *  @tparam S       Size (# of components).
2271  *  @tparam N       Is normalized.
2272  *  @tparam D       Number of texture dimensions.
2273  *
2274  *  @return True if test succeeded, false otherwise.
2275  */
2276 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2277 bool StorageAndSubImageTest::Test()
2278 {
2279         /* Setup. */
2280         PrepareFramebuffer(InternalFormat<T, S, N>(), D);
2281
2282         if (!CreateTexture<T, S, N, D, I>())
2283         {
2284                 return false;
2285         }
2286
2287         /* Action. */
2288         Draw();
2289
2290         /* Compare results with reference. */
2291         bool result = Check<T, S, N, D>();
2292
2293         /* Cleanup. */
2294         CleanTexture();
2295         CleanFramebuffer();
2296         CleanErrors();
2297
2298         /* Pass result. */
2299         return result;
2300 }
2301
2302 /** @brief Lopp test function over S.
2303  *
2304  *  @tparam T      Type.
2305  *  @tparam N      Is normalized.
2306  *  @tparam D      Texture dimension.
2307  *  @tparam I      Choose between SubImage and Storage tests.
2308  *
2309  *  @param [in] skip_rgb            Skip test of S = 3 (needed for some formats).
2310  *
2311  *  @return True if tests succeeded, false otherwise.
2312  */
2313 template <typename T, bool N, glw::GLuint D, bool I>
2314 bool StorageAndSubImageTest::LoopTestOverS(bool skip_rgb)
2315 {
2316         /* Prepare one program per test loop. */
2317         PrepareProgram(FragmentShaderDeclaration<T, N, D>(), FragmentShaderTail<D>());
2318
2319         /* Run tests. */
2320         bool result = true;
2321
2322         result &= Test<T, 1, N, D, I>();
2323
2324         result &= Test<T, 2, N, D, I>();
2325
2326         if (!skip_rgb)
2327         {
2328                 result &= Test<T, 3, N, D, I>();
2329         }
2330
2331         result &= Test<T, 4, N, D, I>();
2332
2333         /* Cleanup.*/
2334         CleanProgram();
2335         CleanErrors();
2336
2337         /* Pass result. */
2338         return result;
2339 }
2340
2341 /** @brief Lopp test function over D and over S.
2342  *
2343  *  @tparam T      Type.
2344  *  @tparam N      Is normalized.
2345  *  @tparam I      Choose between SubImage and Storage tests.
2346  *
2347  *  @param [in] skip_rgb            Skip test of S = 3 (needed for some formats).
2348  *
2349  *  @return True if tests succeeded, false otherwise.
2350  */
2351 template <typename T, bool N, bool I>
2352 bool StorageAndSubImageTest::LoopTestOverDOverS(bool skip_rgb)
2353 {
2354         bool result = true;
2355
2356         result &= LoopTestOverS<T, N, 1, I>(skip_rgb);
2357         result &= LoopTestOverS<T, N, 2, I>(skip_rgb);
2358         result &= LoopTestOverS<T, N, 3, I>(skip_rgb);
2359
2360         return result;
2361 }
2362
2363 /** @brief Function prepares framebuffer with internal format color attachment.
2364  *         Viewport is set up. Content of the framebuffer is cleared.
2365  *
2366  *  @note The function may throw if unexpected error has occured.
2367  */
2368 void StorageAndSubImageTest::PrepareFramebuffer(const glw::GLenum internal_format, const glw::GLuint D)
2369 {
2370         /* Shortcut for GL functionality. */
2371         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2372
2373         /* Prepare framebuffer. */
2374         gl.genFramebuffers(1, &m_fbo);
2375         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
2376
2377         gl.genRenderbuffers(1, &m_rbo);
2378         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
2379
2380         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
2381         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
2382
2383         gl.bindRenderbuffer(GL_RENDERBUFFER, m_rbo);
2384         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
2385
2386         glw::GLuint fbo_size_x = 0;
2387
2388         switch (D)
2389         {
2390         case 1:
2391                 fbo_size_x = 2;
2392                 break;
2393         case 2:
2394                 fbo_size_x = 2 * 3;
2395                 break;
2396         case 3:
2397                 fbo_size_x = 2 * 3 * 4;
2398                 break;
2399         default:
2400                 throw 0;
2401         }
2402
2403         gl.renderbufferStorage(GL_RENDERBUFFER, internal_format, fbo_size_x, 1);
2404         GLU_EXPECT_NO_ERROR(gl.getError(), "glRenderbufferStorage call failed.");
2405
2406         gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_rbo);
2407         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
2408
2409         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
2410         {
2411                 throw 0;
2412         }
2413
2414         gl.viewport(0, 0, fbo_size_x, 1);
2415         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
2416
2417         /* Clear framebuffer's content. */
2418         gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
2419         GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
2420
2421         gl.clear(GL_COLOR_BUFFER_BIT);
2422         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
2423 }
2424
2425 /** @brief Prepare program
2426  *
2427  *  @param [in] variable_declaration      Variables declaration part of fragment shader source code.
2428  *  @param [in] tail                      Tail part of fragment shader source code.
2429  */
2430 void StorageAndSubImageTest::PrepareProgram(const glw::GLchar* variable_declaration, const glw::GLchar* tail)
2431 {
2432         /* Shortcut for GL functionality */
2433         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2434
2435         struct Shader
2436         {
2437                 glw::GLchar const* source[3];
2438                 glw::GLsizei const count;
2439                 glw::GLenum const  type;
2440                 glw::GLuint                id;
2441         } shader[] = { { { s_vertex_shader, NULL, NULL }, 1, GL_VERTEX_SHADER, 0 },
2442                                    { { s_fragment_shader_head, variable_declaration, tail }, 3, GL_FRAGMENT_SHADER, 0 } };
2443
2444         glw::GLuint const shader_count = sizeof(shader) / sizeof(shader[0]);
2445
2446         try
2447         {
2448                 /* Create program. */
2449                 m_po = gl.createProgram();
2450                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateProgram call failed.");
2451
2452                 /* Shader compilation. */
2453
2454                 for (glw::GLuint i = 0; i < shader_count; ++i)
2455                 {
2456                         {
2457                                 shader[i].id = gl.createShader(shader[i].type);
2458
2459                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateShader call failed.");
2460
2461                                 gl.attachShader(m_po, shader[i].id);
2462
2463                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glAttachShader call failed.");
2464
2465                                 gl.shaderSource(shader[i].id, shader[i].count, shader[i].source, NULL);
2466
2467                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource call failed.");
2468
2469                                 gl.compileShader(shader[i].id);
2470
2471                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader call failed.");
2472
2473                                 glw::GLint status = GL_FALSE;
2474
2475                                 gl.getShaderiv(shader[i].id, GL_COMPILE_STATUS, &status);
2476                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
2477
2478                                 if (GL_FALSE == status)
2479                                 {
2480                                         glw::GLint log_size = 0;
2481                                         gl.getShaderiv(shader[i].id, GL_INFO_LOG_LENGTH, &log_size);
2482                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
2483
2484                                         glw::GLchar* log_text = new glw::GLchar[log_size];
2485
2486                                         gl.getShaderInfoLog(shader[i].id, log_size, NULL, &log_text[0]);
2487
2488                                         m_context.getTestContext().getLog()
2489                                                 << tcu::TestLog::Message << "Shader compilation has failed.\n"
2490                                                 << "Shader type: " << glu::getShaderTypeStr(shader[i].type) << "\n"
2491                                                 << "Shader compilation error log:\n"
2492                                                 << log_text << "\n"
2493                                                 << "Shader source code:\n"
2494                                                 << shader[i].source[0] << (shader[i].source[1] ? shader[i].source[1] : "")
2495                                                 << (shader[i].source[2] ? shader[i].source[2] : "") << "\n"
2496                                                 << tcu::TestLog::EndMessage;
2497
2498                                         delete[] log_text;
2499
2500                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog call failed.");
2501
2502                                         throw 0;
2503                                 }
2504                         }
2505                 }
2506
2507                 /* Link. */
2508                 gl.linkProgram(m_po);
2509
2510                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTransformFeedbackVaryings call failed.");
2511
2512                 glw::GLint status = GL_FALSE;
2513
2514                 gl.getProgramiv(m_po, GL_LINK_STATUS, &status);
2515
2516                 if (GL_TRUE == status)
2517                 {
2518                         for (glw::GLuint i = 0; i < shader_count; ++i)
2519                         {
2520                                 if (shader[i].id)
2521                                 {
2522                                         gl.detachShader(m_po, shader[i].id);
2523
2524                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glDetachShader call failed.");
2525                                 }
2526                         }
2527                 }
2528                 else
2529                 {
2530                         glw::GLint log_size = 0;
2531
2532                         gl.getProgramiv(m_po, GL_INFO_LOG_LENGTH, &log_size);
2533
2534                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv call failed.");
2535
2536                         glw::GLchar* log_text = new glw::GLchar[log_size];
2537
2538                         gl.getProgramInfoLog(m_po, log_size, NULL, &log_text[0]);
2539
2540                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "Program linkage has failed due to:\n"
2541                                                                                                 << log_text << "\n"
2542                                                                                                 << tcu::TestLog::EndMessage;
2543
2544                         delete[] log_text;
2545
2546                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramInfoLog call failed.");
2547
2548                         throw 0;
2549                 }
2550         }
2551         catch (...)
2552         {
2553                 if (m_po)
2554                 {
2555                         gl.deleteProgram(m_po);
2556
2557                         m_po = 0;
2558                 }
2559         }
2560
2561         for (glw::GLuint i = 0; i < shader_count; ++i)
2562         {
2563                 if (0 != shader[i].id)
2564                 {
2565                         gl.deleteShader(shader[i].id);
2566
2567                         shader[i].id = 0;
2568                 }
2569         }
2570
2571         if (0 == m_po)
2572         {
2573                 throw 0;
2574         }
2575 }
2576
2577 /** @brief Prepare VAO.
2578  */
2579 void StorageAndSubImageTest::PrepareVertexArray()
2580 {
2581         /* Shortcut for GL functionality. */
2582         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2583
2584         gl.genVertexArrays(1, &m_vao);
2585         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays has failed");
2586
2587         gl.bindVertexArray(m_vao);
2588         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray has failed");
2589 }
2590
2591 /** @brief Test's draw call.
2592  */
2593 void StorageAndSubImageTest::Draw()
2594 {
2595         /* Shortcut for GL functionality. */
2596         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2597
2598         gl.useProgram(m_po);
2599         GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed");
2600
2601         gl.activeTexture(GL_TEXTURE0);
2602         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
2603
2604         gl.bindTextureUnit(0, m_to);
2605         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
2606
2607         gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
2608         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed");
2609 }
2610
2611 /** @brief Clean GL objects, test variables and GL errors.
2612  */
2613 void StorageAndSubImageTest::CleanTexture()
2614 {
2615         /* Shortcut for GL functionality. */
2616         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2617
2618         /* Texture. */
2619         if (m_to)
2620         {
2621                 gl.deleteTextures(1, &m_to);
2622
2623                 m_to = 0;
2624         }
2625 }
2626
2627 /** @brief Clean GL objects, test variables and GL errors.
2628  */
2629 void StorageAndSubImageTest::CleanFramebuffer()
2630 {
2631         /* Shortcut for GL functionality. */
2632         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2633
2634         /* Framebuffer. */
2635         if (m_fbo)
2636         {
2637                 gl.deleteFramebuffers(1, &m_fbo);
2638
2639                 m_fbo = 0;
2640         }
2641
2642         /* Renderbuffer. */
2643         if (m_rbo)
2644         {
2645                 gl.deleteRenderbuffers(1, &m_rbo);
2646
2647                 m_rbo = 0;
2648         }
2649 }
2650
2651 /** @brief Clean GL objects, test variables and GL errors.
2652  */
2653 void StorageAndSubImageTest::CleanProgram()
2654 {
2655         /* Shortcut for GL functionality. */
2656         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2657
2658         /* Program. */
2659         if (m_po)
2660         {
2661                 gl.useProgram(0);
2662
2663                 gl.deleteProgram(m_po);
2664
2665                 m_po = 0;
2666         }
2667 }
2668
2669 /** @brief Clean GL objects, test variables and GL errors.
2670  */
2671 void StorageAndSubImageTest::CleanErrors()
2672 {
2673         /* Shortcut for GL functionality. */
2674         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2675
2676         /* Query all errors until GL_NO_ERROR occure. */
2677         while (GL_NO_ERROR != gl.getError())
2678                 ;
2679 }
2680
2681 /** @brief Clean GL objects, test variables and GL errors.
2682  */
2683 void StorageAndSubImageTest::CleanVertexArray()
2684 {
2685         /* Shortcut for GL functionality. */
2686         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2687
2688         if (m_vao)
2689         {
2690                 gl.bindVertexArray(0);
2691
2692                 gl.deleteVertexArrays(1, &m_vao);
2693
2694                 m_vao = 0;
2695         }
2696 }
2697
2698 /** @brief Iterate Storage Test cases.
2699  *
2700  *  @return Iteration result.
2701  */
2702 tcu::TestNode::IterateResult StorageAndSubImageTest::iterate()
2703 {
2704         /* Shortcut for GL functionality. */
2705         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2706
2707         /* Get context setup. */
2708         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
2709         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
2710
2711         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
2712         {
2713                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
2714
2715                 return STOP;
2716         }
2717
2718         /* Running tests. */
2719         bool is_ok      = true;
2720         bool is_error = false;
2721
2722         try
2723         {
2724                 PrepareVertexArray();
2725
2726                 /* Test TextureStorage* */
2727                 is_ok &= LoopTestOverDOverS<glw::GLbyte, false, false>(true);
2728                 is_ok &= LoopTestOverDOverS<glw::GLubyte, false, false>(true);
2729                 is_ok &= LoopTestOverDOverS<glw::GLshort, false, false>(true);
2730                 is_ok &= LoopTestOverDOverS<glw::GLushort, false, false>(true);
2731                 is_ok &= LoopTestOverDOverS<glw::GLint, false, false>(false);
2732                 is_ok &= LoopTestOverDOverS<glw::GLuint, false, false>(false);
2733                 is_ok &= LoopTestOverDOverS<glw::GLubyte, true, false>(true);
2734                 is_ok &= LoopTestOverDOverS<glw::GLushort, true, false>(true);
2735                 is_ok &= LoopTestOverDOverS<glw::GLfloat, true, false>(false);
2736
2737                 /* Test TextureSubImage* */
2738                 is_ok &= LoopTestOverDOverS<glw::GLbyte, false, true>(true);
2739                 is_ok &= LoopTestOverDOverS<glw::GLubyte, false, true>(true);
2740                 is_ok &= LoopTestOverDOverS<glw::GLshort, false, true>(true);
2741                 is_ok &= LoopTestOverDOverS<glw::GLushort, false, true>(true);
2742                 is_ok &= LoopTestOverDOverS<glw::GLint, false, true>(false);
2743                 is_ok &= LoopTestOverDOverS<glw::GLuint, false, true>(false);
2744                 is_ok &= LoopTestOverDOverS<glw::GLubyte, true, true>(true);
2745                 is_ok &= LoopTestOverDOverS<glw::GLushort, true, true>(true);
2746                 is_ok &= LoopTestOverDOverS<glw::GLfloat, true, true>(false);
2747         }
2748         catch (...)
2749         {
2750                 is_ok   = false;
2751                 is_error = true;
2752         }
2753
2754         /* Cleanup. */
2755         CleanTexture();
2756         CleanFramebuffer();
2757         CleanProgram();
2758         CleanErrors();
2759         CleanVertexArray();
2760
2761         /* Errors clean up. */
2762         while (gl.getError())
2763                 ;
2764
2765         /* Result's setup. */
2766         if (is_ok)
2767         {
2768                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
2769         }
2770         else
2771         {
2772                 if (is_error)
2773                 {
2774                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
2775                 }
2776                 else
2777                 {
2778                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
2779                 }
2780         }
2781
2782         return STOP;
2783 }
2784
2785 /* Vertex shader source code. */
2786 const glw::GLchar* StorageAndSubImageTest::s_vertex_shader = "#version 450\n"
2787                                                                                                                          "\n"
2788                                                                                                                          "void main()\n"
2789                                                                                                                          "{\n"
2790                                                                                                                          "    switch(gl_VertexID)\n"
2791                                                                                                                          "    {\n"
2792                                                                                                                          "        case 0:\n"
2793                                                                                                                          "            gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
2794                                                                                                                          "            break;\n"
2795                                                                                                                          "        case 1:\n"
2796                                                                                                                          "            gl_Position = vec4( 1.0, 1.0, 0.0, 1.0);\n"
2797                                                                                                                          "            break;\n"
2798                                                                                                                          "        case 2:\n"
2799                                                                                                                          "            gl_Position = vec4(-1.0,-1.0, 0.0, 1.0);\n"
2800                                                                                                                          "            break;\n"
2801                                                                                                                          "        case 3:\n"
2802                                                                                                                          "            gl_Position = vec4( 1.0,-1.0, 0.0, 1.0);\n"
2803                                                                                                                          "            break;\n"
2804                                                                                                                          "    }\n"
2805                                                                                                                          "}\n";
2806
2807 /* Fragment shader source program. */
2808 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_head =
2809         "#version 450\n"
2810         "\n"
2811         "layout(pixel_center_integer) in vec4 gl_FragCoord;\n"
2812         "\n";
2813
2814 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_1D_fdecl_lowp =
2815         "uniform  sampler1D texture_input;\nout     vec4          texture_output;\n";
2816 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_1D_idecl_lowp =
2817         "uniform isampler1D texture_input;\nout     ivec4         texture_output;\n";
2818 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_1D_udecl_lowp =
2819         "uniform usampler1D texture_input;\nout     uvec4         texture_output;\n";
2820 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_1D_fdecl_mediump =
2821         "uniform  sampler1D texture_input;\nout     vec4          texture_output;\n";
2822 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_1D_idecl_mediump =
2823         "uniform isampler1D texture_input;\nout     ivec4         texture_output;\n";
2824 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_1D_udecl_mediump =
2825         "uniform usampler1D texture_input;\nout     uvec4         texture_output;\n";
2826 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_1D_fdecl_highp =
2827         "uniform  sampler1D texture_input;\nout     vec4          texture_output;\n";
2828 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_1D_idecl_highp =
2829         "uniform isampler1D texture_input;\nout     ivec4         texture_output;\n";
2830 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_1D_udecl_highp =
2831         "uniform usampler1D texture_input;\nout     uvec4         texture_output;\n";
2832
2833 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_2D_fdecl_lowp =
2834         "uniform  sampler2D texture_input;\nout     vec4          texture_output;\n";
2835 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_2D_idecl_lowp =
2836         "uniform isampler2D texture_input;\nout     ivec4         texture_output;\n";
2837 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_2D_udecl_lowp =
2838         "uniform usampler2D texture_input;\nout     uvec4         texture_output;\n";
2839 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_2D_fdecl_mediump =
2840         "uniform  sampler2D texture_input;\nout     vec4          texture_output;\n";
2841 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_2D_idecl_mediump =
2842         "uniform isampler2D texture_input;\nout     ivec4         texture_output;\n";
2843 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_2D_udecl_mediump =
2844         "uniform usampler2D texture_input;\nout     uvec4         texture_output;\n";
2845 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_2D_fdecl_highp =
2846         "uniform  sampler2D texture_input;\nout     vec4          texture_output;\n";
2847 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_2D_idecl_highp =
2848         "uniform isampler2D texture_input;\nout     ivec4         texture_output;\n";
2849 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_2D_udecl_highp =
2850         "uniform usampler2D texture_input;\nout     uvec4         texture_output;\n";
2851
2852 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_3D_fdecl_lowp =
2853         "uniform  sampler3D texture_input;\nout     vec4          texture_output;\n";
2854 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_3D_idecl_lowp =
2855         "uniform isampler3D texture_input;\nout     ivec4         texture_output;\n";
2856 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_3D_udecl_lowp =
2857         "uniform usampler3D texture_input;\nout     uvec4         texture_output;\n";
2858 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_3D_fdecl_mediump =
2859         "uniform  sampler3D texture_input;\nout     vec4          texture_output;\n";
2860 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_3D_idecl_mediump =
2861         "uniform isampler3D texture_input;\nout     ivec4         texture_output;\n";
2862 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_3D_udecl_mediump =
2863         "uniform usampler3D texture_input;\nout     uvec4         texture_output;\n";
2864 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_3D_fdecl_highp =
2865         "uniform  sampler3D texture_input;\nout     vec4          texture_output;\n";
2866 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_3D_idecl_highp =
2867         "uniform isampler3D texture_input;\nout     ivec4         texture_output;\n";
2868 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_3D_udecl_highp =
2869         "uniform usampler3D texture_input;\nout     uvec4         texture_output;\n";
2870
2871 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_1D_tail =
2872         "\n"
2873         "void main()\n"
2874         "{\n"
2875         "    texture_output = texelFetch(texture_input, int(gl_FragCoord.x), 0);\n"
2876         "}\n";
2877
2878 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_2D_tail =
2879         "\n"
2880         "void main()\n"
2881         "{\n"
2882         "    texture_output = texelFetch(texture_input, ivec2(int(gl_FragCoord.x) % 2, int(floor(gl_FragCoord.x / 2))), "
2883         "0);\n"
2884         "}\n";
2885
2886 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_3D_tail =
2887         "\n"
2888         "void main()\n"
2889         "{\n"
2890         "    texture_output = texelFetch(texture_input, ivec3(int(gl_FragCoord.x) % 2, int(floor(gl_FragCoord.x / 2)) % 3, "
2891         "int(floor(gl_FragCoord.x / 2 / 3))), 0);\n"
2892         "}\n";
2893
2894 /******************************** Storage Multisample Test Implementation   ********************************/
2895
2896 /** @brief Storage Multisample Test constructor.
2897  *
2898  *  @param [in] context     OpenGL context.
2899  */
2900 StorageMultisampleTest::StorageMultisampleTest(deqp::Context& context)
2901         : deqp::TestCase(context, "textures_storage_multisample", "Texture Storage Multisample Test")
2902         , m_fbo_ms(0)
2903         , m_fbo_aux(0)
2904         , m_to_ms(0)
2905         , m_po_ms(0)
2906         , m_po_aux(0)
2907         , m_to(0)
2908         , m_to_aux(0)
2909         , m_vao(0)
2910 {
2911         /* Intentionally left blank. */
2912 }
2913
2914 /** @brief Count of reference data to be teted.
2915  *
2916  *  @tparam S      Size (# of components).
2917  *  @tparam D      Texture dimenisons.
2918  *
2919  *  @return Count.
2920  */
2921 template <glw::GLint S, glw::GLuint D>
2922 glw::GLuint StorageMultisampleTest::TestReferenceDataCount()
2923 {
2924         return 2 /* 1D */ * ((D > 1) ? 3 : 1) /* 2D */ * ((D > 2) ? 4 : 1) /* 3D */ * S /* components */;
2925 }
2926
2927 /** @brief Size of reference data to be teted.
2928  *
2929  *  @tparam T      Type.
2930  *  @tparam S      Size (# of components).
2931  *  @tparam D      Texture dimenisons.
2932  *
2933  *  @return Size.
2934  */
2935 template <typename T, glw::GLint S, glw::GLuint D>
2936 glw::GLuint StorageMultisampleTest::TestReferenceDataSize()
2937 {
2938         return TestReferenceDataCount<S, D>() * sizeof(T);
2939 }
2940
2941 /** @brief Height, width or depth of reference data to be teted.
2942  *
2943  *  @tparam D      Texture dimenisons.
2944  *
2945  *  @return Height, width or depth.
2946  */
2947 template <>
2948 glw::GLuint StorageMultisampleTest::TestReferenceDataHeight<2>()
2949 {
2950         return 3;
2951 }
2952
2953 template <>
2954 glw::GLuint StorageMultisampleTest::TestReferenceDataHeight<3>()
2955 {
2956         return TestReferenceDataHeight<2>();
2957 }
2958
2959 template <>
2960 glw::GLuint StorageMultisampleTest::TestReferenceDataDepth<2>()
2961 {
2962         return 1;
2963 }
2964
2965 template <>
2966 glw::GLuint StorageMultisampleTest::TestReferenceDataDepth<3>()
2967 {
2968         return 4;
2969 }
2970
2971 template <glw::GLuint D>
2972 glw::GLuint                       StorageMultisampleTest::TestReferenceDataWidth()
2973 {
2974         return 2;
2975 }
2976
2977 /** @brief Fragment shader declaration selector.
2978  *
2979  *  @tparam T      Type.
2980  *  @tparam N      Normalized flag.
2981  *  @tparam D      Texture dimenisons.
2982  *
2983  *  @return Frgment shader source code part.
2984  */
2985 template <>
2986 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLubyte, true, 2>()
2987 {
2988         return s_fragment_shader_ms_2D_fdecl_lowp;
2989 }
2990
2991 template <>
2992 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLbyte, false, 2>()
2993 {
2994         return s_fragment_shader_ms_2D_idecl_lowp;
2995 }
2996
2997 template <>
2998 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLubyte, false, 2>()
2999 {
3000         return s_fragment_shader_ms_2D_udecl_lowp;
3001 }
3002
3003 template <>
3004 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLushort, true, 2>()
3005 {
3006         return s_fragment_shader_ms_2D_fdecl_mediump;
3007 }
3008
3009 template <>
3010 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLshort, false, 2>()
3011 {
3012         return s_fragment_shader_ms_2D_idecl_mediump;
3013 }
3014
3015 template <>
3016 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLushort, false, 2>()
3017 {
3018         return s_fragment_shader_ms_2D_udecl_mediump;
3019 }
3020
3021 template <>
3022 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLfloat, true, 2>()
3023 {
3024         return s_fragment_shader_ms_2D_fdecl_highp;
3025 }
3026
3027 template <>
3028 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLint, false, 2>()
3029 {
3030         return s_fragment_shader_ms_2D_idecl_highp;
3031 }
3032
3033 template <>
3034 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLuint, false, 2>()
3035 {
3036         return s_fragment_shader_ms_2D_udecl_highp;
3037 }
3038
3039 /** @brief Fragment shader declaration selector.
3040  *
3041  *  @tparam T      Type.
3042  *  @tparam N      Normalized flag.
3043  *  @tparam D      Texture dimenisons.
3044  *
3045  *  @return Frgment shader source code part.
3046  */
3047 template <>
3048 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLubyte, true, 3>()
3049 {
3050         return s_fragment_shader_ms_3D_fdecl_lowp;
3051 }
3052
3053 template <>
3054 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLbyte, false, 3>()
3055 {
3056         return s_fragment_shader_ms_3D_idecl_lowp;
3057 }
3058
3059 template <>
3060 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLubyte, false, 3>()
3061 {
3062         return s_fragment_shader_ms_3D_udecl_lowp;
3063 }
3064
3065 template <>
3066 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLushort, true, 3>()
3067 {
3068         return s_fragment_shader_ms_3D_fdecl_mediump;
3069 }
3070
3071 template <>
3072 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLshort, false, 3>()
3073 {
3074         return s_fragment_shader_ms_3D_idecl_mediump;
3075 }
3076
3077 template <>
3078 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLushort, false, 3>()
3079 {
3080         return s_fragment_shader_ms_3D_udecl_mediump;
3081 }
3082
3083 template <>
3084 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLfloat, true, 3>()
3085 {
3086         return s_fragment_shader_ms_3D_fdecl_highp;
3087 }
3088
3089 template <>
3090 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLint, false, 3>()
3091 {
3092         return s_fragment_shader_ms_3D_idecl_highp;
3093 }
3094
3095 template <>
3096 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLuint, false, 3>()
3097 {
3098         return s_fragment_shader_ms_3D_udecl_highp;
3099 }
3100
3101 /** @brief Fragment shader declaration selector.
3102  *
3103  *  @tparam T      Type.
3104  *  @tparam N      Normalized flag.
3105  *  @tparam D      Texture dimenisons.
3106  *
3107  *  @return Frgment shader source code part.
3108  */
3109 template <>
3110 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLubyte, true, 2>()
3111 {
3112         return s_fragment_shader_aux_2D_fdecl_lowp;
3113 }
3114
3115 template <>
3116 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLbyte, false, 2>()
3117 {
3118         return s_fragment_shader_aux_2D_idecl_lowp;
3119 }
3120
3121 template <>
3122 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLubyte, false, 2>()
3123 {
3124         return s_fragment_shader_aux_2D_udecl_lowp;
3125 }
3126
3127 template <>
3128 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLushort, true, 2>()
3129 {
3130         return s_fragment_shader_aux_2D_fdecl_mediump;
3131 }
3132
3133 template <>
3134 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLshort, false, 2>()
3135 {
3136         return s_fragment_shader_aux_2D_idecl_mediump;
3137 }
3138
3139 template <>
3140 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLushort, false, 2>()
3141 {
3142         return s_fragment_shader_aux_2D_udecl_mediump;
3143 }
3144
3145 template <>
3146 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLfloat, true, 2>()
3147 {
3148         return s_fragment_shader_aux_2D_fdecl_highp;
3149 }
3150
3151 template <>
3152 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLint, false, 2>()
3153 {
3154         return s_fragment_shader_aux_2D_idecl_highp;
3155 }
3156
3157 template <>
3158 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLuint, false, 2>()
3159 {
3160         return s_fragment_shader_aux_2D_udecl_highp;
3161 }
3162
3163 /** @brief Fragment shader declaration selector.
3164  *
3165  *  @tparam T      Type.
3166  *  @tparam N      Normalized flag.
3167  *  @tparam D      Texture dimenisons.
3168  *
3169  *  @return Frgment shader source code part.
3170  */
3171 template <>
3172 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLubyte, true, 3>()
3173 {
3174         return s_fragment_shader_aux_3D_fdecl_lowp;
3175 }
3176
3177 template <>
3178 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLbyte, false, 3>()
3179 {
3180         return s_fragment_shader_aux_3D_idecl_lowp;
3181 }
3182
3183 template <>
3184 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLubyte, false, 3>()
3185 {
3186         return s_fragment_shader_aux_3D_udecl_lowp;
3187 }
3188
3189 template <>
3190 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLushort, true, 3>()
3191 {
3192         return s_fragment_shader_aux_3D_fdecl_mediump;
3193 }
3194
3195 template <>
3196 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLshort, false, 3>()
3197 {
3198         return s_fragment_shader_aux_3D_idecl_mediump;
3199 }
3200
3201 template <>
3202 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLushort, false, 3>()
3203 {
3204         return s_fragment_shader_aux_3D_udecl_mediump;
3205 }
3206
3207 template <>
3208 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLfloat, true, 3>()
3209 {
3210         return s_fragment_shader_aux_3D_fdecl_highp;
3211 }
3212
3213 template <>
3214 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLint, false, 3>()
3215 {
3216         return s_fragment_shader_aux_3D_idecl_highp;
3217 }
3218
3219 template <>
3220 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLuint, false, 3>()
3221 {
3222         return s_fragment_shader_aux_3D_udecl_highp;
3223 }
3224
3225 /** @brief Fragment shader tail selector.
3226  *
3227  *  @tparam D      Texture dimenisons.
3228  *
3229  *  @return Frgment shader source code part.
3230  */
3231 template <>
3232 const glw::GLchar* StorageMultisampleTest::FragmentShaderTail<2>()
3233 {
3234         return s_fragment_shader_tail_2D;
3235 }
3236
3237 template <>
3238 const glw::GLchar* StorageMultisampleTest::FragmentShaderTail<3>()
3239 {
3240         return s_fragment_shader_tail_3D;
3241 }
3242
3243 /** @brief Texture target selector.
3244  *
3245  *  @tparam D      Texture dimenisons.
3246  *
3247  *  @return Texture target.
3248  */
3249 template <>
3250 glw::GLenum StorageMultisampleTest::InputTextureTarget<2>()
3251 {
3252         return GL_TEXTURE_2D;
3253 }
3254
3255 template <>
3256 glw::GLenum StorageMultisampleTest::InputTextureTarget<3>()
3257 {
3258         return GL_TEXTURE_2D_ARRAY;
3259 }
3260
3261 /** @brief Prepare texture data for input texture.
3262  *
3263  *  @tparam D      Texture dimenisons.
3264  *
3265  *  @note parameters as passed to texImage*
3266  */
3267 template <>
3268 void StorageMultisampleTest::InputTextureImage<2>(const glw::GLenum internal_format, const glw::GLuint width,
3269                                                                                                   const glw::GLuint height, const glw::GLuint depth,
3270                                                                                                   const glw::GLenum format, const glw::GLenum type,
3271                                                                                                   const glw::GLvoid* data)
3272 {
3273         (void)depth;
3274         /* Shortcut for GL functionality. */
3275         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3276
3277         /* Data setup. */
3278         gl.texImage2D(InputTextureTarget<2>(), 0, internal_format, width, height, 0, format, type, data);
3279         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
3280 }
3281
3282 /** @brief Prepare texture data for input texture.
3283  *
3284  *  @tparam D      Texture dimenisons.
3285  *
3286  *  @note parameters as passed to texImage*
3287  */
3288 template <>
3289 void StorageMultisampleTest::InputTextureImage<3>(const glw::GLenum internal_format, const glw::GLuint width,
3290                                                                                                   const glw::GLuint height, const glw::GLuint depth,
3291                                                                                                   const glw::GLenum format, const glw::GLenum type,
3292                                                                                                   const glw::GLvoid* data)
3293 {
3294         /* Shortcut for GL functionality. */
3295         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3296
3297         /* Data setup. */
3298         gl.texImage3D(InputTextureTarget<3>(), 0, internal_format, width, height, depth, 0, format, type, data);
3299         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
3300 }
3301
3302 /** @brief Create texture.
3303  *
3304  *  @tparam T      Type.
3305  *  @tparam S      Size (# of components).
3306  *  @tparam N      Is normalized.
3307  *  @tparam D      Dimmensions.
3308  */
3309 template <typename T, glw::GLint S, bool N, glw::GLuint D>
3310 void StorageMultisampleTest::CreateInputTexture()
3311 {
3312         /* Shortcut for GL functionality. */
3313         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3314
3315         /* Objects creation. */
3316         gl.genTextures(1, &m_to);
3317         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
3318
3319         gl.bindTexture(InputTextureTarget<D>(), m_to);
3320         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
3321
3322         /* Data setup. */
3323         InputTextureImage<D>(InternalFormat<T, S, N>(), TestReferenceDataWidth<D>(), TestReferenceDataHeight<D>(),
3324                                                  TestReferenceDataDepth<D>(), Format<S, N>(), Type<T>(), ReferenceData<T, N>());
3325
3326         /* Parameter setup. */
3327         gl.texParameteri(InputTextureTarget<D>(), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3328         gl.texParameteri(InputTextureTarget<D>(), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3329         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
3330 }
3331
3332 /** @brief Compre results with the reference.
3333  *
3334  *  @tparam T      Type.
3335  *  @tparam S      Size (# of components).
3336  *  @tparam N      Is normalized.
3337  *
3338  *  @return True if equal, false otherwise.
3339  */
3340 template <typename T, glw::GLint S, bool N, glw::GLuint D>
3341 bool StorageMultisampleTest::Check()
3342 {
3343         /* Shortcut for GL functionality. */
3344         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3345
3346         /* Fetching data fro auxiliary texture. */
3347         std::vector<T> result(TestReferenceDataCount<S, D>());
3348
3349         gl.bindTexture(InputTextureTarget<D>() /* Auxiliary target is the same as input. */, m_to_aux);
3350         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
3351
3352         gl.getTexImage(InputTextureTarget<D>() /* Auxiliary target is the same as input. */, 0, Format<S, N>(), Type<T>(),
3353                                    (glw::GLvoid*)(&result[0]));
3354         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexImage has failed");
3355
3356         /* Comparison. */
3357         for (glw::GLuint i = 0; i < TestReferenceDataCount<S, D>(); ++i)
3358         {
3359                 if (!Compare<T>(result[i], ReferenceData<T, N>()[i]))
3360                 {
3361                         return false;
3362                 }
3363         }
3364
3365         return true;
3366 }
3367
3368 /** @brief Test case function.
3369  *
3370  *  @tparam T       Type.
3371  *  @tparam S       Size (# of components).
3372  *  @tparam N       Is normalized.
3373  *  @tparam D       Number of texture dimensions.
3374  *
3375  *  @return True if test succeeded, false otherwise.
3376  */
3377 template <typename T, glw::GLint S, bool N, glw::GLuint D>
3378 bool StorageMultisampleTest::Test()
3379 {
3380         /* Shortcut for GL functionality. */
3381         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3382
3383         /* Setup. */
3384         gl.pixelStorei(GL_UNPACK_ALIGNMENT, sizeof(T));
3385         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
3386
3387         gl.pixelStorei(GL_PACK_ALIGNMENT, sizeof(T));
3388         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
3389
3390         CreateInputTexture<T, S, N, D>();
3391
3392         if (!PrepareFramebufferMultisample<D>(InternalFormat<T, S, N>()))
3393         {
3394                 CleanInputTexture();
3395
3396                 return false;
3397         }
3398
3399         PrepareFramebufferAuxiliary<D>(InternalFormat<T, S, N>());
3400
3401         /* Action. */
3402         Draw<D>();
3403
3404         /* Compare results with reference. */
3405         bool result = Check<T, S, N, D>();
3406
3407         /* Cleanup. */
3408         CleanAuxiliaryTexture();
3409         CleanFramebuffers();
3410         CleanInputTexture();
3411         CleanErrors();
3412
3413         /* Pass result. */
3414         return result;
3415 }
3416
3417 /** @brief Lopp test function over S.
3418  *
3419  *  @tparam T      Type.
3420  *  @tparam N      Is normalized.
3421  *  @tparam D      Texture dimension.
3422  *
3423  *  @param [in] skip_rgb            Skip test of S = 3 (needed for some formats).
3424  *
3425  *  @return True if tests succeeded, false otherwise.
3426  */
3427 template <typename T, bool N, glw::GLuint D>
3428 bool StorageMultisampleTest::LoopTestOverS(bool skip_rgb)
3429 {
3430         /* Prepare one program to create multisample texture and one to copy it to regular texture. */
3431         m_po_ms  = PrepareProgram(FragmentShaderDeclarationMultisample<T, N, D>(), FragmentShaderTail<D>());
3432         m_po_aux = PrepareProgram(FragmentShaderDeclarationAuxiliary<T, N, D>(), FragmentShaderTail<D>());
3433
3434         /* Run tests. */
3435         bool result = true;
3436
3437         result &= Test<T, 1, N, D>();
3438
3439         result &= Test<T, 2, N, D>();
3440
3441         if (!skip_rgb)
3442         {
3443                 result &= Test<T, 3, N, D>();
3444         }
3445
3446         result &= Test<T, 4, N, D>();
3447
3448         /* Cleanup.*/
3449         CleanPrograms();
3450         CleanErrors();
3451
3452         /* Pass result. */
3453         return result;
3454 }
3455
3456 /** @brief Lopp test function over D and next over S.
3457  *
3458  *  @tparam T      Type.
3459  *  @tparam N      Is normalized.
3460  *
3461  *  @param [in] skip_rgb            Skip test of S = 3 (needed for some formats).
3462  *
3463  *  @return True if tests succeeded, false otherwise.
3464  */
3465 template <typename T, bool N>
3466 bool StorageMultisampleTest::LoopTestOverDOverS(bool skip_rgb)
3467 {
3468         bool result = true;
3469
3470         result &= LoopTestOverS<T, N, 2>(skip_rgb);
3471         result &= LoopTestOverS<T, N, 3>(skip_rgb);
3472
3473         return result;
3474 }
3475
3476 /** @brief Function prepares framebuffer with internal format color attachment.
3477  *         Viewport is set up. Content of the framebuffer is cleared.
3478  *
3479  *  @note The function may throw if unexpected error has occured.
3480  */
3481 template <>
3482 bool StorageMultisampleTest::PrepareFramebufferMultisample<2>(const glw::GLenum internal_format)
3483 {
3484         /* Shortcut for GL functionality. */
3485         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3486
3487         /* Prepare framebuffer. */
3488         gl.genFramebuffers(1, &m_fbo_ms);
3489         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
3490
3491         gl.genTextures(1, &m_to_ms);
3492         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
3493
3494         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
3495         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
3496
3497         gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_to_ms);
3498         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
3499
3500         gl.textureStorage2DMultisample(m_to_ms, 1, internal_format, TestReferenceDataWidth<2>(),
3501                                                                    TestReferenceDataHeight<2>(), false);
3502
3503         glw::GLenum error;
3504
3505         if (GL_NO_ERROR != (error = gl.getError()))
3506         {
3507                 CleanFramebuffers();
3508
3509                 m_context.getTestContext().getLog()
3510                         << tcu::TestLog::Message << "glTextureStorage2DMultisample unexpectedly generated error "
3511                         << glu::getErrorStr(error) << " during the test of internal format "
3512                         << glu::getTextureFormatStr(internal_format) << ". Test fails." << tcu::TestLog::EndMessage;
3513
3514                 return false;
3515         }
3516
3517         gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, m_to_ms, 0);
3518         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
3519
3520         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
3521         {
3522                 throw 0;
3523         }
3524
3525         gl.viewport(0, 0, TestReferenceDataWidth<2>(), TestReferenceDataHeight<2>());
3526         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
3527
3528         /* Clear framebuffer's content. */
3529         gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
3530         GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
3531
3532         gl.clear(GL_COLOR_BUFFER_BIT);
3533         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
3534
3535         return true;
3536 }
3537
3538 /** @brief Function prepares framebuffer with internal format color attachment.
3539  *         Viewport is set up. Content of the framebuffer is cleared.
3540  *
3541  *  @note The function may throw if unexpected error has occured.
3542  */
3543 template <>
3544 bool StorageMultisampleTest::PrepareFramebufferMultisample<3>(const glw::GLenum internal_format)
3545 {
3546         /* Shortcut for GL functionality. */
3547         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3548
3549         /* Prepare framebuffer. */
3550         gl.genFramebuffers(1, &m_fbo_ms);
3551         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
3552
3553         gl.genTextures(1, &m_to_ms);
3554         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
3555
3556         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
3557         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
3558
3559         gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, m_to_ms);
3560         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
3561
3562         gl.textureStorage3DMultisample(m_to_ms, 1, internal_format, TestReferenceDataWidth<3>(),
3563                                                                    TestReferenceDataHeight<3>(), TestReferenceDataDepth<3>(), false);
3564
3565         glw::GLenum error;
3566
3567         if (GL_NO_ERROR != (error = gl.getError()))
3568         {
3569                 CleanFramebuffers();
3570
3571                 m_context.getTestContext().getLog()
3572                         << tcu::TestLog::Message << "glTextureStorage3DMultisample unexpectedly generated error "
3573                         << glu::getErrorStr(error) << " during the test of internal format "
3574                         << glu::getTextureFormatStr(internal_format) << ". Test fails." << tcu::TestLog::EndMessage;
3575
3576                 return false;
3577         }
3578
3579         for (glw::GLuint i = 0; i < TestReferenceDataDepth<3>(); ++i)
3580         {
3581                 gl.framebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, m_to_ms, 0, i);
3582                 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
3583         }
3584
3585         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
3586         {
3587                 throw 0;
3588         }
3589
3590         gl.viewport(0, 0, TestReferenceDataWidth<3>(), TestReferenceDataHeight<3>());
3591         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
3592
3593         /* Clear framebuffer's content. */
3594         gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
3595         GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
3596
3597         gl.clear(GL_COLOR_BUFFER_BIT);
3598         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
3599
3600         return true;
3601 }
3602
3603 /** @brief Function prepares framebuffer with internal format color attachment.
3604  *         Viewport is set up. Content of the framebuffer is cleared.
3605  *
3606  *  @note The function may throw if unexpected error has occured.
3607  */
3608 template <>
3609 void StorageMultisampleTest::PrepareFramebufferAuxiliary<2>(const glw::GLenum internal_format)
3610 {
3611         /* Shortcut for GL functionality. */
3612         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3613
3614         /* Prepare framebuffer. */
3615         gl.genFramebuffers(1, &m_fbo_aux);
3616         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
3617
3618         gl.genTextures(1, &m_to_aux);
3619         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
3620
3621         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_aux);
3622         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
3623
3624         gl.bindTexture(GL_TEXTURE_2D, m_to_aux);
3625         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
3626
3627         gl.textureStorage2D(m_to_aux, 1, internal_format, TestReferenceDataWidth<2>(), TestReferenceDataHeight<2>());
3628         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2D call failed.");
3629
3630         /* Parameter setup. */
3631         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3632         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3633         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
3634
3635         gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_to_aux, 0);
3636         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
3637
3638         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
3639         {
3640                 throw 0;
3641         }
3642
3643         gl.viewport(0, 0, TestReferenceDataWidth<2>(), TestReferenceDataHeight<2>());
3644         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
3645
3646         /* Clear framebuffer's content. */
3647         gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
3648         GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
3649
3650         gl.clear(GL_COLOR_BUFFER_BIT);
3651         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
3652 }
3653
3654 /** @brief Function prepares framebuffer with internal format color attachment.
3655  *         Viewport is set up. Content of the framebuffer is cleared.
3656  *
3657  *  @note The function may throw if unexpected error has occured.
3658  */
3659 template <>
3660 void StorageMultisampleTest::PrepareFramebufferAuxiliary<3>(const glw::GLenum internal_format)
3661 {
3662         /* Shortcut for GL functionality. */
3663         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3664
3665         /* Prepare framebuffer. */
3666         gl.genFramebuffers(1, &m_fbo_aux);
3667         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
3668
3669         gl.genTextures(1, &m_to_aux);
3670         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
3671
3672         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_aux);
3673         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
3674
3675         gl.bindTexture(GL_TEXTURE_2D_ARRAY, m_to_aux);
3676         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
3677
3678         gl.textureStorage3D(m_to_aux, 1, internal_format, TestReferenceDataWidth<3>(), TestReferenceDataHeight<3>(),
3679                                                 TestReferenceDataDepth<3>());
3680         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage3D call failed.");
3681
3682         /* Parameter setup. */
3683         gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3684         gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3685         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
3686
3687         for (glw::GLuint i = 0; i < TestReferenceDataDepth<3>(); ++i)
3688         {
3689                 gl.framebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, m_to_aux, 0, i);
3690                 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
3691         }
3692
3693         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
3694         {
3695                 throw 0;
3696         }
3697
3698         gl.viewport(0, 0, TestReferenceDataWidth<3>(), TestReferenceDataHeight<3>());
3699         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
3700
3701         /* Clear framebuffer's content. */
3702         gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
3703         GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
3704
3705         gl.clear(GL_COLOR_BUFFER_BIT);
3706         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
3707 }
3708
3709 /** @brief Prepare program
3710  *
3711  *  @param [in] variable_declaration      Variables declaration part of fragment shader source code.
3712  *  @param [in] tail                      Tail part of fragment shader source code.
3713  */
3714 glw::GLuint StorageMultisampleTest::PrepareProgram(const glw::GLchar* variable_declaration, const glw::GLchar* tail)
3715 {
3716         /* Shortcut for GL functionality */
3717         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3718
3719         struct Shader
3720         {
3721                 glw::GLchar const* source[3];
3722                 glw::GLsizei const count;
3723                 glw::GLenum const  type;
3724                 glw::GLuint                id;
3725         } shader[] = { { { s_vertex_shader, NULL, NULL }, 1, GL_VERTEX_SHADER, 0 },
3726                                    { { s_fragment_shader_head, variable_declaration, tail }, 3, GL_FRAGMENT_SHADER, 0 } };
3727
3728         glw::GLuint const shader_count = sizeof(shader) / sizeof(shader[0]);
3729
3730         glw::GLuint po = 0;
3731
3732         try
3733         {
3734                 /* Create program. */
3735                 po = gl.createProgram();
3736                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateProgram call failed.");
3737
3738                 /* Shader compilation. */
3739
3740                 for (glw::GLuint i = 0; i < shader_count; ++i)
3741                 {
3742                         {
3743                                 shader[i].id = gl.createShader(shader[i].type);
3744
3745                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateShader call failed.");
3746
3747                                 gl.attachShader(po, shader[i].id);
3748
3749                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glAttachShader call failed.");
3750
3751                                 gl.shaderSource(shader[i].id, shader[i].count, shader[i].source, NULL);
3752
3753                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource call failed.");
3754
3755                                 gl.compileShader(shader[i].id);
3756
3757                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader call failed.");
3758
3759                                 glw::GLint status = GL_FALSE;
3760
3761                                 gl.getShaderiv(shader[i].id, GL_COMPILE_STATUS, &status);
3762                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
3763
3764                                 if (GL_FALSE == status)
3765                                 {
3766                                         glw::GLint log_size = 0;
3767                                         gl.getShaderiv(shader[i].id, GL_INFO_LOG_LENGTH, &log_size);
3768                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
3769
3770                                         glw::GLchar* log_text = new glw::GLchar[log_size];
3771
3772                                         gl.getShaderInfoLog(shader[i].id, log_size, NULL, &log_text[0]);
3773
3774                                         m_context.getTestContext().getLog()
3775                                                 << tcu::TestLog::Message << "Shader compilation has failed.\n"
3776                                                 << "Shader type: " << glu::getShaderTypeStr(shader[i].type) << "\n"
3777                                                 << "Shader compilation error log:\n"
3778                                                 << log_text << "\n"
3779                                                 << "Shader source code:\n"
3780                                                 << shader[i].source[0] << (shader[i].source[1] ? shader[i].source[1] : "")
3781                                                 << (shader[i].source[2] ? shader[i].source[2] : "") << "\n"
3782                                                 << tcu::TestLog::EndMessage;
3783
3784                                         delete[] log_text;
3785
3786                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog call failed.");
3787
3788                                         throw 0;
3789                                 }
3790                         }
3791                 }
3792
3793                 /* Link. */
3794                 gl.linkProgram(po);
3795
3796                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTransformFeedbackVaryings call failed.");
3797
3798                 glw::GLint status = GL_FALSE;
3799
3800                 gl.getProgramiv(po, GL_LINK_STATUS, &status);
3801
3802                 if (GL_TRUE == status)
3803                 {
3804                         for (glw::GLuint i = 0; i < shader_count; ++i)
3805                         {
3806                                 if (shader[i].id)
3807                                 {
3808                                         gl.detachShader(po, shader[i].id);
3809
3810                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glDetachShader call failed.");
3811                                 }
3812                         }
3813                 }
3814                 else
3815                 {
3816                         glw::GLint log_size = 0;
3817
3818                         gl.getProgramiv(po, GL_INFO_LOG_LENGTH, &log_size);
3819
3820                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv call failed.");
3821
3822                         glw::GLchar* log_text = new glw::GLchar[log_size];
3823
3824                         gl.getProgramInfoLog(po, log_size, NULL, &log_text[0]);
3825
3826                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "Program linkage has failed due to:\n"
3827                                                                                                 << log_text << "\n"
3828                                                                                                 << tcu::TestLog::EndMessage;
3829
3830                         delete[] log_text;
3831
3832                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramInfoLog call failed.");
3833
3834                         throw 0;
3835                 }
3836         }
3837         catch (...)
3838         {
3839                 if (po)
3840                 {
3841                         gl.deleteProgram(po);
3842
3843                         po = 0;
3844                 }
3845         }
3846
3847         for (glw::GLuint i = 0; i < shader_count; ++i)
3848         {
3849                 if (0 != shader[i].id)
3850                 {
3851                         gl.deleteShader(shader[i].id);
3852
3853                         shader[i].id = 0;
3854                 }
3855         }
3856
3857         if (0 == po)
3858         {
3859                 throw 0;
3860         }
3861
3862         return po;
3863 }
3864
3865 /** @brief Prepare VAO.
3866  */
3867 void StorageMultisampleTest::PrepareVertexArray()
3868 {
3869         /* Shortcut for GL functionality. */
3870         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3871
3872         gl.genVertexArrays(1, &m_vao);
3873         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays has failed");
3874
3875         gl.bindVertexArray(m_vao);
3876         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray has failed");
3877 }
3878
3879 /** @brief Draw call 2D.
3880  */
3881 template <>
3882 void StorageMultisampleTest::Draw<2>()
3883 {
3884         /* Shortcut for GL functionality. */
3885         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3886
3887         /* Prepare multisample texture using draw call. */
3888
3889         /* Prepare framebuffer with multisample texture. */
3890         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
3891         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer has failed");
3892
3893         /* Use first program program. */
3894         gl.useProgram(m_po_ms);
3895         GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed");
3896
3897         /* Prepare texture to be drawn with. */
3898         gl.activeTexture(GL_TEXTURE0);
3899         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
3900
3901         gl.bindTexture(GL_TEXTURE_2D, m_to);
3902         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
3903
3904         gl.uniform1i(gl.getUniformLocation(m_po_ms, "texture_input"), 0);
3905         GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed");
3906
3907         /* Select layer. */
3908         gl.drawBuffer(GL_COLOR_ATTACHMENT0);
3909         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawBuffer has failed");
3910
3911         /* Draw. */
3912         gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
3913         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed");
3914
3915         /* Copy multisample texture to auxiliary texture using draw call. */
3916
3917         /* Prepare framebuffer with auxiliary texture. */
3918         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_aux);
3919         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer has failed");
3920
3921         /* Use first program program. */
3922         gl.useProgram(m_po_aux);
3923         GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed");
3924
3925         /* Prepare texture to be drawn with. */
3926         gl.activeTexture(GL_TEXTURE0);
3927         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
3928
3929         gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_to_ms);
3930         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
3931
3932         gl.bindTextureUnit(0, m_to);
3933
3934         gl.uniform1i(gl.getUniformLocation(m_po_aux, "texture_input"), 0);
3935         GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed");
3936
3937         /* Select layer. */
3938         gl.drawBuffer(GL_COLOR_ATTACHMENT0);
3939         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawBuffer has failed");
3940
3941         /* Draw. */
3942         gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
3943         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed");
3944 }
3945
3946 /** @brief Draw call 3D.
3947  */
3948 template <>
3949 void StorageMultisampleTest::Draw<3>()
3950 {
3951         /* Shortcut for GL functionality. */
3952         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3953
3954         /* Prepare multisample texture using draw call. */
3955
3956         /* Prepare framebuffer with multisample texture. */
3957         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
3958         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer has failed");
3959
3960         /* Use first program program. */
3961         gl.useProgram(m_po_ms);
3962         GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed");
3963
3964         /* Prepare texture to be drawn with. */
3965         gl.activeTexture(GL_TEXTURE0);
3966         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
3967
3968         gl.bindTexture(GL_TEXTURE_2D_ARRAY, m_to);
3969         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
3970
3971         gl.uniform1i(gl.getUniformLocation(m_po_ms, "texture_input"), 0);
3972         GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed");
3973
3974         /* For each texture layer. */
3975         for (glw::GLuint i = 0; i < TestReferenceDataDepth<3>(); ++i)
3976         {
3977                 /* Select layer. */
3978                 gl.drawBuffer(GL_COLOR_ATTACHMENT0 + i);
3979                 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawBuffer has failed");
3980
3981                 gl.uniform1i(gl.getUniformLocation(m_po_aux, "texture_layer"), i);
3982                 GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed");
3983
3984                 /* Draw. */
3985                 gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
3986                 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed");
3987         }
3988
3989         /* Copy multisample texture to auxiliary texture using draw call. */
3990
3991         /* Prepare framebuffer with auxiliary texture. */
3992         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_aux);
3993         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer has failed");
3994
3995         /* Use first program program. */
3996         gl.useProgram(m_po_aux);
3997         GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed");
3998
3999         /* Prepare texture to be drawn with. */
4000         gl.activeTexture(GL_TEXTURE0);
4001         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
4002
4003         gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, m_to_ms);
4004         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
4005
4006         gl.bindTextureUnit(0, m_to);
4007
4008         gl.uniform1i(gl.getUniformLocation(m_po_aux, "texture_input"), 0);
4009         GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed");
4010
4011         /* For each texture layer. */
4012         for (glw::GLuint i = 0; i < TestReferenceDataDepth<3>(); ++i)
4013         {
4014                 /* Select layer. */
4015                 gl.drawBuffer(GL_COLOR_ATTACHMENT0 + i);
4016                 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawBuffer has failed");
4017
4018                 gl.uniform1i(gl.getUniformLocation(m_po_aux, "texture_layer"), i);
4019                 GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed");
4020
4021                 /* Draw. */
4022                 gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
4023                 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed");
4024         }
4025 }
4026
4027 /** @brief Clean GL objects, test variables and GL errors.
4028  */
4029 void StorageMultisampleTest::CleanInputTexture()
4030 {
4031         /* Shortcut for GL functionality. */
4032         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4033
4034         /* Texture. */
4035         if (m_to)
4036         {
4037                 gl.deleteTextures(1, &m_to);
4038
4039                 m_to = 0;
4040         }
4041 }
4042
4043 /** @brief Clean GL objects, test variables and GL errors.
4044  */
4045 void StorageMultisampleTest::CleanAuxiliaryTexture()
4046 {
4047         /* Shortcut for GL functionality. */
4048         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4049
4050         if (m_to_aux)
4051         {
4052                 gl.deleteTextures(1, &m_to_aux);
4053
4054                 m_to_aux = 0;
4055         }
4056 }
4057
4058 /** @brief Clean GL objects, test variables and GL errors.
4059  */
4060 void StorageMultisampleTest::CleanFramebuffers()
4061 {
4062         /* Shortcut for GL functionality. */
4063         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4064
4065         /* Mulitsample framebuffer. */
4066         if (m_fbo_ms)
4067         {
4068                 gl.deleteFramebuffers(1, &m_fbo_ms);
4069
4070                 m_fbo_ms = 0;
4071         }
4072
4073         /* Mulitsample texture. */
4074         if (m_to_ms)
4075         {
4076                 gl.deleteTextures(1, &m_to_ms);
4077
4078                 m_to_ms = 0;
4079         }
4080
4081         /* Auxiliary framebuffer. */
4082         if (m_fbo_aux)
4083         {
4084                 gl.deleteFramebuffers(1, &m_fbo_aux);
4085
4086                 m_fbo_aux = 0;
4087         }
4088
4089         /* Auxiliary texture. */
4090         if (m_to_aux)
4091         {
4092                 gl.deleteTextures(1, &m_to_aux);
4093
4094                 m_to_aux = 0;
4095         }
4096 }
4097
4098 /** @brief Clean GL objects, test variables and GL errors.
4099  */
4100 void StorageMultisampleTest::CleanPrograms()
4101 {
4102         /* Shortcut for GL functionality. */
4103         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4104
4105         /* Binding point. */
4106         gl.useProgram(0);
4107
4108         /* Multisample texture preparation program. */
4109         if (m_po_ms)
4110         {
4111                 gl.deleteProgram(m_po_ms);
4112
4113                 m_po_ms = 0;
4114         }
4115
4116         /* Auxiliary texture preparation program. */
4117         if (m_po_aux)
4118         {
4119                 gl.deleteProgram(m_po_aux);
4120
4121                 m_po_aux = 0;
4122         }
4123 }
4124
4125 /** @brief Clean GL objects, test variables and GL errors.
4126  */
4127 void StorageMultisampleTest::CleanErrors()
4128 {
4129         /* Shortcut for GL functionality. */
4130         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4131
4132         /* Query all errors until GL_NO_ERROR occure. */
4133         while (GL_NO_ERROR != gl.getError())
4134                 ;
4135 }
4136
4137 /** @brief Clean GL objects, test variables and GL errors.
4138  */
4139 void StorageMultisampleTest::CleanVertexArray()
4140 {
4141         /* Shortcut for GL functionality. */
4142         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4143
4144         if (m_vao)
4145         {
4146                 gl.bindVertexArray(0);
4147
4148                 gl.deleteVertexArrays(1, &m_vao);
4149
4150                 m_vao = 0;
4151         }
4152 }
4153
4154 /** @brief Iterate Storage Multisample Test cases.
4155  *
4156  *  @return Iteration result.
4157  */
4158 tcu::TestNode::IterateResult StorageMultisampleTest::iterate()
4159 {
4160         /* Shortcut for GL functionality. */
4161         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4162
4163         /* Get context setup. */
4164         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
4165         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
4166
4167         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
4168         {
4169                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
4170
4171                 return STOP;
4172         }
4173
4174         /* Running tests. */
4175         bool is_ok      = true;
4176         bool is_error = false;
4177
4178         try
4179         {
4180                 PrepareVertexArray();
4181
4182                 //  gl.enable(GL_MULTISAMPLE);
4183
4184                 is_ok &= LoopTestOverDOverS<glw::GLbyte, false>(true);
4185                 is_ok &= LoopTestOverDOverS<glw::GLubyte, false>(true);
4186                 is_ok &= LoopTestOverDOverS<glw::GLshort, false>(true);
4187                 is_ok &= LoopTestOverDOverS<glw::GLushort, false>(true);
4188                 is_ok &= LoopTestOverDOverS<glw::GLint, false>(false);
4189                 is_ok &= LoopTestOverDOverS<glw::GLuint, false>(false);
4190                 is_ok &= LoopTestOverDOverS<glw::GLubyte, true>(true);
4191                 is_ok &= LoopTestOverDOverS<glw::GLushort, true>(true);
4192                 is_ok &= LoopTestOverDOverS<glw::GLfloat, true>(false);
4193         }
4194         catch (...)
4195         {
4196                 is_ok   = false;
4197                 is_error = true;
4198         }
4199
4200         /* Cleanup. */
4201         CleanInputTexture();
4202         CleanAuxiliaryTexture();
4203         CleanFramebuffers();
4204         CleanPrograms();
4205         CleanErrors();
4206         CleanVertexArray();
4207         gl.disable(GL_MULTISAMPLE);
4208
4209         /* Errors clean up. */
4210         while (gl.getError())
4211                 ;
4212
4213         /* Result's setup. */
4214         if (is_ok)
4215         {
4216                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
4217         }
4218         else
4219         {
4220                 if (is_error)
4221                 {
4222                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
4223                 }
4224                 else
4225                 {
4226                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
4227                 }
4228         }
4229
4230         return STOP;
4231 }
4232
4233 /* Vertex shader source code. */
4234 const glw::GLchar* StorageMultisampleTest::s_vertex_shader = "#version 450\n"
4235                                                                                                                          "\n"
4236                                                                                                                          "void main()\n"
4237                                                                                                                          "{\n"
4238                                                                                                                          "    switch(gl_VertexID)\n"
4239                                                                                                                          "    {\n"
4240                                                                                                                          "        case 0:\n"
4241                                                                                                                          "            gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
4242                                                                                                                          "            break;\n"
4243                                                                                                                          "        case 1:\n"
4244                                                                                                                          "            gl_Position = vec4( 1.0, 1.0, 0.0, 1.0);\n"
4245                                                                                                                          "            break;\n"
4246                                                                                                                          "        case 2:\n"
4247                                                                                                                          "            gl_Position = vec4(-1.0,-1.0, 0.0, 1.0);\n"
4248                                                                                                                          "            break;\n"
4249                                                                                                                          "        case 3:\n"
4250                                                                                                                          "            gl_Position = vec4( 1.0,-1.0, 0.0, 1.0);\n"
4251                                                                                                                          "            break;\n"
4252                                                                                                                          "    }\n"
4253                                                                                                                          "}\n";
4254
4255 /* Fragment shader source program. */
4256 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_head =
4257         "#version 450\n"
4258         "\n"
4259         "layout(pixel_center_integer) in vec4 gl_FragCoord;\n"
4260         "\n";
4261
4262 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_fdecl_lowp =
4263         "uniform  sampler2D texture_input;\nout     vec4          texture_output;\n";
4264 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_idecl_lowp =
4265         "uniform isampler2D texture_input;\nout     ivec4         texture_output;\n";
4266 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_udecl_lowp =
4267         "uniform usampler2D texture_input;\nout     uvec4         texture_output;\n";
4268 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_fdecl_mediump =
4269         "uniform  sampler2D texture_input;\nout     vec4          texture_output;\n";
4270 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_idecl_mediump =
4271         "uniform isampler2D texture_input;\nout     ivec4         texture_output;\n";
4272 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_udecl_mediump =
4273         "uniform usampler2D texture_input;\nout     uvec4         texture_output;\n";
4274 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_fdecl_highp =
4275         "uniform  sampler2D texture_input;\nout     vec4          texture_output;\n";
4276 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_idecl_highp =
4277         "uniform isampler2D texture_input;\nout     ivec4         texture_output;\n";
4278 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_udecl_highp =
4279         "uniform usampler2D texture_input;\nout     uvec4         texture_output;\n";
4280
4281 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_fdecl_lowp =
4282         "uniform  sampler2DArray texture_input;\nout     vec4          texture_output;\n";
4283
4284 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_idecl_lowp =
4285         "uniform isampler2DArray texture_input;\nout     ivec4         texture_output;\n";
4286
4287 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_udecl_lowp =
4288         "uniform usampler2DArray texture_input;\nout     uvec4         texture_output;\n";
4289
4290 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_fdecl_mediump =
4291         "uniform  sampler2DArray texture_input;\nout     vec4          texture_output;\n";
4292
4293 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_idecl_mediump =
4294         "uniform isampler2DArray texture_input;\nout     ivec4         texture_output;\n";
4295
4296 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_udecl_mediump =
4297         "uniform usampler2DArray texture_input;\nout     uvec4         texture_output;\n";
4298
4299 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_fdecl_highp =
4300         "uniform  sampler2DArray texture_input;\nout     vec4          texture_output;\n";
4301
4302 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_idecl_highp =
4303         "uniform isampler2DArray texture_input;\nout     ivec4         texture_output;\n";
4304
4305 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_udecl_highp =
4306         "uniform usampler2DArray texture_input;\nout     uvec4         texture_output;\n";
4307
4308 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_fdecl_lowp =
4309         "uniform  sampler2DMS texture_input;\nout     vec4          texture_output;\n";
4310 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_idecl_lowp =
4311         "uniform isampler2DMS texture_input;\nout     ivec4         texture_output;\n";
4312 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_udecl_lowp =
4313         "uniform usampler2DMS texture_input;\nout     uvec4         texture_output;\n";
4314
4315 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_fdecl_mediump =
4316         "uniform  sampler2DMS texture_input;\nout     vec4          texture_output;\n";
4317
4318 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_idecl_mediump =
4319         "uniform isampler2DMS texture_input;\nout     ivec4         texture_output;\n";
4320
4321 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_udecl_mediump =
4322         "uniform usampler2DMS texture_input;\nout     uvec4         texture_output;\n";
4323
4324 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_fdecl_highp =
4325         "uniform  sampler2DMS texture_input;\nout     vec4          texture_output;\n";
4326 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_idecl_highp =
4327         "uniform isampler2DMS texture_input;\nout     ivec4         texture_output;\n";
4328 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_udecl_highp =
4329         "uniform usampler2DMS texture_input;\nout     uvec4         texture_output;\n";
4330
4331 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_fdecl_lowp =
4332         "uniform  sampler2DMSArray texture_input;\nout     vec4          texture_output;\n";
4333
4334 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_idecl_lowp =
4335         "uniform isampler2DMSArray texture_input;\nout     ivec4         texture_output;\n";
4336
4337 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_udecl_lowp =
4338         "uniform usampler2DMSArray texture_input;\nout     uvec4         texture_output;\n";
4339
4340 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_fdecl_mediump =
4341         "uniform  sampler2DMSArray texture_input;\nout     vec4          texture_output;\n";
4342
4343 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_idecl_mediump =
4344         "uniform isampler2DMSArray texture_input;\nout     ivec4         texture_output;\n";
4345
4346 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_udecl_mediump =
4347         "uniform usampler2DMSArray texture_input;\nout     uvec4         texture_output;\n";
4348
4349 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_fdecl_highp =
4350         "uniform  sampler2DMSArray texture_input;\nout     vec4          texture_output;\n";
4351
4352 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_idecl_highp =
4353         "uniform isampler2DMSArray texture_input;\nout     ivec4         texture_output;\n";
4354
4355 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_udecl_highp =
4356         "uniform usampler2DMSArray texture_input;\nout     uvec4         texture_output;\n";
4357
4358 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_tail_2D =
4359         "\n"
4360         "void main()\n"
4361         "{\n"
4362         "    texture_output = texelFetch(texture_input, ivec2(gl_FragCoord.xy), 0);\n"
4363         "}\n";
4364
4365 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_tail_3D =
4366         "\n"
4367         "uniform int texture_layer;\n"
4368         "\n"
4369         "void main()\n"
4370         "{\n"
4371         "    texture_output = texelFetch(texture_input, ivec3(gl_FragCoord.xy, texture_layer), 0);\n"
4372         "}\n";
4373
4374 /******************************** Compressed SubImage Test Implementation   ********************************/
4375
4376 /** @brief Compressed SubImage Test constructor.
4377  *
4378  *  @param [in] context     OpenGL context.
4379  */
4380 CompressedSubImageTest::CompressedSubImageTest(deqp::Context& context)
4381         : deqp::TestCase(context, "textures_compressed_subimage", "Texture Compressed SubImage Test")
4382         , m_to(0)
4383         , m_to_aux(0)
4384         , m_compressed_texture_data(DE_NULL)
4385         , m_reference(DE_NULL)
4386         , m_result(DE_NULL)
4387         , m_reference_size(0)
4388         , m_reference_internalformat(0)
4389 {
4390         /* Intentionally left blank. */
4391 }
4392
4393 /** @brief Create texture.
4394  *
4395  *  @param [in] target      Texture target.
4396  */
4397 void CompressedSubImageTest::CreateTextures(glw::GLenum target)
4398 {
4399         /* Shortcut for GL functionality. */
4400         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4401
4402         /* Auxiliary texture (for content creation). */
4403         gl.genTextures(1, &m_to_aux);
4404         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
4405
4406         gl.bindTexture(target, m_to_aux);
4407         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4408
4409         /* Test texture (for data upload). */
4410         gl.genTextures(1, &m_to);
4411         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
4412
4413         gl.bindTexture(target, m_to);
4414         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4415 }
4416
4417 /** @brief Texture target selector.
4418  *
4419  *  @tparam D      Texture dimenisons.
4420  *
4421  *  @return Texture target.
4422  */
4423 template <>
4424 glw::GLenum CompressedSubImageTest::TextureTarget<1>()
4425 {
4426         return GL_TEXTURE_1D;
4427 }
4428
4429 template <>
4430 glw::GLenum CompressedSubImageTest::TextureTarget<2>()
4431 {
4432         return GL_TEXTURE_2D;
4433 }
4434
4435 template <>
4436 glw::GLenum CompressedSubImageTest::TextureTarget<3>()
4437 {
4438         return GL_TEXTURE_2D_ARRAY;
4439 }
4440
4441 /** @brief Prepare texture data for the auxiliary texture.
4442  *
4443  *  @tparam D      Texture dimenisons.
4444  *
4445  *  @note parameters as passed to texImage*
4446  */
4447 template <>
4448 void CompressedSubImageTest::TextureImage<1>(glw::GLint internalformat)
4449 {
4450         /* Shortcut for GL functionality. */
4451         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4452
4453         gl.texImage1D(TextureTarget<1>(), 0, internalformat, s_texture_width, 0, GL_RGBA, GL_UNSIGNED_BYTE, s_texture_data);
4454         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
4455 }
4456
4457 /** @brief Prepare texture data for the auxiliary texture.
4458  *
4459  *  @tparam D      Texture dimenisons.
4460  *
4461  *  @note parameters as passed to texImage*
4462  */
4463 template <>
4464 void CompressedSubImageTest::TextureImage<2>(glw::GLint internalformat)
4465 {
4466         /* Shortcut for GL functionality. */
4467         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4468
4469         gl.texImage2D(TextureTarget<2>(), 0, internalformat, s_texture_width, s_texture_height, 0, GL_RGBA,
4470                                   GL_UNSIGNED_BYTE, s_texture_data);
4471         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
4472 }
4473
4474 /** @brief Prepare texture data for the auxiliary texture.
4475  *
4476  *  @tparam D      Texture dimenisons.
4477  *
4478  *  @note parameters as passed to texImage*
4479  */
4480 template <>
4481 void CompressedSubImageTest::TextureImage<3>(glw::GLint internalformat)
4482 {
4483         /* Shortcut for GL functionality. */
4484         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4485
4486         gl.texImage3D(TextureTarget<3>(), 0, internalformat, s_texture_width, s_texture_height, s_texture_depth, 0, GL_RGBA,
4487                                   GL_UNSIGNED_BYTE, s_texture_data);
4488         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage3D has failed");
4489 }
4490
4491 /** @brief Prepare texture data for the auxiliary texture.
4492  *
4493  *  @tparam D      Texture dimensions.
4494  *
4495  *  @note parameters as passed to compressedTexImage*
4496  */
4497 template <>
4498 void CompressedSubImageTest::CompressedTexImage<1>(glw::GLint internalformat)
4499 {
4500         /* Shortcut for GL functionality. */
4501         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4502
4503         gl.compressedTexImage1D(TextureTarget<1>(), 0, internalformat, s_texture_width, 0, m_reference_size,
4504                                                         m_compressed_texture_data);
4505         GLU_EXPECT_NO_ERROR(gl.getError(), "glCompressedTexImage1D has failed");
4506 }
4507
4508 /** @brief Prepare texture data for the auxiliary texture.
4509  *
4510  *  @tparam D      Texture dimensions.
4511  *
4512  *  @note parameters as passed to compressedTexImage*
4513  */
4514 template <>
4515 void CompressedSubImageTest::CompressedTexImage<2>(glw::GLint internalformat)
4516 {
4517         /* Shortcut for GL functionality. */
4518         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4519
4520         gl.compressedTexImage2D(TextureTarget<2>(), 0, internalformat, s_texture_width, s_texture_height, 0,
4521                                                         m_reference_size, m_compressed_texture_data);
4522         GLU_EXPECT_NO_ERROR(gl.getError(), "glCompressedTexImage2D has failed");
4523 }
4524
4525 /** @brief Prepare texture data for the auxiliary texture.
4526  *
4527  *  @tparam D      Texture dimensions.
4528  *
4529  *  @note parameters as passed to compressedTexImage*
4530  */
4531 template <>
4532 void CompressedSubImageTest::CompressedTexImage<3>(glw::GLint internalformat)
4533 {
4534         /* Shortcut for GL functionality. */
4535         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4536
4537         gl.compressedTexImage3D(TextureTarget<3>(), 0, internalformat, s_texture_width, s_texture_height, s_texture_depth,
4538                                                         0, m_reference_size, m_compressed_texture_data);
4539         GLU_EXPECT_NO_ERROR(gl.getError(), "glCompressedTexImage3D has failed");
4540 }
4541
4542 /** @brief Prepare texture data for the compressed texture.
4543  *
4544  *  @tparam D      Texture dimenisons.
4545  *
4546  *  @param [in] internalformat      Texture internal format.
4547  *
4548  *  @return True if tested function succeeded, false otherwise.
4549  */
4550 template <>
4551 bool CompressedSubImageTest::CompressedTextureSubImage<1>(glw::GLint internalformat)
4552 {
4553         /* Shortcut for GL functionality. */
4554         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4555
4556         /* Load texture image with tested function. */
4557         if (m_reference_size)
4558         {
4559                 for (glw::GLuint block = 0; block < s_block_count; ++block)
4560                 {
4561                         gl.compressedTextureSubImage1D(m_to, 0, s_texture_width * block, s_texture_width, internalformat,
4562                                                                                    m_reference_size, m_compressed_texture_data);
4563                 }
4564         }
4565         else
4566         {
4567                 /* For 1D version there is no specific compressed texture internal format spcified in OpenGL 4.5 core profile documentation.
4568                  Only implementation depended specific internalformats may provide this functionality. As a result there may be no reference data to be substituted.
4569                  Due to this reason there is no use of CompressedTextureSubImage1D and particulary it cannot be tested. */
4570                 return true;
4571         }
4572
4573         /* Check errors. */
4574         glw::GLenum error;
4575
4576         if (GL_NO_ERROR != (error = gl.getError()))
4577         {
4578                 m_context.getTestContext().getLog()
4579                         << tcu::TestLog::Message << "glCompressedTextureSubImage1D unexpectedly generated error "
4580                         << glu::getErrorStr(error) << " during the test with internal format "
4581                         << glu::getTextureFormatStr(internalformat) << ". Test fails." << tcu::TestLog::EndMessage;
4582
4583                 return false;
4584         }
4585
4586         return true;
4587 }
4588
4589 /** @brief Prepare texture data for the compressed texture.
4590  *
4591  *  @tparam D      Texture dimenisons.
4592  *
4593  *  @param [in] internalformat      Texture internal format.
4594  *
4595  *  @return True if tested function succeeded, false otherwise.
4596  */
4597 template <>
4598 bool CompressedSubImageTest::CompressedTextureSubImage<2>(glw::GLint internalformat)
4599 {
4600         /* Shortcut for GL functionality. */
4601         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4602
4603         for (glw::GLuint y = 0; y < s_block_2d_size_y; ++y)
4604         {
4605                 for (glw::GLuint x = 0; x < s_block_2d_size_x; ++x)
4606                 {
4607                         /* Load texture image with tested function. */
4608                         gl.compressedTextureSubImage2D(m_to, 0, s_texture_width * x, s_texture_height * y, s_texture_width,
4609                                                                                    s_texture_height, internalformat, m_reference_size,
4610                                                                                    m_compressed_texture_data);
4611                 }
4612         }
4613         /* Check errors. */
4614         glw::GLenum error;
4615
4616         if (GL_NO_ERROR != (error = gl.getError()))
4617         {
4618                 m_context.getTestContext().getLog()
4619                         << tcu::TestLog::Message << "glCompressedTextureSubImage2D unexpectedly generated error "
4620                         << glu::getErrorStr(error) << " during the test with internal format "
4621                         << glu::getTextureFormatStr(internalformat) << ". Test fails." << tcu::TestLog::EndMessage;
4622
4623                 return false;
4624         }
4625
4626         return true;
4627 }
4628
4629 /** @brief Prepare texture data for the compressed texture.
4630  *
4631  *  @tparam D      Texture dimenisons.
4632  *
4633  *  @param [in] internalformat      Texture internal format.
4634  *
4635  *  @return True if tested function succeeded, false otherwise.
4636  */
4637 template <>
4638 bool CompressedSubImageTest::CompressedTextureSubImage<3>(glw::GLint internalformat)
4639 {
4640         /* Shortcut for GL functionality. */
4641         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4642
4643         for (glw::GLuint z = 0; z < s_block_3d_size; ++z)
4644         {
4645                 for (glw::GLuint y = 0; y < s_block_3d_size; ++y)
4646                 {
4647                         for (glw::GLuint x = 0; x < s_block_3d_size; ++x)
4648                         {
4649                                 /* Load texture image with tested function. */
4650                                 gl.compressedTextureSubImage3D(m_to, 0, s_texture_width * x, s_texture_height * y, s_texture_depth * z,
4651                                                                                            s_texture_width, s_texture_height, s_texture_depth, internalformat,
4652                                                                                            m_reference_size, m_compressed_texture_data);
4653                         }
4654                 }
4655         }
4656
4657         /* Check errors. */
4658         glw::GLenum error;
4659
4660         if (GL_NO_ERROR != (error = gl.getError()))
4661         {
4662                 m_context.getTestContext().getLog()
4663                         << tcu::TestLog::Message << "glCompressedTextureSubImage2D unexpectedly generated error "
4664                         << glu::getErrorStr(error) << " during the test with internal format "
4665                         << glu::getTextureFormatStr(internalformat) << ". Test fails." << tcu::TestLog::EndMessage;
4666
4667                 return false;
4668         }
4669         return true;
4670 }
4671
4672 /** @brief Prepare the reference data.
4673  *
4674  *  @tparam D      Texture dimenisons.
4675  */
4676 template <glw::GLuint D>
4677 void CompressedSubImageTest::PrepareReferenceData(glw::GLenum internalformat)
4678 {
4679         /* Shortcut for GL functionality. */
4680         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4681
4682         /* Using OpenGL to compress raw data. */
4683         gl.bindTexture(TextureTarget<D>(), m_to_aux);
4684         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4685
4686         TextureImage<D>(internalformat);
4687
4688         /* Sanity checks. */
4689         if ((DE_NULL != m_reference) || (DE_NULL != m_compressed_texture_data))
4690         {
4691                 throw 0;
4692         }
4693
4694         /* Check that really compressed texture. */
4695         glw::GLint is_compressed_texture = 0;
4696         gl.getTexLevelParameteriv(TextureTarget<D>(), 0, GL_TEXTURE_COMPRESSED, &is_compressed_texture);
4697
4698         if (is_compressed_texture)
4699         {
4700                 /* Query texture size. */
4701                 glw::GLint compressed_texture_size = 0;
4702                 gl.getTexLevelParameteriv(TextureTarget<D>(), 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compressed_texture_size);
4703
4704                 /* If compressed then download. */
4705                 if (compressed_texture_size)
4706                 {
4707                         /* Prepare storage. */
4708                         m_compressed_texture_data = new glw::GLubyte[compressed_texture_size];
4709
4710                         if (DE_NULL != m_compressed_texture_data)
4711                         {
4712                                 m_reference_size = compressed_texture_size;
4713                         }
4714                         else
4715                         {
4716                                 throw 0;
4717                         }
4718
4719                         /* Download the source compressed texture image. */
4720                         gl.getCompressedTexImage(TextureTarget<D>(), 0, m_compressed_texture_data);
4721                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
4722
4723                         // Upload the source compressed texture image to the texture object.
4724                         // Some compressed texture format can be emulated by the driver (like the ETC2/EAC formats)
4725                         // The compressed data sent by CompressedTexImage will be stored uncompressed by the driver
4726                         // and will be re-compressed if the application call glGetCompressedTexImage.
4727                         // The compression/decompression is not lossless, so when this happen it's possible for the source
4728                         // and destination (from glGetCompressedTexImage) compressed data to be different.
4729                         // To avoid that we will store both the source (in m_compressed_texture_data) and the destination
4730                         // (in m_reference). The destination will be used later to make sure getCompressedTextureSubImage
4731                         // return the expected value
4732                         CompressedTexImage<D>(internalformat);
4733
4734                         m_reference = new glw::GLubyte[m_reference_size];
4735
4736                         if (DE_NULL == m_reference)
4737                         {
4738                                 throw 0;
4739                         }
4740
4741                         /* Download compressed texture image. */
4742                         gl.getCompressedTexImage(TextureTarget<D>(), 0, m_reference);
4743                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
4744                 }
4745         }
4746 }
4747
4748 /** @brief Prepare texture storage.
4749  *
4750  *  @tparam D      Texture dimenisons.
4751  *
4752  *  @param [in] internalformat      Texture internal format.
4753  */
4754 template <>
4755 void CompressedSubImageTest::PrepareStorage<1>(glw::GLenum internalformat)
4756 {
4757         /* Shortcut for GL functionality. */
4758         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4759
4760         gl.bindTexture(TextureTarget<1>(), m_to);
4761         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4762
4763         gl.texImage1D(TextureTarget<1>(), 0, internalformat, s_texture_width * s_block_count, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4764                                   NULL);
4765         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
4766 }
4767
4768 /** @brief Prepare texture storage.
4769  *
4770  *  @tparam D      Texture dimenisons.
4771  *
4772  *  @param [in] internalformat      Texture internal format.
4773  */
4774 template <>
4775 void CompressedSubImageTest::PrepareStorage<2>(glw::GLenum internalformat)
4776 {
4777         /* Shortcut for GL functionality. */
4778         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4779
4780         gl.bindTexture(TextureTarget<2>(), m_to);
4781         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4782
4783         gl.texImage2D(TextureTarget<2>(), 0, internalformat, s_texture_width * s_block_2d_size_x,
4784                                   s_texture_height * s_block_2d_size_y, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
4785         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
4786 }
4787
4788 /** @brief Prepare texture storage.
4789  *
4790  *  @tparam D      Texture dimenisons.
4791  *
4792  *  @param [in] internalformat      Texture internal format.
4793  */
4794 template <>
4795 void CompressedSubImageTest::PrepareStorage<3>(glw::GLenum internalformat)
4796 {
4797         /* Shortcut for GL functionality. */
4798         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4799
4800         gl.bindTexture(TextureTarget<3>(), m_to);
4801         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4802
4803         gl.texImage3D(TextureTarget<3>(), 0, internalformat, s_texture_width * s_block_3d_size,
4804                                   s_texture_height * s_block_3d_size, s_texture_depth * s_block_3d_size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4805                                   NULL);
4806         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
4807 }
4808
4809 /** @brief Compare results with the reference.
4810  *
4811  *  @tparam T      Type.
4812  *  @tparam S      Size (# of components).
4813  *  @tparam N      Is normalized.
4814  *
4815  *  @param [in] internalformat      Texture internal format.
4816  *
4817  *  @return True if equal, false otherwise.
4818  */
4819 template <glw::GLuint D>
4820 bool CompressedSubImageTest::CheckData(glw::GLenum internalformat)
4821 {
4822         /* Shortcut for GL functionality. */
4823         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4824
4825         /* Check texture content with reference. */
4826         m_result = new glw::GLubyte[m_reference_size * s_block_count];
4827
4828         if (DE_NULL == m_result)
4829         {
4830                 throw 0;
4831         }
4832
4833         gl.getCompressedTexImage(TextureTarget<D>(), 0, m_result);
4834         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
4835         for (glw::GLuint block = 0; block < s_block_count; ++block)
4836         {
4837                 for (glw::GLuint i = 0; i < m_reference_size; ++i)
4838                 {
4839                         if (m_reference[i] != m_result[block * m_reference_size + i])
4840                         {
4841                                 m_context.getTestContext().getLog()
4842                                         << tcu::TestLog::Message << "glCompressedTextureSubImage*D created texture with data "
4843                                         << DataToString(m_reference_size, m_reference) << " however texture contains data "
4844                                         << DataToString(m_reference_size, &(m_result[block * m_reference_size])) << ". Texture target was "
4845                                         << glu::getTextureTargetStr(TextureTarget<D>()) << " and internal format was "
4846                                         << glu::getTextureFormatStr(internalformat) << ". Test fails." << tcu::TestLog::EndMessage;
4847
4848                                 return false;
4849                         }
4850                 }
4851         }
4852
4853         return true;
4854 }
4855
4856 /** @brief Compare results with the reference.
4857  *
4858  *  @tparam T      Type.
4859  *  @tparam S      Size (# of components).
4860  *  @tparam N      Is normalized.
4861  *
4862  *  @param [in] internalformat      Texture internal format.
4863  *
4864  *  @return True if equal, false otherwise.
4865  */
4866 template <>
4867 bool CompressedSubImageTest::CheckData<3>(glw::GLenum internalformat)
4868 {
4869         /* Shortcut for GL functionality. */
4870         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4871
4872         /* Check texture content with reference. */
4873         m_result = new glw::GLubyte[m_reference_size * s_block_count];
4874
4875         if (DE_NULL == m_result)
4876         {
4877                 throw 0;
4878         }
4879
4880         gl.getCompressedTexImage(TextureTarget<3>(), 0, m_result);
4881         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
4882
4883         glw::GLuint reference_layer_size = m_reference_size / s_texture_depth;
4884
4885         for (glw::GLuint i = 0; i < m_reference_size * s_block_count; ++i)
4886         {
4887                 // we will read the result one bytes at the time and compare with the reference
4888                 // for each bytes of the result image we need to figure out which byte in the reference image it corresponds to
4889                 glw::GLuint refIdx              = i % reference_layer_size;
4890                 glw::GLuint refLayerIdx = (i / (reference_layer_size * s_block_3d_size * s_block_3d_size)) % s_texture_depth;
4891                 if (m_reference[refLayerIdx * reference_layer_size + refIdx] != m_result[i])
4892                 {
4893                         m_context.getTestContext().getLog()
4894                                 << tcu::TestLog::Message << "glCompressedTextureSubImage3D created texture with data "
4895                                 << DataToString(reference_layer_size, &(m_reference[refLayerIdx * reference_layer_size]))
4896                                 << " however texture contains data "
4897                                 << DataToString(reference_layer_size, &(m_result[i % reference_layer_size])) << ". Texture target was "
4898                                 << glu::getTextureTargetStr(TextureTarget<3>()) << " and internal format was "
4899                                 << glu::getTextureFormatStr(internalformat) << ". Test fails." << tcu::TestLog::EndMessage;
4900
4901                         return false;
4902                 }
4903         }
4904
4905         return true;
4906 }
4907 /** @brief Test case function.
4908  *
4909  *  @tparam D       Number of texture dimensions.
4910  *
4911  *  @param [in] internal format     Texture internal format.
4912  *
4913  *  @return True if test succeeded, false otherwise.
4914  */
4915 template <glw::GLuint D>
4916 bool CompressedSubImageTest::Test(glw::GLenum internalformat)
4917 {
4918         /* Create texture image. */
4919         CreateTextures(TextureTarget<D>());
4920         PrepareReferenceData<D>(internalformat);
4921         PrepareStorage<D>(internalformat);
4922
4923         /* Setup data with CompressedTextureSubImage<D>D function and check for errors. */
4924         if (!CompressedTextureSubImage<D>(internalformat))
4925         {
4926                 CleanAll();
4927
4928                 return false;
4929         }
4930
4931         /* If compressed reference data was generated than compare values. */
4932         if (m_reference)
4933         {
4934                 if (!CheckData<D>(internalformat))
4935                 {
4936                         CleanAll();
4937
4938                         return false;
4939                 }
4940         }
4941
4942         CleanAll();
4943
4944         return true;
4945 }
4946
4947 /** @brief Clean GL objects, test variables and GL errors.
4948  */
4949 void CompressedSubImageTest::CleanAll()
4950 {
4951         /* Shortcut for GL functionality. */
4952         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4953
4954         /* Textures. */
4955         if (m_to)
4956         {
4957                 gl.deleteTextures(1, &m_to);
4958
4959                 m_to = 0;
4960         }
4961
4962         if (m_to_aux)
4963         {
4964                 gl.deleteTextures(1, &m_to_aux);
4965
4966                 m_to_aux = 0;
4967         }
4968
4969         /* Reference data storage. */
4970         if (DE_NULL != m_reference)
4971         {
4972                 delete[] m_reference;
4973
4974                 m_reference = DE_NULL;
4975         }
4976
4977         if (DE_NULL != m_compressed_texture_data)
4978         {
4979                 delete[] m_compressed_texture_data;
4980
4981                 m_compressed_texture_data = DE_NULL;
4982         }
4983
4984         if (DE_NULL != m_result)
4985         {
4986                 delete[] m_result;
4987
4988                 m_result = DE_NULL;
4989         }
4990
4991         m_reference_size = 0;
4992
4993         /* Errors. */
4994         while (GL_NO_ERROR != gl.getError())
4995                 ;
4996 }
4997
4998 /** @brief Convert raw data into string for logging purposes.
4999  *
5000  *  @param [in] count      Count of the data.
5001  *  @param [in] data       Raw data.
5002  *
5003  *  @return String representation of data.
5004  */
5005 std::string CompressedSubImageTest::DataToString(glw::GLuint count, const glw::GLubyte data[])
5006 {
5007         std::string data_str = "[";
5008
5009         for (glw::GLuint i = 0; i < count; ++i)
5010         {
5011                 std::stringstream int_sstream;
5012
5013                 int_sstream << unsigned(data[i]);
5014
5015                 data_str.append(int_sstream.str());
5016
5017                 if (i + 1 < count)
5018                 {
5019                         data_str.append(", ");
5020                 }
5021                 else
5022                 {
5023                         data_str.append("]");
5024                 }
5025         }
5026
5027         return data_str;
5028 }
5029
5030 /** @brief Iterate Compressed SubImage Test cases.
5031  *
5032  *  @return Iteration result.
5033  */
5034 tcu::TestNode::IterateResult CompressedSubImageTest::iterate()
5035 {
5036         /* Shortcut for GL functionality. */
5037         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5038
5039         /* Get context setup. */
5040         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
5041         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
5042
5043         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
5044         {
5045                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
5046
5047                 return STOP;
5048         }
5049
5050         /* Running tests. */
5051         bool is_ok      = true;
5052         bool is_error = false;
5053
5054         try
5055         {
5056                 is_ok &= Test<1>(GL_COMPRESSED_RGB);
5057
5058                 is_ok &= Test<2>(GL_COMPRESSED_RED_RGTC1);
5059                 is_ok &= Test<2>(GL_COMPRESSED_SIGNED_RED_RGTC1);
5060                 is_ok &= Test<2>(GL_COMPRESSED_RG_RGTC2);
5061                 is_ok &= Test<2>(GL_COMPRESSED_SIGNED_RG_RGTC2);
5062                 is_ok &= Test<2>(GL_COMPRESSED_RGBA_BPTC_UNORM);
5063                 is_ok &= Test<2>(GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM);
5064                 is_ok &= Test<2>(GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT);
5065                 is_ok &= Test<2>(GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT);
5066                 is_ok &= Test<2>(GL_COMPRESSED_RGB8_ETC2);
5067                 is_ok &= Test<2>(GL_COMPRESSED_SRGB8_ETC2);
5068                 is_ok &= Test<2>(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2);
5069                 is_ok &= Test<2>(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2);
5070                 is_ok &= Test<2>(GL_COMPRESSED_RGBA8_ETC2_EAC);
5071                 is_ok &= Test<2>(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC);
5072                 is_ok &= Test<2>(GL_COMPRESSED_R11_EAC);
5073                 is_ok &= Test<2>(GL_COMPRESSED_SIGNED_R11_EAC);
5074                 is_ok &= Test<2>(GL_COMPRESSED_RG11_EAC);
5075                 is_ok &= Test<2>(GL_COMPRESSED_SIGNED_RG11_EAC);
5076
5077                 is_ok &= Test<3>(GL_COMPRESSED_RED_RGTC1);
5078                 is_ok &= Test<3>(GL_COMPRESSED_SIGNED_RED_RGTC1);
5079                 is_ok &= Test<3>(GL_COMPRESSED_RG_RGTC2);
5080                 is_ok &= Test<3>(GL_COMPRESSED_SIGNED_RG_RGTC2);
5081                 is_ok &= Test<3>(GL_COMPRESSED_RGBA_BPTC_UNORM);
5082                 is_ok &= Test<3>(GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM);
5083                 is_ok &= Test<3>(GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT);
5084                 is_ok &= Test<3>(GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT);
5085                 is_ok &= Test<3>(GL_COMPRESSED_RGB8_ETC2);
5086                 is_ok &= Test<3>(GL_COMPRESSED_SRGB8_ETC2);
5087                 is_ok &= Test<3>(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2);
5088                 is_ok &= Test<3>(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2);
5089                 is_ok &= Test<3>(GL_COMPRESSED_RGBA8_ETC2_EAC);
5090                 is_ok &= Test<3>(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC);
5091                 is_ok &= Test<3>(GL_COMPRESSED_R11_EAC);
5092                 is_ok &= Test<3>(GL_COMPRESSED_SIGNED_R11_EAC);
5093                 is_ok &= Test<3>(GL_COMPRESSED_RG11_EAC);
5094                 is_ok &= Test<3>(GL_COMPRESSED_SIGNED_RG11_EAC);
5095         }
5096         catch (...)
5097         {
5098                 is_ok   = false;
5099                 is_error = true;
5100         }
5101
5102         /* Cleanup. */
5103         CleanAll();
5104
5105         /* Errors clean up. */
5106         while (gl.getError())
5107                 ;
5108
5109         /* Result's setup. */
5110         if (is_ok)
5111         {
5112                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
5113         }
5114         else
5115         {
5116                 if (is_error)
5117                 {
5118                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
5119                 }
5120                 else
5121                 {
5122                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
5123                 }
5124         }
5125
5126         return STOP;
5127 }
5128
5129 /** Reference data. */
5130 const glw::GLubyte CompressedSubImageTest::s_texture_data[] = {
5131         0x00, 0x00, 0x00, 0xFF, 0x7f, 0x7f, 0x7f, 0x00, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0x00,
5132         0x88, 0x00, 0x15, 0xFF, 0xed, 0x1c, 0x24, 0x00, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x00, 0x00,
5133         0xc8, 0xbf, 0xe7, 0xFF, 0x70, 0x92, 0xbe, 0x00, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0x00,
5134         0xa3, 0x49, 0xa4, 0xFF, 0x3f, 0x48, 0xcc, 0x00, 0x00, 0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0x00,
5135
5136         0xa3, 0x49, 0xa4, 0xFF, 0xc8, 0xbf, 0xe7, 0x00, 0x88, 0x00, 0x15, 0xff, 0x00, 0x00, 0x00, 0x00,
5137         0x3f, 0x48, 0xcc, 0xFF, 0x70, 0x92, 0xbe, 0x00, 0xed, 0x1c, 0x24, 0xff, 0x7f, 0x7f, 0x7f, 0x00,
5138         0x00, 0xa2, 0xe8, 0xFF, 0x99, 0xd9, 0xea, 0x00, 0xff, 0x7f, 0x27, 0xff, 0xc3, 0xc3, 0xc3, 0x00,
5139         0x22, 0xb1, 0x4c, 0xFF, 0xb5, 0xe6, 0x1d, 0x00, 0xff, 0xf2, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00,
5140
5141         0x22, 0xb1, 0x4c, 0xFF, 0x00, 0xa2, 0xe8, 0x00, 0x3f, 0x48, 0xcc, 0xff, 0xa3, 0x49, 0xa4, 0x00,
5142         0xb5, 0xe6, 0x1d, 0xFF, 0x99, 0xd9, 0xea, 0x00, 0x70, 0x92, 0xbe, 0xff, 0xc8, 0xbf, 0xe7, 0x00,
5143         0xff, 0xf2, 0x00, 0xFF, 0xff, 0x7f, 0x27, 0x00, 0xed, 0x1c, 0x24, 0xff, 0x88, 0x00, 0x15, 0x00,
5144         0xff, 0xff, 0xff, 0xFF, 0xc3, 0xc3, 0xc3, 0x00, 0x7f, 0x7f, 0x7f, 0xff, 0x00, 0x00, 0x00, 0x00,
5145
5146         0xff, 0xff, 0xff, 0xFF, 0xff, 0xf2, 0x00, 0x00, 0xb5, 0xe6, 0x1d, 0xff, 0x22, 0xb1, 0x4c, 0x00,
5147         0xc3, 0xc3, 0xc3, 0xFF, 0xff, 0x7f, 0x27, 0x00, 0x99, 0xd9, 0xea, 0xff, 0x00, 0xa2, 0xe8, 0x00,
5148         0x7f, 0x7f, 0x7f, 0xFF, 0xed, 0x1c, 0x24, 0x00, 0x70, 0x92, 0xbe, 0xff, 0x3f, 0x48, 0xcc, 0x00,
5149         0x00, 0x00, 0x00, 0xFF, 0x88, 0x00, 0x15, 0x00, 0xc8, 0xbf, 0xe7, 0xff, 0xa3, 0x49, 0xa4, 0x00
5150 };
5151
5152 /** Reference data parameters. */
5153 const glw::GLuint CompressedSubImageTest::s_texture_width   = 4;
5154 const glw::GLuint CompressedSubImageTest::s_texture_height  = 4;
5155 const glw::GLuint CompressedSubImageTest::s_texture_depth   = 4;
5156 const glw::GLuint CompressedSubImageTest::s_block_count         = 8;
5157 const glw::GLuint CompressedSubImageTest::s_block_2d_size_x = 4;
5158 const glw::GLuint CompressedSubImageTest::s_block_2d_size_y = 2;
5159 const glw::GLuint CompressedSubImageTest::s_block_3d_size   = 2;
5160
5161 /******************************** Copy SubImage Test Implementation   ********************************/
5162
5163 /** @brief Compressed SubImage Test constructor.
5164  *
5165  *  @param [in] context     OpenGL context.
5166  */
5167 CopyTest::CopyTest(deqp::Context& context)
5168         : deqp::TestCase(context, "textures_copy", "Texture Copy Test")
5169         , m_fbo(0)
5170         , m_to_src(0)
5171         , m_to_dst(0)
5172         , m_result(DE_NULL)
5173 {
5174         /* Intentionally left blank. */
5175 }
5176
5177 /** @brief Texture target selector.
5178  *
5179  *  @tparam D      Texture dimenisons.
5180  *
5181  *  @return Texture target.
5182  */
5183 template <>
5184 glw::GLenum CopyTest::TextureTarget<1>()
5185 {
5186         return GL_TEXTURE_1D;
5187 }
5188 template <>
5189 glw::GLenum CopyTest::TextureTarget<2>()
5190 {
5191         return GL_TEXTURE_2D;
5192 }
5193 template <>
5194 glw::GLenum CopyTest::TextureTarget<3>()
5195 {
5196         return GL_TEXTURE_3D;
5197 }
5198
5199 /** @brief Copy texture, check errors and log.
5200  *
5201  *  @note Parameters as passed to CopyTextureSubImage*D
5202  *
5203  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
5204  */
5205 bool CopyTest::CopyTextureSubImage1DAndCheckErrors(glw::GLuint texture, glw::GLint level, glw::GLint xoffset,
5206                                                                                                    glw::GLint x, glw::GLint y, glw::GLsizei width)
5207 {
5208         /* Shortcut for GL functionality. */
5209         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5210
5211         gl.readBuffer(GL_COLOR_ATTACHMENT0);
5212         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
5213
5214         gl.copyTextureSubImage1D(texture, level, xoffset, x, y, width);
5215
5216         /* Check errors. */
5217         glw::GLenum error;
5218
5219         if (GL_NO_ERROR != (error = gl.getError()))
5220         {
5221                 m_context.getTestContext().getLog() << tcu::TestLog::Message
5222                                                                                         << "glCopyTextureSubImage1D unexpectedly generated error "
5223                                                                                         << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
5224
5225                 return false;
5226         }
5227
5228         return true;
5229 }
5230
5231 /** @brief Copy texture, check errors and log.
5232  *
5233  *  @note Parameters as passed to CopyTextureSubImage*D
5234  *
5235  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
5236  */
5237 bool CopyTest::CopyTextureSubImage2DAndCheckErrors(glw::GLuint texture, glw::GLint level, glw::GLint xoffset,
5238                                                                                                    glw::GLint yoffset, glw::GLint x, glw::GLint y, glw::GLsizei width,
5239                                                                                                    glw::GLsizei height)
5240 {
5241         /* Shortcut for GL functionality. */
5242         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5243
5244         gl.readBuffer(GL_COLOR_ATTACHMENT0);
5245         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
5246
5247         gl.copyTextureSubImage2D(texture, level, xoffset, yoffset, x, y, width, height);
5248
5249         /* Check errors. */
5250         glw::GLenum error;
5251
5252         if (GL_NO_ERROR != (error = gl.getError()))
5253         {
5254                 m_context.getTestContext().getLog() << tcu::TestLog::Message
5255                                                                                         << "glCopyTextureSubImage2D unexpectedly generated error "
5256                                                                                         << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
5257
5258                 return false;
5259         }
5260
5261         return true;
5262 }
5263
5264 /** @brief Copy texture, check errors and log.
5265  *
5266  *  @note Parameters as passed to CopyTextureSubImage*D
5267  *
5268  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
5269  */
5270 bool CopyTest::CopyTextureSubImage3DAndCheckErrors(glw::GLuint texture, glw::GLint level, glw::GLint xoffset,
5271                                                                                                    glw::GLint yoffset, glw::GLint zoffset, glw::GLint x, glw::GLint y,
5272                                                                                                    glw::GLsizei width, glw::GLsizei height)
5273 {
5274         /* Shortcut for GL functionality. */
5275         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5276
5277         gl.readBuffer(GL_COLOR_ATTACHMENT0 + zoffset);
5278         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
5279
5280         gl.copyTextureSubImage3D(texture, level, xoffset, yoffset, zoffset, x, y, width, height);
5281
5282         /* Check errors. */
5283         glw::GLenum error;
5284
5285         if (GL_NO_ERROR != (error = gl.getError()))
5286         {
5287                 m_context.getTestContext().getLog() << tcu::TestLog::Message
5288                                                                                         << "glCopyTextureSubImage3D unexpectedly generated error "
5289                                                                                         << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
5290
5291                 return false;
5292         }
5293
5294         return true;
5295 }
5296
5297 /** @brief Create texture.
5298  *
5299  *  @tparam D      Dimmensions.
5300  */
5301 template <>
5302 void CopyTest::CreateSourceTexture<1>()
5303 {
5304         /* Shortcut for GL functionality. */
5305         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5306
5307         gl.genTextures(1, &m_to_src);
5308         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
5309
5310         gl.bindTexture(TextureTarget<1>(), m_to_src);
5311         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
5312
5313         gl.texImage1D(TextureTarget<1>(), 0, GL_RGBA8, s_texture_width, 0, GL_RGBA, GL_UNSIGNED_BYTE, s_texture_data);
5314         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed.");
5315 }
5316
5317 /** @brief Create texture.
5318  *
5319  *  @tparam D      Dimmensions.
5320  */
5321 template <>
5322 void CopyTest::CreateSourceTexture<2>()
5323 {
5324         /* Shortcut for GL functionality. */
5325         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5326
5327         gl.genTextures(1, &m_to_src);
5328         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
5329
5330         gl.bindTexture(TextureTarget<2>(), m_to_src);
5331         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
5332
5333         gl.texImage2D(TextureTarget<2>(), 0, GL_RGBA8, s_texture_width, s_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
5334                                   s_texture_data);
5335         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed.");
5336 }
5337
5338 /** @brief Create texture.
5339  *
5340  *  @tparam D      Dimmensions.
5341  */
5342 template <>
5343 void CopyTest::CreateSourceTexture<3>()
5344 {
5345         /* Shortcut for GL functionality. */
5346         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5347
5348         gl.genTextures(1, &m_to_src);
5349         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
5350
5351         gl.bindTexture(TextureTarget<3>(), m_to_src);
5352         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
5353
5354         gl.texImage3D(TextureTarget<3>(), 0, GL_RGBA8, s_texture_width, s_texture_height, s_texture_depth, 0, GL_RGBA,
5355                                   GL_UNSIGNED_BYTE, s_texture_data);
5356         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed.");
5357 }
5358
5359 /** @brief Create texture.
5360  *
5361  *  @tparam D      Dimmensions.
5362  */
5363 template <>
5364 void CopyTest::CreateDestinationTexture<1>()
5365 {
5366         /* Shortcut for GL functionality. */
5367         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5368
5369         gl.genTextures(1, &m_to_dst);
5370         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
5371
5372         gl.bindTexture(TextureTarget<1>(), m_to_dst);
5373         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
5374
5375         gl.texImage1D(TextureTarget<1>(), 0, GL_RGBA8, s_texture_width, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
5376         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed.");
5377 }
5378
5379 /** @brief Create texture.
5380  *
5381  *  @tparam D      Dimmensions.
5382  */
5383 template <>
5384 void CopyTest::CreateDestinationTexture<2>()
5385 {
5386         /* Shortcut for GL functionality. */
5387         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5388
5389         gl.genTextures(1, &m_to_dst);
5390         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
5391
5392         gl.bindTexture(TextureTarget<2>(), m_to_dst);
5393         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
5394
5395         gl.texImage2D(TextureTarget<2>(), 0, GL_RGBA8, s_texture_width, s_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
5396                                   DE_NULL);
5397         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed.");
5398 }
5399
5400 /** @brief Create texture.
5401  *
5402  *  @tparam D      Dimmensions.
5403  */
5404 template <>
5405 void CopyTest::CreateDestinationTexture<3>()
5406 {
5407         /* Shortcut for GL functionality. */
5408         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5409
5410         gl.genTextures(1, &m_to_dst);
5411         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
5412
5413         gl.bindTexture(TextureTarget<3>(), m_to_dst);
5414         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
5415
5416         gl.texImage3D(TextureTarget<3>(), 0, GL_RGBA8, s_texture_width, s_texture_height, s_texture_depth, 0, GL_RGBA,
5417                                   GL_UNSIGNED_BYTE, DE_NULL);
5418         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed.");
5419 }
5420
5421 /** @brief Create framebuffer.
5422  *
5423  *  @tparam D      Dimmensions.
5424  */
5425 template <>
5426 void CopyTest::CreateSourceFramebuffer<1>()
5427 {
5428         /* Shortcut for GL functionality. */
5429         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5430
5431         /* Prepare framebuffer. */
5432         gl.genFramebuffers(1, &m_fbo);
5433         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
5434
5435         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
5436         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
5437
5438         gl.framebufferTexture1D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, TextureTarget<1>(), m_to_src, 0);
5439         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture1D call failed.");
5440
5441         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
5442         {
5443                 throw 0;
5444         }
5445
5446         gl.viewport(0, 0, s_texture_width, 1);
5447         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
5448 }
5449
5450 /** @brief Create framebuffer.
5451  *
5452  *  @tparam D      Dimmensions.
5453  */
5454 template <>
5455 void CopyTest::CreateSourceFramebuffer<2>()
5456 {
5457         /* Shortcut for GL functionality. */
5458         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5459
5460         /* Prepare framebuffer. */
5461         gl.genFramebuffers(1, &m_fbo);
5462         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
5463
5464         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
5465         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
5466
5467         gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, TextureTarget<2>(), m_to_src, 0);
5468         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture1D call failed.");
5469
5470         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
5471         {
5472                 throw 0;
5473         }
5474
5475         gl.viewport(0, 0, s_texture_width, s_texture_height);
5476         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
5477 }
5478
5479 /** @brief Create framebuffer.
5480  *
5481  *  @tparam D      Dimmensions.
5482  */
5483 template <>
5484 void CopyTest::CreateSourceFramebuffer<3>()
5485 {
5486         /* Shortcut for GL functionality. */
5487         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5488
5489         /* Prepare framebuffer. */
5490         gl.genFramebuffers(1, &m_fbo);
5491         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
5492
5493         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
5494         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
5495
5496         for (glw::GLuint i = 0; i < s_texture_depth; ++i)
5497         {
5498                 gl.framebufferTexture3D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, TextureTarget<3>(), m_to_src, 0, i);
5499                 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture1D call failed.");
5500         }
5501
5502         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
5503         {
5504                 throw 0;
5505         }
5506
5507         gl.viewport(0, 0, s_texture_width, s_texture_height);
5508         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
5509 }
5510
5511 /** @brief Dispatch function to create test objects */
5512 template <glw::GLuint D>
5513 void                              CopyTest::CreateAll()
5514 {
5515         CreateSourceTexture<D>();
5516         CreateSourceFramebuffer<D>();
5517         CreateDestinationTexture<D>();
5518 }
5519
5520 /** @brief Test function */
5521 template <>
5522 bool CopyTest::Test<1>()
5523 {
5524         CreateAll<1>();
5525
5526         bool result = true;
5527
5528         result &= CopyTextureSubImage1DAndCheckErrors(m_to_dst, 0, 0, 0, 0, s_texture_width / 2);
5529         result &= CopyTextureSubImage1DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, s_texture_width / 2, 0,
5530                                                                                                   s_texture_width / 2);
5531
5532         result &= CheckData(TextureTarget<1>(), 4 /* RGBA */ * s_texture_width);
5533
5534         CleanAll();
5535
5536         return result;
5537 }
5538
5539 /** @brief Test function */
5540 template <>
5541 bool CopyTest::Test<2>()
5542 {
5543         CreateAll<2>();
5544
5545         bool result = true;
5546
5547         result &= CopyTextureSubImage2DAndCheckErrors(m_to_dst, 0, 0, 0, 0, 0, s_texture_width / 2, s_texture_height / 2);
5548         result &= CopyTextureSubImage2DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, 0, s_texture_width / 2, 0,
5549                                                                                                   s_texture_width / 2, s_texture_height / 2);
5550         result &= CopyTextureSubImage2DAndCheckErrors(m_to_dst, 0, 0, s_texture_height / 2, 0, s_texture_height / 2,
5551                                                                                                   s_texture_width / 2, s_texture_height / 2);
5552         result &=
5553                 CopyTextureSubImage2DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, s_texture_height / 2, s_texture_width / 2,
5554                                                                                         s_texture_height / 2, s_texture_width / 2, s_texture_height / 2);
5555
5556         result &= CheckData(TextureTarget<2>(), 4 /* RGBA */ * s_texture_width * s_texture_height);
5557
5558         CleanAll();
5559
5560         return result;
5561 }
5562
5563 /** @brief Test function */
5564 template <>
5565 bool CopyTest::Test<3>()
5566 {
5567         CreateAll<3>();
5568
5569         bool result = true;
5570
5571         for (glw::GLuint i = 0; i < s_texture_depth; ++i)
5572         {
5573                 result &=
5574                         CopyTextureSubImage3DAndCheckErrors(m_to_dst, 0, 0, 0, i, 0, 0, s_texture_width / 2, s_texture_height / 2);
5575                 result &= CopyTextureSubImage3DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, 0, i, s_texture_width / 2, 0,
5576                                                                                                           s_texture_width / 2, s_texture_height / 2);
5577                 result &= CopyTextureSubImage3DAndCheckErrors(m_to_dst, 0, 0, s_texture_height / 2, i, 0, s_texture_height / 2,
5578                                                                                                           s_texture_width / 2, s_texture_height / 2);
5579                 result &= CopyTextureSubImage3DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, s_texture_height / 2, i,
5580                                                                                                           s_texture_width / 2, s_texture_height / 2, s_texture_width / 2,
5581                                                                                                           s_texture_height / 2);
5582         }
5583
5584         result &= CheckData(TextureTarget<3>(), 4 /* RGBA */ * s_texture_width * s_texture_height * s_texture_depth);
5585
5586         CleanAll();
5587
5588         return result;
5589 }
5590
5591 /** @brief Compre results with the reference.
5592  *
5593  *  @param [in] target      Texture target.
5594  *  @param [in] size        Size of the buffer.
5595  *
5596  *  @return True if equal, false otherwise.
5597  */
5598 bool CopyTest::CheckData(glw::GLenum target, glw::GLuint size)
5599 {
5600         /* Shortcut for GL functionality. */
5601         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5602
5603         /* Check texture content with reference. */
5604         m_result = new glw::GLubyte[size];
5605
5606         if (DE_NULL == m_result)
5607         {
5608                 throw 0;
5609         }
5610
5611         gl.getTexImage(target, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_result);
5612         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
5613
5614         for (glw::GLuint i = 0; i < size; ++i)
5615         {
5616                 if (s_texture_data[i] != m_result[i])
5617                 {
5618                         m_context.getTestContext().getLog()
5619                                 << tcu::TestLog::Message << "glCopyTextureSubImage*D created texture with data "
5620                                 << DataToString(size, s_texture_data) << " however texture contains data "
5621                                 << DataToString(size, m_result) << ". Texture target was " << glu::getTextureTargetStr(target)
5622                                 << ". Test fails." << tcu::TestLog::EndMessage;
5623
5624                         return false;
5625                 }
5626         }
5627
5628         return true;
5629 }
5630
5631 /** @brief Convert raw data into string for logging purposes.
5632  *
5633  *  @param [in] count      Count of the data.
5634  *  @param [in] data       Raw data.
5635  *
5636  *  @return String representation of data.
5637  */
5638 std::string CopyTest::DataToString(glw::GLuint count, const glw::GLubyte data[])
5639 {
5640         std::string data_str = "[";
5641
5642         for (glw::GLuint i = 0; i < count; ++i)
5643         {
5644                 std::stringstream int_sstream;
5645
5646                 int_sstream << unsigned(data[i]);
5647
5648                 data_str.append(int_sstream.str());
5649
5650                 if (i + 1 < count)
5651                 {
5652                         data_str.append(", ");
5653                 }
5654                 else
5655                 {
5656                         data_str.append("]");
5657                 }
5658         }
5659
5660         return data_str;
5661 }
5662
5663 /** @brief Clean GL objects, test variables and GL errors.
5664  */
5665 void CopyTest::CleanAll()
5666 {
5667         /* Shortcut for GL functionality. */
5668         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5669
5670         if (m_fbo)
5671         {
5672                 gl.deleteFramebuffers(1, &m_fbo);
5673
5674                 m_fbo = 0;
5675         }
5676
5677         if (m_to_src)
5678         {
5679                 gl.deleteTextures(1, &m_to_src);
5680
5681                 m_to_src = 0;
5682         }
5683
5684         if (m_to_dst)
5685         {
5686                 gl.deleteTextures(1, &m_to_dst);
5687
5688                 m_to_dst = 0;
5689         }
5690
5691         if (DE_NULL == m_result)
5692         {
5693                 delete[] m_result;
5694
5695                 m_result = DE_NULL;
5696         }
5697
5698         while (GL_NO_ERROR != gl.getError())
5699                 ;
5700 }
5701
5702 /** @brief Iterate Copy Test cases.
5703  *
5704  *  @return Iteration result.
5705  */
5706 tcu::TestNode::IterateResult CopyTest::iterate()
5707 {
5708         /* Get context setup. */
5709         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
5710         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
5711
5712         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
5713         {
5714                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
5715
5716                 return STOP;
5717         }
5718
5719         /* Running tests. */
5720         bool is_ok      = true;
5721         bool is_error = false;
5722
5723         try
5724         {
5725                 is_ok &= Test<1>();
5726                 is_ok &= Test<2>();
5727                 is_ok &= Test<3>();
5728         }
5729         catch (...)
5730         {
5731                 is_ok   = false;
5732                 is_error = true;
5733         }
5734
5735         /* Cleanup. */
5736         CleanAll();
5737
5738         /* Result's setup. */
5739         if (is_ok)
5740         {
5741                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
5742         }
5743         else
5744         {
5745                 if (is_error)
5746                 {
5747                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
5748                 }
5749                 else
5750                 {
5751                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
5752                 }
5753         }
5754
5755         return STOP;
5756 }
5757
5758 /** Reference data. */
5759 const glw::GLubyte CopyTest::s_texture_data[] = {
5760         0x00, 0x00, 0x00, 0xFF, 0x7f, 0x7f, 0x7f, 0x00, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0x00,
5761         0x88, 0x00, 0x15, 0xFF, 0xed, 0x1c, 0x24, 0x00, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x00, 0x00,
5762         0xc8, 0xbf, 0xe7, 0xFF, 0x70, 0x92, 0xbe, 0x00, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0x00,
5763         0xa3, 0x49, 0xa4, 0xFF, 0x3f, 0x48, 0xcc, 0x00, 0x00, 0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0x00,
5764
5765         0xa3, 0x49, 0xa4, 0xFF, 0xc8, 0xbf, 0xe7, 0x00, 0x88, 0x00, 0x15, 0xff, 0x00, 0x00, 0x00, 0x00,
5766         0x3f, 0x48, 0xcc, 0xFF, 0x70, 0x92, 0xbe, 0x00, 0xed, 0x1c, 0x24, 0xff, 0x7f, 0x7f, 0x7f, 0x00,
5767         0x00, 0xa2, 0xe8, 0xFF, 0x99, 0xd9, 0xea, 0x00, 0xff, 0x7f, 0x27, 0xff, 0xc3, 0xc3, 0xc3, 0x00,
5768         0x22, 0xb1, 0x4c, 0xFF, 0xb5, 0xe6, 0x1d, 0x00, 0xff, 0xf2, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00,
5769
5770         0x22, 0xb1, 0x4c, 0xFF, 0x00, 0xa2, 0xe8, 0x00, 0x3f, 0x48, 0xcc, 0xff, 0xa3, 0x49, 0xa4, 0x00,
5771         0xb5, 0xe6, 0x1d, 0xFF, 0x99, 0xd9, 0xea, 0x00, 0x70, 0x92, 0xbe, 0xff, 0xc8, 0xbf, 0xe7, 0x00,
5772         0xff, 0xf2, 0x00, 0xFF, 0xff, 0x7f, 0x27, 0x00, 0xed, 0x1c, 0x24, 0xff, 0x88, 0x00, 0x15, 0x00,
5773         0xff, 0xff, 0xff, 0xFF, 0xc3, 0xc3, 0xc3, 0x00, 0x7f, 0x7f, 0x7f, 0xff, 0x00, 0x00, 0x00, 0x00,
5774
5775         0xff, 0xff, 0xff, 0xFF, 0xff, 0xf2, 0x00, 0x00, 0xb5, 0xe6, 0x1d, 0xff, 0x22, 0xb1, 0x4c, 0x00,
5776         0xc3, 0xc3, 0xc3, 0xFF, 0xff, 0x7f, 0x27, 0x00, 0x99, 0xd9, 0xea, 0xff, 0x00, 0xa2, 0xe8, 0x00,
5777         0x7f, 0x7f, 0x7f, 0xFF, 0xed, 0x1c, 0x24, 0x00, 0x70, 0x92, 0xbe, 0xff, 0x3f, 0x48, 0xcc, 0x00,
5778         0x00, 0x00, 0x00, 0xFF, 0x88, 0x00, 0x15, 0x00, 0xc8, 0xbf, 0xe7, 0xff, 0xa3, 0x49, 0xa4, 0x00
5779 };
5780
5781 /** Reference data parameters. */
5782 const glw::GLuint CopyTest::s_texture_width  = 4;
5783 const glw::GLuint CopyTest::s_texture_height = 4;
5784 const glw::GLuint CopyTest::s_texture_depth  = 4;
5785
5786 /******************************** Get Set Parameter Test Implementation   ********************************/
5787
5788 /** @brief Get Set Parameter Test constructor.
5789  *
5790  *  @param [in] context     OpenGL context.
5791  */
5792 GetSetParameterTest::GetSetParameterTest(deqp::Context& context)
5793         : deqp::TestCase(context, "textures_get_set_parameter", "Texture Get Set Parameter Test")
5794 {
5795         /* Intentionally left blank. */
5796 }
5797
5798 /** @brief Iterate Get Set Parameter Test cases.
5799  *
5800  *  @return Iteration result.
5801  */
5802 tcu::TestNode::IterateResult GetSetParameterTest::iterate()
5803 {
5804         /* Shortcut for GL functionality. */
5805         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5806
5807         /* Get context setup. */
5808         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
5809         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
5810
5811         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
5812         {
5813                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
5814
5815                 return STOP;
5816         }
5817
5818         /* Running tests. */
5819         bool is_ok      = true;
5820         bool is_error = false;
5821
5822         /* Texture. */
5823         glw::GLuint texture = 0;
5824
5825         try
5826         {
5827                 gl.genTextures(1, &texture);
5828                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
5829
5830                 gl.bindTexture(GL_TEXTURE_3D, texture);
5831                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
5832
5833                 {
5834                         glw::GLenum name          = GL_DEPTH_STENCIL_TEXTURE_MODE;
5835                         glw::GLint  value_src = GL_DEPTH_COMPONENT;
5836                         glw::GLint  value_dst = 0;
5837
5838                         gl.textureParameteri(texture, name, value_src);
5839                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5840
5841                         gl.getTextureParameteriv(texture, name, &value_dst);
5842                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5843
5844                         is_ok &= CompareAndLog(value_src, value_dst, name);
5845                 }
5846
5847                 {
5848                         glw::GLenum name          = GL_TEXTURE_BASE_LEVEL;
5849                         glw::GLint  value_src = 2;
5850                         glw::GLint  value_dst = 0;
5851
5852                         gl.textureParameteri(texture, name, value_src);
5853                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5854
5855                         gl.getTextureParameteriv(texture, name, &value_dst);
5856                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5857
5858                         is_ok &= CompareAndLog(value_src, value_dst, name);
5859                 }
5860
5861                 {
5862                         glw::GLenum  name                 = GL_TEXTURE_BORDER_COLOR;
5863                         glw::GLfloat value_src[4] = { 0.25, 0.5, 0.75, 1.0 };
5864                         glw::GLfloat value_dst[4] = {};
5865
5866                         gl.textureParameterfv(texture, name, value_src);
5867                         is_ok &= CheckErrorAndLog("glTextureParameterfv", name);
5868
5869                         gl.getTextureParameterfv(texture, name, value_dst);
5870                         is_ok &= CheckErrorAndLog("glGetTextureParameterfv", name);
5871
5872                         is_ok &= CompareAndLog(value_src, value_dst, name);
5873                 }
5874
5875                 {
5876                         glw::GLenum name                 = GL_TEXTURE_BORDER_COLOR;
5877                         glw::GLint  value_src[4] = { 0, 64, -64, -32 };
5878                         glw::GLint  value_dst[4] = {};
5879
5880                         gl.textureParameterIiv(texture, name, value_src);
5881                         is_ok &= CheckErrorAndLog("glTextureParameterIiv", name);
5882
5883                         gl.getTextureParameterIiv(texture, name, value_dst);
5884                         is_ok &= CheckErrorAndLog("glGetTextureParameterIiv", name);
5885
5886                         is_ok &= CompareAndLog(value_src, value_dst, name);
5887                 }
5888
5889                 {
5890                         glw::GLenum name                 = GL_TEXTURE_BORDER_COLOR;
5891                         glw::GLuint value_src[4] = { 0, 64, 128, 192 };
5892                         glw::GLuint value_dst[4] = {};
5893
5894                         gl.textureParameterIuiv(texture, name, value_src);
5895                         is_ok &= CheckErrorAndLog("glTextureParameterIuiv", name);
5896
5897                         gl.getTextureParameterIuiv(texture, name, value_dst);
5898                         is_ok &= CheckErrorAndLog("glGetTextureParameterIuiv", name);
5899
5900                         is_ok &= CompareAndLog(value_src, value_dst, name);
5901                 }
5902
5903                 {
5904                         glw::GLenum name          = GL_TEXTURE_COMPARE_FUNC;
5905                         glw::GLint  value_src = GL_LEQUAL;
5906                         glw::GLint  value_dst = 0;
5907
5908                         gl.textureParameteri(texture, name, value_src);
5909                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5910
5911                         gl.getTextureParameteriv(texture, name, &value_dst);
5912                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5913
5914                         is_ok &= CompareAndLog(value_src, value_dst, name);
5915                 }
5916
5917                 {
5918                         glw::GLenum name          = GL_TEXTURE_COMPARE_MODE;
5919                         glw::GLint  value_src = GL_COMPARE_REF_TO_TEXTURE;
5920                         glw::GLint  value_dst = 0;
5921
5922                         gl.textureParameteri(texture, name, value_src);
5923                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5924
5925                         gl.getTextureParameteriv(texture, name, &value_dst);
5926                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5927
5928                         is_ok &= CompareAndLog(value_src, value_dst, name);
5929                 }
5930
5931                 {
5932                         glw::GLenum  name         = GL_TEXTURE_LOD_BIAS;
5933                         glw::GLfloat value_src = -2.f;
5934                         glw::GLfloat value_dst = 0.f;
5935
5936                         gl.textureParameterf(texture, name, value_src);
5937                         is_ok &= CheckErrorAndLog("glTextureParameterf", name);
5938
5939                         gl.getTextureParameterfv(texture, name, &value_dst);
5940                         is_ok &= CheckErrorAndLog("glGetTextureParameterfv", name);
5941
5942                         is_ok &= CompareAndLog(value_src, value_dst, name);
5943                 }
5944
5945                 {
5946                         glw::GLenum name          = GL_TEXTURE_MIN_FILTER;
5947                         glw::GLint  value_src = GL_LINEAR_MIPMAP_NEAREST;
5948                         glw::GLint  value_dst = 0;
5949
5950                         gl.textureParameteri(texture, name, value_src);
5951                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5952
5953                         gl.getTextureParameteriv(texture, name, &value_dst);
5954                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5955
5956                         is_ok &= CompareAndLog(value_src, value_dst, name);
5957                 }
5958
5959                 {
5960                         glw::GLenum name          = GL_TEXTURE_MAG_FILTER;
5961                         glw::GLint  value_src = GL_NEAREST;
5962                         glw::GLint  value_dst = 0;
5963
5964                         gl.textureParameteri(texture, name, value_src);
5965                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5966
5967                         gl.getTextureParameteriv(texture, name, &value_dst);
5968                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5969
5970                         is_ok &= CompareAndLog(value_src, value_dst, name);
5971                 }
5972
5973                 {
5974                         glw::GLenum name          = GL_TEXTURE_MIN_LOD;
5975                         glw::GLint  value_src = -100;
5976                         glw::GLint  value_dst = 0;
5977
5978                         gl.textureParameteri(texture, name, value_src);
5979                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5980
5981                         gl.getTextureParameteriv(texture, name, &value_dst);
5982                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5983
5984                         is_ok &= CompareAndLog(value_src, value_dst, name);
5985                 }
5986
5987                 {
5988                         glw::GLenum name          = GL_TEXTURE_MAX_LOD;
5989                         glw::GLint  value_src = 100;
5990                         glw::GLint  value_dst = 0;
5991
5992                         gl.textureParameteri(texture, name, value_src);
5993                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5994
5995                         gl.getTextureParameteriv(texture, name, &value_dst);
5996                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5997
5998                         is_ok &= CompareAndLog(value_src, value_dst, name);
5999                 }
6000
6001                 {
6002                         glw::GLenum name          = GL_TEXTURE_MAX_LEVEL;
6003                         glw::GLint  value_src = 100;
6004                         glw::GLint  value_dst = 0;
6005
6006                         gl.textureParameteri(texture, name, value_src);
6007                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
6008
6009                         gl.getTextureParameteriv(texture, name, &value_dst);
6010                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6011
6012                         is_ok &= CompareAndLog(value_src, value_dst, name);
6013                 }
6014
6015                 {
6016                         glw::GLenum name          = GL_TEXTURE_SWIZZLE_R;
6017                         glw::GLint  value_src = GL_BLUE;
6018                         glw::GLint  value_dst = 0;
6019
6020                         gl.textureParameteri(texture, name, value_src);
6021                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
6022
6023                         gl.getTextureParameteriv(texture, name, &value_dst);
6024                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6025
6026                         is_ok &= CompareAndLog(value_src, value_dst, name);
6027                 }
6028
6029                 {
6030                         glw::GLenum name          = GL_TEXTURE_SWIZZLE_G;
6031                         glw::GLint  value_src = GL_ALPHA;
6032                         glw::GLint  value_dst = 0;
6033
6034                         gl.textureParameteri(texture, name, value_src);
6035                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
6036
6037                         gl.getTextureParameteriv(texture, name, &value_dst);
6038                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6039
6040                         is_ok &= CompareAndLog(value_src, value_dst, name);
6041                 }
6042
6043                 {
6044                         glw::GLenum name          = GL_TEXTURE_SWIZZLE_B;
6045                         glw::GLint  value_src = GL_RED;
6046                         glw::GLint  value_dst = 0;
6047
6048                         gl.textureParameteri(texture, name, value_src);
6049                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
6050
6051                         gl.getTextureParameteriv(texture, name, &value_dst);
6052                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6053
6054                         is_ok &= CompareAndLog(value_src, value_dst, name);
6055                 }
6056
6057                 {
6058                         glw::GLenum name          = GL_TEXTURE_SWIZZLE_A;
6059                         glw::GLint  value_src = GL_GREEN;
6060                         glw::GLint  value_dst = 0;
6061
6062                         gl.textureParameteri(texture, name, value_src);
6063                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
6064
6065                         gl.getTextureParameteriv(texture, name, &value_dst);
6066                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6067
6068                         is_ok &= CompareAndLog(value_src, value_dst, name);
6069                 }
6070
6071                 {
6072                         glw::GLenum name                 = GL_TEXTURE_SWIZZLE_RGBA;
6073                         glw::GLint  value_src[4] = { GL_ZERO, GL_ONE, GL_ZERO, GL_ONE };
6074                         glw::GLint  value_dst[4] = {};
6075
6076                         gl.textureParameteriv(texture, name, value_src);
6077                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
6078
6079                         gl.getTextureParameteriv(texture, name, value_dst);
6080                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6081
6082                         is_ok &= CompareAndLog(value_src, value_dst, name);
6083                 }
6084
6085                 {
6086                         glw::GLenum name          = GL_TEXTURE_WRAP_S;
6087                         glw::GLint  value_src = GL_MIRROR_CLAMP_TO_EDGE;
6088                         glw::GLint  value_dst = 11;
6089
6090                         gl.textureParameteri(texture, name, value_src);
6091                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
6092
6093                         gl.getTextureParameteriv(texture, name, &value_dst);
6094                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6095
6096                         is_ok &= CompareAndLog(value_src, value_dst, name);
6097                 }
6098
6099                 {
6100                         glw::GLenum name          = GL_TEXTURE_WRAP_T;
6101                         glw::GLint  value_src = GL_CLAMP_TO_EDGE;
6102                         glw::GLint  value_dst = 11;
6103
6104                         gl.textureParameteri(texture, name, value_src);
6105                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
6106
6107                         gl.getTextureParameteriv(texture, name, &value_dst);
6108                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6109
6110                         is_ok &= CompareAndLog(value_src, value_dst, name);
6111                 }
6112
6113                 {
6114                         glw::GLenum name          = GL_TEXTURE_WRAP_R;
6115                         glw::GLint  value_src = GL_CLAMP_TO_EDGE;
6116                         glw::GLint  value_dst = 11;
6117
6118                         gl.textureParameteriv(texture, name, &value_src);
6119                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
6120
6121                         gl.getTextureParameteriv(texture, name, &value_dst);
6122                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6123
6124                         is_ok &= CompareAndLog(value_src, value_dst, name);
6125                 }
6126         }
6127         catch (...)
6128         {
6129                 is_ok   = false;
6130                 is_error = true;
6131         }
6132
6133         /* Cleanup. */
6134         if (texture)
6135         {
6136                 gl.deleteTextures(1, &texture);
6137         }
6138
6139         while (GL_NO_ERROR != gl.getError())
6140                 ;
6141
6142         /* Result's setup. */
6143         if (is_ok)
6144         {
6145                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
6146         }
6147         else
6148         {
6149                 if (is_error)
6150                 {
6151                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
6152                 }
6153                 else
6154                 {
6155                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
6156                 }
6157         }
6158
6159         return STOP;
6160 }
6161
6162 /** @brief Check for errors and log.
6163  *
6164  *  @param [in] fname     Name of the function (to be logged).
6165  *  @param [in] pname     Parameter name with which function was called.
6166  *
6167  *  @return True if no error, false otherwise.
6168  */
6169 bool GetSetParameterTest::CheckErrorAndLog(const glw::GLchar* fname, glw::GLenum pname)
6170 {
6171         /* Shortcut for GL functionality. */
6172         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
6173
6174         /* Check errors. */
6175         glw::GLenum error;
6176
6177         if (GL_NO_ERROR != (error = gl.getError()))
6178         {
6179                 m_context.getTestContext().getLog() << tcu::TestLog::Message << fname << " unexpectedly generated error "
6180                                                                                         << glu::getErrorStr(error) << " during test of pname "
6181                                                                                         << glu::getTextureParameterStr(pname) << ". Test fails."
6182                                                                                         << tcu::TestLog::EndMessage;
6183
6184                 return false;
6185         }
6186
6187         return true;
6188 }
6189
6190 /** @brief Compare queried value of parameter with the expected vale.
6191  *
6192  *  @param [in] value_src           First value.
6193  *  @param [in] value_dst           Second value.
6194  *  @param [in] pname               Parameter name.
6195  *
6196  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6197  */
6198 bool GetSetParameterTest::CompareAndLog(glw::GLint value_src, glw::GLint value_dst, glw::GLenum pname)
6199 {
6200         if (value_src != value_dst)
6201         {
6202                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Queried value of pname "
6203                                                                                         << glu::getTextureParameterStr(pname) << " is equal to " << value_dst
6204                                                                                         << ", however " << value_src << " was expected. Test fails."
6205                                                                                         << tcu::TestLog::EndMessage;
6206
6207                 return false;
6208         }
6209
6210         return true;
6211 }
6212
6213 /** @brief Compare queried value of parameter with the expected vale.
6214  *
6215  *  @param [in] value_src           First value.
6216  *  @param [in] value_dst           Second value.
6217  *  @param [in] pname               Parameter name.
6218  *
6219  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6220  */
6221 bool GetSetParameterTest::CompareAndLog(glw::GLuint value_src, glw::GLuint value_dst, glw::GLenum pname)
6222 {
6223         if (value_src != value_dst)
6224         {
6225                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Queried value of pname "
6226                                                                                         << glu::getTextureParameterStr(pname) << " is equal to " << value_dst
6227                                                                                         << ", however " << value_src << " was expected. Test fails."
6228                                                                                         << tcu::TestLog::EndMessage;
6229
6230                 return false;
6231         }
6232
6233         return true;
6234 }
6235
6236 /** @brief Compare queried value of parameter with the expected vale.
6237  *
6238  *  @param [in] value_src           First value.
6239  *  @param [in] value_dst           Second value.
6240  *  @param [in] pname               Parameter name.
6241  *
6242  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6243  */
6244 bool GetSetParameterTest::CompareAndLog(glw::GLfloat value_src, glw::GLfloat value_dst, glw::GLenum pname)
6245 {
6246         if (de::abs(value_src - value_dst) > 0.0125 /* Precision */)
6247         {
6248                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Queried value of pname "
6249                                                                                         << glu::getTextureParameterStr(pname) << " is equal to " << value_dst
6250                                                                                         << ", however " << value_src << " was expected. Test fails."
6251                                                                                         << tcu::TestLog::EndMessage;
6252
6253                 return false;
6254         }
6255
6256         return true;
6257 }
6258
6259 /** @brief Compare queried value of parameter with the expected vale.
6260  *
6261  *  @param [in] value_src           First value.
6262  *  @param [in] value_dst           Second value.
6263  *  @param [in] pname               Parameter name.
6264  *
6265  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6266  */
6267 bool GetSetParameterTest::CompareAndLog(glw::GLint value_src[4], glw::GLint value_dst[4], glw::GLenum pname)
6268 {
6269         if ((value_src[0] != value_dst[0]) || (value_src[1] != value_dst[1]) || (value_src[2] != value_dst[2]) ||
6270                 (value_src[3] != value_dst[3]))
6271         {
6272                 m_context.getTestContext().getLog()
6273                         << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6274                         << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3]
6275                         << "], however " << value_src[0] << ", " << value_src[1] << ", " << value_src[2] << ", " << value_src[3]
6276                         << "] was expected. Test fails." << tcu::TestLog::EndMessage;
6277
6278                 return false;
6279         }
6280
6281         return true;
6282 }
6283
6284 /** @brief Compare queried value of parameter with the expected vale.
6285  *
6286  *  @param [in] value_src           First value.
6287  *  @param [in] value_dst           Second value.
6288  *  @param [in] pname               Parameter name.
6289  *
6290  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6291  */
6292 bool GetSetParameterTest::CompareAndLog(glw::GLuint value_src[4], glw::GLuint value_dst[4], glw::GLenum pname)
6293 {
6294         if ((value_src[0] != value_dst[0]) || (value_src[1] != value_dst[1]) || (value_src[2] != value_dst[2]) ||
6295                 (value_src[3] != value_dst[3]))
6296         {
6297                 m_context.getTestContext().getLog()
6298                         << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6299                         << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3]
6300                         << "], however " << value_src[0] << ", " << value_src[1] << ", " << value_src[2] << ", " << value_src[3]
6301                         << "] was expected. Test fails." << tcu::TestLog::EndMessage;
6302
6303                 return false;
6304         }
6305
6306         return true;
6307 }
6308
6309 /** @brief Compare queried value of parameter with the expected vale.
6310  *
6311  *  @param [in] value_src           First value.
6312  *  @param [in] value_dst           Second value.
6313  *  @param [in] pname               Parameter name.
6314  *
6315  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6316  */
6317 bool GetSetParameterTest::CompareAndLog(glw::GLfloat value_src[4], glw::GLfloat value_dst[4], glw::GLenum pname)
6318 {
6319         if ((de::abs(value_src[0] - value_dst[0]) > 0.0125 /* Precision */) ||
6320                 (de::abs(value_src[1] - value_dst[1]) > 0.0125 /* Precision */) ||
6321                 (de::abs(value_src[2] - value_dst[2]) > 0.0125 /* Precision */) ||
6322                 (de::abs(value_src[3] - value_dst[3]) > 0.0125 /* Precision */))
6323         {
6324                 m_context.getTestContext().getLog()
6325                         << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6326                         << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3]
6327                         << "], however " << value_src[0] << ", " << value_src[1] << ", " << value_src[2] << ", " << value_src[3]
6328                         << "] was expected. Test fails." << tcu::TestLog::EndMessage;
6329
6330                 return false;
6331         }
6332
6333         return true;
6334 }
6335
6336 /******************************** Defaults Test Implementation   ********************************/
6337
6338 /** @brief Defaults Test constructor.
6339  *
6340  *  @param [in] context     OpenGL context.
6341  */
6342 DefaultsTest::DefaultsTest(deqp::Context& context)
6343         : deqp::TestCase(context, "textures_defaults", "Texture Defaults Test")
6344 {
6345         /* Intentionally left blank. */
6346 }
6347
6348 /** @brief Defaults Test cases.
6349  *
6350  *  @return Iteration result.
6351  */
6352 tcu::TestNode::IterateResult DefaultsTest::iterate()
6353 {
6354         /* Shortcut for GL functionality. */
6355         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
6356
6357         /* Get context setup. */
6358         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
6359         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
6360
6361         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
6362         {
6363                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
6364
6365                 return STOP;
6366         }
6367
6368         /* Running tests. */
6369         bool is_ok      = true;
6370         bool is_error = false;
6371
6372         /* Texture. */
6373         glw::GLuint texture = 0;
6374
6375         try
6376         {
6377                 gl.createTextures(GL_TEXTURE_3D, 1, &texture);
6378                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
6379
6380                 {
6381                         glw::GLenum name          = GL_DEPTH_STENCIL_TEXTURE_MODE;
6382                         glw::GLint  value_ref = GL_DEPTH_COMPONENT;
6383                         glw::GLint  value_dst = 0;
6384
6385                         gl.getTextureParameteriv(texture, name, &value_dst);
6386                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6387
6388                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6389                 }
6390
6391                 {
6392                         glw::GLenum name          = GL_TEXTURE_BASE_LEVEL;
6393                         glw::GLint  value_ref = 0;
6394                         glw::GLint  value_dst = 1;
6395
6396                         gl.getTextureParameteriv(texture, name, &value_dst);
6397                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6398
6399                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6400                 }
6401
6402                 {
6403                         glw::GLenum  name                 = GL_TEXTURE_BORDER_COLOR;
6404                         glw::GLfloat value_ref[4] = { 0.f, 0.f, 0.f, 0.f };
6405                         glw::GLfloat value_dst[4] = {};
6406
6407                         gl.getTextureParameterfv(texture, name, value_dst);
6408                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6409
6410                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6411                 }
6412
6413                 {
6414                         glw::GLenum name          = GL_TEXTURE_COMPARE_FUNC;
6415                         glw::GLint  value_ref = GL_LEQUAL;
6416                         glw::GLint  value_dst = 0;
6417
6418                         gl.getTextureParameteriv(texture, name, &value_dst);
6419                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6420
6421                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6422                 }
6423
6424                 {
6425                         glw::GLenum name          = GL_TEXTURE_COMPARE_MODE;
6426                         glw::GLint  value_ref = GL_NONE;
6427                         glw::GLint  value_dst = 0;
6428
6429                         gl.getTextureParameteriv(texture, name, &value_dst);
6430                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6431
6432                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6433                 }
6434
6435                 {
6436                         glw::GLenum  name         = GL_TEXTURE_LOD_BIAS;
6437                         glw::GLfloat value_ref = 0.f;
6438                         glw::GLfloat value_dst = 0.f;
6439
6440                         gl.getTextureParameterfv(texture, name, &value_dst);
6441                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6442
6443                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6444                 }
6445
6446                 {
6447                         glw::GLenum name          = GL_TEXTURE_MIN_FILTER;
6448                         glw::GLint  value_ref = GL_NEAREST_MIPMAP_LINEAR;
6449                         glw::GLint  value_dst = 0;
6450
6451                         gl.getTextureParameteriv(texture, name, &value_dst);
6452                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6453
6454                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6455                 }
6456
6457                 {
6458                         glw::GLenum name          = GL_TEXTURE_MAG_FILTER;
6459                         glw::GLint  value_ref = GL_LINEAR;
6460                         glw::GLint  value_dst = 0;
6461
6462                         gl.getTextureParameteriv(texture, name, &value_dst);
6463                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6464
6465                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6466                 }
6467
6468                 {
6469                         glw::GLenum name          = GL_TEXTURE_MIN_LOD;
6470                         glw::GLint  value_ref = -1000;
6471                         glw::GLint  value_dst = 0;
6472
6473                         gl.getTextureParameteriv(texture, name, &value_dst);
6474                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6475
6476                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6477                 }
6478
6479                 {
6480                         glw::GLenum name          = GL_TEXTURE_MAX_LOD;
6481                         glw::GLint  value_ref = 1000;
6482                         glw::GLint  value_dst = 0;
6483
6484                         gl.getTextureParameteriv(texture, name, &value_dst);
6485                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6486
6487                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6488                 }
6489
6490                 {
6491                         glw::GLenum name          = GL_TEXTURE_MAX_LEVEL;
6492                         glw::GLint  value_ref = 1000;
6493                         glw::GLint  value_dst = 0;
6494
6495                         gl.getTextureParameteriv(texture, name, &value_dst);
6496                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6497
6498                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6499                 }
6500
6501                 {
6502                         glw::GLenum name          = GL_TEXTURE_SWIZZLE_R;
6503                         glw::GLint  value_ref = GL_RED;
6504                         glw::GLint  value_dst = 0;
6505
6506                         gl.getTextureParameteriv(texture, name, &value_dst);
6507                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6508
6509                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6510                 }
6511
6512                 {
6513                         glw::GLenum name          = GL_TEXTURE_SWIZZLE_G;
6514                         glw::GLint  value_ref = GL_GREEN;
6515                         glw::GLint  value_dst = 0;
6516
6517                         gl.getTextureParameteriv(texture, name, &value_dst);
6518                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6519
6520                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6521                 }
6522
6523                 {
6524                         glw::GLenum name          = GL_TEXTURE_SWIZZLE_B;
6525                         glw::GLint  value_ref = GL_BLUE;
6526                         glw::GLint  value_dst = 0;
6527
6528                         gl.getTextureParameteriv(texture, name, &value_dst);
6529                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6530
6531                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6532                 }
6533
6534                 {
6535                         glw::GLenum name          = GL_TEXTURE_SWIZZLE_A;
6536                         glw::GLint  value_ref = GL_ALPHA;
6537                         glw::GLint  value_dst = 0;
6538
6539                         gl.getTextureParameteriv(texture, name, &value_dst);
6540                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6541
6542                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6543                 }
6544
6545                 {
6546                         glw::GLenum name          = GL_TEXTURE_WRAP_S;
6547                         glw::GLint  value_ref = GL_REPEAT;
6548                         glw::GLint  value_dst = 11;
6549
6550                         gl.getTextureParameteriv(texture, name, &value_dst);
6551                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6552
6553                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6554                 }
6555
6556                 {
6557                         glw::GLenum name          = GL_TEXTURE_WRAP_T;
6558                         glw::GLint  value_ref = GL_REPEAT;
6559                         glw::GLint  value_dst = 11;
6560
6561                         gl.getTextureParameteriv(texture, name, &value_dst);
6562                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6563
6564                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6565                 }
6566
6567                 {
6568                         glw::GLenum name          = GL_TEXTURE_WRAP_R;
6569                         glw::GLint  value_ref = GL_REPEAT;
6570                         glw::GLint  value_dst = 11;
6571
6572                         gl.getTextureParameteriv(texture, name, &value_dst);
6573                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6574
6575                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6576                 }
6577         }
6578         catch (...)
6579         {
6580                 is_ok   = false;
6581                 is_error = true;
6582         }
6583
6584         /* Cleanup. */
6585         if (texture)
6586         {
6587                 gl.deleteTextures(1, &texture);
6588         }
6589
6590         while (GL_NO_ERROR != gl.getError())
6591                 ;
6592
6593         /* Result's setup. */
6594         if (is_ok)
6595         {
6596                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
6597         }
6598         else
6599         {
6600                 if (is_error)
6601                 {
6602                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
6603                 }
6604                 else
6605                 {
6606                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
6607                 }
6608         }
6609
6610         return STOP;
6611 }
6612
6613 /** @brief Compare queried value of parameter with the expected vale.
6614  *
6615  *  @param [in] value_src           First value.
6616  *  @param [in] value_dst           Second value.
6617  *  @param [in] pname               Parameter name.
6618  *
6619  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6620  */
6621 bool DefaultsTest::CompareAndLog(glw::GLint value_ref, glw::GLint value_dst, glw::GLenum pname)
6622 {
6623         if (value_ref != value_dst)
6624         {
6625                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Queried value of pname "
6626                                                                                         << glu::getTextureParameterStr(pname) << " is equal to " << value_dst
6627                                                                                         << ", however " << value_ref << " was expected. Test fails."
6628                                                                                         << tcu::TestLog::EndMessage;
6629
6630                 return false;
6631         }
6632
6633         return true;
6634 }
6635
6636 /** @brief Compare queried value of parameter with the expected vale.
6637  *
6638  *  @param [in] value_src           First value.
6639  *  @param [in] value_dst           Second value.
6640  *  @param [in] pname               Parameter name.
6641  *
6642  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6643  */
6644 bool DefaultsTest::CompareAndLog(glw::GLuint value_ref, glw::GLuint value_dst, glw::GLenum pname)
6645 {
6646         if (value_ref != value_dst)
6647         {
6648                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Queried value of pname "
6649                                                                                         << glu::getTextureParameterStr(pname) << " is equal to " << value_dst
6650                                                                                         << ", however " << value_ref << " was expected. Test fails."
6651                                                                                         << tcu::TestLog::EndMessage;
6652
6653                 return false;
6654         }
6655
6656         return true;
6657 }
6658
6659 /** @brief Compare queried value of parameter with the expected vale.
6660  *
6661  *  @param [in] value_src           First value.
6662  *  @param [in] value_dst           Second value.
6663  *  @param [in] pname               Parameter name.
6664  *
6665  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6666  */
6667 bool DefaultsTest::CompareAndLog(glw::GLfloat value_ref, glw::GLfloat value_dst, glw::GLenum pname)
6668 {
6669         if (de::abs(value_ref - value_dst) > 0.0125 /* Precision */)
6670         {
6671                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Queried value of pname "
6672                                                                                         << glu::getTextureParameterStr(pname) << " is equal to " << value_dst
6673                                                                                         << ", however " << value_ref << " was expected. Test fails."
6674                                                                                         << tcu::TestLog::EndMessage;
6675
6676                 return false;
6677         }
6678
6679         return true;
6680 }
6681
6682 /** @brief Compare queried value of parameter with the expected vale.
6683  *
6684  *  @param [in] value_src           First value.
6685  *  @param [in] value_dst           Second value.
6686  *  @param [in] pname               Parameter name.
6687  *
6688  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6689  */
6690 bool DefaultsTest::CompareAndLog(glw::GLint value_ref[4], glw::GLint value_dst[4], glw::GLenum pname)
6691 {
6692         if ((value_ref[0] != value_dst[0]) || (value_ref[1] != value_dst[1]) || (value_ref[2] != value_dst[2]) ||
6693                 (value_ref[3] != value_dst[3]))
6694         {
6695                 m_context.getTestContext().getLog()
6696                         << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6697                         << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3]
6698                         << "], however " << value_ref[0] << ", " << value_ref[1] << ", " << value_ref[2] << ", " << value_ref[3]
6699                         << "] was expected. Test fails." << tcu::TestLog::EndMessage;
6700
6701                 return false;
6702         }
6703
6704         return true;
6705 }
6706
6707 /** @brief Compare queried value of parameter with the expected vale.
6708  *
6709  *  @param [in] value_src           First value.
6710  *  @param [in] value_dst           Second value.
6711  *  @param [in] pname               Parameter name.
6712  *
6713  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6714  */
6715 bool DefaultsTest::CompareAndLog(glw::GLuint value_ref[4], glw::GLuint value_dst[4], glw::GLenum pname)
6716 {
6717         if ((value_ref[0] != value_dst[0]) || (value_ref[1] != value_dst[1]) || (value_ref[2] != value_dst[2]) ||
6718                 (value_ref[3] != value_dst[3]))
6719         {
6720                 m_context.getTestContext().getLog()
6721                         << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6722                         << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3]
6723                         << "], however " << value_ref[0] << ", " << value_ref[1] << ", " << value_ref[2] << ", " << value_ref[3]
6724                         << "] was expected. Test fails." << tcu::TestLog::EndMessage;
6725
6726                 return false;
6727         }
6728
6729         return true;
6730 }
6731
6732 /** @brief Compare queried value of parameter with the expected vale.
6733  *
6734  *  @param [in] value_src           First value.
6735  *  @param [in] value_dst           Second value.
6736  *  @param [in] pname               Parameter name.
6737  *
6738  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6739  */
6740 bool DefaultsTest::CompareAndLog(glw::GLfloat value_ref[4], glw::GLfloat value_dst[4], glw::GLenum pname)
6741 {
6742         if ((de::abs(value_ref[0] - value_dst[0]) > 0.0125 /* Precision */) ||
6743                 (de::abs(value_ref[1] - value_dst[1]) > 0.0125 /* Precision */) ||
6744                 (de::abs(value_ref[2] - value_dst[2]) > 0.0125 /* Precision */) ||
6745                 (de::abs(value_ref[3] - value_dst[3]) > 0.0125 /* Precision */))
6746         {
6747                 m_context.getTestContext().getLog()
6748                         << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6749                         << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3]
6750                         << "], however " << value_ref[0] << ", " << value_ref[1] << ", " << value_ref[2] << ", " << value_ref[3]
6751                         << "] was expected. Test fails." << tcu::TestLog::EndMessage;
6752
6753                 return false;
6754         }
6755
6756         return true;
6757 }
6758
6759 /******************************** Generate Mipmap Test Implementation   ********************************/
6760
6761 /** @brief Generate Mipmap Test constructor.
6762  *
6763  *  @param [in] context     OpenGL context.
6764  */
6765 GenerateMipmapTest::GenerateMipmapTest(deqp::Context& context)
6766         : deqp::TestCase(context, "textures_generate_mipmaps", "Textures Generate Mipmap Test")
6767 {
6768         /* Intentionally left blank. */
6769 }
6770
6771 /** @brief Generate Mipmap Test cases.
6772  *
6773  *  @return Iteration result.
6774  */
6775 tcu::TestNode::IterateResult GenerateMipmapTest::iterate()
6776 {
6777         /* Shortcut for GL functionality. */
6778         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
6779
6780         /* Get context setup. */
6781         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
6782         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
6783
6784         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
6785         {
6786                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
6787
6788                 return STOP;
6789         }
6790
6791         /* Running tests. */
6792         bool is_ok      = true;
6793         bool is_error = false;
6794
6795         /* Texture and cpu results storage. */
6796         glw::GLuint   texture = 0;
6797         glw::GLubyte* result  = DE_NULL;
6798
6799         try
6800         {
6801                 /* Prepare texture. */
6802                 gl.genTextures(1, &texture);
6803                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
6804
6805                 gl.bindTexture(GL_TEXTURE_1D, texture);
6806                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
6807
6808                 gl.texImage1D(GL_TEXTURE_1D, 0, GL_R8, s_texture_width, 0, GL_RED, GL_UNSIGNED_BYTE, s_texture_data);
6809                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
6810
6811                 /* Generate mipmaps with tested function. */
6812                 gl.generateTextureMipmap(texture);
6813
6814                 glw::GLenum error = GL_NO_ERROR;
6815
6816                 if (GL_NO_ERROR != (error = gl.getError()))
6817                 {
6818                         m_context.getTestContext().getLog()
6819                                 << tcu::TestLog::Message << "GenerateTextureMipmap unexpectedly generated error "
6820                                 << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
6821
6822                         is_ok = false;
6823                 }
6824
6825                 /* Continue only if mipmaps has been generated. */
6826                 if (is_ok)
6827                 {
6828                         result = new glw::GLubyte[s_texture_width];
6829
6830                         if (DE_NULL == result)
6831                         {
6832                                 throw 0;
6833                         }
6834
6835                         /* For each mipmap. */
6836                         for (glw::GLuint i = 0, j = s_texture_width;
6837                                  i < s_texture_width_log - 1 /* Do not test single pixel mipmap. */; ++i, j /= 2)
6838                         {
6839                                 /* Check mipmap size. */
6840                                 glw::GLint mipmap_size = 0;
6841
6842                                 gl.getTexLevelParameteriv(GL_TEXTURE_1D, i, GL_TEXTURE_WIDTH, &mipmap_size);
6843                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
6844
6845                                 if (mipmap_size != (glw::GLint)j)
6846                                 {
6847                                         m_context.getTestContext().getLog()
6848                                                 << tcu::TestLog::Message
6849                                                 << "GenerateTextureMipmap unexpectedly generated mipmap with improper size. Mipmap size is "
6850                                                 << mipmap_size << ", but " << j << " was expected. Test fails." << tcu::TestLog::EndMessage;
6851
6852                                         is_ok = false;
6853
6854                                         break;
6855                                 }
6856
6857                                 /* Fetch data. */
6858                                 gl.getTexImage(GL_TEXTURE_1D, i, GL_RED, GL_UNSIGNED_BYTE, result);
6859                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexImage has failed");
6860
6861                                 /* Make comparison. */
6862                                 for (glw::GLuint k = 0; k < j - 1; ++k)
6863                                 {
6864                                         if (((glw::GLint)result[k + 1]) - ((glw::GLint)result[k]) < 0)
6865                                         {
6866                                                 m_context.getTestContext().getLog() << tcu::TestLog::Message
6867                                                                                                                         << "GenerateTextureMipmap unexpectedly generated improper "
6868                                                                                                                            "mipmap (not descending). Test fails."
6869                                                                                                                         << tcu::TestLog::EndMessage;
6870
6871                                                 is_ok = false;
6872
6873                                                 break;
6874                                         }
6875                                 }
6876                         }
6877                 }
6878         }
6879         catch (...)
6880         {
6881                 is_ok   = false;
6882                 is_error = true;
6883         }
6884
6885         /* Cleanup. */
6886         if (texture)
6887         {
6888                 gl.deleteTextures(1, &texture);
6889         }
6890
6891         if (DE_NULL != result)
6892         {
6893                 delete[] result;
6894         }
6895
6896         while (GL_NO_ERROR != gl.getError())
6897                 ;
6898
6899         /* Result's setup. */
6900         if (is_ok)
6901         {
6902                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
6903         }
6904         else
6905         {
6906                 if (is_error)
6907                 {
6908                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
6909                 }
6910                 else
6911                 {
6912                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
6913                 }
6914         }
6915
6916         return STOP;
6917 }
6918
6919 /** Reference data. */
6920 const glw::GLubyte GenerateMipmapTest::s_texture_data[] = {
6921         0,   1,   2,   3,   4,   5,   6,   7,   8,   9,   10,  11,  12,  13,  14,  15,  16,  17,  18,  19,  20,  21,
6922         22,  23,  24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,
6923         44,  45,  46,  47,  48,  49,  50,  51,  52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,  63,  64,  65,
6924         66,  67,  68,  69,  70,  71,  72,  73,  74,  75,  76,  77,  78,  79,  80,  81,  82,  83,  84,  85,  86,  87,
6925         88,  89,  90,  91,  92,  93,  94,  95,  96,  97,  98,  99,  100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
6926         110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131,
6927         132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153,
6928         154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
6929         176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197,
6930         198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219,
6931         220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241,
6932         242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
6933 };
6934
6935 /** Reference data parameters. */
6936 const glw::GLuint GenerateMipmapTest::s_texture_width    = 256;
6937 const glw::GLuint GenerateMipmapTest::s_texture_width_log = 8;
6938
6939 /******************************** Bind Unit Test Implementation   ********************************/
6940
6941 /** @brief Bind Unit Test constructor.
6942  *
6943  *  @param [in] context     OpenGL context.
6944  */
6945 BindUnitTest::BindUnitTest(deqp::Context& context)
6946         : deqp::TestCase(context, "textures_bind_unit", "Textures Bind Unit Test")
6947         , m_po(0)
6948         , m_fbo(0)
6949         , m_rbo(0)
6950         , m_vao(0)
6951         , m_result(DE_NULL)
6952 {
6953         m_to[0] = 0;
6954         m_to[1] = 0;
6955         m_to[2] = 0;
6956         m_to[3] = 0;
6957 }
6958
6959 /** @brief Bind Unit Test cases.
6960  *
6961  *  @return Iteration result.
6962  */
6963 tcu::TestNode::IterateResult BindUnitTest::iterate()
6964 {
6965         /* Get context setup. */
6966         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
6967         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
6968
6969         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
6970         {
6971                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
6972
6973                 return STOP;
6974         }
6975
6976         /* Running tests. */
6977         bool is_ok      = true;
6978         bool is_error = false;
6979
6980         try
6981         {
6982                 CreateProgram();
6983                 CreateTextures();
6984                 CreateFrambuffer();
6985                 CreateVertexArray();
6986                 is_ok &= Draw();
6987                 is_ok &= Check();
6988         }
6989         catch (...)
6990         {
6991                 is_ok   = false;
6992                 is_error = true;
6993         }
6994
6995         /* Cleanup. */
6996         CleanAll();
6997
6998         /* Result's setup. */
6999         if (is_ok)
7000         {
7001                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
7002         }
7003         else
7004         {
7005                 if (is_error)
7006                 {
7007                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
7008                 }
7009                 else
7010                 {
7011                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7012                 }
7013         }
7014
7015         return STOP;
7016 }
7017
7018 /** @brief Create test program.
7019  */
7020 void BindUnitTest::CreateProgram()
7021 {
7022         /* Shortcut for GL functionality */
7023         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7024
7025         struct Shader
7026         {
7027                 glw::GLchar const* source;
7028                 glw::GLenum const  type;
7029                 glw::GLuint                id;
7030         } shader[] = { { s_vertex_shader, GL_VERTEX_SHADER, 0 }, { s_fragment_shader, GL_FRAGMENT_SHADER, 0 } };
7031
7032         glw::GLuint const shader_count = sizeof(shader) / sizeof(shader[0]);
7033
7034         try
7035         {
7036                 /* Create program. */
7037                 m_po = gl.createProgram();
7038                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateProgram call failed.");
7039
7040                 /* Shader compilation. */
7041
7042                 for (glw::GLuint i = 0; i < shader_count; ++i)
7043                 {
7044                         if (DE_NULL != shader[i].source)
7045                         {
7046                                 shader[i].id = gl.createShader(shader[i].type);
7047
7048                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateShader call failed.");
7049
7050                                 gl.attachShader(m_po, shader[i].id);
7051
7052                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glAttachShader call failed.");
7053
7054                                 gl.shaderSource(shader[i].id, 1, &shader[i].source, NULL);
7055
7056                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource call failed.");
7057
7058                                 gl.compileShader(shader[i].id);
7059
7060                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader call failed.");
7061
7062                                 glw::GLint status = GL_FALSE;
7063
7064                                 gl.getShaderiv(shader[i].id, GL_COMPILE_STATUS, &status);
7065                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
7066
7067                                 if (GL_FALSE == status)
7068                                 {
7069                                         glw::GLint log_size = 0;
7070                                         gl.getShaderiv(shader[i].id, GL_INFO_LOG_LENGTH, &log_size);
7071                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
7072
7073                                         glw::GLchar* log_text = new glw::GLchar[log_size];
7074
7075                                         gl.getShaderInfoLog(shader[i].id, log_size, NULL, &log_text[0]);
7076
7077                                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "Shader compilation has failed.\n"
7078                                                                                                                 << "Shader type: " << glu::getShaderTypeStr(shader[i].type)
7079                                                                                                                 << "\n"
7080                                                                                                                 << "Shader compilation error log:\n"
7081                                                                                                                 << log_text << "\n"
7082                                                                                                                 << "Shader source code:\n"
7083                                                                                                                 << shader[i].source << "\n"
7084                                                                                                                 << tcu::TestLog::EndMessage;
7085
7086                                         delete[] log_text;
7087
7088                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog call failed.");
7089
7090                                         throw 0;
7091                                 }
7092                         }
7093                 }
7094
7095                 /* Link. */
7096                 gl.linkProgram(m_po);
7097
7098                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTransformFeedbackVaryings call failed.");
7099
7100                 glw::GLint status = GL_FALSE;
7101
7102                 gl.getProgramiv(m_po, GL_LINK_STATUS, &status);
7103
7104                 if (GL_TRUE == status)
7105                 {
7106                         for (glw::GLuint i = 0; i < shader_count; ++i)
7107                         {
7108                                 if (shader[i].id)
7109                                 {
7110                                         gl.detachShader(m_po, shader[i].id);
7111
7112                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glDetachShader call failed.");
7113                                 }
7114                         }
7115                 }
7116                 else
7117                 {
7118                         glw::GLint log_size = 0;
7119
7120                         gl.getProgramiv(m_po, GL_INFO_LOG_LENGTH, &log_size);
7121
7122                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv call failed.");
7123
7124                         glw::GLchar* log_text = new glw::GLchar[log_size];
7125
7126                         gl.getProgramInfoLog(m_po, log_size, NULL, &log_text[0]);
7127
7128                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "Program linkage has failed due to:\n"
7129                                                                                                 << log_text << "\n"
7130                                                                                                 << tcu::TestLog::EndMessage;
7131
7132                         delete[] log_text;
7133
7134                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramInfoLog call failed.");
7135
7136                         throw 0;
7137                 }
7138         }
7139         catch (...)
7140         {
7141                 if (m_po)
7142                 {
7143                         gl.deleteProgram(m_po);
7144
7145                         m_po = 0;
7146                 }
7147         }
7148
7149         for (glw::GLuint i = 0; i < shader_count; ++i)
7150         {
7151                 if (0 != shader[i].id)
7152                 {
7153                         gl.deleteShader(shader[i].id);
7154
7155                         shader[i].id = 0;
7156                 }
7157         }
7158
7159         if (0 == m_po)
7160         {
7161                 throw 0;
7162         }
7163 }
7164
7165 /** @brief Create texture.
7166  */
7167 void BindUnitTest::CreateTextures()
7168 {
7169         /* Shortcut for GL functionality. */
7170         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7171
7172         /* Prepare texture. */
7173         gl.genTextures(4, m_to);
7174         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
7175
7176         /* Setup pixel sotre modes.*/
7177         gl.pixelStorei(GL_UNPACK_ALIGNMENT, sizeof(glw::GLubyte));
7178         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
7179
7180         gl.pixelStorei(GL_PACK_ALIGNMENT, sizeof(glw::GLubyte));
7181         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
7182
7183         /* Red texture. */
7184         gl.bindTexture(GL_TEXTURE_2D, m_to[0]);
7185         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7186
7187         gl.texImage2D(GL_TEXTURE_2D, 0, GL_R8, s_texture_width, s_texture_height, 0, GL_RED, GL_UNSIGNED_BYTE,
7188                                   s_texture_data_r);
7189         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
7190
7191         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
7192         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
7193         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
7194
7195         /* Green texture. */
7196         gl.bindTexture(GL_TEXTURE_2D, m_to[1]);
7197         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7198
7199         gl.texImage2D(GL_TEXTURE_2D, 0, GL_R8, s_texture_width, s_texture_height, 0, GL_RED, GL_UNSIGNED_BYTE,
7200                                   s_texture_data_g);
7201         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
7202
7203         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
7204         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
7205         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
7206
7207         /* Blue texture. */
7208         gl.bindTexture(GL_TEXTURE_2D, m_to[2]);
7209         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7210
7211         gl.texImage2D(GL_TEXTURE_2D, 0, GL_R8, s_texture_width, s_texture_height, 0, GL_RED, GL_UNSIGNED_BYTE,
7212                                   s_texture_data_b);
7213         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
7214
7215         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
7216         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
7217         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
7218
7219         /* Alpha texture. */
7220         gl.bindTexture(GL_TEXTURE_2D, m_to[3]);
7221         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7222
7223         gl.texImage2D(GL_TEXTURE_2D, 0, GL_R8, s_texture_width, s_texture_height, 0, GL_RED, GL_UNSIGNED_BYTE,
7224                                   s_texture_data_a);
7225         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
7226
7227         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
7228         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
7229         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
7230 }
7231
7232 /** @brief Create framebuffer.
7233  */
7234 void BindUnitTest::CreateFrambuffer()
7235 {
7236         /* Shortcut for GL functionality. */
7237         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7238
7239         /* Prepare framebuffer. */
7240         gl.genFramebuffers(1, &m_fbo);
7241         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
7242
7243         gl.genRenderbuffers(1, &m_rbo);
7244         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
7245
7246         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
7247         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
7248
7249         gl.bindRenderbuffer(GL_RENDERBUFFER, m_rbo);
7250         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
7251
7252         gl.renderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, s_texture_width, s_texture_height);
7253         GLU_EXPECT_NO_ERROR(gl.getError(), "glRenderbufferStorage call failed.");
7254
7255         gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_rbo);
7256         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
7257
7258         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
7259         {
7260                 throw 0;
7261         }
7262
7263         gl.viewport(0, 0, s_texture_width, s_texture_height);
7264         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
7265
7266         /* Clear framebuffer's content. */
7267         gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
7268         GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
7269
7270         gl.clear(GL_COLOR_BUFFER_BIT);
7271         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
7272 }
7273
7274 /** @brief Create vertex array object.
7275  */
7276 void BindUnitTest::CreateVertexArray()
7277 {
7278         /* Shortcut for GL functionality. */
7279         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7280
7281         gl.genVertexArrays(1, &m_vao);
7282         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays call has failed.");
7283
7284         gl.bindVertexArray(m_vao);
7285         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray call has failed.");
7286 }
7287
7288 bool BindUnitTest::Draw()
7289 {
7290         /* Shortcut for GL functionality. */
7291         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7292
7293         /* Setup program. */
7294         gl.useProgram(m_po);
7295         GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram call has failed.");
7296
7297         /* Bind textures to proper units and setup program's samplers. */
7298         for (glw::GLuint i = 0; i < 4; ++i)
7299         {
7300                 /* Tested binding funcion. */
7301                 gl.bindTextureUnit(i, m_to[i]);
7302
7303                 /* Check for errors. */
7304                 glw::GLenum error = GL_NO_ERROR;
7305
7306                 if (GL_NO_ERROR != (error = gl.getError()))
7307                 {
7308                         m_context.getTestContext().getLog()
7309                                 << tcu::TestLog::Message << "BindTextureUnit unexpectedly generated error " << glu::getErrorStr(error)
7310                                 << " when binding texture " << m_to[i] << " to texture unit " << i << ". Test fails."
7311                                 << tcu::TestLog::EndMessage;
7312
7313                         return false;
7314                 }
7315
7316                 /* Sampler setup. */
7317                 gl.uniform1i(gl.getUniformLocation(m_po, s_fragment_shader_samplers[i]), i);
7318                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetUniformLocation or glUniform1i call has failed.");
7319         }
7320
7321         /* Draw call. */
7322         gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
7323         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays call has failed.");
7324
7325         return true;
7326 }
7327
7328 /** @brief Compare results with reference.
7329  *
7330  *  @return True if equal, false otherwise.
7331  */
7332 bool BindUnitTest::Check()
7333 {
7334         /* Shortcut for GL functionality. */
7335         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7336
7337         /* Setup storage for results. */
7338         m_result = new glw::GLubyte[s_texture_count_rgba];
7339
7340         /* Setup pixel sotre modes.*/
7341         gl.pixelStorei(GL_UNPACK_ALIGNMENT, sizeof(glw::GLubyte));
7342         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
7343
7344         gl.pixelStorei(GL_PACK_ALIGNMENT, sizeof(glw::GLubyte));
7345         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
7346
7347         /* Query framebuffer's image. */
7348         gl.readPixels(0, 0, s_texture_width, s_texture_height, GL_RGBA, GL_UNSIGNED_BYTE, m_result);
7349         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays call has failed.");
7350
7351         /* Compare values with reference. */
7352         for (glw::GLuint i = 0; i < s_texture_count_rgba; ++i)
7353         {
7354                 if (s_texture_data_rgba[i] != m_result[i])
7355                 {
7356                         m_context.getTestContext().getLog()
7357                                 << tcu::TestLog::Message << "Framebuffer data " << DataToString(s_texture_count_rgba, m_result)
7358                                 << " does not match the reference values " << DataToString(s_texture_count_rgba, s_texture_data_rgba)
7359                                 << "." << tcu::TestLog::EndMessage;
7360
7361                         return false;
7362                 }
7363         }
7364
7365         return true;
7366 }
7367
7368 /** @brief Clean GL objects, test variables and GL errors.
7369  */
7370 void BindUnitTest::CleanAll()
7371 {
7372         /* Shortcut for GL functionality. */
7373         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7374
7375         /* Release GL objects. */
7376         if (m_po)
7377         {
7378                 gl.useProgram(0);
7379
7380                 gl.deleteProgram(m_po);
7381
7382                 m_po = 0;
7383         }
7384
7385         if (m_to[0] || m_to[1] || m_to[2] || m_to[3])
7386         {
7387                 gl.deleteTextures(4, m_to);
7388
7389                 m_to[0] = 0;
7390                 m_to[1] = 0;
7391                 m_to[2] = 0;
7392                 m_to[3] = 0;
7393         }
7394
7395         if (m_fbo)
7396         {
7397                 gl.deleteFramebuffers(1, &m_fbo);
7398
7399                 m_fbo = 0;
7400         }
7401
7402         if (m_rbo)
7403         {
7404                 gl.deleteRenderbuffers(1, &m_rbo);
7405
7406                 m_rbo = 0;
7407         }
7408
7409         /* Release heap. */
7410         if (DE_NULL != m_result)
7411         {
7412                 delete[] m_result;
7413         }
7414
7415         /* Erros clean-up. */
7416         while (GL_NO_ERROR != gl.getError())
7417                 ;
7418 }
7419
7420 /** @brief Convert raw data into string for logging purposes.
7421  *
7422  *  @param [in] count      Count of the data.
7423  *  @param [in] data       Raw data.
7424  *
7425  *  @return String representation of data.
7426  */
7427 std::string BindUnitTest::DataToString(glw::GLuint count, const glw::GLubyte data[])
7428 {
7429         std::string data_str = "[";
7430
7431         for (glw::GLuint i = 0; i < count; ++i)
7432         {
7433                 std::stringstream int_sstream;
7434
7435                 int_sstream << unsigned(data[i]);
7436
7437                 data_str.append(int_sstream.str());
7438
7439                 if (i + 1 < count)
7440                 {
7441                         data_str.append(", ");
7442                 }
7443                 else
7444                 {
7445                         data_str.append("]");
7446                 }
7447         }
7448
7449         return data_str;
7450 }
7451
7452 /** Reference data and parameters. */
7453 const glw::GLubyte BindUnitTest::s_texture_data_r[]     = { 0, 4, 8, 12, 16, 20 };
7454 const glw::GLubyte BindUnitTest::s_texture_data_g[]     = { 1, 5, 9, 13, 17, 21 };
7455 const glw::GLubyte BindUnitTest::s_texture_data_b[]     = { 2, 6, 10, 14, 18, 22 };
7456 const glw::GLubyte BindUnitTest::s_texture_data_a[]     = { 3, 7, 11, 15, 19, 23 };
7457 const glw::GLubyte BindUnitTest::s_texture_data_rgba[] = { 0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11,
7458                                                                                                                    12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 };
7459 const glw::GLuint BindUnitTest::s_texture_width          = 2;
7460 const glw::GLuint BindUnitTest::s_texture_height         = 3;
7461 const glw::GLuint BindUnitTest::s_texture_count_rgba = sizeof(s_texture_data_rgba) / sizeof(s_texture_data_rgba[0]);
7462
7463 /* Vertex shader source code. */
7464 const glw::GLchar* BindUnitTest::s_vertex_shader = "#version 450\n"
7465                                                                                                    "\n"
7466                                                                                                    "void main()\n"
7467                                                                                                    "{\n"
7468                                                                                                    "    switch(gl_VertexID)\n"
7469                                                                                                    "    {\n"
7470                                                                                                    "        case 0:\n"
7471                                                                                                    "            gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
7472                                                                                                    "            break;\n"
7473                                                                                                    "        case 1:\n"
7474                                                                                                    "            gl_Position = vec4( 1.0, 1.0, 0.0, 1.0);\n"
7475                                                                                                    "            break;\n"
7476                                                                                                    "        case 2:\n"
7477                                                                                                    "            gl_Position = vec4(-1.0,-1.0, 0.0, 1.0);\n"
7478                                                                                                    "            break;\n"
7479                                                                                                    "        case 3:\n"
7480                                                                                                    "            gl_Position = vec4( 1.0,-1.0, 0.0, 1.0);\n"
7481                                                                                                    "            break;\n"
7482                                                                                                    "    }\n"
7483                                                                                                    "}\n";
7484
7485 /* Fragment shader source program. */
7486 const glw::GLchar* BindUnitTest::s_fragment_shader =
7487         "#version 450\n"
7488         "\n"
7489         "layout(pixel_center_integer) in vec4 gl_FragCoord;\n"
7490         "\n"
7491         "uniform sampler2D texture_input_r;\n"
7492         "uniform sampler2D texture_input_g;\n"
7493         "uniform sampler2D texture_input_b;\n"
7494         "uniform sampler2D texture_input_a;\n"
7495         "\n"
7496         "out     vec4      color_output;\n"
7497         "\n"
7498         "void main()\n"
7499         "{\n"
7500         "    color_output = vec4(texelFetch(texture_input_r, ivec2(gl_FragCoord.xy), 0).r,\n"
7501         "                        texelFetch(texture_input_g, ivec2(gl_FragCoord.xy), 0).r,\n"
7502         "                        texelFetch(texture_input_b, ivec2(gl_FragCoord.xy), 0).r,\n"
7503         "                        texelFetch(texture_input_a, ivec2(gl_FragCoord.xy), 0).r);\n"
7504         "}\n";
7505
7506 const glw::GLchar* BindUnitTest::s_fragment_shader_samplers[4] = { "texture_input_r", "texture_input_g",
7507                                                                                                                                    "texture_input_b", "texture_input_a" };
7508
7509 /******************************** Get Image Test Implementation   ********************************/
7510
7511 /** @brief Get Image Test constructor.
7512  *
7513  *  @param [in] context     OpenGL context.
7514  */
7515 GetImageTest::GetImageTest(deqp::Context& context)
7516         : deqp::TestCase(context, "textures_get_image", "Textures Get Image Test")
7517 {
7518         /* Intentionally left blank */
7519 }
7520
7521 /** Reference data. */
7522 const glw::GLubyte GetImageTest::s_texture_data[] = { 0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3,
7523                                                                                                           0xff, 0xff, 0xff, 0xff, 0xff, 0x88, 0x0,  0x15, 0xff, 0xed, 0x1c,
7524                                                                                                           0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff, 0xc8,
7525                                                                                                           0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff,
7526                                                                                                           0xb5, 0xe6, 0x1d, 0xff, 0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc,
7527                                                                                                           0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff };
7528
7529 /** Reference data (compressed). */
7530 const glw::GLubyte GetImageTest::s_texture_data_compressed[] = { 0x90, 0x2b, 0x8f, 0x0f, 0xfe, 0x0f, 0x98, 0x99,
7531                                                                                                                                  0x99, 0x99, 0x59, 0x8f, 0x8c, 0xa6, 0xb7, 0x71 };
7532
7533 /** Reference data parameters. */
7534 const glw::GLuint GetImageTest::s_texture_width                   = 4;
7535 const glw::GLuint GetImageTest::s_texture_height                  = 4;
7536 const glw::GLuint GetImageTest::s_texture_size                    = sizeof(s_texture_data);
7537 const glw::GLuint GetImageTest::s_texture_size_compressed = sizeof(s_texture_data_compressed);
7538 const glw::GLuint GetImageTest::s_texture_count                   = s_texture_size / sizeof(s_texture_data[0]);
7539 const glw::GLuint GetImageTest::s_texture_count_compressed =
7540         s_texture_size_compressed / sizeof(s_texture_data_compressed[0]);
7541
7542 /** @brief Get Image Test cases.
7543  *
7544  *  @return Iteration result.
7545  */
7546 tcu::TestNode::IterateResult GetImageTest::iterate()
7547 {
7548         /* Shortcut for GL functionality. */
7549         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7550
7551         /* Get context setup. */
7552         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
7553         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
7554
7555         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
7556         {
7557                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
7558
7559                 return STOP;
7560         }
7561
7562         /* Running tests. */
7563         bool is_ok      = true;
7564         bool is_error = false;
7565
7566         /* Objects. */
7567         glw::GLuint  texture                                                                       = 0;
7568         glw::GLubyte result[s_texture_count]                                       = {};
7569         glw::GLubyte result_compressed[s_texture_count_compressed] = {};
7570
7571         try
7572         {
7573                 /* Uncompressed case. */
7574                 {
7575                         /* Texture initiation. */
7576                         gl.genTextures(1, &texture);
7577                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
7578
7579                         gl.bindTexture(GL_TEXTURE_2D, texture);
7580                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7581
7582                         gl.texImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, s_texture_width, s_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
7583                                                   s_texture_data);
7584                         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
7585
7586                         /* Quering image with tested function. */
7587                         gl.getTextureImage(texture, 0, GL_RGBA, GL_UNSIGNED_BYTE, sizeof(result), result);
7588
7589                         /* Check for errors. */
7590                         glw::GLenum error = GL_NO_ERROR;
7591
7592                         if (GL_NO_ERROR != (error = gl.getError()))
7593                         {
7594                                 m_context.getTestContext().getLog()
7595                                         << tcu::TestLog::Message << "GetTextureImage unexpectedly generated error "
7596                                         << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
7597
7598                                 is_ok = false;
7599                         }
7600                         else
7601                         {
7602                                 /* No error, so compare images. */
7603                                 for (glw::GLuint i = 0; i < s_texture_count; ++i)
7604                                 {
7605                                         if (s_texture_data[i] != result[i])
7606                                         {
7607                                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "GetTextureImage returned "
7608                                                                                                                         << DataToString(s_texture_count, result) << ", but "
7609                                                                                                                         << DataToString(s_texture_count, s_texture_data)
7610                                                                                                                         << " was expected. Test fails." << tcu::TestLog::EndMessage;
7611
7612                                                 is_ok = false;
7613
7614                                                 break;
7615                                         }
7616                                 }
7617                         }
7618                 }
7619
7620                 /* Clean up texture .*/
7621                 gl.deleteTextures(1, &texture);
7622                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
7623
7624                 texture = 0;
7625
7626                 /* Compressed case. */
7627                 {
7628                         /* Texture initiation. */
7629                         gl.genTextures(1, &texture);
7630                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
7631
7632                         gl.bindTexture(GL_TEXTURE_2D, texture);
7633                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7634
7635                         gl.compressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_BPTC_UNORM, s_texture_width, s_texture_height,
7636                                                                         0, s_texture_size_compressed, s_texture_data_compressed);
7637                         GLU_EXPECT_NO_ERROR(gl.getError(), "glCompressedTexImage2D has failed");
7638
7639                         /* Quering image with tested function. */
7640                         gl.getCompressedTextureImage(texture, 0, s_texture_count_compressed * sizeof(result_compressed[0]),
7641                                                                                  result_compressed);
7642
7643                         /* Check for errors. */
7644                         glw::GLenum error = GL_NO_ERROR;
7645
7646                         if (GL_NO_ERROR != (error = gl.getError()))
7647                         {
7648                                 m_context.getTestContext().getLog()
7649                                         << tcu::TestLog::Message << "GetCompressedTextureImage unexpectedly generated error "
7650                                         << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
7651
7652                                 is_ok = false;
7653                         }
7654                         else
7655                         {
7656                                 /* No error, so compare images. */
7657                                 for (glw::GLuint i = 0; i < s_texture_count_compressed; ++i)
7658                                 {
7659                                         if (s_texture_data_compressed[i] != result_compressed[i])
7660                                         {
7661                                                 m_context.getTestContext().getLog()
7662                                                         << tcu::TestLog::Message << "GetCompressedTextureImage returned "
7663                                                         << DataToString(s_texture_count_compressed, result_compressed) << ", but "
7664                                                         << DataToString(s_texture_count_compressed, s_texture_data_compressed)
7665                                                         << " was expected. Test fails." << tcu::TestLog::EndMessage;
7666
7667                                                 is_ok = false;
7668
7669                                                 break;
7670                                         }
7671                                 }
7672                         }
7673                 }
7674         }
7675         catch (...)
7676         {
7677                 is_ok   = false;
7678                 is_error = true;
7679         }
7680
7681         /* Cleanup. */
7682         if (texture)
7683         {
7684                 gl.deleteTextures(1, &texture);
7685         }
7686
7687         /* Result's setup. */
7688         if (is_ok)
7689         {
7690                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
7691         }
7692         else
7693         {
7694                 if (is_error)
7695                 {
7696                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
7697                 }
7698                 else
7699                 {
7700                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7701                 }
7702         }
7703
7704         return STOP;
7705 }
7706
7707 /** @brief Convert raw data into string for logging purposes.
7708  *
7709  *  @param [in] count      Count of the data.
7710  *  @param [in] data       Raw data.
7711  *
7712  *  @return String representation of data.
7713  */
7714 std::string GetImageTest::DataToString(glw::GLuint count, const glw::GLubyte data[])
7715 {
7716         std::string data_str = "[";
7717
7718         for (glw::GLuint i = 0; i < count; ++i)
7719         {
7720                 std::stringstream int_sstream;
7721
7722                 int_sstream << unsigned(data[i]);
7723
7724                 data_str.append(int_sstream.str());
7725
7726                 if (i + 1 < count)
7727                 {
7728                         data_str.append(", ");
7729                 }
7730                 else
7731                 {
7732                         data_str.append("]");
7733                 }
7734         }
7735
7736         return data_str;
7737 }
7738
7739 /******************************** Get Level Parameter Test Implementation   ********************************/
7740
7741 /** @brief Get Level Parameter Test constructor.
7742  *
7743  *  @param [in] context     OpenGL context.
7744  */
7745 GetLevelParameterTest::GetLevelParameterTest(deqp::Context& context)
7746         : deqp::TestCase(context, "textures_get_level_parameter", "Textures Get Level Parameter Test")
7747 {
7748         /* Intentionally left blank */
7749 }
7750
7751 /** Reference data. */
7752 const glw::GLubyte GetLevelParameterTest::s_texture_data[] = {
7753         0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
7754         0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
7755         0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
7756         0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff,
7757
7758         0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
7759         0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
7760         0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
7761         0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff,
7762
7763         0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
7764         0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
7765         0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
7766         0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff,
7767
7768         0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
7769         0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
7770         0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
7771         0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff
7772 };
7773
7774 /** Reference data parameters. */
7775 const glw::GLuint GetLevelParameterTest::s_texture_width  = 4;
7776 const glw::GLuint GetLevelParameterTest::s_texture_height = 4;
7777 const glw::GLuint GetLevelParameterTest::s_texture_depth  = 4;
7778
7779 /** @brief Get Level Parameter Test cases.
7780  *
7781  *  @return Iteration result.
7782  */
7783 tcu::TestNode::IterateResult GetLevelParameterTest::iterate()
7784 {
7785         /* Shortcut for GL functionality. */
7786         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7787
7788         /* Get context setup. */
7789         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
7790         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
7791
7792         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
7793         {
7794                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
7795
7796                 return STOP;
7797         }
7798
7799         /* Running tests. */
7800         bool is_ok      = true;
7801         bool is_error = false;
7802
7803         /* Objects. */
7804         glw::GLuint texture = 0;
7805
7806         try
7807         {
7808                 /* Texture initiation. */
7809                 gl.genTextures(1, &texture);
7810                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
7811
7812                 gl.bindTexture(GL_TEXTURE_3D, texture);
7813                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7814
7815                 gl.texImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, s_texture_width, s_texture_height, s_texture_depth, 0, GL_RGBA,
7816                                           GL_UNSIGNED_BYTE, s_texture_data);
7817                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
7818
7819                 gl.texImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, s_texture_width / 2, s_texture_height / 2, s_texture_depth / 2, 0,
7820                                           GL_RGBA, GL_UNSIGNED_BYTE, s_texture_data);
7821                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
7822
7823                 static const glw::GLenum pnames[] = {
7824                         GL_TEXTURE_WIDTH,         GL_TEXTURE_HEIGHT,     GL_TEXTURE_DEPTH,               GL_TEXTURE_INTERNAL_FORMAT,
7825                         GL_TEXTURE_RED_TYPE,   GL_TEXTURE_GREEN_TYPE, GL_TEXTURE_BLUE_TYPE,  GL_TEXTURE_ALPHA_TYPE,
7826                         GL_TEXTURE_DEPTH_TYPE, GL_TEXTURE_RED_SIZE,   GL_TEXTURE_GREEN_SIZE, GL_TEXTURE_BLUE_SIZE,
7827                         GL_TEXTURE_ALPHA_SIZE, GL_TEXTURE_DEPTH_SIZE, GL_TEXTURE_COMPRESSED
7828                 };
7829                 static const glw::GLuint pnames_count = sizeof(pnames) / sizeof(pnames[0]);
7830
7831                 /* Test GetTextureLevelParameteriv. */
7832                 for (glw::GLuint i = 0; i < 2 /* levels */; ++i)
7833                 {
7834                         for (glw::GLuint j = 0; j < pnames_count; ++j)
7835                         {
7836                                 glw::GLint result_legacy = 0;
7837                                 glw::GLint result_dsa   = 0;
7838
7839                                 /* Quering reference value. */
7840                                 gl.getTexLevelParameteriv(GL_TEXTURE_3D, i, pnames[j], &result_legacy);
7841                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
7842
7843                                 /* Quering using DSA function. */
7844                                 gl.getTextureLevelParameteriv(texture, i, pnames[j], &result_dsa);
7845
7846                                 /* Check for errors. */
7847                                 glw::GLenum error = GL_NO_ERROR;
7848
7849                                 if (GL_NO_ERROR != (error = gl.getError()))
7850                                 {
7851                                         m_context.getTestContext().getLog()
7852                                                 << tcu::TestLog::Message << "GetTextureLevelParameteriv unexpectedly generated error "
7853                                                 << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
7854
7855                                         is_ok = false;
7856                                 }
7857                                 else
7858                                 {
7859                                         /* Compare values. */
7860                                         if (result_legacy != result_dsa)
7861                                         {
7862                                                 m_context.getTestContext().getLog()
7863                                                         << tcu::TestLog::Message << "For parameter name "
7864                                                         << glu::getTextureLevelParameterStr(pnames[j]) << " GetTextureLevelParameteriv returned "
7865                                                         << result_dsa << ", but reference value (queried using GetTexLevelParameteriv) was "
7866                                                         << result_legacy << ". Test fails." << tcu::TestLog::EndMessage;
7867
7868                                                 is_ok = false;
7869                                         }
7870                                 }
7871                         }
7872                 }
7873
7874                 /* Test GetTextureLevelParameterfv. */
7875                 for (glw::GLuint i = 0; i < 2 /* levels */; ++i)
7876                 {
7877                         for (glw::GLuint j = 0; j < pnames_count; ++j)
7878                         {
7879                                 glw::GLfloat result_legacy = 0.f;
7880                                 glw::GLfloat result_dsa = 0.f;
7881
7882                                 /* Quering reference value. */
7883                                 gl.getTexLevelParameterfv(GL_TEXTURE_3D, i, pnames[j], &result_legacy);
7884                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameterfv has failed");
7885
7886                                 /* Quering using DSA function. */
7887                                 gl.getTextureLevelParameterfv(texture, i, pnames[j], &result_dsa);
7888
7889                                 /* Check for errors. */
7890                                 glw::GLenum error = GL_NO_ERROR;
7891
7892                                 if (GL_NO_ERROR != (error = gl.getError()))
7893                                 {
7894                                         m_context.getTestContext().getLog()
7895                                                 << tcu::TestLog::Message << "GetTextureLevelParameterfv unexpectedly generated error "
7896                                                 << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
7897
7898                                         is_ok = false;
7899                                 }
7900                                 else
7901                                 {
7902                                         /* Compare values. */
7903                                         if (de::abs(result_legacy - result_dsa) > 0.125 /* Precision. */)
7904                                         {
7905                                                 m_context.getTestContext().getLog()
7906                                                         << tcu::TestLog::Message << "For parameter name "
7907                                                         << glu::getTextureLevelParameterStr(pnames[j]) << " GetTextureLevelParameterfv returned "
7908                                                         << result_dsa << ", but reference value (queried using GetTexLevelParameterfv) was "
7909                                                         << result_legacy << ". Test fails." << tcu::TestLog::EndMessage;
7910
7911                                                 is_ok = false;
7912                                         }
7913                                 }
7914                         }
7915                 }
7916         }
7917         catch (...)
7918         {
7919                 is_ok   = false;
7920                 is_error = true;
7921         }
7922
7923         /* Cleanup. */
7924         if (texture)
7925         {
7926                 gl.deleteTextures(1, &texture);
7927         }
7928
7929         while (GL_NO_ERROR != gl.getError())
7930                 ;
7931
7932         /* Result's setup. */
7933         if (is_ok)
7934         {
7935                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
7936         }
7937         else
7938         {
7939                 if (is_error)
7940                 {
7941                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
7942                 }
7943                 else
7944                 {
7945                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7946                 }
7947         }
7948
7949         return STOP;
7950 }
7951
7952 /*********************************** Errors Utility Class *****************************************************/
7953
7954 /** @brief Check for errors and log.
7955  *
7956  *  @param [in] context             Test's context.
7957  *  @param [in] expected_error      Expected error value.
7958  *  @param [in] function_name       Name of the function (to be logged).
7959  *  @param [in] log                 Log message.
7960  *
7961  *  @return True if error is equal to expected, false otherwise.
7962  */
7963 bool ErrorsUtilities::CheckErrorAndLog(deqp::Context& context, glw::GLuint expected_error,
7964                                                                            const glw::GLchar* function_name, const glw::GLchar* log)
7965 {
7966         /* Shortcut for GL functionality. */
7967         const glw::Functions& gl = context.getRenderContext().getFunctions();
7968
7969         /* Check error. */
7970         glw::GLenum error = GL_NO_ERROR;
7971
7972         if (expected_error != (error = gl.getError()))
7973         {
7974                 context.getTestContext().getLog() << tcu::TestLog::Message << function_name << " generated error "
7975                                                                                   << glu::getErrorStr(error) << " but, " << glu::getErrorStr(expected_error)
7976                                                                                   << " was expected if " << log << tcu::TestLog::EndMessage;
7977
7978                 return false;
7979         }
7980
7981         return true;
7982 }
7983
7984 /******************************** Creation Errors Test Implementation   ********************************/
7985
7986 /** @brief Creation Errors Test constructor.
7987  *
7988  *  @param [in] context     OpenGL context.
7989  */
7990 CreationErrorsTest::CreationErrorsTest(deqp::Context& context)
7991         : deqp::TestCase(context, "textures_creation_errors", "Texture Objects Creation Errors Test")
7992 {
7993         /* Intentionally left blank. */
7994 }
7995
7996 /** @brief Iterate Creation Errors Test cases.
7997  *
7998  *  @return Iteration result.
7999  */
8000 tcu::TestNode::IterateResult CreationErrorsTest::iterate()
8001 {
8002         /* Shortcut for GL functionality. */
8003         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8004
8005         /* Get context setup. */
8006         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
8007         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
8008
8009         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
8010         {
8011                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
8012
8013                 return STOP;
8014         }
8015
8016         /* Running tests. */
8017         bool is_ok      = true;
8018         bool is_error = false;
8019
8020         /* Textures' objects */
8021         glw::GLuint texture = 0;
8022
8023         try
8024         {
8025                 /* Not a target test. */
8026                 gl.createTextures(NotATarget(), 1, &texture);
8027                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glCreateTextures",
8028                                                                   "target is not one of the allowable values.");
8029
8030                 if (texture)
8031                 {
8032                         gl.deleteTextures(1, &texture);
8033
8034                         texture = 0;
8035                 }
8036
8037                 /* Negative number of textures. */
8038                 gl.createTextures(GL_TEXTURE_2D, -1, &texture);
8039                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCreateTextures", "n is negative.");
8040         }
8041         catch (...)
8042         {
8043                 is_ok   = false;
8044                 is_error = true;
8045         }
8046
8047         /* Cleanup. */
8048         if (texture)
8049         {
8050                 gl.deleteTextures(1, &texture);
8051         }
8052
8053         /* Errors clean up. */
8054         while (gl.getError())
8055                 ;
8056
8057         /* Result's setup. */
8058         if (is_ok)
8059         {
8060                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
8061         }
8062         else
8063         {
8064                 if (is_error)
8065                 {
8066                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
8067                 }
8068                 else
8069                 {
8070                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
8071                 }
8072         }
8073
8074         return STOP;
8075 }
8076
8077 /** @brief Function retruns enum which is not a texture target.
8078  */
8079 glw::GLenum CreationErrorsTest::NotATarget()
8080 {
8081         static const glw::GLenum texture_targets[] = { GL_TEXTURE_1D,
8082                                                                                                    GL_TEXTURE_2D,
8083                                                                                                    GL_TEXTURE_3D,
8084                                                                                                    GL_TEXTURE_1D_ARRAY,
8085                                                                                                    GL_TEXTURE_2D_ARRAY,
8086                                                                                                    GL_TEXTURE_RECTANGLE,
8087                                                                                                    GL_TEXTURE_CUBE_MAP,
8088                                                                                                    GL_TEXTURE_CUBE_MAP_ARRAY,
8089                                                                                                    GL_TEXTURE_BUFFER,
8090                                                                                                    GL_TEXTURE_2D_MULTISAMPLE,
8091                                                                                                    GL_TEXTURE_2D_MULTISAMPLE_ARRAY };
8092
8093         glw::GLenum not_a_target = 0;
8094         bool            is_target       = true;
8095
8096         while (is_target)
8097         {
8098                 not_a_target++;
8099
8100                 is_target = false;
8101
8102                 for (glw::GLuint i = 0; i < sizeof(texture_targets) / sizeof(texture_targets[0]); ++i)
8103                 {
8104                         if (texture_targets[i] == not_a_target)
8105                         {
8106                                 is_target = true;
8107                                 break;
8108                         }
8109                 }
8110         }
8111
8112         return not_a_target;
8113 }
8114
8115 /******************************** Texture Buffer Errors Test Implementation   ********************************/
8116
8117 /** @brief Texture Buffer Errors Test constructor.
8118  *
8119  *  @param [in] context     OpenGL context.
8120  */
8121 BufferErrorsTest::BufferErrorsTest(deqp::Context& context)
8122         : deqp::TestCase(context, "textures_buffer_errors", "Texture Buffer Errors Test")
8123 {
8124         /* Intentionally left blank. */
8125 }
8126
8127 /** @brief Iterate Texture Buffer Errors Test cases.
8128  *
8129  *  @return Iteration result.
8130  */
8131 tcu::TestNode::IterateResult BufferErrorsTest::iterate()
8132 {
8133         /* Shortcut for GL functionality. */
8134         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8135
8136         /* Get context setup. */
8137         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
8138         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
8139
8140         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
8141         {
8142                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
8143
8144                 return STOP;
8145         }
8146
8147         /* Running tests. */
8148         bool is_ok      = true;
8149         bool is_error = false;
8150
8151         /* Textures' objects */
8152         glw::GLuint texture_buffer = 0;
8153         glw::GLuint texture_1D   = 0;
8154         glw::GLuint buffer                 = 0;
8155
8156         static const glw::GLubyte data[4]   = { 1, 2, 3, 4 };
8157         static const glw::GLuint  data_size = sizeof(data);
8158
8159         try
8160         {
8161                 /* Auxiliary objects setup. */
8162                 gl.createTextures(GL_TEXTURE_BUFFER, 1, &texture_buffer);
8163                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8164
8165                 gl.createTextures(GL_TEXTURE_1D, 1, &texture_1D);
8166                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8167
8168                 gl.createBuffers(1, &buffer);
8169                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateBuffers has failed");
8170
8171                 gl.namedBufferData(buffer, data_size, data, GL_STATIC_COPY);
8172                 GLU_EXPECT_NO_ERROR(gl.getError(), "glNamedBufferData has failed");
8173
8174                 /*  Check that INVALID_OPERATION is generated by glTextureBuffer if texture
8175                  is not the name of an existing texture object. */
8176                 {
8177                         glw::GLuint not_a_texture = 0;
8178
8179                         while (gl.isTexture(++not_a_texture))
8180                                 ;
8181                         GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed");
8182
8183                         gl.textureBuffer(not_a_texture, GL_RGBA8, buffer);
8184
8185                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureBuffer",
8186                                                                           "texture is not the name of an existing texture object.");
8187                 }
8188
8189                 /*  Check that INVALID_ENUM is generated by glTextureBuffer if the effective
8190                  target of texture is not TEXTURE_BUFFER. */
8191                 {
8192                         gl.textureBuffer(texture_1D, GL_RGBA8, buffer);
8193
8194                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureBuffer",
8195                                                                           "the effective target of texture is not TEXTURE_BUFFER.");
8196                 }
8197
8198                 /*  Check that INVALID_ENUM is generated if internalformat is not one of the
8199                  sized internal formats described above. */
8200                 {
8201                         gl.textureBuffer(texture_buffer, GL_COMPRESSED_SIGNED_RED_RGTC1, buffer);
8202
8203                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureBuffer",
8204                                                                           "internalformat is not one of the sized internal formats described above..");
8205                 }
8206
8207                 /*  Check that INVALID_OPERATION is generated if buffer is not zero and is
8208                  not the name of an existing buffer object. */
8209                 {
8210                         glw::GLuint not_a_buffer = 0;
8211
8212                         while (gl.isBuffer(++not_a_buffer))
8213                                 ;
8214                         GLU_EXPECT_NO_ERROR(gl.getError(), "glIsBuffer has failed");
8215
8216                         gl.textureBuffer(texture_buffer, GL_RGBA8, not_a_buffer);
8217
8218                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureBuffer",
8219                                                                           "buffer is not zero and is not the name of an existing buffer object.");
8220                 }
8221         }
8222         catch (...)
8223         {
8224                 is_ok   = false;
8225                 is_error = true;
8226         }
8227
8228         /* Cleanup. */
8229         if (texture_1D)
8230         {
8231                 gl.deleteTextures(1, &texture_1D);
8232         }
8233
8234         if (texture_buffer)
8235         {
8236                 gl.deleteTextures(1, &texture_buffer);
8237         }
8238
8239         if (buffer)
8240         {
8241                 gl.deleteBuffers(1, &buffer);
8242         }
8243
8244         /* Errors clean up. */
8245         while (gl.getError())
8246                 ;
8247
8248         /* Result's setup. */
8249         if (is_ok)
8250         {
8251                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
8252         }
8253         else
8254         {
8255                 if (is_error)
8256                 {
8257                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
8258                 }
8259                 else
8260                 {
8261                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
8262                 }
8263         }
8264
8265         return STOP;
8266 }
8267
8268 /******************************** Texture Buffer Range Errors Test Implementation   ********************************/
8269
8270 /** @brief Texture Buffer Range Errors Test constructor.
8271  *
8272  *  @param [in] context     OpenGL context.
8273  */
8274 BufferRangeErrorsTest::BufferRangeErrorsTest(deqp::Context& context)
8275         : deqp::TestCase(context, "textures_buffer_range_errors", "Texture Buffer Range Errors Test")
8276 {
8277         /* Intentionally left blank. */
8278 }
8279
8280 /** @brief Iterate Texture Buffer Range Errors Test cases.
8281  *
8282  *  @return Iteration result.
8283  */
8284 tcu::TestNode::IterateResult BufferRangeErrorsTest::iterate()
8285 {
8286         /* Shortcut for GL functionality. */
8287         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8288
8289         /* Get context setup. */
8290         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
8291         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
8292
8293         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
8294         {
8295                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
8296
8297                 return STOP;
8298         }
8299
8300         /* Running tests. */
8301         bool is_ok      = true;
8302         bool is_error = false;
8303
8304         /* Textures' objects */
8305         glw::GLuint texture_buffer = 0;
8306         glw::GLuint texture_1D   = 0;
8307         glw::GLuint buffer                 = 0;
8308
8309         static const glw::GLubyte data[4]   = { 1, 2, 3, 4 };
8310         static const glw::GLuint  data_size = sizeof(data);
8311
8312         try
8313         {
8314                 /* Auxiliary objects setup. */
8315                 gl.createTextures(GL_TEXTURE_BUFFER, 1, &texture_buffer);
8316                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8317
8318                 gl.createTextures(GL_TEXTURE_1D, 1, &texture_1D);
8319                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8320
8321                 gl.createBuffers(1, &buffer);
8322                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateBuffers has failed");
8323
8324                 gl.namedBufferData(buffer, data_size, data, GL_STATIC_COPY);
8325                 GLU_EXPECT_NO_ERROR(gl.getError(), "glNamedBufferData has failed");
8326
8327                 /*  Check that INVALID_OPERATION is generated by TextureBufferRange if
8328                  texture is not the name of an existing texture object.*/
8329                 {
8330                         glw::GLuint not_a_texture = 0;
8331
8332                         while (gl.isTexture(++not_a_texture))
8333                                 ;
8334                         GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed");
8335
8336                         gl.textureBufferRange(not_a_texture, GL_RGBA8, buffer, 0, data_size);
8337
8338                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureBufferRange",
8339                                                                           "texture is not the name of an existing texture object.");
8340                 }
8341
8342                 /*  Check that INVALID_ENUM is generated by TextureBufferRange if the
8343                  effective target of texture is not TEXTURE_BUFFER. */
8344                 {
8345                         gl.textureBufferRange(texture_1D, GL_RGBA8, buffer, 0, data_size);
8346
8347                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureBufferRange",
8348                                                                           "the effective target of texture is not TEXTURE_BUFFER.");
8349                 }
8350
8351                 /*  Check that INVALID_ENUM is generated by TextureBufferRange if
8352                  internalformat is not one of the sized internal formats described above. */
8353                 {
8354                         gl.textureBufferRange(texture_buffer, GL_COMPRESSED_SIGNED_RED_RGTC1, buffer, 0, data_size);
8355
8356                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureBufferRange",
8357                                                                           "internalformat is not one of the supported sized internal formats.");
8358                 }
8359
8360                 /*  Check that INVALID_OPERATION is generated by TextureBufferRange if
8361                  buffer is not zero and is not the name of an existing buffer object. */
8362                 {
8363                         glw::GLuint not_a_buffer = 0;
8364
8365                         while (gl.isBuffer(++not_a_buffer))
8366                                 ;
8367                         GLU_EXPECT_NO_ERROR(gl.getError(), "glIsBuffer has failed");
8368
8369                         gl.textureBufferRange(texture_buffer, GL_RGBA8, not_a_buffer, 0, data_size);
8370
8371                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureBufferRange",
8372                                                                           "buffer is not zero and is not the name of an existing buffer object.");
8373                 }
8374
8375                 /* Check that INVALID_VALUE is generated by TextureBufferRange if offset
8376                  is negative, if size is less than or equal to zero, or if offset + size
8377                  is greater than the value of BUFFER_SIZE for buffer. */
8378                 {
8379                         gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, -1, data_size);
8380
8381                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureBufferRange", "offset is negative.");
8382
8383                         gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, 0, 0);
8384
8385                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureBufferRange", "size is zero.");
8386
8387                         gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, 0, -1);
8388
8389                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureBufferRange", "size is negative.");
8390
8391                         gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, 0, data_size * 16);
8392
8393                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureBufferRange",
8394                                                                           "size is greater than the value of BUFFER_SIZE for buffer.");
8395                 }
8396
8397                 /* Check that INVALID_VALUE is generated by TextureBufferRange if offset is
8398                  not an integer multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT. */
8399                 {
8400                         glw::GLint gl_texture_buffer_offset_alignment = 0;
8401
8402                         gl.getIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, &gl_texture_buffer_offset_alignment);
8403
8404                         /* If alignmet is 1 we cannot do anything. Error situtation is impossible then. */
8405                         if (gl_texture_buffer_offset_alignment > 1)
8406                         {
8407                                 gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, 1, data_size - 1);
8408
8409                                 is_ok &= CheckErrorAndLog(
8410                                         m_context, GL_INVALID_VALUE, "glTextureBufferRange",
8411                                         "offset is not an integer multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT.");
8412                         }
8413                 }
8414         }
8415         catch (...)
8416         {
8417                 is_ok   = false;
8418                 is_error = true;
8419         }
8420
8421         /* Cleanup. */
8422         if (texture_1D)
8423         {
8424                 gl.deleteTextures(1, &texture_1D);
8425         }
8426
8427         if (texture_buffer)
8428         {
8429                 gl.deleteTextures(1, &texture_buffer);
8430         }
8431
8432         if (buffer)
8433         {
8434                 gl.deleteBuffers(1, &buffer);
8435         }
8436
8437         /* Errors clean up. */
8438         while (gl.getError())
8439                 ;
8440
8441         /* Result's setup. */
8442         if (is_ok)
8443         {
8444                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
8445         }
8446         else
8447         {
8448                 if (is_error)
8449                 {
8450                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
8451                 }
8452                 else
8453                 {
8454                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
8455                 }
8456         }
8457
8458         return STOP;
8459 }
8460
8461 /******************************** Texture Storage Errors Test Implementation   ********************************/
8462
8463 /** @brief Texture Storage Errors Test constructor.
8464  *
8465  *  @param [in] context     OpenGL context.
8466  */
8467 StorageErrorsTest::StorageErrorsTest(deqp::Context& context)
8468         : deqp::TestCase(context, "textures_storage_errors", "Texture Storage Errors Test")
8469         , m_to_1D(0)
8470         , m_to_1D_array(0)
8471         , m_to_2D(0)
8472         , m_to_2D_array(0)
8473         , m_to_3D(0)
8474         , m_to_2D_ms(0)
8475         , m_to_2D_ms_immutable(0)
8476         , m_to_3D_ms(0)
8477         , m_to_3D_ms_immutable(0)
8478         , m_to_invalid(0)
8479         , m_internalformat_invalid(0)
8480         , m_max_texture_size(1)
8481         , m_max_samples(1)
8482         , m_max_array_texture_layers(1)
8483 {
8484         /* Intentionally left blank. */
8485 }
8486
8487 /** @brief Iterate Texture Storage Errors Test cases.
8488  *
8489  *  @return Iteration result.
8490  */
8491 tcu::TestNode::IterateResult StorageErrorsTest::iterate()
8492 {
8493         /* Get context setup. */
8494         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
8495         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
8496
8497         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
8498         {
8499                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
8500
8501                 return STOP;
8502         }
8503
8504         /* Running tests. */
8505         bool is_ok      = true;
8506         bool is_error = false;
8507
8508         try
8509         {
8510                 Prepare();
8511
8512                 is_ok &= Test1D();
8513                 is_ok &= Test2D();
8514                 is_ok &= Test3D();
8515                 is_ok &= Test2DMultisample();
8516                 is_ok &= Test3DMultisample();
8517         }
8518         catch (...)
8519         {
8520                 is_ok   = false;
8521                 is_error = true;
8522         }
8523
8524         /* Cleanup. */
8525         Clean();
8526
8527         /* Result's setup. */
8528         if (is_ok)
8529         {
8530                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
8531         }
8532         else
8533         {
8534                 if (is_error)
8535                 {
8536                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
8537                 }
8538                 else
8539                 {
8540                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
8541                 }
8542         }
8543
8544         return STOP;
8545 }
8546
8547 /** @brief Prepare test objects.
8548  */
8549 void StorageErrorsTest::Prepare()
8550 {
8551         /* Shortcut for GL functionality. */
8552         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8553
8554         /* Auxiliary objects setup. */
8555
8556         /* 1D */
8557         gl.createTextures(GL_TEXTURE_1D, 1, &m_to_1D);
8558         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8559
8560         /* 1D ARRAY */
8561         gl.createTextures(GL_TEXTURE_1D_ARRAY, 1, &m_to_1D_array);
8562         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8563
8564         /* 2D */
8565         gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D);
8566         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8567
8568         /* 2D ARRAY */
8569         gl.createTextures(GL_TEXTURE_2D_ARRAY, 1, &m_to_2D_array);
8570         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8571
8572         /* 3D */
8573         gl.createTextures(GL_TEXTURE_3D, 1, &m_to_3D);
8574         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8575
8576         /* 2D Multisample */
8577         gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &m_to_2D_ms);
8578         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8579
8580         /* 2D Multisample with storage */
8581         gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &m_to_2D_ms_immutable);
8582         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8583
8584         gl.textureStorage2DMultisample(m_to_2D_ms_immutable, 1, GL_R8, 16, 16, false);
8585         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2DMultisample has failed");
8586
8587         /* 3D Multisample */
8588         gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 1, &m_to_3D_ms);
8589         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8590
8591         /* 3D Multisample with storage */
8592         gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 1, &m_to_3D_ms_immutable);
8593         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8594
8595         gl.textureStorage3DMultisample(m_to_3D_ms_immutable, 1, GL_R8, 16, 16, 16, false);
8596         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2DMultisample has failed");
8597
8598         /* Invalid values */
8599
8600         /* invalid texture object */
8601         while (gl.isTexture(++m_to_invalid))
8602                 ;
8603         GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed");
8604
8605         /* invalid internal format */
8606         static const glw::GLenum all_internal_formats[] = { GL_R8,
8607                                                                                                                 GL_R8_SNORM,
8608                                                                                                                 GL_R16,
8609                                                                                                                 GL_R16_SNORM,
8610                                                                                                                 GL_RG8,
8611                                                                                                                 GL_RG8_SNORM,
8612                                                                                                                 GL_RG16,
8613                                                                                                                 GL_RG16_SNORM,
8614                                                                                                                 GL_R3_G3_B2,
8615                                                                                                                 GL_RGB4,
8616                                                                                                                 GL_RGB5,
8617                                                                                                                 GL_RGB565,
8618                                                                                                                 GL_RGB8,
8619                                                                                                                 GL_RGB8_SNORM,
8620                                                                                                                 GL_RGB10,
8621                                                                                                                 GL_RGB12,
8622                                                                                                                 GL_RGB16,
8623                                                                                                                 GL_RGB16_SNORM,
8624                                                                                                                 GL_RGBA2,
8625                                                                                                                 GL_RGBA4,
8626                                                                                                                 GL_RGB5_A1,
8627                                                                                                                 GL_RGBA8,
8628                                                                                                                 GL_RGBA8_SNORM,
8629                                                                                                                 GL_RGB10_A2,
8630                                                                                                                 GL_RGB10_A2UI,
8631                                                                                                                 GL_RGBA12,
8632                                                                                                                 GL_RGBA16,
8633                                                                                                                 GL_RGBA16_SNORM,
8634                                                                                                                 GL_SRGB8,
8635                                                                                                                 GL_SRGB8_ALPHA8,
8636                                                                                                                 GL_R16F,
8637                                                                                                                 GL_RG16F,
8638                                                                                                                 GL_RGB16F,
8639                                                                                                                 GL_RGBA16F,
8640                                                                                                                 GL_R32F,
8641                                                                                                                 GL_RG32F,
8642                                                                                                                 GL_RGB32F,
8643                                                                                                                 GL_RGBA32F,
8644                                                                                                                 GL_R11F_G11F_B10F,
8645                                                                                                                 GL_RGB9_E5,
8646                                                                                                                 GL_R8I,
8647                                                                                                                 GL_R8UI,
8648                                                                                                                 GL_R16I,
8649                                                                                                                 GL_R16UI,
8650                                                                                                                 GL_R32I,
8651                                                                                                                 GL_R32UI,
8652                                                                                                                 GL_RG8I,
8653                                                                                                                 GL_RG8UI,
8654                                                                                                                 GL_RG16I,
8655                                                                                                                 GL_RG16UI,
8656                                                                                                                 GL_RG32I,
8657                                                                                                                 GL_RG32UI,
8658                                                                                                                 GL_RGB8I,
8659                                                                                                                 GL_RGB8UI,
8660                                                                                                                 GL_RGB16I,
8661                                                                                                                 GL_RGB16UI,
8662                                                                                                                 GL_RGB32I,
8663                                                                                                                 GL_RGB32UI,
8664                                                                                                                 GL_RGBA8I,
8665                                                                                                                 GL_RGBA8UI,
8666                                                                                                                 GL_RGBA16I,
8667                                                                                                                 GL_RGBA16UI,
8668                                                                                                                 GL_RGBA32I,
8669                                                                                                                 GL_RGBA32UI,
8670                                                                                                                 GL_COMPRESSED_RED,
8671                                                                                                                 GL_COMPRESSED_RG,
8672                                                                                                                 GL_COMPRESSED_RGB,
8673                                                                                                                 GL_COMPRESSED_RGBA,
8674                                                                                                                 GL_COMPRESSED_SRGB,
8675                                                                                                                 GL_COMPRESSED_SRGB_ALPHA,
8676                                                                                                                 GL_COMPRESSED_RED_RGTC1,
8677                                                                                                                 GL_COMPRESSED_SIGNED_RED_RGTC1,
8678                                                                                                                 GL_COMPRESSED_RG_RGTC2,
8679                                                                                                                 GL_COMPRESSED_SIGNED_RG_RGTC2,
8680                                                                                                                 GL_COMPRESSED_RGBA_BPTC_UNORM,
8681                                                                                                                 GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM,
8682                                                                                                                 GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT,
8683                                                                                                                 GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT,
8684                                                                                                                 GL_COMPRESSED_RGB8_ETC2,
8685                                                                                                                 GL_COMPRESSED_SRGB8_ETC2,
8686                                                                                                                 GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
8687                                                                                                                 GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
8688                                                                                                                 GL_COMPRESSED_RGBA8_ETC2_EAC,
8689                                                                                                                 GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
8690                                                                                                                 GL_COMPRESSED_R11_EAC,
8691                                                                                                                 GL_COMPRESSED_SIGNED_R11_EAC,
8692                                                                                                                 GL_COMPRESSED_RG11_EAC,
8693                                                                                                                 GL_COMPRESSED_SIGNED_RG11_EAC,
8694                                                                                                                 GL_DEPTH_COMPONENT16,
8695                                                                                                                 GL_DEPTH_COMPONENT24,
8696                                                                                                                 GL_DEPTH_COMPONENT32,
8697                                                                                                                 GL_DEPTH_COMPONENT32F,
8698                                                                                                                 GL_DEPTH24_STENCIL8,
8699                                                                                                                 GL_DEPTH32F_STENCIL8,
8700                                                                                                                 GL_STENCIL_INDEX1,
8701                                                                                                                 GL_STENCIL_INDEX4,
8702                                                                                                                 GL_STENCIL_INDEX8,
8703                                                                                                                 GL_STENCIL_INDEX16 };
8704
8705         static const glw::GLuint all_internal_formats_count =
8706                 sizeof(all_internal_formats) / sizeof(all_internal_formats[0]);
8707
8708         bool is_valid                    = true;
8709         m_internalformat_invalid = 0;
8710
8711         while (is_valid)
8712         {
8713                 is_valid = false;
8714                 m_internalformat_invalid++;
8715                 for (glw::GLuint i = 0; i < all_internal_formats_count; ++i)
8716                 {
8717                         if (all_internal_formats[i] == m_internalformat_invalid)
8718                         {
8719                                 is_valid = true;
8720                                 break;
8721                         }
8722                 }
8723         }
8724
8725         /* Maximum texture size.*/
8726         gl.getIntegerv(GL_MAX_TEXTURE_SIZE, &m_max_texture_size);
8727         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
8728
8729         /* Maximum number of samples. */
8730         gl.getIntegerv(GL_MAX_SAMPLES, &m_max_samples);
8731         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
8732
8733         /* Maximum number of array texture layers. */
8734         gl.getIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &m_max_array_texture_layers);
8735         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
8736 }
8737
8738 /** @brief Test TextureStorage1D
8739  *
8740  *  @return Test result.
8741  */
8742 bool StorageErrorsTest::Test1D()
8743 {
8744         /* Shortcut for GL functionality. */
8745         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8746
8747         /* Result. */
8748         bool is_ok = true;
8749
8750         /*  Check that INVALID_OPERATION is generated by TextureStorage1D if texture
8751          is not the name of an existing texture object. */
8752         {
8753                 gl.textureStorage1D(m_to_invalid, 1, GL_R8, 8);
8754                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage1D",
8755                                                                   "texture is not the name of an existing texture object.");
8756         }
8757
8758         /*  Check that INVALID_ENUM is generated by TextureStorage1D if
8759          internalformat is not a valid sized internal format. */
8760         {
8761                 gl.textureStorage1D(m_to_1D, 1, m_internalformat_invalid, 8);
8762                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureStorage1D",
8763                                                                   "internalformat is not a valid sized internal format.");
8764         }
8765
8766         /*  Check that INVALID_ENUM is generated by TextureStorage1D if target or
8767          the effective target of texture is not one of the accepted targets
8768          described above. */
8769         {
8770                 gl.textureStorage1D(m_to_2D, 1, GL_R8, 8);
8771                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage1D",
8772                                                                   "the effective target of texture is not one of the accepted targets.");
8773         }
8774
8775         /*  Check that INVALID_VALUE is generated by TextureStorage1D if width or
8776          levels are less than 1. */
8777         {
8778                 gl.textureStorage1D(m_to_1D, 0, GL_R8, 8);
8779                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage1D", "levels is less than 1.");
8780
8781                 gl.textureStorage1D(m_to_1D, 1, GL_R8, 0);
8782                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage1D", "width is less than 1.");
8783         }
8784
8785         /*  Check that INVALID_OPERATION is generated by TextureStorage1D if levels
8786          is greater than log2(width)+1. */
8787         {
8788                 gl.textureStorage1D(m_to_1D, 8, GL_R8, 8);
8789                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage1D",
8790                                                                   "levels is greater than log2(width)+1.");
8791         }
8792
8793         return is_ok;
8794 }
8795
8796 /** @brief Test TextureStorage2D
8797  *
8798  *  @return Test result.
8799  */
8800 bool StorageErrorsTest::Test2D()
8801 {
8802         /* Shortcut for GL functionality. */
8803         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8804
8805         /* Result. */
8806         bool is_ok = true;
8807
8808         /*  Check that INVALID_OPERATION is generated by TextureStorage2D if
8809          texture is not the name of an existing texture object. */
8810         {
8811                 gl.textureStorage2D(m_to_invalid, 1, GL_R8, 8, 8);
8812                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2D",
8813                                                                   "texture is not the name of an existing texture object.");
8814         }
8815
8816         /*  Check that INVALID_ENUM is generated by TextureStorage2D if
8817          internalformat is not a valid sized internal format. */
8818         {
8819                 gl.textureStorage2D(m_to_2D, 1, m_internalformat_invalid, 8, 8);
8820                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureStorage2D",
8821                                                                   "internalformat is not a valid sized internal format.");
8822         }
8823
8824         /*  Check that INVALID_ENUM is generated by TextureStorage2D if target or
8825          the effective target of texture is not one of the accepted targets
8826          described above. */
8827         {
8828                 gl.textureStorage2D(m_to_1D, 1, GL_R8, 8, 8);
8829                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2D",
8830                                                                   "the effective target of texture is not one of the accepted targets.");
8831         }
8832
8833         /*  Check that INVALID_VALUE is generated by TextureStorage2D if width,
8834          height or levels are less than 1. */
8835         {
8836                 gl.textureStorage2D(m_to_2D, 0, GL_R8, 8, 8);
8837                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2D", "levels is less than 1.");
8838
8839                 gl.textureStorage2D(m_to_2D, 1, GL_R8, 0, 8);
8840                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2D", "width is less than 1.");
8841
8842                 gl.textureStorage2D(m_to_2D, 1, GL_R8, 8, 0);
8843                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2D", "height is less than 1.");
8844         }
8845
8846         /* Check that INVALID_OPERATION is generated by TextureStorage2D if target
8847          is TEXTURE_1D_ARRAY or PROXY_TEXTURE_1D_ARRAY and levels is greater than
8848          log2(width)+1. */
8849         {
8850                 gl.textureStorage2D(m_to_1D_array, 8, GL_R8, 8, 8);
8851                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2D",
8852                                                                   "target is TEXTURE_1D_ARRAY and levels is greater than log2(width)+1.");
8853         }
8854
8855         /*  Check that INVALID_OPERATION is generated by TextureStorage2D if target
8856          is not TEXTURE_1D_ARRAY or PROXY_TEXTURE_1D_ARRAY and levels is greater
8857          than log2(max(width, height))+1.  */
8858         {
8859                 gl.textureStorage2D(m_to_2D, 8, GL_R8, 8, 8);
8860                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2D",
8861                                                                   "target is TEXTURE_2D and levels is greater than log2(max(width, height))+1.");
8862         }
8863
8864         return is_ok;
8865 }
8866
8867 /** @brief Test TextureStorage3D
8868  *
8869  *  @return Test result.
8870  */
8871 bool StorageErrorsTest::Test3D()
8872 {
8873         /* Shortcut for GL functionality. */
8874         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8875
8876         /* Result. */
8877         bool is_ok = true;
8878
8879         /*  Check that INVALID_OPERATION is generated by TextureStorage3D if texture
8880          is not the name of an existing texture object. */
8881         {
8882                 gl.textureStorage3D(m_to_invalid, 1, GL_R8, 8, 8, 8);
8883                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3D",
8884                                                                   "texture is not the name of an existing texture object.");
8885         }
8886
8887         /*  Check that INVALID_ENUM is generated by TextureStorage3D if
8888          internalformat is not a valid sized internal format. */
8889         {
8890                 gl.textureStorage3D(m_to_3D, 1, m_internalformat_invalid, 8, 8, 8);
8891                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureStorage3D",
8892                                                                   "internalformat is not a valid sized internal format.");
8893         }
8894
8895         /*  Check that INVALID_ENUM is generated by TextureStorage3D if target or
8896          the effective target of texture is not one of the accepted targets
8897          described above. */
8898         {
8899                 gl.textureStorage3D(m_to_1D, 1, GL_R8, 8, 8, 8);
8900                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3D",
8901                                                                   "the effective target of texture is not one of the accepted targets.");
8902         }
8903
8904         /*  Check that INVALID_VALUE is generated by TextureStorage3D if width,
8905          height, depth or levels are less than 1. */
8906         {
8907                 gl.textureStorage3D(m_to_3D, 0, GL_R8, 8, 8, 8);
8908                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3D", "levels is less than 1.");
8909
8910                 gl.textureStorage3D(m_to_3D, 1, GL_R8, 0, 8, 8);
8911                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3D", "width is less than 1.");
8912
8913                 gl.textureStorage3D(m_to_3D, 1, GL_R8, 8, 0, 8);
8914                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3D", "height is less than 1.");
8915
8916                 gl.textureStorage3D(m_to_3D, 1, GL_R8, 8, 8, 0);
8917                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3D", "depth is less than 1.");
8918         }
8919
8920         /* Check that INVALID_OPERATION is generated by TextureStorage3D if target
8921          is TEXTURE_3D or PROXY_TEXTURE_3D and levels is greater than
8922          log2(max(width, height, depth))+1. */
8923         {
8924                 gl.textureStorage3D(m_to_3D, 8, GL_R8, 8, 8, 8);
8925                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3D",
8926                                                                   "target is TEXTURE_3D and levels is greater than log2(max(width, height, depth))+1.");
8927         }
8928
8929         /*  Check that INVALID_OPERATION is generated by TextureStorage3D if target
8930          is TEXTURE_2D_ARRAY, PROXY_TEXTURE_2D_ARRAY, TEXURE_CUBE_ARRAY,
8931          or PROXY_TEXTURE_CUBE_MAP_ARRAY and levels is greater than
8932          log2(max(width, height))+1.  */
8933         {
8934                 gl.textureStorage3D(m_to_2D_array, 6, GL_R8, 8, 8, 256);
8935                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3D",
8936                                                                   "target is TEXTURE_2D_ARRAY and levels is greater than log2(max(width, height))+1.");
8937         }
8938
8939         return is_ok;
8940 }
8941
8942 /** @brief Test TextureStorage2DMultisample
8943  *
8944  *  @return Test result.
8945  */
8946 bool StorageErrorsTest::Test2DMultisample()
8947 {
8948         /* Shortcut for GL functionality. */
8949         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8950
8951         /* Result. */
8952         bool is_ok = true;
8953
8954         /*  Check that INVALID_OPERATION is generated by TextureStorage2DMultisample
8955          if texture is not the name of an existing texture object. */
8956         {
8957                 gl.textureStorage2DMultisample(m_to_invalid, 1, GL_R8, 8, 8, false);
8958                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2DMultisample",
8959                                                                   "texture is not the name of an existing texture object.");
8960         }
8961
8962         /*  Check that INVALID_ENUM is generated by TextureStorage2DMultisample if
8963          internalformat is not a valid color-renderable, depth-renderable or
8964          stencil-renderable format. */
8965         {
8966                 gl.textureStorage2DMultisample(m_to_2D_ms, 1, m_internalformat_invalid, 8, 8, false);
8967                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureStorage2DMultisample",
8968                                                                   "internalformat is not a valid sized internal format.");
8969         }
8970
8971         /*  Check that INVALID_OPERATION is generated by TextureStorage2DMultisample if
8972          target or the effective target of texture is not one of the accepted
8973          targets described above. */
8974         {
8975                 gl.textureStorage2DMultisample(m_to_1D, 1, GL_R8, 8, 8, false);
8976                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2DMultisample",
8977                                                                   "the effective target of texture is not one of the accepted targets.");
8978         }
8979
8980         /* Check that INVALID_VALUE is generated by TextureStorage2DMultisample if
8981          width or height are less than 1 or greater than the value of
8982          MAX_TEXTURE_SIZE. */
8983         {
8984                 gl.textureStorage2DMultisample(m_to_2D_ms, 1, GL_R8, 0, 8, false);
8985                 is_ok &=
8986                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2DMultisample", "width is less than 1.");
8987
8988                 gl.textureStorage2DMultisample(m_to_2D_ms, 1, GL_R8, 8, 0, false);
8989                 is_ok &=
8990                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2DMultisample", "height is less than 1.");
8991
8992                 gl.textureStorage2DMultisample(m_to_2D_ms, 1, GL_R8, m_max_texture_size * 2, 8, false);
8993                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2DMultisample",
8994                                                                   "width is greater than the value of MAX_TEXTURE_SIZE.");
8995
8996                 gl.textureStorage2DMultisample(m_to_2D_ms, 1, GL_R8, 8, m_max_texture_size * 2, false);
8997                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2DMultisample",
8998                                                                   "height is greater than the value of MAX_TEXTURE_SIZE.");
8999         }
9000
9001         /* Check that INVALID_OPERATION is generated by TextureStorage2DMultisample if
9002          samples is greater than the value of MAX_SAMPLES. */
9003         {
9004                 gl.textureStorage2DMultisample(m_to_2D_ms, m_max_samples * 2, GL_R8, 8, 8, false);
9005                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2DMultisample",
9006                                                                   "samples is greater than the value of MAX_SAMPLES.");
9007         }
9008
9009         /* Check that INVALID_OPERATION is generated by TextureStorage2DMultisample
9010          if the value of TEXTURE_IMMUTABLE_FORMAT for the texture bound to target
9011          is not FALSE. */
9012         {
9013                 gl.textureStorage2DMultisample(m_to_2D_ms_immutable, 1, GL_R8, 8, 8, false);
9014                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2DMultisample",
9015                                                                   "samples is greater than the value of MAX_SAMPLES.");
9016         }
9017
9018         return is_ok;
9019 }
9020
9021 /** @brief Test TextureStorage3DMultisample
9022  *
9023  *  @return Test result.
9024  */
9025 bool StorageErrorsTest::Test3DMultisample()
9026 {
9027         /* Shortcut for GL functionality. */
9028         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
9029
9030         /* Result. */
9031         bool is_ok = true;
9032
9033         /*  Check that INVALID_OPERATION is generated by TextureStorage3DMultisample
9034          if texture is not the name of an existing texture object. */
9035         {
9036                 gl.textureStorage3DMultisample(m_to_invalid, 1, GL_R8, 8, 8, 8, false);
9037                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3DMultisample",
9038                                                                   "texture is not the name of an existing texture object.");
9039         }
9040
9041         /*  Check that INVALID_ENUM is generated by TextureStorage3DMultisample if
9042          internalformat is not a valid color-renderable, depth-renderable or
9043          stencil-renderable format. */
9044         {
9045                 gl.textureStorage3DMultisample(m_to_3D_ms, 1, m_internalformat_invalid, 8, 8, 8, false);
9046                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureStorage3DMultisample",
9047                                                                   "internalformat is not a valid sized internal format.");
9048         }
9049
9050         /*  Check that INVALID_OPERATION is generated by TextureStorage3DMultisample if
9051          target or the effective target of texture is not one of the accepted
9052          targets described above. */
9053         {
9054                 gl.textureStorage3DMultisample(m_to_1D, 1, GL_R8, 8, 8, 8, false);
9055                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3DMultisample",
9056                                                                   "the effective target of texture is not one of the accepted targets.");
9057         }
9058
9059         /* Check that INVALID_VALUE is generated by TextureStorage3DMultisample if
9060          width or height are less than 1 or greater than the value of
9061          MAX_TEXTURE_SIZE. */
9062         {
9063                 gl.textureStorage3DMultisample(m_to_3D_ms, 1, GL_R8, 0, 8, 8, false);
9064                 is_ok &=
9065                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3DMultisample", "width is less than 1.");
9066
9067                 gl.textureStorage3DMultisample(m_to_3D_ms, 1, GL_R8, 8, 0, 8, false);
9068                 is_ok &=
9069                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3DMultisample", "height is less than 1.");
9070
9071                 gl.textureStorage3DMultisample(m_to_3D_ms, 1, GL_R8, m_max_texture_size * 2, 8, 8, false);
9072                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3DMultisample",
9073                                                                   "width is greater than the value of MAX_TEXTURE_SIZE.");
9074
9075                 gl.textureStorage3DMultisample(m_to_3D_ms, 1, GL_R8, 8, m_max_texture_size * 2, 8, false);
9076                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3DMultisample",
9077                                                                   "height is greater than the value of MAX_TEXTURE_SIZE.");
9078         }
9079
9080         /* Check that INVALID_VALUE is generated by TextureStorage3DMultisample if
9081          depth is less than 1 or greater than the value of
9082          MAX_ARRAY_TEXTURE_LAYERS. */
9083         {
9084                 gl.textureStorage3DMultisample(m_to_3D_ms, 1, GL_R8, 8, 8, 0, false);
9085                 is_ok &=
9086                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3DMultisample", "depth is less than 1.");
9087
9088                 gl.textureStorage3DMultisample(m_to_3D_ms, 1, GL_R8, 8, 8, m_max_array_texture_layers * 2, false);
9089                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3DMultisample",
9090                                                                   "depth is greater than the value of MAX_ARRAY_TEXTURE_LAYERS.");
9091         }
9092
9093         /* Check that INVALID_VALUE is generated by TextureStorage3DMultisample if
9094          samples is greater than the value of MAX_SAMPLES. */
9095         {
9096                 gl.textureStorage3DMultisample(m_to_3D_ms, m_max_samples * 2, GL_R8, 8, 8, 8, false);
9097                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3DMultisample",
9098                                                                   "samples is greater than the value of MAX_SAMPLES.");
9099         }
9100
9101         /* Check that INVALID_OPERATION is generated by TextureStorage3DMultisample
9102          if the value of TEXTURE_IMMUTABLE_FORMAT for the texture bound to target
9103          is not FALSE. */
9104         {
9105                 gl.textureStorage3DMultisample(m_to_3D_ms_immutable, 1, GL_R8, 8, 8, 8, false);
9106                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3DMultisample",
9107                                                                   "samples is greater than the value of MAX_SAMPLES.");
9108         }
9109
9110         return is_ok;
9111 }
9112
9113 /** @brief Clean GL objects, test variables and GL errors.
9114  */
9115 void StorageErrorsTest::Clean()
9116 {
9117         /* Shortcut for GL functionality. */
9118         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
9119
9120         /* Cleanup. */
9121         if (m_to_1D)
9122         {
9123                 gl.deleteTextures(1, &m_to_1D);
9124
9125                 m_to_1D = 0;
9126         }
9127
9128         if (m_to_1D_array)
9129         {
9130                 gl.deleteTextures(1, &m_to_1D_array);
9131
9132                 m_to_1D_array = 0;
9133         }
9134
9135         if (m_to_2D)
9136         {
9137                 gl.deleteTextures(1, &m_to_2D);
9138
9139                 m_to_2D = 0;
9140         }
9141
9142         if (m_to_2D_array)
9143         {
9144                 gl.deleteTextures(1, &m_to_2D_array);
9145
9146                 m_to_2D_array = 0;
9147         }
9148
9149         if (m_to_3D)
9150         {
9151                 gl.deleteTextures(1, &m_to_3D);
9152
9153                 m_to_3D = 0;
9154         }
9155
9156         if (m_to_2D_ms)
9157         {
9158                 gl.deleteTextures(1, &m_to_2D_ms);
9159
9160                 m_to_2D_ms = 0;
9161         }
9162
9163         if (m_to_2D_ms_immutable)
9164         {
9165                 gl.deleteTextures(1, &m_to_2D_ms_immutable);
9166
9167                 m_to_2D_ms_immutable = 0;
9168         }
9169
9170         if (m_to_3D_ms)
9171         {
9172                 gl.deleteTextures(1, &m_to_3D_ms);
9173
9174                 m_to_3D_ms = 0;
9175         }
9176
9177         if (m_to_3D_ms_immutable)
9178         {
9179                 gl.deleteTextures(1, &m_to_3D_ms_immutable);
9180
9181                 m_to_3D_ms_immutable = 0;
9182         }
9183
9184         m_to_invalid                       = 0;
9185         m_internalformat_invalid   = 0;
9186         m_max_texture_size                 = 1;
9187         m_max_samples                      = 1;
9188         m_max_array_texture_layers = 1;
9189
9190         while (GL_NO_ERROR != gl.getError())
9191                 ;
9192 }
9193
9194 /******************************** Texture SubImage Errors Test Implementation   ********************************/
9195
9196 /** @brief Texture SubImage Errors Test constructor.
9197  *
9198  *  @param [in] context     OpenGL context.
9199  */
9200 SubImageErrorsTest::SubImageErrorsTest(deqp::Context& context)
9201         : deqp::TestCase(context, "textures_subimage_errors", "Texture SubImage Errors Test")
9202         , m_to_1D_empty(0)
9203         , m_to_2D_empty(0)
9204         , m_to_3D_empty(0)
9205         , m_to_1D(0)
9206         , m_to_2D(0)
9207         , m_to_3D(0)
9208         , m_to_1D_compressed(0)
9209         , m_to_2D_compressed(0)
9210         , m_to_3D_compressed(0)
9211         , m_to_rectangle_compressed(0)
9212         , m_to_invalid(0)
9213         , m_bo(0)
9214         , m_format_invalid(0)
9215         , m_type_invalid(0)
9216         , m_max_texture_size(1)
9217         , m_reference_compressed_1D(DE_NULL)
9218         , m_reference_compressed_2D(DE_NULL)
9219         , m_reference_compressed_3D(DE_NULL)
9220         , m_reference_compressed_rectangle(DE_NULL)
9221         , m_reference_compressed_1D_size(0)
9222         , m_reference_compressed_2D_size(0)
9223         , m_reference_compressed_3D_size(0)
9224         , m_reference_compressed_rectangle_size(0)
9225         , m_reference_compressed_1D_format(0)
9226         , m_reference_compressed_2D_format(0)
9227         , m_reference_compressed_3D_format(0)
9228         , m_reference_compressed_rectangle_format(0)
9229         , m_not_matching_compressed_1D_format(0)
9230         , m_not_matching_compressed_1D_size(0)
9231         , m_not_matching_compressed_2D_format(0)
9232         , m_not_matching_compressed_2D_size(0)
9233         , m_not_matching_compressed_3D_format(0)
9234         , m_not_matching_compressed_3D_size(0)
9235 {
9236         /* Intentionally left blank. */
9237 }
9238
9239 /** @brief Iterate Texture SubImage Errors Test cases.
9240  *
9241  *  @return Iteration result.
9242  */
9243 tcu::TestNode::IterateResult SubImageErrorsTest::iterate()
9244 {
9245         /* Get context setup. */
9246         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
9247         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
9248
9249         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
9250         {
9251                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
9252
9253                 return STOP;
9254         }
9255
9256         /* Running tests. */
9257         bool is_ok      = true;
9258         bool is_error = false;
9259
9260         try
9261         {
9262                 Prepare();
9263
9264                 is_ok &= Test1D();
9265                 is_ok &= Test2D();
9266                 is_ok &= Test3D();
9267                 is_ok &= Test1DCompressed();
9268                 is_ok &= Test2DCompressed();
9269                 is_ok &= Test3DCompressed();
9270         }
9271         catch (...)
9272         {
9273                 is_ok   = false;
9274                 is_error = true;
9275         }
9276
9277         /* Cleanup. */
9278         Clean();
9279
9280         /* Result's setup. */
9281         if (is_ok)
9282         {
9283                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
9284         }
9285         else
9286         {
9287                 if (is_error)
9288                 {
9289                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
9290                 }
9291                 else
9292                 {
9293                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
9294                 }
9295         }
9296
9297         return STOP;
9298 }
9299
9300 /** @brief Prepare test's objects.
9301  */
9302 void SubImageErrorsTest::Prepare()
9303 {
9304         /* Shortcut for GL functionality. */
9305         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
9306
9307         /* Auxiliary objects setup. */
9308
9309         /* 1D */
9310         gl.createTextures(GL_TEXTURE_1D, 1, &m_to_1D_empty);
9311         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9312
9313         /* 2D */
9314         gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D_empty);
9315         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9316
9317         /* 3D */
9318         gl.createTextures(GL_TEXTURE_3D, 1, &m_to_3D_empty);
9319         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9320
9321         /* 1D */
9322         gl.createTextures(GL_TEXTURE_1D, 1, &m_to_1D);
9323         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9324
9325         gl.bindTexture(GL_TEXTURE_1D, m_to_1D);
9326         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9327
9328         gl.texImage1D(GL_TEXTURE_1D, 0, s_reference_internalformat, s_reference_width, 0, s_reference_format,
9329                                   GL_UNSIGNED_BYTE, s_reference);
9330         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
9331
9332         /* 2D */
9333         gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D);
9334         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9335
9336         gl.bindTexture(GL_TEXTURE_2D, m_to_2D);
9337         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9338
9339         gl.texImage2D(GL_TEXTURE_2D, 0, s_reference_internalformat, s_reference_width, s_reference_height, 0,
9340                                   s_reference_format, GL_UNSIGNED_BYTE, s_reference);
9341         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
9342
9343         /* 3D */
9344         gl.createTextures(GL_TEXTURE_3D, 1, &m_to_3D);
9345         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9346
9347         gl.bindTexture(GL_TEXTURE_3D, m_to_3D);
9348         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9349
9350         gl.texImage3D(GL_TEXTURE_3D, 0, s_reference_internalformat, s_reference_width, s_reference_height,
9351                                   s_reference_depth, 0, s_reference_format, GL_UNSIGNED_BYTE, s_reference);
9352         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
9353
9354         /* 1D Compressed */
9355         gl.createTextures(GL_TEXTURE_1D, 1, &m_to_1D_compressed);
9356         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9357
9358         gl.bindTexture(GL_TEXTURE_1D, m_to_1D_compressed);
9359         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9360
9361         gl.texImage1D(GL_TEXTURE_1D, 0, s_reference_internalformat_compressed, s_reference_width, 0, s_reference_format,
9362                                   GL_UNSIGNED_BYTE, s_reference);
9363         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
9364
9365         glw::GLint is_compressed = 0;
9366
9367         gl.getTexLevelParameteriv(GL_TEXTURE_1D, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9368         GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9369
9370         if (is_compressed)
9371         {
9372                 gl.getTexLevelParameteriv(GL_TEXTURE_1D, 0, GL_TEXTURE_INTERNAL_FORMAT, &m_reference_compressed_1D_format);
9373                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9374
9375                 m_reference_compressed_1D_size = 0;
9376
9377                 gl.getTexLevelParameteriv(GL_TEXTURE_1D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &m_reference_compressed_1D_size);
9378                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9379
9380                 if (m_reference_compressed_1D_size)
9381                 {
9382                         m_reference_compressed_1D = new glw::GLubyte[m_reference_compressed_1D_size];
9383
9384                         gl.getCompressedTexImage(GL_TEXTURE_1D, 0, m_reference_compressed_1D);
9385                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
9386                 }
9387         }
9388
9389         /* 2D Compressed */
9390         gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D_compressed);
9391         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9392
9393         gl.bindTexture(GL_TEXTURE_2D, m_to_2D_compressed);
9394         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9395
9396         gl.texImage2D(GL_TEXTURE_2D, 0, s_reference_internalformat_compressed, s_reference_width, s_reference_height, 0,
9397                                   s_reference_format, GL_UNSIGNED_BYTE, s_reference);
9398         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
9399
9400         is_compressed = 0;
9401
9402         gl.getTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9403         GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9404
9405         if (is_compressed)
9406         {
9407                 gl.getTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &m_reference_compressed_2D_format);
9408                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9409
9410                 m_reference_compressed_2D_size = 0;
9411
9412                 gl.getTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &m_reference_compressed_2D_size);
9413                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9414
9415                 if (m_reference_compressed_2D_size)
9416                 {
9417                         m_reference_compressed_2D = new glw::GLubyte[m_reference_compressed_2D_size];
9418
9419                         gl.getCompressedTexImage(GL_TEXTURE_2D, 0, m_reference_compressed_2D);
9420                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
9421                 }
9422         }
9423
9424         /* 3D Compressed */
9425         gl.createTextures(GL_TEXTURE_2D_ARRAY, 1, &m_to_3D_compressed);
9426         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9427
9428         gl.bindTexture(GL_TEXTURE_2D_ARRAY, m_to_3D_compressed);
9429         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9430
9431         gl.texImage3D(GL_TEXTURE_2D_ARRAY, 0, s_reference_internalformat_compressed, s_reference_width, s_reference_height,
9432                                   s_reference_depth, 0, s_reference_format, GL_UNSIGNED_BYTE, s_reference);
9433         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage3D has failed");
9434
9435         is_compressed = 0;
9436
9437         gl.getTexLevelParameteriv(GL_TEXTURE_2D_ARRAY, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9438         GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9439
9440         if (is_compressed)
9441         {
9442                 gl.getTexLevelParameteriv(GL_TEXTURE_2D_ARRAY, 0, GL_TEXTURE_INTERNAL_FORMAT,
9443                                                                   &m_reference_compressed_3D_format);
9444                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9445
9446                 m_reference_compressed_3D_size = 0;
9447
9448                 gl.getTexLevelParameteriv(GL_TEXTURE_2D_ARRAY, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
9449                                                                   &m_reference_compressed_3D_size);
9450                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9451
9452                 if (m_reference_compressed_3D_size)
9453                 {
9454                         m_reference_compressed_3D = new glw::GLubyte[m_reference_compressed_3D_size];
9455
9456                         gl.getCompressedTexImage(GL_TEXTURE_2D_ARRAY, 0, m_reference_compressed_3D);
9457                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
9458                 }
9459         }
9460
9461         /* RECTANGLE Compressed */
9462         gl.createTextures(GL_TEXTURE_RECTANGLE, 1, &m_to_rectangle_compressed);
9463         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9464
9465         gl.bindTexture(GL_TEXTURE_RECTANGLE, m_to_rectangle_compressed);
9466         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9467
9468         gl.texImage2D(GL_TEXTURE_RECTANGLE, 0, s_reference_internalformat_compressed, s_reference_width, s_reference_height,
9469                                   0, s_reference_format, GL_UNSIGNED_BYTE, s_reference);
9470         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
9471
9472         is_compressed = 0;
9473
9474         gl.getTexLevelParameteriv(GL_TEXTURE_RECTANGLE, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9475         GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9476
9477         if (is_compressed)
9478         {
9479                 gl.getTexLevelParameteriv(GL_TEXTURE_RECTANGLE, 0, GL_TEXTURE_INTERNAL_FORMAT,
9480                                                                   &m_reference_compressed_rectangle_format);
9481                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9482
9483                 m_reference_compressed_rectangle_size = 0;
9484
9485                 gl.getTexLevelParameteriv(GL_TEXTURE_RECTANGLE, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
9486                                                                   &m_reference_compressed_rectangle_size);
9487                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9488
9489                 if (m_reference_compressed_rectangle_size)
9490                 {
9491                         m_reference_compressed_rectangle = new glw::GLubyte[m_reference_compressed_rectangle_size];
9492
9493                         gl.getCompressedTexImage(GL_TEXTURE_RECTANGLE, 0, m_reference_compressed_rectangle);
9494                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
9495                 }
9496         }
9497
9498         /* Buffer object */
9499         gl.createBuffers(1, &m_bo);
9500         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateBuffers has failed");
9501
9502         gl.namedBufferData(m_bo, s_reference_size, s_reference, GL_STATIC_COPY);
9503         GLU_EXPECT_NO_ERROR(gl.getError(), "glNamedBufferData has failed");
9504
9505         /* Invalid values */
9506
9507         /* invalid texture object */
9508         while (gl.isTexture(++m_to_invalid))
9509                 ;
9510         GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed");
9511
9512         /* invalid internal format */
9513         static const glw::GLenum all_formats[] = { GL_STENCIL_INDEX,
9514                                                                                            GL_DEPTH_COMPONENT,
9515                                                                                            GL_DEPTH_STENCIL,
9516                                                                                            GL_RED,
9517                                                                                            GL_GREEN,
9518                                                                                            GL_BLUE,
9519                                                                                            GL_RG,
9520                                                                                            GL_RGB,
9521                                                                                            GL_RGBA,
9522                                                                                            GL_BGR,
9523                                                                                            GL_BGRA,
9524                                                                                            GL_RED_INTEGER,
9525                                                                                            GL_GREEN_INTEGER,
9526                                                                                            GL_BLUE_INTEGER,
9527                                                                                            GL_RG_INTEGER,
9528                                                                                            GL_RGB_INTEGER,
9529                                                                                            GL_RGBA_INTEGER,
9530                                                                                            GL_BGR_INTEGER,
9531                                                                                            GL_BGRA_INTEGER };
9532
9533         static const glw::GLuint all_internal_formats_count = sizeof(all_formats) / sizeof(all_formats[0]);
9534
9535         bool is_valid   = true;
9536         m_format_invalid = 0;
9537
9538         while (is_valid)
9539         {
9540                 is_valid = false;
9541                 m_format_invalid++;
9542                 for (glw::GLuint i = 0; i < all_internal_formats_count; ++i)
9543                 {
9544                         if (all_formats[i] == m_format_invalid)
9545                         {
9546                                 is_valid = true;
9547                                 break;
9548                         }
9549                 }
9550         }
9551
9552         /* Invalid type. */
9553         static const glw::GLenum all_types[] = { GL_UNSIGNED_BYTE,
9554                                                                                          GL_BYTE,
9555                                                                                          GL_UNSIGNED_SHORT,
9556                                                                                          GL_SHORT,
9557                                                                                          GL_UNSIGNED_INT,
9558                                                                                          GL_INT,
9559                                                                                          GL_HALF_FLOAT,
9560                                                                                          GL_FLOAT,
9561                                                                                          GL_UNSIGNED_BYTE_3_3_2,
9562                                                                                          GL_UNSIGNED_BYTE_2_3_3_REV,
9563                                                                                          GL_UNSIGNED_SHORT_5_6_5,
9564                                                                                          GL_UNSIGNED_SHORT_5_6_5_REV,
9565                                                                                          GL_UNSIGNED_SHORT_4_4_4_4,
9566                                                                                          GL_UNSIGNED_SHORT_4_4_4_4_REV,
9567                                                                                          GL_UNSIGNED_SHORT_5_5_5_1,
9568                                                                                          GL_UNSIGNED_SHORT_1_5_5_5_REV,
9569                                                                                          GL_UNSIGNED_INT_8_8_8_8,
9570                                                                                          GL_UNSIGNED_INT_8_8_8_8_REV,
9571                                                                                          GL_UNSIGNED_INT_10_10_10_2,
9572                                                                                          GL_UNSIGNED_INT_2_10_10_10_REV,
9573                                                                                          GL_UNSIGNED_INT_24_8,
9574                                                                                          GL_UNSIGNED_INT_10F_11F_11F_REV,
9575                                                                                          GL_UNSIGNED_INT_5_9_9_9_REV,
9576                                                                                          GL_FLOAT_32_UNSIGNED_INT_24_8_REV };
9577
9578         static const glw::GLuint all_types_count = sizeof(all_types) / sizeof(all_types[0]);
9579
9580         is_valid           = true;
9581         m_type_invalid = 0;
9582
9583         while (is_valid)
9584         {
9585                 is_valid = false;
9586                 m_type_invalid++;
9587                 for (glw::GLuint i = 0; i < all_types_count; ++i)
9588                 {
9589                         if (all_types[i] == m_type_invalid)
9590                         {
9591                                 is_valid = true;
9592                                 break;
9593                         }
9594                 }
9595         }
9596
9597         /* Maximum texture size.*/
9598         gl.getIntegerv(GL_MAX_TEXTURE_SIZE, &m_max_texture_size);
9599         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
9600
9601         glw::GLenum not_matching_format                                    = GL_RED;
9602         glw::GLenum not_matching_internalformat_compressed = GL_COMPRESSED_RED;
9603
9604         /* 1D Compressed with a non matching format. We need to do all the allocation to get the correct image size */
9605         glw::GLuint to_1D_compressed_not_matching;
9606
9607         gl.createTextures(GL_TEXTURE_1D, 1, &to_1D_compressed_not_matching);
9608         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9609
9610         gl.bindTexture(GL_TEXTURE_1D, to_1D_compressed_not_matching);
9611         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9612
9613         gl.texImage1D(GL_TEXTURE_1D, 0, not_matching_internalformat_compressed, s_reference_width, 0, s_reference_format,
9614                                   GL_UNSIGNED_BYTE, s_reference);
9615         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
9616
9617         is_compressed = 0;
9618
9619         gl.getTexLevelParameteriv(GL_TEXTURE_1D, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9620         GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9621
9622         if (is_compressed)
9623         {
9624                 gl.getTexLevelParameteriv(GL_TEXTURE_1D, 0, GL_TEXTURE_INTERNAL_FORMAT, &m_not_matching_compressed_1D_format);
9625                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9626
9627                 m_not_matching_compressed_1D_size = 0;
9628
9629                 gl.getTexLevelParameteriv(GL_TEXTURE_1D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
9630                                                                   &m_not_matching_compressed_1D_size);
9631                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9632         }
9633
9634         gl.deleteTextures(1, &to_1D_compressed_not_matching);
9635         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9636
9637         /* 2D Compressed with a non matching format. We need to do all the allocation to get the correct image size */
9638         glw::GLuint to_2D_compressed_not_matching;
9639
9640         gl.createTextures(GL_TEXTURE_2D, 1, &to_2D_compressed_not_matching);
9641         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9642
9643         gl.bindTexture(GL_TEXTURE_2D, to_2D_compressed_not_matching);
9644         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9645
9646         gl.texImage2D(GL_TEXTURE_2D, 0, not_matching_internalformat_compressed, s_reference_width, s_reference_height, 0,
9647                                   not_matching_format, GL_UNSIGNED_BYTE, s_reference);
9648         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
9649
9650         is_compressed = 0;
9651
9652         gl.getTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9653         GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9654
9655         if (is_compressed)
9656         {
9657                 gl.getTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &m_not_matching_compressed_2D_format);
9658                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9659
9660                 m_not_matching_compressed_2D_size = 0;
9661
9662                 gl.getTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
9663                                                                   &m_not_matching_compressed_2D_size);
9664                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9665         }
9666
9667         gl.deleteTextures(1, &to_2D_compressed_not_matching);
9668         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9669
9670         /* 3D Compressed with a non matching format. We need to do all the allocation to get the correct image size */
9671         glw::GLuint to_3D_compressed_not_matching;
9672
9673         gl.createTextures(GL_TEXTURE_3D, 1, &to_3D_compressed_not_matching);
9674         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9675
9676         gl.bindTexture(GL_TEXTURE_3D, to_3D_compressed_not_matching);
9677         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9678
9679         gl.texImage3D(GL_TEXTURE_3D, 0, not_matching_internalformat_compressed, s_reference_width, s_reference_height,
9680                                   s_reference_depth, 0, not_matching_format, GL_UNSIGNED_BYTE, s_reference);
9681         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage3D has failed");
9682
9683         is_compressed = 0;
9684
9685         gl.getTexLevelParameteriv(GL_TEXTURE_3D, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9686         GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9687
9688         if (is_compressed)
9689         {
9690                 gl.getTexLevelParameteriv(GL_TEXTURE_3D, 0, GL_TEXTURE_INTERNAL_FORMAT, &m_not_matching_compressed_3D_format);
9691                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9692
9693                 m_not_matching_compressed_3D_size = 0;
9694
9695                 gl.getTexLevelParameteriv(GL_TEXTURE_3D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
9696                                                                   &m_not_matching_compressed_3D_size);
9697                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9698         }
9699
9700         gl.deleteTextures(1, &to_3D_compressed_not_matching);
9701         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9702 }
9703
9704 /** @brief Test (negative) of TextureSubImage1D
9705  *
9706  *  @return Test result.
9707  */
9708 bool SubImageErrorsTest::Test1D()
9709 {
9710         /* Shortcut for GL functionality. */
9711         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
9712
9713         /* Result. */
9714         bool is_ok = true;
9715
9716         /* Check that INVALID_OPERATION is generated by TextureSubImage1D if
9717          texture is not the name of an existing texture object. */
9718         {
9719                 gl.textureSubImage1D(m_to_invalid, 0, 0, s_reference_width, s_reference_format, s_reference_type, s_reference);
9720                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9721                                                                   "texture is not the name of an existing texture object.");
9722         }
9723
9724         /* Check that INVALID_ENUM is generated by TextureSubImage1D if format is
9725          not an accepted format constant. */
9726         {
9727                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, m_format_invalid, s_reference_type, s_reference);
9728                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureSubImage1D",
9729                                                                   "format is not an accepted format constant.");
9730         }
9731
9732         /* Check that INVALID_ENUM is generated by TextureSubImage1D if type is not
9733          an accepted type constant. */
9734         {
9735                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, m_type_invalid, s_reference);
9736                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureSubImage1D",
9737                                                                   "type is not an accepted type constant.");
9738         }
9739
9740         /* Check that INVALID_VALUE is generated by TextureSubImage1D if level is
9741          less than 0. */
9742         {
9743                 gl.textureSubImage1D(m_to_1D, -1, 0, s_reference_width, s_reference_format, s_reference_type, s_reference);
9744                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D", "level is less than 0.");
9745         }
9746
9747         /* Check that INVALID_VALUE may be generated by TextureSubImage1D if level
9748          is greater than log2 max, where max is the returned value of
9749          MAX_TEXTURE_SIZE. */
9750         {
9751                 gl.textureSubImage1D(m_to_1D, m_max_texture_size, 0, s_reference_width, s_reference_format, s_reference_type,
9752                                                          s_reference);
9753                 is_ok &=
9754                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D",
9755                                                          "level is greater than log2 max, where max is the returned value of MAX_TEXTURE_SIZE.");
9756         }
9757
9758         /* Check that INVALID_VALUE is generated by TextureSubImage1D if
9759          xoffset<-b, or if (xoffset+width)>(w-b), where w is the TEXTURE_WIDTH,
9760          and b is the width of the TEXTURE_BORDER of the texture image being
9761          modified. Note that w includes twice the border width. */
9762         {
9763                 gl.textureSubImage1D(m_to_1D, 0, -1, s_reference_width, s_reference_format, s_reference_type, s_reference);
9764                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D",
9765                                                                   "xoffset<-b, where b is the width of the TEXTURE_BORDER.");
9766
9767                 gl.textureSubImage1D(m_to_1D, 0, 1, s_reference_width + 1, s_reference_format, s_reference_type, s_reference);
9768                 is_ok &= CheckErrorAndLog(
9769                         m_context, GL_INVALID_VALUE, "glTextureSubImage1D",
9770                         "(xoffset+width)>(w-b), where w is the TEXTURE_WIDTH, b is the width of the TEXTURE_BORDER.");
9771         }
9772
9773         /*Check that INVALID_VALUE is generated by TextureSubImage1D if width is less than 0. */
9774         {
9775 #ifndef TURN_OFF_SUB_IMAGE_ERRORS_TEST_OF_NEGATIVE_WIDTH_HEIGHT_OR_DEPTH
9776                 gl.textureSubImage1D(m_to_1D, 0, 0, -1, s_reference_format, s_reference_type, s_reference);
9777                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D", "width is less than 0.");
9778 #endif
9779         }
9780
9781         /* Check that INVALID_OPERATION is generated by TextureSubImage1D if type
9782          is one of UNSIGNED_BYTE_3_3_2, UNSIGNED_BYTE_2_3_3_REV,
9783          UNSIGNED_SHORT_5_6_5, or UNSIGNED_SHORT_5_6_5_REV and format is not RGB. */
9784         {
9785                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_BYTE_3_3_2, s_reference);
9786                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9787                                                                   "type is UNSIGNED_BYTE_3_3_2 and format is not RGB.");
9788
9789                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_BYTE_2_3_3_REV,
9790                                                          s_reference);
9791                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9792                                                                   "type is UNSIGNED_BYTE_2_3_3_REV and format is not RGB.");
9793
9794                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_SHORT_5_6_5,
9795                                                          s_reference);
9796                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9797                                                                   "type is UNSIGNED_SHORT_5_6_5 and format is not RGB.");
9798
9799                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_SHORT_5_6_5_REV,
9800                                                          s_reference);
9801                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9802                                                                   "type is UNSIGNED_SHORT_5_6_5_REV and format is not RGB.");
9803         }
9804
9805         /* Check that INVALID_OPERATION is generated by TextureSubImage1D if type
9806          is one of UNSIGNED_SHORT_4_4_4_4, UNSIGNED_SHORT_4_4_4_4_REV,
9807          UNSIGNED_SHORT_5_5_5_1, UNSIGNED_SHORT_1_5_5_5_REV,
9808          UNSIGNED_INT_8_8_8_8, UNSIGNED_INT_8_8_8_8_REV, UNSIGNED_INT_10_10_10_2,
9809          or UNSIGNED_INT_2_10_10_10_REV and format is neither RGBA nor BGRA. */
9810         {
9811                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_SHORT_4_4_4_4,
9812                                                          s_reference);
9813                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9814                                                                   "type is UNSIGNED_SHORT_4_4_4_4 and format is neither RGBA nor BGRA.");
9815
9816                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_SHORT_4_4_4_4_REV,
9817                                                          s_reference);
9818                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9819                                                                   "type is UNSIGNED_SHORT_4_4_4_4_REV and format is neither RGBA nor BGRA.");
9820
9821                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_SHORT_5_5_5_1,
9822                                                          s_reference);
9823                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9824                                                                   "type is UNSIGNED_SHORT_5_5_5_1 and format is neither RGBA nor BGRA.");
9825
9826                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_SHORT_1_5_5_5_REV,
9827                                                          s_reference);
9828                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9829                                                                   "type is UNSIGNED_SHORT_1_5_5_5_REV and format is neither RGBA nor BGRA.");
9830
9831                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_INT_8_8_8_8,
9832                                                          s_reference);
9833                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9834                                                                   "type is UNSIGNED_INT_8_8_8_8 and format is neither RGBA nor BGRA.");
9835
9836                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_INT_8_8_8_8_REV,
9837                                                          s_reference);
9838                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9839                                                                   "type is UNSIGNED_INT_8_8_8_8_REV and format is neither RGBA nor BGRA.");
9840
9841                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_INT_10_10_10_2,
9842                                                          s_reference);
9843                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9844                                                                   "type is UNSIGNED_INT_10_10_10_2 and format is neither RGBA nor BGRA.");
9845
9846                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_INT_2_10_10_10_REV,
9847                                                          s_reference);
9848                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9849                                                                   "type is UNSIGNED_INT_2_10_10_10_REV and format is neither RGBA nor BGRA.");
9850         }
9851
9852         /* Check that INVALID_OPERATION is generated by TextureSubImage1D if a
9853          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
9854          and the buffer object's data store is currently mapped. */
9855         {
9856                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
9857                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9858
9859                 gl.mapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
9860
9861                 if (GL_NO_ERROR == gl.getError())
9862                 {
9863                         gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, s_reference_type, NULL);
9864                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9865                                                                           "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and "
9866                                                                           "the buffer object's data store is currently mapped.");
9867
9868                         gl.unmapBuffer(GL_PIXEL_UNPACK_BUFFER);
9869                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9870
9871                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
9872                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9873                 }
9874         }
9875
9876         /* Check that INVALID_OPERATION is generated by TextureSubImage1D if a
9877          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
9878          and the data would be unpacked from the buffer object such that the
9879          memory reads required would exceed the data store size. */
9880         {
9881                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
9882                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9883
9884                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, s_reference_type,
9885                                                          (glw::GLubyte*)NULL + s_reference_size * 2);
9886                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9887                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and the "
9888                                                                   "data would be unpacked from the buffer object such that the memory reads required "
9889                                                                   "would exceed the data store size.");
9890
9891                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
9892                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9893         }
9894
9895         /* Check that INVALID_OPERATION is generated by TextureSubImage1D if a
9896          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
9897          and pixels is not evenly divisible into the number of bytes needed to
9898          store in memory a datum indicated by type. */
9899         {
9900                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
9901                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9902
9903                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, s_reference_type,
9904                                                          (glw::GLubyte*)NULL + 1);
9905                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9906                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and pixels "
9907                                                                   "is not evenly divisible into the number of bytes needed to store in memory a datum "
9908                                                                   "indicated by type.");
9909
9910                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
9911                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9912         }
9913
9914         return is_ok;
9915 }
9916
9917 /** @brief Test (negative) of TextureSubImage2D
9918  *
9919  *  @return Test result.
9920  */
9921 bool SubImageErrorsTest::Test2D()
9922 {
9923         /* Shortcut for GL functionality. */
9924         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
9925
9926         /* Result. */
9927         bool is_ok = true;
9928
9929         /* Check that INVALID_OPERATION is generated by TextureSubImage2D if
9930          texture is not the name of an existing texture object. */
9931         {
9932                 gl.textureSubImage2D(m_to_invalid, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9933                                                          s_reference_type, s_reference);
9934                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9935                                                                   "texture is not the name of an existing texture object.");
9936         }
9937
9938         /* Check that INVALID_ENUM is generated by TextureSubImage2D if format is
9939          not an accepted format constant. */
9940         {
9941                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, m_format_invalid,
9942                                                          s_reference_type, s_reference);
9943                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureSubImage2D",
9944                                                                   "format is not an accepted format constant.");
9945         }
9946
9947         /* Check that INVALID_ENUM is generated by TextureSubImage2D if type is not
9948          an accepted type constant. */
9949         {
9950                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9951                                                          m_type_invalid, s_reference);
9952                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureSubImage2D",
9953                                                                   "type is not an accepted type constant.");
9954         }
9955
9956         /* Check that INVALID_VALUE is generated by TextureSubImage2D if level is
9957          less than 0. */
9958         {
9959                 gl.textureSubImage2D(m_to_2D, -1, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9960                                                          s_reference_type, s_reference);
9961                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage2D", "level is less than 0.");
9962         }
9963
9964         /* Check that INVALID_VALUE may be generated by TextureSubImage2D if level
9965          is greater than log2 max, where max is the returned value of
9966          MAX_TEXTURE_SIZE. */
9967         {
9968                 gl.textureSubImage2D(m_to_2D, m_max_texture_size, 0, 0, s_reference_width, s_reference_height,
9969                                                          s_reference_format, s_reference_type, s_reference);
9970                 is_ok &=
9971                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage2D",
9972                                                          "level is greater than log2 max, where max is the returned value of MAX_TEXTURE_SIZE.");
9973         }
9974
9975         /* Check that INVALID_VALUE may be generated by TextureSubImage2D if level
9976          is greater than log2 max, where max is the returned value of
9977          MAX_TEXTURE_SIZE.
9978          Check that INVALID_VALUE is generated by TextureSubImage2D if
9979          xoffset<-b, (xoffset+width)>(w-b), yoffset<-b, or
9980          (yoffset+height)>(h-b), where w is the TEXTURE_WIDTH, h is the
9981          TEXTURE_HEIGHT, and b is the border width of the texture image being
9982          modified. Note that w and h include twice the border width. */
9983         {
9984                 gl.textureSubImage2D(m_to_2D, 0, -1, 0, s_reference_width, s_reference_height, s_reference_format,
9985                                                          s_reference_type, s_reference);
9986                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage2D",
9987                                                                   "xoffset<-b, where b is the width of the TEXTURE_BORDER.");
9988
9989                 gl.textureSubImage2D(m_to_2D, 0, 1, 0, s_reference_width + 1, s_reference_height, s_reference_format,
9990                                                          s_reference_type, s_reference);
9991                 is_ok &= CheckErrorAndLog(
9992                         m_context, GL_INVALID_VALUE, "glTextureSubImage2D",
9993                         "(xoffset+width)>(w-b), where w is the TEXTURE_WIDTH, b is the width of the TEXTURE_BORDER.");
9994
9995                 gl.textureSubImage2D(m_to_2D, 0, 0, -1, s_reference_width, s_reference_height, s_reference_format,
9996                                                          s_reference_type, s_reference);
9997                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage2D",
9998                                                                   "yoffset<-b, where b is the height of the TEXTURE_BORDER.");
9999
10000                 gl.textureSubImage2D(m_to_2D, 0, 0, 1, s_reference_width + 1, s_reference_height, s_reference_format,
10001                                                          s_reference_type, s_reference);
10002                 is_ok &= CheckErrorAndLog(
10003                         m_context, GL_INVALID_VALUE, "glTextureSubImage2D",
10004                         "(yoffset+height)>(h-b), where h is the TEXTURE_HEIGHT, b is the width of the TEXTURE_BORDER.");
10005         }
10006
10007         /*Check that INVALID_VALUE is generated by TextureSubImage2D if width or height is less than 0. */
10008         {
10009 #ifndef TURN_OFF_SUB_IMAGE_ERRORS_TEST_OF_NEGATIVE_WIDTH_HEIGHT_OR_DEPTH
10010                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, -1, s_reference_height, s_reference_format, s_reference_type,
10011                                                          s_reference);
10012                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage2D", "width is less than 0.");
10013
10014                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, -1, s_reference_format, s_reference_type,
10015                                                          s_reference);
10016                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage2D", "height is less than 0.");
10017 #endif
10018         }
10019
10020         /* Check that INVALID_OPERATION is generated by TextureSubImage2D if type
10021          is one of UNSIGNED_BYTE_3_3_2, UNSIGNED_BYTE_2_3_3_REV,
10022          UNSIGNED_SHORT_5_6_5, or UNSIGNED_SHORT_5_6_5_REV and format is not RGB. */
10023         {
10024                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10025                                                          GL_UNSIGNED_BYTE_3_3_2, s_reference);
10026                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10027                                                                   "type is UNSIGNED_BYTE_3_3_2 and format is not RGB.");
10028
10029                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10030                                                          GL_UNSIGNED_BYTE_2_3_3_REV, s_reference);
10031                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10032                                                                   "type is UNSIGNED_BYTE_2_3_3_REV and format is not RGB.");
10033
10034                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10035                                                          GL_UNSIGNED_SHORT_5_6_5, s_reference);
10036                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10037                                                                   "type is UNSIGNED_SHORT_5_6_5 and format is not RGB.");
10038
10039                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10040                                                          GL_UNSIGNED_SHORT_5_6_5_REV, s_reference);
10041                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10042                                                                   "type is UNSIGNED_SHORT_5_6_5_REV and format is not RGB.");
10043         }
10044
10045         /* Check that INVALID_OPERATION is generated by TextureSubImage2D if type
10046          is one of UNSIGNED_SHORT_4_4_4_4, UNSIGNED_SHORT_4_4_4_4_REV,
10047          UNSIGNED_SHORT_5_5_5_1, UNSIGNED_SHORT_1_5_5_5_REV,
10048          UNSIGNED_INT_8_8_8_8, UNSIGNED_INT_8_8_8_8_REV, UNSIGNED_INT_10_10_10_2,
10049          or UNSIGNED_INT_2_10_10_10_REV and format is neither RGBA nor BGRA. */
10050         {
10051                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10052                                                          GL_UNSIGNED_SHORT_4_4_4_4, s_reference);
10053                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10054                                                                   "type is UNSIGNED_SHORT_4_4_4_4 and format is neither RGBA nor BGRA.");
10055
10056                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10057                                                          GL_UNSIGNED_SHORT_4_4_4_4_REV, s_reference);
10058                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10059                                                                   "type is UNSIGNED_SHORT_4_4_4_4_REV and format is neither RGBA nor BGRA.");
10060
10061                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10062                                                          GL_UNSIGNED_SHORT_5_5_5_1, s_reference);
10063                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10064                                                                   "type is UNSIGNED_SHORT_5_5_5_1 and format is neither RGBA nor BGRA.");
10065
10066                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10067                                                          GL_UNSIGNED_SHORT_1_5_5_5_REV, s_reference);
10068                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10069                                                                   "type is UNSIGNED_SHORT_1_5_5_5_REV and format is neither RGBA nor BGRA.");
10070
10071                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10072                                                          GL_UNSIGNED_INT_8_8_8_8, s_reference);
10073                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10074                                                                   "type is UNSIGNED_INT_8_8_8_8 and format is neither RGBA nor BGRA.");
10075
10076                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10077                                                          GL_UNSIGNED_INT_8_8_8_8_REV, s_reference);
10078                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10079                                                                   "type is UNSIGNED_INT_8_8_8_8_REV and format is neither RGBA nor BGRA.");
10080
10081                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10082                                                          GL_UNSIGNED_INT_10_10_10_2, s_reference);
10083                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10084                                                                   "type is UNSIGNED_INT_10_10_10_2 and format is neither RGBA nor BGRA.");
10085
10086                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10087                                                          GL_UNSIGNED_INT_2_10_10_10_REV, s_reference);
10088                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10089                                                                   "type is UNSIGNED_INT_2_10_10_10_REV and format is neither RGBA nor BGRA.");
10090         }
10091
10092         /* Check that INVALID_OPERATION is generated by TextureSubImage2D if a
10093          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
10094          and the buffer object's data store is currently mapped. */
10095         {
10096                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10097                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10098
10099                 gl.mapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
10100
10101                 if (GL_NO_ERROR == gl.getError())
10102                 {
10103                         gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10104                                                                  s_reference_type, NULL);
10105                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10106                                                                           "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and "
10107                                                                           "the buffer object's data store is currently mapped.");
10108
10109                         gl.unmapBuffer(GL_PIXEL_UNPACK_BUFFER);
10110                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10111
10112                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10113                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10114                 }
10115         }
10116
10117         /* Check that INVALID_OPERATION is generated by TextureSubImage2D if a
10118          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
10119          and the data would be unpacked from the buffer object such that the
10120          memory reads required would exceed the data store size. */
10121         {
10122                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10123                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10124
10125                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10126                                                          s_reference_type, (glw::GLubyte*)NULL + s_reference_size * 2);
10127                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10128                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and the "
10129                                                                   "data would be unpacked from the buffer object such that the memory reads required "
10130                                                                   "would exceed the data store size.");
10131
10132                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10133                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10134         }
10135
10136         /* Check that INVALID_OPERATION is generated by TextureSubImage2D if a
10137          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
10138          and pixels is not evenly divisible into the number of bytes needed to
10139          store in memory a datum indicated by type. */
10140         {
10141                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10142                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10143
10144                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10145                                                          s_reference_type, (glw::GLubyte*)NULL + 1);
10146                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10147                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and pixels "
10148                                                                   "is not evenly divisible into the number of bytes needed to store in memory a datum "
10149                                                                   "indicated by type.");
10150
10151                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10152                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10153         }
10154
10155         return is_ok;
10156 }
10157
10158 /** @brief Test (negative) of TextureSubImage3D
10159  *
10160  *  @return Test result.
10161  */
10162 bool SubImageErrorsTest::Test3D()
10163 {
10164         /* Shortcut for GL functionality. */
10165         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10166
10167         /* Result. */
10168         bool is_ok = true;
10169
10170         /* Check that INVALID_OPERATION is generated by TextureSubImage3D if
10171          texture is not the name of an existing texture object. */
10172         {
10173                 gl.textureSubImage3D(m_to_invalid, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10174                                                          s_reference_format, s_reference_type, s_reference);
10175                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10176                                                                   "texture is not the name of an existing texture object.");
10177         }
10178
10179         /* Check that INVALID_ENUM is generated by TextureSubImage3D if format is
10180          not an accepted format constant. */
10181         {
10182                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10183                                                          m_format_invalid, s_reference_type, s_reference);
10184                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureSubImage3D",
10185                                                                   "format is not an accepted format constant.");
10186         }
10187
10188         /* Check that INVALID_ENUM is generated by TextureSubImage3D if type is not
10189          an accepted type constant. */
10190         {
10191                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10192                                                          s_reference_format, m_type_invalid, s_reference);
10193                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureSubImage3D",
10194                                                                   "type is not an accepted type constant.");
10195         }
10196
10197         /* Check that INVALID_VALUE is generated by TextureSubImage3D if level is
10198          less than 0. */
10199         {
10200                 gl.textureSubImage3D(m_to_3D, -1, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10201                                                          s_reference_format, s_reference_type, s_reference);
10202                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage3D", "level is less than 0.");
10203         }
10204
10205         /* Check that INVALID_VALUE may be generated by TextureSubImage1D if level
10206          is greater than log2 max, where max is the returned value of
10207          MAX_TEXTURE_SIZE. */
10208         {
10209                 gl.textureSubImage3D(m_to_3D, m_max_texture_size, 0, 0, 0, s_reference_width, s_reference_height,
10210                                                          s_reference_depth, s_reference_format, s_reference_type, s_reference);
10211                 is_ok &=
10212                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10213                                                          "level is greater than log2 max, where max is the returned value of MAX_TEXTURE_SIZE.");
10214         }
10215
10216         /* Check that INVALID_VALUE is generated by TextureSubImage3D if
10217          xoffset<-b, (xoffset+width)>(w-b), yoffset<-b, or
10218          (yoffset+height)>(h-b), or zoffset<-b, or (zoffset+depth)>(d-b), where w
10219          is the TEXTURE_WIDTH, h is the TEXTURE_HEIGHT, d is the TEXTURE_DEPTH
10220          and b is the border width of the texture image being modified. Note
10221          that w, h, and d include twice the border width. */
10222         {
10223                 gl.textureSubImage3D(m_to_3D, 0, -1, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10224                                                          s_reference_format, s_reference_type, s_reference);
10225                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10226                                                                   "xoffset<-b, where b is the width of the TEXTURE_BORDER.");
10227
10228                 gl.textureSubImage3D(m_to_3D, 0, 1, 0, 0, s_reference_width + 1, s_reference_height, s_reference_depth,
10229                                                          s_reference_format, s_reference_type, s_reference);
10230                 is_ok &= CheckErrorAndLog(
10231                         m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10232                         "(xoffset+width)>(w-b), where w is the TEXTURE_WIDTH, b is the width of the TEXTURE_BORDER.");
10233
10234                 gl.textureSubImage3D(m_to_3D, 0, 0, -1, 0, s_reference_width, s_reference_height, s_reference_depth,
10235                                                          s_reference_format, s_reference_type, s_reference);
10236                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10237                                                                   "yoffset<-b, where b is the width of the TEXTURE_BORDER.");
10238
10239                 gl.textureSubImage3D(m_to_3D, 0, 0, 1, 0, s_reference_width + 1, s_reference_height, s_reference_depth,
10240                                                          s_reference_format, s_reference_type, s_reference);
10241                 is_ok &= CheckErrorAndLog(
10242                         m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10243                         "(yoffset+height)>(h-b), where h is the TEXTURE_HEIGHT, b is the width of the TEXTURE_BORDER.");
10244
10245                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, -1, s_reference_width, s_reference_height, s_reference_depth,
10246                                                          s_reference_format, s_reference_type, s_reference);
10247                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10248                                                                   "zoffset<-b, where b is the depth of the TEXTURE_BORDER.");
10249
10250                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 1, s_reference_width + 1, s_reference_height, s_reference_depth,
10251                                                          s_reference_format, s_reference_type, s_reference);
10252                 is_ok &= CheckErrorAndLog(
10253                         m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10254                         "(zoffset+width)>(d-b), where d is the TEXTURE_DEPTH, b is the width of the TEXTURE_BORDER.");
10255         }
10256
10257         /*Check that INVALID_VALUE is generated by TextureSubImage3D if width or height or depth is less than 0. */
10258         {
10259 #ifndef TURN_OFF_SUB_IMAGE_ERRORS_TEST_OF_NEGATIVE_WIDTH_HEIGHT_OR_DEPTH
10260                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, -1, s_reference_height, s_reference_depth, s_reference_format,
10261                                                          s_reference_type, s_reference);
10262                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D", "width is less than 0.");
10263
10264                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, -1, s_reference_depth, s_reference_format,
10265                                                          s_reference_type, s_reference);
10266                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D", "height is less than 0.");
10267
10268                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, -1, s_reference_format,
10269                                                          s_reference_type, s_reference);
10270                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D", "depth is less than 0.");
10271 #endif
10272         }
10273
10274         /* Check that INVALID_OPERATION is generated by TextureSubImage3D if type
10275          is one of UNSIGNED_BYTE_3_3_2, UNSIGNED_BYTE_2_3_3_REV,
10276          UNSIGNED_SHORT_5_6_5, or UNSIGNED_SHORT_5_6_5_REV and format is not RGB. */
10277         {
10278                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10279                                                          s_reference_format, GL_UNSIGNED_BYTE_3_3_2, s_reference);
10280                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10281                                                                   "type is UNSIGNED_BYTE_3_3_2 and format is not RGB.");
10282
10283                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10284                                                          s_reference_format, GL_UNSIGNED_BYTE_2_3_3_REV, s_reference);
10285                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10286                                                                   "type is UNSIGNED_BYTE_2_3_3_REV and format is not RGB.");
10287
10288                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10289                                                          s_reference_format, GL_UNSIGNED_SHORT_5_6_5, s_reference);
10290                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10291                                                                   "type is UNSIGNED_SHORT_5_6_5 and format is not RGB.");
10292
10293                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10294                                                          s_reference_format, GL_UNSIGNED_SHORT_5_6_5_REV, s_reference);
10295                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10296                                                                   "type is UNSIGNED_SHORT_5_6_5_REV and format is not RGB.");
10297         }
10298
10299         /* Check that INVALID_OPERATION is generated by TextureSubImage3D if type
10300          is one of UNSIGNED_SHORT_4_4_4_4, UNSIGNED_SHORT_4_4_4_4_REV,
10301          UNSIGNED_SHORT_5_5_5_1, UNSIGNED_SHORT_1_5_5_5_REV,
10302          UNSIGNED_INT_8_8_8_8, UNSIGNED_INT_8_8_8_8_REV, UNSIGNED_INT_10_10_10_2,
10303          or UNSIGNED_INT_2_10_10_10_REV and format is neither RGBA nor BGRA. */
10304         {
10305                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10306                                                          s_reference_format, GL_UNSIGNED_SHORT_4_4_4_4, s_reference);
10307                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10308                                                                   "type is UNSIGNED_SHORT_4_4_4_4 and format is neither RGBA nor BGRA.");
10309
10310                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10311                                                          s_reference_format, GL_UNSIGNED_SHORT_4_4_4_4_REV, s_reference);
10312                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10313                                                                   "type is UNSIGNED_SHORT_4_4_4_4_REV and format is neither RGBA nor BGRA.");
10314
10315                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10316                                                          s_reference_format, GL_UNSIGNED_SHORT_5_5_5_1, s_reference);
10317                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10318                                                                   "type is UNSIGNED_SHORT_5_5_5_1 and format is neither RGBA nor BGRA.");
10319
10320                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10321                                                          s_reference_format, GL_UNSIGNED_SHORT_1_5_5_5_REV, s_reference);
10322                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10323                                                                   "type is UNSIGNED_SHORT_1_5_5_5_REV and format is neither RGBA nor BGRA.");
10324
10325                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10326                                                          s_reference_format, GL_UNSIGNED_INT_8_8_8_8, s_reference);
10327                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10328                                                                   "type is UNSIGNED_INT_8_8_8_8 and format is neither RGBA nor BGRA.");
10329
10330                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10331                                                          s_reference_format, GL_UNSIGNED_INT_8_8_8_8_REV, s_reference);
10332                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10333                                                                   "type is UNSIGNED_INT_8_8_8_8_REV and format is neither RGBA nor BGRA.");
10334
10335                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10336                                                          s_reference_format, GL_UNSIGNED_INT_10_10_10_2, s_reference);
10337                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10338                                                                   "type is UNSIGNED_INT_10_10_10_2 and format is neither RGBA nor BGRA.");
10339
10340                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10341                                                          s_reference_format, GL_UNSIGNED_INT_2_10_10_10_REV, s_reference);
10342                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10343                                                                   "type is UNSIGNED_INT_2_10_10_10_REV and format is neither RGBA nor BGRA.");
10344         }
10345
10346         /* Check that INVALID_OPERATION is generated by TextureSubImage3D if a
10347          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
10348          and the buffer object's data store is currently mapped. */
10349         {
10350                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10351                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10352
10353                 gl.mapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
10354
10355                 if (GL_NO_ERROR == gl.getError())
10356                 {
10357                         gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10358                                                                  s_reference_format, s_reference_type, NULL);
10359                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10360                                                                           "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and "
10361                                                                           "the buffer object's data store is currently mapped.");
10362
10363                         gl.unmapBuffer(GL_PIXEL_UNPACK_BUFFER);
10364                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10365
10366                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10367                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10368                 }
10369         }
10370
10371         /* Check that INVALID_OPERATION is generated by TextureSubImage3D if a
10372          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
10373          and the data would be unpacked from the buffer object such that the
10374          memory reads required would exceed the data store size. */
10375         {
10376                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10377                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10378
10379                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10380                                                          s_reference_format, s_reference_type, (glw::GLubyte*)NULL + s_reference_size * 2);
10381                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10382                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and the "
10383                                                                   "data would be unpacked from the buffer object such that the memory reads required "
10384                                                                   "would exceed the data store size.");
10385
10386                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10387                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10388         }
10389
10390         /* Check that INVALID_OPERATION is generated by TextureSubImage3D if a
10391          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
10392          and pixels is not evenly divisible into the number of bytes needed to
10393          store in memory a datum indicated by type. */
10394         {
10395                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10396                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10397
10398                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10399                                                          s_reference_format, s_reference_type, (glw::GLubyte*)NULL + 1);
10400                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10401                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and pixels "
10402                                                                   "is not evenly divisible into the number of bytes needed to store in memory a datum "
10403                                                                   "indicated by type.");
10404
10405                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10406                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10407         }
10408
10409         return is_ok;
10410 }
10411
10412 /** @brief Test (negative) of TextureSubImage1DCompressed
10413  *
10414  *  @return Test result.
10415  */
10416 bool SubImageErrorsTest::Test1DCompressed()
10417 {
10418         /* Shortcut for GL functionality. */
10419         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10420
10421         /* Result. */
10422         bool is_ok = true;
10423
10424         /* Do tests only if compressed 1D textures are supported. */
10425         if (DE_NULL != m_reference_compressed_1D)
10426         {
10427                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage1D
10428                  if texture is not the name of an existing texture object. */
10429                 {
10430                         gl.compressedTextureSubImage1D(m_to_invalid, 0, 0, s_reference_width, m_reference_compressed_1D_format,
10431                                                                                    m_reference_compressed_1D_size, m_reference_compressed_1D);
10432                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage1D",
10433                                                                           "texture is not the name of an existing texture object.");
10434                 }
10435
10436                 /* Check that INVALID_ENUM is generated by CompressedTextureSubImage1D if
10437                  internalformat is not one of the generic compressed internal formats:
10438                  COMPRESSED_RED, COMPRESSED_RG, COMPRESSED_RGB, COMPRESSED_RGBA.
10439                  COMPRESSED_SRGB, or COMPRESSED_SRGB_ALPHA. */
10440                 {
10441                         /* GL_COMPRESSED_RG_RGTC2 is not 1D as specification says. */
10442                         gl.compressedTextureSubImage1D(m_to_1D_compressed, 0, 0, s_reference_width, GL_COMPRESSED_RG_RGTC2,
10443                                                                                    m_reference_compressed_1D_size, m_reference_compressed_1D);
10444                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glCompressedTextureSubImage1D",
10445                                                                           "internalformat is of the generic compressed internal formats: COMPRESSED_RED, "
10446                                                                           "COMPRESSED_RG, COMPRESSED_RGB, COMPRESSED_RGBA. COMPRESSED_SRGB, or "
10447                                                                           "COMPRESSED_SRGB_ALPHA.");
10448                 }
10449
10450                 /* Check that INVALID_OPERATION is generated if format does not match the
10451                  internal format of the texture image being modified, since these
10452                  commands do not provide for image format conversion. */
10453                 {
10454                         gl.compressedTextureSubImage1D(m_to_1D_compressed, 0, 0, s_reference_width,
10455                                                                                    m_not_matching_compressed_1D_format, m_not_matching_compressed_1D_size,
10456                                                                                    m_reference_compressed_1D);
10457                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage1D",
10458                                                                           "format does not match the internal format of the texture image being modified, "
10459                                                                           "since these commands do not provide for image format conversion.");
10460                 }
10461
10462                 /* Check that INVALID_VALUE is generated by CompressedTextureSubImage1D if
10463                  imageSize is not consistent with the format, dimensions, and contents of
10464                  the specified compressed image data. */
10465                 {
10466                         gl.compressedTextureSubImage1D(m_to_1D_compressed, 0, 0, s_reference_width,
10467                                                                                    m_reference_compressed_1D_format, m_reference_compressed_1D_size - 1,
10468                                                                                    m_reference_compressed_1D);
10469                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCompressedTextureSubImage1D",
10470                                                                           "imageSize is not consistent with the format, dimensions, and contents of the "
10471                                                                           "specified compressed image data.");
10472                 }
10473
10474                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage1D
10475                  if a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER
10476                  target and the buffer object's data store is currently mapped. */
10477                 {
10478                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10479                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10480
10481                         gl.mapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
10482
10483                         if (GL_NO_ERROR == gl.getError())
10484                         {
10485                                 gl.compressedTextureSubImage1D(m_to_1D_compressed, 0, 0, s_reference_width,
10486                                                                                            m_reference_compressed_1D_format, m_reference_compressed_1D_size, NULL);
10487                                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage1D",
10488                                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target "
10489                                                                                   "and the buffer object's data store is currently mapped.");
10490
10491                                 gl.unmapBuffer(GL_PIXEL_UNPACK_BUFFER);
10492                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10493
10494                                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10495                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10496                         }
10497                 }
10498
10499                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage1D
10500                  if a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER
10501                  target and the data would be unpacked from the buffer object such that
10502                  the memory reads required would exceed the data store size. */
10503                 {
10504                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10505                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10506
10507                         gl.compressedTextureSubImage1D(m_to_1D_compressed, 0, 0, s_reference_width,
10508                                                                                    m_reference_compressed_1D_format, m_reference_compressed_1D_size,
10509                                                                                    (glw::GLubyte*)NULL + s_reference_size * 2);
10510                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage1D",
10511                                                                           "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and "
10512                                                                           "the buffer object's data store is currently mapped.");
10513
10514                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10515                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10516                 }
10517         }
10518
10519         return is_ok;
10520 }
10521
10522 /** @brief Test (negative) of TextureSubImage2DCompressed
10523  *
10524  *  @return Test result.
10525  */
10526 bool SubImageErrorsTest::Test2DCompressed()
10527 {
10528         /* Shortcut for GL functionality. */
10529         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10530
10531         /* Result. */
10532         bool is_ok = true;
10533
10534         /* Do tests only if compressed 2D textures are supported. */
10535         if (DE_NULL != m_reference_compressed_2D)
10536         {
10537                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage2D
10538                  if texture is not the name of an existing texture object. */
10539                 {
10540                         gl.compressedTextureSubImage2D(m_to_invalid, 0, 0, 0, s_reference_width, s_reference_height,
10541                                                                                    m_reference_compressed_2D_format, m_reference_compressed_2D_size,
10542                                                                                    m_reference_compressed_2D);
10543                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage2D",
10544                                                                           "texture is not the name of an existing texture object.");
10545                 }
10546
10547                 /* Check that INVALID_ENUM is generated by CompressedTextureSubImage2D if
10548                  internalformat is of the generic compressed internal formats:
10549                  COMPRESSED_RED, COMPRESSED_RG, COMPRESSED_RGB, COMPRESSED_RGBA.
10550                  COMPRESSED_SRGB, or COMPRESSED_SRGB_ALPHA. */
10551                 {
10552                         gl.compressedTextureSubImage2D(m_to_2D_compressed, 0, 0, 0, s_reference_width, s_reference_height,
10553                                                                                    GL_COMPRESSED_RG, m_reference_compressed_2D_size, m_reference_compressed_2D);
10554                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glCompressedTextureSubImage2D",
10555                                                                           "internalformat is of the generic compressed internal formats: COMPRESSED_RED, "
10556                                                                           "COMPRESSED_RG, COMPRESSED_RGB, COMPRESSED_RGBA. COMPRESSED_SRGB, or "
10557                                                                           "COMPRESSED_SRGB_ALPHA.");
10558                 }
10559
10560                 /* Check that INVALID_OPERATION is generated if format does not match the
10561                  internal format of the texture image being modified, since these
10562                  commands do not provide for image format conversion. */
10563                 {
10564                         gl.compressedTextureSubImage2D(m_to_2D_compressed, 0, 0, 0, s_reference_width, s_reference_height,
10565                                                                                    m_not_matching_compressed_2D_format, m_not_matching_compressed_2D_size,
10566                                                                                    m_reference_compressed_2D);
10567                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage2D",
10568                                                                           "format does not match the internal format of the texture image being modified, "
10569                                                                           "since these commands do not provide for image format conversion.");
10570                 }
10571
10572                 /* Check that INVALID_VALUE is generated by CompressedTextureSubImage2D if
10573                  imageSize is not consistent with the format, dimensions, and contents of
10574                  the specified compressed image data. */
10575                 {
10576                         gl.compressedTextureSubImage2D(m_to_2D_compressed, 0, 0, 0, s_reference_width, s_reference_height,
10577                                                                                    m_reference_compressed_2D_format, m_reference_compressed_2D_size - 1,
10578                                                                                    m_reference_compressed_2D);
10579                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCompressedTextureSubImage2D",
10580                                                                           "imageSize is not consistent with the format, dimensions, and contents of the "
10581                                                                           "specified compressed image data.");
10582                 }
10583
10584                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage2D
10585                  if a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER
10586                  target and the buffer object's data store is currently mapped. */
10587                 {
10588                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10589                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10590
10591                         gl.mapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
10592
10593                         if (GL_NO_ERROR == gl.getError())
10594                         {
10595                                 gl.compressedTextureSubImage2D(m_to_2D_compressed, 0, 0, 0, s_reference_width, s_reference_height,
10596                                                                                            m_reference_compressed_2D_format, m_reference_compressed_2D_size, NULL);
10597                                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage2D",
10598                                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target "
10599                                                                                   "and the buffer object's data store is currently mapped.");
10600
10601                                 gl.unmapBuffer(GL_PIXEL_UNPACK_BUFFER);
10602                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10603
10604                                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10605                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10606                         }
10607                 }
10608
10609                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage2D
10610                  if a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER
10611                  target and the data would be unpacked from the buffer object such that
10612                  the memory reads required would exceed the data store size. */
10613                 {
10614                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10615                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10616
10617                         gl.compressedTextureSubImage2D(m_to_2D_compressed, 0, 0, 0, s_reference_width, s_reference_height,
10618                                                                                    m_reference_compressed_2D_format, m_reference_compressed_2D_size,
10619                                                                                    (glw::GLubyte*)NULL + s_reference_size * 2);
10620                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage2D",
10621                                                                           "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and "
10622                                                                           "the buffer object's data store is currently mapped.");
10623
10624                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10625                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10626                 }
10627
10628                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage2D
10629                  if the effective target is TEXTURE_RECTANGLE. */
10630                 if (DE_NULL !=
10631                         m_reference_compressed_rectangle) /* Do test only if rectangle compressed texture is supported by the implementation. */
10632                 {
10633                         gl.compressedTextureSubImage2D(m_to_rectangle_compressed, 0, 0, 0, s_reference_width, s_reference_height,
10634                                                                                    m_reference_compressed_rectangle_format,
10635                                                                                    m_reference_compressed_rectangle_size, m_reference_compressed_rectangle);
10636
10637                         if (m_context.getContextInfo().isExtensionSupported("GL_NV_texture_rectangle_compressed"))
10638                         {
10639                                 is_ok &= CheckErrorAndLog(m_context, GL_NO_ERROR, "glCompressedTextureSubImage2D",
10640                                                                                   "a rectangle texture object is used with this function.");
10641                         }
10642                         else
10643                         {
10644                                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage2D",
10645                                                                                   "a rectangle texture object is used with this function.");
10646                         }
10647                 }
10648         }
10649
10650         return is_ok;
10651 }
10652
10653 /** @brief Test (negative) of TextureSubImage3DCompressed
10654  *
10655  *  @return Test result.
10656  */
10657 bool SubImageErrorsTest::Test3DCompressed()
10658 {
10659         /* Shortcut for GL functionality. */
10660         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10661
10662         /* Result. */
10663         bool is_ok = true;
10664
10665         /* Do tests only if compressed 3D textures are supported. */
10666         if (DE_NULL != m_reference_compressed_3D)
10667         {
10668                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage3D
10669                  if texture is not the name of an existing texture object. */
10670                 {
10671                         gl.compressedTextureSubImage3D(m_to_invalid, 0, 0, 0, 0, s_reference_width, s_reference_height,
10672                                                                                    s_reference_depth, m_reference_compressed_3D_format,
10673                                                                                    m_reference_compressed_3D_size, m_reference_compressed_3D);
10674                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage3D",
10675                                                                           "texture is not the name of an existing texture object.");
10676                 }
10677
10678                 /* Check that INVALID_ENUM is generated by CompressedTextureSubImage3D if
10679                  internalformat is of the generic compressed internal formats:
10680                  COMPRESSED_RED, COMPRESSED_RG, COMPRESSED_RGB, COMPRESSED_RGBA.
10681                  COMPRESSED_SRGB, or COMPRESSED_SRGB_ALPHA. */
10682                 {
10683                         gl.compressedTextureSubImage3D(m_to_3D_compressed, 0, 0, 0, 0, s_reference_width, s_reference_height,
10684                                                                                    s_reference_depth, GL_COMPRESSED_RG, m_reference_compressed_3D_size,
10685                                                                                    m_reference_compressed_3D);
10686                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glCompressedTextureSubImage3D",
10687                                                                           "internalformat is of the generic compressed internal formats: COMPRESSED_RED, "
10688                                                                           "COMPRESSED_RG, COMPRESSED_RGB, COMPRESSED_RGBA. COMPRESSED_SRGB, or "
10689                                                                           "COMPRESSED_SRGB_ALPHA.");
10690                 }
10691
10692                 /* Check that INVALID_OPERATION is generated if format does not match the
10693                  internal format of the texture image being modified, since these
10694                  commands do not provide for image format conversion. */
10695                 {
10696                         gl.compressedTextureSubImage3D(m_to_3D_compressed, 0, 0, 0, 0, s_reference_width, s_reference_height,
10697                                                                                    s_reference_depth, m_not_matching_compressed_3D_format,
10698                                                                                    m_not_matching_compressed_3D_size, m_reference_compressed_3D);
10699                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage3D",
10700                                                                           "format does not match the internal format of the texture image being modified, "
10701                                                                           "since these commands do not provide for image format conversion.");
10702                 }
10703
10704                 /* Check that INVALID_VALUE is generated by CompressedTextureSubImage3D if
10705                  imageSize is not consistent with the format, dimensions, and contents of
10706                  the specified compressed image data. */
10707                 {
10708                         gl.compressedTextureSubImage3D(m_to_3D_compressed, 0, 0, 0, 0, s_reference_width, s_reference_height,
10709                                                                                    s_reference_depth, m_reference_compressed_3D_format,
10710                                                                                    m_reference_compressed_3D_size - 1, m_reference_compressed_3D);
10711                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCompressedTextureSubImage3D",
10712                                                                           "imageSize is not consistent with the format, dimensions, and contents of the "
10713                                                                           "specified compressed image data.");
10714                 }
10715
10716                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage3D
10717                  if a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER
10718                  target and the buffer object's data store is currently mapped. */
10719                 {
10720                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10721                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10722
10723                         gl.mapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
10724
10725                         if (GL_NO_ERROR == gl.getError())
10726                         {
10727                                 gl.compressedTextureSubImage3D(m_to_3D_compressed, 0, 0, 0, 0, s_reference_width, s_reference_height,
10728                                                                                            s_reference_depth, m_reference_compressed_3D_format,
10729                                                                                            m_reference_compressed_3D_size, NULL);
10730                                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage3D",
10731                                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target "
10732                                                                                   "and the buffer object's data store is currently mapped.");
10733
10734                                 gl.unmapBuffer(GL_PIXEL_UNPACK_BUFFER);
10735                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10736
10737                                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10738                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10739                         }
10740                 }
10741
10742                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage3D
10743                  if a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER
10744                  target and the data would be unpacked from the buffer object such that
10745                  the memory reads required would exceed the data store size. */
10746                 {
10747                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10748                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10749
10750                         gl.compressedTextureSubImage3D(m_to_3D_compressed, 0, 0, 0, 0, s_reference_width, s_reference_height,
10751                                                                                    s_reference_depth, m_reference_compressed_3D_format,
10752                                                                                    m_reference_compressed_3D_size, (glw::GLubyte*)NULL + s_reference_size * 2);
10753                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage3D",
10754                                                                           "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and "
10755                                                                           "the buffer object's data store is currently mapped.");
10756
10757                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10758                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10759                 }
10760         }
10761
10762         return is_ok;
10763 }
10764
10765 /** @brief Clean GL objects, test variables and GL errors.
10766  */
10767 void SubImageErrorsTest::Clean()
10768 {
10769         /* Shortcut for GL functionality. */
10770         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10771
10772         /* Cleanup. */
10773         if (m_to_1D_empty)
10774         {
10775                 gl.deleteTextures(1, &m_to_1D_empty);
10776
10777                 m_to_1D_empty = 0;
10778         }
10779
10780         if (m_to_2D_empty)
10781         {
10782                 gl.deleteTextures(1, &m_to_2D_empty);
10783
10784                 m_to_2D_empty = 0;
10785         }
10786
10787         if (m_to_3D_empty)
10788         {
10789                 gl.deleteTextures(1, &m_to_3D_empty);
10790
10791                 m_to_3D_empty = 0;
10792         }
10793
10794         if (m_to_1D)
10795         {
10796                 gl.deleteTextures(1, &m_to_1D);
10797
10798                 m_to_1D = 0;
10799         }
10800
10801         if (m_to_2D)
10802         {
10803                 gl.deleteTextures(1, &m_to_2D);
10804
10805                 m_to_2D = 0;
10806         }
10807
10808         if (m_to_3D)
10809         {
10810                 gl.deleteTextures(1, &m_to_3D);
10811
10812                 m_to_3D = 0;
10813         }
10814
10815         if (m_to_1D_compressed)
10816         {
10817                 gl.deleteTextures(1, &m_to_1D_compressed);
10818
10819                 m_to_1D_compressed = 0;
10820         }
10821
10822         if (m_to_2D_compressed)
10823         {
10824                 gl.deleteTextures(1, &m_to_2D_compressed);
10825
10826                 m_to_2D_compressed = 0;
10827         }
10828
10829         if (m_to_3D_compressed)
10830         {
10831                 gl.deleteTextures(1, &m_to_3D_compressed);
10832
10833                 m_to_3D_compressed = 0;
10834         }
10835
10836         if (m_to_rectangle_compressed)
10837         {
10838                 gl.deleteTextures(1, &m_to_rectangle_compressed);
10839
10840                 m_to_rectangle_compressed = 0;
10841         }
10842
10843         if (m_bo)
10844         {
10845                 gl.deleteBuffers(1, &m_bo);
10846
10847                 m_bo = 0;
10848         }
10849
10850         m_to_invalid       = 0;
10851         m_format_invalid   = 0;
10852         m_type_invalid   = 0;
10853         m_max_texture_size = 1;
10854
10855         if (DE_NULL != m_reference_compressed_1D)
10856         {
10857                 delete[] m_reference_compressed_1D;
10858
10859                 m_reference_compressed_1D = NULL;
10860         }
10861
10862         if (DE_NULL != m_reference_compressed_2D)
10863         {
10864                 delete[] m_reference_compressed_2D;
10865
10866                 m_reference_compressed_2D = NULL;
10867         }
10868
10869         if (DE_NULL != m_reference_compressed_3D)
10870         {
10871                 delete[] m_reference_compressed_3D;
10872
10873                 m_reference_compressed_3D = NULL;
10874         }
10875
10876         if (DE_NULL != m_reference_compressed_rectangle)
10877         {
10878                 delete[] m_reference_compressed_rectangle;
10879
10880                 m_reference_compressed_rectangle = NULL;
10881         }
10882
10883         m_reference_compressed_1D_format                = 0;
10884         m_reference_compressed_2D_format                = 0;
10885         m_reference_compressed_3D_format                = 0;
10886         m_reference_compressed_rectangle_format = 0;
10887         m_reference_compressed_1D_size                  = 0;
10888         m_reference_compressed_2D_size                  = 0;
10889         m_reference_compressed_3D_size                  = 0;
10890         m_reference_compressed_rectangle_size   = 0;
10891         m_not_matching_compressed_1D_format             = 0;
10892         m_not_matching_compressed_1D_size               = 0;
10893         m_not_matching_compressed_2D_format             = 0;
10894         m_not_matching_compressed_2D_size               = 0;
10895         m_not_matching_compressed_3D_format             = 0;
10896         m_not_matching_compressed_3D_size               = 0;
10897
10898         while (GL_NO_ERROR != gl.getError())
10899                 ;
10900 }
10901
10902 /** Reference data */
10903 const glw::GLushort SubImageErrorsTest::s_reference[] = {
10904         0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
10905         0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
10906         0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
10907         0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff,
10908
10909         0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
10910         0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
10911         0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
10912         0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff,
10913
10914         0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
10915         0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
10916         0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
10917         0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff,
10918
10919         0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
10920         0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
10921         0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
10922         0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff
10923 };
10924
10925 /** Reference data parameters. */
10926 const glw::GLuint SubImageErrorsTest::s_reference_size                                          = sizeof(s_reference);
10927 const glw::GLuint SubImageErrorsTest::s_reference_width                                         = 4;
10928 const glw::GLuint SubImageErrorsTest::s_reference_height                                        = 4;
10929 const glw::GLuint SubImageErrorsTest::s_reference_depth                                         = 4;
10930 const glw::GLenum SubImageErrorsTest::s_reference_internalformat                        = GL_RG8;
10931 const glw::GLenum SubImageErrorsTest::s_reference_internalformat_compressed = GL_COMPRESSED_RG;
10932 const glw::GLenum SubImageErrorsTest::s_reference_format = GL_RG; /* !Must not be a RGB, RGBA, or BGRA */
10933 const glw::GLenum SubImageErrorsTest::s_reference_type   = GL_UNSIGNED_SHORT;
10934
10935 /******************************** Copy Errors Test Implementation   ********************************/
10936
10937 /** @brief Copy Errors Test constructor.
10938  *
10939  *  @param [in] context     OpenGL context.
10940  */
10941 CopyErrorsTest::CopyErrorsTest(deqp::Context& context)
10942         : deqp::TestCase(context, "textures_copy_errors", "Texture Copy Errors Test")
10943         , m_fbo(0)
10944         , m_fbo_ms(0)
10945         , m_fbo_incomplete(0)
10946         , m_to_src(0)
10947         , m_to_src_ms(0)
10948         , m_to_1D_dst(0)
10949         , m_to_2D_dst(0)
10950         , m_to_3D_dst(0)
10951         , m_to_invalid(0)
10952 {
10953         /* Intentionally left blank. */
10954 }
10955
10956 /** @brief Iterate Copy Errors Test cases.
10957  *
10958  *  @return Iteration result.
10959  */
10960 tcu::TestNode::IterateResult CopyErrorsTest::iterate()
10961 {
10962         /* Get context setup. */
10963         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
10964         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
10965
10966         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
10967         {
10968                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
10969
10970                 return STOP;
10971         }
10972
10973         /* Running tests. */
10974         bool is_ok      = true;
10975         bool is_error = false;
10976
10977         try
10978         {
10979                 Prepare();
10980
10981                 is_ok &= Test1D();
10982                 is_ok &= Test2D();
10983                 is_ok &= Test3D();
10984         }
10985         catch (...)
10986         {
10987                 is_ok   = false;
10988                 is_error = true;
10989         }
10990
10991         /* Cleanup. */
10992         Clean();
10993
10994         /* Result's setup. */
10995         if (is_ok)
10996         {
10997                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
10998         }
10999         else
11000         {
11001                 if (is_error)
11002                 {
11003                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
11004                 }
11005                 else
11006                 {
11007                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
11008                 }
11009         }
11010
11011         return STOP;
11012 }
11013
11014 /** @brief Prepare test's objects and values.
11015  */
11016 void CopyErrorsTest::Prepare()
11017 {
11018         /* Shortcut for GL functionality. */
11019         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11020
11021         /* Auxiliary objects setup. */
11022
11023         /* Framebuffer. */
11024         gl.genFramebuffers(1, &m_fbo);
11025         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
11026
11027         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
11028         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11029
11030         gl.createTextures(GL_TEXTURE_2D, 1, &m_to_src);
11031         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
11032
11033         gl.textureStorage2D(m_to_src, 1, s_internalformat, s_width, s_height);
11034         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2D has failed");
11035
11036         gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_to_src, 0);
11037         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture1D call failed.");
11038
11039         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
11040         {
11041                 throw 0;
11042         }
11043
11044         gl.viewport(0, 0, s_width, s_height);
11045         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
11046
11047         gl.clear(GL_COLOR_BUFFER_BIT);
11048         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
11049
11050         /* Framebuffer Multisample. */
11051         gl.genFramebuffers(1, &m_fbo_ms);
11052         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
11053
11054         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
11055         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11056
11057         gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &m_to_src_ms);
11058         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
11059
11060         gl.textureStorage2DMultisample(m_to_src_ms, 1, s_internalformat, s_width, s_height, false);
11061         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2DMultisample has failed");
11062
11063         gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, m_to_src_ms, 0);
11064         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture1D call failed.");
11065
11066         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
11067         {
11068                 throw 0;
11069         }
11070
11071         gl.viewport(0, 0, s_width, s_height);
11072         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
11073
11074         gl.clear(GL_COLOR_BUFFER_BIT);
11075         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
11076
11077         /* Framebuffer Incomplete. */
11078         gl.createFramebuffers(1, &m_fbo_incomplete);
11079         GLU_EXPECT_NO_ERROR(gl.getError(), "glcreateFramebuffers call failed.");
11080
11081         /* 1D */
11082         gl.createTextures(GL_TEXTURE_1D, 1, &m_to_1D_dst);
11083         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
11084
11085         gl.textureStorage1D(m_to_1D_dst, 1, s_internalformat, s_width);
11086         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2D has failed");
11087
11088         /* 2D */
11089         gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D_dst);
11090         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
11091
11092         gl.textureStorage2D(m_to_2D_dst, 1, s_internalformat, s_width, s_height);
11093         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2D has failed");
11094
11095         /* 3D */
11096         gl.createTextures(GL_TEXTURE_3D, 1, &m_to_3D_dst);
11097         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
11098
11099         gl.textureStorage3D(m_to_3D_dst, 1, s_internalformat, s_width, s_height, s_depth);
11100         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2D has failed");
11101
11102         /* invalid texture object */
11103         while (gl.isTexture(++m_to_invalid))
11104                 ;
11105         GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed");
11106 }
11107
11108 /** @brief Test (negative) of CopyTextureSubImage1D
11109  *
11110  *  @return Test result.
11111  */
11112 bool CopyErrorsTest::Test1D()
11113 {
11114         /* Shortcut for GL functionality. */
11115         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11116
11117         /* Result. */
11118         bool is_ok = true;
11119
11120         /* Bind framebuffer. */
11121         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_incomplete);
11122         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11123
11124         /* Check that INVALID_FRAMEBUFFER_OPERATION is generated by
11125          CopyTextureSubImage1D if the object bound to READ_FRAMEBUFFER_BINDING is
11126          not framebuffer complete. */
11127         {
11128                 gl.copyTextureSubImage1D(m_to_1D_dst, 0, 0, 0, 0, s_width);
11129                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_FRAMEBUFFER_OPERATION, "glCopyTextureSubImage1D",
11130                                                                   "the object bound to READ_FRAMEBUFFER_BINDING is not framebuffer complete.");
11131         }
11132
11133         /* Bind framebuffer. */
11134         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
11135         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11136
11137         gl.readBuffer(GL_COLOR_ATTACHMENT0);
11138         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11139
11140         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage1D if
11141          texture is not the name of an existing texture object, or if the
11142          effective target of texture is not TEXTURE_1D. */
11143         {
11144                 gl.copyTextureSubImage1D(m_to_invalid, 0, 0, 0, 0, s_width);
11145                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage1D",
11146                                                                   "texture is not the name of an existing texture object.");
11147
11148                 gl.copyTextureSubImage1D(m_to_2D_dst, 0, 0, 0, 0, s_width);
11149                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage1D",
11150                                                                   "the effective target of texture is not TEXTURE_1D.");
11151         }
11152
11153         /* Check that INVALID_VALUE is generated by CopyTextureSubImage1D if level is less than 0. */
11154         {
11155                 gl.copyTextureSubImage1D(m_to_1D_dst, -1, 0, 0, 0, s_width);
11156                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage1D", "level is less than 0.");
11157         }
11158
11159         /* Check that INVALID_VALUE is generated by CopyTextureSubImage1D if
11160          xoffset<0, or (xoffset+width)>w, where w is the TEXTURE_WIDTH of the
11161          texture image being modified. */
11162         {
11163                 gl.copyTextureSubImage1D(m_to_1D_dst, 0, -1, 0, 0, s_width);
11164                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage1D", "xoffset<0.");
11165
11166                 gl.copyTextureSubImage1D(m_to_1D_dst, 0, 1, 0, 0, s_width);
11167                 is_ok &=
11168                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage1D",
11169                                                          "(xoffset+width)>w, where w is the TEXTURE_WIDTH of the texture image being modified.");
11170         }
11171
11172         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage1D if
11173          the read buffer is NONE. */
11174         gl.readBuffer(GL_NONE);
11175         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11176
11177         {
11178                 gl.copyTextureSubImage1D(m_to_1D_dst, 0, 0, 0, 0, s_width);
11179                 is_ok &=
11180                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage1D", "the read buffer is NONE.");
11181         }
11182
11183         /* Bind multisample framebuffer. */
11184         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
11185         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11186
11187         gl.readBuffer(GL_COLOR_ATTACHMENT0);
11188         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11189
11190         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage1D if
11191          the effective value of SAMPLE_BUFFERS for the read
11192          framebuffer is one. */
11193         {
11194                 gl.copyTextureSubImage1D(m_to_1D_dst, 0, 0, 0, 0, s_width);
11195                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage1D",
11196                                                                   "the effective value of SAMPLE_BUFFERS for the read framebuffer is one.");
11197         }
11198
11199         return is_ok;
11200 }
11201
11202 /** @brief Test (negative) of CopyTextureSubImage2D
11203  *
11204  *  @return Test result.
11205  */
11206 bool CopyErrorsTest::Test2D()
11207 {
11208         /* Shortcut for GL functionality. */
11209         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11210
11211         /* Result. */
11212         bool is_ok = true;
11213
11214         /* Bind framebuffer. */
11215         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_incomplete);
11216         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11217
11218         /* Check that INVALID_FRAMEBUFFER_OPERATION is generated by
11219          CopyTextureSubImage2D if the object bound to READ_FRAMEBUFFER_BINDING is
11220          not framebuffer complete. */
11221         {
11222                 gl.copyTextureSubImage2D(m_to_2D_dst, 0, 0, 0, 0, 0, s_width, s_height);
11223                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_FRAMEBUFFER_OPERATION, "glCopyTextureSubImage2D",
11224                                                                   "the object bound to READ_FRAMEBUFFER_BINDING is not framebuffer complete.");
11225         }
11226
11227         /* Bind framebuffer. */
11228         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
11229         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11230
11231         gl.readBuffer(GL_COLOR_ATTACHMENT0);
11232         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11233
11234         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage2D if
11235          texture is not the name of an existing texture object, or if the
11236          effective target of texture is not TEXTURE_2D. */
11237         {
11238                 gl.copyTextureSubImage2D(m_to_invalid, 0, 0, 0, 0, 0, s_width, s_height);
11239                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage2D",
11240                                                                   "texture is not the name of an existing texture object.");
11241
11242                 gl.copyTextureSubImage2D(m_to_1D_dst, 0, 0, 0, 0, 0, s_width, s_height);
11243                 is_ok &= CheckErrorAndLog(
11244                         m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage2D",
11245                         "the effective target of does not correspond to one of the texture targets supported by the function..");
11246         }
11247
11248         /* Check that INVALID_VALUE is generated by CopyTextureSubImage2D if level is less than 0. */
11249         {
11250                 gl.copyTextureSubImage2D(m_to_2D_dst, -1, 0, 0, 0, 0, s_width, s_height);
11251                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage2D", "level is less than 0.");
11252         }
11253
11254         /* Check that INVALID_VALUE is generated by CopyTextureSubImage2D if
11255          xoffset<0, (xoffset+width)>w, yoffset<0, or (yoffset+height)>0, where w
11256          is the TEXTURE_WIDTH, h is the TEXTURE_HEIGHT and of the texture image
11257          being modified. */
11258         {
11259                 gl.copyTextureSubImage2D(m_to_2D_dst, 0, -1, 0, 0, 0, s_width, s_height);
11260                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage2D", "xoffset<0.");
11261
11262                 gl.copyTextureSubImage2D(m_to_2D_dst, 0, 1, 0, 0, 0, s_width, s_height);
11263                 is_ok &=
11264                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage2D",
11265                                                          "(xoffset+width)>w, where w is the TEXTURE_WIDTH of the texture image being modified.");
11266
11267                 gl.copyTextureSubImage2D(m_to_2D_dst, 0, 0, -1, 0, 0, s_width, s_height);
11268                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage2D", "yoffset<0.");
11269
11270                 gl.copyTextureSubImage2D(m_to_2D_dst, 0, 0, 1, 0, 0, s_width, s_height);
11271                 is_ok &=
11272                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage2D",
11273                                                          "(yoffset+height)>h, where h is the TEXTURE_HEIGHT of the texture image being modified.");
11274         }
11275
11276         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage2D if
11277          the read buffer is NONE. */
11278         gl.readBuffer(GL_NONE);
11279         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11280
11281         {
11282                 gl.copyTextureSubImage2D(m_to_2D_dst, 0, 0, 0, 0, 0, s_width, s_height);
11283                 is_ok &=
11284                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage2D", "the read buffer is NONE.");
11285         }
11286
11287         /* Bind multisample framebuffer. */
11288         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
11289         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11290
11291         gl.readBuffer(GL_COLOR_ATTACHMENT0);
11292         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11293
11294         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage2D if
11295          the effective value of SAMPLE_BUFFERS for the read
11296          framebuffer is one. */
11297         {
11298                 gl.copyTextureSubImage2D(m_to_2D_dst, 0, 0, 0, 0, 0, s_width, s_height);
11299                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage2D",
11300                                                                   "the effective value of SAMPLE_BUFFERS for the read framebuffer is one.");
11301         }
11302
11303         return is_ok;
11304 }
11305
11306 /** @brief Test (negative) of CopyTextureSubImage3D
11307  *
11308  *  @return Test result.
11309  */
11310 bool CopyErrorsTest::Test3D()
11311 {
11312         /* Shortcut for GL functionality. */
11313         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11314
11315         /* Result. */
11316         bool is_ok = true;
11317
11318         /* Bind framebuffer. */
11319         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_incomplete);
11320         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11321
11322         /* Check that INVALID_FRAMEBUFFER_OPERATION is generated by
11323          CopyTextureSubImage3D if the object bound to READ_FRAMEBUFFER_BINDING is
11324          not framebuffer complete. */
11325         {
11326                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, 0, 0, 0, 0, s_width, s_height);
11327                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_FRAMEBUFFER_OPERATION, "glCopyTextureSubImage3D",
11328                                                                   "the object bound to READ_FRAMEBUFFER_BINDING is not framebuffer complete.");
11329         }
11330
11331         /* Bind framebuffer. */
11332         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
11333         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11334
11335         gl.readBuffer(GL_COLOR_ATTACHMENT0);
11336         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11337
11338         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage3D if
11339          texture is not the name of an existing texture object, or if the
11340          effective target of texture is not supported by the function. */
11341         {
11342                 gl.copyTextureSubImage3D(m_to_invalid, 0, 0, 0, 0, 0, 0, s_width, s_height);
11343                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage3D",
11344                                                                   "texture is not the name of an existing texture object.");
11345
11346                 gl.copyTextureSubImage3D(m_to_1D_dst, 0, 0, 0, 0, 0, 0, s_width, s_height);
11347                 is_ok &= CheckErrorAndLog(
11348                         m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage3D",
11349                         "the effective target of does not correspond to one of the texture targets supported by the function..");
11350         }
11351
11352         /* Check that INVALID_VALUE is generated by CopyTextureSubImage3D if level is less than 0. */
11353         {
11354                 gl.copyTextureSubImage3D(m_to_3D_dst, -1, 0, 0, 0, 0, 0, s_width, s_height);
11355                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D", "level is less than 0.");
11356         }
11357
11358         /* Check that INVALID_VALUE is generated by CopyTextureSubImage3D if
11359          xoffset<0, (xoffset+width)>w, yoffset<0, (yoffset+height)>h, zoffset<0,
11360          or (zoffset+1)>d, where w is the TEXTURE_WIDTH, h is the TEXTURE_HEIGHT,
11361          d is the TEXTURE_DEPTH and of the texture image being modified. Note
11362          that w, h, and d include twice the border width.  */
11363         {
11364                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, -1, 0, 0, 0, 0, s_width, s_height);
11365                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D", "xoffset<0.");
11366
11367                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, 1, 0, 0, 0, 0, s_width, s_height);
11368                 is_ok &=
11369                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D",
11370                                                          "(xoffset+width)>w, where w is the TEXTURE_WIDTH of the texture image being modified.");
11371
11372                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, -1, 0, 0, 0, s_width, s_height);
11373                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D", "yoffset<0.");
11374
11375                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, 1, 0, 0, 0, s_width, s_height);
11376                 is_ok &=
11377                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D",
11378                                                          "(yoffset+height)>h, where h is the TEXTURE_HEIGHT of the texture image being modified.");
11379
11380                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, 0, -1, 0, 0, s_width, s_height);
11381                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D", "zoffset<0.");
11382
11383                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, 0, s_depth + 1, 0, 0, s_width, s_height);
11384                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D",
11385                                                                   "(zoffset+1)>d, where d is the TEXTURE_DEPTH of the texture image being modified.");
11386         }
11387
11388         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage3D if
11389          the read buffer is NONE. */
11390         gl.readBuffer(GL_NONE);
11391         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11392
11393         {
11394                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, 0, 0, 0, 0, s_width, s_height);
11395                 is_ok &=
11396                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage3D", "the read buffer is NONE.");
11397         }
11398
11399         /* Bind multisample framebuffer. */
11400         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
11401         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11402
11403         gl.readBuffer(GL_COLOR_ATTACHMENT0);
11404         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11405
11406         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage3D if
11407          the effective value of SAMPLE_BUFFERS for the read
11408          framebuffer is one. */
11409         {
11410                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, 0, 0, 0, 0, s_width, s_height);
11411                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage3D",
11412                                                                   "the effective value of SAMPLE_BUFFERS for the read framebuffer is one.");
11413         }
11414
11415         return is_ok;
11416 }
11417
11418 /** @brief Clean GL objects, test variables and GL errors.
11419  */
11420 void CopyErrorsTest::Clean()
11421 {
11422         /* Shortcut for GL functionality. */
11423         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11424
11425         /* Cleanup. */
11426         if (m_fbo)
11427         {
11428                 gl.deleteFramebuffers(1, &m_fbo);
11429
11430                 m_fbo = 0;
11431         }
11432
11433         if (m_fbo_ms)
11434         {
11435                 gl.deleteFramebuffers(1, &m_fbo_ms);
11436
11437                 m_fbo_ms = 0;
11438         }
11439
11440         if (m_fbo_incomplete)
11441         {
11442                 gl.deleteFramebuffers(1, &m_fbo_incomplete);
11443
11444                 m_fbo_incomplete = 0;
11445         }
11446
11447         if (m_to_src)
11448         {
11449                 gl.deleteTextures(1, &m_to_src);
11450
11451                 m_to_src = 0;
11452         }
11453
11454         if (m_to_src_ms)
11455         {
11456                 gl.deleteTextures(1, &m_to_src_ms);
11457
11458                 m_to_src_ms = 0;
11459         }
11460
11461         if (m_to_1D_dst)
11462         {
11463                 gl.deleteTextures(1, &m_to_1D_dst);
11464
11465                 m_to_1D_dst = 0;
11466         }
11467
11468         if (m_to_2D_dst)
11469         {
11470                 gl.deleteTextures(1, &m_to_2D_dst);
11471
11472                 m_to_2D_dst = 0;
11473         }
11474
11475         if (m_to_3D_dst)
11476         {
11477                 gl.deleteTextures(1, &m_to_3D_dst);
11478
11479                 m_to_3D_dst = 0;
11480         }
11481
11482         m_to_invalid = 0;
11483
11484         while (GL_NO_ERROR != gl.getError())
11485                 ;
11486 }
11487
11488 /* Test's parameters. */
11489 const glw::GLuint CopyErrorsTest::s_width                  = 4;
11490 const glw::GLuint CopyErrorsTest::s_height                 = 4;
11491 const glw::GLuint CopyErrorsTest::s_depth                  = 4;
11492 const glw::GLuint CopyErrorsTest::s_internalformat = GL_RGBA8;
11493
11494 /******************************** Parameter Setup Errors Test Implementation   ********************************/
11495
11496 /** @brief Parameter Setup Errors Test constructor.
11497  *
11498  *  @param [in] context     OpenGL context.
11499  */
11500 ParameterSetupErrorsTest::ParameterSetupErrorsTest(deqp::Context& context)
11501         : deqp::TestCase(context, "textures_parameter_setup_errors", "Texture Parameter Setup Errors Test")
11502         , m_to_2D(0)
11503         , m_to_2D_ms(0)
11504         , m_to_rectangle(0)
11505         , m_to_invalid(0)
11506         , m_pname_invalid(0)
11507         , m_depth_stencil_mode_invalid(0)
11508 {
11509         /* Intentionally left blank. */
11510 }
11511
11512 /** @brief Iterate Parameter Setup Errors Test cases.
11513  *
11514  *  @return Iteration result.
11515  */
11516 tcu::TestNode::IterateResult ParameterSetupErrorsTest::iterate()
11517 {
11518         /* Get context setup. */
11519         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
11520         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
11521
11522         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
11523         {
11524                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
11525
11526                 return STOP;
11527         }
11528
11529         /* Running tests. */
11530         bool is_ok      = true;
11531         bool is_error = false;
11532
11533         try
11534         {
11535                 Prepare();
11536
11537                 is_ok &= Testf();
11538                 is_ok &= Testi();
11539                 is_ok &= Testfv();
11540                 is_ok &= Testiv();
11541                 is_ok &= TestIiv();
11542                 is_ok &= TestIuiv();
11543         }
11544         catch (...)
11545         {
11546                 is_ok   = false;
11547                 is_error = true;
11548         }
11549
11550         /* Cleanup. */
11551         Clean();
11552
11553         /* Result's setup. */
11554         if (is_ok)
11555         {
11556                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
11557         }
11558         else
11559         {
11560                 if (is_error)
11561                 {
11562                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
11563                 }
11564                 else
11565                 {
11566                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
11567                 }
11568         }
11569
11570         return STOP;
11571 }
11572
11573 /** @brief Test's preparations.
11574  */
11575 void ParameterSetupErrorsTest::Prepare()
11576 {
11577         /* Shortcut for GL functionality. */
11578         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11579
11580         /* Auxiliary objects setup. */
11581
11582         /* 2D */
11583         gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D);
11584         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
11585
11586         /* 3D */
11587         gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &m_to_2D_ms);
11588         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
11589
11590         /* RECTANGLE */
11591         gl.createTextures(GL_TEXTURE_RECTANGLE, 1, &m_to_rectangle);
11592         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
11593
11594         /* Invalid texture object. */
11595         while (gl.isTexture(++m_to_invalid))
11596                 ;
11597         GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed");
11598
11599         /* Invalid parameter name. */
11600         glw::GLenum all_pnames[] = { GL_DEPTH_STENCIL_TEXTURE_MODE,
11601                                                                  GL_TEXTURE_BASE_LEVEL,
11602                                                                  GL_TEXTURE_COMPARE_FUNC,
11603                                                                  GL_TEXTURE_COMPARE_MODE,
11604                                                                  GL_TEXTURE_LOD_BIAS,
11605                                                                  GL_TEXTURE_MIN_FILTER,
11606                                                                  GL_TEXTURE_MAG_FILTER,
11607                                                                  GL_TEXTURE_MIN_LOD,
11608                                                                  GL_TEXTURE_MAX_LOD,
11609                                                                  GL_TEXTURE_MAX_LEVEL,
11610                                                                  GL_TEXTURE_SWIZZLE_R,
11611                                                                  GL_TEXTURE_SWIZZLE_G,
11612                                                                  GL_TEXTURE_SWIZZLE_B,
11613                                                                  GL_TEXTURE_SWIZZLE_A,
11614                                                                  GL_TEXTURE_WRAP_S,
11615                                                                  GL_TEXTURE_WRAP_T,
11616                                                                  GL_TEXTURE_WRAP_R,
11617                                                                  GL_TEXTURE_BORDER_COLOR,
11618                                                                  GL_TEXTURE_SWIZZLE_RGBA };
11619         glw::GLuint all_pnames_count = sizeof(all_pnames) / sizeof(all_pnames[0]);
11620
11621         bool is_valid = true;
11622
11623         while (is_valid)
11624         {
11625                 is_valid = false;
11626                 ++m_pname_invalid;
11627
11628                 for (glw::GLuint i = 0; i < all_pnames_count; ++i)
11629                 {
11630                         if (all_pnames[i] == m_pname_invalid)
11631                         {
11632                                 is_valid = true;
11633
11634                                 break;
11635                         }
11636                 }
11637         }
11638
11639         /* Invalid depth stencil mode name. */
11640         glw::GLenum all_depth_stencil_modes[]    = { GL_DEPTH_COMPONENT, GL_STENCIL_INDEX };
11641         glw::GLuint all_depth_stencil_modes_count = sizeof(all_depth_stencil_modes) / sizeof(all_depth_stencil_modes[0]);
11642
11643         is_valid = true;
11644
11645         while (is_valid)
11646         {
11647                 is_valid = false;
11648                 ++m_depth_stencil_mode_invalid;
11649
11650                 for (glw::GLuint i = 0; i < all_depth_stencil_modes_count; ++i)
11651                 {
11652                         if (all_depth_stencil_modes[i] == m_depth_stencil_mode_invalid)
11653                         {
11654                                 is_valid = true;
11655
11656                                 break;
11657                         }
11658                 }
11659         }
11660 }
11661
11662 /** @brief Test (negative) of TextureParameterf
11663  *
11664  *  @return Test result.
11665  */
11666 bool ParameterSetupErrorsTest::Testf()
11667 {
11668         /* Shortcut for GL functionality. */
11669         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11670
11671         /* Result. */
11672         bool is_ok = true;
11673
11674         /* Check that INVALID_ENUM is generated by TextureParameter* if pname is
11675          not one of the accepted defined values. */
11676         {
11677                 gl.textureParameterf(m_to_2D, m_pname_invalid, 1.f);
11678
11679                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterf",
11680                                                                   "pname is not one of the accepted defined values.");
11681         }
11682
11683         /* Check that INVALID_ENUM is generated by TextureParameter* if params
11684          should have a defined constant value (based on the value of pname) and
11685          does not. */
11686         {
11687                 gl.textureParameterf(m_to_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, (glw::GLfloat)m_depth_stencil_mode_invalid);
11688
11689                 is_ok &=
11690                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterf",
11691                                                          "params should have a defined constant value (based on the value of pname) and does not.");
11692         }
11693         /* Check that INVALID_ENUM is generated if TextureParameter{if} is called
11694          for a non-scalar parameter (pname TEXTURE_BORDER_COLOR or
11695          TEXTURE_SWIZZLE_RGBA). */
11696         {
11697                 gl.textureParameterf(m_to_2D, GL_TEXTURE_BORDER_COLOR, 1.f);
11698
11699                 is_ok &=
11700                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterf",
11701                                                          "called for a non-scalar parameter (pname TEXTURE_BORDER_COLOR or TEXTURE_SWIZZLE_RGBA).");
11702         }
11703
11704         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11705          effective target is either TEXTURE_2D_MULTISAMPLE or
11706          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states. */
11707         {
11708                 gl.textureParameterf(m_to_2D_ms, GL_TEXTURE_LOD_BIAS, 1.f);
11709
11710                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterf",
11711                                                                   "the  effective target is either TEXTURE_2D_MULTISAMPLE or  "
11712                                                                   "TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states.");
11713         }
11714
11715         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11716          effective target is TEXTURE_RECTANGLE and either of pnames
11717          TEXTURE_WRAP_S or TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE,
11718          MIRRORED_REPEAT or REPEAT. */
11719         {
11720                 gl.textureParameterf(m_to_rectangle, GL_TEXTURE_WRAP_S, GL_MIRROR_CLAMP_TO_EDGE);
11721
11722                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterf",
11723                                                                   "the effective target is TEXTURE_RECTANGLE and either of pnames TEXTURE_WRAP_S or "
11724                                                                   "TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE, MIRRORED_REPEAT or REPEAT.");
11725         }
11726
11727         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11728          effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is
11729          set to a value other than NEAREST or LINEAR (no mipmap filtering is
11730          permitted). */
11731         {
11732                 gl.textureParameterf(m_to_rectangle, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
11733
11734                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterf",
11735                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is set to a "
11736                                                                   "value other than NEAREST or LINEAR (no mipmap filtering is permitted).");
11737         }
11738
11739         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
11740          effective target is either TEXTURE_2D_MULTISAMPLE or
11741          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname TEXTURE_BASE_LEVEL is set to a
11742          value other than zero. */
11743         {
11744                 gl.textureParameterf(m_to_2D_ms, GL_TEXTURE_BASE_LEVEL, 1.f);
11745
11746                 is_ok &=
11747                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterf",
11748                                                          "the effective target is either TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY, "
11749                                                          "and pname TEXTURE_BASE_LEVEL is set to a value other than zero.");
11750         }
11751
11752         /* Check that INVALID_OPERATION is generated by TextureParameter* if
11753          texture is not the name of an existing texture object. */
11754         {
11755                 gl.textureParameterf(m_to_invalid, GL_TEXTURE_LOD_BIAS, 1.f);
11756
11757                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterf",
11758                                                                   "texture is not the name of an existing texture object.");
11759         }
11760
11761         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
11762          effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is
11763          set to any value other than zero. */
11764         {
11765                 gl.textureParameterf(m_to_rectangle, GL_TEXTURE_BASE_LEVEL, 1.f);
11766
11767                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterf",
11768                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is set to "
11769                                                                   "any value other than zero. ");
11770         }
11771
11772         /* Check that INVALID_VALUE is generated by TextureParameter* if pname is
11773          TEXTURE_BASE_LEVEL or TEXTURE_MAX_LEVEL, and param or params is
11774          negative. */
11775         {
11776                 gl.textureParameterf(m_to_2D, GL_TEXTURE_BASE_LEVEL, -1.f);
11777
11778                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameterf",
11779                                                                   "pname is TEXTURE_BASE_LEVEL and param is negative.");
11780
11781                 gl.textureParameterf(m_to_2D, GL_TEXTURE_MAX_LEVEL, -1.f);
11782
11783                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameterf",
11784                                                                   "pname is TEXTURE_MAX_LEVEL and param is negative.");
11785         }
11786
11787         return is_ok;
11788 }
11789
11790 /** @brief Test (negative) of TextureParameteri
11791  *
11792  *  @return Test result.
11793  */
11794 bool ParameterSetupErrorsTest::Testi()
11795 {
11796         /* Shortcut for GL functionality. */
11797         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11798
11799         /* Result. */
11800         bool is_ok = true;
11801
11802         /* Check that INVALID_ENUM is generated by TextureParameter* if pname is
11803          not one of the accepted defined values. */
11804         {
11805                 gl.textureParameteri(m_to_2D, m_pname_invalid, 1);
11806
11807                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteri",
11808                                                                   "pname is not one of the accepted defined values.");
11809         }
11810
11811         /* Check that INVALID_ENUM is generated by TextureParameter* if params
11812          should have a defined constant value (based on the value of pname) and
11813          does not. */
11814         {
11815                 gl.textureParameteri(m_to_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, m_depth_stencil_mode_invalid);
11816
11817                 is_ok &=
11818                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteri",
11819                                                          "params should have a defined constant value (based on the value of pname) and does not.");
11820         }
11821         /* Check that INVALID_ENUM is generated if TextureParameter{if} is called
11822          for a non-scalar parameter (pname TEXTURE_BORDER_COLOR or
11823          TEXTURE_SWIZZLE_RGBA). */
11824         {
11825                 gl.textureParameteri(m_to_2D, GL_TEXTURE_BORDER_COLOR, 1);
11826
11827                 is_ok &=
11828                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteri",
11829                                                          "called for a non-scalar parameter (pname TEXTURE_BORDER_COLOR or TEXTURE_SWIZZLE_RGBA).");
11830         }
11831
11832         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11833          effective target is either TEXTURE_2D_MULTISAMPLE or
11834          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states. */
11835         {
11836                 gl.textureParameteri(m_to_2D_ms, GL_TEXTURE_LOD_BIAS, 1);
11837
11838                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteri",
11839                                                                   "the  effective target is either TEXTURE_2D_MULTISAMPLE or  "
11840                                                                   "TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states.");
11841         }
11842
11843         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11844          effective target is TEXTURE_RECTANGLE and either of pnames
11845          TEXTURE_WRAP_S or TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE,
11846          MIRRORED_REPEAT or REPEAT. */
11847         {
11848                 gl.textureParameteri(m_to_rectangle, GL_TEXTURE_WRAP_S, GL_MIRROR_CLAMP_TO_EDGE);
11849
11850                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteri",
11851                                                                   "the effective target is TEXTURE_RECTANGLE and either of pnames TEXTURE_WRAP_S or "
11852                                                                   "TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE, MIRRORED_REPEAT or REPEAT.");
11853         }
11854
11855         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11856          effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is
11857          set to a value other than NEAREST or LINEAR (no mipmap filtering is
11858          permitted). */
11859         {
11860                 gl.textureParameteri(m_to_rectangle, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
11861
11862                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteri",
11863                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is set to a "
11864                                                                   "value other than NEAREST or LINEAR (no mipmap filtering is permitted).");
11865         }
11866
11867         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
11868          effective target is either TEXTURE_2D_MULTISAMPLE or
11869          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname TEXTURE_BASE_LEVEL is set to a
11870          value other than zero. */
11871         {
11872                 gl.textureParameteri(m_to_2D_ms, GL_TEXTURE_BASE_LEVEL, 1);
11873
11874                 is_ok &=
11875                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteri",
11876                                                          "the effective target is either TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY, "
11877                                                          "and pname TEXTURE_BASE_LEVEL is set to a value other than zero.");
11878         }
11879
11880         /* Check that INVALID_OPERATION is generated by TextureParameter* if
11881          texture is not the name of an existing texture object. */
11882         {
11883                 gl.textureParameteri(m_to_invalid, GL_TEXTURE_LOD_BIAS, 1);
11884
11885                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteri",
11886                                                                   "texture is not the name of an existing texture object.");
11887         }
11888
11889         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
11890          effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is
11891          set to any value other than zero. */
11892         {
11893                 gl.textureParameteri(m_to_rectangle, GL_TEXTURE_BASE_LEVEL, 1);
11894
11895                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteri",
11896                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is set to "
11897                                                                   "any value other than zero. ");
11898         }
11899
11900         /* Check that INVALID_VALUE is generated by TextureParameter* if pname is
11901          TEXTURE_BASE_LEVEL or TEXTURE_MAX_LEVEL, and param or params is
11902          negative. */
11903         {
11904                 gl.textureParameteri(m_to_2D, GL_TEXTURE_BASE_LEVEL, -1);
11905
11906                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameteri",
11907                                                                   "pname is TEXTURE_BASE_LEVEL and param is negative.");
11908
11909                 gl.textureParameteri(m_to_2D, GL_TEXTURE_MAX_LEVEL, -1);
11910
11911                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameteri",
11912                                                                   "pname is TEXTURE_MAX_LEVEL and param is negative.");
11913         }
11914
11915         return is_ok;
11916 }
11917
11918 /** @brief Test (negative) of TextureParameterfv
11919  *
11920  *  @return Test result.
11921  */
11922 bool ParameterSetupErrorsTest::Testfv()
11923 {
11924         /* Shortcut for GL functionality. */
11925         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11926
11927         /* Result. */
11928         bool is_ok = true;
11929
11930         glw::GLfloat one                                                = 1.f;
11931         glw::GLfloat minus_one                                  = -1.f;
11932         glw::GLfloat depth_stencil_mode_invalid = (glw::GLfloat)m_depth_stencil_mode_invalid;
11933         glw::GLfloat wrap_invalid                               = (glw::GLfloat)GL_MIRROR_CLAMP_TO_EDGE;
11934         glw::GLfloat min_filter_invalid                 = (glw::GLfloat)GL_NEAREST_MIPMAP_NEAREST;
11935
11936         /* Check that INVALID_ENUM is generated by TextureParameter* if pname is
11937          not one of the accepted defined values. */
11938         {
11939                 gl.textureParameterfv(m_to_2D, m_pname_invalid, &one);
11940
11941                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterfv",
11942                                                                   "pname is not one of the accepted defined values.");
11943         }
11944
11945         /* Check that INVALID_ENUM is generated by TextureParameter* if params
11946          should have a defined constant value (based on the value of pname) and
11947          does not. */
11948         {
11949                 gl.textureParameterfv(m_to_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, &depth_stencil_mode_invalid);
11950
11951                 is_ok &=
11952                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterfv",
11953                                                          "params should have a defined constant value (based on the value of pname) and does not.");
11954         }
11955
11956         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11957          effective target is either TEXTURE_2D_MULTISAMPLE or
11958          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states. */
11959         {
11960                 gl.textureParameterfv(m_to_2D_ms, GL_TEXTURE_LOD_BIAS, &one);
11961
11962                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterfv",
11963                                                                   "the  effective target is either TEXTURE_2D_MULTISAMPLE or  "
11964                                                                   "TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states.");
11965         }
11966
11967         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11968          effective target is TEXTURE_RECTANGLE and either of pnames
11969          TEXTURE_WRAP_S or TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE,
11970          MIRRORED_REPEAT or REPEAT. */
11971         {
11972                 gl.textureParameterfv(m_to_rectangle, GL_TEXTURE_WRAP_S, &wrap_invalid);
11973
11974                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterfv",
11975                                                                   "the effective target is TEXTURE_RECTANGLE and either of pnames TEXTURE_WRAP_S or "
11976                                                                   "TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE, MIRRORED_REPEAT or REPEAT.");
11977         }
11978
11979         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11980          effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is
11981          set to a value other than NEAREST or LINEAR (no mipmap filtering is
11982          permitted). */
11983         {
11984                 gl.textureParameterfv(m_to_rectangle, GL_TEXTURE_MIN_FILTER, &min_filter_invalid);
11985
11986                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterfv",
11987                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is set to a "
11988                                                                   "value other than NEAREST or LINEAR (no mipmap filtering is permitted).");
11989         }
11990
11991         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
11992          effective target is either TEXTURE_2D_MULTISAMPLE or
11993          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname TEXTURE_BASE_LEVEL is set to a
11994          value other than zero. */
11995         {
11996                 gl.textureParameterfv(m_to_2D_ms, GL_TEXTURE_BASE_LEVEL, &one);
11997
11998                 is_ok &=
11999                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterfv",
12000                                                          "the effective target is either TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY, "
12001                                                          "and pname TEXTURE_BASE_LEVEL is set to a value other than zero.");
12002         }
12003
12004         /* Check that INVALID_OPERATION is generated by TextureParameter* if
12005          texture is not the name of an existing texture object. */
12006         {
12007                 gl.textureParameterfv(m_to_invalid, GL_TEXTURE_LOD_BIAS, &one);
12008
12009                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterfv",
12010                                                                   "texture is not the name of an existing texture object.");
12011         }
12012
12013         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12014          effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is
12015          set to any value other than zero. */
12016         {
12017                 gl.textureParameterfv(m_to_rectangle, GL_TEXTURE_BASE_LEVEL, &one);
12018
12019                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterfv",
12020                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is set to "
12021                                                                   "any value other than zero. ");
12022         }
12023
12024         /* Check that INVALID_VALUE is generated by TextureParameter* if pname is
12025          TEXTURE_BASE_LEVEL or TEXTURE_MAX_LEVEL, and param or params is
12026          negative. */
12027         {
12028                 gl.textureParameterfv(m_to_2D, GL_TEXTURE_BASE_LEVEL, &minus_one);
12029
12030                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameterfv",
12031                                                                   "pname is TEXTURE_BASE_LEVEL and param is negative.");
12032
12033                 gl.textureParameterfv(m_to_2D, GL_TEXTURE_MAX_LEVEL, &minus_one);
12034
12035                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameterfv",
12036                                                                   "pname is TEXTURE_MAX_LEVEL and param is negative.");
12037         }
12038
12039         return is_ok;
12040 }
12041
12042 /** @brief Test (negative) of TextureParameteriv
12043  *
12044  *  @return Test result.
12045  */
12046 bool ParameterSetupErrorsTest::Testiv()
12047 {
12048         /* Shortcut for GL functionality. */
12049         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
12050
12051         /* Result. */
12052         bool is_ok = true;
12053
12054         glw::GLint one                                            = 1;
12055         glw::GLint minus_one                              = -1;
12056         glw::GLint depth_stencil_mode_invalid = (glw::GLint)m_depth_stencil_mode_invalid;
12057         glw::GLint wrap_invalid                           = (glw::GLint)GL_MIRROR_CLAMP_TO_EDGE;
12058         glw::GLint min_filter_invalid             = (glw::GLint)GL_NEAREST_MIPMAP_NEAREST;
12059
12060         /* Check that INVALID_ENUM is generated by TextureParameter* if pname is
12061          not one of the accepted defined values. */
12062         {
12063                 gl.textureParameteriv(m_to_2D, m_pname_invalid, &one);
12064
12065                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteriv",
12066                                                                   "pname is not one of the accepted defined values.");
12067         }
12068
12069         /* Check that INVALID_ENUM is generated by TextureParameter* if params
12070          should have a defined constant value (based on the value of pname) and
12071          does not. */
12072         {
12073                 gl.textureParameteriv(m_to_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, &depth_stencil_mode_invalid);
12074
12075                 is_ok &=
12076                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteriv",
12077                                                          "params should have a defined constant value (based on the value of pname) and does not.");
12078         }
12079
12080         /* Check that INVALID_ENUM is generated by TextureParameter* if the
12081          effective target is either TEXTURE_2D_MULTISAMPLE or
12082          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states. */
12083         {
12084                 gl.textureParameteriv(m_to_2D_ms, GL_TEXTURE_LOD_BIAS, &one);
12085
12086                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteriv",
12087                                                                   "the  effective target is either TEXTURE_2D_MULTISAMPLE or  "
12088                                                                   "TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states.");
12089         }
12090
12091         /* Check that INVALID_ENUM is generated by TextureParameter* if the
12092          effective target is TEXTURE_RECTANGLE and either of pnames
12093          TEXTURE_WRAP_S or TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE,
12094          MIRRORED_REPEAT or REPEAT. */
12095         {
12096                 gl.textureParameteriv(m_to_rectangle, GL_TEXTURE_WRAP_S, &wrap_invalid);
12097
12098                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteriv",
12099                                                                   "the effective target is TEXTURE_RECTANGLE and either of pnames TEXTURE_WRAP_S or "
12100                                                                   "TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE, MIRRORED_REPEAT or REPEAT.");
12101         }
12102
12103         /* Check that INVALID_ENUM is generated by TextureParameter* if the
12104          effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is
12105          set to a value other than NEAREST or LINEAR (no mipmap filtering is
12106          permitted). */
12107         {
12108                 gl.textureParameteriv(m_to_rectangle, GL_TEXTURE_MIN_FILTER, &min_filter_invalid);
12109
12110                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteriv",
12111                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is set to a "
12112                                                                   "value other than NEAREST or LINEAR (no mipmap filtering is permitted).");
12113         }
12114
12115         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12116          effective target is either TEXTURE_2D_MULTISAMPLE or
12117          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname TEXTURE_BASE_LEVEL is set to a
12118          value other than zero. */
12119         {
12120                 gl.textureParameteriv(m_to_2D_ms, GL_TEXTURE_BASE_LEVEL, &one);
12121
12122                 is_ok &=
12123                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteriv",
12124                                                          "the effective target is either TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY, "
12125                                                          "and pname TEXTURE_BASE_LEVEL is set to a value other than zero.");
12126         }
12127
12128         /* Check that INVALID_OPERATION is generated by TextureParameter* if
12129          texture is not the name of an existing texture object. */
12130         {
12131                 gl.textureParameteriv(m_to_invalid, GL_TEXTURE_LOD_BIAS, &one);
12132
12133                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteriv",
12134                                                                   "texture is not the name of an existing texture object.");
12135         }
12136
12137         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12138          effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is
12139          set to any value other than zero. */
12140         {
12141                 gl.textureParameteriv(m_to_rectangle, GL_TEXTURE_BASE_LEVEL, &one);
12142
12143                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteriv",
12144                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is set to "
12145                                                                   "any value other than zero. ");
12146         }
12147
12148         /* Check that INVALID_VALUE is generated by TextureParameter* if pname is
12149          TEXTURE_BASE_LEVEL or TEXTURE_MAX_LEVEL, and param or params is
12150          negative. */
12151         {
12152                 gl.textureParameteriv(m_to_2D, GL_TEXTURE_BASE_LEVEL, &minus_one);
12153
12154                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameteriv",
12155                                                                   "pname is TEXTURE_BASE_LEVEL and param is negative.");
12156
12157                 gl.textureParameteriv(m_to_2D, GL_TEXTURE_MAX_LEVEL, &minus_one);
12158
12159                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameteriv",
12160                                                                   "pname is TEXTURE_MAX_LEVEL and param is negative.");
12161         }
12162
12163         return is_ok;
12164 }
12165
12166 /** @brief Test (negative) of TextureParameterIiv
12167  *
12168  *  @return Test result.
12169  */
12170 bool ParameterSetupErrorsTest::TestIiv()
12171 {
12172         /* Shortcut for GL functionality. */
12173         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
12174
12175         /* Result. */
12176         bool is_ok = true;
12177
12178         glw::GLint one                                            = 1;
12179         glw::GLint minus_one                              = -1;
12180         glw::GLint depth_stencil_mode_invalid = (glw::GLint)m_depth_stencil_mode_invalid;
12181         glw::GLint wrap_invalid                           = (glw::GLint)GL_MIRROR_CLAMP_TO_EDGE;
12182         glw::GLint min_filter_invalid             = (glw::GLint)GL_NEAREST_MIPMAP_NEAREST;
12183
12184         /* Check that INVALID_ENUM is generated by TextureParameter* if pname is
12185          not one of the accepted defined values. */
12186         {
12187                 gl.textureParameterIiv(m_to_2D, m_pname_invalid, &one);
12188
12189                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIiv",
12190                                                                   "pname is not one of the accepted defined values.");
12191         }
12192
12193         /* Check that INVALID_ENUM is generated by TextureParameter* if params
12194          should have a defined constant value (based on the value of pname) and
12195          does not. */
12196         {
12197                 gl.textureParameterIiv(m_to_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, &depth_stencil_mode_invalid);
12198
12199                 is_ok &=
12200                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIiv",
12201                                                          "params should have a defined constant value (based on the value of pname) and does not.");
12202         }
12203
12204         /* Check that INVALID_ENUM is generated by TextureParameter* if the
12205          effective target is either TEXTURE_2D_MULTISAMPLE or
12206          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states. */
12207         {
12208                 gl.textureParameterIiv(m_to_2D_ms, GL_TEXTURE_LOD_BIAS, &one);
12209
12210                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIiv",
12211                                                                   "the  effective target is either TEXTURE_2D_MULTISAMPLE or  "
12212                                                                   "TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states.");
12213         }
12214
12215         /* Check that INVALID_ENUM is generated by TextureParameter* if the
12216          effective target is TEXTURE_RECTANGLE and either of pnames
12217          TEXTURE_WRAP_S or TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE,
12218          MIRRORED_REPEAT or REPEAT. */
12219         {
12220                 gl.textureParameterIiv(m_to_rectangle, GL_TEXTURE_WRAP_S, &wrap_invalid);
12221
12222                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIiv",
12223                                                                   "the effective target is TEXTURE_RECTANGLE and either of pnames TEXTURE_WRAP_S or "
12224                                                                   "TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE, MIRRORED_REPEAT or REPEAT.");
12225         }
12226
12227         /* Check that INVALID_ENUM is generated by TextureParameter* if the
12228          effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is
12229          set to a value other than NEAREST or LINEAR (no mipmap filtering is
12230          permitted). */
12231         {
12232                 gl.textureParameterIiv(m_to_rectangle, GL_TEXTURE_MIN_FILTER, &min_filter_invalid);
12233
12234                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIiv",
12235                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is set to a "
12236                                                                   "value other than NEAREST or LINEAR (no mipmap filtering is permitted).");
12237         }
12238
12239         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12240          effective target is either TEXTURE_2D_MULTISAMPLE or
12241          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname TEXTURE_BASE_LEVEL is set to a
12242          value other than zero. */
12243         {
12244                 gl.textureParameterIiv(m_to_2D_ms, GL_TEXTURE_BASE_LEVEL, &one);
12245
12246                 is_ok &=
12247                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIiv",
12248                                                          "the effective target is either TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY, "
12249                                                          "and pname TEXTURE_BASE_LEVEL is set to a value other than zero.");
12250         }
12251
12252         /* Check that INVALID_OPERATION is generated by TextureParameter* if
12253          texture is not the name of an existing texture object. */
12254         {
12255                 gl.textureParameterIiv(m_to_invalid, GL_TEXTURE_LOD_BIAS, &one);
12256
12257                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIiv",
12258                                                                   "texture is not the name of an existing texture object.");
12259         }
12260
12261         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12262          effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is
12263          set to any value other than zero. */
12264         {
12265                 gl.textureParameterIiv(m_to_rectangle, GL_TEXTURE_BASE_LEVEL, &one);
12266
12267                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIiv",
12268                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is set to "
12269                                                                   "any value other than zero. ");
12270         }
12271
12272         /* Check that INVALID_VALUE is generated by TextureParameter* if pname is
12273          TEXTURE_BASE_LEVEL or TEXTURE_MAX_LEVEL, and param or params is
12274          negative. */
12275         {
12276                 gl.textureParameterIiv(m_to_2D, GL_TEXTURE_BASE_LEVEL, &minus_one);
12277
12278                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameterIiv",
12279                                                                   "pname is TEXTURE_BASE_LEVEL and param is negative.");
12280
12281                 gl.textureParameterIiv(m_to_2D, GL_TEXTURE_MAX_LEVEL, &minus_one);
12282
12283                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameterIiv",
12284                                                                   "pname is TEXTURE_MAX_LEVEL and param is negative.");
12285         }
12286
12287         return is_ok;
12288 }
12289
12290 /** @brief Test (negative) of TextureParameterIuiv
12291  *
12292  *  @return Test result.
12293  */
12294 bool ParameterSetupErrorsTest::TestIuiv()
12295 {
12296         /* Shortcut for GL functionality. */
12297         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
12298
12299         /* Result. */
12300         bool is_ok = true;
12301
12302         glw::GLuint one                                            = 1;
12303         glw::GLuint depth_stencil_mode_invalid = (glw::GLint)m_depth_stencil_mode_invalid;
12304         glw::GLuint wrap_invalid                           = (glw::GLint)GL_MIRROR_CLAMP_TO_EDGE;
12305         glw::GLuint min_filter_invalid             = (glw::GLint)GL_NEAREST_MIPMAP_NEAREST;
12306
12307         /* Check that INVALID_ENUM is generated by TextureParameter* if pname is
12308          not one of the accepted defined values. */
12309         {
12310                 gl.textureParameterIuiv(m_to_2D, m_pname_invalid, &one);
12311
12312                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIuiv",
12313                                                                   "pname is not one of the accepted defined values.");
12314         }
12315
12316         /* Check that INVALID_ENUM is generated by TextureParameter* if params
12317          should have a defined constant value (based on the value of pname) and
12318          does not. */
12319         {
12320                 gl.textureParameterIuiv(m_to_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, &depth_stencil_mode_invalid);
12321
12322                 is_ok &=
12323                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIuiv",
12324                                                          "params should have a defined constant value (based on the value of pname) and does not.");
12325         }
12326
12327         /* Check that INVALID_ENUM is generated by TextureParameter* if the
12328          effective target is either TEXTURE_2D_MULTISAMPLE or
12329          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states. */
12330         {
12331                 gl.textureParameterIuiv(m_to_2D_ms, GL_TEXTURE_LOD_BIAS, &one);
12332
12333                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIuiv",
12334                                                                   "the  effective target is either TEXTURE_2D_MULTISAMPLE or  "
12335                                                                   "TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states.");
12336         }
12337
12338         /* Check that INVALID_ENUM is generated by TextureParameter* if the
12339          effective target is TEXTURE_RECTANGLE and either of pnames
12340          TEXTURE_WRAP_S or TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE,
12341          MIRRORED_REPEAT or REPEAT. */
12342         {
12343                 gl.textureParameterIuiv(m_to_rectangle, GL_TEXTURE_WRAP_S, &wrap_invalid);
12344
12345                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIuiv",
12346                                                                   "the effective target is TEXTURE_RECTANGLE and either of pnames TEXTURE_WRAP_S or "
12347                                                                   "TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE, MIRRORED_REPEAT or REPEAT.");
12348         }
12349
12350         /* Check that INVALID_ENUM is generated by TextureParameter* if the
12351          effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is
12352          set to a value other than NEAREST or LINEAR (no mipmap filtering is
12353          permitted). */
12354         {
12355                 gl.textureParameterIuiv(m_to_rectangle, GL_TEXTURE_MIN_FILTER, &min_filter_invalid);
12356
12357                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIuiv",
12358                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is set to a "
12359                                                                   "value other than NEAREST or LINEAR (no mipmap filtering is permitted).");
12360         }
12361
12362         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12363          effective target is either TEXTURE_2D_MULTISAMPLE or
12364          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname TEXTURE_BASE_LEVEL is set to a
12365          value other than zero. */
12366         {
12367                 gl.textureParameterIuiv(m_to_2D_ms, GL_TEXTURE_BASE_LEVEL, &one);
12368
12369                 is_ok &=
12370                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIuiv",
12371                                                          "the effective target is either TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY, "
12372                                                          "and pname TEXTURE_BASE_LEVEL is set to a value other than zero.");
12373         }
12374
12375         /* Check that INVALID_OPERATION is generated by TextureParameter* if
12376          texture is not the name of an existing texture object. */
12377         {
12378                 gl.textureParameterIuiv(m_to_invalid, GL_TEXTURE_LOD_BIAS, &one);
12379
12380                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIuiv",
12381                                                                   "texture is not the name of an existing texture object.");
12382         }
12383
12384         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12385          effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is
12386          set to any value other than zero. */
12387         {
12388                 gl.textureParameterIuiv(m_to_rectangle, GL_TEXTURE_BASE_LEVEL, &one);
12389
12390                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIuiv",
12391                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is set to "
12392                                                                   "any value other than zero. ");
12393         }
12394
12395         return is_ok;
12396 }
12397
12398 /** @brief Clean GL objects, test variables and GL errors.
12399  */
12400 void ParameterSetupErrorsTest::Clean()
12401 {
12402         /* Shortcut for GL functionality. */
12403         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
12404
12405         /* Cleanup. */
12406         if (m_to_2D)
12407         {
12408                 gl.deleteTextures(1, &m_to_2D);
12409
12410                 m_to_2D = 0;
12411         }
12412
12413         if (m_to_2D_ms)
12414         {
12415                 gl.deleteTextures(1, &m_to_2D_ms);
12416
12417                 m_to_2D_ms = 0;
12418         }
12419
12420         if (m_to_rectangle)
12421         {
12422                 gl.deleteTextures(1, &m_to_rectangle);
12423
12424                 m_to_rectangle = 0;
12425         }
12426
12427         if (m_to_invalid)
12428         {
12429                 gl.deleteTextures(1, &m_to_invalid);
12430
12431                 m_to_invalid = 0;
12432         }
12433
12434         m_to_invalid    = 0;
12435         m_pname_invalid = 0;
12436
12437         while (GL_NO_ERROR != gl.getError())
12438                 ;
12439 }
12440
12441 /******************************** Generate Mipmap Errors Test Implementation   ********************************/
12442
12443 /** @brief Generate Mipmap Errors Test constructor.
12444  *
12445  *  @param [in] context     OpenGL context.
12446  */
12447 GenerateMipmapErrorsTest::GenerateMipmapErrorsTest(deqp::Context& context)
12448         : deqp::TestCase(context, "textures_generate_mipmap_errors", "Texture Generate Mipmap Errors Test")
12449 {
12450         /* Intentionally left blank. */
12451 }
12452
12453 /** @brief Iterate Generate Mipmap Errors Test cases.
12454  *
12455  *  @return Iteration result.
12456  */
12457 tcu::TestNode::IterateResult GenerateMipmapErrorsTest::iterate()
12458 {
12459         /* Shortcut for GL functionality. */
12460         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
12461
12462         /* Get context setup. */
12463         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
12464         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
12465
12466         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
12467         {
12468                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
12469
12470                 return STOP;
12471         }
12472
12473         /* Running tests. */
12474         bool is_ok      = true;
12475         bool is_error = false;
12476
12477         /* Objects. */
12478         glw::GLuint texture_invalid = 0;
12479         glw::GLuint texture_cube        = 0;
12480
12481         try
12482         {
12483                 /* Preparations. */
12484
12485                 /* incomplete cube map */
12486                 gl.genTextures(1, &texture_cube);
12487                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12488
12489                 gl.bindTexture(GL_TEXTURE_CUBE_MAP, texture_cube);
12490                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12491
12492                 gl.texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, s_reference_internalformat, s_reference_width,
12493                                           s_reference_height, 0, s_reference_format, s_reference_type, s_reference_data);
12494                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12495
12496                 /* invalid texture */
12497                 while (gl.isTexture(++texture_invalid))
12498                         ;
12499
12500                 /* Check that INVALID_OPERATION is generated by GenerateTextureMipmap if
12501                  texture is not the name of an existing texture object. */
12502                 gl.generateTextureMipmap(texture_invalid);
12503                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGenerateTextureMipmap",
12504                                                                   "texture is not the name of an existing texture object.");
12505
12506                 /* Check that INVALID_OPERATION is generated by GenerateTextureMipmap if
12507                  target is TEXTURE_CUBE_MAP or TEXTURE_CUBE_MAP_ARRAY, and the specified
12508                  texture object is not cube complete or cube array complete,
12509                  respectively. */
12510                 gl.generateTextureMipmap(texture_cube);
12511                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGenerateTextureMipmap",
12512                                                                   "target is TEXTURE_CUBE_MAP or TEXTURE_CUBE_MAP_ARRAY, and the specified texture "
12513                                                                   "object is not cube complete or cube array complete, respectively.");
12514         }
12515         catch (...)
12516         {
12517                 is_ok   = false;
12518                 is_error = true;
12519         }
12520
12521         /* Cleanup. */
12522         if (texture_cube)
12523         {
12524                 gl.deleteTextures(1, &texture_cube);
12525         }
12526
12527         while (GL_NO_ERROR != gl.getError())
12528                 ;
12529
12530         /* Result's setup. */
12531         if (is_ok)
12532         {
12533                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
12534         }
12535         else
12536         {
12537                 if (is_error)
12538                 {
12539                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
12540                 }
12541                 else
12542                 {
12543                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
12544                 }
12545         }
12546
12547         return STOP;
12548 }
12549
12550 /** Reference data. */
12551 const glw::GLubyte GenerateMipmapErrorsTest::s_reference_data[] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
12552                                                                                                                                         0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF };
12553
12554 /** Reference data parameters. */
12555 const glw::GLuint GenerateMipmapErrorsTest::s_reference_width              = 4;
12556 const glw::GLuint GenerateMipmapErrorsTest::s_reference_height             = 4;
12557 const glw::GLenum GenerateMipmapErrorsTest::s_reference_internalformat = GL_R8;
12558 const glw::GLenum GenerateMipmapErrorsTest::s_reference_format             = GL_RED;
12559 const glw::GLenum GenerateMipmapErrorsTest::s_reference_type               = GL_UNSIGNED_BYTE;
12560
12561 /******************************** Bind Unit Errors Test Implementation   ********************************/
12562
12563 /** @brief Bind Unit Errors Test constructor.
12564  *
12565  *  @param [in] context     OpenGL context.
12566  */
12567 BindUnitErrorsTest::BindUnitErrorsTest(deqp::Context& context)
12568         : deqp::TestCase(context, "textures_bind_unit_errors", "Texture Bind Unit Errors Test")
12569 {
12570         /* Intentionally left blank. */
12571 }
12572
12573 /** @brief IterateBind Unit Errors Test cases.
12574  *
12575  *  @return Iteration result.
12576  */
12577 tcu::TestNode::IterateResult BindUnitErrorsTest::iterate()
12578 {
12579         /* Shortcut for GL functionality. */
12580         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
12581
12582         /* Get context setup. */
12583         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
12584         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
12585
12586         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
12587         {
12588                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
12589
12590                 return STOP;
12591         }
12592
12593         /* Running tests. */
12594         bool is_ok      = true;
12595         bool is_error = false;
12596
12597         /* Objects. */
12598         glw::GLuint texture_invalid = 0;
12599
12600         try
12601         {
12602                 /* Prepare invalid texture */
12603                 while (gl.isTexture(++texture_invalid))
12604                         ;
12605
12606                 /* incomplete cube map */
12607
12608                 /* Check that INVALID_OPERATION error is generated if texture is not zero
12609                  or the name of an existing texture object. */
12610                 gl.bindTextureUnit(0, texture_invalid);
12611                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glBindTextureUnit",
12612                                                                   "texture is not zero or the name of an existing texture object.");
12613         }
12614         catch (...)
12615         {
12616                 is_ok   = false;
12617                 is_error = true;
12618         }
12619
12620         /* Cleanup. */
12621         while (GL_NO_ERROR != gl.getError())
12622                 ;
12623
12624         /* Result's setup. */
12625         if (is_ok)
12626         {
12627                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
12628         }
12629         else
12630         {
12631                 if (is_error)
12632                 {
12633                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
12634                 }
12635                 else
12636                 {
12637                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
12638                 }
12639         }
12640
12641         return STOP;
12642 }
12643
12644 /******************************** Image Query Errors Test Implementation   ********************************/
12645
12646 /** @brief Image Query Errors Test constructor.
12647  *
12648  *  @param [in] context     OpenGL context.
12649  */
12650 ImageQueryErrorsTest::ImageQueryErrorsTest(deqp::Context& context)
12651         : deqp::TestCase(context, "textures_image_query_errors", "Texture Image Query Errors Test")
12652 {
12653         /* Intentionally left blank. */
12654 }
12655
12656 /** Reference data. */
12657 const glw::GLuint ImageQueryErrorsTest::s_reference_data[] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
12658                                                                                                                            0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF };
12659
12660 /** Reference data parameters. */
12661 const glw::GLuint ImageQueryErrorsTest::s_reference_width                                         = 4;
12662 const glw::GLuint ImageQueryErrorsTest::s_reference_height                                        = 4;
12663 const glw::GLuint ImageQueryErrorsTest::s_reference_size                                          = sizeof(s_reference_data);
12664 const glw::GLenum ImageQueryErrorsTest::s_reference_internalformat                        = GL_R8;
12665 const glw::GLenum ImageQueryErrorsTest::s_reference_internalformat_int            = GL_R8I;
12666 const glw::GLenum ImageQueryErrorsTest::s_reference_internalformat_compressed = GL_COMPRESSED_RED_RGTC1;
12667 const glw::GLenum ImageQueryErrorsTest::s_reference_format                                        = GL_RED;
12668 const glw::GLenum ImageQueryErrorsTest::s_reference_type                                          = GL_UNSIGNED_INT;
12669
12670 /** @brief Iterate Image Query Errors Test cases.
12671  *
12672  *  @return Iteration result.
12673  */
12674 tcu::TestNode::IterateResult ImageQueryErrorsTest::iterate()
12675 {
12676         /* Shortcut for GL functionality. */
12677         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
12678
12679         /* Get context setup. */
12680         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
12681         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
12682
12683         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
12684         {
12685                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
12686
12687                 return STOP;
12688         }
12689
12690         /* Running tests. */
12691         bool is_ok      = true;
12692         bool is_error = false;
12693
12694         /* Objects. */
12695         glw::GLuint buffer                                                                                = 0;
12696         glw::GLuint texture_invalid                                                               = 0;
12697         glw::GLuint texture_2D                                                                    = 0;
12698         glw::GLuint texture_2D_int                                                                = 0;
12699         glw::GLuint texture_2D_ms                                                                 = 0;
12700         glw::GLuint texture_2D_stencil                                                    = 0;
12701         glw::GLuint texture_2D_compressed                                                 = 0;
12702         glw::GLuint texture_cube                                                                  = 0;
12703         glw::GLuint texture_rectangle                                                     = 0;
12704         glw::GLint  max_level                                                                     = 0;
12705         char            store[s_reference_size * 6 /* for cubemap */] = {};
12706
12707         try
12708         {
12709                 /* Preparations. */
12710
12711                 /* Buffer. */
12712                 gl.createBuffers(1, &buffer);
12713
12714                 gl.namedBufferData(buffer, s_reference_size + 1, NULL, GL_STATIC_COPY);
12715                 GLU_EXPECT_NO_ERROR(gl.getError(), "glNamedBufferData has failed");
12716
12717                 /* 2D texture */
12718                 gl.genTextures(1, &texture_2D);
12719                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12720
12721                 gl.bindTexture(GL_TEXTURE_2D, texture_2D);
12722                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12723
12724                 gl.texImage2D(GL_TEXTURE_2D, 0, s_reference_internalformat, s_reference_width, s_reference_height, 0,
12725                                           s_reference_format, s_reference_type, s_reference_data);
12726                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12727
12728                 /* 2D texture */
12729                 gl.genTextures(1, &texture_2D);
12730                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12731
12732                 gl.bindTexture(GL_TEXTURE_2D, texture_2D);
12733                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12734
12735                 gl.texImage2D(GL_TEXTURE_2D, 0, s_reference_internalformat, s_reference_width, s_reference_height, 0,
12736                                           s_reference_format, s_reference_type, s_reference_data);
12737                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12738
12739                 /* incomplete cube map */
12740                 gl.genTextures(1, &texture_cube);
12741                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12742
12743                 gl.bindTexture(GL_TEXTURE_CUBE_MAP, texture_cube);
12744                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12745
12746                 gl.texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, s_reference_internalformat, s_reference_width,
12747                                           s_reference_height, 0, s_reference_format, s_reference_type, s_reference_data);
12748                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12749
12750                 /* 2D multisample */
12751                 gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &texture_2D_ms);
12752                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12753
12754                 gl.textureStorage2DMultisample(texture_2D_ms, 1, s_reference_internalformat, s_reference_width,
12755                                                                            s_reference_height, false);
12756                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2DMultisample has failed");
12757
12758                 /* 2D stencil */
12759                 gl.createTextures(GL_TEXTURE_2D, 1, &texture_2D_stencil);
12760                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12761
12762                 gl.textureStorage2D(texture_2D_stencil, 1, GL_STENCIL_INDEX8, s_reference_width, s_reference_height);
12763                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2DMultisample has failed");
12764
12765                 /* 2D compressed texture  */
12766                 gl.genTextures(1, &texture_2D_compressed);
12767                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12768
12769                 gl.bindTexture(GL_TEXTURE_2D, texture_2D_compressed);
12770                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12771
12772                 gl.texImage2D(GL_TEXTURE_2D, 0, s_reference_internalformat_compressed, s_reference_width, s_reference_height, 0,
12773                                           s_reference_format, s_reference_type, s_reference_data);
12774                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12775
12776                 gl.getIntegerv(GL_MAX_TEXTURE_SIZE, &max_level); /* assuming that x > log(x) */
12777                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
12778
12779                 /* Rectangle texture */
12780                 gl.genTextures(1, &texture_rectangle);
12781                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12782
12783                 gl.bindTexture(GL_TEXTURE_RECTANGLE, texture_rectangle);
12784                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12785
12786                 gl.texImage2D(GL_TEXTURE_RECTANGLE, 0, s_reference_internalformat, s_reference_width, s_reference_height, 0,
12787                                           s_reference_format, s_reference_type, s_reference_data);
12788                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12789
12790                 /* invalid texture */
12791                 while (gl.isTexture(++texture_invalid))
12792                         ;
12793
12794                 /* Tests. */
12795
12796                 /* Check that INVALID_ENUM is generated by GetTextureImage functions if
12797                  resulting texture target is not an accepted value TEXTURE_1D,
12798                  TEXTURE_2D, TEXTURE_3D, TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY,
12799                  TEXTURE_CUBE_MAP_ARRAY, TEXTURE_RECTANGLE, and TEXTURE_CUBE_MAP. */
12800                 gl.getTextureImage(texture_2D_ms, 0, s_reference_format, s_reference_type, s_reference_size, store);
12801                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureImage",
12802                                                                   "resulting texture target is not an accepted value TEXTURE_1D, TEXTURE_2D, "
12803                                                                   "TEXTURE_3D, TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP_ARRAY, "
12804                                                                   "TEXTURE_RECTANGLE, and TEXTURE_CUBE_MAP.");
12805
12806                 /* Check that INVALID_OPERATION is generated by GetTextureImage
12807                  if texture is not the name of an existing texture object. */
12808                 gl.getTextureImage(texture_invalid, 0, s_reference_format, s_reference_type, s_reference_size, store);
12809                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12810                                                                   "texture is not the name of an existing texture object.");
12811
12812                 /* Check that INVALID_OPERATION error is generated by GetTextureImage if
12813                  the effective target is TEXTURE_CUBE_MAP or TEXTURE_CUBE_MAP_ARRAY, and
12814                  the texture object is not cube complete or cube array complete,
12815                  respectively. */
12816                 gl.getTextureImage(texture_cube, 0, s_reference_format, s_reference_type, s_reference_size * 6, store);
12817                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12818                                                                   "the effective target is TEXTURE_CUBE_MAP and the texture object is not cube "
12819                                                                   "complete or cube array complete, respectively.");
12820
12821                 /* Check that GL_INVALID_VALUE is generated if level is less than 0 or
12822                  larger than the maximum allowable level. */
12823                 gl.getTextureImage(texture_2D, -1, s_reference_format, s_reference_type, s_reference_size, store);
12824                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureImage", "level is less than 0.");
12825
12826                 gl.getTextureImage(texture_2D, max_level, s_reference_format, s_reference_type, s_reference_size, store);
12827                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureImage",
12828                                                                   "level is larger than the maximum allowable level.");
12829
12830                 /* Check that INVALID_VALUE error is generated if level is non-zero and the
12831                  effective target is TEXTURE_RECTANGLE. */
12832                 gl.getTextureImage(texture_rectangle, 1, s_reference_format, s_reference_type, s_reference_size, store);
12833                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureImage",
12834                                                                   "level is non-zero and the effective target is TEXTURE_RECTANGLE.");
12835
12836                 /* Check that INVALID_OPERATION error is generated if any of the following
12837                  mismatches between format and the internal format of the texture image
12838                  exist:
12839                  -  format is a color format (one of the formats in table 8.3 whose
12840                  target is the color buffer) and the base internal format of the
12841                  texture image is not a color format.
12842                  -  format is DEPTH_COMPONENT and the base internal format is  not
12843                  DEPTH_COMPONENT or DEPTH_STENCIL
12844                  -  format is DEPTH_STENCIL and the base internal format is not
12845                  DEPTH_STENCIL
12846                  -  format is STENCIL_INDEX and the base internal format is not
12847                  STENCIL_INDEX or DEPTH_STENCIL
12848                  -  format is one of the integer formats in table 8.3 and the internal
12849                  format of the texture image is not integer, or format is not one of
12850                  the integer formats in table 8.3 and the internal format is integer. */
12851                 gl.getTextureImage(texture_2D_stencil, 0, s_reference_format /* red */, s_reference_type, s_reference_size,
12852                                                    store);
12853                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12854                                                                   "format is a color format (one of the formats in table 8.3 whose target is the color "
12855                                                                   "buffer) and the base internal format of the texture image is not a color format.");
12856
12857                 gl.getTextureImage(texture_2D, 0, GL_DEPTH_COMPONENT, s_reference_type, s_reference_size, store);
12858                 is_ok &= CheckErrorAndLog(
12859                         m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12860                         "format is DEPTH_COMPONENT and the base internal format is not DEPTH_COMPONENT or DEPTH_STENCIL.");
12861
12862                 gl.getTextureImage(texture_2D, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, s_reference_size, store);
12863                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12864                                                                   "format is DEPTH_STENCIL and the base internal format is not DEPTH_STENCIL.");
12865
12866                 gl.getTextureImage(texture_2D, 0, GL_STENCIL_INDEX, s_reference_type, s_reference_size, store);
12867                 is_ok &= CheckErrorAndLog(
12868                         m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12869                         "format is STENCIL_INDEX and the base internal format is not STENCIL_INDEX or DEPTH_STENCIL.");
12870
12871                 gl.getTextureImage(texture_2D, 0, GL_RED_INTEGER, s_reference_type, s_reference_size, store);
12872                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12873                                                                   "format is one of the integer formats in table 8.3 and the internal format of the "
12874                                                                   "texture image is not integer.");
12875
12876                 gl.getTextureImage(texture_2D_int, 0, GL_RED, s_reference_type, s_reference_size, store);
12877                 is_ok &= CheckErrorAndLog(
12878                         m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12879                         "format is not one of the integer formats in table 8.3 and the internal format is integer.");
12880
12881                 /* Check that INVALID_OPERATION error is generated if a pixel pack buffer
12882                  object is bound and packing the texture image into the buffer’s memory
12883                  would exceed the size of the buffer. */
12884                 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, buffer);
12885                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
12886
12887                 gl.getTextureImage(texture_2D, 0, s_reference_format, s_reference_type, s_reference_size,
12888                                                    (glw::GLuint*)NULL + 1);
12889                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12890                                                                   "a pixel pack buffer object is bound and packing the texture image into the buffer’s "
12891                                                                   "memory would exceed the size of the buffer.");
12892
12893                 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, 0);
12894                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
12895
12896                 /* Check that INVALID_OPERATION error is generated if a pixel pack buffer
12897                  object is bound and pixels is not evenly divisible by the number of
12898                  basic machine units needed to store in memory the GL data type
12899                  corresponding to type (see table 8.2). */
12900                 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, buffer);
12901                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
12902
12903                 gl.getTextureImage(texture_2D, 0, s_reference_format, s_reference_type, s_reference_size,
12904                                                    (glw::GLubyte*)NULL + 1);
12905                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12906                                                                   "a pixel pack buffer object is bound and pixels is not evenly divisible by the "
12907                                                                   "number of basic machine units needed to store in memory the GL data type "
12908                                                                   "corresponding to type (see table 8.2).");
12909
12910                 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, 0);
12911                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
12912
12913                 /* Check that INVALID_OPERATION error is generated by GetTextureImage if
12914                  the buffer size required to store the requested data is greater than
12915                  bufSize. */
12916                 gl.getTextureImage(texture_2D, 0, s_reference_format, s_reference_type,
12917                                                    s_reference_size - sizeof(s_reference_data[0]), store);
12918                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12919                                                                   "the buffer size required to store the requested data is greater than bufSize.");
12920
12921                 /* Check that INVALID_OPERATION is generated by GetCompressedTextureImage
12922                  if texture is not the name of an existing texture object. */
12923                 gl.getCompressedTextureImage(texture_invalid, 0, s_reference_size, store);
12924                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetCompressedTextureImage",
12925                                                                   "texture is not the name of an existing texture object.");
12926
12927                 /* Check that INVALID_VALUE is generated by GetCompressedTextureImage if
12928                  level is less than zero or greater than the maximum number of LODs
12929                  permitted by the implementation. */
12930                 gl.getCompressedTextureImage(texture_2D_compressed, -1, s_reference_size, store);
12931                 is_ok &=
12932                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetCompressedTextureImage", "level is less than zero.");
12933
12934                 gl.getCompressedTextureImage(texture_2D_compressed, max_level, s_reference_size, store);
12935                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetCompressedTextureImage",
12936                                                                   "level is greater than the maximum number of LODs permitted by the implementation.");
12937
12938                 /* Check that INVALID_OPERATION is generated if GetCompressedTextureImage
12939                  is used to retrieve a texture that is in an uncompressed internal
12940                  format. */
12941                 gl.getCompressedTextureImage(texture_2D, 0, s_reference_size, store);
12942                 is_ok &=
12943                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetCompressedTextureImage",
12944                                                          "the function is used to retrieve a texture that is in an uncompressed internal format.");
12945
12946                 /* Check that INVALID_OPERATION is generated by GetCompressedTextureImage
12947                  if a non-zero buffer object name is bound to the PIXEL_PACK_BUFFER
12948                  target, the buffer storage was not initialized with BufferStorage using
12949                  MAP_PERSISTENT_BIT flag, and the buffer object's data store is currently
12950                  mapped. */
12951                 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, buffer);
12952                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
12953
12954                 gl.mapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_WRITE);
12955
12956                 if (GL_NO_ERROR == gl.getError())
12957                 {
12958                         gl.getCompressedTextureImage(texture_2D_compressed, 0, s_reference_size, NULL);
12959                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetCompressedTextureImage",
12960                                                                           "a non-zero buffer object name is bound to the PIXEL_PACK_BUFFER target, the "
12961                                                                           "buffer storage was not initialized with BufferStorage using MAP_PERSISTENT_BIT "
12962                                                                           "flag, and the buffer object's data store is currently mapped.");
12963
12964                         gl.unmapBuffer(GL_PIXEL_PACK_BUFFER);
12965                         GLU_EXPECT_NO_ERROR(gl.getError(), "glUnmapBuffer has failed");
12966                 }
12967                 else
12968                 {
12969                         throw 0;
12970                 }
12971
12972                 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, 0);
12973                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
12974
12975                 /* Check that INVALID_OPERATION is generated by GetCompressedTextureImage
12976                  if a non-zero buffer object name is bound to the PIXEL_PACK_BUFFER
12977                  target and the data would be packed to the buffer object such that the
12978                  memory writes required would exceed the data store size. */
12979                 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, buffer);
12980                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
12981
12982                 gl.getCompressedTextureImage(texture_2D_compressed, 0, s_reference_size, (char*)NULL + s_reference_size - 1);
12983                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetCompressedTextureImage",
12984                                                                   "a non-zero buffer object name is bound to the PIXEL_PACK_BUFFER target and the data "
12985                                                                   "would be packed to the buffer object such that the memory writes required would "
12986                                                                   "exceed the data store size.");
12987
12988                 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, 0);
12989                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
12990         }
12991         catch (...)
12992         {
12993                 is_ok   = false;
12994                 is_error = true;
12995         }
12996
12997         /* Cleanup. */
12998         if (buffer)
12999         {
13000                 gl.deleteBuffers(1, &buffer);
13001         }
13002
13003         if (texture_2D)
13004         {
13005                 gl.deleteTextures(1, &texture_2D);
13006         }
13007
13008         if (texture_2D_int)
13009         {
13010                 gl.deleteTextures(1, &texture_2D_int);
13011         }
13012
13013         if (texture_2D_stencil)
13014         {
13015                 gl.deleteTextures(1, &texture_2D_stencil);
13016         }
13017
13018         if (texture_2D_ms)
13019         {
13020                 gl.deleteTextures(1, &texture_2D_ms);
13021         }
13022
13023         if (texture_2D_compressed)
13024         {
13025                 gl.deleteTextures(1, &texture_2D_compressed);
13026         }
13027
13028         if (texture_cube)
13029         {
13030                 gl.deleteTextures(1, &texture_cube);
13031         }
13032
13033         if (texture_rectangle)
13034         {
13035                 gl.deleteTextures(1, &texture_rectangle);
13036         }
13037
13038         while (GL_NO_ERROR != gl.getError())
13039                 ;
13040
13041         /* Result's setup. */
13042         if (is_ok)
13043         {
13044                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
13045         }
13046         else
13047         {
13048                 if (is_error)
13049                 {
13050                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
13051                 }
13052                 else
13053                 {
13054                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
13055                 }
13056         }
13057
13058         return STOP;
13059 }
13060
13061 /******************************** Level Parameter Query Errors Test Implementation   ********************************/
13062
13063 /** @brief Image Query Errors Test constructor.
13064  *
13065  *  @param [in] context     OpenGL context.
13066  */
13067 LevelParameterErrorsTest::LevelParameterErrorsTest(deqp::Context& context)
13068         : deqp::TestCase(context, "textures_level_parameter_errors", "Texture Level Parameter Query Errors Test")
13069 {
13070         /* Intentionally left blank. */
13071 }
13072
13073 /** @brief Iterate Level Parameter Query Errors Test cases.
13074  *
13075  *  @return Iteration result.
13076  */
13077 tcu::TestNode::IterateResult LevelParameterErrorsTest::iterate()
13078 {
13079         /* Shortcut for GL functionality. */
13080         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
13081
13082         /* Get context setup. */
13083         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
13084         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
13085
13086         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
13087         {
13088                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
13089
13090                 return STOP;
13091         }
13092
13093         /* Running tests. */
13094         bool is_ok      = true;
13095         bool is_error = false;
13096
13097         /* Objects. */
13098         glw::GLuint texture_2D          = 0;
13099         glw::GLuint texture_invalid = 0;
13100         glw::GLint  max_level           = 0;
13101         glw::GLenum pname_invalid   = 0;
13102
13103         glw::GLfloat storef[4] = {};
13104         glw::GLint   storei[4] = {};
13105
13106         try
13107         {
13108                 /* Preparations. */
13109
13110                 /* 2D texture */
13111                 gl.genTextures(1, &texture_2D);
13112                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
13113
13114                 gl.bindTexture(GL_TEXTURE_2D, texture_2D);
13115                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
13116
13117                 gl.texStorage2D(GL_TEXTURE_2D, 1, GL_R8, 1, 1);
13118                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
13119
13120                 /* Limits. */
13121                 gl.getIntegerv(GL_MAX_TEXTURE_SIZE, &max_level); /* assuming that x > log(x) */
13122                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
13123
13124                 /* invalid texture */
13125                 while (gl.isTexture(++texture_invalid))
13126                         ;
13127
13128                 /* invalid pname */
13129                 glw::GLenum all_pnames[] = { GL_TEXTURE_WIDTH,
13130                                                                          GL_TEXTURE_HEIGHT,
13131                                                                          GL_TEXTURE_DEPTH,
13132                                                                          GL_TEXTURE_SAMPLES,
13133                                                                          GL_TEXTURE_FIXED_SAMPLE_LOCATIONS,
13134                                                                          GL_TEXTURE_INTERNAL_FORMAT,
13135                                                                          GL_TEXTURE_RED_SIZE,
13136                                                                          GL_TEXTURE_GREEN_SIZE,
13137                                                                          GL_TEXTURE_BLUE_SIZE,
13138                                                                          GL_TEXTURE_ALPHA_SIZE,
13139                                                                          GL_TEXTURE_DEPTH_SIZE,
13140                                                                          GL_TEXTURE_STENCIL_SIZE,
13141                                                                          GL_TEXTURE_SHARED_SIZE,
13142                                                                          GL_TEXTURE_RED_TYPE,
13143                                                                          GL_TEXTURE_GREEN_TYPE,
13144                                                                          GL_TEXTURE_BLUE_TYPE,
13145                                                                          GL_TEXTURE_ALPHA_TYPE,
13146                                                                          GL_TEXTURE_DEPTH_TYPE,
13147                                                                          GL_TEXTURE_COMPRESSED,
13148                                                                          GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
13149                                                                          GL_TEXTURE_BUFFER_DATA_STORE_BINDING,
13150                                                                          GL_TEXTURE_BUFFER_OFFSET,
13151                                                                          GL_TEXTURE_BUFFER_SIZE };
13152
13153                 glw::GLuint all_pnames_count = sizeof(all_pnames) / sizeof(all_pnames[0]);
13154
13155                 bool is_valid = true;
13156
13157                 while (is_valid)
13158                 {
13159                         is_valid = false;
13160
13161                         ++pname_invalid;
13162
13163                         for (glw::GLuint i = 0; i < all_pnames_count; ++i)
13164                         {
13165                                 if (all_pnames[i] == pname_invalid)
13166                                 {
13167                                         is_valid = true;
13168
13169                                         break;
13170                                 }
13171                         }
13172                 }
13173
13174                 /* Tests. */
13175
13176                 /* Check that INVALID_OPERATION is generated by GetTextureLevelParameterfv
13177                  and GetTextureLevelParameteriv functions if texture is not the name of
13178                  an existing texture object. */
13179                 gl.getTextureLevelParameterfv(texture_invalid, 0, GL_TEXTURE_WIDTH, storef);
13180                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureLevelParameterfv",
13181                                                                   "texture is not the name of an existing texture object.");
13182
13183                 gl.getTextureLevelParameteriv(texture_invalid, 0, GL_TEXTURE_WIDTH, storei);
13184                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureLevelParameteriv",
13185                                                                   "texture is not the name of an existing texture object.");
13186
13187                 /* Check that INVALID_VALUE is generated by GetTextureLevelParameter* if
13188                  level is less than 0. */
13189                 gl.getTextureLevelParameterfv(texture_2D, -1, GL_TEXTURE_WIDTH, storef);
13190                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureLevelParameterfv", "level is less than 0.");
13191
13192                 gl.getTextureLevelParameteriv(texture_2D, -1, GL_TEXTURE_WIDTH, storei);
13193                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureLevelParameteriv", "level is less than 0.");
13194
13195                 /* Check that INVALID_ENUM error is generated by GetTextureLevelParameter*
13196                  if pname is not one of supported constants. */
13197                 gl.getTextureLevelParameterfv(texture_2D, 0, pname_invalid, storef);
13198                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureLevelParameterfv",
13199                                                                   "pname is not one of supported constants.");
13200
13201                 gl.getTextureLevelParameteriv(texture_2D, 0, pname_invalid, storei);
13202                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureLevelParameteriv",
13203                                                                   "pname is not one of supported constants.");
13204
13205                 /* Check that INVALID_VALUE may be generated if level is greater than
13206                  log2 max, where max is the returned value of MAX_TEXTURE_SIZE. */
13207                 gl.getTextureLevelParameterfv(texture_2D, max_level, GL_TEXTURE_WIDTH, storef);
13208                 is_ok &=
13209                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureLevelParameterfv",
13210                                                          "level is greater than log2 max, where max is the returned value of MAX_TEXTURE_SIZE.");
13211
13212                 gl.getTextureLevelParameteriv(texture_2D, max_level, GL_TEXTURE_WIDTH, storei);
13213                 is_ok &=
13214                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureLevelParameteriv",
13215                                                          "level is greater than log2 max, where max is the returned value of MAX_TEXTURE_SIZE.");
13216
13217                 /* Check that INVALID_OPERATION is generated by GetTextureLevelParameter*
13218                  if TEXTURE_COMPRESSED_IMAGE_SIZE is queried on texture images with an
13219                  uncompressed internal format or on proxy targets. */
13220                 gl.getTextureLevelParameterfv(texture_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, storef);
13221                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureLevelParameterfv",
13222                                                                   "TEXTURE_COMPRESSED_IMAGE_SIZE is queried on texture images with an uncompressed "
13223                                                                   "internal format or on proxy targets.");
13224
13225                 gl.getTextureLevelParameteriv(texture_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, storei);
13226                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureLevelParameteriv",
13227                                                                   "TEXTURE_COMPRESSED_IMAGE_SIZE is queried on texture images with an uncompressed "
13228                                                                   "internal format or on proxy targets.");
13229         }
13230         catch (...)
13231         {
13232                 is_ok   = false;
13233                 is_error = true;
13234         }
13235
13236         /* Cleanup. */
13237         if (texture_2D)
13238         {
13239                 gl.deleteTextures(1, &texture_2D);
13240         }
13241
13242         while (GL_NO_ERROR != gl.getError())
13243                 ;
13244
13245         /* Result's setup. */
13246         if (is_ok)
13247         {
13248                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
13249         }
13250         else
13251         {
13252                 if (is_error)
13253                 {
13254                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
13255                 }
13256                 else
13257                 {
13258                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
13259                 }
13260         }
13261
13262         return STOP;
13263 }
13264
13265 /******************************** Parameter Query Errors Test Implementation   ********************************/
13266
13267 /** @brief Parameter Query Errors Test constructor.
13268  *
13269  *  @param [in] context     OpenGL context.
13270  */
13271 ParameterErrorsTest::ParameterErrorsTest(deqp::Context& context)
13272         : deqp::TestCase(context, "textures_parameter_errors", "Texture Parameter Query Errors Test")
13273 {
13274         /* Intentionally left blank. */
13275 }
13276
13277 /** @brief Iterate Parameter Query Errors Test cases.
13278  *
13279  *  @return Iteration result.
13280  */
13281 tcu::TestNode::IterateResult ParameterErrorsTest::iterate()
13282 {
13283         /* Shortcut for GL functionality. */
13284         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
13285
13286         /* Get context setup. */
13287         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
13288         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
13289
13290         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
13291         {
13292                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
13293
13294                 return STOP;
13295         }
13296
13297         /* Running tests. */
13298         bool is_ok      = true;
13299         bool is_error = false;
13300
13301         /* Objects. */
13302         glw::GLuint texture_2D          = 0;
13303         glw::GLuint texture_buffer  = 0;
13304         glw::GLuint texture_invalid = 0;
13305         glw::GLenum pname_invalid   = 0;
13306
13307         glw::GLfloat storef[4] = {};
13308         glw::GLint   storei[4] = {};
13309         glw::GLuint  storeu[4] = {};
13310
13311         try
13312         {
13313                 /* Preparations. */
13314
13315                 /* 2D texture */
13316                 gl.createTextures(GL_TEXTURE_2D, 1, &texture_2D);
13317                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
13318
13319                 /* Buffer texture */
13320                 gl.createTextures(GL_TEXTURE_BUFFER, 1, &texture_buffer);
13321                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
13322
13323                 /* invalid texture */
13324                 while (gl.isTexture(++texture_invalid))
13325                         ;
13326
13327                 /* invalid pname */
13328                 glw::GLenum all_pnames[] = { GL_IMAGE_FORMAT_COMPATIBILITY_TYPE,
13329                                                                          GL_TEXTURE_IMMUTABLE_FORMAT,
13330                                                                          GL_TEXTURE_IMMUTABLE_LEVELS,
13331                                                                          GL_TEXTURE_TARGET,
13332                                                                          GL_TEXTURE_VIEW_MIN_LEVEL,
13333                                                                          GL_TEXTURE_VIEW_NUM_LEVELS,
13334                                                                          GL_TEXTURE_VIEW_MIN_LAYER,
13335                                                                          GL_TEXTURE_VIEW_NUM_LAYERS,
13336                                                                          GL_DEPTH_STENCIL_TEXTURE_MODE,
13337                                                                          GL_DEPTH_COMPONENT,
13338                                                                          GL_STENCIL_INDEX,
13339                                                                          GL_TEXTURE_BASE_LEVEL,
13340                                                                          GL_TEXTURE_BORDER_COLOR,
13341                                                                          GL_TEXTURE_COMPARE_MODE,
13342                                                                          GL_TEXTURE_COMPARE_FUNC,
13343                                                                          GL_TEXTURE_LOD_BIAS,
13344                                                                          GL_TEXTURE_MAG_FILTER,
13345                                                                          GL_TEXTURE_MAX_LEVEL,
13346                                                                          GL_TEXTURE_MAX_LOD,
13347                                                                          GL_TEXTURE_MIN_FILTER,
13348                                                                          GL_TEXTURE_MIN_LOD,
13349                                                                          GL_TEXTURE_SWIZZLE_R,
13350                                                                          GL_TEXTURE_SWIZZLE_G,
13351                                                                          GL_TEXTURE_SWIZZLE_B,
13352                                                                          GL_TEXTURE_SWIZZLE_A,
13353                                                                          GL_TEXTURE_SWIZZLE_RGBA,
13354                                                                          GL_TEXTURE_WRAP_S,
13355                                                                          GL_TEXTURE_WRAP_T,
13356                                                                          GL_TEXTURE_WRAP_R };
13357
13358                 glw::GLuint all_pnames_count = sizeof(all_pnames) / sizeof(all_pnames[0]);
13359
13360                 bool is_valid = true;
13361
13362                 while (is_valid)
13363                 {
13364                         is_valid = false;
13365
13366                         ++pname_invalid;
13367
13368                         for (glw::GLuint i = 0; i < all_pnames_count; ++i)
13369                         {
13370                                 if (all_pnames[i] == pname_invalid)
13371                                 {
13372                                         is_valid = true;
13373
13374                                         break;
13375                                 }
13376                         }
13377                 }
13378
13379                 /* Tests. */
13380
13381                 /* Check that INVALID_ENUM is generated by glGetTextureParameter* if pname
13382                  is not an accepted value. */
13383                 gl.getTextureParameterfv(texture_2D, pname_invalid, storef);
13384                 is_ok &=
13385                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureParameterfv", "pname is not an accepted value.");
13386
13387                 gl.getTextureParameterIiv(texture_2D, pname_invalid, storei);
13388                 is_ok &=
13389                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureParameterIiv", "pname is not an accepted value.");
13390
13391                 gl.getTextureParameterIuiv(texture_2D, pname_invalid, storeu);
13392                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureParameterIuiv",
13393                                                                   "pname is not an accepted value.");
13394
13395                 gl.getTextureParameteriv(texture_2D, pname_invalid, storei);
13396                 is_ok &=
13397                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureParameteriv", "pname is not an accepted value.");
13398
13399                 /* Check that INVALID_OPERATION is generated by glGetTextureParameter* if
13400                  texture is not the name of an existing texture object. */
13401                 gl.getTextureParameterfv(texture_invalid, GL_TEXTURE_TARGET, storef);
13402                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameterfv",
13403                                                                   "texture is not the name of an existing texture object.");
13404
13405                 gl.getTextureParameterIiv(texture_invalid, GL_TEXTURE_TARGET, storei);
13406                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameterIiv",
13407                                                                   "texture is not the name of an existing texture object.");
13408
13409                 gl.getTextureParameterIuiv(texture_invalid, GL_TEXTURE_TARGET, storeu);
13410                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameterIuiv",
13411                                                                   "texture is not the name of an existing texture object.");
13412
13413                 gl.getTextureParameteriv(texture_invalid, GL_TEXTURE_TARGET, storei);
13414                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameteriv",
13415                                                                   "texture is not the name of an existing texture object.");
13416
13417                 /* Check that INVALID_OPERATION error is generated if the effective target is
13418                  not one of the supported texture targets (eg. TEXTURE_BUFFER). */
13419                 gl.getTextureParameterfv(texture_buffer, GL_TEXTURE_TARGET, storef);
13420                 is_ok &=
13421                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameterfv",
13422                                                          "the effective target is not one of the supported texture targets (eg. TEXTURE_BUFFER).");
13423
13424                 gl.getTextureParameterIiv(texture_buffer, GL_TEXTURE_TARGET, storei);
13425                 is_ok &=
13426                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameterIiv",
13427                                                          "the effective target is not one of the supported texture targets (eg. TEXTURE_BUFFER).");
13428
13429                 gl.getTextureParameterIuiv(texture_buffer, GL_TEXTURE_TARGET, storeu);
13430                 is_ok &=
13431                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameterIuiv",
13432                                                          "the effective target is not one of the supported texture targets (eg. TEXTURE_BUFFER).");
13433
13434                 gl.getTextureParameteriv(texture_buffer, GL_TEXTURE_TARGET, storei);
13435                 is_ok &=
13436                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameteriv",
13437                                                          "the effective target is not one of the supported texture targets (eg. TEXTURE_BUFFER).");
13438         }
13439         catch (...)
13440         {
13441                 is_ok   = false;
13442                 is_error = true;
13443         }
13444
13445         /* Cleanup. */
13446         if (texture_2D)
13447         {
13448                 gl.deleteTextures(1, &texture_2D);
13449         }
13450
13451         if (texture_buffer)
13452         {
13453                 gl.deleteTextures(1, &texture_buffer);
13454         }
13455
13456         while (GL_NO_ERROR != gl.getError())
13457                 ;
13458
13459         /* Result's setup. */
13460         if (is_ok)
13461         {
13462                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
13463         }
13464         else
13465         {
13466                 if (is_error)
13467                 {
13468                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
13469                 }
13470                 else
13471                 {
13472                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
13473                 }
13474         }
13475
13476         return STOP;
13477 }
13478
13479 } /* Textures namespace. */
13480 } /* DirectStateAccess namespace. */
13481 } /* gl4cts namespace. */