xref: /aosp_15_r20/external/deqp/external/openglcts/modules/gl/gl4cDirectStateAccessTexturesTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
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  */
CreationTest(deqp::Context & context)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  */
iterate()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 <>
InternalFormat()221 glw::GLenum Reference::InternalFormat<glw::GLbyte, 1, false>()
222 {
223     return GL_R8I;
224 }
225 
226 template <>
InternalFormat()227 glw::GLenum Reference::InternalFormat<glw::GLbyte, 2, false>()
228 {
229     return GL_RG8I;
230 }
231 
232 template <>
InternalFormat()233 glw::GLenum Reference::InternalFormat<glw::GLbyte, 3, false>()
234 {
235     return GL_RGB8I;
236 }
237 
238 template <>
InternalFormat()239 glw::GLenum Reference::InternalFormat<glw::GLbyte, 4, false>()
240 {
241     return GL_RGBA8I;
242 }
243 
244 template <>
InternalFormat()245 glw::GLenum Reference::InternalFormat<glw::GLubyte, 1, false>()
246 {
247     return GL_R8UI;
248 }
249 
250 template <>
InternalFormat()251 glw::GLenum Reference::InternalFormat<glw::GLubyte, 2, false>()
252 {
253     return GL_RG8UI;
254 }
255 
256 template <>
InternalFormat()257 glw::GLenum Reference::InternalFormat<glw::GLubyte, 3, false>()
258 {
259     return GL_RGB8UI;
260 }
261 
262 template <>
InternalFormat()263 glw::GLenum Reference::InternalFormat<glw::GLubyte, 4, false>()
264 {
265     return GL_RGBA8UI;
266 }
267 
268 template <>
InternalFormat()269 glw::GLenum Reference::InternalFormat<glw::GLshort, 1, false>()
270 {
271     return GL_R16I;
272 }
273 
274 template <>
InternalFormat()275 glw::GLenum Reference::InternalFormat<glw::GLshort, 2, false>()
276 {
277     return GL_RG16I;
278 }
279 
280 template <>
InternalFormat()281 glw::GLenum Reference::InternalFormat<glw::GLshort, 3, false>()
282 {
283     return GL_RGB16I;
284 }
285 
286 template <>
InternalFormat()287 glw::GLenum Reference::InternalFormat<glw::GLshort, 4, false>()
288 {
289     return GL_RGBA16I;
290 }
291 
292 template <>
InternalFormat()293 glw::GLenum Reference::InternalFormat<glw::GLushort, 1, false>()
294 {
295     return GL_R16UI;
296 }
297 
298 template <>
InternalFormat()299 glw::GLenum Reference::InternalFormat<glw::GLushort, 2, false>()
300 {
301     return GL_RG16UI;
302 }
303 
304 template <>
InternalFormat()305 glw::GLenum Reference::InternalFormat<glw::GLushort, 3, false>()
306 {
307     return GL_RGB16UI;
308 }
309 
310 template <>
InternalFormat()311 glw::GLenum Reference::InternalFormat<glw::GLushort, 4, false>()
312 {
313     return GL_RGBA16UI;
314 }
315 
316 template <>
InternalFormat()317 glw::GLenum Reference::InternalFormat<glw::GLint, 1, false>()
318 {
319     return GL_R32I;
320 }
321 
322 template <>
InternalFormat()323 glw::GLenum Reference::InternalFormat<glw::GLint, 2, false>()
324 {
325     return GL_RG32I;
326 }
327 
328 template <>
InternalFormat()329 glw::GLenum Reference::InternalFormat<glw::GLint, 3, false>()
330 {
331     return GL_RGB32I;
332 }
333 
334 template <>
InternalFormat()335 glw::GLenum Reference::InternalFormat<glw::GLint, 4, false>()
336 {
337     return GL_RGBA32I;
338 }
339 
340 template <>
InternalFormat()341 glw::GLenum Reference::InternalFormat<glw::GLuint, 1, false>()
342 {
343     return GL_R32UI;
344 }
345 
346 template <>
InternalFormat()347 glw::GLenum Reference::InternalFormat<glw::GLuint, 2, false>()
348 {
349     return GL_RG32UI;
350 }
351 
352 template <>
InternalFormat()353 glw::GLenum Reference::InternalFormat<glw::GLuint, 3, false>()
354 {
355     return GL_RGB32UI;
356 }
357 
358 template <>
InternalFormat()359 glw::GLenum Reference::InternalFormat<glw::GLuint, 4, false>()
360 {
361     return GL_RGBA32UI;
362 }
363 
364 template <>
InternalFormat()365 glw::GLenum Reference::InternalFormat<glw::GLubyte, 1, true>()
366 {
367     return GL_R8;
368 }
369 
370 template <>
InternalFormat()371 glw::GLenum Reference::InternalFormat<glw::GLubyte, 2, true>()
372 {
373     return GL_RG8;
374 }
375 
376 template <>
InternalFormat()377 glw::GLenum Reference::InternalFormat<glw::GLubyte, 3, true>()
378 {
379     return GL_RGB8;
380 }
381 
382 template <>
InternalFormat()383 glw::GLenum Reference::InternalFormat<glw::GLubyte, 4, true>()
384 {
385     return GL_RGBA8;
386 }
387 
388 template <>
InternalFormat()389 glw::GLenum Reference::InternalFormat<glw::GLushort, 1, true>()
390 {
391     return GL_R16;
392 }
393 
394 template <>
InternalFormat()395 glw::GLenum Reference::InternalFormat<glw::GLushort, 2, true>()
396 {
397     return GL_RG16;
398 }
399 
400 template <>
InternalFormat()401 glw::GLenum Reference::InternalFormat<glw::GLushort, 3, true>()
402 {
403     return GL_RGB16;
404 }
405 
406 template <>
InternalFormat()407 glw::GLenum Reference::InternalFormat<glw::GLushort, 4, true>()
408 {
409     return GL_RGBA16;
410 }
411 
412 template <>
InternalFormat()413 glw::GLenum Reference::InternalFormat<glw::GLfloat, 1, true>()
414 {
415     return GL_R32F;
416 }
417 
418 template <>
InternalFormat()419 glw::GLenum Reference::InternalFormat<glw::GLfloat, 2, true>()
420 {
421     return GL_RG32F;
422 }
423 
424 template <>
InternalFormat()425 glw::GLenum Reference::InternalFormat<glw::GLfloat, 3, true>()
426 {
427     return GL_RGB32F;
428 }
429 
430 template <>
InternalFormat()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 <>
Format()444 glw::GLenum Reference::Format<1, false>()
445 {
446     return GL_RED_INTEGER;
447 }
448 
449 template <>
Format()450 glw::GLenum Reference::Format<2, false>()
451 {
452     return GL_RG_INTEGER;
453 }
454 
455 template <>
Format()456 glw::GLenum Reference::Format<3, false>()
457 {
458     return GL_RGB_INTEGER;
459 }
460 
461 template <>
Format()462 glw::GLenum Reference::Format<4, false>()
463 {
464     return GL_RGBA_INTEGER;
465 }
466 
467 template <>
Format()468 glw::GLenum Reference::Format<1, true>()
469 {
470     return GL_RED;
471 }
472 
473 template <>
Format()474 glw::GLenum Reference::Format<2, true>()
475 {
476     return GL_RG;
477 }
478 
479 template <>
Format()480 glw::GLenum Reference::Format<3, true>()
481 {
482     return GL_RGB;
483 }
484 
485 template <>
Format()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 <>
Type()498 glw::GLenum Reference::Type<glw::GLbyte>()
499 {
500     return GL_BYTE;
501 }
502 
503 template <>
Type()504 glw::GLenum Reference::Type<glw::GLubyte>()
505 {
506     return GL_UNSIGNED_BYTE;
507 }
508 
509 template <>
Type()510 glw::GLenum Reference::Type<glw::GLshort>()
511 {
512     return GL_SHORT;
513 }
514 
515 template <>
Type()516 glw::GLenum Reference::Type<glw::GLushort>()
517 {
518     return GL_UNSIGNED_SHORT;
519 }
520 
521 template <>
Type()522 glw::GLenum Reference::Type<glw::GLint>()
523 {
524     return GL_INT;
525 }
526 
527 template <>
Type()528 glw::GLenum Reference::Type<glw::GLuint>()
529 {
530     return GL_UNSIGNED_INT;
531 }
532 
533 template <>
Type()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 <>
ReferenceData()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     return reference;
557 }
558 
559 /* RGBA8UI */
560 template <>
ReferenceData()561 const glw::GLubyte *Reference::ReferenceData<glw::GLubyte, false>()
562 {
563     static const glw::GLubyte reference[s_reference_count] = {
564         0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
565         24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
566         48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
567         72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95};
568     return reference;
569 }
570 
571 /* RGBA16I */
572 template <>
ReferenceData()573 const glw::GLshort *Reference::ReferenceData<glw::GLshort, false>()
574 {
575     static const glw::GLshort reference[s_reference_count] = {
576         0,  -1,  2,  -3,  4,  -5,  6,  -7,  8,  -9,  10, -11, 12, -13, 14, -15, 16, -17, 18, -19, 20, -21, 22, -23,
577         24, -25, 26, -27, 28, -29, 30, -31, 32, -33, 34, -35, 36, -37, 38, -39, 40, -41, 42, -43, 44, -45, 46, -47,
578         48, -49, 50, -51, 52, -53, 54, -55, 56, -57, 58, -59, 60, -61, 62, -63, 64, -65, 66, -67, 68, -69, 70, -71,
579         72, -73, 74, -75, 76, -77, 78, -79, 80, -81, 82, -83, 84, -85, 86, -87, 88, -89, 90, -91, 92, -93, 94, -95};
580     return reference;
581 }
582 
583 /* RGBA16UI */
584 template <>
ReferenceData()585 const glw::GLushort *Reference::ReferenceData<glw::GLushort, false>()
586 {
587     static const glw::GLushort reference[s_reference_count] = {
588         0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
589         24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
590         48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
591         72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95};
592     return reference;
593 }
594 
595 /* RGBA32I */
596 template <>
ReferenceData()597 const glw::GLint *Reference::ReferenceData<glw::GLint, false>()
598 {
599     static const glw::GLint reference[s_reference_count] = {
600         0,  -1,  2,  -3,  4,  -5,  6,  -7,  8,  -9,  10, -11, 12, -13, 14, -15, 16, -17, 18, -19, 20, -21, 22, -23,
601         24, -25, 26, -27, 28, -29, 30, -31, 32, -33, 34, -35, 36, -37, 38, -39, 40, -41, 42, -43, 44, -45, 46, -47,
602         48, -49, 50, -51, 52, -53, 54, -55, 56, -57, 58, -59, 60, -61, 62, -63, 64, -65, 66, -67, 68, -69, 70, -71,
603         72, -73, 74, -75, 76, -77, 78, -79, 80, -81, 82, -83, 84, -85, 86, -87, 88, -89, 90, -91, 92, -93, 94, -95};
604     return reference;
605 }
606 
607 /* RGBA32UI */
608 template <>
ReferenceData()609 const glw::GLuint *Reference::ReferenceData<glw::GLuint, false>()
610 {
611     static const glw::GLuint reference[s_reference_count] = {
612         0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
613         24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
614         48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
615         72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95};
616     return reference;
617 }
618 
619 /* RGBA8 */
620 template <>
ReferenceData()621 const glw::GLubyte *Reference::ReferenceData<glw::GLubyte, true>()
622 {
623     static const glw::GLubyte reference[s_reference_count] = {
624         0,   2,   5,   8,   10,  13,  16,  18,  21,  24,  26,  29,  32,  34,  37,  40,  42,  45,  48,  51,
625         53,  56,  59,  61,  64,  67,  69,  72,  75,  77,  80,  83,  85,  88,  91,  93,  96,  99,  102, 104,
626         107, 110, 112, 115, 118, 120, 123, 126, 128, 131, 134, 136, 139, 142, 144, 147, 150, 153, 155, 158,
627         161, 163, 166, 169, 171, 174, 177, 179, 182, 185, 187, 190, 193, 195, 198, 201, 204, 206, 209, 212,
628         214, 217, 220, 222, 225, 228, 230, 233, 236, 238, 241, 244, 246, 249, 252, 255};
629     return reference;
630 }
631 
632 /* RGBA16 */
633 template <>
ReferenceData()634 const glw::GLushort *Reference::ReferenceData<glw::GLushort, true>()
635 {
636     static const glw::GLushort reference[s_reference_count] = {
637         0,     689,   1379,  2069,  2759,  3449,  4139,  4828,  5518,  6208,  6898,  7588,  8278,  8967,  9657,  10347,
638         11037, 11727, 12417, 13107, 13796, 14486, 15176, 15866, 16556, 17246, 17935, 18625, 19315, 20005, 20695, 21385,
639         22074, 22764, 23454, 24144, 24834, 25524, 26214, 26903, 27593, 28283, 28973, 29663, 30353, 31042, 31732, 32422,
640         33112, 33802, 34492, 35181, 35871, 36561, 37251, 37941, 38631, 39321, 40010, 40700, 41390, 42080, 42770, 43460,
641         44149, 44839, 45529, 46219, 46909, 47599, 48288, 48978, 49668, 50358, 51048, 51738, 52428, 53117, 53807, 54497,
642         55187, 55877, 56567, 57256, 57946, 58636, 59326, 60016, 60706, 61395, 62085, 62775, 63465, 64155, 64845, 65535};
643     return reference;
644 }
645 
646 /* RGBA32F */
647 template <>
ReferenceData()648 const glw::GLfloat *Reference::ReferenceData<glw::GLfloat, true>()
649 {
650     static const glw::GLfloat reference[s_reference_count] = {
651         0.f,           0.0105263158f, 0.0210526316f, 0.0315789474f, 0.0421052632f, 0.0526315789f,
652         0.0631578947f, 0.0736842105f, 0.0842105263f, 0.0947368421f, 0.1052631579f, 0.1157894737f,
653         0.1263157895f, 0.1368421053f, 0.1473684211f, 0.1578947368f, 0.1684210526f, 0.1789473684f,
654         0.1894736842f, 0.2f,          0.2105263158f, 0.2210526316f, 0.2315789474f, 0.2421052632f,
655         0.2526315789f, 0.2631578947f, 0.2736842105f, 0.2842105263f, 0.2947368421f, 0.3052631579f,
656         0.3157894737f, 0.3263157895f, 0.3368421053f, 0.3473684211f, 0.3578947368f, 0.3684210526f,
657         0.3789473684f, 0.3894736842f, 0.4f,          0.4105263158f, 0.4210526316f, 0.4315789474f,
658         0.4421052632f, 0.4526315789f, 0.4631578947f, 0.4736842105f, 0.4842105263f, 0.4947368421f,
659         0.5052631579f, 0.5157894737f, 0.5263157895f, 0.5368421053f, 0.5473684211f, 0.5578947368f,
660         0.5684210526f, 0.5789473684f, 0.5894736842f, 0.6f,          0.6105263158f, 0.6210526316f,
661         0.6315789474f, 0.6421052632f, 0.6526315789f, 0.6631578947f, 0.6736842105f, 0.6842105263f,
662         0.6947368421f, 0.7052631579f, 0.7157894737f, 0.7263157895f, 0.7368421053f, 0.7473684211f,
663         0.7578947368f, 0.7684210526f, 0.7789473684f, 0.7894736842f, 0.8f,          0.8105263158f,
664         0.8210526316f, 0.8315789474f, 0.8421052632f, 0.8526315789f, 0.8631578947f, 0.8736842105f,
665         0.8842105263f, 0.8947368421f, 0.9052631579f, 0.9157894737f, 0.9263157895f, 0.9368421053f,
666         0.9473684211f, 0.9578947368f, 0.9684210526f, 0.9789473684f, 0.9894736842f, 1.f};
667     return reference;
668 }
669 
670 /* Total number of reference components. */
ReferenceDataCount()671 glw::GLuint Reference::ReferenceDataCount()
672 {
673     return s_reference_count;
674 }
675 
676 /* Total number of reference size in basic machine units. */
677 template <typename T>
ReferenceDataSize()678 glw::GLuint Reference::ReferenceDataSize()
679 {
680     return Reference::ReferenceDataCount() * sizeof(T);
681 }
682 
683 /** @brief Comparison function (for floats).
684  *
685  *  @param [in] a      First element.
686  *  @param [in] b      Second element.
687  *
688  *  @return Comparison result.
689  */
690 template <>
Compare(const glw::GLfloat a,const glw::GLfloat b)691 bool Reference::Compare<glw::GLfloat>(const glw::GLfloat a, const glw::GLfloat b)
692 {
693     if (de::abs(a - b) < 1.f / 256.f)
694     {
695         return true;
696     }
697     return false;
698 }
699 
700 /** @brief Comparison function (integer).
701  *
702  *  @param [in] a      First element.
703  *  @param [in] b      Second element.
704  *
705  *  @return Comparison result.
706  */
707 template <typename T>
Compare(const T a,const T b)708 bool Reference::Compare(const T a, const T b)
709 {
710     return a == b;
711 }
712 
713 /******************************** Buffer Test Implementation   ********************************/
714 
715 /** @brief Buffer Test constructor.
716  *
717  *  @tparam T      Type.
718  *  @tparam S      Size.
719  *  @tparam N      Is normalized.
720  *
721  *  @param [in] context     OpenGL context.
722  *  @param [in] name     Name of the test.
723  */
724 template <typename T, glw::GLint S, bool N>
BufferTest(deqp::Context & context,const char * name)725 BufferTest<T, S, N>::BufferTest(deqp::Context &context, const char *name)
726     : deqp::TestCase(context, name, "Texture Buffer Objects Test")
727     , m_fbo(0)
728     , m_rbo(0)
729     , m_po(0)
730     , m_to(0)
731     , m_bo(0)
732     , m_vao(0)
733 {
734     /* Intentionally left blank. */
735 }
736 
737 /** @brief Count of reference data to be teted.
738  *
739  *  @return Count.
740  */
741 template <typename T, glw::GLint S, bool N>
TestReferenceDataCount()742 glw::GLuint BufferTest<T, S, N>::TestReferenceDataCount()
743 {
744     return s_fbo_size_x * S;
745 }
746 
747 /** @brief Size of reference data to be teted..
748  *
749  *  @return Size.
750  */
751 template <typename T, glw::GLint S, bool N>
TestReferenceDataSize()752 glw::GLuint BufferTest<T, S, N>::TestReferenceDataSize()
753 {
754     return static_cast<glw::GLint>(TestReferenceDataCount() * sizeof(T));
755 }
756 
757 /** @brief Create buffer textuew.
758  *
759  *  @param [in] use_range_version       Uses TextureBufferRange instead TextureBuffer.
760  *
761  *  @return True if succeded, false otherwise.
762  */
763 template <typename T, glw::GLint S, bool N>
CreateBufferTexture(bool use_range_version)764 bool BufferTest<T, S, N>::CreateBufferTexture(bool use_range_version)
765 {
766     /* Shortcut for GL functionality. */
767     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
768 
769     /* Objects creation. */
770     gl.genTextures(1, &m_to);
771     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
772 
773     gl.bindTexture(GL_TEXTURE_BUFFER, m_to);
774     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
775 
776     gl.genBuffers(1, &m_bo);
777     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateBuffers has failed");
778 
779     gl.bindBuffer(GL_TEXTURE_BUFFER, m_bo);
780     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
781 
782     /* Data setup. */
783     if (use_range_version)
784     {
785         glw::GLint alignment = 1;
786 
787         gl.getIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, &alignment);
788         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
789 
790         const glw::GLuint b_offset = alignment;
791         const glw::GLuint b_size   = TestReferenceDataSize() + b_offset;
792 
793         gl.bufferData(GL_TEXTURE_BUFFER, b_size, NULL, GL_STATIC_DRAW);
794         GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData has failed");
795 
796         gl.bufferSubData(GL_TEXTURE_BUFFER, b_offset, TestReferenceDataSize(), ReferenceData<T, N>());
797         GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferSubdata has failed");
798 
799         gl.textureBufferRange(m_to, InternalFormat<T, S, N>(), m_bo, b_offset, TestReferenceDataSize());
800     }
801     else
802     {
803         gl.bufferData(GL_TEXTURE_BUFFER, TestReferenceDataSize(), ReferenceData<T, N>(), GL_STATIC_DRAW);
804         GLU_EXPECT_NO_ERROR(gl.getError(), "glNamedBufferData has failed");
805 
806         gl.textureBuffer(m_to, InternalFormat<T, S, N>(), m_bo);
807     }
808 
809     /* Error checking. */
810     glw::GLenum error;
811 
812     if (GL_NO_ERROR != (error = gl.getError()))
813     {
814         /* Log. */
815         m_context.getTestContext().getLog()
816             << tcu::TestLog::Message << (use_range_version ? ("glTextureBufferRange") : ("glTextureBuffer"))
817             << " unexpectedly generated error " << glu::getErrorStr(error) << " during test of internal format "
818             << glu::getTextureFormatStr(InternalFormat<T, S, N>()) << "." << tcu::TestLog::EndMessage;
819 
820         CleanBufferTexture();
821 
822         return false;
823     }
824 
825     return true;
826 }
827 
828 /** @brief Function prepares framebuffer with internal format color attachment.
829  *         Viewport is set up. Content of the framebuffer is cleared.
830  *
831  *  @note The function may throw if unexpected error has occured.
832  *
833  *  @return if the framebuffer returned is supported
834  */
835 template <typename T, glw::GLint S, bool N>
PrepareFramebuffer(const glw::GLenum internal_format)836 bool BufferTest<T, S, N>::PrepareFramebuffer(const glw::GLenum internal_format)
837 {
838     /* Shortcut for GL functionality. */
839     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
840 
841     /* Prepare framebuffer. */
842     gl.genFramebuffers(1, &m_fbo);
843     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
844 
845     gl.genRenderbuffers(1, &m_rbo);
846     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
847 
848     gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
849     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
850 
851     gl.bindRenderbuffer(GL_RENDERBUFFER, m_rbo);
852     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
853 
854     gl.renderbufferStorage(GL_RENDERBUFFER, internal_format, s_fbo_size_x, s_fbo_size_y);
855     GLU_EXPECT_NO_ERROR(gl.getError(), "glRenderbufferStorage call failed.");
856 
857     gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_rbo);
858     GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
859 
860     if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
861     {
862         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_UNSUPPORTED)
863             throw tcu::NotSupportedError("unsupported framebuffer configuration");
864         else
865             throw 0;
866     }
867 
868     gl.viewport(0, 0, s_fbo_size_x, s_fbo_size_y);
869     GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
870 
871     /* Clear framebuffer's content. */
872     gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
873     GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
874 
875     gl.clear(GL_COLOR_BUFFER_BIT);
876     GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
877 
878     return true;
879 }
880 
881 /** @brief Create program.
882  *
883  *  @param [in] variable_declaration    Choose variable declaration of the fragment shader.
884  */
885 template <typename T, glw::GLint S, bool N>
PrepareProgram(const glw::GLchar * variable_declaration)886 void BufferTest<T, S, N>::PrepareProgram(const glw::GLchar *variable_declaration)
887 {
888     /* Shortcut for GL functionality */
889     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
890 
891     struct Shader
892     {
893         glw::GLchar const *source[3];
894         glw::GLsizei const count;
895         glw::GLenum const type;
896         glw::GLuint id;
897     } shader[] = {{{s_vertex_shader, NULL, NULL}, 1, GL_VERTEX_SHADER, 0},
898                   {{s_fragment_shader_head, variable_declaration, s_fragment_shader_tail}, 3, GL_FRAGMENT_SHADER, 0}};
899 
900     glw::GLuint const shader_count = sizeof(shader) / sizeof(shader[0]);
901 
902     try
903     {
904         /* Create program. */
905         m_po = gl.createProgram();
906         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateProgram call failed.");
907 
908         /* Shader compilation. */
909 
910         for (glw::GLuint i = 0; i < shader_count; ++i)
911         {
912             {
913                 shader[i].id = gl.createShader(shader[i].type);
914 
915                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateShader call failed.");
916 
917                 gl.attachShader(m_po, shader[i].id);
918 
919                 GLU_EXPECT_NO_ERROR(gl.getError(), "glAttachShader call failed.");
920 
921                 gl.shaderSource(shader[i].id, shader[i].count, shader[i].source, NULL);
922 
923                 GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource call failed.");
924 
925                 gl.compileShader(shader[i].id);
926 
927                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader call failed.");
928 
929                 glw::GLint status = GL_FALSE;
930 
931                 gl.getShaderiv(shader[i].id, GL_COMPILE_STATUS, &status);
932                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
933 
934                 if (GL_FALSE == status)
935                 {
936                     glw::GLint log_size = 0;
937                     gl.getShaderiv(shader[i].id, GL_INFO_LOG_LENGTH, &log_size);
938                     GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
939 
940                     glw::GLchar *log_text = new glw::GLchar[log_size];
941 
942                     gl.getShaderInfoLog(shader[i].id, log_size, NULL, &log_text[0]);
943 
944                     m_context.getTestContext().getLog()
945                         << tcu::TestLog::Message << "Shader compilation has failed.\n"
946                         << "Shader type: " << glu::getShaderTypeStr(shader[i].type) << "\n"
947                         << "Shader compilation error log:\n"
948                         << log_text << "\n"
949                         << "Shader source code:\n"
950                         << shader[i].source[0] << (shader[i].source[1] ? shader[i].source[1] : "")
951                         << (shader[i].source[2] ? shader[i].source[2] : "") << "\n"
952                         << tcu::TestLog::EndMessage;
953 
954                     delete[] log_text;
955 
956                     GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog call failed.");
957 
958                     throw 0;
959                 }
960             }
961         }
962 
963         /* Link. */
964         gl.linkProgram(m_po);
965 
966         GLU_EXPECT_NO_ERROR(gl.getError(), "glTransformFeedbackVaryings call failed.");
967 
968         glw::GLint status = GL_FALSE;
969 
970         gl.getProgramiv(m_po, GL_LINK_STATUS, &status);
971 
972         if (GL_TRUE == status)
973         {
974             for (glw::GLuint i = 0; i < shader_count; ++i)
975             {
976                 if (shader[i].id)
977                 {
978                     gl.detachShader(m_po, shader[i].id);
979 
980                     GLU_EXPECT_NO_ERROR(gl.getError(), "glDetachShader call failed.");
981                 }
982             }
983         }
984         else
985         {
986             glw::GLint log_size = 0;
987 
988             gl.getProgramiv(m_po, GL_INFO_LOG_LENGTH, &log_size);
989 
990             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv call failed.");
991 
992             glw::GLchar *log_text = new glw::GLchar[log_size];
993 
994             gl.getProgramInfoLog(m_po, log_size, NULL, &log_text[0]);
995 
996             m_context.getTestContext().getLog() << tcu::TestLog::Message << "Program linkage has failed due to:\n"
997                                                 << log_text << "\n"
998                                                 << tcu::TestLog::EndMessage;
999 
1000             delete[] log_text;
1001 
1002             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramInfoLog call failed.");
1003 
1004             throw 0;
1005         }
1006     }
1007     catch (...)
1008     {
1009         if (m_po)
1010         {
1011             gl.deleteProgram(m_po);
1012 
1013             m_po = 0;
1014         }
1015     }
1016 
1017     for (glw::GLuint i = 0; i < shader_count; ++i)
1018     {
1019         if (0 != shader[i].id)
1020         {
1021             gl.deleteShader(shader[i].id);
1022 
1023             shader[i].id = 0;
1024         }
1025     }
1026 
1027     if (0 == m_po)
1028     {
1029         throw 0;
1030     }
1031 }
1032 
1033 /** @brief Create VAO.
1034  */
1035 template <typename T, glw::GLint S, bool N>
PrepareVertexArray()1036 void BufferTest<T, S, N>::PrepareVertexArray()
1037 {
1038     /* Shortcut for GL functionality. */
1039     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1040 
1041     gl.genVertexArrays(1, &m_vao);
1042     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays has failed");
1043 
1044     gl.bindVertexArray(m_vao);
1045     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray has failed");
1046 }
1047 
1048 /** @brief Test's draw function.
1049  */
1050 template <typename T, glw::GLint S, bool N>
Draw()1051 void BufferTest<T, S, N>::Draw()
1052 {
1053     /* Shortcut for GL functionality. */
1054     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1055 
1056     gl.useProgram(m_po);
1057     GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed");
1058 
1059     gl.activeTexture(GL_TEXTURE0);
1060     GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
1061 
1062     gl.bindTextureUnit(0, m_to);
1063     GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
1064 
1065     gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
1066     GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed");
1067 }
1068 
1069 /** @brief Compre results with the reference.
1070  *
1071  *  @return True if equal, false otherwise.
1072  */
1073 template <typename T, glw::GLint S, bool N>
Check()1074 bool BufferTest<T, S, N>::Check()
1075 {
1076     /* Shortcut for GL functionality. */
1077     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1078 
1079     /* Fetching data. */
1080     std::vector<T> result(TestReferenceDataCount());
1081 
1082     gl.pixelStorei(GL_UNPACK_ALIGNMENT, sizeof(T));
1083     GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
1084 
1085     gl.pixelStorei(GL_PACK_ALIGNMENT, sizeof(T));
1086     GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
1087 
1088     gl.readnPixels(0, 0, s_fbo_size_x, s_fbo_size_y, Format<S, N>(), Type<T>(), TestReferenceDataSize(),
1089                    (glw::GLvoid *)(&result[0]));
1090     GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels has failed");
1091 
1092     /* Comparison. */
1093     bool is_ok = true;
1094 
1095     for (glw::GLuint i = 0; i < TestReferenceDataCount(); ++i)
1096     {
1097         if (!Compare<T>(result[i], ReferenceData<T, N>()[i]))
1098         {
1099             is_ok = false;
1100 
1101             break;
1102         }
1103     }
1104 
1105     return is_ok;
1106 }
1107 
1108 /** @brief Test function.
1109  *
1110  *  @param [in] use_range_version   Uses TextureBufferRange instead TextureBuffer.
1111  *
1112  *  @return True if succeeded, false otherwise.
1113  */
1114 template <typename T, glw::GLint S, bool N>
Test(bool use_range_version)1115 bool BufferTest<T, S, N>::Test(bool use_range_version)
1116 {
1117     /* Setup. */
1118     if (!PrepareFramebuffer(InternalFormat<T, S, N>()))
1119     {
1120         /**
1121          * If the framebuffer it not supported, means that the
1122          * tested combination is unsupported for this driver,
1123          * but allowed to be unsupported by OpenGL spec, so we
1124          * just skip.
1125          */
1126         CleanFramebuffer();
1127         CleanErrors();
1128 
1129         return true;
1130     }
1131 
1132     if (!CreateBufferTexture(use_range_version))
1133     {
1134         CleanFramebuffer();
1135         CleanErrors();
1136 
1137         return false;
1138     }
1139 
1140     /* Action. */
1141     Draw();
1142 
1143     /* Compare results with reference. */
1144     bool result = Check();
1145 
1146     /* Cleanup. */
1147     CleanFramebuffer();
1148     CleanBufferTexture();
1149     CleanErrors();
1150 
1151     /* Pass result. */
1152     return result;
1153 }
1154 
1155 /** @brief Clean GL objects
1156  */
1157 template <typename T, glw::GLint S, bool N>
CleanBufferTexture()1158 void BufferTest<T, S, N>::CleanBufferTexture()
1159 {
1160     /* Shortcut for GL functionality. */
1161     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1162 
1163     /* Texture. */
1164     if (m_to)
1165     {
1166         gl.deleteTextures(1, &m_to);
1167 
1168         m_to = 0;
1169     }
1170 
1171     /* Texture buffer. */
1172     if (m_bo)
1173     {
1174         gl.deleteBuffers(1, &m_bo);
1175 
1176         m_bo = 0;
1177     }
1178 }
1179 
1180 /** @brief Clean GL objects
1181  */
1182 template <typename T, glw::GLint S, bool N>
CleanFramebuffer()1183 void BufferTest<T, S, N>::CleanFramebuffer()
1184 {
1185     /* Shortcut for GL functionality. */
1186     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1187 
1188     /* Framebuffer. */
1189     if (m_fbo)
1190     {
1191         gl.deleteFramebuffers(1, &m_fbo);
1192 
1193         m_fbo = 0;
1194     }
1195 
1196     /* Renderbuffer. */
1197     if (m_rbo)
1198     {
1199         gl.deleteRenderbuffers(1, &m_rbo);
1200 
1201         m_rbo = 0;
1202     }
1203 }
1204 
1205 /** @brief Clean GL objects
1206  */
1207 template <typename T, glw::GLint S, bool N>
CleanProgram()1208 void BufferTest<T, S, N>::CleanProgram()
1209 {
1210     /* Shortcut for GL functionality. */
1211     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1212 
1213     /* Program. */
1214     if (m_po)
1215     {
1216         gl.useProgram(0);
1217 
1218         gl.deleteProgram(m_po);
1219 
1220         m_po = 0;
1221     }
1222 }
1223 
1224 /** @brief Clean errors.
1225  */
1226 template <typename T, glw::GLint S, bool N>
CleanErrors()1227 void BufferTest<T, S, N>::CleanErrors()
1228 {
1229     /* Shortcut for GL functionality. */
1230     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1231 
1232     /* Query all errors until GL_NO_ERROR occure. */
1233     while (GL_NO_ERROR != gl.getError())
1234         ;
1235 }
1236 
1237 /** @brief Clean GL objects
1238  */
1239 template <typename T, glw::GLint S, bool N>
CleanVertexArray()1240 void BufferTest<T, S, N>::CleanVertexArray()
1241 {
1242     /* Shortcut for GL functionality. */
1243     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1244 
1245     if (m_vao)
1246     {
1247         gl.bindVertexArray(0);
1248 
1249         gl.deleteVertexArrays(1, &m_vao);
1250 
1251         m_vao = 0;
1252     }
1253 }
1254 
1255 /** @brief Iterate Buffer Test cases.
1256  *
1257  *  @return Iteration result.
1258  */
1259 template <typename T, glw::GLint S, bool N>
iterate()1260 tcu::TestNode::IterateResult BufferTest<T, S, N>::iterate()
1261 {
1262     /* Shortcut for GL functionality. */
1263     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1264 
1265     /* Get context setup. */
1266     bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
1267     bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
1268 
1269     if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
1270     {
1271         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
1272 
1273         return STOP;
1274     }
1275 
1276     /* Running tests. */
1277     bool is_ok    = true;
1278     bool is_error = false;
1279 
1280     try
1281     {
1282         PrepareVertexArray();
1283 
1284         PrepareProgram(FragmentShaderDeclaration());
1285 
1286         for (glw::GLuint i = 0; i < 2; ++i)
1287         {
1288             bool use_range = (i == 1);
1289             is_ok &= Test(use_range);
1290             CleanErrors();
1291         }
1292 
1293         CleanProgram();
1294     }
1295     catch (tcu::NotSupportedError &e)
1296     {
1297         throw e;
1298     }
1299     catch (...)
1300     {
1301         is_ok    = false;
1302         is_error = true;
1303     }
1304 
1305     /* Cleanup. */
1306     CleanBufferTexture();
1307     CleanFramebuffer();
1308     CleanProgram();
1309     CleanErrors();
1310     CleanVertexArray();
1311 
1312     /* Errors clean up. */
1313     while (gl.getError())
1314         ;
1315 
1316     /* Result's setup. */
1317     if (is_ok)
1318     {
1319         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1320     }
1321     else
1322     {
1323         if (is_error)
1324         {
1325             m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
1326         }
1327         else
1328         {
1329             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
1330         }
1331     }
1332 
1333     return STOP;
1334 }
1335 
1336 /* Vertex shader source code. */
1337 template <typename T, glw::GLint S, bool N>
1338 const glw::GLchar *BufferTest<T, S, N>::s_vertex_shader = "#version 450\n"
1339                                                           "\n"
1340                                                           "void main()\n"
1341                                                           "{\n"
1342                                                           "    switch(gl_VertexID)\n"
1343                                                           "    {\n"
1344                                                           "        case 0:\n"
1345                                                           "            gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
1346                                                           "            break;\n"
1347                                                           "        case 1:\n"
1348                                                           "            gl_Position = vec4( 1.0, 1.0, 0.0, 1.0);\n"
1349                                                           "            break;\n"
1350                                                           "        case 2:\n"
1351                                                           "            gl_Position = vec4(-1.0,-1.0, 0.0, 1.0);\n"
1352                                                           "            break;\n"
1353                                                           "        case 3:\n"
1354                                                           "            gl_Position = vec4( 1.0,-1.0, 0.0, 1.0);\n"
1355                                                           "            break;\n"
1356                                                           "    }\n"
1357                                                           "}\n";
1358 
1359 /* Fragment shader source program. */
1360 template <typename T, glw::GLint S, bool N>
1361 const glw::GLchar *BufferTest<T, S, N>::s_fragment_shader_head = "#version 450\n"
1362                                                                  "\n"
1363                                                                  "layout(pixel_center_integer) in vec4 gl_FragCoord;\n"
1364                                                                  "\n";
1365 
1366 template <typename T, glw::GLint S, bool N>
1367 const glw::GLchar *BufferTest<T, S, N>::s_fragment_shader_fdecl_lowp = "uniform samplerBuffer texture_input;\n"
1368                                                                        "out     vec4          texture_output;\n";
1369 
1370 template <typename T, glw::GLint S, bool N>
1371 const glw::GLchar *BufferTest<T, S, N>::s_fragment_shader_idecl_lowp = "uniform isamplerBuffer texture_input;\n"
1372                                                                        "out     ivec4          texture_output;\n";
1373 
1374 template <typename T, glw::GLint S, bool N>
1375 const glw::GLchar *BufferTest<T, S, N>::s_fragment_shader_udecl_lowp = "uniform usamplerBuffer texture_input;\n"
1376                                                                        "out     uvec4          texture_output;\n";
1377 
1378 template <typename T, glw::GLint S, bool N>
1379 const glw::GLchar *BufferTest<T, S, N>::s_fragment_shader_fdecl_mediump = "uniform samplerBuffer texture_input;\n"
1380                                                                           "out     vec4          texture_output;\n";
1381 
1382 template <typename T, glw::GLint S, bool N>
1383 const glw::GLchar *BufferTest<T, S, N>::s_fragment_shader_idecl_mediump = "uniform isamplerBuffer texture_input;\n"
1384                                                                           "out     ivec4          texture_output;\n";
1385 
1386 template <typename T, glw::GLint S, bool N>
1387 const glw::GLchar *BufferTest<T, S, N>::s_fragment_shader_udecl_mediump = "uniform usamplerBuffer texture_input;\n"
1388                                                                           "out     uvec4          texture_output;\n";
1389 
1390 template <typename T, glw::GLint S, bool N>
1391 const glw::GLchar *BufferTest<T, S, N>::s_fragment_shader_fdecl_highp = "uniform samplerBuffer texture_input;\n"
1392                                                                         "out     vec4          texture_output;\n";
1393 
1394 template <typename T, glw::GLint S, bool N>
1395 const glw::GLchar *BufferTest<T, S, N>::s_fragment_shader_idecl_highp = "uniform isamplerBuffer texture_input;\n"
1396                                                                         "out     ivec4          texture_output;\n";
1397 
1398 template <typename T, glw::GLint S, bool N>
1399 const glw::GLchar *BufferTest<T, S, N>::s_fragment_shader_udecl_highp = "uniform usamplerBuffer texture_input;\n"
1400                                                                         "out     uvec4          texture_output;\n";
1401 
1402 template <typename T, glw::GLint S, bool N>
1403 const glw::GLchar *BufferTest<T, S, N>::s_fragment_shader_tail =
1404     "\n"
1405     "void main()\n"
1406     "{\n"
1407     "    texture_output = texelFetch(texture_input, int(gl_FragCoord.x));\n"
1408     "}\n";
1409 
1410 template class BufferTest<glw::GLbyte, 1, false>;
1411 template class BufferTest<glw::GLbyte, 2, false>;
1412 template class BufferTest<glw::GLbyte, 4, false>;
1413 
1414 template class BufferTest<glw::GLubyte, 1, false>;
1415 template class BufferTest<glw::GLubyte, 2, false>;
1416 template class BufferTest<glw::GLubyte, 4, false>;
1417 template class BufferTest<glw::GLubyte, 1, true>;
1418 template class BufferTest<glw::GLubyte, 2, true>;
1419 template class BufferTest<glw::GLubyte, 4, true>;
1420 
1421 template class BufferTest<glw::GLshort, 1, false>;
1422 template class BufferTest<glw::GLshort, 2, false>;
1423 template class BufferTest<glw::GLshort, 4, false>;
1424 
1425 template class BufferTest<glw::GLushort, 1, false>;
1426 template class BufferTest<glw::GLushort, 2, false>;
1427 template class BufferTest<glw::GLushort, 4, false>;
1428 template class BufferTest<glw::GLushort, 1, true>;
1429 template class BufferTest<glw::GLushort, 2, true>;
1430 template class BufferTest<glw::GLushort, 4, true>;
1431 
1432 template class BufferTest<glw::GLint, 1, false>;
1433 template class BufferTest<glw::GLint, 2, false>;
1434 template class BufferTest<glw::GLint, 3, false>;
1435 template class BufferTest<glw::GLint, 4, false>;
1436 
1437 template class BufferTest<glw::GLuint, 1, false>;
1438 template class BufferTest<glw::GLuint, 2, false>;
1439 template class BufferTest<glw::GLuint, 3, false>;
1440 template class BufferTest<glw::GLuint, 4, false>;
1441 
1442 template class BufferTest<glw::GLfloat, 1, true>;
1443 template class BufferTest<glw::GLfloat, 2, true>;
1444 template class BufferTest<glw::GLfloat, 3, true>;
1445 template class BufferTest<glw::GLfloat, 4, true>;
1446 
1447 /******************************** Storage and SubImage Test Implementation   ********************************/
1448 
1449 /** @brief Storage Test constructor.
1450  *
1451  *  @tparam T      Type.
1452  *  @tparam S      Size.
1453  *  @tparam N      Is normalized.
1454  *  @tparam D      Texture dimension.
1455  *  @tparam I      Choose between SubImage and Storage tests.
1456  *
1457  *  @param [in] context     OpenGL context.
1458  *  @param [in] name        Name of the test.
1459  */
1460 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
StorageAndSubImageTest(deqp::Context & context,const char * name)1461 StorageAndSubImageTest<T, S, N, D, I>::StorageAndSubImageTest(deqp::Context &context, const char *name)
1462     : deqp::TestCase(context, name, "Texture Storage and SubImage Test")
1463     , m_fbo(0)
1464     , m_rbo(0)
1465     , m_po(0)
1466     , m_to(0)
1467     , m_vao(0)
1468 {
1469     /* Intentionally left blank. */
1470 }
1471 
1472 /** @brief Count of reference data to be teted.
1473  *
1474  *  @return Count.
1475  */
1476 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
TestReferenceDataCount()1477 glw::GLuint StorageAndSubImageTest<T, S, N, D, I>::TestReferenceDataCount()
1478 {
1479     return 2 /* 1D */ * ((D > 1) ? 3 : 1) /* 2D */ * ((D > 2) ? 4 : 1) /* 3D */ * S /* components */;
1480 }
1481 
1482 /** @brief Size of reference data to be teted.
1483  *
1484  *  @tparam T      Type.
1485  *  @tparam S      Size (# of components).
1486  *  @tparam D      Texture dimenisons.
1487  *
1488  *  @return Size.
1489  */
1490 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
TestReferenceDataSize()1491 glw::GLuint StorageAndSubImageTest<T, S, N, D, I>::TestReferenceDataSize()
1492 {
1493     return static_cast<glw::GLint>(TestReferenceDataCount() * sizeof(T));
1494 }
1495 
1496 /** @brief Height, width or depth of reference data to be teted.
1497  *
1498  *  @return Height, width or depth.
1499  */
1500 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
TestReferenceDataHeight()1501 glw::GLuint StorageAndSubImageTest<T, S, N, D, I>::TestReferenceDataHeight()
1502 {
1503     switch (D)
1504     {
1505     case 2:
1506     case 3:
1507         return 3;
1508     default:
1509         return 1;
1510     }
1511 }
1512 
1513 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
TestReferenceDataDepth()1514 glw::GLuint StorageAndSubImageTest<T, S, N, D, I>::TestReferenceDataDepth()
1515 {
1516     switch (D)
1517     {
1518     case 3:
1519         return 4;
1520     default:
1521         return 1;
1522     }
1523 }
1524 
1525 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
TestReferenceDataWidth()1526 glw::GLuint StorageAndSubImageTest<T, S, N, D, I>::TestReferenceDataWidth()
1527 {
1528     return 2;
1529 }
1530 
1531 /** @brief Fragment shader declaration selector.
1532  *
1533  *  @return Frgment shader source code part.
1534  */
1535 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
FragmentShaderDeclaration()1536 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::FragmentShaderDeclaration()
1537 {
1538     if (typeid(T) == typeid(glw::GLbyte))
1539     {
1540         switch (D)
1541         {
1542         case 1:
1543             return s_fragment_shader_1D_idecl_lowp;
1544         case 2:
1545             return s_fragment_shader_2D_idecl_lowp;
1546         case 3:
1547             return s_fragment_shader_3D_idecl_lowp;
1548         default:
1549             DE_FATAL("invalid texture dimension");
1550             return DE_NULL;
1551         }
1552     }
1553 
1554     if (typeid(T) == typeid(glw::GLubyte))
1555     {
1556         if (N)
1557         {
1558             switch (D)
1559             {
1560             case 1:
1561                 return s_fragment_shader_1D_fdecl_lowp;
1562             case 2:
1563                 return s_fragment_shader_2D_fdecl_lowp;
1564             case 3:
1565                 return s_fragment_shader_3D_fdecl_lowp;
1566             default:
1567                 DE_FATAL("invalid texture dimension");
1568                 return DE_NULL;
1569             }
1570         }
1571         else
1572         {
1573             switch (D)
1574             {
1575             case 1:
1576                 return s_fragment_shader_1D_udecl_lowp;
1577             case 2:
1578                 return s_fragment_shader_2D_udecl_lowp;
1579             case 3:
1580                 return s_fragment_shader_3D_udecl_lowp;
1581             default:
1582                 DE_FATAL("invalid texture dimension");
1583                 return DE_NULL;
1584             }
1585         }
1586     }
1587 
1588     if (typeid(T) == typeid(glw::GLshort))
1589     {
1590         switch (D)
1591         {
1592         case 1:
1593             return s_fragment_shader_1D_idecl_mediump;
1594         case 2:
1595             return s_fragment_shader_2D_idecl_mediump;
1596         case 3:
1597             return s_fragment_shader_3D_idecl_mediump;
1598         default:
1599             DE_FATAL("invalid texture dimension");
1600             return DE_NULL;
1601         }
1602     }
1603 
1604     if (typeid(T) == typeid(glw::GLushort))
1605     {
1606         if (N)
1607         {
1608             switch (D)
1609             {
1610             case 1:
1611                 return s_fragment_shader_1D_fdecl_mediump;
1612             case 2:
1613                 return s_fragment_shader_2D_fdecl_mediump;
1614             case 3:
1615                 return s_fragment_shader_3D_fdecl_mediump;
1616             default:
1617                 DE_FATAL("invalid texture dimension");
1618                 return DE_NULL;
1619             }
1620         }
1621         else
1622         {
1623             switch (D)
1624             {
1625             case 1:
1626                 return s_fragment_shader_1D_udecl_mediump;
1627             case 2:
1628                 return s_fragment_shader_2D_udecl_mediump;
1629             case 3:
1630                 return s_fragment_shader_3D_udecl_mediump;
1631             default:
1632                 DE_FATAL("invalid texture dimension");
1633                 return DE_NULL;
1634             }
1635         }
1636     }
1637 
1638     if (typeid(T) == typeid(glw::GLint))
1639     {
1640         switch (D)
1641         {
1642         case 1:
1643             return s_fragment_shader_1D_idecl_highp;
1644         case 2:
1645             return s_fragment_shader_2D_idecl_highp;
1646         case 3:
1647             return s_fragment_shader_3D_idecl_highp;
1648         default:
1649             DE_FATAL("invalid texture dimension");
1650             return DE_NULL;
1651         }
1652     }
1653 
1654     if (typeid(T) == typeid(glw::GLuint))
1655     {
1656         switch (D)
1657         {
1658         case 1:
1659             return s_fragment_shader_1D_udecl_highp;
1660         case 2:
1661             return s_fragment_shader_2D_udecl_highp;
1662         case 3:
1663             return s_fragment_shader_3D_udecl_highp;
1664         default:
1665             DE_FATAL("invalid texture dimension");
1666             return DE_NULL;
1667         }
1668     }
1669 
1670     switch (D)
1671     {
1672     case 1:
1673         return s_fragment_shader_1D_fdecl_highp;
1674     case 2:
1675         return s_fragment_shader_2D_fdecl_highp;
1676     case 3:
1677         return s_fragment_shader_3D_fdecl_highp;
1678     default:
1679         DE_FATAL("invalid texture dimension");
1680         return DE_NULL;
1681     }
1682 }
1683 
1684 /** @brief Fragment shader tail selector.
1685  *
1686  *  @tparam D      Texture dimenisons.
1687  *
1688  *  @return Frgment shader source code part.
1689  */
1690 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
FragmentShaderTail()1691 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::FragmentShaderTail()
1692 {
1693     switch (D)
1694     {
1695     case 1:
1696         return s_fragment_shader_1D_tail;
1697     case 2:
1698         return s_fragment_shader_2D_tail;
1699     case 3:
1700         return s_fragment_shader_3D_tail;
1701     default:
1702         DE_FATAL("invalid texture dimension");
1703         return DE_NULL;
1704     }
1705 }
1706 
1707 /** @brief Texture target selector.
1708  *
1709  *  @tparam D      Texture dimenisons.
1710  *
1711  *  @return Texture target.
1712  */
1713 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
TextureTarget()1714 glw::GLenum StorageAndSubImageTest<T, S, N, D, I>::TextureTarget()
1715 {
1716     switch (D)
1717     {
1718     case 1:
1719         return GL_TEXTURE_1D;
1720     case 2:
1721         return GL_TEXTURE_2D;
1722     case 3:
1723         return GL_TEXTURE_3D;
1724     default:
1725         DE_FATAL("invalid texture dimension");
1726         return DE_NULL;
1727     }
1728 }
1729 
1730 /** @brief TextureStorage* wrapper.
1731  *
1732  *  @return true if succeed (in legacy always or throw), false otherwise.
1733  */
1734 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
TextureStorage(glw::GLenum target,glw::GLuint texture,glw::GLsizei levels,glw::GLenum internalformat,glw::GLsizei width,glw::GLsizei height,glw::GLsizei depth)1735 bool StorageAndSubImageTest<T, S, N, D, I>::TextureStorage(glw::GLenum target, glw::GLuint texture, glw::GLsizei levels,
1736                                                            glw::GLenum internalformat, glw::GLsizei width,
1737                                                            glw::GLsizei height, glw::GLsizei depth)
1738 {
1739     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1740 
1741     if (I)
1742     {
1743         switch (D)
1744         {
1745         case 1:
1746             gl.texStorage1D(target, levels, internalformat, width);
1747             break;
1748         case 2:
1749             gl.texStorage2D(target, levels, internalformat, width, height);
1750             break;
1751         case 3:
1752             gl.texStorage3D(target, levels, internalformat, width, height, depth);
1753             break;
1754         default:
1755             DE_FATAL("invalid texture dimension");
1756         }
1757 
1758         /* TextureSubImage* (not TextureStorage*) is tested */
1759         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexStorage*() has failed");
1760         return true;
1761     }
1762     else
1763     {
1764         switch (D)
1765         {
1766         case 1:
1767             gl.textureStorage1D(texture, levels, internalformat, width);
1768             break;
1769         case 2:
1770             gl.textureStorage2D(texture, levels, internalformat, width, height);
1771             break;
1772         case 3:
1773             gl.textureStorage3D(texture, levels, internalformat, width, height, depth);
1774             break;
1775         default:
1776             DE_FATAL("invalid texture dimension");
1777         }
1778 
1779         glw::GLenum error;
1780         if (GL_NO_ERROR != (error = gl.getError()))
1781         {
1782             m_context.getTestContext().getLog()
1783                 << tcu::TestLog::Message << "glTextureStorage" << D << "D unexpectedly generated error "
1784                 << glu::getErrorStr(error) << " during test with levels " << levels << ", internal format "
1785                 << internalformat << " width=" << width << " height=" << height << " depth=" << depth << "."
1786                 << tcu::TestLog::EndMessage;
1787 
1788             CleanTexture();
1789             CleanErrors();
1790 
1791             return false;
1792         }
1793 
1794         return true;
1795     }
1796 }
1797 
1798 /** @brief TextureSubImage* wrapper.
1799  *
1800  *  @return true if suuceed (in legacy always or throw), false otherwise.
1801  */
1802 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
TextureSubImage(glw::GLenum target,glw::GLuint texture,glw::GLint level,glw::GLsizei width,glw::GLsizei height,glw::GLsizei depth,glw::GLenum format,glw::GLenum type,const glw::GLvoid * data)1803 bool StorageAndSubImageTest<T, S, N, D, I>::TextureSubImage(glw::GLenum target, glw::GLuint texture, glw::GLint level,
1804                                                             glw::GLsizei width, glw::GLsizei height, glw::GLsizei depth,
1805                                                             glw::GLenum format, glw::GLenum type,
1806                                                             const glw::GLvoid *data)
1807 {
1808     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1809 
1810     if (I)
1811     {
1812         switch (D)
1813         {
1814         case 1:
1815             gl.textureSubImage1D(texture, level, 0, width, format, type, data);
1816             break;
1817         case 2:
1818             gl.textureSubImage2D(texture, level, 0, 0, width, height, format, type, data);
1819             break;
1820         case 3:
1821             gl.textureSubImage3D(texture, level, 0, 0, 0, width, height, depth, format, type, data);
1822             break;
1823         default:
1824             DE_FATAL("invalid texture dimension");
1825         }
1826 
1827         glw::GLenum error;
1828         if (GL_NO_ERROR != (error = gl.getError()))
1829         {
1830             m_context.getTestContext().getLog()
1831                 << tcu::TestLog::Message << "glTextureSubImage" << D << "D unexpectedly generated error "
1832                 << glu::getErrorStr(error) << " during test with level " << level << ", width=" << width
1833                 << ", height=" << height << ", depth=" << depth << " format " << glu::getTextureFormatStr(format)
1834                 << " and type " << glu::getTypeStr(type) << "." << tcu::TestLog::EndMessage;
1835 
1836             CleanTexture();
1837             CleanErrors();
1838 
1839             return false;
1840         }
1841 
1842         return true;
1843     }
1844     else
1845     {
1846         switch (D)
1847         {
1848         case 1:
1849             gl.texSubImage1D(target, level, 0, width, format, type, data);
1850             break;
1851         case 2:
1852             gl.texSubImage2D(target, level, 0, 0, width, height, format, type, data);
1853             break;
1854         case 3:
1855             gl.texSubImage3D(target, level, 0, 0, 0, width, height, depth, format, type, data);
1856             break;
1857         default:
1858             DE_FATAL("invalid texture dimension");
1859         }
1860 
1861         /* TextureStorage* (not TextureSubImage) is tested */
1862         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexSubImage*() has failed");
1863         return true;
1864     }
1865 }
1866 
1867 /** @brief Create texture.
1868  *
1869  *  @tparam T      Type.
1870  *  @tparam S      Size (# of components).
1871  *  @tparam N      Is normalized.
1872  *  @tparam D      Dimmensions.
1873  *  @tparam I      Test SubImage or Storage.
1874  *
1875  *  @return True if succeded, false otherwise.
1876  */
1877 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
CreateTexture()1878 bool StorageAndSubImageTest<T, S, N, D, I>::CreateTexture()
1879 {
1880     /* Shortcut for GL functionality. */
1881     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1882 
1883     /* Objects creation. */
1884     gl.genTextures(1, &m_to);
1885     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
1886 
1887     gl.bindTexture(TextureTarget(), m_to);
1888     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
1889 
1890     /* Storage creation. */
1891     if (TextureStorage(TextureTarget(), m_to, 1, InternalFormat<T, S, N>(), TestReferenceDataWidth(),
1892                        TestReferenceDataHeight(), TestReferenceDataDepth()))
1893     {
1894         /* Data setup. */
1895         if (TextureSubImage(TextureTarget(), m_to, 0, TestReferenceDataWidth(), TestReferenceDataHeight(),
1896                             TestReferenceDataDepth(), Format<S, N>(), Type<T>(), ReferenceData<T, N>()))
1897         {
1898             glTexParameteri(TextureTarget(), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1899             glTexParameteri(TextureTarget(), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1900             return true;
1901         }
1902     }
1903 
1904     CleanTexture();
1905 
1906     return false;
1907 }
1908 
1909 /** @brief Compre results with the reference.
1910  *
1911  *  @return True if equal, false otherwise.
1912  */
1913 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
Check()1914 bool StorageAndSubImageTest<T, S, N, D, I>::Check()
1915 {
1916     /* Shortcut for GL functionality. */
1917     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1918 
1919     /* Fetching data. */
1920     std::vector<T> result(TestReferenceDataCount());
1921 
1922     glw::GLuint fbo_size_x = 0;
1923 
1924     switch (D)
1925     {
1926     case 1:
1927         fbo_size_x = 2;
1928         break;
1929     case 2:
1930         fbo_size_x = 2 * 3;
1931         break;
1932     case 3:
1933         fbo_size_x = 2 * 3 * 4;
1934         break;
1935     default:
1936         throw 0;
1937     }
1938 
1939     gl.readnPixels(0, 0, fbo_size_x, 1, Format<S, N>(), Type<T>(), TestReferenceDataSize(),
1940                    (glw::GLvoid *)(&result[0]));
1941     GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels has failed");
1942 
1943     /* Comparison. */
1944     for (glw::GLuint i = 0; i < TestReferenceDataCount(); ++i)
1945     {
1946         if (!Compare<T>(result[i], ReferenceData<T, N>()[i]))
1947         {
1948             return false;
1949         }
1950     }
1951 
1952     return true;
1953 }
1954 
1955 /** @brief Test case function.
1956  *
1957  *  @return True if test succeeded, false otherwise.
1958  */
1959 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
Test()1960 bool StorageAndSubImageTest<T, S, N, D, I>::Test()
1961 {
1962     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1963 
1964     gl.pixelStorei(GL_UNPACK_ALIGNMENT, sizeof(T));
1965     GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
1966 
1967     gl.pixelStorei(GL_PACK_ALIGNMENT, sizeof(T));
1968     GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
1969 
1970     /* Setup. */
1971     PrepareFramebuffer(InternalFormat<T, S, N>());
1972 
1973     if (!CreateTexture())
1974     {
1975         return false;
1976     }
1977 
1978     /* Action. */
1979     Draw();
1980 
1981     /* Compare results with reference. */
1982     bool result = Check();
1983 
1984     /* Cleanup. */
1985     CleanTexture();
1986     CleanFramebuffer();
1987     CleanErrors();
1988 
1989     /* Pass result. */
1990     return result;
1991 }
1992 
1993 /** @brief Function prepares framebuffer with internal format color attachment.
1994  *         Viewport is set up. Content of the framebuffer is cleared.
1995  *
1996  *  @note The function may throw if unexpected error has occured.
1997  */
1998 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
PrepareFramebuffer(const glw::GLenum internal_format)1999 void StorageAndSubImageTest<T, S, N, D, I>::PrepareFramebuffer(const glw::GLenum internal_format)
2000 {
2001     /* Shortcut for GL functionality. */
2002     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
2003 
2004     /* Prepare framebuffer. */
2005     gl.genFramebuffers(1, &m_fbo);
2006     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
2007 
2008     gl.genRenderbuffers(1, &m_rbo);
2009     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
2010 
2011     gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
2012     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
2013 
2014     gl.bindRenderbuffer(GL_RENDERBUFFER, m_rbo);
2015     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
2016 
2017     glw::GLuint fbo_size_x = 0;
2018 
2019     switch (D)
2020     {
2021     case 1:
2022         fbo_size_x = 2;
2023         break;
2024     case 2:
2025         fbo_size_x = 2 * 3;
2026         break;
2027     case 3:
2028         fbo_size_x = 2 * 3 * 4;
2029         break;
2030     default:
2031         throw 0;
2032     }
2033 
2034     gl.renderbufferStorage(GL_RENDERBUFFER, internal_format, fbo_size_x, 1);
2035     GLU_EXPECT_NO_ERROR(gl.getError(), "glRenderbufferStorage call failed.");
2036 
2037     gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_rbo);
2038     GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
2039 
2040     if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
2041     {
2042         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_UNSUPPORTED)
2043             throw tcu::NotSupportedError("unsupported framebuffer configuration");
2044         else
2045             throw 0;
2046     }
2047 
2048     gl.viewport(0, 0, fbo_size_x, 1);
2049     GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
2050 
2051     /* Clear framebuffer's content. */
2052     gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
2053     GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
2054 
2055     gl.clear(GL_COLOR_BUFFER_BIT);
2056     GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
2057 }
2058 
2059 /** @brief Prepare program
2060  *
2061  *  @param [in] variable_declaration      Variables declaration part of fragment shader source code.
2062  *  @param [in] tail                      Tail part of fragment shader source code.
2063  */
2064 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
PrepareProgram(const glw::GLchar * variable_declaration,const glw::GLchar * tail)2065 void StorageAndSubImageTest<T, S, N, D, I>::PrepareProgram(const glw::GLchar *variable_declaration,
2066                                                            const glw::GLchar *tail)
2067 {
2068     /* Shortcut for GL functionality */
2069     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
2070 
2071     struct Shader
2072     {
2073         glw::GLchar const *source[3];
2074         glw::GLsizei const count;
2075         glw::GLenum const type;
2076         glw::GLuint id;
2077     } shader[] = {{{s_vertex_shader, NULL, NULL}, 1, GL_VERTEX_SHADER, 0},
2078                   {{s_fragment_shader_head, variable_declaration, tail}, 3, GL_FRAGMENT_SHADER, 0}};
2079 
2080     glw::GLuint const shader_count = sizeof(shader) / sizeof(shader[0]);
2081 
2082     try
2083     {
2084         /* Create program. */
2085         m_po = gl.createProgram();
2086         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateProgram call failed.");
2087 
2088         /* Shader compilation. */
2089 
2090         for (glw::GLuint i = 0; i < shader_count; ++i)
2091         {
2092             {
2093                 shader[i].id = gl.createShader(shader[i].type);
2094 
2095                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateShader call failed.");
2096 
2097                 gl.attachShader(m_po, shader[i].id);
2098 
2099                 GLU_EXPECT_NO_ERROR(gl.getError(), "glAttachShader call failed.");
2100 
2101                 gl.shaderSource(shader[i].id, shader[i].count, shader[i].source, NULL);
2102 
2103                 GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource call failed.");
2104 
2105                 gl.compileShader(shader[i].id);
2106 
2107                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader call failed.");
2108 
2109                 glw::GLint status = GL_FALSE;
2110 
2111                 gl.getShaderiv(shader[i].id, GL_COMPILE_STATUS, &status);
2112                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
2113 
2114                 if (GL_FALSE == status)
2115                 {
2116                     glw::GLint log_size = 0;
2117                     gl.getShaderiv(shader[i].id, GL_INFO_LOG_LENGTH, &log_size);
2118                     GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
2119 
2120                     glw::GLchar *log_text = new glw::GLchar[log_size];
2121 
2122                     gl.getShaderInfoLog(shader[i].id, log_size, NULL, &log_text[0]);
2123 
2124                     m_context.getTestContext().getLog()
2125                         << tcu::TestLog::Message << "Shader compilation has failed.\n"
2126                         << "Shader type: " << glu::getShaderTypeStr(shader[i].type) << "\n"
2127                         << "Shader compilation error log:\n"
2128                         << log_text << "\n"
2129                         << "Shader source code:\n"
2130                         << shader[i].source[0] << (shader[i].source[1] ? shader[i].source[1] : "")
2131                         << (shader[i].source[2] ? shader[i].source[2] : "") << "\n"
2132                         << tcu::TestLog::EndMessage;
2133 
2134                     delete[] log_text;
2135 
2136                     GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog call failed.");
2137 
2138                     throw 0;
2139                 }
2140             }
2141         }
2142 
2143         /* Link. */
2144         gl.linkProgram(m_po);
2145 
2146         GLU_EXPECT_NO_ERROR(gl.getError(), "glTransformFeedbackVaryings call failed.");
2147 
2148         glw::GLint status = GL_FALSE;
2149 
2150         gl.getProgramiv(m_po, GL_LINK_STATUS, &status);
2151 
2152         if (GL_TRUE == status)
2153         {
2154             for (glw::GLuint i = 0; i < shader_count; ++i)
2155             {
2156                 if (shader[i].id)
2157                 {
2158                     gl.detachShader(m_po, shader[i].id);
2159 
2160                     GLU_EXPECT_NO_ERROR(gl.getError(), "glDetachShader call failed.");
2161                 }
2162             }
2163         }
2164         else
2165         {
2166             glw::GLint log_size = 0;
2167 
2168             gl.getProgramiv(m_po, GL_INFO_LOG_LENGTH, &log_size);
2169 
2170             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv call failed.");
2171 
2172             glw::GLchar *log_text = new glw::GLchar[log_size];
2173 
2174             gl.getProgramInfoLog(m_po, log_size, NULL, &log_text[0]);
2175 
2176             m_context.getTestContext().getLog() << tcu::TestLog::Message << "Program linkage has failed due to:\n"
2177                                                 << log_text << "\n"
2178                                                 << tcu::TestLog::EndMessage;
2179 
2180             delete[] log_text;
2181 
2182             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramInfoLog call failed.");
2183 
2184             throw 0;
2185         }
2186     }
2187     catch (...)
2188     {
2189         if (m_po)
2190         {
2191             gl.deleteProgram(m_po);
2192 
2193             m_po = 0;
2194         }
2195     }
2196 
2197     for (glw::GLuint i = 0; i < shader_count; ++i)
2198     {
2199         if (0 != shader[i].id)
2200         {
2201             gl.deleteShader(shader[i].id);
2202 
2203             shader[i].id = 0;
2204         }
2205     }
2206 
2207     if (0 == m_po)
2208     {
2209         throw 0;
2210     }
2211 }
2212 
2213 /** @brief Prepare VAO.
2214  */
2215 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
PrepareVertexArray()2216 void StorageAndSubImageTest<T, S, N, D, I>::PrepareVertexArray()
2217 {
2218     /* Shortcut for GL functionality. */
2219     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
2220 
2221     gl.genVertexArrays(1, &m_vao);
2222     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays has failed");
2223 
2224     gl.bindVertexArray(m_vao);
2225     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray has failed");
2226 }
2227 
2228 /** @brief Test's draw call.
2229  */
2230 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
Draw()2231 void StorageAndSubImageTest<T, S, N, D, I>::Draw()
2232 {
2233     /* Shortcut for GL functionality. */
2234     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
2235 
2236     gl.useProgram(m_po);
2237     GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed");
2238 
2239     gl.activeTexture(GL_TEXTURE0);
2240     GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
2241 
2242     gl.bindTextureUnit(0, m_to);
2243     GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
2244 
2245     gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
2246     GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed");
2247 }
2248 
2249 /** @brief Clean GL objects, test variables and GL errors.
2250  */
2251 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
CleanTexture()2252 void StorageAndSubImageTest<T, S, N, D, I>::CleanTexture()
2253 {
2254     /* Shortcut for GL functionality. */
2255     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
2256 
2257     /* Texture. */
2258     if (m_to)
2259     {
2260         gl.deleteTextures(1, &m_to);
2261 
2262         m_to = 0;
2263     }
2264 }
2265 
2266 /** @brief Clean GL objects, test variables and GL errors.
2267  */
2268 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
CleanFramebuffer()2269 void StorageAndSubImageTest<T, S, N, D, I>::CleanFramebuffer()
2270 {
2271     /* Shortcut for GL functionality. */
2272     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
2273 
2274     /* Framebuffer. */
2275     if (m_fbo)
2276     {
2277         gl.deleteFramebuffers(1, &m_fbo);
2278 
2279         m_fbo = 0;
2280     }
2281 
2282     /* Renderbuffer. */
2283     if (m_rbo)
2284     {
2285         gl.deleteRenderbuffers(1, &m_rbo);
2286 
2287         m_rbo = 0;
2288     }
2289 }
2290 
2291 /** @brief Clean GL objects, test variables and GL errors.
2292  */
2293 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
CleanProgram()2294 void StorageAndSubImageTest<T, S, N, D, I>::CleanProgram()
2295 {
2296     /* Shortcut for GL functionality. */
2297     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
2298 
2299     /* Program. */
2300     if (m_po)
2301     {
2302         gl.useProgram(0);
2303 
2304         gl.deleteProgram(m_po);
2305 
2306         m_po = 0;
2307     }
2308 }
2309 
2310 /** @brief Clean GL objects, test variables and GL errors.
2311  */
2312 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
CleanErrors()2313 void StorageAndSubImageTest<T, S, N, D, I>::CleanErrors()
2314 {
2315     /* Shortcut for GL functionality. */
2316     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
2317 
2318     /* Query all errors until GL_NO_ERROR occure. */
2319     while (GL_NO_ERROR != gl.getError())
2320         ;
2321 }
2322 
2323 /** @brief Clean GL objects, test variables and GL errors.
2324  */
2325 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
CleanVertexArray()2326 void StorageAndSubImageTest<T, S, N, D, I>::CleanVertexArray()
2327 {
2328     /* Shortcut for GL functionality. */
2329     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
2330 
2331     if (m_vao)
2332     {
2333         gl.bindVertexArray(0);
2334 
2335         gl.deleteVertexArrays(1, &m_vao);
2336 
2337         m_vao = 0;
2338     }
2339 }
2340 
2341 /** @brief Iterate Storage Test cases.
2342  *
2343  *  @return Iteration result.
2344  */
2345 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
iterate()2346 tcu::TestNode::IterateResult StorageAndSubImageTest<T, S, N, D, I>::iterate()
2347 {
2348     /* Shortcut for GL functionality. */
2349     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
2350 
2351     /* Get context setup. */
2352     bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
2353     bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
2354 
2355     if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
2356     {
2357         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
2358 
2359         return STOP;
2360     }
2361 
2362     /* Running tests. */
2363     bool is_ok    = true;
2364     bool is_error = false;
2365 
2366     try
2367     {
2368         PrepareVertexArray();
2369         PrepareProgram(FragmentShaderDeclaration(), FragmentShaderTail());
2370         is_ok = Test();
2371     }
2372     catch (tcu::NotSupportedError &e)
2373     {
2374         throw e;
2375     }
2376     catch (...)
2377     {
2378         is_ok    = false;
2379         is_error = true;
2380     }
2381 
2382     /* Cleanup. */
2383     CleanTexture();
2384     CleanFramebuffer();
2385     CleanProgram();
2386     CleanErrors();
2387     CleanVertexArray();
2388 
2389     /* Errors clean up. */
2390     while (gl.getError())
2391         ;
2392 
2393     /* Result's setup. */
2394     if (is_ok)
2395     {
2396         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
2397     }
2398     else
2399     {
2400         if (is_error)
2401         {
2402             m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
2403         }
2404         else
2405         {
2406             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
2407         }
2408     }
2409 
2410     return STOP;
2411 }
2412 
2413 /* Vertex shader source code. */
2414 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2415 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_vertex_shader =
2416     "#version 450\n"
2417     "\n"
2418     "void main()\n"
2419     "{\n"
2420     "    switch(gl_VertexID)\n"
2421     "    {\n"
2422     "        case 0:\n"
2423     "            gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
2424     "            break;\n"
2425     "        case 1:\n"
2426     "            gl_Position = vec4( 1.0, 1.0, 0.0, 1.0);\n"
2427     "            break;\n"
2428     "        case 2:\n"
2429     "            gl_Position = vec4(-1.0,-1.0, 0.0, 1.0);\n"
2430     "            break;\n"
2431     "        case 3:\n"
2432     "            gl_Position = vec4( 1.0,-1.0, 0.0, 1.0);\n"
2433     "            break;\n"
2434     "    }\n"
2435     "}\n";
2436 
2437 /* Fragment shader source program. */
2438 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2439 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_head =
2440     "#version 450\n"
2441     "\n"
2442     "layout(pixel_center_integer) in vec4 gl_FragCoord;\n"
2443     "\n";
2444 
2445 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2446 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_fdecl_lowp =
2447     "uniform  sampler1D texture_input;\nout     vec4          texture_output;\n";
2448 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2449 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_idecl_lowp =
2450     "uniform isampler1D texture_input;\nout     ivec4         texture_output;\n";
2451 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2452 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_udecl_lowp =
2453     "uniform usampler1D texture_input;\nout     uvec4         texture_output;\n";
2454 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2455 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_fdecl_mediump =
2456     "uniform  sampler1D texture_input;\nout     vec4          texture_output;\n";
2457 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2458 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_idecl_mediump =
2459     "uniform isampler1D texture_input;\nout     ivec4         texture_output;\n";
2460 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2461 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_udecl_mediump =
2462     "uniform usampler1D texture_input;\nout     uvec4         texture_output;\n";
2463 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2464 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_fdecl_highp =
2465     "uniform  sampler1D texture_input;\nout     vec4          texture_output;\n";
2466 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2467 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_idecl_highp =
2468     "uniform isampler1D texture_input;\nout     ivec4         texture_output;\n";
2469 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2470 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_udecl_highp =
2471     "uniform usampler1D texture_input;\nout     uvec4         texture_output;\n";
2472 
2473 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2474 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_fdecl_lowp =
2475     "uniform  sampler2D texture_input;\nout     vec4          texture_output;\n";
2476 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2477 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_idecl_lowp =
2478     "uniform isampler2D texture_input;\nout     ivec4         texture_output;\n";
2479 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2480 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_udecl_lowp =
2481     "uniform usampler2D texture_input;\nout     uvec4         texture_output;\n";
2482 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2483 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_fdecl_mediump =
2484     "uniform  sampler2D texture_input;\nout     vec4          texture_output;\n";
2485 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2486 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_idecl_mediump =
2487     "uniform isampler2D texture_input;\nout     ivec4         texture_output;\n";
2488 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2489 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_udecl_mediump =
2490     "uniform usampler2D texture_input;\nout     uvec4         texture_output;\n";
2491 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2492 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_fdecl_highp =
2493     "uniform  sampler2D texture_input;\nout     vec4          texture_output;\n";
2494 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2495 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_idecl_highp =
2496     "uniform isampler2D texture_input;\nout     ivec4         texture_output;\n";
2497 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2498 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_udecl_highp =
2499     "uniform usampler2D texture_input;\nout     uvec4         texture_output;\n";
2500 
2501 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2502 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_fdecl_lowp =
2503     "uniform  sampler3D texture_input;\nout     vec4          texture_output;\n";
2504 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2505 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_idecl_lowp =
2506     "uniform isampler3D texture_input;\nout     ivec4         texture_output;\n";
2507 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2508 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_udecl_lowp =
2509     "uniform usampler3D texture_input;\nout     uvec4         texture_output;\n";
2510 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2511 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_fdecl_mediump =
2512     "uniform  sampler3D texture_input;\nout     vec4          texture_output;\n";
2513 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2514 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_idecl_mediump =
2515     "uniform isampler3D texture_input;\nout     ivec4         texture_output;\n";
2516 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2517 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_udecl_mediump =
2518     "uniform usampler3D texture_input;\nout     uvec4         texture_output;\n";
2519 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2520 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_fdecl_highp =
2521     "uniform  sampler3D texture_input;\nout     vec4          texture_output;\n";
2522 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2523 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_idecl_highp =
2524     "uniform isampler3D texture_input;\nout     ivec4         texture_output;\n";
2525 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2526 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_udecl_highp =
2527     "uniform usampler3D texture_input;\nout     uvec4         texture_output;\n";
2528 
2529 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2530 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_tail =
2531     "\n"
2532     "void main()\n"
2533     "{\n"
2534     "    texture_output = texelFetch(texture_input, int(gl_FragCoord.x), 0);\n"
2535     "}\n";
2536 
2537 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2538 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_tail =
2539     "\n"
2540     "void main()\n"
2541     "{\n"
2542     "    texture_output = texelFetch(texture_input, ivec2(int(gl_FragCoord.x) % 2, int(floor(gl_FragCoord.x / 2))), "
2543     "0);\n"
2544     "}\n";
2545 
2546 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I>
2547 const glw::GLchar *StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_tail =
2548     "\n"
2549     "void main()\n"
2550     "{\n"
2551     "    texture_output = texelFetch(texture_input, ivec3(int(gl_FragCoord.x) % 2, int(floor(gl_FragCoord.x / 2)) % 3, "
2552     "int(floor(gl_FragCoord.x / 2 / 3))), 0);\n"
2553     "}\n";
2554 
2555 template class StorageAndSubImageTest<glw::GLbyte, 1, false, 1, false>;
2556 template class StorageAndSubImageTest<glw::GLbyte, 2, false, 1, false>;
2557 template class StorageAndSubImageTest<glw::GLbyte, 4, false, 1, false>;
2558 template class StorageAndSubImageTest<glw::GLbyte, 1, false, 2, false>;
2559 template class StorageAndSubImageTest<glw::GLbyte, 2, false, 2, false>;
2560 template class StorageAndSubImageTest<glw::GLbyte, 4, false, 2, false>;
2561 template class StorageAndSubImageTest<glw::GLbyte, 1, false, 3, false>;
2562 template class StorageAndSubImageTest<glw::GLbyte, 2, false, 3, false>;
2563 template class StorageAndSubImageTest<glw::GLbyte, 4, false, 3, false>;
2564 
2565 template class StorageAndSubImageTest<glw::GLubyte, 1, false, 1, false>;
2566 template class StorageAndSubImageTest<glw::GLubyte, 2, false, 1, false>;
2567 template class StorageAndSubImageTest<glw::GLubyte, 4, false, 1, false>;
2568 template class StorageAndSubImageTest<glw::GLubyte, 1, false, 2, false>;
2569 template class StorageAndSubImageTest<glw::GLubyte, 2, false, 2, false>;
2570 template class StorageAndSubImageTest<glw::GLubyte, 4, false, 2, false>;
2571 template class StorageAndSubImageTest<glw::GLubyte, 1, false, 3, false>;
2572 template class StorageAndSubImageTest<glw::GLubyte, 2, false, 3, false>;
2573 template class StorageAndSubImageTest<glw::GLubyte, 4, false, 3, false>;
2574 
2575 template class StorageAndSubImageTest<glw::GLubyte, 1, true, 1, false>;
2576 template class StorageAndSubImageTest<glw::GLubyte, 2, true, 1, false>;
2577 template class StorageAndSubImageTest<glw::GLubyte, 4, true, 1, false>;
2578 template class StorageAndSubImageTest<glw::GLubyte, 1, true, 2, false>;
2579 template class StorageAndSubImageTest<glw::GLubyte, 2, true, 2, false>;
2580 template class StorageAndSubImageTest<glw::GLubyte, 4, true, 2, false>;
2581 template class StorageAndSubImageTest<glw::GLubyte, 1, true, 3, false>;
2582 template class StorageAndSubImageTest<glw::GLubyte, 2, true, 3, false>;
2583 template class StorageAndSubImageTest<glw::GLubyte, 4, true, 3, false>;
2584 
2585 template class StorageAndSubImageTest<glw::GLshort, 1, false, 1, false>;
2586 template class StorageAndSubImageTest<glw::GLshort, 2, false, 1, false>;
2587 template class StorageAndSubImageTest<glw::GLshort, 4, false, 1, false>;
2588 template class StorageAndSubImageTest<glw::GLshort, 1, false, 2, false>;
2589 template class StorageAndSubImageTest<glw::GLshort, 2, false, 2, false>;
2590 template class StorageAndSubImageTest<glw::GLshort, 4, false, 2, false>;
2591 template class StorageAndSubImageTest<glw::GLshort, 1, false, 3, false>;
2592 template class StorageAndSubImageTest<glw::GLshort, 2, false, 3, false>;
2593 template class StorageAndSubImageTest<glw::GLshort, 4, false, 3, false>;
2594 
2595 template class StorageAndSubImageTest<glw::GLushort, 1, false, 1, false>;
2596 template class StorageAndSubImageTest<glw::GLushort, 2, false, 1, false>;
2597 template class StorageAndSubImageTest<glw::GLushort, 4, false, 1, false>;
2598 template class StorageAndSubImageTest<glw::GLushort, 1, false, 2, false>;
2599 template class StorageAndSubImageTest<glw::GLushort, 2, false, 2, false>;
2600 template class StorageAndSubImageTest<glw::GLushort, 4, false, 2, false>;
2601 template class StorageAndSubImageTest<glw::GLushort, 1, false, 3, false>;
2602 template class StorageAndSubImageTest<glw::GLushort, 2, false, 3, false>;
2603 template class StorageAndSubImageTest<glw::GLushort, 4, false, 3, false>;
2604 
2605 template class StorageAndSubImageTest<glw::GLushort, 1, true, 1, false>;
2606 template class StorageAndSubImageTest<glw::GLushort, 2, true, 1, false>;
2607 template class StorageAndSubImageTest<glw::GLushort, 4, true, 1, false>;
2608 template class StorageAndSubImageTest<glw::GLushort, 1, true, 2, false>;
2609 template class StorageAndSubImageTest<glw::GLushort, 2, true, 2, false>;
2610 template class StorageAndSubImageTest<glw::GLushort, 4, true, 2, false>;
2611 template class StorageAndSubImageTest<glw::GLushort, 1, true, 3, false>;
2612 template class StorageAndSubImageTest<glw::GLushort, 2, true, 3, false>;
2613 template class StorageAndSubImageTest<glw::GLushort, 4, true, 3, false>;
2614 
2615 template class StorageAndSubImageTest<glw::GLint, 1, false, 1, false>;
2616 template class StorageAndSubImageTest<glw::GLint, 2, false, 1, false>;
2617 template class StorageAndSubImageTest<glw::GLint, 3, false, 1, false>;
2618 template class StorageAndSubImageTest<glw::GLint, 4, false, 1, false>;
2619 template class StorageAndSubImageTest<glw::GLint, 1, false, 2, false>;
2620 template class StorageAndSubImageTest<glw::GLint, 2, false, 2, false>;
2621 template class StorageAndSubImageTest<glw::GLint, 3, false, 2, false>;
2622 template class StorageAndSubImageTest<glw::GLint, 4, false, 2, false>;
2623 template class StorageAndSubImageTest<glw::GLint, 1, false, 3, false>;
2624 template class StorageAndSubImageTest<glw::GLint, 2, false, 3, false>;
2625 template class StorageAndSubImageTest<glw::GLint, 3, false, 3, false>;
2626 template class StorageAndSubImageTest<glw::GLint, 4, false, 3, false>;
2627 
2628 template class StorageAndSubImageTest<glw::GLuint, 1, false, 1, false>;
2629 template class StorageAndSubImageTest<glw::GLuint, 2, false, 1, false>;
2630 template class StorageAndSubImageTest<glw::GLuint, 3, false, 1, false>;
2631 template class StorageAndSubImageTest<glw::GLuint, 4, false, 1, false>;
2632 template class StorageAndSubImageTest<glw::GLuint, 1, false, 2, false>;
2633 template class StorageAndSubImageTest<glw::GLuint, 2, false, 2, false>;
2634 template class StorageAndSubImageTest<glw::GLuint, 3, false, 2, false>;
2635 template class StorageAndSubImageTest<glw::GLuint, 4, false, 2, false>;
2636 template class StorageAndSubImageTest<glw::GLuint, 1, false, 3, false>;
2637 template class StorageAndSubImageTest<glw::GLuint, 2, false, 3, false>;
2638 template class StorageAndSubImageTest<glw::GLuint, 3, false, 3, false>;
2639 template class StorageAndSubImageTest<glw::GLuint, 4, false, 3, false>;
2640 
2641 template class StorageAndSubImageTest<glw::GLfloat, 1, true, 1, false>;
2642 template class StorageAndSubImageTest<glw::GLfloat, 2, true, 1, false>;
2643 template class StorageAndSubImageTest<glw::GLfloat, 3, true, 1, false>;
2644 template class StorageAndSubImageTest<glw::GLfloat, 4, true, 1, false>;
2645 template class StorageAndSubImageTest<glw::GLfloat, 1, true, 2, false>;
2646 template class StorageAndSubImageTest<glw::GLfloat, 2, true, 2, false>;
2647 template class StorageAndSubImageTest<glw::GLfloat, 3, true, 2, false>;
2648 template class StorageAndSubImageTest<glw::GLfloat, 4, true, 2, false>;
2649 template class StorageAndSubImageTest<glw::GLfloat, 1, true, 3, false>;
2650 template class StorageAndSubImageTest<glw::GLfloat, 2, true, 3, false>;
2651 template class StorageAndSubImageTest<glw::GLfloat, 3, true, 3, false>;
2652 template class StorageAndSubImageTest<glw::GLfloat, 4, true, 3, false>;
2653 
2654 template class StorageAndSubImageTest<glw::GLbyte, 1, false, 1, true>;
2655 template class StorageAndSubImageTest<glw::GLbyte, 2, false, 1, true>;
2656 template class StorageAndSubImageTest<glw::GLbyte, 4, false, 1, true>;
2657 template class StorageAndSubImageTest<glw::GLbyte, 1, false, 2, true>;
2658 template class StorageAndSubImageTest<glw::GLbyte, 2, false, 2, true>;
2659 template class StorageAndSubImageTest<glw::GLbyte, 4, false, 2, true>;
2660 template class StorageAndSubImageTest<glw::GLbyte, 1, false, 3, true>;
2661 template class StorageAndSubImageTest<glw::GLbyte, 2, false, 3, true>;
2662 template class StorageAndSubImageTest<glw::GLbyte, 4, false, 3, true>;
2663 
2664 template class StorageAndSubImageTest<glw::GLubyte, 1, false, 1, true>;
2665 template class StorageAndSubImageTest<glw::GLubyte, 2, false, 1, true>;
2666 template class StorageAndSubImageTest<glw::GLubyte, 4, false, 1, true>;
2667 template class StorageAndSubImageTest<glw::GLubyte, 1, false, 2, true>;
2668 template class StorageAndSubImageTest<glw::GLubyte, 2, false, 2, true>;
2669 template class StorageAndSubImageTest<glw::GLubyte, 4, false, 2, true>;
2670 template class StorageAndSubImageTest<glw::GLubyte, 1, false, 3, true>;
2671 template class StorageAndSubImageTest<glw::GLubyte, 2, false, 3, true>;
2672 template class StorageAndSubImageTest<glw::GLubyte, 4, false, 3, true>;
2673 
2674 template class StorageAndSubImageTest<glw::GLubyte, 1, true, 1, true>;
2675 template class StorageAndSubImageTest<glw::GLubyte, 2, true, 1, true>;
2676 template class StorageAndSubImageTest<glw::GLubyte, 4, true, 1, true>;
2677 template class StorageAndSubImageTest<glw::GLubyte, 1, true, 2, true>;
2678 template class StorageAndSubImageTest<glw::GLubyte, 2, true, 2, true>;
2679 template class StorageAndSubImageTest<glw::GLubyte, 4, true, 2, true>;
2680 template class StorageAndSubImageTest<glw::GLubyte, 1, true, 3, true>;
2681 template class StorageAndSubImageTest<glw::GLubyte, 2, true, 3, true>;
2682 template class StorageAndSubImageTest<glw::GLubyte, 4, true, 3, true>;
2683 
2684 template class StorageAndSubImageTest<glw::GLshort, 1, false, 1, true>;
2685 template class StorageAndSubImageTest<glw::GLshort, 2, false, 1, true>;
2686 template class StorageAndSubImageTest<glw::GLshort, 4, false, 1, true>;
2687 template class StorageAndSubImageTest<glw::GLshort, 1, false, 2, true>;
2688 template class StorageAndSubImageTest<glw::GLshort, 2, false, 2, true>;
2689 template class StorageAndSubImageTest<glw::GLshort, 4, false, 2, true>;
2690 template class StorageAndSubImageTest<glw::GLshort, 1, false, 3, true>;
2691 template class StorageAndSubImageTest<glw::GLshort, 2, false, 3, true>;
2692 template class StorageAndSubImageTest<glw::GLshort, 4, false, 3, true>;
2693 
2694 template class StorageAndSubImageTest<glw::GLushort, 1, false, 1, true>;
2695 template class StorageAndSubImageTest<glw::GLushort, 2, false, 1, true>;
2696 template class StorageAndSubImageTest<glw::GLushort, 4, false, 1, true>;
2697 template class StorageAndSubImageTest<glw::GLushort, 1, false, 2, true>;
2698 template class StorageAndSubImageTest<glw::GLushort, 2, false, 2, true>;
2699 template class StorageAndSubImageTest<glw::GLushort, 4, false, 2, true>;
2700 template class StorageAndSubImageTest<glw::GLushort, 1, false, 3, true>;
2701 template class StorageAndSubImageTest<glw::GLushort, 2, false, 3, true>;
2702 template class StorageAndSubImageTest<glw::GLushort, 4, false, 3, true>;
2703 
2704 template class StorageAndSubImageTest<glw::GLushort, 1, true, 1, true>;
2705 template class StorageAndSubImageTest<glw::GLushort, 2, true, 1, true>;
2706 template class StorageAndSubImageTest<glw::GLushort, 4, true, 1, true>;
2707 template class StorageAndSubImageTest<glw::GLushort, 1, true, 2, true>;
2708 template class StorageAndSubImageTest<glw::GLushort, 2, true, 2, true>;
2709 template class StorageAndSubImageTest<glw::GLushort, 4, true, 2, true>;
2710 template class StorageAndSubImageTest<glw::GLushort, 1, true, 3, true>;
2711 template class StorageAndSubImageTest<glw::GLushort, 2, true, 3, true>;
2712 template class StorageAndSubImageTest<glw::GLushort, 4, true, 3, true>;
2713 
2714 template class StorageAndSubImageTest<glw::GLint, 1, false, 1, true>;
2715 template class StorageAndSubImageTest<glw::GLint, 2, false, 1, true>;
2716 template class StorageAndSubImageTest<glw::GLint, 3, false, 1, true>;
2717 template class StorageAndSubImageTest<glw::GLint, 4, false, 1, true>;
2718 template class StorageAndSubImageTest<glw::GLint, 1, false, 2, true>;
2719 template class StorageAndSubImageTest<glw::GLint, 2, false, 2, true>;
2720 template class StorageAndSubImageTest<glw::GLint, 3, false, 2, true>;
2721 template class StorageAndSubImageTest<glw::GLint, 4, false, 2, true>;
2722 template class StorageAndSubImageTest<glw::GLint, 1, false, 3, true>;
2723 template class StorageAndSubImageTest<glw::GLint, 2, false, 3, true>;
2724 template class StorageAndSubImageTest<glw::GLint, 3, false, 3, true>;
2725 template class StorageAndSubImageTest<glw::GLint, 4, false, 3, true>;
2726 
2727 template class StorageAndSubImageTest<glw::GLuint, 1, false, 1, true>;
2728 template class StorageAndSubImageTest<glw::GLuint, 2, false, 1, true>;
2729 template class StorageAndSubImageTest<glw::GLuint, 3, false, 1, true>;
2730 template class StorageAndSubImageTest<glw::GLuint, 4, false, 1, true>;
2731 template class StorageAndSubImageTest<glw::GLuint, 1, false, 2, true>;
2732 template class StorageAndSubImageTest<glw::GLuint, 2, false, 2, true>;
2733 template class StorageAndSubImageTest<glw::GLuint, 3, false, 2, true>;
2734 template class StorageAndSubImageTest<glw::GLuint, 4, false, 2, true>;
2735 template class StorageAndSubImageTest<glw::GLuint, 1, false, 3, true>;
2736 template class StorageAndSubImageTest<glw::GLuint, 2, false, 3, true>;
2737 template class StorageAndSubImageTest<glw::GLuint, 3, false, 3, true>;
2738 template class StorageAndSubImageTest<glw::GLuint, 4, false, 3, true>;
2739 
2740 template class StorageAndSubImageTest<glw::GLfloat, 1, true, 1, true>;
2741 template class StorageAndSubImageTest<glw::GLfloat, 2, true, 1, true>;
2742 template class StorageAndSubImageTest<glw::GLfloat, 3, true, 1, true>;
2743 template class StorageAndSubImageTest<glw::GLfloat, 4, true, 1, true>;
2744 template class StorageAndSubImageTest<glw::GLfloat, 1, true, 2, true>;
2745 template class StorageAndSubImageTest<glw::GLfloat, 2, true, 2, true>;
2746 template class StorageAndSubImageTest<glw::GLfloat, 3, true, 2, true>;
2747 template class StorageAndSubImageTest<glw::GLfloat, 4, true, 2, true>;
2748 template class StorageAndSubImageTest<glw::GLfloat, 1, true, 3, true>;
2749 template class StorageAndSubImageTest<glw::GLfloat, 2, true, 3, true>;
2750 template class StorageAndSubImageTest<glw::GLfloat, 3, true, 3, true>;
2751 template class StorageAndSubImageTest<glw::GLfloat, 4, true, 3, true>;
2752 
2753 /******************************** Storage Multisample Test Implementation   ********************************/
2754 
2755 /** @brief Storage Multisample Test constructor.
2756  *
2757  *  @param [in] context     OpenGL context.
2758  */
2759 template <typename T, glw::GLint S, bool N, glw::GLuint D>
StorageMultisampleTest(deqp::Context & context,const char * name)2760 StorageMultisampleTest<T, S, N, D>::StorageMultisampleTest(deqp::Context &context, const char *name)
2761     : deqp::TestCase(context, name, "Texture Storage Multisample Test")
2762     , m_fbo_ms(0)
2763     , m_fbo_aux(0)
2764     , m_to_ms(0)
2765     , m_po_ms(0)
2766     , m_po_aux(0)
2767     , m_to(0)
2768     , m_to_aux(0)
2769     , m_vao(0)
2770 {
2771     /* Intentionally left blank. */
2772 }
2773 
2774 /** @brief Count of reference data to be teted.
2775  *
2776  *  @return Count.
2777  */
2778 template <typename T, glw::GLint S, bool N, glw::GLuint D>
TestReferenceDataCount()2779 glw::GLuint StorageMultisampleTest<T, S, N, D>::TestReferenceDataCount()
2780 {
2781     return 2 /* 1D */ * ((D > 1) ? 3 : 1) /* 2D */ * ((D > 2) ? 4 : 1) /* 3D */ * S /* components */;
2782 }
2783 
2784 /** @brief Size of reference data to be teted.
2785  *
2786  *  @return Size.
2787  */
2788 template <typename T, glw::GLint S, bool N, glw::GLuint D>
TestReferenceDataSize()2789 glw::GLuint StorageMultisampleTest<T, S, N, D>::TestReferenceDataSize()
2790 {
2791     return TestReferenceDataCount() * sizeof(T);
2792 }
2793 
2794 /** @brief Height, width or depth of reference data to be teted.
2795  *
2796  *  @return Height, width or depth.
2797  */
2798 template <typename T, glw::GLint S, bool N, glw::GLuint D>
TestReferenceDataHeight()2799 glw::GLuint StorageMultisampleTest<T, S, N, D>::TestReferenceDataHeight()
2800 {
2801     switch (D)
2802     {
2803     case 3:
2804     case 2:
2805         return 3;
2806     default:
2807         return 1;
2808     }
2809 }
2810 
2811 template <typename T, glw::GLint S, bool N, glw::GLuint D>
TestReferenceDataDepth()2812 glw::GLuint StorageMultisampleTest<T, S, N, D>::TestReferenceDataDepth()
2813 {
2814     switch (D)
2815     {
2816     case 3:
2817         return 4;
2818     default:
2819         return 1;
2820     }
2821 }
2822 
2823 template <typename T, glw::GLint S, bool N, glw::GLuint D>
TestReferenceDataWidth()2824 glw::GLuint StorageMultisampleTest<T, S, N, D>::TestReferenceDataWidth()
2825 {
2826     return 2;
2827 }
2828 
2829 /** @brief Fragment shader declaration selector.
2830  *
2831  *  @return Frgment shader source code part.
2832  */
2833 template <typename T, glw::GLint S, bool N, glw::GLuint D>
FragmentShaderDeclarationMultisample()2834 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::FragmentShaderDeclarationMultisample()
2835 {
2836     if (typeid(T) == typeid(glw::GLbyte))
2837     {
2838         switch (D)
2839         {
2840         case 2:
2841             return s_fragment_shader_ms_2D_idecl_lowp;
2842         case 3:
2843             return s_fragment_shader_ms_3D_idecl_lowp;
2844         default:
2845             DE_FATAL("invalid texture dimension");
2846             return DE_NULL;
2847         }
2848     }
2849 
2850     if (typeid(T) == typeid(glw::GLubyte))
2851     {
2852         if (N)
2853         {
2854             switch (D)
2855             {
2856             case 2:
2857                 return s_fragment_shader_ms_2D_fdecl_lowp;
2858             case 3:
2859                 return s_fragment_shader_ms_3D_fdecl_lowp;
2860             default:
2861                 DE_FATAL("invalid texture dimension");
2862                 return DE_NULL;
2863             }
2864         }
2865         else
2866         {
2867             switch (D)
2868             {
2869             case 2:
2870                 return s_fragment_shader_ms_2D_udecl_lowp;
2871             case 3:
2872                 return s_fragment_shader_ms_3D_udecl_lowp;
2873             default:
2874                 DE_FATAL("invalid texture dimension");
2875                 return DE_NULL;
2876             }
2877         }
2878     }
2879 
2880     if (typeid(T) == typeid(glw::GLshort))
2881     {
2882         switch (D)
2883         {
2884         case 2:
2885             return s_fragment_shader_ms_2D_idecl_mediump;
2886         case 3:
2887             return s_fragment_shader_ms_3D_idecl_mediump;
2888         default:
2889             DE_FATAL("invalid texture dimension");
2890             return DE_NULL;
2891         }
2892     }
2893 
2894     if (typeid(T) == typeid(glw::GLushort))
2895     {
2896         if (N)
2897         {
2898             switch (D)
2899             {
2900             case 2:
2901                 return s_fragment_shader_ms_2D_fdecl_mediump;
2902             case 3:
2903                 return s_fragment_shader_ms_3D_fdecl_mediump;
2904             default:
2905                 DE_FATAL("invalid texture dimension");
2906                 return DE_NULL;
2907             }
2908         }
2909         else
2910         {
2911             switch (D)
2912             {
2913             case 2:
2914                 return s_fragment_shader_ms_2D_udecl_mediump;
2915             case 3:
2916                 return s_fragment_shader_ms_3D_udecl_mediump;
2917             default:
2918                 DE_FATAL("invalid texture dimension");
2919                 return DE_NULL;
2920             }
2921         }
2922     }
2923 
2924     if (typeid(T) == typeid(glw::GLint))
2925     {
2926         switch (D)
2927         {
2928         case 2:
2929             return s_fragment_shader_ms_2D_idecl_highp;
2930         case 3:
2931             return s_fragment_shader_ms_3D_idecl_highp;
2932         default:
2933             DE_FATAL("invalid texture dimension");
2934             return DE_NULL;
2935         }
2936     }
2937 
2938     if (typeid(T) == typeid(glw::GLuint))
2939     {
2940         switch (D)
2941         {
2942         case 2:
2943             return s_fragment_shader_ms_2D_udecl_highp;
2944         case 3:
2945             return s_fragment_shader_ms_3D_udecl_highp;
2946         default:
2947             DE_FATAL("invalid texture dimension");
2948             return DE_NULL;
2949         }
2950     }
2951 
2952     if (typeid(T) == typeid(glw::GLfloat))
2953     {
2954         switch (D)
2955         {
2956         case 2:
2957             return s_fragment_shader_ms_2D_fdecl_highp;
2958         case 3:
2959             return s_fragment_shader_ms_3D_fdecl_highp;
2960         default:
2961             DE_FATAL("invalid texture dimension");
2962             return DE_NULL;
2963         }
2964     }
2965 
2966     DE_FATAL("invalid type");
2967     return DE_NULL;
2968 }
2969 
2970 /** @brief Fragment shader declaration selector.
2971  *
2972  *  @return Frgment shader source code part.
2973  */
2974 template <typename T, glw::GLint S, bool N, glw::GLuint D>
FragmentShaderDeclarationAuxiliary()2975 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::FragmentShaderDeclarationAuxiliary()
2976 {
2977     if (typeid(T) == typeid(glw::GLbyte))
2978     {
2979         switch (D)
2980         {
2981         case 2:
2982             return s_fragment_shader_aux_2D_idecl_lowp;
2983         case 3:
2984             return s_fragment_shader_aux_3D_idecl_lowp;
2985         default:
2986             DE_FATAL("invalid texture dimension");
2987             return DE_NULL;
2988         }
2989     }
2990 
2991     if (typeid(T) == typeid(glw::GLubyte))
2992     {
2993         if (N)
2994         {
2995             switch (D)
2996             {
2997             case 2:
2998                 return s_fragment_shader_aux_2D_fdecl_lowp;
2999             case 3:
3000                 return s_fragment_shader_aux_3D_fdecl_lowp;
3001             default:
3002                 DE_FATAL("invalid texture dimension");
3003                 return DE_NULL;
3004             }
3005         }
3006         else
3007         {
3008             switch (D)
3009             {
3010             case 2:
3011                 return s_fragment_shader_aux_2D_udecl_lowp;
3012             case 3:
3013                 return s_fragment_shader_aux_3D_udecl_lowp;
3014             default:
3015                 DE_FATAL("invalid texture dimension");
3016                 return DE_NULL;
3017             }
3018         }
3019     }
3020 
3021     if (typeid(T) == typeid(glw::GLshort))
3022     {
3023         switch (D)
3024         {
3025         case 2:
3026             return s_fragment_shader_aux_2D_idecl_mediump;
3027         case 3:
3028             return s_fragment_shader_aux_3D_idecl_mediump;
3029         default:
3030             DE_FATAL("invalid texture dimension");
3031             return DE_NULL;
3032         }
3033     }
3034 
3035     if (typeid(T) == typeid(glw::GLushort))
3036     {
3037         if (N)
3038         {
3039             switch (D)
3040             {
3041             case 2:
3042                 return s_fragment_shader_aux_2D_fdecl_mediump;
3043             case 3:
3044                 return s_fragment_shader_aux_3D_fdecl_mediump;
3045             default:
3046                 DE_FATAL("invalid texture dimension");
3047                 return DE_NULL;
3048             }
3049         }
3050         else
3051         {
3052             switch (D)
3053             {
3054             case 2:
3055                 return s_fragment_shader_aux_2D_udecl_mediump;
3056             case 3:
3057                 return s_fragment_shader_aux_3D_udecl_mediump;
3058             default:
3059                 DE_FATAL("invalid texture dimension");
3060                 return DE_NULL;
3061             }
3062         }
3063     }
3064 
3065     if (typeid(T) == typeid(glw::GLint))
3066     {
3067         switch (D)
3068         {
3069         case 2:
3070             return s_fragment_shader_aux_2D_idecl_highp;
3071         case 3:
3072             return s_fragment_shader_aux_3D_idecl_highp;
3073         default:
3074             DE_FATAL("invalid texture dimension");
3075             return DE_NULL;
3076         }
3077     }
3078 
3079     if (typeid(T) == typeid(glw::GLuint))
3080     {
3081         switch (D)
3082         {
3083         case 2:
3084             return s_fragment_shader_aux_2D_udecl_highp;
3085         case 3:
3086             return s_fragment_shader_aux_3D_udecl_highp;
3087         default:
3088             DE_FATAL("invalid texture dimension");
3089             return DE_NULL;
3090         }
3091     }
3092 
3093     if (typeid(T) == typeid(glw::GLfloat))
3094     {
3095         switch (D)
3096         {
3097         case 2:
3098             return s_fragment_shader_aux_2D_fdecl_highp;
3099         case 3:
3100             return s_fragment_shader_aux_3D_fdecl_highp;
3101         default:
3102             DE_FATAL("invalid texture dimension");
3103             return DE_NULL;
3104         }
3105     }
3106 
3107     DE_FATAL("invalid type");
3108     return DE_NULL;
3109 }
3110 
3111 /** @brief Fragment shader tail selector.
3112  *
3113  *  @return Frgment shader source code part.
3114  */
3115 template <typename T, glw::GLint S, bool N, glw::GLuint D>
FragmentShaderTail()3116 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::FragmentShaderTail()
3117 {
3118     switch (D)
3119     {
3120     case 2:
3121         return s_fragment_shader_tail_2D;
3122     case 3:
3123         return s_fragment_shader_tail_3D;
3124     default:
3125         DE_FATAL("invalid texture dimension");
3126         return DE_NULL;
3127     }
3128 }
3129 
3130 /** @brief Multisample texture target selector.
3131  *
3132  *  @return Texture target.
3133  */
3134 template <typename T, glw::GLint S, bool N, glw::GLuint D>
MultisampleTextureTarget()3135 glw::GLenum StorageMultisampleTest<T, S, N, D>::MultisampleTextureTarget()
3136 {
3137     switch (D)
3138     {
3139     case 2:
3140         return GL_TEXTURE_2D_MULTISAMPLE;
3141     case 3:
3142         return GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
3143     default:
3144         DE_FATAL("invalid texture dimension");
3145         return DE_NULL;
3146     }
3147 }
3148 
3149 /** @brief Input texture target selector.
3150  *
3151  *  @return Texture target.
3152  */
3153 template <typename T, glw::GLint S, bool N, glw::GLuint D>
InputTextureTarget()3154 glw::GLenum StorageMultisampleTest<T, S, N, D>::InputTextureTarget()
3155 {
3156     switch (D)
3157     {
3158     case 2:
3159         return GL_TEXTURE_2D;
3160     case 3:
3161         return GL_TEXTURE_2D_ARRAY;
3162     default:
3163         DE_FATAL("invalid texture dimension");
3164         return DE_NULL;
3165     }
3166 }
3167 
3168 /** @brief Prepare texture data for input texture.
3169  *
3170  *  @note parameters as passed to texImage*
3171  */
3172 template <typename T, glw::GLint S, bool N, glw::GLuint D>
InputTextureImage(const glw::GLenum internal_format,const glw::GLuint width,const glw::GLuint height,const glw::GLuint depth,const glw::GLenum format,const glw::GLenum type,const glw::GLvoid * data)3173 void StorageMultisampleTest<T, S, N, D>::InputTextureImage(const glw::GLenum internal_format, const glw::GLuint width,
3174                                                            const glw::GLuint height, const glw::GLuint depth,
3175                                                            const glw::GLenum format, const glw::GLenum type,
3176                                                            const glw::GLvoid *data)
3177 {
3178     (void)depth;
3179     /* Shortcut for GL functionality. */
3180     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
3181 
3182     /* Data setup. */
3183     switch (D)
3184     {
3185     case 2:
3186         gl.texImage2D(InputTextureTarget(), 0, internal_format, width, height, 0, format, type, data);
3187         break;
3188     case 3:
3189         gl.texImage3D(InputTextureTarget(), 0, internal_format, width, height, depth, 0, format, type, data);
3190         break;
3191     default:
3192         DE_FATAL("invalid texture dimension");
3193     }
3194 
3195     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage has failed");
3196 }
3197 
3198 /** @brief Create texture.
3199  *
3200  */
3201 template <typename T, glw::GLint S, bool N, glw::GLuint D>
CreateInputTexture()3202 void StorageMultisampleTest<T, S, N, D>::CreateInputTexture()
3203 {
3204     /* Shortcut for GL functionality. */
3205     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
3206 
3207     /* Objects creation. */
3208     gl.genTextures(1, &m_to);
3209     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
3210 
3211     gl.bindTexture(InputTextureTarget(), m_to);
3212     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
3213 
3214     /* Data setup. */
3215     InputTextureImage(InternalFormat<T, S, N>(), TestReferenceDataWidth(), TestReferenceDataHeight(),
3216                       TestReferenceDataDepth(), Format<S, N>(), Type<T>(), ReferenceData<T, N>());
3217 
3218     /* Parameter setup. */
3219     gl.texParameteri(InputTextureTarget(), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3220     gl.texParameteri(InputTextureTarget(), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3221     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
3222 }
3223 
3224 /** @brief Compre results with the reference.
3225  *
3226  *  @return True if equal, false otherwise.
3227  */
3228 template <typename T, glw::GLint S, bool N, glw::GLuint D>
Check()3229 bool StorageMultisampleTest<T, S, N, D>::Check()
3230 {
3231     /* Shortcut for GL functionality. */
3232     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
3233 
3234     /* Fetching data fro auxiliary texture. */
3235     std::vector<T> result(TestReferenceDataCount());
3236 
3237     gl.bindTexture(InputTextureTarget() /* Auxiliary target is the same as input. */, m_to_aux);
3238     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
3239 
3240     gl.getTexImage(InputTextureTarget() /* Auxiliary target is the same as input. */, 0, Format<S, N>(), Type<T>(),
3241                    (glw::GLvoid *)(&result[0]));
3242     GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexImage has failed");
3243 
3244     /* Comparison. */
3245     for (glw::GLuint i = 0; i < TestReferenceDataCount(); ++i)
3246     {
3247         if (!Compare<T>(result[i], ReferenceData<T, N>()[i]))
3248         {
3249             return false;
3250         }
3251     }
3252 
3253     return true;
3254 }
3255 
3256 /** @brief Test case function.
3257  *
3258  *  @return True if test succeeded, false otherwise.
3259  */
3260 template <typename T, glw::GLint S, bool N, glw::GLuint D>
Test()3261 bool StorageMultisampleTest<T, S, N, D>::Test()
3262 {
3263     /* Shortcut for GL functionality. */
3264     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
3265 
3266     /* Setup. */
3267     gl.pixelStorei(GL_UNPACK_ALIGNMENT, sizeof(T));
3268     GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
3269 
3270     gl.pixelStorei(GL_PACK_ALIGNMENT, sizeof(T));
3271     GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
3272 
3273     CreateInputTexture();
3274 
3275     if (!PrepareFramebufferMultisample(InternalFormat<T, S, N>()))
3276     {
3277         CleanInputTexture();
3278 
3279         return false;
3280     }
3281 
3282     PrepareFramebufferAuxiliary(InternalFormat<T, S, N>());
3283 
3284     /* Action. */
3285     Draw();
3286 
3287     /* Compare results with reference. */
3288     bool result = Check();
3289 
3290     /* Cleanup. */
3291     CleanAuxiliaryTexture();
3292     CleanFramebuffers();
3293     CleanInputTexture();
3294     CleanErrors();
3295 
3296     /* Pass result. */
3297     return result;
3298 }
3299 
3300 /** @brief Function prepares framebuffer with internal format color attachment.
3301  *         Viewport is set up. Content of the framebuffer is cleared.
3302  *
3303  *  @note The function may throw if unexpected error has occured.
3304  */
3305 template <typename T, glw::GLint S, bool N, glw::GLuint D>
PrepareFramebufferMultisample(const glw::GLenum internal_format)3306 bool StorageMultisampleTest<T, S, N, D>::PrepareFramebufferMultisample(const glw::GLenum internal_format)
3307 {
3308     /* Shortcut for GL functionality. */
3309     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
3310 
3311     /* Prepare framebuffer. */
3312     gl.genFramebuffers(1, &m_fbo_ms);
3313     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
3314 
3315     gl.genTextures(1, &m_to_ms);
3316     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
3317 
3318     gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
3319     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
3320 
3321     gl.bindTexture(MultisampleTextureTarget(), m_to_ms);
3322     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
3323 
3324     switch (D)
3325     {
3326     case 2:
3327         gl.textureStorage2DMultisample(m_to_ms, 1, internal_format, TestReferenceDataWidth(), TestReferenceDataHeight(),
3328                                        false);
3329         break;
3330     case 3:
3331         gl.textureStorage3DMultisample(m_to_ms, 1, internal_format, TestReferenceDataWidth(), TestReferenceDataHeight(),
3332                                        TestReferenceDataDepth(), false);
3333         break;
3334     default:
3335         DE_FATAL("invalid texture dimension");
3336         return false;
3337     }
3338 
3339     glw::GLenum error;
3340 
3341     if (GL_NO_ERROR != (error = gl.getError()))
3342     {
3343         CleanFramebuffers();
3344 
3345         m_context.getTestContext().getLog()
3346             << tcu::TestLog::Message << "glTextureStorageMultisample unexpectedly generated error "
3347             << glu::getErrorStr(error) << " during the test of internal format "
3348             << glu::getTextureFormatStr(internal_format) << ". Test fails." << tcu::TestLog::EndMessage;
3349 
3350         return false;
3351     }
3352 
3353     switch (D)
3354     {
3355     case 2:
3356         gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, m_to_ms, 0);
3357         break;
3358     case 3:
3359         for (glw::GLuint i = 0; i < TestReferenceDataDepth(); ++i)
3360         {
3361             gl.framebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, m_to_ms, 0, i);
3362             GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTextureLayer call failed.");
3363         }
3364         break;
3365     default:
3366         DE_FATAL("invalid texture dimension");
3367         return false;
3368     }
3369     GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
3370 
3371     if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
3372     {
3373         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_UNSUPPORTED)
3374             throw tcu::NotSupportedError("unsupported framebuffer configuration");
3375         else
3376             throw 0;
3377     }
3378 
3379     gl.viewport(0, 0, TestReferenceDataWidth(), TestReferenceDataHeight());
3380     GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
3381 
3382     /* Clear framebuffer's content. */
3383     gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
3384     GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
3385 
3386     gl.clear(GL_COLOR_BUFFER_BIT);
3387     GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
3388 
3389     return true;
3390 }
3391 
3392 /** @brief Function prepares framebuffer with internal format color attachment.
3393  *         Viewport is set up. Content of the framebuffer is cleared.
3394  *
3395  *  @note The function may throw if unexpected error has occured.
3396  */
3397 template <typename T, glw::GLint S, bool N, glw::GLuint D>
PrepareFramebufferAuxiliary(const glw::GLenum internal_format)3398 void StorageMultisampleTest<T, S, N, D>::PrepareFramebufferAuxiliary(const glw::GLenum internal_format)
3399 {
3400     /* Shortcut for GL functionality. */
3401     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
3402 
3403     /* Prepare framebuffer. */
3404     gl.genFramebuffers(1, &m_fbo_aux);
3405     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
3406 
3407     gl.genTextures(1, &m_to_aux);
3408     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
3409 
3410     gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_aux);
3411     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
3412 
3413     gl.bindTexture(InputTextureTarget(), m_to_aux);
3414     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
3415 
3416     switch (D)
3417     {
3418     case 2:
3419         gl.textureStorage2D(m_to_aux, 1, internal_format, TestReferenceDataWidth(), TestReferenceDataHeight());
3420         break;
3421     case 3:
3422         gl.textureStorage3D(m_to_aux, 1, internal_format, TestReferenceDataWidth(), TestReferenceDataHeight(),
3423                             TestReferenceDataDepth());
3424         break;
3425     default:
3426         DE_FATAL("invalid texture dimension");
3427     }
3428     GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2D call failed.");
3429 
3430     /* Parameter setup. */
3431     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3432     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3433     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
3434 
3435     switch (D)
3436     {
3437     case 2:
3438         gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_to_aux, 0);
3439         break;
3440     case 3:
3441         for (glw::GLuint i = 0; i < TestReferenceDataDepth(); ++i)
3442         {
3443             gl.framebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, m_to_aux, 0, i);
3444             GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTextureLayer call failed.");
3445         }
3446         break;
3447     default:
3448         DE_FATAL("invalid texture dimension");
3449     }
3450     GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
3451 
3452     if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
3453     {
3454         if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_UNSUPPORTED)
3455             throw tcu::NotSupportedError("unsupported framebuffer configuration");
3456         else
3457             throw 0;
3458     }
3459 
3460     gl.viewport(0, 0, TestReferenceDataWidth(), TestReferenceDataHeight());
3461     GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
3462 
3463     /* Clear framebuffer's content. */
3464     gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
3465     GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
3466 
3467     gl.clear(GL_COLOR_BUFFER_BIT);
3468     GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
3469 }
3470 
3471 /** @brief Prepare program
3472  *
3473  *  @param [in] variable_declaration      Variables declaration part of fragment shader source code.
3474  *  @param [in] tail                      Tail part of fragment shader source code.
3475  */
3476 template <typename T, glw::GLint S, bool N, glw::GLuint D>
PrepareProgram(const glw::GLchar * variable_declaration,const glw::GLchar * tail)3477 glw::GLuint StorageMultisampleTest<T, S, N, D>::PrepareProgram(const glw::GLchar *variable_declaration,
3478                                                                const glw::GLchar *tail)
3479 {
3480     /* Shortcut for GL functionality */
3481     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
3482 
3483     struct Shader
3484     {
3485         glw::GLchar const *source[3];
3486         glw::GLsizei const count;
3487         glw::GLenum const type;
3488         glw::GLuint id;
3489     } shader[] = {{{s_vertex_shader, NULL, NULL}, 1, GL_VERTEX_SHADER, 0},
3490                   {{s_fragment_shader_head, variable_declaration, tail}, 3, GL_FRAGMENT_SHADER, 0}};
3491 
3492     glw::GLuint const shader_count = sizeof(shader) / sizeof(shader[0]);
3493 
3494     glw::GLuint po = 0;
3495 
3496     try
3497     {
3498         /* Create program. */
3499         po = gl.createProgram();
3500         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateProgram call failed.");
3501 
3502         /* Shader compilation. */
3503 
3504         for (glw::GLuint i = 0; i < shader_count; ++i)
3505         {
3506             {
3507                 shader[i].id = gl.createShader(shader[i].type);
3508 
3509                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateShader call failed.");
3510 
3511                 gl.attachShader(po, shader[i].id);
3512 
3513                 GLU_EXPECT_NO_ERROR(gl.getError(), "glAttachShader call failed.");
3514 
3515                 gl.shaderSource(shader[i].id, shader[i].count, shader[i].source, NULL);
3516 
3517                 GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource call failed.");
3518 
3519                 gl.compileShader(shader[i].id);
3520 
3521                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader call failed.");
3522 
3523                 glw::GLint status = GL_FALSE;
3524 
3525                 gl.getShaderiv(shader[i].id, GL_COMPILE_STATUS, &status);
3526                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
3527 
3528                 if (GL_FALSE == status)
3529                 {
3530                     glw::GLint log_size = 0;
3531                     gl.getShaderiv(shader[i].id, GL_INFO_LOG_LENGTH, &log_size);
3532                     GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
3533 
3534                     glw::GLchar *log_text = new glw::GLchar[log_size];
3535 
3536                     gl.getShaderInfoLog(shader[i].id, log_size, NULL, &log_text[0]);
3537 
3538                     m_context.getTestContext().getLog()
3539                         << tcu::TestLog::Message << "Shader compilation has failed.\n"
3540                         << "Shader type: " << glu::getShaderTypeStr(shader[i].type) << "\n"
3541                         << "Shader compilation error log:\n"
3542                         << log_text << "\n"
3543                         << "Shader source code:\n"
3544                         << shader[i].source[0] << (shader[i].source[1] ? shader[i].source[1] : "")
3545                         << (shader[i].source[2] ? shader[i].source[2] : "") << "\n"
3546                         << tcu::TestLog::EndMessage;
3547 
3548                     delete[] log_text;
3549 
3550                     GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog call failed.");
3551 
3552                     throw 0;
3553                 }
3554             }
3555         }
3556 
3557         /* Link. */
3558         gl.linkProgram(po);
3559 
3560         GLU_EXPECT_NO_ERROR(gl.getError(), "glTransformFeedbackVaryings call failed.");
3561 
3562         glw::GLint status = GL_FALSE;
3563 
3564         gl.getProgramiv(po, GL_LINK_STATUS, &status);
3565 
3566         if (GL_TRUE == status)
3567         {
3568             for (glw::GLuint i = 0; i < shader_count; ++i)
3569             {
3570                 if (shader[i].id)
3571                 {
3572                     gl.detachShader(po, shader[i].id);
3573 
3574                     GLU_EXPECT_NO_ERROR(gl.getError(), "glDetachShader call failed.");
3575                 }
3576             }
3577         }
3578         else
3579         {
3580             glw::GLint log_size = 0;
3581 
3582             gl.getProgramiv(po, GL_INFO_LOG_LENGTH, &log_size);
3583 
3584             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv call failed.");
3585 
3586             glw::GLchar *log_text = new glw::GLchar[log_size];
3587 
3588             gl.getProgramInfoLog(po, log_size, NULL, &log_text[0]);
3589 
3590             m_context.getTestContext().getLog() << tcu::TestLog::Message << "Program linkage has failed due to:\n"
3591                                                 << log_text << "\n"
3592                                                 << tcu::TestLog::EndMessage;
3593 
3594             delete[] log_text;
3595 
3596             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramInfoLog call failed.");
3597 
3598             throw 0;
3599         }
3600     }
3601     catch (...)
3602     {
3603         if (po)
3604         {
3605             gl.deleteProgram(po);
3606 
3607             po = 0;
3608         }
3609     }
3610 
3611     for (glw::GLuint i = 0; i < shader_count; ++i)
3612     {
3613         if (0 != shader[i].id)
3614         {
3615             gl.deleteShader(shader[i].id);
3616 
3617             shader[i].id = 0;
3618         }
3619     }
3620 
3621     if (0 == po)
3622     {
3623         throw 0;
3624     }
3625 
3626     return po;
3627 }
3628 
3629 /** @brief Prepare VAO.
3630  */
3631 template <typename T, glw::GLint S, bool N, glw::GLuint D>
PrepareVertexArray()3632 void StorageMultisampleTest<T, S, N, D>::PrepareVertexArray()
3633 {
3634     /* Shortcut for GL functionality. */
3635     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
3636 
3637     gl.genVertexArrays(1, &m_vao);
3638     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays has failed");
3639 
3640     gl.bindVertexArray(m_vao);
3641     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray has failed");
3642 }
3643 
3644 /** @brief Draw call
3645  */
3646 template <typename T, glw::GLint S, bool N, glw::GLuint D>
Draw()3647 void StorageMultisampleTest<T, S, N, D>::Draw()
3648 {
3649     /* Shortcut for GL functionality. */
3650     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
3651 
3652     /* Prepare multisample texture using draw call. */
3653 
3654     /* Prepare framebuffer with multisample texture. */
3655     gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
3656     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer has failed");
3657 
3658     /* Use first program program. */
3659     gl.useProgram(m_po_ms);
3660     GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed");
3661 
3662     /* Prepare texture to be drawn with. */
3663     gl.activeTexture(GL_TEXTURE0);
3664     GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
3665 
3666     gl.bindTexture(InputTextureTarget(), m_to);
3667     GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
3668 
3669     gl.uniform1i(gl.getUniformLocation(m_po_ms, "texture_input"), 0);
3670     GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed");
3671 
3672     for (glw::GLuint i = 0; i < TestReferenceDataDepth(); ++i)
3673     {
3674         /* Select layer. */
3675         gl.drawBuffer(GL_COLOR_ATTACHMENT0 + i);
3676         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawBuffer has failed");
3677 
3678         if (D == 3)
3679         {
3680             gl.uniform1i(gl.getUniformLocation(m_po_aux, "texture_layer"), i);
3681             GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed");
3682         }
3683 
3684         /* Draw. */
3685         gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
3686         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed");
3687     }
3688 
3689     /* Copy multisample texture to auxiliary texture using draw call. */
3690 
3691     /* Prepare framebuffer with auxiliary texture. */
3692     gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_aux);
3693     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer has failed");
3694 
3695     /* Use first program program. */
3696     gl.useProgram(m_po_aux);
3697     GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed");
3698 
3699     /* Prepare texture to be drawn with. */
3700     gl.activeTexture(GL_TEXTURE0);
3701     GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
3702 
3703     gl.bindTexture(MultisampleTextureTarget(), m_to_ms);
3704     GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed");
3705 
3706     gl.bindTextureUnit(0, m_to);
3707 
3708     gl.uniform1i(gl.getUniformLocation(m_po_aux, "texture_input"), 0);
3709     GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed");
3710 
3711     /* For each texture layer. */
3712     for (glw::GLuint i = 0; i < TestReferenceDataDepth(); ++i)
3713     {
3714         /* Select layer. */
3715         gl.drawBuffer(GL_COLOR_ATTACHMENT0 + i);
3716         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawBuffer has failed");
3717 
3718         if (D == 3)
3719         {
3720             gl.uniform1i(gl.getUniformLocation(m_po_aux, "texture_layer"), i);
3721             GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed");
3722         }
3723 
3724         /* Draw. */
3725         gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
3726         GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed");
3727     }
3728 }
3729 
3730 /** @brief Clean GL objects, test variables and GL errors.
3731  */
3732 template <typename T, glw::GLint S, bool N, glw::GLuint D>
CleanInputTexture()3733 void StorageMultisampleTest<T, S, N, D>::CleanInputTexture()
3734 {
3735     /* Shortcut for GL functionality. */
3736     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
3737 
3738     /* Texture. */
3739     if (m_to)
3740     {
3741         gl.deleteTextures(1, &m_to);
3742 
3743         m_to = 0;
3744     }
3745 }
3746 
3747 /** @brief Clean GL objects, test variables and GL errors.
3748  */
3749 template <typename T, glw::GLint S, bool N, glw::GLuint D>
CleanAuxiliaryTexture()3750 void StorageMultisampleTest<T, S, N, D>::CleanAuxiliaryTexture()
3751 {
3752     /* Shortcut for GL functionality. */
3753     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
3754 
3755     if (m_to_aux)
3756     {
3757         gl.deleteTextures(1, &m_to_aux);
3758 
3759         m_to_aux = 0;
3760     }
3761 }
3762 
3763 /** @brief Clean GL objects, test variables and GL errors.
3764  */
3765 template <typename T, glw::GLint S, bool N, glw::GLuint D>
CleanFramebuffers()3766 void StorageMultisampleTest<T, S, N, D>::CleanFramebuffers()
3767 {
3768     /* Shortcut for GL functionality. */
3769     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
3770 
3771     /* Mulitsample framebuffer. */
3772     if (m_fbo_ms)
3773     {
3774         gl.deleteFramebuffers(1, &m_fbo_ms);
3775 
3776         m_fbo_ms = 0;
3777     }
3778 
3779     /* Mulitsample texture. */
3780     if (m_to_ms)
3781     {
3782         gl.deleteTextures(1, &m_to_ms);
3783 
3784         m_to_ms = 0;
3785     }
3786 
3787     /* Auxiliary framebuffer. */
3788     if (m_fbo_aux)
3789     {
3790         gl.deleteFramebuffers(1, &m_fbo_aux);
3791 
3792         m_fbo_aux = 0;
3793     }
3794 
3795     /* Auxiliary texture. */
3796     if (m_to_aux)
3797     {
3798         gl.deleteTextures(1, &m_to_aux);
3799 
3800         m_to_aux = 0;
3801     }
3802 }
3803 
3804 /** @brief Clean GL objects, test variables and GL errors.
3805  */
3806 template <typename T, glw::GLint S, bool N, glw::GLuint D>
CleanPrograms()3807 void StorageMultisampleTest<T, S, N, D>::CleanPrograms()
3808 {
3809     /* Shortcut for GL functionality. */
3810     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
3811 
3812     /* Binding point. */
3813     gl.useProgram(0);
3814 
3815     /* Multisample texture preparation program. */
3816     if (m_po_ms)
3817     {
3818         gl.deleteProgram(m_po_ms);
3819 
3820         m_po_ms = 0;
3821     }
3822 
3823     /* Auxiliary texture preparation program. */
3824     if (m_po_aux)
3825     {
3826         gl.deleteProgram(m_po_aux);
3827 
3828         m_po_aux = 0;
3829     }
3830 }
3831 
3832 /** @brief Clean GL objects, test variables and GL errors.
3833  */
3834 template <typename T, glw::GLint S, bool N, glw::GLuint D>
CleanErrors()3835 void StorageMultisampleTest<T, S, N, D>::CleanErrors()
3836 {
3837     /* Shortcut for GL functionality. */
3838     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
3839 
3840     /* Query all errors until GL_NO_ERROR occure. */
3841     while (GL_NO_ERROR != gl.getError())
3842         ;
3843 }
3844 
3845 /** @brief Clean GL objects, test variables and GL errors.
3846  */
3847 template <typename T, glw::GLint S, bool N, glw::GLuint D>
CleanVertexArray()3848 void StorageMultisampleTest<T, S, N, D>::CleanVertexArray()
3849 {
3850     /* Shortcut for GL functionality. */
3851     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
3852 
3853     if (m_vao)
3854     {
3855         gl.bindVertexArray(0);
3856 
3857         gl.deleteVertexArrays(1, &m_vao);
3858 
3859         m_vao = 0;
3860     }
3861 }
3862 
3863 /** @brief Iterate Storage Multisample Test cases.
3864  *
3865  *  @return Iteration result.
3866  */
3867 template <typename T, glw::GLint S, bool N, glw::GLuint D>
iterate()3868 tcu::TestNode::IterateResult StorageMultisampleTest<T, S, N, D>::iterate()
3869 {
3870     /* Shortcut for GL functionality. */
3871     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
3872 
3873     /* Get context setup. */
3874     bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
3875     bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
3876 
3877     if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
3878     {
3879         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
3880 
3881         return STOP;
3882     }
3883 
3884     /* Running tests. */
3885     bool is_ok    = true;
3886     bool is_error = false;
3887 
3888     try
3889     {
3890         PrepareVertexArray();
3891 
3892         //  gl.enable(GL_MULTISAMPLE);
3893 
3894         m_po_ms  = PrepareProgram(FragmentShaderDeclarationMultisample(), FragmentShaderTail());
3895         m_po_aux = PrepareProgram(FragmentShaderDeclarationAuxiliary(), FragmentShaderTail());
3896 
3897         is_ok = Test();
3898     }
3899     catch (tcu::NotSupportedError &e)
3900     {
3901         throw e;
3902     }
3903     catch (...)
3904     {
3905         is_ok    = false;
3906         is_error = true;
3907     }
3908 
3909     /* Cleanup. */
3910     CleanInputTexture();
3911     CleanAuxiliaryTexture();
3912     CleanFramebuffers();
3913     CleanPrograms();
3914     CleanErrors();
3915     CleanVertexArray();
3916     gl.disable(GL_MULTISAMPLE);
3917 
3918     /* Errors clean up. */
3919     while (gl.getError())
3920         ;
3921 
3922     /* Result's setup. */
3923     if (is_ok)
3924     {
3925         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
3926     }
3927     else
3928     {
3929         if (is_error)
3930         {
3931             m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
3932         }
3933         else
3934         {
3935             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
3936         }
3937     }
3938 
3939     return STOP;
3940 }
3941 
3942 /* Vertex shader source code. */
3943 template <typename T, glw::GLint S, bool N, glw::GLuint D>
3944 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_vertex_shader =
3945     "#version 450\n"
3946     "\n"
3947     "void main()\n"
3948     "{\n"
3949     "    switch(gl_VertexID)\n"
3950     "    {\n"
3951     "        case 0:\n"
3952     "            gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
3953     "            break;\n"
3954     "        case 1:\n"
3955     "            gl_Position = vec4( 1.0, 1.0, 0.0, 1.0);\n"
3956     "            break;\n"
3957     "        case 2:\n"
3958     "            gl_Position = vec4(-1.0,-1.0, 0.0, 1.0);\n"
3959     "            break;\n"
3960     "        case 3:\n"
3961     "            gl_Position = vec4( 1.0,-1.0, 0.0, 1.0);\n"
3962     "            break;\n"
3963     "    }\n"
3964     "}\n";
3965 
3966 /* Fragment shader source program. */
3967 template <typename T, glw::GLint S, bool N, glw::GLuint D>
3968 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_head =
3969     "#version 450\n"
3970     "\n"
3971     "layout(pixel_center_integer) in vec4 gl_FragCoord;\n"
3972     "\n";
3973 
3974 template <typename T, glw::GLint S, bool N, glw::GLuint D>
3975 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_2D_fdecl_lowp =
3976     "uniform  sampler2D texture_input;\nout     vec4          texture_output;\n";
3977 template <typename T, glw::GLint S, bool N, glw::GLuint D>
3978 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_2D_idecl_lowp =
3979     "uniform isampler2D texture_input;\nout     ivec4         texture_output;\n";
3980 template <typename T, glw::GLint S, bool N, glw::GLuint D>
3981 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_2D_udecl_lowp =
3982     "uniform usampler2D texture_input;\nout     uvec4         texture_output;\n";
3983 template <typename T, glw::GLint S, bool N, glw::GLuint D>
3984 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_2D_fdecl_mediump =
3985     "uniform  sampler2D texture_input;\nout     vec4          texture_output;\n";
3986 template <typename T, glw::GLint S, bool N, glw::GLuint D>
3987 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_2D_idecl_mediump =
3988     "uniform isampler2D texture_input;\nout     ivec4         texture_output;\n";
3989 template <typename T, glw::GLint S, bool N, glw::GLuint D>
3990 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_2D_udecl_mediump =
3991     "uniform usampler2D texture_input;\nout     uvec4         texture_output;\n";
3992 template <typename T, glw::GLint S, bool N, glw::GLuint D>
3993 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_2D_fdecl_highp =
3994     "uniform  sampler2D texture_input;\nout     vec4          texture_output;\n";
3995 template <typename T, glw::GLint S, bool N, glw::GLuint D>
3996 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_2D_idecl_highp =
3997     "uniform isampler2D texture_input;\nout     ivec4         texture_output;\n";
3998 template <typename T, glw::GLint S, bool N, glw::GLuint D>
3999 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_2D_udecl_highp =
4000     "uniform usampler2D texture_input;\nout     uvec4         texture_output;\n";
4001 
4002 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4003 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_3D_fdecl_lowp =
4004     "uniform  sampler2DArray texture_input;\nout     vec4          texture_output;\n";
4005 
4006 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4007 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_3D_idecl_lowp =
4008     "uniform isampler2DArray texture_input;\nout     ivec4         texture_output;\n";
4009 
4010 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4011 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_3D_udecl_lowp =
4012     "uniform usampler2DArray texture_input;\nout     uvec4         texture_output;\n";
4013 
4014 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4015 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_3D_fdecl_mediump =
4016     "uniform  sampler2DArray texture_input;\nout     vec4          texture_output;\n";
4017 
4018 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4019 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_3D_idecl_mediump =
4020     "uniform isampler2DArray texture_input;\nout     ivec4         texture_output;\n";
4021 
4022 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4023 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_3D_udecl_mediump =
4024     "uniform usampler2DArray texture_input;\nout     uvec4         texture_output;\n";
4025 
4026 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4027 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_3D_fdecl_highp =
4028     "uniform  sampler2DArray texture_input;\nout     vec4          texture_output;\n";
4029 
4030 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4031 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_3D_idecl_highp =
4032     "uniform isampler2DArray texture_input;\nout     ivec4         texture_output;\n";
4033 
4034 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4035 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_3D_udecl_highp =
4036     "uniform usampler2DArray texture_input;\nout     uvec4         texture_output;\n";
4037 
4038 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4039 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_aux_2D_fdecl_lowp =
4040     "uniform  sampler2DMS texture_input;\nout     vec4          texture_output;\n";
4041 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4042 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_aux_2D_idecl_lowp =
4043     "uniform isampler2DMS texture_input;\nout     ivec4         texture_output;\n";
4044 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4045 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_aux_2D_udecl_lowp =
4046     "uniform usampler2DMS texture_input;\nout     uvec4         texture_output;\n";
4047 
4048 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4049 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_aux_2D_fdecl_mediump =
4050     "uniform  sampler2DMS texture_input;\nout     vec4          texture_output;\n";
4051 
4052 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4053 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_aux_2D_idecl_mediump =
4054     "uniform isampler2DMS texture_input;\nout     ivec4         texture_output;\n";
4055 
4056 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4057 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_aux_2D_udecl_mediump =
4058     "uniform usampler2DMS texture_input;\nout     uvec4         texture_output;\n";
4059 
4060 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4061 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_aux_2D_fdecl_highp =
4062     "uniform  sampler2DMS texture_input;\nout     vec4          texture_output;\n";
4063 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4064 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_aux_2D_idecl_highp =
4065     "uniform isampler2DMS texture_input;\nout     ivec4         texture_output;\n";
4066 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4067 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_aux_2D_udecl_highp =
4068     "uniform usampler2DMS texture_input;\nout     uvec4         texture_output;\n";
4069 
4070 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4071 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_aux_3D_fdecl_lowp =
4072     "uniform  sampler2DMSArray texture_input;\nout     vec4          texture_output;\n";
4073 
4074 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4075 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_aux_3D_idecl_lowp =
4076     "uniform isampler2DMSArray texture_input;\nout     ivec4         texture_output;\n";
4077 
4078 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4079 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_aux_3D_udecl_lowp =
4080     "uniform usampler2DMSArray texture_input;\nout     uvec4         texture_output;\n";
4081 
4082 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4083 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_aux_3D_fdecl_mediump =
4084     "uniform  sampler2DMSArray texture_input;\nout     vec4          texture_output;\n";
4085 
4086 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4087 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_aux_3D_idecl_mediump =
4088     "uniform isampler2DMSArray texture_input;\nout     ivec4         texture_output;\n";
4089 
4090 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4091 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_aux_3D_udecl_mediump =
4092     "uniform usampler2DMSArray texture_input;\nout     uvec4         texture_output;\n";
4093 
4094 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4095 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_aux_3D_fdecl_highp =
4096     "uniform  sampler2DMSArray texture_input;\nout     vec4          texture_output;\n";
4097 
4098 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4099 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_aux_3D_idecl_highp =
4100     "uniform isampler2DMSArray texture_input;\nout     ivec4         texture_output;\n";
4101 
4102 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4103 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_aux_3D_udecl_highp =
4104     "uniform usampler2DMSArray texture_input;\nout     uvec4         texture_output;\n";
4105 
4106 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4107 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_tail_2D =
4108     "\n"
4109     "void main()\n"
4110     "{\n"
4111     "    texture_output = texelFetch(texture_input, ivec2(gl_FragCoord.xy), 0);\n"
4112     "}\n";
4113 
4114 template <typename T, glw::GLint S, bool N, glw::GLuint D>
4115 const glw::GLchar *StorageMultisampleTest<T, S, N, D>::s_fragment_shader_tail_3D =
4116     "\n"
4117     "uniform int texture_layer;\n"
4118     "\n"
4119     "void main()\n"
4120     "{\n"
4121     "    texture_output = texelFetch(texture_input, ivec3(gl_FragCoord.xy, texture_layer), 0);\n"
4122     "}\n";
4123 
4124 template class StorageMultisampleTest<glw::GLbyte, 1, false, 2>;
4125 template class StorageMultisampleTest<glw::GLbyte, 2, false, 2>;
4126 template class StorageMultisampleTest<glw::GLbyte, 4, false, 2>;
4127 template class StorageMultisampleTest<glw::GLbyte, 1, false, 3>;
4128 template class StorageMultisampleTest<glw::GLbyte, 2, false, 3>;
4129 template class StorageMultisampleTest<glw::GLbyte, 4, false, 3>;
4130 
4131 template class StorageMultisampleTest<glw::GLubyte, 1, false, 2>;
4132 template class StorageMultisampleTest<glw::GLubyte, 2, false, 2>;
4133 template class StorageMultisampleTest<glw::GLubyte, 4, false, 2>;
4134 template class StorageMultisampleTest<glw::GLubyte, 1, false, 3>;
4135 template class StorageMultisampleTest<glw::GLubyte, 2, false, 3>;
4136 template class StorageMultisampleTest<glw::GLubyte, 4, false, 3>;
4137 
4138 template class StorageMultisampleTest<glw::GLubyte, 1, true, 2>;
4139 template class StorageMultisampleTest<glw::GLubyte, 2, true, 2>;
4140 template class StorageMultisampleTest<glw::GLubyte, 4, true, 2>;
4141 template class StorageMultisampleTest<glw::GLubyte, 1, true, 3>;
4142 template class StorageMultisampleTest<glw::GLubyte, 2, true, 3>;
4143 template class StorageMultisampleTest<glw::GLubyte, 4, true, 3>;
4144 
4145 template class StorageMultisampleTest<glw::GLshort, 1, false, 2>;
4146 template class StorageMultisampleTest<glw::GLshort, 2, false, 2>;
4147 template class StorageMultisampleTest<glw::GLshort, 4, false, 2>;
4148 template class StorageMultisampleTest<glw::GLshort, 1, false, 3>;
4149 template class StorageMultisampleTest<glw::GLshort, 2, false, 3>;
4150 template class StorageMultisampleTest<glw::GLshort, 4, false, 3>;
4151 
4152 template class StorageMultisampleTest<glw::GLushort, 1, false, 2>;
4153 template class StorageMultisampleTest<glw::GLushort, 2, false, 2>;
4154 template class StorageMultisampleTest<glw::GLushort, 4, false, 2>;
4155 template class StorageMultisampleTest<glw::GLushort, 1, false, 3>;
4156 template class StorageMultisampleTest<glw::GLushort, 2, false, 3>;
4157 template class StorageMultisampleTest<glw::GLushort, 4, false, 3>;
4158 
4159 template class StorageMultisampleTest<glw::GLushort, 1, true, 2>;
4160 template class StorageMultisampleTest<glw::GLushort, 2, true, 2>;
4161 template class StorageMultisampleTest<glw::GLushort, 4, true, 2>;
4162 template class StorageMultisampleTest<glw::GLushort, 1, true, 3>;
4163 template class StorageMultisampleTest<glw::GLushort, 2, true, 3>;
4164 template class StorageMultisampleTest<glw::GLushort, 4, true, 3>;
4165 
4166 template class StorageMultisampleTest<glw::GLint, 1, false, 2>;
4167 template class StorageMultisampleTest<glw::GLint, 2, false, 2>;
4168 template class StorageMultisampleTest<glw::GLint, 3, false, 2>;
4169 template class StorageMultisampleTest<glw::GLint, 4, false, 2>;
4170 template class StorageMultisampleTest<glw::GLint, 1, false, 3>;
4171 template class StorageMultisampleTest<glw::GLint, 2, false, 3>;
4172 template class StorageMultisampleTest<glw::GLint, 3, false, 3>;
4173 template class StorageMultisampleTest<glw::GLint, 4, false, 3>;
4174 
4175 template class StorageMultisampleTest<glw::GLuint, 1, false, 2>;
4176 template class StorageMultisampleTest<glw::GLuint, 2, false, 2>;
4177 template class StorageMultisampleTest<glw::GLuint, 3, false, 2>;
4178 template class StorageMultisampleTest<glw::GLuint, 4, false, 2>;
4179 template class StorageMultisampleTest<glw::GLuint, 1, false, 3>;
4180 template class StorageMultisampleTest<glw::GLuint, 2, false, 3>;
4181 template class StorageMultisampleTest<glw::GLuint, 3, false, 3>;
4182 template class StorageMultisampleTest<glw::GLuint, 4, false, 3>;
4183 
4184 template class StorageMultisampleTest<glw::GLfloat, 1, true, 2>;
4185 template class StorageMultisampleTest<glw::GLfloat, 2, true, 2>;
4186 template class StorageMultisampleTest<glw::GLfloat, 3, true, 2>;
4187 template class StorageMultisampleTest<glw::GLfloat, 4, true, 2>;
4188 template class StorageMultisampleTest<glw::GLfloat, 1, true, 3>;
4189 template class StorageMultisampleTest<glw::GLfloat, 2, true, 3>;
4190 template class StorageMultisampleTest<glw::GLfloat, 3, true, 3>;
4191 template class StorageMultisampleTest<glw::GLfloat, 4, true, 3>;
4192 
4193 /******************************** Compressed SubImage Test Implementation   ********************************/
4194 
4195 /* Compressed m_reference data for unsupported compression formats */
4196 
4197 static const unsigned char data_0x8dbb_2D_8[] = {34, 237, 94, 207, 252, 29, 75, 25};
4198 
4199 static const unsigned char data_0x8dbb_3D_32[] = {34,  237, 94,  207, 252, 29,  75,  25,  34,  237, 44,
4200                                                   173, 101, 230, 139, 254, 34,  237, 176, 88,  174, 127,
4201                                                   248, 206, 34,  237, 127, 209, 211, 203, 100, 150};
4202 
4203 static const unsigned char data_0x8dbc_2D_8[] = {127, 0, 233, 64, 0, 42, 71, 231};
4204 
4205 static const unsigned char data_0x8dbc_3D_32[] = {127, 0,   233, 64,  0,   42,  71, 231, 127, 0,  20,
4206                                                   227, 162, 33,  246, 1,   127, 0,  143, 57,  86, 0,
4207                                                   136, 53,  127, 0,   192, 62,  48, 69,  29,  138};
4208 
4209 static const unsigned char data_0x8dbd_2D_16[] = {34, 237, 94, 207, 252, 29,  75, 25,
4210                                                   28, 242, 94, 111, 44,  101, 35, 145};
4211 
4212 static const unsigned char data_0x8dbd_3D_64[] = {
4213     34,  237, 94,  207, 252, 29,  75,  25,  28,  242, 94,  111, 44,  101, 35,  145, 34,  237, 44,  173, 101, 230,
4214     139, 254, 28,  242, 170, 45,  98,  236, 202, 228, 34,  237, 176, 88,  174, 127, 248, 206, 28,  242, 164, 148,
4215     178, 25,  252, 206, 34,  237, 127, 209, 211, 203, 100, 150, 28,  242, 79,  216, 149, 3,   101, 87};
4216 
4217 static const unsigned char data_0x8dbe_2D_16[] = {127, 0, 233, 64, 0, 42, 71, 231, 127, 0, 233, 144, 23, 163, 100, 115};
4218 
4219 static const unsigned char data_0x8dbe_3D_64[] = {
4220     127, 0,   233, 64, 0,   42, 71,  231, 127, 0,  233, 144, 23,  163, 100, 115, 127, 0,  20,  227, 162, 33,
4221     246, 1,   127, 0,  94,  98, 190, 84,  55,  1,  127, 0,   143, 57,  86,  0,   136, 53, 127, 0,   163, 45,
4222     113, 232, 131, 53, 127, 0,  192, 62,  48,  69, 29,  138, 127, 0,   128, 182, 138, 61, 157, 204};
4223 
4224 static const unsigned char data_0x8e8c_2D_16[] = {144, 43,  143, 15,  254, 15,  152, 153,
4225                                                   153, 153, 89,  143, 140, 166, 183, 113};
4226 
4227 static const unsigned char data_0x8e8c_3D_64[] = {
4228     144, 43,  143, 15,  254, 15,  152, 153, 153, 153, 89,  143, 140, 166, 183, 113, 144, 43,  143, 15,  254, 15,
4229     152, 153, 153, 153, 55,  48,  102, 244, 186, 241, 144, 43,  143, 15,  254, 15,  152, 153, 153, 153, 231, 54,
4230     211, 92,  240, 14,  144, 121, 253, 241, 193, 15,  152, 153, 153, 153, 25,  41,  102, 244, 248, 135};
4231 
4232 static const unsigned char data_0x8e8d_2D_16[] = {144, 43,  143, 15,  254, 15,  152, 153,
4233                                                   153, 153, 89,  143, 140, 166, 183, 113};
4234 
4235 static const unsigned char data_0x8e8d_3D_64[] = {
4236     144, 43,  143, 15,  254, 15,  152, 153, 153, 153, 89,  143, 140, 166, 183, 113, 144, 43,  143, 15,  254, 15,
4237     152, 153, 153, 153, 55,  48,  102, 244, 186, 241, 144, 43,  143, 15,  254, 15,  152, 153, 153, 153, 231, 54,
4238     211, 92,  240, 14,  144, 121, 253, 241, 193, 15,  152, 153, 153, 153, 25,  41,  102, 244, 248, 135};
4239 
4240 static const unsigned char data_0x8e8e_2D_16[] = {67,  155, 82,  120, 142, 7,   31,  124,
4241                                                   224, 255, 165, 221, 239, 223, 122, 223};
4242 
4243 static const unsigned char data_0x8e8e_3D_64[] = {
4244     67, 155, 82, 120, 142, 7,  31,  124, 224, 255, 165, 221, 239, 223, 122, 223, 35, 30,  124, 240, 209, 166,
4245     20, 158, 11, 250, 24,  21, 0,   2,   34,  2,   35,  30,  124, 240, 209, 166, 20, 158, 5,   88,  2,   1,
4246     34, 165, 0,  241, 35,  30, 124, 240, 209, 166, 20,  158, 33,  34,  32,  0,   81, 129, 175, 80};
4247 
4248 static const unsigned char data_0x8e8f_2D_16[] = {131, 54,  165, 148, 26,  47,  62,  248,
4249                                                   176, 254, 149, 203, 222, 206, 187, 173};
4250 
4251 static const unsigned char data_0x8e8f_3D_64[] = {
4252     131, 54,  165, 148, 26, 47,  62,  248, 176, 254, 149, 203, 222, 206, 187, 173, 99,  188, 248, 224, 163, 77,
4253     41,  165, 24,  250, 36, 70,  18,  20,  53,  3,   99,  188, 248, 224, 163, 77,  41,  165, 42,  68,  19,  18,
4254     67,  166, 16,  244, 99, 188, 248, 224, 163, 77,  41,  165, 48,  83,  65,  33,  100, 66,  175, 65};
4255 
4256 static const unsigned char data_GL_COMPRESSED_R11_EAC_2D_8[] = {146, 253, 99, 81, 202, 222, 63, 243};
4257 
4258 static const unsigned char data_GL_COMPRESSED_R11_EAC_3D_32[] = {146, 253, 99,  81,  202, 222, 63,  243, 146, 253, 169,
4259                                                                  188, 102, 31,  246, 55,  146, 253, 123, 247, 62,  71,
4260                                                                  139, 131, 146, 253, 248, 63,  248, 208, 230, 213};
4261 
4262 static const unsigned char data_GL_COMPRESSED_RG11_EAC_2D_16[] = {146, 253, 99,  81, 202, 222, 63,  243,
4263                                                                   140, 254, 110, 0,  160, 130, 207, 180};
4264 
4265 static const unsigned char data_GL_COMPRESSED_RG11_EAC_3D_64[] = {
4266     146, 253, 99,  81,  202, 222, 63,  243, 140, 254, 110, 0,   160, 130, 207, 180, 146, 253, 169, 188, 102, 31,
4267     246, 55,  140, 254, 2,   73,  46,  104, 102, 39,  146, 253, 123, 247, 62,  71,  139, 131, 140, 254, 155, 121,
4268     68,  17,  1,   27,  146, 253, 248, 63,  248, 208, 230, 213, 140, 254, 240, 60,  19,  214, 73,  0};
4269 
4270 static const unsigned char data_GL_COMPRESSED_RGB8_ETC2_2D_8[] = {168, 122, 150, 252, 234, 35, 0, 0};
4271 
4272 static const unsigned char data_GL_COMPRESSED_RGB8_ETC2_3D_32[] = {
4273     168, 122, 150, 252, 234, 35, 0, 0, 168, 122, 150, 253, 31, 140, 0, 0,
4274     138, 167, 105, 252, 196, 87, 0, 0, 138, 167, 105, 253, 49, 248, 0, 0};
4275 
4276 static const unsigned char data_GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2_2D_8[] = {83, 83, 75, 252, 240, 240, 15, 4};
4277 
4278 static const unsigned char data_GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2_3D_32[] = {
4279     83,  83,  75,  252, 240, 240, 15, 4,  107, 99,  99,  253, 240, 240, 14, 15,
4280     135, 135, 135, 252, 240, 240, 15, 15, 108, 108, 108, 253, 240, 248, 11, 11};
4281 
4282 static const unsigned char data_GL_COMPRESSED_RGBA8_ETC2_EAC_2D_16[] = {127, 245, 255, 244, 146, 255, 244, 146,
4283                                                                         168, 122, 150, 252, 234, 35,  0,   0};
4284 
4285 static const unsigned char data_GL_COMPRESSED_RGBA8_ETC2_EAC_3D_64[] = {
4286     127, 245, 255, 244, 146, 255, 244, 146, 168, 122, 150, 252, 234, 35,  0,   0,   127, 245, 255, 244, 146, 255,
4287     244, 146, 168, 122, 150, 253, 31,  140, 0,   0,   127, 245, 255, 244, 146, 255, 244, 146, 138, 167, 105, 252,
4288     196, 87,  0,   0,   127, 245, 255, 244, 146, 255, 244, 146, 138, 167, 105, 253, 49,  248, 0,   0};
4289 
4290 static const unsigned char data_GL_COMPRESSED_SIGNED_R11_EAC_2D_8[] = {73, 221, 99, 81, 201, 222, 63, 241};
4291 
4292 static const unsigned char data_GL_COMPRESSED_SIGNED_R11_EAC_3D_32[] = {
4293     73, 221, 99, 81,  201, 222, 63,  241, 73, 221, 165, 156, 102, 31,  246, 55,
4294     73, 221, 59, 247, 62,  39,  139, 131, 73, 221, 248, 63,  248, 208, 226, 205};
4295 
4296 static const unsigned char data_GL_COMPRESSED_SIGNED_RG11_EAC_2D_16[] = {73, 221, 99,  81, 201, 222, 63, 241,
4297                                                                          66, 191, 110, 0,  96,  131, 77, 180};
4298 
4299 static const unsigned char data_GL_COMPRESSED_SIGNED_RG11_EAC_3D_64[] = {
4300     73,  221, 99,  81,  201, 222, 63,  241, 66,  191, 110, 0,   96, 131, 77,  180, 73,  221, 165, 156, 102, 31,
4301     246, 55,  66,  191, 2,   73,  54,  100, 102, 38,  73,  221, 59, 247, 62,  39,  139, 131, 66,  191, 155, 105,
4302     132, 16,  129, 27,  73,  221, 248, 63,  248, 208, 226, 205, 66, 191, 208, 60,  11,  218, 73,  0};
4303 
4304 static const unsigned char data_GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC_2D_16[] = {127, 245, 255, 244, 146, 255, 244, 146,
4305                                                                                150, 122, 168, 252, 234, 35,  0,   0};
4306 
4307 static const unsigned char data_GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC_3D_64[] = {
4308     127, 245, 255, 244, 146, 255, 244, 146, 150, 122, 168, 252, 234, 35,  0,   0,   127, 245, 255, 244, 146, 255,
4309     244, 146, 150, 122, 168, 253, 31,  140, 0,   0,   127, 245, 255, 244, 146, 255, 244, 146, 105, 167, 138, 252,
4310     196, 87,  0,   0,   127, 245, 255, 244, 146, 255, 244, 146, 105, 167, 138, 253, 49,  248, 0,   0};
4311 
4312 static const unsigned char data_GL_COMPRESSED_SRGB8_ETC2_2D_8[] = {168, 122, 150, 252, 234, 35, 0, 0};
4313 
4314 static const unsigned char data_GL_COMPRESSED_SRGB8_ETC2_3D_32[] = {
4315     168, 122, 150, 252, 234, 35, 0, 0, 168, 122, 150, 253, 31, 140, 0, 0,
4316     138, 167, 105, 252, 196, 87, 0, 0, 138, 167, 105, 253, 49, 248, 0, 0};
4317 
4318 static const unsigned char data_GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2_2D_8[] = {75,  83,  83, 252,
4319                                                                                        240, 240, 15, 4};
4320 
4321 static const unsigned char data_GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2_3D_32[] = {
4322     75,  83,  83,  252, 240, 240, 15, 4,  99,  99,  107, 253, 240, 240, 14, 15,
4323     135, 135, 135, 252, 240, 240, 15, 15, 108, 108, 108, 253, 240, 248, 11, 11};
4324 
4325 /** @brief Compressed SubImage Test constructor.
4326  *
4327  *  @param [in] context     OpenGL context.
4328  */
CompressedSubImageTest(deqp::Context & context)4329 CompressedSubImageTest::CompressedSubImageTest(deqp::Context &context)
4330     : deqp::TestCase(context, "textures_compressed_subimage", "Texture Compressed SubImage Test")
4331     , m_to(0)
4332     , m_to_aux(0)
4333     , m_compressed_texture_data(DE_NULL)
4334     , m_reference(DE_NULL)
4335     , m_result(DE_NULL)
4336     , m_reference_size(0)
4337     , m_reference_internalformat(0)
4338 {
4339     /* Intentionally left blank. */
4340 }
4341 
4342 /** @brief Create texture.
4343  *
4344  *  @param [in] target      Texture target.
4345  */
CreateTextures(glw::GLenum target)4346 void CompressedSubImageTest::CreateTextures(glw::GLenum target)
4347 {
4348     /* Shortcut for GL functionality. */
4349     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
4350 
4351     /* Auxiliary texture (for content creation). */
4352     gl.genTextures(1, &m_to_aux);
4353     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
4354 
4355     gl.bindTexture(target, m_to_aux);
4356     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4357 
4358     /* Test texture (for data upload). */
4359     gl.genTextures(1, &m_to);
4360     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
4361 
4362     gl.bindTexture(target, m_to);
4363     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4364 }
4365 
4366 /** @brief Texture target selector.
4367  *
4368  *  @tparam D      Texture dimenisons.
4369  *
4370  *  @return Texture target.
4371  */
4372 template <>
TextureTarget()4373 glw::GLenum CompressedSubImageTest::TextureTarget<1>()
4374 {
4375     return GL_TEXTURE_1D;
4376 }
4377 
4378 template <>
TextureTarget()4379 glw::GLenum CompressedSubImageTest::TextureTarget<2>()
4380 {
4381     return GL_TEXTURE_2D;
4382 }
4383 
4384 template <>
TextureTarget()4385 glw::GLenum CompressedSubImageTest::TextureTarget<3>()
4386 {
4387     return GL_TEXTURE_2D_ARRAY;
4388 }
4389 
4390 /** @brief Prepare texture data for the auxiliary texture.
4391  *
4392  *  @tparam D      Texture dimenisons.
4393  *
4394  *  @note parameters as passed to texImage*
4395  *
4396  *  @return False if the internal format is unsupported for online compression, True otherwise
4397  */
4398 template <>
TextureImage(glw::GLint internalformat)4399 bool CompressedSubImageTest::TextureImage<1>(glw::GLint internalformat)
4400 {
4401     /* Shortcut for GL functionality. */
4402     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
4403 
4404     gl.texImage1D(TextureTarget<1>(), 0, internalformat, s_texture_width, 0, GL_RGBA, GL_UNSIGNED_BYTE, s_texture_data);
4405 
4406     /* Online compression may be unsupported for some formats */
4407     GLenum error = gl.getError();
4408     if (error == GL_INVALID_OPERATION)
4409         return false;
4410 
4411     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
4412 
4413     return true;
4414 }
4415 
4416 /** @brief Prepare texture data for the auxiliary texture.
4417  *
4418  *  @tparam D      Texture dimenisons.
4419  *
4420  *  @note parameters as passed to texImage*
4421  *
4422  *  @return False if the internal format is unsupported for online compression, True otherwise
4423  */
4424 template <>
TextureImage(glw::GLint internalformat)4425 bool CompressedSubImageTest::TextureImage<2>(glw::GLint internalformat)
4426 {
4427     /* Shortcut for GL functionality. */
4428     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
4429 
4430     gl.texImage2D(TextureTarget<2>(), 0, internalformat, s_texture_width, s_texture_height, 0, GL_RGBA,
4431                   GL_UNSIGNED_BYTE, s_texture_data);
4432 
4433     /* Online compression may be unsupported for some formats */
4434     GLenum error = gl.getError();
4435     if (error == GL_INVALID_OPERATION)
4436         return false;
4437 
4438     GLU_EXPECT_NO_ERROR(error, "glTexImage2D has failed");
4439 
4440     return true;
4441 }
4442 
4443 /** @brief Prepare texture data for the auxiliary texture.
4444  *
4445  *  @tparam D      Texture dimenisons.
4446  *
4447  *  @note parameters as passed to texImage*
4448  *
4449  *  @return False if the internal format is unsupported for online compression, True otherwise
4450  */
4451 template <>
TextureImage(glw::GLint internalformat)4452 bool CompressedSubImageTest::TextureImage<3>(glw::GLint internalformat)
4453 {
4454     /* Shortcut for GL functionality. */
4455     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
4456 
4457     gl.texImage3D(TextureTarget<3>(), 0, internalformat, s_texture_width, s_texture_height, s_texture_depth, 0, GL_RGBA,
4458                   GL_UNSIGNED_BYTE, s_texture_data);
4459 
4460     /* Online compression may be unsupported for some formats */
4461     GLenum error = gl.getError();
4462     if (error == GL_INVALID_OPERATION)
4463         return false;
4464 
4465     GLU_EXPECT_NO_ERROR(error, "glTexImage3D has failed");
4466 
4467     return true;
4468 }
4469 
4470 /** @brief Prepare texture data for the auxiliary texture.
4471  *
4472  *  @tparam D      Texture dimensions.
4473  *
4474  *  @note parameters as passed to compressedTexImage*
4475  */
4476 template <>
CompressedTexImage(glw::GLint internalformat)4477 void CompressedSubImageTest::CompressedTexImage<1>(glw::GLint internalformat)
4478 {
4479     /* Shortcut for GL functionality. */
4480     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
4481 
4482     gl.compressedTexImage1D(TextureTarget<1>(), 0, internalformat, s_texture_width, 0, m_reference_size,
4483                             m_compressed_texture_data);
4484     GLU_EXPECT_NO_ERROR(gl.getError(), "glCompressedTexImage1D has failed");
4485 }
4486 
4487 /** @brief Prepare texture data for the auxiliary texture.
4488  *
4489  *  @tparam D      Texture dimensions.
4490  *
4491  *  @note parameters as passed to compressedTexImage*
4492  */
4493 template <>
CompressedTexImage(glw::GLint internalformat)4494 void CompressedSubImageTest::CompressedTexImage<2>(glw::GLint internalformat)
4495 {
4496     /* Shortcut for GL functionality. */
4497     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
4498 
4499     gl.compressedTexImage2D(TextureTarget<2>(), 0, internalformat, s_texture_width, s_texture_height, 0,
4500                             m_reference_size, m_compressed_texture_data);
4501     GLU_EXPECT_NO_ERROR(gl.getError(), "glCompressedTexImage2D has failed");
4502 }
4503 
4504 /** @brief Prepare texture data for the auxiliary texture.
4505  *
4506  *  @tparam D      Texture dimensions.
4507  *
4508  *  @note parameters as passed to compressedTexImage*
4509  */
4510 template <>
CompressedTexImage(glw::GLint internalformat)4511 void CompressedSubImageTest::CompressedTexImage<3>(glw::GLint internalformat)
4512 {
4513     /* Shortcut for GL functionality. */
4514     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
4515 
4516     gl.compressedTexImage3D(TextureTarget<3>(), 0, internalformat, s_texture_width, s_texture_height, s_texture_depth,
4517                             0, m_reference_size, m_compressed_texture_data);
4518     GLU_EXPECT_NO_ERROR(gl.getError(), "glCompressedTexImage3D has failed");
4519 }
4520 
4521 /** @brief Prepare texture data for the compressed texture.
4522  *
4523  *  @tparam D      Texture dimenisons.
4524  *
4525  *  @return True if tested function succeeded, false otherwise.
4526  */
4527 template <>
CompressedTextureSubImage(glw::GLint internalformat)4528 bool CompressedSubImageTest::CompressedTextureSubImage<1>(glw::GLint internalformat)
4529 {
4530     /* Shortcut for GL functionality. */
4531     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
4532 
4533     /* Load texture image with tested function. */
4534     if (m_reference_size)
4535     {
4536         for (glw::GLuint block = 0; block < s_block_count; ++block)
4537         {
4538             gl.compressedTextureSubImage1D(m_to, 0, s_texture_width * block, s_texture_width, internalformat,
4539                                            m_reference_size, m_compressed_texture_data);
4540         }
4541     }
4542     else
4543     {
4544         /* For 1D version there is no specific compressed texture internal format spcified in OpenGL 4.5 core profile documentation.
4545          Only implementation depended specific internalformats may provide this functionality. As a result there may be no reference data to be substituted.
4546          Due to this reason there is no use of CompressedTextureSubImage1D and particulary it cannot be tested. */
4547         return true;
4548     }
4549 
4550     /* Check errors. */
4551     glw::GLenum error;
4552 
4553     if (GL_NO_ERROR != (error = gl.getError()))
4554     {
4555         m_context.getTestContext().getLog()
4556             << tcu::TestLog::Message << "glCompressedTextureSubImage1D unexpectedly generated error "
4557             << glu::getErrorStr(error) << " during the test with internal format "
4558             << glu::getTextureFormatStr(internalformat) << ". Test fails." << tcu::TestLog::EndMessage;
4559 
4560         return false;
4561     }
4562 
4563     return true;
4564 }
4565 
4566 /** @brief Prepare texture data for the compressed texture.
4567  *
4568  *  @tparam D      Texture dimenisons.
4569  *
4570  *  @param [in] internalformat      Texture internal format.
4571  *
4572  *  @return True if tested function succeeded, false otherwise.
4573  */
4574 template <>
CompressedTextureSubImage(glw::GLint internalformat)4575 bool CompressedSubImageTest::CompressedTextureSubImage<2>(glw::GLint internalformat)
4576 {
4577     /* Shortcut for GL functionality. */
4578     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
4579 
4580     for (glw::GLuint y = 0; y < s_block_2d_size_y; ++y)
4581     {
4582         for (glw::GLuint x = 0; x < s_block_2d_size_x; ++x)
4583         {
4584             /* Load texture image with tested function. */
4585             gl.compressedTextureSubImage2D(m_to, 0, s_texture_width * x, s_texture_height * y, s_texture_width,
4586                                            s_texture_height, internalformat, m_reference_size,
4587                                            m_compressed_texture_data);
4588         }
4589     }
4590     /* Check errors. */
4591     glw::GLenum error;
4592 
4593     if (GL_NO_ERROR != (error = gl.getError()))
4594     {
4595         m_context.getTestContext().getLog()
4596             << tcu::TestLog::Message << "glCompressedTextureSubImage2D unexpectedly generated error "
4597             << glu::getErrorStr(error) << " during the test with internal format "
4598             << glu::getTextureFormatStr(internalformat) << ". Test fails." << tcu::TestLog::EndMessage;
4599 
4600         return false;
4601     }
4602 
4603     return true;
4604 }
4605 
4606 /** @brief Prepare texture data for the compressed texture.
4607  *
4608  *  @tparam D      Texture dimenisons.
4609  *
4610  *  @param [in] internalformat      Texture internal format.
4611  *
4612  *  @return True if tested function succeeded, false otherwise.
4613  */
4614 template <>
CompressedTextureSubImage(glw::GLint internalformat)4615 bool CompressedSubImageTest::CompressedTextureSubImage<3>(glw::GLint internalformat)
4616 {
4617     /* Shortcut for GL functionality. */
4618     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
4619 
4620     for (glw::GLuint z = 0; z < s_block_3d_size; ++z)
4621     {
4622         for (glw::GLuint y = 0; y < s_block_3d_size; ++y)
4623         {
4624             for (glw::GLuint x = 0; x < s_block_3d_size; ++x)
4625             {
4626                 /* Load texture image with tested function. */
4627                 gl.compressedTextureSubImage3D(m_to, 0, s_texture_width * x, s_texture_height * y, s_texture_depth * z,
4628                                                s_texture_width, s_texture_height, s_texture_depth, internalformat,
4629                                                m_reference_size, m_compressed_texture_data);
4630             }
4631         }
4632     }
4633 
4634     /* Check errors. */
4635     glw::GLenum error;
4636 
4637     if (GL_NO_ERROR != (error = gl.getError()))
4638     {
4639         m_context.getTestContext().getLog()
4640             << tcu::TestLog::Message << "glCompressedTextureSubImage2D unexpectedly generated error "
4641             << glu::getErrorStr(error) << " during the test with internal format "
4642             << glu::getTextureFormatStr(internalformat) << ". Test fails." << tcu::TestLog::EndMessage;
4643 
4644         return false;
4645     }
4646     return true;
4647 }
4648 
4649 struct CompressedData
4650 {
4651     glw::GLenum iformat;
4652     const unsigned char *data;
4653     int data_size;
4654     int dimensions;
4655 };
4656 
4657 static CompressedData compressed_images[] = {
4658     /* 2D images */
4659 
4660     {GL_COMPRESSED_RED_RGTC1, data_0x8dbb_2D_8, sizeof data_0x8dbb_2D_8, 2},
4661     {GL_COMPRESSED_SIGNED_RED_RGTC1, data_0x8dbc_2D_8, sizeof data_0x8dbc_2D_8, 2},
4662     {GL_COMPRESSED_RG_RGTC2, data_0x8dbd_2D_16, sizeof data_0x8dbd_2D_16, 2},
4663     {GL_COMPRESSED_SIGNED_RG_RGTC2, data_0x8dbe_2D_16, sizeof data_0x8dbe_2D_16, 2},
4664     {GL_COMPRESSED_RGBA_BPTC_UNORM, data_0x8e8c_2D_16, sizeof data_0x8e8c_2D_16, 2},
4665     {GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM, data_0x8e8d_2D_16, sizeof data_0x8e8d_2D_16, 2},
4666     {GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT, data_0x8e8e_2D_16, sizeof data_0x8e8e_2D_16, 2},
4667     {GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT, data_0x8e8f_2D_16, sizeof data_0x8e8f_2D_16, 2},
4668     {GL_COMPRESSED_RGB8_ETC2, data_GL_COMPRESSED_RGB8_ETC2_2D_8, sizeof data_GL_COMPRESSED_RGB8_ETC2_2D_8, 2},
4669     {GL_COMPRESSED_SRGB8_ETC2, data_GL_COMPRESSED_SRGB8_ETC2_2D_8, sizeof data_GL_COMPRESSED_SRGB8_ETC2_2D_8, 2},
4670     {GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, data_GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2_2D_8,
4671      sizeof data_GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2_2D_8, 2},
4672     {GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, data_GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2_2D_8,
4673      sizeof data_GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2_2D_8, 2},
4674     {GL_COMPRESSED_RGBA8_ETC2_EAC, data_GL_COMPRESSED_RGBA8_ETC2_EAC_2D_16,
4675      sizeof data_GL_COMPRESSED_RGBA8_ETC2_EAC_2D_16, 2},
4676     {GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, data_GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC_2D_16,
4677      sizeof data_GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC_2D_16, 2},
4678     {GL_COMPRESSED_R11_EAC, data_GL_COMPRESSED_R11_EAC_2D_8, sizeof data_GL_COMPRESSED_R11_EAC_2D_8, 2},
4679     {GL_COMPRESSED_SIGNED_R11_EAC, data_GL_COMPRESSED_SIGNED_R11_EAC_2D_8,
4680      sizeof data_GL_COMPRESSED_SIGNED_R11_EAC_2D_8, 2},
4681     {GL_COMPRESSED_RG11_EAC, data_GL_COMPRESSED_RG11_EAC_2D_16, sizeof data_GL_COMPRESSED_SIGNED_RG11_EAC_2D_16, 2},
4682     {GL_COMPRESSED_SIGNED_RG11_EAC, data_GL_COMPRESSED_SIGNED_RG11_EAC_2D_16,
4683      sizeof data_GL_COMPRESSED_SIGNED_RG11_EAC_2D_16, 2},
4684 
4685     /* 3D images */
4686 
4687     {0x8dbb, data_0x8dbb_3D_32, sizeof data_0x8dbb_3D_32, 3},
4688     {0x8dbc, data_0x8dbc_3D_32, sizeof data_0x8dbc_3D_32, 3},
4689     {0x8dbd, data_0x8dbd_3D_64, sizeof data_0x8dbd_3D_64, 3},
4690     {0x8dbe, data_0x8dbe_3D_64, sizeof data_0x8dbe_3D_64, 3},
4691     {0x8e8c, data_0x8e8c_3D_64, sizeof data_0x8e8c_3D_64, 3},
4692     {0x8e8d, data_0x8e8d_3D_64, sizeof data_0x8e8d_3D_64, 3},
4693     {0x8e8e, data_0x8e8e_3D_64, sizeof data_0x8e8e_3D_64, 3},
4694     {0x8e8f, data_0x8e8f_3D_64, sizeof data_0x8e8f_3D_64, 3},
4695     {GL_COMPRESSED_RGB8_ETC2, data_GL_COMPRESSED_RGB8_ETC2_3D_32, sizeof data_GL_COMPRESSED_RGB8_ETC2_3D_32, 3},
4696     {GL_COMPRESSED_SRGB8_ETC2, data_GL_COMPRESSED_SRGB8_ETC2_3D_32, sizeof data_GL_COMPRESSED_SRGB8_ETC2_3D_32, 3},
4697     {GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, data_GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2_3D_32,
4698      sizeof data_GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2_3D_32, 3},
4699     {GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, data_GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2_3D_32,
4700      sizeof data_GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2_3D_32, 3},
4701     {GL_COMPRESSED_R11_EAC, data_GL_COMPRESSED_R11_EAC_3D_32, sizeof data_GL_COMPRESSED_R11_EAC_3D_32, 3},
4702     {GL_COMPRESSED_SIGNED_R11_EAC, data_GL_COMPRESSED_SIGNED_R11_EAC_3D_32,
4703      sizeof data_GL_COMPRESSED_SIGNED_R11_EAC_3D_32, 3},
4704 
4705     {GL_COMPRESSED_RGBA8_ETC2_EAC, data_GL_COMPRESSED_RGBA8_ETC2_EAC_3D_64,
4706      sizeof data_GL_COMPRESSED_RGBA8_ETC2_EAC_3D_64, 3},
4707     {GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, data_GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC_3D_64,
4708      sizeof data_GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC_3D_64, 3},
4709     {GL_COMPRESSED_RG11_EAC, data_GL_COMPRESSED_RG11_EAC_3D_64, sizeof data_GL_COMPRESSED_RG11_EAC_3D_64, 3},
4710     {GL_COMPRESSED_SIGNED_RG11_EAC, data_GL_COMPRESSED_SIGNED_RG11_EAC_3D_64,
4711      sizeof data_GL_COMPRESSED_SIGNED_RG11_EAC_3D_64, 3}};
4712 
4713 /** @brief Prepare the reference data.
4714  *
4715  *  @tparam D      Texture dimenisons.
4716  *
4717  *  @return False if the internal format is unsupported for online compression, True otherwise
4718  */
4719 template <glw::GLuint D>
PrepareReferenceData(glw::GLenum internalformat)4720 bool CompressedSubImageTest::PrepareReferenceData(glw::GLenum internalformat)
4721 {
4722     /* Shortcut for GL functionality. */
4723     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
4724 
4725     /* Using OpenGL to compress raw data. */
4726     gl.bindTexture(TextureTarget<D>(), m_to_aux);
4727     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4728 
4729     glw::GLint is_compressed_texture   = 0;
4730     glw::GLint compressed_texture_size = 0;
4731 
4732     /* Quick checks. */
4733     if ((DE_NULL != m_reference) || (DE_NULL != m_compressed_texture_data))
4734     {
4735         throw 0;
4736     }
4737 
4738     /* "if" path is taken when there is no support for online compression for the format
4739      * and we upload compressed data directly */
4740     if (!TextureImage<D>(internalformat))
4741     {
4742         for (unsigned int i = 0; i < sizeof compressed_images / sizeof *compressed_images; i++)
4743         {
4744             if (internalformat == compressed_images[i].iformat && D == compressed_images[i].dimensions)
4745             {
4746                 is_compressed_texture   = 1;
4747                 compressed_texture_size = compressed_images[i].data_size;
4748 
4749                 m_reference_size           = compressed_texture_size;
4750                 m_reference_internalformat = compressed_images[i].iformat;
4751 
4752                 m_reference               = new glw::GLubyte[compressed_texture_size];
4753                 m_compressed_texture_data = new glw::GLubyte[compressed_texture_size];
4754 
4755                 memcpy(m_reference, compressed_images[i].data, compressed_texture_size);
4756                 memcpy(m_compressed_texture_data, compressed_images[i].data, compressed_texture_size);
4757             }
4758         }
4759 
4760         if (!is_compressed_texture)
4761             return false;
4762 
4763         PrepareCompressedStorage<D>(m_reference_internalformat);
4764     }
4765     else
4766     {
4767         /* Check that really compressed texture. */
4768         gl.getTexLevelParameteriv(TextureTarget<D>(), 0, GL_TEXTURE_COMPRESSED, &is_compressed_texture);
4769 
4770         if (is_compressed_texture)
4771         {
4772             /* Query texture size. */
4773             gl.getTexLevelParameteriv(TextureTarget<D>(), 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
4774                                       &compressed_texture_size);
4775 
4776             /* If compressed then download. */
4777             if (compressed_texture_size)
4778             {
4779                 /* Prepare storage. */
4780                 m_compressed_texture_data = new glw::GLubyte[compressed_texture_size];
4781 
4782                 if (DE_NULL != m_compressed_texture_data)
4783                 {
4784                     m_reference_size = compressed_texture_size;
4785                 }
4786                 else
4787                 {
4788                     throw 0;
4789                 }
4790 
4791                 /* Download the source compressed texture image. */
4792                 gl.getCompressedTexImage(TextureTarget<D>(), 0, m_compressed_texture_data);
4793                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
4794 
4795                 // Upload the source compressed texture image to the texture object.
4796                 // Some compressed texture format can be emulated by the driver (like the ETC2/EAC formats)
4797                 // The compressed data sent by CompressedTexImage will be stored uncompressed by the driver
4798                 // and will be re-compressed if the application call glGetCompressedTexImage.
4799                 // The compression/decompression is not lossless, so when this happen it's possible for the source
4800                 // and destination (from glGetCompressedTexImage) compressed data to be different.
4801                 // To avoid that we will store both the source (in m_compressed_texture_data) and the destination
4802                 // (in m_reference). The destination will be used later to make sure getCompressedTextureSubImage
4803                 // return the expected value
4804                 CompressedTexImage<D>(internalformat);
4805 
4806                 m_reference = new glw::GLubyte[m_reference_size];
4807 
4808                 if (DE_NULL == m_reference)
4809                 {
4810                     throw 0;
4811                 }
4812 
4813                 /* Download compressed texture image. */
4814                 gl.getCompressedTexImage(TextureTarget<D>(), 0, m_reference);
4815                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
4816             }
4817         }
4818 
4819         PrepareStorage<D>(internalformat);
4820     }
4821 
4822     return true;
4823 }
4824 
4825 /** @brief Prepare texture storage.
4826  *
4827  *  @tparam D      Texture dimenisons.
4828  *
4829  *  @param [in] internalformat      Texture internal format.
4830  */
4831 template <>
PrepareStorage(glw::GLenum internalformat)4832 void CompressedSubImageTest::PrepareStorage<1>(glw::GLenum internalformat)
4833 {
4834     /* Shortcut for GL functionality. */
4835     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
4836 
4837     gl.bindTexture(TextureTarget<1>(), m_to);
4838     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4839 
4840     gl.texImage1D(TextureTarget<1>(), 0, internalformat, s_texture_width * s_block_count, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4841                   NULL);
4842     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
4843 }
4844 
4845 /** @brief Prepare texture storage.
4846  *
4847  *  @tparam D      Texture dimenisons.
4848  *
4849  *  @param [in] internalformat      Texture internal format.
4850  */
4851 template <>
PrepareStorage(glw::GLenum internalformat)4852 void CompressedSubImageTest::PrepareStorage<2>(glw::GLenum internalformat)
4853 {
4854     /* Shortcut for GL functionality. */
4855     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
4856 
4857     gl.bindTexture(TextureTarget<2>(), m_to);
4858     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4859 
4860     gl.texImage2D(TextureTarget<2>(), 0, internalformat, s_texture_width * s_block_2d_size_x,
4861                   s_texture_height * s_block_2d_size_y, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
4862     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
4863 }
4864 
4865 /** @brief Prepare texture storage.
4866  *
4867  *  @tparam D      Texture dimenisons.
4868  *
4869  *  @param [in] internalformat      Texture internal format.
4870  */
4871 template <>
PrepareStorage(glw::GLenum internalformat)4872 void CompressedSubImageTest::PrepareStorage<3>(glw::GLenum internalformat)
4873 {
4874     /* Shortcut for GL functionality. */
4875     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
4876 
4877     gl.bindTexture(TextureTarget<3>(), m_to);
4878     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4879 
4880     gl.texImage3D(TextureTarget<3>(), 0, internalformat, s_texture_width * s_block_3d_size,
4881                   s_texture_height * s_block_3d_size, s_texture_depth * s_block_3d_size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4882                   NULL);
4883     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
4884 }
4885 
4886 /** @brief Prepare compressed texture storage.
4887  * @tparam D        Texture dimensions.
4888  *
4889  * @tparam [in] internalformat        Texture internal format.
4890  */
4891 template <>
PrepareCompressedStorage(glw::GLenum internalformat)4892 void CompressedSubImageTest::PrepareCompressedStorage<1>(glw::GLenum internalformat)
4893 {
4894     /* Shortcut for GL functionality */
4895     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
4896 
4897     gl.bindTexture(TextureTarget<1>(), m_to);
4898     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4899 
4900     gl.compressedTexImage1D(TextureTarget<1>(), 0, internalformat, s_texture_width * s_block_count, 0,
4901                             s_texture_width * s_block_count, 0);
4902     GLU_EXPECT_NO_ERROR(gl.getError(), "glCompressedTexImage1D has failed");
4903 }
4904 
4905 /** @brief Prepare compressed texture storage.
4906  * @tparam D        Texture dimensions.
4907  *
4908  * @tparam [in] internalformat        Texture internal format.
4909  */
4910 template <>
PrepareCompressedStorage(glw::GLenum internalformat)4911 void CompressedSubImageTest::PrepareCompressedStorage<2>(glw::GLenum internalformat)
4912 {
4913     /* Shortcut for GL functionality */
4914     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
4915 
4916     gl.bindTexture(TextureTarget<2>(), m_to);
4917     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4918 
4919     GLsizei size_x = s_texture_width * s_block_2d_size_x;
4920     GLsizei size_y = s_texture_height * s_block_2d_size_y;
4921     GLsizei size   = m_reference_size * s_block_2d_size_x * s_block_2d_size_y;
4922 
4923     gl.compressedTexImage2D(TextureTarget<2>(), 0, internalformat, size_x, size_y, 0, size, 0);
4924     GLU_EXPECT_NO_ERROR(gl.getError(), "glCompressedTexImage2D has failed");
4925 }
4926 
4927 /** @brief Prepare compressed texture storage.
4928  * @tparam D        Texture dimensions.
4929  *
4930  * @tparam [in] internalformat        Texture internal format.
4931  */
4932 template <>
PrepareCompressedStorage(glw::GLenum internalformat)4933 void CompressedSubImageTest::PrepareCompressedStorage<3>(glw::GLenum internalformat)
4934 {
4935     /* Shortcut for GL functionality */
4936     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
4937 
4938     gl.bindTexture(TextureTarget<3>(), m_to);
4939     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
4940 
4941     GLsizei size_x = s_texture_width * s_block_3d_size;
4942     GLsizei size_y = s_texture_height * s_block_3d_size;
4943     GLsizei size_z = s_texture_depth * s_block_3d_size;
4944     GLsizei size   = m_reference_size * s_block_3d_size * s_block_3d_size * s_block_3d_size;
4945 
4946     gl.compressedTexImage3D(TextureTarget<3>(), 0, internalformat, size_x, size_y, size_z, 0, size, 0);
4947     GLU_EXPECT_NO_ERROR(gl.getError(), "glCompressedTexImage3D has failed");
4948 }
4949 
4950 /** @brief Compare results with the reference.
4951  *
4952  *  @tparam T      Type.
4953  *  @tparam S      Size (# of components).
4954  *  @tparam N      Is normalized.
4955  *
4956  *  @param [in] internalformat      Texture internal format.
4957  *
4958  *  @return True if equal, false otherwise.
4959  */
4960 template <glw::GLuint D>
CheckData(glw::GLenum internalformat)4961 bool CompressedSubImageTest::CheckData(glw::GLenum internalformat)
4962 {
4963     /* Shortcut for GL functionality. */
4964     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
4965 
4966     /* Check texture content with reference. */
4967     m_result = new glw::GLubyte[m_reference_size * s_block_count];
4968 
4969     if (DE_NULL == m_result)
4970     {
4971         throw 0;
4972     }
4973 
4974     gl.getCompressedTexImage(TextureTarget<D>(), 0, m_result);
4975     GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
4976     for (glw::GLuint block = 0; block < s_block_count; ++block)
4977     {
4978         for (glw::GLuint i = 0; i < m_reference_size; ++i)
4979         {
4980             if (m_reference[i] != m_result[block * m_reference_size + i])
4981             {
4982                 m_context.getTestContext().getLog()
4983                     << tcu::TestLog::Message << "glCompressedTextureSubImage*D created texture with data "
4984                     << DataToString(m_reference_size, m_reference) << " however texture contains data "
4985                     << DataToString(m_reference_size, &(m_result[block * m_reference_size])) << ". Texture target was "
4986                     << glu::getTextureTargetStr(TextureTarget<D>()) << " and internal format was "
4987                     << glu::getTextureFormatStr(internalformat) << ". Test fails." << tcu::TestLog::EndMessage;
4988 
4989                 return false;
4990             }
4991         }
4992     }
4993 
4994     return true;
4995 }
4996 
4997 /** @brief Compare results with the reference.
4998  *
4999  *  @tparam T      Type.
5000  *  @tparam S      Size (# of components).
5001  *  @tparam N      Is normalized.
5002  *
5003  *  @param [in] internalformat      Texture internal format.
5004  *
5005  *  @return True if equal, false otherwise.
5006  */
5007 template <>
CheckData(glw::GLenum internalformat)5008 bool CompressedSubImageTest::CheckData<3>(glw::GLenum internalformat)
5009 {
5010     /* Shortcut for GL functionality. */
5011     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
5012 
5013     /* Check texture content with reference. */
5014     m_result = new glw::GLubyte[m_reference_size * s_block_count];
5015 
5016     if (DE_NULL == m_result)
5017     {
5018         throw 0;
5019     }
5020 
5021     gl.getCompressedTexImage(TextureTarget<3>(), 0, m_result);
5022     GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
5023 
5024     glw::GLuint reference_layer_size = m_reference_size / s_texture_depth;
5025 
5026     for (glw::GLuint i = 0; i < m_reference_size * s_block_count; ++i)
5027     {
5028         // we will read the result one bytes at the time and compare with the reference
5029         // for each bytes of the result image we need to figure out which byte in the reference image it corresponds to
5030         glw::GLuint refIdx      = i % reference_layer_size;
5031         glw::GLuint refLayerIdx = (i / (reference_layer_size * s_block_3d_size * s_block_3d_size)) % s_texture_depth;
5032         if (m_reference[refLayerIdx * reference_layer_size + refIdx] != m_result[i])
5033         {
5034             m_context.getTestContext().getLog()
5035                 << tcu::TestLog::Message << "glCompressedTextureSubImage3D created texture with data "
5036                 << DataToString(reference_layer_size, &(m_reference[refLayerIdx * reference_layer_size]))
5037                 << " however texture contains data "
5038                 << DataToString(reference_layer_size, &(m_result[i % reference_layer_size])) << ". Texture target was "
5039                 << glu::getTextureTargetStr(TextureTarget<3>()) << " and internal format was "
5040                 << glu::getTextureFormatStr(internalformat) << ". Test fails." << tcu::TestLog::EndMessage;
5041 
5042             return false;
5043         }
5044     }
5045 
5046     return true;
5047 }
5048 /** @brief Test case function.
5049  *
5050  *  @tparam D       Number of texture dimensions.
5051  *
5052  *  @param [in] internal format     Texture internal format.
5053  *
5054  *  @param [in] can be unsupported     If the format may not support online compression
5055  *
5056  *  @return True if test succeeded, false otherwise.
5057  */
5058 template <glw::GLuint D>
Test(glw::GLenum internalformat,bool can_be_unsupported)5059 bool CompressedSubImageTest::Test(glw::GLenum internalformat, bool can_be_unsupported)
5060 {
5061     /* Create texture image. */
5062     CreateTextures(TextureTarget<D>());
5063 
5064     if (!PrepareReferenceData<D>(internalformat))
5065     {
5066         CleanAll();
5067         return can_be_unsupported;
5068     }
5069 
5070     /* Setup data with CompressedTextureSubImage<D>D function and check for errors. */
5071     if (!CompressedTextureSubImage<D>(internalformat))
5072     {
5073         CleanAll();
5074 
5075         return false;
5076     }
5077 
5078     /* If compressed reference data was generated than compare values. */
5079     if (m_reference)
5080     {
5081         if (!CheckData<D>(internalformat))
5082         {
5083             CleanAll();
5084 
5085             return false;
5086         }
5087     }
5088 
5089     CleanAll();
5090 
5091     return true;
5092 }
5093 
5094 /** @brief Clean GL objects, test variables and GL errors.
5095  */
CleanAll()5096 void CompressedSubImageTest::CleanAll()
5097 {
5098     /* Shortcut for GL functionality. */
5099     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
5100 
5101     /* Textures. */
5102     if (m_to)
5103     {
5104         gl.deleteTextures(1, &m_to);
5105 
5106         m_to = 0;
5107     }
5108 
5109     if (m_to_aux)
5110     {
5111         gl.deleteTextures(1, &m_to_aux);
5112 
5113         m_to_aux = 0;
5114     }
5115 
5116     /* Reference data storage. */
5117     if (DE_NULL != m_reference)
5118     {
5119         delete[] m_reference;
5120 
5121         m_reference = DE_NULL;
5122     }
5123 
5124     if (DE_NULL != m_compressed_texture_data)
5125     {
5126         delete[] m_compressed_texture_data;
5127 
5128         m_compressed_texture_data = DE_NULL;
5129     }
5130 
5131     if (DE_NULL != m_result)
5132     {
5133         delete[] m_result;
5134 
5135         m_result = DE_NULL;
5136     }
5137 
5138     m_reference_size = 0;
5139 
5140     /* Errors. */
5141     while (GL_NO_ERROR != gl.getError())
5142         ;
5143 }
5144 
5145 /** @brief Convert raw data into string for logging purposes.
5146  *
5147  *  @param [in] count      Count of the data.
5148  *  @param [in] data       Raw data.
5149  *
5150  *  @return String representation of data.
5151  */
DataToString(glw::GLuint count,const glw::GLubyte data[])5152 std::string CompressedSubImageTest::DataToString(glw::GLuint count, const glw::GLubyte data[])
5153 {
5154     std::string data_str = "[";
5155 
5156     for (glw::GLuint i = 0; i < count; ++i)
5157     {
5158         std::stringstream int_sstream;
5159 
5160         int_sstream << unsigned(data[i]);
5161 
5162         data_str.append(int_sstream.str());
5163 
5164         if (i + 1 < count)
5165         {
5166             data_str.append(", ");
5167         }
5168         else
5169         {
5170             data_str.append("]");
5171         }
5172     }
5173 
5174     return data_str;
5175 }
5176 
5177 /** @brief Iterate Compressed SubImage Test cases.
5178  *
5179  *  @return Iteration result.
5180  */
iterate()5181 tcu::TestNode::IterateResult CompressedSubImageTest::iterate()
5182 {
5183     /* Shortcut for GL functionality. */
5184     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
5185 
5186     /* Get context setup. */
5187     bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
5188     bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
5189 
5190     if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
5191     {
5192         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
5193 
5194         return STOP;
5195     }
5196 
5197     /* Running tests. */
5198     bool is_ok    = true;
5199     bool is_error = false;
5200 
5201     try
5202     {
5203         is_ok &= Test<1>(GL_COMPRESSED_RGB, false);
5204 
5205         is_ok &= Test<2>(GL_COMPRESSED_RED_RGTC1, false);
5206         is_ok &= Test<2>(GL_COMPRESSED_SIGNED_RED_RGTC1, false);
5207         is_ok &= Test<2>(GL_COMPRESSED_RG_RGTC2, false);
5208         is_ok &= Test<2>(GL_COMPRESSED_SIGNED_RG_RGTC2, false);
5209         is_ok &= Test<2>(GL_COMPRESSED_RGBA_BPTC_UNORM, false);
5210         is_ok &= Test<2>(GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM, false);
5211         is_ok &= Test<2>(GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT, false);
5212         is_ok &= Test<2>(GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT, false);
5213         is_ok &= Test<2>(GL_COMPRESSED_RGB8_ETC2, true);
5214         is_ok &= Test<2>(GL_COMPRESSED_SRGB8_ETC2, true);
5215         is_ok &= Test<2>(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, true);
5216         is_ok &= Test<2>(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, true);
5217         is_ok &= Test<2>(GL_COMPRESSED_RGBA8_ETC2_EAC, true);
5218         is_ok &= Test<2>(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, true);
5219         is_ok &= Test<2>(GL_COMPRESSED_R11_EAC, true);
5220         is_ok &= Test<2>(GL_COMPRESSED_SIGNED_R11_EAC, true);
5221         is_ok &= Test<2>(GL_COMPRESSED_RG11_EAC, true);
5222         is_ok &= Test<2>(GL_COMPRESSED_SIGNED_RG11_EAC, true);
5223 
5224         is_ok &= Test<3>(GL_COMPRESSED_RED_RGTC1, false);
5225         is_ok &= Test<3>(GL_COMPRESSED_SIGNED_RED_RGTC1, false);
5226         is_ok &= Test<3>(GL_COMPRESSED_RG_RGTC2, false);
5227         is_ok &= Test<3>(GL_COMPRESSED_SIGNED_RG_RGTC2, false);
5228         is_ok &= Test<3>(GL_COMPRESSED_RGBA_BPTC_UNORM, false);
5229         is_ok &= Test<3>(GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM, false);
5230         is_ok &= Test<3>(GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT, false);
5231         is_ok &= Test<3>(GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT, false);
5232         is_ok &= Test<3>(GL_COMPRESSED_RGB8_ETC2, true);
5233         is_ok &= Test<3>(GL_COMPRESSED_SRGB8_ETC2, true);
5234         is_ok &= Test<3>(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, true);
5235         is_ok &= Test<3>(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, true);
5236         is_ok &= Test<3>(GL_COMPRESSED_RGBA8_ETC2_EAC, true);
5237         is_ok &= Test<3>(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, true);
5238         is_ok &= Test<3>(GL_COMPRESSED_R11_EAC, true);
5239         is_ok &= Test<3>(GL_COMPRESSED_SIGNED_R11_EAC, true);
5240         is_ok &= Test<3>(GL_COMPRESSED_RG11_EAC, true);
5241         is_ok &= Test<3>(GL_COMPRESSED_SIGNED_RG11_EAC, true);
5242     }
5243     catch (...)
5244     {
5245         is_ok    = false;
5246         is_error = true;
5247     }
5248 
5249     /* Cleanup. */
5250     CleanAll();
5251 
5252     /* Errors clean up. */
5253     while (gl.getError())
5254         ;
5255 
5256     /* Result's setup. */
5257     if (is_ok)
5258     {
5259         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
5260     }
5261     else
5262     {
5263         if (is_error)
5264         {
5265             m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
5266         }
5267         else
5268         {
5269             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
5270         }
5271     }
5272 
5273     return STOP;
5274 }
5275 
5276 /** Reference data. */
5277 const glw::GLubyte CompressedSubImageTest::s_texture_data[] = {
5278     0x00, 0x00, 0x00, 0xFF, 0x7f, 0x7f, 0x7f, 0x00, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0x00,
5279     0x88, 0x00, 0x15, 0xFF, 0xed, 0x1c, 0x24, 0x00, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x00, 0x00,
5280     0xc8, 0xbf, 0xe7, 0xFF, 0x70, 0x92, 0xbe, 0x00, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0x00,
5281     0xa3, 0x49, 0xa4, 0xFF, 0x3f, 0x48, 0xcc, 0x00, 0x00, 0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0x00,
5282 
5283     0xa3, 0x49, 0xa4, 0xFF, 0xc8, 0xbf, 0xe7, 0x00, 0x88, 0x00, 0x15, 0xff, 0x00, 0x00, 0x00, 0x00,
5284     0x3f, 0x48, 0xcc, 0xFF, 0x70, 0x92, 0xbe, 0x00, 0xed, 0x1c, 0x24, 0xff, 0x7f, 0x7f, 0x7f, 0x00,
5285     0x00, 0xa2, 0xe8, 0xFF, 0x99, 0xd9, 0xea, 0x00, 0xff, 0x7f, 0x27, 0xff, 0xc3, 0xc3, 0xc3, 0x00,
5286     0x22, 0xb1, 0x4c, 0xFF, 0xb5, 0xe6, 0x1d, 0x00, 0xff, 0xf2, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00,
5287 
5288     0x22, 0xb1, 0x4c, 0xFF, 0x00, 0xa2, 0xe8, 0x00, 0x3f, 0x48, 0xcc, 0xff, 0xa3, 0x49, 0xa4, 0x00,
5289     0xb5, 0xe6, 0x1d, 0xFF, 0x99, 0xd9, 0xea, 0x00, 0x70, 0x92, 0xbe, 0xff, 0xc8, 0xbf, 0xe7, 0x00,
5290     0xff, 0xf2, 0x00, 0xFF, 0xff, 0x7f, 0x27, 0x00, 0xed, 0x1c, 0x24, 0xff, 0x88, 0x00, 0x15, 0x00,
5291     0xff, 0xff, 0xff, 0xFF, 0xc3, 0xc3, 0xc3, 0x00, 0x7f, 0x7f, 0x7f, 0xff, 0x00, 0x00, 0x00, 0x00,
5292 
5293     0xff, 0xff, 0xff, 0xFF, 0xff, 0xf2, 0x00, 0x00, 0xb5, 0xe6, 0x1d, 0xff, 0x22, 0xb1, 0x4c, 0x00,
5294     0xc3, 0xc3, 0xc3, 0xFF, 0xff, 0x7f, 0x27, 0x00, 0x99, 0xd9, 0xea, 0xff, 0x00, 0xa2, 0xe8, 0x00,
5295     0x7f, 0x7f, 0x7f, 0xFF, 0xed, 0x1c, 0x24, 0x00, 0x70, 0x92, 0xbe, 0xff, 0x3f, 0x48, 0xcc, 0x00,
5296     0x00, 0x00, 0x00, 0xFF, 0x88, 0x00, 0x15, 0x00, 0xc8, 0xbf, 0xe7, 0xff, 0xa3, 0x49, 0xa4, 0x00};
5297 
5298 /** Reference data parameters. */
5299 const glw::GLuint CompressedSubImageTest::s_texture_width   = 4;
5300 const glw::GLuint CompressedSubImageTest::s_texture_height  = 4;
5301 const glw::GLuint CompressedSubImageTest::s_texture_depth   = 4;
5302 const glw::GLuint CompressedSubImageTest::s_block_count     = 8;
5303 const glw::GLuint CompressedSubImageTest::s_block_2d_size_x = 4;
5304 const glw::GLuint CompressedSubImageTest::s_block_2d_size_y = 2;
5305 const glw::GLuint CompressedSubImageTest::s_block_3d_size   = 2;
5306 
5307 /******************************** Copy SubImage Test Implementation   ********************************/
5308 
5309 /** @brief Compressed SubImage Test constructor.
5310  *
5311  *  @param [in] context     OpenGL context.
5312  */
CopyTest(deqp::Context & context)5313 CopyTest::CopyTest(deqp::Context &context)
5314     : deqp::TestCase(context, "textures_copy", "Texture Copy Test")
5315     , m_fbo(0)
5316     , m_to_src(0)
5317     , m_to_dst(0)
5318     , m_result(DE_NULL)
5319 {
5320     /* Intentionally left blank. */
5321 }
5322 
5323 /** @brief Texture target selector.
5324  *
5325  *  @tparam D      Texture dimenisons.
5326  *
5327  *  @return Texture target.
5328  */
5329 template <>
TextureTarget()5330 glw::GLenum CopyTest::TextureTarget<1>()
5331 {
5332     return GL_TEXTURE_1D;
5333 }
5334 template <>
TextureTarget()5335 glw::GLenum CopyTest::TextureTarget<2>()
5336 {
5337     return GL_TEXTURE_2D;
5338 }
5339 template <>
TextureTarget()5340 glw::GLenum CopyTest::TextureTarget<3>()
5341 {
5342     return GL_TEXTURE_3D;
5343 }
5344 
5345 /** @brief Copy texture, check errors and log.
5346  *
5347  *  @note Parameters as passed to CopyTextureSubImage*D
5348  *
5349  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
5350  */
CopyTextureSubImage1DAndCheckErrors(glw::GLuint texture,glw::GLint level,glw::GLint xoffset,glw::GLint x,glw::GLint y,glw::GLsizei width)5351 bool CopyTest::CopyTextureSubImage1DAndCheckErrors(glw::GLuint texture, glw::GLint level, glw::GLint xoffset,
5352                                                    glw::GLint x, glw::GLint y, glw::GLsizei width)
5353 {
5354     /* Shortcut for GL functionality. */
5355     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
5356 
5357     gl.readBuffer(GL_COLOR_ATTACHMENT0);
5358     GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
5359 
5360     gl.copyTextureSubImage1D(texture, level, xoffset, x, y, width);
5361 
5362     /* Check errors. */
5363     glw::GLenum error;
5364 
5365     if (GL_NO_ERROR != (error = gl.getError()))
5366     {
5367         m_context.getTestContext().getLog()
5368             << tcu::TestLog::Message << "glCopyTextureSubImage1D unexpectedly generated error "
5369             << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
5370 
5371         return false;
5372     }
5373 
5374     return true;
5375 }
5376 
5377 /** @brief Copy texture, check errors and log.
5378  *
5379  *  @note Parameters as passed to CopyTextureSubImage*D
5380  *
5381  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
5382  */
CopyTextureSubImage2DAndCheckErrors(glw::GLuint texture,glw::GLint level,glw::GLint xoffset,glw::GLint yoffset,glw::GLint x,glw::GLint y,glw::GLsizei width,glw::GLsizei height)5383 bool CopyTest::CopyTextureSubImage2DAndCheckErrors(glw::GLuint texture, glw::GLint level, glw::GLint xoffset,
5384                                                    glw::GLint yoffset, glw::GLint x, glw::GLint y, glw::GLsizei width,
5385                                                    glw::GLsizei height)
5386 {
5387     /* Shortcut for GL functionality. */
5388     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
5389 
5390     gl.readBuffer(GL_COLOR_ATTACHMENT0);
5391     GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
5392 
5393     gl.copyTextureSubImage2D(texture, level, xoffset, yoffset, x, y, width, height);
5394 
5395     /* Check errors. */
5396     glw::GLenum error;
5397 
5398     if (GL_NO_ERROR != (error = gl.getError()))
5399     {
5400         m_context.getTestContext().getLog()
5401             << tcu::TestLog::Message << "glCopyTextureSubImage2D unexpectedly generated error "
5402             << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
5403 
5404         return false;
5405     }
5406 
5407     return true;
5408 }
5409 
5410 /** @brief Copy texture, check errors and log.
5411  *
5412  *  @note Parameters as passed to CopyTextureSubImage*D
5413  *
5414  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
5415  */
CopyTextureSubImage3DAndCheckErrors(glw::GLuint texture,glw::GLint level,glw::GLint xoffset,glw::GLint yoffset,glw::GLint zoffset,glw::GLint x,glw::GLint y,glw::GLsizei width,glw::GLsizei height)5416 bool CopyTest::CopyTextureSubImage3DAndCheckErrors(glw::GLuint texture, glw::GLint level, glw::GLint xoffset,
5417                                                    glw::GLint yoffset, glw::GLint zoffset, glw::GLint x, glw::GLint y,
5418                                                    glw::GLsizei width, glw::GLsizei height)
5419 {
5420     /* Shortcut for GL functionality. */
5421     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
5422 
5423     gl.readBuffer(GL_COLOR_ATTACHMENT0 + zoffset);
5424     GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
5425 
5426     gl.copyTextureSubImage3D(texture, level, xoffset, yoffset, zoffset, x, y, width, height);
5427 
5428     /* Check errors. */
5429     glw::GLenum error;
5430 
5431     if (GL_NO_ERROR != (error = gl.getError()))
5432     {
5433         m_context.getTestContext().getLog()
5434             << tcu::TestLog::Message << "glCopyTextureSubImage3D unexpectedly generated error "
5435             << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
5436 
5437         return false;
5438     }
5439 
5440     return true;
5441 }
5442 
5443 /** @brief Create texture.
5444  *
5445  *  @tparam D      Dimmensions.
5446  */
5447 template <>
CreateSourceTexture()5448 void CopyTest::CreateSourceTexture<1>()
5449 {
5450     /* Shortcut for GL functionality. */
5451     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
5452 
5453     gl.genTextures(1, &m_to_src);
5454     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
5455 
5456     gl.bindTexture(TextureTarget<1>(), m_to_src);
5457     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
5458 
5459     gl.texImage1D(TextureTarget<1>(), 0, GL_RGBA8, s_texture_width, 0, GL_RGBA, GL_UNSIGNED_BYTE, s_texture_data);
5460     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed.");
5461 }
5462 
5463 /** @brief Create texture.
5464  *
5465  *  @tparam D      Dimmensions.
5466  */
5467 template <>
CreateSourceTexture()5468 void CopyTest::CreateSourceTexture<2>()
5469 {
5470     /* Shortcut for GL functionality. */
5471     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
5472 
5473     gl.genTextures(1, &m_to_src);
5474     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
5475 
5476     gl.bindTexture(TextureTarget<2>(), m_to_src);
5477     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
5478 
5479     gl.texImage2D(TextureTarget<2>(), 0, GL_RGBA8, s_texture_width, s_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
5480                   s_texture_data);
5481     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed.");
5482 }
5483 
5484 /** @brief Create texture.
5485  *
5486  *  @tparam D      Dimmensions.
5487  */
5488 template <>
CreateSourceTexture()5489 void CopyTest::CreateSourceTexture<3>()
5490 {
5491     /* Shortcut for GL functionality. */
5492     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
5493 
5494     gl.genTextures(1, &m_to_src);
5495     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
5496 
5497     gl.bindTexture(TextureTarget<3>(), m_to_src);
5498     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
5499 
5500     gl.texImage3D(TextureTarget<3>(), 0, GL_RGBA8, s_texture_width, s_texture_height, s_texture_depth, 0, GL_RGBA,
5501                   GL_UNSIGNED_BYTE, s_texture_data);
5502     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed.");
5503 }
5504 
5505 /** @brief Create texture.
5506  *
5507  *  @tparam D      Dimmensions.
5508  */
5509 template <>
CreateDestinationTexture()5510 void CopyTest::CreateDestinationTexture<1>()
5511 {
5512     /* Shortcut for GL functionality. */
5513     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
5514 
5515     gl.genTextures(1, &m_to_dst);
5516     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
5517 
5518     gl.bindTexture(TextureTarget<1>(), m_to_dst);
5519     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
5520 
5521     gl.texImage1D(TextureTarget<1>(), 0, GL_RGBA8, s_texture_width, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
5522     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed.");
5523 }
5524 
5525 /** @brief Create texture.
5526  *
5527  *  @tparam D      Dimmensions.
5528  */
5529 template <>
CreateDestinationTexture()5530 void CopyTest::CreateDestinationTexture<2>()
5531 {
5532     /* Shortcut for GL functionality. */
5533     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
5534 
5535     gl.genTextures(1, &m_to_dst);
5536     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
5537 
5538     gl.bindTexture(TextureTarget<2>(), m_to_dst);
5539     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
5540 
5541     gl.texImage2D(TextureTarget<2>(), 0, GL_RGBA8, s_texture_width, s_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
5542                   DE_NULL);
5543     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed.");
5544 }
5545 
5546 /** @brief Create texture.
5547  *
5548  *  @tparam D      Dimmensions.
5549  */
5550 template <>
CreateDestinationTexture()5551 void CopyTest::CreateDestinationTexture<3>()
5552 {
5553     /* Shortcut for GL functionality. */
5554     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
5555 
5556     gl.genTextures(1, &m_to_dst);
5557     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
5558 
5559     gl.bindTexture(TextureTarget<3>(), m_to_dst);
5560     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
5561 
5562     gl.texImage3D(TextureTarget<3>(), 0, GL_RGBA8, s_texture_width, s_texture_height, s_texture_depth, 0, GL_RGBA,
5563                   GL_UNSIGNED_BYTE, DE_NULL);
5564     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed.");
5565 }
5566 
5567 /** @brief Create framebuffer.
5568  *
5569  *  @tparam D      Dimmensions.
5570  */
5571 template <>
CreateSourceFramebuffer()5572 void CopyTest::CreateSourceFramebuffer<1>()
5573 {
5574     /* Shortcut for GL functionality. */
5575     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
5576 
5577     /* Prepare framebuffer. */
5578     gl.genFramebuffers(1, &m_fbo);
5579     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
5580 
5581     gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
5582     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
5583 
5584     gl.framebufferTexture1D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, TextureTarget<1>(), m_to_src, 0);
5585     GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture1D call failed.");
5586 
5587     if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
5588     {
5589         throw 0;
5590     }
5591 
5592     gl.viewport(0, 0, s_texture_width, 1);
5593     GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
5594 }
5595 
5596 /** @brief Create framebuffer.
5597  *
5598  *  @tparam D      Dimmensions.
5599  */
5600 template <>
CreateSourceFramebuffer()5601 void CopyTest::CreateSourceFramebuffer<2>()
5602 {
5603     /* Shortcut for GL functionality. */
5604     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
5605 
5606     /* Prepare framebuffer. */
5607     gl.genFramebuffers(1, &m_fbo);
5608     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
5609 
5610     gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
5611     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
5612 
5613     gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, TextureTarget<2>(), m_to_src, 0);
5614     GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture1D call failed.");
5615 
5616     if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
5617     {
5618         throw 0;
5619     }
5620 
5621     gl.viewport(0, 0, s_texture_width, s_texture_height);
5622     GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
5623 }
5624 
5625 /** @brief Create framebuffer.
5626  *
5627  *  @tparam D      Dimmensions.
5628  */
5629 template <>
CreateSourceFramebuffer()5630 void CopyTest::CreateSourceFramebuffer<3>()
5631 {
5632     /* Shortcut for GL functionality. */
5633     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
5634 
5635     /* Prepare framebuffer. */
5636     gl.genFramebuffers(1, &m_fbo);
5637     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
5638 
5639     gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
5640     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
5641 
5642     for (glw::GLuint i = 0; i < s_texture_depth; ++i)
5643     {
5644         gl.framebufferTexture3D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, TextureTarget<3>(), m_to_src, 0, i);
5645         GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture1D call failed.");
5646     }
5647 
5648     if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
5649     {
5650         throw 0;
5651     }
5652 
5653     gl.viewport(0, 0, s_texture_width, s_texture_height);
5654     GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
5655 }
5656 
5657 /** @brief Dispatch function to create test objects */
5658 template <glw::GLuint D>
CreateAll()5659 void CopyTest::CreateAll()
5660 {
5661     CreateSourceTexture<D>();
5662     CreateSourceFramebuffer<D>();
5663     CreateDestinationTexture<D>();
5664 }
5665 
5666 /** @brief Test function */
5667 template <>
Test()5668 bool CopyTest::Test<1>()
5669 {
5670     CreateAll<1>();
5671 
5672     bool result = true;
5673 
5674     result &= CopyTextureSubImage1DAndCheckErrors(m_to_dst, 0, 0, 0, 0, s_texture_width / 2);
5675     result &= CopyTextureSubImage1DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, s_texture_width / 2, 0,
5676                                                   s_texture_width / 2);
5677 
5678     result &= CheckData(TextureTarget<1>(), 4 /* RGBA */ * s_texture_width);
5679 
5680     CleanAll();
5681 
5682     return result;
5683 }
5684 
5685 /** @brief Test function */
5686 template <>
Test()5687 bool CopyTest::Test<2>()
5688 {
5689     CreateAll<2>();
5690 
5691     bool result = true;
5692 
5693     result &= CopyTextureSubImage2DAndCheckErrors(m_to_dst, 0, 0, 0, 0, 0, s_texture_width / 2, s_texture_height / 2);
5694     result &= CopyTextureSubImage2DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, 0, s_texture_width / 2, 0,
5695                                                   s_texture_width / 2, s_texture_height / 2);
5696     result &= CopyTextureSubImage2DAndCheckErrors(m_to_dst, 0, 0, s_texture_height / 2, 0, s_texture_height / 2,
5697                                                   s_texture_width / 2, s_texture_height / 2);
5698     result &=
5699         CopyTextureSubImage2DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, s_texture_height / 2, s_texture_width / 2,
5700                                             s_texture_height / 2, s_texture_width / 2, s_texture_height / 2);
5701 
5702     result &= CheckData(TextureTarget<2>(), 4 /* RGBA */ * s_texture_width * s_texture_height);
5703 
5704     CleanAll();
5705 
5706     return result;
5707 }
5708 
5709 /** @brief Test function */
5710 template <>
Test()5711 bool CopyTest::Test<3>()
5712 {
5713     CreateAll<3>();
5714 
5715     bool result = true;
5716 
5717     for (glw::GLuint i = 0; i < s_texture_depth; ++i)
5718     {
5719         result &=
5720             CopyTextureSubImage3DAndCheckErrors(m_to_dst, 0, 0, 0, i, 0, 0, s_texture_width / 2, s_texture_height / 2);
5721         result &= CopyTextureSubImage3DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, 0, i, s_texture_width / 2, 0,
5722                                                       s_texture_width / 2, s_texture_height / 2);
5723         result &= CopyTextureSubImage3DAndCheckErrors(m_to_dst, 0, 0, s_texture_height / 2, i, 0, s_texture_height / 2,
5724                                                       s_texture_width / 2, s_texture_height / 2);
5725         result &= CopyTextureSubImage3DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, s_texture_height / 2, i,
5726                                                       s_texture_width / 2, s_texture_height / 2, s_texture_width / 2,
5727                                                       s_texture_height / 2);
5728     }
5729 
5730     result &= CheckData(TextureTarget<3>(), 4 /* RGBA */ * s_texture_width * s_texture_height * s_texture_depth);
5731 
5732     CleanAll();
5733 
5734     return result;
5735 }
5736 
5737 /** @brief Compre results with the reference.
5738  *
5739  *  @param [in] target      Texture target.
5740  *  @param [in] size        Size of the buffer.
5741  *
5742  *  @return True if equal, false otherwise.
5743  */
CheckData(glw::GLenum target,glw::GLuint size)5744 bool CopyTest::CheckData(glw::GLenum target, glw::GLuint size)
5745 {
5746     /* Shortcut for GL functionality. */
5747     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
5748 
5749     /* Check texture content with reference. */
5750     m_result = new glw::GLubyte[size];
5751 
5752     if (DE_NULL == m_result)
5753     {
5754         throw 0;
5755     }
5756 
5757     gl.getTexImage(target, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_result);
5758     GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
5759 
5760     for (glw::GLuint i = 0; i < size; ++i)
5761     {
5762         if (s_texture_data[i] != m_result[i])
5763         {
5764             m_context.getTestContext().getLog()
5765                 << tcu::TestLog::Message << "glCopyTextureSubImage*D created texture with data "
5766                 << DataToString(size, s_texture_data) << " however texture contains data "
5767                 << DataToString(size, m_result) << ". Texture target was " << glu::getTextureTargetStr(target)
5768                 << ". Test fails." << tcu::TestLog::EndMessage;
5769 
5770             return false;
5771         }
5772     }
5773 
5774     return true;
5775 }
5776 
5777 /** @brief Convert raw data into string for logging purposes.
5778  *
5779  *  @param [in] count      Count of the data.
5780  *  @param [in] data       Raw data.
5781  *
5782  *  @return String representation of data.
5783  */
DataToString(glw::GLuint count,const glw::GLubyte data[])5784 std::string CopyTest::DataToString(glw::GLuint count, const glw::GLubyte data[])
5785 {
5786     std::string data_str = "[";
5787 
5788     for (glw::GLuint i = 0; i < count; ++i)
5789     {
5790         std::stringstream int_sstream;
5791 
5792         int_sstream << unsigned(data[i]);
5793 
5794         data_str.append(int_sstream.str());
5795 
5796         if (i + 1 < count)
5797         {
5798             data_str.append(", ");
5799         }
5800         else
5801         {
5802             data_str.append("]");
5803         }
5804     }
5805 
5806     return data_str;
5807 }
5808 
5809 /** @brief Clean GL objects, test variables and GL errors.
5810  */
CleanAll()5811 void CopyTest::CleanAll()
5812 {
5813     /* Shortcut for GL functionality. */
5814     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
5815 
5816     if (m_fbo)
5817     {
5818         gl.deleteFramebuffers(1, &m_fbo);
5819 
5820         m_fbo = 0;
5821     }
5822 
5823     if (m_to_src)
5824     {
5825         gl.deleteTextures(1, &m_to_src);
5826 
5827         m_to_src = 0;
5828     }
5829 
5830     if (m_to_dst)
5831     {
5832         gl.deleteTextures(1, &m_to_dst);
5833 
5834         m_to_dst = 0;
5835     }
5836 
5837     if (DE_NULL == m_result)
5838     {
5839         delete[] m_result;
5840 
5841         m_result = DE_NULL;
5842     }
5843 
5844     while (GL_NO_ERROR != gl.getError())
5845         ;
5846 }
5847 
5848 /** @brief Iterate Copy Test cases.
5849  *
5850  *  @return Iteration result.
5851  */
iterate()5852 tcu::TestNode::IterateResult CopyTest::iterate()
5853 {
5854     /* Get context setup. */
5855     bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
5856     bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
5857 
5858     if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
5859     {
5860         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
5861 
5862         return STOP;
5863     }
5864 
5865     /* Running tests. */
5866     bool is_ok    = true;
5867     bool is_error = false;
5868 
5869     try
5870     {
5871         is_ok &= Test<1>();
5872         is_ok &= Test<2>();
5873         is_ok &= Test<3>();
5874     }
5875     catch (...)
5876     {
5877         is_ok    = false;
5878         is_error = true;
5879     }
5880 
5881     /* Cleanup. */
5882     CleanAll();
5883 
5884     /* Result's setup. */
5885     if (is_ok)
5886     {
5887         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
5888     }
5889     else
5890     {
5891         if (is_error)
5892         {
5893             m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
5894         }
5895         else
5896         {
5897             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
5898         }
5899     }
5900 
5901     return STOP;
5902 }
5903 
5904 /** Reference data. */
5905 const glw::GLubyte CopyTest::s_texture_data[] = {
5906     0x00, 0x00, 0x00, 0xFF, 0x7f, 0x7f, 0x7f, 0x00, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0x00,
5907     0x88, 0x00, 0x15, 0xFF, 0xed, 0x1c, 0x24, 0x00, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x00, 0x00,
5908     0xc8, 0xbf, 0xe7, 0xFF, 0x70, 0x92, 0xbe, 0x00, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0x00,
5909     0xa3, 0x49, 0xa4, 0xFF, 0x3f, 0x48, 0xcc, 0x00, 0x00, 0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0x00,
5910 
5911     0xa3, 0x49, 0xa4, 0xFF, 0xc8, 0xbf, 0xe7, 0x00, 0x88, 0x00, 0x15, 0xff, 0x00, 0x00, 0x00, 0x00,
5912     0x3f, 0x48, 0xcc, 0xFF, 0x70, 0x92, 0xbe, 0x00, 0xed, 0x1c, 0x24, 0xff, 0x7f, 0x7f, 0x7f, 0x00,
5913     0x00, 0xa2, 0xe8, 0xFF, 0x99, 0xd9, 0xea, 0x00, 0xff, 0x7f, 0x27, 0xff, 0xc3, 0xc3, 0xc3, 0x00,
5914     0x22, 0xb1, 0x4c, 0xFF, 0xb5, 0xe6, 0x1d, 0x00, 0xff, 0xf2, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00,
5915 
5916     0x22, 0xb1, 0x4c, 0xFF, 0x00, 0xa2, 0xe8, 0x00, 0x3f, 0x48, 0xcc, 0xff, 0xa3, 0x49, 0xa4, 0x00,
5917     0xb5, 0xe6, 0x1d, 0xFF, 0x99, 0xd9, 0xea, 0x00, 0x70, 0x92, 0xbe, 0xff, 0xc8, 0xbf, 0xe7, 0x00,
5918     0xff, 0xf2, 0x00, 0xFF, 0xff, 0x7f, 0x27, 0x00, 0xed, 0x1c, 0x24, 0xff, 0x88, 0x00, 0x15, 0x00,
5919     0xff, 0xff, 0xff, 0xFF, 0xc3, 0xc3, 0xc3, 0x00, 0x7f, 0x7f, 0x7f, 0xff, 0x00, 0x00, 0x00, 0x00,
5920 
5921     0xff, 0xff, 0xff, 0xFF, 0xff, 0xf2, 0x00, 0x00, 0xb5, 0xe6, 0x1d, 0xff, 0x22, 0xb1, 0x4c, 0x00,
5922     0xc3, 0xc3, 0xc3, 0xFF, 0xff, 0x7f, 0x27, 0x00, 0x99, 0xd9, 0xea, 0xff, 0x00, 0xa2, 0xe8, 0x00,
5923     0x7f, 0x7f, 0x7f, 0xFF, 0xed, 0x1c, 0x24, 0x00, 0x70, 0x92, 0xbe, 0xff, 0x3f, 0x48, 0xcc, 0x00,
5924     0x00, 0x00, 0x00, 0xFF, 0x88, 0x00, 0x15, 0x00, 0xc8, 0xbf, 0xe7, 0xff, 0xa3, 0x49, 0xa4, 0x00};
5925 
5926 /** Reference data parameters. */
5927 const glw::GLuint CopyTest::s_texture_width  = 4;
5928 const glw::GLuint CopyTest::s_texture_height = 4;
5929 const glw::GLuint CopyTest::s_texture_depth  = 4;
5930 
5931 /******************************** Get Set Parameter Test Implementation   ********************************/
5932 
5933 /** @brief Get Set Parameter Test constructor.
5934  *
5935  *  @param [in] context     OpenGL context.
5936  */
GetSetParameterTest(deqp::Context & context)5937 GetSetParameterTest::GetSetParameterTest(deqp::Context &context)
5938     : deqp::TestCase(context, "textures_get_set_parameter", "Texture Get Set Parameter Test")
5939 {
5940     /* Intentionally left blank. */
5941 }
5942 
5943 /** @brief Iterate Get Set Parameter Test cases.
5944  *
5945  *  @return Iteration result.
5946  */
iterate()5947 tcu::TestNode::IterateResult GetSetParameterTest::iterate()
5948 {
5949     /* Shortcut for GL functionality. */
5950     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
5951 
5952     /* Get context setup. */
5953     bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
5954     bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
5955 
5956     if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
5957     {
5958         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
5959 
5960         return STOP;
5961     }
5962 
5963     /* Running tests. */
5964     bool is_ok    = true;
5965     bool is_error = false;
5966 
5967     /* Texture. */
5968     glw::GLuint texture = 0;
5969 
5970     try
5971     {
5972         gl.genTextures(1, &texture);
5973         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
5974 
5975         gl.bindTexture(GL_TEXTURE_3D, texture);
5976         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
5977 
5978         {
5979             glw::GLenum name     = GL_DEPTH_STENCIL_TEXTURE_MODE;
5980             glw::GLint value_src = GL_DEPTH_COMPONENT;
5981             glw::GLint value_dst = 0;
5982 
5983             gl.textureParameteri(texture, name, value_src);
5984             is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5985 
5986             gl.getTextureParameteriv(texture, name, &value_dst);
5987             is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
5988 
5989             is_ok &= CompareAndLog(value_src, value_dst, name);
5990         }
5991 
5992         {
5993             glw::GLenum name     = GL_TEXTURE_BASE_LEVEL;
5994             glw::GLint value_src = 2;
5995             glw::GLint value_dst = 0;
5996 
5997             gl.textureParameteri(texture, name, value_src);
5998             is_ok &= CheckErrorAndLog("glTextureParameteri", name);
5999 
6000             gl.getTextureParameteriv(texture, name, &value_dst);
6001             is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6002 
6003             is_ok &= CompareAndLog(value_src, value_dst, name);
6004         }
6005 
6006         {
6007             glw::GLenum name          = GL_TEXTURE_BORDER_COLOR;
6008             glw::GLfloat value_src[4] = {0.25, 0.5, 0.75, 1.0};
6009             glw::GLfloat value_dst[4] = {};
6010 
6011             gl.textureParameterfv(texture, name, value_src);
6012             is_ok &= CheckErrorAndLog("glTextureParameterfv", name);
6013 
6014             gl.getTextureParameterfv(texture, name, value_dst);
6015             is_ok &= CheckErrorAndLog("glGetTextureParameterfv", name);
6016 
6017             is_ok &= CompareAndLog(value_src, value_dst, name);
6018         }
6019 
6020         {
6021             glw::GLenum name        = GL_TEXTURE_BORDER_COLOR;
6022             glw::GLint value_src[4] = {0, 64, -64, -32};
6023             glw::GLint value_dst[4] = {};
6024 
6025             gl.textureParameterIiv(texture, name, value_src);
6026             is_ok &= CheckErrorAndLog("glTextureParameterIiv", name);
6027 
6028             gl.getTextureParameterIiv(texture, name, value_dst);
6029             is_ok &= CheckErrorAndLog("glGetTextureParameterIiv", name);
6030 
6031             is_ok &= CompareAndLog(value_src, value_dst, name);
6032         }
6033 
6034         {
6035             glw::GLenum name         = GL_TEXTURE_BORDER_COLOR;
6036             glw::GLuint value_src[4] = {0, 64, 128, 192};
6037             glw::GLuint value_dst[4] = {};
6038 
6039             gl.textureParameterIuiv(texture, name, value_src);
6040             is_ok &= CheckErrorAndLog("glTextureParameterIuiv", name);
6041 
6042             gl.getTextureParameterIuiv(texture, name, value_dst);
6043             is_ok &= CheckErrorAndLog("glGetTextureParameterIuiv", name);
6044 
6045             is_ok &= CompareAndLog(value_src, value_dst, name);
6046         }
6047 
6048         {
6049             glw::GLenum name     = GL_TEXTURE_COMPARE_FUNC;
6050             glw::GLint value_src = GL_LEQUAL;
6051             glw::GLint value_dst = 0;
6052 
6053             gl.textureParameteri(texture, name, value_src);
6054             is_ok &= CheckErrorAndLog("glTextureParameteri", name);
6055 
6056             gl.getTextureParameteriv(texture, name, &value_dst);
6057             is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6058 
6059             is_ok &= CompareAndLog(value_src, value_dst, name);
6060         }
6061 
6062         {
6063             glw::GLenum name     = GL_TEXTURE_COMPARE_MODE;
6064             glw::GLint value_src = GL_COMPARE_REF_TO_TEXTURE;
6065             glw::GLint value_dst = 0;
6066 
6067             gl.textureParameteri(texture, name, value_src);
6068             is_ok &= CheckErrorAndLog("glTextureParameteri", name);
6069 
6070             gl.getTextureParameteriv(texture, name, &value_dst);
6071             is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6072 
6073             is_ok &= CompareAndLog(value_src, value_dst, name);
6074         }
6075 
6076         {
6077             glw::GLenum name       = GL_TEXTURE_LOD_BIAS;
6078             glw::GLfloat value_src = -2.f;
6079             glw::GLfloat value_dst = 0.f;
6080 
6081             gl.textureParameterf(texture, name, value_src);
6082             is_ok &= CheckErrorAndLog("glTextureParameterf", name);
6083 
6084             gl.getTextureParameterfv(texture, name, &value_dst);
6085             is_ok &= CheckErrorAndLog("glGetTextureParameterfv", name);
6086 
6087             is_ok &= CompareAndLog(value_src, value_dst, name);
6088         }
6089 
6090         {
6091             glw::GLenum name     = GL_TEXTURE_MIN_FILTER;
6092             glw::GLint value_src = GL_LINEAR_MIPMAP_NEAREST;
6093             glw::GLint value_dst = 0;
6094 
6095             gl.textureParameteri(texture, name, value_src);
6096             is_ok &= CheckErrorAndLog("glTextureParameteri", name);
6097 
6098             gl.getTextureParameteriv(texture, name, &value_dst);
6099             is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6100 
6101             is_ok &= CompareAndLog(value_src, value_dst, name);
6102         }
6103 
6104         {
6105             glw::GLenum name     = GL_TEXTURE_MAG_FILTER;
6106             glw::GLint value_src = GL_NEAREST;
6107             glw::GLint value_dst = 0;
6108 
6109             gl.textureParameteri(texture, name, value_src);
6110             is_ok &= CheckErrorAndLog("glTextureParameteri", name);
6111 
6112             gl.getTextureParameteriv(texture, name, &value_dst);
6113             is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6114 
6115             is_ok &= CompareAndLog(value_src, value_dst, name);
6116         }
6117 
6118         {
6119             glw::GLenum name     = GL_TEXTURE_MIN_LOD;
6120             glw::GLint value_src = -100;
6121             glw::GLint value_dst = 0;
6122 
6123             gl.textureParameteri(texture, name, value_src);
6124             is_ok &= CheckErrorAndLog("glTextureParameteri", name);
6125 
6126             gl.getTextureParameteriv(texture, name, &value_dst);
6127             is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6128 
6129             is_ok &= CompareAndLog(value_src, value_dst, name);
6130         }
6131 
6132         {
6133             glw::GLenum name     = GL_TEXTURE_MAX_LOD;
6134             glw::GLint value_src = 100;
6135             glw::GLint value_dst = 0;
6136 
6137             gl.textureParameteri(texture, name, value_src);
6138             is_ok &= CheckErrorAndLog("glTextureParameteri", name);
6139 
6140             gl.getTextureParameteriv(texture, name, &value_dst);
6141             is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6142 
6143             is_ok &= CompareAndLog(value_src, value_dst, name);
6144         }
6145 
6146         {
6147             glw::GLenum name     = GL_TEXTURE_MAX_LEVEL;
6148             glw::GLint value_src = 100;
6149             glw::GLint value_dst = 0;
6150 
6151             gl.textureParameteri(texture, name, value_src);
6152             is_ok &= CheckErrorAndLog("glTextureParameteri", name);
6153 
6154             gl.getTextureParameteriv(texture, name, &value_dst);
6155             is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6156 
6157             is_ok &= CompareAndLog(value_src, value_dst, name);
6158         }
6159 
6160         {
6161             glw::GLenum name     = GL_TEXTURE_SWIZZLE_R;
6162             glw::GLint value_src = GL_BLUE;
6163             glw::GLint value_dst = 0;
6164 
6165             gl.textureParameteri(texture, name, value_src);
6166             is_ok &= CheckErrorAndLog("glTextureParameteri", name);
6167 
6168             gl.getTextureParameteriv(texture, name, &value_dst);
6169             is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6170 
6171             is_ok &= CompareAndLog(value_src, value_dst, name);
6172         }
6173 
6174         {
6175             glw::GLenum name     = GL_TEXTURE_SWIZZLE_G;
6176             glw::GLint value_src = GL_ALPHA;
6177             glw::GLint value_dst = 0;
6178 
6179             gl.textureParameteri(texture, name, value_src);
6180             is_ok &= CheckErrorAndLog("glTextureParameteri", name);
6181 
6182             gl.getTextureParameteriv(texture, name, &value_dst);
6183             is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6184 
6185             is_ok &= CompareAndLog(value_src, value_dst, name);
6186         }
6187 
6188         {
6189             glw::GLenum name     = GL_TEXTURE_SWIZZLE_B;
6190             glw::GLint value_src = GL_RED;
6191             glw::GLint value_dst = 0;
6192 
6193             gl.textureParameteri(texture, name, value_src);
6194             is_ok &= CheckErrorAndLog("glTextureParameteri", name);
6195 
6196             gl.getTextureParameteriv(texture, name, &value_dst);
6197             is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6198 
6199             is_ok &= CompareAndLog(value_src, value_dst, name);
6200         }
6201 
6202         {
6203             glw::GLenum name     = GL_TEXTURE_SWIZZLE_A;
6204             glw::GLint value_src = GL_GREEN;
6205             glw::GLint value_dst = 0;
6206 
6207             gl.textureParameteri(texture, name, value_src);
6208             is_ok &= CheckErrorAndLog("glTextureParameteri", name);
6209 
6210             gl.getTextureParameteriv(texture, name, &value_dst);
6211             is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6212 
6213             is_ok &= CompareAndLog(value_src, value_dst, name);
6214         }
6215 
6216         {
6217             glw::GLenum name        = GL_TEXTURE_SWIZZLE_RGBA;
6218             glw::GLint value_src[4] = {GL_ZERO, GL_ONE, GL_ZERO, GL_ONE};
6219             glw::GLint value_dst[4] = {};
6220 
6221             gl.textureParameteriv(texture, name, value_src);
6222             is_ok &= CheckErrorAndLog("glTextureParameteri", name);
6223 
6224             gl.getTextureParameteriv(texture, name, value_dst);
6225             is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6226 
6227             is_ok &= CompareAndLog(value_src, value_dst, name);
6228         }
6229 
6230         {
6231             glw::GLenum name     = GL_TEXTURE_WRAP_S;
6232             glw::GLint value_src = GL_MIRROR_CLAMP_TO_EDGE;
6233             glw::GLint value_dst = 11;
6234 
6235             gl.textureParameteri(texture, name, value_src);
6236             is_ok &= CheckErrorAndLog("glTextureParameteri", name);
6237 
6238             gl.getTextureParameteriv(texture, name, &value_dst);
6239             is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6240 
6241             is_ok &= CompareAndLog(value_src, value_dst, name);
6242         }
6243 
6244         {
6245             glw::GLenum name     = GL_TEXTURE_WRAP_T;
6246             glw::GLint value_src = GL_CLAMP_TO_EDGE;
6247             glw::GLint value_dst = 11;
6248 
6249             gl.textureParameteri(texture, name, value_src);
6250             is_ok &= CheckErrorAndLog("glTextureParameteri", name);
6251 
6252             gl.getTextureParameteriv(texture, name, &value_dst);
6253             is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6254 
6255             is_ok &= CompareAndLog(value_src, value_dst, name);
6256         }
6257 
6258         {
6259             glw::GLenum name     = GL_TEXTURE_WRAP_R;
6260             glw::GLint value_src = GL_CLAMP_TO_EDGE;
6261             glw::GLint value_dst = 11;
6262 
6263             gl.textureParameteriv(texture, name, &value_src);
6264             is_ok &= CheckErrorAndLog("glTextureParameteri", name);
6265 
6266             gl.getTextureParameteriv(texture, name, &value_dst);
6267             is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name);
6268 
6269             is_ok &= CompareAndLog(value_src, value_dst, name);
6270         }
6271     }
6272     catch (...)
6273     {
6274         is_ok    = false;
6275         is_error = true;
6276     }
6277 
6278     /* Cleanup. */
6279     if (texture)
6280     {
6281         gl.deleteTextures(1, &texture);
6282     }
6283 
6284     while (GL_NO_ERROR != gl.getError())
6285         ;
6286 
6287     /* Result's setup. */
6288     if (is_ok)
6289     {
6290         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
6291     }
6292     else
6293     {
6294         if (is_error)
6295         {
6296             m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
6297         }
6298         else
6299         {
6300             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
6301         }
6302     }
6303 
6304     return STOP;
6305 }
6306 
6307 /** @brief Check for errors and log.
6308  *
6309  *  @param [in] fname     Name of the function (to be logged).
6310  *  @param [in] pname     Parameter name with which function was called.
6311  *
6312  *  @return True if no error, false otherwise.
6313  */
CheckErrorAndLog(const glw::GLchar * fname,glw::GLenum pname)6314 bool GetSetParameterTest::CheckErrorAndLog(const glw::GLchar *fname, glw::GLenum pname)
6315 {
6316     /* Shortcut for GL functionality. */
6317     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
6318 
6319     /* Check errors. */
6320     glw::GLenum error;
6321 
6322     if (GL_NO_ERROR != (error = gl.getError()))
6323     {
6324         m_context.getTestContext().getLog()
6325             << tcu::TestLog::Message << fname << " unexpectedly generated error " << glu::getErrorStr(error)
6326             << " during test of pname " << glu::getTextureParameterStr(pname) << ". Test fails."
6327             << tcu::TestLog::EndMessage;
6328 
6329         return false;
6330     }
6331 
6332     return true;
6333 }
6334 
6335 /** @brief Compare queried value of parameter with the expected vale.
6336  *
6337  *  @param [in] value_src           First value.
6338  *  @param [in] value_dst           Second value.
6339  *  @param [in] pname               Parameter name.
6340  *
6341  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6342  */
CompareAndLog(glw::GLint value_src,glw::GLint value_dst,glw::GLenum pname)6343 bool GetSetParameterTest::CompareAndLog(glw::GLint value_src, glw::GLint value_dst, glw::GLenum pname)
6344 {
6345     if (value_src != value_dst)
6346     {
6347         m_context.getTestContext().getLog()
6348             << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6349             << " is equal to " << value_dst << ", however " << value_src << " was expected. Test fails."
6350             << tcu::TestLog::EndMessage;
6351 
6352         return false;
6353     }
6354 
6355     return true;
6356 }
6357 
6358 /** @brief Compare queried value of parameter with the expected vale.
6359  *
6360  *  @param [in] value_src           First value.
6361  *  @param [in] value_dst           Second value.
6362  *  @param [in] pname               Parameter name.
6363  *
6364  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6365  */
CompareAndLog(glw::GLuint value_src,glw::GLuint value_dst,glw::GLenum pname)6366 bool GetSetParameterTest::CompareAndLog(glw::GLuint value_src, glw::GLuint value_dst, glw::GLenum pname)
6367 {
6368     if (value_src != value_dst)
6369     {
6370         m_context.getTestContext().getLog()
6371             << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6372             << " is equal to " << value_dst << ", however " << value_src << " was expected. Test fails."
6373             << tcu::TestLog::EndMessage;
6374 
6375         return false;
6376     }
6377 
6378     return true;
6379 }
6380 
6381 /** @brief Compare queried value of parameter with the expected vale.
6382  *
6383  *  @param [in] value_src           First value.
6384  *  @param [in] value_dst           Second value.
6385  *  @param [in] pname               Parameter name.
6386  *
6387  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6388  */
CompareAndLog(glw::GLfloat value_src,glw::GLfloat value_dst,glw::GLenum pname)6389 bool GetSetParameterTest::CompareAndLog(glw::GLfloat value_src, glw::GLfloat value_dst, glw::GLenum pname)
6390 {
6391     if (de::abs(value_src - value_dst) > 0.0125 /* Precision */)
6392     {
6393         m_context.getTestContext().getLog()
6394             << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6395             << " is equal to " << value_dst << ", however " << value_src << " was expected. Test fails."
6396             << tcu::TestLog::EndMessage;
6397 
6398         return false;
6399     }
6400 
6401     return true;
6402 }
6403 
6404 /** @brief Compare queried value of parameter with the expected vale.
6405  *
6406  *  @param [in] value_src           First value.
6407  *  @param [in] value_dst           Second value.
6408  *  @param [in] pname               Parameter name.
6409  *
6410  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6411  */
CompareAndLog(glw::GLint value_src[4],glw::GLint value_dst[4],glw::GLenum pname)6412 bool GetSetParameterTest::CompareAndLog(glw::GLint value_src[4], glw::GLint value_dst[4], glw::GLenum pname)
6413 {
6414     if ((value_src[0] != value_dst[0]) || (value_src[1] != value_dst[1]) || (value_src[2] != value_dst[2]) ||
6415         (value_src[3] != value_dst[3]))
6416     {
6417         m_context.getTestContext().getLog()
6418             << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6419             << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3]
6420             << "], however " << value_src[0] << ", " << value_src[1] << ", " << value_src[2] << ", " << value_src[3]
6421             << "] was expected. Test fails." << tcu::TestLog::EndMessage;
6422 
6423         return false;
6424     }
6425 
6426     return true;
6427 }
6428 
6429 /** @brief Compare queried value of parameter with the expected vale.
6430  *
6431  *  @param [in] value_src           First value.
6432  *  @param [in] value_dst           Second value.
6433  *  @param [in] pname               Parameter name.
6434  *
6435  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6436  */
CompareAndLog(glw::GLuint value_src[4],glw::GLuint value_dst[4],glw::GLenum pname)6437 bool GetSetParameterTest::CompareAndLog(glw::GLuint value_src[4], glw::GLuint value_dst[4], glw::GLenum pname)
6438 {
6439     if ((value_src[0] != value_dst[0]) || (value_src[1] != value_dst[1]) || (value_src[2] != value_dst[2]) ||
6440         (value_src[3] != value_dst[3]))
6441     {
6442         m_context.getTestContext().getLog()
6443             << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6444             << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3]
6445             << "], however " << value_src[0] << ", " << value_src[1] << ", " << value_src[2] << ", " << value_src[3]
6446             << "] was expected. Test fails." << tcu::TestLog::EndMessage;
6447 
6448         return false;
6449     }
6450 
6451     return true;
6452 }
6453 
6454 /** @brief Compare queried value of parameter with the expected vale.
6455  *
6456  *  @param [in] value_src           First value.
6457  *  @param [in] value_dst           Second value.
6458  *  @param [in] pname               Parameter name.
6459  *
6460  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6461  */
CompareAndLog(glw::GLfloat value_src[4],glw::GLfloat value_dst[4],glw::GLenum pname)6462 bool GetSetParameterTest::CompareAndLog(glw::GLfloat value_src[4], glw::GLfloat value_dst[4], glw::GLenum pname)
6463 {
6464     if ((de::abs(value_src[0] - value_dst[0]) > 0.0125 /* Precision */) ||
6465         (de::abs(value_src[1] - value_dst[1]) > 0.0125 /* Precision */) ||
6466         (de::abs(value_src[2] - value_dst[2]) > 0.0125 /* Precision */) ||
6467         (de::abs(value_src[3] - value_dst[3]) > 0.0125 /* Precision */))
6468     {
6469         m_context.getTestContext().getLog()
6470             << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6471             << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3]
6472             << "], however " << value_src[0] << ", " << value_src[1] << ", " << value_src[2] << ", " << value_src[3]
6473             << "] was expected. Test fails." << tcu::TestLog::EndMessage;
6474 
6475         return false;
6476     }
6477 
6478     return true;
6479 }
6480 
6481 /******************************** Defaults Test Implementation   ********************************/
6482 
6483 /** @brief Defaults Test constructor.
6484  *
6485  *  @param [in] context     OpenGL context.
6486  */
DefaultsTest(deqp::Context & context)6487 DefaultsTest::DefaultsTest(deqp::Context &context)
6488     : deqp::TestCase(context, "textures_defaults", "Texture Defaults Test")
6489 {
6490     /* Intentionally left blank. */
6491 }
6492 
6493 /** @brief Defaults Test cases.
6494  *
6495  *  @return Iteration result.
6496  */
iterate()6497 tcu::TestNode::IterateResult DefaultsTest::iterate()
6498 {
6499     /* Shortcut for GL functionality. */
6500     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
6501 
6502     /* Get context setup. */
6503     bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
6504     bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
6505 
6506     if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
6507     {
6508         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
6509 
6510         return STOP;
6511     }
6512 
6513     /* Running tests. */
6514     bool is_ok    = true;
6515     bool is_error = false;
6516 
6517     /* Texture. */
6518     glw::GLuint texture = 0;
6519 
6520     try
6521     {
6522         gl.createTextures(GL_TEXTURE_3D, 1, &texture);
6523         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
6524 
6525         {
6526             glw::GLenum name     = GL_DEPTH_STENCIL_TEXTURE_MODE;
6527             glw::GLint value_ref = GL_DEPTH_COMPONENT;
6528             glw::GLint value_dst = 0;
6529 
6530             gl.getTextureParameteriv(texture, name, &value_dst);
6531             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6532 
6533             is_ok &= CompareAndLog(value_ref, value_dst, name);
6534         }
6535 
6536         {
6537             glw::GLenum name     = GL_TEXTURE_BASE_LEVEL;
6538             glw::GLint value_ref = 0;
6539             glw::GLint value_dst = 1;
6540 
6541             gl.getTextureParameteriv(texture, name, &value_dst);
6542             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6543 
6544             is_ok &= CompareAndLog(value_ref, value_dst, name);
6545         }
6546 
6547         {
6548             glw::GLenum name          = GL_TEXTURE_BORDER_COLOR;
6549             glw::GLfloat value_ref[4] = {0.f, 0.f, 0.f, 0.f};
6550             glw::GLfloat value_dst[4] = {};
6551 
6552             gl.getTextureParameterfv(texture, name, value_dst);
6553             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6554 
6555             is_ok &= CompareAndLog(value_ref, value_dst, name);
6556         }
6557 
6558         {
6559             glw::GLenum name     = GL_TEXTURE_COMPARE_FUNC;
6560             glw::GLint value_ref = GL_LEQUAL;
6561             glw::GLint value_dst = 0;
6562 
6563             gl.getTextureParameteriv(texture, name, &value_dst);
6564             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6565 
6566             is_ok &= CompareAndLog(value_ref, value_dst, name);
6567         }
6568 
6569         {
6570             glw::GLenum name     = GL_TEXTURE_COMPARE_MODE;
6571             glw::GLint value_ref = GL_NONE;
6572             glw::GLint value_dst = 0;
6573 
6574             gl.getTextureParameteriv(texture, name, &value_dst);
6575             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6576 
6577             is_ok &= CompareAndLog(value_ref, value_dst, name);
6578         }
6579 
6580         {
6581             glw::GLenum name       = GL_TEXTURE_LOD_BIAS;
6582             glw::GLfloat value_ref = 0.f;
6583             glw::GLfloat value_dst = 0.f;
6584 
6585             gl.getTextureParameterfv(texture, name, &value_dst);
6586             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6587 
6588             is_ok &= CompareAndLog(value_ref, value_dst, name);
6589         }
6590 
6591         {
6592             glw::GLenum name     = GL_TEXTURE_MIN_FILTER;
6593             glw::GLint value_ref = GL_NEAREST_MIPMAP_LINEAR;
6594             glw::GLint value_dst = 0;
6595 
6596             gl.getTextureParameteriv(texture, name, &value_dst);
6597             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6598 
6599             is_ok &= CompareAndLog(value_ref, value_dst, name);
6600         }
6601 
6602         {
6603             glw::GLenum name     = GL_TEXTURE_MAG_FILTER;
6604             glw::GLint value_ref = GL_LINEAR;
6605             glw::GLint value_dst = 0;
6606 
6607             gl.getTextureParameteriv(texture, name, &value_dst);
6608             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6609 
6610             is_ok &= CompareAndLog(value_ref, value_dst, name);
6611         }
6612 
6613         {
6614             glw::GLenum name     = GL_TEXTURE_MIN_LOD;
6615             glw::GLint value_ref = -1000;
6616             glw::GLint value_dst = 0;
6617 
6618             gl.getTextureParameteriv(texture, name, &value_dst);
6619             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6620 
6621             is_ok &= CompareAndLog(value_ref, value_dst, name);
6622         }
6623 
6624         {
6625             glw::GLenum name     = GL_TEXTURE_MAX_LOD;
6626             glw::GLint value_ref = 1000;
6627             glw::GLint value_dst = 0;
6628 
6629             gl.getTextureParameteriv(texture, name, &value_dst);
6630             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6631 
6632             is_ok &= CompareAndLog(value_ref, value_dst, name);
6633         }
6634 
6635         {
6636             glw::GLenum name     = GL_TEXTURE_MAX_LEVEL;
6637             glw::GLint value_ref = 1000;
6638             glw::GLint value_dst = 0;
6639 
6640             gl.getTextureParameteriv(texture, name, &value_dst);
6641             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6642 
6643             is_ok &= CompareAndLog(value_ref, value_dst, name);
6644         }
6645 
6646         {
6647             glw::GLenum name     = GL_TEXTURE_SWIZZLE_R;
6648             glw::GLint value_ref = GL_RED;
6649             glw::GLint value_dst = 0;
6650 
6651             gl.getTextureParameteriv(texture, name, &value_dst);
6652             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6653 
6654             is_ok &= CompareAndLog(value_ref, value_dst, name);
6655         }
6656 
6657         {
6658             glw::GLenum name     = GL_TEXTURE_SWIZZLE_G;
6659             glw::GLint value_ref = GL_GREEN;
6660             glw::GLint value_dst = 0;
6661 
6662             gl.getTextureParameteriv(texture, name, &value_dst);
6663             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6664 
6665             is_ok &= CompareAndLog(value_ref, value_dst, name);
6666         }
6667 
6668         {
6669             glw::GLenum name     = GL_TEXTURE_SWIZZLE_B;
6670             glw::GLint value_ref = GL_BLUE;
6671             glw::GLint value_dst = 0;
6672 
6673             gl.getTextureParameteriv(texture, name, &value_dst);
6674             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6675 
6676             is_ok &= CompareAndLog(value_ref, value_dst, name);
6677         }
6678 
6679         {
6680             glw::GLenum name     = GL_TEXTURE_SWIZZLE_A;
6681             glw::GLint value_ref = GL_ALPHA;
6682             glw::GLint value_dst = 0;
6683 
6684             gl.getTextureParameteriv(texture, name, &value_dst);
6685             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6686 
6687             is_ok &= CompareAndLog(value_ref, value_dst, name);
6688         }
6689 
6690         {
6691             glw::GLenum name     = GL_TEXTURE_WRAP_S;
6692             glw::GLint value_ref = GL_REPEAT;
6693             glw::GLint value_dst = 11;
6694 
6695             gl.getTextureParameteriv(texture, name, &value_dst);
6696             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6697 
6698             is_ok &= CompareAndLog(value_ref, value_dst, name);
6699         }
6700 
6701         {
6702             glw::GLenum name     = GL_TEXTURE_WRAP_T;
6703             glw::GLint value_ref = GL_REPEAT;
6704             glw::GLint value_dst = 11;
6705 
6706             gl.getTextureParameteriv(texture, name, &value_dst);
6707             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6708 
6709             is_ok &= CompareAndLog(value_ref, value_dst, name);
6710         }
6711 
6712         {
6713             glw::GLenum name     = GL_TEXTURE_WRAP_R;
6714             glw::GLint value_ref = GL_REPEAT;
6715             glw::GLint value_dst = 11;
6716 
6717             gl.getTextureParameteriv(texture, name, &value_dst);
6718             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed");
6719 
6720             is_ok &= CompareAndLog(value_ref, value_dst, name);
6721         }
6722     }
6723     catch (...)
6724     {
6725         is_ok    = false;
6726         is_error = true;
6727     }
6728 
6729     /* Cleanup. */
6730     if (texture)
6731     {
6732         gl.deleteTextures(1, &texture);
6733     }
6734 
6735     while (GL_NO_ERROR != gl.getError())
6736         ;
6737 
6738     /* Result's setup. */
6739     if (is_ok)
6740     {
6741         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
6742     }
6743     else
6744     {
6745         if (is_error)
6746         {
6747             m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
6748         }
6749         else
6750         {
6751             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
6752         }
6753     }
6754 
6755     return STOP;
6756 }
6757 
6758 /** @brief Compare queried value of parameter with the expected vale.
6759  *
6760  *  @param [in] value_src           First value.
6761  *  @param [in] value_dst           Second value.
6762  *  @param [in] pname               Parameter name.
6763  *
6764  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6765  */
CompareAndLog(glw::GLint value_ref,glw::GLint value_dst,glw::GLenum pname)6766 bool DefaultsTest::CompareAndLog(glw::GLint value_ref, glw::GLint value_dst, glw::GLenum pname)
6767 {
6768     if (value_ref != value_dst)
6769     {
6770         m_context.getTestContext().getLog()
6771             << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6772             << " is equal to " << value_dst << ", however " << value_ref << " was expected. Test fails."
6773             << tcu::TestLog::EndMessage;
6774 
6775         return false;
6776     }
6777 
6778     return true;
6779 }
6780 
6781 /** @brief Compare queried value of parameter with the expected vale.
6782  *
6783  *  @param [in] value_src           First value.
6784  *  @param [in] value_dst           Second value.
6785  *  @param [in] pname               Parameter name.
6786  *
6787  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6788  */
CompareAndLog(glw::GLuint value_ref,glw::GLuint value_dst,glw::GLenum pname)6789 bool DefaultsTest::CompareAndLog(glw::GLuint value_ref, glw::GLuint value_dst, glw::GLenum pname)
6790 {
6791     if (value_ref != value_dst)
6792     {
6793         m_context.getTestContext().getLog()
6794             << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6795             << " is equal to " << value_dst << ", however " << value_ref << " was expected. Test fails."
6796             << tcu::TestLog::EndMessage;
6797 
6798         return false;
6799     }
6800 
6801     return true;
6802 }
6803 
6804 /** @brief Compare queried value of parameter with the expected vale.
6805  *
6806  *  @param [in] value_src           First value.
6807  *  @param [in] value_dst           Second value.
6808  *  @param [in] pname               Parameter name.
6809  *
6810  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6811  */
CompareAndLog(glw::GLfloat value_ref,glw::GLfloat value_dst,glw::GLenum pname)6812 bool DefaultsTest::CompareAndLog(glw::GLfloat value_ref, glw::GLfloat value_dst, glw::GLenum pname)
6813 {
6814     if (de::abs(value_ref - value_dst) > 0.0125 /* Precision */)
6815     {
6816         m_context.getTestContext().getLog()
6817             << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6818             << " is equal to " << value_dst << ", however " << value_ref << " was expected. Test fails."
6819             << tcu::TestLog::EndMessage;
6820 
6821         return false;
6822     }
6823 
6824     return true;
6825 }
6826 
6827 /** @brief Compare queried value of parameter with the expected vale.
6828  *
6829  *  @param [in] value_src           First value.
6830  *  @param [in] value_dst           Second value.
6831  *  @param [in] pname               Parameter name.
6832  *
6833  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6834  */
CompareAndLog(glw::GLint value_ref[4],glw::GLint value_dst[4],glw::GLenum pname)6835 bool DefaultsTest::CompareAndLog(glw::GLint value_ref[4], glw::GLint value_dst[4], glw::GLenum pname)
6836 {
6837     if ((value_ref[0] != value_dst[0]) || (value_ref[1] != value_dst[1]) || (value_ref[2] != value_dst[2]) ||
6838         (value_ref[3] != value_dst[3]))
6839     {
6840         m_context.getTestContext().getLog()
6841             << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6842             << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3]
6843             << "], however " << value_ref[0] << ", " << value_ref[1] << ", " << value_ref[2] << ", " << value_ref[3]
6844             << "] was expected. Test fails." << tcu::TestLog::EndMessage;
6845 
6846         return false;
6847     }
6848 
6849     return true;
6850 }
6851 
6852 /** @brief Compare queried value of parameter with the expected vale.
6853  *
6854  *  @param [in] value_src           First value.
6855  *  @param [in] value_dst           Second value.
6856  *  @param [in] pname               Parameter name.
6857  *
6858  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6859  */
CompareAndLog(glw::GLuint value_ref[4],glw::GLuint value_dst[4],glw::GLenum pname)6860 bool DefaultsTest::CompareAndLog(glw::GLuint value_ref[4], glw::GLuint value_dst[4], glw::GLenum pname)
6861 {
6862     if ((value_ref[0] != value_dst[0]) || (value_ref[1] != value_dst[1]) || (value_ref[2] != value_dst[2]) ||
6863         (value_ref[3] != value_dst[3]))
6864     {
6865         m_context.getTestContext().getLog()
6866             << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6867             << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3]
6868             << "], however " << value_ref[0] << ", " << value_ref[1] << ", " << value_ref[2] << ", " << value_ref[3]
6869             << "] was expected. Test fails." << tcu::TestLog::EndMessage;
6870 
6871         return false;
6872     }
6873 
6874     return true;
6875 }
6876 
6877 /** @brief Compare queried value of parameter with the expected vale.
6878  *
6879  *  @param [in] value_src           First value.
6880  *  @param [in] value_dst           Second value.
6881  *  @param [in] pname               Parameter name.
6882  *
6883  *  @return True if no error was generated by CopyTextureSubImage*D, false otherwise
6884  */
CompareAndLog(glw::GLfloat value_ref[4],glw::GLfloat value_dst[4],glw::GLenum pname)6885 bool DefaultsTest::CompareAndLog(glw::GLfloat value_ref[4], glw::GLfloat value_dst[4], glw::GLenum pname)
6886 {
6887     if ((de::abs(value_ref[0] - value_dst[0]) > 0.0125 /* Precision */) ||
6888         (de::abs(value_ref[1] - value_dst[1]) > 0.0125 /* Precision */) ||
6889         (de::abs(value_ref[2] - value_dst[2]) > 0.0125 /* Precision */) ||
6890         (de::abs(value_ref[3] - value_dst[3]) > 0.0125 /* Precision */))
6891     {
6892         m_context.getTestContext().getLog()
6893             << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname)
6894             << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3]
6895             << "], however " << value_ref[0] << ", " << value_ref[1] << ", " << value_ref[2] << ", " << value_ref[3]
6896             << "] was expected. Test fails." << tcu::TestLog::EndMessage;
6897 
6898         return false;
6899     }
6900 
6901     return true;
6902 }
6903 
6904 /******************************** Generate Mipmap Test Implementation   ********************************/
6905 
6906 /** @brief Generate Mipmap Test constructor.
6907  *
6908  *  @param [in] context     OpenGL context.
6909  */
GenerateMipmapTest(deqp::Context & context)6910 GenerateMipmapTest::GenerateMipmapTest(deqp::Context &context)
6911     : deqp::TestCase(context, "textures_generate_mipmaps", "Textures Generate Mipmap Test")
6912 {
6913     /* Intentionally left blank. */
6914 }
6915 
6916 /** @brief Generate Mipmap Test cases.
6917  *
6918  *  @return Iteration result.
6919  */
iterate()6920 tcu::TestNode::IterateResult GenerateMipmapTest::iterate()
6921 {
6922     /* Shortcut for GL functionality. */
6923     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
6924 
6925     /* Get context setup. */
6926     bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
6927     bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
6928 
6929     if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
6930     {
6931         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
6932 
6933         return STOP;
6934     }
6935 
6936     /* Running tests. */
6937     bool is_ok    = true;
6938     bool is_error = false;
6939 
6940     /* Texture and cpu results storage. */
6941     glw::GLuint texture  = 0;
6942     glw::GLubyte *result = DE_NULL;
6943 
6944     try
6945     {
6946         /* Prepare texture. */
6947         gl.genTextures(1, &texture);
6948         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
6949 
6950         gl.bindTexture(GL_TEXTURE_1D, texture);
6951         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
6952 
6953         gl.texImage1D(GL_TEXTURE_1D, 0, GL_R8, s_texture_width, 0, GL_RED, GL_UNSIGNED_BYTE, s_texture_data);
6954         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
6955 
6956         /* Generate mipmaps with tested function. */
6957         gl.generateTextureMipmap(texture);
6958 
6959         glw::GLenum error = GL_NO_ERROR;
6960 
6961         if (GL_NO_ERROR != (error = gl.getError()))
6962         {
6963             m_context.getTestContext().getLog()
6964                 << tcu::TestLog::Message << "GenerateTextureMipmap unexpectedly generated error "
6965                 << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
6966 
6967             is_ok = false;
6968         }
6969 
6970         /* Continue only if mipmaps has been generated. */
6971         if (is_ok)
6972         {
6973             result = new glw::GLubyte[s_texture_width];
6974 
6975             if (DE_NULL == result)
6976             {
6977                 throw 0;
6978             }
6979 
6980             /* For each mipmap. */
6981             for (glw::GLuint i = 0, j = s_texture_width;
6982                  i < s_texture_width_log - 1 /* Do not test single pixel mipmap. */; ++i, j /= 2)
6983             {
6984                 /* Check mipmap size. */
6985                 glw::GLint mipmap_size = 0;
6986 
6987                 gl.getTexLevelParameteriv(GL_TEXTURE_1D, i, GL_TEXTURE_WIDTH, &mipmap_size);
6988                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
6989 
6990                 if (mipmap_size != (glw::GLint)j)
6991                 {
6992                     m_context.getTestContext().getLog()
6993                         << tcu::TestLog::Message
6994                         << "GenerateTextureMipmap unexpectedly generated mipmap with improper size. Mipmap size is "
6995                         << mipmap_size << ", but " << j << " was expected. Test fails." << tcu::TestLog::EndMessage;
6996 
6997                     is_ok = false;
6998 
6999                     break;
7000                 }
7001 
7002                 /* Fetch data. */
7003                 gl.getTexImage(GL_TEXTURE_1D, i, GL_RED, GL_UNSIGNED_BYTE, result);
7004                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexImage has failed");
7005 
7006                 /* Make comparison. */
7007                 for (glw::GLuint k = 0; k < j - 1; ++k)
7008                 {
7009                     if (((glw::GLint)result[k + 1]) - ((glw::GLint)result[k]) < 0)
7010                     {
7011                         m_context.getTestContext().getLog() << tcu::TestLog::Message
7012                                                             << "GenerateTextureMipmap unexpectedly generated improper "
7013                                                                "mipmap (not descending). Test fails."
7014                                                             << tcu::TestLog::EndMessage;
7015 
7016                         is_ok = false;
7017 
7018                         break;
7019                     }
7020                 }
7021             }
7022         }
7023     }
7024     catch (...)
7025     {
7026         is_ok    = false;
7027         is_error = true;
7028     }
7029 
7030     /* Cleanup. */
7031     if (texture)
7032     {
7033         gl.deleteTextures(1, &texture);
7034     }
7035 
7036     if (DE_NULL != result)
7037     {
7038         delete[] result;
7039     }
7040 
7041     while (GL_NO_ERROR != gl.getError())
7042         ;
7043 
7044     /* Result's setup. */
7045     if (is_ok)
7046     {
7047         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
7048     }
7049     else
7050     {
7051         if (is_error)
7052         {
7053             m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
7054         }
7055         else
7056         {
7057             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7058         }
7059     }
7060 
7061     return STOP;
7062 }
7063 
7064 /** Reference data. */
7065 const glw::GLubyte GenerateMipmapTest::s_texture_data[] = {
7066     0,   1,   2,   3,   4,   5,   6,   7,   8,   9,   10,  11,  12,  13,  14,  15,  16,  17,  18,  19,  20,  21,
7067     22,  23,  24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,
7068     44,  45,  46,  47,  48,  49,  50,  51,  52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,  63,  64,  65,
7069     66,  67,  68,  69,  70,  71,  72,  73,  74,  75,  76,  77,  78,  79,  80,  81,  82,  83,  84,  85,  86,  87,
7070     88,  89,  90,  91,  92,  93,  94,  95,  96,  97,  98,  99,  100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
7071     110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131,
7072     132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153,
7073     154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
7074     176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197,
7075     198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219,
7076     220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241,
7077     242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255};
7078 
7079 /** Reference data parameters. */
7080 const glw::GLuint GenerateMipmapTest::s_texture_width     = 256;
7081 const glw::GLuint GenerateMipmapTest::s_texture_width_log = 8;
7082 
7083 /******************************** Bind Unit Test Implementation   ********************************/
7084 
7085 /** @brief Bind Unit Test constructor.
7086  *
7087  *  @param [in] context     OpenGL context.
7088  */
BindUnitTest(deqp::Context & context)7089 BindUnitTest::BindUnitTest(deqp::Context &context)
7090     : deqp::TestCase(context, "textures_bind_unit", "Textures Bind Unit Test")
7091     , m_po(0)
7092     , m_fbo(0)
7093     , m_rbo(0)
7094     , m_vao(0)
7095     , m_result(DE_NULL)
7096 {
7097     m_to[0] = 0;
7098     m_to[1] = 0;
7099     m_to[2] = 0;
7100     m_to[3] = 0;
7101 }
7102 
7103 /** @brief Bind Unit Test cases.
7104  *
7105  *  @return Iteration result.
7106  */
iterate()7107 tcu::TestNode::IterateResult BindUnitTest::iterate()
7108 {
7109     /* Get context setup. */
7110     bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
7111     bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
7112 
7113     if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
7114     {
7115         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
7116 
7117         return STOP;
7118     }
7119 
7120     /* Running tests. */
7121     bool is_ok    = true;
7122     bool is_error = false;
7123 
7124     try
7125     {
7126         CreateProgram();
7127         CreateTextures();
7128         CreateFrambuffer();
7129         CreateVertexArray();
7130         is_ok &= Draw();
7131         is_ok &= Check();
7132     }
7133     catch (...)
7134     {
7135         is_ok    = false;
7136         is_error = true;
7137     }
7138 
7139     /* Cleanup. */
7140     CleanAll();
7141 
7142     /* Result's setup. */
7143     if (is_ok)
7144     {
7145         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
7146     }
7147     else
7148     {
7149         if (is_error)
7150         {
7151             m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
7152         }
7153         else
7154         {
7155             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7156         }
7157     }
7158 
7159     return STOP;
7160 }
7161 
7162 /** @brief Create test program.
7163  */
CreateProgram()7164 void BindUnitTest::CreateProgram()
7165 {
7166     /* Shortcut for GL functionality */
7167     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
7168 
7169     struct Shader
7170     {
7171         glw::GLchar const *source;
7172         glw::GLenum const type;
7173         glw::GLuint id;
7174     } shader[] = {{s_vertex_shader, GL_VERTEX_SHADER, 0}, {s_fragment_shader, GL_FRAGMENT_SHADER, 0}};
7175 
7176     glw::GLuint const shader_count = sizeof(shader) / sizeof(shader[0]);
7177 
7178     try
7179     {
7180         /* Create program. */
7181         m_po = gl.createProgram();
7182         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateProgram call failed.");
7183 
7184         /* Shader compilation. */
7185 
7186         for (glw::GLuint i = 0; i < shader_count; ++i)
7187         {
7188             if (DE_NULL != shader[i].source)
7189             {
7190                 shader[i].id = gl.createShader(shader[i].type);
7191 
7192                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateShader call failed.");
7193 
7194                 gl.attachShader(m_po, shader[i].id);
7195 
7196                 GLU_EXPECT_NO_ERROR(gl.getError(), "glAttachShader call failed.");
7197 
7198                 gl.shaderSource(shader[i].id, 1, &shader[i].source, NULL);
7199 
7200                 GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource call failed.");
7201 
7202                 gl.compileShader(shader[i].id);
7203 
7204                 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader call failed.");
7205 
7206                 glw::GLint status = GL_FALSE;
7207 
7208                 gl.getShaderiv(shader[i].id, GL_COMPILE_STATUS, &status);
7209                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
7210 
7211                 if (GL_FALSE == status)
7212                 {
7213                     glw::GLint log_size = 0;
7214                     gl.getShaderiv(shader[i].id, GL_INFO_LOG_LENGTH, &log_size);
7215                     GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
7216 
7217                     glw::GLchar *log_text = new glw::GLchar[log_size];
7218 
7219                     gl.getShaderInfoLog(shader[i].id, log_size, NULL, &log_text[0]);
7220 
7221                     m_context.getTestContext().getLog()
7222                         << tcu::TestLog::Message << "Shader compilation has failed.\n"
7223                         << "Shader type: " << glu::getShaderTypeStr(shader[i].type) << "\n"
7224                         << "Shader compilation error log:\n"
7225                         << log_text << "\n"
7226                         << "Shader source code:\n"
7227                         << shader[i].source << "\n"
7228                         << tcu::TestLog::EndMessage;
7229 
7230                     delete[] log_text;
7231 
7232                     GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog call failed.");
7233 
7234                     throw 0;
7235                 }
7236             }
7237         }
7238 
7239         /* Link. */
7240         gl.linkProgram(m_po);
7241 
7242         GLU_EXPECT_NO_ERROR(gl.getError(), "glTransformFeedbackVaryings call failed.");
7243 
7244         glw::GLint status = GL_FALSE;
7245 
7246         gl.getProgramiv(m_po, GL_LINK_STATUS, &status);
7247 
7248         if (GL_TRUE == status)
7249         {
7250             for (glw::GLuint i = 0; i < shader_count; ++i)
7251             {
7252                 if (shader[i].id)
7253                 {
7254                     gl.detachShader(m_po, shader[i].id);
7255 
7256                     GLU_EXPECT_NO_ERROR(gl.getError(), "glDetachShader call failed.");
7257                 }
7258             }
7259         }
7260         else
7261         {
7262             glw::GLint log_size = 0;
7263 
7264             gl.getProgramiv(m_po, GL_INFO_LOG_LENGTH, &log_size);
7265 
7266             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv call failed.");
7267 
7268             glw::GLchar *log_text = new glw::GLchar[log_size];
7269 
7270             gl.getProgramInfoLog(m_po, log_size, NULL, &log_text[0]);
7271 
7272             m_context.getTestContext().getLog() << tcu::TestLog::Message << "Program linkage has failed due to:\n"
7273                                                 << log_text << "\n"
7274                                                 << tcu::TestLog::EndMessage;
7275 
7276             delete[] log_text;
7277 
7278             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramInfoLog call failed.");
7279 
7280             throw 0;
7281         }
7282     }
7283     catch (...)
7284     {
7285         if (m_po)
7286         {
7287             gl.deleteProgram(m_po);
7288 
7289             m_po = 0;
7290         }
7291     }
7292 
7293     for (glw::GLuint i = 0; i < shader_count; ++i)
7294     {
7295         if (0 != shader[i].id)
7296         {
7297             gl.deleteShader(shader[i].id);
7298 
7299             shader[i].id = 0;
7300         }
7301     }
7302 
7303     if (0 == m_po)
7304     {
7305         throw 0;
7306     }
7307 }
7308 
7309 /** @brief Create texture.
7310  */
CreateTextures()7311 void BindUnitTest::CreateTextures()
7312 {
7313     /* Shortcut for GL functionality. */
7314     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
7315 
7316     /* Prepare texture. */
7317     gl.genTextures(4, m_to);
7318     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
7319 
7320     /* Setup pixel sotre modes.*/
7321     gl.pixelStorei(GL_UNPACK_ALIGNMENT, sizeof(glw::GLubyte));
7322     GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
7323 
7324     gl.pixelStorei(GL_PACK_ALIGNMENT, sizeof(glw::GLubyte));
7325     GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
7326 
7327     /* Red texture. */
7328     gl.bindTexture(GL_TEXTURE_2D, m_to[0]);
7329     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7330 
7331     gl.texImage2D(GL_TEXTURE_2D, 0, GL_R8, s_texture_width, s_texture_height, 0, GL_RED, GL_UNSIGNED_BYTE,
7332                   s_texture_data_r);
7333     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
7334 
7335     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
7336     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
7337     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
7338 
7339     /* Green texture. */
7340     gl.bindTexture(GL_TEXTURE_2D, m_to[1]);
7341     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7342 
7343     gl.texImage2D(GL_TEXTURE_2D, 0, GL_R8, s_texture_width, s_texture_height, 0, GL_RED, GL_UNSIGNED_BYTE,
7344                   s_texture_data_g);
7345     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
7346 
7347     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
7348     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
7349     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
7350 
7351     /* Blue texture. */
7352     gl.bindTexture(GL_TEXTURE_2D, m_to[2]);
7353     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7354 
7355     gl.texImage2D(GL_TEXTURE_2D, 0, GL_R8, s_texture_width, s_texture_height, 0, GL_RED, GL_UNSIGNED_BYTE,
7356                   s_texture_data_b);
7357     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
7358 
7359     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
7360     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
7361     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
7362 
7363     /* Alpha texture. */
7364     gl.bindTexture(GL_TEXTURE_2D, m_to[3]);
7365     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7366 
7367     gl.texImage2D(GL_TEXTURE_2D, 0, GL_R8, s_texture_width, s_texture_height, 0, GL_RED, GL_UNSIGNED_BYTE,
7368                   s_texture_data_a);
7369     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
7370 
7371     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
7372     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
7373     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed.");
7374 }
7375 
7376 /** @brief Create framebuffer.
7377  */
CreateFrambuffer()7378 void BindUnitTest::CreateFrambuffer()
7379 {
7380     /* Shortcut for GL functionality. */
7381     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
7382 
7383     /* Prepare framebuffer. */
7384     gl.genFramebuffers(1, &m_fbo);
7385     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
7386 
7387     gl.genRenderbuffers(1, &m_rbo);
7388     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
7389 
7390     gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
7391     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
7392 
7393     gl.bindRenderbuffer(GL_RENDERBUFFER, m_rbo);
7394     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
7395 
7396     gl.renderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, s_texture_width, s_texture_height);
7397     GLU_EXPECT_NO_ERROR(gl.getError(), "glRenderbufferStorage call failed.");
7398 
7399     gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_rbo);
7400     GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
7401 
7402     if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
7403     {
7404         throw 0;
7405     }
7406 
7407     gl.viewport(0, 0, s_texture_width, s_texture_height);
7408     GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
7409 
7410     /* Clear framebuffer's content. */
7411     gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
7412     GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
7413 
7414     gl.clear(GL_COLOR_BUFFER_BIT);
7415     GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
7416 }
7417 
7418 /** @brief Create vertex array object.
7419  */
CreateVertexArray()7420 void BindUnitTest::CreateVertexArray()
7421 {
7422     /* Shortcut for GL functionality. */
7423     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
7424 
7425     gl.genVertexArrays(1, &m_vao);
7426     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays call has failed.");
7427 
7428     gl.bindVertexArray(m_vao);
7429     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray call has failed.");
7430 }
7431 
Draw()7432 bool BindUnitTest::Draw()
7433 {
7434     /* Shortcut for GL functionality. */
7435     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
7436 
7437     /* Setup program. */
7438     gl.useProgram(m_po);
7439     GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram call has failed.");
7440 
7441     /* Bind textures to proper units and setup program's samplers. */
7442     for (glw::GLuint i = 0; i < 4; ++i)
7443     {
7444         /* Tested binding funcion. */
7445         gl.bindTextureUnit(i, m_to[i]);
7446 
7447         /* Check for errors. */
7448         glw::GLenum error = GL_NO_ERROR;
7449 
7450         if (GL_NO_ERROR != (error = gl.getError()))
7451         {
7452             m_context.getTestContext().getLog()
7453                 << tcu::TestLog::Message << "BindTextureUnit unexpectedly generated error " << glu::getErrorStr(error)
7454                 << " when binding texture " << m_to[i] << " to texture unit " << i << ". Test fails."
7455                 << tcu::TestLog::EndMessage;
7456 
7457             return false;
7458         }
7459 
7460         /* Sampler setup. */
7461         gl.uniform1i(gl.getUniformLocation(m_po, s_fragment_shader_samplers[i]), i);
7462         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetUniformLocation or glUniform1i call has failed.");
7463     }
7464 
7465     /* Draw call. */
7466     gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
7467     GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays call has failed.");
7468 
7469     return true;
7470 }
7471 
7472 /** @brief Compare results with reference.
7473  *
7474  *  @return True if equal, false otherwise.
7475  */
Check()7476 bool BindUnitTest::Check()
7477 {
7478     /* Shortcut for GL functionality. */
7479     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
7480 
7481     /* Setup storage for results. */
7482     m_result = new glw::GLubyte[s_texture_count_rgba];
7483 
7484     /* Setup pixel sotre modes.*/
7485     gl.pixelStorei(GL_UNPACK_ALIGNMENT, sizeof(glw::GLubyte));
7486     GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
7487 
7488     gl.pixelStorei(GL_PACK_ALIGNMENT, sizeof(glw::GLubyte));
7489     GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed");
7490 
7491     /* Query framebuffer's image. */
7492     gl.readPixels(0, 0, s_texture_width, s_texture_height, GL_RGBA, GL_UNSIGNED_BYTE, m_result);
7493     GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays call has failed.");
7494 
7495     /* Compare values with reference. */
7496     for (glw::GLuint i = 0; i < s_texture_count_rgba; ++i)
7497     {
7498         if (s_texture_data_rgba[i] != m_result[i])
7499         {
7500             m_context.getTestContext().getLog()
7501                 << tcu::TestLog::Message << "Framebuffer data " << DataToString(s_texture_count_rgba, m_result)
7502                 << " does not match the reference values " << DataToString(s_texture_count_rgba, s_texture_data_rgba)
7503                 << "." << tcu::TestLog::EndMessage;
7504 
7505             return false;
7506         }
7507     }
7508 
7509     return true;
7510 }
7511 
7512 /** @brief Clean GL objects, test variables and GL errors.
7513  */
CleanAll()7514 void BindUnitTest::CleanAll()
7515 {
7516     /* Shortcut for GL functionality. */
7517     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
7518 
7519     /* Release GL objects. */
7520     if (m_po)
7521     {
7522         gl.useProgram(0);
7523 
7524         gl.deleteProgram(m_po);
7525 
7526         m_po = 0;
7527     }
7528 
7529     if (m_to[0] || m_to[1] || m_to[2] || m_to[3])
7530     {
7531         gl.deleteTextures(4, m_to);
7532 
7533         m_to[0] = 0;
7534         m_to[1] = 0;
7535         m_to[2] = 0;
7536         m_to[3] = 0;
7537     }
7538 
7539     if (m_fbo)
7540     {
7541         gl.deleteFramebuffers(1, &m_fbo);
7542 
7543         m_fbo = 0;
7544     }
7545 
7546     if (m_rbo)
7547     {
7548         gl.deleteRenderbuffers(1, &m_rbo);
7549 
7550         m_rbo = 0;
7551     }
7552 
7553     /* Release heap. */
7554     if (DE_NULL != m_result)
7555     {
7556         delete[] m_result;
7557     }
7558 
7559     /* Erros clean-up. */
7560     while (GL_NO_ERROR != gl.getError())
7561         ;
7562 }
7563 
7564 /** @brief Convert raw data into string for logging purposes.
7565  *
7566  *  @param [in] count      Count of the data.
7567  *  @param [in] data       Raw data.
7568  *
7569  *  @return String representation of data.
7570  */
DataToString(glw::GLuint count,const glw::GLubyte data[])7571 std::string BindUnitTest::DataToString(glw::GLuint count, const glw::GLubyte data[])
7572 {
7573     std::string data_str = "[";
7574 
7575     for (glw::GLuint i = 0; i < count; ++i)
7576     {
7577         std::stringstream int_sstream;
7578 
7579         int_sstream << unsigned(data[i]);
7580 
7581         data_str.append(int_sstream.str());
7582 
7583         if (i + 1 < count)
7584         {
7585             data_str.append(", ");
7586         }
7587         else
7588         {
7589             data_str.append("]");
7590         }
7591     }
7592 
7593     return data_str;
7594 }
7595 
7596 /** Reference data and parameters. */
7597 const glw::GLubyte BindUnitTest::s_texture_data_r[]    = {0, 4, 8, 12, 16, 20};
7598 const glw::GLubyte BindUnitTest::s_texture_data_g[]    = {1, 5, 9, 13, 17, 21};
7599 const glw::GLubyte BindUnitTest::s_texture_data_b[]    = {2, 6, 10, 14, 18, 22};
7600 const glw::GLubyte BindUnitTest::s_texture_data_a[]    = {3, 7, 11, 15, 19, 23};
7601 const glw::GLubyte BindUnitTest::s_texture_data_rgba[] = {0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11,
7602                                                           12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23};
7603 const glw::GLuint BindUnitTest::s_texture_width        = 2;
7604 const glw::GLuint BindUnitTest::s_texture_height       = 3;
7605 const glw::GLuint BindUnitTest::s_texture_count_rgba   = sizeof(s_texture_data_rgba) / sizeof(s_texture_data_rgba[0]);
7606 
7607 /* Vertex shader source code. */
7608 const glw::GLchar *BindUnitTest::s_vertex_shader = "#version 450\n"
7609                                                    "\n"
7610                                                    "void main()\n"
7611                                                    "{\n"
7612                                                    "    switch(gl_VertexID)\n"
7613                                                    "    {\n"
7614                                                    "        case 0:\n"
7615                                                    "            gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
7616                                                    "            break;\n"
7617                                                    "        case 1:\n"
7618                                                    "            gl_Position = vec4( 1.0, 1.0, 0.0, 1.0);\n"
7619                                                    "            break;\n"
7620                                                    "        case 2:\n"
7621                                                    "            gl_Position = vec4(-1.0,-1.0, 0.0, 1.0);\n"
7622                                                    "            break;\n"
7623                                                    "        case 3:\n"
7624                                                    "            gl_Position = vec4( 1.0,-1.0, 0.0, 1.0);\n"
7625                                                    "            break;\n"
7626                                                    "    }\n"
7627                                                    "}\n";
7628 
7629 /* Fragment shader source program. */
7630 const glw::GLchar *BindUnitTest::s_fragment_shader =
7631     "#version 450\n"
7632     "\n"
7633     "layout(pixel_center_integer) in vec4 gl_FragCoord;\n"
7634     "\n"
7635     "uniform sampler2D texture_input_r;\n"
7636     "uniform sampler2D texture_input_g;\n"
7637     "uniform sampler2D texture_input_b;\n"
7638     "uniform sampler2D texture_input_a;\n"
7639     "\n"
7640     "out     vec4      color_output;\n"
7641     "\n"
7642     "void main()\n"
7643     "{\n"
7644     "    color_output = vec4(texelFetch(texture_input_r, ivec2(gl_FragCoord.xy), 0).r,\n"
7645     "                        texelFetch(texture_input_g, ivec2(gl_FragCoord.xy), 0).r,\n"
7646     "                        texelFetch(texture_input_b, ivec2(gl_FragCoord.xy), 0).r,\n"
7647     "                        texelFetch(texture_input_a, ivec2(gl_FragCoord.xy), 0).r);\n"
7648     "}\n";
7649 
7650 const glw::GLchar *BindUnitTest::s_fragment_shader_samplers[4] = {"texture_input_r", "texture_input_g",
7651                                                                   "texture_input_b", "texture_input_a"};
7652 
7653 /******************************** Get Image Test Implementation   ********************************/
7654 
7655 /** @brief Get Image Test constructor.
7656  *
7657  *  @param [in] context     OpenGL context.
7658  */
GetImageTest(deqp::Context & context)7659 GetImageTest::GetImageTest(deqp::Context &context)
7660     : deqp::TestCase(context, "textures_get_image", "Textures Get Image Test")
7661 {
7662     /* Intentionally left blank */
7663 }
7664 
7665 /** Reference data. */
7666 const glw::GLubyte GetImageTest::s_texture_data[] = {
7667     0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
7668     0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
7669     0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
7670     0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff};
7671 
7672 /** Reference data (compressed). */
7673 const glw::GLubyte GetImageTest::s_texture_data_compressed[] = {0x90, 0x2b, 0x8f, 0x0f, 0xfe, 0x0f, 0x98, 0x99,
7674                                                                 0x99, 0x99, 0x59, 0x8f, 0x8c, 0xa6, 0xb7, 0x71};
7675 
7676 /** Reference data parameters. */
7677 const glw::GLuint GetImageTest::s_texture_width           = 4;
7678 const glw::GLuint GetImageTest::s_texture_height          = 4;
7679 const glw::GLuint GetImageTest::s_texture_size            = sizeof(s_texture_data);
7680 const glw::GLuint GetImageTest::s_texture_size_compressed = sizeof(s_texture_data_compressed);
7681 const glw::GLuint GetImageTest::s_texture_count           = s_texture_size / sizeof(s_texture_data[0]);
7682 const glw::GLuint GetImageTest::s_texture_count_compressed =
7683     s_texture_size_compressed / sizeof(s_texture_data_compressed[0]);
7684 
7685 /** @brief Get Image Test cases.
7686  *
7687  *  @return Iteration result.
7688  */
iterate()7689 tcu::TestNode::IterateResult GetImageTest::iterate()
7690 {
7691     /* Shortcut for GL functionality. */
7692     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
7693 
7694     /* Get context setup. */
7695     bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
7696     bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
7697 
7698     if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
7699     {
7700         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
7701 
7702         return STOP;
7703     }
7704 
7705     /* Running tests. */
7706     bool is_ok    = true;
7707     bool is_error = false;
7708 
7709     /* Objects. */
7710     glw::GLuint texture                                        = 0;
7711     glw::GLubyte result[s_texture_count]                       = {};
7712     glw::GLubyte result_compressed[s_texture_count_compressed] = {};
7713 
7714     try
7715     {
7716         /* Uncompressed case. */
7717         {
7718             /* Texture initiation. */
7719             gl.genTextures(1, &texture);
7720             GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
7721 
7722             gl.bindTexture(GL_TEXTURE_2D, texture);
7723             GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7724 
7725             gl.texImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, s_texture_width, s_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
7726                           s_texture_data);
7727             GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
7728 
7729             /* Quering image with tested function. */
7730             gl.getTextureImage(texture, 0, GL_RGBA, GL_UNSIGNED_BYTE, sizeof(result), result);
7731 
7732             /* Check for errors. */
7733             glw::GLenum error = GL_NO_ERROR;
7734 
7735             if (GL_NO_ERROR != (error = gl.getError()))
7736             {
7737                 m_context.getTestContext().getLog()
7738                     << tcu::TestLog::Message << "GetTextureImage unexpectedly generated error "
7739                     << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
7740 
7741                 is_ok = false;
7742             }
7743             else
7744             {
7745                 /* No error, so compare images. */
7746                 for (glw::GLuint i = 0; i < s_texture_count; ++i)
7747                 {
7748                     if (s_texture_data[i] != result[i])
7749                     {
7750                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "GetTextureImage returned "
7751                                                             << DataToString(s_texture_count, result) << ", but "
7752                                                             << DataToString(s_texture_count, s_texture_data)
7753                                                             << " was expected. Test fails." << tcu::TestLog::EndMessage;
7754 
7755                         is_ok = false;
7756 
7757                         break;
7758                     }
7759                 }
7760             }
7761         }
7762 
7763         /* Clean up texture .*/
7764         gl.deleteTextures(1, &texture);
7765         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
7766 
7767         texture = 0;
7768 
7769         /* Compressed case. */
7770         {
7771             /* Texture initiation. */
7772             gl.genTextures(1, &texture);
7773             GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
7774 
7775             gl.bindTexture(GL_TEXTURE_2D, texture);
7776             GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7777 
7778             gl.compressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_BPTC_UNORM, s_texture_width, s_texture_height,
7779                                     0, s_texture_size_compressed, s_texture_data_compressed);
7780             GLU_EXPECT_NO_ERROR(gl.getError(), "glCompressedTexImage2D has failed");
7781 
7782             /* Quering image with tested function. */
7783             gl.getCompressedTextureImage(texture, 0, s_texture_count_compressed * sizeof(result_compressed[0]),
7784                                          result_compressed);
7785 
7786             /* Check for errors. */
7787             glw::GLenum error = GL_NO_ERROR;
7788 
7789             if (GL_NO_ERROR != (error = gl.getError()))
7790             {
7791                 m_context.getTestContext().getLog()
7792                     << tcu::TestLog::Message << "GetCompressedTextureImage unexpectedly generated error "
7793                     << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
7794 
7795                 is_ok = false;
7796             }
7797             else
7798             {
7799                 /* No error, so compare images. */
7800                 for (glw::GLuint i = 0; i < s_texture_count_compressed; ++i)
7801                 {
7802                     if (s_texture_data_compressed[i] != result_compressed[i])
7803                     {
7804                         m_context.getTestContext().getLog()
7805                             << tcu::TestLog::Message << "GetCompressedTextureImage returned "
7806                             << DataToString(s_texture_count_compressed, result_compressed) << ", but "
7807                             << DataToString(s_texture_count_compressed, s_texture_data_compressed)
7808                             << " was expected. Test fails." << tcu::TestLog::EndMessage;
7809 
7810                         is_ok = false;
7811 
7812                         break;
7813                     }
7814                 }
7815             }
7816         }
7817     }
7818     catch (...)
7819     {
7820         is_ok    = false;
7821         is_error = true;
7822     }
7823 
7824     /* Cleanup. */
7825     if (texture)
7826     {
7827         gl.deleteTextures(1, &texture);
7828     }
7829 
7830     /* Result's setup. */
7831     if (is_ok)
7832     {
7833         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
7834     }
7835     else
7836     {
7837         if (is_error)
7838         {
7839             m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
7840         }
7841         else
7842         {
7843             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7844         }
7845     }
7846 
7847     return STOP;
7848 }
7849 
7850 /** @brief Convert raw data into string for logging purposes.
7851  *
7852  *  @param [in] count      Count of the data.
7853  *  @param [in] data       Raw data.
7854  *
7855  *  @return String representation of data.
7856  */
DataToString(glw::GLuint count,const glw::GLubyte data[])7857 std::string GetImageTest::DataToString(glw::GLuint count, const glw::GLubyte data[])
7858 {
7859     std::string data_str = "[";
7860 
7861     for (glw::GLuint i = 0; i < count; ++i)
7862     {
7863         std::stringstream int_sstream;
7864 
7865         int_sstream << unsigned(data[i]);
7866 
7867         data_str.append(int_sstream.str());
7868 
7869         if (i + 1 < count)
7870         {
7871             data_str.append(", ");
7872         }
7873         else
7874         {
7875             data_str.append("]");
7876         }
7877     }
7878 
7879     return data_str;
7880 }
7881 
7882 /******************************** Get Level Parameter Test Implementation   ********************************/
7883 
7884 /** @brief Get Level Parameter Test constructor.
7885  *
7886  *  @param [in] context     OpenGL context.
7887  */
GetLevelParameterTest(deqp::Context & context)7888 GetLevelParameterTest::GetLevelParameterTest(deqp::Context &context)
7889     : deqp::TestCase(context, "textures_get_level_parameter", "Textures Get Level Parameter Test")
7890 {
7891     /* Intentionally left blank */
7892 }
7893 
7894 /** Reference data. */
7895 const glw::GLubyte GetLevelParameterTest::s_texture_data[] = {
7896     0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
7897     0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
7898     0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
7899     0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff,
7900 
7901     0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
7902     0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
7903     0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
7904     0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff,
7905 
7906     0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
7907     0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
7908     0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
7909     0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff,
7910 
7911     0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
7912     0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
7913     0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
7914     0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff};
7915 
7916 /** Reference data parameters. */
7917 const glw::GLuint GetLevelParameterTest::s_texture_width  = 4;
7918 const glw::GLuint GetLevelParameterTest::s_texture_height = 4;
7919 const glw::GLuint GetLevelParameterTest::s_texture_depth  = 4;
7920 
7921 /** @brief Get Level Parameter Test cases.
7922  *
7923  *  @return Iteration result.
7924  */
iterate()7925 tcu::TestNode::IterateResult GetLevelParameterTest::iterate()
7926 {
7927     /* Shortcut for GL functionality. */
7928     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
7929 
7930     /* Get context setup. */
7931     bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
7932     bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
7933 
7934     if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
7935     {
7936         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
7937 
7938         return STOP;
7939     }
7940 
7941     /* Running tests. */
7942     bool is_ok    = true;
7943     bool is_error = false;
7944 
7945     /* Objects. */
7946     glw::GLuint texture = 0;
7947 
7948     try
7949     {
7950         /* Texture initiation. */
7951         gl.genTextures(1, &texture);
7952         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
7953 
7954         gl.bindTexture(GL_TEXTURE_3D, texture);
7955         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
7956 
7957         gl.texImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, s_texture_width, s_texture_height, s_texture_depth, 0, GL_RGBA,
7958                       GL_UNSIGNED_BYTE, s_texture_data);
7959         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
7960 
7961         gl.texImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, s_texture_width / 2, s_texture_height / 2, s_texture_depth / 2, 0,
7962                       GL_RGBA, GL_UNSIGNED_BYTE, s_texture_data);
7963         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
7964 
7965         static const glw::GLenum pnames[]     = {GL_TEXTURE_WIDTH,           GL_TEXTURE_HEIGHT,     GL_TEXTURE_DEPTH,
7966                                                  GL_TEXTURE_INTERNAL_FORMAT, GL_TEXTURE_RED_TYPE,   GL_TEXTURE_GREEN_TYPE,
7967                                                  GL_TEXTURE_BLUE_TYPE,       GL_TEXTURE_ALPHA_TYPE, GL_TEXTURE_DEPTH_TYPE,
7968                                                  GL_TEXTURE_RED_SIZE,        GL_TEXTURE_GREEN_SIZE, GL_TEXTURE_BLUE_SIZE,
7969                                                  GL_TEXTURE_ALPHA_SIZE,      GL_TEXTURE_DEPTH_SIZE, GL_TEXTURE_COMPRESSED};
7970         static const glw::GLuint pnames_count = sizeof(pnames) / sizeof(pnames[0]);
7971 
7972         /* Test GetTextureLevelParameteriv. */
7973         for (glw::GLuint i = 0; i < 2 /* levels */; ++i)
7974         {
7975             for (glw::GLuint j = 0; j < pnames_count; ++j)
7976             {
7977                 glw::GLint result_legacy = 0;
7978                 glw::GLint result_dsa    = 0;
7979 
7980                 /* Quering reference value. */
7981                 gl.getTexLevelParameteriv(GL_TEXTURE_3D, i, pnames[j], &result_legacy);
7982                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
7983 
7984                 /* Quering using DSA function. */
7985                 gl.getTextureLevelParameteriv(texture, i, pnames[j], &result_dsa);
7986 
7987                 /* Check for errors. */
7988                 glw::GLenum error = GL_NO_ERROR;
7989 
7990                 if (GL_NO_ERROR != (error = gl.getError()))
7991                 {
7992                     m_context.getTestContext().getLog()
7993                         << tcu::TestLog::Message << "GetTextureLevelParameteriv unexpectedly generated error "
7994                         << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
7995 
7996                     is_ok = false;
7997                 }
7998                 else
7999                 {
8000                     /* Compare values. */
8001                     if (result_legacy != result_dsa)
8002                     {
8003                         m_context.getTestContext().getLog()
8004                             << tcu::TestLog::Message << "For parameter name "
8005                             << glu::getTextureLevelParameterStr(pnames[j]) << " GetTextureLevelParameteriv returned "
8006                             << result_dsa << ", but reference value (queried using GetTexLevelParameteriv) was "
8007                             << result_legacy << ". Test fails." << tcu::TestLog::EndMessage;
8008 
8009                         is_ok = false;
8010                     }
8011                 }
8012             }
8013         }
8014 
8015         /* Test GetTextureLevelParameterfv. */
8016         for (glw::GLuint i = 0; i < 2 /* levels */; ++i)
8017         {
8018             for (glw::GLuint j = 0; j < pnames_count; ++j)
8019             {
8020                 glw::GLfloat result_legacy = 0.f;
8021                 glw::GLfloat result_dsa    = 0.f;
8022 
8023                 /* Quering reference value. */
8024                 gl.getTexLevelParameterfv(GL_TEXTURE_3D, i, pnames[j], &result_legacy);
8025                 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameterfv has failed");
8026 
8027                 /* Quering using DSA function. */
8028                 gl.getTextureLevelParameterfv(texture, i, pnames[j], &result_dsa);
8029 
8030                 /* Check for errors. */
8031                 glw::GLenum error = GL_NO_ERROR;
8032 
8033                 if (GL_NO_ERROR != (error = gl.getError()))
8034                 {
8035                     m_context.getTestContext().getLog()
8036                         << tcu::TestLog::Message << "GetTextureLevelParameterfv unexpectedly generated error "
8037                         << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage;
8038 
8039                     is_ok = false;
8040                 }
8041                 else
8042                 {
8043                     /* Compare values. */
8044                     if (de::abs(result_legacy - result_dsa) > 0.125 /* Precision. */)
8045                     {
8046                         m_context.getTestContext().getLog()
8047                             << tcu::TestLog::Message << "For parameter name "
8048                             << glu::getTextureLevelParameterStr(pnames[j]) << " GetTextureLevelParameterfv returned "
8049                             << result_dsa << ", but reference value (queried using GetTexLevelParameterfv) was "
8050                             << result_legacy << ". Test fails." << tcu::TestLog::EndMessage;
8051 
8052                         is_ok = false;
8053                     }
8054                 }
8055             }
8056         }
8057     }
8058     catch (...)
8059     {
8060         is_ok    = false;
8061         is_error = true;
8062     }
8063 
8064     /* Cleanup. */
8065     if (texture)
8066     {
8067         gl.deleteTextures(1, &texture);
8068     }
8069 
8070     while (GL_NO_ERROR != gl.getError())
8071         ;
8072 
8073     /* Result's setup. */
8074     if (is_ok)
8075     {
8076         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
8077     }
8078     else
8079     {
8080         if (is_error)
8081         {
8082             m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
8083         }
8084         else
8085         {
8086             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
8087         }
8088     }
8089 
8090     return STOP;
8091 }
8092 
8093 /*********************************** Errors Utility Class *****************************************************/
8094 
8095 /** @brief Check for errors and log.
8096  *
8097  *  @param [in] context             Test's context.
8098  *  @param [in] expected_error      Expected error value.
8099  *  @param [in] function_name       Name of the function (to be logged).
8100  *  @param [in] log                 Log message.
8101  *
8102  *  @return True if error is equal to expected, false otherwise.
8103  */
CheckErrorAndLog(deqp::Context & context,glw::GLuint expected_error,const glw::GLchar * function_name,const glw::GLchar * log)8104 bool ErrorsUtilities::CheckErrorAndLog(deqp::Context &context, glw::GLuint expected_error,
8105                                        const glw::GLchar *function_name, const glw::GLchar *log)
8106 {
8107     /* Shortcut for GL functionality. */
8108     const glw::Functions &gl = context.getRenderContext().getFunctions();
8109 
8110     /* Check error. */
8111     glw::GLenum error = GL_NO_ERROR;
8112 
8113     if (expected_error != (error = gl.getError()))
8114     {
8115         context.getTestContext().getLog()
8116             << tcu::TestLog::Message << function_name << " generated error " << glu::getErrorStr(error) << " but, "
8117             << glu::getErrorStr(expected_error) << " was expected if " << log << tcu::TestLog::EndMessage;
8118 
8119         return false;
8120     }
8121 
8122     return true;
8123 }
8124 
8125 /******************************** Creation Errors Test Implementation   ********************************/
8126 
8127 /** @brief Creation Errors Test constructor.
8128  *
8129  *  @param [in] context     OpenGL context.
8130  */
CreationErrorsTest(deqp::Context & context)8131 CreationErrorsTest::CreationErrorsTest(deqp::Context &context)
8132     : deqp::TestCase(context, "textures_creation_errors", "Texture Objects Creation Errors Test")
8133 {
8134     /* Intentionally left blank. */
8135 }
8136 
8137 /** @brief Iterate Creation Errors Test cases.
8138  *
8139  *  @return Iteration result.
8140  */
iterate()8141 tcu::TestNode::IterateResult CreationErrorsTest::iterate()
8142 {
8143     /* Shortcut for GL functionality. */
8144     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
8145 
8146     /* Get context setup. */
8147     bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
8148     bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
8149 
8150     if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
8151     {
8152         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
8153 
8154         return STOP;
8155     }
8156 
8157     /* Running tests. */
8158     bool is_ok    = true;
8159     bool is_error = false;
8160 
8161     /* Textures' objects */
8162     glw::GLuint texture = 0;
8163 
8164     try
8165     {
8166         /* Not a target test. */
8167         gl.createTextures(NotATarget(), 1, &texture);
8168         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glCreateTextures",
8169                                   "target is not one of the allowable values.");
8170 
8171         if (texture)
8172         {
8173             gl.deleteTextures(1, &texture);
8174 
8175             texture = 0;
8176         }
8177 
8178         /* Negative number of textures. */
8179         gl.createTextures(GL_TEXTURE_2D, -1, &texture);
8180         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCreateTextures", "n is negative.");
8181     }
8182     catch (...)
8183     {
8184         is_ok    = false;
8185         is_error = true;
8186     }
8187 
8188     /* Cleanup. */
8189     if (texture)
8190     {
8191         gl.deleteTextures(1, &texture);
8192     }
8193 
8194     /* Errors clean up. */
8195     while (gl.getError())
8196         ;
8197 
8198     /* Result's setup. */
8199     if (is_ok)
8200     {
8201         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
8202     }
8203     else
8204     {
8205         if (is_error)
8206         {
8207             m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
8208         }
8209         else
8210         {
8211             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
8212         }
8213     }
8214 
8215     return STOP;
8216 }
8217 
8218 /** @brief Function retruns enum which is not a texture target.
8219  */
NotATarget()8220 glw::GLenum CreationErrorsTest::NotATarget()
8221 {
8222     static const glw::GLenum texture_targets[] = {GL_TEXTURE_1D,
8223                                                   GL_TEXTURE_2D,
8224                                                   GL_TEXTURE_3D,
8225                                                   GL_TEXTURE_1D_ARRAY,
8226                                                   GL_TEXTURE_2D_ARRAY,
8227                                                   GL_TEXTURE_RECTANGLE,
8228                                                   GL_TEXTURE_CUBE_MAP,
8229                                                   GL_TEXTURE_CUBE_MAP_ARRAY,
8230                                                   GL_TEXTURE_BUFFER,
8231                                                   GL_TEXTURE_2D_MULTISAMPLE,
8232                                                   GL_TEXTURE_2D_MULTISAMPLE_ARRAY};
8233 
8234     glw::GLenum not_a_target = 0;
8235     bool is_target           = true;
8236 
8237     while (is_target)
8238     {
8239         not_a_target++;
8240 
8241         is_target = false;
8242 
8243         for (glw::GLuint i = 0; i < sizeof(texture_targets) / sizeof(texture_targets[0]); ++i)
8244         {
8245             if (texture_targets[i] == not_a_target)
8246             {
8247                 is_target = true;
8248                 break;
8249             }
8250         }
8251     }
8252 
8253     return not_a_target;
8254 }
8255 
8256 /******************************** Texture Buffer Errors Test Implementation   ********************************/
8257 
8258 /** @brief Texture Buffer Errors Test constructor.
8259  *
8260  *  @param [in] context     OpenGL context.
8261  */
BufferErrorsTest(deqp::Context & context)8262 BufferErrorsTest::BufferErrorsTest(deqp::Context &context)
8263     : deqp::TestCase(context, "textures_buffer_errors", "Texture Buffer Errors Test")
8264 {
8265     /* Intentionally left blank. */
8266 }
8267 
8268 /** @brief Iterate Texture Buffer Errors Test cases.
8269  *
8270  *  @return Iteration result.
8271  */
iterate()8272 tcu::TestNode::IterateResult BufferErrorsTest::iterate()
8273 {
8274     /* Shortcut for GL functionality. */
8275     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
8276 
8277     /* Get context setup. */
8278     bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
8279     bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
8280 
8281     if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
8282     {
8283         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
8284 
8285         return STOP;
8286     }
8287 
8288     /* Running tests. */
8289     bool is_ok    = true;
8290     bool is_error = false;
8291 
8292     /* Textures' objects */
8293     glw::GLuint texture_buffer = 0;
8294     glw::GLuint texture_1D     = 0;
8295     glw::GLuint buffer         = 0;
8296 
8297     static const glw::GLubyte data[4]  = {1, 2, 3, 4};
8298     static const glw::GLuint data_size = sizeof(data);
8299 
8300     try
8301     {
8302         /* Auxiliary objects setup. */
8303         gl.createTextures(GL_TEXTURE_BUFFER, 1, &texture_buffer);
8304         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8305 
8306         gl.createTextures(GL_TEXTURE_1D, 1, &texture_1D);
8307         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8308 
8309         gl.createBuffers(1, &buffer);
8310         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateBuffers has failed");
8311 
8312         gl.namedBufferData(buffer, data_size, data, GL_STATIC_COPY);
8313         GLU_EXPECT_NO_ERROR(gl.getError(), "glNamedBufferData has failed");
8314 
8315         /*  Check that INVALID_OPERATION is generated by glTextureBuffer if texture
8316          is not the name of an existing texture object. */
8317         {
8318             glw::GLuint not_a_texture = 0;
8319 
8320             while (gl.isTexture(++not_a_texture))
8321                 ;
8322             GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed");
8323 
8324             gl.textureBuffer(not_a_texture, GL_RGBA8, buffer);
8325 
8326             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureBuffer",
8327                                       "texture is not the name of an existing texture object.");
8328         }
8329 
8330         /*  Check that INVALID_ENUM is generated by glTextureBuffer if the effective
8331          target of texture is not TEXTURE_BUFFER. */
8332         {
8333             gl.textureBuffer(texture_1D, GL_RGBA8, buffer);
8334 
8335             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureBuffer",
8336                                       "the effective target of texture is not TEXTURE_BUFFER.");
8337         }
8338 
8339         /*  Check that INVALID_ENUM is generated if internalformat is not one of the
8340          sized internal formats described above. */
8341         {
8342             gl.textureBuffer(texture_buffer, GL_COMPRESSED_SIGNED_RED_RGTC1, buffer);
8343 
8344             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureBuffer",
8345                                       "internalformat is not one of the sized internal formats described above..");
8346         }
8347 
8348         /*  Check that INVALID_OPERATION is generated if buffer is not zero and is
8349          not the name of an existing buffer object. */
8350         {
8351             glw::GLuint not_a_buffer = 0;
8352 
8353             while (gl.isBuffer(++not_a_buffer))
8354                 ;
8355             GLU_EXPECT_NO_ERROR(gl.getError(), "glIsBuffer has failed");
8356 
8357             gl.textureBuffer(texture_buffer, GL_RGBA8, not_a_buffer);
8358 
8359             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureBuffer",
8360                                       "buffer is not zero and is not the name of an existing buffer object.");
8361         }
8362     }
8363     catch (...)
8364     {
8365         is_ok    = false;
8366         is_error = true;
8367     }
8368 
8369     /* Cleanup. */
8370     if (texture_1D)
8371     {
8372         gl.deleteTextures(1, &texture_1D);
8373     }
8374 
8375     if (texture_buffer)
8376     {
8377         gl.deleteTextures(1, &texture_buffer);
8378     }
8379 
8380     if (buffer)
8381     {
8382         gl.deleteBuffers(1, &buffer);
8383     }
8384 
8385     /* Errors clean up. */
8386     while (gl.getError())
8387         ;
8388 
8389     /* Result's setup. */
8390     if (is_ok)
8391     {
8392         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
8393     }
8394     else
8395     {
8396         if (is_error)
8397         {
8398             m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
8399         }
8400         else
8401         {
8402             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
8403         }
8404     }
8405 
8406     return STOP;
8407 }
8408 
8409 /******************************** Texture Buffer Range Errors Test Implementation   ********************************/
8410 
8411 /** @brief Texture Buffer Range Errors Test constructor.
8412  *
8413  *  @param [in] context     OpenGL context.
8414  */
BufferRangeErrorsTest(deqp::Context & context)8415 BufferRangeErrorsTest::BufferRangeErrorsTest(deqp::Context &context)
8416     : deqp::TestCase(context, "textures_buffer_range_errors", "Texture Buffer Range Errors Test")
8417 {
8418     /* Intentionally left blank. */
8419 }
8420 
8421 /** @brief Iterate Texture Buffer Range Errors Test cases.
8422  *
8423  *  @return Iteration result.
8424  */
iterate()8425 tcu::TestNode::IterateResult BufferRangeErrorsTest::iterate()
8426 {
8427     /* Shortcut for GL functionality. */
8428     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
8429 
8430     /* Get context setup. */
8431     bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
8432     bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
8433 
8434     if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
8435     {
8436         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
8437 
8438         return STOP;
8439     }
8440 
8441     /* Running tests. */
8442     bool is_ok    = true;
8443     bool is_error = false;
8444 
8445     /* Textures' objects */
8446     glw::GLuint texture_buffer = 0;
8447     glw::GLuint texture_1D     = 0;
8448     glw::GLuint buffer         = 0;
8449 
8450     static const glw::GLubyte data[4]  = {1, 2, 3, 4};
8451     static const glw::GLuint data_size = sizeof(data);
8452 
8453     try
8454     {
8455         /* Auxiliary objects setup. */
8456         gl.createTextures(GL_TEXTURE_BUFFER, 1, &texture_buffer);
8457         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8458 
8459         gl.createTextures(GL_TEXTURE_1D, 1, &texture_1D);
8460         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8461 
8462         gl.createBuffers(1, &buffer);
8463         GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateBuffers has failed");
8464 
8465         gl.namedBufferData(buffer, data_size, data, GL_STATIC_COPY);
8466         GLU_EXPECT_NO_ERROR(gl.getError(), "glNamedBufferData has failed");
8467 
8468         /*  Check that INVALID_OPERATION is generated by TextureBufferRange if
8469          texture is not the name of an existing texture object.*/
8470         {
8471             glw::GLuint not_a_texture = 0;
8472 
8473             while (gl.isTexture(++not_a_texture))
8474                 ;
8475             GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed");
8476 
8477             gl.textureBufferRange(not_a_texture, GL_RGBA8, buffer, 0, data_size);
8478 
8479             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureBufferRange",
8480                                       "texture is not the name of an existing texture object.");
8481         }
8482 
8483         /*  Check that INVALID_ENUM is generated by TextureBufferRange if the
8484          effective target of texture is not TEXTURE_BUFFER. */
8485         {
8486             gl.textureBufferRange(texture_1D, GL_RGBA8, buffer, 0, data_size);
8487 
8488             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureBufferRange",
8489                                       "the effective target of texture is not TEXTURE_BUFFER.");
8490         }
8491 
8492         /*  Check that INVALID_ENUM is generated by TextureBufferRange if
8493          internalformat is not one of the sized internal formats described above. */
8494         {
8495             gl.textureBufferRange(texture_buffer, GL_COMPRESSED_SIGNED_RED_RGTC1, buffer, 0, data_size);
8496 
8497             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureBufferRange",
8498                                       "internalformat is not one of the supported sized internal formats.");
8499         }
8500 
8501         /*  Check that INVALID_OPERATION is generated by TextureBufferRange if
8502          buffer is not zero and is not the name of an existing buffer object. */
8503         {
8504             glw::GLuint not_a_buffer = 0;
8505 
8506             while (gl.isBuffer(++not_a_buffer))
8507                 ;
8508             GLU_EXPECT_NO_ERROR(gl.getError(), "glIsBuffer has failed");
8509 
8510             gl.textureBufferRange(texture_buffer, GL_RGBA8, not_a_buffer, 0, data_size);
8511 
8512             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureBufferRange",
8513                                       "buffer is not zero and is not the name of an existing buffer object.");
8514         }
8515 
8516         /* Check that INVALID_VALUE is generated by TextureBufferRange if offset
8517          is negative, if size is less than or equal to zero, or if offset + size
8518          is greater than the value of BUFFER_SIZE for buffer. */
8519         {
8520             gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, -1, data_size);
8521 
8522             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureBufferRange", "offset is negative.");
8523 
8524             gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, 0, 0);
8525 
8526             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureBufferRange", "size is zero.");
8527 
8528             gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, 0, -1);
8529 
8530             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureBufferRange", "size is negative.");
8531 
8532             gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, 0, data_size * 16);
8533 
8534             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureBufferRange",
8535                                       "size is greater than the value of BUFFER_SIZE for buffer.");
8536         }
8537 
8538         /* Check that INVALID_VALUE is generated by TextureBufferRange if offset is
8539          not an integer multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT. */
8540         {
8541             glw::GLint gl_texture_buffer_offset_alignment = 0;
8542 
8543             gl.getIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, &gl_texture_buffer_offset_alignment);
8544 
8545             /* If alignmet is 1 we cannot do anything. Error situtation is impossible then. */
8546             if (gl_texture_buffer_offset_alignment > 1)
8547             {
8548                 gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, 1, data_size - 1);
8549 
8550                 is_ok &= CheckErrorAndLog(
8551                     m_context, GL_INVALID_VALUE, "glTextureBufferRange",
8552                     "offset is not an integer multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT.");
8553             }
8554         }
8555     }
8556     catch (...)
8557     {
8558         is_ok    = false;
8559         is_error = true;
8560     }
8561 
8562     /* Cleanup. */
8563     if (texture_1D)
8564     {
8565         gl.deleteTextures(1, &texture_1D);
8566     }
8567 
8568     if (texture_buffer)
8569     {
8570         gl.deleteTextures(1, &texture_buffer);
8571     }
8572 
8573     if (buffer)
8574     {
8575         gl.deleteBuffers(1, &buffer);
8576     }
8577 
8578     /* Errors clean up. */
8579     while (gl.getError())
8580         ;
8581 
8582     /* Result's setup. */
8583     if (is_ok)
8584     {
8585         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
8586     }
8587     else
8588     {
8589         if (is_error)
8590         {
8591             m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
8592         }
8593         else
8594         {
8595             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
8596         }
8597     }
8598 
8599     return STOP;
8600 }
8601 
8602 /******************************** Texture Storage Errors Test Implementation   ********************************/
8603 
8604 /** @brief Texture Storage Errors Test constructor.
8605  *
8606  *  @param [in] context     OpenGL context.
8607  */
StorageErrorsTest(deqp::Context & context)8608 StorageErrorsTest::StorageErrorsTest(deqp::Context &context)
8609     : deqp::TestCase(context, "textures_storage_errors", "Texture Storage Errors Test")
8610     , m_to_1D(0)
8611     , m_to_1D_array(0)
8612     , m_to_2D(0)
8613     , m_to_2D_array(0)
8614     , m_to_3D(0)
8615     , m_to_2D_ms(0)
8616     , m_to_2D_ms_immutable(0)
8617     , m_to_3D_ms(0)
8618     , m_to_3D_ms_immutable(0)
8619     , m_to_invalid(0)
8620     , m_internalformat_invalid(0)
8621     , m_max_texture_size(1)
8622     , m_max_samples(1)
8623     , m_max_array_texture_layers(1)
8624 {
8625     /* Intentionally left blank. */
8626 }
8627 
8628 /** @brief Iterate Texture Storage Errors Test cases.
8629  *
8630  *  @return Iteration result.
8631  */
iterate()8632 tcu::TestNode::IterateResult StorageErrorsTest::iterate()
8633 {
8634     /* Get context setup. */
8635     bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
8636     bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
8637 
8638     if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
8639     {
8640         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
8641 
8642         return STOP;
8643     }
8644 
8645     /* Running tests. */
8646     bool is_ok    = true;
8647     bool is_error = false;
8648 
8649     try
8650     {
8651         Prepare();
8652 
8653         is_ok &= Test1D();
8654         is_ok &= Test2D();
8655         is_ok &= Test3D();
8656         is_ok &= Test2DMultisample();
8657         is_ok &= Test3DMultisample();
8658     }
8659     catch (...)
8660     {
8661         is_ok    = false;
8662         is_error = true;
8663     }
8664 
8665     /* Cleanup. */
8666     Clean();
8667 
8668     /* Result's setup. */
8669     if (is_ok)
8670     {
8671         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
8672     }
8673     else
8674     {
8675         if (is_error)
8676         {
8677             m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
8678         }
8679         else
8680         {
8681             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
8682         }
8683     }
8684 
8685     return STOP;
8686 }
8687 
8688 /** @brief Prepare test objects.
8689  */
Prepare()8690 void StorageErrorsTest::Prepare()
8691 {
8692     /* Shortcut for GL functionality. */
8693     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
8694 
8695     /* Auxiliary objects setup. */
8696 
8697     /* 1D */
8698     gl.createTextures(GL_TEXTURE_1D, 1, &m_to_1D);
8699     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8700 
8701     /* 1D ARRAY */
8702     gl.createTextures(GL_TEXTURE_1D_ARRAY, 1, &m_to_1D_array);
8703     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8704 
8705     /* 2D */
8706     gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D);
8707     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8708 
8709     /* 2D ARRAY */
8710     gl.createTextures(GL_TEXTURE_2D_ARRAY, 1, &m_to_2D_array);
8711     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8712 
8713     /* 3D */
8714     gl.createTextures(GL_TEXTURE_3D, 1, &m_to_3D);
8715     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8716 
8717     /* 2D Multisample */
8718     gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &m_to_2D_ms);
8719     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8720 
8721     /* 2D Multisample with storage */
8722     gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &m_to_2D_ms_immutable);
8723     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8724 
8725     gl.textureStorage2DMultisample(m_to_2D_ms_immutable, 1, GL_R8, 16, 16, false);
8726     GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2DMultisample has failed");
8727 
8728     /* 3D Multisample */
8729     gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 1, &m_to_3D_ms);
8730     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8731 
8732     /* 3D Multisample with storage */
8733     gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 1, &m_to_3D_ms_immutable);
8734     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
8735 
8736     gl.textureStorage3DMultisample(m_to_3D_ms_immutable, 1, GL_R8, 16, 16, 16, false);
8737     GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2DMultisample has failed");
8738 
8739     /* Invalid values */
8740 
8741     /* invalid texture object */
8742     while (gl.isTexture(++m_to_invalid))
8743         ;
8744     GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed");
8745 
8746     /* invalid internal format */
8747     static const glw::GLenum all_internal_formats[] = {GL_R8,
8748                                                        GL_R8_SNORM,
8749                                                        GL_R16,
8750                                                        GL_R16_SNORM,
8751                                                        GL_RG8,
8752                                                        GL_RG8_SNORM,
8753                                                        GL_RG16,
8754                                                        GL_RG16_SNORM,
8755                                                        GL_R3_G3_B2,
8756                                                        GL_RGB4,
8757                                                        GL_RGB5,
8758                                                        GL_RGB565,
8759                                                        GL_RGB8,
8760                                                        GL_RGB8_SNORM,
8761                                                        GL_RGB10,
8762                                                        GL_RGB12,
8763                                                        GL_RGB16,
8764                                                        GL_RGB16_SNORM,
8765                                                        GL_RGBA2,
8766                                                        GL_RGBA4,
8767                                                        GL_RGB5_A1,
8768                                                        GL_RGBA8,
8769                                                        GL_RGBA8_SNORM,
8770                                                        GL_RGB10_A2,
8771                                                        GL_RGB10_A2UI,
8772                                                        GL_RGBA12,
8773                                                        GL_RGBA16,
8774                                                        GL_RGBA16_SNORM,
8775                                                        GL_SRGB8,
8776                                                        GL_SRGB8_ALPHA8,
8777                                                        GL_R16F,
8778                                                        GL_RG16F,
8779                                                        GL_RGB16F,
8780                                                        GL_RGBA16F,
8781                                                        GL_R32F,
8782                                                        GL_RG32F,
8783                                                        GL_RGB32F,
8784                                                        GL_RGBA32F,
8785                                                        GL_R11F_G11F_B10F,
8786                                                        GL_RGB9_E5,
8787                                                        GL_R8I,
8788                                                        GL_R8UI,
8789                                                        GL_R16I,
8790                                                        GL_R16UI,
8791                                                        GL_R32I,
8792                                                        GL_R32UI,
8793                                                        GL_RG8I,
8794                                                        GL_RG8UI,
8795                                                        GL_RG16I,
8796                                                        GL_RG16UI,
8797                                                        GL_RG32I,
8798                                                        GL_RG32UI,
8799                                                        GL_RGB8I,
8800                                                        GL_RGB8UI,
8801                                                        GL_RGB16I,
8802                                                        GL_RGB16UI,
8803                                                        GL_RGB32I,
8804                                                        GL_RGB32UI,
8805                                                        GL_RGBA8I,
8806                                                        GL_RGBA8UI,
8807                                                        GL_RGBA16I,
8808                                                        GL_RGBA16UI,
8809                                                        GL_RGBA32I,
8810                                                        GL_RGBA32UI,
8811                                                        GL_COMPRESSED_RED,
8812                                                        GL_COMPRESSED_RG,
8813                                                        GL_COMPRESSED_RGB,
8814                                                        GL_COMPRESSED_RGBA,
8815                                                        GL_COMPRESSED_SRGB,
8816                                                        GL_COMPRESSED_SRGB_ALPHA,
8817                                                        GL_COMPRESSED_RED_RGTC1,
8818                                                        GL_COMPRESSED_SIGNED_RED_RGTC1,
8819                                                        GL_COMPRESSED_RG_RGTC2,
8820                                                        GL_COMPRESSED_SIGNED_RG_RGTC2,
8821                                                        GL_COMPRESSED_RGBA_BPTC_UNORM,
8822                                                        GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM,
8823                                                        GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT,
8824                                                        GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT,
8825                                                        GL_COMPRESSED_RGB8_ETC2,
8826                                                        GL_COMPRESSED_SRGB8_ETC2,
8827                                                        GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
8828                                                        GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
8829                                                        GL_COMPRESSED_RGBA8_ETC2_EAC,
8830                                                        GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
8831                                                        GL_COMPRESSED_R11_EAC,
8832                                                        GL_COMPRESSED_SIGNED_R11_EAC,
8833                                                        GL_COMPRESSED_RG11_EAC,
8834                                                        GL_COMPRESSED_SIGNED_RG11_EAC,
8835                                                        GL_DEPTH_COMPONENT16,
8836                                                        GL_DEPTH_COMPONENT24,
8837                                                        GL_DEPTH_COMPONENT32,
8838                                                        GL_DEPTH_COMPONENT32F,
8839                                                        GL_DEPTH24_STENCIL8,
8840                                                        GL_DEPTH32F_STENCIL8,
8841                                                        GL_STENCIL_INDEX1,
8842                                                        GL_STENCIL_INDEX4,
8843                                                        GL_STENCIL_INDEX8,
8844                                                        GL_STENCIL_INDEX16};
8845 
8846     static const glw::GLuint all_internal_formats_count =
8847         sizeof(all_internal_formats) / sizeof(all_internal_formats[0]);
8848 
8849     bool is_valid            = true;
8850     m_internalformat_invalid = 0;
8851 
8852     while (is_valid)
8853     {
8854         is_valid = false;
8855         m_internalformat_invalid++;
8856         for (glw::GLuint i = 0; i < all_internal_formats_count; ++i)
8857         {
8858             if (all_internal_formats[i] == m_internalformat_invalid)
8859             {
8860                 is_valid = true;
8861                 break;
8862             }
8863         }
8864     }
8865 
8866     /* Maximum texture size.*/
8867     gl.getIntegerv(GL_MAX_TEXTURE_SIZE, &m_max_texture_size);
8868     GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
8869 
8870     /* Maximum number of samples. */
8871     gl.getInternalformativ(GL_RENDERBUFFER, GL_R8, GL_SAMPLES, 1, &m_max_samples);
8872     GLU_EXPECT_NO_ERROR(gl.getError(), "glGetInternalformativ has failed");
8873 
8874     /* Maximum number of array texture layers. */
8875     gl.getIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &m_max_array_texture_layers);
8876     GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
8877 }
8878 
8879 /** @brief Test TextureStorage1D
8880  *
8881  *  @return Test result.
8882  */
Test1D()8883 bool StorageErrorsTest::Test1D()
8884 {
8885     /* Shortcut for GL functionality. */
8886     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
8887 
8888     /* Result. */
8889     bool is_ok = true;
8890 
8891     /*  Check that INVALID_OPERATION is generated by TextureStorage1D if texture
8892      is not the name of an existing texture object. */
8893     {
8894         gl.textureStorage1D(m_to_invalid, 1, GL_R8, 8);
8895         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage1D",
8896                                   "texture is not the name of an existing texture object.");
8897     }
8898 
8899     /*  Check that INVALID_ENUM is generated by TextureStorage1D if
8900      internalformat is not a valid sized internal format. */
8901     {
8902         gl.textureStorage1D(m_to_1D, 1, m_internalformat_invalid, 8);
8903         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureStorage1D",
8904                                   "internalformat is not a valid sized internal format.");
8905     }
8906 
8907     /*  Check that INVALID_ENUM is generated by TextureStorage1D if target or
8908      the effective target of texture is not one of the accepted targets
8909      described above. */
8910     {
8911         gl.textureStorage1D(m_to_2D, 1, GL_R8, 8);
8912         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage1D",
8913                                   "the effective target of texture is not one of the accepted targets.");
8914     }
8915 
8916     /*  Check that INVALID_VALUE is generated by TextureStorage1D if width or
8917      levels are less than 1. */
8918     {
8919         gl.textureStorage1D(m_to_1D, 0, GL_R8, 8);
8920         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage1D", "levels is less than 1.");
8921 
8922         gl.textureStorage1D(m_to_1D, 1, GL_R8, 0);
8923         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage1D", "width is less than 1.");
8924     }
8925 
8926     /*  Check that INVALID_OPERATION is generated by TextureStorage1D if levels
8927      is greater than log2(width)+1. */
8928     {
8929         gl.textureStorage1D(m_to_1D, 8, GL_R8, 8);
8930         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage1D",
8931                                   "levels is greater than log2(width)+1.");
8932     }
8933 
8934     return is_ok;
8935 }
8936 
8937 /** @brief Test TextureStorage2D
8938  *
8939  *  @return Test result.
8940  */
Test2D()8941 bool StorageErrorsTest::Test2D()
8942 {
8943     /* Shortcut for GL functionality. */
8944     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
8945 
8946     /* Result. */
8947     bool is_ok = true;
8948 
8949     /*  Check that INVALID_OPERATION is generated by TextureStorage2D if
8950      texture is not the name of an existing texture object. */
8951     {
8952         gl.textureStorage2D(m_to_invalid, 1, GL_R8, 8, 8);
8953         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2D",
8954                                   "texture is not the name of an existing texture object.");
8955     }
8956 
8957     /*  Check that INVALID_ENUM is generated by TextureStorage2D if
8958      internalformat is not a valid sized internal format. */
8959     {
8960         gl.textureStorage2D(m_to_2D, 1, m_internalformat_invalid, 8, 8);
8961         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureStorage2D",
8962                                   "internalformat is not a valid sized internal format.");
8963     }
8964 
8965     /*  Check that INVALID_ENUM is generated by TextureStorage2D if target or
8966      the effective target of texture is not one of the accepted targets
8967      described above. */
8968     {
8969         gl.textureStorage2D(m_to_1D, 1, GL_R8, 8, 8);
8970         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2D",
8971                                   "the effective target of texture is not one of the accepted targets.");
8972     }
8973 
8974     /*  Check that INVALID_VALUE is generated by TextureStorage2D if width,
8975      height or levels are less than 1. */
8976     {
8977         gl.textureStorage2D(m_to_2D, 0, GL_R8, 8, 8);
8978         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2D", "levels is less than 1.");
8979 
8980         gl.textureStorage2D(m_to_2D, 1, GL_R8, 0, 8);
8981         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2D", "width is less than 1.");
8982 
8983         gl.textureStorage2D(m_to_2D, 1, GL_R8, 8, 0);
8984         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2D", "height is less than 1.");
8985     }
8986 
8987     /* Check that INVALID_OPERATION is generated by TextureStorage2D if target
8988      is TEXTURE_1D_ARRAY or PROXY_TEXTURE_1D_ARRAY and levels is greater than
8989      log2(width)+1. */
8990     {
8991         gl.textureStorage2D(m_to_1D_array, 8, GL_R8, 8, 8);
8992         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2D",
8993                                   "target is TEXTURE_1D_ARRAY and levels is greater than log2(width)+1.");
8994     }
8995 
8996     /*  Check that INVALID_OPERATION is generated by TextureStorage2D if target
8997      is not TEXTURE_1D_ARRAY or PROXY_TEXTURE_1D_ARRAY and levels is greater
8998      than log2(max(width, height))+1.  */
8999     {
9000         gl.textureStorage2D(m_to_2D, 8, GL_R8, 8, 8);
9001         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2D",
9002                                   "target is TEXTURE_2D and levels is greater than log2(max(width, height))+1.");
9003     }
9004 
9005     return is_ok;
9006 }
9007 
9008 /** @brief Test TextureStorage3D
9009  *
9010  *  @return Test result.
9011  */
Test3D()9012 bool StorageErrorsTest::Test3D()
9013 {
9014     /* Shortcut for GL functionality. */
9015     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
9016 
9017     /* Result. */
9018     bool is_ok = true;
9019 
9020     /*  Check that INVALID_OPERATION is generated by TextureStorage3D if texture
9021      is not the name of an existing texture object. */
9022     {
9023         gl.textureStorage3D(m_to_invalid, 1, GL_R8, 8, 8, 8);
9024         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3D",
9025                                   "texture is not the name of an existing texture object.");
9026     }
9027 
9028     /*  Check that INVALID_ENUM is generated by TextureStorage3D if
9029      internalformat is not a valid sized internal format. */
9030     {
9031         gl.textureStorage3D(m_to_3D, 1, m_internalformat_invalid, 8, 8, 8);
9032         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureStorage3D",
9033                                   "internalformat is not a valid sized internal format.");
9034     }
9035 
9036     /*  Check that INVALID_ENUM is generated by TextureStorage3D if target or
9037      the effective target of texture is not one of the accepted targets
9038      described above. */
9039     {
9040         gl.textureStorage3D(m_to_1D, 1, GL_R8, 8, 8, 8);
9041         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3D",
9042                                   "the effective target of texture is not one of the accepted targets.");
9043     }
9044 
9045     /*  Check that INVALID_VALUE is generated by TextureStorage3D if width,
9046      height, depth or levels are less than 1. */
9047     {
9048         gl.textureStorage3D(m_to_3D, 0, GL_R8, 8, 8, 8);
9049         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3D", "levels is less than 1.");
9050 
9051         gl.textureStorage3D(m_to_3D, 1, GL_R8, 0, 8, 8);
9052         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3D", "width is less than 1.");
9053 
9054         gl.textureStorage3D(m_to_3D, 1, GL_R8, 8, 0, 8);
9055         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3D", "height is less than 1.");
9056 
9057         gl.textureStorage3D(m_to_3D, 1, GL_R8, 8, 8, 0);
9058         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3D", "depth is less than 1.");
9059     }
9060 
9061     /* Check that INVALID_OPERATION is generated by TextureStorage3D if target
9062      is TEXTURE_3D or PROXY_TEXTURE_3D and levels is greater than
9063      log2(max(width, height, depth))+1. */
9064     {
9065         gl.textureStorage3D(m_to_3D, 8, GL_R8, 8, 8, 8);
9066         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3D",
9067                                   "target is TEXTURE_3D and levels is greater than log2(max(width, height, depth))+1.");
9068     }
9069 
9070     /*  Check that INVALID_OPERATION is generated by TextureStorage3D if target
9071      is TEXTURE_2D_ARRAY, PROXY_TEXTURE_2D_ARRAY, TEXURE_CUBE_ARRAY,
9072      or PROXY_TEXTURE_CUBE_MAP_ARRAY and levels is greater than
9073      log2(max(width, height))+1.  */
9074     {
9075         gl.textureStorage3D(m_to_2D_array, 6, GL_R8, 8, 8, 256);
9076         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3D",
9077                                   "target is TEXTURE_2D_ARRAY and levels is greater than log2(max(width, height))+1.");
9078     }
9079 
9080     return is_ok;
9081 }
9082 
9083 /** @brief Test TextureStorage2DMultisample
9084  *
9085  *  @return Test result.
9086  */
Test2DMultisample()9087 bool StorageErrorsTest::Test2DMultisample()
9088 {
9089     /* Shortcut for GL functionality. */
9090     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
9091 
9092     /* Result. */
9093     bool is_ok = true;
9094 
9095     /*  Check that INVALID_OPERATION is generated by TextureStorage2DMultisample
9096      if texture is not the name of an existing texture object. */
9097     {
9098         gl.textureStorage2DMultisample(m_to_invalid, 1, GL_R8, 8, 8, false);
9099         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2DMultisample",
9100                                   "texture is not the name of an existing texture object.");
9101     }
9102 
9103     /*  Check that INVALID_ENUM is generated by TextureStorage2DMultisample if
9104      internalformat is not a valid color-renderable, depth-renderable or
9105      stencil-renderable format. */
9106     {
9107         gl.textureStorage2DMultisample(m_to_2D_ms, 1, m_internalformat_invalid, 8, 8, false);
9108         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureStorage2DMultisample",
9109                                   "internalformat is not a valid sized internal format.");
9110     }
9111 
9112     /*  Check that INVALID_OPERATION is generated by TextureStorage2DMultisample if
9113      target or the effective target of texture is not one of the accepted
9114      targets described above. */
9115     {
9116         gl.textureStorage2DMultisample(m_to_1D, 1, GL_R8, 8, 8, false);
9117         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2DMultisample",
9118                                   "the effective target of texture is not one of the accepted targets.");
9119     }
9120 
9121     /* Check that INVALID_VALUE is generated by TextureStorage2DMultisample if
9122      width or height are less than 1 or greater than the value of
9123      MAX_TEXTURE_SIZE. */
9124     {
9125         gl.textureStorage2DMultisample(m_to_2D_ms, 1, GL_R8, 0, 8, false);
9126         is_ok &=
9127             CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2DMultisample", "width is less than 1.");
9128 
9129         gl.textureStorage2DMultisample(m_to_2D_ms, 1, GL_R8, 8, 0, false);
9130         is_ok &=
9131             CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2DMultisample", "height is less than 1.");
9132 
9133         gl.textureStorage2DMultisample(m_to_2D_ms, 1, GL_R8, m_max_texture_size * 2, 8, false);
9134         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2DMultisample",
9135                                   "width is greater than the value of MAX_TEXTURE_SIZE.");
9136 
9137         gl.textureStorage2DMultisample(m_to_2D_ms, 1, GL_R8, 8, m_max_texture_size * 2, false);
9138         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2DMultisample",
9139                                   "height is greater than the value of MAX_TEXTURE_SIZE.");
9140     }
9141 
9142     /* Check that INVALID_OPERATION is generated by TextureStorage2DMultisample if
9143      samples is greater than the value of MAX_SAMPLES. */
9144     {
9145         gl.textureStorage2DMultisample(m_to_2D_ms, m_max_samples * 2, GL_R8, 8, 8, false);
9146         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2DMultisample",
9147                                   "samples is greater than the value of MAX_SAMPLES.");
9148     }
9149 
9150     /* Check that INVALID_OPERATION is generated by TextureStorage2DMultisample
9151      if the value of TEXTURE_IMMUTABLE_FORMAT for the texture bound to target
9152      is not FALSE. */
9153     {
9154         gl.textureStorage2DMultisample(m_to_2D_ms_immutable, 1, GL_R8, 8, 8, false);
9155         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2DMultisample",
9156                                   "samples is greater than the value of MAX_SAMPLES.");
9157     }
9158 
9159     return is_ok;
9160 }
9161 
9162 /** @brief Test TextureStorage3DMultisample
9163  *
9164  *  @return Test result.
9165  */
Test3DMultisample()9166 bool StorageErrorsTest::Test3DMultisample()
9167 {
9168     /* Shortcut for GL functionality. */
9169     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
9170 
9171     /* Result. */
9172     bool is_ok = true;
9173 
9174     /*  Check that INVALID_OPERATION is generated by TextureStorage3DMultisample
9175      if texture is not the name of an existing texture object. */
9176     {
9177         gl.textureStorage3DMultisample(m_to_invalid, 1, GL_R8, 8, 8, 8, false);
9178         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3DMultisample",
9179                                   "texture is not the name of an existing texture object.");
9180     }
9181 
9182     /*  Check that INVALID_ENUM is generated by TextureStorage3DMultisample if
9183      internalformat is not a valid color-renderable, depth-renderable or
9184      stencil-renderable format. */
9185     {
9186         gl.textureStorage3DMultisample(m_to_3D_ms, 1, m_internalformat_invalid, 8, 8, 8, false);
9187         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureStorage3DMultisample",
9188                                   "internalformat is not a valid sized internal format.");
9189     }
9190 
9191     /*  Check that INVALID_OPERATION is generated by TextureStorage3DMultisample if
9192      target or the effective target of texture is not one of the accepted
9193      targets described above. */
9194     {
9195         gl.textureStorage3DMultisample(m_to_1D, 1, GL_R8, 8, 8, 8, false);
9196         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3DMultisample",
9197                                   "the effective target of texture is not one of the accepted targets.");
9198     }
9199 
9200     /* Check that INVALID_VALUE is generated by TextureStorage3DMultisample if
9201      width or height are less than 1 or greater than the value of
9202      MAX_TEXTURE_SIZE. */
9203     {
9204         gl.textureStorage3DMultisample(m_to_3D_ms, 1, GL_R8, 0, 8, 8, false);
9205         is_ok &=
9206             CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3DMultisample", "width is less than 1.");
9207 
9208         gl.textureStorage3DMultisample(m_to_3D_ms, 1, GL_R8, 8, 0, 8, false);
9209         is_ok &=
9210             CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3DMultisample", "height is less than 1.");
9211 
9212         gl.textureStorage3DMultisample(m_to_3D_ms, 1, GL_R8, m_max_texture_size * 2, 8, 8, false);
9213         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3DMultisample",
9214                                   "width is greater than the value of MAX_TEXTURE_SIZE.");
9215 
9216         gl.textureStorage3DMultisample(m_to_3D_ms, 1, GL_R8, 8, m_max_texture_size * 2, 8, false);
9217         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3DMultisample",
9218                                   "height is greater than the value of MAX_TEXTURE_SIZE.");
9219     }
9220 
9221     /* Check that INVALID_VALUE is generated by TextureStorage3DMultisample if
9222      depth is less than 1 or greater than the value of
9223      MAX_ARRAY_TEXTURE_LAYERS. */
9224     {
9225         gl.textureStorage3DMultisample(m_to_3D_ms, 1, GL_R8, 8, 8, 0, false);
9226         is_ok &=
9227             CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3DMultisample", "depth is less than 1.");
9228 
9229         gl.textureStorage3DMultisample(m_to_3D_ms, 1, GL_R8, 8, 8, m_max_array_texture_layers * 2, false);
9230         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3DMultisample",
9231                                   "depth is greater than the value of MAX_ARRAY_TEXTURE_LAYERS.");
9232     }
9233 
9234     /* Check that INVALID_VALUE is generated by TextureStorage3DMultisample if
9235      samples is greater than the maximum number of samples reported for GL_R8 */
9236     {
9237         gl.textureStorage3DMultisample(m_to_3D_ms, m_max_samples * 2, GL_R8, 8, 8, 8, false);
9238         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3DMultisample",
9239                                   "samples is greater than the value of MAX_SAMPLES.");
9240     }
9241 
9242     /* Check that INVALID_OPERATION is generated by TextureStorage3DMultisample
9243      if the value of TEXTURE_IMMUTABLE_FORMAT for the texture bound to target
9244      is not FALSE. */
9245     {
9246         gl.textureStorage3DMultisample(m_to_3D_ms_immutable, 1, GL_R8, 8, 8, 8, false);
9247         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3DMultisample",
9248                                   "samples is greater than the value of MAX_SAMPLES.");
9249     }
9250 
9251     return is_ok;
9252 }
9253 
9254 /** @brief Clean GL objects, test variables and GL errors.
9255  */
Clean()9256 void StorageErrorsTest::Clean()
9257 {
9258     /* Shortcut for GL functionality. */
9259     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
9260 
9261     /* Cleanup. */
9262     if (m_to_1D)
9263     {
9264         gl.deleteTextures(1, &m_to_1D);
9265 
9266         m_to_1D = 0;
9267     }
9268 
9269     if (m_to_1D_array)
9270     {
9271         gl.deleteTextures(1, &m_to_1D_array);
9272 
9273         m_to_1D_array = 0;
9274     }
9275 
9276     if (m_to_2D)
9277     {
9278         gl.deleteTextures(1, &m_to_2D);
9279 
9280         m_to_2D = 0;
9281     }
9282 
9283     if (m_to_2D_array)
9284     {
9285         gl.deleteTextures(1, &m_to_2D_array);
9286 
9287         m_to_2D_array = 0;
9288     }
9289 
9290     if (m_to_3D)
9291     {
9292         gl.deleteTextures(1, &m_to_3D);
9293 
9294         m_to_3D = 0;
9295     }
9296 
9297     if (m_to_2D_ms)
9298     {
9299         gl.deleteTextures(1, &m_to_2D_ms);
9300 
9301         m_to_2D_ms = 0;
9302     }
9303 
9304     if (m_to_2D_ms_immutable)
9305     {
9306         gl.deleteTextures(1, &m_to_2D_ms_immutable);
9307 
9308         m_to_2D_ms_immutable = 0;
9309     }
9310 
9311     if (m_to_3D_ms)
9312     {
9313         gl.deleteTextures(1, &m_to_3D_ms);
9314 
9315         m_to_3D_ms = 0;
9316     }
9317 
9318     if (m_to_3D_ms_immutable)
9319     {
9320         gl.deleteTextures(1, &m_to_3D_ms_immutable);
9321 
9322         m_to_3D_ms_immutable = 0;
9323     }
9324 
9325     m_to_invalid               = 0;
9326     m_internalformat_invalid   = 0;
9327     m_max_texture_size         = 1;
9328     m_max_samples              = 1;
9329     m_max_array_texture_layers = 1;
9330 
9331     while (GL_NO_ERROR != gl.getError())
9332         ;
9333 }
9334 
9335 /******************************** Texture SubImage Errors Test Implementation   ********************************/
9336 
9337 /** @brief Texture SubImage Errors Test constructor.
9338  *
9339  *  @param [in] context     OpenGL context.
9340  */
SubImageErrorsTest(deqp::Context & context)9341 SubImageErrorsTest::SubImageErrorsTest(deqp::Context &context)
9342     : deqp::TestCase(context, "textures_subimage_errors", "Texture SubImage Errors Test")
9343     , m_to_1D_empty(0)
9344     , m_to_2D_empty(0)
9345     , m_to_3D_empty(0)
9346     , m_to_1D(0)
9347     , m_to_2D(0)
9348     , m_to_3D(0)
9349     , m_to_1D_compressed(0)
9350     , m_to_2D_compressed(0)
9351     , m_to_3D_compressed(0)
9352     , m_to_rectangle_compressed(0)
9353     , m_to_invalid(0)
9354     , m_bo(0)
9355     , m_format_invalid(0)
9356     , m_type_invalid(0)
9357     , m_max_texture_size(1)
9358     , m_reference_compressed_1D(DE_NULL)
9359     , m_reference_compressed_2D(DE_NULL)
9360     , m_reference_compressed_3D(DE_NULL)
9361     , m_reference_compressed_rectangle(DE_NULL)
9362     , m_reference_compressed_1D_size(0)
9363     , m_reference_compressed_2D_size(0)
9364     , m_reference_compressed_3D_size(0)
9365     , m_reference_compressed_rectangle_size(0)
9366     , m_reference_compressed_1D_format(0)
9367     , m_reference_compressed_2D_format(0)
9368     , m_reference_compressed_3D_format(0)
9369     , m_reference_compressed_rectangle_format(0)
9370     , m_not_matching_compressed_1D_format(0)
9371     , m_not_matching_compressed_1D_size(0)
9372     , m_not_matching_compressed_2D_format(0)
9373     , m_not_matching_compressed_2D_size(0)
9374     , m_not_matching_compressed_3D_format(0)
9375     , m_not_matching_compressed_3D_size(0)
9376 {
9377     /* Intentionally left blank. */
9378 }
9379 
9380 /** @brief Iterate Texture SubImage Errors Test cases.
9381  *
9382  *  @return Iteration result.
9383  */
iterate()9384 tcu::TestNode::IterateResult SubImageErrorsTest::iterate()
9385 {
9386     /* Get context setup. */
9387     bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
9388     bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
9389 
9390     if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
9391     {
9392         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
9393 
9394         return STOP;
9395     }
9396 
9397     /* Running tests. */
9398     bool is_ok    = true;
9399     bool is_error = false;
9400 
9401     try
9402     {
9403         Prepare();
9404 
9405         is_ok &= Test1D();
9406         is_ok &= Test2D();
9407         is_ok &= Test3D();
9408         is_ok &= Test1DCompressed();
9409         is_ok &= Test2DCompressed();
9410         is_ok &= Test3DCompressed();
9411     }
9412     catch (...)
9413     {
9414         is_ok    = false;
9415         is_error = true;
9416     }
9417 
9418     /* Cleanup. */
9419     Clean();
9420 
9421     /* Result's setup. */
9422     if (is_ok)
9423     {
9424         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
9425     }
9426     else
9427     {
9428         if (is_error)
9429         {
9430             m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
9431         }
9432         else
9433         {
9434             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
9435         }
9436     }
9437 
9438     return STOP;
9439 }
9440 
9441 /** @brief Prepare test's objects.
9442  */
Prepare()9443 void SubImageErrorsTest::Prepare()
9444 {
9445     /* Shortcut for GL functionality. */
9446     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
9447 
9448     /* Auxiliary objects setup. */
9449 
9450     /* 1D */
9451     gl.createTextures(GL_TEXTURE_1D, 1, &m_to_1D_empty);
9452     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9453 
9454     /* 2D */
9455     gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D_empty);
9456     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9457 
9458     /* 3D */
9459     gl.createTextures(GL_TEXTURE_3D, 1, &m_to_3D_empty);
9460     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9461 
9462     /* 1D */
9463     gl.createTextures(GL_TEXTURE_1D, 1, &m_to_1D);
9464     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9465 
9466     gl.bindTexture(GL_TEXTURE_1D, m_to_1D);
9467     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9468 
9469     gl.texImage1D(GL_TEXTURE_1D, 0, s_reference_internalformat, s_reference_width, 0, s_reference_format,
9470                   GL_UNSIGNED_BYTE, s_reference);
9471     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
9472 
9473     /* 2D */
9474     gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D);
9475     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9476 
9477     gl.bindTexture(GL_TEXTURE_2D, m_to_2D);
9478     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9479 
9480     gl.texImage2D(GL_TEXTURE_2D, 0, s_reference_internalformat, s_reference_width, s_reference_height, 0,
9481                   s_reference_format, GL_UNSIGNED_BYTE, s_reference);
9482     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
9483 
9484     /* 3D */
9485     gl.createTextures(GL_TEXTURE_3D, 1, &m_to_3D);
9486     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9487 
9488     gl.bindTexture(GL_TEXTURE_3D, m_to_3D);
9489     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9490 
9491     gl.texImage3D(GL_TEXTURE_3D, 0, s_reference_internalformat, s_reference_width, s_reference_height,
9492                   s_reference_depth, 0, s_reference_format, GL_UNSIGNED_BYTE, s_reference);
9493     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
9494 
9495     /* 1D Compressed */
9496     gl.createTextures(GL_TEXTURE_1D, 1, &m_to_1D_compressed);
9497     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9498 
9499     gl.bindTexture(GL_TEXTURE_1D, m_to_1D_compressed);
9500     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9501 
9502     gl.texImage1D(GL_TEXTURE_1D, 0, s_reference_internalformat_compressed, s_reference_width, 0, s_reference_format,
9503                   GL_UNSIGNED_BYTE, s_reference);
9504     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
9505 
9506     glw::GLint is_compressed = 0;
9507 
9508     gl.getTexLevelParameteriv(GL_TEXTURE_1D, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9509     GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9510 
9511     if (is_compressed)
9512     {
9513         gl.getTexLevelParameteriv(GL_TEXTURE_1D, 0, GL_TEXTURE_INTERNAL_FORMAT, &m_reference_compressed_1D_format);
9514         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9515 
9516         m_reference_compressed_1D_size = 0;
9517 
9518         gl.getTexLevelParameteriv(GL_TEXTURE_1D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &m_reference_compressed_1D_size);
9519         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9520 
9521         if (m_reference_compressed_1D_size)
9522         {
9523             m_reference_compressed_1D = new glw::GLubyte[m_reference_compressed_1D_size];
9524 
9525             gl.getCompressedTexImage(GL_TEXTURE_1D, 0, m_reference_compressed_1D);
9526             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
9527         }
9528     }
9529 
9530     /* 2D Compressed */
9531     gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D_compressed);
9532     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9533 
9534     gl.bindTexture(GL_TEXTURE_2D, m_to_2D_compressed);
9535     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9536 
9537     gl.texImage2D(GL_TEXTURE_2D, 0, s_reference_internalformat_compressed, s_reference_width, s_reference_height, 0,
9538                   s_reference_format, GL_UNSIGNED_BYTE, s_reference);
9539     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
9540 
9541     is_compressed = 0;
9542 
9543     gl.getTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9544     GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9545 
9546     if (is_compressed)
9547     {
9548         gl.getTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &m_reference_compressed_2D_format);
9549         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9550 
9551         m_reference_compressed_2D_size = 0;
9552 
9553         gl.getTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &m_reference_compressed_2D_size);
9554         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9555 
9556         if (m_reference_compressed_2D_size)
9557         {
9558             m_reference_compressed_2D = new glw::GLubyte[m_reference_compressed_2D_size];
9559 
9560             gl.getCompressedTexImage(GL_TEXTURE_2D, 0, m_reference_compressed_2D);
9561             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
9562         }
9563     }
9564 
9565     /* 3D Compressed */
9566     gl.createTextures(GL_TEXTURE_2D_ARRAY, 1, &m_to_3D_compressed);
9567     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9568 
9569     gl.bindTexture(GL_TEXTURE_2D_ARRAY, m_to_3D_compressed);
9570     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9571 
9572     gl.texImage3D(GL_TEXTURE_2D_ARRAY, 0, s_reference_internalformat_compressed, s_reference_width, s_reference_height,
9573                   s_reference_depth, 0, s_reference_format, GL_UNSIGNED_BYTE, s_reference);
9574     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage3D has failed");
9575 
9576     is_compressed = 0;
9577 
9578     gl.getTexLevelParameteriv(GL_TEXTURE_2D_ARRAY, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9579     GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9580 
9581     if (is_compressed)
9582     {
9583         gl.getTexLevelParameteriv(GL_TEXTURE_2D_ARRAY, 0, GL_TEXTURE_INTERNAL_FORMAT,
9584                                   &m_reference_compressed_3D_format);
9585         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9586 
9587         m_reference_compressed_3D_size = 0;
9588 
9589         gl.getTexLevelParameteriv(GL_TEXTURE_2D_ARRAY, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
9590                                   &m_reference_compressed_3D_size);
9591         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9592 
9593         if (m_reference_compressed_3D_size)
9594         {
9595             m_reference_compressed_3D = new glw::GLubyte[m_reference_compressed_3D_size];
9596 
9597             gl.getCompressedTexImage(GL_TEXTURE_2D_ARRAY, 0, m_reference_compressed_3D);
9598             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
9599         }
9600     }
9601 
9602     /* RECTANGLE Compressed */
9603     gl.createTextures(GL_TEXTURE_RECTANGLE, 1, &m_to_rectangle_compressed);
9604     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9605 
9606     gl.bindTexture(GL_TEXTURE_RECTANGLE, m_to_rectangle_compressed);
9607     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9608 
9609     gl.texImage2D(GL_TEXTURE_RECTANGLE, 0, s_reference_internalformat_compressed, s_reference_width, s_reference_height,
9610                   0, s_reference_format, GL_UNSIGNED_BYTE, s_reference);
9611     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
9612 
9613     is_compressed = 0;
9614 
9615     gl.getTexLevelParameteriv(GL_TEXTURE_RECTANGLE, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9616     GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9617 
9618     if (is_compressed)
9619     {
9620         gl.getTexLevelParameteriv(GL_TEXTURE_RECTANGLE, 0, GL_TEXTURE_INTERNAL_FORMAT,
9621                                   &m_reference_compressed_rectangle_format);
9622         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9623 
9624         m_reference_compressed_rectangle_size = 0;
9625 
9626         gl.getTexLevelParameteriv(GL_TEXTURE_RECTANGLE, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
9627                                   &m_reference_compressed_rectangle_size);
9628         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9629 
9630         if (m_reference_compressed_rectangle_size)
9631         {
9632             m_reference_compressed_rectangle = new glw::GLubyte[m_reference_compressed_rectangle_size];
9633 
9634             gl.getCompressedTexImage(GL_TEXTURE_RECTANGLE, 0, m_reference_compressed_rectangle);
9635             GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed");
9636         }
9637     }
9638 
9639     /* Buffer object */
9640     gl.createBuffers(1, &m_bo);
9641     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateBuffers has failed");
9642 
9643     gl.namedBufferData(m_bo, s_reference_size, s_reference, GL_STATIC_COPY);
9644     GLU_EXPECT_NO_ERROR(gl.getError(), "glNamedBufferData has failed");
9645 
9646     /* Invalid values */
9647 
9648     /* invalid texture object */
9649     while (gl.isTexture(++m_to_invalid))
9650         ;
9651     GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed");
9652 
9653     /* invalid internal format */
9654     static const glw::GLenum all_formats[] = {GL_STENCIL_INDEX,
9655                                               GL_DEPTH_COMPONENT,
9656                                               GL_DEPTH_STENCIL,
9657                                               GL_RED,
9658                                               GL_GREEN,
9659                                               GL_BLUE,
9660                                               GL_RG,
9661                                               GL_RGB,
9662                                               GL_RGBA,
9663                                               GL_BGR,
9664                                               GL_BGRA,
9665                                               GL_RED_INTEGER,
9666                                               GL_GREEN_INTEGER,
9667                                               GL_BLUE_INTEGER,
9668                                               GL_RG_INTEGER,
9669                                               GL_RGB_INTEGER,
9670                                               GL_RGBA_INTEGER,
9671                                               GL_BGR_INTEGER,
9672                                               GL_BGRA_INTEGER};
9673 
9674     static const glw::GLuint all_internal_formats_count = sizeof(all_formats) / sizeof(all_formats[0]);
9675 
9676     bool is_valid    = true;
9677     m_format_invalid = 0;
9678 
9679     while (is_valid)
9680     {
9681         is_valid = false;
9682         m_format_invalid++;
9683         for (glw::GLuint i = 0; i < all_internal_formats_count; ++i)
9684         {
9685             if (all_formats[i] == m_format_invalid)
9686             {
9687                 is_valid = true;
9688                 break;
9689             }
9690         }
9691     }
9692 
9693     /* Invalid type. */
9694     static const glw::GLenum all_types[] = {GL_UNSIGNED_BYTE,
9695                                             GL_BYTE,
9696                                             GL_UNSIGNED_SHORT,
9697                                             GL_SHORT,
9698                                             GL_UNSIGNED_INT,
9699                                             GL_INT,
9700                                             GL_HALF_FLOAT,
9701                                             GL_FLOAT,
9702                                             GL_UNSIGNED_BYTE_3_3_2,
9703                                             GL_UNSIGNED_BYTE_2_3_3_REV,
9704                                             GL_UNSIGNED_SHORT_5_6_5,
9705                                             GL_UNSIGNED_SHORT_5_6_5_REV,
9706                                             GL_UNSIGNED_SHORT_4_4_4_4,
9707                                             GL_UNSIGNED_SHORT_4_4_4_4_REV,
9708                                             GL_UNSIGNED_SHORT_5_5_5_1,
9709                                             GL_UNSIGNED_SHORT_1_5_5_5_REV,
9710                                             GL_UNSIGNED_INT_8_8_8_8,
9711                                             GL_UNSIGNED_INT_8_8_8_8_REV,
9712                                             GL_UNSIGNED_INT_10_10_10_2,
9713                                             GL_UNSIGNED_INT_2_10_10_10_REV,
9714                                             GL_UNSIGNED_INT_24_8,
9715                                             GL_UNSIGNED_INT_10F_11F_11F_REV,
9716                                             GL_UNSIGNED_INT_5_9_9_9_REV,
9717                                             GL_FLOAT_32_UNSIGNED_INT_24_8_REV};
9718 
9719     static const glw::GLuint all_types_count = sizeof(all_types) / sizeof(all_types[0]);
9720 
9721     is_valid       = true;
9722     m_type_invalid = 0;
9723 
9724     while (is_valid)
9725     {
9726         is_valid = false;
9727         m_type_invalid++;
9728         for (glw::GLuint i = 0; i < all_types_count; ++i)
9729         {
9730             if (all_types[i] == m_type_invalid)
9731             {
9732                 is_valid = true;
9733                 break;
9734             }
9735         }
9736     }
9737 
9738     /* Maximum texture size.*/
9739     gl.getIntegerv(GL_MAX_TEXTURE_SIZE, &m_max_texture_size);
9740     GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
9741 
9742     glw::GLenum not_matching_format                    = GL_RED;
9743     glw::GLenum not_matching_internalformat_compressed = GL_COMPRESSED_RED;
9744 
9745     /* 1D Compressed with a non matching format. We need to do all the allocation to get the correct image size */
9746     glw::GLuint to_1D_compressed_not_matching;
9747 
9748     gl.createTextures(GL_TEXTURE_1D, 1, &to_1D_compressed_not_matching);
9749     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9750 
9751     gl.bindTexture(GL_TEXTURE_1D, to_1D_compressed_not_matching);
9752     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9753 
9754     gl.texImage1D(GL_TEXTURE_1D, 0, not_matching_internalformat_compressed, s_reference_width, 0, s_reference_format,
9755                   GL_UNSIGNED_BYTE, s_reference);
9756     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed");
9757 
9758     is_compressed = 0;
9759 
9760     gl.getTexLevelParameteriv(GL_TEXTURE_1D, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9761     GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9762 
9763     if (is_compressed)
9764     {
9765         gl.getTexLevelParameteriv(GL_TEXTURE_1D, 0, GL_TEXTURE_INTERNAL_FORMAT, &m_not_matching_compressed_1D_format);
9766         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9767 
9768         m_not_matching_compressed_1D_size = 0;
9769 
9770         gl.getTexLevelParameteriv(GL_TEXTURE_1D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
9771                                   &m_not_matching_compressed_1D_size);
9772         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9773     }
9774 
9775     gl.deleteTextures(1, &to_1D_compressed_not_matching);
9776     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9777 
9778     /* 2D Compressed with a non matching format. We need to do all the allocation to get the correct image size */
9779     glw::GLuint to_2D_compressed_not_matching;
9780 
9781     gl.createTextures(GL_TEXTURE_2D, 1, &to_2D_compressed_not_matching);
9782     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9783 
9784     gl.bindTexture(GL_TEXTURE_2D, to_2D_compressed_not_matching);
9785     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9786 
9787     gl.texImage2D(GL_TEXTURE_2D, 0, not_matching_internalformat_compressed, s_reference_width, s_reference_height, 0,
9788                   not_matching_format, GL_UNSIGNED_BYTE, s_reference);
9789     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
9790 
9791     is_compressed = 0;
9792 
9793     gl.getTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9794     GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9795 
9796     if (is_compressed)
9797     {
9798         gl.getTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &m_not_matching_compressed_2D_format);
9799         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9800 
9801         m_not_matching_compressed_2D_size = 0;
9802 
9803         gl.getTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
9804                                   &m_not_matching_compressed_2D_size);
9805         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9806     }
9807 
9808     gl.deleteTextures(1, &to_2D_compressed_not_matching);
9809     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9810 
9811     /* 3D Compressed with a non matching format. We need to do all the allocation to get the correct image size */
9812     glw::GLuint to_3D_compressed_not_matching;
9813 
9814     gl.createTextures(GL_TEXTURE_3D, 1, &to_3D_compressed_not_matching);
9815     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9816 
9817     gl.bindTexture(GL_TEXTURE_3D, to_3D_compressed_not_matching);
9818     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
9819 
9820     gl.texImage3D(GL_TEXTURE_3D, 0, not_matching_internalformat_compressed, s_reference_width, s_reference_height,
9821                   s_reference_depth, 0, not_matching_format, GL_UNSIGNED_BYTE, s_reference);
9822     GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage3D has failed");
9823 
9824     is_compressed = 0;
9825 
9826     gl.getTexLevelParameteriv(GL_TEXTURE_3D, 0, GL_TEXTURE_COMPRESSED, &is_compressed);
9827     GLU_EXPECT_NO_ERROR(gl.getError(), "glTetTexLevelParameteriv has failed");
9828 
9829     if (is_compressed)
9830     {
9831         gl.getTexLevelParameteriv(GL_TEXTURE_3D, 0, GL_TEXTURE_INTERNAL_FORMAT, &m_not_matching_compressed_3D_format);
9832         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9833 
9834         m_not_matching_compressed_3D_size = 0;
9835 
9836         gl.getTexLevelParameteriv(GL_TEXTURE_3D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
9837                                   &m_not_matching_compressed_3D_size);
9838         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed");
9839     }
9840 
9841     gl.deleteTextures(1, &to_3D_compressed_not_matching);
9842     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
9843 }
9844 
9845 /** @brief Test (negative) of TextureSubImage1D
9846  *
9847  *  @return Test result.
9848  */
Test1D()9849 bool SubImageErrorsTest::Test1D()
9850 {
9851     /* Shortcut for GL functionality. */
9852     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
9853 
9854     /* Result. */
9855     bool is_ok = true;
9856 
9857     /* Check that INVALID_OPERATION is generated by TextureSubImage1D if
9858      texture is not the name of an existing texture object. */
9859     {
9860         gl.textureSubImage1D(m_to_invalid, 0, 0, s_reference_width, s_reference_format, s_reference_type, s_reference);
9861         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9862                                   "texture is not the name of an existing texture object.");
9863     }
9864 
9865     /* Check that INVALID_ENUM is generated by TextureSubImage1D if format is
9866      not an accepted format constant. */
9867     {
9868         gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, m_format_invalid, s_reference_type, s_reference);
9869         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureSubImage1D",
9870                                   "format is not an accepted format constant.");
9871     }
9872 
9873     /* Check that INVALID_ENUM is generated by TextureSubImage1D if type is not
9874      an accepted type constant. */
9875     {
9876         gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, m_type_invalid, s_reference);
9877         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureSubImage1D",
9878                                   "type is not an accepted type constant.");
9879     }
9880 
9881     /* Check that INVALID_VALUE is generated by TextureSubImage1D if level is
9882      less than 0. */
9883     {
9884         gl.textureSubImage1D(m_to_1D, -1, 0, s_reference_width, s_reference_format, s_reference_type, s_reference);
9885         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D", "level is less than 0.");
9886     }
9887 
9888     /* Check that INVALID_VALUE may be generated by TextureSubImage1D if level
9889      is greater than log2 max, where max is the returned value of
9890      MAX_TEXTURE_SIZE. */
9891     {
9892         gl.textureSubImage1D(m_to_1D, m_max_texture_size, 0, s_reference_width, s_reference_format, s_reference_type,
9893                              s_reference);
9894         is_ok &=
9895             CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D",
9896                              "level is greater than log2 max, where max is the returned value of MAX_TEXTURE_SIZE.");
9897     }
9898 
9899     /* Check that INVALID_VALUE is generated by TextureSubImage1D if
9900      xoffset<-b, or if (xoffset+width)>(w-b), where w is the TEXTURE_WIDTH,
9901      and b is the width of the TEXTURE_BORDER of the texture image being
9902      modified. Note that w includes twice the border width. */
9903     {
9904         gl.textureSubImage1D(m_to_1D, 0, -1, s_reference_width, s_reference_format, s_reference_type, s_reference);
9905         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D",
9906                                   "xoffset<-b, where b is the width of the TEXTURE_BORDER.");
9907 
9908         gl.textureSubImage1D(m_to_1D, 0, 1, s_reference_width + 1, s_reference_format, s_reference_type, s_reference);
9909         is_ok &= CheckErrorAndLog(
9910             m_context, GL_INVALID_VALUE, "glTextureSubImage1D",
9911             "(xoffset+width)>(w-b), where w is the TEXTURE_WIDTH, b is the width of the TEXTURE_BORDER.");
9912     }
9913 
9914     /*Check that INVALID_VALUE is generated by TextureSubImage1D if width is less than 0. */
9915     {
9916 #ifndef TURN_OFF_SUB_IMAGE_ERRORS_TEST_OF_NEGATIVE_WIDTH_HEIGHT_OR_DEPTH
9917         gl.textureSubImage1D(m_to_1D, 0, 0, -1, s_reference_format, s_reference_type, s_reference);
9918         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D", "width is less than 0.");
9919 #endif
9920     }
9921 
9922     /* Check that INVALID_OPERATION is generated by TextureSubImage1D if type
9923      is one of UNSIGNED_BYTE_3_3_2, UNSIGNED_BYTE_2_3_3_REV,
9924      UNSIGNED_SHORT_5_6_5, or UNSIGNED_SHORT_5_6_5_REV and format is not RGB. */
9925     {
9926         gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_BYTE_3_3_2, s_reference);
9927         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9928                                   "type is UNSIGNED_BYTE_3_3_2 and format is not RGB.");
9929 
9930         gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_BYTE_2_3_3_REV,
9931                              s_reference);
9932         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9933                                   "type is UNSIGNED_BYTE_2_3_3_REV and format is not RGB.");
9934 
9935         gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_SHORT_5_6_5,
9936                              s_reference);
9937         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9938                                   "type is UNSIGNED_SHORT_5_6_5 and format is not RGB.");
9939 
9940         gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_SHORT_5_6_5_REV,
9941                              s_reference);
9942         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9943                                   "type is UNSIGNED_SHORT_5_6_5_REV and format is not RGB.");
9944     }
9945 
9946     /* Check that INVALID_OPERATION is generated by TextureSubImage1D if type
9947      is one of UNSIGNED_SHORT_4_4_4_4, UNSIGNED_SHORT_4_4_4_4_REV,
9948      UNSIGNED_SHORT_5_5_5_1, UNSIGNED_SHORT_1_5_5_5_REV,
9949      UNSIGNED_INT_8_8_8_8, UNSIGNED_INT_8_8_8_8_REV, UNSIGNED_INT_10_10_10_2,
9950      or UNSIGNED_INT_2_10_10_10_REV and format is neither RGBA nor BGRA. */
9951     {
9952         gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_SHORT_4_4_4_4,
9953                              s_reference);
9954         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9955                                   "type is UNSIGNED_SHORT_4_4_4_4 and format is neither RGBA nor BGRA.");
9956 
9957         gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_SHORT_4_4_4_4_REV,
9958                              s_reference);
9959         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9960                                   "type is UNSIGNED_SHORT_4_4_4_4_REV and format is neither RGBA nor BGRA.");
9961 
9962         gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_SHORT_5_5_5_1,
9963                              s_reference);
9964         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9965                                   "type is UNSIGNED_SHORT_5_5_5_1 and format is neither RGBA nor BGRA.");
9966 
9967         gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_SHORT_1_5_5_5_REV,
9968                              s_reference);
9969         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9970                                   "type is UNSIGNED_SHORT_1_5_5_5_REV and format is neither RGBA nor BGRA.");
9971 
9972         gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_INT_8_8_8_8,
9973                              s_reference);
9974         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9975                                   "type is UNSIGNED_INT_8_8_8_8 and format is neither RGBA nor BGRA.");
9976 
9977         gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_INT_8_8_8_8_REV,
9978                              s_reference);
9979         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9980                                   "type is UNSIGNED_INT_8_8_8_8_REV and format is neither RGBA nor BGRA.");
9981 
9982         gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_INT_10_10_10_2,
9983                              s_reference);
9984         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9985                                   "type is UNSIGNED_INT_10_10_10_2 and format is neither RGBA nor BGRA.");
9986 
9987         gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, GL_UNSIGNED_INT_2_10_10_10_REV,
9988                              s_reference);
9989         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
9990                                   "type is UNSIGNED_INT_2_10_10_10_REV and format is neither RGBA nor BGRA.");
9991     }
9992 
9993     /* Check that INVALID_OPERATION is generated by TextureSubImage1D if a
9994      non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
9995      and the buffer object's data store is currently mapped. */
9996     {
9997         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
9998         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
9999 
10000         gl.mapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
10001 
10002         if (GL_NO_ERROR == gl.getError())
10003         {
10004             gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, s_reference_type, NULL);
10005             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
10006                                       "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and "
10007                                       "the buffer object's data store is currently mapped.");
10008 
10009             gl.unmapBuffer(GL_PIXEL_UNPACK_BUFFER);
10010             GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10011 
10012             gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10013             GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10014         }
10015     }
10016 
10017     /* Check that INVALID_OPERATION is generated by TextureSubImage1D if a
10018      non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
10019      and the data would be unpacked from the buffer object such that the
10020      memory reads required would exceed the data store size. */
10021     {
10022         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10023         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10024 
10025         gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, s_reference_type,
10026                              glu::BufferOffsetAsPointer(s_reference_size * 2));
10027         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
10028                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and the "
10029                                   "data would be unpacked from the buffer object such that the memory reads required "
10030                                   "would exceed the data store size.");
10031 
10032         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10033         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10034     }
10035 
10036     /* Check that INVALID_OPERATION is generated by TextureSubImage1D if a
10037      non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
10038      and pixels is not evenly divisible into the number of bytes needed to
10039      store in memory a datum indicated by type. */
10040     {
10041         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10042         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10043 
10044         gl.textureSubImage1D(m_to_1D, 0, 0, s_reference_width, s_reference_format, s_reference_type,
10045                              glu::BufferOffsetAsPointer(1));
10046         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage1D",
10047                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and pixels "
10048                                   "is not evenly divisible into the number of bytes needed to store in memory a datum "
10049                                   "indicated by type.");
10050 
10051         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10052         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10053     }
10054 
10055     return is_ok;
10056 }
10057 
10058 /** @brief Test (negative) of TextureSubImage2D
10059  *
10060  *  @return Test result.
10061  */
Test2D()10062 bool SubImageErrorsTest::Test2D()
10063 {
10064     /* Shortcut for GL functionality. */
10065     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
10066 
10067     /* Result. */
10068     bool is_ok = true;
10069 
10070     /* Check that INVALID_OPERATION is generated by TextureSubImage2D if
10071      texture is not the name of an existing texture object. */
10072     {
10073         gl.textureSubImage2D(m_to_invalid, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10074                              s_reference_type, s_reference);
10075         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10076                                   "texture is not the name of an existing texture object.");
10077     }
10078 
10079     /* Check that INVALID_ENUM is generated by TextureSubImage2D if format is
10080      not an accepted format constant. */
10081     {
10082         gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, m_format_invalid,
10083                              s_reference_type, s_reference);
10084         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureSubImage2D",
10085                                   "format is not an accepted format constant.");
10086     }
10087 
10088     /* Check that INVALID_ENUM is generated by TextureSubImage2D if type is not
10089      an accepted type constant. */
10090     {
10091         gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10092                              m_type_invalid, s_reference);
10093         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureSubImage2D",
10094                                   "type is not an accepted type constant.");
10095     }
10096 
10097     /* Check that INVALID_VALUE is generated by TextureSubImage2D if level is
10098      less than 0. */
10099     {
10100         gl.textureSubImage2D(m_to_2D, -1, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10101                              s_reference_type, s_reference);
10102         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage2D", "level is less than 0.");
10103     }
10104 
10105     /* Check that INVALID_VALUE may be generated by TextureSubImage2D if level
10106      is greater than log2 max, where max is the returned value of
10107      MAX_TEXTURE_SIZE. */
10108     {
10109         gl.textureSubImage2D(m_to_2D, m_max_texture_size, 0, 0, s_reference_width, s_reference_height,
10110                              s_reference_format, s_reference_type, s_reference);
10111         is_ok &=
10112             CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage2D",
10113                              "level is greater than log2 max, where max is the returned value of MAX_TEXTURE_SIZE.");
10114     }
10115 
10116     /* Check that INVALID_VALUE may be generated by TextureSubImage2D if level
10117      is greater than log2 max, where max is the returned value of
10118      MAX_TEXTURE_SIZE.
10119      Check that INVALID_VALUE is generated by TextureSubImage2D if
10120      xoffset<-b, (xoffset+width)>(w-b), yoffset<-b, or
10121      (yoffset+height)>(h-b), where w is the TEXTURE_WIDTH, h is the
10122      TEXTURE_HEIGHT, and b is the border width of the texture image being
10123      modified. Note that w and h include twice the border width. */
10124     {
10125         gl.textureSubImage2D(m_to_2D, 0, -1, 0, s_reference_width, s_reference_height, s_reference_format,
10126                              s_reference_type, s_reference);
10127         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage2D",
10128                                   "xoffset<-b, where b is the width of the TEXTURE_BORDER.");
10129 
10130         gl.textureSubImage2D(m_to_2D, 0, 1, 0, s_reference_width + 1, s_reference_height, s_reference_format,
10131                              s_reference_type, s_reference);
10132         is_ok &= CheckErrorAndLog(
10133             m_context, GL_INVALID_VALUE, "glTextureSubImage2D",
10134             "(xoffset+width)>(w-b), where w is the TEXTURE_WIDTH, b is the width of the TEXTURE_BORDER.");
10135 
10136         gl.textureSubImage2D(m_to_2D, 0, 0, -1, s_reference_width, s_reference_height, s_reference_format,
10137                              s_reference_type, s_reference);
10138         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage2D",
10139                                   "yoffset<-b, where b is the height of the TEXTURE_BORDER.");
10140 
10141         gl.textureSubImage2D(m_to_2D, 0, 0, 1, s_reference_width + 1, s_reference_height, s_reference_format,
10142                              s_reference_type, s_reference);
10143         is_ok &= CheckErrorAndLog(
10144             m_context, GL_INVALID_VALUE, "glTextureSubImage2D",
10145             "(yoffset+height)>(h-b), where h is the TEXTURE_HEIGHT, b is the width of the TEXTURE_BORDER.");
10146     }
10147 
10148     /*Check that INVALID_VALUE is generated by TextureSubImage2D if width or height is less than 0. */
10149     {
10150 #ifndef TURN_OFF_SUB_IMAGE_ERRORS_TEST_OF_NEGATIVE_WIDTH_HEIGHT_OR_DEPTH
10151         gl.textureSubImage2D(m_to_2D, 0, 0, 0, -1, s_reference_height, s_reference_format, s_reference_type,
10152                              s_reference);
10153         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage2D", "width is less than 0.");
10154 
10155         gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, -1, s_reference_format, s_reference_type,
10156                              s_reference);
10157         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage2D", "height is less than 0.");
10158 #endif
10159     }
10160 
10161     /* Check that INVALID_OPERATION is generated by TextureSubImage2D if type
10162      is one of UNSIGNED_BYTE_3_3_2, UNSIGNED_BYTE_2_3_3_REV,
10163      UNSIGNED_SHORT_5_6_5, or UNSIGNED_SHORT_5_6_5_REV and format is not RGB. */
10164     {
10165         gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10166                              GL_UNSIGNED_BYTE_3_3_2, s_reference);
10167         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10168                                   "type is UNSIGNED_BYTE_3_3_2 and format is not RGB.");
10169 
10170         gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10171                              GL_UNSIGNED_BYTE_2_3_3_REV, s_reference);
10172         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10173                                   "type is UNSIGNED_BYTE_2_3_3_REV and format is not RGB.");
10174 
10175         gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10176                              GL_UNSIGNED_SHORT_5_6_5, s_reference);
10177         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10178                                   "type is UNSIGNED_SHORT_5_6_5 and format is not RGB.");
10179 
10180         gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10181                              GL_UNSIGNED_SHORT_5_6_5_REV, s_reference);
10182         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10183                                   "type is UNSIGNED_SHORT_5_6_5_REV and format is not RGB.");
10184     }
10185 
10186     /* Check that INVALID_OPERATION is generated by TextureSubImage2D if type
10187      is one of UNSIGNED_SHORT_4_4_4_4, UNSIGNED_SHORT_4_4_4_4_REV,
10188      UNSIGNED_SHORT_5_5_5_1, UNSIGNED_SHORT_1_5_5_5_REV,
10189      UNSIGNED_INT_8_8_8_8, UNSIGNED_INT_8_8_8_8_REV, UNSIGNED_INT_10_10_10_2,
10190      or UNSIGNED_INT_2_10_10_10_REV and format is neither RGBA nor BGRA. */
10191     {
10192         gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10193                              GL_UNSIGNED_SHORT_4_4_4_4, s_reference);
10194         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10195                                   "type is UNSIGNED_SHORT_4_4_4_4 and format is neither RGBA nor BGRA.");
10196 
10197         gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10198                              GL_UNSIGNED_SHORT_4_4_4_4_REV, s_reference);
10199         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10200                                   "type is UNSIGNED_SHORT_4_4_4_4_REV and format is neither RGBA nor BGRA.");
10201 
10202         gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10203                              GL_UNSIGNED_SHORT_5_5_5_1, s_reference);
10204         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10205                                   "type is UNSIGNED_SHORT_5_5_5_1 and format is neither RGBA nor BGRA.");
10206 
10207         gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10208                              GL_UNSIGNED_SHORT_1_5_5_5_REV, s_reference);
10209         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10210                                   "type is UNSIGNED_SHORT_1_5_5_5_REV and format is neither RGBA nor BGRA.");
10211 
10212         gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10213                              GL_UNSIGNED_INT_8_8_8_8, s_reference);
10214         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10215                                   "type is UNSIGNED_INT_8_8_8_8 and format is neither RGBA nor BGRA.");
10216 
10217         gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10218                              GL_UNSIGNED_INT_8_8_8_8_REV, s_reference);
10219         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10220                                   "type is UNSIGNED_INT_8_8_8_8_REV and format is neither RGBA nor BGRA.");
10221 
10222         gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10223                              GL_UNSIGNED_INT_10_10_10_2, s_reference);
10224         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10225                                   "type is UNSIGNED_INT_10_10_10_2 and format is neither RGBA nor BGRA.");
10226 
10227         gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10228                              GL_UNSIGNED_INT_2_10_10_10_REV, s_reference);
10229         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10230                                   "type is UNSIGNED_INT_2_10_10_10_REV and format is neither RGBA nor BGRA.");
10231     }
10232 
10233     /* Check that INVALID_OPERATION is generated by TextureSubImage2D if a
10234      non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
10235      and the buffer object's data store is currently mapped. */
10236     {
10237         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10238         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10239 
10240         gl.mapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
10241 
10242         if (GL_NO_ERROR == gl.getError())
10243         {
10244             gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10245                                  s_reference_type, NULL);
10246             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10247                                       "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and "
10248                                       "the buffer object's data store is currently mapped.");
10249 
10250             gl.unmapBuffer(GL_PIXEL_UNPACK_BUFFER);
10251             GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10252 
10253             gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10254             GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10255         }
10256     }
10257 
10258     /* Check that INVALID_OPERATION is generated by TextureSubImage2D if a
10259      non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
10260      and the data would be unpacked from the buffer object such that the
10261      memory reads required would exceed the data store size. */
10262     {
10263         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10264         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10265 
10266         gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10267                              s_reference_type, glu::BufferOffsetAsPointer(s_reference_size * 2));
10268         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10269                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and the "
10270                                   "data would be unpacked from the buffer object such that the memory reads required "
10271                                   "would exceed the data store size.");
10272 
10273         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10274         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10275     }
10276 
10277     /* Check that INVALID_OPERATION is generated by TextureSubImage2D if a
10278      non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
10279      and pixels is not evenly divisible into the number of bytes needed to
10280      store in memory a datum indicated by type. */
10281     {
10282         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10283         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10284 
10285         gl.textureSubImage2D(m_to_2D, 0, 0, 0, s_reference_width, s_reference_height, s_reference_format,
10286                              s_reference_type, glu::BufferOffsetAsPointer(1));
10287         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage2D",
10288                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and pixels "
10289                                   "is not evenly divisible into the number of bytes needed to store in memory a datum "
10290                                   "indicated by type.");
10291 
10292         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10293         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10294     }
10295 
10296     return is_ok;
10297 }
10298 
10299 /** @brief Test (negative) of TextureSubImage3D
10300  *
10301  *  @return Test result.
10302  */
Test3D()10303 bool SubImageErrorsTest::Test3D()
10304 {
10305     /* Shortcut for GL functionality. */
10306     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
10307 
10308     /* Result. */
10309     bool is_ok = true;
10310 
10311     /* Check that INVALID_OPERATION is generated by TextureSubImage3D if
10312      texture is not the name of an existing texture object. */
10313     {
10314         gl.textureSubImage3D(m_to_invalid, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10315                              s_reference_format, s_reference_type, s_reference);
10316         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10317                                   "texture is not the name of an existing texture object.");
10318     }
10319 
10320     /* Check that INVALID_ENUM is generated by TextureSubImage3D if format is
10321      not an accepted format constant. */
10322     {
10323         gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10324                              m_format_invalid, s_reference_type, s_reference);
10325         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureSubImage3D",
10326                                   "format is not an accepted format constant.");
10327     }
10328 
10329     /* Check that INVALID_ENUM is generated by TextureSubImage3D if type is not
10330      an accepted type constant. */
10331     {
10332         gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10333                              s_reference_format, m_type_invalid, s_reference);
10334         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureSubImage3D",
10335                                   "type is not an accepted type constant.");
10336     }
10337 
10338     /* Check that INVALID_VALUE is generated by TextureSubImage3D if level is
10339      less than 0. */
10340     {
10341         gl.textureSubImage3D(m_to_3D, -1, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10342                              s_reference_format, s_reference_type, s_reference);
10343         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage3D", "level is less than 0.");
10344     }
10345 
10346     /* Check that INVALID_VALUE may be generated by TextureSubImage1D if level
10347      is greater than log2 max, where max is the returned value of
10348      MAX_TEXTURE_SIZE. */
10349     {
10350         gl.textureSubImage3D(m_to_3D, m_max_texture_size, 0, 0, 0, s_reference_width, s_reference_height,
10351                              s_reference_depth, s_reference_format, s_reference_type, s_reference);
10352         is_ok &=
10353             CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10354                              "level is greater than log2 max, where max is the returned value of MAX_TEXTURE_SIZE.");
10355     }
10356 
10357     /* Check that INVALID_VALUE is generated by TextureSubImage3D if
10358      xoffset<-b, (xoffset+width)>(w-b), yoffset<-b, or
10359      (yoffset+height)>(h-b), or zoffset<-b, or (zoffset+depth)>(d-b), where w
10360      is the TEXTURE_WIDTH, h is the TEXTURE_HEIGHT, d is the TEXTURE_DEPTH
10361      and b is the border width of the texture image being modified. Note
10362      that w, h, and d include twice the border width. */
10363     {
10364         gl.textureSubImage3D(m_to_3D, 0, -1, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10365                              s_reference_format, s_reference_type, s_reference);
10366         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10367                                   "xoffset<-b, where b is the width of the TEXTURE_BORDER.");
10368 
10369         gl.textureSubImage3D(m_to_3D, 0, 1, 0, 0, s_reference_width + 1, s_reference_height, s_reference_depth,
10370                              s_reference_format, s_reference_type, s_reference);
10371         is_ok &= CheckErrorAndLog(
10372             m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10373             "(xoffset+width)>(w-b), where w is the TEXTURE_WIDTH, b is the width of the TEXTURE_BORDER.");
10374 
10375         gl.textureSubImage3D(m_to_3D, 0, 0, -1, 0, s_reference_width, s_reference_height, s_reference_depth,
10376                              s_reference_format, s_reference_type, s_reference);
10377         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10378                                   "yoffset<-b, where b is the width of the TEXTURE_BORDER.");
10379 
10380         gl.textureSubImage3D(m_to_3D, 0, 0, 1, 0, s_reference_width + 1, s_reference_height, s_reference_depth,
10381                              s_reference_format, s_reference_type, s_reference);
10382         is_ok &= CheckErrorAndLog(
10383             m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10384             "(yoffset+height)>(h-b), where h is the TEXTURE_HEIGHT, b is the width of the TEXTURE_BORDER.");
10385 
10386         gl.textureSubImage3D(m_to_3D, 0, 0, 0, -1, s_reference_width, s_reference_height, s_reference_depth,
10387                              s_reference_format, s_reference_type, s_reference);
10388         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10389                                   "zoffset<-b, where b is the depth of the TEXTURE_BORDER.");
10390 
10391         gl.textureSubImage3D(m_to_3D, 0, 0, 0, 1, s_reference_width + 1, s_reference_height, s_reference_depth,
10392                              s_reference_format, s_reference_type, s_reference);
10393         is_ok &= CheckErrorAndLog(
10394             m_context, GL_INVALID_VALUE, "glTextureSubImage3D",
10395             "(zoffset+width)>(d-b), where d is the TEXTURE_DEPTH, b is the width of the TEXTURE_BORDER.");
10396     }
10397 
10398     /*Check that INVALID_VALUE is generated by TextureSubImage3D if width or height or depth is less than 0. */
10399     {
10400 #ifndef TURN_OFF_SUB_IMAGE_ERRORS_TEST_OF_NEGATIVE_WIDTH_HEIGHT_OR_DEPTH
10401         gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, -1, s_reference_height, s_reference_depth, s_reference_format,
10402                              s_reference_type, s_reference);
10403         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D", "width is less than 0.");
10404 
10405         gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, -1, s_reference_depth, s_reference_format,
10406                              s_reference_type, s_reference);
10407         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D", "height is less than 0.");
10408 
10409         gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, -1, s_reference_format,
10410                              s_reference_type, s_reference);
10411         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureSubImage1D", "depth is less than 0.");
10412 #endif
10413     }
10414 
10415     /* Check that INVALID_OPERATION is generated by TextureSubImage3D if type
10416      is one of UNSIGNED_BYTE_3_3_2, UNSIGNED_BYTE_2_3_3_REV,
10417      UNSIGNED_SHORT_5_6_5, or UNSIGNED_SHORT_5_6_5_REV and format is not RGB. */
10418     {
10419         gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10420                              s_reference_format, GL_UNSIGNED_BYTE_3_3_2, s_reference);
10421         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10422                                   "type is UNSIGNED_BYTE_3_3_2 and format is not RGB.");
10423 
10424         gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10425                              s_reference_format, GL_UNSIGNED_BYTE_2_3_3_REV, s_reference);
10426         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10427                                   "type is UNSIGNED_BYTE_2_3_3_REV and format is not RGB.");
10428 
10429         gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10430                              s_reference_format, GL_UNSIGNED_SHORT_5_6_5, s_reference);
10431         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10432                                   "type is UNSIGNED_SHORT_5_6_5 and format is not RGB.");
10433 
10434         gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10435                              s_reference_format, GL_UNSIGNED_SHORT_5_6_5_REV, s_reference);
10436         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10437                                   "type is UNSIGNED_SHORT_5_6_5_REV and format is not RGB.");
10438     }
10439 
10440     /* Check that INVALID_OPERATION is generated by TextureSubImage3D if type
10441      is one of UNSIGNED_SHORT_4_4_4_4, UNSIGNED_SHORT_4_4_4_4_REV,
10442      UNSIGNED_SHORT_5_5_5_1, UNSIGNED_SHORT_1_5_5_5_REV,
10443      UNSIGNED_INT_8_8_8_8, UNSIGNED_INT_8_8_8_8_REV, UNSIGNED_INT_10_10_10_2,
10444      or UNSIGNED_INT_2_10_10_10_REV and format is neither RGBA nor BGRA. */
10445     {
10446         gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10447                              s_reference_format, GL_UNSIGNED_SHORT_4_4_4_4, s_reference);
10448         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10449                                   "type is UNSIGNED_SHORT_4_4_4_4 and format is neither RGBA nor BGRA.");
10450 
10451         gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10452                              s_reference_format, GL_UNSIGNED_SHORT_4_4_4_4_REV, s_reference);
10453         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10454                                   "type is UNSIGNED_SHORT_4_4_4_4_REV and format is neither RGBA nor BGRA.");
10455 
10456         gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10457                              s_reference_format, GL_UNSIGNED_SHORT_5_5_5_1, s_reference);
10458         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10459                                   "type is UNSIGNED_SHORT_5_5_5_1 and format is neither RGBA nor BGRA.");
10460 
10461         gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10462                              s_reference_format, GL_UNSIGNED_SHORT_1_5_5_5_REV, s_reference);
10463         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10464                                   "type is UNSIGNED_SHORT_1_5_5_5_REV and format is neither RGBA nor BGRA.");
10465 
10466         gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10467                              s_reference_format, GL_UNSIGNED_INT_8_8_8_8, s_reference);
10468         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10469                                   "type is UNSIGNED_INT_8_8_8_8 and format is neither RGBA nor BGRA.");
10470 
10471         gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10472                              s_reference_format, GL_UNSIGNED_INT_8_8_8_8_REV, s_reference);
10473         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10474                                   "type is UNSIGNED_INT_8_8_8_8_REV and format is neither RGBA nor BGRA.");
10475 
10476         gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10477                              s_reference_format, GL_UNSIGNED_INT_10_10_10_2, s_reference);
10478         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10479                                   "type is UNSIGNED_INT_10_10_10_2 and format is neither RGBA nor BGRA.");
10480 
10481         gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10482                              s_reference_format, GL_UNSIGNED_INT_2_10_10_10_REV, s_reference);
10483         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10484                                   "type is UNSIGNED_INT_2_10_10_10_REV and format is neither RGBA nor BGRA.");
10485     }
10486 
10487     /* Check that INVALID_OPERATION is generated by TextureSubImage3D if a
10488      non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
10489      and the buffer object's data store is currently mapped. */
10490     {
10491         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10492         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10493 
10494         gl.mapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
10495 
10496         if (GL_NO_ERROR == gl.getError())
10497         {
10498             gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10499                                  s_reference_format, s_reference_type, NULL);
10500             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10501                                       "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and "
10502                                       "the buffer object's data store is currently mapped.");
10503 
10504             gl.unmapBuffer(GL_PIXEL_UNPACK_BUFFER);
10505             GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10506 
10507             gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10508             GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10509         }
10510     }
10511 
10512     /* Check that INVALID_OPERATION is generated by TextureSubImage3D if a
10513      non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
10514      and the data would be unpacked from the buffer object such that the
10515      memory reads required would exceed the data store size. */
10516     {
10517         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10518         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10519 
10520         gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10521                              s_reference_format, s_reference_type, glu::BufferOffsetAsPointer(s_reference_size * 2));
10522         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10523                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and the "
10524                                   "data would be unpacked from the buffer object such that the memory reads required "
10525                                   "would exceed the data store size.");
10526 
10527         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10528         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10529     }
10530 
10531     /* Check that INVALID_OPERATION is generated by TextureSubImage3D if a
10532      non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target
10533      and pixels is not evenly divisible into the number of bytes needed to
10534      store in memory a datum indicated by type. */
10535     {
10536         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10537         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10538 
10539         gl.textureSubImage3D(m_to_3D, 0, 0, 0, 0, s_reference_width, s_reference_height, s_reference_depth,
10540                              s_reference_format, s_reference_type, glu::BufferOffsetAsPointer(1));
10541         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureSubImage3D",
10542                                   "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and pixels "
10543                                   "is not evenly divisible into the number of bytes needed to store in memory a datum "
10544                                   "indicated by type.");
10545 
10546         gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10547         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10548     }
10549 
10550     return is_ok;
10551 }
10552 
10553 /** @brief Test (negative) of TextureSubImage1DCompressed
10554  *
10555  *  @return Test result.
10556  */
Test1DCompressed()10557 bool SubImageErrorsTest::Test1DCompressed()
10558 {
10559     /* Shortcut for GL functionality. */
10560     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
10561 
10562     /* Result. */
10563     bool is_ok = true;
10564 
10565     /* Do tests only if compressed 1D textures are supported. */
10566     if (DE_NULL != m_reference_compressed_1D)
10567     {
10568         /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage1D
10569          if texture is not the name of an existing texture object. */
10570         {
10571             gl.compressedTextureSubImage1D(m_to_invalid, 0, 0, s_reference_width, m_reference_compressed_1D_format,
10572                                            m_reference_compressed_1D_size, m_reference_compressed_1D);
10573             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage1D",
10574                                       "texture is not the name of an existing texture object.");
10575         }
10576 
10577         /* Check that INVALID_ENUM is generated by CompressedTextureSubImage1D if
10578          internalformat is not one of the generic compressed internal formats:
10579          COMPRESSED_RED, COMPRESSED_RG, COMPRESSED_RGB, COMPRESSED_RGBA.
10580          COMPRESSED_SRGB, or COMPRESSED_SRGB_ALPHA. */
10581         {
10582             /* GL_COMPRESSED_RG_RGTC2 is not 1D as specification says. */
10583             gl.compressedTextureSubImage1D(m_to_1D_compressed, 0, 0, s_reference_width, GL_COMPRESSED_RG_RGTC2,
10584                                            m_reference_compressed_1D_size, m_reference_compressed_1D);
10585             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glCompressedTextureSubImage1D",
10586                                       "internalformat is of the generic compressed internal formats: COMPRESSED_RED, "
10587                                       "COMPRESSED_RG, COMPRESSED_RGB, COMPRESSED_RGBA. COMPRESSED_SRGB, or "
10588                                       "COMPRESSED_SRGB_ALPHA.");
10589         }
10590 
10591         /* Check that INVALID_OPERATION is generated if format does not match the
10592          internal format of the texture image being modified, since these
10593          commands do not provide for image format conversion. */
10594         {
10595             gl.compressedTextureSubImage1D(m_to_1D_compressed, 0, 0, s_reference_width,
10596                                            m_not_matching_compressed_1D_format, m_not_matching_compressed_1D_size,
10597                                            m_reference_compressed_1D);
10598             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage1D",
10599                                       "format does not match the internal format of the texture image being modified, "
10600                                       "since these commands do not provide for image format conversion.");
10601         }
10602 
10603         /* Check that INVALID_VALUE is generated by CompressedTextureSubImage1D if
10604          imageSize is not consistent with the format, dimensions, and contents of
10605          the specified compressed image data. */
10606         {
10607             gl.compressedTextureSubImage1D(m_to_1D_compressed, 0, 0, s_reference_width,
10608                                            m_reference_compressed_1D_format, m_reference_compressed_1D_size - 1,
10609                                            m_reference_compressed_1D);
10610             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCompressedTextureSubImage1D",
10611                                       "imageSize is not consistent with the format, dimensions, and contents of the "
10612                                       "specified compressed image data.");
10613         }
10614 
10615         /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage1D
10616          if a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER
10617          target and the buffer object's data store is currently mapped. */
10618         {
10619             gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10620             GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10621 
10622             gl.mapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
10623 
10624             if (GL_NO_ERROR == gl.getError())
10625             {
10626                 gl.compressedTextureSubImage1D(m_to_1D_compressed, 0, 0, s_reference_width,
10627                                                m_reference_compressed_1D_format, m_reference_compressed_1D_size, NULL);
10628                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage1D",
10629                                           "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target "
10630                                           "and the buffer object's data store is currently mapped.");
10631 
10632                 gl.unmapBuffer(GL_PIXEL_UNPACK_BUFFER);
10633                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10634 
10635                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10636                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10637             }
10638         }
10639 
10640         /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage1D
10641          if a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER
10642          target and the data would be unpacked from the buffer object such that
10643          the memory reads required would exceed the data store size. */
10644         {
10645             gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10646             GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10647 
10648             gl.compressedTextureSubImage1D(m_to_1D_compressed, 0, 0, s_reference_width,
10649                                            m_reference_compressed_1D_format, m_reference_compressed_1D_size,
10650                                            glu::BufferOffsetAsPointer(s_reference_size * 2));
10651             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage1D",
10652                                       "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and "
10653                                       "the buffer object's data store is currently mapped.");
10654 
10655             gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10656             GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10657         }
10658     }
10659 
10660     return is_ok;
10661 }
10662 
10663 /** @brief Test (negative) of TextureSubImage2DCompressed
10664  *
10665  *  @return Test result.
10666  */
Test2DCompressed()10667 bool SubImageErrorsTest::Test2DCompressed()
10668 {
10669     /* Shortcut for GL functionality. */
10670     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
10671 
10672     /* Result. */
10673     bool is_ok = true;
10674 
10675     /* Do tests only if compressed 2D textures are supported. */
10676     if (DE_NULL != m_reference_compressed_2D)
10677     {
10678         /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage2D
10679          if texture is not the name of an existing texture object. */
10680         {
10681             gl.compressedTextureSubImage2D(m_to_invalid, 0, 0, 0, s_reference_width, s_reference_height,
10682                                            m_reference_compressed_2D_format, m_reference_compressed_2D_size,
10683                                            m_reference_compressed_2D);
10684             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage2D",
10685                                       "texture is not the name of an existing texture object.");
10686         }
10687 
10688         /* Check that INVALID_ENUM is generated by CompressedTextureSubImage2D if
10689          internalformat is of the generic compressed internal formats:
10690          COMPRESSED_RED, COMPRESSED_RG, COMPRESSED_RGB, COMPRESSED_RGBA.
10691          COMPRESSED_SRGB, or COMPRESSED_SRGB_ALPHA. */
10692         {
10693             gl.compressedTextureSubImage2D(m_to_2D_compressed, 0, 0, 0, s_reference_width, s_reference_height,
10694                                            GL_COMPRESSED_RG, m_reference_compressed_2D_size, m_reference_compressed_2D);
10695             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glCompressedTextureSubImage2D",
10696                                       "internalformat is of the generic compressed internal formats: COMPRESSED_RED, "
10697                                       "COMPRESSED_RG, COMPRESSED_RGB, COMPRESSED_RGBA. COMPRESSED_SRGB, or "
10698                                       "COMPRESSED_SRGB_ALPHA.");
10699         }
10700 
10701         /* Check that INVALID_OPERATION is generated if format does not match the
10702          internal format of the texture image being modified, since these
10703          commands do not provide for image format conversion. */
10704         {
10705             gl.compressedTextureSubImage2D(m_to_2D_compressed, 0, 0, 0, s_reference_width, s_reference_height,
10706                                            m_not_matching_compressed_2D_format, m_not_matching_compressed_2D_size,
10707                                            m_reference_compressed_2D);
10708             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage2D",
10709                                       "format does not match the internal format of the texture image being modified, "
10710                                       "since these commands do not provide for image format conversion.");
10711         }
10712 
10713         /* Check that INVALID_VALUE is generated by CompressedTextureSubImage2D if
10714          imageSize is not consistent with the format, dimensions, and contents of
10715          the specified compressed image data. */
10716         {
10717             gl.compressedTextureSubImage2D(m_to_2D_compressed, 0, 0, 0, s_reference_width, s_reference_height,
10718                                            m_reference_compressed_2D_format, m_reference_compressed_2D_size - 1,
10719                                            m_reference_compressed_2D);
10720             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCompressedTextureSubImage2D",
10721                                       "imageSize is not consistent with the format, dimensions, and contents of the "
10722                                       "specified compressed image data.");
10723         }
10724 
10725         /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage2D
10726          if a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER
10727          target and the buffer object's data store is currently mapped. */
10728         {
10729             gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10730             GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10731 
10732             gl.mapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
10733 
10734             if (GL_NO_ERROR == gl.getError())
10735             {
10736                 gl.compressedTextureSubImage2D(m_to_2D_compressed, 0, 0, 0, s_reference_width, s_reference_height,
10737                                                m_reference_compressed_2D_format, m_reference_compressed_2D_size, NULL);
10738                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage2D",
10739                                           "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target "
10740                                           "and the buffer object's data store is currently mapped.");
10741 
10742                 gl.unmapBuffer(GL_PIXEL_UNPACK_BUFFER);
10743                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10744 
10745                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10746                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10747             }
10748         }
10749 
10750         /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage2D
10751          if a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER
10752          target and the data would be unpacked from the buffer object such that
10753          the memory reads required would exceed the data store size. */
10754         {
10755             gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10756             GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10757 
10758             gl.compressedTextureSubImage2D(m_to_2D_compressed, 0, 0, 0, s_reference_width, s_reference_height,
10759                                            m_reference_compressed_2D_format, m_reference_compressed_2D_size,
10760                                            glu::BufferOffsetAsPointer(s_reference_size * 2));
10761             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage2D",
10762                                       "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and "
10763                                       "the buffer object's data store is currently mapped.");
10764 
10765             gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10766             GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10767         }
10768 
10769         /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage2D
10770          if the effective target is TEXTURE_RECTANGLE. */
10771         if (DE_NULL !=
10772             m_reference_compressed_rectangle) /* Do test only if rectangle compressed texture is supported by the implementation. */
10773         {
10774             gl.compressedTextureSubImage2D(m_to_rectangle_compressed, 0, 0, 0, s_reference_width, s_reference_height,
10775                                            m_reference_compressed_rectangle_format,
10776                                            m_reference_compressed_rectangle_size, m_reference_compressed_rectangle);
10777 
10778             if (m_context.getContextInfo().isExtensionSupported("GL_NV_texture_rectangle_compressed"))
10779             {
10780                 is_ok &= CheckErrorAndLog(m_context, GL_NO_ERROR, "glCompressedTextureSubImage2D",
10781                                           "a rectangle texture object is used with this function.");
10782             }
10783             else
10784             {
10785                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage2D",
10786                                           "a rectangle texture object is used with this function.");
10787             }
10788         }
10789     }
10790 
10791     return is_ok;
10792 }
10793 
10794 /** @brief Test (negative) of TextureSubImage3DCompressed
10795  *
10796  *  @return Test result.
10797  */
Test3DCompressed()10798 bool SubImageErrorsTest::Test3DCompressed()
10799 {
10800     /* Shortcut for GL functionality. */
10801     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
10802 
10803     /* Result. */
10804     bool is_ok = true;
10805 
10806     /* Do tests only if compressed 3D textures are supported. */
10807     if (DE_NULL != m_reference_compressed_3D)
10808     {
10809         /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage3D
10810          if texture is not the name of an existing texture object. */
10811         {
10812             gl.compressedTextureSubImage3D(m_to_invalid, 0, 0, 0, 0, s_reference_width, s_reference_height,
10813                                            s_reference_depth, m_reference_compressed_3D_format,
10814                                            m_reference_compressed_3D_size, m_reference_compressed_3D);
10815             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage3D",
10816                                       "texture is not the name of an existing texture object.");
10817         }
10818 
10819         /* Check that INVALID_ENUM is generated by CompressedTextureSubImage3D if
10820          internalformat is of the generic compressed internal formats:
10821          COMPRESSED_RED, COMPRESSED_RG, COMPRESSED_RGB, COMPRESSED_RGBA.
10822          COMPRESSED_SRGB, or COMPRESSED_SRGB_ALPHA. */
10823         {
10824             gl.compressedTextureSubImage3D(m_to_3D_compressed, 0, 0, 0, 0, s_reference_width, s_reference_height,
10825                                            s_reference_depth, GL_COMPRESSED_RG, m_reference_compressed_3D_size,
10826                                            m_reference_compressed_3D);
10827             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glCompressedTextureSubImage3D",
10828                                       "internalformat is of the generic compressed internal formats: COMPRESSED_RED, "
10829                                       "COMPRESSED_RG, COMPRESSED_RGB, COMPRESSED_RGBA. COMPRESSED_SRGB, or "
10830                                       "COMPRESSED_SRGB_ALPHA.");
10831         }
10832 
10833         /* Check that INVALID_OPERATION is generated if format does not match the
10834          internal format of the texture image being modified, since these
10835          commands do not provide for image format conversion. */
10836         {
10837             gl.compressedTextureSubImage3D(m_to_3D_compressed, 0, 0, 0, 0, s_reference_width, s_reference_height,
10838                                            s_reference_depth, m_not_matching_compressed_3D_format,
10839                                            m_not_matching_compressed_3D_size, m_reference_compressed_3D);
10840             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage3D",
10841                                       "format does not match the internal format of the texture image being modified, "
10842                                       "since these commands do not provide for image format conversion.");
10843         }
10844 
10845         /* Check that INVALID_VALUE is generated by CompressedTextureSubImage3D if
10846          imageSize is not consistent with the format, dimensions, and contents of
10847          the specified compressed image data. */
10848         {
10849             gl.compressedTextureSubImage3D(m_to_3D_compressed, 0, 0, 0, 0, s_reference_width, s_reference_height,
10850                                            s_reference_depth, m_reference_compressed_3D_format,
10851                                            m_reference_compressed_3D_size - 1, m_reference_compressed_3D);
10852             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCompressedTextureSubImage3D",
10853                                       "imageSize is not consistent with the format, dimensions, and contents of the "
10854                                       "specified compressed image data.");
10855         }
10856 
10857         /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage3D
10858          if a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER
10859          target and the buffer object's data store is currently mapped. */
10860         {
10861             gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10862             GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10863 
10864             gl.mapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
10865 
10866             if (GL_NO_ERROR == gl.getError())
10867             {
10868                 gl.compressedTextureSubImage3D(m_to_3D_compressed, 0, 0, 0, 0, s_reference_width, s_reference_height,
10869                                                s_reference_depth, m_reference_compressed_3D_format,
10870                                                m_reference_compressed_3D_size, NULL);
10871                 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage3D",
10872                                           "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target "
10873                                           "and the buffer object's data store is currently mapped.");
10874 
10875                 gl.unmapBuffer(GL_PIXEL_UNPACK_BUFFER);
10876                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10877 
10878                 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10879                 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10880             }
10881         }
10882 
10883         /* Check that INVALID_OPERATION is generated by CompressedTextureSubImage3D
10884          if a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER
10885          target and the data would be unpacked from the buffer object such that
10886          the memory reads required would exceed the data store size. */
10887         {
10888             gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, m_bo);
10889             GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10890 
10891             gl.compressedTextureSubImage3D(m_to_3D_compressed, 0, 0, 0, 0, s_reference_width, s_reference_height,
10892                                            s_reference_depth, m_reference_compressed_3D_format,
10893                                            m_reference_compressed_3D_size,
10894                                            glu::BufferOffsetAsPointer(s_reference_size * 2));
10895             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCompressedTextureSubImage3D",
10896                                       "a non-zero buffer object name is bound to the PIXEL_UNPACK_BUFFER target and "
10897                                       "the buffer object's data store is currently mapped.");
10898 
10899             gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10900             GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
10901         }
10902     }
10903 
10904     return is_ok;
10905 }
10906 
10907 /** @brief Clean GL objects, test variables and GL errors.
10908  */
Clean()10909 void SubImageErrorsTest::Clean()
10910 {
10911     /* Shortcut for GL functionality. */
10912     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
10913 
10914     /* Cleanup. */
10915     if (m_to_1D_empty)
10916     {
10917         gl.deleteTextures(1, &m_to_1D_empty);
10918 
10919         m_to_1D_empty = 0;
10920     }
10921 
10922     if (m_to_2D_empty)
10923     {
10924         gl.deleteTextures(1, &m_to_2D_empty);
10925 
10926         m_to_2D_empty = 0;
10927     }
10928 
10929     if (m_to_3D_empty)
10930     {
10931         gl.deleteTextures(1, &m_to_3D_empty);
10932 
10933         m_to_3D_empty = 0;
10934     }
10935 
10936     if (m_to_1D)
10937     {
10938         gl.deleteTextures(1, &m_to_1D);
10939 
10940         m_to_1D = 0;
10941     }
10942 
10943     if (m_to_2D)
10944     {
10945         gl.deleteTextures(1, &m_to_2D);
10946 
10947         m_to_2D = 0;
10948     }
10949 
10950     if (m_to_3D)
10951     {
10952         gl.deleteTextures(1, &m_to_3D);
10953 
10954         m_to_3D = 0;
10955     }
10956 
10957     if (m_to_1D_compressed)
10958     {
10959         gl.deleteTextures(1, &m_to_1D_compressed);
10960 
10961         m_to_1D_compressed = 0;
10962     }
10963 
10964     if (m_to_2D_compressed)
10965     {
10966         gl.deleteTextures(1, &m_to_2D_compressed);
10967 
10968         m_to_2D_compressed = 0;
10969     }
10970 
10971     if (m_to_3D_compressed)
10972     {
10973         gl.deleteTextures(1, &m_to_3D_compressed);
10974 
10975         m_to_3D_compressed = 0;
10976     }
10977 
10978     if (m_to_rectangle_compressed)
10979     {
10980         gl.deleteTextures(1, &m_to_rectangle_compressed);
10981 
10982         m_to_rectangle_compressed = 0;
10983     }
10984 
10985     if (m_bo)
10986     {
10987         gl.deleteBuffers(1, &m_bo);
10988 
10989         m_bo = 0;
10990     }
10991 
10992     m_to_invalid       = 0;
10993     m_format_invalid   = 0;
10994     m_type_invalid     = 0;
10995     m_max_texture_size = 1;
10996 
10997     if (DE_NULL != m_reference_compressed_1D)
10998     {
10999         delete[] m_reference_compressed_1D;
11000 
11001         m_reference_compressed_1D = NULL;
11002     }
11003 
11004     if (DE_NULL != m_reference_compressed_2D)
11005     {
11006         delete[] m_reference_compressed_2D;
11007 
11008         m_reference_compressed_2D = NULL;
11009     }
11010 
11011     if (DE_NULL != m_reference_compressed_3D)
11012     {
11013         delete[] m_reference_compressed_3D;
11014 
11015         m_reference_compressed_3D = NULL;
11016     }
11017 
11018     if (DE_NULL != m_reference_compressed_rectangle)
11019     {
11020         delete[] m_reference_compressed_rectangle;
11021 
11022         m_reference_compressed_rectangle = NULL;
11023     }
11024 
11025     m_reference_compressed_1D_format        = 0;
11026     m_reference_compressed_2D_format        = 0;
11027     m_reference_compressed_3D_format        = 0;
11028     m_reference_compressed_rectangle_format = 0;
11029     m_reference_compressed_1D_size          = 0;
11030     m_reference_compressed_2D_size          = 0;
11031     m_reference_compressed_3D_size          = 0;
11032     m_reference_compressed_rectangle_size   = 0;
11033     m_not_matching_compressed_1D_format     = 0;
11034     m_not_matching_compressed_1D_size       = 0;
11035     m_not_matching_compressed_2D_format     = 0;
11036     m_not_matching_compressed_2D_size       = 0;
11037     m_not_matching_compressed_3D_format     = 0;
11038     m_not_matching_compressed_3D_size       = 0;
11039 
11040     while (GL_NO_ERROR != gl.getError())
11041         ;
11042 }
11043 
11044 /** Reference data */
11045 const glw::GLushort SubImageErrorsTest::s_reference[] = {
11046     0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
11047     0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
11048     0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
11049     0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff,
11050 
11051     0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
11052     0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
11053     0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
11054     0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff,
11055 
11056     0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
11057     0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
11058     0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
11059     0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff,
11060 
11061     0x0,  0x0,  0x0,  0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff,
11062     0x88, 0x0,  0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0,  0xff,
11063     0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff,
11064     0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0,  0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff};
11065 
11066 /** Reference data parameters. */
11067 const glw::GLuint SubImageErrorsTest::s_reference_size                      = sizeof(s_reference);
11068 const glw::GLuint SubImageErrorsTest::s_reference_width                     = 4;
11069 const glw::GLuint SubImageErrorsTest::s_reference_height                    = 4;
11070 const glw::GLuint SubImageErrorsTest::s_reference_depth                     = 4;
11071 const glw::GLenum SubImageErrorsTest::s_reference_internalformat            = GL_RG8;
11072 const glw::GLenum SubImageErrorsTest::s_reference_internalformat_compressed = GL_COMPRESSED_RG;
11073 const glw::GLenum SubImageErrorsTest::s_reference_format = GL_RG; /* !Must not be a RGB, RGBA, or BGRA */
11074 const glw::GLenum SubImageErrorsTest::s_reference_type   = GL_UNSIGNED_SHORT;
11075 
11076 /******************************** Copy Errors Test Implementation   ********************************/
11077 
11078 /** @brief Copy Errors Test constructor.
11079  *
11080  *  @param [in] context     OpenGL context.
11081  */
CopyErrorsTest(deqp::Context & context)11082 CopyErrorsTest::CopyErrorsTest(deqp::Context &context)
11083     : deqp::TestCase(context, "textures_copy_errors", "Texture Copy Errors Test")
11084     , m_fbo(0)
11085     , m_fbo_ms(0)
11086     , m_fbo_incomplete(0)
11087     , m_to_src(0)
11088     , m_to_src_ms(0)
11089     , m_to_1D_dst(0)
11090     , m_to_2D_dst(0)
11091     , m_to_3D_dst(0)
11092     , m_to_invalid(0)
11093 {
11094     /* Intentionally left blank. */
11095 }
11096 
11097 /** @brief Iterate Copy Errors Test cases.
11098  *
11099  *  @return Iteration result.
11100  */
iterate()11101 tcu::TestNode::IterateResult CopyErrorsTest::iterate()
11102 {
11103     /* Get context setup. */
11104     bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
11105     bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
11106 
11107     if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
11108     {
11109         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
11110 
11111         return STOP;
11112     }
11113 
11114     /* Running tests. */
11115     bool is_ok    = true;
11116     bool is_error = false;
11117 
11118     try
11119     {
11120         Prepare();
11121 
11122         is_ok &= Test1D();
11123         is_ok &= Test2D();
11124         is_ok &= Test3D();
11125     }
11126     catch (...)
11127     {
11128         is_ok    = false;
11129         is_error = true;
11130     }
11131 
11132     /* Cleanup. */
11133     Clean();
11134 
11135     /* Result's setup. */
11136     if (is_ok)
11137     {
11138         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
11139     }
11140     else
11141     {
11142         if (is_error)
11143         {
11144             m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
11145         }
11146         else
11147         {
11148             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
11149         }
11150     }
11151 
11152     return STOP;
11153 }
11154 
11155 /** @brief Prepare test's objects and values.
11156  */
Prepare()11157 void CopyErrorsTest::Prepare()
11158 {
11159     /* Shortcut for GL functionality. */
11160     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
11161 
11162     /* Auxiliary objects setup. */
11163 
11164     /* Framebuffer. */
11165     gl.genFramebuffers(1, &m_fbo);
11166     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
11167 
11168     gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
11169     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11170 
11171     gl.createTextures(GL_TEXTURE_2D, 1, &m_to_src);
11172     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
11173 
11174     gl.textureStorage2D(m_to_src, 1, s_internalformat, s_width, s_height);
11175     GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2D has failed");
11176 
11177     gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_to_src, 0);
11178     GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture1D call failed.");
11179 
11180     if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
11181     {
11182         throw 0;
11183     }
11184 
11185     gl.viewport(0, 0, s_width, s_height);
11186     GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
11187 
11188     gl.clear(GL_COLOR_BUFFER_BIT);
11189     GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
11190 
11191     /* Framebuffer Multisample. */
11192     gl.genFramebuffers(1, &m_fbo_ms);
11193     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
11194 
11195     gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
11196     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11197 
11198     gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &m_to_src_ms);
11199     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
11200 
11201     gl.textureStorage2DMultisample(m_to_src_ms, 1, s_internalformat, s_width, s_height, false);
11202     GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2DMultisample has failed");
11203 
11204     gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, m_to_src_ms, 0);
11205     GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture1D call failed.");
11206 
11207     if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
11208     {
11209         throw 0;
11210     }
11211 
11212     gl.viewport(0, 0, s_width, s_height);
11213     GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
11214 
11215     gl.clear(GL_COLOR_BUFFER_BIT);
11216     GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed.");
11217 
11218     /* Framebuffer Incomplete. */
11219     gl.createFramebuffers(1, &m_fbo_incomplete);
11220     GLU_EXPECT_NO_ERROR(gl.getError(), "glcreateFramebuffers call failed.");
11221 
11222     /* 1D */
11223     gl.createTextures(GL_TEXTURE_1D, 1, &m_to_1D_dst);
11224     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
11225 
11226     gl.textureStorage1D(m_to_1D_dst, 1, s_internalformat, s_width);
11227     GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2D has failed");
11228 
11229     /* 2D */
11230     gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D_dst);
11231     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
11232 
11233     gl.textureStorage2D(m_to_2D_dst, 1, s_internalformat, s_width, s_height);
11234     GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2D has failed");
11235 
11236     /* 3D */
11237     gl.createTextures(GL_TEXTURE_3D, 1, &m_to_3D_dst);
11238     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
11239 
11240     gl.textureStorage3D(m_to_3D_dst, 1, s_internalformat, s_width, s_height, s_depth);
11241     GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2D has failed");
11242 
11243     /* invalid texture object */
11244     while (gl.isTexture(++m_to_invalid))
11245         ;
11246     GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed");
11247 }
11248 
11249 /** @brief Test (negative) of CopyTextureSubImage1D
11250  *
11251  *  @return Test result.
11252  */
Test1D()11253 bool CopyErrorsTest::Test1D()
11254 {
11255     /* Shortcut for GL functionality. */
11256     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
11257 
11258     /* Result. */
11259     bool is_ok = true;
11260 
11261     /* Bind framebuffer. */
11262     gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_incomplete);
11263     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11264 
11265     /* Check that INVALID_FRAMEBUFFER_OPERATION is generated by
11266      CopyTextureSubImage1D if the object bound to READ_FRAMEBUFFER_BINDING is
11267      not framebuffer complete. */
11268     {
11269         gl.copyTextureSubImage1D(m_to_1D_dst, 0, 0, 0, 0, s_width);
11270         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_FRAMEBUFFER_OPERATION, "glCopyTextureSubImage1D",
11271                                   "the object bound to READ_FRAMEBUFFER_BINDING is not framebuffer complete.");
11272     }
11273 
11274     /* Bind framebuffer. */
11275     gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
11276     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11277 
11278     gl.readBuffer(GL_COLOR_ATTACHMENT0);
11279     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11280 
11281     /* Check that INVALID_OPERATION is generated by CopyTextureSubImage1D if
11282      texture is not the name of an existing texture object, or if the
11283      effective target of texture is not TEXTURE_1D. */
11284     {
11285         gl.copyTextureSubImage1D(m_to_invalid, 0, 0, 0, 0, s_width);
11286         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage1D",
11287                                   "texture is not the name of an existing texture object.");
11288 
11289         gl.copyTextureSubImage1D(m_to_2D_dst, 0, 0, 0, 0, s_width);
11290         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage1D",
11291                                   "the effective target of texture is not TEXTURE_1D.");
11292     }
11293 
11294     /* Check that INVALID_VALUE is generated by CopyTextureSubImage1D if level is less than 0. */
11295     {
11296         gl.copyTextureSubImage1D(m_to_1D_dst, -1, 0, 0, 0, s_width);
11297         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage1D", "level is less than 0.");
11298     }
11299 
11300     /* Check that INVALID_VALUE is generated by CopyTextureSubImage1D if
11301      xoffset<0, or (xoffset+width)>w, where w is the TEXTURE_WIDTH of the
11302      texture image being modified. */
11303     {
11304         gl.copyTextureSubImage1D(m_to_1D_dst, 0, -1, 0, 0, s_width);
11305         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage1D", "xoffset<0.");
11306 
11307         gl.copyTextureSubImage1D(m_to_1D_dst, 0, 1, 0, 0, s_width);
11308         is_ok &=
11309             CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage1D",
11310                              "(xoffset+width)>w, where w is the TEXTURE_WIDTH of the texture image being modified.");
11311     }
11312 
11313     /* Check that INVALID_OPERATION is generated by CopyTextureSubImage1D if
11314      the read buffer is NONE. */
11315     gl.readBuffer(GL_NONE);
11316     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11317 
11318     {
11319         gl.copyTextureSubImage1D(m_to_1D_dst, 0, 0, 0, 0, s_width);
11320         is_ok &=
11321             CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage1D", "the read buffer is NONE.");
11322     }
11323 
11324     /* Bind multisample framebuffer. */
11325     gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
11326     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11327 
11328     gl.readBuffer(GL_COLOR_ATTACHMENT0);
11329     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11330 
11331     /* Check that INVALID_OPERATION is generated by CopyTextureSubImage1D if
11332      the effective value of SAMPLE_BUFFERS for the read
11333      framebuffer is one. */
11334     {
11335         gl.copyTextureSubImage1D(m_to_1D_dst, 0, 0, 0, 0, s_width);
11336         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage1D",
11337                                   "the effective value of SAMPLE_BUFFERS for the read framebuffer is one.");
11338     }
11339 
11340     return is_ok;
11341 }
11342 
11343 /** @brief Test (negative) of CopyTextureSubImage2D
11344  *
11345  *  @return Test result.
11346  */
Test2D()11347 bool CopyErrorsTest::Test2D()
11348 {
11349     /* Shortcut for GL functionality. */
11350     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
11351 
11352     /* Result. */
11353     bool is_ok = true;
11354 
11355     /* Bind framebuffer. */
11356     gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_incomplete);
11357     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11358 
11359     /* Check that INVALID_FRAMEBUFFER_OPERATION is generated by
11360      CopyTextureSubImage2D if the object bound to READ_FRAMEBUFFER_BINDING is
11361      not framebuffer complete. */
11362     {
11363         gl.copyTextureSubImage2D(m_to_2D_dst, 0, 0, 0, 0, 0, s_width, s_height);
11364         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_FRAMEBUFFER_OPERATION, "glCopyTextureSubImage2D",
11365                                   "the object bound to READ_FRAMEBUFFER_BINDING is not framebuffer complete.");
11366     }
11367 
11368     /* Bind framebuffer. */
11369     gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
11370     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11371 
11372     gl.readBuffer(GL_COLOR_ATTACHMENT0);
11373     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11374 
11375     /* Check that INVALID_OPERATION is generated by CopyTextureSubImage2D if
11376      texture is not the name of an existing texture object, or if the
11377      effective target of texture is not TEXTURE_2D. */
11378     {
11379         gl.copyTextureSubImage2D(m_to_invalid, 0, 0, 0, 0, 0, s_width, s_height);
11380         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage2D",
11381                                   "texture is not the name of an existing texture object.");
11382 
11383         gl.copyTextureSubImage2D(m_to_1D_dst, 0, 0, 0, 0, 0, s_width, s_height);
11384         is_ok &= CheckErrorAndLog(
11385             m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage2D",
11386             "the effective target of does not correspond to one of the texture targets supported by the function..");
11387     }
11388 
11389     /* Check that INVALID_VALUE is generated by CopyTextureSubImage2D if level is less than 0. */
11390     {
11391         gl.copyTextureSubImage2D(m_to_2D_dst, -1, 0, 0, 0, 0, s_width, s_height);
11392         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage2D", "level is less than 0.");
11393     }
11394 
11395     /* Check that INVALID_VALUE is generated by CopyTextureSubImage2D if
11396      xoffset<0, (xoffset+width)>w, yoffset<0, or (yoffset+height)>0, where w
11397      is the TEXTURE_WIDTH, h is the TEXTURE_HEIGHT and of the texture image
11398      being modified. */
11399     {
11400         gl.copyTextureSubImage2D(m_to_2D_dst, 0, -1, 0, 0, 0, s_width, s_height);
11401         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage2D", "xoffset<0.");
11402 
11403         gl.copyTextureSubImage2D(m_to_2D_dst, 0, 1, 0, 0, 0, s_width, s_height);
11404         is_ok &=
11405             CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage2D",
11406                              "(xoffset+width)>w, where w is the TEXTURE_WIDTH of the texture image being modified.");
11407 
11408         gl.copyTextureSubImage2D(m_to_2D_dst, 0, 0, -1, 0, 0, s_width, s_height);
11409         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage2D", "yoffset<0.");
11410 
11411         gl.copyTextureSubImage2D(m_to_2D_dst, 0, 0, 1, 0, 0, s_width, s_height);
11412         is_ok &=
11413             CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage2D",
11414                              "(yoffset+height)>h, where h is the TEXTURE_HEIGHT of the texture image being modified.");
11415     }
11416 
11417     /* Check that INVALID_OPERATION is generated by CopyTextureSubImage2D if
11418      the read buffer is NONE. */
11419     gl.readBuffer(GL_NONE);
11420     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11421 
11422     {
11423         gl.copyTextureSubImage2D(m_to_2D_dst, 0, 0, 0, 0, 0, s_width, s_height);
11424         is_ok &=
11425             CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage2D", "the read buffer is NONE.");
11426     }
11427 
11428     /* Bind multisample framebuffer. */
11429     gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
11430     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11431 
11432     gl.readBuffer(GL_COLOR_ATTACHMENT0);
11433     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11434 
11435     /* Check that INVALID_OPERATION is generated by CopyTextureSubImage2D if
11436      the effective value of SAMPLE_BUFFERS for the read
11437      framebuffer is one. */
11438     {
11439         gl.copyTextureSubImage2D(m_to_2D_dst, 0, 0, 0, 0, 0, s_width, s_height);
11440         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage2D",
11441                                   "the effective value of SAMPLE_BUFFERS for the read framebuffer is one.");
11442     }
11443 
11444     return is_ok;
11445 }
11446 
11447 /** @brief Test (negative) of CopyTextureSubImage3D
11448  *
11449  *  @return Test result.
11450  */
Test3D()11451 bool CopyErrorsTest::Test3D()
11452 {
11453     /* Shortcut for GL functionality. */
11454     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
11455 
11456     /* Result. */
11457     bool is_ok = true;
11458 
11459     /* Bind framebuffer. */
11460     gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_incomplete);
11461     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11462 
11463     /* Check that INVALID_FRAMEBUFFER_OPERATION is generated by
11464      CopyTextureSubImage3D if the object bound to READ_FRAMEBUFFER_BINDING is
11465      not framebuffer complete. */
11466     {
11467         gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, 0, 0, 0, 0, s_width, s_height);
11468         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_FRAMEBUFFER_OPERATION, "glCopyTextureSubImage3D",
11469                                   "the object bound to READ_FRAMEBUFFER_BINDING is not framebuffer complete.");
11470     }
11471 
11472     /* Bind framebuffer. */
11473     gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
11474     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11475 
11476     gl.readBuffer(GL_COLOR_ATTACHMENT0);
11477     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11478 
11479     /* Check that INVALID_OPERATION is generated by CopyTextureSubImage3D if
11480      texture is not the name of an existing texture object, or if the
11481      effective target of texture is not supported by the function. */
11482     {
11483         gl.copyTextureSubImage3D(m_to_invalid, 0, 0, 0, 0, 0, 0, s_width, s_height);
11484         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage3D",
11485                                   "texture is not the name of an existing texture object.");
11486 
11487         gl.copyTextureSubImage3D(m_to_1D_dst, 0, 0, 0, 0, 0, 0, s_width, s_height);
11488         is_ok &= CheckErrorAndLog(
11489             m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage3D",
11490             "the effective target of does not correspond to one of the texture targets supported by the function..");
11491     }
11492 
11493     /* Check that INVALID_VALUE is generated by CopyTextureSubImage3D if level is less than 0. */
11494     {
11495         gl.copyTextureSubImage3D(m_to_3D_dst, -1, 0, 0, 0, 0, 0, s_width, s_height);
11496         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D", "level is less than 0.");
11497     }
11498 
11499     /* Check that INVALID_VALUE is generated by CopyTextureSubImage3D if
11500      xoffset<0, (xoffset+width)>w, yoffset<0, (yoffset+height)>h, zoffset<0,
11501      or (zoffset+1)>d, where w is the TEXTURE_WIDTH, h is the TEXTURE_HEIGHT,
11502      d is the TEXTURE_DEPTH and of the texture image being modified. Note
11503      that w, h, and d include twice the border width.  */
11504     {
11505         gl.copyTextureSubImage3D(m_to_3D_dst, 0, -1, 0, 0, 0, 0, s_width, s_height);
11506         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D", "xoffset<0.");
11507 
11508         gl.copyTextureSubImage3D(m_to_3D_dst, 0, 1, 0, 0, 0, 0, s_width, s_height);
11509         is_ok &=
11510             CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D",
11511                              "(xoffset+width)>w, where w is the TEXTURE_WIDTH of the texture image being modified.");
11512 
11513         gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, -1, 0, 0, 0, s_width, s_height);
11514         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D", "yoffset<0.");
11515 
11516         gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, 1, 0, 0, 0, s_width, s_height);
11517         is_ok &=
11518             CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D",
11519                              "(yoffset+height)>h, where h is the TEXTURE_HEIGHT of the texture image being modified.");
11520 
11521         gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, 0, -1, 0, 0, s_width, s_height);
11522         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D", "zoffset<0.");
11523 
11524         gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, 0, s_depth + 1, 0, 0, s_width, s_height);
11525         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCopyTextureSubImage3D",
11526                                   "(zoffset+1)>d, where d is the TEXTURE_DEPTH of the texture image being modified.");
11527     }
11528 
11529     /* Check that INVALID_OPERATION is generated by CopyTextureSubImage3D if
11530      the read buffer is NONE. */
11531     gl.readBuffer(GL_NONE);
11532     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11533 
11534     {
11535         gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, 0, 0, 0, 0, s_width, s_height);
11536         is_ok &=
11537             CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage3D", "the read buffer is NONE.");
11538     }
11539 
11540     /* Bind multisample framebuffer. */
11541     gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms);
11542     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11543 
11544     gl.readBuffer(GL_COLOR_ATTACHMENT0);
11545     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
11546 
11547     /* Check that INVALID_OPERATION is generated by CopyTextureSubImage3D if
11548      the effective value of SAMPLE_BUFFERS for the read
11549      framebuffer is one. */
11550     {
11551         gl.copyTextureSubImage3D(m_to_3D_dst, 0, 0, 0, 0, 0, 0, s_width, s_height);
11552         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glCopyTextureSubImage3D",
11553                                   "the effective value of SAMPLE_BUFFERS for the read framebuffer is one.");
11554     }
11555 
11556     return is_ok;
11557 }
11558 
11559 /** @brief Clean GL objects, test variables and GL errors.
11560  */
Clean()11561 void CopyErrorsTest::Clean()
11562 {
11563     /* Shortcut for GL functionality. */
11564     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
11565 
11566     /* Cleanup. */
11567     if (m_fbo)
11568     {
11569         gl.deleteFramebuffers(1, &m_fbo);
11570 
11571         m_fbo = 0;
11572     }
11573 
11574     if (m_fbo_ms)
11575     {
11576         gl.deleteFramebuffers(1, &m_fbo_ms);
11577 
11578         m_fbo_ms = 0;
11579     }
11580 
11581     if (m_fbo_incomplete)
11582     {
11583         gl.deleteFramebuffers(1, &m_fbo_incomplete);
11584 
11585         m_fbo_incomplete = 0;
11586     }
11587 
11588     if (m_to_src)
11589     {
11590         gl.deleteTextures(1, &m_to_src);
11591 
11592         m_to_src = 0;
11593     }
11594 
11595     if (m_to_src_ms)
11596     {
11597         gl.deleteTextures(1, &m_to_src_ms);
11598 
11599         m_to_src_ms = 0;
11600     }
11601 
11602     if (m_to_1D_dst)
11603     {
11604         gl.deleteTextures(1, &m_to_1D_dst);
11605 
11606         m_to_1D_dst = 0;
11607     }
11608 
11609     if (m_to_2D_dst)
11610     {
11611         gl.deleteTextures(1, &m_to_2D_dst);
11612 
11613         m_to_2D_dst = 0;
11614     }
11615 
11616     if (m_to_3D_dst)
11617     {
11618         gl.deleteTextures(1, &m_to_3D_dst);
11619 
11620         m_to_3D_dst = 0;
11621     }
11622 
11623     m_to_invalid = 0;
11624 
11625     while (GL_NO_ERROR != gl.getError())
11626         ;
11627 }
11628 
11629 /* Test's parameters. */
11630 const glw::GLuint CopyErrorsTest::s_width          = 4;
11631 const glw::GLuint CopyErrorsTest::s_height         = 4;
11632 const glw::GLuint CopyErrorsTest::s_depth          = 4;
11633 const glw::GLuint CopyErrorsTest::s_internalformat = GL_RGBA8;
11634 
11635 /******************************** Parameter Setup Errors Test Implementation   ********************************/
11636 
11637 /** @brief Parameter Setup Errors Test constructor.
11638  *
11639  *  @param [in] context     OpenGL context.
11640  */
ParameterSetupErrorsTest(deqp::Context & context)11641 ParameterSetupErrorsTest::ParameterSetupErrorsTest(deqp::Context &context)
11642     : deqp::TestCase(context, "textures_parameter_setup_errors", "Texture Parameter Setup Errors Test")
11643     , m_to_2D(0)
11644     , m_to_2D_ms(0)
11645     , m_to_rectangle(0)
11646     , m_to_invalid(0)
11647     , m_pname_invalid(0)
11648     , m_depth_stencil_mode_invalid(0)
11649 {
11650     /* Intentionally left blank. */
11651 }
11652 
11653 /** @brief Iterate Parameter Setup Errors Test cases.
11654  *
11655  *  @return Iteration result.
11656  */
iterate()11657 tcu::TestNode::IterateResult ParameterSetupErrorsTest::iterate()
11658 {
11659     /* Get context setup. */
11660     bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
11661     bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
11662 
11663     if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
11664     {
11665         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
11666 
11667         return STOP;
11668     }
11669 
11670     /* Running tests. */
11671     bool is_ok    = true;
11672     bool is_error = false;
11673 
11674     try
11675     {
11676         Prepare();
11677 
11678         is_ok &= Testf();
11679         is_ok &= Testi();
11680         is_ok &= Testfv();
11681         is_ok &= Testiv();
11682         is_ok &= TestIiv();
11683         is_ok &= TestIuiv();
11684     }
11685     catch (...)
11686     {
11687         is_ok    = false;
11688         is_error = true;
11689     }
11690 
11691     /* Cleanup. */
11692     Clean();
11693 
11694     /* Result's setup. */
11695     if (is_ok)
11696     {
11697         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
11698     }
11699     else
11700     {
11701         if (is_error)
11702         {
11703             m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
11704         }
11705         else
11706         {
11707             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
11708         }
11709     }
11710 
11711     return STOP;
11712 }
11713 
11714 /** @brief Test's preparations.
11715  */
Prepare()11716 void ParameterSetupErrorsTest::Prepare()
11717 {
11718     /* Shortcut for GL functionality. */
11719     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
11720 
11721     /* Auxiliary objects setup. */
11722 
11723     /* 2D */
11724     gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D);
11725     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
11726 
11727     /* 3D */
11728     gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &m_to_2D_ms);
11729     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
11730 
11731     /* RECTANGLE */
11732     gl.createTextures(GL_TEXTURE_RECTANGLE, 1, &m_to_rectangle);
11733     GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed");
11734 
11735     /* Invalid texture object. */
11736     while (gl.isTexture(++m_to_invalid))
11737         ;
11738     GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed");
11739 
11740     /* Invalid parameter name. */
11741     glw::GLenum all_pnames[]     = {GL_DEPTH_STENCIL_TEXTURE_MODE,
11742                                     GL_TEXTURE_BASE_LEVEL,
11743                                     GL_TEXTURE_COMPARE_FUNC,
11744                                     GL_TEXTURE_COMPARE_MODE,
11745                                     GL_TEXTURE_LOD_BIAS,
11746                                     GL_TEXTURE_MIN_FILTER,
11747                                     GL_TEXTURE_MAG_FILTER,
11748                                     GL_TEXTURE_MIN_LOD,
11749                                     GL_TEXTURE_MAX_LOD,
11750                                     GL_TEXTURE_MAX_LEVEL,
11751                                     GL_TEXTURE_SWIZZLE_R,
11752                                     GL_TEXTURE_SWIZZLE_G,
11753                                     GL_TEXTURE_SWIZZLE_B,
11754                                     GL_TEXTURE_SWIZZLE_A,
11755                                     GL_TEXTURE_WRAP_S,
11756                                     GL_TEXTURE_WRAP_T,
11757                                     GL_TEXTURE_WRAP_R,
11758                                     GL_TEXTURE_BORDER_COLOR,
11759                                     GL_TEXTURE_SWIZZLE_RGBA};
11760     glw::GLuint all_pnames_count = sizeof(all_pnames) / sizeof(all_pnames[0]);
11761 
11762     bool is_valid = true;
11763 
11764     while (is_valid)
11765     {
11766         is_valid = false;
11767         ++m_pname_invalid;
11768 
11769         for (glw::GLuint i = 0; i < all_pnames_count; ++i)
11770         {
11771             if (all_pnames[i] == m_pname_invalid)
11772             {
11773                 is_valid = true;
11774 
11775                 break;
11776             }
11777         }
11778     }
11779 
11780     /* Invalid depth stencil mode name. */
11781     glw::GLenum all_depth_stencil_modes[]     = {GL_DEPTH_COMPONENT, GL_STENCIL_INDEX};
11782     glw::GLuint all_depth_stencil_modes_count = sizeof(all_depth_stencil_modes) / sizeof(all_depth_stencil_modes[0]);
11783 
11784     is_valid = true;
11785 
11786     while (is_valid)
11787     {
11788         is_valid = false;
11789         ++m_depth_stencil_mode_invalid;
11790 
11791         for (glw::GLuint i = 0; i < all_depth_stencil_modes_count; ++i)
11792         {
11793             if (all_depth_stencil_modes[i] == m_depth_stencil_mode_invalid)
11794             {
11795                 is_valid = true;
11796 
11797                 break;
11798             }
11799         }
11800     }
11801 }
11802 
11803 /** @brief Test (negative) of TextureParameterf
11804  *
11805  *  @return Test result.
11806  */
Testf()11807 bool ParameterSetupErrorsTest::Testf()
11808 {
11809     /* Shortcut for GL functionality. */
11810     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
11811 
11812     /* Result. */
11813     bool is_ok = true;
11814 
11815     /* Check that INVALID_ENUM is generated by TextureParameter* if pname is
11816      not one of the accepted defined values. */
11817     {
11818         gl.textureParameterf(m_to_2D, m_pname_invalid, 1.f);
11819 
11820         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterf",
11821                                   "pname is not one of the accepted defined values.");
11822     }
11823 
11824     /* Check that INVALID_ENUM is generated by TextureParameter* if params
11825      should have a defined constant value (based on the value of pname) and
11826      does not. */
11827     {
11828         gl.textureParameterf(m_to_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, (glw::GLfloat)m_depth_stencil_mode_invalid);
11829 
11830         is_ok &=
11831             CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterf",
11832                              "params should have a defined constant value (based on the value of pname) and does not.");
11833     }
11834     /* Check that INVALID_ENUM is generated if TextureParameter{if} is called
11835      for a non-scalar parameter (pname TEXTURE_BORDER_COLOR or
11836      TEXTURE_SWIZZLE_RGBA). */
11837     {
11838         gl.textureParameterf(m_to_2D, GL_TEXTURE_BORDER_COLOR, 1.f);
11839 
11840         is_ok &=
11841             CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterf",
11842                              "called for a non-scalar parameter (pname TEXTURE_BORDER_COLOR or TEXTURE_SWIZZLE_RGBA).");
11843     }
11844 
11845     /* Check that INVALID_ENUM is generated by TextureParameter* if the
11846      effective target is either TEXTURE_2D_MULTISAMPLE or
11847      TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states. */
11848     {
11849         gl.textureParameterf(m_to_2D_ms, GL_TEXTURE_LOD_BIAS, 1.f);
11850 
11851         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterf",
11852                                   "the  effective target is either TEXTURE_2D_MULTISAMPLE or  "
11853                                   "TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states.");
11854     }
11855 
11856     /* Check that INVALID_ENUM is generated by TextureParameter* if the
11857      effective target is TEXTURE_RECTANGLE and either of pnames
11858      TEXTURE_WRAP_S or TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE,
11859      MIRRORED_REPEAT or REPEAT. */
11860     {
11861         gl.textureParameterf(m_to_rectangle, GL_TEXTURE_WRAP_S, GL_MIRROR_CLAMP_TO_EDGE);
11862 
11863         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterf",
11864                                   "the effective target is TEXTURE_RECTANGLE and either of pnames TEXTURE_WRAP_S or "
11865                                   "TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE, MIRRORED_REPEAT or REPEAT.");
11866     }
11867 
11868     /* Check that INVALID_ENUM is generated by TextureParameter* if the
11869      effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is
11870      set to a value other than NEAREST or LINEAR (no mipmap filtering is
11871      permitted). */
11872     {
11873         gl.textureParameterf(m_to_rectangle, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
11874 
11875         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterf",
11876                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is set to a "
11877                                   "value other than NEAREST or LINEAR (no mipmap filtering is permitted).");
11878     }
11879 
11880     /* Check that INVALID_OPERATION is generated by TextureParameter* if the
11881      effective target is either TEXTURE_2D_MULTISAMPLE or
11882      TEXTURE_2D_MULTISAMPLE_ARRAY, and pname TEXTURE_BASE_LEVEL is set to a
11883      value other than zero. */
11884     {
11885         gl.textureParameterf(m_to_2D_ms, GL_TEXTURE_BASE_LEVEL, 1.f);
11886 
11887         is_ok &=
11888             CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterf",
11889                              "the effective target is either TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY, "
11890                              "and pname TEXTURE_BASE_LEVEL is set to a value other than zero.");
11891     }
11892 
11893     /* Check that INVALID_OPERATION is generated by TextureParameter* if
11894      texture is not the name of an existing texture object. */
11895     {
11896         gl.textureParameterf(m_to_invalid, GL_TEXTURE_LOD_BIAS, 1.f);
11897 
11898         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterf",
11899                                   "texture is not the name of an existing texture object.");
11900     }
11901 
11902     /* Check that INVALID_OPERATION is generated by TextureParameter* if the
11903      effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is
11904      set to any value other than zero. */
11905     {
11906         gl.textureParameterf(m_to_rectangle, GL_TEXTURE_BASE_LEVEL, 1.f);
11907 
11908         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterf",
11909                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is set to "
11910                                   "any value other than zero. ");
11911     }
11912 
11913     /* Check that INVALID_VALUE is generated by TextureParameter* if pname is
11914      TEXTURE_BASE_LEVEL or TEXTURE_MAX_LEVEL, and param or params is
11915      negative. */
11916     {
11917         gl.textureParameterf(m_to_2D, GL_TEXTURE_BASE_LEVEL, -1.f);
11918 
11919         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameterf",
11920                                   "pname is TEXTURE_BASE_LEVEL and param is negative.");
11921 
11922         gl.textureParameterf(m_to_2D, GL_TEXTURE_MAX_LEVEL, -1.f);
11923 
11924         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameterf",
11925                                   "pname is TEXTURE_MAX_LEVEL and param is negative.");
11926     }
11927 
11928     return is_ok;
11929 }
11930 
11931 /** @brief Test (negative) of TextureParameteri
11932  *
11933  *  @return Test result.
11934  */
Testi()11935 bool ParameterSetupErrorsTest::Testi()
11936 {
11937     /* Shortcut for GL functionality. */
11938     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
11939 
11940     /* Result. */
11941     bool is_ok = true;
11942 
11943     /* Check that INVALID_ENUM is generated by TextureParameter* if pname is
11944      not one of the accepted defined values. */
11945     {
11946         gl.textureParameteri(m_to_2D, m_pname_invalid, 1);
11947 
11948         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteri",
11949                                   "pname is not one of the accepted defined values.");
11950     }
11951 
11952     /* Check that INVALID_ENUM is generated by TextureParameter* if params
11953      should have a defined constant value (based on the value of pname) and
11954      does not. */
11955     {
11956         gl.textureParameteri(m_to_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, m_depth_stencil_mode_invalid);
11957 
11958         is_ok &=
11959             CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteri",
11960                              "params should have a defined constant value (based on the value of pname) and does not.");
11961     }
11962     /* Check that INVALID_ENUM is generated if TextureParameter{if} is called
11963      for a non-scalar parameter (pname TEXTURE_BORDER_COLOR or
11964      TEXTURE_SWIZZLE_RGBA). */
11965     {
11966         gl.textureParameteri(m_to_2D, GL_TEXTURE_BORDER_COLOR, 1);
11967 
11968         is_ok &=
11969             CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteri",
11970                              "called for a non-scalar parameter (pname TEXTURE_BORDER_COLOR or TEXTURE_SWIZZLE_RGBA).");
11971     }
11972 
11973     /* Check that INVALID_ENUM is generated by TextureParameter* if the
11974      effective target is either TEXTURE_2D_MULTISAMPLE or
11975      TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states. */
11976     {
11977         gl.textureParameteri(m_to_2D_ms, GL_TEXTURE_LOD_BIAS, 1);
11978 
11979         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteri",
11980                                   "the  effective target is either TEXTURE_2D_MULTISAMPLE or  "
11981                                   "TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states.");
11982     }
11983 
11984     /* Check that INVALID_ENUM is generated by TextureParameter* if the
11985      effective target is TEXTURE_RECTANGLE and either of pnames
11986      TEXTURE_WRAP_S or TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE,
11987      MIRRORED_REPEAT or REPEAT. */
11988     {
11989         gl.textureParameteri(m_to_rectangle, GL_TEXTURE_WRAP_S, GL_MIRROR_CLAMP_TO_EDGE);
11990 
11991         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteri",
11992                                   "the effective target is TEXTURE_RECTANGLE and either of pnames TEXTURE_WRAP_S or "
11993                                   "TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE, MIRRORED_REPEAT or REPEAT.");
11994     }
11995 
11996     /* Check that INVALID_ENUM is generated by TextureParameter* if the
11997      effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is
11998      set to a value other than NEAREST or LINEAR (no mipmap filtering is
11999      permitted). */
12000     {
12001         gl.textureParameteri(m_to_rectangle, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
12002 
12003         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteri",
12004                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is set to a "
12005                                   "value other than NEAREST or LINEAR (no mipmap filtering is permitted).");
12006     }
12007 
12008     /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12009      effective target is either TEXTURE_2D_MULTISAMPLE or
12010      TEXTURE_2D_MULTISAMPLE_ARRAY, and pname TEXTURE_BASE_LEVEL is set to a
12011      value other than zero. */
12012     {
12013         gl.textureParameteri(m_to_2D_ms, GL_TEXTURE_BASE_LEVEL, 1);
12014 
12015         is_ok &=
12016             CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteri",
12017                              "the effective target is either TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY, "
12018                              "and pname TEXTURE_BASE_LEVEL is set to a value other than zero.");
12019     }
12020 
12021     /* Check that INVALID_OPERATION is generated by TextureParameter* if
12022      texture is not the name of an existing texture object. */
12023     {
12024         gl.textureParameteri(m_to_invalid, GL_TEXTURE_LOD_BIAS, 1);
12025 
12026         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteri",
12027                                   "texture is not the name of an existing texture object.");
12028     }
12029 
12030     /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12031      effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is
12032      set to any value other than zero. */
12033     {
12034         gl.textureParameteri(m_to_rectangle, GL_TEXTURE_BASE_LEVEL, 1);
12035 
12036         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteri",
12037                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is set to "
12038                                   "any value other than zero. ");
12039     }
12040 
12041     /* Check that INVALID_VALUE is generated by TextureParameter* if pname is
12042      TEXTURE_BASE_LEVEL or TEXTURE_MAX_LEVEL, and param or params is
12043      negative. */
12044     {
12045         gl.textureParameteri(m_to_2D, GL_TEXTURE_BASE_LEVEL, -1);
12046 
12047         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameteri",
12048                                   "pname is TEXTURE_BASE_LEVEL and param is negative.");
12049 
12050         gl.textureParameteri(m_to_2D, GL_TEXTURE_MAX_LEVEL, -1);
12051 
12052         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameteri",
12053                                   "pname is TEXTURE_MAX_LEVEL and param is negative.");
12054     }
12055 
12056     return is_ok;
12057 }
12058 
12059 /** @brief Test (negative) of TextureParameterfv
12060  *
12061  *  @return Test result.
12062  */
Testfv()12063 bool ParameterSetupErrorsTest::Testfv()
12064 {
12065     /* Shortcut for GL functionality. */
12066     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
12067 
12068     /* Result. */
12069     bool is_ok = true;
12070 
12071     glw::GLfloat one                        = 1.f;
12072     glw::GLfloat minus_one                  = -1.f;
12073     glw::GLfloat depth_stencil_mode_invalid = (glw::GLfloat)m_depth_stencil_mode_invalid;
12074     glw::GLfloat wrap_invalid               = (glw::GLfloat)GL_MIRROR_CLAMP_TO_EDGE;
12075     glw::GLfloat min_filter_invalid         = (glw::GLfloat)GL_NEAREST_MIPMAP_NEAREST;
12076 
12077     /* Check that INVALID_ENUM is generated by TextureParameter* if pname is
12078      not one of the accepted defined values. */
12079     {
12080         gl.textureParameterfv(m_to_2D, m_pname_invalid, &one);
12081 
12082         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterfv",
12083                                   "pname is not one of the accepted defined values.");
12084     }
12085 
12086     /* Check that INVALID_ENUM is generated by TextureParameter* if params
12087      should have a defined constant value (based on the value of pname) and
12088      does not. */
12089     {
12090         gl.textureParameterfv(m_to_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, &depth_stencil_mode_invalid);
12091 
12092         is_ok &=
12093             CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterfv",
12094                              "params should have a defined constant value (based on the value of pname) and does not.");
12095     }
12096 
12097     /* Check that INVALID_ENUM is generated by TextureParameter* if the
12098      effective target is either TEXTURE_2D_MULTISAMPLE or
12099      TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states. */
12100     {
12101         gl.textureParameterfv(m_to_2D_ms, GL_TEXTURE_LOD_BIAS, &one);
12102 
12103         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterfv",
12104                                   "the  effective target is either TEXTURE_2D_MULTISAMPLE or  "
12105                                   "TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states.");
12106     }
12107 
12108     /* Check that INVALID_ENUM is generated by TextureParameter* if the
12109      effective target is TEXTURE_RECTANGLE and either of pnames
12110      TEXTURE_WRAP_S or TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE,
12111      MIRRORED_REPEAT or REPEAT. */
12112     {
12113         gl.textureParameterfv(m_to_rectangle, GL_TEXTURE_WRAP_S, &wrap_invalid);
12114 
12115         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterfv",
12116                                   "the effective target is TEXTURE_RECTANGLE and either of pnames TEXTURE_WRAP_S or "
12117                                   "TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE, MIRRORED_REPEAT or REPEAT.");
12118     }
12119 
12120     /* Check that INVALID_ENUM is generated by TextureParameter* if the
12121      effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is
12122      set to a value other than NEAREST or LINEAR (no mipmap filtering is
12123      permitted). */
12124     {
12125         gl.textureParameterfv(m_to_rectangle, GL_TEXTURE_MIN_FILTER, &min_filter_invalid);
12126 
12127         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterfv",
12128                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is set to a "
12129                                   "value other than NEAREST or LINEAR (no mipmap filtering is permitted).");
12130     }
12131 
12132     /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12133      effective target is either TEXTURE_2D_MULTISAMPLE or
12134      TEXTURE_2D_MULTISAMPLE_ARRAY, and pname TEXTURE_BASE_LEVEL is set to a
12135      value other than zero. */
12136     {
12137         gl.textureParameterfv(m_to_2D_ms, GL_TEXTURE_BASE_LEVEL, &one);
12138 
12139         is_ok &=
12140             CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterfv",
12141                              "the effective target is either TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY, "
12142                              "and pname TEXTURE_BASE_LEVEL is set to a value other than zero.");
12143     }
12144 
12145     /* Check that INVALID_OPERATION is generated by TextureParameter* if
12146      texture is not the name of an existing texture object. */
12147     {
12148         gl.textureParameterfv(m_to_invalid, GL_TEXTURE_LOD_BIAS, &one);
12149 
12150         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterfv",
12151                                   "texture is not the name of an existing texture object.");
12152     }
12153 
12154     /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12155      effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is
12156      set to any value other than zero. */
12157     {
12158         gl.textureParameterfv(m_to_rectangle, GL_TEXTURE_BASE_LEVEL, &one);
12159 
12160         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterfv",
12161                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is set to "
12162                                   "any value other than zero. ");
12163     }
12164 
12165     /* Check that INVALID_VALUE is generated by TextureParameter* if pname is
12166      TEXTURE_BASE_LEVEL or TEXTURE_MAX_LEVEL, and param or params is
12167      negative. */
12168     {
12169         gl.textureParameterfv(m_to_2D, GL_TEXTURE_BASE_LEVEL, &minus_one);
12170 
12171         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameterfv",
12172                                   "pname is TEXTURE_BASE_LEVEL and param is negative.");
12173 
12174         gl.textureParameterfv(m_to_2D, GL_TEXTURE_MAX_LEVEL, &minus_one);
12175 
12176         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameterfv",
12177                                   "pname is TEXTURE_MAX_LEVEL and param is negative.");
12178     }
12179 
12180     return is_ok;
12181 }
12182 
12183 /** @brief Test (negative) of TextureParameteriv
12184  *
12185  *  @return Test result.
12186  */
Testiv()12187 bool ParameterSetupErrorsTest::Testiv()
12188 {
12189     /* Shortcut for GL functionality. */
12190     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
12191 
12192     /* Result. */
12193     bool is_ok = true;
12194 
12195     glw::GLint one                        = 1;
12196     glw::GLint minus_one                  = -1;
12197     glw::GLint depth_stencil_mode_invalid = (glw::GLint)m_depth_stencil_mode_invalid;
12198     glw::GLint wrap_invalid               = (glw::GLint)GL_MIRROR_CLAMP_TO_EDGE;
12199     glw::GLint min_filter_invalid         = (glw::GLint)GL_NEAREST_MIPMAP_NEAREST;
12200 
12201     /* Check that INVALID_ENUM is generated by TextureParameter* if pname is
12202      not one of the accepted defined values. */
12203     {
12204         gl.textureParameteriv(m_to_2D, m_pname_invalid, &one);
12205 
12206         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteriv",
12207                                   "pname is not one of the accepted defined values.");
12208     }
12209 
12210     /* Check that INVALID_ENUM is generated by TextureParameter* if params
12211      should have a defined constant value (based on the value of pname) and
12212      does not. */
12213     {
12214         gl.textureParameteriv(m_to_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, &depth_stencil_mode_invalid);
12215 
12216         is_ok &=
12217             CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteriv",
12218                              "params should have a defined constant value (based on the value of pname) and does not.");
12219     }
12220 
12221     /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12222      effective target is either TEXTURE_2D_MULTISAMPLE or
12223      TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states. */
12224     {
12225         gl.textureParameteriv(m_to_2D_ms, GL_TEXTURE_LOD_BIAS, &one);
12226 
12227         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteriv",
12228                                   "the  effective target is either TEXTURE_2D_MULTISAMPLE or  "
12229                                   "TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states.");
12230     }
12231 
12232     /* Check that INVALID_ENUM is generated by TextureParameter* if the
12233      effective target is TEXTURE_RECTANGLE and either of pnames
12234      TEXTURE_WRAP_S or TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE,
12235      MIRRORED_REPEAT or REPEAT. */
12236     {
12237         gl.textureParameteriv(m_to_rectangle, GL_TEXTURE_WRAP_S, &wrap_invalid);
12238 
12239         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteriv",
12240                                   "the effective target is TEXTURE_RECTANGLE and either of pnames TEXTURE_WRAP_S or "
12241                                   "TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE, MIRRORED_REPEAT or REPEAT.");
12242     }
12243 
12244     /* Check that INVALID_ENUM is generated by TextureParameter* if the
12245      effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is
12246      set to a value other than NEAREST or LINEAR (no mipmap filtering is
12247      permitted). */
12248     {
12249         gl.textureParameteriv(m_to_rectangle, GL_TEXTURE_MIN_FILTER, &min_filter_invalid);
12250 
12251         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameteriv",
12252                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is set to a "
12253                                   "value other than NEAREST or LINEAR (no mipmap filtering is permitted).");
12254     }
12255 
12256     /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12257      effective target is either TEXTURE_2D_MULTISAMPLE or
12258      TEXTURE_2D_MULTISAMPLE_ARRAY, and pname TEXTURE_BASE_LEVEL is set to a
12259      value other than zero. */
12260     {
12261         gl.textureParameteriv(m_to_2D_ms, GL_TEXTURE_BASE_LEVEL, &one);
12262 
12263         is_ok &=
12264             CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteriv",
12265                              "the effective target is either TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY, "
12266                              "and pname TEXTURE_BASE_LEVEL is set to a value other than zero.");
12267     }
12268 
12269     /* Check that INVALID_OPERATION is generated by TextureParameter* if
12270      texture is not the name of an existing texture object. */
12271     {
12272         gl.textureParameteriv(m_to_invalid, GL_TEXTURE_LOD_BIAS, &one);
12273 
12274         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteriv",
12275                                   "texture is not the name of an existing texture object.");
12276     }
12277 
12278     /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12279      effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is
12280      set to any value other than zero. */
12281     {
12282         gl.textureParameteriv(m_to_rectangle, GL_TEXTURE_BASE_LEVEL, &one);
12283 
12284         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameteriv",
12285                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is set to "
12286                                   "any value other than zero. ");
12287     }
12288 
12289     /* Check that INVALID_VALUE is generated by TextureParameter* if pname is
12290      TEXTURE_BASE_LEVEL or TEXTURE_MAX_LEVEL, and param or params is
12291      negative. */
12292     {
12293         gl.textureParameteriv(m_to_2D, GL_TEXTURE_BASE_LEVEL, &minus_one);
12294 
12295         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameteriv",
12296                                   "pname is TEXTURE_BASE_LEVEL and param is negative.");
12297 
12298         gl.textureParameteriv(m_to_2D, GL_TEXTURE_MAX_LEVEL, &minus_one);
12299 
12300         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameteriv",
12301                                   "pname is TEXTURE_MAX_LEVEL and param is negative.");
12302     }
12303 
12304     return is_ok;
12305 }
12306 
12307 /** @brief Test (negative) of TextureParameterIiv
12308  *
12309  *  @return Test result.
12310  */
TestIiv()12311 bool ParameterSetupErrorsTest::TestIiv()
12312 {
12313     /* Shortcut for GL functionality. */
12314     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
12315 
12316     /* Result. */
12317     bool is_ok = true;
12318 
12319     glw::GLint one                        = 1;
12320     glw::GLint minus_one                  = -1;
12321     glw::GLint depth_stencil_mode_invalid = (glw::GLint)m_depth_stencil_mode_invalid;
12322     glw::GLint wrap_invalid               = (glw::GLint)GL_MIRROR_CLAMP_TO_EDGE;
12323     glw::GLint min_filter_invalid         = (glw::GLint)GL_NEAREST_MIPMAP_NEAREST;
12324 
12325     /* Check that INVALID_ENUM is generated by TextureParameter* if pname is
12326      not one of the accepted defined values. */
12327     {
12328         gl.textureParameterIiv(m_to_2D, m_pname_invalid, &one);
12329 
12330         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIiv",
12331                                   "pname is not one of the accepted defined values.");
12332     }
12333 
12334     /* Check that INVALID_ENUM is generated by TextureParameter* if params
12335      should have a defined constant value (based on the value of pname) and
12336      does not. */
12337     {
12338         gl.textureParameterIiv(m_to_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, &depth_stencil_mode_invalid);
12339 
12340         is_ok &=
12341             CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIiv",
12342                              "params should have a defined constant value (based on the value of pname) and does not.");
12343     }
12344 
12345     /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12346      effective target is either TEXTURE_2D_MULTISAMPLE or
12347      TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states. */
12348     {
12349         gl.textureParameterIiv(m_to_2D_ms, GL_TEXTURE_LOD_BIAS, &one);
12350 
12351         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIiv",
12352                                   "the  effective target is either TEXTURE_2D_MULTISAMPLE or  "
12353                                   "TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states.");
12354     }
12355 
12356     /* Check that INVALID_ENUM is generated by TextureParameter* if the
12357      effective target is TEXTURE_RECTANGLE and either of pnames
12358      TEXTURE_WRAP_S or TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE,
12359      MIRRORED_REPEAT or REPEAT. */
12360     {
12361         gl.textureParameterIiv(m_to_rectangle, GL_TEXTURE_WRAP_S, &wrap_invalid);
12362 
12363         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIiv",
12364                                   "the effective target is TEXTURE_RECTANGLE and either of pnames TEXTURE_WRAP_S or "
12365                                   "TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE, MIRRORED_REPEAT or REPEAT.");
12366     }
12367 
12368     /* Check that INVALID_ENUM is generated by TextureParameter* if the
12369      effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is
12370      set to a value other than NEAREST or LINEAR (no mipmap filtering is
12371      permitted). */
12372     {
12373         gl.textureParameterIiv(m_to_rectangle, GL_TEXTURE_MIN_FILTER, &min_filter_invalid);
12374 
12375         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIiv",
12376                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is set to a "
12377                                   "value other than NEAREST or LINEAR (no mipmap filtering is permitted).");
12378     }
12379 
12380     /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12381      effective target is either TEXTURE_2D_MULTISAMPLE or
12382      TEXTURE_2D_MULTISAMPLE_ARRAY, and pname TEXTURE_BASE_LEVEL is set to a
12383      value other than zero. */
12384     {
12385         gl.textureParameterIiv(m_to_2D_ms, GL_TEXTURE_BASE_LEVEL, &one);
12386 
12387         is_ok &=
12388             CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIiv",
12389                              "the effective target is either TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY, "
12390                              "and pname TEXTURE_BASE_LEVEL is set to a value other than zero.");
12391     }
12392 
12393     /* Check that INVALID_OPERATION is generated by TextureParameter* if
12394      texture is not the name of an existing texture object. */
12395     {
12396         gl.textureParameterIiv(m_to_invalid, GL_TEXTURE_LOD_BIAS, &one);
12397 
12398         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIiv",
12399                                   "texture is not the name of an existing texture object.");
12400     }
12401 
12402     /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12403      effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is
12404      set to any value other than zero. */
12405     {
12406         gl.textureParameterIiv(m_to_rectangle, GL_TEXTURE_BASE_LEVEL, &one);
12407 
12408         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIiv",
12409                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is set to "
12410                                   "any value other than zero. ");
12411     }
12412 
12413     /* Check that INVALID_VALUE is generated by TextureParameter* if pname is
12414      TEXTURE_BASE_LEVEL or TEXTURE_MAX_LEVEL, and param or params is
12415      negative. */
12416     {
12417         gl.textureParameterIiv(m_to_2D, GL_TEXTURE_BASE_LEVEL, &minus_one);
12418 
12419         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameterIiv",
12420                                   "pname is TEXTURE_BASE_LEVEL and param is negative.");
12421 
12422         gl.textureParameterIiv(m_to_2D, GL_TEXTURE_MAX_LEVEL, &minus_one);
12423 
12424         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureParameterIiv",
12425                                   "pname is TEXTURE_MAX_LEVEL and param is negative.");
12426     }
12427 
12428     return is_ok;
12429 }
12430 
12431 /** @brief Test (negative) of TextureParameterIuiv
12432  *
12433  *  @return Test result.
12434  */
TestIuiv()12435 bool ParameterSetupErrorsTest::TestIuiv()
12436 {
12437     /* Shortcut for GL functionality. */
12438     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
12439 
12440     /* Result. */
12441     bool is_ok = true;
12442 
12443     glw::GLuint one                        = 1;
12444     glw::GLuint depth_stencil_mode_invalid = (glw::GLint)m_depth_stencil_mode_invalid;
12445     glw::GLuint wrap_invalid               = (glw::GLint)GL_MIRROR_CLAMP_TO_EDGE;
12446     glw::GLuint min_filter_invalid         = (glw::GLint)GL_NEAREST_MIPMAP_NEAREST;
12447 
12448     /* Check that INVALID_ENUM is generated by TextureParameter* if pname is
12449      not one of the accepted defined values. */
12450     {
12451         gl.textureParameterIuiv(m_to_2D, m_pname_invalid, &one);
12452 
12453         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIuiv",
12454                                   "pname is not one of the accepted defined values.");
12455     }
12456 
12457     /* Check that INVALID_ENUM is generated by TextureParameter* if params
12458      should have a defined constant value (based on the value of pname) and
12459      does not. */
12460     {
12461         gl.textureParameterIuiv(m_to_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, &depth_stencil_mode_invalid);
12462 
12463         is_ok &=
12464             CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIuiv",
12465                              "params should have a defined constant value (based on the value of pname) and does not.");
12466     }
12467 
12468     /* Check that INVALID_ENUM is generated by TextureParameter* if the
12469      effective target is either TEXTURE_2D_MULTISAMPLE or
12470      TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states. */
12471     {
12472         gl.textureParameterIuiv(m_to_2D_ms, GL_TEXTURE_LOD_BIAS, &one);
12473 
12474         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIuiv",
12475                                   "the  effective target is either TEXTURE_2D_MULTISAMPLE or  "
12476                                   "TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is any of the sampler states.");
12477     }
12478 
12479     /* Check that INVALID_ENUM is generated by TextureParameter* if the
12480      effective target is TEXTURE_RECTANGLE and either of pnames
12481      TEXTURE_WRAP_S or TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE,
12482      MIRRORED_REPEAT or REPEAT. */
12483     {
12484         gl.textureParameterIuiv(m_to_rectangle, GL_TEXTURE_WRAP_S, &wrap_invalid);
12485 
12486         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIuiv",
12487                                   "the effective target is TEXTURE_RECTANGLE and either of pnames TEXTURE_WRAP_S or "
12488                                   "TEXTURE_WRAP_T is set to either MIRROR_CLAMP_TO_EDGE, MIRRORED_REPEAT or REPEAT.");
12489     }
12490 
12491     /* Check that INVALID_ENUM is generated by TextureParameter* if the
12492      effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is
12493      set to a value other than NEAREST or LINEAR (no mipmap filtering is
12494      permitted). */
12495     {
12496         gl.textureParameterIuiv(m_to_rectangle, GL_TEXTURE_MIN_FILTER, &min_filter_invalid);
12497 
12498         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureParameterIuiv",
12499                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_MIN_FILTER is set to a "
12500                                   "value other than NEAREST or LINEAR (no mipmap filtering is permitted).");
12501     }
12502 
12503     /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12504      effective target is either TEXTURE_2D_MULTISAMPLE or
12505      TEXTURE_2D_MULTISAMPLE_ARRAY, and pname TEXTURE_BASE_LEVEL is set to a
12506      value other than zero. */
12507     {
12508         gl.textureParameterIuiv(m_to_2D_ms, GL_TEXTURE_BASE_LEVEL, &one);
12509 
12510         is_ok &=
12511             CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIuiv",
12512                              "the effective target is either TEXTURE_2D_MULTISAMPLE or TEXTURE_2D_MULTISAMPLE_ARRAY, "
12513                              "and pname TEXTURE_BASE_LEVEL is set to a value other than zero.");
12514     }
12515 
12516     /* Check that INVALID_OPERATION is generated by TextureParameter* if
12517      texture is not the name of an existing texture object. */
12518     {
12519         gl.textureParameterIuiv(m_to_invalid, GL_TEXTURE_LOD_BIAS, &one);
12520 
12521         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIuiv",
12522                                   "texture is not the name of an existing texture object.");
12523     }
12524 
12525     /* Check that INVALID_OPERATION is generated by TextureParameter* if the
12526      effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is
12527      set to any value other than zero. */
12528     {
12529         gl.textureParameterIuiv(m_to_rectangle, GL_TEXTURE_BASE_LEVEL, &one);
12530 
12531         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureParameterIuiv",
12532                                   "the effective target is TEXTURE_RECTANGLE and pname TEXTURE_BASE_LEVEL is set to "
12533                                   "any value other than zero. ");
12534     }
12535 
12536     return is_ok;
12537 }
12538 
12539 /** @brief Clean GL objects, test variables and GL errors.
12540  */
Clean()12541 void ParameterSetupErrorsTest::Clean()
12542 {
12543     /* Shortcut for GL functionality. */
12544     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
12545 
12546     /* Cleanup. */
12547     if (m_to_2D)
12548     {
12549         gl.deleteTextures(1, &m_to_2D);
12550 
12551         m_to_2D = 0;
12552     }
12553 
12554     if (m_to_2D_ms)
12555     {
12556         gl.deleteTextures(1, &m_to_2D_ms);
12557 
12558         m_to_2D_ms = 0;
12559     }
12560 
12561     if (m_to_rectangle)
12562     {
12563         gl.deleteTextures(1, &m_to_rectangle);
12564 
12565         m_to_rectangle = 0;
12566     }
12567 
12568     if (m_to_invalid)
12569     {
12570         gl.deleteTextures(1, &m_to_invalid);
12571 
12572         m_to_invalid = 0;
12573     }
12574 
12575     m_to_invalid    = 0;
12576     m_pname_invalid = 0;
12577 
12578     while (GL_NO_ERROR != gl.getError())
12579         ;
12580 }
12581 
12582 /******************************** Generate Mipmap Errors Test Implementation   ********************************/
12583 
12584 /** @brief Generate Mipmap Errors Test constructor.
12585  *
12586  *  @param [in] context     OpenGL context.
12587  */
GenerateMipmapErrorsTest(deqp::Context & context)12588 GenerateMipmapErrorsTest::GenerateMipmapErrorsTest(deqp::Context &context)
12589     : deqp::TestCase(context, "textures_generate_mipmap_errors", "Texture Generate Mipmap Errors Test")
12590 {
12591     /* Intentionally left blank. */
12592 }
12593 
12594 /** @brief Iterate Generate Mipmap Errors Test cases.
12595  *
12596  *  @return Iteration result.
12597  */
iterate()12598 tcu::TestNode::IterateResult GenerateMipmapErrorsTest::iterate()
12599 {
12600     /* Shortcut for GL functionality. */
12601     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
12602 
12603     /* Get context setup. */
12604     bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
12605     bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
12606 
12607     if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
12608     {
12609         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
12610 
12611         return STOP;
12612     }
12613 
12614     /* Running tests. */
12615     bool is_ok    = true;
12616     bool is_error = false;
12617 
12618     /* Objects. */
12619     glw::GLuint texture_invalid = 0;
12620     glw::GLuint texture_cube    = 0;
12621 
12622     try
12623     {
12624         /* Preparations. */
12625 
12626         /* incomplete cube map */
12627         gl.genTextures(1, &texture_cube);
12628         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12629 
12630         gl.bindTexture(GL_TEXTURE_CUBE_MAP, texture_cube);
12631         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12632 
12633         gl.texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, s_reference_internalformat, s_reference_width,
12634                       s_reference_height, 0, s_reference_format, s_reference_type, s_reference_data);
12635         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12636 
12637         /* invalid texture */
12638         while (gl.isTexture(++texture_invalid))
12639             ;
12640 
12641         /* Check that INVALID_OPERATION is generated by GenerateTextureMipmap if
12642          texture is not the name of an existing texture object. */
12643         gl.generateTextureMipmap(texture_invalid);
12644         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGenerateTextureMipmap",
12645                                   "texture is not the name of an existing texture object.");
12646 
12647         /* Check that INVALID_OPERATION is generated by GenerateTextureMipmap if
12648          target is TEXTURE_CUBE_MAP or TEXTURE_CUBE_MAP_ARRAY, and the specified
12649          texture object is not cube complete or cube array complete,
12650          respectively. */
12651         gl.generateTextureMipmap(texture_cube);
12652         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGenerateTextureMipmap",
12653                                   "target is TEXTURE_CUBE_MAP or TEXTURE_CUBE_MAP_ARRAY, and the specified texture "
12654                                   "object is not cube complete or cube array complete, respectively.");
12655     }
12656     catch (...)
12657     {
12658         is_ok    = false;
12659         is_error = true;
12660     }
12661 
12662     /* Cleanup. */
12663     if (texture_cube)
12664     {
12665         gl.deleteTextures(1, &texture_cube);
12666     }
12667 
12668     while (GL_NO_ERROR != gl.getError())
12669         ;
12670 
12671     /* Result's setup. */
12672     if (is_ok)
12673     {
12674         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
12675     }
12676     else
12677     {
12678         if (is_error)
12679         {
12680             m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
12681         }
12682         else
12683         {
12684             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
12685         }
12686     }
12687 
12688     return STOP;
12689 }
12690 
12691 /** Reference data. */
12692 const glw::GLubyte GenerateMipmapErrorsTest::s_reference_data[] = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
12693                                                                    0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF};
12694 
12695 /** Reference data parameters. */
12696 const glw::GLuint GenerateMipmapErrorsTest::s_reference_width          = 4;
12697 const glw::GLuint GenerateMipmapErrorsTest::s_reference_height         = 4;
12698 const glw::GLenum GenerateMipmapErrorsTest::s_reference_internalformat = GL_R8;
12699 const glw::GLenum GenerateMipmapErrorsTest::s_reference_format         = GL_RED;
12700 const glw::GLenum GenerateMipmapErrorsTest::s_reference_type           = GL_UNSIGNED_BYTE;
12701 
12702 /******************************** Bind Unit Errors Test Implementation   ********************************/
12703 
12704 /** @brief Bind Unit Errors Test constructor.
12705  *
12706  *  @param [in] context     OpenGL context.
12707  */
BindUnitErrorsTest(deqp::Context & context)12708 BindUnitErrorsTest::BindUnitErrorsTest(deqp::Context &context)
12709     : deqp::TestCase(context, "textures_bind_unit_errors", "Texture Bind Unit Errors Test")
12710 {
12711     /* Intentionally left blank. */
12712 }
12713 
12714 /** @brief IterateBind Unit Errors Test cases.
12715  *
12716  *  @return Iteration result.
12717  */
iterate()12718 tcu::TestNode::IterateResult BindUnitErrorsTest::iterate()
12719 {
12720     /* Shortcut for GL functionality. */
12721     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
12722 
12723     /* Get context setup. */
12724     bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
12725     bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
12726 
12727     if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
12728     {
12729         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
12730 
12731         return STOP;
12732     }
12733 
12734     /* Running tests. */
12735     bool is_ok    = true;
12736     bool is_error = false;
12737 
12738     /* Objects. */
12739     glw::GLuint texture_invalid = 0;
12740 
12741     try
12742     {
12743         /* Prepare invalid texture */
12744         while (gl.isTexture(++texture_invalid))
12745             ;
12746 
12747         /* incomplete cube map */
12748 
12749         /* Check that INVALID_OPERATION error is generated if texture is not zero
12750          or the name of an existing texture object. */
12751         gl.bindTextureUnit(0, texture_invalid);
12752         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glBindTextureUnit",
12753                                   "texture is not zero or the name of an existing texture object.");
12754     }
12755     catch (...)
12756     {
12757         is_ok    = false;
12758         is_error = true;
12759     }
12760 
12761     /* Cleanup. */
12762     while (GL_NO_ERROR != gl.getError())
12763         ;
12764 
12765     /* Result's setup. */
12766     if (is_ok)
12767     {
12768         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
12769     }
12770     else
12771     {
12772         if (is_error)
12773         {
12774             m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
12775         }
12776         else
12777         {
12778             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
12779         }
12780     }
12781 
12782     return STOP;
12783 }
12784 
12785 /******************************** Image Query Errors Test Implementation   ********************************/
12786 
12787 /** @brief Image Query Errors Test constructor.
12788  *
12789  *  @param [in] context     OpenGL context.
12790  */
ImageQueryErrorsTest(deqp::Context & context)12791 ImageQueryErrorsTest::ImageQueryErrorsTest(deqp::Context &context)
12792     : deqp::TestCase(context, "textures_image_query_errors", "Texture Image Query Errors Test")
12793 {
12794     /* Intentionally left blank. */
12795 }
12796 
12797 /** Reference data. */
12798 const glw::GLuint ImageQueryErrorsTest::s_reference_data[] = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
12799                                                               0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF};
12800 
12801 /** Reference data parameters. */
12802 const glw::GLuint ImageQueryErrorsTest::s_reference_width                     = 4;
12803 const glw::GLuint ImageQueryErrorsTest::s_reference_height                    = 4;
12804 const glw::GLuint ImageQueryErrorsTest::s_reference_size                      = sizeof(s_reference_data);
12805 const glw::GLenum ImageQueryErrorsTest::s_reference_internalformat            = GL_R8;
12806 const glw::GLenum ImageQueryErrorsTest::s_reference_internalformat_int        = GL_R8I;
12807 const glw::GLenum ImageQueryErrorsTest::s_reference_internalformat_compressed = GL_COMPRESSED_RED_RGTC1;
12808 const glw::GLenum ImageQueryErrorsTest::s_reference_format                    = GL_RED;
12809 const glw::GLenum ImageQueryErrorsTest::s_reference_type                      = GL_UNSIGNED_INT;
12810 
12811 /** @brief Iterate Image Query Errors Test cases.
12812  *
12813  *  @return Iteration result.
12814  */
iterate()12815 tcu::TestNode::IterateResult ImageQueryErrorsTest::iterate()
12816 {
12817     /* Shortcut for GL functionality. */
12818     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
12819 
12820     /* Get context setup. */
12821     bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
12822     bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
12823 
12824     if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
12825     {
12826         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
12827 
12828         return STOP;
12829     }
12830 
12831     /* Running tests. */
12832     bool is_ok    = true;
12833     bool is_error = false;
12834 
12835     /* Objects. */
12836     glw::GLuint buffer                                 = 0;
12837     glw::GLuint texture_invalid                        = 0;
12838     glw::GLuint texture_2D                             = 0;
12839     glw::GLuint texture_2D_int                         = 0;
12840     glw::GLuint texture_2D_ms                          = 0;
12841     glw::GLuint texture_2D_stencil                     = 0;
12842     glw::GLuint texture_2D_compressed                  = 0;
12843     glw::GLuint texture_cube                           = 0;
12844     glw::GLuint texture_rectangle                      = 0;
12845     glw::GLint max_level                               = 0;
12846     char store[s_reference_size * 6 /* for cubemap */] = {};
12847 
12848     try
12849     {
12850         /* Preparations. */
12851 
12852         /* Buffer. */
12853         gl.createBuffers(1, &buffer);
12854 
12855         gl.namedBufferData(buffer, s_reference_size + 1, NULL, GL_STATIC_COPY);
12856         GLU_EXPECT_NO_ERROR(gl.getError(), "glNamedBufferData has failed");
12857 
12858         /* 2D texture */
12859         gl.genTextures(1, &texture_2D);
12860         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12861 
12862         gl.bindTexture(GL_TEXTURE_2D, texture_2D);
12863         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12864 
12865         gl.texImage2D(GL_TEXTURE_2D, 0, s_reference_internalformat, s_reference_width, s_reference_height, 0,
12866                       s_reference_format, s_reference_type, s_reference_data);
12867         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12868 
12869         /* 2D texture */
12870         gl.genTextures(1, &texture_2D);
12871         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12872 
12873         gl.bindTexture(GL_TEXTURE_2D, texture_2D);
12874         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12875 
12876         gl.texImage2D(GL_TEXTURE_2D, 0, s_reference_internalformat, s_reference_width, s_reference_height, 0,
12877                       s_reference_format, s_reference_type, s_reference_data);
12878         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12879 
12880         /* incomplete cube map */
12881         gl.genTextures(1, &texture_cube);
12882         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12883 
12884         gl.bindTexture(GL_TEXTURE_CUBE_MAP, texture_cube);
12885         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12886 
12887         gl.texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, s_reference_internalformat, s_reference_width,
12888                       s_reference_height, 0, s_reference_format, s_reference_type, s_reference_data);
12889         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12890 
12891         /* 2D multisample */
12892         gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &texture_2D_ms);
12893         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12894 
12895         gl.textureStorage2DMultisample(texture_2D_ms, 1, s_reference_internalformat, s_reference_width,
12896                                        s_reference_height, false);
12897         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2DMultisample has failed");
12898 
12899         /* 2D stencil */
12900         gl.createTextures(GL_TEXTURE_2D, 1, &texture_2D_stencil);
12901         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12902 
12903         gl.textureStorage2D(texture_2D_stencil, 1, GL_STENCIL_INDEX8, s_reference_width, s_reference_height);
12904         GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2DMultisample has failed");
12905 
12906         /* 2D compressed texture  */
12907         gl.genTextures(1, &texture_2D_compressed);
12908         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12909 
12910         gl.bindTexture(GL_TEXTURE_2D, texture_2D_compressed);
12911         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12912 
12913         gl.texImage2D(GL_TEXTURE_2D, 0, s_reference_internalformat_compressed, s_reference_width, s_reference_height, 0,
12914                       s_reference_format, s_reference_type, s_reference_data);
12915         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12916 
12917         gl.getIntegerv(GL_MAX_TEXTURE_SIZE, &max_level); /* assuming that x > log(x) */
12918         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
12919 
12920         /* Rectangle texture */
12921         gl.genTextures(1, &texture_rectangle);
12922         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
12923 
12924         gl.bindTexture(GL_TEXTURE_RECTANGLE, texture_rectangle);
12925         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
12926 
12927         gl.texImage2D(GL_TEXTURE_RECTANGLE, 0, s_reference_internalformat, s_reference_width, s_reference_height, 0,
12928                       s_reference_format, s_reference_type, s_reference_data);
12929         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
12930 
12931         /* invalid texture */
12932         while (gl.isTexture(++texture_invalid))
12933             ;
12934 
12935         /* Tests. */
12936 
12937         /* Check that INVALID_OPERATION is generated by GetTextureImage functions if
12938          resulting texture target is not an accepted value TEXTURE_1D,
12939          TEXTURE_2D, TEXTURE_3D, TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY,
12940          TEXTURE_CUBE_MAP_ARRAY, TEXTURE_RECTANGLE, and TEXTURE_CUBE_MAP. */
12941         gl.getTextureImage(texture_2D_ms, 0, s_reference_format, s_reference_type, s_reference_size, store);
12942         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12943                                   "resulting texture target is not an accepted value TEXTURE_1D, TEXTURE_2D, "
12944                                   "TEXTURE_3D, TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP_ARRAY, "
12945                                   "TEXTURE_RECTANGLE, and TEXTURE_CUBE_MAP.");
12946 
12947         /* Check that INVALID_OPERATION is generated by GetTextureImage
12948          if texture is not the name of an existing texture object. */
12949         gl.getTextureImage(texture_invalid, 0, s_reference_format, s_reference_type, s_reference_size, store);
12950         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12951                                   "texture is not the name of an existing texture object.");
12952 
12953         /* Check that INVALID_OPERATION error is generated by GetTextureImage if
12954          the effective target is TEXTURE_CUBE_MAP or TEXTURE_CUBE_MAP_ARRAY, and
12955          the texture object is not cube complete or cube array complete,
12956          respectively. */
12957         gl.getTextureImage(texture_cube, 0, s_reference_format, s_reference_type, s_reference_size * 6, store);
12958         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12959                                   "the effective target is TEXTURE_CUBE_MAP and the texture object is not cube "
12960                                   "complete or cube array complete, respectively.");
12961 
12962         /* Check that GL_INVALID_VALUE is generated if level is less than 0 or
12963          larger than the maximum allowable level. */
12964         gl.getTextureImage(texture_2D, -1, s_reference_format, s_reference_type, s_reference_size, store);
12965         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureImage", "level is less than 0.");
12966 
12967         gl.getTextureImage(texture_2D, max_level, s_reference_format, s_reference_type, s_reference_size, store);
12968         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureImage",
12969                                   "level is larger than the maximum allowable level.");
12970 
12971         /* Check that INVALID_VALUE error is generated if level is non-zero and the
12972          effective target is TEXTURE_RECTANGLE. */
12973         gl.getTextureImage(texture_rectangle, 1, s_reference_format, s_reference_type, s_reference_size, store);
12974         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureImage",
12975                                   "level is non-zero and the effective target is TEXTURE_RECTANGLE.");
12976 
12977         /* Check that INVALID_OPERATION error is generated if any of the following
12978          mismatches between format and the internal format of the texture image
12979          exist:
12980          -  format is a color format (one of the formats in table 8.3 whose
12981          target is the color buffer) and the base internal format of the
12982          texture image is not a color format.
12983          -  format is DEPTH_COMPONENT and the base internal format is  not
12984          DEPTH_COMPONENT or DEPTH_STENCIL
12985          -  format is DEPTH_STENCIL and the base internal format is not
12986          DEPTH_STENCIL
12987          -  format is STENCIL_INDEX and the base internal format is not
12988          STENCIL_INDEX or DEPTH_STENCIL
12989          -  format is one of the integer formats in table 8.3 and the internal
12990          format of the texture image is not integer, or format is not one of
12991          the integer formats in table 8.3 and the internal format is integer. */
12992         gl.getTextureImage(texture_2D_stencil, 0, s_reference_format /* red */, s_reference_type, s_reference_size,
12993                            store);
12994         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
12995                                   "format is a color format (one of the formats in table 8.3 whose target is the color "
12996                                   "buffer) and the base internal format of the texture image is not a color format.");
12997 
12998         gl.getTextureImage(texture_2D, 0, GL_DEPTH_COMPONENT, s_reference_type, s_reference_size, store);
12999         is_ok &= CheckErrorAndLog(
13000             m_context, GL_INVALID_OPERATION, "glGetTextureImage",
13001             "format is DEPTH_COMPONENT and the base internal format is not DEPTH_COMPONENT or DEPTH_STENCIL.");
13002 
13003         gl.getTextureImage(texture_2D, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, s_reference_size, store);
13004         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
13005                                   "format is DEPTH_STENCIL and the base internal format is not DEPTH_STENCIL.");
13006 
13007         gl.getTextureImage(texture_2D, 0, GL_STENCIL_INDEX, s_reference_type, s_reference_size, store);
13008         is_ok &= CheckErrorAndLog(
13009             m_context, GL_INVALID_OPERATION, "glGetTextureImage",
13010             "format is STENCIL_INDEX and the base internal format is not STENCIL_INDEX or DEPTH_STENCIL.");
13011 
13012         gl.getTextureImage(texture_2D, 0, GL_RED_INTEGER, s_reference_type, s_reference_size, store);
13013         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
13014                                   "format is one of the integer formats in table 8.3 and the internal format of the "
13015                                   "texture image is not integer.");
13016 
13017         gl.getTextureImage(texture_2D_int, 0, GL_RED, s_reference_type, s_reference_size, store);
13018         is_ok &= CheckErrorAndLog(
13019             m_context, GL_INVALID_OPERATION, "glGetTextureImage",
13020             "format is not one of the integer formats in table 8.3 and the internal format is integer.");
13021 
13022         /* Check that INVALID_OPERATION error is generated if a pixel pack buffer
13023          object is bound and packing the texture image into the buffer's memory
13024          would exceed the size of the buffer. */
13025         gl.bindBuffer(GL_PIXEL_PACK_BUFFER, buffer);
13026         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
13027 
13028         gl.getTextureImage(texture_2D, 0, s_reference_format, s_reference_type, s_reference_size,
13029                            glu::BufferOffsetAsPointer(1 * sizeof(GLuint)));
13030         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
13031                                   "a pixel pack buffer object is bound and packing the texture image into the buffer's "
13032                                   "memory would exceed the size of the buffer.");
13033 
13034         gl.bindBuffer(GL_PIXEL_PACK_BUFFER, 0);
13035         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
13036 
13037         /* Check that INVALID_OPERATION error is generated if a pixel pack buffer
13038          object is bound and pixels is not evenly divisible by the number of
13039          basic machine units needed to store in memory the GL data type
13040          corresponding to type (see table 8.2). */
13041         gl.bindBuffer(GL_PIXEL_PACK_BUFFER, buffer);
13042         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
13043 
13044         gl.getTextureImage(texture_2D, 0, s_reference_format, s_reference_type, s_reference_size,
13045                            glu::BufferOffsetAsPointer(1));
13046         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
13047                                   "a pixel pack buffer object is bound and pixels is not evenly divisible by the "
13048                                   "number of basic machine units needed to store in memory the GL data type "
13049                                   "corresponding to type (see table 8.2).");
13050 
13051         gl.bindBuffer(GL_PIXEL_PACK_BUFFER, 0);
13052         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
13053 
13054         /* Check that INVALID_OPERATION error is generated by GetTextureImage if
13055          the buffer size required to store the requested data is greater than
13056          bufSize. */
13057         gl.getTextureImage(texture_2D, 0, s_reference_format, s_reference_type,
13058                            s_reference_size - sizeof(s_reference_data[0]), store);
13059         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureImage",
13060                                   "the buffer size required to store the requested data is greater than bufSize.");
13061 
13062         /* Check that INVALID_OPERATION is generated by GetCompressedTextureImage
13063          if texture is not the name of an existing texture object. */
13064         gl.getCompressedTextureImage(texture_invalid, 0, s_reference_size, store);
13065         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetCompressedTextureImage",
13066                                   "texture is not the name of an existing texture object.");
13067 
13068         /* Check that INVALID_VALUE is generated by GetCompressedTextureImage if
13069          level is less than zero or greater than the maximum number of LODs
13070          permitted by the implementation. */
13071         gl.getCompressedTextureImage(texture_2D_compressed, -1, s_reference_size, store);
13072         is_ok &=
13073             CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetCompressedTextureImage", "level is less than zero.");
13074 
13075         gl.getCompressedTextureImage(texture_2D_compressed, max_level, s_reference_size, store);
13076         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetCompressedTextureImage",
13077                                   "level is greater than the maximum number of LODs permitted by the implementation.");
13078 
13079         /* Check that INVALID_OPERATION is generated if GetCompressedTextureImage
13080          is used to retrieve a texture that is in an uncompressed internal
13081          format. */
13082         gl.getCompressedTextureImage(texture_2D, 0, s_reference_size, store);
13083         is_ok &=
13084             CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetCompressedTextureImage",
13085                              "the function is used to retrieve a texture that is in an uncompressed internal format.");
13086 
13087         /* Check that INVALID_OPERATION is generated by GetCompressedTextureImage
13088          if a non-zero buffer object name is bound to the PIXEL_PACK_BUFFER
13089          target, the buffer storage was not initialized with BufferStorage using
13090          MAP_PERSISTENT_BIT flag, and the buffer object's data store is currently
13091          mapped. */
13092         gl.bindBuffer(GL_PIXEL_PACK_BUFFER, buffer);
13093         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
13094 
13095         gl.mapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_WRITE);
13096 
13097         if (GL_NO_ERROR == gl.getError())
13098         {
13099             gl.getCompressedTextureImage(texture_2D_compressed, 0, s_reference_size, NULL);
13100             is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetCompressedTextureImage",
13101                                       "a non-zero buffer object name is bound to the PIXEL_PACK_BUFFER target, the "
13102                                       "buffer storage was not initialized with BufferStorage using MAP_PERSISTENT_BIT "
13103                                       "flag, and the buffer object's data store is currently mapped.");
13104 
13105             gl.unmapBuffer(GL_PIXEL_PACK_BUFFER);
13106             GLU_EXPECT_NO_ERROR(gl.getError(), "glUnmapBuffer has failed");
13107         }
13108         else
13109         {
13110             throw 0;
13111         }
13112 
13113         gl.bindBuffer(GL_PIXEL_PACK_BUFFER, 0);
13114         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
13115 
13116         /* Check that INVALID_OPERATION is generated by GetCompressedTextureImage
13117          if a non-zero buffer object name is bound to the PIXEL_PACK_BUFFER
13118          target and the data would be packed to the buffer object such that the
13119          memory writes required would exceed the data store size. */
13120         gl.bindBuffer(GL_PIXEL_PACK_BUFFER, buffer);
13121         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
13122 
13123         gl.getCompressedTextureImage(texture_2D_compressed, 0, s_reference_size,
13124                                      glu::BufferOffsetAsPointer(s_reference_size - 1));
13125         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetCompressedTextureImage",
13126                                   "a non-zero buffer object name is bound to the PIXEL_PACK_BUFFER target and the data "
13127                                   "would be packed to the buffer object such that the memory writes required would "
13128                                   "exceed the data store size.");
13129 
13130         gl.bindBuffer(GL_PIXEL_PACK_BUFFER, 0);
13131         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed");
13132     }
13133     catch (...)
13134     {
13135         is_ok    = false;
13136         is_error = true;
13137     }
13138 
13139     /* Cleanup. */
13140     if (buffer)
13141     {
13142         gl.deleteBuffers(1, &buffer);
13143     }
13144 
13145     if (texture_2D)
13146     {
13147         gl.deleteTextures(1, &texture_2D);
13148     }
13149 
13150     if (texture_2D_int)
13151     {
13152         gl.deleteTextures(1, &texture_2D_int);
13153     }
13154 
13155     if (texture_2D_stencil)
13156     {
13157         gl.deleteTextures(1, &texture_2D_stencil);
13158     }
13159 
13160     if (texture_2D_ms)
13161     {
13162         gl.deleteTextures(1, &texture_2D_ms);
13163     }
13164 
13165     if (texture_2D_compressed)
13166     {
13167         gl.deleteTextures(1, &texture_2D_compressed);
13168     }
13169 
13170     if (texture_cube)
13171     {
13172         gl.deleteTextures(1, &texture_cube);
13173     }
13174 
13175     if (texture_rectangle)
13176     {
13177         gl.deleteTextures(1, &texture_rectangle);
13178     }
13179 
13180     while (GL_NO_ERROR != gl.getError())
13181         ;
13182 
13183     /* Result's setup. */
13184     if (is_ok)
13185     {
13186         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
13187     }
13188     else
13189     {
13190         if (is_error)
13191         {
13192             m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
13193         }
13194         else
13195         {
13196             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
13197         }
13198     }
13199 
13200     return STOP;
13201 }
13202 
13203 /******************************** Level Parameter Query Errors Test Implementation   ********************************/
13204 
13205 /** @brief Image Query Errors Test constructor.
13206  *
13207  *  @param [in] context     OpenGL context.
13208  */
LevelParameterErrorsTest(deqp::Context & context)13209 LevelParameterErrorsTest::LevelParameterErrorsTest(deqp::Context &context)
13210     : deqp::TestCase(context, "textures_level_parameter_errors", "Texture Level Parameter Query Errors Test")
13211 {
13212     /* Intentionally left blank. */
13213 }
13214 
13215 /** @brief Iterate Level Parameter Query Errors Test cases.
13216  *
13217  *  @return Iteration result.
13218  */
iterate()13219 tcu::TestNode::IterateResult LevelParameterErrorsTest::iterate()
13220 {
13221     /* Shortcut for GL functionality. */
13222     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
13223 
13224     /* Get context setup. */
13225     bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
13226     bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
13227 
13228     if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
13229     {
13230         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
13231 
13232         return STOP;
13233     }
13234 
13235     /* Running tests. */
13236     bool is_ok    = true;
13237     bool is_error = false;
13238 
13239     /* Objects. */
13240     glw::GLuint texture_2D      = 0;
13241     glw::GLuint texture_invalid = 0;
13242     glw::GLint max_level        = 0;
13243     glw::GLenum pname_invalid   = 0;
13244 
13245     glw::GLfloat storef[4] = {};
13246     glw::GLint storei[4]   = {};
13247 
13248     try
13249     {
13250         /* Preparations. */
13251 
13252         /* 2D texture */
13253         gl.genTextures(1, &texture_2D);
13254         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
13255 
13256         gl.bindTexture(GL_TEXTURE_2D, texture_2D);
13257         GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed");
13258 
13259         gl.texStorage2D(GL_TEXTURE_2D, 1, GL_R8, 1, 1);
13260         GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed");
13261 
13262         /* Limits. */
13263         gl.getIntegerv(GL_MAX_TEXTURE_SIZE, &max_level); /* assuming that x > log(x) */
13264         GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed");
13265 
13266         /* invalid texture */
13267         while (gl.isTexture(++texture_invalid))
13268             ;
13269 
13270         /* invalid pname */
13271         glw::GLenum all_pnames[] = {GL_TEXTURE_WIDTH,
13272                                     GL_TEXTURE_HEIGHT,
13273                                     GL_TEXTURE_DEPTH,
13274                                     GL_TEXTURE_SAMPLES,
13275                                     GL_TEXTURE_FIXED_SAMPLE_LOCATIONS,
13276                                     GL_TEXTURE_INTERNAL_FORMAT,
13277                                     GL_TEXTURE_RED_SIZE,
13278                                     GL_TEXTURE_GREEN_SIZE,
13279                                     GL_TEXTURE_BLUE_SIZE,
13280                                     GL_TEXTURE_ALPHA_SIZE,
13281                                     GL_TEXTURE_DEPTH_SIZE,
13282                                     GL_TEXTURE_STENCIL_SIZE,
13283                                     GL_TEXTURE_SHARED_SIZE,
13284                                     GL_TEXTURE_RED_TYPE,
13285                                     GL_TEXTURE_GREEN_TYPE,
13286                                     GL_TEXTURE_BLUE_TYPE,
13287                                     GL_TEXTURE_ALPHA_TYPE,
13288                                     GL_TEXTURE_DEPTH_TYPE,
13289                                     GL_TEXTURE_COMPRESSED,
13290                                     GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
13291                                     GL_TEXTURE_BUFFER_DATA_STORE_BINDING,
13292                                     GL_TEXTURE_BUFFER_OFFSET,
13293                                     GL_TEXTURE_BUFFER_SIZE};
13294 
13295         glw::GLuint all_pnames_count = sizeof(all_pnames) / sizeof(all_pnames[0]);
13296 
13297         bool is_valid = true;
13298 
13299         while (is_valid)
13300         {
13301             is_valid = false;
13302 
13303             ++pname_invalid;
13304 
13305             for (glw::GLuint i = 0; i < all_pnames_count; ++i)
13306             {
13307                 if (all_pnames[i] == pname_invalid)
13308                 {
13309                     is_valid = true;
13310 
13311                     break;
13312                 }
13313             }
13314         }
13315 
13316         /* Tests. */
13317 
13318         /* Check that INVALID_OPERATION is generated by GetTextureLevelParameterfv
13319          and GetTextureLevelParameteriv functions if texture is not the name of
13320          an existing texture object. */
13321         gl.getTextureLevelParameterfv(texture_invalid, 0, GL_TEXTURE_WIDTH, storef);
13322         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureLevelParameterfv",
13323                                   "texture is not the name of an existing texture object.");
13324 
13325         gl.getTextureLevelParameteriv(texture_invalid, 0, GL_TEXTURE_WIDTH, storei);
13326         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureLevelParameteriv",
13327                                   "texture is not the name of an existing texture object.");
13328 
13329         /* Check that INVALID_VALUE is generated by GetTextureLevelParameter* if
13330          level is less than 0. */
13331         gl.getTextureLevelParameterfv(texture_2D, -1, GL_TEXTURE_WIDTH, storef);
13332         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureLevelParameterfv", "level is less than 0.");
13333 
13334         gl.getTextureLevelParameteriv(texture_2D, -1, GL_TEXTURE_WIDTH, storei);
13335         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureLevelParameteriv", "level is less than 0.");
13336 
13337         /* Check that INVALID_ENUM error is generated by GetTextureLevelParameter*
13338          if pname is not one of supported constants. */
13339         gl.getTextureLevelParameterfv(texture_2D, 0, pname_invalid, storef);
13340         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureLevelParameterfv",
13341                                   "pname is not one of supported constants.");
13342 
13343         gl.getTextureLevelParameteriv(texture_2D, 0, pname_invalid, storei);
13344         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureLevelParameteriv",
13345                                   "pname is not one of supported constants.");
13346 
13347         /* Check that INVALID_VALUE may be generated if level is greater than
13348          log2 max, where max is the returned value of MAX_TEXTURE_SIZE. */
13349         gl.getTextureLevelParameterfv(texture_2D, max_level, GL_TEXTURE_WIDTH, storef);
13350         is_ok &=
13351             CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureLevelParameterfv",
13352                              "level is greater than log2 max, where max is the returned value of MAX_TEXTURE_SIZE.");
13353 
13354         gl.getTextureLevelParameteriv(texture_2D, max_level, GL_TEXTURE_WIDTH, storei);
13355         is_ok &=
13356             CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glGetTextureLevelParameteriv",
13357                              "level is greater than log2 max, where max is the returned value of MAX_TEXTURE_SIZE.");
13358 
13359         /* Check that INVALID_OPERATION is generated by GetTextureLevelParameter*
13360          if TEXTURE_COMPRESSED_IMAGE_SIZE is queried on texture images with an
13361          uncompressed internal format or on proxy targets. */
13362         gl.getTextureLevelParameterfv(texture_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, storef);
13363         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureLevelParameterfv",
13364                                   "TEXTURE_COMPRESSED_IMAGE_SIZE is queried on texture images with an uncompressed "
13365                                   "internal format or on proxy targets.");
13366 
13367         gl.getTextureLevelParameteriv(texture_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, storei);
13368         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureLevelParameteriv",
13369                                   "TEXTURE_COMPRESSED_IMAGE_SIZE is queried on texture images with an uncompressed "
13370                                   "internal format or on proxy targets.");
13371     }
13372     catch (...)
13373     {
13374         is_ok    = false;
13375         is_error = true;
13376     }
13377 
13378     /* Cleanup. */
13379     if (texture_2D)
13380     {
13381         gl.deleteTextures(1, &texture_2D);
13382     }
13383 
13384     while (GL_NO_ERROR != gl.getError())
13385         ;
13386 
13387     /* Result's setup. */
13388     if (is_ok)
13389     {
13390         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
13391     }
13392     else
13393     {
13394         if (is_error)
13395         {
13396             m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
13397         }
13398         else
13399         {
13400             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
13401         }
13402     }
13403 
13404     return STOP;
13405 }
13406 
13407 /******************************** Parameter Query Errors Test Implementation   ********************************/
13408 
13409 /** @brief Parameter Query Errors Test constructor.
13410  *
13411  *  @param [in] context     OpenGL context.
13412  */
ParameterErrorsTest(deqp::Context & context)13413 ParameterErrorsTest::ParameterErrorsTest(deqp::Context &context)
13414     : deqp::TestCase(context, "textures_parameter_errors", "Texture Parameter Query Errors Test")
13415 {
13416     /* Intentionally left blank. */
13417 }
13418 
13419 /** @brief Iterate Parameter Query Errors Test cases.
13420  *
13421  *  @return Iteration result.
13422  */
iterate()13423 tcu::TestNode::IterateResult ParameterErrorsTest::iterate()
13424 {
13425     /* Shortcut for GL functionality. */
13426     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
13427 
13428     /* Get context setup. */
13429     bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
13430     bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access");
13431 
13432     if ((!is_at_least_gl_45) && (!is_arb_direct_state_access))
13433     {
13434         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
13435 
13436         return STOP;
13437     }
13438 
13439     /* Running tests. */
13440     bool is_ok    = true;
13441     bool is_error = false;
13442 
13443     /* Objects. */
13444     glw::GLuint texture_2D      = 0;
13445     glw::GLuint texture_buffer  = 0;
13446     glw::GLuint texture_invalid = 0;
13447     glw::GLenum pname_invalid   = 0;
13448 
13449     glw::GLfloat storef[4] = {};
13450     glw::GLint storei[4]   = {};
13451     glw::GLuint storeu[4]  = {};
13452 
13453     try
13454     {
13455         /* Preparations. */
13456 
13457         /* 2D texture */
13458         gl.createTextures(GL_TEXTURE_2D, 1, &texture_2D);
13459         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
13460 
13461         /* Buffer texture */
13462         gl.createTextures(GL_TEXTURE_BUFFER, 1, &texture_buffer);
13463         GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed");
13464 
13465         /* invalid texture */
13466         while (gl.isTexture(++texture_invalid))
13467             ;
13468 
13469         /* invalid pname */
13470         glw::GLenum all_pnames[] = {GL_IMAGE_FORMAT_COMPATIBILITY_TYPE,
13471                                     GL_TEXTURE_IMMUTABLE_FORMAT,
13472                                     GL_TEXTURE_IMMUTABLE_LEVELS,
13473                                     GL_TEXTURE_TARGET,
13474                                     GL_TEXTURE_VIEW_MIN_LEVEL,
13475                                     GL_TEXTURE_VIEW_NUM_LEVELS,
13476                                     GL_TEXTURE_VIEW_MIN_LAYER,
13477                                     GL_TEXTURE_VIEW_NUM_LAYERS,
13478                                     GL_DEPTH_STENCIL_TEXTURE_MODE,
13479                                     GL_DEPTH_COMPONENT,
13480                                     GL_STENCIL_INDEX,
13481                                     GL_TEXTURE_BASE_LEVEL,
13482                                     GL_TEXTURE_BORDER_COLOR,
13483                                     GL_TEXTURE_COMPARE_MODE,
13484                                     GL_TEXTURE_COMPARE_FUNC,
13485                                     GL_TEXTURE_LOD_BIAS,
13486                                     GL_TEXTURE_MAG_FILTER,
13487                                     GL_TEXTURE_MAX_LEVEL,
13488                                     GL_TEXTURE_MAX_LOD,
13489                                     GL_TEXTURE_MIN_FILTER,
13490                                     GL_TEXTURE_MIN_LOD,
13491                                     GL_TEXTURE_SWIZZLE_R,
13492                                     GL_TEXTURE_SWIZZLE_G,
13493                                     GL_TEXTURE_SWIZZLE_B,
13494                                     GL_TEXTURE_SWIZZLE_A,
13495                                     GL_TEXTURE_SWIZZLE_RGBA,
13496                                     GL_TEXTURE_WRAP_S,
13497                                     GL_TEXTURE_WRAP_T,
13498                                     GL_TEXTURE_WRAP_R};
13499 
13500         glw::GLuint all_pnames_count = sizeof(all_pnames) / sizeof(all_pnames[0]);
13501 
13502         bool is_valid = true;
13503 
13504         while (is_valid)
13505         {
13506             is_valid = false;
13507 
13508             ++pname_invalid;
13509 
13510             for (glw::GLuint i = 0; i < all_pnames_count; ++i)
13511             {
13512                 if (all_pnames[i] == pname_invalid)
13513                 {
13514                     is_valid = true;
13515 
13516                     break;
13517                 }
13518             }
13519         }
13520 
13521         /* Tests. */
13522 
13523         /* Check that INVALID_ENUM is generated by glGetTextureParameter* if pname
13524          is not an accepted value. */
13525         gl.getTextureParameterfv(texture_2D, pname_invalid, storef);
13526         is_ok &=
13527             CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureParameterfv", "pname is not an accepted value.");
13528 
13529         gl.getTextureParameterIiv(texture_2D, pname_invalid, storei);
13530         is_ok &=
13531             CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureParameterIiv", "pname is not an accepted value.");
13532 
13533         gl.getTextureParameterIuiv(texture_2D, pname_invalid, storeu);
13534         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureParameterIuiv",
13535                                   "pname is not an accepted value.");
13536 
13537         gl.getTextureParameteriv(texture_2D, pname_invalid, storei);
13538         is_ok &=
13539             CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glGetTextureParameteriv", "pname is not an accepted value.");
13540 
13541         /* Check that INVALID_OPERATION is generated by glGetTextureParameter* if
13542          texture is not the name of an existing texture object. */
13543         gl.getTextureParameterfv(texture_invalid, GL_TEXTURE_TARGET, storef);
13544         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameterfv",
13545                                   "texture is not the name of an existing texture object.");
13546 
13547         gl.getTextureParameterIiv(texture_invalid, GL_TEXTURE_TARGET, storei);
13548         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameterIiv",
13549                                   "texture is not the name of an existing texture object.");
13550 
13551         gl.getTextureParameterIuiv(texture_invalid, GL_TEXTURE_TARGET, storeu);
13552         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameterIuiv",
13553                                   "texture is not the name of an existing texture object.");
13554 
13555         gl.getTextureParameteriv(texture_invalid, GL_TEXTURE_TARGET, storei);
13556         is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameteriv",
13557                                   "texture is not the name of an existing texture object.");
13558 
13559         /* Check that INVALID_OPERATION error is generated if the effective target is
13560          not one of the supported texture targets (eg. TEXTURE_BUFFER). */
13561         gl.getTextureParameterfv(texture_buffer, GL_TEXTURE_TARGET, storef);
13562         is_ok &=
13563             CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameterfv",
13564                              "the effective target is not one of the supported texture targets (eg. TEXTURE_BUFFER).");
13565 
13566         gl.getTextureParameterIiv(texture_buffer, GL_TEXTURE_TARGET, storei);
13567         is_ok &=
13568             CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameterIiv",
13569                              "the effective target is not one of the supported texture targets (eg. TEXTURE_BUFFER).");
13570 
13571         gl.getTextureParameterIuiv(texture_buffer, GL_TEXTURE_TARGET, storeu);
13572         is_ok &=
13573             CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameterIuiv",
13574                              "the effective target is not one of the supported texture targets (eg. TEXTURE_BUFFER).");
13575 
13576         gl.getTextureParameteriv(texture_buffer, GL_TEXTURE_TARGET, storei);
13577         is_ok &=
13578             CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glGetTextureParameteriv",
13579                              "the effective target is not one of the supported texture targets (eg. TEXTURE_BUFFER).");
13580     }
13581     catch (...)
13582     {
13583         is_ok    = false;
13584         is_error = true;
13585     }
13586 
13587     /* Cleanup. */
13588     if (texture_2D)
13589     {
13590         gl.deleteTextures(1, &texture_2D);
13591     }
13592 
13593     if (texture_buffer)
13594     {
13595         gl.deleteTextures(1, &texture_buffer);
13596     }
13597 
13598     while (GL_NO_ERROR != gl.getError())
13599         ;
13600 
13601     /* Result's setup. */
13602     if (is_ok)
13603     {
13604         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
13605     }
13606     else
13607     {
13608         if (is_error)
13609         {
13610             m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error");
13611         }
13612         else
13613         {
13614             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
13615         }
13616     }
13617 
13618     return STOP;
13619 }
13620 
13621 } // namespace Textures
13622 } // namespace DirectStateAccess
13623 } // namespace gl4cts
13624