Hash :
183d7e24
Author :
Date :
2015-11-20T15:59:09
Remove predefined precision qualifiers from ESSL3 samplers New sampler types in ESSL3 should not have default precision qualifiers. This is specified in ESSL 3.00.4 section 4.5.4. BUG=angleproject:1222 TEST=angle_unittests Change-Id: I9c8e7a5fbb4278db80de79bcaeebaf23e64242a0 Reviewed-on: https://chromium-review.googlesource.com/312048 Tryjob-Request: Olli Etuaho <oetuaho@nvidia.com> Tested-by: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Zhenyao Mo <zmo@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123
//
// Copyright 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "test_utils/ANGLETest.h"
using namespace angle;
namespace
{
class TextureTest : public ANGLETest
{
protected:
TextureTest()
{
setWindowWidth(128);
setWindowHeight(128);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
}
void SetUp() override
{
ANGLETest::SetUp();
glGenTextures(1, &mTexture2D);
glGenTextures(1, &mTextureCube);
glBindTexture(GL_TEXTURE_2D, mTexture2D);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
EXPECT_GL_NO_ERROR();
glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
glTexStorage2DEXT(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
EXPECT_GL_NO_ERROR();
ASSERT_GL_NO_ERROR();
const std::string vertexShaderSource = SHADER_SOURCE
(
precision highp float;
attribute vec4 position;
varying vec2 texcoord;
uniform vec2 textureScale;
void main()
{
gl_Position = vec4(position.xy * textureScale, 0.0, 1.0);
texcoord = (position.xy * 0.5) + 0.5;
}
);
const std::string fragmentShaderSource2D = SHADER_SOURCE
(
precision highp float;
uniform sampler2D tex;
varying vec2 texcoord;
void main()
{
gl_FragColor = texture2D(tex, texcoord);
}
);
const std::string fragmentShaderSourceCube = SHADER_SOURCE
(
precision highp float;
uniform sampler2D tex2D;
uniform samplerCube texCube;
varying vec2 texcoord;
void main()
{
gl_FragColor = texture2D(tex2D, texcoord);
gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
}
);
m2DProgram = CompileProgram(vertexShaderSource, fragmentShaderSource2D);
mCubeProgram = CompileProgram(vertexShaderSource, fragmentShaderSourceCube);
ASSERT_NE(0u, m2DProgram);
ASSERT_NE(0u, mCubeProgram);
mTexture2DUniformLocation = glGetUniformLocation(m2DProgram, "tex");
ASSERT_NE(-1, mTexture2DUniformLocation);
mTextureScaleUniformLocation = glGetUniformLocation(m2DProgram, "textureScale");
ASSERT_NE(-1, mTextureScaleUniformLocation);
glUseProgram(m2DProgram);
glUniform2f(mTextureScaleUniformLocation, 1.0f, 1.0f);
glUseProgram(0);
ASSERT_GL_NO_ERROR();
}
void TearDown() override
{
glDeleteTextures(1, &mTexture2D);
glDeleteTextures(1, &mTextureCube);
glDeleteProgram(m2DProgram);
glDeleteProgram(mCubeProgram);
ANGLETest::TearDown();
}
// Tests CopyTexSubImage with floating point textures of various formats.
void testFloatCopySubImage(int sourceImageChannels, int destImageChannels)
{
// TODO(jmadill): Figure out why this is broken on Intel D3D11
if (isIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
{
std::cout << "Test skipped on Intel D3D11." << std::endl;
return;
}
if (getClientVersion() < 3)
{
if (!extensionEnabled("GL_OES_texture_float"))
{
std::cout << "Test skipped due to missing GL_OES_texture_float." << std::endl;
return;
}
if ((sourceImageChannels < 3 || destImageChannels < 3) && !extensionEnabled("GL_EXT_texture_rg"))
{
std::cout << "Test skipped due to missing GL_EXT_texture_rg." << std::endl;
return;
}
}
GLfloat sourceImageData[4][16] =
{
{ // R
1.0f,
0.0f,
0.0f,
1.0f
},
{ // RG
1.0f, 0.0f,
0.0f, 1.0f,
0.0f, 0.0f,
1.0f, 1.0f
},
{ // RGB
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f,
1.0f, 1.0f, 0.0f
},
{ // RGBA
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
1.0f, 1.0f, 0.0f, 1.0f
},
};
GLenum imageFormats[] =
{
GL_R32F,
GL_RG32F,
GL_RGB32F,
GL_RGBA32F,
};
GLenum sourceUnsizedFormats[] =
{
GL_RED,
GL_RG,
GL_RGB,
GL_RGBA,
};
GLuint textures[2];
glGenTextures(2, textures);
GLfloat *imageData = sourceImageData[sourceImageChannels - 1];
GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1];
GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1];
GLenum destImageFormat = imageFormats[destImageChannels - 1];
glBindTexture(GL_TEXTURE_2D, textures[0]);
glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData);
if (sourceImageChannels < 3 && !extensionEnabled("GL_EXT_texture_rg"))
{
// This is not supported
ASSERT_GL_ERROR(GL_INVALID_OPERATION);
}
else
{
ASSERT_GL_NO_ERROR();
}
GLuint fbo;
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
glBindTexture(GL_TEXTURE_2D, textures[1]);
glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
ASSERT_GL_NO_ERROR();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
drawQuad(m2DProgram, "position", 0.5f);
int testImageChannels = std::min(sourceImageChannels, destImageChannels);
EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
if (testImageChannels > 1)
{
EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255);
EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255);
if (testImageChannels > 2)
{
EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255);
}
}
glDeleteFramebuffers(1, &fbo);
glDeleteTextures(2, textures);
ASSERT_GL_NO_ERROR();
}
GLuint mTexture2D;
GLuint mTextureCube;
GLuint m2DProgram;
GLuint mCubeProgram;
GLint mTexture2DUniformLocation;
GLint mTextureScaleUniformLocation;
};
class TextureTestES3 : public ANGLETest
{
protected:
TextureTestES3()
: m2DArrayTexture(0),
m2DArrayProgram(0),
mTextureArrayLocation(-1)
{
setWindowWidth(128);
setWindowHeight(128);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
}
void SetUp() override
{
ANGLETest::SetUp();
const std::string vertexShaderSource =
"#version 300 es\n"
"out vec2 texcoord;\n"
"in vec4 position;\n"
"void main() {\n"
" gl_Position = vec4(position.xy, 0.0, 1.0);\n"
" texcoord = (position.xy * 0.5) + 0.5;\n"
"}";
const std::string fragmentShaderSource2DArray =
"#version 300 es\n"
"precision highp float;\n"
"uniform highp sampler2DArray tex2DArray;\n"
"in vec2 texcoord;\n"
"out vec4 fragColor;\n"
"void main()\n"
"{\n"
" fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n"
"}\n";
m2DArrayProgram = CompileProgram(vertexShaderSource, fragmentShaderSource2DArray);
ASSERT_NE(0u, m2DArrayProgram);
mTextureArrayLocation = glGetUniformLocation(m2DArrayProgram, "tex2DArray");
ASSERT_NE(-1, mTextureArrayLocation);
glGenTextures(1, &m2DArrayTexture);
ASSERT_GL_NO_ERROR();
}
void TearDown() override
{
glDeleteTextures(1, &m2DArrayTexture);
glDeleteProgram(m2DArrayProgram);
}
GLuint m2DArrayTexture;
GLuint m2DArrayProgram;
GLint mTextureArrayLocation;
};
TEST_P(TextureTest, NegativeAPISubImage)
{
glBindTexture(GL_TEXTURE_2D, mTexture2D);
EXPECT_GL_ERROR(GL_NO_ERROR);
const GLubyte *pixels[20] = { 0 };
glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
}
TEST_P(TextureTest, ZeroSizedUploads)
{
glBindTexture(GL_TEXTURE_2D, mTexture2D);
EXPECT_GL_ERROR(GL_NO_ERROR);
// Use the texture first to make sure it's in video memory
glUseProgram(m2DProgram);
glUniform1i(mTexture2DUniformLocation, 0);
drawQuad(m2DProgram, "position", 0.5f);
const GLubyte *pixel[4] = { 0 };
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
EXPECT_GL_NO_ERROR();
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
EXPECT_GL_NO_ERROR();
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
EXPECT_GL_NO_ERROR();
}
// Test drawing with two texture types, to trigger an ANGLE bug in validation
TEST_P(TextureTest, CubeMapBug)
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, mTexture2D);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
EXPECT_GL_ERROR(GL_NO_ERROR);
glUseProgram(mCubeProgram);
GLint tex2DUniformLocation = glGetUniformLocation(mCubeProgram, "tex2D");
GLint texCubeUniformLocation = glGetUniformLocation(mCubeProgram, "texCube");
EXPECT_NE(-1, tex2DUniformLocation);
EXPECT_NE(-1, texCubeUniformLocation);
glUniform1i(tex2DUniformLocation, 0);
glUniform1i(texCubeUniformLocation, 1);
drawQuad(mCubeProgram, "position", 0.5f);
EXPECT_GL_NO_ERROR();
}
// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
TEST_P(TextureTest, MipmapsTwice)
{
int px = getWindowWidth() / 2;
int py = getWindowHeight() / 2;
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, mTexture2D);
// Fill with red
std::vector<GLubyte> pixels(4 * 16 * 16);
for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
{
pixels[pixelId * 4 + 0] = 255;
pixels[pixelId * 4 + 1] = 0;
pixels[pixelId * 4 + 2] = 0;
pixels[pixelId * 4 + 3] = 255;
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glGenerateMipmap(GL_TEXTURE_2D);
glUseProgram(m2DProgram);
glUniform1i(mTexture2DUniformLocation, 0);
glUniform2f(mTextureScaleUniformLocation, 0.0625f, 0.0625f);
drawQuad(m2DProgram, "position", 0.5f);
EXPECT_GL_NO_ERROR();
EXPECT_PIXEL_EQ(px, py, 255, 0, 0, 255);
// Fill with blue
for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
{
pixels[pixelId * 4 + 0] = 0;
pixels[pixelId * 4 + 1] = 0;
pixels[pixelId * 4 + 2] = 255;
pixels[pixelId * 4 + 3] = 255;
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
glGenerateMipmap(GL_TEXTURE_2D);
// Fill with green
for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
{
pixels[pixelId * 4 + 0] = 0;
pixels[pixelId * 4 + 1] = 255;
pixels[pixelId * 4 + 2] = 0;
pixels[pixelId * 4 + 3] = 255;
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
glGenerateMipmap(GL_TEXTURE_2D);
drawQuad(m2DProgram, "position", 0.5f);
EXPECT_GL_NO_ERROR();
EXPECT_PIXEL_EQ(px, py, 0, 255, 0, 255);
}
// Test creating a FBO with a cube map render target, to test an ANGLE bug
// https://code.google.com/p/angleproject/issues/detail?id=849
TEST_P(TextureTest, CubeMapFBO)
{
GLuint fbo;
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mTextureCube, 0);
EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
glDeleteFramebuffers(1, &fbo);
EXPECT_GL_NO_ERROR();
}
// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a default color.
TEST_P(TextureTest, TexStorage)
{
int width = getWindowWidth();
int height = getWindowHeight();
GLuint tex2D;
glGenTextures(1, &tex2D);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex2D);
// Fill with red
std::vector<GLubyte> pixels(3 * 16 * 16);
for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
{
pixels[pixelId * 3 + 0] = 255;
pixels[pixelId * 3 + 1] = 0;
pixels[pixelId * 3 + 2] = 0;
}
// ANGLE internally uses RGBA as the DirectX format for RGB images
// therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
// The data is kept in a CPU-side image and the image is marked as dirty.
glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
// Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
// glTexSubImage2D should take into account that the image is dirty.
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glUseProgram(m2DProgram);
glUniform1i(mTexture2DUniformLocation, 0);
glUniform2f(mTextureScaleUniformLocation, 1.f, 1.f);
drawQuad(m2DProgram, "position", 0.5f);
glDeleteTextures(1, &tex2D);
EXPECT_GL_NO_ERROR();
EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
// Validate that the region of the texture without data has an alpha of 1.0
GLubyte pixel[4];
glReadPixels(3 * width / 4, 3 * height / 4, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
EXPECT_EQ(pixel[3], 255);
}
// Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has initialized the image with a default color.
TEST_P(TextureTest, TexStorageWithPBO)
{
if (extensionEnabled("NV_pixel_buffer_object"))
{
int width = getWindowWidth();
int height = getWindowHeight();
GLuint tex2D;
glGenTextures(1, &tex2D);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex2D);
// Fill with red
std::vector<GLubyte> pixels(3 * 16 * 16);
for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
{
pixels[pixelId * 3 + 0] = 255;
pixels[pixelId * 3 + 1] = 0;
pixels[pixelId * 3 + 2] = 0;
}
// Read 16x16 region from red backbuffer to PBO
GLuint pbo;
glGenBuffers(1, &pbo);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
// ANGLE internally uses RGBA as the DirectX format for RGB images
// therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
// The data is kept in a CPU-side image and the image is marked as dirty.
glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
// Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
// glTexSubImage2D should take into account that the image is dirty.
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glUseProgram(m2DProgram);
glUniform1i(mTexture2DUniformLocation, 0);
glUniform2f(mTextureScaleUniformLocation, 1.f, 1.f);
drawQuad(m2DProgram, "position", 0.5f);
glDeleteTextures(1, &tex2D);
glDeleteTextures(1, &pbo);
EXPECT_GL_NO_ERROR();
EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
}
}
// See description on testFloatCopySubImage
TEST_P(TextureTest, CopySubImageFloat_R_R)
{
testFloatCopySubImage(1, 1);
}
TEST_P(TextureTest, CopySubImageFloat_RG_R)
{
testFloatCopySubImage(2, 1);
}
TEST_P(TextureTest, CopySubImageFloat_RG_RG)
{
testFloatCopySubImage(2, 2);
}
TEST_P(TextureTest, CopySubImageFloat_RGB_R)
{
testFloatCopySubImage(3, 1);
}
TEST_P(TextureTest, CopySubImageFloat_RGB_RG)
{
testFloatCopySubImage(3, 2);
}
TEST_P(TextureTest, CopySubImageFloat_RGB_RGB)
{
testFloatCopySubImage(3, 3);
}
TEST_P(TextureTest, CopySubImageFloat_RGBA_R)
{
testFloatCopySubImage(4, 1);
}
TEST_P(TextureTest, CopySubImageFloat_RGBA_RG)
{
testFloatCopySubImage(4, 2);
}
TEST_P(TextureTest, CopySubImageFloat_RGBA_RGB)
{
testFloatCopySubImage(4, 3);
}
TEST_P(TextureTest, CopySubImageFloat_RGBA_RGBA)
{
testFloatCopySubImage(4, 4);
}
// Port of https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
// Run against GL_ALPHA/UNSIGNED_BYTE format, to ensure that D3D11 Feature Level 9_3 correctly handles GL_ALPHA
TEST_P(TextureTest, TextureNPOT_GL_ALPHA_UBYTE)
{
const int npotTexSize = 5;
const int potTexSize = 4; // Should be less than npotTexSize
GLuint tex2D;
if (extensionEnabled("GL_OES_texture_npot"))
{
// This test isn't applicable if texture_npot is enabled
return;
}
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &tex2D);
glBindTexture(GL_TEXTURE_2D, tex2D);
std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize);
for (size_t pixelId = 0; pixelId < npotTexSize * npotTexSize; ++pixelId)
{
pixels[pixelId] = 64;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// Check that an NPOT texture not on level 0 generates INVALID_VALUE
glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
EXPECT_GL_ERROR(GL_INVALID_VALUE);
// Check that an NPOT texture on level 0 succeeds
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
EXPECT_GL_NO_ERROR();
// Check that generateMipmap fails on NPOT
glGenerateMipmap(GL_TEXTURE_2D);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
// Check that nothing is drawn if filtering is not correct for NPOT
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glClear(GL_COLOR_BUFFER_BIT);
drawQuad(m2DProgram, "position", 1.0f);
EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
// NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
glClear(GL_COLOR_BUFFER_BIT);
drawQuad(m2DProgram, "position", 1.0f);
EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
// NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glClear(GL_COLOR_BUFFER_BIT);
drawQuad(m2DProgram, "position", 1.0f);
EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
// Check that glTexImage2D for POT texture succeeds
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
EXPECT_GL_NO_ERROR();
// Check that generateMipmap for an POT texture succeeds
glGenerateMipmap(GL_TEXTURE_2D);
EXPECT_GL_NO_ERROR();
// POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glClear(GL_COLOR_BUFFER_BIT);
drawQuad(m2DProgram, "position", 1.0f);
EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
EXPECT_GL_NO_ERROR();
}
// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
TEST_P(TextureTest, NPOTSubImageParameters)
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, mTexture2D);
// Create an 8x8 (i.e. power-of-two) texture.
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glGenerateMipmap(GL_TEXTURE_2D);
// Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
// This should always work, even if GL_OES_texture_npot isn't active.
glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
EXPECT_GL_NO_ERROR();
}
// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG RBA->RGBA8, with 1.0
// in the alpha channel. This test covers a bug where redefining array textures with these formats does not work as
// expected.
TEST_P(TextureTestES3, RedefineInittableArray)
{
std::vector<GLubyte> pixelData;
for (size_t count = 0; count < 5000; count++)
{
pixelData.push_back(0u);
pixelData.push_back(255u);
pixelData.push_back(0u);
}
glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
glUseProgram(m2DArrayProgram);
glUniform1i(mTextureArrayLocation, 0);
// The first draw worked correctly.
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
drawQuad(m2DArrayProgram, "position", 1.0f);
EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
// The dimension of the respecification must match the original exactly to trigger the bug.
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
drawQuad(m2DArrayProgram, "position", 1.0f);
EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
ASSERT_GL_NO_ERROR();
}
class TextureLimitsTest : public ANGLETest
{
protected:
struct RGBA8
{
uint8_t R, G, B, A;
};
TextureLimitsTest()
: mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
{
setWindowWidth(128);
setWindowHeight(128);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
}
~TextureLimitsTest()
{
if (mProgram != 0)
{
glDeleteProgram(mProgram);
mProgram = 0;
if (!mTextures.empty())
{
glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
}
}
}
void SetUp() override
{
ANGLETest::SetUp();
glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
ASSERT_GL_NO_ERROR();
}
void compileProgramWithTextureCounts(const std::string &vertexPrefix,
GLint vertexTextureCount,
GLint vertexActiveTextureCount,
const std::string &fragPrefix,
GLint fragmentTextureCount,
GLint fragmentActiveTextureCount)
{
std::stringstream vertexShaderStr;
vertexShaderStr << "attribute vec2 position;\n"
<< "varying vec4 color;\n"
<< "varying vec2 texCoord;\n";
for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
{
vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
}
vertexShaderStr << "void main() {\n"
<< " gl_Position = vec4(position, 0, 1);\n"
<< " texCoord = (position * 0.5) + 0.5;\n"
<< " color = vec4(0);\n";
for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
{
vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
<< ", texCoord);\n";
}
vertexShaderStr << "}";
std::stringstream fragmentShaderStr;
fragmentShaderStr << "varying mediump vec4 color;\n"
<< "varying mediump vec2 texCoord;\n";
for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
{
fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
}
fragmentShaderStr << "void main() {\n"
<< " gl_FragColor = color;\n";
for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
{
fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
<< ", texCoord);\n";
}
fragmentShaderStr << "}";
const std::string &vertexShaderSource = vertexShaderStr.str();
const std::string &fragmentShaderSource = fragmentShaderStr.str();
mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
}
RGBA8 getPixel(GLint texIndex)
{
RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
0, 255u};
return pixel;
}
void initTextures(GLint tex2DCount, GLint texCubeCount)
{
GLint totalCount = tex2DCount + texCubeCount;
mTextures.assign(totalCount, 0);
glGenTextures(totalCount, &mTextures[0]);
ASSERT_GL_NO_ERROR();
std::vector<RGBA8> texData(16 * 16);
GLint texIndex = 0;
for (; texIndex < tex2DCount; ++texIndex)
{
texData.assign(texData.size(), getPixel(texIndex));
glActiveTexture(GL_TEXTURE0 + texIndex);
glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
&texData[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
ASSERT_GL_NO_ERROR();
for (; texIndex < texCubeCount; ++texIndex)
{
texData.assign(texData.size(), getPixel(texIndex));
glActiveTexture(GL_TEXTURE0 + texIndex);
glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
GL_UNSIGNED_BYTE, &texData[0]);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
GL_UNSIGNED_BYTE, &texData[0]);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
GL_UNSIGNED_BYTE, &texData[0]);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
GL_UNSIGNED_BYTE, &texData[0]);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
GL_UNSIGNED_BYTE, &texData[0]);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
GL_UNSIGNED_BYTE, &texData[0]);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
ASSERT_GL_NO_ERROR();
}
void testWithTextures(GLint vertexTextureCount,
const std::string &vertexTexturePrefix,
GLint fragmentTextureCount,
const std::string &fragmentTexturePrefix)
{
// Generate textures
initTextures(vertexTextureCount + fragmentTextureCount, 0);
glUseProgram(mProgram);
RGBA8 expectedSum = {0};
for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
{
std::stringstream uniformNameStr;
uniformNameStr << vertexTexturePrefix << texIndex;
const std::string &uniformName = uniformNameStr.str();
GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
ASSERT_NE(-1, location);
glUniform1i(location, texIndex);
RGBA8 contribution = getPixel(texIndex);
expectedSum.R += contribution.R;
expectedSum.G += contribution.G;
}
for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
{
std::stringstream uniformNameStr;
uniformNameStr << fragmentTexturePrefix << texIndex;
const std::string &uniformName = uniformNameStr.str();
GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
ASSERT_NE(-1, location);
glUniform1i(location, texIndex + vertexTextureCount);
RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
expectedSum.R += contribution.R;
expectedSum.G += contribution.G;
}
ASSERT_GE(256u, expectedSum.G);
drawQuad(mProgram, "position", 0.5f);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
}
GLuint mProgram;
std::vector<GLuint> mTextures;
GLint mMaxVertexTextures;
GLint mMaxFragmentTextures;
GLint mMaxCombinedTextures;
};
// Test rendering with the maximum vertex texture units.
TEST_P(TextureLimitsTest, MaxVertexTextures)
{
// TODO(jmadill): Figure out why this fails on Intel.
if (isIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
{
std::cout << "Test skipped on Intel." << std::endl;
return;
}
compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
ASSERT_NE(0u, mProgram);
ASSERT_GL_NO_ERROR();
testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
}
// Test rendering with the maximum fragment texture units.
TEST_P(TextureLimitsTest, MaxFragmentTextures)
{
// TODO(jmadill): Figure out why this fails on Intel.
if (isIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
{
std::cout << "Test skipped on Intel." << std::endl;
return;
}
compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
ASSERT_NE(0u, mProgram);
ASSERT_GL_NO_ERROR();
testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
}
// Test rendering with maximum combined texture units.
TEST_P(TextureLimitsTest, MaxCombinedTextures)
{
// TODO(jmadill): Investigate workaround.
if (isIntel() && GetParam() == ES2_OPENGL())
{
std::cout << "Test skipped on Intel." << std::endl;
return;
}
GLint vertexTextures = mMaxVertexTextures;
if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
{
vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
}
compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
mMaxFragmentTextures, mMaxFragmentTextures);
ASSERT_NE(0u, mProgram);
ASSERT_GL_NO_ERROR();
testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
}
// Negative test for exceeding the number of vertex textures
TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
{
compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
0);
ASSERT_EQ(0u, mProgram);
}
// Negative test for exceeding the number of fragment textures
TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
{
compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
mMaxFragmentTextures + 1);
ASSERT_EQ(0u, mProgram);
}
// Test active vertex textures under the limit, but excessive textures specified.
TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
{
// TODO(jmadill): Figure out why this fails on Intel.
if (isIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
{
std::cout << "Test skipped on Intel." << std::endl;
return;
}
compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
ASSERT_NE(0u, mProgram);
ASSERT_GL_NO_ERROR();
testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
}
// Test active fragment textures under the limit, but excessive textures specified.
TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
{
// TODO(jmadill): Figure out why this fails on Intel.
if (isIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
{
std::cout << "Test skipped on Intel." << std::endl;
return;
}
compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
mMaxFragmentTextures);
ASSERT_NE(0u, mProgram);
ASSERT_GL_NO_ERROR();
testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
}
// Negative test for pointing two sampler uniforms of different types to the same texture.
TEST_P(TextureLimitsTest, TextureTypeConflict)
{
const std::string &vertexShader =
"attribute vec2 position;\n"
"varying float color;\n"
"uniform sampler2D tex2D;\n"
"uniform samplerCube texCube;\n"
"void main() {\n"
" gl_Position = vec4(position, 0, 1);\n"
" vec2 texCoord = (position * 0.5) + 0.5;\n"
" color = texture2D(tex2D, texCoord).x;\n"
" color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
"}";
const std::string &fragmentShader =
"varying mediump float color;\n"
"void main() {\n"
" gl_FragColor = vec4(color, 0, 0, 1);\n"
"}";
mProgram = CompileProgram(vertexShader, fragmentShader);
ASSERT_NE(0u, mProgram);
initTextures(1, 0);
glUseProgram(mProgram);
GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
ASSERT_NE(-1, tex2DLocation);
GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
ASSERT_NE(-1, texCubeLocation);
glUniform1i(tex2DLocation, 0);
glUniform1i(texCubeLocation, 0);
ASSERT_GL_NO_ERROR();
drawQuad(mProgram, "position", 0.5f);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
}
// Negative test for rendering with texture outside the valid range.
// TODO(jmadill): Research if this is correct.
TEST_P(TextureLimitsTest, DrawWithTexturePastMaximum)
{
const std::string &vertexShader =
"attribute vec2 position;\n"
"varying float color;\n"
"uniform sampler2D tex2D;\n"
"void main() {\n"
" gl_Position = vec4(position, 0, 1);\n"
" vec2 texCoord = (position * 0.5) + 0.5;\n"
" color = texture2D(tex2D, texCoord).x;\n"
"}";
const std::string &fragmentShader =
"varying mediump float color;\n"
"void main() {\n"
" gl_FragColor = vec4(color, 0, 0, 1);\n"
"}";
mProgram = CompileProgram(vertexShader, fragmentShader);
ASSERT_NE(0u, mProgram);
glUseProgram(mProgram);
GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
ASSERT_NE(-1, tex2DLocation);
glUniform1i(tex2DLocation, mMaxCombinedTextures);
ASSERT_GL_NO_ERROR();
drawQuad(mProgram, "position", 0.5f);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
}
// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
ANGLE_INSTANTIATE_TEST(TextureTest, ES2_D3D9(), ES2_D3D11(), ES2_D3D11_FL9_3()); // TODO(geofflang): Figure out why this test fails on Intel OpenGL
ANGLE_INSTANTIATE_TEST(TextureTestES3, ES3_D3D11(), ES3_OPENGL());
ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL());
} // namespace