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