blob: 679a70713e4bc7d4ea09c15b633a8df41fa705f2 [file] [log] [blame]
Jamie Madillfa05f602015-05-07 13:47:11 -04001//
2// Copyright 2015 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Corentin Wallezac3ab882015-05-12 13:31:28 -04007#include "end2end_tests/ANGLETest.h"
Jamie Madillf67115c2014-04-22 13:14:05 -04008
Jamie Madillfa05f602015-05-07 13:47:11 -04009using namespace angle;
Austin Kinross18b931d2014-09-29 12:58:31 -070010
Jamie Madillfa05f602015-05-07 13:47:11 -040011namespace
12{
13
Jamie Madillf67115c2014-04-22 13:14:05 -040014class TextureTest : public ANGLETest
15{
Jamie Madillbc393df2015-01-29 13:46:07 -050016 protected:
Jamie Madillfa05f602015-05-07 13:47:11 -040017 TextureTest()
Jamie Madillf67115c2014-04-22 13:14:05 -040018 {
19 setWindowWidth(128);
20 setWindowHeight(128);
21 setConfigRedBits(8);
22 setConfigGreenBits(8);
23 setConfigBlueBits(8);
24 setConfigAlphaBits(8);
25 }
26
Jamie Madillfa05f602015-05-07 13:47:11 -040027 void SetUp() override
Jamie Madillf67115c2014-04-22 13:14:05 -040028 {
29 ANGLETest::SetUp();
Jamie Madilld4cfa572014-07-08 10:00:32 -040030 glGenTextures(1, &mTexture2D);
31 glGenTextures(1, &mTextureCube);
Jamie Madillf67115c2014-04-22 13:14:05 -040032
Jamie Madilld4cfa572014-07-08 10:00:32 -040033 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -040034 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
35 EXPECT_GL_NO_ERROR();
36
Jamie Madilld4cfa572014-07-08 10:00:32 -040037 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
38 glTexStorage2DEXT(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
39 EXPECT_GL_NO_ERROR();
40
Jamie Madillf67115c2014-04-22 13:14:05 -040041 ASSERT_GL_NO_ERROR();
Geoff Langc41e42d2014-04-28 10:58:16 -040042
43 const std::string vertexShaderSource = SHADER_SOURCE
44 (
45 precision highp float;
46 attribute vec4 position;
47 varying vec2 texcoord;
48
Jamie Madill9aca0592014-10-06 16:26:59 -040049 uniform vec2 textureScale;
50
Geoff Langc41e42d2014-04-28 10:58:16 -040051 void main()
52 {
Jamie Madill9aca0592014-10-06 16:26:59 -040053 gl_Position = vec4(position.xy * textureScale, 0.0, 1.0);
Geoff Langc41e42d2014-04-28 10:58:16 -040054 texcoord = (position.xy * 0.5) + 0.5;
55 }
56 );
57
Jamie Madilld4cfa572014-07-08 10:00:32 -040058 const std::string fragmentShaderSource2D = SHADER_SOURCE
Geoff Langc41e42d2014-04-28 10:58:16 -040059 (
60 precision highp float;
61 uniform sampler2D tex;
62 varying vec2 texcoord;
63
64 void main()
65 {
66 gl_FragColor = texture2D(tex, texcoord);
67 }
68 );
69
Jamie Madilld4cfa572014-07-08 10:00:32 -040070 const std::string fragmentShaderSourceCube = SHADER_SOURCE
71 (
72 precision highp float;
73 uniform sampler2D tex2D;
74 uniform samplerCube texCube;
75 varying vec2 texcoord;
76
77 void main()
78 {
79 gl_FragColor = texture2D(tex2D, texcoord);
80 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
81 }
82 );
83
Jamie Madill5599c8f2014-08-26 13:16:39 -040084 m2DProgram = CompileProgram(vertexShaderSource, fragmentShaderSource2D);
85 mCubeProgram = CompileProgram(vertexShaderSource, fragmentShaderSourceCube);
Jamie Madilld4cfa572014-07-08 10:00:32 -040086 if (m2DProgram == 0 || mCubeProgram == 0)
Geoff Langc41e42d2014-04-28 10:58:16 -040087 {
88 FAIL() << "shader compilation failed.";
89 }
90
Jamie Madilld4cfa572014-07-08 10:00:32 -040091 mTexture2DUniformLocation = glGetUniformLocation(m2DProgram, "tex");
Jamie Madill9aca0592014-10-06 16:26:59 -040092 ASSERT_NE(-1, mTexture2DUniformLocation);
93
94 mTextureScaleUniformLocation = glGetUniformLocation(m2DProgram, "textureScale");
95 ASSERT_NE(-1, mTextureScaleUniformLocation);
96
97 glUseProgram(m2DProgram);
98 glUniform2f(mTextureScaleUniformLocation, 1.0f, 1.0f);
99 glUseProgram(0);
100 ASSERT_GL_NO_ERROR();
Jamie Madillf67115c2014-04-22 13:14:05 -0400101 }
102
Jamie Madillfa05f602015-05-07 13:47:11 -0400103 void TearDown() override
Jamie Madillf67115c2014-04-22 13:14:05 -0400104 {
Jamie Madilld4cfa572014-07-08 10:00:32 -0400105 glDeleteTextures(1, &mTexture2D);
106 glDeleteTextures(1, &mTextureCube);
107 glDeleteProgram(m2DProgram);
108 glDeleteProgram(mCubeProgram);
Jamie Madillf67115c2014-04-22 13:14:05 -0400109
110 ANGLETest::TearDown();
111 }
112
Jamie Madillbc393df2015-01-29 13:46:07 -0500113 // Tests CopyTexSubImage with floating point textures of various formats.
114 void testFloatCopySubImage(int sourceImageChannels, int destImageChannels)
115 {
Geoff Langbde666a2015-04-07 17:17:08 -0400116 // TODO(jmadill): Figure out why this is broken on Intel D3D11
117 if (isIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
118 {
119 std::cout << "Test skipped on Intel D3D11." << std::endl;
120 return;
121 }
122
Geoff Langfbfa47c2015-03-31 11:26:00 -0400123 if (getClientVersion() < 3)
124 {
125 if (!extensionEnabled("GL_OES_texture_float"))
126 {
127 std::cout << "Test skipped due to missing GL_OES_texture_float." << std::endl;
128 return;
129 }
130
131 if ((sourceImageChannels < 3 || destImageChannels < 3) && !extensionEnabled("GL_EXT_texture_rg"))
132 {
133 std::cout << "Test skipped due to missing GL_EXT_texture_rg." << std::endl;
134 return;
135 }
136 }
137
Jamie Madillbc393df2015-01-29 13:46:07 -0500138 GLfloat sourceImageData[4][16] =
139 {
140 { // R
141 1.0f,
142 0.0f,
143 0.0f,
144 1.0f
145 },
146 { // RG
147 1.0f, 0.0f,
148 0.0f, 1.0f,
149 0.0f, 0.0f,
150 1.0f, 1.0f
151 },
152 { // RGB
153 1.0f, 0.0f, 0.0f,
154 0.0f, 1.0f, 0.0f,
155 0.0f, 0.0f, 1.0f,
156 1.0f, 1.0f, 0.0f
157 },
158 { // RGBA
159 1.0f, 0.0f, 0.0f, 1.0f,
160 0.0f, 1.0f, 0.0f, 1.0f,
161 0.0f, 0.0f, 1.0f, 1.0f,
162 1.0f, 1.0f, 0.0f, 1.0f
163 },
164 };
165
166 GLenum imageFormats[] =
167 {
168 GL_R32F,
169 GL_RG32F,
170 GL_RGB32F,
171 GL_RGBA32F,
172 };
173
174 GLenum sourceUnsizedFormats[] =
175 {
176 GL_RED,
177 GL_RG,
178 GL_RGB,
179 GL_RGBA,
180 };
181
182 GLuint textures[2];
183
184 glGenTextures(2, textures);
185
186 GLfloat *imageData = sourceImageData[sourceImageChannels - 1];
187 GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1];
188 GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1];
189 GLenum destImageFormat = imageFormats[destImageChannels - 1];
190
191 glBindTexture(GL_TEXTURE_2D, textures[0]);
192 glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
193 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
194 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
195 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData);
196
hendrikwb27f79a2015-03-04 11:26:46 -0800197 if (sourceImageChannels < 3 && !extensionEnabled("GL_EXT_texture_rg"))
Jamie Madillbc393df2015-01-29 13:46:07 -0500198 {
199 // This is not supported
200 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
201 }
202 else
203 {
204 ASSERT_GL_NO_ERROR();
205 }
206
207 GLuint fbo;
208 glGenFramebuffers(1, &fbo);
209 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
210 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
211
212 glBindTexture(GL_TEXTURE_2D, textures[1]);
213 glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
214 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
215 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
216
217 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
218 ASSERT_GL_NO_ERROR();
219
220 glBindFramebuffer(GL_FRAMEBUFFER, 0);
221 drawQuad(m2DProgram, "position", 0.5f);
222 swapBuffers();
223
224 int testImageChannels = std::min(sourceImageChannels, destImageChannels);
225
226 EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
227 if (testImageChannels > 1)
228 {
229 EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255);
230 EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255);
231 if (testImageChannels > 2)
232 {
233 EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255);
234 }
235 }
236
237 glDeleteFramebuffers(1, &fbo);
238 glDeleteTextures(2, textures);
239
240 ASSERT_GL_NO_ERROR();
241 }
242
Jamie Madilld4cfa572014-07-08 10:00:32 -0400243 GLuint mTexture2D;
244 GLuint mTextureCube;
Geoff Langc41e42d2014-04-28 10:58:16 -0400245
Jamie Madilld4cfa572014-07-08 10:00:32 -0400246 GLuint m2DProgram;
247 GLuint mCubeProgram;
248 GLint mTexture2DUniformLocation;
Jamie Madill9aca0592014-10-06 16:26:59 -0400249 GLint mTextureScaleUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400250};
251
Jamie Madillfa05f602015-05-07 13:47:11 -0400252TEST_P(TextureTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -0400253{
Jamie Madilld4cfa572014-07-08 10:00:32 -0400254 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -0400255 EXPECT_GL_ERROR(GL_NO_ERROR);
256
257 const GLubyte *pixels[20] = { 0 };
258 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
259 EXPECT_GL_ERROR(GL_INVALID_VALUE);
260}
Geoff Langc41e42d2014-04-28 10:58:16 -0400261
Jamie Madillfa05f602015-05-07 13:47:11 -0400262TEST_P(TextureTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -0400263{
Jamie Madilld4cfa572014-07-08 10:00:32 -0400264 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -0400265 EXPECT_GL_ERROR(GL_NO_ERROR);
266
267 // Use the texture first to make sure it's in video memory
Jamie Madilld4cfa572014-07-08 10:00:32 -0400268 glUseProgram(m2DProgram);
269 glUniform1i(mTexture2DUniformLocation, 0);
270 drawQuad(m2DProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -0400271
272 const GLubyte *pixel[4] = { 0 };
273
274 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
275 EXPECT_GL_NO_ERROR();
276
277 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
278 EXPECT_GL_NO_ERROR();
279
280 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
281 EXPECT_GL_NO_ERROR();
282}
Jamie Madilld4cfa572014-07-08 10:00:32 -0400283
284// Test drawing with two texture types, to trigger an ANGLE bug in validation
Jamie Madillfa05f602015-05-07 13:47:11 -0400285TEST_P(TextureTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -0400286{
287 glActiveTexture(GL_TEXTURE0);
288 glBindTexture(GL_TEXTURE_2D, mTexture2D);
289 glActiveTexture(GL_TEXTURE1);
290 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
291 EXPECT_GL_ERROR(GL_NO_ERROR);
292
293 glUseProgram(mCubeProgram);
294 GLint tex2DUniformLocation = glGetUniformLocation(mCubeProgram, "tex2D");
295 GLint texCubeUniformLocation = glGetUniformLocation(mCubeProgram, "texCube");
296 EXPECT_NE(-1, tex2DUniformLocation);
297 EXPECT_NE(-1, texCubeUniformLocation);
298 glUniform1i(tex2DUniformLocation, 0);
299 glUniform1i(texCubeUniformLocation, 1);
300 drawQuad(mCubeProgram, "position", 0.5f);
301 EXPECT_GL_NO_ERROR();
302}
Jamie Madill9aca0592014-10-06 16:26:59 -0400303
304// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Jamie Madillfa05f602015-05-07 13:47:11 -0400305TEST_P(TextureTest, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -0400306{
307 int px = getWindowWidth() / 2;
308 int py = getWindowHeight() / 2;
309
310 glActiveTexture(GL_TEXTURE0);
311 glBindTexture(GL_TEXTURE_2D, mTexture2D);
312
313 // Fill with red
314 std::vector<GLubyte> pixels(4 * 16 * 16);
315 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
316 {
317 pixels[pixelId * 4 + 0] = 255;
318 pixels[pixelId * 4 + 1] = 0;
319 pixels[pixelId * 4 + 2] = 0;
320 pixels[pixelId * 4 + 3] = 255;
321 }
322
323 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
324 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
325 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
326 glGenerateMipmap(GL_TEXTURE_2D);
327
328 glUseProgram(m2DProgram);
329 glUniform1i(mTexture2DUniformLocation, 0);
330 glUniform2f(mTextureScaleUniformLocation, 0.0625f, 0.0625f);
331 drawQuad(m2DProgram, "position", 0.5f);
332 EXPECT_GL_NO_ERROR();
333 EXPECT_PIXEL_EQ(px, py, 255, 0, 0, 255);
334
335 // Fill with blue
336 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
337 {
338 pixels[pixelId * 4 + 0] = 0;
339 pixels[pixelId * 4 + 1] = 0;
340 pixels[pixelId * 4 + 2] = 255;
341 pixels[pixelId * 4 + 3] = 255;
342 }
343
344 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
345 glGenerateMipmap(GL_TEXTURE_2D);
346
347 // Fill with green
348 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
349 {
350 pixels[pixelId * 4 + 0] = 0;
351 pixels[pixelId * 4 + 1] = 255;
352 pixels[pixelId * 4 + 2] = 0;
353 pixels[pixelId * 4 + 3] = 255;
354 }
355
356 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
357 glGenerateMipmap(GL_TEXTURE_2D);
358
359 drawQuad(m2DProgram, "position", 0.5f);
360
361 EXPECT_GL_NO_ERROR();
362 EXPECT_PIXEL_EQ(px, py, 0, 255, 0, 255);
363}
Jamie Madillf8fccb32014-11-12 15:05:26 -0500364
Jamie Madilleb32a2e2014-12-10 14:27:53 -0500365// Test creating a FBO with a cube map render target, to test an ANGLE bug
366// https://code.google.com/p/angleproject/issues/detail?id=849
Jamie Madillfa05f602015-05-07 13:47:11 -0400367TEST_P(TextureTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -0500368{
369 GLuint fbo;
370 glGenFramebuffers(1, &fbo);
371 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
372
373 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
374 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mTextureCube, 0);
375
376 EXPECT_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
377
378 glDeleteFramebuffers(1, &fbo);
379
380 EXPECT_GL_NO_ERROR();
381}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +0000382
383// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a default color.
Jamie Madillfa05f602015-05-07 13:47:11 -0400384TEST_P(TextureTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +0000385{
386 int width = getWindowWidth();
387 int height = getWindowHeight();
388
389 GLuint tex2D;
390 glGenTextures(1, &tex2D);
391 glActiveTexture(GL_TEXTURE0);
392 glBindTexture(GL_TEXTURE_2D, tex2D);
393
394 // Fill with red
395 std::vector<GLubyte> pixels(3 * 16 * 16);
396 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
397 {
398 pixels[pixelId * 3 + 0] = 255;
399 pixels[pixelId * 3 + 1] = 0;
400 pixels[pixelId * 3 + 2] = 0;
401 }
402
403 // ANGLE internally uses RGBA as the DirectX format for RGB images
404 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
405 // The data is kept in a CPU-side image and the image is marked as dirty.
406 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
407
408 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
409 // glTexSubImage2D should take into account that the image is dirty.
410 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
411 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
412 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
413
414 glUseProgram(m2DProgram);
415 glUniform1i(mTexture2DUniformLocation, 0);
416 glUniform2f(mTextureScaleUniformLocation, 1.f, 1.f);
417 drawQuad(m2DProgram, "position", 0.5f);
418 glDeleteTextures(1, &tex2D);
419 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +0000420 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -0400421
422 // Validate that the region of the texture without data has an alpha of 1.0
423 GLubyte pixel[4];
424 glReadPixels(3 * width / 4, 3 * height / 4, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
425 EXPECT_EQ(pixel[3], 255);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +0000426}
427
428// Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has initialized the image with a default color.
Jamie Madillfa05f602015-05-07 13:47:11 -0400429TEST_P(TextureTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +0000430{
431 if (extensionEnabled("NV_pixel_buffer_object"))
432 {
433 int width = getWindowWidth();
434 int height = getWindowHeight();
435
436 GLuint tex2D;
437 glGenTextures(1, &tex2D);
438 glActiveTexture(GL_TEXTURE0);
439 glBindTexture(GL_TEXTURE_2D, tex2D);
440
441 // Fill with red
442 std::vector<GLubyte> pixels(3 * 16 * 16);
443 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
444 {
445 pixels[pixelId * 3 + 0] = 255;
446 pixels[pixelId * 3 + 1] = 0;
447 pixels[pixelId * 3 + 2] = 0;
448 }
449
450 // Read 16x16 region from red backbuffer to PBO
451 GLuint pbo;
452 glGenBuffers(1, &pbo);
453 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
454 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
455
456 // ANGLE internally uses RGBA as the DirectX format for RGB images
457 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
458 // The data is kept in a CPU-side image and the image is marked as dirty.
459 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
460
461 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
462 // glTexSubImage2D should take into account that the image is dirty.
463 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, NULL);
464 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
465 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
466
467 glUseProgram(m2DProgram);
468 glUniform1i(mTexture2DUniformLocation, 0);
469 glUniform2f(mTextureScaleUniformLocation, 1.f, 1.f);
470 drawQuad(m2DProgram, "position", 0.5f);
471 glDeleteTextures(1, &tex2D);
472 glDeleteTextures(1, &pbo);
473 EXPECT_GL_NO_ERROR();
474 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
475 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
476 }
477}
Jamie Madillbc393df2015-01-29 13:46:07 -0500478
479// See description on testFloatCopySubImage
Jamie Madillfa05f602015-05-07 13:47:11 -0400480TEST_P(TextureTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -0500481{
482 testFloatCopySubImage(1, 1);
483}
484
Jamie Madillfa05f602015-05-07 13:47:11 -0400485TEST_P(TextureTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -0500486{
487 testFloatCopySubImage(2, 1);
488}
489
Jamie Madillfa05f602015-05-07 13:47:11 -0400490TEST_P(TextureTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -0500491{
492 testFloatCopySubImage(2, 2);
493}
494
Jamie Madillfa05f602015-05-07 13:47:11 -0400495TEST_P(TextureTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -0500496{
497 testFloatCopySubImage(3, 1);
498}
499
Jamie Madillfa05f602015-05-07 13:47:11 -0400500TEST_P(TextureTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -0500501{
502 testFloatCopySubImage(3, 2);
503}
504
Jamie Madillfa05f602015-05-07 13:47:11 -0400505TEST_P(TextureTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -0500506{
507 testFloatCopySubImage(3, 3);
508}
509
Jamie Madillfa05f602015-05-07 13:47:11 -0400510TEST_P(TextureTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -0500511{
512 testFloatCopySubImage(4, 1);
513}
514
Jamie Madillfa05f602015-05-07 13:47:11 -0400515TEST_P(TextureTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -0500516{
517 testFloatCopySubImage(4, 2);
518}
519
Jamie Madillfa05f602015-05-07 13:47:11 -0400520TEST_P(TextureTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -0500521{
522 testFloatCopySubImage(4, 3);
523}
524
Jamie Madillfa05f602015-05-07 13:47:11 -0400525TEST_P(TextureTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -0500526{
527 testFloatCopySubImage(4, 4);
528}
Austin Kinross07285142015-03-26 11:36:16 -0700529
530// Port of https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
531// Run against GL_ALPHA/UNSIGNED_BYTE format, to ensure that D3D11 Feature Level 9_3 correctly handles GL_ALPHA
Jamie Madillfa05f602015-05-07 13:47:11 -0400532TEST_P(TextureTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -0700533{
534 const int npotTexSize = 5;
535 const int potTexSize = 4; // Should be less than npotTexSize
536 GLuint tex2D;
537
538 if (extensionEnabled("GL_OES_texture_npot"))
539 {
540 // This test isn't applicable if texture_npot is enabled
541 return;
542 }
543
544 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
545
546 glActiveTexture(GL_TEXTURE0);
547 glGenTextures(1, &tex2D);
548 glBindTexture(GL_TEXTURE_2D, tex2D);
549
550 std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize);
551 for (size_t pixelId = 0; pixelId < npotTexSize * npotTexSize; ++pixelId)
552 {
553 pixels[pixelId] = 64;
554 }
555
556 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
557 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
558
559 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
560 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
561 EXPECT_GL_ERROR(GL_INVALID_VALUE);
562
563 // Check that an NPOT texture on level 0 succeeds
564 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
565 EXPECT_GL_NO_ERROR();
566
567 // Check that generateMipmap fails on NPOT
568 glGenerateMipmap(GL_TEXTURE_2D);
569 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
570
571 // Check that nothing is drawn if filtering is not correct for NPOT
572 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
573 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
574 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
575 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
576 glClear(GL_COLOR_BUFFER_BIT);
577 drawQuad(m2DProgram, "position", 1.0f);
578 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
579
580 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
581 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
582 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
583 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
584 glClear(GL_COLOR_BUFFER_BIT);
585 drawQuad(m2DProgram, "position", 1.0f);
586 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
587
588 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
589 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
590 glClear(GL_COLOR_BUFFER_BIT);
591 drawQuad(m2DProgram, "position", 1.0f);
592 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
593
594 // Check that glTexImage2D for POT texture succeeds
595 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
596 EXPECT_GL_NO_ERROR();
597
598 // Check that generateMipmap for an POT texture succeeds
599 glGenerateMipmap(GL_TEXTURE_2D);
600 EXPECT_GL_NO_ERROR();
601
602 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
603 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
604 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
605 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
606 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
607 glClear(GL_COLOR_BUFFER_BIT);
608 drawQuad(m2DProgram, "position", 1.0f);
609 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
610 EXPECT_GL_NO_ERROR();
611}
Jamie Madillfa05f602015-05-07 13:47:11 -0400612
613// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
614ANGLE_INSTANTIATE_TEST(TextureTest, ES2_D3D9(), ES2_D3D11(), ES2_D3D11_FL9_3());
615
616} // namespace