1 #include "ANGLETest.h" 2 3 class TextureTest : public ANGLETest 4 { 5 protected: 6 TextureTest() 7 { 8 setWindowWidth(128); 9 setWindowHeight(128); 10 setConfigRedBits(8); 11 setConfigGreenBits(8); 12 setConfigBlueBits(8); 13 setConfigAlphaBits(8); 14 } 15 16 virtual void SetUp() 17 { 18 ANGLETest::SetUp(); 19 glGenTextures(1, &mTexture2D); 20 glGenTextures(1, &mTextureCube); 21 22 glBindTexture(GL_TEXTURE_2D, mTexture2D); 23 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); 24 EXPECT_GL_NO_ERROR(); 25 26 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube); 27 glTexStorage2DEXT(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1); 28 EXPECT_GL_NO_ERROR(); 29 30 ASSERT_GL_NO_ERROR(); 31 32 const std::string vertexShaderSource = SHADER_SOURCE 33 ( 34 precision highp float; 35 attribute vec4 position; 36 varying vec2 texcoord; 37 38 void main() 39 { 40 gl_Position = position; 41 texcoord = (position.xy * 0.5) + 0.5; 42 } 43 ); 44 45 const std::string fragmentShaderSource2D = SHADER_SOURCE 46 ( 47 precision highp float; 48 uniform sampler2D tex; 49 varying vec2 texcoord; 50 51 void main() 52 { 53 gl_FragColor = texture2D(tex, texcoord); 54 } 55 ); 56 57 const std::string fragmentShaderSourceCube = SHADER_SOURCE 58 ( 59 precision highp float; 60 uniform sampler2D tex2D; 61 uniform samplerCube texCube; 62 varying vec2 texcoord; 63 64 void main() 65 { 66 gl_FragColor = texture2D(tex2D, texcoord); 67 gl_FragColor += textureCube(texCube, vec3(texcoord, 0)); 68 } 69 ); 70 71 m2DProgram = CompileProgram(vertexShaderSource, fragmentShaderSource2D); 72 mCubeProgram = CompileProgram(vertexShaderSource, fragmentShaderSourceCube); 73 if (m2DProgram == 0 || mCubeProgram == 0) 74 { 75 FAIL() << "shader compilation failed."; 76 } 77 78 mTexture2DUniformLocation = glGetUniformLocation(m2DProgram, "tex"); 79 } 80 81 virtual void TearDown() 82 { 83 glDeleteTextures(1, &mTexture2D); 84 glDeleteTextures(1, &mTextureCube); 85 glDeleteProgram(m2DProgram); 86 glDeleteProgram(mCubeProgram); 87 88 ANGLETest::TearDown(); 89 } 90 91 GLuint mTexture2D; 92 GLuint mTextureCube; 93 94 GLuint m2DProgram; 95 GLuint mCubeProgram; 96 GLint mTexture2DUniformLocation; 97 }; 98 99 TEST_F(TextureTest, NegativeAPISubImage) 100 { 101 glBindTexture(GL_TEXTURE_2D, mTexture2D); 102 EXPECT_GL_ERROR(GL_NO_ERROR); 103 104 const GLubyte *pixels[20] = { 0 }; 105 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 106 EXPECT_GL_ERROR(GL_INVALID_VALUE); 107 } 108 109 TEST_F(TextureTest, ZeroSizedUploads) 110 { 111 glBindTexture(GL_TEXTURE_2D, mTexture2D); 112 EXPECT_GL_ERROR(GL_NO_ERROR); 113 114 // Use the texture first to make sure it's in video memory 115 glUseProgram(m2DProgram); 116 glUniform1i(mTexture2DUniformLocation, 0); 117 drawQuad(m2DProgram, "position", 0.5f); 118 119 const GLubyte *pixel[4] = { 0 }; 120 121 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel); 122 EXPECT_GL_NO_ERROR(); 123 124 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); 125 EXPECT_GL_NO_ERROR(); 126 127 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel); 128 EXPECT_GL_NO_ERROR(); 129 } 130 131 // Test drawing with two texture types, to trigger an ANGLE bug in validation 132 TEST_F(TextureTest, CubeMapBug) 133 { 134 glActiveTexture(GL_TEXTURE0); 135 glBindTexture(GL_TEXTURE_2D, mTexture2D); 136 glActiveTexture(GL_TEXTURE1); 137 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube); 138 EXPECT_GL_ERROR(GL_NO_ERROR); 139 140 glUseProgram(mCubeProgram); 141 GLint tex2DUniformLocation = glGetUniformLocation(mCubeProgram, "tex2D"); 142 GLint texCubeUniformLocation = glGetUniformLocation(mCubeProgram, "texCube"); 143 EXPECT_NE(-1, tex2DUniformLocation); 144 EXPECT_NE(-1, texCubeUniformLocation); 145 glUniform1i(tex2DUniformLocation, 0); 146 glUniform1i(texCubeUniformLocation, 1); 147 drawQuad(mCubeProgram, "position", 0.5f); 148 EXPECT_GL_NO_ERROR(); 149 } 150