blob: c2434dc383cb12299084c78b3f191f93a32d5a11 [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 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300177 setUpProgram();
178
Martin Radev1be913c2016-07-11 17:59:16 +0300179 if (getClientMajorVersion() < 3)
Geoff Langfbfa47c2015-03-31 11:26:00 -0400180 {
Geoff Langc4e93662017-05-01 10:45:59 -0400181 if (!extensionEnabled("GL_EXT_texture_storage"))
182 {
183 std::cout << "Test skipped due to missing GL_EXT_texture_storage." << std::endl;
184 return;
185 }
186
Geoff Langfbfa47c2015-03-31 11:26:00 -0400187 if (!extensionEnabled("GL_OES_texture_float"))
188 {
189 std::cout << "Test skipped due to missing GL_OES_texture_float." << std::endl;
190 return;
191 }
192
193 if ((sourceImageChannels < 3 || destImageChannels < 3) && !extensionEnabled("GL_EXT_texture_rg"))
194 {
195 std::cout << "Test skipped due to missing GL_EXT_texture_rg." << std::endl;
196 return;
197 }
Geoff Lang677bb6f2017-04-05 12:40:40 -0400198
199 if (destImageChannels == 3 && !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"))
200 {
201 std::cout << "Test skipped due to missing GL_CHROMIUM_color_buffer_float_rgb."
202 << std::endl;
203 return;
204 }
205
206 if (destImageChannels == 4 && !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba"))
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 <= 2)
214 {
215 std::cout << "Test skipped because no extensions grant renderability to 1 and 2 "
216 "channel floating point textures."
217 << std::endl;
218 return;
219 }
220 }
221 else
222 {
223 if (!extensionEnabled("GL_color_buffer_float"))
224 {
225 std::cout << "Test skipped due to missing GL_color_buffer_float." << std::endl;
226 return;
227 }
228
229 if (destImageChannels == 3 && !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"))
230 {
231 std::cout << "Test skipped due to missing GL_CHROMIUM_color_buffer_float_rgb."
232 << std::endl;
233 return;
234 }
Geoff Langfbfa47c2015-03-31 11:26:00 -0400235 }
236
Jamie Madillbc393df2015-01-29 13:46:07 -0500237 GLfloat sourceImageData[4][16] =
238 {
239 { // R
240 1.0f,
241 0.0f,
242 0.0f,
243 1.0f
244 },
245 { // RG
246 1.0f, 0.0f,
247 0.0f, 1.0f,
248 0.0f, 0.0f,
249 1.0f, 1.0f
250 },
251 { // RGB
252 1.0f, 0.0f, 0.0f,
253 0.0f, 1.0f, 0.0f,
254 0.0f, 0.0f, 1.0f,
255 1.0f, 1.0f, 0.0f
256 },
257 { // RGBA
258 1.0f, 0.0f, 0.0f, 1.0f,
259 0.0f, 1.0f, 0.0f, 1.0f,
260 0.0f, 0.0f, 1.0f, 1.0f,
261 1.0f, 1.0f, 0.0f, 1.0f
262 },
263 };
264
265 GLenum imageFormats[] =
266 {
267 GL_R32F,
268 GL_RG32F,
269 GL_RGB32F,
270 GL_RGBA32F,
271 };
272
273 GLenum sourceUnsizedFormats[] =
274 {
275 GL_RED,
276 GL_RG,
277 GL_RGB,
278 GL_RGBA,
279 };
280
281 GLuint textures[2];
282
283 glGenTextures(2, textures);
284
285 GLfloat *imageData = sourceImageData[sourceImageChannels - 1];
286 GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1];
287 GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1];
288 GLenum destImageFormat = imageFormats[destImageChannels - 1];
289
290 glBindTexture(GL_TEXTURE_2D, textures[0]);
Geoff Langc4e93662017-05-01 10:45:59 -0400291 if (getClientMajorVersion() >= 3)
292 {
293 glTexStorage2D(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
294 }
295 else
296 {
297 glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
298 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500299 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
300 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
301 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData);
302
hendrikwb27f79a2015-03-04 11:26:46 -0800303 if (sourceImageChannels < 3 && !extensionEnabled("GL_EXT_texture_rg"))
Jamie Madillbc393df2015-01-29 13:46:07 -0500304 {
305 // This is not supported
306 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
307 }
308 else
309 {
310 ASSERT_GL_NO_ERROR();
311 }
312
313 GLuint fbo;
314 glGenFramebuffers(1, &fbo);
315 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
316 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
317
318 glBindTexture(GL_TEXTURE_2D, textures[1]);
Geoff Langc4e93662017-05-01 10:45:59 -0400319 if (getClientMajorVersion() >= 3)
320 {
321 glTexStorage2D(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
322 }
323 else
324 {
325 glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
326 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500327 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
328 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
329
330 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
331 ASSERT_GL_NO_ERROR();
332
333 glBindFramebuffer(GL_FRAMEBUFFER, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200334 drawQuad(mProgram, "position", 0.5f);
Jamie Madillbc393df2015-01-29 13:46:07 -0500335
336 int testImageChannels = std::min(sourceImageChannels, destImageChannels);
337
Olli Etuahoa314b612016-03-10 16:43:00 +0200338 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Jamie Madillbc393df2015-01-29 13:46:07 -0500339 if (testImageChannels > 1)
340 {
341 EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255);
342 EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255);
343 if (testImageChannels > 2)
344 {
345 EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255);
346 }
347 }
348
349 glDeleteFramebuffers(1, &fbo);
350 glDeleteTextures(2, textures);
351
352 ASSERT_GL_NO_ERROR();
353 }
354
Jamie Madilld4cfa572014-07-08 10:00:32 -0400355 GLuint mTexture2D;
Jamie Madilld4cfa572014-07-08 10:00:32 -0400356 GLint mTexture2DUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400357};
358
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200359class Texture2DTestES3 : public Texture2DTest
360{
361 protected:
362 Texture2DTestES3() : Texture2DTest() {}
363
364 std::string getVertexShaderSource() override
365 {
366 return std::string(
367 "#version 300 es\n"
368 "out vec2 texcoord;\n"
369 "in vec4 position;\n"
370 "void main()\n"
371 "{\n"
372 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
373 " texcoord = (position.xy * 0.5) + 0.5;\n"
374 "}\n");
375 }
376
377 std::string getFragmentShaderSource() override
378 {
379 return std::string(
380 "#version 300 es\n"
381 "precision highp float;\n"
382 "uniform highp sampler2D tex;\n"
383 "in vec2 texcoord;\n"
384 "out vec4 fragColor;\n"
385 "void main()\n"
386 "{\n"
387 " fragColor = texture(tex, texcoord);\n"
388 "}\n");
389 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300390
391 void SetUp() override
392 {
393 Texture2DTest::SetUp();
394 setUpProgram();
395 }
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200396};
397
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200398class Texture2DIntegerAlpha1TestES3 : public Texture2DTest
399{
400 protected:
401 Texture2DIntegerAlpha1TestES3() : Texture2DTest() {}
402
403 std::string getVertexShaderSource() override
404 {
405 return std::string(
406 "#version 300 es\n"
407 "out vec2 texcoord;\n"
408 "in vec4 position;\n"
409 "void main()\n"
410 "{\n"
411 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
412 " texcoord = (position.xy * 0.5) + 0.5;\n"
413 "}\n");
414 }
415
416 std::string getFragmentShaderSource() override
417 {
418 return std::string(
419 "#version 300 es\n"
420 "precision highp float;\n"
421 "uniform highp isampler2D tex;\n"
422 "in vec2 texcoord;\n"
423 "out vec4 fragColor;\n"
424 "void main()\n"
425 "{\n"
426 " vec4 green = vec4(0, 1, 0, 1);\n"
427 " vec4 black = vec4(0, 0, 0, 0);\n"
428 " fragColor = (texture(tex, texcoord).a == 1) ? green : black;\n"
429 "}\n");
430 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300431
432 void SetUp() override
433 {
434 Texture2DTest::SetUp();
435 setUpProgram();
436 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200437};
438
439class Texture2DUnsignedIntegerAlpha1TestES3 : public Texture2DTest
440{
441 protected:
442 Texture2DUnsignedIntegerAlpha1TestES3() : Texture2DTest() {}
443
444 std::string getVertexShaderSource() override
445 {
446 return std::string(
447 "#version 300 es\n"
448 "out vec2 texcoord;\n"
449 "in vec4 position;\n"
450 "void main()\n"
451 "{\n"
452 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
453 " texcoord = (position.xy * 0.5) + 0.5;\n"
454 "}\n");
455 }
456
457 std::string getFragmentShaderSource() override
458 {
459 return std::string(
460 "#version 300 es\n"
461 "precision highp float;\n"
462 "uniform highp usampler2D tex;\n"
463 "in vec2 texcoord;\n"
464 "out vec4 fragColor;\n"
465 "void main()\n"
466 "{\n"
467 " vec4 green = vec4(0, 1, 0, 1);\n"
468 " vec4 black = vec4(0, 0, 0, 0);\n"
469 " fragColor = (texture(tex, texcoord).a == 1u) ? green : black;\n"
470 "}\n");
471 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300472
473 void SetUp() override
474 {
475 Texture2DTest::SetUp();
476 setUpProgram();
477 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200478};
479
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200480class Texture2DTestWithDrawScale : public Texture2DTest
Jamie Madill2453dbc2015-07-14 11:35:42 -0400481{
482 protected:
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200483 Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {}
484
485 std::string getVertexShaderSource() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400486 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300487 return
488 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200489 attribute vec4 position;
490 varying vec2 texcoord;
491
492 uniform vec2 drawScale;
493
494 void main()
495 {
496 gl_Position = vec4(position.xy * drawScale, 0.0, 1.0);
497 texcoord = (position.xy * 0.5) + 0.5;
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300498 })";
Jamie Madill2453dbc2015-07-14 11:35:42 -0400499 }
500
501 void SetUp() override
502 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200503 Texture2DTest::SetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300504
505 setUpProgram();
506
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200507 mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale");
508 ASSERT_NE(-1, mDrawScaleUniformLocation);
Jamie Madill2453dbc2015-07-14 11:35:42 -0400509
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200510 glUseProgram(mProgram);
511 glUniform2f(mDrawScaleUniformLocation, 1.0f, 1.0f);
512 glUseProgram(0);
513 ASSERT_GL_NO_ERROR();
514 }
515
516 GLint mDrawScaleUniformLocation;
517};
518
Olli Etuaho4644a202016-01-12 15:12:53 +0200519class Sampler2DAsFunctionParameterTest : public Texture2DTest
520{
521 protected:
522 Sampler2DAsFunctionParameterTest() : Texture2DTest() {}
523
524 std::string getFragmentShaderSource() override
525 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300526 return
527 R"(precision highp float;
Olli Etuaho4644a202016-01-12 15:12:53 +0200528 uniform sampler2D tex;
529 varying vec2 texcoord;
530
531 vec4 computeFragColor(sampler2D aTex)
532 {
533 return texture2D(aTex, texcoord);
534 }
535
536 void main()
537 {
538 gl_FragColor = computeFragColor(tex);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300539 })";
Olli Etuaho4644a202016-01-12 15:12:53 +0200540 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300541
542 void SetUp() override
543 {
544 Texture2DTest::SetUp();
545 setUpProgram();
546 }
Olli Etuaho4644a202016-01-12 15:12:53 +0200547};
548
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200549class TextureCubeTest : public TexCoordDrawTest
550{
551 protected:
552 TextureCubeTest()
553 : TexCoordDrawTest(),
554 mTexture2D(0),
555 mTextureCube(0),
556 mTexture2DUniformLocation(-1),
557 mTextureCubeUniformLocation(-1)
558 {
559 }
560
561 std::string getFragmentShaderSource() override
562 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300563 return
564 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200565 uniform sampler2D tex2D;
566 uniform samplerCube texCube;
567 varying vec2 texcoord;
568
569 void main()
570 {
571 gl_FragColor = texture2D(tex2D, texcoord);
572 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300573 })";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200574 }
575
576 void SetUp() override
577 {
578 TexCoordDrawTest::SetUp();
579
580 glGenTextures(1, &mTextureCube);
581 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Geoff Langc4e93662017-05-01 10:45:59 -0400582 for (GLenum face = 0; face < 6; face++)
583 {
584 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
585 GL_UNSIGNED_BYTE, nullptr);
586 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200587 EXPECT_GL_NO_ERROR();
588
589 mTexture2D = create2DTexture();
590
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300591 setUpProgram();
592
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200593 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
594 ASSERT_NE(-1, mTexture2DUniformLocation);
595 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
596 ASSERT_NE(-1, mTextureCubeUniformLocation);
597 }
598
599 void TearDown() override
600 {
601 glDeleteTextures(1, &mTextureCube);
602 TexCoordDrawTest::TearDown();
603 }
604
605 GLuint mTexture2D;
606 GLuint mTextureCube;
607 GLint mTexture2DUniformLocation;
608 GLint mTextureCubeUniformLocation;
609};
610
Martin Radev7e2c0d32017-09-15 14:25:42 +0300611class TextureCubeTestES3 : public ANGLETest
612{
613 protected:
614 TextureCubeTestES3() {}
615};
616
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200617class SamplerArrayTest : public TexCoordDrawTest
618{
619 protected:
620 SamplerArrayTest()
621 : TexCoordDrawTest(),
622 mTexture2DA(0),
623 mTexture2DB(0),
624 mTexture0UniformLocation(-1),
625 mTexture1UniformLocation(-1)
626 {
627 }
628
629 std::string getFragmentShaderSource() override
630 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300631 return
632 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200633 uniform highp sampler2D tex2DArray[2];
634 varying vec2 texcoord;
635 void main()
636 {
637 gl_FragColor = texture2D(tex2DArray[0], texcoord);
638 gl_FragColor += texture2D(tex2DArray[1], texcoord);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300639 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200640 }
641
642 void SetUp() override
643 {
644 TexCoordDrawTest::SetUp();
645
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300646 setUpProgram();
647
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200648 mTexture0UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[0]");
649 ASSERT_NE(-1, mTexture0UniformLocation);
650 mTexture1UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[1]");
651 ASSERT_NE(-1, mTexture1UniformLocation);
652
653 mTexture2DA = create2DTexture();
654 mTexture2DB = create2DTexture();
655 ASSERT_GL_NO_ERROR();
656 }
657
658 void TearDown() override
659 {
660 glDeleteTextures(1, &mTexture2DA);
661 glDeleteTextures(1, &mTexture2DB);
662 TexCoordDrawTest::TearDown();
663 }
664
665 void testSamplerArrayDraw()
666 {
667 GLubyte texData[4];
668 texData[0] = 0;
669 texData[1] = 60;
670 texData[2] = 0;
671 texData[3] = 255;
672
673 glActiveTexture(GL_TEXTURE0);
674 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
675 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
676
677 texData[1] = 120;
678 glActiveTexture(GL_TEXTURE1);
679 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
680 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
681 EXPECT_GL_ERROR(GL_NO_ERROR);
682
683 glUseProgram(mProgram);
684 glUniform1i(mTexture0UniformLocation, 0);
685 glUniform1i(mTexture1UniformLocation, 1);
686 drawQuad(mProgram, "position", 0.5f);
687 EXPECT_GL_NO_ERROR();
688
689 EXPECT_PIXEL_NEAR(0, 0, 0, 180, 0, 255, 2);
690 }
691
692 GLuint mTexture2DA;
693 GLuint mTexture2DB;
694 GLint mTexture0UniformLocation;
695 GLint mTexture1UniformLocation;
696};
697
698
699class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest
700{
701 protected:
702 SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {}
703
704 std::string getFragmentShaderSource() override
705 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300706 return
707 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200708 uniform highp sampler2D tex2DArray[2];
709 varying vec2 texcoord;
710
711 vec4 computeFragColor(highp sampler2D aTex2DArray[2])
712 {
713 return texture2D(aTex2DArray[0], texcoord) + texture2D(aTex2DArray[1], texcoord);
714 }
715
716 void main()
717 {
718 gl_FragColor = computeFragColor(tex2DArray);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300719 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200720 }
721};
722
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200723class Texture2DArrayTestES3 : public TexCoordDrawTest
724{
725 protected:
726 Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {}
727
728 std::string getVertexShaderSource() override
729 {
730 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400731 "#version 300 es\n"
732 "out vec2 texcoord;\n"
733 "in vec4 position;\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200734 "void main()\n"
735 "{\n"
736 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
737 " texcoord = (position.xy * 0.5) + 0.5;\n"
738 "}\n");
739 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400740
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200741 std::string getFragmentShaderSource() override
742 {
743 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400744 "#version 300 es\n"
745 "precision highp float;\n"
Olli Etuaho183d7e22015-11-20 15:59:09 +0200746 "uniform highp sampler2DArray tex2DArray;\n"
Jamie Madill2453dbc2015-07-14 11:35:42 -0400747 "in vec2 texcoord;\n"
748 "out vec4 fragColor;\n"
749 "void main()\n"
750 "{\n"
751 " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200752 "}\n");
753 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400754
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200755 void SetUp() override
756 {
757 TexCoordDrawTest::SetUp();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400758
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300759 setUpProgram();
760
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200761 mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray");
Jamie Madill2453dbc2015-07-14 11:35:42 -0400762 ASSERT_NE(-1, mTextureArrayLocation);
763
764 glGenTextures(1, &m2DArrayTexture);
765 ASSERT_GL_NO_ERROR();
766 }
767
768 void TearDown() override
769 {
770 glDeleteTextures(1, &m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200771 TexCoordDrawTest::TearDown();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400772 }
773
774 GLuint m2DArrayTexture;
Jamie Madill2453dbc2015-07-14 11:35:42 -0400775 GLint mTextureArrayLocation;
776};
777
Olli Etuahobce743a2016-01-15 17:18:28 +0200778class TextureSizeTextureArrayTest : public TexCoordDrawTest
779{
780 protected:
781 TextureSizeTextureArrayTest()
782 : TexCoordDrawTest(),
783 mTexture2DA(0),
784 mTexture2DB(0),
785 mTexture0Location(-1),
786 mTexture1Location(-1)
787 {
788 }
789
790 std::string getVertexShaderSource() override
791 {
792 return std::string(
793 "#version 300 es\n"
794 "in vec4 position;\n"
795 "void main()\n"
796 "{\n"
797 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
798 "}\n");
799 }
800
801 std::string getFragmentShaderSource() override
802 {
803 return std::string(
804 "#version 300 es\n"
805 "precision highp float;\n"
806 "uniform highp sampler2D tex2DArray[2];\n"
807 "out vec4 fragColor;\n"
808 "void main()\n"
809 "{\n"
810 " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n"
811 " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n"
812 " fragColor = vec4(red, green, 0.0, 1.0);\n"
813 "}\n");
814 }
815
816 void SetUp() override
817 {
818 TexCoordDrawTest::SetUp();
819
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300820 setUpProgram();
821
Olli Etuahobce743a2016-01-15 17:18:28 +0200822 mTexture0Location = glGetUniformLocation(mProgram, "tex2DArray[0]");
823 ASSERT_NE(-1, mTexture0Location);
824 mTexture1Location = glGetUniformLocation(mProgram, "tex2DArray[1]");
825 ASSERT_NE(-1, mTexture1Location);
826
827 mTexture2DA = create2DTexture();
828 mTexture2DB = create2DTexture();
829 ASSERT_GL_NO_ERROR();
830 }
831
832 void TearDown() override
833 {
834 glDeleteTextures(1, &mTexture2DA);
835 glDeleteTextures(1, &mTexture2DB);
836 TexCoordDrawTest::TearDown();
837 }
838
839 GLuint mTexture2DA;
840 GLuint mTexture2DB;
841 GLint mTexture0Location;
842 GLint mTexture1Location;
843};
844
Olli Etuahoa314b612016-03-10 16:43:00 +0200845class Texture3DTestES3 : public TexCoordDrawTest
846{
847 protected:
848 Texture3DTestES3() : TexCoordDrawTest(), mTexture3D(0), mTexture3DUniformLocation(-1) {}
849
850 std::string getVertexShaderSource() override
851 {
852 return std::string(
853 "#version 300 es\n"
854 "out vec2 texcoord;\n"
855 "in vec4 position;\n"
856 "void main()\n"
857 "{\n"
858 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
859 " texcoord = (position.xy * 0.5) + 0.5;\n"
860 "}\n");
861 }
862
863 std::string getFragmentShaderSource() override
864 {
865 return std::string(
866 "#version 300 es\n"
867 "precision highp float;\n"
868 "uniform highp sampler3D tex3D;\n"
869 "in vec2 texcoord;\n"
870 "out vec4 fragColor;\n"
871 "void main()\n"
872 "{\n"
873 " fragColor = texture(tex3D, vec3(texcoord, 0.0));\n"
874 "}\n");
875 }
876
877 void SetUp() override
878 {
879 TexCoordDrawTest::SetUp();
880
881 glGenTextures(1, &mTexture3D);
882
883 setUpProgram();
884
885 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
886 ASSERT_NE(-1, mTexture3DUniformLocation);
887 }
888
889 void TearDown() override
890 {
891 glDeleteTextures(1, &mTexture3D);
892 TexCoordDrawTest::TearDown();
893 }
894
895 GLuint mTexture3D;
896 GLint mTexture3DUniformLocation;
897};
898
Olli Etuaho1a679902016-01-14 12:21:47 +0200899class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest
900{
901 protected:
902 ShadowSamplerPlusSampler3DTestES3()
903 : TexCoordDrawTest(),
904 mTextureShadow(0),
905 mTexture3D(0),
906 mTextureShadowUniformLocation(-1),
907 mTexture3DUniformLocation(-1),
908 mDepthRefUniformLocation(-1)
909 {
910 }
911
912 std::string getVertexShaderSource() override
913 {
914 return std::string(
915 "#version 300 es\n"
916 "out vec2 texcoord;\n"
917 "in vec4 position;\n"
918 "void main()\n"
919 "{\n"
920 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
921 " texcoord = (position.xy * 0.5) + 0.5;\n"
922 "}\n");
923 }
924
925 std::string getFragmentShaderSource() override
926 {
927 return std::string(
928 "#version 300 es\n"
929 "precision highp float;\n"
930 "uniform highp sampler2DShadow tex2DShadow;\n"
931 "uniform highp sampler3D tex3D;\n"
932 "in vec2 texcoord;\n"
933 "uniform float depthRef;\n"
934 "out vec4 fragColor;\n"
935 "void main()\n"
936 "{\n"
937 " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n"
938 " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n"
939 "}\n");
940 }
941
942 void SetUp() override
943 {
944 TexCoordDrawTest::SetUp();
945
946 glGenTextures(1, &mTexture3D);
947
948 glGenTextures(1, &mTextureShadow);
949 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
950 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
951
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300952 setUpProgram();
953
Olli Etuaho1a679902016-01-14 12:21:47 +0200954 mTextureShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
955 ASSERT_NE(-1, mTextureShadowUniformLocation);
956 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
957 ASSERT_NE(-1, mTexture3DUniformLocation);
958 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
959 ASSERT_NE(-1, mDepthRefUniformLocation);
960 }
961
962 void TearDown() override
963 {
964 glDeleteTextures(1, &mTextureShadow);
965 glDeleteTextures(1, &mTexture3D);
966 TexCoordDrawTest::TearDown();
967 }
968
969 GLuint mTextureShadow;
970 GLuint mTexture3D;
971 GLint mTextureShadowUniformLocation;
972 GLint mTexture3DUniformLocation;
973 GLint mDepthRefUniformLocation;
974};
975
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200976class SamplerTypeMixTestES3 : public TexCoordDrawTest
977{
978 protected:
979 SamplerTypeMixTestES3()
980 : TexCoordDrawTest(),
981 mTexture2D(0),
982 mTextureCube(0),
983 mTexture2DShadow(0),
984 mTextureCubeShadow(0),
985 mTexture2DUniformLocation(-1),
986 mTextureCubeUniformLocation(-1),
987 mTexture2DShadowUniformLocation(-1),
988 mTextureCubeShadowUniformLocation(-1),
989 mDepthRefUniformLocation(-1)
990 {
991 }
992
993 std::string getVertexShaderSource() override
994 {
995 return std::string(
996 "#version 300 es\n"
997 "out vec2 texcoord;\n"
998 "in vec4 position;\n"
999 "void main()\n"
1000 "{\n"
1001 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1002 " texcoord = (position.xy * 0.5) + 0.5;\n"
1003 "}\n");
1004 }
1005
1006 std::string getFragmentShaderSource() override
1007 {
1008 return std::string(
1009 "#version 300 es\n"
1010 "precision highp float;\n"
1011 "uniform highp sampler2D tex2D;\n"
1012 "uniform highp samplerCube texCube;\n"
1013 "uniform highp sampler2DShadow tex2DShadow;\n"
1014 "uniform highp samplerCubeShadow texCubeShadow;\n"
1015 "in vec2 texcoord;\n"
1016 "uniform float depthRef;\n"
1017 "out vec4 fragColor;\n"
1018 "void main()\n"
1019 "{\n"
1020 " fragColor = texture(tex2D, texcoord);\n"
1021 " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n"
1022 " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n"
1023 " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * "
1024 "0.125);\n"
1025 "}\n");
1026 }
1027
1028 void SetUp() override
1029 {
1030 TexCoordDrawTest::SetUp();
1031
1032 glGenTextures(1, &mTexture2D);
1033 glGenTextures(1, &mTextureCube);
1034
1035 glGenTextures(1, &mTexture2DShadow);
1036 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
1037 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
1038
1039 glGenTextures(1, &mTextureCubeShadow);
1040 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
1041 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
1042
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001043 setUpProgram();
1044
Olli Etuahoc8c99a02016-01-14 16:47:22 +02001045 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
1046 ASSERT_NE(-1, mTexture2DUniformLocation);
1047 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
1048 ASSERT_NE(-1, mTextureCubeUniformLocation);
1049 mTexture2DShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
1050 ASSERT_NE(-1, mTexture2DShadowUniformLocation);
1051 mTextureCubeShadowUniformLocation = glGetUniformLocation(mProgram, "texCubeShadow");
1052 ASSERT_NE(-1, mTextureCubeShadowUniformLocation);
1053 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
1054 ASSERT_NE(-1, mDepthRefUniformLocation);
1055
1056 ASSERT_GL_NO_ERROR();
1057 }
1058
1059 void TearDown() override
1060 {
1061 glDeleteTextures(1, &mTexture2D);
1062 glDeleteTextures(1, &mTextureCube);
1063 glDeleteTextures(1, &mTexture2DShadow);
1064 glDeleteTextures(1, &mTextureCubeShadow);
1065 TexCoordDrawTest::TearDown();
1066 }
1067
1068 GLuint mTexture2D;
1069 GLuint mTextureCube;
1070 GLuint mTexture2DShadow;
1071 GLuint mTextureCubeShadow;
1072 GLint mTexture2DUniformLocation;
1073 GLint mTextureCubeUniformLocation;
1074 GLint mTexture2DShadowUniformLocation;
1075 GLint mTextureCubeShadowUniformLocation;
1076 GLint mDepthRefUniformLocation;
1077};
1078
Olli Etuaho96963162016-03-21 11:54:33 +02001079class SamplerInStructTest : public Texture2DTest
1080{
1081 protected:
1082 SamplerInStructTest() : Texture2DTest() {}
1083
1084 const char *getTextureUniformName() override { return "us.tex"; }
1085
1086 std::string getFragmentShaderSource() override
1087 {
1088 return std::string(
1089 "precision highp float;\n"
1090 "struct S\n"
1091 "{\n"
1092 " vec4 a;\n"
1093 " highp sampler2D tex;\n"
1094 "};\n"
1095 "uniform S us;\n"
1096 "varying vec2 texcoord;\n"
1097 "void main()\n"
1098 "{\n"
1099 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x);\n"
1100 "}\n");
1101 }
1102
1103 void runSamplerInStructTest()
1104 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001105 setUpProgram();
1106
Olli Etuaho96963162016-03-21 11:54:33 +02001107 glActiveTexture(GL_TEXTURE0);
1108 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001109 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1110 &GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001111 drawQuad(mProgram, "position", 0.5f);
Olli Etuahoa314b612016-03-10 16:43:00 +02001112 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001113 }
1114};
1115
1116class SamplerInStructAsFunctionParameterTest : public SamplerInStructTest
1117{
1118 protected:
1119 SamplerInStructAsFunctionParameterTest() : SamplerInStructTest() {}
1120
1121 std::string getFragmentShaderSource() override
1122 {
1123 return std::string(
1124 "precision highp float;\n"
1125 "struct S\n"
1126 "{\n"
1127 " vec4 a;\n"
1128 " highp sampler2D tex;\n"
1129 "};\n"
1130 "uniform S us;\n"
1131 "varying vec2 texcoord;\n"
1132 "vec4 sampleFrom(S s) {\n"
1133 " return texture2D(s.tex, texcoord + s.a.x);\n"
1134 "}\n"
1135 "void main()\n"
1136 "{\n"
1137 " gl_FragColor = sampleFrom(us);\n"
1138 "}\n");
1139 }
1140};
1141
1142class SamplerInStructArrayAsFunctionParameterTest : public SamplerInStructTest
1143{
1144 protected:
1145 SamplerInStructArrayAsFunctionParameterTest() : SamplerInStructTest() {}
1146
1147 const char *getTextureUniformName() override { return "us[0].tex"; }
1148
1149 std::string getFragmentShaderSource() override
1150 {
1151 return std::string(
1152 "precision highp float;\n"
1153 "struct S\n"
1154 "{\n"
1155 " vec4 a;\n"
1156 " highp sampler2D tex;\n"
1157 "};\n"
1158 "uniform S us[1];\n"
1159 "varying vec2 texcoord;\n"
1160 "vec4 sampleFrom(S s) {\n"
1161 " return texture2D(s.tex, texcoord + s.a.x);\n"
1162 "}\n"
1163 "void main()\n"
1164 "{\n"
1165 " gl_FragColor = sampleFrom(us[0]);\n"
1166 "}\n");
1167 }
1168};
1169
1170class SamplerInNestedStructAsFunctionParameterTest : public SamplerInStructTest
1171{
1172 protected:
1173 SamplerInNestedStructAsFunctionParameterTest() : SamplerInStructTest() {}
1174
1175 const char *getTextureUniformName() override { return "us[0].sub.tex"; }
1176
1177 std::string getFragmentShaderSource() override
1178 {
1179 return std::string(
1180 "precision highp float;\n"
1181 "struct SUB\n"
1182 "{\n"
1183 " vec4 a;\n"
1184 " highp sampler2D tex;\n"
1185 "};\n"
1186 "struct S\n"
1187 "{\n"
1188 " SUB sub;\n"
1189 "};\n"
1190 "uniform S us[1];\n"
1191 "varying vec2 texcoord;\n"
1192 "vec4 sampleFrom(SUB s) {\n"
1193 " return texture2D(s.tex, texcoord + s.a.x);\n"
1194 "}\n"
1195 "void main()\n"
1196 "{\n"
1197 " gl_FragColor = sampleFrom(us[0].sub);\n"
1198 "}\n");
1199 }
1200};
1201
1202class SamplerInStructAndOtherVariableTest : public SamplerInStructTest
1203{
1204 protected:
1205 SamplerInStructAndOtherVariableTest() : SamplerInStructTest() {}
1206
1207 std::string getFragmentShaderSource() override
1208 {
1209 return std::string(
1210 "precision highp float;\n"
1211 "struct S\n"
1212 "{\n"
1213 " vec4 a;\n"
1214 " highp sampler2D tex;\n"
1215 "};\n"
1216 "uniform S us;\n"
1217 "uniform float us_tex;\n"
1218 "varying vec2 texcoord;\n"
1219 "void main()\n"
1220 "{\n"
1221 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x + us_tex);\n"
1222 "}\n");
1223 }
1224};
1225
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001226TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001227{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001228 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001229 EXPECT_GL_ERROR(GL_NO_ERROR);
1230
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001231 setUpProgram();
1232
Jamie Madillf67115c2014-04-22 13:14:05 -04001233 const GLubyte *pixels[20] = { 0 };
1234 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1235 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001236
1237 if (extensionEnabled("GL_EXT_texture_storage"))
1238 {
1239 // Create a 1-level immutable texture.
1240 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1241
1242 // Try calling sub image on the second level.
1243 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1244 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1245 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001246}
Geoff Langc41e42d2014-04-28 10:58:16 -04001247
John Bauman18319182016-09-28 14:22:27 -07001248// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1249TEST_P(Texture2DTest, QueryBinding)
1250{
1251 glBindTexture(GL_TEXTURE_2D, 0);
1252 EXPECT_GL_ERROR(GL_NO_ERROR);
1253
1254 GLint textureBinding;
1255 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1256 EXPECT_GL_NO_ERROR();
1257 EXPECT_EQ(0, textureBinding);
1258
1259 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
1260 if (extensionEnabled("GL_OES_EGL_image_external") ||
1261 extensionEnabled("GL_NV_EGL_stream_consumer_external"))
1262 {
1263 EXPECT_GL_NO_ERROR();
1264 EXPECT_EQ(0, textureBinding);
1265 }
1266 else
1267 {
1268 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1269 }
1270}
1271
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001272TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001273{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001274 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001275 EXPECT_GL_ERROR(GL_NO_ERROR);
1276
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001277 setUpProgram();
1278
Geoff Langc41e42d2014-04-28 10:58:16 -04001279 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001280 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001281 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001282 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001283
1284 const GLubyte *pixel[4] = { 0 };
1285
1286 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1287 EXPECT_GL_NO_ERROR();
1288
1289 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1290 EXPECT_GL_NO_ERROR();
1291
1292 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1293 EXPECT_GL_NO_ERROR();
1294}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001295
1296// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001297TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001298{
1299 glActiveTexture(GL_TEXTURE0);
1300 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1301 glActiveTexture(GL_TEXTURE1);
1302 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1303 EXPECT_GL_ERROR(GL_NO_ERROR);
1304
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001305 glUseProgram(mProgram);
1306 glUniform1i(mTexture2DUniformLocation, 0);
1307 glUniform1i(mTextureCubeUniformLocation, 1);
1308 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001309 EXPECT_GL_NO_ERROR();
1310}
Jamie Madill9aca0592014-10-06 16:26:59 -04001311
Olli Etuaho53a2da12016-01-11 15:43:32 +02001312// Test drawing with two texture types accessed from the same shader and check that the result of
1313// drawing is correct.
1314TEST_P(TextureCubeTest, CubeMapDraw)
1315{
1316 GLubyte texData[4];
1317 texData[0] = 0;
1318 texData[1] = 60;
1319 texData[2] = 0;
1320 texData[3] = 255;
1321
1322 glActiveTexture(GL_TEXTURE0);
1323 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1324 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1325
1326 glActiveTexture(GL_TEXTURE1);
1327 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1328 texData[1] = 120;
1329 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1330 texData);
1331 EXPECT_GL_ERROR(GL_NO_ERROR);
1332
1333 glUseProgram(mProgram);
1334 glUniform1i(mTexture2DUniformLocation, 0);
1335 glUniform1i(mTextureCubeUniformLocation, 1);
1336 drawQuad(mProgram, "position", 0.5f);
1337 EXPECT_GL_NO_ERROR();
1338
1339 int px = getWindowWidth() - 1;
1340 int py = 0;
1341 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1342}
1343
Olli Etuaho4644a202016-01-12 15:12:53 +02001344TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1345{
1346 glActiveTexture(GL_TEXTURE0);
1347 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1348 GLubyte texData[4];
1349 texData[0] = 0;
1350 texData[1] = 128;
1351 texData[2] = 0;
1352 texData[3] = 255;
1353 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1354 glUseProgram(mProgram);
1355 glUniform1i(mTexture2DUniformLocation, 0);
1356 drawQuad(mProgram, "position", 0.5f);
1357 EXPECT_GL_NO_ERROR();
1358
1359 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1360}
1361
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001362// Test drawing with two textures passed to the shader in a sampler array.
1363TEST_P(SamplerArrayTest, SamplerArrayDraw)
1364{
1365 testSamplerArrayDraw();
1366}
1367
1368// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1369// user-defined function in the shader.
1370TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1371{
1372 testSamplerArrayDraw();
1373}
1374
Jamie Madill9aca0592014-10-06 16:26:59 -04001375// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001376TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001377{
1378 int px = getWindowWidth() / 2;
1379 int py = getWindowHeight() / 2;
1380
1381 glActiveTexture(GL_TEXTURE0);
1382 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1383
Olli Etuahoa314b612016-03-10 16:43:00 +02001384 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001385
Olli Etuahoa314b612016-03-10 16:43:00 +02001386 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001387 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1388 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1389 glGenerateMipmap(GL_TEXTURE_2D);
1390
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001391 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001392 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001393 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1394 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001395 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001396 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001397
Olli Etuahoa314b612016-03-10 16:43:00 +02001398 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001399
Olli Etuahoa314b612016-03-10 16:43:00 +02001400 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1401 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001402 glGenerateMipmap(GL_TEXTURE_2D);
1403
Olli Etuahoa314b612016-03-10 16:43:00 +02001404 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001405
Olli Etuahoa314b612016-03-10 16:43:00 +02001406 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1407 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001408 glGenerateMipmap(GL_TEXTURE_2D);
1409
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001410 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001411
1412 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001413 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001414}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001415
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001416// Test creating a FBO with a cube map render target, to test an ANGLE bug
1417// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001418TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001419{
1420 GLuint fbo;
1421 glGenFramebuffers(1, &fbo);
1422 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1423
1424 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1425 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mTextureCube, 0);
1426
Corentin Wallez322653b2015-06-17 18:33:56 +02001427 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001428
1429 glDeleteFramebuffers(1, &fbo);
1430
1431 EXPECT_GL_NO_ERROR();
1432}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001433
1434// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001435TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001436{
Geoff Langc4e93662017-05-01 10:45:59 -04001437 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_texture_storage"))
1438 {
1439 std::cout << "Test skipped because ES3 or GL_EXT_texture_storage not available."
1440 << std::endl;
1441 return;
1442 }
1443
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001444 int width = getWindowWidth();
1445 int height = getWindowHeight();
1446
1447 GLuint tex2D;
1448 glGenTextures(1, &tex2D);
1449 glActiveTexture(GL_TEXTURE0);
1450 glBindTexture(GL_TEXTURE_2D, tex2D);
1451
1452 // Fill with red
1453 std::vector<GLubyte> pixels(3 * 16 * 16);
1454 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1455 {
1456 pixels[pixelId * 3 + 0] = 255;
1457 pixels[pixelId * 3 + 1] = 0;
1458 pixels[pixelId * 3 + 2] = 0;
1459 }
1460
1461 // ANGLE internally uses RGBA as the DirectX format for RGB images
1462 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1463 // The data is kept in a CPU-side image and the image is marked as dirty.
Geoff Langc4e93662017-05-01 10:45:59 -04001464 if (getClientMajorVersion() >= 3)
1465 {
1466 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1467 }
1468 else
1469 {
1470 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1471 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001472
1473 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1474 // glTexSubImage2D should take into account that the image is dirty.
1475 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1476 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1477 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1478
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001479 setUpProgram();
1480
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001481 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001482 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001483 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001484 glDeleteTextures(1, &tex2D);
1485 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001486 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001487
1488 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001489 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1490 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001491}
1492
1493// 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 +02001494TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001495{
1496 if (extensionEnabled("NV_pixel_buffer_object"))
1497 {
1498 int width = getWindowWidth();
1499 int height = getWindowHeight();
1500
1501 GLuint tex2D;
1502 glGenTextures(1, &tex2D);
1503 glActiveTexture(GL_TEXTURE0);
1504 glBindTexture(GL_TEXTURE_2D, tex2D);
1505
1506 // Fill with red
1507 std::vector<GLubyte> pixels(3 * 16 * 16);
1508 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1509 {
1510 pixels[pixelId * 3 + 0] = 255;
1511 pixels[pixelId * 3 + 1] = 0;
1512 pixels[pixelId * 3 + 2] = 0;
1513 }
1514
1515 // Read 16x16 region from red backbuffer to PBO
1516 GLuint pbo;
1517 glGenBuffers(1, &pbo);
1518 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1519 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1520
1521 // ANGLE internally uses RGBA as the DirectX format for RGB images
1522 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1523 // The data is kept in a CPU-side image and the image is marked as dirty.
1524 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1525
1526 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1527 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001528 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 +00001529 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1530 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1531
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001532 setUpProgram();
1533
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001534 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001535 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001536 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001537 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001538 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001539 EXPECT_GL_NO_ERROR();
1540 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1541 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1542 }
1543}
Jamie Madillbc393df2015-01-29 13:46:07 -05001544
1545// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001546TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001547{
1548 testFloatCopySubImage(1, 1);
1549}
1550
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001551TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001552{
1553 testFloatCopySubImage(2, 1);
1554}
1555
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001556TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001557{
1558 testFloatCopySubImage(2, 2);
1559}
1560
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001561TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001562{
1563 testFloatCopySubImage(3, 1);
1564}
1565
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001566TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001567{
1568 testFloatCopySubImage(3, 2);
1569}
1570
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001571TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001572{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001573 if (IsIntel() && IsLinux())
1574 {
1575 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1576 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1577 return;
1578 }
1579
Austin Kinrossd544cc92016-01-11 15:26:42 -08001580 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001581 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001582 {
1583 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1584 return;
1585 }
1586
Jamie Madillbc393df2015-01-29 13:46:07 -05001587 testFloatCopySubImage(3, 3);
1588}
1589
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001590TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001591{
1592 testFloatCopySubImage(4, 1);
1593}
1594
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001595TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001596{
1597 testFloatCopySubImage(4, 2);
1598}
1599
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001600TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001601{
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(4, 3);
1610}
1611
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001612TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001613{
Austin Kinrossd544cc92016-01-11 15:26:42 -08001614 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001615 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001616 {
1617 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1618 return;
1619 }
1620
Jamie Madillbc393df2015-01-29 13:46:07 -05001621 testFloatCopySubImage(4, 4);
1622}
Austin Kinross07285142015-03-26 11:36:16 -07001623
1624// Port of https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1625// 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 +02001626TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001627{
1628 const int npotTexSize = 5;
1629 const int potTexSize = 4; // Should be less than npotTexSize
1630 GLuint tex2D;
1631
1632 if (extensionEnabled("GL_OES_texture_npot"))
1633 {
1634 // This test isn't applicable if texture_npot is enabled
1635 return;
1636 }
1637
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001638 setUpProgram();
1639
Austin Kinross07285142015-03-26 11:36:16 -07001640 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1641
Austin Kinross5faa15b2016-01-11 13:32:48 -08001642 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1643 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1644
Austin Kinross07285142015-03-26 11:36:16 -07001645 glActiveTexture(GL_TEXTURE0);
1646 glGenTextures(1, &tex2D);
1647 glBindTexture(GL_TEXTURE_2D, tex2D);
1648
1649 std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize);
1650 for (size_t pixelId = 0; pixelId < npotTexSize * npotTexSize; ++pixelId)
1651 {
1652 pixels[pixelId] = 64;
1653 }
1654
1655 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1656 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1657
1658 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
1659 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1660 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1661
1662 // Check that an NPOT texture on level 0 succeeds
1663 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1664 EXPECT_GL_NO_ERROR();
1665
1666 // Check that generateMipmap fails on NPOT
1667 glGenerateMipmap(GL_TEXTURE_2D);
1668 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1669
1670 // Check that nothing is drawn if filtering is not correct for NPOT
1671 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1672 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1673 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1674 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1675 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001676 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001677 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1678
1679 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1680 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1681 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1682 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1683 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001684 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001685 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1686
1687 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1688 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1689 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001690 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001691 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1692
1693 // Check that glTexImage2D for POT texture succeeds
1694 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1695 EXPECT_GL_NO_ERROR();
1696
1697 // Check that generateMipmap for an POT texture succeeds
1698 glGenerateMipmap(GL_TEXTURE_2D);
1699 EXPECT_GL_NO_ERROR();
1700
1701 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1702 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1703 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1704 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1705 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1706 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001707 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001708 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1709 EXPECT_GL_NO_ERROR();
1710}
Jamie Madillfa05f602015-05-07 13:47:11 -04001711
Austin Kinross08528e12015-10-07 16:24:40 -07001712// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1713// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001714TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001715{
1716 glActiveTexture(GL_TEXTURE0);
1717 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1718
1719 // Create an 8x8 (i.e. power-of-two) texture.
1720 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1721 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1722 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1723 glGenerateMipmap(GL_TEXTURE_2D);
1724
1725 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1726 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001727 std::array<GLColor, 3 * 3> data;
1728 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001729
1730 EXPECT_GL_NO_ERROR();
1731}
1732
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001733// Test to check that texture completeness is determined correctly when the texture base level is
1734// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1735TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1736{
1737 glActiveTexture(GL_TEXTURE0);
1738 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001739
1740 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1741 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1742 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1743 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1744 texDataGreen.data());
1745 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1746 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001747 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1748 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1749 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1750
1751 EXPECT_GL_NO_ERROR();
1752
1753 drawQuad(mProgram, "position", 0.5f);
1754
Olli Etuahoa314b612016-03-10 16:43:00 +02001755 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1756}
1757
1758// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1759// have images defined.
1760TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1761{
1762 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1763 {
1764 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1765 std::cout << "Test skipped on AMD OpenGL." << std::endl;
1766 return;
1767 }
1768 if (IsOSX())
1769 {
1770 // Observed incorrect rendering on OSX.
1771 std::cout << "Test skipped on OSX." << std::endl;
1772 return;
1773 }
1774 glActiveTexture(GL_TEXTURE0);
1775 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1776 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1777 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1778 texDataGreen.data());
1779 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1780 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1781 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1782 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1783
1784 EXPECT_GL_NO_ERROR();
1785
1786 drawQuad(mProgram, "position", 0.5f);
1787
1788 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1789}
1790
Olli Etuahoe8528d82016-05-16 17:50:52 +03001791// Test that drawing works correctly when level 0 is undefined and base level is 1.
1792TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1793{
1794 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1795 {
1796 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1797 std::cout << "Test skipped on AMD OpenGL." << std::endl;
1798 return;
1799 }
1800 if (IsOSX())
1801 {
1802 // Observed incorrect rendering on OSX.
1803 std::cout << "Test skipped on OSX." << std::endl;
1804 return;
1805 }
1806 glActiveTexture(GL_TEXTURE0);
1807 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1808 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1809 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1810 texDataGreen.data());
1811 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1812 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1813 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1814 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1815
1816 EXPECT_GL_NO_ERROR();
1817
1818 // Texture is incomplete.
1819 drawQuad(mProgram, "position", 0.5f);
1820 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1821
1822 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1823 texDataGreen.data());
1824
1825 // Texture is now complete.
1826 drawQuad(mProgram, "position", 0.5f);
1827 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1828}
1829
Olli Etuahoa314b612016-03-10 16:43:00 +02001830// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1831// dimensions that don't fit the images inside the range.
1832// GLES 3.0.4 section 3.8.13 Texture completeness
1833TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1834{
1835 if (IsOSX())
1836 {
1837 // Observed incorrect rendering on OSX.
1838 std::cout << "Test skipped on OSX." << std::endl;
1839 return;
1840 }
1841 glActiveTexture(GL_TEXTURE0);
1842 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1843 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1844 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1845 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1846
1847 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1848 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1849
1850 // Two levels that are initially unused.
1851 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1852 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1853 texDataCyan.data());
1854
1855 // One level that is used - only this level should affect completeness.
1856 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1857 texDataGreen.data());
1858
1859 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1860 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1861
1862 EXPECT_GL_NO_ERROR();
1863
1864 drawQuad(mProgram, "position", 0.5f);
1865
1866 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1867
1868 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1869 {
1870 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
1871 // level was changed.
1872 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
1873 return;
1874 }
1875
1876 // Switch the level that is being used to the cyan level 2.
1877 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1878 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1879
1880 EXPECT_GL_NO_ERROR();
1881
1882 drawQuad(mProgram, "position", 0.5f);
1883
1884 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1885}
1886
1887// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1888// have images defined.
1889TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1890{
1891 if (IsOSX())
1892 {
1893 // Observed incorrect rendering on OSX.
1894 std::cout << "Test skipped on OSX." << std::endl;
1895 return;
1896 }
1897 glActiveTexture(GL_TEXTURE0);
1898 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1899 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1900 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1901 texDataGreen.data());
1902 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1903 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1904 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1905 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1906
1907 EXPECT_GL_NO_ERROR();
1908
1909 drawQuad(mProgram, "position", 0.5f);
1910
1911 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1912}
1913
1914// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1915// dimensions that don't fit the images inside the range.
1916// GLES 3.0.4 section 3.8.13 Texture completeness
1917TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1918{
1919 if (IsOSX())
1920 {
1921 // Observed incorrect rendering on OSX.
1922 std::cout << "Test skipped on OSX." << std::endl;
1923 return;
1924 }
1925 glActiveTexture(GL_TEXTURE0);
1926 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1927 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1928 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1929 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1930
1931 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1932 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1933
1934 // Two levels that are initially unused.
1935 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1936 texDataRed.data());
1937 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1938 texDataCyan.data());
1939
1940 // One level that is used - only this level should affect completeness.
1941 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1942 texDataGreen.data());
1943
1944 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1945 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1946
1947 EXPECT_GL_NO_ERROR();
1948
1949 drawQuad(mProgram, "position", 0.5f);
1950
1951 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1952
1953 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1954 {
1955 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
1956 // level was changed.
1957 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
1958 return;
1959 }
1960
1961 // Switch the level that is being used to the cyan level 2.
1962 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
1963 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
1964
1965 EXPECT_GL_NO_ERROR();
1966
1967 drawQuad(mProgram, "position", 0.5f);
1968
1969 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1970}
1971
1972// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1973// have images defined.
1974TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
1975{
1976 if (IsOSX())
1977 {
1978 // Observed incorrect rendering on OSX.
1979 std::cout << "Test skipped on OSX." << std::endl;
1980 return;
1981 }
1982 glActiveTexture(GL_TEXTURE0);
1983 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
1984 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1985 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1986 texDataGreen.data());
1987 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1988 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1989 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1990 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1991
1992 EXPECT_GL_NO_ERROR();
1993
1994 drawQuad(mProgram, "position", 0.5f);
1995
1996 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1997}
1998
1999// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2000// dimensions that don't fit the images inside the range.
2001// GLES 3.0.4 section 3.8.13 Texture completeness
2002TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2003{
2004 if (IsOSX())
2005 {
2006 // Observed incorrect rendering on OSX.
2007 std::cout << "Test skipped on OSX." << std::endl;
2008 return;
2009 }
2010 glActiveTexture(GL_TEXTURE0);
2011 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
2012 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2013 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2014 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2015
2016 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2017 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2018
2019 // Two levels that are initially unused.
2020 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2021 texDataRed.data());
2022 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2023 texDataCyan.data());
2024
2025 // One level that is used - only this level should affect completeness.
2026 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2027 texDataGreen.data());
2028
2029 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2030 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2031
2032 EXPECT_GL_NO_ERROR();
2033
2034 drawQuad(mProgram, "position", 0.5f);
2035
2036 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2037
2038 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2039 {
2040 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
2041 // level was changed.
2042 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
2043 return;
2044 }
2045 if (IsNVIDIA() && (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
2046 getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE))
2047 {
2048 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
2049 // level was changed.
2050 std::cout << "Test partially skipped on NVIDIA OpenGL." << std::endl;
2051 return;
2052 }
2053
2054 // Switch the level that is being used to the cyan level 2.
2055 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2056 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2057
2058 EXPECT_GL_NO_ERROR();
2059
2060 drawQuad(mProgram, "position", 0.5f);
2061
2062 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2063}
2064
2065// Test that texture completeness is updated if texture max level changes.
2066// GLES 3.0.4 section 3.8.13 Texture completeness
2067TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2068{
2069 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2070 {
2071 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2072 // the base level.
2073 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2074 return;
2075 }
2076 if (IsOSX())
2077 {
2078 // Observed incorrect rendering on OSX.
2079 std::cout << "Test skipped on OSX." << std::endl;
2080 return;
2081 }
2082
2083 glActiveTexture(GL_TEXTURE0);
2084 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2085 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2086
2087 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2088 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2089
2090 // A level that is initially unused.
2091 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2092 texDataGreen.data());
2093
2094 // One level that is initially used - only this level should affect completeness.
2095 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2096 texDataGreen.data());
2097
2098 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2099 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2100
2101 EXPECT_GL_NO_ERROR();
2102
2103 drawQuad(mProgram, "position", 0.5f);
2104
2105 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2106
2107 // Switch the max level to level 1. The levels within the used range now have inconsistent
2108 // dimensions and the texture should be incomplete.
2109 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2110
2111 EXPECT_GL_NO_ERROR();
2112
2113 drawQuad(mProgram, "position", 0.5f);
2114
2115 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2116}
2117
2118// Test that 3D texture completeness is updated if texture max level changes.
2119// GLES 3.0.4 section 3.8.13 Texture completeness
2120TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2121{
2122 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2123 {
2124 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2125 // the base level.
2126 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2127 return;
2128 }
2129 if (IsOSX())
2130 {
2131 // Observed incorrect rendering on OSX.
2132 std::cout << "Test skipped on OSX." << std::endl;
2133 return;
2134 }
2135
2136 glActiveTexture(GL_TEXTURE0);
2137 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2138 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2139
2140 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2141 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2142
2143 // A level that is initially unused.
2144 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2145 texDataGreen.data());
2146
2147 // One level that is initially used - only this level should affect completeness.
2148 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2149 texDataGreen.data());
2150
2151 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2152 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2153
2154 EXPECT_GL_NO_ERROR();
2155
2156 drawQuad(mProgram, "position", 0.5f);
2157
2158 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2159
2160 // Switch the max level to level 1. The levels within the used range now have inconsistent
2161 // dimensions and the texture should be incomplete.
2162 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2163
2164 EXPECT_GL_NO_ERROR();
2165
2166 drawQuad(mProgram, "position", 0.5f);
2167
2168 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2169}
2170
2171// Test that texture completeness is updated if texture base level changes.
2172// GLES 3.0.4 section 3.8.13 Texture completeness
2173TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2174{
2175 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2176 {
2177 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2178 // the base level.
2179 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2180 return;
2181 }
2182
2183 glActiveTexture(GL_TEXTURE0);
2184 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2185 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2186
2187 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2188 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2189
2190 // Two levels that are initially unused.
2191 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2192 texDataGreen.data());
2193 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2194 texDataGreen.data());
2195
2196 // One level that is initially used - only this level should affect completeness.
2197 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2198 texDataGreen.data());
2199
2200 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2201 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2202
2203 EXPECT_GL_NO_ERROR();
2204
2205 drawQuad(mProgram, "position", 0.5f);
2206
2207 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2208
2209 // Switch the base level to level 1. The levels within the used range now have inconsistent
2210 // dimensions and the texture should be incomplete.
2211 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2212
2213 EXPECT_GL_NO_ERROR();
2214
2215 drawQuad(mProgram, "position", 0.5f);
2216
2217 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2218}
2219
2220// Test that texture is not complete if base level is greater than max level.
2221// GLES 3.0.4 section 3.8.13 Texture completeness
2222TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2223{
2224 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2225 {
2226 // Intel Windows OpenGL driver crashes if the base level of a non-immutable texture is out
2227 // of range.
2228 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2229 return;
2230 }
2231
2232 glActiveTexture(GL_TEXTURE0);
2233 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2234
2235 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2236 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2237
2238 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2239
2240 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2241 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2242
2243 EXPECT_GL_NO_ERROR();
2244
2245 drawQuad(mProgram, "position", 0.5f);
2246
2247 // Texture should be incomplete.
2248 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2249}
2250
2251// Test that immutable texture base level and max level are clamped.
2252// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2253TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2254{
Olli Etuahoa314b612016-03-10 16:43:00 +02002255 glActiveTexture(GL_TEXTURE0);
2256 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2257
2258 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2259 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2260
2261 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2262
2263 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2264
2265 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2266 // should be clamped to [base_level, levels - 1].
2267 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2268 // In the case of this test, those rules make the effective base level and max level 0.
2269 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2270 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2271
2272 EXPECT_GL_NO_ERROR();
2273
2274 drawQuad(mProgram, "position", 0.5f);
2275
2276 // Texture should be complete.
2277 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2278}
2279
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002280// Test that changing base level works when it affects the format of the texture.
2281TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2282{
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002283 if (IsNVIDIA() && IsOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002284 {
2285 // Observed rendering corruption on NVIDIA OpenGL.
2286 std::cout << "Test skipped on NVIDIA OpenGL." << std::endl;
2287 return;
2288 }
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002289 if (IsIntel() && IsDesktopOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002290 {
2291 // Observed incorrect rendering on Intel OpenGL.
2292 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2293 return;
2294 }
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002295 if (IsAMD() && IsDesktopOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002296 {
2297 // Observed incorrect rendering on AMD OpenGL.
2298 std::cout << "Test skipped on AMD OpenGL." << std::endl;
2299 return;
2300 }
2301
2302 glActiveTexture(GL_TEXTURE0);
2303 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2304 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2305 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2306
2307 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2308 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2309
2310 // RGBA8 level that's initially unused.
2311 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2312 texDataCyan.data());
2313
2314 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2315 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2316
2317 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2318 // format. It reads green channel data from the green and alpha channels of texDataGreen
2319 // (this is a bit hacky but works).
2320 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2321
2322 EXPECT_GL_NO_ERROR();
2323
2324 drawQuad(mProgram, "position", 0.5f);
2325
2326 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2327
2328 // Switch the texture to use the cyan level 0 with the RGBA format.
2329 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2330 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2331
2332 EXPECT_GL_NO_ERROR();
2333
2334 drawQuad(mProgram, "position", 0.5f);
2335
2336 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2337}
2338
Olli Etuahoa314b612016-03-10 16:43:00 +02002339// Test that setting a texture image works when base level is out of range.
2340TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2341{
2342 glActiveTexture(GL_TEXTURE0);
2343 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2344
2345 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2346 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2347
2348 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2349 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2350
2351 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2352
2353 EXPECT_GL_NO_ERROR();
2354
2355 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2356
2357 drawQuad(mProgram, "position", 0.5f);
2358
2359 // Texture should be complete.
2360 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002361}
2362
Jamie Madill2453dbc2015-07-14 11:35:42 -04002363// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG RBA->RGBA8, with 1.0
2364// in the alpha channel. This test covers a bug where redefining array textures with these formats does not work as
2365// expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002366TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002367{
2368 std::vector<GLubyte> pixelData;
2369 for (size_t count = 0; count < 5000; count++)
2370 {
2371 pixelData.push_back(0u);
2372 pixelData.push_back(255u);
2373 pixelData.push_back(0u);
2374 }
2375
2376 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002377 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002378 glUniform1i(mTextureArrayLocation, 0);
2379
2380 // The first draw worked correctly.
2381 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
2382
2383 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2384 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2385 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2386 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002387 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002388 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002389
2390 // The dimension of the respecification must match the original exactly to trigger the bug.
2391 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 +02002392 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002393 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002394
2395 ASSERT_GL_NO_ERROR();
2396}
2397
Olli Etuaho1a679902016-01-14 12:21:47 +02002398// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2399// This test is needed especially to confirm that sampler registers get assigned correctly on
2400// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2401TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2402{
2403 glActiveTexture(GL_TEXTURE0);
2404 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2405 GLubyte texData[4];
2406 texData[0] = 0;
2407 texData[1] = 60;
2408 texData[2] = 0;
2409 texData[3] = 255;
2410 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2411
2412 glActiveTexture(GL_TEXTURE1);
2413 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2414 GLfloat depthTexData[1];
2415 depthTexData[0] = 0.5f;
2416 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2417 depthTexData);
2418
2419 glUseProgram(mProgram);
2420 glUniform1f(mDepthRefUniformLocation, 0.3f);
2421 glUniform1i(mTexture3DUniformLocation, 0);
2422 glUniform1i(mTextureShadowUniformLocation, 1);
2423
2424 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2425 drawQuad(mProgram, "position", 0.5f);
2426 EXPECT_GL_NO_ERROR();
2427 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2428 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2429
2430 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2431 drawQuad(mProgram, "position", 0.5f);
2432 EXPECT_GL_NO_ERROR();
2433 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2434 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2435}
2436
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002437// Test multiple different sampler types in the same shader.
2438// This test makes sure that even if sampler / texture registers get grouped together based on type
2439// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2440// still has the right register index information for each ESSL sampler.
2441// The tested ESSL samplers have the following types in D3D11 HLSL:
2442// sampler2D: Texture2D + SamplerState
2443// samplerCube: TextureCube + SamplerState
2444// sampler2DShadow: Texture2D + SamplerComparisonState
2445// samplerCubeShadow: TextureCube + SamplerComparisonState
2446TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2447{
2448 glActiveTexture(GL_TEXTURE0);
2449 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2450 GLubyte texData[4];
2451 texData[0] = 0;
2452 texData[1] = 0;
2453 texData[2] = 120;
2454 texData[3] = 255;
2455 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2456
2457 glActiveTexture(GL_TEXTURE1);
2458 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2459 texData[0] = 0;
2460 texData[1] = 90;
2461 texData[2] = 0;
2462 texData[3] = 255;
2463 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2464 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2465 texData);
2466
2467 glActiveTexture(GL_TEXTURE2);
2468 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2469 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2470 GLfloat depthTexData[1];
2471 depthTexData[0] = 0.5f;
2472 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2473 depthTexData);
2474
2475 glActiveTexture(GL_TEXTURE3);
2476 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2477 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2478 depthTexData[0] = 0.2f;
2479 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2480 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2481 depthTexData);
2482
2483 EXPECT_GL_NO_ERROR();
2484
2485 glUseProgram(mProgram);
2486 glUniform1f(mDepthRefUniformLocation, 0.3f);
2487 glUniform1i(mTexture2DUniformLocation, 0);
2488 glUniform1i(mTextureCubeUniformLocation, 1);
2489 glUniform1i(mTexture2DShadowUniformLocation, 2);
2490 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2491
2492 drawQuad(mProgram, "position", 0.5f);
2493 EXPECT_GL_NO_ERROR();
2494 // The shader writes:
2495 // <texture 2d color> +
2496 // <cube map color> +
2497 // 0.25 * <comparison result (1.0)> +
2498 // 0.125 * <comparison result (0.0)>
2499 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2500}
2501
Olli Etuahobce743a2016-01-15 17:18:28 +02002502// Test different base levels on textures accessed through the same sampler array.
2503// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2504TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2505{
Jiangd9227752017-10-19 16:23:07 +08002506 if (IsAMD() && IsD3D11())
Olli Etuahobce743a2016-01-15 17:18:28 +02002507 {
Jiangd9227752017-10-19 16:23:07 +08002508 std::cout << "Test skipped on AMD D3D." << std::endl;
Olli Etuahobce743a2016-01-15 17:18:28 +02002509 return;
2510 }
2511 glActiveTexture(GL_TEXTURE0);
2512 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2513 GLsizei size = 64;
2514 for (GLint level = 0; level < 7; ++level)
2515 {
2516 ASSERT_LT(0, size);
2517 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2518 nullptr);
2519 size = size / 2;
2520 }
2521 ASSERT_EQ(0, size);
2522 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2523
2524 glActiveTexture(GL_TEXTURE1);
2525 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2526 size = 128;
2527 for (GLint level = 0; level < 8; ++level)
2528 {
2529 ASSERT_LT(0, size);
2530 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2531 nullptr);
2532 size = size / 2;
2533 }
2534 ASSERT_EQ(0, size);
2535 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2536 EXPECT_GL_NO_ERROR();
2537
2538 glUseProgram(mProgram);
2539 glUniform1i(mTexture0Location, 0);
2540 glUniform1i(mTexture1Location, 1);
2541
2542 drawQuad(mProgram, "position", 0.5f);
2543 EXPECT_GL_NO_ERROR();
2544 // Red channel: width of level 1 of texture A: 32.
2545 // Green channel: width of level 3 of texture B: 16.
2546 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2547}
2548
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002549// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2550// ES 3.0.4 table 3.24
2551TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2552{
2553 glActiveTexture(GL_TEXTURE0);
2554 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2555 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2556 EXPECT_GL_NO_ERROR();
2557
2558 drawQuad(mProgram, "position", 0.5f);
2559
2560 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2561}
2562
2563// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2564// ES 3.0.4 table 3.24
2565TEST_P(Texture2DTestES3, TextureLuminanceImplicitAlpha1)
2566{
2567 glActiveTexture(GL_TEXTURE0);
2568 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2569 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2570 EXPECT_GL_NO_ERROR();
2571
2572 drawQuad(mProgram, "position", 0.5f);
2573
2574 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2575}
2576
2577// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2578// ES 3.0.4 table 3.24
2579TEST_P(Texture2DTestES3, TextureLuminance32ImplicitAlpha1)
2580{
2581 if (extensionEnabled("GL_OES_texture_float"))
2582 {
2583 glActiveTexture(GL_TEXTURE0);
2584 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2585 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, 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
2594// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2595// ES 3.0.4 table 3.24
2596TEST_P(Texture2DTestES3, TextureLuminance16ImplicitAlpha1)
2597{
2598 if (extensionEnabled("GL_OES_texture_half_float"))
2599 {
Yuly Novikovafcec832016-06-21 22:19:51 -04002600 if (IsNVIDIA() && IsOpenGLES())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002601 {
2602 std::cout << "Test skipped on NVIDIA" << std::endl;
2603 return;
2604 }
Yuly Novikovafcec832016-06-21 22:19:51 -04002605 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2606 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2607 {
2608 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2609 return;
2610 }
2611
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002612 glActiveTexture(GL_TEXTURE0);
2613 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2614 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES,
2615 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(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2627{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002628 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002629 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002630 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002631 return;
2632 }
2633 glActiveTexture(GL_TEXTURE0);
2634 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2635 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2636 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2637 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2638 EXPECT_GL_NO_ERROR();
2639
2640 drawQuad(mProgram, "position", 0.5f);
2641
2642 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2643}
2644
2645// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2646// ES 3.0.4 table 3.24
2647TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2648{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002649 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002650 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002651 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002652 return;
2653 }
2654 glActiveTexture(GL_TEXTURE0);
2655 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2656
2657 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2658 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2659 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2660 EXPECT_GL_NO_ERROR();
2661
2662 drawQuad(mProgram, "position", 0.5f);
2663
2664 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2665}
2666
2667// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2668// ES 3.0.4 table 3.24
2669TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2670{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002671 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002672 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002673 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002674 return;
2675 }
2676 glActiveTexture(GL_TEXTURE0);
2677 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2678 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2679 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2680 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2681 EXPECT_GL_NO_ERROR();
2682
2683 drawQuad(mProgram, "position", 0.5f);
2684
2685 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2686}
2687
2688// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2689// ES 3.0.4 table 3.24
2690TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2691{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002692 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002693 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002694 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002695 return;
2696 }
2697 glActiveTexture(GL_TEXTURE0);
2698 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2699 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2700 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2701 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2702 EXPECT_GL_NO_ERROR();
2703
2704 drawQuad(mProgram, "position", 0.5f);
2705
2706 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2707}
2708
2709// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2710// ES 3.0.4 table 3.24
2711TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2712{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002713 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002714 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002715 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002716 return;
2717 }
2718 glActiveTexture(GL_TEXTURE0);
2719 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2720 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2721 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2722 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2723 EXPECT_GL_NO_ERROR();
2724
2725 drawQuad(mProgram, "position", 0.5f);
2726
2727 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2728}
2729
2730// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2731// ES 3.0.4 table 3.24
2732TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2733{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002734 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002735 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002736 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002737 return;
2738 }
2739 glActiveTexture(GL_TEXTURE0);
2740 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2741 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2742 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2743 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2744 EXPECT_GL_NO_ERROR();
2745
2746 drawQuad(mProgram, "position", 0.5f);
2747
2748 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2749}
2750
2751// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2752// ES 3.0.4 table 3.24
2753TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2754{
2755 glActiveTexture(GL_TEXTURE0);
2756 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2757 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2758 EXPECT_GL_NO_ERROR();
2759
2760 drawQuad(mProgram, "position", 0.5f);
2761
2762 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2763}
2764
2765// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2766// ES 3.0.4 table 3.24
2767TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2768{
2769 glActiveTexture(GL_TEXTURE0);
2770 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2771 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2772 nullptr);
2773 EXPECT_GL_NO_ERROR();
2774
2775 drawQuad(mProgram, "position", 0.5f);
2776
2777 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2778}
2779
2780// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2781// ES 3.0.4 table 3.24
2782TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2783{
Jamie Madillbb1db482017-01-10 10:48:32 -05002784 if (IsOSX() && IsIntel() && IsOpenGL())
2785 {
2786 // Seems to fail on OSX 10.12 Intel.
2787 std::cout << "Test skipped on OSX Intel." << std::endl;
2788 return;
2789 }
2790
Yuly Novikov49886892018-01-23 21:18:27 -05002791 // http://anglebug.com/2190
2792 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2793
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002794 glActiveTexture(GL_TEXTURE0);
2795 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2796 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2797 EXPECT_GL_NO_ERROR();
2798
2799 drawQuad(mProgram, "position", 0.5f);
2800
2801 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2802}
2803
2804// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2805// ES 3.0.4 table 3.24
2806TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2807{
Yunchao He14cb42c2018-01-24 14:11:19 +08002808 if (IsOSX() && IsIntel() && IsOpenGL())
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002809 {
Yunchao He14cb42c2018-01-24 14:11:19 +08002810 // Seems to fail on OSX 10.12 Intel.
2811 std::cout << "Test skipped on OSX Intel." << std::endl;
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002812 return;
2813 }
2814
Yuly Novikov49886892018-01-23 21:18:27 -05002815 // http://anglebug.com/2190
2816 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2817
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002818 glActiveTexture(GL_TEXTURE0);
2819 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2820 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2821 EXPECT_GL_NO_ERROR();
2822
2823 drawQuad(mProgram, "position", 0.5f);
2824
2825 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2826}
2827
Olli Etuaho96963162016-03-21 11:54:33 +02002828// Use a sampler in a uniform struct.
2829TEST_P(SamplerInStructTest, SamplerInStruct)
2830{
2831 runSamplerInStructTest();
2832}
2833
2834// Use a sampler in a uniform struct that's passed as a function parameter.
2835TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2836{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002837 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2838 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2839 {
2840 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2841 return;
2842 }
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002843
Olli Etuaho96963162016-03-21 11:54:33 +02002844 runSamplerInStructTest();
2845}
2846
2847// Use a sampler in a uniform struct array with a struct from the array passed as a function
2848// parameter.
2849TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2850{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002851 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2852 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2853 {
2854 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2855 return;
2856 }
Olli Etuaho96963162016-03-21 11:54:33 +02002857 runSamplerInStructTest();
2858}
2859
2860// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2861// parameter.
2862TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2863{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002864 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2865 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2866 {
2867 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2868 return;
2869 }
Olli Etuaho96963162016-03-21 11:54:33 +02002870 runSamplerInStructTest();
2871}
2872
2873// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2874// similarly named uniform.
2875TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2876{
2877 runSamplerInStructTest();
2878}
2879
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002880class TextureLimitsTest : public ANGLETest
2881{
2882 protected:
2883 struct RGBA8
2884 {
2885 uint8_t R, G, B, A;
2886 };
2887
2888 TextureLimitsTest()
2889 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
2890 {
2891 setWindowWidth(128);
2892 setWindowHeight(128);
2893 setConfigRedBits(8);
2894 setConfigGreenBits(8);
2895 setConfigBlueBits(8);
2896 setConfigAlphaBits(8);
2897 }
2898
2899 ~TextureLimitsTest()
2900 {
2901 if (mProgram != 0)
2902 {
2903 glDeleteProgram(mProgram);
2904 mProgram = 0;
2905
2906 if (!mTextures.empty())
2907 {
2908 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
2909 }
2910 }
2911 }
2912
2913 void SetUp() override
2914 {
2915 ANGLETest::SetUp();
2916
2917 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
2918 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
2919 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
2920
2921 ASSERT_GL_NO_ERROR();
2922 }
2923
2924 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
2925 GLint vertexTextureCount,
2926 GLint vertexActiveTextureCount,
2927 const std::string &fragPrefix,
2928 GLint fragmentTextureCount,
2929 GLint fragmentActiveTextureCount)
2930 {
2931 std::stringstream vertexShaderStr;
2932 vertexShaderStr << "attribute vec2 position;\n"
2933 << "varying vec4 color;\n"
2934 << "varying vec2 texCoord;\n";
2935
2936 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
2937 {
2938 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
2939 }
2940
2941 vertexShaderStr << "void main() {\n"
2942 << " gl_Position = vec4(position, 0, 1);\n"
2943 << " texCoord = (position * 0.5) + 0.5;\n"
2944 << " color = vec4(0);\n";
2945
2946 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
2947 {
2948 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
2949 << ", texCoord);\n";
2950 }
2951
2952 vertexShaderStr << "}";
2953
2954 std::stringstream fragmentShaderStr;
2955 fragmentShaderStr << "varying mediump vec4 color;\n"
2956 << "varying mediump vec2 texCoord;\n";
2957
2958 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
2959 {
2960 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
2961 }
2962
2963 fragmentShaderStr << "void main() {\n"
2964 << " gl_FragColor = color;\n";
2965
2966 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
2967 {
2968 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
2969 << ", texCoord);\n";
2970 }
2971
2972 fragmentShaderStr << "}";
2973
2974 const std::string &vertexShaderSource = vertexShaderStr.str();
2975 const std::string &fragmentShaderSource = fragmentShaderStr.str();
2976
2977 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
2978 }
2979
2980 RGBA8 getPixel(GLint texIndex)
2981 {
2982 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
2983 0, 255u};
2984 return pixel;
2985 }
2986
2987 void initTextures(GLint tex2DCount, GLint texCubeCount)
2988 {
2989 GLint totalCount = tex2DCount + texCubeCount;
2990 mTextures.assign(totalCount, 0);
2991 glGenTextures(totalCount, &mTextures[0]);
2992 ASSERT_GL_NO_ERROR();
2993
2994 std::vector<RGBA8> texData(16 * 16);
2995
2996 GLint texIndex = 0;
2997 for (; texIndex < tex2DCount; ++texIndex)
2998 {
2999 texData.assign(texData.size(), getPixel(texIndex));
3000 glActiveTexture(GL_TEXTURE0 + texIndex);
3001 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3002 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3003 &texData[0]);
3004 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3005 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3006 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3007 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3008 }
3009
3010 ASSERT_GL_NO_ERROR();
3011
3012 for (; texIndex < texCubeCount; ++texIndex)
3013 {
3014 texData.assign(texData.size(), getPixel(texIndex));
3015 glActiveTexture(GL_TEXTURE0 + texIndex);
3016 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3017 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3018 GL_UNSIGNED_BYTE, &texData[0]);
3019 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3020 GL_UNSIGNED_BYTE, &texData[0]);
3021 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3022 GL_UNSIGNED_BYTE, &texData[0]);
3023 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3024 GL_UNSIGNED_BYTE, &texData[0]);
3025 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3026 GL_UNSIGNED_BYTE, &texData[0]);
3027 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3028 GL_UNSIGNED_BYTE, &texData[0]);
3029 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3030 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3031 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3032 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3033 }
3034
3035 ASSERT_GL_NO_ERROR();
3036 }
3037
3038 void testWithTextures(GLint vertexTextureCount,
3039 const std::string &vertexTexturePrefix,
3040 GLint fragmentTextureCount,
3041 const std::string &fragmentTexturePrefix)
3042 {
3043 // Generate textures
3044 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3045
3046 glUseProgram(mProgram);
3047 RGBA8 expectedSum = {0};
3048 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3049 {
3050 std::stringstream uniformNameStr;
3051 uniformNameStr << vertexTexturePrefix << texIndex;
3052 const std::string &uniformName = uniformNameStr.str();
3053 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
3054 ASSERT_NE(-1, location);
3055
3056 glUniform1i(location, texIndex);
3057 RGBA8 contribution = getPixel(texIndex);
3058 expectedSum.R += contribution.R;
3059 expectedSum.G += contribution.G;
3060 }
3061
3062 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3063 {
3064 std::stringstream uniformNameStr;
3065 uniformNameStr << fragmentTexturePrefix << texIndex;
3066 const std::string &uniformName = uniformNameStr.str();
3067 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
3068 ASSERT_NE(-1, location);
3069
3070 glUniform1i(location, texIndex + vertexTextureCount);
3071 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3072 expectedSum.R += contribution.R;
3073 expectedSum.G += contribution.G;
3074 }
3075
3076 ASSERT_GE(256u, expectedSum.G);
3077
3078 drawQuad(mProgram, "position", 0.5f);
3079 ASSERT_GL_NO_ERROR();
3080 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3081 }
3082
3083 GLuint mProgram;
3084 std::vector<GLuint> mTextures;
3085 GLint mMaxVertexTextures;
3086 GLint mMaxFragmentTextures;
3087 GLint mMaxCombinedTextures;
3088};
3089
3090// Test rendering with the maximum vertex texture units.
3091TEST_P(TextureLimitsTest, MaxVertexTextures)
3092{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003093 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003094 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003095 {
3096 std::cout << "Test skipped on Intel." << std::endl;
3097 return;
3098 }
3099
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003100 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3101 ASSERT_NE(0u, mProgram);
3102 ASSERT_GL_NO_ERROR();
3103
3104 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3105}
3106
3107// Test rendering with the maximum fragment texture units.
3108TEST_P(TextureLimitsTest, MaxFragmentTextures)
3109{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003110 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003111 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003112 {
3113 std::cout << "Test skipped on Intel." << std::endl;
3114 return;
3115 }
3116
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003117 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3118 ASSERT_NE(0u, mProgram);
3119 ASSERT_GL_NO_ERROR();
3120
3121 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3122}
3123
3124// Test rendering with maximum combined texture units.
3125TEST_P(TextureLimitsTest, MaxCombinedTextures)
3126{
Jamie Madill412f17d2015-09-25 08:43:54 -04003127 // TODO(jmadill): Investigate workaround.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003128 if (IsIntel() && GetParam() == ES2_OPENGL())
Jamie Madill412f17d2015-09-25 08:43:54 -04003129 {
3130 std::cout << "Test skipped on Intel." << std::endl;
3131 return;
3132 }
3133
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003134 GLint vertexTextures = mMaxVertexTextures;
3135
3136 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3137 {
3138 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3139 }
3140
3141 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3142 mMaxFragmentTextures, mMaxFragmentTextures);
3143 ASSERT_NE(0u, mProgram);
3144 ASSERT_GL_NO_ERROR();
3145
3146 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3147}
3148
3149// Negative test for exceeding the number of vertex textures
3150TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3151{
3152 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3153 0);
3154 ASSERT_EQ(0u, mProgram);
3155}
3156
3157// Negative test for exceeding the number of fragment textures
3158TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3159{
3160 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3161 mMaxFragmentTextures + 1);
3162 ASSERT_EQ(0u, mProgram);
3163}
3164
3165// Test active vertex textures under the limit, but excessive textures specified.
3166TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3167{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003168 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003169 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003170 {
3171 std::cout << "Test skipped on Intel." << std::endl;
3172 return;
3173 }
3174
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003175 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3176 ASSERT_NE(0u, mProgram);
3177 ASSERT_GL_NO_ERROR();
3178
3179 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3180}
3181
3182// Test active fragment textures under the limit, but excessive textures specified.
3183TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3184{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003185 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003186 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003187 {
3188 std::cout << "Test skipped on Intel." << std::endl;
3189 return;
3190 }
3191
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003192 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3193 mMaxFragmentTextures);
3194 ASSERT_NE(0u, mProgram);
3195 ASSERT_GL_NO_ERROR();
3196
3197 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3198}
3199
3200// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003201// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003202TEST_P(TextureLimitsTest, TextureTypeConflict)
3203{
3204 const std::string &vertexShader =
3205 "attribute vec2 position;\n"
3206 "varying float color;\n"
3207 "uniform sampler2D tex2D;\n"
3208 "uniform samplerCube texCube;\n"
3209 "void main() {\n"
3210 " gl_Position = vec4(position, 0, 1);\n"
3211 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3212 " color = texture2D(tex2D, texCoord).x;\n"
3213 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3214 "}";
3215 const std::string &fragmentShader =
3216 "varying mediump float color;\n"
3217 "void main() {\n"
3218 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3219 "}";
3220
3221 mProgram = CompileProgram(vertexShader, fragmentShader);
3222 ASSERT_NE(0u, mProgram);
3223
3224 initTextures(1, 0);
3225
3226 glUseProgram(mProgram);
3227 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3228 ASSERT_NE(-1, tex2DLocation);
3229 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3230 ASSERT_NE(-1, texCubeLocation);
3231
3232 glUniform1i(tex2DLocation, 0);
3233 glUniform1i(texCubeLocation, 0);
3234 ASSERT_GL_NO_ERROR();
3235
3236 drawQuad(mProgram, "position", 0.5f);
3237 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3238}
3239
Vincent Lang25ab4512016-05-13 18:13:59 +02003240class Texture2DNorm16TestES3 : public Texture2DTestES3
3241{
3242 protected:
3243 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3244
3245 void SetUp() override
3246 {
3247 Texture2DTestES3::SetUp();
3248
3249 glActiveTexture(GL_TEXTURE0);
3250 glGenTextures(3, mTextures);
3251 glGenFramebuffers(1, &mFBO);
3252 glGenRenderbuffers(1, &mRenderbuffer);
3253
3254 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3255 {
3256 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3257 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3258 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3259 }
3260
3261 glBindTexture(GL_TEXTURE_2D, 0);
3262
3263 ASSERT_GL_NO_ERROR();
3264 }
3265
3266 void TearDown() override
3267 {
3268 glDeleteTextures(3, mTextures);
3269 glDeleteFramebuffers(1, &mFBO);
3270 glDeleteRenderbuffers(1, &mRenderbuffer);
3271
3272 Texture2DTestES3::TearDown();
3273 }
3274
3275 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3276 {
Geoff Langf607c602016-09-21 11:46:48 -04003277 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3278 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003279
3280 setUpProgram();
3281
3282 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3283 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3284 0);
3285
3286 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3287 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3288
3289 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003290 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003291
3292 EXPECT_GL_NO_ERROR();
3293
3294 drawQuad(mProgram, "position", 0.5f);
3295
Geoff Langf607c602016-09-21 11:46:48 -04003296 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003297
Geoff Langf607c602016-09-21 11:46:48 -04003298 EXPECT_PIXEL_COLOR_EQ(
3299 0, 0, SliceFormatColor(
3300 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003301
3302 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3303
3304 ASSERT_GL_NO_ERROR();
3305 }
3306
3307 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3308 {
3309 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003310 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003311
3312 setUpProgram();
3313
3314 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3315 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3316
3317 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3318 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3319 0);
3320
3321 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003322 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003323
3324 EXPECT_GL_NO_ERROR();
3325
3326 drawQuad(mProgram, "position", 0.5f);
3327
Geoff Langf607c602016-09-21 11:46:48 -04003328 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
3329 EXPECT_PIXEL_COLOR_EQ(
3330 0, 0, SliceFormatColor(
3331 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003332
3333 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3334 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3335 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3336 mRenderbuffer);
3337 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3338 EXPECT_GL_NO_ERROR();
3339
3340 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3341 glClear(GL_COLOR_BUFFER_BIT);
3342
3343 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3344
Geoff Langf607c602016-09-21 11:46:48 -04003345 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003346
3347 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3348
3349 ASSERT_GL_NO_ERROR();
3350 }
3351
3352 GLuint mTextures[3];
3353 GLuint mFBO;
3354 GLuint mRenderbuffer;
3355};
3356
3357// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3358TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3359{
3360 if (!extensionEnabled("GL_EXT_texture_norm16"))
3361 {
3362 std::cout << "Test skipped due to missing GL_EXT_texture_norm16." << std::endl;
3363 return;
3364 }
3365
3366 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3367 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3368 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3369 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3370 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3371 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3372 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3373 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3374
3375 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3376 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3377 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3378}
3379
Olli Etuaho95faa232016-06-07 14:01:53 -07003380// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3381// GLES 3.0.4 section 3.8.3.
3382TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3383{
Corentin Wallezc7f59d02016-06-20 10:12:08 -04003384 if (IsIntel() && IsDesktopOpenGL())
Olli Etuaho95faa232016-06-07 14:01:53 -07003385 {
3386 std::cout << "Test skipped on Intel OpenGL." << std::endl;
3387 return;
3388 }
Yuly Novikov3c754192016-06-27 19:36:41 -04003389 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1429 is fixed
3390 if (IsAndroid() && IsAdreno() && IsOpenGLES())
3391 {
3392 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
3393 return;
3394 }
Olli Etuaho95faa232016-06-07 14:01:53 -07003395
3396 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3397 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3398 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3399 ASSERT_GL_NO_ERROR();
3400
3401 // SKIP_IMAGES should not have an effect on uploading 2D textures
3402 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3403 ASSERT_GL_NO_ERROR();
3404
3405 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3406
3407 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3408 pixelsGreen.data());
3409 ASSERT_GL_NO_ERROR();
3410
3411 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3412 pixelsGreen.data());
3413 ASSERT_GL_NO_ERROR();
3414
3415 glUseProgram(mProgram);
3416 drawQuad(mProgram, "position", 0.5f);
3417 ASSERT_GL_NO_ERROR();
3418
3419 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3420}
3421
Olli Etuaho989cac32016-06-08 16:18:49 -07003422// Test that skip defined in unpack parameters is taken into account when determining whether
3423// unpacking source extends outside unpack buffer bounds.
3424TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3425{
3426 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3427 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3428 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3429 ASSERT_GL_NO_ERROR();
3430
3431 GLBuffer buf;
3432 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3433 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3434 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3435 GL_DYNAMIC_COPY);
3436 ASSERT_GL_NO_ERROR();
3437
3438 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3439 ASSERT_GL_NO_ERROR();
3440
3441 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3442 ASSERT_GL_NO_ERROR();
3443
3444 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3445 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3446
3447 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3448 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3449 ASSERT_GL_NO_ERROR();
3450
3451 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3452 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3453}
3454
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003455// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3456TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3457{
3458 if (IsD3D11())
3459 {
3460 std::cout << "Test skipped on D3D." << std::endl;
3461 return;
3462 }
3463 if (IsOSX() && IsAMD())
3464 {
3465 // Incorrect rendering results seen on OSX AMD.
3466 std::cout << "Test skipped on OSX AMD." << std::endl;
3467 return;
3468 }
3469
3470 const GLuint width = 8u;
3471 const GLuint height = 8u;
3472 const GLuint unpackRowLength = 5u;
3473 const GLuint unpackSkipPixels = 1u;
3474
3475 setWindowWidth(width);
3476 setWindowHeight(height);
3477
3478 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3479 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3480 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3481 ASSERT_GL_NO_ERROR();
3482
3483 GLBuffer buf;
3484 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3485 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3486 GLColor::green);
3487
3488 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3489 {
3490 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3491 }
3492
3493 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3494 GL_DYNAMIC_COPY);
3495 ASSERT_GL_NO_ERROR();
3496
3497 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3498 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3499 ASSERT_GL_NO_ERROR();
3500
3501 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3502 ASSERT_GL_NO_ERROR();
3503
3504 glUseProgram(mProgram);
3505 drawQuad(mProgram, "position", 0.5f);
3506 ASSERT_GL_NO_ERROR();
3507
3508 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3509 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3510 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3511 actual.data());
3512 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3513 EXPECT_EQ(expected, actual);
3514}
3515
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003516template <typename T>
3517T UNorm(double value)
3518{
3519 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3520}
3521
3522// Test rendering a depth texture with mipmaps.
3523TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3524{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003525 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3526 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
3527 // http://anglebugs.com/1706
3528 if (IsIntel() && IsWindows())
Corentin Walleze731d8a2016-09-07 10:56:25 -04003529 {
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003530 std::cout << "Test skipped on Win Intel." << std::endl;
Corentin Walleze731d8a2016-09-07 10:56:25 -04003531 return;
3532 }
3533
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003534 const int size = getWindowWidth();
3535
3536 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003537 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003538
3539 glActiveTexture(GL_TEXTURE0);
3540 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3541 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3542 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3543 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3544 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3545 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3546 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3547 ASSERT_GL_NO_ERROR();
3548
3549 glUseProgram(mProgram);
3550 glUniform1i(mTexture2DUniformLocation, 0);
3551
3552 std::vector<unsigned char> expected;
3553
3554 for (int level = 0; level < levels; ++level)
3555 {
3556 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3557 expected.push_back(UNorm<unsigned char>(value));
3558
3559 int levelDim = dim(level);
3560
3561 ASSERT_GT(levelDim, 0);
3562
3563 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3564 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3565 GL_UNSIGNED_INT, initData.data());
3566 }
3567 ASSERT_GL_NO_ERROR();
3568
3569 for (int level = 0; level < levels; ++level)
3570 {
3571 glViewport(0, 0, dim(level), dim(level));
3572 drawQuad(mProgram, "position", 0.5f);
3573 GLColor actual = ReadColor(0, 0);
3574 EXPECT_NEAR(expected[level], actual.R, 10u);
3575 }
3576
3577 ASSERT_GL_NO_ERROR();
3578}
3579
Jamie Madill7ffdda92016-09-08 13:26:51 -04003580// Tests unpacking into the unsized GL_ALPHA format.
3581TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3582{
3583 // TODO(jmadill): Figure out why this fails on OSX.
3584 ANGLE_SKIP_TEST_IF(IsOSX());
3585
3586 // Initialize the texure.
3587 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3588 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3589 GL_UNSIGNED_BYTE, nullptr);
3590 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3591 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3592
3593 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3594
3595 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04003596 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04003597 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3598 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3599 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
3600 GL_STATIC_DRAW);
3601
3602 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
3603 GL_UNSIGNED_BYTE, nullptr);
3604
3605 // Clear to a weird color to make sure we're drawing something.
3606 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
3607 glClear(GL_COLOR_BUFFER_BIT);
3608
3609 // Draw with the alpha texture and verify.
3610 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04003611
3612 ASSERT_GL_NO_ERROR();
3613 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
3614}
3615
Jamie Madill2e600342016-09-19 13:56:40 -04003616// Ensure stale unpack data doesn't propagate in D3D11.
3617TEST_P(Texture2DTestES3, StaleUnpackData)
3618{
3619 // Init unpack buffer.
3620 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
3621 std::vector<GLColor> pixels(pixelCount, GLColor::red);
3622
3623 GLBuffer unpackBuffer;
3624 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3625 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3626 GLsizei bufferSize = pixelCount * sizeof(GLColor);
3627 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
3628
3629 // Create from unpack buffer.
3630 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3631 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
3632 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3633 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3634 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3635
3636 drawQuad(mProgram, "position", 0.5f);
3637
3638 ASSERT_GL_NO_ERROR();
3639 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3640
3641 // Fill unpack with green, recreating buffer.
3642 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
3643 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
3644 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
3645
3646 // Reinit texture with green.
3647 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
3648 GL_UNSIGNED_BYTE, nullptr);
3649
3650 drawQuad(mProgram, "position", 0.5f);
3651
3652 ASSERT_GL_NO_ERROR();
3653 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3654}
3655
Geoff Langfb7685f2017-11-13 11:44:11 -05003656// Ensure that texture parameters passed as floats that are converted to ints are rounded before
3657// validating they are less than 0.
3658TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
3659{
3660 GLTexture texture;
3661 glBindTexture(GL_TEXTURE_2D, texture);
3662
3663 // Use a negative number that will round to zero when converted to an integer
3664 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
3665 // "Validation of values performed by state-setting commands is performed after conversion,
3666 // unless specified otherwise for a specific command."
3667 GLfloat param = -7.30157126e-07f;
3668 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
3669 EXPECT_GL_NO_ERROR();
3670
3671 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
3672 EXPECT_GL_NO_ERROR();
3673}
3674
Jamie Madillf097e232016-11-05 00:44:15 -04003675// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
3676// being properly checked, and the texture storage of the previous texture format was persisting.
3677// This would result in an ASSERT in debug and incorrect rendering in release.
3678// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
3679TEST_P(Texture3DTestES3, FormatRedefinitionBug)
3680{
3681 GLTexture tex;
3682 glBindTexture(GL_TEXTURE_3D, tex.get());
3683 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3684
3685 GLFramebuffer framebuffer;
3686 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3687 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
3688
3689 glCheckFramebufferStatus(GL_FRAMEBUFFER);
3690
3691 std::vector<uint8_t> pixelData(100, 0);
3692
3693 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
3694 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
3695 pixelData.data());
3696
3697 ASSERT_GL_NO_ERROR();
3698}
3699
Corentin Wallezd2627992017-04-28 17:17:03 -04003700// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
3701TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
3702{
3703 // 2D tests
3704 {
3705 GLTexture tex;
3706 glBindTexture(GL_TEXTURE_2D, tex.get());
3707
3708 GLBuffer pbo;
3709 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3710
3711 // Test OOB
3712 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
3713 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3714 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3715
3716 // Test OOB
3717 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
3718 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3719 ASSERT_GL_NO_ERROR();
3720 }
3721
3722 // 3D tests
3723 {
3724 GLTexture tex;
3725 glBindTexture(GL_TEXTURE_3D, tex.get());
3726
3727 GLBuffer pbo;
3728 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3729
3730 // Test OOB
3731 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
3732 GL_STATIC_DRAW);
3733 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3734 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3735
3736 // Test OOB
3737 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
3738 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3739 ASSERT_GL_NO_ERROR();
3740 }
3741}
3742
Jamie Madill3ed60422017-09-07 11:32:52 -04003743// Tests behaviour with a single texture and multiple sampler objects.
3744TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
3745{
3746 GLint maxTextureUnits = 0;
3747 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
3748 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
3749
3750 constexpr int kSize = 16;
3751
3752 // Make a single-level texture, fill it with red.
3753 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
3754 GLTexture tex;
3755 glBindTexture(GL_TEXTURE_2D, tex);
3756 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3757 redColors.data());
3758 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3759 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3760
3761 // Simple sanity check.
3762 draw2DTexturedQuad(0.5f, 1.0f, true);
3763 ASSERT_GL_NO_ERROR();
3764 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3765
3766 // Bind texture to unit 1 with a sampler object making it incomplete.
3767 GLSampler sampler;
3768 glBindSampler(0, sampler);
3769 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3770 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3771
3772 // Make a mipmap texture, fill it with blue.
3773 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
3774 GLTexture mipmapTex;
3775 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3776 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3777 blueColors.data());
3778 glGenerateMipmap(GL_TEXTURE_2D);
3779
3780 // Draw with the sampler, expect blue.
3781 draw2DTexturedQuad(0.5f, 1.0f, true);
3782 ASSERT_GL_NO_ERROR();
3783 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
3784
3785 // Simple multitexturing program.
3786 const std::string vs =
3787 "#version 300 es\n"
3788 "in vec2 position;\n"
3789 "out vec2 texCoord;\n"
3790 "void main()\n"
3791 "{\n"
3792 " gl_Position = vec4(position, 0, 1);\n"
3793 " texCoord = position * 0.5 + vec2(0.5);\n"
3794 "}";
3795 const std::string fs =
3796 "#version 300 es\n"
3797 "precision mediump float;\n"
3798 "in vec2 texCoord;\n"
3799 "uniform sampler2D tex1;\n"
3800 "uniform sampler2D tex2;\n"
3801 "uniform sampler2D tex3;\n"
3802 "uniform sampler2D tex4;\n"
3803 "out vec4 color;\n"
3804 "void main()\n"
3805 "{\n"
3806 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
3807 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
3808 "}";
3809
3810 ANGLE_GL_PROGRAM(program, vs, fs);
3811
3812 std::array<GLint, 4> texLocations = {
3813 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
3814 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
3815 for (GLint location : texLocations)
3816 {
3817 ASSERT_NE(-1, location);
3818 }
3819
3820 // Init the uniform data.
3821 glUseProgram(program);
3822 for (GLint location = 0; location < 4; ++location)
3823 {
3824 glUniform1i(texLocations[location], location);
3825 }
3826
3827 // Initialize four samplers
3828 GLSampler samplers[4];
3829
3830 // 0: non-mipped.
3831 glBindSampler(0, samplers[0]);
3832 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3833 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3834
3835 // 1: mipped.
3836 glBindSampler(1, samplers[1]);
3837 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3838 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3839
3840 // 2: non-mipped.
3841 glBindSampler(2, samplers[2]);
3842 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3843 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3844
3845 // 3: mipped.
3846 glBindSampler(3, samplers[3]);
3847 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3848 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3849
3850 // Bind two blue mipped textures and two single layer textures, should all draw.
3851 glActiveTexture(GL_TEXTURE0);
3852 glBindTexture(GL_TEXTURE_2D, tex);
3853
3854 glActiveTexture(GL_TEXTURE1);
3855 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3856
3857 glActiveTexture(GL_TEXTURE2);
3858 glBindTexture(GL_TEXTURE_2D, tex);
3859
3860 glActiveTexture(GL_TEXTURE3);
3861 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3862
3863 ASSERT_GL_NO_ERROR();
3864
3865 drawQuad(program, "position", 0.5f);
3866 ASSERT_GL_NO_ERROR();
3867 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
3868
3869 // Bind four single layer textures, two should be incomplete.
3870 glActiveTexture(GL_TEXTURE1);
3871 glBindTexture(GL_TEXTURE_2D, tex);
3872
3873 glActiveTexture(GL_TEXTURE3);
3874 glBindTexture(GL_TEXTURE_2D, tex);
3875
3876 drawQuad(program, "position", 0.5f);
3877 ASSERT_GL_NO_ERROR();
3878 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
3879}
3880
Martin Radev7e2c0d32017-09-15 14:25:42 +03003881// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
3882// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
3883// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
3884// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
3885// samples the cubemap using a direction vector (1,1,1).
3886TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
3887{
3888 if (IsOSX())
3889 {
3890 // Check http://anglebug.com/2155.
3891 std::cout << "Test skipped on OSX." << std::endl;
3892 return;
3893 }
3894 const std::string vs =
3895 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003896 precision mediump float;
3897 in vec3 pos;
3898 void main() {
3899 gl_Position = vec4(pos, 1.0);
3900 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003901
3902 const std::string fs =
3903 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003904 precision mediump float;
3905 out vec4 color;
3906 uniform samplerCube uTex;
3907 void main(){
3908 color = texture(uTex, vec3(1.0));
3909 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003910 ANGLE_GL_PROGRAM(program, vs, fs);
3911 glUseProgram(program);
3912
3913 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
3914 glActiveTexture(GL_TEXTURE0);
3915
3916 GLTexture cubeTex;
3917 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
3918
3919 const int kFaceWidth = 1;
3920 const int kFaceHeight = 1;
3921 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
3922 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3923 GL_UNSIGNED_BYTE, texData.data());
3924 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3925 GL_UNSIGNED_BYTE, texData.data());
3926 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3927 GL_UNSIGNED_BYTE, texData.data());
3928 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3929 GL_UNSIGNED_BYTE, texData.data());
3930 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3931 GL_UNSIGNED_BYTE, texData.data());
3932 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3933 GL_UNSIGNED_BYTE, texData.data());
3934 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3935 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3936 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
3937 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
3938 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
3939 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
3940
3941 drawQuad(program, "pos", 0.5f, 1.0f, true);
3942 ASSERT_GL_NO_ERROR();
3943
3944 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
3945}
3946
Jamie Madillfa05f602015-05-07 13:47:11 -04003947// 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 +02003948// TODO(oetuaho): Enable all below tests on OpenGL. Requires a fix for ANGLE bug 1278.
Geoff Lange0cc2a42016-01-20 10:58:17 -05003949ANGLE_INSTANTIATE_TEST(Texture2DTest,
3950 ES2_D3D9(),
3951 ES2_D3D11(),
3952 ES2_D3D11_FL9_3(),
3953 ES2_OPENGL(),
3954 ES2_OPENGLES());
3955ANGLE_INSTANTIATE_TEST(TextureCubeTest,
3956 ES2_D3D9(),
3957 ES2_D3D11(),
Geoff Langf7480ad2017-10-24 11:46:02 -04003958 ES2_D3D11_FL10_0(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003959 ES2_D3D11_FL9_3(),
3960 ES2_OPENGL(),
3961 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003962ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
3963 ES2_D3D9(),
3964 ES2_D3D11(),
3965 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003966 ES2_OPENGL(),
3967 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003968ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
3969 ES2_D3D9(),
3970 ES2_D3D11(),
3971 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003972 ES2_OPENGL(),
3973 ES2_OPENGLES());
3974ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
3975 ES2_D3D9(),
3976 ES2_D3D11(),
3977 ES2_D3D11_FL9_3(),
3978 ES2_OPENGL(),
3979 ES2_OPENGLES());
3980ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
3981 ES2_D3D9(),
3982 ES2_D3D11(),
3983 ES2_D3D11_FL9_3(),
3984 ES2_OPENGL(),
3985 ES2_OPENGLES());
3986ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02003987ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003988ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3989ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
3990 ES3_D3D11(),
3991 ES3_OPENGL(),
3992 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003993ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
3994 ES3_D3D11(),
3995 ES3_OPENGL(),
3996 ES3_OPENGLES());
3997ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3998ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02003999ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02004000ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
4001 ES2_D3D11(),
4002 ES2_D3D11_FL9_3(),
4003 ES2_D3D9(),
4004 ES2_OPENGL(),
4005 ES2_OPENGLES());
4006ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
4007 ES2_D3D11(),
4008 ES2_D3D11_FL9_3(),
4009 ES2_D3D9(),
4010 ES2_OPENGL(),
4011 ES2_OPENGLES());
4012ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
4013 ES2_D3D11(),
4014 ES2_D3D11_FL9_3(),
4015 ES2_D3D9(),
4016 ES2_OPENGL(),
4017 ES2_OPENGLES());
4018ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
4019 ES2_D3D11(),
4020 ES2_D3D11_FL9_3(),
4021 ES2_D3D9(),
4022 ES2_OPENGL(),
4023 ES2_OPENGLES());
4024ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
4025 ES2_D3D11(),
4026 ES2_D3D11_FL9_3(),
4027 ES2_D3D9(),
4028 ES2_OPENGL(),
4029 ES2_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004030ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES());
Vincent Lang25ab4512016-05-13 18:13:59 +02004031ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03004032ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04004033
Jamie Madill7ffdda92016-09-08 13:26:51 -04004034} // anonymous namespace