blob: d2234feb734b0a480fe1aaa96bf37d0b0d4926dd [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 {
Yunchao He9550c602018-02-13 14:47:05 +0800181 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_storage") ||
182 !extensionEnabled("GL_OES_texture_float"));
Geoff Langc4e93662017-05-01 10:45:59 -0400183
Yunchao He9550c602018-02-13 14:47:05 +0800184 ANGLE_SKIP_TEST_IF((sourceImageChannels < 3 || destImageChannels < 3) &&
185 !extensionEnabled("GL_EXT_texture_rg"));
Geoff Langfbfa47c2015-03-31 11:26:00 -0400186
Yunchao He9550c602018-02-13 14:47:05 +0800187 ANGLE_SKIP_TEST_IF(destImageChannels == 3 &&
188 !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400189
Yunchao He9550c602018-02-13 14:47:05 +0800190 ANGLE_SKIP_TEST_IF(destImageChannels == 4 &&
191 !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400192
Yunchao He9550c602018-02-13 14:47:05 +0800193 ANGLE_SKIP_TEST_IF(destImageChannels <= 2);
Geoff Lang677bb6f2017-04-05 12:40:40 -0400194 }
195 else
196 {
Yunchao He9550c602018-02-13 14:47:05 +0800197 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_color_buffer_float"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400198
Yunchao He9550c602018-02-13 14:47:05 +0800199 ANGLE_SKIP_TEST_IF(destImageChannels == 3 &&
200 !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"));
Geoff Langfbfa47c2015-03-31 11:26:00 -0400201 }
202
Jamie Madillbc393df2015-01-29 13:46:07 -0500203 GLfloat sourceImageData[4][16] =
204 {
205 { // R
206 1.0f,
207 0.0f,
208 0.0f,
209 1.0f
210 },
211 { // RG
212 1.0f, 0.0f,
213 0.0f, 1.0f,
214 0.0f, 0.0f,
215 1.0f, 1.0f
216 },
217 { // RGB
218 1.0f, 0.0f, 0.0f,
219 0.0f, 1.0f, 0.0f,
220 0.0f, 0.0f, 1.0f,
221 1.0f, 1.0f, 0.0f
222 },
223 { // RGBA
224 1.0f, 0.0f, 0.0f, 1.0f,
225 0.0f, 1.0f, 0.0f, 1.0f,
226 0.0f, 0.0f, 1.0f, 1.0f,
227 1.0f, 1.0f, 0.0f, 1.0f
228 },
229 };
230
231 GLenum imageFormats[] =
232 {
233 GL_R32F,
234 GL_RG32F,
235 GL_RGB32F,
236 GL_RGBA32F,
237 };
238
239 GLenum sourceUnsizedFormats[] =
240 {
241 GL_RED,
242 GL_RG,
243 GL_RGB,
244 GL_RGBA,
245 };
246
247 GLuint textures[2];
248
249 glGenTextures(2, textures);
250
251 GLfloat *imageData = sourceImageData[sourceImageChannels - 1];
252 GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1];
253 GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1];
254 GLenum destImageFormat = imageFormats[destImageChannels - 1];
255
256 glBindTexture(GL_TEXTURE_2D, textures[0]);
Geoff Langc4e93662017-05-01 10:45:59 -0400257 if (getClientMajorVersion() >= 3)
258 {
259 glTexStorage2D(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
260 }
261 else
262 {
263 glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
264 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500265 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
266 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
267 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData);
268
hendrikwb27f79a2015-03-04 11:26:46 -0800269 if (sourceImageChannels < 3 && !extensionEnabled("GL_EXT_texture_rg"))
Jamie Madillbc393df2015-01-29 13:46:07 -0500270 {
271 // This is not supported
272 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
273 }
274 else
275 {
276 ASSERT_GL_NO_ERROR();
277 }
278
279 GLuint fbo;
280 glGenFramebuffers(1, &fbo);
281 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
282 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
283
284 glBindTexture(GL_TEXTURE_2D, textures[1]);
Geoff Langc4e93662017-05-01 10:45:59 -0400285 if (getClientMajorVersion() >= 3)
286 {
287 glTexStorage2D(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
288 }
289 else
290 {
291 glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
292 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500293 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
294 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
295
296 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
297 ASSERT_GL_NO_ERROR();
298
299 glBindFramebuffer(GL_FRAMEBUFFER, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200300 drawQuad(mProgram, "position", 0.5f);
Jamie Madillbc393df2015-01-29 13:46:07 -0500301
302 int testImageChannels = std::min(sourceImageChannels, destImageChannels);
303
Olli Etuahoa314b612016-03-10 16:43:00 +0200304 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Jamie Madillbc393df2015-01-29 13:46:07 -0500305 if (testImageChannels > 1)
306 {
307 EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255);
308 EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255);
309 if (testImageChannels > 2)
310 {
311 EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255);
312 }
313 }
314
315 glDeleteFramebuffers(1, &fbo);
316 glDeleteTextures(2, textures);
317
318 ASSERT_GL_NO_ERROR();
319 }
320
Jamie Madilld4cfa572014-07-08 10:00:32 -0400321 GLuint mTexture2D;
Jamie Madilld4cfa572014-07-08 10:00:32 -0400322 GLint mTexture2DUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400323};
324
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200325class Texture2DTestES3 : public Texture2DTest
326{
327 protected:
328 Texture2DTestES3() : Texture2DTest() {}
329
330 std::string getVertexShaderSource() override
331 {
332 return std::string(
333 "#version 300 es\n"
334 "out vec2 texcoord;\n"
335 "in vec4 position;\n"
336 "void main()\n"
337 "{\n"
338 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
339 " texcoord = (position.xy * 0.5) + 0.5;\n"
340 "}\n");
341 }
342
343 std::string getFragmentShaderSource() override
344 {
345 return std::string(
346 "#version 300 es\n"
347 "precision highp float;\n"
348 "uniform highp sampler2D tex;\n"
349 "in vec2 texcoord;\n"
350 "out vec4 fragColor;\n"
351 "void main()\n"
352 "{\n"
353 " fragColor = texture(tex, texcoord);\n"
354 "}\n");
355 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300356
357 void SetUp() override
358 {
359 Texture2DTest::SetUp();
360 setUpProgram();
361 }
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200362};
363
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200364class Texture2DIntegerAlpha1TestES3 : public Texture2DTest
365{
366 protected:
367 Texture2DIntegerAlpha1TestES3() : Texture2DTest() {}
368
369 std::string getVertexShaderSource() override
370 {
371 return std::string(
372 "#version 300 es\n"
373 "out vec2 texcoord;\n"
374 "in vec4 position;\n"
375 "void main()\n"
376 "{\n"
377 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
378 " texcoord = (position.xy * 0.5) + 0.5;\n"
379 "}\n");
380 }
381
382 std::string getFragmentShaderSource() override
383 {
384 return std::string(
385 "#version 300 es\n"
386 "precision highp float;\n"
387 "uniform highp isampler2D tex;\n"
388 "in vec2 texcoord;\n"
389 "out vec4 fragColor;\n"
390 "void main()\n"
391 "{\n"
392 " vec4 green = vec4(0, 1, 0, 1);\n"
393 " vec4 black = vec4(0, 0, 0, 0);\n"
394 " fragColor = (texture(tex, texcoord).a == 1) ? green : black;\n"
395 "}\n");
396 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300397
398 void SetUp() override
399 {
400 Texture2DTest::SetUp();
401 setUpProgram();
402 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200403};
404
405class Texture2DUnsignedIntegerAlpha1TestES3 : public Texture2DTest
406{
407 protected:
408 Texture2DUnsignedIntegerAlpha1TestES3() : Texture2DTest() {}
409
410 std::string getVertexShaderSource() override
411 {
412 return std::string(
413 "#version 300 es\n"
414 "out vec2 texcoord;\n"
415 "in vec4 position;\n"
416 "void main()\n"
417 "{\n"
418 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
419 " texcoord = (position.xy * 0.5) + 0.5;\n"
420 "}\n");
421 }
422
423 std::string getFragmentShaderSource() override
424 {
425 return std::string(
426 "#version 300 es\n"
427 "precision highp float;\n"
428 "uniform highp usampler2D tex;\n"
429 "in vec2 texcoord;\n"
430 "out vec4 fragColor;\n"
431 "void main()\n"
432 "{\n"
433 " vec4 green = vec4(0, 1, 0, 1);\n"
434 " vec4 black = vec4(0, 0, 0, 0);\n"
435 " fragColor = (texture(tex, texcoord).a == 1u) ? green : black;\n"
436 "}\n");
437 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300438
439 void SetUp() override
440 {
441 Texture2DTest::SetUp();
442 setUpProgram();
443 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200444};
445
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200446class Texture2DTestWithDrawScale : public Texture2DTest
Jamie Madill2453dbc2015-07-14 11:35:42 -0400447{
448 protected:
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200449 Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {}
450
451 std::string getVertexShaderSource() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400452 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300453 return
454 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200455 attribute vec4 position;
456 varying vec2 texcoord;
457
458 uniform vec2 drawScale;
459
460 void main()
461 {
462 gl_Position = vec4(position.xy * drawScale, 0.0, 1.0);
463 texcoord = (position.xy * 0.5) + 0.5;
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300464 })";
Jamie Madill2453dbc2015-07-14 11:35:42 -0400465 }
466
467 void SetUp() override
468 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200469 Texture2DTest::SetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300470
471 setUpProgram();
472
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200473 mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale");
474 ASSERT_NE(-1, mDrawScaleUniformLocation);
Jamie Madill2453dbc2015-07-14 11:35:42 -0400475
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200476 glUseProgram(mProgram);
477 glUniform2f(mDrawScaleUniformLocation, 1.0f, 1.0f);
478 glUseProgram(0);
479 ASSERT_GL_NO_ERROR();
480 }
481
482 GLint mDrawScaleUniformLocation;
483};
484
Olli Etuaho4644a202016-01-12 15:12:53 +0200485class Sampler2DAsFunctionParameterTest : public Texture2DTest
486{
487 protected:
488 Sampler2DAsFunctionParameterTest() : Texture2DTest() {}
489
490 std::string getFragmentShaderSource() override
491 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300492 return
493 R"(precision highp float;
Olli Etuaho4644a202016-01-12 15:12:53 +0200494 uniform sampler2D tex;
495 varying vec2 texcoord;
496
497 vec4 computeFragColor(sampler2D aTex)
498 {
499 return texture2D(aTex, texcoord);
500 }
501
502 void main()
503 {
504 gl_FragColor = computeFragColor(tex);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300505 })";
Olli Etuaho4644a202016-01-12 15:12:53 +0200506 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300507
508 void SetUp() override
509 {
510 Texture2DTest::SetUp();
511 setUpProgram();
512 }
Olli Etuaho4644a202016-01-12 15:12:53 +0200513};
514
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200515class TextureCubeTest : public TexCoordDrawTest
516{
517 protected:
518 TextureCubeTest()
519 : TexCoordDrawTest(),
520 mTexture2D(0),
521 mTextureCube(0),
522 mTexture2DUniformLocation(-1),
523 mTextureCubeUniformLocation(-1)
524 {
525 }
526
527 std::string getFragmentShaderSource() override
528 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300529 return
530 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200531 uniform sampler2D tex2D;
532 uniform samplerCube texCube;
533 varying vec2 texcoord;
534
535 void main()
536 {
537 gl_FragColor = texture2D(tex2D, texcoord);
538 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300539 })";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200540 }
541
542 void SetUp() override
543 {
544 TexCoordDrawTest::SetUp();
545
546 glGenTextures(1, &mTextureCube);
547 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Geoff Langc4e93662017-05-01 10:45:59 -0400548 for (GLenum face = 0; face < 6; face++)
549 {
550 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
551 GL_UNSIGNED_BYTE, nullptr);
552 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200553 EXPECT_GL_NO_ERROR();
554
555 mTexture2D = create2DTexture();
556
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300557 setUpProgram();
558
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200559 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
560 ASSERT_NE(-1, mTexture2DUniformLocation);
561 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
562 ASSERT_NE(-1, mTextureCubeUniformLocation);
563 }
564
565 void TearDown() override
566 {
567 glDeleteTextures(1, &mTextureCube);
568 TexCoordDrawTest::TearDown();
569 }
570
571 GLuint mTexture2D;
572 GLuint mTextureCube;
573 GLint mTexture2DUniformLocation;
574 GLint mTextureCubeUniformLocation;
575};
576
Martin Radev7e2c0d32017-09-15 14:25:42 +0300577class TextureCubeTestES3 : public ANGLETest
578{
579 protected:
580 TextureCubeTestES3() {}
581};
582
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200583class SamplerArrayTest : public TexCoordDrawTest
584{
585 protected:
586 SamplerArrayTest()
587 : TexCoordDrawTest(),
588 mTexture2DA(0),
589 mTexture2DB(0),
590 mTexture0UniformLocation(-1),
591 mTexture1UniformLocation(-1)
592 {
593 }
594
595 std::string getFragmentShaderSource() override
596 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300597 return
598 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200599 uniform highp sampler2D tex2DArray[2];
600 varying vec2 texcoord;
601 void main()
602 {
603 gl_FragColor = texture2D(tex2DArray[0], texcoord);
604 gl_FragColor += texture2D(tex2DArray[1], texcoord);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300605 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200606 }
607
608 void SetUp() override
609 {
610 TexCoordDrawTest::SetUp();
611
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300612 setUpProgram();
613
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200614 mTexture0UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[0]");
615 ASSERT_NE(-1, mTexture0UniformLocation);
616 mTexture1UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[1]");
617 ASSERT_NE(-1, mTexture1UniformLocation);
618
619 mTexture2DA = create2DTexture();
620 mTexture2DB = create2DTexture();
621 ASSERT_GL_NO_ERROR();
622 }
623
624 void TearDown() override
625 {
626 glDeleteTextures(1, &mTexture2DA);
627 glDeleteTextures(1, &mTexture2DB);
628 TexCoordDrawTest::TearDown();
629 }
630
631 void testSamplerArrayDraw()
632 {
633 GLubyte texData[4];
634 texData[0] = 0;
635 texData[1] = 60;
636 texData[2] = 0;
637 texData[3] = 255;
638
639 glActiveTexture(GL_TEXTURE0);
640 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
641 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
642
643 texData[1] = 120;
644 glActiveTexture(GL_TEXTURE1);
645 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
646 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
647 EXPECT_GL_ERROR(GL_NO_ERROR);
648
649 glUseProgram(mProgram);
650 glUniform1i(mTexture0UniformLocation, 0);
651 glUniform1i(mTexture1UniformLocation, 1);
652 drawQuad(mProgram, "position", 0.5f);
653 EXPECT_GL_NO_ERROR();
654
655 EXPECT_PIXEL_NEAR(0, 0, 0, 180, 0, 255, 2);
656 }
657
658 GLuint mTexture2DA;
659 GLuint mTexture2DB;
660 GLint mTexture0UniformLocation;
661 GLint mTexture1UniformLocation;
662};
663
664
665class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest
666{
667 protected:
668 SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {}
669
670 std::string getFragmentShaderSource() override
671 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300672 return
673 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200674 uniform highp sampler2D tex2DArray[2];
675 varying vec2 texcoord;
676
677 vec4 computeFragColor(highp sampler2D aTex2DArray[2])
678 {
679 return texture2D(aTex2DArray[0], texcoord) + texture2D(aTex2DArray[1], texcoord);
680 }
681
682 void main()
683 {
684 gl_FragColor = computeFragColor(tex2DArray);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300685 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200686 }
687};
688
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200689class Texture2DArrayTestES3 : public TexCoordDrawTest
690{
691 protected:
692 Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {}
693
694 std::string getVertexShaderSource() override
695 {
696 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400697 "#version 300 es\n"
698 "out vec2 texcoord;\n"
699 "in vec4 position;\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200700 "void main()\n"
701 "{\n"
702 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
703 " texcoord = (position.xy * 0.5) + 0.5;\n"
704 "}\n");
705 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400706
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200707 std::string getFragmentShaderSource() override
708 {
709 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400710 "#version 300 es\n"
711 "precision highp float;\n"
Olli Etuaho183d7e22015-11-20 15:59:09 +0200712 "uniform highp sampler2DArray tex2DArray;\n"
Jamie Madill2453dbc2015-07-14 11:35:42 -0400713 "in vec2 texcoord;\n"
714 "out vec4 fragColor;\n"
715 "void main()\n"
716 "{\n"
717 " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200718 "}\n");
719 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400720
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200721 void SetUp() override
722 {
723 TexCoordDrawTest::SetUp();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400724
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300725 setUpProgram();
726
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200727 mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray");
Jamie Madill2453dbc2015-07-14 11:35:42 -0400728 ASSERT_NE(-1, mTextureArrayLocation);
729
730 glGenTextures(1, &m2DArrayTexture);
731 ASSERT_GL_NO_ERROR();
732 }
733
734 void TearDown() override
735 {
736 glDeleteTextures(1, &m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200737 TexCoordDrawTest::TearDown();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400738 }
739
740 GLuint m2DArrayTexture;
Jamie Madill2453dbc2015-07-14 11:35:42 -0400741 GLint mTextureArrayLocation;
742};
743
Olli Etuahobce743a2016-01-15 17:18:28 +0200744class TextureSizeTextureArrayTest : public TexCoordDrawTest
745{
746 protected:
747 TextureSizeTextureArrayTest()
748 : TexCoordDrawTest(),
749 mTexture2DA(0),
750 mTexture2DB(0),
751 mTexture0Location(-1),
752 mTexture1Location(-1)
753 {
754 }
755
756 std::string getVertexShaderSource() override
757 {
Olli Etuaho5804dc82018-04-13 14:11:46 +0300758 return std::string(essl3_shaders::vs::Simple());
Olli Etuahobce743a2016-01-15 17:18:28 +0200759 }
760
761 std::string getFragmentShaderSource() override
762 {
763 return std::string(
764 "#version 300 es\n"
765 "precision highp float;\n"
766 "uniform highp sampler2D tex2DArray[2];\n"
767 "out vec4 fragColor;\n"
768 "void main()\n"
769 "{\n"
770 " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n"
771 " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n"
772 " fragColor = vec4(red, green, 0.0, 1.0);\n"
773 "}\n");
774 }
775
776 void SetUp() override
777 {
778 TexCoordDrawTest::SetUp();
779
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300780 setUpProgram();
781
Olli Etuahobce743a2016-01-15 17:18:28 +0200782 mTexture0Location = glGetUniformLocation(mProgram, "tex2DArray[0]");
783 ASSERT_NE(-1, mTexture0Location);
784 mTexture1Location = glGetUniformLocation(mProgram, "tex2DArray[1]");
785 ASSERT_NE(-1, mTexture1Location);
786
787 mTexture2DA = create2DTexture();
788 mTexture2DB = create2DTexture();
789 ASSERT_GL_NO_ERROR();
790 }
791
792 void TearDown() override
793 {
794 glDeleteTextures(1, &mTexture2DA);
795 glDeleteTextures(1, &mTexture2DB);
796 TexCoordDrawTest::TearDown();
797 }
798
799 GLuint mTexture2DA;
800 GLuint mTexture2DB;
801 GLint mTexture0Location;
802 GLint mTexture1Location;
803};
804
Olli Etuahoa314b612016-03-10 16:43:00 +0200805class Texture3DTestES3 : public TexCoordDrawTest
806{
807 protected:
808 Texture3DTestES3() : TexCoordDrawTest(), mTexture3D(0), mTexture3DUniformLocation(-1) {}
809
810 std::string getVertexShaderSource() override
811 {
812 return std::string(
813 "#version 300 es\n"
814 "out vec2 texcoord;\n"
815 "in vec4 position;\n"
816 "void main()\n"
817 "{\n"
818 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
819 " texcoord = (position.xy * 0.5) + 0.5;\n"
820 "}\n");
821 }
822
823 std::string getFragmentShaderSource() override
824 {
825 return std::string(
826 "#version 300 es\n"
827 "precision highp float;\n"
828 "uniform highp sampler3D tex3D;\n"
829 "in vec2 texcoord;\n"
830 "out vec4 fragColor;\n"
831 "void main()\n"
832 "{\n"
833 " fragColor = texture(tex3D, vec3(texcoord, 0.0));\n"
834 "}\n");
835 }
836
837 void SetUp() override
838 {
839 TexCoordDrawTest::SetUp();
840
841 glGenTextures(1, &mTexture3D);
842
843 setUpProgram();
844
845 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
846 ASSERT_NE(-1, mTexture3DUniformLocation);
847 }
848
849 void TearDown() override
850 {
851 glDeleteTextures(1, &mTexture3D);
852 TexCoordDrawTest::TearDown();
853 }
854
855 GLuint mTexture3D;
856 GLint mTexture3DUniformLocation;
857};
858
Olli Etuaho1a679902016-01-14 12:21:47 +0200859class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest
860{
861 protected:
862 ShadowSamplerPlusSampler3DTestES3()
863 : TexCoordDrawTest(),
864 mTextureShadow(0),
865 mTexture3D(0),
866 mTextureShadowUniformLocation(-1),
867 mTexture3DUniformLocation(-1),
868 mDepthRefUniformLocation(-1)
869 {
870 }
871
872 std::string getVertexShaderSource() override
873 {
874 return std::string(
875 "#version 300 es\n"
876 "out vec2 texcoord;\n"
877 "in vec4 position;\n"
878 "void main()\n"
879 "{\n"
880 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
881 " texcoord = (position.xy * 0.5) + 0.5;\n"
882 "}\n");
883 }
884
885 std::string getFragmentShaderSource() override
886 {
887 return std::string(
888 "#version 300 es\n"
889 "precision highp float;\n"
890 "uniform highp sampler2DShadow tex2DShadow;\n"
891 "uniform highp sampler3D tex3D;\n"
892 "in vec2 texcoord;\n"
893 "uniform float depthRef;\n"
894 "out vec4 fragColor;\n"
895 "void main()\n"
896 "{\n"
897 " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n"
898 " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n"
899 "}\n");
900 }
901
902 void SetUp() override
903 {
904 TexCoordDrawTest::SetUp();
905
906 glGenTextures(1, &mTexture3D);
907
908 glGenTextures(1, &mTextureShadow);
909 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
910 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
911
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300912 setUpProgram();
913
Olli Etuaho1a679902016-01-14 12:21:47 +0200914 mTextureShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
915 ASSERT_NE(-1, mTextureShadowUniformLocation);
916 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
917 ASSERT_NE(-1, mTexture3DUniformLocation);
918 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
919 ASSERT_NE(-1, mDepthRefUniformLocation);
920 }
921
922 void TearDown() override
923 {
924 glDeleteTextures(1, &mTextureShadow);
925 glDeleteTextures(1, &mTexture3D);
926 TexCoordDrawTest::TearDown();
927 }
928
929 GLuint mTextureShadow;
930 GLuint mTexture3D;
931 GLint mTextureShadowUniformLocation;
932 GLint mTexture3DUniformLocation;
933 GLint mDepthRefUniformLocation;
934};
935
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200936class SamplerTypeMixTestES3 : public TexCoordDrawTest
937{
938 protected:
939 SamplerTypeMixTestES3()
940 : TexCoordDrawTest(),
941 mTexture2D(0),
942 mTextureCube(0),
943 mTexture2DShadow(0),
944 mTextureCubeShadow(0),
945 mTexture2DUniformLocation(-1),
946 mTextureCubeUniformLocation(-1),
947 mTexture2DShadowUniformLocation(-1),
948 mTextureCubeShadowUniformLocation(-1),
949 mDepthRefUniformLocation(-1)
950 {
951 }
952
953 std::string getVertexShaderSource() override
954 {
955 return std::string(
956 "#version 300 es\n"
957 "out vec2 texcoord;\n"
958 "in vec4 position;\n"
959 "void main()\n"
960 "{\n"
961 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
962 " texcoord = (position.xy * 0.5) + 0.5;\n"
963 "}\n");
964 }
965
966 std::string getFragmentShaderSource() override
967 {
968 return std::string(
969 "#version 300 es\n"
970 "precision highp float;\n"
971 "uniform highp sampler2D tex2D;\n"
972 "uniform highp samplerCube texCube;\n"
973 "uniform highp sampler2DShadow tex2DShadow;\n"
974 "uniform highp samplerCubeShadow texCubeShadow;\n"
975 "in vec2 texcoord;\n"
976 "uniform float depthRef;\n"
977 "out vec4 fragColor;\n"
978 "void main()\n"
979 "{\n"
980 " fragColor = texture(tex2D, texcoord);\n"
981 " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n"
982 " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n"
983 " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * "
984 "0.125);\n"
985 "}\n");
986 }
987
988 void SetUp() override
989 {
990 TexCoordDrawTest::SetUp();
991
992 glGenTextures(1, &mTexture2D);
993 glGenTextures(1, &mTextureCube);
994
995 glGenTextures(1, &mTexture2DShadow);
996 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
997 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
998
999 glGenTextures(1, &mTextureCubeShadow);
1000 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
1001 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
1002
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001003 setUpProgram();
1004
Olli Etuahoc8c99a02016-01-14 16:47:22 +02001005 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
1006 ASSERT_NE(-1, mTexture2DUniformLocation);
1007 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
1008 ASSERT_NE(-1, mTextureCubeUniformLocation);
1009 mTexture2DShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
1010 ASSERT_NE(-1, mTexture2DShadowUniformLocation);
1011 mTextureCubeShadowUniformLocation = glGetUniformLocation(mProgram, "texCubeShadow");
1012 ASSERT_NE(-1, mTextureCubeShadowUniformLocation);
1013 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
1014 ASSERT_NE(-1, mDepthRefUniformLocation);
1015
1016 ASSERT_GL_NO_ERROR();
1017 }
1018
1019 void TearDown() override
1020 {
1021 glDeleteTextures(1, &mTexture2D);
1022 glDeleteTextures(1, &mTextureCube);
1023 glDeleteTextures(1, &mTexture2DShadow);
1024 glDeleteTextures(1, &mTextureCubeShadow);
1025 TexCoordDrawTest::TearDown();
1026 }
1027
1028 GLuint mTexture2D;
1029 GLuint mTextureCube;
1030 GLuint mTexture2DShadow;
1031 GLuint mTextureCubeShadow;
1032 GLint mTexture2DUniformLocation;
1033 GLint mTextureCubeUniformLocation;
1034 GLint mTexture2DShadowUniformLocation;
1035 GLint mTextureCubeShadowUniformLocation;
1036 GLint mDepthRefUniformLocation;
1037};
1038
Olli Etuaho96963162016-03-21 11:54:33 +02001039class SamplerInStructTest : public Texture2DTest
1040{
1041 protected:
1042 SamplerInStructTest() : Texture2DTest() {}
1043
1044 const char *getTextureUniformName() override { return "us.tex"; }
1045
1046 std::string getFragmentShaderSource() override
1047 {
1048 return std::string(
1049 "precision highp float;\n"
1050 "struct S\n"
1051 "{\n"
1052 " vec4 a;\n"
1053 " highp sampler2D tex;\n"
1054 "};\n"
1055 "uniform S us;\n"
1056 "varying vec2 texcoord;\n"
1057 "void main()\n"
1058 "{\n"
1059 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x);\n"
1060 "}\n");
1061 }
1062
1063 void runSamplerInStructTest()
1064 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001065 setUpProgram();
1066
Olli Etuaho96963162016-03-21 11:54:33 +02001067 glActiveTexture(GL_TEXTURE0);
1068 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001069 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1070 &GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001071 drawQuad(mProgram, "position", 0.5f);
Olli Etuahoa314b612016-03-10 16:43:00 +02001072 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001073 }
1074};
1075
1076class SamplerInStructAsFunctionParameterTest : public SamplerInStructTest
1077{
1078 protected:
1079 SamplerInStructAsFunctionParameterTest() : SamplerInStructTest() {}
1080
1081 std::string getFragmentShaderSource() override
1082 {
1083 return std::string(
1084 "precision highp float;\n"
1085 "struct S\n"
1086 "{\n"
1087 " vec4 a;\n"
1088 " highp sampler2D tex;\n"
1089 "};\n"
1090 "uniform S us;\n"
1091 "varying vec2 texcoord;\n"
1092 "vec4 sampleFrom(S s) {\n"
1093 " return texture2D(s.tex, texcoord + s.a.x);\n"
1094 "}\n"
1095 "void main()\n"
1096 "{\n"
1097 " gl_FragColor = sampleFrom(us);\n"
1098 "}\n");
1099 }
1100};
1101
1102class SamplerInStructArrayAsFunctionParameterTest : public SamplerInStructTest
1103{
1104 protected:
1105 SamplerInStructArrayAsFunctionParameterTest() : SamplerInStructTest() {}
1106
1107 const char *getTextureUniformName() override { return "us[0].tex"; }
1108
1109 std::string getFragmentShaderSource() override
1110 {
1111 return std::string(
1112 "precision highp float;\n"
1113 "struct S\n"
1114 "{\n"
1115 " vec4 a;\n"
1116 " highp sampler2D tex;\n"
1117 "};\n"
1118 "uniform S us[1];\n"
1119 "varying vec2 texcoord;\n"
1120 "vec4 sampleFrom(S s) {\n"
1121 " return texture2D(s.tex, texcoord + s.a.x);\n"
1122 "}\n"
1123 "void main()\n"
1124 "{\n"
1125 " gl_FragColor = sampleFrom(us[0]);\n"
1126 "}\n");
1127 }
1128};
1129
1130class SamplerInNestedStructAsFunctionParameterTest : public SamplerInStructTest
1131{
1132 protected:
1133 SamplerInNestedStructAsFunctionParameterTest() : SamplerInStructTest() {}
1134
1135 const char *getTextureUniformName() override { return "us[0].sub.tex"; }
1136
1137 std::string getFragmentShaderSource() override
1138 {
1139 return std::string(
1140 "precision highp float;\n"
1141 "struct SUB\n"
1142 "{\n"
1143 " vec4 a;\n"
1144 " highp sampler2D tex;\n"
1145 "};\n"
1146 "struct S\n"
1147 "{\n"
1148 " SUB sub;\n"
1149 "};\n"
1150 "uniform S us[1];\n"
1151 "varying vec2 texcoord;\n"
1152 "vec4 sampleFrom(SUB s) {\n"
1153 " return texture2D(s.tex, texcoord + s.a.x);\n"
1154 "}\n"
1155 "void main()\n"
1156 "{\n"
1157 " gl_FragColor = sampleFrom(us[0].sub);\n"
1158 "}\n");
1159 }
1160};
1161
1162class SamplerInStructAndOtherVariableTest : public SamplerInStructTest
1163{
1164 protected:
1165 SamplerInStructAndOtherVariableTest() : SamplerInStructTest() {}
1166
1167 std::string getFragmentShaderSource() override
1168 {
1169 return std::string(
1170 "precision highp float;\n"
1171 "struct S\n"
1172 "{\n"
1173 " vec4 a;\n"
1174 " highp sampler2D tex;\n"
1175 "};\n"
1176 "uniform S us;\n"
1177 "uniform float us_tex;\n"
1178 "varying vec2 texcoord;\n"
1179 "void main()\n"
1180 "{\n"
1181 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x + us_tex);\n"
1182 "}\n");
1183 }
1184};
1185
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001186TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001187{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001188 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001189 EXPECT_GL_ERROR(GL_NO_ERROR);
1190
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001191 setUpProgram();
1192
Jamie Madillf67115c2014-04-22 13:14:05 -04001193 const GLubyte *pixels[20] = { 0 };
1194 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1195 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001196
1197 if (extensionEnabled("GL_EXT_texture_storage"))
1198 {
1199 // Create a 1-level immutable texture.
1200 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1201
1202 // Try calling sub image on the second level.
1203 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1204 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1205 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001206}
Geoff Langc41e42d2014-04-28 10:58:16 -04001207
John Bauman18319182016-09-28 14:22:27 -07001208// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1209TEST_P(Texture2DTest, QueryBinding)
1210{
1211 glBindTexture(GL_TEXTURE_2D, 0);
1212 EXPECT_GL_ERROR(GL_NO_ERROR);
1213
1214 GLint textureBinding;
1215 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1216 EXPECT_GL_NO_ERROR();
1217 EXPECT_EQ(0, textureBinding);
1218
1219 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
1220 if (extensionEnabled("GL_OES_EGL_image_external") ||
1221 extensionEnabled("GL_NV_EGL_stream_consumer_external"))
1222 {
1223 EXPECT_GL_NO_ERROR();
1224 EXPECT_EQ(0, textureBinding);
1225 }
1226 else
1227 {
1228 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1229 }
1230}
1231
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001232TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001233{
Luc Ferrond8c632c2018-04-10 12:31:44 -04001234 // TODO(lucferron): Enable this test on Vulkan after Sampler Arrays are implemented.
1235 // http://anglebug.com/2462
Luc Ferron5164b792018-03-06 09:10:12 -05001236 ANGLE_SKIP_TEST_IF(IsVulkan());
1237
Jamie Madilld4cfa572014-07-08 10:00:32 -04001238 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001239 EXPECT_GL_ERROR(GL_NO_ERROR);
1240
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001241 setUpProgram();
1242
Geoff Langc41e42d2014-04-28 10:58:16 -04001243 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001244 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001245 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001246 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001247
1248 const GLubyte *pixel[4] = { 0 };
1249
1250 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1251 EXPECT_GL_NO_ERROR();
1252
1253 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1254 EXPECT_GL_NO_ERROR();
1255
1256 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1257 EXPECT_GL_NO_ERROR();
1258}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001259
1260// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001261TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001262{
1263 glActiveTexture(GL_TEXTURE0);
1264 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1265 glActiveTexture(GL_TEXTURE1);
1266 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1267 EXPECT_GL_ERROR(GL_NO_ERROR);
1268
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001269 glUseProgram(mProgram);
1270 glUniform1i(mTexture2DUniformLocation, 0);
1271 glUniform1i(mTextureCubeUniformLocation, 1);
1272 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001273 EXPECT_GL_NO_ERROR();
1274}
Jamie Madill9aca0592014-10-06 16:26:59 -04001275
Olli Etuaho53a2da12016-01-11 15:43:32 +02001276// Test drawing with two texture types accessed from the same shader and check that the result of
1277// drawing is correct.
1278TEST_P(TextureCubeTest, CubeMapDraw)
1279{
1280 GLubyte texData[4];
1281 texData[0] = 0;
1282 texData[1] = 60;
1283 texData[2] = 0;
1284 texData[3] = 255;
1285
1286 glActiveTexture(GL_TEXTURE0);
1287 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1288 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1289
1290 glActiveTexture(GL_TEXTURE1);
1291 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1292 texData[1] = 120;
1293 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1294 texData);
1295 EXPECT_GL_ERROR(GL_NO_ERROR);
1296
1297 glUseProgram(mProgram);
1298 glUniform1i(mTexture2DUniformLocation, 0);
1299 glUniform1i(mTextureCubeUniformLocation, 1);
1300 drawQuad(mProgram, "position", 0.5f);
1301 EXPECT_GL_NO_ERROR();
1302
1303 int px = getWindowWidth() - 1;
1304 int py = 0;
1305 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1306}
1307
Olli Etuaho4644a202016-01-12 15:12:53 +02001308TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1309{
1310 glActiveTexture(GL_TEXTURE0);
1311 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1312 GLubyte texData[4];
1313 texData[0] = 0;
1314 texData[1] = 128;
1315 texData[2] = 0;
1316 texData[3] = 255;
1317 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1318 glUseProgram(mProgram);
1319 glUniform1i(mTexture2DUniformLocation, 0);
1320 drawQuad(mProgram, "position", 0.5f);
1321 EXPECT_GL_NO_ERROR();
1322
1323 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1324}
1325
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001326// Test drawing with two textures passed to the shader in a sampler array.
1327TEST_P(SamplerArrayTest, SamplerArrayDraw)
1328{
1329 testSamplerArrayDraw();
1330}
1331
1332// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1333// user-defined function in the shader.
1334TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1335{
1336 testSamplerArrayDraw();
1337}
1338
Jamie Madill9aca0592014-10-06 16:26:59 -04001339// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001340TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001341{
Luc Ferronaf883622018-06-08 15:57:31 -04001342 // TODO(lucferron): Diagnose and fix
1343 // http://anglebug.com/2653
1344 ANGLE_SKIP_TEST_IF(IsVulkan());
1345
Jamie Madill9aca0592014-10-06 16:26:59 -04001346 int px = getWindowWidth() / 2;
1347 int py = getWindowHeight() / 2;
1348
1349 glActiveTexture(GL_TEXTURE0);
1350 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1351
Olli Etuahoa314b612016-03-10 16:43:00 +02001352 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001353
Olli Etuahoa314b612016-03-10 16:43:00 +02001354 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001355 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1356 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1357 glGenerateMipmap(GL_TEXTURE_2D);
1358
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001359 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001360 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001361 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1362 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001363 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001364 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001365
Olli Etuahoa314b612016-03-10 16:43:00 +02001366 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001367
Olli Etuahoa314b612016-03-10 16:43:00 +02001368 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1369 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001370 glGenerateMipmap(GL_TEXTURE_2D);
1371
Olli Etuahoa314b612016-03-10 16:43:00 +02001372 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001373
Olli Etuahoa314b612016-03-10 16:43:00 +02001374 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1375 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001376 glGenerateMipmap(GL_TEXTURE_2D);
1377
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001378 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001379
1380 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001381 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001382}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001383
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001384// Test creating a FBO with a cube map render target, to test an ANGLE bug
1385// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001386TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001387{
Luc Ferronaf883622018-06-08 15:57:31 -04001388 // TODO(jmadill): Cube map render targets. http://anglebug.com/2470
1389 ANGLE_SKIP_TEST_IF(IsVulkan());
1390
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001391 GLuint fbo;
1392 glGenFramebuffers(1, &fbo);
1393 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1394
1395 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1396 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mTextureCube, 0);
1397
Corentin Wallez322653b2015-06-17 18:33:56 +02001398 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001399
1400 glDeleteFramebuffers(1, &fbo);
1401
1402 EXPECT_GL_NO_ERROR();
1403}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001404
1405// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001406TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001407{
Luc Ferron7348fc52018-05-09 07:17:16 -04001408 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -04001409
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001410 int width = getWindowWidth();
1411 int height = getWindowHeight();
1412
1413 GLuint tex2D;
1414 glGenTextures(1, &tex2D);
1415 glActiveTexture(GL_TEXTURE0);
1416 glBindTexture(GL_TEXTURE_2D, tex2D);
1417
1418 // Fill with red
1419 std::vector<GLubyte> pixels(3 * 16 * 16);
1420 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1421 {
1422 pixels[pixelId * 3 + 0] = 255;
1423 pixels[pixelId * 3 + 1] = 0;
1424 pixels[pixelId * 3 + 2] = 0;
1425 }
1426
1427 // ANGLE internally uses RGBA as the DirectX format for RGB images
1428 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1429 // The data is kept in a CPU-side image and the image is marked as dirty.
Geoff Langc4e93662017-05-01 10:45:59 -04001430 if (getClientMajorVersion() >= 3)
1431 {
1432 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1433 }
1434 else
1435 {
1436 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1437 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001438
1439 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1440 // glTexSubImage2D should take into account that the image is dirty.
1441 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1442 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1443 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1444
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001445 setUpProgram();
1446
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001447 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001448 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001449 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001450 glDeleteTextures(1, &tex2D);
1451 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001452 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001453
1454 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001455 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1456 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001457}
1458
1459// 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 +02001460TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001461{
1462 if (extensionEnabled("NV_pixel_buffer_object"))
1463 {
1464 int width = getWindowWidth();
1465 int height = getWindowHeight();
1466
1467 GLuint tex2D;
1468 glGenTextures(1, &tex2D);
1469 glActiveTexture(GL_TEXTURE0);
1470 glBindTexture(GL_TEXTURE_2D, tex2D);
1471
1472 // Fill with red
1473 std::vector<GLubyte> pixels(3 * 16 * 16);
1474 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1475 {
1476 pixels[pixelId * 3 + 0] = 255;
1477 pixels[pixelId * 3 + 1] = 0;
1478 pixels[pixelId * 3 + 2] = 0;
1479 }
1480
1481 // Read 16x16 region from red backbuffer to PBO
1482 GLuint pbo;
1483 glGenBuffers(1, &pbo);
1484 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1485 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1486
1487 // ANGLE internally uses RGBA as the DirectX format for RGB images
1488 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1489 // The data is kept in a CPU-side image and the image is marked as dirty.
1490 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1491
1492 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1493 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001494 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 +00001495 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1496 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1497
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001498 setUpProgram();
1499
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001500 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001501 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001502 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001503 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001504 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001505 EXPECT_GL_NO_ERROR();
1506 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1507 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1508 }
1509}
Jamie Madillbc393df2015-01-29 13:46:07 -05001510
1511// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001512TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001513{
1514 testFloatCopySubImage(1, 1);
1515}
1516
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001517TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001518{
1519 testFloatCopySubImage(2, 1);
1520}
1521
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001522TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001523{
1524 testFloatCopySubImage(2, 2);
1525}
1526
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001527TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001528{
1529 testFloatCopySubImage(3, 1);
1530}
1531
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001532TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001533{
1534 testFloatCopySubImage(3, 2);
1535}
1536
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001537TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001538{
Yunchao He9550c602018-02-13 14:47:05 +08001539 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1540 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001541
Yunchao He9550c602018-02-13 14:47:05 +08001542 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1543 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001544
Jamie Madillbc393df2015-01-29 13:46:07 -05001545 testFloatCopySubImage(3, 3);
1546}
1547
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001548TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001549{
1550 testFloatCopySubImage(4, 1);
1551}
1552
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001553TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001554{
1555 testFloatCopySubImage(4, 2);
1556}
1557
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001558TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001559{
Yunchao He9550c602018-02-13 14:47:05 +08001560 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1561 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001562
Jamie Madillbc393df2015-01-29 13:46:07 -05001563 testFloatCopySubImage(4, 3);
1564}
1565
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001566TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001567{
Luc Ferronfa7503c2018-05-08 11:25:06 -04001568 // TODO(lucferron): copySubImage isn't implemented yet.
1569 // http://anglebug.com/2501
1570 ANGLE_SKIP_TEST_IF(IsVulkan());
1571
Yunchao He9550c602018-02-13 14:47:05 +08001572 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1573 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001574
Jamie Madillbc393df2015-01-29 13:46:07 -05001575 testFloatCopySubImage(4, 4);
1576}
Austin Kinross07285142015-03-26 11:36:16 -07001577
1578// Port of https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1579// 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 +02001580TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001581{
Luc Ferron5164b792018-03-06 09:10:12 -05001582 // TODO(lucferron): DIRTY_BIT_UNPACK_STATE isn't implemented on Vulkan yet.
1583 ANGLE_SKIP_TEST_IF(IsVulkan());
1584
Austin Kinross07285142015-03-26 11:36:16 -07001585 const int npotTexSize = 5;
1586 const int potTexSize = 4; // Should be less than npotTexSize
1587 GLuint tex2D;
1588
1589 if (extensionEnabled("GL_OES_texture_npot"))
1590 {
1591 // This test isn't applicable if texture_npot is enabled
1592 return;
1593 }
1594
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001595 setUpProgram();
1596
Austin Kinross07285142015-03-26 11:36:16 -07001597 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1598
Austin Kinross5faa15b2016-01-11 13:32:48 -08001599 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1600 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1601
Austin Kinross07285142015-03-26 11:36:16 -07001602 glActiveTexture(GL_TEXTURE0);
1603 glGenTextures(1, &tex2D);
1604 glBindTexture(GL_TEXTURE_2D, tex2D);
1605
1606 std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize);
1607 for (size_t pixelId = 0; pixelId < npotTexSize * npotTexSize; ++pixelId)
1608 {
1609 pixels[pixelId] = 64;
1610 }
1611
1612 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1613 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1614
1615 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
1616 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1617 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1618
1619 // Check that an NPOT texture on level 0 succeeds
1620 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1621 EXPECT_GL_NO_ERROR();
1622
1623 // Check that generateMipmap fails on NPOT
1624 glGenerateMipmap(GL_TEXTURE_2D);
1625 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1626
1627 // Check that nothing is drawn if filtering is not correct for NPOT
1628 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1629 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1630 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1631 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1632 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001633 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001634 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1635
1636 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1637 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1638 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1639 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1640 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001641 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001642 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1643
1644 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1645 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1646 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001647 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001648 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1649
1650 // Check that glTexImage2D for POT texture succeeds
1651 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1652 EXPECT_GL_NO_ERROR();
1653
1654 // Check that generateMipmap for an POT texture succeeds
1655 glGenerateMipmap(GL_TEXTURE_2D);
1656 EXPECT_GL_NO_ERROR();
1657
1658 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1659 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1660 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1661 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1662 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1663 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001664 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001665 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1666 EXPECT_GL_NO_ERROR();
1667}
Jamie Madillfa05f602015-05-07 13:47:11 -04001668
Austin Kinross08528e12015-10-07 16:24:40 -07001669// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1670// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001671TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001672{
Luc Ferron5164b792018-03-06 09:10:12 -05001673 // TODO(lucferron): Generate mipmap on vulkan isn't implemented yet. Re-enable this when it
1674 // is.
1675 ANGLE_SKIP_TEST_IF(IsVulkan());
1676
Austin Kinross08528e12015-10-07 16:24:40 -07001677 glActiveTexture(GL_TEXTURE0);
1678 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1679
1680 // Create an 8x8 (i.e. power-of-two) texture.
1681 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1682 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1683 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1684 glGenerateMipmap(GL_TEXTURE_2D);
1685
1686 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1687 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001688 std::array<GLColor, 3 * 3> data;
1689 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001690
1691 EXPECT_GL_NO_ERROR();
1692}
1693
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001694// Test to check that texture completeness is determined correctly when the texture base level is
1695// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1696TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1697{
1698 glActiveTexture(GL_TEXTURE0);
1699 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001700
1701 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1702 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1703 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1704 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1705 texDataGreen.data());
1706 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1707 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001708 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1709 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1710 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1711
1712 EXPECT_GL_NO_ERROR();
1713
1714 drawQuad(mProgram, "position", 0.5f);
1715
Olli Etuahoa314b612016-03-10 16:43:00 +02001716 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1717}
1718
1719// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1720// have images defined.
1721TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1722{
Yunchao He9550c602018-02-13 14:47:05 +08001723 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1724 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1725
Olli Etuahoa314b612016-03-10 16:43:00 +02001726 glActiveTexture(GL_TEXTURE0);
1727 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1728 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1729 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1730 texDataGreen.data());
1731 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1732 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1733 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1734 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1735
1736 EXPECT_GL_NO_ERROR();
1737
1738 drawQuad(mProgram, "position", 0.5f);
1739
1740 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1741}
1742
Olli Etuahoe8528d82016-05-16 17:50:52 +03001743// Test that drawing works correctly when level 0 is undefined and base level is 1.
1744TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1745{
Yunchao He9550c602018-02-13 14:47:05 +08001746 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1747 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1748
Olli Etuahoe8528d82016-05-16 17:50:52 +03001749 glActiveTexture(GL_TEXTURE0);
1750 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1751 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1752 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1753 texDataGreen.data());
1754 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1755 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1756 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1757 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1758
1759 EXPECT_GL_NO_ERROR();
1760
1761 // Texture is incomplete.
1762 drawQuad(mProgram, "position", 0.5f);
1763 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1764
1765 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1766 texDataGreen.data());
1767
1768 // Texture is now complete.
1769 drawQuad(mProgram, "position", 0.5f);
1770 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1771}
1772
Olli Etuahoa314b612016-03-10 16:43:00 +02001773// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1774// dimensions that don't fit the images inside the range.
1775// GLES 3.0.4 section 3.8.13 Texture completeness
1776TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1777{
Olli Etuahoa314b612016-03-10 16:43:00 +02001778 glActiveTexture(GL_TEXTURE0);
1779 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1780 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1781 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1782 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1783
1784 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1785 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1786
1787 // Two levels that are initially unused.
1788 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1789 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1790 texDataCyan.data());
1791
1792 // One level that is used - only this level should affect completeness.
1793 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1794 texDataGreen.data());
1795
1796 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1797 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1798
1799 EXPECT_GL_NO_ERROR();
1800
1801 drawQuad(mProgram, "position", 0.5f);
1802
1803 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1804
Yunchao He2f23f352018-02-11 22:11:37 +08001805 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001806
1807 // Switch the level that is being used to the cyan level 2.
1808 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1809 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1810
1811 EXPECT_GL_NO_ERROR();
1812
1813 drawQuad(mProgram, "position", 0.5f);
1814
1815 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1816}
1817
1818// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1819// have images defined.
1820TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1821{
Olli Etuahoa314b612016-03-10 16:43:00 +02001822 glActiveTexture(GL_TEXTURE0);
1823 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1824 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1825 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1826 texDataGreen.data());
1827 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1828 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1829 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1830 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1831
1832 EXPECT_GL_NO_ERROR();
1833
1834 drawQuad(mProgram, "position", 0.5f);
1835
1836 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1837}
1838
1839// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1840// dimensions that don't fit the images inside the range.
1841// GLES 3.0.4 section 3.8.13 Texture completeness
1842TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1843{
Olli Etuahoa314b612016-03-10 16:43:00 +02001844 glActiveTexture(GL_TEXTURE0);
1845 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1846 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1847 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1848 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1849
1850 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1851 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1852
1853 // Two levels that are initially unused.
1854 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1855 texDataRed.data());
1856 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1857 texDataCyan.data());
1858
1859 // One level that is used - only this level should affect completeness.
1860 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1861 texDataGreen.data());
1862
1863 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1864 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1865
1866 EXPECT_GL_NO_ERROR();
1867
1868 drawQuad(mProgram, "position", 0.5f);
1869
1870 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1871
Yunchao He2f23f352018-02-11 22:11:37 +08001872 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001873
1874 // Switch the level that is being used to the cyan level 2.
1875 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
1876 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
1877
1878 EXPECT_GL_NO_ERROR();
1879
1880 drawQuad(mProgram, "position", 0.5f);
1881
1882 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1883}
1884
1885// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1886// have images defined.
1887TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
1888{
Olli Etuahoa314b612016-03-10 16:43:00 +02001889 glActiveTexture(GL_TEXTURE0);
1890 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
1891 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1892 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1893 texDataGreen.data());
1894 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1895 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1896 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1897 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1898
1899 EXPECT_GL_NO_ERROR();
1900
1901 drawQuad(mProgram, "position", 0.5f);
1902
1903 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1904}
1905
1906// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1907// dimensions that don't fit the images inside the range.
1908// GLES 3.0.4 section 3.8.13 Texture completeness
1909TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1910{
Olli Etuahoa314b612016-03-10 16:43:00 +02001911 glActiveTexture(GL_TEXTURE0);
1912 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
1913 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1914 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1915 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1916
1917 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1918 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1919
1920 // Two levels that are initially unused.
1921 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1922 texDataRed.data());
1923 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1924 texDataCyan.data());
1925
1926 // One level that is used - only this level should affect completeness.
1927 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1928 texDataGreen.data());
1929
1930 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1931 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1932
1933 EXPECT_GL_NO_ERROR();
1934
1935 drawQuad(mProgram, "position", 0.5f);
1936
1937 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1938
Yunchao He2f23f352018-02-11 22:11:37 +08001939 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
1940
Yunchao He9550c602018-02-13 14:47:05 +08001941 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
1942 // level was changed.
1943 ANGLE_SKIP_TEST_IF(IsNVIDIA() && (IsOpenGL() || IsOpenGLES()));
Olli Etuahoa314b612016-03-10 16:43:00 +02001944
1945 // Switch the level that is being used to the cyan level 2.
1946 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
1947 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
1948
1949 EXPECT_GL_NO_ERROR();
1950
1951 drawQuad(mProgram, "position", 0.5f);
1952
1953 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1954}
1955
1956// Test that texture completeness is updated if texture max level changes.
1957// GLES 3.0.4 section 3.8.13 Texture completeness
1958TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
1959{
Olli Etuahoa314b612016-03-10 16:43:00 +02001960 glActiveTexture(GL_TEXTURE0);
1961 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1962 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
1963
1964 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1965 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1966
1967 // A level that is initially unused.
1968 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1969 texDataGreen.data());
1970
1971 // One level that is initially used - only this level should affect completeness.
1972 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1973 texDataGreen.data());
1974
1975 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
1976 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
1977
1978 EXPECT_GL_NO_ERROR();
1979
1980 drawQuad(mProgram, "position", 0.5f);
1981
1982 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1983
1984 // Switch the max level to level 1. The levels within the used range now have inconsistent
1985 // dimensions and the texture should be incomplete.
1986 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1987
1988 EXPECT_GL_NO_ERROR();
1989
1990 drawQuad(mProgram, "position", 0.5f);
1991
1992 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1993}
1994
1995// Test that 3D texture completeness is updated if texture max level changes.
1996// GLES 3.0.4 section 3.8.13 Texture completeness
1997TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
1998{
Olli Etuahoa314b612016-03-10 16:43:00 +02001999 glActiveTexture(GL_TEXTURE0);
2000 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2001 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2002
2003 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2004 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2005
2006 // A level that is initially unused.
2007 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2008 texDataGreen.data());
2009
2010 // One level that is initially used - only this level should affect completeness.
2011 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2012 texDataGreen.data());
2013
2014 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2015 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2016
2017 EXPECT_GL_NO_ERROR();
2018
2019 drawQuad(mProgram, "position", 0.5f);
2020
2021 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2022
2023 // Switch the max level to level 1. The levels within the used range now have inconsistent
2024 // dimensions and the texture should be incomplete.
2025 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2026
2027 EXPECT_GL_NO_ERROR();
2028
2029 drawQuad(mProgram, "position", 0.5f);
2030
2031 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2032}
2033
2034// Test that texture completeness is updated if texture base level changes.
2035// GLES 3.0.4 section 3.8.13 Texture completeness
2036TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2037{
Olli Etuahoa314b612016-03-10 16:43:00 +02002038 glActiveTexture(GL_TEXTURE0);
2039 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2040 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2041
2042 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2043 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2044
2045 // Two levels that are initially unused.
2046 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2047 texDataGreen.data());
2048 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2049 texDataGreen.data());
2050
2051 // One level that is initially used - only this level should affect completeness.
2052 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2053 texDataGreen.data());
2054
2055 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2056 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2057
2058 EXPECT_GL_NO_ERROR();
2059
2060 drawQuad(mProgram, "position", 0.5f);
2061
2062 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2063
2064 // Switch the base level to level 1. The levels within the used range now have inconsistent
2065 // dimensions and the texture should be incomplete.
2066 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2067
2068 EXPECT_GL_NO_ERROR();
2069
2070 drawQuad(mProgram, "position", 0.5f);
2071
2072 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2073}
2074
2075// Test that texture is not complete if base level is greater than max level.
2076// GLES 3.0.4 section 3.8.13 Texture completeness
2077TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2078{
Olli Etuahoa314b612016-03-10 16:43:00 +02002079 glActiveTexture(GL_TEXTURE0);
2080 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2081
2082 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2083 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2084
2085 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2086
2087 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2088 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2089
2090 EXPECT_GL_NO_ERROR();
2091
2092 drawQuad(mProgram, "position", 0.5f);
2093
2094 // Texture should be incomplete.
2095 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2096}
2097
2098// Test that immutable texture base level and max level are clamped.
2099// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2100TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2101{
Olli Etuahoa314b612016-03-10 16:43:00 +02002102 glActiveTexture(GL_TEXTURE0);
2103 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2104
2105 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2106 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2107
2108 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2109
2110 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2111
2112 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2113 // should be clamped to [base_level, levels - 1].
2114 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2115 // In the case of this test, those rules make the effective base level and max level 0.
2116 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2117 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2118
2119 EXPECT_GL_NO_ERROR();
2120
2121 drawQuad(mProgram, "position", 0.5f);
2122
2123 // Texture should be complete.
2124 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2125}
2126
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002127// Test that changing base level works when it affects the format of the texture.
2128TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2129{
Yunchao He9550c602018-02-13 14:47:05 +08002130 // Observed rendering corruption on NVIDIA OpenGL.
2131 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL());
2132
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002133 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002134
2135 // Observed incorrect rendering on AMD OpenGL.
2136 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002137
2138 glActiveTexture(GL_TEXTURE0);
2139 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2140 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2141 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2142
2143 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2144 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2145
2146 // RGBA8 level that's initially unused.
2147 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2148 texDataCyan.data());
2149
2150 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2151 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2152
2153 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2154 // format. It reads green channel data from the green and alpha channels of texDataGreen
2155 // (this is a bit hacky but works).
2156 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2157
2158 EXPECT_GL_NO_ERROR();
2159
2160 drawQuad(mProgram, "position", 0.5f);
2161
2162 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2163
2164 // Switch the texture to use the cyan level 0 with the RGBA format.
2165 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2166 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2167
2168 EXPECT_GL_NO_ERROR();
2169
2170 drawQuad(mProgram, "position", 0.5f);
2171
2172 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2173}
2174
Olli Etuahoa314b612016-03-10 16:43:00 +02002175// Test that setting a texture image works when base level is out of range.
2176TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2177{
2178 glActiveTexture(GL_TEXTURE0);
2179 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2180
2181 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2182 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2183
2184 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2185 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2186
2187 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2188
2189 EXPECT_GL_NO_ERROR();
2190
2191 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2192
2193 drawQuad(mProgram, "position", 0.5f);
2194
2195 // Texture should be complete.
2196 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002197}
2198
Jamie Madill2453dbc2015-07-14 11:35:42 -04002199// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG RBA->RGBA8, with 1.0
2200// in the alpha channel. This test covers a bug where redefining array textures with these formats does not work as
2201// expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002202TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002203{
2204 std::vector<GLubyte> pixelData;
2205 for (size_t count = 0; count < 5000; count++)
2206 {
2207 pixelData.push_back(0u);
2208 pixelData.push_back(255u);
2209 pixelData.push_back(0u);
2210 }
2211
2212 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002213 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002214 glUniform1i(mTextureArrayLocation, 0);
2215
2216 // The first draw worked correctly.
2217 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
2218
2219 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2220 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2221 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2222 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002223 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002224 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002225
2226 // The dimension of the respecification must match the original exactly to trigger the bug.
2227 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 +02002228 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002229 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002230
2231 ASSERT_GL_NO_ERROR();
2232}
2233
Olli Etuaho1a679902016-01-14 12:21:47 +02002234// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2235// This test is needed especially to confirm that sampler registers get assigned correctly on
2236// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2237TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2238{
2239 glActiveTexture(GL_TEXTURE0);
2240 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2241 GLubyte texData[4];
2242 texData[0] = 0;
2243 texData[1] = 60;
2244 texData[2] = 0;
2245 texData[3] = 255;
2246 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2247
2248 glActiveTexture(GL_TEXTURE1);
2249 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2250 GLfloat depthTexData[1];
2251 depthTexData[0] = 0.5f;
2252 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2253 depthTexData);
2254
2255 glUseProgram(mProgram);
2256 glUniform1f(mDepthRefUniformLocation, 0.3f);
2257 glUniform1i(mTexture3DUniformLocation, 0);
2258 glUniform1i(mTextureShadowUniformLocation, 1);
2259
2260 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2261 drawQuad(mProgram, "position", 0.5f);
2262 EXPECT_GL_NO_ERROR();
2263 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2264 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2265
2266 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2267 drawQuad(mProgram, "position", 0.5f);
2268 EXPECT_GL_NO_ERROR();
2269 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2270 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2271}
2272
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002273// Test multiple different sampler types in the same shader.
2274// This test makes sure that even if sampler / texture registers get grouped together based on type
2275// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2276// still has the right register index information for each ESSL sampler.
2277// The tested ESSL samplers have the following types in D3D11 HLSL:
2278// sampler2D: Texture2D + SamplerState
2279// samplerCube: TextureCube + SamplerState
2280// sampler2DShadow: Texture2D + SamplerComparisonState
2281// samplerCubeShadow: TextureCube + SamplerComparisonState
2282TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2283{
2284 glActiveTexture(GL_TEXTURE0);
2285 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2286 GLubyte texData[4];
2287 texData[0] = 0;
2288 texData[1] = 0;
2289 texData[2] = 120;
2290 texData[3] = 255;
2291 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2292
2293 glActiveTexture(GL_TEXTURE1);
2294 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2295 texData[0] = 0;
2296 texData[1] = 90;
2297 texData[2] = 0;
2298 texData[3] = 255;
2299 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2300 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2301 texData);
2302
2303 glActiveTexture(GL_TEXTURE2);
2304 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2305 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
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 glActiveTexture(GL_TEXTURE3);
2312 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2313 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2314 depthTexData[0] = 0.2f;
2315 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2316 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2317 depthTexData);
2318
2319 EXPECT_GL_NO_ERROR();
2320
2321 glUseProgram(mProgram);
2322 glUniform1f(mDepthRefUniformLocation, 0.3f);
2323 glUniform1i(mTexture2DUniformLocation, 0);
2324 glUniform1i(mTextureCubeUniformLocation, 1);
2325 glUniform1i(mTexture2DShadowUniformLocation, 2);
2326 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2327
2328 drawQuad(mProgram, "position", 0.5f);
2329 EXPECT_GL_NO_ERROR();
2330 // The shader writes:
2331 // <texture 2d color> +
2332 // <cube map color> +
2333 // 0.25 * <comparison result (1.0)> +
2334 // 0.125 * <comparison result (0.0)>
2335 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2336}
2337
Olli Etuahobce743a2016-01-15 17:18:28 +02002338// Test different base levels on textures accessed through the same sampler array.
2339// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2340TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2341{
Yunchao He9550c602018-02-13 14:47:05 +08002342 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2343
Olli Etuahobce743a2016-01-15 17:18:28 +02002344 glActiveTexture(GL_TEXTURE0);
2345 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2346 GLsizei size = 64;
2347 for (GLint level = 0; level < 7; ++level)
2348 {
2349 ASSERT_LT(0, size);
2350 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2351 nullptr);
2352 size = size / 2;
2353 }
2354 ASSERT_EQ(0, size);
2355 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2356
2357 glActiveTexture(GL_TEXTURE1);
2358 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2359 size = 128;
2360 for (GLint level = 0; level < 8; ++level)
2361 {
2362 ASSERT_LT(0, size);
2363 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2364 nullptr);
2365 size = size / 2;
2366 }
2367 ASSERT_EQ(0, size);
2368 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2369 EXPECT_GL_NO_ERROR();
2370
2371 glUseProgram(mProgram);
2372 glUniform1i(mTexture0Location, 0);
2373 glUniform1i(mTexture1Location, 1);
2374
Olli Etuaho5804dc82018-04-13 14:11:46 +03002375 drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
Olli Etuahobce743a2016-01-15 17:18:28 +02002376 EXPECT_GL_NO_ERROR();
2377 // Red channel: width of level 1 of texture A: 32.
2378 // Green channel: width of level 3 of texture B: 16.
2379 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2380}
2381
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002382// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2383// ES 3.0.4 table 3.24
2384TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2385{
2386 glActiveTexture(GL_TEXTURE0);
2387 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2388 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2389 EXPECT_GL_NO_ERROR();
2390
2391 drawQuad(mProgram, "position", 0.5f);
2392
2393 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2394}
2395
2396// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2397// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002398TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002399{
Luc Ferron5164b792018-03-06 09:10:12 -05002400 setUpProgram();
2401
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002402 glActiveTexture(GL_TEXTURE0);
2403 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2404 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2405 EXPECT_GL_NO_ERROR();
2406
2407 drawQuad(mProgram, "position", 0.5f);
2408
2409 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2410}
2411
Luc Ferron5164b792018-03-06 09:10:12 -05002412// Validate that every component of the pixel will be equal to the luminance value we've set
2413// and that the alpha channel will be 1 (or 255 to be exact).
2414TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2415{
2416 setUpProgram();
2417
2418 glActiveTexture(GL_TEXTURE0);
2419 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2420 uint8_t pixel = 50;
2421 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2422 EXPECT_GL_NO_ERROR();
2423
2424 drawQuad(mProgram, "position", 0.5f);
2425
2426 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2427}
2428
2429// Validate that every component of the pixel will be equal to the luminance value we've set
2430// and that the alpha channel will be the second component.
2431TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2432{
2433 setUpProgram();
2434
2435 glActiveTexture(GL_TEXTURE0);
2436 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2437 uint8_t pixel[] = {50, 25};
2438 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2439 GL_UNSIGNED_BYTE, pixel);
2440 EXPECT_GL_NO_ERROR();
2441
2442 drawQuad(mProgram, "position", 0.5f);
2443
2444 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2445}
2446
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002447// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2448// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002449TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002450{
Luc Ferrond8c632c2018-04-10 12:31:44 -04002451 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
2452 ANGLE_SKIP_TEST_IF(IsD3D9());
2453 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002454
2455 setUpProgram();
2456
Luc Ferrond8c632c2018-04-10 12:31:44 -04002457 glActiveTexture(GL_TEXTURE0);
2458 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2459 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2460 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002461
Luc Ferrond8c632c2018-04-10 12:31:44 -04002462 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002463
Luc Ferrond8c632c2018-04-10 12:31:44 -04002464 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002465}
2466
2467// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2468// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002469TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002470{
Luc Ferrond8c632c2018-04-10 12:31:44 -04002471 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
2472 ANGLE_SKIP_TEST_IF(IsD3D9());
2473 ANGLE_SKIP_TEST_IF(IsVulkan());
2474 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES());
2475 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2476 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002477
Luc Ferrond8c632c2018-04-10 12:31:44 -04002478 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002479
Luc Ferrond8c632c2018-04-10 12:31:44 -04002480 glActiveTexture(GL_TEXTURE0);
2481 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2482 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2483 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002484
Luc Ferrond8c632c2018-04-10 12:31:44 -04002485 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002486
Luc Ferrond8c632c2018-04-10 12:31:44 -04002487 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002488}
2489
2490// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2491// ES 3.0.4 table 3.24
2492TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2493{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002494 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2495
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002496 glActiveTexture(GL_TEXTURE0);
2497 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2498 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2499 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2500 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2501 EXPECT_GL_NO_ERROR();
2502
2503 drawQuad(mProgram, "position", 0.5f);
2504
2505 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2506}
2507
2508// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2509// ES 3.0.4 table 3.24
2510TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2511{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002512 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2513
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002514 glActiveTexture(GL_TEXTURE0);
2515 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2516
2517 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2518 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2519 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2520 EXPECT_GL_NO_ERROR();
2521
2522 drawQuad(mProgram, "position", 0.5f);
2523
2524 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2525}
2526
2527// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2528// ES 3.0.4 table 3.24
2529TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2530{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002531 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2532
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002533 glActiveTexture(GL_TEXTURE0);
2534 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2535 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2536 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2537 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2538 EXPECT_GL_NO_ERROR();
2539
2540 drawQuad(mProgram, "position", 0.5f);
2541
2542 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2543}
2544
2545// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2546// ES 3.0.4 table 3.24
2547TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2548{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002549 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2550
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002551 glActiveTexture(GL_TEXTURE0);
2552 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2553 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2554 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2555 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2556 EXPECT_GL_NO_ERROR();
2557
2558 drawQuad(mProgram, "position", 0.5f);
2559
2560 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2561}
2562
2563// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2564// ES 3.0.4 table 3.24
2565TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2566{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002567 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2568
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002569 glActiveTexture(GL_TEXTURE0);
2570 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2571 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2572 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2573 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2574 EXPECT_GL_NO_ERROR();
2575
2576 drawQuad(mProgram, "position", 0.5f);
2577
2578 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2579}
2580
2581// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2582// ES 3.0.4 table 3.24
2583TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2584{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002585 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2586
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002587 glActiveTexture(GL_TEXTURE0);
2588 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2589 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2590 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2591 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2592 EXPECT_GL_NO_ERROR();
2593
2594 drawQuad(mProgram, "position", 0.5f);
2595
2596 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2597}
2598
2599// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2600// ES 3.0.4 table 3.24
2601TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2602{
2603 glActiveTexture(GL_TEXTURE0);
2604 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2605 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2606 EXPECT_GL_NO_ERROR();
2607
2608 drawQuad(mProgram, "position", 0.5f);
2609
2610 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2611}
2612
2613// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2614// ES 3.0.4 table 3.24
2615TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2616{
2617 glActiveTexture(GL_TEXTURE0);
2618 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2619 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2620 nullptr);
2621 EXPECT_GL_NO_ERROR();
2622
2623 drawQuad(mProgram, "position", 0.5f);
2624
2625 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2626}
2627
2628// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2629// ES 3.0.4 table 3.24
2630TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2631{
Yunchao He9550c602018-02-13 14:47:05 +08002632 // Seems to fail on OSX 10.12 Intel.
2633 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Jamie Madillbb1db482017-01-10 10:48:32 -05002634
Yuly Novikov49886892018-01-23 21:18:27 -05002635 // http://anglebug.com/2190
2636 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2637
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002638 glActiveTexture(GL_TEXTURE0);
2639 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2640 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2641 EXPECT_GL_NO_ERROR();
2642
2643 drawQuad(mProgram, "position", 0.5f);
2644
2645 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2646}
2647
2648// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2649// ES 3.0.4 table 3.24
2650TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2651{
Yunchao He9550c602018-02-13 14:47:05 +08002652 // Seems to fail on OSX 10.12 Intel.
2653 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002654
Yuly Novikov49886892018-01-23 21:18:27 -05002655 // http://anglebug.com/2190
2656 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2657
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002658 glActiveTexture(GL_TEXTURE0);
2659 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2660 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2661 EXPECT_GL_NO_ERROR();
2662
2663 drawQuad(mProgram, "position", 0.5f);
2664
2665 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2666}
2667
Olli Etuaho96963162016-03-21 11:54:33 +02002668// Use a sampler in a uniform struct.
2669TEST_P(SamplerInStructTest, SamplerInStruct)
2670{
2671 runSamplerInStructTest();
2672}
2673
2674// Use a sampler in a uniform struct that's passed as a function parameter.
2675TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2676{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002677 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002678 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002679
Olli Etuaho96963162016-03-21 11:54:33 +02002680 runSamplerInStructTest();
2681}
2682
2683// Use a sampler in a uniform struct array with a struct from the array passed as a function
2684// parameter.
2685TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2686{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002687 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002688 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
2689
Olli Etuaho96963162016-03-21 11:54:33 +02002690 runSamplerInStructTest();
2691}
2692
2693// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2694// parameter.
2695TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2696{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002697 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002698 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
2699
Olli Etuaho96963162016-03-21 11:54:33 +02002700 runSamplerInStructTest();
2701}
2702
2703// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2704// similarly named uniform.
2705TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2706{
2707 runSamplerInStructTest();
2708}
2709
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002710class TextureLimitsTest : public ANGLETest
2711{
2712 protected:
2713 struct RGBA8
2714 {
2715 uint8_t R, G, B, A;
2716 };
2717
2718 TextureLimitsTest()
2719 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
2720 {
2721 setWindowWidth(128);
2722 setWindowHeight(128);
2723 setConfigRedBits(8);
2724 setConfigGreenBits(8);
2725 setConfigBlueBits(8);
2726 setConfigAlphaBits(8);
2727 }
2728
2729 ~TextureLimitsTest()
2730 {
2731 if (mProgram != 0)
2732 {
2733 glDeleteProgram(mProgram);
2734 mProgram = 0;
2735
2736 if (!mTextures.empty())
2737 {
2738 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
2739 }
2740 }
2741 }
2742
2743 void SetUp() override
2744 {
2745 ANGLETest::SetUp();
2746
2747 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
2748 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
2749 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
2750
2751 ASSERT_GL_NO_ERROR();
2752 }
2753
2754 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
2755 GLint vertexTextureCount,
2756 GLint vertexActiveTextureCount,
2757 const std::string &fragPrefix,
2758 GLint fragmentTextureCount,
2759 GLint fragmentActiveTextureCount)
2760 {
2761 std::stringstream vertexShaderStr;
2762 vertexShaderStr << "attribute vec2 position;\n"
2763 << "varying vec4 color;\n"
2764 << "varying vec2 texCoord;\n";
2765
2766 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
2767 {
2768 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
2769 }
2770
2771 vertexShaderStr << "void main() {\n"
2772 << " gl_Position = vec4(position, 0, 1);\n"
2773 << " texCoord = (position * 0.5) + 0.5;\n"
2774 << " color = vec4(0);\n";
2775
2776 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
2777 {
2778 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
2779 << ", texCoord);\n";
2780 }
2781
2782 vertexShaderStr << "}";
2783
2784 std::stringstream fragmentShaderStr;
2785 fragmentShaderStr << "varying mediump vec4 color;\n"
2786 << "varying mediump vec2 texCoord;\n";
2787
2788 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
2789 {
2790 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
2791 }
2792
2793 fragmentShaderStr << "void main() {\n"
2794 << " gl_FragColor = color;\n";
2795
2796 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
2797 {
2798 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
2799 << ", texCoord);\n";
2800 }
2801
2802 fragmentShaderStr << "}";
2803
2804 const std::string &vertexShaderSource = vertexShaderStr.str();
2805 const std::string &fragmentShaderSource = fragmentShaderStr.str();
2806
2807 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
2808 }
2809
2810 RGBA8 getPixel(GLint texIndex)
2811 {
2812 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
2813 0, 255u};
2814 return pixel;
2815 }
2816
2817 void initTextures(GLint tex2DCount, GLint texCubeCount)
2818 {
2819 GLint totalCount = tex2DCount + texCubeCount;
2820 mTextures.assign(totalCount, 0);
2821 glGenTextures(totalCount, &mTextures[0]);
2822 ASSERT_GL_NO_ERROR();
2823
2824 std::vector<RGBA8> texData(16 * 16);
2825
2826 GLint texIndex = 0;
2827 for (; texIndex < tex2DCount; ++texIndex)
2828 {
2829 texData.assign(texData.size(), getPixel(texIndex));
2830 glActiveTexture(GL_TEXTURE0 + texIndex);
2831 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
2832 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2833 &texData[0]);
2834 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2835 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2836 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2837 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2838 }
2839
2840 ASSERT_GL_NO_ERROR();
2841
2842 for (; texIndex < texCubeCount; ++texIndex)
2843 {
2844 texData.assign(texData.size(), getPixel(texIndex));
2845 glActiveTexture(GL_TEXTURE0 + texIndex);
2846 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
2847 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2848 GL_UNSIGNED_BYTE, &texData[0]);
2849 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2850 GL_UNSIGNED_BYTE, &texData[0]);
2851 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2852 GL_UNSIGNED_BYTE, &texData[0]);
2853 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2854 GL_UNSIGNED_BYTE, &texData[0]);
2855 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2856 GL_UNSIGNED_BYTE, &texData[0]);
2857 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2858 GL_UNSIGNED_BYTE, &texData[0]);
2859 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2860 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2861 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2862 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2863 }
2864
2865 ASSERT_GL_NO_ERROR();
2866 }
2867
2868 void testWithTextures(GLint vertexTextureCount,
2869 const std::string &vertexTexturePrefix,
2870 GLint fragmentTextureCount,
2871 const std::string &fragmentTexturePrefix)
2872 {
2873 // Generate textures
2874 initTextures(vertexTextureCount + fragmentTextureCount, 0);
2875
2876 glUseProgram(mProgram);
2877 RGBA8 expectedSum = {0};
2878 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
2879 {
2880 std::stringstream uniformNameStr;
2881 uniformNameStr << vertexTexturePrefix << texIndex;
2882 const std::string &uniformName = uniformNameStr.str();
2883 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
2884 ASSERT_NE(-1, location);
2885
2886 glUniform1i(location, texIndex);
2887 RGBA8 contribution = getPixel(texIndex);
2888 expectedSum.R += contribution.R;
2889 expectedSum.G += contribution.G;
2890 }
2891
2892 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
2893 {
2894 std::stringstream uniformNameStr;
2895 uniformNameStr << fragmentTexturePrefix << texIndex;
2896 const std::string &uniformName = uniformNameStr.str();
2897 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
2898 ASSERT_NE(-1, location);
2899
2900 glUniform1i(location, texIndex + vertexTextureCount);
2901 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
2902 expectedSum.R += contribution.R;
2903 expectedSum.G += contribution.G;
2904 }
2905
2906 ASSERT_GE(256u, expectedSum.G);
2907
2908 drawQuad(mProgram, "position", 0.5f);
2909 ASSERT_GL_NO_ERROR();
2910 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
2911 }
2912
2913 GLuint mProgram;
2914 std::vector<GLuint> mTextures;
2915 GLint mMaxVertexTextures;
2916 GLint mMaxFragmentTextures;
2917 GLint mMaxCombinedTextures;
2918};
2919
2920// Test rendering with the maximum vertex texture units.
2921TEST_P(TextureLimitsTest, MaxVertexTextures)
2922{
2923 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
2924 ASSERT_NE(0u, mProgram);
2925 ASSERT_GL_NO_ERROR();
2926
2927 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
2928}
2929
2930// Test rendering with the maximum fragment texture units.
2931TEST_P(TextureLimitsTest, MaxFragmentTextures)
2932{
2933 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
2934 ASSERT_NE(0u, mProgram);
2935 ASSERT_GL_NO_ERROR();
2936
2937 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
2938}
2939
2940// Test rendering with maximum combined texture units.
2941TEST_P(TextureLimitsTest, MaxCombinedTextures)
2942{
Luc Ferronaf883622018-06-08 15:57:31 -04002943 // TODO(lucferron): Diagnose and fix
2944 // http://anglebug.com/2654
2945 ANGLE_SKIP_TEST_IF(IsVulkan());
2946
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002947 GLint vertexTextures = mMaxVertexTextures;
2948
2949 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
2950 {
2951 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
2952 }
2953
2954 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
2955 mMaxFragmentTextures, mMaxFragmentTextures);
2956 ASSERT_NE(0u, mProgram);
2957 ASSERT_GL_NO_ERROR();
2958
2959 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
2960}
2961
2962// Negative test for exceeding the number of vertex textures
2963TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
2964{
2965 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
2966 0);
2967 ASSERT_EQ(0u, mProgram);
2968}
2969
2970// Negative test for exceeding the number of fragment textures
2971TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
2972{
2973 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
2974 mMaxFragmentTextures + 1);
2975 ASSERT_EQ(0u, mProgram);
2976}
2977
2978// Test active vertex textures under the limit, but excessive textures specified.
2979TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
2980{
Luc Ferronaf883622018-06-08 15:57:31 -04002981 // TODO(lucferron): Diagnose and fix
2982 // http://anglebug.com/2654
2983 ANGLE_SKIP_TEST_IF(IsVulkan());
2984
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002985 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
2986 ASSERT_NE(0u, mProgram);
2987 ASSERT_GL_NO_ERROR();
2988
2989 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
2990}
2991
2992// Test active fragment textures under the limit, but excessive textures specified.
2993TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
2994{
Luc Ferronaf883622018-06-08 15:57:31 -04002995 // TODO(lucferron): Diagnose and fix
2996 // http://anglebug.com/2654
2997 ANGLE_SKIP_TEST_IF(IsVulkan());
2998
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002999 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3000 mMaxFragmentTextures);
3001 ASSERT_NE(0u, mProgram);
3002 ASSERT_GL_NO_ERROR();
3003
3004 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3005}
3006
3007// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003008// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003009TEST_P(TextureLimitsTest, TextureTypeConflict)
3010{
3011 const std::string &vertexShader =
3012 "attribute vec2 position;\n"
3013 "varying float color;\n"
3014 "uniform sampler2D tex2D;\n"
3015 "uniform samplerCube texCube;\n"
3016 "void main() {\n"
3017 " gl_Position = vec4(position, 0, 1);\n"
3018 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3019 " color = texture2D(tex2D, texCoord).x;\n"
3020 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3021 "}";
3022 const std::string &fragmentShader =
3023 "varying mediump float color;\n"
3024 "void main() {\n"
3025 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3026 "}";
3027
3028 mProgram = CompileProgram(vertexShader, fragmentShader);
3029 ASSERT_NE(0u, mProgram);
3030
3031 initTextures(1, 0);
3032
3033 glUseProgram(mProgram);
3034 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3035 ASSERT_NE(-1, tex2DLocation);
3036 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3037 ASSERT_NE(-1, texCubeLocation);
3038
3039 glUniform1i(tex2DLocation, 0);
3040 glUniform1i(texCubeLocation, 0);
3041 ASSERT_GL_NO_ERROR();
3042
3043 drawQuad(mProgram, "position", 0.5f);
3044 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3045}
3046
Vincent Lang25ab4512016-05-13 18:13:59 +02003047class Texture2DNorm16TestES3 : public Texture2DTestES3
3048{
3049 protected:
3050 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3051
3052 void SetUp() override
3053 {
3054 Texture2DTestES3::SetUp();
3055
3056 glActiveTexture(GL_TEXTURE0);
3057 glGenTextures(3, mTextures);
3058 glGenFramebuffers(1, &mFBO);
3059 glGenRenderbuffers(1, &mRenderbuffer);
3060
3061 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3062 {
3063 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3064 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3065 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3066 }
3067
3068 glBindTexture(GL_TEXTURE_2D, 0);
3069
3070 ASSERT_GL_NO_ERROR();
3071 }
3072
3073 void TearDown() override
3074 {
3075 glDeleteTextures(3, mTextures);
3076 glDeleteFramebuffers(1, &mFBO);
3077 glDeleteRenderbuffers(1, &mRenderbuffer);
3078
3079 Texture2DTestES3::TearDown();
3080 }
3081
3082 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3083 {
Geoff Langf607c602016-09-21 11:46:48 -04003084 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3085 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003086
3087 setUpProgram();
3088
3089 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3090 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3091 0);
3092
3093 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3094 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3095
3096 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003097 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003098
3099 EXPECT_GL_NO_ERROR();
3100
3101 drawQuad(mProgram, "position", 0.5f);
3102
Geoff Langf607c602016-09-21 11:46:48 -04003103 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003104
Geoff Langf607c602016-09-21 11:46:48 -04003105 EXPECT_PIXEL_COLOR_EQ(
3106 0, 0, SliceFormatColor(
3107 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003108
3109 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3110
3111 ASSERT_GL_NO_ERROR();
3112 }
3113
3114 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3115 {
3116 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003117 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003118
3119 setUpProgram();
3120
3121 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3122 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3123
3124 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3125 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3126 0);
3127
3128 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
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 = static_cast<GLubyte>(pixelValue >> 8);
3136 EXPECT_PIXEL_COLOR_EQ(
3137 0, 0, SliceFormatColor(
3138 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003139
3140 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3141 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3142 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3143 mRenderbuffer);
3144 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3145 EXPECT_GL_NO_ERROR();
3146
3147 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3148 glClear(GL_COLOR_BUFFER_BIT);
3149
3150 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3151
Geoff Langf607c602016-09-21 11:46:48 -04003152 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003153
3154 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3155
3156 ASSERT_GL_NO_ERROR();
3157 }
3158
3159 GLuint mTextures[3];
3160 GLuint mFBO;
3161 GLuint mRenderbuffer;
3162};
3163
3164// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3165TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3166{
Yunchao He9550c602018-02-13 14:47:05 +08003167 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02003168
3169 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3170 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3171 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3172 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3173 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3174 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3175 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3176 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3177
3178 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3179 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3180 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3181}
3182
Olli Etuaho95faa232016-06-07 14:01:53 -07003183// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3184// GLES 3.0.4 section 3.8.3.
3185TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3186{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08003187 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
3188
Yuly Novikov3c754192016-06-27 19:36:41 -04003189 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1429 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08003190 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07003191
3192 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3193 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3194 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3195 ASSERT_GL_NO_ERROR();
3196
3197 // SKIP_IMAGES should not have an effect on uploading 2D textures
3198 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3199 ASSERT_GL_NO_ERROR();
3200
3201 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3202
3203 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3204 pixelsGreen.data());
3205 ASSERT_GL_NO_ERROR();
3206
3207 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3208 pixelsGreen.data());
3209 ASSERT_GL_NO_ERROR();
3210
3211 glUseProgram(mProgram);
3212 drawQuad(mProgram, "position", 0.5f);
3213 ASSERT_GL_NO_ERROR();
3214
3215 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3216}
3217
Olli Etuaho989cac32016-06-08 16:18:49 -07003218// Test that skip defined in unpack parameters is taken into account when determining whether
3219// unpacking source extends outside unpack buffer bounds.
3220TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3221{
3222 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3223 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3224 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3225 ASSERT_GL_NO_ERROR();
3226
3227 GLBuffer buf;
3228 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3229 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3230 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3231 GL_DYNAMIC_COPY);
3232 ASSERT_GL_NO_ERROR();
3233
3234 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3235 ASSERT_GL_NO_ERROR();
3236
3237 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3238 ASSERT_GL_NO_ERROR();
3239
3240 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3241 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3242
3243 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3244 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3245 ASSERT_GL_NO_ERROR();
3246
3247 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3248 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3249}
3250
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003251// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3252TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3253{
Yunchao He9550c602018-02-13 14:47:05 +08003254 ANGLE_SKIP_TEST_IF(IsD3D11());
3255
3256 // Incorrect rendering results seen on OSX AMD.
3257 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003258
3259 const GLuint width = 8u;
3260 const GLuint height = 8u;
3261 const GLuint unpackRowLength = 5u;
3262 const GLuint unpackSkipPixels = 1u;
3263
3264 setWindowWidth(width);
3265 setWindowHeight(height);
3266
3267 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3268 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3269 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3270 ASSERT_GL_NO_ERROR();
3271
3272 GLBuffer buf;
3273 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3274 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3275 GLColor::green);
3276
3277 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3278 {
3279 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3280 }
3281
3282 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3283 GL_DYNAMIC_COPY);
3284 ASSERT_GL_NO_ERROR();
3285
3286 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3287 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3288 ASSERT_GL_NO_ERROR();
3289
3290 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3291 ASSERT_GL_NO_ERROR();
3292
3293 glUseProgram(mProgram);
3294 drawQuad(mProgram, "position", 0.5f);
3295 ASSERT_GL_NO_ERROR();
3296
3297 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3298 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3299 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3300 actual.data());
3301 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3302 EXPECT_EQ(expected, actual);
3303}
3304
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003305template <typename T>
3306T UNorm(double value)
3307{
3308 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3309}
3310
3311// Test rendering a depth texture with mipmaps.
3312TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3313{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003314 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3315 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
3316 // http://anglebugs.com/1706
Yunchao He9550c602018-02-13 14:47:05 +08003317 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows());
Corentin Walleze731d8a2016-09-07 10:56:25 -04003318
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003319 const int size = getWindowWidth();
3320
3321 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003322 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003323
3324 glActiveTexture(GL_TEXTURE0);
3325 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3326 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3327 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3328 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3329 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3330 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3331 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3332 ASSERT_GL_NO_ERROR();
3333
3334 glUseProgram(mProgram);
3335 glUniform1i(mTexture2DUniformLocation, 0);
3336
3337 std::vector<unsigned char> expected;
3338
3339 for (int level = 0; level < levels; ++level)
3340 {
3341 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3342 expected.push_back(UNorm<unsigned char>(value));
3343
3344 int levelDim = dim(level);
3345
3346 ASSERT_GT(levelDim, 0);
3347
3348 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3349 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3350 GL_UNSIGNED_INT, initData.data());
3351 }
3352 ASSERT_GL_NO_ERROR();
3353
3354 for (int level = 0; level < levels; ++level)
3355 {
3356 glViewport(0, 0, dim(level), dim(level));
3357 drawQuad(mProgram, "position", 0.5f);
3358 GLColor actual = ReadColor(0, 0);
3359 EXPECT_NEAR(expected[level], actual.R, 10u);
3360 }
3361
3362 ASSERT_GL_NO_ERROR();
3363}
3364
Jamie Madill7ffdda92016-09-08 13:26:51 -04003365// Tests unpacking into the unsized GL_ALPHA format.
3366TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3367{
Jamie Madill7ffdda92016-09-08 13:26:51 -04003368 // Initialize the texure.
3369 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3370 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3371 GL_UNSIGNED_BYTE, nullptr);
3372 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3373 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3374
3375 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3376
3377 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04003378 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04003379 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3380 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3381 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
3382 GL_STATIC_DRAW);
3383
3384 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
3385 GL_UNSIGNED_BYTE, nullptr);
3386
3387 // Clear to a weird color to make sure we're drawing something.
3388 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
3389 glClear(GL_COLOR_BUFFER_BIT);
3390
3391 // Draw with the alpha texture and verify.
3392 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04003393
3394 ASSERT_GL_NO_ERROR();
3395 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
3396}
3397
Jamie Madill2e600342016-09-19 13:56:40 -04003398// Ensure stale unpack data doesn't propagate in D3D11.
3399TEST_P(Texture2DTestES3, StaleUnpackData)
3400{
3401 // Init unpack buffer.
3402 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
3403 std::vector<GLColor> pixels(pixelCount, GLColor::red);
3404
3405 GLBuffer unpackBuffer;
3406 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3407 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3408 GLsizei bufferSize = pixelCount * sizeof(GLColor);
3409 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
3410
3411 // Create from unpack buffer.
3412 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3413 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
3414 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3415 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3416 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3417
3418 drawQuad(mProgram, "position", 0.5f);
3419
3420 ASSERT_GL_NO_ERROR();
3421 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3422
3423 // Fill unpack with green, recreating buffer.
3424 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
3425 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
3426 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
3427
3428 // Reinit texture with green.
3429 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
3430 GL_UNSIGNED_BYTE, nullptr);
3431
3432 drawQuad(mProgram, "position", 0.5f);
3433
3434 ASSERT_GL_NO_ERROR();
3435 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3436}
3437
Geoff Langfb7685f2017-11-13 11:44:11 -05003438// Ensure that texture parameters passed as floats that are converted to ints are rounded before
3439// validating they are less than 0.
3440TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
3441{
3442 GLTexture texture;
3443 glBindTexture(GL_TEXTURE_2D, texture);
3444
3445 // Use a negative number that will round to zero when converted to an integer
3446 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
3447 // "Validation of values performed by state-setting commands is performed after conversion,
3448 // unless specified otherwise for a specific command."
3449 GLfloat param = -7.30157126e-07f;
3450 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
3451 EXPECT_GL_NO_ERROR();
3452
3453 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
3454 EXPECT_GL_NO_ERROR();
3455}
3456
Jamie Madillf097e232016-11-05 00:44:15 -04003457// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
3458// being properly checked, and the texture storage of the previous texture format was persisting.
3459// This would result in an ASSERT in debug and incorrect rendering in release.
3460// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
3461TEST_P(Texture3DTestES3, FormatRedefinitionBug)
3462{
3463 GLTexture tex;
3464 glBindTexture(GL_TEXTURE_3D, tex.get());
3465 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3466
3467 GLFramebuffer framebuffer;
3468 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3469 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
3470
3471 glCheckFramebufferStatus(GL_FRAMEBUFFER);
3472
3473 std::vector<uint8_t> pixelData(100, 0);
3474
3475 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
3476 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
3477 pixelData.data());
3478
3479 ASSERT_GL_NO_ERROR();
3480}
3481
Corentin Wallezd2627992017-04-28 17:17:03 -04003482// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
3483TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
3484{
3485 // 2D tests
3486 {
3487 GLTexture tex;
3488 glBindTexture(GL_TEXTURE_2D, tex.get());
3489
3490 GLBuffer pbo;
3491 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3492
3493 // Test OOB
3494 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
3495 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3496 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3497
3498 // Test OOB
3499 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
3500 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3501 ASSERT_GL_NO_ERROR();
3502 }
3503
3504 // 3D tests
3505 {
3506 GLTexture tex;
3507 glBindTexture(GL_TEXTURE_3D, tex.get());
3508
3509 GLBuffer pbo;
3510 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3511
3512 // Test OOB
3513 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
3514 GL_STATIC_DRAW);
3515 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3516 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3517
3518 // Test OOB
3519 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
3520 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3521 ASSERT_GL_NO_ERROR();
3522 }
3523}
3524
Jamie Madill3ed60422017-09-07 11:32:52 -04003525// Tests behaviour with a single texture and multiple sampler objects.
3526TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
3527{
3528 GLint maxTextureUnits = 0;
3529 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
3530 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
3531
3532 constexpr int kSize = 16;
3533
3534 // Make a single-level texture, fill it with red.
3535 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
3536 GLTexture tex;
3537 glBindTexture(GL_TEXTURE_2D, tex);
3538 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3539 redColors.data());
3540 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3541 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3542
3543 // Simple sanity check.
3544 draw2DTexturedQuad(0.5f, 1.0f, true);
3545 ASSERT_GL_NO_ERROR();
3546 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3547
3548 // Bind texture to unit 1 with a sampler object making it incomplete.
3549 GLSampler sampler;
3550 glBindSampler(0, sampler);
3551 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3552 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3553
3554 // Make a mipmap texture, fill it with blue.
3555 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
3556 GLTexture mipmapTex;
3557 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3558 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3559 blueColors.data());
3560 glGenerateMipmap(GL_TEXTURE_2D);
3561
3562 // Draw with the sampler, expect blue.
3563 draw2DTexturedQuad(0.5f, 1.0f, true);
3564 ASSERT_GL_NO_ERROR();
3565 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
3566
3567 // Simple multitexturing program.
3568 const std::string vs =
3569 "#version 300 es\n"
3570 "in vec2 position;\n"
3571 "out vec2 texCoord;\n"
3572 "void main()\n"
3573 "{\n"
3574 " gl_Position = vec4(position, 0, 1);\n"
3575 " texCoord = position * 0.5 + vec2(0.5);\n"
3576 "}";
3577 const std::string fs =
3578 "#version 300 es\n"
3579 "precision mediump float;\n"
3580 "in vec2 texCoord;\n"
3581 "uniform sampler2D tex1;\n"
3582 "uniform sampler2D tex2;\n"
3583 "uniform sampler2D tex3;\n"
3584 "uniform sampler2D tex4;\n"
3585 "out vec4 color;\n"
3586 "void main()\n"
3587 "{\n"
3588 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
3589 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
3590 "}";
3591
3592 ANGLE_GL_PROGRAM(program, vs, fs);
3593
3594 std::array<GLint, 4> texLocations = {
3595 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
3596 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
3597 for (GLint location : texLocations)
3598 {
3599 ASSERT_NE(-1, location);
3600 }
3601
3602 // Init the uniform data.
3603 glUseProgram(program);
3604 for (GLint location = 0; location < 4; ++location)
3605 {
3606 glUniform1i(texLocations[location], location);
3607 }
3608
3609 // Initialize four samplers
3610 GLSampler samplers[4];
3611
3612 // 0: non-mipped.
3613 glBindSampler(0, samplers[0]);
3614 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3615 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3616
3617 // 1: mipped.
3618 glBindSampler(1, samplers[1]);
3619 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3620 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3621
3622 // 2: non-mipped.
3623 glBindSampler(2, samplers[2]);
3624 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3625 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3626
3627 // 3: mipped.
3628 glBindSampler(3, samplers[3]);
3629 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3630 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3631
3632 // Bind two blue mipped textures and two single layer textures, should all draw.
3633 glActiveTexture(GL_TEXTURE0);
3634 glBindTexture(GL_TEXTURE_2D, tex);
3635
3636 glActiveTexture(GL_TEXTURE1);
3637 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3638
3639 glActiveTexture(GL_TEXTURE2);
3640 glBindTexture(GL_TEXTURE_2D, tex);
3641
3642 glActiveTexture(GL_TEXTURE3);
3643 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3644
3645 ASSERT_GL_NO_ERROR();
3646
3647 drawQuad(program, "position", 0.5f);
3648 ASSERT_GL_NO_ERROR();
3649 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
3650
3651 // Bind four single layer textures, two should be incomplete.
3652 glActiveTexture(GL_TEXTURE1);
3653 glBindTexture(GL_TEXTURE_2D, tex);
3654
3655 glActiveTexture(GL_TEXTURE3);
3656 glBindTexture(GL_TEXTURE_2D, tex);
3657
3658 drawQuad(program, "position", 0.5f);
3659 ASSERT_GL_NO_ERROR();
3660 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
3661}
3662
Martin Radev7e2c0d32017-09-15 14:25:42 +03003663// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
3664// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
3665// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
3666// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
3667// samples the cubemap using a direction vector (1,1,1).
3668TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
3669{
Yunchao He2f23f352018-02-11 22:11:37 +08003670 // Check http://anglebug.com/2155.
3671 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
3672
Martin Radev7e2c0d32017-09-15 14:25:42 +03003673 const std::string vs =
3674 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003675 precision mediump float;
3676 in vec3 pos;
3677 void main() {
3678 gl_Position = vec4(pos, 1.0);
3679 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003680
3681 const std::string fs =
3682 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003683 precision mediump float;
3684 out vec4 color;
3685 uniform samplerCube uTex;
3686 void main(){
3687 color = texture(uTex, vec3(1.0));
3688 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003689 ANGLE_GL_PROGRAM(program, vs, fs);
3690 glUseProgram(program);
3691
3692 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
3693 glActiveTexture(GL_TEXTURE0);
3694
3695 GLTexture cubeTex;
3696 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
3697
3698 const int kFaceWidth = 1;
3699 const int kFaceHeight = 1;
3700 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
3701 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3702 GL_UNSIGNED_BYTE, texData.data());
3703 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3704 GL_UNSIGNED_BYTE, texData.data());
3705 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3706 GL_UNSIGNED_BYTE, texData.data());
3707 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3708 GL_UNSIGNED_BYTE, texData.data());
3709 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3710 GL_UNSIGNED_BYTE, texData.data());
3711 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3712 GL_UNSIGNED_BYTE, texData.data());
3713 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3714 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3715 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
3716 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
3717 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
3718 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
3719
3720 drawQuad(program, "pos", 0.5f, 1.0f, true);
3721 ASSERT_GL_NO_ERROR();
3722
3723 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
3724}
3725
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08003726// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
3727TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
3728{
3729 GLuint texture = create2DTexture();
3730
3731 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
3732 EXPECT_GL_ERROR(GL_INVALID_VALUE);
3733
3734 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
3735 EXPECT_GL_ERROR(GL_INVALID_VALUE);
3736
3737 glDeleteTextures(1, &texture);
3738 EXPECT_GL_NO_ERROR();
3739}
3740
Olli Etuaho023371b2018-04-24 17:43:32 +03003741// Test setting base level after calling generateMipmap on a LUMA texture.
3742// Covers http://anglebug.com/2498
3743TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA)
3744{
3745 glActiveTexture(GL_TEXTURE0);
3746 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3747
3748 constexpr const GLsizei kWidth = 8;
3749 constexpr const GLsizei kHeight = 8;
3750 std::array<GLubyte, kWidth * kHeight * 2> whiteData;
3751 whiteData.fill(255u);
3752
3753 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA,
3754 GL_UNSIGNED_BYTE, whiteData.data());
3755 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
3756 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3757 glGenerateMipmap(GL_TEXTURE_2D);
3758 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
3759 EXPECT_GL_NO_ERROR();
3760
3761 drawQuad(mProgram, "position", 0.5f);
3762 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
3763}
3764
Jamie Madillfa05f602015-05-07 13:47:11 -04003765// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -05003766ANGLE_INSTANTIATE_TEST(Texture2DTest,
3767 ES2_D3D9(),
3768 ES2_D3D11(),
3769 ES2_D3D11_FL9_3(),
3770 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05003771 ES2_OPENGLES(),
3772 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003773ANGLE_INSTANTIATE_TEST(TextureCubeTest,
3774 ES2_D3D9(),
3775 ES2_D3D11(),
Geoff Langf7480ad2017-10-24 11:46:02 -04003776 ES2_D3D11_FL10_0(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003777 ES2_D3D11_FL9_3(),
3778 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04003779 ES2_OPENGLES(),
3780 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003781ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
3782 ES2_D3D9(),
3783 ES2_D3D11(),
3784 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003785 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04003786 ES2_OPENGLES(),
3787 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003788ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
3789 ES2_D3D9(),
3790 ES2_D3D11(),
3791 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003792 ES2_OPENGL(),
3793 ES2_OPENGLES());
3794ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
3795 ES2_D3D9(),
3796 ES2_D3D11(),
3797 ES2_D3D11_FL9_3(),
3798 ES2_OPENGL(),
3799 ES2_OPENGLES());
3800ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
3801 ES2_D3D9(),
3802 ES2_D3D11(),
3803 ES2_D3D11_FL9_3(),
3804 ES2_OPENGL(),
3805 ES2_OPENGLES());
3806ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02003807ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003808ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3809ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
3810 ES3_D3D11(),
3811 ES3_OPENGL(),
3812 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003813ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
3814 ES3_D3D11(),
3815 ES3_OPENGL(),
3816 ES3_OPENGLES());
3817ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3818ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02003819ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02003820ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
3821 ES2_D3D11(),
3822 ES2_D3D11_FL9_3(),
3823 ES2_D3D9(),
3824 ES2_OPENGL(),
3825 ES2_OPENGLES());
3826ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
3827 ES2_D3D11(),
3828 ES2_D3D11_FL9_3(),
3829 ES2_D3D9(),
3830 ES2_OPENGL(),
3831 ES2_OPENGLES());
3832ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
3833 ES2_D3D11(),
3834 ES2_D3D11_FL9_3(),
3835 ES2_D3D9(),
3836 ES2_OPENGL(),
3837 ES2_OPENGLES());
3838ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
3839 ES2_D3D11(),
3840 ES2_D3D11_FL9_3(),
3841 ES2_D3D9(),
3842 ES2_OPENGL(),
3843 ES2_OPENGLES());
3844ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
3845 ES2_D3D11(),
3846 ES2_D3D11_FL9_3(),
3847 ES2_D3D9(),
3848 ES2_OPENGL(),
3849 ES2_OPENGLES());
Luc Ferronaf883622018-06-08 15:57:31 -04003850ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN());
Vincent Lang25ab4512016-05-13 18:13:59 +02003851ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03003852ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04003853
Jamie Madill7ffdda92016-09-08 13:26:51 -04003854} // anonymous namespace