blob: d6242d61b68ec980375b228e5a3f27a4f841c735 [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{
Geoff Lange0cc2a42016-01-20 10:58:17 -05001730 // TODO(geofflang): Allow the GL backend to accept SubImage calls with a null data ptr. (bug
1731 // 1278)
1732 if (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
1733 getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE)
1734 {
1735 std::cout << "Test disabled on OpenGL." << std::endl;
1736 return;
1737 }
1738
Austin Kinross08528e12015-10-07 16:24:40 -07001739 glActiveTexture(GL_TEXTURE0);
1740 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1741
1742 // Create an 8x8 (i.e. power-of-two) texture.
1743 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1744 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1745 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1746 glGenerateMipmap(GL_TEXTURE_2D);
1747
1748 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1749 // This should always work, even if GL_OES_texture_npot isn't active.
1750 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1751
1752 EXPECT_GL_NO_ERROR();
1753}
1754
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001755// Test to check that texture completeness is determined correctly when the texture base level is
1756// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1757TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1758{
1759 glActiveTexture(GL_TEXTURE0);
1760 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001761
1762 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1763 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1764 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1765 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1766 texDataGreen.data());
1767 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1768 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001769 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1770 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1771 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1772
1773 EXPECT_GL_NO_ERROR();
1774
1775 drawQuad(mProgram, "position", 0.5f);
1776
Olli Etuahoa314b612016-03-10 16:43:00 +02001777 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1778}
1779
1780// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1781// have images defined.
1782TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1783{
1784 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1785 {
1786 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1787 std::cout << "Test skipped on AMD OpenGL." << std::endl;
1788 return;
1789 }
1790 if (IsOSX())
1791 {
1792 // Observed incorrect rendering on OSX.
1793 std::cout << "Test skipped on OSX." << std::endl;
1794 return;
1795 }
1796 glActiveTexture(GL_TEXTURE0);
1797 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1798 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1799 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1800 texDataGreen.data());
1801 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1802 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1803 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1804 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1805
1806 EXPECT_GL_NO_ERROR();
1807
1808 drawQuad(mProgram, "position", 0.5f);
1809
1810 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1811}
1812
Olli Etuahoe8528d82016-05-16 17:50:52 +03001813// Test that drawing works correctly when level 0 is undefined and base level is 1.
1814TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1815{
1816 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1817 {
1818 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1819 std::cout << "Test skipped on AMD OpenGL." << std::endl;
1820 return;
1821 }
1822 if (IsOSX())
1823 {
1824 // Observed incorrect rendering on OSX.
1825 std::cout << "Test skipped on OSX." << std::endl;
1826 return;
1827 }
1828 glActiveTexture(GL_TEXTURE0);
1829 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1830 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1831 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1832 texDataGreen.data());
1833 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1834 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1835 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1836 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1837
1838 EXPECT_GL_NO_ERROR();
1839
1840 // Texture is incomplete.
1841 drawQuad(mProgram, "position", 0.5f);
1842 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1843
1844 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1845 texDataGreen.data());
1846
1847 // Texture is now complete.
1848 drawQuad(mProgram, "position", 0.5f);
1849 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1850}
1851
Olli Etuahoa314b612016-03-10 16:43:00 +02001852// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1853// dimensions that don't fit the images inside the range.
1854// GLES 3.0.4 section 3.8.13 Texture completeness
1855TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1856{
1857 if (IsOSX())
1858 {
1859 // Observed incorrect rendering on OSX.
1860 std::cout << "Test skipped on OSX." << std::endl;
1861 return;
1862 }
1863 glActiveTexture(GL_TEXTURE0);
1864 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1865 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1866 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1867 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1868
1869 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1870 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1871
1872 // Two levels that are initially unused.
1873 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1874 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1875 texDataCyan.data());
1876
1877 // One level that is used - only this level should affect completeness.
1878 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1879 texDataGreen.data());
1880
1881 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1882 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1883
1884 EXPECT_GL_NO_ERROR();
1885
1886 drawQuad(mProgram, "position", 0.5f);
1887
1888 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1889
1890 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1891 {
1892 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
1893 // level was changed.
1894 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
1895 return;
1896 }
1897
1898 // Switch the level that is being used to the cyan level 2.
1899 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1900 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1901
1902 EXPECT_GL_NO_ERROR();
1903
1904 drawQuad(mProgram, "position", 0.5f);
1905
1906 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1907}
1908
1909// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1910// have images defined.
1911TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1912{
1913 if (IsOSX())
1914 {
1915 // Observed incorrect rendering on OSX.
1916 std::cout << "Test skipped on OSX." << std::endl;
1917 return;
1918 }
1919 glActiveTexture(GL_TEXTURE0);
1920 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1921 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1922 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1923 texDataGreen.data());
1924 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1925 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1926 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1927 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1928
1929 EXPECT_GL_NO_ERROR();
1930
1931 drawQuad(mProgram, "position", 0.5f);
1932
1933 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1934}
1935
1936// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1937// dimensions that don't fit the images inside the range.
1938// GLES 3.0.4 section 3.8.13 Texture completeness
1939TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1940{
1941 if (IsOSX())
1942 {
1943 // Observed incorrect rendering on OSX.
1944 std::cout << "Test skipped on OSX." << std::endl;
1945 return;
1946 }
1947 glActiveTexture(GL_TEXTURE0);
1948 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1949 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1950 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1951 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1952
1953 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1954 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1955
1956 // Two levels that are initially unused.
1957 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1958 texDataRed.data());
1959 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1960 texDataCyan.data());
1961
1962 // One level that is used - only this level should affect completeness.
1963 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1964 texDataGreen.data());
1965
1966 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1967 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1968
1969 EXPECT_GL_NO_ERROR();
1970
1971 drawQuad(mProgram, "position", 0.5f);
1972
1973 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1974
1975 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1976 {
1977 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
1978 // level was changed.
1979 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
1980 return;
1981 }
1982
1983 // Switch the level that is being used to the cyan level 2.
1984 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
1985 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
1986
1987 EXPECT_GL_NO_ERROR();
1988
1989 drawQuad(mProgram, "position", 0.5f);
1990
1991 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1992}
1993
1994// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1995// have images defined.
1996TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
1997{
1998 if (IsOSX())
1999 {
2000 // Observed incorrect rendering on OSX.
2001 std::cout << "Test skipped on OSX." << std::endl;
2002 return;
2003 }
2004 glActiveTexture(GL_TEXTURE0);
2005 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
2006 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2007 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2008 texDataGreen.data());
2009 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2010 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2011 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2012 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2013
2014 EXPECT_GL_NO_ERROR();
2015
2016 drawQuad(mProgram, "position", 0.5f);
2017
2018 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2019}
2020
2021// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2022// dimensions that don't fit the images inside the range.
2023// GLES 3.0.4 section 3.8.13 Texture completeness
2024TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2025{
2026 if (IsOSX())
2027 {
2028 // Observed incorrect rendering on OSX.
2029 std::cout << "Test skipped on OSX." << std::endl;
2030 return;
2031 }
2032 glActiveTexture(GL_TEXTURE0);
2033 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
2034 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2035 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2036 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2037
2038 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2039 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2040
2041 // Two levels that are initially unused.
2042 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2043 texDataRed.data());
2044 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2045 texDataCyan.data());
2046
2047 // One level that is used - only this level should affect completeness.
2048 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2049 texDataGreen.data());
2050
2051 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2052 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2053
2054 EXPECT_GL_NO_ERROR();
2055
2056 drawQuad(mProgram, "position", 0.5f);
2057
2058 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2059
2060 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2061 {
2062 // Intel 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 Intel OpenGL." << std::endl;
2065 return;
2066 }
2067 if (IsNVIDIA() && (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
2068 getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE))
2069 {
2070 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
2071 // level was changed.
2072 std::cout << "Test partially skipped on NVIDIA OpenGL." << std::endl;
2073 return;
2074 }
2075
2076 // Switch the level that is being used to the cyan level 2.
2077 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2078 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2079
2080 EXPECT_GL_NO_ERROR();
2081
2082 drawQuad(mProgram, "position", 0.5f);
2083
2084 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2085}
2086
2087// Test that texture completeness is updated if texture max level changes.
2088// GLES 3.0.4 section 3.8.13 Texture completeness
2089TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2090{
2091 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2092 {
2093 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2094 // the base level.
2095 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2096 return;
2097 }
2098 if (IsOSX())
2099 {
2100 // Observed incorrect rendering on OSX.
2101 std::cout << "Test skipped on OSX." << std::endl;
2102 return;
2103 }
2104
2105 glActiveTexture(GL_TEXTURE0);
2106 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2107 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2108
2109 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2110 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2111
2112 // A level that is initially unused.
2113 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2114 texDataGreen.data());
2115
2116 // One level that is initially used - only this level should affect completeness.
2117 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2118 texDataGreen.data());
2119
2120 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2121 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2122
2123 EXPECT_GL_NO_ERROR();
2124
2125 drawQuad(mProgram, "position", 0.5f);
2126
2127 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2128
2129 // Switch the max level to level 1. The levels within the used range now have inconsistent
2130 // dimensions and the texture should be incomplete.
2131 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2132
2133 EXPECT_GL_NO_ERROR();
2134
2135 drawQuad(mProgram, "position", 0.5f);
2136
2137 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2138}
2139
2140// Test that 3D texture completeness is updated if texture max level changes.
2141// GLES 3.0.4 section 3.8.13 Texture completeness
2142TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2143{
2144 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2145 {
2146 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2147 // the base level.
2148 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2149 return;
2150 }
2151 if (IsOSX())
2152 {
2153 // Observed incorrect rendering on OSX.
2154 std::cout << "Test skipped on OSX." << std::endl;
2155 return;
2156 }
2157
2158 glActiveTexture(GL_TEXTURE0);
2159 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2160 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2161
2162 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2163 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2164
2165 // A level that is initially unused.
2166 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2167 texDataGreen.data());
2168
2169 // One level that is initially used - only this level should affect completeness.
2170 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2171 texDataGreen.data());
2172
2173 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2174 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2175
2176 EXPECT_GL_NO_ERROR();
2177
2178 drawQuad(mProgram, "position", 0.5f);
2179
2180 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2181
2182 // Switch the max level to level 1. The levels within the used range now have inconsistent
2183 // dimensions and the texture should be incomplete.
2184 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2185
2186 EXPECT_GL_NO_ERROR();
2187
2188 drawQuad(mProgram, "position", 0.5f);
2189
2190 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2191}
2192
2193// Test that texture completeness is updated if texture base level changes.
2194// GLES 3.0.4 section 3.8.13 Texture completeness
2195TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2196{
2197 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2198 {
2199 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2200 // the base level.
2201 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2202 return;
2203 }
2204
2205 glActiveTexture(GL_TEXTURE0);
2206 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2207 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2208
2209 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2210 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2211
2212 // Two levels that are initially unused.
2213 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2214 texDataGreen.data());
2215 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2216 texDataGreen.data());
2217
2218 // One level that is initially used - only this level should affect completeness.
2219 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2220 texDataGreen.data());
2221
2222 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2223 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2224
2225 EXPECT_GL_NO_ERROR();
2226
2227 drawQuad(mProgram, "position", 0.5f);
2228
2229 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2230
2231 // Switch the base level to level 1. The levels within the used range now have inconsistent
2232 // dimensions and the texture should be incomplete.
2233 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2234
2235 EXPECT_GL_NO_ERROR();
2236
2237 drawQuad(mProgram, "position", 0.5f);
2238
2239 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2240}
2241
2242// Test that texture is not complete if base level is greater than max level.
2243// GLES 3.0.4 section 3.8.13 Texture completeness
2244TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2245{
2246 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2247 {
2248 // Intel Windows OpenGL driver crashes if the base level of a non-immutable texture is out
2249 // of range.
2250 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2251 return;
2252 }
2253
2254 glActiveTexture(GL_TEXTURE0);
2255 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2256
2257 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2258 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2259
2260 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2261
2262 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2263 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2264
2265 EXPECT_GL_NO_ERROR();
2266
2267 drawQuad(mProgram, "position", 0.5f);
2268
2269 // Texture should be incomplete.
2270 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2271}
2272
2273// Test that immutable texture base level and max level are clamped.
2274// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2275TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2276{
Olli Etuahoa314b612016-03-10 16:43:00 +02002277 glActiveTexture(GL_TEXTURE0);
2278 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2279
2280 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2281 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2282
2283 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2284
2285 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2286
2287 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2288 // should be clamped to [base_level, levels - 1].
2289 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2290 // In the case of this test, those rules make the effective base level and max level 0.
2291 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2292 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2293
2294 EXPECT_GL_NO_ERROR();
2295
2296 drawQuad(mProgram, "position", 0.5f);
2297
2298 // Texture should be complete.
2299 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2300}
2301
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002302// Test that changing base level works when it affects the format of the texture.
2303TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2304{
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002305 if (IsNVIDIA() && IsOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002306 {
2307 // Observed rendering corruption on NVIDIA OpenGL.
2308 std::cout << "Test skipped on NVIDIA OpenGL." << std::endl;
2309 return;
2310 }
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002311 if (IsIntel() && IsDesktopOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002312 {
2313 // Observed incorrect rendering on Intel OpenGL.
2314 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2315 return;
2316 }
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002317 if (IsAMD() && IsDesktopOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002318 {
2319 // Observed incorrect rendering on AMD OpenGL.
2320 std::cout << "Test skipped on AMD OpenGL." << std::endl;
2321 return;
2322 }
2323
2324 glActiveTexture(GL_TEXTURE0);
2325 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2326 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2327 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2328
2329 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2330 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2331
2332 // RGBA8 level that's initially unused.
2333 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2334 texDataCyan.data());
2335
2336 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2337 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2338
2339 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2340 // format. It reads green channel data from the green and alpha channels of texDataGreen
2341 // (this is a bit hacky but works).
2342 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2343
2344 EXPECT_GL_NO_ERROR();
2345
2346 drawQuad(mProgram, "position", 0.5f);
2347
2348 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2349
2350 // Switch the texture to use the cyan level 0 with the RGBA format.
2351 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2352 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2353
2354 EXPECT_GL_NO_ERROR();
2355
2356 drawQuad(mProgram, "position", 0.5f);
2357
2358 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2359}
2360
Olli Etuahoa314b612016-03-10 16:43:00 +02002361// Test that setting a texture image works when base level is out of range.
2362TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2363{
2364 glActiveTexture(GL_TEXTURE0);
2365 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2366
2367 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2368 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2369
2370 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2371 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2372
2373 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2374
2375 EXPECT_GL_NO_ERROR();
2376
2377 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2378
2379 drawQuad(mProgram, "position", 0.5f);
2380
2381 // Texture should be complete.
2382 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002383}
2384
Jamie Madill2453dbc2015-07-14 11:35:42 -04002385// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG RBA->RGBA8, with 1.0
2386// in the alpha channel. This test covers a bug where redefining array textures with these formats does not work as
2387// expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002388TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002389{
2390 std::vector<GLubyte> pixelData;
2391 for (size_t count = 0; count < 5000; count++)
2392 {
2393 pixelData.push_back(0u);
2394 pixelData.push_back(255u);
2395 pixelData.push_back(0u);
2396 }
2397
2398 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002399 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002400 glUniform1i(mTextureArrayLocation, 0);
2401
2402 // The first draw worked correctly.
2403 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
2404
2405 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2406 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2407 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2408 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002409 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002410 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002411
2412 // The dimension of the respecification must match the original exactly to trigger the bug.
2413 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 +02002414 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002415 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002416
2417 ASSERT_GL_NO_ERROR();
2418}
2419
Olli Etuaho1a679902016-01-14 12:21:47 +02002420// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2421// This test is needed especially to confirm that sampler registers get assigned correctly on
2422// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2423TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2424{
2425 glActiveTexture(GL_TEXTURE0);
2426 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2427 GLubyte texData[4];
2428 texData[0] = 0;
2429 texData[1] = 60;
2430 texData[2] = 0;
2431 texData[3] = 255;
2432 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2433
2434 glActiveTexture(GL_TEXTURE1);
2435 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2436 GLfloat depthTexData[1];
2437 depthTexData[0] = 0.5f;
2438 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2439 depthTexData);
2440
2441 glUseProgram(mProgram);
2442 glUniform1f(mDepthRefUniformLocation, 0.3f);
2443 glUniform1i(mTexture3DUniformLocation, 0);
2444 glUniform1i(mTextureShadowUniformLocation, 1);
2445
2446 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2447 drawQuad(mProgram, "position", 0.5f);
2448 EXPECT_GL_NO_ERROR();
2449 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2450 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2451
2452 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2453 drawQuad(mProgram, "position", 0.5f);
2454 EXPECT_GL_NO_ERROR();
2455 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2456 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2457}
2458
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002459// Test multiple different sampler types in the same shader.
2460// This test makes sure that even if sampler / texture registers get grouped together based on type
2461// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2462// still has the right register index information for each ESSL sampler.
2463// The tested ESSL samplers have the following types in D3D11 HLSL:
2464// sampler2D: Texture2D + SamplerState
2465// samplerCube: TextureCube + SamplerState
2466// sampler2DShadow: Texture2D + SamplerComparisonState
2467// samplerCubeShadow: TextureCube + SamplerComparisonState
2468TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2469{
2470 glActiveTexture(GL_TEXTURE0);
2471 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2472 GLubyte texData[4];
2473 texData[0] = 0;
2474 texData[1] = 0;
2475 texData[2] = 120;
2476 texData[3] = 255;
2477 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2478
2479 glActiveTexture(GL_TEXTURE1);
2480 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2481 texData[0] = 0;
2482 texData[1] = 90;
2483 texData[2] = 0;
2484 texData[3] = 255;
2485 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2486 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2487 texData);
2488
2489 glActiveTexture(GL_TEXTURE2);
2490 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2491 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2492 GLfloat depthTexData[1];
2493 depthTexData[0] = 0.5f;
2494 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2495 depthTexData);
2496
2497 glActiveTexture(GL_TEXTURE3);
2498 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2499 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2500 depthTexData[0] = 0.2f;
2501 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2502 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2503 depthTexData);
2504
2505 EXPECT_GL_NO_ERROR();
2506
2507 glUseProgram(mProgram);
2508 glUniform1f(mDepthRefUniformLocation, 0.3f);
2509 glUniform1i(mTexture2DUniformLocation, 0);
2510 glUniform1i(mTextureCubeUniformLocation, 1);
2511 glUniform1i(mTexture2DShadowUniformLocation, 2);
2512 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2513
2514 drawQuad(mProgram, "position", 0.5f);
2515 EXPECT_GL_NO_ERROR();
2516 // The shader writes:
2517 // <texture 2d color> +
2518 // <cube map color> +
2519 // 0.25 * <comparison result (1.0)> +
2520 // 0.125 * <comparison result (0.0)>
2521 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2522}
2523
Olli Etuahobce743a2016-01-15 17:18:28 +02002524// Test different base levels on textures accessed through the same sampler array.
2525// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2526TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2527{
Jiangd9227752017-10-19 16:23:07 +08002528 if (IsAMD() && IsD3D11())
Olli Etuahobce743a2016-01-15 17:18:28 +02002529 {
Jiangd9227752017-10-19 16:23:07 +08002530 std::cout << "Test skipped on AMD D3D." << std::endl;
Olli Etuahobce743a2016-01-15 17:18:28 +02002531 return;
2532 }
2533 glActiveTexture(GL_TEXTURE0);
2534 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2535 GLsizei size = 64;
2536 for (GLint level = 0; level < 7; ++level)
2537 {
2538 ASSERT_LT(0, size);
2539 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2540 nullptr);
2541 size = size / 2;
2542 }
2543 ASSERT_EQ(0, size);
2544 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2545
2546 glActiveTexture(GL_TEXTURE1);
2547 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2548 size = 128;
2549 for (GLint level = 0; level < 8; ++level)
2550 {
2551 ASSERT_LT(0, size);
2552 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2553 nullptr);
2554 size = size / 2;
2555 }
2556 ASSERT_EQ(0, size);
2557 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2558 EXPECT_GL_NO_ERROR();
2559
2560 glUseProgram(mProgram);
2561 glUniform1i(mTexture0Location, 0);
2562 glUniform1i(mTexture1Location, 1);
2563
2564 drawQuad(mProgram, "position", 0.5f);
2565 EXPECT_GL_NO_ERROR();
2566 // Red channel: width of level 1 of texture A: 32.
2567 // Green channel: width of level 3 of texture B: 16.
2568 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2569}
2570
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002571// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2572// ES 3.0.4 table 3.24
2573TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2574{
2575 glActiveTexture(GL_TEXTURE0);
2576 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2577 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2578 EXPECT_GL_NO_ERROR();
2579
2580 drawQuad(mProgram, "position", 0.5f);
2581
2582 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2583}
2584
2585// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2586// ES 3.0.4 table 3.24
2587TEST_P(Texture2DTestES3, TextureLuminanceImplicitAlpha1)
2588{
2589 glActiveTexture(GL_TEXTURE0);
2590 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2591 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2592 EXPECT_GL_NO_ERROR();
2593
2594 drawQuad(mProgram, "position", 0.5f);
2595
2596 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2597}
2598
2599// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2600// ES 3.0.4 table 3.24
2601TEST_P(Texture2DTestES3, TextureLuminance32ImplicitAlpha1)
2602{
2603 if (extensionEnabled("GL_OES_texture_float"))
2604 {
2605 glActiveTexture(GL_TEXTURE0);
2606 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2607 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2608 EXPECT_GL_NO_ERROR();
2609
2610 drawQuad(mProgram, "position", 0.5f);
2611
2612 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2613 }
2614}
2615
2616// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2617// ES 3.0.4 table 3.24
2618TEST_P(Texture2DTestES3, TextureLuminance16ImplicitAlpha1)
2619{
2620 if (extensionEnabled("GL_OES_texture_half_float"))
2621 {
Yuly Novikovafcec832016-06-21 22:19:51 -04002622 if (IsNVIDIA() && IsOpenGLES())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002623 {
2624 std::cout << "Test skipped on NVIDIA" << std::endl;
2625 return;
2626 }
Yuly Novikovafcec832016-06-21 22:19:51 -04002627 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2628 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2629 {
2630 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2631 return;
2632 }
2633
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002634 glActiveTexture(GL_TEXTURE0);
2635 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2636 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES,
2637 nullptr);
2638 EXPECT_GL_NO_ERROR();
2639
2640 drawQuad(mProgram, "position", 0.5f);
2641
2642 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2643 }
2644}
2645
2646// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2647// ES 3.0.4 table 3.24
2648TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2649{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002650 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002651 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002652 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002653 return;
2654 }
2655 glActiveTexture(GL_TEXTURE0);
2656 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2657 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2658 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2659 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2660 EXPECT_GL_NO_ERROR();
2661
2662 drawQuad(mProgram, "position", 0.5f);
2663
2664 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2665}
2666
2667// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2668// ES 3.0.4 table 3.24
2669TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2670{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002671 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002672 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002673 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002674 return;
2675 }
2676 glActiveTexture(GL_TEXTURE0);
2677 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2678
2679 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2680 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2681 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2682 EXPECT_GL_NO_ERROR();
2683
2684 drawQuad(mProgram, "position", 0.5f);
2685
2686 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2687}
2688
2689// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2690// ES 3.0.4 table 3.24
2691TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2692{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002693 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002694 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002695 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002696 return;
2697 }
2698 glActiveTexture(GL_TEXTURE0);
2699 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2700 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2701 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2702 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2703 EXPECT_GL_NO_ERROR();
2704
2705 drawQuad(mProgram, "position", 0.5f);
2706
2707 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2708}
2709
2710// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2711// ES 3.0.4 table 3.24
2712TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2713{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002714 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002715 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002716 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002717 return;
2718 }
2719 glActiveTexture(GL_TEXTURE0);
2720 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2721 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2722 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2723 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2724 EXPECT_GL_NO_ERROR();
2725
2726 drawQuad(mProgram, "position", 0.5f);
2727
2728 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2729}
2730
2731// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2732// ES 3.0.4 table 3.24
2733TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2734{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002735 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002736 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002737 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002738 return;
2739 }
2740 glActiveTexture(GL_TEXTURE0);
2741 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2742 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2743 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2744 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2745 EXPECT_GL_NO_ERROR();
2746
2747 drawQuad(mProgram, "position", 0.5f);
2748
2749 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2750}
2751
2752// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2753// ES 3.0.4 table 3.24
2754TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2755{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002756 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002757 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002758 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002759 return;
2760 }
2761 glActiveTexture(GL_TEXTURE0);
2762 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2763 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2764 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2765 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2766 EXPECT_GL_NO_ERROR();
2767
2768 drawQuad(mProgram, "position", 0.5f);
2769
2770 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2771}
2772
2773// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2774// ES 3.0.4 table 3.24
2775TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2776{
2777 glActiveTexture(GL_TEXTURE0);
2778 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2779 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2780 EXPECT_GL_NO_ERROR();
2781
2782 drawQuad(mProgram, "position", 0.5f);
2783
2784 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2785}
2786
2787// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2788// ES 3.0.4 table 3.24
2789TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2790{
2791 glActiveTexture(GL_TEXTURE0);
2792 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2793 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2794 nullptr);
2795 EXPECT_GL_NO_ERROR();
2796
2797 drawQuad(mProgram, "position", 0.5f);
2798
2799 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2800}
2801
2802// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2803// ES 3.0.4 table 3.24
2804TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2805{
Jamie Madillbb1db482017-01-10 10:48:32 -05002806 if (IsOSX() && IsIntel() && IsOpenGL())
2807 {
2808 // Seems to fail on OSX 10.12 Intel.
2809 std::cout << "Test skipped on OSX Intel." << std::endl;
2810 return;
2811 }
2812
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002813 glActiveTexture(GL_TEXTURE0);
2814 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2815 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2816 EXPECT_GL_NO_ERROR();
2817
2818 drawQuad(mProgram, "position", 0.5f);
2819
2820 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2821}
2822
2823// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2824// ES 3.0.4 table 3.24
2825TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2826{
Jamie Madillbb1db482017-01-10 10:48:32 -05002827 if (IsIntel() && IsOpenGL() && (IsLinux() || IsOSX()))
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002828 {
2829 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
Jamie Madillbb1db482017-01-10 10:48:32 -05002830 // Also seems to fail on OSX 10.12 Intel.
2831 std::cout << "Test disabled on Linux and OSX Intel OpenGL." << std::endl;
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002832 return;
2833 }
2834
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002835 glActiveTexture(GL_TEXTURE0);
2836 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2837 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2838 EXPECT_GL_NO_ERROR();
2839
2840 drawQuad(mProgram, "position", 0.5f);
2841
2842 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2843}
2844
Olli Etuaho96963162016-03-21 11:54:33 +02002845// Use a sampler in a uniform struct.
2846TEST_P(SamplerInStructTest, SamplerInStruct)
2847{
2848 runSamplerInStructTest();
2849}
2850
2851// Use a sampler in a uniform struct that's passed as a function parameter.
2852TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2853{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002854 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2855 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2856 {
2857 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2858 return;
2859 }
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002860
Olli Etuaho96963162016-03-21 11:54:33 +02002861 runSamplerInStructTest();
2862}
2863
2864// Use a sampler in a uniform struct array with a struct from the array passed as a function
2865// parameter.
2866TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2867{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002868 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2869 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2870 {
2871 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2872 return;
2873 }
Olli Etuaho96963162016-03-21 11:54:33 +02002874 runSamplerInStructTest();
2875}
2876
2877// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2878// parameter.
2879TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2880{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002881 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2882 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2883 {
2884 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2885 return;
2886 }
Olli Etuaho96963162016-03-21 11:54:33 +02002887 runSamplerInStructTest();
2888}
2889
2890// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2891// similarly named uniform.
2892TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2893{
2894 runSamplerInStructTest();
2895}
2896
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002897class TextureLimitsTest : public ANGLETest
2898{
2899 protected:
2900 struct RGBA8
2901 {
2902 uint8_t R, G, B, A;
2903 };
2904
2905 TextureLimitsTest()
2906 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
2907 {
2908 setWindowWidth(128);
2909 setWindowHeight(128);
2910 setConfigRedBits(8);
2911 setConfigGreenBits(8);
2912 setConfigBlueBits(8);
2913 setConfigAlphaBits(8);
2914 }
2915
2916 ~TextureLimitsTest()
2917 {
2918 if (mProgram != 0)
2919 {
2920 glDeleteProgram(mProgram);
2921 mProgram = 0;
2922
2923 if (!mTextures.empty())
2924 {
2925 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
2926 }
2927 }
2928 }
2929
2930 void SetUp() override
2931 {
2932 ANGLETest::SetUp();
2933
2934 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
2935 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
2936 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
2937
2938 ASSERT_GL_NO_ERROR();
2939 }
2940
2941 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
2942 GLint vertexTextureCount,
2943 GLint vertexActiveTextureCount,
2944 const std::string &fragPrefix,
2945 GLint fragmentTextureCount,
2946 GLint fragmentActiveTextureCount)
2947 {
2948 std::stringstream vertexShaderStr;
2949 vertexShaderStr << "attribute vec2 position;\n"
2950 << "varying vec4 color;\n"
2951 << "varying vec2 texCoord;\n";
2952
2953 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
2954 {
2955 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
2956 }
2957
2958 vertexShaderStr << "void main() {\n"
2959 << " gl_Position = vec4(position, 0, 1);\n"
2960 << " texCoord = (position * 0.5) + 0.5;\n"
2961 << " color = vec4(0);\n";
2962
2963 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
2964 {
2965 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
2966 << ", texCoord);\n";
2967 }
2968
2969 vertexShaderStr << "}";
2970
2971 std::stringstream fragmentShaderStr;
2972 fragmentShaderStr << "varying mediump vec4 color;\n"
2973 << "varying mediump vec2 texCoord;\n";
2974
2975 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
2976 {
2977 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
2978 }
2979
2980 fragmentShaderStr << "void main() {\n"
2981 << " gl_FragColor = color;\n";
2982
2983 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
2984 {
2985 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
2986 << ", texCoord);\n";
2987 }
2988
2989 fragmentShaderStr << "}";
2990
2991 const std::string &vertexShaderSource = vertexShaderStr.str();
2992 const std::string &fragmentShaderSource = fragmentShaderStr.str();
2993
2994 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
2995 }
2996
2997 RGBA8 getPixel(GLint texIndex)
2998 {
2999 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3000 0, 255u};
3001 return pixel;
3002 }
3003
3004 void initTextures(GLint tex2DCount, GLint texCubeCount)
3005 {
3006 GLint totalCount = tex2DCount + texCubeCount;
3007 mTextures.assign(totalCount, 0);
3008 glGenTextures(totalCount, &mTextures[0]);
3009 ASSERT_GL_NO_ERROR();
3010
3011 std::vector<RGBA8> texData(16 * 16);
3012
3013 GLint texIndex = 0;
3014 for (; texIndex < tex2DCount; ++texIndex)
3015 {
3016 texData.assign(texData.size(), getPixel(texIndex));
3017 glActiveTexture(GL_TEXTURE0 + texIndex);
3018 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3019 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3020 &texData[0]);
3021 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3022 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3023 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3024 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3025 }
3026
3027 ASSERT_GL_NO_ERROR();
3028
3029 for (; texIndex < texCubeCount; ++texIndex)
3030 {
3031 texData.assign(texData.size(), getPixel(texIndex));
3032 glActiveTexture(GL_TEXTURE0 + texIndex);
3033 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3034 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3035 GL_UNSIGNED_BYTE, &texData[0]);
3036 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3037 GL_UNSIGNED_BYTE, &texData[0]);
3038 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3039 GL_UNSIGNED_BYTE, &texData[0]);
3040 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3041 GL_UNSIGNED_BYTE, &texData[0]);
3042 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3043 GL_UNSIGNED_BYTE, &texData[0]);
3044 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3045 GL_UNSIGNED_BYTE, &texData[0]);
3046 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3047 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3048 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3049 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3050 }
3051
3052 ASSERT_GL_NO_ERROR();
3053 }
3054
3055 void testWithTextures(GLint vertexTextureCount,
3056 const std::string &vertexTexturePrefix,
3057 GLint fragmentTextureCount,
3058 const std::string &fragmentTexturePrefix)
3059 {
3060 // Generate textures
3061 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3062
3063 glUseProgram(mProgram);
3064 RGBA8 expectedSum = {0};
3065 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3066 {
3067 std::stringstream uniformNameStr;
3068 uniformNameStr << vertexTexturePrefix << texIndex;
3069 const std::string &uniformName = uniformNameStr.str();
3070 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
3071 ASSERT_NE(-1, location);
3072
3073 glUniform1i(location, texIndex);
3074 RGBA8 contribution = getPixel(texIndex);
3075 expectedSum.R += contribution.R;
3076 expectedSum.G += contribution.G;
3077 }
3078
3079 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3080 {
3081 std::stringstream uniformNameStr;
3082 uniformNameStr << fragmentTexturePrefix << texIndex;
3083 const std::string &uniformName = uniformNameStr.str();
3084 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
3085 ASSERT_NE(-1, location);
3086
3087 glUniform1i(location, texIndex + vertexTextureCount);
3088 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3089 expectedSum.R += contribution.R;
3090 expectedSum.G += contribution.G;
3091 }
3092
3093 ASSERT_GE(256u, expectedSum.G);
3094
3095 drawQuad(mProgram, "position", 0.5f);
3096 ASSERT_GL_NO_ERROR();
3097 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3098 }
3099
3100 GLuint mProgram;
3101 std::vector<GLuint> mTextures;
3102 GLint mMaxVertexTextures;
3103 GLint mMaxFragmentTextures;
3104 GLint mMaxCombinedTextures;
3105};
3106
3107// Test rendering with the maximum vertex texture units.
3108TEST_P(TextureLimitsTest, MaxVertexTextures)
3109{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003110 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003111 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003112 {
3113 std::cout << "Test skipped on Intel." << std::endl;
3114 return;
3115 }
3116
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003117 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3118 ASSERT_NE(0u, mProgram);
3119 ASSERT_GL_NO_ERROR();
3120
3121 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3122}
3123
3124// Test rendering with the maximum fragment texture units.
3125TEST_P(TextureLimitsTest, MaxFragmentTextures)
3126{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003127 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003128 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003129 {
3130 std::cout << "Test skipped on Intel." << std::endl;
3131 return;
3132 }
3133
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003134 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3135 ASSERT_NE(0u, mProgram);
3136 ASSERT_GL_NO_ERROR();
3137
3138 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3139}
3140
3141// Test rendering with maximum combined texture units.
3142TEST_P(TextureLimitsTest, MaxCombinedTextures)
3143{
Jamie Madill412f17d2015-09-25 08:43:54 -04003144 // TODO(jmadill): Investigate workaround.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003145 if (IsIntel() && GetParam() == ES2_OPENGL())
Jamie Madill412f17d2015-09-25 08:43:54 -04003146 {
3147 std::cout << "Test skipped on Intel." << std::endl;
3148 return;
3149 }
3150
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003151 GLint vertexTextures = mMaxVertexTextures;
3152
3153 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3154 {
3155 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3156 }
3157
3158 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3159 mMaxFragmentTextures, mMaxFragmentTextures);
3160 ASSERT_NE(0u, mProgram);
3161 ASSERT_GL_NO_ERROR();
3162
3163 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3164}
3165
3166// Negative test for exceeding the number of vertex textures
3167TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3168{
3169 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3170 0);
3171 ASSERT_EQ(0u, mProgram);
3172}
3173
3174// Negative test for exceeding the number of fragment textures
3175TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3176{
3177 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3178 mMaxFragmentTextures + 1);
3179 ASSERT_EQ(0u, mProgram);
3180}
3181
3182// Test active vertex textures under the limit, but excessive textures specified.
3183TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3184{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003185 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003186 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003187 {
3188 std::cout << "Test skipped on Intel." << std::endl;
3189 return;
3190 }
3191
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003192 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3193 ASSERT_NE(0u, mProgram);
3194 ASSERT_GL_NO_ERROR();
3195
3196 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3197}
3198
3199// Test active fragment textures under the limit, but excessive textures specified.
3200TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3201{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003202 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003203 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003204 {
3205 std::cout << "Test skipped on Intel." << std::endl;
3206 return;
3207 }
3208
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003209 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3210 mMaxFragmentTextures);
3211 ASSERT_NE(0u, mProgram);
3212 ASSERT_GL_NO_ERROR();
3213
3214 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3215}
3216
3217// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003218// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003219TEST_P(TextureLimitsTest, TextureTypeConflict)
3220{
3221 const std::string &vertexShader =
3222 "attribute vec2 position;\n"
3223 "varying float color;\n"
3224 "uniform sampler2D tex2D;\n"
3225 "uniform samplerCube texCube;\n"
3226 "void main() {\n"
3227 " gl_Position = vec4(position, 0, 1);\n"
3228 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3229 " color = texture2D(tex2D, texCoord).x;\n"
3230 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3231 "}";
3232 const std::string &fragmentShader =
3233 "varying mediump float color;\n"
3234 "void main() {\n"
3235 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3236 "}";
3237
3238 mProgram = CompileProgram(vertexShader, fragmentShader);
3239 ASSERT_NE(0u, mProgram);
3240
3241 initTextures(1, 0);
3242
3243 glUseProgram(mProgram);
3244 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3245 ASSERT_NE(-1, tex2DLocation);
3246 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3247 ASSERT_NE(-1, texCubeLocation);
3248
3249 glUniform1i(tex2DLocation, 0);
3250 glUniform1i(texCubeLocation, 0);
3251 ASSERT_GL_NO_ERROR();
3252
3253 drawQuad(mProgram, "position", 0.5f);
3254 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3255}
3256
Vincent Lang25ab4512016-05-13 18:13:59 +02003257class Texture2DNorm16TestES3 : public Texture2DTestES3
3258{
3259 protected:
3260 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3261
3262 void SetUp() override
3263 {
3264 Texture2DTestES3::SetUp();
3265
3266 glActiveTexture(GL_TEXTURE0);
3267 glGenTextures(3, mTextures);
3268 glGenFramebuffers(1, &mFBO);
3269 glGenRenderbuffers(1, &mRenderbuffer);
3270
3271 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3272 {
3273 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3274 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3275 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3276 }
3277
3278 glBindTexture(GL_TEXTURE_2D, 0);
3279
3280 ASSERT_GL_NO_ERROR();
3281 }
3282
3283 void TearDown() override
3284 {
3285 glDeleteTextures(3, mTextures);
3286 glDeleteFramebuffers(1, &mFBO);
3287 glDeleteRenderbuffers(1, &mRenderbuffer);
3288
3289 Texture2DTestES3::TearDown();
3290 }
3291
3292 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3293 {
Geoff Langf607c602016-09-21 11:46:48 -04003294 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3295 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003296
3297 setUpProgram();
3298
3299 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3300 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3301 0);
3302
3303 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3304 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3305
3306 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003307 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003308
3309 EXPECT_GL_NO_ERROR();
3310
3311 drawQuad(mProgram, "position", 0.5f);
3312
Geoff Langf607c602016-09-21 11:46:48 -04003313 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003314
Geoff Langf607c602016-09-21 11:46:48 -04003315 EXPECT_PIXEL_COLOR_EQ(
3316 0, 0, SliceFormatColor(
3317 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003318
3319 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3320
3321 ASSERT_GL_NO_ERROR();
3322 }
3323
3324 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3325 {
3326 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003327 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003328
3329 setUpProgram();
3330
3331 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3332 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3333
3334 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3335 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3336 0);
3337
3338 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003339 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003340
3341 EXPECT_GL_NO_ERROR();
3342
3343 drawQuad(mProgram, "position", 0.5f);
3344
Geoff Langf607c602016-09-21 11:46:48 -04003345 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
3346 EXPECT_PIXEL_COLOR_EQ(
3347 0, 0, SliceFormatColor(
3348 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003349
3350 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3351 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3352 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3353 mRenderbuffer);
3354 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3355 EXPECT_GL_NO_ERROR();
3356
3357 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3358 glClear(GL_COLOR_BUFFER_BIT);
3359
3360 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3361
Geoff Langf607c602016-09-21 11:46:48 -04003362 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003363
3364 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3365
3366 ASSERT_GL_NO_ERROR();
3367 }
3368
3369 GLuint mTextures[3];
3370 GLuint mFBO;
3371 GLuint mRenderbuffer;
3372};
3373
3374// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3375TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3376{
3377 if (!extensionEnabled("GL_EXT_texture_norm16"))
3378 {
3379 std::cout << "Test skipped due to missing GL_EXT_texture_norm16." << std::endl;
3380 return;
3381 }
3382
3383 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3384 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3385 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3386 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3387 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3388 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3389 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3390 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3391
3392 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3393 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3394 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3395}
3396
Olli Etuaho95faa232016-06-07 14:01:53 -07003397// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3398// GLES 3.0.4 section 3.8.3.
3399TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3400{
Corentin Wallezc7f59d02016-06-20 10:12:08 -04003401 if (IsIntel() && IsDesktopOpenGL())
Olli Etuaho95faa232016-06-07 14:01:53 -07003402 {
3403 std::cout << "Test skipped on Intel OpenGL." << std::endl;
3404 return;
3405 }
Yuly Novikov3c754192016-06-27 19:36:41 -04003406 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1429 is fixed
3407 if (IsAndroid() && IsAdreno() && IsOpenGLES())
3408 {
3409 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
3410 return;
3411 }
Olli Etuaho95faa232016-06-07 14:01:53 -07003412
3413 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3414 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3415 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3416 ASSERT_GL_NO_ERROR();
3417
3418 // SKIP_IMAGES should not have an effect on uploading 2D textures
3419 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3420 ASSERT_GL_NO_ERROR();
3421
3422 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3423
3424 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3425 pixelsGreen.data());
3426 ASSERT_GL_NO_ERROR();
3427
3428 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3429 pixelsGreen.data());
3430 ASSERT_GL_NO_ERROR();
3431
3432 glUseProgram(mProgram);
3433 drawQuad(mProgram, "position", 0.5f);
3434 ASSERT_GL_NO_ERROR();
3435
3436 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3437}
3438
Olli Etuaho989cac32016-06-08 16:18:49 -07003439// Test that skip defined in unpack parameters is taken into account when determining whether
3440// unpacking source extends outside unpack buffer bounds.
3441TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3442{
3443 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3444 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3445 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3446 ASSERT_GL_NO_ERROR();
3447
3448 GLBuffer buf;
3449 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3450 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3451 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3452 GL_DYNAMIC_COPY);
3453 ASSERT_GL_NO_ERROR();
3454
3455 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3456 ASSERT_GL_NO_ERROR();
3457
3458 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3459 ASSERT_GL_NO_ERROR();
3460
3461 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3462 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3463
3464 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3465 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3466 ASSERT_GL_NO_ERROR();
3467
3468 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3469 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3470}
3471
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003472// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3473TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3474{
3475 if (IsD3D11())
3476 {
3477 std::cout << "Test skipped on D3D." << std::endl;
3478 return;
3479 }
3480 if (IsOSX() && IsAMD())
3481 {
3482 // Incorrect rendering results seen on OSX AMD.
3483 std::cout << "Test skipped on OSX AMD." << std::endl;
3484 return;
3485 }
3486
3487 const GLuint width = 8u;
3488 const GLuint height = 8u;
3489 const GLuint unpackRowLength = 5u;
3490 const GLuint unpackSkipPixels = 1u;
3491
3492 setWindowWidth(width);
3493 setWindowHeight(height);
3494
3495 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3496 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3497 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3498 ASSERT_GL_NO_ERROR();
3499
3500 GLBuffer buf;
3501 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3502 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3503 GLColor::green);
3504
3505 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3506 {
3507 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3508 }
3509
3510 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3511 GL_DYNAMIC_COPY);
3512 ASSERT_GL_NO_ERROR();
3513
3514 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3515 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3516 ASSERT_GL_NO_ERROR();
3517
3518 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3519 ASSERT_GL_NO_ERROR();
3520
3521 glUseProgram(mProgram);
3522 drawQuad(mProgram, "position", 0.5f);
3523 ASSERT_GL_NO_ERROR();
3524
3525 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3526 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3527 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3528 actual.data());
3529 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3530 EXPECT_EQ(expected, actual);
3531}
3532
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003533template <typename T>
3534T UNorm(double value)
3535{
3536 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3537}
3538
3539// Test rendering a depth texture with mipmaps.
3540TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3541{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003542 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3543 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
3544 // http://anglebugs.com/1706
3545 if (IsIntel() && IsWindows())
Corentin Walleze731d8a2016-09-07 10:56:25 -04003546 {
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003547 std::cout << "Test skipped on Win Intel." << std::endl;
Corentin Walleze731d8a2016-09-07 10:56:25 -04003548 return;
3549 }
3550
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003551 const int size = getWindowWidth();
3552
3553 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003554 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003555
3556 glActiveTexture(GL_TEXTURE0);
3557 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3558 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3559 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3560 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3561 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3562 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3563 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3564 ASSERT_GL_NO_ERROR();
3565
3566 glUseProgram(mProgram);
3567 glUniform1i(mTexture2DUniformLocation, 0);
3568
3569 std::vector<unsigned char> expected;
3570
3571 for (int level = 0; level < levels; ++level)
3572 {
3573 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3574 expected.push_back(UNorm<unsigned char>(value));
3575
3576 int levelDim = dim(level);
3577
3578 ASSERT_GT(levelDim, 0);
3579
3580 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3581 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3582 GL_UNSIGNED_INT, initData.data());
3583 }
3584 ASSERT_GL_NO_ERROR();
3585
3586 for (int level = 0; level < levels; ++level)
3587 {
3588 glViewport(0, 0, dim(level), dim(level));
3589 drawQuad(mProgram, "position", 0.5f);
3590 GLColor actual = ReadColor(0, 0);
3591 EXPECT_NEAR(expected[level], actual.R, 10u);
3592 }
3593
3594 ASSERT_GL_NO_ERROR();
3595}
3596
Jamie Madill7ffdda92016-09-08 13:26:51 -04003597// Tests unpacking into the unsized GL_ALPHA format.
3598TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3599{
3600 // TODO(jmadill): Figure out why this fails on OSX.
3601 ANGLE_SKIP_TEST_IF(IsOSX());
3602
3603 // Initialize the texure.
3604 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3605 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3606 GL_UNSIGNED_BYTE, nullptr);
3607 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3608 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3609
3610 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3611
3612 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04003613 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04003614 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3615 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3616 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
3617 GL_STATIC_DRAW);
3618
3619 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
3620 GL_UNSIGNED_BYTE, nullptr);
3621
3622 // Clear to a weird color to make sure we're drawing something.
3623 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
3624 glClear(GL_COLOR_BUFFER_BIT);
3625
3626 // Draw with the alpha texture and verify.
3627 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04003628
3629 ASSERT_GL_NO_ERROR();
3630 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
3631}
3632
Jamie Madill2e600342016-09-19 13:56:40 -04003633// Ensure stale unpack data doesn't propagate in D3D11.
3634TEST_P(Texture2DTestES3, StaleUnpackData)
3635{
3636 // Init unpack buffer.
3637 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
3638 std::vector<GLColor> pixels(pixelCount, GLColor::red);
3639
3640 GLBuffer unpackBuffer;
3641 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3642 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3643 GLsizei bufferSize = pixelCount * sizeof(GLColor);
3644 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
3645
3646 // Create from unpack buffer.
3647 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3648 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
3649 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3650 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3651 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3652
3653 drawQuad(mProgram, "position", 0.5f);
3654
3655 ASSERT_GL_NO_ERROR();
3656 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3657
3658 // Fill unpack with green, recreating buffer.
3659 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
3660 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
3661 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
3662
3663 // Reinit texture with green.
3664 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
3665 GL_UNSIGNED_BYTE, nullptr);
3666
3667 drawQuad(mProgram, "position", 0.5f);
3668
3669 ASSERT_GL_NO_ERROR();
3670 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3671}
3672
Jamie Madillf097e232016-11-05 00:44:15 -04003673// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
3674// being properly checked, and the texture storage of the previous texture format was persisting.
3675// This would result in an ASSERT in debug and incorrect rendering in release.
3676// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
3677TEST_P(Texture3DTestES3, FormatRedefinitionBug)
3678{
3679 GLTexture tex;
3680 glBindTexture(GL_TEXTURE_3D, tex.get());
3681 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3682
3683 GLFramebuffer framebuffer;
3684 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3685 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
3686
3687 glCheckFramebufferStatus(GL_FRAMEBUFFER);
3688
3689 std::vector<uint8_t> pixelData(100, 0);
3690
3691 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
3692 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
3693 pixelData.data());
3694
3695 ASSERT_GL_NO_ERROR();
3696}
3697
Corentin Wallezd2627992017-04-28 17:17:03 -04003698// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
3699TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
3700{
3701 // 2D tests
3702 {
3703 GLTexture tex;
3704 glBindTexture(GL_TEXTURE_2D, tex.get());
3705
3706 GLBuffer pbo;
3707 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3708
3709 // Test OOB
3710 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
3711 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3712 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3713
3714 // Test OOB
3715 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
3716 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3717 ASSERT_GL_NO_ERROR();
3718 }
3719
3720 // 3D tests
3721 {
3722 GLTexture tex;
3723 glBindTexture(GL_TEXTURE_3D, tex.get());
3724
3725 GLBuffer pbo;
3726 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3727
3728 // Test OOB
3729 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
3730 GL_STATIC_DRAW);
3731 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3732 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3733
3734 // Test OOB
3735 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
3736 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3737 ASSERT_GL_NO_ERROR();
3738 }
3739}
3740
Jamie Madill3ed60422017-09-07 11:32:52 -04003741// Tests behaviour with a single texture and multiple sampler objects.
3742TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
3743{
3744 GLint maxTextureUnits = 0;
3745 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
3746 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
3747
3748 constexpr int kSize = 16;
3749
3750 // Make a single-level texture, fill it with red.
3751 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
3752 GLTexture tex;
3753 glBindTexture(GL_TEXTURE_2D, tex);
3754 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3755 redColors.data());
3756 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3757 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3758
3759 // Simple sanity check.
3760 draw2DTexturedQuad(0.5f, 1.0f, true);
3761 ASSERT_GL_NO_ERROR();
3762 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3763
3764 // Bind texture to unit 1 with a sampler object making it incomplete.
3765 GLSampler sampler;
3766 glBindSampler(0, sampler);
3767 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3768 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3769
3770 // Make a mipmap texture, fill it with blue.
3771 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
3772 GLTexture mipmapTex;
3773 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3774 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3775 blueColors.data());
3776 glGenerateMipmap(GL_TEXTURE_2D);
3777
3778 // Draw with the sampler, expect blue.
3779 draw2DTexturedQuad(0.5f, 1.0f, true);
3780 ASSERT_GL_NO_ERROR();
3781 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
3782
3783 // Simple multitexturing program.
3784 const std::string vs =
3785 "#version 300 es\n"
3786 "in vec2 position;\n"
3787 "out vec2 texCoord;\n"
3788 "void main()\n"
3789 "{\n"
3790 " gl_Position = vec4(position, 0, 1);\n"
3791 " texCoord = position * 0.5 + vec2(0.5);\n"
3792 "}";
3793 const std::string fs =
3794 "#version 300 es\n"
3795 "precision mediump float;\n"
3796 "in vec2 texCoord;\n"
3797 "uniform sampler2D tex1;\n"
3798 "uniform sampler2D tex2;\n"
3799 "uniform sampler2D tex3;\n"
3800 "uniform sampler2D tex4;\n"
3801 "out vec4 color;\n"
3802 "void main()\n"
3803 "{\n"
3804 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
3805 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
3806 "}";
3807
3808 ANGLE_GL_PROGRAM(program, vs, fs);
3809
3810 std::array<GLint, 4> texLocations = {
3811 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
3812 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
3813 for (GLint location : texLocations)
3814 {
3815 ASSERT_NE(-1, location);
3816 }
3817
3818 // Init the uniform data.
3819 glUseProgram(program);
3820 for (GLint location = 0; location < 4; ++location)
3821 {
3822 glUniform1i(texLocations[location], location);
3823 }
3824
3825 // Initialize four samplers
3826 GLSampler samplers[4];
3827
3828 // 0: non-mipped.
3829 glBindSampler(0, samplers[0]);
3830 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3831 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3832
3833 // 1: mipped.
3834 glBindSampler(1, samplers[1]);
3835 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3836 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3837
3838 // 2: non-mipped.
3839 glBindSampler(2, samplers[2]);
3840 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3841 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3842
3843 // 3: mipped.
3844 glBindSampler(3, samplers[3]);
3845 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3846 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3847
3848 // Bind two blue mipped textures and two single layer textures, should all draw.
3849 glActiveTexture(GL_TEXTURE0);
3850 glBindTexture(GL_TEXTURE_2D, tex);
3851
3852 glActiveTexture(GL_TEXTURE1);
3853 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3854
3855 glActiveTexture(GL_TEXTURE2);
3856 glBindTexture(GL_TEXTURE_2D, tex);
3857
3858 glActiveTexture(GL_TEXTURE3);
3859 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3860
3861 ASSERT_GL_NO_ERROR();
3862
3863 drawQuad(program, "position", 0.5f);
3864 ASSERT_GL_NO_ERROR();
3865 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
3866
3867 // Bind four single layer textures, two should be incomplete.
3868 glActiveTexture(GL_TEXTURE1);
3869 glBindTexture(GL_TEXTURE_2D, tex);
3870
3871 glActiveTexture(GL_TEXTURE3);
3872 glBindTexture(GL_TEXTURE_2D, tex);
3873
3874 drawQuad(program, "position", 0.5f);
3875 ASSERT_GL_NO_ERROR();
3876 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
3877}
3878
Martin Radev7e2c0d32017-09-15 14:25:42 +03003879// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
3880// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
3881// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
3882// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
3883// samples the cubemap using a direction vector (1,1,1).
3884TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
3885{
3886 if (IsOSX())
3887 {
3888 // Check http://anglebug.com/2155.
3889 std::cout << "Test skipped on OSX." << std::endl;
3890 return;
3891 }
3892 const std::string vs =
3893 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003894 precision mediump float;
3895 in vec3 pos;
3896 void main() {
3897 gl_Position = vec4(pos, 1.0);
3898 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003899
3900 const std::string fs =
3901 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003902 precision mediump float;
3903 out vec4 color;
3904 uniform samplerCube uTex;
3905 void main(){
3906 color = texture(uTex, vec3(1.0));
3907 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003908 ANGLE_GL_PROGRAM(program, vs, fs);
3909 glUseProgram(program);
3910
3911 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
3912 glActiveTexture(GL_TEXTURE0);
3913
3914 GLTexture cubeTex;
3915 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
3916
3917 const int kFaceWidth = 1;
3918 const int kFaceHeight = 1;
3919 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
3920 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3921 GL_UNSIGNED_BYTE, texData.data());
3922 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3923 GL_UNSIGNED_BYTE, texData.data());
3924 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3925 GL_UNSIGNED_BYTE, texData.data());
3926 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3927 GL_UNSIGNED_BYTE, texData.data());
3928 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3929 GL_UNSIGNED_BYTE, texData.data());
3930 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3931 GL_UNSIGNED_BYTE, texData.data());
3932 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3933 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3934 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
3935 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
3936 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
3937 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
3938
3939 drawQuad(program, "pos", 0.5f, 1.0f, true);
3940 ASSERT_GL_NO_ERROR();
3941
3942 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
3943}
3944
Jamie Madillfa05f602015-05-07 13:47:11 -04003945// 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 +02003946// TODO(oetuaho): Enable all below tests on OpenGL. Requires a fix for ANGLE bug 1278.
Geoff Lange0cc2a42016-01-20 10:58:17 -05003947ANGLE_INSTANTIATE_TEST(Texture2DTest,
3948 ES2_D3D9(),
3949 ES2_D3D11(),
3950 ES2_D3D11_FL9_3(),
3951 ES2_OPENGL(),
3952 ES2_OPENGLES());
3953ANGLE_INSTANTIATE_TEST(TextureCubeTest,
3954 ES2_D3D9(),
3955 ES2_D3D11(),
Geoff Langf7480ad2017-10-24 11:46:02 -04003956 ES2_D3D11_FL10_0(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003957 ES2_D3D11_FL9_3(),
3958 ES2_OPENGL(),
3959 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003960ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
3961 ES2_D3D9(),
3962 ES2_D3D11(),
3963 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003964 ES2_OPENGL(),
3965 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003966ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
3967 ES2_D3D9(),
3968 ES2_D3D11(),
3969 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003970 ES2_OPENGL(),
3971 ES2_OPENGLES());
3972ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
3973 ES2_D3D9(),
3974 ES2_D3D11(),
3975 ES2_D3D11_FL9_3(),
3976 ES2_OPENGL(),
3977 ES2_OPENGLES());
3978ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
3979 ES2_D3D9(),
3980 ES2_D3D11(),
3981 ES2_D3D11_FL9_3(),
3982 ES2_OPENGL(),
3983 ES2_OPENGLES());
3984ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02003985ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003986ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3987ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
3988 ES3_D3D11(),
3989 ES3_OPENGL(),
3990 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003991ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
3992 ES3_D3D11(),
3993 ES3_OPENGL(),
3994 ES3_OPENGLES());
3995ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3996ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02003997ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02003998ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
3999 ES2_D3D11(),
4000 ES2_D3D11_FL9_3(),
4001 ES2_D3D9(),
4002 ES2_OPENGL(),
4003 ES2_OPENGLES());
4004ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
4005 ES2_D3D11(),
4006 ES2_D3D11_FL9_3(),
4007 ES2_D3D9(),
4008 ES2_OPENGL(),
4009 ES2_OPENGLES());
4010ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
4011 ES2_D3D11(),
4012 ES2_D3D11_FL9_3(),
4013 ES2_D3D9(),
4014 ES2_OPENGL(),
4015 ES2_OPENGLES());
4016ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
4017 ES2_D3D11(),
4018 ES2_D3D11_FL9_3(),
4019 ES2_D3D9(),
4020 ES2_OPENGL(),
4021 ES2_OPENGLES());
4022ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
4023 ES2_D3D11(),
4024 ES2_D3D11_FL9_3(),
4025 ES2_D3D9(),
4026 ES2_OPENGL(),
4027 ES2_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004028ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES());
Vincent Lang25ab4512016-05-13 18:13:59 +02004029ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03004030ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04004031
Jamie Madill7ffdda92016-09-08 13:26:51 -04004032} // anonymous namespace