d57714457e0b4a651a821a5f7c2fc9ebed783a94
[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  *  @tparam T      Type.
1463  *  @tparam S      Size.
1464  *  @tparam N      Is normalized.
1465  *  @tparam D      Texture dimension.
1466  *  @tparam I      Choose between SubImage and Storage tests.
1467  *
1468  *  @param [in] context     OpenGL context.
1469  *  @param [in] name        Name of the test.
1470  */
1471 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
1472 StorageAndSubImageTest<T, S, N, D, I>::StorageAndSubImageTest(deqp::Context& context, const char* name)
1473         : deqp::TestCase(context, name, "Texture Storage and SubImage Test")
1474         , m_fbo(0)
1475         , m_rbo(0)
1476         , m_po(0)
1477         , m_to(0)
1478         , m_vao(0)
1479 {
1480         /* Intentionally left blank. */
1481 }
1482
1483 /** @brief Count of reference data to be teted.
1484  *
1485  *  @return Count.
1486  */
1487 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
1488 glw::GLuint StorageAndSubImageTest<T, S, N, D, I>::TestReferenceDataCount()
1489 {
1490         return 2 /* 1D */ * ((D > 1) ? 3 : 1) /* 2D */ * ((D > 2) ? 4 : 1) /* 3D */ * S /* components */;
1491 }
1492
1493 /** @brief Size of reference data to be teted.
1494  *
1495  *  @tparam T      Type.
1496  *  @tparam S      Size (# of components).
1497  *  @tparam D      Texture dimenisons.
1498  *
1499  *  @return Size.
1500  */
1501 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
1502 glw::GLuint StorageAndSubImageTest<T, S, N, D, I>::TestReferenceDataSize()
1503 {
1504         return static_cast<glw::GLint>(TestReferenceDataCount() * sizeof(T));
1505 }
1506
1507 /** @brief Height, width or depth of reference data to be teted.
1508  *
1509  *  @return Height, width or depth.
1510  */
1511 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
1512 glw::GLuint StorageAndSubImageTest<T, S, N, D, I>::TestReferenceDataHeight()
1513 {
1514         switch (D)
1515         {
1516         case 2:
1517         case 3:
1518                 return 3;
1519         default:
1520                 return 1;
1521         }
1522 }
1523
1524 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
1525 glw::GLuint StorageAndSubImageTest<T, S, N, D, I>::TestReferenceDataDepth()
1526 {
1527         switch (D)
1528         {
1529         case 3:
1530                 return 4;
1531         default:
1532                 return 1;
1533         }
1534 }
1535
1536 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
1537 glw::GLuint StorageAndSubImageTest<T, S, N, D, I>::TestReferenceDataWidth()
1538 {
1539         return 2;
1540 }
1541
1542 /** @brief Fragment shader declaration selector.
1543  *
1544  *  @return Frgment shader source code part.
1545  */
1546 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
1547 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::FragmentShaderDeclaration()
1548 {
1549         if (typeid(T) == typeid(glw::GLbyte))
1550         {
1551                 switch (D)
1552                 {
1553                 case 1:
1554                         return s_fragment_shader_1D_idecl_lowp;
1555                 case 2:
1556                         return s_fragment_shader_2D_idecl_lowp;
1557                 case 3:
1558                         return s_fragment_shader_3D_idecl_lowp;
1559                 default:
1560                         DE_ASSERT("invalid texture dimension");
1561                         return DE_NULL;
1562                 }
1563         }
1564
1565         if (typeid(T) == typeid(glw::GLubyte))
1566         {
1567                 if (N)
1568                 {
1569                         switch (D)
1570                         {
1571                         case 1:
1572                                 return s_fragment_shader_1D_fdecl_lowp;
1573                         case 2:
1574                                 return s_fragment_shader_2D_fdecl_lowp;
1575                         case 3:
1576                                 return s_fragment_shader_3D_fdecl_lowp;
1577                         default:
1578                                 DE_ASSERT("invalid texture dimension");
1579                                 return DE_NULL;
1580                         }
1581                 }
1582                 else
1583                 {
1584                         switch (D)
1585                         {
1586                         case 1:
1587                                 return s_fragment_shader_1D_udecl_lowp;
1588                         case 2:
1589                                 return s_fragment_shader_2D_udecl_lowp;
1590                         case 3:
1591                                 return s_fragment_shader_3D_udecl_lowp;
1592                         default:
1593                                 DE_ASSERT("invalid texture dimension");
1594                                 return DE_NULL;
1595                         }
1596                 }
1597         }
1598
1599         if (typeid(T) == typeid(glw::GLshort))
1600         {
1601                 switch (D)
1602                 {
1603                 case 1:
1604                         return s_fragment_shader_1D_idecl_mediump;
1605                 case 2:
1606                         return s_fragment_shader_2D_idecl_mediump;
1607                 case 3:
1608                         return s_fragment_shader_3D_idecl_mediump;
1609                 default:
1610                         DE_ASSERT("invalid texture dimension");
1611                         return DE_NULL;
1612                 }
1613         }
1614
1615         if (typeid(T) == typeid(glw::GLushort))
1616         {
1617                 if (N)
1618                 {
1619                         switch (D)
1620                         {
1621                         case 1:
1622                                 return s_fragment_shader_1D_fdecl_mediump;
1623                         case 2:
1624                                 return s_fragment_shader_2D_fdecl_mediump;
1625                         case 3:
1626                                 return s_fragment_shader_3D_fdecl_mediump;
1627                         default:
1628                                 DE_ASSERT("invalid texture dimension");
1629                                 return DE_NULL;
1630                         }
1631                 }
1632                 else
1633                 {
1634                         switch (D)
1635                         {
1636                         case 1:
1637                                 return s_fragment_shader_1D_udecl_mediump;
1638                         case 2:
1639                                 return s_fragment_shader_2D_udecl_mediump;
1640                         case 3:
1641                                 return s_fragment_shader_3D_udecl_mediump;
1642                         default:
1643                                 DE_ASSERT("invalid texture dimension");
1644                                 return DE_NULL;
1645                         }
1646                 }
1647         }
1648
1649         if (typeid(T) == typeid(glw::GLint))
1650         {
1651                 switch (D)
1652                 {
1653                 case 1:
1654                         return s_fragment_shader_1D_idecl_highp;
1655                 case 2:
1656                         return s_fragment_shader_2D_idecl_highp;
1657                 case 3:
1658                         return s_fragment_shader_3D_idecl_highp;
1659                 default:
1660                         DE_ASSERT("invalid texture dimension");
1661                         return DE_NULL;
1662                 }
1663         }
1664
1665         if (typeid(T) == typeid(glw::GLuint))
1666         {
1667                 switch (D)
1668                 {
1669                 case 1:
1670                         return s_fragment_shader_1D_udecl_highp;
1671                 case 2:
1672                         return s_fragment_shader_2D_udecl_highp;
1673                 case 3:
1674                         return s_fragment_shader_3D_udecl_highp;
1675                 default:
1676                         DE_ASSERT("invalid texture dimension");
1677                         return DE_NULL;
1678                 }
1679         }
1680
1681         switch (D)
1682         {
1683         case 1:
1684                 return s_fragment_shader_1D_fdecl_highp;
1685         case 2:
1686                 return s_fragment_shader_2D_fdecl_highp;
1687         case 3:
1688                 return s_fragment_shader_3D_fdecl_highp;
1689         default:
1690                 DE_ASSERT("invalid texture dimension");
1691                 return DE_NULL;
1692         }
1693 }
1694
1695 /** @brief Fragment shader tail selector.
1696  *
1697  *  @tparam D      Texture dimenisons.
1698  *
1699  *  @return Frgment shader source code part.
1700  */
1701 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
1702 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::FragmentShaderTail()
1703 {
1704         switch (D)
1705         {
1706         case 1:
1707                 return s_fragment_shader_1D_tail;
1708         case 2:
1709                 return s_fragment_shader_2D_tail;
1710         case 3:
1711                 return s_fragment_shader_3D_tail;
1712         default:
1713                 DE_ASSERT("invalid texture dimension");
1714                 return DE_NULL;
1715         }
1716 }
1717
1718 /** @brief Texture target selector.
1719  *
1720  *  @tparam D      Texture dimenisons.
1721  *
1722  *  @return Texture target.
1723  */
1724 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
1725 glw::GLenum StorageAndSubImageTest<T, S, N, D, I>::TextureTarget()
1726 {
1727         switch (D)
1728         {
1729         case 1:
1730                 return GL_TEXTURE_1D;
1731         case 2:
1732                 return GL_TEXTURE_2D;
1733         case 3:
1734                 return GL_TEXTURE_3D;
1735         default:
1736                 DE_ASSERT("invalid texture dimension");
1737                 return DE_NULL;
1738         }
1739 }
1740
1741 /** @brief TextureStorage* wrapper.
1742  *
1743  *  @return true if succeed (in legacy always or throw), false otherwise.
1744  */
1745 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
1746 bool StorageAndSubImageTest<T, S, N, D, I>::TextureStorage(glw::GLenum target, glw::GLuint texture, glw::GLsizei levels,
1747                                                                                                                    glw::GLenum internalformat, glw::GLsizei width,
1748                                                                                                                    glw::GLsizei height, glw::GLsizei depth)
1749 {
1750         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1751
1752         if (I)
1753         {
1754                 switch (D)
1755                 {
1756                 case 1:
1757                         gl.texStorage1D(target, levels, internalformat, width);
1758                         break;
1759                 case 2:
1760                         gl.texStorage2D(target, levels, internalformat, width, height);
1761                         break;
1762                 case 3:
1763                         gl.texStorage3D(target, levels, internalformat, width, height, depth);
1764                         break;
1765                 default:
1766                         DE_ASSERT("invalid texture dimension");
1767                 }
1768
1769                 /* TextureSubImage* (not TextureStorage*) is tested */
1770                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexStorage*() has failed");
1771                 return true;
1772         }
1773         else
1774         {
1775                 switch (D)
1776                 {
1777                 case 1:
1778                         gl.textureStorage1D(texture, levels, internalformat, width);
1779                         break;
1780                 case 2:
1781                         gl.textureStorage2D(texture, levels, internalformat, width, height);
1782                         break;
1783                 case 3:
1784                         gl.textureStorage3D(texture, levels, internalformat, width, height, depth);
1785                         break;
1786                 default:
1787                         DE_ASSERT("invalid texture dimension");
1788                 }
1789
1790                 glw::GLenum error;
1791                 if (GL_NO_ERROR != (error = gl.getError()))
1792                 {
1793                         m_context.getTestContext().getLog()
1794                                 << tcu::TestLog::Message << "glTextureStorage" << D << "D unexpectedly generated error " << glu::getErrorStr(error)
1795                                 << " during test with levels " << levels << ", internal format " << internalformat
1796                                 << " width=" << width << " height=" << height << " depth=" << depth
1797                                 << "." << tcu::TestLog::EndMessage;
1798
1799                         CleanTexture();
1800                         CleanErrors();
1801
1802                         return false;
1803                 }
1804
1805                 return true;
1806         }
1807 }
1808
1809 /** @brief TextureSubImage* wrapper.
1810  *
1811  *  @return true if suuceed (in legacy always or throw), false otherwise.
1812  */
1813 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
1814 bool StorageAndSubImageTest<T, S, N, D, I>::TextureSubImage(glw::GLenum target, glw::GLuint texture, glw::GLint level,
1815                                                                                                                         glw::GLsizei width, glw::GLsizei height, glw::GLsizei depth,
1816                                                                                                                         glw::GLenum format, glw::GLenum type, const glw::GLvoid* data)
1817 {
1818         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1819
1820         if (I)
1821         {
1822                 switch (D)
1823                 {
1824                 case 1:
1825                         gl.textureSubImage1D(texture, level, 0, width, format, type, data);
1826                         break;
1827                 case 2:
1828                         gl.textureSubImage2D(texture, level, 0, 0, width, height, format, type, data);
1829                         break;
1830                 case 3:
1831                         gl.textureSubImage3D(texture, level, 0, 0, 0, width, height, depth, format, type, data);
1832                         break;
1833                 default:
1834                         DE_ASSERT("invalid texture dimension");
1835                 }
1836
1837                 glw::GLenum error;
1838                 if (GL_NO_ERROR != (error = gl.getError()))
1839                 {
1840                         m_context.getTestContext().getLog()
1841                                 << tcu::TestLog::Message << "glTextureSubImage" << D << "D unexpectedly generated error " << glu::getErrorStr(error)
1842                                 << " during test with level " << level << ", width=" << width << ", height=" << height << ", depth=" << depth
1843                                 << " format " << glu::getTextureFormatStr(format) << " and type " << glu::getTypeStr(type) << "."
1844                                 << tcu::TestLog::EndMessage;
1845
1846                         CleanTexture();
1847                         CleanErrors();
1848
1849                         return false;
1850                 }
1851
1852                 return true;
1853         }
1854         else
1855         {
1856                 switch (D)
1857                 {
1858                 case 1:
1859                         gl.texSubImage1D(target, level, 0, width, format, type, data);
1860                         break;
1861                 case 2:
1862                         gl.texSubImage2D(target, level, 0, 0, width, height, format, type, data);
1863                         break;
1864                 case 3:
1865                         gl.texSubImage3D(target, level, 0, 0, 0, width, height, depth, format, type, data);
1866                         break;
1867                 default:
1868                         DE_ASSERT("invalid texture dimension");
1869                 }
1870
1871                 /* TextureStorage* (not TextureSubImage) is tested */
1872                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexSubImage*() has failed");
1873                 return true;
1874         }
1875 }
1876
1877 /** @brief Create texture.
1878  *
1879  *  @tparam T      Type.
1880  *  @tparam S      Size (# of components).
1881  *  @tparam N      Is normalized.
1882  *  @tparam D      Dimmensions.
1883  *  @tparam I      Test SubImage or Storage.
1884  *
1885  *  @return True if succeded, false otherwise.
1886  */
1887 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
1888 bool StorageAndSubImageTest<T, S, N, D, I>::CreateTexture()
1889 {
1890         /* Shortcut for GL functionality. */
1891         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1892
1893         /* Objects creation. */
1894         gl.genTextures(1, &m_to);
1895         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
1896
1897         gl.bindTexture(TextureTarget(), m_to);
1898         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
1899
1900         /* Storage creation. */
1901         if (TextureStorage(TextureTarget(), m_to, 1, InternalFormat<T, S, N>(), TestReferenceDataWidth(),
1902                                            TestReferenceDataHeight(), TestReferenceDataDepth()))
1903         {
1904                 /* Data setup. */
1905                 if (TextureSubImage(TextureTarget(), m_to, 0, TestReferenceDataWidth(), TestReferenceDataHeight(), TestReferenceDataDepth(),
1906                                                         Format<S, N>(), Type<T>(), ReferenceData<T, N>()))
1907                 {
1908                         glTexParameteri(TextureTarget(), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1909                         glTexParameteri(TextureTarget(), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1910                         return true;
1911                 }
1912         }
1913
1914         CleanTexture();
1915
1916         return false;
1917 }
1918
1919 /** @brief Compre results with the reference.
1920  *
1921  *  @return True if equal, false otherwise.
1922  */
1923 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
1924 bool StorageAndSubImageTest<T, S, N, D, I>::Check()
1925 {
1926         /* Shortcut for GL functionality. */
1927         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1928
1929         /* Fetching data. */
1930         std::vector<T> result(TestReferenceDataCount());
1931
1932         glw::GLuint fbo_size_x = 0;
1933
1934         switch (D)
1935         {
1936         case 1:
1937                 fbo_size_x = 2;
1938                 break;
1939         case 2:
1940                 fbo_size_x = 2 * 3;
1941                 break;
1942         case 3:
1943                 fbo_size_x = 2 * 3 * 4;
1944                 break;
1945         default:
1946                 throw 0;
1947         }
1948
1949         gl.readnPixels(0, 0, fbo_size_x, 1, Format<S, N>(), Type<T>(), TestReferenceDataSize(),
1950                                    (glw::GLvoid*)(&result[0]));
1951         GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels has failed");
1952
1953         /* Comparison. */
1954         for (glw::GLuint i = 0; i < TestReferenceDataCount(); ++i)
1955         {
1956                 if (!Compare<T>(result[i], ReferenceData<T, N>()[i]))
1957                 {
1958                         return false;
1959                 }
1960         }
1961
1962         return true;
1963 }
1964
1965 /** @brief Test case function.
1966  *
1967  *  @return True if test succeeded, false otherwise.
1968  */
1969 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
1970 bool StorageAndSubImageTest<T, S, N, D, I>::Test()
1971 {
1972         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1973
1974         gl.pixelStorei(GL_UNPACK_ALIGNMENT, sizeof(T));
1975         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
1976
1977         gl.pixelStorei(GL_PACK_ALIGNMENT, sizeof(T));
1978         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
1979
1980         /* Setup. */
1981         PrepareFramebuffer(InternalFormat<T, S, N>());
1982
1983         if (!CreateTexture())
1984         {
1985                 return false;
1986         }
1987
1988         /* Action. */
1989         Draw();
1990
1991         /* Compare results with reference. */
1992         bool result = Check();
1993
1994         /* Cleanup. */
1995         CleanTexture();
1996         CleanFramebuffer();
1997         CleanErrors();
1998
1999         /* Pass result. */
2000         return result;
2001 }
2002
2003 /** @brief Function prepares framebuffer with internal format color attachment.
2004  *         Viewport is set up. Content of the framebuffer is cleared.
2005  *
2006  *  @note The function may throw if unexpected error has occured.
2007  */
2008 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2009 void StorageAndSubImageTest<T, S, N, D, I>::PrepareFramebuffer(const glw::GLenum internal_format)
2010 {
2011         /* Shortcut for GL functionality. */
2012         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2013
2014         /* Prepare framebuffer. */
2015         gl.genFramebuffers(1, &m_fbo);
2016         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
2017
2018         gl.genRenderbuffers(1, &m_rbo);
2019         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
2020
2021         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
2022         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
2023
2024         gl.bindRenderbuffer(GL_RENDERBUFFER, m_rbo);
2025         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
2026
2027         glw::GLuint fbo_size_x = 0;
2028
2029         switch (D)
2030         {
2031         case 1:
2032                 fbo_size_x = 2;
2033                 break;
2034         case 2:
2035                 fbo_size_x = 2 * 3;
2036                 break;
2037         case 3:
2038                 fbo_size_x = 2 * 3 * 4;
2039                 break;
2040         default:
2041                 throw 0;
2042         }
2043
2044         gl.renderbufferStorage(GL_RENDERBUFFER, internal_format, fbo_size_x, 1);
2045         GLU_EXPECT_NO_ERROR(gl.getError(), "glRenderbufferStorage call failed.");
2046
2047         gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_rbo);
2048         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
2049
2050         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
2051         {
2052                 if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_UNSUPPORTED)
2053                         throw tcu::NotSupportedError("unsupported framebuffer configuration");
2054                 else
2055                         throw 0;
2056         }
2057
2058         gl.viewport(0, 0, fbo_size_x, 1);
2059         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
2060
2061         /* Clear framebuffer's content. */
2062         gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
2063         GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
2064
2065         gl.clear(GL_COLOR_BUFFER_BIT);
2066         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
2067 }
2068
2069 /** @brief Prepare program
2070  *
2071  *  @param [in] variable_declaration      Variables declaration part of fragment shader source code.
2072  *  @param [in] tail                      Tail part of fragment shader source code.
2073  */
2074 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2075 void StorageAndSubImageTest<T, S, N, D, I>::PrepareProgram(const glw::GLchar* variable_declaration, const glw::GLchar* tail)
2076 {
2077         /* Shortcut for GL functionality */
2078         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2079
2080         struct Shader
2081         {
2082                 glw::GLchar const* source[3];
2083                 glw::GLsizei const count;
2084                 glw::GLenum const  type;
2085                 glw::GLuint                id;
2086         } shader[] = { { { s_vertex_shader, NULL, NULL }, 1, GL_VERTEX_SHADER, 0 },
2087                                    { { s_fragment_shader_head, variable_declaration, tail }, 3, GL_FRAGMENT_SHADER, 0 } };
2088
2089         glw::GLuint const shader_count = sizeof(shader) / sizeof(shader[0]);
2090
2091         try
2092         {
2093                 /* Create program. */
2094                 m_po = gl.createProgram();
2095                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateProgram call failed.");
2096
2097                 /* Shader compilation. */
2098
2099                 for (glw::GLuint i = 0; i < shader_count; ++i)
2100                 {
2101                         {
2102                                 shader[i].id = gl.createShader(shader[i].type);
2103
2104                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateShader call failed.");
2105
2106                                 gl.attachShader(m_po, shader[i].id);
2107
2108                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glAttachShader call failed.");
2109
2110                                 gl.shaderSource(shader[i].id, shader[i].count, shader[i].source, NULL);
2111
2112                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource call failed.");
2113
2114                                 gl.compileShader(shader[i].id);
2115
2116                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader call failed.");
2117
2118                                 glw::GLint status = GL_FALSE;
2119
2120                                 gl.getShaderiv(shader[i].id, GL_COMPILE_STATUS, &status);
2121                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
2122
2123                                 if (GL_FALSE == status)
2124                                 {
2125                                         glw::GLint log_size = 0;
2126                                         gl.getShaderiv(shader[i].id, GL_INFO_LOG_LENGTH, &log_size);
2127                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
2128
2129                                         glw::GLchar* log_text = new glw::GLchar[log_size];
2130
2131                                         gl.getShaderInfoLog(shader[i].id, log_size, NULL, &log_text[0]);
2132
2133                                         m_context.getTestContext().getLog()
2134                                                 << tcu::TestLog::Message << "Shader compilation has failed.\n"
2135                                                 << "Shader type: " << glu::getShaderTypeStr(shader[i].type) << "\n"
2136                                                 << "Shader compilation error log:\n"
2137                                                 << log_text << "\n"
2138                                                 << "Shader source code:\n"
2139                                                 << shader[i].source[0] << (shader[i].source[1] ? shader[i].source[1] : "")
2140                                                 << (shader[i].source[2] ? shader[i].source[2] : "") << "\n"
2141                                                 << tcu::TestLog::EndMessage;
2142
2143                                         delete[] log_text;
2144
2145                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog call failed.");
2146
2147                                         throw 0;
2148                                 }
2149                         }
2150                 }
2151
2152                 /* Link. */
2153                 gl.linkProgram(m_po);
2154
2155                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTransformFeedbackVaryings call failed.");
2156
2157                 glw::GLint status = GL_FALSE;
2158
2159                 gl.getProgramiv(m_po, GL_LINK_STATUS, &status);
2160
2161                 if (GL_TRUE == status)
2162                 {
2163                         for (glw::GLuint i = 0; i < shader_count; ++i)
2164                         {
2165                                 if (shader[i].id)
2166                                 {
2167                                         gl.detachShader(m_po, shader[i].id);
2168
2169                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glDetachShader call failed.");
2170                                 }
2171                         }
2172                 }
2173                 else
2174                 {
2175                         glw::GLint log_size = 0;
2176
2177                         gl.getProgramiv(m_po, GL_INFO_LOG_LENGTH, &log_size);
2178
2179                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv call failed.");
2180
2181                         glw::GLchar* log_text = new glw::GLchar[log_size];
2182
2183                         gl.getProgramInfoLog(m_po, log_size, NULL, &log_text[0]);
2184
2185                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "Program linkage has failed due to:\n"
2186                                                                                                 << log_text << "\n"
2187                                                                                                 << tcu::TestLog::EndMessage;
2188
2189                         delete[] log_text;
2190
2191                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramInfoLog call failed.");
2192
2193                         throw 0;
2194                 }
2195         }
2196         catch (...)
2197         {
2198                 if (m_po)
2199                 {
2200                         gl.deleteProgram(m_po);
2201
2202                         m_po = 0;
2203                 }
2204         }
2205
2206         for (glw::GLuint i = 0; i < shader_count; ++i)
2207         {
2208                 if (0 != shader[i].id)
2209                 {
2210                         gl.deleteShader(shader[i].id);
2211
2212                         shader[i].id = 0;
2213                 }
2214         }
2215
2216         if (0 == m_po)
2217         {
2218                 throw 0;
2219         }
2220 }
2221
2222 /** @brief Prepare VAO.
2223  */
2224 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2225 void StorageAndSubImageTest<T, S, N, D, I>::PrepareVertexArray()
2226 {
2227         /* Shortcut for GL functionality. */
2228         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2229
2230         gl.genVertexArrays(1, &m_vao);
2231         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays has failed");
2232
2233         gl.bindVertexArray(m_vao);
2234         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray has failed");
2235 }
2236
2237 /** @brief Test's draw call.
2238  */
2239 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2240 void StorageAndSubImageTest<T, S, N, D, I>::Draw()
2241 {
2242         /* Shortcut for GL functionality. */
2243         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2244
2245         gl.useProgram(m_po);
2246         GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed");
2247
2248         gl.activeTexture(GL_TEXTURE0);
2249         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
2250
2251         gl.bindTextureUnit(0, m_to);
2252         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
2253
2254         gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
2255         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed");
2256 }
2257
2258 /** @brief Clean GL objects, test variables and GL errors.
2259  */
2260 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2261 void StorageAndSubImageTest<T, S, N, D, I>::CleanTexture()
2262 {
2263         /* Shortcut for GL functionality. */
2264         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2265
2266         /* Texture. */
2267         if (m_to)
2268         {
2269                 gl.deleteTextures(1, &m_to);
2270
2271                 m_to = 0;
2272         }
2273 }
2274
2275 /** @brief Clean GL objects, test variables and GL errors.
2276  */
2277 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2278 void StorageAndSubImageTest<T, S, N, D, I>::CleanFramebuffer()
2279 {
2280         /* Shortcut for GL functionality. */
2281         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2282
2283         /* Framebuffer. */
2284         if (m_fbo)
2285         {
2286                 gl.deleteFramebuffers(1, &m_fbo);
2287
2288                 m_fbo = 0;
2289         }
2290
2291         /* Renderbuffer. */
2292         if (m_rbo)
2293         {
2294                 gl.deleteRenderbuffers(1, &m_rbo);
2295
2296                 m_rbo = 0;
2297         }
2298 }
2299
2300 /** @brief Clean GL objects, test variables and GL errors.
2301  */
2302 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2303 void StorageAndSubImageTest<T, S, N, D, I>::CleanProgram()
2304 {
2305         /* Shortcut for GL functionality. */
2306         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2307
2308         /* Program. */
2309         if (m_po)
2310         {
2311                 gl.useProgram(0);
2312
2313                 gl.deleteProgram(m_po);
2314
2315                 m_po = 0;
2316         }
2317 }
2318
2319 /** @brief Clean GL objects, test variables and GL errors.
2320  */
2321 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2322 void StorageAndSubImageTest<T, S, N, D, I>::CleanErrors()
2323 {
2324         /* Shortcut for GL functionality. */
2325         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2326
2327         /* Query all errors until GL_NO_ERROR occure. */
2328         while (GL_NO_ERROR != gl.getError())
2329                 ;
2330 }
2331
2332 /** @brief Clean GL objects, test variables and GL errors.
2333  */
2334 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2335 void StorageAndSubImageTest<T, S, N, D, I>::CleanVertexArray()
2336 {
2337         /* Shortcut for GL functionality. */
2338         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2339
2340         if (m_vao)
2341         {
2342                 gl.bindVertexArray(0);
2343
2344                 gl.deleteVertexArrays(1, &m_vao);
2345
2346                 m_vao = 0;
2347         }
2348 }
2349
2350 /** @brief Iterate Storage Test cases.
2351  *
2352  *  @return Iteration result.
2353  */
2354 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2355 tcu::TestNode::IterateResult StorageAndSubImageTest<T, S, N, D, I>::iterate()
2356 {
2357         /* Shortcut for GL functionality. */
2358         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2359
2360         /* Get context setup. */
2361         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
2362         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
2363
2364         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
2365         {
2366                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
2367
2368                 return STOP;
2369         }
2370
2371         /* Running tests. */
2372         bool is_ok      = true;
2373         bool is_error = false;
2374
2375         try
2376         {
2377                 PrepareVertexArray();
2378                 PrepareProgram(FragmentShaderDeclaration(), FragmentShaderTail());
2379                 is_ok = Test();
2380         }
2381         catch (tcu::NotSupportedError e)
2382         {
2383                 throw e;
2384         }
2385         catch (...)
2386         {
2387                 is_ok   = false;
2388                 is_error = true;
2389         }
2390
2391         /* Cleanup. */
2392         CleanTexture();
2393         CleanFramebuffer();
2394         CleanProgram();
2395         CleanErrors();
2396         CleanVertexArray();
2397
2398         /* Errors clean up. */
2399         while (gl.getError())
2400                 ;
2401
2402         /* Result's setup. */
2403         if (is_ok)
2404         {
2405                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
2406         }
2407         else
2408         {
2409                 if (is_error)
2410                 {
2411                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
2412                 }
2413                 else
2414                 {
2415                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
2416                 }
2417         }
2418
2419         return STOP;
2420 }
2421
2422 /* Vertex shader source code. */
2423 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2424 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_vertex_shader =
2425         "#version 450\n"
2426         "\n"
2427         "void main()\n"
2428         "{\n"
2429         "    switch(gl_VertexID)\n"
2430         "    {\n"
2431         "        case 0:\n"
2432         "            gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
2433         "            break;\n"
2434         "        case 1:\n"
2435         "            gl_Position = vec4( 1.0, 1.0, 0.0, 1.0);\n"
2436         "            break;\n"
2437         "        case 2:\n"
2438         "            gl_Position = vec4(-1.0,-1.0, 0.0, 1.0);\n"
2439         "            break;\n"
2440         "        case 3:\n"
2441         "            gl_Position = vec4( 1.0,-1.0, 0.0, 1.0);\n"
2442         "            break;\n"
2443         "    }\n"
2444         "}\n";
2445
2446 /* Fragment shader source program. */
2447 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2448 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_head =
2449         "#version 450\n"
2450         "\n"
2451         "layout(pixel_center_integer) in vec4 gl_FragCoord;\n"
2452         "\n";
2453
2454 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2455 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_fdecl_lowp =
2456         "uniform  sampler1D texture_input;\nout     vec4          texture_output;\n";
2457 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2458 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_idecl_lowp =
2459         "uniform isampler1D texture_input;\nout     ivec4         texture_output;\n";
2460 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2461 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_udecl_lowp =
2462         "uniform usampler1D texture_input;\nout     uvec4         texture_output;\n";
2463 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2464 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_fdecl_mediump =
2465         "uniform  sampler1D texture_input;\nout     vec4          texture_output;\n";
2466 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2467 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_idecl_mediump =
2468         "uniform isampler1D texture_input;\nout     ivec4         texture_output;\n";
2469 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2470 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_udecl_mediump =
2471         "uniform usampler1D texture_input;\nout     uvec4         texture_output;\n";
2472 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2473 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_fdecl_highp =
2474         "uniform  sampler1D texture_input;\nout     vec4          texture_output;\n";
2475 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2476 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_idecl_highp =
2477         "uniform isampler1D texture_input;\nout     ivec4         texture_output;\n";
2478 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2479 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_udecl_highp =
2480         "uniform usampler1D texture_input;\nout     uvec4         texture_output;\n";
2481
2482 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2483 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_fdecl_lowp =
2484         "uniform  sampler2D texture_input;\nout     vec4          texture_output;\n";
2485 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2486 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_idecl_lowp =
2487         "uniform isampler2D texture_input;\nout     ivec4         texture_output;\n";
2488 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2489 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_udecl_lowp =
2490         "uniform usampler2D texture_input;\nout     uvec4         texture_output;\n";
2491 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2492 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_fdecl_mediump =
2493         "uniform  sampler2D texture_input;\nout     vec4          texture_output;\n";
2494 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2495 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_idecl_mediump =
2496         "uniform isampler2D texture_input;\nout     ivec4         texture_output;\n";
2497 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2498 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_udecl_mediump =
2499         "uniform usampler2D texture_input;\nout     uvec4         texture_output;\n";
2500 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2501 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_fdecl_highp =
2502         "uniform  sampler2D texture_input;\nout     vec4          texture_output;\n";
2503 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2504 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_idecl_highp =
2505         "uniform isampler2D texture_input;\nout     ivec4         texture_output;\n";
2506 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2507 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_udecl_highp =
2508         "uniform usampler2D texture_input;\nout     uvec4         texture_output;\n";
2509
2510 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2511 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_fdecl_lowp =
2512         "uniform  sampler3D texture_input;\nout     vec4          texture_output;\n";
2513 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2514 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_idecl_lowp =
2515         "uniform isampler3D texture_input;\nout     ivec4         texture_output;\n";
2516 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2517 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_udecl_lowp =
2518         "uniform usampler3D texture_input;\nout     uvec4         texture_output;\n";
2519 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2520 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_fdecl_mediump =
2521         "uniform  sampler3D texture_input;\nout     vec4          texture_output;\n";
2522 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2523 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_idecl_mediump =
2524         "uniform isampler3D texture_input;\nout     ivec4         texture_output;\n";
2525 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2526 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_udecl_mediump =
2527         "uniform usampler3D texture_input;\nout     uvec4         texture_output;\n";
2528 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2529 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_fdecl_highp =
2530         "uniform  sampler3D texture_input;\nout     vec4          texture_output;\n";
2531 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2532 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_idecl_highp =
2533         "uniform isampler3D texture_input;\nout     ivec4         texture_output;\n";
2534 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2535 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_udecl_highp =
2536         "uniform usampler3D texture_input;\nout     uvec4         texture_output;\n";
2537
2538 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2539 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_tail =
2540         "\n"
2541         "void main()\n"
2542         "{\n"
2543         "    texture_output = texelFetch(texture_input, int(gl_FragCoord.x), 0);\n"
2544         "}\n";
2545
2546 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2547 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_tail =
2548         "\n"
2549         "void main()\n"
2550         "{\n"
2551         "    texture_output = texelFetch(texture_input, ivec2(int(gl_FragCoord.x) % 2, int(floor(gl_FragCoord.x / 2))), "
2552         "0);\n"
2553         "}\n";
2554
2555 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2556 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_tail =
2557         "\n"
2558         "void main()\n"
2559         "{\n"
2560         "    texture_output = texelFetch(texture_input, ivec3(int(gl_FragCoord.x) % 2, int(floor(gl_FragCoord.x / 2)) % 3, "
2561         "int(floor(gl_FragCoord.x / 2 / 3))), 0);\n"
2562         "}\n";
2563
2564 template class StorageAndSubImageTest<glw::GLbyte, 1, false, 1, false>;
2565 template class StorageAndSubImageTest<glw::GLbyte, 2, false, 1, false>;
2566 template class StorageAndSubImageTest<glw::GLbyte, 4, false, 1, false>;
2567 template class StorageAndSubImageTest<glw::GLbyte, 1, false, 2, false>;
2568 template class StorageAndSubImageTest<glw::GLbyte, 2, false, 2, false>;
2569 template class StorageAndSubImageTest<glw::GLbyte, 4, false, 2, false>;
2570 template class StorageAndSubImageTest<glw::GLbyte, 1, false, 3, false>;
2571 template class StorageAndSubImageTest<glw::GLbyte, 2, false, 3, false>;
2572 template class StorageAndSubImageTest<glw::GLbyte, 4, false, 3, false>;
2573
2574 template class StorageAndSubImageTest<glw::GLubyte, 1, false, 1, false>;
2575 template class StorageAndSubImageTest<glw::GLubyte, 2, false, 1, false>;
2576 template class StorageAndSubImageTest<glw::GLubyte, 4, false, 1, false>;
2577 template class StorageAndSubImageTest<glw::GLubyte, 1, false, 2, false>;
2578 template class StorageAndSubImageTest<glw::GLubyte, 2, false, 2, false>;
2579 template class StorageAndSubImageTest<glw::GLubyte, 4, false, 2, false>;
2580 template class StorageAndSubImageTest<glw::GLubyte, 1, false, 3, false>;
2581 template class StorageAndSubImageTest<glw::GLubyte, 2, false, 3, false>;
2582 template class StorageAndSubImageTest<glw::GLubyte, 4, false, 3, false>;
2583
2584 template class StorageAndSubImageTest<glw::GLubyte, 1, true, 1, false>;
2585 template class StorageAndSubImageTest<glw::GLubyte, 2, true, 1, false>;
2586 template class StorageAndSubImageTest<glw::GLubyte, 4, true, 1, false>;
2587 template class StorageAndSubImageTest<glw::GLubyte, 1, true, 2, false>;
2588 template class StorageAndSubImageTest<glw::GLubyte, 2, true, 2, false>;
2589 template class StorageAndSubImageTest<glw::GLubyte, 4, true, 2, false>;
2590 template class StorageAndSubImageTest<glw::GLubyte, 1, true, 3, false>;
2591 template class StorageAndSubImageTest<glw::GLubyte, 2, true, 3, false>;
2592 template class StorageAndSubImageTest<glw::GLubyte, 4, true, 3, false>;
2593
2594 template class StorageAndSubImageTest<glw::GLshort, 1, false, 1, false>;
2595 template class StorageAndSubImageTest<glw::GLshort, 2, false, 1, false>;
2596 template class StorageAndSubImageTest<glw::GLshort, 4, false, 1, false>;
2597 template class StorageAndSubImageTest<glw::GLshort, 1, false, 2, false>;
2598 template class StorageAndSubImageTest<glw::GLshort, 2, false, 2, false>;
2599 template class StorageAndSubImageTest<glw::GLshort, 4, false, 2, false>;
2600 template class StorageAndSubImageTest<glw::GLshort, 1, false, 3, false>;
2601 template class StorageAndSubImageTest<glw::GLshort, 2, false, 3, false>;
2602 template class StorageAndSubImageTest<glw::GLshort, 4, false, 3, false>;
2603
2604 template class StorageAndSubImageTest<glw::GLushort, 1, false, 1, false>;
2605 template class StorageAndSubImageTest<glw::GLushort, 2, false, 1, false>;
2606 template class StorageAndSubImageTest<glw::GLushort, 4, false, 1, false>;
2607 template class StorageAndSubImageTest<glw::GLushort, 1, false, 2, false>;
2608 template class StorageAndSubImageTest<glw::GLushort, 2, false, 2, false>;
2609 template class StorageAndSubImageTest<glw::GLushort, 4, false, 2, false>;
2610 template class StorageAndSubImageTest<glw::GLushort, 1, false, 3, false>;
2611 template class StorageAndSubImageTest<glw::GLushort, 2, false, 3, false>;
2612 template class StorageAndSubImageTest<glw::GLushort, 4, false, 3, false>;
2613
2614 template class StorageAndSubImageTest<glw::GLushort, 1, true, 1, false>;
2615 template class StorageAndSubImageTest<glw::GLushort, 2, true, 1, false>;
2616 template class StorageAndSubImageTest<glw::GLushort, 4, true, 1, false>;
2617 template class StorageAndSubImageTest<glw::GLushort, 1, true, 2, false>;
2618 template class StorageAndSubImageTest<glw::GLushort, 2, true, 2, false>;
2619 template class StorageAndSubImageTest<glw::GLushort, 4, true, 2, false>;
2620 template class StorageAndSubImageTest<glw::GLushort, 1, true, 3, false>;
2621 template class StorageAndSubImageTest<glw::GLushort, 2, true, 3, false>;
2622 template class StorageAndSubImageTest<glw::GLushort, 4, true, 3, false>;
2623
2624 template class StorageAndSubImageTest<glw::GLint, 1, false, 1, false>;
2625 template class StorageAndSubImageTest<glw::GLint, 2, false, 1, false>;
2626 template class StorageAndSubImageTest<glw::GLint, 3, false, 1, false>;
2627 template class StorageAndSubImageTest<glw::GLint, 4, false, 1, false>;
2628 template class StorageAndSubImageTest<glw::GLint, 1, false, 2, false>;
2629 template class StorageAndSubImageTest<glw::GLint, 2, false, 2, false>;
2630 template class StorageAndSubImageTest<glw::GLint, 3, false, 2, false>;
2631 template class StorageAndSubImageTest<glw::GLint, 4, false, 2, false>;
2632 template class StorageAndSubImageTest<glw::GLint, 1, false, 3, false>;
2633 template class StorageAndSubImageTest<glw::GLint, 2, false, 3, false>;
2634 template class StorageAndSubImageTest<glw::GLint, 3, false, 3, false>;
2635 template class StorageAndSubImageTest<glw::GLint, 4, false, 3, false>;
2636
2637 template class StorageAndSubImageTest<glw::GLuint, 1, false, 1, false>;
2638 template class StorageAndSubImageTest<glw::GLuint, 2, false, 1, false>;
2639 template class StorageAndSubImageTest<glw::GLuint, 3, false, 1, false>;
2640 template class StorageAndSubImageTest<glw::GLuint, 4, false, 1, false>;
2641 template class StorageAndSubImageTest<glw::GLuint, 1, false, 2, false>;
2642 template class StorageAndSubImageTest<glw::GLuint, 2, false, 2, false>;
2643 template class StorageAndSubImageTest<glw::GLuint, 3, false, 2, false>;
2644 template class StorageAndSubImageTest<glw::GLuint, 4, false, 2, false>;
2645 template class StorageAndSubImageTest<glw::GLuint, 1, false, 3, false>;
2646 template class StorageAndSubImageTest<glw::GLuint, 2, false, 3, false>;
2647 template class StorageAndSubImageTest<glw::GLuint, 3, false, 3, false>;
2648 template class StorageAndSubImageTest<glw::GLuint, 4, false, 3, false>;
2649
2650 template class StorageAndSubImageTest<glw::GLfloat, 1, true, 1, false>;
2651 template class StorageAndSubImageTest<glw::GLfloat, 2, true, 1, false>;
2652 template class StorageAndSubImageTest<glw::GLfloat, 3, true, 1, false>;
2653 template class StorageAndSubImageTest<glw::GLfloat, 4, true, 1, false>;
2654 template class StorageAndSubImageTest<glw::GLfloat, 1, true, 2, false>;
2655 template class StorageAndSubImageTest<glw::GLfloat, 2, true, 2, false>;
2656 template class StorageAndSubImageTest<glw::GLfloat, 3, true, 2, false>;
2657 template class StorageAndSubImageTest<glw::GLfloat, 4, true, 2, false>;
2658 template class StorageAndSubImageTest<glw::GLfloat, 1, true, 3, false>;
2659 template class StorageAndSubImageTest<glw::GLfloat, 2, true, 3, false>;
2660 template class StorageAndSubImageTest<glw::GLfloat, 3, true, 3, false>;
2661 template class StorageAndSubImageTest<glw::GLfloat, 4, true, 3, false>;
2662
2663 template class StorageAndSubImageTest<glw::GLbyte, 1, false, 1, true>;
2664 template class StorageAndSubImageTest<glw::GLbyte, 2, false, 1, true>;
2665 template class StorageAndSubImageTest<glw::GLbyte, 4, false, 1, true>;
2666 template class StorageAndSubImageTest<glw::GLbyte, 1, false, 2, true>;
2667 template class StorageAndSubImageTest<glw::GLbyte, 2, false, 2, true>;
2668 template class StorageAndSubImageTest<glw::GLbyte, 4, false, 2, true>;
2669 template class StorageAndSubImageTest<glw::GLbyte, 1, false, 3, true>;
2670 template class StorageAndSubImageTest<glw::GLbyte, 2, false, 3, true>;
2671 template class StorageAndSubImageTest<glw::GLbyte, 4, false, 3, true>;
2672
2673 template class StorageAndSubImageTest<glw::GLubyte, 1, false, 1, true>;
2674 template class StorageAndSubImageTest<glw::GLubyte, 2, false, 1, true>;
2675 template class StorageAndSubImageTest<glw::GLubyte, 4, false, 1, true>;
2676 template class StorageAndSubImageTest<glw::GLubyte, 1, false, 2, true>;
2677 template class StorageAndSubImageTest<glw::GLubyte, 2, false, 2, true>;
2678 template class StorageAndSubImageTest<glw::GLubyte, 4, false, 2, true>;
2679 template class StorageAndSubImageTest<glw::GLubyte, 1, false, 3, true>;
2680 template class StorageAndSubImageTest<glw::GLubyte, 2, false, 3, true>;
2681 template class StorageAndSubImageTest<glw::GLubyte, 4, false, 3, true>;
2682
2683 template class StorageAndSubImageTest<glw::GLubyte, 1, true, 1, true>;
2684 template class StorageAndSubImageTest<glw::GLubyte, 2, true, 1, true>;
2685 template class StorageAndSubImageTest<glw::GLubyte, 4, true, 1, true>;
2686 template class StorageAndSubImageTest<glw::GLubyte, 1, true, 2, true>;
2687 template class StorageAndSubImageTest<glw::GLubyte, 2, true, 2, true>;
2688 template class StorageAndSubImageTest<glw::GLubyte, 4, true, 2, true>;
2689 template class StorageAndSubImageTest<glw::GLubyte, 1, true, 3, true>;
2690 template class StorageAndSubImageTest<glw::GLubyte, 2, true, 3, true>;
2691 template class StorageAndSubImageTest<glw::GLubyte, 4, true, 3, true>;
2692
2693 template class StorageAndSubImageTest<glw::GLshort, 1, false, 1, true>;
2694 template class StorageAndSubImageTest<glw::GLshort, 2, false, 1, true>;
2695 template class StorageAndSubImageTest<glw::GLshort, 4, false, 1, true>;
2696 template class StorageAndSubImageTest<glw::GLshort, 1, false, 2, true>;
2697 template class StorageAndSubImageTest<glw::GLshort, 2, false, 2, true>;
2698 template class StorageAndSubImageTest<glw::GLshort, 4, false, 2, true>;
2699 template class StorageAndSubImageTest<glw::GLshort, 1, false, 3, true>;
2700 template class StorageAndSubImageTest<glw::GLshort, 2, false, 3, true>;
2701 template class StorageAndSubImageTest<glw::GLshort, 4, false, 3, true>;
2702
2703 template class StorageAndSubImageTest<glw::GLushort, 1, false, 1, true>;
2704 template class StorageAndSubImageTest<glw::GLushort, 2, false, 1, true>;
2705 template class StorageAndSubImageTest<glw::GLushort, 4, false, 1, true>;
2706 template class StorageAndSubImageTest<glw::GLushort, 1, false, 2, true>;
2707 template class StorageAndSubImageTest<glw::GLushort, 2, false, 2, true>;
2708 template class StorageAndSubImageTest<glw::GLushort, 4, false, 2, true>;
2709 template class StorageAndSubImageTest<glw::GLushort, 1, false, 3, true>;
2710 template class StorageAndSubImageTest<glw::GLushort, 2, false, 3, true>;
2711 template class StorageAndSubImageTest<glw::GLushort, 4, false, 3, true>;
2712
2713 template class StorageAndSubImageTest<glw::GLushort, 1, true, 1, true>;
2714 template class StorageAndSubImageTest<glw::GLushort, 2, true, 1, true>;
2715 template class StorageAndSubImageTest<glw::GLushort, 4, true, 1, true>;
2716 template class StorageAndSubImageTest<glw::GLushort, 1, true, 2, true>;
2717 template class StorageAndSubImageTest<glw::GLushort, 2, true, 2, true>;
2718 template class StorageAndSubImageTest<glw::GLushort, 4, true, 2, true>;
2719 template class StorageAndSubImageTest<glw::GLushort, 1, true, 3, true>;
2720 template class StorageAndSubImageTest<glw::GLushort, 2, true, 3, true>;
2721 template class StorageAndSubImageTest<glw::GLushort, 4, true, 3, true>;
2722
2723 template class StorageAndSubImageTest<glw::GLint, 1, false, 1, true>;
2724 template class StorageAndSubImageTest<glw::GLint, 2, false, 1, true>;
2725 template class StorageAndSubImageTest<glw::GLint, 3, false, 1, true>;
2726 template class StorageAndSubImageTest<glw::GLint, 4, false, 1, true>;
2727 template class StorageAndSubImageTest<glw::GLint, 1, false, 2, true>;
2728 template class StorageAndSubImageTest<glw::GLint, 2, false, 2, true>;
2729 template class StorageAndSubImageTest<glw::GLint, 3, false, 2, true>;
2730 template class StorageAndSubImageTest<glw::GLint, 4, false, 2, true>;
2731 template class StorageAndSubImageTest<glw::GLint, 1, false, 3, true>;
2732 template class StorageAndSubImageTest<glw::GLint, 2, false, 3, true>;
2733 template class StorageAndSubImageTest<glw::GLint, 3, false, 3, true>;
2734 template class StorageAndSubImageTest<glw::GLint, 4, false, 3, true>;
2735
2736 template class StorageAndSubImageTest<glw::GLuint, 1, false, 1, true>;
2737 template class StorageAndSubImageTest<glw::GLuint, 2, false, 1, true>;
2738 template class StorageAndSubImageTest<glw::GLuint, 3, false, 1, true>;
2739 template class StorageAndSubImageTest<glw::GLuint, 4, false, 1, true>;
2740 template class StorageAndSubImageTest<glw::GLuint, 1, false, 2, true>;
2741 template class StorageAndSubImageTest<glw::GLuint, 2, false, 2, true>;
2742 template class StorageAndSubImageTest<glw::GLuint, 3, false, 2, true>;
2743 template class StorageAndSubImageTest<glw::GLuint, 4, false, 2, true>;
2744 template class StorageAndSubImageTest<glw::GLuint, 1, false, 3, true>;
2745 template class StorageAndSubImageTest<glw::GLuint, 2, false, 3, true>;
2746 template class StorageAndSubImageTest<glw::GLuint, 3, false, 3, true>;
2747 template class StorageAndSubImageTest<glw::GLuint, 4, false, 3, true>;
2748
2749 template class StorageAndSubImageTest<glw::GLfloat, 1, true, 1, true>;
2750 template class StorageAndSubImageTest<glw::GLfloat, 2, true, 1, true>;
2751 template class StorageAndSubImageTest<glw::GLfloat, 3, true, 1, true>;
2752 template class StorageAndSubImageTest<glw::GLfloat, 4, true, 1, true>;
2753 template class StorageAndSubImageTest<glw::GLfloat, 1, true, 2, true>;
2754 template class StorageAndSubImageTest<glw::GLfloat, 2, true, 2, true>;
2755 template class StorageAndSubImageTest<glw::GLfloat, 3, true, 2, true>;
2756 template class StorageAndSubImageTest<glw::GLfloat, 4, true, 2, true>;
2757 template class StorageAndSubImageTest<glw::GLfloat, 1, true, 3, true>;
2758 template class StorageAndSubImageTest<glw::GLfloat, 2, true, 3, true>;
2759 template class StorageAndSubImageTest<glw::GLfloat, 3, true, 3, true>;
2760 template class StorageAndSubImageTest<glw::GLfloat, 4, true, 3, true>;
2761
2762 /******************************** Storage Multisample Test Implementation   ********************************/
2763
2764 /** @brief Storage Multisample Test constructor.
2765  *
2766  *  @param [in] context     OpenGL context.
2767  */
2768 StorageMultisampleTest::StorageMultisampleTest(deqp::Context& context)
2769         : deqp::TestCase(context, "textures_storage_multisample", "Texture Storage Multisample Test")
2770         , m_fbo_ms(0)
2771         , m_fbo_aux(0)
2772         , m_to_ms(0)
2773         , m_po_ms(0)
2774         , m_po_aux(0)
2775         , m_to(0)
2776         , m_to_aux(0)
2777         , m_vao(0)
2778 {
2779         /* Intentionally left blank. */
2780 }
2781
2782 /** @brief Count of reference data to be teted.
2783  *
2784  *  @tparam S      Size (# of components).
2785  *  @tparam D      Texture dimenisons.
2786  *
2787  *  @return Count.
2788  */
2789 template <glw::GLint S, glw::GLuint D>
2790 glw::GLuint StorageMultisampleTest::TestReferenceDataCount()
2791 {
2792         return 2 /* 1D */ * ((D > 1) ? 3 : 1) /* 2D */ * ((D > 2) ? 4 : 1) /* 3D */ * S /* components */;
2793 }
2794
2795 /** @brief Size of reference data to be teted.
2796  *
2797  *  @tparam T      Type.
2798  *  @tparam S      Size (# of components).
2799  *  @tparam D      Texture dimenisons.
2800  *
2801  *  @return Size.
2802  */
2803 template <typename T, glw::GLint S, glw::GLuint D>
2804 glw::GLuint StorageMultisampleTest::TestReferenceDataSize()
2805 {
2806         return TestReferenceDataCount<S, D>() * sizeof(T);
2807 }
2808
2809 /** @brief Height, width or depth of reference data to be teted.
2810  *
2811  *  @tparam D      Texture dimenisons.
2812  *
2813  *  @return Height, width or depth.
2814  */
2815 template <>
2816 glw::GLuint StorageMultisampleTest::TestReferenceDataHeight<2>()
2817 {
2818         return 3;
2819 }
2820
2821 template <>
2822 glw::GLuint StorageMultisampleTest::TestReferenceDataHeight<3>()
2823 {
2824         return TestReferenceDataHeight<2>();
2825 }
2826
2827 template <>
2828 glw::GLuint StorageMultisampleTest::TestReferenceDataDepth<2>()
2829 {
2830         return 1;
2831 }
2832
2833 template <>
2834 glw::GLuint StorageMultisampleTest::TestReferenceDataDepth<3>()
2835 {
2836         return 4;
2837 }
2838
2839 template <glw::GLuint D>
2840 glw::GLuint                       StorageMultisampleTest::TestReferenceDataWidth()
2841 {
2842         return 2;
2843 }
2844
2845 /** @brief Fragment shader declaration selector.
2846  *
2847  *  @tparam T      Type.
2848  *  @tparam N      Normalized flag.
2849  *  @tparam D      Texture dimenisons.
2850  *
2851  *  @return Frgment shader source code part.
2852  */
2853 template <>
2854 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLubyte, true, 2>()
2855 {
2856         return s_fragment_shader_ms_2D_fdecl_lowp;
2857 }
2858
2859 template <>
2860 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLbyte, false, 2>()
2861 {
2862         return s_fragment_shader_ms_2D_idecl_lowp;
2863 }
2864
2865 template <>
2866 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLubyte, false, 2>()
2867 {
2868         return s_fragment_shader_ms_2D_udecl_lowp;
2869 }
2870
2871 template <>
2872 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLushort, true, 2>()
2873 {
2874         return s_fragment_shader_ms_2D_fdecl_mediump;
2875 }
2876
2877 template <>
2878 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLshort, false, 2>()
2879 {
2880         return s_fragment_shader_ms_2D_idecl_mediump;
2881 }
2882
2883 template <>
2884 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLushort, false, 2>()
2885 {
2886         return s_fragment_shader_ms_2D_udecl_mediump;
2887 }
2888
2889 template <>
2890 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLfloat, true, 2>()
2891 {
2892         return s_fragment_shader_ms_2D_fdecl_highp;
2893 }
2894
2895 template <>
2896 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLint, false, 2>()
2897 {
2898         return s_fragment_shader_ms_2D_idecl_highp;
2899 }
2900
2901 template <>
2902 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLuint, false, 2>()
2903 {
2904         return s_fragment_shader_ms_2D_udecl_highp;
2905 }
2906
2907 /** @brief Fragment shader declaration selector.
2908  *
2909  *  @tparam T      Type.
2910  *  @tparam N      Normalized flag.
2911  *  @tparam D      Texture dimenisons.
2912  *
2913  *  @return Frgment shader source code part.
2914  */
2915 template <>
2916 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLubyte, true, 3>()
2917 {
2918         return s_fragment_shader_ms_3D_fdecl_lowp;
2919 }
2920
2921 template <>
2922 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLbyte, false, 3>()
2923 {
2924         return s_fragment_shader_ms_3D_idecl_lowp;
2925 }
2926
2927 template <>
2928 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLubyte, false, 3>()
2929 {
2930         return s_fragment_shader_ms_3D_udecl_lowp;
2931 }
2932
2933 template <>
2934 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLushort, true, 3>()
2935 {
2936         return s_fragment_shader_ms_3D_fdecl_mediump;
2937 }
2938
2939 template <>
2940 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLshort, false, 3>()
2941 {
2942         return s_fragment_shader_ms_3D_idecl_mediump;
2943 }
2944
2945 template <>
2946 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLushort, false, 3>()
2947 {
2948         return s_fragment_shader_ms_3D_udecl_mediump;
2949 }
2950
2951 template <>
2952 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLfloat, true, 3>()
2953 {
2954         return s_fragment_shader_ms_3D_fdecl_highp;
2955 }
2956
2957 template <>
2958 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLint, false, 3>()
2959 {
2960         return s_fragment_shader_ms_3D_idecl_highp;
2961 }
2962
2963 template <>
2964 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLuint, false, 3>()
2965 {
2966         return s_fragment_shader_ms_3D_udecl_highp;
2967 }
2968
2969 /** @brief Fragment shader declaration selector.
2970  *
2971  *  @tparam T      Type.
2972  *  @tparam N      Normalized flag.
2973  *  @tparam D      Texture dimenisons.
2974  *
2975  *  @return Frgment shader source code part.
2976  */
2977 template <>
2978 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLubyte, true, 2>()
2979 {
2980         return s_fragment_shader_aux_2D_fdecl_lowp;
2981 }
2982
2983 template <>
2984 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLbyte, false, 2>()
2985 {
2986         return s_fragment_shader_aux_2D_idecl_lowp;
2987 }
2988
2989 template <>
2990 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLubyte, false, 2>()
2991 {
2992         return s_fragment_shader_aux_2D_udecl_lowp;
2993 }
2994
2995 template <>
2996 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLushort, true, 2>()
2997 {
2998         return s_fragment_shader_aux_2D_fdecl_mediump;
2999 }
3000
3001 template <>
3002 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLshort, false, 2>()
3003 {
3004         return s_fragment_shader_aux_2D_idecl_mediump;
3005 }
3006
3007 template <>
3008 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLushort, false, 2>()
3009 {
3010         return s_fragment_shader_aux_2D_udecl_mediump;
3011 }
3012
3013 template <>
3014 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLfloat, true, 2>()
3015 {
3016         return s_fragment_shader_aux_2D_fdecl_highp;
3017 }
3018
3019 template <>
3020 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLint, false, 2>()
3021 {
3022         return s_fragment_shader_aux_2D_idecl_highp;
3023 }
3024
3025 template <>
3026 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLuint, false, 2>()
3027 {
3028         return s_fragment_shader_aux_2D_udecl_highp;
3029 }
3030
3031 /** @brief Fragment shader declaration selector.
3032  *
3033  *  @tparam T      Type.
3034  *  @tparam N      Normalized flag.
3035  *  @tparam D      Texture dimenisons.
3036  *
3037  *  @return Frgment shader source code part.
3038  */
3039 template <>
3040 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLubyte, true, 3>()
3041 {
3042         return s_fragment_shader_aux_3D_fdecl_lowp;
3043 }
3044
3045 template <>
3046 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLbyte, false, 3>()
3047 {
3048         return s_fragment_shader_aux_3D_idecl_lowp;
3049 }
3050
3051 template <>
3052 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLubyte, false, 3>()
3053 {
3054         return s_fragment_shader_aux_3D_udecl_lowp;
3055 }
3056
3057 template <>
3058 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLushort, true, 3>()
3059 {
3060         return s_fragment_shader_aux_3D_fdecl_mediump;
3061 }
3062
3063 template <>
3064 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLshort, false, 3>()
3065 {
3066         return s_fragment_shader_aux_3D_idecl_mediump;
3067 }
3068
3069 template <>
3070 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLushort, false, 3>()
3071 {
3072         return s_fragment_shader_aux_3D_udecl_mediump;
3073 }
3074
3075 template <>
3076 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLfloat, true, 3>()
3077 {
3078         return s_fragment_shader_aux_3D_fdecl_highp;
3079 }
3080
3081 template <>
3082 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLint, false, 3>()
3083 {
3084         return s_fragment_shader_aux_3D_idecl_highp;
3085 }
3086
3087 template <>
3088 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLuint, false, 3>()
3089 {
3090         return s_fragment_shader_aux_3D_udecl_highp;
3091 }
3092
3093 /** @brief Fragment shader tail selector.
3094  *
3095  *  @tparam D      Texture dimenisons.
3096  *
3097  *  @return Frgment shader source code part.
3098  */
3099 template <>
3100 const glw::GLchar* StorageMultisampleTest::FragmentShaderTail<2>()
3101 {
3102         return s_fragment_shader_tail_2D;
3103 }
3104
3105 template <>
3106 const glw::GLchar* StorageMultisampleTest::FragmentShaderTail<3>()
3107 {
3108         return s_fragment_shader_tail_3D;
3109 }
3110
3111 /** @brief Texture target selector.
3112  *
3113  *  @tparam D      Texture dimenisons.
3114  *
3115  *  @return Texture target.
3116  */
3117 template <>
3118 glw::GLenum StorageMultisampleTest::InputTextureTarget<2>()
3119 {
3120         return GL_TEXTURE_2D;
3121 }
3122
3123 template <>
3124 glw::GLenum StorageMultisampleTest::InputTextureTarget<3>()
3125 {
3126         return GL_TEXTURE_2D_ARRAY;
3127 }
3128
3129 /** @brief Prepare texture data for input texture.
3130  *
3131  *  @tparam D      Texture dimenisons.
3132  *
3133  *  @note parameters as passed to texImage*
3134  */
3135 template <>
3136 void StorageMultisampleTest::InputTextureImage<2>(const glw::GLenum internal_format, const glw::GLuint width,
3137                                                                                                   const glw::GLuint height, const glw::GLuint depth,
3138                                                                                                   const glw::GLenum format, const glw::GLenum type,
3139                                                                                                   const glw::GLvoid* data)
3140 {
3141         (void)depth;
3142         /* Shortcut for GL functionality. */
3143         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3144
3145         /* Data setup. */
3146         gl.texImage2D(InputTextureTarget<2>(), 0, internal_format, width, height, 0, format, type, data);
3147         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
3148 }
3149
3150 /** @brief Prepare texture data for input texture.
3151  *
3152  *  @tparam D      Texture dimenisons.
3153  *
3154  *  @note parameters as passed to texImage*
3155  */
3156 template <>
3157 void StorageMultisampleTest::InputTextureImage<3>(const glw::GLenum internal_format, const glw::GLuint width,
3158                                                                                                   const glw::GLuint height, const glw::GLuint depth,
3159                                                                                                   const glw::GLenum format, const glw::GLenum type,
3160                                                                                                   const glw::GLvoid* data)
3161 {
3162         /* Shortcut for GL functionality. */
3163         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3164
3165         /* Data setup. */
3166         gl.texImage3D(InputTextureTarget<3>(), 0, internal_format, width, height, depth, 0, format, type, data);
3167         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
3168 }
3169
3170 /** @brief Create texture.
3171  *
3172  *  @tparam T      Type.
3173  *  @tparam S      Size (# of components).
3174  *  @tparam N      Is normalized.
3175  *  @tparam D      Dimmensions.
3176  */
3177 template <typename T, glw::GLint S, bool N, glw::GLuint D>
3178 void StorageMultisampleTest::CreateInputTexture()
3179 {
3180         /* Shortcut for GL functionality. */
3181         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3182
3183         /* Objects creation. */
3184         gl.genTextures(1, &m_to);
3185         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
3186
3187         gl.bindTexture(InputTextureTarget<D>(), m_to);
3188         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
3189
3190         /* Data setup. */
3191         InputTextureImage<D>(InternalFormat<T, S, N>(), TestReferenceDataWidth<D>(), TestReferenceDataHeight<D>(),
3192                                                  TestReferenceDataDepth<D>(), Format<S, N>(), Type<T>(), ReferenceData<T, N>());
3193
3194         /* Parameter setup. */
3195         gl.texParameteri(InputTextureTarget<D>(), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3196         gl.texParameteri(InputTextureTarget<D>(), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3197         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
3198 }
3199
3200 /** @brief Compre results with the reference.
3201  *
3202  *  @tparam T      Type.
3203  *  @tparam S      Size (# of components).
3204  *  @tparam N      Is normalized.
3205  *
3206  *  @return True if equal, false otherwise.
3207  */
3208 template <typename T, glw::GLint S, bool N, glw::GLuint D>
3209 bool StorageMultisampleTest::Check()
3210 {
3211         /* Shortcut for GL functionality. */
3212         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3213
3214         /* Fetching data fro auxiliary texture. */
3215         std::vector<T> result(TestReferenceDataCount<S, D>());
3216
3217         gl.bindTexture(InputTextureTarget<D>() /* Auxiliary target is the same as input. */, m_to_aux);
3218         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
3219
3220         gl.getTexImage(InputTextureTarget<D>() /* Auxiliary target is the same as input. */, 0, Format<S, N>(), Type<T>(),
3221                                    (glw::GLvoid*)(&result[0]));
3222         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexImage has failed");
3223
3224         /* Comparison. */
3225         for (glw::GLuint i = 0; i < TestReferenceDataCount<S, D>(); ++i)
3226         {
3227                 if (!Compare<T>(result[i], ReferenceData<T, N>()[i]))
3228                 {
3229                         return false;
3230                 }
3231         }
3232
3233         return true;
3234 }
3235
3236 /** @brief Test case function.
3237  *
3238  *  @tparam T       Type.
3239  *  @tparam S       Size (# of components).
3240  *  @tparam N       Is normalized.
3241  *  @tparam D       Number of texture dimensions.
3242  *
3243  *  @return True if test succeeded, false otherwise.
3244  */
3245 template <typename T, glw::GLint S, bool N, glw::GLuint D>
3246 bool StorageMultisampleTest::Test()
3247 {
3248         /* Shortcut for GL functionality. */
3249         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3250
3251         /* Setup. */
3252         gl.pixelStorei(GL_UNPACK_ALIGNMENT, sizeof(T));
3253         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
3254
3255         gl.pixelStorei(GL_PACK_ALIGNMENT, sizeof(T));
3256         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
3257
3258         CreateInputTexture<T, S, N, D>();
3259
3260         if (!PrepareFramebufferMultisample<D>(InternalFormat<T, S, N>()))
3261         {
3262                 CleanInputTexture();
3263
3264                 return false;
3265         }
3266
3267         PrepareFramebufferAuxiliary<D>(InternalFormat<T, S, N>());
3268
3269         /* Action. */
3270         Draw<D>();
3271
3272         /* Compare results with reference. */
3273         bool result = Check<T, S, N, D>();
3274
3275         /* Cleanup. */
3276         CleanAuxiliaryTexture();
3277         CleanFramebuffers();
3278         CleanInputTexture();
3279         CleanErrors();
3280
3281         /* Pass result. */
3282         return result;
3283 }
3284
3285 /** @brief Lopp test function over S.
3286  *
3287  *  @tparam T      Type.
3288  *  @tparam N      Is normalized.
3289  *  @tparam D      Texture dimension.
3290  *
3291  *  @param [in] skip_rgb            Skip test of S = 3 (needed for some formats).
3292  *
3293  *  @return True if tests succeeded, false otherwise.
3294  */
3295 template <typename T, bool N, glw::GLuint D>
3296 bool StorageMultisampleTest::LoopTestOverS(bool skip_rgb)
3297 {
3298         /* Prepare one program to create multisample texture and one to copy it to regular texture. */
3299         m_po_ms  = PrepareProgram(FragmentShaderDeclarationMultisample<T, N, D>(), FragmentShaderTail<D>());
3300         m_po_aux = PrepareProgram(FragmentShaderDeclarationAuxiliary<T, N, D>(), FragmentShaderTail<D>());
3301
3302         /* Run tests. */
3303         bool result = true;
3304
3305         result &= Test<T, 1, N, D>();
3306
3307         result &= Test<T, 2, N, D>();
3308
3309         if (!skip_rgb)
3310         {
3311                 result &= Test<T, 3, N, D>();
3312         }
3313
3314         result &= Test<T, 4, N, D>();
3315
3316         /* Cleanup.*/
3317         CleanPrograms();
3318         CleanErrors();
3319
3320         /* Pass result. */
3321         return result;
3322 }
3323
3324 /** @brief Lopp test function over D and next over S.
3325  *
3326  *  @tparam T      Type.
3327  *  @tparam N      Is normalized.
3328  *
3329  *  @param [in] skip_rgb            Skip test of S = 3 (needed for some formats).
3330  *
3331  *  @return True if tests succeeded, false otherwise.
3332  */
3333 template <typename T, bool N>
3334 bool StorageMultisampleTest::LoopTestOverDOverS(bool skip_rgb)
3335 {
3336         bool result = true;
3337
3338         result &= LoopTestOverS<T, N, 2>(skip_rgb);
3339         result &= LoopTestOverS<T, N, 3>(skip_rgb);
3340
3341         return result;
3342 }
3343
3344 /** @brief Function prepares framebuffer with internal format color attachment.
3345  *         Viewport is set up. Content of the framebuffer is cleared.
3346  *
3347  *  @note The function may throw if unexpected error has occured.
3348  */
3349 template <>
3350 bool StorageMultisampleTest::PrepareFramebufferMultisample<2>(const glw::GLenum internal_format)
3351 {
3352         /* Shortcut for GL functionality. */
3353         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3354
3355         /* Prepare framebuffer. */
3356         gl.genFramebuffers(1, &m_fbo_ms);
3357         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
3358
3359         gl.genTextures(1, &m_to_ms);
3360         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
3361
3362         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
3363         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
3364
3365         gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_to_ms);
3366         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
3367
3368         gl.textureStorage2DMultisample(m_to_ms, 1, internal_format, TestReferenceDataWidth<2>(),
3369                                                                    TestReferenceDataHeight<2>(), false);
3370
3371         glw::GLenum error;
3372
3373         if (GL_NO_ERROR != (error = gl.getError()))
3374         {
3375                 CleanFramebuffers();
3376
3377                 m_context.getTestContext().getLog()
3378                         << tcu::TestLog::Message << "glTextureStorage2DMultisample unexpectedly generated error "
3379                         << glu::getErrorStr(error) << " during the test of internal format "
3380                         << glu::getTextureFormatStr(internal_format) << ". Test fails." << tcu::TestLog::EndMessage;
3381
3382                 return false;
3383         }
3384
3385         gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, m_to_ms, 0);
3386         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
3387
3388         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
3389         {
3390                 throw 0;
3391         }
3392
3393         gl.viewport(0, 0, TestReferenceDataWidth<2>(), TestReferenceDataHeight<2>());
3394         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
3395
3396         /* Clear framebuffer's content. */
3397         gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
3398         GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
3399
3400         gl.clear(GL_COLOR_BUFFER_BIT);
3401         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
3402
3403         return true;
3404 }
3405
3406 /** @brief Function prepares framebuffer with internal format color attachment.
3407  *         Viewport is set up. Content of the framebuffer is cleared.
3408  *
3409  *  @note The function may throw if unexpected error has occured.
3410  */
3411 template <>
3412 bool StorageMultisampleTest::PrepareFramebufferMultisample<3>(const glw::GLenum internal_format)
3413 {
3414         /* Shortcut for GL functionality. */
3415         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3416
3417         /* Prepare framebuffer. */
3418         gl.genFramebuffers(1, &m_fbo_ms);
3419         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
3420
3421         gl.genTextures(1, &m_to_ms);
3422         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
3423
3424         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
3425         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
3426
3427         gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, m_to_ms);
3428         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
3429
3430         gl.textureStorage3DMultisample(m_to_ms, 1, internal_format, TestReferenceDataWidth<3>(),
3431                                                                    TestReferenceDataHeight<3>(), TestReferenceDataDepth<3>(), false);
3432
3433         glw::GLenum error;
3434
3435         if (GL_NO_ERROR != (error = gl.getError()))
3436         {
3437                 CleanFramebuffers();
3438
3439                 m_context.getTestContext().getLog()
3440                         << tcu::TestLog::Message << "glTextureStorage3DMultisample unexpectedly generated error "
3441                         << glu::getErrorStr(error) << " during the test of internal format "
3442                         << glu::getTextureFormatStr(internal_format) << ". Test fails." << tcu::TestLog::EndMessage;
3443
3444                 return false;
3445         }
3446
3447         for (glw::GLuint i = 0; i < TestReferenceDataDepth<3>(); ++i)
3448         {
3449                 gl.framebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, m_to_ms, 0, i);
3450                 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
3451         }
3452
3453         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
3454         {
3455                 throw 0;
3456         }
3457
3458         gl.viewport(0, 0, TestReferenceDataWidth<3>(), TestReferenceDataHeight<3>());
3459         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
3460
3461         /* Clear framebuffer's content. */
3462         gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
3463         GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
3464
3465         gl.clear(GL_COLOR_BUFFER_BIT);
3466         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
3467
3468         return true;
3469 }
3470
3471 /** @brief Function prepares framebuffer with internal format color attachment.
3472  *         Viewport is set up. Content of the framebuffer is cleared.
3473  *
3474  *  @note The function may throw if unexpected error has occured.
3475  */
3476 template <>
3477 void StorageMultisampleTest::PrepareFramebufferAuxiliary<2>(const glw::GLenum internal_format)
3478 {
3479         /* Shortcut for GL functionality. */
3480         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3481
3482         /* Prepare framebuffer. */
3483         gl.genFramebuffers(1, &m_fbo_aux);
3484         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
3485
3486         gl.genTextures(1, &m_to_aux);
3487         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
3488
3489         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_aux);
3490         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
3491
3492         gl.bindTexture(GL_TEXTURE_2D, m_to_aux);
3493         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
3494
3495         gl.textureStorage2D(m_to_aux, 1, internal_format, TestReferenceDataWidth<2>(), TestReferenceDataHeight<2>());
3496         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2D call failed.");
3497
3498         /* Parameter setup. */
3499         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3500         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3501         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
3502
3503         gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_to_aux, 0);
3504         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
3505
3506         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
3507         {
3508                 throw 0;
3509         }
3510
3511         gl.viewport(0, 0, TestReferenceDataWidth<2>(), TestReferenceDataHeight<2>());
3512         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
3513
3514         /* Clear framebuffer's content. */
3515         gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
3516         GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
3517
3518         gl.clear(GL_COLOR_BUFFER_BIT);
3519         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
3520 }
3521
3522 /** @brief Function prepares framebuffer with internal format color attachment.
3523  *         Viewport is set up. Content of the framebuffer is cleared.
3524  *
3525  *  @note The function may throw if unexpected error has occured.
3526  */
3527 template <>
3528 void StorageMultisampleTest::PrepareFramebufferAuxiliary<3>(const glw::GLenum internal_format)
3529 {
3530         /* Shortcut for GL functionality. */
3531         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3532
3533         /* Prepare framebuffer. */
3534         gl.genFramebuffers(1, &m_fbo_aux);
3535         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
3536
3537         gl.genTextures(1, &m_to_aux);
3538         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
3539
3540         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_aux);
3541         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
3542
3543         gl.bindTexture(GL_TEXTURE_2D_ARRAY, m_to_aux);
3544         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
3545
3546         gl.textureStorage3D(m_to_aux, 1, internal_format, TestReferenceDataWidth<3>(), TestReferenceDataHeight<3>(),
3547                                                 TestReferenceDataDepth<3>());
3548         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage3D call failed.");
3549
3550         /* Parameter setup. */
3551         gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3552         gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3553         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
3554
3555         for (glw::GLuint i = 0; i < TestReferenceDataDepth<3>(); ++i)
3556         {
3557                 gl.framebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, m_to_aux, 0, i);
3558                 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
3559         }
3560
3561         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
3562         {
3563                 throw 0;
3564         }
3565
3566         gl.viewport(0, 0, TestReferenceDataWidth<3>(), TestReferenceDataHeight<3>());
3567         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
3568
3569         /* Clear framebuffer's content. */
3570         gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
3571         GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
3572
3573         gl.clear(GL_COLOR_BUFFER_BIT);
3574         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
3575 }
3576
3577 /** @brief Prepare program
3578  *
3579  *  @param [in] variable_declaration      Variables declaration part of fragment shader source code.
3580  *  @param [in] tail                      Tail part of fragment shader source code.
3581  */
3582 glw::GLuint StorageMultisampleTest::PrepareProgram(const glw::GLchar* variable_declaration, const glw::GLchar* tail)
3583 {
3584         /* Shortcut for GL functionality */
3585         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3586
3587         struct Shader
3588         {
3589                 glw::GLchar const* source[3];
3590                 glw::GLsizei const count;
3591                 glw::GLenum const  type;
3592                 glw::GLuint                id;
3593         } shader[] = { { { s_vertex_shader, NULL, NULL }, 1, GL_VERTEX_SHADER, 0 },
3594                                    { { s_fragment_shader_head, variable_declaration, tail }, 3, GL_FRAGMENT_SHADER, 0 } };
3595
3596         glw::GLuint const shader_count = sizeof(shader) / sizeof(shader[0]);
3597
3598         glw::GLuint po = 0;
3599
3600         try
3601         {
3602                 /* Create program. */
3603                 po = gl.createProgram();
3604                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateProgram call failed.");
3605
3606                 /* Shader compilation. */
3607
3608                 for (glw::GLuint i = 0; i < shader_count; ++i)
3609                 {
3610                         {
3611                                 shader[i].id = gl.createShader(shader[i].type);
3612
3613                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateShader call failed.");
3614
3615                                 gl.attachShader(po, shader[i].id);
3616
3617                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glAttachShader call failed.");
3618
3619                                 gl.shaderSource(shader[i].id, shader[i].count, shader[i].source, NULL);
3620
3621                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource call failed.");
3622
3623                                 gl.compileShader(shader[i].id);
3624
3625                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader call failed.");
3626
3627                                 glw::GLint status = GL_FALSE;
3628
3629                                 gl.getShaderiv(shader[i].id, GL_COMPILE_STATUS, &status);
3630                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
3631
3632                                 if (GL_FALSE == status)
3633                                 {
3634                                         glw::GLint log_size = 0;
3635                                         gl.getShaderiv(shader[i].id, GL_INFO_LOG_LENGTH, &log_size);
3636                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
3637
3638                                         glw::GLchar* log_text = new glw::GLchar[log_size];
3639
3640                                         gl.getShaderInfoLog(shader[i].id, log_size, NULL, &log_text[0]);
3641
3642                                         m_context.getTestContext().getLog()
3643                                                 << tcu::TestLog::Message << "Shader compilation has failed.\n"
3644                                                 << "Shader type: " << glu::getShaderTypeStr(shader[i].type) << "\n"
3645                                                 << "Shader compilation error log:\n"
3646                                                 << log_text << "\n"
3647                                                 << "Shader source code:\n"
3648                                                 << shader[i].source[0] << (shader[i].source[1] ? shader[i].source[1] : "")
3649                                                 << (shader[i].source[2] ? shader[i].source[2] : "") << "\n"
3650                                                 << tcu::TestLog::EndMessage;
3651
3652                                         delete[] log_text;
3653
3654                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog call failed.");
3655
3656                                         throw 0;
3657                                 }
3658                         }
3659                 }
3660
3661                 /* Link. */
3662                 gl.linkProgram(po);
3663
3664                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTransformFeedbackVaryings call failed.");
3665
3666                 glw::GLint status = GL_FALSE;
3667
3668                 gl.getProgramiv(po, GL_LINK_STATUS, &status);
3669
3670                 if (GL_TRUE == status)
3671                 {
3672                         for (glw::GLuint i = 0; i < shader_count; ++i)
3673                         {
3674                                 if (shader[i].id)
3675                                 {
3676                                         gl.detachShader(po, shader[i].id);
3677
3678                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glDetachShader call failed.");
3679                                 }
3680                         }
3681                 }
3682                 else
3683                 {
3684                         glw::GLint log_size = 0;
3685
3686                         gl.getProgramiv(po, GL_INFO_LOG_LENGTH, &log_size);
3687
3688                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv call failed.");
3689
3690                         glw::GLchar* log_text = new glw::GLchar[log_size];
3691
3692                         gl.getProgramInfoLog(po, log_size, NULL, &log_text[0]);
3693
3694                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "Program linkage has failed due to:\n"
3695                                                                                                 << log_text << "\n"
3696                                                                                                 << tcu::TestLog::EndMessage;
3697
3698                         delete[] log_text;
3699
3700                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramInfoLog call failed.");
3701
3702                         throw 0;
3703                 }
3704         }
3705         catch (...)
3706         {
3707                 if (po)
3708                 {
3709                         gl.deleteProgram(po);
3710
3711                         po = 0;
3712                 }
3713         }
3714
3715         for (glw::GLuint i = 0; i < shader_count; ++i)
3716         {
3717                 if (0 != shader[i].id)
3718                 {
3719                         gl.deleteShader(shader[i].id);
3720
3721                         shader[i].id = 0;
3722                 }
3723         }
3724
3725         if (0 == po)
3726         {
3727                 throw 0;
3728         }
3729
3730         return po;
3731 }
3732
3733 /** @brief Prepare VAO.
3734  */
3735 void StorageMultisampleTest::PrepareVertexArray()
3736 {
3737         /* Shortcut for GL functionality. */
3738         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3739
3740         gl.genVertexArrays(1, &m_vao);
3741         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays has failed");
3742
3743         gl.bindVertexArray(m_vao);
3744         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray has failed");
3745 }
3746
3747 /** @brief Draw call 2D.
3748  */
3749 template <>
3750 void StorageMultisampleTest::Draw<2>()
3751 {
3752         /* Shortcut for GL functionality. */
3753         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3754
3755         /* Prepare multisample texture using draw call. */
3756
3757         /* Prepare framebuffer with multisample texture. */
3758         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
3759         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer has failed");
3760
3761         /* Use first program program. */
3762         gl.useProgram(m_po_ms);
3763         GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed");
3764
3765         /* Prepare texture to be drawn with. */
3766         gl.activeTexture(GL_TEXTURE0);
3767         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
3768
3769         gl.bindTexture(GL_TEXTURE_2D, m_to);
3770         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
3771
3772         gl.uniform1i(gl.getUniformLocation(m_po_ms, "texture_input"), 0);
3773         GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed");
3774
3775         /* Select layer. */
3776         gl.drawBuffer(GL_COLOR_ATTACHMENT0);
3777         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawBuffer has failed");
3778
3779         /* Draw. */
3780         gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
3781         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed");
3782
3783         /* Copy multisample texture to auxiliary texture using draw call. */
3784
3785         /* Prepare framebuffer with auxiliary texture. */
3786         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_aux);
3787         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer has failed");
3788
3789         /* Use first program program. */
3790         gl.useProgram(m_po_aux);
3791         GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed");
3792
3793         /* Prepare texture to be drawn with. */
3794         gl.activeTexture(GL_TEXTURE0);
3795         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
3796
3797         gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_to_ms);
3798         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
3799
3800         gl.bindTextureUnit(0, m_to);
3801
3802         gl.uniform1i(gl.getUniformLocation(m_po_aux, "texture_input"), 0);
3803         GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed");
3804
3805         /* Select layer. */
3806         gl.drawBuffer(GL_COLOR_ATTACHMENT0);
3807         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawBuffer has failed");
3808
3809         /* Draw. */
3810         gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
3811         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed");
3812 }
3813
3814 /** @brief Draw call 3D.
3815  */
3816 template <>
3817 void StorageMultisampleTest::Draw<3>()
3818 {
3819         /* Shortcut for GL functionality. */
3820         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3821
3822         /* Prepare multisample texture using draw call. */
3823
3824         /* Prepare framebuffer with multisample texture. */
3825         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
3826         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer has failed");
3827
3828         /* Use first program program. */
3829         gl.useProgram(m_po_ms);
3830         GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed");
3831
3832         /* Prepare texture to be drawn with. */
3833         gl.activeTexture(GL_TEXTURE0);
3834         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
3835
3836         gl.bindTexture(GL_TEXTURE_2D_ARRAY, m_to);
3837         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
3838
3839         gl.uniform1i(gl.getUniformLocation(m_po_ms, "texture_input"), 0);
3840         GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed");
3841
3842         /* For each texture layer. */
3843         for (glw::GLuint i = 0; i < TestReferenceDataDepth<3>(); ++i)
3844         {
3845                 /* Select layer. */
3846                 gl.drawBuffer(GL_COLOR_ATTACHMENT0 + i);
3847                 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawBuffer has failed");
3848
3849                 gl.uniform1i(gl.getUniformLocation(m_po_aux, "texture_layer"), i);
3850                 GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed");
3851
3852                 /* Draw. */
3853                 gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
3854                 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed");
3855         }
3856
3857         /* Copy multisample texture to auxiliary texture using draw call. */
3858
3859         /* Prepare framebuffer with auxiliary texture. */
3860         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_aux);
3861         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer has failed");
3862
3863         /* Use first program program. */
3864         gl.useProgram(m_po_aux);
3865         GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed");
3866
3867         /* Prepare texture to be drawn with. */
3868         gl.activeTexture(GL_TEXTURE0);
3869         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
3870
3871         gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, m_to_ms);
3872         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
3873
3874         gl.bindTextureUnit(0, m_to);
3875
3876         gl.uniform1i(gl.getUniformLocation(m_po_aux, "texture_input"), 0);
3877         GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed");
3878
3879         /* For each texture layer. */
3880         for (glw::GLuint i = 0; i < TestReferenceDataDepth<3>(); ++i)
3881         {
3882                 /* Select layer. */
3883                 gl.drawBuffer(GL_COLOR_ATTACHMENT0 + i);
3884                 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawBuffer has failed");
3885
3886                 gl.uniform1i(gl.getUniformLocation(m_po_aux, "texture_layer"), i);
3887                 GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed");
3888
3889                 /* Draw. */
3890                 gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
3891                 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed");
3892         }
3893 }
3894
3895 /** @brief Clean GL objects, test variables and GL errors.
3896  */
3897 void StorageMultisampleTest::CleanInputTexture()
3898 {
3899         /* Shortcut for GL functionality. */
3900         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3901
3902         /* Texture. */
3903         if (m_to)
3904         {
3905                 gl.deleteTextures(1, &m_to);
3906
3907                 m_to = 0;
3908         }
3909 }
3910
3911 /** @brief Clean GL objects, test variables and GL errors.
3912  */
3913 void StorageMultisampleTest::CleanAuxiliaryTexture()
3914 {
3915         /* Shortcut for GL functionality. */
3916         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3917
3918         if (m_to_aux)
3919         {
3920                 gl.deleteTextures(1, &m_to_aux);
3921
3922                 m_to_aux = 0;
3923         }
3924 }
3925
3926 /** @brief Clean GL objects, test variables and GL errors.
3927  */
3928 void StorageMultisampleTest::CleanFramebuffers()
3929 {
3930         /* Shortcut for GL functionality. */
3931         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3932
3933         /* Mulitsample framebuffer. */
3934         if (m_fbo_ms)
3935         {
3936                 gl.deleteFramebuffers(1, &m_fbo_ms);
3937
3938                 m_fbo_ms = 0;
3939         }
3940
3941         /* Mulitsample texture. */
3942         if (m_to_ms)
3943         {
3944                 gl.deleteTextures(1, &m_to_ms);
3945
3946                 m_to_ms = 0;
3947         }
3948
3949         /* Auxiliary framebuffer. */
3950         if (m_fbo_aux)
3951         {
3952                 gl.deleteFramebuffers(1, &m_fbo_aux);
3953
3954                 m_fbo_aux = 0;
3955         }
3956
3957         /* Auxiliary texture. */
3958         if (m_to_aux)
3959         {
3960                 gl.deleteTextures(1, &m_to_aux);
3961
3962                 m_to_aux = 0;
3963         }
3964 }
3965
3966 /** @brief Clean GL objects, test variables and GL errors.
3967  */
3968 void StorageMultisampleTest::CleanPrograms()
3969 {
3970         /* Shortcut for GL functionality. */
3971         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3972
3973         /* Binding point. */
3974         gl.useProgram(0);
3975
3976         /* Multisample texture preparation program. */
3977         if (m_po_ms)
3978         {
3979                 gl.deleteProgram(m_po_ms);
3980
3981                 m_po_ms = 0;
3982         }
3983
3984         /* Auxiliary texture preparation program. */
3985         if (m_po_aux)
3986         {
3987                 gl.deleteProgram(m_po_aux);
3988
3989                 m_po_aux = 0;
3990         }
3991 }
3992
3993 /** @brief Clean GL objects, test variables and GL errors.
3994  */
3995 void StorageMultisampleTest::CleanErrors()
3996 {
3997         /* Shortcut for GL functionality. */
3998         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3999
4000         /* Query all errors until GL_NO_ERROR occure. */
4001         while (GL_NO_ERROR != gl.getError())
4002                 ;
4003 }
4004
4005 /** @brief Clean GL objects, test variables and GL errors.
4006  */
4007 void StorageMultisampleTest::CleanVertexArray()
4008 {
4009         /* Shortcut for GL functionality. */
4010         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4011
4012         if (m_vao)
4013         {
4014                 gl.bindVertexArray(0);
4015
4016                 gl.deleteVertexArrays(1, &m_vao);
4017
4018                 m_vao = 0;
4019         }
4020 }
4021
4022 /** @brief Iterate Storage Multisample Test cases.
4023  *
4024  *  @return Iteration result.
4025  */
4026 tcu::TestNode::IterateResult StorageMultisampleTest::iterate()
4027 {
4028         /* Shortcut for GL functionality. */
4029         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4030
4031         /* Get context setup. */
4032         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
4033         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
4034
4035         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
4036         {
4037                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
4038
4039                 return STOP;
4040         }
4041
4042         /* Running tests. */
4043         bool is_ok      = true;
4044         bool is_error = false;
4045
4046         try
4047         {
4048                 PrepareVertexArray();
4049
4050                 //  gl.enable(GL_MULTISAMPLE);
4051
4052                 is_ok &= LoopTestOverDOverS<glw::GLbyte, false>(true);
4053                 is_ok &= LoopTestOverDOverS<glw::GLubyte, false>(true);
4054                 is_ok &= LoopTestOverDOverS<glw::GLshort, false>(true);
4055                 is_ok &= LoopTestOverDOverS<glw::GLushort, false>(true);
4056                 is_ok &= LoopTestOverDOverS<glw::GLint, false>(false);
4057                 is_ok &= LoopTestOverDOverS<glw::GLuint, false>(false);
4058                 is_ok &= LoopTestOverDOverS<glw::GLubyte, true>(true);
4059                 is_ok &= LoopTestOverDOverS<glw::GLushort, true>(true);
4060                 is_ok &= LoopTestOverDOverS<glw::GLfloat, true>(false);
4061         }
4062         catch (...)
4063         {
4064                 is_ok   = false;
4065                 is_error = true;
4066         }
4067
4068         /* Cleanup. */
4069         CleanInputTexture();
4070         CleanAuxiliaryTexture();
4071         CleanFramebuffers();
4072         CleanPrograms();
4073         CleanErrors();
4074         CleanVertexArray();
4075         gl.disable(GL_MULTISAMPLE);
4076
4077         /* Errors clean up. */
4078         while (gl.getError())
4079                 ;
4080
4081         /* Result's setup. */
4082         if (is_ok)
4083         {
4084                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
4085         }
4086         else
4087         {
4088                 if (is_error)
4089                 {
4090                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
4091                 }
4092                 else
4093                 {
4094                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
4095                 }
4096         }
4097
4098         return STOP;
4099 }
4100
4101 /* Vertex shader source code. */
4102 const glw::GLchar* StorageMultisampleTest::s_vertex_shader = "#version 450\n"
4103                                                                                                                          "\n"
4104                                                                                                                          "void main()\n"
4105                                                                                                                          "{\n"
4106                                                                                                                          "    switch(gl_VertexID)\n"
4107                                                                                                                          "    {\n"
4108                                                                                                                          "        case 0:\n"
4109                                                                                                                          "            gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
4110                                                                                                                          "            break;\n"
4111                                                                                                                          "        case 1:\n"
4112                                                                                                                          "            gl_Position = vec4( 1.0, 1.0, 0.0, 1.0);\n"
4113                                                                                                                          "            break;\n"
4114                                                                                                                          "        case 2:\n"
4115                                                                                                                          "            gl_Position = vec4(-1.0,-1.0, 0.0, 1.0);\n"
4116                                                                                                                          "            break;\n"
4117                                                                                                                          "        case 3:\n"
4118                                                                                                                          "            gl_Position = vec4( 1.0,-1.0, 0.0, 1.0);\n"
4119                                                                                                                          "            break;\n"
4120                                                                                                                          "    }\n"
4121                                                                                                                          "}\n";
4122
4123 /* Fragment shader source program. */
4124 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_head =
4125         "#version 450\n"
4126         "\n"
4127         "layout(pixel_center_integer) in vec4 gl_FragCoord;\n"
4128         "\n";
4129
4130 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_fdecl_lowp =
4131         "uniform  sampler2D texture_input;\nout     vec4          texture_output;\n";
4132 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_idecl_lowp =
4133         "uniform isampler2D texture_input;\nout     ivec4         texture_output;\n";
4134 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_udecl_lowp =
4135         "uniform usampler2D texture_input;\nout     uvec4         texture_output;\n";
4136 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_fdecl_mediump =
4137         "uniform  sampler2D texture_input;\nout     vec4          texture_output;\n";
4138 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_idecl_mediump =
4139         "uniform isampler2D texture_input;\nout     ivec4         texture_output;\n";
4140 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_udecl_mediump =
4141         "uniform usampler2D texture_input;\nout     uvec4         texture_output;\n";
4142 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_fdecl_highp =
4143         "uniform  sampler2D texture_input;\nout     vec4          texture_output;\n";
4144 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_idecl_highp =
4145         "uniform isampler2D texture_input;\nout     ivec4         texture_output;\n";
4146 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_udecl_highp =
4147         "uniform usampler2D texture_input;\nout     uvec4         texture_output;\n";
4148
4149 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_fdecl_lowp =
4150         "uniform  sampler2DArray texture_input;\nout     vec4          texture_output;\n";
4151
4152 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_idecl_lowp =
4153         "uniform isampler2DArray texture_input;\nout     ivec4         texture_output;\n";
4154
4155 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_udecl_lowp =
4156         "uniform usampler2DArray texture_input;\nout     uvec4         texture_output;\n";
4157
4158 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_fdecl_mediump =
4159         "uniform  sampler2DArray texture_input;\nout     vec4          texture_output;\n";
4160
4161 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_idecl_mediump =
4162         "uniform isampler2DArray texture_input;\nout     ivec4         texture_output;\n";
4163
4164 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_udecl_mediump =
4165         "uniform usampler2DArray texture_input;\nout     uvec4         texture_output;\n";
4166
4167 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_fdecl_highp =
4168         "uniform  sampler2DArray texture_input;\nout     vec4          texture_output;\n";
4169
4170 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_idecl_highp =
4171         "uniform isampler2DArray texture_input;\nout     ivec4         texture_output;\n";
4172
4173 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_udecl_highp =
4174         "uniform usampler2DArray texture_input;\nout     uvec4         texture_output;\n";
4175
4176 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_fdecl_lowp =
4177         "uniform  sampler2DMS texture_input;\nout     vec4          texture_output;\n";
4178 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_idecl_lowp =
4179         "uniform isampler2DMS texture_input;\nout     ivec4         texture_output;\n";
4180 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_udecl_lowp =
4181         "uniform usampler2DMS texture_input;\nout     uvec4         texture_output;\n";
4182
4183 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_fdecl_mediump =
4184         "uniform  sampler2DMS texture_input;\nout     vec4          texture_output;\n";
4185
4186 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_idecl_mediump =
4187         "uniform isampler2DMS texture_input;\nout     ivec4         texture_output;\n";
4188
4189 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_udecl_mediump =
4190         "uniform usampler2DMS texture_input;\nout     uvec4         texture_output;\n";
4191
4192 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_fdecl_highp =
4193         "uniform  sampler2DMS texture_input;\nout     vec4          texture_output;\n";
4194 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_idecl_highp =
4195         "uniform isampler2DMS texture_input;\nout     ivec4         texture_output;\n";
4196 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_udecl_highp =
4197         "uniform usampler2DMS texture_input;\nout     uvec4         texture_output;\n";
4198
4199 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_fdecl_lowp =
4200         "uniform  sampler2DMSArray texture_input;\nout     vec4          texture_output;\n";
4201
4202 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_idecl_lowp =
4203         "uniform isampler2DMSArray texture_input;\nout     ivec4         texture_output;\n";
4204
4205 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_udecl_lowp =
4206         "uniform usampler2DMSArray texture_input;\nout     uvec4         texture_output;\n";
4207
4208 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_fdecl_mediump =
4209         "uniform  sampler2DMSArray texture_input;\nout     vec4          texture_output;\n";
4210
4211 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_idecl_mediump =
4212         "uniform isampler2DMSArray texture_input;\nout     ivec4         texture_output;\n";
4213
4214 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_udecl_mediump =
4215         "uniform usampler2DMSArray texture_input;\nout     uvec4         texture_output;\n";
4216
4217 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_fdecl_highp =
4218         "uniform  sampler2DMSArray texture_input;\nout     vec4          texture_output;\n";
4219
4220 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_idecl_highp =
4221         "uniform isampler2DMSArray texture_input;\nout     ivec4         texture_output;\n";
4222
4223 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_udecl_highp =
4224         "uniform usampler2DMSArray texture_input;\nout     uvec4         texture_output;\n";
4225
4226 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_tail_2D =
4227         "\n"
4228         "void main()\n"
4229         "{\n"
4230         "    texture_output = texelFetch(texture_input, ivec2(gl_FragCoord.xy), 0);\n"
4231         "}\n";
4232
4233 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_tail_3D =
4234         "\n"
4235         "uniform int texture_layer;\n"
4236         "\n"
4237         "void main()\n"
4238         "{\n"
4239         "    texture_output = texelFetch(texture_input, ivec3(gl_FragCoord.xy, texture_layer), 0);\n"
4240         "}\n";
4241
4242 /******************************** Compressed SubImage Test Implementation   ********************************/
4243
4244 /** @brief Compressed SubImage Test constructor.
4245  *
4246  *  @param [in] context     OpenGL context.
4247  */
4248 CompressedSubImageTest::CompressedSubImageTest(deqp::Context& context)
4249         : deqp::TestCase(context, "textures_compressed_subimage", "Texture Compressed SubImage Test")
4250         , m_to(0)
4251         , m_to_aux(0)
4252         , m_compressed_texture_data(DE_NULL)
4253         , m_reference(DE_NULL)
4254         , m_result(DE_NULL)
4255         , m_reference_size(0)
4256         , m_reference_internalformat(0)
4257 {
4258         /* Intentionally left blank. */
4259 }
4260
4261 /** @brief Create texture.
4262  *
4263  *  @param [in] target      Texture target.
4264  */
4265 void CompressedSubImageTest::CreateTextures(glw::GLenum target)
4266 {
4267         /* Shortcut for GL functionality. */
4268         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4269
4270         /* Auxiliary texture (for content creation). */
4271         gl.genTextures(1, &m_to_aux);
4272         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
4273
4274         gl.bindTexture(target, m_to_aux);
4275         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4276
4277         /* Test texture (for data upload). */
4278         gl.genTextures(1, &m_to);
4279         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
4280
4281         gl.bindTexture(target, m_to);
4282         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4283 }
4284
4285 /** @brief Texture target selector.
4286  *
4287  *  @tparam D      Texture dimenisons.
4288  *
4289  *  @return Texture target.
4290  */
4291 template <>
4292 glw::GLenum CompressedSubImageTest::TextureTarget<1>()
4293 {
4294         return GL_TEXTURE_1D;
4295 }
4296
4297 template <>
4298 glw::GLenum CompressedSubImageTest::TextureTarget<2>()
4299 {
4300         return GL_TEXTURE_2D;
4301 }
4302
4303 template <>
4304 glw::GLenum CompressedSubImageTest::TextureTarget<3>()
4305 {
4306         return GL_TEXTURE_2D_ARRAY;
4307 }
4308
4309 /** @brief Prepare texture data for the auxiliary texture.
4310  *
4311  *  @tparam D      Texture dimenisons.
4312  *
4313  *  @note parameters as passed to texImage*
4314  */
4315 template <>
4316 void CompressedSubImageTest::TextureImage<1>(glw::GLint internalformat)
4317 {
4318         /* Shortcut for GL functionality. */
4319         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4320
4321         gl.texImage1D(TextureTarget<1>(), 0, internalformat, s_texture_width, 0, GL_RGBA, GL_UNSIGNED_BYTE, s_texture_data);
4322         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
4323 }
4324
4325 /** @brief Prepare texture data for the auxiliary texture.
4326  *
4327  *  @tparam D      Texture dimenisons.
4328  *
4329  *  @note parameters as passed to texImage*
4330  */
4331 template <>
4332 void CompressedSubImageTest::TextureImage<2>(glw::GLint internalformat)
4333 {
4334         /* Shortcut for GL functionality. */
4335         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4336
4337         gl.texImage2D(TextureTarget<2>(), 0, internalformat, s_texture_width, s_texture_height, 0, GL_RGBA,
4338                                   GL_UNSIGNED_BYTE, s_texture_data);
4339         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
4340 }
4341
4342 /** @brief Prepare texture data for the auxiliary texture.
4343  *
4344  *  @tparam D      Texture dimenisons.
4345  *
4346  *  @note parameters as passed to texImage*
4347  */
4348 template <>
4349 void CompressedSubImageTest::TextureImage<3>(glw::GLint internalformat)
4350 {
4351         /* Shortcut for GL functionality. */
4352         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4353
4354         gl.texImage3D(TextureTarget<3>(), 0, internalformat, s_texture_width, s_texture_height, s_texture_depth, 0, GL_RGBA,
4355                                   GL_UNSIGNED_BYTE, s_texture_data);
4356         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage3D has failed");
4357 }
4358
4359 /** @brief Prepare texture data for the auxiliary texture.
4360  *
4361  *  @tparam D      Texture dimensions.
4362  *
4363  *  @note parameters as passed to compressedTexImage*
4364  */
4365 template <>
4366 void CompressedSubImageTest::CompressedTexImage<1>(glw::GLint internalformat)
4367 {
4368         /* Shortcut for GL functionality. */
4369         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4370
4371         gl.compressedTexImage1D(TextureTarget<1>(), 0, internalformat, s_texture_width, 0, m_reference_size,
4372                                                         m_compressed_texture_data);
4373         GLU_EXPECT_NO_ERROR(gl.getError(), "glCompressedTexImage1D has failed");
4374 }
4375
4376 /** @brief Prepare texture data for the auxiliary texture.
4377  *
4378  *  @tparam D      Texture dimensions.
4379  *
4380  *  @note parameters as passed to compressedTexImage*
4381  */
4382 template <>
4383 void CompressedSubImageTest::CompressedTexImage<2>(glw::GLint internalformat)
4384 {
4385         /* Shortcut for GL functionality. */
4386         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4387
4388         gl.compressedTexImage2D(TextureTarget<2>(), 0, internalformat, s_texture_width, s_texture_height, 0,
4389                                                         m_reference_size, m_compressed_texture_data);
4390         GLU_EXPECT_NO_ERROR(gl.getError(), "glCompressedTexImage2D has failed");
4391 }
4392
4393 /** @brief Prepare texture data for the auxiliary texture.
4394  *
4395  *  @tparam D      Texture dimensions.
4396  *
4397  *  @note parameters as passed to compressedTexImage*
4398  */
4399 template <>
4400 void CompressedSubImageTest::CompressedTexImage<3>(glw::GLint internalformat)
4401 {
4402         /* Shortcut for GL functionality. */
4403         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4404
4405         gl.compressedTexImage3D(TextureTarget<3>(), 0, internalformat, s_texture_width, s_texture_height, s_texture_depth,
4406                                                         0, m_reference_size, m_compressed_texture_data);
4407         GLU_EXPECT_NO_ERROR(gl.getError(), "glCompressedTexImage3D has failed");
4408 }
4409
4410 /** @brief Prepare texture data for the compressed texture.
4411  *
4412  *  @tparam D      Texture dimenisons.
4413  *
4414  *  @param [in] internalformat      Texture internal format.
4415  *
4416  *  @return True if tested function succeeded, false otherwise.
4417  */
4418 template <>
4419 bool CompressedSubImageTest::CompressedTextureSubImage<1>(glw::GLint internalformat)
4420 {
4421         /* Shortcut for GL functionality. */
4422         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4423
4424         /* Load texture image with tested function. */
4425         if (m_reference_size)
4426         {
4427                 for (glw::GLuint block = 0; block < s_block_count; ++block)
4428                 {
4429                         gl.compressedTextureSubImage1D(m_to, 0, s_texture_width * block, s_texture_width, internalformat,
4430                                                                                    m_reference_size, m_compressed_texture_data);
4431                 }
4432         }
4433         else
4434         {
4435                 /* For 1D version there is no specific compressed texture internal format spcified in OpenGL 4.5 core profile documentation.
4436                  Only implementation depended specific internalformats may provide this functionality. As a result there may be no reference data to be substituted.
4437                  Due to this reason there is no use of CompressedTextureSubImage1D and particulary it cannot be tested. */
4438                 return true;
4439         }
4440
4441         /* Check errors. */
4442         glw::GLenum error;
4443
4444         if (GL_NO_ERROR != (error = gl.getError()))
4445         {
4446                 m_context.getTestContext().getLog()
4447                         << tcu::TestLog::Message << "glCompressedTextureSubImage1D unexpectedly generated error "
4448                         << glu::getErrorStr(error) << " during the test with internal format "
4449                         << glu::getTextureFormatStr(internalformat) << ". Test fails." << tcu::TestLog::EndMessage;
4450
4451                 return false;
4452         }
4453
4454         return true;
4455 }
4456
4457 /** @brief Prepare texture data for the compressed texture.
4458  *
4459  *  @tparam D      Texture dimenisons.
4460  *
4461  *  @param [in] internalformat      Texture internal format.
4462  *
4463  *  @return True if tested function succeeded, false otherwise.
4464  */
4465 template <>
4466 bool CompressedSubImageTest::CompressedTextureSubImage<2>(glw::GLint internalformat)
4467 {
4468         /* Shortcut for GL functionality. */
4469         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4470
4471         for (glw::GLuint y = 0; y < s_block_2d_size_y; ++y)
4472         {
4473                 for (glw::GLuint x = 0; x < s_block_2d_size_x; ++x)
4474                 {
4475                         /* Load texture image with tested function. */
4476                         gl.compressedTextureSubImage2D(m_to, 0, s_texture_width * x, s_texture_height * y, s_texture_width,
4477                                                                                    s_texture_height, internalformat, m_reference_size,
4478                                                                                    m_compressed_texture_data);
4479                 }
4480         }
4481         /* Check errors. */
4482         glw::GLenum error;
4483
4484         if (GL_NO_ERROR != (error = gl.getError()))
4485         {
4486                 m_context.getTestContext().getLog()
4487                         << tcu::TestLog::Message << "glCompressedTextureSubImage2D unexpectedly generated error "
4488                         << glu::getErrorStr(error) << " during the test with internal format "
4489                         << glu::getTextureFormatStr(internalformat) << ". Test fails." << tcu::TestLog::EndMessage;
4490
4491                 return false;
4492         }
4493
4494         return true;
4495 }
4496
4497 /** @brief Prepare texture data for the compressed texture.
4498  *
4499  *  @tparam D      Texture dimenisons.
4500  *
4501  *  @param [in] internalformat      Texture internal format.
4502  *
4503  *  @return True if tested function succeeded, false otherwise.
4504  */
4505 template <>
4506 bool CompressedSubImageTest::CompressedTextureSubImage<3>(glw::GLint internalformat)
4507 {
4508         /* Shortcut for GL functionality. */
4509         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4510
4511         for (glw::GLuint z = 0; z < s_block_3d_size; ++z)
4512         {
4513                 for (glw::GLuint y = 0; y < s_block_3d_size; ++y)
4514                 {
4515                         for (glw::GLuint x = 0; x < s_block_3d_size; ++x)
4516                         {
4517                                 /* Load texture image with tested function. */
4518                                 gl.compressedTextureSubImage3D(m_to, 0, s_texture_width * x, s_texture_height * y, s_texture_depth * z,
4519                                                                                            s_texture_width, s_texture_height, s_texture_depth, internalformat,
4520                                                                                            m_reference_size, m_compressed_texture_data);
4521                         }
4522                 }
4523         }
4524
4525         /* Check errors. */
4526         glw::GLenum error;
4527
4528         if (GL_NO_ERROR != (error = gl.getError()))
4529         {
4530                 m_context.getTestContext().getLog()
4531                         << tcu::TestLog::Message << "glCompressedTextureSubImage2D unexpectedly generated error "
4532                         << glu::getErrorStr(error) << " during the test with internal format "
4533                         << glu::getTextureFormatStr(internalformat) << ". Test fails." << tcu::TestLog::EndMessage;
4534
4535                 return false;
4536         }
4537         return true;
4538 }
4539
4540 /** @brief Prepare the reference data.
4541  *
4542  *  @tparam D      Texture dimenisons.
4543  */
4544 template <glw::GLuint D>
4545 void CompressedSubImageTest::PrepareReferenceData(glw::GLenum internalformat)
4546 {
4547         /* Shortcut for GL functionality. */
4548         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4549
4550         /* Using OpenGL to compress raw data. */
4551         gl.bindTexture(TextureTarget<D>(), m_to_aux);
4552         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4553
4554         TextureImage<D>(internalformat);
4555
4556         /* Sanity checks. */
4557         if ((DE_NULL != m_reference) || (DE_NULL != m_compressed_texture_data))
4558         {
4559                 throw 0;
4560         }
4561
4562         /* Check that really compressed texture. */
4563         glw::GLint is_compressed_texture = 0;
4564         gl.getTexLevelParameteriv(TextureTarget<D>(), 0, GL_TEXTURE_COMPRESSED, &is_compressed_texture);
4565
4566         if (is_compressed_texture)
4567         {
4568                 /* Query texture size. */
4569                 glw::GLint compressed_texture_size = 0;
4570                 gl.getTexLevelParameteriv(TextureTarget<D>(), 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compressed_texture_size);
4571
4572                 /* If compressed then download. */
4573                 if (compressed_texture_size)
4574                 {
4575                         /* Prepare storage. */
4576                         m_compressed_texture_data = new glw::GLubyte[compressed_texture_size];
4577
4578                         if (DE_NULL != m_compressed_texture_data)
4579                         {
4580                                 m_reference_size = compressed_texture_size;
4581                         }
4582                         else
4583                         {
4584                                 throw 0;
4585                         }
4586
4587                         /* Download the source compressed texture image. */
4588                         gl.getCompressedTexImage(TextureTarget<D>(), 0, m_compressed_texture_data);
4589                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
4590
4591                         // Upload the source compressed texture image to the texture object.
4592                         // Some compressed texture format can be emulated by the driver (like the ETC2/EAC formats)
4593                         // The compressed data sent by CompressedTexImage will be stored uncompressed by the driver
4594                         // and will be re-compressed if the application call glGetCompressedTexImage.
4595                         // The compression/decompression is not lossless, so when this happen it's possible for the source
4596                         // and destination (from glGetCompressedTexImage) compressed data to be different.
4597                         // To avoid that we will store both the source (in m_compressed_texture_data) and the destination
4598                         // (in m_reference). The destination will be used later to make sure getCompressedTextureSubImage
4599                         // return the expected value
4600                         CompressedTexImage<D>(internalformat);
4601
4602                         m_reference = new glw::GLubyte[m_reference_size];
4603
4604                         if (DE_NULL == m_reference)
4605                         {
4606                                 throw 0;
4607                         }
4608
4609                         /* Download compressed texture image. */
4610                         gl.getCompressedTexImage(TextureTarget<D>(), 0, m_reference);
4611                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
4612                 }
4613         }
4614 }
4615
4616 /** @brief Prepare texture storage.
4617  *
4618  *  @tparam D      Texture dimenisons.
4619  *
4620  *  @param [in] internalformat      Texture internal format.
4621  */
4622 template <>
4623 void CompressedSubImageTest::PrepareStorage<1>(glw::GLenum internalformat)
4624 {
4625         /* Shortcut for GL functionality. */
4626         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4627
4628         gl.bindTexture(TextureTarget<1>(), m_to);
4629         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4630
4631         gl.texImage1D(TextureTarget<1>(), 0, internalformat, s_texture_width * s_block_count, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4632                                   NULL);
4633         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
4634 }
4635
4636 /** @brief Prepare texture storage.
4637  *
4638  *  @tparam D      Texture dimenisons.
4639  *
4640  *  @param [in] internalformat      Texture internal format.
4641  */
4642 template <>
4643 void CompressedSubImageTest::PrepareStorage<2>(glw::GLenum internalformat)
4644 {
4645         /* Shortcut for GL functionality. */
4646         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4647
4648         gl.bindTexture(TextureTarget<2>(), m_to);
4649         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4650
4651         gl.texImage2D(TextureTarget<2>(), 0, internalformat, s_texture_width * s_block_2d_size_x,
4652                                   s_texture_height * s_block_2d_size_y, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
4653         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
4654 }
4655
4656 /** @brief Prepare texture storage.
4657  *
4658  *  @tparam D      Texture dimenisons.
4659  *
4660  *  @param [in] internalformat      Texture internal format.
4661  */
4662 template <>
4663 void CompressedSubImageTest::PrepareStorage<3>(glw::GLenum internalformat)
4664 {
4665         /* Shortcut for GL functionality. */
4666         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4667
4668         gl.bindTexture(TextureTarget<3>(), m_to);
4669         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4670
4671         gl.texImage3D(TextureTarget<3>(), 0, internalformat, s_texture_width * s_block_3d_size,
4672                                   s_texture_height * s_block_3d_size, s_texture_depth * s_block_3d_size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4673                                   NULL);
4674         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
4675 }
4676
4677 /** @brief Compare results with the reference.
4678  *
4679  *  @tparam T      Type.
4680  *  @tparam S      Size (# of components).
4681  *  @tparam N      Is normalized.
4682  *
4683  *  @param [in] internalformat      Texture internal format.
4684  *
4685  *  @return True if equal, false otherwise.
4686  */
4687 template <glw::GLuint D>
4688 bool CompressedSubImageTest::CheckData(glw::GLenum internalformat)
4689 {
4690         /* Shortcut for GL functionality. */
4691         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4692
4693         /* Check texture content with reference. */
4694         m_result = new glw::GLubyte[m_reference_size * s_block_count];
4695
4696         if (DE_NULL == m_result)
4697         {
4698                 throw 0;
4699         }
4700
4701         gl.getCompressedTexImage(TextureTarget<D>(), 0, m_result);
4702         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
4703         for (glw::GLuint block = 0; block < s_block_count; ++block)
4704         {
4705                 for (glw::GLuint i = 0; i < m_reference_size; ++i)
4706                 {
4707                         if (m_reference[i] != m_result[block * m_reference_size + i])
4708                         {
4709                                 m_context.getTestContext().getLog()
4710                                         << tcu::TestLog::Message << "glCompressedTextureSubImage*D created texture with data "
4711                                         << DataToString(m_reference_size, m_reference) << " however texture contains data "
4712                                         << DataToString(m_reference_size, &(m_result[block * m_reference_size])) << ". Texture target was "
4713                                         << glu::getTextureTargetStr(TextureTarget<D>()) << " and internal format was "
4714                                         << glu::getTextureFormatStr(internalformat) << ". Test fails." << tcu::TestLog::EndMessage;
4715
4716                                 return false;
4717                         }
4718                 }
4719         }
4720
4721         return true;
4722 }
4723
4724 /** @brief Compare results with the reference.
4725  *
4726  *  @tparam T      Type.
4727  *  @tparam S      Size (# of components).
4728  *  @tparam N      Is normalized.
4729  *
4730  *  @param [in] internalformat      Texture internal format.
4731  *
4732  *  @return True if equal, false otherwise.
4733  */
4734 template <>
4735 bool CompressedSubImageTest::CheckData<3>(glw::GLenum internalformat)
4736 {
4737         /* Shortcut for GL functionality. */
4738         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4739
4740         /* Check texture content with reference. */
4741         m_result = new glw::GLubyte[m_reference_size * s_block_count];
4742
4743         if (DE_NULL == m_result)
4744         {
4745                 throw 0;
4746         }
4747
4748         gl.getCompressedTexImage(TextureTarget<3>(), 0, m_result);
4749         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
4750
4751         glw::GLuint reference_layer_size = m_reference_size / s_texture_depth;
4752
4753         for (glw::GLuint i = 0; i < m_reference_size * s_block_count; ++i)
4754         {
4755                 // we will read the result one bytes at the time and compare with the reference
4756                 // for each bytes of the result image we need to figure out which byte in the reference image it corresponds to
4757                 glw::GLuint refIdx              = i % reference_layer_size;
4758                 glw::GLuint refLayerIdx = (i / (reference_layer_size * s_block_3d_size * s_block_3d_size)) % s_texture_depth;
4759                 if (m_reference[refLayerIdx * reference_layer_size + refIdx] != m_result[i])
4760                 {
4761                         m_context.getTestContext().getLog()
4762                                 << tcu::TestLog::Message << "glCompressedTextureSubImage3D created texture with data "
4763                                 << DataToString(reference_layer_size, &(m_reference[refLayerIdx * reference_layer_size]))
4764                                 << " however texture contains data "
4765                                 << DataToString(reference_layer_size, &(m_result[i % reference_layer_size])) << ". Texture target was "
4766                                 << glu::getTextureTargetStr(TextureTarget<3>()) << " and internal format was "
4767                                 << glu::getTextureFormatStr(internalformat) << ". Test fails." << tcu::TestLog::EndMessage;
4768
4769                         return false;
4770                 }
4771         }
4772
4773         return true;
4774 }
4775 /** @brief Test case function.
4776  *
4777  *  @tparam D       Number of texture dimensions.
4778  *
4779  *  @param [in] internal format     Texture internal format.
4780  *
4781  *  @return True if test succeeded, false otherwise.
4782  */
4783 template <glw::GLuint D>
4784 bool CompressedSubImageTest::Test(glw::GLenum internalformat)
4785 {
4786         /* Create texture image. */
4787         CreateTextures(TextureTarget<D>());
4788         PrepareReferenceData<D>(internalformat);
4789         PrepareStorage<D>(internalformat);
4790
4791         /* Setup data with CompressedTextureSubImage<D>D function and check for errors. */
4792         if (!CompressedTextureSubImage<D>(internalformat))
4793         {
4794                 CleanAll();
4795
4796                 return false;
4797         }
4798
4799         /* If compressed reference data was generated than compare values. */
4800         if (m_reference)
4801         {
4802                 if (!CheckData<D>(internalformat))
4803                 {
4804                         CleanAll();
4805
4806                         return false;
4807                 }
4808         }
4809
4810         CleanAll();
4811
4812         return true;
4813 }
4814
4815 /** @brief Clean GL objects, test variables and GL errors.
4816  */
4817 void CompressedSubImageTest::CleanAll()
4818 {
4819         /* Shortcut for GL functionality. */
4820         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4821
4822         /* Textures. */
4823         if (m_to)
4824         {
4825                 gl.deleteTextures(1, &m_to);
4826
4827                 m_to = 0;
4828         }
4829
4830         if (m_to_aux)
4831         {
4832                 gl.deleteTextures(1, &m_to_aux);
4833
4834                 m_to_aux = 0;
4835         }
4836
4837         /* Reference data storage. */
4838         if (DE_NULL != m_reference)
4839         {
4840                 delete[] m_reference;
4841
4842                 m_reference = DE_NULL;
4843         }
4844
4845         if (DE_NULL != m_compressed_texture_data)
4846         {
4847                 delete[] m_compressed_texture_data;
4848
4849                 m_compressed_texture_data = DE_NULL;
4850         }
4851
4852         if (DE_NULL != m_result)
4853         {
4854                 delete[] m_result;
4855
4856                 m_result = DE_NULL;
4857         }
4858
4859         m_reference_size = 0;
4860
4861         /* Errors. */
4862         while (GL_NO_ERROR != gl.getError())
4863                 ;
4864 }
4865
4866 /** @brief Convert raw data into string for logging purposes.
4867  *
4868  *  @param [in] count      Count of the data.
4869  *  @param [in] data       Raw data.
4870  *
4871  *  @return String representation of data.
4872  */
4873 std::string CompressedSubImageTest::DataToString(glw::GLuint count, const glw::GLubyte data[])
4874 {
4875         std::string data_str = "[";
4876
4877         for (glw::GLuint i = 0; i < count; ++i)
4878         {
4879                 std::stringstream int_sstream;
4880
4881                 int_sstream << unsigned(data[i]);
4882
4883                 data_str.append(int_sstream.str());
4884
4885                 if (i + 1 < count)
4886                 {
4887                         data_str.append(", ");
4888                 }
4889                 else
4890                 {
4891                         data_str.append("]");
4892                 }
4893         }
4894
4895         return data_str;
4896 }
4897
4898 /** @brief Iterate Compressed SubImage Test cases.
4899  *
4900  *  @return Iteration result.
4901  */
4902 tcu::TestNode::IterateResult CompressedSubImageTest::iterate()
4903 {
4904         /* Shortcut for GL functionality. */
4905         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4906
4907         /* Get context setup. */
4908         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
4909         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
4910
4911         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
4912         {
4913                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
4914
4915                 return STOP;
4916         }
4917
4918         /* Running tests. */
4919         bool is_ok      = true;
4920         bool is_error = false;
4921
4922         try
4923         {
4924                 is_ok &= Test<1>(GL_COMPRESSED_RGB);
4925
4926                 is_ok &= Test<2>(GL_COMPRESSED_RED_RGTC1);
4927                 is_ok &= Test<2>(GL_COMPRESSED_SIGNED_RED_RGTC1);
4928                 is_ok &= Test<2>(GL_COMPRESSED_RG_RGTC2);
4929                 is_ok &= Test<2>(GL_COMPRESSED_SIGNED_RG_RGTC2);
4930                 is_ok &= Test<2>(GL_COMPRESSED_RGBA_BPTC_UNORM);
4931                 is_ok &= Test<2>(GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM);
4932                 is_ok &= Test<2>(GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT);
4933                 is_ok &= Test<2>(GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT);
4934                 is_ok &= Test<2>(GL_COMPRESSED_RGB8_ETC2);
4935                 is_ok &= Test<2>(GL_COMPRESSED_SRGB8_ETC2);
4936                 is_ok &= Test<2>(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2);
4937                 is_ok &= Test<2>(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2);
4938                 is_ok &= Test<2>(GL_COMPRESSED_RGBA8_ETC2_EAC);
4939                 is_ok &= Test<2>(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC);
4940                 is_ok &= Test<2>(GL_COMPRESSED_R11_EAC);
4941                 is_ok &= Test<2>(GL_COMPRESSED_SIGNED_R11_EAC);
4942                 is_ok &= Test<2>(GL_COMPRESSED_RG11_EAC);
4943                 is_ok &= Test<2>(GL_COMPRESSED_SIGNED_RG11_EAC);
4944
4945                 is_ok &= Test<3>(GL_COMPRESSED_RED_RGTC1);
4946                 is_ok &= Test<3>(GL_COMPRESSED_SIGNED_RED_RGTC1);
4947                 is_ok &= Test<3>(GL_COMPRESSED_RG_RGTC2);
4948                 is_ok &= Test<3>(GL_COMPRESSED_SIGNED_RG_RGTC2);
4949                 is_ok &= Test<3>(GL_COMPRESSED_RGBA_BPTC_UNORM);
4950                 is_ok &= Test<3>(GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM);
4951                 is_ok &= Test<3>(GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT);
4952                 is_ok &= Test<3>(GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT);
4953                 is_ok &= Test<3>(GL_COMPRESSED_RGB8_ETC2);
4954                 is_ok &= Test<3>(GL_COMPRESSED_SRGB8_ETC2);
4955                 is_ok &= Test<3>(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2);
4956                 is_ok &= Test<3>(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2);
4957                 is_ok &= Test<3>(GL_COMPRESSED_RGBA8_ETC2_EAC);
4958                 is_ok &= Test<3>(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC);
4959                 is_ok &= Test<3>(GL_COMPRESSED_R11_EAC);
4960                 is_ok &= Test<3>(GL_COMPRESSED_SIGNED_R11_EAC);
4961                 is_ok &= Test<3>(GL_COMPRESSED_RG11_EAC);
4962                 is_ok &= Test<3>(GL_COMPRESSED_SIGNED_RG11_EAC);
4963         }
4964         catch (...)
4965         {
4966                 is_ok   = false;
4967                 is_error = true;
4968         }
4969
4970         /* Cleanup. */
4971         CleanAll();
4972
4973         /* Errors clean up. */
4974         while (gl.getError())
4975                 ;
4976
4977         /* Result's setup. */
4978         if (is_ok)
4979         {
4980                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
4981         }
4982         else
4983         {
4984                 if (is_error)
4985                 {
4986                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
4987                 }
4988                 else
4989                 {
4990                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
4991                 }
4992         }
4993
4994         return STOP;
4995 }
4996
4997 /** Reference data. */
4998 const glw::GLubyte CompressedSubImageTest::s_texture_data[] = {
4999         0x00, 0x00, 0x00, 0xFF, 0x7f, 0x7f, 0x7f, 0x00, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0x00,
5000         0x88, 0x00, 0x15, 0xFF, 0xed, 0x1c, 0x24, 0x00, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x00, 0x00,
5001         0xc8, 0xbf, 0xe7, 0xFF, 0x70, 0x92, 0xbe, 0x00, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0x00,
5002         0xa3, 0x49, 0xa4, 0xFF, 0x3f, 0x48, 0xcc, 0x00, 0x00, 0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0x00,
5003
5004         0xa3, 0x49, 0xa4, 0xFF, 0xc8, 0xbf, 0xe7, 0x00, 0x88, 0x00, 0x15, 0xff, 0x00, 0x00, 0x00, 0x00,
5005         0x3f, 0x48, 0xcc, 0xFF, 0x70, 0x92, 0xbe, 0x00, 0xed, 0x1c, 0x24, 0xff, 0x7f, 0x7f, 0x7f, 0x00,
5006         0x00, 0xa2, 0xe8, 0xFF, 0x99, 0xd9, 0xea, 0x00, 0xff, 0x7f, 0x27, 0xff, 0xc3, 0xc3, 0xc3, 0x00,
5007         0x22, 0xb1, 0x4c, 0xFF, 0xb5, 0xe6, 0x1d, 0x00, 0xff, 0xf2, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00,
5008
5009         0x22, 0xb1, 0x4c, 0xFF, 0x00, 0xa2, 0xe8, 0x00, 0x3f, 0x48, 0xcc, 0xff, 0xa3, 0x49, 0xa4, 0x00,
5010         0xb5, 0xe6, 0x1d, 0xFF, 0x99, 0xd9, 0xea, 0x00, 0x70, 0x92, 0xbe, 0xff, 0xc8, 0xbf, 0xe7, 0x00,
5011         0xff, 0xf2, 0x00, 0xFF, 0xff, 0x7f, 0x27, 0x00, 0xed, 0x1c, 0x24, 0xff, 0x88, 0x00, 0x15, 0x00,
5012         0xff, 0xff, 0xff, 0xFF, 0xc3, 0xc3, 0xc3, 0x00, 0x7f, 0x7f, 0x7f, 0xff, 0x00, 0x00, 0x00, 0x00,
5013
5014         0xff, 0xff, 0xff, 0xFF, 0xff, 0xf2, 0x00, 0x00, 0xb5, 0xe6, 0x1d, 0xff, 0x22, 0xb1, 0x4c, 0x00,
5015         0xc3, 0xc3, 0xc3, 0xFF, 0xff, 0x7f, 0x27, 0x00, 0x99, 0xd9, 0xea, 0xff, 0x00, 0xa2, 0xe8, 0x00,
5016         0x7f, 0x7f, 0x7f, 0xFF, 0xed, 0x1c, 0x24, 0x00, 0x70, 0x92, 0xbe, 0xff, 0x3f, 0x48, 0xcc, 0x00,
5017         0x00, 0x00, 0x00, 0xFF, 0x88, 0x00, 0x15, 0x00, 0xc8, 0xbf, 0xe7, 0xff, 0xa3, 0x49, 0xa4, 0x00
5018 };
5019
5020 /** Reference data parameters. */
5021 const glw::GLuint CompressedSubImageTest::s_texture_width   = 4;
5022 const glw::GLuint CompressedSubImageTest::s_texture_height  = 4;
5023 const glw::GLuint CompressedSubImageTest::s_texture_depth   = 4;
5024 const glw::GLuint CompressedSubImageTest::s_block_count         = 8;
5025 const glw::GLuint CompressedSubImageTest::s_block_2d_size_x = 4;
5026 const glw::GLuint CompressedSubImageTest::s_block_2d_size_y = 2;
5027 const glw::GLuint CompressedSubImageTest::s_block_3d_size   = 2;
5028
5029 /******************************** Copy SubImage Test Implementation   ********************************/
5030
5031 /** @brief Compressed SubImage Test constructor.
5032  *
5033  *  @param [in] context     OpenGL context.
5034  */
5035 CopyTest::CopyTest(deqp::Context& context)
5036         : deqp::TestCase(context, "textures_copy", "Texture Copy Test")
5037         , m_fbo(0)
5038         , m_to_src(0)
5039         , m_to_dst(0)
5040         , m_result(DE_NULL)
5041 {
5042         /* Intentionally left blank. */
5043 }
5044
5045 /** @brief Texture target selector.
5046  *
5047  *  @tparam D      Texture dimenisons.
5048  *
5049  *  @return Texture target.
5050  */
5051 template <>
5052 glw::GLenum CopyTest::TextureTarget<1>()
5053 {
5054         return GL_TEXTURE_1D;
5055 }
5056 template <>
5057 glw::GLenum CopyTest::TextureTarget<2>()
5058 {
5059         return GL_TEXTURE_2D;
5060 }
5061 template <>
5062 glw::GLenum CopyTest::TextureTarget<3>()
5063 {
5064         return GL_TEXTURE_3D;
5065 }
5066
5067 /** @brief Copy texture, check errors and log.
5068  *
5069  *  @note Parameters as passed to CopyTextureSubImage*D
5070  *
5071  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
5072  */
5073 bool CopyTest::CopyTextureSubImage1DAndCheckErrors(glw::GLuint texture, glw::GLint level, glw::GLint xoffset,
5074                                                                                                    glw::GLint x, glw::GLint y, glw::GLsizei width)
5075 {
5076         /* Shortcut for GL functionality. */
5077         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5078
5079         gl.readBuffer(GL_COLOR_ATTACHMENT0);
5080         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
5081
5082         gl.copyTextureSubImage1D(texture, level, xoffset, x, y, width);
5083
5084         /* Check errors. */
5085         glw::GLenum error;
5086
5087         if (GL_NO_ERROR != (error = gl.getError()))
5088         {
5089                 m_context.getTestContext().getLog() << tcu::TestLog::Message
5090                                                                                         << "glCopyTextureSubImage1D unexpectedly generated error "
5091                                                                                         << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
5092
5093                 return false;
5094         }
5095
5096         return true;
5097 }
5098
5099 /** @brief Copy texture, check errors and log.
5100  *
5101  *  @note Parameters as passed to CopyTextureSubImage*D
5102  *
5103  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
5104  */
5105 bool CopyTest::CopyTextureSubImage2DAndCheckErrors(glw::GLuint texture, glw::GLint level, glw::GLint xoffset,
5106                                                                                                    glw::GLint yoffset, glw::GLint x, glw::GLint y, glw::GLsizei width,
5107                                                                                                    glw::GLsizei height)
5108 {
5109         /* Shortcut for GL functionality. */
5110         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5111
5112         gl.readBuffer(GL_COLOR_ATTACHMENT0);
5113         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
5114
5115         gl.copyTextureSubImage2D(texture, level, xoffset, yoffset, x, y, width, height);
5116
5117         /* Check errors. */
5118         glw::GLenum error;
5119
5120         if (GL_NO_ERROR != (error = gl.getError()))
5121         {
5122                 m_context.getTestContext().getLog() << tcu::TestLog::Message
5123                                                                                         << "glCopyTextureSubImage2D unexpectedly generated error "
5124                                                                                         << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
5125
5126                 return false;
5127         }
5128
5129         return true;
5130 }
5131
5132 /** @brief Copy texture, check errors and log.
5133  *
5134  *  @note Parameters as passed to CopyTextureSubImage*D
5135  *
5136  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
5137  */
5138 bool CopyTest::CopyTextureSubImage3DAndCheckErrors(glw::GLuint texture, glw::GLint level, glw::GLint xoffset,
5139                                                                                                    glw::GLint yoffset, glw::GLint zoffset, glw::GLint x, glw::GLint y,
5140                                                                                                    glw::GLsizei width, glw::GLsizei height)
5141 {
5142         /* Shortcut for GL functionality. */
5143         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5144
5145         gl.readBuffer(GL_COLOR_ATTACHMENT0 + zoffset);
5146         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
5147
5148         gl.copyTextureSubImage3D(texture, level, xoffset, yoffset, zoffset, x, y, width, height);
5149
5150         /* Check errors. */
5151         glw::GLenum error;
5152
5153         if (GL_NO_ERROR != (error = gl.getError()))
5154         {
5155                 m_context.getTestContext().getLog() << tcu::TestLog::Message
5156                                                                                         << "glCopyTextureSubImage3D unexpectedly generated error "
5157                                                                                         << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
5158
5159                 return false;
5160         }
5161
5162         return true;
5163 }
5164
5165 /** @brief Create texture.
5166  *
5167  *  @tparam D      Dimmensions.
5168  */
5169 template <>
5170 void CopyTest::CreateSourceTexture<1>()
5171 {
5172         /* Shortcut for GL functionality. */
5173         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5174
5175         gl.genTextures(1, &m_to_src);
5176         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
5177
5178         gl.bindTexture(TextureTarget<1>(), m_to_src);
5179         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
5180
5181         gl.texImage1D(TextureTarget<1>(), 0, GL_RGBA8, s_texture_width, 0, GL_RGBA, GL_UNSIGNED_BYTE, s_texture_data);
5182         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed.");
5183 }
5184
5185 /** @brief Create texture.
5186  *
5187  *  @tparam D      Dimmensions.
5188  */
5189 template <>
5190 void CopyTest::CreateSourceTexture<2>()
5191 {
5192         /* Shortcut for GL functionality. */
5193         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5194
5195         gl.genTextures(1, &m_to_src);
5196         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
5197
5198         gl.bindTexture(TextureTarget<2>(), m_to_src);
5199         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
5200
5201         gl.texImage2D(TextureTarget<2>(), 0, GL_RGBA8, s_texture_width, s_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
5202                                   s_texture_data);
5203         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed.");
5204 }
5205
5206 /** @brief Create texture.
5207  *
5208  *  @tparam D      Dimmensions.
5209  */
5210 template <>
5211 void CopyTest::CreateSourceTexture<3>()
5212 {
5213         /* Shortcut for GL functionality. */
5214         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5215
5216         gl.genTextures(1, &m_to_src);
5217         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
5218
5219         gl.bindTexture(TextureTarget<3>(), m_to_src);
5220         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
5221
5222         gl.texImage3D(TextureTarget<3>(), 0, GL_RGBA8, s_texture_width, s_texture_height, s_texture_depth, 0, GL_RGBA,
5223                                   GL_UNSIGNED_BYTE, s_texture_data);
5224         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed.");
5225 }
5226
5227 /** @brief Create texture.
5228  *
5229  *  @tparam D      Dimmensions.
5230  */
5231 template <>
5232 void CopyTest::CreateDestinationTexture<1>()
5233 {
5234         /* Shortcut for GL functionality. */
5235         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5236
5237         gl.genTextures(1, &m_to_dst);
5238         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
5239
5240         gl.bindTexture(TextureTarget<1>(), m_to_dst);
5241         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
5242
5243         gl.texImage1D(TextureTarget<1>(), 0, GL_RGBA8, s_texture_width, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
5244         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed.");
5245 }
5246
5247 /** @brief Create texture.
5248  *
5249  *  @tparam D      Dimmensions.
5250  */
5251 template <>
5252 void CopyTest::CreateDestinationTexture<2>()
5253 {
5254         /* Shortcut for GL functionality. */
5255         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5256
5257         gl.genTextures(1, &m_to_dst);
5258         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
5259
5260         gl.bindTexture(TextureTarget<2>(), m_to_dst);
5261         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
5262
5263         gl.texImage2D(TextureTarget<2>(), 0, GL_RGBA8, s_texture_width, s_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
5264                                   DE_NULL);
5265         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed.");
5266 }
5267
5268 /** @brief Create texture.
5269  *
5270  *  @tparam D      Dimmensions.
5271  */
5272 template <>
5273 void CopyTest::CreateDestinationTexture<3>()
5274 {
5275         /* Shortcut for GL functionality. */
5276         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5277
5278         gl.genTextures(1, &m_to_dst);
5279         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
5280
5281         gl.bindTexture(TextureTarget<3>(), m_to_dst);
5282         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
5283
5284         gl.texImage3D(TextureTarget<3>(), 0, GL_RGBA8, s_texture_width, s_texture_height, s_texture_depth, 0, GL_RGBA,
5285                                   GL_UNSIGNED_BYTE, DE_NULL);
5286         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed.");
5287 }
5288
5289 /** @brief Create framebuffer.
5290  *
5291  *  @tparam D      Dimmensions.
5292  */
5293 template <>
5294 void CopyTest::CreateSourceFramebuffer<1>()
5295 {
5296         /* Shortcut for GL functionality. */
5297         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5298
5299         /* Prepare framebuffer. */
5300         gl.genFramebuffers(1, &m_fbo);
5301         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
5302
5303         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
5304         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
5305
5306         gl.framebufferTexture1D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, TextureTarget<1>(), m_to_src, 0);
5307         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture1D call failed.");
5308
5309         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
5310         {
5311                 throw 0;
5312         }
5313
5314         gl.viewport(0, 0, s_texture_width, 1);
5315         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
5316 }
5317
5318 /** @brief Create framebuffer.
5319  *
5320  *  @tparam D      Dimmensions.
5321  */
5322 template <>
5323 void CopyTest::CreateSourceFramebuffer<2>()
5324 {
5325         /* Shortcut for GL functionality. */
5326         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5327
5328         /* Prepare framebuffer. */
5329         gl.genFramebuffers(1, &m_fbo);
5330         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
5331
5332         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
5333         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
5334
5335         gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, TextureTarget<2>(), m_to_src, 0);
5336         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture1D call failed.");
5337
5338         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
5339         {
5340                 throw 0;
5341         }
5342
5343         gl.viewport(0, 0, s_texture_width, s_texture_height);
5344         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
5345 }
5346
5347 /** @brief Create framebuffer.
5348  *
5349  *  @tparam D      Dimmensions.
5350  */
5351 template <>
5352 void CopyTest::CreateSourceFramebuffer<3>()
5353 {
5354         /* Shortcut for GL functionality. */
5355         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5356
5357         /* Prepare framebuffer. */
5358         gl.genFramebuffers(1, &m_fbo);
5359         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
5360
5361         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
5362         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
5363
5364         for (glw::GLuint i = 0; i < s_texture_depth; ++i)
5365         {
5366                 gl.framebufferTexture3D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, TextureTarget<3>(), m_to_src, 0, i);
5367                 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture1D call failed.");
5368         }
5369
5370         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
5371         {
5372                 throw 0;
5373         }
5374
5375         gl.viewport(0, 0, s_texture_width, s_texture_height);
5376         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
5377 }
5378
5379 /** @brief Dispatch function to create test objects */
5380 template <glw::GLuint D>
5381 void                              CopyTest::CreateAll()
5382 {
5383         CreateSourceTexture<D>();
5384         CreateSourceFramebuffer<D>();
5385         CreateDestinationTexture<D>();
5386 }
5387
5388 /** @brief Test function */
5389 template <>
5390 bool CopyTest::Test<1>()
5391 {
5392         CreateAll<1>();
5393
5394         bool result = true;
5395
5396         result &= CopyTextureSubImage1DAndCheckErrors(m_to_dst, 0, 0, 0, 0, s_texture_width / 2);
5397         result &= CopyTextureSubImage1DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, s_texture_width / 2, 0,
5398                                                                                                   s_texture_width / 2);
5399
5400         result &= CheckData(TextureTarget<1>(), 4 /* RGBA */ * s_texture_width);
5401
5402         CleanAll();
5403
5404         return result;
5405 }
5406
5407 /** @brief Test function */
5408 template <>
5409 bool CopyTest::Test<2>()
5410 {
5411         CreateAll<2>();
5412
5413         bool result = true;
5414
5415         result &= CopyTextureSubImage2DAndCheckErrors(m_to_dst, 0, 0, 0, 0, 0, s_texture_width / 2, s_texture_height / 2);
5416         result &= CopyTextureSubImage2DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, 0, s_texture_width / 2, 0,
5417                                                                                                   s_texture_width / 2, s_texture_height / 2);
5418         result &= CopyTextureSubImage2DAndCheckErrors(m_to_dst, 0, 0, s_texture_height / 2, 0, s_texture_height / 2,
5419                                                                                                   s_texture_width / 2, s_texture_height / 2);
5420         result &=
5421                 CopyTextureSubImage2DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, s_texture_height / 2, s_texture_width / 2,
5422                                                                                         s_texture_height / 2, s_texture_width / 2, s_texture_height / 2);
5423
5424         result &= CheckData(TextureTarget<2>(), 4 /* RGBA */ * s_texture_width * s_texture_height);
5425
5426         CleanAll();
5427
5428         return result;
5429 }
5430
5431 /** @brief Test function */
5432 template <>
5433 bool CopyTest::Test<3>()
5434 {
5435         CreateAll<3>();
5436
5437         bool result = true;
5438
5439         for (glw::GLuint i = 0; i < s_texture_depth; ++i)
5440         {
5441                 result &=
5442                         CopyTextureSubImage3DAndCheckErrors(m_to_dst, 0, 0, 0, i, 0, 0, s_texture_width / 2, s_texture_height / 2);
5443                 result &= CopyTextureSubImage3DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, 0, i, s_texture_width / 2, 0,
5444                                                                                                           s_texture_width / 2, s_texture_height / 2);
5445                 result &= CopyTextureSubImage3DAndCheckErrors(m_to_dst, 0, 0, s_texture_height / 2, i, 0, s_texture_height / 2,
5446                                                                                                           s_texture_width / 2, s_texture_height / 2);
5447                 result &= CopyTextureSubImage3DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, s_texture_height / 2, i,
5448                                                                                                           s_texture_width / 2, s_texture_height / 2, s_texture_width / 2,
5449                                                                                                           s_texture_height / 2);
5450         }
5451
5452         result &= CheckData(TextureTarget<3>(), 4 /* RGBA */ * s_texture_width * s_texture_height * s_texture_depth);
5453
5454         CleanAll();
5455
5456         return result;
5457 }
5458
5459 /** @brief Compre results with the reference.
5460  *
5461  *  @param [in] target      Texture target.
5462  *  @param [in] size        Size of the buffer.
5463  *
5464  *  @return True if equal, false otherwise.
5465  */
5466 bool CopyTest::CheckData(glw::GLenum target, glw::GLuint size)
5467 {
5468         /* Shortcut for GL functionality. */
5469         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5470
5471         /* Check texture content with reference. */
5472         m_result = new glw::GLubyte[size];
5473
5474         if (DE_NULL == m_result)
5475         {
5476                 throw 0;
5477         }
5478
5479         gl.getTexImage(target, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_result);
5480         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
5481
5482         for (glw::GLuint i = 0; i < size; ++i)
5483         {
5484                 if (s_texture_data[i] != m_result[i])
5485                 {
5486                         m_context.getTestContext().getLog()
5487                                 << tcu::TestLog::Message << "glCopyTextureSubImage*D created texture with data "
5488                                 << DataToString(size, s_texture_data) << " however texture contains data "
5489                                 << DataToString(size, m_result) << ". Texture target was " << glu::getTextureTargetStr(target)
5490                                 << ". Test fails." << tcu::TestLog::EndMessage;
5491
5492                         return false;
5493                 }
5494         }
5495
5496         return true;
5497 }
5498
5499 /** @brief Convert raw data into string for logging purposes.
5500  *
5501  *  @param [in] count      Count of the data.
5502  *  @param [in] data       Raw data.
5503  *
5504  *  @return String representation of data.
5505  */
5506 std::string CopyTest::DataToString(glw::GLuint count, const glw::GLubyte data[])
5507 {
5508         std::string data_str = "[";
5509
5510         for (glw::GLuint i = 0; i < count; ++i)
5511         {
5512                 std::stringstream int_sstream;
5513
5514                 int_sstream << unsigned(data[i]);
5515
5516                 data_str.append(int_sstream.str());
5517
5518                 if (i + 1 < count)
5519                 {
5520                         data_str.append(", ");
5521                 }
5522                 else
5523                 {
5524                         data_str.append("]");
5525                 }
5526         }
5527
5528         return data_str;
5529 }
5530
5531 /** @brief Clean GL objects, test variables and GL errors.
5532  */
5533 void CopyTest::CleanAll()
5534 {
5535         /* Shortcut for GL functionality. */
5536         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5537
5538         if (m_fbo)
5539         {
5540                 gl.deleteFramebuffers(1, &m_fbo);
5541
5542                 m_fbo = 0;
5543         }
5544
5545         if (m_to_src)
5546         {
5547                 gl.deleteTextures(1, &m_to_src);
5548
5549                 m_to_src = 0;
5550         }
5551
5552         if (m_to_dst)
5553         {
5554                 gl.deleteTextures(1, &m_to_dst);
5555
5556                 m_to_dst = 0;
5557         }
5558
5559         if (DE_NULL == m_result)
5560         {
5561                 delete[] m_result;
5562
5563                 m_result = DE_NULL;
5564         }
5565
5566         while (GL_NO_ERROR != gl.getError())
5567                 ;
5568 }
5569
5570 /** @brief Iterate Copy Test cases.
5571  *
5572  *  @return Iteration result.
5573  */
5574 tcu::TestNode::IterateResult CopyTest::iterate()
5575 {
5576         /* Get context setup. */
5577         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
5578         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
5579
5580         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
5581         {
5582                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
5583
5584                 return STOP;
5585         }
5586
5587         /* Running tests. */
5588         bool is_ok      = true;
5589         bool is_error = false;
5590
5591         try
5592         {
5593                 is_ok &= Test<1>();
5594                 is_ok &= Test<2>();
5595                 is_ok &= Test<3>();
5596         }
5597         catch (...)
5598         {
5599                 is_ok   = false;
5600                 is_error = true;
5601         }
5602
5603         /* Cleanup. */
5604         CleanAll();
5605
5606         /* Result's setup. */
5607         if (is_ok)
5608         {
5609                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
5610         }
5611         else
5612         {
5613                 if (is_error)
5614                 {
5615                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
5616                 }
5617                 else
5618                 {
5619                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
5620                 }
5621         }
5622
5623         return STOP;
5624 }
5625
5626 /** Reference data. */
5627 const glw::GLubyte CopyTest::s_texture_data[] = {
5628         0x00, 0x00, 0x00, 0xFF, 0x7f, 0x7f, 0x7f, 0x00, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0x00,
5629         0x88, 0x00, 0x15, 0xFF, 0xed, 0x1c, 0x24, 0x00, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x00, 0x00,
5630         0xc8, 0xbf, 0xe7, 0xFF, 0x70, 0x92, 0xbe, 0x00, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0x00,
5631         0xa3, 0x49, 0xa4, 0xFF, 0x3f, 0x48, 0xcc, 0x00, 0x00, 0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0x00,
5632
5633         0xa3, 0x49, 0xa4, 0xFF, 0xc8, 0xbf, 0xe7, 0x00, 0x88, 0x00, 0x15, 0xff, 0x00, 0x00, 0x00, 0x00,
5634         0x3f, 0x48, 0xcc, 0xFF, 0x70, 0x92, 0xbe, 0x00, 0xed, 0x1c, 0x24, 0xff, 0x7f, 0x7f, 0x7f, 0x00,
5635         0x00, 0xa2, 0xe8, 0xFF, 0x99, 0xd9, 0xea, 0x00, 0xff, 0x7f, 0x27, 0xff, 0xc3, 0xc3, 0xc3, 0x00,
5636         0x22, 0xb1, 0x4c, 0xFF, 0xb5, 0xe6, 0x1d, 0x00, 0xff, 0xf2, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00,
5637
5638         0x22, 0xb1, 0x4c, 0xFF, 0x00, 0xa2, 0xe8, 0x00, 0x3f, 0x48, 0xcc, 0xff, 0xa3, 0x49, 0xa4, 0x00,
5639         0xb5, 0xe6, 0x1d, 0xFF, 0x99, 0xd9, 0xea, 0x00, 0x70, 0x92, 0xbe, 0xff, 0xc8, 0xbf, 0xe7, 0x00,
5640         0xff, 0xf2, 0x00, 0xFF, 0xff, 0x7f, 0x27, 0x00, 0xed, 0x1c, 0x24, 0xff, 0x88, 0x00, 0x15, 0x00,
5641         0xff, 0xff, 0xff, 0xFF, 0xc3, 0xc3, 0xc3, 0x00, 0x7f, 0x7f, 0x7f, 0xff, 0x00, 0x00, 0x00, 0x00,
5642
5643         0xff, 0xff, 0xff, 0xFF, 0xff, 0xf2, 0x00, 0x00, 0xb5, 0xe6, 0x1d, 0xff, 0x22, 0xb1, 0x4c, 0x00,
5644         0xc3, 0xc3, 0xc3, 0xFF, 0xff, 0x7f, 0x27, 0x00, 0x99, 0xd9, 0xea, 0xff, 0x00, 0xa2, 0xe8, 0x00,
5645         0x7f, 0x7f, 0x7f, 0xFF, 0xed, 0x1c, 0x24, 0x00, 0x70, 0x92, 0xbe, 0xff, 0x3f, 0x48, 0xcc, 0x00,
5646         0x00, 0x00, 0x00, 0xFF, 0x88, 0x00, 0x15, 0x00, 0xc8, 0xbf, 0xe7, 0xff, 0xa3, 0x49, 0xa4, 0x00
5647 };
5648
5649 /** Reference data parameters. */
5650 const glw::GLuint CopyTest::s_texture_width  = 4;
5651 const glw::GLuint CopyTest::s_texture_height = 4;
5652 const glw::GLuint CopyTest::s_texture_depth  = 4;
5653
5654 /******************************** Get Set Parameter Test Implementation   ********************************/
5655
5656 /** @brief Get Set Parameter Test constructor.
5657  *
5658  *  @param [in] context     OpenGL context.
5659  */
5660 GetSetParameterTest::GetSetParameterTest(deqp::Context& context)
5661         : deqp::TestCase(context, "textures_get_set_parameter", "Texture Get Set Parameter Test")
5662 {
5663         /* Intentionally left blank. */
5664 }
5665
5666 /** @brief Iterate Get Set Parameter Test cases.
5667  *
5668  *  @return Iteration result.
5669  */
5670 tcu::TestNode::IterateResult GetSetParameterTest::iterate()
5671 {
5672         /* Shortcut for GL functionality. */
5673         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5674
5675         /* Get context setup. */
5676         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
5677         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
5678
5679         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
5680         {
5681                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
5682
5683                 return STOP;
5684         }
5685
5686         /* Running tests. */
5687         bool is_ok      = true;
5688         bool is_error = false;
5689
5690         /* Texture. */
5691         glw::GLuint texture = 0;
5692
5693         try
5694         {
5695                 gl.genTextures(1, &texture);
5696                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
5697
5698                 gl.bindTexture(GL_TEXTURE_3D, texture);
5699                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
5700
5701                 {
5702                         glw::GLenum name          = GL_DEPTH_STENCIL_TEXTURE_MODE;
5703                         glw::GLint  value_src = GL_DEPTH_COMPONENT;
5704                         glw::GLint  value_dst = 0;
5705
5706                         gl.textureParameteri(texture, name, value_src);
5707                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5708
5709                         gl.getTextureParameteriv(texture, name, &value_dst);
5710                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5711
5712                         is_ok &= CompareAndLog(value_src, value_dst, name);
5713                 }
5714
5715                 {
5716                         glw::GLenum name          = GL_TEXTURE_BASE_LEVEL;
5717                         glw::GLint  value_src = 2;
5718                         glw::GLint  value_dst = 0;
5719
5720                         gl.textureParameteri(texture, name, value_src);
5721                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5722
5723                         gl.getTextureParameteriv(texture, name, &value_dst);
5724                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5725
5726                         is_ok &= CompareAndLog(value_src, value_dst, name);
5727                 }
5728
5729                 {
5730                         glw::GLenum  name                 = GL_TEXTURE_BORDER_COLOR;
5731                         glw::GLfloat value_src[4] = { 0.25, 0.5, 0.75, 1.0 };
5732                         glw::GLfloat value_dst[4] = {};
5733
5734                         gl.textureParameterfv(texture, name, value_src);
5735                         is_ok &= CheckErrorAndLog("glTextureParameterfv", name);
5736
5737                         gl.getTextureParameterfv(texture, name, value_dst);
5738                         is_ok &= CheckErrorAndLog("glGetTextureParameterfv", name);
5739
5740                         is_ok &= CompareAndLog(value_src, value_dst, name);
5741                 }
5742
5743                 {
5744                         glw::GLenum name                 = GL_TEXTURE_BORDER_COLOR;
5745                         glw::GLint  value_src[4] = { 0, 64, -64, -32 };
5746                         glw::GLint  value_dst[4] = {};
5747
5748                         gl.textureParameterIiv(texture, name, value_src);
5749                         is_ok &= CheckErrorAndLog("glTextureParameterIiv", name);
5750
5751                         gl.getTextureParameterIiv(texture, name, value_dst);
5752                         is_ok &= CheckErrorAndLog("glGetTextureParameterIiv", name);
5753
5754                         is_ok &= CompareAndLog(value_src, value_dst, name);
5755                 }
5756
5757                 {
5758                         glw::GLenum name                 = GL_TEXTURE_BORDER_COLOR;
5759                         glw::GLuint value_src[4] = { 0, 64, 128, 192 };
5760                         glw::GLuint value_dst[4] = {};
5761
5762                         gl.textureParameterIuiv(texture, name, value_src);
5763                         is_ok &= CheckErrorAndLog("glTextureParameterIuiv", name);
5764
5765                         gl.getTextureParameterIuiv(texture, name, value_dst);
5766                         is_ok &= CheckErrorAndLog("glGetTextureParameterIuiv", name);
5767
5768                         is_ok &= CompareAndLog(value_src, value_dst, name);
5769                 }
5770
5771                 {
5772                         glw::GLenum name          = GL_TEXTURE_COMPARE_FUNC;
5773                         glw::GLint  value_src = GL_LEQUAL;
5774                         glw::GLint  value_dst = 0;
5775
5776                         gl.textureParameteri(texture, name, value_src);
5777                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5778
5779                         gl.getTextureParameteriv(texture, name, &value_dst);
5780                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5781
5782                         is_ok &= CompareAndLog(value_src, value_dst, name);
5783                 }
5784
5785                 {
5786                         glw::GLenum name          = GL_TEXTURE_COMPARE_MODE;
5787                         glw::GLint  value_src = GL_COMPARE_REF_TO_TEXTURE;
5788                         glw::GLint  value_dst = 0;
5789
5790                         gl.textureParameteri(texture, name, value_src);
5791                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5792
5793                         gl.getTextureParameteriv(texture, name, &value_dst);
5794                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5795
5796                         is_ok &= CompareAndLog(value_src, value_dst, name);
5797                 }
5798
5799                 {
5800                         glw::GLenum  name         = GL_TEXTURE_LOD_BIAS;
5801                         glw::GLfloat value_src = -2.f;
5802                         glw::GLfloat value_dst = 0.f;
5803
5804                         gl.textureParameterf(texture, name, value_src);
5805                         is_ok &= CheckErrorAndLog("glTextureParameterf", name);
5806
5807                         gl.getTextureParameterfv(texture, name, &value_dst);
5808                         is_ok &= CheckErrorAndLog("glGetTextureParameterfv", name);
5809
5810                         is_ok &= CompareAndLog(value_src, value_dst, name);
5811                 }
5812
5813                 {
5814                         glw::GLenum name          = GL_TEXTURE_MIN_FILTER;
5815                         glw::GLint  value_src = GL_LINEAR_MIPMAP_NEAREST;
5816                         glw::GLint  value_dst = 0;
5817
5818                         gl.textureParameteri(texture, name, value_src);
5819                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5820
5821                         gl.getTextureParameteriv(texture, name, &value_dst);
5822                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5823
5824                         is_ok &= CompareAndLog(value_src, value_dst, name);
5825                 }
5826
5827                 {
5828                         glw::GLenum name          = GL_TEXTURE_MAG_FILTER;
5829                         glw::GLint  value_src = GL_NEAREST;
5830                         glw::GLint  value_dst = 0;
5831
5832                         gl.textureParameteri(texture, name, value_src);
5833                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5834
5835                         gl.getTextureParameteriv(texture, name, &value_dst);
5836                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5837
5838                         is_ok &= CompareAndLog(value_src, value_dst, name);
5839                 }
5840
5841                 {
5842                         glw::GLenum name          = GL_TEXTURE_MIN_LOD;
5843                         glw::GLint  value_src = -100;
5844                         glw::GLint  value_dst = 0;
5845
5846                         gl.textureParameteri(texture, name, value_src);
5847                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5848
5849                         gl.getTextureParameteriv(texture, name, &value_dst);
5850                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5851
5852                         is_ok &= CompareAndLog(value_src, value_dst, name);
5853                 }
5854
5855                 {
5856                         glw::GLenum name          = GL_TEXTURE_MAX_LOD;
5857                         glw::GLint  value_src = 100;
5858                         glw::GLint  value_dst = 0;
5859
5860                         gl.textureParameteri(texture, name, value_src);
5861                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5862
5863                         gl.getTextureParameteriv(texture, name, &value_dst);
5864                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5865
5866                         is_ok &= CompareAndLog(value_src, value_dst, name);
5867                 }
5868
5869                 {
5870                         glw::GLenum name          = GL_TEXTURE_MAX_LEVEL;
5871                         glw::GLint  value_src = 100;
5872                         glw::GLint  value_dst = 0;
5873
5874                         gl.textureParameteri(texture, name, value_src);
5875                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5876
5877                         gl.getTextureParameteriv(texture, name, &value_dst);
5878                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5879
5880                         is_ok &= CompareAndLog(value_src, value_dst, name);
5881                 }
5882
5883                 {
5884                         glw::GLenum name          = GL_TEXTURE_SWIZZLE_R;
5885                         glw::GLint  value_src = GL_BLUE;
5886                         glw::GLint  value_dst = 0;
5887
5888                         gl.textureParameteri(texture, name, value_src);
5889                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5890
5891                         gl.getTextureParameteriv(texture, name, &value_dst);
5892                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5893
5894                         is_ok &= CompareAndLog(value_src, value_dst, name);
5895                 }
5896
5897                 {
5898                         glw::GLenum name          = GL_TEXTURE_SWIZZLE_G;
5899                         glw::GLint  value_src = GL_ALPHA;
5900                         glw::GLint  value_dst = 0;
5901
5902                         gl.textureParameteri(texture, name, value_src);
5903                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5904
5905                         gl.getTextureParameteriv(texture, name, &value_dst);
5906                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5907
5908                         is_ok &= CompareAndLog(value_src, value_dst, name);
5909                 }
5910
5911                 {
5912                         glw::GLenum name          = GL_TEXTURE_SWIZZLE_B;
5913                         glw::GLint  value_src = GL_RED;
5914                         glw::GLint  value_dst = 0;
5915
5916                         gl.textureParameteri(texture, name, value_src);
5917                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5918
5919                         gl.getTextureParameteriv(texture, name, &value_dst);
5920                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5921
5922                         is_ok &= CompareAndLog(value_src, value_dst, name);
5923                 }
5924
5925                 {
5926                         glw::GLenum name          = GL_TEXTURE_SWIZZLE_A;
5927                         glw::GLint  value_src = GL_GREEN;
5928                         glw::GLint  value_dst = 0;
5929
5930                         gl.textureParameteri(texture, name, value_src);
5931                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5932
5933                         gl.getTextureParameteriv(texture, name, &value_dst);
5934                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5935
5936                         is_ok &= CompareAndLog(value_src, value_dst, name);
5937                 }
5938
5939                 {
5940                         glw::GLenum name                 = GL_TEXTURE_SWIZZLE_RGBA;
5941                         glw::GLint  value_src[4] = { GL_ZERO, GL_ONE, GL_ZERO, GL_ONE };
5942                         glw::GLint  value_dst[4] = {};
5943
5944                         gl.textureParameteriv(texture, name, value_src);
5945                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5946
5947                         gl.getTextureParameteriv(texture, name, value_dst);
5948                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5949
5950                         is_ok &= CompareAndLog(value_src, value_dst, name);
5951                 }
5952
5953                 {
5954                         glw::GLenum name          = GL_TEXTURE_WRAP_S;
5955                         glw::GLint  value_src = GL_MIRROR_CLAMP_TO_EDGE;
5956                         glw::GLint  value_dst = 11;
5957
5958                         gl.textureParameteri(texture, name, value_src);
5959                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5960
5961                         gl.getTextureParameteriv(texture, name, &value_dst);
5962                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5963
5964                         is_ok &= CompareAndLog(value_src, value_dst, name);
5965                 }
5966
5967                 {
5968                         glw::GLenum name          = GL_TEXTURE_WRAP_T;
5969                         glw::GLint  value_src = GL_CLAMP_TO_EDGE;
5970                         glw::GLint  value_dst = 11;
5971
5972                         gl.textureParameteri(texture, name, value_src);
5973                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5974
5975                         gl.getTextureParameteriv(texture, name, &value_dst);
5976                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5977
5978                         is_ok &= CompareAndLog(value_src, value_dst, name);
5979                 }
5980
5981                 {
5982                         glw::GLenum name          = GL_TEXTURE_WRAP_R;
5983                         glw::GLint  value_src = GL_CLAMP_TO_EDGE;
5984                         glw::GLint  value_dst = 11;
5985
5986                         gl.textureParameteriv(texture, name, &value_src);
5987                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5988
5989                         gl.getTextureParameteriv(texture, name, &value_dst);
5990                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5991
5992                         is_ok &= CompareAndLog(value_src, value_dst, name);
5993                 }
5994         }
5995         catch (...)
5996         {
5997                 is_ok   = false;
5998                 is_error = true;
5999         }
6000
6001         /* Cleanup. */
6002         if (texture)
6003         {
6004                 gl.deleteTextures(1, &texture);
6005         }
6006
6007         while (GL_NO_ERROR != gl.getError())
6008                 ;
6009
6010         /* Result's setup. */
6011         if (is_ok)
6012         {
6013                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
6014         }
6015         else
6016         {
6017                 if (is_error)
6018                 {
6019                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
6020                 }
6021                 else
6022                 {
6023                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
6024                 }
6025         }
6026
6027         return STOP;
6028 }
6029
6030 /** @brief Check for errors and log.
6031  *
6032  *  @param [in] fname     Name of the function (to be logged).
6033  *  @param [in] pname     Parameter name with which function was called.
6034  *
6035  *  @return True if no error, false otherwise.
6036  */
6037 bool GetSetParameterTest::CheckErrorAndLog(const glw::GLchar* fname, glw::GLenum pname)
6038 {
6039         /* Shortcut for GL functionality. */
6040         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
6041
6042         /* Check errors. */
6043         glw::GLenum error;
6044
6045         if (GL_NO_ERROR != (error = gl.getError()))
6046         {
6047                 m_context.getTestContext().getLog() << tcu::TestLog::Message << fname << " unexpectedly generated error "
6048                                                                                         << glu::getErrorStr(error) << " during test of pname "
6049                                                                                         << glu::getTextureParameterStr(pname) << ". Test fails."
6050                                                                                         << tcu::TestLog::EndMessage;
6051
6052                 return false;
6053         }
6054
6055         return true;
6056 }
6057
6058 /** @brief Compare queried value of parameter with the expected vale.
6059  *
6060  *  @param [in] value_src           First value.
6061  *  @param [in] value_dst           Second value.
6062  *  @param [in] pname               Parameter name.
6063  *
6064  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6065  */
6066 bool GetSetParameterTest::CompareAndLog(glw::GLint value_src, glw::GLint value_dst, glw::GLenum pname)
6067 {
6068         if (value_src != value_dst)
6069         {
6070                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Queried value of pname "
6071                                                                                         << glu::getTextureParameterStr(pname) << " is equal to " << value_dst
6072                                                                                         << ", however " << value_src << " was expected. Test fails."
6073                                                                                         << tcu::TestLog::EndMessage;
6074
6075                 return false;
6076         }
6077
6078         return true;
6079 }
6080
6081 /** @brief Compare queried value of parameter with the expected vale.
6082  *
6083  *  @param [in] value_src           First value.
6084  *  @param [in] value_dst           Second value.
6085  *  @param [in] pname               Parameter name.
6086  *
6087  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6088  */
6089 bool GetSetParameterTest::CompareAndLog(glw::GLuint value_src, glw::GLuint value_dst, glw::GLenum pname)
6090 {
6091         if (value_src != value_dst)
6092         {
6093                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Queried value of pname "
6094                                                                                         << glu::getTextureParameterStr(pname) << " is equal to " << value_dst
6095                                                                                         << ", however " << value_src << " was expected. Test fails."
6096                                                                                         << tcu::TestLog::EndMessage;
6097
6098                 return false;
6099         }
6100
6101         return true;
6102 }
6103
6104 /** @brief Compare queried value of parameter with the expected vale.
6105  *
6106  *  @param [in] value_src           First value.
6107  *  @param [in] value_dst           Second value.
6108  *  @param [in] pname               Parameter name.
6109  *
6110  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6111  */
6112 bool GetSetParameterTest::CompareAndLog(glw::GLfloat value_src, glw::GLfloat value_dst, glw::GLenum pname)
6113 {
6114         if (de::abs(value_src - value_dst) > 0.0125 /* Precision */)
6115         {
6116                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Queried value of pname "
6117                                                                                         << glu::getTextureParameterStr(pname) << " is equal to " << value_dst
6118                                                                                         << ", however " << value_src << " was expected. Test fails."
6119                                                                                         << tcu::TestLog::EndMessage;
6120
6121                 return false;
6122         }
6123
6124         return true;
6125 }
6126
6127 /** @brief Compare queried value of parameter with the expected vale.
6128  *
6129  *  @param [in] value_src           First value.
6130  *  @param [in] value_dst           Second value.
6131  *  @param [in] pname               Parameter name.
6132  *
6133  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6134  */
6135 bool GetSetParameterTest::CompareAndLog(glw::GLint value_src[4], glw::GLint value_dst[4], glw::GLenum pname)
6136 {
6137         if ((value_src[0] != value_dst[0]) || (value_src[1] != value_dst[1]) || (value_src[2] != value_dst[2]) ||
6138                 (value_src[3] != value_dst[3]))
6139         {
6140                 m_context.getTestContext().getLog()
6141                         << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6142                         << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3]
6143                         << "], however " << value_src[0] << ", " << value_src[1] << ", " << value_src[2] << ", " << value_src[3]
6144                         << "] was expected. Test fails." << tcu::TestLog::EndMessage;
6145
6146                 return false;
6147         }
6148
6149         return true;
6150 }
6151
6152 /** @brief Compare queried value of parameter with the expected vale.
6153  *
6154  *  @param [in] value_src           First value.
6155  *  @param [in] value_dst           Second value.
6156  *  @param [in] pname               Parameter name.
6157  *
6158  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6159  */
6160 bool GetSetParameterTest::CompareAndLog(glw::GLuint value_src[4], glw::GLuint value_dst[4], glw::GLenum pname)
6161 {
6162         if ((value_src[0] != value_dst[0]) || (value_src[1] != value_dst[1]) || (value_src[2] != value_dst[2]) ||
6163                 (value_src[3] != value_dst[3]))
6164         {
6165                 m_context.getTestContext().getLog()
6166                         << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6167                         << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3]
6168                         << "], however " << value_src[0] << ", " << value_src[1] << ", " << value_src[2] << ", " << value_src[3]
6169                         << "] was expected. Test fails." << tcu::TestLog::EndMessage;
6170
6171                 return false;
6172         }
6173
6174         return true;
6175 }
6176
6177 /** @brief Compare queried value of parameter with the expected vale.
6178  *
6179  *  @param [in] value_src           First value.
6180  *  @param [in] value_dst           Second value.
6181  *  @param [in] pname               Parameter name.
6182  *
6183  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6184  */
6185 bool GetSetParameterTest::CompareAndLog(glw::GLfloat value_src[4], glw::GLfloat value_dst[4], glw::GLenum pname)
6186 {
6187         if ((de::abs(value_src[0] - value_dst[0]) > 0.0125 /* Precision */) ||
6188                 (de::abs(value_src[1] - value_dst[1]) > 0.0125 /* Precision */) ||
6189                 (de::abs(value_src[2] - value_dst[2]) > 0.0125 /* Precision */) ||
6190                 (de::abs(value_src[3] - value_dst[3]) > 0.0125 /* Precision */))
6191         {
6192                 m_context.getTestContext().getLog()
6193                         << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6194                         << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3]
6195                         << "], however " << value_src[0] << ", " << value_src[1] << ", " << value_src[2] << ", " << value_src[3]
6196                         << "] was expected. Test fails." << tcu::TestLog::EndMessage;
6197
6198                 return false;
6199         }
6200
6201         return true;
6202 }
6203
6204 /******************************** Defaults Test Implementation   ********************************/
6205
6206 /** @brief Defaults Test constructor.
6207  *
6208  *  @param [in] context     OpenGL context.
6209  */
6210 DefaultsTest::DefaultsTest(deqp::Context& context)
6211         : deqp::TestCase(context, "textures_defaults", "Texture Defaults Test")
6212 {
6213         /* Intentionally left blank. */
6214 }
6215
6216 /** @brief Defaults Test cases.
6217  *
6218  *  @return Iteration result.
6219  */
6220 tcu::TestNode::IterateResult DefaultsTest::iterate()
6221 {
6222         /* Shortcut for GL functionality. */
6223         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
6224
6225         /* Get context setup. */
6226         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
6227         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
6228
6229         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
6230         {
6231                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
6232
6233                 return STOP;
6234         }
6235
6236         /* Running tests. */
6237         bool is_ok      = true;
6238         bool is_error = false;
6239
6240         /* Texture. */
6241         glw::GLuint texture = 0;
6242
6243         try
6244         {
6245                 gl.createTextures(GL_TEXTURE_3D, 1, &texture);
6246                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
6247
6248                 {
6249                         glw::GLenum name          = GL_DEPTH_STENCIL_TEXTURE_MODE;
6250                         glw::GLint  value_ref = GL_DEPTH_COMPONENT;
6251                         glw::GLint  value_dst = 0;
6252
6253                         gl.getTextureParameteriv(texture, name, &value_dst);
6254                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6255
6256                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6257                 }
6258
6259                 {
6260                         glw::GLenum name          = GL_TEXTURE_BASE_LEVEL;
6261                         glw::GLint  value_ref = 0;
6262                         glw::GLint  value_dst = 1;
6263
6264                         gl.getTextureParameteriv(texture, name, &value_dst);
6265                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6266
6267                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6268                 }
6269
6270                 {
6271                         glw::GLenum  name                 = GL_TEXTURE_BORDER_COLOR;
6272                         glw::GLfloat value_ref[4] = { 0.f, 0.f, 0.f, 0.f };
6273                         glw::GLfloat value_dst[4] = {};
6274
6275                         gl.getTextureParameterfv(texture, name, value_dst);
6276                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6277
6278                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6279                 }
6280
6281                 {
6282                         glw::GLenum name          = GL_TEXTURE_COMPARE_FUNC;
6283                         glw::GLint  value_ref = GL_LEQUAL;
6284                         glw::GLint  value_dst = 0;
6285
6286                         gl.getTextureParameteriv(texture, name, &value_dst);
6287                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6288
6289                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6290                 }
6291
6292                 {
6293                         glw::GLenum name          = GL_TEXTURE_COMPARE_MODE;
6294                         glw::GLint  value_ref = GL_NONE;
6295                         glw::GLint  value_dst = 0;
6296
6297                         gl.getTextureParameteriv(texture, name, &value_dst);
6298                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6299
6300                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6301                 }
6302
6303                 {
6304                         glw::GLenum  name         = GL_TEXTURE_LOD_BIAS;
6305                         glw::GLfloat value_ref = 0.f;
6306                         glw::GLfloat value_dst = 0.f;
6307
6308                         gl.getTextureParameterfv(texture, name, &value_dst);
6309                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6310
6311                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6312                 }
6313
6314                 {
6315                         glw::GLenum name          = GL_TEXTURE_MIN_FILTER;
6316                         glw::GLint  value_ref = GL_NEAREST_MIPMAP_LINEAR;
6317                         glw::GLint  value_dst = 0;
6318
6319                         gl.getTextureParameteriv(texture, name, &value_dst);
6320                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6321
6322                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6323                 }
6324
6325                 {
6326                         glw::GLenum name          = GL_TEXTURE_MAG_FILTER;
6327                         glw::GLint  value_ref = GL_LINEAR;
6328                         glw::GLint  value_dst = 0;
6329
6330                         gl.getTextureParameteriv(texture, name, &value_dst);
6331                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6332
6333                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6334                 }
6335
6336                 {
6337                         glw::GLenum name          = GL_TEXTURE_MIN_LOD;
6338                         glw::GLint  value_ref = -1000;
6339                         glw::GLint  value_dst = 0;
6340
6341                         gl.getTextureParameteriv(texture, name, &value_dst);
6342                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6343
6344                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6345                 }
6346
6347                 {
6348                         glw::GLenum name          = GL_TEXTURE_MAX_LOD;
6349                         glw::GLint  value_ref = 1000;
6350                         glw::GLint  value_dst = 0;
6351
6352                         gl.getTextureParameteriv(texture, name, &value_dst);
6353                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6354
6355                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6356                 }
6357
6358                 {
6359                         glw::GLenum name          = GL_TEXTURE_MAX_LEVEL;
6360                         glw::GLint  value_ref = 1000;
6361                         glw::GLint  value_dst = 0;
6362
6363                         gl.getTextureParameteriv(texture, name, &value_dst);
6364                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6365
6366                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6367                 }
6368
6369                 {
6370                         glw::GLenum name          = GL_TEXTURE_SWIZZLE_R;
6371                         glw::GLint  value_ref = GL_RED;
6372                         glw::GLint  value_dst = 0;
6373
6374                         gl.getTextureParameteriv(texture, name, &value_dst);
6375                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6376
6377                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6378                 }
6379
6380                 {
6381                         glw::GLenum name          = GL_TEXTURE_SWIZZLE_G;
6382                         glw::GLint  value_ref = GL_GREEN;
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_SWIZZLE_B;
6393                         glw::GLint  value_ref = GL_BLUE;
6394                         glw::GLint  value_dst = 0;
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_SWIZZLE_A;
6404                         glw::GLint  value_ref = GL_ALPHA;
6405                         glw::GLint  value_dst = 0;
6406
6407                         gl.getTextureParameteriv(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_WRAP_S;
6415                         glw::GLint  value_ref = GL_REPEAT;
6416                         glw::GLint  value_dst = 11;
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_WRAP_T;
6426                         glw::GLint  value_ref = GL_REPEAT;
6427                         glw::GLint  value_dst = 11;
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_WRAP_R;
6437                         glw::GLint  value_ref = GL_REPEAT;
6438                         glw::GLint  value_dst = 11;
6439
6440                         gl.getTextureParameteriv(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         catch (...)
6447         {
6448                 is_ok   = false;
6449                 is_error = true;
6450         }
6451
6452         /* Cleanup. */
6453         if (texture)
6454         {
6455                 gl.deleteTextures(1, &texture);
6456         }
6457
6458         while (GL_NO_ERROR != gl.getError())
6459                 ;
6460
6461         /* Result's setup. */
6462         if (is_ok)
6463         {
6464                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
6465         }
6466         else
6467         {
6468                 if (is_error)
6469                 {
6470                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
6471                 }
6472                 else
6473                 {
6474                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
6475                 }
6476         }
6477
6478         return STOP;
6479 }
6480
6481 /** @brief Compare queried value of parameter with the expected vale.
6482  *
6483  *  @param [in] value_src           First value.
6484  *  @param [in] value_dst           Second value.
6485  *  @param [in] pname               Parameter name.
6486  *
6487  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6488  */
6489 bool DefaultsTest::CompareAndLog(glw::GLint value_ref, glw::GLint value_dst, glw::GLenum pname)
6490 {
6491         if (value_ref != value_dst)
6492         {
6493                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Queried value of pname "
6494                                                                                         << glu::getTextureParameterStr(pname) << " is equal to " << value_dst
6495                                                                                         << ", however " << value_ref << " was expected. Test fails."
6496                                                                                         << tcu::TestLog::EndMessage;
6497
6498                 return false;
6499         }
6500
6501         return true;
6502 }
6503
6504 /** @brief Compare queried value of parameter with the expected vale.
6505  *
6506  *  @param [in] value_src           First value.
6507  *  @param [in] value_dst           Second value.
6508  *  @param [in] pname               Parameter name.
6509  *
6510  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6511  */
6512 bool DefaultsTest::CompareAndLog(glw::GLuint value_ref, glw::GLuint value_dst, glw::GLenum pname)
6513 {
6514         if (value_ref != value_dst)
6515         {
6516                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Queried value of pname "
6517                                                                                         << glu::getTextureParameterStr(pname) << " is equal to " << value_dst
6518                                                                                         << ", however " << value_ref << " was expected. Test fails."
6519                                                                                         << tcu::TestLog::EndMessage;
6520
6521                 return false;
6522         }
6523
6524         return true;
6525 }
6526
6527 /** @brief Compare queried value of parameter with the expected vale.
6528  *
6529  *  @param [in] value_src           First value.
6530  *  @param [in] value_dst           Second value.
6531  *  @param [in] pname               Parameter name.
6532  *
6533  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6534  */
6535 bool DefaultsTest::CompareAndLog(glw::GLfloat value_ref, glw::GLfloat value_dst, glw::GLenum pname)
6536 {
6537         if (de::abs(value_ref - value_dst) > 0.0125 /* Precision */)
6538         {
6539                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Queried value of pname "
6540                                                                                         << glu::getTextureParameterStr(pname) << " is equal to " << value_dst
6541                                                                                         << ", however " << value_ref << " was expected. Test fails."
6542                                                                                         << tcu::TestLog::EndMessage;
6543
6544                 return false;
6545         }
6546
6547         return true;
6548 }
6549
6550 /** @brief Compare queried value of parameter with the expected vale.
6551  *
6552  *  @param [in] value_src           First value.
6553  *  @param [in] value_dst           Second value.
6554  *  @param [in] pname               Parameter name.
6555  *
6556  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6557  */
6558 bool DefaultsTest::CompareAndLog(glw::GLint value_ref[4], glw::GLint value_dst[4], glw::GLenum pname)
6559 {
6560         if ((value_ref[0] != value_dst[0]) || (value_ref[1] != value_dst[1]) || (value_ref[2] != value_dst[2]) ||
6561                 (value_ref[3] != value_dst[3]))
6562         {
6563                 m_context.getTestContext().getLog()
6564                         << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6565                         << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3]
6566                         << "], however " << value_ref[0] << ", " << value_ref[1] << ", " << value_ref[2] << ", " << value_ref[3]
6567                         << "] was expected. Test fails." << tcu::TestLog::EndMessage;
6568
6569                 return false;
6570         }
6571
6572         return true;
6573 }
6574
6575 /** @brief Compare queried value of parameter with the expected vale.
6576  *
6577  *  @param [in] value_src           First value.
6578  *  @param [in] value_dst           Second value.
6579  *  @param [in] pname               Parameter name.
6580  *
6581  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6582  */
6583 bool DefaultsTest::CompareAndLog(glw::GLuint value_ref[4], glw::GLuint value_dst[4], glw::GLenum pname)
6584 {
6585         if ((value_ref[0] != value_dst[0]) || (value_ref[1] != value_dst[1]) || (value_ref[2] != value_dst[2]) ||
6586                 (value_ref[3] != value_dst[3]))
6587         {
6588                 m_context.getTestContext().getLog()
6589                         << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6590                         << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3]
6591                         << "], however " << value_ref[0] << ", " << value_ref[1] << ", " << value_ref[2] << ", " << value_ref[3]
6592                         << "] was expected. Test fails." << tcu::TestLog::EndMessage;
6593
6594                 return false;
6595         }
6596
6597         return true;
6598 }
6599
6600 /** @brief Compare queried value of parameter with the expected vale.
6601  *
6602  *  @param [in] value_src           First value.
6603  *  @param [in] value_dst           Second value.
6604  *  @param [in] pname               Parameter name.
6605  *
6606  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6607  */
6608 bool DefaultsTest::CompareAndLog(glw::GLfloat value_ref[4], glw::GLfloat value_dst[4], glw::GLenum pname)
6609 {
6610         if ((de::abs(value_ref[0] - value_dst[0]) > 0.0125 /* Precision */) ||
6611                 (de::abs(value_ref[1] - value_dst[1]) > 0.0125 /* Precision */) ||
6612                 (de::abs(value_ref[2] - value_dst[2]) > 0.0125 /* Precision */) ||
6613                 (de::abs(value_ref[3] - value_dst[3]) > 0.0125 /* Precision */))
6614         {
6615                 m_context.getTestContext().getLog()
6616                         << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6617                         << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3]
6618                         << "], however " << value_ref[0] << ", " << value_ref[1] << ", " << value_ref[2] << ", " << value_ref[3]
6619                         << "] was expected. Test fails." << tcu::TestLog::EndMessage;
6620
6621                 return false;
6622         }
6623
6624         return true;
6625 }
6626
6627 /******************************** Generate Mipmap Test Implementation   ********************************/
6628
6629 /** @brief Generate Mipmap Test constructor.
6630  *
6631  *  @param [in] context     OpenGL context.
6632  */
6633 GenerateMipmapTest::GenerateMipmapTest(deqp::Context& context)
6634         : deqp::TestCase(context, "textures_generate_mipmaps", "Textures Generate Mipmap Test")
6635 {
6636         /* Intentionally left blank. */
6637 }
6638
6639 /** @brief Generate Mipmap Test cases.
6640  *
6641  *  @return Iteration result.
6642  */
6643 tcu::TestNode::IterateResult GenerateMipmapTest::iterate()
6644 {
6645         /* Shortcut for GL functionality. */
6646         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
6647
6648         /* Get context setup. */
6649         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
6650         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
6651
6652         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
6653         {
6654                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
6655
6656                 return STOP;
6657         }
6658
6659         /* Running tests. */
6660         bool is_ok      = true;
6661         bool is_error = false;
6662
6663         /* Texture and cpu results storage. */
6664         glw::GLuint   texture = 0;
6665         glw::GLubyte* result  = DE_NULL;
6666
6667         try
6668         {
6669                 /* Prepare texture. */
6670                 gl.genTextures(1, &texture);
6671                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
6672
6673                 gl.bindTexture(GL_TEXTURE_1D, texture);
6674                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
6675
6676                 gl.texImage1D(GL_TEXTURE_1D, 0, GL_R8, s_texture_width, 0, GL_RED, GL_UNSIGNED_BYTE, s_texture_data);
6677                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
6678
6679                 /* Generate mipmaps with tested function. */
6680                 gl.generateTextureMipmap(texture);
6681
6682                 glw::GLenum error = GL_NO_ERROR;
6683
6684                 if (GL_NO_ERROR != (error = gl.getError()))
6685                 {
6686                         m_context.getTestContext().getLog()
6687                                 << tcu::TestLog::Message << "GenerateTextureMipmap unexpectedly generated error "
6688                                 << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
6689
6690                         is_ok = false;
6691                 }
6692
6693                 /* Continue only if mipmaps has been generated. */
6694                 if (is_ok)
6695                 {
6696                         result = new glw::GLubyte[s_texture_width];
6697
6698                         if (DE_NULL == result)
6699                         {
6700                                 throw 0;
6701                         }
6702
6703                         /* For each mipmap. */
6704                         for (glw::GLuint i = 0, j = s_texture_width;
6705                                  i < s_texture_width_log - 1 /* Do not test single pixel mipmap. */; ++i, j /= 2)
6706                         {
6707                                 /* Check mipmap size. */
6708                                 glw::GLint mipmap_size = 0;
6709
6710                                 gl.getTexLevelParameteriv(GL_TEXTURE_1D, i, GL_TEXTURE_WIDTH, &mipmap_size);
6711                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
6712
6713                                 if (mipmap_size != (glw::GLint)j)
6714                                 {
6715                                         m_context.getTestContext().getLog()
6716                                                 << tcu::TestLog::Message
6717                                                 << "GenerateTextureMipmap unexpectedly generated mipmap with improper size. Mipmap size is "
6718                                                 << mipmap_size << ", but " << j << " was expected. Test fails." << tcu::TestLog::EndMessage;
6719
6720                                         is_ok = false;
6721
6722                                         break;
6723                                 }
6724
6725                                 /* Fetch data. */
6726                                 gl.getTexImage(GL_TEXTURE_1D, i, GL_RED, GL_UNSIGNED_BYTE, result);
6727                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexImage has failed");
6728
6729                                 /* Make comparison. */
6730                                 for (glw::GLuint k = 0; k < j - 1; ++k)
6731                                 {
6732                                         if (((glw::GLint)result[k + 1]) - ((glw::GLint)result[k]) < 0)
6733                                         {
6734                                                 m_context.getTestContext().getLog() << tcu::TestLog::Message
6735                                                                                                                         << "GenerateTextureMipmap unexpectedly generated improper "
6736                                                                                                                            "mipmap (not descending). Test fails."
6737                                                                                                                         << tcu::TestLog::EndMessage;
6738
6739                                                 is_ok = false;
6740
6741                                                 break;
6742                                         }
6743                                 }
6744                         }
6745                 }
6746         }
6747         catch (...)
6748         {
6749                 is_ok   = false;
6750                 is_error = true;
6751         }
6752
6753         /* Cleanup. */
6754         if (texture)
6755         {
6756                 gl.deleteTextures(1, &texture);
6757         }
6758
6759         if (DE_NULL != result)
6760         {
6761                 delete[] result;
6762         }
6763
6764         while (GL_NO_ERROR != gl.getError())
6765                 ;
6766
6767         /* Result's setup. */
6768         if (is_ok)
6769         {
6770                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
6771         }
6772         else
6773         {
6774                 if (is_error)
6775                 {
6776                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
6777                 }
6778                 else
6779                 {
6780                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
6781                 }
6782         }
6783
6784         return STOP;
6785 }
6786
6787 /** Reference data. */
6788 const glw::GLubyte GenerateMipmapTest::s_texture_data[] = {
6789         0,   1,   2,   3,   4,   5,   6,   7,   8,   9,   10,  11,  12,  13,  14,  15,  16,  17,  18,  19,  20,  21,
6790         22,  23,  24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,
6791         44,  45,  46,  47,  48,  49,  50,  51,  52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,  63,  64,  65,
6792         66,  67,  68,  69,  70,  71,  72,  73,  74,  75,  76,  77,  78,  79,  80,  81,  82,  83,  84,  85,  86,  87,
6793         88,  89,  90,  91,  92,  93,  94,  95,  96,  97,  98,  99,  100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
6794         110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131,
6795         132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153,
6796         154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
6797         176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197,
6798         198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219,
6799         220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241,
6800         242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
6801 };
6802
6803 /** Reference data parameters. */
6804 const glw::GLuint GenerateMipmapTest::s_texture_width    = 256;
6805 const glw::GLuint GenerateMipmapTest::s_texture_width_log = 8;
6806
6807 /******************************** Bind Unit Test Implementation   ********************************/
6808
6809 /** @brief Bind Unit Test constructor.
6810  *
6811  *  @param [in] context     OpenGL context.
6812  */
6813 BindUnitTest::BindUnitTest(deqp::Context& context)
6814         : deqp::TestCase(context, "textures_bind_unit", "Textures Bind Unit Test")
6815         , m_po(0)
6816         , m_fbo(0)
6817         , m_rbo(0)
6818         , m_vao(0)
6819         , m_result(DE_NULL)
6820 {
6821         m_to[0] = 0;
6822         m_to[1] = 0;
6823         m_to[2] = 0;
6824         m_to[3] = 0;
6825 }
6826
6827 /** @brief Bind Unit Test cases.
6828  *
6829  *  @return Iteration result.
6830  */
6831 tcu::TestNode::IterateResult BindUnitTest::iterate()
6832 {
6833         /* Get context setup. */
6834         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
6835         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
6836
6837         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
6838         {
6839                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
6840
6841                 return STOP;
6842         }
6843
6844         /* Running tests. */
6845         bool is_ok      = true;
6846         bool is_error = false;
6847
6848         try
6849         {
6850                 CreateProgram();
6851                 CreateTextures();
6852                 CreateFrambuffer();
6853                 CreateVertexArray();
6854                 is_ok &= Draw();
6855                 is_ok &= Check();
6856         }
6857         catch (...)
6858         {
6859                 is_ok   = false;
6860                 is_error = true;
6861         }
6862
6863         /* Cleanup. */
6864         CleanAll();
6865
6866         /* Result's setup. */
6867         if (is_ok)
6868         {
6869                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
6870         }
6871         else
6872         {
6873                 if (is_error)
6874                 {
6875                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
6876                 }
6877                 else
6878                 {
6879                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
6880                 }
6881         }
6882
6883         return STOP;
6884 }
6885
6886 /** @brief Create test program.
6887  */
6888 void BindUnitTest::CreateProgram()
6889 {
6890         /* Shortcut for GL functionality */
6891         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
6892
6893         struct Shader
6894         {
6895                 glw::GLchar const* source;
6896                 glw::GLenum const  type;
6897                 glw::GLuint                id;
6898         } shader[] = { { s_vertex_shader, GL_VERTEX_SHADER, 0 }, { s_fragment_shader, GL_FRAGMENT_SHADER, 0 } };
6899
6900         glw::GLuint const shader_count = sizeof(shader) / sizeof(shader[0]);
6901
6902         try
6903         {
6904                 /* Create program. */
6905                 m_po = gl.createProgram();
6906                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateProgram call failed.");
6907
6908                 /* Shader compilation. */
6909
6910                 for (glw::GLuint i = 0; i < shader_count; ++i)
6911                 {
6912                         if (DE_NULL != shader[i].source)
6913                         {
6914                                 shader[i].id = gl.createShader(shader[i].type);
6915
6916                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateShader call failed.");
6917
6918                                 gl.attachShader(m_po, shader[i].id);
6919
6920                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glAttachShader call failed.");
6921
6922                                 gl.shaderSource(shader[i].id, 1, &shader[i].source, NULL);
6923
6924                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource call failed.");
6925
6926                                 gl.compileShader(shader[i].id);
6927
6928                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader call failed.");
6929
6930                                 glw::GLint status = GL_FALSE;
6931
6932                                 gl.getShaderiv(shader[i].id, GL_COMPILE_STATUS, &status);
6933                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
6934
6935                                 if (GL_FALSE == status)
6936                                 {
6937                                         glw::GLint log_size = 0;
6938                                         gl.getShaderiv(shader[i].id, GL_INFO_LOG_LENGTH, &log_size);
6939                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
6940
6941                                         glw::GLchar* log_text = new glw::GLchar[log_size];
6942
6943                                         gl.getShaderInfoLog(shader[i].id, log_size, NULL, &log_text[0]);
6944
6945                                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "Shader compilation has failed.\n"
6946                                                                                                                 << "Shader type: " << glu::getShaderTypeStr(shader[i].type)
6947                                                                                                                 << "\n"
6948                                                                                                                 << "Shader compilation error log:\n"
6949                                                                                                                 << log_text << "\n"
6950                                                                                                                 << "Shader source code:\n"
6951                                                                                                                 << shader[i].source << "\n"
6952                                                                                                                 << tcu::TestLog::EndMessage;
6953
6954                                         delete[] log_text;
6955
6956                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog call failed.");
6957
6958                                         throw 0;
6959                                 }
6960                         }
6961                 }
6962
6963                 /* Link. */
6964                 gl.linkProgram(m_po);
6965
6966                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTransformFeedbackVaryings call failed.");
6967
6968                 glw::GLint status = GL_FALSE;
6969
6970                 gl.getProgramiv(m_po, GL_LINK_STATUS, &status);
6971
6972                 if (GL_TRUE == status)
6973                 {
6974                         for (glw::GLuint i = 0; i < shader_count; ++i)
6975                         {
6976                                 if (shader[i].id)
6977                                 {
6978                                         gl.detachShader(m_po, shader[i].id);
6979
6980                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glDetachShader call failed.");
6981                                 }
6982                         }
6983                 }
6984                 else
6985                 {
6986                         glw::GLint log_size = 0;
6987
6988                         gl.getProgramiv(m_po, GL_INFO_LOG_LENGTH, &log_size);
6989
6990                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv call failed.");
6991
6992                         glw::GLchar* log_text = new glw::GLchar[log_size];
6993
6994                         gl.getProgramInfoLog(m_po, log_size, NULL, &log_text[0]);
6995
6996                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "Program linkage has failed due to:\n"
6997                                                                                                 << log_text << "\n"
6998                                                                                                 << tcu::TestLog::EndMessage;
6999
7000                         delete[] log_text;
7001
7002                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramInfoLog call failed.");
7003
7004                         throw 0;
7005                 }
7006         }
7007         catch (...)
7008         {
7009                 if (m_po)
7010                 {
7011                         gl.deleteProgram(m_po);
7012
7013                         m_po = 0;
7014                 }
7015         }
7016
7017         for (glw::GLuint i = 0; i < shader_count; ++i)
7018         {
7019                 if (0 != shader[i].id)
7020                 {
7021                         gl.deleteShader(shader[i].id);
7022
7023                         shader[i].id = 0;
7024                 }
7025         }
7026
7027         if (0 == m_po)
7028         {
7029                 throw 0;
7030         }
7031 }
7032
7033 /** @brief Create texture.
7034  */
7035 void BindUnitTest::CreateTextures()
7036 {
7037         /* Shortcut for GL functionality. */
7038         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7039
7040         /* Prepare texture. */
7041         gl.genTextures(4, m_to);
7042         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
7043
7044         /* Setup pixel sotre modes.*/
7045         gl.pixelStorei(GL_UNPACK_ALIGNMENT, sizeof(glw::GLubyte));
7046         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
7047
7048         gl.pixelStorei(GL_PACK_ALIGNMENT, sizeof(glw::GLubyte));
7049         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
7050
7051         /* Red texture. */
7052         gl.bindTexture(GL_TEXTURE_2D, m_to[0]);
7053         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7054
7055         gl.texImage2D(GL_TEXTURE_2D, 0, GL_R8, s_texture_width, s_texture_height, 0, GL_RED, GL_UNSIGNED_BYTE,
7056                                   s_texture_data_r);
7057         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
7058
7059         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
7060         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
7061         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
7062
7063         /* Green texture. */
7064         gl.bindTexture(GL_TEXTURE_2D, m_to[1]);
7065         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7066
7067         gl.texImage2D(GL_TEXTURE_2D, 0, GL_R8, s_texture_width, s_texture_height, 0, GL_RED, GL_UNSIGNED_BYTE,
7068                                   s_texture_data_g);
7069         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
7070
7071         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
7072         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
7073         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
7074
7075         /* Blue texture. */
7076         gl.bindTexture(GL_TEXTURE_2D, m_to[2]);
7077         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7078
7079         gl.texImage2D(GL_TEXTURE_2D, 0, GL_R8, s_texture_width, s_texture_height, 0, GL_RED, GL_UNSIGNED_BYTE,
7080                                   s_texture_data_b);
7081         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
7082
7083         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
7084         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
7085         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
7086
7087         /* Alpha texture. */
7088         gl.bindTexture(GL_TEXTURE_2D, m_to[3]);
7089         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7090
7091         gl.texImage2D(GL_TEXTURE_2D, 0, GL_R8, s_texture_width, s_texture_height, 0, GL_RED, GL_UNSIGNED_BYTE,
7092                                   s_texture_data_a);
7093         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
7094
7095         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
7096         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
7097         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
7098 }
7099
7100 /** @brief Create framebuffer.
7101  */
7102 void BindUnitTest::CreateFrambuffer()
7103 {
7104         /* Shortcut for GL functionality. */
7105         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7106
7107         /* Prepare framebuffer. */
7108         gl.genFramebuffers(1, &m_fbo);
7109         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
7110
7111         gl.genRenderbuffers(1, &m_rbo);
7112         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
7113
7114         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
7115         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
7116
7117         gl.bindRenderbuffer(GL_RENDERBUFFER, m_rbo);
7118         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
7119
7120         gl.renderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, s_texture_width, s_texture_height);
7121         GLU_EXPECT_NO_ERROR(gl.getError(), "glRenderbufferStorage call failed.");
7122
7123         gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_rbo);
7124         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
7125
7126         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
7127         {
7128                 throw 0;
7129         }
7130
7131         gl.viewport(0, 0, s_texture_width, s_texture_height);
7132         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
7133
7134         /* Clear framebuffer's content. */
7135         gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
7136         GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
7137
7138         gl.clear(GL_COLOR_BUFFER_BIT);
7139         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
7140 }
7141
7142 /** @brief Create vertex array object.
7143  */
7144 void BindUnitTest::CreateVertexArray()
7145 {
7146         /* Shortcut for GL functionality. */
7147         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7148
7149         gl.genVertexArrays(1, &m_vao);
7150         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays call has failed.");
7151
7152         gl.bindVertexArray(m_vao);
7153         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray call has failed.");
7154 }
7155
7156 bool BindUnitTest::Draw()
7157 {
7158         /* Shortcut for GL functionality. */
7159         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7160
7161         /* Setup program. */
7162         gl.useProgram(m_po);
7163         GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram call has failed.");
7164
7165         /* Bind textures to proper units and setup program's samplers. */
7166         for (glw::GLuint i = 0; i < 4; ++i)
7167         {
7168                 /* Tested binding funcion. */
7169                 gl.bindTextureUnit(i, m_to[i]);
7170
7171                 /* Check for errors. */
7172                 glw::GLenum error = GL_NO_ERROR;
7173
7174                 if (GL_NO_ERROR != (error = gl.getError()))
7175                 {
7176                         m_context.getTestContext().getLog()
7177                                 << tcu::TestLog::Message << "BindTextureUnit unexpectedly generated error " << glu::getErrorStr(error)
7178                                 << " when binding texture " << m_to[i] << " to texture unit " << i << ". Test fails."
7179                                 << tcu::TestLog::EndMessage;
7180
7181                         return false;
7182                 }
7183
7184                 /* Sampler setup. */
7185                 gl.uniform1i(gl.getUniformLocation(m_po, s_fragment_shader_samplers[i]), i);
7186                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetUniformLocation or glUniform1i call has failed.");
7187         }
7188
7189         /* Draw call. */
7190         gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
7191         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays call has failed.");
7192
7193         return true;
7194 }
7195
7196 /** @brief Compare results with reference.
7197  *
7198  *  @return True if equal, false otherwise.
7199  */
7200 bool BindUnitTest::Check()
7201 {
7202         /* Shortcut for GL functionality. */
7203         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7204
7205         /* Setup storage for results. */
7206         m_result = new glw::GLubyte[s_texture_count_rgba];
7207
7208         /* Setup pixel sotre modes.*/
7209         gl.pixelStorei(GL_UNPACK_ALIGNMENT, sizeof(glw::GLubyte));
7210         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
7211
7212         gl.pixelStorei(GL_PACK_ALIGNMENT, sizeof(glw::GLubyte));
7213         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
7214
7215         /* Query framebuffer's image. */
7216         gl.readPixels(0, 0, s_texture_width, s_texture_height, GL_RGBA, GL_UNSIGNED_BYTE, m_result);
7217         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays call has failed.");
7218
7219         /* Compare values with reference. */
7220         for (glw::GLuint i = 0; i < s_texture_count_rgba; ++i)
7221         {
7222                 if (s_texture_data_rgba[i] != m_result[i])
7223                 {
7224                         m_context.getTestContext().getLog()
7225                                 << tcu::TestLog::Message << "Framebuffer data " << DataToString(s_texture_count_rgba, m_result)
7226                                 << " does not match the reference values " << DataToString(s_texture_count_rgba, s_texture_data_rgba)
7227                                 << "." << tcu::TestLog::EndMessage;
7228
7229                         return false;
7230                 }
7231         }
7232
7233         return true;
7234 }
7235
7236 /** @brief Clean GL objects, test variables and GL errors.
7237  */
7238 void BindUnitTest::CleanAll()
7239 {
7240         /* Shortcut for GL functionality. */
7241         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7242
7243         /* Release GL objects. */
7244         if (m_po)
7245         {
7246                 gl.useProgram(0);
7247
7248                 gl.deleteProgram(m_po);
7249
7250                 m_po = 0;
7251         }
7252
7253         if (m_to[0] || m_to[1] || m_to[2] || m_to[3])
7254         {
7255                 gl.deleteTextures(4, m_to);
7256
7257                 m_to[0] = 0;
7258                 m_to[1] = 0;
7259                 m_to[2] = 0;
7260                 m_to[3] = 0;
7261         }
7262
7263         if (m_fbo)
7264         {
7265                 gl.deleteFramebuffers(1, &m_fbo);
7266
7267                 m_fbo = 0;
7268         }
7269
7270         if (m_rbo)
7271         {
7272                 gl.deleteRenderbuffers(1, &m_rbo);
7273
7274                 m_rbo = 0;
7275         }
7276
7277         /* Release heap. */
7278         if (DE_NULL != m_result)
7279         {
7280                 delete[] m_result;
7281         }
7282
7283         /* Erros clean-up. */
7284         while (GL_NO_ERROR != gl.getError())
7285                 ;
7286 }
7287
7288 /** @brief Convert raw data into string for logging purposes.
7289  *
7290  *  @param [in] count      Count of the data.
7291  *  @param [in] data       Raw data.
7292  *
7293  *  @return String representation of data.
7294  */
7295 std::string BindUnitTest::DataToString(glw::GLuint count, const glw::GLubyte data[])
7296 {
7297         std::string data_str = "[";
7298
7299         for (glw::GLuint i = 0; i < count; ++i)
7300         {
7301                 std::stringstream int_sstream;
7302
7303                 int_sstream << unsigned(data[i]);
7304
7305                 data_str.append(int_sstream.str());
7306
7307                 if (i + 1 < count)
7308                 {
7309                         data_str.append(", ");
7310                 }
7311                 else
7312                 {
7313                         data_str.append("]");
7314                 }
7315         }
7316
7317         return data_str;
7318 }
7319
7320 /** Reference data and parameters. */
7321 const glw::GLubyte BindUnitTest::s_texture_data_r[]     = { 0, 4, 8, 12, 16, 20 };
7322 const glw::GLubyte BindUnitTest::s_texture_data_g[]     = { 1, 5, 9, 13, 17, 21 };
7323 const glw::GLubyte BindUnitTest::s_texture_data_b[]     = { 2, 6, 10, 14, 18, 22 };
7324 const glw::GLubyte BindUnitTest::s_texture_data_a[]     = { 3, 7, 11, 15, 19, 23 };
7325 const glw::GLubyte BindUnitTest::s_texture_data_rgba[] = { 0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11,
7326                                                                                                                    12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 };
7327 const glw::GLuint BindUnitTest::s_texture_width          = 2;
7328 const glw::GLuint BindUnitTest::s_texture_height         = 3;
7329 const glw::GLuint BindUnitTest::s_texture_count_rgba = sizeof(s_texture_data_rgba) / sizeof(s_texture_data_rgba[0]);
7330
7331 /* Vertex shader source code. */
7332 const glw::GLchar* BindUnitTest::s_vertex_shader = "#version 450\n"
7333                                                                                                    "\n"
7334                                                                                                    "void main()\n"
7335                                                                                                    "{\n"
7336                                                                                                    "    switch(gl_VertexID)\n"
7337                                                                                                    "    {\n"
7338                                                                                                    "        case 0:\n"
7339                                                                                                    "            gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
7340                                                                                                    "            break;\n"
7341                                                                                                    "        case 1:\n"
7342                                                                                                    "            gl_Position = vec4( 1.0, 1.0, 0.0, 1.0);\n"
7343                                                                                                    "            break;\n"
7344                                                                                                    "        case 2:\n"
7345                                                                                                    "            gl_Position = vec4(-1.0,-1.0, 0.0, 1.0);\n"
7346                                                                                                    "            break;\n"
7347                                                                                                    "        case 3:\n"
7348                                                                                                    "            gl_Position = vec4( 1.0,-1.0, 0.0, 1.0);\n"
7349                                                                                                    "            break;\n"
7350                                                                                                    "    }\n"
7351                                                                                                    "}\n";
7352
7353 /* Fragment shader source program. */
7354 const glw::GLchar* BindUnitTest::s_fragment_shader =
7355         "#version 450\n"
7356         "\n"
7357         "layout(pixel_center_integer) in vec4 gl_FragCoord;\n"
7358         "\n"
7359         "uniform sampler2D texture_input_r;\n"
7360         "uniform sampler2D texture_input_g;\n"
7361         "uniform sampler2D texture_input_b;\n"
7362         "uniform sampler2D texture_input_a;\n"
7363         "\n"
7364         "out     vec4      color_output;\n"
7365         "\n"
7366         "void main()\n"
7367         "{\n"
7368         "    color_output = vec4(texelFetch(texture_input_r, ivec2(gl_FragCoord.xy), 0).r,\n"
7369         "                        texelFetch(texture_input_g, ivec2(gl_FragCoord.xy), 0).r,\n"
7370         "                        texelFetch(texture_input_b, ivec2(gl_FragCoord.xy), 0).r,\n"
7371         "                        texelFetch(texture_input_a, ivec2(gl_FragCoord.xy), 0).r);\n"
7372         "}\n";
7373
7374 const glw::GLchar* BindUnitTest::s_fragment_shader_samplers[4] = { "texture_input_r", "texture_input_g",
7375                                                                                                                                    "texture_input_b", "texture_input_a" };
7376
7377 /******************************** Get Image Test Implementation   ********************************/
7378
7379 /** @brief Get Image Test constructor.
7380  *
7381  *  @param [in] context     OpenGL context.
7382  */
7383 GetImageTest::GetImageTest(deqp::Context& context)
7384         : deqp::TestCase(context, "textures_get_image", "Textures Get Image Test")
7385 {
7386         /* Intentionally left blank */
7387 }
7388
7389 /** Reference data. */
7390 const glw::GLubyte GetImageTest::s_texture_data[] = { 0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3,
7391                                                                                                           0xff, 0xff, 0xff, 0xff, 0xff, 0x88, 0x0,  0x15, 0xff, 0xed, 0x1c,
7392                                                                                                           0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff, 0xc8,
7393                                                                                                           0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff,
7394                                                                                                           0xb5, 0xe6, 0x1d, 0xff, 0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc,
7395                                                                                                           0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff };
7396
7397 /** Reference data (compressed). */
7398 const glw::GLubyte GetImageTest::s_texture_data_compressed[] = { 0x90, 0x2b, 0x8f, 0x0f, 0xfe, 0x0f, 0x98, 0x99,
7399                                                                                                                                  0x99, 0x99, 0x59, 0x8f, 0x8c, 0xa6, 0xb7, 0x71 };
7400
7401 /** Reference data parameters. */
7402 const glw::GLuint GetImageTest::s_texture_width                   = 4;
7403 const glw::GLuint GetImageTest::s_texture_height                  = 4;
7404 const glw::GLuint GetImageTest::s_texture_size                    = sizeof(s_texture_data);
7405 const glw::GLuint GetImageTest::s_texture_size_compressed = sizeof(s_texture_data_compressed);
7406 const glw::GLuint GetImageTest::s_texture_count                   = s_texture_size / sizeof(s_texture_data[0]);
7407 const glw::GLuint GetImageTest::s_texture_count_compressed =
7408         s_texture_size_compressed / sizeof(s_texture_data_compressed[0]);
7409
7410 /** @brief Get Image Test cases.
7411  *
7412  *  @return Iteration result.
7413  */
7414 tcu::TestNode::IterateResult GetImageTest::iterate()
7415 {
7416         /* Shortcut for GL functionality. */
7417         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7418
7419         /* Get context setup. */
7420         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
7421         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
7422
7423         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
7424         {
7425                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
7426
7427                 return STOP;
7428         }
7429
7430         /* Running tests. */
7431         bool is_ok      = true;
7432         bool is_error = false;
7433
7434         /* Objects. */
7435         glw::GLuint  texture                                                                       = 0;
7436         glw::GLubyte result[s_texture_count]                                       = {};
7437         glw::GLubyte result_compressed[s_texture_count_compressed] = {};
7438
7439         try
7440         {
7441                 /* Uncompressed case. */
7442                 {
7443                         /* Texture initiation. */
7444                         gl.genTextures(1, &texture);
7445                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
7446
7447                         gl.bindTexture(GL_TEXTURE_2D, texture);
7448                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7449
7450                         gl.texImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, s_texture_width, s_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
7451                                                   s_texture_data);
7452                         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
7453
7454                         /* Quering image with tested function. */
7455                         gl.getTextureImage(texture, 0, GL_RGBA, GL_UNSIGNED_BYTE, sizeof(result), result);
7456
7457                         /* Check for errors. */
7458                         glw::GLenum error = GL_NO_ERROR;
7459
7460                         if (GL_NO_ERROR != (error = gl.getError()))
7461                         {
7462                                 m_context.getTestContext().getLog()
7463                                         << tcu::TestLog::Message << "GetTextureImage unexpectedly generated error "
7464                                         << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
7465
7466                                 is_ok = false;
7467                         }
7468                         else
7469                         {
7470                                 /* No error, so compare images. */
7471                                 for (glw::GLuint i = 0; i < s_texture_count; ++i)
7472                                 {
7473                                         if (s_texture_data[i] != result[i])
7474                                         {
7475                                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "GetTextureImage returned "
7476                                                                                                                         << DataToString(s_texture_count, result) << ", but "
7477                                                                                                                         << DataToString(s_texture_count, s_texture_data)
7478                                                                                                                         << " was expected. Test fails." << tcu::TestLog::EndMessage;
7479
7480                                                 is_ok = false;
7481
7482                                                 break;
7483                                         }
7484                                 }
7485                         }
7486                 }
7487
7488                 /* Clean up texture .*/
7489                 gl.deleteTextures(1, &texture);
7490                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
7491
7492                 texture = 0;
7493
7494                 /* Compressed case. */
7495                 {
7496                         /* Texture initiation. */
7497                         gl.genTextures(1, &texture);
7498                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
7499
7500                         gl.bindTexture(GL_TEXTURE_2D, texture);
7501                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7502
7503                         gl.compressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_BPTC_UNORM, s_texture_width, s_texture_height,
7504                                                                         0, s_texture_size_compressed, s_texture_data_compressed);
7505                         GLU_EXPECT_NO_ERROR(gl.getError(), "glCompressedTexImage2D has failed");
7506
7507                         /* Quering image with tested function. */
7508                         gl.getCompressedTextureImage(texture, 0, s_texture_count_compressed * sizeof(result_compressed[0]),
7509                                                                                  result_compressed);
7510
7511                         /* Check for errors. */
7512                         glw::GLenum error = GL_NO_ERROR;
7513
7514                         if (GL_NO_ERROR != (error = gl.getError()))
7515                         {
7516                                 m_context.getTestContext().getLog()
7517                                         << tcu::TestLog::Message << "GetCompressedTextureImage unexpectedly generated error "
7518                                         << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
7519
7520                                 is_ok = false;
7521                         }
7522                         else
7523                         {
7524                                 /* No error, so compare images. */
7525                                 for (glw::GLuint i = 0; i < s_texture_count_compressed; ++i)
7526                                 {
7527                                         if (s_texture_data_compressed[i] != result_compressed[i])
7528                                         {
7529                                                 m_context.getTestContext().getLog()
7530                                                         << tcu::TestLog::Message << "GetCompressedTextureImage returned "
7531                                                         << DataToString(s_texture_count_compressed, result_compressed) << ", but "
7532                                                         << DataToString(s_texture_count_compressed, s_texture_data_compressed)
7533                                                         << " was expected. Test fails." << tcu::TestLog::EndMessage;
7534
7535                                                 is_ok = false;
7536
7537                                                 break;
7538                                         }
7539                                 }
7540                         }
7541                 }
7542         }
7543         catch (...)
7544         {
7545                 is_ok   = false;
7546                 is_error = true;
7547         }
7548
7549         /* Cleanup. */
7550         if (texture)
7551         {
7552                 gl.deleteTextures(1, &texture);
7553         }
7554
7555         /* Result's setup. */
7556         if (is_ok)
7557         {
7558                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
7559         }
7560         else
7561         {
7562                 if (is_error)
7563                 {
7564                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
7565                 }
7566                 else
7567                 {
7568                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7569                 }
7570         }
7571
7572         return STOP;
7573 }
7574
7575 /** @brief Convert raw data into string for logging purposes.
7576  *
7577  *  @param [in] count      Count of the data.
7578  *  @param [in] data       Raw data.
7579  *
7580  *  @return String representation of data.
7581  */
7582 std::string GetImageTest::DataToString(glw::GLuint count, const glw::GLubyte data[])
7583 {
7584         std::string data_str = "[";
7585
7586         for (glw::GLuint i = 0; i < count; ++i)
7587         {
7588                 std::stringstream int_sstream;
7589
7590                 int_sstream << unsigned(data[i]);
7591
7592                 data_str.append(int_sstream.str());
7593
7594                 if (i + 1 < count)
7595                 {
7596                         data_str.append(", ");
7597                 }
7598                 else
7599                 {
7600                         data_str.append("]");
7601                 }
7602         }
7603
7604         return data_str;
7605 }
7606
7607 /******************************** Get Level Parameter Test Implementation   ********************************/
7608
7609 /** @brief Get Level Parameter Test constructor.
7610  *
7611  *  @param [in] context     OpenGL context.
7612  */
7613 GetLevelParameterTest::GetLevelParameterTest(deqp::Context& context)
7614         : deqp::TestCase(context, "textures_get_level_parameter", "Textures Get Level Parameter Test")
7615 {
7616         /* Intentionally left blank */
7617 }
7618
7619 /** Reference data. */
7620 const glw::GLubyte GetLevelParameterTest::s_texture_data[] = {
7621         0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
7622         0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
7623         0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
7624         0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff,
7625
7626         0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
7627         0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
7628         0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
7629         0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff,
7630
7631         0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
7632         0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
7633         0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
7634         0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff,
7635
7636         0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
7637         0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
7638         0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
7639         0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff
7640 };
7641
7642 /** Reference data parameters. */
7643 const glw::GLuint GetLevelParameterTest::s_texture_width  = 4;
7644 const glw::GLuint GetLevelParameterTest::s_texture_height = 4;
7645 const glw::GLuint GetLevelParameterTest::s_texture_depth  = 4;
7646
7647 /** @brief Get Level Parameter Test cases.
7648  *
7649  *  @return Iteration result.
7650  */
7651 tcu::TestNode::IterateResult GetLevelParameterTest::iterate()
7652 {
7653         /* Shortcut for GL functionality. */
7654         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7655
7656         /* Get context setup. */
7657         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
7658         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
7659
7660         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
7661         {
7662                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
7663
7664                 return STOP;
7665         }
7666
7667         /* Running tests. */
7668         bool is_ok      = true;
7669         bool is_error = false;
7670
7671         /* Objects. */
7672         glw::GLuint texture = 0;
7673
7674         try
7675         {
7676                 /* Texture initiation. */
7677                 gl.genTextures(1, &texture);
7678                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
7679
7680                 gl.bindTexture(GL_TEXTURE_3D, texture);
7681                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7682
7683                 gl.texImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, s_texture_width, s_texture_height, s_texture_depth, 0, GL_RGBA,
7684                                           GL_UNSIGNED_BYTE, s_texture_data);
7685                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
7686
7687                 gl.texImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, s_texture_width / 2, s_texture_height / 2, s_texture_depth / 2, 0,
7688                                           GL_RGBA, GL_UNSIGNED_BYTE, s_texture_data);
7689                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
7690
7691                 static const glw::GLenum pnames[] = {
7692                         GL_TEXTURE_WIDTH,         GL_TEXTURE_HEIGHT,     GL_TEXTURE_DEPTH,               GL_TEXTURE_INTERNAL_FORMAT,
7693                         GL_TEXTURE_RED_TYPE,   GL_TEXTURE_GREEN_TYPE, GL_TEXTURE_BLUE_TYPE,  GL_TEXTURE_ALPHA_TYPE,
7694                         GL_TEXTURE_DEPTH_TYPE, GL_TEXTURE_RED_SIZE,   GL_TEXTURE_GREEN_SIZE, GL_TEXTURE_BLUE_SIZE,
7695                         GL_TEXTURE_ALPHA_SIZE, GL_TEXTURE_DEPTH_SIZE, GL_TEXTURE_COMPRESSED
7696                 };
7697                 static const glw::GLuint pnames_count = sizeof(pnames) / sizeof(pnames[0]);
7698
7699                 /* Test GetTextureLevelParameteriv. */
7700                 for (glw::GLuint i = 0; i < 2 /* levels */; ++i)
7701                 {
7702                         for (glw::GLuint j = 0; j < pnames_count; ++j)
7703                         {
7704                                 glw::GLint result_legacy = 0;
7705                                 glw::GLint result_dsa   = 0;
7706
7707                                 /* Quering reference value. */
7708                                 gl.getTexLevelParameteriv(GL_TEXTURE_3D, i, pnames[j], &result_legacy);
7709                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
7710
7711                                 /* Quering using DSA function. */
7712                                 gl.getTextureLevelParameteriv(texture, i, pnames[j], &result_dsa);
7713
7714                                 /* Check for errors. */
7715                                 glw::GLenum error = GL_NO_ERROR;
7716
7717                                 if (GL_NO_ERROR != (error = gl.getError()))
7718                                 {
7719                                         m_context.getTestContext().getLog()
7720                                                 << tcu::TestLog::Message << "GetTextureLevelParameteriv unexpectedly generated error "
7721                                                 << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
7722
7723                                         is_ok = false;
7724                                 }
7725                                 else
7726                                 {
7727                                         /* Compare values. */
7728                                         if (result_legacy != result_dsa)
7729                                         {
7730                                                 m_context.getTestContext().getLog()
7731                                                         << tcu::TestLog::Message << "For parameter name "
7732                                                         << glu::getTextureLevelParameterStr(pnames[j]) << " GetTextureLevelParameteriv returned "
7733                                                         << result_dsa << ", but reference value (queried using GetTexLevelParameteriv) was "
7734                                                         << result_legacy << ". Test fails." << tcu::TestLog::EndMessage;
7735
7736                                                 is_ok = false;
7737                                         }
7738                                 }
7739                         }
7740                 }
7741
7742                 /* Test GetTextureLevelParameterfv. */
7743                 for (glw::GLuint i = 0; i < 2 /* levels */; ++i)
7744                 {
7745                         for (glw::GLuint j = 0; j < pnames_count; ++j)
7746                         {
7747                                 glw::GLfloat result_legacy = 0.f;
7748                                 glw::GLfloat result_dsa = 0.f;
7749
7750                                 /* Quering reference value. */
7751                                 gl.getTexLevelParameterfv(GL_TEXTURE_3D, i, pnames[j], &result_legacy);
7752                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameterfv has failed");
7753
7754                                 /* Quering using DSA function. */
7755                                 gl.getTextureLevelParameterfv(texture, i, pnames[j], &result_dsa);
7756
7757                                 /* Check for errors. */
7758                                 glw::GLenum error = GL_NO_ERROR;
7759
7760                                 if (GL_NO_ERROR != (error = gl.getError()))
7761                                 {
7762                                         m_context.getTestContext().getLog()
7763                                                 << tcu::TestLog::Message << "GetTextureLevelParameterfv unexpectedly generated error "
7764                                                 << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
7765
7766                                         is_ok = false;
7767                                 }
7768                                 else
7769                                 {
7770                                         /* Compare values. */
7771                                         if (de::abs(result_legacy - result_dsa) > 0.125 /* Precision. */)
7772                                         {
7773                                                 m_context.getTestContext().getLog()
7774                                                         << tcu::TestLog::Message << "For parameter name "
7775                                                         << glu::getTextureLevelParameterStr(pnames[j]) << " GetTextureLevelParameterfv returned "
7776                                                         << result_dsa << ", but reference value (queried using GetTexLevelParameterfv) was "
7777                                                         << result_legacy << ". Test fails." << tcu::TestLog::EndMessage;
7778
7779                                                 is_ok = false;
7780                                         }
7781                                 }
7782                         }
7783                 }
7784         }
7785         catch (...)
7786         {
7787                 is_ok   = false;
7788                 is_error = true;
7789         }
7790
7791         /* Cleanup. */
7792         if (texture)
7793         {
7794                 gl.deleteTextures(1, &texture);
7795         }
7796
7797         while (GL_NO_ERROR != gl.getError())
7798                 ;
7799
7800         /* Result's setup. */
7801         if (is_ok)
7802         {
7803                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
7804         }
7805         else
7806         {
7807                 if (is_error)
7808                 {
7809                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
7810                 }
7811                 else
7812                 {
7813                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7814                 }
7815         }
7816
7817         return STOP;
7818 }
7819
7820 /*********************************** Errors Utility Class *****************************************************/
7821
7822 /** @brief Check for errors and log.
7823  *
7824  *  @param [in] context             Test's context.
7825  *  @param [in] expected_error      Expected error value.
7826  *  @param [in] function_name       Name of the function (to be logged).
7827  *  @param [in] log                 Log message.
7828  *
7829  *  @return True if error is equal to expected, false otherwise.
7830  */
7831 bool ErrorsUtilities::CheckErrorAndLog(deqp::Context& context, glw::GLuint expected_error,
7832                                                                            const glw::GLchar* function_name, const glw::GLchar* log)
7833 {
7834         /* Shortcut for GL functionality. */
7835         const glw::Functions& gl = context.getRenderContext().getFunctions();
7836
7837         /* Check error. */
7838         glw::GLenum error = GL_NO_ERROR;
7839
7840         if (expected_error != (error = gl.getError()))
7841         {
7842                 context.getTestContext().getLog() << tcu::TestLog::Message << function_name << " generated error "
7843                                                                                   << glu::getErrorStr(error) << " but, " << glu::getErrorStr(expected_error)
7844                                                                                   << " was expected if " << log << tcu::TestLog::EndMessage;
7845
7846                 return false;
7847         }
7848
7849         return true;
7850 }
7851
7852 /******************************** Creation Errors Test Implementation   ********************************/
7853
7854 /** @brief Creation Errors Test constructor.
7855  *
7856  *  @param [in] context     OpenGL context.
7857  */
7858 CreationErrorsTest::CreationErrorsTest(deqp::Context& context)
7859         : deqp::TestCase(context, "textures_creation_errors", "Texture Objects Creation Errors Test")
7860 {
7861         /* Intentionally left blank. */
7862 }
7863
7864 /** @brief Iterate Creation Errors Test cases.
7865  *
7866  *  @return Iteration result.
7867  */
7868 tcu::TestNode::IterateResult CreationErrorsTest::iterate()
7869 {
7870         /* Shortcut for GL functionality. */
7871         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7872
7873         /* Get context setup. */
7874         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
7875         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
7876
7877         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
7878         {
7879                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
7880
7881                 return STOP;
7882         }
7883
7884         /* Running tests. */
7885         bool is_ok      = true;
7886         bool is_error = false;
7887
7888         /* Textures' objects */
7889         glw::GLuint texture = 0;
7890
7891         try
7892         {
7893                 /* Not a target test. */
7894                 gl.createTextures(NotATarget(), 1, &texture);
7895                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glCreateTextures",
7896                                                                   "target is not one of the allowable values.");
7897
7898                 if (texture)
7899                 {
7900                         gl.deleteTextures(1, &texture);
7901
7902                         texture = 0;
7903                 }
7904
7905                 /* Negative number of textures. */
7906                 gl.createTextures(GL_TEXTURE_2D, -1, &texture);
7907                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCreateTextures", "n is negative.");
7908         }
7909         catch (...)
7910         {
7911                 is_ok   = false;
7912                 is_error = true;
7913         }
7914
7915         /* Cleanup. */
7916         if (texture)
7917         {
7918                 gl.deleteTextures(1, &texture);
7919         }
7920
7921         /* Errors clean up. */
7922         while (gl.getError())
7923                 ;
7924
7925         /* Result's setup. */
7926         if (is_ok)
7927         {
7928                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
7929         }
7930         else
7931         {
7932                 if (is_error)
7933                 {
7934                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
7935                 }
7936                 else
7937                 {
7938                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7939                 }
7940         }
7941
7942         return STOP;
7943 }
7944
7945 /** @brief Function retruns enum which is not a texture target.
7946  */
7947 glw::GLenum CreationErrorsTest::NotATarget()
7948 {
7949         static const glw::GLenum texture_targets[] = { GL_TEXTURE_1D,
7950                                                                                                    GL_TEXTURE_2D,
7951                                                                                                    GL_TEXTURE_3D,
7952                                                                                                    GL_TEXTURE_1D_ARRAY,
7953                                                                                                    GL_TEXTURE_2D_ARRAY,
7954                                                                                                    GL_TEXTURE_RECTANGLE,
7955                                                                                                    GL_TEXTURE_CUBE_MAP,
7956                                                                                                    GL_TEXTURE_CUBE_MAP_ARRAY,
7957                                                                                                    GL_TEXTURE_BUFFER,
7958                                                                                                    GL_TEXTURE_2D_MULTISAMPLE,
7959                                                                                                    GL_TEXTURE_2D_MULTISAMPLE_ARRAY };
7960
7961         glw::GLenum not_a_target = 0;
7962         bool            is_target       = true;
7963
7964         while (is_target)
7965         {
7966                 not_a_target++;
7967
7968                 is_target = false;
7969
7970                 for (glw::GLuint i = 0; i < sizeof(texture_targets) / sizeof(texture_targets[0]); ++i)
7971                 {
7972                         if (texture_targets[i] == not_a_target)
7973                         {
7974                                 is_target = true;
7975                                 break;
7976                         }
7977                 }
7978         }
7979
7980         return not_a_target;
7981 }
7982
7983 /******************************** Texture Buffer Errors Test Implementation   ********************************/
7984
7985 /** @brief Texture Buffer Errors Test constructor.
7986  *
7987  *  @param [in] context     OpenGL context.
7988  */
7989 BufferErrorsTest::BufferErrorsTest(deqp::Context& context)
7990         : deqp::TestCase(context, "textures_buffer_errors", "Texture Buffer Errors Test")
7991 {
7992         /* Intentionally left blank. */
7993 }
7994
7995 /** @brief Iterate Texture Buffer Errors Test cases.
7996  *
7997  *  @return Iteration result.
7998  */
7999 tcu::TestNode::IterateResult BufferErrorsTest::iterate()
8000 {
8001         /* Shortcut for GL functionality. */
8002         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8003
8004         /* Get context setup. */
8005         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
8006         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
8007
8008         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
8009         {
8010                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
8011
8012                 return STOP;
8013         }
8014
8015         /* Running tests. */
8016         bool is_ok      = true;
8017         bool is_error = false;
8018
8019         /* Textures' objects */
8020         glw::GLuint texture_buffer = 0;
8021         glw::GLuint texture_1D   = 0;
8022         glw::GLuint buffer                 = 0;
8023
8024         static const glw::GLubyte data[4]   = { 1, 2, 3, 4 };
8025         static const glw::GLuint  data_size = sizeof(data);
8026
8027         try
8028         {
8029                 /* Auxiliary objects setup. */
8030                 gl.createTextures(GL_TEXTURE_BUFFER, 1, &texture_buffer);
8031                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8032
8033                 gl.createTextures(GL_TEXTURE_1D, 1, &texture_1D);
8034                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8035
8036                 gl.createBuffers(1, &buffer);
8037                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateBuffers has failed");
8038
8039                 gl.namedBufferData(buffer, data_size, data, GL_STATIC_COPY);
8040                 GLU_EXPECT_NO_ERROR(gl.getError(), "glNamedBufferData has failed");
8041
8042                 /*  Check that INVALID_OPERATION is generated by glTextureBuffer if texture
8043                  is not the name of an existing texture object. */
8044                 {
8045                         glw::GLuint not_a_texture = 0;
8046
8047                         while (gl.isTexture(++not_a_texture))
8048                                 ;
8049                         GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed");
8050
8051                         gl.textureBuffer(not_a_texture, GL_RGBA8, buffer);
8052
8053                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureBuffer",
8054                                                                           "texture is not the name of an existing texture object.");
8055                 }
8056
8057                 /*  Check that INVALID_ENUM is generated by glTextureBuffer if the effective
8058                  target of texture is not TEXTURE_BUFFER. */
8059                 {
8060                         gl.textureBuffer(texture_1D, GL_RGBA8, buffer);
8061
8062                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureBuffer",
8063                                                                           "the effective target of texture is not TEXTURE_BUFFER.");
8064                 }
8065
8066                 /*  Check that INVALID_ENUM is generated if internalformat is not one of the
8067                  sized internal formats described above. */
8068                 {
8069                         gl.textureBuffer(texture_buffer, GL_COMPRESSED_SIGNED_RED_RGTC1, buffer);
8070
8071                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureBuffer",
8072                                                                           "internalformat is not one of the sized internal formats described above..");
8073                 }
8074
8075                 /*  Check that INVALID_OPERATION is generated if buffer is not zero and is
8076                  not the name of an existing buffer object. */
8077                 {
8078                         glw::GLuint not_a_buffer = 0;
8079
8080                         while (gl.isBuffer(++not_a_buffer))
8081                                 ;
8082                         GLU_EXPECT_NO_ERROR(gl.getError(), "glIsBuffer has failed");
8083
8084                         gl.textureBuffer(texture_buffer, GL_RGBA8, not_a_buffer);
8085
8086                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureBuffer",
8087                                                                           "buffer is not zero and is not the name of an existing buffer object.");
8088                 }
8089         }
8090         catch (...)
8091         {
8092                 is_ok   = false;
8093                 is_error = true;
8094         }
8095
8096         /* Cleanup. */
8097         if (texture_1D)
8098         {
8099                 gl.deleteTextures(1, &texture_1D);
8100         }
8101
8102         if (texture_buffer)
8103         {
8104                 gl.deleteTextures(1, &texture_buffer);
8105         }
8106
8107         if (buffer)
8108         {
8109                 gl.deleteBuffers(1, &buffer);
8110         }
8111
8112         /* Errors clean up. */
8113         while (gl.getError())
8114                 ;
8115
8116         /* Result's setup. */
8117         if (is_ok)
8118         {
8119                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
8120         }
8121         else
8122         {
8123                 if (is_error)
8124                 {
8125                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
8126                 }
8127                 else
8128                 {
8129                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
8130                 }
8131         }
8132
8133         return STOP;
8134 }
8135
8136 /******************************** Texture Buffer Range Errors Test Implementation   ********************************/
8137
8138 /** @brief Texture Buffer Range Errors Test constructor.
8139  *
8140  *  @param [in] context     OpenGL context.
8141  */
8142 BufferRangeErrorsTest::BufferRangeErrorsTest(deqp::Context& context)
8143         : deqp::TestCase(context, "textures_buffer_range_errors", "Texture Buffer Range Errors Test")
8144 {
8145         /* Intentionally left blank. */
8146 }
8147
8148 /** @brief Iterate Texture Buffer Range Errors Test cases.
8149  *
8150  *  @return Iteration result.
8151  */
8152 tcu::TestNode::IterateResult BufferRangeErrorsTest::iterate()
8153 {
8154         /* Shortcut for GL functionality. */
8155         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8156
8157         /* Get context setup. */
8158         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
8159         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
8160
8161         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
8162         {
8163                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
8164
8165                 return STOP;
8166         }
8167
8168         /* Running tests. */
8169         bool is_ok      = true;
8170         bool is_error = false;
8171
8172         /* Textures' objects */
8173         glw::GLuint texture_buffer = 0;
8174         glw::GLuint texture_1D   = 0;
8175         glw::GLuint buffer                 = 0;
8176
8177         static const glw::GLubyte data[4]   = { 1, 2, 3, 4 };
8178         static const glw::GLuint  data_size = sizeof(data);
8179
8180         try
8181         {
8182                 /* Auxiliary objects setup. */
8183                 gl.createTextures(GL_TEXTURE_BUFFER, 1, &texture_buffer);
8184                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8185
8186                 gl.createTextures(GL_TEXTURE_1D, 1, &texture_1D);
8187                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8188
8189                 gl.createBuffers(1, &buffer);
8190                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateBuffers has failed");
8191
8192                 gl.namedBufferData(buffer, data_size, data, GL_STATIC_COPY);
8193                 GLU_EXPECT_NO_ERROR(gl.getError(), "glNamedBufferData has failed");
8194
8195                 /*  Check that INVALID_OPERATION is generated by TextureBufferRange if
8196                  texture is not the name of an existing texture object.*/
8197                 {
8198                         glw::GLuint not_a_texture = 0;
8199
8200                         while (gl.isTexture(++not_a_texture))
8201                                 ;
8202                         GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed");
8203
8204                         gl.textureBufferRange(not_a_texture, GL_RGBA8, buffer, 0, data_size);
8205
8206                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureBufferRange",
8207                                                                           "texture is not the name of an existing texture object.");
8208                 }
8209
8210                 /*  Check that INVALID_ENUM is generated by TextureBufferRange if the
8211                  effective target of texture is not TEXTURE_BUFFER. */
8212                 {
8213                         gl.textureBufferRange(texture_1D, GL_RGBA8, buffer, 0, data_size);
8214
8215                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureBufferRange",
8216                                                                           "the effective target of texture is not TEXTURE_BUFFER.");
8217                 }
8218
8219                 /*  Check that INVALID_ENUM is generated by TextureBufferRange if
8220                  internalformat is not one of the sized internal formats described above. */
8221                 {
8222                         gl.textureBufferRange(texture_buffer, GL_COMPRESSED_SIGNED_RED_RGTC1, buffer, 0, data_size);
8223
8224                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureBufferRange",
8225                                                                           "internalformat is not one of the supported sized internal formats.");
8226                 }
8227
8228                 /*  Check that INVALID_OPERATION is generated by TextureBufferRange if
8229                  buffer is not zero and is not the name of an existing buffer object. */
8230                 {
8231                         glw::GLuint not_a_buffer = 0;
8232
8233                         while (gl.isBuffer(++not_a_buffer))
8234                                 ;
8235                         GLU_EXPECT_NO_ERROR(gl.getError(), "glIsBuffer has failed");
8236
8237                         gl.textureBufferRange(texture_buffer, GL_RGBA8, not_a_buffer, 0, data_size);
8238
8239                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureBufferRange",
8240                                                                           "buffer is not zero and is not the name of an existing buffer object.");
8241                 }
8242
8243                 /* Check that INVALID_VALUE is generated by TextureBufferRange if offset
8244                  is negative, if size is less than or equal to zero, or if offset + size
8245                  is greater than the value of BUFFER_SIZE for buffer. */
8246                 {
8247                         gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, -1, data_size);
8248
8249                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureBufferRange", "offset is negative.");
8250
8251                         gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, 0, 0);
8252
8253                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureBufferRange", "size is zero.");
8254
8255                         gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, 0, -1);
8256
8257                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureBufferRange", "size is negative.");
8258
8259                         gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, 0, data_size * 16);
8260
8261                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureBufferRange",
8262                                                                           "size is greater than the value of BUFFER_SIZE for buffer.");
8263                 }
8264
8265                 /* Check that INVALID_VALUE is generated by TextureBufferRange if offset is
8266                  not an integer multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT. */
8267                 {
8268                         glw::GLint gl_texture_buffer_offset_alignment = 0;
8269
8270                         gl.getIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, &gl_texture_buffer_offset_alignment);
8271
8272                         /* If alignmet is 1 we cannot do anything. Error situtation is impossible then. */
8273                         if (gl_texture_buffer_offset_alignment > 1)
8274                         {
8275                                 gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, 1, data_size - 1);
8276
8277                                 is_ok &= CheckErrorAndLog(
8278                                         m_context, GL_INVALID_VALUE, "glTextureBufferRange",
8279                                         "offset is not an integer multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT.");
8280                         }
8281                 }
8282         }
8283         catch (...)
8284         {
8285                 is_ok   = false;
8286                 is_error = true;
8287         }
8288
8289         /* Cleanup. */
8290         if (texture_1D)
8291         {
8292                 gl.deleteTextures(1, &texture_1D);
8293         }
8294
8295         if (texture_buffer)
8296         {
8297                 gl.deleteTextures(1, &texture_buffer);
8298         }
8299
8300         if (buffer)
8301         {
8302                 gl.deleteBuffers(1, &buffer);
8303         }
8304
8305         /* Errors clean up. */
8306         while (gl.getError())
8307                 ;
8308
8309         /* Result's setup. */
8310         if (is_ok)
8311         {
8312                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
8313         }
8314         else
8315         {
8316                 if (is_error)
8317                 {
8318                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
8319                 }
8320                 else
8321                 {
8322                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
8323                 }
8324         }
8325
8326         return STOP;
8327 }
8328
8329 /******************************** Texture Storage Errors Test Implementation   ********************************/
8330
8331 /** @brief Texture Storage Errors Test constructor.
8332  *
8333  *  @param [in] context     OpenGL context.
8334  */
8335 StorageErrorsTest::StorageErrorsTest(deqp::Context& context)
8336         : deqp::TestCase(context, "textures_storage_errors", "Texture Storage Errors Test")
8337         , m_to_1D(0)
8338         , m_to_1D_array(0)
8339         , m_to_2D(0)
8340         , m_to_2D_array(0)
8341         , m_to_3D(0)
8342         , m_to_2D_ms(0)
8343         , m_to_2D_ms_immutable(0)
8344         , m_to_3D_ms(0)
8345         , m_to_3D_ms_immutable(0)
8346         , m_to_invalid(0)
8347         , m_internalformat_invalid(0)
8348         , m_max_texture_size(1)
8349         , m_max_samples(1)
8350         , m_max_array_texture_layers(1)
8351 {
8352         /* Intentionally left blank. */
8353 }
8354
8355 /** @brief Iterate Texture Storage Errors Test cases.
8356  *
8357  *  @return Iteration result.
8358  */
8359 tcu::TestNode::IterateResult StorageErrorsTest::iterate()
8360 {
8361         /* Get context setup. */
8362         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
8363         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
8364
8365         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
8366         {
8367                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
8368
8369                 return STOP;
8370         }
8371
8372         /* Running tests. */
8373         bool is_ok      = true;
8374         bool is_error = false;
8375
8376         try
8377         {
8378                 Prepare();
8379
8380                 is_ok &= Test1D();
8381                 is_ok &= Test2D();
8382                 is_ok &= Test3D();
8383                 is_ok &= Test2DMultisample();
8384                 is_ok &= Test3DMultisample();
8385         }
8386         catch (...)
8387         {
8388                 is_ok   = false;
8389                 is_error = true;
8390         }
8391
8392         /* Cleanup. */
8393         Clean();
8394
8395         /* Result's setup. */
8396         if (is_ok)
8397         {
8398                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
8399         }
8400         else
8401         {
8402                 if (is_error)
8403                 {
8404                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
8405                 }
8406                 else
8407                 {
8408                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
8409                 }
8410         }
8411
8412         return STOP;
8413 }
8414
8415 /** @brief Prepare test objects.
8416  */
8417 void StorageErrorsTest::Prepare()
8418 {
8419         /* Shortcut for GL functionality. */
8420         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8421
8422         /* Auxiliary objects setup. */
8423
8424         /* 1D */
8425         gl.createTextures(GL_TEXTURE_1D, 1, &m_to_1D);
8426         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8427
8428         /* 1D ARRAY */
8429         gl.createTextures(GL_TEXTURE_1D_ARRAY, 1, &m_to_1D_array);
8430         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8431
8432         /* 2D */
8433         gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D);
8434         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8435
8436         /* 2D ARRAY */
8437         gl.createTextures(GL_TEXTURE_2D_ARRAY, 1, &m_to_2D_array);
8438         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8439
8440         /* 3D */
8441         gl.createTextures(GL_TEXTURE_3D, 1, &m_to_3D);
8442         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8443
8444         /* 2D Multisample */
8445         gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &m_to_2D_ms);
8446         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8447
8448         /* 2D Multisample with storage */
8449         gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &m_to_2D_ms_immutable);
8450         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8451
8452         gl.textureStorage2DMultisample(m_to_2D_ms_immutable, 1, GL_R8, 16, 16, false);
8453         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2DMultisample has failed");
8454
8455         /* 3D Multisample */
8456         gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 1, &m_to_3D_ms);
8457         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8458
8459         /* 3D Multisample with storage */
8460         gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 1, &m_to_3D_ms_immutable);
8461         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8462
8463         gl.textureStorage3DMultisample(m_to_3D_ms_immutable, 1, GL_R8, 16, 16, 16, false);
8464         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2DMultisample has failed");
8465
8466         /* Invalid values */
8467
8468         /* invalid texture object */
8469         while (gl.isTexture(++m_to_invalid))
8470                 ;
8471         GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed");
8472
8473         /* invalid internal format */
8474         static const glw::GLenum all_internal_formats[] = { GL_R8,
8475                                                                                                                 GL_R8_SNORM,
8476                                                                                                                 GL_R16,
8477                                                                                                                 GL_R16_SNORM,
8478                                                                                                                 GL_RG8,
8479                                                                                                                 GL_RG8_SNORM,
8480                                                                                                                 GL_RG16,
8481                                                                                                                 GL_RG16_SNORM,
8482                                                                                                                 GL_R3_G3_B2,
8483                                                                                                                 GL_RGB4,
8484                                                                                                                 GL_RGB5,
8485                                                                                                                 GL_RGB565,
8486                                                                                                                 GL_RGB8,
8487                                                                                                                 GL_RGB8_SNORM,
8488                                                                                                                 GL_RGB10,
8489                                                                                                                 GL_RGB12,
8490                                                                                                                 GL_RGB16,
8491                                                                                                                 GL_RGB16_SNORM,
8492                                                                                                                 GL_RGBA2,
8493                                                                                                                 GL_RGBA4,
8494                                                                                                                 GL_RGB5_A1,
8495                                                                                                                 GL_RGBA8,
8496                                                                                                                 GL_RGBA8_SNORM,
8497                                                                                                                 GL_RGB10_A2,
8498                                                                                                                 GL_RGB10_A2UI,
8499                                                                                                                 GL_RGBA12,
8500                                                                                                                 GL_RGBA16,
8501                                                                                                                 GL_RGBA16_SNORM,
8502                                                                                                                 GL_SRGB8,
8503                                                                                                                 GL_SRGB8_ALPHA8,
8504                                                                                                                 GL_R16F,
8505                                                                                                                 GL_RG16F,
8506                                                                                                                 GL_RGB16F,
8507                                                                                                                 GL_RGBA16F,
8508                                                                                                                 GL_R32F,
8509                                                                                                                 GL_RG32F,
8510                                                                                                                 GL_RGB32F,
8511                                                                                                                 GL_RGBA32F,
8512                                                                                                                 GL_R11F_G11F_B10F,
8513                                                                                                                 GL_RGB9_E5,
8514                                                                                                                 GL_R8I,
8515                                                                                                                 GL_R8UI,
8516                                                                                                                 GL_R16I,
8517                                                                                                                 GL_R16UI,
8518                                                                                                                 GL_R32I,
8519                                                                                                                 GL_R32UI,
8520                                                                                                                 GL_RG8I,
8521                                                                                                                 GL_RG8UI,
8522                                                                                                                 GL_RG16I,
8523                                                                                                                 GL_RG16UI,
8524                                                                                                                 GL_RG32I,
8525                                                                                                                 GL_RG32UI,
8526                                                                                                                 GL_RGB8I,
8527                                                                                                                 GL_RGB8UI,
8528                                                                                                                 GL_RGB16I,
8529                                                                                                                 GL_RGB16UI,
8530                                                                                                                 GL_RGB32I,
8531                                                                                                                 GL_RGB32UI,
8532                                                                                                                 GL_RGBA8I,
8533                                                                                                                 GL_RGBA8UI,
8534                                                                                                                 GL_RGBA16I,
8535                                                                                                                 GL_RGBA16UI,
8536                                                                                                                 GL_RGBA32I,
8537                                                                                                                 GL_RGBA32UI,
8538                                                                                                                 GL_COMPRESSED_RED,
8539                                                                                                                 GL_COMPRESSED_RG,
8540                                                                                                                 GL_COMPRESSED_RGB,
8541                                                                                                                 GL_COMPRESSED_RGBA,
8542                                                                                                                 GL_COMPRESSED_SRGB,
8543                                                                                                                 GL_COMPRESSED_SRGB_ALPHA,
8544                                                                                                                 GL_COMPRESSED_RED_RGTC1,
8545                                                                                                                 GL_COMPRESSED_SIGNED_RED_RGTC1,
8546                                                                                                                 GL_COMPRESSED_RG_RGTC2,
8547                                                                                                                 GL_COMPRESSED_SIGNED_RG_RGTC2,
8548                                                                                                                 GL_COMPRESSED_RGBA_BPTC_UNORM,
8549                                                                                                                 GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM,
8550                                                                                                                 GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT,
8551                                                                                                                 GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT,
8552                                                                                                                 GL_COMPRESSED_RGB8_ETC2,
8553                                                                                                                 GL_COMPRESSED_SRGB8_ETC2,
8554                                                                                                                 GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
8555                                                                                                                 GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
8556                                                                                                                 GL_COMPRESSED_RGBA8_ETC2_EAC,
8557                                                                                                                 GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
8558                                                                                                                 GL_COMPRESSED_R11_EAC,
8559                                                                                                                 GL_COMPRESSED_SIGNED_R11_EAC,
8560                                                                                                                 GL_COMPRESSED_RG11_EAC,
8561                                                                                                                 GL_COMPRESSED_SIGNED_RG11_EAC,
8562                                                                                                                 GL_DEPTH_COMPONENT16,
8563                                                                                                                 GL_DEPTH_COMPONENT24,
8564                                                                                                                 GL_DEPTH_COMPONENT32,
8565                                                                                                                 GL_DEPTH_COMPONENT32F,
8566                                                                                                                 GL_DEPTH24_STENCIL8,
8567                                                                                                                 GL_DEPTH32F_STENCIL8,
8568                                                                                                                 GL_STENCIL_INDEX1,
8569                                                                                                                 GL_STENCIL_INDEX4,
8570                                                                                                                 GL_STENCIL_INDEX8,
8571                                                                                                                 GL_STENCIL_INDEX16 };
8572
8573         static const glw::GLuint all_internal_formats_count =
8574                 sizeof(all_internal_formats) / sizeof(all_internal_formats[0]);
8575
8576         bool is_valid                    = true;
8577         m_internalformat_invalid = 0;
8578
8579         while (is_valid)
8580         {
8581                 is_valid = false;
8582                 m_internalformat_invalid++;
8583                 for (glw::GLuint i = 0; i < all_internal_formats_count; ++i)
8584                 {
8585                         if (all_internal_formats[i] == m_internalformat_invalid)
8586                         {
8587                                 is_valid = true;
8588                                 break;
8589                         }
8590                 }
8591         }
8592
8593         /* Maximum texture size.*/
8594         gl.getIntegerv(GL_MAX_TEXTURE_SIZE, &m_max_texture_size);
8595         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
8596
8597         /* Maximum number of samples. */
8598         gl.getIntegerv(GL_MAX_SAMPLES, &m_max_samples);
8599         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
8600
8601         /* Maximum number of array texture layers. */
8602         gl.getIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &m_max_array_texture_layers);
8603         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
8604 }
8605
8606 /** @brief Test TextureStorage1D
8607  *
8608  *  @return Test result.
8609  */
8610 bool StorageErrorsTest::Test1D()
8611 {
8612         /* Shortcut for GL functionality. */
8613         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8614
8615         /* Result. */
8616         bool is_ok = true;
8617
8618         /*  Check that INVALID_OPERATION is generated by TextureStorage1D if texture
8619          is not the name of an existing texture object. */
8620         {
8621                 gl.textureStorage1D(m_to_invalid, 1, GL_R8, 8);
8622                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage1D",
8623                                                                   "texture is not the name of an existing texture object.");
8624         }
8625
8626         /*  Check that INVALID_ENUM is generated by TextureStorage1D if
8627          internalformat is not a valid sized internal format. */
8628         {
8629                 gl.textureStorage1D(m_to_1D, 1, m_internalformat_invalid, 8);
8630                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureStorage1D",
8631                                                                   "internalformat is not a valid sized internal format.");
8632         }
8633
8634         /*  Check that INVALID_ENUM is generated by TextureStorage1D if target or
8635          the effective target of texture is not one of the accepted targets
8636          described above. */
8637         {
8638                 gl.textureStorage1D(m_to_2D, 1, GL_R8, 8);
8639                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage1D",
8640                                                                   "the effective target of texture is not one of the accepted targets.");
8641         }
8642
8643         /*  Check that INVALID_VALUE is generated by TextureStorage1D if width or
8644          levels are less than 1. */
8645         {
8646                 gl.textureStorage1D(m_to_1D, 0, GL_R8, 8);
8647                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage1D", "levels is less than 1.");
8648
8649                 gl.textureStorage1D(m_to_1D, 1, GL_R8, 0);
8650                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage1D", "width is less than 1.");
8651         }
8652
8653         /*  Check that INVALID_OPERATION is generated by TextureStorage1D if levels
8654          is greater than log2(width)+1. */
8655         {
8656                 gl.textureStorage1D(m_to_1D, 8, GL_R8, 8);
8657                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage1D",
8658                                                                   "levels is greater than log2(width)+1.");
8659         }
8660
8661         return is_ok;
8662 }
8663
8664 /** @brief Test TextureStorage2D
8665  *
8666  *  @return Test result.
8667  */
8668 bool StorageErrorsTest::Test2D()
8669 {
8670         /* Shortcut for GL functionality. */
8671         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8672
8673         /* Result. */
8674         bool is_ok = true;
8675
8676         /*  Check that INVALID_OPERATION is generated by TextureStorage2D if
8677          texture is not the name of an existing texture object. */
8678         {
8679                 gl.textureStorage2D(m_to_invalid, 1, GL_R8, 8, 8);
8680                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2D",
8681                                                                   "texture is not the name of an existing texture object.");
8682         }
8683
8684         /*  Check that INVALID_ENUM is generated by TextureStorage2D if
8685          internalformat is not a valid sized internal format. */
8686         {
8687                 gl.textureStorage2D(m_to_2D, 1, m_internalformat_invalid, 8, 8);
8688                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureStorage2D",
8689                                                                   "internalformat is not a valid sized internal format.");
8690         }
8691
8692         /*  Check that INVALID_ENUM is generated by TextureStorage2D if target or
8693          the effective target of texture is not one of the accepted targets
8694          described above. */
8695         {
8696                 gl.textureStorage2D(m_to_1D, 1, GL_R8, 8, 8);
8697                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2D",
8698                                                                   "the effective target of texture is not one of the accepted targets.");
8699         }
8700
8701         /*  Check that INVALID_VALUE is generated by TextureStorage2D if width,
8702          height or levels are less than 1. */
8703         {
8704                 gl.textureStorage2D(m_to_2D, 0, GL_R8, 8, 8);
8705                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2D", "levels is less than 1.");
8706
8707                 gl.textureStorage2D(m_to_2D, 1, GL_R8, 0, 8);
8708                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2D", "width is less than 1.");
8709
8710                 gl.textureStorage2D(m_to_2D, 1, GL_R8, 8, 0);
8711                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2D", "height is less than 1.");
8712         }
8713
8714         /* Check that INVALID_OPERATION is generated by TextureStorage2D if target
8715          is TEXTURE_1D_ARRAY or PROXY_TEXTURE_1D_ARRAY and levels is greater than
8716          log2(width)+1. */
8717         {
8718                 gl.textureStorage2D(m_to_1D_array, 8, GL_R8, 8, 8);
8719                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2D",
8720                                                                   "target is TEXTURE_1D_ARRAY and levels is greater than log2(width)+1.");
8721         }
8722
8723         /*  Check that INVALID_OPERATION is generated by TextureStorage2D if target
8724          is not TEXTURE_1D_ARRAY or PROXY_TEXTURE_1D_ARRAY and levels is greater
8725          than log2(max(width, height))+1.  */
8726         {
8727                 gl.textureStorage2D(m_to_2D, 8, GL_R8, 8, 8);
8728                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2D",
8729                                                                   "target is TEXTURE_2D and levels is greater than log2(max(width, height))+1.");
8730         }
8731
8732         return is_ok;
8733 }
8734
8735 /** @brief Test TextureStorage3D
8736  *
8737  *  @return Test result.
8738  */
8739 bool StorageErrorsTest::Test3D()
8740 {
8741         /* Shortcut for GL functionality. */
8742         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8743
8744         /* Result. */
8745         bool is_ok = true;
8746
8747         /*  Check that INVALID_OPERATION is generated by TextureStorage3D if texture
8748          is not the name of an existing texture object. */
8749         {
8750                 gl.textureStorage3D(m_to_invalid, 1, GL_R8, 8, 8, 8);
8751                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3D",
8752                                                                   "texture is not the name of an existing texture object.");
8753         }
8754
8755         /*  Check that INVALID_ENUM is generated by TextureStorage3D if
8756          internalformat is not a valid sized internal format. */
8757         {
8758                 gl.textureStorage3D(m_to_3D, 1, m_internalformat_invalid, 8, 8, 8);
8759                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureStorage3D",
8760                                                                   "internalformat is not a valid sized internal format.");
8761         }
8762
8763         /*  Check that INVALID_ENUM is generated by TextureStorage3D if target or
8764          the effective target of texture is not one of the accepted targets
8765          described above. */
8766         {
8767                 gl.textureStorage3D(m_to_1D, 1, GL_R8, 8, 8, 8);
8768                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3D",
8769                                                                   "the effective target of texture is not one of the accepted targets.");
8770         }
8771
8772         /*  Check that INVALID_VALUE is generated by TextureStorage3D if width,
8773          height, depth or levels are less than 1. */
8774         {
8775                 gl.textureStorage3D(m_to_3D, 0, GL_R8, 8, 8, 8);
8776                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3D", "levels is less than 1.");
8777
8778                 gl.textureStorage3D(m_to_3D, 1, GL_R8, 0, 8, 8);
8779                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3D", "width is less than 1.");
8780
8781                 gl.textureStorage3D(m_to_3D, 1, GL_R8, 8, 0, 8);
8782                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3D", "height is less than 1.");
8783
8784                 gl.textureStorage3D(m_to_3D, 1, GL_R8, 8, 8, 0);
8785                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3D", "depth is less than 1.");
8786         }
8787
8788         /* Check that INVALID_OPERATION is generated by TextureStorage3D if target
8789          is TEXTURE_3D or PROXY_TEXTURE_3D and levels is greater than
8790          log2(max(width, height, depth))+1. */
8791         {
8792                 gl.textureStorage3D(m_to_3D, 8, GL_R8, 8, 8, 8);
8793                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3D",
8794                                                                   "target is TEXTURE_3D and levels is greater than log2(max(width, height, depth))+1.");
8795         }
8796
8797         /*  Check that INVALID_OPERATION is generated by TextureStorage3D if target
8798          is TEXTURE_2D_ARRAY, PROXY_TEXTURE_2D_ARRAY, TEXURE_CUBE_ARRAY,
8799          or PROXY_TEXTURE_CUBE_MAP_ARRAY and levels is greater than
8800          log2(max(width, height))+1.  */
8801         {
8802                 gl.textureStorage3D(m_to_2D_array, 6, GL_R8, 8, 8, 256);
8803                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3D",
8804                                                                   "target is TEXTURE_2D_ARRAY and levels is greater than log2(max(width, height))+1.");
8805         }
8806
8807         return is_ok;
8808 }
8809
8810 /** @brief Test TextureStorage2DMultisample
8811  *
8812  *  @return Test result.
8813  */
8814 bool StorageErrorsTest::Test2DMultisample()
8815 {
8816         /* Shortcut for GL functionality. */
8817         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8818
8819         /* Result. */
8820         bool is_ok = true;
8821
8822         /*  Check that INVALID_OPERATION is generated by TextureStorage2DMultisample
8823          if texture is not the name of an existing texture object. */
8824         {
8825                 gl.textureStorage2DMultisample(m_to_invalid, 1, GL_R8, 8, 8, false);
8826                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2DMultisample",
8827                                                                   "texture is not the name of an existing texture object.");
8828         }
8829
8830         /*  Check that INVALID_ENUM is generated by TextureStorage2DMultisample if
8831          internalformat is not a valid color-renderable, depth-renderable or
8832          stencil-renderable format. */
8833         {
8834                 gl.textureStorage2DMultisample(m_to_2D_ms, 1, m_internalformat_invalid, 8, 8, false);
8835                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureStorage2DMultisample",
8836                                                                   "internalformat is not a valid sized internal format.");
8837         }
8838
8839         /*  Check that INVALID_OPERATION is generated by TextureStorage2DMultisample if
8840          target or the effective target of texture is not one of the accepted
8841          targets described above. */
8842         {
8843                 gl.textureStorage2DMultisample(m_to_1D, 1, GL_R8, 8, 8, false);
8844                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2DMultisample",
8845                                                                   "the effective target of texture is not one of the accepted targets.");
8846         }
8847
8848         /* Check that INVALID_VALUE is generated by TextureStorage2DMultisample if
8849          width or height are less than 1 or greater than the value of
8850          MAX_TEXTURE_SIZE. */
8851         {
8852                 gl.textureStorage2DMultisample(m_to_2D_ms, 1, GL_R8, 0, 8, false);
8853                 is_ok &=
8854                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2DMultisample", "width is less than 1.");
8855
8856                 gl.textureStorage2DMultisample(m_to_2D_ms, 1, GL_R8, 8, 0, false);
8857                 is_ok &=
8858                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2DMultisample", "height is less than 1.");
8859
8860                 gl.textureStorage2DMultisample(m_to_2D_ms, 1, GL_R8, m_max_texture_size * 2, 8, false);
8861                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2DMultisample",
8862                                                                   "width is greater than the value of MAX_TEXTURE_SIZE.");
8863
8864                 gl.textureStorage2DMultisample(m_to_2D_ms, 1, GL_R8, 8, m_max_texture_size * 2, false);
8865                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2DMultisample",
8866                                                                   "height is greater than the value of MAX_TEXTURE_SIZE.");
8867         }
8868
8869         /* Check that INVALID_OPERATION is generated by TextureStorage2DMultisample if
8870          samples is greater than the value of MAX_SAMPLES. */
8871         {
8872                 gl.textureStorage2DMultisample(m_to_2D_ms, m_max_samples * 2, GL_R8, 8, 8, false);
8873                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2DMultisample",
8874                                                                   "samples is greater than the value of MAX_SAMPLES.");
8875         }
8876
8877         /* Check that INVALID_OPERATION is generated by TextureStorage2DMultisample
8878          if the value of TEXTURE_IMMUTABLE_FORMAT for the texture bound to target
8879          is not FALSE. */
8880         {
8881                 gl.textureStorage2DMultisample(m_to_2D_ms_immutable, 1, GL_R8, 8, 8, false);
8882                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2DMultisample",
8883                                                                   "samples is greater than the value of MAX_SAMPLES.");
8884         }
8885
8886         return is_ok;
8887 }
8888
8889 /** @brief Test TextureStorage3DMultisample
8890  *
8891  *  @return Test result.
8892  */
8893 bool StorageErrorsTest::Test3DMultisample()
8894 {
8895         /* Shortcut for GL functionality. */
8896         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8897
8898         /* Result. */
8899         bool is_ok = true;
8900
8901         /*  Check that INVALID_OPERATION is generated by TextureStorage3DMultisample
8902          if texture is not the name of an existing texture object. */
8903         {
8904                 gl.textureStorage3DMultisample(m_to_invalid, 1, GL_R8, 8, 8, 8, false);
8905                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3DMultisample",
8906                                                                   "texture is not the name of an existing texture object.");
8907         }
8908
8909         /*  Check that INVALID_ENUM is generated by TextureStorage3DMultisample if
8910          internalformat is not a valid color-renderable, depth-renderable or
8911          stencil-renderable format. */
8912         {
8913                 gl.textureStorage3DMultisample(m_to_3D_ms, 1, m_internalformat_invalid, 8, 8, 8, false);
8914                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureStorage3DMultisample",
8915                                                                   "internalformat is not a valid sized internal format.");
8916         }
8917
8918         /*  Check that INVALID_OPERATION is generated by TextureStorage3DMultisample if
8919          target or the effective target of texture is not one of the accepted
8920          targets described above. */
8921         {
8922                 gl.textureStorage3DMultisample(m_to_1D, 1, GL_R8, 8, 8, 8, false);
8923                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3DMultisample",
8924                                                                   "the effective target of texture is not one of the accepted targets.");
8925         }
8926
8927         /* Check that INVALID_VALUE is generated by TextureStorage3DMultisample if
8928          width or height are less than 1 or greater than the value of
8929          MAX_TEXTURE_SIZE. */
8930         {
8931                 gl.textureStorage3DMultisample(m_to_3D_ms, 1, GL_R8, 0, 8, 8, false);
8932                 is_ok &=
8933                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3DMultisample", "width is less than 1.");
8934
8935                 gl.textureStorage3DMultisample(m_to_3D_ms, 1, GL_R8, 8, 0, 8, false);
8936                 is_ok &=
8937                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3DMultisample", "height is less than 1.");
8938
8939                 gl.textureStorage3DMultisample(m_to_3D_ms, 1, GL_R8, m_max_texture_size * 2, 8, 8, false);
8940                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3DMultisample",
8941                                                                   "width is greater than the value of MAX_TEXTURE_SIZE.");
8942
8943                 gl.textureStorage3DMultisample(m_to_3D_ms, 1, GL_R8, 8, m_max_texture_size * 2, 8, false);
8944                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3DMultisample",
8945                                                                   "height is greater than the value of MAX_TEXTURE_SIZE.");
8946         }
8947
8948         /* Check that INVALID_VALUE is generated by TextureStorage3DMultisample if
8949          depth is less than 1 or greater than the value of
8950          MAX_ARRAY_TEXTURE_LAYERS. */
8951         {
8952                 gl.textureStorage3DMultisample(m_to_3D_ms, 1, GL_R8, 8, 8, 0, false);
8953                 is_ok &=
8954                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3DMultisample", "depth is less than 1.");
8955
8956                 gl.textureStorage3DMultisample(m_to_3D_ms, 1, GL_R8, 8, 8, m_max_array_texture_layers * 2, false);
8957                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3DMultisample",
8958                                                                   "depth is greater than the value of MAX_ARRAY_TEXTURE_LAYERS.");
8959         }
8960
8961         /* Check that INVALID_VALUE is generated by TextureStorage3DMultisample if
8962          samples is greater than the value of MAX_SAMPLES. */
8963         {
8964                 gl.textureStorage3DMultisample(m_to_3D_ms, m_max_samples * 2, GL_R8, 8, 8, 8, false);
8965                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3DMultisample",
8966                                                                   "samples is greater than the value of MAX_SAMPLES.");
8967         }
8968
8969         /* Check that INVALID_OPERATION is generated by TextureStorage3DMultisample
8970          if the value of TEXTURE_IMMUTABLE_FORMAT for the texture bound to target
8971          is not FALSE. */
8972         {
8973                 gl.textureStorage3DMultisample(m_to_3D_ms_immutable, 1, GL_R8, 8, 8, 8, false);
8974                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3DMultisample",
8975                                                                   "samples is greater than the value of MAX_SAMPLES.");
8976         }
8977
8978         return is_ok;
8979 }
8980
8981 /** @brief Clean GL objects, test variables and GL errors.
8982  */
8983 void StorageErrorsTest::Clean()
8984 {
8985         /* Shortcut for GL functionality. */
8986         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8987
8988         /* Cleanup. */
8989         if (m_to_1D)
8990         {
8991                 gl.deleteTextures(1, &m_to_1D);
8992
8993                 m_to_1D = 0;
8994         }
8995
8996         if (m_to_1D_array)
8997         {
8998                 gl.deleteTextures(1, &m_to_1D_array);
8999
9000                 m_to_1D_array = 0;
9001         }
9002
9003         if (m_to_2D)
9004         {
9005                 gl.deleteTextures(1, &m_to_2D);
9006
9007                 m_to_2D = 0;
9008         }
9009
9010         if (m_to_2D_array)
9011         {
9012                 gl.deleteTextures(1, &m_to_2D_array);
9013
9014                 m_to_2D_array = 0;
9015         }
9016
9017         if (m_to_3D)
9018         {
9019                 gl.deleteTextures(1, &m_to_3D);
9020
9021                 m_to_3D = 0;
9022         }
9023
9024         if (m_to_2D_ms)
9025         {
9026                 gl.deleteTextures(1, &m_to_2D_ms);
9027
9028                 m_to_2D_ms = 0;
9029         }
9030
9031         if (m_to_2D_ms_immutable)
9032         {
9033                 gl.deleteTextures(1, &m_to_2D_ms_immutable);
9034
9035                 m_to_2D_ms_immutable = 0;
9036         }
9037
9038         if (m_to_3D_ms)
9039         {
9040                 gl.deleteTextures(1, &m_to_3D_ms);
9041
9042                 m_to_3D_ms = 0;
9043         }
9044
9045         if (m_to_3D_ms_immutable)
9046         {
9047                 gl.deleteTextures(1, &m_to_3D_ms_immutable);
9048
9049                 m_to_3D_ms_immutable = 0;
9050         }
9051
9052         m_to_invalid                       = 0;
9053         m_internalformat_invalid   = 0;
9054         m_max_texture_size                 = 1;
9055         m_max_samples                      = 1;
9056         m_max_array_texture_layers = 1;
9057
9058         while (GL_NO_ERROR != gl.getError())
9059                 ;
9060 }
9061
9062 /******************************** Texture SubImage Errors Test Implementation   ********************************/
9063
9064 /** @brief Texture SubImage Errors Test constructor.
9065  *
9066  *  @param [in] context     OpenGL context.
9067  */
9068 SubImageErrorsTest::SubImageErrorsTest(deqp::Context& context)
9069         : deqp::TestCase(context, "textures_subimage_errors", "Texture SubImage Errors Test")
9070         , m_to_1D_empty(0)
9071         , m_to_2D_empty(0)
9072         , m_to_3D_empty(0)
9073         , m_to_1D(0)
9074         , m_to_2D(0)
9075         , m_to_3D(0)
9076         , m_to_1D_compressed(0)
9077         , m_to_2D_compressed(0)
9078         , m_to_3D_compressed(0)
9079         , m_to_rectangle_compressed(0)
9080         , m_to_invalid(0)
9081         , m_bo(0)
9082         , m_format_invalid(0)
9083         , m_type_invalid(0)
9084         , m_max_texture_size(1)
9085         , m_reference_compressed_1D(DE_NULL)
9086         , m_reference_compressed_2D(DE_NULL)
9087         , m_reference_compressed_3D(DE_NULL)
9088         , m_reference_compressed_rectangle(DE_NULL)
9089         , m_reference_compressed_1D_size(0)
9090         , m_reference_compressed_2D_size(0)
9091         , m_reference_compressed_3D_size(0)
9092         , m_reference_compressed_rectangle_size(0)
9093         , m_reference_compressed_1D_format(0)
9094         , m_reference_compressed_2D_format(0)
9095         , m_reference_compressed_3D_format(0)
9096         , m_reference_compressed_rectangle_format(0)
9097         , m_not_matching_compressed_1D_format(0)
9098         , m_not_matching_compressed_1D_size(0)
9099         , m_not_matching_compressed_2D_format(0)
9100         , m_not_matching_compressed_2D_size(0)
9101         , m_not_matching_compressed_3D_format(0)
9102         , m_not_matching_compressed_3D_size(0)
9103 {
9104         /* Intentionally left blank. */
9105 }
9106
9107 /** @brief Iterate Texture SubImage Errors Test cases.
9108  *
9109  *  @return Iteration result.
9110  */
9111 tcu::TestNode::IterateResult SubImageErrorsTest::iterate()
9112 {
9113         /* Get context setup. */
9114         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
9115         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
9116
9117         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
9118         {
9119                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
9120
9121                 return STOP;
9122         }
9123
9124         /* Running tests. */
9125         bool is_ok      = true;
9126         bool is_error = false;
9127
9128         try
9129         {
9130                 Prepare();
9131
9132                 is_ok &= Test1D();
9133                 is_ok &= Test2D();
9134                 is_ok &= Test3D();
9135                 is_ok &= Test1DCompressed();
9136                 is_ok &= Test2DCompressed();
9137                 is_ok &= Test3DCompressed();
9138         }
9139         catch (...)
9140         {
9141                 is_ok   = false;
9142                 is_error = true;
9143         }
9144
9145         /* Cleanup. */
9146         Clean();
9147
9148         /* Result's setup. */
9149         if (is_ok)
9150         {
9151                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
9152         }
9153         else
9154         {
9155                 if (is_error)
9156                 {
9157                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
9158                 }
9159                 else
9160                 {
9161                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
9162                 }
9163         }
9164
9165         return STOP;
9166 }
9167
9168 /** @brief Prepare test's objects.
9169  */
9170 void SubImageErrorsTest::Prepare()
9171 {
9172         /* Shortcut for GL functionality. */
9173         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
9174
9175         /* Auxiliary objects setup. */
9176
9177         /* 1D */
9178         gl.createTextures(GL_TEXTURE_1D, 1, &m_to_1D_empty);
9179         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9180
9181         /* 2D */
9182         gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D_empty);
9183         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9184
9185         /* 3D */
9186         gl.createTextures(GL_TEXTURE_3D, 1, &m_to_3D_empty);
9187         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9188
9189         /* 1D */
9190         gl.createTextures(GL_TEXTURE_1D, 1, &m_to_1D);
9191         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9192
9193         gl.bindTexture(GL_TEXTURE_1D, m_to_1D);
9194         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9195
9196         gl.texImage1D(GL_TEXTURE_1D, 0, s_reference_internalformat, s_reference_width, 0, s_reference_format,
9197                                   GL_UNSIGNED_BYTE, s_reference);
9198         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
9199
9200         /* 2D */
9201         gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D);
9202         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9203
9204         gl.bindTexture(GL_TEXTURE_2D, m_to_2D);
9205         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9206
9207         gl.texImage2D(GL_TEXTURE_2D, 0, s_reference_internalformat, s_reference_width, s_reference_height, 0,
9208                                   s_reference_format, GL_UNSIGNED_BYTE, s_reference);
9209         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
9210
9211         /* 3D */
9212         gl.createTextures(GL_TEXTURE_3D, 1, &m_to_3D);
9213         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9214
9215         gl.bindTexture(GL_TEXTURE_3D, m_to_3D);
9216         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9217
9218         gl.texImage3D(GL_TEXTURE_3D, 0, s_reference_internalformat, s_reference_width, s_reference_height,
9219                                   s_reference_depth, 0, s_reference_format, GL_UNSIGNED_BYTE, s_reference);
9220         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
9221
9222         /* 1D Compressed */
9223         gl.createTextures(GL_TEXTURE_1D, 1, &m_to_1D_compressed);
9224         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9225
9226         gl.bindTexture(GL_TEXTURE_1D, m_to_1D_compressed);
9227         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9228
9229         gl.texImage1D(GL_TEXTURE_1D, 0, s_reference_internalformat_compressed, s_reference_width, 0, s_reference_format,
9230                                   GL_UNSIGNED_BYTE, s_reference);
9231         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
9232
9233         glw::GLint is_compressed = 0;
9234
9235         gl.getTexLevelParameteriv(GL_TEXTURE_1D, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9236         GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9237
9238         if (is_compressed)
9239         {
9240                 gl.getTexLevelParameteriv(GL_TEXTURE_1D, 0, GL_TEXTURE_INTERNAL_FORMAT, &m_reference_compressed_1D_format);
9241                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9242
9243                 m_reference_compressed_1D_size = 0;
9244
9245                 gl.getTexLevelParameteriv(GL_TEXTURE_1D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &m_reference_compressed_1D_size);
9246                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9247
9248                 if (m_reference_compressed_1D_size)
9249                 {
9250                         m_reference_compressed_1D = new glw::GLubyte[m_reference_compressed_1D_size];
9251
9252                         gl.getCompressedTexImage(GL_TEXTURE_1D, 0, m_reference_compressed_1D);
9253                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
9254                 }
9255         }
9256
9257         /* 2D Compressed */
9258         gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D_compressed);
9259         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9260
9261         gl.bindTexture(GL_TEXTURE_2D, m_to_2D_compressed);
9262         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9263
9264         gl.texImage2D(GL_TEXTURE_2D, 0, s_reference_internalformat_compressed, s_reference_width, s_reference_height, 0,
9265                                   s_reference_format, GL_UNSIGNED_BYTE, s_reference);
9266         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
9267
9268         is_compressed = 0;
9269
9270         gl.getTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9271         GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9272
9273         if (is_compressed)
9274         {
9275                 gl.getTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &m_reference_compressed_2D_format);
9276                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9277
9278                 m_reference_compressed_2D_size = 0;
9279
9280                 gl.getTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &m_reference_compressed_2D_size);
9281                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9282
9283                 if (m_reference_compressed_2D_size)
9284                 {
9285                         m_reference_compressed_2D = new glw::GLubyte[m_reference_compressed_2D_size];
9286
9287                         gl.getCompressedTexImage(GL_TEXTURE_2D, 0, m_reference_compressed_2D);
9288                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
9289                 }
9290         }
9291
9292         /* 3D Compressed */
9293         gl.createTextures(GL_TEXTURE_2D_ARRAY, 1, &m_to_3D_compressed);
9294         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9295
9296         gl.bindTexture(GL_TEXTURE_2D_ARRAY, m_to_3D_compressed);
9297         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9298
9299         gl.texImage3D(GL_TEXTURE_2D_ARRAY, 0, s_reference_internalformat_compressed, s_reference_width, s_reference_height,
9300                                   s_reference_depth, 0, s_reference_format, GL_UNSIGNED_BYTE, s_reference);
9301         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage3D has failed");
9302
9303         is_compressed = 0;
9304
9305         gl.getTexLevelParameteriv(GL_TEXTURE_2D_ARRAY, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9306         GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9307
9308         if (is_compressed)
9309         {
9310                 gl.getTexLevelParameteriv(GL_TEXTURE_2D_ARRAY, 0, GL_TEXTURE_INTERNAL_FORMAT,
9311                                                                   &m_reference_compressed_3D_format);
9312                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9313
9314                 m_reference_compressed_3D_size = 0;
9315
9316                 gl.getTexLevelParameteriv(GL_TEXTURE_2D_ARRAY, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
9317                                                                   &m_reference_compressed_3D_size);
9318                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9319
9320                 if (m_reference_compressed_3D_size)
9321                 {
9322                         m_reference_compressed_3D = new glw::GLubyte[m_reference_compressed_3D_size];
9323
9324                         gl.getCompressedTexImage(GL_TEXTURE_2D_ARRAY, 0, m_reference_compressed_3D);
9325                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
9326                 }
9327         }
9328
9329         /* RECTANGLE Compressed */
9330         gl.createTextures(GL_TEXTURE_RECTANGLE, 1, &m_to_rectangle_compressed);
9331         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9332
9333         gl.bindTexture(GL_TEXTURE_RECTANGLE, m_to_rectangle_compressed);
9334         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9335
9336         gl.texImage2D(GL_TEXTURE_RECTANGLE, 0, s_reference_internalformat_compressed, s_reference_width, s_reference_height,
9337                                   0, s_reference_format, GL_UNSIGNED_BYTE, s_reference);
9338         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
9339
9340         is_compressed = 0;
9341
9342         gl.getTexLevelParameteriv(GL_TEXTURE_RECTANGLE, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9343         GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9344
9345         if (is_compressed)
9346         {
9347                 gl.getTexLevelParameteriv(GL_TEXTURE_RECTANGLE, 0, GL_TEXTURE_INTERNAL_FORMAT,
9348                                                                   &m_reference_compressed_rectangle_format);
9349                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9350
9351                 m_reference_compressed_rectangle_size = 0;
9352
9353                 gl.getTexLevelParameteriv(GL_TEXTURE_RECTANGLE, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
9354                                                                   &m_reference_compressed_rectangle_size);
9355                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9356
9357                 if (m_reference_compressed_rectangle_size)
9358                 {
9359                         m_reference_compressed_rectangle = new glw::GLubyte[m_reference_compressed_rectangle_size];
9360
9361                         gl.getCompressedTexImage(GL_TEXTURE_RECTANGLE, 0, m_reference_compressed_rectangle);
9362                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
9363                 }
9364         }
9365
9366         /* Buffer object */
9367         gl.createBuffers(1, &m_bo);
9368         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateBuffers has failed");
9369
9370         gl.namedBufferData(m_bo, s_reference_size, s_reference, GL_STATIC_COPY);
9371         GLU_EXPECT_NO_ERROR(gl.getError(), "glNamedBufferData has failed");
9372
9373         /* Invalid values */
9374
9375         /* invalid texture object */
9376         while (gl.isTexture(++m_to_invalid))
9377                 ;
9378         GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed");
9379
9380         /* invalid internal format */
9381         static const glw::GLenum all_formats[] = { GL_STENCIL_INDEX,
9382                                                                                            GL_DEPTH_COMPONENT,
9383                                                                                            GL_DEPTH_STENCIL,
9384                                                                                            GL_RED,
9385                                                                                            GL_GREEN,
9386                                                                                            GL_BLUE,
9387                                                                                            GL_RG,
9388                                                                                            GL_RGB,
9389                                                                                            GL_RGBA,
9390                                                                                            GL_BGR,
9391                                                                                            GL_BGRA,
9392                                                                                            GL_RED_INTEGER,
9393                                                                                            GL_GREEN_INTEGER,
9394                                                                                            GL_BLUE_INTEGER,
9395                                                                                            GL_RG_INTEGER,
9396                                                                                            GL_RGB_INTEGER,
9397                                                                                            GL_RGBA_INTEGER,
9398                                                                                            GL_BGR_INTEGER,
9399                                                                                            GL_BGRA_INTEGER };
9400
9401         static const glw::GLuint all_internal_formats_count = sizeof(all_formats) / sizeof(all_formats[0]);
9402
9403         bool is_valid   = true;
9404         m_format_invalid = 0;
9405
9406         while (is_valid)
9407         {
9408                 is_valid = false;
9409                 m_format_invalid++;
9410                 for (glw::GLuint i = 0; i < all_internal_formats_count; ++i)
9411                 {
9412                         if (all_formats[i] == m_format_invalid)
9413                         {
9414                                 is_valid = true;
9415                                 break;
9416                         }
9417                 }
9418         }
9419
9420         /* Invalid type. */
9421         static const glw::GLenum all_types[] = { GL_UNSIGNED_BYTE,
9422                                                                                          GL_BYTE,
9423                                                                                          GL_UNSIGNED_SHORT,
9424                                                                                          GL_SHORT,
9425                                                                                          GL_UNSIGNED_INT,
9426                                                                                          GL_INT,
9427                                                                                          GL_HALF_FLOAT,
9428                                                                                          GL_FLOAT,
9429                                                                                          GL_UNSIGNED_BYTE_3_3_2,
9430                                                                                          GL_UNSIGNED_BYTE_2_3_3_REV,
9431                                                                                          GL_UNSIGNED_SHORT_5_6_5,
9432                                                                                          GL_UNSIGNED_SHORT_5_6_5_REV,
9433                                                                                          GL_UNSIGNED_SHORT_4_4_4_4,
9434                                                                                          GL_UNSIGNED_SHORT_4_4_4_4_REV,
9435                                                                                          GL_UNSIGNED_SHORT_5_5_5_1,
9436                                                                                          GL_UNSIGNED_SHORT_1_5_5_5_REV,
9437                                                                                          GL_UNSIGNED_INT_8_8_8_8,
9438                                                                                          GL_UNSIGNED_INT_8_8_8_8_REV,
9439                                                                                          GL_UNSIGNED_INT_10_10_10_2,
9440                                                                                          GL_UNSIGNED_INT_2_10_10_10_REV,
9441                                                                                          GL_UNSIGNED_INT_24_8,
9442                                                                                          GL_UNSIGNED_INT_10F_11F_11F_REV,
9443                                                                                          GL_UNSIGNED_INT_5_9_9_9_REV,
9444                                                                                          GL_FLOAT_32_UNSIGNED_INT_24_8_REV };
9445
9446         static const glw::GLuint all_types_count = sizeof(all_types) / sizeof(all_types[0]);
9447
9448         is_valid           = true;
9449         m_type_invalid = 0;
9450
9451         while (is_valid)
9452         {
9453                 is_valid = false;
9454                 m_type_invalid++;
9455                 for (glw::GLuint i = 0; i < all_types_count; ++i)
9456                 {
9457                         if (all_types[i] == m_type_invalid)
9458                         {
9459                                 is_valid = true;
9460                                 break;
9461                         }
9462                 }
9463         }
9464
9465         /* Maximum texture size.*/
9466         gl.getIntegerv(GL_MAX_TEXTURE_SIZE, &m_max_texture_size);
9467         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
9468
9469         glw::GLenum not_matching_format                                    = GL_RED;
9470         glw::GLenum not_matching_internalformat_compressed = GL_COMPRESSED_RED;
9471
9472         /* 1D Compressed with a non matching format. We need to do all the allocation to get the correct image size */
9473         glw::GLuint to_1D_compressed_not_matching;
9474
9475         gl.createTextures(GL_TEXTURE_1D, 1, &to_1D_compressed_not_matching);
9476         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9477
9478         gl.bindTexture(GL_TEXTURE_1D, to_1D_compressed_not_matching);
9479         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9480
9481         gl.texImage1D(GL_TEXTURE_1D, 0, not_matching_internalformat_compressed, s_reference_width, 0, s_reference_format,
9482                                   GL_UNSIGNED_BYTE, s_reference);
9483         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
9484
9485         is_compressed = 0;
9486
9487         gl.getTexLevelParameteriv(GL_TEXTURE_1D, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9488         GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9489
9490         if (is_compressed)
9491         {
9492                 gl.getTexLevelParameteriv(GL_TEXTURE_1D, 0, GL_TEXTURE_INTERNAL_FORMAT, &m_not_matching_compressed_1D_format);
9493                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9494
9495                 m_not_matching_compressed_1D_size = 0;
9496
9497                 gl.getTexLevelParameteriv(GL_TEXTURE_1D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
9498                                                                   &m_not_matching_compressed_1D_size);
9499                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9500         }
9501
9502         gl.deleteTextures(1, &to_1D_compressed_not_matching);
9503         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9504
9505         /* 2D Compressed with a non matching format. We need to do all the allocation to get the correct image size */
9506         glw::GLuint to_2D_compressed_not_matching;
9507
9508         gl.createTextures(GL_TEXTURE_2D, 1, &to_2D_compressed_not_matching);
9509         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9510
9511         gl.bindTexture(GL_TEXTURE_2D, to_2D_compressed_not_matching);
9512         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9513
9514         gl.texImage2D(GL_TEXTURE_2D, 0, not_matching_internalformat_compressed, s_reference_width, s_reference_height, 0,
9515                                   not_matching_format, GL_UNSIGNED_BYTE, s_reference);
9516         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
9517
9518         is_compressed = 0;
9519
9520         gl.getTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9521         GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9522
9523         if (is_compressed)
9524         {
9525                 gl.getTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &m_not_matching_compressed_2D_format);
9526                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9527
9528                 m_not_matching_compressed_2D_size = 0;
9529
9530                 gl.getTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
9531                                                                   &m_not_matching_compressed_2D_size);
9532                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9533         }
9534
9535         gl.deleteTextures(1, &to_2D_compressed_not_matching);
9536         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9537
9538         /* 3D Compressed with a non matching format. We need to do all the allocation to get the correct image size */
9539         glw::GLuint to_3D_compressed_not_matching;
9540
9541         gl.createTextures(GL_TEXTURE_3D, 1, &to_3D_compressed_not_matching);
9542         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9543
9544         gl.bindTexture(GL_TEXTURE_3D, to_3D_compressed_not_matching);
9545         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9546
9547         gl.texImage3D(GL_TEXTURE_3D, 0, not_matching_internalformat_compressed, s_reference_width, s_reference_height,
9548                                   s_reference_depth, 0, not_matching_format, GL_UNSIGNED_BYTE, s_reference);
9549         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage3D has failed");
9550
9551         is_compressed = 0;
9552
9553         gl.getTexLevelParameteriv(GL_TEXTURE_3D, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9554         GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9555
9556         if (is_compressed)
9557         {
9558                 gl.getTexLevelParameteriv(GL_TEXTURE_3D, 0, GL_TEXTURE_INTERNAL_FORMAT, &m_not_matching_compressed_3D_format);
9559                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9560
9561                 m_not_matching_compressed_3D_size = 0;
9562
9563                 gl.getTexLevelParameteriv(GL_TEXTURE_3D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
9564                                                                   &m_not_matching_compressed_3D_size);
9565                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9566         }
9567
9568         gl.deleteTextures(1, &to_3D_compressed_not_matching);
9569         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9570 }
9571
9572 /** @brief Test (negative) of TextureSubImage1D
9573  *
9574  *  @return Test result.
9575  */
9576 bool SubImageErrorsTest::Test1D()
9577 {
9578         /* Shortcut for GL functionality. */
9579         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
9580
9581         /* Result. */
9582         bool is_ok = true;
9583
9584         /* Check that INVALID_OPERATION is generated by TextureSubImage1D if
9585          texture is not the name of an existing texture object. */
9586         {
9587                 gl.textureSubImage1D(m_to_invalid, 0, 0, s_reference_width, s_reference_format, s_reference_type, s_reference);
9588                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9589                                                                   "texture is not the name of an existing texture object.");
9590         }
9591
9592         /* Check that INVALID_ENUM is generated by TextureSubImage1D if format is
9593          not an accepted format constant. */
9594         {
9595                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, m_format_invalid, s_reference_type, s_reference);
9596                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureSubImage1D",
9597                                                                   "format is not an accepted format constant.");
9598         }
9599
9600         /* Check that INVALID_ENUM is generated by TextureSubImage1D if type is not
9601          an accepted type constant. */
9602         {
9603                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, m_type_invalid, s_reference);
9604                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureSubImage1D",
9605                                                                   "type is not an accepted type constant.");
9606         }
9607
9608         /* Check that INVALID_VALUE is generated by TextureSubImage1D if level is
9609          less than 0. */
9610         {
9611                 gl.textureSubImage1D(m_to_1D, -1, 0, s_reference_width, s_reference_format, s_reference_type, s_reference);
9612                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D", "level is less than 0.");
9613         }
9614
9615         /* Check that INVALID_VALUE may be generated by TextureSubImage1D if level
9616          is greater than log2 max, where max is the returned value of
9617          MAX_TEXTURE_SIZE. */
9618         {
9619                 gl.textureSubImage1D(m_to_1D, m_max_texture_size, 0, s_reference_width, s_reference_format, s_reference_type,
9620                                                          s_reference);
9621                 is_ok &=
9622                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D",
9623                                                          "level is greater than log2 max, where max is the returned value of MAX_TEXTURE_SIZE.");
9624         }
9625
9626         /* Check that INVALID_VALUE is generated by TextureSubImage1D if
9627          xoffset<-b, or if (xoffset+width)>(w-b), where w is the TEXTURE_WIDTH,
9628          and b is the width of the TEXTURE_BORDER of the texture image being
9629          modified. Note that w includes twice the border width. */
9630         {
9631                 gl.textureSubImage1D(m_to_1D, 0, -1, s_reference_width, s_reference_format, s_reference_type, s_reference);
9632                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D",
9633                                                                   "xoffset<-b, where b is the width of the TEXTURE_BORDER.");
9634
9635                 gl.textureSubImage1D(m_to_1D, 0, 1, s_reference_width + 1, s_reference_format, s_reference_type, s_reference);
9636                 is_ok &= CheckErrorAndLog(
9637                         m_context, GL_INVALID_VALUE, "glTextureSubImage1D",
9638                         "(xoffset+width)>(w-b), where w is the TEXTURE_WIDTH, b is the width of the TEXTURE_BORDER.");
9639         }
9640
9641         /*Check that INVALID_VALUE is generated by TextureSubImage1D if width is less than 0. */
9642         {
9643 #ifndef TURN_OFF_SUB_IMAGE_ERRORS_TEST_OF_NEGATIVE_WIDTH_HEIGHT_OR_DEPTH
9644                 gl.textureSubImage1D(m_to_1D, 0, 0, -1, s_reference_format, s_reference_type, s_reference);
9645                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D", "width is less than 0.");
9646 #endif
9647         }
9648
9649         /* Check that INVALID_OPERATION is generated by TextureSubImage1D if type
9650          is one of UNSIGNED_BYTE_3_3_2, UNSIGNED_BYTE_2_3_3_REV,
9651          UNSIGNED_SHORT_5_6_5, or UNSIGNED_SHORT_5_6_5_REV and format is not RGB. */
9652         {
9653                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_BYTE_3_3_2, s_reference);
9654                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9655                                                                   "type is UNSIGNED_BYTE_3_3_2 and format is not RGB.");
9656
9657                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_BYTE_2_3_3_REV,
9658                                                          s_reference);
9659                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9660                                                                   "type is UNSIGNED_BYTE_2_3_3_REV and format is not RGB.");
9661
9662                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_SHORT_5_6_5,
9663                                                          s_reference);
9664                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9665                                                                   "type is UNSIGNED_SHORT_5_6_5 and format is not RGB.");
9666
9667                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_SHORT_5_6_5_REV,
9668                                                          s_reference);
9669                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9670                                                                   "type is UNSIGNED_SHORT_5_6_5_REV and format is not RGB.");
9671         }
9672
9673         /* Check that INVALID_OPERATION is generated by TextureSubImage1D if type
9674          is one of UNSIGNED_SHORT_4_4_4_4, UNSIGNED_SHORT_4_4_4_4_REV,
9675          UNSIGNED_SHORT_5_5_5_1, UNSIGNED_SHORT_1_5_5_5_REV,
9676          UNSIGNED_INT_8_8_8_8, UNSIGNED_INT_8_8_8_8_REV, UNSIGNED_INT_10_10_10_2,
9677          or UNSIGNED_INT_2_10_10_10_REV and format is neither RGBA nor BGRA. */
9678         {
9679                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_SHORT_4_4_4_4,
9680                                                          s_reference);
9681                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9682                                                                   "type is UNSIGNED_SHORT_4_4_4_4 and format is neither RGBA nor BGRA.");
9683
9684                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_SHORT_4_4_4_4_REV,
9685                                                          s_reference);
9686                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9687                                                                   "type is UNSIGNED_SHORT_4_4_4_4_REV and format is neither RGBA nor BGRA.");
9688
9689                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_SHORT_5_5_5_1,
9690                                                          s_reference);
9691                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9692                                                                   "type is UNSIGNED_SHORT_5_5_5_1 and format is neither RGBA nor BGRA.");
9693
9694                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_SHORT_1_5_5_5_REV,
9695                                                          s_reference);
9696                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9697                                                                   "type is UNSIGNED_SHORT_1_5_5_5_REV and format is neither RGBA nor BGRA.");
9698
9699                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_INT_8_8_8_8,
9700                                                          s_reference);
9701                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9702                                                                   "type is UNSIGNED_INT_8_8_8_8 and format is neither RGBA nor BGRA.");
9703
9704                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_INT_8_8_8_8_REV,
9705                                                          s_reference);
9706                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9707                                                                   "type is UNSIGNED_INT_8_8_8_8_REV and format is neither RGBA nor BGRA.");
9708
9709                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_INT_10_10_10_2,
9710                                                          s_reference);
9711                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9712                                                                   "type is UNSIGNED_INT_10_10_10_2 and format is neither RGBA nor BGRA.");
9713
9714                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_INT_2_10_10_10_REV,
9715                                                          s_reference);
9716                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9717                                                                   "type is UNSIGNED_INT_2_10_10_10_REV and format is neither RGBA nor BGRA.");
9718         }
9719
9720         /* Check that INVALID_OPERATION is generated by TextureSubImage1D if a
9721          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
9722          and the buffer object's data store is currently mapped. */
9723         {
9724                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
9725                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9726
9727                 gl.mapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
9728
9729                 if (GL_NO_ERROR == gl.getError())
9730                 {
9731                         gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, s_reference_type, NULL);
9732                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9733                                                                           "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and "
9734                                                                           "the buffer object's data store is currently mapped.");
9735
9736                         gl.unmapBuffer(GL_PIXEL_UNPACK_BUFFER);
9737                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9738
9739                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
9740                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9741                 }
9742         }
9743
9744         /* Check that INVALID_OPERATION is generated by TextureSubImage1D if a
9745          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
9746          and the data would be unpacked from the buffer object such that the
9747          memory reads required would exceed the data store size. */
9748         {
9749                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
9750                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9751
9752                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, s_reference_type,
9753                                                          (glw::GLubyte*)NULL + s_reference_size * 2);
9754                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9755                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and the "
9756                                                                   "data would be unpacked from the buffer object such that the memory reads required "
9757                                                                   "would exceed the data store size.");
9758
9759                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
9760                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9761         }
9762
9763         /* Check that INVALID_OPERATION is generated by TextureSubImage1D if a
9764          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
9765          and pixels is not evenly divisible into the number of bytes needed to
9766          store in memory a datum indicated by type. */
9767         {
9768                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
9769                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9770
9771                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, s_reference_type,
9772                                                          (glw::GLubyte*)NULL + 1);
9773                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9774                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and pixels "
9775                                                                   "is not evenly divisible into the number of bytes needed to store in memory a datum "
9776                                                                   "indicated by type.");
9777
9778                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
9779                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9780         }
9781
9782         return is_ok;
9783 }
9784
9785 /** @brief Test (negative) of TextureSubImage2D
9786  *
9787  *  @return Test result.
9788  */
9789 bool SubImageErrorsTest::Test2D()
9790 {
9791         /* Shortcut for GL functionality. */
9792         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
9793
9794         /* Result. */
9795         bool is_ok = true;
9796
9797         /* Check that INVALID_OPERATION is generated by TextureSubImage2D if
9798          texture is not the name of an existing texture object. */
9799         {
9800                 gl.textureSubImage2D(m_to_invalid, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9801                                                          s_reference_type, s_reference);
9802                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9803                                                                   "texture is not the name of an existing texture object.");
9804         }
9805
9806         /* Check that INVALID_ENUM is generated by TextureSubImage2D if format is
9807          not an accepted format constant. */
9808         {
9809                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, m_format_invalid,
9810                                                          s_reference_type, s_reference);
9811                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureSubImage2D",
9812                                                                   "format is not an accepted format constant.");
9813         }
9814
9815         /* Check that INVALID_ENUM is generated by TextureSubImage2D if type is not
9816          an accepted type constant. */
9817         {
9818                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9819                                                          m_type_invalid, s_reference);
9820                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureSubImage2D",
9821                                                                   "type is not an accepted type constant.");
9822         }
9823
9824         /* Check that INVALID_VALUE is generated by TextureSubImage2D if level is
9825          less than 0. */
9826         {
9827                 gl.textureSubImage2D(m_to_2D, -1, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9828                                                          s_reference_type, s_reference);
9829                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage2D", "level is less than 0.");
9830         }
9831
9832         /* Check that INVALID_VALUE may be generated by TextureSubImage2D if level
9833          is greater than log2 max, where max is the returned value of
9834          MAX_TEXTURE_SIZE. */
9835         {
9836                 gl.textureSubImage2D(m_to_2D, m_max_texture_size, 0, 0, s_reference_width, s_reference_height,
9837                                                          s_reference_format, s_reference_type, s_reference);
9838                 is_ok &=
9839                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage2D",
9840                                                          "level is greater than log2 max, where max is the returned value of MAX_TEXTURE_SIZE.");
9841         }
9842
9843         /* Check that INVALID_VALUE may be generated by TextureSubImage2D if level
9844          is greater than log2 max, where max is the returned value of
9845          MAX_TEXTURE_SIZE.
9846          Check that INVALID_VALUE is generated by TextureSubImage2D if
9847          xoffset<-b, (xoffset+width)>(w-b), yoffset<-b, or
9848          (yoffset+height)>(h-b), where w is the TEXTURE_WIDTH, h is the
9849          TEXTURE_HEIGHT, and b is the border width of the texture image being
9850          modified. Note that w and h include twice the border width. */
9851         {
9852                 gl.textureSubImage2D(m_to_2D, 0, -1, 0, s_reference_width, s_reference_height, s_reference_format,
9853                                                          s_reference_type, s_reference);
9854                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage2D",
9855                                                                   "xoffset<-b, where b is the width of the TEXTURE_BORDER.");
9856
9857                 gl.textureSubImage2D(m_to_2D, 0, 1, 0, s_reference_width + 1, s_reference_height, s_reference_format,
9858                                                          s_reference_type, s_reference);
9859                 is_ok &= CheckErrorAndLog(
9860                         m_context, GL_INVALID_VALUE, "glTextureSubImage2D",
9861                         "(xoffset+width)>(w-b), where w is the TEXTURE_WIDTH, b is the width of the TEXTURE_BORDER.");
9862
9863                 gl.textureSubImage2D(m_to_2D, 0, 0, -1, s_reference_width, s_reference_height, s_reference_format,
9864                                                          s_reference_type, s_reference);
9865                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage2D",
9866                                                                   "yoffset<-b, where b is the height of the TEXTURE_BORDER.");
9867
9868                 gl.textureSubImage2D(m_to_2D, 0, 0, 1, s_reference_width + 1, s_reference_height, s_reference_format,
9869                                                          s_reference_type, s_reference);
9870                 is_ok &= CheckErrorAndLog(
9871                         m_context, GL_INVALID_VALUE, "glTextureSubImage2D",
9872                         "(yoffset+height)>(h-b), where h is the TEXTURE_HEIGHT, b is the width of the TEXTURE_BORDER.");
9873         }
9874
9875         /*Check that INVALID_VALUE is generated by TextureSubImage2D if width or height is less than 0. */
9876         {
9877 #ifndef TURN_OFF_SUB_IMAGE_ERRORS_TEST_OF_NEGATIVE_WIDTH_HEIGHT_OR_DEPTH
9878                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, -1, s_reference_height, s_reference_format, s_reference_type,
9879                                                          s_reference);
9880                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage2D", "width is less than 0.");
9881
9882                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, -1, s_reference_format, s_reference_type,
9883                                                          s_reference);
9884                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage2D", "height is less than 0.");
9885 #endif
9886         }
9887
9888         /* Check that INVALID_OPERATION is generated by TextureSubImage2D if type
9889          is one of UNSIGNED_BYTE_3_3_2, UNSIGNED_BYTE_2_3_3_REV,
9890          UNSIGNED_SHORT_5_6_5, or UNSIGNED_SHORT_5_6_5_REV and format is not RGB. */
9891         {
9892                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9893                                                          GL_UNSIGNED_BYTE_3_3_2, s_reference);
9894                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9895                                                                   "type is UNSIGNED_BYTE_3_3_2 and format is not RGB.");
9896
9897                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9898                                                          GL_UNSIGNED_BYTE_2_3_3_REV, s_reference);
9899                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9900                                                                   "type is UNSIGNED_BYTE_2_3_3_REV and format is not RGB.");
9901
9902                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9903                                                          GL_UNSIGNED_SHORT_5_6_5, s_reference);
9904                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9905                                                                   "type is UNSIGNED_SHORT_5_6_5 and format is not RGB.");
9906
9907                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9908                                                          GL_UNSIGNED_SHORT_5_6_5_REV, s_reference);
9909                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9910                                                                   "type is UNSIGNED_SHORT_5_6_5_REV and format is not RGB.");
9911         }
9912
9913         /* Check that INVALID_OPERATION is generated by TextureSubImage2D if type
9914          is one of UNSIGNED_SHORT_4_4_4_4, UNSIGNED_SHORT_4_4_4_4_REV,
9915          UNSIGNED_SHORT_5_5_5_1, UNSIGNED_SHORT_1_5_5_5_REV,
9916          UNSIGNED_INT_8_8_8_8, UNSIGNED_INT_8_8_8_8_REV, UNSIGNED_INT_10_10_10_2,
9917          or UNSIGNED_INT_2_10_10_10_REV and format is neither RGBA nor BGRA. */
9918         {
9919                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9920                                                          GL_UNSIGNED_SHORT_4_4_4_4, s_reference);
9921                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9922                                                                   "type is UNSIGNED_SHORT_4_4_4_4 and format is neither RGBA nor BGRA.");
9923
9924                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9925                                                          GL_UNSIGNED_SHORT_4_4_4_4_REV, s_reference);
9926                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9927                                                                   "type is UNSIGNED_SHORT_4_4_4_4_REV and format is neither RGBA nor BGRA.");
9928
9929                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9930                                                          GL_UNSIGNED_SHORT_5_5_5_1, s_reference);
9931                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9932                                                                   "type is UNSIGNED_SHORT_5_5_5_1 and format is neither RGBA nor BGRA.");
9933
9934                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9935                                                          GL_UNSIGNED_SHORT_1_5_5_5_REV, s_reference);
9936                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9937                                                                   "type is UNSIGNED_SHORT_1_5_5_5_REV and format is neither RGBA nor BGRA.");
9938
9939                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9940                                                          GL_UNSIGNED_INT_8_8_8_8, s_reference);
9941                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9942                                                                   "type is UNSIGNED_INT_8_8_8_8 and format is neither RGBA nor BGRA.");
9943
9944                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9945                                                          GL_UNSIGNED_INT_8_8_8_8_REV, s_reference);
9946                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9947                                                                   "type is UNSIGNED_INT_8_8_8_8_REV and format is neither RGBA nor BGRA.");
9948
9949                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9950                                                          GL_UNSIGNED_INT_10_10_10_2, s_reference);
9951                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9952                                                                   "type is UNSIGNED_INT_10_10_10_2 and format is neither RGBA nor BGRA.");
9953
9954                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9955                                                          GL_UNSIGNED_INT_2_10_10_10_REV, s_reference);
9956                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9957                                                                   "type is UNSIGNED_INT_2_10_10_10_REV and format is neither RGBA nor BGRA.");
9958         }
9959
9960         /* Check that INVALID_OPERATION is generated by TextureSubImage2D if a
9961          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
9962          and the buffer object's data store is currently mapped. */
9963         {
9964                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
9965                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9966
9967                 gl.mapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
9968
9969                 if (GL_NO_ERROR == gl.getError())
9970                 {
9971                         gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9972                                                                  s_reference_type, NULL);
9973                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9974                                                                           "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and "
9975                                                                           "the buffer object's data store is currently mapped.");
9976
9977                         gl.unmapBuffer(GL_PIXEL_UNPACK_BUFFER);
9978                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9979
9980                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
9981                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9982                 }
9983         }
9984
9985         /* Check that INVALID_OPERATION is generated by TextureSubImage2D if a
9986          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
9987          and the data would be unpacked from the buffer object such that the
9988          memory reads required would exceed the data store size. */
9989         {
9990                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
9991                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9992
9993                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9994                                                          s_reference_type, (glw::GLubyte*)NULL + s_reference_size * 2);
9995                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9996                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and the "
9997                                                                   "data would be unpacked from the buffer object such that the memory reads required "
9998                                                                   "would exceed the data store size.");
9999
10000                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10001                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10002         }
10003
10004         /* Check that INVALID_OPERATION is generated by TextureSubImage2D if a
10005          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
10006          and pixels is not evenly divisible into the number of bytes needed to
10007          store in memory a datum indicated by type. */
10008         {
10009                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10010                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10011
10012                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10013                                                          s_reference_type, (glw::GLubyte*)NULL + 1);
10014                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10015                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and pixels "
10016                                                                   "is not evenly divisible into the number of bytes needed to store in memory a datum "
10017                                                                   "indicated by type.");
10018
10019                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10020                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10021         }
10022
10023         return is_ok;
10024 }
10025
10026 /** @brief Test (negative) of TextureSubImage3D
10027  *
10028  *  @return Test result.
10029  */
10030 bool SubImageErrorsTest::Test3D()
10031 {
10032         /* Shortcut for GL functionality. */
10033         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10034
10035         /* Result. */
10036         bool is_ok = true;
10037
10038         /* Check that INVALID_OPERATION is generated by TextureSubImage3D if
10039          texture is not the name of an existing texture object. */
10040         {
10041                 gl.textureSubImage3D(m_to_invalid, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10042                                                          s_reference_format, s_reference_type, s_reference);
10043                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10044                                                                   "texture is not the name of an existing texture object.");
10045         }
10046
10047         /* Check that INVALID_ENUM is generated by TextureSubImage3D if format is
10048          not an accepted format constant. */
10049         {
10050                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10051                                                          m_format_invalid, s_reference_type, s_reference);
10052                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureSubImage3D",
10053                                                                   "format is not an accepted format constant.");
10054         }
10055
10056         /* Check that INVALID_ENUM is generated by TextureSubImage3D if type is not
10057          an accepted type constant. */
10058         {
10059                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10060                                                          s_reference_format, m_type_invalid, s_reference);
10061                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureSubImage3D",
10062                                                                   "type is not an accepted type constant.");
10063         }
10064
10065         /* Check that INVALID_VALUE is generated by TextureSubImage3D if level is
10066          less than 0. */
10067         {
10068                 gl.textureSubImage3D(m_to_3D, -1, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10069                                                          s_reference_format, s_reference_type, s_reference);
10070                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage3D", "level is less than 0.");
10071         }
10072
10073         /* Check that INVALID_VALUE may be generated by TextureSubImage1D if level
10074          is greater than log2 max, where max is the returned value of
10075          MAX_TEXTURE_SIZE. */
10076         {
10077                 gl.textureSubImage3D(m_to_3D, m_max_texture_size, 0, 0, 0, s_reference_width, s_reference_height,
10078                                                          s_reference_depth, s_reference_format, s_reference_type, s_reference);
10079                 is_ok &=
10080                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10081                                                          "level is greater than log2 max, where max is the returned value of MAX_TEXTURE_SIZE.");
10082         }
10083
10084         /* Check that INVALID_VALUE is generated by TextureSubImage3D if
10085          xoffset<-b, (xoffset+width)>(w-b), yoffset<-b, or
10086          (yoffset+height)>(h-b), or zoffset<-b, or (zoffset+depth)>(d-b), where w
10087          is the TEXTURE_WIDTH, h is the TEXTURE_HEIGHT, d is the TEXTURE_DEPTH
10088          and b is the border width of the texture image being modified. Note
10089          that w, h, and d include twice the border width. */
10090         {
10091                 gl.textureSubImage3D(m_to_3D, 0, -1, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10092                                                          s_reference_format, s_reference_type, s_reference);
10093                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10094                                                                   "xoffset<-b, where b is the width of the TEXTURE_BORDER.");
10095
10096                 gl.textureSubImage3D(m_to_3D, 0, 1, 0, 0, s_reference_width + 1, s_reference_height, s_reference_depth,
10097                                                          s_reference_format, s_reference_type, s_reference);
10098                 is_ok &= CheckErrorAndLog(
10099                         m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10100                         "(xoffset+width)>(w-b), where w is the TEXTURE_WIDTH, b is the width of the TEXTURE_BORDER.");
10101
10102                 gl.textureSubImage3D(m_to_3D, 0, 0, -1, 0, s_reference_width, s_reference_height, s_reference_depth,
10103                                                          s_reference_format, s_reference_type, s_reference);
10104                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10105                                                                   "yoffset<-b, where b is the width of the TEXTURE_BORDER.");
10106
10107                 gl.textureSubImage3D(m_to_3D, 0, 0, 1, 0, s_reference_width + 1, s_reference_height, s_reference_depth,
10108                                                          s_reference_format, s_reference_type, s_reference);
10109                 is_ok &= CheckErrorAndLog(
10110                         m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10111                         "(yoffset+height)>(h-b), where h is the TEXTURE_HEIGHT, b is the width of the TEXTURE_BORDER.");
10112
10113                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, -1, s_reference_width, s_reference_height, s_reference_depth,
10114                                                          s_reference_format, s_reference_type, s_reference);
10115                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10116                                                                   "zoffset<-b, where b is the depth of the TEXTURE_BORDER.");
10117
10118                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 1, s_reference_width + 1, s_reference_height, s_reference_depth,
10119                                                          s_reference_format, s_reference_type, s_reference);
10120                 is_ok &= CheckErrorAndLog(
10121                         m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10122                         "(zoffset+width)>(d-b), where d is the TEXTURE_DEPTH, b is the width of the TEXTURE_BORDER.");
10123         }
10124
10125         /*Check that INVALID_VALUE is generated by TextureSubImage3D if width or height or depth is less than 0. */
10126         {
10127 #ifndef TURN_OFF_SUB_IMAGE_ERRORS_TEST_OF_NEGATIVE_WIDTH_HEIGHT_OR_DEPTH
10128                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, -1, s_reference_height, s_reference_depth, s_reference_format,
10129                                                          s_reference_type, s_reference);
10130                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D", "width is less than 0.");
10131
10132                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, -1, s_reference_depth, s_reference_format,
10133                                                          s_reference_type, s_reference);
10134                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D", "height is less than 0.");
10135
10136                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, -1, s_reference_format,
10137                                                          s_reference_type, s_reference);
10138                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D", "depth is less than 0.");
10139 #endif
10140         }
10141
10142         /* Check that INVALID_OPERATION is generated by TextureSubImage3D if type
10143          is one of UNSIGNED_BYTE_3_3_2, UNSIGNED_BYTE_2_3_3_REV,
10144          UNSIGNED_SHORT_5_6_5, or UNSIGNED_SHORT_5_6_5_REV and format is not RGB. */
10145         {
10146                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10147                                                          s_reference_format, GL_UNSIGNED_BYTE_3_3_2, s_reference);
10148                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10149                                                                   "type is UNSIGNED_BYTE_3_3_2 and format is not RGB.");
10150
10151                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10152                                                          s_reference_format, GL_UNSIGNED_BYTE_2_3_3_REV, s_reference);
10153                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10154                                                                   "type is UNSIGNED_BYTE_2_3_3_REV and format is not RGB.");
10155
10156                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10157                                                          s_reference_format, GL_UNSIGNED_SHORT_5_6_5, s_reference);
10158                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10159                                                                   "type is UNSIGNED_SHORT_5_6_5 and format is not RGB.");
10160
10161                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10162                                                          s_reference_format, GL_UNSIGNED_SHORT_5_6_5_REV, s_reference);
10163                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10164                                                                   "type is UNSIGNED_SHORT_5_6_5_REV and format is not RGB.");
10165         }
10166
10167         /* Check that INVALID_OPERATION is generated by TextureSubImage3D if type
10168          is one of UNSIGNED_SHORT_4_4_4_4, UNSIGNED_SHORT_4_4_4_4_REV,
10169          UNSIGNED_SHORT_5_5_5_1, UNSIGNED_SHORT_1_5_5_5_REV,
10170          UNSIGNED_INT_8_8_8_8, UNSIGNED_INT_8_8_8_8_REV, UNSIGNED_INT_10_10_10_2,
10171          or UNSIGNED_INT_2_10_10_10_REV and format is neither RGBA nor BGRA. */
10172         {
10173                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10174                                                          s_reference_format, GL_UNSIGNED_SHORT_4_4_4_4, s_reference);
10175                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10176                                                                   "type is UNSIGNED_SHORT_4_4_4_4 and format is neither RGBA nor BGRA.");
10177
10178                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10179                                                          s_reference_format, GL_UNSIGNED_SHORT_4_4_4_4_REV, s_reference);
10180                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10181                                                                   "type is UNSIGNED_SHORT_4_4_4_4_REV and format is neither RGBA nor BGRA.");
10182
10183                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10184                                                          s_reference_format, GL_UNSIGNED_SHORT_5_5_5_1, s_reference);
10185                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10186                                                                   "type is UNSIGNED_SHORT_5_5_5_1 and format is neither RGBA nor BGRA.");
10187
10188                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10189                                                          s_reference_format, GL_UNSIGNED_SHORT_1_5_5_5_REV, s_reference);
10190                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10191                                                                   "type is UNSIGNED_SHORT_1_5_5_5_REV and format is neither RGBA nor BGRA.");
10192
10193                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10194                                                          s_reference_format, GL_UNSIGNED_INT_8_8_8_8, s_reference);
10195                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10196                                                                   "type is UNSIGNED_INT_8_8_8_8 and format is neither RGBA nor BGRA.");
10197
10198                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10199                                                          s_reference_format, GL_UNSIGNED_INT_8_8_8_8_REV, s_reference);
10200                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10201                                                                   "type is UNSIGNED_INT_8_8_8_8_REV and format is neither RGBA nor BGRA.");
10202
10203                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10204                                                          s_reference_format, GL_UNSIGNED_INT_10_10_10_2, s_reference);
10205                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10206                                                                   "type is UNSIGNED_INT_10_10_10_2 and format is neither RGBA nor BGRA.");
10207
10208                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10209                                                          s_reference_format, GL_UNSIGNED_INT_2_10_10_10_REV, s_reference);
10210                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10211                                                                   "type is UNSIGNED_INT_2_10_10_10_REV and format is neither RGBA nor BGRA.");
10212         }
10213
10214         /* Check that INVALID_OPERATION is generated by TextureSubImage3D if a
10215          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
10216          and the buffer object's data store is currently mapped. */
10217         {
10218                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10219                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10220
10221                 gl.mapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
10222
10223                 if (GL_NO_ERROR == gl.getError())
10224                 {
10225                         gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10226                                                                  s_reference_format, s_reference_type, NULL);
10227                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10228                                                                           "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and "
10229                                                                           "the buffer object's data store is currently mapped.");
10230
10231                         gl.unmapBuffer(GL_PIXEL_UNPACK_BUFFER);
10232                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10233
10234                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10235                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10236                 }
10237         }
10238
10239         /* Check that INVALID_OPERATION is generated by TextureSubImage3D if a
10240          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
10241          and the data would be unpacked from the buffer object such that the
10242          memory reads required would exceed the data store size. */
10243         {
10244                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10245                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10246
10247                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10248                                                          s_reference_format, s_reference_type, (glw::GLubyte*)NULL + s_reference_size * 2);
10249                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10250                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and the "
10251                                                                   "data would be unpacked from the buffer object such that the memory reads required "
10252                                                                   "would exceed the data store size.");
10253
10254                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10255                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10256         }
10257
10258         /* Check that INVALID_OPERATION is generated by TextureSubImage3D if a
10259          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
10260          and pixels is not evenly divisible into the number of bytes needed to
10261          store in memory a datum indicated by type. */
10262         {
10263                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10264                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10265
10266                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10267                                                          s_reference_format, s_reference_type, (glw::GLubyte*)NULL + 1);
10268                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10269                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and pixels "
10270                                                                   "is not evenly divisible into the number of bytes needed to store in memory a datum "
10271                                                                   "indicated by type.");
10272
10273                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10274                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10275         }
10276
10277         return is_ok;
10278 }
10279
10280 /** @brief Test (negative) of TextureSubImage1DCompressed
10281  *
10282  *  @return Test result.
10283  */
10284 bool SubImageErrorsTest::Test1DCompressed()
10285 {
10286         /* Shortcut for GL functionality. */
10287         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10288
10289         /* Result. */
10290         bool is_ok = true;
10291
10292         /* Do tests only if compressed 1D textures are supported. */
10293         if (DE_NULL != m_reference_compressed_1D)
10294         {
10295                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage1D
10296                  if texture is not the name of an existing texture object. */
10297                 {
10298                         gl.compressedTextureSubImage1D(m_to_invalid, 0, 0, s_reference_width, m_reference_compressed_1D_format,
10299                                                                                    m_reference_compressed_1D_size, m_reference_compressed_1D);
10300                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage1D",
10301                                                                           "texture is not the name of an existing texture object.");
10302                 }
10303
10304                 /* Check that INVALID_ENUM is generated by CompressedTextureSubImage1D if
10305                  internalformat is not one of the generic compressed internal formats:
10306                  COMPRESSED_RED, COMPRESSED_RG, COMPRESSED_RGB, COMPRESSED_RGBA.
10307                  COMPRESSED_SRGB, or COMPRESSED_SRGB_ALPHA. */
10308                 {
10309                         /* GL_COMPRESSED_RG_RGTC2 is not 1D as specification says. */
10310                         gl.compressedTextureSubImage1D(m_to_1D_compressed, 0, 0, s_reference_width, GL_COMPRESSED_RG_RGTC2,
10311                                                                                    m_reference_compressed_1D_size, m_reference_compressed_1D);
10312                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glCompressedTextureSubImage1D",
10313                                                                           "internalformat is of the generic compressed internal formats: COMPRESSED_RED, "
10314                                                                           "COMPRESSED_RG, COMPRESSED_RGB, COMPRESSED_RGBA. COMPRESSED_SRGB, or "
10315                                                                           "COMPRESSED_SRGB_ALPHA.");
10316                 }
10317
10318                 /* Check that INVALID_OPERATION is generated if format does not match the
10319                  internal format of the texture image being modified, since these
10320                  commands do not provide for image format conversion. */
10321                 {
10322                         gl.compressedTextureSubImage1D(m_to_1D_compressed, 0, 0, s_reference_width,
10323                                                                                    m_not_matching_compressed_1D_format, m_not_matching_compressed_1D_size,
10324                                                                                    m_reference_compressed_1D);
10325                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage1D",
10326                                                                           "format does not match the internal format of the texture image being modified, "
10327                                                                           "since these commands do not provide for image format conversion.");
10328                 }
10329
10330                 /* Check that INVALID_VALUE is generated by CompressedTextureSubImage1D if
10331                  imageSize is not consistent with the format, dimensions, and contents of
10332                  the specified compressed image data. */
10333                 {
10334                         gl.compressedTextureSubImage1D(m_to_1D_compressed, 0, 0, s_reference_width,
10335                                                                                    m_reference_compressed_1D_format, m_reference_compressed_1D_size - 1,
10336                                                                                    m_reference_compressed_1D);
10337                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCompressedTextureSubImage1D",
10338                                                                           "imageSize is not consistent with the format, dimensions, and contents of the "
10339                                                                           "specified compressed image data.");
10340                 }
10341
10342                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage1D
10343                  if a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER
10344                  target and the buffer object's data store is currently mapped. */
10345                 {
10346                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10347                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10348
10349                         gl.mapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
10350
10351                         if (GL_NO_ERROR == gl.getError())
10352                         {
10353                                 gl.compressedTextureSubImage1D(m_to_1D_compressed, 0, 0, s_reference_width,
10354                                                                                            m_reference_compressed_1D_format, m_reference_compressed_1D_size, NULL);
10355                                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage1D",
10356                                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target "
10357                                                                                   "and the buffer object's data store is currently mapped.");
10358
10359                                 gl.unmapBuffer(GL_PIXEL_UNPACK_BUFFER);
10360                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10361
10362                                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10363                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10364                         }
10365                 }
10366
10367                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage1D
10368                  if a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER
10369                  target and the data would be unpacked from the buffer object such that
10370                  the memory reads required would exceed the data store size. */
10371                 {
10372                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10373                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10374
10375                         gl.compressedTextureSubImage1D(m_to_1D_compressed, 0, 0, s_reference_width,
10376                                                                                    m_reference_compressed_1D_format, m_reference_compressed_1D_size,
10377                                                                                    (glw::GLubyte*)NULL + s_reference_size * 2);
10378                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage1D",
10379                                                                           "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and "
10380                                                                           "the buffer object's data store is currently mapped.");
10381
10382                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10383                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10384                 }
10385         }
10386
10387         return is_ok;
10388 }
10389
10390 /** @brief Test (negative) of TextureSubImage2DCompressed
10391  *
10392  *  @return Test result.
10393  */
10394 bool SubImageErrorsTest::Test2DCompressed()
10395 {
10396         /* Shortcut for GL functionality. */
10397         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10398
10399         /* Result. */
10400         bool is_ok = true;
10401
10402         /* Do tests only if compressed 2D textures are supported. */
10403         if (DE_NULL != m_reference_compressed_2D)
10404         {
10405                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage2D
10406                  if texture is not the name of an existing texture object. */
10407                 {
10408                         gl.compressedTextureSubImage2D(m_to_invalid, 0, 0, 0, s_reference_width, s_reference_height,
10409                                                                                    m_reference_compressed_2D_format, m_reference_compressed_2D_size,
10410                                                                                    m_reference_compressed_2D);
10411                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage2D",
10412                                                                           "texture is not the name of an existing texture object.");
10413                 }
10414
10415                 /* Check that INVALID_ENUM is generated by CompressedTextureSubImage2D if
10416                  internalformat is of the generic compressed internal formats:
10417                  COMPRESSED_RED, COMPRESSED_RG, COMPRESSED_RGB, COMPRESSED_RGBA.
10418                  COMPRESSED_SRGB, or COMPRESSED_SRGB_ALPHA. */
10419                 {
10420                         gl.compressedTextureSubImage2D(m_to_2D_compressed, 0, 0, 0, s_reference_width, s_reference_height,
10421                                                                                    GL_COMPRESSED_RG, m_reference_compressed_2D_size, m_reference_compressed_2D);
10422                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glCompressedTextureSubImage2D",
10423                                                                           "internalformat is of the generic compressed internal formats: COMPRESSED_RED, "
10424                                                                           "COMPRESSED_RG, COMPRESSED_RGB, COMPRESSED_RGBA. COMPRESSED_SRGB, or "
10425                                                                           "COMPRESSED_SRGB_ALPHA.");
10426                 }
10427
10428                 /* Check that INVALID_OPERATION is generated if format does not match the
10429                  internal format of the texture image being modified, since these
10430                  commands do not provide for image format conversion. */
10431                 {
10432                         gl.compressedTextureSubImage2D(m_to_2D_compressed, 0, 0, 0, s_reference_width, s_reference_height,
10433                                                                                    m_not_matching_compressed_2D_format, m_not_matching_compressed_2D_size,
10434                                                                                    m_reference_compressed_2D);
10435                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage2D",
10436                                                                           "format does not match the internal format of the texture image being modified, "
10437                                                                           "since these commands do not provide for image format conversion.");
10438                 }
10439
10440                 /* Check that INVALID_VALUE is generated by CompressedTextureSubImage2D if
10441                  imageSize is not consistent with the format, dimensions, and contents of
10442                  the specified compressed image data. */
10443                 {
10444                         gl.compressedTextureSubImage2D(m_to_2D_compressed, 0, 0, 0, s_reference_width, s_reference_height,
10445                                                                                    m_reference_compressed_2D_format, m_reference_compressed_2D_size - 1,
10446                                                                                    m_reference_compressed_2D);
10447                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCompressedTextureSubImage2D",
10448                                                                           "imageSize is not consistent with the format, dimensions, and contents of the "
10449                                                                           "specified compressed image data.");
10450                 }
10451
10452                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage2D
10453                  if a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER
10454                  target and the buffer object's data store is currently mapped. */
10455                 {
10456                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10457                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10458
10459                         gl.mapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
10460
10461                         if (GL_NO_ERROR == gl.getError())
10462                         {
10463                                 gl.compressedTextureSubImage2D(m_to_2D_compressed, 0, 0, 0, s_reference_width, s_reference_height,
10464                                                                                            m_reference_compressed_2D_format, m_reference_compressed_2D_size, NULL);
10465                                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage2D",
10466                                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target "
10467                                                                                   "and the buffer object's data store is currently mapped.");
10468
10469                                 gl.unmapBuffer(GL_PIXEL_UNPACK_BUFFER);
10470                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10471
10472                                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10473                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10474                         }
10475                 }
10476
10477                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage2D
10478                  if a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER
10479                  target and the data would be unpacked from the buffer object such that
10480                  the memory reads required would exceed the data store size. */
10481                 {
10482                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10483                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10484
10485                         gl.compressedTextureSubImage2D(m_to_2D_compressed, 0, 0, 0, s_reference_width, s_reference_height,
10486                                                                                    m_reference_compressed_2D_format, m_reference_compressed_2D_size,
10487                                                                                    (glw::GLubyte*)NULL + s_reference_size * 2);
10488                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage2D",
10489                                                                           "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and "
10490                                                                           "the buffer object's data store is currently mapped.");
10491
10492                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10493                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10494                 }
10495
10496                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage2D
10497                  if the effective target is TEXTURE_RECTANGLE. */
10498                 if (DE_NULL !=
10499                         m_reference_compressed_rectangle) /* Do test only if rectangle compressed texture is supported by the implementation. */
10500                 {
10501                         gl.compressedTextureSubImage2D(m_to_rectangle_compressed, 0, 0, 0, s_reference_width, s_reference_height,
10502                                                                                    m_reference_compressed_rectangle_format,
10503                                                                                    m_reference_compressed_rectangle_size, m_reference_compressed_rectangle);
10504
10505                         if (m_context.getContextInfo().isExtensionSupported("GL_NV_texture_rectangle_compressed"))
10506                         {
10507                                 is_ok &= CheckErrorAndLog(m_context, GL_NO_ERROR, "glCompressedTextureSubImage2D",
10508                                                                                   "a rectangle texture object is used with this function.");
10509                         }
10510                         else
10511                         {
10512                                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage2D",
10513                                                                                   "a rectangle texture object is used with this function.");
10514                         }
10515                 }
10516         }
10517
10518         return is_ok;
10519 }
10520
10521 /** @brief Test (negative) of TextureSubImage3DCompressed
10522  *
10523  *  @return Test result.
10524  */
10525 bool SubImageErrorsTest::Test3DCompressed()
10526 {
10527         /* Shortcut for GL functionality. */
10528         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10529
10530         /* Result. */
10531         bool is_ok = true;
10532
10533         /* Do tests only if compressed 3D textures are supported. */
10534         if (DE_NULL != m_reference_compressed_3D)
10535         {
10536                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage3D
10537                  if texture is not the name of an existing texture object. */
10538                 {
10539                         gl.compressedTextureSubImage3D(m_to_invalid, 0, 0, 0, 0, s_reference_width, s_reference_height,
10540                                                                                    s_reference_depth, m_reference_compressed_3D_format,
10541                                                                                    m_reference_compressed_3D_size, m_reference_compressed_3D);
10542                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage3D",
10543                                                                           "texture is not the name of an existing texture object.");
10544                 }
10545
10546                 /* Check that INVALID_ENUM is generated by CompressedTextureSubImage3D if
10547                  internalformat is of the generic compressed internal formats:
10548                  COMPRESSED_RED, COMPRESSED_RG, COMPRESSED_RGB, COMPRESSED_RGBA.
10549                  COMPRESSED_SRGB, or COMPRESSED_SRGB_ALPHA. */
10550                 {
10551                         gl.compressedTextureSubImage3D(m_to_3D_compressed, 0, 0, 0, 0, s_reference_width, s_reference_height,
10552                                                                                    s_reference_depth, GL_COMPRESSED_RG, m_reference_compressed_3D_size,
10553                                                                                    m_reference_compressed_3D);
10554                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glCompressedTextureSubImage3D",
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.compressedTextureSubImage3D(m_to_3D_compressed, 0, 0, 0, 0, s_reference_width, s_reference_height,
10565                                                                                    s_reference_depth, m_not_matching_compressed_3D_format,
10566                                                                                    m_not_matching_compressed_3D_size, m_reference_compressed_3D);
10567                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage3D",
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 CompressedTextureSubImage3D if
10573                  imageSize is not consistent with the format, dimensions, and contents of
10574                  the specified compressed image data. */
10575                 {
10576                         gl.compressedTextureSubImage3D(m_to_3D_compressed, 0, 0, 0, 0, s_reference_width, s_reference_height,
10577                                                                                    s_reference_depth, m_reference_compressed_3D_format,
10578                                                                                    m_reference_compressed_3D_size - 1, m_reference_compressed_3D);
10579                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCompressedTextureSubImage3D",
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 CompressedTextureSubImage3D
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.compressedTextureSubImage3D(m_to_3D_compressed, 0, 0, 0, 0, s_reference_width, s_reference_height,
10596                                                                                            s_reference_depth, m_reference_compressed_3D_format,
10597                                                                                            m_reference_compressed_3D_size, NULL);
10598                                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage3D",
10599                                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target "
10600                                                                                   "and the buffer object's data store is currently mapped.");
10601
10602                                 gl.unmapBuffer(GL_PIXEL_UNPACK_BUFFER);
10603                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10604
10605                                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10606                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10607                         }
10608                 }
10609
10610                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage3D
10611                  if a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER
10612                  target and the data would be unpacked from the buffer object such that
10613                  the memory reads required would exceed the data store size. */
10614                 {
10615                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10616                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10617
10618                         gl.compressedTextureSubImage3D(m_to_3D_compressed, 0, 0, 0, 0, s_reference_width, s_reference_height,
10619                                                                                    s_reference_depth, m_reference_compressed_3D_format,
10620                                                                                    m_reference_compressed_3D_size, (glw::GLubyte*)NULL + s_reference_size * 2);
10621                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage3D",
10622                                                                           "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and "
10623                                                                           "the buffer object's data store is currently mapped.");
10624
10625                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10626                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10627                 }
10628         }
10629
10630         return is_ok;
10631 }
10632
10633 /** @brief Clean GL objects, test variables and GL errors.
10634  */
10635 void SubImageErrorsTest::Clean()
10636 {
10637         /* Shortcut for GL functionality. */
10638         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10639
10640         /* Cleanup. */
10641         if (m_to_1D_empty)
10642         {
10643                 gl.deleteTextures(1, &m_to_1D_empty);
10644
10645                 m_to_1D_empty = 0;
10646         }
10647
10648         if (m_to_2D_empty)
10649         {
10650                 gl.deleteTextures(1, &m_to_2D_empty);
10651
10652                 m_to_2D_empty = 0;
10653         }
10654
10655         if (m_to_3D_empty)
10656         {
10657                 gl.deleteTextures(1, &m_to_3D_empty);
10658
10659                 m_to_3D_empty = 0;
10660         }
10661
10662         if (m_to_1D)
10663         {
10664                 gl.deleteTextures(1, &m_to_1D);
10665
10666                 m_to_1D = 0;
10667         }
10668
10669         if (m_to_2D)
10670         {
10671                 gl.deleteTextures(1, &m_to_2D);
10672
10673                 m_to_2D = 0;
10674         }
10675
10676         if (m_to_3D)
10677         {
10678                 gl.deleteTextures(1, &m_to_3D);
10679
10680                 m_to_3D = 0;
10681         }
10682
10683         if (m_to_1D_compressed)
10684         {
10685                 gl.deleteTextures(1, &m_to_1D_compressed);
10686
10687                 m_to_1D_compressed = 0;
10688         }
10689
10690         if (m_to_2D_compressed)
10691         {
10692                 gl.deleteTextures(1, &m_to_2D_compressed);
10693
10694                 m_to_2D_compressed = 0;
10695         }
10696
10697         if (m_to_3D_compressed)
10698         {
10699                 gl.deleteTextures(1, &m_to_3D_compressed);
10700
10701                 m_to_3D_compressed = 0;
10702         }
10703
10704         if (m_to_rectangle_compressed)
10705         {
10706                 gl.deleteTextures(1, &m_to_rectangle_compressed);
10707
10708                 m_to_rectangle_compressed = 0;
10709         }
10710
10711         if (m_bo)
10712         {
10713                 gl.deleteBuffers(1, &m_bo);
10714
10715                 m_bo = 0;
10716         }
10717
10718         m_to_invalid       = 0;
10719         m_format_invalid   = 0;
10720         m_type_invalid   = 0;
10721         m_max_texture_size = 1;
10722
10723         if (DE_NULL != m_reference_compressed_1D)
10724         {
10725                 delete[] m_reference_compressed_1D;
10726
10727                 m_reference_compressed_1D = NULL;
10728         }
10729
10730         if (DE_NULL != m_reference_compressed_2D)
10731         {
10732                 delete[] m_reference_compressed_2D;
10733
10734                 m_reference_compressed_2D = NULL;
10735         }
10736
10737         if (DE_NULL != m_reference_compressed_3D)
10738         {
10739                 delete[] m_reference_compressed_3D;
10740
10741                 m_reference_compressed_3D = NULL;
10742         }
10743
10744         if (DE_NULL != m_reference_compressed_rectangle)
10745         {
10746                 delete[] m_reference_compressed_rectangle;
10747
10748                 m_reference_compressed_rectangle = NULL;
10749         }
10750
10751         m_reference_compressed_1D_format                = 0;
10752         m_reference_compressed_2D_format                = 0;
10753         m_reference_compressed_3D_format                = 0;
10754         m_reference_compressed_rectangle_format = 0;
10755         m_reference_compressed_1D_size                  = 0;
10756         m_reference_compressed_2D_size                  = 0;
10757         m_reference_compressed_3D_size                  = 0;
10758         m_reference_compressed_rectangle_size   = 0;
10759         m_not_matching_compressed_1D_format             = 0;
10760         m_not_matching_compressed_1D_size               = 0;
10761         m_not_matching_compressed_2D_format             = 0;
10762         m_not_matching_compressed_2D_size               = 0;
10763         m_not_matching_compressed_3D_format             = 0;
10764         m_not_matching_compressed_3D_size               = 0;
10765
10766         while (GL_NO_ERROR != gl.getError())
10767                 ;
10768 }
10769
10770 /** Reference data */
10771 const glw::GLushort SubImageErrorsTest::s_reference[] = {
10772         0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
10773         0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
10774         0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
10775         0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff,
10776
10777         0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
10778         0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
10779         0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
10780         0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff,
10781
10782         0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
10783         0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
10784         0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
10785         0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff,
10786
10787         0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
10788         0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
10789         0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
10790         0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff
10791 };
10792
10793 /** Reference data parameters. */
10794 const glw::GLuint SubImageErrorsTest::s_reference_size                                          = sizeof(s_reference);
10795 const glw::GLuint SubImageErrorsTest::s_reference_width                                         = 4;
10796 const glw::GLuint SubImageErrorsTest::s_reference_height                                        = 4;
10797 const glw::GLuint SubImageErrorsTest::s_reference_depth                                         = 4;
10798 const glw::GLenum SubImageErrorsTest::s_reference_internalformat                        = GL_RG8;
10799 const glw::GLenum SubImageErrorsTest::s_reference_internalformat_compressed = GL_COMPRESSED_RG;
10800 const glw::GLenum SubImageErrorsTest::s_reference_format = GL_RG; /* !Must not be a RGB, RGBA, or BGRA */
10801 const glw::GLenum SubImageErrorsTest::s_reference_type   = GL_UNSIGNED_SHORT;
10802
10803 /******************************** Copy Errors Test Implementation   ********************************/
10804
10805 /** @brief Copy Errors Test constructor.
10806  *
10807  *  @param [in] context     OpenGL context.
10808  */
10809 CopyErrorsTest::CopyErrorsTest(deqp::Context& context)
10810         : deqp::TestCase(context, "textures_copy_errors", "Texture Copy Errors Test")
10811         , m_fbo(0)
10812         , m_fbo_ms(0)
10813         , m_fbo_incomplete(0)
10814         , m_to_src(0)
10815         , m_to_src_ms(0)
10816         , m_to_1D_dst(0)
10817         , m_to_2D_dst(0)
10818         , m_to_3D_dst(0)
10819         , m_to_invalid(0)
10820 {
10821         /* Intentionally left blank. */
10822 }
10823
10824 /** @brief Iterate Copy Errors Test cases.
10825  *
10826  *  @return Iteration result.
10827  */
10828 tcu::TestNode::IterateResult CopyErrorsTest::iterate()
10829 {
10830         /* Get context setup. */
10831         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
10832         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
10833
10834         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
10835         {
10836                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
10837
10838                 return STOP;
10839         }
10840
10841         /* Running tests. */
10842         bool is_ok      = true;
10843         bool is_error = false;
10844
10845         try
10846         {
10847                 Prepare();
10848
10849                 is_ok &= Test1D();
10850                 is_ok &= Test2D();
10851                 is_ok &= Test3D();
10852         }
10853         catch (...)
10854         {
10855                 is_ok   = false;
10856                 is_error = true;
10857         }
10858
10859         /* Cleanup. */
10860         Clean();
10861
10862         /* Result's setup. */
10863         if (is_ok)
10864         {
10865                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
10866         }
10867         else
10868         {
10869                 if (is_error)
10870                 {
10871                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
10872                 }
10873                 else
10874                 {
10875                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
10876                 }
10877         }
10878
10879         return STOP;
10880 }
10881
10882 /** @brief Prepare test's objects and values.
10883  */
10884 void CopyErrorsTest::Prepare()
10885 {
10886         /* Shortcut for GL functionality. */
10887         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10888
10889         /* Auxiliary objects setup. */
10890
10891         /* Framebuffer. */
10892         gl.genFramebuffers(1, &m_fbo);
10893         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
10894
10895         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
10896         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
10897
10898         gl.createTextures(GL_TEXTURE_2D, 1, &m_to_src);
10899         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
10900
10901         gl.textureStorage2D(m_to_src, 1, s_internalformat, s_width, s_height);
10902         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2D has failed");
10903
10904         gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_to_src, 0);
10905         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture1D call failed.");
10906
10907         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
10908         {
10909                 throw 0;
10910         }
10911
10912         gl.viewport(0, 0, s_width, s_height);
10913         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
10914
10915         gl.clear(GL_COLOR_BUFFER_BIT);
10916         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
10917
10918         /* Framebuffer Multisample. */
10919         gl.genFramebuffers(1, &m_fbo_ms);
10920         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
10921
10922         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
10923         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
10924
10925         gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &m_to_src_ms);
10926         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
10927
10928         gl.textureStorage2DMultisample(m_to_src_ms, 1, s_internalformat, s_width, s_height, false);
10929         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2DMultisample has failed");
10930
10931         gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, m_to_src_ms, 0);
10932         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture1D call failed.");
10933
10934         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
10935         {
10936                 throw 0;
10937         }
10938
10939         gl.viewport(0, 0, s_width, s_height);
10940         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
10941
10942         gl.clear(GL_COLOR_BUFFER_BIT);
10943         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
10944
10945         /* Framebuffer Incomplete. */
10946         gl.createFramebuffers(1, &m_fbo_incomplete);
10947         GLU_EXPECT_NO_ERROR(gl.getError(), "glcreateFramebuffers call failed.");
10948
10949         /* 1D */
10950         gl.createTextures(GL_TEXTURE_1D, 1, &m_to_1D_dst);
10951         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
10952
10953         gl.textureStorage1D(m_to_1D_dst, 1, s_internalformat, s_width);
10954         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2D has failed");
10955
10956         /* 2D */
10957         gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D_dst);
10958         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
10959
10960         gl.textureStorage2D(m_to_2D_dst, 1, s_internalformat, s_width, s_height);
10961         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2D has failed");
10962
10963         /* 3D */
10964         gl.createTextures(GL_TEXTURE_3D, 1, &m_to_3D_dst);
10965         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
10966
10967         gl.textureStorage3D(m_to_3D_dst, 1, s_internalformat, s_width, s_height, s_depth);
10968         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2D has failed");
10969
10970         /* invalid texture object */
10971         while (gl.isTexture(++m_to_invalid))
10972                 ;
10973         GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed");
10974 }
10975
10976 /** @brief Test (negative) of CopyTextureSubImage1D
10977  *
10978  *  @return Test result.
10979  */
10980 bool CopyErrorsTest::Test1D()
10981 {
10982         /* Shortcut for GL functionality. */
10983         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10984
10985         /* Result. */
10986         bool is_ok = true;
10987
10988         /* Bind framebuffer. */
10989         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_incomplete);
10990         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
10991
10992         /* Check that INVALID_FRAMEBUFFER_OPERATION is generated by
10993          CopyTextureSubImage1D if the object bound to READ_FRAMEBUFFER_BINDING is
10994          not framebuffer complete. */
10995         {
10996                 gl.copyTextureSubImage1D(m_to_1D_dst, 0, 0, 0, 0, s_width);
10997                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_FRAMEBUFFER_OPERATION, "glCopyTextureSubImage1D",
10998                                                                   "the object bound to READ_FRAMEBUFFER_BINDING is not framebuffer complete.");
10999         }
11000
11001         /* Bind framebuffer. */
11002         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
11003         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11004
11005         gl.readBuffer(GL_COLOR_ATTACHMENT0);
11006         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11007
11008         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage1D if
11009          texture is not the name of an existing texture object, or if the
11010          effective target of texture is not TEXTURE_1D. */
11011         {
11012                 gl.copyTextureSubImage1D(m_to_invalid, 0, 0, 0, 0, s_width);
11013                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage1D",
11014                                                                   "texture is not the name of an existing texture object.");
11015
11016                 gl.copyTextureSubImage1D(m_to_2D_dst, 0, 0, 0, 0, s_width);
11017                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage1D",
11018                                                                   "the effective target of texture is not TEXTURE_1D.");
11019         }
11020
11021         /* Check that INVALID_VALUE is generated by CopyTextureSubImage1D if level is less than 0. */
11022         {
11023                 gl.copyTextureSubImage1D(m_to_1D_dst, -1, 0, 0, 0, s_width);
11024                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage1D", "level is less than 0.");
11025         }
11026
11027         /* Check that INVALID_VALUE is generated by CopyTextureSubImage1D if
11028          xoffset<0, or (xoffset+width)>w, where w is the TEXTURE_WIDTH of the
11029          texture image being modified. */
11030         {
11031                 gl.copyTextureSubImage1D(m_to_1D_dst, 0, -1, 0, 0, s_width);
11032                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage1D", "xoffset<0.");
11033
11034                 gl.copyTextureSubImage1D(m_to_1D_dst, 0, 1, 0, 0, s_width);
11035                 is_ok &=
11036                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage1D",
11037                                                          "(xoffset+width)>w, where w is the TEXTURE_WIDTH of the texture image being modified.");
11038         }
11039
11040         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage1D if
11041          the read buffer is NONE. */
11042         gl.readBuffer(GL_NONE);
11043         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11044
11045         {
11046                 gl.copyTextureSubImage1D(m_to_1D_dst, 0, 0, 0, 0, s_width);
11047                 is_ok &=
11048                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage1D", "the read buffer is NONE.");
11049         }
11050
11051         /* Bind multisample framebuffer. */
11052         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
11053         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11054
11055         gl.readBuffer(GL_COLOR_ATTACHMENT0);
11056         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11057
11058         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage1D if
11059          the effective value of SAMPLE_BUFFERS for the read
11060          framebuffer is one. */
11061         {
11062                 gl.copyTextureSubImage1D(m_to_1D_dst, 0, 0, 0, 0, s_width);
11063                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage1D",
11064                                                                   "the effective value of SAMPLE_BUFFERS for the read framebuffer is one.");
11065         }
11066
11067         return is_ok;
11068 }
11069
11070 /** @brief Test (negative) of CopyTextureSubImage2D
11071  *
11072  *  @return Test result.
11073  */
11074 bool CopyErrorsTest::Test2D()
11075 {
11076         /* Shortcut for GL functionality. */
11077         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11078
11079         /* Result. */
11080         bool is_ok = true;
11081
11082         /* Bind framebuffer. */
11083         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_incomplete);
11084         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11085
11086         /* Check that INVALID_FRAMEBUFFER_OPERATION is generated by
11087          CopyTextureSubImage2D if the object bound to READ_FRAMEBUFFER_BINDING is
11088          not framebuffer complete. */
11089         {
11090                 gl.copyTextureSubImage2D(m_to_2D_dst, 0, 0, 0, 0, 0, s_width, s_height);
11091                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_FRAMEBUFFER_OPERATION, "glCopyTextureSubImage2D",
11092                                                                   "the object bound to READ_FRAMEBUFFER_BINDING is not framebuffer complete.");
11093         }
11094
11095         /* Bind framebuffer. */
11096         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
11097         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11098
11099         gl.readBuffer(GL_COLOR_ATTACHMENT0);
11100         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11101
11102         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage2D if
11103          texture is not the name of an existing texture object, or if the
11104          effective target of texture is not TEXTURE_2D. */
11105         {
11106                 gl.copyTextureSubImage2D(m_to_invalid, 0, 0, 0, 0, 0, s_width, s_height);
11107                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage2D",
11108                                                                   "texture is not the name of an existing texture object.");
11109
11110                 gl.copyTextureSubImage2D(m_to_1D_dst, 0, 0, 0, 0, 0, s_width, s_height);
11111                 is_ok &= CheckErrorAndLog(
11112                         m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage2D",
11113                         "the effective target of does not correspond to one of the texture targets supported by the function..");
11114         }
11115
11116         /* Check that INVALID_VALUE is generated by CopyTextureSubImage2D if level is less than 0. */
11117         {
11118                 gl.copyTextureSubImage2D(m_to_2D_dst, -1, 0, 0, 0, 0, s_width, s_height);
11119                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage2D", "level is less than 0.");
11120         }
11121
11122         /* Check that INVALID_VALUE is generated by CopyTextureSubImage2D if
11123          xoffset<0, (xoffset+width)>w, yoffset<0, or (yoffset+height)>0, where w
11124          is the TEXTURE_WIDTH, h is the TEXTURE_HEIGHT and of the texture image
11125          being modified. */
11126         {
11127                 gl.copyTextureSubImage2D(m_to_2D_dst, 0, -1, 0, 0, 0, s_width, s_height);
11128                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage2D", "xoffset<0.");
11129
11130                 gl.copyTextureSubImage2D(m_to_2D_dst, 0, 1, 0, 0, 0, s_width, s_height);
11131                 is_ok &=
11132                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage2D",
11133                                                          "(xoffset+width)>w, where w is the TEXTURE_WIDTH of the texture image being modified.");
11134
11135                 gl.copyTextureSubImage2D(m_to_2D_dst, 0, 0, -1, 0, 0, s_width, s_height);
11136                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage2D", "yoffset<0.");
11137
11138                 gl.copyTextureSubImage2D(m_to_2D_dst, 0, 0, 1, 0, 0, s_width, s_height);
11139                 is_ok &=
11140                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage2D",
11141                                                          "(yoffset+height)>h, where h is the TEXTURE_HEIGHT of the texture image being modified.");
11142         }
11143
11144         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage2D if
11145          the read buffer is NONE. */
11146         gl.readBuffer(GL_NONE);
11147         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11148
11149         {
11150                 gl.copyTextureSubImage2D(m_to_2D_dst, 0, 0, 0, 0, 0, s_width, s_height);
11151                 is_ok &=
11152                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage2D", "the read buffer is NONE.");
11153         }
11154
11155         /* Bind multisample framebuffer. */
11156         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
11157         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11158
11159         gl.readBuffer(GL_COLOR_ATTACHMENT0);
11160         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11161
11162         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage2D if
11163          the effective value of SAMPLE_BUFFERS for the read
11164          framebuffer is one. */
11165         {
11166                 gl.copyTextureSubImage2D(m_to_2D_dst, 0, 0, 0, 0, 0, s_width, s_height);
11167                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage2D",
11168                                                                   "the effective value of SAMPLE_BUFFERS for the read framebuffer is one.");
11169         }
11170
11171         return is_ok;
11172 }
11173
11174 /** @brief Test (negative) of CopyTextureSubImage3D
11175  *
11176  *  @return Test result.
11177  */
11178 bool CopyErrorsTest::Test3D()
11179 {
11180         /* Shortcut for GL functionality. */
11181         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11182
11183         /* Result. */
11184         bool is_ok = true;
11185
11186         /* Bind framebuffer. */
11187         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_incomplete);
11188         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11189
11190         /* Check that INVALID_FRAMEBUFFER_OPERATION is generated by
11191          CopyTextureSubImage3D if the object bound to READ_FRAMEBUFFER_BINDING is
11192          not framebuffer complete. */
11193         {
11194                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, 0, 0, 0, 0, s_width, s_height);
11195                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_FRAMEBUFFER_OPERATION, "glCopyTextureSubImage3D",
11196                                                                   "the object bound to READ_FRAMEBUFFER_BINDING is not framebuffer complete.");
11197         }
11198
11199         /* Bind framebuffer. */
11200         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
11201         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11202
11203         gl.readBuffer(GL_COLOR_ATTACHMENT0);
11204         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11205
11206         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage3D if
11207          texture is not the name of an existing texture object, or if the
11208          effective target of texture is not supported by the function. */
11209         {
11210                 gl.copyTextureSubImage3D(m_to_invalid, 0, 0, 0, 0, 0, 0, s_width, s_height);
11211                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage3D",
11212                                                                   "texture is not the name of an existing texture object.");
11213
11214                 gl.copyTextureSubImage3D(m_to_1D_dst, 0, 0, 0, 0, 0, 0, s_width, s_height);
11215                 is_ok &= CheckErrorAndLog(
11216                         m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage3D",
11217                         "the effective target of does not correspond to one of the texture targets supported by the function..");
11218         }
11219
11220         /* Check that INVALID_VALUE is generated by CopyTextureSubImage3D if level is less than 0. */
11221         {
11222                 gl.copyTextureSubImage3D(m_to_3D_dst, -1, 0, 0, 0, 0, 0, s_width, s_height);
11223                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D", "level is less than 0.");
11224         }
11225
11226         /* Check that INVALID_VALUE is generated by CopyTextureSubImage3D if
11227          xoffset<0, (xoffset+width)>w, yoffset<0, (yoffset+height)>h, zoffset<0,
11228          or (zoffset+1)>d, where w is the TEXTURE_WIDTH, h is the TEXTURE_HEIGHT,
11229          d is the TEXTURE_DEPTH and of the texture image being modified. Note
11230          that w, h, and d include twice the border width.  */
11231         {
11232                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, -1, 0, 0, 0, 0, s_width, s_height);
11233                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D", "xoffset<0.");
11234
11235                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, 1, 0, 0, 0, 0, s_width, s_height);
11236                 is_ok &=
11237                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D",
11238                                                          "(xoffset+width)>w, where w is the TEXTURE_WIDTH of the texture image being modified.");
11239
11240                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, -1, 0, 0, 0, s_width, s_height);
11241                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D", "yoffset<0.");
11242
11243                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, 1, 0, 0, 0, s_width, s_height);
11244                 is_ok &=
11245                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D",
11246                                                          "(yoffset+height)>h, where h is the TEXTURE_HEIGHT of the texture image being modified.");
11247
11248                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, 0, -1, 0, 0, s_width, s_height);
11249                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D", "zoffset<0.");
11250
11251                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, 0, s_depth + 1, 0, 0, s_width, s_height);
11252                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D",
11253                                                                   "(zoffset+1)>d, where d is the TEXTURE_DEPTH of the texture image being modified.");
11254         }
11255
11256         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage3D if
11257          the read buffer is NONE. */
11258         gl.readBuffer(GL_NONE);
11259         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11260
11261         {
11262                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, 0, 0, 0, 0, s_width, s_height);
11263                 is_ok &=
11264                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage3D", "the read buffer is NONE.");
11265         }
11266
11267         /* Bind multisample framebuffer. */
11268         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
11269         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11270
11271         gl.readBuffer(GL_COLOR_ATTACHMENT0);
11272         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11273
11274         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage3D if
11275          the effective value of SAMPLE_BUFFERS for the read
11276          framebuffer is one. */
11277         {
11278                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, 0, 0, 0, 0, s_width, s_height);
11279                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage3D",
11280                                                                   "the effective value of SAMPLE_BUFFERS for the read framebuffer is one.");
11281         }
11282
11283         return is_ok;
11284 }
11285
11286 /** @brief Clean GL objects, test variables and GL errors.
11287  */
11288 void CopyErrorsTest::Clean()
11289 {
11290         /* Shortcut for GL functionality. */
11291         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11292
11293         /* Cleanup. */
11294         if (m_fbo)
11295         {
11296                 gl.deleteFramebuffers(1, &m_fbo);
11297
11298                 m_fbo = 0;
11299         }
11300
11301         if (m_fbo_ms)
11302         {
11303                 gl.deleteFramebuffers(1, &m_fbo_ms);
11304
11305                 m_fbo_ms = 0;
11306         }
11307
11308         if (m_fbo_incomplete)
11309         {
11310                 gl.deleteFramebuffers(1, &m_fbo_incomplete);
11311
11312                 m_fbo_incomplete = 0;
11313         }
11314
11315         if (m_to_src)
11316         {
11317                 gl.deleteTextures(1, &m_to_src);
11318
11319                 m_to_src = 0;
11320         }
11321
11322         if (m_to_src_ms)
11323         {
11324                 gl.deleteTextures(1, &m_to_src_ms);
11325
11326                 m_to_src_ms = 0;
11327         }
11328
11329         if (m_to_1D_dst)
11330         {
11331                 gl.deleteTextures(1, &m_to_1D_dst);
11332
11333                 m_to_1D_dst = 0;
11334         }
11335
11336         if (m_to_2D_dst)
11337         {
11338                 gl.deleteTextures(1, &m_to_2D_dst);
11339
11340                 m_to_2D_dst = 0;
11341         }
11342
11343         if (m_to_3D_dst)
11344         {
11345                 gl.deleteTextures(1, &m_to_3D_dst);
11346
11347                 m_to_3D_dst = 0;
11348         }
11349
11350         m_to_invalid = 0;
11351
11352         while (GL_NO_ERROR != gl.getError())
11353                 ;
11354 }
11355
11356 /* Test's parameters. */
11357 const glw::GLuint CopyErrorsTest::s_width                  = 4;
11358 const glw::GLuint CopyErrorsTest::s_height                 = 4;
11359 const glw::GLuint CopyErrorsTest::s_depth                  = 4;
11360 const glw::GLuint CopyErrorsTest::s_internalformat = GL_RGBA8;
11361
11362 /******************************** Parameter Setup Errors Test Implementation   ********************************/
11363
11364 /** @brief Parameter Setup Errors Test constructor.
11365  *
11366  *  @param [in] context     OpenGL context.
11367  */
11368 ParameterSetupErrorsTest::ParameterSetupErrorsTest(deqp::Context& context)
11369         : deqp::TestCase(context, "textures_parameter_setup_errors", "Texture Parameter Setup Errors Test")
11370         , m_to_2D(0)
11371         , m_to_2D_ms(0)
11372         , m_to_rectangle(0)
11373         , m_to_invalid(0)
11374         , m_pname_invalid(0)
11375         , m_depth_stencil_mode_invalid(0)
11376 {
11377         /* Intentionally left blank. */
11378 }
11379
11380 /** @brief Iterate Parameter Setup Errors Test cases.
11381  *
11382  *  @return Iteration result.
11383  */
11384 tcu::TestNode::IterateResult ParameterSetupErrorsTest::iterate()
11385 {
11386         /* Get context setup. */
11387         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
11388         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
11389
11390         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
11391         {
11392                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
11393
11394                 return STOP;
11395         }
11396
11397         /* Running tests. */
11398         bool is_ok      = true;
11399         bool is_error = false;
11400
11401         try
11402         {
11403                 Prepare();
11404
11405                 is_ok &= Testf();
11406                 is_ok &= Testi();
11407                 is_ok &= Testfv();
11408                 is_ok &= Testiv();
11409                 is_ok &= TestIiv();
11410                 is_ok &= TestIuiv();
11411         }
11412         catch (...)
11413         {
11414                 is_ok   = false;
11415                 is_error = true;
11416         }
11417
11418         /* Cleanup. */
11419         Clean();
11420
11421         /* Result's setup. */
11422         if (is_ok)
11423         {
11424                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
11425         }
11426         else
11427         {
11428                 if (is_error)
11429                 {
11430                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
11431                 }
11432                 else
11433                 {
11434                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
11435                 }
11436         }
11437
11438         return STOP;
11439 }
11440
11441 /** @brief Test's preparations.
11442  */
11443 void ParameterSetupErrorsTest::Prepare()
11444 {
11445         /* Shortcut for GL functionality. */
11446         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11447
11448         /* Auxiliary objects setup. */
11449
11450         /* 2D */
11451         gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D);
11452         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
11453
11454         /* 3D */
11455         gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &m_to_2D_ms);
11456         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
11457
11458         /* RECTANGLE */
11459         gl.createTextures(GL_TEXTURE_RECTANGLE, 1, &m_to_rectangle);
11460         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
11461
11462         /* Invalid texture object. */
11463         while (gl.isTexture(++m_to_invalid))
11464                 ;
11465         GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed");
11466
11467         /* Invalid parameter name. */
11468         glw::GLenum all_pnames[] = { GL_DEPTH_STENCIL_TEXTURE_MODE,
11469                                                                  GL_TEXTURE_BASE_LEVEL,
11470                                                                  GL_TEXTURE_COMPARE_FUNC,
11471                                                                  GL_TEXTURE_COMPARE_MODE,
11472                                                                  GL_TEXTURE_LOD_BIAS,
11473                                                                  GL_TEXTURE_MIN_FILTER,
11474                                                                  GL_TEXTURE_MAG_FILTER,
11475                                                                  GL_TEXTURE_MIN_LOD,
11476                                                                  GL_TEXTURE_MAX_LOD,
11477                                                                  GL_TEXTURE_MAX_LEVEL,
11478                                                                  GL_TEXTURE_SWIZZLE_R,
11479                                                                  GL_TEXTURE_SWIZZLE_G,
11480                                                                  GL_TEXTURE_SWIZZLE_B,
11481                                                                  GL_TEXTURE_SWIZZLE_A,
11482                                                                  GL_TEXTURE_WRAP_S,
11483                                                                  GL_TEXTURE_WRAP_T,
11484                                                                  GL_TEXTURE_WRAP_R,
11485                                                                  GL_TEXTURE_BORDER_COLOR,
11486                                                                  GL_TEXTURE_SWIZZLE_RGBA };
11487         glw::GLuint all_pnames_count = sizeof(all_pnames) / sizeof(all_pnames[0]);
11488
11489         bool is_valid = true;
11490
11491         while (is_valid)
11492         {
11493                 is_valid = false;
11494                 ++m_pname_invalid;
11495
11496                 for (glw::GLuint i = 0; i < all_pnames_count; ++i)
11497                 {
11498                         if (all_pnames[i] == m_pname_invalid)
11499                         {
11500                                 is_valid = true;
11501
11502                                 break;
11503                         }
11504                 }
11505         }
11506
11507         /* Invalid depth stencil mode name. */
11508         glw::GLenum all_depth_stencil_modes[]    = { GL_DEPTH_COMPONENT, GL_STENCIL_INDEX };
11509         glw::GLuint all_depth_stencil_modes_count = sizeof(all_depth_stencil_modes) / sizeof(all_depth_stencil_modes[0]);
11510
11511         is_valid = true;
11512
11513         while (is_valid)
11514         {
11515                 is_valid = false;
11516                 ++m_depth_stencil_mode_invalid;
11517
11518                 for (glw::GLuint i = 0; i < all_depth_stencil_modes_count; ++i)
11519                 {
11520                         if (all_depth_stencil_modes[i] == m_depth_stencil_mode_invalid)
11521                         {
11522                                 is_valid = true;
11523
11524                                 break;
11525                         }
11526                 }
11527         }
11528 }
11529
11530 /** @brief Test (negative) of TextureParameterf
11531  *
11532  *  @return Test result.
11533  */
11534 bool ParameterSetupErrorsTest::Testf()
11535 {
11536         /* Shortcut for GL functionality. */
11537         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11538
11539         /* Result. */
11540         bool is_ok = true;
11541
11542         /* Check that INVALID_ENUM is generated by TextureParameter* if pname is
11543          not one of the accepted defined values. */
11544         {
11545                 gl.textureParameterf(m_to_2D, m_pname_invalid, 1.f);
11546
11547                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterf",
11548                                                                   "pname is not one of the accepted defined values.");
11549         }
11550
11551         /* Check that INVALID_ENUM is generated by TextureParameter* if params
11552          should have a defined constant value (based on the value of pname) and
11553          does not. */
11554         {
11555                 gl.textureParameterf(m_to_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, (glw::GLfloat)m_depth_stencil_mode_invalid);
11556
11557                 is_ok &=
11558                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterf",
11559                                                          "params should have a defined constant value (based on the value of pname) and does not.");
11560         }
11561         /* Check that INVALID_ENUM is generated if TextureParameter{if} is called
11562          for a non-scalar parameter (pname TEXTURE_BORDER_COLOR or
11563          TEXTURE_SWIZZLE_RGBA). */
11564         {
11565                 gl.textureParameterf(m_to_2D, GL_TEXTURE_BORDER_COLOR, 1.f);
11566
11567                 is_ok &=
11568                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterf",
11569                                                          "called for a non-scalar parameter (pname TEXTURE_BORDER_COLOR or TEXTURE_SWIZZLE_RGBA).");
11570         }
11571
11572         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11573          effective target is either TEXTURE_2D_MULTISAMPLE or
11574          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states. */
11575         {
11576                 gl.textureParameterf(m_to_2D_ms, GL_TEXTURE_LOD_BIAS, 1.f);
11577
11578                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterf",
11579                                                                   "the  effective target is either TEXTURE_2D_MULTISAMPLE or  "
11580                                                                   "TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states.");
11581         }
11582
11583         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11584          effective target is TEXTURE_RECTANGLE and either of pnames
11585          TEXTURE_WRAP_S or TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE,
11586          MIRRORED_REPEAT or REPEAT. */
11587         {
11588                 gl.textureParameterf(m_to_rectangle, GL_TEXTURE_WRAP_S, GL_MIRROR_CLAMP_TO_EDGE);
11589
11590                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterf",
11591                                                                   "the effective target is TEXTURE_RECTANGLE and either of pnames TEXTURE_WRAP_S or "
11592                                                                   "TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE, MIRRORED_REPEAT or REPEAT.");
11593         }
11594
11595         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11596          effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is
11597          set to a value other than NEAREST or LINEAR (no mipmap filtering is
11598          permitted). */
11599         {
11600                 gl.textureParameterf(m_to_rectangle, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
11601
11602                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterf",
11603                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is set to a "
11604                                                                   "value other than NEAREST or LINEAR (no mipmap filtering is permitted).");
11605         }
11606
11607         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
11608          effective target is either TEXTURE_2D_MULTISAMPLE or
11609          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname TEXTURE_BASE_LEVEL is set to a
11610          value other than zero. */
11611         {
11612                 gl.textureParameterf(m_to_2D_ms, GL_TEXTURE_BASE_LEVEL, 1.f);
11613
11614                 is_ok &=
11615                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterf",
11616                                                          "the effective target is either TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY, "
11617                                                          "and pname TEXTURE_BASE_LEVEL is set to a value other than zero.");
11618         }
11619
11620         /* Check that INVALID_OPERATION is generated by TextureParameter* if
11621          texture is not the name of an existing texture object. */
11622         {
11623                 gl.textureParameterf(m_to_invalid, GL_TEXTURE_LOD_BIAS, 1.f);
11624
11625                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterf",
11626                                                                   "texture is not the name of an existing texture object.");
11627         }
11628
11629         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
11630          effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is
11631          set to any value other than zero. */
11632         {
11633                 gl.textureParameterf(m_to_rectangle, GL_TEXTURE_BASE_LEVEL, 1.f);
11634
11635                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterf",
11636                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is set to "
11637                                                                   "any value other than zero. ");
11638         }
11639
11640         /* Check that INVALID_VALUE is generated by TextureParameter* if pname is
11641          TEXTURE_BASE_LEVEL or TEXTURE_MAX_LEVEL, and param or params is
11642          negative. */
11643         {
11644                 gl.textureParameterf(m_to_2D, GL_TEXTURE_BASE_LEVEL, -1.f);
11645
11646                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameterf",
11647                                                                   "pname is TEXTURE_BASE_LEVEL and param is negative.");
11648
11649                 gl.textureParameterf(m_to_2D, GL_TEXTURE_MAX_LEVEL, -1.f);
11650
11651                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameterf",
11652                                                                   "pname is TEXTURE_MAX_LEVEL and param is negative.");
11653         }
11654
11655         return is_ok;
11656 }
11657
11658 /** @brief Test (negative) of TextureParameteri
11659  *
11660  *  @return Test result.
11661  */
11662 bool ParameterSetupErrorsTest::Testi()
11663 {
11664         /* Shortcut for GL functionality. */
11665         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11666
11667         /* Result. */
11668         bool is_ok = true;
11669
11670         /* Check that INVALID_ENUM is generated by TextureParameter* if pname is
11671          not one of the accepted defined values. */
11672         {
11673                 gl.textureParameteri(m_to_2D, m_pname_invalid, 1);
11674
11675                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteri",
11676                                                                   "pname is not one of the accepted defined values.");
11677         }
11678
11679         /* Check that INVALID_ENUM is generated by TextureParameter* if params
11680          should have a defined constant value (based on the value of pname) and
11681          does not. */
11682         {
11683                 gl.textureParameteri(m_to_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, m_depth_stencil_mode_invalid);
11684
11685                 is_ok &=
11686                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteri",
11687                                                          "params should have a defined constant value (based on the value of pname) and does not.");
11688         }
11689         /* Check that INVALID_ENUM is generated if TextureParameter{if} is called
11690          for a non-scalar parameter (pname TEXTURE_BORDER_COLOR or
11691          TEXTURE_SWIZZLE_RGBA). */
11692         {
11693                 gl.textureParameteri(m_to_2D, GL_TEXTURE_BORDER_COLOR, 1);
11694
11695                 is_ok &=
11696                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteri",
11697                                                          "called for a non-scalar parameter (pname TEXTURE_BORDER_COLOR or TEXTURE_SWIZZLE_RGBA).");
11698         }
11699
11700         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11701          effective target is either TEXTURE_2D_MULTISAMPLE or
11702          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states. */
11703         {
11704                 gl.textureParameteri(m_to_2D_ms, GL_TEXTURE_LOD_BIAS, 1);
11705
11706                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteri",
11707                                                                   "the  effective target is either TEXTURE_2D_MULTISAMPLE or  "
11708                                                                   "TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states.");
11709         }
11710
11711         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11712          effective target is TEXTURE_RECTANGLE and either of pnames
11713          TEXTURE_WRAP_S or TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE,
11714          MIRRORED_REPEAT or REPEAT. */
11715         {
11716                 gl.textureParameteri(m_to_rectangle, GL_TEXTURE_WRAP_S, GL_MIRROR_CLAMP_TO_EDGE);
11717
11718                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteri",
11719                                                                   "the effective target is TEXTURE_RECTANGLE and either of pnames TEXTURE_WRAP_S or "
11720                                                                   "TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE, MIRRORED_REPEAT or REPEAT.");
11721         }
11722
11723         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11724          effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is
11725          set to a value other than NEAREST or LINEAR (no mipmap filtering is
11726          permitted). */
11727         {
11728                 gl.textureParameteri(m_to_rectangle, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
11729
11730                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteri",
11731                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is set to a "
11732                                                                   "value other than NEAREST or LINEAR (no mipmap filtering is permitted).");
11733         }
11734
11735         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
11736          effective target is either TEXTURE_2D_MULTISAMPLE or
11737          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname TEXTURE_BASE_LEVEL is set to a
11738          value other than zero. */
11739         {
11740                 gl.textureParameteri(m_to_2D_ms, GL_TEXTURE_BASE_LEVEL, 1);
11741
11742                 is_ok &=
11743                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteri",
11744                                                          "the effective target is either TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY, "
11745                                                          "and pname TEXTURE_BASE_LEVEL is set to a value other than zero.");
11746         }
11747
11748         /* Check that INVALID_OPERATION is generated by TextureParameter* if
11749          texture is not the name of an existing texture object. */
11750         {
11751                 gl.textureParameteri(m_to_invalid, GL_TEXTURE_LOD_BIAS, 1);
11752
11753                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteri",
11754                                                                   "texture is not the name of an existing texture object.");
11755         }
11756
11757         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
11758          effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is
11759          set to any value other than zero. */
11760         {
11761                 gl.textureParameteri(m_to_rectangle, GL_TEXTURE_BASE_LEVEL, 1);
11762
11763                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteri",
11764                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is set to "
11765                                                                   "any value other than zero. ");
11766         }
11767
11768         /* Check that INVALID_VALUE is generated by TextureParameter* if pname is
11769          TEXTURE_BASE_LEVEL or TEXTURE_MAX_LEVEL, and param or params is
11770          negative. */
11771         {
11772                 gl.textureParameteri(m_to_2D, GL_TEXTURE_BASE_LEVEL, -1);
11773
11774                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameteri",
11775                                                                   "pname is TEXTURE_BASE_LEVEL and param is negative.");
11776
11777                 gl.textureParameteri(m_to_2D, GL_TEXTURE_MAX_LEVEL, -1);
11778
11779                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameteri",
11780                                                                   "pname is TEXTURE_MAX_LEVEL and param is negative.");
11781         }
11782
11783         return is_ok;
11784 }
11785
11786 /** @brief Test (negative) of TextureParameterfv
11787  *
11788  *  @return Test result.
11789  */
11790 bool ParameterSetupErrorsTest::Testfv()
11791 {
11792         /* Shortcut for GL functionality. */
11793         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11794
11795         /* Result. */
11796         bool is_ok = true;
11797
11798         glw::GLfloat one                                                = 1.f;
11799         glw::GLfloat minus_one                                  = -1.f;
11800         glw::GLfloat depth_stencil_mode_invalid = (glw::GLfloat)m_depth_stencil_mode_invalid;
11801         glw::GLfloat wrap_invalid                               = (glw::GLfloat)GL_MIRROR_CLAMP_TO_EDGE;
11802         glw::GLfloat min_filter_invalid                 = (glw::GLfloat)GL_NEAREST_MIPMAP_NEAREST;
11803
11804         /* Check that INVALID_ENUM is generated by TextureParameter* if pname is
11805          not one of the accepted defined values. */
11806         {
11807                 gl.textureParameterfv(m_to_2D, m_pname_invalid, &one);
11808
11809                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterfv",
11810                                                                   "pname is not one of the accepted defined values.");
11811         }
11812
11813         /* Check that INVALID_ENUM is generated by TextureParameter* if params
11814          should have a defined constant value (based on the value of pname) and
11815          does not. */
11816         {
11817                 gl.textureParameterfv(m_to_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, &depth_stencil_mode_invalid);
11818
11819                 is_ok &=
11820                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterfv",
11821                                                          "params should have a defined constant value (based on the value of pname) and does not.");
11822         }
11823
11824         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11825          effective target is either TEXTURE_2D_MULTISAMPLE or
11826          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states. */
11827         {
11828                 gl.textureParameterfv(m_to_2D_ms, GL_TEXTURE_LOD_BIAS, &one);
11829
11830                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterfv",
11831                                                                   "the  effective target is either TEXTURE_2D_MULTISAMPLE or  "
11832                                                                   "TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states.");
11833         }
11834
11835         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11836          effective target is TEXTURE_RECTANGLE and either of pnames
11837          TEXTURE_WRAP_S or TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE,
11838          MIRRORED_REPEAT or REPEAT. */
11839         {
11840                 gl.textureParameterfv(m_to_rectangle, GL_TEXTURE_WRAP_S, &wrap_invalid);
11841
11842                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterfv",
11843                                                                   "the effective target is TEXTURE_RECTANGLE and either of pnames TEXTURE_WRAP_S or "
11844                                                                   "TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE, MIRRORED_REPEAT or REPEAT.");
11845         }
11846
11847         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11848          effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is
11849          set to a value other than NEAREST or LINEAR (no mipmap filtering is
11850          permitted). */
11851         {
11852                 gl.textureParameterfv(m_to_rectangle, GL_TEXTURE_MIN_FILTER, &min_filter_invalid);
11853
11854                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterfv",
11855                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is set to a "
11856                                                                   "value other than NEAREST or LINEAR (no mipmap filtering is permitted).");
11857         }
11858
11859         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
11860          effective target is either TEXTURE_2D_MULTISAMPLE or
11861          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname TEXTURE_BASE_LEVEL is set to a
11862          value other than zero. */
11863         {
11864                 gl.textureParameterfv(m_to_2D_ms, GL_TEXTURE_BASE_LEVEL, &one);
11865
11866                 is_ok &=
11867                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterfv",
11868                                                          "the effective target is either TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY, "
11869                                                          "and pname TEXTURE_BASE_LEVEL is set to a value other than zero.");
11870         }
11871
11872         /* Check that INVALID_OPERATION is generated by TextureParameter* if
11873          texture is not the name of an existing texture object. */
11874         {
11875                 gl.textureParameterfv(m_to_invalid, GL_TEXTURE_LOD_BIAS, &one);
11876
11877                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterfv",
11878                                                                   "texture is not the name of an existing texture object.");
11879         }
11880
11881         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
11882          effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is
11883          set to any value other than zero. */
11884         {
11885                 gl.textureParameterfv(m_to_rectangle, GL_TEXTURE_BASE_LEVEL, &one);
11886
11887                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterfv",
11888                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is set to "
11889                                                                   "any value other than zero. ");
11890         }
11891
11892         /* Check that INVALID_VALUE is generated by TextureParameter* if pname is
11893          TEXTURE_BASE_LEVEL or TEXTURE_MAX_LEVEL, and param or params is
11894          negative. */
11895         {
11896                 gl.textureParameterfv(m_to_2D, GL_TEXTURE_BASE_LEVEL, &minus_one);
11897
11898                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameterfv",
11899                                                                   "pname is TEXTURE_BASE_LEVEL and param is negative.");
11900
11901                 gl.textureParameterfv(m_to_2D, GL_TEXTURE_MAX_LEVEL, &minus_one);
11902
11903                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameterfv",
11904                                                                   "pname is TEXTURE_MAX_LEVEL and param is negative.");
11905         }
11906
11907         return is_ok;
11908 }
11909
11910 /** @brief Test (negative) of TextureParameteriv
11911  *
11912  *  @return Test result.
11913  */
11914 bool ParameterSetupErrorsTest::Testiv()
11915 {
11916         /* Shortcut for GL functionality. */
11917         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11918
11919         /* Result. */
11920         bool is_ok = true;
11921
11922         glw::GLint one                                            = 1;
11923         glw::GLint minus_one                              = -1;
11924         glw::GLint depth_stencil_mode_invalid = (glw::GLint)m_depth_stencil_mode_invalid;
11925         glw::GLint wrap_invalid                           = (glw::GLint)GL_MIRROR_CLAMP_TO_EDGE;
11926         glw::GLint min_filter_invalid             = (glw::GLint)GL_NEAREST_MIPMAP_NEAREST;
11927
11928         /* Check that INVALID_ENUM is generated by TextureParameter* if pname is
11929          not one of the accepted defined values. */
11930         {
11931                 gl.textureParameteriv(m_to_2D, m_pname_invalid, &one);
11932
11933                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteriv",
11934                                                                   "pname is not one of the accepted defined values.");
11935         }
11936
11937         /* Check that INVALID_ENUM is generated by TextureParameter* if params
11938          should have a defined constant value (based on the value of pname) and
11939          does not. */
11940         {
11941                 gl.textureParameteriv(m_to_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, &depth_stencil_mode_invalid);
11942
11943                 is_ok &=
11944                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteriv",
11945                                                          "params should have a defined constant value (based on the value of pname) and does not.");
11946         }
11947
11948         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11949          effective target is either TEXTURE_2D_MULTISAMPLE or
11950          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states. */
11951         {
11952                 gl.textureParameteriv(m_to_2D_ms, GL_TEXTURE_LOD_BIAS, &one);
11953
11954                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteriv",
11955                                                                   "the  effective target is either TEXTURE_2D_MULTISAMPLE or  "
11956                                                                   "TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states.");
11957         }
11958
11959         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11960          effective target is TEXTURE_RECTANGLE and either of pnames
11961          TEXTURE_WRAP_S or TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE,
11962          MIRRORED_REPEAT or REPEAT. */
11963         {
11964                 gl.textureParameteriv(m_to_rectangle, GL_TEXTURE_WRAP_S, &wrap_invalid);
11965
11966                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteriv",
11967                                                                   "the effective target is TEXTURE_RECTANGLE and either of pnames TEXTURE_WRAP_S or "
11968                                                                   "TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE, MIRRORED_REPEAT or REPEAT.");
11969         }
11970
11971         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11972          effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is
11973          set to a value other than NEAREST or LINEAR (no mipmap filtering is
11974          permitted). */
11975         {
11976                 gl.textureParameteriv(m_to_rectangle, GL_TEXTURE_MIN_FILTER, &min_filter_invalid);
11977
11978                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteriv",
11979                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is set to a "
11980                                                                   "value other than NEAREST or LINEAR (no mipmap filtering is permitted).");
11981         }
11982
11983         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
11984          effective target is either TEXTURE_2D_MULTISAMPLE or
11985          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname TEXTURE_BASE_LEVEL is set to a
11986          value other than zero. */
11987         {
11988                 gl.textureParameteriv(m_to_2D_ms, GL_TEXTURE_BASE_LEVEL, &one);
11989
11990                 is_ok &=
11991                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteriv",
11992                                                          "the effective target is either TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY, "
11993                                                          "and pname TEXTURE_BASE_LEVEL is set to a value other than zero.");
11994         }
11995
11996         /* Check that INVALID_OPERATION is generated by TextureParameter* if
11997          texture is not the name of an existing texture object. */
11998         {
11999                 gl.textureParameteriv(m_to_invalid, GL_TEXTURE_LOD_BIAS, &one);
12000
12001                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteriv",
12002                                                                   "texture is not the name of an existing texture object.");
12003         }
12004
12005         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12006          effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is
12007          set to any value other than zero. */
12008         {
12009                 gl.textureParameteriv(m_to_rectangle, GL_TEXTURE_BASE_LEVEL, &one);
12010
12011                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteriv",
12012                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is set to "
12013                                                                   "any value other than zero. ");
12014         }
12015
12016         /* Check that INVALID_VALUE is generated by TextureParameter* if pname is
12017          TEXTURE_BASE_LEVEL or TEXTURE_MAX_LEVEL, and param or params is
12018          negative. */
12019         {
12020                 gl.textureParameteriv(m_to_2D, GL_TEXTURE_BASE_LEVEL, &minus_one);
12021
12022                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameteriv",
12023                                                                   "pname is TEXTURE_BASE_LEVEL and param is negative.");
12024
12025                 gl.textureParameteriv(m_to_2D, GL_TEXTURE_MAX_LEVEL, &minus_one);
12026
12027                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameteriv",
12028                                                                   "pname is TEXTURE_MAX_LEVEL and param is negative.");
12029         }
12030
12031         return is_ok;
12032 }
12033
12034 /** @brief Test (negative) of TextureParameterIiv
12035  *
12036  *  @return Test result.
12037  */
12038 bool ParameterSetupErrorsTest::TestIiv()
12039 {
12040         /* Shortcut for GL functionality. */
12041         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
12042
12043         /* Result. */
12044         bool is_ok = true;
12045
12046         glw::GLint one                                            = 1;
12047         glw::GLint minus_one                              = -1;
12048         glw::GLint depth_stencil_mode_invalid = (glw::GLint)m_depth_stencil_mode_invalid;
12049         glw::GLint wrap_invalid                           = (glw::GLint)GL_MIRROR_CLAMP_TO_EDGE;
12050         glw::GLint min_filter_invalid             = (glw::GLint)GL_NEAREST_MIPMAP_NEAREST;
12051
12052         /* Check that INVALID_ENUM is generated by TextureParameter* if pname is
12053          not one of the accepted defined values. */
12054         {
12055                 gl.textureParameterIiv(m_to_2D, m_pname_invalid, &one);
12056
12057                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIiv",
12058                                                                   "pname is not one of the accepted defined values.");
12059         }
12060
12061         /* Check that INVALID_ENUM is generated by TextureParameter* if params
12062          should have a defined constant value (based on the value of pname) and
12063          does not. */
12064         {
12065                 gl.textureParameterIiv(m_to_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, &depth_stencil_mode_invalid);
12066
12067                 is_ok &=
12068                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIiv",
12069                                                          "params should have a defined constant value (based on the value of pname) and does not.");
12070         }
12071
12072         /* Check that INVALID_ENUM is generated by TextureParameter* if the
12073          effective target is either TEXTURE_2D_MULTISAMPLE or
12074          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states. */
12075         {
12076                 gl.textureParameterIiv(m_to_2D_ms, GL_TEXTURE_LOD_BIAS, &one);
12077
12078                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIiv",
12079                                                                   "the  effective target is either TEXTURE_2D_MULTISAMPLE or  "
12080                                                                   "TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states.");
12081         }
12082
12083         /* Check that INVALID_ENUM is generated by TextureParameter* if the
12084          effective target is TEXTURE_RECTANGLE and either of pnames
12085          TEXTURE_WRAP_S or TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE,
12086          MIRRORED_REPEAT or REPEAT. */
12087         {
12088                 gl.textureParameterIiv(m_to_rectangle, GL_TEXTURE_WRAP_S, &wrap_invalid);
12089
12090                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIiv",
12091                                                                   "the effective target is TEXTURE_RECTANGLE and either of pnames TEXTURE_WRAP_S or "
12092                                                                   "TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE, MIRRORED_REPEAT or REPEAT.");
12093         }
12094
12095         /* Check that INVALID_ENUM is generated by TextureParameter* if the
12096          effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is
12097          set to a value other than NEAREST or LINEAR (no mipmap filtering is
12098          permitted). */
12099         {
12100                 gl.textureParameterIiv(m_to_rectangle, GL_TEXTURE_MIN_FILTER, &min_filter_invalid);
12101
12102                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIiv",
12103                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is set to a "
12104                                                                   "value other than NEAREST or LINEAR (no mipmap filtering is permitted).");
12105         }
12106
12107         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12108          effective target is either TEXTURE_2D_MULTISAMPLE or
12109          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname TEXTURE_BASE_LEVEL is set to a
12110          value other than zero. */
12111         {
12112                 gl.textureParameterIiv(m_to_2D_ms, GL_TEXTURE_BASE_LEVEL, &one);
12113
12114                 is_ok &=
12115                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIiv",
12116                                                          "the effective target is either TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY, "
12117                                                          "and pname TEXTURE_BASE_LEVEL is set to a value other than zero.");
12118         }
12119
12120         /* Check that INVALID_OPERATION is generated by TextureParameter* if
12121          texture is not the name of an existing texture object. */
12122         {
12123                 gl.textureParameterIiv(m_to_invalid, GL_TEXTURE_LOD_BIAS, &one);
12124
12125                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIiv",
12126                                                                   "texture is not the name of an existing texture object.");
12127         }
12128
12129         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12130          effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is
12131          set to any value other than zero. */
12132         {
12133                 gl.textureParameterIiv(m_to_rectangle, GL_TEXTURE_BASE_LEVEL, &one);
12134
12135                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIiv",
12136                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is set to "
12137                                                                   "any value other than zero. ");
12138         }
12139
12140         /* Check that INVALID_VALUE is generated by TextureParameter* if pname is
12141          TEXTURE_BASE_LEVEL or TEXTURE_MAX_LEVEL, and param or params is
12142          negative. */
12143         {
12144                 gl.textureParameterIiv(m_to_2D, GL_TEXTURE_BASE_LEVEL, &minus_one);
12145
12146                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameterIiv",
12147                                                                   "pname is TEXTURE_BASE_LEVEL and param is negative.");
12148
12149                 gl.textureParameterIiv(m_to_2D, GL_TEXTURE_MAX_LEVEL, &minus_one);
12150
12151                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameterIiv",
12152                                                                   "pname is TEXTURE_MAX_LEVEL and param is negative.");
12153         }
12154
12155         return is_ok;
12156 }
12157
12158 /** @brief Test (negative) of TextureParameterIuiv
12159  *
12160  *  @return Test result.
12161  */
12162 bool ParameterSetupErrorsTest::TestIuiv()
12163 {
12164         /* Shortcut for GL functionality. */
12165         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
12166
12167         /* Result. */
12168         bool is_ok = true;
12169
12170         glw::GLuint one                                            = 1;
12171         glw::GLuint depth_stencil_mode_invalid = (glw::GLint)m_depth_stencil_mode_invalid;
12172         glw::GLuint wrap_invalid                           = (glw::GLint)GL_MIRROR_CLAMP_TO_EDGE;
12173         glw::GLuint min_filter_invalid             = (glw::GLint)GL_NEAREST_MIPMAP_NEAREST;
12174
12175         /* Check that INVALID_ENUM is generated by TextureParameter* if pname is
12176          not one of the accepted defined values. */
12177         {
12178                 gl.textureParameterIuiv(m_to_2D, m_pname_invalid, &one);
12179
12180                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIuiv",
12181                                                                   "pname is not one of the accepted defined values.");
12182         }
12183
12184         /* Check that INVALID_ENUM is generated by TextureParameter* if params
12185          should have a defined constant value (based on the value of pname) and
12186          does not. */
12187         {
12188                 gl.textureParameterIuiv(m_to_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, &depth_stencil_mode_invalid);
12189
12190                 is_ok &=
12191                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIuiv",
12192                                                          "params should have a defined constant value (based on the value of pname) and does not.");
12193         }
12194
12195         /* Check that INVALID_ENUM is generated by TextureParameter* if the
12196          effective target is either TEXTURE_2D_MULTISAMPLE or
12197          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states. */
12198         {
12199                 gl.textureParameterIuiv(m_to_2D_ms, GL_TEXTURE_LOD_BIAS, &one);
12200
12201                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIuiv",
12202                                                                   "the  effective target is either TEXTURE_2D_MULTISAMPLE or  "
12203                                                                   "TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states.");
12204         }
12205
12206         /* Check that INVALID_ENUM is generated by TextureParameter* if the
12207          effective target is TEXTURE_RECTANGLE and either of pnames
12208          TEXTURE_WRAP_S or TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE,
12209          MIRRORED_REPEAT or REPEAT. */
12210         {
12211                 gl.textureParameterIuiv(m_to_rectangle, GL_TEXTURE_WRAP_S, &wrap_invalid);
12212
12213                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIuiv",
12214                                                                   "the effective target is TEXTURE_RECTANGLE and either of pnames TEXTURE_WRAP_S or "
12215                                                                   "TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE, MIRRORED_REPEAT or REPEAT.");
12216         }
12217
12218         /* Check that INVALID_ENUM is generated by TextureParameter* if the
12219          effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is
12220          set to a value other than NEAREST or LINEAR (no mipmap filtering is
12221          permitted). */
12222         {
12223                 gl.textureParameterIuiv(m_to_rectangle, GL_TEXTURE_MIN_FILTER, &min_filter_invalid);
12224
12225                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIuiv",
12226                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is set to a "
12227                                                                   "value other than NEAREST or LINEAR (no mipmap filtering is permitted).");
12228         }
12229
12230         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12231          effective target is either TEXTURE_2D_MULTISAMPLE or
12232          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname TEXTURE_BASE_LEVEL is set to a
12233          value other than zero. */
12234         {
12235                 gl.textureParameterIuiv(m_to_2D_ms, GL_TEXTURE_BASE_LEVEL, &one);
12236
12237                 is_ok &=
12238                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIuiv",
12239                                                          "the effective target is either TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY, "
12240                                                          "and pname TEXTURE_BASE_LEVEL is set to a value other than zero.");
12241         }
12242
12243         /* Check that INVALID_OPERATION is generated by TextureParameter* if
12244          texture is not the name of an existing texture object. */
12245         {
12246                 gl.textureParameterIuiv(m_to_invalid, GL_TEXTURE_LOD_BIAS, &one);
12247
12248                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIuiv",
12249                                                                   "texture is not the name of an existing texture object.");
12250         }
12251
12252         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12253          effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is
12254          set to any value other than zero. */
12255         {
12256                 gl.textureParameterIuiv(m_to_rectangle, GL_TEXTURE_BASE_LEVEL, &one);
12257
12258                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIuiv",
12259                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is set to "
12260                                                                   "any value other than zero. ");
12261         }
12262
12263         return is_ok;
12264 }
12265
12266 /** @brief Clean GL objects, test variables and GL errors.
12267  */
12268 void ParameterSetupErrorsTest::Clean()
12269 {
12270         /* Shortcut for GL functionality. */
12271         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
12272
12273         /* Cleanup. */
12274         if (m_to_2D)
12275         {
12276                 gl.deleteTextures(1, &m_to_2D);
12277
12278                 m_to_2D = 0;
12279         }
12280
12281         if (m_to_2D_ms)
12282         {
12283                 gl.deleteTextures(1, &m_to_2D_ms);
12284
12285                 m_to_2D_ms = 0;
12286         }
12287
12288         if (m_to_rectangle)
12289         {
12290                 gl.deleteTextures(1, &m_to_rectangle);
12291
12292                 m_to_rectangle = 0;
12293         }
12294
12295         if (m_to_invalid)
12296         {
12297                 gl.deleteTextures(1, &m_to_invalid);
12298
12299                 m_to_invalid = 0;
12300         }
12301
12302         m_to_invalid    = 0;
12303         m_pname_invalid = 0;
12304
12305         while (GL_NO_ERROR != gl.getError())
12306                 ;
12307 }
12308
12309 /******************************** Generate Mipmap Errors Test Implementation   ********************************/
12310
12311 /** @brief Generate Mipmap Errors Test constructor.
12312  *
12313  *  @param [in] context     OpenGL context.
12314  */
12315 GenerateMipmapErrorsTest::GenerateMipmapErrorsTest(deqp::Context& context)
12316         : deqp::TestCase(context, "textures_generate_mipmap_errors", "Texture Generate Mipmap Errors Test")
12317 {
12318         /* Intentionally left blank. */
12319 }
12320
12321 /** @brief Iterate Generate Mipmap Errors Test cases.
12322  *
12323  *  @return Iteration result.
12324  */
12325 tcu::TestNode::IterateResult GenerateMipmapErrorsTest::iterate()
12326 {
12327         /* Shortcut for GL functionality. */
12328         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
12329
12330         /* Get context setup. */
12331         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
12332         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
12333
12334         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
12335         {
12336                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
12337
12338                 return STOP;
12339         }
12340
12341         /* Running tests. */
12342         bool is_ok      = true;
12343         bool is_error = false;
12344
12345         /* Objects. */
12346         glw::GLuint texture_invalid = 0;
12347         glw::GLuint texture_cube        = 0;
12348
12349         try
12350         {
12351                 /* Preparations. */
12352
12353                 /* incomplete cube map */
12354                 gl.genTextures(1, &texture_cube);
12355                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12356
12357                 gl.bindTexture(GL_TEXTURE_CUBE_MAP, texture_cube);
12358                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12359
12360                 gl.texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, s_reference_internalformat, s_reference_width,
12361                                           s_reference_height, 0, s_reference_format, s_reference_type, s_reference_data);
12362                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12363
12364                 /* invalid texture */
12365                 while (gl.isTexture(++texture_invalid))
12366                         ;
12367
12368                 /* Check that INVALID_OPERATION is generated by GenerateTextureMipmap if
12369                  texture is not the name of an existing texture object. */
12370                 gl.generateTextureMipmap(texture_invalid);
12371                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGenerateTextureMipmap",
12372                                                                   "texture is not the name of an existing texture object.");
12373
12374                 /* Check that INVALID_OPERATION is generated by GenerateTextureMipmap if
12375                  target is TEXTURE_CUBE_MAP or TEXTURE_CUBE_MAP_ARRAY, and the specified
12376                  texture object is not cube complete or cube array complete,
12377                  respectively. */
12378                 gl.generateTextureMipmap(texture_cube);
12379                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGenerateTextureMipmap",
12380                                                                   "target is TEXTURE_CUBE_MAP or TEXTURE_CUBE_MAP_ARRAY, and the specified texture "
12381                                                                   "object is not cube complete or cube array complete, respectively.");
12382         }
12383         catch (...)
12384         {
12385                 is_ok   = false;
12386                 is_error = true;
12387         }
12388
12389         /* Cleanup. */
12390         if (texture_cube)
12391         {
12392                 gl.deleteTextures(1, &texture_cube);
12393         }
12394
12395         while (GL_NO_ERROR != gl.getError())
12396                 ;
12397
12398         /* Result's setup. */
12399         if (is_ok)
12400         {
12401                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
12402         }
12403         else
12404         {
12405                 if (is_error)
12406                 {
12407                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
12408                 }
12409                 else
12410                 {
12411                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
12412                 }
12413         }
12414
12415         return STOP;
12416 }
12417
12418 /** Reference data. */
12419 const glw::GLubyte GenerateMipmapErrorsTest::s_reference_data[] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
12420                                                                                                                                         0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF };
12421
12422 /** Reference data parameters. */
12423 const glw::GLuint GenerateMipmapErrorsTest::s_reference_width              = 4;
12424 const glw::GLuint GenerateMipmapErrorsTest::s_reference_height             = 4;
12425 const glw::GLenum GenerateMipmapErrorsTest::s_reference_internalformat = GL_R8;
12426 const glw::GLenum GenerateMipmapErrorsTest::s_reference_format             = GL_RED;
12427 const glw::GLenum GenerateMipmapErrorsTest::s_reference_type               = GL_UNSIGNED_BYTE;
12428
12429 /******************************** Bind Unit Errors Test Implementation   ********************************/
12430
12431 /** @brief Bind Unit Errors Test constructor.
12432  *
12433  *  @param [in] context     OpenGL context.
12434  */
12435 BindUnitErrorsTest::BindUnitErrorsTest(deqp::Context& context)
12436         : deqp::TestCase(context, "textures_bind_unit_errors", "Texture Bind Unit Errors Test")
12437 {
12438         /* Intentionally left blank. */
12439 }
12440
12441 /** @brief IterateBind Unit Errors Test cases.
12442  *
12443  *  @return Iteration result.
12444  */
12445 tcu::TestNode::IterateResult BindUnitErrorsTest::iterate()
12446 {
12447         /* Shortcut for GL functionality. */
12448         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
12449
12450         /* Get context setup. */
12451         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
12452         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
12453
12454         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
12455         {
12456                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
12457
12458                 return STOP;
12459         }
12460
12461         /* Running tests. */
12462         bool is_ok      = true;
12463         bool is_error = false;
12464
12465         /* Objects. */
12466         glw::GLuint texture_invalid = 0;
12467
12468         try
12469         {
12470                 /* Prepare invalid texture */
12471                 while (gl.isTexture(++texture_invalid))
12472                         ;
12473
12474                 /* incomplete cube map */
12475
12476                 /* Check that INVALID_OPERATION error is generated if texture is not zero
12477                  or the name of an existing texture object. */
12478                 gl.bindTextureUnit(0, texture_invalid);
12479                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glBindTextureUnit",
12480                                                                   "texture is not zero or the name of an existing texture object.");
12481         }
12482         catch (...)
12483         {
12484                 is_ok   = false;
12485                 is_error = true;
12486         }
12487
12488         /* Cleanup. */
12489         while (GL_NO_ERROR != gl.getError())
12490                 ;
12491
12492         /* Result's setup. */
12493         if (is_ok)
12494         {
12495                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
12496         }
12497         else
12498         {
12499                 if (is_error)
12500                 {
12501                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
12502                 }
12503                 else
12504                 {
12505                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
12506                 }
12507         }
12508
12509         return STOP;
12510 }
12511
12512 /******************************** Image Query Errors Test Implementation   ********************************/
12513
12514 /** @brief Image Query Errors Test constructor.
12515  *
12516  *  @param [in] context     OpenGL context.
12517  */
12518 ImageQueryErrorsTest::ImageQueryErrorsTest(deqp::Context& context)
12519         : deqp::TestCase(context, "textures_image_query_errors", "Texture Image Query Errors Test")
12520 {
12521         /* Intentionally left blank. */
12522 }
12523
12524 /** Reference data. */
12525 const glw::GLuint ImageQueryErrorsTest::s_reference_data[] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
12526                                                                                                                            0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF };
12527
12528 /** Reference data parameters. */
12529 const glw::GLuint ImageQueryErrorsTest::s_reference_width                                         = 4;
12530 const glw::GLuint ImageQueryErrorsTest::s_reference_height                                        = 4;
12531 const glw::GLuint ImageQueryErrorsTest::s_reference_size                                          = sizeof(s_reference_data);
12532 const glw::GLenum ImageQueryErrorsTest::s_reference_internalformat                        = GL_R8;
12533 const glw::GLenum ImageQueryErrorsTest::s_reference_internalformat_int            = GL_R8I;
12534 const glw::GLenum ImageQueryErrorsTest::s_reference_internalformat_compressed = GL_COMPRESSED_RED_RGTC1;
12535 const glw::GLenum ImageQueryErrorsTest::s_reference_format                                        = GL_RED;
12536 const glw::GLenum ImageQueryErrorsTest::s_reference_type                                          = GL_UNSIGNED_INT;
12537
12538 /** @brief Iterate Image Query Errors Test cases.
12539  *
12540  *  @return Iteration result.
12541  */
12542 tcu::TestNode::IterateResult ImageQueryErrorsTest::iterate()
12543 {
12544         /* Shortcut for GL functionality. */
12545         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
12546
12547         /* Get context setup. */
12548         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
12549         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
12550
12551         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
12552         {
12553                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
12554
12555                 return STOP;
12556         }
12557
12558         /* Running tests. */
12559         bool is_ok      = true;
12560         bool is_error = false;
12561
12562         /* Objects. */
12563         glw::GLuint buffer                                                                                = 0;
12564         glw::GLuint texture_invalid                                                               = 0;
12565         glw::GLuint texture_2D                                                                    = 0;
12566         glw::GLuint texture_2D_int                                                                = 0;
12567         glw::GLuint texture_2D_ms                                                                 = 0;
12568         glw::GLuint texture_2D_stencil                                                    = 0;
12569         glw::GLuint texture_2D_compressed                                                 = 0;
12570         glw::GLuint texture_cube                                                                  = 0;
12571         glw::GLuint texture_rectangle                                                     = 0;
12572         glw::GLint  max_level                                                                     = 0;
12573         char            store[s_reference_size * 6 /* for cubemap */] = {};
12574
12575         try
12576         {
12577                 /* Preparations. */
12578
12579                 /* Buffer. */
12580                 gl.createBuffers(1, &buffer);
12581
12582                 gl.namedBufferData(buffer, s_reference_size + 1, NULL, GL_STATIC_COPY);
12583                 GLU_EXPECT_NO_ERROR(gl.getError(), "glNamedBufferData has failed");
12584
12585                 /* 2D texture */
12586                 gl.genTextures(1, &texture_2D);
12587                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12588
12589                 gl.bindTexture(GL_TEXTURE_2D, texture_2D);
12590                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12591
12592                 gl.texImage2D(GL_TEXTURE_2D, 0, s_reference_internalformat, s_reference_width, s_reference_height, 0,
12593                                           s_reference_format, s_reference_type, s_reference_data);
12594                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12595
12596                 /* 2D texture */
12597                 gl.genTextures(1, &texture_2D);
12598                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12599
12600                 gl.bindTexture(GL_TEXTURE_2D, texture_2D);
12601                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12602
12603                 gl.texImage2D(GL_TEXTURE_2D, 0, s_reference_internalformat, s_reference_width, s_reference_height, 0,
12604                                           s_reference_format, s_reference_type, s_reference_data);
12605                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12606
12607                 /* incomplete cube map */
12608                 gl.genTextures(1, &texture_cube);
12609                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12610
12611                 gl.bindTexture(GL_TEXTURE_CUBE_MAP, texture_cube);
12612                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12613
12614                 gl.texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, s_reference_internalformat, s_reference_width,
12615                                           s_reference_height, 0, s_reference_format, s_reference_type, s_reference_data);
12616                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12617
12618                 /* 2D multisample */
12619                 gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &texture_2D_ms);
12620                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12621
12622                 gl.textureStorage2DMultisample(texture_2D_ms, 1, s_reference_internalformat, s_reference_width,
12623                                                                            s_reference_height, false);
12624                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2DMultisample has failed");
12625
12626                 /* 2D stencil */
12627                 gl.createTextures(GL_TEXTURE_2D, 1, &texture_2D_stencil);
12628                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12629
12630                 gl.textureStorage2D(texture_2D_stencil, 1, GL_STENCIL_INDEX8, s_reference_width, s_reference_height);
12631                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2DMultisample has failed");
12632
12633                 /* 2D compressed texture  */
12634                 gl.genTextures(1, &texture_2D_compressed);
12635                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12636
12637                 gl.bindTexture(GL_TEXTURE_2D, texture_2D_compressed);
12638                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12639
12640                 gl.texImage2D(GL_TEXTURE_2D, 0, s_reference_internalformat_compressed, s_reference_width, s_reference_height, 0,
12641                                           s_reference_format, s_reference_type, s_reference_data);
12642                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12643
12644                 gl.getIntegerv(GL_MAX_TEXTURE_SIZE, &max_level); /* assuming that x > log(x) */
12645                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
12646
12647                 /* Rectangle texture */
12648                 gl.genTextures(1, &texture_rectangle);
12649                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12650
12651                 gl.bindTexture(GL_TEXTURE_RECTANGLE, texture_rectangle);
12652                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12653
12654                 gl.texImage2D(GL_TEXTURE_RECTANGLE, 0, s_reference_internalformat, s_reference_width, s_reference_height, 0,
12655                                           s_reference_format, s_reference_type, s_reference_data);
12656                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12657
12658                 /* invalid texture */
12659                 while (gl.isTexture(++texture_invalid))
12660                         ;
12661
12662                 /* Tests. */
12663
12664                 /* Check that INVALID_OPERATION is generated by GetTextureImage functions if
12665                  resulting texture target is not an accepted value TEXTURE_1D,
12666                  TEXTURE_2D, TEXTURE_3D, TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY,
12667                  TEXTURE_CUBE_MAP_ARRAY, TEXTURE_RECTANGLE, and TEXTURE_CUBE_MAP. */
12668                 gl.getTextureImage(texture_2D_ms, 0, s_reference_format, s_reference_type, s_reference_size, store);
12669                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12670                                                                   "resulting texture target is not an accepted value TEXTURE_1D, TEXTURE_2D, "
12671                                                                   "TEXTURE_3D, TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP_ARRAY, "
12672                                                                   "TEXTURE_RECTANGLE, and TEXTURE_CUBE_MAP.");
12673
12674                 /* Check that INVALID_OPERATION is generated by GetTextureImage
12675                  if texture is not the name of an existing texture object. */
12676                 gl.getTextureImage(texture_invalid, 0, s_reference_format, s_reference_type, s_reference_size, store);
12677                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12678                                                                   "texture is not the name of an existing texture object.");
12679
12680                 /* Check that INVALID_OPERATION error is generated by GetTextureImage if
12681                  the effective target is TEXTURE_CUBE_MAP or TEXTURE_CUBE_MAP_ARRAY, and
12682                  the texture object is not cube complete or cube array complete,
12683                  respectively. */
12684                 gl.getTextureImage(texture_cube, 0, s_reference_format, s_reference_type, s_reference_size * 6, store);
12685                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12686                                                                   "the effective target is TEXTURE_CUBE_MAP and the texture object is not cube "
12687                                                                   "complete or cube array complete, respectively.");
12688
12689                 /* Check that GL_INVALID_VALUE is generated if level is less than 0 or
12690                  larger than the maximum allowable level. */
12691                 gl.getTextureImage(texture_2D, -1, s_reference_format, s_reference_type, s_reference_size, store);
12692                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureImage", "level is less than 0.");
12693
12694                 gl.getTextureImage(texture_2D, max_level, s_reference_format, s_reference_type, s_reference_size, store);
12695                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureImage",
12696                                                                   "level is larger than the maximum allowable level.");
12697
12698                 /* Check that INVALID_VALUE error is generated if level is non-zero and the
12699                  effective target is TEXTURE_RECTANGLE. */
12700                 gl.getTextureImage(texture_rectangle, 1, s_reference_format, s_reference_type, s_reference_size, store);
12701                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureImage",
12702                                                                   "level is non-zero and the effective target is TEXTURE_RECTANGLE.");
12703
12704                 /* Check that INVALID_OPERATION error is generated if any of the following
12705                  mismatches between format and the internal format of the texture image
12706                  exist:
12707                  -  format is a color format (one of the formats in table 8.3 whose
12708                  target is the color buffer) and the base internal format of the
12709                  texture image is not a color format.
12710                  -  format is DEPTH_COMPONENT and the base internal format is  not
12711                  DEPTH_COMPONENT or DEPTH_STENCIL
12712                  -  format is DEPTH_STENCIL and the base internal format is not
12713                  DEPTH_STENCIL
12714                  -  format is STENCIL_INDEX and the base internal format is not
12715                  STENCIL_INDEX or DEPTH_STENCIL
12716                  -  format is one of the integer formats in table 8.3 and the internal
12717                  format of the texture image is not integer, or format is not one of
12718                  the integer formats in table 8.3 and the internal format is integer. */
12719                 gl.getTextureImage(texture_2D_stencil, 0, s_reference_format /* red */, s_reference_type, s_reference_size,
12720                                                    store);
12721                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12722                                                                   "format is a color format (one of the formats in table 8.3 whose target is the color "
12723                                                                   "buffer) and the base internal format of the texture image is not a color format.");
12724
12725                 gl.getTextureImage(texture_2D, 0, GL_DEPTH_COMPONENT, s_reference_type, s_reference_size, store);
12726                 is_ok &= CheckErrorAndLog(
12727                         m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12728                         "format is DEPTH_COMPONENT and the base internal format is not DEPTH_COMPONENT or DEPTH_STENCIL.");
12729
12730                 gl.getTextureImage(texture_2D, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, s_reference_size, store);
12731                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12732                                                                   "format is DEPTH_STENCIL and the base internal format is not DEPTH_STENCIL.");
12733
12734                 gl.getTextureImage(texture_2D, 0, GL_STENCIL_INDEX, s_reference_type, s_reference_size, store);
12735                 is_ok &= CheckErrorAndLog(
12736                         m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12737                         "format is STENCIL_INDEX and the base internal format is not STENCIL_INDEX or DEPTH_STENCIL.");
12738
12739                 gl.getTextureImage(texture_2D, 0, GL_RED_INTEGER, s_reference_type, s_reference_size, store);
12740                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12741                                                                   "format is one of the integer formats in table 8.3 and the internal format of the "
12742                                                                   "texture image is not integer.");
12743
12744                 gl.getTextureImage(texture_2D_int, 0, GL_RED, s_reference_type, s_reference_size, store);
12745                 is_ok &= CheckErrorAndLog(
12746                         m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12747                         "format is not one of the integer formats in table 8.3 and the internal format is integer.");
12748
12749                 /* Check that INVALID_OPERATION error is generated if a pixel pack buffer
12750                  object is bound and packing the texture image into the buffer’s memory
12751                  would exceed the size of the buffer. */
12752                 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, buffer);
12753                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
12754
12755                 gl.getTextureImage(texture_2D, 0, s_reference_format, s_reference_type, s_reference_size,
12756                                                    (glw::GLuint*)NULL + 1);
12757                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12758                                                                   "a pixel pack buffer object is bound and packing the texture image into the buffer’s "
12759                                                                   "memory would exceed the size of the buffer.");
12760
12761                 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, 0);
12762                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
12763
12764                 /* Check that INVALID_OPERATION error is generated if a pixel pack buffer
12765                  object is bound and pixels is not evenly divisible by the number of
12766                  basic machine units needed to store in memory the GL data type
12767                  corresponding to type (see table 8.2). */
12768                 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, buffer);
12769                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
12770
12771                 gl.getTextureImage(texture_2D, 0, s_reference_format, s_reference_type, s_reference_size,
12772                                                    (glw::GLubyte*)NULL + 1);
12773                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12774                                                                   "a pixel pack buffer object is bound and pixels is not evenly divisible by the "
12775                                                                   "number of basic machine units needed to store in memory the GL data type "
12776                                                                   "corresponding to type (see table 8.2).");
12777
12778                 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, 0);
12779                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
12780
12781                 /* Check that INVALID_OPERATION error is generated by GetTextureImage if
12782                  the buffer size required to store the requested data is greater than
12783                  bufSize. */
12784                 gl.getTextureImage(texture_2D, 0, s_reference_format, s_reference_type,
12785                                                    s_reference_size - sizeof(s_reference_data[0]), store);
12786                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12787                                                                   "the buffer size required to store the requested data is greater than bufSize.");
12788
12789                 /* Check that INVALID_OPERATION is generated by GetCompressedTextureImage
12790                  if texture is not the name of an existing texture object. */
12791                 gl.getCompressedTextureImage(texture_invalid, 0, s_reference_size, store);
12792                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetCompressedTextureImage",
12793                                                                   "texture is not the name of an existing texture object.");
12794
12795                 /* Check that INVALID_VALUE is generated by GetCompressedTextureImage if
12796                  level is less than zero or greater than the maximum number of LODs
12797                  permitted by the implementation. */
12798                 gl.getCompressedTextureImage(texture_2D_compressed, -1, s_reference_size, store);
12799                 is_ok &=
12800                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetCompressedTextureImage", "level is less than zero.");
12801
12802                 gl.getCompressedTextureImage(texture_2D_compressed, max_level, s_reference_size, store);
12803                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetCompressedTextureImage",
12804                                                                   "level is greater than the maximum number of LODs permitted by the implementation.");
12805
12806                 /* Check that INVALID_OPERATION is generated if GetCompressedTextureImage
12807                  is used to retrieve a texture that is in an uncompressed internal
12808                  format. */
12809                 gl.getCompressedTextureImage(texture_2D, 0, s_reference_size, store);
12810                 is_ok &=
12811                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetCompressedTextureImage",
12812                                                          "the function is used to retrieve a texture that is in an uncompressed internal format.");
12813
12814                 /* Check that INVALID_OPERATION is generated by GetCompressedTextureImage
12815                  if a non-zero buffer object name is bound to the PIXEL_PACK_BUFFER
12816                  target, the buffer storage was not initialized with BufferStorage using
12817                  MAP_PERSISTENT_BIT flag, and the buffer object's data store is currently
12818                  mapped. */
12819                 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, buffer);
12820                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
12821
12822                 gl.mapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_WRITE);
12823
12824                 if (GL_NO_ERROR == gl.getError())
12825                 {
12826                         gl.getCompressedTextureImage(texture_2D_compressed, 0, s_reference_size, NULL);
12827                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetCompressedTextureImage",
12828                                                                           "a non-zero buffer object name is bound to the PIXEL_PACK_BUFFER target, the "
12829                                                                           "buffer storage was not initialized with BufferStorage using MAP_PERSISTENT_BIT "
12830                                                                           "flag, and the buffer object's data store is currently mapped.");
12831
12832                         gl.unmapBuffer(GL_PIXEL_PACK_BUFFER);
12833                         GLU_EXPECT_NO_ERROR(gl.getError(), "glUnmapBuffer has failed");
12834                 }
12835                 else
12836                 {
12837                         throw 0;
12838                 }
12839
12840                 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, 0);
12841                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
12842
12843                 /* Check that INVALID_OPERATION is generated by GetCompressedTextureImage
12844                  if a non-zero buffer object name is bound to the PIXEL_PACK_BUFFER
12845                  target and the data would be packed to the buffer object such that the
12846                  memory writes required would exceed the data store size. */
12847                 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, buffer);
12848                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
12849
12850                 gl.getCompressedTextureImage(texture_2D_compressed, 0, s_reference_size, (char*)NULL + s_reference_size - 1);
12851                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetCompressedTextureImage",
12852                                                                   "a non-zero buffer object name is bound to the PIXEL_PACK_BUFFER target and the data "
12853                                                                   "would be packed to the buffer object such that the memory writes required would "
12854                                                                   "exceed the data store size.");
12855
12856                 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, 0);
12857                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
12858         }
12859         catch (...)
12860         {
12861                 is_ok   = false;
12862                 is_error = true;
12863         }
12864
12865         /* Cleanup. */
12866         if (buffer)
12867         {
12868                 gl.deleteBuffers(1, &buffer);
12869         }
12870
12871         if (texture_2D)
12872         {
12873                 gl.deleteTextures(1, &texture_2D);
12874         }
12875
12876         if (texture_2D_int)
12877         {
12878                 gl.deleteTextures(1, &texture_2D_int);
12879         }
12880
12881         if (texture_2D_stencil)
12882         {
12883                 gl.deleteTextures(1, &texture_2D_stencil);
12884         }
12885
12886         if (texture_2D_ms)
12887         {
12888                 gl.deleteTextures(1, &texture_2D_ms);
12889         }
12890
12891         if (texture_2D_compressed)
12892         {
12893                 gl.deleteTextures(1, &texture_2D_compressed);
12894         }
12895
12896         if (texture_cube)
12897         {
12898                 gl.deleteTextures(1, &texture_cube);
12899         }
12900
12901         if (texture_rectangle)
12902         {
12903                 gl.deleteTextures(1, &texture_rectangle);
12904         }
12905
12906         while (GL_NO_ERROR != gl.getError())
12907                 ;
12908
12909         /* Result's setup. */
12910         if (is_ok)
12911         {
12912                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
12913         }
12914         else
12915         {
12916                 if (is_error)
12917                 {
12918                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
12919                 }
12920                 else
12921                 {
12922                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
12923                 }
12924         }
12925
12926         return STOP;
12927 }
12928
12929 /******************************** Level Parameter Query Errors Test Implementation   ********************************/
12930
12931 /** @brief Image Query Errors Test constructor.
12932  *
12933  *  @param [in] context     OpenGL context.
12934  */
12935 LevelParameterErrorsTest::LevelParameterErrorsTest(deqp::Context& context)
12936         : deqp::TestCase(context, "textures_level_parameter_errors", "Texture Level Parameter Query Errors Test")
12937 {
12938         /* Intentionally left blank. */
12939 }
12940
12941 /** @brief Iterate Level Parameter Query Errors Test cases.
12942  *
12943  *  @return Iteration result.
12944  */
12945 tcu::TestNode::IterateResult LevelParameterErrorsTest::iterate()
12946 {
12947         /* Shortcut for GL functionality. */
12948         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
12949
12950         /* Get context setup. */
12951         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
12952         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
12953
12954         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
12955         {
12956                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
12957
12958                 return STOP;
12959         }
12960
12961         /* Running tests. */
12962         bool is_ok      = true;
12963         bool is_error = false;
12964
12965         /* Objects. */
12966         glw::GLuint texture_2D          = 0;
12967         glw::GLuint texture_invalid = 0;
12968         glw::GLint  max_level           = 0;
12969         glw::GLenum pname_invalid   = 0;
12970
12971         glw::GLfloat storef[4] = {};
12972         glw::GLint   storei[4] = {};
12973
12974         try
12975         {
12976                 /* Preparations. */
12977
12978                 /* 2D texture */
12979                 gl.genTextures(1, &texture_2D);
12980                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12981
12982                 gl.bindTexture(GL_TEXTURE_2D, texture_2D);
12983                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12984
12985                 gl.texStorage2D(GL_TEXTURE_2D, 1, GL_R8, 1, 1);
12986                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12987
12988                 /* Limits. */
12989                 gl.getIntegerv(GL_MAX_TEXTURE_SIZE, &max_level); /* assuming that x > log(x) */
12990                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
12991
12992                 /* invalid texture */
12993                 while (gl.isTexture(++texture_invalid))
12994                         ;
12995
12996                 /* invalid pname */
12997                 glw::GLenum all_pnames[] = { GL_TEXTURE_WIDTH,
12998                                                                          GL_TEXTURE_HEIGHT,
12999                                                                          GL_TEXTURE_DEPTH,
13000                                                                          GL_TEXTURE_SAMPLES,
13001                                                                          GL_TEXTURE_FIXED_SAMPLE_LOCATIONS,
13002                                                                          GL_TEXTURE_INTERNAL_FORMAT,
13003                                                                          GL_TEXTURE_RED_SIZE,
13004                                                                          GL_TEXTURE_GREEN_SIZE,
13005                                                                          GL_TEXTURE_BLUE_SIZE,
13006                                                                          GL_TEXTURE_ALPHA_SIZE,
13007                                                                          GL_TEXTURE_DEPTH_SIZE,
13008                                                                          GL_TEXTURE_STENCIL_SIZE,
13009                                                                          GL_TEXTURE_SHARED_SIZE,
13010                                                                          GL_TEXTURE_RED_TYPE,
13011                                                                          GL_TEXTURE_GREEN_TYPE,
13012                                                                          GL_TEXTURE_BLUE_TYPE,
13013                                                                          GL_TEXTURE_ALPHA_TYPE,
13014                                                                          GL_TEXTURE_DEPTH_TYPE,
13015                                                                          GL_TEXTURE_COMPRESSED,
13016                                                                          GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
13017                                                                          GL_TEXTURE_BUFFER_DATA_STORE_BINDING,
13018                                                                          GL_TEXTURE_BUFFER_OFFSET,
13019                                                                          GL_TEXTURE_BUFFER_SIZE };
13020
13021                 glw::GLuint all_pnames_count = sizeof(all_pnames) / sizeof(all_pnames[0]);
13022
13023                 bool is_valid = true;
13024
13025                 while (is_valid)
13026                 {
13027                         is_valid = false;
13028
13029                         ++pname_invalid;
13030
13031                         for (glw::GLuint i = 0; i < all_pnames_count; ++i)
13032                         {
13033                                 if (all_pnames[i] == pname_invalid)
13034                                 {
13035                                         is_valid = true;
13036
13037                                         break;
13038                                 }
13039                         }
13040                 }
13041
13042                 /* Tests. */
13043
13044                 /* Check that INVALID_OPERATION is generated by GetTextureLevelParameterfv
13045                  and GetTextureLevelParameteriv functions if texture is not the name of
13046                  an existing texture object. */
13047                 gl.getTextureLevelParameterfv(texture_invalid, 0, GL_TEXTURE_WIDTH, storef);
13048                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureLevelParameterfv",
13049                                                                   "texture is not the name of an existing texture object.");
13050
13051                 gl.getTextureLevelParameteriv(texture_invalid, 0, GL_TEXTURE_WIDTH, storei);
13052                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureLevelParameteriv",
13053                                                                   "texture is not the name of an existing texture object.");
13054
13055                 /* Check that INVALID_VALUE is generated by GetTextureLevelParameter* if
13056                  level is less than 0. */
13057                 gl.getTextureLevelParameterfv(texture_2D, -1, GL_TEXTURE_WIDTH, storef);
13058                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureLevelParameterfv", "level is less than 0.");
13059
13060                 gl.getTextureLevelParameteriv(texture_2D, -1, GL_TEXTURE_WIDTH, storei);
13061                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureLevelParameteriv", "level is less than 0.");
13062
13063                 /* Check that INVALID_ENUM error is generated by GetTextureLevelParameter*
13064                  if pname is not one of supported constants. */
13065                 gl.getTextureLevelParameterfv(texture_2D, 0, pname_invalid, storef);
13066                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureLevelParameterfv",
13067                                                                   "pname is not one of supported constants.");
13068
13069                 gl.getTextureLevelParameteriv(texture_2D, 0, pname_invalid, storei);
13070                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureLevelParameteriv",
13071                                                                   "pname is not one of supported constants.");
13072
13073                 /* Check that INVALID_VALUE may be generated if level is greater than
13074                  log2 max, where max is the returned value of MAX_TEXTURE_SIZE. */
13075                 gl.getTextureLevelParameterfv(texture_2D, max_level, GL_TEXTURE_WIDTH, storef);
13076                 is_ok &=
13077                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureLevelParameterfv",
13078                                                          "level is greater than log2 max, where max is the returned value of MAX_TEXTURE_SIZE.");
13079
13080                 gl.getTextureLevelParameteriv(texture_2D, max_level, GL_TEXTURE_WIDTH, storei);
13081                 is_ok &=
13082                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureLevelParameteriv",
13083                                                          "level is greater than log2 max, where max is the returned value of MAX_TEXTURE_SIZE.");
13084
13085                 /* Check that INVALID_OPERATION is generated by GetTextureLevelParameter*
13086                  if TEXTURE_COMPRESSED_IMAGE_SIZE is queried on texture images with an
13087                  uncompressed internal format or on proxy targets. */
13088                 gl.getTextureLevelParameterfv(texture_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, storef);
13089                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureLevelParameterfv",
13090                                                                   "TEXTURE_COMPRESSED_IMAGE_SIZE is queried on texture images with an uncompressed "
13091                                                                   "internal format or on proxy targets.");
13092
13093                 gl.getTextureLevelParameteriv(texture_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, storei);
13094                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureLevelParameteriv",
13095                                                                   "TEXTURE_COMPRESSED_IMAGE_SIZE is queried on texture images with an uncompressed "
13096                                                                   "internal format or on proxy targets.");
13097         }
13098         catch (...)
13099         {
13100                 is_ok   = false;
13101                 is_error = true;
13102         }
13103
13104         /* Cleanup. */
13105         if (texture_2D)
13106         {
13107                 gl.deleteTextures(1, &texture_2D);
13108         }
13109
13110         while (GL_NO_ERROR != gl.getError())
13111                 ;
13112
13113         /* Result's setup. */
13114         if (is_ok)
13115         {
13116                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
13117         }
13118         else
13119         {
13120                 if (is_error)
13121                 {
13122                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
13123                 }
13124                 else
13125                 {
13126                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
13127                 }
13128         }
13129
13130         return STOP;
13131 }
13132
13133 /******************************** Parameter Query Errors Test Implementation   ********************************/
13134
13135 /** @brief Parameter Query Errors Test constructor.
13136  *
13137  *  @param [in] context     OpenGL context.
13138  */
13139 ParameterErrorsTest::ParameterErrorsTest(deqp::Context& context)
13140         : deqp::TestCase(context, "textures_parameter_errors", "Texture Parameter Query Errors Test")
13141 {
13142         /* Intentionally left blank. */
13143 }
13144
13145 /** @brief Iterate Parameter Query Errors Test cases.
13146  *
13147  *  @return Iteration result.
13148  */
13149 tcu::TestNode::IterateResult ParameterErrorsTest::iterate()
13150 {
13151         /* Shortcut for GL functionality. */
13152         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
13153
13154         /* Get context setup. */
13155         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
13156         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
13157
13158         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
13159         {
13160                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
13161
13162                 return STOP;
13163         }
13164
13165         /* Running tests. */
13166         bool is_ok      = true;
13167         bool is_error = false;
13168
13169         /* Objects. */
13170         glw::GLuint texture_2D          = 0;
13171         glw::GLuint texture_buffer  = 0;
13172         glw::GLuint texture_invalid = 0;
13173         glw::GLenum pname_invalid   = 0;
13174
13175         glw::GLfloat storef[4] = {};
13176         glw::GLint   storei[4] = {};
13177         glw::GLuint  storeu[4] = {};
13178
13179         try
13180         {
13181                 /* Preparations. */
13182
13183                 /* 2D texture */
13184                 gl.createTextures(GL_TEXTURE_2D, 1, &texture_2D);
13185                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
13186
13187                 /* Buffer texture */
13188                 gl.createTextures(GL_TEXTURE_BUFFER, 1, &texture_buffer);
13189                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
13190
13191                 /* invalid texture */
13192                 while (gl.isTexture(++texture_invalid))
13193                         ;
13194
13195                 /* invalid pname */
13196                 glw::GLenum all_pnames[] = { GL_IMAGE_FORMAT_COMPATIBILITY_TYPE,
13197                                                                          GL_TEXTURE_IMMUTABLE_FORMAT,
13198                                                                          GL_TEXTURE_IMMUTABLE_LEVELS,
13199                                                                          GL_TEXTURE_TARGET,
13200                                                                          GL_TEXTURE_VIEW_MIN_LEVEL,
13201                                                                          GL_TEXTURE_VIEW_NUM_LEVELS,
13202                                                                          GL_TEXTURE_VIEW_MIN_LAYER,
13203                                                                          GL_TEXTURE_VIEW_NUM_LAYERS,
13204                                                                          GL_DEPTH_STENCIL_TEXTURE_MODE,
13205                                                                          GL_DEPTH_COMPONENT,
13206                                                                          GL_STENCIL_INDEX,
13207                                                                          GL_TEXTURE_BASE_LEVEL,
13208                                                                          GL_TEXTURE_BORDER_COLOR,
13209                                                                          GL_TEXTURE_COMPARE_MODE,
13210                                                                          GL_TEXTURE_COMPARE_FUNC,
13211                                                                          GL_TEXTURE_LOD_BIAS,
13212                                                                          GL_TEXTURE_MAG_FILTER,
13213                                                                          GL_TEXTURE_MAX_LEVEL,
13214                                                                          GL_TEXTURE_MAX_LOD,
13215                                                                          GL_TEXTURE_MIN_FILTER,
13216                                                                          GL_TEXTURE_MIN_LOD,
13217                                                                          GL_TEXTURE_SWIZZLE_R,
13218                                                                          GL_TEXTURE_SWIZZLE_G,
13219                                                                          GL_TEXTURE_SWIZZLE_B,
13220                                                                          GL_TEXTURE_SWIZZLE_A,
13221                                                                          GL_TEXTURE_SWIZZLE_RGBA,
13222                                                                          GL_TEXTURE_WRAP_S,
13223                                                                          GL_TEXTURE_WRAP_T,
13224                                                                          GL_TEXTURE_WRAP_R };
13225
13226                 glw::GLuint all_pnames_count = sizeof(all_pnames) / sizeof(all_pnames[0]);
13227
13228                 bool is_valid = true;
13229
13230                 while (is_valid)
13231                 {
13232                         is_valid = false;
13233
13234                         ++pname_invalid;
13235
13236                         for (glw::GLuint i = 0; i < all_pnames_count; ++i)
13237                         {
13238                                 if (all_pnames[i] == pname_invalid)
13239                                 {
13240                                         is_valid = true;
13241
13242                                         break;
13243                                 }
13244                         }
13245                 }
13246
13247                 /* Tests. */
13248
13249                 /* Check that INVALID_ENUM is generated by glGetTextureParameter* if pname
13250                  is not an accepted value. */
13251                 gl.getTextureParameterfv(texture_2D, pname_invalid, storef);
13252                 is_ok &=
13253                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureParameterfv", "pname is not an accepted value.");
13254
13255                 gl.getTextureParameterIiv(texture_2D, pname_invalid, storei);
13256                 is_ok &=
13257                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureParameterIiv", "pname is not an accepted value.");
13258
13259                 gl.getTextureParameterIuiv(texture_2D, pname_invalid, storeu);
13260                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureParameterIuiv",
13261                                                                   "pname is not an accepted value.");
13262
13263                 gl.getTextureParameteriv(texture_2D, pname_invalid, storei);
13264                 is_ok &=
13265                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureParameteriv", "pname is not an accepted value.");
13266
13267                 /* Check that INVALID_OPERATION is generated by glGetTextureParameter* if
13268                  texture is not the name of an existing texture object. */
13269                 gl.getTextureParameterfv(texture_invalid, GL_TEXTURE_TARGET, storef);
13270                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameterfv",
13271                                                                   "texture is not the name of an existing texture object.");
13272
13273                 gl.getTextureParameterIiv(texture_invalid, GL_TEXTURE_TARGET, storei);
13274                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameterIiv",
13275                                                                   "texture is not the name of an existing texture object.");
13276
13277                 gl.getTextureParameterIuiv(texture_invalid, GL_TEXTURE_TARGET, storeu);
13278                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameterIuiv",
13279                                                                   "texture is not the name of an existing texture object.");
13280
13281                 gl.getTextureParameteriv(texture_invalid, GL_TEXTURE_TARGET, storei);
13282                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameteriv",
13283                                                                   "texture is not the name of an existing texture object.");
13284
13285                 /* Check that INVALID_OPERATION error is generated if the effective target is
13286                  not one of the supported texture targets (eg. TEXTURE_BUFFER). */
13287                 gl.getTextureParameterfv(texture_buffer, GL_TEXTURE_TARGET, storef);
13288                 is_ok &=
13289                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameterfv",
13290                                                          "the effective target is not one of the supported texture targets (eg. TEXTURE_BUFFER).");
13291
13292                 gl.getTextureParameterIiv(texture_buffer, GL_TEXTURE_TARGET, storei);
13293                 is_ok &=
13294                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameterIiv",
13295                                                          "the effective target is not one of the supported texture targets (eg. TEXTURE_BUFFER).");
13296
13297                 gl.getTextureParameterIuiv(texture_buffer, GL_TEXTURE_TARGET, storeu);
13298                 is_ok &=
13299                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameterIuiv",
13300                                                          "the effective target is not one of the supported texture targets (eg. TEXTURE_BUFFER).");
13301
13302                 gl.getTextureParameteriv(texture_buffer, GL_TEXTURE_TARGET, storei);
13303                 is_ok &=
13304                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameteriv",
13305                                                          "the effective target is not one of the supported texture targets (eg. TEXTURE_BUFFER).");
13306         }
13307         catch (...)
13308         {
13309                 is_ok   = false;
13310                 is_error = true;
13311         }
13312
13313         /* Cleanup. */
13314         if (texture_2D)
13315         {
13316                 gl.deleteTextures(1, &texture_2D);
13317         }
13318
13319         if (texture_buffer)
13320         {
13321                 gl.deleteTextures(1, &texture_buffer);
13322         }
13323
13324         while (GL_NO_ERROR != gl.getError())
13325                 ;
13326
13327         /* Result's setup. */
13328         if (is_ok)
13329         {
13330                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
13331         }
13332         else
13333         {
13334                 if (is_error)
13335                 {
13336                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
13337                 }
13338                 else
13339                 {
13340                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
13341                 }
13342         }
13343
13344         return STOP;
13345 }
13346
13347 } /* Textures namespace. */
13348 } /* DirectStateAccess namespace. */
13349 } /* gl4cts namespace. */