blob: 3aad142cda1a7448a47ea66c981a541ccb70107e [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
Jamie Madill35cd7332018-12-02 12:03:33 -050050 virtual const char *getVertexShaderSource()
Jamie Madillf67115c2014-04-22 13:14:05 -040051 {
Jamie Madill35cd7332018-12-02 12:03:33 -050052 return R"(precision highp float;
53attribute vec4 position;
54varying vec2 texcoord;
Geoff Langc41e42d2014-04-28 10:58:16 -040055
Jamie Madill35cd7332018-12-02 12:03:33 -050056void main()
57{
58 gl_Position = vec4(position.xy, 0.0, 1.0);
59 texcoord = (position.xy * 0.5) + 0.5;
60})";
Olli Etuaho4a8329f2016-01-11 17:12:57 +020061 }
Geoff Langc41e42d2014-04-28 10:58:16 -040062
Jamie Madill35cd7332018-12-02 12:03:33 -050063 virtual const char *getFragmentShaderSource() = 0;
Olli Etuaho4a8329f2016-01-11 17:12:57 +020064
Olli Etuahoa1c917f2016-04-06 13:50:03 +030065 virtual void setUpProgram()
Olli Etuaho4a8329f2016-01-11 17:12:57 +020066 {
Jamie Madill35cd7332018-12-02 12:03:33 -050067 const char *vertexShaderSource = getVertexShaderSource();
68 const char *fragmentShaderSource = getFragmentShaderSource();
Olli Etuaho4a8329f2016-01-11 17:12:57 +020069
70 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
71 ASSERT_NE(0u, mProgram);
72 ASSERT_GL_NO_ERROR();
Olli Etuahoa1c917f2016-04-06 13:50:03 +030073 }
74
75 void SetUp() override
76 {
77 ANGLETest::SetUp();
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020078
79 setUpFramebuffer();
Olli Etuaho4a8329f2016-01-11 17:12:57 +020080 }
81
82 void TearDown() override
83 {
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020084 glBindFramebuffer(GL_FRAMEBUFFER, 0);
85 glDeleteFramebuffers(1, &mFramebuffer);
86 glDeleteTextures(1, &mFramebufferColorTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +020087 glDeleteProgram(mProgram);
88 ANGLETest::TearDown();
89 }
90
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020091 void setUpFramebuffer()
92 {
93 // We use an FBO to work around an issue where the default framebuffer applies SRGB
94 // conversion (particularly known to happen incorrectly on Intel GL drivers). It's not
95 // clear whether this issue can even be fixed on all backends. For example GLES 3.0.4 spec
96 // section 4.4 says that the format of the default framebuffer is entirely up to the window
97 // system, so it might be SRGB, and GLES 3.0 doesn't have a "FRAMEBUFFER_SRGB" to turn off
98 // SRGB conversion like desktop GL does.
99 // TODO(oetuaho): Get rid of this if the underlying issue is fixed.
100 glGenFramebuffers(1, &mFramebuffer);
101 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
102
103 glGenTextures(1, &mFramebufferColorTexture);
104 glBindTexture(GL_TEXTURE_2D, mFramebufferColorTexture);
105 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
106 GL_UNSIGNED_BYTE, nullptr);
107 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
108 mFramebufferColorTexture, 0);
109 ASSERT_GL_NO_ERROR();
110 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
111 glBindTexture(GL_TEXTURE_2D, 0);
112 }
113
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200114 // Returns the created texture ID.
115 GLuint create2DTexture()
116 {
117 GLuint texture2D;
118 glGenTextures(1, &texture2D);
119 glBindTexture(GL_TEXTURE_2D, texture2D);
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800120 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200121 EXPECT_GL_NO_ERROR();
122 return texture2D;
123 }
124
125 GLuint mProgram;
Olli Etuaho51f1c0f2016-01-13 16:16:24 +0200126 GLuint mFramebuffer;
127
128 private:
129 GLuint mFramebufferColorTexture;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200130};
131
132class Texture2DTest : public TexCoordDrawTest
133{
134 protected:
135 Texture2DTest() : TexCoordDrawTest(), mTexture2D(0), mTexture2DUniformLocation(-1) {}
136
Jamie Madill35cd7332018-12-02 12:03:33 -0500137 const char *getFragmentShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200138 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500139 return R"(precision highp float;
140uniform sampler2D tex;
141varying vec2 texcoord;
Geoff Langc41e42d2014-04-28 10:58:16 -0400142
Jamie Madill35cd7332018-12-02 12:03:33 -0500143void main()
144{
145 gl_FragColor = texture2D(tex, texcoord);
146})";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200147 }
Geoff Langc41e42d2014-04-28 10:58:16 -0400148
Olli Etuaho96963162016-03-21 11:54:33 +0200149 virtual const char *getTextureUniformName() { return "tex"; }
150
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300151 void setUpProgram() override
152 {
153 TexCoordDrawTest::setUpProgram();
154 mTexture2DUniformLocation = glGetUniformLocation(mProgram, getTextureUniformName());
155 ASSERT_NE(-1, mTexture2DUniformLocation);
156 }
157
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200158 void SetUp() override
159 {
160 TexCoordDrawTest::SetUp();
161 mTexture2D = create2DTexture();
Jamie Madilld4cfa572014-07-08 10:00:32 -0400162
Jamie Madill9aca0592014-10-06 16:26:59 -0400163 ASSERT_GL_NO_ERROR();
Jamie Madillf67115c2014-04-22 13:14:05 -0400164 }
165
Jamie Madillfa05f602015-05-07 13:47:11 -0400166 void TearDown() override
Jamie Madillf67115c2014-04-22 13:14:05 -0400167 {
Jamie Madilld4cfa572014-07-08 10:00:32 -0400168 glDeleteTextures(1, &mTexture2D);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200169 TexCoordDrawTest::TearDown();
Jamie Madillf67115c2014-04-22 13:14:05 -0400170 }
171
Jamie Madillbc393df2015-01-29 13:46:07 -0500172 // Tests CopyTexSubImage with floating point textures of various formats.
173 void testFloatCopySubImage(int sourceImageChannels, int destImageChannels)
174 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300175 setUpProgram();
176
Martin Radev1be913c2016-07-11 17:59:16 +0300177 if (getClientMajorVersion() < 3)
Geoff Langfbfa47c2015-03-31 11:26:00 -0400178 {
Yunchao He9550c602018-02-13 14:47:05 +0800179 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_storage") ||
180 !extensionEnabled("GL_OES_texture_float"));
Geoff Langc4e93662017-05-01 10:45:59 -0400181
Yunchao He9550c602018-02-13 14:47:05 +0800182 ANGLE_SKIP_TEST_IF((sourceImageChannels < 3 || destImageChannels < 3) &&
183 !extensionEnabled("GL_EXT_texture_rg"));
Geoff Langfbfa47c2015-03-31 11:26:00 -0400184
Yunchao He9550c602018-02-13 14:47:05 +0800185 ANGLE_SKIP_TEST_IF(destImageChannels == 3 &&
186 !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400187
Yunchao He9550c602018-02-13 14:47:05 +0800188 ANGLE_SKIP_TEST_IF(destImageChannels == 4 &&
189 !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400190
Yunchao He9550c602018-02-13 14:47:05 +0800191 ANGLE_SKIP_TEST_IF(destImageChannels <= 2);
Geoff Lang677bb6f2017-04-05 12:40:40 -0400192 }
193 else
194 {
Yunchao He9550c602018-02-13 14:47:05 +0800195 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_color_buffer_float"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400196
Yunchao He9550c602018-02-13 14:47:05 +0800197 ANGLE_SKIP_TEST_IF(destImageChannels == 3 &&
198 !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"));
Geoff Langfbfa47c2015-03-31 11:26:00 -0400199 }
200
Jamie Madill50cf2be2018-06-15 09:46:57 -0400201 // clang-format off
Jamie Madillbc393df2015-01-29 13:46:07 -0500202 GLfloat sourceImageData[4][16] =
203 {
204 { // R
205 1.0f,
206 0.0f,
207 0.0f,
208 1.0f
209 },
210 { // RG
211 1.0f, 0.0f,
212 0.0f, 1.0f,
213 0.0f, 0.0f,
214 1.0f, 1.0f
215 },
216 { // RGB
217 1.0f, 0.0f, 0.0f,
218 0.0f, 1.0f, 0.0f,
219 0.0f, 0.0f, 1.0f,
220 1.0f, 1.0f, 0.0f
221 },
222 { // RGBA
223 1.0f, 0.0f, 0.0f, 1.0f,
224 0.0f, 1.0f, 0.0f, 1.0f,
225 0.0f, 0.0f, 1.0f, 1.0f,
226 1.0f, 1.0f, 0.0f, 1.0f
227 },
228 };
Jamie Madill50cf2be2018-06-15 09:46:57 -0400229 // clang-format on
Jamie Madillbc393df2015-01-29 13:46:07 -0500230
Jamie Madill50cf2be2018-06-15 09:46:57 -0400231 GLenum imageFormats[] = {
Jamie Madillb980c562018-11-27 11:34:27 -0500232 GL_R32F,
233 GL_RG32F,
234 GL_RGB32F,
235 GL_RGBA32F,
Jamie Madillbc393df2015-01-29 13:46:07 -0500236 };
237
Jamie Madill50cf2be2018-06-15 09:46:57 -0400238 GLenum sourceUnsizedFormats[] = {
Jamie Madillb980c562018-11-27 11:34:27 -0500239 GL_RED,
240 GL_RG,
241 GL_RGB,
242 GL_RGBA,
Jamie Madillbc393df2015-01-29 13:46:07 -0500243 };
244
245 GLuint textures[2];
246
247 glGenTextures(2, textures);
248
Jamie Madill50cf2be2018-06-15 09:46:57 -0400249 GLfloat *imageData = sourceImageData[sourceImageChannels - 1];
250 GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1];
Jamie Madillbc393df2015-01-29 13:46:07 -0500251 GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1];
Jamie Madill50cf2be2018-06-15 09:46:57 -0400252 GLenum destImageFormat = imageFormats[destImageChannels - 1];
Jamie Madillbc393df2015-01-29 13:46:07 -0500253
254 glBindTexture(GL_TEXTURE_2D, textures[0]);
Geoff Langc4e93662017-05-01 10:45:59 -0400255 if (getClientMajorVersion() >= 3)
256 {
257 glTexStorage2D(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
258 }
259 else
260 {
261 glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
262 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500263 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
264 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
265 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData);
266
hendrikwb27f79a2015-03-04 11:26:46 -0800267 if (sourceImageChannels < 3 && !extensionEnabled("GL_EXT_texture_rg"))
Jamie Madillbc393df2015-01-29 13:46:07 -0500268 {
269 // This is not supported
270 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
271 }
272 else
273 {
274 ASSERT_GL_NO_ERROR();
275 }
276
277 GLuint fbo;
278 glGenFramebuffers(1, &fbo);
279 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
280 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
281
282 glBindTexture(GL_TEXTURE_2D, textures[1]);
Geoff Langc4e93662017-05-01 10:45:59 -0400283 if (getClientMajorVersion() >= 3)
284 {
285 glTexStorage2D(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
286 }
287 else
288 {
289 glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
290 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500291 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
292 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
293
294 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
295 ASSERT_GL_NO_ERROR();
296
297 glBindFramebuffer(GL_FRAMEBUFFER, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200298 drawQuad(mProgram, "position", 0.5f);
Jamie Madillbc393df2015-01-29 13:46:07 -0500299
300 int testImageChannels = std::min(sourceImageChannels, destImageChannels);
301
Olli Etuahoa314b612016-03-10 16:43:00 +0200302 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Jamie Madillbc393df2015-01-29 13:46:07 -0500303 if (testImageChannels > 1)
304 {
305 EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255);
306 EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255);
307 if (testImageChannels > 2)
308 {
309 EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255);
310 }
311 }
312
313 glDeleteFramebuffers(1, &fbo);
314 glDeleteTextures(2, textures);
315
316 ASSERT_GL_NO_ERROR();
317 }
318
Jamie Madilld4cfa572014-07-08 10:00:32 -0400319 GLuint mTexture2D;
Jamie Madilld4cfa572014-07-08 10:00:32 -0400320 GLint mTexture2DUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400321};
322
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200323class Texture2DTestES3 : public Texture2DTest
324{
325 protected:
326 Texture2DTestES3() : Texture2DTest() {}
327
Jamie Madill35cd7332018-12-02 12:03:33 -0500328 const char *getVertexShaderSource() override
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200329 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500330 return "#version 300 es\n"
331 "out vec2 texcoord;\n"
332 "in vec4 position;\n"
333 "void main()\n"
334 "{\n"
335 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
336 " texcoord = (position.xy * 0.5) + 0.5;\n"
337 "}\n";
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200338 }
339
Jamie Madill35cd7332018-12-02 12:03:33 -0500340 const char *getFragmentShaderSource() override
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200341 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500342 return "#version 300 es\n"
343 "precision highp float;\n"
344 "uniform highp sampler2D tex;\n"
345 "in vec2 texcoord;\n"
346 "out vec4 fragColor;\n"
347 "void main()\n"
348 "{\n"
349 " fragColor = texture(tex, texcoord);\n"
350 "}\n";
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200351 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300352
353 void SetUp() override
354 {
355 Texture2DTest::SetUp();
356 setUpProgram();
357 }
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200358};
359
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200360class Texture2DIntegerAlpha1TestES3 : public Texture2DTest
361{
362 protected:
363 Texture2DIntegerAlpha1TestES3() : Texture2DTest() {}
364
Jamie Madill35cd7332018-12-02 12:03:33 -0500365 const char *getVertexShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200366 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500367 return "#version 300 es\n"
368 "out vec2 texcoord;\n"
369 "in vec4 position;\n"
370 "void main()\n"
371 "{\n"
372 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
373 " texcoord = (position.xy * 0.5) + 0.5;\n"
374 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200375 }
376
Jamie Madill35cd7332018-12-02 12:03:33 -0500377 const char *getFragmentShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200378 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500379 return "#version 300 es\n"
380 "precision highp float;\n"
381 "uniform highp isampler2D tex;\n"
382 "in vec2 texcoord;\n"
383 "out vec4 fragColor;\n"
384 "void main()\n"
385 "{\n"
386 " vec4 green = vec4(0, 1, 0, 1);\n"
387 " vec4 black = vec4(0, 0, 0, 0);\n"
388 " fragColor = (texture(tex, texcoord).a == 1) ? green : black;\n"
389 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200390 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300391
392 void SetUp() override
393 {
394 Texture2DTest::SetUp();
395 setUpProgram();
396 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200397};
398
399class Texture2DUnsignedIntegerAlpha1TestES3 : public Texture2DTest
400{
401 protected:
402 Texture2DUnsignedIntegerAlpha1TestES3() : Texture2DTest() {}
403
Jamie Madill35cd7332018-12-02 12:03:33 -0500404 const char *getVertexShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200405 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500406 return "#version 300 es\n"
407 "out vec2 texcoord;\n"
408 "in vec4 position;\n"
409 "void main()\n"
410 "{\n"
411 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
412 " texcoord = (position.xy * 0.5) + 0.5;\n"
413 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200414 }
415
Jamie Madill35cd7332018-12-02 12:03:33 -0500416 const char *getFragmentShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200417 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500418 return "#version 300 es\n"
419 "precision highp float;\n"
420 "uniform highp usampler2D tex;\n"
421 "in vec2 texcoord;\n"
422 "out vec4 fragColor;\n"
423 "void main()\n"
424 "{\n"
425 " vec4 green = vec4(0, 1, 0, 1);\n"
426 " vec4 black = vec4(0, 0, 0, 0);\n"
427 " fragColor = (texture(tex, texcoord).a == 1u) ? green : black;\n"
428 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200429 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300430
431 void SetUp() override
432 {
433 Texture2DTest::SetUp();
434 setUpProgram();
435 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200436};
437
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200438class Texture2DTestWithDrawScale : public Texture2DTest
Jamie Madill2453dbc2015-07-14 11:35:42 -0400439{
440 protected:
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200441 Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {}
442
Jamie Madill35cd7332018-12-02 12:03:33 -0500443 const char *getVertexShaderSource() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400444 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300445 return
446 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200447 attribute vec4 position;
448 varying vec2 texcoord;
449
450 uniform vec2 drawScale;
451
452 void main()
453 {
454 gl_Position = vec4(position.xy * drawScale, 0.0, 1.0);
455 texcoord = (position.xy * 0.5) + 0.5;
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300456 })";
Jamie Madill2453dbc2015-07-14 11:35:42 -0400457 }
458
459 void SetUp() override
460 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200461 Texture2DTest::SetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300462
463 setUpProgram();
464
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200465 mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale");
466 ASSERT_NE(-1, mDrawScaleUniformLocation);
Jamie Madill2453dbc2015-07-14 11:35:42 -0400467
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200468 glUseProgram(mProgram);
469 glUniform2f(mDrawScaleUniformLocation, 1.0f, 1.0f);
470 glUseProgram(0);
471 ASSERT_GL_NO_ERROR();
472 }
473
474 GLint mDrawScaleUniformLocation;
475};
476
Olli Etuaho4644a202016-01-12 15:12:53 +0200477class Sampler2DAsFunctionParameterTest : public Texture2DTest
478{
479 protected:
480 Sampler2DAsFunctionParameterTest() : Texture2DTest() {}
481
Jamie Madill35cd7332018-12-02 12:03:33 -0500482 const char *getFragmentShaderSource() override
Olli Etuaho4644a202016-01-12 15:12:53 +0200483 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300484 return
485 R"(precision highp float;
Olli Etuaho4644a202016-01-12 15:12:53 +0200486 uniform sampler2D tex;
487 varying vec2 texcoord;
488
489 vec4 computeFragColor(sampler2D aTex)
490 {
491 return texture2D(aTex, texcoord);
492 }
493
494 void main()
495 {
496 gl_FragColor = computeFragColor(tex);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300497 })";
Olli Etuaho4644a202016-01-12 15:12:53 +0200498 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300499
500 void SetUp() override
501 {
502 Texture2DTest::SetUp();
503 setUpProgram();
504 }
Olli Etuaho4644a202016-01-12 15:12:53 +0200505};
506
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200507class TextureCubeTest : public TexCoordDrawTest
508{
509 protected:
510 TextureCubeTest()
511 : TexCoordDrawTest(),
512 mTexture2D(0),
513 mTextureCube(0),
514 mTexture2DUniformLocation(-1),
515 mTextureCubeUniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500516 {}
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200517
Jamie Madill35cd7332018-12-02 12:03:33 -0500518 const char *getFragmentShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200519 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300520 return
521 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200522 uniform sampler2D tex2D;
523 uniform samplerCube texCube;
524 varying vec2 texcoord;
525
526 void main()
527 {
528 gl_FragColor = texture2D(tex2D, texcoord);
529 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300530 })";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200531 }
532
533 void SetUp() override
534 {
535 TexCoordDrawTest::SetUp();
536
537 glGenTextures(1, &mTextureCube);
538 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Geoff Langc4e93662017-05-01 10:45:59 -0400539 for (GLenum face = 0; face < 6; face++)
540 {
541 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
542 GL_UNSIGNED_BYTE, nullptr);
543 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200544 EXPECT_GL_NO_ERROR();
545
546 mTexture2D = create2DTexture();
547
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300548 setUpProgram();
549
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200550 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
551 ASSERT_NE(-1, mTexture2DUniformLocation);
552 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
553 ASSERT_NE(-1, mTextureCubeUniformLocation);
554 }
555
556 void TearDown() override
557 {
558 glDeleteTextures(1, &mTextureCube);
559 TexCoordDrawTest::TearDown();
560 }
561
562 GLuint mTexture2D;
563 GLuint mTextureCube;
564 GLint mTexture2DUniformLocation;
565 GLint mTextureCubeUniformLocation;
566};
567
Martin Radev7e2c0d32017-09-15 14:25:42 +0300568class TextureCubeTestES3 : public ANGLETest
569{
570 protected:
571 TextureCubeTestES3() {}
572};
573
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200574class SamplerArrayTest : public TexCoordDrawTest
575{
576 protected:
577 SamplerArrayTest()
578 : TexCoordDrawTest(),
579 mTexture2DA(0),
580 mTexture2DB(0),
581 mTexture0UniformLocation(-1),
582 mTexture1UniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500583 {}
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200584
Jamie Madill35cd7332018-12-02 12:03:33 -0500585 const char *getFragmentShaderSource() override
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200586 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300587 return
588 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200589 uniform highp sampler2D tex2DArray[2];
590 varying vec2 texcoord;
591 void main()
592 {
593 gl_FragColor = texture2D(tex2DArray[0], texcoord);
594 gl_FragColor += texture2D(tex2DArray[1], texcoord);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300595 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200596 }
597
598 void SetUp() override
599 {
600 TexCoordDrawTest::SetUp();
601
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300602 setUpProgram();
603
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200604 mTexture0UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[0]");
605 ASSERT_NE(-1, mTexture0UniformLocation);
606 mTexture1UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[1]");
607 ASSERT_NE(-1, mTexture1UniformLocation);
608
609 mTexture2DA = create2DTexture();
610 mTexture2DB = create2DTexture();
611 ASSERT_GL_NO_ERROR();
612 }
613
614 void TearDown() override
615 {
616 glDeleteTextures(1, &mTexture2DA);
617 glDeleteTextures(1, &mTexture2DB);
618 TexCoordDrawTest::TearDown();
619 }
620
621 void testSamplerArrayDraw()
622 {
623 GLubyte texData[4];
624 texData[0] = 0;
625 texData[1] = 60;
626 texData[2] = 0;
627 texData[3] = 255;
628
629 glActiveTexture(GL_TEXTURE0);
630 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
631 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
632
633 texData[1] = 120;
634 glActiveTexture(GL_TEXTURE1);
635 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
636 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
637 EXPECT_GL_ERROR(GL_NO_ERROR);
638
639 glUseProgram(mProgram);
640 glUniform1i(mTexture0UniformLocation, 0);
641 glUniform1i(mTexture1UniformLocation, 1);
642 drawQuad(mProgram, "position", 0.5f);
643 EXPECT_GL_NO_ERROR();
644
645 EXPECT_PIXEL_NEAR(0, 0, 0, 180, 0, 255, 2);
646 }
647
648 GLuint mTexture2DA;
649 GLuint mTexture2DB;
650 GLint mTexture0UniformLocation;
651 GLint mTexture1UniformLocation;
652};
653
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200654class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest
655{
656 protected:
657 SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {}
658
Jamie Madill35cd7332018-12-02 12:03:33 -0500659 const char *getFragmentShaderSource() override
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200660 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300661 return
662 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200663 uniform highp sampler2D tex2DArray[2];
664 varying vec2 texcoord;
665
666 vec4 computeFragColor(highp sampler2D aTex2DArray[2])
667 {
668 return texture2D(aTex2DArray[0], texcoord) + texture2D(aTex2DArray[1], texcoord);
669 }
670
671 void main()
672 {
673 gl_FragColor = computeFragColor(tex2DArray);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300674 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200675 }
676};
677
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200678class Texture2DArrayTestES3 : public TexCoordDrawTest
679{
680 protected:
681 Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {}
682
Jamie Madill35cd7332018-12-02 12:03:33 -0500683 const char *getVertexShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200684 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500685 return "#version 300 es\n"
686 "out vec2 texcoord;\n"
687 "in vec4 position;\n"
688 "void main()\n"
689 "{\n"
690 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
691 " texcoord = (position.xy * 0.5) + 0.5;\n"
692 "}\n";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200693 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400694
Jamie Madill35cd7332018-12-02 12:03:33 -0500695 const char *getFragmentShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200696 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500697 return "#version 300 es\n"
698 "precision highp float;\n"
699 "uniform highp sampler2DArray tex2DArray;\n"
700 "in vec2 texcoord;\n"
701 "out vec4 fragColor;\n"
702 "void main()\n"
703 "{\n"
704 " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n"
705 "}\n";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200706 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400707
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200708 void SetUp() override
709 {
710 TexCoordDrawTest::SetUp();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400711
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300712 setUpProgram();
713
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200714 mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray");
Jamie Madill2453dbc2015-07-14 11:35:42 -0400715 ASSERT_NE(-1, mTextureArrayLocation);
716
717 glGenTextures(1, &m2DArrayTexture);
718 ASSERT_GL_NO_ERROR();
719 }
720
721 void TearDown() override
722 {
723 glDeleteTextures(1, &m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200724 TexCoordDrawTest::TearDown();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400725 }
726
727 GLuint m2DArrayTexture;
Jamie Madill2453dbc2015-07-14 11:35:42 -0400728 GLint mTextureArrayLocation;
729};
730
Olli Etuahobce743a2016-01-15 17:18:28 +0200731class TextureSizeTextureArrayTest : public TexCoordDrawTest
732{
733 protected:
734 TextureSizeTextureArrayTest()
735 : TexCoordDrawTest(),
736 mTexture2DA(0),
737 mTexture2DB(0),
738 mTexture0Location(-1),
739 mTexture1Location(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500740 {}
Olli Etuahobce743a2016-01-15 17:18:28 +0200741
Jamie Madill35cd7332018-12-02 12:03:33 -0500742 const char *getVertexShaderSource() override { return essl3_shaders::vs::Simple(); }
Olli Etuahobce743a2016-01-15 17:18:28 +0200743
Jamie Madill35cd7332018-12-02 12:03:33 -0500744 const char *getFragmentShaderSource() override
Olli Etuahobce743a2016-01-15 17:18:28 +0200745 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500746 return "#version 300 es\n"
747 "precision highp float;\n"
748 "uniform highp sampler2D tex2DArray[2];\n"
749 "out vec4 fragColor;\n"
750 "void main()\n"
751 "{\n"
752 " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n"
753 " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n"
754 " fragColor = vec4(red, green, 0.0, 1.0);\n"
755 "}\n";
Olli Etuahobce743a2016-01-15 17:18:28 +0200756 }
757
758 void SetUp() override
759 {
760 TexCoordDrawTest::SetUp();
761
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300762 setUpProgram();
763
Olli Etuahobce743a2016-01-15 17:18:28 +0200764 mTexture0Location = glGetUniformLocation(mProgram, "tex2DArray[0]");
765 ASSERT_NE(-1, mTexture0Location);
766 mTexture1Location = glGetUniformLocation(mProgram, "tex2DArray[1]");
767 ASSERT_NE(-1, mTexture1Location);
768
769 mTexture2DA = create2DTexture();
770 mTexture2DB = create2DTexture();
771 ASSERT_GL_NO_ERROR();
772 }
773
774 void TearDown() override
775 {
776 glDeleteTextures(1, &mTexture2DA);
777 glDeleteTextures(1, &mTexture2DB);
778 TexCoordDrawTest::TearDown();
779 }
780
781 GLuint mTexture2DA;
782 GLuint mTexture2DB;
783 GLint mTexture0Location;
784 GLint mTexture1Location;
785};
786
Olli Etuahoa314b612016-03-10 16:43:00 +0200787class Texture3DTestES3 : public TexCoordDrawTest
788{
789 protected:
790 Texture3DTestES3() : TexCoordDrawTest(), mTexture3D(0), mTexture3DUniformLocation(-1) {}
791
Jamie Madill35cd7332018-12-02 12:03:33 -0500792 const char *getVertexShaderSource() override
Olli Etuahoa314b612016-03-10 16:43:00 +0200793 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500794 return "#version 300 es\n"
795 "out vec2 texcoord;\n"
796 "in vec4 position;\n"
797 "void main()\n"
798 "{\n"
799 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
800 " texcoord = (position.xy * 0.5) + 0.5;\n"
801 "}\n";
Olli Etuahoa314b612016-03-10 16:43:00 +0200802 }
803
Jamie Madill35cd7332018-12-02 12:03:33 -0500804 const char *getFragmentShaderSource() override
Olli Etuahoa314b612016-03-10 16:43:00 +0200805 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500806 return "#version 300 es\n"
807 "precision highp float;\n"
808 "uniform highp sampler3D tex3D;\n"
809 "in vec2 texcoord;\n"
810 "out vec4 fragColor;\n"
811 "void main()\n"
812 "{\n"
813 " fragColor = texture(tex3D, vec3(texcoord, 0.0));\n"
814 "}\n";
Olli Etuahoa314b612016-03-10 16:43:00 +0200815 }
816
817 void SetUp() override
818 {
819 TexCoordDrawTest::SetUp();
820
821 glGenTextures(1, &mTexture3D);
822
823 setUpProgram();
824
825 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
826 ASSERT_NE(-1, mTexture3DUniformLocation);
827 }
828
829 void TearDown() override
830 {
831 glDeleteTextures(1, &mTexture3D);
832 TexCoordDrawTest::TearDown();
833 }
834
835 GLuint mTexture3D;
836 GLint mTexture3DUniformLocation;
837};
838
Olli Etuaho1a679902016-01-14 12:21:47 +0200839class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest
840{
841 protected:
842 ShadowSamplerPlusSampler3DTestES3()
843 : TexCoordDrawTest(),
844 mTextureShadow(0),
845 mTexture3D(0),
846 mTextureShadowUniformLocation(-1),
847 mTexture3DUniformLocation(-1),
848 mDepthRefUniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500849 {}
Olli Etuaho1a679902016-01-14 12:21:47 +0200850
Jamie Madill35cd7332018-12-02 12:03:33 -0500851 const char *getVertexShaderSource() override
Olli Etuaho1a679902016-01-14 12:21:47 +0200852 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500853 return "#version 300 es\n"
854 "out vec2 texcoord;\n"
855 "in vec4 position;\n"
856 "void main()\n"
857 "{\n"
858 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
859 " texcoord = (position.xy * 0.5) + 0.5;\n"
860 "}\n";
Olli Etuaho1a679902016-01-14 12:21:47 +0200861 }
862
Jamie Madill35cd7332018-12-02 12:03:33 -0500863 const char *getFragmentShaderSource() override
Olli Etuaho1a679902016-01-14 12:21:47 +0200864 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500865 return "#version 300 es\n"
866 "precision highp float;\n"
867 "uniform highp sampler2DShadow tex2DShadow;\n"
868 "uniform highp sampler3D tex3D;\n"
869 "in vec2 texcoord;\n"
870 "uniform float depthRef;\n"
871 "out vec4 fragColor;\n"
872 "void main()\n"
873 "{\n"
874 " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n"
875 " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n"
876 "}\n";
Olli Etuaho1a679902016-01-14 12:21:47 +0200877 }
878
879 void SetUp() override
880 {
881 TexCoordDrawTest::SetUp();
882
883 glGenTextures(1, &mTexture3D);
884
885 glGenTextures(1, &mTextureShadow);
886 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
887 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
888
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300889 setUpProgram();
890
Olli Etuaho1a679902016-01-14 12:21:47 +0200891 mTextureShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
892 ASSERT_NE(-1, mTextureShadowUniformLocation);
893 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
894 ASSERT_NE(-1, mTexture3DUniformLocation);
895 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
896 ASSERT_NE(-1, mDepthRefUniformLocation);
897 }
898
899 void TearDown() override
900 {
901 glDeleteTextures(1, &mTextureShadow);
902 glDeleteTextures(1, &mTexture3D);
903 TexCoordDrawTest::TearDown();
904 }
905
906 GLuint mTextureShadow;
907 GLuint mTexture3D;
908 GLint mTextureShadowUniformLocation;
909 GLint mTexture3DUniformLocation;
910 GLint mDepthRefUniformLocation;
911};
912
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200913class SamplerTypeMixTestES3 : public TexCoordDrawTest
914{
915 protected:
916 SamplerTypeMixTestES3()
917 : TexCoordDrawTest(),
918 mTexture2D(0),
919 mTextureCube(0),
920 mTexture2DShadow(0),
921 mTextureCubeShadow(0),
922 mTexture2DUniformLocation(-1),
923 mTextureCubeUniformLocation(-1),
924 mTexture2DShadowUniformLocation(-1),
925 mTextureCubeShadowUniformLocation(-1),
926 mDepthRefUniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500927 {}
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200928
Jamie Madill35cd7332018-12-02 12:03:33 -0500929 const char *getVertexShaderSource() override
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200930 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500931 return "#version 300 es\n"
932 "out vec2 texcoord;\n"
933 "in vec4 position;\n"
934 "void main()\n"
935 "{\n"
936 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
937 " texcoord = (position.xy * 0.5) + 0.5;\n"
938 "}\n";
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200939 }
940
Jamie Madill35cd7332018-12-02 12:03:33 -0500941 const char *getFragmentShaderSource() override
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200942 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500943 return "#version 300 es\n"
944 "precision highp float;\n"
945 "uniform highp sampler2D tex2D;\n"
946 "uniform highp samplerCube texCube;\n"
947 "uniform highp sampler2DShadow tex2DShadow;\n"
948 "uniform highp samplerCubeShadow texCubeShadow;\n"
949 "in vec2 texcoord;\n"
950 "uniform float depthRef;\n"
951 "out vec4 fragColor;\n"
952 "void main()\n"
953 "{\n"
954 " fragColor = texture(tex2D, texcoord);\n"
955 " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n"
956 " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n"
957 " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * "
958 "0.125);\n"
959 "}\n";
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200960 }
961
962 void SetUp() override
963 {
964 TexCoordDrawTest::SetUp();
965
966 glGenTextures(1, &mTexture2D);
967 glGenTextures(1, &mTextureCube);
968
969 glGenTextures(1, &mTexture2DShadow);
970 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
971 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
972
973 glGenTextures(1, &mTextureCubeShadow);
974 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
975 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
976
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300977 setUpProgram();
978
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200979 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
980 ASSERT_NE(-1, mTexture2DUniformLocation);
981 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
982 ASSERT_NE(-1, mTextureCubeUniformLocation);
983 mTexture2DShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
984 ASSERT_NE(-1, mTexture2DShadowUniformLocation);
985 mTextureCubeShadowUniformLocation = glGetUniformLocation(mProgram, "texCubeShadow");
986 ASSERT_NE(-1, mTextureCubeShadowUniformLocation);
987 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
988 ASSERT_NE(-1, mDepthRefUniformLocation);
989
990 ASSERT_GL_NO_ERROR();
991 }
992
993 void TearDown() override
994 {
995 glDeleteTextures(1, &mTexture2D);
996 glDeleteTextures(1, &mTextureCube);
997 glDeleteTextures(1, &mTexture2DShadow);
998 glDeleteTextures(1, &mTextureCubeShadow);
999 TexCoordDrawTest::TearDown();
1000 }
1001
1002 GLuint mTexture2D;
1003 GLuint mTextureCube;
1004 GLuint mTexture2DShadow;
1005 GLuint mTextureCubeShadow;
1006 GLint mTexture2DUniformLocation;
1007 GLint mTextureCubeUniformLocation;
1008 GLint mTexture2DShadowUniformLocation;
1009 GLint mTextureCubeShadowUniformLocation;
1010 GLint mDepthRefUniformLocation;
1011};
1012
Olli Etuaho96963162016-03-21 11:54:33 +02001013class SamplerInStructTest : public Texture2DTest
1014{
1015 protected:
1016 SamplerInStructTest() : Texture2DTest() {}
1017
1018 const char *getTextureUniformName() override { return "us.tex"; }
1019
Jamie Madill35cd7332018-12-02 12:03:33 -05001020 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001021 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001022 return "precision highp float;\n"
1023 "struct S\n"
1024 "{\n"
1025 " vec4 a;\n"
1026 " highp sampler2D tex;\n"
1027 "};\n"
1028 "uniform S us;\n"
1029 "varying vec2 texcoord;\n"
1030 "void main()\n"
1031 "{\n"
1032 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x);\n"
1033 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001034 }
1035
1036 void runSamplerInStructTest()
1037 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001038 setUpProgram();
1039
Olli Etuaho96963162016-03-21 11:54:33 +02001040 glActiveTexture(GL_TEXTURE0);
1041 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001042 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1043 &GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001044 drawQuad(mProgram, "position", 0.5f);
Olli Etuahoa314b612016-03-10 16:43:00 +02001045 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001046 }
1047};
1048
1049class SamplerInStructAsFunctionParameterTest : public SamplerInStructTest
1050{
1051 protected:
1052 SamplerInStructAsFunctionParameterTest() : SamplerInStructTest() {}
1053
Jamie Madill35cd7332018-12-02 12:03:33 -05001054 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001055 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001056 return "precision highp float;\n"
1057 "struct S\n"
1058 "{\n"
1059 " vec4 a;\n"
1060 " highp sampler2D tex;\n"
1061 "};\n"
1062 "uniform S us;\n"
1063 "varying vec2 texcoord;\n"
1064 "vec4 sampleFrom(S s) {\n"
1065 " return texture2D(s.tex, texcoord + s.a.x);\n"
1066 "}\n"
1067 "void main()\n"
1068 "{\n"
1069 " gl_FragColor = sampleFrom(us);\n"
1070 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001071 }
1072};
1073
1074class SamplerInStructArrayAsFunctionParameterTest : public SamplerInStructTest
1075{
1076 protected:
1077 SamplerInStructArrayAsFunctionParameterTest() : SamplerInStructTest() {}
1078
1079 const char *getTextureUniformName() override { return "us[0].tex"; }
1080
Jamie Madill35cd7332018-12-02 12:03:33 -05001081 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001082 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001083 return "precision highp float;\n"
1084 "struct S\n"
1085 "{\n"
1086 " vec4 a;\n"
1087 " highp sampler2D tex;\n"
1088 "};\n"
1089 "uniform S us[1];\n"
1090 "varying vec2 texcoord;\n"
1091 "vec4 sampleFrom(S s) {\n"
1092 " return texture2D(s.tex, texcoord + s.a.x);\n"
1093 "}\n"
1094 "void main()\n"
1095 "{\n"
1096 " gl_FragColor = sampleFrom(us[0]);\n"
1097 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001098 }
1099};
1100
1101class SamplerInNestedStructAsFunctionParameterTest : public SamplerInStructTest
1102{
1103 protected:
1104 SamplerInNestedStructAsFunctionParameterTest() : SamplerInStructTest() {}
1105
1106 const char *getTextureUniformName() override { return "us[0].sub.tex"; }
1107
Jamie Madill35cd7332018-12-02 12:03:33 -05001108 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001109 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001110 return "precision highp float;\n"
1111 "struct SUB\n"
1112 "{\n"
1113 " vec4 a;\n"
1114 " highp sampler2D tex;\n"
1115 "};\n"
1116 "struct S\n"
1117 "{\n"
1118 " SUB sub;\n"
1119 "};\n"
1120 "uniform S us[1];\n"
1121 "varying vec2 texcoord;\n"
1122 "vec4 sampleFrom(SUB s) {\n"
1123 " return texture2D(s.tex, texcoord + s.a.x);\n"
1124 "}\n"
1125 "void main()\n"
1126 "{\n"
1127 " gl_FragColor = sampleFrom(us[0].sub);\n"
1128 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001129 }
1130};
1131
1132class SamplerInStructAndOtherVariableTest : public SamplerInStructTest
1133{
1134 protected:
1135 SamplerInStructAndOtherVariableTest() : SamplerInStructTest() {}
1136
Jamie Madill35cd7332018-12-02 12:03:33 -05001137 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001138 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001139 return "precision highp float;\n"
1140 "struct S\n"
1141 "{\n"
1142 " vec4 a;\n"
1143 " highp sampler2D tex;\n"
1144 "};\n"
1145 "uniform S us;\n"
1146 "uniform float us_tex;\n"
1147 "varying vec2 texcoord;\n"
1148 "void main()\n"
1149 "{\n"
1150 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x + us_tex);\n"
1151 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001152 }
1153};
1154
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001155TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001156{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001157 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001158 EXPECT_GL_ERROR(GL_NO_ERROR);
1159
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001160 setUpProgram();
1161
Jamie Madill50cf2be2018-06-15 09:46:57 -04001162 const GLubyte *pixels[20] = {0};
Jamie Madillf67115c2014-04-22 13:14:05 -04001163 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1164 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001165
1166 if (extensionEnabled("GL_EXT_texture_storage"))
1167 {
1168 // Create a 1-level immutable texture.
1169 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1170
1171 // Try calling sub image on the second level.
1172 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1173 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1174 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001175}
Geoff Langc41e42d2014-04-28 10:58:16 -04001176
John Bauman18319182016-09-28 14:22:27 -07001177// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1178TEST_P(Texture2DTest, QueryBinding)
1179{
1180 glBindTexture(GL_TEXTURE_2D, 0);
1181 EXPECT_GL_ERROR(GL_NO_ERROR);
1182
1183 GLint textureBinding;
1184 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1185 EXPECT_GL_NO_ERROR();
1186 EXPECT_EQ(0, textureBinding);
1187
1188 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
1189 if (extensionEnabled("GL_OES_EGL_image_external") ||
1190 extensionEnabled("GL_NV_EGL_stream_consumer_external"))
1191 {
1192 EXPECT_GL_NO_ERROR();
1193 EXPECT_EQ(0, textureBinding);
1194 }
1195 else
1196 {
1197 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1198 }
1199}
1200
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001201TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001202{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001203 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001204 EXPECT_GL_ERROR(GL_NO_ERROR);
1205
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001206 setUpProgram();
1207
Geoff Langc41e42d2014-04-28 10:58:16 -04001208 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001209 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001210 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001211 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001212
Jamie Madill50cf2be2018-06-15 09:46:57 -04001213 const GLubyte *pixel[4] = {0};
Geoff Langc41e42d2014-04-28 10:58:16 -04001214
1215 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1216 EXPECT_GL_NO_ERROR();
1217
1218 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1219 EXPECT_GL_NO_ERROR();
1220
1221 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1222 EXPECT_GL_NO_ERROR();
1223}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001224
1225// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001226TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001227{
1228 glActiveTexture(GL_TEXTURE0);
1229 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1230 glActiveTexture(GL_TEXTURE1);
1231 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1232 EXPECT_GL_ERROR(GL_NO_ERROR);
1233
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001234 glUseProgram(mProgram);
1235 glUniform1i(mTexture2DUniformLocation, 0);
1236 glUniform1i(mTextureCubeUniformLocation, 1);
1237 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001238 EXPECT_GL_NO_ERROR();
1239}
Jamie Madill9aca0592014-10-06 16:26:59 -04001240
Olli Etuaho53a2da12016-01-11 15:43:32 +02001241// Test drawing with two texture types accessed from the same shader and check that the result of
1242// drawing is correct.
1243TEST_P(TextureCubeTest, CubeMapDraw)
1244{
1245 GLubyte texData[4];
1246 texData[0] = 0;
1247 texData[1] = 60;
1248 texData[2] = 0;
1249 texData[3] = 255;
1250
1251 glActiveTexture(GL_TEXTURE0);
1252 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1253 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1254
1255 glActiveTexture(GL_TEXTURE1);
1256 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1257 texData[1] = 120;
1258 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1259 texData);
1260 EXPECT_GL_ERROR(GL_NO_ERROR);
1261
1262 glUseProgram(mProgram);
1263 glUniform1i(mTexture2DUniformLocation, 0);
1264 glUniform1i(mTextureCubeUniformLocation, 1);
1265 drawQuad(mProgram, "position", 0.5f);
1266 EXPECT_GL_NO_ERROR();
1267
1268 int px = getWindowWidth() - 1;
1269 int py = 0;
1270 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1271}
1272
Olli Etuaho4644a202016-01-12 15:12:53 +02001273TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1274{
1275 glActiveTexture(GL_TEXTURE0);
1276 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1277 GLubyte texData[4];
1278 texData[0] = 0;
1279 texData[1] = 128;
1280 texData[2] = 0;
1281 texData[3] = 255;
1282 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1283 glUseProgram(mProgram);
1284 glUniform1i(mTexture2DUniformLocation, 0);
1285 drawQuad(mProgram, "position", 0.5f);
1286 EXPECT_GL_NO_ERROR();
1287
1288 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1289}
1290
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001291// Test drawing with two textures passed to the shader in a sampler array.
1292TEST_P(SamplerArrayTest, SamplerArrayDraw)
1293{
1294 testSamplerArrayDraw();
1295}
1296
1297// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1298// user-defined function in the shader.
1299TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1300{
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05001301 // TODO: Diagnose and fix. http://anglebug.com/2955
1302 ANGLE_SKIP_TEST_IF(IsVulkan() && IsAndroid());
1303
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001304 testSamplerArrayDraw();
1305}
1306
Jamie Madill9aca0592014-10-06 16:26:59 -04001307// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001308TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001309{
1310 int px = getWindowWidth() / 2;
1311 int py = getWindowHeight() / 2;
1312
1313 glActiveTexture(GL_TEXTURE0);
1314 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1315
Olli Etuahoa314b612016-03-10 16:43:00 +02001316 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001317
Olli Etuahoa314b612016-03-10 16:43:00 +02001318 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001319 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1320 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1321 glGenerateMipmap(GL_TEXTURE_2D);
1322
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001323 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001324 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001325 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1326 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001327 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001328 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001329
Olli Etuahoa314b612016-03-10 16:43:00 +02001330 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001331
Olli Etuahoa314b612016-03-10 16:43:00 +02001332 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1333 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001334 glGenerateMipmap(GL_TEXTURE_2D);
1335
Olli Etuahoa314b612016-03-10 16:43:00 +02001336 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001337
Olli Etuahoa314b612016-03-10 16:43:00 +02001338 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1339 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001340 glGenerateMipmap(GL_TEXTURE_2D);
1341
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001342 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001343
1344 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001345 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001346}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001347
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001348// Test creating a FBO with a cube map render target, to test an ANGLE bug
1349// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001350TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001351{
Michael Spangd8506c72019-01-29 15:35:09 -05001352 // http://anglebug.com/3145
1353 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
1354
Shahbaz Youssefi0c128e12019-03-25 23:50:14 -04001355 // http://anglebug.com/2822
1356 ANGLE_SKIP_TEST_IF(IsWindows() && IsIntel() && IsVulkan());
1357
Jamie Madill3f3b3582018-09-14 10:38:44 -04001358 GLFramebuffer fbo;
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001359 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1360
1361 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Jamie Madill50cf2be2018-06-15 09:46:57 -04001362 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1363 mTextureCube, 0);
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001364
Corentin Wallez322653b2015-06-17 18:33:56 +02001365 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001366 EXPECT_GL_NO_ERROR();
Jamie Madill3f3b3582018-09-14 10:38:44 -04001367
1368 // Test clearing the six mip faces individually.
1369 std::array<GLColor, 6> faceColors = {{GLColor::red, GLColor::green, GLColor::blue,
1370 GLColor::yellow, GLColor::cyan, GLColor::magenta}};
1371
1372 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1373 {
1374 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1375 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1376
1377 Vector4 clearColorF = faceColors[faceIndex].toNormalizedVector();
1378 glClearColor(clearColorF.x(), clearColorF.y(), clearColorF.z(), clearColorF.w());
1379 glClear(GL_COLOR_BUFFER_BIT);
1380
1381 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex]);
1382 }
1383
1384 // Iterate the faces again to make sure the colors haven't changed.
1385 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1386 {
1387 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1388 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1389 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex])
1390 << "face color " << faceIndex << " shouldn't change";
1391 }
1392}
1393
1394// Tests clearing a cube map with a scissor enabled.
1395TEST_P(TextureCubeTest, CubeMapFBOScissoredClear)
1396{
1397 // TODO(jie.a.chen): Diagnose and fix. http://anglebug.com/2822
1398 ANGLE_SKIP_TEST_IF(IsVulkan() && IsIntel() && IsWindows());
1399
Michael Spangd8506c72019-01-29 15:35:09 -05001400 // http://anglebug.com/3145
1401 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
1402
Jamie Madill3f3b3582018-09-14 10:38:44 -04001403 constexpr size_t kSize = 16;
1404
1405 GLFramebuffer fbo;
1406 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1407 glViewport(0, 0, kSize, kSize);
1408
1409 GLTexture texcube;
1410 glBindTexture(GL_TEXTURE_CUBE_MAP, texcube);
1411 for (GLenum face = 0; face < 6; face++)
1412 {
1413 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA,
1414 GL_UNSIGNED_BYTE, nullptr);
1415 }
1416 ASSERT_GL_NO_ERROR();
1417
1418 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1419 texcube, 0);
1420
1421 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1422 ASSERT_GL_NO_ERROR();
1423
1424 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1425 glClear(GL_COLOR_BUFFER_BIT);
1426 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1427
1428 glEnable(GL_SCISSOR_TEST);
1429 glScissor(kSize / 2, 0, kSize / 2, kSize);
1430 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
1431 glClear(GL_COLOR_BUFFER_BIT);
1432
1433 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1434 EXPECT_PIXEL_COLOR_EQ(kSize / 2 + 1, 0, GLColor::green);
1435
1436 ASSERT_GL_NO_ERROR();
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001437}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001438
Jamie Madill50cf2be2018-06-15 09:46:57 -04001439// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a
1440// default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001441TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001442{
Luc Ferron7348fc52018-05-09 07:17:16 -04001443 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -04001444
Jamie Madill50cf2be2018-06-15 09:46:57 -04001445 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001446 int height = getWindowHeight();
1447
1448 GLuint tex2D;
1449 glGenTextures(1, &tex2D);
1450 glActiveTexture(GL_TEXTURE0);
1451 glBindTexture(GL_TEXTURE_2D, tex2D);
1452
1453 // Fill with red
1454 std::vector<GLubyte> pixels(3 * 16 * 16);
1455 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1456 {
1457 pixels[pixelId * 3 + 0] = 255;
1458 pixels[pixelId * 3 + 1] = 0;
1459 pixels[pixelId * 3 + 2] = 0;
1460 }
1461
1462 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001463 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1464 // alpha color. The data is kept in a CPU-side image and the image is marked as dirty.
Geoff Langc4e93662017-05-01 10:45:59 -04001465 if (getClientMajorVersion() >= 3)
1466 {
1467 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1468 }
1469 else
1470 {
1471 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1472 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001473
1474 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1475 // glTexSubImage2D should take into account that the image is dirty.
1476 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1477 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1478 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1479
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001480 setUpProgram();
1481
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001482 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001483 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001484 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001485 glDeleteTextures(1, &tex2D);
1486 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001487 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001488
1489 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001490 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1491 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001492}
1493
Jamie Madill50cf2be2018-06-15 09:46:57 -04001494// Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has
1495// initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001496TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001497{
1498 if (extensionEnabled("NV_pixel_buffer_object"))
1499 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04001500 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001501 int height = getWindowHeight();
1502
1503 GLuint tex2D;
1504 glGenTextures(1, &tex2D);
1505 glActiveTexture(GL_TEXTURE0);
1506 glBindTexture(GL_TEXTURE_2D, tex2D);
1507
1508 // Fill with red
1509 std::vector<GLubyte> pixels(3 * 16 * 16);
1510 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1511 {
1512 pixels[pixelId * 3 + 0] = 255;
1513 pixels[pixelId * 3 + 1] = 0;
1514 pixels[pixelId * 3 + 2] = 0;
1515 }
1516
1517 // Read 16x16 region from red backbuffer to PBO
1518 GLuint pbo;
1519 glGenBuffers(1, &pbo);
1520 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1521 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1522
1523 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001524 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1525 // alpha color. The data is kept in a CPU-side image and the image is marked as dirty.
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001526 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1527
1528 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1529 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001530 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 +00001531 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1532 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1533
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001534 setUpProgram();
1535
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001536 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001537 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001538 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001539 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001540 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001541 EXPECT_GL_NO_ERROR();
1542 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1543 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1544 }
1545}
Jamie Madillbc393df2015-01-29 13:46:07 -05001546
1547// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001548TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001549{
1550 testFloatCopySubImage(1, 1);
1551}
1552
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001553TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001554{
1555 testFloatCopySubImage(2, 1);
1556}
1557
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001558TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001559{
1560 testFloatCopySubImage(2, 2);
1561}
1562
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001563TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001564{
1565 testFloatCopySubImage(3, 1);
1566}
1567
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001568TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001569{
1570 testFloatCopySubImage(3, 2);
1571}
1572
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001573TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001574{
Yunchao He9550c602018-02-13 14:47:05 +08001575 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1576 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001577
Yunchao He9550c602018-02-13 14:47:05 +08001578 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1579 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001580
Jamie Madillbc393df2015-01-29 13:46:07 -05001581 testFloatCopySubImage(3, 3);
1582}
1583
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001584TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001585{
1586 testFloatCopySubImage(4, 1);
1587}
1588
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001589TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001590{
1591 testFloatCopySubImage(4, 2);
1592}
1593
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001594TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001595{
Yunchao He9550c602018-02-13 14:47:05 +08001596 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1597 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001598
Jamie Madillbc393df2015-01-29 13:46:07 -05001599 testFloatCopySubImage(4, 3);
1600}
1601
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001602TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001603{
Luc Ferronf786b702018-07-10 11:01:43 -04001604 // TODO(lucferron): This test fails only on linux and intel.
1605 // http://anglebug.com/2726
1606 ANGLE_SKIP_TEST_IF(IsVulkan() && IsLinux() && IsIntel());
1607
Yunchao He9550c602018-02-13 14:47:05 +08001608 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1609 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001610
Jamie Madillbc393df2015-01-29 13:46:07 -05001611 testFloatCopySubImage(4, 4);
1612}
Austin Kinross07285142015-03-26 11:36:16 -07001613
Jamie Madill50cf2be2018-06-15 09:46:57 -04001614// Port of
1615// https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1616// Run against GL_ALPHA/UNSIGNED_BYTE format, to ensure that D3D11 Feature Level 9_3 correctly
1617// handles GL_ALPHA
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001618TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001619{
1620 const int npotTexSize = 5;
Jamie Madill50cf2be2018-06-15 09:46:57 -04001621 const int potTexSize = 4; // Should be less than npotTexSize
Austin Kinross07285142015-03-26 11:36:16 -07001622 GLuint tex2D;
1623
1624 if (extensionEnabled("GL_OES_texture_npot"))
1625 {
1626 // This test isn't applicable if texture_npot is enabled
1627 return;
1628 }
1629
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001630 setUpProgram();
1631
Austin Kinross07285142015-03-26 11:36:16 -07001632 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1633
Austin Kinross5faa15b2016-01-11 13:32:48 -08001634 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1635 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1636
Austin Kinross07285142015-03-26 11:36:16 -07001637 glActiveTexture(GL_TEXTURE0);
1638 glGenTextures(1, &tex2D);
1639 glBindTexture(GL_TEXTURE_2D, tex2D);
1640
Till Rathmannc1551dc2018-08-15 17:04:49 +02001641 const std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize, 64);
Austin Kinross07285142015-03-26 11:36:16 -07001642
1643 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1644 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1645
1646 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
Jamie Madill50cf2be2018-06-15 09:46:57 -04001647 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1648 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001649 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1650
1651 // Check that an NPOT texture on level 0 succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001652 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1653 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001654 EXPECT_GL_NO_ERROR();
1655
1656 // Check that generateMipmap fails on NPOT
1657 glGenerateMipmap(GL_TEXTURE_2D);
1658 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1659
1660 // Check that nothing is drawn if filtering is not correct for NPOT
1661 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1662 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1663 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1664 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1665 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001666 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001667 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1668
1669 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1670 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1671 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1672 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1673 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001674 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001675 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1676
1677 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1678 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1679 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001680 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001681 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1682
1683 // Check that glTexImage2D for POT texture succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001684 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE,
1685 pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001686 EXPECT_GL_NO_ERROR();
1687
1688 // Check that generateMipmap for an POT texture succeeds
1689 glGenerateMipmap(GL_TEXTURE_2D);
1690 EXPECT_GL_NO_ERROR();
1691
1692 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1693 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1694 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1695 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1696 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1697 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001698 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001699 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1700 EXPECT_GL_NO_ERROR();
1701}
Jamie Madillfa05f602015-05-07 13:47:11 -04001702
Austin Kinross08528e12015-10-07 16:24:40 -07001703// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1704// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001705TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001706{
1707 glActiveTexture(GL_TEXTURE0);
1708 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1709
1710 // Create an 8x8 (i.e. power-of-two) texture.
1711 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1712 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1713 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1714 glGenerateMipmap(GL_TEXTURE_2D);
1715
1716 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1717 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001718 std::array<GLColor, 3 * 3> data;
1719 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001720
1721 EXPECT_GL_NO_ERROR();
1722}
1723
Geoff Lang3702d8c2019-04-08 13:44:06 -04001724// Regression test for http://crbug.com/949985 to make sure dirty bits are propagated up from
1725// TextureImpl and the texture is synced before being used in a draw call.
1726TEST_P(Texture2DTestES3, TextureImplPropogatesDirtyBits)
1727{
1728 ANGLE_SKIP_TEST_IF(IsIntel() && IsOpenGL());
Yuly Novikove6b23e42019-04-10 17:19:15 -04001729 // Flaky hangs on Win10 AMD RX 550 GL. http://anglebug.com/3371
1730 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsOpenGL());
Geoff Lang3702d8c2019-04-08 13:44:06 -04001731
1732 // The workaround in the GL backend required to trigger this bug generates driver warning
1733 // messages.
1734 ScopedIgnorePlatformMessages ignoreMessages;
1735
1736 setUpProgram();
1737 glUseProgram(mProgram);
1738 glActiveTexture(GL_TEXTURE0 + mTexture2DUniformLocation);
1739
1740 GLTexture dest;
1741 glBindTexture(GL_TEXTURE_2D, dest);
1742
1743 GLTexture source;
1744 glBindTexture(GL_TEXTURE_2D, source);
1745
1746 // Put data in mip 0 and 1
1747 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1748 GLColor::red.data());
1749 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1750 GLColor::green.data());
1751
1752 // Disable mipmapping so source is complete
1753 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1754 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1755
1756 // Force the dirty bits to be synchronized in source
1757 drawQuad(mProgram, "position", 1.0f);
1758
1759 // Copy from mip 1 of the source. In the GL backend this internally sets the base level to mip
1760 // 1 and sets a dirty bit.
1761 glCopyTextureCHROMIUM(source, 1, GL_TEXTURE_2D, dest, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_FALSE,
1762 GL_FALSE, GL_FALSE);
1763
1764 // Draw again, assertions are generated if the texture has internal dirty bits at draw time
1765 drawQuad(mProgram, "position", 1.0f);
1766}
1767
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001768// Test to check that texture completeness is determined correctly when the texture base level is
1769// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1770TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1771{
1772 glActiveTexture(GL_TEXTURE0);
1773 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001774
1775 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1776 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1777 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1778 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1779 texDataGreen.data());
1780 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1781 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001782 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1783 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1784 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1785
1786 EXPECT_GL_NO_ERROR();
1787
1788 drawQuad(mProgram, "position", 0.5f);
1789
Olli Etuahoa314b612016-03-10 16:43:00 +02001790 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1791}
1792
1793// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1794// have images defined.
1795TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1796{
Yunchao He9550c602018-02-13 14:47:05 +08001797 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1798 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1799
Olli Etuahoa314b612016-03-10 16:43:00 +02001800 glActiveTexture(GL_TEXTURE0);
1801 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1802 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1803 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1804 texDataGreen.data());
1805 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1806 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1807 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1808 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1809
1810 EXPECT_GL_NO_ERROR();
1811
1812 drawQuad(mProgram, "position", 0.5f);
1813
1814 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1815}
1816
Olli Etuahoe8528d82016-05-16 17:50:52 +03001817// Test that drawing works correctly when level 0 is undefined and base level is 1.
1818TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1819{
Yunchao He9550c602018-02-13 14:47:05 +08001820 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1821 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1822
Olli Etuahoe8528d82016-05-16 17:50:52 +03001823 glActiveTexture(GL_TEXTURE0);
1824 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1825 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1826 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1827 texDataGreen.data());
1828 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1829 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1830 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1831 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1832
1833 EXPECT_GL_NO_ERROR();
1834
1835 // Texture is incomplete.
1836 drawQuad(mProgram, "position", 0.5f);
1837 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1838
1839 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1840 texDataGreen.data());
1841
1842 // Texture is now complete.
1843 drawQuad(mProgram, "position", 0.5f);
1844 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1845}
1846
Olli Etuahoa314b612016-03-10 16:43:00 +02001847// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1848// dimensions that don't fit the images inside the range.
1849// GLES 3.0.4 section 3.8.13 Texture completeness
1850TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1851{
Olli Etuahoa314b612016-03-10 16:43:00 +02001852 glActiveTexture(GL_TEXTURE0);
1853 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1854 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1855 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1856 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1857
1858 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1859 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1860
1861 // Two levels that are initially unused.
1862 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1863 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1864 texDataCyan.data());
1865
1866 // One level that is used - only this level should affect completeness.
1867 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1868 texDataGreen.data());
1869
1870 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1871 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1872
1873 EXPECT_GL_NO_ERROR();
1874
1875 drawQuad(mProgram, "position", 0.5f);
1876
1877 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1878
Yunchao He2f23f352018-02-11 22:11:37 +08001879 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001880
1881 // Switch the level that is being used to the cyan level 2.
1882 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1883 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1884
1885 EXPECT_GL_NO_ERROR();
1886
1887 drawQuad(mProgram, "position", 0.5f);
1888
1889 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1890}
1891
1892// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1893// have images defined.
1894TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1895{
Olli Etuahoa314b612016-03-10 16:43:00 +02001896 glActiveTexture(GL_TEXTURE0);
1897 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1898 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1899 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1900 texDataGreen.data());
1901 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1902 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1903 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1904 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1905
1906 EXPECT_GL_NO_ERROR();
1907
1908 drawQuad(mProgram, "position", 0.5f);
1909
1910 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1911}
1912
1913// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1914// dimensions that don't fit the images inside the range.
1915// GLES 3.0.4 section 3.8.13 Texture completeness
1916TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1917{
Olli Etuahoa314b612016-03-10 16:43:00 +02001918 glActiveTexture(GL_TEXTURE0);
1919 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1920 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1921 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1922 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1923
1924 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1925 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1926
1927 // Two levels that are initially unused.
1928 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1929 texDataRed.data());
1930 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1931 texDataCyan.data());
1932
1933 // One level that is used - only this level should affect completeness.
1934 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1935 texDataGreen.data());
1936
1937 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1938 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1939
1940 EXPECT_GL_NO_ERROR();
1941
1942 drawQuad(mProgram, "position", 0.5f);
1943
1944 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1945
Yunchao He2f23f352018-02-11 22:11:37 +08001946 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001947
1948 // Switch the level that is being used to the cyan level 2.
1949 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
1950 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
1951
1952 EXPECT_GL_NO_ERROR();
1953
1954 drawQuad(mProgram, "position", 0.5f);
1955
1956 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1957}
1958
1959// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1960// have images defined.
1961TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
1962{
Olli Etuahoa314b612016-03-10 16:43:00 +02001963 glActiveTexture(GL_TEXTURE0);
1964 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
1965 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1966 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1967 texDataGreen.data());
1968 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1969 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1970 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1971 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1972
1973 EXPECT_GL_NO_ERROR();
1974
1975 drawQuad(mProgram, "position", 0.5f);
1976
1977 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1978}
1979
1980// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1981// dimensions that don't fit the images inside the range.
1982// GLES 3.0.4 section 3.8.13 Texture completeness
1983TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1984{
Olli Etuahoa314b612016-03-10 16:43:00 +02001985 glActiveTexture(GL_TEXTURE0);
1986 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
1987 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1988 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1989 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1990
1991 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1992 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1993
1994 // Two levels that are initially unused.
1995 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1996 texDataRed.data());
1997 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1998 texDataCyan.data());
1999
2000 // One level that is used - only this level should affect completeness.
2001 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2002 texDataGreen.data());
2003
2004 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2005 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2006
2007 EXPECT_GL_NO_ERROR();
2008
2009 drawQuad(mProgram, "position", 0.5f);
2010
2011 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2012
Yunchao He2f23f352018-02-11 22:11:37 +08002013 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
2014
Yunchao He9550c602018-02-13 14:47:05 +08002015 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
2016 // level was changed.
2017 ANGLE_SKIP_TEST_IF(IsNVIDIA() && (IsOpenGL() || IsOpenGLES()));
Olli Etuahoa314b612016-03-10 16:43:00 +02002018
2019 // Switch the level that is being used to the cyan level 2.
2020 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2021 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2022
2023 EXPECT_GL_NO_ERROR();
2024
2025 drawQuad(mProgram, "position", 0.5f);
2026
2027 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2028}
2029
2030// Test that texture completeness is updated if texture max level changes.
2031// GLES 3.0.4 section 3.8.13 Texture completeness
2032TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2033{
Olli Etuahoa314b612016-03-10 16:43:00 +02002034 glActiveTexture(GL_TEXTURE0);
2035 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2036 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2037
2038 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2039 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2040
2041 // A level that is initially unused.
2042 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2043 texDataGreen.data());
2044
2045 // One level that is initially used - only this level should affect completeness.
2046 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2047 texDataGreen.data());
2048
2049 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2050 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2051
2052 EXPECT_GL_NO_ERROR();
2053
2054 drawQuad(mProgram, "position", 0.5f);
2055
2056 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2057
2058 // Switch the max level to level 1. The levels within the used range now have inconsistent
2059 // dimensions and the texture should be incomplete.
2060 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2061
2062 EXPECT_GL_NO_ERROR();
2063
2064 drawQuad(mProgram, "position", 0.5f);
2065
2066 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2067}
2068
2069// Test that 3D texture completeness is updated if texture max level changes.
2070// GLES 3.0.4 section 3.8.13 Texture completeness
2071TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2072{
Olli Etuahoa314b612016-03-10 16:43:00 +02002073 glActiveTexture(GL_TEXTURE0);
2074 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2075 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2076
2077 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2078 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2079
2080 // A level that is initially unused.
2081 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2082 texDataGreen.data());
2083
2084 // One level that is initially used - only this level should affect completeness.
2085 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2086 texDataGreen.data());
2087
2088 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2089 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2090
2091 EXPECT_GL_NO_ERROR();
2092
2093 drawQuad(mProgram, "position", 0.5f);
2094
2095 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2096
2097 // Switch the max level to level 1. The levels within the used range now have inconsistent
2098 // dimensions and the texture should be incomplete.
2099 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2100
2101 EXPECT_GL_NO_ERROR();
2102
2103 drawQuad(mProgram, "position", 0.5f);
2104
2105 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2106}
2107
2108// Test that texture completeness is updated if texture base level changes.
2109// GLES 3.0.4 section 3.8.13 Texture completeness
2110TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2111{
Olli Etuahoa314b612016-03-10 16:43:00 +02002112 glActiveTexture(GL_TEXTURE0);
2113 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2114 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2115
2116 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2117 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2118
2119 // Two levels that are initially unused.
2120 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2121 texDataGreen.data());
2122 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2123 texDataGreen.data());
2124
2125 // One level that is initially used - only this level should affect completeness.
2126 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2127 texDataGreen.data());
2128
2129 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2130 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2131
2132 EXPECT_GL_NO_ERROR();
2133
2134 drawQuad(mProgram, "position", 0.5f);
2135
2136 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2137
2138 // Switch the base level to level 1. The levels within the used range now have inconsistent
2139 // dimensions and the texture should be incomplete.
2140 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2141
2142 EXPECT_GL_NO_ERROR();
2143
2144 drawQuad(mProgram, "position", 0.5f);
2145
2146 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2147}
2148
2149// Test that texture is not complete if base level is greater than max level.
2150// GLES 3.0.4 section 3.8.13 Texture completeness
2151TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2152{
Olli Etuahoa314b612016-03-10 16:43:00 +02002153 glActiveTexture(GL_TEXTURE0);
2154 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2155
2156 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2157 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2158
2159 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2160
2161 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2162 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2163
2164 EXPECT_GL_NO_ERROR();
2165
2166 drawQuad(mProgram, "position", 0.5f);
2167
2168 // Texture should be incomplete.
2169 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2170}
2171
2172// Test that immutable texture base level and max level are clamped.
2173// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2174TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2175{
Olli Etuahoa314b612016-03-10 16:43:00 +02002176 glActiveTexture(GL_TEXTURE0);
2177 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2178
2179 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2180 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2181
2182 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2183
2184 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2185
2186 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2187 // should be clamped to [base_level, levels - 1].
2188 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2189 // In the case of this test, those rules make the effective base level and max level 0.
2190 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2191 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2192
2193 EXPECT_GL_NO_ERROR();
2194
2195 drawQuad(mProgram, "position", 0.5f);
2196
2197 // Texture should be complete.
2198 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2199}
2200
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002201// Test that changing base level works when it affects the format of the texture.
2202TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2203{
Yunchao He9550c602018-02-13 14:47:05 +08002204 // Observed rendering corruption on NVIDIA OpenGL.
2205 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL());
2206
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002207 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002208
2209 // Observed incorrect rendering on AMD OpenGL.
2210 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002211
2212 glActiveTexture(GL_TEXTURE0);
2213 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2214 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2215 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2216
2217 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2218 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2219
2220 // RGBA8 level that's initially unused.
2221 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2222 texDataCyan.data());
2223
2224 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2225 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2226
2227 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2228 // format. It reads green channel data from the green and alpha channels of texDataGreen
2229 // (this is a bit hacky but works).
2230 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2231
2232 EXPECT_GL_NO_ERROR();
2233
2234 drawQuad(mProgram, "position", 0.5f);
2235
2236 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2237
2238 // Switch the texture to use the cyan level 0 with the RGBA format.
2239 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2240 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2241
2242 EXPECT_GL_NO_ERROR();
2243
2244 drawQuad(mProgram, "position", 0.5f);
2245
2246 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2247}
2248
Olli Etuahoa314b612016-03-10 16:43:00 +02002249// Test that setting a texture image works when base level is out of range.
2250TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2251{
2252 glActiveTexture(GL_TEXTURE0);
2253 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2254
2255 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2256 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2257
2258 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2259 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2260
2261 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2262
2263 EXPECT_GL_NO_ERROR();
2264
2265 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2266
2267 drawQuad(mProgram, "position", 0.5f);
2268
2269 // Texture should be complete.
2270 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002271}
2272
Jamie Madill50cf2be2018-06-15 09:46:57 -04002273// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG
2274// RBA->RGBA8, with 1.0 in the alpha channel. This test covers a bug where redefining array textures
2275// with these formats does not work as expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002276TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002277{
2278 std::vector<GLubyte> pixelData;
2279 for (size_t count = 0; count < 5000; count++)
2280 {
2281 pixelData.push_back(0u);
2282 pixelData.push_back(255u);
2283 pixelData.push_back(0u);
2284 }
2285
2286 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002287 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002288 glUniform1i(mTextureArrayLocation, 0);
2289
2290 // The first draw worked correctly.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002291 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2292 &pixelData[0]);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002293
2294 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2295 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2296 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2297 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002298 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002299 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002300
2301 // The dimension of the respecification must match the original exactly to trigger the bug.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002302 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2303 &pixelData[0]);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002304 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002305 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002306
2307 ASSERT_GL_NO_ERROR();
2308}
2309
Olli Etuaho1a679902016-01-14 12:21:47 +02002310// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2311// This test is needed especially to confirm that sampler registers get assigned correctly on
2312// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2313TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2314{
2315 glActiveTexture(GL_TEXTURE0);
2316 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2317 GLubyte texData[4];
2318 texData[0] = 0;
2319 texData[1] = 60;
2320 texData[2] = 0;
2321 texData[3] = 255;
2322 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2323
2324 glActiveTexture(GL_TEXTURE1);
2325 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2326 GLfloat depthTexData[1];
2327 depthTexData[0] = 0.5f;
2328 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2329 depthTexData);
2330
2331 glUseProgram(mProgram);
2332 glUniform1f(mDepthRefUniformLocation, 0.3f);
2333 glUniform1i(mTexture3DUniformLocation, 0);
2334 glUniform1i(mTextureShadowUniformLocation, 1);
2335
2336 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2337 drawQuad(mProgram, "position", 0.5f);
2338 EXPECT_GL_NO_ERROR();
2339 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2340 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2341
2342 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2343 drawQuad(mProgram, "position", 0.5f);
2344 EXPECT_GL_NO_ERROR();
2345 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2346 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2347}
2348
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002349// Test multiple different sampler types in the same shader.
2350// This test makes sure that even if sampler / texture registers get grouped together based on type
2351// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2352// still has the right register index information for each ESSL sampler.
2353// The tested ESSL samplers have the following types in D3D11 HLSL:
2354// sampler2D: Texture2D + SamplerState
2355// samplerCube: TextureCube + SamplerState
2356// sampler2DShadow: Texture2D + SamplerComparisonState
2357// samplerCubeShadow: TextureCube + SamplerComparisonState
2358TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2359{
2360 glActiveTexture(GL_TEXTURE0);
2361 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2362 GLubyte texData[4];
2363 texData[0] = 0;
2364 texData[1] = 0;
2365 texData[2] = 120;
2366 texData[3] = 255;
2367 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2368
2369 glActiveTexture(GL_TEXTURE1);
2370 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2371 texData[0] = 0;
2372 texData[1] = 90;
2373 texData[2] = 0;
2374 texData[3] = 255;
2375 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2376 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2377 texData);
2378
2379 glActiveTexture(GL_TEXTURE2);
2380 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2381 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2382 GLfloat depthTexData[1];
2383 depthTexData[0] = 0.5f;
2384 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2385 depthTexData);
2386
2387 glActiveTexture(GL_TEXTURE3);
2388 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2389 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2390 depthTexData[0] = 0.2f;
2391 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2392 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2393 depthTexData);
2394
2395 EXPECT_GL_NO_ERROR();
2396
2397 glUseProgram(mProgram);
2398 glUniform1f(mDepthRefUniformLocation, 0.3f);
2399 glUniform1i(mTexture2DUniformLocation, 0);
2400 glUniform1i(mTextureCubeUniformLocation, 1);
2401 glUniform1i(mTexture2DShadowUniformLocation, 2);
2402 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2403
2404 drawQuad(mProgram, "position", 0.5f);
2405 EXPECT_GL_NO_ERROR();
2406 // The shader writes:
2407 // <texture 2d color> +
2408 // <cube map color> +
2409 // 0.25 * <comparison result (1.0)> +
2410 // 0.125 * <comparison result (0.0)>
2411 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2412}
2413
Olli Etuahobce743a2016-01-15 17:18:28 +02002414// Test different base levels on textures accessed through the same sampler array.
2415// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2416TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2417{
Yunchao He9550c602018-02-13 14:47:05 +08002418 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2419
Olli Etuahobce743a2016-01-15 17:18:28 +02002420 glActiveTexture(GL_TEXTURE0);
2421 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2422 GLsizei size = 64;
2423 for (GLint level = 0; level < 7; ++level)
2424 {
2425 ASSERT_LT(0, size);
2426 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2427 nullptr);
2428 size = size / 2;
2429 }
2430 ASSERT_EQ(0, size);
2431 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2432
2433 glActiveTexture(GL_TEXTURE1);
2434 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2435 size = 128;
2436 for (GLint level = 0; level < 8; ++level)
2437 {
2438 ASSERT_LT(0, size);
2439 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2440 nullptr);
2441 size = size / 2;
2442 }
2443 ASSERT_EQ(0, size);
2444 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2445 EXPECT_GL_NO_ERROR();
2446
2447 glUseProgram(mProgram);
2448 glUniform1i(mTexture0Location, 0);
2449 glUniform1i(mTexture1Location, 1);
2450
Olli Etuaho5804dc82018-04-13 14:11:46 +03002451 drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
Olli Etuahobce743a2016-01-15 17:18:28 +02002452 EXPECT_GL_NO_ERROR();
2453 // Red channel: width of level 1 of texture A: 32.
2454 // Green channel: width of level 3 of texture B: 16.
2455 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2456}
2457
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002458// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2459// ES 3.0.4 table 3.24
2460TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2461{
2462 glActiveTexture(GL_TEXTURE0);
2463 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2464 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2465 EXPECT_GL_NO_ERROR();
2466
2467 drawQuad(mProgram, "position", 0.5f);
2468
2469 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2470}
2471
2472// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2473// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002474TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002475{
Luc Ferron5164b792018-03-06 09:10:12 -05002476 setUpProgram();
2477
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002478 glActiveTexture(GL_TEXTURE0);
2479 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2480 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2481 EXPECT_GL_NO_ERROR();
2482
2483 drawQuad(mProgram, "position", 0.5f);
2484
2485 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2486}
2487
Luc Ferron5164b792018-03-06 09:10:12 -05002488// Validate that every component of the pixel will be equal to the luminance value we've set
2489// and that the alpha channel will be 1 (or 255 to be exact).
2490TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2491{
2492 setUpProgram();
2493
2494 glActiveTexture(GL_TEXTURE0);
2495 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2496 uint8_t pixel = 50;
2497 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2498 EXPECT_GL_NO_ERROR();
2499
2500 drawQuad(mProgram, "position", 0.5f);
2501
2502 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2503}
2504
2505// Validate that every component of the pixel will be equal to the luminance value we've set
2506// and that the alpha channel will be the second component.
2507TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2508{
2509 setUpProgram();
2510
2511 glActiveTexture(GL_TEXTURE0);
2512 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2513 uint8_t pixel[] = {50, 25};
2514 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2515 GL_UNSIGNED_BYTE, pixel);
2516 EXPECT_GL_NO_ERROR();
2517
2518 drawQuad(mProgram, "position", 0.5f);
2519
2520 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2521}
2522
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002523// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2524// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002525TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002526{
Luc Ferrond8c632c2018-04-10 12:31:44 -04002527 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
2528 ANGLE_SKIP_TEST_IF(IsD3D9());
2529 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002530
2531 setUpProgram();
2532
Luc Ferrond8c632c2018-04-10 12:31:44 -04002533 glActiveTexture(GL_TEXTURE0);
2534 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2535 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2536 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002537
Luc Ferrond8c632c2018-04-10 12:31:44 -04002538 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002539
Luc Ferrond8c632c2018-04-10 12:31:44 -04002540 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002541}
2542
2543// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2544// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002545TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002546{
Luc Ferrond8c632c2018-04-10 12:31:44 -04002547 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
2548 ANGLE_SKIP_TEST_IF(IsD3D9());
2549 ANGLE_SKIP_TEST_IF(IsVulkan());
2550 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES());
2551 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2552 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002553
Luc Ferrond8c632c2018-04-10 12:31:44 -04002554 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002555
Luc Ferrond8c632c2018-04-10 12:31:44 -04002556 glActiveTexture(GL_TEXTURE0);
2557 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2558 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2559 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002560
Luc Ferrond8c632c2018-04-10 12:31:44 -04002561 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002562
Luc Ferrond8c632c2018-04-10 12:31:44 -04002563 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002564}
2565
2566// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2567// ES 3.0.4 table 3.24
2568TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2569{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002570 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2571
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002572 glActiveTexture(GL_TEXTURE0);
2573 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2574 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2575 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2576 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2577 EXPECT_GL_NO_ERROR();
2578
2579 drawQuad(mProgram, "position", 0.5f);
2580
2581 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2582}
2583
2584// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2585// ES 3.0.4 table 3.24
2586TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2587{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002588 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2589
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002590 glActiveTexture(GL_TEXTURE0);
2591 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2592
2593 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2594 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2595 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2596 EXPECT_GL_NO_ERROR();
2597
2598 drawQuad(mProgram, "position", 0.5f);
2599
2600 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2601}
2602
2603// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2604// ES 3.0.4 table 3.24
2605TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2606{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002607 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2608
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002609 glActiveTexture(GL_TEXTURE0);
2610 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2611 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2612 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2613 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2614 EXPECT_GL_NO_ERROR();
2615
2616 drawQuad(mProgram, "position", 0.5f);
2617
2618 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2619}
2620
2621// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2622// ES 3.0.4 table 3.24
2623TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2624{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002625 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2626
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002627 glActiveTexture(GL_TEXTURE0);
2628 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2629 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2630 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2631 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2632 EXPECT_GL_NO_ERROR();
2633
2634 drawQuad(mProgram, "position", 0.5f);
2635
2636 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2637}
2638
2639// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2640// ES 3.0.4 table 3.24
2641TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2642{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002643 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2644
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002645 glActiveTexture(GL_TEXTURE0);
2646 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2647 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2648 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2649 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2650 EXPECT_GL_NO_ERROR();
2651
2652 drawQuad(mProgram, "position", 0.5f);
2653
2654 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2655}
2656
2657// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2658// ES 3.0.4 table 3.24
2659TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2660{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002661 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2662
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002663 glActiveTexture(GL_TEXTURE0);
2664 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2665 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2666 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2667 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2668 EXPECT_GL_NO_ERROR();
2669
2670 drawQuad(mProgram, "position", 0.5f);
2671
2672 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2673}
2674
2675// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2676// ES 3.0.4 table 3.24
2677TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2678{
2679 glActiveTexture(GL_TEXTURE0);
2680 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2681 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2682 EXPECT_GL_NO_ERROR();
2683
2684 drawQuad(mProgram, "position", 0.5f);
2685
2686 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2687}
2688
2689// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2690// ES 3.0.4 table 3.24
2691TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2692{
2693 glActiveTexture(GL_TEXTURE0);
2694 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2695 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2696 nullptr);
2697 EXPECT_GL_NO_ERROR();
2698
2699 drawQuad(mProgram, "position", 0.5f);
2700
2701 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2702}
2703
2704// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2705// ES 3.0.4 table 3.24
2706TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2707{
Yunchao He9550c602018-02-13 14:47:05 +08002708 // Seems to fail on OSX 10.12 Intel.
2709 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Jamie Madillbb1db482017-01-10 10:48:32 -05002710
Yuly Novikov49886892018-01-23 21:18:27 -05002711 // http://anglebug.com/2190
2712 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2713
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002714 glActiveTexture(GL_TEXTURE0);
2715 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2716 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2717 EXPECT_GL_NO_ERROR();
2718
2719 drawQuad(mProgram, "position", 0.5f);
2720
2721 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2722}
2723
2724// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2725// ES 3.0.4 table 3.24
2726TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2727{
Yunchao He9550c602018-02-13 14:47:05 +08002728 // Seems to fail on OSX 10.12 Intel.
2729 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002730
Yuly Novikov49886892018-01-23 21:18:27 -05002731 // http://anglebug.com/2190
2732 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2733
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002734 glActiveTexture(GL_TEXTURE0);
2735 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2736 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2737 EXPECT_GL_NO_ERROR();
2738
2739 drawQuad(mProgram, "position", 0.5f);
2740
2741 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2742}
2743
Olli Etuaho96963162016-03-21 11:54:33 +02002744// Use a sampler in a uniform struct.
2745TEST_P(SamplerInStructTest, SamplerInStruct)
2746{
2747 runSamplerInStructTest();
2748}
2749
2750// Use a sampler in a uniform struct that's passed as a function parameter.
2751TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2752{
Yuly Novikovd18c0482019-04-04 19:56:43 -04002753 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
2754 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002755
Olli Etuaho96963162016-03-21 11:54:33 +02002756 runSamplerInStructTest();
2757}
2758
2759// Use a sampler in a uniform struct array with a struct from the array passed as a function
2760// parameter.
2761TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2762{
Yuly Novikovd18c0482019-04-04 19:56:43 -04002763 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
2764 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08002765
Olli Etuaho96963162016-03-21 11:54:33 +02002766 runSamplerInStructTest();
2767}
2768
2769// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2770// parameter.
2771TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2772{
Yuly Novikovd18c0482019-04-04 19:56:43 -04002773 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
2774 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08002775
Olli Etuaho96963162016-03-21 11:54:33 +02002776 runSamplerInStructTest();
2777}
2778
2779// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2780// similarly named uniform.
2781TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2782{
2783 runSamplerInStructTest();
2784}
2785
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05002786// GL_EXT_texture_filter_anisotropic
2787class TextureAnisotropyTest : public Texture2DTest
2788{
2789 protected:
2790 void uploadTexture()
2791 {
2792 glActiveTexture(GL_TEXTURE0);
2793 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2794 GLColor texDataRed[1] = {GLColor::red};
2795 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed);
2796 EXPECT_GL_NO_ERROR();
2797 }
2798};
2799
2800// Tests that setting anisotropic filtering doesn't cause failures at draw time.
2801TEST_P(TextureAnisotropyTest, AnisotropyFunctional)
2802{
2803 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_filter_anisotropic"));
2804
2805 setUpProgram();
2806
2807 uploadTexture();
2808
2809 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2810 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2811 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f);
2812 EXPECT_GL_NO_ERROR();
2813
2814 drawQuad(mProgram, "position", 0.5f);
2815
2816 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
2817 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
2818 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::red);
2819}
2820
Till Rathmannb8543632018-10-02 19:46:14 +02002821// GL_OES_texture_border_clamp
2822class TextureBorderClampTest : public Texture2DTest
2823{
2824 protected:
2825 TextureBorderClampTest() : Texture2DTest() {}
2826
Jamie Madill35cd7332018-12-02 12:03:33 -05002827 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02002828 {
2829 return
2830 R"(precision highp float;
2831 attribute vec4 position;
2832 varying vec2 texcoord;
2833
2834 void main()
2835 {
2836 gl_Position = vec4(position.xy, 0.0, 1.0);
2837 // texcoords in [-0.5, 1.5]
2838 texcoord = (position.xy) + 0.5;
2839 })";
2840 }
2841
2842 void uploadTexture()
2843 {
2844 glActiveTexture(GL_TEXTURE0);
2845 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2846 std::vector<GLColor> texDataRed(1, GLColor::red);
2847 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2848 texDataRed.data());
2849 EXPECT_GL_NO_ERROR();
2850 }
2851};
2852
2853// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
2854// GL_CLAMP_TO_BORDER wrap mode (set with glTexParameter).
2855TEST_P(TextureBorderClampTest, TextureBorderClampFunctional)
2856{
2857 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
2858
2859 setUpProgram();
2860
2861 uploadTexture();
2862
2863 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
2864 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
2865 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2866 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2867 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2868 EXPECT_GL_NO_ERROR();
2869
2870 drawQuad(mProgram, "position", 0.5f);
2871
2872 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
2873 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2874 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
2875}
2876
2877// Test reading back GL_TEXTURE_BORDER_COLOR by glGetTexParameter.
2878TEST_P(TextureBorderClampTest, TextureBorderClampFunctional2)
2879{
2880 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
2881
2882 glActiveTexture(GL_TEXTURE0);
2883 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2884
2885 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2886
2887 GLint colorFixedPoint[4] = {0};
2888 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
2889 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
2890 std::numeric_limits<GLint>::max()};
2891 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
2892 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
2893 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
2894 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
2895
2896 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
2897 std::numeric_limits<GLint>::max()};
2898 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
2899
2900 GLfloat color[4] = {0.0f};
2901 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
2902 EXPECT_EQ(color[0], kFloatBlue.R);
2903 EXPECT_EQ(color[1], kFloatBlue.G);
2904 EXPECT_EQ(color[2], kFloatBlue.B);
2905 EXPECT_EQ(color[3], kFloatBlue.A);
2906}
2907
2908// Test GL_TEXTURE_BORDER_COLOR parameter validation at glTexParameter.
2909TEST_P(TextureBorderClampTest, TextureBorderClampValidation)
2910{
2911 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
2912
2913 glActiveTexture(GL_TEXTURE0);
2914 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2915
2916 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, 1.0f);
2917 EXPECT_GL_ERROR(GL_INVALID_ENUM);
2918
2919 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
2920 EXPECT_GL_ERROR(GL_INVALID_ENUM);
2921
2922 glTexParameterfv(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2923 EXPECT_GL_ERROR(GL_INVALID_ENUM);
2924
2925 GLint colorInt[4] = {0};
2926 glTexParameteriv(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_BORDER_COLOR, colorInt);
2927 EXPECT_GL_ERROR(GL_INVALID_ENUM);
2928
2929 if (getClientMajorVersion() < 3)
2930 {
2931 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
2932 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2933 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
2934 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2935
2936 GLuint colorUInt[4] = {0};
2937 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
2938 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2939 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
2940 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2941
2942 GLSampler sampler;
2943 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
2944 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2945 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
2946 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2947
2948 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
2949 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2950 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
2951 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2952 }
2953}
2954
2955class TextureBorderClampTestES3 : public TextureBorderClampTest
2956{
2957 protected:
2958 TextureBorderClampTestES3() : TextureBorderClampTest() {}
2959};
2960
2961// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
2962// GL_CLAMP_TO_BORDER wrap mode (set with glSamplerParameter).
2963TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional)
2964{
2965 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
2966
2967 setUpProgram();
2968
2969 uploadTexture();
2970
2971 GLSampler sampler;
2972 glBindSampler(0, sampler);
2973 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
2974 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
2975 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2976 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2977 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2978 EXPECT_GL_NO_ERROR();
2979
2980 drawQuad(mProgram, "position", 0.5f);
2981
2982 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
2983 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2984 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
2985}
2986
2987// Test reading back GL_TEXTURE_BORDER_COLOR by glGetSamplerParameter.
2988TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional2)
2989{
2990 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
2991
2992 glActiveTexture(GL_TEXTURE0);
2993
2994 GLSampler sampler;
2995 glBindSampler(0, sampler);
2996
2997 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2998
2999 GLint colorFixedPoint[4] = {0};
3000 glGetSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3001 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3002 std::numeric_limits<GLint>::max()};
3003 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3004 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3005 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3006 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3007
3008 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3009 std::numeric_limits<GLint>::max()};
3010 glSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3011
3012 GLfloat color[4] = {0.0f};
3013 glGetSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, color);
3014 EXPECT_EQ(color[0], kFloatBlue.R);
3015 EXPECT_EQ(color[1], kFloatBlue.G);
3016 EXPECT_EQ(color[2], kFloatBlue.B);
3017 EXPECT_EQ(color[3], kFloatBlue.A);
3018
3019 constexpr GLint colorSomewhatRedInt[4] = {500000, 0, 0, std::numeric_limits<GLint>::max()};
3020 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedInt);
3021 GLint colorInt[4] = {0};
3022 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3023 EXPECT_EQ(colorInt[0], colorSomewhatRedInt[0]);
3024 EXPECT_EQ(colorInt[1], colorSomewhatRedInt[1]);
3025 EXPECT_EQ(colorInt[2], colorSomewhatRedInt[2]);
3026 EXPECT_EQ(colorInt[3], colorSomewhatRedInt[3]);
3027
3028 constexpr GLuint colorSomewhatRedUInt[4] = {500000, 0, 0, std::numeric_limits<GLuint>::max()};
3029 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedUInt);
3030 GLuint colorUInt[4] = {0};
3031 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3032 EXPECT_EQ(colorUInt[0], colorSomewhatRedUInt[0]);
3033 EXPECT_EQ(colorUInt[1], colorSomewhatRedUInt[1]);
3034 EXPECT_EQ(colorUInt[2], colorSomewhatRedUInt[2]);
3035 EXPECT_EQ(colorUInt[3], colorSomewhatRedUInt[3]);
3036
3037 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3038
3039 constexpr GLint colorSomewhatGreenInt[4] = {0, 500000, 0, std::numeric_limits<GLint>::max()};
3040 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenInt);
3041 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3042 EXPECT_EQ(colorInt[0], colorSomewhatGreenInt[0]);
3043 EXPECT_EQ(colorInt[1], colorSomewhatGreenInt[1]);
3044 EXPECT_EQ(colorInt[2], colorSomewhatGreenInt[2]);
3045 EXPECT_EQ(colorInt[3], colorSomewhatGreenInt[3]);
3046
3047 constexpr GLuint colorSomewhatGreenUInt[4] = {0, 500000, 0, std::numeric_limits<GLuint>::max()};
3048 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenUInt);
3049 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3050 EXPECT_EQ(colorUInt[0], colorSomewhatGreenUInt[0]);
3051 EXPECT_EQ(colorUInt[1], colorSomewhatGreenUInt[1]);
3052 EXPECT_EQ(colorUInt[2], colorSomewhatGreenUInt[2]);
3053 EXPECT_EQ(colorUInt[3], colorSomewhatGreenUInt[3]);
3054}
3055
3056// Test GL_TEXTURE_BORDER_COLOR parameter validation at glSamplerParameter.
3057TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Validation)
3058{
3059 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
3060
3061 glActiveTexture(GL_TEXTURE0);
3062
3063 GLSampler sampler;
3064 glBindSampler(0, sampler);
3065
3066 glSamplerParameterf(sampler, GL_TEXTURE_BORDER_COLOR, 1.0f);
3067 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3068
3069 glSamplerParameteri(sampler, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3070 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3071}
3072
3073class TextureBorderClampIntegerTestES3 : public Texture2DTest
3074{
3075 protected:
3076 TextureBorderClampIntegerTestES3() : Texture2DTest(), isUnsignedIntTest(false) {}
3077
Jamie Madill35cd7332018-12-02 12:03:33 -05003078 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003079 {
3080 return
3081 R"(#version 300 es
3082 out vec2 texcoord;
3083 in vec4 position;
3084
3085 void main()
3086 {
3087 gl_Position = vec4(position.xy, 0.0, 1.0);
3088 // texcoords in [-0.5, 1.5]
3089 texcoord = (position.xy) + 0.5;
3090 })";
3091 }
3092
Jamie Madillba319ba2018-12-29 10:29:33 -05003093 const char *getFragmentShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003094 {
Jamie Madill35cd7332018-12-02 12:03:33 -05003095 if (isUnsignedIntTest)
3096 {
3097 return "#version 300 es\n"
3098 "precision highp float;\n"
3099 "uniform highp usampler2D tex;\n"
3100 "in vec2 texcoord;\n"
3101 "out vec4 fragColor;\n"
Till Rathmannb8543632018-10-02 19:46:14 +02003102
Jamie Madill35cd7332018-12-02 12:03:33 -05003103 "void main()\n"
3104 "{\n"
3105 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3106 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3107 "fragColor = (texture(tex, texcoord).r == 150u)"
3108 " ? green : red;\n"
3109 "}\n";
3110 }
3111 else
3112 {
3113 return "#version 300 es\n"
3114 "precision highp float;\n"
3115 "uniform highp isampler2D tex;\n"
3116 "in vec2 texcoord;\n"
3117 "out vec4 fragColor;\n"
3118
3119 "void main()\n"
3120 "{\n"
3121 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3122 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3123 "fragColor = (texture(tex, texcoord).r == -50)"
3124 " ? green : red;\n"
3125 "}\n";
3126 }
Till Rathmannb8543632018-10-02 19:46:14 +02003127 }
3128
3129 void uploadTexture()
3130 {
3131 glActiveTexture(GL_TEXTURE0);
3132 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3133 if (isUnsignedIntTest)
3134 {
3135 std::vector<GLubyte> texData(4, 100);
3136 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE,
3137 texData.data());
3138 }
3139 else
3140 {
3141 std::vector<GLbyte> texData(4, 100);
3142 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8I, 1, 1, 0, GL_RGBA_INTEGER, GL_BYTE,
3143 texData.data());
3144 }
3145 EXPECT_GL_NO_ERROR();
3146 }
3147
3148 bool isUnsignedIntTest;
3149};
3150
3151// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3152// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3153TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger)
3154{
3155 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
3156
3157 setUpProgram();
3158
3159 uploadTexture();
3160
3161 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3162 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3163 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3164 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3165
3166 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3167 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3168
3169 EXPECT_GL_NO_ERROR();
3170
3171 drawQuad(mProgram, "position", 0.5f);
3172
3173 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3174 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3175 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3176}
3177
3178// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3179// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3180TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger2)
3181{
3182 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
3183
3184 setUpProgram();
3185
3186 uploadTexture();
3187
3188 GLSampler sampler;
3189 glBindSampler(0, sampler);
3190 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3191 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3192 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3193 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3194
3195 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3196 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3197
3198 EXPECT_GL_NO_ERROR();
3199
3200 drawQuad(mProgram, "position", 0.5f);
3201
3202 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3203 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3204 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3205}
3206
3207// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3208// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIuivOES).
3209TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned)
3210{
3211 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
3212
3213 isUnsignedIntTest = true;
3214
3215 setUpProgram();
3216
3217 uploadTexture();
3218
3219 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3220 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3221 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3222 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3223
3224 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3225 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3226
3227 EXPECT_GL_NO_ERROR();
3228
3229 drawQuad(mProgram, "position", 0.5f);
3230
3231 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3232 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3233 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3234}
3235
3236// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3237// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with
3238// glSamplerParameterIuivOES).
3239TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned2)
3240{
3241 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
3242
3243 isUnsignedIntTest = true;
3244
3245 setUpProgram();
3246
3247 uploadTexture();
3248
3249 GLSampler sampler;
3250 glBindSampler(0, sampler);
3251 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3252 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3253 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3254 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3255
3256 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3257 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3258
3259 EXPECT_GL_NO_ERROR();
3260
3261 drawQuad(mProgram, "position", 0.5f);
3262
3263 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3264 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3265 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3266}
3267
3268// ~GL_OES_texture_border_clamp
3269
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003270class TextureLimitsTest : public ANGLETest
3271{
3272 protected:
3273 struct RGBA8
3274 {
3275 uint8_t R, G, B, A;
3276 };
3277
3278 TextureLimitsTest()
3279 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
3280 {
3281 setWindowWidth(128);
3282 setWindowHeight(128);
3283 setConfigRedBits(8);
3284 setConfigGreenBits(8);
3285 setConfigBlueBits(8);
3286 setConfigAlphaBits(8);
3287 }
3288
Jamie Madill0fdb9562018-09-17 17:18:43 -04003289 void SetUp() override
3290 {
3291 ANGLETest::SetUp();
3292
3293 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
3294 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
3295 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
3296
3297 ASSERT_GL_NO_ERROR();
3298 }
3299
3300 void TearDown() override
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003301 {
3302 if (mProgram != 0)
3303 {
3304 glDeleteProgram(mProgram);
3305 mProgram = 0;
3306
3307 if (!mTextures.empty())
3308 {
3309 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
3310 }
3311 }
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003312
Jamie Madill0fdb9562018-09-17 17:18:43 -04003313 ANGLETest::TearDown();
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003314 }
3315
3316 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
3317 GLint vertexTextureCount,
3318 GLint vertexActiveTextureCount,
3319 const std::string &fragPrefix,
3320 GLint fragmentTextureCount,
3321 GLint fragmentActiveTextureCount)
3322 {
3323 std::stringstream vertexShaderStr;
3324 vertexShaderStr << "attribute vec2 position;\n"
3325 << "varying vec4 color;\n"
3326 << "varying vec2 texCoord;\n";
3327
3328 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
3329 {
3330 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
3331 }
3332
3333 vertexShaderStr << "void main() {\n"
3334 << " gl_Position = vec4(position, 0, 1);\n"
3335 << " texCoord = (position * 0.5) + 0.5;\n"
3336 << " color = vec4(0);\n";
3337
3338 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
3339 {
3340 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
3341 << ", texCoord);\n";
3342 }
3343
3344 vertexShaderStr << "}";
3345
3346 std::stringstream fragmentShaderStr;
3347 fragmentShaderStr << "varying mediump vec4 color;\n"
3348 << "varying mediump vec2 texCoord;\n";
3349
3350 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
3351 {
3352 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
3353 }
3354
3355 fragmentShaderStr << "void main() {\n"
3356 << " gl_FragColor = color;\n";
3357
3358 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
3359 {
3360 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
3361 << ", texCoord);\n";
3362 }
3363
3364 fragmentShaderStr << "}";
3365
3366 const std::string &vertexShaderSource = vertexShaderStr.str();
3367 const std::string &fragmentShaderSource = fragmentShaderStr.str();
3368
Jamie Madill35cd7332018-12-02 12:03:33 -05003369 mProgram = CompileProgram(vertexShaderSource.c_str(), fragmentShaderSource.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003370 }
3371
3372 RGBA8 getPixel(GLint texIndex)
3373 {
3374 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3375 0, 255u};
3376 return pixel;
3377 }
3378
3379 void initTextures(GLint tex2DCount, GLint texCubeCount)
3380 {
3381 GLint totalCount = tex2DCount + texCubeCount;
3382 mTextures.assign(totalCount, 0);
3383 glGenTextures(totalCount, &mTextures[0]);
3384 ASSERT_GL_NO_ERROR();
3385
3386 std::vector<RGBA8> texData(16 * 16);
3387
3388 GLint texIndex = 0;
3389 for (; texIndex < tex2DCount; ++texIndex)
3390 {
3391 texData.assign(texData.size(), getPixel(texIndex));
3392 glActiveTexture(GL_TEXTURE0 + texIndex);
3393 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3394 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3395 &texData[0]);
3396 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3397 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3398 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3399 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3400 }
3401
3402 ASSERT_GL_NO_ERROR();
3403
3404 for (; texIndex < texCubeCount; ++texIndex)
3405 {
3406 texData.assign(texData.size(), getPixel(texIndex));
3407 glActiveTexture(GL_TEXTURE0 + texIndex);
3408 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3409 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3410 GL_UNSIGNED_BYTE, &texData[0]);
3411 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3412 GL_UNSIGNED_BYTE, &texData[0]);
3413 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3414 GL_UNSIGNED_BYTE, &texData[0]);
3415 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3416 GL_UNSIGNED_BYTE, &texData[0]);
3417 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3418 GL_UNSIGNED_BYTE, &texData[0]);
3419 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3420 GL_UNSIGNED_BYTE, &texData[0]);
3421 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3422 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3423 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3424 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3425 }
3426
3427 ASSERT_GL_NO_ERROR();
3428 }
3429
3430 void testWithTextures(GLint vertexTextureCount,
3431 const std::string &vertexTexturePrefix,
3432 GLint fragmentTextureCount,
3433 const std::string &fragmentTexturePrefix)
3434 {
3435 // Generate textures
3436 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3437
3438 glUseProgram(mProgram);
3439 RGBA8 expectedSum = {0};
3440 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3441 {
3442 std::stringstream uniformNameStr;
3443 uniformNameStr << vertexTexturePrefix << texIndex;
3444 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003445 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003446 ASSERT_NE(-1, location);
3447
3448 glUniform1i(location, texIndex);
3449 RGBA8 contribution = getPixel(texIndex);
3450 expectedSum.R += contribution.R;
3451 expectedSum.G += contribution.G;
3452 }
3453
3454 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3455 {
3456 std::stringstream uniformNameStr;
3457 uniformNameStr << fragmentTexturePrefix << texIndex;
3458 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003459 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003460 ASSERT_NE(-1, location);
3461
3462 glUniform1i(location, texIndex + vertexTextureCount);
3463 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3464 expectedSum.R += contribution.R;
3465 expectedSum.G += contribution.G;
3466 }
3467
3468 ASSERT_GE(256u, expectedSum.G);
3469
3470 drawQuad(mProgram, "position", 0.5f);
3471 ASSERT_GL_NO_ERROR();
3472 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3473 }
3474
3475 GLuint mProgram;
3476 std::vector<GLuint> mTextures;
3477 GLint mMaxVertexTextures;
3478 GLint mMaxFragmentTextures;
3479 GLint mMaxCombinedTextures;
3480};
3481
3482// Test rendering with the maximum vertex texture units.
3483TEST_P(TextureLimitsTest, MaxVertexTextures)
3484{
3485 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3486 ASSERT_NE(0u, mProgram);
3487 ASSERT_GL_NO_ERROR();
3488
3489 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3490}
3491
3492// Test rendering with the maximum fragment texture units.
3493TEST_P(TextureLimitsTest, MaxFragmentTextures)
3494{
3495 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3496 ASSERT_NE(0u, mProgram);
3497 ASSERT_GL_NO_ERROR();
3498
3499 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3500}
3501
3502// Test rendering with maximum combined texture units.
3503TEST_P(TextureLimitsTest, MaxCombinedTextures)
3504{
3505 GLint vertexTextures = mMaxVertexTextures;
3506
3507 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3508 {
3509 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3510 }
3511
3512 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3513 mMaxFragmentTextures, mMaxFragmentTextures);
3514 ASSERT_NE(0u, mProgram);
3515 ASSERT_GL_NO_ERROR();
3516
3517 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3518}
3519
3520// Negative test for exceeding the number of vertex textures
3521TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3522{
3523 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3524 0);
3525 ASSERT_EQ(0u, mProgram);
3526}
3527
3528// Negative test for exceeding the number of fragment textures
3529TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3530{
3531 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3532 mMaxFragmentTextures + 1);
3533 ASSERT_EQ(0u, mProgram);
3534}
3535
3536// Test active vertex textures under the limit, but excessive textures specified.
3537TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3538{
3539 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3540 ASSERT_NE(0u, mProgram);
3541 ASSERT_GL_NO_ERROR();
3542
3543 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3544}
3545
3546// Test active fragment textures under the limit, but excessive textures specified.
3547TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3548{
3549 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3550 mMaxFragmentTextures);
3551 ASSERT_NE(0u, mProgram);
3552 ASSERT_GL_NO_ERROR();
3553
3554 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3555}
3556
3557// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003558// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003559TEST_P(TextureLimitsTest, TextureTypeConflict)
3560{
Jamie Madill35cd7332018-12-02 12:03:33 -05003561 constexpr char kVS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003562 "attribute vec2 position;\n"
3563 "varying float color;\n"
3564 "uniform sampler2D tex2D;\n"
3565 "uniform samplerCube texCube;\n"
3566 "void main() {\n"
3567 " gl_Position = vec4(position, 0, 1);\n"
3568 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3569 " color = texture2D(tex2D, texCoord).x;\n"
3570 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3571 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05003572 constexpr char kFS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003573 "varying mediump float color;\n"
3574 "void main() {\n"
3575 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3576 "}";
3577
Jamie Madill35cd7332018-12-02 12:03:33 -05003578 mProgram = CompileProgram(kVS, kFS);
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003579 ASSERT_NE(0u, mProgram);
3580
3581 initTextures(1, 0);
3582
3583 glUseProgram(mProgram);
3584 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3585 ASSERT_NE(-1, tex2DLocation);
3586 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3587 ASSERT_NE(-1, texCubeLocation);
3588
3589 glUniform1i(tex2DLocation, 0);
3590 glUniform1i(texCubeLocation, 0);
3591 ASSERT_GL_NO_ERROR();
3592
3593 drawQuad(mProgram, "position", 0.5f);
3594 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3595}
3596
Vincent Lang25ab4512016-05-13 18:13:59 +02003597class Texture2DNorm16TestES3 : public Texture2DTestES3
3598{
3599 protected:
3600 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3601
3602 void SetUp() override
3603 {
3604 Texture2DTestES3::SetUp();
3605
3606 glActiveTexture(GL_TEXTURE0);
3607 glGenTextures(3, mTextures);
3608 glGenFramebuffers(1, &mFBO);
3609 glGenRenderbuffers(1, &mRenderbuffer);
3610
3611 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3612 {
3613 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3614 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3615 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3616 }
3617
3618 glBindTexture(GL_TEXTURE_2D, 0);
3619
3620 ASSERT_GL_NO_ERROR();
3621 }
3622
3623 void TearDown() override
3624 {
3625 glDeleteTextures(3, mTextures);
3626 glDeleteFramebuffers(1, &mFBO);
3627 glDeleteRenderbuffers(1, &mRenderbuffer);
3628
3629 Texture2DTestES3::TearDown();
3630 }
3631
3632 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3633 {
Geoff Langf607c602016-09-21 11:46:48 -04003634 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3635 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003636
3637 setUpProgram();
3638
3639 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3640 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3641 0);
3642
3643 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3644 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3645
3646 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003647 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003648
3649 EXPECT_GL_NO_ERROR();
3650
3651 drawQuad(mProgram, "position", 0.5f);
3652
Geoff Langf607c602016-09-21 11:46:48 -04003653 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003654
Jamie Madill50cf2be2018-06-15 09:46:57 -04003655 EXPECT_PIXEL_COLOR_EQ(0, 0,
3656 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3657 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003658
3659 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3660
3661 ASSERT_GL_NO_ERROR();
3662 }
3663
3664 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3665 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04003666 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003667 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003668
3669 setUpProgram();
3670
3671 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3672 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3673
3674 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3675 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3676 0);
3677
3678 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003679 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003680
3681 EXPECT_GL_NO_ERROR();
3682
3683 drawQuad(mProgram, "position", 0.5f);
3684
Geoff Langf607c602016-09-21 11:46:48 -04003685 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
Jamie Madill50cf2be2018-06-15 09:46:57 -04003686 EXPECT_PIXEL_COLOR_EQ(0, 0,
3687 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3688 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003689
3690 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3691 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3692 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3693 mRenderbuffer);
3694 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3695 EXPECT_GL_NO_ERROR();
3696
3697 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3698 glClear(GL_COLOR_BUFFER_BIT);
3699
3700 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3701
Geoff Langf607c602016-09-21 11:46:48 -04003702 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003703
3704 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3705
3706 ASSERT_GL_NO_ERROR();
3707 }
3708
3709 GLuint mTextures[3];
3710 GLuint mFBO;
3711 GLuint mRenderbuffer;
3712};
3713
3714// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3715TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3716{
Yunchao He9550c602018-02-13 14:47:05 +08003717 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02003718
3719 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3720 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3721 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3722 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3723 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3724 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3725 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3726 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3727
3728 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3729 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3730 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3731}
3732
Olli Etuaho95faa232016-06-07 14:01:53 -07003733// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3734// GLES 3.0.4 section 3.8.3.
3735TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3736{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003737 // Crashes on Nexus 5X due to a driver bug. http://anglebug.com/1429
3738 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07003739
3740 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3741 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3742 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3743 ASSERT_GL_NO_ERROR();
3744
3745 // SKIP_IMAGES should not have an effect on uploading 2D textures
3746 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3747 ASSERT_GL_NO_ERROR();
3748
3749 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3750
3751 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3752 pixelsGreen.data());
3753 ASSERT_GL_NO_ERROR();
3754
3755 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3756 pixelsGreen.data());
3757 ASSERT_GL_NO_ERROR();
3758
3759 glUseProgram(mProgram);
3760 drawQuad(mProgram, "position", 0.5f);
3761 ASSERT_GL_NO_ERROR();
3762
3763 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3764}
3765
Olli Etuaho989cac32016-06-08 16:18:49 -07003766// Test that skip defined in unpack parameters is taken into account when determining whether
3767// unpacking source extends outside unpack buffer bounds.
3768TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3769{
3770 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3771 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3772 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3773 ASSERT_GL_NO_ERROR();
3774
3775 GLBuffer buf;
3776 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3777 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3778 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3779 GL_DYNAMIC_COPY);
3780 ASSERT_GL_NO_ERROR();
3781
3782 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3783 ASSERT_GL_NO_ERROR();
3784
3785 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3786 ASSERT_GL_NO_ERROR();
3787
3788 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3789 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3790
3791 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3792 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3793 ASSERT_GL_NO_ERROR();
3794
3795 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3796 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3797}
3798
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003799// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3800TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3801{
Yunchao He9550c602018-02-13 14:47:05 +08003802 ANGLE_SKIP_TEST_IF(IsD3D11());
3803
3804 // Incorrect rendering results seen on OSX AMD.
3805 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003806
3807 const GLuint width = 8u;
3808 const GLuint height = 8u;
3809 const GLuint unpackRowLength = 5u;
3810 const GLuint unpackSkipPixels = 1u;
3811
3812 setWindowWidth(width);
3813 setWindowHeight(height);
3814
3815 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3816 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3817 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3818 ASSERT_GL_NO_ERROR();
3819
3820 GLBuffer buf;
3821 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3822 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3823 GLColor::green);
3824
3825 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3826 {
3827 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3828 }
3829
3830 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3831 GL_DYNAMIC_COPY);
3832 ASSERT_GL_NO_ERROR();
3833
3834 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3835 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3836 ASSERT_GL_NO_ERROR();
3837
3838 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3839 ASSERT_GL_NO_ERROR();
3840
3841 glUseProgram(mProgram);
3842 drawQuad(mProgram, "position", 0.5f);
3843 ASSERT_GL_NO_ERROR();
3844
3845 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3846 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3847 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3848 actual.data());
3849 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3850 EXPECT_EQ(expected, actual);
3851}
3852
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003853template <typename T>
3854T UNorm(double value)
3855{
3856 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3857}
3858
3859// Test rendering a depth texture with mipmaps.
3860TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3861{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003862 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3863 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
Jiawei Shaoaf0f31d2018-09-27 15:42:31 +08003864 // http://anglebug.com/1706
3865 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Corentin Walleze731d8a2016-09-07 10:56:25 -04003866
Jamie Madill24980272019-04-03 09:03:51 -04003867 // Seems to fail on AMD D3D11. Possibly driver bug. http://anglebug.com/3342
3868 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsD3D11());
3869
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003870 const int size = getWindowWidth();
3871
3872 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003873 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003874
3875 glActiveTexture(GL_TEXTURE0);
3876 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3877 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3878 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3879 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3880 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3881 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3882 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3883 ASSERT_GL_NO_ERROR();
3884
3885 glUseProgram(mProgram);
3886 glUniform1i(mTexture2DUniformLocation, 0);
3887
3888 std::vector<unsigned char> expected;
3889
3890 for (int level = 0; level < levels; ++level)
3891 {
3892 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3893 expected.push_back(UNorm<unsigned char>(value));
3894
3895 int levelDim = dim(level);
3896
3897 ASSERT_GT(levelDim, 0);
3898
3899 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3900 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3901 GL_UNSIGNED_INT, initData.data());
3902 }
3903 ASSERT_GL_NO_ERROR();
3904
3905 for (int level = 0; level < levels; ++level)
3906 {
3907 glViewport(0, 0, dim(level), dim(level));
3908 drawQuad(mProgram, "position", 0.5f);
3909 GLColor actual = ReadColor(0, 0);
3910 EXPECT_NEAR(expected[level], actual.R, 10u);
3911 }
3912
3913 ASSERT_GL_NO_ERROR();
3914}
3915
Jamie Madill7ffdda92016-09-08 13:26:51 -04003916// Tests unpacking into the unsized GL_ALPHA format.
3917TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3918{
Jamie Madill7ffdda92016-09-08 13:26:51 -04003919 // Initialize the texure.
3920 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3921 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3922 GL_UNSIGNED_BYTE, nullptr);
3923 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3924 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3925
3926 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3927
3928 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04003929 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04003930 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3931 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3932 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
3933 GL_STATIC_DRAW);
3934
3935 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
3936 GL_UNSIGNED_BYTE, nullptr);
3937
3938 // Clear to a weird color to make sure we're drawing something.
3939 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
3940 glClear(GL_COLOR_BUFFER_BIT);
3941
3942 // Draw with the alpha texture and verify.
3943 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04003944
3945 ASSERT_GL_NO_ERROR();
3946 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
3947}
3948
Jamie Madill2e600342016-09-19 13:56:40 -04003949// Ensure stale unpack data doesn't propagate in D3D11.
3950TEST_P(Texture2DTestES3, StaleUnpackData)
3951{
3952 // Init unpack buffer.
3953 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
3954 std::vector<GLColor> pixels(pixelCount, GLColor::red);
3955
3956 GLBuffer unpackBuffer;
3957 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3958 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3959 GLsizei bufferSize = pixelCount * sizeof(GLColor);
3960 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
3961
3962 // Create from unpack buffer.
3963 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3964 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
3965 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3966 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3967 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3968
3969 drawQuad(mProgram, "position", 0.5f);
3970
3971 ASSERT_GL_NO_ERROR();
3972 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3973
3974 // Fill unpack with green, recreating buffer.
3975 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
3976 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
3977 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
3978
3979 // Reinit texture with green.
3980 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
3981 GL_UNSIGNED_BYTE, nullptr);
3982
3983 drawQuad(mProgram, "position", 0.5f);
3984
3985 ASSERT_GL_NO_ERROR();
3986 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3987}
3988
Geoff Langfb7685f2017-11-13 11:44:11 -05003989// Ensure that texture parameters passed as floats that are converted to ints are rounded before
3990// validating they are less than 0.
3991TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
3992{
3993 GLTexture texture;
3994 glBindTexture(GL_TEXTURE_2D, texture);
3995
3996 // Use a negative number that will round to zero when converted to an integer
3997 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
3998 // "Validation of values performed by state-setting commands is performed after conversion,
3999 // unless specified otherwise for a specific command."
4000 GLfloat param = -7.30157126e-07f;
4001 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
4002 EXPECT_GL_NO_ERROR();
4003
4004 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
4005 EXPECT_GL_NO_ERROR();
4006}
4007
Jamie Madillf097e232016-11-05 00:44:15 -04004008// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
4009// being properly checked, and the texture storage of the previous texture format was persisting.
4010// This would result in an ASSERT in debug and incorrect rendering in release.
4011// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
4012TEST_P(Texture3DTestES3, FormatRedefinitionBug)
4013{
4014 GLTexture tex;
4015 glBindTexture(GL_TEXTURE_3D, tex.get());
4016 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4017
4018 GLFramebuffer framebuffer;
4019 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
4020 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
4021
4022 glCheckFramebufferStatus(GL_FRAMEBUFFER);
4023
4024 std::vector<uint8_t> pixelData(100, 0);
4025
4026 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
4027 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
4028 pixelData.data());
4029
4030 ASSERT_GL_NO_ERROR();
4031}
4032
Corentin Wallezd2627992017-04-28 17:17:03 -04004033// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
4034TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
4035{
4036 // 2D tests
4037 {
4038 GLTexture tex;
4039 glBindTexture(GL_TEXTURE_2D, tex.get());
4040
4041 GLBuffer pbo;
4042 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4043
4044 // Test OOB
4045 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
4046 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4047 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4048
4049 // Test OOB
4050 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
4051 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4052 ASSERT_GL_NO_ERROR();
4053 }
4054
4055 // 3D tests
4056 {
4057 GLTexture tex;
4058 glBindTexture(GL_TEXTURE_3D, tex.get());
4059
4060 GLBuffer pbo;
4061 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4062
4063 // Test OOB
4064 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
4065 GL_STATIC_DRAW);
4066 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4067 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4068
4069 // Test OOB
4070 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
4071 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4072 ASSERT_GL_NO_ERROR();
4073 }
4074}
4075
Jamie Madill3ed60422017-09-07 11:32:52 -04004076// Tests behaviour with a single texture and multiple sampler objects.
4077TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
4078{
4079 GLint maxTextureUnits = 0;
4080 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
4081 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
4082
4083 constexpr int kSize = 16;
4084
4085 // Make a single-level texture, fill it with red.
4086 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
4087 GLTexture tex;
4088 glBindTexture(GL_TEXTURE_2D, tex);
4089 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4090 redColors.data());
4091 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4092 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4093
4094 // Simple sanity check.
4095 draw2DTexturedQuad(0.5f, 1.0f, true);
4096 ASSERT_GL_NO_ERROR();
4097 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4098
4099 // Bind texture to unit 1 with a sampler object making it incomplete.
4100 GLSampler sampler;
4101 glBindSampler(0, sampler);
4102 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4103 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4104
4105 // Make a mipmap texture, fill it with blue.
4106 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
4107 GLTexture mipmapTex;
4108 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4109 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4110 blueColors.data());
4111 glGenerateMipmap(GL_TEXTURE_2D);
4112
4113 // Draw with the sampler, expect blue.
4114 draw2DTexturedQuad(0.5f, 1.0f, true);
4115 ASSERT_GL_NO_ERROR();
4116 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
4117
4118 // Simple multitexturing program.
Jamie Madill35cd7332018-12-02 12:03:33 -05004119 constexpr char kVS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004120 "#version 300 es\n"
4121 "in vec2 position;\n"
4122 "out vec2 texCoord;\n"
4123 "void main()\n"
4124 "{\n"
4125 " gl_Position = vec4(position, 0, 1);\n"
4126 " texCoord = position * 0.5 + vec2(0.5);\n"
4127 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05004128
4129 constexpr char kFS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004130 "#version 300 es\n"
4131 "precision mediump float;\n"
4132 "in vec2 texCoord;\n"
4133 "uniform sampler2D tex1;\n"
4134 "uniform sampler2D tex2;\n"
4135 "uniform sampler2D tex3;\n"
4136 "uniform sampler2D tex4;\n"
4137 "out vec4 color;\n"
4138 "void main()\n"
4139 "{\n"
4140 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
4141 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
4142 "}";
4143
Jamie Madill35cd7332018-12-02 12:03:33 -05004144 ANGLE_GL_PROGRAM(program, kVS, kFS);
Jamie Madill3ed60422017-09-07 11:32:52 -04004145
4146 std::array<GLint, 4> texLocations = {
4147 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
4148 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
4149 for (GLint location : texLocations)
4150 {
4151 ASSERT_NE(-1, location);
4152 }
4153
4154 // Init the uniform data.
4155 glUseProgram(program);
4156 for (GLint location = 0; location < 4; ++location)
4157 {
4158 glUniform1i(texLocations[location], location);
4159 }
4160
4161 // Initialize four samplers
4162 GLSampler samplers[4];
4163
4164 // 0: non-mipped.
4165 glBindSampler(0, samplers[0]);
4166 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4167 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4168
4169 // 1: mipped.
4170 glBindSampler(1, samplers[1]);
4171 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4172 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4173
4174 // 2: non-mipped.
4175 glBindSampler(2, samplers[2]);
4176 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4177 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4178
4179 // 3: mipped.
4180 glBindSampler(3, samplers[3]);
4181 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4182 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4183
4184 // Bind two blue mipped textures and two single layer textures, should all draw.
4185 glActiveTexture(GL_TEXTURE0);
4186 glBindTexture(GL_TEXTURE_2D, tex);
4187
4188 glActiveTexture(GL_TEXTURE1);
4189 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4190
4191 glActiveTexture(GL_TEXTURE2);
4192 glBindTexture(GL_TEXTURE_2D, tex);
4193
4194 glActiveTexture(GL_TEXTURE3);
4195 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4196
4197 ASSERT_GL_NO_ERROR();
4198
4199 drawQuad(program, "position", 0.5f);
4200 ASSERT_GL_NO_ERROR();
4201 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
4202
4203 // Bind four single layer textures, two should be incomplete.
4204 glActiveTexture(GL_TEXTURE1);
4205 glBindTexture(GL_TEXTURE_2D, tex);
4206
4207 glActiveTexture(GL_TEXTURE3);
4208 glBindTexture(GL_TEXTURE_2D, tex);
4209
4210 drawQuad(program, "position", 0.5f);
4211 ASSERT_GL_NO_ERROR();
4212 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
4213}
4214
Martin Radev7e2c0d32017-09-15 14:25:42 +03004215// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
4216// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
4217// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
4218// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
4219// samples the cubemap using a direction vector (1,1,1).
4220TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
4221{
Yunchao He2f23f352018-02-11 22:11:37 +08004222 // Check http://anglebug.com/2155.
4223 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
4224
Jamie Madill35cd7332018-12-02 12:03:33 -05004225 constexpr char kVS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004226 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004227 precision mediump float;
4228 in vec3 pos;
4229 void main() {
4230 gl_Position = vec4(pos, 1.0);
4231 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03004232
Jamie Madill35cd7332018-12-02 12:03:33 -05004233 constexpr char kFS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004234 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004235 precision mediump float;
4236 out vec4 color;
4237 uniform samplerCube uTex;
4238 void main(){
4239 color = texture(uTex, vec3(1.0));
4240 })";
Jamie Madill35cd7332018-12-02 12:03:33 -05004241
4242 ANGLE_GL_PROGRAM(program, kVS, kFS);
Martin Radev7e2c0d32017-09-15 14:25:42 +03004243 glUseProgram(program);
4244
4245 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
4246 glActiveTexture(GL_TEXTURE0);
4247
4248 GLTexture cubeTex;
4249 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
4250
4251 const int kFaceWidth = 1;
4252 const int kFaceHeight = 1;
4253 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
4254 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4255 GL_UNSIGNED_BYTE, texData.data());
4256 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4257 GL_UNSIGNED_BYTE, texData.data());
4258 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4259 GL_UNSIGNED_BYTE, texData.data());
4260 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4261 GL_UNSIGNED_BYTE, texData.data());
4262 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4263 GL_UNSIGNED_BYTE, texData.data());
4264 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4265 GL_UNSIGNED_BYTE, texData.data());
4266 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4267 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4268 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
4269 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
4270 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
4271 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
4272
4273 drawQuad(program, "pos", 0.5f, 1.0f, true);
4274 ASSERT_GL_NO_ERROR();
4275
4276 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4277}
4278
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08004279// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
4280TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
4281{
4282 GLuint texture = create2DTexture();
4283
4284 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
4285 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4286
4287 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
4288 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4289
4290 glDeleteTextures(1, &texture);
4291 EXPECT_GL_NO_ERROR();
4292}
4293
Olli Etuaho023371b2018-04-24 17:43:32 +03004294// Test setting base level after calling generateMipmap on a LUMA texture.
4295// Covers http://anglebug.com/2498
4296TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA)
4297{
4298 glActiveTexture(GL_TEXTURE0);
4299 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4300
4301 constexpr const GLsizei kWidth = 8;
4302 constexpr const GLsizei kHeight = 8;
4303 std::array<GLubyte, kWidth * kHeight * 2> whiteData;
4304 whiteData.fill(255u);
4305
4306 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA,
4307 GL_UNSIGNED_BYTE, whiteData.data());
4308 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
4309 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4310 glGenerateMipmap(GL_TEXTURE_2D);
4311 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
4312 EXPECT_GL_NO_ERROR();
4313
4314 drawQuad(mProgram, "position", 0.5f);
4315 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4316}
4317
Till Rathmannc1551dc2018-08-15 17:04:49 +02004318// Covers a bug in the D3D11 backend: http://anglebug.com/2772
4319// When using a sampler the texture was created as if it has mipmaps,
4320// regardless what you specified in GL_TEXTURE_MIN_FILTER via
4321// glSamplerParameteri() -- mistakenly the default value
4322// GL_NEAREST_MIPMAP_LINEAR or the value set via glTexParameteri() was
4323// evaluated.
4324// If you didn't provide mipmaps and didn't let the driver generate them
4325// this led to not sampling your texture data when minification occurred.
4326TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping)
4327{
Jamie Madill35cd7332018-12-02 12:03:33 -05004328 constexpr char kVS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004329 "#version 300 es\n"
4330 "out vec2 texcoord;\n"
4331 "in vec4 position;\n"
4332 "void main()\n"
4333 "{\n"
4334 " gl_Position = vec4(position.xy * 0.1, 0.0, 1.0);\n"
4335 " texcoord = (position.xy * 0.5) + 0.5;\n"
4336 "}\n";
4337
Jamie Madill35cd7332018-12-02 12:03:33 -05004338 constexpr char kFS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004339 "#version 300 es\n"
4340 "precision highp float;\n"
4341 "uniform highp sampler2D tex;\n"
4342 "in vec2 texcoord;\n"
4343 "out vec4 fragColor;\n"
4344 "void main()\n"
4345 "{\n"
4346 " fragColor = texture(tex, texcoord);\n"
4347 "}\n";
Jamie Madill35cd7332018-12-02 12:03:33 -05004348
4349 ANGLE_GL_PROGRAM(program, kVS, kFS);
Till Rathmannc1551dc2018-08-15 17:04:49 +02004350
4351 GLSampler sampler;
4352 glBindSampler(0, sampler);
4353 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4354 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4355
4356 glActiveTexture(GL_TEXTURE0);
4357 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4358
4359 const GLsizei texWidth = getWindowWidth();
4360 const GLsizei texHeight = getWindowHeight();
4361 const std::vector<GLColor> whiteData(texWidth * texHeight, GLColor::white);
4362
4363 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4364 whiteData.data());
4365 EXPECT_GL_NO_ERROR();
4366
4367 drawQuad(program, "position", 0.5f);
4368 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, angle::GLColor::white);
4369}
4370
Jamie Madill50cf2be2018-06-15 09:46:57 -04004371// Use this to select which configurations (e.g. which renderer, which GLES major version) these
4372// tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -05004373ANGLE_INSTANTIATE_TEST(Texture2DTest,
4374 ES2_D3D9(),
4375 ES2_D3D11(),
4376 ES2_D3D11_FL9_3(),
4377 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05004378 ES2_OPENGLES(),
4379 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004380ANGLE_INSTANTIATE_TEST(TextureCubeTest,
4381 ES2_D3D9(),
4382 ES2_D3D11(),
Geoff Langf7480ad2017-10-24 11:46:02 -04004383 ES2_D3D11_FL10_0(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004384 ES2_D3D11_FL9_3(),
4385 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004386 ES2_OPENGLES(),
4387 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004388ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
4389 ES2_D3D9(),
4390 ES2_D3D11(),
4391 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004392 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004393 ES2_OPENGLES(),
4394 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004395ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
4396 ES2_D3D9(),
4397 ES2_D3D11(),
4398 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004399 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004400 ES2_OPENGLES(),
4401 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004402ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
4403 ES2_D3D9(),
4404 ES2_D3D11(),
4405 ES2_D3D11_FL9_3(),
4406 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004407 ES2_OPENGLES(),
4408 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004409ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
4410 ES2_D3D9(),
4411 ES2_D3D11(),
4412 ES2_D3D11_FL9_3(),
4413 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004414 ES2_OPENGLES(),
4415 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004416ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02004417ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02004418ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4419ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
4420 ES3_D3D11(),
4421 ES3_OPENGL(),
4422 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004423ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
4424 ES3_D3D11(),
4425 ES3_OPENGL(),
4426 ES3_OPENGLES());
4427ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4428ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02004429ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02004430ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
4431 ES2_D3D11(),
4432 ES2_D3D11_FL9_3(),
4433 ES2_D3D9(),
4434 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004435 ES2_OPENGLES(),
4436 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004437ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
4438 ES2_D3D11(),
4439 ES2_D3D11_FL9_3(),
4440 ES2_D3D9(),
4441 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004442 ES2_OPENGLES(),
4443 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004444ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
4445 ES2_D3D11(),
4446 ES2_D3D11_FL9_3(),
4447 ES2_D3D9(),
4448 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004449 ES2_OPENGLES(),
4450 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004451ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
4452 ES2_D3D11(),
4453 ES2_D3D11_FL9_3(),
4454 ES2_D3D9(),
4455 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004456 ES2_OPENGLES(),
4457 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004458ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
4459 ES2_D3D11(),
4460 ES2_D3D11_FL9_3(),
4461 ES2_D3D9(),
4462 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004463 ES2_OPENGLES(),
4464 ES2_VULKAN());
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05004465ANGLE_INSTANTIATE_TEST(TextureAnisotropyTest,
4466 ES2_D3D11(),
4467 ES2_D3D9(),
4468 ES2_OPENGL(),
4469 ES2_OPENGLES(),
4470 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02004471ANGLE_INSTANTIATE_TEST(TextureBorderClampTest,
4472 ES2_D3D11(),
4473 ES2_D3D9(),
4474 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004475 ES2_OPENGLES(),
4476 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02004477ANGLE_INSTANTIATE_TEST(TextureBorderClampTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4478ANGLE_INSTANTIATE_TEST(TextureBorderClampIntegerTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Luc Ferronaf883622018-06-08 15:57:31 -04004479ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN());
Vincent Lang25ab4512016-05-13 18:13:59 +02004480ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03004481ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04004482
Jamie Madill7ffdda92016-09-08 13:26:51 -04004483} // anonymous namespace