blob: 7e8a9545c03452b01a66b40865e287c1ccdf2b97 [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 }
Olli Etuahoa314b612016-03-10 16:43:00 +02001768 glActiveTexture(GL_TEXTURE0);
1769 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1770 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1771 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1772 texDataGreen.data());
1773 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1774 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1775 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1776 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1777
1778 EXPECT_GL_NO_ERROR();
1779
1780 drawQuad(mProgram, "position", 0.5f);
1781
1782 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1783}
1784
Olli Etuahoe8528d82016-05-16 17:50:52 +03001785// Test that drawing works correctly when level 0 is undefined and base level is 1.
1786TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1787{
1788 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1789 {
1790 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1791 std::cout << "Test skipped on AMD OpenGL." << std::endl;
1792 return;
1793 }
Olli Etuahoe8528d82016-05-16 17:50:52 +03001794 glActiveTexture(GL_TEXTURE0);
1795 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1796 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1797 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1798 texDataGreen.data());
1799 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1800 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1801 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1802 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1803
1804 EXPECT_GL_NO_ERROR();
1805
1806 // Texture is incomplete.
1807 drawQuad(mProgram, "position", 0.5f);
1808 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1809
1810 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1811 texDataGreen.data());
1812
1813 // Texture is now complete.
1814 drawQuad(mProgram, "position", 0.5f);
1815 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1816}
1817
Olli Etuahoa314b612016-03-10 16:43:00 +02001818// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1819// dimensions that don't fit the images inside the range.
1820// GLES 3.0.4 section 3.8.13 Texture completeness
1821TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1822{
Olli Etuahoa314b612016-03-10 16:43:00 +02001823 glActiveTexture(GL_TEXTURE0);
1824 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1825 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1826 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1827 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1828
1829 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1830 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1831
1832 // Two levels that are initially unused.
1833 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1834 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1835 texDataCyan.data());
1836
1837 // One level that is used - only this level should affect completeness.
1838 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1839 texDataGreen.data());
1840
1841 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1842 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1843
1844 EXPECT_GL_NO_ERROR();
1845
1846 drawQuad(mProgram, "position", 0.5f);
1847
1848 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1849
Yunchao He2f23f352018-02-11 22:11:37 +08001850 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001851
1852 // Switch the level that is being used to the cyan level 2.
1853 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1854 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1855
1856 EXPECT_GL_NO_ERROR();
1857
1858 drawQuad(mProgram, "position", 0.5f);
1859
1860 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1861}
1862
1863// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1864// have images defined.
1865TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1866{
Olli Etuahoa314b612016-03-10 16:43:00 +02001867 glActiveTexture(GL_TEXTURE0);
1868 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1869 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1870 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1871 texDataGreen.data());
1872 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1873 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1874 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1875 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1876
1877 EXPECT_GL_NO_ERROR();
1878
1879 drawQuad(mProgram, "position", 0.5f);
1880
1881 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1882}
1883
1884// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1885// dimensions that don't fit the images inside the range.
1886// GLES 3.0.4 section 3.8.13 Texture completeness
1887TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1888{
Olli Etuahoa314b612016-03-10 16:43:00 +02001889 glActiveTexture(GL_TEXTURE0);
1890 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1891 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1892 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1893 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1894
1895 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1896 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1897
1898 // Two levels that are initially unused.
1899 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1900 texDataRed.data());
1901 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1902 texDataCyan.data());
1903
1904 // One level that is used - only this level should affect completeness.
1905 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1906 texDataGreen.data());
1907
1908 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1909 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1910
1911 EXPECT_GL_NO_ERROR();
1912
1913 drawQuad(mProgram, "position", 0.5f);
1914
1915 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1916
Yunchao He2f23f352018-02-11 22:11:37 +08001917 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001918
1919 // Switch the level that is being used to the cyan level 2.
1920 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
1921 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
1922
1923 EXPECT_GL_NO_ERROR();
1924
1925 drawQuad(mProgram, "position", 0.5f);
1926
1927 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1928}
1929
1930// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1931// have images defined.
1932TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
1933{
Olli Etuahoa314b612016-03-10 16:43:00 +02001934 glActiveTexture(GL_TEXTURE0);
1935 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
1936 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1937 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1938 texDataGreen.data());
1939 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1940 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1941 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1942 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1943
1944 EXPECT_GL_NO_ERROR();
1945
1946 drawQuad(mProgram, "position", 0.5f);
1947
1948 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1949}
1950
1951// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1952// dimensions that don't fit the images inside the range.
1953// GLES 3.0.4 section 3.8.13 Texture completeness
1954TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1955{
Olli Etuahoa314b612016-03-10 16:43:00 +02001956 glActiveTexture(GL_TEXTURE0);
1957 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
1958 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1959 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1960 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1961
1962 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1963 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1964
1965 // Two levels that are initially unused.
1966 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1967 texDataRed.data());
1968 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1969 texDataCyan.data());
1970
1971 // One level that is used - only this level should affect completeness.
1972 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1973 texDataGreen.data());
1974
1975 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1976 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1977
1978 EXPECT_GL_NO_ERROR();
1979
1980 drawQuad(mProgram, "position", 0.5f);
1981
1982 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1983
Yunchao He2f23f352018-02-11 22:11:37 +08001984 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
1985
Olli Etuahoa314b612016-03-10 16:43:00 +02001986 if (IsNVIDIA() && (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
1987 getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE))
1988 {
1989 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
1990 // level was changed.
1991 std::cout << "Test partially skipped on NVIDIA OpenGL." << std::endl;
1992 return;
1993 }
1994
1995 // Switch the level that is being used to the cyan level 2.
1996 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
1997 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
1998
1999 EXPECT_GL_NO_ERROR();
2000
2001 drawQuad(mProgram, "position", 0.5f);
2002
2003 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2004}
2005
2006// Test that texture completeness is updated if texture max level changes.
2007// GLES 3.0.4 section 3.8.13 Texture completeness
2008TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2009{
Olli Etuahoa314b612016-03-10 16:43:00 +02002010 glActiveTexture(GL_TEXTURE0);
2011 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2012 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2013
2014 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2015 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2016
2017 // A level that is initially unused.
2018 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2019 texDataGreen.data());
2020
2021 // One level that is initially used - only this level should affect completeness.
2022 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2023 texDataGreen.data());
2024
2025 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2026 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2027
2028 EXPECT_GL_NO_ERROR();
2029
2030 drawQuad(mProgram, "position", 0.5f);
2031
2032 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2033
2034 // Switch the max level to level 1. The levels within the used range now have inconsistent
2035 // dimensions and the texture should be incomplete.
2036 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2037
2038 EXPECT_GL_NO_ERROR();
2039
2040 drawQuad(mProgram, "position", 0.5f);
2041
2042 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2043}
2044
2045// Test that 3D texture completeness is updated if texture max level changes.
2046// GLES 3.0.4 section 3.8.13 Texture completeness
2047TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2048{
Olli Etuahoa314b612016-03-10 16:43:00 +02002049 glActiveTexture(GL_TEXTURE0);
2050 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2051 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2052
2053 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2054 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2055
2056 // A level that is initially unused.
2057 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2058 texDataGreen.data());
2059
2060 // One level that is initially used - only this level should affect completeness.
2061 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2062 texDataGreen.data());
2063
2064 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2065 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2066
2067 EXPECT_GL_NO_ERROR();
2068
2069 drawQuad(mProgram, "position", 0.5f);
2070
2071 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2072
2073 // Switch the max level to level 1. The levels within the used range now have inconsistent
2074 // dimensions and the texture should be incomplete.
2075 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2076
2077 EXPECT_GL_NO_ERROR();
2078
2079 drawQuad(mProgram, "position", 0.5f);
2080
2081 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2082}
2083
2084// Test that texture completeness is updated if texture base level changes.
2085// GLES 3.0.4 section 3.8.13 Texture completeness
2086TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2087{
Olli Etuahoa314b612016-03-10 16:43:00 +02002088 glActiveTexture(GL_TEXTURE0);
2089 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2090 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2091
2092 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2093 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2094
2095 // Two levels that are initially unused.
2096 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2097 texDataGreen.data());
2098 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2099 texDataGreen.data());
2100
2101 // One level that is initially used - only this level should affect completeness.
2102 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2103 texDataGreen.data());
2104
2105 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2106 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2107
2108 EXPECT_GL_NO_ERROR();
2109
2110 drawQuad(mProgram, "position", 0.5f);
2111
2112 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2113
2114 // Switch the base level to level 1. The levels within the used range now have inconsistent
2115 // dimensions and the texture should be incomplete.
2116 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2117
2118 EXPECT_GL_NO_ERROR();
2119
2120 drawQuad(mProgram, "position", 0.5f);
2121
2122 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2123}
2124
2125// Test that texture is not complete if base level is greater than max level.
2126// GLES 3.0.4 section 3.8.13 Texture completeness
2127TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2128{
Olli Etuahoa314b612016-03-10 16:43:00 +02002129 glActiveTexture(GL_TEXTURE0);
2130 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2131
2132 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2133 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2134
2135 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2136
2137 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2138 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2139
2140 EXPECT_GL_NO_ERROR();
2141
2142 drawQuad(mProgram, "position", 0.5f);
2143
2144 // Texture should be incomplete.
2145 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2146}
2147
2148// Test that immutable texture base level and max level are clamped.
2149// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2150TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2151{
Olli Etuahoa314b612016-03-10 16:43:00 +02002152 glActiveTexture(GL_TEXTURE0);
2153 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2154
2155 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2156 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2157
2158 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2159
2160 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2161
2162 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2163 // should be clamped to [base_level, levels - 1].
2164 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2165 // In the case of this test, those rules make the effective base level and max level 0.
2166 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2167 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2168
2169 EXPECT_GL_NO_ERROR();
2170
2171 drawQuad(mProgram, "position", 0.5f);
2172
2173 // Texture should be complete.
2174 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2175}
2176
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002177// Test that changing base level works when it affects the format of the texture.
2178TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2179{
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002180 if (IsNVIDIA() && IsOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002181 {
2182 // Observed rendering corruption on NVIDIA OpenGL.
2183 std::cout << "Test skipped on NVIDIA OpenGL." << std::endl;
2184 return;
2185 }
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002186 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002187 if (IsAMD() && IsDesktopOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002188 {
2189 // Observed incorrect rendering on AMD OpenGL.
2190 std::cout << "Test skipped on AMD OpenGL." << std::endl;
2191 return;
2192 }
2193
2194 glActiveTexture(GL_TEXTURE0);
2195 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2196 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2197 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2198
2199 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2200 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2201
2202 // RGBA8 level that's initially unused.
2203 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2204 texDataCyan.data());
2205
2206 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2207 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2208
2209 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2210 // format. It reads green channel data from the green and alpha channels of texDataGreen
2211 // (this is a bit hacky but works).
2212 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2213
2214 EXPECT_GL_NO_ERROR();
2215
2216 drawQuad(mProgram, "position", 0.5f);
2217
2218 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2219
2220 // Switch the texture to use the cyan level 0 with the RGBA format.
2221 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2222 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2223
2224 EXPECT_GL_NO_ERROR();
2225
2226 drawQuad(mProgram, "position", 0.5f);
2227
2228 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2229}
2230
Olli Etuahoa314b612016-03-10 16:43:00 +02002231// Test that setting a texture image works when base level is out of range.
2232TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2233{
2234 glActiveTexture(GL_TEXTURE0);
2235 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2236
2237 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2238 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2239
2240 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2241 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2242
2243 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2244
2245 EXPECT_GL_NO_ERROR();
2246
2247 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2248
2249 drawQuad(mProgram, "position", 0.5f);
2250
2251 // Texture should be complete.
2252 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002253}
2254
Jamie Madill2453dbc2015-07-14 11:35:42 -04002255// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG RBA->RGBA8, with 1.0
2256// in the alpha channel. This test covers a bug where redefining array textures with these formats does not work as
2257// expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002258TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002259{
2260 std::vector<GLubyte> pixelData;
2261 for (size_t count = 0; count < 5000; count++)
2262 {
2263 pixelData.push_back(0u);
2264 pixelData.push_back(255u);
2265 pixelData.push_back(0u);
2266 }
2267
2268 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002269 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002270 glUniform1i(mTextureArrayLocation, 0);
2271
2272 // The first draw worked correctly.
2273 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
2274
2275 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2276 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2277 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2278 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002279 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002280 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002281
2282 // The dimension of the respecification must match the original exactly to trigger the bug.
2283 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 +02002284 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002285 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002286
2287 ASSERT_GL_NO_ERROR();
2288}
2289
Olli Etuaho1a679902016-01-14 12:21:47 +02002290// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2291// This test is needed especially to confirm that sampler registers get assigned correctly on
2292// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2293TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2294{
2295 glActiveTexture(GL_TEXTURE0);
2296 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2297 GLubyte texData[4];
2298 texData[0] = 0;
2299 texData[1] = 60;
2300 texData[2] = 0;
2301 texData[3] = 255;
2302 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2303
2304 glActiveTexture(GL_TEXTURE1);
2305 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2306 GLfloat depthTexData[1];
2307 depthTexData[0] = 0.5f;
2308 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2309 depthTexData);
2310
2311 glUseProgram(mProgram);
2312 glUniform1f(mDepthRefUniformLocation, 0.3f);
2313 glUniform1i(mTexture3DUniformLocation, 0);
2314 glUniform1i(mTextureShadowUniformLocation, 1);
2315
2316 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2317 drawQuad(mProgram, "position", 0.5f);
2318 EXPECT_GL_NO_ERROR();
2319 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2320 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2321
2322 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2323 drawQuad(mProgram, "position", 0.5f);
2324 EXPECT_GL_NO_ERROR();
2325 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2326 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2327}
2328
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002329// Test multiple different sampler types in the same shader.
2330// This test makes sure that even if sampler / texture registers get grouped together based on type
2331// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2332// still has the right register index information for each ESSL sampler.
2333// The tested ESSL samplers have the following types in D3D11 HLSL:
2334// sampler2D: Texture2D + SamplerState
2335// samplerCube: TextureCube + SamplerState
2336// sampler2DShadow: Texture2D + SamplerComparisonState
2337// samplerCubeShadow: TextureCube + SamplerComparisonState
2338TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2339{
2340 glActiveTexture(GL_TEXTURE0);
2341 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2342 GLubyte texData[4];
2343 texData[0] = 0;
2344 texData[1] = 0;
2345 texData[2] = 120;
2346 texData[3] = 255;
2347 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2348
2349 glActiveTexture(GL_TEXTURE1);
2350 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2351 texData[0] = 0;
2352 texData[1] = 90;
2353 texData[2] = 0;
2354 texData[3] = 255;
2355 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2356 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2357 texData);
2358
2359 glActiveTexture(GL_TEXTURE2);
2360 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2361 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2362 GLfloat depthTexData[1];
2363 depthTexData[0] = 0.5f;
2364 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2365 depthTexData);
2366
2367 glActiveTexture(GL_TEXTURE3);
2368 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2369 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2370 depthTexData[0] = 0.2f;
2371 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2372 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2373 depthTexData);
2374
2375 EXPECT_GL_NO_ERROR();
2376
2377 glUseProgram(mProgram);
2378 glUniform1f(mDepthRefUniformLocation, 0.3f);
2379 glUniform1i(mTexture2DUniformLocation, 0);
2380 glUniform1i(mTextureCubeUniformLocation, 1);
2381 glUniform1i(mTexture2DShadowUniformLocation, 2);
2382 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2383
2384 drawQuad(mProgram, "position", 0.5f);
2385 EXPECT_GL_NO_ERROR();
2386 // The shader writes:
2387 // <texture 2d color> +
2388 // <cube map color> +
2389 // 0.25 * <comparison result (1.0)> +
2390 // 0.125 * <comparison result (0.0)>
2391 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2392}
2393
Olli Etuahobce743a2016-01-15 17:18:28 +02002394// Test different base levels on textures accessed through the same sampler array.
2395// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2396TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2397{
Jiangd9227752017-10-19 16:23:07 +08002398 if (IsAMD() && IsD3D11())
Olli Etuahobce743a2016-01-15 17:18:28 +02002399 {
Jiangd9227752017-10-19 16:23:07 +08002400 std::cout << "Test skipped on AMD D3D." << std::endl;
Olli Etuahobce743a2016-01-15 17:18:28 +02002401 return;
2402 }
2403 glActiveTexture(GL_TEXTURE0);
2404 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2405 GLsizei size = 64;
2406 for (GLint level = 0; level < 7; ++level)
2407 {
2408 ASSERT_LT(0, size);
2409 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2410 nullptr);
2411 size = size / 2;
2412 }
2413 ASSERT_EQ(0, size);
2414 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2415
2416 glActiveTexture(GL_TEXTURE1);
2417 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2418 size = 128;
2419 for (GLint level = 0; level < 8; ++level)
2420 {
2421 ASSERT_LT(0, size);
2422 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2423 nullptr);
2424 size = size / 2;
2425 }
2426 ASSERT_EQ(0, size);
2427 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2428 EXPECT_GL_NO_ERROR();
2429
2430 glUseProgram(mProgram);
2431 glUniform1i(mTexture0Location, 0);
2432 glUniform1i(mTexture1Location, 1);
2433
2434 drawQuad(mProgram, "position", 0.5f);
2435 EXPECT_GL_NO_ERROR();
2436 // Red channel: width of level 1 of texture A: 32.
2437 // Green channel: width of level 3 of texture B: 16.
2438 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2439}
2440
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002441// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2442// ES 3.0.4 table 3.24
2443TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2444{
2445 glActiveTexture(GL_TEXTURE0);
2446 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2447 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2448 EXPECT_GL_NO_ERROR();
2449
2450 drawQuad(mProgram, "position", 0.5f);
2451
2452 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2453}
2454
2455// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2456// ES 3.0.4 table 3.24
2457TEST_P(Texture2DTestES3, TextureLuminanceImplicitAlpha1)
2458{
2459 glActiveTexture(GL_TEXTURE0);
2460 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2461 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2462 EXPECT_GL_NO_ERROR();
2463
2464 drawQuad(mProgram, "position", 0.5f);
2465
2466 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2467}
2468
2469// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2470// ES 3.0.4 table 3.24
2471TEST_P(Texture2DTestES3, TextureLuminance32ImplicitAlpha1)
2472{
2473 if (extensionEnabled("GL_OES_texture_float"))
2474 {
2475 glActiveTexture(GL_TEXTURE0);
2476 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2477 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2478 EXPECT_GL_NO_ERROR();
2479
2480 drawQuad(mProgram, "position", 0.5f);
2481
2482 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2483 }
2484}
2485
2486// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2487// ES 3.0.4 table 3.24
2488TEST_P(Texture2DTestES3, TextureLuminance16ImplicitAlpha1)
2489{
2490 if (extensionEnabled("GL_OES_texture_half_float"))
2491 {
Yuly Novikovafcec832016-06-21 22:19:51 -04002492 if (IsNVIDIA() && IsOpenGLES())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002493 {
2494 std::cout << "Test skipped on NVIDIA" << std::endl;
2495 return;
2496 }
Yuly Novikovafcec832016-06-21 22:19:51 -04002497 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2498 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2499 {
2500 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2501 return;
2502 }
2503
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002504 glActiveTexture(GL_TEXTURE0);
2505 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2506 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES,
2507 nullptr);
2508 EXPECT_GL_NO_ERROR();
2509
2510 drawQuad(mProgram, "position", 0.5f);
2511
2512 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2513 }
2514}
2515
2516// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2517// ES 3.0.4 table 3.24
2518TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2519{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002520 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2521
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002522 glActiveTexture(GL_TEXTURE0);
2523 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2524 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2525 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2526 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2527 EXPECT_GL_NO_ERROR();
2528
2529 drawQuad(mProgram, "position", 0.5f);
2530
2531 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2532}
2533
2534// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2535// ES 3.0.4 table 3.24
2536TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2537{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002538 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2539
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002540 glActiveTexture(GL_TEXTURE0);
2541 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2542
2543 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2544 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2545 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2546 EXPECT_GL_NO_ERROR();
2547
2548 drawQuad(mProgram, "position", 0.5f);
2549
2550 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2551}
2552
2553// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2554// ES 3.0.4 table 3.24
2555TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2556{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002557 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2558
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002559 glActiveTexture(GL_TEXTURE0);
2560 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2561 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2562 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2563 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2564 EXPECT_GL_NO_ERROR();
2565
2566 drawQuad(mProgram, "position", 0.5f);
2567
2568 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2569}
2570
2571// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2572// ES 3.0.4 table 3.24
2573TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2574{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002575 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
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_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2580 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2581 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2582 EXPECT_GL_NO_ERROR();
2583
2584 drawQuad(mProgram, "position", 0.5f);
2585
2586 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
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, TextureRGB32UIImplicitAlpha1)
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_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, 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, TextureRGB32IImplicitAlpha1)
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 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2616 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2617 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2618 EXPECT_GL_NO_ERROR();
2619
2620 drawQuad(mProgram, "position", 0.5f);
2621
2622 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2623}
2624
2625// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2626// ES 3.0.4 table 3.24
2627TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2628{
2629 glActiveTexture(GL_TEXTURE0);
2630 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2631 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2632 EXPECT_GL_NO_ERROR();
2633
2634 drawQuad(mProgram, "position", 0.5f);
2635
2636 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2637}
2638
2639// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2640// ES 3.0.4 table 3.24
2641TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2642{
2643 glActiveTexture(GL_TEXTURE0);
2644 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2645 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2646 nullptr);
2647 EXPECT_GL_NO_ERROR();
2648
2649 drawQuad(mProgram, "position", 0.5f);
2650
2651 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2652}
2653
2654// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2655// ES 3.0.4 table 3.24
2656TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2657{
Jamie Madillbb1db482017-01-10 10:48:32 -05002658 if (IsOSX() && IsIntel() && IsOpenGL())
2659 {
2660 // Seems to fail on OSX 10.12 Intel.
2661 std::cout << "Test skipped on OSX Intel." << std::endl;
2662 return;
2663 }
2664
Yuly Novikov49886892018-01-23 21:18:27 -05002665 // http://anglebug.com/2190
2666 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2667
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002668 glActiveTexture(GL_TEXTURE0);
2669 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2670 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2671 EXPECT_GL_NO_ERROR();
2672
2673 drawQuad(mProgram, "position", 0.5f);
2674
2675 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2676}
2677
2678// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2679// ES 3.0.4 table 3.24
2680TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2681{
Yunchao He14cb42c2018-01-24 14:11:19 +08002682 if (IsOSX() && IsIntel() && IsOpenGL())
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002683 {
Yunchao He14cb42c2018-01-24 14:11:19 +08002684 // Seems to fail on OSX 10.12 Intel.
2685 std::cout << "Test skipped on OSX Intel." << std::endl;
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002686 return;
2687 }
2688
Yuly Novikov49886892018-01-23 21:18:27 -05002689 // http://anglebug.com/2190
2690 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2691
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002692 glActiveTexture(GL_TEXTURE0);
2693 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2694 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2695 EXPECT_GL_NO_ERROR();
2696
2697 drawQuad(mProgram, "position", 0.5f);
2698
2699 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2700}
2701
Olli Etuaho96963162016-03-21 11:54:33 +02002702// Use a sampler in a uniform struct.
2703TEST_P(SamplerInStructTest, SamplerInStruct)
2704{
2705 runSamplerInStructTest();
2706}
2707
2708// Use a sampler in a uniform struct that's passed as a function parameter.
2709TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2710{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002711 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2712 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2713 {
2714 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2715 return;
2716 }
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002717
Olli Etuaho96963162016-03-21 11:54:33 +02002718 runSamplerInStructTest();
2719}
2720
2721// Use a sampler in a uniform struct array with a struct from the array passed as a function
2722// parameter.
2723TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2724{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002725 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2726 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2727 {
2728 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2729 return;
2730 }
Olli Etuaho96963162016-03-21 11:54:33 +02002731 runSamplerInStructTest();
2732}
2733
2734// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2735// parameter.
2736TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2737{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002738 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2739 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2740 {
2741 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2742 return;
2743 }
Olli Etuaho96963162016-03-21 11:54:33 +02002744 runSamplerInStructTest();
2745}
2746
2747// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2748// similarly named uniform.
2749TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2750{
2751 runSamplerInStructTest();
2752}
2753
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002754class TextureLimitsTest : public ANGLETest
2755{
2756 protected:
2757 struct RGBA8
2758 {
2759 uint8_t R, G, B, A;
2760 };
2761
2762 TextureLimitsTest()
2763 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
2764 {
2765 setWindowWidth(128);
2766 setWindowHeight(128);
2767 setConfigRedBits(8);
2768 setConfigGreenBits(8);
2769 setConfigBlueBits(8);
2770 setConfigAlphaBits(8);
2771 }
2772
2773 ~TextureLimitsTest()
2774 {
2775 if (mProgram != 0)
2776 {
2777 glDeleteProgram(mProgram);
2778 mProgram = 0;
2779
2780 if (!mTextures.empty())
2781 {
2782 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
2783 }
2784 }
2785 }
2786
2787 void SetUp() override
2788 {
2789 ANGLETest::SetUp();
2790
2791 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
2792 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
2793 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
2794
2795 ASSERT_GL_NO_ERROR();
2796 }
2797
2798 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
2799 GLint vertexTextureCount,
2800 GLint vertexActiveTextureCount,
2801 const std::string &fragPrefix,
2802 GLint fragmentTextureCount,
2803 GLint fragmentActiveTextureCount)
2804 {
2805 std::stringstream vertexShaderStr;
2806 vertexShaderStr << "attribute vec2 position;\n"
2807 << "varying vec4 color;\n"
2808 << "varying vec2 texCoord;\n";
2809
2810 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
2811 {
2812 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
2813 }
2814
2815 vertexShaderStr << "void main() {\n"
2816 << " gl_Position = vec4(position, 0, 1);\n"
2817 << " texCoord = (position * 0.5) + 0.5;\n"
2818 << " color = vec4(0);\n";
2819
2820 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
2821 {
2822 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
2823 << ", texCoord);\n";
2824 }
2825
2826 vertexShaderStr << "}";
2827
2828 std::stringstream fragmentShaderStr;
2829 fragmentShaderStr << "varying mediump vec4 color;\n"
2830 << "varying mediump vec2 texCoord;\n";
2831
2832 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
2833 {
2834 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
2835 }
2836
2837 fragmentShaderStr << "void main() {\n"
2838 << " gl_FragColor = color;\n";
2839
2840 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
2841 {
2842 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
2843 << ", texCoord);\n";
2844 }
2845
2846 fragmentShaderStr << "}";
2847
2848 const std::string &vertexShaderSource = vertexShaderStr.str();
2849 const std::string &fragmentShaderSource = fragmentShaderStr.str();
2850
2851 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
2852 }
2853
2854 RGBA8 getPixel(GLint texIndex)
2855 {
2856 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
2857 0, 255u};
2858 return pixel;
2859 }
2860
2861 void initTextures(GLint tex2DCount, GLint texCubeCount)
2862 {
2863 GLint totalCount = tex2DCount + texCubeCount;
2864 mTextures.assign(totalCount, 0);
2865 glGenTextures(totalCount, &mTextures[0]);
2866 ASSERT_GL_NO_ERROR();
2867
2868 std::vector<RGBA8> texData(16 * 16);
2869
2870 GLint texIndex = 0;
2871 for (; texIndex < tex2DCount; ++texIndex)
2872 {
2873 texData.assign(texData.size(), getPixel(texIndex));
2874 glActiveTexture(GL_TEXTURE0 + texIndex);
2875 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
2876 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2877 &texData[0]);
2878 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2879 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2880 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2881 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2882 }
2883
2884 ASSERT_GL_NO_ERROR();
2885
2886 for (; texIndex < texCubeCount; ++texIndex)
2887 {
2888 texData.assign(texData.size(), getPixel(texIndex));
2889 glActiveTexture(GL_TEXTURE0 + texIndex);
2890 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
2891 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2892 GL_UNSIGNED_BYTE, &texData[0]);
2893 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2894 GL_UNSIGNED_BYTE, &texData[0]);
2895 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2896 GL_UNSIGNED_BYTE, &texData[0]);
2897 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2898 GL_UNSIGNED_BYTE, &texData[0]);
2899 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2900 GL_UNSIGNED_BYTE, &texData[0]);
2901 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2902 GL_UNSIGNED_BYTE, &texData[0]);
2903 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2904 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2905 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2906 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2907 }
2908
2909 ASSERT_GL_NO_ERROR();
2910 }
2911
2912 void testWithTextures(GLint vertexTextureCount,
2913 const std::string &vertexTexturePrefix,
2914 GLint fragmentTextureCount,
2915 const std::string &fragmentTexturePrefix)
2916 {
2917 // Generate textures
2918 initTextures(vertexTextureCount + fragmentTextureCount, 0);
2919
2920 glUseProgram(mProgram);
2921 RGBA8 expectedSum = {0};
2922 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
2923 {
2924 std::stringstream uniformNameStr;
2925 uniformNameStr << vertexTexturePrefix << texIndex;
2926 const std::string &uniformName = uniformNameStr.str();
2927 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
2928 ASSERT_NE(-1, location);
2929
2930 glUniform1i(location, texIndex);
2931 RGBA8 contribution = getPixel(texIndex);
2932 expectedSum.R += contribution.R;
2933 expectedSum.G += contribution.G;
2934 }
2935
2936 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
2937 {
2938 std::stringstream uniformNameStr;
2939 uniformNameStr << fragmentTexturePrefix << texIndex;
2940 const std::string &uniformName = uniformNameStr.str();
2941 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
2942 ASSERT_NE(-1, location);
2943
2944 glUniform1i(location, texIndex + vertexTextureCount);
2945 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
2946 expectedSum.R += contribution.R;
2947 expectedSum.G += contribution.G;
2948 }
2949
2950 ASSERT_GE(256u, expectedSum.G);
2951
2952 drawQuad(mProgram, "position", 0.5f);
2953 ASSERT_GL_NO_ERROR();
2954 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
2955 }
2956
2957 GLuint mProgram;
2958 std::vector<GLuint> mTextures;
2959 GLint mMaxVertexTextures;
2960 GLint mMaxFragmentTextures;
2961 GLint mMaxCombinedTextures;
2962};
2963
2964// Test rendering with the maximum vertex texture units.
2965TEST_P(TextureLimitsTest, MaxVertexTextures)
2966{
2967 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
2968 ASSERT_NE(0u, mProgram);
2969 ASSERT_GL_NO_ERROR();
2970
2971 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
2972}
2973
2974// Test rendering with the maximum fragment texture units.
2975TEST_P(TextureLimitsTest, MaxFragmentTextures)
2976{
2977 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
2978 ASSERT_NE(0u, mProgram);
2979 ASSERT_GL_NO_ERROR();
2980
2981 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
2982}
2983
2984// Test rendering with maximum combined texture units.
2985TEST_P(TextureLimitsTest, MaxCombinedTextures)
2986{
2987 GLint vertexTextures = mMaxVertexTextures;
2988
2989 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
2990 {
2991 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
2992 }
2993
2994 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
2995 mMaxFragmentTextures, mMaxFragmentTextures);
2996 ASSERT_NE(0u, mProgram);
2997 ASSERT_GL_NO_ERROR();
2998
2999 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3000}
3001
3002// Negative test for exceeding the number of vertex textures
3003TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3004{
3005 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3006 0);
3007 ASSERT_EQ(0u, mProgram);
3008}
3009
3010// Negative test for exceeding the number of fragment textures
3011TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3012{
3013 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3014 mMaxFragmentTextures + 1);
3015 ASSERT_EQ(0u, mProgram);
3016}
3017
3018// Test active vertex textures under the limit, but excessive textures specified.
3019TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3020{
3021 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3022 ASSERT_NE(0u, mProgram);
3023 ASSERT_GL_NO_ERROR();
3024
3025 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3026}
3027
3028// Test active fragment textures under the limit, but excessive textures specified.
3029TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3030{
3031 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3032 mMaxFragmentTextures);
3033 ASSERT_NE(0u, mProgram);
3034 ASSERT_GL_NO_ERROR();
3035
3036 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3037}
3038
3039// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003040// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003041TEST_P(TextureLimitsTest, TextureTypeConflict)
3042{
3043 const std::string &vertexShader =
3044 "attribute vec2 position;\n"
3045 "varying float color;\n"
3046 "uniform sampler2D tex2D;\n"
3047 "uniform samplerCube texCube;\n"
3048 "void main() {\n"
3049 " gl_Position = vec4(position, 0, 1);\n"
3050 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3051 " color = texture2D(tex2D, texCoord).x;\n"
3052 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3053 "}";
3054 const std::string &fragmentShader =
3055 "varying mediump float color;\n"
3056 "void main() {\n"
3057 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3058 "}";
3059
3060 mProgram = CompileProgram(vertexShader, fragmentShader);
3061 ASSERT_NE(0u, mProgram);
3062
3063 initTextures(1, 0);
3064
3065 glUseProgram(mProgram);
3066 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3067 ASSERT_NE(-1, tex2DLocation);
3068 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3069 ASSERT_NE(-1, texCubeLocation);
3070
3071 glUniform1i(tex2DLocation, 0);
3072 glUniform1i(texCubeLocation, 0);
3073 ASSERT_GL_NO_ERROR();
3074
3075 drawQuad(mProgram, "position", 0.5f);
3076 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3077}
3078
Vincent Lang25ab4512016-05-13 18:13:59 +02003079class Texture2DNorm16TestES3 : public Texture2DTestES3
3080{
3081 protected:
3082 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3083
3084 void SetUp() override
3085 {
3086 Texture2DTestES3::SetUp();
3087
3088 glActiveTexture(GL_TEXTURE0);
3089 glGenTextures(3, mTextures);
3090 glGenFramebuffers(1, &mFBO);
3091 glGenRenderbuffers(1, &mRenderbuffer);
3092
3093 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3094 {
3095 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3096 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3097 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3098 }
3099
3100 glBindTexture(GL_TEXTURE_2D, 0);
3101
3102 ASSERT_GL_NO_ERROR();
3103 }
3104
3105 void TearDown() override
3106 {
3107 glDeleteTextures(3, mTextures);
3108 glDeleteFramebuffers(1, &mFBO);
3109 glDeleteRenderbuffers(1, &mRenderbuffer);
3110
3111 Texture2DTestES3::TearDown();
3112 }
3113
3114 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3115 {
Geoff Langf607c602016-09-21 11:46:48 -04003116 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3117 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003118
3119 setUpProgram();
3120
3121 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3122 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3123 0);
3124
3125 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3126 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3127
3128 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003129 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003130
3131 EXPECT_GL_NO_ERROR();
3132
3133 drawQuad(mProgram, "position", 0.5f);
3134
Geoff Langf607c602016-09-21 11:46:48 -04003135 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003136
Geoff Langf607c602016-09-21 11:46:48 -04003137 EXPECT_PIXEL_COLOR_EQ(
3138 0, 0, SliceFormatColor(
3139 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003140
3141 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3142
3143 ASSERT_GL_NO_ERROR();
3144 }
3145
3146 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3147 {
3148 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003149 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003150
3151 setUpProgram();
3152
3153 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3154 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3155
3156 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3157 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3158 0);
3159
3160 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003161 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003162
3163 EXPECT_GL_NO_ERROR();
3164
3165 drawQuad(mProgram, "position", 0.5f);
3166
Geoff Langf607c602016-09-21 11:46:48 -04003167 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
3168 EXPECT_PIXEL_COLOR_EQ(
3169 0, 0, SliceFormatColor(
3170 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003171
3172 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3173 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3174 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3175 mRenderbuffer);
3176 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3177 EXPECT_GL_NO_ERROR();
3178
3179 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3180 glClear(GL_COLOR_BUFFER_BIT);
3181
3182 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3183
Geoff Langf607c602016-09-21 11:46:48 -04003184 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003185
3186 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3187
3188 ASSERT_GL_NO_ERROR();
3189 }
3190
3191 GLuint mTextures[3];
3192 GLuint mFBO;
3193 GLuint mRenderbuffer;
3194};
3195
3196// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3197TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3198{
3199 if (!extensionEnabled("GL_EXT_texture_norm16"))
3200 {
3201 std::cout << "Test skipped due to missing GL_EXT_texture_norm16." << std::endl;
3202 return;
3203 }
3204
3205 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3206 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3207 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3208 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3209 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3210 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3211 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3212 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3213
3214 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3215 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3216 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3217}
3218
Olli Etuaho95faa232016-06-07 14:01:53 -07003219// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3220// GLES 3.0.4 section 3.8.3.
3221TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3222{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08003223 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
3224
Yuly Novikov3c754192016-06-27 19:36:41 -04003225 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1429 is fixed
3226 if (IsAndroid() && IsAdreno() && IsOpenGLES())
3227 {
3228 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
3229 return;
3230 }
Olli Etuaho95faa232016-06-07 14:01:53 -07003231
3232 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3233 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3234 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3235 ASSERT_GL_NO_ERROR();
3236
3237 // SKIP_IMAGES should not have an effect on uploading 2D textures
3238 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3239 ASSERT_GL_NO_ERROR();
3240
3241 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3242
3243 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3244 pixelsGreen.data());
3245 ASSERT_GL_NO_ERROR();
3246
3247 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3248 pixelsGreen.data());
3249 ASSERT_GL_NO_ERROR();
3250
3251 glUseProgram(mProgram);
3252 drawQuad(mProgram, "position", 0.5f);
3253 ASSERT_GL_NO_ERROR();
3254
3255 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3256}
3257
Olli Etuaho989cac32016-06-08 16:18:49 -07003258// Test that skip defined in unpack parameters is taken into account when determining whether
3259// unpacking source extends outside unpack buffer bounds.
3260TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3261{
3262 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3263 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3264 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3265 ASSERT_GL_NO_ERROR();
3266
3267 GLBuffer buf;
3268 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3269 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3270 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3271 GL_DYNAMIC_COPY);
3272 ASSERT_GL_NO_ERROR();
3273
3274 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3275 ASSERT_GL_NO_ERROR();
3276
3277 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3278 ASSERT_GL_NO_ERROR();
3279
3280 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3281 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3282
3283 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3284 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3285 ASSERT_GL_NO_ERROR();
3286
3287 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3288 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3289}
3290
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003291// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3292TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3293{
3294 if (IsD3D11())
3295 {
3296 std::cout << "Test skipped on D3D." << std::endl;
3297 return;
3298 }
3299 if (IsOSX() && IsAMD())
3300 {
3301 // Incorrect rendering results seen on OSX AMD.
3302 std::cout << "Test skipped on OSX AMD." << std::endl;
3303 return;
3304 }
3305
3306 const GLuint width = 8u;
3307 const GLuint height = 8u;
3308 const GLuint unpackRowLength = 5u;
3309 const GLuint unpackSkipPixels = 1u;
3310
3311 setWindowWidth(width);
3312 setWindowHeight(height);
3313
3314 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3315 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3316 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3317 ASSERT_GL_NO_ERROR();
3318
3319 GLBuffer buf;
3320 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3321 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3322 GLColor::green);
3323
3324 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3325 {
3326 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3327 }
3328
3329 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3330 GL_DYNAMIC_COPY);
3331 ASSERT_GL_NO_ERROR();
3332
3333 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3334 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3335 ASSERT_GL_NO_ERROR();
3336
3337 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3338 ASSERT_GL_NO_ERROR();
3339
3340 glUseProgram(mProgram);
3341 drawQuad(mProgram, "position", 0.5f);
3342 ASSERT_GL_NO_ERROR();
3343
3344 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3345 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3346 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3347 actual.data());
3348 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3349 EXPECT_EQ(expected, actual);
3350}
3351
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003352template <typename T>
3353T UNorm(double value)
3354{
3355 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3356}
3357
3358// Test rendering a depth texture with mipmaps.
3359TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3360{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003361 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3362 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
3363 // http://anglebugs.com/1706
3364 if (IsIntel() && IsWindows())
Corentin Walleze731d8a2016-09-07 10:56:25 -04003365 {
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003366 std::cout << "Test skipped on Win Intel." << std::endl;
Corentin Walleze731d8a2016-09-07 10:56:25 -04003367 return;
3368 }
3369
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003370 const int size = getWindowWidth();
3371
3372 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003373 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003374
3375 glActiveTexture(GL_TEXTURE0);
3376 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3377 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3378 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3379 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3380 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3381 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3382 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3383 ASSERT_GL_NO_ERROR();
3384
3385 glUseProgram(mProgram);
3386 glUniform1i(mTexture2DUniformLocation, 0);
3387
3388 std::vector<unsigned char> expected;
3389
3390 for (int level = 0; level < levels; ++level)
3391 {
3392 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3393 expected.push_back(UNorm<unsigned char>(value));
3394
3395 int levelDim = dim(level);
3396
3397 ASSERT_GT(levelDim, 0);
3398
3399 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3400 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3401 GL_UNSIGNED_INT, initData.data());
3402 }
3403 ASSERT_GL_NO_ERROR();
3404
3405 for (int level = 0; level < levels; ++level)
3406 {
3407 glViewport(0, 0, dim(level), dim(level));
3408 drawQuad(mProgram, "position", 0.5f);
3409 GLColor actual = ReadColor(0, 0);
3410 EXPECT_NEAR(expected[level], actual.R, 10u);
3411 }
3412
3413 ASSERT_GL_NO_ERROR();
3414}
3415
Jamie Madill7ffdda92016-09-08 13:26:51 -04003416// Tests unpacking into the unsized GL_ALPHA format.
3417TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3418{
Jamie Madill7ffdda92016-09-08 13:26:51 -04003419 // Initialize the texure.
3420 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3421 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3422 GL_UNSIGNED_BYTE, nullptr);
3423 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3424 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3425
3426 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3427
3428 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04003429 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04003430 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3431 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3432 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
3433 GL_STATIC_DRAW);
3434
3435 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
3436 GL_UNSIGNED_BYTE, nullptr);
3437
3438 // Clear to a weird color to make sure we're drawing something.
3439 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
3440 glClear(GL_COLOR_BUFFER_BIT);
3441
3442 // Draw with the alpha texture and verify.
3443 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04003444
3445 ASSERT_GL_NO_ERROR();
3446 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
3447}
3448
Jamie Madill2e600342016-09-19 13:56:40 -04003449// Ensure stale unpack data doesn't propagate in D3D11.
3450TEST_P(Texture2DTestES3, StaleUnpackData)
3451{
3452 // Init unpack buffer.
3453 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
3454 std::vector<GLColor> pixels(pixelCount, GLColor::red);
3455
3456 GLBuffer unpackBuffer;
3457 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3458 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3459 GLsizei bufferSize = pixelCount * sizeof(GLColor);
3460 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
3461
3462 // Create from unpack buffer.
3463 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3464 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
3465 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3466 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3467 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3468
3469 drawQuad(mProgram, "position", 0.5f);
3470
3471 ASSERT_GL_NO_ERROR();
3472 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3473
3474 // Fill unpack with green, recreating buffer.
3475 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
3476 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
3477 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
3478
3479 // Reinit texture with green.
3480 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
3481 GL_UNSIGNED_BYTE, nullptr);
3482
3483 drawQuad(mProgram, "position", 0.5f);
3484
3485 ASSERT_GL_NO_ERROR();
3486 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3487}
3488
Geoff Langfb7685f2017-11-13 11:44:11 -05003489// Ensure that texture parameters passed as floats that are converted to ints are rounded before
3490// validating they are less than 0.
3491TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
3492{
3493 GLTexture texture;
3494 glBindTexture(GL_TEXTURE_2D, texture);
3495
3496 // Use a negative number that will round to zero when converted to an integer
3497 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
3498 // "Validation of values performed by state-setting commands is performed after conversion,
3499 // unless specified otherwise for a specific command."
3500 GLfloat param = -7.30157126e-07f;
3501 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
3502 EXPECT_GL_NO_ERROR();
3503
3504 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
3505 EXPECT_GL_NO_ERROR();
3506}
3507
Jamie Madillf097e232016-11-05 00:44:15 -04003508// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
3509// being properly checked, and the texture storage of the previous texture format was persisting.
3510// This would result in an ASSERT in debug and incorrect rendering in release.
3511// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
3512TEST_P(Texture3DTestES3, FormatRedefinitionBug)
3513{
3514 GLTexture tex;
3515 glBindTexture(GL_TEXTURE_3D, tex.get());
3516 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3517
3518 GLFramebuffer framebuffer;
3519 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3520 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
3521
3522 glCheckFramebufferStatus(GL_FRAMEBUFFER);
3523
3524 std::vector<uint8_t> pixelData(100, 0);
3525
3526 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
3527 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
3528 pixelData.data());
3529
3530 ASSERT_GL_NO_ERROR();
3531}
3532
Corentin Wallezd2627992017-04-28 17:17:03 -04003533// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
3534TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
3535{
3536 // 2D tests
3537 {
3538 GLTexture tex;
3539 glBindTexture(GL_TEXTURE_2D, tex.get());
3540
3541 GLBuffer pbo;
3542 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3543
3544 // Test OOB
3545 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
3546 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3547 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3548
3549 // Test OOB
3550 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
3551 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3552 ASSERT_GL_NO_ERROR();
3553 }
3554
3555 // 3D tests
3556 {
3557 GLTexture tex;
3558 glBindTexture(GL_TEXTURE_3D, tex.get());
3559
3560 GLBuffer pbo;
3561 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3562
3563 // Test OOB
3564 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
3565 GL_STATIC_DRAW);
3566 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3567 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3568
3569 // Test OOB
3570 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
3571 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3572 ASSERT_GL_NO_ERROR();
3573 }
3574}
3575
Jamie Madill3ed60422017-09-07 11:32:52 -04003576// Tests behaviour with a single texture and multiple sampler objects.
3577TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
3578{
3579 GLint maxTextureUnits = 0;
3580 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
3581 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
3582
3583 constexpr int kSize = 16;
3584
3585 // Make a single-level texture, fill it with red.
3586 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
3587 GLTexture tex;
3588 glBindTexture(GL_TEXTURE_2D, tex);
3589 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3590 redColors.data());
3591 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3592 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3593
3594 // Simple sanity check.
3595 draw2DTexturedQuad(0.5f, 1.0f, true);
3596 ASSERT_GL_NO_ERROR();
3597 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3598
3599 // Bind texture to unit 1 with a sampler object making it incomplete.
3600 GLSampler sampler;
3601 glBindSampler(0, sampler);
3602 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3603 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3604
3605 // Make a mipmap texture, fill it with blue.
3606 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
3607 GLTexture mipmapTex;
3608 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3609 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3610 blueColors.data());
3611 glGenerateMipmap(GL_TEXTURE_2D);
3612
3613 // Draw with the sampler, expect blue.
3614 draw2DTexturedQuad(0.5f, 1.0f, true);
3615 ASSERT_GL_NO_ERROR();
3616 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
3617
3618 // Simple multitexturing program.
3619 const std::string vs =
3620 "#version 300 es\n"
3621 "in vec2 position;\n"
3622 "out vec2 texCoord;\n"
3623 "void main()\n"
3624 "{\n"
3625 " gl_Position = vec4(position, 0, 1);\n"
3626 " texCoord = position * 0.5 + vec2(0.5);\n"
3627 "}";
3628 const std::string fs =
3629 "#version 300 es\n"
3630 "precision mediump float;\n"
3631 "in vec2 texCoord;\n"
3632 "uniform sampler2D tex1;\n"
3633 "uniform sampler2D tex2;\n"
3634 "uniform sampler2D tex3;\n"
3635 "uniform sampler2D tex4;\n"
3636 "out vec4 color;\n"
3637 "void main()\n"
3638 "{\n"
3639 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
3640 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
3641 "}";
3642
3643 ANGLE_GL_PROGRAM(program, vs, fs);
3644
3645 std::array<GLint, 4> texLocations = {
3646 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
3647 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
3648 for (GLint location : texLocations)
3649 {
3650 ASSERT_NE(-1, location);
3651 }
3652
3653 // Init the uniform data.
3654 glUseProgram(program);
3655 for (GLint location = 0; location < 4; ++location)
3656 {
3657 glUniform1i(texLocations[location], location);
3658 }
3659
3660 // Initialize four samplers
3661 GLSampler samplers[4];
3662
3663 // 0: non-mipped.
3664 glBindSampler(0, samplers[0]);
3665 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3666 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3667
3668 // 1: mipped.
3669 glBindSampler(1, samplers[1]);
3670 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3671 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3672
3673 // 2: non-mipped.
3674 glBindSampler(2, samplers[2]);
3675 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3676 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3677
3678 // 3: mipped.
3679 glBindSampler(3, samplers[3]);
3680 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3681 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3682
3683 // Bind two blue mipped textures and two single layer textures, should all draw.
3684 glActiveTexture(GL_TEXTURE0);
3685 glBindTexture(GL_TEXTURE_2D, tex);
3686
3687 glActiveTexture(GL_TEXTURE1);
3688 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3689
3690 glActiveTexture(GL_TEXTURE2);
3691 glBindTexture(GL_TEXTURE_2D, tex);
3692
3693 glActiveTexture(GL_TEXTURE3);
3694 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3695
3696 ASSERT_GL_NO_ERROR();
3697
3698 drawQuad(program, "position", 0.5f);
3699 ASSERT_GL_NO_ERROR();
3700 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
3701
3702 // Bind four single layer textures, two should be incomplete.
3703 glActiveTexture(GL_TEXTURE1);
3704 glBindTexture(GL_TEXTURE_2D, tex);
3705
3706 glActiveTexture(GL_TEXTURE3);
3707 glBindTexture(GL_TEXTURE_2D, tex);
3708
3709 drawQuad(program, "position", 0.5f);
3710 ASSERT_GL_NO_ERROR();
3711 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
3712}
3713
Martin Radev7e2c0d32017-09-15 14:25:42 +03003714// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
3715// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
3716// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
3717// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
3718// samples the cubemap using a direction vector (1,1,1).
3719TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
3720{
Yunchao He2f23f352018-02-11 22:11:37 +08003721 // Check http://anglebug.com/2155.
3722 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
3723
Martin Radev7e2c0d32017-09-15 14:25:42 +03003724 const std::string vs =
3725 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003726 precision mediump float;
3727 in vec3 pos;
3728 void main() {
3729 gl_Position = vec4(pos, 1.0);
3730 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003731
3732 const std::string fs =
3733 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003734 precision mediump float;
3735 out vec4 color;
3736 uniform samplerCube uTex;
3737 void main(){
3738 color = texture(uTex, vec3(1.0));
3739 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003740 ANGLE_GL_PROGRAM(program, vs, fs);
3741 glUseProgram(program);
3742
3743 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
3744 glActiveTexture(GL_TEXTURE0);
3745
3746 GLTexture cubeTex;
3747 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
3748
3749 const int kFaceWidth = 1;
3750 const int kFaceHeight = 1;
3751 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
3752 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3753 GL_UNSIGNED_BYTE, texData.data());
3754 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3755 GL_UNSIGNED_BYTE, texData.data());
3756 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3757 GL_UNSIGNED_BYTE, texData.data());
3758 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3759 GL_UNSIGNED_BYTE, texData.data());
3760 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3761 GL_UNSIGNED_BYTE, texData.data());
3762 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3763 GL_UNSIGNED_BYTE, texData.data());
3764 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3765 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3766 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
3767 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
3768 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
3769 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
3770
3771 drawQuad(program, "pos", 0.5f, 1.0f, true);
3772 ASSERT_GL_NO_ERROR();
3773
3774 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
3775}
3776
Jamie Madillfa05f602015-05-07 13:47:11 -04003777// 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 +02003778// TODO(oetuaho): Enable all below tests on OpenGL. Requires a fix for ANGLE bug 1278.
Geoff Lange0cc2a42016-01-20 10:58:17 -05003779ANGLE_INSTANTIATE_TEST(Texture2DTest,
3780 ES2_D3D9(),
3781 ES2_D3D11(),
3782 ES2_D3D11_FL9_3(),
3783 ES2_OPENGL(),
3784 ES2_OPENGLES());
3785ANGLE_INSTANTIATE_TEST(TextureCubeTest,
3786 ES2_D3D9(),
3787 ES2_D3D11(),
Geoff Langf7480ad2017-10-24 11:46:02 -04003788 ES2_D3D11_FL10_0(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003789 ES2_D3D11_FL9_3(),
3790 ES2_OPENGL(),
3791 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003792ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
3793 ES2_D3D9(),
3794 ES2_D3D11(),
3795 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003796 ES2_OPENGL(),
3797 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003798ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
3799 ES2_D3D9(),
3800 ES2_D3D11(),
3801 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003802 ES2_OPENGL(),
3803 ES2_OPENGLES());
3804ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
3805 ES2_D3D9(),
3806 ES2_D3D11(),
3807 ES2_D3D11_FL9_3(),
3808 ES2_OPENGL(),
3809 ES2_OPENGLES());
3810ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
3811 ES2_D3D9(),
3812 ES2_D3D11(),
3813 ES2_D3D11_FL9_3(),
3814 ES2_OPENGL(),
3815 ES2_OPENGLES());
3816ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02003817ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003818ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3819ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
3820 ES3_D3D11(),
3821 ES3_OPENGL(),
3822 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003823ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
3824 ES3_D3D11(),
3825 ES3_OPENGL(),
3826 ES3_OPENGLES());
3827ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3828ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02003829ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02003830ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
3831 ES2_D3D11(),
3832 ES2_D3D11_FL9_3(),
3833 ES2_D3D9(),
3834 ES2_OPENGL(),
3835 ES2_OPENGLES());
3836ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
3837 ES2_D3D11(),
3838 ES2_D3D11_FL9_3(),
3839 ES2_D3D9(),
3840 ES2_OPENGL(),
3841 ES2_OPENGLES());
3842ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
3843 ES2_D3D11(),
3844 ES2_D3D11_FL9_3(),
3845 ES2_D3D9(),
3846 ES2_OPENGL(),
3847 ES2_OPENGLES());
3848ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
3849 ES2_D3D11(),
3850 ES2_D3D11_FL9_3(),
3851 ES2_D3D9(),
3852 ES2_OPENGL(),
3853 ES2_OPENGLES());
3854ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
3855 ES2_D3D11(),
3856 ES2_D3D11_FL9_3(),
3857 ES2_D3D9(),
3858 ES2_OPENGL(),
3859 ES2_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003860ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES());
Vincent Lang25ab4512016-05-13 18:13:59 +02003861ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03003862ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04003863
Jamie Madill7ffdda92016-09-08 13:26:51 -04003864} // anonymous namespace