blob: ff53bd96de11c006541f27dd6fd8e95b960cf1ee [file] [log] [blame]
Jamie Madillf67115c2014-04-22 13:14:05 -04001#include "ANGLETest.h"
2
Austin Kinross18b931d2014-09-29 12:58:31 -07003// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
4typedef ::testing::Types<TFT<Gles::Two, Rend::D3D11>, TFT<Gles::Two, Rend::D3D9>> TestFixtureTypes;
5TYPED_TEST_CASE(TextureTest, TestFixtureTypes);
6
7template<typename T>
Jamie Madillf67115c2014-04-22 13:14:05 -04008class TextureTest : public ANGLETest
9{
10protected:
Austin Kinross18b931d2014-09-29 12:58:31 -070011 TextureTest() : ANGLETest(T::GetGlesMajorVersion(), T::GetRequestedRenderer())
Jamie Madillf67115c2014-04-22 13:14:05 -040012 {
13 setWindowWidth(128);
14 setWindowHeight(128);
15 setConfigRedBits(8);
16 setConfigGreenBits(8);
17 setConfigBlueBits(8);
18 setConfigAlphaBits(8);
19 }
20
21 virtual void SetUp()
22 {
23 ANGLETest::SetUp();
Jamie Madilld4cfa572014-07-08 10:00:32 -040024 glGenTextures(1, &mTexture2D);
25 glGenTextures(1, &mTextureCube);
Jamie Madillf67115c2014-04-22 13:14:05 -040026
Jamie Madilld4cfa572014-07-08 10:00:32 -040027 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -040028 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
29 EXPECT_GL_NO_ERROR();
30
Jamie Madilld4cfa572014-07-08 10:00:32 -040031 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
32 glTexStorage2DEXT(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
33 EXPECT_GL_NO_ERROR();
34
Jamie Madillf67115c2014-04-22 13:14:05 -040035 ASSERT_GL_NO_ERROR();
Geoff Langc41e42d2014-04-28 10:58:16 -040036
37 const std::string vertexShaderSource = SHADER_SOURCE
38 (
39 precision highp float;
40 attribute vec4 position;
41 varying vec2 texcoord;
42
Jamie Madill9aca0592014-10-06 16:26:59 -040043 uniform vec2 textureScale;
44
Geoff Langc41e42d2014-04-28 10:58:16 -040045 void main()
46 {
Jamie Madill9aca0592014-10-06 16:26:59 -040047 gl_Position = vec4(position.xy * textureScale, 0.0, 1.0);
Geoff Langc41e42d2014-04-28 10:58:16 -040048 texcoord = (position.xy * 0.5) + 0.5;
49 }
50 );
51
Jamie Madilld4cfa572014-07-08 10:00:32 -040052 const std::string fragmentShaderSource2D = SHADER_SOURCE
Geoff Langc41e42d2014-04-28 10:58:16 -040053 (
54 precision highp float;
55 uniform sampler2D tex;
56 varying vec2 texcoord;
57
58 void main()
59 {
60 gl_FragColor = texture2D(tex, texcoord);
61 }
62 );
63
Jamie Madilld4cfa572014-07-08 10:00:32 -040064 const std::string fragmentShaderSourceCube = SHADER_SOURCE
65 (
66 precision highp float;
67 uniform sampler2D tex2D;
68 uniform samplerCube texCube;
69 varying vec2 texcoord;
70
71 void main()
72 {
73 gl_FragColor = texture2D(tex2D, texcoord);
74 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
75 }
76 );
77
Jamie Madill5599c8f2014-08-26 13:16:39 -040078 m2DProgram = CompileProgram(vertexShaderSource, fragmentShaderSource2D);
79 mCubeProgram = CompileProgram(vertexShaderSource, fragmentShaderSourceCube);
Jamie Madilld4cfa572014-07-08 10:00:32 -040080 if (m2DProgram == 0 || mCubeProgram == 0)
Geoff Langc41e42d2014-04-28 10:58:16 -040081 {
82 FAIL() << "shader compilation failed.";
83 }
84
Jamie Madilld4cfa572014-07-08 10:00:32 -040085 mTexture2DUniformLocation = glGetUniformLocation(m2DProgram, "tex");
Jamie Madill9aca0592014-10-06 16:26:59 -040086 ASSERT_NE(-1, mTexture2DUniformLocation);
87
88 mTextureScaleUniformLocation = glGetUniformLocation(m2DProgram, "textureScale");
89 ASSERT_NE(-1, mTextureScaleUniformLocation);
90
91 glUseProgram(m2DProgram);
92 glUniform2f(mTextureScaleUniformLocation, 1.0f, 1.0f);
93 glUseProgram(0);
94 ASSERT_GL_NO_ERROR();
Jamie Madillf67115c2014-04-22 13:14:05 -040095 }
96
97 virtual void TearDown()
98 {
Jamie Madilld4cfa572014-07-08 10:00:32 -040099 glDeleteTextures(1, &mTexture2D);
100 glDeleteTextures(1, &mTextureCube);
101 glDeleteProgram(m2DProgram);
102 glDeleteProgram(mCubeProgram);
Jamie Madillf67115c2014-04-22 13:14:05 -0400103
104 ANGLETest::TearDown();
105 }
106
Jamie Madilld4cfa572014-07-08 10:00:32 -0400107 GLuint mTexture2D;
108 GLuint mTextureCube;
Geoff Langc41e42d2014-04-28 10:58:16 -0400109
Jamie Madilld4cfa572014-07-08 10:00:32 -0400110 GLuint m2DProgram;
111 GLuint mCubeProgram;
112 GLint mTexture2DUniformLocation;
Jamie Madill9aca0592014-10-06 16:26:59 -0400113 GLint mTextureScaleUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400114};
115
Austin Kinross18b931d2014-09-29 12:58:31 -0700116TYPED_TEST(TextureTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -0400117{
Jamie Madilld4cfa572014-07-08 10:00:32 -0400118 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -0400119 EXPECT_GL_ERROR(GL_NO_ERROR);
120
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);
124}
Geoff Langc41e42d2014-04-28 10:58:16 -0400125
Austin Kinross18b931d2014-09-29 12:58:31 -0700126TYPED_TEST(TextureTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -0400127{
Jamie Madilld4cfa572014-07-08 10:00:32 -0400128 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -0400129 EXPECT_GL_ERROR(GL_NO_ERROR);
130
131 // Use the texture first to make sure it's in video memory
Jamie Madilld4cfa572014-07-08 10:00:32 -0400132 glUseProgram(m2DProgram);
133 glUniform1i(mTexture2DUniformLocation, 0);
134 drawQuad(m2DProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -0400135
136 const GLubyte *pixel[4] = { 0 };
137
138 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
139 EXPECT_GL_NO_ERROR();
140
141 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
142 EXPECT_GL_NO_ERROR();
143
144 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
145 EXPECT_GL_NO_ERROR();
146}
Jamie Madilld4cfa572014-07-08 10:00:32 -0400147
148// Test drawing with two texture types, to trigger an ANGLE bug in validation
Austin Kinross18b931d2014-09-29 12:58:31 -0700149TYPED_TEST(TextureTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -0400150{
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);
156
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();
166}
Jamie Madill9aca0592014-10-06 16:26:59 -0400167
168// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
169TYPED_TEST(TextureTest, MipmapsTwice)
170{
171 int px = getWindowWidth() / 2;
172 int py = getWindowHeight() / 2;
173
174 glActiveTexture(GL_TEXTURE0);
175 glBindTexture(GL_TEXTURE_2D, mTexture2D);
176
177 // Fill with red
178 std::vector<GLubyte> pixels(4 * 16 * 16);
179 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
180 {
181 pixels[pixelId * 4 + 0] = 255;
182 pixels[pixelId * 4 + 1] = 0;
183 pixels[pixelId * 4 + 2] = 0;
184 pixels[pixelId * 4 + 3] = 255;
185 }
186
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);
191
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);
198
199 // Fill with blue
200 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
201 {
202 pixels[pixelId * 4 + 0] = 0;
203 pixels[pixelId * 4 + 1] = 0;
204 pixels[pixelId * 4 + 2] = 255;
205 pixels[pixelId * 4 + 3] = 255;
206 }
207
208 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
209 glGenerateMipmap(GL_TEXTURE_2D);
210
211 // Fill with green
212 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
213 {
214 pixels[pixelId * 4 + 0] = 0;
215 pixels[pixelId * 4 + 1] = 255;
216 pixels[pixelId * 4 + 2] = 0;
217 pixels[pixelId * 4 + 3] = 255;
218 }
219
220 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
221 glGenerateMipmap(GL_TEXTURE_2D);
222
223 drawQuad(m2DProgram, "position", 0.5f);
224
225 EXPECT_GL_NO_ERROR();
226 EXPECT_PIXEL_EQ(px, py, 0, 255, 0, 255);
227}