blob: 1096709b1b1c348d7593d5c377994f4ea6300455 [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
Jamie Madill14718762016-09-06 15:56:54 -04007#include "common/mathutil.h"
Corentin Wallezd3970de2015-05-14 11:07:48 -04008#include "test_utils/ANGLETest.h"
Olli Etuaho989cac32016-06-08 16:18:49 -07009#include "test_utils/gl_raii.h"
Jamie Madillf67115c2014-04-22 13:14:05 -040010
Jamie Madillfa05f602015-05-07 13:47:11 -040011using namespace angle;
Austin Kinross18b931d2014-09-29 12:58:31 -070012
Jamie Madillfa05f602015-05-07 13:47:11 -040013namespace
14{
15
Vincent Lang25ab4512016-05-13 18:13:59 +020016// Take a pixel, and reset the components not covered by the format to default
Geoff Langf607c602016-09-21 11:46:48 -040017// values. In particular, the default value for the alpha component is 255
Vincent Lang25ab4512016-05-13 18:13:59 +020018// (1.0 as unsigned normalized fixed point value).
Geoff Langf607c602016-09-21 11:46:48 -040019GLColor SliceFormatColor(GLenum format, GLColor full)
Vincent Lang25ab4512016-05-13 18:13:59 +020020{
21 switch (format)
22 {
23 case GL_RED:
Geoff Langf607c602016-09-21 11:46:48 -040024 return GLColor(full.R, 0, 0, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020025 case GL_RG:
Geoff Langf607c602016-09-21 11:46:48 -040026 return GLColor(full.R, full.G, 0, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020027 case GL_RGB:
Geoff Langf607c602016-09-21 11:46:48 -040028 return GLColor(full.R, full.G, full.B, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020029 case GL_RGBA:
30 return full;
31 default:
Jamie Madille1faacb2016-12-13 12:42:14 -050032 EXPECT_TRUE(false);
Geoff Langf607c602016-09-21 11:46:48 -040033 return GLColor::white;
Vincent Lang25ab4512016-05-13 18:13:59 +020034 }
Vincent Lang25ab4512016-05-13 18:13:59 +020035}
36
Olli Etuaho4a8329f2016-01-11 17:12:57 +020037class TexCoordDrawTest : public ANGLETest
Jamie Madillf67115c2014-04-22 13:14:05 -040038{
Jamie Madillbc393df2015-01-29 13:46:07 -050039 protected:
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020040 TexCoordDrawTest() : ANGLETest(), mProgram(0), mFramebuffer(0), mFramebufferColorTexture(0)
Jamie Madillf67115c2014-04-22 13:14:05 -040041 {
42 setWindowWidth(128);
43 setWindowHeight(128);
44 setConfigRedBits(8);
45 setConfigGreenBits(8);
46 setConfigBlueBits(8);
47 setConfigAlphaBits(8);
48 }
49
Olli Etuaho4a8329f2016-01-11 17:12:57 +020050 virtual std::string getVertexShaderSource()
Jamie Madillf67115c2014-04-22 13:14:05 -040051 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +030052 return
53 R"(precision highp float;
Geoff Langc41e42d2014-04-28 10:58:16 -040054 attribute vec4 position;
55 varying vec2 texcoord;
56
57 void main()
58 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +020059 gl_Position = vec4(position.xy, 0.0, 1.0);
Geoff Langc41e42d2014-04-28 10:58:16 -040060 texcoord = (position.xy * 0.5) + 0.5;
Olli Etuahoa20af6d2017-09-18 13:32:29 +030061 })";
Olli Etuaho4a8329f2016-01-11 17:12:57 +020062 }
Geoff Langc41e42d2014-04-28 10:58:16 -040063
Olli Etuaho4a8329f2016-01-11 17:12:57 +020064 virtual std::string getFragmentShaderSource() = 0;
65
Olli Etuahoa1c917f2016-04-06 13:50:03 +030066 virtual void setUpProgram()
Olli Etuaho4a8329f2016-01-11 17:12:57 +020067 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +020068 const std::string vertexShaderSource = getVertexShaderSource();
69 const std::string fragmentShaderSource = getFragmentShaderSource();
70
71 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
72 ASSERT_NE(0u, mProgram);
73 ASSERT_GL_NO_ERROR();
Olli Etuahoa1c917f2016-04-06 13:50:03 +030074 }
75
76 void SetUp() override
77 {
78 ANGLETest::SetUp();
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020079
80 setUpFramebuffer();
Olli Etuaho4a8329f2016-01-11 17:12:57 +020081 }
82
83 void TearDown() override
84 {
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020085 glBindFramebuffer(GL_FRAMEBUFFER, 0);
86 glDeleteFramebuffers(1, &mFramebuffer);
87 glDeleteTextures(1, &mFramebufferColorTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +020088 glDeleteProgram(mProgram);
89 ANGLETest::TearDown();
90 }
91
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020092 void setUpFramebuffer()
93 {
94 // We use an FBO to work around an issue where the default framebuffer applies SRGB
95 // conversion (particularly known to happen incorrectly on Intel GL drivers). It's not
96 // clear whether this issue can even be fixed on all backends. For example GLES 3.0.4 spec
97 // section 4.4 says that the format of the default framebuffer is entirely up to the window
98 // system, so it might be SRGB, and GLES 3.0 doesn't have a "FRAMEBUFFER_SRGB" to turn off
99 // SRGB conversion like desktop GL does.
100 // TODO(oetuaho): Get rid of this if the underlying issue is fixed.
101 glGenFramebuffers(1, &mFramebuffer);
102 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
103
104 glGenTextures(1, &mFramebufferColorTexture);
105 glBindTexture(GL_TEXTURE_2D, mFramebufferColorTexture);
106 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
107 GL_UNSIGNED_BYTE, nullptr);
108 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
109 mFramebufferColorTexture, 0);
110 ASSERT_GL_NO_ERROR();
111 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
112 glBindTexture(GL_TEXTURE_2D, 0);
113 }
114
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200115 // Returns the created texture ID.
116 GLuint create2DTexture()
117 {
118 GLuint texture2D;
119 glGenTextures(1, &texture2D);
120 glBindTexture(GL_TEXTURE_2D, texture2D);
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800121 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200122 EXPECT_GL_NO_ERROR();
123 return texture2D;
124 }
125
126 GLuint mProgram;
Olli Etuaho51f1c0f2016-01-13 16:16:24 +0200127 GLuint mFramebuffer;
128
129 private:
130 GLuint mFramebufferColorTexture;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200131};
132
133class Texture2DTest : public TexCoordDrawTest
134{
135 protected:
136 Texture2DTest() : TexCoordDrawTest(), mTexture2D(0), mTexture2DUniformLocation(-1) {}
137
138 std::string getFragmentShaderSource() override
139 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300140 return
141 R"(precision highp float;
Geoff Langc41e42d2014-04-28 10:58:16 -0400142 uniform sampler2D tex;
143 varying vec2 texcoord;
144
145 void main()
146 {
147 gl_FragColor = texture2D(tex, texcoord);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300148 })";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200149 }
Geoff Langc41e42d2014-04-28 10:58:16 -0400150
Olli Etuaho96963162016-03-21 11:54:33 +0200151 virtual const char *getTextureUniformName() { return "tex"; }
152
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300153 void setUpProgram() override
154 {
155 TexCoordDrawTest::setUpProgram();
156 mTexture2DUniformLocation = glGetUniformLocation(mProgram, getTextureUniformName());
157 ASSERT_NE(-1, mTexture2DUniformLocation);
158 }
159
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200160 void SetUp() override
161 {
162 TexCoordDrawTest::SetUp();
163 mTexture2D = create2DTexture();
Jamie Madilld4cfa572014-07-08 10:00:32 -0400164
Jamie Madill9aca0592014-10-06 16:26:59 -0400165 ASSERT_GL_NO_ERROR();
Jamie Madillf67115c2014-04-22 13:14:05 -0400166 }
167
Jamie Madillfa05f602015-05-07 13:47:11 -0400168 void TearDown() override
Jamie Madillf67115c2014-04-22 13:14:05 -0400169 {
Jamie Madilld4cfa572014-07-08 10:00:32 -0400170 glDeleteTextures(1, &mTexture2D);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200171 TexCoordDrawTest::TearDown();
Jamie Madillf67115c2014-04-22 13:14:05 -0400172 }
173
Jamie Madillbc393df2015-01-29 13:46:07 -0500174 // Tests CopyTexSubImage with floating point textures of various formats.
175 void testFloatCopySubImage(int sourceImageChannels, int destImageChannels)
176 {
Geoff Langbde666a2015-04-07 17:17:08 -0400177 // TODO(jmadill): Figure out why this is broken on Intel D3D11
Jamie Madill518b9fa2016-03-02 11:26:02 -0500178 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
Geoff Langbde666a2015-04-07 17:17:08 -0400179 {
180 std::cout << "Test skipped on Intel D3D11." << std::endl;
181 return;
182 }
183
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300184 setUpProgram();
185
Martin Radev1be913c2016-07-11 17:59:16 +0300186 if (getClientMajorVersion() < 3)
Geoff Langfbfa47c2015-03-31 11:26:00 -0400187 {
Geoff Langc4e93662017-05-01 10:45:59 -0400188 if (!extensionEnabled("GL_EXT_texture_storage"))
189 {
190 std::cout << "Test skipped due to missing GL_EXT_texture_storage." << std::endl;
191 return;
192 }
193
Geoff Langfbfa47c2015-03-31 11:26:00 -0400194 if (!extensionEnabled("GL_OES_texture_float"))
195 {
196 std::cout << "Test skipped due to missing GL_OES_texture_float." << std::endl;
197 return;
198 }
199
200 if ((sourceImageChannels < 3 || destImageChannels < 3) && !extensionEnabled("GL_EXT_texture_rg"))
201 {
202 std::cout << "Test skipped due to missing GL_EXT_texture_rg." << std::endl;
203 return;
204 }
Geoff Lang677bb6f2017-04-05 12:40:40 -0400205
206 if (destImageChannels == 3 && !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"))
207 {
208 std::cout << "Test skipped due to missing GL_CHROMIUM_color_buffer_float_rgb."
209 << std::endl;
210 return;
211 }
212
213 if (destImageChannels == 4 && !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba"))
214 {
215 std::cout << "Test skipped due to missing GL_CHROMIUM_color_buffer_float_rgb."
216 << std::endl;
217 return;
218 }
219
220 if (destImageChannels <= 2)
221 {
222 std::cout << "Test skipped because no extensions grant renderability to 1 and 2 "
223 "channel floating point textures."
224 << std::endl;
225 return;
226 }
227 }
228 else
229 {
230 if (!extensionEnabled("GL_color_buffer_float"))
231 {
232 std::cout << "Test skipped due to missing GL_color_buffer_float." << std::endl;
233 return;
234 }
235
236 if (destImageChannels == 3 && !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"))
237 {
238 std::cout << "Test skipped due to missing GL_CHROMIUM_color_buffer_float_rgb."
239 << std::endl;
240 return;
241 }
Geoff Langfbfa47c2015-03-31 11:26:00 -0400242 }
243
Jamie Madillbc393df2015-01-29 13:46:07 -0500244 GLfloat sourceImageData[4][16] =
245 {
246 { // R
247 1.0f,
248 0.0f,
249 0.0f,
250 1.0f
251 },
252 { // RG
253 1.0f, 0.0f,
254 0.0f, 1.0f,
255 0.0f, 0.0f,
256 1.0f, 1.0f
257 },
258 { // RGB
259 1.0f, 0.0f, 0.0f,
260 0.0f, 1.0f, 0.0f,
261 0.0f, 0.0f, 1.0f,
262 1.0f, 1.0f, 0.0f
263 },
264 { // RGBA
265 1.0f, 0.0f, 0.0f, 1.0f,
266 0.0f, 1.0f, 0.0f, 1.0f,
267 0.0f, 0.0f, 1.0f, 1.0f,
268 1.0f, 1.0f, 0.0f, 1.0f
269 },
270 };
271
272 GLenum imageFormats[] =
273 {
274 GL_R32F,
275 GL_RG32F,
276 GL_RGB32F,
277 GL_RGBA32F,
278 };
279
280 GLenum sourceUnsizedFormats[] =
281 {
282 GL_RED,
283 GL_RG,
284 GL_RGB,
285 GL_RGBA,
286 };
287
288 GLuint textures[2];
289
290 glGenTextures(2, textures);
291
292 GLfloat *imageData = sourceImageData[sourceImageChannels - 1];
293 GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1];
294 GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1];
295 GLenum destImageFormat = imageFormats[destImageChannels - 1];
296
297 glBindTexture(GL_TEXTURE_2D, textures[0]);
Geoff Langc4e93662017-05-01 10:45:59 -0400298 if (getClientMajorVersion() >= 3)
299 {
300 glTexStorage2D(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
301 }
302 else
303 {
304 glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
305 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500306 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
307 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
308 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData);
309
hendrikwb27f79a2015-03-04 11:26:46 -0800310 if (sourceImageChannels < 3 && !extensionEnabled("GL_EXT_texture_rg"))
Jamie Madillbc393df2015-01-29 13:46:07 -0500311 {
312 // This is not supported
313 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
314 }
315 else
316 {
317 ASSERT_GL_NO_ERROR();
318 }
319
320 GLuint fbo;
321 glGenFramebuffers(1, &fbo);
322 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
323 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
324
325 glBindTexture(GL_TEXTURE_2D, textures[1]);
Geoff Langc4e93662017-05-01 10:45:59 -0400326 if (getClientMajorVersion() >= 3)
327 {
328 glTexStorage2D(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
329 }
330 else
331 {
332 glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
333 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500334 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
335 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
336
337 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
338 ASSERT_GL_NO_ERROR();
339
340 glBindFramebuffer(GL_FRAMEBUFFER, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200341 drawQuad(mProgram, "position", 0.5f);
Jamie Madillbc393df2015-01-29 13:46:07 -0500342
343 int testImageChannels = std::min(sourceImageChannels, destImageChannels);
344
Olli Etuahoa314b612016-03-10 16:43:00 +0200345 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Jamie Madillbc393df2015-01-29 13:46:07 -0500346 if (testImageChannels > 1)
347 {
348 EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255);
349 EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255);
350 if (testImageChannels > 2)
351 {
352 EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255);
353 }
354 }
355
356 glDeleteFramebuffers(1, &fbo);
357 glDeleteTextures(2, textures);
358
359 ASSERT_GL_NO_ERROR();
360 }
361
Jamie Madilld4cfa572014-07-08 10:00:32 -0400362 GLuint mTexture2D;
Jamie Madilld4cfa572014-07-08 10:00:32 -0400363 GLint mTexture2DUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400364};
365
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200366class Texture2DTestES3 : public Texture2DTest
367{
368 protected:
369 Texture2DTestES3() : Texture2DTest() {}
370
371 std::string getVertexShaderSource() override
372 {
373 return std::string(
374 "#version 300 es\n"
375 "out vec2 texcoord;\n"
376 "in vec4 position;\n"
377 "void main()\n"
378 "{\n"
379 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
380 " texcoord = (position.xy * 0.5) + 0.5;\n"
381 "}\n");
382 }
383
384 std::string getFragmentShaderSource() override
385 {
386 return std::string(
387 "#version 300 es\n"
388 "precision highp float;\n"
389 "uniform highp sampler2D tex;\n"
390 "in vec2 texcoord;\n"
391 "out vec4 fragColor;\n"
392 "void main()\n"
393 "{\n"
394 " fragColor = texture(tex, texcoord);\n"
395 "}\n");
396 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300397
398 void SetUp() override
399 {
400 Texture2DTest::SetUp();
401 setUpProgram();
402 }
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200403};
404
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200405class Texture2DIntegerAlpha1TestES3 : public Texture2DTest
406{
407 protected:
408 Texture2DIntegerAlpha1TestES3() : Texture2DTest() {}
409
410 std::string getVertexShaderSource() override
411 {
412 return std::string(
413 "#version 300 es\n"
414 "out vec2 texcoord;\n"
415 "in vec4 position;\n"
416 "void main()\n"
417 "{\n"
418 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
419 " texcoord = (position.xy * 0.5) + 0.5;\n"
420 "}\n");
421 }
422
423 std::string getFragmentShaderSource() override
424 {
425 return std::string(
426 "#version 300 es\n"
427 "precision highp float;\n"
428 "uniform highp isampler2D tex;\n"
429 "in vec2 texcoord;\n"
430 "out vec4 fragColor;\n"
431 "void main()\n"
432 "{\n"
433 " vec4 green = vec4(0, 1, 0, 1);\n"
434 " vec4 black = vec4(0, 0, 0, 0);\n"
435 " fragColor = (texture(tex, texcoord).a == 1) ? green : black;\n"
436 "}\n");
437 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300438
439 void SetUp() override
440 {
441 Texture2DTest::SetUp();
442 setUpProgram();
443 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200444};
445
446class Texture2DUnsignedIntegerAlpha1TestES3 : public Texture2DTest
447{
448 protected:
449 Texture2DUnsignedIntegerAlpha1TestES3() : Texture2DTest() {}
450
451 std::string getVertexShaderSource() override
452 {
453 return std::string(
454 "#version 300 es\n"
455 "out vec2 texcoord;\n"
456 "in vec4 position;\n"
457 "void main()\n"
458 "{\n"
459 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
460 " texcoord = (position.xy * 0.5) + 0.5;\n"
461 "}\n");
462 }
463
464 std::string getFragmentShaderSource() override
465 {
466 return std::string(
467 "#version 300 es\n"
468 "precision highp float;\n"
469 "uniform highp usampler2D tex;\n"
470 "in vec2 texcoord;\n"
471 "out vec4 fragColor;\n"
472 "void main()\n"
473 "{\n"
474 " vec4 green = vec4(0, 1, 0, 1);\n"
475 " vec4 black = vec4(0, 0, 0, 0);\n"
476 " fragColor = (texture(tex, texcoord).a == 1u) ? green : black;\n"
477 "}\n");
478 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300479
480 void SetUp() override
481 {
482 Texture2DTest::SetUp();
483 setUpProgram();
484 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200485};
486
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200487class Texture2DTestWithDrawScale : public Texture2DTest
Jamie Madill2453dbc2015-07-14 11:35:42 -0400488{
489 protected:
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200490 Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {}
491
492 std::string getVertexShaderSource() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400493 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300494 return
495 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200496 attribute vec4 position;
497 varying vec2 texcoord;
498
499 uniform vec2 drawScale;
500
501 void main()
502 {
503 gl_Position = vec4(position.xy * drawScale, 0.0, 1.0);
504 texcoord = (position.xy * 0.5) + 0.5;
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300505 })";
Jamie Madill2453dbc2015-07-14 11:35:42 -0400506 }
507
508 void SetUp() override
509 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200510 Texture2DTest::SetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300511
512 setUpProgram();
513
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200514 mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale");
515 ASSERT_NE(-1, mDrawScaleUniformLocation);
Jamie Madill2453dbc2015-07-14 11:35:42 -0400516
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200517 glUseProgram(mProgram);
518 glUniform2f(mDrawScaleUniformLocation, 1.0f, 1.0f);
519 glUseProgram(0);
520 ASSERT_GL_NO_ERROR();
521 }
522
523 GLint mDrawScaleUniformLocation;
524};
525
Olli Etuaho4644a202016-01-12 15:12:53 +0200526class Sampler2DAsFunctionParameterTest : public Texture2DTest
527{
528 protected:
529 Sampler2DAsFunctionParameterTest() : Texture2DTest() {}
530
531 std::string getFragmentShaderSource() override
532 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300533 return
534 R"(precision highp float;
Olli Etuaho4644a202016-01-12 15:12:53 +0200535 uniform sampler2D tex;
536 varying vec2 texcoord;
537
538 vec4 computeFragColor(sampler2D aTex)
539 {
540 return texture2D(aTex, texcoord);
541 }
542
543 void main()
544 {
545 gl_FragColor = computeFragColor(tex);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300546 })";
Olli Etuaho4644a202016-01-12 15:12:53 +0200547 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300548
549 void SetUp() override
550 {
551 Texture2DTest::SetUp();
552 setUpProgram();
553 }
Olli Etuaho4644a202016-01-12 15:12:53 +0200554};
555
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200556class TextureCubeTest : public TexCoordDrawTest
557{
558 protected:
559 TextureCubeTest()
560 : TexCoordDrawTest(),
561 mTexture2D(0),
562 mTextureCube(0),
563 mTexture2DUniformLocation(-1),
564 mTextureCubeUniformLocation(-1)
565 {
566 }
567
568 std::string getFragmentShaderSource() override
569 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300570 return
571 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200572 uniform sampler2D tex2D;
573 uniform samplerCube texCube;
574 varying vec2 texcoord;
575
576 void main()
577 {
578 gl_FragColor = texture2D(tex2D, texcoord);
579 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300580 })";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200581 }
582
583 void SetUp() override
584 {
585 TexCoordDrawTest::SetUp();
586
587 glGenTextures(1, &mTextureCube);
588 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Geoff Langc4e93662017-05-01 10:45:59 -0400589 for (GLenum face = 0; face < 6; face++)
590 {
591 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
592 GL_UNSIGNED_BYTE, nullptr);
593 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200594 EXPECT_GL_NO_ERROR();
595
596 mTexture2D = create2DTexture();
597
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300598 setUpProgram();
599
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200600 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
601 ASSERT_NE(-1, mTexture2DUniformLocation);
602 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
603 ASSERT_NE(-1, mTextureCubeUniformLocation);
604 }
605
606 void TearDown() override
607 {
608 glDeleteTextures(1, &mTextureCube);
609 TexCoordDrawTest::TearDown();
610 }
611
612 GLuint mTexture2D;
613 GLuint mTextureCube;
614 GLint mTexture2DUniformLocation;
615 GLint mTextureCubeUniformLocation;
616};
617
Martin Radev7e2c0d32017-09-15 14:25:42 +0300618class TextureCubeTestES3 : public ANGLETest
619{
620 protected:
621 TextureCubeTestES3() {}
622};
623
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200624class SamplerArrayTest : public TexCoordDrawTest
625{
626 protected:
627 SamplerArrayTest()
628 : TexCoordDrawTest(),
629 mTexture2DA(0),
630 mTexture2DB(0),
631 mTexture0UniformLocation(-1),
632 mTexture1UniformLocation(-1)
633 {
634 }
635
636 std::string getFragmentShaderSource() override
637 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300638 return
639 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200640 uniform highp sampler2D tex2DArray[2];
641 varying vec2 texcoord;
642 void main()
643 {
644 gl_FragColor = texture2D(tex2DArray[0], texcoord);
645 gl_FragColor += texture2D(tex2DArray[1], texcoord);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300646 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200647 }
648
649 void SetUp() override
650 {
651 TexCoordDrawTest::SetUp();
652
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300653 setUpProgram();
654
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200655 mTexture0UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[0]");
656 ASSERT_NE(-1, mTexture0UniformLocation);
657 mTexture1UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[1]");
658 ASSERT_NE(-1, mTexture1UniformLocation);
659
660 mTexture2DA = create2DTexture();
661 mTexture2DB = create2DTexture();
662 ASSERT_GL_NO_ERROR();
663 }
664
665 void TearDown() override
666 {
667 glDeleteTextures(1, &mTexture2DA);
668 glDeleteTextures(1, &mTexture2DB);
669 TexCoordDrawTest::TearDown();
670 }
671
672 void testSamplerArrayDraw()
673 {
674 GLubyte texData[4];
675 texData[0] = 0;
676 texData[1] = 60;
677 texData[2] = 0;
678 texData[3] = 255;
679
680 glActiveTexture(GL_TEXTURE0);
681 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
682 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
683
684 texData[1] = 120;
685 glActiveTexture(GL_TEXTURE1);
686 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
687 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
688 EXPECT_GL_ERROR(GL_NO_ERROR);
689
690 glUseProgram(mProgram);
691 glUniform1i(mTexture0UniformLocation, 0);
692 glUniform1i(mTexture1UniformLocation, 1);
693 drawQuad(mProgram, "position", 0.5f);
694 EXPECT_GL_NO_ERROR();
695
696 EXPECT_PIXEL_NEAR(0, 0, 0, 180, 0, 255, 2);
697 }
698
699 GLuint mTexture2DA;
700 GLuint mTexture2DB;
701 GLint mTexture0UniformLocation;
702 GLint mTexture1UniformLocation;
703};
704
705
706class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest
707{
708 protected:
709 SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {}
710
711 std::string getFragmentShaderSource() override
712 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300713 return
714 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200715 uniform highp sampler2D tex2DArray[2];
716 varying vec2 texcoord;
717
718 vec4 computeFragColor(highp sampler2D aTex2DArray[2])
719 {
720 return texture2D(aTex2DArray[0], texcoord) + texture2D(aTex2DArray[1], texcoord);
721 }
722
723 void main()
724 {
725 gl_FragColor = computeFragColor(tex2DArray);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300726 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200727 }
728};
729
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200730class Texture2DArrayTestES3 : public TexCoordDrawTest
731{
732 protected:
733 Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {}
734
735 std::string getVertexShaderSource() override
736 {
737 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400738 "#version 300 es\n"
739 "out vec2 texcoord;\n"
740 "in vec4 position;\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200741 "void main()\n"
742 "{\n"
743 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
744 " texcoord = (position.xy * 0.5) + 0.5;\n"
745 "}\n");
746 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400747
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200748 std::string getFragmentShaderSource() override
749 {
750 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400751 "#version 300 es\n"
752 "precision highp float;\n"
Olli Etuaho183d7e22015-11-20 15:59:09 +0200753 "uniform highp sampler2DArray tex2DArray;\n"
Jamie Madill2453dbc2015-07-14 11:35:42 -0400754 "in vec2 texcoord;\n"
755 "out vec4 fragColor;\n"
756 "void main()\n"
757 "{\n"
758 " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200759 "}\n");
760 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400761
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200762 void SetUp() override
763 {
764 TexCoordDrawTest::SetUp();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400765
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300766 setUpProgram();
767
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200768 mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray");
Jamie Madill2453dbc2015-07-14 11:35:42 -0400769 ASSERT_NE(-1, mTextureArrayLocation);
770
771 glGenTextures(1, &m2DArrayTexture);
772 ASSERT_GL_NO_ERROR();
773 }
774
775 void TearDown() override
776 {
777 glDeleteTextures(1, &m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200778 TexCoordDrawTest::TearDown();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400779 }
780
781 GLuint m2DArrayTexture;
Jamie Madill2453dbc2015-07-14 11:35:42 -0400782 GLint mTextureArrayLocation;
783};
784
Olli Etuahobce743a2016-01-15 17:18:28 +0200785class TextureSizeTextureArrayTest : public TexCoordDrawTest
786{
787 protected:
788 TextureSizeTextureArrayTest()
789 : TexCoordDrawTest(),
790 mTexture2DA(0),
791 mTexture2DB(0),
792 mTexture0Location(-1),
793 mTexture1Location(-1)
794 {
795 }
796
797 std::string getVertexShaderSource() override
798 {
799 return std::string(
800 "#version 300 es\n"
801 "in vec4 position;\n"
802 "void main()\n"
803 "{\n"
804 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
805 "}\n");
806 }
807
808 std::string getFragmentShaderSource() override
809 {
810 return std::string(
811 "#version 300 es\n"
812 "precision highp float;\n"
813 "uniform highp sampler2D tex2DArray[2];\n"
814 "out vec4 fragColor;\n"
815 "void main()\n"
816 "{\n"
817 " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n"
818 " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n"
819 " fragColor = vec4(red, green, 0.0, 1.0);\n"
820 "}\n");
821 }
822
823 void SetUp() override
824 {
825 TexCoordDrawTest::SetUp();
826
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300827 setUpProgram();
828
Olli Etuahobce743a2016-01-15 17:18:28 +0200829 mTexture0Location = glGetUniformLocation(mProgram, "tex2DArray[0]");
830 ASSERT_NE(-1, mTexture0Location);
831 mTexture1Location = glGetUniformLocation(mProgram, "tex2DArray[1]");
832 ASSERT_NE(-1, mTexture1Location);
833
834 mTexture2DA = create2DTexture();
835 mTexture2DB = create2DTexture();
836 ASSERT_GL_NO_ERROR();
837 }
838
839 void TearDown() override
840 {
841 glDeleteTextures(1, &mTexture2DA);
842 glDeleteTextures(1, &mTexture2DB);
843 TexCoordDrawTest::TearDown();
844 }
845
846 GLuint mTexture2DA;
847 GLuint mTexture2DB;
848 GLint mTexture0Location;
849 GLint mTexture1Location;
850};
851
Olli Etuahoa314b612016-03-10 16:43:00 +0200852class Texture3DTestES3 : public TexCoordDrawTest
853{
854 protected:
855 Texture3DTestES3() : TexCoordDrawTest(), mTexture3D(0), mTexture3DUniformLocation(-1) {}
856
857 std::string getVertexShaderSource() override
858 {
859 return std::string(
860 "#version 300 es\n"
861 "out vec2 texcoord;\n"
862 "in vec4 position;\n"
863 "void main()\n"
864 "{\n"
865 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
866 " texcoord = (position.xy * 0.5) + 0.5;\n"
867 "}\n");
868 }
869
870 std::string getFragmentShaderSource() override
871 {
872 return std::string(
873 "#version 300 es\n"
874 "precision highp float;\n"
875 "uniform highp sampler3D tex3D;\n"
876 "in vec2 texcoord;\n"
877 "out vec4 fragColor;\n"
878 "void main()\n"
879 "{\n"
880 " fragColor = texture(tex3D, vec3(texcoord, 0.0));\n"
881 "}\n");
882 }
883
884 void SetUp() override
885 {
886 TexCoordDrawTest::SetUp();
887
888 glGenTextures(1, &mTexture3D);
889
890 setUpProgram();
891
892 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
893 ASSERT_NE(-1, mTexture3DUniformLocation);
894 }
895
896 void TearDown() override
897 {
898 glDeleteTextures(1, &mTexture3D);
899 TexCoordDrawTest::TearDown();
900 }
901
902 GLuint mTexture3D;
903 GLint mTexture3DUniformLocation;
904};
905
Olli Etuaho1a679902016-01-14 12:21:47 +0200906class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest
907{
908 protected:
909 ShadowSamplerPlusSampler3DTestES3()
910 : TexCoordDrawTest(),
911 mTextureShadow(0),
912 mTexture3D(0),
913 mTextureShadowUniformLocation(-1),
914 mTexture3DUniformLocation(-1),
915 mDepthRefUniformLocation(-1)
916 {
917 }
918
919 std::string getVertexShaderSource() override
920 {
921 return std::string(
922 "#version 300 es\n"
923 "out vec2 texcoord;\n"
924 "in vec4 position;\n"
925 "void main()\n"
926 "{\n"
927 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
928 " texcoord = (position.xy * 0.5) + 0.5;\n"
929 "}\n");
930 }
931
932 std::string getFragmentShaderSource() override
933 {
934 return std::string(
935 "#version 300 es\n"
936 "precision highp float;\n"
937 "uniform highp sampler2DShadow tex2DShadow;\n"
938 "uniform highp sampler3D tex3D;\n"
939 "in vec2 texcoord;\n"
940 "uniform float depthRef;\n"
941 "out vec4 fragColor;\n"
942 "void main()\n"
943 "{\n"
944 " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n"
945 " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n"
946 "}\n");
947 }
948
949 void SetUp() override
950 {
951 TexCoordDrawTest::SetUp();
952
953 glGenTextures(1, &mTexture3D);
954
955 glGenTextures(1, &mTextureShadow);
956 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
957 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
958
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300959 setUpProgram();
960
Olli Etuaho1a679902016-01-14 12:21:47 +0200961 mTextureShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
962 ASSERT_NE(-1, mTextureShadowUniformLocation);
963 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
964 ASSERT_NE(-1, mTexture3DUniformLocation);
965 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
966 ASSERT_NE(-1, mDepthRefUniformLocation);
967 }
968
969 void TearDown() override
970 {
971 glDeleteTextures(1, &mTextureShadow);
972 glDeleteTextures(1, &mTexture3D);
973 TexCoordDrawTest::TearDown();
974 }
975
976 GLuint mTextureShadow;
977 GLuint mTexture3D;
978 GLint mTextureShadowUniformLocation;
979 GLint mTexture3DUniformLocation;
980 GLint mDepthRefUniformLocation;
981};
982
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200983class SamplerTypeMixTestES3 : public TexCoordDrawTest
984{
985 protected:
986 SamplerTypeMixTestES3()
987 : TexCoordDrawTest(),
988 mTexture2D(0),
989 mTextureCube(0),
990 mTexture2DShadow(0),
991 mTextureCubeShadow(0),
992 mTexture2DUniformLocation(-1),
993 mTextureCubeUniformLocation(-1),
994 mTexture2DShadowUniformLocation(-1),
995 mTextureCubeShadowUniformLocation(-1),
996 mDepthRefUniformLocation(-1)
997 {
998 }
999
1000 std::string getVertexShaderSource() override
1001 {
1002 return std::string(
1003 "#version 300 es\n"
1004 "out vec2 texcoord;\n"
1005 "in vec4 position;\n"
1006 "void main()\n"
1007 "{\n"
1008 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1009 " texcoord = (position.xy * 0.5) + 0.5;\n"
1010 "}\n");
1011 }
1012
1013 std::string getFragmentShaderSource() override
1014 {
1015 return std::string(
1016 "#version 300 es\n"
1017 "precision highp float;\n"
1018 "uniform highp sampler2D tex2D;\n"
1019 "uniform highp samplerCube texCube;\n"
1020 "uniform highp sampler2DShadow tex2DShadow;\n"
1021 "uniform highp samplerCubeShadow texCubeShadow;\n"
1022 "in vec2 texcoord;\n"
1023 "uniform float depthRef;\n"
1024 "out vec4 fragColor;\n"
1025 "void main()\n"
1026 "{\n"
1027 " fragColor = texture(tex2D, texcoord);\n"
1028 " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n"
1029 " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n"
1030 " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * "
1031 "0.125);\n"
1032 "}\n");
1033 }
1034
1035 void SetUp() override
1036 {
1037 TexCoordDrawTest::SetUp();
1038
1039 glGenTextures(1, &mTexture2D);
1040 glGenTextures(1, &mTextureCube);
1041
1042 glGenTextures(1, &mTexture2DShadow);
1043 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
1044 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
1045
1046 glGenTextures(1, &mTextureCubeShadow);
1047 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
1048 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
1049
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001050 setUpProgram();
1051
Olli Etuahoc8c99a02016-01-14 16:47:22 +02001052 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
1053 ASSERT_NE(-1, mTexture2DUniformLocation);
1054 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
1055 ASSERT_NE(-1, mTextureCubeUniformLocation);
1056 mTexture2DShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
1057 ASSERT_NE(-1, mTexture2DShadowUniformLocation);
1058 mTextureCubeShadowUniformLocation = glGetUniformLocation(mProgram, "texCubeShadow");
1059 ASSERT_NE(-1, mTextureCubeShadowUniformLocation);
1060 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
1061 ASSERT_NE(-1, mDepthRefUniformLocation);
1062
1063 ASSERT_GL_NO_ERROR();
1064 }
1065
1066 void TearDown() override
1067 {
1068 glDeleteTextures(1, &mTexture2D);
1069 glDeleteTextures(1, &mTextureCube);
1070 glDeleteTextures(1, &mTexture2DShadow);
1071 glDeleteTextures(1, &mTextureCubeShadow);
1072 TexCoordDrawTest::TearDown();
1073 }
1074
1075 GLuint mTexture2D;
1076 GLuint mTextureCube;
1077 GLuint mTexture2DShadow;
1078 GLuint mTextureCubeShadow;
1079 GLint mTexture2DUniformLocation;
1080 GLint mTextureCubeUniformLocation;
1081 GLint mTexture2DShadowUniformLocation;
1082 GLint mTextureCubeShadowUniformLocation;
1083 GLint mDepthRefUniformLocation;
1084};
1085
Olli Etuaho96963162016-03-21 11:54:33 +02001086class SamplerInStructTest : public Texture2DTest
1087{
1088 protected:
1089 SamplerInStructTest() : Texture2DTest() {}
1090
1091 const char *getTextureUniformName() override { return "us.tex"; }
1092
1093 std::string getFragmentShaderSource() override
1094 {
1095 return std::string(
1096 "precision highp float;\n"
1097 "struct S\n"
1098 "{\n"
1099 " vec4 a;\n"
1100 " highp sampler2D tex;\n"
1101 "};\n"
1102 "uniform S us;\n"
1103 "varying vec2 texcoord;\n"
1104 "void main()\n"
1105 "{\n"
1106 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x);\n"
1107 "}\n");
1108 }
1109
1110 void runSamplerInStructTest()
1111 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001112 setUpProgram();
1113
Olli Etuaho96963162016-03-21 11:54:33 +02001114 glActiveTexture(GL_TEXTURE0);
1115 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001116 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1117 &GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001118 drawQuad(mProgram, "position", 0.5f);
Olli Etuahoa314b612016-03-10 16:43:00 +02001119 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001120 }
1121};
1122
1123class SamplerInStructAsFunctionParameterTest : public SamplerInStructTest
1124{
1125 protected:
1126 SamplerInStructAsFunctionParameterTest() : SamplerInStructTest() {}
1127
1128 std::string getFragmentShaderSource() override
1129 {
1130 return std::string(
1131 "precision highp float;\n"
1132 "struct S\n"
1133 "{\n"
1134 " vec4 a;\n"
1135 " highp sampler2D tex;\n"
1136 "};\n"
1137 "uniform S us;\n"
1138 "varying vec2 texcoord;\n"
1139 "vec4 sampleFrom(S s) {\n"
1140 " return texture2D(s.tex, texcoord + s.a.x);\n"
1141 "}\n"
1142 "void main()\n"
1143 "{\n"
1144 " gl_FragColor = sampleFrom(us);\n"
1145 "}\n");
1146 }
1147};
1148
1149class SamplerInStructArrayAsFunctionParameterTest : public SamplerInStructTest
1150{
1151 protected:
1152 SamplerInStructArrayAsFunctionParameterTest() : SamplerInStructTest() {}
1153
1154 const char *getTextureUniformName() override { return "us[0].tex"; }
1155
1156 std::string getFragmentShaderSource() override
1157 {
1158 return std::string(
1159 "precision highp float;\n"
1160 "struct S\n"
1161 "{\n"
1162 " vec4 a;\n"
1163 " highp sampler2D tex;\n"
1164 "};\n"
1165 "uniform S us[1];\n"
1166 "varying vec2 texcoord;\n"
1167 "vec4 sampleFrom(S s) {\n"
1168 " return texture2D(s.tex, texcoord + s.a.x);\n"
1169 "}\n"
1170 "void main()\n"
1171 "{\n"
1172 " gl_FragColor = sampleFrom(us[0]);\n"
1173 "}\n");
1174 }
1175};
1176
1177class SamplerInNestedStructAsFunctionParameterTest : public SamplerInStructTest
1178{
1179 protected:
1180 SamplerInNestedStructAsFunctionParameterTest() : SamplerInStructTest() {}
1181
1182 const char *getTextureUniformName() override { return "us[0].sub.tex"; }
1183
1184 std::string getFragmentShaderSource() override
1185 {
1186 return std::string(
1187 "precision highp float;\n"
1188 "struct SUB\n"
1189 "{\n"
1190 " vec4 a;\n"
1191 " highp sampler2D tex;\n"
1192 "};\n"
1193 "struct S\n"
1194 "{\n"
1195 " SUB sub;\n"
1196 "};\n"
1197 "uniform S us[1];\n"
1198 "varying vec2 texcoord;\n"
1199 "vec4 sampleFrom(SUB s) {\n"
1200 " return texture2D(s.tex, texcoord + s.a.x);\n"
1201 "}\n"
1202 "void main()\n"
1203 "{\n"
1204 " gl_FragColor = sampleFrom(us[0].sub);\n"
1205 "}\n");
1206 }
1207};
1208
1209class SamplerInStructAndOtherVariableTest : public SamplerInStructTest
1210{
1211 protected:
1212 SamplerInStructAndOtherVariableTest() : SamplerInStructTest() {}
1213
1214 std::string getFragmentShaderSource() override
1215 {
1216 return std::string(
1217 "precision highp float;\n"
1218 "struct S\n"
1219 "{\n"
1220 " vec4 a;\n"
1221 " highp sampler2D tex;\n"
1222 "};\n"
1223 "uniform S us;\n"
1224 "uniform float us_tex;\n"
1225 "varying vec2 texcoord;\n"
1226 "void main()\n"
1227 "{\n"
1228 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x + us_tex);\n"
1229 "}\n");
1230 }
1231};
1232
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001233TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001234{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001235 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001236 EXPECT_GL_ERROR(GL_NO_ERROR);
1237
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001238 setUpProgram();
1239
Jamie Madillf67115c2014-04-22 13:14:05 -04001240 const GLubyte *pixels[20] = { 0 };
1241 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1242 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001243
1244 if (extensionEnabled("GL_EXT_texture_storage"))
1245 {
1246 // Create a 1-level immutable texture.
1247 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1248
1249 // Try calling sub image on the second level.
1250 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1251 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1252 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001253}
Geoff Langc41e42d2014-04-28 10:58:16 -04001254
John Bauman18319182016-09-28 14:22:27 -07001255// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1256TEST_P(Texture2DTest, QueryBinding)
1257{
1258 glBindTexture(GL_TEXTURE_2D, 0);
1259 EXPECT_GL_ERROR(GL_NO_ERROR);
1260
1261 GLint textureBinding;
1262 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1263 EXPECT_GL_NO_ERROR();
1264 EXPECT_EQ(0, textureBinding);
1265
1266 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
1267 if (extensionEnabled("GL_OES_EGL_image_external") ||
1268 extensionEnabled("GL_NV_EGL_stream_consumer_external"))
1269 {
1270 EXPECT_GL_NO_ERROR();
1271 EXPECT_EQ(0, textureBinding);
1272 }
1273 else
1274 {
1275 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1276 }
1277}
1278
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001279TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001280{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001281 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001282 EXPECT_GL_ERROR(GL_NO_ERROR);
1283
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001284 setUpProgram();
1285
Geoff Langc41e42d2014-04-28 10:58:16 -04001286 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001287 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001288 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001289 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001290
1291 const GLubyte *pixel[4] = { 0 };
1292
1293 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1294 EXPECT_GL_NO_ERROR();
1295
1296 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1297 EXPECT_GL_NO_ERROR();
1298
1299 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1300 EXPECT_GL_NO_ERROR();
1301}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001302
1303// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001304TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001305{
1306 glActiveTexture(GL_TEXTURE0);
1307 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1308 glActiveTexture(GL_TEXTURE1);
1309 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1310 EXPECT_GL_ERROR(GL_NO_ERROR);
1311
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001312 glUseProgram(mProgram);
1313 glUniform1i(mTexture2DUniformLocation, 0);
1314 glUniform1i(mTextureCubeUniformLocation, 1);
1315 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001316 EXPECT_GL_NO_ERROR();
1317}
Jamie Madill9aca0592014-10-06 16:26:59 -04001318
Olli Etuaho53a2da12016-01-11 15:43:32 +02001319// Test drawing with two texture types accessed from the same shader and check that the result of
1320// drawing is correct.
1321TEST_P(TextureCubeTest, CubeMapDraw)
1322{
1323 GLubyte texData[4];
1324 texData[0] = 0;
1325 texData[1] = 60;
1326 texData[2] = 0;
1327 texData[3] = 255;
1328
1329 glActiveTexture(GL_TEXTURE0);
1330 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1331 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1332
1333 glActiveTexture(GL_TEXTURE1);
1334 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1335 texData[1] = 120;
1336 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1337 texData);
1338 EXPECT_GL_ERROR(GL_NO_ERROR);
1339
1340 glUseProgram(mProgram);
1341 glUniform1i(mTexture2DUniformLocation, 0);
1342 glUniform1i(mTextureCubeUniformLocation, 1);
1343 drawQuad(mProgram, "position", 0.5f);
1344 EXPECT_GL_NO_ERROR();
1345
1346 int px = getWindowWidth() - 1;
1347 int py = 0;
1348 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1349}
1350
Olli Etuaho4644a202016-01-12 15:12:53 +02001351TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1352{
1353 glActiveTexture(GL_TEXTURE0);
1354 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1355 GLubyte texData[4];
1356 texData[0] = 0;
1357 texData[1] = 128;
1358 texData[2] = 0;
1359 texData[3] = 255;
1360 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1361 glUseProgram(mProgram);
1362 glUniform1i(mTexture2DUniformLocation, 0);
1363 drawQuad(mProgram, "position", 0.5f);
1364 EXPECT_GL_NO_ERROR();
1365
1366 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1367}
1368
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001369// Test drawing with two textures passed to the shader in a sampler array.
1370TEST_P(SamplerArrayTest, SamplerArrayDraw)
1371{
1372 testSamplerArrayDraw();
1373}
1374
1375// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1376// user-defined function in the shader.
1377TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1378{
1379 testSamplerArrayDraw();
1380}
1381
Jamie Madill9aca0592014-10-06 16:26:59 -04001382// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001383TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001384{
1385 int px = getWindowWidth() / 2;
1386 int py = getWindowHeight() / 2;
1387
1388 glActiveTexture(GL_TEXTURE0);
1389 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1390
Olli Etuahoa314b612016-03-10 16:43:00 +02001391 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001392
Olli Etuahoa314b612016-03-10 16:43:00 +02001393 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001394 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1395 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1396 glGenerateMipmap(GL_TEXTURE_2D);
1397
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001398 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001399 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001400 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1401 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001402 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001403 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001404
Olli Etuahoa314b612016-03-10 16:43:00 +02001405 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001406
Olli Etuahoa314b612016-03-10 16:43:00 +02001407 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1408 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001409 glGenerateMipmap(GL_TEXTURE_2D);
1410
Olli Etuahoa314b612016-03-10 16:43:00 +02001411 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001412
Olli Etuahoa314b612016-03-10 16:43:00 +02001413 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1414 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001415 glGenerateMipmap(GL_TEXTURE_2D);
1416
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001417 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001418
1419 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001420 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001421}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001422
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001423// Test creating a FBO with a cube map render target, to test an ANGLE bug
1424// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001425TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001426{
1427 GLuint fbo;
1428 glGenFramebuffers(1, &fbo);
1429 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1430
1431 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1432 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mTextureCube, 0);
1433
Corentin Wallez322653b2015-06-17 18:33:56 +02001434 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001435
1436 glDeleteFramebuffers(1, &fbo);
1437
1438 EXPECT_GL_NO_ERROR();
1439}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001440
1441// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001442TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001443{
Geoff Langc4e93662017-05-01 10:45:59 -04001444 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_texture_storage"))
1445 {
1446 std::cout << "Test skipped because ES3 or GL_EXT_texture_storage not available."
1447 << std::endl;
1448 return;
1449 }
1450
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001451 int width = getWindowWidth();
1452 int height = getWindowHeight();
1453
1454 GLuint tex2D;
1455 glGenTextures(1, &tex2D);
1456 glActiveTexture(GL_TEXTURE0);
1457 glBindTexture(GL_TEXTURE_2D, tex2D);
1458
1459 // Fill with red
1460 std::vector<GLubyte> pixels(3 * 16 * 16);
1461 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1462 {
1463 pixels[pixelId * 3 + 0] = 255;
1464 pixels[pixelId * 3 + 1] = 0;
1465 pixels[pixelId * 3 + 2] = 0;
1466 }
1467
1468 // ANGLE internally uses RGBA as the DirectX format for RGB images
1469 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1470 // The data is kept in a CPU-side image and the image is marked as dirty.
Geoff Langc4e93662017-05-01 10:45:59 -04001471 if (getClientMajorVersion() >= 3)
1472 {
1473 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1474 }
1475 else
1476 {
1477 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1478 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001479
1480 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1481 // glTexSubImage2D should take into account that the image is dirty.
1482 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1483 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1484 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1485
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001486 setUpProgram();
1487
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001488 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001489 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001490 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001491 glDeleteTextures(1, &tex2D);
1492 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001493 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001494
1495 // Validate that the region of the texture without data has an alpha of 1.0
1496 GLubyte pixel[4];
1497 glReadPixels(3 * width / 4, 3 * height / 4, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1498 EXPECT_EQ(pixel[3], 255);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001499}
1500
1501// Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001502TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001503{
1504 if (extensionEnabled("NV_pixel_buffer_object"))
1505 {
1506 int width = getWindowWidth();
1507 int height = getWindowHeight();
1508
1509 GLuint tex2D;
1510 glGenTextures(1, &tex2D);
1511 glActiveTexture(GL_TEXTURE0);
1512 glBindTexture(GL_TEXTURE_2D, tex2D);
1513
1514 // Fill with red
1515 std::vector<GLubyte> pixels(3 * 16 * 16);
1516 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1517 {
1518 pixels[pixelId * 3 + 0] = 255;
1519 pixels[pixelId * 3 + 1] = 0;
1520 pixels[pixelId * 3 + 2] = 0;
1521 }
1522
1523 // Read 16x16 region from red backbuffer to PBO
1524 GLuint pbo;
1525 glGenBuffers(1, &pbo);
1526 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1527 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1528
1529 // ANGLE internally uses RGBA as the DirectX format for RGB images
1530 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1531 // The data is kept in a CPU-side image and the image is marked as dirty.
1532 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1533
1534 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1535 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001536 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001537 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1538 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1539
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001540 setUpProgram();
1541
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001542 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001543 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001544 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001545 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001546 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001547 EXPECT_GL_NO_ERROR();
1548 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1549 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1550 }
1551}
Jamie Madillbc393df2015-01-29 13:46:07 -05001552
1553// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001554TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001555{
1556 testFloatCopySubImage(1, 1);
1557}
1558
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001559TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001560{
1561 testFloatCopySubImage(2, 1);
1562}
1563
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001564TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001565{
1566 testFloatCopySubImage(2, 2);
1567}
1568
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001569TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001570{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001571 if (IsIntel() && IsLinux())
1572 {
1573 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1574 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1575 return;
1576 }
1577
Jamie Madillbc393df2015-01-29 13:46:07 -05001578 testFloatCopySubImage(3, 1);
1579}
1580
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001581TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001582{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001583 if (IsIntel() && IsLinux())
1584 {
1585 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1586 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1587 return;
1588 }
1589
Jamie Madillbc393df2015-01-29 13:46:07 -05001590 testFloatCopySubImage(3, 2);
1591}
1592
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001593TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001594{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001595 if (IsIntel() && IsLinux())
1596 {
1597 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1598 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1599 return;
1600 }
1601
Austin Kinrossd544cc92016-01-11 15:26:42 -08001602 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001603 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001604 {
1605 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1606 return;
1607 }
1608
Jamie Madillbc393df2015-01-29 13:46:07 -05001609 testFloatCopySubImage(3, 3);
1610}
1611
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001612TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001613{
1614 testFloatCopySubImage(4, 1);
1615}
1616
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001617TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001618{
1619 testFloatCopySubImage(4, 2);
1620}
1621
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001622TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001623{
Austin Kinrossd544cc92016-01-11 15:26:42 -08001624 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001625 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001626 {
1627 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1628 return;
1629 }
1630
Jamie Madillbc393df2015-01-29 13:46:07 -05001631 testFloatCopySubImage(4, 3);
1632}
1633
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001634TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001635{
Austin Kinrossd544cc92016-01-11 15:26:42 -08001636 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001637 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001638 {
1639 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1640 return;
1641 }
1642
Jamie Madillbc393df2015-01-29 13:46:07 -05001643 testFloatCopySubImage(4, 4);
1644}
Austin Kinross07285142015-03-26 11:36:16 -07001645
1646// Port of https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1647// Run against GL_ALPHA/UNSIGNED_BYTE format, to ensure that D3D11 Feature Level 9_3 correctly handles GL_ALPHA
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001648TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001649{
1650 const int npotTexSize = 5;
1651 const int potTexSize = 4; // Should be less than npotTexSize
1652 GLuint tex2D;
1653
1654 if (extensionEnabled("GL_OES_texture_npot"))
1655 {
1656 // This test isn't applicable if texture_npot is enabled
1657 return;
1658 }
1659
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001660 setUpProgram();
1661
Austin Kinross07285142015-03-26 11:36:16 -07001662 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1663
Austin Kinross5faa15b2016-01-11 13:32:48 -08001664 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1665 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1666
Austin Kinross07285142015-03-26 11:36:16 -07001667 glActiveTexture(GL_TEXTURE0);
1668 glGenTextures(1, &tex2D);
1669 glBindTexture(GL_TEXTURE_2D, tex2D);
1670
1671 std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize);
1672 for (size_t pixelId = 0; pixelId < npotTexSize * npotTexSize; ++pixelId)
1673 {
1674 pixels[pixelId] = 64;
1675 }
1676
1677 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1678 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1679
1680 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
1681 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1682 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1683
1684 // Check that an NPOT texture on level 0 succeeds
1685 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1686 EXPECT_GL_NO_ERROR();
1687
1688 // Check that generateMipmap fails on NPOT
1689 glGenerateMipmap(GL_TEXTURE_2D);
1690 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1691
1692 // Check that nothing is drawn if filtering is not correct for NPOT
1693 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1694 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1695 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1696 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1697 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001698 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001699 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1700
1701 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1702 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1703 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1704 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1705 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001706 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001707 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1708
1709 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1710 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1711 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001712 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001713 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1714
1715 // Check that glTexImage2D for POT texture succeeds
1716 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1717 EXPECT_GL_NO_ERROR();
1718
1719 // Check that generateMipmap for an POT texture succeeds
1720 glGenerateMipmap(GL_TEXTURE_2D);
1721 EXPECT_GL_NO_ERROR();
1722
1723 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1724 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1725 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1726 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1727 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1728 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001729 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001730 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1731 EXPECT_GL_NO_ERROR();
1732}
Jamie Madillfa05f602015-05-07 13:47:11 -04001733
Austin Kinross08528e12015-10-07 16:24:40 -07001734// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1735// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001736TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001737{
Geoff Lange0cc2a42016-01-20 10:58:17 -05001738 // TODO(geofflang): Allow the GL backend to accept SubImage calls with a null data ptr. (bug
1739 // 1278)
1740 if (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
1741 getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE)
1742 {
1743 std::cout << "Test disabled on OpenGL." << std::endl;
1744 return;
1745 }
1746
Austin Kinross08528e12015-10-07 16:24:40 -07001747 glActiveTexture(GL_TEXTURE0);
1748 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1749
1750 // Create an 8x8 (i.e. power-of-two) texture.
1751 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1752 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1753 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1754 glGenerateMipmap(GL_TEXTURE_2D);
1755
1756 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1757 // This should always work, even if GL_OES_texture_npot isn't active.
1758 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1759
1760 EXPECT_GL_NO_ERROR();
1761}
1762
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001763// Test to check that texture completeness is determined correctly when the texture base level is
1764// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1765TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1766{
1767 glActiveTexture(GL_TEXTURE0);
1768 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001769
1770 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1771 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1772 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1773 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1774 texDataGreen.data());
1775 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1776 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001777 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1778 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1779 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1780
1781 EXPECT_GL_NO_ERROR();
1782
1783 drawQuad(mProgram, "position", 0.5f);
1784
Olli Etuahoa314b612016-03-10 16:43:00 +02001785 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1786}
1787
1788// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1789// have images defined.
1790TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1791{
1792 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1793 {
1794 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1795 std::cout << "Test skipped on AMD OpenGL." << std::endl;
1796 return;
1797 }
1798 if (IsOSX())
1799 {
1800 // Observed incorrect rendering on OSX.
1801 std::cout << "Test skipped on OSX." << std::endl;
1802 return;
1803 }
1804 glActiveTexture(GL_TEXTURE0);
1805 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1806 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1807 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1808 texDataGreen.data());
1809 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1810 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1811 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1812 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1813
1814 EXPECT_GL_NO_ERROR();
1815
1816 drawQuad(mProgram, "position", 0.5f);
1817
1818 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1819}
1820
Olli Etuahoe8528d82016-05-16 17:50:52 +03001821// Test that drawing works correctly when level 0 is undefined and base level is 1.
1822TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1823{
1824 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1825 {
1826 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1827 std::cout << "Test skipped on AMD OpenGL." << std::endl;
1828 return;
1829 }
1830 if (IsOSX())
1831 {
1832 // Observed incorrect rendering on OSX.
1833 std::cout << "Test skipped on OSX." << std::endl;
1834 return;
1835 }
1836 glActiveTexture(GL_TEXTURE0);
1837 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1838 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1839 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1840 texDataGreen.data());
1841 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1842 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1843 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1844 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1845
1846 EXPECT_GL_NO_ERROR();
1847
1848 // Texture is incomplete.
1849 drawQuad(mProgram, "position", 0.5f);
1850 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1851
1852 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1853 texDataGreen.data());
1854
1855 // Texture is now complete.
1856 drawQuad(mProgram, "position", 0.5f);
1857 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1858}
1859
Olli Etuahoa314b612016-03-10 16:43:00 +02001860// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1861// dimensions that don't fit the images inside the range.
1862// GLES 3.0.4 section 3.8.13 Texture completeness
1863TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1864{
1865 if (IsOSX())
1866 {
1867 // Observed incorrect rendering on OSX.
1868 std::cout << "Test skipped on OSX." << std::endl;
1869 return;
1870 }
1871 glActiveTexture(GL_TEXTURE0);
1872 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1873 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1874 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1875 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1876
1877 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1878 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1879
1880 // Two levels that are initially unused.
1881 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1882 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1883 texDataCyan.data());
1884
1885 // One level that is used - only this level should affect completeness.
1886 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1887 texDataGreen.data());
1888
1889 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1890 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1891
1892 EXPECT_GL_NO_ERROR();
1893
1894 drawQuad(mProgram, "position", 0.5f);
1895
1896 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1897
1898 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1899 {
1900 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
1901 // level was changed.
1902 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
1903 return;
1904 }
1905
1906 // Switch the level that is being used to the cyan level 2.
1907 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1908 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1909
1910 EXPECT_GL_NO_ERROR();
1911
1912 drawQuad(mProgram, "position", 0.5f);
1913
1914 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1915}
1916
1917// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1918// have images defined.
1919TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1920{
1921 if (IsOSX())
1922 {
1923 // Observed incorrect rendering on OSX.
1924 std::cout << "Test skipped on OSX." << std::endl;
1925 return;
1926 }
1927 glActiveTexture(GL_TEXTURE0);
1928 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1929 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1930 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1931 texDataGreen.data());
1932 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1933 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1934 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1935 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1936
1937 EXPECT_GL_NO_ERROR();
1938
1939 drawQuad(mProgram, "position", 0.5f);
1940
1941 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1942}
1943
1944// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1945// dimensions that don't fit the images inside the range.
1946// GLES 3.0.4 section 3.8.13 Texture completeness
1947TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1948{
1949 if (IsOSX())
1950 {
1951 // Observed incorrect rendering on OSX.
1952 std::cout << "Test skipped on OSX." << std::endl;
1953 return;
1954 }
1955 glActiveTexture(GL_TEXTURE0);
1956 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1957 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1958 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1959 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1960
1961 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1962 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1963
1964 // Two levels that are initially unused.
1965 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1966 texDataRed.data());
1967 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1968 texDataCyan.data());
1969
1970 // One level that is used - only this level should affect completeness.
1971 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1972 texDataGreen.data());
1973
1974 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1975 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1976
1977 EXPECT_GL_NO_ERROR();
1978
1979 drawQuad(mProgram, "position", 0.5f);
1980
1981 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1982
1983 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1984 {
1985 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
1986 // level was changed.
1987 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
1988 return;
1989 }
1990
1991 // Switch the level that is being used to the cyan level 2.
1992 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
1993 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
1994
1995 EXPECT_GL_NO_ERROR();
1996
1997 drawQuad(mProgram, "position", 0.5f);
1998
1999 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2000}
2001
2002// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2003// have images defined.
2004TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
2005{
2006 if (IsOSX())
2007 {
2008 // Observed incorrect rendering on OSX.
2009 std::cout << "Test skipped on OSX." << std::endl;
2010 return;
2011 }
2012 glActiveTexture(GL_TEXTURE0);
2013 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
2014 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2015 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2016 texDataGreen.data());
2017 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2018 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2019 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2020 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2021
2022 EXPECT_GL_NO_ERROR();
2023
2024 drawQuad(mProgram, "position", 0.5f);
2025
2026 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2027}
2028
2029// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2030// dimensions that don't fit the images inside the range.
2031// GLES 3.0.4 section 3.8.13 Texture completeness
2032TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2033{
2034 if (IsOSX())
2035 {
2036 // Observed incorrect rendering on OSX.
2037 std::cout << "Test skipped on OSX." << std::endl;
2038 return;
2039 }
2040 glActiveTexture(GL_TEXTURE0);
2041 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
2042 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2043 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2044 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2045
2046 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2047 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2048
2049 // Two levels that are initially unused.
2050 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2051 texDataRed.data());
2052 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2053 texDataCyan.data());
2054
2055 // One level that is used - only this level should affect completeness.
2056 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2057 texDataGreen.data());
2058
2059 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2060 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2061
2062 EXPECT_GL_NO_ERROR();
2063
2064 drawQuad(mProgram, "position", 0.5f);
2065
2066 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2067
2068 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2069 {
2070 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
2071 // level was changed.
2072 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
2073 return;
2074 }
2075 if (IsNVIDIA() && (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
2076 getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE))
2077 {
2078 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
2079 // level was changed.
2080 std::cout << "Test partially skipped on NVIDIA OpenGL." << std::endl;
2081 return;
2082 }
2083
2084 // Switch the level that is being used to the cyan level 2.
2085 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2086 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2087
2088 EXPECT_GL_NO_ERROR();
2089
2090 drawQuad(mProgram, "position", 0.5f);
2091
2092 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2093}
2094
2095// Test that texture completeness is updated if texture max level changes.
2096// GLES 3.0.4 section 3.8.13 Texture completeness
2097TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2098{
2099 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2100 {
2101 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2102 // the base level.
2103 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2104 return;
2105 }
2106 if (IsOSX())
2107 {
2108 // Observed incorrect rendering on OSX.
2109 std::cout << "Test skipped on OSX." << std::endl;
2110 return;
2111 }
2112
2113 glActiveTexture(GL_TEXTURE0);
2114 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2115 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2116
2117 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2118 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2119
2120 // A level that is initially unused.
2121 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2122 texDataGreen.data());
2123
2124 // One level that is initially used - only this level should affect completeness.
2125 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2126 texDataGreen.data());
2127
2128 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2129 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2130
2131 EXPECT_GL_NO_ERROR();
2132
2133 drawQuad(mProgram, "position", 0.5f);
2134
2135 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2136
2137 // Switch the max level to level 1. The levels within the used range now have inconsistent
2138 // dimensions and the texture should be incomplete.
2139 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2140
2141 EXPECT_GL_NO_ERROR();
2142
2143 drawQuad(mProgram, "position", 0.5f);
2144
2145 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2146}
2147
2148// Test that 3D texture completeness is updated if texture max level changes.
2149// GLES 3.0.4 section 3.8.13 Texture completeness
2150TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2151{
2152 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2153 {
2154 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2155 // the base level.
2156 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2157 return;
2158 }
2159 if (IsOSX())
2160 {
2161 // Observed incorrect rendering on OSX.
2162 std::cout << "Test skipped on OSX." << std::endl;
2163 return;
2164 }
2165
2166 glActiveTexture(GL_TEXTURE0);
2167 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2168 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2169
2170 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2171 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2172
2173 // A level that is initially unused.
2174 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2175 texDataGreen.data());
2176
2177 // One level that is initially used - only this level should affect completeness.
2178 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2179 texDataGreen.data());
2180
2181 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2182 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2183
2184 EXPECT_GL_NO_ERROR();
2185
2186 drawQuad(mProgram, "position", 0.5f);
2187
2188 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2189
2190 // Switch the max level to level 1. The levels within the used range now have inconsistent
2191 // dimensions and the texture should be incomplete.
2192 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2193
2194 EXPECT_GL_NO_ERROR();
2195
2196 drawQuad(mProgram, "position", 0.5f);
2197
2198 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2199}
2200
2201// Test that texture completeness is updated if texture base level changes.
2202// GLES 3.0.4 section 3.8.13 Texture completeness
2203TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2204{
2205 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2206 {
2207 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2208 // the base level.
2209 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2210 return;
2211 }
2212
2213 glActiveTexture(GL_TEXTURE0);
2214 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2215 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2216
2217 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2218 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2219
2220 // Two levels that are initially unused.
2221 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2222 texDataGreen.data());
2223 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2224 texDataGreen.data());
2225
2226 // One level that is initially used - only this level should affect completeness.
2227 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2228 texDataGreen.data());
2229
2230 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2231 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2232
2233 EXPECT_GL_NO_ERROR();
2234
2235 drawQuad(mProgram, "position", 0.5f);
2236
2237 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2238
2239 // Switch the base level to level 1. The levels within the used range now have inconsistent
2240 // dimensions and the texture should be incomplete.
2241 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2242
2243 EXPECT_GL_NO_ERROR();
2244
2245 drawQuad(mProgram, "position", 0.5f);
2246
2247 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2248}
2249
2250// Test that texture is not complete if base level is greater than max level.
2251// GLES 3.0.4 section 3.8.13 Texture completeness
2252TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2253{
2254 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2255 {
2256 // Intel Windows OpenGL driver crashes if the base level of a non-immutable texture is out
2257 // of range.
2258 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2259 return;
2260 }
2261
2262 glActiveTexture(GL_TEXTURE0);
2263 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2264
2265 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2266 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2267
2268 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2269
2270 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2271 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2272
2273 EXPECT_GL_NO_ERROR();
2274
2275 drawQuad(mProgram, "position", 0.5f);
2276
2277 // Texture should be incomplete.
2278 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2279}
2280
2281// Test that immutable texture base level and max level are clamped.
2282// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2283TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2284{
Olli Etuahoa314b612016-03-10 16:43:00 +02002285 glActiveTexture(GL_TEXTURE0);
2286 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2287
2288 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2289 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2290
2291 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2292
2293 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2294
2295 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2296 // should be clamped to [base_level, levels - 1].
2297 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2298 // In the case of this test, those rules make the effective base level and max level 0.
2299 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2300 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2301
2302 EXPECT_GL_NO_ERROR();
2303
2304 drawQuad(mProgram, "position", 0.5f);
2305
2306 // Texture should be complete.
2307 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2308}
2309
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002310// Test that changing base level works when it affects the format of the texture.
2311TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2312{
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002313 if (IsNVIDIA() && IsOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002314 {
2315 // Observed rendering corruption on NVIDIA OpenGL.
2316 std::cout << "Test skipped on NVIDIA OpenGL." << std::endl;
2317 return;
2318 }
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002319 if (IsIntel() && IsDesktopOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002320 {
2321 // Observed incorrect rendering on Intel OpenGL.
2322 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2323 return;
2324 }
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002325 if (IsAMD() && IsDesktopOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002326 {
2327 // Observed incorrect rendering on AMD OpenGL.
2328 std::cout << "Test skipped on AMD OpenGL." << std::endl;
2329 return;
2330 }
2331
2332 glActiveTexture(GL_TEXTURE0);
2333 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2334 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2335 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2336
2337 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2338 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2339
2340 // RGBA8 level that's initially unused.
2341 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2342 texDataCyan.data());
2343
2344 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2345 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2346
2347 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2348 // format. It reads green channel data from the green and alpha channels of texDataGreen
2349 // (this is a bit hacky but works).
2350 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2351
2352 EXPECT_GL_NO_ERROR();
2353
2354 drawQuad(mProgram, "position", 0.5f);
2355
2356 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2357
2358 // Switch the texture to use the cyan level 0 with the RGBA format.
2359 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2360 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2361
2362 EXPECT_GL_NO_ERROR();
2363
2364 drawQuad(mProgram, "position", 0.5f);
2365
2366 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2367}
2368
Olli Etuahoa314b612016-03-10 16:43:00 +02002369// Test that setting a texture image works when base level is out of range.
2370TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2371{
2372 glActiveTexture(GL_TEXTURE0);
2373 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2374
2375 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2376 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2377
2378 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2379 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2380
2381 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2382
2383 EXPECT_GL_NO_ERROR();
2384
2385 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2386
2387 drawQuad(mProgram, "position", 0.5f);
2388
2389 // Texture should be complete.
2390 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002391}
2392
Jamie Madill2453dbc2015-07-14 11:35:42 -04002393// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG RBA->RGBA8, with 1.0
2394// in the alpha channel. This test covers a bug where redefining array textures with these formats does not work as
2395// expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002396TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002397{
2398 std::vector<GLubyte> pixelData;
2399 for (size_t count = 0; count < 5000; count++)
2400 {
2401 pixelData.push_back(0u);
2402 pixelData.push_back(255u);
2403 pixelData.push_back(0u);
2404 }
2405
2406 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002407 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002408 glUniform1i(mTextureArrayLocation, 0);
2409
2410 // The first draw worked correctly.
2411 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
2412
2413 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2414 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2415 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2416 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002417 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002418 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002419
2420 // The dimension of the respecification must match the original exactly to trigger the bug.
2421 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002422 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002423 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002424
2425 ASSERT_GL_NO_ERROR();
2426}
2427
Olli Etuaho1a679902016-01-14 12:21:47 +02002428// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2429// This test is needed especially to confirm that sampler registers get assigned correctly on
2430// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2431TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2432{
2433 glActiveTexture(GL_TEXTURE0);
2434 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2435 GLubyte texData[4];
2436 texData[0] = 0;
2437 texData[1] = 60;
2438 texData[2] = 0;
2439 texData[3] = 255;
2440 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2441
2442 glActiveTexture(GL_TEXTURE1);
2443 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2444 GLfloat depthTexData[1];
2445 depthTexData[0] = 0.5f;
2446 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2447 depthTexData);
2448
2449 glUseProgram(mProgram);
2450 glUniform1f(mDepthRefUniformLocation, 0.3f);
2451 glUniform1i(mTexture3DUniformLocation, 0);
2452 glUniform1i(mTextureShadowUniformLocation, 1);
2453
2454 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2455 drawQuad(mProgram, "position", 0.5f);
2456 EXPECT_GL_NO_ERROR();
2457 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2458 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2459
2460 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2461 drawQuad(mProgram, "position", 0.5f);
2462 EXPECT_GL_NO_ERROR();
2463 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2464 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2465}
2466
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002467// Test multiple different sampler types in the same shader.
2468// This test makes sure that even if sampler / texture registers get grouped together based on type
2469// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2470// still has the right register index information for each ESSL sampler.
2471// The tested ESSL samplers have the following types in D3D11 HLSL:
2472// sampler2D: Texture2D + SamplerState
2473// samplerCube: TextureCube + SamplerState
2474// sampler2DShadow: Texture2D + SamplerComparisonState
2475// samplerCubeShadow: TextureCube + SamplerComparisonState
2476TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2477{
2478 glActiveTexture(GL_TEXTURE0);
2479 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2480 GLubyte texData[4];
2481 texData[0] = 0;
2482 texData[1] = 0;
2483 texData[2] = 120;
2484 texData[3] = 255;
2485 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2486
2487 glActiveTexture(GL_TEXTURE1);
2488 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2489 texData[0] = 0;
2490 texData[1] = 90;
2491 texData[2] = 0;
2492 texData[3] = 255;
2493 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2494 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2495 texData);
2496
2497 glActiveTexture(GL_TEXTURE2);
2498 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2499 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2500 GLfloat depthTexData[1];
2501 depthTexData[0] = 0.5f;
2502 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2503 depthTexData);
2504
2505 glActiveTexture(GL_TEXTURE3);
2506 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2507 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2508 depthTexData[0] = 0.2f;
2509 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2510 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2511 depthTexData);
2512
2513 EXPECT_GL_NO_ERROR();
2514
2515 glUseProgram(mProgram);
2516 glUniform1f(mDepthRefUniformLocation, 0.3f);
2517 glUniform1i(mTexture2DUniformLocation, 0);
2518 glUniform1i(mTextureCubeUniformLocation, 1);
2519 glUniform1i(mTexture2DShadowUniformLocation, 2);
2520 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2521
2522 drawQuad(mProgram, "position", 0.5f);
2523 EXPECT_GL_NO_ERROR();
2524 // The shader writes:
2525 // <texture 2d color> +
2526 // <cube map color> +
2527 // 0.25 * <comparison result (1.0)> +
2528 // 0.125 * <comparison result (0.0)>
2529 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2530}
2531
Olli Etuahobce743a2016-01-15 17:18:28 +02002532// Test different base levels on textures accessed through the same sampler array.
2533// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2534TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2535{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002536 if ((IsAMD() || IsIntel()) && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
Olli Etuahobce743a2016-01-15 17:18:28 +02002537 {
2538 std::cout << "Test skipped on Intel and AMD D3D." << std::endl;
2539 return;
2540 }
2541 glActiveTexture(GL_TEXTURE0);
2542 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2543 GLsizei size = 64;
2544 for (GLint level = 0; level < 7; ++level)
2545 {
2546 ASSERT_LT(0, size);
2547 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2548 nullptr);
2549 size = size / 2;
2550 }
2551 ASSERT_EQ(0, size);
2552 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2553
2554 glActiveTexture(GL_TEXTURE1);
2555 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2556 size = 128;
2557 for (GLint level = 0; level < 8; ++level)
2558 {
2559 ASSERT_LT(0, size);
2560 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2561 nullptr);
2562 size = size / 2;
2563 }
2564 ASSERT_EQ(0, size);
2565 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2566 EXPECT_GL_NO_ERROR();
2567
2568 glUseProgram(mProgram);
2569 glUniform1i(mTexture0Location, 0);
2570 glUniform1i(mTexture1Location, 1);
2571
2572 drawQuad(mProgram, "position", 0.5f);
2573 EXPECT_GL_NO_ERROR();
2574 // Red channel: width of level 1 of texture A: 32.
2575 // Green channel: width of level 3 of texture B: 16.
2576 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2577}
2578
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002579// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2580// ES 3.0.4 table 3.24
2581TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2582{
2583 glActiveTexture(GL_TEXTURE0);
2584 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2585 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2586 EXPECT_GL_NO_ERROR();
2587
2588 drawQuad(mProgram, "position", 0.5f);
2589
2590 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2591}
2592
2593// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2594// ES 3.0.4 table 3.24
2595TEST_P(Texture2DTestES3, TextureLuminanceImplicitAlpha1)
2596{
2597 glActiveTexture(GL_TEXTURE0);
2598 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2599 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2600 EXPECT_GL_NO_ERROR();
2601
2602 drawQuad(mProgram, "position", 0.5f);
2603
2604 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2605}
2606
2607// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2608// ES 3.0.4 table 3.24
2609TEST_P(Texture2DTestES3, TextureLuminance32ImplicitAlpha1)
2610{
2611 if (extensionEnabled("GL_OES_texture_float"))
2612 {
2613 glActiveTexture(GL_TEXTURE0);
2614 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2615 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2616 EXPECT_GL_NO_ERROR();
2617
2618 drawQuad(mProgram, "position", 0.5f);
2619
2620 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2621 }
2622}
2623
2624// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2625// ES 3.0.4 table 3.24
2626TEST_P(Texture2DTestES3, TextureLuminance16ImplicitAlpha1)
2627{
2628 if (extensionEnabled("GL_OES_texture_half_float"))
2629 {
Yuly Novikovafcec832016-06-21 22:19:51 -04002630 if (IsNVIDIA() && IsOpenGLES())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002631 {
2632 std::cout << "Test skipped on NVIDIA" << std::endl;
2633 return;
2634 }
Yuly Novikovafcec832016-06-21 22:19:51 -04002635 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2636 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2637 {
2638 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2639 return;
2640 }
2641
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002642 glActiveTexture(GL_TEXTURE0);
2643 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2644 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES,
2645 nullptr);
2646 EXPECT_GL_NO_ERROR();
2647
2648 drawQuad(mProgram, "position", 0.5f);
2649
2650 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2651 }
2652}
2653
2654// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2655// ES 3.0.4 table 3.24
2656TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2657{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002658 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002659 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002660 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002661 return;
2662 }
2663 glActiveTexture(GL_TEXTURE0);
2664 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2665 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2666 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2667 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2668 EXPECT_GL_NO_ERROR();
2669
2670 drawQuad(mProgram, "position", 0.5f);
2671
2672 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2673}
2674
2675// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2676// ES 3.0.4 table 3.24
2677TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2678{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002679 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002680 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002681 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002682 return;
2683 }
2684 glActiveTexture(GL_TEXTURE0);
2685 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2686
2687 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2688 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2689 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2690 EXPECT_GL_NO_ERROR();
2691
2692 drawQuad(mProgram, "position", 0.5f);
2693
2694 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2695}
2696
2697// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2698// ES 3.0.4 table 3.24
2699TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2700{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002701 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002702 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002703 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002704 return;
2705 }
2706 glActiveTexture(GL_TEXTURE0);
2707 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2708 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2709 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2710 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2711 EXPECT_GL_NO_ERROR();
2712
2713 drawQuad(mProgram, "position", 0.5f);
2714
2715 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2716}
2717
2718// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2719// ES 3.0.4 table 3.24
2720TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2721{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002722 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002723 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002724 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002725 return;
2726 }
2727 glActiveTexture(GL_TEXTURE0);
2728 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2729 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2730 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2731 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2732 EXPECT_GL_NO_ERROR();
2733
2734 drawQuad(mProgram, "position", 0.5f);
2735
2736 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2737}
2738
2739// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2740// ES 3.0.4 table 3.24
2741TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2742{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002743 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002744 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002745 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002746 return;
2747 }
2748 glActiveTexture(GL_TEXTURE0);
2749 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2750 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2751 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2752 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2753 EXPECT_GL_NO_ERROR();
2754
2755 drawQuad(mProgram, "position", 0.5f);
2756
2757 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2758}
2759
2760// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2761// ES 3.0.4 table 3.24
2762TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2763{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002764 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002765 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002766 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002767 return;
2768 }
2769 glActiveTexture(GL_TEXTURE0);
2770 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2771 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2772 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2773 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2774 EXPECT_GL_NO_ERROR();
2775
2776 drawQuad(mProgram, "position", 0.5f);
2777
2778 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2779}
2780
2781// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2782// ES 3.0.4 table 3.24
2783TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2784{
2785 glActiveTexture(GL_TEXTURE0);
2786 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2787 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2788 EXPECT_GL_NO_ERROR();
2789
2790 drawQuad(mProgram, "position", 0.5f);
2791
2792 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2793}
2794
2795// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2796// ES 3.0.4 table 3.24
2797TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2798{
2799 glActiveTexture(GL_TEXTURE0);
2800 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2801 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2802 nullptr);
2803 EXPECT_GL_NO_ERROR();
2804
2805 drawQuad(mProgram, "position", 0.5f);
2806
2807 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2808}
2809
2810// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2811// ES 3.0.4 table 3.24
2812TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2813{
Jamie Madillbb1db482017-01-10 10:48:32 -05002814 if (IsOSX() && IsIntel() && IsOpenGL())
2815 {
2816 // Seems to fail on OSX 10.12 Intel.
2817 std::cout << "Test skipped on OSX Intel." << std::endl;
2818 return;
2819 }
2820
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002821 glActiveTexture(GL_TEXTURE0);
2822 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2823 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2824 EXPECT_GL_NO_ERROR();
2825
2826 drawQuad(mProgram, "position", 0.5f);
2827
2828 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2829}
2830
2831// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2832// ES 3.0.4 table 3.24
2833TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2834{
Jamie Madillbb1db482017-01-10 10:48:32 -05002835 if (IsIntel() && IsOpenGL() && (IsLinux() || IsOSX()))
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002836 {
2837 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
Jamie Madillbb1db482017-01-10 10:48:32 -05002838 // Also seems to fail on OSX 10.12 Intel.
2839 std::cout << "Test disabled on Linux and OSX Intel OpenGL." << std::endl;
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002840 return;
2841 }
2842
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002843 glActiveTexture(GL_TEXTURE0);
2844 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2845 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2846 EXPECT_GL_NO_ERROR();
2847
2848 drawQuad(mProgram, "position", 0.5f);
2849
2850 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2851}
2852
Olli Etuaho96963162016-03-21 11:54:33 +02002853// Use a sampler in a uniform struct.
2854TEST_P(SamplerInStructTest, SamplerInStruct)
2855{
2856 runSamplerInStructTest();
2857}
2858
2859// Use a sampler in a uniform struct that's passed as a function parameter.
2860TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2861{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002862 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2863 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2864 {
2865 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2866 return;
2867 }
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002868
2869 if (IsWindows() && IsIntel() && IsOpenGL())
2870 {
2871 std::cout << "Test skipped on Windows OpenGL on Intel." << std::endl;
2872 return;
2873 }
2874
Olli Etuaho96963162016-03-21 11:54:33 +02002875 runSamplerInStructTest();
2876}
2877
2878// Use a sampler in a uniform struct array with a struct from the array passed as a function
2879// parameter.
2880TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2881{
Olli Etuahoa1c917f2016-04-06 13:50:03 +03002882 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2883 {
2884 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2885 return;
2886 }
Yuly Novikovad6c0452016-06-24 22:24:37 -04002887 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2888 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2889 {
2890 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2891 return;
2892 }
Olli Etuaho96963162016-03-21 11:54:33 +02002893 runSamplerInStructTest();
2894}
2895
2896// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2897// parameter.
2898TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2899{
Olli Etuahoa1c917f2016-04-06 13:50:03 +03002900 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2901 {
2902 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2903 return;
2904 }
Yuly Novikovad6c0452016-06-24 22:24:37 -04002905 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2906 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2907 {
2908 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2909 return;
2910 }
Olli Etuaho96963162016-03-21 11:54:33 +02002911 runSamplerInStructTest();
2912}
2913
2914// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2915// similarly named uniform.
2916TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2917{
2918 runSamplerInStructTest();
2919}
2920
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002921class TextureLimitsTest : public ANGLETest
2922{
2923 protected:
2924 struct RGBA8
2925 {
2926 uint8_t R, G, B, A;
2927 };
2928
2929 TextureLimitsTest()
2930 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
2931 {
2932 setWindowWidth(128);
2933 setWindowHeight(128);
2934 setConfigRedBits(8);
2935 setConfigGreenBits(8);
2936 setConfigBlueBits(8);
2937 setConfigAlphaBits(8);
2938 }
2939
2940 ~TextureLimitsTest()
2941 {
2942 if (mProgram != 0)
2943 {
2944 glDeleteProgram(mProgram);
2945 mProgram = 0;
2946
2947 if (!mTextures.empty())
2948 {
2949 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
2950 }
2951 }
2952 }
2953
2954 void SetUp() override
2955 {
2956 ANGLETest::SetUp();
2957
2958 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
2959 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
2960 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
2961
2962 ASSERT_GL_NO_ERROR();
2963 }
2964
2965 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
2966 GLint vertexTextureCount,
2967 GLint vertexActiveTextureCount,
2968 const std::string &fragPrefix,
2969 GLint fragmentTextureCount,
2970 GLint fragmentActiveTextureCount)
2971 {
2972 std::stringstream vertexShaderStr;
2973 vertexShaderStr << "attribute vec2 position;\n"
2974 << "varying vec4 color;\n"
2975 << "varying vec2 texCoord;\n";
2976
2977 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
2978 {
2979 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
2980 }
2981
2982 vertexShaderStr << "void main() {\n"
2983 << " gl_Position = vec4(position, 0, 1);\n"
2984 << " texCoord = (position * 0.5) + 0.5;\n"
2985 << " color = vec4(0);\n";
2986
2987 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
2988 {
2989 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
2990 << ", texCoord);\n";
2991 }
2992
2993 vertexShaderStr << "}";
2994
2995 std::stringstream fragmentShaderStr;
2996 fragmentShaderStr << "varying mediump vec4 color;\n"
2997 << "varying mediump vec2 texCoord;\n";
2998
2999 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
3000 {
3001 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
3002 }
3003
3004 fragmentShaderStr << "void main() {\n"
3005 << " gl_FragColor = color;\n";
3006
3007 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
3008 {
3009 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
3010 << ", texCoord);\n";
3011 }
3012
3013 fragmentShaderStr << "}";
3014
3015 const std::string &vertexShaderSource = vertexShaderStr.str();
3016 const std::string &fragmentShaderSource = fragmentShaderStr.str();
3017
3018 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
3019 }
3020
3021 RGBA8 getPixel(GLint texIndex)
3022 {
3023 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3024 0, 255u};
3025 return pixel;
3026 }
3027
3028 void initTextures(GLint tex2DCount, GLint texCubeCount)
3029 {
3030 GLint totalCount = tex2DCount + texCubeCount;
3031 mTextures.assign(totalCount, 0);
3032 glGenTextures(totalCount, &mTextures[0]);
3033 ASSERT_GL_NO_ERROR();
3034
3035 std::vector<RGBA8> texData(16 * 16);
3036
3037 GLint texIndex = 0;
3038 for (; texIndex < tex2DCount; ++texIndex)
3039 {
3040 texData.assign(texData.size(), getPixel(texIndex));
3041 glActiveTexture(GL_TEXTURE0 + texIndex);
3042 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3043 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3044 &texData[0]);
3045 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3046 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3047 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3048 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3049 }
3050
3051 ASSERT_GL_NO_ERROR();
3052
3053 for (; texIndex < texCubeCount; ++texIndex)
3054 {
3055 texData.assign(texData.size(), getPixel(texIndex));
3056 glActiveTexture(GL_TEXTURE0 + texIndex);
3057 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3058 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3059 GL_UNSIGNED_BYTE, &texData[0]);
3060 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3061 GL_UNSIGNED_BYTE, &texData[0]);
3062 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3063 GL_UNSIGNED_BYTE, &texData[0]);
3064 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3065 GL_UNSIGNED_BYTE, &texData[0]);
3066 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3067 GL_UNSIGNED_BYTE, &texData[0]);
3068 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3069 GL_UNSIGNED_BYTE, &texData[0]);
3070 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3071 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3072 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3073 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3074 }
3075
3076 ASSERT_GL_NO_ERROR();
3077 }
3078
3079 void testWithTextures(GLint vertexTextureCount,
3080 const std::string &vertexTexturePrefix,
3081 GLint fragmentTextureCount,
3082 const std::string &fragmentTexturePrefix)
3083 {
3084 // Generate textures
3085 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3086
3087 glUseProgram(mProgram);
3088 RGBA8 expectedSum = {0};
3089 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3090 {
3091 std::stringstream uniformNameStr;
3092 uniformNameStr << vertexTexturePrefix << texIndex;
3093 const std::string &uniformName = uniformNameStr.str();
3094 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
3095 ASSERT_NE(-1, location);
3096
3097 glUniform1i(location, texIndex);
3098 RGBA8 contribution = getPixel(texIndex);
3099 expectedSum.R += contribution.R;
3100 expectedSum.G += contribution.G;
3101 }
3102
3103 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3104 {
3105 std::stringstream uniformNameStr;
3106 uniformNameStr << fragmentTexturePrefix << texIndex;
3107 const std::string &uniformName = uniformNameStr.str();
3108 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
3109 ASSERT_NE(-1, location);
3110
3111 glUniform1i(location, texIndex + vertexTextureCount);
3112 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3113 expectedSum.R += contribution.R;
3114 expectedSum.G += contribution.G;
3115 }
3116
3117 ASSERT_GE(256u, expectedSum.G);
3118
3119 drawQuad(mProgram, "position", 0.5f);
3120 ASSERT_GL_NO_ERROR();
3121 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3122 }
3123
3124 GLuint mProgram;
3125 std::vector<GLuint> mTextures;
3126 GLint mMaxVertexTextures;
3127 GLint mMaxFragmentTextures;
3128 GLint mMaxCombinedTextures;
3129};
3130
3131// Test rendering with the maximum vertex texture units.
3132TEST_P(TextureLimitsTest, MaxVertexTextures)
3133{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003134 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003135 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003136 {
3137 std::cout << "Test skipped on Intel." << std::endl;
3138 return;
3139 }
3140
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003141 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3142 ASSERT_NE(0u, mProgram);
3143 ASSERT_GL_NO_ERROR();
3144
3145 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3146}
3147
3148// Test rendering with the maximum fragment texture units.
3149TEST_P(TextureLimitsTest, MaxFragmentTextures)
3150{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003151 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003152 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003153 {
3154 std::cout << "Test skipped on Intel." << std::endl;
3155 return;
3156 }
3157
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003158 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3159 ASSERT_NE(0u, mProgram);
3160 ASSERT_GL_NO_ERROR();
3161
3162 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3163}
3164
3165// Test rendering with maximum combined texture units.
3166TEST_P(TextureLimitsTest, MaxCombinedTextures)
3167{
Jamie Madill412f17d2015-09-25 08:43:54 -04003168 // TODO(jmadill): Investigate workaround.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003169 if (IsIntel() && GetParam() == ES2_OPENGL())
Jamie Madill412f17d2015-09-25 08:43:54 -04003170 {
3171 std::cout << "Test skipped on Intel." << std::endl;
3172 return;
3173 }
3174
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003175 GLint vertexTextures = mMaxVertexTextures;
3176
3177 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3178 {
3179 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3180 }
3181
3182 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3183 mMaxFragmentTextures, mMaxFragmentTextures);
3184 ASSERT_NE(0u, mProgram);
3185 ASSERT_GL_NO_ERROR();
3186
3187 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3188}
3189
3190// Negative test for exceeding the number of vertex textures
3191TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3192{
3193 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3194 0);
3195 ASSERT_EQ(0u, mProgram);
3196}
3197
3198// Negative test for exceeding the number of fragment textures
3199TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3200{
3201 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3202 mMaxFragmentTextures + 1);
3203 ASSERT_EQ(0u, mProgram);
3204}
3205
3206// Test active vertex textures under the limit, but excessive textures specified.
3207TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3208{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003209 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003210 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003211 {
3212 std::cout << "Test skipped on Intel." << std::endl;
3213 return;
3214 }
3215
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003216 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3217 ASSERT_NE(0u, mProgram);
3218 ASSERT_GL_NO_ERROR();
3219
3220 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3221}
3222
3223// Test active fragment textures under the limit, but excessive textures specified.
3224TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3225{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003226 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003227 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003228 {
3229 std::cout << "Test skipped on Intel." << std::endl;
3230 return;
3231 }
3232
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003233 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3234 mMaxFragmentTextures);
3235 ASSERT_NE(0u, mProgram);
3236 ASSERT_GL_NO_ERROR();
3237
3238 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3239}
3240
3241// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003242// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003243TEST_P(TextureLimitsTest, TextureTypeConflict)
3244{
3245 const std::string &vertexShader =
3246 "attribute vec2 position;\n"
3247 "varying float color;\n"
3248 "uniform sampler2D tex2D;\n"
3249 "uniform samplerCube texCube;\n"
3250 "void main() {\n"
3251 " gl_Position = vec4(position, 0, 1);\n"
3252 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3253 " color = texture2D(tex2D, texCoord).x;\n"
3254 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3255 "}";
3256 const std::string &fragmentShader =
3257 "varying mediump float color;\n"
3258 "void main() {\n"
3259 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3260 "}";
3261
3262 mProgram = CompileProgram(vertexShader, fragmentShader);
3263 ASSERT_NE(0u, mProgram);
3264
3265 initTextures(1, 0);
3266
3267 glUseProgram(mProgram);
3268 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3269 ASSERT_NE(-1, tex2DLocation);
3270 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3271 ASSERT_NE(-1, texCubeLocation);
3272
3273 glUniform1i(tex2DLocation, 0);
3274 glUniform1i(texCubeLocation, 0);
3275 ASSERT_GL_NO_ERROR();
3276
3277 drawQuad(mProgram, "position", 0.5f);
3278 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3279}
3280
Vincent Lang25ab4512016-05-13 18:13:59 +02003281class Texture2DNorm16TestES3 : public Texture2DTestES3
3282{
3283 protected:
3284 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3285
3286 void SetUp() override
3287 {
3288 Texture2DTestES3::SetUp();
3289
3290 glActiveTexture(GL_TEXTURE0);
3291 glGenTextures(3, mTextures);
3292 glGenFramebuffers(1, &mFBO);
3293 glGenRenderbuffers(1, &mRenderbuffer);
3294
3295 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3296 {
3297 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3298 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3299 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3300 }
3301
3302 glBindTexture(GL_TEXTURE_2D, 0);
3303
3304 ASSERT_GL_NO_ERROR();
3305 }
3306
3307 void TearDown() override
3308 {
3309 glDeleteTextures(3, mTextures);
3310 glDeleteFramebuffers(1, &mFBO);
3311 glDeleteRenderbuffers(1, &mRenderbuffer);
3312
3313 Texture2DTestES3::TearDown();
3314 }
3315
3316 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3317 {
Geoff Langf607c602016-09-21 11:46:48 -04003318 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3319 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003320
3321 setUpProgram();
3322
3323 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3324 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3325 0);
3326
3327 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3328 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3329
3330 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003331 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003332
3333 EXPECT_GL_NO_ERROR();
3334
3335 drawQuad(mProgram, "position", 0.5f);
3336
Geoff Langf607c602016-09-21 11:46:48 -04003337 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003338
Geoff Langf607c602016-09-21 11:46:48 -04003339 EXPECT_PIXEL_COLOR_EQ(
3340 0, 0, SliceFormatColor(
3341 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003342
3343 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3344
3345 ASSERT_GL_NO_ERROR();
3346 }
3347
3348 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3349 {
3350 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003351 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003352
3353 setUpProgram();
3354
3355 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3356 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3357
3358 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3359 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3360 0);
3361
3362 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003363 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003364
3365 EXPECT_GL_NO_ERROR();
3366
3367 drawQuad(mProgram, "position", 0.5f);
3368
Geoff Langf607c602016-09-21 11:46:48 -04003369 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
3370 EXPECT_PIXEL_COLOR_EQ(
3371 0, 0, SliceFormatColor(
3372 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003373
3374 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3375 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3376 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3377 mRenderbuffer);
3378 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3379 EXPECT_GL_NO_ERROR();
3380
3381 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3382 glClear(GL_COLOR_BUFFER_BIT);
3383
3384 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3385
Geoff Langf607c602016-09-21 11:46:48 -04003386 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003387
3388 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3389
3390 ASSERT_GL_NO_ERROR();
3391 }
3392
3393 GLuint mTextures[3];
3394 GLuint mFBO;
3395 GLuint mRenderbuffer;
3396};
3397
3398// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3399TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3400{
3401 if (!extensionEnabled("GL_EXT_texture_norm16"))
3402 {
3403 std::cout << "Test skipped due to missing GL_EXT_texture_norm16." << std::endl;
3404 return;
3405 }
3406
3407 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3408 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3409 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3410 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3411 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3412 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3413 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3414 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3415
3416 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3417 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3418 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3419}
3420
Olli Etuaho95faa232016-06-07 14:01:53 -07003421// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3422// GLES 3.0.4 section 3.8.3.
3423TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3424{
Corentin Wallezc7f59d02016-06-20 10:12:08 -04003425 if (IsIntel() && IsDesktopOpenGL())
Olli Etuaho95faa232016-06-07 14:01:53 -07003426 {
3427 std::cout << "Test skipped on Intel OpenGL." << std::endl;
3428 return;
3429 }
Yuly Novikov3c754192016-06-27 19:36:41 -04003430 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1429 is fixed
3431 if (IsAndroid() && IsAdreno() && IsOpenGLES())
3432 {
3433 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
3434 return;
3435 }
Olli Etuaho95faa232016-06-07 14:01:53 -07003436
3437 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3438 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3439 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3440 ASSERT_GL_NO_ERROR();
3441
3442 // SKIP_IMAGES should not have an effect on uploading 2D textures
3443 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3444 ASSERT_GL_NO_ERROR();
3445
3446 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3447
3448 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3449 pixelsGreen.data());
3450 ASSERT_GL_NO_ERROR();
3451
3452 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3453 pixelsGreen.data());
3454 ASSERT_GL_NO_ERROR();
3455
3456 glUseProgram(mProgram);
3457 drawQuad(mProgram, "position", 0.5f);
3458 ASSERT_GL_NO_ERROR();
3459
3460 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3461}
3462
Olli Etuaho989cac32016-06-08 16:18:49 -07003463// Test that skip defined in unpack parameters is taken into account when determining whether
3464// unpacking source extends outside unpack buffer bounds.
3465TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3466{
3467 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3468 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3469 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3470 ASSERT_GL_NO_ERROR();
3471
3472 GLBuffer buf;
3473 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3474 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3475 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3476 GL_DYNAMIC_COPY);
3477 ASSERT_GL_NO_ERROR();
3478
3479 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3480 ASSERT_GL_NO_ERROR();
3481
3482 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3483 ASSERT_GL_NO_ERROR();
3484
3485 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3486 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3487
3488 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3489 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3490 ASSERT_GL_NO_ERROR();
3491
3492 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3493 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3494}
3495
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003496// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3497TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3498{
3499 if (IsD3D11())
3500 {
3501 std::cout << "Test skipped on D3D." << std::endl;
3502 return;
3503 }
3504 if (IsOSX() && IsAMD())
3505 {
3506 // Incorrect rendering results seen on OSX AMD.
3507 std::cout << "Test skipped on OSX AMD." << std::endl;
3508 return;
3509 }
3510
3511 const GLuint width = 8u;
3512 const GLuint height = 8u;
3513 const GLuint unpackRowLength = 5u;
3514 const GLuint unpackSkipPixels = 1u;
3515
3516 setWindowWidth(width);
3517 setWindowHeight(height);
3518
3519 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3520 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3521 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3522 ASSERT_GL_NO_ERROR();
3523
3524 GLBuffer buf;
3525 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3526 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3527 GLColor::green);
3528
3529 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3530 {
3531 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3532 }
3533
3534 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3535 GL_DYNAMIC_COPY);
3536 ASSERT_GL_NO_ERROR();
3537
3538 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3539 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3540 ASSERT_GL_NO_ERROR();
3541
3542 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3543 ASSERT_GL_NO_ERROR();
3544
3545 glUseProgram(mProgram);
3546 drawQuad(mProgram, "position", 0.5f);
3547 ASSERT_GL_NO_ERROR();
3548
3549 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3550 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3551 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3552 actual.data());
3553 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3554 EXPECT_EQ(expected, actual);
3555}
3556
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003557template <typename T>
3558T UNorm(double value)
3559{
3560 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3561}
3562
3563// Test rendering a depth texture with mipmaps.
3564TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3565{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003566 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3567 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
3568 // http://anglebugs.com/1706
3569 if (IsIntel() && IsWindows())
Corentin Walleze731d8a2016-09-07 10:56:25 -04003570 {
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003571 std::cout << "Test skipped on Win Intel." << std::endl;
Corentin Walleze731d8a2016-09-07 10:56:25 -04003572 return;
3573 }
3574
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003575 const int size = getWindowWidth();
3576
3577 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003578 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003579
3580 glActiveTexture(GL_TEXTURE0);
3581 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3582 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3583 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3584 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3585 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3586 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3587 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3588 ASSERT_GL_NO_ERROR();
3589
3590 glUseProgram(mProgram);
3591 glUniform1i(mTexture2DUniformLocation, 0);
3592
3593 std::vector<unsigned char> expected;
3594
3595 for (int level = 0; level < levels; ++level)
3596 {
3597 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3598 expected.push_back(UNorm<unsigned char>(value));
3599
3600 int levelDim = dim(level);
3601
3602 ASSERT_GT(levelDim, 0);
3603
3604 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3605 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3606 GL_UNSIGNED_INT, initData.data());
3607 }
3608 ASSERT_GL_NO_ERROR();
3609
3610 for (int level = 0; level < levels; ++level)
3611 {
3612 glViewport(0, 0, dim(level), dim(level));
3613 drawQuad(mProgram, "position", 0.5f);
3614 GLColor actual = ReadColor(0, 0);
3615 EXPECT_NEAR(expected[level], actual.R, 10u);
3616 }
3617
3618 ASSERT_GL_NO_ERROR();
3619}
3620
Jamie Madill7ffdda92016-09-08 13:26:51 -04003621// Tests unpacking into the unsized GL_ALPHA format.
3622TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3623{
3624 // TODO(jmadill): Figure out why this fails on OSX.
3625 ANGLE_SKIP_TEST_IF(IsOSX());
3626
3627 // Initialize the texure.
3628 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3629 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3630 GL_UNSIGNED_BYTE, nullptr);
3631 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3632 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3633
3634 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3635
3636 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04003637 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04003638 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3639 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3640 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
3641 GL_STATIC_DRAW);
3642
3643 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
3644 GL_UNSIGNED_BYTE, nullptr);
3645
3646 // Clear to a weird color to make sure we're drawing something.
3647 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
3648 glClear(GL_COLOR_BUFFER_BIT);
3649
3650 // Draw with the alpha texture and verify.
3651 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04003652
3653 ASSERT_GL_NO_ERROR();
3654 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
3655}
3656
Jamie Madill2e600342016-09-19 13:56:40 -04003657// Ensure stale unpack data doesn't propagate in D3D11.
3658TEST_P(Texture2DTestES3, StaleUnpackData)
3659{
3660 // Init unpack buffer.
3661 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
3662 std::vector<GLColor> pixels(pixelCount, GLColor::red);
3663
3664 GLBuffer unpackBuffer;
3665 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3666 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3667 GLsizei bufferSize = pixelCount * sizeof(GLColor);
3668 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
3669
3670 // Create from unpack buffer.
3671 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3672 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
3673 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3674 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3675 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3676
3677 drawQuad(mProgram, "position", 0.5f);
3678
3679 ASSERT_GL_NO_ERROR();
3680 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3681
3682 // Fill unpack with green, recreating buffer.
3683 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
3684 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
3685 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
3686
3687 // Reinit texture with green.
3688 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
3689 GL_UNSIGNED_BYTE, nullptr);
3690
3691 drawQuad(mProgram, "position", 0.5f);
3692
3693 ASSERT_GL_NO_ERROR();
3694 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3695}
3696
Jamie Madillf097e232016-11-05 00:44:15 -04003697// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
3698// being properly checked, and the texture storage of the previous texture format was persisting.
3699// This would result in an ASSERT in debug and incorrect rendering in release.
3700// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
3701TEST_P(Texture3DTestES3, FormatRedefinitionBug)
3702{
3703 GLTexture tex;
3704 glBindTexture(GL_TEXTURE_3D, tex.get());
3705 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3706
3707 GLFramebuffer framebuffer;
3708 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3709 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
3710
3711 glCheckFramebufferStatus(GL_FRAMEBUFFER);
3712
3713 std::vector<uint8_t> pixelData(100, 0);
3714
3715 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
3716 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
3717 pixelData.data());
3718
3719 ASSERT_GL_NO_ERROR();
3720}
3721
Corentin Wallezd2627992017-04-28 17:17:03 -04003722// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
3723TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
3724{
3725 // 2D tests
3726 {
3727 GLTexture tex;
3728 glBindTexture(GL_TEXTURE_2D, tex.get());
3729
3730 GLBuffer pbo;
3731 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3732
3733 // Test OOB
3734 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
3735 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3736 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3737
3738 // Test OOB
3739 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
3740 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3741 ASSERT_GL_NO_ERROR();
3742 }
3743
3744 // 3D tests
3745 {
3746 GLTexture tex;
3747 glBindTexture(GL_TEXTURE_3D, tex.get());
3748
3749 GLBuffer pbo;
3750 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3751
3752 // Test OOB
3753 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
3754 GL_STATIC_DRAW);
3755 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3756 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3757
3758 // Test OOB
3759 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
3760 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3761 ASSERT_GL_NO_ERROR();
3762 }
3763}
3764
Jamie Madill3ed60422017-09-07 11:32:52 -04003765// Tests behaviour with a single texture and multiple sampler objects.
3766TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
3767{
3768 GLint maxTextureUnits = 0;
3769 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
3770 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
3771
3772 constexpr int kSize = 16;
3773
3774 // Make a single-level texture, fill it with red.
3775 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
3776 GLTexture tex;
3777 glBindTexture(GL_TEXTURE_2D, tex);
3778 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3779 redColors.data());
3780 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3781 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3782
3783 // Simple sanity check.
3784 draw2DTexturedQuad(0.5f, 1.0f, true);
3785 ASSERT_GL_NO_ERROR();
3786 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3787
3788 // Bind texture to unit 1 with a sampler object making it incomplete.
3789 GLSampler sampler;
3790 glBindSampler(0, sampler);
3791 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3792 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3793
3794 // Make a mipmap texture, fill it with blue.
3795 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
3796 GLTexture mipmapTex;
3797 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3798 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3799 blueColors.data());
3800 glGenerateMipmap(GL_TEXTURE_2D);
3801
3802 // Draw with the sampler, expect blue.
3803 draw2DTexturedQuad(0.5f, 1.0f, true);
3804 ASSERT_GL_NO_ERROR();
3805 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
3806
3807 // Simple multitexturing program.
3808 const std::string vs =
3809 "#version 300 es\n"
3810 "in vec2 position;\n"
3811 "out vec2 texCoord;\n"
3812 "void main()\n"
3813 "{\n"
3814 " gl_Position = vec4(position, 0, 1);\n"
3815 " texCoord = position * 0.5 + vec2(0.5);\n"
3816 "}";
3817 const std::string fs =
3818 "#version 300 es\n"
3819 "precision mediump float;\n"
3820 "in vec2 texCoord;\n"
3821 "uniform sampler2D tex1;\n"
3822 "uniform sampler2D tex2;\n"
3823 "uniform sampler2D tex3;\n"
3824 "uniform sampler2D tex4;\n"
3825 "out vec4 color;\n"
3826 "void main()\n"
3827 "{\n"
3828 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
3829 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
3830 "}";
3831
3832 ANGLE_GL_PROGRAM(program, vs, fs);
3833
3834 std::array<GLint, 4> texLocations = {
3835 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
3836 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
3837 for (GLint location : texLocations)
3838 {
3839 ASSERT_NE(-1, location);
3840 }
3841
3842 // Init the uniform data.
3843 glUseProgram(program);
3844 for (GLint location = 0; location < 4; ++location)
3845 {
3846 glUniform1i(texLocations[location], location);
3847 }
3848
3849 // Initialize four samplers
3850 GLSampler samplers[4];
3851
3852 // 0: non-mipped.
3853 glBindSampler(0, samplers[0]);
3854 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3855 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3856
3857 // 1: mipped.
3858 glBindSampler(1, samplers[1]);
3859 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3860 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3861
3862 // 2: non-mipped.
3863 glBindSampler(2, samplers[2]);
3864 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3865 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3866
3867 // 3: mipped.
3868 glBindSampler(3, samplers[3]);
3869 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3870 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3871
3872 // Bind two blue mipped textures and two single layer textures, should all draw.
3873 glActiveTexture(GL_TEXTURE0);
3874 glBindTexture(GL_TEXTURE_2D, tex);
3875
3876 glActiveTexture(GL_TEXTURE1);
3877 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3878
3879 glActiveTexture(GL_TEXTURE2);
3880 glBindTexture(GL_TEXTURE_2D, tex);
3881
3882 glActiveTexture(GL_TEXTURE3);
3883 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3884
3885 ASSERT_GL_NO_ERROR();
3886
3887 drawQuad(program, "position", 0.5f);
3888 ASSERT_GL_NO_ERROR();
3889 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
3890
3891 // Bind four single layer textures, two should be incomplete.
3892 glActiveTexture(GL_TEXTURE1);
3893 glBindTexture(GL_TEXTURE_2D, tex);
3894
3895 glActiveTexture(GL_TEXTURE3);
3896 glBindTexture(GL_TEXTURE_2D, tex);
3897
3898 drawQuad(program, "position", 0.5f);
3899 ASSERT_GL_NO_ERROR();
3900 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
3901}
3902
Martin Radev7e2c0d32017-09-15 14:25:42 +03003903// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
3904// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
3905// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
3906// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
3907// samples the cubemap using a direction vector (1,1,1).
3908TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
3909{
3910 if (IsOSX())
3911 {
3912 // Check http://anglebug.com/2155.
3913 std::cout << "Test skipped on OSX." << std::endl;
3914 return;
3915 }
3916 const std::string vs =
3917 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003918 precision mediump float;
3919 in vec3 pos;
3920 void main() {
3921 gl_Position = vec4(pos, 1.0);
3922 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003923
3924 const std::string fs =
3925 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003926 precision mediump float;
3927 out vec4 color;
3928 uniform samplerCube uTex;
3929 void main(){
3930 color = texture(uTex, vec3(1.0));
3931 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003932 ANGLE_GL_PROGRAM(program, vs, fs);
3933 glUseProgram(program);
3934
3935 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
3936 glActiveTexture(GL_TEXTURE0);
3937
3938 GLTexture cubeTex;
3939 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
3940
3941 const int kFaceWidth = 1;
3942 const int kFaceHeight = 1;
3943 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
3944 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3945 GL_UNSIGNED_BYTE, texData.data());
3946 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3947 GL_UNSIGNED_BYTE, texData.data());
3948 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3949 GL_UNSIGNED_BYTE, texData.data());
3950 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3951 GL_UNSIGNED_BYTE, texData.data());
3952 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3953 GL_UNSIGNED_BYTE, texData.data());
3954 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3955 GL_UNSIGNED_BYTE, texData.data());
3956 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3957 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3958 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
3959 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
3960 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
3961 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
3962
3963 drawQuad(program, "pos", 0.5f, 1.0f, true);
3964 ASSERT_GL_NO_ERROR();
3965
3966 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
3967}
3968
Jamie Madillfa05f602015-05-07 13:47:11 -04003969// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003970// TODO(oetuaho): Enable all below tests on OpenGL. Requires a fix for ANGLE bug 1278.
Geoff Lange0cc2a42016-01-20 10:58:17 -05003971ANGLE_INSTANTIATE_TEST(Texture2DTest,
3972 ES2_D3D9(),
3973 ES2_D3D11(),
3974 ES2_D3D11_FL9_3(),
3975 ES2_OPENGL(),
3976 ES2_OPENGLES());
3977ANGLE_INSTANTIATE_TEST(TextureCubeTest,
3978 ES2_D3D9(),
3979 ES2_D3D11(),
3980 ES2_D3D11_FL9_3(),
3981 ES2_OPENGL(),
3982 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003983ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
3984 ES2_D3D9(),
3985 ES2_D3D11(),
3986 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003987 ES2_OPENGL(),
3988 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003989ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
3990 ES2_D3D9(),
3991 ES2_D3D11(),
3992 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003993 ES2_OPENGL(),
3994 ES2_OPENGLES());
3995ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
3996 ES2_D3D9(),
3997 ES2_D3D11(),
3998 ES2_D3D11_FL9_3(),
3999 ES2_OPENGL(),
4000 ES2_OPENGLES());
4001ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
4002 ES2_D3D9(),
4003 ES2_D3D11(),
4004 ES2_D3D11_FL9_3(),
4005 ES2_OPENGL(),
4006 ES2_OPENGLES());
4007ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02004008ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02004009ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4010ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
4011 ES3_D3D11(),
4012 ES3_OPENGL(),
4013 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004014ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
4015 ES3_D3D11(),
4016 ES3_OPENGL(),
4017 ES3_OPENGLES());
4018ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4019ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02004020ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02004021ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
4022 ES2_D3D11(),
4023 ES2_D3D11_FL9_3(),
4024 ES2_D3D9(),
4025 ES2_OPENGL(),
4026 ES2_OPENGLES());
4027ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
4028 ES2_D3D11(),
4029 ES2_D3D11_FL9_3(),
4030 ES2_D3D9(),
4031 ES2_OPENGL(),
4032 ES2_OPENGLES());
4033ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
4034 ES2_D3D11(),
4035 ES2_D3D11_FL9_3(),
4036 ES2_D3D9(),
4037 ES2_OPENGL(),
4038 ES2_OPENGLES());
4039ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
4040 ES2_D3D11(),
4041 ES2_D3D11_FL9_3(),
4042 ES2_D3D9(),
4043 ES2_OPENGL(),
4044 ES2_OPENGLES());
4045ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
4046 ES2_D3D11(),
4047 ES2_D3D11_FL9_3(),
4048 ES2_D3D9(),
4049 ES2_OPENGL(),
4050 ES2_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004051ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES());
Vincent Lang25ab4512016-05-13 18:13:59 +02004052ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03004053ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04004054
Jamie Madill7ffdda92016-09-08 13:26:51 -04004055} // anonymous namespace