3 // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
4 typedef ::testing::Types<TFT<Gles::Two, Rend::D3D11>, TFT<Gles::Two, Rend::D3D9>> TestFixtureTypes;
5 TYPED_TEST_CASE(TextureTest, TestFixtureTypes);
8 class TextureTest : public ANGLETest
11 TextureTest() : ANGLETest(T::GetGlesMajorVersion(), T::GetRequestedRenderer())
16 setConfigGreenBits(8);
18 setConfigAlphaBits(8);
24 glGenTextures(1, &mTexture2D);
25 glGenTextures(1, &mTextureCube);
27 glBindTexture(GL_TEXTURE_2D, mTexture2D);
28 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
31 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
32 glTexStorage2DEXT(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
37 const std::string vertexShaderSource = SHADER_SOURCE
39 precision highp float;
40 attribute vec4 position;
41 varying vec2 texcoord;
43 uniform vec2 textureScale;
47 gl_Position = vec4(position.xy * textureScale, 0.0, 1.0);
48 texcoord = (position.xy * 0.5) + 0.5;
52 const std::string fragmentShaderSource2D = SHADER_SOURCE
54 precision highp float;
55 uniform sampler2D tex;
56 varying vec2 texcoord;
60 gl_FragColor = texture2D(tex, texcoord);
64 const std::string fragmentShaderSourceCube = SHADER_SOURCE
66 precision highp float;
67 uniform sampler2D tex2D;
68 uniform samplerCube texCube;
69 varying vec2 texcoord;
73 gl_FragColor = texture2D(tex2D, texcoord);
74 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
78 m2DProgram = CompileProgram(vertexShaderSource, fragmentShaderSource2D);
79 mCubeProgram = CompileProgram(vertexShaderSource, fragmentShaderSourceCube);
80 if (m2DProgram == 0 || mCubeProgram == 0)
82 FAIL() << "shader compilation failed.";
85 mTexture2DUniformLocation = glGetUniformLocation(m2DProgram, "tex");
86 ASSERT_NE(-1, mTexture2DUniformLocation);
88 mTextureScaleUniformLocation = glGetUniformLocation(m2DProgram, "textureScale");
89 ASSERT_NE(-1, mTextureScaleUniformLocation);
91 glUseProgram(m2DProgram);
92 glUniform2f(mTextureScaleUniformLocation, 1.0f, 1.0f);
97 virtual void TearDown()
99 glDeleteTextures(1, &mTexture2D);
100 glDeleteTextures(1, &mTextureCube);
101 glDeleteProgram(m2DProgram);
102 glDeleteProgram(mCubeProgram);
104 ANGLETest::TearDown();
112 GLint mTexture2DUniformLocation;
113 GLint mTextureScaleUniformLocation;
116 TYPED_TEST(TextureTest, NegativeAPISubImage)
118 glBindTexture(GL_TEXTURE_2D, mTexture2D);
119 EXPECT_GL_ERROR(GL_NO_ERROR);
121 const GLubyte *pixels[20] = { 0 };
122 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
123 EXPECT_GL_ERROR(GL_INVALID_VALUE);
126 TYPED_TEST(TextureTest, ZeroSizedUploads)
128 glBindTexture(GL_TEXTURE_2D, mTexture2D);
129 EXPECT_GL_ERROR(GL_NO_ERROR);
131 // Use the texture first to make sure it's in video memory
132 glUseProgram(m2DProgram);
133 glUniform1i(mTexture2DUniformLocation, 0);
134 drawQuad(m2DProgram, "position", 0.5f);
136 const GLubyte *pixel[4] = { 0 };
138 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
139 EXPECT_GL_NO_ERROR();
141 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
142 EXPECT_GL_NO_ERROR();
144 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
145 EXPECT_GL_NO_ERROR();
148 // Test drawing with two texture types, to trigger an ANGLE bug in validation
149 TYPED_TEST(TextureTest, CubeMapBug)
151 glActiveTexture(GL_TEXTURE0);
152 glBindTexture(GL_TEXTURE_2D, mTexture2D);
153 glActiveTexture(GL_TEXTURE1);
154 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
155 EXPECT_GL_ERROR(GL_NO_ERROR);
157 glUseProgram(mCubeProgram);
158 GLint tex2DUniformLocation = glGetUniformLocation(mCubeProgram, "tex2D");
159 GLint texCubeUniformLocation = glGetUniformLocation(mCubeProgram, "texCube");
160 EXPECT_NE(-1, tex2DUniformLocation);
161 EXPECT_NE(-1, texCubeUniformLocation);
162 glUniform1i(tex2DUniformLocation, 0);
163 glUniform1i(texCubeUniformLocation, 1);
164 drawQuad(mCubeProgram, "position", 0.5f);
165 EXPECT_GL_NO_ERROR();
168 // Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
169 TYPED_TEST(TextureTest, MipmapsTwice)
171 int px = getWindowWidth() / 2;
172 int py = getWindowHeight() / 2;
174 glActiveTexture(GL_TEXTURE0);
175 glBindTexture(GL_TEXTURE_2D, mTexture2D);
178 std::vector<GLubyte> pixels(4 * 16 * 16);
179 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
181 pixels[pixelId * 4 + 0] = 255;
182 pixels[pixelId * 4 + 1] = 0;
183 pixels[pixelId * 4 + 2] = 0;
184 pixels[pixelId * 4 + 3] = 255;
187 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
188 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
189 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
190 glGenerateMipmap(GL_TEXTURE_2D);
192 glUseProgram(m2DProgram);
193 glUniform1i(mTexture2DUniformLocation, 0);
194 glUniform2f(mTextureScaleUniformLocation, 0.0625f, 0.0625f);
195 drawQuad(m2DProgram, "position", 0.5f);
196 EXPECT_GL_NO_ERROR();
197 EXPECT_PIXEL_EQ(px, py, 255, 0, 0, 255);
200 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
202 pixels[pixelId * 4 + 0] = 0;
203 pixels[pixelId * 4 + 1] = 0;
204 pixels[pixelId * 4 + 2] = 255;
205 pixels[pixelId * 4 + 3] = 255;
208 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
209 glGenerateMipmap(GL_TEXTURE_2D);
212 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
214 pixels[pixelId * 4 + 0] = 0;
215 pixels[pixelId * 4 + 1] = 255;
216 pixels[pixelId * 4 + 2] = 0;
217 pixels[pixelId * 4 + 3] = 255;
220 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
221 glGenerateMipmap(GL_TEXTURE_2D);
223 drawQuad(m2DProgram, "position", 0.5f);
225 EXPECT_GL_NO_ERROR();
226 EXPECT_PIXEL_EQ(px, py, 0, 255, 0, 255);