3030b8d88bdb63e7732db99c9ae1a97e5135f209
[platform/upstream/VK-GL-CTS.git] / external / openglcts / modules / gl / gl4cDirectStateAccessTexturesTests.cpp
1 /*-------------------------------------------------------------------------
2  * OpenGL Conformance Test Suite
3  * -----------------------------
4  *
5  * Copyright (c) 2015-2016 The Khronos Group Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */ /*!
20  * \file
21  * \brief
22  */ /*-------------------------------------------------------------------*/
23
24 /**
25  */ /*!
26  * \file  gl4cDirectStateAccessTexturesTests.cpp
27  * \brief Conformance tests for the Direct State Access feature functionality (Texture access part).
28  */ /*-----------------------------------------------------------------------------------------------------------*/
29
30 /* Uncomment this if SubImageErrorsTest crashes during negative test of TextureSubImage (negative value width/height/depth passed to the function). */
31 /* #define TURN_OFF_SUB_IMAGE_ERRORS_TEST_OF_NEGATIVE_WIDTH_HEIGHT_OR_DEPTH */
32
33 /* Includes. */
34 #include "gl4cDirectStateAccessTests.hpp"
35
36 #include "deSharedPtr.hpp"
37
38 #include "gluContextInfo.hpp"
39 #include "gluDefs.hpp"
40 #include "gluPixelTransfer.hpp"
41 #include "gluStrUtil.hpp"
42
43 #include "tcuFuzzyImageCompare.hpp"
44 #include "tcuImageCompare.hpp"
45 #include "tcuRenderTarget.hpp"
46 #include "tcuSurface.hpp"
47 #include "tcuTestLog.hpp"
48
49 #include "glw.h"
50 #include "glwFunctions.hpp"
51
52 #include <algorithm>
53 #include <climits>
54 #include <set>
55 #include <sstream>
56 #include <stack>
57 #include <string>
58
59 namespace gl4cts
60 {
61 namespace DirectStateAccess
62 {
63 namespace Textures
64 {
65 /******************************** Creation Test Implementation   ********************************/
66
67 /** @brief Creation Test constructor.
68  *
69  *  @param [in] context     OpenGL context.
70  */
71 CreationTest::CreationTest(deqp::Context& context)
72         : deqp::TestCase(context, "textures_creation", "Texture Objects Creation Test")
73 {
74         /* Intentionally left blank. */
75 }
76
77 /** @brief Iterate Creation Test cases.
78  *
79  *  @return Iteration result.
80  */
81 tcu::TestNode::IterateResult CreationTest::iterate()
82 {
83         /* Shortcut for GL functionality. */
84         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
85
86         /* Get context setup. */
87         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
88         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
89
90         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
91         {
92                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
93
94                 return STOP;
95         }
96
97         /* Running tests. */
98         bool is_ok      = true;
99         bool is_error = false;
100
101         /* Textures' objects */
102         static const glw::GLenum texture_targets[] = { GL_TEXTURE_1D,
103                                                                                                    GL_TEXTURE_2D,
104                                                                                                    GL_TEXTURE_3D,
105                                                                                                    GL_TEXTURE_1D_ARRAY,
106                                                                                                    GL_TEXTURE_2D_ARRAY,
107                                                                                                    GL_TEXTURE_RECTANGLE,
108                                                                                                    GL_TEXTURE_CUBE_MAP,
109                                                                                                    GL_TEXTURE_CUBE_MAP_ARRAY,
110                                                                                                    GL_TEXTURE_BUFFER,
111                                                                                                    GL_TEXTURE_2D_MULTISAMPLE,
112                                                                                                    GL_TEXTURE_2D_MULTISAMPLE_ARRAY };
113         static const glw::GLuint texture_targets_count = sizeof(texture_targets) / sizeof(texture_targets[0]);
114         static const glw::GLuint textures_count            = 2;
115
116         glw::GLuint textures_legacy[textures_count]                                             = {};
117         glw::GLuint textures_dsa[texture_targets_count][textures_count] = {};
118
119         try
120         {
121                 /* Check legacy state creation. */
122                 gl.genTextures(textures_count, textures_legacy);
123                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
124
125                 for (glw::GLuint i = 0; i < textures_count; ++i)
126                 {
127                         if (gl.isTexture(textures_legacy[i]))
128                         {
129                                 is_ok = false;
130
131                                 /* Log. */
132                                 m_context.getTestContext().getLog()
133                                         << tcu::TestLog::Message
134                                         << "GenTextures has created default objects, but it should create only a names."
135                                         << tcu::TestLog::EndMessage;
136                         }
137                 }
138
139                 /* Check direct state creation. */
140                 for (glw::GLuint j = 0; j < texture_targets_count; ++j)
141                 {
142                         gl.createTextures(texture_targets[j], textures_count, textures_dsa[j]);
143                         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
144
145                         for (glw::GLuint i = 0; i < textures_count; ++i)
146                         {
147                                 if (!gl.isTexture(textures_dsa[j][i]))
148                                 {
149                                         is_ok = false;
150
151                                         /* Log. */
152                                         m_context.getTestContext().getLog()
153                                                 << tcu::TestLog::Message << "CreateTextures has not created default objects for target "
154                                                 << glu::getTextureTargetStr(texture_targets[j]) << "." << tcu::TestLog::EndMessage;
155                                 }
156                         }
157                 }
158         }
159         catch (...)
160         {
161                 is_ok   = false;
162                 is_error = true;
163         }
164
165         /* Cleanup. */
166         for (glw::GLuint i = 0; i < textures_count; ++i)
167         {
168                 if (textures_legacy[i])
169                 {
170                         gl.deleteTextures(1, &textures_legacy[i]);
171
172                         textures_legacy[i] = 0;
173                 }
174
175                 for (glw::GLuint j = 0; j < texture_targets_count; ++j)
176                 {
177                         if (textures_dsa[j][i])
178                         {
179                                 gl.deleteTextures(1, &textures_dsa[j][i]);
180
181                                 textures_dsa[j][i] = 0;
182                         }
183                 }
184         }
185
186         /* Errors clean up. */
187         while (gl.getError())
188                 ;
189
190         /* Result's setup. */
191         if (is_ok)
192         {
193                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
194         }
195         else
196         {
197                 if (is_error)
198                 {
199                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
200                 }
201                 else
202                 {
203                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
204                 }
205         }
206
207         return STOP;
208 }
209
210 /******************************** Reference Data Implementation   *****************************/
211
212 /** @brief Internal Format selector.
213  *
214  *  @tparam T      Type.
215  *  @tparam S      Size (# of components).
216  *  @tparam N      Is normalized.
217  *
218  *  @return Internal format.
219  */
220 template <>
221 glw::GLenum Reference::InternalFormat<glw::GLbyte, 1, false>()
222 {
223         return GL_R8I;
224 }
225
226 template <>
227 glw::GLenum Reference::InternalFormat<glw::GLbyte, 2, false>()
228 {
229         return GL_RG8I;
230 }
231
232 template <>
233 glw::GLenum Reference::InternalFormat<glw::GLbyte, 3, false>()
234 {
235         return GL_RGB8I;
236 }
237
238 template <>
239 glw::GLenum Reference::InternalFormat<glw::GLbyte, 4, false>()
240 {
241         return GL_RGBA8I;
242 }
243
244 template <>
245 glw::GLenum Reference::InternalFormat<glw::GLubyte, 1, false>()
246 {
247         return GL_R8UI;
248 }
249
250 template <>
251 glw::GLenum Reference::InternalFormat<glw::GLubyte, 2, false>()
252 {
253         return GL_RG8UI;
254 }
255
256 template <>
257 glw::GLenum Reference::InternalFormat<glw::GLubyte, 3, false>()
258 {
259         return GL_RGB8UI;
260 }
261
262 template <>
263 glw::GLenum Reference::InternalFormat<glw::GLubyte, 4, false>()
264 {
265         return GL_RGBA8UI;
266 }
267
268 template <>
269 glw::GLenum Reference::InternalFormat<glw::GLshort, 1, false>()
270 {
271         return GL_R16I;
272 }
273
274 template <>
275 glw::GLenum Reference::InternalFormat<glw::GLshort, 2, false>()
276 {
277         return GL_RG16I;
278 }
279
280 template <>
281 glw::GLenum Reference::InternalFormat<glw::GLshort, 3, false>()
282 {
283         return GL_RGB16I;
284 }
285
286 template <>
287 glw::GLenum Reference::InternalFormat<glw::GLshort, 4, false>()
288 {
289         return GL_RGBA16I;
290 }
291
292 template <>
293 glw::GLenum Reference::InternalFormat<glw::GLushort, 1, false>()
294 {
295         return GL_R16UI;
296 }
297
298 template <>
299 glw::GLenum Reference::InternalFormat<glw::GLushort, 2, false>()
300 {
301         return GL_RG16UI;
302 }
303
304 template <>
305 glw::GLenum Reference::InternalFormat<glw::GLushort, 3, false>()
306 {
307         return GL_RGB16UI;
308 }
309
310 template <>
311 glw::GLenum Reference::InternalFormat<glw::GLushort, 4, false>()
312 {
313         return GL_RGBA16UI;
314 }
315
316 template <>
317 glw::GLenum Reference::InternalFormat<glw::GLint, 1, false>()
318 {
319         return GL_R32I;
320 }
321
322 template <>
323 glw::GLenum Reference::InternalFormat<glw::GLint, 2, false>()
324 {
325         return GL_RG32I;
326 }
327
328 template <>
329 glw::GLenum Reference::InternalFormat<glw::GLint, 3, false>()
330 {
331         return GL_RGB32I;
332 }
333
334 template <>
335 glw::GLenum Reference::InternalFormat<glw::GLint, 4, false>()
336 {
337         return GL_RGBA32I;
338 }
339
340 template <>
341 glw::GLenum Reference::InternalFormat<glw::GLuint, 1, false>()
342 {
343         return GL_R32UI;
344 }
345
346 template <>
347 glw::GLenum Reference::InternalFormat<glw::GLuint, 2, false>()
348 {
349         return GL_RG32UI;
350 }
351
352 template <>
353 glw::GLenum Reference::InternalFormat<glw::GLuint, 3, false>()
354 {
355         return GL_RGB32UI;
356 }
357
358 template <>
359 glw::GLenum Reference::InternalFormat<glw::GLuint, 4, false>()
360 {
361         return GL_RGBA32UI;
362 }
363
364 template <>
365 glw::GLenum Reference::InternalFormat<glw::GLubyte, 1, true>()
366 {
367         return GL_R8;
368 }
369
370 template <>
371 glw::GLenum Reference::InternalFormat<glw::GLubyte, 2, true>()
372 {
373         return GL_RG8;
374 }
375
376 template <>
377 glw::GLenum Reference::InternalFormat<glw::GLubyte, 3, true>()
378 {
379         return GL_RGB8;
380 }
381
382 template <>
383 glw::GLenum Reference::InternalFormat<glw::GLubyte, 4, true>()
384 {
385         return GL_RGBA8;
386 }
387
388 template <>
389 glw::GLenum Reference::InternalFormat<glw::GLushort, 1, true>()
390 {
391         return GL_R16;
392 }
393
394 template <>
395 glw::GLenum Reference::InternalFormat<glw::GLushort, 2, true>()
396 {
397         return GL_RG16;
398 }
399
400 template <>
401 glw::GLenum Reference::InternalFormat<glw::GLushort, 3, true>()
402 {
403         return GL_RGB16;
404 }
405
406 template <>
407 glw::GLenum Reference::InternalFormat<glw::GLushort, 4, true>()
408 {
409         return GL_RGBA16;
410 }
411
412 template <>
413 glw::GLenum Reference::InternalFormat<glw::GLfloat, 1, true>()
414 {
415         return GL_R32F;
416 }
417
418 template <>
419 glw::GLenum Reference::InternalFormat<glw::GLfloat, 2, true>()
420 {
421         return GL_RG32F;
422 }
423
424 template <>
425 glw::GLenum Reference::InternalFormat<glw::GLfloat, 3, true>()
426 {
427         return GL_RGB32F;
428 }
429
430 template <>
431 glw::GLenum Reference::InternalFormat<glw::GLfloat, 4, true>()
432 {
433         return GL_RGBA32F;
434 }
435
436 /** @brief Format selector.
437  *
438  *  @tparam S      Size (# of components).
439  *  @tparam N      Is normalized.
440  *
441  *  @return format.
442  */
443 template <>
444 glw::GLenum Reference::Format<1, false>()
445 {
446         return GL_RED_INTEGER;
447 }
448
449 template <>
450 glw::GLenum Reference::Format<2, false>()
451 {
452         return GL_RG_INTEGER;
453 }
454
455 template <>
456 glw::GLenum Reference::Format<3, false>()
457 {
458         return GL_RGB_INTEGER;
459 }
460
461 template <>
462 glw::GLenum Reference::Format<4, false>()
463 {
464         return GL_RGBA_INTEGER;
465 }
466
467 template <>
468 glw::GLenum Reference::Format<1, true>()
469 {
470         return GL_RED;
471 }
472
473 template <>
474 glw::GLenum Reference::Format<2, true>()
475 {
476         return GL_RG;
477 }
478
479 template <>
480 glw::GLenum Reference::Format<3, true>()
481 {
482         return GL_RGB;
483 }
484
485 template <>
486 glw::GLenum Reference::Format<4, true>()
487 {
488         return GL_RGBA;
489 }
490
491 /** @brief Type selector.
492  *
493  *  @tparam T      Type.
494  *
495  *  @return Type.
496  */
497 template <>
498 glw::GLenum Reference::Type<glw::GLbyte>()
499 {
500         return GL_BYTE;
501 }
502
503 template <>
504 glw::GLenum Reference::Type<glw::GLubyte>()
505 {
506         return GL_UNSIGNED_BYTE;
507 }
508
509 template <>
510 glw::GLenum Reference::Type<glw::GLshort>()
511 {
512         return GL_SHORT;
513 }
514
515 template <>
516 glw::GLenum Reference::Type<glw::GLushort>()
517 {
518         return GL_UNSIGNED_SHORT;
519 }
520
521 template <>
522 glw::GLenum Reference::Type<glw::GLint>()
523 {
524         return GL_INT;
525 }
526
527 template <>
528 glw::GLenum Reference::Type<glw::GLuint>()
529 {
530         return GL_UNSIGNED_INT;
531 }
532
533 template <>
534 glw::GLenum Reference::Type<glw::GLfloat>()
535 {
536         return GL_FLOAT;
537 }
538
539 /** @brief Reference data selector.
540  *
541  *  @tparam T      Type.
542  *  @tparam N      Is normalized.
543  *
544  *  @return Reference data.
545  */
546
547 /* RGBA8I */
548 template <>
549 const glw::GLbyte* Reference::ReferenceData<glw::GLbyte, false>()
550 {
551         static const glw::GLbyte reference[s_reference_count] = {
552                 0,  -1,  2,  -3,  4,  -5,  6,  -7,  8,  -9,  10, -11, 12, -13, 14, -15, 16, -17, 18, -19, 20, -21, 22, -23,
553                 24, -25, 26, -27, 28, -29, 30, -31, 32, -33, 34, -35, 36, -37, 38, -39, 40, -41, 42, -43, 44, -45, 46, -47,
554                 48, -49, 50, -51, 52, -53, 54, -55, 56, -57, 58, -59, 60, -61, 62, -63, 64, -65, 66, -67, 68, -69, 70, -71,
555                 72, -73, 74, -75, 76, -77, 78, -79, 80, -81, 82, -83, 84, -85, 86, -87, 88, -89, 90, -91, 92, -93, 94, -95
556         };
557         return reference;
558 }
559
560 /* RGBA8UI */
561 template <>
562 const glw::GLubyte* Reference::ReferenceData<glw::GLubyte, false>()
563 {
564         static const glw::GLubyte reference[s_reference_count] = {
565                 0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
566                 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
567                 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
568                 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95
569         };
570         return reference;
571 }
572
573 /* RGBA16I */
574 template <>
575 const glw::GLshort* Reference::ReferenceData<glw::GLshort, false>()
576 {
577         static const glw::GLshort reference[s_reference_count] = {
578                 0,  -1,  2,  -3,  4,  -5,  6,  -7,  8,  -9,  10, -11, 12, -13, 14, -15, 16, -17, 18, -19, 20, -21, 22, -23,
579                 24, -25, 26, -27, 28, -29, 30, -31, 32, -33, 34, -35, 36, -37, 38, -39, 40, -41, 42, -43, 44, -45, 46, -47,
580                 48, -49, 50, -51, 52, -53, 54, -55, 56, -57, 58, -59, 60, -61, 62, -63, 64, -65, 66, -67, 68, -69, 70, -71,
581                 72, -73, 74, -75, 76, -77, 78, -79, 80, -81, 82, -83, 84, -85, 86, -87, 88, -89, 90, -91, 92, -93, 94, -95
582         };
583         return reference;
584 }
585
586 /* RGBA16UI */
587 template <>
588 const glw::GLushort* Reference::ReferenceData<glw::GLushort, false>()
589 {
590         static const glw::GLushort reference[s_reference_count] = {
591                 0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
592                 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
593                 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
594                 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95
595         };
596         return reference;
597 }
598
599 /* RGBA32I */
600 template <>
601 const glw::GLint* Reference::ReferenceData<glw::GLint, false>()
602 {
603         static const glw::GLint reference[s_reference_count] = {
604                 0,  -1,  2,  -3,  4,  -5,  6,  -7,  8,  -9,  10, -11, 12, -13, 14, -15, 16, -17, 18, -19, 20, -21, 22, -23,
605                 24, -25, 26, -27, 28, -29, 30, -31, 32, -33, 34, -35, 36, -37, 38, -39, 40, -41, 42, -43, 44, -45, 46, -47,
606                 48, -49, 50, -51, 52, -53, 54, -55, 56, -57, 58, -59, 60, -61, 62, -63, 64, -65, 66, -67, 68, -69, 70, -71,
607                 72, -73, 74, -75, 76, -77, 78, -79, 80, -81, 82, -83, 84, -85, 86, -87, 88, -89, 90, -91, 92, -93, 94, -95
608         };
609         return reference;
610 }
611
612 /* RGBA32UI */
613 template <>
614 const glw::GLuint* Reference::ReferenceData<glw::GLuint, false>()
615 {
616         static const glw::GLuint reference[s_reference_count] = {
617                 0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
618                 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
619                 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
620                 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95
621         };
622         return reference;
623 }
624
625 /* RGBA8 */
626 template <>
627 const glw::GLubyte* Reference::ReferenceData<glw::GLubyte, true>()
628 {
629         static const glw::GLubyte reference[s_reference_count] = {
630                 0,   2,   5,   8,   10,  13,  16,  18,  21,  24,  26,  29,  32,  34,  37,  40,  42,  45,  48,  51,
631                 53,  56,  59,  61,  64,  67,  69,  72,  75,  77,  80,  83,  85,  88,  91,  93,  96,  99,  102, 104,
632                 107, 110, 112, 115, 118, 120, 123, 126, 128, 131, 134, 136, 139, 142, 144, 147, 150, 153, 155, 158,
633                 161, 163, 166, 169, 171, 174, 177, 179, 182, 185, 187, 190, 193, 195, 198, 201, 204, 206, 209, 212,
634                 214, 217, 220, 222, 225, 228, 230, 233, 236, 238, 241, 244, 246, 249, 252, 255
635         };
636         return reference;
637 }
638
639 /* RGBA16 */
640 template <>
641 const glw::GLushort* Reference::ReferenceData<glw::GLushort, true>()
642 {
643         static const glw::GLushort reference[s_reference_count] = {
644                 0,       689,   1379,  2069,  2759,  3449,  4139,  4828,  5518,  6208,  6898,  7588,  8278,  8967,  9657,  10347,
645                 11037, 11727, 12417, 13107, 13796, 14486, 15176, 15866, 16556, 17246, 17935, 18625, 19315, 20005, 20695, 21385,
646                 22074, 22764, 23454, 24144, 24834, 25524, 26214, 26903, 27593, 28283, 28973, 29663, 30353, 31042, 31732, 32422,
647                 33112, 33802, 34492, 35181, 35871, 36561, 37251, 37941, 38631, 39321, 40010, 40700, 41390, 42080, 42770, 43460,
648                 44149, 44839, 45529, 46219, 46909, 47599, 48288, 48978, 49668, 50358, 51048, 51738, 52428, 53117, 53807, 54497,
649                 55187, 55877, 56567, 57256, 57946, 58636, 59326, 60016, 60706, 61395, 62085, 62775, 63465, 64155, 64845, 65535
650         };
651         return reference;
652 }
653
654 /* RGBA32F */
655 template <>
656 const glw::GLfloat* Reference::ReferenceData<glw::GLfloat, true>()
657 {
658         static const glw::GLfloat reference[s_reference_count] = {
659                 0.f,               0.0105263158f, 0.0210526316f, 0.0315789474f, 0.0421052632f, 0.0526315789f,
660                 0.0631578947f, 0.0736842105f, 0.0842105263f, 0.0947368421f, 0.1052631579f, 0.1157894737f,
661                 0.1263157895f, 0.1368421053f, 0.1473684211f, 0.1578947368f, 0.1684210526f, 0.1789473684f,
662                 0.1894736842f, 0.2f,              0.2105263158f, 0.2210526316f, 0.2315789474f, 0.2421052632f,
663                 0.2526315789f, 0.2631578947f, 0.2736842105f, 0.2842105263f, 0.2947368421f, 0.3052631579f,
664                 0.3157894737f, 0.3263157895f, 0.3368421053f, 0.3473684211f, 0.3578947368f, 0.3684210526f,
665                 0.3789473684f, 0.3894736842f, 0.4f,                      0.4105263158f, 0.4210526316f, 0.4315789474f,
666                 0.4421052632f, 0.4526315789f, 0.4631578947f, 0.4736842105f, 0.4842105263f, 0.4947368421f,
667                 0.5052631579f, 0.5157894737f, 0.5263157895f, 0.5368421053f, 0.5473684211f, 0.5578947368f,
668                 0.5684210526f, 0.5789473684f, 0.5894736842f, 0.6f,                      0.6105263158f, 0.6210526316f,
669                 0.6315789474f, 0.6421052632f, 0.6526315789f, 0.6631578947f, 0.6736842105f, 0.6842105263f,
670                 0.6947368421f, 0.7052631579f, 0.7157894737f, 0.7263157895f, 0.7368421053f, 0.7473684211f,
671                 0.7578947368f, 0.7684210526f, 0.7789473684f, 0.7894736842f, 0.8f,                  0.8105263158f,
672                 0.8210526316f, 0.8315789474f, 0.8421052632f, 0.8526315789f, 0.8631578947f, 0.8736842105f,
673                 0.8842105263f, 0.8947368421f, 0.9052631579f, 0.9157894737f, 0.9263157895f, 0.9368421053f,
674                 0.9473684211f, 0.9578947368f, 0.9684210526f, 0.9789473684f, 0.9894736842f, 1.f
675         };
676         return reference;
677 }
678
679 /* Total number of reference components. */
680 glw::GLuint Reference::ReferenceDataCount()
681 {
682         return s_reference_count;
683 }
684
685 /* Total number of reference size in basic machine units. */
686 template <typename T>
687 glw::GLuint Reference::ReferenceDataSize()
688 {
689         return Reference::ReferenceDataCount() * sizeof(T);
690 }
691
692 /** @brief Comparison function (for floats).
693  *
694  *  @param [in] a      First element.
695  *  @param [in] b      Second element.
696  *
697  *  @return Comparison result.
698  */
699 template <>
700 bool Reference::Compare<glw::GLfloat>(const glw::GLfloat a, const glw::GLfloat b)
701 {
702         if (de::abs(a - b) < 1.f / 256.f)
703         {
704                 return true;
705         }
706         return false;
707 }
708
709 /** @brief Comparison function (integer).
710  *
711  *  @param [in] a      First element.
712  *  @param [in] b      Second element.
713  *
714  *  @return Comparison result.
715  */
716 template <typename T>
717 bool Reference::Compare(const T a, const T b)
718 {
719         return a == b;
720 }
721
722 /******************************** Buffer Test Implementation   ********************************/
723
724 /** @brief Buffer Test constructor.
725  *
726  *  @tparam T      Type.
727  *  @tparam S      Size.
728  *  @tparam N      Is normalized.
729  *
730  *  @param [in] context     OpenGL context.
731  *  @param [in] name     Name of the test.
732  */
733 template <typename T, glw::GLint S, bool N>
734 BufferTest<T, S, N>::BufferTest(deqp::Context& context, const char* name)
735         : deqp::TestCase(context, name, "Texture Buffer Objects Test")
736         , m_fbo(0)
737         , m_rbo(0)
738         , m_po(0)
739         , m_to(0)
740         , m_bo(0)
741         , m_vao(0)
742 {
743         /* Intentionally left blank. */
744 }
745
746 /** @brief Count of reference data to be teted.
747  *
748  *  @return Count.
749  */
750 template <typename T, glw::GLint S, bool N>
751 glw::GLuint BufferTest<T, S, N>::TestReferenceDataCount()
752 {
753         return s_fbo_size_x * S;
754 }
755
756 /** @brief Size of reference data to be teted..
757  *
758  *  @return Size.
759  */
760 template <typename T, glw::GLint S, bool N>
761 glw::GLuint BufferTest<T, S, N>::TestReferenceDataSize()
762 {
763         return static_cast<glw::GLint>(TestReferenceDataCount() * sizeof(T));
764 }
765
766 /** @brief Create buffer textuew.
767  *
768  *  @param [in] use_range_version       Uses TextureBufferRange instead TextureBuffer.
769  *
770  *  @return True if succeded, false otherwise.
771  */
772 template <typename T, glw::GLint S, bool N>
773 bool BufferTest<T, S, N>::CreateBufferTexture(bool use_range_version)
774 {
775         /* Shortcut for GL functionality. */
776         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
777
778         /* Objects creation. */
779         gl.genTextures(1, &m_to);
780         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
781
782         gl.bindTexture(GL_TEXTURE_BUFFER, m_to);
783         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
784
785         gl.genBuffers(1, &m_bo);
786         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateBuffers has failed");
787
788         gl.bindBuffer(GL_TEXTURE_BUFFER, m_bo);
789         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
790
791         /* Data setup. */
792         if (use_range_version)
793         {
794                 glw::GLint alignment = 1;
795
796                 gl.getIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, &alignment);
797                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
798
799                 const glw::GLuint b_offset = alignment;
800                 const glw::GLuint b_size   = TestReferenceDataSize() + b_offset;
801
802                 gl.bufferData(GL_TEXTURE_BUFFER, b_size, NULL, GL_STATIC_DRAW);
803                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData has failed");
804
805                 gl.bufferSubData(GL_TEXTURE_BUFFER, b_offset, TestReferenceDataSize(), ReferenceData<T, N>());
806                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferSubdata has failed");
807
808                 gl.textureBufferRange(m_to, InternalFormat<T, S, N>(), m_bo, b_offset, TestReferenceDataSize());
809         }
810         else
811         {
812                 gl.bufferData(GL_TEXTURE_BUFFER, TestReferenceDataSize(), ReferenceData<T, N>(), GL_STATIC_DRAW);
813                 GLU_EXPECT_NO_ERROR(gl.getError(), "glNamedBufferData has failed");
814
815                 gl.textureBuffer(m_to, InternalFormat<T, S, N>(), m_bo);
816         }
817
818         /* Error checking. */
819         glw::GLenum error;
820
821         if (GL_NO_ERROR != (error = gl.getError()))
822         {
823                 /* Log. */
824                 m_context.getTestContext().getLog()
825                         << tcu::TestLog::Message << (use_range_version ? ("glTextureBufferRange") : ("glTextureBuffer"))
826                         << " unexpectedly generated error " << glu::getErrorStr(error) << " during test of internal format "
827                         << glu::getTextureFormatStr(InternalFormat<T, S, N>()) << "." << tcu::TestLog::EndMessage;
828
829                 CleanBufferTexture();
830
831                 return false;
832         }
833
834         return true;
835 }
836
837 /** @brief Function prepares framebuffer with internal format color attachment.
838  *         Viewport is set up. Content of the framebuffer is cleared.
839  *
840  *  @note The function may throw if unexpected error has occured.
841  *
842  *  @return if the framebuffer returned is supported
843  */
844 template <typename T, glw::GLint S, bool N>
845 bool BufferTest<T, S, N>::PrepareFramebuffer(const glw::GLenum internal_format)
846 {
847         /* Shortcut for GL functionality. */
848         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
849
850         /* Prepare framebuffer. */
851         gl.genFramebuffers(1, &m_fbo);
852         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
853
854         gl.genRenderbuffers(1, &m_rbo);
855         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
856
857         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
858         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
859
860         gl.bindRenderbuffer(GL_RENDERBUFFER, m_rbo);
861         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
862
863         gl.renderbufferStorage(GL_RENDERBUFFER, internal_format, s_fbo_size_x, s_fbo_size_y);
864         GLU_EXPECT_NO_ERROR(gl.getError(), "glRenderbufferStorage call failed.");
865
866         gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_rbo);
867         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
868
869         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
870         {
871                 if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_UNSUPPORTED)
872                         throw tcu::NotSupportedError("unsupported framebuffer configuration");
873                 else
874                         throw 0;
875         }
876
877         gl.viewport(0, 0, s_fbo_size_x, s_fbo_size_y);
878         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
879
880         /* Clear framebuffer's content. */
881         gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
882         GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
883
884         gl.clear(GL_COLOR_BUFFER_BIT);
885         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
886
887         return true;
888 }
889
890 /** @brief Create program.
891  *
892  *  @param [in] variable_declaration    Choose variable declaration of the fragment shader.
893  */
894 template <typename T, glw::GLint S, bool N>
895 void BufferTest<T, S, N>::PrepareProgram(const glw::GLchar* variable_declaration)
896 {
897         /* Shortcut for GL functionality */
898         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
899
900         struct Shader
901         {
902                 glw::GLchar const* source[3];
903                 glw::GLsizei const count;
904                 glw::GLenum const  type;
905                 glw::GLuint                id;
906         } shader[] = {
907                 { { s_vertex_shader, NULL, NULL }, 1, GL_VERTEX_SHADER, 0 },
908                 { { s_fragment_shader_head, variable_declaration, s_fragment_shader_tail }, 3, GL_FRAGMENT_SHADER, 0 }
909         };
910
911         glw::GLuint const shader_count = sizeof(shader) / sizeof(shader[0]);
912
913         try
914         {
915                 /* Create program. */
916                 m_po = gl.createProgram();
917                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateProgram call failed.");
918
919                 /* Shader compilation. */
920
921                 for (glw::GLuint i = 0; i < shader_count; ++i)
922                 {
923                         {
924                                 shader[i].id = gl.createShader(shader[i].type);
925
926                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateShader call failed.");
927
928                                 gl.attachShader(m_po, shader[i].id);
929
930                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glAttachShader call failed.");
931
932                                 gl.shaderSource(shader[i].id, shader[i].count, shader[i].source, NULL);
933
934                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource call failed.");
935
936                                 gl.compileShader(shader[i].id);
937
938                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader call failed.");
939
940                                 glw::GLint status = GL_FALSE;
941
942                                 gl.getShaderiv(shader[i].id, GL_COMPILE_STATUS, &status);
943                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
944
945                                 if (GL_FALSE == status)
946                                 {
947                                         glw::GLint log_size = 0;
948                                         gl.getShaderiv(shader[i].id, GL_INFO_LOG_LENGTH, &log_size);
949                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
950
951                                         glw::GLchar* log_text = new glw::GLchar[log_size];
952
953                                         gl.getShaderInfoLog(shader[i].id, log_size, NULL, &log_text[0]);
954
955                                         m_context.getTestContext().getLog()
956                                                 << tcu::TestLog::Message << "Shader compilation has failed.\n"
957                                                 << "Shader type: " << glu::getShaderTypeStr(shader[i].type) << "\n"
958                                                 << "Shader compilation error log:\n"
959                                                 << log_text << "\n"
960                                                 << "Shader source code:\n"
961                                                 << shader[i].source[0] << (shader[i].source[1] ? shader[i].source[1] : "")
962                                                 << (shader[i].source[2] ? shader[i].source[2] : "") << "\n"
963                                                 << tcu::TestLog::EndMessage;
964
965                                         delete[] log_text;
966
967                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog call failed.");
968
969                                         throw 0;
970                                 }
971                         }
972                 }
973
974                 /* Link. */
975                 gl.linkProgram(m_po);
976
977                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTransformFeedbackVaryings call failed.");
978
979                 glw::GLint status = GL_FALSE;
980
981                 gl.getProgramiv(m_po, GL_LINK_STATUS, &status);
982
983                 if (GL_TRUE == status)
984                 {
985                         for (glw::GLuint i = 0; i < shader_count; ++i)
986                         {
987                                 if (shader[i].id)
988                                 {
989                                         gl.detachShader(m_po, shader[i].id);
990
991                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glDetachShader call failed.");
992                                 }
993                         }
994                 }
995                 else
996                 {
997                         glw::GLint log_size = 0;
998
999                         gl.getProgramiv(m_po, GL_INFO_LOG_LENGTH, &log_size);
1000
1001                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv call failed.");
1002
1003                         glw::GLchar* log_text = new glw::GLchar[log_size];
1004
1005                         gl.getProgramInfoLog(m_po, log_size, NULL, &log_text[0]);
1006
1007                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "Program linkage has failed due to:\n"
1008                                                                                                 << log_text << "\n"
1009                                                                                                 << tcu::TestLog::EndMessage;
1010
1011                         delete[] log_text;
1012
1013                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramInfoLog call failed.");
1014
1015                         throw 0;
1016                 }
1017         }
1018         catch (...)
1019         {
1020                 if (m_po)
1021                 {
1022                         gl.deleteProgram(m_po);
1023
1024                         m_po = 0;
1025                 }
1026         }
1027
1028         for (glw::GLuint i = 0; i < shader_count; ++i)
1029         {
1030                 if (0 != shader[i].id)
1031                 {
1032                         gl.deleteShader(shader[i].id);
1033
1034                         shader[i].id = 0;
1035                 }
1036         }
1037
1038         if (0 == m_po)
1039         {
1040                 throw 0;
1041         }
1042 }
1043
1044 /** @brief Create VAO.
1045  */
1046 template <typename T, glw::GLint S, bool N>
1047 void BufferTest<T, S, N>::PrepareVertexArray()
1048 {
1049         /* Shortcut for GL functionality. */
1050         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1051
1052         gl.genVertexArrays(1, &m_vao);
1053         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays has failed");
1054
1055         gl.bindVertexArray(m_vao);
1056         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray has failed");
1057 }
1058
1059 /** @brief Test's draw function.
1060  */
1061 template <typename T, glw::GLint S, bool N>
1062 void BufferTest<T, S, N>::Draw()
1063 {
1064         /* Shortcut for GL functionality. */
1065         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1066
1067         gl.useProgram(m_po);
1068         GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed");
1069
1070         gl.activeTexture(GL_TEXTURE0);
1071         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
1072
1073         gl.bindTextureUnit(0, m_to);
1074         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
1075
1076         gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
1077         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed");
1078 }
1079
1080 /** @brief Compre results with the reference.
1081  *
1082  *  @return True if equal, false otherwise.
1083  */
1084 template <typename T, glw::GLint S, bool N>
1085 bool BufferTest<T, S, N>::Check()
1086 {
1087         /* Shortcut for GL functionality. */
1088         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1089
1090         /* Fetching data. */
1091         std::vector<T> result(TestReferenceDataCount());
1092
1093         gl.pixelStorei(GL_UNPACK_ALIGNMENT, sizeof(T));
1094         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
1095
1096         gl.pixelStorei(GL_PACK_ALIGNMENT, sizeof(T));
1097         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
1098
1099         gl.readnPixels(0, 0, s_fbo_size_x, s_fbo_size_y, Format<S, N>(), Type<T>(), TestReferenceDataSize(),
1100                                    (glw::GLvoid*)(&result[0]));
1101         GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels has failed");
1102
1103         /* Comparison. */
1104         bool is_ok = true;
1105
1106         for (glw::GLuint i = 0; i < TestReferenceDataCount(); ++i)
1107         {
1108                 if (!Compare<T>(result[i], ReferenceData<T, N>()[i]))
1109                 {
1110                         is_ok = false;
1111
1112                         break;
1113                 }
1114         }
1115
1116         return is_ok;
1117 }
1118
1119 /** @brief Test function.
1120  *
1121  *  @param [in] use_range_version   Uses TextureBufferRange instead TextureBuffer.
1122  *
1123  *  @return True if succeeded, false otherwise.
1124  */
1125 template <typename T, glw::GLint S, bool N>
1126 bool BufferTest<T, S, N>::Test(bool use_range_version)
1127 {
1128         /* Setup. */
1129         if (!PrepareFramebuffer(InternalFormat<T, S, N>()))
1130         {
1131                 /**
1132                  * If the framebuffer it not supported, means that the
1133                  * tested combination is unsupported for this driver,
1134                  * but allowed to be unsupported by OpenGL spec, so we
1135                  * just skip.
1136                  */
1137                 CleanFramebuffer();
1138                 CleanErrors();
1139
1140                 return true;
1141         }
1142
1143         if (!CreateBufferTexture(use_range_version))
1144         {
1145                 CleanFramebuffer();
1146                 CleanErrors();
1147
1148                 return false;
1149         }
1150
1151         /* Action. */
1152         Draw();
1153
1154         /* Compare results with reference. */
1155         bool result = Check();
1156
1157         /* Cleanup. */
1158         CleanFramebuffer();
1159         CleanBufferTexture();
1160         CleanErrors();
1161
1162         /* Pass result. */
1163         return result;
1164 }
1165
1166 /** @brief Clean GL objects
1167  */
1168 template <typename T, glw::GLint S, bool N>
1169 void BufferTest<T, S, N>::CleanBufferTexture()
1170 {
1171         /* Shortcut for GL functionality. */
1172         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1173
1174         /* Texture. */
1175         if (m_to)
1176         {
1177                 gl.deleteTextures(1, &m_to);
1178
1179                 m_to = 0;
1180         }
1181
1182         /* Texture buffer. */
1183         if (m_bo)
1184         {
1185                 gl.deleteBuffers(1, &m_bo);
1186
1187                 m_bo = 0;
1188         }
1189 }
1190
1191 /** @brief Clean GL objects
1192  */
1193 template <typename T, glw::GLint S, bool N>
1194 void BufferTest<T, S, N>::CleanFramebuffer()
1195 {
1196         /* Shortcut for GL functionality. */
1197         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1198
1199         /* Framebuffer. */
1200         if (m_fbo)
1201         {
1202                 gl.deleteFramebuffers(1, &m_fbo);
1203
1204                 m_fbo = 0;
1205         }
1206
1207         /* Renderbuffer. */
1208         if (m_rbo)
1209         {
1210                 gl.deleteRenderbuffers(1, &m_rbo);
1211
1212                 m_rbo = 0;
1213         }
1214 }
1215
1216 /** @brief Clean GL objects
1217  */
1218 template <typename T, glw::GLint S, bool N>
1219 void BufferTest<T, S, N>::CleanProgram()
1220 {
1221         /* Shortcut for GL functionality. */
1222         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1223
1224         /* Program. */
1225         if (m_po)
1226         {
1227                 gl.useProgram(0);
1228
1229                 gl.deleteProgram(m_po);
1230
1231                 m_po = 0;
1232         }
1233 }
1234
1235 /** @brief Clean errors.
1236  */
1237 template <typename T, glw::GLint S, bool N>
1238 void BufferTest<T, S, N>::CleanErrors()
1239 {
1240         /* Shortcut for GL functionality. */
1241         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1242
1243         /* Query all errors until GL_NO_ERROR occure. */
1244         while (GL_NO_ERROR != gl.getError())
1245                 ;
1246 }
1247
1248 /** @brief Clean GL objects
1249  */
1250 template <typename T, glw::GLint S, bool N>
1251 void BufferTest<T, S, N>::CleanVertexArray()
1252 {
1253         /* Shortcut for GL functionality. */
1254         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1255
1256         if (m_vao)
1257         {
1258                 gl.bindVertexArray(0);
1259
1260                 gl.deleteVertexArrays(1, &m_vao);
1261
1262                 m_vao = 0;
1263         }
1264 }
1265
1266 /** @brief Iterate Buffer Test cases.
1267  *
1268  *  @return Iteration result.
1269  */
1270 template <typename T, glw::GLint S, bool N>
1271 tcu::TestNode::IterateResult BufferTest<T, S, N>::iterate()
1272 {
1273         /* Shortcut for GL functionality. */
1274         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1275
1276         /* Get context setup. */
1277         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
1278         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
1279
1280         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
1281         {
1282                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
1283
1284                 return STOP;
1285         }
1286
1287         /* Running tests. */
1288         bool is_ok      = true;
1289         bool is_error = false;
1290
1291         try
1292         {
1293                 PrepareVertexArray();
1294
1295                 PrepareProgram(FragmentShaderDeclaration());
1296
1297                 for (glw::GLuint i = 0; i < 2; ++i)
1298                 {
1299                         bool use_range = (i == 1);
1300                         is_ok &= Test(use_range);
1301                         CleanErrors();
1302                 }
1303
1304                 CleanProgram();
1305         }
1306         catch (tcu::NotSupportedError e)
1307         {
1308                 throw e;
1309         }
1310         catch (...)
1311         {
1312                 is_ok   = false;
1313                 is_error = true;
1314         }
1315
1316         /* Cleanup. */
1317         CleanBufferTexture();
1318         CleanFramebuffer();
1319         CleanProgram();
1320         CleanErrors();
1321         CleanVertexArray();
1322
1323         /* Errors clean up. */
1324         while (gl.getError())
1325                 ;
1326
1327         /* Result's setup. */
1328         if (is_ok)
1329         {
1330                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1331         }
1332         else
1333         {
1334                 if (is_error)
1335                 {
1336                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
1337                 }
1338                 else
1339                 {
1340                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
1341                 }
1342         }
1343
1344         return STOP;
1345 }
1346
1347 /* Vertex shader source code. */
1348 template <typename T, glw::GLint S, bool N>
1349 const glw::GLchar* BufferTest<T, S, N>::s_vertex_shader = "#version 450\n"
1350                                                                                                                   "\n"
1351                                                                                                                   "void main()\n"
1352                                                                                                                   "{\n"
1353                                                                                                                   "    switch(gl_VertexID)\n"
1354                                                                                                                   "    {\n"
1355                                                                                                                   "        case 0:\n"
1356                                                                                                                   "            gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
1357                                                                                                                   "            break;\n"
1358                                                                                                                   "        case 1:\n"
1359                                                                                                                   "            gl_Position = vec4( 1.0, 1.0, 0.0, 1.0);\n"
1360                                                                                                                   "            break;\n"
1361                                                                                                                   "        case 2:\n"
1362                                                                                                                   "            gl_Position = vec4(-1.0,-1.0, 0.0, 1.0);\n"
1363                                                                                                                   "            break;\n"
1364                                                                                                                   "        case 3:\n"
1365                                                                                                                   "            gl_Position = vec4( 1.0,-1.0, 0.0, 1.0);\n"
1366                                                                                                                   "            break;\n"
1367                                                                                                                   "    }\n"
1368                                                                                                                   "}\n";
1369
1370 /* Fragment shader source program. */
1371 template <typename T, glw::GLint S, bool N>
1372 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_head = "#version 450\n"
1373                                                                                                                                  "\n"
1374                                                                                                                                  "layout(pixel_center_integer) in vec4 gl_FragCoord;\n"
1375                                                                                                                                  "\n";
1376
1377 template <typename T, glw::GLint S, bool N>
1378 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_fdecl_lowp = "uniform samplerBuffer texture_input;\n"
1379                                                                                                                                            "out     vec4          texture_output;\n";
1380
1381 template <typename T, glw::GLint S, bool N>
1382 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_idecl_lowp = "uniform isamplerBuffer texture_input;\n"
1383                                                                                                                                            "out     ivec4          texture_output;\n";
1384
1385 template <typename T, glw::GLint S, bool N>
1386 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_udecl_lowp = "uniform usamplerBuffer texture_input;\n"
1387                                                                                                                                            "out     uvec4          texture_output;\n";
1388
1389 template <typename T, glw::GLint S, bool N>
1390 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_fdecl_mediump = "uniform samplerBuffer texture_input;\n"
1391                                                                                                                                                   "out     vec4          texture_output;\n";
1392
1393 template <typename T, glw::GLint S, bool N>
1394 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_idecl_mediump = "uniform isamplerBuffer texture_input;\n"
1395                                                                                                                                                   "out     ivec4          texture_output;\n";
1396
1397 template <typename T, glw::GLint S, bool N>
1398 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_udecl_mediump = "uniform usamplerBuffer texture_input;\n"
1399                                                                                                                                                   "out     uvec4          texture_output;\n";
1400
1401 template <typename T, glw::GLint S, bool N>
1402 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_fdecl_highp = "uniform samplerBuffer texture_input;\n"
1403                                                                                                                                                 "out     vec4          texture_output;\n";
1404
1405 template <typename T, glw::GLint S, bool N>
1406 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_idecl_highp = "uniform isamplerBuffer texture_input;\n"
1407                                                                                                                                                 "out     ivec4          texture_output;\n";
1408
1409 template <typename T, glw::GLint S, bool N>
1410 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_udecl_highp = "uniform usamplerBuffer texture_input;\n"
1411                                                                                                                                                 "out     uvec4          texture_output;\n";
1412
1413 template <typename T, glw::GLint S, bool N>
1414 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_tail =
1415         "\n"
1416         "void main()\n"
1417         "{\n"
1418         "    texture_output = texelFetch(texture_input, int(gl_FragCoord.x));\n"
1419         "}\n";
1420
1421 template class BufferTest<glw::GLbyte, 1, false>;
1422 template class BufferTest<glw::GLbyte, 2, false>;
1423 template class BufferTest<glw::GLbyte, 4, false>;
1424
1425 template class BufferTest<glw::GLubyte, 1, false>;
1426 template class BufferTest<glw::GLubyte, 2, false>;
1427 template class BufferTest<glw::GLubyte, 4, false>;
1428 template class BufferTest<glw::GLubyte, 1, true>;
1429 template class BufferTest<glw::GLubyte, 2, true>;
1430 template class BufferTest<glw::GLubyte, 4, true>;
1431
1432 template class BufferTest<glw::GLshort, 1, false>;
1433 template class BufferTest<glw::GLshort, 2, false>;
1434 template class BufferTest<glw::GLshort, 4, false>;
1435
1436 template class BufferTest<glw::GLushort, 1, false>;
1437 template class BufferTest<glw::GLushort, 2, false>;
1438 template class BufferTest<glw::GLushort, 4, false>;
1439 template class BufferTest<glw::GLushort, 1, true>;
1440 template class BufferTest<glw::GLushort, 2, true>;
1441 template class BufferTest<glw::GLushort, 4, true>;
1442
1443 template class BufferTest<glw::GLint, 1, false>;
1444 template class BufferTest<glw::GLint, 2, false>;
1445 template class BufferTest<glw::GLint, 3, false>;
1446 template class BufferTest<glw::GLint, 4, false>;
1447
1448 template class BufferTest<glw::GLuint, 1, false>;
1449 template class BufferTest<glw::GLuint, 2, false>;
1450 template class BufferTest<glw::GLuint, 3, false>;
1451 template class BufferTest<glw::GLuint, 4, false>;
1452
1453 template class BufferTest<glw::GLfloat, 1, true>;
1454 template class BufferTest<glw::GLfloat, 2, true>;
1455 template class BufferTest<glw::GLfloat, 3, true>;
1456 template class BufferTest<glw::GLfloat, 4, true>;
1457
1458 /******************************** Storage and SubImage Test Implementation   ********************************/
1459
1460 /** @brief Storage Test constructor.
1461  *
1462  *  @param [in] context     OpenGL context.
1463  */
1464 StorageAndSubImageTest::StorageAndSubImageTest(deqp::Context& context)
1465         : deqp::TestCase(context, "textures_storage_and_subimage", "Texture Storage and SubImage Test")
1466         , m_fbo(0)
1467         , m_rbo(0)
1468         , m_po(0)
1469         , m_to(0)
1470         , m_vao(0)
1471 {
1472         /* Intentionally left blank. */
1473 }
1474
1475 /** @brief Count of reference data to be teted.
1476  *
1477  *  @tparam S      Size (# of components).
1478  *  @tparam D      Texture dimenisons.
1479  *
1480  *  @return Count.
1481  */
1482 template <glw::GLint S, glw::GLuint D>
1483 glw::GLuint StorageAndSubImageTest::TestReferenceDataCount()
1484 {
1485         return 2 /* 1D */ * ((D > 1) ? 3 : 1) /* 2D */ * ((D > 2) ? 4 : 1) /* 3D */ * S /* components */;
1486 }
1487
1488 /** @brief Size of reference data to be teted.
1489  *
1490  *  @tparam T      Type.
1491  *  @tparam S      Size (# of components).
1492  *  @tparam D      Texture dimenisons.
1493  *
1494  *  @return Size.
1495  */
1496 template <typename T, glw::GLint S, glw::GLuint D>
1497 glw::GLuint StorageAndSubImageTest::TestReferenceDataSize()
1498 {
1499         return static_cast<glw::GLint>(TestReferenceDataCount<S, D>() * sizeof(T));
1500 }
1501
1502 /** @brief Height, width or depth of reference data to be teted.
1503  *
1504  *  @tparam D      Texture dimenisons.
1505  *
1506  *  @return Height, width or depth.
1507  */
1508 template <>
1509 glw::GLuint StorageAndSubImageTest::TestReferenceDataHeight<2>()
1510 {
1511         return 3;
1512 }
1513
1514 template <>
1515 glw::GLuint StorageAndSubImageTest::TestReferenceDataHeight<3>()
1516 {
1517         return 3;
1518 }
1519
1520 template <>
1521 glw::GLuint StorageAndSubImageTest::TestReferenceDataDepth<3>()
1522 {
1523         return 4;
1524 }
1525
1526 template <glw::GLuint D>
1527 glw::GLuint                       StorageAndSubImageTest::TestReferenceDataWidth()
1528 {
1529         return 2;
1530 }
1531
1532 template <glw::GLuint D>
1533 glw::GLuint                       StorageAndSubImageTest::TestReferenceDataHeight()
1534 {
1535         return 1;
1536 }
1537
1538 template <glw::GLuint D>
1539 glw::GLuint                       StorageAndSubImageTest::TestReferenceDataDepth()
1540 {
1541         return 1;
1542 }
1543
1544 /** @brief Fragment shader declaration selector.
1545  *
1546  *  @tparam T      Type.
1547  *  @tparam N      Normalized flag.
1548  *  @tparam D      Texture dimenisons.
1549  *
1550  *  @return Frgment shader source code part.
1551  */
1552 template <>
1553 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLbyte, false, 1>()
1554 {
1555         return s_fragment_shader_1D_fdecl_lowp;
1556 }
1557
1558 template <>
1559 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLubyte, false, 1>()
1560 {
1561         return s_fragment_shader_1D_idecl_lowp;
1562 }
1563
1564 template <>
1565 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLshort, false, 1>()
1566 {
1567         return s_fragment_shader_1D_udecl_lowp;
1568 }
1569
1570 template <>
1571 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLushort, false, 1>()
1572 {
1573         return s_fragment_shader_1D_fdecl_mediump;
1574 }
1575
1576 template <>
1577 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLint, false, 1>()
1578 {
1579         return s_fragment_shader_1D_idecl_mediump;
1580 }
1581
1582 template <>
1583 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLuint, false, 1>()
1584 {
1585         return s_fragment_shader_1D_udecl_mediump;
1586 }
1587
1588 template <>
1589 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLubyte, true, 1>()
1590 {
1591         return s_fragment_shader_1D_fdecl_highp;
1592 }
1593
1594 template <>
1595 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLushort, true, 1>()
1596 {
1597         return s_fragment_shader_1D_idecl_highp;
1598 }
1599
1600 template <>
1601 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLfloat, true, 1>()
1602 {
1603         return s_fragment_shader_1D_udecl_highp;
1604 }
1605
1606 template <>
1607 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLbyte, false, 2>()
1608 {
1609         return s_fragment_shader_2D_fdecl_lowp;
1610 }
1611
1612 template <>
1613 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLubyte, false, 2>()
1614 {
1615         return s_fragment_shader_2D_idecl_lowp;
1616 }
1617
1618 template <>
1619 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLshort, false, 2>()
1620 {
1621         return s_fragment_shader_2D_udecl_lowp;
1622 }
1623
1624 template <>
1625 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLushort, false, 2>()
1626 {
1627         return s_fragment_shader_2D_fdecl_mediump;
1628 }
1629
1630 template <>
1631 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLint, false, 2>()
1632 {
1633         return s_fragment_shader_2D_idecl_mediump;
1634 }
1635
1636 template <>
1637 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLuint, false, 2>()
1638 {
1639         return s_fragment_shader_2D_udecl_mediump;
1640 }
1641
1642 template <>
1643 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLubyte, true, 2>()
1644 {
1645         return s_fragment_shader_2D_fdecl_highp;
1646 }
1647
1648 template <>
1649 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLushort, true, 2>()
1650 {
1651         return s_fragment_shader_2D_idecl_highp;
1652 }
1653
1654 template <>
1655 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLfloat, true, 2>()
1656 {
1657         return s_fragment_shader_2D_udecl_highp;
1658 }
1659
1660 template <>
1661 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLbyte, false, 3>()
1662 {
1663         return s_fragment_shader_3D_fdecl_lowp;
1664 }
1665
1666 template <>
1667 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLubyte, false, 3>()
1668 {
1669         return s_fragment_shader_3D_idecl_lowp;
1670 }
1671
1672 template <>
1673 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLshort, false, 3>()
1674 {
1675         return s_fragment_shader_3D_udecl_lowp;
1676 }
1677
1678 template <>
1679 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLushort, false, 3>()
1680 {
1681         return s_fragment_shader_3D_fdecl_mediump;
1682 }
1683
1684 template <>
1685 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLint, false, 3>()
1686 {
1687         return s_fragment_shader_3D_idecl_mediump;
1688 }
1689
1690 template <>
1691 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLuint, false, 3>()
1692 {
1693         return s_fragment_shader_3D_udecl_mediump;
1694 }
1695
1696 template <>
1697 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLubyte, true, 3>()
1698 {
1699         return s_fragment_shader_3D_fdecl_highp;
1700 }
1701
1702 template <>
1703 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLushort, true, 3>()
1704 {
1705         return s_fragment_shader_3D_idecl_highp;
1706 }
1707
1708 template <>
1709 const glw::GLchar* StorageAndSubImageTest::FragmentShaderDeclaration<glw::GLfloat, true, 3>()
1710 {
1711         return s_fragment_shader_3D_udecl_highp;
1712 }
1713
1714 /** @brief Fragment shader tail selector.
1715  *
1716  *  @tparam D      Texture dimenisons.
1717  *
1718  *  @return Frgment shader source code part.
1719  */
1720 template <>
1721 const glw::GLchar* StorageAndSubImageTest::FragmentShaderTail<1>()
1722 {
1723         return s_fragment_shader_1D_tail;
1724 }
1725
1726 template <>
1727 const glw::GLchar* StorageAndSubImageTest::FragmentShaderTail<2>()
1728 {
1729         return s_fragment_shader_2D_tail;
1730 }
1731
1732 template <>
1733 const glw::GLchar* StorageAndSubImageTest::FragmentShaderTail<3>()
1734 {
1735         return s_fragment_shader_3D_tail;
1736 }
1737
1738 /** @brief Texture target selector.
1739  *
1740  *  @tparam D      Texture dimenisons.
1741  *
1742  *  @return Texture target.
1743  */
1744 template <>
1745 glw::GLenum StorageAndSubImageTest::TextureTarget<1>()
1746 {
1747         return GL_TEXTURE_1D;
1748 }
1749
1750 template <>
1751 glw::GLenum StorageAndSubImageTest::TextureTarget<2>()
1752 {
1753         return GL_TEXTURE_2D;
1754 }
1755
1756 template <>
1757 glw::GLenum StorageAndSubImageTest::TextureTarget<3>()
1758 {
1759         return GL_TEXTURE_3D;
1760 }
1761
1762 /** @brief TextureStorage* wrapper.
1763  *
1764  *  @tparam D      Texture dimenisons.
1765  *  @tparam I      Select between legacy/DSA way.
1766  *
1767  *  @return true if suuceed (in legacy always or throw), false otherwise.
1768  */
1769 template <>
1770 bool StorageAndSubImageTest::TextureStorage<1, true>(glw::GLenum target, glw::GLuint texture, glw::GLsizei levels,
1771                                                                                                          glw::GLenum internalformat, glw::GLsizei width,
1772                                                                                                          glw::GLsizei height, glw::GLsizei depth)
1773 {
1774         (void)texture;
1775         (void)height;
1776         (void)depth;
1777         /* Shortcut for GL functionality. */
1778         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1779
1780         /* Preparing storage. */
1781         gl.texStorage1D(target, levels, internalformat, width);
1782         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexStorage1D has failed");
1783
1784         /* TextureSubImage* (not TextureStorage*) is tested so here we only throw when error occurs. */
1785         return true;
1786 }
1787
1788 /** @brief TextureStorage* wrapper.
1789  *
1790  *  @tparam D      Texture dimenisons.
1791  *  @tparam I      Select between legacy/DSA way.
1792  *
1793  *  @return true if suuceed (in legacy always or throw), false otherwise.
1794  */
1795 template <>
1796 bool StorageAndSubImageTest::TextureStorage<2, true>(glw::GLenum target, glw::GLuint texture, glw::GLsizei levels,
1797                                                                                                          glw::GLenum internalformat, glw::GLsizei width,
1798                                                                                                          glw::GLsizei height, glw::GLsizei depth)
1799 {
1800         (void)texture;
1801         (void)depth;
1802         /* Shortcut for GL functionality. */
1803         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1804
1805         /* Preparing storage. */
1806         gl.texStorage2D(target, levels, internalformat, width, height);
1807         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexStorage2D has failed");
1808
1809         /* TextureSubImage* (not TextureStorage*) is tested so here we only throw when error occurs. */
1810         return true;
1811 }
1812
1813 /** @brief TextureStorage* wrapper.
1814  *
1815  *  @tparam D      Texture dimenisons.
1816  *  @tparam I      Select between legacy/DSA way.
1817  *
1818  *  @return true if suuceed (in legacy always or throw), false otherwise.
1819  */
1820 template <>
1821 bool StorageAndSubImageTest::TextureStorage<3, true>(glw::GLenum target, glw::GLuint texture, glw::GLsizei levels,
1822                                                                                                          glw::GLenum internalformat, glw::GLsizei width,
1823                                                                                                          glw::GLsizei height, glw::GLsizei depth)
1824 {
1825         (void)texture;
1826         /* Shortcut for GL functionality. */
1827         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1828
1829         /* Preparing storage. */
1830         gl.texStorage3D(target, levels, internalformat, width, height, depth);
1831         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexStorage3D has failed");
1832
1833         /* TextureSubImage* (not TextureStorage*) is tested so here we only throw when error occurs. */
1834         return true;
1835 }
1836
1837 /** @brief TextureStorage* wrapper.
1838  *
1839  *  @tparam D      Texture dimenisons.
1840  *  @tparam I      Select between legacy/DSA way.
1841  *
1842  *  @return true if suuceed (in legacy always or throw), false otherwise.
1843  */
1844 template <>
1845 bool StorageAndSubImageTest::TextureStorage<1, false>(glw::GLenum target, glw::GLuint texture, glw::GLsizei levels,
1846                                                                                                           glw::GLenum internalformat, glw::GLsizei width,
1847                                                                                                           glw::GLsizei height, glw::GLsizei depth)
1848 {
1849         (void)target;
1850         (void)height;
1851         (void)depth;
1852         /* Shortcut for GL functionality. */
1853         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1854
1855         /* Preparing storage. */
1856         gl.textureStorage1D(texture, levels, internalformat, width);
1857
1858         /* Error checking. */
1859         glw::GLenum error;
1860
1861         if (GL_NO_ERROR != (error = gl.getError()))
1862         {
1863                 /* Log. */
1864                 m_context.getTestContext().getLog()
1865                         << tcu::TestLog::Message << "glTextureStorage1D unexpectedly generated error " << glu::getErrorStr(error)
1866                         << " during test with levels " << levels << ", internal format " << internalformat << " and width " << width
1867                         << "." << tcu::TestLog::EndMessage;
1868
1869                 CleanTexture();
1870                 CleanErrors();
1871
1872                 return false;
1873         }
1874
1875         return true;
1876 }
1877
1878 /** @brief TextureStorage* wrapper.
1879  *
1880  *  @tparam D      Texture dimenisons.
1881  *  @tparam I      Select between legacy/DSA way.
1882  *
1883  *  @return true if suuceed (in legacy always or throw), false otherwise.
1884  */
1885 template <>
1886 bool StorageAndSubImageTest::TextureStorage<2, false>(glw::GLenum target, glw::GLuint texture, glw::GLsizei levels,
1887                                                                                                           glw::GLenum internalformat, glw::GLsizei width,
1888                                                                                                           glw::GLsizei height, glw::GLsizei depth)
1889 {
1890         (void)target;
1891         (void)depth;
1892         /* Shortcut for GL functionality. */
1893         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1894
1895         /* Preparing storage. */
1896         gl.textureStorage2D(texture, levels, internalformat, width, height);
1897
1898         /* Error checking. */
1899         glw::GLenum error;
1900
1901         if (GL_NO_ERROR != (error = gl.getError()))
1902         {
1903                 /* Log. */
1904                 m_context.getTestContext().getLog()
1905                         << tcu::TestLog::Message << "glTextureStorage2D unexpectedly generated error " << glu::getErrorStr(error)
1906                         << " during test with levels " << levels << ", internal format " << internalformat << ", width " << width
1907                         << " and height " << height << "." << tcu::TestLog::EndMessage;
1908
1909                 CleanTexture();
1910                 CleanErrors();
1911
1912                 return false;
1913         }
1914
1915         return true;
1916 }
1917
1918 /** @brief TextureStorage* wrapper.
1919  *
1920  *  @tparam D      Texture dimenisons.
1921  *  @tparam I      Select between legacy/DSA way.
1922  *
1923  *  @return true if suuceed (in legacy always or throw), false otherwise.
1924  */
1925 template <>
1926 bool StorageAndSubImageTest::TextureStorage<3, false>(glw::GLenum target, glw::GLuint texture, glw::GLsizei levels,
1927                                                                                                           glw::GLenum internalformat, glw::GLsizei width,
1928                                                                                                           glw::GLsizei height, glw::GLsizei depth)
1929 {
1930         (void)target;
1931         /* Shortcut for GL functionality. */
1932         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1933
1934         /* Preparing storage. */
1935         gl.textureStorage3D(texture, levels, internalformat, width, height, depth);
1936
1937         /* Error checking. */
1938         glw::GLenum error;
1939
1940         if (GL_NO_ERROR != (error = gl.getError()))
1941         {
1942                 /* Log. */
1943                 m_context.getTestContext().getLog()
1944                         << tcu::TestLog::Message << "glTextureStorage3D unexpectedly generated error " << glu::getErrorStr(error)
1945                         << " during test with levels " << levels << ", internal format " << glu::getTextureFormatStr(internalformat)
1946                         << ", width " << width << ", height " << height << " and depth " << depth << "."
1947                         << tcu::TestLog::EndMessage;
1948
1949                 CleanTexture();
1950                 CleanErrors();
1951
1952                 return false;
1953         }
1954
1955         return true;
1956 }
1957
1958 /** @brief TextureSubImage* wrapper.
1959  *
1960  *  @tparam D      Texture dimenisons.
1961  *  @tparam I      Select between legacy/DSA way.
1962  *
1963  *  @return true if suuceed (in legacy always or throw), false otherwise.
1964  */
1965 template <>
1966 bool StorageAndSubImageTest::TextureSubImage<1, false>(glw::GLenum target, glw::GLuint texture, glw::GLint level,
1967                                                                                                            glw::GLint internalformat, glw::GLsizei width,
1968                                                                                                            glw::GLsizei height, glw::GLsizei depth, glw::GLenum format,
1969                                                                                                            glw::GLenum type, const glw::GLvoid* data)
1970 {
1971         (void)texture;
1972         (void)internalformat;
1973         (void)height;
1974         (void)depth;
1975         /* Shortcut for GL functionality. */
1976         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1977
1978         /* Action. */
1979         gl.texSubImage1D(target, level, 0, width, format, type, data);
1980         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexSubImage1D has failed");
1981
1982         /* TextureStorage* (not TextureSubImage) is tested so here we only throw when error occurs. */
1983         return true;
1984 }
1985
1986 /** @brief TextureSubImage* wrapper.
1987  *
1988  *  @tparam D      Texture dimenisons.
1989  *  @tparam I      Select between legacy/DSA way.
1990  *
1991  *  @return true if suuceed (in legacy always or throw), false otherwise.
1992  */
1993 template <>
1994 bool StorageAndSubImageTest::TextureSubImage<2, false>(glw::GLenum target, glw::GLuint texture, glw::GLint level,
1995                                                                                                            glw::GLint internalformat, glw::GLsizei width,
1996                                                                                                            glw::GLsizei height, glw::GLsizei depth, glw::GLenum format,
1997                                                                                                            glw::GLenum type, const glw::GLvoid* data)
1998 {
1999         (void)texture;
2000         (void)internalformat;
2001         (void)depth;
2002         /* Shortcut for GL functionality. */
2003         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2004
2005         /* Action. */
2006         gl.texSubImage2D(target, level, 0, 0, width, height, format, type, data);
2007         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexSubImage2D has failed");
2008
2009         /* TextureStorage* (not TextureSubImage) is tested so here we only throw when error occurs. */
2010         return true;
2011 }
2012
2013 /** @brief TextureSubImage* wrapper.
2014  *
2015  *  @tparam D      Texture dimenisons.
2016  *  @tparam I      Select between legacy/DSA way.
2017  *
2018  *  @return true if suuceed (in legacy always or throw), false otherwise.
2019  */
2020 template <>
2021 bool StorageAndSubImageTest::TextureSubImage<3, false>(glw::GLenum target, glw::GLuint texture, glw::GLint level,
2022                                                                                                            glw::GLint internalformat, glw::GLsizei width,
2023                                                                                                            glw::GLsizei height, glw::GLsizei depth, glw::GLenum format,
2024                                                                                                            glw::GLenum type, const glw::GLvoid* data)
2025 {
2026         (void)texture;
2027         (void)internalformat;
2028         /* Shortcut for GL functionality. */
2029         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2030
2031         /* Action. */
2032         gl.texSubImage3D(target, level, 0, 0, 0, width, height, depth, format, type, data);
2033         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexSubImage3D has failed");
2034
2035         /* TextureStorage* (not TextureSubImage) is tested so here we only throw when error occurs. */
2036         return true;
2037 }
2038
2039 /** @brief TextureSubImage* wrapper.
2040  *
2041  *  @tparam D      Texture dimenisons.
2042  *  @tparam I      Select between legacy/DSA way.
2043  *
2044  *  @return true if suuceed (in legacy always or throw), false otherwise.
2045  */
2046 template <>
2047 bool StorageAndSubImageTest::TextureSubImage<1, true>(glw::GLenum target, glw::GLuint texture, glw::GLint level,
2048                                                                                                           glw::GLint internalformat, glw::GLsizei width,
2049                                                                                                           glw::GLsizei height, glw::GLsizei depth, glw::GLenum format,
2050                                                                                                           glw::GLenum type, const glw::GLvoid* data)
2051 {
2052         (void)target;
2053         (void)internalformat;
2054         (void)height;
2055         (void)depth;
2056         /* Shortcut for GL functionality. */
2057         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2058
2059         /* Action. */
2060         gl.textureSubImage1D(texture, level, 0, width, format, type, data);
2061
2062         /* Error checking. */
2063         glw::GLenum error;
2064
2065         if (GL_NO_ERROR != (error = gl.getError()))
2066         {
2067                 /* Log. */
2068                 m_context.getTestContext().getLog()
2069                         << tcu::TestLog::Message << "glTextureSubImage1D unexpectedly generated error " << glu::getErrorStr(error)
2070                         << " during test with level " << level << ", width " << width << ", format "
2071                         << glu::getTextureFormatStr(format) << " and type " << glu::getTypeStr(type) << "."
2072                         << tcu::TestLog::EndMessage;
2073
2074                 CleanTexture();
2075                 CleanErrors();
2076
2077                 return false;
2078         }
2079
2080         return true;
2081 }
2082
2083 /** @brief TextureSubImage* wrapper.
2084  *
2085  *  @tparam D      Texture dimenisons.
2086  *  @tparam I      Select between legacy/DSA way.
2087  *
2088  *  @return true if suuceed (in legacy always or throw), false otherwise.
2089  */
2090 template <>
2091 bool StorageAndSubImageTest::TextureSubImage<2, true>(glw::GLenum target, glw::GLuint texture, glw::GLint level,
2092                                                                                                           glw::GLint internalformat, glw::GLsizei width,
2093                                                                                                           glw::GLsizei height, glw::GLsizei depth, glw::GLenum format,
2094                                                                                                           glw::GLenum type, const glw::GLvoid* data)
2095 {
2096         (void)target;
2097         (void)internalformat;
2098         (void)depth;
2099         /* Shortcut for GL functionality. */
2100         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2101
2102         /* Action. */
2103         gl.textureSubImage2D(texture, level, 0, 0, width, height, format, type, data);
2104
2105         /* Error checking. */
2106         glw::GLenum error;
2107
2108         if (GL_NO_ERROR != (error = gl.getError()))
2109         {
2110                 /* Log. */
2111                 m_context.getTestContext().getLog()
2112                         << tcu::TestLog::Message << "glTextureSubImage2D unexpectedly generated error " << glu::getErrorStr(error)
2113                         << " during test with level " << level << ", width " << width << ", height " << height << ", format "
2114                         << glu::getTextureFormatStr(format) << " and type " << glu::getTypeStr(type) << "."
2115                         << tcu::TestLog::EndMessage;
2116
2117                 CleanTexture();
2118                 CleanErrors();
2119
2120                 return false;
2121         }
2122
2123         return true;
2124 }
2125
2126 /** @brief TextureSubImage* wrapper.
2127  *
2128  *  @tparam D      Texture dimenisons.
2129  *  @tparam I      Select between legacy/DSA way.
2130  *
2131  *  @return true if suuceed (in legacy always or throw), false otherwise.
2132  */
2133 template <>
2134 bool StorageAndSubImageTest::TextureSubImage<3, true>(glw::GLenum target, glw::GLuint texture, glw::GLint level,
2135                                                                                                           glw::GLint internalformat, glw::GLsizei width,
2136                                                                                                           glw::GLsizei height, glw::GLsizei depth, glw::GLenum format,
2137                                                                                                           glw::GLenum type, const glw::GLvoid* data)
2138 {
2139         (void)target;
2140         (void)internalformat;
2141         /* Shortcut for GL functionality. */
2142         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2143
2144         /* Action. */
2145         gl.textureSubImage3D(texture, level, 0, 0, 0, width, height, depth, format, type, data);
2146
2147         /* Error checking. */
2148         glw::GLenum error;
2149
2150         if (GL_NO_ERROR != (error = gl.getError()))
2151         {
2152                 /* Log. */
2153                 m_context.getTestContext().getLog()
2154                         << tcu::TestLog::Message << "glTextureSubImage3D unexpectedly generated error " << glu::getErrorStr(error)
2155                         << " during test with level " << level << ", width " << width << ", height " << height << ", depth "
2156                         << depth << ", format " << glu::getTextureFormatStr(format) << " and type " << glu::getTypeStr(type) << "."
2157                         << tcu::TestLog::EndMessage;
2158
2159                 CleanTexture();
2160                 CleanErrors();
2161
2162                 return false;
2163         }
2164
2165         return true;
2166 }
2167
2168 /** @brief Create texture.
2169  *
2170  *  @tparam T      Type.
2171  *  @tparam S      Size (# of components).
2172  *  @tparam N      Is normalized.
2173  *  @tparam D      Dimmensions.
2174  *  @tparam I      Test SubImage or Storage.
2175  *
2176  *  @return True if succeded, false otherwise.
2177  */
2178 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2179 bool StorageAndSubImageTest::CreateTexture()
2180 {
2181         /* Shortcut for GL functionality. */
2182         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2183
2184         /* Objects creation. */
2185         gl.genTextures(1, &m_to);
2186         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
2187
2188         gl.bindTexture(TextureTarget<D>(), m_to);
2189         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
2190
2191         /* Storage creation. */
2192         if (TextureStorage<D, I>(TextureTarget<D>(), m_to, 1, InternalFormat<T, S, N>(), TestReferenceDataWidth<D>(),
2193                                                          TestReferenceDataHeight<D>(), TestReferenceDataDepth<D>()))
2194         {
2195                 /* Data setup. */
2196                 if (TextureSubImage<D, I>(TextureTarget<D>(), m_to, 0, InternalFormat<T, S, N>(), TestReferenceDataWidth<D>(),
2197                                                                   TestReferenceDataHeight<D>(), TestReferenceDataDepth<D>(), Format<S, N>(), Type<T>(),
2198                                                                   ReferenceData<T, N>()))
2199                 {
2200                         glTexParameteri(TextureTarget<D>(), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2201                         glTexParameteri(TextureTarget<D>(), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2202                         return true;
2203                 }
2204         }
2205
2206         CleanTexture();
2207
2208         return false;
2209 }
2210
2211 /** @brief Compre results with the reference.
2212  *
2213  *  @tparam T      Type.
2214  *  @tparam S      Size (# of components).
2215  *  @tparam N      Is normalized.
2216  *
2217  *  @return True if equal, false otherwise.
2218  */
2219 template <typename T, glw::GLint S, bool N, glw::GLuint D>
2220 bool StorageAndSubImageTest::Check()
2221 {
2222         /* Shortcut for GL functionality. */
2223         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2224
2225         /* Fetching data. */
2226         std::vector<T> result(TestReferenceDataCount<S, D>());
2227
2228         gl.pixelStorei(GL_UNPACK_ALIGNMENT, sizeof(T));
2229         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
2230
2231         gl.pixelStorei(GL_PACK_ALIGNMENT, sizeof(T));
2232         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
2233
2234         glw::GLuint fbo_size_x = 0;
2235
2236         switch (D)
2237         {
2238         case 1:
2239                 fbo_size_x = 2;
2240                 break;
2241         case 2:
2242                 fbo_size_x = 2 * 3;
2243                 break;
2244         case 3:
2245                 fbo_size_x = 2 * 3 * 4;
2246                 break;
2247         default:
2248                 throw 0;
2249         }
2250
2251         gl.readnPixels(0, 0, fbo_size_x, 1, Format<S, N>(), Type<T>(), TestReferenceDataSize<T, S, D>(),
2252                                    (glw::GLvoid*)(&result[0]));
2253         GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels has failed");
2254
2255         /* Comparison. */
2256         for (glw::GLuint i = 0; i < TestReferenceDataCount<S, D>(); ++i)
2257         {
2258                 if (!Compare<T>(result[i], ReferenceData<T, N>()[i]))
2259                 {
2260                         return false;
2261                 }
2262         }
2263
2264         return true;
2265 }
2266
2267 /** @brief Test case function.
2268  *
2269  *  @tparam T       Type.
2270  *  @tparam S       Size (# of components).
2271  *  @tparam N       Is normalized.
2272  *  @tparam D       Number of texture dimensions.
2273  *
2274  *  @return True if test succeeded, false otherwise.
2275  */
2276 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2277 bool StorageAndSubImageTest::Test()
2278 {
2279         /* Setup. */
2280         PrepareFramebuffer(InternalFormat<T, S, N>(), D);
2281
2282         if (!CreateTexture<T, S, N, D, I>())
2283         {
2284                 return false;
2285         }
2286
2287         /* Action. */
2288         Draw();
2289
2290         /* Compare results with reference. */
2291         bool result = Check<T, S, N, D>();
2292
2293         /* Cleanup. */
2294         CleanTexture();
2295         CleanFramebuffer();
2296         CleanErrors();
2297
2298         /* Pass result. */
2299         return result;
2300 }
2301
2302 /** @brief Lopp test function over S.
2303  *
2304  *  @tparam T      Type.
2305  *  @tparam N      Is normalized.
2306  *  @tparam D      Texture dimension.
2307  *  @tparam I      Choose between SubImage and Storage tests.
2308  *
2309  *  @param [in] skip_rgb            Skip test of S = 3 (needed for some formats).
2310  *
2311  *  @return True if tests succeeded, false otherwise.
2312  */
2313 template <typename T, bool N, glw::GLuint D, bool I>
2314 bool StorageAndSubImageTest::LoopTestOverS(bool skip_rgb)
2315 {
2316         /* Prepare one program per test loop. */
2317         PrepareProgram(FragmentShaderDeclaration<T, N, D>(), FragmentShaderTail<D>());
2318
2319         /* Run tests. */
2320         bool result = true;
2321
2322         result &= Test<T, 1, N, D, I>();
2323
2324         result &= Test<T, 2, N, D, I>();
2325
2326         if (!skip_rgb)
2327         {
2328                 result &= Test<T, 3, N, D, I>();
2329         }
2330
2331         result &= Test<T, 4, N, D, I>();
2332
2333         /* Cleanup.*/
2334         CleanProgram();
2335         CleanErrors();
2336
2337         /* Pass result. */
2338         return result;
2339 }
2340
2341 /** @brief Lopp test function over D and over S.
2342  *
2343  *  @tparam T      Type.
2344  *  @tparam N      Is normalized.
2345  *  @tparam I      Choose between SubImage and Storage tests.
2346  *
2347  *  @param [in] skip_rgb            Skip test of S = 3 (needed for some formats).
2348  *
2349  *  @return True if tests succeeded, false otherwise.
2350  */
2351 template <typename T, bool N, bool I>
2352 bool StorageAndSubImageTest::LoopTestOverDOverS(bool skip_rgb)
2353 {
2354         bool result = true;
2355
2356         result &= LoopTestOverS<T, N, 1, I>(skip_rgb);
2357         result &= LoopTestOverS<T, N, 2, I>(skip_rgb);
2358         result &= LoopTestOverS<T, N, 3, I>(skip_rgb);
2359
2360         return result;
2361 }
2362
2363 /** @brief Function prepares framebuffer with internal format color attachment.
2364  *         Viewport is set up. Content of the framebuffer is cleared.
2365  *
2366  *  @note The function may throw if unexpected error has occured.
2367  */
2368 void StorageAndSubImageTest::PrepareFramebuffer(const glw::GLenum internal_format, const glw::GLuint D)
2369 {
2370         /* Shortcut for GL functionality. */
2371         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2372
2373         /* Prepare framebuffer. */
2374         gl.genFramebuffers(1, &m_fbo);
2375         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
2376
2377         gl.genRenderbuffers(1, &m_rbo);
2378         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
2379
2380         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
2381         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
2382
2383         gl.bindRenderbuffer(GL_RENDERBUFFER, m_rbo);
2384         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
2385
2386         glw::GLuint fbo_size_x = 0;
2387
2388         switch (D)
2389         {
2390         case 1:
2391                 fbo_size_x = 2;
2392                 break;
2393         case 2:
2394                 fbo_size_x = 2 * 3;
2395                 break;
2396         case 3:
2397                 fbo_size_x = 2 * 3 * 4;
2398                 break;
2399         default:
2400                 throw 0;
2401         }
2402
2403         gl.renderbufferStorage(GL_RENDERBUFFER, internal_format, fbo_size_x, 1);
2404         GLU_EXPECT_NO_ERROR(gl.getError(), "glRenderbufferStorage call failed.");
2405
2406         gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_rbo);
2407         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
2408
2409         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
2410         {
2411                 throw 0;
2412         }
2413
2414         gl.viewport(0, 0, fbo_size_x, 1);
2415         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
2416
2417         /* Clear framebuffer's content. */
2418         gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
2419         GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
2420
2421         gl.clear(GL_COLOR_BUFFER_BIT);
2422         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
2423 }
2424
2425 /** @brief Prepare program
2426  *
2427  *  @param [in] variable_declaration      Variables declaration part of fragment shader source code.
2428  *  @param [in] tail                      Tail part of fragment shader source code.
2429  */
2430 void StorageAndSubImageTest::PrepareProgram(const glw::GLchar* variable_declaration, const glw::GLchar* tail)
2431 {
2432         /* Shortcut for GL functionality */
2433         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2434
2435         struct Shader
2436         {
2437                 glw::GLchar const* source[3];
2438                 glw::GLsizei const count;
2439                 glw::GLenum const  type;
2440                 glw::GLuint                id;
2441         } shader[] = { { { s_vertex_shader, NULL, NULL }, 1, GL_VERTEX_SHADER, 0 },
2442                                    { { s_fragment_shader_head, variable_declaration, tail }, 3, GL_FRAGMENT_SHADER, 0 } };
2443
2444         glw::GLuint const shader_count = sizeof(shader) / sizeof(shader[0]);
2445
2446         try
2447         {
2448                 /* Create program. */
2449                 m_po = gl.createProgram();
2450                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateProgram call failed.");
2451
2452                 /* Shader compilation. */
2453
2454                 for (glw::GLuint i = 0; i < shader_count; ++i)
2455                 {
2456                         {
2457                                 shader[i].id = gl.createShader(shader[i].type);
2458
2459                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateShader call failed.");
2460
2461                                 gl.attachShader(m_po, shader[i].id);
2462
2463                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glAttachShader call failed.");
2464
2465                                 gl.shaderSource(shader[i].id, shader[i].count, shader[i].source, NULL);
2466
2467                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource call failed.");
2468
2469                                 gl.compileShader(shader[i].id);
2470
2471                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader call failed.");
2472
2473                                 glw::GLint status = GL_FALSE;
2474
2475                                 gl.getShaderiv(shader[i].id, GL_COMPILE_STATUS, &status);
2476                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
2477
2478                                 if (GL_FALSE == status)
2479                                 {
2480                                         glw::GLint log_size = 0;
2481                                         gl.getShaderiv(shader[i].id, GL_INFO_LOG_LENGTH, &log_size);
2482                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
2483
2484                                         glw::GLchar* log_text = new glw::GLchar[log_size];
2485
2486                                         gl.getShaderInfoLog(shader[i].id, log_size, NULL, &log_text[0]);
2487
2488                                         m_context.getTestContext().getLog()
2489                                                 << tcu::TestLog::Message << "Shader compilation has failed.\n"
2490                                                 << "Shader type: " << glu::getShaderTypeStr(shader[i].type) << "\n"
2491                                                 << "Shader compilation error log:\n"
2492                                                 << log_text << "\n"
2493                                                 << "Shader source code:\n"
2494                                                 << shader[i].source[0] << (shader[i].source[1] ? shader[i].source[1] : "")
2495                                                 << (shader[i].source[2] ? shader[i].source[2] : "") << "\n"
2496                                                 << tcu::TestLog::EndMessage;
2497
2498                                         delete[] log_text;
2499
2500                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog call failed.");
2501
2502                                         throw 0;
2503                                 }
2504                         }
2505                 }
2506
2507                 /* Link. */
2508                 gl.linkProgram(m_po);
2509
2510                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTransformFeedbackVaryings call failed.");
2511
2512                 glw::GLint status = GL_FALSE;
2513
2514                 gl.getProgramiv(m_po, GL_LINK_STATUS, &status);
2515
2516                 if (GL_TRUE == status)
2517                 {
2518                         for (glw::GLuint i = 0; i < shader_count; ++i)
2519                         {
2520                                 if (shader[i].id)
2521                                 {
2522                                         gl.detachShader(m_po, shader[i].id);
2523
2524                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glDetachShader call failed.");
2525                                 }
2526                         }
2527                 }
2528                 else
2529                 {
2530                         glw::GLint log_size = 0;
2531
2532                         gl.getProgramiv(m_po, GL_INFO_LOG_LENGTH, &log_size);
2533
2534                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv call failed.");
2535
2536                         glw::GLchar* log_text = new glw::GLchar[log_size];
2537
2538                         gl.getProgramInfoLog(m_po, log_size, NULL, &log_text[0]);
2539
2540                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "Program linkage has failed due to:\n"
2541                                                                                                 << log_text << "\n"
2542                                                                                                 << tcu::TestLog::EndMessage;
2543
2544                         delete[] log_text;
2545
2546                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramInfoLog call failed.");
2547
2548                         throw 0;
2549                 }
2550         }
2551         catch (...)
2552         {
2553                 if (m_po)
2554                 {
2555                         gl.deleteProgram(m_po);
2556
2557                         m_po = 0;
2558                 }
2559         }
2560
2561         for (glw::GLuint i = 0; i < shader_count; ++i)
2562         {
2563                 if (0 != shader[i].id)
2564                 {
2565                         gl.deleteShader(shader[i].id);
2566
2567                         shader[i].id = 0;
2568                 }
2569         }
2570
2571         if (0 == m_po)
2572         {
2573                 throw 0;
2574         }
2575 }
2576
2577 /** @brief Prepare VAO.
2578  */
2579 void StorageAndSubImageTest::PrepareVertexArray()
2580 {
2581         /* Shortcut for GL functionality. */
2582         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2583
2584         gl.genVertexArrays(1, &m_vao);
2585         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays has failed");
2586
2587         gl.bindVertexArray(m_vao);
2588         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray has failed");
2589 }
2590
2591 /** @brief Test's draw call.
2592  */
2593 void StorageAndSubImageTest::Draw()
2594 {
2595         /* Shortcut for GL functionality. */
2596         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2597
2598         gl.useProgram(m_po);
2599         GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed");
2600
2601         gl.activeTexture(GL_TEXTURE0);
2602         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
2603
2604         gl.bindTextureUnit(0, m_to);
2605         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
2606
2607         gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
2608         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed");
2609 }
2610
2611 /** @brief Clean GL objects, test variables and GL errors.
2612  */
2613 void StorageAndSubImageTest::CleanTexture()
2614 {
2615         /* Shortcut for GL functionality. */
2616         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2617
2618         /* Texture. */
2619         if (m_to)
2620         {
2621                 gl.deleteTextures(1, &m_to);
2622
2623                 m_to = 0;
2624         }
2625 }
2626
2627 /** @brief Clean GL objects, test variables and GL errors.
2628  */
2629 void StorageAndSubImageTest::CleanFramebuffer()
2630 {
2631         /* Shortcut for GL functionality. */
2632         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2633
2634         /* Framebuffer. */
2635         if (m_fbo)
2636         {
2637                 gl.deleteFramebuffers(1, &m_fbo);
2638
2639                 m_fbo = 0;
2640         }
2641
2642         /* Renderbuffer. */
2643         if (m_rbo)
2644         {
2645                 gl.deleteRenderbuffers(1, &m_rbo);
2646
2647                 m_rbo = 0;
2648         }
2649 }
2650
2651 /** @brief Clean GL objects, test variables and GL errors.
2652  */
2653 void StorageAndSubImageTest::CleanProgram()
2654 {
2655         /* Shortcut for GL functionality. */
2656         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2657
2658         /* Program. */
2659         if (m_po)
2660         {
2661                 gl.useProgram(0);
2662
2663                 gl.deleteProgram(m_po);
2664
2665                 m_po = 0;
2666         }
2667 }
2668
2669 /** @brief Clean GL objects, test variables and GL errors.
2670  */
2671 void StorageAndSubImageTest::CleanErrors()
2672 {
2673         /* Shortcut for GL functionality. */
2674         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2675
2676         /* Query all errors until GL_NO_ERROR occure. */
2677         while (GL_NO_ERROR != gl.getError())
2678                 ;
2679 }
2680
2681 /** @brief Clean GL objects, test variables and GL errors.
2682  */
2683 void StorageAndSubImageTest::CleanVertexArray()
2684 {
2685         /* Shortcut for GL functionality. */
2686         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2687
2688         if (m_vao)
2689         {
2690                 gl.bindVertexArray(0);
2691
2692                 gl.deleteVertexArrays(1, &m_vao);
2693
2694                 m_vao = 0;
2695         }
2696 }
2697
2698 /** @brief Iterate Storage Test cases.
2699  *
2700  *  @return Iteration result.
2701  */
2702 tcu::TestNode::IterateResult StorageAndSubImageTest::iterate()
2703 {
2704         /* Shortcut for GL functionality. */
2705         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2706
2707         /* Get context setup. */
2708         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
2709         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
2710
2711         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
2712         {
2713                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
2714
2715                 return STOP;
2716         }
2717
2718         /* Running tests. */
2719         bool is_ok      = true;
2720         bool is_error = false;
2721
2722         try
2723         {
2724                 PrepareVertexArray();
2725
2726                 /* Test TextureStorage* */
2727                 is_ok &= LoopTestOverDOverS<glw::GLbyte, false, false>(true);
2728                 is_ok &= LoopTestOverDOverS<glw::GLubyte, false, false>(true);
2729                 is_ok &= LoopTestOverDOverS<glw::GLshort, false, false>(true);
2730                 is_ok &= LoopTestOverDOverS<glw::GLushort, false, false>(true);
2731                 is_ok &= LoopTestOverDOverS<glw::GLint, false, false>(false);
2732                 is_ok &= LoopTestOverDOverS<glw::GLuint, false, false>(false);
2733                 is_ok &= LoopTestOverDOverS<glw::GLubyte, true, false>(true);
2734                 is_ok &= LoopTestOverDOverS<glw::GLushort, true, false>(true);
2735                 is_ok &= LoopTestOverDOverS<glw::GLfloat, true, false>(false);
2736
2737                 /* Test TextureSubImage* */
2738                 is_ok &= LoopTestOverDOverS<glw::GLbyte, false, true>(true);
2739                 is_ok &= LoopTestOverDOverS<glw::GLubyte, false, true>(true);
2740                 is_ok &= LoopTestOverDOverS<glw::GLshort, false, true>(true);
2741                 is_ok &= LoopTestOverDOverS<glw::GLushort, false, true>(true);
2742                 is_ok &= LoopTestOverDOverS<glw::GLint, false, true>(false);
2743                 is_ok &= LoopTestOverDOverS<glw::GLuint, false, true>(false);
2744                 is_ok &= LoopTestOverDOverS<glw::GLubyte, true, true>(true);
2745                 is_ok &= LoopTestOverDOverS<glw::GLushort, true, true>(true);
2746                 is_ok &= LoopTestOverDOverS<glw::GLfloat, true, true>(false);
2747         }
2748         catch (...)
2749         {
2750                 is_ok   = false;
2751                 is_error = true;
2752         }
2753
2754         /* Cleanup. */
2755         CleanTexture();
2756         CleanFramebuffer();
2757         CleanProgram();
2758         CleanErrors();
2759         CleanVertexArray();
2760
2761         /* Errors clean up. */
2762         while (gl.getError())
2763                 ;
2764
2765         /* Result's setup. */
2766         if (is_ok)
2767         {
2768                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
2769         }
2770         else
2771         {
2772                 if (is_error)
2773                 {
2774                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
2775                 }
2776                 else
2777                 {
2778                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
2779                 }
2780         }
2781
2782         return STOP;
2783 }
2784
2785 /* Vertex shader source code. */
2786 const glw::GLchar* StorageAndSubImageTest::s_vertex_shader = "#version 450\n"
2787                                                                                                                          "\n"
2788                                                                                                                          "void main()\n"
2789                                                                                                                          "{\n"
2790                                                                                                                          "    switch(gl_VertexID)\n"
2791                                                                                                                          "    {\n"
2792                                                                                                                          "        case 0:\n"
2793                                                                                                                          "            gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
2794                                                                                                                          "            break;\n"
2795                                                                                                                          "        case 1:\n"
2796                                                                                                                          "            gl_Position = vec4( 1.0, 1.0, 0.0, 1.0);\n"
2797                                                                                                                          "            break;\n"
2798                                                                                                                          "        case 2:\n"
2799                                                                                                                          "            gl_Position = vec4(-1.0,-1.0, 0.0, 1.0);\n"
2800                                                                                                                          "            break;\n"
2801                                                                                                                          "        case 3:\n"
2802                                                                                                                          "            gl_Position = vec4( 1.0,-1.0, 0.0, 1.0);\n"
2803                                                                                                                          "            break;\n"
2804                                                                                                                          "    }\n"
2805                                                                                                                          "}\n";
2806
2807 /* Fragment shader source program. */
2808 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_head =
2809         "#version 450\n"
2810         "\n"
2811         "layout(pixel_center_integer) in vec4 gl_FragCoord;\n"
2812         "\n";
2813
2814 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_1D_fdecl_lowp =
2815         "uniform  sampler1D texture_input;\nout     vec4          texture_output;\n";
2816 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_1D_idecl_lowp =
2817         "uniform isampler1D texture_input;\nout     ivec4         texture_output;\n";
2818 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_1D_udecl_lowp =
2819         "uniform usampler1D texture_input;\nout     uvec4         texture_output;\n";
2820 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_1D_fdecl_mediump =
2821         "uniform  sampler1D texture_input;\nout     vec4          texture_output;\n";
2822 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_1D_idecl_mediump =
2823         "uniform isampler1D texture_input;\nout     ivec4         texture_output;\n";
2824 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_1D_udecl_mediump =
2825         "uniform usampler1D texture_input;\nout     uvec4         texture_output;\n";
2826 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_1D_fdecl_highp =
2827         "uniform  sampler1D texture_input;\nout     vec4          texture_output;\n";
2828 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_1D_idecl_highp =
2829         "uniform isampler1D texture_input;\nout     ivec4         texture_output;\n";
2830 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_1D_udecl_highp =
2831         "uniform usampler1D texture_input;\nout     uvec4         texture_output;\n";
2832
2833 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_2D_fdecl_lowp =
2834         "uniform  sampler2D texture_input;\nout     vec4          texture_output;\n";
2835 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_2D_idecl_lowp =
2836         "uniform isampler2D texture_input;\nout     ivec4         texture_output;\n";
2837 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_2D_udecl_lowp =
2838         "uniform usampler2D texture_input;\nout     uvec4         texture_output;\n";
2839 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_2D_fdecl_mediump =
2840         "uniform  sampler2D texture_input;\nout     vec4          texture_output;\n";
2841 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_2D_idecl_mediump =
2842         "uniform isampler2D texture_input;\nout     ivec4         texture_output;\n";
2843 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_2D_udecl_mediump =
2844         "uniform usampler2D texture_input;\nout     uvec4         texture_output;\n";
2845 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_2D_fdecl_highp =
2846         "uniform  sampler2D texture_input;\nout     vec4          texture_output;\n";
2847 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_2D_idecl_highp =
2848         "uniform isampler2D texture_input;\nout     ivec4         texture_output;\n";
2849 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_2D_udecl_highp =
2850         "uniform usampler2D texture_input;\nout     uvec4         texture_output;\n";
2851
2852 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_3D_fdecl_lowp =
2853         "uniform  sampler3D texture_input;\nout     vec4          texture_output;\n";
2854 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_3D_idecl_lowp =
2855         "uniform isampler3D texture_input;\nout     ivec4         texture_output;\n";
2856 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_3D_udecl_lowp =
2857         "uniform usampler3D texture_input;\nout     uvec4         texture_output;\n";
2858 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_3D_fdecl_mediump =
2859         "uniform  sampler3D texture_input;\nout     vec4          texture_output;\n";
2860 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_3D_idecl_mediump =
2861         "uniform isampler3D texture_input;\nout     ivec4         texture_output;\n";
2862 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_3D_udecl_mediump =
2863         "uniform usampler3D texture_input;\nout     uvec4         texture_output;\n";
2864 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_3D_fdecl_highp =
2865         "uniform  sampler3D texture_input;\nout     vec4          texture_output;\n";
2866 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_3D_idecl_highp =
2867         "uniform isampler3D texture_input;\nout     ivec4         texture_output;\n";
2868 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_3D_udecl_highp =
2869         "uniform usampler3D texture_input;\nout     uvec4         texture_output;\n";
2870
2871 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_1D_tail =
2872         "\n"
2873         "void main()\n"
2874         "{\n"
2875         "    texture_output = texelFetch(texture_input, int(gl_FragCoord.x), 0);\n"
2876         "}\n";
2877
2878 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_2D_tail =
2879         "\n"
2880         "void main()\n"
2881         "{\n"
2882         "    texture_output = texelFetch(texture_input, ivec2(int(gl_FragCoord.x) % 2, int(floor(gl_FragCoord.x / 2))), "
2883         "0);\n"
2884         "}\n";
2885
2886 const glw::GLchar* StorageAndSubImageTest::s_fragment_shader_3D_tail =
2887         "\n"
2888         "void main()\n"
2889         "{\n"
2890         "    texture_output = texelFetch(texture_input, ivec3(int(gl_FragCoord.x) % 2, int(floor(gl_FragCoord.x / 2)) % 3, "
2891         "int(floor(gl_FragCoord.x / 2 / 3))), 0);\n"
2892         "}\n";
2893
2894 /******************************** Storage Multisample Test Implementation   ********************************/
2895
2896 /** @brief Storage Multisample Test constructor.
2897  *
2898  *  @param [in] context     OpenGL context.
2899  */
2900 StorageMultisampleTest::StorageMultisampleTest(deqp::Context& context)
2901         : deqp::TestCase(context, "textures_storage_multisample", "Texture Storage Multisample Test")
2902         , m_fbo_ms(0)
2903         , m_fbo_aux(0)
2904         , m_to_ms(0)
2905         , m_po_ms(0)
2906         , m_po_aux(0)
2907         , m_to(0)
2908         , m_to_aux(0)
2909         , m_vao(0)
2910 {
2911         /* Intentionally left blank. */
2912 }
2913
2914 /** @brief Count of reference data to be teted.
2915  *
2916  *  @tparam S      Size (# of components).
2917  *  @tparam D      Texture dimenisons.
2918  *
2919  *  @return Count.
2920  */
2921 template <glw::GLint S, glw::GLuint D>
2922 glw::GLuint StorageMultisampleTest::TestReferenceDataCount()
2923 {
2924         return 2 /* 1D */ * ((D > 1) ? 3 : 1) /* 2D */ * ((D > 2) ? 4 : 1) /* 3D */ * S /* components */;
2925 }
2926
2927 /** @brief Size of reference data to be teted.
2928  *
2929  *  @tparam T      Type.
2930  *  @tparam S      Size (# of components).
2931  *  @tparam D      Texture dimenisons.
2932  *
2933  *  @return Size.
2934  */
2935 template <typename T, glw::GLint S, glw::GLuint D>
2936 glw::GLuint StorageMultisampleTest::TestReferenceDataSize()
2937 {
2938         return TestReferenceDataCount<S, D>() * sizeof(T);
2939 }
2940
2941 /** @brief Height, width or depth of reference data to be teted.
2942  *
2943  *  @tparam D      Texture dimenisons.
2944  *
2945  *  @return Height, width or depth.
2946  */
2947 template <>
2948 glw::GLuint StorageMultisampleTest::TestReferenceDataHeight<2>()
2949 {
2950         return 3;
2951 }
2952
2953 template <>
2954 glw::GLuint StorageMultisampleTest::TestReferenceDataHeight<3>()
2955 {
2956         return TestReferenceDataHeight<2>();
2957 }
2958
2959 template <>
2960 glw::GLuint StorageMultisampleTest::TestReferenceDataDepth<2>()
2961 {
2962         return 1;
2963 }
2964
2965 template <>
2966 glw::GLuint StorageMultisampleTest::TestReferenceDataDepth<3>()
2967 {
2968         return 4;
2969 }
2970
2971 template <glw::GLuint D>
2972 glw::GLuint                       StorageMultisampleTest::TestReferenceDataWidth()
2973 {
2974         return 2;
2975 }
2976
2977 /** @brief Fragment shader declaration selector.
2978  *
2979  *  @tparam T      Type.
2980  *  @tparam N      Normalized flag.
2981  *  @tparam D      Texture dimenisons.
2982  *
2983  *  @return Frgment shader source code part.
2984  */
2985 template <>
2986 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLubyte, true, 2>()
2987 {
2988         return s_fragment_shader_ms_2D_fdecl_lowp;
2989 }
2990
2991 template <>
2992 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLbyte, false, 2>()
2993 {
2994         return s_fragment_shader_ms_2D_idecl_lowp;
2995 }
2996
2997 template <>
2998 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLubyte, false, 2>()
2999 {
3000         return s_fragment_shader_ms_2D_udecl_lowp;
3001 }
3002
3003 template <>
3004 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLushort, true, 2>()
3005 {
3006         return s_fragment_shader_ms_2D_fdecl_mediump;
3007 }
3008
3009 template <>
3010 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLshort, false, 2>()
3011 {
3012         return s_fragment_shader_ms_2D_idecl_mediump;
3013 }
3014
3015 template <>
3016 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLushort, false, 2>()
3017 {
3018         return s_fragment_shader_ms_2D_udecl_mediump;
3019 }
3020
3021 template <>
3022 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLfloat, true, 2>()
3023 {
3024         return s_fragment_shader_ms_2D_fdecl_highp;
3025 }
3026
3027 template <>
3028 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLint, false, 2>()
3029 {
3030         return s_fragment_shader_ms_2D_idecl_highp;
3031 }
3032
3033 template <>
3034 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLuint, false, 2>()
3035 {
3036         return s_fragment_shader_ms_2D_udecl_highp;
3037 }
3038
3039 /** @brief Fragment shader declaration selector.
3040  *
3041  *  @tparam T      Type.
3042  *  @tparam N      Normalized flag.
3043  *  @tparam D      Texture dimenisons.
3044  *
3045  *  @return Frgment shader source code part.
3046  */
3047 template <>
3048 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLubyte, true, 3>()
3049 {
3050         return s_fragment_shader_ms_3D_fdecl_lowp;
3051 }
3052
3053 template <>
3054 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLbyte, false, 3>()
3055 {
3056         return s_fragment_shader_ms_3D_idecl_lowp;
3057 }
3058
3059 template <>
3060 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLubyte, false, 3>()
3061 {
3062         return s_fragment_shader_ms_3D_udecl_lowp;
3063 }
3064
3065 template <>
3066 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLushort, true, 3>()
3067 {
3068         return s_fragment_shader_ms_3D_fdecl_mediump;
3069 }
3070
3071 template <>
3072 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLshort, false, 3>()
3073 {
3074         return s_fragment_shader_ms_3D_idecl_mediump;
3075 }
3076
3077 template <>
3078 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLushort, false, 3>()
3079 {
3080         return s_fragment_shader_ms_3D_udecl_mediump;
3081 }
3082
3083 template <>
3084 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLfloat, true, 3>()
3085 {
3086         return s_fragment_shader_ms_3D_fdecl_highp;
3087 }
3088
3089 template <>
3090 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLint, false, 3>()
3091 {
3092         return s_fragment_shader_ms_3D_idecl_highp;
3093 }
3094
3095 template <>
3096 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationMultisample<glw::GLuint, false, 3>()
3097 {
3098         return s_fragment_shader_ms_3D_udecl_highp;
3099 }
3100
3101 /** @brief Fragment shader declaration selector.
3102  *
3103  *  @tparam T      Type.
3104  *  @tparam N      Normalized flag.
3105  *  @tparam D      Texture dimenisons.
3106  *
3107  *  @return Frgment shader source code part.
3108  */
3109 template <>
3110 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLubyte, true, 2>()
3111 {
3112         return s_fragment_shader_aux_2D_fdecl_lowp;
3113 }
3114
3115 template <>
3116 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLbyte, false, 2>()
3117 {
3118         return s_fragment_shader_aux_2D_idecl_lowp;
3119 }
3120
3121 template <>
3122 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLubyte, false, 2>()
3123 {
3124         return s_fragment_shader_aux_2D_udecl_lowp;
3125 }
3126
3127 template <>
3128 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLushort, true, 2>()
3129 {
3130         return s_fragment_shader_aux_2D_fdecl_mediump;
3131 }
3132
3133 template <>
3134 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLshort, false, 2>()
3135 {
3136         return s_fragment_shader_aux_2D_idecl_mediump;
3137 }
3138
3139 template <>
3140 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLushort, false, 2>()
3141 {
3142         return s_fragment_shader_aux_2D_udecl_mediump;
3143 }
3144
3145 template <>
3146 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLfloat, true, 2>()
3147 {
3148         return s_fragment_shader_aux_2D_fdecl_highp;
3149 }
3150
3151 template <>
3152 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLint, false, 2>()
3153 {
3154         return s_fragment_shader_aux_2D_idecl_highp;
3155 }
3156
3157 template <>
3158 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLuint, false, 2>()
3159 {
3160         return s_fragment_shader_aux_2D_udecl_highp;
3161 }
3162
3163 /** @brief Fragment shader declaration selector.
3164  *
3165  *  @tparam T      Type.
3166  *  @tparam N      Normalized flag.
3167  *  @tparam D      Texture dimenisons.
3168  *
3169  *  @return Frgment shader source code part.
3170  */
3171 template <>
3172 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLubyte, true, 3>()
3173 {
3174         return s_fragment_shader_aux_3D_fdecl_lowp;
3175 }
3176
3177 template <>
3178 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLbyte, false, 3>()
3179 {
3180         return s_fragment_shader_aux_3D_idecl_lowp;
3181 }
3182
3183 template <>
3184 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLubyte, false, 3>()
3185 {
3186         return s_fragment_shader_aux_3D_udecl_lowp;
3187 }
3188
3189 template <>
3190 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLushort, true, 3>()
3191 {
3192         return s_fragment_shader_aux_3D_fdecl_mediump;
3193 }
3194
3195 template <>
3196 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLshort, false, 3>()
3197 {
3198         return s_fragment_shader_aux_3D_idecl_mediump;
3199 }
3200
3201 template <>
3202 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLushort, false, 3>()
3203 {
3204         return s_fragment_shader_aux_3D_udecl_mediump;
3205 }
3206
3207 template <>
3208 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLfloat, true, 3>()
3209 {
3210         return s_fragment_shader_aux_3D_fdecl_highp;
3211 }
3212
3213 template <>
3214 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLint, false, 3>()
3215 {
3216         return s_fragment_shader_aux_3D_idecl_highp;
3217 }
3218
3219 template <>
3220 const glw::GLchar* StorageMultisampleTest::FragmentShaderDeclarationAuxiliary<glw::GLuint, false, 3>()
3221 {
3222         return s_fragment_shader_aux_3D_udecl_highp;
3223 }
3224
3225 /** @brief Fragment shader tail selector.
3226  *
3227  *  @tparam D      Texture dimenisons.
3228  *
3229  *  @return Frgment shader source code part.
3230  */
3231 template <>
3232 const glw::GLchar* StorageMultisampleTest::FragmentShaderTail<2>()
3233 {
3234         return s_fragment_shader_tail_2D;
3235 }
3236
3237 template <>
3238 const glw::GLchar* StorageMultisampleTest::FragmentShaderTail<3>()
3239 {
3240         return s_fragment_shader_tail_3D;
3241 }
3242
3243 /** @brief Texture target selector.
3244  *
3245  *  @tparam D      Texture dimenisons.
3246  *
3247  *  @return Texture target.
3248  */
3249 template <>
3250 glw::GLenum StorageMultisampleTest::InputTextureTarget<2>()
3251 {
3252         return GL_TEXTURE_2D;
3253 }
3254
3255 template <>
3256 glw::GLenum StorageMultisampleTest::InputTextureTarget<3>()
3257 {
3258         return GL_TEXTURE_2D_ARRAY;
3259 }
3260
3261 /** @brief Prepare texture data for input texture.
3262  *
3263  *  @tparam D      Texture dimenisons.
3264  *
3265  *  @note parameters as passed to texImage*
3266  */
3267 template <>
3268 void StorageMultisampleTest::InputTextureImage<2>(const glw::GLenum internal_format, const glw::GLuint width,
3269                                                                                                   const glw::GLuint height, const glw::GLuint depth,
3270                                                                                                   const glw::GLenum format, const glw::GLenum type,
3271                                                                                                   const glw::GLvoid* data)
3272 {
3273         (void)depth;
3274         /* Shortcut for GL functionality. */
3275         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3276
3277         /* Data setup. */
3278         gl.texImage2D(InputTextureTarget<2>(), 0, internal_format, width, height, 0, format, type, data);
3279         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
3280 }
3281
3282 /** @brief Prepare texture data for input texture.
3283  *
3284  *  @tparam D      Texture dimenisons.
3285  *
3286  *  @note parameters as passed to texImage*
3287  */
3288 template <>
3289 void StorageMultisampleTest::InputTextureImage<3>(const glw::GLenum internal_format, const glw::GLuint width,
3290                                                                                                   const glw::GLuint height, const glw::GLuint depth,
3291                                                                                                   const glw::GLenum format, const glw::GLenum type,
3292                                                                                                   const glw::GLvoid* data)
3293 {
3294         /* Shortcut for GL functionality. */
3295         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3296
3297         /* Data setup. */
3298         gl.texImage3D(InputTextureTarget<3>(), 0, internal_format, width, height, depth, 0, format, type, data);
3299         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
3300 }
3301
3302 /** @brief Create texture.
3303  *
3304  *  @tparam T      Type.
3305  *  @tparam S      Size (# of components).
3306  *  @tparam N      Is normalized.
3307  *  @tparam D      Dimmensions.
3308  */
3309 template <typename T, glw::GLint S, bool N, glw::GLuint D>
3310 void StorageMultisampleTest::CreateInputTexture()
3311 {
3312         /* Shortcut for GL functionality. */
3313         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3314
3315         /* Objects creation. */
3316         gl.genTextures(1, &m_to);
3317         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
3318
3319         gl.bindTexture(InputTextureTarget<D>(), m_to);
3320         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
3321
3322         /* Data setup. */
3323         InputTextureImage<D>(InternalFormat<T, S, N>(), TestReferenceDataWidth<D>(), TestReferenceDataHeight<D>(),
3324                                                  TestReferenceDataDepth<D>(), Format<S, N>(), Type<T>(), ReferenceData<T, N>());
3325
3326         /* Parameter setup. */
3327         gl.texParameteri(InputTextureTarget<D>(), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3328         gl.texParameteri(InputTextureTarget<D>(), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3329         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
3330 }
3331
3332 /** @brief Compre results with the reference.
3333  *
3334  *  @tparam T      Type.
3335  *  @tparam S      Size (# of components).
3336  *  @tparam N      Is normalized.
3337  *
3338  *  @return True if equal, false otherwise.
3339  */
3340 template <typename T, glw::GLint S, bool N, glw::GLuint D>
3341 bool StorageMultisampleTest::Check()
3342 {
3343         /* Shortcut for GL functionality. */
3344         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3345
3346         /* Fetching data fro auxiliary texture. */
3347         std::vector<T> result(TestReferenceDataCount<S, D>());
3348
3349         gl.bindTexture(InputTextureTarget<D>() /* Auxiliary target is the same as input. */, m_to_aux);
3350         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
3351
3352         gl.getTexImage(InputTextureTarget<D>() /* Auxiliary target is the same as input. */, 0, Format<S, N>(), Type<T>(),
3353                                    (glw::GLvoid*)(&result[0]));
3354         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexImage has failed");
3355
3356         /* Comparison. */
3357         for (glw::GLuint i = 0; i < TestReferenceDataCount<S, D>(); ++i)
3358         {
3359                 if (!Compare<T>(result[i], ReferenceData<T, N>()[i]))
3360                 {
3361                         return false;
3362                 }
3363         }
3364
3365         return true;
3366 }
3367
3368 /** @brief Test case function.
3369  *
3370  *  @tparam T       Type.
3371  *  @tparam S       Size (# of components).
3372  *  @tparam N       Is normalized.
3373  *  @tparam D       Number of texture dimensions.
3374  *
3375  *  @return True if test succeeded, false otherwise.
3376  */
3377 template <typename T, glw::GLint S, bool N, glw::GLuint D>
3378 bool StorageMultisampleTest::Test()
3379 {
3380         /* Shortcut for GL functionality. */
3381         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3382
3383         /* Setup. */
3384         gl.pixelStorei(GL_UNPACK_ALIGNMENT, sizeof(T));
3385         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
3386
3387         gl.pixelStorei(GL_PACK_ALIGNMENT, sizeof(T));
3388         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
3389
3390         CreateInputTexture<T, S, N, D>();
3391
3392         if (!PrepareFramebufferMultisample<D>(InternalFormat<T, S, N>()))
3393         {
3394                 CleanInputTexture();
3395
3396                 return false;
3397         }
3398
3399         PrepareFramebufferAuxiliary<D>(InternalFormat<T, S, N>());
3400
3401         /* Action. */
3402         Draw<D>();
3403
3404         /* Compare results with reference. */
3405         bool result = Check<T, S, N, D>();
3406
3407         /* Cleanup. */
3408         CleanAuxiliaryTexture();
3409         CleanFramebuffers();
3410         CleanInputTexture();
3411         CleanErrors();
3412
3413         /* Pass result. */
3414         return result;
3415 }
3416
3417 /** @brief Lopp test function over S.
3418  *
3419  *  @tparam T      Type.
3420  *  @tparam N      Is normalized.
3421  *  @tparam D      Texture dimension.
3422  *
3423  *  @param [in] skip_rgb            Skip test of S = 3 (needed for some formats).
3424  *
3425  *  @return True if tests succeeded, false otherwise.
3426  */
3427 template <typename T, bool N, glw::GLuint D>
3428 bool StorageMultisampleTest::LoopTestOverS(bool skip_rgb)
3429 {
3430         /* Prepare one program to create multisample texture and one to copy it to regular texture. */
3431         m_po_ms  = PrepareProgram(FragmentShaderDeclarationMultisample<T, N, D>(), FragmentShaderTail<D>());
3432         m_po_aux = PrepareProgram(FragmentShaderDeclarationAuxiliary<T, N, D>(), FragmentShaderTail<D>());
3433
3434         /* Run tests. */
3435         bool result = true;
3436
3437         result &= Test<T, 1, N, D>();
3438
3439         result &= Test<T, 2, N, D>();
3440
3441         if (!skip_rgb)
3442         {
3443                 result &= Test<T, 3, N, D>();
3444         }
3445
3446         result &= Test<T, 4, N, D>();
3447
3448         /* Cleanup.*/
3449         CleanPrograms();
3450         CleanErrors();
3451
3452         /* Pass result. */
3453         return result;
3454 }
3455
3456 /** @brief Lopp test function over D and next over S.
3457  *
3458  *  @tparam T      Type.
3459  *  @tparam N      Is normalized.
3460  *
3461  *  @param [in] skip_rgb            Skip test of S = 3 (needed for some formats).
3462  *
3463  *  @return True if tests succeeded, false otherwise.
3464  */
3465 template <typename T, bool N>
3466 bool StorageMultisampleTest::LoopTestOverDOverS(bool skip_rgb)
3467 {
3468         bool result = true;
3469
3470         result &= LoopTestOverS<T, N, 2>(skip_rgb);
3471         result &= LoopTestOverS<T, N, 3>(skip_rgb);
3472
3473         return result;
3474 }
3475
3476 /** @brief Function prepares framebuffer with internal format color attachment.
3477  *         Viewport is set up. Content of the framebuffer is cleared.
3478  *
3479  *  @note The function may throw if unexpected error has occured.
3480  */
3481 template <>
3482 bool StorageMultisampleTest::PrepareFramebufferMultisample<2>(const glw::GLenum internal_format)
3483 {
3484         /* Shortcut for GL functionality. */
3485         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3486
3487         /* Prepare framebuffer. */
3488         gl.genFramebuffers(1, &m_fbo_ms);
3489         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
3490
3491         gl.genTextures(1, &m_to_ms);
3492         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
3493
3494         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
3495         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
3496
3497         gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_to_ms);
3498         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
3499
3500         gl.textureStorage2DMultisample(m_to_ms, 1, internal_format, TestReferenceDataWidth<2>(),
3501                                                                    TestReferenceDataHeight<2>(), false);
3502
3503         glw::GLenum error;
3504
3505         if (GL_NO_ERROR != (error = gl.getError()))
3506         {
3507                 CleanFramebuffers();
3508
3509                 m_context.getTestContext().getLog()
3510                         << tcu::TestLog::Message << "glTextureStorage2DMultisample unexpectedly generated error "
3511                         << glu::getErrorStr(error) << " during the test of internal format "
3512                         << glu::getTextureFormatStr(internal_format) << ". Test fails." << tcu::TestLog::EndMessage;
3513
3514                 return false;
3515         }
3516
3517         gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, m_to_ms, 0);
3518         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
3519
3520         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
3521         {
3522                 throw 0;
3523         }
3524
3525         gl.viewport(0, 0, TestReferenceDataWidth<2>(), TestReferenceDataHeight<2>());
3526         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
3527
3528         /* Clear framebuffer's content. */
3529         gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
3530         GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
3531
3532         gl.clear(GL_COLOR_BUFFER_BIT);
3533         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
3534
3535         return true;
3536 }
3537
3538 /** @brief Function prepares framebuffer with internal format color attachment.
3539  *         Viewport is set up. Content of the framebuffer is cleared.
3540  *
3541  *  @note The function may throw if unexpected error has occured.
3542  */
3543 template <>
3544 bool StorageMultisampleTest::PrepareFramebufferMultisample<3>(const glw::GLenum internal_format)
3545 {
3546         /* Shortcut for GL functionality. */
3547         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3548
3549         /* Prepare framebuffer. */
3550         gl.genFramebuffers(1, &m_fbo_ms);
3551         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
3552
3553         gl.genTextures(1, &m_to_ms);
3554         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
3555
3556         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
3557         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
3558
3559         gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, m_to_ms);
3560         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
3561
3562         gl.textureStorage3DMultisample(m_to_ms, 1, internal_format, TestReferenceDataWidth<3>(),
3563                                                                    TestReferenceDataHeight<3>(), TestReferenceDataDepth<3>(), false);
3564
3565         glw::GLenum error;
3566
3567         if (GL_NO_ERROR != (error = gl.getError()))
3568         {
3569                 CleanFramebuffers();
3570
3571                 m_context.getTestContext().getLog()
3572                         << tcu::TestLog::Message << "glTextureStorage3DMultisample unexpectedly generated error "
3573                         << glu::getErrorStr(error) << " during the test of internal format "
3574                         << glu::getTextureFormatStr(internal_format) << ". Test fails." << tcu::TestLog::EndMessage;
3575
3576                 return false;
3577         }
3578
3579         for (glw::GLuint i = 0; i < TestReferenceDataDepth<3>(); ++i)
3580         {
3581                 gl.framebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, m_to_ms, 0, i);
3582                 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
3583         }
3584
3585         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
3586         {
3587                 throw 0;
3588         }
3589
3590         gl.viewport(0, 0, TestReferenceDataWidth<3>(), TestReferenceDataHeight<3>());
3591         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
3592
3593         /* Clear framebuffer's content. */
3594         gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
3595         GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
3596
3597         gl.clear(GL_COLOR_BUFFER_BIT);
3598         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
3599
3600         return true;
3601 }
3602
3603 /** @brief Function prepares framebuffer with internal format color attachment.
3604  *         Viewport is set up. Content of the framebuffer is cleared.
3605  *
3606  *  @note The function may throw if unexpected error has occured.
3607  */
3608 template <>
3609 void StorageMultisampleTest::PrepareFramebufferAuxiliary<2>(const glw::GLenum internal_format)
3610 {
3611         /* Shortcut for GL functionality. */
3612         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3613
3614         /* Prepare framebuffer. */
3615         gl.genFramebuffers(1, &m_fbo_aux);
3616         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
3617
3618         gl.genTextures(1, &m_to_aux);
3619         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
3620
3621         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_aux);
3622         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
3623
3624         gl.bindTexture(GL_TEXTURE_2D, m_to_aux);
3625         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
3626
3627         gl.textureStorage2D(m_to_aux, 1, internal_format, TestReferenceDataWidth<2>(), TestReferenceDataHeight<2>());
3628         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2D call failed.");
3629
3630         /* Parameter setup. */
3631         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3632         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3633         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
3634
3635         gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_to_aux, 0);
3636         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
3637
3638         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
3639         {
3640                 throw 0;
3641         }
3642
3643         gl.viewport(0, 0, TestReferenceDataWidth<2>(), TestReferenceDataHeight<2>());
3644         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
3645
3646         /* Clear framebuffer's content. */
3647         gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
3648         GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
3649
3650         gl.clear(GL_COLOR_BUFFER_BIT);
3651         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
3652 }
3653
3654 /** @brief Function prepares framebuffer with internal format color attachment.
3655  *         Viewport is set up. Content of the framebuffer is cleared.
3656  *
3657  *  @note The function may throw if unexpected error has occured.
3658  */
3659 template <>
3660 void StorageMultisampleTest::PrepareFramebufferAuxiliary<3>(const glw::GLenum internal_format)
3661 {
3662         /* Shortcut for GL functionality. */
3663         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3664
3665         /* Prepare framebuffer. */
3666         gl.genFramebuffers(1, &m_fbo_aux);
3667         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
3668
3669         gl.genTextures(1, &m_to_aux);
3670         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
3671
3672         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_aux);
3673         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
3674
3675         gl.bindTexture(GL_TEXTURE_2D_ARRAY, m_to_aux);
3676         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
3677
3678         gl.textureStorage3D(m_to_aux, 1, internal_format, TestReferenceDataWidth<3>(), TestReferenceDataHeight<3>(),
3679                                                 TestReferenceDataDepth<3>());
3680         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage3D call failed.");
3681
3682         /* Parameter setup. */
3683         gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3684         gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3685         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
3686
3687         for (glw::GLuint i = 0; i < TestReferenceDataDepth<3>(); ++i)
3688         {
3689                 gl.framebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, m_to_aux, 0, i);
3690                 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
3691         }
3692
3693         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
3694         {
3695                 throw 0;
3696         }
3697
3698         gl.viewport(0, 0, TestReferenceDataWidth<3>(), TestReferenceDataHeight<3>());
3699         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
3700
3701         /* Clear framebuffer's content. */
3702         gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
3703         GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
3704
3705         gl.clear(GL_COLOR_BUFFER_BIT);
3706         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
3707 }
3708
3709 /** @brief Prepare program
3710  *
3711  *  @param [in] variable_declaration      Variables declaration part of fragment shader source code.
3712  *  @param [in] tail                      Tail part of fragment shader source code.
3713  */
3714 glw::GLuint StorageMultisampleTest::PrepareProgram(const glw::GLchar* variable_declaration, const glw::GLchar* tail)
3715 {
3716         /* Shortcut for GL functionality */
3717         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3718
3719         struct Shader
3720         {
3721                 glw::GLchar const* source[3];
3722                 glw::GLsizei const count;
3723                 glw::GLenum const  type;
3724                 glw::GLuint                id;
3725         } shader[] = { { { s_vertex_shader, NULL, NULL }, 1, GL_VERTEX_SHADER, 0 },
3726                                    { { s_fragment_shader_head, variable_declaration, tail }, 3, GL_FRAGMENT_SHADER, 0 } };
3727
3728         glw::GLuint const shader_count = sizeof(shader) / sizeof(shader[0]);
3729
3730         glw::GLuint po = 0;
3731
3732         try
3733         {
3734                 /* Create program. */
3735                 po = gl.createProgram();
3736                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateProgram call failed.");
3737
3738                 /* Shader compilation. */
3739
3740                 for (glw::GLuint i = 0; i < shader_count; ++i)
3741                 {
3742                         {
3743                                 shader[i].id = gl.createShader(shader[i].type);
3744
3745                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateShader call failed.");
3746
3747                                 gl.attachShader(po, shader[i].id);
3748
3749                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glAttachShader call failed.");
3750
3751                                 gl.shaderSource(shader[i].id, shader[i].count, shader[i].source, NULL);
3752
3753                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource call failed.");
3754
3755                                 gl.compileShader(shader[i].id);
3756
3757                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader call failed.");
3758
3759                                 glw::GLint status = GL_FALSE;
3760
3761                                 gl.getShaderiv(shader[i].id, GL_COMPILE_STATUS, &status);
3762                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
3763
3764                                 if (GL_FALSE == status)
3765                                 {
3766                                         glw::GLint log_size = 0;
3767                                         gl.getShaderiv(shader[i].id, GL_INFO_LOG_LENGTH, &log_size);
3768                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
3769
3770                                         glw::GLchar* log_text = new glw::GLchar[log_size];
3771
3772                                         gl.getShaderInfoLog(shader[i].id, log_size, NULL, &log_text[0]);
3773
3774                                         m_context.getTestContext().getLog()
3775                                                 << tcu::TestLog::Message << "Shader compilation has failed.\n"
3776                                                 << "Shader type: " << glu::getShaderTypeStr(shader[i].type) << "\n"
3777                                                 << "Shader compilation error log:\n"
3778                                                 << log_text << "\n"
3779                                                 << "Shader source code:\n"
3780                                                 << shader[i].source[0] << (shader[i].source[1] ? shader[i].source[1] : "")
3781                                                 << (shader[i].source[2] ? shader[i].source[2] : "") << "\n"
3782                                                 << tcu::TestLog::EndMessage;
3783
3784                                         delete[] log_text;
3785
3786                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog call failed.");
3787
3788                                         throw 0;
3789                                 }
3790                         }
3791                 }
3792
3793                 /* Link. */
3794                 gl.linkProgram(po);
3795
3796                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTransformFeedbackVaryings call failed.");
3797
3798                 glw::GLint status = GL_FALSE;
3799
3800                 gl.getProgramiv(po, GL_LINK_STATUS, &status);
3801
3802                 if (GL_TRUE == status)
3803                 {
3804                         for (glw::GLuint i = 0; i < shader_count; ++i)
3805                         {
3806                                 if (shader[i].id)
3807                                 {
3808                                         gl.detachShader(po, shader[i].id);
3809
3810                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glDetachShader call failed.");
3811                                 }
3812                         }
3813                 }
3814                 else
3815                 {
3816                         glw::GLint log_size = 0;
3817
3818                         gl.getProgramiv(po, GL_INFO_LOG_LENGTH, &log_size);
3819
3820                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv call failed.");
3821
3822                         glw::GLchar* log_text = new glw::GLchar[log_size];
3823
3824                         gl.getProgramInfoLog(po, log_size, NULL, &log_text[0]);
3825
3826                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "Program linkage has failed due to:\n"
3827                                                                                                 << log_text << "\n"
3828                                                                                                 << tcu::TestLog::EndMessage;
3829
3830                         delete[] log_text;
3831
3832                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramInfoLog call failed.");
3833
3834                         throw 0;
3835                 }
3836         }
3837         catch (...)
3838         {
3839                 if (po)
3840                 {
3841                         gl.deleteProgram(po);
3842
3843                         po = 0;
3844                 }
3845         }
3846
3847         for (glw::GLuint i = 0; i < shader_count; ++i)
3848         {
3849                 if (0 != shader[i].id)
3850                 {
3851                         gl.deleteShader(shader[i].id);
3852
3853                         shader[i].id = 0;
3854                 }
3855         }
3856
3857         if (0 == po)
3858         {
3859                 throw 0;
3860         }
3861
3862         return po;
3863 }
3864
3865 /** @brief Prepare VAO.
3866  */
3867 void StorageMultisampleTest::PrepareVertexArray()
3868 {
3869         /* Shortcut for GL functionality. */
3870         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3871
3872         gl.genVertexArrays(1, &m_vao);
3873         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays has failed");
3874
3875         gl.bindVertexArray(m_vao);
3876         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray has failed");
3877 }
3878
3879 /** @brief Draw call 2D.
3880  */
3881 template <>
3882 void StorageMultisampleTest::Draw<2>()
3883 {
3884         /* Shortcut for GL functionality. */
3885         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3886
3887         /* Prepare multisample texture using draw call. */
3888
3889         /* Prepare framebuffer with multisample texture. */
3890         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
3891         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer has failed");
3892
3893         /* Use first program program. */
3894         gl.useProgram(m_po_ms);
3895         GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed");
3896
3897         /* Prepare texture to be drawn with. */
3898         gl.activeTexture(GL_TEXTURE0);
3899         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
3900
3901         gl.bindTexture(GL_TEXTURE_2D, m_to);
3902         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
3903
3904         gl.uniform1i(gl.getUniformLocation(m_po_ms, "texture_input"), 0);
3905         GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed");
3906
3907         /* Select layer. */
3908         gl.drawBuffer(GL_COLOR_ATTACHMENT0);
3909         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawBuffer has failed");
3910
3911         /* Draw. */
3912         gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
3913         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed");
3914
3915         /* Copy multisample texture to auxiliary texture using draw call. */
3916
3917         /* Prepare framebuffer with auxiliary texture. */
3918         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_aux);
3919         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer has failed");
3920
3921         /* Use first program program. */
3922         gl.useProgram(m_po_aux);
3923         GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed");
3924
3925         /* Prepare texture to be drawn with. */
3926         gl.activeTexture(GL_TEXTURE0);
3927         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
3928
3929         gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_to_ms);
3930         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
3931
3932         gl.bindTextureUnit(0, m_to);
3933
3934         gl.uniform1i(gl.getUniformLocation(m_po_aux, "texture_input"), 0);
3935         GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed");
3936
3937         /* Select layer. */
3938         gl.drawBuffer(GL_COLOR_ATTACHMENT0);
3939         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawBuffer has failed");
3940
3941         /* Draw. */
3942         gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
3943         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed");
3944 }
3945
3946 /** @brief Draw call 3D.
3947  */
3948 template <>
3949 void StorageMultisampleTest::Draw<3>()
3950 {
3951         /* Shortcut for GL functionality. */
3952         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3953
3954         /* Prepare multisample texture using draw call. */
3955
3956         /* Prepare framebuffer with multisample texture. */
3957         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
3958         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer has failed");
3959
3960         /* Use first program program. */
3961         gl.useProgram(m_po_ms);
3962         GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed");
3963
3964         /* Prepare texture to be drawn with. */
3965         gl.activeTexture(GL_TEXTURE0);
3966         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
3967
3968         gl.bindTexture(GL_TEXTURE_2D_ARRAY, m_to);
3969         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
3970
3971         gl.uniform1i(gl.getUniformLocation(m_po_ms, "texture_input"), 0);
3972         GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed");
3973
3974         /* For each texture layer. */
3975         for (glw::GLuint i = 0; i < TestReferenceDataDepth<3>(); ++i)
3976         {
3977                 /* Select layer. */
3978                 gl.drawBuffer(GL_COLOR_ATTACHMENT0 + i);
3979                 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawBuffer has failed");
3980
3981                 gl.uniform1i(gl.getUniformLocation(m_po_aux, "texture_layer"), i);
3982                 GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed");
3983
3984                 /* Draw. */
3985                 gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
3986                 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed");
3987         }
3988
3989         /* Copy multisample texture to auxiliary texture using draw call. */
3990
3991         /* Prepare framebuffer with auxiliary texture. */
3992         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_aux);
3993         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer has failed");
3994
3995         /* Use first program program. */
3996         gl.useProgram(m_po_aux);
3997         GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed");
3998
3999         /* Prepare texture to be drawn with. */
4000         gl.activeTexture(GL_TEXTURE0);
4001         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
4002
4003         gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, m_to_ms);
4004         GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
4005
4006         gl.bindTextureUnit(0, m_to);
4007
4008         gl.uniform1i(gl.getUniformLocation(m_po_aux, "texture_input"), 0);
4009         GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed");
4010
4011         /* For each texture layer. */
4012         for (glw::GLuint i = 0; i < TestReferenceDataDepth<3>(); ++i)
4013         {
4014                 /* Select layer. */
4015                 gl.drawBuffer(GL_COLOR_ATTACHMENT0 + i);
4016                 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawBuffer has failed");
4017
4018                 gl.uniform1i(gl.getUniformLocation(m_po_aux, "texture_layer"), i);
4019                 GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed");
4020
4021                 /* Draw. */
4022                 gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
4023                 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed");
4024         }
4025 }
4026
4027 /** @brief Clean GL objects, test variables and GL errors.
4028  */
4029 void StorageMultisampleTest::CleanInputTexture()
4030 {
4031         /* Shortcut for GL functionality. */
4032         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4033
4034         /* Texture. */
4035         if (m_to)
4036         {
4037                 gl.deleteTextures(1, &m_to);
4038
4039                 m_to = 0;
4040         }
4041 }
4042
4043 /** @brief Clean GL objects, test variables and GL errors.
4044  */
4045 void StorageMultisampleTest::CleanAuxiliaryTexture()
4046 {
4047         /* Shortcut for GL functionality. */
4048         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4049
4050         if (m_to_aux)
4051         {
4052                 gl.deleteTextures(1, &m_to_aux);
4053
4054                 m_to_aux = 0;
4055         }
4056 }
4057
4058 /** @brief Clean GL objects, test variables and GL errors.
4059  */
4060 void StorageMultisampleTest::CleanFramebuffers()
4061 {
4062         /* Shortcut for GL functionality. */
4063         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4064
4065         /* Mulitsample framebuffer. */
4066         if (m_fbo_ms)
4067         {
4068                 gl.deleteFramebuffers(1, &m_fbo_ms);
4069
4070                 m_fbo_ms = 0;
4071         }
4072
4073         /* Mulitsample texture. */
4074         if (m_to_ms)
4075         {
4076                 gl.deleteTextures(1, &m_to_ms);
4077
4078                 m_to_ms = 0;
4079         }
4080
4081         /* Auxiliary framebuffer. */
4082         if (m_fbo_aux)
4083         {
4084                 gl.deleteFramebuffers(1, &m_fbo_aux);
4085
4086                 m_fbo_aux = 0;
4087         }
4088
4089         /* Auxiliary texture. */
4090         if (m_to_aux)
4091         {
4092                 gl.deleteTextures(1, &m_to_aux);
4093
4094                 m_to_aux = 0;
4095         }
4096 }
4097
4098 /** @brief Clean GL objects, test variables and GL errors.
4099  */
4100 void StorageMultisampleTest::CleanPrograms()
4101 {
4102         /* Shortcut for GL functionality. */
4103         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4104
4105         /* Binding point. */
4106         gl.useProgram(0);
4107
4108         /* Multisample texture preparation program. */
4109         if (m_po_ms)
4110         {
4111                 gl.deleteProgram(m_po_ms);
4112
4113                 m_po_ms = 0;
4114         }
4115
4116         /* Auxiliary texture preparation program. */
4117         if (m_po_aux)
4118         {
4119                 gl.deleteProgram(m_po_aux);
4120
4121                 m_po_aux = 0;
4122         }
4123 }
4124
4125 /** @brief Clean GL objects, test variables and GL errors.
4126  */
4127 void StorageMultisampleTest::CleanErrors()
4128 {
4129         /* Shortcut for GL functionality. */
4130         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4131
4132         /* Query all errors until GL_NO_ERROR occure. */
4133         while (GL_NO_ERROR != gl.getError())
4134                 ;
4135 }
4136
4137 /** @brief Clean GL objects, test variables and GL errors.
4138  */
4139 void StorageMultisampleTest::CleanVertexArray()
4140 {
4141         /* Shortcut for GL functionality. */
4142         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4143
4144         if (m_vao)
4145         {
4146                 gl.bindVertexArray(0);
4147
4148                 gl.deleteVertexArrays(1, &m_vao);
4149
4150                 m_vao = 0;
4151         }
4152 }
4153
4154 /** @brief Iterate Storage Multisample Test cases.
4155  *
4156  *  @return Iteration result.
4157  */
4158 tcu::TestNode::IterateResult StorageMultisampleTest::iterate()
4159 {
4160         /* Shortcut for GL functionality. */
4161         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4162
4163         /* Get context setup. */
4164         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
4165         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
4166
4167         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
4168         {
4169                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
4170
4171                 return STOP;
4172         }
4173
4174         /* Running tests. */
4175         bool is_ok      = true;
4176         bool is_error = false;
4177
4178         try
4179         {
4180                 PrepareVertexArray();
4181
4182                 //  gl.enable(GL_MULTISAMPLE);
4183
4184                 is_ok &= LoopTestOverDOverS<glw::GLbyte, false>(true);
4185                 is_ok &= LoopTestOverDOverS<glw::GLubyte, false>(true);
4186                 is_ok &= LoopTestOverDOverS<glw::GLshort, false>(true);
4187                 is_ok &= LoopTestOverDOverS<glw::GLushort, false>(true);
4188                 is_ok &= LoopTestOverDOverS<glw::GLint, false>(false);
4189                 is_ok &= LoopTestOverDOverS<glw::GLuint, false>(false);
4190                 is_ok &= LoopTestOverDOverS<glw::GLubyte, true>(true);
4191                 is_ok &= LoopTestOverDOverS<glw::GLushort, true>(true);
4192                 is_ok &= LoopTestOverDOverS<glw::GLfloat, true>(false);
4193         }
4194         catch (...)
4195         {
4196                 is_ok   = false;
4197                 is_error = true;
4198         }
4199
4200         /* Cleanup. */
4201         CleanInputTexture();
4202         CleanAuxiliaryTexture();
4203         CleanFramebuffers();
4204         CleanPrograms();
4205         CleanErrors();
4206         CleanVertexArray();
4207         gl.disable(GL_MULTISAMPLE);
4208
4209         /* Errors clean up. */
4210         while (gl.getError())
4211                 ;
4212
4213         /* Result's setup. */
4214         if (is_ok)
4215         {
4216                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
4217         }
4218         else
4219         {
4220                 if (is_error)
4221                 {
4222                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
4223                 }
4224                 else
4225                 {
4226                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
4227                 }
4228         }
4229
4230         return STOP;
4231 }
4232
4233 /* Vertex shader source code. */
4234 const glw::GLchar* StorageMultisampleTest::s_vertex_shader = "#version 450\n"
4235                                                                                                                          "\n"
4236                                                                                                                          "void main()\n"
4237                                                                                                                          "{\n"
4238                                                                                                                          "    switch(gl_VertexID)\n"
4239                                                                                                                          "    {\n"
4240                                                                                                                          "        case 0:\n"
4241                                                                                                                          "            gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
4242                                                                                                                          "            break;\n"
4243                                                                                                                          "        case 1:\n"
4244                                                                                                                          "            gl_Position = vec4( 1.0, 1.0, 0.0, 1.0);\n"
4245                                                                                                                          "            break;\n"
4246                                                                                                                          "        case 2:\n"
4247                                                                                                                          "            gl_Position = vec4(-1.0,-1.0, 0.0, 1.0);\n"
4248                                                                                                                          "            break;\n"
4249                                                                                                                          "        case 3:\n"
4250                                                                                                                          "            gl_Position = vec4( 1.0,-1.0, 0.0, 1.0);\n"
4251                                                                                                                          "            break;\n"
4252                                                                                                                          "    }\n"
4253                                                                                                                          "}\n";
4254
4255 /* Fragment shader source program. */
4256 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_head =
4257         "#version 450\n"
4258         "\n"
4259         "layout(pixel_center_integer) in vec4 gl_FragCoord;\n"
4260         "\n";
4261
4262 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_fdecl_lowp =
4263         "uniform  sampler2D texture_input;\nout     vec4          texture_output;\n";
4264 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_idecl_lowp =
4265         "uniform isampler2D texture_input;\nout     ivec4         texture_output;\n";
4266 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_udecl_lowp =
4267         "uniform usampler2D texture_input;\nout     uvec4         texture_output;\n";
4268 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_fdecl_mediump =
4269         "uniform  sampler2D texture_input;\nout     vec4          texture_output;\n";
4270 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_idecl_mediump =
4271         "uniform isampler2D texture_input;\nout     ivec4         texture_output;\n";
4272 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_udecl_mediump =
4273         "uniform usampler2D texture_input;\nout     uvec4         texture_output;\n";
4274 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_fdecl_highp =
4275         "uniform  sampler2D texture_input;\nout     vec4          texture_output;\n";
4276 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_idecl_highp =
4277         "uniform isampler2D texture_input;\nout     ivec4         texture_output;\n";
4278 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_2D_udecl_highp =
4279         "uniform usampler2D texture_input;\nout     uvec4         texture_output;\n";
4280
4281 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_fdecl_lowp =
4282         "uniform  sampler2DArray texture_input;\nout     vec4          texture_output;\n";
4283
4284 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_idecl_lowp =
4285         "uniform isampler2DArray texture_input;\nout     ivec4         texture_output;\n";
4286
4287 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_udecl_lowp =
4288         "uniform usampler2DArray texture_input;\nout     uvec4         texture_output;\n";
4289
4290 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_fdecl_mediump =
4291         "uniform  sampler2DArray texture_input;\nout     vec4          texture_output;\n";
4292
4293 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_idecl_mediump =
4294         "uniform isampler2DArray texture_input;\nout     ivec4         texture_output;\n";
4295
4296 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_udecl_mediump =
4297         "uniform usampler2DArray texture_input;\nout     uvec4         texture_output;\n";
4298
4299 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_fdecl_highp =
4300         "uniform  sampler2DArray texture_input;\nout     vec4          texture_output;\n";
4301
4302 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_idecl_highp =
4303         "uniform isampler2DArray texture_input;\nout     ivec4         texture_output;\n";
4304
4305 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_ms_3D_udecl_highp =
4306         "uniform usampler2DArray texture_input;\nout     uvec4         texture_output;\n";
4307
4308 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_fdecl_lowp =
4309         "uniform  sampler2DMS texture_input;\nout     vec4          texture_output;\n";
4310 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_idecl_lowp =
4311         "uniform isampler2DMS texture_input;\nout     ivec4         texture_output;\n";
4312 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_udecl_lowp =
4313         "uniform usampler2DMS texture_input;\nout     uvec4         texture_output;\n";
4314
4315 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_fdecl_mediump =
4316         "uniform  sampler2DMS texture_input;\nout     vec4          texture_output;\n";
4317
4318 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_idecl_mediump =
4319         "uniform isampler2DMS texture_input;\nout     ivec4         texture_output;\n";
4320
4321 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_udecl_mediump =
4322         "uniform usampler2DMS texture_input;\nout     uvec4         texture_output;\n";
4323
4324 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_fdecl_highp =
4325         "uniform  sampler2DMS texture_input;\nout     vec4          texture_output;\n";
4326 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_idecl_highp =
4327         "uniform isampler2DMS texture_input;\nout     ivec4         texture_output;\n";
4328 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_2D_udecl_highp =
4329         "uniform usampler2DMS texture_input;\nout     uvec4         texture_output;\n";
4330
4331 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_fdecl_lowp =
4332         "uniform  sampler2DMSArray texture_input;\nout     vec4          texture_output;\n";
4333
4334 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_idecl_lowp =
4335         "uniform isampler2DMSArray texture_input;\nout     ivec4         texture_output;\n";
4336
4337 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_udecl_lowp =
4338         "uniform usampler2DMSArray texture_input;\nout     uvec4         texture_output;\n";
4339
4340 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_fdecl_mediump =
4341         "uniform  sampler2DMSArray texture_input;\nout     vec4          texture_output;\n";
4342
4343 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_idecl_mediump =
4344         "uniform isampler2DMSArray texture_input;\nout     ivec4         texture_output;\n";
4345
4346 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_udecl_mediump =
4347         "uniform usampler2DMSArray texture_input;\nout     uvec4         texture_output;\n";
4348
4349 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_fdecl_highp =
4350         "uniform  sampler2DMSArray texture_input;\nout     vec4          texture_output;\n";
4351
4352 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_idecl_highp =
4353         "uniform isampler2DMSArray texture_input;\nout     ivec4         texture_output;\n";
4354
4355 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_aux_3D_udecl_highp =
4356         "uniform usampler2DMSArray texture_input;\nout     uvec4         texture_output;\n";
4357
4358 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_tail_2D =
4359         "\n"
4360         "void main()\n"
4361         "{\n"
4362         "    texture_output = texelFetch(texture_input, ivec2(gl_FragCoord.xy), 0);\n"
4363         "}\n";
4364
4365 const glw::GLchar* StorageMultisampleTest::s_fragment_shader_tail_3D =
4366         "\n"
4367         "uniform int texture_layer;\n"
4368         "\n"
4369         "void main()\n"
4370         "{\n"
4371         "    texture_output = texelFetch(texture_input, ivec3(gl_FragCoord.xy, texture_layer), 0);\n"
4372         "}\n";
4373
4374 /******************************** Compressed SubImage Test Implementation   ********************************/
4375
4376 /** @brief Compressed SubImage Test constructor.
4377  *
4378  *  @param [in] context     OpenGL context.
4379  */
4380 CompressedSubImageTest::CompressedSubImageTest(deqp::Context& context)
4381         : deqp::TestCase(context, "textures_compressed_subimage", "Texture Compressed SubImage Test")
4382         , m_to(0)
4383         , m_to_aux(0)
4384         , m_reference(DE_NULL)
4385         , m_result(DE_NULL)
4386         , m_reference_size(0)
4387         , m_reference_internalformat(0)
4388 {
4389         /* Intentionally left blank. */
4390 }
4391
4392 /** @brief Create texture.
4393  *
4394  *  @param [in] target      Texture target.
4395  */
4396 void CompressedSubImageTest::CreateTextures(glw::GLenum target)
4397 {
4398         /* Shortcut for GL functionality. */
4399         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4400
4401         /* Auxiliary texture (for content creation). */
4402         gl.genTextures(1, &m_to_aux);
4403         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
4404
4405         gl.bindTexture(target, m_to_aux);
4406         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4407
4408         /* Test texture (for data upload). */
4409         gl.genTextures(1, &m_to);
4410         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
4411
4412         gl.bindTexture(target, m_to);
4413         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4414 }
4415
4416 /** @brief Texture target selector.
4417  *
4418  *  @tparam D      Texture dimenisons.
4419  *
4420  *  @return Texture target.
4421  */
4422 template <>
4423 glw::GLenum CompressedSubImageTest::TextureTarget<1>()
4424 {
4425         return GL_TEXTURE_1D;
4426 }
4427
4428 template <>
4429 glw::GLenum CompressedSubImageTest::TextureTarget<2>()
4430 {
4431         return GL_TEXTURE_2D;
4432 }
4433
4434 template <>
4435 glw::GLenum CompressedSubImageTest::TextureTarget<3>()
4436 {
4437         return GL_TEXTURE_2D_ARRAY;
4438 }
4439
4440 /** @brief Prepare texture data for the auxiliary texture.
4441  *
4442  *  @tparam D      Texture dimenisons.
4443  *
4444  *  @note parameters as passed to texImage*
4445  */
4446 template <>
4447 void CompressedSubImageTest::TextureImage<1>(glw::GLint internalformat)
4448 {
4449         /* Shortcut for GL functionality. */
4450         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4451
4452         gl.texImage1D(TextureTarget<1>(), 0, internalformat, s_texture_width, 0, GL_RGBA, GL_UNSIGNED_BYTE, s_texture_data);
4453         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
4454 }
4455
4456 /** @brief Prepare texture data for the auxiliary texture.
4457  *
4458  *  @tparam D      Texture dimenisons.
4459  *
4460  *  @note parameters as passed to texImage*
4461  */
4462 template <>
4463 void CompressedSubImageTest::TextureImage<2>(glw::GLint internalformat)
4464 {
4465         /* Shortcut for GL functionality. */
4466         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4467
4468         gl.texImage2D(TextureTarget<2>(), 0, internalformat, s_texture_width, s_texture_height, 0, GL_RGBA,
4469                                   GL_UNSIGNED_BYTE, s_texture_data);
4470         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
4471 }
4472
4473 /** @brief Prepare texture data for the auxiliary texture.
4474  *
4475  *  @tparam D      Texture dimenisons.
4476  *
4477  *  @note parameters as passed to texImage*
4478  */
4479 template <>
4480 void CompressedSubImageTest::TextureImage<3>(glw::GLint internalformat)
4481 {
4482         /* Shortcut for GL functionality. */
4483         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4484
4485         gl.texImage3D(TextureTarget<3>(), 0, internalformat, s_texture_width, s_texture_height, s_texture_depth, 0, GL_RGBA,
4486                                   GL_UNSIGNED_BYTE, s_texture_data);
4487         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage3D has failed");
4488 }
4489
4490 /** @brief Prepare texture data for the compressed texture.
4491  *
4492  *  @tparam D      Texture dimenisons.
4493  *
4494  *  @param [in] internalformat      Texture internal format.
4495  *
4496  *  @return True if tested function succeeded, false otherwise.
4497  */
4498 template <>
4499 bool CompressedSubImageTest::CompressedTextureSubImage<1>(glw::GLint internalformat)
4500 {
4501         /* Shortcut for GL functionality. */
4502         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4503
4504         /* Load texture image with tested function. */
4505         if (m_reference_size)
4506         {
4507                 gl.compressedTextureSubImage1D(m_to, 0, 0, s_texture_width, internalformat, m_reference_size, m_reference);
4508         }
4509         else
4510         {
4511                 /* For 1D version there is no specific compressed texture internal format spcified in OpenGL 4.5 core profile documentation.
4512                  Only implementation depended specific internalformats may provide this functionality. As a result there may be no reference data to be substituted.
4513                  Due to this reason there is no use of CompressedTextureSubImage1D and particulary it cannot be tested. */
4514                 return true;
4515         }
4516
4517         /* Check errors. */
4518         glw::GLenum error;
4519
4520         if (GL_NO_ERROR != (error = gl.getError()))
4521         {
4522                 m_context.getTestContext().getLog()
4523                         << tcu::TestLog::Message << "glCompressedTextureSubImage1D unexpectedly generated error "
4524                         << glu::getErrorStr(error) << " during the test with internal format "
4525                         << glu::getTextureFormatStr(internalformat) << ". Test fails." << tcu::TestLog::EndMessage;
4526
4527                 return false;
4528         }
4529
4530         return true;
4531 }
4532
4533 /** @brief Prepare texture data for the compressed texture.
4534  *
4535  *  @tparam D      Texture dimenisons.
4536  *
4537  *  @param [in] internalformat      Texture internal format.
4538  *
4539  *  @return True if tested function succeeded, false otherwise.
4540  */
4541 template <>
4542 bool CompressedSubImageTest::CompressedTextureSubImage<2>(glw::GLint internalformat)
4543 {
4544         /* Shortcut for GL functionality. */
4545         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4546
4547         /* Load texture image with tested function. */
4548         gl.compressedTextureSubImage2D(m_to, 0, 0, 0, s_texture_width, s_texture_height, internalformat, m_reference_size,
4549                                                                    m_reference);
4550
4551         /* Check errors. */
4552         glw::GLenum error;
4553
4554         if (GL_NO_ERROR != (error = gl.getError()))
4555         {
4556                 m_context.getTestContext().getLog()
4557                         << tcu::TestLog::Message << "glCompressedTextureSubImage2D unexpectedly generated error "
4558                         << glu::getErrorStr(error) << " during the test with internal format "
4559                         << glu::getTextureFormatStr(internalformat) << ". Test fails." << tcu::TestLog::EndMessage;
4560
4561                 return false;
4562         }
4563
4564         return true;
4565 }
4566
4567 /** @brief Prepare texture data for the compressed texture.
4568  *
4569  *  @tparam D      Texture dimenisons.
4570  *
4571  *  @param [in] internalformat      Texture internal format.
4572  *
4573  *  @return True if tested function succeeded, false otherwise.
4574  */
4575 template <>
4576 bool CompressedSubImageTest::CompressedTextureSubImage<3>(glw::GLint internalformat)
4577 {
4578         /* Shortcut for GL functionality. */
4579         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4580
4581         /* Load texture image with tested function. */
4582         gl.compressedTextureSubImage3D(m_to, 0, 0, 0, 0, s_texture_width, s_texture_height, s_texture_depth, internalformat,
4583                                                                    m_reference_size, m_reference);
4584
4585         /* Check errors. */
4586         glw::GLenum error;
4587
4588         if (GL_NO_ERROR != (error = gl.getError()))
4589         {
4590                 m_context.getTestContext().getLog()
4591                         << tcu::TestLog::Message << "glCompressedTextureSubImage2D unexpectedly generated error "
4592                         << glu::getErrorStr(error) << " during the test with internal format "
4593                         << glu::getTextureFormatStr(internalformat) << ". Test fails." << tcu::TestLog::EndMessage;
4594
4595                 return false;
4596         }
4597         return true;
4598 }
4599
4600 /** @brief Prepare the reference data.
4601  *
4602  *  @tparam D      Texture dimenisons.
4603  */
4604 template <glw::GLuint D>
4605 void CompressedSubImageTest::PrepareReferenceData(glw::GLenum internalformat)
4606 {
4607         /* Shortcut for GL functionality. */
4608         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4609
4610         /* Using OpenGL to compress raw data. */
4611         gl.bindTexture(TextureTarget<D>(), m_to_aux);
4612         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4613
4614         TextureImage<D>(internalformat);
4615
4616         /* Sanity checks. */
4617         if (DE_NULL != m_reference)
4618         {
4619                 throw 0;
4620         }
4621
4622         /* Check that really compressed texture. */
4623         glw::GLint is_compressed_texture = 0;
4624         gl.getTexLevelParameteriv(TextureTarget<D>(), 0, GL_TEXTURE_COMPRESSED, &is_compressed_texture);
4625
4626         if (is_compressed_texture)
4627         {
4628                 /* Query texture size. */
4629                 glw::GLint compressed_texture_size = 0;
4630                 gl.getTexLevelParameteriv(TextureTarget<D>(), 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compressed_texture_size);
4631
4632                 /* If compressed then download. */
4633                 if (compressed_texture_size)
4634                 {
4635                         /* Prepare storage. */
4636                         m_reference = new glw::GLubyte[compressed_texture_size];
4637
4638                         if (DE_NULL != m_reference)
4639                         {
4640                                 m_reference_size = compressed_texture_size;
4641                         }
4642                         else
4643                         {
4644                                 throw 0;
4645                         }
4646
4647                         /* Download compressed texture image. */
4648                         gl.getCompressedTexImage(TextureTarget<D>(), 0, m_reference);
4649                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
4650                 }
4651         }
4652 }
4653
4654 /** @brief Prepare texture storage.
4655  *
4656  *  @tparam D      Texture dimenisons.
4657  *
4658  *  @param [in] internalformat      Texture internal format.
4659  */
4660 template <>
4661 void CompressedSubImageTest::PrepareStorage<1>(glw::GLenum internalformat)
4662 {
4663         /* Shortcut for GL functionality. */
4664         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4665
4666         gl.bindTexture(TextureTarget<1>(), m_to);
4667         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4668
4669         gl.texImage1D(TextureTarget<1>(), 0, internalformat, s_texture_width, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
4670         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
4671 }
4672
4673 /** @brief Prepare texture storage.
4674  *
4675  *  @tparam D      Texture dimenisons.
4676  *
4677  *  @param [in] internalformat      Texture internal format.
4678  */
4679 template <>
4680 void CompressedSubImageTest::PrepareStorage<2>(glw::GLenum internalformat)
4681 {
4682         /* Shortcut for GL functionality. */
4683         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4684
4685         gl.bindTexture(TextureTarget<2>(), m_to);
4686         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4687
4688         gl.texImage2D(TextureTarget<2>(), 0, internalformat, s_texture_width, s_texture_height, 0, GL_RGBA,
4689                                   GL_UNSIGNED_BYTE, NULL);
4690         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
4691 }
4692
4693 /** @brief Prepare texture storage.
4694  *
4695  *  @tparam D      Texture dimenisons.
4696  *
4697  *  @param [in] internalformat      Texture internal format.
4698  */
4699 template <>
4700 void CompressedSubImageTest::PrepareStorage<3>(glw::GLenum internalformat)
4701 {
4702         /* Shortcut for GL functionality. */
4703         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4704
4705         gl.bindTexture(TextureTarget<3>(), m_to);
4706         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4707
4708         gl.texImage3D(TextureTarget<3>(), 0, internalformat, s_texture_width, s_texture_height, s_texture_depth, 0, GL_RGBA,
4709                                   GL_UNSIGNED_BYTE, NULL);
4710         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
4711 }
4712
4713 /** @brief Compre results with the reference.
4714  *
4715  *  @tparam T      Type.
4716  *  @tparam S      Size (# of components).
4717  *  @tparam N      Is normalized.
4718  *
4719  *  @param [in] target              Texture target.
4720  *  @param [in] internalformat      Texture internal format.
4721  *
4722  *  @return True if equal, false otherwise.
4723  */
4724 bool CompressedSubImageTest::CheckData(glw::GLenum target, glw::GLenum internalformat)
4725 {
4726         /* Shortcut for GL functionality. */
4727         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4728
4729         /* Check texture content with reference. */
4730         m_result = new glw::GLubyte[m_reference_size];
4731
4732         if (DE_NULL == m_result)
4733         {
4734                 throw 0;
4735         }
4736
4737         gl.getCompressedTexImage(target, 0, m_result);
4738         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
4739
4740         for (glw::GLuint i = 0; i < m_reference_size; ++i)
4741         {
4742                 if (m_reference[i] != m_result[i])
4743                 {
4744                         m_context.getTestContext().getLog()
4745                                 << tcu::TestLog::Message << "glCompressedTextureSubImage*D created texture with data "
4746                                 << DataToString(m_reference_size, m_reference) << " however texture contains data "
4747                                 << DataToString(m_reference_size, m_result) << ". Texture target was "
4748                                 << glu::getTextureTargetStr(target) << " and internal format was "
4749                                 << glu::getTextureFormatStr(internalformat) << ". Test fails." << tcu::TestLog::EndMessage;
4750
4751                         return false;
4752                 }
4753         }
4754
4755         return true;
4756 }
4757
4758 /** @brief Test case function.
4759  *
4760  *  @tparam D       Number of texture dimensions.
4761  *
4762  *  @param [in] internal format     Texture internal format.
4763  *
4764  *  @return True if test succeeded, false otherwise.
4765  */
4766 template <glw::GLuint D>
4767 bool CompressedSubImageTest::Test(glw::GLenum internalformat)
4768 {
4769         /* Create texture image. */
4770         CreateTextures(TextureTarget<D>());
4771         PrepareReferenceData<D>(internalformat);
4772         PrepareStorage<D>(internalformat);
4773
4774         /* Setup data with CompressedTextureSubImage<D>D function and check for errors. */
4775         if (!CompressedTextureSubImage<D>(internalformat))
4776         {
4777                 CleanAll();
4778
4779                 return false;
4780         }
4781
4782         /* If compressed reference data was generated than compare values. */
4783         if (m_reference)
4784         {
4785                 if (!CheckData(TextureTarget<D>(), internalformat))
4786                 {
4787                         CleanAll();
4788
4789                         return false;
4790                 }
4791         }
4792
4793         CleanAll();
4794
4795         return true;
4796 }
4797
4798 /** @brief Clean GL objects, test variables and GL errors.
4799  */
4800 void CompressedSubImageTest::CleanAll()
4801 {
4802         /* Shortcut for GL functionality. */
4803         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4804
4805         /* Textures. */
4806         if (m_to)
4807         {
4808                 gl.deleteTextures(1, &m_to);
4809
4810                 m_to = 0;
4811         }
4812
4813         if (m_to_aux)
4814         {
4815                 gl.deleteTextures(1, &m_to_aux);
4816
4817                 m_to_aux = 0;
4818         }
4819
4820         /* Reference data storage. */
4821         if (DE_NULL != m_reference)
4822         {
4823                 delete[] m_reference;
4824
4825                 m_reference = DE_NULL;
4826         }
4827
4828         if (DE_NULL != m_result)
4829         {
4830                 delete[] m_result;
4831
4832                 m_result = DE_NULL;
4833         }
4834
4835         m_reference_size = 0;
4836
4837         /* Errors. */
4838         while (GL_NO_ERROR != gl.getError())
4839                 ;
4840 }
4841
4842 /** @brief Convert raw data into string for logging purposes.
4843  *
4844  *  @param [in] count      Count of the data.
4845  *  @param [in] data       Raw data.
4846  *
4847  *  @return String representation of data.
4848  */
4849 std::string CompressedSubImageTest::DataToString(glw::GLuint count, const glw::GLubyte data[])
4850 {
4851         std::string data_str = "[";
4852
4853         for (glw::GLuint i = 0; i < count; ++i)
4854         {
4855                 std::stringstream int_sstream;
4856
4857                 int_sstream << unsigned(data[i]);
4858
4859                 data_str.append(int_sstream.str());
4860
4861                 if (i + 1 < count)
4862                 {
4863                         data_str.append(", ");
4864                 }
4865                 else
4866                 {
4867                         data_str.append("]");
4868                 }
4869         }
4870
4871         return data_str;
4872 }
4873
4874 /** @brief Iterate Compressed SubImage Test cases.
4875  *
4876  *  @return Iteration result.
4877  */
4878 tcu::TestNode::IterateResult CompressedSubImageTest::iterate()
4879 {
4880         /* Shortcut for GL functionality. */
4881         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4882
4883         /* Get context setup. */
4884         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
4885         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
4886
4887         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
4888         {
4889                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
4890
4891                 return STOP;
4892         }
4893
4894         /* Running tests. */
4895         bool is_ok      = true;
4896         bool is_error = false;
4897
4898         try
4899         {
4900                 is_ok &= Test<1>(GL_COMPRESSED_RGB);
4901
4902                 is_ok &= Test<2>(GL_COMPRESSED_RED_RGTC1);
4903                 is_ok &= Test<2>(GL_COMPRESSED_SIGNED_RED_RGTC1);
4904                 is_ok &= Test<2>(GL_COMPRESSED_RG_RGTC2);
4905                 is_ok &= Test<2>(GL_COMPRESSED_SIGNED_RG_RGTC2);
4906                 is_ok &= Test<2>(GL_COMPRESSED_RGBA_BPTC_UNORM);
4907                 is_ok &= Test<2>(GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM);
4908                 is_ok &= Test<2>(GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT);
4909                 is_ok &= Test<2>(GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT);
4910                 is_ok &= Test<2>(GL_COMPRESSED_RGB8_ETC2);
4911                 is_ok &= Test<2>(GL_COMPRESSED_SRGB8_ETC2);
4912                 is_ok &= Test<2>(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2);
4913                 is_ok &= Test<2>(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2);
4914                 is_ok &= Test<2>(GL_COMPRESSED_RGBA8_ETC2_EAC);
4915                 is_ok &= Test<2>(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC);
4916                 is_ok &= Test<2>(GL_COMPRESSED_R11_EAC);
4917                 is_ok &= Test<2>(GL_COMPRESSED_SIGNED_R11_EAC);
4918                 is_ok &= Test<2>(GL_COMPRESSED_RG11_EAC);
4919                 is_ok &= Test<2>(GL_COMPRESSED_SIGNED_RG11_EAC);
4920
4921                 is_ok &= Test<3>(GL_COMPRESSED_RED_RGTC1);
4922                 is_ok &= Test<3>(GL_COMPRESSED_SIGNED_RED_RGTC1);
4923                 is_ok &= Test<3>(GL_COMPRESSED_RG_RGTC2);
4924                 is_ok &= Test<3>(GL_COMPRESSED_SIGNED_RG_RGTC2);
4925                 is_ok &= Test<3>(GL_COMPRESSED_RGBA_BPTC_UNORM);
4926                 is_ok &= Test<3>(GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM);
4927                 is_ok &= Test<3>(GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT);
4928                 is_ok &= Test<3>(GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT);
4929                 is_ok &= Test<3>(GL_COMPRESSED_RGB8_ETC2);
4930                 is_ok &= Test<3>(GL_COMPRESSED_SRGB8_ETC2);
4931                 is_ok &= Test<3>(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2);
4932                 is_ok &= Test<3>(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2);
4933                 is_ok &= Test<3>(GL_COMPRESSED_RGBA8_ETC2_EAC);
4934                 is_ok &= Test<3>(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC);
4935                 is_ok &= Test<3>(GL_COMPRESSED_R11_EAC);
4936                 is_ok &= Test<3>(GL_COMPRESSED_SIGNED_R11_EAC);
4937                 is_ok &= Test<3>(GL_COMPRESSED_RG11_EAC);
4938                 is_ok &= Test<3>(GL_COMPRESSED_SIGNED_RG11_EAC);
4939         }
4940         catch (...)
4941         {
4942                 is_ok   = false;
4943                 is_error = true;
4944         }
4945
4946         /* Cleanup. */
4947         CleanAll();
4948
4949         /* Errors clean up. */
4950         while (gl.getError())
4951                 ;
4952
4953         /* Result's setup. */
4954         if (is_ok)
4955         {
4956                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
4957         }
4958         else
4959         {
4960                 if (is_error)
4961                 {
4962                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
4963                 }
4964                 else
4965                 {
4966                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
4967                 }
4968         }
4969
4970         return STOP;
4971 }
4972
4973 /** Reference data. */
4974 const glw::GLubyte CompressedSubImageTest::s_texture_data[] = {
4975         0x00, 0x00, 0x00, 0xFF, 0x7f, 0x7f, 0x7f, 0x00, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0x00,
4976         0x88, 0x00, 0x15, 0xFF, 0xed, 0x1c, 0x24, 0x00, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x00, 0x00,
4977         0xc8, 0xbf, 0xe7, 0xFF, 0x70, 0x92, 0xbe, 0x00, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0x00,
4978         0xa3, 0x49, 0xa4, 0xFF, 0x3f, 0x48, 0xcc, 0x00, 0x00, 0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0x00,
4979
4980         0xa3, 0x49, 0xa4, 0xFF, 0xc8, 0xbf, 0xe7, 0x00, 0x88, 0x00, 0x15, 0xff, 0x00, 0x00, 0x00, 0x00,
4981         0x3f, 0x48, 0xcc, 0xFF, 0x70, 0x92, 0xbe, 0x00, 0xed, 0x1c, 0x24, 0xff, 0x7f, 0x7f, 0x7f, 0x00,
4982         0x00, 0xa2, 0xe8, 0xFF, 0x99, 0xd9, 0xea, 0x00, 0xff, 0x7f, 0x27, 0xff, 0xc3, 0xc3, 0xc3, 0x00,
4983         0x22, 0xb1, 0x4c, 0xFF, 0xb5, 0xe6, 0x1d, 0x00, 0xff, 0xf2, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00,
4984
4985         0x22, 0xb1, 0x4c, 0xFF, 0x00, 0xa2, 0xe8, 0x00, 0x3f, 0x48, 0xcc, 0xff, 0xa3, 0x49, 0xa4, 0x00,
4986         0xb5, 0xe6, 0x1d, 0xFF, 0x99, 0xd9, 0xea, 0x00, 0x70, 0x92, 0xbe, 0xff, 0xc8, 0xbf, 0xe7, 0x00,
4987         0xff, 0xf2, 0x00, 0xFF, 0xff, 0x7f, 0x27, 0x00, 0xed, 0x1c, 0x24, 0xff, 0x88, 0x00, 0x15, 0x00,
4988         0xff, 0xff, 0xff, 0xFF, 0xc3, 0xc3, 0xc3, 0x00, 0x7f, 0x7f, 0x7f, 0xff, 0x00, 0x00, 0x00, 0x00,
4989
4990         0xff, 0xff, 0xff, 0xFF, 0xff, 0xf2, 0x00, 0x00, 0xb5, 0xe6, 0x1d, 0xff, 0x22, 0xb1, 0x4c, 0x00,
4991         0xc3, 0xc3, 0xc3, 0xFF, 0xff, 0x7f, 0x27, 0x00, 0x99, 0xd9, 0xea, 0xff, 0x00, 0xa2, 0xe8, 0x00,
4992         0x7f, 0x7f, 0x7f, 0xFF, 0xed, 0x1c, 0x24, 0x00, 0x70, 0x92, 0xbe, 0xff, 0x3f, 0x48, 0xcc, 0x00,
4993         0x00, 0x00, 0x00, 0xFF, 0x88, 0x00, 0x15, 0x00, 0xc8, 0xbf, 0xe7, 0xff, 0xa3, 0x49, 0xa4, 0x00
4994 };
4995
4996 /** Reference data parameters. */
4997 const glw::GLuint CompressedSubImageTest::s_texture_width  = 4;
4998 const glw::GLuint CompressedSubImageTest::s_texture_height = 4;
4999 const glw::GLuint CompressedSubImageTest::s_texture_depth  = 4;
5000
5001 /******************************** Copy SubImage Test Implementation   ********************************/
5002
5003 /** @brief Compressed SubImage Test constructor.
5004  *
5005  *  @param [in] context     OpenGL context.
5006  */
5007 CopyTest::CopyTest(deqp::Context& context)
5008         : deqp::TestCase(context, "textures_copy", "Texture Copy Test")
5009         , m_fbo(0)
5010         , m_to_src(0)
5011         , m_to_dst(0)
5012         , m_result(DE_NULL)
5013 {
5014         /* Intentionally left blank. */
5015 }
5016
5017 /** @brief Texture target selector.
5018  *
5019  *  @tparam D      Texture dimenisons.
5020  *
5021  *  @return Texture target.
5022  */
5023 template <>
5024 glw::GLenum CopyTest::TextureTarget<1>()
5025 {
5026         return GL_TEXTURE_1D;
5027 }
5028 template <>
5029 glw::GLenum CopyTest::TextureTarget<2>()
5030 {
5031         return GL_TEXTURE_2D;
5032 }
5033 template <>
5034 glw::GLenum CopyTest::TextureTarget<3>()
5035 {
5036         return GL_TEXTURE_3D;
5037 }
5038
5039 /** @brief Copy texture, check errors and log.
5040  *
5041  *  @note Parameters as passed to CopyTextureSubImage*D
5042  *
5043  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
5044  */
5045 bool CopyTest::CopyTextureSubImage1DAndCheckErrors(glw::GLuint texture, glw::GLint level, glw::GLint xoffset,
5046                                                                                                    glw::GLint x, glw::GLint y, glw::GLsizei width)
5047 {
5048         /* Shortcut for GL functionality. */
5049         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5050
5051         gl.readBuffer(GL_COLOR_ATTACHMENT0);
5052         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
5053
5054         gl.copyTextureSubImage1D(texture, level, xoffset, x, y, width);
5055
5056         /* Check errors. */
5057         glw::GLenum error;
5058
5059         if (GL_NO_ERROR != (error = gl.getError()))
5060         {
5061                 m_context.getTestContext().getLog() << tcu::TestLog::Message
5062                                                                                         << "glCopyTextureSubImage1D unexpectedly generated error "
5063                                                                                         << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
5064
5065                 return false;
5066         }
5067
5068         return true;
5069 }
5070
5071 /** @brief Copy texture, check errors and log.
5072  *
5073  *  @note Parameters as passed to CopyTextureSubImage*D
5074  *
5075  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
5076  */
5077 bool CopyTest::CopyTextureSubImage2DAndCheckErrors(glw::GLuint texture, glw::GLint level, glw::GLint xoffset,
5078                                                                                                    glw::GLint yoffset, glw::GLint x, glw::GLint y, glw::GLsizei width,
5079                                                                                                    glw::GLsizei height)
5080 {
5081         /* Shortcut for GL functionality. */
5082         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5083
5084         gl.readBuffer(GL_COLOR_ATTACHMENT0);
5085         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
5086
5087         gl.copyTextureSubImage2D(texture, level, xoffset, yoffset, x, y, width, height);
5088
5089         /* Check errors. */
5090         glw::GLenum error;
5091
5092         if (GL_NO_ERROR != (error = gl.getError()))
5093         {
5094                 m_context.getTestContext().getLog() << tcu::TestLog::Message
5095                                                                                         << "glCopyTextureSubImage2D unexpectedly generated error "
5096                                                                                         << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
5097
5098                 return false;
5099         }
5100
5101         return true;
5102 }
5103
5104 /** @brief Copy texture, check errors and log.
5105  *
5106  *  @note Parameters as passed to CopyTextureSubImage*D
5107  *
5108  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
5109  */
5110 bool CopyTest::CopyTextureSubImage3DAndCheckErrors(glw::GLuint texture, glw::GLint level, glw::GLint xoffset,
5111                                                                                                    glw::GLint yoffset, glw::GLint zoffset, glw::GLint x, glw::GLint y,
5112                                                                                                    glw::GLsizei width, glw::GLsizei height)
5113 {
5114         /* Shortcut for GL functionality. */
5115         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5116
5117         gl.readBuffer(GL_COLOR_ATTACHMENT0 + zoffset);
5118         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
5119
5120         gl.copyTextureSubImage3D(texture, level, xoffset, yoffset, zoffset, x, y, width, height);
5121
5122         /* Check errors. */
5123         glw::GLenum error;
5124
5125         if (GL_NO_ERROR != (error = gl.getError()))
5126         {
5127                 m_context.getTestContext().getLog() << tcu::TestLog::Message
5128                                                                                         << "glCopyTextureSubImage3D unexpectedly generated error "
5129                                                                                         << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
5130
5131                 return false;
5132         }
5133
5134         return true;
5135 }
5136
5137 /** @brief Create texture.
5138  *
5139  *  @tparam D      Dimmensions.
5140  */
5141 template <>
5142 void CopyTest::CreateSourceTexture<1>()
5143 {
5144         /* Shortcut for GL functionality. */
5145         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5146
5147         gl.genTextures(1, &m_to_src);
5148         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
5149
5150         gl.bindTexture(TextureTarget<1>(), m_to_src);
5151         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
5152
5153         gl.texImage1D(TextureTarget<1>(), 0, GL_RGBA8, s_texture_width, 0, GL_RGBA, GL_UNSIGNED_BYTE, s_texture_data);
5154         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed.");
5155 }
5156
5157 /** @brief Create texture.
5158  *
5159  *  @tparam D      Dimmensions.
5160  */
5161 template <>
5162 void CopyTest::CreateSourceTexture<2>()
5163 {
5164         /* Shortcut for GL functionality. */
5165         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5166
5167         gl.genTextures(1, &m_to_src);
5168         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
5169
5170         gl.bindTexture(TextureTarget<2>(), m_to_src);
5171         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
5172
5173         gl.texImage2D(TextureTarget<2>(), 0, GL_RGBA8, s_texture_width, s_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
5174                                   s_texture_data);
5175         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed.");
5176 }
5177
5178 /** @brief Create texture.
5179  *
5180  *  @tparam D      Dimmensions.
5181  */
5182 template <>
5183 void CopyTest::CreateSourceTexture<3>()
5184 {
5185         /* Shortcut for GL functionality. */
5186         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5187
5188         gl.genTextures(1, &m_to_src);
5189         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
5190
5191         gl.bindTexture(TextureTarget<3>(), m_to_src);
5192         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
5193
5194         gl.texImage3D(TextureTarget<3>(), 0, GL_RGBA8, s_texture_width, s_texture_height, s_texture_depth, 0, GL_RGBA,
5195                                   GL_UNSIGNED_BYTE, s_texture_data);
5196         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed.");
5197 }
5198
5199 /** @brief Create texture.
5200  *
5201  *  @tparam D      Dimmensions.
5202  */
5203 template <>
5204 void CopyTest::CreateDestinationTexture<1>()
5205 {
5206         /* Shortcut for GL functionality. */
5207         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5208
5209         gl.genTextures(1, &m_to_dst);
5210         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
5211
5212         gl.bindTexture(TextureTarget<1>(), m_to_dst);
5213         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
5214
5215         gl.texImage1D(TextureTarget<1>(), 0, GL_RGBA8, s_texture_width, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
5216         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed.");
5217 }
5218
5219 /** @brief Create texture.
5220  *
5221  *  @tparam D      Dimmensions.
5222  */
5223 template <>
5224 void CopyTest::CreateDestinationTexture<2>()
5225 {
5226         /* Shortcut for GL functionality. */
5227         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5228
5229         gl.genTextures(1, &m_to_dst);
5230         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
5231
5232         gl.bindTexture(TextureTarget<2>(), m_to_dst);
5233         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
5234
5235         gl.texImage2D(TextureTarget<2>(), 0, GL_RGBA8, s_texture_width, s_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
5236                                   DE_NULL);
5237         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed.");
5238 }
5239
5240 /** @brief Create texture.
5241  *
5242  *  @tparam D      Dimmensions.
5243  */
5244 template <>
5245 void CopyTest::CreateDestinationTexture<3>()
5246 {
5247         /* Shortcut for GL functionality. */
5248         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5249
5250         gl.genTextures(1, &m_to_dst);
5251         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
5252
5253         gl.bindTexture(TextureTarget<3>(), m_to_dst);
5254         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
5255
5256         gl.texImage3D(TextureTarget<3>(), 0, GL_RGBA8, s_texture_width, s_texture_height, s_texture_depth, 0, GL_RGBA,
5257                                   GL_UNSIGNED_BYTE, DE_NULL);
5258         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed.");
5259 }
5260
5261 /** @brief Create framebuffer.
5262  *
5263  *  @tparam D      Dimmensions.
5264  */
5265 template <>
5266 void CopyTest::CreateSourceFramebuffer<1>()
5267 {
5268         /* Shortcut for GL functionality. */
5269         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5270
5271         /* Prepare framebuffer. */
5272         gl.genFramebuffers(1, &m_fbo);
5273         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
5274
5275         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
5276         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
5277
5278         gl.framebufferTexture1D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, TextureTarget<1>(), m_to_src, 0);
5279         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture1D call failed.");
5280
5281         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
5282         {
5283                 throw 0;
5284         }
5285
5286         gl.viewport(0, 0, s_texture_width, 1);
5287         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
5288 }
5289
5290 /** @brief Create framebuffer.
5291  *
5292  *  @tparam D      Dimmensions.
5293  */
5294 template <>
5295 void CopyTest::CreateSourceFramebuffer<2>()
5296 {
5297         /* Shortcut for GL functionality. */
5298         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5299
5300         /* Prepare framebuffer. */
5301         gl.genFramebuffers(1, &m_fbo);
5302         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
5303
5304         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
5305         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
5306
5307         gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, TextureTarget<2>(), m_to_src, 0);
5308         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture1D call failed.");
5309
5310         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
5311         {
5312                 throw 0;
5313         }
5314
5315         gl.viewport(0, 0, s_texture_width, s_texture_height);
5316         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
5317 }
5318
5319 /** @brief Create framebuffer.
5320  *
5321  *  @tparam D      Dimmensions.
5322  */
5323 template <>
5324 void CopyTest::CreateSourceFramebuffer<3>()
5325 {
5326         /* Shortcut for GL functionality. */
5327         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5328
5329         /* Prepare framebuffer. */
5330         gl.genFramebuffers(1, &m_fbo);
5331         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
5332
5333         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
5334         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
5335
5336         for (glw::GLuint i = 0; i < s_texture_depth; ++i)
5337         {
5338                 gl.framebufferTexture3D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, TextureTarget<3>(), m_to_src, 0, i);
5339                 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture1D call failed.");
5340         }
5341
5342         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
5343         {
5344                 throw 0;
5345         }
5346
5347         gl.viewport(0, 0, s_texture_width, s_texture_height);
5348         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
5349 }
5350
5351 /** @brief Dispatch function to create test objects */
5352 template <glw::GLuint D>
5353 void                              CopyTest::CreateAll()
5354 {
5355         CreateSourceTexture<D>();
5356         CreateSourceFramebuffer<D>();
5357         CreateDestinationTexture<D>();
5358 }
5359
5360 /** @brief Test function */
5361 template <>
5362 bool CopyTest::Test<1>()
5363 {
5364         CreateAll<1>();
5365
5366         bool result = true;
5367
5368         result &= CopyTextureSubImage1DAndCheckErrors(m_to_dst, 0, 0, 0, 0, s_texture_width / 2);
5369         result &= CopyTextureSubImage1DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, s_texture_width / 2, 0,
5370                                                                                                   s_texture_width / 2);
5371
5372         result &= CheckData(TextureTarget<1>(), 4 /* RGBA */ * s_texture_width);
5373
5374         CleanAll();
5375
5376         return result;
5377 }
5378
5379 /** @brief Test function */
5380 template <>
5381 bool CopyTest::Test<2>()
5382 {
5383         CreateAll<2>();
5384
5385         bool result = true;
5386
5387         result &= CopyTextureSubImage2DAndCheckErrors(m_to_dst, 0, 0, 0, 0, 0, s_texture_width / 2, s_texture_height / 2);
5388         result &= CopyTextureSubImage2DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, 0, s_texture_width / 2, 0,
5389                                                                                                   s_texture_width / 2, s_texture_height / 2);
5390         result &= CopyTextureSubImage2DAndCheckErrors(m_to_dst, 0, 0, s_texture_height / 2, 0, s_texture_height / 2,
5391                                                                                                   s_texture_width / 2, s_texture_height / 2);
5392         result &=
5393                 CopyTextureSubImage2DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, s_texture_height / 2, s_texture_width / 2,
5394                                                                                         s_texture_height / 2, s_texture_width / 2, s_texture_height / 2);
5395
5396         result &= CheckData(TextureTarget<2>(), 4 /* RGBA */ * s_texture_width * s_texture_height);
5397
5398         CleanAll();
5399
5400         return result;
5401 }
5402
5403 /** @brief Test function */
5404 template <>
5405 bool CopyTest::Test<3>()
5406 {
5407         CreateAll<3>();
5408
5409         bool result = true;
5410
5411         for (glw::GLuint i = 0; i < s_texture_depth; ++i)
5412         {
5413                 result &=
5414                         CopyTextureSubImage3DAndCheckErrors(m_to_dst, 0, 0, 0, i, 0, 0, s_texture_width / 2, s_texture_height / 2);
5415                 result &= CopyTextureSubImage3DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, 0, i, s_texture_width / 2, 0,
5416                                                                                                           s_texture_width / 2, s_texture_height / 2);
5417                 result &= CopyTextureSubImage3DAndCheckErrors(m_to_dst, 0, 0, s_texture_height / 2, i, 0, s_texture_height / 2,
5418                                                                                                           s_texture_width / 2, s_texture_height / 2);
5419                 result &= CopyTextureSubImage3DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, s_texture_height / 2, i,
5420                                                                                                           s_texture_width / 2, s_texture_height / 2, s_texture_width / 2,
5421                                                                                                           s_texture_height / 2);
5422         }
5423
5424         result &= CheckData(TextureTarget<3>(), 4 /* RGBA */ * s_texture_width * s_texture_height * s_texture_depth);
5425
5426         CleanAll();
5427
5428         return result;
5429 }
5430
5431 /** @brief Compre results with the reference.
5432  *
5433  *  @param [in] target      Texture target.
5434  *  @param [in] size        Size of the buffer.
5435  *
5436  *  @return True if equal, false otherwise.
5437  */
5438 bool CopyTest::CheckData(glw::GLenum target, glw::GLuint size)
5439 {
5440         /* Shortcut for GL functionality. */
5441         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5442
5443         /* Check texture content with reference. */
5444         m_result = new glw::GLubyte[size];
5445
5446         if (DE_NULL == m_result)
5447         {
5448                 throw 0;
5449         }
5450
5451         gl.getTexImage(target, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_result);
5452         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
5453
5454         for (glw::GLuint i = 0; i < size; ++i)
5455         {
5456                 if (s_texture_data[i] != m_result[i])
5457                 {
5458                         m_context.getTestContext().getLog()
5459                                 << tcu::TestLog::Message << "glCopyTextureSubImage*D created texture with data "
5460                                 << DataToString(size, s_texture_data) << " however texture contains data "
5461                                 << DataToString(size, m_result) << ". Texture target was " << glu::getTextureTargetStr(target)
5462                                 << ". Test fails." << tcu::TestLog::EndMessage;
5463
5464                         return false;
5465                 }
5466         }
5467
5468         return true;
5469 }
5470
5471 /** @brief Convert raw data into string for logging purposes.
5472  *
5473  *  @param [in] count      Count of the data.
5474  *  @param [in] data       Raw data.
5475  *
5476  *  @return String representation of data.
5477  */
5478 std::string CopyTest::DataToString(glw::GLuint count, const glw::GLubyte data[])
5479 {
5480         std::string data_str = "[";
5481
5482         for (glw::GLuint i = 0; i < count; ++i)
5483         {
5484                 std::stringstream int_sstream;
5485
5486                 int_sstream << unsigned(data[i]);
5487
5488                 data_str.append(int_sstream.str());
5489
5490                 if (i + 1 < count)
5491                 {
5492                         data_str.append(", ");
5493                 }
5494                 else
5495                 {
5496                         data_str.append("]");
5497                 }
5498         }
5499
5500         return data_str;
5501 }
5502
5503 /** @brief Clean GL objects, test variables and GL errors.
5504  */
5505 void CopyTest::CleanAll()
5506 {
5507         /* Shortcut for GL functionality. */
5508         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5509
5510         if (m_fbo)
5511         {
5512                 gl.deleteFramebuffers(1, &m_fbo);
5513
5514                 m_fbo = 0;
5515         }
5516
5517         if (m_to_src)
5518         {
5519                 gl.deleteTextures(1, &m_to_src);
5520
5521                 m_to_src = 0;
5522         }
5523
5524         if (m_to_dst)
5525         {
5526                 gl.deleteTextures(1, &m_to_dst);
5527
5528                 m_to_dst = 0;
5529         }
5530
5531         if (DE_NULL == m_result)
5532         {
5533                 delete[] m_result;
5534
5535                 m_result = DE_NULL;
5536         }
5537
5538         while (GL_NO_ERROR != gl.getError())
5539                 ;
5540 }
5541
5542 /** @brief Iterate Copy Test cases.
5543  *
5544  *  @return Iteration result.
5545  */
5546 tcu::TestNode::IterateResult CopyTest::iterate()
5547 {
5548         /* Get context setup. */
5549         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
5550         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
5551
5552         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
5553         {
5554                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
5555
5556                 return STOP;
5557         }
5558
5559         /* Running tests. */
5560         bool is_ok      = true;
5561         bool is_error = false;
5562
5563         try
5564         {
5565                 is_ok &= Test<1>();
5566                 is_ok &= Test<2>();
5567                 is_ok &= Test<3>();
5568         }
5569         catch (...)
5570         {
5571                 is_ok   = false;
5572                 is_error = true;
5573         }
5574
5575         /* Cleanup. */
5576         CleanAll();
5577
5578         /* Result's setup. */
5579         if (is_ok)
5580         {
5581                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
5582         }
5583         else
5584         {
5585                 if (is_error)
5586                 {
5587                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
5588                 }
5589                 else
5590                 {
5591                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
5592                 }
5593         }
5594
5595         return STOP;
5596 }
5597
5598 /** Reference data. */
5599 const glw::GLubyte CopyTest::s_texture_data[] = {
5600         0x00, 0x00, 0x00, 0xFF, 0x7f, 0x7f, 0x7f, 0x00, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0x00,
5601         0x88, 0x00, 0x15, 0xFF, 0xed, 0x1c, 0x24, 0x00, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x00, 0x00,
5602         0xc8, 0xbf, 0xe7, 0xFF, 0x70, 0x92, 0xbe, 0x00, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0x00,
5603         0xa3, 0x49, 0xa4, 0xFF, 0x3f, 0x48, 0xcc, 0x00, 0x00, 0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0x00,
5604
5605         0xa3, 0x49, 0xa4, 0xFF, 0xc8, 0xbf, 0xe7, 0x00, 0x88, 0x00, 0x15, 0xff, 0x00, 0x00, 0x00, 0x00,
5606         0x3f, 0x48, 0xcc, 0xFF, 0x70, 0x92, 0xbe, 0x00, 0xed, 0x1c, 0x24, 0xff, 0x7f, 0x7f, 0x7f, 0x00,
5607         0x00, 0xa2, 0xe8, 0xFF, 0x99, 0xd9, 0xea, 0x00, 0xff, 0x7f, 0x27, 0xff, 0xc3, 0xc3, 0xc3, 0x00,
5608         0x22, 0xb1, 0x4c, 0xFF, 0xb5, 0xe6, 0x1d, 0x00, 0xff, 0xf2, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00,
5609
5610         0x22, 0xb1, 0x4c, 0xFF, 0x00, 0xa2, 0xe8, 0x00, 0x3f, 0x48, 0xcc, 0xff, 0xa3, 0x49, 0xa4, 0x00,
5611         0xb5, 0xe6, 0x1d, 0xFF, 0x99, 0xd9, 0xea, 0x00, 0x70, 0x92, 0xbe, 0xff, 0xc8, 0xbf, 0xe7, 0x00,
5612         0xff, 0xf2, 0x00, 0xFF, 0xff, 0x7f, 0x27, 0x00, 0xed, 0x1c, 0x24, 0xff, 0x88, 0x00, 0x15, 0x00,
5613         0xff, 0xff, 0xff, 0xFF, 0xc3, 0xc3, 0xc3, 0x00, 0x7f, 0x7f, 0x7f, 0xff, 0x00, 0x00, 0x00, 0x00,
5614
5615         0xff, 0xff, 0xff, 0xFF, 0xff, 0xf2, 0x00, 0x00, 0xb5, 0xe6, 0x1d, 0xff, 0x22, 0xb1, 0x4c, 0x00,
5616         0xc3, 0xc3, 0xc3, 0xFF, 0xff, 0x7f, 0x27, 0x00, 0x99, 0xd9, 0xea, 0xff, 0x00, 0xa2, 0xe8, 0x00,
5617         0x7f, 0x7f, 0x7f, 0xFF, 0xed, 0x1c, 0x24, 0x00, 0x70, 0x92, 0xbe, 0xff, 0x3f, 0x48, 0xcc, 0x00,
5618         0x00, 0x00, 0x00, 0xFF, 0x88, 0x00, 0x15, 0x00, 0xc8, 0xbf, 0xe7, 0xff, 0xa3, 0x49, 0xa4, 0x00
5619 };
5620
5621 /** Reference data parameters. */
5622 const glw::GLuint CopyTest::s_texture_width  = 4;
5623 const glw::GLuint CopyTest::s_texture_height = 4;
5624 const glw::GLuint CopyTest::s_texture_depth  = 4;
5625
5626 /******************************** Get Set Parameter Test Implementation   ********************************/
5627
5628 /** @brief Get Set Parameter Test constructor.
5629  *
5630  *  @param [in] context     OpenGL context.
5631  */
5632 GetSetParameterTest::GetSetParameterTest(deqp::Context& context)
5633         : deqp::TestCase(context, "textures_get_set_parameter", "Texture Get Set Parameter Test")
5634 {
5635         /* Intentionally left blank. */
5636 }
5637
5638 /** @brief Iterate Get Set Parameter Test cases.
5639  *
5640  *  @return Iteration result.
5641  */
5642 tcu::TestNode::IterateResult GetSetParameterTest::iterate()
5643 {
5644         /* Shortcut for GL functionality. */
5645         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5646
5647         /* Get context setup. */
5648         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
5649         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
5650
5651         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
5652         {
5653                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
5654
5655                 return STOP;
5656         }
5657
5658         /* Running tests. */
5659         bool is_ok      = true;
5660         bool is_error = false;
5661
5662         /* Texture. */
5663         glw::GLuint texture = 0;
5664
5665         try
5666         {
5667                 gl.genTextures(1, &texture);
5668                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
5669
5670                 gl.bindTexture(GL_TEXTURE_3D, texture);
5671                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
5672
5673                 {
5674                         glw::GLenum name          = GL_DEPTH_STENCIL_TEXTURE_MODE;
5675                         glw::GLint  value_src = GL_DEPTH_COMPONENT;
5676                         glw::GLint  value_dst = 0;
5677
5678                         gl.textureParameteri(texture, name, value_src);
5679                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5680
5681                         gl.getTextureParameteriv(texture, name, &value_dst);
5682                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5683
5684                         is_ok &= CompareAndLog(value_src, value_dst, name);
5685                 }
5686
5687                 {
5688                         glw::GLenum name          = GL_TEXTURE_BASE_LEVEL;
5689                         glw::GLint  value_src = 2;
5690                         glw::GLint  value_dst = 0;
5691
5692                         gl.textureParameteri(texture, name, value_src);
5693                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5694
5695                         gl.getTextureParameteriv(texture, name, &value_dst);
5696                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5697
5698                         is_ok &= CompareAndLog(value_src, value_dst, name);
5699                 }
5700
5701                 {
5702                         glw::GLenum  name                 = GL_TEXTURE_BORDER_COLOR;
5703                         glw::GLfloat value_src[4] = { 0.25, 0.5, 0.75, 1.0 };
5704                         glw::GLfloat value_dst[4] = {};
5705
5706                         gl.textureParameterfv(texture, name, value_src);
5707                         is_ok &= CheckErrorAndLog("glTextureParameterfv", name);
5708
5709                         gl.getTextureParameterfv(texture, name, value_dst);
5710                         is_ok &= CheckErrorAndLog("glGetTextureParameterfv", name);
5711
5712                         is_ok &= CompareAndLog(value_src, value_dst, name);
5713                 }
5714
5715                 {
5716                         glw::GLenum name                 = GL_TEXTURE_BORDER_COLOR;
5717                         glw::GLint  value_src[4] = { 0, 64, -64, -32 };
5718                         glw::GLint  value_dst[4] = {};
5719
5720                         gl.textureParameterIiv(texture, name, value_src);
5721                         is_ok &= CheckErrorAndLog("glTextureParameterIiv", name);
5722
5723                         gl.getTextureParameterIiv(texture, name, value_dst);
5724                         is_ok &= CheckErrorAndLog("glGetTextureParameterIiv", name);
5725
5726                         is_ok &= CompareAndLog(value_src, value_dst, name);
5727                 }
5728
5729                 {
5730                         glw::GLenum name                 = GL_TEXTURE_BORDER_COLOR;
5731                         glw::GLuint value_src[4] = { 0, 64, 128, 192 };
5732                         glw::GLuint value_dst[4] = {};
5733
5734                         gl.textureParameterIuiv(texture, name, value_src);
5735                         is_ok &= CheckErrorAndLog("glTextureParameterIuiv", name);
5736
5737                         gl.getTextureParameterIuiv(texture, name, value_dst);
5738                         is_ok &= CheckErrorAndLog("glGetTextureParameterIuiv", name);
5739
5740                         is_ok &= CompareAndLog(value_src, value_dst, name);
5741                 }
5742
5743                 {
5744                         glw::GLenum name          = GL_TEXTURE_COMPARE_FUNC;
5745                         glw::GLint  value_src = GL_LEQUAL;
5746                         glw::GLint  value_dst = 0;
5747
5748                         gl.textureParameteri(texture, name, value_src);
5749                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5750
5751                         gl.getTextureParameteriv(texture, name, &value_dst);
5752                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5753
5754                         is_ok &= CompareAndLog(value_src, value_dst, name);
5755                 }
5756
5757                 {
5758                         glw::GLenum name          = GL_TEXTURE_COMPARE_MODE;
5759                         glw::GLint  value_src = GL_COMPARE_REF_TO_TEXTURE;
5760                         glw::GLint  value_dst = 0;
5761
5762                         gl.textureParameteri(texture, name, value_src);
5763                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5764
5765                         gl.getTextureParameteriv(texture, name, &value_dst);
5766                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5767
5768                         is_ok &= CompareAndLog(value_src, value_dst, name);
5769                 }
5770
5771                 {
5772                         glw::GLenum  name         = GL_TEXTURE_LOD_BIAS;
5773                         glw::GLfloat value_src = -2.f;
5774                         glw::GLfloat value_dst = 0.f;
5775
5776                         gl.textureParameterf(texture, name, value_src);
5777                         is_ok &= CheckErrorAndLog("glTextureParameterf", name);
5778
5779                         gl.getTextureParameterfv(texture, name, &value_dst);
5780                         is_ok &= CheckErrorAndLog("glGetTextureParameterfv", name);
5781
5782                         is_ok &= CompareAndLog(value_src, value_dst, name);
5783                 }
5784
5785                 {
5786                         glw::GLenum name          = GL_TEXTURE_MIN_FILTER;
5787                         glw::GLint  value_src = GL_LINEAR_MIPMAP_NEAREST;
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_MAG_FILTER;
5801                         glw::GLint  value_src = GL_NEAREST;
5802                         glw::GLint  value_dst = 0;
5803
5804                         gl.textureParameteri(texture, name, value_src);
5805                         is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5806
5807                         gl.getTextureParameteriv(texture, name, &value_dst);
5808                         is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5809
5810                         is_ok &= CompareAndLog(value_src, value_dst, name);
5811                 }
5812
5813                 {
5814                         glw::GLenum name          = GL_TEXTURE_MIN_LOD;
5815                         glw::GLint  value_src = -100;
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_MAX_LOD;
5829                         glw::GLint  value_src = 100;
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_MAX_LEVEL;
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_SWIZZLE_R;
5857                         glw::GLint  value_src = GL_BLUE;
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_SWIZZLE_G;
5871                         glw::GLint  value_src = GL_ALPHA;
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_B;
5885                         glw::GLint  value_src = GL_RED;
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_A;
5899                         glw::GLint  value_src = GL_GREEN;
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_RGBA;
5913                         glw::GLint  value_src[4] = { GL_ZERO, GL_ONE, GL_ZERO, GL_ONE };
5914                         glw::GLint  value_dst[4] = {};
5915
5916                         gl.textureParameteriv(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_WRAP_S;
5927                         glw::GLint  value_src = GL_MIRROR_CLAMP_TO_EDGE;
5928                         glw::GLint  value_dst = 11;
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_WRAP_T;
5941                         glw::GLint  value_src = GL_CLAMP_TO_EDGE;
5942                         glw::GLint  value_dst = 11;
5943
5944                         gl.textureParameteri(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_R;
5955                         glw::GLint  value_src = GL_CLAMP_TO_EDGE;
5956                         glw::GLint  value_dst = 11;
5957
5958                         gl.textureParameteriv(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         catch (...)
5968         {
5969                 is_ok   = false;
5970                 is_error = true;
5971         }
5972
5973         /* Cleanup. */
5974         if (texture)
5975         {
5976                 gl.deleteTextures(1, &texture);
5977         }
5978
5979         while (GL_NO_ERROR != gl.getError())
5980                 ;
5981
5982         /* Result's setup. */
5983         if (is_ok)
5984         {
5985                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
5986         }
5987         else
5988         {
5989                 if (is_error)
5990                 {
5991                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
5992                 }
5993                 else
5994                 {
5995                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
5996                 }
5997         }
5998
5999         return STOP;
6000 }
6001
6002 /** @brief Check for errors and log.
6003  *
6004  *  @param [in] fname     Name of the function (to be logged).
6005  *  @param [in] pname     Parameter name with which function was called.
6006  *
6007  *  @return True if no error, false otherwise.
6008  */
6009 bool GetSetParameterTest::CheckErrorAndLog(const glw::GLchar* fname, glw::GLenum pname)
6010 {
6011         /* Shortcut for GL functionality. */
6012         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
6013
6014         /* Check errors. */
6015         glw::GLenum error;
6016
6017         if (GL_NO_ERROR != (error = gl.getError()))
6018         {
6019                 m_context.getTestContext().getLog() << tcu::TestLog::Message << fname << " unexpectedly generated error "
6020                                                                                         << glu::getErrorStr(error) << " during test of pname "
6021                                                                                         << glu::getTextureParameterStr(pname) << ". Test fails."
6022                                                                                         << tcu::TestLog::EndMessage;
6023
6024                 return false;
6025         }
6026
6027         return true;
6028 }
6029
6030 /** @brief Compare queried value of parameter with the expected vale.
6031  *
6032  *  @param [in] value_src           First value.
6033  *  @param [in] value_dst           Second value.
6034  *  @param [in] pname               Parameter name.
6035  *
6036  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6037  */
6038 bool GetSetParameterTest::CompareAndLog(glw::GLint value_src, glw::GLint value_dst, glw::GLenum pname)
6039 {
6040         if (value_src != value_dst)
6041         {
6042                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Queried value of pname "
6043                                                                                         << glu::getTextureParameterStr(pname) << " is equal to " << value_dst
6044                                                                                         << ", however " << value_src << " was expected. Test fails."
6045                                                                                         << tcu::TestLog::EndMessage;
6046
6047                 return false;
6048         }
6049
6050         return true;
6051 }
6052
6053 /** @brief Compare queried value of parameter with the expected vale.
6054  *
6055  *  @param [in] value_src           First value.
6056  *  @param [in] value_dst           Second value.
6057  *  @param [in] pname               Parameter name.
6058  *
6059  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6060  */
6061 bool GetSetParameterTest::CompareAndLog(glw::GLuint value_src, glw::GLuint value_dst, glw::GLenum pname)
6062 {
6063         if (value_src != value_dst)
6064         {
6065                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Queried value of pname "
6066                                                                                         << glu::getTextureParameterStr(pname) << " is equal to " << value_dst
6067                                                                                         << ", however " << value_src << " was expected. Test fails."
6068                                                                                         << tcu::TestLog::EndMessage;
6069
6070                 return false;
6071         }
6072
6073         return true;
6074 }
6075
6076 /** @brief Compare queried value of parameter with the expected vale.
6077  *
6078  *  @param [in] value_src           First value.
6079  *  @param [in] value_dst           Second value.
6080  *  @param [in] pname               Parameter name.
6081  *
6082  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6083  */
6084 bool GetSetParameterTest::CompareAndLog(glw::GLfloat value_src, glw::GLfloat value_dst, glw::GLenum pname)
6085 {
6086         if (de::abs(value_src - value_dst) > 0.0125 /* Precision */)
6087         {
6088                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Queried value of pname "
6089                                                                                         << glu::getTextureParameterStr(pname) << " is equal to " << value_dst
6090                                                                                         << ", however " << value_src << " was expected. Test fails."
6091                                                                                         << tcu::TestLog::EndMessage;
6092
6093                 return false;
6094         }
6095
6096         return true;
6097 }
6098
6099 /** @brief Compare queried value of parameter with the expected vale.
6100  *
6101  *  @param [in] value_src           First value.
6102  *  @param [in] value_dst           Second value.
6103  *  @param [in] pname               Parameter name.
6104  *
6105  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6106  */
6107 bool GetSetParameterTest::CompareAndLog(glw::GLint value_src[4], glw::GLint value_dst[4], glw::GLenum pname)
6108 {
6109         if ((value_src[0] != value_dst[0]) || (value_src[1] != value_dst[1]) || (value_src[2] != value_dst[2]) ||
6110                 (value_src[3] != value_dst[3]))
6111         {
6112                 m_context.getTestContext().getLog()
6113                         << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6114                         << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3]
6115                         << "], however " << value_src[0] << ", " << value_src[1] << ", " << value_src[2] << ", " << value_src[3]
6116                         << "] was expected. Test fails." << tcu::TestLog::EndMessage;
6117
6118                 return false;
6119         }
6120
6121         return true;
6122 }
6123
6124 /** @brief Compare queried value of parameter with the expected vale.
6125  *
6126  *  @param [in] value_src           First value.
6127  *  @param [in] value_dst           Second value.
6128  *  @param [in] pname               Parameter name.
6129  *
6130  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6131  */
6132 bool GetSetParameterTest::CompareAndLog(glw::GLuint value_src[4], glw::GLuint value_dst[4], glw::GLenum pname)
6133 {
6134         if ((value_src[0] != value_dst[0]) || (value_src[1] != value_dst[1]) || (value_src[2] != value_dst[2]) ||
6135                 (value_src[3] != value_dst[3]))
6136         {
6137                 m_context.getTestContext().getLog()
6138                         << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6139                         << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3]
6140                         << "], however " << value_src[0] << ", " << value_src[1] << ", " << value_src[2] << ", " << value_src[3]
6141                         << "] was expected. Test fails." << tcu::TestLog::EndMessage;
6142
6143                 return false;
6144         }
6145
6146         return true;
6147 }
6148
6149 /** @brief Compare queried value of parameter with the expected vale.
6150  *
6151  *  @param [in] value_src           First value.
6152  *  @param [in] value_dst           Second value.
6153  *  @param [in] pname               Parameter name.
6154  *
6155  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6156  */
6157 bool GetSetParameterTest::CompareAndLog(glw::GLfloat value_src[4], glw::GLfloat value_dst[4], glw::GLenum pname)
6158 {
6159         if ((de::abs(value_src[0] - value_dst[0]) > 0.0125 /* Precision */) ||
6160                 (de::abs(value_src[1] - value_dst[1]) > 0.0125 /* Precision */) ||
6161                 (de::abs(value_src[2] - value_dst[2]) > 0.0125 /* Precision */) ||
6162                 (de::abs(value_src[3] - value_dst[3]) > 0.0125 /* Precision */))
6163         {
6164                 m_context.getTestContext().getLog()
6165                         << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6166                         << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3]
6167                         << "], however " << value_src[0] << ", " << value_src[1] << ", " << value_src[2] << ", " << value_src[3]
6168                         << "] was expected. Test fails." << tcu::TestLog::EndMessage;
6169
6170                 return false;
6171         }
6172
6173         return true;
6174 }
6175
6176 /******************************** Defaults Test Implementation   ********************************/
6177
6178 /** @brief Defaults Test constructor.
6179  *
6180  *  @param [in] context     OpenGL context.
6181  */
6182 DefaultsTest::DefaultsTest(deqp::Context& context)
6183         : deqp::TestCase(context, "textures_defaults", "Texture Defaults Test")
6184 {
6185         /* Intentionally left blank. */
6186 }
6187
6188 /** @brief Defaults Test cases.
6189  *
6190  *  @return Iteration result.
6191  */
6192 tcu::TestNode::IterateResult DefaultsTest::iterate()
6193 {
6194         /* Shortcut for GL functionality. */
6195         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
6196
6197         /* Get context setup. */
6198         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
6199         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
6200
6201         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
6202         {
6203                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
6204
6205                 return STOP;
6206         }
6207
6208         /* Running tests. */
6209         bool is_ok      = true;
6210         bool is_error = false;
6211
6212         /* Texture. */
6213         glw::GLuint texture = 0;
6214
6215         try
6216         {
6217                 gl.createTextures(GL_TEXTURE_3D, 1, &texture);
6218                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
6219
6220                 {
6221                         glw::GLenum name          = GL_DEPTH_STENCIL_TEXTURE_MODE;
6222                         glw::GLint  value_ref = GL_DEPTH_COMPONENT;
6223                         glw::GLint  value_dst = 0;
6224
6225                         gl.getTextureParameteriv(texture, name, &value_dst);
6226                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6227
6228                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6229                 }
6230
6231                 {
6232                         glw::GLenum name          = GL_TEXTURE_BASE_LEVEL;
6233                         glw::GLint  value_ref = 0;
6234                         glw::GLint  value_dst = 1;
6235
6236                         gl.getTextureParameteriv(texture, name, &value_dst);
6237                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6238
6239                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6240                 }
6241
6242                 {
6243                         glw::GLenum  name                 = GL_TEXTURE_BORDER_COLOR;
6244                         glw::GLfloat value_ref[4] = { 0.f, 0.f, 0.f, 0.f };
6245                         glw::GLfloat value_dst[4] = {};
6246
6247                         gl.getTextureParameterfv(texture, name, value_dst);
6248                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6249
6250                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6251                 }
6252
6253                 {
6254                         glw::GLenum name          = GL_TEXTURE_COMPARE_FUNC;
6255                         glw::GLint  value_ref = GL_LEQUAL;
6256                         glw::GLint  value_dst = 0;
6257
6258                         gl.getTextureParameteriv(texture, name, &value_dst);
6259                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6260
6261                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6262                 }
6263
6264                 {
6265                         glw::GLenum name          = GL_TEXTURE_COMPARE_MODE;
6266                         glw::GLint  value_ref = GL_NONE;
6267                         glw::GLint  value_dst = 0;
6268
6269                         gl.getTextureParameteriv(texture, name, &value_dst);
6270                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6271
6272                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6273                 }
6274
6275                 {
6276                         glw::GLenum  name         = GL_TEXTURE_LOD_BIAS;
6277                         glw::GLfloat value_ref = 0.f;
6278                         glw::GLfloat value_dst = 0.f;
6279
6280                         gl.getTextureParameterfv(texture, name, &value_dst);
6281                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6282
6283                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6284                 }
6285
6286                 {
6287                         glw::GLenum name          = GL_TEXTURE_MIN_FILTER;
6288                         glw::GLint  value_ref = GL_NEAREST_MIPMAP_LINEAR;
6289                         glw::GLint  value_dst = 0;
6290
6291                         gl.getTextureParameteriv(texture, name, &value_dst);
6292                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6293
6294                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6295                 }
6296
6297                 {
6298                         glw::GLenum name          = GL_TEXTURE_MAG_FILTER;
6299                         glw::GLint  value_ref = GL_LINEAR;
6300                         glw::GLint  value_dst = 0;
6301
6302                         gl.getTextureParameteriv(texture, name, &value_dst);
6303                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6304
6305                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6306                 }
6307
6308                 {
6309                         glw::GLenum name          = GL_TEXTURE_MIN_LOD;
6310                         glw::GLint  value_ref = -1000;
6311                         glw::GLint  value_dst = 0;
6312
6313                         gl.getTextureParameteriv(texture, name, &value_dst);
6314                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6315
6316                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6317                 }
6318
6319                 {
6320                         glw::GLenum name          = GL_TEXTURE_MAX_LOD;
6321                         glw::GLint  value_ref = 1000;
6322                         glw::GLint  value_dst = 0;
6323
6324                         gl.getTextureParameteriv(texture, name, &value_dst);
6325                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6326
6327                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6328                 }
6329
6330                 {
6331                         glw::GLenum name          = GL_TEXTURE_MAX_LEVEL;
6332                         glw::GLint  value_ref = 1000;
6333                         glw::GLint  value_dst = 0;
6334
6335                         gl.getTextureParameteriv(texture, name, &value_dst);
6336                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6337
6338                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6339                 }
6340
6341                 {
6342                         glw::GLenum name          = GL_TEXTURE_SWIZZLE_R;
6343                         glw::GLint  value_ref = GL_RED;
6344                         glw::GLint  value_dst = 0;
6345
6346                         gl.getTextureParameteriv(texture, name, &value_dst);
6347                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6348
6349                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6350                 }
6351
6352                 {
6353                         glw::GLenum name          = GL_TEXTURE_SWIZZLE_G;
6354                         glw::GLint  value_ref = GL_GREEN;
6355                         glw::GLint  value_dst = 0;
6356
6357                         gl.getTextureParameteriv(texture, name, &value_dst);
6358                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6359
6360                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6361                 }
6362
6363                 {
6364                         glw::GLenum name          = GL_TEXTURE_SWIZZLE_B;
6365                         glw::GLint  value_ref = GL_BLUE;
6366                         glw::GLint  value_dst = 0;
6367
6368                         gl.getTextureParameteriv(texture, name, &value_dst);
6369                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6370
6371                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6372                 }
6373
6374                 {
6375                         glw::GLenum name          = GL_TEXTURE_SWIZZLE_A;
6376                         glw::GLint  value_ref = GL_ALPHA;
6377                         glw::GLint  value_dst = 0;
6378
6379                         gl.getTextureParameteriv(texture, name, &value_dst);
6380                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6381
6382                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6383                 }
6384
6385                 {
6386                         glw::GLenum name          = GL_TEXTURE_WRAP_S;
6387                         glw::GLint  value_ref = GL_REPEAT;
6388                         glw::GLint  value_dst = 11;
6389
6390                         gl.getTextureParameteriv(texture, name, &value_dst);
6391                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6392
6393                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6394                 }
6395
6396                 {
6397                         glw::GLenum name          = GL_TEXTURE_WRAP_T;
6398                         glw::GLint  value_ref = GL_REPEAT;
6399                         glw::GLint  value_dst = 11;
6400
6401                         gl.getTextureParameteriv(texture, name, &value_dst);
6402                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6403
6404                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6405                 }
6406
6407                 {
6408                         glw::GLenum name          = GL_TEXTURE_WRAP_R;
6409                         glw::GLint  value_ref = GL_REPEAT;
6410                         glw::GLint  value_dst = 11;
6411
6412                         gl.getTextureParameteriv(texture, name, &value_dst);
6413                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6414
6415                         is_ok &= CompareAndLog(value_ref, value_dst, name);
6416                 }
6417         }
6418         catch (...)
6419         {
6420                 is_ok   = false;
6421                 is_error = true;
6422         }
6423
6424         /* Cleanup. */
6425         if (texture)
6426         {
6427                 gl.deleteTextures(1, &texture);
6428         }
6429
6430         while (GL_NO_ERROR != gl.getError())
6431                 ;
6432
6433         /* Result's setup. */
6434         if (is_ok)
6435         {
6436                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
6437         }
6438         else
6439         {
6440                 if (is_error)
6441                 {
6442                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
6443                 }
6444                 else
6445                 {
6446                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
6447                 }
6448         }
6449
6450         return STOP;
6451 }
6452
6453 /** @brief Compare queried value of parameter with the expected vale.
6454  *
6455  *  @param [in] value_src           First value.
6456  *  @param [in] value_dst           Second value.
6457  *  @param [in] pname               Parameter name.
6458  *
6459  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6460  */
6461 bool DefaultsTest::CompareAndLog(glw::GLint value_ref, glw::GLint value_dst, glw::GLenum pname)
6462 {
6463         if (value_ref != value_dst)
6464         {
6465                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Queried value of pname "
6466                                                                                         << glu::getTextureParameterStr(pname) << " is equal to " << value_dst
6467                                                                                         << ", however " << value_ref << " was expected. Test fails."
6468                                                                                         << tcu::TestLog::EndMessage;
6469
6470                 return false;
6471         }
6472
6473         return true;
6474 }
6475
6476 /** @brief Compare queried value of parameter with the expected vale.
6477  *
6478  *  @param [in] value_src           First value.
6479  *  @param [in] value_dst           Second value.
6480  *  @param [in] pname               Parameter name.
6481  *
6482  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6483  */
6484 bool DefaultsTest::CompareAndLog(glw::GLuint value_ref, glw::GLuint value_dst, glw::GLenum pname)
6485 {
6486         if (value_ref != value_dst)
6487         {
6488                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Queried value of pname "
6489                                                                                         << glu::getTextureParameterStr(pname) << " is equal to " << value_dst
6490                                                                                         << ", however " << value_ref << " was expected. Test fails."
6491                                                                                         << tcu::TestLog::EndMessage;
6492
6493                 return false;
6494         }
6495
6496         return true;
6497 }
6498
6499 /** @brief Compare queried value of parameter with the expected vale.
6500  *
6501  *  @param [in] value_src           First value.
6502  *  @param [in] value_dst           Second value.
6503  *  @param [in] pname               Parameter name.
6504  *
6505  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6506  */
6507 bool DefaultsTest::CompareAndLog(glw::GLfloat value_ref, glw::GLfloat value_dst, glw::GLenum pname)
6508 {
6509         if (de::abs(value_ref - value_dst) > 0.0125 /* Precision */)
6510         {
6511                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Queried value of pname "
6512                                                                                         << glu::getTextureParameterStr(pname) << " is equal to " << value_dst
6513                                                                                         << ", however " << value_ref << " was expected. Test fails."
6514                                                                                         << tcu::TestLog::EndMessage;
6515
6516                 return false;
6517         }
6518
6519         return true;
6520 }
6521
6522 /** @brief Compare queried value of parameter with the expected vale.
6523  *
6524  *  @param [in] value_src           First value.
6525  *  @param [in] value_dst           Second value.
6526  *  @param [in] pname               Parameter name.
6527  *
6528  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6529  */
6530 bool DefaultsTest::CompareAndLog(glw::GLint value_ref[4], glw::GLint value_dst[4], glw::GLenum pname)
6531 {
6532         if ((value_ref[0] != value_dst[0]) || (value_ref[1] != value_dst[1]) || (value_ref[2] != value_dst[2]) ||
6533                 (value_ref[3] != value_dst[3]))
6534         {
6535                 m_context.getTestContext().getLog()
6536                         << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6537                         << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3]
6538                         << "], however " << value_ref[0] << ", " << value_ref[1] << ", " << value_ref[2] << ", " << value_ref[3]
6539                         << "] was expected. Test fails." << tcu::TestLog::EndMessage;
6540
6541                 return false;
6542         }
6543
6544         return true;
6545 }
6546
6547 /** @brief Compare queried value of parameter with the expected vale.
6548  *
6549  *  @param [in] value_src           First value.
6550  *  @param [in] value_dst           Second value.
6551  *  @param [in] pname               Parameter name.
6552  *
6553  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6554  */
6555 bool DefaultsTest::CompareAndLog(glw::GLuint value_ref[4], glw::GLuint value_dst[4], glw::GLenum pname)
6556 {
6557         if ((value_ref[0] != value_dst[0]) || (value_ref[1] != value_dst[1]) || (value_ref[2] != value_dst[2]) ||
6558                 (value_ref[3] != value_dst[3]))
6559         {
6560                 m_context.getTestContext().getLog()
6561                         << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6562                         << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3]
6563                         << "], however " << value_ref[0] << ", " << value_ref[1] << ", " << value_ref[2] << ", " << value_ref[3]
6564                         << "] was expected. Test fails." << tcu::TestLog::EndMessage;
6565
6566                 return false;
6567         }
6568
6569         return true;
6570 }
6571
6572 /** @brief Compare queried value of parameter with the expected vale.
6573  *
6574  *  @param [in] value_src           First value.
6575  *  @param [in] value_dst           Second value.
6576  *  @param [in] pname               Parameter name.
6577  *
6578  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6579  */
6580 bool DefaultsTest::CompareAndLog(glw::GLfloat value_ref[4], glw::GLfloat value_dst[4], glw::GLenum pname)
6581 {
6582         if ((de::abs(value_ref[0] - value_dst[0]) > 0.0125 /* Precision */) ||
6583                 (de::abs(value_ref[1] - value_dst[1]) > 0.0125 /* Precision */) ||
6584                 (de::abs(value_ref[2] - value_dst[2]) > 0.0125 /* Precision */) ||
6585                 (de::abs(value_ref[3] - value_dst[3]) > 0.0125 /* Precision */))
6586         {
6587                 m_context.getTestContext().getLog()
6588                         << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6589                         << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3]
6590                         << "], however " << value_ref[0] << ", " << value_ref[1] << ", " << value_ref[2] << ", " << value_ref[3]
6591                         << "] was expected. Test fails." << tcu::TestLog::EndMessage;
6592
6593                 return false;
6594         }
6595
6596         return true;
6597 }
6598
6599 /******************************** Generate Mipmap Test Implementation   ********************************/
6600
6601 /** @brief Generate Mipmap Test constructor.
6602  *
6603  *  @param [in] context     OpenGL context.
6604  */
6605 GenerateMipmapTest::GenerateMipmapTest(deqp::Context& context)
6606         : deqp::TestCase(context, "textures_generate_mipmaps", "Textures Generate Mipmap Test")
6607 {
6608         /* Intentionally left blank. */
6609 }
6610
6611 /** @brief Generate Mipmap Test cases.
6612  *
6613  *  @return Iteration result.
6614  */
6615 tcu::TestNode::IterateResult GenerateMipmapTest::iterate()
6616 {
6617         /* Shortcut for GL functionality. */
6618         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
6619
6620         /* Get context setup. */
6621         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
6622         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
6623
6624         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
6625         {
6626                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
6627
6628                 return STOP;
6629         }
6630
6631         /* Running tests. */
6632         bool is_ok      = true;
6633         bool is_error = false;
6634
6635         /* Texture and cpu results storage. */
6636         glw::GLuint   texture = 0;
6637         glw::GLubyte* result  = DE_NULL;
6638
6639         try
6640         {
6641                 /* Prepare texture. */
6642                 gl.genTextures(1, &texture);
6643                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
6644
6645                 gl.bindTexture(GL_TEXTURE_1D, texture);
6646                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
6647
6648                 gl.texImage1D(GL_TEXTURE_1D, 0, GL_R8, s_texture_width, 0, GL_RED, GL_UNSIGNED_BYTE, s_texture_data);
6649                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
6650
6651                 /* Generate mipmaps with tested function. */
6652                 gl.generateTextureMipmap(texture);
6653
6654                 glw::GLenum error = GL_NO_ERROR;
6655
6656                 if (GL_NO_ERROR != (error = gl.getError()))
6657                 {
6658                         m_context.getTestContext().getLog()
6659                                 << tcu::TestLog::Message << "GenerateTextureMipmap unexpectedly generated error "
6660                                 << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
6661
6662                         is_ok = false;
6663                 }
6664
6665                 /* Continue only if mipmaps has been generated. */
6666                 if (is_ok)
6667                 {
6668                         result = new glw::GLubyte[s_texture_width];
6669
6670                         if (DE_NULL == result)
6671                         {
6672                                 throw 0;
6673                         }
6674
6675                         /* For each mipmap. */
6676                         for (glw::GLuint i = 0, j = s_texture_width;
6677                                  i < s_texture_width_log - 1 /* Do not test single pixel mipmap. */; ++i, j /= 2)
6678                         {
6679                                 /* Check mipmap size. */
6680                                 glw::GLint mipmap_size = 0;
6681
6682                                 gl.getTexLevelParameteriv(GL_TEXTURE_1D, i, GL_TEXTURE_WIDTH, &mipmap_size);
6683                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
6684
6685                                 if (mipmap_size != (glw::GLint)j)
6686                                 {
6687                                         m_context.getTestContext().getLog()
6688                                                 << tcu::TestLog::Message
6689                                                 << "GenerateTextureMipmap unexpectedly generated mipmap with improper size. Mipmap size is "
6690                                                 << mipmap_size << ", but " << j << " was expected. Test fails." << tcu::TestLog::EndMessage;
6691
6692                                         is_ok = false;
6693
6694                                         break;
6695                                 }
6696
6697                                 /* Fetch data. */
6698                                 gl.getTexImage(GL_TEXTURE_1D, i, GL_RED, GL_UNSIGNED_BYTE, result);
6699                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexImage has failed");
6700
6701                                 /* Make comparison. */
6702                                 for (glw::GLuint k = 0; k < j - 1; ++k)
6703                                 {
6704                                         if (((glw::GLint)result[k + 1]) - ((glw::GLint)result[k]) < 0)
6705                                         {
6706                                                 m_context.getTestContext().getLog() << tcu::TestLog::Message
6707                                                                                                                         << "GenerateTextureMipmap unexpectedly generated improper "
6708                                                                                                                            "mipmap (not descending). Test fails."
6709                                                                                                                         << tcu::TestLog::EndMessage;
6710
6711                                                 is_ok = false;
6712
6713                                                 break;
6714                                         }
6715                                 }
6716                         }
6717                 }
6718         }
6719         catch (...)
6720         {
6721                 is_ok   = false;
6722                 is_error = true;
6723         }
6724
6725         /* Cleanup. */
6726         if (texture)
6727         {
6728                 gl.deleteTextures(1, &texture);
6729         }
6730
6731         if (DE_NULL != result)
6732         {
6733                 delete[] result;
6734         }
6735
6736         while (GL_NO_ERROR != gl.getError())
6737                 ;
6738
6739         /* Result's setup. */
6740         if (is_ok)
6741         {
6742                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
6743         }
6744         else
6745         {
6746                 if (is_error)
6747                 {
6748                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
6749                 }
6750                 else
6751                 {
6752                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
6753                 }
6754         }
6755
6756         return STOP;
6757 }
6758
6759 /** Reference data. */
6760 const glw::GLubyte GenerateMipmapTest::s_texture_data[] = {
6761         0,   1,   2,   3,   4,   5,   6,   7,   8,   9,   10,  11,  12,  13,  14,  15,  16,  17,  18,  19,  20,  21,
6762         22,  23,  24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,
6763         44,  45,  46,  47,  48,  49,  50,  51,  52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,  63,  64,  65,
6764         66,  67,  68,  69,  70,  71,  72,  73,  74,  75,  76,  77,  78,  79,  80,  81,  82,  83,  84,  85,  86,  87,
6765         88,  89,  90,  91,  92,  93,  94,  95,  96,  97,  98,  99,  100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
6766         110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131,
6767         132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153,
6768         154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
6769         176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197,
6770         198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219,
6771         220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241,
6772         242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
6773 };
6774
6775 /** Reference data parameters. */
6776 const glw::GLuint GenerateMipmapTest::s_texture_width    = 256;
6777 const glw::GLuint GenerateMipmapTest::s_texture_width_log = 8;
6778
6779 /******************************** Bind Unit Test Implementation   ********************************/
6780
6781 /** @brief Bind Unit Test constructor.
6782  *
6783  *  @param [in] context     OpenGL context.
6784  */
6785 BindUnitTest::BindUnitTest(deqp::Context& context)
6786         : deqp::TestCase(context, "textures_bind_unit", "Textures Bind Unit Test")
6787         , m_po(0)
6788         , m_fbo(0)
6789         , m_rbo(0)
6790         , m_vao(0)
6791         , m_result(DE_NULL)
6792 {
6793         m_to[0] = 0;
6794         m_to[1] = 0;
6795         m_to[2] = 0;
6796         m_to[3] = 0;
6797 }
6798
6799 /** @brief Bind Unit Test cases.
6800  *
6801  *  @return Iteration result.
6802  */
6803 tcu::TestNode::IterateResult BindUnitTest::iterate()
6804 {
6805         /* Get context setup. */
6806         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
6807         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
6808
6809         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
6810         {
6811                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
6812
6813                 return STOP;
6814         }
6815
6816         /* Running tests. */
6817         bool is_ok      = true;
6818         bool is_error = false;
6819
6820         try
6821         {
6822                 CreateProgram();
6823                 CreateTextures();
6824                 CreateFrambuffer();
6825                 CreateVertexArray();
6826                 is_ok &= Draw();
6827                 is_ok &= Check();
6828         }
6829         catch (...)
6830         {
6831                 is_ok   = false;
6832                 is_error = true;
6833         }
6834
6835         /* Cleanup. */
6836         CleanAll();
6837
6838         /* Result's setup. */
6839         if (is_ok)
6840         {
6841                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
6842         }
6843         else
6844         {
6845                 if (is_error)
6846                 {
6847                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
6848                 }
6849                 else
6850                 {
6851                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
6852                 }
6853         }
6854
6855         return STOP;
6856 }
6857
6858 /** @brief Create test program.
6859  */
6860 void BindUnitTest::CreateProgram()
6861 {
6862         /* Shortcut for GL functionality */
6863         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
6864
6865         struct Shader
6866         {
6867                 glw::GLchar const* source;
6868                 glw::GLenum const  type;
6869                 glw::GLuint                id;
6870         } shader[] = { { s_vertex_shader, GL_VERTEX_SHADER, 0 }, { s_fragment_shader, GL_FRAGMENT_SHADER, 0 } };
6871
6872         glw::GLuint const shader_count = sizeof(shader) / sizeof(shader[0]);
6873
6874         try
6875         {
6876                 /* Create program. */
6877                 m_po = gl.createProgram();
6878                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateProgram call failed.");
6879
6880                 /* Shader compilation. */
6881
6882                 for (glw::GLuint i = 0; i < shader_count; ++i)
6883                 {
6884                         if (DE_NULL != shader[i].source)
6885                         {
6886                                 shader[i].id = gl.createShader(shader[i].type);
6887
6888                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateShader call failed.");
6889
6890                                 gl.attachShader(m_po, shader[i].id);
6891
6892                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glAttachShader call failed.");
6893
6894                                 gl.shaderSource(shader[i].id, 1, &shader[i].source, NULL);
6895
6896                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource call failed.");
6897
6898                                 gl.compileShader(shader[i].id);
6899
6900                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader call failed.");
6901
6902                                 glw::GLint status = GL_FALSE;
6903
6904                                 gl.getShaderiv(shader[i].id, GL_COMPILE_STATUS, &status);
6905                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
6906
6907                                 if (GL_FALSE == status)
6908                                 {
6909                                         glw::GLint log_size = 0;
6910                                         gl.getShaderiv(shader[i].id, GL_INFO_LOG_LENGTH, &log_size);
6911                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
6912
6913                                         glw::GLchar* log_text = new glw::GLchar[log_size];
6914
6915                                         gl.getShaderInfoLog(shader[i].id, log_size, NULL, &log_text[0]);
6916
6917                                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "Shader compilation has failed.\n"
6918                                                                                                                 << "Shader type: " << glu::getShaderTypeStr(shader[i].type)
6919                                                                                                                 << "\n"
6920                                                                                                                 << "Shader compilation error log:\n"
6921                                                                                                                 << log_text << "\n"
6922                                                                                                                 << "Shader source code:\n"
6923                                                                                                                 << shader[i].source << "\n"
6924                                                                                                                 << tcu::TestLog::EndMessage;
6925
6926                                         delete[] log_text;
6927
6928                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog call failed.");
6929
6930                                         throw 0;
6931                                 }
6932                         }
6933                 }
6934
6935                 /* Link. */
6936                 gl.linkProgram(m_po);
6937
6938                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTransformFeedbackVaryings call failed.");
6939
6940                 glw::GLint status = GL_FALSE;
6941
6942                 gl.getProgramiv(m_po, GL_LINK_STATUS, &status);
6943
6944                 if (GL_TRUE == status)
6945                 {
6946                         for (glw::GLuint i = 0; i < shader_count; ++i)
6947                         {
6948                                 if (shader[i].id)
6949                                 {
6950                                         gl.detachShader(m_po, shader[i].id);
6951
6952                                         GLU_EXPECT_NO_ERROR(gl.getError(), "glDetachShader call failed.");
6953                                 }
6954                         }
6955                 }
6956                 else
6957                 {
6958                         glw::GLint log_size = 0;
6959
6960                         gl.getProgramiv(m_po, GL_INFO_LOG_LENGTH, &log_size);
6961
6962                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv call failed.");
6963
6964                         glw::GLchar* log_text = new glw::GLchar[log_size];
6965
6966                         gl.getProgramInfoLog(m_po, log_size, NULL, &log_text[0]);
6967
6968                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "Program linkage has failed due to:\n"
6969                                                                                                 << log_text << "\n"
6970                                                                                                 << tcu::TestLog::EndMessage;
6971
6972                         delete[] log_text;
6973
6974                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramInfoLog call failed.");
6975
6976                         throw 0;
6977                 }
6978         }
6979         catch (...)
6980         {
6981                 if (m_po)
6982                 {
6983                         gl.deleteProgram(m_po);
6984
6985                         m_po = 0;
6986                 }
6987         }
6988
6989         for (glw::GLuint i = 0; i < shader_count; ++i)
6990         {
6991                 if (0 != shader[i].id)
6992                 {
6993                         gl.deleteShader(shader[i].id);
6994
6995                         shader[i].id = 0;
6996                 }
6997         }
6998
6999         if (0 == m_po)
7000         {
7001                 throw 0;
7002         }
7003 }
7004
7005 /** @brief Create texture.
7006  */
7007 void BindUnitTest::CreateTextures()
7008 {
7009         /* Shortcut for GL functionality. */
7010         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7011
7012         /* Prepare texture. */
7013         gl.genTextures(4, m_to);
7014         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
7015
7016         /* Setup pixel sotre modes.*/
7017         gl.pixelStorei(GL_UNPACK_ALIGNMENT, sizeof(glw::GLubyte));
7018         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
7019
7020         gl.pixelStorei(GL_PACK_ALIGNMENT, sizeof(glw::GLubyte));
7021         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
7022
7023         /* Red texture. */
7024         gl.bindTexture(GL_TEXTURE_2D, m_to[0]);
7025         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7026
7027         gl.texImage2D(GL_TEXTURE_2D, 0, GL_R8, s_texture_width, s_texture_height, 0, GL_RED, GL_UNSIGNED_BYTE,
7028                                   s_texture_data_r);
7029         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
7030
7031         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
7032         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
7033         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
7034
7035         /* Green texture. */
7036         gl.bindTexture(GL_TEXTURE_2D, m_to[1]);
7037         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7038
7039         gl.texImage2D(GL_TEXTURE_2D, 0, GL_R8, s_texture_width, s_texture_height, 0, GL_RED, GL_UNSIGNED_BYTE,
7040                                   s_texture_data_g);
7041         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
7042
7043         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
7044         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
7045         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
7046
7047         /* Blue texture. */
7048         gl.bindTexture(GL_TEXTURE_2D, m_to[2]);
7049         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7050
7051         gl.texImage2D(GL_TEXTURE_2D, 0, GL_R8, s_texture_width, s_texture_height, 0, GL_RED, GL_UNSIGNED_BYTE,
7052                                   s_texture_data_b);
7053         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
7054
7055         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
7056         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
7057         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
7058
7059         /* Alpha texture. */
7060         gl.bindTexture(GL_TEXTURE_2D, m_to[3]);
7061         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7062
7063         gl.texImage2D(GL_TEXTURE_2D, 0, GL_R8, s_texture_width, s_texture_height, 0, GL_RED, GL_UNSIGNED_BYTE,
7064                                   s_texture_data_a);
7065         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
7066
7067         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
7068         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
7069         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
7070 }
7071
7072 /** @brief Create framebuffer.
7073  */
7074 void BindUnitTest::CreateFrambuffer()
7075 {
7076         /* Shortcut for GL functionality. */
7077         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7078
7079         /* Prepare framebuffer. */
7080         gl.genFramebuffers(1, &m_fbo);
7081         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
7082
7083         gl.genRenderbuffers(1, &m_rbo);
7084         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
7085
7086         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
7087         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
7088
7089         gl.bindRenderbuffer(GL_RENDERBUFFER, m_rbo);
7090         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
7091
7092         gl.renderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, s_texture_width, s_texture_height);
7093         GLU_EXPECT_NO_ERROR(gl.getError(), "glRenderbufferStorage call failed.");
7094
7095         gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_rbo);
7096         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
7097
7098         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
7099         {
7100                 throw 0;
7101         }
7102
7103         gl.viewport(0, 0, s_texture_width, s_texture_height);
7104         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
7105
7106         /* Clear framebuffer's content. */
7107         gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
7108         GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
7109
7110         gl.clear(GL_COLOR_BUFFER_BIT);
7111         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
7112 }
7113
7114 /** @brief Create vertex array object.
7115  */
7116 void BindUnitTest::CreateVertexArray()
7117 {
7118         /* Shortcut for GL functionality. */
7119         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7120
7121         gl.genVertexArrays(1, &m_vao);
7122         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays call has failed.");
7123
7124         gl.bindVertexArray(m_vao);
7125         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray call has failed.");
7126 }
7127
7128 bool BindUnitTest::Draw()
7129 {
7130         /* Shortcut for GL functionality. */
7131         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7132
7133         /* Setup program. */
7134         gl.useProgram(m_po);
7135         GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram call has failed.");
7136
7137         /* Bind textures to proper units and setup program's samplers. */
7138         for (glw::GLuint i = 0; i < 4; ++i)
7139         {
7140                 /* Tested binding funcion. */
7141                 gl.bindTextureUnit(i, m_to[i]);
7142
7143                 /* Check for errors. */
7144                 glw::GLenum error = GL_NO_ERROR;
7145
7146                 if (GL_NO_ERROR != (error = gl.getError()))
7147                 {
7148                         m_context.getTestContext().getLog()
7149                                 << tcu::TestLog::Message << "BindTextureUnit unexpectedly generated error " << glu::getErrorStr(error)
7150                                 << " when binding texture " << m_to[i] << " to texture unit " << i << ". Test fails."
7151                                 << tcu::TestLog::EndMessage;
7152
7153                         return false;
7154                 }
7155
7156                 /* Sampler setup. */
7157                 gl.uniform1i(gl.getUniformLocation(m_po, s_fragment_shader_samplers[i]), i);
7158                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetUniformLocation or glUniform1i call has failed.");
7159         }
7160
7161         /* Draw call. */
7162         gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
7163         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays call has failed.");
7164
7165         return true;
7166 }
7167
7168 /** @brief Compare results with reference.
7169  *
7170  *  @return True if equal, false otherwise.
7171  */
7172 bool BindUnitTest::Check()
7173 {
7174         /* Shortcut for GL functionality. */
7175         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7176
7177         /* Setup storage for results. */
7178         m_result = new glw::GLubyte[s_texture_count_rgba];
7179
7180         /* Setup pixel sotre modes.*/
7181         gl.pixelStorei(GL_UNPACK_ALIGNMENT, sizeof(glw::GLubyte));
7182         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
7183
7184         gl.pixelStorei(GL_PACK_ALIGNMENT, sizeof(glw::GLubyte));
7185         GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
7186
7187         /* Query framebuffer's image. */
7188         gl.readPixels(0, 0, s_texture_width, s_texture_height, GL_RGBA, GL_UNSIGNED_BYTE, m_result);
7189         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays call has failed.");
7190
7191         /* Compare values with reference. */
7192         for (glw::GLuint i = 0; i < s_texture_count_rgba; ++i)
7193         {
7194                 if (s_texture_data_rgba[i] != m_result[i])
7195                 {
7196                         m_context.getTestContext().getLog()
7197                                 << tcu::TestLog::Message << "Framebuffer data " << DataToString(s_texture_count_rgba, m_result)
7198                                 << " does not match the reference values " << DataToString(s_texture_count_rgba, s_texture_data_rgba)
7199                                 << "." << tcu::TestLog::EndMessage;
7200
7201                         return false;
7202                 }
7203         }
7204
7205         return true;
7206 }
7207
7208 /** @brief Clean GL objects, test variables and GL errors.
7209  */
7210 void BindUnitTest::CleanAll()
7211 {
7212         /* Shortcut for GL functionality. */
7213         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7214
7215         /* Release GL objects. */
7216         if (m_po)
7217         {
7218                 gl.useProgram(0);
7219
7220                 gl.deleteProgram(m_po);
7221
7222                 m_po = 0;
7223         }
7224
7225         if (m_to[0] || m_to[1] || m_to[2] || m_to[3])
7226         {
7227                 gl.deleteTextures(4, m_to);
7228
7229                 m_to[0] = 0;
7230                 m_to[1] = 0;
7231                 m_to[2] = 0;
7232                 m_to[3] = 0;
7233         }
7234
7235         if (m_fbo)
7236         {
7237                 gl.deleteFramebuffers(1, &m_fbo);
7238
7239                 m_fbo = 0;
7240         }
7241
7242         if (m_rbo)
7243         {
7244                 gl.deleteRenderbuffers(1, &m_rbo);
7245
7246                 m_rbo = 0;
7247         }
7248
7249         /* Release heap. */
7250         if (DE_NULL != m_result)
7251         {
7252                 delete[] m_result;
7253         }
7254
7255         /* Erros clean-up. */
7256         while (GL_NO_ERROR != gl.getError())
7257                 ;
7258 }
7259
7260 /** @brief Convert raw data into string for logging purposes.
7261  *
7262  *  @param [in] count      Count of the data.
7263  *  @param [in] data       Raw data.
7264  *
7265  *  @return String representation of data.
7266  */
7267 std::string BindUnitTest::DataToString(glw::GLuint count, const glw::GLubyte data[])
7268 {
7269         std::string data_str = "[";
7270
7271         for (glw::GLuint i = 0; i < count; ++i)
7272         {
7273                 std::stringstream int_sstream;
7274
7275                 int_sstream << unsigned(data[i]);
7276
7277                 data_str.append(int_sstream.str());
7278
7279                 if (i + 1 < count)
7280                 {
7281                         data_str.append(", ");
7282                 }
7283                 else
7284                 {
7285                         data_str.append("]");
7286                 }
7287         }
7288
7289         return data_str;
7290 }
7291
7292 /** Reference data and parameters. */
7293 const glw::GLubyte BindUnitTest::s_texture_data_r[]     = { 0, 4, 8, 12, 16, 20 };
7294 const glw::GLubyte BindUnitTest::s_texture_data_g[]     = { 1, 5, 9, 13, 17, 21 };
7295 const glw::GLubyte BindUnitTest::s_texture_data_b[]     = { 2, 6, 10, 14, 18, 22 };
7296 const glw::GLubyte BindUnitTest::s_texture_data_a[]     = { 3, 7, 11, 15, 19, 23 };
7297 const glw::GLubyte BindUnitTest::s_texture_data_rgba[] = { 0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11,
7298                                                                                                                    12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 };
7299 const glw::GLuint BindUnitTest::s_texture_width          = 2;
7300 const glw::GLuint BindUnitTest::s_texture_height         = 3;
7301 const glw::GLuint BindUnitTest::s_texture_count_rgba = sizeof(s_texture_data_rgba) / sizeof(s_texture_data_rgba[0]);
7302
7303 /* Vertex shader source code. */
7304 const glw::GLchar* BindUnitTest::s_vertex_shader = "#version 450\n"
7305                                                                                                    "\n"
7306                                                                                                    "void main()\n"
7307                                                                                                    "{\n"
7308                                                                                                    "    switch(gl_VertexID)\n"
7309                                                                                                    "    {\n"
7310                                                                                                    "        case 0:\n"
7311                                                                                                    "            gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
7312                                                                                                    "            break;\n"
7313                                                                                                    "        case 1:\n"
7314                                                                                                    "            gl_Position = vec4( 1.0, 1.0, 0.0, 1.0);\n"
7315                                                                                                    "            break;\n"
7316                                                                                                    "        case 2:\n"
7317                                                                                                    "            gl_Position = vec4(-1.0,-1.0, 0.0, 1.0);\n"
7318                                                                                                    "            break;\n"
7319                                                                                                    "        case 3:\n"
7320                                                                                                    "            gl_Position = vec4( 1.0,-1.0, 0.0, 1.0);\n"
7321                                                                                                    "            break;\n"
7322                                                                                                    "    }\n"
7323                                                                                                    "}\n";
7324
7325 /* Fragment shader source program. */
7326 const glw::GLchar* BindUnitTest::s_fragment_shader =
7327         "#version 450\n"
7328         "\n"
7329         "layout(pixel_center_integer) in vec4 gl_FragCoord;\n"
7330         "\n"
7331         "uniform sampler2D texture_input_r;\n"
7332         "uniform sampler2D texture_input_g;\n"
7333         "uniform sampler2D texture_input_b;\n"
7334         "uniform sampler2D texture_input_a;\n"
7335         "\n"
7336         "out     vec4      color_output;\n"
7337         "\n"
7338         "void main()\n"
7339         "{\n"
7340         "    color_output = vec4(texelFetch(texture_input_r, ivec2(gl_FragCoord.xy), 0).r,\n"
7341         "                        texelFetch(texture_input_g, ivec2(gl_FragCoord.xy), 0).r,\n"
7342         "                        texelFetch(texture_input_b, ivec2(gl_FragCoord.xy), 0).r,\n"
7343         "                        texelFetch(texture_input_a, ivec2(gl_FragCoord.xy), 0).r);\n"
7344         "}\n";
7345
7346 const glw::GLchar* BindUnitTest::s_fragment_shader_samplers[4] = { "texture_input_r", "texture_input_g",
7347                                                                                                                                    "texture_input_b", "texture_input_a" };
7348
7349 /******************************** Get Image Test Implementation   ********************************/
7350
7351 /** @brief Get Image Test constructor.
7352  *
7353  *  @param [in] context     OpenGL context.
7354  */
7355 GetImageTest::GetImageTest(deqp::Context& context)
7356         : deqp::TestCase(context, "textures_get_image", "Textures Get Image Test")
7357 {
7358         /* Intentionally left blank */
7359 }
7360
7361 /** Reference data. */
7362 const glw::GLubyte GetImageTest::s_texture_data[] = { 0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3,
7363                                                                                                           0xff, 0xff, 0xff, 0xff, 0xff, 0x88, 0x0,  0x15, 0xff, 0xed, 0x1c,
7364                                                                                                           0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff, 0xc8,
7365                                                                                                           0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff,
7366                                                                                                           0xb5, 0xe6, 0x1d, 0xff, 0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc,
7367                                                                                                           0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff };
7368
7369 /** Reference data (compressed). */
7370 const glw::GLubyte GetImageTest::s_texture_data_compressed[] = { 0xa6, 0x39, 0x9, 0xf1, 0x88, 0x8b, 0x75, 0x85 };
7371
7372 /** Reference data parameters. */
7373 const glw::GLuint GetImageTest::s_texture_width                   = 4;
7374 const glw::GLuint GetImageTest::s_texture_height                  = 4;
7375 const glw::GLuint GetImageTest::s_texture_size                    = sizeof(s_texture_data);
7376 const glw::GLuint GetImageTest::s_texture_size_compressed = sizeof(s_texture_data_compressed);
7377 const glw::GLuint GetImageTest::s_texture_count                   = s_texture_size / sizeof(s_texture_data[0]);
7378 const glw::GLuint GetImageTest::s_texture_count_compressed =
7379         s_texture_size_compressed / sizeof(s_texture_data_compressed[0]);
7380
7381 /** @brief Get Image Test cases.
7382  *
7383  *  @return Iteration result.
7384  */
7385 tcu::TestNode::IterateResult GetImageTest::iterate()
7386 {
7387         /* Shortcut for GL functionality. */
7388         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7389
7390         /* Get context setup. */
7391         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
7392         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
7393
7394         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
7395         {
7396                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
7397
7398                 return STOP;
7399         }
7400
7401         /* Running tests. */
7402         bool is_ok      = true;
7403         bool is_error = false;
7404
7405         /* Objects. */
7406         glw::GLuint  texture                                                                       = 0;
7407         glw::GLubyte result[s_texture_count]                                       = {};
7408         glw::GLubyte result_compressed[s_texture_count_compressed] = {};
7409
7410         try
7411         {
7412                 /* Uncompressed case. */
7413                 {
7414                         /* Texture initiation. */
7415                         gl.genTextures(1, &texture);
7416                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
7417
7418                         gl.bindTexture(GL_TEXTURE_2D, texture);
7419                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7420
7421                         gl.texImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, s_texture_width, s_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
7422                                                   s_texture_data);
7423                         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
7424
7425                         /* Quering image with tested function. */
7426                         gl.getTextureImage(texture, 0, GL_RGBA, GL_UNSIGNED_BYTE, sizeof(result), result);
7427
7428                         /* Check for errors. */
7429                         glw::GLenum error = GL_NO_ERROR;
7430
7431                         if (GL_NO_ERROR != (error = gl.getError()))
7432                         {
7433                                 m_context.getTestContext().getLog()
7434                                         << tcu::TestLog::Message << "GetTextureImage unexpectedly generated error "
7435                                         << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
7436
7437                                 is_ok = false;
7438                         }
7439                         else
7440                         {
7441                                 /* No error, so compare images. */
7442                                 for (glw::GLuint i = 0; i < s_texture_count; ++i)
7443                                 {
7444                                         if (s_texture_data[i] != result[i])
7445                                         {
7446                                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "GetTextureImage returned "
7447                                                                                                                         << DataToString(s_texture_count, result) << ", but "
7448                                                                                                                         << DataToString(s_texture_count, s_texture_data)
7449                                                                                                                         << " was expected. Test fails." << tcu::TestLog::EndMessage;
7450
7451                                                 is_ok = false;
7452
7453                                                 break;
7454                                         }
7455                                 }
7456                         }
7457                 }
7458
7459                 /* Clean up texture .*/
7460                 gl.deleteTextures(1, &texture);
7461                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
7462
7463                 texture = 0;
7464
7465                 /* Compressed case. */
7466                 {
7467                         /* Texture initiation. */
7468                         gl.genTextures(1, &texture);
7469                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
7470
7471                         gl.bindTexture(GL_TEXTURE_2D, texture);
7472                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7473
7474                         gl.compressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, s_texture_width, s_texture_height, 0,
7475                                                                         s_texture_size_compressed, s_texture_data_compressed);
7476                         GLU_EXPECT_NO_ERROR(gl.getError(), "glCompressedTexImage2D has failed");
7477
7478                         /* Quering image with tested function. */
7479                         gl.getCompressedTextureImage(texture, 0, s_texture_count_compressed * sizeof(result_compressed[0]),
7480                                                                                  result_compressed);
7481
7482                         /* Check for errors. */
7483                         glw::GLenum error = GL_NO_ERROR;
7484
7485                         if (GL_NO_ERROR != (error = gl.getError()))
7486                         {
7487                                 m_context.getTestContext().getLog()
7488                                         << tcu::TestLog::Message << "GetCompressedTextureImage unexpectedly generated error "
7489                                         << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
7490
7491                                 is_ok = false;
7492                         }
7493                         else
7494                         {
7495                                 /* No error, so compare images. */
7496                                 for (glw::GLuint i = 0; i < s_texture_count_compressed; ++i)
7497                                 {
7498                                         if (s_texture_data_compressed[i] != result_compressed[i])
7499                                         {
7500                                                 m_context.getTestContext().getLog()
7501                                                         << tcu::TestLog::Message << "GetCompressedTextureImage returned "
7502                                                         << DataToString(s_texture_count_compressed, result_compressed) << ", but "
7503                                                         << DataToString(s_texture_count_compressed, s_texture_data_compressed)
7504                                                         << " was expected. Test fails." << tcu::TestLog::EndMessage;
7505
7506                                                 is_ok = false;
7507
7508                                                 break;
7509                                         }
7510                                 }
7511                         }
7512                 }
7513         }
7514         catch (...)
7515         {
7516                 is_ok   = false;
7517                 is_error = true;
7518         }
7519
7520         /* Cleanup. */
7521         if (texture)
7522         {
7523                 gl.deleteTextures(1, &texture);
7524         }
7525
7526         /* Result's setup. */
7527         if (is_ok)
7528         {
7529                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
7530         }
7531         else
7532         {
7533                 if (is_error)
7534                 {
7535                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
7536                 }
7537                 else
7538                 {
7539                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7540                 }
7541         }
7542
7543         return STOP;
7544 }
7545
7546 /** @brief Convert raw data into string for logging purposes.
7547  *
7548  *  @param [in] count      Count of the data.
7549  *  @param [in] data       Raw data.
7550  *
7551  *  @return String representation of data.
7552  */
7553 std::string GetImageTest::DataToString(glw::GLuint count, const glw::GLubyte data[])
7554 {
7555         std::string data_str = "[";
7556
7557         for (glw::GLuint i = 0; i < count; ++i)
7558         {
7559                 std::stringstream int_sstream;
7560
7561                 int_sstream << unsigned(data[i]);
7562
7563                 data_str.append(int_sstream.str());
7564
7565                 if (i + 1 < count)
7566                 {
7567                         data_str.append(", ");
7568                 }
7569                 else
7570                 {
7571                         data_str.append("]");
7572                 }
7573         }
7574
7575         return data_str;
7576 }
7577
7578 /******************************** Get Level Parameter Test Implementation   ********************************/
7579
7580 /** @brief Get Level Parameter Test constructor.
7581  *
7582  *  @param [in] context     OpenGL context.
7583  */
7584 GetLevelParameterTest::GetLevelParameterTest(deqp::Context& context)
7585         : deqp::TestCase(context, "textures_get_level_parameter", "Textures Get Level Parameter Test")
7586 {
7587         /* Intentionally left blank */
7588 }
7589
7590 /** Reference data. */
7591 const glw::GLubyte GetLevelParameterTest::s_texture_data[] = {
7592         0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
7593         0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
7594         0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
7595         0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff,
7596
7597         0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
7598         0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
7599         0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
7600         0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff,
7601
7602         0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
7603         0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
7604         0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
7605         0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff,
7606
7607         0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
7608         0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
7609         0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
7610         0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff
7611 };
7612
7613 /** Reference data parameters. */
7614 const glw::GLuint GetLevelParameterTest::s_texture_width  = 4;
7615 const glw::GLuint GetLevelParameterTest::s_texture_height = 4;
7616 const glw::GLuint GetLevelParameterTest::s_texture_depth  = 4;
7617
7618 /** @brief Get Level Parameter Test cases.
7619  *
7620  *  @return Iteration result.
7621  */
7622 tcu::TestNode::IterateResult GetLevelParameterTest::iterate()
7623 {
7624         /* Shortcut for GL functionality. */
7625         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7626
7627         /* Get context setup. */
7628         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
7629         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
7630
7631         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
7632         {
7633                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
7634
7635                 return STOP;
7636         }
7637
7638         /* Running tests. */
7639         bool is_ok      = true;
7640         bool is_error = false;
7641
7642         /* Objects. */
7643         glw::GLuint texture = 0;
7644
7645         try
7646         {
7647                 /* Texture initiation. */
7648                 gl.genTextures(1, &texture);
7649                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
7650
7651                 gl.bindTexture(GL_TEXTURE_3D, texture);
7652                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7653
7654                 gl.texImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, s_texture_width, s_texture_height, s_texture_depth, 0, GL_RGBA,
7655                                           GL_UNSIGNED_BYTE, s_texture_data);
7656                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
7657
7658                 gl.texImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, s_texture_width / 2, s_texture_height / 2, s_texture_depth / 2, 0,
7659                                           GL_RGBA, GL_UNSIGNED_BYTE, s_texture_data);
7660                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
7661
7662                 static const glw::GLenum pnames[] = {
7663                         GL_TEXTURE_WIDTH,         GL_TEXTURE_HEIGHT,     GL_TEXTURE_DEPTH,               GL_TEXTURE_INTERNAL_FORMAT,
7664                         GL_TEXTURE_RED_TYPE,   GL_TEXTURE_GREEN_TYPE, GL_TEXTURE_BLUE_TYPE,  GL_TEXTURE_ALPHA_TYPE,
7665                         GL_TEXTURE_DEPTH_TYPE, GL_TEXTURE_RED_SIZE,   GL_TEXTURE_GREEN_SIZE, GL_TEXTURE_BLUE_SIZE,
7666                         GL_TEXTURE_ALPHA_SIZE, GL_TEXTURE_DEPTH_SIZE, GL_TEXTURE_COMPRESSED
7667                 };
7668                 static const glw::GLuint pnames_count = sizeof(pnames) / sizeof(pnames[0]);
7669
7670                 /* Test GetTextureLevelParameteriv. */
7671                 for (glw::GLuint i = 0; i < 2 /* levels */; ++i)
7672                 {
7673                         for (glw::GLuint j = 0; j < pnames_count; ++j)
7674                         {
7675                                 glw::GLint result_legacy = 0;
7676                                 glw::GLint result_dsa   = 0;
7677
7678                                 /* Quering reference value. */
7679                                 gl.getTexLevelParameteriv(GL_TEXTURE_3D, i, pnames[j], &result_legacy);
7680                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
7681
7682                                 /* Quering using DSA function. */
7683                                 gl.getTextureLevelParameteriv(texture, i, pnames[j], &result_dsa);
7684
7685                                 /* Check for errors. */
7686                                 glw::GLenum error = GL_NO_ERROR;
7687
7688                                 if (GL_NO_ERROR != (error = gl.getError()))
7689                                 {
7690                                         m_context.getTestContext().getLog()
7691                                                 << tcu::TestLog::Message << "GetTextureLevelParameteriv unexpectedly generated error "
7692                                                 << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
7693
7694                                         is_ok = false;
7695                                 }
7696                                 else
7697                                 {
7698                                         /* Compare values. */
7699                                         if (result_legacy != result_dsa)
7700                                         {
7701                                                 m_context.getTestContext().getLog()
7702                                                         << tcu::TestLog::Message << "For parameter name "
7703                                                         << glu::getTextureLevelParameterStr(pnames[j]) << " GetTextureLevelParameteriv returned "
7704                                                         << result_dsa << ", but reference value (queried using GetTexLevelParameteriv) was "
7705                                                         << result_legacy << ". Test fails." << tcu::TestLog::EndMessage;
7706
7707                                                 is_ok = false;
7708                                         }
7709                                 }
7710                         }
7711                 }
7712
7713                 /* Test GetTextureLevelParameterfv. */
7714                 for (glw::GLuint i = 0; i < 2 /* levels */; ++i)
7715                 {
7716                         for (glw::GLuint j = 0; j < pnames_count; ++j)
7717                         {
7718                                 glw::GLfloat result_legacy = 0.f;
7719                                 glw::GLfloat result_dsa = 0.f;
7720
7721                                 /* Quering reference value. */
7722                                 gl.getTexLevelParameterfv(GL_TEXTURE_3D, i, pnames[j], &result_legacy);
7723                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameterfv has failed");
7724
7725                                 /* Quering using DSA function. */
7726                                 gl.getTextureLevelParameterfv(texture, i, pnames[j], &result_dsa);
7727
7728                                 /* Check for errors. */
7729                                 glw::GLenum error = GL_NO_ERROR;
7730
7731                                 if (GL_NO_ERROR != (error = gl.getError()))
7732                                 {
7733                                         m_context.getTestContext().getLog()
7734                                                 << tcu::TestLog::Message << "GetTextureLevelParameterfv unexpectedly generated error "
7735                                                 << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
7736
7737                                         is_ok = false;
7738                                 }
7739                                 else
7740                                 {
7741                                         /* Compare values. */
7742                                         if (de::abs(result_legacy - result_dsa) > 0.125 /* Precision. */)
7743                                         {
7744                                                 m_context.getTestContext().getLog()
7745                                                         << tcu::TestLog::Message << "For parameter name "
7746                                                         << glu::getTextureLevelParameterStr(pnames[j]) << " GetTextureLevelParameterfv returned "
7747                                                         << result_dsa << ", but reference value (queried using GetTexLevelParameterfv) was "
7748                                                         << result_legacy << ". Test fails." << tcu::TestLog::EndMessage;
7749
7750                                                 is_ok = false;
7751                                         }
7752                                 }
7753                         }
7754                 }
7755         }
7756         catch (...)
7757         {
7758                 is_ok   = false;
7759                 is_error = true;
7760         }
7761
7762         /* Cleanup. */
7763         if (texture)
7764         {
7765                 gl.deleteTextures(1, &texture);
7766         }
7767
7768         while (GL_NO_ERROR != gl.getError())
7769                 ;
7770
7771         /* Result's setup. */
7772         if (is_ok)
7773         {
7774                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
7775         }
7776         else
7777         {
7778                 if (is_error)
7779                 {
7780                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
7781                 }
7782                 else
7783                 {
7784                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7785                 }
7786         }
7787
7788         return STOP;
7789 }
7790
7791 /*********************************** Errors Utility Class *****************************************************/
7792
7793 /** @brief Check for errors and log.
7794  *
7795  *  @param [in] context             Test's context.
7796  *  @param [in] expected_error      Expected error value.
7797  *  @param [in] function_name       Name of the function (to be logged).
7798  *  @param [in] log                 Log message.
7799  *
7800  *  @return True if error is equal to expected, false otherwise.
7801  */
7802 bool ErrorsUtilities::CheckErrorAndLog(deqp::Context& context, glw::GLuint expected_error,
7803                                                                            const glw::GLchar* function_name, const glw::GLchar* log)
7804 {
7805         /* Shortcut for GL functionality. */
7806         const glw::Functions& gl = context.getRenderContext().getFunctions();
7807
7808         /* Check error. */
7809         glw::GLenum error = GL_NO_ERROR;
7810
7811         if (expected_error != (error = gl.getError()))
7812         {
7813                 context.getTestContext().getLog() << tcu::TestLog::Message << function_name << " generated error "
7814                                                                                   << glu::getErrorStr(error) << " but, " << glu::getErrorStr(expected_error)
7815                                                                                   << " was expected if " << log << tcu::TestLog::EndMessage;
7816
7817                 return false;
7818         }
7819
7820         return true;
7821 }
7822
7823 /******************************** Creation Errors Test Implementation   ********************************/
7824
7825 /** @brief Creation Errors Test constructor.
7826  *
7827  *  @param [in] context     OpenGL context.
7828  */
7829 CreationErrorsTest::CreationErrorsTest(deqp::Context& context)
7830         : deqp::TestCase(context, "textures_creation_errors", "Texture Objects Creation Errors Test")
7831 {
7832         /* Intentionally left blank. */
7833 }
7834
7835 /** @brief Iterate Creation Errors Test cases.
7836  *
7837  *  @return Iteration result.
7838  */
7839 tcu::TestNode::IterateResult CreationErrorsTest::iterate()
7840 {
7841         /* Shortcut for GL functionality. */
7842         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7843
7844         /* Get context setup. */
7845         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
7846         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
7847
7848         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
7849         {
7850                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
7851
7852                 return STOP;
7853         }
7854
7855         /* Running tests. */
7856         bool is_ok      = true;
7857         bool is_error = false;
7858
7859         /* Textures' objects */
7860         glw::GLuint texture = 0;
7861
7862         try
7863         {
7864                 /* Not a target test. */
7865                 gl.createTextures(NotATarget(), 1, &texture);
7866                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glCreateTextures",
7867                                                                   "target is not one of the allowable values.");
7868
7869                 if (texture)
7870                 {
7871                         gl.deleteTextures(1, &texture);
7872
7873                         texture = 0;
7874                 }
7875
7876                 /* Negative number of textures. */
7877                 gl.createTextures(GL_TEXTURE_2D, -1, &texture);
7878                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCreateTextures", "n is negative.");
7879         }
7880         catch (...)
7881         {
7882                 is_ok   = false;
7883                 is_error = true;
7884         }
7885
7886         /* Cleanup. */
7887         if (texture)
7888         {
7889                 gl.deleteTextures(1, &texture);
7890         }
7891
7892         /* Errors clean up. */
7893         while (gl.getError())
7894                 ;
7895
7896         /* Result's setup. */
7897         if (is_ok)
7898         {
7899                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
7900         }
7901         else
7902         {
7903                 if (is_error)
7904                 {
7905                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
7906                 }
7907                 else
7908                 {
7909                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7910                 }
7911         }
7912
7913         return STOP;
7914 }
7915
7916 /** @brief Function retruns enum which is not a texture target.
7917  */
7918 glw::GLenum CreationErrorsTest::NotATarget()
7919 {
7920         static const glw::GLenum texture_targets[] = { GL_TEXTURE_1D,
7921                                                                                                    GL_TEXTURE_2D,
7922                                                                                                    GL_TEXTURE_3D,
7923                                                                                                    GL_TEXTURE_1D_ARRAY,
7924                                                                                                    GL_TEXTURE_2D_ARRAY,
7925                                                                                                    GL_TEXTURE_RECTANGLE,
7926                                                                                                    GL_TEXTURE_CUBE_MAP,
7927                                                                                                    GL_TEXTURE_CUBE_MAP_ARRAY,
7928                                                                                                    GL_TEXTURE_BUFFER,
7929                                                                                                    GL_TEXTURE_2D_MULTISAMPLE,
7930                                                                                                    GL_TEXTURE_2D_MULTISAMPLE_ARRAY };
7931
7932         glw::GLenum not_a_target = 0;
7933         bool            is_target       = true;
7934
7935         while (is_target)
7936         {
7937                 not_a_target++;
7938
7939                 is_target = false;
7940
7941                 for (glw::GLuint i = 0; i < sizeof(texture_targets) / sizeof(texture_targets[0]); ++i)
7942                 {
7943                         if (texture_targets[i] == not_a_target)
7944                         {
7945                                 is_target = true;
7946                                 break;
7947                         }
7948                 }
7949         }
7950
7951         return not_a_target;
7952 }
7953
7954 /******************************** Texture Buffer Errors Test Implementation   ********************************/
7955
7956 /** @brief Texture Buffer Errors Test constructor.
7957  *
7958  *  @param [in] context     OpenGL context.
7959  */
7960 BufferErrorsTest::BufferErrorsTest(deqp::Context& context)
7961         : deqp::TestCase(context, "textures_buffer_errors", "Texture Buffer Errors Test")
7962 {
7963         /* Intentionally left blank. */
7964 }
7965
7966 /** @brief Iterate Texture Buffer Errors Test cases.
7967  *
7968  *  @return Iteration result.
7969  */
7970 tcu::TestNode::IterateResult BufferErrorsTest::iterate()
7971 {
7972         /* Shortcut for GL functionality. */
7973         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7974
7975         /* Get context setup. */
7976         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
7977         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
7978
7979         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
7980         {
7981                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
7982
7983                 return STOP;
7984         }
7985
7986         /* Running tests. */
7987         bool is_ok      = true;
7988         bool is_error = false;
7989
7990         /* Textures' objects */
7991         glw::GLuint texture_buffer = 0;
7992         glw::GLuint texture_1D   = 0;
7993         glw::GLuint buffer                 = 0;
7994
7995         static const glw::GLubyte data[4]   = { 1, 2, 3, 4 };
7996         static const glw::GLuint  data_size = sizeof(data);
7997
7998         try
7999         {
8000                 /* Auxiliary objects setup. */
8001                 gl.createTextures(GL_TEXTURE_BUFFER, 1, &texture_buffer);
8002                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8003
8004                 gl.createTextures(GL_TEXTURE_1D, 1, &texture_1D);
8005                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8006
8007                 gl.createBuffers(1, &buffer);
8008                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateBuffers has failed");
8009
8010                 gl.namedBufferData(buffer, data_size, data, GL_STATIC_COPY);
8011                 GLU_EXPECT_NO_ERROR(gl.getError(), "glNamedBufferData has failed");
8012
8013                 /*  Check that INVALID_OPERATION is generated by glTextureBuffer if texture
8014                  is not the name of an existing texture object. */
8015                 {
8016                         glw::GLuint not_a_texture = 0;
8017
8018                         while (gl.isTexture(++not_a_texture))
8019                                 ;
8020                         GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed");
8021
8022                         gl.textureBuffer(not_a_texture, GL_RGBA8, buffer);
8023
8024                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureBuffer",
8025                                                                           "texture is not the name of an existing texture object.");
8026                 }
8027
8028                 /*  Check that INVALID_ENUM is generated by glTextureBuffer if the effective
8029                  target of texture is not TEXTURE_BUFFER. */
8030                 {
8031                         gl.textureBuffer(texture_1D, GL_RGBA8, buffer);
8032
8033                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureBuffer",
8034                                                                           "the effective target of texture is not TEXTURE_BUFFER.");
8035                 }
8036
8037                 /*  Check that INVALID_ENUM is generated if internalformat is not one of the
8038                  sized internal formats described above. */
8039                 {
8040                         gl.textureBuffer(texture_buffer, GL_COMPRESSED_SIGNED_RED_RGTC1, buffer);
8041
8042                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureBuffer",
8043                                                                           "internalformat is not one of the sized internal formats described above..");
8044                 }
8045
8046                 /*  Check that INVALID_OPERATION is generated if buffer is not zero and is
8047                  not the name of an existing buffer object. */
8048                 {
8049                         glw::GLuint not_a_buffer = 0;
8050
8051                         while (gl.isBuffer(++not_a_buffer))
8052                                 ;
8053                         GLU_EXPECT_NO_ERROR(gl.getError(), "glIsBuffer has failed");
8054
8055                         gl.textureBuffer(texture_buffer, GL_RGBA8, not_a_buffer);
8056
8057                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureBuffer",
8058                                                                           "buffer is not zero and is not the name of an existing buffer object.");
8059                 }
8060         }
8061         catch (...)
8062         {
8063                 is_ok   = false;
8064                 is_error = true;
8065         }
8066
8067         /* Cleanup. */
8068         if (texture_1D)
8069         {
8070                 gl.deleteTextures(1, &texture_1D);
8071         }
8072
8073         if (texture_buffer)
8074         {
8075                 gl.deleteTextures(1, &texture_buffer);
8076         }
8077
8078         if (buffer)
8079         {
8080                 gl.deleteBuffers(1, &buffer);
8081         }
8082
8083         /* Errors clean up. */
8084         while (gl.getError())
8085                 ;
8086
8087         /* Result's setup. */
8088         if (is_ok)
8089         {
8090                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
8091         }
8092         else
8093         {
8094                 if (is_error)
8095                 {
8096                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
8097                 }
8098                 else
8099                 {
8100                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
8101                 }
8102         }
8103
8104         return STOP;
8105 }
8106
8107 /******************************** Texture Buffer Range Errors Test Implementation   ********************************/
8108
8109 /** @brief Texture Buffer Range Errors Test constructor.
8110  *
8111  *  @param [in] context     OpenGL context.
8112  */
8113 BufferRangeErrorsTest::BufferRangeErrorsTest(deqp::Context& context)
8114         : deqp::TestCase(context, "textures_buffer_range_errors", "Texture Buffer Range Errors Test")
8115 {
8116         /* Intentionally left blank. */
8117 }
8118
8119 /** @brief Iterate Texture Buffer Range Errors Test cases.
8120  *
8121  *  @return Iteration result.
8122  */
8123 tcu::TestNode::IterateResult BufferRangeErrorsTest::iterate()
8124 {
8125         /* Shortcut for GL functionality. */
8126         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8127
8128         /* Get context setup. */
8129         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
8130         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
8131
8132         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
8133         {
8134                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
8135
8136                 return STOP;
8137         }
8138
8139         /* Running tests. */
8140         bool is_ok      = true;
8141         bool is_error = false;
8142
8143         /* Textures' objects */
8144         glw::GLuint texture_buffer = 0;
8145         glw::GLuint texture_1D   = 0;
8146         glw::GLuint buffer                 = 0;
8147
8148         static const glw::GLubyte data[4]   = { 1, 2, 3, 4 };
8149         static const glw::GLuint  data_size = sizeof(data);
8150
8151         try
8152         {
8153                 /* Auxiliary objects setup. */
8154                 gl.createTextures(GL_TEXTURE_BUFFER, 1, &texture_buffer);
8155                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8156
8157                 gl.createTextures(GL_TEXTURE_1D, 1, &texture_1D);
8158                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8159
8160                 gl.createBuffers(1, &buffer);
8161                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateBuffers has failed");
8162
8163                 gl.namedBufferData(buffer, data_size, data, GL_STATIC_COPY);
8164                 GLU_EXPECT_NO_ERROR(gl.getError(), "glNamedBufferData has failed");
8165
8166                 /*  Check that INVALID_OPERATION is generated by TextureBufferRange if
8167                  texture is not the name of an existing texture object.*/
8168                 {
8169                         glw::GLuint not_a_texture = 0;
8170
8171                         while (gl.isTexture(++not_a_texture))
8172                                 ;
8173                         GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed");
8174
8175                         gl.textureBufferRange(not_a_texture, GL_RGBA8, buffer, 0, data_size);
8176
8177                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureBufferRange",
8178                                                                           "texture is not the name of an existing texture object.");
8179                 }
8180
8181                 /*  Check that INVALID_ENUM is generated by TextureBufferRange if the
8182                  effective target of texture is not TEXTURE_BUFFER. */
8183                 {
8184                         gl.textureBufferRange(texture_1D, GL_RGBA8, buffer, 0, data_size);
8185
8186                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureBufferRange",
8187                                                                           "the effective target of texture is not TEXTURE_BUFFER.");
8188                 }
8189
8190                 /*  Check that INVALID_ENUM is generated by TextureBufferRange if
8191                  internalformat is not one of the sized internal formats described above. */
8192                 {
8193                         gl.textureBufferRange(texture_buffer, GL_COMPRESSED_SIGNED_RED_RGTC1, buffer, 0, data_size);
8194
8195                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureBufferRange",
8196                                                                           "internalformat is not one of the supported sized internal formats.");
8197                 }
8198
8199                 /*  Check that INVALID_OPERATION is generated by TextureBufferRange if
8200                  buffer is not zero and is not the name of an existing buffer object. */
8201                 {
8202                         glw::GLuint not_a_buffer = 0;
8203
8204                         while (gl.isBuffer(++not_a_buffer))
8205                                 ;
8206                         GLU_EXPECT_NO_ERROR(gl.getError(), "glIsBuffer has failed");
8207
8208                         gl.textureBufferRange(texture_buffer, GL_RGBA8, not_a_buffer, 0, data_size);
8209
8210                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureBufferRange",
8211                                                                           "buffer is not zero and is not the name of an existing buffer object.");
8212                 }
8213
8214                 /* Check that INVALID_VALUE is generated by TextureBufferRange if offset
8215                  is negative, if size is less than or equal to zero, or if offset + size
8216                  is greater than the value of BUFFER_SIZE for buffer. */
8217                 {
8218                         gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, -1, data_size);
8219
8220                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureBufferRange", "offset is negative.");
8221
8222                         gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, 0, 0);
8223
8224                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureBufferRange", "size is zero.");
8225
8226                         gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, 0, -1);
8227
8228                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureBufferRange", "size is negative.");
8229
8230                         gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, 0, data_size * 16);
8231
8232                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureBufferRange",
8233                                                                           "size is greater than the value of BUFFER_SIZE for buffer.");
8234                 }
8235
8236                 /* Check that INVALID_VALUE is generated by TextureBufferRange if offset is
8237                  not an integer multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT. */
8238                 {
8239                         glw::GLint gl_texture_buffer_offset_alignment = 0;
8240
8241                         gl.getIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, &gl_texture_buffer_offset_alignment);
8242
8243                         /* If alignmet is 1 we cannot do anything. Error situtation is impossible then. */
8244                         if (gl_texture_buffer_offset_alignment > 1)
8245                         {
8246                                 gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, 1, data_size - 1);
8247
8248                                 is_ok &= CheckErrorAndLog(
8249                                         m_context, GL_INVALID_VALUE, "glTextureBufferRange",
8250                                         "offset is not an integer multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT.");
8251                         }
8252                 }
8253         }
8254         catch (...)
8255         {
8256                 is_ok   = false;
8257                 is_error = true;
8258         }
8259
8260         /* Cleanup. */
8261         if (texture_1D)
8262         {
8263                 gl.deleteTextures(1, &texture_1D);
8264         }
8265
8266         if (texture_buffer)
8267         {
8268                 gl.deleteTextures(1, &texture_buffer);
8269         }
8270
8271         if (buffer)
8272         {
8273                 gl.deleteBuffers(1, &buffer);
8274         }
8275
8276         /* Errors clean up. */
8277         while (gl.getError())
8278                 ;
8279
8280         /* Result's setup. */
8281         if (is_ok)
8282         {
8283                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
8284         }
8285         else
8286         {
8287                 if (is_error)
8288                 {
8289                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
8290                 }
8291                 else
8292                 {
8293                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
8294                 }
8295         }
8296
8297         return STOP;
8298 }
8299
8300 /******************************** Texture Storage Errors Test Implementation   ********************************/
8301
8302 /** @brief Texture Storage Errors Test constructor.
8303  *
8304  *  @param [in] context     OpenGL context.
8305  */
8306 StorageErrorsTest::StorageErrorsTest(deqp::Context& context)
8307         : deqp::TestCase(context, "textures_storage_errors", "Texture Storage Errors Test")
8308         , m_to_1D(0)
8309         , m_to_1D_array(0)
8310         , m_to_2D(0)
8311         , m_to_2D_array(0)
8312         , m_to_3D(0)
8313         , m_to_2D_ms(0)
8314         , m_to_2D_ms_immutable(0)
8315         , m_to_3D_ms(0)
8316         , m_to_3D_ms_immutable(0)
8317         , m_to_invalid(0)
8318         , m_internalformat_invalid(0)
8319         , m_max_texture_size(1)
8320         , m_max_samples(1)
8321         , m_max_array_texture_layers(1)
8322 {
8323         /* Intentionally left blank. */
8324 }
8325
8326 /** @brief Iterate Texture Storage Errors Test cases.
8327  *
8328  *  @return Iteration result.
8329  */
8330 tcu::TestNode::IterateResult StorageErrorsTest::iterate()
8331 {
8332         /* Get context setup. */
8333         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
8334         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
8335
8336         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
8337         {
8338                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
8339
8340                 return STOP;
8341         }
8342
8343         /* Running tests. */
8344         bool is_ok      = true;
8345         bool is_error = false;
8346
8347         try
8348         {
8349                 Prepare();
8350
8351                 is_ok &= Test1D();
8352                 is_ok &= Test2D();
8353                 is_ok &= Test3D();
8354                 is_ok &= Test2DMultisample();
8355                 is_ok &= Test3DMultisample();
8356         }
8357         catch (...)
8358         {
8359                 is_ok   = false;
8360                 is_error = true;
8361         }
8362
8363         /* Cleanup. */
8364         Clean();
8365
8366         /* Result's setup. */
8367         if (is_ok)
8368         {
8369                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
8370         }
8371         else
8372         {
8373                 if (is_error)
8374                 {
8375                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
8376                 }
8377                 else
8378                 {
8379                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
8380                 }
8381         }
8382
8383         return STOP;
8384 }
8385
8386 /** @brief Prepare test objects.
8387  */
8388 void StorageErrorsTest::Prepare()
8389 {
8390         /* Shortcut for GL functionality. */
8391         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8392
8393         /* Auxiliary objects setup. */
8394
8395         /* 1D */
8396         gl.createTextures(GL_TEXTURE_1D, 1, &m_to_1D);
8397         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8398
8399         /* 1D ARRAY */
8400         gl.createTextures(GL_TEXTURE_1D_ARRAY, 1, &m_to_1D_array);
8401         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8402
8403         /* 2D */
8404         gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D);
8405         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8406
8407         /* 2D ARRAY */
8408         gl.createTextures(GL_TEXTURE_2D_ARRAY, 1, &m_to_2D_array);
8409         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8410
8411         /* 3D */
8412         gl.createTextures(GL_TEXTURE_3D, 1, &m_to_3D);
8413         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8414
8415         /* 2D Multisample */
8416         gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &m_to_2D_ms);
8417         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8418
8419         /* 2D Multisample with storage */
8420         gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &m_to_2D_ms_immutable);
8421         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8422
8423         gl.textureStorage2DMultisample(m_to_2D_ms_immutable, 1, GL_R8, 16, 16, false);
8424         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2DMultisample has failed");
8425
8426         /* 3D Multisample */
8427         gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 1, &m_to_3D_ms);
8428         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8429
8430         /* 3D Multisample with storage */
8431         gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 1, &m_to_3D_ms_immutable);
8432         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8433
8434         gl.textureStorage3DMultisample(m_to_3D_ms_immutable, 1, GL_R8, 16, 16, 16, false);
8435         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2DMultisample has failed");
8436
8437         /* Invalid values */
8438
8439         /* invalid texture object */
8440         while (gl.isTexture(++m_to_invalid))
8441                 ;
8442         GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed");
8443
8444         /* invalid internal format */
8445         static const glw::GLenum all_internal_formats[] = { GL_R8,
8446                                                                                                                 GL_R8_SNORM,
8447                                                                                                                 GL_R16,
8448                                                                                                                 GL_R16_SNORM,
8449                                                                                                                 GL_RG8,
8450                                                                                                                 GL_RG8_SNORM,
8451                                                                                                                 GL_RG16,
8452                                                                                                                 GL_RG16_SNORM,
8453                                                                                                                 GL_R3_G3_B2,
8454                                                                                                                 GL_RGB4,
8455                                                                                                                 GL_RGB5,
8456                                                                                                                 GL_RGB565,
8457                                                                                                                 GL_RGB8,
8458                                                                                                                 GL_RGB8_SNORM,
8459                                                                                                                 GL_RGB10,
8460                                                                                                                 GL_RGB12,
8461                                                                                                                 GL_RGB16,
8462                                                                                                                 GL_RGB16_SNORM,
8463                                                                                                                 GL_RGBA2,
8464                                                                                                                 GL_RGBA4,
8465                                                                                                                 GL_RGB5_A1,
8466                                                                                                                 GL_RGBA8,
8467                                                                                                                 GL_RGBA8_SNORM,
8468                                                                                                                 GL_RGB10_A2,
8469                                                                                                                 GL_RGB10_A2UI,
8470                                                                                                                 GL_RGBA12,
8471                                                                                                                 GL_RGBA16,
8472                                                                                                                 GL_RGBA16_SNORM,
8473                                                                                                                 GL_SRGB8,
8474                                                                                                                 GL_SRGB8_ALPHA8,
8475                                                                                                                 GL_R16F,
8476                                                                                                                 GL_RG16F,
8477                                                                                                                 GL_RGB16F,
8478                                                                                                                 GL_RGBA16F,
8479                                                                                                                 GL_R32F,
8480                                                                                                                 GL_RG32F,
8481                                                                                                                 GL_RGB32F,
8482                                                                                                                 GL_RGBA32F,
8483                                                                                                                 GL_R11F_G11F_B10F,
8484                                                                                                                 GL_RGB9_E5,
8485                                                                                                                 GL_R8I,
8486                                                                                                                 GL_R8UI,
8487                                                                                                                 GL_R16I,
8488                                                                                                                 GL_R16UI,
8489                                                                                                                 GL_R32I,
8490                                                                                                                 GL_R32UI,
8491                                                                                                                 GL_RG8I,
8492                                                                                                                 GL_RG8UI,
8493                                                                                                                 GL_RG16I,
8494                                                                                                                 GL_RG16UI,
8495                                                                                                                 GL_RG32I,
8496                                                                                                                 GL_RG32UI,
8497                                                                                                                 GL_RGB8I,
8498                                                                                                                 GL_RGB8UI,
8499                                                                                                                 GL_RGB16I,
8500                                                                                                                 GL_RGB16UI,
8501                                                                                                                 GL_RGB32I,
8502                                                                                                                 GL_RGB32UI,
8503                                                                                                                 GL_RGBA8I,
8504                                                                                                                 GL_RGBA8UI,
8505                                                                                                                 GL_RGBA16I,
8506                                                                                                                 GL_RGBA16UI,
8507                                                                                                                 GL_RGBA32I,
8508                                                                                                                 GL_RGBA32UI,
8509                                                                                                                 GL_COMPRESSED_RED,
8510                                                                                                                 GL_COMPRESSED_RG,
8511                                                                                                                 GL_COMPRESSED_RGB,
8512                                                                                                                 GL_COMPRESSED_RGBA,
8513                                                                                                                 GL_COMPRESSED_SRGB,
8514                                                                                                                 GL_COMPRESSED_SRGB_ALPHA,
8515                                                                                                                 GL_COMPRESSED_RED_RGTC1,
8516                                                                                                                 GL_COMPRESSED_SIGNED_RED_RGTC1,
8517                                                                                                                 GL_COMPRESSED_RG_RGTC2,
8518                                                                                                                 GL_COMPRESSED_SIGNED_RG_RGTC2,
8519                                                                                                                 GL_COMPRESSED_RGBA_BPTC_UNORM,
8520                                                                                                                 GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM,
8521                                                                                                                 GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT,
8522                                                                                                                 GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT,
8523                                                                                                                 GL_COMPRESSED_RGB8_ETC2,
8524                                                                                                                 GL_COMPRESSED_SRGB8_ETC2,
8525                                                                                                                 GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
8526                                                                                                                 GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
8527                                                                                                                 GL_COMPRESSED_RGBA8_ETC2_EAC,
8528                                                                                                                 GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
8529                                                                                                                 GL_COMPRESSED_R11_EAC,
8530                                                                                                                 GL_COMPRESSED_SIGNED_R11_EAC,
8531                                                                                                                 GL_COMPRESSED_RG11_EAC,
8532                                                                                                                 GL_COMPRESSED_SIGNED_RG11_EAC,
8533                                                                                                                 GL_DEPTH_COMPONENT16,
8534                                                                                                                 GL_DEPTH_COMPONENT24,
8535                                                                                                                 GL_DEPTH_COMPONENT32,
8536                                                                                                                 GL_DEPTH_COMPONENT32F,
8537                                                                                                                 GL_DEPTH24_STENCIL8,
8538                                                                                                                 GL_DEPTH32F_STENCIL8,
8539                                                                                                                 GL_STENCIL_INDEX1,
8540                                                                                                                 GL_STENCIL_INDEX4,
8541                                                                                                                 GL_STENCIL_INDEX8,
8542                                                                                                                 GL_STENCIL_INDEX16 };
8543
8544         static const glw::GLuint all_internal_formats_count =
8545                 sizeof(all_internal_formats) / sizeof(all_internal_formats[0]);
8546
8547         bool is_valid                    = true;
8548         m_internalformat_invalid = 0;
8549
8550         while (is_valid)
8551         {
8552                 is_valid = false;
8553                 m_internalformat_invalid++;
8554                 for (glw::GLuint i = 0; i < all_internal_formats_count; ++i)
8555                 {
8556                         if (all_internal_formats[i] == m_internalformat_invalid)
8557                         {
8558                                 is_valid = true;
8559                                 break;
8560                         }
8561                 }
8562         }
8563
8564         /* Maximum texture size.*/
8565         gl.getIntegerv(GL_MAX_TEXTURE_SIZE, &m_max_texture_size);
8566         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
8567
8568         /* Maximum number of samples. */
8569         gl.getIntegerv(GL_MAX_SAMPLES, &m_max_samples);
8570         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
8571
8572         /* Maximum number of array texture layers. */
8573         gl.getIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &m_max_array_texture_layers);
8574         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
8575 }
8576
8577 /** @brief Test TextureStorage1D
8578  *
8579  *  @return Test result.
8580  */
8581 bool StorageErrorsTest::Test1D()
8582 {
8583         /* Shortcut for GL functionality. */
8584         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8585
8586         /* Result. */
8587         bool is_ok = true;
8588
8589         /*  Check that INVALID_OPERATION is generated by TextureStorage1D if texture
8590          is not the name of an existing texture object. */
8591         {
8592                 gl.textureStorage1D(m_to_invalid, 1, GL_R8, 8);
8593                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage1D",
8594                                                                   "texture is not the name of an existing texture object.");
8595         }
8596
8597         /*  Check that INVALID_ENUM is generated by TextureStorage1D if
8598          internalformat is not a valid sized internal format. */
8599         {
8600                 gl.textureStorage1D(m_to_1D, 1, m_internalformat_invalid, 8);
8601                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureStorage1D",
8602                                                                   "internalformat is not a valid sized internal format.");
8603         }
8604
8605         /*  Check that INVALID_ENUM is generated by TextureStorage1D if target or
8606          the effective target of texture is not one of the accepted targets
8607          described above. */
8608         {
8609                 gl.textureStorage1D(m_to_2D, 1, GL_R8, 8);
8610                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage1D",
8611                                                                   "the effective target of texture is not one of the accepted targets.");
8612         }
8613
8614         /*  Check that INVALID_VALUE is generated by TextureStorage1D if width or
8615          levels are less than 1. */
8616         {
8617                 gl.textureStorage1D(m_to_1D, 0, GL_R8, 8);
8618                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage1D", "levels is less than 1.");
8619
8620                 gl.textureStorage1D(m_to_1D, 1, GL_R8, 0);
8621                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage1D", "width is less than 1.");
8622         }
8623
8624         /*  Check that INVALID_OPERATION is generated by TextureStorage1D if levels
8625          is greater than log2(width)+1. */
8626         {
8627                 gl.textureStorage1D(m_to_1D, 8, GL_R8, 8);
8628                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage1D",
8629                                                                   "levels is greater than log2(width)+1.");
8630         }
8631
8632         return is_ok;
8633 }
8634
8635 /** @brief Test TextureStorage2D
8636  *
8637  *  @return Test result.
8638  */
8639 bool StorageErrorsTest::Test2D()
8640 {
8641         /* Shortcut for GL functionality. */
8642         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8643
8644         /* Result. */
8645         bool is_ok = true;
8646
8647         /*  Check that INVALID_OPERATION is generated by TextureStorage2D if
8648          texture is not the name of an existing texture object. */
8649         {
8650                 gl.textureStorage2D(m_to_invalid, 1, GL_R8, 8, 8);
8651                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2D",
8652                                                                   "texture is not the name of an existing texture object.");
8653         }
8654
8655         /*  Check that INVALID_ENUM is generated by TextureStorage2D if
8656          internalformat is not a valid sized internal format. */
8657         {
8658                 gl.textureStorage2D(m_to_2D, 1, m_internalformat_invalid, 8, 8);
8659                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureStorage2D",
8660                                                                   "internalformat is not a valid sized internal format.");
8661         }
8662
8663         /*  Check that INVALID_ENUM is generated by TextureStorage2D if target or
8664          the effective target of texture is not one of the accepted targets
8665          described above. */
8666         {
8667                 gl.textureStorage2D(m_to_1D, 1, GL_R8, 8, 8);
8668                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2D",
8669                                                                   "the effective target of texture is not one of the accepted targets.");
8670         }
8671
8672         /*  Check that INVALID_VALUE is generated by TextureStorage2D if width,
8673          height or levels are less than 1. */
8674         {
8675                 gl.textureStorage2D(m_to_2D, 0, GL_R8, 8, 8);
8676                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2D", "levels is less than 1.");
8677
8678                 gl.textureStorage2D(m_to_2D, 1, GL_R8, 0, 8);
8679                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2D", "width is less than 1.");
8680
8681                 gl.textureStorage2D(m_to_2D, 1, GL_R8, 8, 0);
8682                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2D", "height is less than 1.");
8683         }
8684
8685         /* Check that INVALID_OPERATION is generated by TextureStorage2D if target
8686          is TEXTURE_1D_ARRAY or PROXY_TEXTURE_1D_ARRAY and levels is greater than
8687          log2(width)+1. */
8688         {
8689                 gl.textureStorage2D(m_to_1D_array, 8, GL_R8, 8, 8);
8690                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2D",
8691                                                                   "target is TEXTURE_1D_ARRAY and levels is greater than log2(width)+1.");
8692         }
8693
8694         /*  Check that INVALID_OPERATION is generated by TextureStorage2D if target
8695          is not TEXTURE_1D_ARRAY or PROXY_TEXTURE_1D_ARRAY and levels is greater
8696          than log2(max(width, height))+1.  */
8697         {
8698                 gl.textureStorage2D(m_to_2D, 8, GL_R8, 8, 8);
8699                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2D",
8700                                                                   "target is TEXTURE_2D and levels is greater than log2(max(width, height))+1.");
8701         }
8702
8703         return is_ok;
8704 }
8705
8706 /** @brief Test TextureStorage3D
8707  *
8708  *  @return Test result.
8709  */
8710 bool StorageErrorsTest::Test3D()
8711 {
8712         /* Shortcut for GL functionality. */
8713         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8714
8715         /* Result. */
8716         bool is_ok = true;
8717
8718         /*  Check that INVALID_OPERATION is generated by TextureStorage3D if texture
8719          is not the name of an existing texture object. */
8720         {
8721                 gl.textureStorage3D(m_to_invalid, 1, GL_R8, 8, 8, 8);
8722                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3D",
8723                                                                   "texture is not the name of an existing texture object.");
8724         }
8725
8726         /*  Check that INVALID_ENUM is generated by TextureStorage3D if
8727          internalformat is not a valid sized internal format. */
8728         {
8729                 gl.textureStorage3D(m_to_3D, 1, m_internalformat_invalid, 8, 8, 8);
8730                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureStorage3D",
8731                                                                   "internalformat is not a valid sized internal format.");
8732         }
8733
8734         /*  Check that INVALID_ENUM is generated by TextureStorage3D if target or
8735          the effective target of texture is not one of the accepted targets
8736          described above. */
8737         {
8738                 gl.textureStorage3D(m_to_1D, 1, GL_R8, 8, 8, 8);
8739                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3D",
8740                                                                   "the effective target of texture is not one of the accepted targets.");
8741         }
8742
8743         /*  Check that INVALID_VALUE is generated by TextureStorage3D if width,
8744          height, depth or levels are less than 1. */
8745         {
8746                 gl.textureStorage3D(m_to_3D, 0, GL_R8, 8, 8, 8);
8747                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3D", "levels is less than 1.");
8748
8749                 gl.textureStorage3D(m_to_3D, 1, GL_R8, 0, 8, 8);
8750                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3D", "width is less than 1.");
8751
8752                 gl.textureStorage3D(m_to_3D, 1, GL_R8, 8, 0, 8);
8753                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3D", "height is less than 1.");
8754
8755                 gl.textureStorage3D(m_to_3D, 1, GL_R8, 8, 8, 0);
8756                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3D", "depth is less than 1.");
8757         }
8758
8759         /* Check that INVALID_OPERATION is generated by TextureStorage3D if target
8760          is TEXTURE_3D or PROXY_TEXTURE_3D and levels is greater than
8761          log2(max(width, height, depth))+1. */
8762         {
8763                 gl.textureStorage3D(m_to_3D, 8, GL_R8, 8, 8, 8);
8764                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3D",
8765                                                                   "target is TEXTURE_3D and levels is greater than log2(max(width, height, depth))+1.");
8766         }
8767
8768         /*  Check that INVALID_OPERATION is generated by TextureStorage3D if target
8769          is TEXTURE_2D_ARRAY, PROXY_TEXTURE_2D_ARRAY, TEXURE_CUBE_ARRAY,
8770          or PROXY_TEXTURE_CUBE_MAP_ARRAY and levels is greater than
8771          log2(max(width, height))+1.  */
8772         {
8773                 gl.textureStorage3D(m_to_2D_array, 6, GL_R8, 8, 8, 256);
8774                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3D",
8775                                                                   "target is TEXTURE_2D_ARRAY and levels is greater than log2(max(width, height))+1.");
8776         }
8777
8778         return is_ok;
8779 }
8780
8781 /** @brief Test TextureStorage2DMultisample
8782  *
8783  *  @return Test result.
8784  */
8785 bool StorageErrorsTest::Test2DMultisample()
8786 {
8787         /* Shortcut for GL functionality. */
8788         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8789
8790         /* Result. */
8791         bool is_ok = true;
8792
8793         /*  Check that INVALID_OPERATION is generated by TextureStorage2DMultisample
8794          if texture is not the name of an existing texture object. */
8795         {
8796                 gl.textureStorage2DMultisample(m_to_invalid, 1, GL_R8, 8, 8, false);
8797                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2DMultisample",
8798                                                                   "texture is not the name of an existing texture object.");
8799         }
8800
8801         /*  Check that INVALID_ENUM is generated by TextureStorage2DMultisample if
8802          internalformat is not a valid color-renderable, depth-renderable or
8803          stencil-renderable format. */
8804         {
8805                 gl.textureStorage2DMultisample(m_to_2D_ms, 1, m_internalformat_invalid, 8, 8, false);
8806                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureStorage2DMultisample",
8807                                                                   "internalformat is not a valid sized internal format.");
8808         }
8809
8810         /*  Check that INVALID_OPERATION is generated by TextureStorage2DMultisample if
8811          target or the effective target of texture is not one of the accepted
8812          targets described above. */
8813         {
8814                 gl.textureStorage2DMultisample(m_to_1D, 1, GL_R8, 8, 8, false);
8815                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2DMultisample",
8816                                                                   "the effective target of texture is not one of the accepted targets.");
8817         }
8818
8819         /* Check that INVALID_VALUE is generated by TextureStorage2DMultisample if
8820          width or height are less than 1 or greater than the value of
8821          MAX_TEXTURE_SIZE. */
8822         {
8823                 gl.textureStorage2DMultisample(m_to_2D_ms, 1, GL_R8, 0, 8, false);
8824                 is_ok &=
8825                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2DMultisample", "width is less than 1.");
8826
8827                 gl.textureStorage2DMultisample(m_to_2D_ms, 1, GL_R8, 8, 0, false);
8828                 is_ok &=
8829                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2DMultisample", "height is less than 1.");
8830
8831                 gl.textureStorage2DMultisample(m_to_2D_ms, 1, GL_R8, m_max_texture_size * 2, 8, false);
8832                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2DMultisample",
8833                                                                   "width is greater than the value of MAX_TEXTURE_SIZE.");
8834
8835                 gl.textureStorage2DMultisample(m_to_2D_ms, 1, GL_R8, 8, m_max_texture_size * 2, false);
8836                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2DMultisample",
8837                                                                   "height is greater than the value of MAX_TEXTURE_SIZE.");
8838         }
8839
8840         /* Check that INVALID_OPERATION is generated by TextureStorage2DMultisample if
8841          samples is greater than the value of MAX_SAMPLES. */
8842         {
8843                 gl.textureStorage2DMultisample(m_to_2D_ms, m_max_samples * 2, GL_R8, 8, 8, false);
8844                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2DMultisample",
8845                                                                   "samples is greater than the value of MAX_SAMPLES.");
8846         }
8847
8848         /* Check that INVALID_OPERATION is generated by TextureStorage2DMultisample
8849          if the value of TEXTURE_IMMUTABLE_FORMAT for the texture bound to target
8850          is not FALSE. */
8851         {
8852                 gl.textureStorage2DMultisample(m_to_2D_ms_immutable, 1, GL_R8, 8, 8, false);
8853                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2DMultisample",
8854                                                                   "samples is greater than the value of MAX_SAMPLES.");
8855         }
8856
8857         return is_ok;
8858 }
8859
8860 /** @brief Test TextureStorage3DMultisample
8861  *
8862  *  @return Test result.
8863  */
8864 bool StorageErrorsTest::Test3DMultisample()
8865 {
8866         /* Shortcut for GL functionality. */
8867         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8868
8869         /* Result. */
8870         bool is_ok = true;
8871
8872         /*  Check that INVALID_OPERATION is generated by TextureStorage3DMultisample
8873          if texture is not the name of an existing texture object. */
8874         {
8875                 gl.textureStorage3DMultisample(m_to_invalid, 1, GL_R8, 8, 8, 8, false);
8876                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3DMultisample",
8877                                                                   "texture is not the name of an existing texture object.");
8878         }
8879
8880         /*  Check that INVALID_ENUM is generated by TextureStorage3DMultisample if
8881          internalformat is not a valid color-renderable, depth-renderable or
8882          stencil-renderable format. */
8883         {
8884                 gl.textureStorage3DMultisample(m_to_3D_ms, 1, m_internalformat_invalid, 8, 8, 8, false);
8885                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureStorage3DMultisample",
8886                                                                   "internalformat is not a valid sized internal format.");
8887         }
8888
8889         /*  Check that INVALID_OPERATION is generated by TextureStorage3DMultisample if
8890          target or the effective target of texture is not one of the accepted
8891          targets described above. */
8892         {
8893                 gl.textureStorage3DMultisample(m_to_1D, 1, GL_R8, 8, 8, 8, false);
8894                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3DMultisample",
8895                                                                   "the effective target of texture is not one of the accepted targets.");
8896         }
8897
8898         /* Check that INVALID_VALUE is generated by TextureStorage3DMultisample if
8899          width or height are less than 1 or greater than the value of
8900          MAX_TEXTURE_SIZE. */
8901         {
8902                 gl.textureStorage3DMultisample(m_to_3D_ms, 1, GL_R8, 0, 8, 8, false);
8903                 is_ok &=
8904                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3DMultisample", "width is less than 1.");
8905
8906                 gl.textureStorage3DMultisample(m_to_3D_ms, 1, GL_R8, 8, 0, 8, false);
8907                 is_ok &=
8908                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3DMultisample", "height is less than 1.");
8909
8910                 gl.textureStorage3DMultisample(m_to_3D_ms, 1, GL_R8, m_max_texture_size * 2, 8, 8, false);
8911                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3DMultisample",
8912                                                                   "width is greater than the value of MAX_TEXTURE_SIZE.");
8913
8914                 gl.textureStorage3DMultisample(m_to_3D_ms, 1, GL_R8, 8, m_max_texture_size * 2, 8, false);
8915                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3DMultisample",
8916                                                                   "height is greater than the value of MAX_TEXTURE_SIZE.");
8917         }
8918
8919         /* Check that INVALID_VALUE is generated by TextureStorage3DMultisample if
8920          depth is less than 1 or greater than the value of
8921          MAX_ARRAY_TEXTURE_LAYERS. */
8922         {
8923                 gl.textureStorage3DMultisample(m_to_3D_ms, 1, GL_R8, 8, 8, 0, false);
8924                 is_ok &=
8925                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3DMultisample", "depth is less than 1.");
8926
8927                 gl.textureStorage3DMultisample(m_to_3D_ms, 1, GL_R8, 8, 8, m_max_array_texture_layers * 2, false);
8928                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3DMultisample",
8929                                                                   "depth is greater than the value of MAX_ARRAY_TEXTURE_LAYERS.");
8930         }
8931
8932         /* Check that INVALID_VALUE is generated by TextureStorage3DMultisample if
8933          samples is greater than the value of MAX_SAMPLES. */
8934         {
8935                 gl.textureStorage3DMultisample(m_to_3D_ms, m_max_samples * 2, GL_R8, 8, 8, 8, false);
8936                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3DMultisample",
8937                                                                   "samples is greater than the value of MAX_SAMPLES.");
8938         }
8939
8940         /* Check that INVALID_OPERATION is generated by TextureStorage3DMultisample
8941          if the value of TEXTURE_IMMUTABLE_FORMAT for the texture bound to target
8942          is not FALSE. */
8943         {
8944                 gl.textureStorage3DMultisample(m_to_3D_ms_immutable, 1, GL_R8, 8, 8, 8, false);
8945                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3DMultisample",
8946                                                                   "samples is greater than the value of MAX_SAMPLES.");
8947         }
8948
8949         return is_ok;
8950 }
8951
8952 /** @brief Clean GL objects, test variables and GL errors.
8953  */
8954 void StorageErrorsTest::Clean()
8955 {
8956         /* Shortcut for GL functionality. */
8957         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8958
8959         /* Cleanup. */
8960         if (m_to_1D)
8961         {
8962                 gl.deleteTextures(1, &m_to_1D);
8963
8964                 m_to_1D = 0;
8965         }
8966
8967         if (m_to_1D_array)
8968         {
8969                 gl.deleteTextures(1, &m_to_1D_array);
8970
8971                 m_to_1D_array = 0;
8972         }
8973
8974         if (m_to_2D)
8975         {
8976                 gl.deleteTextures(1, &m_to_2D);
8977
8978                 m_to_2D = 0;
8979         }
8980
8981         if (m_to_2D_array)
8982         {
8983                 gl.deleteTextures(1, &m_to_2D_array);
8984
8985                 m_to_2D_array = 0;
8986         }
8987
8988         if (m_to_3D)
8989         {
8990                 gl.deleteTextures(1, &m_to_3D);
8991
8992                 m_to_3D = 0;
8993         }
8994
8995         if (m_to_2D_ms)
8996         {
8997                 gl.deleteTextures(1, &m_to_2D_ms);
8998
8999                 m_to_2D_ms = 0;
9000         }
9001
9002         if (m_to_2D_ms_immutable)
9003         {
9004                 gl.deleteTextures(1, &m_to_2D_ms_immutable);
9005
9006                 m_to_2D_ms_immutable = 0;
9007         }
9008
9009         if (m_to_3D_ms)
9010         {
9011                 gl.deleteTextures(1, &m_to_3D_ms);
9012
9013                 m_to_3D_ms = 0;
9014         }
9015
9016         if (m_to_3D_ms_immutable)
9017         {
9018                 gl.deleteTextures(1, &m_to_3D_ms_immutable);
9019
9020                 m_to_3D_ms_immutable = 0;
9021         }
9022
9023         m_to_invalid                       = 0;
9024         m_internalformat_invalid   = 0;
9025         m_max_texture_size                 = 1;
9026         m_max_samples                      = 1;
9027         m_max_array_texture_layers = 1;
9028
9029         while (GL_NO_ERROR != gl.getError())
9030                 ;
9031 }
9032
9033 /******************************** Texture SubImage Errors Test Implementation   ********************************/
9034
9035 /** @brief Texture SubImage Errors Test constructor.
9036  *
9037  *  @param [in] context     OpenGL context.
9038  */
9039 SubImageErrorsTest::SubImageErrorsTest(deqp::Context& context)
9040         : deqp::TestCase(context, "textures_subimage_errors", "Texture SubImage Errors Test")
9041         , m_to_1D_empty(0)
9042         , m_to_2D_empty(0)
9043         , m_to_3D_empty(0)
9044         , m_to_1D(0)
9045         , m_to_2D(0)
9046         , m_to_3D(0)
9047         , m_to_1D_compressed(0)
9048         , m_to_2D_compressed(0)
9049         , m_to_3D_compressed(0)
9050         , m_to_rectangle_compressed(0)
9051         , m_to_invalid(0)
9052         , m_bo(0)
9053         , m_format_invalid(0)
9054         , m_type_invalid(0)
9055         , m_max_texture_size(1)
9056         , m_reference_compressed_1D(DE_NULL)
9057         , m_reference_compressed_2D(DE_NULL)
9058         , m_reference_compressed_3D(DE_NULL)
9059         , m_reference_compressed_rectangle(DE_NULL)
9060         , m_reference_compressed_1D_size(0)
9061         , m_reference_compressed_2D_size(0)
9062         , m_reference_compressed_3D_size(0)
9063         , m_reference_compressed_rectangle_size(0)
9064         , m_reference_compressed_1D_format(0)
9065         , m_reference_compressed_2D_format(0)
9066         , m_reference_compressed_3D_format(0)
9067         , m_reference_compressed_rectangle_format(0)
9068         , m_not_matching_compressed_1D_format(0)
9069         , m_not_matching_compressed_1D_size(0)
9070         , m_not_matching_compressed_2D_format(0)
9071         , m_not_matching_compressed_2D_size(0)
9072         , m_not_matching_compressed_3D_format(0)
9073         , m_not_matching_compressed_3D_size(0)
9074 {
9075         /* Intentionally left blank. */
9076 }
9077
9078 /** @brief Iterate Texture SubImage Errors Test cases.
9079  *
9080  *  @return Iteration result.
9081  */
9082 tcu::TestNode::IterateResult SubImageErrorsTest::iterate()
9083 {
9084         /* Get context setup. */
9085         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
9086         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
9087
9088         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
9089         {
9090                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
9091
9092                 return STOP;
9093         }
9094
9095         /* Running tests. */
9096         bool is_ok      = true;
9097         bool is_error = false;
9098
9099         try
9100         {
9101                 Prepare();
9102
9103                 is_ok &= Test1D();
9104                 is_ok &= Test2D();
9105                 is_ok &= Test3D();
9106                 is_ok &= Test1DCompressed();
9107                 is_ok &= Test2DCompressed();
9108                 is_ok &= Test3DCompressed();
9109         }
9110         catch (...)
9111         {
9112                 is_ok   = false;
9113                 is_error = true;
9114         }
9115
9116         /* Cleanup. */
9117         Clean();
9118
9119         /* Result's setup. */
9120         if (is_ok)
9121         {
9122                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
9123         }
9124         else
9125         {
9126                 if (is_error)
9127                 {
9128                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
9129                 }
9130                 else
9131                 {
9132                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
9133                 }
9134         }
9135
9136         return STOP;
9137 }
9138
9139 /** @brief Prepare test's objects.
9140  */
9141 void SubImageErrorsTest::Prepare()
9142 {
9143         /* Shortcut for GL functionality. */
9144         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
9145
9146         /* Auxiliary objects setup. */
9147
9148         /* 1D */
9149         gl.createTextures(GL_TEXTURE_1D, 1, &m_to_1D_empty);
9150         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9151
9152         /* 2D */
9153         gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D_empty);
9154         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9155
9156         /* 3D */
9157         gl.createTextures(GL_TEXTURE_3D, 1, &m_to_3D_empty);
9158         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9159
9160         /* 1D */
9161         gl.createTextures(GL_TEXTURE_1D, 1, &m_to_1D);
9162         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9163
9164         gl.bindTexture(GL_TEXTURE_1D, m_to_1D);
9165         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9166
9167         gl.texImage1D(GL_TEXTURE_1D, 0, s_reference_internalformat, s_reference_width, 0, s_reference_format,
9168                                   GL_UNSIGNED_BYTE, s_reference);
9169         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
9170
9171         /* 2D */
9172         gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D);
9173         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9174
9175         gl.bindTexture(GL_TEXTURE_2D, m_to_2D);
9176         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9177
9178         gl.texImage2D(GL_TEXTURE_2D, 0, s_reference_internalformat, s_reference_width, s_reference_height, 0,
9179                                   s_reference_format, GL_UNSIGNED_BYTE, s_reference);
9180         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
9181
9182         /* 3D */
9183         gl.createTextures(GL_TEXTURE_3D, 1, &m_to_3D);
9184         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9185
9186         gl.bindTexture(GL_TEXTURE_3D, m_to_3D);
9187         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9188
9189         gl.texImage3D(GL_TEXTURE_3D, 0, s_reference_internalformat, s_reference_width, s_reference_height,
9190                                   s_reference_depth, 0, s_reference_format, GL_UNSIGNED_BYTE, s_reference);
9191         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
9192
9193         /* 1D Compressed */
9194         gl.createTextures(GL_TEXTURE_1D, 1, &m_to_1D_compressed);
9195         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9196
9197         gl.bindTexture(GL_TEXTURE_1D, m_to_1D_compressed);
9198         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9199
9200         gl.texImage1D(GL_TEXTURE_1D, 0, s_reference_internalformat_compressed, s_reference_width, 0, s_reference_format,
9201                                   GL_UNSIGNED_BYTE, s_reference);
9202         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
9203
9204         glw::GLint is_compressed = 0;
9205
9206         gl.getTexLevelParameteriv(GL_TEXTURE_1D, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9207         GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9208
9209         if (is_compressed)
9210         {
9211                 gl.getTexLevelParameteriv(GL_TEXTURE_1D, 0, GL_TEXTURE_INTERNAL_FORMAT, &m_reference_compressed_1D_format);
9212                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9213
9214                 m_reference_compressed_1D_size = 0;
9215
9216                 gl.getTexLevelParameteriv(GL_TEXTURE_1D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &m_reference_compressed_1D_size);
9217                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9218
9219                 if (m_reference_compressed_1D_size)
9220                 {
9221                         m_reference_compressed_1D = new glw::GLubyte[m_reference_compressed_1D_size];
9222
9223                         gl.getCompressedTexImage(GL_TEXTURE_1D, 0, m_reference_compressed_1D);
9224                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
9225                 }
9226         }
9227
9228         /* 2D Compressed */
9229         gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D_compressed);
9230         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9231
9232         gl.bindTexture(GL_TEXTURE_2D, m_to_2D_compressed);
9233         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9234
9235         gl.texImage2D(GL_TEXTURE_2D, 0, s_reference_internalformat_compressed, s_reference_width, s_reference_height, 0,
9236                                   s_reference_format, GL_UNSIGNED_BYTE, s_reference);
9237         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
9238
9239         is_compressed = 0;
9240
9241         gl.getTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9242         GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9243
9244         if (is_compressed)
9245         {
9246                 gl.getTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &m_reference_compressed_2D_format);
9247                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9248
9249                 m_reference_compressed_2D_size = 0;
9250
9251                 gl.getTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &m_reference_compressed_2D_size);
9252                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9253
9254                 if (m_reference_compressed_2D_size)
9255                 {
9256                         m_reference_compressed_2D = new glw::GLubyte[m_reference_compressed_2D_size];
9257
9258                         gl.getCompressedTexImage(GL_TEXTURE_2D, 0, m_reference_compressed_2D);
9259                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
9260                 }
9261         }
9262
9263         /* 3D Compressed */
9264         gl.createTextures(GL_TEXTURE_2D_ARRAY, 1, &m_to_3D_compressed);
9265         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9266
9267         gl.bindTexture(GL_TEXTURE_2D_ARRAY, m_to_3D_compressed);
9268         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9269
9270         gl.texImage3D(GL_TEXTURE_2D_ARRAY, 0, s_reference_internalformat_compressed, s_reference_width, s_reference_height,
9271                                   s_reference_depth, 0, s_reference_format, GL_UNSIGNED_BYTE, s_reference);
9272         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage3D has failed");
9273
9274         is_compressed = 0;
9275
9276         gl.getTexLevelParameteriv(GL_TEXTURE_2D_ARRAY, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9277         GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9278
9279         if (is_compressed)
9280         {
9281                 gl.getTexLevelParameteriv(GL_TEXTURE_2D_ARRAY, 0, GL_TEXTURE_INTERNAL_FORMAT,
9282                                                                   &m_reference_compressed_3D_format);
9283                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9284
9285                 m_reference_compressed_3D_size = 0;
9286
9287                 gl.getTexLevelParameteriv(GL_TEXTURE_2D_ARRAY, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
9288                                                                   &m_reference_compressed_3D_size);
9289                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9290
9291                 if (m_reference_compressed_3D_size)
9292                 {
9293                         m_reference_compressed_3D = new glw::GLubyte[m_reference_compressed_3D_size];
9294
9295                         gl.getCompressedTexImage(GL_TEXTURE_2D_ARRAY, 0, m_reference_compressed_3D);
9296                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
9297                 }
9298         }
9299
9300         /* RECTANGLE Compressed */
9301         gl.createTextures(GL_TEXTURE_RECTANGLE, 1, &m_to_rectangle_compressed);
9302         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9303
9304         gl.bindTexture(GL_TEXTURE_RECTANGLE, m_to_rectangle_compressed);
9305         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9306
9307         gl.texImage2D(GL_TEXTURE_RECTANGLE, 0, s_reference_internalformat_compressed, s_reference_width, s_reference_height,
9308                                   0, s_reference_format, GL_UNSIGNED_BYTE, s_reference);
9309         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
9310
9311         is_compressed = 0;
9312
9313         gl.getTexLevelParameteriv(GL_TEXTURE_RECTANGLE, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9314         GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9315
9316         if (is_compressed)
9317         {
9318                 gl.getTexLevelParameteriv(GL_TEXTURE_RECTANGLE, 0, GL_TEXTURE_INTERNAL_FORMAT,
9319                                                                   &m_reference_compressed_rectangle_format);
9320                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9321
9322                 m_reference_compressed_rectangle_size = 0;
9323
9324                 gl.getTexLevelParameteriv(GL_TEXTURE_RECTANGLE, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
9325                                                                   &m_reference_compressed_rectangle_size);
9326                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9327
9328                 if (m_reference_compressed_rectangle_size)
9329                 {
9330                         m_reference_compressed_rectangle = new glw::GLubyte[m_reference_compressed_rectangle_size];
9331
9332                         gl.getCompressedTexImage(GL_TEXTURE_RECTANGLE, 0, m_reference_compressed_rectangle);
9333                         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
9334                 }
9335         }
9336
9337         /* Buffer object */
9338         gl.createBuffers(1, &m_bo);
9339         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateBuffers has failed");
9340
9341         gl.namedBufferData(m_bo, s_reference_size, s_reference, GL_STATIC_COPY);
9342         GLU_EXPECT_NO_ERROR(gl.getError(), "glNamedBufferData has failed");
9343
9344         /* Invalid values */
9345
9346         /* invalid texture object */
9347         while (gl.isTexture(++m_to_invalid))
9348                 ;
9349         GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed");
9350
9351         /* invalid internal format */
9352         static const glw::GLenum all_formats[] = { GL_STENCIL_INDEX,
9353                                                                                            GL_DEPTH_COMPONENT,
9354                                                                                            GL_DEPTH_STENCIL,
9355                                                                                            GL_RED,
9356                                                                                            GL_GREEN,
9357                                                                                            GL_BLUE,
9358                                                                                            GL_RG,
9359                                                                                            GL_RGB,
9360                                                                                            GL_RGBA,
9361                                                                                            GL_BGR,
9362                                                                                            GL_BGRA,
9363                                                                                            GL_RED_INTEGER,
9364                                                                                            GL_GREEN_INTEGER,
9365                                                                                            GL_BLUE_INTEGER,
9366                                                                                            GL_RG_INTEGER,
9367                                                                                            GL_RGB_INTEGER,
9368                                                                                            GL_RGBA_INTEGER,
9369                                                                                            GL_BGR_INTEGER,
9370                                                                                            GL_BGRA_INTEGER };
9371
9372         static const glw::GLuint all_internal_formats_count = sizeof(all_formats) / sizeof(all_formats[0]);
9373
9374         bool is_valid   = true;
9375         m_format_invalid = 0;
9376
9377         while (is_valid)
9378         {
9379                 is_valid = false;
9380                 m_format_invalid++;
9381                 for (glw::GLuint i = 0; i < all_internal_formats_count; ++i)
9382                 {
9383                         if (all_formats[i] == m_format_invalid)
9384                         {
9385                                 is_valid = true;
9386                                 break;
9387                         }
9388                 }
9389         }
9390
9391         /* Invalid type. */
9392         static const glw::GLenum all_types[] = { GL_UNSIGNED_BYTE,
9393                                                                                          GL_BYTE,
9394                                                                                          GL_UNSIGNED_SHORT,
9395                                                                                          GL_SHORT,
9396                                                                                          GL_UNSIGNED_INT,
9397                                                                                          GL_INT,
9398                                                                                          GL_HALF_FLOAT,
9399                                                                                          GL_FLOAT,
9400                                                                                          GL_UNSIGNED_BYTE_3_3_2,
9401                                                                                          GL_UNSIGNED_BYTE_2_3_3_REV,
9402                                                                                          GL_UNSIGNED_SHORT_5_6_5,
9403                                                                                          GL_UNSIGNED_SHORT_5_6_5_REV,
9404                                                                                          GL_UNSIGNED_SHORT_4_4_4_4,
9405                                                                                          GL_UNSIGNED_SHORT_4_4_4_4_REV,
9406                                                                                          GL_UNSIGNED_SHORT_5_5_5_1,
9407                                                                                          GL_UNSIGNED_SHORT_1_5_5_5_REV,
9408                                                                                          GL_UNSIGNED_INT_8_8_8_8,
9409                                                                                          GL_UNSIGNED_INT_8_8_8_8_REV,
9410                                                                                          GL_UNSIGNED_INT_10_10_10_2,
9411                                                                                          GL_UNSIGNED_INT_2_10_10_10_REV,
9412                                                                                          GL_UNSIGNED_INT_24_8,
9413                                                                                          GL_UNSIGNED_INT_10F_11F_11F_REV,
9414                                                                                          GL_UNSIGNED_INT_5_9_9_9_REV,
9415                                                                                          GL_FLOAT_32_UNSIGNED_INT_24_8_REV };
9416
9417         static const glw::GLuint all_types_count = sizeof(all_types) / sizeof(all_types[0]);
9418
9419         is_valid           = true;
9420         m_type_invalid = 0;
9421
9422         while (is_valid)
9423         {
9424                 is_valid = false;
9425                 m_type_invalid++;
9426                 for (glw::GLuint i = 0; i < all_types_count; ++i)
9427                 {
9428                         if (all_types[i] == m_type_invalid)
9429                         {
9430                                 is_valid = true;
9431                                 break;
9432                         }
9433                 }
9434         }
9435
9436         /* Maximum texture size.*/
9437         gl.getIntegerv(GL_MAX_TEXTURE_SIZE, &m_max_texture_size);
9438         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
9439
9440         glw::GLenum not_matching_format                                    = GL_RED;
9441         glw::GLenum not_matching_internalformat_compressed = GL_COMPRESSED_RED;
9442
9443         /* 1D Compressed with a non matching format. We need to do all the allocation to get the correct image size */
9444         glw::GLuint to_1D_compressed_not_matching;
9445
9446         gl.createTextures(GL_TEXTURE_1D, 1, &to_1D_compressed_not_matching);
9447         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9448
9449         gl.bindTexture(GL_TEXTURE_1D, to_1D_compressed_not_matching);
9450         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9451
9452         gl.texImage1D(GL_TEXTURE_1D, 0, not_matching_internalformat_compressed, s_reference_width, 0, s_reference_format,
9453                                   GL_UNSIGNED_BYTE, s_reference);
9454         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
9455
9456         is_compressed = 0;
9457
9458         gl.getTexLevelParameteriv(GL_TEXTURE_1D, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9459         GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9460
9461         if (is_compressed)
9462         {
9463                 gl.getTexLevelParameteriv(GL_TEXTURE_1D, 0, GL_TEXTURE_INTERNAL_FORMAT, &m_not_matching_compressed_1D_format);
9464                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9465
9466                 m_not_matching_compressed_1D_size = 0;
9467
9468                 gl.getTexLevelParameteriv(GL_TEXTURE_1D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
9469                                                                   &m_not_matching_compressed_1D_size);
9470                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9471         }
9472
9473         gl.deleteTextures(1, &to_1D_compressed_not_matching);
9474         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9475
9476         /* 2D Compressed with a non matching format. We need to do all the allocation to get the correct image size */
9477         glw::GLuint to_2D_compressed_not_matching;
9478
9479         gl.createTextures(GL_TEXTURE_2D, 1, &to_2D_compressed_not_matching);
9480         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9481
9482         gl.bindTexture(GL_TEXTURE_2D, to_2D_compressed_not_matching);
9483         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9484
9485         gl.texImage2D(GL_TEXTURE_2D, 0, not_matching_internalformat_compressed, s_reference_width, s_reference_height, 0,
9486                                   not_matching_format, GL_UNSIGNED_BYTE, s_reference);
9487         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
9488
9489         is_compressed = 0;
9490
9491         gl.getTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9492         GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9493
9494         if (is_compressed)
9495         {
9496                 gl.getTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &m_not_matching_compressed_2D_format);
9497                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9498
9499                 m_not_matching_compressed_2D_size = 0;
9500
9501                 gl.getTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
9502                                                                   &m_not_matching_compressed_2D_size);
9503                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9504         }
9505
9506         gl.deleteTextures(1, &to_2D_compressed_not_matching);
9507         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9508
9509         /* 3D Compressed with a non matching format. We need to do all the allocation to get the correct image size */
9510         glw::GLuint to_3D_compressed_not_matching;
9511
9512         gl.createTextures(GL_TEXTURE_3D, 1, &to_3D_compressed_not_matching);
9513         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9514
9515         gl.bindTexture(GL_TEXTURE_3D, to_3D_compressed_not_matching);
9516         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9517
9518         gl.texImage3D(GL_TEXTURE_3D, 0, not_matching_internalformat_compressed, s_reference_width, s_reference_height,
9519                                   s_reference_depth, 0, not_matching_format, GL_UNSIGNED_BYTE, s_reference);
9520         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage3D has failed");
9521
9522         is_compressed = 0;
9523
9524         gl.getTexLevelParameteriv(GL_TEXTURE_3D, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9525         GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9526
9527         if (is_compressed)
9528         {
9529                 gl.getTexLevelParameteriv(GL_TEXTURE_3D, 0, GL_TEXTURE_INTERNAL_FORMAT, &m_not_matching_compressed_3D_format);
9530                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9531
9532                 m_not_matching_compressed_3D_size = 0;
9533
9534                 gl.getTexLevelParameteriv(GL_TEXTURE_3D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
9535                                                                   &m_not_matching_compressed_3D_size);
9536                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9537         }
9538
9539         gl.deleteTextures(1, &to_3D_compressed_not_matching);
9540         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9541 }
9542
9543 /** @brief Test (negative) of TextureSubImage1D
9544  *
9545  *  @return Test result.
9546  */
9547 bool SubImageErrorsTest::Test1D()
9548 {
9549         /* Shortcut for GL functionality. */
9550         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
9551
9552         /* Result. */
9553         bool is_ok = true;
9554
9555         /* Check that INVALID_OPERATION is generated by TextureSubImage1D if
9556          texture is not the name of an existing texture object. */
9557         {
9558                 gl.textureSubImage1D(m_to_invalid, 0, 0, s_reference_width, s_reference_format, s_reference_type, s_reference);
9559                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9560                                                                   "texture is not the name of an existing texture object.");
9561         }
9562
9563         /* Check that INVALID_ENUM is generated by TextureSubImage1D if format is
9564          not an accepted format constant. */
9565         {
9566                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, m_format_invalid, s_reference_type, s_reference);
9567                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureSubImage1D",
9568                                                                   "format is not an accepted format constant.");
9569         }
9570
9571         /* Check that INVALID_ENUM is generated by TextureSubImage1D if type is not
9572          an accepted type constant. */
9573         {
9574                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, m_type_invalid, s_reference);
9575                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureSubImage1D",
9576                                                                   "type is not an accepted type constant.");
9577         }
9578
9579         /* Check that INVALID_VALUE is generated by TextureSubImage1D if level is
9580          less than 0. */
9581         {
9582                 gl.textureSubImage1D(m_to_1D, -1, 0, s_reference_width, s_reference_format, s_reference_type, s_reference);
9583                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D", "level is less than 0.");
9584         }
9585
9586         /* Check that INVALID_VALUE may be generated by TextureSubImage1D if level
9587          is greater than log2 max, where max is the returned value of
9588          MAX_TEXTURE_SIZE. */
9589         {
9590                 gl.textureSubImage1D(m_to_1D, m_max_texture_size, 0, s_reference_width, s_reference_format, s_reference_type,
9591                                                          s_reference);
9592                 is_ok &=
9593                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D",
9594                                                          "level is greater than log2 max, where max is the returned value of MAX_TEXTURE_SIZE.");
9595         }
9596
9597         /* Check that INVALID_VALUE is generated by TextureSubImage1D if
9598          xoffset<-b, or if (xoffset+width)>(w-b), where w is the TEXTURE_WIDTH,
9599          and b is the width of the TEXTURE_BORDER of the texture image being
9600          modified. Note that w includes twice the border width. */
9601         {
9602                 gl.textureSubImage1D(m_to_1D, 0, -1, s_reference_width, s_reference_format, s_reference_type, s_reference);
9603                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D",
9604                                                                   "xoffset<-b, where b is the width of the TEXTURE_BORDER.");
9605
9606                 gl.textureSubImage1D(m_to_1D, 0, 1, s_reference_width + 1, s_reference_format, s_reference_type, s_reference);
9607                 is_ok &= CheckErrorAndLog(
9608                         m_context, GL_INVALID_VALUE, "glTextureSubImage1D",
9609                         "(xoffset+width)>(w-b), where w is the TEXTURE_WIDTH, b is the width of the TEXTURE_BORDER.");
9610         }
9611
9612         /*Check that INVALID_VALUE is generated by TextureSubImage1D if width is less than 0. */
9613         {
9614 #ifndef TURN_OFF_SUB_IMAGE_ERRORS_TEST_OF_NEGATIVE_WIDTH_HEIGHT_OR_DEPTH
9615                 gl.textureSubImage1D(m_to_1D, 0, 0, -1, s_reference_format, s_reference_type, s_reference);
9616                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D", "width is less than 0.");
9617 #endif
9618         }
9619
9620         /* Check that INVALID_OPERATION is generated by TextureSubImage1D if type
9621          is one of UNSIGNED_BYTE_3_3_2, UNSIGNED_BYTE_2_3_3_REV,
9622          UNSIGNED_SHORT_5_6_5, or UNSIGNED_SHORT_5_6_5_REV and format is not RGB. */
9623         {
9624                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_BYTE_3_3_2, s_reference);
9625                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9626                                                                   "type is UNSIGNED_BYTE_3_3_2 and format is not RGB.");
9627
9628                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_BYTE_2_3_3_REV,
9629                                                          s_reference);
9630                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9631                                                                   "type is UNSIGNED_BYTE_2_3_3_REV and format is not RGB.");
9632
9633                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_SHORT_5_6_5,
9634                                                          s_reference);
9635                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9636                                                                   "type is UNSIGNED_SHORT_5_6_5 and format is not RGB.");
9637
9638                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_SHORT_5_6_5_REV,
9639                                                          s_reference);
9640                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9641                                                                   "type is UNSIGNED_SHORT_5_6_5_REV and format is not RGB.");
9642         }
9643
9644         /* Check that INVALID_OPERATION is generated by TextureSubImage1D if type
9645          is one of UNSIGNED_SHORT_4_4_4_4, UNSIGNED_SHORT_4_4_4_4_REV,
9646          UNSIGNED_SHORT_5_5_5_1, UNSIGNED_SHORT_1_5_5_5_REV,
9647          UNSIGNED_INT_8_8_8_8, UNSIGNED_INT_8_8_8_8_REV, UNSIGNED_INT_10_10_10_2,
9648          or UNSIGNED_INT_2_10_10_10_REV and format is neither RGBA nor BGRA. */
9649         {
9650                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_SHORT_4_4_4_4,
9651                                                          s_reference);
9652                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9653                                                                   "type is UNSIGNED_SHORT_4_4_4_4 and format is neither RGBA nor BGRA.");
9654
9655                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_SHORT_4_4_4_4_REV,
9656                                                          s_reference);
9657                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9658                                                                   "type is UNSIGNED_SHORT_4_4_4_4_REV and format is neither RGBA nor BGRA.");
9659
9660                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_SHORT_5_5_5_1,
9661                                                          s_reference);
9662                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9663                                                                   "type is UNSIGNED_SHORT_5_5_5_1 and format is neither RGBA nor BGRA.");
9664
9665                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_SHORT_1_5_5_5_REV,
9666                                                          s_reference);
9667                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9668                                                                   "type is UNSIGNED_SHORT_1_5_5_5_REV and format is neither RGBA nor BGRA.");
9669
9670                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_INT_8_8_8_8,
9671                                                          s_reference);
9672                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9673                                                                   "type is UNSIGNED_INT_8_8_8_8 and format is neither RGBA nor BGRA.");
9674
9675                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_INT_8_8_8_8_REV,
9676                                                          s_reference);
9677                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9678                                                                   "type is UNSIGNED_INT_8_8_8_8_REV and format is neither RGBA nor BGRA.");
9679
9680                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_INT_10_10_10_2,
9681                                                          s_reference);
9682                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9683                                                                   "type is UNSIGNED_INT_10_10_10_2 and format is neither RGBA nor BGRA.");
9684
9685                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_INT_2_10_10_10_REV,
9686                                                          s_reference);
9687                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9688                                                                   "type is UNSIGNED_INT_2_10_10_10_REV and format is neither RGBA nor BGRA.");
9689         }
9690
9691         /* Check that INVALID_OPERATION is generated by TextureSubImage1D if a
9692          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
9693          and the buffer object's data store is currently mapped. */
9694         {
9695                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
9696                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9697
9698                 gl.mapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
9699
9700                 if (GL_NO_ERROR == gl.getError())
9701                 {
9702                         gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, s_reference_type, NULL);
9703                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9704                                                                           "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and "
9705                                                                           "the buffer object's data store is currently mapped.");
9706
9707                         gl.unmapBuffer(GL_PIXEL_UNPACK_BUFFER);
9708                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9709
9710                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
9711                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9712                 }
9713         }
9714
9715         /* Check that INVALID_OPERATION is generated by TextureSubImage1D if a
9716          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
9717          and the data would be unpacked from the buffer object such that the
9718          memory reads required would exceed the data store size. */
9719         {
9720                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
9721                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9722
9723                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, s_reference_type,
9724                                                          (glw::GLubyte*)NULL + s_reference_size * 2);
9725                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9726                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and the "
9727                                                                   "data would be unpacked from the buffer object such that the memory reads required "
9728                                                                   "would exceed the data store size.");
9729
9730                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
9731                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9732         }
9733
9734         /* Check that INVALID_OPERATION is generated by TextureSubImage1D if a
9735          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
9736          and pixels is not evenly divisible into the number of bytes needed to
9737          store in memory a datum indicated by type. */
9738         {
9739                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
9740                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9741
9742                 gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, s_reference_type,
9743                                                          (glw::GLubyte*)NULL + 1);
9744                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9745                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and pixels "
9746                                                                   "is not evenly divisible into the number of bytes needed to store in memory a datum "
9747                                                                   "indicated by type.");
9748
9749                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
9750                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9751         }
9752
9753         return is_ok;
9754 }
9755
9756 /** @brief Test (negative) of TextureSubImage2D
9757  *
9758  *  @return Test result.
9759  */
9760 bool SubImageErrorsTest::Test2D()
9761 {
9762         /* Shortcut for GL functionality. */
9763         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
9764
9765         /* Result. */
9766         bool is_ok = true;
9767
9768         /* Check that INVALID_OPERATION is generated by TextureSubImage2D if
9769          texture is not the name of an existing texture object. */
9770         {
9771                 gl.textureSubImage2D(m_to_invalid, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9772                                                          s_reference_type, s_reference);
9773                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9774                                                                   "texture is not the name of an existing texture object.");
9775         }
9776
9777         /* Check that INVALID_ENUM is generated by TextureSubImage2D if format is
9778          not an accepted format constant. */
9779         {
9780                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, m_format_invalid,
9781                                                          s_reference_type, s_reference);
9782                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureSubImage2D",
9783                                                                   "format is not an accepted format constant.");
9784         }
9785
9786         /* Check that INVALID_ENUM is generated by TextureSubImage2D if type is not
9787          an accepted type constant. */
9788         {
9789                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9790                                                          m_type_invalid, s_reference);
9791                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureSubImage2D",
9792                                                                   "type is not an accepted type constant.");
9793         }
9794
9795         /* Check that INVALID_VALUE is generated by TextureSubImage2D if level is
9796          less than 0. */
9797         {
9798                 gl.textureSubImage2D(m_to_2D, -1, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9799                                                          s_reference_type, s_reference);
9800                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage2D", "level is less than 0.");
9801         }
9802
9803         /* Check that INVALID_VALUE may be generated by TextureSubImage2D if level
9804          is greater than log2 max, where max is the returned value of
9805          MAX_TEXTURE_SIZE. */
9806         {
9807                 gl.textureSubImage2D(m_to_2D, m_max_texture_size, 0, 0, s_reference_width, s_reference_height,
9808                                                          s_reference_format, s_reference_type, s_reference);
9809                 is_ok &=
9810                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage2D",
9811                                                          "level is greater than log2 max, where max is the returned value of MAX_TEXTURE_SIZE.");
9812         }
9813
9814         /* Check that INVALID_VALUE may be generated by TextureSubImage2D if level
9815          is greater than log2 max, where max is the returned value of
9816          MAX_TEXTURE_SIZE.
9817          Check that INVALID_VALUE is generated by TextureSubImage2D if
9818          xoffset<-b, (xoffset+width)>(w-b), yoffset<-b, or
9819          (yoffset+height)>(h-b), where w is the TEXTURE_WIDTH, h is the
9820          TEXTURE_HEIGHT, and b is the border width of the texture image being
9821          modified. Note that w and h include twice the border width. */
9822         {
9823                 gl.textureSubImage2D(m_to_2D, 0, -1, 0, s_reference_width, s_reference_height, s_reference_format,
9824                                                          s_reference_type, s_reference);
9825                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage2D",
9826                                                                   "xoffset<-b, where b is the width of the TEXTURE_BORDER.");
9827
9828                 gl.textureSubImage2D(m_to_2D, 0, 1, 0, s_reference_width + 1, s_reference_height, s_reference_format,
9829                                                          s_reference_type, s_reference);
9830                 is_ok &= CheckErrorAndLog(
9831                         m_context, GL_INVALID_VALUE, "glTextureSubImage2D",
9832                         "(xoffset+width)>(w-b), where w is the TEXTURE_WIDTH, b is the width of the TEXTURE_BORDER.");
9833
9834                 gl.textureSubImage2D(m_to_2D, 0, 0, -1, s_reference_width, s_reference_height, s_reference_format,
9835                                                          s_reference_type, s_reference);
9836                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage2D",
9837                                                                   "yoffset<-b, where b is the height of the TEXTURE_BORDER.");
9838
9839                 gl.textureSubImage2D(m_to_2D, 0, 0, 1, s_reference_width + 1, s_reference_height, s_reference_format,
9840                                                          s_reference_type, s_reference);
9841                 is_ok &= CheckErrorAndLog(
9842                         m_context, GL_INVALID_VALUE, "glTextureSubImage2D",
9843                         "(yoffset+height)>(h-b), where h is the TEXTURE_HEIGHT, b is the width of the TEXTURE_BORDER.");
9844         }
9845
9846         /*Check that INVALID_VALUE is generated by TextureSubImage2D if width or height is less than 0. */
9847         {
9848 #ifndef TURN_OFF_SUB_IMAGE_ERRORS_TEST_OF_NEGATIVE_WIDTH_HEIGHT_OR_DEPTH
9849                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, -1, s_reference_height, s_reference_format, s_reference_type,
9850                                                          s_reference);
9851                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage2D", "width is less than 0.");
9852
9853                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, -1, s_reference_format, s_reference_type,
9854                                                          s_reference);
9855                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage2D", "height is less than 0.");
9856 #endif
9857         }
9858
9859         /* Check that INVALID_OPERATION is generated by TextureSubImage2D if type
9860          is one of UNSIGNED_BYTE_3_3_2, UNSIGNED_BYTE_2_3_3_REV,
9861          UNSIGNED_SHORT_5_6_5, or UNSIGNED_SHORT_5_6_5_REV and format is not RGB. */
9862         {
9863                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9864                                                          GL_UNSIGNED_BYTE_3_3_2, s_reference);
9865                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9866                                                                   "type is UNSIGNED_BYTE_3_3_2 and format is not RGB.");
9867
9868                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9869                                                          GL_UNSIGNED_BYTE_2_3_3_REV, s_reference);
9870                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9871                                                                   "type is UNSIGNED_BYTE_2_3_3_REV and format is not RGB.");
9872
9873                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9874                                                          GL_UNSIGNED_SHORT_5_6_5, s_reference);
9875                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9876                                                                   "type is UNSIGNED_SHORT_5_6_5 and format is not RGB.");
9877
9878                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9879                                                          GL_UNSIGNED_SHORT_5_6_5_REV, s_reference);
9880                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9881                                                                   "type is UNSIGNED_SHORT_5_6_5_REV and format is not RGB.");
9882         }
9883
9884         /* Check that INVALID_OPERATION is generated by TextureSubImage2D if type
9885          is one of UNSIGNED_SHORT_4_4_4_4, UNSIGNED_SHORT_4_4_4_4_REV,
9886          UNSIGNED_SHORT_5_5_5_1, UNSIGNED_SHORT_1_5_5_5_REV,
9887          UNSIGNED_INT_8_8_8_8, UNSIGNED_INT_8_8_8_8_REV, UNSIGNED_INT_10_10_10_2,
9888          or UNSIGNED_INT_2_10_10_10_REV and format is neither RGBA nor BGRA. */
9889         {
9890                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9891                                                          GL_UNSIGNED_SHORT_4_4_4_4, s_reference);
9892                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9893                                                                   "type is UNSIGNED_SHORT_4_4_4_4 and format is neither RGBA nor BGRA.");
9894
9895                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9896                                                          GL_UNSIGNED_SHORT_4_4_4_4_REV, s_reference);
9897                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9898                                                                   "type is UNSIGNED_SHORT_4_4_4_4_REV and format is neither RGBA nor BGRA.");
9899
9900                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9901                                                          GL_UNSIGNED_SHORT_5_5_5_1, s_reference);
9902                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9903                                                                   "type is UNSIGNED_SHORT_5_5_5_1 and format is neither RGBA nor BGRA.");
9904
9905                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9906                                                          GL_UNSIGNED_SHORT_1_5_5_5_REV, s_reference);
9907                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9908                                                                   "type is UNSIGNED_SHORT_1_5_5_5_REV and format is neither RGBA nor BGRA.");
9909
9910                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9911                                                          GL_UNSIGNED_INT_8_8_8_8, s_reference);
9912                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9913                                                                   "type is UNSIGNED_INT_8_8_8_8 and format is neither RGBA nor BGRA.");
9914
9915                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9916                                                          GL_UNSIGNED_INT_8_8_8_8_REV, s_reference);
9917                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9918                                                                   "type is UNSIGNED_INT_8_8_8_8_REV and format is neither RGBA nor BGRA.");
9919
9920                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9921                                                          GL_UNSIGNED_INT_10_10_10_2, s_reference);
9922                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9923                                                                   "type is UNSIGNED_INT_10_10_10_2 and format is neither RGBA nor BGRA.");
9924
9925                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9926                                                          GL_UNSIGNED_INT_2_10_10_10_REV, s_reference);
9927                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9928                                                                   "type is UNSIGNED_INT_2_10_10_10_REV and format is neither RGBA nor BGRA.");
9929         }
9930
9931         /* Check that INVALID_OPERATION is generated by TextureSubImage2D if a
9932          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
9933          and the buffer object's data store is currently mapped. */
9934         {
9935                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
9936                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9937
9938                 gl.mapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
9939
9940                 if (GL_NO_ERROR == gl.getError())
9941                 {
9942                         gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9943                                                                  s_reference_type, NULL);
9944                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9945                                                                           "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and "
9946                                                                           "the buffer object's data store is currently mapped.");
9947
9948                         gl.unmapBuffer(GL_PIXEL_UNPACK_BUFFER);
9949                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9950
9951                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
9952                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9953                 }
9954         }
9955
9956         /* Check that INVALID_OPERATION is generated by TextureSubImage2D if a
9957          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
9958          and the data would be unpacked from the buffer object such that the
9959          memory reads required would exceed the data store size. */
9960         {
9961                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
9962                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9963
9964                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9965                                                          s_reference_type, (glw::GLubyte*)NULL + s_reference_size * 2);
9966                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9967                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and the "
9968                                                                   "data would be unpacked from the buffer object such that the memory reads required "
9969                                                                   "would exceed the data store size.");
9970
9971                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
9972                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9973         }
9974
9975         /* Check that INVALID_OPERATION is generated by TextureSubImage2D if a
9976          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
9977          and pixels is not evenly divisible into the number of bytes needed to
9978          store in memory a datum indicated by type. */
9979         {
9980                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
9981                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9982
9983                 gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
9984                                                          s_reference_type, (glw::GLubyte*)NULL + 1);
9985                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
9986                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and pixels "
9987                                                                   "is not evenly divisible into the number of bytes needed to store in memory a datum "
9988                                                                   "indicated by type.");
9989
9990                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
9991                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9992         }
9993
9994         return is_ok;
9995 }
9996
9997 /** @brief Test (negative) of TextureSubImage3D
9998  *
9999  *  @return Test result.
10000  */
10001 bool SubImageErrorsTest::Test3D()
10002 {
10003         /* Shortcut for GL functionality. */
10004         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10005
10006         /* Result. */
10007         bool is_ok = true;
10008
10009         /* Check that INVALID_OPERATION is generated by TextureSubImage3D if
10010          texture is not the name of an existing texture object. */
10011         {
10012                 gl.textureSubImage3D(m_to_invalid, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10013                                                          s_reference_format, s_reference_type, s_reference);
10014                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10015                                                                   "texture is not the name of an existing texture object.");
10016         }
10017
10018         /* Check that INVALID_ENUM is generated by TextureSubImage3D if format is
10019          not an accepted format constant. */
10020         {
10021                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10022                                                          m_format_invalid, s_reference_type, s_reference);
10023                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureSubImage3D",
10024                                                                   "format is not an accepted format constant.");
10025         }
10026
10027         /* Check that INVALID_ENUM is generated by TextureSubImage3D if type is not
10028          an accepted type constant. */
10029         {
10030                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10031                                                          s_reference_format, m_type_invalid, s_reference);
10032                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureSubImage3D",
10033                                                                   "type is not an accepted type constant.");
10034         }
10035
10036         /* Check that INVALID_VALUE is generated by TextureSubImage3D if level is
10037          less than 0. */
10038         {
10039                 gl.textureSubImage3D(m_to_3D, -1, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10040                                                          s_reference_format, s_reference_type, s_reference);
10041                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage3D", "level is less than 0.");
10042         }
10043
10044         /* Check that INVALID_VALUE may be generated by TextureSubImage1D if level
10045          is greater than log2 max, where max is the returned value of
10046          MAX_TEXTURE_SIZE. */
10047         {
10048                 gl.textureSubImage3D(m_to_3D, m_max_texture_size, 0, 0, 0, s_reference_width, s_reference_height,
10049                                                          s_reference_depth, s_reference_format, s_reference_type, s_reference);
10050                 is_ok &=
10051                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10052                                                          "level is greater than log2 max, where max is the returned value of MAX_TEXTURE_SIZE.");
10053         }
10054
10055         /* Check that INVALID_VALUE is generated by TextureSubImage3D if
10056          xoffset<-b, (xoffset+width)>(w-b), yoffset<-b, or
10057          (yoffset+height)>(h-b), or zoffset<-b, or (zoffset+depth)>(d-b), where w
10058          is the TEXTURE_WIDTH, h is the TEXTURE_HEIGHT, d is the TEXTURE_DEPTH
10059          and b is the border width of the texture image being modified. Note
10060          that w, h, and d include twice the border width. */
10061         {
10062                 gl.textureSubImage3D(m_to_3D, 0, -1, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10063                                                          s_reference_format, s_reference_type, s_reference);
10064                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10065                                                                   "xoffset<-b, where b is the width of the TEXTURE_BORDER.");
10066
10067                 gl.textureSubImage3D(m_to_3D, 0, 1, 0, 0, s_reference_width + 1, s_reference_height, s_reference_depth,
10068                                                          s_reference_format, s_reference_type, s_reference);
10069                 is_ok &= CheckErrorAndLog(
10070                         m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10071                         "(xoffset+width)>(w-b), where w is the TEXTURE_WIDTH, b is the width of the TEXTURE_BORDER.");
10072
10073                 gl.textureSubImage3D(m_to_3D, 0, 0, -1, 0, s_reference_width, s_reference_height, s_reference_depth,
10074                                                          s_reference_format, s_reference_type, s_reference);
10075                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10076                                                                   "yoffset<-b, where b is the width of the TEXTURE_BORDER.");
10077
10078                 gl.textureSubImage3D(m_to_3D, 0, 0, 1, 0, s_reference_width + 1, s_reference_height, s_reference_depth,
10079                                                          s_reference_format, s_reference_type, s_reference);
10080                 is_ok &= CheckErrorAndLog(
10081                         m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10082                         "(yoffset+height)>(h-b), where h is the TEXTURE_HEIGHT, b is the width of the TEXTURE_BORDER.");
10083
10084                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, -1, s_reference_width, s_reference_height, s_reference_depth,
10085                                                          s_reference_format, s_reference_type, s_reference);
10086                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10087                                                                   "zoffset<-b, where b is the depth of the TEXTURE_BORDER.");
10088
10089                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 1, s_reference_width + 1, s_reference_height, s_reference_depth,
10090                                                          s_reference_format, s_reference_type, s_reference);
10091                 is_ok &= CheckErrorAndLog(
10092                         m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10093                         "(zoffset+width)>(d-b), where d is the TEXTURE_DEPTH, b is the width of the TEXTURE_BORDER.");
10094         }
10095
10096         /*Check that INVALID_VALUE is generated by TextureSubImage3D if width or height or depth is less than 0. */
10097         {
10098 #ifndef TURN_OFF_SUB_IMAGE_ERRORS_TEST_OF_NEGATIVE_WIDTH_HEIGHT_OR_DEPTH
10099                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, -1, s_reference_height, s_reference_depth, s_reference_format,
10100                                                          s_reference_type, s_reference);
10101                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D", "width is less than 0.");
10102
10103                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, -1, s_reference_depth, s_reference_format,
10104                                                          s_reference_type, s_reference);
10105                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D", "height is less than 0.");
10106
10107                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, -1, s_reference_format,
10108                                                          s_reference_type, s_reference);
10109                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D", "depth is less than 0.");
10110 #endif
10111         }
10112
10113         /* Check that INVALID_OPERATION is generated by TextureSubImage3D if type
10114          is one of UNSIGNED_BYTE_3_3_2, UNSIGNED_BYTE_2_3_3_REV,
10115          UNSIGNED_SHORT_5_6_5, or UNSIGNED_SHORT_5_6_5_REV and format is not RGB. */
10116         {
10117                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10118                                                          s_reference_format, GL_UNSIGNED_BYTE_3_3_2, s_reference);
10119                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10120                                                                   "type is UNSIGNED_BYTE_3_3_2 and format is not RGB.");
10121
10122                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10123                                                          s_reference_format, GL_UNSIGNED_BYTE_2_3_3_REV, s_reference);
10124                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10125                                                                   "type is UNSIGNED_BYTE_2_3_3_REV and format is not RGB.");
10126
10127                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10128                                                          s_reference_format, GL_UNSIGNED_SHORT_5_6_5, s_reference);
10129                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10130                                                                   "type is UNSIGNED_SHORT_5_6_5 and format is not RGB.");
10131
10132                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10133                                                          s_reference_format, GL_UNSIGNED_SHORT_5_6_5_REV, s_reference);
10134                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10135                                                                   "type is UNSIGNED_SHORT_5_6_5_REV and format is not RGB.");
10136         }
10137
10138         /* Check that INVALID_OPERATION is generated by TextureSubImage3D if type
10139          is one of UNSIGNED_SHORT_4_4_4_4, UNSIGNED_SHORT_4_4_4_4_REV,
10140          UNSIGNED_SHORT_5_5_5_1, UNSIGNED_SHORT_1_5_5_5_REV,
10141          UNSIGNED_INT_8_8_8_8, UNSIGNED_INT_8_8_8_8_REV, UNSIGNED_INT_10_10_10_2,
10142          or UNSIGNED_INT_2_10_10_10_REV and format is neither RGBA nor BGRA. */
10143         {
10144                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10145                                                          s_reference_format, GL_UNSIGNED_SHORT_4_4_4_4, s_reference);
10146                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10147                                                                   "type is UNSIGNED_SHORT_4_4_4_4 and format is neither RGBA nor BGRA.");
10148
10149                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10150                                                          s_reference_format, GL_UNSIGNED_SHORT_4_4_4_4_REV, s_reference);
10151                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10152                                                                   "type is UNSIGNED_SHORT_4_4_4_4_REV and format is neither RGBA nor BGRA.");
10153
10154                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10155                                                          s_reference_format, GL_UNSIGNED_SHORT_5_5_5_1, s_reference);
10156                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10157                                                                   "type is UNSIGNED_SHORT_5_5_5_1 and format is neither RGBA nor BGRA.");
10158
10159                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10160                                                          s_reference_format, GL_UNSIGNED_SHORT_1_5_5_5_REV, s_reference);
10161                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10162                                                                   "type is UNSIGNED_SHORT_1_5_5_5_REV and format is neither RGBA nor BGRA.");
10163
10164                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10165                                                          s_reference_format, GL_UNSIGNED_INT_8_8_8_8, s_reference);
10166                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10167                                                                   "type is UNSIGNED_INT_8_8_8_8 and format is neither RGBA nor BGRA.");
10168
10169                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10170                                                          s_reference_format, GL_UNSIGNED_INT_8_8_8_8_REV, s_reference);
10171                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10172                                                                   "type is UNSIGNED_INT_8_8_8_8_REV and format is neither RGBA nor BGRA.");
10173
10174                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10175                                                          s_reference_format, GL_UNSIGNED_INT_10_10_10_2, s_reference);
10176                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10177                                                                   "type is UNSIGNED_INT_10_10_10_2 and format is neither RGBA nor BGRA.");
10178
10179                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10180                                                          s_reference_format, GL_UNSIGNED_INT_2_10_10_10_REV, s_reference);
10181                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10182                                                                   "type is UNSIGNED_INT_2_10_10_10_REV and format is neither RGBA nor BGRA.");
10183         }
10184
10185         /* Check that INVALID_OPERATION is generated by TextureSubImage3D if a
10186          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
10187          and the buffer object's data store is currently mapped. */
10188         {
10189                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10190                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10191
10192                 gl.mapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
10193
10194                 if (GL_NO_ERROR == gl.getError())
10195                 {
10196                         gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10197                                                                  s_reference_format, s_reference_type, NULL);
10198                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10199                                                                           "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and "
10200                                                                           "the buffer object's data store is currently mapped.");
10201
10202                         gl.unmapBuffer(GL_PIXEL_UNPACK_BUFFER);
10203                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10204
10205                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10206                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10207                 }
10208         }
10209
10210         /* Check that INVALID_OPERATION is generated by TextureSubImage3D if a
10211          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
10212          and the data would be unpacked from the buffer object such that the
10213          memory reads required would exceed the data store size. */
10214         {
10215                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10216                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10217
10218                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10219                                                          s_reference_format, s_reference_type, (glw::GLubyte*)NULL + s_reference_size * 2);
10220                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10221                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and the "
10222                                                                   "data would be unpacked from the buffer object such that the memory reads required "
10223                                                                   "would exceed the data store size.");
10224
10225                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10226                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10227         }
10228
10229         /* Check that INVALID_OPERATION is generated by TextureSubImage3D if a
10230          non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
10231          and pixels is not evenly divisible into the number of bytes needed to
10232          store in memory a datum indicated by type. */
10233         {
10234                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10235                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10236
10237                 gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10238                                                          s_reference_format, s_reference_type, (glw::GLubyte*)NULL + 1);
10239                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10240                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and pixels "
10241                                                                   "is not evenly divisible into the number of bytes needed to store in memory a datum "
10242                                                                   "indicated by type.");
10243
10244                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10245                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10246         }
10247
10248         return is_ok;
10249 }
10250
10251 /** @brief Test (negative) of TextureSubImage1DCompressed
10252  *
10253  *  @return Test result.
10254  */
10255 bool SubImageErrorsTest::Test1DCompressed()
10256 {
10257         /* Shortcut for GL functionality. */
10258         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10259
10260         /* Result. */
10261         bool is_ok = true;
10262
10263         /* Do tests only if compressed 1D textures are supported. */
10264         if (DE_NULL != m_reference_compressed_1D)
10265         {
10266                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage1D
10267                  if texture is not the name of an existing texture object. */
10268                 {
10269                         gl.compressedTextureSubImage1D(m_to_invalid, 0, 0, s_reference_width, m_reference_compressed_1D_format,
10270                                                                                    m_reference_compressed_1D_size, m_reference_compressed_1D);
10271                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage1D",
10272                                                                           "texture is not the name of an existing texture object.");
10273                 }
10274
10275                 /* Check that INVALID_ENUM is generated by CompressedTextureSubImage1D if
10276                  internalformat is not one of the generic compressed internal formats:
10277                  COMPRESSED_RED, COMPRESSED_RG, COMPRESSED_RGB, COMPRESSED_RGBA.
10278                  COMPRESSED_SRGB, or COMPRESSED_SRGB_ALPHA. */
10279                 {
10280                         /* GL_COMPRESSED_RG_RGTC2 is not 1D as specification says. */
10281                         gl.compressedTextureSubImage1D(m_to_1D_compressed, 0, 0, s_reference_width, GL_COMPRESSED_RG_RGTC2,
10282                                                                                    m_reference_compressed_1D_size, m_reference_compressed_1D);
10283                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glCompressedTextureSubImage1D",
10284                                                                           "internalformat is of the generic compressed internal formats: COMPRESSED_RED, "
10285                                                                           "COMPRESSED_RG, COMPRESSED_RGB, COMPRESSED_RGBA. COMPRESSED_SRGB, or "
10286                                                                           "COMPRESSED_SRGB_ALPHA.");
10287                 }
10288
10289                 /* Check that INVALID_OPERATION is generated if format does not match the
10290                  internal format of the texture image being modified, since these
10291                  commands do not provide for image format conversion. */
10292                 {
10293                         gl.compressedTextureSubImage1D(m_to_1D_compressed, 0, 0, s_reference_width,
10294                                                                                    m_not_matching_compressed_1D_format, m_not_matching_compressed_1D_size,
10295                                                                                    m_reference_compressed_1D);
10296                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage1D",
10297                                                                           "format does not match the internal format of the texture image being modified, "
10298                                                                           "since these commands do not provide for image format conversion.");
10299                 }
10300
10301                 /* Check that INVALID_VALUE is generated by CompressedTextureSubImage1D if
10302                  imageSize is not consistent with the format, dimensions, and contents of
10303                  the specified compressed image data. */
10304                 {
10305                         gl.compressedTextureSubImage1D(m_to_1D_compressed, 0, 0, s_reference_width,
10306                                                                                    m_reference_compressed_1D_format, m_reference_compressed_1D_size - 1,
10307                                                                                    m_reference_compressed_1D);
10308                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCompressedTextureSubImage1D",
10309                                                                           "imageSize is not consistent with the format, dimensions, and contents of the "
10310                                                                           "specified compressed image data.");
10311                 }
10312
10313                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage1D
10314                  if a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER
10315                  target and the buffer object's data store is currently mapped. */
10316                 {
10317                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10318                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10319
10320                         gl.mapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
10321
10322                         if (GL_NO_ERROR == gl.getError())
10323                         {
10324                                 gl.compressedTextureSubImage1D(m_to_1D_compressed, 0, 0, s_reference_width,
10325                                                                                            m_reference_compressed_1D_format, m_reference_compressed_1D_size, NULL);
10326                                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage1D",
10327                                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target "
10328                                                                                   "and the buffer object's data store is currently mapped.");
10329
10330                                 gl.unmapBuffer(GL_PIXEL_UNPACK_BUFFER);
10331                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10332
10333                                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10334                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10335                         }
10336                 }
10337
10338                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage1D
10339                  if a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER
10340                  target and the data would be unpacked from the buffer object such that
10341                  the memory reads required would exceed the data store size. */
10342                 {
10343                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10344                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10345
10346                         gl.compressedTextureSubImage1D(m_to_1D_compressed, 0, 0, s_reference_width,
10347                                                                                    m_reference_compressed_1D_format, m_reference_compressed_1D_size,
10348                                                                                    (glw::GLubyte*)NULL + s_reference_size * 2);
10349                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage1D",
10350                                                                           "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and "
10351                                                                           "the buffer object's data store is currently mapped.");
10352
10353                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10354                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10355                 }
10356         }
10357
10358         return is_ok;
10359 }
10360
10361 /** @brief Test (negative) of TextureSubImage2DCompressed
10362  *
10363  *  @return Test result.
10364  */
10365 bool SubImageErrorsTest::Test2DCompressed()
10366 {
10367         /* Shortcut for GL functionality. */
10368         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10369
10370         /* Result. */
10371         bool is_ok = true;
10372
10373         /* Do tests only if compressed 2D textures are supported. */
10374         if (DE_NULL != m_reference_compressed_2D)
10375         {
10376                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage2D
10377                  if texture is not the name of an existing texture object. */
10378                 {
10379                         gl.compressedTextureSubImage2D(m_to_invalid, 0, 0, 0, s_reference_width, s_reference_height,
10380                                                                                    m_reference_compressed_2D_format, m_reference_compressed_2D_size,
10381                                                                                    m_reference_compressed_2D);
10382                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage2D",
10383                                                                           "texture is not the name of an existing texture object.");
10384                 }
10385
10386                 /* Check that INVALID_ENUM is generated by CompressedTextureSubImage2D if
10387                  internalformat is of the generic compressed internal formats:
10388                  COMPRESSED_RED, COMPRESSED_RG, COMPRESSED_RGB, COMPRESSED_RGBA.
10389                  COMPRESSED_SRGB, or COMPRESSED_SRGB_ALPHA. */
10390                 {
10391                         gl.compressedTextureSubImage2D(m_to_2D_compressed, 0, 0, 0, s_reference_width, s_reference_height,
10392                                                                                    GL_COMPRESSED_RG, m_reference_compressed_2D_size, m_reference_compressed_2D);
10393                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glCompressedTextureSubImage2D",
10394                                                                           "internalformat is of the generic compressed internal formats: COMPRESSED_RED, "
10395                                                                           "COMPRESSED_RG, COMPRESSED_RGB, COMPRESSED_RGBA. COMPRESSED_SRGB, or "
10396                                                                           "COMPRESSED_SRGB_ALPHA.");
10397                 }
10398
10399                 /* Check that INVALID_OPERATION is generated if format does not match the
10400                  internal format of the texture image being modified, since these
10401                  commands do not provide for image format conversion. */
10402                 {
10403                         gl.compressedTextureSubImage2D(m_to_2D_compressed, 0, 0, 0, s_reference_width, s_reference_height,
10404                                                                                    m_not_matching_compressed_2D_format, m_not_matching_compressed_2D_size,
10405                                                                                    m_reference_compressed_2D);
10406                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage2D",
10407                                                                           "format does not match the internal format of the texture image being modified, "
10408                                                                           "since these commands do not provide for image format conversion.");
10409                 }
10410
10411                 /* Check that INVALID_VALUE is generated by CompressedTextureSubImage2D if
10412                  imageSize is not consistent with the format, dimensions, and contents of
10413                  the specified compressed image data. */
10414                 {
10415                         gl.compressedTextureSubImage2D(m_to_2D_compressed, 0, 0, 0, s_reference_width, s_reference_height,
10416                                                                                    m_reference_compressed_2D_format, m_reference_compressed_2D_size - 1,
10417                                                                                    m_reference_compressed_2D);
10418                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCompressedTextureSubImage2D",
10419                                                                           "imageSize is not consistent with the format, dimensions, and contents of the "
10420                                                                           "specified compressed image data.");
10421                 }
10422
10423                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage2D
10424                  if a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER
10425                  target and the buffer object's data store is currently mapped. */
10426                 {
10427                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10428                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10429
10430                         gl.mapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
10431
10432                         if (GL_NO_ERROR == gl.getError())
10433                         {
10434                                 gl.compressedTextureSubImage2D(m_to_2D_compressed, 0, 0, 0, s_reference_width, s_reference_height,
10435                                                                                            m_reference_compressed_2D_format, m_reference_compressed_2D_size, NULL);
10436                                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage2D",
10437                                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target "
10438                                                                                   "and the buffer object's data store is currently mapped.");
10439
10440                                 gl.unmapBuffer(GL_PIXEL_UNPACK_BUFFER);
10441                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10442
10443                                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10444                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10445                         }
10446                 }
10447
10448                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage2D
10449                  if a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER
10450                  target and the data would be unpacked from the buffer object such that
10451                  the memory reads required would exceed the data store size. */
10452                 {
10453                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10454                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10455
10456                         gl.compressedTextureSubImage2D(m_to_2D_compressed, 0, 0, 0, s_reference_width, s_reference_height,
10457                                                                                    m_reference_compressed_2D_format, m_reference_compressed_2D_size,
10458                                                                                    (glw::GLubyte*)NULL + s_reference_size * 2);
10459                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage2D",
10460                                                                           "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and "
10461                                                                           "the buffer object's data store is currently mapped.");
10462
10463                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10464                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10465                 }
10466
10467                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage2D
10468                  if the effective target is TEXTURE_RECTANGLE. */
10469                 if (DE_NULL !=
10470                         m_reference_compressed_rectangle) /* Do test only if rectangle compressed texture is supported by the implementation. */
10471                 {
10472                         gl.compressedTextureSubImage2D(m_to_rectangle_compressed, 0, 0, 0, s_reference_width, s_reference_height,
10473                                                                                    m_reference_compressed_rectangle_format,
10474                                                                                    m_reference_compressed_rectangle_size, m_reference_compressed_rectangle);
10475
10476                         if (m_context.getContextInfo().isExtensionSupported("GL_NV_texture_rectangle_compressed"))
10477                         {
10478                                 is_ok &= CheckErrorAndLog(m_context, GL_NO_ERROR, "glCompressedTextureSubImage2D",
10479                                                                                   "a rectangle texture object is used with this function.");
10480                         }
10481                         else
10482                         {
10483                                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage2D",
10484                                                                                   "a rectangle texture object is used with this function.");
10485                         }
10486                 }
10487         }
10488
10489         return is_ok;
10490 }
10491
10492 /** @brief Test (negative) of TextureSubImage3DCompressed
10493  *
10494  *  @return Test result.
10495  */
10496 bool SubImageErrorsTest::Test3DCompressed()
10497 {
10498         /* Shortcut for GL functionality. */
10499         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10500
10501         /* Result. */
10502         bool is_ok = true;
10503
10504         /* Do tests only if compressed 3D textures are supported. */
10505         if (DE_NULL != m_reference_compressed_3D)
10506         {
10507                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage3D
10508                  if texture is not the name of an existing texture object. */
10509                 {
10510                         gl.compressedTextureSubImage3D(m_to_invalid, 0, 0, 0, 0, s_reference_width, s_reference_height,
10511                                                                                    s_reference_depth, m_reference_compressed_3D_format,
10512                                                                                    m_reference_compressed_3D_size, m_reference_compressed_3D);
10513                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage3D",
10514                                                                           "texture is not the name of an existing texture object.");
10515                 }
10516
10517                 /* Check that INVALID_ENUM is generated by CompressedTextureSubImage3D if
10518                  internalformat is of the generic compressed internal formats:
10519                  COMPRESSED_RED, COMPRESSED_RG, COMPRESSED_RGB, COMPRESSED_RGBA.
10520                  COMPRESSED_SRGB, or COMPRESSED_SRGB_ALPHA. */
10521                 {
10522                         gl.compressedTextureSubImage3D(m_to_3D_compressed, 0, 0, 0, 0, s_reference_width, s_reference_height,
10523                                                                                    s_reference_depth, GL_COMPRESSED_RG, m_reference_compressed_3D_size,
10524                                                                                    m_reference_compressed_3D);
10525                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glCompressedTextureSubImage3D",
10526                                                                           "internalformat is of the generic compressed internal formats: COMPRESSED_RED, "
10527                                                                           "COMPRESSED_RG, COMPRESSED_RGB, COMPRESSED_RGBA. COMPRESSED_SRGB, or "
10528                                                                           "COMPRESSED_SRGB_ALPHA.");
10529                 }
10530
10531                 /* Check that INVALID_OPERATION is generated if format does not match the
10532                  internal format of the texture image being modified, since these
10533                  commands do not provide for image format conversion. */
10534                 {
10535                         gl.compressedTextureSubImage3D(m_to_3D_compressed, 0, 0, 0, 0, s_reference_width, s_reference_height,
10536                                                                                    s_reference_depth, m_not_matching_compressed_3D_format,
10537                                                                                    m_not_matching_compressed_3D_size, m_reference_compressed_3D);
10538                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage3D",
10539                                                                           "format does not match the internal format of the texture image being modified, "
10540                                                                           "since these commands do not provide for image format conversion.");
10541                 }
10542
10543                 /* Check that INVALID_VALUE is generated by CompressedTextureSubImage3D if
10544                  imageSize is not consistent with the format, dimensions, and contents of
10545                  the specified compressed image data. */
10546                 {
10547                         gl.compressedTextureSubImage3D(m_to_3D_compressed, 0, 0, 0, 0, s_reference_width, s_reference_height,
10548                                                                                    s_reference_depth, m_reference_compressed_3D_format,
10549                                                                                    m_reference_compressed_3D_size - 1, m_reference_compressed_3D);
10550                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCompressedTextureSubImage3D",
10551                                                                           "imageSize is not consistent with the format, dimensions, and contents of the "
10552                                                                           "specified compressed image data.");
10553                 }
10554
10555                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage3D
10556                  if a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER
10557                  target and the buffer object's data store is currently mapped. */
10558                 {
10559                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10560                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10561
10562                         gl.mapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
10563
10564                         if (GL_NO_ERROR == gl.getError())
10565                         {
10566                                 gl.compressedTextureSubImage3D(m_to_3D_compressed, 0, 0, 0, 0, s_reference_width, s_reference_height,
10567                                                                                            s_reference_depth, m_reference_compressed_3D_format,
10568                                                                                            m_reference_compressed_3D_size, NULL);
10569                                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage3D",
10570                                                                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target "
10571                                                                                   "and the buffer object's data store is currently mapped.");
10572
10573                                 gl.unmapBuffer(GL_PIXEL_UNPACK_BUFFER);
10574                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10575
10576                                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10577                                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10578                         }
10579                 }
10580
10581                 /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage3D
10582                  if a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER
10583                  target and the data would be unpacked from the buffer object such that
10584                  the memory reads required would exceed the data store size. */
10585                 {
10586                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10587                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10588
10589                         gl.compressedTextureSubImage3D(m_to_3D_compressed, 0, 0, 0, 0, s_reference_width, s_reference_height,
10590                                                                                    s_reference_depth, m_reference_compressed_3D_format,
10591                                                                                    m_reference_compressed_3D_size, (glw::GLubyte*)NULL + s_reference_size * 2);
10592                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage3D",
10593                                                                           "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and "
10594                                                                           "the buffer object's data store is currently mapped.");
10595
10596                         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10597                         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10598                 }
10599         }
10600
10601         return is_ok;
10602 }
10603
10604 /** @brief Clean GL objects, test variables and GL errors.
10605  */
10606 void SubImageErrorsTest::Clean()
10607 {
10608         /* Shortcut for GL functionality. */
10609         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10610
10611         /* Cleanup. */
10612         if (m_to_1D_empty)
10613         {
10614                 gl.deleteTextures(1, &m_to_1D_empty);
10615
10616                 m_to_1D_empty = 0;
10617         }
10618
10619         if (m_to_2D_empty)
10620         {
10621                 gl.deleteTextures(1, &m_to_2D_empty);
10622
10623                 m_to_2D_empty = 0;
10624         }
10625
10626         if (m_to_3D_empty)
10627         {
10628                 gl.deleteTextures(1, &m_to_3D_empty);
10629
10630                 m_to_3D_empty = 0;
10631         }
10632
10633         if (m_to_1D)
10634         {
10635                 gl.deleteTextures(1, &m_to_1D);
10636
10637                 m_to_1D = 0;
10638         }
10639
10640         if (m_to_2D)
10641         {
10642                 gl.deleteTextures(1, &m_to_2D);
10643
10644                 m_to_2D = 0;
10645         }
10646
10647         if (m_to_3D)
10648         {
10649                 gl.deleteTextures(1, &m_to_3D);
10650
10651                 m_to_3D = 0;
10652         }
10653
10654         if (m_to_1D_compressed)
10655         {
10656                 gl.deleteTextures(1, &m_to_1D_compressed);
10657
10658                 m_to_1D_compressed = 0;
10659         }
10660
10661         if (m_to_2D_compressed)
10662         {
10663                 gl.deleteTextures(1, &m_to_2D_compressed);
10664
10665                 m_to_2D_compressed = 0;
10666         }
10667
10668         if (m_to_3D_compressed)
10669         {
10670                 gl.deleteTextures(1, &m_to_3D_compressed);
10671
10672                 m_to_3D_compressed = 0;
10673         }
10674
10675         if (m_to_rectangle_compressed)
10676         {
10677                 gl.deleteTextures(1, &m_to_rectangle_compressed);
10678
10679                 m_to_rectangle_compressed = 0;
10680         }
10681
10682         if (m_bo)
10683         {
10684                 gl.deleteBuffers(1, &m_bo);
10685
10686                 m_bo = 0;
10687         }
10688
10689         m_to_invalid       = 0;
10690         m_format_invalid   = 0;
10691         m_type_invalid   = 0;
10692         m_max_texture_size = 1;
10693
10694         if (DE_NULL != m_reference_compressed_1D)
10695         {
10696                 delete[] m_reference_compressed_1D;
10697
10698                 m_reference_compressed_1D = NULL;
10699         }
10700
10701         if (DE_NULL != m_reference_compressed_2D)
10702         {
10703                 delete[] m_reference_compressed_2D;
10704
10705                 m_reference_compressed_2D = NULL;
10706         }
10707
10708         if (DE_NULL != m_reference_compressed_3D)
10709         {
10710                 delete[] m_reference_compressed_3D;
10711
10712                 m_reference_compressed_3D = NULL;
10713         }
10714
10715         if (DE_NULL != m_reference_compressed_rectangle)
10716         {
10717                 delete[] m_reference_compressed_rectangle;
10718
10719                 m_reference_compressed_rectangle = NULL;
10720         }
10721
10722         m_reference_compressed_1D_format                = 0;
10723         m_reference_compressed_2D_format                = 0;
10724         m_reference_compressed_3D_format                = 0;
10725         m_reference_compressed_rectangle_format = 0;
10726         m_reference_compressed_1D_size                  = 0;
10727         m_reference_compressed_2D_size                  = 0;
10728         m_reference_compressed_3D_size                  = 0;
10729         m_reference_compressed_rectangle_size   = 0;
10730         m_not_matching_compressed_1D_format             = 0;
10731         m_not_matching_compressed_1D_size               = 0;
10732         m_not_matching_compressed_2D_format             = 0;
10733         m_not_matching_compressed_2D_size               = 0;
10734         m_not_matching_compressed_3D_format             = 0;
10735         m_not_matching_compressed_3D_size               = 0;
10736
10737         while (GL_NO_ERROR != gl.getError())
10738                 ;
10739 }
10740
10741 /** Reference data */
10742 const glw::GLushort SubImageErrorsTest::s_reference[] = {
10743         0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
10744         0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
10745         0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
10746         0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff,
10747
10748         0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
10749         0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
10750         0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
10751         0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff,
10752
10753         0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
10754         0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
10755         0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
10756         0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff,
10757
10758         0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
10759         0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
10760         0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
10761         0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff
10762 };
10763
10764 /** Reference data parameters. */
10765 const glw::GLuint SubImageErrorsTest::s_reference_size                                          = sizeof(s_reference);
10766 const glw::GLuint SubImageErrorsTest::s_reference_width                                         = 4;
10767 const glw::GLuint SubImageErrorsTest::s_reference_height                                        = 4;
10768 const glw::GLuint SubImageErrorsTest::s_reference_depth                                         = 4;
10769 const glw::GLenum SubImageErrorsTest::s_reference_internalformat                        = GL_RG8;
10770 const glw::GLenum SubImageErrorsTest::s_reference_internalformat_compressed = GL_COMPRESSED_RG;
10771 const glw::GLenum SubImageErrorsTest::s_reference_format = GL_RG; /* !Must not be a RGB, RGBA, or BGRA */
10772 const glw::GLenum SubImageErrorsTest::s_reference_type   = GL_UNSIGNED_SHORT;
10773
10774 /******************************** Copy Errors Test Implementation   ********************************/
10775
10776 /** @brief Copy Errors Test constructor.
10777  *
10778  *  @param [in] context     OpenGL context.
10779  */
10780 CopyErrorsTest::CopyErrorsTest(deqp::Context& context)
10781         : deqp::TestCase(context, "textures_copy_errors", "Texture Copy Errors Test")
10782         , m_fbo(0)
10783         , m_fbo_ms(0)
10784         , m_fbo_incomplete(0)
10785         , m_to_src(0)
10786         , m_to_src_ms(0)
10787         , m_to_1D_dst(0)
10788         , m_to_2D_dst(0)
10789         , m_to_3D_dst(0)
10790         , m_to_invalid(0)
10791 {
10792         /* Intentionally left blank. */
10793 }
10794
10795 /** @brief Iterate Copy Errors Test cases.
10796  *
10797  *  @return Iteration result.
10798  */
10799 tcu::TestNode::IterateResult CopyErrorsTest::iterate()
10800 {
10801         /* Get context setup. */
10802         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
10803         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
10804
10805         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
10806         {
10807                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
10808
10809                 return STOP;
10810         }
10811
10812         /* Running tests. */
10813         bool is_ok      = true;
10814         bool is_error = false;
10815
10816         try
10817         {
10818                 Prepare();
10819
10820                 is_ok &= Test1D();
10821                 is_ok &= Test2D();
10822                 is_ok &= Test3D();
10823         }
10824         catch (...)
10825         {
10826                 is_ok   = false;
10827                 is_error = true;
10828         }
10829
10830         /* Cleanup. */
10831         Clean();
10832
10833         /* Result's setup. */
10834         if (is_ok)
10835         {
10836                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
10837         }
10838         else
10839         {
10840                 if (is_error)
10841                 {
10842                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
10843                 }
10844                 else
10845                 {
10846                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
10847                 }
10848         }
10849
10850         return STOP;
10851 }
10852
10853 /** @brief Prepare test's objects and values.
10854  */
10855 void CopyErrorsTest::Prepare()
10856 {
10857         /* Shortcut for GL functionality. */
10858         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10859
10860         /* Auxiliary objects setup. */
10861
10862         /* Framebuffer. */
10863         gl.genFramebuffers(1, &m_fbo);
10864         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
10865
10866         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
10867         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
10868
10869         gl.createTextures(GL_TEXTURE_2D, 1, &m_to_src);
10870         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
10871
10872         gl.textureStorage2D(m_to_src, 1, s_internalformat, s_width, s_height);
10873         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2D has failed");
10874
10875         gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_to_src, 0);
10876         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture1D call failed.");
10877
10878         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
10879         {
10880                 throw 0;
10881         }
10882
10883         gl.viewport(0, 0, s_width, s_height);
10884         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
10885
10886         gl.clear(GL_COLOR_BUFFER_BIT);
10887         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
10888
10889         /* Framebuffer Multisample. */
10890         gl.genFramebuffers(1, &m_fbo_ms);
10891         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
10892
10893         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
10894         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
10895
10896         gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &m_to_src_ms);
10897         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
10898
10899         gl.textureStorage2DMultisample(m_to_src_ms, 1, s_internalformat, s_width, s_height, false);
10900         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2DMultisample has failed");
10901
10902         gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, m_to_src_ms, 0);
10903         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture1D call failed.");
10904
10905         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
10906         {
10907                 throw 0;
10908         }
10909
10910         gl.viewport(0, 0, s_width, s_height);
10911         GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
10912
10913         gl.clear(GL_COLOR_BUFFER_BIT);
10914         GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
10915
10916         /* Framebuffer Incomplete. */
10917         gl.createFramebuffers(1, &m_fbo_incomplete);
10918         GLU_EXPECT_NO_ERROR(gl.getError(), "glcreateFramebuffers call failed.");
10919
10920         /* 1D */
10921         gl.createTextures(GL_TEXTURE_1D, 1, &m_to_1D_dst);
10922         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
10923
10924         gl.textureStorage1D(m_to_1D_dst, 1, s_internalformat, s_width);
10925         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2D has failed");
10926
10927         /* 2D */
10928         gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D_dst);
10929         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
10930
10931         gl.textureStorage2D(m_to_2D_dst, 1, s_internalformat, s_width, s_height);
10932         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2D has failed");
10933
10934         /* 3D */
10935         gl.createTextures(GL_TEXTURE_3D, 1, &m_to_3D_dst);
10936         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
10937
10938         gl.textureStorage3D(m_to_3D_dst, 1, s_internalformat, s_width, s_height, s_depth);
10939         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2D has failed");
10940
10941         /* invalid texture object */
10942         while (gl.isTexture(++m_to_invalid))
10943                 ;
10944         GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed");
10945 }
10946
10947 /** @brief Test (negative) of CopyTextureSubImage1D
10948  *
10949  *  @return Test result.
10950  */
10951 bool CopyErrorsTest::Test1D()
10952 {
10953         /* Shortcut for GL functionality. */
10954         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10955
10956         /* Result. */
10957         bool is_ok = true;
10958
10959         /* Bind framebuffer. */
10960         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_incomplete);
10961         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
10962
10963         /* Check that INVALID_FRAMEBUFFER_OPERATION is generated by
10964          CopyTextureSubImage1D if the object bound to READ_FRAMEBUFFER_BINDING is
10965          not framebuffer complete. */
10966         {
10967                 gl.copyTextureSubImage1D(m_to_1D_dst, 0, 0, 0, 0, s_width);
10968                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_FRAMEBUFFER_OPERATION, "glCopyTextureSubImage1D",
10969                                                                   "the object bound to READ_FRAMEBUFFER_BINDING is not framebuffer complete.");
10970         }
10971
10972         /* Bind framebuffer. */
10973         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
10974         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
10975
10976         gl.readBuffer(GL_COLOR_ATTACHMENT0);
10977         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
10978
10979         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage1D if
10980          texture is not the name of an existing texture object, or if the
10981          effective target of texture is not TEXTURE_1D. */
10982         {
10983                 gl.copyTextureSubImage1D(m_to_invalid, 0, 0, 0, 0, s_width);
10984                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage1D",
10985                                                                   "texture is not the name of an existing texture object.");
10986
10987                 gl.copyTextureSubImage1D(m_to_2D_dst, 0, 0, 0, 0, s_width);
10988                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage1D",
10989                                                                   "the effective target of texture is not TEXTURE_1D.");
10990         }
10991
10992         /* Check that INVALID_VALUE is generated by CopyTextureSubImage1D if level is less than 0. */
10993         {
10994                 gl.copyTextureSubImage1D(m_to_1D_dst, -1, 0, 0, 0, s_width);
10995                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage1D", "level is less than 0.");
10996         }
10997
10998         /* Check that INVALID_VALUE is generated by CopyTextureSubImage1D if
10999          xoffset<0, or (xoffset+width)>w, where w is the TEXTURE_WIDTH of the
11000          texture image being modified. */
11001         {
11002                 gl.copyTextureSubImage1D(m_to_1D_dst, 0, -1, 0, 0, s_width);
11003                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage1D", "xoffset<0.");
11004
11005                 gl.copyTextureSubImage1D(m_to_1D_dst, 0, 1, 0, 0, s_width);
11006                 is_ok &=
11007                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage1D",
11008                                                          "(xoffset+width)>w, where w is the TEXTURE_WIDTH of the texture image being modified.");
11009         }
11010
11011         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage1D if
11012          the read buffer is NONE. */
11013         gl.readBuffer(GL_NONE);
11014         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11015
11016         {
11017                 gl.copyTextureSubImage1D(m_to_1D_dst, 0, 0, 0, 0, s_width);
11018                 is_ok &=
11019                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage1D", "the read buffer is NONE.");
11020         }
11021
11022         /* Bind multisample framebuffer. */
11023         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
11024         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11025
11026         gl.readBuffer(GL_COLOR_ATTACHMENT0);
11027         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11028
11029         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage1D if
11030          the effective value of SAMPLE_BUFFERS for the read
11031          framebuffer is one. */
11032         {
11033                 gl.copyTextureSubImage1D(m_to_1D_dst, 0, 0, 0, 0, s_width);
11034                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage1D",
11035                                                                   "the effective value of SAMPLE_BUFFERS for the read framebuffer is one.");
11036         }
11037
11038         return is_ok;
11039 }
11040
11041 /** @brief Test (negative) of CopyTextureSubImage2D
11042  *
11043  *  @return Test result.
11044  */
11045 bool CopyErrorsTest::Test2D()
11046 {
11047         /* Shortcut for GL functionality. */
11048         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11049
11050         /* Result. */
11051         bool is_ok = true;
11052
11053         /* Bind framebuffer. */
11054         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_incomplete);
11055         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11056
11057         /* Check that INVALID_FRAMEBUFFER_OPERATION is generated by
11058          CopyTextureSubImage2D if the object bound to READ_FRAMEBUFFER_BINDING is
11059          not framebuffer complete. */
11060         {
11061                 gl.copyTextureSubImage2D(m_to_2D_dst, 0, 0, 0, 0, 0, s_width, s_height);
11062                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_FRAMEBUFFER_OPERATION, "glCopyTextureSubImage2D",
11063                                                                   "the object bound to READ_FRAMEBUFFER_BINDING is not framebuffer complete.");
11064         }
11065
11066         /* Bind framebuffer. */
11067         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
11068         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11069
11070         gl.readBuffer(GL_COLOR_ATTACHMENT0);
11071         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11072
11073         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage2D if
11074          texture is not the name of an existing texture object, or if the
11075          effective target of texture is not TEXTURE_2D. */
11076         {
11077                 gl.copyTextureSubImage2D(m_to_invalid, 0, 0, 0, 0, 0, s_width, s_height);
11078                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage2D",
11079                                                                   "texture is not the name of an existing texture object.");
11080
11081                 gl.copyTextureSubImage2D(m_to_1D_dst, 0, 0, 0, 0, 0, s_width, s_height);
11082                 is_ok &= CheckErrorAndLog(
11083                         m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage2D",
11084                         "the effective target of does not correspond to one of the texture targets supported by the function..");
11085         }
11086
11087         /* Check that INVALID_VALUE is generated by CopyTextureSubImage2D if level is less than 0. */
11088         {
11089                 gl.copyTextureSubImage2D(m_to_2D_dst, -1, 0, 0, 0, 0, s_width, s_height);
11090                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage2D", "level is less than 0.");
11091         }
11092
11093         /* Check that INVALID_VALUE is generated by CopyTextureSubImage2D if
11094          xoffset<0, (xoffset+width)>w, yoffset<0, or (yoffset+height)>0, where w
11095          is the TEXTURE_WIDTH, h is the TEXTURE_HEIGHT and of the texture image
11096          being modified. */
11097         {
11098                 gl.copyTextureSubImage2D(m_to_2D_dst, 0, -1, 0, 0, 0, s_width, s_height);
11099                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage2D", "xoffset<0.");
11100
11101                 gl.copyTextureSubImage2D(m_to_2D_dst, 0, 1, 0, 0, 0, s_width, s_height);
11102                 is_ok &=
11103                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage2D",
11104                                                          "(xoffset+width)>w, where w is the TEXTURE_WIDTH of the texture image being modified.");
11105
11106                 gl.copyTextureSubImage2D(m_to_2D_dst, 0, 0, -1, 0, 0, s_width, s_height);
11107                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage2D", "yoffset<0.");
11108
11109                 gl.copyTextureSubImage2D(m_to_2D_dst, 0, 0, 1, 0, 0, s_width, s_height);
11110                 is_ok &=
11111                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage2D",
11112                                                          "(yoffset+height)>h, where h is the TEXTURE_HEIGHT of the texture image being modified.");
11113         }
11114
11115         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage2D if
11116          the read buffer is NONE. */
11117         gl.readBuffer(GL_NONE);
11118         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11119
11120         {
11121                 gl.copyTextureSubImage2D(m_to_2D_dst, 0, 0, 0, 0, 0, s_width, s_height);
11122                 is_ok &=
11123                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage2D", "the read buffer is NONE.");
11124         }
11125
11126         /* Bind multisample framebuffer. */
11127         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
11128         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11129
11130         gl.readBuffer(GL_COLOR_ATTACHMENT0);
11131         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11132
11133         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage2D if
11134          the effective value of SAMPLE_BUFFERS for the read
11135          framebuffer is one. */
11136         {
11137                 gl.copyTextureSubImage2D(m_to_2D_dst, 0, 0, 0, 0, 0, s_width, s_height);
11138                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage2D",
11139                                                                   "the effective value of SAMPLE_BUFFERS for the read framebuffer is one.");
11140         }
11141
11142         return is_ok;
11143 }
11144
11145 /** @brief Test (negative) of CopyTextureSubImage3D
11146  *
11147  *  @return Test result.
11148  */
11149 bool CopyErrorsTest::Test3D()
11150 {
11151         /* Shortcut for GL functionality. */
11152         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11153
11154         /* Result. */
11155         bool is_ok = true;
11156
11157         /* Bind framebuffer. */
11158         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_incomplete);
11159         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11160
11161         /* Check that INVALID_FRAMEBUFFER_OPERATION is generated by
11162          CopyTextureSubImage3D if the object bound to READ_FRAMEBUFFER_BINDING is
11163          not framebuffer complete. */
11164         {
11165                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, 0, 0, 0, 0, s_width, s_height);
11166                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_FRAMEBUFFER_OPERATION, "glCopyTextureSubImage3D",
11167                                                                   "the object bound to READ_FRAMEBUFFER_BINDING is not framebuffer complete.");
11168         }
11169
11170         /* Bind framebuffer. */
11171         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
11172         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11173
11174         gl.readBuffer(GL_COLOR_ATTACHMENT0);
11175         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11176
11177         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage3D if
11178          texture is not the name of an existing texture object, or if the
11179          effective target of texture is not supported by the function. */
11180         {
11181                 gl.copyTextureSubImage3D(m_to_invalid, 0, 0, 0, 0, 0, 0, s_width, s_height);
11182                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage3D",
11183                                                                   "texture is not the name of an existing texture object.");
11184
11185                 gl.copyTextureSubImage3D(m_to_1D_dst, 0, 0, 0, 0, 0, 0, s_width, s_height);
11186                 is_ok &= CheckErrorAndLog(
11187                         m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage3D",
11188                         "the effective target of does not correspond to one of the texture targets supported by the function..");
11189         }
11190
11191         /* Check that INVALID_VALUE is generated by CopyTextureSubImage3D if level is less than 0. */
11192         {
11193                 gl.copyTextureSubImage3D(m_to_3D_dst, -1, 0, 0, 0, 0, 0, s_width, s_height);
11194                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D", "level is less than 0.");
11195         }
11196
11197         /* Check that INVALID_VALUE is generated by CopyTextureSubImage3D if
11198          xoffset<0, (xoffset+width)>w, yoffset<0, (yoffset+height)>h, zoffset<0,
11199          or (zoffset+1)>d, where w is the TEXTURE_WIDTH, h is the TEXTURE_HEIGHT,
11200          d is the TEXTURE_DEPTH and of the texture image being modified. Note
11201          that w, h, and d include twice the border width.  */
11202         {
11203                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, -1, 0, 0, 0, 0, s_width, s_height);
11204                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D", "xoffset<0.");
11205
11206                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, 1, 0, 0, 0, 0, s_width, s_height);
11207                 is_ok &=
11208                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D",
11209                                                          "(xoffset+width)>w, where w is the TEXTURE_WIDTH of the texture image being modified.");
11210
11211                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, -1, 0, 0, 0, s_width, s_height);
11212                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D", "yoffset<0.");
11213
11214                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, 1, 0, 0, 0, s_width, s_height);
11215                 is_ok &=
11216                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D",
11217                                                          "(yoffset+height)>h, where h is the TEXTURE_HEIGHT of the texture image being modified.");
11218
11219                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, 0, -1, 0, 0, s_width, s_height);
11220                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D", "zoffset<0.");
11221
11222                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, 0, s_depth + 1, 0, 0, s_width, s_height);
11223                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D",
11224                                                                   "(zoffset+1)>d, where d is the TEXTURE_DEPTH of the texture image being modified.");
11225         }
11226
11227         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage3D if
11228          the read buffer is NONE. */
11229         gl.readBuffer(GL_NONE);
11230         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11231
11232         {
11233                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, 0, 0, 0, 0, s_width, s_height);
11234                 is_ok &=
11235                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage3D", "the read buffer is NONE.");
11236         }
11237
11238         /* Bind multisample framebuffer. */
11239         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
11240         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11241
11242         gl.readBuffer(GL_COLOR_ATTACHMENT0);
11243         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11244
11245         /* Check that INVALID_OPERATION is generated by CopyTextureSubImage3D if
11246          the effective value of SAMPLE_BUFFERS for the read
11247          framebuffer is one. */
11248         {
11249                 gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, 0, 0, 0, 0, s_width, s_height);
11250                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage3D",
11251                                                                   "the effective value of SAMPLE_BUFFERS for the read framebuffer is one.");
11252         }
11253
11254         return is_ok;
11255 }
11256
11257 /** @brief Clean GL objects, test variables and GL errors.
11258  */
11259 void CopyErrorsTest::Clean()
11260 {
11261         /* Shortcut for GL functionality. */
11262         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11263
11264         /* Cleanup. */
11265         if (m_fbo)
11266         {
11267                 gl.deleteFramebuffers(1, &m_fbo);
11268
11269                 m_fbo = 0;
11270         }
11271
11272         if (m_fbo_ms)
11273         {
11274                 gl.deleteFramebuffers(1, &m_fbo_ms);
11275
11276                 m_fbo_ms = 0;
11277         }
11278
11279         if (m_fbo_incomplete)
11280         {
11281                 gl.deleteFramebuffers(1, &m_fbo_incomplete);
11282
11283                 m_fbo_incomplete = 0;
11284         }
11285
11286         if (m_to_src)
11287         {
11288                 gl.deleteTextures(1, &m_to_src);
11289
11290                 m_to_src = 0;
11291         }
11292
11293         if (m_to_src_ms)
11294         {
11295                 gl.deleteTextures(1, &m_to_src_ms);
11296
11297                 m_to_src_ms = 0;
11298         }
11299
11300         if (m_to_1D_dst)
11301         {
11302                 gl.deleteTextures(1, &m_to_1D_dst);
11303
11304                 m_to_1D_dst = 0;
11305         }
11306
11307         if (m_to_2D_dst)
11308         {
11309                 gl.deleteTextures(1, &m_to_2D_dst);
11310
11311                 m_to_2D_dst = 0;
11312         }
11313
11314         if (m_to_3D_dst)
11315         {
11316                 gl.deleteTextures(1, &m_to_3D_dst);
11317
11318                 m_to_3D_dst = 0;
11319         }
11320
11321         m_to_invalid = 0;
11322
11323         while (GL_NO_ERROR != gl.getError())
11324                 ;
11325 }
11326
11327 /* Test's parameters. */
11328 const glw::GLuint CopyErrorsTest::s_width                  = 4;
11329 const glw::GLuint CopyErrorsTest::s_height                 = 4;
11330 const glw::GLuint CopyErrorsTest::s_depth                  = 4;
11331 const glw::GLuint CopyErrorsTest::s_internalformat = GL_RGBA8;
11332
11333 /******************************** Parameter Setup Errors Test Implementation   ********************************/
11334
11335 /** @brief Parameter Setup Errors Test constructor.
11336  *
11337  *  @param [in] context     OpenGL context.
11338  */
11339 ParameterSetupErrorsTest::ParameterSetupErrorsTest(deqp::Context& context)
11340         : deqp::TestCase(context, "textures_parameter_setup_errors", "Texture Parameter Setup Errors Test")
11341         , m_to_2D(0)
11342         , m_to_2D_ms(0)
11343         , m_to_rectangle(0)
11344         , m_to_invalid(0)
11345         , m_pname_invalid(0)
11346         , m_depth_stencil_mode_invalid(0)
11347 {
11348         /* Intentionally left blank. */
11349 }
11350
11351 /** @brief Iterate Parameter Setup Errors Test cases.
11352  *
11353  *  @return Iteration result.
11354  */
11355 tcu::TestNode::IterateResult ParameterSetupErrorsTest::iterate()
11356 {
11357         /* Get context setup. */
11358         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
11359         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
11360
11361         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
11362         {
11363                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
11364
11365                 return STOP;
11366         }
11367
11368         /* Running tests. */
11369         bool is_ok      = true;
11370         bool is_error = false;
11371
11372         try
11373         {
11374                 Prepare();
11375
11376                 is_ok &= Testf();
11377                 is_ok &= Testi();
11378                 is_ok &= Testfv();
11379                 is_ok &= Testiv();
11380                 is_ok &= TestIiv();
11381                 is_ok &= TestIuiv();
11382         }
11383         catch (...)
11384         {
11385                 is_ok   = false;
11386                 is_error = true;
11387         }
11388
11389         /* Cleanup. */
11390         Clean();
11391
11392         /* Result's setup. */
11393         if (is_ok)
11394         {
11395                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
11396         }
11397         else
11398         {
11399                 if (is_error)
11400                 {
11401                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
11402                 }
11403                 else
11404                 {
11405                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
11406                 }
11407         }
11408
11409         return STOP;
11410 }
11411
11412 /** @brief Test's preparations.
11413  */
11414 void ParameterSetupErrorsTest::Prepare()
11415 {
11416         /* Shortcut for GL functionality. */
11417         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11418
11419         /* Auxiliary objects setup. */
11420
11421         /* 2D */
11422         gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D);
11423         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
11424
11425         /* 3D */
11426         gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &m_to_2D_ms);
11427         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
11428
11429         /* RECTANGLE */
11430         gl.createTextures(GL_TEXTURE_RECTANGLE, 1, &m_to_rectangle);
11431         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
11432
11433         /* Invalid texture object. */
11434         while (gl.isTexture(++m_to_invalid))
11435                 ;
11436         GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed");
11437
11438         /* Invalid parameter name. */
11439         glw::GLenum all_pnames[] = { GL_DEPTH_STENCIL_TEXTURE_MODE,
11440                                                                  GL_TEXTURE_BASE_LEVEL,
11441                                                                  GL_TEXTURE_COMPARE_FUNC,
11442                                                                  GL_TEXTURE_COMPARE_MODE,
11443                                                                  GL_TEXTURE_LOD_BIAS,
11444                                                                  GL_TEXTURE_MIN_FILTER,
11445                                                                  GL_TEXTURE_MAG_FILTER,
11446                                                                  GL_TEXTURE_MIN_LOD,
11447                                                                  GL_TEXTURE_MAX_LOD,
11448                                                                  GL_TEXTURE_MAX_LEVEL,
11449                                                                  GL_TEXTURE_SWIZZLE_R,
11450                                                                  GL_TEXTURE_SWIZZLE_G,
11451                                                                  GL_TEXTURE_SWIZZLE_B,
11452                                                                  GL_TEXTURE_SWIZZLE_A,
11453                                                                  GL_TEXTURE_WRAP_S,
11454                                                                  GL_TEXTURE_WRAP_T,
11455                                                                  GL_TEXTURE_WRAP_R,
11456                                                                  GL_TEXTURE_BORDER_COLOR,
11457                                                                  GL_TEXTURE_SWIZZLE_RGBA };
11458         glw::GLuint all_pnames_count = sizeof(all_pnames) / sizeof(all_pnames[0]);
11459
11460         bool is_valid = true;
11461
11462         while (is_valid)
11463         {
11464                 is_valid = false;
11465                 ++m_pname_invalid;
11466
11467                 for (glw::GLuint i = 0; i < all_pnames_count; ++i)
11468                 {
11469                         if (all_pnames[i] == m_pname_invalid)
11470                         {
11471                                 is_valid = true;
11472
11473                                 break;
11474                         }
11475                 }
11476         }
11477
11478         /* Invalid depth stencil mode name. */
11479         glw::GLenum all_depth_stencil_modes[]    = { GL_DEPTH_COMPONENT, GL_STENCIL_INDEX };
11480         glw::GLuint all_depth_stencil_modes_count = sizeof(all_depth_stencil_modes) / sizeof(all_depth_stencil_modes[0]);
11481
11482         is_valid = true;
11483
11484         while (is_valid)
11485         {
11486                 is_valid = false;
11487                 ++m_depth_stencil_mode_invalid;
11488
11489                 for (glw::GLuint i = 0; i < all_depth_stencil_modes_count; ++i)
11490                 {
11491                         if (all_depth_stencil_modes[i] == m_depth_stencil_mode_invalid)
11492                         {
11493                                 is_valid = true;
11494
11495                                 break;
11496                         }
11497                 }
11498         }
11499 }
11500
11501 /** @brief Test (negative) of TextureParameterf
11502  *
11503  *  @return Test result.
11504  */
11505 bool ParameterSetupErrorsTest::Testf()
11506 {
11507         /* Shortcut for GL functionality. */
11508         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11509
11510         /* Result. */
11511         bool is_ok = true;
11512
11513         /* Check that INVALID_ENUM is generated by TextureParameter* if pname is
11514          not one of the accepted defined values. */
11515         {
11516                 gl.textureParameterf(m_to_2D, m_pname_invalid, 1.f);
11517
11518                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterf",
11519                                                                   "pname is not one of the accepted defined values.");
11520         }
11521
11522         /* Check that INVALID_ENUM is generated by TextureParameter* if params
11523          should have a defined constant value (based on the value of pname) and
11524          does not. */
11525         {
11526                 gl.textureParameterf(m_to_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, (glw::GLfloat)m_depth_stencil_mode_invalid);
11527
11528                 is_ok &=
11529                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterf",
11530                                                          "params should have a defined constant value (based on the value of pname) and does not.");
11531         }
11532         /* Check that INVALID_ENUM is generated if TextureParameter{if} is called
11533          for a non-scalar parameter (pname TEXTURE_BORDER_COLOR or
11534          TEXTURE_SWIZZLE_RGBA). */
11535         {
11536                 gl.textureParameterf(m_to_2D, GL_TEXTURE_BORDER_COLOR, 1.f);
11537
11538                 is_ok &=
11539                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterf",
11540                                                          "called for a non-scalar parameter (pname TEXTURE_BORDER_COLOR or TEXTURE_SWIZZLE_RGBA).");
11541         }
11542
11543         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11544          effective target is either TEXTURE_2D_MULTISAMPLE or
11545          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states. */
11546         {
11547                 gl.textureParameterf(m_to_2D_ms, GL_TEXTURE_LOD_BIAS, 1.f);
11548
11549                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterf",
11550                                                                   "the  effective target is either TEXTURE_2D_MULTISAMPLE or  "
11551                                                                   "TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states.");
11552         }
11553
11554         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11555          effective target is TEXTURE_RECTANGLE and either of pnames
11556          TEXTURE_WRAP_S or TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE,
11557          MIRRORED_REPEAT or REPEAT. */
11558         {
11559                 gl.textureParameterf(m_to_rectangle, GL_TEXTURE_WRAP_S, GL_MIRROR_CLAMP_TO_EDGE);
11560
11561                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterf",
11562                                                                   "the effective target is TEXTURE_RECTANGLE and either of pnames TEXTURE_WRAP_S or "
11563                                                                   "TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE, MIRRORED_REPEAT or REPEAT.");
11564         }
11565
11566         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11567          effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is
11568          set to a value other than NEAREST or LINEAR (no mipmap filtering is
11569          permitted). */
11570         {
11571                 gl.textureParameterf(m_to_rectangle, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
11572
11573                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterf",
11574                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is set to a "
11575                                                                   "value other than NEAREST or LINEAR (no mipmap filtering is permitted).");
11576         }
11577
11578         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
11579          effective target is either TEXTURE_2D_MULTISAMPLE or
11580          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname TEXTURE_BASE_LEVEL is set to a
11581          value other than zero. */
11582         {
11583                 gl.textureParameterf(m_to_2D_ms, GL_TEXTURE_BASE_LEVEL, 1.f);
11584
11585                 is_ok &=
11586                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterf",
11587                                                          "the effective target is either TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY, "
11588                                                          "and pname TEXTURE_BASE_LEVEL is set to a value other than zero.");
11589         }
11590
11591         /* Check that INVALID_OPERATION is generated by TextureParameter* if
11592          texture is not the name of an existing texture object. */
11593         {
11594                 gl.textureParameterf(m_to_invalid, GL_TEXTURE_LOD_BIAS, 1.f);
11595
11596                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterf",
11597                                                                   "texture is not the name of an existing texture object.");
11598         }
11599
11600         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
11601          effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is
11602          set to any value other than zero. */
11603         {
11604                 gl.textureParameterf(m_to_rectangle, GL_TEXTURE_BASE_LEVEL, 1.f);
11605
11606                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterf",
11607                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is set to "
11608                                                                   "any value other than zero. ");
11609         }
11610
11611         /* Check that INVALID_VALUE is generated by TextureParameter* if pname is
11612          TEXTURE_BASE_LEVEL or TEXTURE_MAX_LEVEL, and param or params is
11613          negative. */
11614         {
11615                 gl.textureParameterf(m_to_2D, GL_TEXTURE_BASE_LEVEL, -1.f);
11616
11617                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameterf",
11618                                                                   "pname is TEXTURE_BASE_LEVEL and param is negative.");
11619
11620                 gl.textureParameterf(m_to_2D, GL_TEXTURE_MAX_LEVEL, -1.f);
11621
11622                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameterf",
11623                                                                   "pname is TEXTURE_MAX_LEVEL and param is negative.");
11624         }
11625
11626         return is_ok;
11627 }
11628
11629 /** @brief Test (negative) of TextureParameteri
11630  *
11631  *  @return Test result.
11632  */
11633 bool ParameterSetupErrorsTest::Testi()
11634 {
11635         /* Shortcut for GL functionality. */
11636         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11637
11638         /* Result. */
11639         bool is_ok = true;
11640
11641         /* Check that INVALID_ENUM is generated by TextureParameter* if pname is
11642          not one of the accepted defined values. */
11643         {
11644                 gl.textureParameteri(m_to_2D, m_pname_invalid, 1);
11645
11646                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteri",
11647                                                                   "pname is not one of the accepted defined values.");
11648         }
11649
11650         /* Check that INVALID_ENUM is generated by TextureParameter* if params
11651          should have a defined constant value (based on the value of pname) and
11652          does not. */
11653         {
11654                 gl.textureParameteri(m_to_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, m_depth_stencil_mode_invalid);
11655
11656                 is_ok &=
11657                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteri",
11658                                                          "params should have a defined constant value (based on the value of pname) and does not.");
11659         }
11660         /* Check that INVALID_ENUM is generated if TextureParameter{if} is called
11661          for a non-scalar parameter (pname TEXTURE_BORDER_COLOR or
11662          TEXTURE_SWIZZLE_RGBA). */
11663         {
11664                 gl.textureParameteri(m_to_2D, GL_TEXTURE_BORDER_COLOR, 1);
11665
11666                 is_ok &=
11667                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteri",
11668                                                          "called for a non-scalar parameter (pname TEXTURE_BORDER_COLOR or TEXTURE_SWIZZLE_RGBA).");
11669         }
11670
11671         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11672          effective target is either TEXTURE_2D_MULTISAMPLE or
11673          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states. */
11674         {
11675                 gl.textureParameteri(m_to_2D_ms, GL_TEXTURE_LOD_BIAS, 1);
11676
11677                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteri",
11678                                                                   "the  effective target is either TEXTURE_2D_MULTISAMPLE or  "
11679                                                                   "TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states.");
11680         }
11681
11682         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11683          effective target is TEXTURE_RECTANGLE and either of pnames
11684          TEXTURE_WRAP_S or TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE,
11685          MIRRORED_REPEAT or REPEAT. */
11686         {
11687                 gl.textureParameteri(m_to_rectangle, GL_TEXTURE_WRAP_S, GL_MIRROR_CLAMP_TO_EDGE);
11688
11689                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteri",
11690                                                                   "the effective target is TEXTURE_RECTANGLE and either of pnames TEXTURE_WRAP_S or "
11691                                                                   "TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE, MIRRORED_REPEAT or REPEAT.");
11692         }
11693
11694         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11695          effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is
11696          set to a value other than NEAREST or LINEAR (no mipmap filtering is
11697          permitted). */
11698         {
11699                 gl.textureParameteri(m_to_rectangle, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
11700
11701                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteri",
11702                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is set to a "
11703                                                                   "value other than NEAREST or LINEAR (no mipmap filtering is permitted).");
11704         }
11705
11706         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
11707          effective target is either TEXTURE_2D_MULTISAMPLE or
11708          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname TEXTURE_BASE_LEVEL is set to a
11709          value other than zero. */
11710         {
11711                 gl.textureParameteri(m_to_2D_ms, GL_TEXTURE_BASE_LEVEL, 1);
11712
11713                 is_ok &=
11714                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteri",
11715                                                          "the effective target is either TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY, "
11716                                                          "and pname TEXTURE_BASE_LEVEL is set to a value other than zero.");
11717         }
11718
11719         /* Check that INVALID_OPERATION is generated by TextureParameter* if
11720          texture is not the name of an existing texture object. */
11721         {
11722                 gl.textureParameteri(m_to_invalid, GL_TEXTURE_LOD_BIAS, 1);
11723
11724                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteri",
11725                                                                   "texture is not the name of an existing texture object.");
11726         }
11727
11728         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
11729          effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is
11730          set to any value other than zero. */
11731         {
11732                 gl.textureParameteri(m_to_rectangle, GL_TEXTURE_BASE_LEVEL, 1);
11733
11734                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteri",
11735                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is set to "
11736                                                                   "any value other than zero. ");
11737         }
11738
11739         /* Check that INVALID_VALUE is generated by TextureParameter* if pname is
11740          TEXTURE_BASE_LEVEL or TEXTURE_MAX_LEVEL, and param or params is
11741          negative. */
11742         {
11743                 gl.textureParameteri(m_to_2D, GL_TEXTURE_BASE_LEVEL, -1);
11744
11745                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameteri",
11746                                                                   "pname is TEXTURE_BASE_LEVEL and param is negative.");
11747
11748                 gl.textureParameteri(m_to_2D, GL_TEXTURE_MAX_LEVEL, -1);
11749
11750                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameteri",
11751                                                                   "pname is TEXTURE_MAX_LEVEL and param is negative.");
11752         }
11753
11754         return is_ok;
11755 }
11756
11757 /** @brief Test (negative) of TextureParameterfv
11758  *
11759  *  @return Test result.
11760  */
11761 bool ParameterSetupErrorsTest::Testfv()
11762 {
11763         /* Shortcut for GL functionality. */
11764         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11765
11766         /* Result. */
11767         bool is_ok = true;
11768
11769         glw::GLfloat one                                                = 1.f;
11770         glw::GLfloat minus_one                                  = -1.f;
11771         glw::GLfloat depth_stencil_mode_invalid = (glw::GLfloat)m_depth_stencil_mode_invalid;
11772         glw::GLfloat wrap_invalid                               = (glw::GLfloat)GL_MIRROR_CLAMP_TO_EDGE;
11773         glw::GLfloat min_filter_invalid                 = (glw::GLfloat)GL_NEAREST_MIPMAP_NEAREST;
11774
11775         /* Check that INVALID_ENUM is generated by TextureParameter* if pname is
11776          not one of the accepted defined values. */
11777         {
11778                 gl.textureParameterfv(m_to_2D, m_pname_invalid, &one);
11779
11780                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterfv",
11781                                                                   "pname is not one of the accepted defined values.");
11782         }
11783
11784         /* Check that INVALID_ENUM is generated by TextureParameter* if params
11785          should have a defined constant value (based on the value of pname) and
11786          does not. */
11787         {
11788                 gl.textureParameterfv(m_to_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, &depth_stencil_mode_invalid);
11789
11790                 is_ok &=
11791                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterfv",
11792                                                          "params should have a defined constant value (based on the value of pname) and does not.");
11793         }
11794
11795         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11796          effective target is either TEXTURE_2D_MULTISAMPLE or
11797          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states. */
11798         {
11799                 gl.textureParameterfv(m_to_2D_ms, GL_TEXTURE_LOD_BIAS, &one);
11800
11801                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterfv",
11802                                                                   "the  effective target is either TEXTURE_2D_MULTISAMPLE or  "
11803                                                                   "TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states.");
11804         }
11805
11806         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11807          effective target is TEXTURE_RECTANGLE and either of pnames
11808          TEXTURE_WRAP_S or TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE,
11809          MIRRORED_REPEAT or REPEAT. */
11810         {
11811                 gl.textureParameterfv(m_to_rectangle, GL_TEXTURE_WRAP_S, &wrap_invalid);
11812
11813                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterfv",
11814                                                                   "the effective target is TEXTURE_RECTANGLE and either of pnames TEXTURE_WRAP_S or "
11815                                                                   "TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE, MIRRORED_REPEAT or REPEAT.");
11816         }
11817
11818         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11819          effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is
11820          set to a value other than NEAREST or LINEAR (no mipmap filtering is
11821          permitted). */
11822         {
11823                 gl.textureParameterfv(m_to_rectangle, GL_TEXTURE_MIN_FILTER, &min_filter_invalid);
11824
11825                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterfv",
11826                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is set to a "
11827                                                                   "value other than NEAREST or LINEAR (no mipmap filtering is permitted).");
11828         }
11829
11830         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
11831          effective target is either TEXTURE_2D_MULTISAMPLE or
11832          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname TEXTURE_BASE_LEVEL is set to a
11833          value other than zero. */
11834         {
11835                 gl.textureParameterfv(m_to_2D_ms, GL_TEXTURE_BASE_LEVEL, &one);
11836
11837                 is_ok &=
11838                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterfv",
11839                                                          "the effective target is either TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY, "
11840                                                          "and pname TEXTURE_BASE_LEVEL is set to a value other than zero.");
11841         }
11842
11843         /* Check that INVALID_OPERATION is generated by TextureParameter* if
11844          texture is not the name of an existing texture object. */
11845         {
11846                 gl.textureParameterfv(m_to_invalid, GL_TEXTURE_LOD_BIAS, &one);
11847
11848                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterfv",
11849                                                                   "texture is not the name of an existing texture object.");
11850         }
11851
11852         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
11853          effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is
11854          set to any value other than zero. */
11855         {
11856                 gl.textureParameterfv(m_to_rectangle, GL_TEXTURE_BASE_LEVEL, &one);
11857
11858                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterfv",
11859                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is set to "
11860                                                                   "any value other than zero. ");
11861         }
11862
11863         /* Check that INVALID_VALUE is generated by TextureParameter* if pname is
11864          TEXTURE_BASE_LEVEL or TEXTURE_MAX_LEVEL, and param or params is
11865          negative. */
11866         {
11867                 gl.textureParameterfv(m_to_2D, GL_TEXTURE_BASE_LEVEL, &minus_one);
11868
11869                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameterfv",
11870                                                                   "pname is TEXTURE_BASE_LEVEL and param is negative.");
11871
11872                 gl.textureParameterfv(m_to_2D, GL_TEXTURE_MAX_LEVEL, &minus_one);
11873
11874                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameterfv",
11875                                                                   "pname is TEXTURE_MAX_LEVEL and param is negative.");
11876         }
11877
11878         return is_ok;
11879 }
11880
11881 /** @brief Test (negative) of TextureParameteriv
11882  *
11883  *  @return Test result.
11884  */
11885 bool ParameterSetupErrorsTest::Testiv()
11886 {
11887         /* Shortcut for GL functionality. */
11888         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11889
11890         /* Result. */
11891         bool is_ok = true;
11892
11893         glw::GLint one                                            = 1;
11894         glw::GLint minus_one                              = -1;
11895         glw::GLint depth_stencil_mode_invalid = (glw::GLint)m_depth_stencil_mode_invalid;
11896         glw::GLint wrap_invalid                           = (glw::GLint)GL_MIRROR_CLAMP_TO_EDGE;
11897         glw::GLint min_filter_invalid             = (glw::GLint)GL_NEAREST_MIPMAP_NEAREST;
11898
11899         /* Check that INVALID_ENUM is generated by TextureParameter* if pname is
11900          not one of the accepted defined values. */
11901         {
11902                 gl.textureParameteriv(m_to_2D, m_pname_invalid, &one);
11903
11904                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteriv",
11905                                                                   "pname is not one of the accepted defined values.");
11906         }
11907
11908         /* Check that INVALID_ENUM is generated by TextureParameter* if params
11909          should have a defined constant value (based on the value of pname) and
11910          does not. */
11911         {
11912                 gl.textureParameteriv(m_to_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, &depth_stencil_mode_invalid);
11913
11914                 is_ok &=
11915                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteriv",
11916                                                          "params should have a defined constant value (based on the value of pname) and does not.");
11917         }
11918
11919         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11920          effective target is either TEXTURE_2D_MULTISAMPLE or
11921          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states. */
11922         {
11923                 gl.textureParameteriv(m_to_2D_ms, GL_TEXTURE_LOD_BIAS, &one);
11924
11925                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteriv",
11926                                                                   "the  effective target is either TEXTURE_2D_MULTISAMPLE or  "
11927                                                                   "TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states.");
11928         }
11929
11930         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11931          effective target is TEXTURE_RECTANGLE and either of pnames
11932          TEXTURE_WRAP_S or TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE,
11933          MIRRORED_REPEAT or REPEAT. */
11934         {
11935                 gl.textureParameteriv(m_to_rectangle, GL_TEXTURE_WRAP_S, &wrap_invalid);
11936
11937                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteriv",
11938                                                                   "the effective target is TEXTURE_RECTANGLE and either of pnames TEXTURE_WRAP_S or "
11939                                                                   "TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE, MIRRORED_REPEAT or REPEAT.");
11940         }
11941
11942         /* Check that INVALID_ENUM is generated by TextureParameter* if the
11943          effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is
11944          set to a value other than NEAREST or LINEAR (no mipmap filtering is
11945          permitted). */
11946         {
11947                 gl.textureParameteriv(m_to_rectangle, GL_TEXTURE_MIN_FILTER, &min_filter_invalid);
11948
11949                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteriv",
11950                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is set to a "
11951                                                                   "value other than NEAREST or LINEAR (no mipmap filtering is permitted).");
11952         }
11953
11954         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
11955          effective target is either TEXTURE_2D_MULTISAMPLE or
11956          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname TEXTURE_BASE_LEVEL is set to a
11957          value other than zero. */
11958         {
11959                 gl.textureParameteriv(m_to_2D_ms, GL_TEXTURE_BASE_LEVEL, &one);
11960
11961                 is_ok &=
11962                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteriv",
11963                                                          "the effective target is either TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY, "
11964                                                          "and pname TEXTURE_BASE_LEVEL is set to a value other than zero.");
11965         }
11966
11967         /* Check that INVALID_OPERATION is generated by TextureParameter* if
11968          texture is not the name of an existing texture object. */
11969         {
11970                 gl.textureParameteriv(m_to_invalid, GL_TEXTURE_LOD_BIAS, &one);
11971
11972                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteriv",
11973                                                                   "texture is not the name of an existing texture object.");
11974         }
11975
11976         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
11977          effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is
11978          set to any value other than zero. */
11979         {
11980                 gl.textureParameteriv(m_to_rectangle, GL_TEXTURE_BASE_LEVEL, &one);
11981
11982                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteriv",
11983                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is set to "
11984                                                                   "any value other than zero. ");
11985         }
11986
11987         /* Check that INVALID_VALUE is generated by TextureParameter* if pname is
11988          TEXTURE_BASE_LEVEL or TEXTURE_MAX_LEVEL, and param or params is
11989          negative. */
11990         {
11991                 gl.textureParameteriv(m_to_2D, GL_TEXTURE_BASE_LEVEL, &minus_one);
11992
11993                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameteriv",
11994                                                                   "pname is TEXTURE_BASE_LEVEL and param is negative.");
11995
11996                 gl.textureParameteriv(m_to_2D, GL_TEXTURE_MAX_LEVEL, &minus_one);
11997
11998                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameteriv",
11999                                                                   "pname is TEXTURE_MAX_LEVEL and param is negative.");
12000         }
12001
12002         return is_ok;
12003 }
12004
12005 /** @brief Test (negative) of TextureParameterIiv
12006  *
12007  *  @return Test result.
12008  */
12009 bool ParameterSetupErrorsTest::TestIiv()
12010 {
12011         /* Shortcut for GL functionality. */
12012         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
12013
12014         /* Result. */
12015         bool is_ok = true;
12016
12017         glw::GLint one                                            = 1;
12018         glw::GLint minus_one                              = -1;
12019         glw::GLint depth_stencil_mode_invalid = (glw::GLint)m_depth_stencil_mode_invalid;
12020         glw::GLint wrap_invalid                           = (glw::GLint)GL_MIRROR_CLAMP_TO_EDGE;
12021         glw::GLint min_filter_invalid             = (glw::GLint)GL_NEAREST_MIPMAP_NEAREST;
12022
12023         /* Check that INVALID_ENUM is generated by TextureParameter* if pname is
12024          not one of the accepted defined values. */
12025         {
12026                 gl.textureParameterIiv(m_to_2D, m_pname_invalid, &one);
12027
12028                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIiv",
12029                                                                   "pname is not one of the accepted defined values.");
12030         }
12031
12032         /* Check that INVALID_ENUM is generated by TextureParameter* if params
12033          should have a defined constant value (based on the value of pname) and
12034          does not. */
12035         {
12036                 gl.textureParameterIiv(m_to_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, &depth_stencil_mode_invalid);
12037
12038                 is_ok &=
12039                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIiv",
12040                                                          "params should have a defined constant value (based on the value of pname) and does not.");
12041         }
12042
12043         /* Check that INVALID_ENUM is generated by TextureParameter* if the
12044          effective target is either TEXTURE_2D_MULTISAMPLE or
12045          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states. */
12046         {
12047                 gl.textureParameterIiv(m_to_2D_ms, GL_TEXTURE_LOD_BIAS, &one);
12048
12049                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIiv",
12050                                                                   "the  effective target is either TEXTURE_2D_MULTISAMPLE or  "
12051                                                                   "TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states.");
12052         }
12053
12054         /* Check that INVALID_ENUM is generated by TextureParameter* if the
12055          effective target is TEXTURE_RECTANGLE and either of pnames
12056          TEXTURE_WRAP_S or TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE,
12057          MIRRORED_REPEAT or REPEAT. */
12058         {
12059                 gl.textureParameterIiv(m_to_rectangle, GL_TEXTURE_WRAP_S, &wrap_invalid);
12060
12061                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIiv",
12062                                                                   "the effective target is TEXTURE_RECTANGLE and either of pnames TEXTURE_WRAP_S or "
12063                                                                   "TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE, MIRRORED_REPEAT or REPEAT.");
12064         }
12065
12066         /* Check that INVALID_ENUM is generated by TextureParameter* if the
12067          effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is
12068          set to a value other than NEAREST or LINEAR (no mipmap filtering is
12069          permitted). */
12070         {
12071                 gl.textureParameterIiv(m_to_rectangle, GL_TEXTURE_MIN_FILTER, &min_filter_invalid);
12072
12073                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIiv",
12074                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is set to a "
12075                                                                   "value other than NEAREST or LINEAR (no mipmap filtering is permitted).");
12076         }
12077
12078         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12079          effective target is either TEXTURE_2D_MULTISAMPLE or
12080          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname TEXTURE_BASE_LEVEL is set to a
12081          value other than zero. */
12082         {
12083                 gl.textureParameterIiv(m_to_2D_ms, GL_TEXTURE_BASE_LEVEL, &one);
12084
12085                 is_ok &=
12086                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIiv",
12087                                                          "the effective target is either TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY, "
12088                                                          "and pname TEXTURE_BASE_LEVEL is set to a value other than zero.");
12089         }
12090
12091         /* Check that INVALID_OPERATION is generated by TextureParameter* if
12092          texture is not the name of an existing texture object. */
12093         {
12094                 gl.textureParameterIiv(m_to_invalid, GL_TEXTURE_LOD_BIAS, &one);
12095
12096                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIiv",
12097                                                                   "texture is not the name of an existing texture object.");
12098         }
12099
12100         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12101          effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is
12102          set to any value other than zero. */
12103         {
12104                 gl.textureParameterIiv(m_to_rectangle, GL_TEXTURE_BASE_LEVEL, &one);
12105
12106                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIiv",
12107                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is set to "
12108                                                                   "any value other than zero. ");
12109         }
12110
12111         /* Check that INVALID_VALUE is generated by TextureParameter* if pname is
12112          TEXTURE_BASE_LEVEL or TEXTURE_MAX_LEVEL, and param or params is
12113          negative. */
12114         {
12115                 gl.textureParameterIiv(m_to_2D, GL_TEXTURE_BASE_LEVEL, &minus_one);
12116
12117                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameterIiv",
12118                                                                   "pname is TEXTURE_BASE_LEVEL and param is negative.");
12119
12120                 gl.textureParameterIiv(m_to_2D, GL_TEXTURE_MAX_LEVEL, &minus_one);
12121
12122                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameterIiv",
12123                                                                   "pname is TEXTURE_MAX_LEVEL and param is negative.");
12124         }
12125
12126         return is_ok;
12127 }
12128
12129 /** @brief Test (negative) of TextureParameterIuiv
12130  *
12131  *  @return Test result.
12132  */
12133 bool ParameterSetupErrorsTest::TestIuiv()
12134 {
12135         /* Shortcut for GL functionality. */
12136         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
12137
12138         /* Result. */
12139         bool is_ok = true;
12140
12141         glw::GLuint one                                            = 1;
12142         glw::GLuint depth_stencil_mode_invalid = (glw::GLint)m_depth_stencil_mode_invalid;
12143         glw::GLuint wrap_invalid                           = (glw::GLint)GL_MIRROR_CLAMP_TO_EDGE;
12144         glw::GLuint min_filter_invalid             = (glw::GLint)GL_NEAREST_MIPMAP_NEAREST;
12145
12146         /* Check that INVALID_ENUM is generated by TextureParameter* if pname is
12147          not one of the accepted defined values. */
12148         {
12149                 gl.textureParameterIuiv(m_to_2D, m_pname_invalid, &one);
12150
12151                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIuiv",
12152                                                                   "pname is not one of the accepted defined values.");
12153         }
12154
12155         /* Check that INVALID_ENUM is generated by TextureParameter* if params
12156          should have a defined constant value (based on the value of pname) and
12157          does not. */
12158         {
12159                 gl.textureParameterIuiv(m_to_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, &depth_stencil_mode_invalid);
12160
12161                 is_ok &=
12162                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIuiv",
12163                                                          "params should have a defined constant value (based on the value of pname) and does not.");
12164         }
12165
12166         /* Check that INVALID_ENUM is generated by TextureParameter* if the
12167          effective target is either TEXTURE_2D_MULTISAMPLE or
12168          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states. */
12169         {
12170                 gl.textureParameterIuiv(m_to_2D_ms, GL_TEXTURE_LOD_BIAS, &one);
12171
12172                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIuiv",
12173                                                                   "the  effective target is either TEXTURE_2D_MULTISAMPLE or  "
12174                                                                   "TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states.");
12175         }
12176
12177         /* Check that INVALID_ENUM is generated by TextureParameter* if the
12178          effective target is TEXTURE_RECTANGLE and either of pnames
12179          TEXTURE_WRAP_S or TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE,
12180          MIRRORED_REPEAT or REPEAT. */
12181         {
12182                 gl.textureParameterIuiv(m_to_rectangle, GL_TEXTURE_WRAP_S, &wrap_invalid);
12183
12184                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIuiv",
12185                                                                   "the effective target is TEXTURE_RECTANGLE and either of pnames TEXTURE_WRAP_S or "
12186                                                                   "TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE, MIRRORED_REPEAT or REPEAT.");
12187         }
12188
12189         /* Check that INVALID_ENUM is generated by TextureParameter* if the
12190          effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is
12191          set to a value other than NEAREST or LINEAR (no mipmap filtering is
12192          permitted). */
12193         {
12194                 gl.textureParameterIuiv(m_to_rectangle, GL_TEXTURE_MIN_FILTER, &min_filter_invalid);
12195
12196                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIuiv",
12197                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is set to a "
12198                                                                   "value other than NEAREST or LINEAR (no mipmap filtering is permitted).");
12199         }
12200
12201         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12202          effective target is either TEXTURE_2D_MULTISAMPLE or
12203          TEXTURE_2D_MULTISAMPLE_ARRAY, and pname TEXTURE_BASE_LEVEL is set to a
12204          value other than zero. */
12205         {
12206                 gl.textureParameterIuiv(m_to_2D_ms, GL_TEXTURE_BASE_LEVEL, &one);
12207
12208                 is_ok &=
12209                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIuiv",
12210                                                          "the effective target is either TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY, "
12211                                                          "and pname TEXTURE_BASE_LEVEL is set to a value other than zero.");
12212         }
12213
12214         /* Check that INVALID_OPERATION is generated by TextureParameter* if
12215          texture is not the name of an existing texture object. */
12216         {
12217                 gl.textureParameterIuiv(m_to_invalid, GL_TEXTURE_LOD_BIAS, &one);
12218
12219                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIuiv",
12220                                                                   "texture is not the name of an existing texture object.");
12221         }
12222
12223         /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12224          effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is
12225          set to any value other than zero. */
12226         {
12227                 gl.textureParameterIuiv(m_to_rectangle, GL_TEXTURE_BASE_LEVEL, &one);
12228
12229                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIuiv",
12230                                                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is set to "
12231                                                                   "any value other than zero. ");
12232         }
12233
12234         return is_ok;
12235 }
12236
12237 /** @brief Clean GL objects, test variables and GL errors.
12238  */
12239 void ParameterSetupErrorsTest::Clean()
12240 {
12241         /* Shortcut for GL functionality. */
12242         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
12243
12244         /* Cleanup. */
12245         if (m_to_2D)
12246         {
12247                 gl.deleteTextures(1, &m_to_2D);
12248
12249                 m_to_2D = 0;
12250         }
12251
12252         if (m_to_2D_ms)
12253         {
12254                 gl.deleteTextures(1, &m_to_2D_ms);
12255
12256                 m_to_2D_ms = 0;
12257         }
12258
12259         if (m_to_rectangle)
12260         {
12261                 gl.deleteTextures(1, &m_to_rectangle);
12262
12263                 m_to_rectangle = 0;
12264         }
12265
12266         if (m_to_invalid)
12267         {
12268                 gl.deleteTextures(1, &m_to_invalid);
12269
12270                 m_to_invalid = 0;
12271         }
12272
12273         m_to_invalid    = 0;
12274         m_pname_invalid = 0;
12275
12276         while (GL_NO_ERROR != gl.getError())
12277                 ;
12278 }
12279
12280 /******************************** Generate Mipmap Errors Test Implementation   ********************************/
12281
12282 /** @brief Generate Mipmap Errors Test constructor.
12283  *
12284  *  @param [in] context     OpenGL context.
12285  */
12286 GenerateMipmapErrorsTest::GenerateMipmapErrorsTest(deqp::Context& context)
12287         : deqp::TestCase(context, "textures_generate_mipmap_errors", "Texture Generate Mipmap Errors Test")
12288 {
12289         /* Intentionally left blank. */
12290 }
12291
12292 /** @brief Iterate Generate Mipmap Errors Test cases.
12293  *
12294  *  @return Iteration result.
12295  */
12296 tcu::TestNode::IterateResult GenerateMipmapErrorsTest::iterate()
12297 {
12298         /* Shortcut for GL functionality. */
12299         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
12300
12301         /* Get context setup. */
12302         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
12303         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
12304
12305         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
12306         {
12307                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
12308
12309                 return STOP;
12310         }
12311
12312         /* Running tests. */
12313         bool is_ok      = true;
12314         bool is_error = false;
12315
12316         /* Objects. */
12317         glw::GLuint texture_invalid = 0;
12318         glw::GLuint texture_cube        = 0;
12319
12320         try
12321         {
12322                 /* Preparations. */
12323
12324                 /* incomplete cube map */
12325                 gl.genTextures(1, &texture_cube);
12326                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12327
12328                 gl.bindTexture(GL_TEXTURE_CUBE_MAP, texture_cube);
12329                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12330
12331                 gl.texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, s_reference_internalformat, s_reference_width,
12332                                           s_reference_height, 0, s_reference_format, s_reference_type, s_reference_data);
12333                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12334
12335                 /* invalid texture */
12336                 while (gl.isTexture(++texture_invalid))
12337                         ;
12338
12339                 /* Check that INVALID_OPERATION is generated by GenerateTextureMipmap if
12340                  texture is not the name of an existing texture object. */
12341                 gl.generateTextureMipmap(texture_invalid);
12342                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGenerateTextureMipmap",
12343                                                                   "texture is not the name of an existing texture object.");
12344
12345                 /* Check that INVALID_OPERATION is generated by GenerateTextureMipmap if
12346                  target is TEXTURE_CUBE_MAP or TEXTURE_CUBE_MAP_ARRAY, and the specified
12347                  texture object is not cube complete or cube array complete,
12348                  respectively. */
12349                 gl.generateTextureMipmap(texture_cube);
12350                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGenerateTextureMipmap",
12351                                                                   "target is TEXTURE_CUBE_MAP or TEXTURE_CUBE_MAP_ARRAY, and the specified texture "
12352                                                                   "object is not cube complete or cube array complete, respectively.");
12353         }
12354         catch (...)
12355         {
12356                 is_ok   = false;
12357                 is_error = true;
12358         }
12359
12360         /* Cleanup. */
12361         if (texture_cube)
12362         {
12363                 gl.deleteTextures(1, &texture_cube);
12364         }
12365
12366         while (GL_NO_ERROR != gl.getError())
12367                 ;
12368
12369         /* Result's setup. */
12370         if (is_ok)
12371         {
12372                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
12373         }
12374         else
12375         {
12376                 if (is_error)
12377                 {
12378                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
12379                 }
12380                 else
12381                 {
12382                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
12383                 }
12384         }
12385
12386         return STOP;
12387 }
12388
12389 /** Reference data. */
12390 const glw::GLubyte GenerateMipmapErrorsTest::s_reference_data[] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
12391                                                                                                                                         0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF };
12392
12393 /** Reference data parameters. */
12394 const glw::GLuint GenerateMipmapErrorsTest::s_reference_width              = 4;
12395 const glw::GLuint GenerateMipmapErrorsTest::s_reference_height             = 4;
12396 const glw::GLenum GenerateMipmapErrorsTest::s_reference_internalformat = GL_R8;
12397 const glw::GLenum GenerateMipmapErrorsTest::s_reference_format             = GL_RED;
12398 const glw::GLenum GenerateMipmapErrorsTest::s_reference_type               = GL_UNSIGNED_BYTE;
12399
12400 /******************************** Bind Unit Errors Test Implementation   ********************************/
12401
12402 /** @brief Bind Unit Errors Test constructor.
12403  *
12404  *  @param [in] context     OpenGL context.
12405  */
12406 BindUnitErrorsTest::BindUnitErrorsTest(deqp::Context& context)
12407         : deqp::TestCase(context, "textures_bind_unit_errors", "Texture Bind Unit Errors Test")
12408 {
12409         /* Intentionally left blank. */
12410 }
12411
12412 /** @brief IterateBind Unit Errors Test cases.
12413  *
12414  *  @return Iteration result.
12415  */
12416 tcu::TestNode::IterateResult BindUnitErrorsTest::iterate()
12417 {
12418         /* Shortcut for GL functionality. */
12419         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
12420
12421         /* Get context setup. */
12422         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
12423         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
12424
12425         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
12426         {
12427                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
12428
12429                 return STOP;
12430         }
12431
12432         /* Running tests. */
12433         bool is_ok      = true;
12434         bool is_error = false;
12435
12436         /* Objects. */
12437         glw::GLuint texture_invalid = 0;
12438
12439         try
12440         {
12441                 /* Prepare invalid texture */
12442                 while (gl.isTexture(++texture_invalid))
12443                         ;
12444
12445                 /* incomplete cube map */
12446
12447                 /* Check that INVALID_OPERATION error is generated if texture is not zero
12448                  or the name of an existing texture object. */
12449                 gl.bindTextureUnit(0, texture_invalid);
12450                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glBindTextureUnit",
12451                                                                   "texture is not zero or the name of an existing texture object.");
12452         }
12453         catch (...)
12454         {
12455                 is_ok   = false;
12456                 is_error = true;
12457         }
12458
12459         /* Cleanup. */
12460         while (GL_NO_ERROR != gl.getError())
12461                 ;
12462
12463         /* Result's setup. */
12464         if (is_ok)
12465         {
12466                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
12467         }
12468         else
12469         {
12470                 if (is_error)
12471                 {
12472                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
12473                 }
12474                 else
12475                 {
12476                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
12477                 }
12478         }
12479
12480         return STOP;
12481 }
12482
12483 /******************************** Image Query Errors Test Implementation   ********************************/
12484
12485 /** @brief Image Query Errors Test constructor.
12486  *
12487  *  @param [in] context     OpenGL context.
12488  */
12489 ImageQueryErrorsTest::ImageQueryErrorsTest(deqp::Context& context)
12490         : deqp::TestCase(context, "textures_image_query_errors", "Texture Image Query Errors Test")
12491 {
12492         /* Intentionally left blank. */
12493 }
12494
12495 /** Reference data. */
12496 const glw::GLuint ImageQueryErrorsTest::s_reference_data[] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
12497                                                                                                                            0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF };
12498
12499 /** Reference data parameters. */
12500 const glw::GLuint ImageQueryErrorsTest::s_reference_width                                         = 4;
12501 const glw::GLuint ImageQueryErrorsTest::s_reference_height                                        = 4;
12502 const glw::GLuint ImageQueryErrorsTest::s_reference_size                                          = sizeof(s_reference_data);
12503 const glw::GLenum ImageQueryErrorsTest::s_reference_internalformat                        = GL_R8;
12504 const glw::GLenum ImageQueryErrorsTest::s_reference_internalformat_int            = GL_R8I;
12505 const glw::GLenum ImageQueryErrorsTest::s_reference_internalformat_compressed = GL_COMPRESSED_RED_RGTC1;
12506 const glw::GLenum ImageQueryErrorsTest::s_reference_format                                        = GL_RED;
12507 const glw::GLenum ImageQueryErrorsTest::s_reference_type                                          = GL_UNSIGNED_INT;
12508
12509 /** @brief Iterate Image Query Errors Test cases.
12510  *
12511  *  @return Iteration result.
12512  */
12513 tcu::TestNode::IterateResult ImageQueryErrorsTest::iterate()
12514 {
12515         /* Shortcut for GL functionality. */
12516         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
12517
12518         /* Get context setup. */
12519         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
12520         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
12521
12522         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
12523         {
12524                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
12525
12526                 return STOP;
12527         }
12528
12529         /* Running tests. */
12530         bool is_ok      = true;
12531         bool is_error = false;
12532
12533         /* Objects. */
12534         glw::GLuint buffer                                                                                = 0;
12535         glw::GLuint texture_invalid                                                               = 0;
12536         glw::GLuint texture_2D                                                                    = 0;
12537         glw::GLuint texture_2D_int                                                                = 0;
12538         glw::GLuint texture_2D_ms                                                                 = 0;
12539         glw::GLuint texture_2D_stencil                                                    = 0;
12540         glw::GLuint texture_2D_compressed                                                 = 0;
12541         glw::GLuint texture_cube                                                                  = 0;
12542         glw::GLuint texture_rectangle                                                     = 0;
12543         glw::GLint  max_level                                                                     = 0;
12544         char            store[s_reference_size * 6 /* for cubemap */] = {};
12545
12546         try
12547         {
12548                 /* Preparations. */
12549
12550                 /* Buffer. */
12551                 gl.createBuffers(1, &buffer);
12552
12553                 gl.namedBufferData(buffer, s_reference_size + 1, NULL, GL_STATIC_COPY);
12554                 GLU_EXPECT_NO_ERROR(gl.getError(), "glNamedBufferData has failed");
12555
12556                 /* 2D texture */
12557                 gl.genTextures(1, &texture_2D);
12558                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12559
12560                 gl.bindTexture(GL_TEXTURE_2D, texture_2D);
12561                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12562
12563                 gl.texImage2D(GL_TEXTURE_2D, 0, s_reference_internalformat, s_reference_width, s_reference_height, 0,
12564                                           s_reference_format, s_reference_type, s_reference_data);
12565                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12566
12567                 /* 2D texture */
12568                 gl.genTextures(1, &texture_2D);
12569                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12570
12571                 gl.bindTexture(GL_TEXTURE_2D, texture_2D);
12572                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12573
12574                 gl.texImage2D(GL_TEXTURE_2D, 0, s_reference_internalformat, s_reference_width, s_reference_height, 0,
12575                                           s_reference_format, s_reference_type, s_reference_data);
12576                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12577
12578                 /* incomplete cube map */
12579                 gl.genTextures(1, &texture_cube);
12580                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12581
12582                 gl.bindTexture(GL_TEXTURE_CUBE_MAP, texture_cube);
12583                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12584
12585                 gl.texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, s_reference_internalformat, s_reference_width,
12586                                           s_reference_height, 0, s_reference_format, s_reference_type, s_reference_data);
12587                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12588
12589                 /* 2D multisample */
12590                 gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &texture_2D_ms);
12591                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12592
12593                 gl.textureStorage2DMultisample(texture_2D_ms, 1, s_reference_internalformat, s_reference_width,
12594                                                                            s_reference_height, false);
12595                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2DMultisample has failed");
12596
12597                 /* 2D stencil */
12598                 gl.createTextures(GL_TEXTURE_2D, 1, &texture_2D_stencil);
12599                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12600
12601                 gl.textureStorage2D(texture_2D_stencil, 1, GL_STENCIL_INDEX8, s_reference_width, s_reference_height);
12602                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2DMultisample has failed");
12603
12604                 /* 2D compressed texture  */
12605                 gl.genTextures(1, &texture_2D_compressed);
12606                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12607
12608                 gl.bindTexture(GL_TEXTURE_2D, texture_2D_compressed);
12609                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12610
12611                 gl.texImage2D(GL_TEXTURE_2D, 0, s_reference_internalformat_compressed, s_reference_width, s_reference_height, 0,
12612                                           s_reference_format, s_reference_type, s_reference_data);
12613                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12614
12615                 gl.getIntegerv(GL_MAX_TEXTURE_SIZE, &max_level); /* assuming that x > log(x) */
12616                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
12617
12618                 /* Rectangle texture */
12619                 gl.genTextures(1, &texture_rectangle);
12620                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12621
12622                 gl.bindTexture(GL_TEXTURE_RECTANGLE, texture_rectangle);
12623                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12624
12625                 gl.texImage2D(GL_TEXTURE_RECTANGLE, 0, s_reference_internalformat, s_reference_width, s_reference_height, 0,
12626                                           s_reference_format, s_reference_type, s_reference_data);
12627                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12628
12629                 /* invalid texture */
12630                 while (gl.isTexture(++texture_invalid))
12631                         ;
12632
12633                 /* Tests. */
12634
12635                 /* Check that INVALID_ENUM is generated by GetTextureImage functions if
12636                  resulting texture target is not an accepted value TEXTURE_1D,
12637                  TEXTURE_2D, TEXTURE_3D, TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY,
12638                  TEXTURE_CUBE_MAP_ARRAY, TEXTURE_RECTANGLE, and TEXTURE_CUBE_MAP. */
12639                 gl.getTextureImage(texture_2D_ms, 0, s_reference_format, s_reference_type, s_reference_size, store);
12640                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureImage",
12641                                                                   "resulting texture target is not an accepted value TEXTURE_1D, TEXTURE_2D, "
12642                                                                   "TEXTURE_3D, TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP_ARRAY, "
12643                                                                   "TEXTURE_RECTANGLE, and TEXTURE_CUBE_MAP.");
12644
12645                 /* Check that INVALID_OPERATION is generated by GetTextureImage
12646                  if texture is not the name of an existing texture object. */
12647                 gl.getTextureImage(texture_invalid, 0, s_reference_format, s_reference_type, s_reference_size, store);
12648                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12649                                                                   "texture is not the name of an existing texture object.");
12650
12651                 /* Check that INVALID_OPERATION error is generated by GetTextureImage if
12652                  the effective target is TEXTURE_CUBE_MAP or TEXTURE_CUBE_MAP_ARRAY, and
12653                  the texture object is not cube complete or cube array complete,
12654                  respectively. */
12655                 gl.getTextureImage(texture_cube, 0, s_reference_format, s_reference_type, s_reference_size * 6, store);
12656                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12657                                                                   "the effective target is TEXTURE_CUBE_MAP and the texture object is not cube "
12658                                                                   "complete or cube array complete, respectively.");
12659
12660                 /* Check that GL_INVALID_VALUE is generated if level is less than 0 or
12661                  larger than the maximum allowable level. */
12662                 gl.getTextureImage(texture_2D, -1, s_reference_format, s_reference_type, s_reference_size, store);
12663                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureImage", "level is less than 0.");
12664
12665                 gl.getTextureImage(texture_2D, max_level, s_reference_format, s_reference_type, s_reference_size, store);
12666                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureImage",
12667                                                                   "level is larger than the maximum allowable level.");
12668
12669                 /* Check that INVALID_VALUE error is generated if level is non-zero and the
12670                  effective target is TEXTURE_RECTANGLE. */
12671                 gl.getTextureImage(texture_rectangle, 1, s_reference_format, s_reference_type, s_reference_size, store);
12672                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureImage",
12673                                                                   "level is non-zero and the effective target is TEXTURE_RECTANGLE.");
12674
12675                 /* Check that INVALID_OPERATION error is generated if any of the following
12676                  mismatches between format and the internal format of the texture image
12677                  exist:
12678                  -  format is a color format (one of the formats in table 8.3 whose
12679                  target is the color buffer) and the base internal format of the
12680                  texture image is not a color format.
12681                  -  format is DEPTH_COMPONENT and the base internal format is  not
12682                  DEPTH_COMPONENT or DEPTH_STENCIL
12683                  -  format is DEPTH_STENCIL and the base internal format is not
12684                  DEPTH_STENCIL
12685                  -  format is STENCIL_INDEX and the base internal format is not
12686                  STENCIL_INDEX or DEPTH_STENCIL
12687                  -  format is one of the integer formats in table 8.3 and the internal
12688                  format of the texture image is not integer, or format is not one of
12689                  the integer formats in table 8.3 and the internal format is integer. */
12690                 gl.getTextureImage(texture_2D_stencil, 0, s_reference_format /* red */, s_reference_type, s_reference_size,
12691                                                    store);
12692                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12693                                                                   "format is a color format (one of the formats in table 8.3 whose target is the color "
12694                                                                   "buffer) and the base internal format of the texture image is not a color format.");
12695
12696                 gl.getTextureImage(texture_2D, 0, GL_DEPTH_COMPONENT, s_reference_type, s_reference_size, store);
12697                 is_ok &= CheckErrorAndLog(
12698                         m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12699                         "format is DEPTH_COMPONENT and the base internal format is not DEPTH_COMPONENT or DEPTH_STENCIL.");
12700
12701                 gl.getTextureImage(texture_2D, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, s_reference_size, store);
12702                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12703                                                                   "format is DEPTH_STENCIL and the base internal format is not DEPTH_STENCIL.");
12704
12705                 gl.getTextureImage(texture_2D, 0, GL_STENCIL_INDEX, s_reference_type, s_reference_size, store);
12706                 is_ok &= CheckErrorAndLog(
12707                         m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12708                         "format is STENCIL_INDEX and the base internal format is not STENCIL_INDEX or DEPTH_STENCIL.");
12709
12710                 gl.getTextureImage(texture_2D, 0, GL_RED_INTEGER, s_reference_type, s_reference_size, store);
12711                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12712                                                                   "format is one of the integer formats in table 8.3 and the internal format of the "
12713                                                                   "texture image is not integer.");
12714
12715                 gl.getTextureImage(texture_2D_int, 0, GL_RED, s_reference_type, s_reference_size, store);
12716                 is_ok &= CheckErrorAndLog(
12717                         m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12718                         "format is not one of the integer formats in table 8.3 and the internal format is integer.");
12719
12720                 /* Check that INVALID_OPERATION error is generated if a pixel pack buffer
12721                  object is bound and packing the texture image into the buffer’s memory
12722                  would exceed the size of the buffer. */
12723                 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, buffer);
12724                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
12725
12726                 gl.getTextureImage(texture_2D, 0, s_reference_format, s_reference_type, s_reference_size,
12727                                                    (glw::GLuint*)NULL + 1);
12728                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12729                                                                   "a pixel pack buffer object is bound and packing the texture image into the buffer’s "
12730                                                                   "memory would exceed the size of the buffer.");
12731
12732                 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, 0);
12733                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
12734
12735                 /* Check that INVALID_OPERATION error is generated if a pixel pack buffer
12736                  object is bound and pixels is not evenly divisible by the number of
12737                  basic machine units needed to store in memory the GL data type
12738                  corresponding to type (see table 8.2). */
12739                 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, buffer);
12740                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
12741
12742                 gl.getTextureImage(texture_2D, 0, s_reference_format, s_reference_type, s_reference_size,
12743                                                    (glw::GLubyte*)NULL + 1);
12744                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12745                                                                   "a pixel pack buffer object is bound and pixels is not evenly divisible by the "
12746                                                                   "number of basic machine units needed to store in memory the GL data type "
12747                                                                   "corresponding to type (see table 8.2).");
12748
12749                 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, 0);
12750                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
12751
12752                 /* Check that INVALID_OPERATION error is generated by GetTextureImage if
12753                  the buffer size required to store the requested data is greater than
12754                  bufSize. */
12755                 gl.getTextureImage(texture_2D, 0, s_reference_format, s_reference_type,
12756                                                    s_reference_size - sizeof(s_reference_data[0]), store);
12757                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12758                                                                   "the buffer size required to store the requested data is greater than bufSize.");
12759
12760                 /* Check that INVALID_OPERATION is generated by GetCompressedTextureImage
12761                  if texture is not the name of an existing texture object. */
12762                 gl.getCompressedTextureImage(texture_invalid, 0, s_reference_size, store);
12763                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetCompressedTextureImage",
12764                                                                   "texture is not the name of an existing texture object.");
12765
12766                 /* Check that INVALID_VALUE is generated by GetCompressedTextureImage if
12767                  level is less than zero or greater than the maximum number of LODs
12768                  permitted by the implementation. */
12769                 gl.getCompressedTextureImage(texture_2D_compressed, -1, s_reference_size, store);
12770                 is_ok &=
12771                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetCompressedTextureImage", "level is less than zero.");
12772
12773                 gl.getCompressedTextureImage(texture_2D_compressed, max_level, s_reference_size, store);
12774                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetCompressedTextureImage",
12775                                                                   "level is greater than the maximum number of LODs permitted by the implementation.");
12776
12777                 /* Check that INVALID_OPERATION is generated if GetCompressedTextureImage
12778                  is used to retrieve a texture that is in an uncompressed internal
12779                  format. */
12780                 gl.getCompressedTextureImage(texture_2D, 0, s_reference_size, store);
12781                 is_ok &=
12782                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetCompressedTextureImage",
12783                                                          "the function is used to retrieve a texture that is in an uncompressed internal format.");
12784
12785                 /* Check that INVALID_OPERATION is generated by GetCompressedTextureImage
12786                  if a non-zero buffer object name is bound to the PIXEL_PACK_BUFFER
12787                  target, the buffer storage was not initialized with BufferStorage using
12788                  MAP_PERSISTENT_BIT flag, and the buffer object's data store is currently
12789                  mapped. */
12790                 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, buffer);
12791                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
12792
12793                 gl.mapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_WRITE);
12794
12795                 if (GL_NO_ERROR == gl.getError())
12796                 {
12797                         gl.getCompressedTextureImage(texture_2D_compressed, 0, s_reference_size, NULL);
12798                         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetCompressedTextureImage",
12799                                                                           "a non-zero buffer object name is bound to the PIXEL_PACK_BUFFER target, the "
12800                                                                           "buffer storage was not initialized with BufferStorage using MAP_PERSISTENT_BIT "
12801                                                                           "flag, and the buffer object's data store is currently mapped.");
12802
12803                         gl.unmapBuffer(GL_PIXEL_PACK_BUFFER);
12804                         GLU_EXPECT_NO_ERROR(gl.getError(), "glUnmapBuffer has failed");
12805                 }
12806                 else
12807                 {
12808                         throw 0;
12809                 }
12810
12811                 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, 0);
12812                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
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 and the data would be packed to the buffer object such that the
12817                  memory writes required would exceed the data store size. */
12818                 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, buffer);
12819                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
12820
12821                 gl.getCompressedTextureImage(texture_2D_compressed, 0, s_reference_size, (char*)NULL + s_reference_size - 1);
12822                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetCompressedTextureImage",
12823                                                                   "a non-zero buffer object name is bound to the PIXEL_PACK_BUFFER target and the data "
12824                                                                   "would be packed to the buffer object such that the memory writes required would "
12825                                                                   "exceed the data store size.");
12826
12827                 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, 0);
12828                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
12829         }
12830         catch (...)
12831         {
12832                 is_ok   = false;
12833                 is_error = true;
12834         }
12835
12836         /* Cleanup. */
12837         if (buffer)
12838         {
12839                 gl.deleteBuffers(1, &buffer);
12840         }
12841
12842         if (texture_2D)
12843         {
12844                 gl.deleteTextures(1, &texture_2D);
12845         }
12846
12847         if (texture_2D_int)
12848         {
12849                 gl.deleteTextures(1, &texture_2D_int);
12850         }
12851
12852         if (texture_2D_stencil)
12853         {
12854                 gl.deleteTextures(1, &texture_2D_stencil);
12855         }
12856
12857         if (texture_2D_ms)
12858         {
12859                 gl.deleteTextures(1, &texture_2D_ms);
12860         }
12861
12862         if (texture_2D_compressed)
12863         {
12864                 gl.deleteTextures(1, &texture_2D_compressed);
12865         }
12866
12867         if (texture_cube)
12868         {
12869                 gl.deleteTextures(1, &texture_cube);
12870         }
12871
12872         if (texture_rectangle)
12873         {
12874                 gl.deleteTextures(1, &texture_rectangle);
12875         }
12876
12877         while (GL_NO_ERROR != gl.getError())
12878                 ;
12879
12880         /* Result's setup. */
12881         if (is_ok)
12882         {
12883                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
12884         }
12885         else
12886         {
12887                 if (is_error)
12888                 {
12889                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
12890                 }
12891                 else
12892                 {
12893                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
12894                 }
12895         }
12896
12897         return STOP;
12898 }
12899
12900 /******************************** Level Parameter Query Errors Test Implementation   ********************************/
12901
12902 /** @brief Image Query Errors Test constructor.
12903  *
12904  *  @param [in] context     OpenGL context.
12905  */
12906 LevelParameterErrorsTest::LevelParameterErrorsTest(deqp::Context& context)
12907         : deqp::TestCase(context, "textures_level_parameter_errors", "Texture Level Parameter Query Errors Test")
12908 {
12909         /* Intentionally left blank. */
12910 }
12911
12912 /** @brief Iterate Level Parameter Query Errors Test cases.
12913  *
12914  *  @return Iteration result.
12915  */
12916 tcu::TestNode::IterateResult LevelParameterErrorsTest::iterate()
12917 {
12918         /* Shortcut for GL functionality. */
12919         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
12920
12921         /* Get context setup. */
12922         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
12923         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
12924
12925         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
12926         {
12927                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
12928
12929                 return STOP;
12930         }
12931
12932         /* Running tests. */
12933         bool is_ok      = true;
12934         bool is_error = false;
12935
12936         /* Objects. */
12937         glw::GLuint texture_2D          = 0;
12938         glw::GLuint texture_invalid = 0;
12939         glw::GLint  max_level           = 0;
12940         glw::GLenum pname_invalid   = 0;
12941
12942         glw::GLfloat storef[4] = {};
12943         glw::GLint   storei[4] = {};
12944
12945         try
12946         {
12947                 /* Preparations. */
12948
12949                 /* 2D texture */
12950                 gl.genTextures(1, &texture_2D);
12951                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12952
12953                 gl.bindTexture(GL_TEXTURE_2D, texture_2D);
12954                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12955
12956                 gl.texStorage2D(GL_TEXTURE_2D, 1, GL_R8, 1, 1);
12957                 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12958
12959                 /* Limits. */
12960                 gl.getIntegerv(GL_MAX_TEXTURE_SIZE, &max_level); /* assuming that x > log(x) */
12961                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
12962
12963                 /* invalid texture */
12964                 while (gl.isTexture(++texture_invalid))
12965                         ;
12966
12967                 /* invalid pname */
12968                 glw::GLenum all_pnames[] = { GL_TEXTURE_WIDTH,
12969                                                                          GL_TEXTURE_HEIGHT,
12970                                                                          GL_TEXTURE_DEPTH,
12971                                                                          GL_TEXTURE_SAMPLES,
12972                                                                          GL_TEXTURE_FIXED_SAMPLE_LOCATIONS,
12973                                                                          GL_TEXTURE_INTERNAL_FORMAT,
12974                                                                          GL_TEXTURE_RED_SIZE,
12975                                                                          GL_TEXTURE_GREEN_SIZE,
12976                                                                          GL_TEXTURE_BLUE_SIZE,
12977                                                                          GL_TEXTURE_ALPHA_SIZE,
12978                                                                          GL_TEXTURE_DEPTH_SIZE,
12979                                                                          GL_TEXTURE_STENCIL_SIZE,
12980                                                                          GL_TEXTURE_SHARED_SIZE,
12981                                                                          GL_TEXTURE_RED_TYPE,
12982                                                                          GL_TEXTURE_GREEN_TYPE,
12983                                                                          GL_TEXTURE_BLUE_TYPE,
12984                                                                          GL_TEXTURE_ALPHA_TYPE,
12985                                                                          GL_TEXTURE_DEPTH_TYPE,
12986                                                                          GL_TEXTURE_COMPRESSED,
12987                                                                          GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
12988                                                                          GL_TEXTURE_BUFFER_DATA_STORE_BINDING,
12989                                                                          GL_TEXTURE_BUFFER_OFFSET,
12990                                                                          GL_TEXTURE_BUFFER_SIZE };
12991
12992                 glw::GLuint all_pnames_count = sizeof(all_pnames) / sizeof(all_pnames[0]);
12993
12994                 bool is_valid = true;
12995
12996                 while (is_valid)
12997                 {
12998                         is_valid = false;
12999
13000                         ++pname_invalid;
13001
13002                         for (glw::GLuint i = 0; i < all_pnames_count; ++i)
13003                         {
13004                                 if (all_pnames[i] == pname_invalid)
13005                                 {
13006                                         is_valid = true;
13007
13008                                         break;
13009                                 }
13010                         }
13011                 }
13012
13013                 /* Tests. */
13014
13015                 /* Check that INVALID_OPERATION is generated by GetTextureLevelParameterfv
13016                  and GetTextureLevelParameteriv functions if texture is not the name of
13017                  an existing texture object. */
13018                 gl.getTextureLevelParameterfv(texture_invalid, 0, GL_TEXTURE_WIDTH, storef);
13019                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureLevelParameterfv",
13020                                                                   "texture is not the name of an existing texture object.");
13021
13022                 gl.getTextureLevelParameteriv(texture_invalid, 0, GL_TEXTURE_WIDTH, storei);
13023                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureLevelParameteriv",
13024                                                                   "texture is not the name of an existing texture object.");
13025
13026                 /* Check that INVALID_VALUE is generated by GetTextureLevelParameter* if
13027                  level is less than 0. */
13028                 gl.getTextureLevelParameterfv(texture_2D, -1, GL_TEXTURE_WIDTH, storef);
13029                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureLevelParameterfv", "level is less than 0.");
13030
13031                 gl.getTextureLevelParameteriv(texture_2D, -1, GL_TEXTURE_WIDTH, storei);
13032                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureLevelParameteriv", "level is less than 0.");
13033
13034                 /* Check that INVALID_ENUM error is generated by GetTextureLevelParameter*
13035                  if pname is not one of supported constants. */
13036                 gl.getTextureLevelParameterfv(texture_2D, 0, pname_invalid, storef);
13037                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureLevelParameterfv",
13038                                                                   "pname is not one of supported constants.");
13039
13040                 gl.getTextureLevelParameteriv(texture_2D, 0, pname_invalid, storei);
13041                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureLevelParameteriv",
13042                                                                   "pname is not one of supported constants.");
13043
13044                 /* Check that INVALID_VALUE may be generated if level is greater than
13045                  log2 max, where max is the returned value of MAX_TEXTURE_SIZE. */
13046                 gl.getTextureLevelParameterfv(texture_2D, max_level, GL_TEXTURE_WIDTH, storef);
13047                 is_ok &=
13048                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureLevelParameterfv",
13049                                                          "level is greater than log2 max, where max is the returned value of MAX_TEXTURE_SIZE.");
13050
13051                 gl.getTextureLevelParameteriv(texture_2D, max_level, GL_TEXTURE_WIDTH, storei);
13052                 is_ok &=
13053                         CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureLevelParameteriv",
13054                                                          "level is greater than log2 max, where max is the returned value of MAX_TEXTURE_SIZE.");
13055
13056                 /* Check that INVALID_OPERATION is generated by GetTextureLevelParameter*
13057                  if TEXTURE_COMPRESSED_IMAGE_SIZE is queried on texture images with an
13058                  uncompressed internal format or on proxy targets. */
13059                 gl.getTextureLevelParameterfv(texture_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, storef);
13060                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureLevelParameterfv",
13061                                                                   "TEXTURE_COMPRESSED_IMAGE_SIZE is queried on texture images with an uncompressed "
13062                                                                   "internal format or on proxy targets.");
13063
13064                 gl.getTextureLevelParameteriv(texture_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, storei);
13065                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureLevelParameteriv",
13066                                                                   "TEXTURE_COMPRESSED_IMAGE_SIZE is queried on texture images with an uncompressed "
13067                                                                   "internal format or on proxy targets.");
13068         }
13069         catch (...)
13070         {
13071                 is_ok   = false;
13072                 is_error = true;
13073         }
13074
13075         /* Cleanup. */
13076         if (texture_2D)
13077         {
13078                 gl.deleteTextures(1, &texture_2D);
13079         }
13080
13081         while (GL_NO_ERROR != gl.getError())
13082                 ;
13083
13084         /* Result's setup. */
13085         if (is_ok)
13086         {
13087                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
13088         }
13089         else
13090         {
13091                 if (is_error)
13092                 {
13093                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
13094                 }
13095                 else
13096                 {
13097                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
13098                 }
13099         }
13100
13101         return STOP;
13102 }
13103
13104 /******************************** Parameter Query Errors Test Implementation   ********************************/
13105
13106 /** @brief Parameter Query Errors Test constructor.
13107  *
13108  *  @param [in] context     OpenGL context.
13109  */
13110 ParameterErrorsTest::ParameterErrorsTest(deqp::Context& context)
13111         : deqp::TestCase(context, "textures_parameter_errors", "Texture Parameter Query Errors Test")
13112 {
13113         /* Intentionally left blank. */
13114 }
13115
13116 /** @brief Iterate Parameter Query Errors Test cases.
13117  *
13118  *  @return Iteration result.
13119  */
13120 tcu::TestNode::IterateResult ParameterErrorsTest::iterate()
13121 {
13122         /* Shortcut for GL functionality. */
13123         const glw::Functions& gl = m_context.getRenderContext().getFunctions();
13124
13125         /* Get context setup. */
13126         bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
13127         bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
13128
13129         if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
13130         {
13131                 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
13132
13133                 return STOP;
13134         }
13135
13136         /* Running tests. */
13137         bool is_ok      = true;
13138         bool is_error = false;
13139
13140         /* Objects. */
13141         glw::GLuint texture_2D          = 0;
13142         glw::GLuint texture_buffer  = 0;
13143         glw::GLuint texture_invalid = 0;
13144         glw::GLenum pname_invalid   = 0;
13145
13146         glw::GLfloat storef[4] = {};
13147         glw::GLint   storei[4] = {};
13148         glw::GLuint  storeu[4] = {};
13149
13150         try
13151         {
13152                 /* Preparations. */
13153
13154                 /* 2D texture */
13155                 gl.createTextures(GL_TEXTURE_2D, 1, &texture_2D);
13156                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
13157
13158                 /* Buffer texture */
13159                 gl.createTextures(GL_TEXTURE_BUFFER, 1, &texture_buffer);
13160                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
13161
13162                 /* invalid texture */
13163                 while (gl.isTexture(++texture_invalid))
13164                         ;
13165
13166                 /* invalid pname */
13167                 glw::GLenum all_pnames[] = { GL_IMAGE_FORMAT_COMPATIBILITY_TYPE,
13168                                                                          GL_TEXTURE_IMMUTABLE_FORMAT,
13169                                                                          GL_TEXTURE_IMMUTABLE_LEVELS,
13170                                                                          GL_TEXTURE_TARGET,
13171                                                                          GL_TEXTURE_VIEW_MIN_LEVEL,
13172                                                                          GL_TEXTURE_VIEW_NUM_LEVELS,
13173                                                                          GL_TEXTURE_VIEW_MIN_LAYER,
13174                                                                          GL_TEXTURE_VIEW_NUM_LAYERS,
13175                                                                          GL_DEPTH_STENCIL_TEXTURE_MODE,
13176                                                                          GL_DEPTH_COMPONENT,
13177                                                                          GL_STENCIL_INDEX,
13178                                                                          GL_TEXTURE_BASE_LEVEL,
13179                                                                          GL_TEXTURE_BORDER_COLOR,
13180                                                                          GL_TEXTURE_COMPARE_MODE,
13181                                                                          GL_TEXTURE_COMPARE_FUNC,
13182                                                                          GL_TEXTURE_LOD_BIAS,
13183                                                                          GL_TEXTURE_MAG_FILTER,
13184                                                                          GL_TEXTURE_MAX_LEVEL,
13185                                                                          GL_TEXTURE_MAX_LOD,
13186                                                                          GL_TEXTURE_MIN_FILTER,
13187                                                                          GL_TEXTURE_MIN_LOD,
13188                                                                          GL_TEXTURE_SWIZZLE_R,
13189                                                                          GL_TEXTURE_SWIZZLE_G,
13190                                                                          GL_TEXTURE_SWIZZLE_B,
13191                                                                          GL_TEXTURE_SWIZZLE_A,
13192                                                                          GL_TEXTURE_SWIZZLE_RGBA,
13193                                                                          GL_TEXTURE_WRAP_S,
13194                                                                          GL_TEXTURE_WRAP_T,
13195                                                                          GL_TEXTURE_WRAP_R };
13196
13197                 glw::GLuint all_pnames_count = sizeof(all_pnames) / sizeof(all_pnames[0]);
13198
13199                 bool is_valid = true;
13200
13201                 while (is_valid)
13202                 {
13203                         is_valid = false;
13204
13205                         ++pname_invalid;
13206
13207                         for (glw::GLuint i = 0; i < all_pnames_count; ++i)
13208                         {
13209                                 if (all_pnames[i] == pname_invalid)
13210                                 {
13211                                         is_valid = true;
13212
13213                                         break;
13214                                 }
13215                         }
13216                 }
13217
13218                 /* Tests. */
13219
13220                 /* Check that INVALID_ENUM is generated by glGetTextureParameter* if pname
13221                  is not an accepted value. */
13222                 gl.getTextureParameterfv(texture_2D, pname_invalid, storef);
13223                 is_ok &=
13224                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureParameterfv", "pname is not an accepted value.");
13225
13226                 gl.getTextureParameterIiv(texture_2D, pname_invalid, storei);
13227                 is_ok &=
13228                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureParameterIiv", "pname is not an accepted value.");
13229
13230                 gl.getTextureParameterIuiv(texture_2D, pname_invalid, storeu);
13231                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureParameterIuiv",
13232                                                                   "pname is not an accepted value.");
13233
13234                 gl.getTextureParameteriv(texture_2D, pname_invalid, storei);
13235                 is_ok &=
13236                         CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureParameteriv", "pname is not an accepted value.");
13237
13238                 /* Check that INVALID_OPERATION is generated by glGetTextureParameter* if
13239                  texture is not the name of an existing texture object. */
13240                 gl.getTextureParameterfv(texture_invalid, GL_TEXTURE_TARGET, storef);
13241                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameterfv",
13242                                                                   "texture is not the name of an existing texture object.");
13243
13244                 gl.getTextureParameterIiv(texture_invalid, GL_TEXTURE_TARGET, storei);
13245                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameterIiv",
13246                                                                   "texture is not the name of an existing texture object.");
13247
13248                 gl.getTextureParameterIuiv(texture_invalid, GL_TEXTURE_TARGET, storeu);
13249                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameterIuiv",
13250                                                                   "texture is not the name of an existing texture object.");
13251
13252                 gl.getTextureParameteriv(texture_invalid, GL_TEXTURE_TARGET, storei);
13253                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameteriv",
13254                                                                   "texture is not the name of an existing texture object.");
13255
13256                 /* Check that INVALID_OPERATION error is generated if the effective target is
13257                  not one of the supported texture targets (eg. TEXTURE_BUFFER). */
13258                 gl.getTextureParameterfv(texture_buffer, GL_TEXTURE_TARGET, storef);
13259                 is_ok &=
13260                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameterfv",
13261                                                          "the effective target is not one of the supported texture targets (eg. TEXTURE_BUFFER).");
13262
13263                 gl.getTextureParameterIiv(texture_buffer, GL_TEXTURE_TARGET, storei);
13264                 is_ok &=
13265                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameterIiv",
13266                                                          "the effective target is not one of the supported texture targets (eg. TEXTURE_BUFFER).");
13267
13268                 gl.getTextureParameterIuiv(texture_buffer, GL_TEXTURE_TARGET, storeu);
13269                 is_ok &=
13270                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameterIuiv",
13271                                                          "the effective target is not one of the supported texture targets (eg. TEXTURE_BUFFER).");
13272
13273                 gl.getTextureParameteriv(texture_buffer, GL_TEXTURE_TARGET, storei);
13274                 is_ok &=
13275                         CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameteriv",
13276                                                          "the effective target is not one of the supported texture targets (eg. TEXTURE_BUFFER).");
13277         }
13278         catch (...)
13279         {
13280                 is_ok   = false;
13281                 is_error = true;
13282         }
13283
13284         /* Cleanup. */
13285         if (texture_2D)
13286         {
13287                 gl.deleteTextures(1, &texture_2D);
13288         }
13289
13290         if (texture_buffer)
13291         {
13292                 gl.deleteTextures(1, &texture_buffer);
13293         }
13294
13295         while (GL_NO_ERROR != gl.getError())
13296                 ;
13297
13298         /* Result's setup. */
13299         if (is_ok)
13300         {
13301                 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
13302         }
13303         else
13304         {
13305                 if (is_error)
13306                 {
13307                         m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
13308                 }
13309                 else
13310                 {
13311                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
13312                 }
13313         }
13314
13315         return STOP;
13316 }
13317
13318 } /* Textures namespace. */
13319 } /* DirectStateAccess namespace. */
13320 } /* gl4cts namespace. */