blob: a4b16fb0e6c8ef19366dd45144f3bce33ad4c224 [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{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001563 if (IsIntel() && IsLinux())
1564 {
1565 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1566 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1567 return;
1568 }
1569
Jamie Madillbc393df2015-01-29 13:46:07 -05001570 testFloatCopySubImage(3, 1);
1571}
1572
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001573TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001574{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001575 if (IsIntel() && IsLinux())
1576 {
1577 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1578 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1579 return;
1580 }
1581
Jamie Madillbc393df2015-01-29 13:46:07 -05001582 testFloatCopySubImage(3, 2);
1583}
1584
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001585TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001586{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001587 if (IsIntel() && IsLinux())
1588 {
1589 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1590 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1591 return;
1592 }
1593
Austin Kinrossd544cc92016-01-11 15:26:42 -08001594 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001595 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001596 {
1597 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1598 return;
1599 }
1600
Jamie Madillbc393df2015-01-29 13:46:07 -05001601 testFloatCopySubImage(3, 3);
1602}
1603
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001604TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001605{
1606 testFloatCopySubImage(4, 1);
1607}
1608
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001609TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001610{
1611 testFloatCopySubImage(4, 2);
1612}
1613
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001614TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001615{
Austin Kinrossd544cc92016-01-11 15:26:42 -08001616 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001617 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001618 {
1619 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1620 return;
1621 }
1622
Jamie Madillbc393df2015-01-29 13:46:07 -05001623 testFloatCopySubImage(4, 3);
1624}
1625
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001626TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001627{
Austin Kinrossd544cc92016-01-11 15:26:42 -08001628 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001629 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001630 {
1631 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1632 return;
1633 }
1634
Jamie Madillbc393df2015-01-29 13:46:07 -05001635 testFloatCopySubImage(4, 4);
1636}
Austin Kinross07285142015-03-26 11:36:16 -07001637
1638// Port of https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1639// 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 +02001640TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001641{
1642 const int npotTexSize = 5;
1643 const int potTexSize = 4; // Should be less than npotTexSize
1644 GLuint tex2D;
1645
1646 if (extensionEnabled("GL_OES_texture_npot"))
1647 {
1648 // This test isn't applicable if texture_npot is enabled
1649 return;
1650 }
1651
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001652 setUpProgram();
1653
Austin Kinross07285142015-03-26 11:36:16 -07001654 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1655
Austin Kinross5faa15b2016-01-11 13:32:48 -08001656 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1657 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1658
Austin Kinross07285142015-03-26 11:36:16 -07001659 glActiveTexture(GL_TEXTURE0);
1660 glGenTextures(1, &tex2D);
1661 glBindTexture(GL_TEXTURE_2D, tex2D);
1662
1663 std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize);
1664 for (size_t pixelId = 0; pixelId < npotTexSize * npotTexSize; ++pixelId)
1665 {
1666 pixels[pixelId] = 64;
1667 }
1668
1669 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1670 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1671
1672 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
1673 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1674 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1675
1676 // Check that an NPOT texture on level 0 succeeds
1677 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1678 EXPECT_GL_NO_ERROR();
1679
1680 // Check that generateMipmap fails on NPOT
1681 glGenerateMipmap(GL_TEXTURE_2D);
1682 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1683
1684 // Check that nothing is drawn if filtering is not correct for NPOT
1685 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1686 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1687 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1688 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
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, 255);
1692
1693 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1694 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1695 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1696 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1697 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001698 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001699 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1700
1701 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1702 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1703 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001704 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001705 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1706
1707 // Check that glTexImage2D for POT texture succeeds
1708 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1709 EXPECT_GL_NO_ERROR();
1710
1711 // Check that generateMipmap for an POT texture succeeds
1712 glGenerateMipmap(GL_TEXTURE_2D);
1713 EXPECT_GL_NO_ERROR();
1714
1715 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1716 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1717 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1718 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1719 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1720 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001721 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001722 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1723 EXPECT_GL_NO_ERROR();
1724}
Jamie Madillfa05f602015-05-07 13:47:11 -04001725
Austin Kinross08528e12015-10-07 16:24:40 -07001726// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1727// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001728TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001729{
1730 glActiveTexture(GL_TEXTURE0);
1731 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1732
1733 // Create an 8x8 (i.e. power-of-two) texture.
1734 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1735 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1736 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1737 glGenerateMipmap(GL_TEXTURE_2D);
1738
1739 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1740 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001741 std::array<GLColor, 3 * 3> data;
1742 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001743
1744 EXPECT_GL_NO_ERROR();
1745}
1746
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001747// Test to check that texture completeness is determined correctly when the texture base level is
1748// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1749TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1750{
1751 glActiveTexture(GL_TEXTURE0);
1752 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001753
1754 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1755 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1756 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1757 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1758 texDataGreen.data());
1759 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1760 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001761 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1762 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1763 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1764
1765 EXPECT_GL_NO_ERROR();
1766
1767 drawQuad(mProgram, "position", 0.5f);
1768
Olli Etuahoa314b612016-03-10 16:43:00 +02001769 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1770}
1771
1772// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1773// have images defined.
1774TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1775{
1776 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1777 {
1778 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1779 std::cout << "Test skipped on AMD OpenGL." << std::endl;
1780 return;
1781 }
1782 if (IsOSX())
1783 {
1784 // Observed incorrect rendering on OSX.
1785 std::cout << "Test skipped on OSX." << std::endl;
1786 return;
1787 }
1788 glActiveTexture(GL_TEXTURE0);
1789 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1790 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1791 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1792 texDataGreen.data());
1793 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1794 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1795 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1796 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1797
1798 EXPECT_GL_NO_ERROR();
1799
1800 drawQuad(mProgram, "position", 0.5f);
1801
1802 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1803}
1804
Olli Etuahoe8528d82016-05-16 17:50:52 +03001805// Test that drawing works correctly when level 0 is undefined and base level is 1.
1806TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1807{
1808 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1809 {
1810 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1811 std::cout << "Test skipped on AMD OpenGL." << std::endl;
1812 return;
1813 }
1814 if (IsOSX())
1815 {
1816 // Observed incorrect rendering on OSX.
1817 std::cout << "Test skipped on OSX." << std::endl;
1818 return;
1819 }
1820 glActiveTexture(GL_TEXTURE0);
1821 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1822 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1823 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1824 texDataGreen.data());
1825 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1826 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1827 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1828 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1829
1830 EXPECT_GL_NO_ERROR();
1831
1832 // Texture is incomplete.
1833 drawQuad(mProgram, "position", 0.5f);
1834 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1835
1836 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1837 texDataGreen.data());
1838
1839 // Texture is now complete.
1840 drawQuad(mProgram, "position", 0.5f);
1841 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1842}
1843
Olli Etuahoa314b612016-03-10 16:43:00 +02001844// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1845// dimensions that don't fit the images inside the range.
1846// GLES 3.0.4 section 3.8.13 Texture completeness
1847TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1848{
1849 if (IsOSX())
1850 {
1851 // Observed incorrect rendering on OSX.
1852 std::cout << "Test skipped on OSX." << std::endl;
1853 return;
1854 }
1855 glActiveTexture(GL_TEXTURE0);
1856 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1857 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1858 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1859 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1860
1861 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1862 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1863
1864 // Two levels that are initially unused.
1865 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1866 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1867 texDataCyan.data());
1868
1869 // One level that is used - only this level should affect completeness.
1870 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1871 texDataGreen.data());
1872
1873 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1874 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1875
1876 EXPECT_GL_NO_ERROR();
1877
1878 drawQuad(mProgram, "position", 0.5f);
1879
1880 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1881
1882 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1883 {
1884 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
1885 // level was changed.
1886 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
1887 return;
1888 }
1889
1890 // Switch the level that is being used to the cyan level 2.
1891 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1892 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1893
1894 EXPECT_GL_NO_ERROR();
1895
1896 drawQuad(mProgram, "position", 0.5f);
1897
1898 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1899}
1900
1901// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1902// have images defined.
1903TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1904{
1905 if (IsOSX())
1906 {
1907 // Observed incorrect rendering on OSX.
1908 std::cout << "Test skipped on OSX." << std::endl;
1909 return;
1910 }
1911 glActiveTexture(GL_TEXTURE0);
1912 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1913 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1914 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1915 texDataGreen.data());
1916 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1917 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1918 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1919 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1920
1921 EXPECT_GL_NO_ERROR();
1922
1923 drawQuad(mProgram, "position", 0.5f);
1924
1925 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1926}
1927
1928// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1929// dimensions that don't fit the images inside the range.
1930// GLES 3.0.4 section 3.8.13 Texture completeness
1931TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1932{
1933 if (IsOSX())
1934 {
1935 // Observed incorrect rendering on OSX.
1936 std::cout << "Test skipped on OSX." << std::endl;
1937 return;
1938 }
1939 glActiveTexture(GL_TEXTURE0);
1940 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1941 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1942 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1943 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1944
1945 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1946 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1947
1948 // Two levels that are initially unused.
1949 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1950 texDataRed.data());
1951 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1952 texDataCyan.data());
1953
1954 // One level that is used - only this level should affect completeness.
1955 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1956 texDataGreen.data());
1957
1958 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1959 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1960
1961 EXPECT_GL_NO_ERROR();
1962
1963 drawQuad(mProgram, "position", 0.5f);
1964
1965 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1966
1967 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1968 {
1969 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
1970 // level was changed.
1971 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
1972 return;
1973 }
1974
1975 // Switch the level that is being used to the cyan level 2.
1976 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
1977 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
1978
1979 EXPECT_GL_NO_ERROR();
1980
1981 drawQuad(mProgram, "position", 0.5f);
1982
1983 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1984}
1985
1986// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1987// have images defined.
1988TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
1989{
1990 if (IsOSX())
1991 {
1992 // Observed incorrect rendering on OSX.
1993 std::cout << "Test skipped on OSX." << std::endl;
1994 return;
1995 }
1996 glActiveTexture(GL_TEXTURE0);
1997 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
1998 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1999 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2000 texDataGreen.data());
2001 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2002 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2003 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2004 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2005
2006 EXPECT_GL_NO_ERROR();
2007
2008 drawQuad(mProgram, "position", 0.5f);
2009
2010 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2011}
2012
2013// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2014// dimensions that don't fit the images inside the range.
2015// GLES 3.0.4 section 3.8.13 Texture completeness
2016TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2017{
2018 if (IsOSX())
2019 {
2020 // Observed incorrect rendering on OSX.
2021 std::cout << "Test skipped on OSX." << std::endl;
2022 return;
2023 }
2024 glActiveTexture(GL_TEXTURE0);
2025 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
2026 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2027 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2028 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2029
2030 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2031 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2032
2033 // Two levels that are initially unused.
2034 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2035 texDataRed.data());
2036 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2037 texDataCyan.data());
2038
2039 // One level that is used - only this level should affect completeness.
2040 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2041 texDataGreen.data());
2042
2043 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2044 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2045
2046 EXPECT_GL_NO_ERROR();
2047
2048 drawQuad(mProgram, "position", 0.5f);
2049
2050 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2051
2052 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2053 {
2054 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
2055 // level was changed.
2056 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
2057 return;
2058 }
2059 if (IsNVIDIA() && (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
2060 getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE))
2061 {
2062 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
2063 // level was changed.
2064 std::cout << "Test partially skipped on NVIDIA OpenGL." << std::endl;
2065 return;
2066 }
2067
2068 // Switch the level that is being used to the cyan level 2.
2069 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2070 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2071
2072 EXPECT_GL_NO_ERROR();
2073
2074 drawQuad(mProgram, "position", 0.5f);
2075
2076 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2077}
2078
2079// Test that texture completeness is updated if texture max level changes.
2080// GLES 3.0.4 section 3.8.13 Texture completeness
2081TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2082{
2083 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2084 {
2085 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2086 // the base level.
2087 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2088 return;
2089 }
2090 if (IsOSX())
2091 {
2092 // Observed incorrect rendering on OSX.
2093 std::cout << "Test skipped on OSX." << std::endl;
2094 return;
2095 }
2096
2097 glActiveTexture(GL_TEXTURE0);
2098 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2099 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2100
2101 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2102 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2103
2104 // A level that is initially unused.
2105 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2106 texDataGreen.data());
2107
2108 // One level that is initially used - only this level should affect completeness.
2109 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2110 texDataGreen.data());
2111
2112 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2113 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2114
2115 EXPECT_GL_NO_ERROR();
2116
2117 drawQuad(mProgram, "position", 0.5f);
2118
2119 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2120
2121 // Switch the max level to level 1. The levels within the used range now have inconsistent
2122 // dimensions and the texture should be incomplete.
2123 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2124
2125 EXPECT_GL_NO_ERROR();
2126
2127 drawQuad(mProgram, "position", 0.5f);
2128
2129 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2130}
2131
2132// Test that 3D texture completeness is updated if texture max level changes.
2133// GLES 3.0.4 section 3.8.13 Texture completeness
2134TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2135{
2136 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2137 {
2138 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2139 // the base level.
2140 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2141 return;
2142 }
2143 if (IsOSX())
2144 {
2145 // Observed incorrect rendering on OSX.
2146 std::cout << "Test skipped on OSX." << std::endl;
2147 return;
2148 }
2149
2150 glActiveTexture(GL_TEXTURE0);
2151 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2152 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2153
2154 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2155 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2156
2157 // A level that is initially unused.
2158 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2159 texDataGreen.data());
2160
2161 // One level that is initially used - only this level should affect completeness.
2162 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2163 texDataGreen.data());
2164
2165 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2166 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2167
2168 EXPECT_GL_NO_ERROR();
2169
2170 drawQuad(mProgram, "position", 0.5f);
2171
2172 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2173
2174 // Switch the max level to level 1. The levels within the used range now have inconsistent
2175 // dimensions and the texture should be incomplete.
2176 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2177
2178 EXPECT_GL_NO_ERROR();
2179
2180 drawQuad(mProgram, "position", 0.5f);
2181
2182 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2183}
2184
2185// Test that texture completeness is updated if texture base level changes.
2186// GLES 3.0.4 section 3.8.13 Texture completeness
2187TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2188{
2189 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2190 {
2191 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2192 // the base level.
2193 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2194 return;
2195 }
2196
2197 glActiveTexture(GL_TEXTURE0);
2198 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2199 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2200
2201 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2202 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2203
2204 // Two levels that are initially unused.
2205 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2206 texDataGreen.data());
2207 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2208 texDataGreen.data());
2209
2210 // One level that is initially used - only this level should affect completeness.
2211 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2212 texDataGreen.data());
2213
2214 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2215 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2216
2217 EXPECT_GL_NO_ERROR();
2218
2219 drawQuad(mProgram, "position", 0.5f);
2220
2221 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2222
2223 // Switch the base level to level 1. The levels within the used range now have inconsistent
2224 // dimensions and the texture should be incomplete.
2225 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2226
2227 EXPECT_GL_NO_ERROR();
2228
2229 drawQuad(mProgram, "position", 0.5f);
2230
2231 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2232}
2233
2234// Test that texture is not complete if base level is greater than max level.
2235// GLES 3.0.4 section 3.8.13 Texture completeness
2236TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2237{
2238 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2239 {
2240 // Intel Windows OpenGL driver crashes if the base level of a non-immutable texture is out
2241 // of range.
2242 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2243 return;
2244 }
2245
2246 glActiveTexture(GL_TEXTURE0);
2247 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2248
2249 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2250 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2251
2252 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2253
2254 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2255 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2256
2257 EXPECT_GL_NO_ERROR();
2258
2259 drawQuad(mProgram, "position", 0.5f);
2260
2261 // Texture should be incomplete.
2262 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2263}
2264
2265// Test that immutable texture base level and max level are clamped.
2266// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2267TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2268{
Olli Etuahoa314b612016-03-10 16:43:00 +02002269 glActiveTexture(GL_TEXTURE0);
2270 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2271
2272 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2273 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2274
2275 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2276
2277 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2278
2279 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2280 // should be clamped to [base_level, levels - 1].
2281 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2282 // In the case of this test, those rules make the effective base level and max level 0.
2283 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2284 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2285
2286 EXPECT_GL_NO_ERROR();
2287
2288 drawQuad(mProgram, "position", 0.5f);
2289
2290 // Texture should be complete.
2291 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2292}
2293
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002294// Test that changing base level works when it affects the format of the texture.
2295TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2296{
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002297 if (IsNVIDIA() && IsOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002298 {
2299 // Observed rendering corruption on NVIDIA OpenGL.
2300 std::cout << "Test skipped on NVIDIA OpenGL." << std::endl;
2301 return;
2302 }
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002303 if (IsIntel() && IsDesktopOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002304 {
2305 // Observed incorrect rendering on Intel OpenGL.
2306 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2307 return;
2308 }
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002309 if (IsAMD() && IsDesktopOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002310 {
2311 // Observed incorrect rendering on AMD OpenGL.
2312 std::cout << "Test skipped on AMD OpenGL." << std::endl;
2313 return;
2314 }
2315
2316 glActiveTexture(GL_TEXTURE0);
2317 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2318 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2319 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2320
2321 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2322 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2323
2324 // RGBA8 level that's initially unused.
2325 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2326 texDataCyan.data());
2327
2328 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2329 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2330
2331 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2332 // format. It reads green channel data from the green and alpha channels of texDataGreen
2333 // (this is a bit hacky but works).
2334 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2335
2336 EXPECT_GL_NO_ERROR();
2337
2338 drawQuad(mProgram, "position", 0.5f);
2339
2340 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2341
2342 // Switch the texture to use the cyan level 0 with the RGBA format.
2343 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2344 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2345
2346 EXPECT_GL_NO_ERROR();
2347
2348 drawQuad(mProgram, "position", 0.5f);
2349
2350 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2351}
2352
Olli Etuahoa314b612016-03-10 16:43:00 +02002353// Test that setting a texture image works when base level is out of range.
2354TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2355{
2356 glActiveTexture(GL_TEXTURE0);
2357 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2358
2359 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2360 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2361
2362 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2363 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2364
2365 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2366
2367 EXPECT_GL_NO_ERROR();
2368
2369 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2370
2371 drawQuad(mProgram, "position", 0.5f);
2372
2373 // Texture should be complete.
2374 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002375}
2376
Jamie Madill2453dbc2015-07-14 11:35:42 -04002377// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG RBA->RGBA8, with 1.0
2378// in the alpha channel. This test covers a bug where redefining array textures with these formats does not work as
2379// expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002380TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002381{
2382 std::vector<GLubyte> pixelData;
2383 for (size_t count = 0; count < 5000; count++)
2384 {
2385 pixelData.push_back(0u);
2386 pixelData.push_back(255u);
2387 pixelData.push_back(0u);
2388 }
2389
2390 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002391 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002392 glUniform1i(mTextureArrayLocation, 0);
2393
2394 // The first draw worked correctly.
2395 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
2396
2397 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2398 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2399 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2400 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002401 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002402 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002403
2404 // The dimension of the respecification must match the original exactly to trigger the bug.
2405 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 +02002406 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002407 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002408
2409 ASSERT_GL_NO_ERROR();
2410}
2411
Olli Etuaho1a679902016-01-14 12:21:47 +02002412// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2413// This test is needed especially to confirm that sampler registers get assigned correctly on
2414// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2415TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2416{
2417 glActiveTexture(GL_TEXTURE0);
2418 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2419 GLubyte texData[4];
2420 texData[0] = 0;
2421 texData[1] = 60;
2422 texData[2] = 0;
2423 texData[3] = 255;
2424 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2425
2426 glActiveTexture(GL_TEXTURE1);
2427 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2428 GLfloat depthTexData[1];
2429 depthTexData[0] = 0.5f;
2430 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2431 depthTexData);
2432
2433 glUseProgram(mProgram);
2434 glUniform1f(mDepthRefUniformLocation, 0.3f);
2435 glUniform1i(mTexture3DUniformLocation, 0);
2436 glUniform1i(mTextureShadowUniformLocation, 1);
2437
2438 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2439 drawQuad(mProgram, "position", 0.5f);
2440 EXPECT_GL_NO_ERROR();
2441 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2442 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2443
2444 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2445 drawQuad(mProgram, "position", 0.5f);
2446 EXPECT_GL_NO_ERROR();
2447 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2448 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2449}
2450
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002451// Test multiple different sampler types in the same shader.
2452// This test makes sure that even if sampler / texture registers get grouped together based on type
2453// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2454// still has the right register index information for each ESSL sampler.
2455// The tested ESSL samplers have the following types in D3D11 HLSL:
2456// sampler2D: Texture2D + SamplerState
2457// samplerCube: TextureCube + SamplerState
2458// sampler2DShadow: Texture2D + SamplerComparisonState
2459// samplerCubeShadow: TextureCube + SamplerComparisonState
2460TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2461{
2462 glActiveTexture(GL_TEXTURE0);
2463 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2464 GLubyte texData[4];
2465 texData[0] = 0;
2466 texData[1] = 0;
2467 texData[2] = 120;
2468 texData[3] = 255;
2469 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2470
2471 glActiveTexture(GL_TEXTURE1);
2472 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2473 texData[0] = 0;
2474 texData[1] = 90;
2475 texData[2] = 0;
2476 texData[3] = 255;
2477 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2478 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2479 texData);
2480
2481 glActiveTexture(GL_TEXTURE2);
2482 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2483 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2484 GLfloat depthTexData[1];
2485 depthTexData[0] = 0.5f;
2486 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2487 depthTexData);
2488
2489 glActiveTexture(GL_TEXTURE3);
2490 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2491 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2492 depthTexData[0] = 0.2f;
2493 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2494 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2495 depthTexData);
2496
2497 EXPECT_GL_NO_ERROR();
2498
2499 glUseProgram(mProgram);
2500 glUniform1f(mDepthRefUniformLocation, 0.3f);
2501 glUniform1i(mTexture2DUniformLocation, 0);
2502 glUniform1i(mTextureCubeUniformLocation, 1);
2503 glUniform1i(mTexture2DShadowUniformLocation, 2);
2504 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2505
2506 drawQuad(mProgram, "position", 0.5f);
2507 EXPECT_GL_NO_ERROR();
2508 // The shader writes:
2509 // <texture 2d color> +
2510 // <cube map color> +
2511 // 0.25 * <comparison result (1.0)> +
2512 // 0.125 * <comparison result (0.0)>
2513 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2514}
2515
Olli Etuahobce743a2016-01-15 17:18:28 +02002516// Test different base levels on textures accessed through the same sampler array.
2517// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2518TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2519{
Jiangd9227752017-10-19 16:23:07 +08002520 if (IsAMD() && IsD3D11())
Olli Etuahobce743a2016-01-15 17:18:28 +02002521 {
Jiangd9227752017-10-19 16:23:07 +08002522 std::cout << "Test skipped on AMD D3D." << std::endl;
Olli Etuahobce743a2016-01-15 17:18:28 +02002523 return;
2524 }
2525 glActiveTexture(GL_TEXTURE0);
2526 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2527 GLsizei size = 64;
2528 for (GLint level = 0; level < 7; ++level)
2529 {
2530 ASSERT_LT(0, size);
2531 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2532 nullptr);
2533 size = size / 2;
2534 }
2535 ASSERT_EQ(0, size);
2536 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2537
2538 glActiveTexture(GL_TEXTURE1);
2539 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2540 size = 128;
2541 for (GLint level = 0; level < 8; ++level)
2542 {
2543 ASSERT_LT(0, size);
2544 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2545 nullptr);
2546 size = size / 2;
2547 }
2548 ASSERT_EQ(0, size);
2549 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2550 EXPECT_GL_NO_ERROR();
2551
2552 glUseProgram(mProgram);
2553 glUniform1i(mTexture0Location, 0);
2554 glUniform1i(mTexture1Location, 1);
2555
2556 drawQuad(mProgram, "position", 0.5f);
2557 EXPECT_GL_NO_ERROR();
2558 // Red channel: width of level 1 of texture A: 32.
2559 // Green channel: width of level 3 of texture B: 16.
2560 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2561}
2562
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002563// 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, TextureRGBImplicitAlpha1)
2566{
2567 glActiveTexture(GL_TEXTURE0);
2568 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2569 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, 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, TextureLuminanceImplicitAlpha1)
2580{
2581 glActiveTexture(GL_TEXTURE0);
2582 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2583 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2584 EXPECT_GL_NO_ERROR();
2585
2586 drawQuad(mProgram, "position", 0.5f);
2587
2588 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2589}
2590
2591// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2592// ES 3.0.4 table 3.24
2593TEST_P(Texture2DTestES3, TextureLuminance32ImplicitAlpha1)
2594{
2595 if (extensionEnabled("GL_OES_texture_float"))
2596 {
2597 glActiveTexture(GL_TEXTURE0);
2598 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2599 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2600 EXPECT_GL_NO_ERROR();
2601
2602 drawQuad(mProgram, "position", 0.5f);
2603
2604 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2605 }
2606}
2607
2608// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2609// ES 3.0.4 table 3.24
2610TEST_P(Texture2DTestES3, TextureLuminance16ImplicitAlpha1)
2611{
2612 if (extensionEnabled("GL_OES_texture_half_float"))
2613 {
Yuly Novikovafcec832016-06-21 22:19:51 -04002614 if (IsNVIDIA() && IsOpenGLES())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002615 {
2616 std::cout << "Test skipped on NVIDIA" << std::endl;
2617 return;
2618 }
Yuly Novikovafcec832016-06-21 22:19:51 -04002619 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2620 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2621 {
2622 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2623 return;
2624 }
2625
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002626 glActiveTexture(GL_TEXTURE0);
2627 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2628 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES,
2629 nullptr);
2630 EXPECT_GL_NO_ERROR();
2631
2632 drawQuad(mProgram, "position", 0.5f);
2633
2634 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2635 }
2636}
2637
2638// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2639// ES 3.0.4 table 3.24
2640TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2641{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002642 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002643 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002644 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002645 return;
2646 }
2647 glActiveTexture(GL_TEXTURE0);
2648 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2649 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2650 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2651 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2652 EXPECT_GL_NO_ERROR();
2653
2654 drawQuad(mProgram, "position", 0.5f);
2655
2656 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2657}
2658
2659// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2660// ES 3.0.4 table 3.24
2661TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2662{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002663 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002664 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002665 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002666 return;
2667 }
2668 glActiveTexture(GL_TEXTURE0);
2669 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2670
2671 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2672 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2673 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2674 EXPECT_GL_NO_ERROR();
2675
2676 drawQuad(mProgram, "position", 0.5f);
2677
2678 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2679}
2680
2681// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2682// ES 3.0.4 table 3.24
2683TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2684{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002685 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002686 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002687 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002688 return;
2689 }
2690 glActiveTexture(GL_TEXTURE0);
2691 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2692 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2693 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2694 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2695 EXPECT_GL_NO_ERROR();
2696
2697 drawQuad(mProgram, "position", 0.5f);
2698
2699 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2700}
2701
2702// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2703// ES 3.0.4 table 3.24
2704TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2705{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002706 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002707 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002708 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002709 return;
2710 }
2711 glActiveTexture(GL_TEXTURE0);
2712 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2713 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2714 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2715 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2716 EXPECT_GL_NO_ERROR();
2717
2718 drawQuad(mProgram, "position", 0.5f);
2719
2720 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2721}
2722
2723// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2724// ES 3.0.4 table 3.24
2725TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2726{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002727 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002728 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002729 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002730 return;
2731 }
2732 glActiveTexture(GL_TEXTURE0);
2733 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2734 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2735 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2736 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2737 EXPECT_GL_NO_ERROR();
2738
2739 drawQuad(mProgram, "position", 0.5f);
2740
2741 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2742}
2743
2744// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2745// ES 3.0.4 table 3.24
2746TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2747{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002748 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002749 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002750 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002751 return;
2752 }
2753 glActiveTexture(GL_TEXTURE0);
2754 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2755 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2756 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2757 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
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, TextureRGBSNORMImplicitAlpha1)
2768{
2769 glActiveTexture(GL_TEXTURE0);
2770 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2771 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2772 EXPECT_GL_NO_ERROR();
2773
2774 drawQuad(mProgram, "position", 0.5f);
2775
2776 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2777}
2778
2779// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2780// ES 3.0.4 table 3.24
2781TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2782{
2783 glActiveTexture(GL_TEXTURE0);
2784 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2785 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2786 nullptr);
2787 EXPECT_GL_NO_ERROR();
2788
2789 drawQuad(mProgram, "position", 0.5f);
2790
2791 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2792}
2793
2794// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2795// ES 3.0.4 table 3.24
2796TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2797{
Jamie Madillbb1db482017-01-10 10:48:32 -05002798 if (IsOSX() && IsIntel() && IsOpenGL())
2799 {
2800 // Seems to fail on OSX 10.12 Intel.
2801 std::cout << "Test skipped on OSX Intel." << std::endl;
2802 return;
2803 }
2804
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002805 glActiveTexture(GL_TEXTURE0);
2806 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2807 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2808 EXPECT_GL_NO_ERROR();
2809
2810 drawQuad(mProgram, "position", 0.5f);
2811
2812 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2813}
2814
2815// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2816// ES 3.0.4 table 3.24
2817TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2818{
Jamie Madillbb1db482017-01-10 10:48:32 -05002819 if (IsIntel() && IsOpenGL() && (IsLinux() || IsOSX()))
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002820 {
2821 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
Jamie Madillbb1db482017-01-10 10:48:32 -05002822 // Also seems to fail on OSX 10.12 Intel.
2823 std::cout << "Test disabled on Linux and OSX Intel OpenGL." << std::endl;
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002824 return;
2825 }
2826
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002827 glActiveTexture(GL_TEXTURE0);
2828 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2829 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2830 EXPECT_GL_NO_ERROR();
2831
2832 drawQuad(mProgram, "position", 0.5f);
2833
2834 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2835}
2836
Olli Etuaho96963162016-03-21 11:54:33 +02002837// Use a sampler in a uniform struct.
2838TEST_P(SamplerInStructTest, SamplerInStruct)
2839{
2840 runSamplerInStructTest();
2841}
2842
2843// Use a sampler in a uniform struct that's passed as a function parameter.
2844TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2845{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002846 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2847 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2848 {
2849 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2850 return;
2851 }
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002852
Olli Etuaho96963162016-03-21 11:54:33 +02002853 runSamplerInStructTest();
2854}
2855
2856// Use a sampler in a uniform struct array with a struct from the array passed as a function
2857// parameter.
2858TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2859{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002860 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2861 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2862 {
2863 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2864 return;
2865 }
Olli Etuaho96963162016-03-21 11:54:33 +02002866 runSamplerInStructTest();
2867}
2868
2869// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2870// parameter.
2871TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2872{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002873 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2874 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2875 {
2876 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2877 return;
2878 }
Olli Etuaho96963162016-03-21 11:54:33 +02002879 runSamplerInStructTest();
2880}
2881
2882// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2883// similarly named uniform.
2884TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2885{
2886 runSamplerInStructTest();
2887}
2888
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002889class TextureLimitsTest : public ANGLETest
2890{
2891 protected:
2892 struct RGBA8
2893 {
2894 uint8_t R, G, B, A;
2895 };
2896
2897 TextureLimitsTest()
2898 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
2899 {
2900 setWindowWidth(128);
2901 setWindowHeight(128);
2902 setConfigRedBits(8);
2903 setConfigGreenBits(8);
2904 setConfigBlueBits(8);
2905 setConfigAlphaBits(8);
2906 }
2907
2908 ~TextureLimitsTest()
2909 {
2910 if (mProgram != 0)
2911 {
2912 glDeleteProgram(mProgram);
2913 mProgram = 0;
2914
2915 if (!mTextures.empty())
2916 {
2917 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
2918 }
2919 }
2920 }
2921
2922 void SetUp() override
2923 {
2924 ANGLETest::SetUp();
2925
2926 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
2927 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
2928 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
2929
2930 ASSERT_GL_NO_ERROR();
2931 }
2932
2933 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
2934 GLint vertexTextureCount,
2935 GLint vertexActiveTextureCount,
2936 const std::string &fragPrefix,
2937 GLint fragmentTextureCount,
2938 GLint fragmentActiveTextureCount)
2939 {
2940 std::stringstream vertexShaderStr;
2941 vertexShaderStr << "attribute vec2 position;\n"
2942 << "varying vec4 color;\n"
2943 << "varying vec2 texCoord;\n";
2944
2945 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
2946 {
2947 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
2948 }
2949
2950 vertexShaderStr << "void main() {\n"
2951 << " gl_Position = vec4(position, 0, 1);\n"
2952 << " texCoord = (position * 0.5) + 0.5;\n"
2953 << " color = vec4(0);\n";
2954
2955 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
2956 {
2957 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
2958 << ", texCoord);\n";
2959 }
2960
2961 vertexShaderStr << "}";
2962
2963 std::stringstream fragmentShaderStr;
2964 fragmentShaderStr << "varying mediump vec4 color;\n"
2965 << "varying mediump vec2 texCoord;\n";
2966
2967 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
2968 {
2969 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
2970 }
2971
2972 fragmentShaderStr << "void main() {\n"
2973 << " gl_FragColor = color;\n";
2974
2975 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
2976 {
2977 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
2978 << ", texCoord);\n";
2979 }
2980
2981 fragmentShaderStr << "}";
2982
2983 const std::string &vertexShaderSource = vertexShaderStr.str();
2984 const std::string &fragmentShaderSource = fragmentShaderStr.str();
2985
2986 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
2987 }
2988
2989 RGBA8 getPixel(GLint texIndex)
2990 {
2991 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
2992 0, 255u};
2993 return pixel;
2994 }
2995
2996 void initTextures(GLint tex2DCount, GLint texCubeCount)
2997 {
2998 GLint totalCount = tex2DCount + texCubeCount;
2999 mTextures.assign(totalCount, 0);
3000 glGenTextures(totalCount, &mTextures[0]);
3001 ASSERT_GL_NO_ERROR();
3002
3003 std::vector<RGBA8> texData(16 * 16);
3004
3005 GLint texIndex = 0;
3006 for (; texIndex < tex2DCount; ++texIndex)
3007 {
3008 texData.assign(texData.size(), getPixel(texIndex));
3009 glActiveTexture(GL_TEXTURE0 + texIndex);
3010 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3011 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3012 &texData[0]);
3013 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3014 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3015 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3016 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3017 }
3018
3019 ASSERT_GL_NO_ERROR();
3020
3021 for (; texIndex < texCubeCount; ++texIndex)
3022 {
3023 texData.assign(texData.size(), getPixel(texIndex));
3024 glActiveTexture(GL_TEXTURE0 + texIndex);
3025 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3026 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3027 GL_UNSIGNED_BYTE, &texData[0]);
3028 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3029 GL_UNSIGNED_BYTE, &texData[0]);
3030 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3031 GL_UNSIGNED_BYTE, &texData[0]);
3032 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3033 GL_UNSIGNED_BYTE, &texData[0]);
3034 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3035 GL_UNSIGNED_BYTE, &texData[0]);
3036 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3037 GL_UNSIGNED_BYTE, &texData[0]);
3038 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3039 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3040 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3041 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3042 }
3043
3044 ASSERT_GL_NO_ERROR();
3045 }
3046
3047 void testWithTextures(GLint vertexTextureCount,
3048 const std::string &vertexTexturePrefix,
3049 GLint fragmentTextureCount,
3050 const std::string &fragmentTexturePrefix)
3051 {
3052 // Generate textures
3053 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3054
3055 glUseProgram(mProgram);
3056 RGBA8 expectedSum = {0};
3057 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3058 {
3059 std::stringstream uniformNameStr;
3060 uniformNameStr << vertexTexturePrefix << texIndex;
3061 const std::string &uniformName = uniformNameStr.str();
3062 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
3063 ASSERT_NE(-1, location);
3064
3065 glUniform1i(location, texIndex);
3066 RGBA8 contribution = getPixel(texIndex);
3067 expectedSum.R += contribution.R;
3068 expectedSum.G += contribution.G;
3069 }
3070
3071 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3072 {
3073 std::stringstream uniformNameStr;
3074 uniformNameStr << fragmentTexturePrefix << texIndex;
3075 const std::string &uniformName = uniformNameStr.str();
3076 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
3077 ASSERT_NE(-1, location);
3078
3079 glUniform1i(location, texIndex + vertexTextureCount);
3080 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3081 expectedSum.R += contribution.R;
3082 expectedSum.G += contribution.G;
3083 }
3084
3085 ASSERT_GE(256u, expectedSum.G);
3086
3087 drawQuad(mProgram, "position", 0.5f);
3088 ASSERT_GL_NO_ERROR();
3089 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3090 }
3091
3092 GLuint mProgram;
3093 std::vector<GLuint> mTextures;
3094 GLint mMaxVertexTextures;
3095 GLint mMaxFragmentTextures;
3096 GLint mMaxCombinedTextures;
3097};
3098
3099// Test rendering with the maximum vertex texture units.
3100TEST_P(TextureLimitsTest, MaxVertexTextures)
3101{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003102 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003103 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003104 {
3105 std::cout << "Test skipped on Intel." << std::endl;
3106 return;
3107 }
3108
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003109 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3110 ASSERT_NE(0u, mProgram);
3111 ASSERT_GL_NO_ERROR();
3112
3113 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3114}
3115
3116// Test rendering with the maximum fragment texture units.
3117TEST_P(TextureLimitsTest, MaxFragmentTextures)
3118{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003119 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003120 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003121 {
3122 std::cout << "Test skipped on Intel." << std::endl;
3123 return;
3124 }
3125
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003126 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3127 ASSERT_NE(0u, mProgram);
3128 ASSERT_GL_NO_ERROR();
3129
3130 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3131}
3132
3133// Test rendering with maximum combined texture units.
3134TEST_P(TextureLimitsTest, MaxCombinedTextures)
3135{
Jamie Madill412f17d2015-09-25 08:43:54 -04003136 // TODO(jmadill): Investigate workaround.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003137 if (IsIntel() && GetParam() == ES2_OPENGL())
Jamie Madill412f17d2015-09-25 08:43:54 -04003138 {
3139 std::cout << "Test skipped on Intel." << std::endl;
3140 return;
3141 }
3142
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003143 GLint vertexTextures = mMaxVertexTextures;
3144
3145 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3146 {
3147 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3148 }
3149
3150 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3151 mMaxFragmentTextures, mMaxFragmentTextures);
3152 ASSERT_NE(0u, mProgram);
3153 ASSERT_GL_NO_ERROR();
3154
3155 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3156}
3157
3158// Negative test for exceeding the number of vertex textures
3159TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3160{
3161 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3162 0);
3163 ASSERT_EQ(0u, mProgram);
3164}
3165
3166// Negative test for exceeding the number of fragment textures
3167TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3168{
3169 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3170 mMaxFragmentTextures + 1);
3171 ASSERT_EQ(0u, mProgram);
3172}
3173
3174// Test active vertex textures under the limit, but excessive textures specified.
3175TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3176{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003177 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003178 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003179 {
3180 std::cout << "Test skipped on Intel." << std::endl;
3181 return;
3182 }
3183
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003184 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3185 ASSERT_NE(0u, mProgram);
3186 ASSERT_GL_NO_ERROR();
3187
3188 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3189}
3190
3191// Test active fragment textures under the limit, but excessive textures specified.
3192TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3193{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003194 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003195 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003196 {
3197 std::cout << "Test skipped on Intel." << std::endl;
3198 return;
3199 }
3200
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003201 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3202 mMaxFragmentTextures);
3203 ASSERT_NE(0u, mProgram);
3204 ASSERT_GL_NO_ERROR();
3205
3206 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3207}
3208
3209// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003210// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003211TEST_P(TextureLimitsTest, TextureTypeConflict)
3212{
3213 const std::string &vertexShader =
3214 "attribute vec2 position;\n"
3215 "varying float color;\n"
3216 "uniform sampler2D tex2D;\n"
3217 "uniform samplerCube texCube;\n"
3218 "void main() {\n"
3219 " gl_Position = vec4(position, 0, 1);\n"
3220 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3221 " color = texture2D(tex2D, texCoord).x;\n"
3222 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3223 "}";
3224 const std::string &fragmentShader =
3225 "varying mediump float color;\n"
3226 "void main() {\n"
3227 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3228 "}";
3229
3230 mProgram = CompileProgram(vertexShader, fragmentShader);
3231 ASSERT_NE(0u, mProgram);
3232
3233 initTextures(1, 0);
3234
3235 glUseProgram(mProgram);
3236 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3237 ASSERT_NE(-1, tex2DLocation);
3238 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3239 ASSERT_NE(-1, texCubeLocation);
3240
3241 glUniform1i(tex2DLocation, 0);
3242 glUniform1i(texCubeLocation, 0);
3243 ASSERT_GL_NO_ERROR();
3244
3245 drawQuad(mProgram, "position", 0.5f);
3246 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3247}
3248
Vincent Lang25ab4512016-05-13 18:13:59 +02003249class Texture2DNorm16TestES3 : public Texture2DTestES3
3250{
3251 protected:
3252 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3253
3254 void SetUp() override
3255 {
3256 Texture2DTestES3::SetUp();
3257
3258 glActiveTexture(GL_TEXTURE0);
3259 glGenTextures(3, mTextures);
3260 glGenFramebuffers(1, &mFBO);
3261 glGenRenderbuffers(1, &mRenderbuffer);
3262
3263 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3264 {
3265 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3266 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3267 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3268 }
3269
3270 glBindTexture(GL_TEXTURE_2D, 0);
3271
3272 ASSERT_GL_NO_ERROR();
3273 }
3274
3275 void TearDown() override
3276 {
3277 glDeleteTextures(3, mTextures);
3278 glDeleteFramebuffers(1, &mFBO);
3279 glDeleteRenderbuffers(1, &mRenderbuffer);
3280
3281 Texture2DTestES3::TearDown();
3282 }
3283
3284 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3285 {
Geoff Langf607c602016-09-21 11:46:48 -04003286 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3287 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003288
3289 setUpProgram();
3290
3291 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3292 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3293 0);
3294
3295 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3296 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3297
3298 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003299 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003300
3301 EXPECT_GL_NO_ERROR();
3302
3303 drawQuad(mProgram, "position", 0.5f);
3304
Geoff Langf607c602016-09-21 11:46:48 -04003305 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003306
Geoff Langf607c602016-09-21 11:46:48 -04003307 EXPECT_PIXEL_COLOR_EQ(
3308 0, 0, SliceFormatColor(
3309 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003310
3311 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3312
3313 ASSERT_GL_NO_ERROR();
3314 }
3315
3316 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3317 {
3318 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003319 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003320
3321 setUpProgram();
3322
3323 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3324 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3325
3326 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3327 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3328 0);
3329
3330 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003331 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003332
3333 EXPECT_GL_NO_ERROR();
3334
3335 drawQuad(mProgram, "position", 0.5f);
3336
Geoff Langf607c602016-09-21 11:46:48 -04003337 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
3338 EXPECT_PIXEL_COLOR_EQ(
3339 0, 0, SliceFormatColor(
3340 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003341
3342 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3343 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3344 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3345 mRenderbuffer);
3346 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3347 EXPECT_GL_NO_ERROR();
3348
3349 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3350 glClear(GL_COLOR_BUFFER_BIT);
3351
3352 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3353
Geoff Langf607c602016-09-21 11:46:48 -04003354 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003355
3356 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3357
3358 ASSERT_GL_NO_ERROR();
3359 }
3360
3361 GLuint mTextures[3];
3362 GLuint mFBO;
3363 GLuint mRenderbuffer;
3364};
3365
3366// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3367TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3368{
3369 if (!extensionEnabled("GL_EXT_texture_norm16"))
3370 {
3371 std::cout << "Test skipped due to missing GL_EXT_texture_norm16." << std::endl;
3372 return;
3373 }
3374
3375 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3376 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3377 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3378 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3379 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3380 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3381 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3382 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3383
3384 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3385 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3386 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3387}
3388
Olli Etuaho95faa232016-06-07 14:01:53 -07003389// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3390// GLES 3.0.4 section 3.8.3.
3391TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3392{
Corentin Wallezc7f59d02016-06-20 10:12:08 -04003393 if (IsIntel() && IsDesktopOpenGL())
Olli Etuaho95faa232016-06-07 14:01:53 -07003394 {
3395 std::cout << "Test skipped on Intel OpenGL." << std::endl;
3396 return;
3397 }
Yuly Novikov3c754192016-06-27 19:36:41 -04003398 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1429 is fixed
3399 if (IsAndroid() && IsAdreno() && IsOpenGLES())
3400 {
3401 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
3402 return;
3403 }
Olli Etuaho95faa232016-06-07 14:01:53 -07003404
3405 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3406 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3407 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3408 ASSERT_GL_NO_ERROR();
3409
3410 // SKIP_IMAGES should not have an effect on uploading 2D textures
3411 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3412 ASSERT_GL_NO_ERROR();
3413
3414 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3415
3416 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3417 pixelsGreen.data());
3418 ASSERT_GL_NO_ERROR();
3419
3420 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3421 pixelsGreen.data());
3422 ASSERT_GL_NO_ERROR();
3423
3424 glUseProgram(mProgram);
3425 drawQuad(mProgram, "position", 0.5f);
3426 ASSERT_GL_NO_ERROR();
3427
3428 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3429}
3430
Olli Etuaho989cac32016-06-08 16:18:49 -07003431// Test that skip defined in unpack parameters is taken into account when determining whether
3432// unpacking source extends outside unpack buffer bounds.
3433TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3434{
3435 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3436 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3437 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3438 ASSERT_GL_NO_ERROR();
3439
3440 GLBuffer buf;
3441 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3442 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3443 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3444 GL_DYNAMIC_COPY);
3445 ASSERT_GL_NO_ERROR();
3446
3447 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3448 ASSERT_GL_NO_ERROR();
3449
3450 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3451 ASSERT_GL_NO_ERROR();
3452
3453 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3454 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3455
3456 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3457 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3458 ASSERT_GL_NO_ERROR();
3459
3460 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3461 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3462}
3463
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003464// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3465TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3466{
3467 if (IsD3D11())
3468 {
3469 std::cout << "Test skipped on D3D." << std::endl;
3470 return;
3471 }
3472 if (IsOSX() && IsAMD())
3473 {
3474 // Incorrect rendering results seen on OSX AMD.
3475 std::cout << "Test skipped on OSX AMD." << std::endl;
3476 return;
3477 }
3478
3479 const GLuint width = 8u;
3480 const GLuint height = 8u;
3481 const GLuint unpackRowLength = 5u;
3482 const GLuint unpackSkipPixels = 1u;
3483
3484 setWindowWidth(width);
3485 setWindowHeight(height);
3486
3487 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3488 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3489 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3490 ASSERT_GL_NO_ERROR();
3491
3492 GLBuffer buf;
3493 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3494 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3495 GLColor::green);
3496
3497 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3498 {
3499 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3500 }
3501
3502 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3503 GL_DYNAMIC_COPY);
3504 ASSERT_GL_NO_ERROR();
3505
3506 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3507 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3508 ASSERT_GL_NO_ERROR();
3509
3510 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3511 ASSERT_GL_NO_ERROR();
3512
3513 glUseProgram(mProgram);
3514 drawQuad(mProgram, "position", 0.5f);
3515 ASSERT_GL_NO_ERROR();
3516
3517 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3518 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3519 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3520 actual.data());
3521 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3522 EXPECT_EQ(expected, actual);
3523}
3524
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003525template <typename T>
3526T UNorm(double value)
3527{
3528 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3529}
3530
3531// Test rendering a depth texture with mipmaps.
3532TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3533{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003534 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3535 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
3536 // http://anglebugs.com/1706
3537 if (IsIntel() && IsWindows())
Corentin Walleze731d8a2016-09-07 10:56:25 -04003538 {
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003539 std::cout << "Test skipped on Win Intel." << std::endl;
Corentin Walleze731d8a2016-09-07 10:56:25 -04003540 return;
3541 }
3542
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003543 const int size = getWindowWidth();
3544
3545 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003546 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003547
3548 glActiveTexture(GL_TEXTURE0);
3549 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3550 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3551 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3552 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3553 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3554 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3555 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3556 ASSERT_GL_NO_ERROR();
3557
3558 glUseProgram(mProgram);
3559 glUniform1i(mTexture2DUniformLocation, 0);
3560
3561 std::vector<unsigned char> expected;
3562
3563 for (int level = 0; level < levels; ++level)
3564 {
3565 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3566 expected.push_back(UNorm<unsigned char>(value));
3567
3568 int levelDim = dim(level);
3569
3570 ASSERT_GT(levelDim, 0);
3571
3572 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3573 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3574 GL_UNSIGNED_INT, initData.data());
3575 }
3576 ASSERT_GL_NO_ERROR();
3577
3578 for (int level = 0; level < levels; ++level)
3579 {
3580 glViewport(0, 0, dim(level), dim(level));
3581 drawQuad(mProgram, "position", 0.5f);
3582 GLColor actual = ReadColor(0, 0);
3583 EXPECT_NEAR(expected[level], actual.R, 10u);
3584 }
3585
3586 ASSERT_GL_NO_ERROR();
3587}
3588
Jamie Madill7ffdda92016-09-08 13:26:51 -04003589// Tests unpacking into the unsized GL_ALPHA format.
3590TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3591{
3592 // TODO(jmadill): Figure out why this fails on OSX.
3593 ANGLE_SKIP_TEST_IF(IsOSX());
3594
3595 // Initialize the texure.
3596 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3597 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3598 GL_UNSIGNED_BYTE, nullptr);
3599 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3600 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3601
3602 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3603
3604 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04003605 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04003606 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3607 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3608 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
3609 GL_STATIC_DRAW);
3610
3611 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
3612 GL_UNSIGNED_BYTE, nullptr);
3613
3614 // Clear to a weird color to make sure we're drawing something.
3615 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
3616 glClear(GL_COLOR_BUFFER_BIT);
3617
3618 // Draw with the alpha texture and verify.
3619 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04003620
3621 ASSERT_GL_NO_ERROR();
3622 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
3623}
3624
Jamie Madill2e600342016-09-19 13:56:40 -04003625// Ensure stale unpack data doesn't propagate in D3D11.
3626TEST_P(Texture2DTestES3, StaleUnpackData)
3627{
3628 // Init unpack buffer.
3629 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
3630 std::vector<GLColor> pixels(pixelCount, GLColor::red);
3631
3632 GLBuffer unpackBuffer;
3633 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3634 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3635 GLsizei bufferSize = pixelCount * sizeof(GLColor);
3636 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
3637
3638 // Create from unpack buffer.
3639 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3640 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
3641 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3642 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3643 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3644
3645 drawQuad(mProgram, "position", 0.5f);
3646
3647 ASSERT_GL_NO_ERROR();
3648 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3649
3650 // Fill unpack with green, recreating buffer.
3651 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
3652 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
3653 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
3654
3655 // Reinit texture with green.
3656 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
3657 GL_UNSIGNED_BYTE, nullptr);
3658
3659 drawQuad(mProgram, "position", 0.5f);
3660
3661 ASSERT_GL_NO_ERROR();
3662 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3663}
3664
Geoff Langfb7685f2017-11-13 11:44:11 -05003665// Ensure that texture parameters passed as floats that are converted to ints are rounded before
3666// validating they are less than 0.
3667TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
3668{
3669 GLTexture texture;
3670 glBindTexture(GL_TEXTURE_2D, texture);
3671
3672 // Use a negative number that will round to zero when converted to an integer
3673 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
3674 // "Validation of values performed by state-setting commands is performed after conversion,
3675 // unless specified otherwise for a specific command."
3676 GLfloat param = -7.30157126e-07f;
3677 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
3678 EXPECT_GL_NO_ERROR();
3679
3680 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
3681 EXPECT_GL_NO_ERROR();
3682}
3683
Jamie Madillf097e232016-11-05 00:44:15 -04003684// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
3685// being properly checked, and the texture storage of the previous texture format was persisting.
3686// This would result in an ASSERT in debug and incorrect rendering in release.
3687// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
3688TEST_P(Texture3DTestES3, FormatRedefinitionBug)
3689{
3690 GLTexture tex;
3691 glBindTexture(GL_TEXTURE_3D, tex.get());
3692 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3693
3694 GLFramebuffer framebuffer;
3695 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3696 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
3697
3698 glCheckFramebufferStatus(GL_FRAMEBUFFER);
3699
3700 std::vector<uint8_t> pixelData(100, 0);
3701
3702 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
3703 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
3704 pixelData.data());
3705
3706 ASSERT_GL_NO_ERROR();
3707}
3708
Corentin Wallezd2627992017-04-28 17:17:03 -04003709// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
3710TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
3711{
3712 // 2D tests
3713 {
3714 GLTexture tex;
3715 glBindTexture(GL_TEXTURE_2D, tex.get());
3716
3717 GLBuffer pbo;
3718 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3719
3720 // Test OOB
3721 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
3722 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3723 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3724
3725 // Test OOB
3726 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
3727 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3728 ASSERT_GL_NO_ERROR();
3729 }
3730
3731 // 3D tests
3732 {
3733 GLTexture tex;
3734 glBindTexture(GL_TEXTURE_3D, tex.get());
3735
3736 GLBuffer pbo;
3737 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3738
3739 // Test OOB
3740 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
3741 GL_STATIC_DRAW);
3742 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3743 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3744
3745 // Test OOB
3746 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
3747 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3748 ASSERT_GL_NO_ERROR();
3749 }
3750}
3751
Jamie Madill3ed60422017-09-07 11:32:52 -04003752// Tests behaviour with a single texture and multiple sampler objects.
3753TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
3754{
3755 GLint maxTextureUnits = 0;
3756 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
3757 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
3758
3759 constexpr int kSize = 16;
3760
3761 // Make a single-level texture, fill it with red.
3762 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
3763 GLTexture tex;
3764 glBindTexture(GL_TEXTURE_2D, tex);
3765 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3766 redColors.data());
3767 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3768 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3769
3770 // Simple sanity check.
3771 draw2DTexturedQuad(0.5f, 1.0f, true);
3772 ASSERT_GL_NO_ERROR();
3773 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3774
3775 // Bind texture to unit 1 with a sampler object making it incomplete.
3776 GLSampler sampler;
3777 glBindSampler(0, sampler);
3778 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3779 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3780
3781 // Make a mipmap texture, fill it with blue.
3782 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
3783 GLTexture mipmapTex;
3784 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3785 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3786 blueColors.data());
3787 glGenerateMipmap(GL_TEXTURE_2D);
3788
3789 // Draw with the sampler, expect blue.
3790 draw2DTexturedQuad(0.5f, 1.0f, true);
3791 ASSERT_GL_NO_ERROR();
3792 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
3793
3794 // Simple multitexturing program.
3795 const std::string vs =
3796 "#version 300 es\n"
3797 "in vec2 position;\n"
3798 "out vec2 texCoord;\n"
3799 "void main()\n"
3800 "{\n"
3801 " gl_Position = vec4(position, 0, 1);\n"
3802 " texCoord = position * 0.5 + vec2(0.5);\n"
3803 "}";
3804 const std::string fs =
3805 "#version 300 es\n"
3806 "precision mediump float;\n"
3807 "in vec2 texCoord;\n"
3808 "uniform sampler2D tex1;\n"
3809 "uniform sampler2D tex2;\n"
3810 "uniform sampler2D tex3;\n"
3811 "uniform sampler2D tex4;\n"
3812 "out vec4 color;\n"
3813 "void main()\n"
3814 "{\n"
3815 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
3816 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
3817 "}";
3818
3819 ANGLE_GL_PROGRAM(program, vs, fs);
3820
3821 std::array<GLint, 4> texLocations = {
3822 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
3823 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
3824 for (GLint location : texLocations)
3825 {
3826 ASSERT_NE(-1, location);
3827 }
3828
3829 // Init the uniform data.
3830 glUseProgram(program);
3831 for (GLint location = 0; location < 4; ++location)
3832 {
3833 glUniform1i(texLocations[location], location);
3834 }
3835
3836 // Initialize four samplers
3837 GLSampler samplers[4];
3838
3839 // 0: non-mipped.
3840 glBindSampler(0, samplers[0]);
3841 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3842 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3843
3844 // 1: mipped.
3845 glBindSampler(1, samplers[1]);
3846 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3847 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3848
3849 // 2: non-mipped.
3850 glBindSampler(2, samplers[2]);
3851 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3852 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3853
3854 // 3: mipped.
3855 glBindSampler(3, samplers[3]);
3856 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3857 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3858
3859 // Bind two blue mipped textures and two single layer textures, should all draw.
3860 glActiveTexture(GL_TEXTURE0);
3861 glBindTexture(GL_TEXTURE_2D, tex);
3862
3863 glActiveTexture(GL_TEXTURE1);
3864 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3865
3866 glActiveTexture(GL_TEXTURE2);
3867 glBindTexture(GL_TEXTURE_2D, tex);
3868
3869 glActiveTexture(GL_TEXTURE3);
3870 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3871
3872 ASSERT_GL_NO_ERROR();
3873
3874 drawQuad(program, "position", 0.5f);
3875 ASSERT_GL_NO_ERROR();
3876 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
3877
3878 // Bind four single layer textures, two should be incomplete.
3879 glActiveTexture(GL_TEXTURE1);
3880 glBindTexture(GL_TEXTURE_2D, tex);
3881
3882 glActiveTexture(GL_TEXTURE3);
3883 glBindTexture(GL_TEXTURE_2D, tex);
3884
3885 drawQuad(program, "position", 0.5f);
3886 ASSERT_GL_NO_ERROR();
3887 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
3888}
3889
Martin Radev7e2c0d32017-09-15 14:25:42 +03003890// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
3891// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
3892// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
3893// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
3894// samples the cubemap using a direction vector (1,1,1).
3895TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
3896{
3897 if (IsOSX())
3898 {
3899 // Check http://anglebug.com/2155.
3900 std::cout << "Test skipped on OSX." << std::endl;
3901 return;
3902 }
3903 const std::string vs =
3904 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003905 precision mediump float;
3906 in vec3 pos;
3907 void main() {
3908 gl_Position = vec4(pos, 1.0);
3909 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003910
3911 const std::string fs =
3912 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003913 precision mediump float;
3914 out vec4 color;
3915 uniform samplerCube uTex;
3916 void main(){
3917 color = texture(uTex, vec3(1.0));
3918 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003919 ANGLE_GL_PROGRAM(program, vs, fs);
3920 glUseProgram(program);
3921
3922 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
3923 glActiveTexture(GL_TEXTURE0);
3924
3925 GLTexture cubeTex;
3926 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
3927
3928 const int kFaceWidth = 1;
3929 const int kFaceHeight = 1;
3930 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
3931 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3932 GL_UNSIGNED_BYTE, texData.data());
3933 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3934 GL_UNSIGNED_BYTE, texData.data());
3935 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3936 GL_UNSIGNED_BYTE, texData.data());
3937 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3938 GL_UNSIGNED_BYTE, texData.data());
3939 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3940 GL_UNSIGNED_BYTE, texData.data());
3941 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3942 GL_UNSIGNED_BYTE, texData.data());
3943 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3944 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3945 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
3946 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
3947 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
3948 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
3949
3950 drawQuad(program, "pos", 0.5f, 1.0f, true);
3951 ASSERT_GL_NO_ERROR();
3952
3953 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
3954}
3955
Jamie Madillfa05f602015-05-07 13:47:11 -04003956// 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 +02003957// TODO(oetuaho): Enable all below tests on OpenGL. Requires a fix for ANGLE bug 1278.
Geoff Lange0cc2a42016-01-20 10:58:17 -05003958ANGLE_INSTANTIATE_TEST(Texture2DTest,
3959 ES2_D3D9(),
3960 ES2_D3D11(),
3961 ES2_D3D11_FL9_3(),
3962 ES2_OPENGL(),
3963 ES2_OPENGLES());
3964ANGLE_INSTANTIATE_TEST(TextureCubeTest,
3965 ES2_D3D9(),
3966 ES2_D3D11(),
Geoff Langf7480ad2017-10-24 11:46:02 -04003967 ES2_D3D11_FL10_0(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003968 ES2_D3D11_FL9_3(),
3969 ES2_OPENGL(),
3970 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003971ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
3972 ES2_D3D9(),
3973 ES2_D3D11(),
3974 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003975 ES2_OPENGL(),
3976 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003977ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
3978 ES2_D3D9(),
3979 ES2_D3D11(),
3980 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003981 ES2_OPENGL(),
3982 ES2_OPENGLES());
3983ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
3984 ES2_D3D9(),
3985 ES2_D3D11(),
3986 ES2_D3D11_FL9_3(),
3987 ES2_OPENGL(),
3988 ES2_OPENGLES());
3989ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
3990 ES2_D3D9(),
3991 ES2_D3D11(),
3992 ES2_D3D11_FL9_3(),
3993 ES2_OPENGL(),
3994 ES2_OPENGLES());
3995ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02003996ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003997ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3998ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
3999 ES3_D3D11(),
4000 ES3_OPENGL(),
4001 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004002ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
4003 ES3_D3D11(),
4004 ES3_OPENGL(),
4005 ES3_OPENGLES());
4006ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4007ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02004008ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02004009ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
4010 ES2_D3D11(),
4011 ES2_D3D11_FL9_3(),
4012 ES2_D3D9(),
4013 ES2_OPENGL(),
4014 ES2_OPENGLES());
4015ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
4016 ES2_D3D11(),
4017 ES2_D3D11_FL9_3(),
4018 ES2_D3D9(),
4019 ES2_OPENGL(),
4020 ES2_OPENGLES());
4021ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
4022 ES2_D3D11(),
4023 ES2_D3D11_FL9_3(),
4024 ES2_D3D9(),
4025 ES2_OPENGL(),
4026 ES2_OPENGLES());
4027ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
4028 ES2_D3D11(),
4029 ES2_D3D11_FL9_3(),
4030 ES2_D3D9(),
4031 ES2_OPENGL(),
4032 ES2_OPENGLES());
4033ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
4034 ES2_D3D11(),
4035 ES2_D3D11_FL9_3(),
4036 ES2_D3D9(),
4037 ES2_OPENGL(),
4038 ES2_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004039ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES());
Vincent Lang25ab4512016-05-13 18:13:59 +02004040ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03004041ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04004042
Jamie Madill7ffdda92016-09-08 13:26:51 -04004043} // anonymous namespace