1 /*------------------------------------------------------------------------- 2 * OpenGL Conformance Test Suite 3 * ----------------------------- 4 * 5 * Copyright (c) 2015-2016 The Khronos Group Inc. 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 * 19 */ /*! 20 * \file 21 * \brief 22 */ /*-------------------------------------------------------------------*/ 23 24 /** 25 */ /*! 26 * \file gl4cDirectStateAccessTexturesTests.cpp 27 * \brief Conformance tests for the Direct State Access feature functionality (Texture access part). 28 */ /*-----------------------------------------------------------------------------------------------------------*/ 29 30 /* Uncomment this if SubImageErrorsTest crashes during negative test of TextureSubImage (negative value width/height/depth passed to the function). */ 31 /* #define TURN_OFF_SUB_IMAGE_ERRORS_TEST_OF_NEGATIVE_WIDTH_HEIGHT_OR_DEPTH */ 32 33 /* Includes. */ 34 #include "gl4cDirectStateAccessTests.hpp" 35 36 #include "deSharedPtr.hpp" 37 38 #include "gluContextInfo.hpp" 39 #include "gluDefs.hpp" 40 #include "gluPixelTransfer.hpp" 41 #include "gluStrUtil.hpp" 42 43 #include "tcuFuzzyImageCompare.hpp" 44 #include "tcuImageCompare.hpp" 45 #include "tcuRenderTarget.hpp" 46 #include "tcuSurface.hpp" 47 #include "tcuTestLog.hpp" 48 49 #include "glw.h" 50 #include "glwFunctions.hpp" 51 52 #include <algorithm> 53 #include <climits> 54 #include <set> 55 #include <sstream> 56 #include <stack> 57 #include <string> 58 59 namespace gl4cts 60 { 61 namespace DirectStateAccess 62 { 63 namespace Textures 64 { 65 /******************************** Creation Test Implementation ********************************/ 66 67 /** @brief Creation Test constructor. 68 * 69 * @param [in] context OpenGL context. 70 */ 71 CreationTest::CreationTest(deqp::Context& context) 72 : deqp::TestCase(context, "textures_creation", "Texture Objects Creation Test") 73 { 74 /* Intentionally left blank. */ 75 } 76 77 /** @brief Iterate Creation Test cases. 78 * 79 * @return Iteration result. 80 */ 81 tcu::TestNode::IterateResult CreationTest::iterate() 82 { 83 /* Shortcut for GL functionality. */ 84 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 85 86 /* Get context setup. */ 87 bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5))); 88 bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access"); 89 90 if ((!is_at_least_gl_45) && (!is_arb_direct_state_access)) 91 { 92 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported"); 93 94 return STOP; 95 } 96 97 /* Running tests. */ 98 bool is_ok = true; 99 bool is_error = false; 100 101 /* Textures' objects */ 102 static const glw::GLenum texture_targets[] = { GL_TEXTURE_1D, 103 GL_TEXTURE_2D, 104 GL_TEXTURE_3D, 105 GL_TEXTURE_1D_ARRAY, 106 GL_TEXTURE_2D_ARRAY, 107 GL_TEXTURE_RECTANGLE, 108 GL_TEXTURE_CUBE_MAP, 109 GL_TEXTURE_CUBE_MAP_ARRAY, 110 GL_TEXTURE_BUFFER, 111 GL_TEXTURE_2D_MULTISAMPLE, 112 GL_TEXTURE_2D_MULTISAMPLE_ARRAY }; 113 static const glw::GLuint texture_targets_count = sizeof(texture_targets) / sizeof(texture_targets[0]); 114 static const glw::GLuint textures_count = 2; 115 116 glw::GLuint textures_legacy[textures_count] = {}; 117 glw::GLuint textures_dsa[texture_targets_count][textures_count] = {}; 118 119 try 120 { 121 /* Check legacy state creation. */ 122 gl.genTextures(textures_count, textures_legacy); 123 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed"); 124 125 for (glw::GLuint i = 0; i < textures_count; ++i) 126 { 127 if (gl.isTexture(textures_legacy[i])) 128 { 129 is_ok = false; 130 131 /* Log. */ 132 m_context.getTestContext().getLog() 133 << tcu::TestLog::Message 134 << "GenTextures has created default objects, but it should create only a names." 135 << tcu::TestLog::EndMessage; 136 } 137 } 138 139 /* Check direct state creation. */ 140 for (glw::GLuint j = 0; j < texture_targets_count; ++j) 141 { 142 gl.createTextures(texture_targets[j], textures_count, textures_dsa[j]); 143 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed"); 144 145 for (glw::GLuint i = 0; i < textures_count; ++i) 146 { 147 if (!gl.isTexture(textures_dsa[j][i])) 148 { 149 is_ok = false; 150 151 /* Log. */ 152 m_context.getTestContext().getLog() 153 << tcu::TestLog::Message << "CreateTextures has not created default objects for target " 154 << glu::getTextureTargetStr(texture_targets[j]) << "." << tcu::TestLog::EndMessage; 155 } 156 } 157 } 158 } 159 catch (...) 160 { 161 is_ok = false; 162 is_error = true; 163 } 164 165 /* Cleanup. */ 166 for (glw::GLuint i = 0; i < textures_count; ++i) 167 { 168 if (textures_legacy[i]) 169 { 170 gl.deleteTextures(1, &textures_legacy[i]); 171 172 textures_legacy[i] = 0; 173 } 174 175 for (glw::GLuint j = 0; j < texture_targets_count; ++j) 176 { 177 if (textures_dsa[j][i]) 178 { 179 gl.deleteTextures(1, &textures_dsa[j][i]); 180 181 textures_dsa[j][i] = 0; 182 } 183 } 184 } 185 186 /* Errors clean up. */ 187 while (gl.getError()) 188 ; 189 190 /* Result's setup. */ 191 if (is_ok) 192 { 193 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 194 } 195 else 196 { 197 if (is_error) 198 { 199 m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error"); 200 } 201 else 202 { 203 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); 204 } 205 } 206 207 return STOP; 208 } 209 210 /******************************** Reference Data Implementation *****************************/ 211 212 /** @brief Internal Format selector. 213 * 214 * @tparam T Type. 215 * @tparam S Size (# of components). 216 * @tparam N Is normalized. 217 * 218 * @return Internal format. 219 */ 220 template <> 221 glw::GLenum Reference::InternalFormat<glw::GLbyte, 1, false>() 222 { 223 return GL_R8I; 224 } 225 226 template <> 227 glw::GLenum Reference::InternalFormat<glw::GLbyte, 2, false>() 228 { 229 return GL_RG8I; 230 } 231 232 template <> 233 glw::GLenum Reference::InternalFormat<glw::GLbyte, 3, false>() 234 { 235 return GL_RGB8I; 236 } 237 238 template <> 239 glw::GLenum Reference::InternalFormat<glw::GLbyte, 4, false>() 240 { 241 return GL_RGBA8I; 242 } 243 244 template <> 245 glw::GLenum Reference::InternalFormat<glw::GLubyte, 1, false>() 246 { 247 return GL_R8UI; 248 } 249 250 template <> 251 glw::GLenum Reference::InternalFormat<glw::GLubyte, 2, false>() 252 { 253 return GL_RG8UI; 254 } 255 256 template <> 257 glw::GLenum Reference::InternalFormat<glw::GLubyte, 3, false>() 258 { 259 return GL_RGB8UI; 260 } 261 262 template <> 263 glw::GLenum Reference::InternalFormat<glw::GLubyte, 4, false>() 264 { 265 return GL_RGBA8UI; 266 } 267 268 template <> 269 glw::GLenum Reference::InternalFormat<glw::GLshort, 1, false>() 270 { 271 return GL_R16I; 272 } 273 274 template <> 275 glw::GLenum Reference::InternalFormat<glw::GLshort, 2, false>() 276 { 277 return GL_RG16I; 278 } 279 280 template <> 281 glw::GLenum Reference::InternalFormat<glw::GLshort, 3, false>() 282 { 283 return GL_RGB16I; 284 } 285 286 template <> 287 glw::GLenum Reference::InternalFormat<glw::GLshort, 4, false>() 288 { 289 return GL_RGBA16I; 290 } 291 292 template <> 293 glw::GLenum Reference::InternalFormat<glw::GLushort, 1, false>() 294 { 295 return GL_R16UI; 296 } 297 298 template <> 299 glw::GLenum Reference::InternalFormat<glw::GLushort, 2, false>() 300 { 301 return GL_RG16UI; 302 } 303 304 template <> 305 glw::GLenum Reference::InternalFormat<glw::GLushort, 3, false>() 306 { 307 return GL_RGB16UI; 308 } 309 310 template <> 311 glw::GLenum Reference::InternalFormat<glw::GLushort, 4, false>() 312 { 313 return GL_RGBA16UI; 314 } 315 316 template <> 317 glw::GLenum Reference::InternalFormat<glw::GLint, 1, false>() 318 { 319 return GL_R32I; 320 } 321 322 template <> 323 glw::GLenum Reference::InternalFormat<glw::GLint, 2, false>() 324 { 325 return GL_RG32I; 326 } 327 328 template <> 329 glw::GLenum Reference::InternalFormat<glw::GLint, 3, false>() 330 { 331 return GL_RGB32I; 332 } 333 334 template <> 335 glw::GLenum Reference::InternalFormat<glw::GLint, 4, false>() 336 { 337 return GL_RGBA32I; 338 } 339 340 template <> 341 glw::GLenum Reference::InternalFormat<glw::GLuint, 1, false>() 342 { 343 return GL_R32UI; 344 } 345 346 template <> 347 glw::GLenum Reference::InternalFormat<glw::GLuint, 2, false>() 348 { 349 return GL_RG32UI; 350 } 351 352 template <> 353 glw::GLenum Reference::InternalFormat<glw::GLuint, 3, false>() 354 { 355 return GL_RGB32UI; 356 } 357 358 template <> 359 glw::GLenum Reference::InternalFormat<glw::GLuint, 4, false>() 360 { 361 return GL_RGBA32UI; 362 } 363 364 template <> 365 glw::GLenum Reference::InternalFormat<glw::GLubyte, 1, true>() 366 { 367 return GL_R8; 368 } 369 370 template <> 371 glw::GLenum Reference::InternalFormat<glw::GLubyte, 2, true>() 372 { 373 return GL_RG8; 374 } 375 376 template <> 377 glw::GLenum Reference::InternalFormat<glw::GLubyte, 3, true>() 378 { 379 return GL_RGB8; 380 } 381 382 template <> 383 glw::GLenum Reference::InternalFormat<glw::GLubyte, 4, true>() 384 { 385 return GL_RGBA8; 386 } 387 388 template <> 389 glw::GLenum Reference::InternalFormat<glw::GLushort, 1, true>() 390 { 391 return GL_R16; 392 } 393 394 template <> 395 glw::GLenum Reference::InternalFormat<glw::GLushort, 2, true>() 396 { 397 return GL_RG16; 398 } 399 400 template <> 401 glw::GLenum Reference::InternalFormat<glw::GLushort, 3, true>() 402 { 403 return GL_RGB16; 404 } 405 406 template <> 407 glw::GLenum Reference::InternalFormat<glw::GLushort, 4, true>() 408 { 409 return GL_RGBA16; 410 } 411 412 template <> 413 glw::GLenum Reference::InternalFormat<glw::GLfloat, 1, true>() 414 { 415 return GL_R32F; 416 } 417 418 template <> 419 glw::GLenum Reference::InternalFormat<glw::GLfloat, 2, true>() 420 { 421 return GL_RG32F; 422 } 423 424 template <> 425 glw::GLenum Reference::InternalFormat<glw::GLfloat, 3, true>() 426 { 427 return GL_RGB32F; 428 } 429 430 template <> 431 glw::GLenum Reference::InternalFormat<glw::GLfloat, 4, true>() 432 { 433 return GL_RGBA32F; 434 } 435 436 /** @brief Format selector. 437 * 438 * @tparam S Size (# of components). 439 * @tparam N Is normalized. 440 * 441 * @return format. 442 */ 443 template <> 444 glw::GLenum Reference::Format<1, false>() 445 { 446 return GL_RED_INTEGER; 447 } 448 449 template <> 450 glw::GLenum Reference::Format<2, false>() 451 { 452 return GL_RG_INTEGER; 453 } 454 455 template <> 456 glw::GLenum Reference::Format<3, false>() 457 { 458 return GL_RGB_INTEGER; 459 } 460 461 template <> 462 glw::GLenum Reference::Format<4, false>() 463 { 464 return GL_RGBA_INTEGER; 465 } 466 467 template <> 468 glw::GLenum Reference::Format<1, true>() 469 { 470 return GL_RED; 471 } 472 473 template <> 474 glw::GLenum Reference::Format<2, true>() 475 { 476 return GL_RG; 477 } 478 479 template <> 480 glw::GLenum Reference::Format<3, true>() 481 { 482 return GL_RGB; 483 } 484 485 template <> 486 glw::GLenum Reference::Format<4, true>() 487 { 488 return GL_RGBA; 489 } 490 491 /** @brief Type selector. 492 * 493 * @tparam T Type. 494 * 495 * @return Type. 496 */ 497 template <> 498 glw::GLenum Reference::Type<glw::GLbyte>() 499 { 500 return GL_BYTE; 501 } 502 503 template <> 504 glw::GLenum Reference::Type<glw::GLubyte>() 505 { 506 return GL_UNSIGNED_BYTE; 507 } 508 509 template <> 510 glw::GLenum Reference::Type<glw::GLshort>() 511 { 512 return GL_SHORT; 513 } 514 515 template <> 516 glw::GLenum Reference::Type<glw::GLushort>() 517 { 518 return GL_UNSIGNED_SHORT; 519 } 520 521 template <> 522 glw::GLenum Reference::Type<glw::GLint>() 523 { 524 return GL_INT; 525 } 526 527 template <> 528 glw::GLenum Reference::Type<glw::GLuint>() 529 { 530 return GL_UNSIGNED_INT; 531 } 532 533 template <> 534 glw::GLenum Reference::Type<glw::GLfloat>() 535 { 536 return GL_FLOAT; 537 } 538 539 /** @brief Reference data selector. 540 * 541 * @tparam T Type. 542 * @tparam N Is normalized. 543 * 544 * @return Reference data. 545 */ 546 547 /* RGBA8I */ 548 template <> 549 const glw::GLbyte* Reference::ReferenceData<glw::GLbyte, false>() 550 { 551 static const glw::GLbyte reference[s_reference_count] = { 552 0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15, 16, -17, 18, -19, 20, -21, 22, -23, 553 24, -25, 26, -27, 28, -29, 30, -31, 32, -33, 34, -35, 36, -37, 38, -39, 40, -41, 42, -43, 44, -45, 46, -47, 554 48, -49, 50, -51, 52, -53, 54, -55, 56, -57, 58, -59, 60, -61, 62, -63, 64, -65, 66, -67, 68, -69, 70, -71, 555 72, -73, 74, -75, 76, -77, 78, -79, 80, -81, 82, -83, 84, -85, 86, -87, 88, -89, 90, -91, 92, -93, 94, -95 556 }; 557 return reference; 558 } 559 560 /* RGBA8UI */ 561 template <> 562 const glw::GLubyte* Reference::ReferenceData<glw::GLubyte, false>() 563 { 564 static const glw::GLubyte reference[s_reference_count] = { 565 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 566 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 567 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 568 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95 569 }; 570 return reference; 571 } 572 573 /* RGBA16I */ 574 template <> 575 const glw::GLshort* Reference::ReferenceData<glw::GLshort, false>() 576 { 577 static const glw::GLshort reference[s_reference_count] = { 578 0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15, 16, -17, 18, -19, 20, -21, 22, -23, 579 24, -25, 26, -27, 28, -29, 30, -31, 32, -33, 34, -35, 36, -37, 38, -39, 40, -41, 42, -43, 44, -45, 46, -47, 580 48, -49, 50, -51, 52, -53, 54, -55, 56, -57, 58, -59, 60, -61, 62, -63, 64, -65, 66, -67, 68, -69, 70, -71, 581 72, -73, 74, -75, 76, -77, 78, -79, 80, -81, 82, -83, 84, -85, 86, -87, 88, -89, 90, -91, 92, -93, 94, -95 582 }; 583 return reference; 584 } 585 586 /* RGBA16UI */ 587 template <> 588 const glw::GLushort* Reference::ReferenceData<glw::GLushort, false>() 589 { 590 static const glw::GLushort reference[s_reference_count] = { 591 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 592 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 593 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 594 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95 595 }; 596 return reference; 597 } 598 599 /* RGBA32I */ 600 template <> 601 const glw::GLint* Reference::ReferenceData<glw::GLint, false>() 602 { 603 static const glw::GLint reference[s_reference_count] = { 604 0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15, 16, -17, 18, -19, 20, -21, 22, -23, 605 24, -25, 26, -27, 28, -29, 30, -31, 32, -33, 34, -35, 36, -37, 38, -39, 40, -41, 42, -43, 44, -45, 46, -47, 606 48, -49, 50, -51, 52, -53, 54, -55, 56, -57, 58, -59, 60, -61, 62, -63, 64, -65, 66, -67, 68, -69, 70, -71, 607 72, -73, 74, -75, 76, -77, 78, -79, 80, -81, 82, -83, 84, -85, 86, -87, 88, -89, 90, -91, 92, -93, 94, -95 608 }; 609 return reference; 610 } 611 612 /* RGBA32UI */ 613 template <> 614 const glw::GLuint* Reference::ReferenceData<glw::GLuint, false>() 615 { 616 static const glw::GLuint reference[s_reference_count] = { 617 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 618 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 619 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 620 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95 621 }; 622 return reference; 623 } 624 625 /* RGBA8 */ 626 template <> 627 const glw::GLubyte* Reference::ReferenceData<glw::GLubyte, true>() 628 { 629 static const glw::GLubyte reference[s_reference_count] = { 630 0, 2, 5, 8, 10, 13, 16, 18, 21, 24, 26, 29, 32, 34, 37, 40, 42, 45, 48, 51, 631 53, 56, 59, 61, 64, 67, 69, 72, 75, 77, 80, 83, 85, 88, 91, 93, 96, 99, 102, 104, 632 107, 110, 112, 115, 118, 120, 123, 126, 128, 131, 134, 136, 139, 142, 144, 147, 150, 153, 155, 158, 633 161, 163, 166, 169, 171, 174, 177, 179, 182, 185, 187, 190, 193, 195, 198, 201, 204, 206, 209, 212, 634 214, 217, 220, 222, 225, 228, 230, 233, 236, 238, 241, 244, 246, 249, 252, 255 635 }; 636 return reference; 637 } 638 639 /* RGBA16 */ 640 template <> 641 const glw::GLushort* Reference::ReferenceData<glw::GLushort, true>() 642 { 643 static const glw::GLushort reference[s_reference_count] = { 644 0, 689, 1379, 2069, 2759, 3449, 4139, 4828, 5518, 6208, 6898, 7588, 8278, 8967, 9657, 10347, 645 11037, 11727, 12417, 13107, 13796, 14486, 15176, 15866, 16556, 17246, 17935, 18625, 19315, 20005, 20695, 21385, 646 22074, 22764, 23454, 24144, 24834, 25524, 26214, 26903, 27593, 28283, 28973, 29663, 30353, 31042, 31732, 32422, 647 33112, 33802, 34492, 35181, 35871, 36561, 37251, 37941, 38631, 39321, 40010, 40700, 41390, 42080, 42770, 43460, 648 44149, 44839, 45529, 46219, 46909, 47599, 48288, 48978, 49668, 50358, 51048, 51738, 52428, 53117, 53807, 54497, 649 55187, 55877, 56567, 57256, 57946, 58636, 59326, 60016, 60706, 61395, 62085, 62775, 63465, 64155, 64845, 65535 650 }; 651 return reference; 652 } 653 654 /* RGBA32F */ 655 template <> 656 const glw::GLfloat* Reference::ReferenceData<glw::GLfloat, true>() 657 { 658 static const glw::GLfloat reference[s_reference_count] = { 659 0.f, 0.0105263158f, 0.0210526316f, 0.0315789474f, 0.0421052632f, 0.0526315789f, 660 0.0631578947f, 0.0736842105f, 0.0842105263f, 0.0947368421f, 0.1052631579f, 0.1157894737f, 661 0.1263157895f, 0.1368421053f, 0.1473684211f, 0.1578947368f, 0.1684210526f, 0.1789473684f, 662 0.1894736842f, 0.2f, 0.2105263158f, 0.2210526316f, 0.2315789474f, 0.2421052632f, 663 0.2526315789f, 0.2631578947f, 0.2736842105f, 0.2842105263f, 0.2947368421f, 0.3052631579f, 664 0.3157894737f, 0.3263157895f, 0.3368421053f, 0.3473684211f, 0.3578947368f, 0.3684210526f, 665 0.3789473684f, 0.3894736842f, 0.4f, 0.4105263158f, 0.4210526316f, 0.4315789474f, 666 0.4421052632f, 0.4526315789f, 0.4631578947f, 0.4736842105f, 0.4842105263f, 0.4947368421f, 667 0.5052631579f, 0.5157894737f, 0.5263157895f, 0.5368421053f, 0.5473684211f, 0.5578947368f, 668 0.5684210526f, 0.5789473684f, 0.5894736842f, 0.6f, 0.6105263158f, 0.6210526316f, 669 0.6315789474f, 0.6421052632f, 0.6526315789f, 0.6631578947f, 0.6736842105f, 0.6842105263f, 670 0.6947368421f, 0.7052631579f, 0.7157894737f, 0.7263157895f, 0.7368421053f, 0.7473684211f, 671 0.7578947368f, 0.7684210526f, 0.7789473684f, 0.7894736842f, 0.8f, 0.8105263158f, 672 0.8210526316f, 0.8315789474f, 0.8421052632f, 0.8526315789f, 0.8631578947f, 0.8736842105f, 673 0.8842105263f, 0.8947368421f, 0.9052631579f, 0.9157894737f, 0.9263157895f, 0.9368421053f, 674 0.9473684211f, 0.9578947368f, 0.9684210526f, 0.9789473684f, 0.9894736842f, 1.f 675 }; 676 return reference; 677 } 678 679 /* Total number of reference components. */ 680 glw::GLuint Reference::ReferenceDataCount() 681 { 682 return s_reference_count; 683 } 684 685 /* Total number of reference size in basic machine units. */ 686 template <typename T> 687 glw::GLuint Reference::ReferenceDataSize() 688 { 689 return Reference::ReferenceDataCount() * sizeof(T); 690 } 691 692 /** @brief Comparison function (for floats). 693 * 694 * @param [in] a First element. 695 * @param [in] b Second element. 696 * 697 * @return Comparison result. 698 */ 699 template <> 700 bool Reference::Compare<glw::GLfloat>(const glw::GLfloat a, const glw::GLfloat b) 701 { 702 if (de::abs(a - b) < 1.f / 256.f) 703 { 704 return true; 705 } 706 return false; 707 } 708 709 /** @brief Comparison function (integer). 710 * 711 * @param [in] a First element. 712 * @param [in] b Second element. 713 * 714 * @return Comparison result. 715 */ 716 template <typename T> 717 bool Reference::Compare(const T a, const T b) 718 { 719 return a == b; 720 } 721 722 /******************************** Buffer Test Implementation ********************************/ 723 724 /** @brief Buffer Test constructor. 725 * 726 * @tparam T Type. 727 * @tparam S Size. 728 * @tparam N Is normalized. 729 * 730 * @param [in] context OpenGL context. 731 * @param [in] name Name of the test. 732 */ 733 template <typename T, glw::GLint S, bool N> 734 BufferTest<T, S, N>::BufferTest(deqp::Context& context, const char* name) 735 : deqp::TestCase(context, name, "Texture Buffer Objects Test") 736 , m_fbo(0) 737 , m_rbo(0) 738 , m_po(0) 739 , m_to(0) 740 , m_bo(0) 741 , m_vao(0) 742 { 743 /* Intentionally left blank. */ 744 } 745 746 /** @brief Count of reference data to be teted. 747 * 748 * @return Count. 749 */ 750 template <typename T, glw::GLint S, bool N> 751 glw::GLuint BufferTest<T, S, N>::TestReferenceDataCount() 752 { 753 return s_fbo_size_x * S; 754 } 755 756 /** @brief Size of reference data to be teted.. 757 * 758 * @return Size. 759 */ 760 template <typename T, glw::GLint S, bool N> 761 glw::GLuint BufferTest<T, S, N>::TestReferenceDataSize() 762 { 763 return static_cast<glw::GLint>(TestReferenceDataCount() * sizeof(T)); 764 } 765 766 /** @brief Create buffer textuew. 767 * 768 * @param [in] use_range_version Uses TextureBufferRange instead TextureBuffer. 769 * 770 * @return True if succeded, false otherwise. 771 */ 772 template <typename T, glw::GLint S, bool N> 773 bool BufferTest<T, S, N>::CreateBufferTexture(bool use_range_version) 774 { 775 /* Shortcut for GL functionality. */ 776 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 777 778 /* Objects creation. */ 779 gl.genTextures(1, &m_to); 780 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed"); 781 782 gl.bindTexture(GL_TEXTURE_BUFFER, m_to); 783 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed"); 784 785 gl.genBuffers(1, &m_bo); 786 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateBuffers has failed"); 787 788 gl.bindBuffer(GL_TEXTURE_BUFFER, m_bo); 789 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer has failed"); 790 791 /* Data setup. */ 792 if (use_range_version) 793 { 794 glw::GLint alignment = 1; 795 796 gl.getIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, &alignment); 797 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed"); 798 799 const glw::GLuint b_offset = alignment; 800 const glw::GLuint b_size = TestReferenceDataSize() + b_offset; 801 802 gl.bufferData(GL_TEXTURE_BUFFER, b_size, NULL, GL_STATIC_DRAW); 803 GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData has failed"); 804 805 gl.bufferSubData(GL_TEXTURE_BUFFER, b_offset, TestReferenceDataSize(), ReferenceData<T, N>()); 806 GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferSubdata has failed"); 807 808 gl.textureBufferRange(m_to, InternalFormat<T, S, N>(), m_bo, b_offset, TestReferenceDataSize()); 809 } 810 else 811 { 812 gl.bufferData(GL_TEXTURE_BUFFER, TestReferenceDataSize(), ReferenceData<T, N>(), GL_STATIC_DRAW); 813 GLU_EXPECT_NO_ERROR(gl.getError(), "glNamedBufferData has failed"); 814 815 gl.textureBuffer(m_to, InternalFormat<T, S, N>(), m_bo); 816 } 817 818 /* Error checking. */ 819 glw::GLenum error; 820 821 if (GL_NO_ERROR != (error = gl.getError())) 822 { 823 /* Log. */ 824 m_context.getTestContext().getLog() 825 << tcu::TestLog::Message << (use_range_version ? ("glTextureBufferRange") : ("glTextureBuffer")) 826 << " unexpectedly generated error " << glu::getErrorStr(error) << " during test of internal format " 827 << glu::getTextureFormatStr(InternalFormat<T, S, N>()) << "." << tcu::TestLog::EndMessage; 828 829 CleanBufferTexture(); 830 831 return false; 832 } 833 834 return true; 835 } 836 837 /** @brief Function prepares framebuffer with internal format color attachment. 838 * Viewport is set up. Content of the framebuffer is cleared. 839 * 840 * @note The function may throw if unexpected error has occured. 841 * 842 * @return if the framebuffer returned is supported 843 */ 844 template <typename T, glw::GLint S, bool N> 845 bool BufferTest<T, S, N>::PrepareFramebuffer(const glw::GLenum internal_format) 846 { 847 /* Shortcut for GL functionality. */ 848 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 849 850 /* Prepare framebuffer. */ 851 gl.genFramebuffers(1, &m_fbo); 852 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed."); 853 854 gl.genRenderbuffers(1, &m_rbo); 855 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed."); 856 857 gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo); 858 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed."); 859 860 gl.bindRenderbuffer(GL_RENDERBUFFER, m_rbo); 861 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed."); 862 863 gl.renderbufferStorage(GL_RENDERBUFFER, internal_format, s_fbo_size_x, s_fbo_size_y); 864 GLU_EXPECT_NO_ERROR(gl.getError(), "glRenderbufferStorage call failed."); 865 866 gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_rbo); 867 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed."); 868 869 if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) 870 { 871 if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_UNSUPPORTED) 872 throw tcu::NotSupportedError("unsupported framebuffer configuration"); 873 else 874 throw 0; 875 } 876 877 gl.viewport(0, 0, s_fbo_size_x, s_fbo_size_y); 878 GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed."); 879 880 /* Clear framebuffer's content. */ 881 gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f); 882 GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed."); 883 884 gl.clear(GL_COLOR_BUFFER_BIT); 885 GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed."); 886 887 return true; 888 } 889 890 /** @brief Create program. 891 * 892 * @param [in] variable_declaration Choose variable declaration of the fragment shader. 893 */ 894 template <typename T, glw::GLint S, bool N> 895 void BufferTest<T, S, N>::PrepareProgram(const glw::GLchar* variable_declaration) 896 { 897 /* Shortcut for GL functionality */ 898 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 899 900 struct Shader 901 { 902 glw::GLchar const* source[3]; 903 glw::GLsizei const count; 904 glw::GLenum const type; 905 glw::GLuint id; 906 } shader[] = { 907 { { s_vertex_shader, NULL, NULL }, 1, GL_VERTEX_SHADER, 0 }, 908 { { s_fragment_shader_head, variable_declaration, s_fragment_shader_tail }, 3, GL_FRAGMENT_SHADER, 0 } 909 }; 910 911 glw::GLuint const shader_count = sizeof(shader) / sizeof(shader[0]); 912 913 try 914 { 915 /* Create program. */ 916 m_po = gl.createProgram(); 917 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateProgram call failed."); 918 919 /* Shader compilation. */ 920 921 for (glw::GLuint i = 0; i < shader_count; ++i) 922 { 923 { 924 shader[i].id = gl.createShader(shader[i].type); 925 926 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateShader call failed."); 927 928 gl.attachShader(m_po, shader[i].id); 929 930 GLU_EXPECT_NO_ERROR(gl.getError(), "glAttachShader call failed."); 931 932 gl.shaderSource(shader[i].id, shader[i].count, shader[i].source, NULL); 933 934 GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource call failed."); 935 936 gl.compileShader(shader[i].id); 937 938 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader call failed."); 939 940 glw::GLint status = GL_FALSE; 941 942 gl.getShaderiv(shader[i].id, GL_COMPILE_STATUS, &status); 943 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed."); 944 945 if (GL_FALSE == status) 946 { 947 glw::GLint log_size = 0; 948 gl.getShaderiv(shader[i].id, GL_INFO_LOG_LENGTH, &log_size); 949 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed."); 950 951 glw::GLchar* log_text = new glw::GLchar[log_size]; 952 953 gl.getShaderInfoLog(shader[i].id, log_size, NULL, &log_text[0]); 954 955 m_context.getTestContext().getLog() 956 << tcu::TestLog::Message << "Shader compilation has failed.\n" 957 << "Shader type: " << glu::getShaderTypeStr(shader[i].type) << "\n" 958 << "Shader compilation error log:\n" 959 << log_text << "\n" 960 << "Shader source code:\n" 961 << shader[i].source[0] << (shader[i].source[1] ? shader[i].source[1] : "") 962 << (shader[i].source[2] ? shader[i].source[2] : "") << "\n" 963 << tcu::TestLog::EndMessage; 964 965 delete[] log_text; 966 967 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog call failed."); 968 969 throw 0; 970 } 971 } 972 } 973 974 /* Link. */ 975 gl.linkProgram(m_po); 976 977 GLU_EXPECT_NO_ERROR(gl.getError(), "glTransformFeedbackVaryings call failed."); 978 979 glw::GLint status = GL_FALSE; 980 981 gl.getProgramiv(m_po, GL_LINK_STATUS, &status); 982 983 if (GL_TRUE == status) 984 { 985 for (glw::GLuint i = 0; i < shader_count; ++i) 986 { 987 if (shader[i].id) 988 { 989 gl.detachShader(m_po, shader[i].id); 990 991 GLU_EXPECT_NO_ERROR(gl.getError(), "glDetachShader call failed."); 992 } 993 } 994 } 995 else 996 { 997 glw::GLint log_size = 0; 998 999 gl.getProgramiv(m_po, GL_INFO_LOG_LENGTH, &log_size); 1000 1001 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv call failed."); 1002 1003 glw::GLchar* log_text = new glw::GLchar[log_size]; 1004 1005 gl.getProgramInfoLog(m_po, log_size, NULL, &log_text[0]); 1006 1007 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Program linkage has failed due to:\n" 1008 << log_text << "\n" 1009 << tcu::TestLog::EndMessage; 1010 1011 delete[] log_text; 1012 1013 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramInfoLog call failed."); 1014 1015 throw 0; 1016 } 1017 } 1018 catch (...) 1019 { 1020 if (m_po) 1021 { 1022 gl.deleteProgram(m_po); 1023 1024 m_po = 0; 1025 } 1026 } 1027 1028 for (glw::GLuint i = 0; i < shader_count; ++i) 1029 { 1030 if (0 != shader[i].id) 1031 { 1032 gl.deleteShader(shader[i].id); 1033 1034 shader[i].id = 0; 1035 } 1036 } 1037 1038 if (0 == m_po) 1039 { 1040 throw 0; 1041 } 1042 } 1043 1044 /** @brief Create VAO. 1045 */ 1046 template <typename T, glw::GLint S, bool N> 1047 void BufferTest<T, S, N>::PrepareVertexArray() 1048 { 1049 /* Shortcut for GL functionality. */ 1050 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 1051 1052 gl.genVertexArrays(1, &m_vao); 1053 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays has failed"); 1054 1055 gl.bindVertexArray(m_vao); 1056 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray has failed"); 1057 } 1058 1059 /** @brief Test's draw function. 1060 */ 1061 template <typename T, glw::GLint S, bool N> 1062 void BufferTest<T, S, N>::Draw() 1063 { 1064 /* Shortcut for GL functionality. */ 1065 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 1066 1067 gl.useProgram(m_po); 1068 GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed"); 1069 1070 gl.activeTexture(GL_TEXTURE0); 1071 GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed"); 1072 1073 gl.bindTextureUnit(0, m_to); 1074 GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed"); 1075 1076 gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4); 1077 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed"); 1078 } 1079 1080 /** @brief Compre results with the reference. 1081 * 1082 * @return True if equal, false otherwise. 1083 */ 1084 template <typename T, glw::GLint S, bool N> 1085 bool BufferTest<T, S, N>::Check() 1086 { 1087 /* Shortcut for GL functionality. */ 1088 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 1089 1090 /* Fetching data. */ 1091 std::vector<T> result(TestReferenceDataCount()); 1092 1093 gl.pixelStorei(GL_UNPACK_ALIGNMENT, sizeof(T)); 1094 GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed"); 1095 1096 gl.pixelStorei(GL_PACK_ALIGNMENT, sizeof(T)); 1097 GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed"); 1098 1099 gl.readnPixels(0, 0, s_fbo_size_x, s_fbo_size_y, Format<S, N>(), Type<T>(), TestReferenceDataSize(), 1100 (glw::GLvoid*)(&result[0])); 1101 GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels has failed"); 1102 1103 /* Comparison. */ 1104 bool is_ok = true; 1105 1106 for (glw::GLuint i = 0; i < TestReferenceDataCount(); ++i) 1107 { 1108 if (!Compare<T>(result[i], ReferenceData<T, N>()[i])) 1109 { 1110 is_ok = false; 1111 1112 break; 1113 } 1114 } 1115 1116 return is_ok; 1117 } 1118 1119 /** @brief Test function. 1120 * 1121 * @param [in] use_range_version Uses TextureBufferRange instead TextureBuffer. 1122 * 1123 * @return True if succeeded, false otherwise. 1124 */ 1125 template <typename T, glw::GLint S, bool N> 1126 bool BufferTest<T, S, N>::Test(bool use_range_version) 1127 { 1128 /* Setup. */ 1129 if (!PrepareFramebuffer(InternalFormat<T, S, N>())) 1130 { 1131 /** 1132 * If the framebuffer it not supported, means that the 1133 * tested combination is unsupported for this driver, 1134 * but allowed to be unsupported by OpenGL spec, so we 1135 * just skip. 1136 */ 1137 CleanFramebuffer(); 1138 CleanErrors(); 1139 1140 return true; 1141 } 1142 1143 if (!CreateBufferTexture(use_range_version)) 1144 { 1145 CleanFramebuffer(); 1146 CleanErrors(); 1147 1148 return false; 1149 } 1150 1151 /* Action. */ 1152 Draw(); 1153 1154 /* Compare results with reference. */ 1155 bool result = Check(); 1156 1157 /* Cleanup. */ 1158 CleanFramebuffer(); 1159 CleanBufferTexture(); 1160 CleanErrors(); 1161 1162 /* Pass result. */ 1163 return result; 1164 } 1165 1166 /** @brief Clean GL objects 1167 */ 1168 template <typename T, glw::GLint S, bool N> 1169 void BufferTest<T, S, N>::CleanBufferTexture() 1170 { 1171 /* Shortcut for GL functionality. */ 1172 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 1173 1174 /* Texture. */ 1175 if (m_to) 1176 { 1177 gl.deleteTextures(1, &m_to); 1178 1179 m_to = 0; 1180 } 1181 1182 /* Texture buffer. */ 1183 if (m_bo) 1184 { 1185 gl.deleteBuffers(1, &m_bo); 1186 1187 m_bo = 0; 1188 } 1189 } 1190 1191 /** @brief Clean GL objects 1192 */ 1193 template <typename T, glw::GLint S, bool N> 1194 void BufferTest<T, S, N>::CleanFramebuffer() 1195 { 1196 /* Shortcut for GL functionality. */ 1197 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 1198 1199 /* Framebuffer. */ 1200 if (m_fbo) 1201 { 1202 gl.deleteFramebuffers(1, &m_fbo); 1203 1204 m_fbo = 0; 1205 } 1206 1207 /* Renderbuffer. */ 1208 if (m_rbo) 1209 { 1210 gl.deleteRenderbuffers(1, &m_rbo); 1211 1212 m_rbo = 0; 1213 } 1214 } 1215 1216 /** @brief Clean GL objects 1217 */ 1218 template <typename T, glw::GLint S, bool N> 1219 void BufferTest<T, S, N>::CleanProgram() 1220 { 1221 /* Shortcut for GL functionality. */ 1222 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 1223 1224 /* Program. */ 1225 if (m_po) 1226 { 1227 gl.useProgram(0); 1228 1229 gl.deleteProgram(m_po); 1230 1231 m_po = 0; 1232 } 1233 } 1234 1235 /** @brief Clean errors. 1236 */ 1237 template <typename T, glw::GLint S, bool N> 1238 void BufferTest<T, S, N>::CleanErrors() 1239 { 1240 /* Shortcut for GL functionality. */ 1241 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 1242 1243 /* Query all errors until GL_NO_ERROR occure. */ 1244 while (GL_NO_ERROR != gl.getError()) 1245 ; 1246 } 1247 1248 /** @brief Clean GL objects 1249 */ 1250 template <typename T, glw::GLint S, bool N> 1251 void BufferTest<T, S, N>::CleanVertexArray() 1252 { 1253 /* Shortcut for GL functionality. */ 1254 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 1255 1256 if (m_vao) 1257 { 1258 gl.bindVertexArray(0); 1259 1260 gl.deleteVertexArrays(1, &m_vao); 1261 1262 m_vao = 0; 1263 } 1264 } 1265 1266 /** @brief Iterate Buffer Test cases. 1267 * 1268 * @return Iteration result. 1269 */ 1270 template <typename T, glw::GLint S, bool N> 1271 tcu::TestNode::IterateResult BufferTest<T, S, N>::iterate() 1272 { 1273 /* Shortcut for GL functionality. */ 1274 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 1275 1276 /* Get context setup. */ 1277 bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5))); 1278 bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access"); 1279 1280 if ((!is_at_least_gl_45) && (!is_arb_direct_state_access)) 1281 { 1282 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported"); 1283 1284 return STOP; 1285 } 1286 1287 /* Running tests. */ 1288 bool is_ok = true; 1289 bool is_error = false; 1290 1291 try 1292 { 1293 PrepareVertexArray(); 1294 1295 PrepareProgram(FragmentShaderDeclaration()); 1296 1297 for (glw::GLuint i = 0; i < 2; ++i) 1298 { 1299 bool use_range = (i == 1); 1300 is_ok &= Test(use_range); 1301 CleanErrors(); 1302 } 1303 1304 CleanProgram(); 1305 } 1306 catch (tcu::NotSupportedError e) 1307 { 1308 throw e; 1309 } 1310 catch (...) 1311 { 1312 is_ok = false; 1313 is_error = true; 1314 } 1315 1316 /* Cleanup. */ 1317 CleanBufferTexture(); 1318 CleanFramebuffer(); 1319 CleanProgram(); 1320 CleanErrors(); 1321 CleanVertexArray(); 1322 1323 /* Errors clean up. */ 1324 while (gl.getError()) 1325 ; 1326 1327 /* Result's setup. */ 1328 if (is_ok) 1329 { 1330 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 1331 } 1332 else 1333 { 1334 if (is_error) 1335 { 1336 m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error"); 1337 } 1338 else 1339 { 1340 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); 1341 } 1342 } 1343 1344 return STOP; 1345 } 1346 1347 /* Vertex shader source code. */ 1348 template <typename T, glw::GLint S, bool N> 1349 const glw::GLchar* BufferTest<T, S, N>::s_vertex_shader = "#version 450\n" 1350 "\n" 1351 "void main()\n" 1352 "{\n" 1353 " switch(gl_VertexID)\n" 1354 " {\n" 1355 " case 0:\n" 1356 " gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n" 1357 " break;\n" 1358 " case 1:\n" 1359 " gl_Position = vec4( 1.0, 1.0, 0.0, 1.0);\n" 1360 " break;\n" 1361 " case 2:\n" 1362 " gl_Position = vec4(-1.0,-1.0, 0.0, 1.0);\n" 1363 " break;\n" 1364 " case 3:\n" 1365 " gl_Position = vec4( 1.0,-1.0, 0.0, 1.0);\n" 1366 " break;\n" 1367 " }\n" 1368 "}\n"; 1369 1370 /* Fragment shader source program. */ 1371 template <typename T, glw::GLint S, bool N> 1372 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_head = "#version 450\n" 1373 "\n" 1374 "layout(pixel_center_integer) in vec4 gl_FragCoord;\n" 1375 "\n"; 1376 1377 template <typename T, glw::GLint S, bool N> 1378 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_fdecl_lowp = "uniform samplerBuffer texture_input;\n" 1379 "out vec4 texture_output;\n"; 1380 1381 template <typename T, glw::GLint S, bool N> 1382 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_idecl_lowp = "uniform isamplerBuffer texture_input;\n" 1383 "out ivec4 texture_output;\n"; 1384 1385 template <typename T, glw::GLint S, bool N> 1386 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_udecl_lowp = "uniform usamplerBuffer texture_input;\n" 1387 "out uvec4 texture_output;\n"; 1388 1389 template <typename T, glw::GLint S, bool N> 1390 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_fdecl_mediump = "uniform samplerBuffer texture_input;\n" 1391 "out vec4 texture_output;\n"; 1392 1393 template <typename T, glw::GLint S, bool N> 1394 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_idecl_mediump = "uniform isamplerBuffer texture_input;\n" 1395 "out ivec4 texture_output;\n"; 1396 1397 template <typename T, glw::GLint S, bool N> 1398 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_udecl_mediump = "uniform usamplerBuffer texture_input;\n" 1399 "out uvec4 texture_output;\n"; 1400 1401 template <typename T, glw::GLint S, bool N> 1402 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_fdecl_highp = "uniform samplerBuffer texture_input;\n" 1403 "out vec4 texture_output;\n"; 1404 1405 template <typename T, glw::GLint S, bool N> 1406 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_idecl_highp = "uniform isamplerBuffer texture_input;\n" 1407 "out ivec4 texture_output;\n"; 1408 1409 template <typename T, glw::GLint S, bool N> 1410 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_udecl_highp = "uniform usamplerBuffer texture_input;\n" 1411 "out uvec4 texture_output;\n"; 1412 1413 template <typename T, glw::GLint S, bool N> 1414 const glw::GLchar* BufferTest<T, S, N>::s_fragment_shader_tail = 1415 "\n" 1416 "void main()\n" 1417 "{\n" 1418 " texture_output = texelFetch(texture_input, int(gl_FragCoord.x));\n" 1419 "}\n"; 1420 1421 template class BufferTest<glw::GLbyte, 1, false>; 1422 template class BufferTest<glw::GLbyte, 2, false>; 1423 template class BufferTest<glw::GLbyte, 4, false>; 1424 1425 template class BufferTest<glw::GLubyte, 1, false>; 1426 template class BufferTest<glw::GLubyte, 2, false>; 1427 template class BufferTest<glw::GLubyte, 4, false>; 1428 template class BufferTest<glw::GLubyte, 1, true>; 1429 template class BufferTest<glw::GLubyte, 2, true>; 1430 template class BufferTest<glw::GLubyte, 4, true>; 1431 1432 template class BufferTest<glw::GLshort, 1, false>; 1433 template class BufferTest<glw::GLshort, 2, false>; 1434 template class BufferTest<glw::GLshort, 4, false>; 1435 1436 template class BufferTest<glw::GLushort, 1, false>; 1437 template class BufferTest<glw::GLushort, 2, false>; 1438 template class BufferTest<glw::GLushort, 4, false>; 1439 template class BufferTest<glw::GLushort, 1, true>; 1440 template class BufferTest<glw::GLushort, 2, true>; 1441 template class BufferTest<glw::GLushort, 4, true>; 1442 1443 template class BufferTest<glw::GLint, 1, false>; 1444 template class BufferTest<glw::GLint, 2, false>; 1445 template class BufferTest<glw::GLint, 3, false>; 1446 template class BufferTest<glw::GLint, 4, false>; 1447 1448 template class BufferTest<glw::GLuint, 1, false>; 1449 template class BufferTest<glw::GLuint, 2, false>; 1450 template class BufferTest<glw::GLuint, 3, false>; 1451 template class BufferTest<glw::GLuint, 4, false>; 1452 1453 template class BufferTest<glw::GLfloat, 1, true>; 1454 template class BufferTest<glw::GLfloat, 2, true>; 1455 template class BufferTest<glw::GLfloat, 3, true>; 1456 template class BufferTest<glw::GLfloat, 4, true>; 1457 1458 /******************************** Storage and SubImage Test Implementation ********************************/ 1459 1460 /** @brief Storage Test constructor. 1461 * 1462 * @tparam T Type. 1463 * @tparam S Size. 1464 * @tparam N Is normalized. 1465 * @tparam D Texture dimension. 1466 * @tparam I Choose between SubImage and Storage tests. 1467 * 1468 * @param [in] context OpenGL context. 1469 * @param [in] name Name of the test. 1470 */ 1471 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 1472 StorageAndSubImageTest<T, S, N, D, I>::StorageAndSubImageTest(deqp::Context& context, const char* name) 1473 : deqp::TestCase(context, name, "Texture Storage and SubImage Test") 1474 , m_fbo(0) 1475 , m_rbo(0) 1476 , m_po(0) 1477 , m_to(0) 1478 , m_vao(0) 1479 { 1480 /* Intentionally left blank. */ 1481 } 1482 1483 /** @brief Count of reference data to be teted. 1484 * 1485 * @return Count. 1486 */ 1487 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 1488 glw::GLuint StorageAndSubImageTest<T, S, N, D, I>::TestReferenceDataCount() 1489 { 1490 return 2 /* 1D */ * ((D > 1) ? 3 : 1) /* 2D */ * ((D > 2) ? 4 : 1) /* 3D */ * S /* components */; 1491 } 1492 1493 /** @brief Size of reference data to be teted. 1494 * 1495 * @tparam T Type. 1496 * @tparam S Size (# of components). 1497 * @tparam D Texture dimenisons. 1498 * 1499 * @return Size. 1500 */ 1501 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 1502 glw::GLuint StorageAndSubImageTest<T, S, N, D, I>::TestReferenceDataSize() 1503 { 1504 return static_cast<glw::GLint>(TestReferenceDataCount() * sizeof(T)); 1505 } 1506 1507 /** @brief Height, width or depth of reference data to be teted. 1508 * 1509 * @return Height, width or depth. 1510 */ 1511 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 1512 glw::GLuint StorageAndSubImageTest<T, S, N, D, I>::TestReferenceDataHeight() 1513 { 1514 switch (D) 1515 { 1516 case 2: 1517 case 3: 1518 return 3; 1519 default: 1520 return 1; 1521 } 1522 } 1523 1524 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 1525 glw::GLuint StorageAndSubImageTest<T, S, N, D, I>::TestReferenceDataDepth() 1526 { 1527 switch (D) 1528 { 1529 case 3: 1530 return 4; 1531 default: 1532 return 1; 1533 } 1534 } 1535 1536 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 1537 glw::GLuint StorageAndSubImageTest<T, S, N, D, I>::TestReferenceDataWidth() 1538 { 1539 return 2; 1540 } 1541 1542 /** @brief Fragment shader declaration selector. 1543 * 1544 * @return Frgment shader source code part. 1545 */ 1546 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 1547 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::FragmentShaderDeclaration() 1548 { 1549 if (typeid(T) == typeid(glw::GLbyte)) 1550 { 1551 switch (D) 1552 { 1553 case 1: 1554 return s_fragment_shader_1D_idecl_lowp; 1555 case 2: 1556 return s_fragment_shader_2D_idecl_lowp; 1557 case 3: 1558 return s_fragment_shader_3D_idecl_lowp; 1559 default: 1560 DE_ASSERT("invalid texture dimension"); 1561 return DE_NULL; 1562 } 1563 } 1564 1565 if (typeid(T) == typeid(glw::GLubyte)) 1566 { 1567 if (N) 1568 { 1569 switch (D) 1570 { 1571 case 1: 1572 return s_fragment_shader_1D_fdecl_lowp; 1573 case 2: 1574 return s_fragment_shader_2D_fdecl_lowp; 1575 case 3: 1576 return s_fragment_shader_3D_fdecl_lowp; 1577 default: 1578 DE_ASSERT("invalid texture dimension"); 1579 return DE_NULL; 1580 } 1581 } 1582 else 1583 { 1584 switch (D) 1585 { 1586 case 1: 1587 return s_fragment_shader_1D_udecl_lowp; 1588 case 2: 1589 return s_fragment_shader_2D_udecl_lowp; 1590 case 3: 1591 return s_fragment_shader_3D_udecl_lowp; 1592 default: 1593 DE_ASSERT("invalid texture dimension"); 1594 return DE_NULL; 1595 } 1596 } 1597 } 1598 1599 if (typeid(T) == typeid(glw::GLshort)) 1600 { 1601 switch (D) 1602 { 1603 case 1: 1604 return s_fragment_shader_1D_idecl_mediump; 1605 case 2: 1606 return s_fragment_shader_2D_idecl_mediump; 1607 case 3: 1608 return s_fragment_shader_3D_idecl_mediump; 1609 default: 1610 DE_ASSERT("invalid texture dimension"); 1611 return DE_NULL; 1612 } 1613 } 1614 1615 if (typeid(T) == typeid(glw::GLushort)) 1616 { 1617 if (N) 1618 { 1619 switch (D) 1620 { 1621 case 1: 1622 return s_fragment_shader_1D_fdecl_mediump; 1623 case 2: 1624 return s_fragment_shader_2D_fdecl_mediump; 1625 case 3: 1626 return s_fragment_shader_3D_fdecl_mediump; 1627 default: 1628 DE_ASSERT("invalid texture dimension"); 1629 return DE_NULL; 1630 } 1631 } 1632 else 1633 { 1634 switch (D) 1635 { 1636 case 1: 1637 return s_fragment_shader_1D_udecl_mediump; 1638 case 2: 1639 return s_fragment_shader_2D_udecl_mediump; 1640 case 3: 1641 return s_fragment_shader_3D_udecl_mediump; 1642 default: 1643 DE_ASSERT("invalid texture dimension"); 1644 return DE_NULL; 1645 } 1646 } 1647 } 1648 1649 if (typeid(T) == typeid(glw::GLint)) 1650 { 1651 switch (D) 1652 { 1653 case 1: 1654 return s_fragment_shader_1D_idecl_highp; 1655 case 2: 1656 return s_fragment_shader_2D_idecl_highp; 1657 case 3: 1658 return s_fragment_shader_3D_idecl_highp; 1659 default: 1660 DE_ASSERT("invalid texture dimension"); 1661 return DE_NULL; 1662 } 1663 } 1664 1665 if (typeid(T) == typeid(glw::GLuint)) 1666 { 1667 switch (D) 1668 { 1669 case 1: 1670 return s_fragment_shader_1D_udecl_highp; 1671 case 2: 1672 return s_fragment_shader_2D_udecl_highp; 1673 case 3: 1674 return s_fragment_shader_3D_udecl_highp; 1675 default: 1676 DE_ASSERT("invalid texture dimension"); 1677 return DE_NULL; 1678 } 1679 } 1680 1681 switch (D) 1682 { 1683 case 1: 1684 return s_fragment_shader_1D_fdecl_highp; 1685 case 2: 1686 return s_fragment_shader_2D_fdecl_highp; 1687 case 3: 1688 return s_fragment_shader_3D_fdecl_highp; 1689 default: 1690 DE_ASSERT("invalid texture dimension"); 1691 return DE_NULL; 1692 } 1693 } 1694 1695 /** @brief Fragment shader tail selector. 1696 * 1697 * @tparam D Texture dimenisons. 1698 * 1699 * @return Frgment shader source code part. 1700 */ 1701 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 1702 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::FragmentShaderTail() 1703 { 1704 switch (D) 1705 { 1706 case 1: 1707 return s_fragment_shader_1D_tail; 1708 case 2: 1709 return s_fragment_shader_2D_tail; 1710 case 3: 1711 return s_fragment_shader_3D_tail; 1712 default: 1713 DE_ASSERT("invalid texture dimension"); 1714 return DE_NULL; 1715 } 1716 } 1717 1718 /** @brief Texture target selector. 1719 * 1720 * @tparam D Texture dimenisons. 1721 * 1722 * @return Texture target. 1723 */ 1724 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 1725 glw::GLenum StorageAndSubImageTest<T, S, N, D, I>::TextureTarget() 1726 { 1727 switch (D) 1728 { 1729 case 1: 1730 return GL_TEXTURE_1D; 1731 case 2: 1732 return GL_TEXTURE_2D; 1733 case 3: 1734 return GL_TEXTURE_3D; 1735 default: 1736 DE_ASSERT("invalid texture dimension"); 1737 return DE_NULL; 1738 } 1739 } 1740 1741 /** @brief TextureStorage* wrapper. 1742 * 1743 * @return true if succeed (in legacy always or throw), false otherwise. 1744 */ 1745 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 1746 bool StorageAndSubImageTest<T, S, N, D, I>::TextureStorage(glw::GLenum target, glw::GLuint texture, glw::GLsizei levels, 1747 glw::GLenum internalformat, glw::GLsizei width, 1748 glw::GLsizei height, glw::GLsizei depth) 1749 { 1750 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 1751 1752 if (I) 1753 { 1754 switch (D) 1755 { 1756 case 1: 1757 gl.texStorage1D(target, levels, internalformat, width); 1758 break; 1759 case 2: 1760 gl.texStorage2D(target, levels, internalformat, width, height); 1761 break; 1762 case 3: 1763 gl.texStorage3D(target, levels, internalformat, width, height, depth); 1764 break; 1765 default: 1766 DE_ASSERT("invalid texture dimension"); 1767 } 1768 1769 /* TextureSubImage* (not TextureStorage*) is tested */ 1770 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexStorage*() has failed"); 1771 return true; 1772 } 1773 else 1774 { 1775 switch (D) 1776 { 1777 case 1: 1778 gl.textureStorage1D(texture, levels, internalformat, width); 1779 break; 1780 case 2: 1781 gl.textureStorage2D(texture, levels, internalformat, width, height); 1782 break; 1783 case 3: 1784 gl.textureStorage3D(texture, levels, internalformat, width, height, depth); 1785 break; 1786 default: 1787 DE_ASSERT("invalid texture dimension"); 1788 } 1789 1790 glw::GLenum error; 1791 if (GL_NO_ERROR != (error = gl.getError())) 1792 { 1793 m_context.getTestContext().getLog() 1794 << tcu::TestLog::Message << "glTextureStorage" << D << "D unexpectedly generated error " << glu::getErrorStr(error) 1795 << " during test with levels " << levels << ", internal format " << internalformat 1796 << " width=" << width << " height=" << height << " depth=" << depth 1797 << "." << tcu::TestLog::EndMessage; 1798 1799 CleanTexture(); 1800 CleanErrors(); 1801 1802 return false; 1803 } 1804 1805 return true; 1806 } 1807 } 1808 1809 /** @brief TextureSubImage* wrapper. 1810 * 1811 * @return true if suuceed (in legacy always or throw), false otherwise. 1812 */ 1813 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 1814 bool StorageAndSubImageTest<T, S, N, D, I>::TextureSubImage(glw::GLenum target, glw::GLuint texture, glw::GLint level, 1815 glw::GLsizei width, glw::GLsizei height, glw::GLsizei depth, 1816 glw::GLenum format, glw::GLenum type, const glw::GLvoid* data) 1817 { 1818 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 1819 1820 if (I) 1821 { 1822 switch (D) 1823 { 1824 case 1: 1825 gl.textureSubImage1D(texture, level, 0, width, format, type, data); 1826 break; 1827 case 2: 1828 gl.textureSubImage2D(texture, level, 0, 0, width, height, format, type, data); 1829 break; 1830 case 3: 1831 gl.textureSubImage3D(texture, level, 0, 0, 0, width, height, depth, format, type, data); 1832 break; 1833 default: 1834 DE_ASSERT("invalid texture dimension"); 1835 } 1836 1837 glw::GLenum error; 1838 if (GL_NO_ERROR != (error = gl.getError())) 1839 { 1840 m_context.getTestContext().getLog() 1841 << tcu::TestLog::Message << "glTextureSubImage" << D << "D unexpectedly generated error " << glu::getErrorStr(error) 1842 << " during test with level " << level << ", width=" << width << ", height=" << height << ", depth=" << depth 1843 << " format " << glu::getTextureFormatStr(format) << " and type " << glu::getTypeStr(type) << "." 1844 << tcu::TestLog::EndMessage; 1845 1846 CleanTexture(); 1847 CleanErrors(); 1848 1849 return false; 1850 } 1851 1852 return true; 1853 } 1854 else 1855 { 1856 switch (D) 1857 { 1858 case 1: 1859 gl.texSubImage1D(target, level, 0, width, format, type, data); 1860 break; 1861 case 2: 1862 gl.texSubImage2D(target, level, 0, 0, width, height, format, type, data); 1863 break; 1864 case 3: 1865 gl.texSubImage3D(target, level, 0, 0, 0, width, height, depth, format, type, data); 1866 break; 1867 default: 1868 DE_ASSERT("invalid texture dimension"); 1869 } 1870 1871 /* TextureStorage* (not TextureSubImage) is tested */ 1872 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexSubImage*() has failed"); 1873 return true; 1874 } 1875 } 1876 1877 /** @brief Create texture. 1878 * 1879 * @tparam T Type. 1880 * @tparam S Size (# of components). 1881 * @tparam N Is normalized. 1882 * @tparam D Dimmensions. 1883 * @tparam I Test SubImage or Storage. 1884 * 1885 * @return True if succeded, false otherwise. 1886 */ 1887 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 1888 bool StorageAndSubImageTest<T, S, N, D, I>::CreateTexture() 1889 { 1890 /* Shortcut for GL functionality. */ 1891 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 1892 1893 /* Objects creation. */ 1894 gl.genTextures(1, &m_to); 1895 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed"); 1896 1897 gl.bindTexture(TextureTarget(), m_to); 1898 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed"); 1899 1900 /* Storage creation. */ 1901 if (TextureStorage(TextureTarget(), m_to, 1, InternalFormat<T, S, N>(), TestReferenceDataWidth(), 1902 TestReferenceDataHeight(), TestReferenceDataDepth())) 1903 { 1904 /* Data setup. */ 1905 if (TextureSubImage(TextureTarget(), m_to, 0, TestReferenceDataWidth(), TestReferenceDataHeight(), TestReferenceDataDepth(), 1906 Format<S, N>(), Type<T>(), ReferenceData<T, N>())) 1907 { 1908 glTexParameteri(TextureTarget(), GL_TEXTURE_MIN_FILTER, GL_NEAREST); 1909 glTexParameteri(TextureTarget(), GL_TEXTURE_MAG_FILTER, GL_NEAREST); 1910 return true; 1911 } 1912 } 1913 1914 CleanTexture(); 1915 1916 return false; 1917 } 1918 1919 /** @brief Compre results with the reference. 1920 * 1921 * @return True if equal, false otherwise. 1922 */ 1923 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 1924 bool StorageAndSubImageTest<T, S, N, D, I>::Check() 1925 { 1926 /* Shortcut for GL functionality. */ 1927 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 1928 1929 /* Fetching data. */ 1930 std::vector<T> result(TestReferenceDataCount()); 1931 1932 glw::GLuint fbo_size_x = 0; 1933 1934 switch (D) 1935 { 1936 case 1: 1937 fbo_size_x = 2; 1938 break; 1939 case 2: 1940 fbo_size_x = 2 * 3; 1941 break; 1942 case 3: 1943 fbo_size_x = 2 * 3 * 4; 1944 break; 1945 default: 1946 throw 0; 1947 } 1948 1949 gl.readnPixels(0, 0, fbo_size_x, 1, Format<S, N>(), Type<T>(), TestReferenceDataSize(), 1950 (glw::GLvoid*)(&result[0])); 1951 GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels has failed"); 1952 1953 /* Comparison. */ 1954 for (glw::GLuint i = 0; i < TestReferenceDataCount(); ++i) 1955 { 1956 if (!Compare<T>(result[i], ReferenceData<T, N>()[i])) 1957 { 1958 return false; 1959 } 1960 } 1961 1962 return true; 1963 } 1964 1965 /** @brief Test case function. 1966 * 1967 * @return True if test succeeded, false otherwise. 1968 */ 1969 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 1970 bool StorageAndSubImageTest<T, S, N, D, I>::Test() 1971 { 1972 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 1973 1974 gl.pixelStorei(GL_UNPACK_ALIGNMENT, sizeof(T)); 1975 GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed"); 1976 1977 gl.pixelStorei(GL_PACK_ALIGNMENT, sizeof(T)); 1978 GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed"); 1979 1980 /* Setup. */ 1981 PrepareFramebuffer(InternalFormat<T, S, N>()); 1982 1983 if (!CreateTexture()) 1984 { 1985 return false; 1986 } 1987 1988 /* Action. */ 1989 Draw(); 1990 1991 /* Compare results with reference. */ 1992 bool result = Check(); 1993 1994 /* Cleanup. */ 1995 CleanTexture(); 1996 CleanFramebuffer(); 1997 CleanErrors(); 1998 1999 /* Pass result. */ 2000 return result; 2001 } 2002 2003 /** @brief Function prepares framebuffer with internal format color attachment. 2004 * Viewport is set up. Content of the framebuffer is cleared. 2005 * 2006 * @note The function may throw if unexpected error has occured. 2007 */ 2008 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2009 void StorageAndSubImageTest<T, S, N, D, I>::PrepareFramebuffer(const glw::GLenum internal_format) 2010 { 2011 /* Shortcut for GL functionality. */ 2012 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 2013 2014 /* Prepare framebuffer. */ 2015 gl.genFramebuffers(1, &m_fbo); 2016 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed."); 2017 2018 gl.genRenderbuffers(1, &m_rbo); 2019 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed."); 2020 2021 gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo); 2022 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed."); 2023 2024 gl.bindRenderbuffer(GL_RENDERBUFFER, m_rbo); 2025 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed."); 2026 2027 glw::GLuint fbo_size_x = 0; 2028 2029 switch (D) 2030 { 2031 case 1: 2032 fbo_size_x = 2; 2033 break; 2034 case 2: 2035 fbo_size_x = 2 * 3; 2036 break; 2037 case 3: 2038 fbo_size_x = 2 * 3 * 4; 2039 break; 2040 default: 2041 throw 0; 2042 } 2043 2044 gl.renderbufferStorage(GL_RENDERBUFFER, internal_format, fbo_size_x, 1); 2045 GLU_EXPECT_NO_ERROR(gl.getError(), "glRenderbufferStorage call failed."); 2046 2047 gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_rbo); 2048 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed."); 2049 2050 if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) 2051 { 2052 if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_UNSUPPORTED) 2053 throw tcu::NotSupportedError("unsupported framebuffer configuration"); 2054 else 2055 throw 0; 2056 } 2057 2058 gl.viewport(0, 0, fbo_size_x, 1); 2059 GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed."); 2060 2061 /* Clear framebuffer's content. */ 2062 gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f); 2063 GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed."); 2064 2065 gl.clear(GL_COLOR_BUFFER_BIT); 2066 GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed."); 2067 } 2068 2069 /** @brief Prepare program 2070 * 2071 * @param [in] variable_declaration Variables declaration part of fragment shader source code. 2072 * @param [in] tail Tail part of fragment shader source code. 2073 */ 2074 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2075 void StorageAndSubImageTest<T, S, N, D, I>::PrepareProgram(const glw::GLchar* variable_declaration, const glw::GLchar* tail) 2076 { 2077 /* Shortcut for GL functionality */ 2078 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 2079 2080 struct Shader 2081 { 2082 glw::GLchar const* source[3]; 2083 glw::GLsizei const count; 2084 glw::GLenum const type; 2085 glw::GLuint id; 2086 } shader[] = { { { s_vertex_shader, NULL, NULL }, 1, GL_VERTEX_SHADER, 0 }, 2087 { { s_fragment_shader_head, variable_declaration, tail }, 3, GL_FRAGMENT_SHADER, 0 } }; 2088 2089 glw::GLuint const shader_count = sizeof(shader) / sizeof(shader[0]); 2090 2091 try 2092 { 2093 /* Create program. */ 2094 m_po = gl.createProgram(); 2095 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateProgram call failed."); 2096 2097 /* Shader compilation. */ 2098 2099 for (glw::GLuint i = 0; i < shader_count; ++i) 2100 { 2101 { 2102 shader[i].id = gl.createShader(shader[i].type); 2103 2104 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateShader call failed."); 2105 2106 gl.attachShader(m_po, shader[i].id); 2107 2108 GLU_EXPECT_NO_ERROR(gl.getError(), "glAttachShader call failed."); 2109 2110 gl.shaderSource(shader[i].id, shader[i].count, shader[i].source, NULL); 2111 2112 GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource call failed."); 2113 2114 gl.compileShader(shader[i].id); 2115 2116 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader call failed."); 2117 2118 glw::GLint status = GL_FALSE; 2119 2120 gl.getShaderiv(shader[i].id, GL_COMPILE_STATUS, &status); 2121 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed."); 2122 2123 if (GL_FALSE == status) 2124 { 2125 glw::GLint log_size = 0; 2126 gl.getShaderiv(shader[i].id, GL_INFO_LOG_LENGTH, &log_size); 2127 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed."); 2128 2129 glw::GLchar* log_text = new glw::GLchar[log_size]; 2130 2131 gl.getShaderInfoLog(shader[i].id, log_size, NULL, &log_text[0]); 2132 2133 m_context.getTestContext().getLog() 2134 << tcu::TestLog::Message << "Shader compilation has failed.\n" 2135 << "Shader type: " << glu::getShaderTypeStr(shader[i].type) << "\n" 2136 << "Shader compilation error log:\n" 2137 << log_text << "\n" 2138 << "Shader source code:\n" 2139 << shader[i].source[0] << (shader[i].source[1] ? shader[i].source[1] : "") 2140 << (shader[i].source[2] ? shader[i].source[2] : "") << "\n" 2141 << tcu::TestLog::EndMessage; 2142 2143 delete[] log_text; 2144 2145 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog call failed."); 2146 2147 throw 0; 2148 } 2149 } 2150 } 2151 2152 /* Link. */ 2153 gl.linkProgram(m_po); 2154 2155 GLU_EXPECT_NO_ERROR(gl.getError(), "glTransformFeedbackVaryings call failed."); 2156 2157 glw::GLint status = GL_FALSE; 2158 2159 gl.getProgramiv(m_po, GL_LINK_STATUS, &status); 2160 2161 if (GL_TRUE == status) 2162 { 2163 for (glw::GLuint i = 0; i < shader_count; ++i) 2164 { 2165 if (shader[i].id) 2166 { 2167 gl.detachShader(m_po, shader[i].id); 2168 2169 GLU_EXPECT_NO_ERROR(gl.getError(), "glDetachShader call failed."); 2170 } 2171 } 2172 } 2173 else 2174 { 2175 glw::GLint log_size = 0; 2176 2177 gl.getProgramiv(m_po, GL_INFO_LOG_LENGTH, &log_size); 2178 2179 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv call failed."); 2180 2181 glw::GLchar* log_text = new glw::GLchar[log_size]; 2182 2183 gl.getProgramInfoLog(m_po, log_size, NULL, &log_text[0]); 2184 2185 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Program linkage has failed due to:\n" 2186 << log_text << "\n" 2187 << tcu::TestLog::EndMessage; 2188 2189 delete[] log_text; 2190 2191 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramInfoLog call failed."); 2192 2193 throw 0; 2194 } 2195 } 2196 catch (...) 2197 { 2198 if (m_po) 2199 { 2200 gl.deleteProgram(m_po); 2201 2202 m_po = 0; 2203 } 2204 } 2205 2206 for (glw::GLuint i = 0; i < shader_count; ++i) 2207 { 2208 if (0 != shader[i].id) 2209 { 2210 gl.deleteShader(shader[i].id); 2211 2212 shader[i].id = 0; 2213 } 2214 } 2215 2216 if (0 == m_po) 2217 { 2218 throw 0; 2219 } 2220 } 2221 2222 /** @brief Prepare VAO. 2223 */ 2224 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2225 void StorageAndSubImageTest<T, S, N, D, I>::PrepareVertexArray() 2226 { 2227 /* Shortcut for GL functionality. */ 2228 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 2229 2230 gl.genVertexArrays(1, &m_vao); 2231 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays has failed"); 2232 2233 gl.bindVertexArray(m_vao); 2234 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray has failed"); 2235 } 2236 2237 /** @brief Test's draw call. 2238 */ 2239 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2240 void StorageAndSubImageTest<T, S, N, D, I>::Draw() 2241 { 2242 /* Shortcut for GL functionality. */ 2243 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 2244 2245 gl.useProgram(m_po); 2246 GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed"); 2247 2248 gl.activeTexture(GL_TEXTURE0); 2249 GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed"); 2250 2251 gl.bindTextureUnit(0, m_to); 2252 GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed"); 2253 2254 gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4); 2255 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed"); 2256 } 2257 2258 /** @brief Clean GL objects, test variables and GL errors. 2259 */ 2260 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2261 void StorageAndSubImageTest<T, S, N, D, I>::CleanTexture() 2262 { 2263 /* Shortcut for GL functionality. */ 2264 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 2265 2266 /* Texture. */ 2267 if (m_to) 2268 { 2269 gl.deleteTextures(1, &m_to); 2270 2271 m_to = 0; 2272 } 2273 } 2274 2275 /** @brief Clean GL objects, test variables and GL errors. 2276 */ 2277 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2278 void StorageAndSubImageTest<T, S, N, D, I>::CleanFramebuffer() 2279 { 2280 /* Shortcut for GL functionality. */ 2281 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 2282 2283 /* Framebuffer. */ 2284 if (m_fbo) 2285 { 2286 gl.deleteFramebuffers(1, &m_fbo); 2287 2288 m_fbo = 0; 2289 } 2290 2291 /* Renderbuffer. */ 2292 if (m_rbo) 2293 { 2294 gl.deleteRenderbuffers(1, &m_rbo); 2295 2296 m_rbo = 0; 2297 } 2298 } 2299 2300 /** @brief Clean GL objects, test variables and GL errors. 2301 */ 2302 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2303 void StorageAndSubImageTest<T, S, N, D, I>::CleanProgram() 2304 { 2305 /* Shortcut for GL functionality. */ 2306 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 2307 2308 /* Program. */ 2309 if (m_po) 2310 { 2311 gl.useProgram(0); 2312 2313 gl.deleteProgram(m_po); 2314 2315 m_po = 0; 2316 } 2317 } 2318 2319 /** @brief Clean GL objects, test variables and GL errors. 2320 */ 2321 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2322 void StorageAndSubImageTest<T, S, N, D, I>::CleanErrors() 2323 { 2324 /* Shortcut for GL functionality. */ 2325 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 2326 2327 /* Query all errors until GL_NO_ERROR occure. */ 2328 while (GL_NO_ERROR != gl.getError()) 2329 ; 2330 } 2331 2332 /** @brief Clean GL objects, test variables and GL errors. 2333 */ 2334 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2335 void StorageAndSubImageTest<T, S, N, D, I>::CleanVertexArray() 2336 { 2337 /* Shortcut for GL functionality. */ 2338 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 2339 2340 if (m_vao) 2341 { 2342 gl.bindVertexArray(0); 2343 2344 gl.deleteVertexArrays(1, &m_vao); 2345 2346 m_vao = 0; 2347 } 2348 } 2349 2350 /** @brief Iterate Storage Test cases. 2351 * 2352 * @return Iteration result. 2353 */ 2354 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2355 tcu::TestNode::IterateResult StorageAndSubImageTest<T, S, N, D, I>::iterate() 2356 { 2357 /* Shortcut for GL functionality. */ 2358 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 2359 2360 /* Get context setup. */ 2361 bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5))); 2362 bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access"); 2363 2364 if ((!is_at_least_gl_45) && (!is_arb_direct_state_access)) 2365 { 2366 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported"); 2367 2368 return STOP; 2369 } 2370 2371 /* Running tests. */ 2372 bool is_ok = true; 2373 bool is_error = false; 2374 2375 try 2376 { 2377 PrepareVertexArray(); 2378 PrepareProgram(FragmentShaderDeclaration(), FragmentShaderTail()); 2379 is_ok = Test(); 2380 } 2381 catch (tcu::NotSupportedError e) 2382 { 2383 throw e; 2384 } 2385 catch (...) 2386 { 2387 is_ok = false; 2388 is_error = true; 2389 } 2390 2391 /* Cleanup. */ 2392 CleanTexture(); 2393 CleanFramebuffer(); 2394 CleanProgram(); 2395 CleanErrors(); 2396 CleanVertexArray(); 2397 2398 /* Errors clean up. */ 2399 while (gl.getError()) 2400 ; 2401 2402 /* Result's setup. */ 2403 if (is_ok) 2404 { 2405 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 2406 } 2407 else 2408 { 2409 if (is_error) 2410 { 2411 m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error"); 2412 } 2413 else 2414 { 2415 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); 2416 } 2417 } 2418 2419 return STOP; 2420 } 2421 2422 /* Vertex shader source code. */ 2423 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2424 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_vertex_shader = 2425 "#version 450\n" 2426 "\n" 2427 "void main()\n" 2428 "{\n" 2429 " switch(gl_VertexID)\n" 2430 " {\n" 2431 " case 0:\n" 2432 " gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n" 2433 " break;\n" 2434 " case 1:\n" 2435 " gl_Position = vec4( 1.0, 1.0, 0.0, 1.0);\n" 2436 " break;\n" 2437 " case 2:\n" 2438 " gl_Position = vec4(-1.0,-1.0, 0.0, 1.0);\n" 2439 " break;\n" 2440 " case 3:\n" 2441 " gl_Position = vec4( 1.0,-1.0, 0.0, 1.0);\n" 2442 " break;\n" 2443 " }\n" 2444 "}\n"; 2445 2446 /* Fragment shader source program. */ 2447 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2448 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_head = 2449 "#version 450\n" 2450 "\n" 2451 "layout(pixel_center_integer) in vec4 gl_FragCoord;\n" 2452 "\n"; 2453 2454 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2455 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_fdecl_lowp = 2456 "uniform sampler1D texture_input;\nout vec4 texture_output;\n"; 2457 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2458 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_idecl_lowp = 2459 "uniform isampler1D texture_input;\nout ivec4 texture_output;\n"; 2460 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2461 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_udecl_lowp = 2462 "uniform usampler1D texture_input;\nout uvec4 texture_output;\n"; 2463 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2464 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_fdecl_mediump = 2465 "uniform sampler1D texture_input;\nout vec4 texture_output;\n"; 2466 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2467 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_idecl_mediump = 2468 "uniform isampler1D texture_input;\nout ivec4 texture_output;\n"; 2469 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2470 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_udecl_mediump = 2471 "uniform usampler1D texture_input;\nout uvec4 texture_output;\n"; 2472 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2473 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_fdecl_highp = 2474 "uniform sampler1D texture_input;\nout vec4 texture_output;\n"; 2475 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2476 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_idecl_highp = 2477 "uniform isampler1D texture_input;\nout ivec4 texture_output;\n"; 2478 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2479 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_udecl_highp = 2480 "uniform usampler1D texture_input;\nout uvec4 texture_output;\n"; 2481 2482 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2483 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_fdecl_lowp = 2484 "uniform sampler2D texture_input;\nout vec4 texture_output;\n"; 2485 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2486 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_idecl_lowp = 2487 "uniform isampler2D texture_input;\nout ivec4 texture_output;\n"; 2488 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2489 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_udecl_lowp = 2490 "uniform usampler2D texture_input;\nout uvec4 texture_output;\n"; 2491 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2492 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_fdecl_mediump = 2493 "uniform sampler2D texture_input;\nout vec4 texture_output;\n"; 2494 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2495 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_idecl_mediump = 2496 "uniform isampler2D texture_input;\nout ivec4 texture_output;\n"; 2497 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2498 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_udecl_mediump = 2499 "uniform usampler2D texture_input;\nout uvec4 texture_output;\n"; 2500 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2501 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_fdecl_highp = 2502 "uniform sampler2D texture_input;\nout vec4 texture_output;\n"; 2503 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2504 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_idecl_highp = 2505 "uniform isampler2D texture_input;\nout ivec4 texture_output;\n"; 2506 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2507 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_udecl_highp = 2508 "uniform usampler2D texture_input;\nout uvec4 texture_output;\n"; 2509 2510 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2511 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_fdecl_lowp = 2512 "uniform sampler3D texture_input;\nout vec4 texture_output;\n"; 2513 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2514 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_idecl_lowp = 2515 "uniform isampler3D texture_input;\nout ivec4 texture_output;\n"; 2516 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2517 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_udecl_lowp = 2518 "uniform usampler3D texture_input;\nout uvec4 texture_output;\n"; 2519 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2520 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_fdecl_mediump = 2521 "uniform sampler3D texture_input;\nout vec4 texture_output;\n"; 2522 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2523 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_idecl_mediump = 2524 "uniform isampler3D texture_input;\nout ivec4 texture_output;\n"; 2525 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2526 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_udecl_mediump = 2527 "uniform usampler3D texture_input;\nout uvec4 texture_output;\n"; 2528 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2529 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_fdecl_highp = 2530 "uniform sampler3D texture_input;\nout vec4 texture_output;\n"; 2531 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2532 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_idecl_highp = 2533 "uniform isampler3D texture_input;\nout ivec4 texture_output;\n"; 2534 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2535 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_udecl_highp = 2536 "uniform usampler3D texture_input;\nout uvec4 texture_output;\n"; 2537 2538 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2539 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_1D_tail = 2540 "\n" 2541 "void main()\n" 2542 "{\n" 2543 " texture_output = texelFetch(texture_input, int(gl_FragCoord.x), 0);\n" 2544 "}\n"; 2545 2546 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2547 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_2D_tail = 2548 "\n" 2549 "void main()\n" 2550 "{\n" 2551 " texture_output = texelFetch(texture_input, ivec2(int(gl_FragCoord.x) % 2, int(floor(gl_FragCoord.x / 2))), " 2552 "0);\n" 2553 "}\n"; 2554 2555 template <typename T, glw::GLint S, bool N, glw::GLuint D, bool I> 2556 const glw::GLchar* StorageAndSubImageTest<T, S, N, D, I>::s_fragment_shader_3D_tail = 2557 "\n" 2558 "void main()\n" 2559 "{\n" 2560 " texture_output = texelFetch(texture_input, ivec3(int(gl_FragCoord.x) % 2, int(floor(gl_FragCoord.x / 2)) % 3, " 2561 "int(floor(gl_FragCoord.x / 2 / 3))), 0);\n" 2562 "}\n"; 2563 2564 template class StorageAndSubImageTest<glw::GLbyte, 1, false, 1, false>; 2565 template class StorageAndSubImageTest<glw::GLbyte, 2, false, 1, false>; 2566 template class StorageAndSubImageTest<glw::GLbyte, 4, false, 1, false>; 2567 template class StorageAndSubImageTest<glw::GLbyte, 1, false, 2, false>; 2568 template class StorageAndSubImageTest<glw::GLbyte, 2, false, 2, false>; 2569 template class StorageAndSubImageTest<glw::GLbyte, 4, false, 2, false>; 2570 template class StorageAndSubImageTest<glw::GLbyte, 1, false, 3, false>; 2571 template class StorageAndSubImageTest<glw::GLbyte, 2, false, 3, false>; 2572 template class StorageAndSubImageTest<glw::GLbyte, 4, false, 3, false>; 2573 2574 template class StorageAndSubImageTest<glw::GLubyte, 1, false, 1, false>; 2575 template class StorageAndSubImageTest<glw::GLubyte, 2, false, 1, false>; 2576 template class StorageAndSubImageTest<glw::GLubyte, 4, false, 1, false>; 2577 template class StorageAndSubImageTest<glw::GLubyte, 1, false, 2, false>; 2578 template class StorageAndSubImageTest<glw::GLubyte, 2, false, 2, false>; 2579 template class StorageAndSubImageTest<glw::GLubyte, 4, false, 2, false>; 2580 template class StorageAndSubImageTest<glw::GLubyte, 1, false, 3, false>; 2581 template class StorageAndSubImageTest<glw::GLubyte, 2, false, 3, false>; 2582 template class StorageAndSubImageTest<glw::GLubyte, 4, false, 3, false>; 2583 2584 template class StorageAndSubImageTest<glw::GLubyte, 1, true, 1, false>; 2585 template class StorageAndSubImageTest<glw::GLubyte, 2, true, 1, false>; 2586 template class StorageAndSubImageTest<glw::GLubyte, 4, true, 1, false>; 2587 template class StorageAndSubImageTest<glw::GLubyte, 1, true, 2, false>; 2588 template class StorageAndSubImageTest<glw::GLubyte, 2, true, 2, false>; 2589 template class StorageAndSubImageTest<glw::GLubyte, 4, true, 2, false>; 2590 template class StorageAndSubImageTest<glw::GLubyte, 1, true, 3, false>; 2591 template class StorageAndSubImageTest<glw::GLubyte, 2, true, 3, false>; 2592 template class StorageAndSubImageTest<glw::GLubyte, 4, true, 3, false>; 2593 2594 template class StorageAndSubImageTest<glw::GLshort, 1, false, 1, false>; 2595 template class StorageAndSubImageTest<glw::GLshort, 2, false, 1, false>; 2596 template class StorageAndSubImageTest<glw::GLshort, 4, false, 1, false>; 2597 template class StorageAndSubImageTest<glw::GLshort, 1, false, 2, false>; 2598 template class StorageAndSubImageTest<glw::GLshort, 2, false, 2, false>; 2599 template class StorageAndSubImageTest<glw::GLshort, 4, false, 2, false>; 2600 template class StorageAndSubImageTest<glw::GLshort, 1, false, 3, false>; 2601 template class StorageAndSubImageTest<glw::GLshort, 2, false, 3, false>; 2602 template class StorageAndSubImageTest<glw::GLshort, 4, false, 3, false>; 2603 2604 template class StorageAndSubImageTest<glw::GLushort, 1, false, 1, false>; 2605 template class StorageAndSubImageTest<glw::GLushort, 2, false, 1, false>; 2606 template class StorageAndSubImageTest<glw::GLushort, 4, false, 1, false>; 2607 template class StorageAndSubImageTest<glw::GLushort, 1, false, 2, false>; 2608 template class StorageAndSubImageTest<glw::GLushort, 2, false, 2, false>; 2609 template class StorageAndSubImageTest<glw::GLushort, 4, false, 2, false>; 2610 template class StorageAndSubImageTest<glw::GLushort, 1, false, 3, false>; 2611 template class StorageAndSubImageTest<glw::GLushort, 2, false, 3, false>; 2612 template class StorageAndSubImageTest<glw::GLushort, 4, false, 3, false>; 2613 2614 template class StorageAndSubImageTest<glw::GLushort, 1, true, 1, false>; 2615 template class StorageAndSubImageTest<glw::GLushort, 2, true, 1, false>; 2616 template class StorageAndSubImageTest<glw::GLushort, 4, true, 1, false>; 2617 template class StorageAndSubImageTest<glw::GLushort, 1, true, 2, false>; 2618 template class StorageAndSubImageTest<glw::GLushort, 2, true, 2, false>; 2619 template class StorageAndSubImageTest<glw::GLushort, 4, true, 2, false>; 2620 template class StorageAndSubImageTest<glw::GLushort, 1, true, 3, false>; 2621 template class StorageAndSubImageTest<glw::GLushort, 2, true, 3, false>; 2622 template class StorageAndSubImageTest<glw::GLushort, 4, true, 3, false>; 2623 2624 template class StorageAndSubImageTest<glw::GLint, 1, false, 1, false>; 2625 template class StorageAndSubImageTest<glw::GLint, 2, false, 1, false>; 2626 template class StorageAndSubImageTest<glw::GLint, 3, false, 1, false>; 2627 template class StorageAndSubImageTest<glw::GLint, 4, false, 1, false>; 2628 template class StorageAndSubImageTest<glw::GLint, 1, false, 2, false>; 2629 template class StorageAndSubImageTest<glw::GLint, 2, false, 2, false>; 2630 template class StorageAndSubImageTest<glw::GLint, 3, false, 2, false>; 2631 template class StorageAndSubImageTest<glw::GLint, 4, false, 2, false>; 2632 template class StorageAndSubImageTest<glw::GLint, 1, false, 3, false>; 2633 template class StorageAndSubImageTest<glw::GLint, 2, false, 3, false>; 2634 template class StorageAndSubImageTest<glw::GLint, 3, false, 3, false>; 2635 template class StorageAndSubImageTest<glw::GLint, 4, false, 3, false>; 2636 2637 template class StorageAndSubImageTest<glw::GLuint, 1, false, 1, false>; 2638 template class StorageAndSubImageTest<glw::GLuint, 2, false, 1, false>; 2639 template class StorageAndSubImageTest<glw::GLuint, 3, false, 1, false>; 2640 template class StorageAndSubImageTest<glw::GLuint, 4, false, 1, false>; 2641 template class StorageAndSubImageTest<glw::GLuint, 1, false, 2, false>; 2642 template class StorageAndSubImageTest<glw::GLuint, 2, false, 2, false>; 2643 template class StorageAndSubImageTest<glw::GLuint, 3, false, 2, false>; 2644 template class StorageAndSubImageTest<glw::GLuint, 4, false, 2, false>; 2645 template class StorageAndSubImageTest<glw::GLuint, 1, false, 3, false>; 2646 template class StorageAndSubImageTest<glw::GLuint, 2, false, 3, false>; 2647 template class StorageAndSubImageTest<glw::GLuint, 3, false, 3, false>; 2648 template class StorageAndSubImageTest<glw::GLuint, 4, false, 3, false>; 2649 2650 template class StorageAndSubImageTest<glw::GLfloat, 1, true, 1, false>; 2651 template class StorageAndSubImageTest<glw::GLfloat, 2, true, 1, false>; 2652 template class StorageAndSubImageTest<glw::GLfloat, 3, true, 1, false>; 2653 template class StorageAndSubImageTest<glw::GLfloat, 4, true, 1, false>; 2654 template class StorageAndSubImageTest<glw::GLfloat, 1, true, 2, false>; 2655 template class StorageAndSubImageTest<glw::GLfloat, 2, true, 2, false>; 2656 template class StorageAndSubImageTest<glw::GLfloat, 3, true, 2, false>; 2657 template class StorageAndSubImageTest<glw::GLfloat, 4, true, 2, false>; 2658 template class StorageAndSubImageTest<glw::GLfloat, 1, true, 3, false>; 2659 template class StorageAndSubImageTest<glw::GLfloat, 2, true, 3, false>; 2660 template class StorageAndSubImageTest<glw::GLfloat, 3, true, 3, false>; 2661 template class StorageAndSubImageTest<glw::GLfloat, 4, true, 3, false>; 2662 2663 template class StorageAndSubImageTest<glw::GLbyte, 1, false, 1, true>; 2664 template class StorageAndSubImageTest<glw::GLbyte, 2, false, 1, true>; 2665 template class StorageAndSubImageTest<glw::GLbyte, 4, false, 1, true>; 2666 template class StorageAndSubImageTest<glw::GLbyte, 1, false, 2, true>; 2667 template class StorageAndSubImageTest<glw::GLbyte, 2, false, 2, true>; 2668 template class StorageAndSubImageTest<glw::GLbyte, 4, false, 2, true>; 2669 template class StorageAndSubImageTest<glw::GLbyte, 1, false, 3, true>; 2670 template class StorageAndSubImageTest<glw::GLbyte, 2, false, 3, true>; 2671 template class StorageAndSubImageTest<glw::GLbyte, 4, false, 3, true>; 2672 2673 template class StorageAndSubImageTest<glw::GLubyte, 1, false, 1, true>; 2674 template class StorageAndSubImageTest<glw::GLubyte, 2, false, 1, true>; 2675 template class StorageAndSubImageTest<glw::GLubyte, 4, false, 1, true>; 2676 template class StorageAndSubImageTest<glw::GLubyte, 1, false, 2, true>; 2677 template class StorageAndSubImageTest<glw::GLubyte, 2, false, 2, true>; 2678 template class StorageAndSubImageTest<glw::GLubyte, 4, false, 2, true>; 2679 template class StorageAndSubImageTest<glw::GLubyte, 1, false, 3, true>; 2680 template class StorageAndSubImageTest<glw::GLubyte, 2, false, 3, true>; 2681 template class StorageAndSubImageTest<glw::GLubyte, 4, false, 3, true>; 2682 2683 template class StorageAndSubImageTest<glw::GLubyte, 1, true, 1, true>; 2684 template class StorageAndSubImageTest<glw::GLubyte, 2, true, 1, true>; 2685 template class StorageAndSubImageTest<glw::GLubyte, 4, true, 1, true>; 2686 template class StorageAndSubImageTest<glw::GLubyte, 1, true, 2, true>; 2687 template class StorageAndSubImageTest<glw::GLubyte, 2, true, 2, true>; 2688 template class StorageAndSubImageTest<glw::GLubyte, 4, true, 2, true>; 2689 template class StorageAndSubImageTest<glw::GLubyte, 1, true, 3, true>; 2690 template class StorageAndSubImageTest<glw::GLubyte, 2, true, 3, true>; 2691 template class StorageAndSubImageTest<glw::GLubyte, 4, true, 3, true>; 2692 2693 template class StorageAndSubImageTest<glw::GLshort, 1, false, 1, true>; 2694 template class StorageAndSubImageTest<glw::GLshort, 2, false, 1, true>; 2695 template class StorageAndSubImageTest<glw::GLshort, 4, false, 1, true>; 2696 template class StorageAndSubImageTest<glw::GLshort, 1, false, 2, true>; 2697 template class StorageAndSubImageTest<glw::GLshort, 2, false, 2, true>; 2698 template class StorageAndSubImageTest<glw::GLshort, 4, false, 2, true>; 2699 template class StorageAndSubImageTest<glw::GLshort, 1, false, 3, true>; 2700 template class StorageAndSubImageTest<glw::GLshort, 2, false, 3, true>; 2701 template class StorageAndSubImageTest<glw::GLshort, 4, false, 3, true>; 2702 2703 template class StorageAndSubImageTest<glw::GLushort, 1, false, 1, true>; 2704 template class StorageAndSubImageTest<glw::GLushort, 2, false, 1, true>; 2705 template class StorageAndSubImageTest<glw::GLushort, 4, false, 1, true>; 2706 template class StorageAndSubImageTest<glw::GLushort, 1, false, 2, true>; 2707 template class StorageAndSubImageTest<glw::GLushort, 2, false, 2, true>; 2708 template class StorageAndSubImageTest<glw::GLushort, 4, false, 2, true>; 2709 template class StorageAndSubImageTest<glw::GLushort, 1, false, 3, true>; 2710 template class StorageAndSubImageTest<glw::GLushort, 2, false, 3, true>; 2711 template class StorageAndSubImageTest<glw::GLushort, 4, false, 3, true>; 2712 2713 template class StorageAndSubImageTest<glw::GLushort, 1, true, 1, true>; 2714 template class StorageAndSubImageTest<glw::GLushort, 2, true, 1, true>; 2715 template class StorageAndSubImageTest<glw::GLushort, 4, true, 1, true>; 2716 template class StorageAndSubImageTest<glw::GLushort, 1, true, 2, true>; 2717 template class StorageAndSubImageTest<glw::GLushort, 2, true, 2, true>; 2718 template class StorageAndSubImageTest<glw::GLushort, 4, true, 2, true>; 2719 template class StorageAndSubImageTest<glw::GLushort, 1, true, 3, true>; 2720 template class StorageAndSubImageTest<glw::GLushort, 2, true, 3, true>; 2721 template class StorageAndSubImageTest<glw::GLushort, 4, true, 3, true>; 2722 2723 template class StorageAndSubImageTest<glw::GLint, 1, false, 1, true>; 2724 template class StorageAndSubImageTest<glw::GLint, 2, false, 1, true>; 2725 template class StorageAndSubImageTest<glw::GLint, 3, false, 1, true>; 2726 template class StorageAndSubImageTest<glw::GLint, 4, false, 1, true>; 2727 template class StorageAndSubImageTest<glw::GLint, 1, false, 2, true>; 2728 template class StorageAndSubImageTest<glw::GLint, 2, false, 2, true>; 2729 template class StorageAndSubImageTest<glw::GLint, 3, false, 2, true>; 2730 template class StorageAndSubImageTest<glw::GLint, 4, false, 2, true>; 2731 template class StorageAndSubImageTest<glw::GLint, 1, false, 3, true>; 2732 template class StorageAndSubImageTest<glw::GLint, 2, false, 3, true>; 2733 template class StorageAndSubImageTest<glw::GLint, 3, false, 3, true>; 2734 template class StorageAndSubImageTest<glw::GLint, 4, false, 3, true>; 2735 2736 template class StorageAndSubImageTest<glw::GLuint, 1, false, 1, true>; 2737 template class StorageAndSubImageTest<glw::GLuint, 2, false, 1, true>; 2738 template class StorageAndSubImageTest<glw::GLuint, 3, false, 1, true>; 2739 template class StorageAndSubImageTest<glw::GLuint, 4, false, 1, true>; 2740 template class StorageAndSubImageTest<glw::GLuint, 1, false, 2, true>; 2741 template class StorageAndSubImageTest<glw::GLuint, 2, false, 2, true>; 2742 template class StorageAndSubImageTest<glw::GLuint, 3, false, 2, true>; 2743 template class StorageAndSubImageTest<glw::GLuint, 4, false, 2, true>; 2744 template class StorageAndSubImageTest<glw::GLuint, 1, false, 3, true>; 2745 template class StorageAndSubImageTest<glw::GLuint, 2, false, 3, true>; 2746 template class StorageAndSubImageTest<glw::GLuint, 3, false, 3, true>; 2747 template class StorageAndSubImageTest<glw::GLuint, 4, false, 3, true>; 2748 2749 template class StorageAndSubImageTest<glw::GLfloat, 1, true, 1, true>; 2750 template class StorageAndSubImageTest<glw::GLfloat, 2, true, 1, true>; 2751 template class StorageAndSubImageTest<glw::GLfloat, 3, true, 1, true>; 2752 template class StorageAndSubImageTest<glw::GLfloat, 4, true, 1, true>; 2753 template class StorageAndSubImageTest<glw::GLfloat, 1, true, 2, true>; 2754 template class StorageAndSubImageTest<glw::GLfloat, 2, true, 2, true>; 2755 template class StorageAndSubImageTest<glw::GLfloat, 3, true, 2, true>; 2756 template class StorageAndSubImageTest<glw::GLfloat, 4, true, 2, true>; 2757 template class StorageAndSubImageTest<glw::GLfloat, 1, true, 3, true>; 2758 template class StorageAndSubImageTest<glw::GLfloat, 2, true, 3, true>; 2759 template class StorageAndSubImageTest<glw::GLfloat, 3, true, 3, true>; 2760 template class StorageAndSubImageTest<glw::GLfloat, 4, true, 3, true>; 2761 2762 /******************************** Storage Multisample Test Implementation ********************************/ 2763 2764 /** @brief Storage Multisample Test constructor. 2765 * 2766 * @param [in] context OpenGL context. 2767 */ 2768 template <typename T, glw::GLint S, bool N, glw::GLuint D> 2769 StorageMultisampleTest<T, S, N, D>::StorageMultisampleTest(deqp::Context& context, const char* name) 2770 : deqp::TestCase(context, name, "Texture Storage Multisample Test") 2771 , m_fbo_ms(0) 2772 , m_fbo_aux(0) 2773 , m_to_ms(0) 2774 , m_po_ms(0) 2775 , m_po_aux(0) 2776 , m_to(0) 2777 , m_to_aux(0) 2778 , m_vao(0) 2779 { 2780 /* Intentionally left blank. */ 2781 } 2782 2783 /** @brief Count of reference data to be teted. 2784 * 2785 * @return Count. 2786 */ 2787 template <typename T, glw::GLint S, bool N, glw::GLuint D> 2788 glw::GLuint StorageMultisampleTest<T, S, N, D>::TestReferenceDataCount() 2789 { 2790 return 2 /* 1D */ * ((D > 1) ? 3 : 1) /* 2D */ * ((D > 2) ? 4 : 1) /* 3D */ * S /* components */; 2791 } 2792 2793 /** @brief Size of reference data to be teted. 2794 * 2795 * @return Size. 2796 */ 2797 template <typename T, glw::GLint S, bool N, glw::GLuint D> 2798 glw::GLuint StorageMultisampleTest<T, S, N, D>::TestReferenceDataSize() 2799 { 2800 return TestReferenceDataCount() * sizeof(T); 2801 } 2802 2803 /** @brief Height, width or depth of reference data to be teted. 2804 * 2805 * @return Height, width or depth. 2806 */ 2807 template <typename T, glw::GLint S, bool N, glw::GLuint D> 2808 glw::GLuint StorageMultisampleTest<T, S, N, D>::TestReferenceDataHeight() 2809 { 2810 switch(D) 2811 { 2812 case 3: 2813 case 2: 2814 return 3; 2815 default: 2816 return 1; 2817 } 2818 } 2819 2820 template <typename T, glw::GLint S, bool N, glw::GLuint D> 2821 glw::GLuint StorageMultisampleTest<T, S, N, D>::TestReferenceDataDepth() 2822 { 2823 switch(D) 2824 { 2825 case 3: 2826 return 4; 2827 default: 2828 return 1; 2829 } 2830 } 2831 2832 template <typename T, glw::GLint S, bool N, glw::GLuint D> 2833 glw::GLuint StorageMultisampleTest<T, S, N, D>::TestReferenceDataWidth() 2834 { 2835 return 2; 2836 } 2837 2838 /** @brief Fragment shader declaration selector. 2839 * 2840 * @return Frgment shader source code part. 2841 */ 2842 template <typename T, glw::GLint S, bool N, glw::GLuint D> 2843 const glw::GLchar* StorageMultisampleTest<T, S, N, D>::FragmentShaderDeclarationMultisample() 2844 { 2845 if (typeid(T) == typeid(glw::GLbyte)) 2846 { 2847 switch (D) 2848 { 2849 case 2: 2850 return s_fragment_shader_ms_2D_idecl_lowp; 2851 case 3: 2852 return s_fragment_shader_ms_3D_idecl_lowp; 2853 default: 2854 DE_ASSERT("invalid texture dimension"); 2855 return DE_NULL; 2856 } 2857 } 2858 2859 if (typeid(T) == typeid(glw::GLubyte)) 2860 { 2861 if (N) 2862 { 2863 switch (D) 2864 { 2865 case 2: 2866 return s_fragment_shader_ms_2D_fdecl_lowp; 2867 case 3: 2868 return s_fragment_shader_ms_3D_fdecl_lowp; 2869 default: 2870 DE_ASSERT("invalid texture dimension"); 2871 return DE_NULL; 2872 } 2873 } 2874 else 2875 { 2876 switch (D) 2877 { 2878 case 2: 2879 return s_fragment_shader_ms_2D_udecl_lowp; 2880 case 3: 2881 return s_fragment_shader_ms_3D_udecl_lowp; 2882 default: 2883 DE_ASSERT("invalid texture dimension"); 2884 return DE_NULL; 2885 } 2886 } 2887 } 2888 2889 if (typeid(T) == typeid(glw::GLshort)) 2890 { 2891 switch (D) 2892 { 2893 case 2: 2894 return s_fragment_shader_ms_2D_idecl_mediump; 2895 case 3: 2896 return s_fragment_shader_ms_3D_idecl_mediump; 2897 default: 2898 DE_ASSERT("invalid texture dimension"); 2899 return DE_NULL; 2900 } 2901 } 2902 2903 if (typeid(T) == typeid(glw::GLushort)) 2904 { 2905 if (N) 2906 { 2907 switch (D) 2908 { 2909 case 2: 2910 return s_fragment_shader_ms_2D_fdecl_mediump; 2911 case 3: 2912 return s_fragment_shader_ms_3D_fdecl_mediump; 2913 default: 2914 DE_ASSERT("invalid texture dimension"); 2915 return DE_NULL; 2916 } 2917 } 2918 else 2919 { 2920 switch (D) 2921 { 2922 case 2: 2923 return s_fragment_shader_ms_2D_udecl_mediump; 2924 case 3: 2925 return s_fragment_shader_ms_3D_udecl_mediump; 2926 default: 2927 DE_ASSERT("invalid texture dimension"); 2928 return DE_NULL; 2929 } 2930 } 2931 } 2932 2933 if (typeid(T) == typeid(glw::GLint)) 2934 { 2935 switch (D) 2936 { 2937 case 2: 2938 return s_fragment_shader_ms_2D_idecl_highp; 2939 case 3: 2940 return s_fragment_shader_ms_3D_idecl_highp; 2941 default: 2942 DE_ASSERT("invalid texture dimension"); 2943 return DE_NULL; 2944 } 2945 } 2946 2947 if (typeid(T) == typeid(glw::GLuint)) 2948 { 2949 switch (D) 2950 { 2951 case 2: 2952 return s_fragment_shader_ms_2D_udecl_highp; 2953 case 3: 2954 return s_fragment_shader_ms_3D_udecl_highp; 2955 default: 2956 DE_ASSERT("invalid texture dimension"); 2957 return DE_NULL; 2958 } 2959 } 2960 2961 if (typeid(T) == typeid(glw::GLfloat)) 2962 { 2963 switch (D) 2964 { 2965 case 2: 2966 return s_fragment_shader_ms_2D_fdecl_highp; 2967 case 3: 2968 return s_fragment_shader_ms_3D_fdecl_highp; 2969 default: 2970 DE_ASSERT("invalid texture dimension"); 2971 return DE_NULL; 2972 } 2973 } 2974 2975 DE_ASSERT("invalid type"); 2976 return DE_NULL; 2977 } 2978 2979 /** @brief Fragment shader declaration selector. 2980 * 2981 * @return Frgment shader source code part. 2982 */ 2983 template <typename T, glw::GLint S, bool N, glw::GLuint D> 2984 const glw::GLchar* StorageMultisampleTest<T, S, N, D>::FragmentShaderDeclarationAuxiliary() 2985 { 2986 if (typeid(T) == typeid(glw::GLbyte)) 2987 { 2988 switch (D) 2989 { 2990 case 2: 2991 return s_fragment_shader_aux_2D_idecl_lowp; 2992 case 3: 2993 return s_fragment_shader_aux_3D_idecl_lowp; 2994 default: 2995 DE_ASSERT("invalid texture dimension"); 2996 return DE_NULL; 2997 } 2998 } 2999 3000 if (typeid(T) == typeid(glw::GLubyte)) 3001 { 3002 if (N) 3003 { 3004 switch (D) 3005 { 3006 case 2: 3007 return s_fragment_shader_aux_2D_fdecl_lowp; 3008 case 3: 3009 return s_fragment_shader_aux_3D_fdecl_lowp; 3010 default: 3011 DE_ASSERT("invalid texture dimension"); 3012 return DE_NULL; 3013 } 3014 } 3015 else 3016 { 3017 switch (D) 3018 { 3019 case 2: 3020 return s_fragment_shader_aux_2D_udecl_lowp; 3021 case 3: 3022 return s_fragment_shader_aux_3D_udecl_lowp; 3023 default: 3024 DE_ASSERT("invalid texture dimension"); 3025 return DE_NULL; 3026 } 3027 } 3028 } 3029 3030 if (typeid(T) == typeid(glw::GLshort)) 3031 { 3032 switch (D) 3033 { 3034 case 2: 3035 return s_fragment_shader_aux_2D_idecl_mediump; 3036 case 3: 3037 return s_fragment_shader_aux_3D_idecl_mediump; 3038 default: 3039 DE_ASSERT("invalid texture dimension"); 3040 return DE_NULL; 3041 } 3042 } 3043 3044 if (typeid(T) == typeid(glw::GLushort)) 3045 { 3046 if (N) 3047 { 3048 switch (D) 3049 { 3050 case 2: 3051 return s_fragment_shader_aux_2D_fdecl_mediump; 3052 case 3: 3053 return s_fragment_shader_aux_3D_fdecl_mediump; 3054 default: 3055 DE_ASSERT("invalid texture dimension"); 3056 return DE_NULL; 3057 } 3058 } 3059 else 3060 { 3061 switch (D) 3062 { 3063 case 2: 3064 return s_fragment_shader_aux_2D_udecl_mediump; 3065 case 3: 3066 return s_fragment_shader_aux_3D_udecl_mediump; 3067 default: 3068 DE_ASSERT("invalid texture dimension"); 3069 return DE_NULL; 3070 } 3071 } 3072 } 3073 3074 if (typeid(T) == typeid(glw::GLint)) 3075 { 3076 switch (D) 3077 { 3078 case 2: 3079 return s_fragment_shader_aux_2D_idecl_highp; 3080 case 3: 3081 return s_fragment_shader_aux_3D_idecl_highp; 3082 default: 3083 DE_ASSERT("invalid texture dimension"); 3084 return DE_NULL; 3085 } 3086 } 3087 3088 if (typeid(T) == typeid(glw::GLuint)) 3089 { 3090 switch (D) 3091 { 3092 case 2: 3093 return s_fragment_shader_aux_2D_udecl_highp; 3094 case 3: 3095 return s_fragment_shader_aux_3D_udecl_highp; 3096 default: 3097 DE_ASSERT("invalid texture dimension"); 3098 return DE_NULL; 3099 } 3100 } 3101 3102 if (typeid(T) == typeid(glw::GLfloat)) 3103 { 3104 switch (D) 3105 { 3106 case 2: 3107 return s_fragment_shader_aux_2D_fdecl_highp; 3108 case 3: 3109 return s_fragment_shader_aux_3D_fdecl_highp; 3110 default: 3111 DE_ASSERT("invalid texture dimension"); 3112 return DE_NULL; 3113 } 3114 } 3115 3116 DE_ASSERT("invalid type"); 3117 return DE_NULL; 3118 } 3119 3120 /** @brief Fragment shader tail selector. 3121 * 3122 * @return Frgment shader source code part. 3123 */ 3124 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3125 const glw::GLchar* StorageMultisampleTest<T, S, N, D>::FragmentShaderTail() 3126 { 3127 switch (D) 3128 { 3129 case 2: 3130 return s_fragment_shader_tail_2D; 3131 case 3: 3132 return s_fragment_shader_tail_3D; 3133 default: 3134 DE_ASSERT("invalid texture dimension"); 3135 return DE_NULL; 3136 } 3137 } 3138 3139 /** @brief Multisample texture target selector. 3140 * 3141 * @return Texture target. 3142 */ 3143 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3144 glw::GLenum StorageMultisampleTest<T, S, N, D>::MultisampleTextureTarget() 3145 { 3146 switch (D) 3147 { 3148 case 2: 3149 return GL_TEXTURE_2D_MULTISAMPLE; 3150 case 3: 3151 return GL_TEXTURE_2D_MULTISAMPLE_ARRAY; 3152 default: 3153 DE_ASSERT("invalid texture dimension"); 3154 return DE_NULL; 3155 } 3156 } 3157 3158 /** @brief Input texture target selector. 3159 * 3160 * @return Texture target. 3161 */ 3162 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3163 glw::GLenum StorageMultisampleTest<T, S, N, D>::InputTextureTarget() 3164 { 3165 switch (D) 3166 { 3167 case 2: 3168 return GL_TEXTURE_2D; 3169 case 3: 3170 return GL_TEXTURE_2D_ARRAY; 3171 default: 3172 DE_ASSERT("invalid texture dimension"); 3173 return DE_NULL; 3174 } 3175 } 3176 3177 /** @brief Prepare texture data for input texture. 3178 * 3179 * @note parameters as passed to texImage* 3180 */ 3181 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3182 void StorageMultisampleTest<T, S, N, D>::InputTextureImage(const glw::GLenum internal_format, const glw::GLuint width, 3183 const glw::GLuint height, const glw::GLuint depth, 3184 const glw::GLenum format, const glw::GLenum type, 3185 const glw::GLvoid* data) 3186 { 3187 (void)depth; 3188 /* Shortcut for GL functionality. */ 3189 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 3190 3191 /* Data setup. */ 3192 switch (D) 3193 { 3194 case 2: 3195 gl.texImage2D(InputTextureTarget(), 0, internal_format, width, height, 0, format, type, data); 3196 break; 3197 case 3: 3198 gl.texImage3D(InputTextureTarget(), 0, internal_format, width, height, depth, 0, format, type, data); 3199 break; 3200 default: 3201 DE_ASSERT("invalid texture dimension"); 3202 } 3203 3204 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage has failed"); 3205 } 3206 3207 /** @brief Create texture. 3208 * 3209 */ 3210 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3211 void StorageMultisampleTest<T, S, N, D>::CreateInputTexture() 3212 { 3213 /* Shortcut for GL functionality. */ 3214 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 3215 3216 /* Objects creation. */ 3217 gl.genTextures(1, &m_to); 3218 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed"); 3219 3220 gl.bindTexture(InputTextureTarget(), m_to); 3221 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed"); 3222 3223 /* Data setup. */ 3224 InputTextureImage(InternalFormat<T, S, N>(), TestReferenceDataWidth(), TestReferenceDataHeight(), 3225 TestReferenceDataDepth(), Format<S, N>(), Type<T>(), ReferenceData<T, N>()); 3226 3227 /* Parameter setup. */ 3228 gl.texParameteri(InputTextureTarget(), GL_TEXTURE_MAG_FILTER, GL_NEAREST); 3229 gl.texParameteri(InputTextureTarget(), GL_TEXTURE_MIN_FILTER, GL_NEAREST); 3230 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed."); 3231 } 3232 3233 /** @brief Compre results with the reference. 3234 * 3235 * @return True if equal, false otherwise. 3236 */ 3237 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3238 bool StorageMultisampleTest<T, S, N, D>::Check() 3239 { 3240 /* Shortcut for GL functionality. */ 3241 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 3242 3243 /* Fetching data fro auxiliary texture. */ 3244 std::vector<T> result(TestReferenceDataCount()); 3245 3246 gl.bindTexture(InputTextureTarget() /* Auxiliary target is the same as input. */, m_to_aux); 3247 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed"); 3248 3249 gl.getTexImage(InputTextureTarget() /* Auxiliary target is the same as input. */, 0, Format<S, N>(), Type<T>(), 3250 (glw::GLvoid*)(&result[0])); 3251 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexImage has failed"); 3252 3253 /* Comparison. */ 3254 for (glw::GLuint i = 0; i < TestReferenceDataCount(); ++i) 3255 { 3256 if (!Compare<T>(result[i], ReferenceData<T, N>()[i])) 3257 { 3258 return false; 3259 } 3260 } 3261 3262 return true; 3263 } 3264 3265 /** @brief Test case function. 3266 * 3267 * @return True if test succeeded, false otherwise. 3268 */ 3269 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3270 bool StorageMultisampleTest<T, S, N, D>::Test() 3271 { 3272 /* Shortcut for GL functionality. */ 3273 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 3274 3275 /* Setup. */ 3276 gl.pixelStorei(GL_UNPACK_ALIGNMENT, sizeof(T)); 3277 GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed"); 3278 3279 gl.pixelStorei(GL_PACK_ALIGNMENT, sizeof(T)); 3280 GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed"); 3281 3282 CreateInputTexture(); 3283 3284 if (!PrepareFramebufferMultisample(InternalFormat<T, S, N>())) 3285 { 3286 CleanInputTexture(); 3287 3288 return false; 3289 } 3290 3291 PrepareFramebufferAuxiliary(InternalFormat<T, S, N>()); 3292 3293 /* Action. */ 3294 Draw(); 3295 3296 /* Compare results with reference. */ 3297 bool result = Check(); 3298 3299 /* Cleanup. */ 3300 CleanAuxiliaryTexture(); 3301 CleanFramebuffers(); 3302 CleanInputTexture(); 3303 CleanErrors(); 3304 3305 /* Pass result. */ 3306 return result; 3307 } 3308 3309 /** @brief Function prepares framebuffer with internal format color attachment. 3310 * Viewport is set up. Content of the framebuffer is cleared. 3311 * 3312 * @note The function may throw if unexpected error has occured. 3313 */ 3314 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3315 bool StorageMultisampleTest<T, S, N, D>::PrepareFramebufferMultisample(const glw::GLenum internal_format) 3316 { 3317 /* Shortcut for GL functionality. */ 3318 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 3319 3320 /* Prepare framebuffer. */ 3321 gl.genFramebuffers(1, &m_fbo_ms); 3322 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed."); 3323 3324 gl.genTextures(1, &m_to_ms); 3325 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed."); 3326 3327 gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms); 3328 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed."); 3329 3330 gl.bindTexture(MultisampleTextureTarget(), m_to_ms); 3331 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed."); 3332 3333 switch (D) 3334 { 3335 case 2: 3336 gl.textureStorage2DMultisample(m_to_ms, 1, internal_format, TestReferenceDataWidth(), 3337 TestReferenceDataHeight(), false); 3338 break; 3339 case 3: 3340 gl.textureStorage3DMultisample(m_to_ms, 1, internal_format, TestReferenceDataWidth(), 3341 TestReferenceDataHeight(), TestReferenceDataDepth(), false); 3342 break; 3343 default: 3344 DE_ASSERT("invalid texture dimension"); 3345 return false; 3346 } 3347 3348 glw::GLenum error; 3349 3350 if (GL_NO_ERROR != (error = gl.getError())) 3351 { 3352 CleanFramebuffers(); 3353 3354 m_context.getTestContext().getLog() 3355 << tcu::TestLog::Message << "glTextureStorageMultisample unexpectedly generated error " 3356 << glu::getErrorStr(error) << " during the test of internal format " 3357 << glu::getTextureFormatStr(internal_format) << ". Test fails." << tcu::TestLog::EndMessage; 3358 3359 return false; 3360 } 3361 3362 switch (D) 3363 { 3364 case 2: 3365 gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, m_to_ms, 0); 3366 break; 3367 case 3: 3368 for (glw::GLuint i = 0; i < TestReferenceDataDepth(); ++i) 3369 { 3370 gl.framebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, m_to_ms, 0, i); 3371 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTextureLayer call failed."); 3372 } 3373 break; 3374 default: 3375 DE_ASSERT("invalid texture dimension"); 3376 return false; 3377 } 3378 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed."); 3379 3380 if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) 3381 { 3382 if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_UNSUPPORTED) 3383 throw tcu::NotSupportedError("unsupported framebuffer configuration"); 3384 else 3385 throw 0; 3386 } 3387 3388 gl.viewport(0, 0, TestReferenceDataWidth(), TestReferenceDataHeight()); 3389 GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed."); 3390 3391 /* Clear framebuffer's content. */ 3392 gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f); 3393 GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed."); 3394 3395 gl.clear(GL_COLOR_BUFFER_BIT); 3396 GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed."); 3397 3398 return true; 3399 } 3400 3401 /** @brief Function prepares framebuffer with internal format color attachment. 3402 * Viewport is set up. Content of the framebuffer is cleared. 3403 * 3404 * @note The function may throw if unexpected error has occured. 3405 */ 3406 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3407 void StorageMultisampleTest<T, S, N, D>::PrepareFramebufferAuxiliary(const glw::GLenum internal_format) 3408 { 3409 /* Shortcut for GL functionality. */ 3410 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 3411 3412 /* Prepare framebuffer. */ 3413 gl.genFramebuffers(1, &m_fbo_aux); 3414 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed."); 3415 3416 gl.genTextures(1, &m_to_aux); 3417 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed."); 3418 3419 gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_aux); 3420 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed."); 3421 3422 gl.bindTexture(InputTextureTarget(), m_to_aux); 3423 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed."); 3424 3425 switch (D) 3426 { 3427 case 2: 3428 gl.textureStorage2D(m_to_aux, 1, internal_format, TestReferenceDataWidth(), TestReferenceDataHeight()); 3429 break; 3430 case 3: 3431 gl.textureStorage3D(m_to_aux, 1, internal_format, TestReferenceDataWidth(), TestReferenceDataHeight(), 3432 TestReferenceDataDepth()); 3433 break; 3434 default: 3435 DE_ASSERT("invalid texture dimension"); 3436 } 3437 GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2D call failed."); 3438 3439 /* Parameter setup. */ 3440 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 3441 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 3442 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed."); 3443 3444 switch (D) 3445 { 3446 case 2: 3447 gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_to_aux, 0); 3448 break; 3449 case 3: 3450 for (glw::GLuint i = 0; i < TestReferenceDataDepth(); ++i) 3451 { 3452 gl.framebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, m_to_aux, 0, i); 3453 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTextureLayer call failed."); 3454 } 3455 break; 3456 default: 3457 DE_ASSERT("invalid texture dimension"); 3458 } 3459 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed."); 3460 3461 if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) 3462 { 3463 if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_UNSUPPORTED) 3464 throw tcu::NotSupportedError("unsupported framebuffer configuration"); 3465 else 3466 throw 0; 3467 } 3468 3469 gl.viewport(0, 0, TestReferenceDataWidth(), TestReferenceDataHeight()); 3470 GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed."); 3471 3472 /* Clear framebuffer's content. */ 3473 gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f); 3474 GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed."); 3475 3476 gl.clear(GL_COLOR_BUFFER_BIT); 3477 GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed."); 3478 } 3479 3480 /** @brief Prepare program 3481 * 3482 * @param [in] variable_declaration Variables declaration part of fragment shader source code. 3483 * @param [in] tail Tail part of fragment shader source code. 3484 */ 3485 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3486 glw::GLuint StorageMultisampleTest<T, S, N, D>::PrepareProgram(const glw::GLchar* variable_declaration, const glw::GLchar* tail) 3487 { 3488 /* Shortcut for GL functionality */ 3489 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 3490 3491 struct Shader 3492 { 3493 glw::GLchar const* source[3]; 3494 glw::GLsizei const count; 3495 glw::GLenum const type; 3496 glw::GLuint id; 3497 } shader[] = { { { s_vertex_shader, NULL, NULL }, 1, GL_VERTEX_SHADER, 0 }, 3498 { { s_fragment_shader_head, variable_declaration, tail }, 3, GL_FRAGMENT_SHADER, 0 } }; 3499 3500 glw::GLuint const shader_count = sizeof(shader) / sizeof(shader[0]); 3501 3502 glw::GLuint po = 0; 3503 3504 try 3505 { 3506 /* Create program. */ 3507 po = gl.createProgram(); 3508 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateProgram call failed."); 3509 3510 /* Shader compilation. */ 3511 3512 for (glw::GLuint i = 0; i < shader_count; ++i) 3513 { 3514 { 3515 shader[i].id = gl.createShader(shader[i].type); 3516 3517 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateShader call failed."); 3518 3519 gl.attachShader(po, shader[i].id); 3520 3521 GLU_EXPECT_NO_ERROR(gl.getError(), "glAttachShader call failed."); 3522 3523 gl.shaderSource(shader[i].id, shader[i].count, shader[i].source, NULL); 3524 3525 GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource call failed."); 3526 3527 gl.compileShader(shader[i].id); 3528 3529 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader call failed."); 3530 3531 glw::GLint status = GL_FALSE; 3532 3533 gl.getShaderiv(shader[i].id, GL_COMPILE_STATUS, &status); 3534 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed."); 3535 3536 if (GL_FALSE == status) 3537 { 3538 glw::GLint log_size = 0; 3539 gl.getShaderiv(shader[i].id, GL_INFO_LOG_LENGTH, &log_size); 3540 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed."); 3541 3542 glw::GLchar* log_text = new glw::GLchar[log_size]; 3543 3544 gl.getShaderInfoLog(shader[i].id, log_size, NULL, &log_text[0]); 3545 3546 m_context.getTestContext().getLog() 3547 << tcu::TestLog::Message << "Shader compilation has failed.\n" 3548 << "Shader type: " << glu::getShaderTypeStr(shader[i].type) << "\n" 3549 << "Shader compilation error log:\n" 3550 << log_text << "\n" 3551 << "Shader source code:\n" 3552 << shader[i].source[0] << (shader[i].source[1] ? shader[i].source[1] : "") 3553 << (shader[i].source[2] ? shader[i].source[2] : "") << "\n" 3554 << tcu::TestLog::EndMessage; 3555 3556 delete[] log_text; 3557 3558 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog call failed."); 3559 3560 throw 0; 3561 } 3562 } 3563 } 3564 3565 /* Link. */ 3566 gl.linkProgram(po); 3567 3568 GLU_EXPECT_NO_ERROR(gl.getError(), "glTransformFeedbackVaryings call failed."); 3569 3570 glw::GLint status = GL_FALSE; 3571 3572 gl.getProgramiv(po, GL_LINK_STATUS, &status); 3573 3574 if (GL_TRUE == status) 3575 { 3576 for (glw::GLuint i = 0; i < shader_count; ++i) 3577 { 3578 if (shader[i].id) 3579 { 3580 gl.detachShader(po, shader[i].id); 3581 3582 GLU_EXPECT_NO_ERROR(gl.getError(), "glDetachShader call failed."); 3583 } 3584 } 3585 } 3586 else 3587 { 3588 glw::GLint log_size = 0; 3589 3590 gl.getProgramiv(po, GL_INFO_LOG_LENGTH, &log_size); 3591 3592 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv call failed."); 3593 3594 glw::GLchar* log_text = new glw::GLchar[log_size]; 3595 3596 gl.getProgramInfoLog(po, log_size, NULL, &log_text[0]); 3597 3598 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Program linkage has failed due to:\n" 3599 << log_text << "\n" 3600 << tcu::TestLog::EndMessage; 3601 3602 delete[] log_text; 3603 3604 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramInfoLog call failed."); 3605 3606 throw 0; 3607 } 3608 } 3609 catch (...) 3610 { 3611 if (po) 3612 { 3613 gl.deleteProgram(po); 3614 3615 po = 0; 3616 } 3617 } 3618 3619 for (glw::GLuint i = 0; i < shader_count; ++i) 3620 { 3621 if (0 != shader[i].id) 3622 { 3623 gl.deleteShader(shader[i].id); 3624 3625 shader[i].id = 0; 3626 } 3627 } 3628 3629 if (0 == po) 3630 { 3631 throw 0; 3632 } 3633 3634 return po; 3635 } 3636 3637 /** @brief Prepare VAO. 3638 */ 3639 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3640 void StorageMultisampleTest<T, S, N, D>::PrepareVertexArray() 3641 { 3642 /* Shortcut for GL functionality. */ 3643 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 3644 3645 gl.genVertexArrays(1, &m_vao); 3646 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays has failed"); 3647 3648 gl.bindVertexArray(m_vao); 3649 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray has failed"); 3650 } 3651 3652 /** @brief Draw call 3653 */ 3654 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3655 void StorageMultisampleTest<T, S, N, D>::Draw() 3656 { 3657 /* Shortcut for GL functionality. */ 3658 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 3659 3660 /* Prepare multisample texture using draw call. */ 3661 3662 /* Prepare framebuffer with multisample texture. */ 3663 gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_ms); 3664 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer has failed"); 3665 3666 /* Use first program program. */ 3667 gl.useProgram(m_po_ms); 3668 GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed"); 3669 3670 /* Prepare texture to be drawn with. */ 3671 gl.activeTexture(GL_TEXTURE0); 3672 GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed"); 3673 3674 gl.bindTexture(InputTextureTarget(), m_to); 3675 GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed"); 3676 3677 gl.uniform1i(gl.getUniformLocation(m_po_ms, "texture_input"), 0); 3678 GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed"); 3679 3680 for (glw::GLuint i = 0; i < TestReferenceDataDepth(); ++i) 3681 { 3682 /* Select layer. */ 3683 gl.drawBuffer(GL_COLOR_ATTACHMENT0 + i); 3684 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawBuffer has failed"); 3685 3686 if (D == 3) 3687 { 3688 gl.uniform1i(gl.getUniformLocation(m_po_aux, "texture_layer"), i); 3689 GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed"); 3690 } 3691 3692 /* Draw. */ 3693 gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4); 3694 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed"); 3695 } 3696 3697 /* Copy multisample texture to auxiliary texture using draw call. */ 3698 3699 /* Prepare framebuffer with auxiliary texture. */ 3700 gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_aux); 3701 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer has failed"); 3702 3703 /* Use first program program. */ 3704 gl.useProgram(m_po_aux); 3705 GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram has failed"); 3706 3707 /* Prepare texture to be drawn with. */ 3708 gl.activeTexture(GL_TEXTURE0); 3709 GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed"); 3710 3711 gl.bindTexture(MultisampleTextureTarget(), m_to_ms); 3712 GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture has failed"); 3713 3714 gl.bindTextureUnit(0, m_to); 3715 3716 gl.uniform1i(gl.getUniformLocation(m_po_aux, "texture_input"), 0); 3717 GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed"); 3718 3719 /* For each texture layer. */ 3720 for (glw::GLuint i = 0; i < TestReferenceDataDepth(); ++i) 3721 { 3722 /* Select layer. */ 3723 gl.drawBuffer(GL_COLOR_ATTACHMENT0 + i); 3724 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawBuffer has failed"); 3725 3726 if (D == 3) 3727 { 3728 gl.uniform1i(gl.getUniformLocation(m_po_aux, "texture_layer"), i); 3729 GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i or glGetUniformLocation has failed"); 3730 } 3731 3732 /* Draw. */ 3733 gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4); 3734 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays has failed"); 3735 } 3736 } 3737 3738 /** @brief Clean GL objects, test variables and GL errors. 3739 */ 3740 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3741 void StorageMultisampleTest<T, S, N, D>::CleanInputTexture() 3742 { 3743 /* Shortcut for GL functionality. */ 3744 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 3745 3746 /* Texture. */ 3747 if (m_to) 3748 { 3749 gl.deleteTextures(1, &m_to); 3750 3751 m_to = 0; 3752 } 3753 } 3754 3755 /** @brief Clean GL objects, test variables and GL errors. 3756 */ 3757 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3758 void StorageMultisampleTest<T, S, N, D>::CleanAuxiliaryTexture() 3759 { 3760 /* Shortcut for GL functionality. */ 3761 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 3762 3763 if (m_to_aux) 3764 { 3765 gl.deleteTextures(1, &m_to_aux); 3766 3767 m_to_aux = 0; 3768 } 3769 } 3770 3771 /** @brief Clean GL objects, test variables and GL errors. 3772 */ 3773 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3774 void StorageMultisampleTest<T, S, N, D>::CleanFramebuffers() 3775 { 3776 /* Shortcut for GL functionality. */ 3777 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 3778 3779 /* Mulitsample framebuffer. */ 3780 if (m_fbo_ms) 3781 { 3782 gl.deleteFramebuffers(1, &m_fbo_ms); 3783 3784 m_fbo_ms = 0; 3785 } 3786 3787 /* Mulitsample texture. */ 3788 if (m_to_ms) 3789 { 3790 gl.deleteTextures(1, &m_to_ms); 3791 3792 m_to_ms = 0; 3793 } 3794 3795 /* Auxiliary framebuffer. */ 3796 if (m_fbo_aux) 3797 { 3798 gl.deleteFramebuffers(1, &m_fbo_aux); 3799 3800 m_fbo_aux = 0; 3801 } 3802 3803 /* Auxiliary texture. */ 3804 if (m_to_aux) 3805 { 3806 gl.deleteTextures(1, &m_to_aux); 3807 3808 m_to_aux = 0; 3809 } 3810 } 3811 3812 /** @brief Clean GL objects, test variables and GL errors. 3813 */ 3814 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3815 void StorageMultisampleTest<T, S, N, D>::CleanPrograms() 3816 { 3817 /* Shortcut for GL functionality. */ 3818 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 3819 3820 /* Binding point. */ 3821 gl.useProgram(0); 3822 3823 /* Multisample texture preparation program. */ 3824 if (m_po_ms) 3825 { 3826 gl.deleteProgram(m_po_ms); 3827 3828 m_po_ms = 0; 3829 } 3830 3831 /* Auxiliary texture preparation program. */ 3832 if (m_po_aux) 3833 { 3834 gl.deleteProgram(m_po_aux); 3835 3836 m_po_aux = 0; 3837 } 3838 } 3839 3840 /** @brief Clean GL objects, test variables and GL errors. 3841 */ 3842 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3843 void StorageMultisampleTest<T, S, N, D>::CleanErrors() 3844 { 3845 /* Shortcut for GL functionality. */ 3846 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 3847 3848 /* Query all errors until GL_NO_ERROR occure. */ 3849 while (GL_NO_ERROR != gl.getError()) 3850 ; 3851 } 3852 3853 /** @brief Clean GL objects, test variables and GL errors. 3854 */ 3855 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3856 void StorageMultisampleTest<T, S, N, D>::CleanVertexArray() 3857 { 3858 /* Shortcut for GL functionality. */ 3859 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 3860 3861 if (m_vao) 3862 { 3863 gl.bindVertexArray(0); 3864 3865 gl.deleteVertexArrays(1, &m_vao); 3866 3867 m_vao = 0; 3868 } 3869 } 3870 3871 /** @brief Iterate Storage Multisample Test cases. 3872 * 3873 * @return Iteration result. 3874 */ 3875 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3876 tcu::TestNode::IterateResult StorageMultisampleTest<T, S, N, D>::iterate() 3877 { 3878 /* Shortcut for GL functionality. */ 3879 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 3880 3881 /* Get context setup. */ 3882 bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5))); 3883 bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access"); 3884 3885 if ((!is_at_least_gl_45) && (!is_arb_direct_state_access)) 3886 { 3887 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported"); 3888 3889 return STOP; 3890 } 3891 3892 /* Running tests. */ 3893 bool is_ok = true; 3894 bool is_error = false; 3895 3896 try 3897 { 3898 PrepareVertexArray(); 3899 3900 // gl.enable(GL_MULTISAMPLE); 3901 3902 m_po_ms = PrepareProgram(FragmentShaderDeclarationMultisample(), FragmentShaderTail()); 3903 m_po_aux = PrepareProgram(FragmentShaderDeclarationAuxiliary(), FragmentShaderTail()); 3904 3905 is_ok = Test(); 3906 } 3907 catch (tcu::NotSupportedError e) 3908 { 3909 throw e; 3910 } 3911 catch (...) 3912 { 3913 is_ok = false; 3914 is_error = true; 3915 } 3916 3917 /* Cleanup. */ 3918 CleanInputTexture(); 3919 CleanAuxiliaryTexture(); 3920 CleanFramebuffers(); 3921 CleanPrograms(); 3922 CleanErrors(); 3923 CleanVertexArray(); 3924 gl.disable(GL_MULTISAMPLE); 3925 3926 /* Errors clean up. */ 3927 while (gl.getError()) 3928 ; 3929 3930 /* Result's setup. */ 3931 if (is_ok) 3932 { 3933 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 3934 } 3935 else 3936 { 3937 if (is_error) 3938 { 3939 m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error"); 3940 } 3941 else 3942 { 3943 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); 3944 } 3945 } 3946 3947 return STOP; 3948 } 3949 3950 /* Vertex shader source code. */ 3951 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3952 const glw::GLchar* StorageMultisampleTest<T, S, N, D>::s_vertex_shader = 3953 "#version 450\n" 3954 "\n" 3955 "void main()\n" 3956 "{\n" 3957 " switch(gl_VertexID)\n" 3958 " {\n" 3959 " case 0:\n" 3960 " gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n" 3961 " break;\n" 3962 " case 1:\n" 3963 " gl_Position = vec4( 1.0, 1.0, 0.0, 1.0);\n" 3964 " break;\n" 3965 " case 2:\n" 3966 " gl_Position = vec4(-1.0,-1.0, 0.0, 1.0);\n" 3967 " break;\n" 3968 " case 3:\n" 3969 " gl_Position = vec4( 1.0,-1.0, 0.0, 1.0);\n" 3970 " break;\n" 3971 " }\n" 3972 "}\n"; 3973 3974 /* Fragment shader source program. */ 3975 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3976 const glw::GLchar* StorageMultisampleTest<T, S, N, D>::s_fragment_shader_head = 3977 "#version 450\n" 3978 "\n" 3979 "layout(pixel_center_integer) in vec4 gl_FragCoord;\n" 3980 "\n"; 3981 3982 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3983 const glw::GLchar* StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_2D_fdecl_lowp = 3984 "uniform sampler2D texture_input;\nout vec4 texture_output;\n"; 3985 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3986 const glw::GLchar* StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_2D_idecl_lowp = 3987 "uniform isampler2D texture_input;\nout ivec4 texture_output;\n"; 3988 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3989 const glw::GLchar* StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_2D_udecl_lowp = 3990 "uniform usampler2D texture_input;\nout uvec4 texture_output;\n"; 3991 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3992 const glw::GLchar* StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_2D_fdecl_mediump = 3993 "uniform sampler2D texture_input;\nout vec4 texture_output;\n"; 3994 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3995 const glw::GLchar* StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_2D_idecl_mediump = 3996 "uniform isampler2D texture_input;\nout ivec4 texture_output;\n"; 3997 template <typename T, glw::GLint S, bool N, glw::GLuint D> 3998 const glw::GLchar* StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_2D_udecl_mediump = 3999 "uniform usampler2D texture_input;\nout uvec4 texture_output;\n"; 4000 template <typename T, glw::GLint S, bool N, glw::GLuint D> 4001 const glw::GLchar* StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_2D_fdecl_highp = 4002 "uniform sampler2D texture_input;\nout vec4 texture_output;\n"; 4003 template <typename T, glw::GLint S, bool N, glw::GLuint D> 4004 const glw::GLchar* StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_2D_idecl_highp = 4005 "uniform isampler2D texture_input;\nout ivec4 texture_output;\n"; 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_2D_udecl_highp = 4008 "uniform usampler2D texture_input;\nout uvec4 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_fdecl_lowp = 4012 "uniform sampler2DArray texture_input;\nout vec4 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_idecl_lowp = 4016 "uniform isampler2DArray texture_input;\nout ivec4 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_udecl_lowp = 4020 "uniform usampler2DArray texture_input;\nout uvec4 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_fdecl_mediump = 4024 "uniform sampler2DArray texture_input;\nout vec4 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_idecl_mediump = 4028 "uniform isampler2DArray texture_input;\nout ivec4 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_udecl_mediump = 4032 "uniform usampler2DArray texture_input;\nout uvec4 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_fdecl_highp = 4036 "uniform sampler2DArray texture_input;\nout vec4 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_ms_3D_idecl_highp = 4040 "uniform isampler2DArray texture_input;\nout ivec4 texture_output;\n"; 4041 4042 template <typename T, glw::GLint S, bool N, glw::GLuint D> 4043 const glw::GLchar* StorageMultisampleTest<T, S, N, D>::s_fragment_shader_ms_3D_udecl_highp = 4044 "uniform usampler2DArray texture_input;\nout uvec4 texture_output;\n"; 4045 4046 template <typename T, glw::GLint S, bool N, glw::GLuint D> 4047 const glw::GLchar* StorageMultisampleTest<T, S, N, D>::s_fragment_shader_aux_2D_fdecl_lowp = 4048 "uniform sampler2DMS texture_input;\nout vec4 texture_output;\n"; 4049 template <typename T, glw::GLint S, bool N, glw::GLuint D> 4050 const glw::GLchar* StorageMultisampleTest<T, S, N, D>::s_fragment_shader_aux_2D_idecl_lowp = 4051 "uniform isampler2DMS texture_input;\nout ivec4 texture_output;\n"; 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_udecl_lowp = 4054 "uniform usampler2DMS texture_input;\nout uvec4 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_fdecl_mediump = 4058 "uniform sampler2DMS texture_input;\nout vec4 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_idecl_mediump = 4062 "uniform isampler2DMS texture_input;\nout ivec4 texture_output;\n"; 4063 4064 template <typename T, glw::GLint S, bool N, glw::GLuint D> 4065 const glw::GLchar* StorageMultisampleTest<T, S, N, D>::s_fragment_shader_aux_2D_udecl_mediump = 4066 "uniform usampler2DMS texture_input;\nout uvec4 texture_output;\n"; 4067 4068 template <typename T, glw::GLint S, bool N, glw::GLuint D> 4069 const glw::GLchar* StorageMultisampleTest<T, S, N, D>::s_fragment_shader_aux_2D_fdecl_highp = 4070 "uniform sampler2DMS texture_input;\nout vec4 texture_output;\n"; 4071 template <typename T, glw::GLint S, bool N, glw::GLuint D> 4072 const glw::GLchar* StorageMultisampleTest<T, S, N, D>::s_fragment_shader_aux_2D_idecl_highp = 4073 "uniform isampler2DMS texture_input;\nout ivec4 texture_output;\n"; 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_2D_udecl_highp = 4076 "uniform usampler2DMS texture_input;\nout uvec4 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_fdecl_lowp = 4080 "uniform sampler2DMSArray texture_input;\nout vec4 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_idecl_lowp = 4084 "uniform isampler2DMSArray texture_input;\nout ivec4 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_udecl_lowp = 4088 "uniform usampler2DMSArray texture_input;\nout uvec4 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_fdecl_mediump = 4092 "uniform sampler2DMSArray texture_input;\nout vec4 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_idecl_mediump = 4096 "uniform isampler2DMSArray texture_input;\nout ivec4 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_udecl_mediump = 4100 "uniform usampler2DMSArray texture_input;\nout uvec4 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_fdecl_highp = 4104 "uniform sampler2DMSArray texture_input;\nout vec4 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_aux_3D_idecl_highp = 4108 "uniform isampler2DMSArray texture_input;\nout ivec4 texture_output;\n"; 4109 4110 template <typename T, glw::GLint S, bool N, glw::GLuint D> 4111 const glw::GLchar* StorageMultisampleTest<T, S, N, D>::s_fragment_shader_aux_3D_udecl_highp = 4112 "uniform usampler2DMSArray texture_input;\nout uvec4 texture_output;\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_2D = 4116 "\n" 4117 "void main()\n" 4118 "{\n" 4119 " texture_output = texelFetch(texture_input, ivec2(gl_FragCoord.xy), 0);\n" 4120 "}\n"; 4121 4122 template <typename T, glw::GLint S, bool N, glw::GLuint D> 4123 const glw::GLchar* StorageMultisampleTest<T, S, N, D>::s_fragment_shader_tail_3D = 4124 "\n" 4125 "uniform int texture_layer;\n" 4126 "\n" 4127 "void main()\n" 4128 "{\n" 4129 " texture_output = texelFetch(texture_input, ivec3(gl_FragCoord.xy, texture_layer), 0);\n" 4130 "}\n"; 4131 4132 template class StorageMultisampleTest<glw::GLbyte, 1, false, 2>; 4133 template class StorageMultisampleTest<glw::GLbyte, 2, false, 2>; 4134 template class StorageMultisampleTest<glw::GLbyte, 4, false, 2>; 4135 template class StorageMultisampleTest<glw::GLbyte, 1, false, 3>; 4136 template class StorageMultisampleTest<glw::GLbyte, 2, false, 3>; 4137 template class StorageMultisampleTest<glw::GLbyte, 4, false, 3>; 4138 4139 template class StorageMultisampleTest<glw::GLubyte, 1, false, 2>; 4140 template class StorageMultisampleTest<glw::GLubyte, 2, false, 2>; 4141 template class StorageMultisampleTest<glw::GLubyte, 4, false, 2>; 4142 template class StorageMultisampleTest<glw::GLubyte, 1, false, 3>; 4143 template class StorageMultisampleTest<glw::GLubyte, 2, false, 3>; 4144 template class StorageMultisampleTest<glw::GLubyte, 4, false, 3>; 4145 4146 template class StorageMultisampleTest<glw::GLubyte, 1, true, 2>; 4147 template class StorageMultisampleTest<glw::GLubyte, 2, true, 2>; 4148 template class StorageMultisampleTest<glw::GLubyte, 4, true, 2>; 4149 template class StorageMultisampleTest<glw::GLubyte, 1, true, 3>; 4150 template class StorageMultisampleTest<glw::GLubyte, 2, true, 3>; 4151 template class StorageMultisampleTest<glw::GLubyte, 4, true, 3>; 4152 4153 template class StorageMultisampleTest<glw::GLshort, 1, false, 2>; 4154 template class StorageMultisampleTest<glw::GLshort, 2, false, 2>; 4155 template class StorageMultisampleTest<glw::GLshort, 4, false, 2>; 4156 template class StorageMultisampleTest<glw::GLshort, 1, false, 3>; 4157 template class StorageMultisampleTest<glw::GLshort, 2, false, 3>; 4158 template class StorageMultisampleTest<glw::GLshort, 4, false, 3>; 4159 4160 template class StorageMultisampleTest<glw::GLushort, 1, false, 2>; 4161 template class StorageMultisampleTest<glw::GLushort, 2, false, 2>; 4162 template class StorageMultisampleTest<glw::GLushort, 4, false, 2>; 4163 template class StorageMultisampleTest<glw::GLushort, 1, false, 3>; 4164 template class StorageMultisampleTest<glw::GLushort, 2, false, 3>; 4165 template class StorageMultisampleTest<glw::GLushort, 4, false, 3>; 4166 4167 template class StorageMultisampleTest<glw::GLushort, 1, true, 2>; 4168 template class StorageMultisampleTest<glw::GLushort, 2, true, 2>; 4169 template class StorageMultisampleTest<glw::GLushort, 4, true, 2>; 4170 template class StorageMultisampleTest<glw::GLushort, 1, true, 3>; 4171 template class StorageMultisampleTest<glw::GLushort, 2, true, 3>; 4172 template class StorageMultisampleTest<glw::GLushort, 4, true, 3>; 4173 4174 template class StorageMultisampleTest<glw::GLint, 1, false, 2>; 4175 template class StorageMultisampleTest<glw::GLint, 2, false, 2>; 4176 template class StorageMultisampleTest<glw::GLint, 3, false, 2>; 4177 template class StorageMultisampleTest<glw::GLint, 4, false, 2>; 4178 template class StorageMultisampleTest<glw::GLint, 1, false, 3>; 4179 template class StorageMultisampleTest<glw::GLint, 2, false, 3>; 4180 template class StorageMultisampleTest<glw::GLint, 3, false, 3>; 4181 template class StorageMultisampleTest<glw::GLint, 4, false, 3>; 4182 4183 template class StorageMultisampleTest<glw::GLuint, 1, false, 2>; 4184 template class StorageMultisampleTest<glw::GLuint, 2, false, 2>; 4185 template class StorageMultisampleTest<glw::GLuint, 3, false, 2>; 4186 template class StorageMultisampleTest<glw::GLuint, 4, false, 2>; 4187 template class StorageMultisampleTest<glw::GLuint, 1, false, 3>; 4188 template class StorageMultisampleTest<glw::GLuint, 2, false, 3>; 4189 template class StorageMultisampleTest<glw::GLuint, 3, false, 3>; 4190 template class StorageMultisampleTest<glw::GLuint, 4, false, 3>; 4191 4192 template class StorageMultisampleTest<glw::GLfloat, 1, true, 2>; 4193 template class StorageMultisampleTest<glw::GLfloat, 2, true, 2>; 4194 template class StorageMultisampleTest<glw::GLfloat, 3, true, 2>; 4195 template class StorageMultisampleTest<glw::GLfloat, 4, true, 2>; 4196 template class StorageMultisampleTest<glw::GLfloat, 1, true, 3>; 4197 template class StorageMultisampleTest<glw::GLfloat, 2, true, 3>; 4198 template class StorageMultisampleTest<glw::GLfloat, 3, true, 3>; 4199 template class StorageMultisampleTest<glw::GLfloat, 4, true, 3>; 4200 4201 /******************************** Compressed SubImage Test Implementation ********************************/ 4202 4203 /** @brief Compressed SubImage Test constructor. 4204 * 4205 * @param [in] context OpenGL context. 4206 */ 4207 CompressedSubImageTest::CompressedSubImageTest(deqp::Context& context) 4208 : deqp::TestCase(context, "textures_compressed_subimage", "Texture Compressed SubImage Test") 4209 , m_to(0) 4210 , m_to_aux(0) 4211 , m_compressed_texture_data(DE_NULL) 4212 , m_reference(DE_NULL) 4213 , m_result(DE_NULL) 4214 , m_reference_size(0) 4215 , m_reference_internalformat(0) 4216 { 4217 /* Intentionally left blank. */ 4218 } 4219 4220 /** @brief Create texture. 4221 * 4222 * @param [in] target Texture target. 4223 */ 4224 void CompressedSubImageTest::CreateTextures(glw::GLenum target) 4225 { 4226 /* Shortcut for GL functionality. */ 4227 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 4228 4229 /* Auxiliary texture (for content creation). */ 4230 gl.genTextures(1, &m_to_aux); 4231 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed"); 4232 4233 gl.bindTexture(target, m_to_aux); 4234 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed"); 4235 4236 /* Test texture (for data upload). */ 4237 gl.genTextures(1, &m_to); 4238 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed"); 4239 4240 gl.bindTexture(target, m_to); 4241 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed"); 4242 } 4243 4244 /** @brief Texture target selector. 4245 * 4246 * @tparam D Texture dimenisons. 4247 * 4248 * @return Texture target. 4249 */ 4250 template <> 4251 glw::GLenum CompressedSubImageTest::TextureTarget<1>() 4252 { 4253 return GL_TEXTURE_1D; 4254 } 4255 4256 template <> 4257 glw::GLenum CompressedSubImageTest::TextureTarget<2>() 4258 { 4259 return GL_TEXTURE_2D; 4260 } 4261 4262 template <> 4263 glw::GLenum CompressedSubImageTest::TextureTarget<3>() 4264 { 4265 return GL_TEXTURE_2D_ARRAY; 4266 } 4267 4268 /** @brief Prepare texture data for the auxiliary texture. 4269 * 4270 * @tparam D Texture dimenisons. 4271 * 4272 * @note parameters as passed to texImage* 4273 */ 4274 template <> 4275 void CompressedSubImageTest::TextureImage<1>(glw::GLint internalformat) 4276 { 4277 /* Shortcut for GL functionality. */ 4278 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 4279 4280 gl.texImage1D(TextureTarget<1>(), 0, internalformat, s_texture_width, 0, GL_RGBA, GL_UNSIGNED_BYTE, s_texture_data); 4281 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed"); 4282 } 4283 4284 /** @brief Prepare texture data for the auxiliary texture. 4285 * 4286 * @tparam D Texture dimenisons. 4287 * 4288 * @note parameters as passed to texImage* 4289 */ 4290 template <> 4291 void CompressedSubImageTest::TextureImage<2>(glw::GLint internalformat) 4292 { 4293 /* Shortcut for GL functionality. */ 4294 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 4295 4296 gl.texImage2D(TextureTarget<2>(), 0, internalformat, s_texture_width, s_texture_height, 0, GL_RGBA, 4297 GL_UNSIGNED_BYTE, s_texture_data); 4298 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed"); 4299 } 4300 4301 /** @brief Prepare texture data for the auxiliary texture. 4302 * 4303 * @tparam D Texture dimenisons. 4304 * 4305 * @note parameters as passed to texImage* 4306 */ 4307 template <> 4308 void CompressedSubImageTest::TextureImage<3>(glw::GLint internalformat) 4309 { 4310 /* Shortcut for GL functionality. */ 4311 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 4312 4313 gl.texImage3D(TextureTarget<3>(), 0, internalformat, s_texture_width, s_texture_height, s_texture_depth, 0, GL_RGBA, 4314 GL_UNSIGNED_BYTE, s_texture_data); 4315 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage3D has failed"); 4316 } 4317 4318 /** @brief Prepare texture data for the auxiliary texture. 4319 * 4320 * @tparam D Texture dimensions. 4321 * 4322 * @note parameters as passed to compressedTexImage* 4323 */ 4324 template <> 4325 void CompressedSubImageTest::CompressedTexImage<1>(glw::GLint internalformat) 4326 { 4327 /* Shortcut for GL functionality. */ 4328 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 4329 4330 gl.compressedTexImage1D(TextureTarget<1>(), 0, internalformat, s_texture_width, 0, m_reference_size, 4331 m_compressed_texture_data); 4332 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompressedTexImage1D has failed"); 4333 } 4334 4335 /** @brief Prepare texture data for the auxiliary texture. 4336 * 4337 * @tparam D Texture dimensions. 4338 * 4339 * @note parameters as passed to compressedTexImage* 4340 */ 4341 template <> 4342 void CompressedSubImageTest::CompressedTexImage<2>(glw::GLint internalformat) 4343 { 4344 /* Shortcut for GL functionality. */ 4345 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 4346 4347 gl.compressedTexImage2D(TextureTarget<2>(), 0, internalformat, s_texture_width, s_texture_height, 0, 4348 m_reference_size, m_compressed_texture_data); 4349 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompressedTexImage2D has failed"); 4350 } 4351 4352 /** @brief Prepare texture data for the auxiliary texture. 4353 * 4354 * @tparam D Texture dimensions. 4355 * 4356 * @note parameters as passed to compressedTexImage* 4357 */ 4358 template <> 4359 void CompressedSubImageTest::CompressedTexImage<3>(glw::GLint internalformat) 4360 { 4361 /* Shortcut for GL functionality. */ 4362 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 4363 4364 gl.compressedTexImage3D(TextureTarget<3>(), 0, internalformat, s_texture_width, s_texture_height, s_texture_depth, 4365 0, m_reference_size, m_compressed_texture_data); 4366 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompressedTexImage3D has failed"); 4367 } 4368 4369 /** @brief Prepare texture data for the compressed texture. 4370 * 4371 * @tparam D Texture dimenisons. 4372 * 4373 * @param [in] internalformat Texture internal format. 4374 * 4375 * @return True if tested function succeeded, false otherwise. 4376 */ 4377 template <> 4378 bool CompressedSubImageTest::CompressedTextureSubImage<1>(glw::GLint internalformat) 4379 { 4380 /* Shortcut for GL functionality. */ 4381 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 4382 4383 /* Load texture image with tested function. */ 4384 if (m_reference_size) 4385 { 4386 for (glw::GLuint block = 0; block < s_block_count; ++block) 4387 { 4388 gl.compressedTextureSubImage1D(m_to, 0, s_texture_width * block, s_texture_width, internalformat, 4389 m_reference_size, m_compressed_texture_data); 4390 } 4391 } 4392 else 4393 { 4394 /* For 1D version there is no specific compressed texture internal format spcified in OpenGL 4.5 core profile documentation. 4395 Only implementation depended specific internalformats may provide this functionality. As a result there may be no reference data to be substituted. 4396 Due to this reason there is no use of CompressedTextureSubImage1D and particulary it cannot be tested. */ 4397 return true; 4398 } 4399 4400 /* Check errors. */ 4401 glw::GLenum error; 4402 4403 if (GL_NO_ERROR != (error = gl.getError())) 4404 { 4405 m_context.getTestContext().getLog() 4406 << tcu::TestLog::Message << "glCompressedTextureSubImage1D unexpectedly generated error " 4407 << glu::getErrorStr(error) << " during the test with internal format " 4408 << glu::getTextureFormatStr(internalformat) << ". Test fails." << tcu::TestLog::EndMessage; 4409 4410 return false; 4411 } 4412 4413 return true; 4414 } 4415 4416 /** @brief Prepare texture data for the compressed texture. 4417 * 4418 * @tparam D Texture dimenisons. 4419 * 4420 * @param [in] internalformat Texture internal format. 4421 * 4422 * @return True if tested function succeeded, false otherwise. 4423 */ 4424 template <> 4425 bool CompressedSubImageTest::CompressedTextureSubImage<2>(glw::GLint internalformat) 4426 { 4427 /* Shortcut for GL functionality. */ 4428 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 4429 4430 for (glw::GLuint y = 0; y < s_block_2d_size_y; ++y) 4431 { 4432 for (glw::GLuint x = 0; x < s_block_2d_size_x; ++x) 4433 { 4434 /* Load texture image with tested function. */ 4435 gl.compressedTextureSubImage2D(m_to, 0, s_texture_width * x, s_texture_height * y, s_texture_width, 4436 s_texture_height, internalformat, m_reference_size, 4437 m_compressed_texture_data); 4438 } 4439 } 4440 /* Check errors. */ 4441 glw::GLenum error; 4442 4443 if (GL_NO_ERROR != (error = gl.getError())) 4444 { 4445 m_context.getTestContext().getLog() 4446 << tcu::TestLog::Message << "glCompressedTextureSubImage2D unexpectedly generated error " 4447 << glu::getErrorStr(error) << " during the test with internal format " 4448 << glu::getTextureFormatStr(internalformat) << ". Test fails." << tcu::TestLog::EndMessage; 4449 4450 return false; 4451 } 4452 4453 return true; 4454 } 4455 4456 /** @brief Prepare texture data for the compressed texture. 4457 * 4458 * @tparam D Texture dimenisons. 4459 * 4460 * @param [in] internalformat Texture internal format. 4461 * 4462 * @return True if tested function succeeded, false otherwise. 4463 */ 4464 template <> 4465 bool CompressedSubImageTest::CompressedTextureSubImage<3>(glw::GLint internalformat) 4466 { 4467 /* Shortcut for GL functionality. */ 4468 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 4469 4470 for (glw::GLuint z = 0; z < s_block_3d_size; ++z) 4471 { 4472 for (glw::GLuint y = 0; y < s_block_3d_size; ++y) 4473 { 4474 for (glw::GLuint x = 0; x < s_block_3d_size; ++x) 4475 { 4476 /* Load texture image with tested function. */ 4477 gl.compressedTextureSubImage3D(m_to, 0, s_texture_width * x, s_texture_height * y, s_texture_depth * z, 4478 s_texture_width, s_texture_height, s_texture_depth, internalformat, 4479 m_reference_size, m_compressed_texture_data); 4480 } 4481 } 4482 } 4483 4484 /* Check errors. */ 4485 glw::GLenum error; 4486 4487 if (GL_NO_ERROR != (error = gl.getError())) 4488 { 4489 m_context.getTestContext().getLog() 4490 << tcu::TestLog::Message << "glCompressedTextureSubImage2D unexpectedly generated error " 4491 << glu::getErrorStr(error) << " during the test with internal format " 4492 << glu::getTextureFormatStr(internalformat) << ". Test fails." << tcu::TestLog::EndMessage; 4493 4494 return false; 4495 } 4496 return true; 4497 } 4498 4499 /** @brief Prepare the reference data. 4500 * 4501 * @tparam D Texture dimenisons. 4502 */ 4503 template <glw::GLuint D> 4504 void CompressedSubImageTest::PrepareReferenceData(glw::GLenum internalformat) 4505 { 4506 /* Shortcut for GL functionality. */ 4507 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 4508 4509 /* Using OpenGL to compress raw data. */ 4510 gl.bindTexture(TextureTarget<D>(), m_to_aux); 4511 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed"); 4512 4513 TextureImage<D>(internalformat); 4514 4515 /* Sanity checks. */ 4516 if ((DE_NULL != m_reference) || (DE_NULL != m_compressed_texture_data)) 4517 { 4518 throw 0; 4519 } 4520 4521 /* Check that really compressed texture. */ 4522 glw::GLint is_compressed_texture = 0; 4523 gl.getTexLevelParameteriv(TextureTarget<D>(), 0, GL_TEXTURE_COMPRESSED, &is_compressed_texture); 4524 4525 if (is_compressed_texture) 4526 { 4527 /* Query texture size. */ 4528 glw::GLint compressed_texture_size = 0; 4529 gl.getTexLevelParameteriv(TextureTarget<D>(), 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compressed_texture_size); 4530 4531 /* If compressed then download. */ 4532 if (compressed_texture_size) 4533 { 4534 /* Prepare storage. */ 4535 m_compressed_texture_data = new glw::GLubyte[compressed_texture_size]; 4536 4537 if (DE_NULL != m_compressed_texture_data) 4538 { 4539 m_reference_size = compressed_texture_size; 4540 } 4541 else 4542 { 4543 throw 0; 4544 } 4545 4546 /* Download the source compressed texture image. */ 4547 gl.getCompressedTexImage(TextureTarget<D>(), 0, m_compressed_texture_data); 4548 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed"); 4549 4550 // Upload the source compressed texture image to the texture object. 4551 // Some compressed texture format can be emulated by the driver (like the ETC2/EAC formats) 4552 // The compressed data sent by CompressedTexImage will be stored uncompressed by the driver 4553 // and will be re-compressed if the application call glGetCompressedTexImage. 4554 // The compression/decompression is not lossless, so when this happen it's possible for the source 4555 // and destination (from glGetCompressedTexImage) compressed data to be different. 4556 // To avoid that we will store both the source (in m_compressed_texture_data) and the destination 4557 // (in m_reference). The destination will be used later to make sure getCompressedTextureSubImage 4558 // return the expected value 4559 CompressedTexImage<D>(internalformat); 4560 4561 m_reference = new glw::GLubyte[m_reference_size]; 4562 4563 if (DE_NULL == m_reference) 4564 { 4565 throw 0; 4566 } 4567 4568 /* Download compressed texture image. */ 4569 gl.getCompressedTexImage(TextureTarget<D>(), 0, m_reference); 4570 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed"); 4571 } 4572 } 4573 } 4574 4575 /** @brief Prepare texture storage. 4576 * 4577 * @tparam D Texture dimenisons. 4578 * 4579 * @param [in] internalformat Texture internal format. 4580 */ 4581 template <> 4582 void CompressedSubImageTest::PrepareStorage<1>(glw::GLenum internalformat) 4583 { 4584 /* Shortcut for GL functionality. */ 4585 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 4586 4587 gl.bindTexture(TextureTarget<1>(), m_to); 4588 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed"); 4589 4590 gl.texImage1D(TextureTarget<1>(), 0, internalformat, s_texture_width * s_block_count, 0, GL_RGBA, GL_UNSIGNED_BYTE, 4591 NULL); 4592 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed"); 4593 } 4594 4595 /** @brief Prepare texture storage. 4596 * 4597 * @tparam D Texture dimenisons. 4598 * 4599 * @param [in] internalformat Texture internal format. 4600 */ 4601 template <> 4602 void CompressedSubImageTest::PrepareStorage<2>(glw::GLenum internalformat) 4603 { 4604 /* Shortcut for GL functionality. */ 4605 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 4606 4607 gl.bindTexture(TextureTarget<2>(), m_to); 4608 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed"); 4609 4610 gl.texImage2D(TextureTarget<2>(), 0, internalformat, s_texture_width * s_block_2d_size_x, 4611 s_texture_height * s_block_2d_size_y, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); 4612 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed"); 4613 } 4614 4615 /** @brief Prepare texture storage. 4616 * 4617 * @tparam D Texture dimenisons. 4618 * 4619 * @param [in] internalformat Texture internal format. 4620 */ 4621 template <> 4622 void CompressedSubImageTest::PrepareStorage<3>(glw::GLenum internalformat) 4623 { 4624 /* Shortcut for GL functionality. */ 4625 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 4626 4627 gl.bindTexture(TextureTarget<3>(), m_to); 4628 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed"); 4629 4630 gl.texImage3D(TextureTarget<3>(), 0, internalformat, s_texture_width * s_block_3d_size, 4631 s_texture_height * s_block_3d_size, s_texture_depth * s_block_3d_size, 0, GL_RGBA, GL_UNSIGNED_BYTE, 4632 NULL); 4633 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed"); 4634 } 4635 4636 /** @brief Compare results with the reference. 4637 * 4638 * @tparam T Type. 4639 * @tparam S Size (# of components). 4640 * @tparam N Is normalized. 4641 * 4642 * @param [in] internalformat Texture internal format. 4643 * 4644 * @return True if equal, false otherwise. 4645 */ 4646 template <glw::GLuint D> 4647 bool CompressedSubImageTest::CheckData(glw::GLenum internalformat) 4648 { 4649 /* Shortcut for GL functionality. */ 4650 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 4651 4652 /* Check texture content with reference. */ 4653 m_result = new glw::GLubyte[m_reference_size * s_block_count]; 4654 4655 if (DE_NULL == m_result) 4656 { 4657 throw 0; 4658 } 4659 4660 gl.getCompressedTexImage(TextureTarget<D>(), 0, m_result); 4661 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed"); 4662 for (glw::GLuint block = 0; block < s_block_count; ++block) 4663 { 4664 for (glw::GLuint i = 0; i < m_reference_size; ++i) 4665 { 4666 if (m_reference[i] != m_result[block * m_reference_size + i]) 4667 { 4668 m_context.getTestContext().getLog() 4669 << tcu::TestLog::Message << "glCompressedTextureSubImage*D created texture with data " 4670 << DataToString(m_reference_size, m_reference) << " however texture contains data " 4671 << DataToString(m_reference_size, &(m_result[block * m_reference_size])) << ". Texture target was " 4672 << glu::getTextureTargetStr(TextureTarget<D>()) << " and internal format was " 4673 << glu::getTextureFormatStr(internalformat) << ". Test fails." << tcu::TestLog::EndMessage; 4674 4675 return false; 4676 } 4677 } 4678 } 4679 4680 return true; 4681 } 4682 4683 /** @brief Compare results with the reference. 4684 * 4685 * @tparam T Type. 4686 * @tparam S Size (# of components). 4687 * @tparam N Is normalized. 4688 * 4689 * @param [in] internalformat Texture internal format. 4690 * 4691 * @return True if equal, false otherwise. 4692 */ 4693 template <> 4694 bool CompressedSubImageTest::CheckData<3>(glw::GLenum internalformat) 4695 { 4696 /* Shortcut for GL functionality. */ 4697 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 4698 4699 /* Check texture content with reference. */ 4700 m_result = new glw::GLubyte[m_reference_size * s_block_count]; 4701 4702 if (DE_NULL == m_result) 4703 { 4704 throw 0; 4705 } 4706 4707 gl.getCompressedTexImage(TextureTarget<3>(), 0, m_result); 4708 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed"); 4709 4710 glw::GLuint reference_layer_size = m_reference_size / s_texture_depth; 4711 4712 for (glw::GLuint i = 0; i < m_reference_size * s_block_count; ++i) 4713 { 4714 // we will read the result one bytes at the time and compare with the reference 4715 // for each bytes of the result image we need to figure out which byte in the reference image it corresponds to 4716 glw::GLuint refIdx = i % reference_layer_size; 4717 glw::GLuint refLayerIdx = (i / (reference_layer_size * s_block_3d_size * s_block_3d_size)) % s_texture_depth; 4718 if (m_reference[refLayerIdx * reference_layer_size + refIdx] != m_result[i]) 4719 { 4720 m_context.getTestContext().getLog() 4721 << tcu::TestLog::Message << "glCompressedTextureSubImage3D created texture with data " 4722 << DataToString(reference_layer_size, &(m_reference[refLayerIdx * reference_layer_size])) 4723 << " however texture contains data " 4724 << DataToString(reference_layer_size, &(m_result[i % reference_layer_size])) << ". Texture target was " 4725 << glu::getTextureTargetStr(TextureTarget<3>()) << " and internal format was " 4726 << glu::getTextureFormatStr(internalformat) << ". Test fails." << tcu::TestLog::EndMessage; 4727 4728 return false; 4729 } 4730 } 4731 4732 return true; 4733 } 4734 /** @brief Test case function. 4735 * 4736 * @tparam D Number of texture dimensions. 4737 * 4738 * @param [in] internal format Texture internal format. 4739 * 4740 * @return True if test succeeded, false otherwise. 4741 */ 4742 template <glw::GLuint D> 4743 bool CompressedSubImageTest::Test(glw::GLenum internalformat) 4744 { 4745 /* Create texture image. */ 4746 CreateTextures(TextureTarget<D>()); 4747 PrepareReferenceData<D>(internalformat); 4748 PrepareStorage<D>(internalformat); 4749 4750 /* Setup data with CompressedTextureSubImage<D>D function and check for errors. */ 4751 if (!CompressedTextureSubImage<D>(internalformat)) 4752 { 4753 CleanAll(); 4754 4755 return false; 4756 } 4757 4758 /* If compressed reference data was generated than compare values. */ 4759 if (m_reference) 4760 { 4761 if (!CheckData<D>(internalformat)) 4762 { 4763 CleanAll(); 4764 4765 return false; 4766 } 4767 } 4768 4769 CleanAll(); 4770 4771 return true; 4772 } 4773 4774 /** @brief Clean GL objects, test variables and GL errors. 4775 */ 4776 void CompressedSubImageTest::CleanAll() 4777 { 4778 /* Shortcut for GL functionality. */ 4779 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 4780 4781 /* Textures. */ 4782 if (m_to) 4783 { 4784 gl.deleteTextures(1, &m_to); 4785 4786 m_to = 0; 4787 } 4788 4789 if (m_to_aux) 4790 { 4791 gl.deleteTextures(1, &m_to_aux); 4792 4793 m_to_aux = 0; 4794 } 4795 4796 /* Reference data storage. */ 4797 if (DE_NULL != m_reference) 4798 { 4799 delete[] m_reference; 4800 4801 m_reference = DE_NULL; 4802 } 4803 4804 if (DE_NULL != m_compressed_texture_data) 4805 { 4806 delete[] m_compressed_texture_data; 4807 4808 m_compressed_texture_data = DE_NULL; 4809 } 4810 4811 if (DE_NULL != m_result) 4812 { 4813 delete[] m_result; 4814 4815 m_result = DE_NULL; 4816 } 4817 4818 m_reference_size = 0; 4819 4820 /* Errors. */ 4821 while (GL_NO_ERROR != gl.getError()) 4822 ; 4823 } 4824 4825 /** @brief Convert raw data into string for logging purposes. 4826 * 4827 * @param [in] count Count of the data. 4828 * @param [in] data Raw data. 4829 * 4830 * @return String representation of data. 4831 */ 4832 std::string CompressedSubImageTest::DataToString(glw::GLuint count, const glw::GLubyte data[]) 4833 { 4834 std::string data_str = "["; 4835 4836 for (glw::GLuint i = 0; i < count; ++i) 4837 { 4838 std::stringstream int_sstream; 4839 4840 int_sstream << unsigned(data[i]); 4841 4842 data_str.append(int_sstream.str()); 4843 4844 if (i + 1 < count) 4845 { 4846 data_str.append(", "); 4847 } 4848 else 4849 { 4850 data_str.append("]"); 4851 } 4852 } 4853 4854 return data_str; 4855 } 4856 4857 /** @brief Iterate Compressed SubImage Test cases. 4858 * 4859 * @return Iteration result. 4860 */ 4861 tcu::TestNode::IterateResult CompressedSubImageTest::iterate() 4862 { 4863 /* Shortcut for GL functionality. */ 4864 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 4865 4866 /* Get context setup. */ 4867 bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5))); 4868 bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access"); 4869 4870 if ((!is_at_least_gl_45) && (!is_arb_direct_state_access)) 4871 { 4872 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported"); 4873 4874 return STOP; 4875 } 4876 4877 /* Running tests. */ 4878 bool is_ok = true; 4879 bool is_error = false; 4880 4881 try 4882 { 4883 is_ok &= Test<1>(GL_COMPRESSED_RGB); 4884 4885 is_ok &= Test<2>(GL_COMPRESSED_RED_RGTC1); 4886 is_ok &= Test<2>(GL_COMPRESSED_SIGNED_RED_RGTC1); 4887 is_ok &= Test<2>(GL_COMPRESSED_RG_RGTC2); 4888 is_ok &= Test<2>(GL_COMPRESSED_SIGNED_RG_RGTC2); 4889 is_ok &= Test<2>(GL_COMPRESSED_RGBA_BPTC_UNORM); 4890 is_ok &= Test<2>(GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM); 4891 is_ok &= Test<2>(GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT); 4892 is_ok &= Test<2>(GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT); 4893 is_ok &= Test<2>(GL_COMPRESSED_RGB8_ETC2); 4894 is_ok &= Test<2>(GL_COMPRESSED_SRGB8_ETC2); 4895 is_ok &= Test<2>(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2); 4896 is_ok &= Test<2>(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2); 4897 is_ok &= Test<2>(GL_COMPRESSED_RGBA8_ETC2_EAC); 4898 is_ok &= Test<2>(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC); 4899 is_ok &= Test<2>(GL_COMPRESSED_R11_EAC); 4900 is_ok &= Test<2>(GL_COMPRESSED_SIGNED_R11_EAC); 4901 is_ok &= Test<2>(GL_COMPRESSED_RG11_EAC); 4902 is_ok &= Test<2>(GL_COMPRESSED_SIGNED_RG11_EAC); 4903 4904 is_ok &= Test<3>(GL_COMPRESSED_RED_RGTC1); 4905 is_ok &= Test<3>(GL_COMPRESSED_SIGNED_RED_RGTC1); 4906 is_ok &= Test<3>(GL_COMPRESSED_RG_RGTC2); 4907 is_ok &= Test<3>(GL_COMPRESSED_SIGNED_RG_RGTC2); 4908 is_ok &= Test<3>(GL_COMPRESSED_RGBA_BPTC_UNORM); 4909 is_ok &= Test<3>(GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM); 4910 is_ok &= Test<3>(GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT); 4911 is_ok &= Test<3>(GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT); 4912 is_ok &= Test<3>(GL_COMPRESSED_RGB8_ETC2); 4913 is_ok &= Test<3>(GL_COMPRESSED_SRGB8_ETC2); 4914 is_ok &= Test<3>(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2); 4915 is_ok &= Test<3>(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2); 4916 is_ok &= Test<3>(GL_COMPRESSED_RGBA8_ETC2_EAC); 4917 is_ok &= Test<3>(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC); 4918 is_ok &= Test<3>(GL_COMPRESSED_R11_EAC); 4919 is_ok &= Test<3>(GL_COMPRESSED_SIGNED_R11_EAC); 4920 is_ok &= Test<3>(GL_COMPRESSED_RG11_EAC); 4921 is_ok &= Test<3>(GL_COMPRESSED_SIGNED_RG11_EAC); 4922 } 4923 catch (...) 4924 { 4925 is_ok = false; 4926 is_error = true; 4927 } 4928 4929 /* Cleanup. */ 4930 CleanAll(); 4931 4932 /* Errors clean up. */ 4933 while (gl.getError()) 4934 ; 4935 4936 /* Result's setup. */ 4937 if (is_ok) 4938 { 4939 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 4940 } 4941 else 4942 { 4943 if (is_error) 4944 { 4945 m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error"); 4946 } 4947 else 4948 { 4949 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); 4950 } 4951 } 4952 4953 return STOP; 4954 } 4955 4956 /** Reference data. */ 4957 const glw::GLubyte CompressedSubImageTest::s_texture_data[] = { 4958 0x00, 0x00, 0x00, 0xFF, 0x7f, 0x7f, 0x7f, 0x00, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0x00, 4959 0x88, 0x00, 0x15, 0xFF, 0xed, 0x1c, 0x24, 0x00, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x00, 0x00, 4960 0xc8, 0xbf, 0xe7, 0xFF, 0x70, 0x92, 0xbe, 0x00, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0x00, 4961 0xa3, 0x49, 0xa4, 0xFF, 0x3f, 0x48, 0xcc, 0x00, 0x00, 0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0x00, 4962 4963 0xa3, 0x49, 0xa4, 0xFF, 0xc8, 0xbf, 0xe7, 0x00, 0x88, 0x00, 0x15, 0xff, 0x00, 0x00, 0x00, 0x00, 4964 0x3f, 0x48, 0xcc, 0xFF, 0x70, 0x92, 0xbe, 0x00, 0xed, 0x1c, 0x24, 0xff, 0x7f, 0x7f, 0x7f, 0x00, 4965 0x00, 0xa2, 0xe8, 0xFF, 0x99, 0xd9, 0xea, 0x00, 0xff, 0x7f, 0x27, 0xff, 0xc3, 0xc3, 0xc3, 0x00, 4966 0x22, 0xb1, 0x4c, 0xFF, 0xb5, 0xe6, 0x1d, 0x00, 0xff, 0xf2, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 4967 4968 0x22, 0xb1, 0x4c, 0xFF, 0x00, 0xa2, 0xe8, 0x00, 0x3f, 0x48, 0xcc, 0xff, 0xa3, 0x49, 0xa4, 0x00, 4969 0xb5, 0xe6, 0x1d, 0xFF, 0x99, 0xd9, 0xea, 0x00, 0x70, 0x92, 0xbe, 0xff, 0xc8, 0xbf, 0xe7, 0x00, 4970 0xff, 0xf2, 0x00, 0xFF, 0xff, 0x7f, 0x27, 0x00, 0xed, 0x1c, 0x24, 0xff, 0x88, 0x00, 0x15, 0x00, 4971 0xff, 0xff, 0xff, 0xFF, 0xc3, 0xc3, 0xc3, 0x00, 0x7f, 0x7f, 0x7f, 0xff, 0x00, 0x00, 0x00, 0x00, 4972 4973 0xff, 0xff, 0xff, 0xFF, 0xff, 0xf2, 0x00, 0x00, 0xb5, 0xe6, 0x1d, 0xff, 0x22, 0xb1, 0x4c, 0x00, 4974 0xc3, 0xc3, 0xc3, 0xFF, 0xff, 0x7f, 0x27, 0x00, 0x99, 0xd9, 0xea, 0xff, 0x00, 0xa2, 0xe8, 0x00, 4975 0x7f, 0x7f, 0x7f, 0xFF, 0xed, 0x1c, 0x24, 0x00, 0x70, 0x92, 0xbe, 0xff, 0x3f, 0x48, 0xcc, 0x00, 4976 0x00, 0x00, 0x00, 0xFF, 0x88, 0x00, 0x15, 0x00, 0xc8, 0xbf, 0xe7, 0xff, 0xa3, 0x49, 0xa4, 0x00 4977 }; 4978 4979 /** Reference data parameters. */ 4980 const glw::GLuint CompressedSubImageTest::s_texture_width = 4; 4981 const glw::GLuint CompressedSubImageTest::s_texture_height = 4; 4982 const glw::GLuint CompressedSubImageTest::s_texture_depth = 4; 4983 const glw::GLuint CompressedSubImageTest::s_block_count = 8; 4984 const glw::GLuint CompressedSubImageTest::s_block_2d_size_x = 4; 4985 const glw::GLuint CompressedSubImageTest::s_block_2d_size_y = 2; 4986 const glw::GLuint CompressedSubImageTest::s_block_3d_size = 2; 4987 4988 /******************************** Copy SubImage Test Implementation ********************************/ 4989 4990 /** @brief Compressed SubImage Test constructor. 4991 * 4992 * @param [in] context OpenGL context. 4993 */ 4994 CopyTest::CopyTest(deqp::Context& context) 4995 : deqp::TestCase(context, "textures_copy", "Texture Copy Test") 4996 , m_fbo(0) 4997 , m_to_src(0) 4998 , m_to_dst(0) 4999 , m_result(DE_NULL) 5000 { 5001 /* Intentionally left blank. */ 5002 } 5003 5004 /** @brief Texture target selector. 5005 * 5006 * @tparam D Texture dimenisons. 5007 * 5008 * @return Texture target. 5009 */ 5010 template <> 5011 glw::GLenum CopyTest::TextureTarget<1>() 5012 { 5013 return GL_TEXTURE_1D; 5014 } 5015 template <> 5016 glw::GLenum CopyTest::TextureTarget<2>() 5017 { 5018 return GL_TEXTURE_2D; 5019 } 5020 template <> 5021 glw::GLenum CopyTest::TextureTarget<3>() 5022 { 5023 return GL_TEXTURE_3D; 5024 } 5025 5026 /** @brief Copy texture, check errors and log. 5027 * 5028 * @note Parameters as passed to CopyTextureSubImage*D 5029 * 5030 * @return True if no error was generated by CopyTextureSubImage*D, false otherwise 5031 */ 5032 bool CopyTest::CopyTextureSubImage1DAndCheckErrors(glw::GLuint texture, glw::GLint level, glw::GLint xoffset, 5033 glw::GLint x, glw::GLint y, glw::GLsizei width) 5034 { 5035 /* Shortcut for GL functionality. */ 5036 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 5037 5038 gl.readBuffer(GL_COLOR_ATTACHMENT0); 5039 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed"); 5040 5041 gl.copyTextureSubImage1D(texture, level, xoffset, x, y, width); 5042 5043 /* Check errors. */ 5044 glw::GLenum error; 5045 5046 if (GL_NO_ERROR != (error = gl.getError())) 5047 { 5048 m_context.getTestContext().getLog() << tcu::TestLog::Message 5049 << "glCopyTextureSubImage1D unexpectedly generated error " 5050 << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage; 5051 5052 return false; 5053 } 5054 5055 return true; 5056 } 5057 5058 /** @brief Copy texture, check errors and log. 5059 * 5060 * @note Parameters as passed to CopyTextureSubImage*D 5061 * 5062 * @return True if no error was generated by CopyTextureSubImage*D, false otherwise 5063 */ 5064 bool CopyTest::CopyTextureSubImage2DAndCheckErrors(glw::GLuint texture, glw::GLint level, glw::GLint xoffset, 5065 glw::GLint yoffset, glw::GLint x, glw::GLint y, glw::GLsizei width, 5066 glw::GLsizei height) 5067 { 5068 /* Shortcut for GL functionality. */ 5069 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 5070 5071 gl.readBuffer(GL_COLOR_ATTACHMENT0); 5072 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed"); 5073 5074 gl.copyTextureSubImage2D(texture, level, xoffset, yoffset, x, y, width, height); 5075 5076 /* Check errors. */ 5077 glw::GLenum error; 5078 5079 if (GL_NO_ERROR != (error = gl.getError())) 5080 { 5081 m_context.getTestContext().getLog() << tcu::TestLog::Message 5082 << "glCopyTextureSubImage2D unexpectedly generated error " 5083 << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage; 5084 5085 return false; 5086 } 5087 5088 return true; 5089 } 5090 5091 /** @brief Copy texture, check errors and log. 5092 * 5093 * @note Parameters as passed to CopyTextureSubImage*D 5094 * 5095 * @return True if no error was generated by CopyTextureSubImage*D, false otherwise 5096 */ 5097 bool CopyTest::CopyTextureSubImage3DAndCheckErrors(glw::GLuint texture, glw::GLint level, glw::GLint xoffset, 5098 glw::GLint yoffset, glw::GLint zoffset, glw::GLint x, glw::GLint y, 5099 glw::GLsizei width, glw::GLsizei height) 5100 { 5101 /* Shortcut for GL functionality. */ 5102 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 5103 5104 gl.readBuffer(GL_COLOR_ATTACHMENT0 + zoffset); 5105 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed"); 5106 5107 gl.copyTextureSubImage3D(texture, level, xoffset, yoffset, zoffset, x, y, width, height); 5108 5109 /* Check errors. */ 5110 glw::GLenum error; 5111 5112 if (GL_NO_ERROR != (error = gl.getError())) 5113 { 5114 m_context.getTestContext().getLog() << tcu::TestLog::Message 5115 << "glCopyTextureSubImage3D unexpectedly generated error " 5116 << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage; 5117 5118 return false; 5119 } 5120 5121 return true; 5122 } 5123 5124 /** @brief Create texture. 5125 * 5126 * @tparam D Dimmensions. 5127 */ 5128 template <> 5129 void CopyTest::CreateSourceTexture<1>() 5130 { 5131 /* Shortcut for GL functionality. */ 5132 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 5133 5134 gl.genTextures(1, &m_to_src); 5135 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed."); 5136 5137 gl.bindTexture(TextureTarget<1>(), m_to_src); 5138 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed."); 5139 5140 gl.texImage1D(TextureTarget<1>(), 0, GL_RGBA8, s_texture_width, 0, GL_RGBA, GL_UNSIGNED_BYTE, s_texture_data); 5141 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed."); 5142 } 5143 5144 /** @brief Create texture. 5145 * 5146 * @tparam D Dimmensions. 5147 */ 5148 template <> 5149 void CopyTest::CreateSourceTexture<2>() 5150 { 5151 /* Shortcut for GL functionality. */ 5152 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 5153 5154 gl.genTextures(1, &m_to_src); 5155 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed."); 5156 5157 gl.bindTexture(TextureTarget<2>(), m_to_src); 5158 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed."); 5159 5160 gl.texImage2D(TextureTarget<2>(), 0, GL_RGBA8, s_texture_width, s_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 5161 s_texture_data); 5162 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed."); 5163 } 5164 5165 /** @brief Create texture. 5166 * 5167 * @tparam D Dimmensions. 5168 */ 5169 template <> 5170 void CopyTest::CreateSourceTexture<3>() 5171 { 5172 /* Shortcut for GL functionality. */ 5173 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 5174 5175 gl.genTextures(1, &m_to_src); 5176 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed."); 5177 5178 gl.bindTexture(TextureTarget<3>(), m_to_src); 5179 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed."); 5180 5181 gl.texImage3D(TextureTarget<3>(), 0, GL_RGBA8, s_texture_width, s_texture_height, s_texture_depth, 0, GL_RGBA, 5182 GL_UNSIGNED_BYTE, s_texture_data); 5183 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed."); 5184 } 5185 5186 /** @brief Create texture. 5187 * 5188 * @tparam D Dimmensions. 5189 */ 5190 template <> 5191 void CopyTest::CreateDestinationTexture<1>() 5192 { 5193 /* Shortcut for GL functionality. */ 5194 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 5195 5196 gl.genTextures(1, &m_to_dst); 5197 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed."); 5198 5199 gl.bindTexture(TextureTarget<1>(), m_to_dst); 5200 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed."); 5201 5202 gl.texImage1D(TextureTarget<1>(), 0, GL_RGBA8, s_texture_width, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL); 5203 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed."); 5204 } 5205 5206 /** @brief Create texture. 5207 * 5208 * @tparam D Dimmensions. 5209 */ 5210 template <> 5211 void CopyTest::CreateDestinationTexture<2>() 5212 { 5213 /* Shortcut for GL functionality. */ 5214 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 5215 5216 gl.genTextures(1, &m_to_dst); 5217 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed."); 5218 5219 gl.bindTexture(TextureTarget<2>(), m_to_dst); 5220 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed."); 5221 5222 gl.texImage2D(TextureTarget<2>(), 0, GL_RGBA8, s_texture_width, s_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 5223 DE_NULL); 5224 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed."); 5225 } 5226 5227 /** @brief Create texture. 5228 * 5229 * @tparam D Dimmensions. 5230 */ 5231 template <> 5232 void CopyTest::CreateDestinationTexture<3>() 5233 { 5234 /* Shortcut for GL functionality. */ 5235 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 5236 5237 gl.genTextures(1, &m_to_dst); 5238 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed."); 5239 5240 gl.bindTexture(TextureTarget<3>(), m_to_dst); 5241 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed."); 5242 5243 gl.texImage3D(TextureTarget<3>(), 0, GL_RGBA8, s_texture_width, s_texture_height, s_texture_depth, 0, GL_RGBA, 5244 GL_UNSIGNED_BYTE, DE_NULL); 5245 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D call failed."); 5246 } 5247 5248 /** @brief Create framebuffer. 5249 * 5250 * @tparam D Dimmensions. 5251 */ 5252 template <> 5253 void CopyTest::CreateSourceFramebuffer<1>() 5254 { 5255 /* Shortcut for GL functionality. */ 5256 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 5257 5258 /* Prepare framebuffer. */ 5259 gl.genFramebuffers(1, &m_fbo); 5260 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed."); 5261 5262 gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo); 5263 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed."); 5264 5265 gl.framebufferTexture1D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, TextureTarget<1>(), m_to_src, 0); 5266 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture1D call failed."); 5267 5268 if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) 5269 { 5270 throw 0; 5271 } 5272 5273 gl.viewport(0, 0, s_texture_width, 1); 5274 GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed."); 5275 } 5276 5277 /** @brief Create framebuffer. 5278 * 5279 * @tparam D Dimmensions. 5280 */ 5281 template <> 5282 void CopyTest::CreateSourceFramebuffer<2>() 5283 { 5284 /* Shortcut for GL functionality. */ 5285 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 5286 5287 /* Prepare framebuffer. */ 5288 gl.genFramebuffers(1, &m_fbo); 5289 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed."); 5290 5291 gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo); 5292 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed."); 5293 5294 gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, TextureTarget<2>(), m_to_src, 0); 5295 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture1D call failed."); 5296 5297 if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) 5298 { 5299 throw 0; 5300 } 5301 5302 gl.viewport(0, 0, s_texture_width, s_texture_height); 5303 GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed."); 5304 } 5305 5306 /** @brief Create framebuffer. 5307 * 5308 * @tparam D Dimmensions. 5309 */ 5310 template <> 5311 void CopyTest::CreateSourceFramebuffer<3>() 5312 { 5313 /* Shortcut for GL functionality. */ 5314 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 5315 5316 /* Prepare framebuffer. */ 5317 gl.genFramebuffers(1, &m_fbo); 5318 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed."); 5319 5320 gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo); 5321 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed."); 5322 5323 for (glw::GLuint i = 0; i < s_texture_depth; ++i) 5324 { 5325 gl.framebufferTexture3D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, TextureTarget<3>(), m_to_src, 0, i); 5326 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture1D call failed."); 5327 } 5328 5329 if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) 5330 { 5331 throw 0; 5332 } 5333 5334 gl.viewport(0, 0, s_texture_width, s_texture_height); 5335 GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed."); 5336 } 5337 5338 /** @brief Dispatch function to create test objects */ 5339 template <glw::GLuint D> 5340 void CopyTest::CreateAll() 5341 { 5342 CreateSourceTexture<D>(); 5343 CreateSourceFramebuffer<D>(); 5344 CreateDestinationTexture<D>(); 5345 } 5346 5347 /** @brief Test function */ 5348 template <> 5349 bool CopyTest::Test<1>() 5350 { 5351 CreateAll<1>(); 5352 5353 bool result = true; 5354 5355 result &= CopyTextureSubImage1DAndCheckErrors(m_to_dst, 0, 0, 0, 0, s_texture_width / 2); 5356 result &= CopyTextureSubImage1DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, s_texture_width / 2, 0, 5357 s_texture_width / 2); 5358 5359 result &= CheckData(TextureTarget<1>(), 4 /* RGBA */ * s_texture_width); 5360 5361 CleanAll(); 5362 5363 return result; 5364 } 5365 5366 /** @brief Test function */ 5367 template <> 5368 bool CopyTest::Test<2>() 5369 { 5370 CreateAll<2>(); 5371 5372 bool result = true; 5373 5374 result &= CopyTextureSubImage2DAndCheckErrors(m_to_dst, 0, 0, 0, 0, 0, s_texture_width / 2, s_texture_height / 2); 5375 result &= CopyTextureSubImage2DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, 0, s_texture_width / 2, 0, 5376 s_texture_width / 2, s_texture_height / 2); 5377 result &= CopyTextureSubImage2DAndCheckErrors(m_to_dst, 0, 0, s_texture_height / 2, 0, s_texture_height / 2, 5378 s_texture_width / 2, s_texture_height / 2); 5379 result &= 5380 CopyTextureSubImage2DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, s_texture_height / 2, s_texture_width / 2, 5381 s_texture_height / 2, s_texture_width / 2, s_texture_height / 2); 5382 5383 result &= CheckData(TextureTarget<2>(), 4 /* RGBA */ * s_texture_width * s_texture_height); 5384 5385 CleanAll(); 5386 5387 return result; 5388 } 5389 5390 /** @brief Test function */ 5391 template <> 5392 bool CopyTest::Test<3>() 5393 { 5394 CreateAll<3>(); 5395 5396 bool result = true; 5397 5398 for (glw::GLuint i = 0; i < s_texture_depth; ++i) 5399 { 5400 result &= 5401 CopyTextureSubImage3DAndCheckErrors(m_to_dst, 0, 0, 0, i, 0, 0, s_texture_width / 2, s_texture_height / 2); 5402 result &= CopyTextureSubImage3DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, 0, i, s_texture_width / 2, 0, 5403 s_texture_width / 2, s_texture_height / 2); 5404 result &= CopyTextureSubImage3DAndCheckErrors(m_to_dst, 0, 0, s_texture_height / 2, i, 0, s_texture_height / 2, 5405 s_texture_width / 2, s_texture_height / 2); 5406 result &= CopyTextureSubImage3DAndCheckErrors(m_to_dst, 0, s_texture_width / 2, s_texture_height / 2, i, 5407 s_texture_width / 2, s_texture_height / 2, s_texture_width / 2, 5408 s_texture_height / 2); 5409 } 5410 5411 result &= CheckData(TextureTarget<3>(), 4 /* RGBA */ * s_texture_width * s_texture_height * s_texture_depth); 5412 5413 CleanAll(); 5414 5415 return result; 5416 } 5417 5418 /** @brief Compre results with the reference. 5419 * 5420 * @param [in] target Texture target. 5421 * @param [in] size Size of the buffer. 5422 * 5423 * @return True if equal, false otherwise. 5424 */ 5425 bool CopyTest::CheckData(glw::GLenum target, glw::GLuint size) 5426 { 5427 /* Shortcut for GL functionality. */ 5428 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 5429 5430 /* Check texture content with reference. */ 5431 m_result = new glw::GLubyte[size]; 5432 5433 if (DE_NULL == m_result) 5434 { 5435 throw 0; 5436 } 5437 5438 gl.getTexImage(target, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_result); 5439 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetCompressedTexImage has failed"); 5440 5441 for (glw::GLuint i = 0; i < size; ++i) 5442 { 5443 if (s_texture_data[i] != m_result[i]) 5444 { 5445 m_context.getTestContext().getLog() 5446 << tcu::TestLog::Message << "glCopyTextureSubImage*D created texture with data " 5447 << DataToString(size, s_texture_data) << " however texture contains data " 5448 << DataToString(size, m_result) << ". Texture target was " << glu::getTextureTargetStr(target) 5449 << ". Test fails." << tcu::TestLog::EndMessage; 5450 5451 return false; 5452 } 5453 } 5454 5455 return true; 5456 } 5457 5458 /** @brief Convert raw data into string for logging purposes. 5459 * 5460 * @param [in] count Count of the data. 5461 * @param [in] data Raw data. 5462 * 5463 * @return String representation of data. 5464 */ 5465 std::string CopyTest::DataToString(glw::GLuint count, const glw::GLubyte data[]) 5466 { 5467 std::string data_str = "["; 5468 5469 for (glw::GLuint i = 0; i < count; ++i) 5470 { 5471 std::stringstream int_sstream; 5472 5473 int_sstream << unsigned(data[i]); 5474 5475 data_str.append(int_sstream.str()); 5476 5477 if (i + 1 < count) 5478 { 5479 data_str.append(", "); 5480 } 5481 else 5482 { 5483 data_str.append("]"); 5484 } 5485 } 5486 5487 return data_str; 5488 } 5489 5490 /** @brief Clean GL objects, test variables and GL errors. 5491 */ 5492 void CopyTest::CleanAll() 5493 { 5494 /* Shortcut for GL functionality. */ 5495 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 5496 5497 if (m_fbo) 5498 { 5499 gl.deleteFramebuffers(1, &m_fbo); 5500 5501 m_fbo = 0; 5502 } 5503 5504 if (m_to_src) 5505 { 5506 gl.deleteTextures(1, &m_to_src); 5507 5508 m_to_src = 0; 5509 } 5510 5511 if (m_to_dst) 5512 { 5513 gl.deleteTextures(1, &m_to_dst); 5514 5515 m_to_dst = 0; 5516 } 5517 5518 if (DE_NULL == m_result) 5519 { 5520 delete[] m_result; 5521 5522 m_result = DE_NULL; 5523 } 5524 5525 while (GL_NO_ERROR != gl.getError()) 5526 ; 5527 } 5528 5529 /** @brief Iterate Copy Test cases. 5530 * 5531 * @return Iteration result. 5532 */ 5533 tcu::TestNode::IterateResult CopyTest::iterate() 5534 { 5535 /* Get context setup. */ 5536 bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5))); 5537 bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access"); 5538 5539 if ((!is_at_least_gl_45) && (!is_arb_direct_state_access)) 5540 { 5541 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported"); 5542 5543 return STOP; 5544 } 5545 5546 /* Running tests. */ 5547 bool is_ok = true; 5548 bool is_error = false; 5549 5550 try 5551 { 5552 is_ok &= Test<1>(); 5553 is_ok &= Test<2>(); 5554 is_ok &= Test<3>(); 5555 } 5556 catch (...) 5557 { 5558 is_ok = false; 5559 is_error = true; 5560 } 5561 5562 /* Cleanup. */ 5563 CleanAll(); 5564 5565 /* Result's setup. */ 5566 if (is_ok) 5567 { 5568 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 5569 } 5570 else 5571 { 5572 if (is_error) 5573 { 5574 m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error"); 5575 } 5576 else 5577 { 5578 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); 5579 } 5580 } 5581 5582 return STOP; 5583 } 5584 5585 /** Reference data. */ 5586 const glw::GLubyte CopyTest::s_texture_data[] = { 5587 0x00, 0x00, 0x00, 0xFF, 0x7f, 0x7f, 0x7f, 0x00, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0x00, 5588 0x88, 0x00, 0x15, 0xFF, 0xed, 0x1c, 0x24, 0x00, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x00, 0x00, 5589 0xc8, 0xbf, 0xe7, 0xFF, 0x70, 0x92, 0xbe, 0x00, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0x00, 5590 0xa3, 0x49, 0xa4, 0xFF, 0x3f, 0x48, 0xcc, 0x00, 0x00, 0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0x00, 5591 5592 0xa3, 0x49, 0xa4, 0xFF, 0xc8, 0xbf, 0xe7, 0x00, 0x88, 0x00, 0x15, 0xff, 0x00, 0x00, 0x00, 0x00, 5593 0x3f, 0x48, 0xcc, 0xFF, 0x70, 0x92, 0xbe, 0x00, 0xed, 0x1c, 0x24, 0xff, 0x7f, 0x7f, 0x7f, 0x00, 5594 0x00, 0xa2, 0xe8, 0xFF, 0x99, 0xd9, 0xea, 0x00, 0xff, 0x7f, 0x27, 0xff, 0xc3, 0xc3, 0xc3, 0x00, 5595 0x22, 0xb1, 0x4c, 0xFF, 0xb5, 0xe6, 0x1d, 0x00, 0xff, 0xf2, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 5596 5597 0x22, 0xb1, 0x4c, 0xFF, 0x00, 0xa2, 0xe8, 0x00, 0x3f, 0x48, 0xcc, 0xff, 0xa3, 0x49, 0xa4, 0x00, 5598 0xb5, 0xe6, 0x1d, 0xFF, 0x99, 0xd9, 0xea, 0x00, 0x70, 0x92, 0xbe, 0xff, 0xc8, 0xbf, 0xe7, 0x00, 5599 0xff, 0xf2, 0x00, 0xFF, 0xff, 0x7f, 0x27, 0x00, 0xed, 0x1c, 0x24, 0xff, 0x88, 0x00, 0x15, 0x00, 5600 0xff, 0xff, 0xff, 0xFF, 0xc3, 0xc3, 0xc3, 0x00, 0x7f, 0x7f, 0x7f, 0xff, 0x00, 0x00, 0x00, 0x00, 5601 5602 0xff, 0xff, 0xff, 0xFF, 0xff, 0xf2, 0x00, 0x00, 0xb5, 0xe6, 0x1d, 0xff, 0x22, 0xb1, 0x4c, 0x00, 5603 0xc3, 0xc3, 0xc3, 0xFF, 0xff, 0x7f, 0x27, 0x00, 0x99, 0xd9, 0xea, 0xff, 0x00, 0xa2, 0xe8, 0x00, 5604 0x7f, 0x7f, 0x7f, 0xFF, 0xed, 0x1c, 0x24, 0x00, 0x70, 0x92, 0xbe, 0xff, 0x3f, 0x48, 0xcc, 0x00, 5605 0x00, 0x00, 0x00, 0xFF, 0x88, 0x00, 0x15, 0x00, 0xc8, 0xbf, 0xe7, 0xff, 0xa3, 0x49, 0xa4, 0x00 5606 }; 5607 5608 /** Reference data parameters. */ 5609 const glw::GLuint CopyTest::s_texture_width = 4; 5610 const glw::GLuint CopyTest::s_texture_height = 4; 5611 const glw::GLuint CopyTest::s_texture_depth = 4; 5612 5613 /******************************** Get Set Parameter Test Implementation ********************************/ 5614 5615 /** @brief Get Set Parameter Test constructor. 5616 * 5617 * @param [in] context OpenGL context. 5618 */ 5619 GetSetParameterTest::GetSetParameterTest(deqp::Context& context) 5620 : deqp::TestCase(context, "textures_get_set_parameter", "Texture Get Set Parameter Test") 5621 { 5622 /* Intentionally left blank. */ 5623 } 5624 5625 /** @brief Iterate Get Set Parameter Test cases. 5626 * 5627 * @return Iteration result. 5628 */ 5629 tcu::TestNode::IterateResult GetSetParameterTest::iterate() 5630 { 5631 /* Shortcut for GL functionality. */ 5632 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 5633 5634 /* Get context setup. */ 5635 bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5))); 5636 bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access"); 5637 5638 if ((!is_at_least_gl_45) && (!is_arb_direct_state_access)) 5639 { 5640 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported"); 5641 5642 return STOP; 5643 } 5644 5645 /* Running tests. */ 5646 bool is_ok = true; 5647 bool is_error = false; 5648 5649 /* Texture. */ 5650 glw::GLuint texture = 0; 5651 5652 try 5653 { 5654 gl.genTextures(1, &texture); 5655 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed"); 5656 5657 gl.bindTexture(GL_TEXTURE_3D, texture); 5658 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed"); 5659 5660 { 5661 glw::GLenum name = GL_DEPTH_STENCIL_TEXTURE_MODE; 5662 glw::GLint value_src = GL_DEPTH_COMPONENT; 5663 glw::GLint value_dst = 0; 5664 5665 gl.textureParameteri(texture, name, value_src); 5666 is_ok &= CheckErrorAndLog("glTextureParameteri", name); 5667 5668 gl.getTextureParameteriv(texture, name, &value_dst); 5669 is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name); 5670 5671 is_ok &= CompareAndLog(value_src, value_dst, name); 5672 } 5673 5674 { 5675 glw::GLenum name = GL_TEXTURE_BASE_LEVEL; 5676 glw::GLint value_src = 2; 5677 glw::GLint value_dst = 0; 5678 5679 gl.textureParameteri(texture, name, value_src); 5680 is_ok &= CheckErrorAndLog("glTextureParameteri", name); 5681 5682 gl.getTextureParameteriv(texture, name, &value_dst); 5683 is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name); 5684 5685 is_ok &= CompareAndLog(value_src, value_dst, name); 5686 } 5687 5688 { 5689 glw::GLenum name = GL_TEXTURE_BORDER_COLOR; 5690 glw::GLfloat value_src[4] = { 0.25, 0.5, 0.75, 1.0 }; 5691 glw::GLfloat value_dst[4] = {}; 5692 5693 gl.textureParameterfv(texture, name, value_src); 5694 is_ok &= CheckErrorAndLog("glTextureParameterfv", name); 5695 5696 gl.getTextureParameterfv(texture, name, value_dst); 5697 is_ok &= CheckErrorAndLog("glGetTextureParameterfv", name); 5698 5699 is_ok &= CompareAndLog(value_src, value_dst, name); 5700 } 5701 5702 { 5703 glw::GLenum name = GL_TEXTURE_BORDER_COLOR; 5704 glw::GLint value_src[4] = { 0, 64, -64, -32 }; 5705 glw::GLint value_dst[4] = {}; 5706 5707 gl.textureParameterIiv(texture, name, value_src); 5708 is_ok &= CheckErrorAndLog("glTextureParameterIiv", name); 5709 5710 gl.getTextureParameterIiv(texture, name, value_dst); 5711 is_ok &= CheckErrorAndLog("glGetTextureParameterIiv", name); 5712 5713 is_ok &= CompareAndLog(value_src, value_dst, name); 5714 } 5715 5716 { 5717 glw::GLenum name = GL_TEXTURE_BORDER_COLOR; 5718 glw::GLuint value_src[4] = { 0, 64, 128, 192 }; 5719 glw::GLuint value_dst[4] = {}; 5720 5721 gl.textureParameterIuiv(texture, name, value_src); 5722 is_ok &= CheckErrorAndLog("glTextureParameterIuiv", name); 5723 5724 gl.getTextureParameterIuiv(texture, name, value_dst); 5725 is_ok &= CheckErrorAndLog("glGetTextureParameterIuiv", name); 5726 5727 is_ok &= CompareAndLog(value_src, value_dst, name); 5728 } 5729 5730 { 5731 glw::GLenum name = GL_TEXTURE_COMPARE_FUNC; 5732 glw::GLint value_src = GL_LEQUAL; 5733 glw::GLint value_dst = 0; 5734 5735 gl.textureParameteri(texture, name, value_src); 5736 is_ok &= CheckErrorAndLog("glTextureParameteri", name); 5737 5738 gl.getTextureParameteriv(texture, name, &value_dst); 5739 is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name); 5740 5741 is_ok &= CompareAndLog(value_src, value_dst, name); 5742 } 5743 5744 { 5745 glw::GLenum name = GL_TEXTURE_COMPARE_MODE; 5746 glw::GLint value_src = GL_COMPARE_REF_TO_TEXTURE; 5747 glw::GLint value_dst = 0; 5748 5749 gl.textureParameteri(texture, name, value_src); 5750 is_ok &= CheckErrorAndLog("glTextureParameteri", name); 5751 5752 gl.getTextureParameteriv(texture, name, &value_dst); 5753 is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name); 5754 5755 is_ok &= CompareAndLog(value_src, value_dst, name); 5756 } 5757 5758 { 5759 glw::GLenum name = GL_TEXTURE_LOD_BIAS; 5760 glw::GLfloat value_src = -2.f; 5761 glw::GLfloat value_dst = 0.f; 5762 5763 gl.textureParameterf(texture, name, value_src); 5764 is_ok &= CheckErrorAndLog("glTextureParameterf", name); 5765 5766 gl.getTextureParameterfv(texture, name, &value_dst); 5767 is_ok &= CheckErrorAndLog("glGetTextureParameterfv", name); 5768 5769 is_ok &= CompareAndLog(value_src, value_dst, name); 5770 } 5771 5772 { 5773 glw::GLenum name = GL_TEXTURE_MIN_FILTER; 5774 glw::GLint value_src = GL_LINEAR_MIPMAP_NEAREST; 5775 glw::GLint value_dst = 0; 5776 5777 gl.textureParameteri(texture, name, value_src); 5778 is_ok &= CheckErrorAndLog("glTextureParameteri", name); 5779 5780 gl.getTextureParameteriv(texture, name, &value_dst); 5781 is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name); 5782 5783 is_ok &= CompareAndLog(value_src, value_dst, name); 5784 } 5785 5786 { 5787 glw::GLenum name = GL_TEXTURE_MAG_FILTER; 5788 glw::GLint value_src = GL_NEAREST; 5789 glw::GLint value_dst = 0; 5790 5791 gl.textureParameteri(texture, name, value_src); 5792 is_ok &= CheckErrorAndLog("glTextureParameteri", name); 5793 5794 gl.getTextureParameteriv(texture, name, &value_dst); 5795 is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name); 5796 5797 is_ok &= CompareAndLog(value_src, value_dst, name); 5798 } 5799 5800 { 5801 glw::GLenum name = GL_TEXTURE_MIN_LOD; 5802 glw::GLint value_src = -100; 5803 glw::GLint value_dst = 0; 5804 5805 gl.textureParameteri(texture, name, value_src); 5806 is_ok &= CheckErrorAndLog("glTextureParameteri", name); 5807 5808 gl.getTextureParameteriv(texture, name, &value_dst); 5809 is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name); 5810 5811 is_ok &= CompareAndLog(value_src, value_dst, name); 5812 } 5813 5814 { 5815 glw::GLenum name = GL_TEXTURE_MAX_LOD; 5816 glw::GLint value_src = 100; 5817 glw::GLint value_dst = 0; 5818 5819 gl.textureParameteri(texture, name, value_src); 5820 is_ok &= CheckErrorAndLog("glTextureParameteri", name); 5821 5822 gl.getTextureParameteriv(texture, name, &value_dst); 5823 is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name); 5824 5825 is_ok &= CompareAndLog(value_src, value_dst, name); 5826 } 5827 5828 { 5829 glw::GLenum name = GL_TEXTURE_MAX_LEVEL; 5830 glw::GLint value_src = 100; 5831 glw::GLint value_dst = 0; 5832 5833 gl.textureParameteri(texture, name, value_src); 5834 is_ok &= CheckErrorAndLog("glTextureParameteri", name); 5835 5836 gl.getTextureParameteriv(texture, name, &value_dst); 5837 is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name); 5838 5839 is_ok &= CompareAndLog(value_src, value_dst, name); 5840 } 5841 5842 { 5843 glw::GLenum name = GL_TEXTURE_SWIZZLE_R; 5844 glw::GLint value_src = GL_BLUE; 5845 glw::GLint value_dst = 0; 5846 5847 gl.textureParameteri(texture, name, value_src); 5848 is_ok &= CheckErrorAndLog("glTextureParameteri", name); 5849 5850 gl.getTextureParameteriv(texture, name, &value_dst); 5851 is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name); 5852 5853 is_ok &= CompareAndLog(value_src, value_dst, name); 5854 } 5855 5856 { 5857 glw::GLenum name = GL_TEXTURE_SWIZZLE_G; 5858 glw::GLint value_src = GL_ALPHA; 5859 glw::GLint value_dst = 0; 5860 5861 gl.textureParameteri(texture, name, value_src); 5862 is_ok &= CheckErrorAndLog("glTextureParameteri", name); 5863 5864 gl.getTextureParameteriv(texture, name, &value_dst); 5865 is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name); 5866 5867 is_ok &= CompareAndLog(value_src, value_dst, name); 5868 } 5869 5870 { 5871 glw::GLenum name = GL_TEXTURE_SWIZZLE_B; 5872 glw::GLint value_src = GL_RED; 5873 glw::GLint value_dst = 0; 5874 5875 gl.textureParameteri(texture, name, value_src); 5876 is_ok &= CheckErrorAndLog("glTextureParameteri", name); 5877 5878 gl.getTextureParameteriv(texture, name, &value_dst); 5879 is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name); 5880 5881 is_ok &= CompareAndLog(value_src, value_dst, name); 5882 } 5883 5884 { 5885 glw::GLenum name = GL_TEXTURE_SWIZZLE_A; 5886 glw::GLint value_src = GL_GREEN; 5887 glw::GLint value_dst = 0; 5888 5889 gl.textureParameteri(texture, name, value_src); 5890 is_ok &= CheckErrorAndLog("glTextureParameteri", name); 5891 5892 gl.getTextureParameteriv(texture, name, &value_dst); 5893 is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name); 5894 5895 is_ok &= CompareAndLog(value_src, value_dst, name); 5896 } 5897 5898 { 5899 glw::GLenum name = GL_TEXTURE_SWIZZLE_RGBA; 5900 glw::GLint value_src[4] = { GL_ZERO, GL_ONE, GL_ZERO, GL_ONE }; 5901 glw::GLint value_dst[4] = {}; 5902 5903 gl.textureParameteriv(texture, name, value_src); 5904 is_ok &= CheckErrorAndLog("glTextureParameteri", name); 5905 5906 gl.getTextureParameteriv(texture, name, value_dst); 5907 is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name); 5908 5909 is_ok &= CompareAndLog(value_src, value_dst, name); 5910 } 5911 5912 { 5913 glw::GLenum name = GL_TEXTURE_WRAP_S; 5914 glw::GLint value_src = GL_MIRROR_CLAMP_TO_EDGE; 5915 glw::GLint value_dst = 11; 5916 5917 gl.textureParameteri(texture, name, value_src); 5918 is_ok &= CheckErrorAndLog("glTextureParameteri", name); 5919 5920 gl.getTextureParameteriv(texture, name, &value_dst); 5921 is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name); 5922 5923 is_ok &= CompareAndLog(value_src, value_dst, name); 5924 } 5925 5926 { 5927 glw::GLenum name = GL_TEXTURE_WRAP_T; 5928 glw::GLint value_src = GL_CLAMP_TO_EDGE; 5929 glw::GLint value_dst = 11; 5930 5931 gl.textureParameteri(texture, name, value_src); 5932 is_ok &= CheckErrorAndLog("glTextureParameteri", name); 5933 5934 gl.getTextureParameteriv(texture, name, &value_dst); 5935 is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name); 5936 5937 is_ok &= CompareAndLog(value_src, value_dst, name); 5938 } 5939 5940 { 5941 glw::GLenum name = GL_TEXTURE_WRAP_R; 5942 glw::GLint value_src = GL_CLAMP_TO_EDGE; 5943 glw::GLint value_dst = 11; 5944 5945 gl.textureParameteriv(texture, name, &value_src); 5946 is_ok &= CheckErrorAndLog("glTextureParameteri", name); 5947 5948 gl.getTextureParameteriv(texture, name, &value_dst); 5949 is_ok &= CheckErrorAndLog("glGetTextureParameteriv", name); 5950 5951 is_ok &= CompareAndLog(value_src, value_dst, name); 5952 } 5953 } 5954 catch (...) 5955 { 5956 is_ok = false; 5957 is_error = true; 5958 } 5959 5960 /* Cleanup. */ 5961 if (texture) 5962 { 5963 gl.deleteTextures(1, &texture); 5964 } 5965 5966 while (GL_NO_ERROR != gl.getError()) 5967 ; 5968 5969 /* Result's setup. */ 5970 if (is_ok) 5971 { 5972 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 5973 } 5974 else 5975 { 5976 if (is_error) 5977 { 5978 m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error"); 5979 } 5980 else 5981 { 5982 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); 5983 } 5984 } 5985 5986 return STOP; 5987 } 5988 5989 /** @brief Check for errors and log. 5990 * 5991 * @param [in] fname Name of the function (to be logged). 5992 * @param [in] pname Parameter name with which function was called. 5993 * 5994 * @return True if no error, false otherwise. 5995 */ 5996 bool GetSetParameterTest::CheckErrorAndLog(const glw::GLchar* fname, glw::GLenum pname) 5997 { 5998 /* Shortcut for GL functionality. */ 5999 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 6000 6001 /* Check errors. */ 6002 glw::GLenum error; 6003 6004 if (GL_NO_ERROR != (error = gl.getError())) 6005 { 6006 m_context.getTestContext().getLog() << tcu::TestLog::Message << fname << " unexpectedly generated error " 6007 << glu::getErrorStr(error) << " during test of pname " 6008 << glu::getTextureParameterStr(pname) << ". Test fails." 6009 << tcu::TestLog::EndMessage; 6010 6011 return false; 6012 } 6013 6014 return true; 6015 } 6016 6017 /** @brief Compare queried value of parameter with the expected vale. 6018 * 6019 * @param [in] value_src First value. 6020 * @param [in] value_dst Second value. 6021 * @param [in] pname Parameter name. 6022 * 6023 * @return True if no error was generated by CopyTextureSubImage*D, false otherwise 6024 */ 6025 bool GetSetParameterTest::CompareAndLog(glw::GLint value_src, glw::GLint value_dst, glw::GLenum pname) 6026 { 6027 if (value_src != value_dst) 6028 { 6029 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Queried value of pname " 6030 << glu::getTextureParameterStr(pname) << " is equal to " << value_dst 6031 << ", however " << value_src << " was expected. Test fails." 6032 << tcu::TestLog::EndMessage; 6033 6034 return false; 6035 } 6036 6037 return true; 6038 } 6039 6040 /** @brief Compare queried value of parameter with the expected vale. 6041 * 6042 * @param [in] value_src First value. 6043 * @param [in] value_dst Second value. 6044 * @param [in] pname Parameter name. 6045 * 6046 * @return True if no error was generated by CopyTextureSubImage*D, false otherwise 6047 */ 6048 bool GetSetParameterTest::CompareAndLog(glw::GLuint value_src, glw::GLuint value_dst, glw::GLenum pname) 6049 { 6050 if (value_src != value_dst) 6051 { 6052 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Queried value of pname " 6053 << glu::getTextureParameterStr(pname) << " is equal to " << value_dst 6054 << ", however " << value_src << " was expected. Test fails." 6055 << tcu::TestLog::EndMessage; 6056 6057 return false; 6058 } 6059 6060 return true; 6061 } 6062 6063 /** @brief Compare queried value of parameter with the expected vale. 6064 * 6065 * @param [in] value_src First value. 6066 * @param [in] value_dst Second value. 6067 * @param [in] pname Parameter name. 6068 * 6069 * @return True if no error was generated by CopyTextureSubImage*D, false otherwise 6070 */ 6071 bool GetSetParameterTest::CompareAndLog(glw::GLfloat value_src, glw::GLfloat value_dst, glw::GLenum pname) 6072 { 6073 if (de::abs(value_src - value_dst) > 0.0125 /* Precision */) 6074 { 6075 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Queried value of pname " 6076 << glu::getTextureParameterStr(pname) << " is equal to " << value_dst 6077 << ", however " << value_src << " was expected. Test fails." 6078 << tcu::TestLog::EndMessage; 6079 6080 return false; 6081 } 6082 6083 return true; 6084 } 6085 6086 /** @brief Compare queried value of parameter with the expected vale. 6087 * 6088 * @param [in] value_src First value. 6089 * @param [in] value_dst Second value. 6090 * @param [in] pname Parameter name. 6091 * 6092 * @return True if no error was generated by CopyTextureSubImage*D, false otherwise 6093 */ 6094 bool GetSetParameterTest::CompareAndLog(glw::GLint value_src[4], glw::GLint value_dst[4], glw::GLenum pname) 6095 { 6096 if ((value_src[0] != value_dst[0]) || (value_src[1] != value_dst[1]) || (value_src[2] != value_dst[2]) || 6097 (value_src[3] != value_dst[3])) 6098 { 6099 m_context.getTestContext().getLog() 6100 << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname) 6101 << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3] 6102 << "], however " << value_src[0] << ", " << value_src[1] << ", " << value_src[2] << ", " << value_src[3] 6103 << "] was expected. Test fails." << tcu::TestLog::EndMessage; 6104 6105 return false; 6106 } 6107 6108 return true; 6109 } 6110 6111 /** @brief Compare queried value of parameter with the expected vale. 6112 * 6113 * @param [in] value_src First value. 6114 * @param [in] value_dst Second value. 6115 * @param [in] pname Parameter name. 6116 * 6117 * @return True if no error was generated by CopyTextureSubImage*D, false otherwise 6118 */ 6119 bool GetSetParameterTest::CompareAndLog(glw::GLuint value_src[4], glw::GLuint value_dst[4], glw::GLenum pname) 6120 { 6121 if ((value_src[0] != value_dst[0]) || (value_src[1] != value_dst[1]) || (value_src[2] != value_dst[2]) || 6122 (value_src[3] != value_dst[3])) 6123 { 6124 m_context.getTestContext().getLog() 6125 << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname) 6126 << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3] 6127 << "], however " << value_src[0] << ", " << value_src[1] << ", " << value_src[2] << ", " << value_src[3] 6128 << "] was expected. Test fails." << tcu::TestLog::EndMessage; 6129 6130 return false; 6131 } 6132 6133 return true; 6134 } 6135 6136 /** @brief Compare queried value of parameter with the expected vale. 6137 * 6138 * @param [in] value_src First value. 6139 * @param [in] value_dst Second value. 6140 * @param [in] pname Parameter name. 6141 * 6142 * @return True if no error was generated by CopyTextureSubImage*D, false otherwise 6143 */ 6144 bool GetSetParameterTest::CompareAndLog(glw::GLfloat value_src[4], glw::GLfloat value_dst[4], glw::GLenum pname) 6145 { 6146 if ((de::abs(value_src[0] - value_dst[0]) > 0.0125 /* Precision */) || 6147 (de::abs(value_src[1] - value_dst[1]) > 0.0125 /* Precision */) || 6148 (de::abs(value_src[2] - value_dst[2]) > 0.0125 /* Precision */) || 6149 (de::abs(value_src[3] - value_dst[3]) > 0.0125 /* Precision */)) 6150 { 6151 m_context.getTestContext().getLog() 6152 << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname) 6153 << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3] 6154 << "], however " << value_src[0] << ", " << value_src[1] << ", " << value_src[2] << ", " << value_src[3] 6155 << "] was expected. Test fails." << tcu::TestLog::EndMessage; 6156 6157 return false; 6158 } 6159 6160 return true; 6161 } 6162 6163 /******************************** Defaults Test Implementation ********************************/ 6164 6165 /** @brief Defaults Test constructor. 6166 * 6167 * @param [in] context OpenGL context. 6168 */ 6169 DefaultsTest::DefaultsTest(deqp::Context& context) 6170 : deqp::TestCase(context, "textures_defaults", "Texture Defaults Test") 6171 { 6172 /* Intentionally left blank. */ 6173 } 6174 6175 /** @brief Defaults Test cases. 6176 * 6177 * @return Iteration result. 6178 */ 6179 tcu::TestNode::IterateResult DefaultsTest::iterate() 6180 { 6181 /* Shortcut for GL functionality. */ 6182 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 6183 6184 /* Get context setup. */ 6185 bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5))); 6186 bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access"); 6187 6188 if ((!is_at_least_gl_45) && (!is_arb_direct_state_access)) 6189 { 6190 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported"); 6191 6192 return STOP; 6193 } 6194 6195 /* Running tests. */ 6196 bool is_ok = true; 6197 bool is_error = false; 6198 6199 /* Texture. */ 6200 glw::GLuint texture = 0; 6201 6202 try 6203 { 6204 gl.createTextures(GL_TEXTURE_3D, 1, &texture); 6205 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed"); 6206 6207 { 6208 glw::GLenum name = GL_DEPTH_STENCIL_TEXTURE_MODE; 6209 glw::GLint value_ref = GL_DEPTH_COMPONENT; 6210 glw::GLint value_dst = 0; 6211 6212 gl.getTextureParameteriv(texture, name, &value_dst); 6213 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed"); 6214 6215 is_ok &= CompareAndLog(value_ref, value_dst, name); 6216 } 6217 6218 { 6219 glw::GLenum name = GL_TEXTURE_BASE_LEVEL; 6220 glw::GLint value_ref = 0; 6221 glw::GLint value_dst = 1; 6222 6223 gl.getTextureParameteriv(texture, name, &value_dst); 6224 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed"); 6225 6226 is_ok &= CompareAndLog(value_ref, value_dst, name); 6227 } 6228 6229 { 6230 glw::GLenum name = GL_TEXTURE_BORDER_COLOR; 6231 glw::GLfloat value_ref[4] = { 0.f, 0.f, 0.f, 0.f }; 6232 glw::GLfloat value_dst[4] = {}; 6233 6234 gl.getTextureParameterfv(texture, name, value_dst); 6235 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed"); 6236 6237 is_ok &= CompareAndLog(value_ref, value_dst, name); 6238 } 6239 6240 { 6241 glw::GLenum name = GL_TEXTURE_COMPARE_FUNC; 6242 glw::GLint value_ref = GL_LEQUAL; 6243 glw::GLint value_dst = 0; 6244 6245 gl.getTextureParameteriv(texture, name, &value_dst); 6246 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed"); 6247 6248 is_ok &= CompareAndLog(value_ref, value_dst, name); 6249 } 6250 6251 { 6252 glw::GLenum name = GL_TEXTURE_COMPARE_MODE; 6253 glw::GLint value_ref = GL_NONE; 6254 glw::GLint value_dst = 0; 6255 6256 gl.getTextureParameteriv(texture, name, &value_dst); 6257 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed"); 6258 6259 is_ok &= CompareAndLog(value_ref, value_dst, name); 6260 } 6261 6262 { 6263 glw::GLenum name = GL_TEXTURE_LOD_BIAS; 6264 glw::GLfloat value_ref = 0.f; 6265 glw::GLfloat value_dst = 0.f; 6266 6267 gl.getTextureParameterfv(texture, name, &value_dst); 6268 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed"); 6269 6270 is_ok &= CompareAndLog(value_ref, value_dst, name); 6271 } 6272 6273 { 6274 glw::GLenum name = GL_TEXTURE_MIN_FILTER; 6275 glw::GLint value_ref = GL_NEAREST_MIPMAP_LINEAR; 6276 glw::GLint value_dst = 0; 6277 6278 gl.getTextureParameteriv(texture, name, &value_dst); 6279 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed"); 6280 6281 is_ok &= CompareAndLog(value_ref, value_dst, name); 6282 } 6283 6284 { 6285 glw::GLenum name = GL_TEXTURE_MAG_FILTER; 6286 glw::GLint value_ref = GL_LINEAR; 6287 glw::GLint value_dst = 0; 6288 6289 gl.getTextureParameteriv(texture, name, &value_dst); 6290 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed"); 6291 6292 is_ok &= CompareAndLog(value_ref, value_dst, name); 6293 } 6294 6295 { 6296 glw::GLenum name = GL_TEXTURE_MIN_LOD; 6297 glw::GLint value_ref = -1000; 6298 glw::GLint value_dst = 0; 6299 6300 gl.getTextureParameteriv(texture, name, &value_dst); 6301 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed"); 6302 6303 is_ok &= CompareAndLog(value_ref, value_dst, name); 6304 } 6305 6306 { 6307 glw::GLenum name = GL_TEXTURE_MAX_LOD; 6308 glw::GLint value_ref = 1000; 6309 glw::GLint value_dst = 0; 6310 6311 gl.getTextureParameteriv(texture, name, &value_dst); 6312 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed"); 6313 6314 is_ok &= CompareAndLog(value_ref, value_dst, name); 6315 } 6316 6317 { 6318 glw::GLenum name = GL_TEXTURE_MAX_LEVEL; 6319 glw::GLint value_ref = 1000; 6320 glw::GLint value_dst = 0; 6321 6322 gl.getTextureParameteriv(texture, name, &value_dst); 6323 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed"); 6324 6325 is_ok &= CompareAndLog(value_ref, value_dst, name); 6326 } 6327 6328 { 6329 glw::GLenum name = GL_TEXTURE_SWIZZLE_R; 6330 glw::GLint value_ref = GL_RED; 6331 glw::GLint value_dst = 0; 6332 6333 gl.getTextureParameteriv(texture, name, &value_dst); 6334 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed"); 6335 6336 is_ok &= CompareAndLog(value_ref, value_dst, name); 6337 } 6338 6339 { 6340 glw::GLenum name = GL_TEXTURE_SWIZZLE_G; 6341 glw::GLint value_ref = GL_GREEN; 6342 glw::GLint value_dst = 0; 6343 6344 gl.getTextureParameteriv(texture, name, &value_dst); 6345 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed"); 6346 6347 is_ok &= CompareAndLog(value_ref, value_dst, name); 6348 } 6349 6350 { 6351 glw::GLenum name = GL_TEXTURE_SWIZZLE_B; 6352 glw::GLint value_ref = GL_BLUE; 6353 glw::GLint value_dst = 0; 6354 6355 gl.getTextureParameteriv(texture, name, &value_dst); 6356 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed"); 6357 6358 is_ok &= CompareAndLog(value_ref, value_dst, name); 6359 } 6360 6361 { 6362 glw::GLenum name = GL_TEXTURE_SWIZZLE_A; 6363 glw::GLint value_ref = GL_ALPHA; 6364 glw::GLint value_dst = 0; 6365 6366 gl.getTextureParameteriv(texture, name, &value_dst); 6367 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed"); 6368 6369 is_ok &= CompareAndLog(value_ref, value_dst, name); 6370 } 6371 6372 { 6373 glw::GLenum name = GL_TEXTURE_WRAP_S; 6374 glw::GLint value_ref = GL_REPEAT; 6375 glw::GLint value_dst = 11; 6376 6377 gl.getTextureParameteriv(texture, name, &value_dst); 6378 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed"); 6379 6380 is_ok &= CompareAndLog(value_ref, value_dst, name); 6381 } 6382 6383 { 6384 glw::GLenum name = GL_TEXTURE_WRAP_T; 6385 glw::GLint value_ref = GL_REPEAT; 6386 glw::GLint value_dst = 11; 6387 6388 gl.getTextureParameteriv(texture, name, &value_dst); 6389 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed"); 6390 6391 is_ok &= CompareAndLog(value_ref, value_dst, name); 6392 } 6393 6394 { 6395 glw::GLenum name = GL_TEXTURE_WRAP_R; 6396 glw::GLint value_ref = GL_REPEAT; 6397 glw::GLint value_dst = 11; 6398 6399 gl.getTextureParameteriv(texture, name, &value_dst); 6400 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTextureParameter has failed"); 6401 6402 is_ok &= CompareAndLog(value_ref, value_dst, name); 6403 } 6404 } 6405 catch (...) 6406 { 6407 is_ok = false; 6408 is_error = true; 6409 } 6410 6411 /* Cleanup. */ 6412 if (texture) 6413 { 6414 gl.deleteTextures(1, &texture); 6415 } 6416 6417 while (GL_NO_ERROR != gl.getError()) 6418 ; 6419 6420 /* Result's setup. */ 6421 if (is_ok) 6422 { 6423 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 6424 } 6425 else 6426 { 6427 if (is_error) 6428 { 6429 m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error"); 6430 } 6431 else 6432 { 6433 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); 6434 } 6435 } 6436 6437 return STOP; 6438 } 6439 6440 /** @brief Compare queried value of parameter with the expected vale. 6441 * 6442 * @param [in] value_src First value. 6443 * @param [in] value_dst Second value. 6444 * @param [in] pname Parameter name. 6445 * 6446 * @return True if no error was generated by CopyTextureSubImage*D, false otherwise 6447 */ 6448 bool DefaultsTest::CompareAndLog(glw::GLint value_ref, glw::GLint value_dst, glw::GLenum pname) 6449 { 6450 if (value_ref != value_dst) 6451 { 6452 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Queried value of pname " 6453 << glu::getTextureParameterStr(pname) << " is equal to " << value_dst 6454 << ", however " << value_ref << " was expected. Test fails." 6455 << tcu::TestLog::EndMessage; 6456 6457 return false; 6458 } 6459 6460 return true; 6461 } 6462 6463 /** @brief Compare queried value of parameter with the expected vale. 6464 * 6465 * @param [in] value_src First value. 6466 * @param [in] value_dst Second value. 6467 * @param [in] pname Parameter name. 6468 * 6469 * @return True if no error was generated by CopyTextureSubImage*D, false otherwise 6470 */ 6471 bool DefaultsTest::CompareAndLog(glw::GLuint value_ref, glw::GLuint value_dst, glw::GLenum pname) 6472 { 6473 if (value_ref != value_dst) 6474 { 6475 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Queried value of pname " 6476 << glu::getTextureParameterStr(pname) << " is equal to " << value_dst 6477 << ", however " << value_ref << " was expected. Test fails." 6478 << tcu::TestLog::EndMessage; 6479 6480 return false; 6481 } 6482 6483 return true; 6484 } 6485 6486 /** @brief Compare queried value of parameter with the expected vale. 6487 * 6488 * @param [in] value_src First value. 6489 * @param [in] value_dst Second value. 6490 * @param [in] pname Parameter name. 6491 * 6492 * @return True if no error was generated by CopyTextureSubImage*D, false otherwise 6493 */ 6494 bool DefaultsTest::CompareAndLog(glw::GLfloat value_ref, glw::GLfloat value_dst, glw::GLenum pname) 6495 { 6496 if (de::abs(value_ref - value_dst) > 0.0125 /* Precision */) 6497 { 6498 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Queried value of pname " 6499 << glu::getTextureParameterStr(pname) << " is equal to " << value_dst 6500 << ", however " << value_ref << " was expected. Test fails." 6501 << tcu::TestLog::EndMessage; 6502 6503 return false; 6504 } 6505 6506 return true; 6507 } 6508 6509 /** @brief Compare queried value of parameter with the expected vale. 6510 * 6511 * @param [in] value_src First value. 6512 * @param [in] value_dst Second value. 6513 * @param [in] pname Parameter name. 6514 * 6515 * @return True if no error was generated by CopyTextureSubImage*D, false otherwise 6516 */ 6517 bool DefaultsTest::CompareAndLog(glw::GLint value_ref[4], glw::GLint value_dst[4], glw::GLenum pname) 6518 { 6519 if ((value_ref[0] != value_dst[0]) || (value_ref[1] != value_dst[1]) || (value_ref[2] != value_dst[2]) || 6520 (value_ref[3] != value_dst[3])) 6521 { 6522 m_context.getTestContext().getLog() 6523 << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname) 6524 << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3] 6525 << "], however " << value_ref[0] << ", " << value_ref[1] << ", " << value_ref[2] << ", " << value_ref[3] 6526 << "] was expected. Test fails." << tcu::TestLog::EndMessage; 6527 6528 return false; 6529 } 6530 6531 return true; 6532 } 6533 6534 /** @brief Compare queried value of parameter with the expected vale. 6535 * 6536 * @param [in] value_src First value. 6537 * @param [in] value_dst Second value. 6538 * @param [in] pname Parameter name. 6539 * 6540 * @return True if no error was generated by CopyTextureSubImage*D, false otherwise 6541 */ 6542 bool DefaultsTest::CompareAndLog(glw::GLuint value_ref[4], glw::GLuint value_dst[4], glw::GLenum pname) 6543 { 6544 if ((value_ref[0] != value_dst[0]) || (value_ref[1] != value_dst[1]) || (value_ref[2] != value_dst[2]) || 6545 (value_ref[3] != value_dst[3])) 6546 { 6547 m_context.getTestContext().getLog() 6548 << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname) 6549 << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3] 6550 << "], however " << value_ref[0] << ", " << value_ref[1] << ", " << value_ref[2] << ", " << value_ref[3] 6551 << "] was expected. Test fails." << tcu::TestLog::EndMessage; 6552 6553 return false; 6554 } 6555 6556 return true; 6557 } 6558 6559 /** @brief Compare queried value of parameter with the expected vale. 6560 * 6561 * @param [in] value_src First value. 6562 * @param [in] value_dst Second value. 6563 * @param [in] pname Parameter name. 6564 * 6565 * @return True if no error was generated by CopyTextureSubImage*D, false otherwise 6566 */ 6567 bool DefaultsTest::CompareAndLog(glw::GLfloat value_ref[4], glw::GLfloat value_dst[4], glw::GLenum pname) 6568 { 6569 if ((de::abs(value_ref[0] - value_dst[0]) > 0.0125 /* Precision */) || 6570 (de::abs(value_ref[1] - value_dst[1]) > 0.0125 /* Precision */) || 6571 (de::abs(value_ref[2] - value_dst[2]) > 0.0125 /* Precision */) || 6572 (de::abs(value_ref[3] - value_dst[3]) > 0.0125 /* Precision */)) 6573 { 6574 m_context.getTestContext().getLog() 6575 << tcu::TestLog::Message << "Queried value of pname " << glu::getTextureParameterStr(pname) 6576 << " is equal to [" << value_dst[0] << ", " << value_dst[1] << ", " << value_dst[2] << ", " << value_dst[3] 6577 << "], however " << value_ref[0] << ", " << value_ref[1] << ", " << value_ref[2] << ", " << value_ref[3] 6578 << "] was expected. Test fails." << tcu::TestLog::EndMessage; 6579 6580 return false; 6581 } 6582 6583 return true; 6584 } 6585 6586 /******************************** Generate Mipmap Test Implementation ********************************/ 6587 6588 /** @brief Generate Mipmap Test constructor. 6589 * 6590 * @param [in] context OpenGL context. 6591 */ 6592 GenerateMipmapTest::GenerateMipmapTest(deqp::Context& context) 6593 : deqp::TestCase(context, "textures_generate_mipmaps", "Textures Generate Mipmap Test") 6594 { 6595 /* Intentionally left blank. */ 6596 } 6597 6598 /** @brief Generate Mipmap Test cases. 6599 * 6600 * @return Iteration result. 6601 */ 6602 tcu::TestNode::IterateResult GenerateMipmapTest::iterate() 6603 { 6604 /* Shortcut for GL functionality. */ 6605 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 6606 6607 /* Get context setup. */ 6608 bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5))); 6609 bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access"); 6610 6611 if ((!is_at_least_gl_45) && (!is_arb_direct_state_access)) 6612 { 6613 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported"); 6614 6615 return STOP; 6616 } 6617 6618 /* Running tests. */ 6619 bool is_ok = true; 6620 bool is_error = false; 6621 6622 /* Texture and cpu results storage. */ 6623 glw::GLuint texture = 0; 6624 glw::GLubyte* result = DE_NULL; 6625 6626 try 6627 { 6628 /* Prepare texture. */ 6629 gl.genTextures(1, &texture); 6630 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed"); 6631 6632 gl.bindTexture(GL_TEXTURE_1D, texture); 6633 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed"); 6634 6635 gl.texImage1D(GL_TEXTURE_1D, 0, GL_R8, s_texture_width, 0, GL_RED, GL_UNSIGNED_BYTE, s_texture_data); 6636 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed"); 6637 6638 /* Generate mipmaps with tested function. */ 6639 gl.generateTextureMipmap(texture); 6640 6641 glw::GLenum error = GL_NO_ERROR; 6642 6643 if (GL_NO_ERROR != (error = gl.getError())) 6644 { 6645 m_context.getTestContext().getLog() 6646 << tcu::TestLog::Message << "GenerateTextureMipmap unexpectedly generated error " 6647 << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage; 6648 6649 is_ok = false; 6650 } 6651 6652 /* Continue only if mipmaps has been generated. */ 6653 if (is_ok) 6654 { 6655 result = new glw::GLubyte[s_texture_width]; 6656 6657 if (DE_NULL == result) 6658 { 6659 throw 0; 6660 } 6661 6662 /* For each mipmap. */ 6663 for (glw::GLuint i = 0, j = s_texture_width; 6664 i < s_texture_width_log - 1 /* Do not test single pixel mipmap. */; ++i, j /= 2) 6665 { 6666 /* Check mipmap size. */ 6667 glw::GLint mipmap_size = 0; 6668 6669 gl.getTexLevelParameteriv(GL_TEXTURE_1D, i, GL_TEXTURE_WIDTH, &mipmap_size); 6670 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed"); 6671 6672 if (mipmap_size != (glw::GLint)j) 6673 { 6674 m_context.getTestContext().getLog() 6675 << tcu::TestLog::Message 6676 << "GenerateTextureMipmap unexpectedly generated mipmap with improper size. Mipmap size is " 6677 << mipmap_size << ", but " << j << " was expected. Test fails." << tcu::TestLog::EndMessage; 6678 6679 is_ok = false; 6680 6681 break; 6682 } 6683 6684 /* Fetch data. */ 6685 gl.getTexImage(GL_TEXTURE_1D, i, GL_RED, GL_UNSIGNED_BYTE, result); 6686 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexImage has failed"); 6687 6688 /* Make comparison. */ 6689 for (glw::GLuint k = 0; k < j - 1; ++k) 6690 { 6691 if (((glw::GLint)result[k + 1]) - ((glw::GLint)result[k]) < 0) 6692 { 6693 m_context.getTestContext().getLog() << tcu::TestLog::Message 6694 << "GenerateTextureMipmap unexpectedly generated improper " 6695 "mipmap (not descending). Test fails." 6696 << tcu::TestLog::EndMessage; 6697 6698 is_ok = false; 6699 6700 break; 6701 } 6702 } 6703 } 6704 } 6705 } 6706 catch (...) 6707 { 6708 is_ok = false; 6709 is_error = true; 6710 } 6711 6712 /* Cleanup. */ 6713 if (texture) 6714 { 6715 gl.deleteTextures(1, &texture); 6716 } 6717 6718 if (DE_NULL != result) 6719 { 6720 delete[] result; 6721 } 6722 6723 while (GL_NO_ERROR != gl.getError()) 6724 ; 6725 6726 /* Result's setup. */ 6727 if (is_ok) 6728 { 6729 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 6730 } 6731 else 6732 { 6733 if (is_error) 6734 { 6735 m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error"); 6736 } 6737 else 6738 { 6739 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); 6740 } 6741 } 6742 6743 return STOP; 6744 } 6745 6746 /** Reference data. */ 6747 const glw::GLubyte GenerateMipmapTest::s_texture_data[] = { 6748 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 6749 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 6750 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 6751 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 6752 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 6753 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 6754 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 6755 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 6756 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 6757 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 6758 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 6759 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255 6760 }; 6761 6762 /** Reference data parameters. */ 6763 const glw::GLuint GenerateMipmapTest::s_texture_width = 256; 6764 const glw::GLuint GenerateMipmapTest::s_texture_width_log = 8; 6765 6766 /******************************** Bind Unit Test Implementation ********************************/ 6767 6768 /** @brief Bind Unit Test constructor. 6769 * 6770 * @param [in] context OpenGL context. 6771 */ 6772 BindUnitTest::BindUnitTest(deqp::Context& context) 6773 : deqp::TestCase(context, "textures_bind_unit", "Textures Bind Unit Test") 6774 , m_po(0) 6775 , m_fbo(0) 6776 , m_rbo(0) 6777 , m_vao(0) 6778 , m_result(DE_NULL) 6779 { 6780 m_to[0] = 0; 6781 m_to[1] = 0; 6782 m_to[2] = 0; 6783 m_to[3] = 0; 6784 } 6785 6786 /** @brief Bind Unit Test cases. 6787 * 6788 * @return Iteration result. 6789 */ 6790 tcu::TestNode::IterateResult BindUnitTest::iterate() 6791 { 6792 /* Get context setup. */ 6793 bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5))); 6794 bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access"); 6795 6796 if ((!is_at_least_gl_45) && (!is_arb_direct_state_access)) 6797 { 6798 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported"); 6799 6800 return STOP; 6801 } 6802 6803 /* Running tests. */ 6804 bool is_ok = true; 6805 bool is_error = false; 6806 6807 try 6808 { 6809 CreateProgram(); 6810 CreateTextures(); 6811 CreateFrambuffer(); 6812 CreateVertexArray(); 6813 is_ok &= Draw(); 6814 is_ok &= Check(); 6815 } 6816 catch (...) 6817 { 6818 is_ok = false; 6819 is_error = true; 6820 } 6821 6822 /* Cleanup. */ 6823 CleanAll(); 6824 6825 /* Result's setup. */ 6826 if (is_ok) 6827 { 6828 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 6829 } 6830 else 6831 { 6832 if (is_error) 6833 { 6834 m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error"); 6835 } 6836 else 6837 { 6838 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); 6839 } 6840 } 6841 6842 return STOP; 6843 } 6844 6845 /** @brief Create test program. 6846 */ 6847 void BindUnitTest::CreateProgram() 6848 { 6849 /* Shortcut for GL functionality */ 6850 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 6851 6852 struct Shader 6853 { 6854 glw::GLchar const* source; 6855 glw::GLenum const type; 6856 glw::GLuint id; 6857 } shader[] = { { s_vertex_shader, GL_VERTEX_SHADER, 0 }, { s_fragment_shader, GL_FRAGMENT_SHADER, 0 } }; 6858 6859 glw::GLuint const shader_count = sizeof(shader) / sizeof(shader[0]); 6860 6861 try 6862 { 6863 /* Create program. */ 6864 m_po = gl.createProgram(); 6865 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateProgram call failed."); 6866 6867 /* Shader compilation. */ 6868 6869 for (glw::GLuint i = 0; i < shader_count; ++i) 6870 { 6871 if (DE_NULL != shader[i].source) 6872 { 6873 shader[i].id = gl.createShader(shader[i].type); 6874 6875 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateShader call failed."); 6876 6877 gl.attachShader(m_po, shader[i].id); 6878 6879 GLU_EXPECT_NO_ERROR(gl.getError(), "glAttachShader call failed."); 6880 6881 gl.shaderSource(shader[i].id, 1, &shader[i].source, NULL); 6882 6883 GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource call failed."); 6884 6885 gl.compileShader(shader[i].id); 6886 6887 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader call failed."); 6888 6889 glw::GLint status = GL_FALSE; 6890 6891 gl.getShaderiv(shader[i].id, GL_COMPILE_STATUS, &status); 6892 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed."); 6893 6894 if (GL_FALSE == status) 6895 { 6896 glw::GLint log_size = 0; 6897 gl.getShaderiv(shader[i].id, GL_INFO_LOG_LENGTH, &log_size); 6898 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed."); 6899 6900 glw::GLchar* log_text = new glw::GLchar[log_size]; 6901 6902 gl.getShaderInfoLog(shader[i].id, log_size, NULL, &log_text[0]); 6903 6904 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Shader compilation has failed.\n" 6905 << "Shader type: " << glu::getShaderTypeStr(shader[i].type) 6906 << "\n" 6907 << "Shader compilation error log:\n" 6908 << log_text << "\n" 6909 << "Shader source code:\n" 6910 << shader[i].source << "\n" 6911 << tcu::TestLog::EndMessage; 6912 6913 delete[] log_text; 6914 6915 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog call failed."); 6916 6917 throw 0; 6918 } 6919 } 6920 } 6921 6922 /* Link. */ 6923 gl.linkProgram(m_po); 6924 6925 GLU_EXPECT_NO_ERROR(gl.getError(), "glTransformFeedbackVaryings call failed."); 6926 6927 glw::GLint status = GL_FALSE; 6928 6929 gl.getProgramiv(m_po, GL_LINK_STATUS, &status); 6930 6931 if (GL_TRUE == status) 6932 { 6933 for (glw::GLuint i = 0; i < shader_count; ++i) 6934 { 6935 if (shader[i].id) 6936 { 6937 gl.detachShader(m_po, shader[i].id); 6938 6939 GLU_EXPECT_NO_ERROR(gl.getError(), "glDetachShader call failed."); 6940 } 6941 } 6942 } 6943 else 6944 { 6945 glw::GLint log_size = 0; 6946 6947 gl.getProgramiv(m_po, GL_INFO_LOG_LENGTH, &log_size); 6948 6949 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv call failed."); 6950 6951 glw::GLchar* log_text = new glw::GLchar[log_size]; 6952 6953 gl.getProgramInfoLog(m_po, log_size, NULL, &log_text[0]); 6954 6955 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Program linkage has failed due to:\n" 6956 << log_text << "\n" 6957 << tcu::TestLog::EndMessage; 6958 6959 delete[] log_text; 6960 6961 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramInfoLog call failed."); 6962 6963 throw 0; 6964 } 6965 } 6966 catch (...) 6967 { 6968 if (m_po) 6969 { 6970 gl.deleteProgram(m_po); 6971 6972 m_po = 0; 6973 } 6974 } 6975 6976 for (glw::GLuint i = 0; i < shader_count; ++i) 6977 { 6978 if (0 != shader[i].id) 6979 { 6980 gl.deleteShader(shader[i].id); 6981 6982 shader[i].id = 0; 6983 } 6984 } 6985 6986 if (0 == m_po) 6987 { 6988 throw 0; 6989 } 6990 } 6991 6992 /** @brief Create texture. 6993 */ 6994 void BindUnitTest::CreateTextures() 6995 { 6996 /* Shortcut for GL functionality. */ 6997 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 6998 6999 /* Prepare texture. */ 7000 gl.genTextures(4, m_to); 7001 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed"); 7002 7003 /* Setup pixel sotre modes.*/ 7004 gl.pixelStorei(GL_UNPACK_ALIGNMENT, sizeof(glw::GLubyte)); 7005 GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed"); 7006 7007 gl.pixelStorei(GL_PACK_ALIGNMENT, sizeof(glw::GLubyte)); 7008 GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed"); 7009 7010 /* Red texture. */ 7011 gl.bindTexture(GL_TEXTURE_2D, m_to[0]); 7012 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed"); 7013 7014 gl.texImage2D(GL_TEXTURE_2D, 0, GL_R8, s_texture_width, s_texture_height, 0, GL_RED, GL_UNSIGNED_BYTE, 7015 s_texture_data_r); 7016 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed"); 7017 7018 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 7019 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 7020 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed."); 7021 7022 /* Green texture. */ 7023 gl.bindTexture(GL_TEXTURE_2D, m_to[1]); 7024 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed"); 7025 7026 gl.texImage2D(GL_TEXTURE_2D, 0, GL_R8, s_texture_width, s_texture_height, 0, GL_RED, GL_UNSIGNED_BYTE, 7027 s_texture_data_g); 7028 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed"); 7029 7030 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 7031 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 7032 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed."); 7033 7034 /* Blue texture. */ 7035 gl.bindTexture(GL_TEXTURE_2D, m_to[2]); 7036 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed"); 7037 7038 gl.texImage2D(GL_TEXTURE_2D, 0, GL_R8, s_texture_width, s_texture_height, 0, GL_RED, GL_UNSIGNED_BYTE, 7039 s_texture_data_b); 7040 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed"); 7041 7042 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 7043 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 7044 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed."); 7045 7046 /* Alpha texture. */ 7047 gl.bindTexture(GL_TEXTURE_2D, m_to[3]); 7048 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed"); 7049 7050 gl.texImage2D(GL_TEXTURE_2D, 0, GL_R8, s_texture_width, s_texture_height, 0, GL_RED, GL_UNSIGNED_BYTE, 7051 s_texture_data_a); 7052 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage1D has failed"); 7053 7054 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 7055 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 7056 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri call failed."); 7057 } 7058 7059 /** @brief Create framebuffer. 7060 */ 7061 void BindUnitTest::CreateFrambuffer() 7062 { 7063 /* Shortcut for GL functionality. */ 7064 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 7065 7066 /* Prepare framebuffer. */ 7067 gl.genFramebuffers(1, &m_fbo); 7068 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed."); 7069 7070 gl.genRenderbuffers(1, &m_rbo); 7071 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed."); 7072 7073 gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo); 7074 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed."); 7075 7076 gl.bindRenderbuffer(GL_RENDERBUFFER, m_rbo); 7077 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed."); 7078 7079 gl.renderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, s_texture_width, s_texture_height); 7080 GLU_EXPECT_NO_ERROR(gl.getError(), "glRenderbufferStorage call failed."); 7081 7082 gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_rbo); 7083 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed."); 7084 7085 if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) 7086 { 7087 throw 0; 7088 } 7089 7090 gl.viewport(0, 0, s_texture_width, s_texture_height); 7091 GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed."); 7092 7093 /* Clear framebuffer's content. */ 7094 gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f); 7095 GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed."); 7096 7097 gl.clear(GL_COLOR_BUFFER_BIT); 7098 GLU_EXPECT_NO_ERROR(gl.getError(), "glClear call failed."); 7099 } 7100 7101 /** @brief Create vertex array object. 7102 */ 7103 void BindUnitTest::CreateVertexArray() 7104 { 7105 /* Shortcut for GL functionality. */ 7106 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 7107 7108 gl.genVertexArrays(1, &m_vao); 7109 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays call has failed."); 7110 7111 gl.bindVertexArray(m_vao); 7112 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray call has failed."); 7113 } 7114 7115 bool BindUnitTest::Draw() 7116 { 7117 /* Shortcut for GL functionality. */ 7118 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 7119 7120 /* Setup program. */ 7121 gl.useProgram(m_po); 7122 GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram call has failed."); 7123 7124 /* Bind textures to proper units and setup program's samplers. */ 7125 for (glw::GLuint i = 0; i < 4; ++i) 7126 { 7127 /* Tested binding funcion. */ 7128 gl.bindTextureUnit(i, m_to[i]); 7129 7130 /* Check for errors. */ 7131 glw::GLenum error = GL_NO_ERROR; 7132 7133 if (GL_NO_ERROR != (error = gl.getError())) 7134 { 7135 m_context.getTestContext().getLog() 7136 << tcu::TestLog::Message << "BindTextureUnit unexpectedly generated error " << glu::getErrorStr(error) 7137 << " when binding texture " << m_to[i] << " to texture unit " << i << ". Test fails." 7138 << tcu::TestLog::EndMessage; 7139 7140 return false; 7141 } 7142 7143 /* Sampler setup. */ 7144 gl.uniform1i(gl.getUniformLocation(m_po, s_fragment_shader_samplers[i]), i); 7145 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetUniformLocation or glUniform1i call has failed."); 7146 } 7147 7148 /* Draw call. */ 7149 gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4); 7150 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays call has failed."); 7151 7152 return true; 7153 } 7154 7155 /** @brief Compare results with reference. 7156 * 7157 * @return True if equal, false otherwise. 7158 */ 7159 bool BindUnitTest::Check() 7160 { 7161 /* Shortcut for GL functionality. */ 7162 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 7163 7164 /* Setup storage for results. */ 7165 m_result = new glw::GLubyte[s_texture_count_rgba]; 7166 7167 /* Setup pixel sotre modes.*/ 7168 gl.pixelStorei(GL_UNPACK_ALIGNMENT, sizeof(glw::GLubyte)); 7169 GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed"); 7170 7171 gl.pixelStorei(GL_PACK_ALIGNMENT, sizeof(glw::GLubyte)); 7172 GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei has failed"); 7173 7174 /* Query framebuffer's image. */ 7175 gl.readPixels(0, 0, s_texture_width, s_texture_height, GL_RGBA, GL_UNSIGNED_BYTE, m_result); 7176 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays call has failed."); 7177 7178 /* Compare values with reference. */ 7179 for (glw::GLuint i = 0; i < s_texture_count_rgba; ++i) 7180 { 7181 if (s_texture_data_rgba[i] != m_result[i]) 7182 { 7183 m_context.getTestContext().getLog() 7184 << tcu::TestLog::Message << "Framebuffer data " << DataToString(s_texture_count_rgba, m_result) 7185 << " does not match the reference values " << DataToString(s_texture_count_rgba, s_texture_data_rgba) 7186 << "." << tcu::TestLog::EndMessage; 7187 7188 return false; 7189 } 7190 } 7191 7192 return true; 7193 } 7194 7195 /** @brief Clean GL objects, test variables and GL errors. 7196 */ 7197 void BindUnitTest::CleanAll() 7198 { 7199 /* Shortcut for GL functionality. */ 7200 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 7201 7202 /* Release GL objects. */ 7203 if (m_po) 7204 { 7205 gl.useProgram(0); 7206 7207 gl.deleteProgram(m_po); 7208 7209 m_po = 0; 7210 } 7211 7212 if (m_to[0] || m_to[1] || m_to[2] || m_to[3]) 7213 { 7214 gl.deleteTextures(4, m_to); 7215 7216 m_to[0] = 0; 7217 m_to[1] = 0; 7218 m_to[2] = 0; 7219 m_to[3] = 0; 7220 } 7221 7222 if (m_fbo) 7223 { 7224 gl.deleteFramebuffers(1, &m_fbo); 7225 7226 m_fbo = 0; 7227 } 7228 7229 if (m_rbo) 7230 { 7231 gl.deleteRenderbuffers(1, &m_rbo); 7232 7233 m_rbo = 0; 7234 } 7235 7236 /* Release heap. */ 7237 if (DE_NULL != m_result) 7238 { 7239 delete[] m_result; 7240 } 7241 7242 /* Erros clean-up. */ 7243 while (GL_NO_ERROR != gl.getError()) 7244 ; 7245 } 7246 7247 /** @brief Convert raw data into string for logging purposes. 7248 * 7249 * @param [in] count Count of the data. 7250 * @param [in] data Raw data. 7251 * 7252 * @return String representation of data. 7253 */ 7254 std::string BindUnitTest::DataToString(glw::GLuint count, const glw::GLubyte data[]) 7255 { 7256 std::string data_str = "["; 7257 7258 for (glw::GLuint i = 0; i < count; ++i) 7259 { 7260 std::stringstream int_sstream; 7261 7262 int_sstream << unsigned(data[i]); 7263 7264 data_str.append(int_sstream.str()); 7265 7266 if (i + 1 < count) 7267 { 7268 data_str.append(", "); 7269 } 7270 else 7271 { 7272 data_str.append("]"); 7273 } 7274 } 7275 7276 return data_str; 7277 } 7278 7279 /** Reference data and parameters. */ 7280 const glw::GLubyte BindUnitTest::s_texture_data_r[] = { 0, 4, 8, 12, 16, 20 }; 7281 const glw::GLubyte BindUnitTest::s_texture_data_g[] = { 1, 5, 9, 13, 17, 21 }; 7282 const glw::GLubyte BindUnitTest::s_texture_data_b[] = { 2, 6, 10, 14, 18, 22 }; 7283 const glw::GLubyte BindUnitTest::s_texture_data_a[] = { 3, 7, 11, 15, 19, 23 }; 7284 const glw::GLubyte BindUnitTest::s_texture_data_rgba[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 7285 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }; 7286 const glw::GLuint BindUnitTest::s_texture_width = 2; 7287 const glw::GLuint BindUnitTest::s_texture_height = 3; 7288 const glw::GLuint BindUnitTest::s_texture_count_rgba = sizeof(s_texture_data_rgba) / sizeof(s_texture_data_rgba[0]); 7289 7290 /* Vertex shader source code. */ 7291 const glw::GLchar* BindUnitTest::s_vertex_shader = "#version 450\n" 7292 "\n" 7293 "void main()\n" 7294 "{\n" 7295 " switch(gl_VertexID)\n" 7296 " {\n" 7297 " case 0:\n" 7298 " gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n" 7299 " break;\n" 7300 " case 1:\n" 7301 " gl_Position = vec4( 1.0, 1.0, 0.0, 1.0);\n" 7302 " break;\n" 7303 " case 2:\n" 7304 " gl_Position = vec4(-1.0,-1.0, 0.0, 1.0);\n" 7305 " break;\n" 7306 " case 3:\n" 7307 " gl_Position = vec4( 1.0,-1.0, 0.0, 1.0);\n" 7308 " break;\n" 7309 " }\n" 7310 "}\n"; 7311 7312 /* Fragment shader source program. */ 7313 const glw::GLchar* BindUnitTest::s_fragment_shader = 7314 "#version 450\n" 7315 "\n" 7316 "layout(pixel_center_integer) in vec4 gl_FragCoord;\n" 7317 "\n" 7318 "uniform sampler2D texture_input_r;\n" 7319 "uniform sampler2D texture_input_g;\n" 7320 "uniform sampler2D texture_input_b;\n" 7321 "uniform sampler2D texture_input_a;\n" 7322 "\n" 7323 "out vec4 color_output;\n" 7324 "\n" 7325 "void main()\n" 7326 "{\n" 7327 " color_output = vec4(texelFetch(texture_input_r, ivec2(gl_FragCoord.xy), 0).r,\n" 7328 " texelFetch(texture_input_g, ivec2(gl_FragCoord.xy), 0).r,\n" 7329 " texelFetch(texture_input_b, ivec2(gl_FragCoord.xy), 0).r,\n" 7330 " texelFetch(texture_input_a, ivec2(gl_FragCoord.xy), 0).r);\n" 7331 "}\n"; 7332 7333 const glw::GLchar* BindUnitTest::s_fragment_shader_samplers[4] = { "texture_input_r", "texture_input_g", 7334 "texture_input_b", "texture_input_a" }; 7335 7336 /******************************** Get Image Test Implementation ********************************/ 7337 7338 /** @brief Get Image Test constructor. 7339 * 7340 * @param [in] context OpenGL context. 7341 */ 7342 GetImageTest::GetImageTest(deqp::Context& context) 7343 : deqp::TestCase(context, "textures_get_image", "Textures Get Image Test") 7344 { 7345 /* Intentionally left blank */ 7346 } 7347 7348 /** Reference data. */ 7349 const glw::GLubyte GetImageTest::s_texture_data[] = { 0x0, 0x0, 0x0, 0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 7350 0xff, 0xff, 0xff, 0xff, 0xff, 0x88, 0x0, 0x15, 0xff, 0xed, 0x1c, 7351 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0, 0xff, 0xc8, 7352 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 7353 0xb5, 0xe6, 0x1d, 0xff, 0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 7354 0xff, 0x0, 0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff }; 7355 7356 /** Reference data (compressed). */ 7357 const glw::GLubyte GetImageTest::s_texture_data_compressed[] = { 0x90, 0x2b, 0x8f, 0x0f, 0xfe, 0x0f, 0x98, 0x99, 7358 0x99, 0x99, 0x59, 0x8f, 0x8c, 0xa6, 0xb7, 0x71 }; 7359 7360 /** Reference data parameters. */ 7361 const glw::GLuint GetImageTest::s_texture_width = 4; 7362 const glw::GLuint GetImageTest::s_texture_height = 4; 7363 const glw::GLuint GetImageTest::s_texture_size = sizeof(s_texture_data); 7364 const glw::GLuint GetImageTest::s_texture_size_compressed = sizeof(s_texture_data_compressed); 7365 const glw::GLuint GetImageTest::s_texture_count = s_texture_size / sizeof(s_texture_data[0]); 7366 const glw::GLuint GetImageTest::s_texture_count_compressed = 7367 s_texture_size_compressed / sizeof(s_texture_data_compressed[0]); 7368 7369 /** @brief Get Image Test cases. 7370 * 7371 * @return Iteration result. 7372 */ 7373 tcu::TestNode::IterateResult GetImageTest::iterate() 7374 { 7375 /* Shortcut for GL functionality. */ 7376 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 7377 7378 /* Get context setup. */ 7379 bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5))); 7380 bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access"); 7381 7382 if ((!is_at_least_gl_45) && (!is_arb_direct_state_access)) 7383 { 7384 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported"); 7385 7386 return STOP; 7387 } 7388 7389 /* Running tests. */ 7390 bool is_ok = true; 7391 bool is_error = false; 7392 7393 /* Objects. */ 7394 glw::GLuint texture = 0; 7395 glw::GLubyte result[s_texture_count] = {}; 7396 glw::GLubyte result_compressed[s_texture_count_compressed] = {}; 7397 7398 try 7399 { 7400 /* Uncompressed case. */ 7401 { 7402 /* Texture initiation. */ 7403 gl.genTextures(1, &texture); 7404 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed"); 7405 7406 gl.bindTexture(GL_TEXTURE_2D, texture); 7407 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed"); 7408 7409 gl.texImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, s_texture_width, s_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 7410 s_texture_data); 7411 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed"); 7412 7413 /* Quering image with tested function. */ 7414 gl.getTextureImage(texture, 0, GL_RGBA, GL_UNSIGNED_BYTE, sizeof(result), result); 7415 7416 /* Check for errors. */ 7417 glw::GLenum error = GL_NO_ERROR; 7418 7419 if (GL_NO_ERROR != (error = gl.getError())) 7420 { 7421 m_context.getTestContext().getLog() 7422 << tcu::TestLog::Message << "GetTextureImage unexpectedly generated error " 7423 << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage; 7424 7425 is_ok = false; 7426 } 7427 else 7428 { 7429 /* No error, so compare images. */ 7430 for (glw::GLuint i = 0; i < s_texture_count; ++i) 7431 { 7432 if (s_texture_data[i] != result[i]) 7433 { 7434 m_context.getTestContext().getLog() << tcu::TestLog::Message << "GetTextureImage returned " 7435 << DataToString(s_texture_count, result) << ", but " 7436 << DataToString(s_texture_count, s_texture_data) 7437 << " was expected. Test fails." << tcu::TestLog::EndMessage; 7438 7439 is_ok = false; 7440 7441 break; 7442 } 7443 } 7444 } 7445 } 7446 7447 /* Clean up texture .*/ 7448 gl.deleteTextures(1, &texture); 7449 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed"); 7450 7451 texture = 0; 7452 7453 /* Compressed case. */ 7454 { 7455 /* Texture initiation. */ 7456 gl.genTextures(1, &texture); 7457 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed"); 7458 7459 gl.bindTexture(GL_TEXTURE_2D, texture); 7460 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed"); 7461 7462 gl.compressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_BPTC_UNORM, s_texture_width, s_texture_height, 7463 0, s_texture_size_compressed, s_texture_data_compressed); 7464 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompressedTexImage2D has failed"); 7465 7466 /* Quering image with tested function. */ 7467 gl.getCompressedTextureImage(texture, 0, s_texture_count_compressed * sizeof(result_compressed[0]), 7468 result_compressed); 7469 7470 /* Check for errors. */ 7471 glw::GLenum error = GL_NO_ERROR; 7472 7473 if (GL_NO_ERROR != (error = gl.getError())) 7474 { 7475 m_context.getTestContext().getLog() 7476 << tcu::TestLog::Message << "GetCompressedTextureImage unexpectedly generated error " 7477 << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage; 7478 7479 is_ok = false; 7480 } 7481 else 7482 { 7483 /* No error, so compare images. */ 7484 for (glw::GLuint i = 0; i < s_texture_count_compressed; ++i) 7485 { 7486 if (s_texture_data_compressed[i] != result_compressed[i]) 7487 { 7488 m_context.getTestContext().getLog() 7489 << tcu::TestLog::Message << "GetCompressedTextureImage returned " 7490 << DataToString(s_texture_count_compressed, result_compressed) << ", but " 7491 << DataToString(s_texture_count_compressed, s_texture_data_compressed) 7492 << " was expected. Test fails." << tcu::TestLog::EndMessage; 7493 7494 is_ok = false; 7495 7496 break; 7497 } 7498 } 7499 } 7500 } 7501 } 7502 catch (...) 7503 { 7504 is_ok = false; 7505 is_error = true; 7506 } 7507 7508 /* Cleanup. */ 7509 if (texture) 7510 { 7511 gl.deleteTextures(1, &texture); 7512 } 7513 7514 /* Result's setup. */ 7515 if (is_ok) 7516 { 7517 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 7518 } 7519 else 7520 { 7521 if (is_error) 7522 { 7523 m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error"); 7524 } 7525 else 7526 { 7527 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); 7528 } 7529 } 7530 7531 return STOP; 7532 } 7533 7534 /** @brief Convert raw data into string for logging purposes. 7535 * 7536 * @param [in] count Count of the data. 7537 * @param [in] data Raw data. 7538 * 7539 * @return String representation of data. 7540 */ 7541 std::string GetImageTest::DataToString(glw::GLuint count, const glw::GLubyte data[]) 7542 { 7543 std::string data_str = "["; 7544 7545 for (glw::GLuint i = 0; i < count; ++i) 7546 { 7547 std::stringstream int_sstream; 7548 7549 int_sstream << unsigned(data[i]); 7550 7551 data_str.append(int_sstream.str()); 7552 7553 if (i + 1 < count) 7554 { 7555 data_str.append(", "); 7556 } 7557 else 7558 { 7559 data_str.append("]"); 7560 } 7561 } 7562 7563 return data_str; 7564 } 7565 7566 /******************************** Get Level Parameter Test Implementation ********************************/ 7567 7568 /** @brief Get Level Parameter Test constructor. 7569 * 7570 * @param [in] context OpenGL context. 7571 */ 7572 GetLevelParameterTest::GetLevelParameterTest(deqp::Context& context) 7573 : deqp::TestCase(context, "textures_get_level_parameter", "Textures Get Level Parameter Test") 7574 { 7575 /* Intentionally left blank */ 7576 } 7577 7578 /** Reference data. */ 7579 const glw::GLubyte GetLevelParameterTest::s_texture_data[] = { 7580 0x0, 0x0, 0x0, 0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff, 7581 0x88, 0x0, 0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0, 0xff, 7582 0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff, 7583 0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0, 0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff, 7584 7585 0x0, 0x0, 0x0, 0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff, 7586 0x88, 0x0, 0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0, 0xff, 7587 0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff, 7588 0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0, 0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff, 7589 7590 0x0, 0x0, 0x0, 0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff, 7591 0x88, 0x0, 0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0, 0xff, 7592 0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff, 7593 0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0, 0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff, 7594 7595 0x0, 0x0, 0x0, 0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff, 7596 0x88, 0x0, 0x15, 0xff, 0xed, 0x1c, 0x24, 0xff, 0xff, 0x7f, 0x27, 0xff, 0xff, 0xf2, 0x0, 0xff, 7597 0xc8, 0xbf, 0xe7, 0xff, 0x70, 0x92, 0xbe, 0xff, 0x99, 0xd9, 0xea, 0xff, 0xb5, 0xe6, 0x1d, 0xff, 7598 0xa3, 0x49, 0xa4, 0xff, 0x3f, 0x48, 0xcc, 0xff, 0x0, 0xa2, 0xe8, 0xff, 0x22, 0xb1, 0x4c, 0xff 7599 }; 7600 7601 /** Reference data parameters. */ 7602 const glw::GLuint GetLevelParameterTest::s_texture_width = 4; 7603 const glw::GLuint GetLevelParameterTest::s_texture_height = 4; 7604 const glw::GLuint GetLevelParameterTest::s_texture_depth = 4; 7605 7606 /** @brief Get Level Parameter Test cases. 7607 * 7608 * @return Iteration result. 7609 */ 7610 tcu::TestNode::IterateResult GetLevelParameterTest::iterate() 7611 { 7612 /* Shortcut for GL functionality. */ 7613 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 7614 7615 /* Get context setup. */ 7616 bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5))); 7617 bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access"); 7618 7619 if ((!is_at_least_gl_45) && (!is_arb_direct_state_access)) 7620 { 7621 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported"); 7622 7623 return STOP; 7624 } 7625 7626 /* Running tests. */ 7627 bool is_ok = true; 7628 bool is_error = false; 7629 7630 /* Objects. */ 7631 glw::GLuint texture = 0; 7632 7633 try 7634 { 7635 /* Texture initiation. */ 7636 gl.genTextures(1, &texture); 7637 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures has failed"); 7638 7639 gl.bindTexture(GL_TEXTURE_3D, texture); 7640 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture has failed"); 7641 7642 gl.texImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, s_texture_width, s_texture_height, s_texture_depth, 0, GL_RGBA, 7643 GL_UNSIGNED_BYTE, s_texture_data); 7644 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed"); 7645 7646 gl.texImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, s_texture_width / 2, s_texture_height / 2, s_texture_depth / 2, 0, 7647 GL_RGBA, GL_UNSIGNED_BYTE, s_texture_data); 7648 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D has failed"); 7649 7650 static const glw::GLenum pnames[] = { 7651 GL_TEXTURE_WIDTH, GL_TEXTURE_HEIGHT, GL_TEXTURE_DEPTH, GL_TEXTURE_INTERNAL_FORMAT, 7652 GL_TEXTURE_RED_TYPE, GL_TEXTURE_GREEN_TYPE, GL_TEXTURE_BLUE_TYPE, GL_TEXTURE_ALPHA_TYPE, 7653 GL_TEXTURE_DEPTH_TYPE, GL_TEXTURE_RED_SIZE, GL_TEXTURE_GREEN_SIZE, GL_TEXTURE_BLUE_SIZE, 7654 GL_TEXTURE_ALPHA_SIZE, GL_TEXTURE_DEPTH_SIZE, GL_TEXTURE_COMPRESSED 7655 }; 7656 static const glw::GLuint pnames_count = sizeof(pnames) / sizeof(pnames[0]); 7657 7658 /* Test GetTextureLevelParameteriv. */ 7659 for (glw::GLuint i = 0; i < 2 /* levels */; ++i) 7660 { 7661 for (glw::GLuint j = 0; j < pnames_count; ++j) 7662 { 7663 glw::GLint result_legacy = 0; 7664 glw::GLint result_dsa = 0; 7665 7666 /* Quering reference value. */ 7667 gl.getTexLevelParameteriv(GL_TEXTURE_3D, i, pnames[j], &result_legacy); 7668 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameteriv has failed"); 7669 7670 /* Quering using DSA function. */ 7671 gl.getTextureLevelParameteriv(texture, i, pnames[j], &result_dsa); 7672 7673 /* Check for errors. */ 7674 glw::GLenum error = GL_NO_ERROR; 7675 7676 if (GL_NO_ERROR != (error = gl.getError())) 7677 { 7678 m_context.getTestContext().getLog() 7679 << tcu::TestLog::Message << "GetTextureLevelParameteriv unexpectedly generated error " 7680 << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage; 7681 7682 is_ok = false; 7683 } 7684 else 7685 { 7686 /* Compare values. */ 7687 if (result_legacy != result_dsa) 7688 { 7689 m_context.getTestContext().getLog() 7690 << tcu::TestLog::Message << "For parameter name " 7691 << glu::getTextureLevelParameterStr(pnames[j]) << " GetTextureLevelParameteriv returned " 7692 << result_dsa << ", but reference value (queried using GetTexLevelParameteriv) was " 7693 << result_legacy << ". Test fails." << tcu::TestLog::EndMessage; 7694 7695 is_ok = false; 7696 } 7697 } 7698 } 7699 } 7700 7701 /* Test GetTextureLevelParameterfv. */ 7702 for (glw::GLuint i = 0; i < 2 /* levels */; ++i) 7703 { 7704 for (glw::GLuint j = 0; j < pnames_count; ++j) 7705 { 7706 glw::GLfloat result_legacy = 0.f; 7707 glw::GLfloat result_dsa = 0.f; 7708 7709 /* Quering reference value. */ 7710 gl.getTexLevelParameterfv(GL_TEXTURE_3D, i, pnames[j], &result_legacy); 7711 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetTexLevelParameterfv has failed"); 7712 7713 /* Quering using DSA function. */ 7714 gl.getTextureLevelParameterfv(texture, i, pnames[j], &result_dsa); 7715 7716 /* Check for errors. */ 7717 glw::GLenum error = GL_NO_ERROR; 7718 7719 if (GL_NO_ERROR != (error = gl.getError())) 7720 { 7721 m_context.getTestContext().getLog() 7722 << tcu::TestLog::Message << "GetTextureLevelParameterfv unexpectedly generated error " 7723 << glu::getErrorStr(error) << ". Test fails." << tcu::TestLog::EndMessage; 7724 7725 is_ok = false; 7726 } 7727 else 7728 { 7729 /* Compare values. */ 7730 if (de::abs(result_legacy - result_dsa) > 0.125 /* Precision. */) 7731 { 7732 m_context.getTestContext().getLog() 7733 << tcu::TestLog::Message << "For parameter name " 7734 << glu::getTextureLevelParameterStr(pnames[j]) << " GetTextureLevelParameterfv returned " 7735 << result_dsa << ", but reference value (queried using GetTexLevelParameterfv) was " 7736 << result_legacy << ". Test fails." << tcu::TestLog::EndMessage; 7737 7738 is_ok = false; 7739 } 7740 } 7741 } 7742 } 7743 } 7744 catch (...) 7745 { 7746 is_ok = false; 7747 is_error = true; 7748 } 7749 7750 /* Cleanup. */ 7751 if (texture) 7752 { 7753 gl.deleteTextures(1, &texture); 7754 } 7755 7756 while (GL_NO_ERROR != gl.getError()) 7757 ; 7758 7759 /* Result's setup. */ 7760 if (is_ok) 7761 { 7762 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 7763 } 7764 else 7765 { 7766 if (is_error) 7767 { 7768 m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error"); 7769 } 7770 else 7771 { 7772 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); 7773 } 7774 } 7775 7776 return STOP; 7777 } 7778 7779 /*********************************** Errors Utility Class *****************************************************/ 7780 7781 /** @brief Check for errors and log. 7782 * 7783 * @param [in] context Test's context. 7784 * @param [in] expected_error Expected error value. 7785 * @param [in] function_name Name of the function (to be logged). 7786 * @param [in] log Log message. 7787 * 7788 * @return True if error is equal to expected, false otherwise. 7789 */ 7790 bool ErrorsUtilities::CheckErrorAndLog(deqp::Context& context, glw::GLuint expected_error, 7791 const glw::GLchar* function_name, const glw::GLchar* log) 7792 { 7793 /* Shortcut for GL functionality. */ 7794 const glw::Functions& gl = context.getRenderContext().getFunctions(); 7795 7796 /* Check error. */ 7797 glw::GLenum error = GL_NO_ERROR; 7798 7799 if (expected_error != (error = gl.getError())) 7800 { 7801 context.getTestContext().getLog() << tcu::TestLog::Message << function_name << " generated error " 7802 << glu::getErrorStr(error) << " but, " << glu::getErrorStr(expected_error) 7803 << " was expected if " << log << tcu::TestLog::EndMessage; 7804 7805 return false; 7806 } 7807 7808 return true; 7809 } 7810 7811 /******************************** Creation Errors Test Implementation ********************************/ 7812 7813 /** @brief Creation Errors Test constructor. 7814 * 7815 * @param [in] context OpenGL context. 7816 */ 7817 CreationErrorsTest::CreationErrorsTest(deqp::Context& context) 7818 : deqp::TestCase(context, "textures_creation_errors", "Texture Objects Creation Errors Test") 7819 { 7820 /* Intentionally left blank. */ 7821 } 7822 7823 /** @brief Iterate Creation Errors Test cases. 7824 * 7825 * @return Iteration result. 7826 */ 7827 tcu::TestNode::IterateResult CreationErrorsTest::iterate() 7828 { 7829 /* Shortcut for GL functionality. */ 7830 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 7831 7832 /* Get context setup. */ 7833 bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5))); 7834 bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access"); 7835 7836 if ((!is_at_least_gl_45) && (!is_arb_direct_state_access)) 7837 { 7838 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported"); 7839 7840 return STOP; 7841 } 7842 7843 /* Running tests. */ 7844 bool is_ok = true; 7845 bool is_error = false; 7846 7847 /* Textures' objects */ 7848 glw::GLuint texture = 0; 7849 7850 try 7851 { 7852 /* Not a target test. */ 7853 gl.createTextures(NotATarget(), 1, &texture); 7854 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glCreateTextures", 7855 "target is not one of the allowable values."); 7856 7857 if (texture) 7858 { 7859 gl.deleteTextures(1, &texture); 7860 7861 texture = 0; 7862 } 7863 7864 /* Negative number of textures. */ 7865 gl.createTextures(GL_TEXTURE_2D, -1, &texture); 7866 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glCreateTextures", "n is negative."); 7867 } 7868 catch (...) 7869 { 7870 is_ok = false; 7871 is_error = true; 7872 } 7873 7874 /* Cleanup. */ 7875 if (texture) 7876 { 7877 gl.deleteTextures(1, &texture); 7878 } 7879 7880 /* Errors clean up. */ 7881 while (gl.getError()) 7882 ; 7883 7884 /* Result's setup. */ 7885 if (is_ok) 7886 { 7887 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 7888 } 7889 else 7890 { 7891 if (is_error) 7892 { 7893 m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error"); 7894 } 7895 else 7896 { 7897 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); 7898 } 7899 } 7900 7901 return STOP; 7902 } 7903 7904 /** @brief Function retruns enum which is not a texture target. 7905 */ 7906 glw::GLenum CreationErrorsTest::NotATarget() 7907 { 7908 static const glw::GLenum texture_targets[] = { GL_TEXTURE_1D, 7909 GL_TEXTURE_2D, 7910 GL_TEXTURE_3D, 7911 GL_TEXTURE_1D_ARRAY, 7912 GL_TEXTURE_2D_ARRAY, 7913 GL_TEXTURE_RECTANGLE, 7914 GL_TEXTURE_CUBE_MAP, 7915 GL_TEXTURE_CUBE_MAP_ARRAY, 7916 GL_TEXTURE_BUFFER, 7917 GL_TEXTURE_2D_MULTISAMPLE, 7918 GL_TEXTURE_2D_MULTISAMPLE_ARRAY }; 7919 7920 glw::GLenum not_a_target = 0; 7921 bool is_target = true; 7922 7923 while (is_target) 7924 { 7925 not_a_target++; 7926 7927 is_target = false; 7928 7929 for (glw::GLuint i = 0; i < sizeof(texture_targets) / sizeof(texture_targets[0]); ++i) 7930 { 7931 if (texture_targets[i] == not_a_target) 7932 { 7933 is_target = true; 7934 break; 7935 } 7936 } 7937 } 7938 7939 return not_a_target; 7940 } 7941 7942 /******************************** Texture Buffer Errors Test Implementation ********************************/ 7943 7944 /** @brief Texture Buffer Errors Test constructor. 7945 * 7946 * @param [in] context OpenGL context. 7947 */ 7948 BufferErrorsTest::BufferErrorsTest(deqp::Context& context) 7949 : deqp::TestCase(context, "textures_buffer_errors", "Texture Buffer Errors Test") 7950 { 7951 /* Intentionally left blank. */ 7952 } 7953 7954 /** @brief Iterate Texture Buffer Errors Test cases. 7955 * 7956 * @return Iteration result. 7957 */ 7958 tcu::TestNode::IterateResult BufferErrorsTest::iterate() 7959 { 7960 /* Shortcut for GL functionality. */ 7961 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 7962 7963 /* Get context setup. */ 7964 bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5))); 7965 bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access"); 7966 7967 if ((!is_at_least_gl_45) && (!is_arb_direct_state_access)) 7968 { 7969 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported"); 7970 7971 return STOP; 7972 } 7973 7974 /* Running tests. */ 7975 bool is_ok = true; 7976 bool is_error = false; 7977 7978 /* Textures' objects */ 7979 glw::GLuint texture_buffer = 0; 7980 glw::GLuint texture_1D = 0; 7981 glw::GLuint buffer = 0; 7982 7983 static const glw::GLubyte data[4] = { 1, 2, 3, 4 }; 7984 static const glw::GLuint data_size = sizeof(data); 7985 7986 try 7987 { 7988 /* Auxiliary objects setup. */ 7989 gl.createTextures(GL_TEXTURE_BUFFER, 1, &texture_buffer); 7990 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed"); 7991 7992 gl.createTextures(GL_TEXTURE_1D, 1, &texture_1D); 7993 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed"); 7994 7995 gl.createBuffers(1, &buffer); 7996 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateBuffers has failed"); 7997 7998 gl.namedBufferData(buffer, data_size, data, GL_STATIC_COPY); 7999 GLU_EXPECT_NO_ERROR(gl.getError(), "glNamedBufferData has failed"); 8000 8001 /* Check that INVALID_OPERATION is generated by glTextureBuffer if texture 8002 is not the name of an existing texture object. */ 8003 { 8004 glw::GLuint not_a_texture = 0; 8005 8006 while (gl.isTexture(++not_a_texture)) 8007 ; 8008 GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed"); 8009 8010 gl.textureBuffer(not_a_texture, GL_RGBA8, buffer); 8011 8012 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureBuffer", 8013 "texture is not the name of an existing texture object."); 8014 } 8015 8016 /* Check that INVALID_ENUM is generated by glTextureBuffer if the effective 8017 target of texture is not TEXTURE_BUFFER. */ 8018 { 8019 gl.textureBuffer(texture_1D, GL_RGBA8, buffer); 8020 8021 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureBuffer", 8022 "the effective target of texture is not TEXTURE_BUFFER."); 8023 } 8024 8025 /* Check that INVALID_ENUM is generated if internalformat is not one of the 8026 sized internal formats described above. */ 8027 { 8028 gl.textureBuffer(texture_buffer, GL_COMPRESSED_SIGNED_RED_RGTC1, buffer); 8029 8030 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureBuffer", 8031 "internalformat is not one of the sized internal formats described above.."); 8032 } 8033 8034 /* Check that INVALID_OPERATION is generated if buffer is not zero and is 8035 not the name of an existing buffer object. */ 8036 { 8037 glw::GLuint not_a_buffer = 0; 8038 8039 while (gl.isBuffer(++not_a_buffer)) 8040 ; 8041 GLU_EXPECT_NO_ERROR(gl.getError(), "glIsBuffer has failed"); 8042 8043 gl.textureBuffer(texture_buffer, GL_RGBA8, not_a_buffer); 8044 8045 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureBuffer", 8046 "buffer is not zero and is not the name of an existing buffer object."); 8047 } 8048 } 8049 catch (...) 8050 { 8051 is_ok = false; 8052 is_error = true; 8053 } 8054 8055 /* Cleanup. */ 8056 if (texture_1D) 8057 { 8058 gl.deleteTextures(1, &texture_1D); 8059 } 8060 8061 if (texture_buffer) 8062 { 8063 gl.deleteTextures(1, &texture_buffer); 8064 } 8065 8066 if (buffer) 8067 { 8068 gl.deleteBuffers(1, &buffer); 8069 } 8070 8071 /* Errors clean up. */ 8072 while (gl.getError()) 8073 ; 8074 8075 /* Result's setup. */ 8076 if (is_ok) 8077 { 8078 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 8079 } 8080 else 8081 { 8082 if (is_error) 8083 { 8084 m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error"); 8085 } 8086 else 8087 { 8088 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); 8089 } 8090 } 8091 8092 return STOP; 8093 } 8094 8095 /******************************** Texture Buffer Range Errors Test Implementation ********************************/ 8096 8097 /** @brief Texture Buffer Range Errors Test constructor. 8098 * 8099 * @param [in] context OpenGL context. 8100 */ 8101 BufferRangeErrorsTest::BufferRangeErrorsTest(deqp::Context& context) 8102 : deqp::TestCase(context, "textures_buffer_range_errors", "Texture Buffer Range Errors Test") 8103 { 8104 /* Intentionally left blank. */ 8105 } 8106 8107 /** @brief Iterate Texture Buffer Range Errors Test cases. 8108 * 8109 * @return Iteration result. 8110 */ 8111 tcu::TestNode::IterateResult BufferRangeErrorsTest::iterate() 8112 { 8113 /* Shortcut for GL functionality. */ 8114 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 8115 8116 /* Get context setup. */ 8117 bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5))); 8118 bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access"); 8119 8120 if ((!is_at_least_gl_45) && (!is_arb_direct_state_access)) 8121 { 8122 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported"); 8123 8124 return STOP; 8125 } 8126 8127 /* Running tests. */ 8128 bool is_ok = true; 8129 bool is_error = false; 8130 8131 /* Textures' objects */ 8132 glw::GLuint texture_buffer = 0; 8133 glw::GLuint texture_1D = 0; 8134 glw::GLuint buffer = 0; 8135 8136 static const glw::GLubyte data[4] = { 1, 2, 3, 4 }; 8137 static const glw::GLuint data_size = sizeof(data); 8138 8139 try 8140 { 8141 /* Auxiliary objects setup. */ 8142 gl.createTextures(GL_TEXTURE_BUFFER, 1, &texture_buffer); 8143 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed"); 8144 8145 gl.createTextures(GL_TEXTURE_1D, 1, &texture_1D); 8146 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed"); 8147 8148 gl.createBuffers(1, &buffer); 8149 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateBuffers has failed"); 8150 8151 gl.namedBufferData(buffer, data_size, data, GL_STATIC_COPY); 8152 GLU_EXPECT_NO_ERROR(gl.getError(), "glNamedBufferData has failed"); 8153 8154 /* Check that INVALID_OPERATION is generated by TextureBufferRange if 8155 texture is not the name of an existing texture object.*/ 8156 { 8157 glw::GLuint not_a_texture = 0; 8158 8159 while (gl.isTexture(++not_a_texture)) 8160 ; 8161 GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed"); 8162 8163 gl.textureBufferRange(not_a_texture, GL_RGBA8, buffer, 0, data_size); 8164 8165 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureBufferRange", 8166 "texture is not the name of an existing texture object."); 8167 } 8168 8169 /* Check that INVALID_ENUM is generated by TextureBufferRange if the 8170 effective target of texture is not TEXTURE_BUFFER. */ 8171 { 8172 gl.textureBufferRange(texture_1D, GL_RGBA8, buffer, 0, data_size); 8173 8174 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureBufferRange", 8175 "the effective target of texture is not TEXTURE_BUFFER."); 8176 } 8177 8178 /* Check that INVALID_ENUM is generated by TextureBufferRange if 8179 internalformat is not one of the sized internal formats described above. */ 8180 { 8181 gl.textureBufferRange(texture_buffer, GL_COMPRESSED_SIGNED_RED_RGTC1, buffer, 0, data_size); 8182 8183 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureBufferRange", 8184 "internalformat is not one of the supported sized internal formats."); 8185 } 8186 8187 /* Check that INVALID_OPERATION is generated by TextureBufferRange if 8188 buffer is not zero and is not the name of an existing buffer object. */ 8189 { 8190 glw::GLuint not_a_buffer = 0; 8191 8192 while (gl.isBuffer(++not_a_buffer)) 8193 ; 8194 GLU_EXPECT_NO_ERROR(gl.getError(), "glIsBuffer has failed"); 8195 8196 gl.textureBufferRange(texture_buffer, GL_RGBA8, not_a_buffer, 0, data_size); 8197 8198 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureBufferRange", 8199 "buffer is not zero and is not the name of an existing buffer object."); 8200 } 8201 8202 /* Check that INVALID_VALUE is generated by TextureBufferRange if offset 8203 is negative, if size is less than or equal to zero, or if offset + size 8204 is greater than the value of BUFFER_SIZE for buffer. */ 8205 { 8206 gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, -1, data_size); 8207 8208 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureBufferRange", "offset is negative."); 8209 8210 gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, 0, 0); 8211 8212 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureBufferRange", "size is zero."); 8213 8214 gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, 0, -1); 8215 8216 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureBufferRange", "size is negative."); 8217 8218 gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, 0, data_size * 16); 8219 8220 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureBufferRange", 8221 "size is greater than the value of BUFFER_SIZE for buffer."); 8222 } 8223 8224 /* Check that INVALID_VALUE is generated by TextureBufferRange if offset is 8225 not an integer multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT. */ 8226 { 8227 glw::GLint gl_texture_buffer_offset_alignment = 0; 8228 8229 gl.getIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, &gl_texture_buffer_offset_alignment); 8230 8231 /* If alignmet is 1 we cannot do anything. Error situtation is impossible then. */ 8232 if (gl_texture_buffer_offset_alignment > 1) 8233 { 8234 gl.textureBufferRange(texture_buffer, GL_RGBA8, buffer, 1, data_size - 1); 8235 8236 is_ok &= CheckErrorAndLog( 8237 m_context, GL_INVALID_VALUE, "glTextureBufferRange", 8238 "offset is not an integer multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT."); 8239 } 8240 } 8241 } 8242 catch (...) 8243 { 8244 is_ok = false; 8245 is_error = true; 8246 } 8247 8248 /* Cleanup. */ 8249 if (texture_1D) 8250 { 8251 gl.deleteTextures(1, &texture_1D); 8252 } 8253 8254 if (texture_buffer) 8255 { 8256 gl.deleteTextures(1, &texture_buffer); 8257 } 8258 8259 if (buffer) 8260 { 8261 gl.deleteBuffers(1, &buffer); 8262 } 8263 8264 /* Errors clean up. */ 8265 while (gl.getError()) 8266 ; 8267 8268 /* Result's setup. */ 8269 if (is_ok) 8270 { 8271 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 8272 } 8273 else 8274 { 8275 if (is_error) 8276 { 8277 m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error"); 8278 } 8279 else 8280 { 8281 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); 8282 } 8283 } 8284 8285 return STOP; 8286 } 8287 8288 /******************************** Texture Storage Errors Test Implementation ********************************/ 8289 8290 /** @brief Texture Storage Errors Test constructor. 8291 * 8292 * @param [in] context OpenGL context. 8293 */ 8294 StorageErrorsTest::StorageErrorsTest(deqp::Context& context) 8295 : deqp::TestCase(context, "textures_storage_errors", "Texture Storage Errors Test") 8296 , m_to_1D(0) 8297 , m_to_1D_array(0) 8298 , m_to_2D(0) 8299 , m_to_2D_array(0) 8300 , m_to_3D(0) 8301 , m_to_2D_ms(0) 8302 , m_to_2D_ms_immutable(0) 8303 , m_to_3D_ms(0) 8304 , m_to_3D_ms_immutable(0) 8305 , m_to_invalid(0) 8306 , m_internalformat_invalid(0) 8307 , m_max_texture_size(1) 8308 , m_max_samples(1) 8309 , m_max_array_texture_layers(1) 8310 { 8311 /* Intentionally left blank. */ 8312 } 8313 8314 /** @brief Iterate Texture Storage Errors Test cases. 8315 * 8316 * @return Iteration result. 8317 */ 8318 tcu::TestNode::IterateResult StorageErrorsTest::iterate() 8319 { 8320 /* Get context setup. */ 8321 bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5))); 8322 bool is_arb_direct_state_access = m_context.getContextInfo().isExtensionSupported("GL_ARB_direct_state_access"); 8323 8324 if ((!is_at_least_gl_45) && (!is_arb_direct_state_access)) 8325 { 8326 m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported"); 8327 8328 return STOP; 8329 } 8330 8331 /* Running tests. */ 8332 bool is_ok = true; 8333 bool is_error = false; 8334 8335 try 8336 { 8337 Prepare(); 8338 8339 is_ok &= Test1D(); 8340 is_ok &= Test2D(); 8341 is_ok &= Test3D(); 8342 is_ok &= Test2DMultisample(); 8343 is_ok &= Test3DMultisample(); 8344 } 8345 catch (...) 8346 { 8347 is_ok = false; 8348 is_error = true; 8349 } 8350 8351 /* Cleanup. */ 8352 Clean(); 8353 8354 /* Result's setup. */ 8355 if (is_ok) 8356 { 8357 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 8358 } 8359 else 8360 { 8361 if (is_error) 8362 { 8363 m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Error"); 8364 } 8365 else 8366 { 8367 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); 8368 } 8369 } 8370 8371 return STOP; 8372 } 8373 8374 /** @brief Prepare test objects. 8375 */ 8376 void StorageErrorsTest::Prepare() 8377 { 8378 /* Shortcut for GL functionality. */ 8379 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 8380 8381 /* Auxiliary objects setup. */ 8382 8383 /* 1D */ 8384 gl.createTextures(GL_TEXTURE_1D, 1, &m_to_1D); 8385 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed"); 8386 8387 /* 1D ARRAY */ 8388 gl.createTextures(GL_TEXTURE_1D_ARRAY, 1, &m_to_1D_array); 8389 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed"); 8390 8391 /* 2D */ 8392 gl.createTextures(GL_TEXTURE_2D, 1, &m_to_2D); 8393 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed"); 8394 8395 /* 2D ARRAY */ 8396 gl.createTextures(GL_TEXTURE_2D_ARRAY, 1, &m_to_2D_array); 8397 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed"); 8398 8399 /* 3D */ 8400 gl.createTextures(GL_TEXTURE_3D, 1, &m_to_3D); 8401 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed"); 8402 8403 /* 2D Multisample */ 8404 gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &m_to_2D_ms); 8405 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed"); 8406 8407 /* 2D Multisample with storage */ 8408 gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &m_to_2D_ms_immutable); 8409 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed"); 8410 8411 gl.textureStorage2DMultisample(m_to_2D_ms_immutable, 1, GL_R8, 16, 16, false); 8412 GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2DMultisample has failed"); 8413 8414 /* 3D Multisample */ 8415 gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 1, &m_to_3D_ms); 8416 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed"); 8417 8418 /* 3D Multisample with storage */ 8419 gl.createTextures(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 1, &m_to_3D_ms_immutable); 8420 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateTextures has failed"); 8421 8422 gl.textureStorage3DMultisample(m_to_3D_ms_immutable, 1, GL_R8, 16, 16, 16, false); 8423 GLU_EXPECT_NO_ERROR(gl.getError(), "glTextureStorage2DMultisample has failed"); 8424 8425 /* Invalid values */ 8426 8427 /* invalid texture object */ 8428 while (gl.isTexture(++m_to_invalid)) 8429 ; 8430 GLU_EXPECT_NO_ERROR(gl.getError(), "glIsTexture has failed"); 8431 8432 /* invalid internal format */ 8433 static const glw::GLenum all_internal_formats[] = { GL_R8, 8434 GL_R8_SNORM, 8435 GL_R16, 8436 GL_R16_SNORM, 8437 GL_RG8, 8438 GL_RG8_SNORM, 8439 GL_RG16, 8440 GL_RG16_SNORM, 8441 GL_R3_G3_B2, 8442 GL_RGB4, 8443 GL_RGB5, 8444 GL_RGB565, 8445 GL_RGB8, 8446 GL_RGB8_SNORM, 8447 GL_RGB10, 8448 GL_RGB12, 8449 GL_RGB16, 8450 GL_RGB16_SNORM, 8451 GL_RGBA2, 8452 GL_RGBA4, 8453 GL_RGB5_A1, 8454 GL_RGBA8, 8455 GL_RGBA8_SNORM, 8456 GL_RGB10_A2, 8457 GL_RGB10_A2UI, 8458 GL_RGBA12, 8459 GL_RGBA16, 8460 GL_RGBA16_SNORM, 8461 GL_SRGB8, 8462 GL_SRGB8_ALPHA8, 8463 GL_R16F, 8464 GL_RG16F, 8465 GL_RGB16F, 8466 GL_RGBA16F, 8467 GL_R32F, 8468 GL_RG32F, 8469 GL_RGB32F, 8470 GL_RGBA32F, 8471 GL_R11F_G11F_B10F, 8472 GL_RGB9_E5, 8473 GL_R8I, 8474 GL_R8UI, 8475 GL_R16I, 8476 GL_R16UI, 8477 GL_R32I, 8478 GL_R32UI, 8479 GL_RG8I, 8480 GL_RG8UI, 8481 GL_RG16I, 8482 GL_RG16UI, 8483 GL_RG32I, 8484 GL_RG32UI, 8485 GL_RGB8I, 8486 GL_RGB8UI, 8487 GL_RGB16I, 8488 GL_RGB16UI, 8489 GL_RGB32I, 8490 GL_RGB32UI, 8491 GL_RGBA8I, 8492 GL_RGBA8UI, 8493 GL_RGBA16I, 8494 GL_RGBA16UI, 8495 GL_RGBA32I, 8496 GL_RGBA32UI, 8497 GL_COMPRESSED_RED, 8498 GL_COMPRESSED_RG, 8499 GL_COMPRESSED_RGB, 8500 GL_COMPRESSED_RGBA, 8501 GL_COMPRESSED_SRGB, 8502 GL_COMPRESSED_SRGB_ALPHA, 8503 GL_COMPRESSED_RED_RGTC1, 8504 GL_COMPRESSED_SIGNED_RED_RGTC1, 8505 GL_COMPRESSED_RG_RGTC2, 8506 GL_COMPRESSED_SIGNED_RG_RGTC2, 8507 GL_COMPRESSED_RGBA_BPTC_UNORM, 8508 GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM, 8509 GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT, 8510 GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT, 8511 GL_COMPRESSED_RGB8_ETC2, 8512 GL_COMPRESSED_SRGB8_ETC2, 8513 GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, 8514 GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, 8515 GL_COMPRESSED_RGBA8_ETC2_EAC, 8516 GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, 8517 GL_COMPRESSED_R11_EAC, 8518 GL_COMPRESSED_SIGNED_R11_EAC, 8519 GL_COMPRESSED_RG11_EAC, 8520 GL_COMPRESSED_SIGNED_RG11_EAC, 8521 GL_DEPTH_COMPONENT16, 8522 GL_DEPTH_COMPONENT24, 8523 GL_DEPTH_COMPONENT32, 8524 GL_DEPTH_COMPONENT32F, 8525 GL_DEPTH24_STENCIL8, 8526 GL_DEPTH32F_STENCIL8, 8527 GL_STENCIL_INDEX1, 8528 GL_STENCIL_INDEX4, 8529 GL_STENCIL_INDEX8, 8530 GL_STENCIL_INDEX16 }; 8531 8532 static const glw::GLuint all_internal_formats_count = 8533 sizeof(all_internal_formats) / sizeof(all_internal_formats[0]); 8534 8535 bool is_valid = true; 8536 m_internalformat_invalid = 0; 8537 8538 while (is_valid) 8539 { 8540 is_valid = false; 8541 m_internalformat_invalid++; 8542 for (glw::GLuint i = 0; i < all_internal_formats_count; ++i) 8543 { 8544 if (all_internal_formats[i] == m_internalformat_invalid) 8545 { 8546 is_valid = true; 8547 break; 8548 } 8549 } 8550 } 8551 8552 /* Maximum texture size.*/ 8553 gl.getIntegerv(GL_MAX_TEXTURE_SIZE, &m_max_texture_size); 8554 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed"); 8555 8556 /* Maximum number of samples. */ 8557 gl.getIntegerv(GL_MAX_SAMPLES, &m_max_samples); 8558 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed"); 8559 8560 /* Maximum number of array texture layers. */ 8561 gl.getIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &m_max_array_texture_layers); 8562 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv has failed"); 8563 } 8564 8565 /** @brief Test TextureStorage1D 8566 * 8567 * @return Test result. 8568 */ 8569 bool StorageErrorsTest::Test1D() 8570 { 8571 /* Shortcut for GL functionality. */ 8572 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 8573 8574 /* Result. */ 8575 bool is_ok = true; 8576 8577 /* Check that INVALID_OPERATION is generated by TextureStorage1D if texture 8578 is not the name of an existing texture object. */ 8579 { 8580 gl.textureStorage1D(m_to_invalid, 1, GL_R8, 8); 8581 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage1D", 8582 "texture is not the name of an existing texture object."); 8583 } 8584 8585 /* Check that INVALID_ENUM is generated by TextureStorage1D if 8586 internalformat is not a valid sized internal format. */ 8587 { 8588 gl.textureStorage1D(m_to_1D, 1, m_internalformat_invalid, 8); 8589 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureStorage1D", 8590 "internalformat is not a valid sized internal format."); 8591 } 8592 8593 /* Check that INVALID_ENUM is generated by TextureStorage1D if target or 8594 the effective target of texture is not one of the accepted targets 8595 described above. */ 8596 { 8597 gl.textureStorage1D(m_to_2D, 1, GL_R8, 8); 8598 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage1D", 8599 "the effective target of texture is not one of the accepted targets."); 8600 } 8601 8602 /* Check that INVALID_VALUE is generated by TextureStorage1D if width or 8603 levels are less than 1. */ 8604 { 8605 gl.textureStorage1D(m_to_1D, 0, GL_R8, 8); 8606 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage1D", "levels is less than 1."); 8607 8608 gl.textureStorage1D(m_to_1D, 1, GL_R8, 0); 8609 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage1D", "width is less than 1."); 8610 } 8611 8612 /* Check that INVALID_OPERATION is generated by TextureStorage1D if levels 8613 is greater than log2(width)+1. */ 8614 { 8615 gl.textureStorage1D(m_to_1D, 8, GL_R8, 8); 8616 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage1D", 8617 "levels is greater than log2(width)+1."); 8618 } 8619 8620 return is_ok; 8621 } 8622 8623 /** @brief Test TextureStorage2D 8624 * 8625 * @return Test result. 8626 */ 8627 bool StorageErrorsTest::Test2D() 8628 { 8629 /* Shortcut for GL functionality. */ 8630 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 8631 8632 /* Result. */ 8633 bool is_ok = true; 8634 8635 /* Check that INVALID_OPERATION is generated by TextureStorage2D if 8636 texture is not the name of an existing texture object. */ 8637 { 8638 gl.textureStorage2D(m_to_invalid, 1, GL_R8, 8, 8); 8639 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2D", 8640 "texture is not the name of an existing texture object."); 8641 } 8642 8643 /* Check that INVALID_ENUM is generated by TextureStorage2D if 8644 internalformat is not a valid sized internal format. */ 8645 { 8646 gl.textureStorage2D(m_to_2D, 1, m_internalformat_invalid, 8, 8); 8647 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureStorage2D", 8648 "internalformat is not a valid sized internal format."); 8649 } 8650 8651 /* Check that INVALID_ENUM is generated by TextureStorage2D if target or 8652 the effective target of texture is not one of the accepted targets 8653 described above. */ 8654 { 8655 gl.textureStorage2D(m_to_1D, 1, GL_R8, 8, 8); 8656 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2D", 8657 "the effective target of texture is not one of the accepted targets."); 8658 } 8659 8660 /* Check that INVALID_VALUE is generated by TextureStorage2D if width, 8661 height or levels are less than 1. */ 8662 { 8663 gl.textureStorage2D(m_to_2D, 0, GL_R8, 8, 8); 8664 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2D", "levels is less than 1."); 8665 8666 gl.textureStorage2D(m_to_2D, 1, GL_R8, 0, 8); 8667 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2D", "width is less than 1."); 8668 8669 gl.textureStorage2D(m_to_2D, 1, GL_R8, 8, 0); 8670 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage2D", "height is less than 1."); 8671 } 8672 8673 /* Check that INVALID_OPERATION is generated by TextureStorage2D if target 8674 is TEXTURE_1D_ARRAY or PROXY_TEXTURE_1D_ARRAY and levels is greater than 8675 log2(width)+1. */ 8676 { 8677 gl.textureStorage2D(m_to_1D_array, 8, GL_R8, 8, 8); 8678 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2D", 8679 "target is TEXTURE_1D_ARRAY and levels is greater than log2(width)+1."); 8680 } 8681 8682 /* Check that INVALID_OPERATION is generated by TextureStorage2D if target 8683 is not TEXTURE_1D_ARRAY or PROXY_TEXTURE_1D_ARRAY and levels is greater 8684 than log2(max(width, height))+1. */ 8685 { 8686 gl.textureStorage2D(m_to_2D, 8, GL_R8, 8, 8); 8687 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage2D", 8688 "target is TEXTURE_2D and levels is greater than log2(max(width, height))+1."); 8689 } 8690 8691 return is_ok; 8692 } 8693 8694 /** @brief Test TextureStorage3D 8695 * 8696 * @return Test result. 8697 */ 8698 bool StorageErrorsTest::Test3D() 8699 { 8700 /* Shortcut for GL functionality. */ 8701 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 8702 8703 /* Result. */ 8704 bool is_ok = true; 8705 8706 /* Check that INVALID_OPERATION is generated by TextureStorage3D if texture 8707 is not the name of an existing texture object. */ 8708 { 8709 gl.textureStorage3D(m_to_invalid, 1, GL_R8, 8, 8, 8); 8710 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3D", 8711 "texture is not the name of an existing texture object."); 8712 } 8713 8714 /* Check that INVALID_ENUM is generated by TextureStorage3D if 8715 internalformat is not a valid sized internal format. */ 8716 { 8717 gl.textureStorage3D(m_to_3D, 1, m_internalformat_invalid, 8, 8, 8); 8718 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_ENUM, "glTextureStorage3D", 8719 "internalformat is not a valid sized internal format."); 8720 } 8721 8722 /* Check that INVALID_ENUM is generated by TextureStorage3D if target or 8723 the effective target of texture is not one of the accepted targets 8724 described above. */ 8725 { 8726 gl.textureStorage3D(m_to_1D, 1, GL_R8, 8, 8, 8); 8727 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_OPERATION, "glTextureStorage3D", 8728 "the effective target of texture is not one of the accepted targets."); 8729 } 8730 8731 /* Check that INVALID_VALUE is generated by TextureStorage3D if width, 8732 height, depth or levels are less than 1. */ 8733 { 8734 gl.textureStorage3D(m_to_3D, 0, GL_R8, 8, 8, 8); 8735 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3D", "levels is less than 1."); 8736 8737 gl.textureStorage3D(m_to_3D, 1, GL_R8, 0, 8, 8); 8738 is_ok &= CheckErrorAndLog(m_context, GL_INVALID_VALUE, "glTextureStorage3D", "width is less than 1."); 8739