blob: a4b292e9d0ff813a12eb3b1a34167f7c4f1d71fb [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 {
Jamie Madillb8149072019-04-30 16:14:44 -0400179 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_storage") ||
180 !IsGLExtensionEnabled("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) &&
Jamie Madillb8149072019-04-30 16:14:44 -0400183 !IsGLExtensionEnabled("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 &&
Jamie Madillb8149072019-04-30 16:14:44 -0400186 !IsGLExtensionEnabled("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 &&
Jamie Madillb8149072019-04-30 16:14:44 -0400189 !IsGLExtensionEnabled("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 {
Jamie Madillb8149072019-04-30 16:14:44 -0400195 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("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 &&
Jamie Madillb8149072019-04-30 16:14:44 -0400198 !IsGLExtensionEnabled("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
Jamie Madillb8149072019-04-30 16:14:44 -0400267 if (sourceImageChannels < 3 && !IsGLExtensionEnabled("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
Anders Leinof6cbe442019-04-18 15:32:07 +03001155class Texture2DIntegerTestES3 : public Texture2DTest
1156{
1157 protected:
1158 Texture2DIntegerTestES3() : Texture2DTest() {}
1159
1160 const char *getVertexShaderSource() override
1161 {
1162 return "#version 300 es\n"
1163 "out vec2 texcoord;\n"
1164 "in vec4 position;\n"
1165 "void main()\n"
1166 "{\n"
1167 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1168 " texcoord = (position.xy * 0.5) + 0.5;\n"
1169 "}\n";
1170 }
1171
1172 const char *getFragmentShaderSource() override
1173 {
1174 return "#version 300 es\n"
1175 "precision highp float;\n"
1176 "precision highp usampler2D;\n"
1177 "uniform usampler2D tex;\n"
1178 "in vec2 texcoord;\n"
1179 "out vec4 fragColor;\n"
1180 "void main()\n"
1181 "{\n"
1182 " fragColor = vec4(texture(tex, texcoord));\n"
1183 "}\n";
1184 }
1185};
1186
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001187TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001188{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001189 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001190 EXPECT_GL_ERROR(GL_NO_ERROR);
1191
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001192 setUpProgram();
1193
Jamie Madill50cf2be2018-06-15 09:46:57 -04001194 const GLubyte *pixels[20] = {0};
Jamie Madillf67115c2014-04-22 13:14:05 -04001195 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1196 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001197
Jamie Madillb8149072019-04-30 16:14:44 -04001198 if (IsGLExtensionEnabled("GL_EXT_texture_storage"))
Geoff Langc51642b2016-11-14 16:18:26 -05001199 {
1200 // Create a 1-level immutable texture.
1201 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1202
1203 // Try calling sub image on the second level.
1204 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1205 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1206 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001207}
Geoff Langc41e42d2014-04-28 10:58:16 -04001208
John Bauman18319182016-09-28 14:22:27 -07001209// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1210TEST_P(Texture2DTest, QueryBinding)
1211{
1212 glBindTexture(GL_TEXTURE_2D, 0);
1213 EXPECT_GL_ERROR(GL_NO_ERROR);
1214
1215 GLint textureBinding;
1216 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1217 EXPECT_GL_NO_ERROR();
1218 EXPECT_EQ(0, textureBinding);
1219
1220 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
Jamie Madillb8149072019-04-30 16:14:44 -04001221 if (IsGLExtensionEnabled("GL_OES_EGL_image_external") ||
1222 IsGLExtensionEnabled("GL_NV_EGL_stream_consumer_external"))
John Bauman18319182016-09-28 14:22:27 -07001223 {
1224 EXPECT_GL_NO_ERROR();
1225 EXPECT_EQ(0, textureBinding);
1226 }
1227 else
1228 {
1229 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1230 }
1231}
1232
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001233TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001234{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001235 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001236 EXPECT_GL_ERROR(GL_NO_ERROR);
1237
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001238 setUpProgram();
1239
Geoff Langc41e42d2014-04-28 10:58:16 -04001240 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001241 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001242 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001243 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001244
Jamie Madill50cf2be2018-06-15 09:46:57 -04001245 const GLubyte *pixel[4] = {0};
Geoff Langc41e42d2014-04-28 10:58:16 -04001246
1247 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1248 EXPECT_GL_NO_ERROR();
1249
1250 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1251 EXPECT_GL_NO_ERROR();
1252
1253 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1254 EXPECT_GL_NO_ERROR();
1255}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001256
1257// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001258TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001259{
1260 glActiveTexture(GL_TEXTURE0);
1261 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1262 glActiveTexture(GL_TEXTURE1);
1263 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1264 EXPECT_GL_ERROR(GL_NO_ERROR);
1265
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001266 glUseProgram(mProgram);
1267 glUniform1i(mTexture2DUniformLocation, 0);
1268 glUniform1i(mTextureCubeUniformLocation, 1);
1269 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001270 EXPECT_GL_NO_ERROR();
1271}
Jamie Madill9aca0592014-10-06 16:26:59 -04001272
Olli Etuaho53a2da12016-01-11 15:43:32 +02001273// Test drawing with two texture types accessed from the same shader and check that the result of
1274// drawing is correct.
1275TEST_P(TextureCubeTest, CubeMapDraw)
1276{
1277 GLubyte texData[4];
1278 texData[0] = 0;
1279 texData[1] = 60;
1280 texData[2] = 0;
1281 texData[3] = 255;
1282
1283 glActiveTexture(GL_TEXTURE0);
1284 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1285 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1286
1287 glActiveTexture(GL_TEXTURE1);
1288 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1289 texData[1] = 120;
1290 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1291 texData);
1292 EXPECT_GL_ERROR(GL_NO_ERROR);
1293
1294 glUseProgram(mProgram);
1295 glUniform1i(mTexture2DUniformLocation, 0);
1296 glUniform1i(mTextureCubeUniformLocation, 1);
1297 drawQuad(mProgram, "position", 0.5f);
1298 EXPECT_GL_NO_ERROR();
1299
1300 int px = getWindowWidth() - 1;
1301 int py = 0;
1302 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1303}
1304
Olli Etuaho4644a202016-01-12 15:12:53 +02001305TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1306{
1307 glActiveTexture(GL_TEXTURE0);
1308 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1309 GLubyte texData[4];
1310 texData[0] = 0;
1311 texData[1] = 128;
1312 texData[2] = 0;
1313 texData[3] = 255;
1314 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1315 glUseProgram(mProgram);
1316 glUniform1i(mTexture2DUniformLocation, 0);
1317 drawQuad(mProgram, "position", 0.5f);
1318 EXPECT_GL_NO_ERROR();
1319
1320 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1321}
1322
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001323// Test drawing with two textures passed to the shader in a sampler array.
1324TEST_P(SamplerArrayTest, SamplerArrayDraw)
1325{
1326 testSamplerArrayDraw();
1327}
1328
1329// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1330// user-defined function in the shader.
1331TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1332{
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05001333 // TODO: Diagnose and fix. http://anglebug.com/2955
1334 ANGLE_SKIP_TEST_IF(IsVulkan() && IsAndroid());
1335
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001336 testSamplerArrayDraw();
1337}
1338
Jamie Madill9aca0592014-10-06 16:26:59 -04001339// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001340TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001341{
1342 int px = getWindowWidth() / 2;
1343 int py = getWindowHeight() / 2;
1344
1345 glActiveTexture(GL_TEXTURE0);
1346 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1347
Olli Etuahoa314b612016-03-10 16:43:00 +02001348 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001349
Olli Etuahoa314b612016-03-10 16:43:00 +02001350 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001351 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1352 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1353 glGenerateMipmap(GL_TEXTURE_2D);
1354
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001355 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001356 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001357 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1358 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001359 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001360 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001361
Olli Etuahoa314b612016-03-10 16:43:00 +02001362 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001363
Olli Etuahoa314b612016-03-10 16:43:00 +02001364 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1365 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001366 glGenerateMipmap(GL_TEXTURE_2D);
1367
Olli Etuahoa314b612016-03-10 16:43:00 +02001368 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001369
Olli Etuahoa314b612016-03-10 16:43:00 +02001370 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1371 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001372 glGenerateMipmap(GL_TEXTURE_2D);
1373
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001374 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001375
1376 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001377 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001378}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001379
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001380// Test creating a FBO with a cube map render target, to test an ANGLE bug
1381// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001382TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001383{
Michael Spangd8506c72019-01-29 15:35:09 -05001384 // http://anglebug.com/3145
1385 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
1386
Shahbaz Youssefi0c128e12019-03-25 23:50:14 -04001387 // http://anglebug.com/2822
1388 ANGLE_SKIP_TEST_IF(IsWindows() && IsIntel() && IsVulkan());
1389
Jamie Madill3f3b3582018-09-14 10:38:44 -04001390 GLFramebuffer fbo;
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001391 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1392
1393 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Jamie Madill50cf2be2018-06-15 09:46:57 -04001394 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1395 mTextureCube, 0);
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001396
Corentin Wallez322653b2015-06-17 18:33:56 +02001397 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001398 EXPECT_GL_NO_ERROR();
Jamie Madill3f3b3582018-09-14 10:38:44 -04001399
1400 // Test clearing the six mip faces individually.
1401 std::array<GLColor, 6> faceColors = {{GLColor::red, GLColor::green, GLColor::blue,
1402 GLColor::yellow, GLColor::cyan, GLColor::magenta}};
1403
1404 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1405 {
1406 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1407 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1408
1409 Vector4 clearColorF = faceColors[faceIndex].toNormalizedVector();
1410 glClearColor(clearColorF.x(), clearColorF.y(), clearColorF.z(), clearColorF.w());
1411 glClear(GL_COLOR_BUFFER_BIT);
1412
1413 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex]);
1414 }
1415
1416 // Iterate the faces again to make sure the colors haven't changed.
1417 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1418 {
1419 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1420 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1421 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex])
1422 << "face color " << faceIndex << " shouldn't change";
1423 }
1424}
1425
1426// Tests clearing a cube map with a scissor enabled.
1427TEST_P(TextureCubeTest, CubeMapFBOScissoredClear)
1428{
1429 // TODO(jie.a.chen): Diagnose and fix. http://anglebug.com/2822
1430 ANGLE_SKIP_TEST_IF(IsVulkan() && IsIntel() && IsWindows());
1431
Michael Spangd8506c72019-01-29 15:35:09 -05001432 // http://anglebug.com/3145
1433 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
1434
Jamie Madill3f3b3582018-09-14 10:38:44 -04001435 constexpr size_t kSize = 16;
1436
1437 GLFramebuffer fbo;
1438 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1439 glViewport(0, 0, kSize, kSize);
1440
1441 GLTexture texcube;
1442 glBindTexture(GL_TEXTURE_CUBE_MAP, texcube);
1443 for (GLenum face = 0; face < 6; face++)
1444 {
1445 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA,
1446 GL_UNSIGNED_BYTE, nullptr);
1447 }
1448 ASSERT_GL_NO_ERROR();
1449
1450 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1451 texcube, 0);
1452
1453 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1454 ASSERT_GL_NO_ERROR();
1455
1456 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1457 glClear(GL_COLOR_BUFFER_BIT);
1458 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1459
1460 glEnable(GL_SCISSOR_TEST);
1461 glScissor(kSize / 2, 0, kSize / 2, kSize);
1462 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
1463 glClear(GL_COLOR_BUFFER_BIT);
1464
1465 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1466 EXPECT_PIXEL_COLOR_EQ(kSize / 2 + 1, 0, GLColor::green);
1467
1468 ASSERT_GL_NO_ERROR();
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001469}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001470
Jamie Madill50cf2be2018-06-15 09:46:57 -04001471// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a
1472// default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001473TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001474{
Jamie Madillb8149072019-04-30 16:14:44 -04001475 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 &&
1476 !IsGLExtensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -04001477
Jamie Madill50cf2be2018-06-15 09:46:57 -04001478 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001479 int height = getWindowHeight();
1480
1481 GLuint tex2D;
1482 glGenTextures(1, &tex2D);
1483 glActiveTexture(GL_TEXTURE0);
1484 glBindTexture(GL_TEXTURE_2D, tex2D);
1485
1486 // Fill with red
1487 std::vector<GLubyte> pixels(3 * 16 * 16);
1488 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1489 {
1490 pixels[pixelId * 3 + 0] = 255;
1491 pixels[pixelId * 3 + 1] = 0;
1492 pixels[pixelId * 3 + 2] = 0;
1493 }
1494
1495 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001496 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1497 // 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 -04001498 if (getClientMajorVersion() >= 3)
1499 {
1500 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1501 }
1502 else
1503 {
1504 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1505 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001506
1507 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1508 // glTexSubImage2D should take into account that the image is dirty.
1509 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1510 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1511 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1512
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001513 setUpProgram();
1514
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001515 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001516 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001517 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001518 glDeleteTextures(1, &tex2D);
1519 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001520 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001521
1522 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001523 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1524 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001525}
1526
Jamie Madill50cf2be2018-06-15 09:46:57 -04001527// Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has
1528// initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001529TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001530{
Jamie Madillb8149072019-04-30 16:14:44 -04001531 if (IsGLExtensionEnabled("NV_pixel_buffer_object"))
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001532 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04001533 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001534 int height = getWindowHeight();
1535
1536 GLuint tex2D;
1537 glGenTextures(1, &tex2D);
1538 glActiveTexture(GL_TEXTURE0);
1539 glBindTexture(GL_TEXTURE_2D, tex2D);
1540
1541 // Fill with red
1542 std::vector<GLubyte> pixels(3 * 16 * 16);
1543 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1544 {
1545 pixels[pixelId * 3 + 0] = 255;
1546 pixels[pixelId * 3 + 1] = 0;
1547 pixels[pixelId * 3 + 2] = 0;
1548 }
1549
1550 // Read 16x16 region from red backbuffer to PBO
1551 GLuint pbo;
1552 glGenBuffers(1, &pbo);
1553 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1554 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1555
1556 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001557 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1558 // 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 +00001559 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1560
1561 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1562 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001563 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 +00001564 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1565 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1566
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001567 setUpProgram();
1568
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001569 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001570 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001571 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001572 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001573 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001574 EXPECT_GL_NO_ERROR();
1575 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1576 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1577 }
1578}
Jamie Madillbc393df2015-01-29 13:46:07 -05001579
1580// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001581TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001582{
1583 testFloatCopySubImage(1, 1);
1584}
1585
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001586TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001587{
1588 testFloatCopySubImage(2, 1);
1589}
1590
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001591TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001592{
1593 testFloatCopySubImage(2, 2);
1594}
1595
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001596TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001597{
1598 testFloatCopySubImage(3, 1);
1599}
1600
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001601TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001602{
1603 testFloatCopySubImage(3, 2);
1604}
1605
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001606TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001607{
Yunchao He9550c602018-02-13 14:47:05 +08001608 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1609 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001610
Yunchao He9550c602018-02-13 14:47:05 +08001611 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1612 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001613
Jamie Madillbc393df2015-01-29 13:46:07 -05001614 testFloatCopySubImage(3, 3);
1615}
1616
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001617TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001618{
1619 testFloatCopySubImage(4, 1);
1620}
1621
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001622TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001623{
1624 testFloatCopySubImage(4, 2);
1625}
1626
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001627TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001628{
Yunchao He9550c602018-02-13 14:47:05 +08001629 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1630 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001631
Jamie Madillbc393df2015-01-29 13:46:07 -05001632 testFloatCopySubImage(4, 3);
1633}
1634
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001635TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001636{
Luc Ferronf786b702018-07-10 11:01:43 -04001637 // TODO(lucferron): This test fails only on linux and intel.
1638 // http://anglebug.com/2726
1639 ANGLE_SKIP_TEST_IF(IsVulkan() && IsLinux() && IsIntel());
1640
Yunchao He9550c602018-02-13 14:47:05 +08001641 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1642 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001643
Jamie Madillbc393df2015-01-29 13:46:07 -05001644 testFloatCopySubImage(4, 4);
1645}
Austin Kinross07285142015-03-26 11:36:16 -07001646
Jamie Madill50cf2be2018-06-15 09:46:57 -04001647// Port of
1648// https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1649// Run against GL_ALPHA/UNSIGNED_BYTE format, to ensure that D3D11 Feature Level 9_3 correctly
1650// handles GL_ALPHA
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001651TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001652{
1653 const int npotTexSize = 5;
Jamie Madill50cf2be2018-06-15 09:46:57 -04001654 const int potTexSize = 4; // Should be less than npotTexSize
Austin Kinross07285142015-03-26 11:36:16 -07001655 GLuint tex2D;
1656
Jamie Madillb8149072019-04-30 16:14:44 -04001657 if (IsGLExtensionEnabled("GL_OES_texture_npot"))
Austin Kinross07285142015-03-26 11:36:16 -07001658 {
1659 // This test isn't applicable if texture_npot is enabled
1660 return;
1661 }
1662
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001663 setUpProgram();
1664
Austin Kinross07285142015-03-26 11:36:16 -07001665 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1666
Austin Kinross5faa15b2016-01-11 13:32:48 -08001667 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1668 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1669
Austin Kinross07285142015-03-26 11:36:16 -07001670 glActiveTexture(GL_TEXTURE0);
1671 glGenTextures(1, &tex2D);
1672 glBindTexture(GL_TEXTURE_2D, tex2D);
1673
Till Rathmannc1551dc2018-08-15 17:04:49 +02001674 const std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize, 64);
Austin Kinross07285142015-03-26 11:36:16 -07001675
1676 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1677 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1678
1679 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
Jamie Madill50cf2be2018-06-15 09:46:57 -04001680 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1681 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001682 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1683
1684 // Check that an NPOT texture on level 0 succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001685 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1686 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001687 EXPECT_GL_NO_ERROR();
1688
1689 // Check that generateMipmap fails on NPOT
1690 glGenerateMipmap(GL_TEXTURE_2D);
1691 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1692
1693 // Check that nothing is drawn if filtering is not correct for NPOT
1694 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1695 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1696 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1697 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1698 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001699 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001700 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1701
1702 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1703 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1704 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1705 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1706 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001707 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001708 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1709
1710 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1711 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1712 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001713 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001714 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1715
1716 // Check that glTexImage2D for POT texture succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001717 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE,
1718 pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001719 EXPECT_GL_NO_ERROR();
1720
1721 // Check that generateMipmap for an POT texture succeeds
1722 glGenerateMipmap(GL_TEXTURE_2D);
1723 EXPECT_GL_NO_ERROR();
1724
1725 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1726 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1727 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1728 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1729 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1730 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001731 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001732 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1733 EXPECT_GL_NO_ERROR();
1734}
Jamie Madillfa05f602015-05-07 13:47:11 -04001735
Austin Kinross08528e12015-10-07 16:24:40 -07001736// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1737// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001738TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001739{
1740 glActiveTexture(GL_TEXTURE0);
1741 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1742
1743 // Create an 8x8 (i.e. power-of-two) texture.
1744 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1745 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1746 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1747 glGenerateMipmap(GL_TEXTURE_2D);
1748
1749 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1750 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001751 std::array<GLColor, 3 * 3> data;
1752 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001753
1754 EXPECT_GL_NO_ERROR();
1755}
1756
Geoff Lang3702d8c2019-04-08 13:44:06 -04001757// Regression test for http://crbug.com/949985 to make sure dirty bits are propagated up from
1758// TextureImpl and the texture is synced before being used in a draw call.
1759TEST_P(Texture2DTestES3, TextureImplPropogatesDirtyBits)
1760{
1761 ANGLE_SKIP_TEST_IF(IsIntel() && IsOpenGL());
Yuly Novikove6b23e42019-04-10 17:19:15 -04001762 // Flaky hangs on Win10 AMD RX 550 GL. http://anglebug.com/3371
1763 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsOpenGL());
Geoff Lang3702d8c2019-04-08 13:44:06 -04001764
1765 // The workaround in the GL backend required to trigger this bug generates driver warning
1766 // messages.
1767 ScopedIgnorePlatformMessages ignoreMessages;
1768
1769 setUpProgram();
1770 glUseProgram(mProgram);
1771 glActiveTexture(GL_TEXTURE0 + mTexture2DUniformLocation);
1772
1773 GLTexture dest;
1774 glBindTexture(GL_TEXTURE_2D, dest);
1775
1776 GLTexture source;
1777 glBindTexture(GL_TEXTURE_2D, source);
1778
1779 // Put data in mip 0 and 1
1780 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1781 GLColor::red.data());
1782 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1783 GLColor::green.data());
1784
1785 // Disable mipmapping so source is complete
1786 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1787 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1788
1789 // Force the dirty bits to be synchronized in source
1790 drawQuad(mProgram, "position", 1.0f);
1791
1792 // Copy from mip 1 of the source. In the GL backend this internally sets the base level to mip
1793 // 1 and sets a dirty bit.
1794 glCopyTextureCHROMIUM(source, 1, GL_TEXTURE_2D, dest, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_FALSE,
1795 GL_FALSE, GL_FALSE);
1796
1797 // Draw again, assertions are generated if the texture has internal dirty bits at draw time
1798 drawQuad(mProgram, "position", 1.0f);
1799}
1800
Geoff Lang6f691fb2019-04-25 11:01:52 -04001801// This test case changes the base level of a texture that's attached to a framebuffer, clears every
1802// level to green, and then samples the texture when rendering. Test is taken from
1803// https://www.khronos.org/registry/webgl/sdk/tests/conformance2/rendering/framebuffer-texture-changing-base-level.html
1804TEST_P(Texture2DTestES3, FramebufferTextureChangingBaselevel)
1805{
1806 // TODO(geofflang): Investigate on D3D11. http://anglebug.com/2291
1807 ANGLE_SKIP_TEST_IF(IsD3D11());
1808
1809 setUpProgram();
1810
1811 constexpr GLint width = 8;
1812 constexpr GLint height = 4;
1813
1814 GLTexture texture;
1815 glBindTexture(GL_TEXTURE_2D, texture);
1816 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1817 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1818 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1819 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1820
1821 // Create all mipmap levels for the texture from level 0 to the 1x1 pixel level.
1822 GLint level = 0;
1823 GLint levelW = width;
1824 GLint levelH = height;
1825 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, levelW, levelH, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1826 nullptr);
1827 while (levelW > 1 || levelH > 1)
1828 {
1829 ++level;
1830 levelW = static_cast<GLint>(std::max(1.0, std::floor(width / std::pow(2, level))));
1831 levelH = static_cast<GLint>(std::max(1.0, std::floor(height / std::pow(2, level))));
1832 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, levelW, levelH, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1833 nullptr);
1834 }
1835
1836 // Clear each level of the texture using an FBO. Change the base level to match the level used
1837 // for the FBO on each iteration.
1838 GLFramebuffer fbo;
1839 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1840 level = 0;
1841 levelW = width;
1842 levelH = height;
1843 while (levelW > 1 || levelH > 1)
1844 {
1845 levelW = static_cast<GLint>(std::floor(width / std::pow(2, level)));
1846 levelH = static_cast<GLint>(std::floor(height / std::pow(2, level)));
1847
1848 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, level);
1849 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, level);
1850
1851 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1852 EXPECT_GL_NO_ERROR();
1853
1854 glClearColor(0, 1, 0, 1);
1855 glClear(GL_COLOR_BUFFER_BIT);
1856
1857 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1858
1859 ++level;
1860 }
1861
1862 glBindFramebuffer(GL_FRAMEBUFFER, 0);
1863 glViewport(0, 0, 16, 16);
1864 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
1865
1866 drawQuad(mProgram, "position", 0.5f);
1867
1868 EXPECT_GL_NO_ERROR();
1869 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1870}
1871
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001872// Test to check that texture completeness is determined correctly when the texture base level is
1873// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1874TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1875{
1876 glActiveTexture(GL_TEXTURE0);
1877 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001878
1879 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1880 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1881 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1882 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1883 texDataGreen.data());
1884 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1885 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001886 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1887 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1888 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1889
1890 EXPECT_GL_NO_ERROR();
1891
1892 drawQuad(mProgram, "position", 0.5f);
1893
Olli Etuahoa314b612016-03-10 16:43:00 +02001894 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1895}
1896
1897// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1898// have images defined.
1899TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1900{
Yunchao He9550c602018-02-13 14:47:05 +08001901 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1902 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1903
Olli Etuahoa314b612016-03-10 16:43:00 +02001904 glActiveTexture(GL_TEXTURE0);
1905 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1906 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1907 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1908 texDataGreen.data());
1909 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1910 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1911 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1912 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1913
1914 EXPECT_GL_NO_ERROR();
1915
1916 drawQuad(mProgram, "position", 0.5f);
1917
1918 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1919}
1920
Olli Etuahoe8528d82016-05-16 17:50:52 +03001921// Test that drawing works correctly when level 0 is undefined and base level is 1.
1922TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1923{
Yunchao He9550c602018-02-13 14:47:05 +08001924 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1925 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1926
Olli Etuahoe8528d82016-05-16 17:50:52 +03001927 glActiveTexture(GL_TEXTURE0);
1928 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1929 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1930 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1931 texDataGreen.data());
1932 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1933 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1934 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1935 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1936
1937 EXPECT_GL_NO_ERROR();
1938
1939 // Texture is incomplete.
1940 drawQuad(mProgram, "position", 0.5f);
1941 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1942
1943 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1944 texDataGreen.data());
1945
1946 // Texture is now complete.
1947 drawQuad(mProgram, "position", 0.5f);
1948 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1949}
1950
Olli Etuahoa314b612016-03-10 16:43:00 +02001951// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1952// dimensions that don't fit the images inside the range.
1953// GLES 3.0.4 section 3.8.13 Texture completeness
1954TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1955{
Olli Etuahoa314b612016-03-10 16:43:00 +02001956 glActiveTexture(GL_TEXTURE0);
1957 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1958 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1959 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1960 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1961
1962 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1963 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1964
1965 // Two levels that are initially unused.
1966 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1967 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1968 texDataCyan.data());
1969
1970 // One level that is used - only this level should affect completeness.
1971 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1972 texDataGreen.data());
1973
1974 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1975 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1976
1977 EXPECT_GL_NO_ERROR();
1978
1979 drawQuad(mProgram, "position", 0.5f);
1980
1981 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1982
Yunchao He2f23f352018-02-11 22:11:37 +08001983 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001984
1985 // Switch the level that is being used to the cyan level 2.
1986 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1987 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1988
1989 EXPECT_GL_NO_ERROR();
1990
1991 drawQuad(mProgram, "position", 0.5f);
1992
1993 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1994}
1995
1996// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1997// have images defined.
1998TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1999{
Olli Etuahoa314b612016-03-10 16:43:00 +02002000 glActiveTexture(GL_TEXTURE0);
2001 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2002 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2003 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2004 texDataGreen.data());
2005 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2006 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2007 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
2008 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2009
2010 EXPECT_GL_NO_ERROR();
2011
2012 drawQuad(mProgram, "position", 0.5f);
2013
2014 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2015}
2016
2017// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2018// dimensions that don't fit the images inside the range.
2019// GLES 3.0.4 section 3.8.13 Texture completeness
2020TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2021{
Olli Etuahoa314b612016-03-10 16:43:00 +02002022 glActiveTexture(GL_TEXTURE0);
2023 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2024 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2025 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2026 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2027
2028 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2029 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2030
2031 // Two levels that are initially unused.
2032 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2033 texDataRed.data());
2034 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2035 texDataCyan.data());
2036
2037 // One level that is used - only this level should affect completeness.
2038 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2039 texDataGreen.data());
2040
2041 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
2042 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2043
2044 EXPECT_GL_NO_ERROR();
2045
2046 drawQuad(mProgram, "position", 0.5f);
2047
2048 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2049
Yunchao He2f23f352018-02-11 22:11:37 +08002050 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02002051
2052 // Switch the level that is being used to the cyan level 2.
2053 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
2054 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
2055
2056 EXPECT_GL_NO_ERROR();
2057
2058 drawQuad(mProgram, "position", 0.5f);
2059
2060 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2061}
2062
2063// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2064// have images defined.
2065TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
2066{
Olli Etuahoa314b612016-03-10 16:43:00 +02002067 glActiveTexture(GL_TEXTURE0);
2068 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
2069 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2070 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2071 texDataGreen.data());
2072 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2073 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2074 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2075 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2076
2077 EXPECT_GL_NO_ERROR();
2078
2079 drawQuad(mProgram, "position", 0.5f);
2080
2081 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2082}
2083
2084// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2085// dimensions that don't fit the images inside the range.
2086// GLES 3.0.4 section 3.8.13 Texture completeness
2087TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2088{
Olli Etuahoa314b612016-03-10 16:43:00 +02002089 glActiveTexture(GL_TEXTURE0);
2090 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
2091 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2092 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2093 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2094
2095 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2096 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2097
2098 // Two levels that are initially unused.
2099 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2100 texDataRed.data());
2101 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2102 texDataCyan.data());
2103
2104 // One level that is used - only this level should affect completeness.
2105 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2106 texDataGreen.data());
2107
2108 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2109 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2110
2111 EXPECT_GL_NO_ERROR();
2112
2113 drawQuad(mProgram, "position", 0.5f);
2114
2115 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2116
Yunchao He2f23f352018-02-11 22:11:37 +08002117 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
2118
Yunchao He9550c602018-02-13 14:47:05 +08002119 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
2120 // level was changed.
2121 ANGLE_SKIP_TEST_IF(IsNVIDIA() && (IsOpenGL() || IsOpenGLES()));
Olli Etuahoa314b612016-03-10 16:43:00 +02002122
2123 // Switch the level that is being used to the cyan level 2.
2124 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2125 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2126
2127 EXPECT_GL_NO_ERROR();
2128
2129 drawQuad(mProgram, "position", 0.5f);
2130
2131 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2132}
2133
2134// Test that texture completeness is updated if texture max level changes.
2135// GLES 3.0.4 section 3.8.13 Texture completeness
2136TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2137{
Olli Etuahoa314b612016-03-10 16:43:00 +02002138 glActiveTexture(GL_TEXTURE0);
2139 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2140 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2141
2142 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2143 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2144
2145 // A level that is initially unused.
2146 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2147 texDataGreen.data());
2148
2149 // One level that is initially used - only this level should affect completeness.
2150 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2151 texDataGreen.data());
2152
2153 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2154 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2155
2156 EXPECT_GL_NO_ERROR();
2157
2158 drawQuad(mProgram, "position", 0.5f);
2159
2160 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2161
2162 // Switch the max level to level 1. The levels within the used range now have inconsistent
2163 // dimensions and the texture should be incomplete.
2164 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2165
2166 EXPECT_GL_NO_ERROR();
2167
2168 drawQuad(mProgram, "position", 0.5f);
2169
2170 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2171}
2172
2173// Test that 3D texture completeness is updated if texture max level changes.
2174// GLES 3.0.4 section 3.8.13 Texture completeness
2175TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2176{
Olli Etuahoa314b612016-03-10 16:43:00 +02002177 glActiveTexture(GL_TEXTURE0);
2178 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2179 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2180
2181 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2182 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2183
2184 // A level that is initially unused.
2185 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2186 texDataGreen.data());
2187
2188 // One level that is initially used - only this level should affect completeness.
2189 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2190 texDataGreen.data());
2191
2192 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2193 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2194
2195 EXPECT_GL_NO_ERROR();
2196
2197 drawQuad(mProgram, "position", 0.5f);
2198
2199 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2200
2201 // Switch the max level to level 1. The levels within the used range now have inconsistent
2202 // dimensions and the texture should be incomplete.
2203 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2204
2205 EXPECT_GL_NO_ERROR();
2206
2207 drawQuad(mProgram, "position", 0.5f);
2208
2209 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2210}
2211
2212// Test that texture completeness is updated if texture base level changes.
2213// GLES 3.0.4 section 3.8.13 Texture completeness
2214TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2215{
Olli Etuahoa314b612016-03-10 16:43:00 +02002216 glActiveTexture(GL_TEXTURE0);
2217 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2218 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2219
2220 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2221 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2222
2223 // Two levels that are initially unused.
2224 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2225 texDataGreen.data());
2226 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2227 texDataGreen.data());
2228
2229 // One level that is initially used - only this level should affect completeness.
2230 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2231 texDataGreen.data());
2232
2233 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2234 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2235
2236 EXPECT_GL_NO_ERROR();
2237
2238 drawQuad(mProgram, "position", 0.5f);
2239
2240 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2241
2242 // Switch the base level to level 1. The levels within the used range now have inconsistent
2243 // dimensions and the texture should be incomplete.
2244 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2245
2246 EXPECT_GL_NO_ERROR();
2247
2248 drawQuad(mProgram, "position", 0.5f);
2249
2250 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2251}
2252
2253// Test that texture is not complete if base level is greater than max level.
2254// GLES 3.0.4 section 3.8.13 Texture completeness
2255TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2256{
Olli Etuahoa314b612016-03-10 16:43:00 +02002257 glActiveTexture(GL_TEXTURE0);
2258 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2259
2260 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2261 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2262
2263 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2264
2265 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2266 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2267
2268 EXPECT_GL_NO_ERROR();
2269
2270 drawQuad(mProgram, "position", 0.5f);
2271
2272 // Texture should be incomplete.
2273 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2274}
2275
2276// Test that immutable texture base level and max level are clamped.
2277// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2278TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2279{
Olli Etuahoa314b612016-03-10 16:43:00 +02002280 glActiveTexture(GL_TEXTURE0);
2281 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2282
2283 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2284 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2285
2286 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2287
2288 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2289
2290 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2291 // should be clamped to [base_level, levels - 1].
2292 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2293 // In the case of this test, those rules make the effective base level and max level 0.
2294 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2295 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2296
2297 EXPECT_GL_NO_ERROR();
2298
2299 drawQuad(mProgram, "position", 0.5f);
2300
2301 // Texture should be complete.
2302 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2303}
2304
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002305// Test that changing base level works when it affects the format of the texture.
2306TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2307{
Yunchao He9550c602018-02-13 14:47:05 +08002308 // Observed rendering corruption on NVIDIA OpenGL.
2309 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL());
2310
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002311 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002312
2313 // Observed incorrect rendering on AMD OpenGL.
2314 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002315
2316 glActiveTexture(GL_TEXTURE0);
2317 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2318 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2319 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2320
2321 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2322 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2323
2324 // RGBA8 level that's initially unused.
2325 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2326 texDataCyan.data());
2327
2328 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2329 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2330
2331 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2332 // format. It reads green channel data from the green and alpha channels of texDataGreen
2333 // (this is a bit hacky but works).
2334 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2335
2336 EXPECT_GL_NO_ERROR();
2337
2338 drawQuad(mProgram, "position", 0.5f);
2339
2340 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2341
2342 // Switch the texture to use the cyan level 0 with the RGBA format.
2343 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2344 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2345
2346 EXPECT_GL_NO_ERROR();
2347
2348 drawQuad(mProgram, "position", 0.5f);
2349
2350 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2351}
2352
Olli Etuahoa314b612016-03-10 16:43:00 +02002353// Test that setting a texture image works when base level is out of range.
2354TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2355{
2356 glActiveTexture(GL_TEXTURE0);
2357 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2358
2359 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2360 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2361
2362 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2363 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2364
2365 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2366
2367 EXPECT_GL_NO_ERROR();
2368
2369 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2370
2371 drawQuad(mProgram, "position", 0.5f);
2372
2373 // Texture should be complete.
2374 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002375}
2376
Jamie Madill50cf2be2018-06-15 09:46:57 -04002377// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG
2378// RBA->RGBA8, with 1.0 in the alpha channel. This test covers a bug where redefining array textures
2379// with these formats does not work as expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002380TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002381{
2382 std::vector<GLubyte> pixelData;
2383 for (size_t count = 0; count < 5000; count++)
2384 {
2385 pixelData.push_back(0u);
2386 pixelData.push_back(255u);
2387 pixelData.push_back(0u);
2388 }
2389
2390 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002391 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002392 glUniform1i(mTextureArrayLocation, 0);
2393
2394 // The first draw worked correctly.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002395 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2396 &pixelData[0]);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002397
2398 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2399 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2400 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2401 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002402 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002403 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002404
2405 // The dimension of the respecification must match the original exactly to trigger the bug.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002406 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2407 &pixelData[0]);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002408 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002409 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002410
2411 ASSERT_GL_NO_ERROR();
2412}
2413
Olli Etuaho1a679902016-01-14 12:21:47 +02002414// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2415// This test is needed especially to confirm that sampler registers get assigned correctly on
2416// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2417TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2418{
2419 glActiveTexture(GL_TEXTURE0);
2420 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2421 GLubyte texData[4];
2422 texData[0] = 0;
2423 texData[1] = 60;
2424 texData[2] = 0;
2425 texData[3] = 255;
2426 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2427
2428 glActiveTexture(GL_TEXTURE1);
2429 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2430 GLfloat depthTexData[1];
2431 depthTexData[0] = 0.5f;
2432 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2433 depthTexData);
2434
2435 glUseProgram(mProgram);
2436 glUniform1f(mDepthRefUniformLocation, 0.3f);
2437 glUniform1i(mTexture3DUniformLocation, 0);
2438 glUniform1i(mTextureShadowUniformLocation, 1);
2439
2440 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2441 drawQuad(mProgram, "position", 0.5f);
2442 EXPECT_GL_NO_ERROR();
2443 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2444 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2445
2446 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2447 drawQuad(mProgram, "position", 0.5f);
2448 EXPECT_GL_NO_ERROR();
2449 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2450 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2451}
2452
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002453// Test multiple different sampler types in the same shader.
2454// This test makes sure that even if sampler / texture registers get grouped together based on type
2455// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2456// still has the right register index information for each ESSL sampler.
2457// The tested ESSL samplers have the following types in D3D11 HLSL:
2458// sampler2D: Texture2D + SamplerState
2459// samplerCube: TextureCube + SamplerState
2460// sampler2DShadow: Texture2D + SamplerComparisonState
2461// samplerCubeShadow: TextureCube + SamplerComparisonState
2462TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2463{
2464 glActiveTexture(GL_TEXTURE0);
2465 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2466 GLubyte texData[4];
2467 texData[0] = 0;
2468 texData[1] = 0;
2469 texData[2] = 120;
2470 texData[3] = 255;
2471 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2472
2473 glActiveTexture(GL_TEXTURE1);
2474 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2475 texData[0] = 0;
2476 texData[1] = 90;
2477 texData[2] = 0;
2478 texData[3] = 255;
2479 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2480 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2481 texData);
2482
2483 glActiveTexture(GL_TEXTURE2);
2484 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2485 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2486 GLfloat depthTexData[1];
2487 depthTexData[0] = 0.5f;
2488 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2489 depthTexData);
2490
2491 glActiveTexture(GL_TEXTURE3);
2492 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2493 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2494 depthTexData[0] = 0.2f;
2495 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2496 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2497 depthTexData);
2498
2499 EXPECT_GL_NO_ERROR();
2500
2501 glUseProgram(mProgram);
2502 glUniform1f(mDepthRefUniformLocation, 0.3f);
2503 glUniform1i(mTexture2DUniformLocation, 0);
2504 glUniform1i(mTextureCubeUniformLocation, 1);
2505 glUniform1i(mTexture2DShadowUniformLocation, 2);
2506 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2507
2508 drawQuad(mProgram, "position", 0.5f);
2509 EXPECT_GL_NO_ERROR();
2510 // The shader writes:
2511 // <texture 2d color> +
2512 // <cube map color> +
2513 // 0.25 * <comparison result (1.0)> +
2514 // 0.125 * <comparison result (0.0)>
2515 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2516}
2517
Olli Etuahobce743a2016-01-15 17:18:28 +02002518// Test different base levels on textures accessed through the same sampler array.
2519// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2520TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2521{
Yunchao He9550c602018-02-13 14:47:05 +08002522 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2523
Olli Etuahobce743a2016-01-15 17:18:28 +02002524 glActiveTexture(GL_TEXTURE0);
2525 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2526 GLsizei size = 64;
2527 for (GLint level = 0; level < 7; ++level)
2528 {
2529 ASSERT_LT(0, size);
2530 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2531 nullptr);
2532 size = size / 2;
2533 }
2534 ASSERT_EQ(0, size);
2535 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2536
2537 glActiveTexture(GL_TEXTURE1);
2538 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2539 size = 128;
2540 for (GLint level = 0; level < 8; ++level)
2541 {
2542 ASSERT_LT(0, size);
2543 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2544 nullptr);
2545 size = size / 2;
2546 }
2547 ASSERT_EQ(0, size);
2548 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2549 EXPECT_GL_NO_ERROR();
2550
2551 glUseProgram(mProgram);
2552 glUniform1i(mTexture0Location, 0);
2553 glUniform1i(mTexture1Location, 1);
2554
Olli Etuaho5804dc82018-04-13 14:11:46 +03002555 drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
Olli Etuahobce743a2016-01-15 17:18:28 +02002556 EXPECT_GL_NO_ERROR();
2557 // Red channel: width of level 1 of texture A: 32.
2558 // Green channel: width of level 3 of texture B: 16.
2559 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2560}
2561
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002562// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2563// ES 3.0.4 table 3.24
2564TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2565{
2566 glActiveTexture(GL_TEXTURE0);
2567 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2568 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2569 EXPECT_GL_NO_ERROR();
2570
2571 drawQuad(mProgram, "position", 0.5f);
2572
2573 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2574}
2575
2576// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2577// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002578TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002579{
Luc Ferron5164b792018-03-06 09:10:12 -05002580 setUpProgram();
2581
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002582 glActiveTexture(GL_TEXTURE0);
2583 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2584 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2585 EXPECT_GL_NO_ERROR();
2586
2587 drawQuad(mProgram, "position", 0.5f);
2588
2589 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2590}
2591
Luc Ferron5164b792018-03-06 09:10:12 -05002592// Validate that every component of the pixel will be equal to the luminance value we've set
2593// and that the alpha channel will be 1 (or 255 to be exact).
2594TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2595{
2596 setUpProgram();
2597
2598 glActiveTexture(GL_TEXTURE0);
2599 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2600 uint8_t pixel = 50;
2601 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2602 EXPECT_GL_NO_ERROR();
2603
2604 drawQuad(mProgram, "position", 0.5f);
2605
2606 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2607}
2608
2609// Validate that every component of the pixel will be equal to the luminance value we've set
2610// and that the alpha channel will be the second component.
2611TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2612{
2613 setUpProgram();
2614
2615 glActiveTexture(GL_TEXTURE0);
2616 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2617 uint8_t pixel[] = {50, 25};
2618 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2619 GL_UNSIGNED_BYTE, pixel);
2620 EXPECT_GL_NO_ERROR();
2621
2622 drawQuad(mProgram, "position", 0.5f);
2623
2624 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2625}
2626
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002627// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2628// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002629TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002630{
Jamie Madillb8149072019-04-30 16:14:44 -04002631 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002632 ANGLE_SKIP_TEST_IF(IsD3D9());
2633 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002634
2635 setUpProgram();
2636
Luc Ferrond8c632c2018-04-10 12:31:44 -04002637 glActiveTexture(GL_TEXTURE0);
2638 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2639 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2640 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002641
Luc Ferrond8c632c2018-04-10 12:31:44 -04002642 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002643
Luc Ferrond8c632c2018-04-10 12:31:44 -04002644 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002645}
2646
2647// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2648// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002649TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002650{
Jamie Madillb8149072019-04-30 16:14:44 -04002651 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002652 ANGLE_SKIP_TEST_IF(IsD3D9());
2653 ANGLE_SKIP_TEST_IF(IsVulkan());
2654 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES());
2655 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2656 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002657
Luc Ferrond8c632c2018-04-10 12:31:44 -04002658 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002659
Luc Ferrond8c632c2018-04-10 12:31:44 -04002660 glActiveTexture(GL_TEXTURE0);
2661 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2662 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2663 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002664
Luc Ferrond8c632c2018-04-10 12:31:44 -04002665 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002666
Luc Ferrond8c632c2018-04-10 12:31:44 -04002667 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002668}
2669
2670// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2671// ES 3.0.4 table 3.24
2672TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2673{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002674 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2675
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002676 glActiveTexture(GL_TEXTURE0);
2677 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2678 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2679 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2680 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2681 EXPECT_GL_NO_ERROR();
2682
2683 drawQuad(mProgram, "position", 0.5f);
2684
2685 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2686}
2687
2688// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2689// ES 3.0.4 table 3.24
2690TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2691{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002692 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2693
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002694 glActiveTexture(GL_TEXTURE0);
2695 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2696
2697 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2698 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2699 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2700 EXPECT_GL_NO_ERROR();
2701
2702 drawQuad(mProgram, "position", 0.5f);
2703
2704 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2705}
2706
2707// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2708// ES 3.0.4 table 3.24
2709TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2710{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002711 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2712
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002713 glActiveTexture(GL_TEXTURE0);
2714 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2715 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2716 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2717 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2718 EXPECT_GL_NO_ERROR();
2719
2720 drawQuad(mProgram, "position", 0.5f);
2721
2722 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2723}
2724
2725// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2726// ES 3.0.4 table 3.24
2727TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2728{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002729 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2730
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002731 glActiveTexture(GL_TEXTURE0);
2732 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2733 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2734 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2735 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2736 EXPECT_GL_NO_ERROR();
2737
2738 drawQuad(mProgram, "position", 0.5f);
2739
2740 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2741}
2742
2743// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2744// ES 3.0.4 table 3.24
2745TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2746{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002747 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2748
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002749 glActiveTexture(GL_TEXTURE0);
2750 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2751 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2752 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2753 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2754 EXPECT_GL_NO_ERROR();
2755
2756 drawQuad(mProgram, "position", 0.5f);
2757
2758 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2759}
2760
2761// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2762// ES 3.0.4 table 3.24
2763TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2764{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002765 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2766
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002767 glActiveTexture(GL_TEXTURE0);
2768 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2769 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2770 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2771 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2772 EXPECT_GL_NO_ERROR();
2773
2774 drawQuad(mProgram, "position", 0.5f);
2775
2776 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2777}
2778
2779// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2780// ES 3.0.4 table 3.24
2781TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2782{
2783 glActiveTexture(GL_TEXTURE0);
2784 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2785 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2786 EXPECT_GL_NO_ERROR();
2787
2788 drawQuad(mProgram, "position", 0.5f);
2789
2790 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2791}
2792
2793// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2794// ES 3.0.4 table 3.24
2795TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2796{
2797 glActiveTexture(GL_TEXTURE0);
2798 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2799 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2800 nullptr);
2801 EXPECT_GL_NO_ERROR();
2802
2803 drawQuad(mProgram, "position", 0.5f);
2804
2805 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2806}
2807
2808// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2809// ES 3.0.4 table 3.24
2810TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2811{
Yunchao He9550c602018-02-13 14:47:05 +08002812 // Seems to fail on OSX 10.12 Intel.
2813 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Jamie Madillbb1db482017-01-10 10:48:32 -05002814
Yuly Novikov49886892018-01-23 21:18:27 -05002815 // http://anglebug.com/2190
2816 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2817
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002818 glActiveTexture(GL_TEXTURE0);
2819 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2820 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2821 EXPECT_GL_NO_ERROR();
2822
2823 drawQuad(mProgram, "position", 0.5f);
2824
2825 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2826}
2827
2828// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2829// ES 3.0.4 table 3.24
2830TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2831{
Yunchao He9550c602018-02-13 14:47:05 +08002832 // Seems to fail on OSX 10.12 Intel.
2833 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002834
Yuly Novikov49886892018-01-23 21:18:27 -05002835 // http://anglebug.com/2190
2836 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2837
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002838 glActiveTexture(GL_TEXTURE0);
2839 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2840 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2841 EXPECT_GL_NO_ERROR();
2842
2843 drawQuad(mProgram, "position", 0.5f);
2844
2845 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2846}
2847
Olli Etuaho96963162016-03-21 11:54:33 +02002848// Use a sampler in a uniform struct.
2849TEST_P(SamplerInStructTest, SamplerInStruct)
2850{
2851 runSamplerInStructTest();
2852}
2853
2854// Use a sampler in a uniform struct that's passed as a function parameter.
2855TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2856{
Yuly Novikovd18c0482019-04-04 19:56:43 -04002857 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
2858 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002859
Olli Etuaho96963162016-03-21 11:54:33 +02002860 runSamplerInStructTest();
2861}
2862
2863// Use a sampler in a uniform struct array with a struct from the array passed as a function
2864// parameter.
2865TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2866{
Yuly Novikovd18c0482019-04-04 19:56:43 -04002867 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
2868 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08002869
Olli Etuaho96963162016-03-21 11:54:33 +02002870 runSamplerInStructTest();
2871}
2872
2873// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2874// parameter.
2875TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2876{
Yuly Novikovd18c0482019-04-04 19:56:43 -04002877 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
2878 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08002879
Olli Etuaho96963162016-03-21 11:54:33 +02002880 runSamplerInStructTest();
2881}
2882
2883// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2884// similarly named uniform.
2885TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2886{
2887 runSamplerInStructTest();
2888}
2889
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05002890// GL_EXT_texture_filter_anisotropic
2891class TextureAnisotropyTest : public Texture2DTest
2892{
2893 protected:
2894 void uploadTexture()
2895 {
2896 glActiveTexture(GL_TEXTURE0);
2897 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2898 GLColor texDataRed[1] = {GLColor::red};
2899 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed);
2900 EXPECT_GL_NO_ERROR();
2901 }
2902};
2903
2904// Tests that setting anisotropic filtering doesn't cause failures at draw time.
2905TEST_P(TextureAnisotropyTest, AnisotropyFunctional)
2906{
Jamie Madillb8149072019-04-30 16:14:44 -04002907 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_filter_anisotropic"));
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05002908
2909 setUpProgram();
2910
2911 uploadTexture();
2912
2913 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2914 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2915 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f);
2916 EXPECT_GL_NO_ERROR();
2917
2918 drawQuad(mProgram, "position", 0.5f);
2919
2920 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
2921 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
2922 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::red);
2923}
2924
Till Rathmannb8543632018-10-02 19:46:14 +02002925// GL_OES_texture_border_clamp
2926class TextureBorderClampTest : public Texture2DTest
2927{
2928 protected:
2929 TextureBorderClampTest() : Texture2DTest() {}
2930
Jamie Madill35cd7332018-12-02 12:03:33 -05002931 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02002932 {
2933 return
2934 R"(precision highp float;
2935 attribute vec4 position;
2936 varying vec2 texcoord;
2937
2938 void main()
2939 {
2940 gl_Position = vec4(position.xy, 0.0, 1.0);
2941 // texcoords in [-0.5, 1.5]
2942 texcoord = (position.xy) + 0.5;
2943 })";
2944 }
2945
2946 void uploadTexture()
2947 {
2948 glActiveTexture(GL_TEXTURE0);
2949 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2950 std::vector<GLColor> texDataRed(1, GLColor::red);
2951 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2952 texDataRed.data());
2953 EXPECT_GL_NO_ERROR();
2954 }
2955};
2956
2957// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
2958// GL_CLAMP_TO_BORDER wrap mode (set with glTexParameter).
2959TEST_P(TextureBorderClampTest, TextureBorderClampFunctional)
2960{
Jamie Madillb8149072019-04-30 16:14:44 -04002961 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02002962
2963 setUpProgram();
2964
2965 uploadTexture();
2966
2967 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
2968 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
2969 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2970 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2971 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2972 EXPECT_GL_NO_ERROR();
2973
2974 drawQuad(mProgram, "position", 0.5f);
2975
2976 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
2977 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2978 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
2979}
2980
2981// Test reading back GL_TEXTURE_BORDER_COLOR by glGetTexParameter.
2982TEST_P(TextureBorderClampTest, TextureBorderClampFunctional2)
2983{
Jamie Madillb8149072019-04-30 16:14:44 -04002984 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02002985
2986 glActiveTexture(GL_TEXTURE0);
2987 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2988
2989 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2990
2991 GLint colorFixedPoint[4] = {0};
2992 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
2993 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
2994 std::numeric_limits<GLint>::max()};
2995 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
2996 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
2997 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
2998 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
2999
3000 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3001 std::numeric_limits<GLint>::max()};
3002 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3003
3004 GLfloat color[4] = {0.0f};
3005 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
3006 EXPECT_EQ(color[0], kFloatBlue.R);
3007 EXPECT_EQ(color[1], kFloatBlue.G);
3008 EXPECT_EQ(color[2], kFloatBlue.B);
3009 EXPECT_EQ(color[3], kFloatBlue.A);
3010}
3011
3012// Test GL_TEXTURE_BORDER_COLOR parameter validation at glTexParameter.
3013TEST_P(TextureBorderClampTest, TextureBorderClampValidation)
3014{
Jamie Madillb8149072019-04-30 16:14:44 -04003015 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003016
3017 glActiveTexture(GL_TEXTURE0);
3018 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3019
3020 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, 1.0f);
3021 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3022
3023 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3024 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3025
3026 glTexParameterfv(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3027 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3028
3029 GLint colorInt[4] = {0};
3030 glTexParameteriv(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_BORDER_COLOR, colorInt);
3031 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3032
3033 if (getClientMajorVersion() < 3)
3034 {
3035 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3036 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3037 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3038 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3039
3040 GLuint colorUInt[4] = {0};
3041 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3042 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3043 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3044 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3045
3046 GLSampler sampler;
3047 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3048 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3049 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3050 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3051
3052 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3053 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3054 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3055 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3056 }
3057}
3058
3059class TextureBorderClampTestES3 : public TextureBorderClampTest
3060{
3061 protected:
3062 TextureBorderClampTestES3() : TextureBorderClampTest() {}
3063};
3064
3065// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3066// GL_CLAMP_TO_BORDER wrap mode (set with glSamplerParameter).
3067TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional)
3068{
Jamie Madillb8149072019-04-30 16:14:44 -04003069 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003070
3071 setUpProgram();
3072
3073 uploadTexture();
3074
3075 GLSampler sampler;
3076 glBindSampler(0, sampler);
3077 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3078 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3079 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3080 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3081 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3082 EXPECT_GL_NO_ERROR();
3083
3084 drawQuad(mProgram, "position", 0.5f);
3085
3086 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3087 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3088 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3089}
3090
3091// Test reading back GL_TEXTURE_BORDER_COLOR by glGetSamplerParameter.
3092TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional2)
3093{
Jamie Madillb8149072019-04-30 16:14:44 -04003094 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003095
3096 glActiveTexture(GL_TEXTURE0);
3097
3098 GLSampler sampler;
3099 glBindSampler(0, sampler);
3100
3101 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3102
3103 GLint colorFixedPoint[4] = {0};
3104 glGetSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3105 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3106 std::numeric_limits<GLint>::max()};
3107 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3108 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3109 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3110 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3111
3112 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3113 std::numeric_limits<GLint>::max()};
3114 glSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3115
3116 GLfloat color[4] = {0.0f};
3117 glGetSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, color);
3118 EXPECT_EQ(color[0], kFloatBlue.R);
3119 EXPECT_EQ(color[1], kFloatBlue.G);
3120 EXPECT_EQ(color[2], kFloatBlue.B);
3121 EXPECT_EQ(color[3], kFloatBlue.A);
3122
3123 constexpr GLint colorSomewhatRedInt[4] = {500000, 0, 0, std::numeric_limits<GLint>::max()};
3124 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedInt);
3125 GLint colorInt[4] = {0};
3126 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3127 EXPECT_EQ(colorInt[0], colorSomewhatRedInt[0]);
3128 EXPECT_EQ(colorInt[1], colorSomewhatRedInt[1]);
3129 EXPECT_EQ(colorInt[2], colorSomewhatRedInt[2]);
3130 EXPECT_EQ(colorInt[3], colorSomewhatRedInt[3]);
3131
3132 constexpr GLuint colorSomewhatRedUInt[4] = {500000, 0, 0, std::numeric_limits<GLuint>::max()};
3133 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedUInt);
3134 GLuint colorUInt[4] = {0};
3135 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3136 EXPECT_EQ(colorUInt[0], colorSomewhatRedUInt[0]);
3137 EXPECT_EQ(colorUInt[1], colorSomewhatRedUInt[1]);
3138 EXPECT_EQ(colorUInt[2], colorSomewhatRedUInt[2]);
3139 EXPECT_EQ(colorUInt[3], colorSomewhatRedUInt[3]);
3140
3141 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3142
3143 constexpr GLint colorSomewhatGreenInt[4] = {0, 500000, 0, std::numeric_limits<GLint>::max()};
3144 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenInt);
3145 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3146 EXPECT_EQ(colorInt[0], colorSomewhatGreenInt[0]);
3147 EXPECT_EQ(colorInt[1], colorSomewhatGreenInt[1]);
3148 EXPECT_EQ(colorInt[2], colorSomewhatGreenInt[2]);
3149 EXPECT_EQ(colorInt[3], colorSomewhatGreenInt[3]);
3150
3151 constexpr GLuint colorSomewhatGreenUInt[4] = {0, 500000, 0, std::numeric_limits<GLuint>::max()};
3152 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenUInt);
3153 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3154 EXPECT_EQ(colorUInt[0], colorSomewhatGreenUInt[0]);
3155 EXPECT_EQ(colorUInt[1], colorSomewhatGreenUInt[1]);
3156 EXPECT_EQ(colorUInt[2], colorSomewhatGreenUInt[2]);
3157 EXPECT_EQ(colorUInt[3], colorSomewhatGreenUInt[3]);
3158}
3159
3160// Test GL_TEXTURE_BORDER_COLOR parameter validation at glSamplerParameter.
3161TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Validation)
3162{
Jamie Madillb8149072019-04-30 16:14:44 -04003163 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003164
3165 glActiveTexture(GL_TEXTURE0);
3166
3167 GLSampler sampler;
3168 glBindSampler(0, sampler);
3169
3170 glSamplerParameterf(sampler, GL_TEXTURE_BORDER_COLOR, 1.0f);
3171 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3172
3173 glSamplerParameteri(sampler, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3174 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3175}
3176
3177class TextureBorderClampIntegerTestES3 : public Texture2DTest
3178{
3179 protected:
3180 TextureBorderClampIntegerTestES3() : Texture2DTest(), isUnsignedIntTest(false) {}
3181
Jamie Madill35cd7332018-12-02 12:03:33 -05003182 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003183 {
3184 return
3185 R"(#version 300 es
3186 out vec2 texcoord;
3187 in vec4 position;
3188
3189 void main()
3190 {
3191 gl_Position = vec4(position.xy, 0.0, 1.0);
3192 // texcoords in [-0.5, 1.5]
3193 texcoord = (position.xy) + 0.5;
3194 })";
3195 }
3196
Jamie Madillba319ba2018-12-29 10:29:33 -05003197 const char *getFragmentShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003198 {
Jamie Madill35cd7332018-12-02 12:03:33 -05003199 if (isUnsignedIntTest)
3200 {
3201 return "#version 300 es\n"
3202 "precision highp float;\n"
3203 "uniform highp usampler2D tex;\n"
3204 "in vec2 texcoord;\n"
3205 "out vec4 fragColor;\n"
Till Rathmannb8543632018-10-02 19:46:14 +02003206
Jamie Madill35cd7332018-12-02 12:03:33 -05003207 "void main()\n"
3208 "{\n"
3209 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3210 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3211 "fragColor = (texture(tex, texcoord).r == 150u)"
3212 " ? green : red;\n"
3213 "}\n";
3214 }
3215 else
3216 {
3217 return "#version 300 es\n"
3218 "precision highp float;\n"
3219 "uniform highp isampler2D tex;\n"
3220 "in vec2 texcoord;\n"
3221 "out vec4 fragColor;\n"
3222
3223 "void main()\n"
3224 "{\n"
3225 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3226 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3227 "fragColor = (texture(tex, texcoord).r == -50)"
3228 " ? green : red;\n"
3229 "}\n";
3230 }
Till Rathmannb8543632018-10-02 19:46:14 +02003231 }
3232
3233 void uploadTexture()
3234 {
3235 glActiveTexture(GL_TEXTURE0);
3236 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3237 if (isUnsignedIntTest)
3238 {
3239 std::vector<GLubyte> texData(4, 100);
3240 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE,
3241 texData.data());
3242 }
3243 else
3244 {
3245 std::vector<GLbyte> texData(4, 100);
3246 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8I, 1, 1, 0, GL_RGBA_INTEGER, GL_BYTE,
3247 texData.data());
3248 }
3249 EXPECT_GL_NO_ERROR();
3250 }
3251
3252 bool isUnsignedIntTest;
3253};
3254
3255// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3256// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3257TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger)
3258{
Jamie Madillb8149072019-04-30 16:14:44 -04003259 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003260
3261 setUpProgram();
3262
3263 uploadTexture();
3264
3265 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3266 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3267 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3268 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3269
3270 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3271 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3272
3273 EXPECT_GL_NO_ERROR();
3274
3275 drawQuad(mProgram, "position", 0.5f);
3276
3277 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3278 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3279 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3280}
3281
3282// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3283// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3284TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger2)
3285{
Jamie Madillb8149072019-04-30 16:14:44 -04003286 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003287
3288 setUpProgram();
3289
3290 uploadTexture();
3291
3292 GLSampler sampler;
3293 glBindSampler(0, sampler);
3294 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3295 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3296 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3297 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3298
3299 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3300 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3301
3302 EXPECT_GL_NO_ERROR();
3303
3304 drawQuad(mProgram, "position", 0.5f);
3305
3306 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3307 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3308 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3309}
3310
3311// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3312// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIuivOES).
3313TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned)
3314{
Jamie Madillb8149072019-04-30 16:14:44 -04003315 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003316
3317 isUnsignedIntTest = true;
3318
3319 setUpProgram();
3320
3321 uploadTexture();
3322
3323 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3324 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3325 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3326 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3327
3328 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3329 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3330
3331 EXPECT_GL_NO_ERROR();
3332
3333 drawQuad(mProgram, "position", 0.5f);
3334
3335 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3336 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3337 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3338}
3339
3340// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3341// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with
3342// glSamplerParameterIuivOES).
3343TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned2)
3344{
Jamie Madillb8149072019-04-30 16:14:44 -04003345 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003346
3347 isUnsignedIntTest = true;
3348
3349 setUpProgram();
3350
3351 uploadTexture();
3352
3353 GLSampler sampler;
3354 glBindSampler(0, sampler);
3355 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3356 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3357 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3358 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3359
3360 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3361 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3362
3363 EXPECT_GL_NO_ERROR();
3364
3365 drawQuad(mProgram, "position", 0.5f);
3366
3367 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3368 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3369 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3370}
3371
3372// ~GL_OES_texture_border_clamp
3373
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003374class TextureLimitsTest : public ANGLETest
3375{
3376 protected:
3377 struct RGBA8
3378 {
3379 uint8_t R, G, B, A;
3380 };
3381
3382 TextureLimitsTest()
3383 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
3384 {
3385 setWindowWidth(128);
3386 setWindowHeight(128);
3387 setConfigRedBits(8);
3388 setConfigGreenBits(8);
3389 setConfigBlueBits(8);
3390 setConfigAlphaBits(8);
3391 }
3392
Jamie Madill0fdb9562018-09-17 17:18:43 -04003393 void SetUp() override
3394 {
3395 ANGLETest::SetUp();
3396
3397 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
3398 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
3399 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
3400
3401 ASSERT_GL_NO_ERROR();
3402 }
3403
3404 void TearDown() override
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003405 {
3406 if (mProgram != 0)
3407 {
3408 glDeleteProgram(mProgram);
3409 mProgram = 0;
3410
3411 if (!mTextures.empty())
3412 {
3413 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
3414 }
3415 }
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003416
Jamie Madill0fdb9562018-09-17 17:18:43 -04003417 ANGLETest::TearDown();
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003418 }
3419
3420 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
3421 GLint vertexTextureCount,
3422 GLint vertexActiveTextureCount,
3423 const std::string &fragPrefix,
3424 GLint fragmentTextureCount,
3425 GLint fragmentActiveTextureCount)
3426 {
3427 std::stringstream vertexShaderStr;
3428 vertexShaderStr << "attribute vec2 position;\n"
3429 << "varying vec4 color;\n"
3430 << "varying vec2 texCoord;\n";
3431
3432 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
3433 {
3434 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
3435 }
3436
3437 vertexShaderStr << "void main() {\n"
3438 << " gl_Position = vec4(position, 0, 1);\n"
3439 << " texCoord = (position * 0.5) + 0.5;\n"
3440 << " color = vec4(0);\n";
3441
3442 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
3443 {
3444 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
3445 << ", texCoord);\n";
3446 }
3447
3448 vertexShaderStr << "}";
3449
3450 std::stringstream fragmentShaderStr;
3451 fragmentShaderStr << "varying mediump vec4 color;\n"
3452 << "varying mediump vec2 texCoord;\n";
3453
3454 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
3455 {
3456 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
3457 }
3458
3459 fragmentShaderStr << "void main() {\n"
3460 << " gl_FragColor = color;\n";
3461
3462 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
3463 {
3464 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
3465 << ", texCoord);\n";
3466 }
3467
3468 fragmentShaderStr << "}";
3469
3470 const std::string &vertexShaderSource = vertexShaderStr.str();
3471 const std::string &fragmentShaderSource = fragmentShaderStr.str();
3472
Jamie Madill35cd7332018-12-02 12:03:33 -05003473 mProgram = CompileProgram(vertexShaderSource.c_str(), fragmentShaderSource.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003474 }
3475
3476 RGBA8 getPixel(GLint texIndex)
3477 {
3478 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3479 0, 255u};
3480 return pixel;
3481 }
3482
3483 void initTextures(GLint tex2DCount, GLint texCubeCount)
3484 {
3485 GLint totalCount = tex2DCount + texCubeCount;
3486 mTextures.assign(totalCount, 0);
3487 glGenTextures(totalCount, &mTextures[0]);
3488 ASSERT_GL_NO_ERROR();
3489
3490 std::vector<RGBA8> texData(16 * 16);
3491
3492 GLint texIndex = 0;
3493 for (; texIndex < tex2DCount; ++texIndex)
3494 {
3495 texData.assign(texData.size(), getPixel(texIndex));
3496 glActiveTexture(GL_TEXTURE0 + texIndex);
3497 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3498 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3499 &texData[0]);
3500 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3501 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3502 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3503 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3504 }
3505
3506 ASSERT_GL_NO_ERROR();
3507
3508 for (; texIndex < texCubeCount; ++texIndex)
3509 {
3510 texData.assign(texData.size(), getPixel(texIndex));
3511 glActiveTexture(GL_TEXTURE0 + texIndex);
3512 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3513 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3514 GL_UNSIGNED_BYTE, &texData[0]);
3515 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3516 GL_UNSIGNED_BYTE, &texData[0]);
3517 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3518 GL_UNSIGNED_BYTE, &texData[0]);
3519 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3520 GL_UNSIGNED_BYTE, &texData[0]);
3521 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3522 GL_UNSIGNED_BYTE, &texData[0]);
3523 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3524 GL_UNSIGNED_BYTE, &texData[0]);
3525 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3526 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3527 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3528 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3529 }
3530
3531 ASSERT_GL_NO_ERROR();
3532 }
3533
3534 void testWithTextures(GLint vertexTextureCount,
3535 const std::string &vertexTexturePrefix,
3536 GLint fragmentTextureCount,
3537 const std::string &fragmentTexturePrefix)
3538 {
3539 // Generate textures
3540 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3541
3542 glUseProgram(mProgram);
3543 RGBA8 expectedSum = {0};
3544 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3545 {
3546 std::stringstream uniformNameStr;
3547 uniformNameStr << vertexTexturePrefix << texIndex;
3548 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003549 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003550 ASSERT_NE(-1, location);
3551
3552 glUniform1i(location, texIndex);
3553 RGBA8 contribution = getPixel(texIndex);
3554 expectedSum.R += contribution.R;
3555 expectedSum.G += contribution.G;
3556 }
3557
3558 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3559 {
3560 std::stringstream uniformNameStr;
3561 uniformNameStr << fragmentTexturePrefix << texIndex;
3562 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003563 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003564 ASSERT_NE(-1, location);
3565
3566 glUniform1i(location, texIndex + vertexTextureCount);
3567 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3568 expectedSum.R += contribution.R;
3569 expectedSum.G += contribution.G;
3570 }
3571
3572 ASSERT_GE(256u, expectedSum.G);
3573
3574 drawQuad(mProgram, "position", 0.5f);
3575 ASSERT_GL_NO_ERROR();
3576 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3577 }
3578
3579 GLuint mProgram;
3580 std::vector<GLuint> mTextures;
3581 GLint mMaxVertexTextures;
3582 GLint mMaxFragmentTextures;
3583 GLint mMaxCombinedTextures;
3584};
3585
3586// Test rendering with the maximum vertex texture units.
3587TEST_P(TextureLimitsTest, MaxVertexTextures)
3588{
3589 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3590 ASSERT_NE(0u, mProgram);
3591 ASSERT_GL_NO_ERROR();
3592
3593 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3594}
3595
3596// Test rendering with the maximum fragment texture units.
3597TEST_P(TextureLimitsTest, MaxFragmentTextures)
3598{
3599 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3600 ASSERT_NE(0u, mProgram);
3601 ASSERT_GL_NO_ERROR();
3602
3603 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3604}
3605
3606// Test rendering with maximum combined texture units.
3607TEST_P(TextureLimitsTest, MaxCombinedTextures)
3608{
3609 GLint vertexTextures = mMaxVertexTextures;
3610
3611 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3612 {
3613 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3614 }
3615
3616 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3617 mMaxFragmentTextures, mMaxFragmentTextures);
3618 ASSERT_NE(0u, mProgram);
3619 ASSERT_GL_NO_ERROR();
3620
3621 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3622}
3623
3624// Negative test for exceeding the number of vertex textures
3625TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3626{
3627 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3628 0);
3629 ASSERT_EQ(0u, mProgram);
3630}
3631
3632// Negative test for exceeding the number of fragment textures
3633TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3634{
3635 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3636 mMaxFragmentTextures + 1);
3637 ASSERT_EQ(0u, mProgram);
3638}
3639
3640// Test active vertex textures under the limit, but excessive textures specified.
3641TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3642{
3643 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3644 ASSERT_NE(0u, mProgram);
3645 ASSERT_GL_NO_ERROR();
3646
3647 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3648}
3649
3650// Test active fragment textures under the limit, but excessive textures specified.
3651TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3652{
3653 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3654 mMaxFragmentTextures);
3655 ASSERT_NE(0u, mProgram);
3656 ASSERT_GL_NO_ERROR();
3657
3658 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3659}
3660
3661// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003662// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003663TEST_P(TextureLimitsTest, TextureTypeConflict)
3664{
Jamie Madill35cd7332018-12-02 12:03:33 -05003665 constexpr char kVS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003666 "attribute vec2 position;\n"
3667 "varying float color;\n"
3668 "uniform sampler2D tex2D;\n"
3669 "uniform samplerCube texCube;\n"
3670 "void main() {\n"
3671 " gl_Position = vec4(position, 0, 1);\n"
3672 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3673 " color = texture2D(tex2D, texCoord).x;\n"
3674 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3675 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05003676 constexpr char kFS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003677 "varying mediump float color;\n"
3678 "void main() {\n"
3679 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3680 "}";
3681
Jamie Madill35cd7332018-12-02 12:03:33 -05003682 mProgram = CompileProgram(kVS, kFS);
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003683 ASSERT_NE(0u, mProgram);
3684
3685 initTextures(1, 0);
3686
3687 glUseProgram(mProgram);
3688 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3689 ASSERT_NE(-1, tex2DLocation);
3690 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3691 ASSERT_NE(-1, texCubeLocation);
3692
3693 glUniform1i(tex2DLocation, 0);
3694 glUniform1i(texCubeLocation, 0);
3695 ASSERT_GL_NO_ERROR();
3696
3697 drawQuad(mProgram, "position", 0.5f);
3698 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3699}
3700
Vincent Lang25ab4512016-05-13 18:13:59 +02003701class Texture2DNorm16TestES3 : public Texture2DTestES3
3702{
3703 protected:
3704 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3705
3706 void SetUp() override
3707 {
3708 Texture2DTestES3::SetUp();
3709
3710 glActiveTexture(GL_TEXTURE0);
3711 glGenTextures(3, mTextures);
3712 glGenFramebuffers(1, &mFBO);
3713 glGenRenderbuffers(1, &mRenderbuffer);
3714
3715 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3716 {
3717 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3718 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3719 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3720 }
3721
3722 glBindTexture(GL_TEXTURE_2D, 0);
3723
3724 ASSERT_GL_NO_ERROR();
3725 }
3726
3727 void TearDown() override
3728 {
3729 glDeleteTextures(3, mTextures);
3730 glDeleteFramebuffers(1, &mFBO);
3731 glDeleteRenderbuffers(1, &mRenderbuffer);
3732
3733 Texture2DTestES3::TearDown();
3734 }
3735
3736 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3737 {
Geoff Langf607c602016-09-21 11:46:48 -04003738 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3739 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003740
3741 setUpProgram();
3742
3743 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3744 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3745 0);
3746
3747 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3748 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3749
3750 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003751 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003752
3753 EXPECT_GL_NO_ERROR();
3754
3755 drawQuad(mProgram, "position", 0.5f);
3756
Geoff Langf607c602016-09-21 11:46:48 -04003757 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003758
Jamie Madill50cf2be2018-06-15 09:46:57 -04003759 EXPECT_PIXEL_COLOR_EQ(0, 0,
3760 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3761 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003762
3763 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3764
3765 ASSERT_GL_NO_ERROR();
3766 }
3767
3768 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3769 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04003770 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003771 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003772
3773 setUpProgram();
3774
3775 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3776 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3777
3778 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3779 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3780 0);
3781
3782 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003783 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003784
3785 EXPECT_GL_NO_ERROR();
3786
3787 drawQuad(mProgram, "position", 0.5f);
3788
Geoff Langf607c602016-09-21 11:46:48 -04003789 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
Jamie Madill50cf2be2018-06-15 09:46:57 -04003790 EXPECT_PIXEL_COLOR_EQ(0, 0,
3791 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3792 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003793
3794 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3795 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3796 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3797 mRenderbuffer);
3798 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3799 EXPECT_GL_NO_ERROR();
3800
3801 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3802 glClear(GL_COLOR_BUFFER_BIT);
3803
3804 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3805
Geoff Langf607c602016-09-21 11:46:48 -04003806 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003807
3808 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3809
3810 ASSERT_GL_NO_ERROR();
3811 }
3812
3813 GLuint mTextures[3];
3814 GLuint mFBO;
3815 GLuint mRenderbuffer;
3816};
3817
3818// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3819TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3820{
Jamie Madillb8149072019-04-30 16:14:44 -04003821 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02003822
3823 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3824 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3825 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3826 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3827 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3828 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3829 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3830 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3831
3832 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3833 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3834 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3835}
3836
Olli Etuaho95faa232016-06-07 14:01:53 -07003837// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3838// GLES 3.0.4 section 3.8.3.
3839TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3840{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003841 // Crashes on Nexus 5X due to a driver bug. http://anglebug.com/1429
3842 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07003843
3844 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3845 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3846 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3847 ASSERT_GL_NO_ERROR();
3848
3849 // SKIP_IMAGES should not have an effect on uploading 2D textures
3850 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3851 ASSERT_GL_NO_ERROR();
3852
3853 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3854
3855 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3856 pixelsGreen.data());
3857 ASSERT_GL_NO_ERROR();
3858
3859 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3860 pixelsGreen.data());
3861 ASSERT_GL_NO_ERROR();
3862
3863 glUseProgram(mProgram);
3864 drawQuad(mProgram, "position", 0.5f);
3865 ASSERT_GL_NO_ERROR();
3866
3867 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3868}
3869
Olli Etuaho989cac32016-06-08 16:18:49 -07003870// Test that skip defined in unpack parameters is taken into account when determining whether
3871// unpacking source extends outside unpack buffer bounds.
3872TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3873{
3874 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3875 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3876 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3877 ASSERT_GL_NO_ERROR();
3878
3879 GLBuffer buf;
3880 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3881 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3882 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3883 GL_DYNAMIC_COPY);
3884 ASSERT_GL_NO_ERROR();
3885
3886 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3887 ASSERT_GL_NO_ERROR();
3888
3889 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3890 ASSERT_GL_NO_ERROR();
3891
3892 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3893 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3894
3895 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3896 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3897 ASSERT_GL_NO_ERROR();
3898
3899 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3900 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3901}
3902
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003903// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3904TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3905{
Yunchao He9550c602018-02-13 14:47:05 +08003906 ANGLE_SKIP_TEST_IF(IsD3D11());
3907
3908 // Incorrect rendering results seen on OSX AMD.
3909 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003910
3911 const GLuint width = 8u;
3912 const GLuint height = 8u;
3913 const GLuint unpackRowLength = 5u;
3914 const GLuint unpackSkipPixels = 1u;
3915
3916 setWindowWidth(width);
3917 setWindowHeight(height);
3918
3919 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3920 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3921 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3922 ASSERT_GL_NO_ERROR();
3923
3924 GLBuffer buf;
3925 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3926 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3927 GLColor::green);
3928
3929 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3930 {
3931 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3932 }
3933
3934 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3935 GL_DYNAMIC_COPY);
3936 ASSERT_GL_NO_ERROR();
3937
3938 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3939 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3940 ASSERT_GL_NO_ERROR();
3941
3942 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3943 ASSERT_GL_NO_ERROR();
3944
3945 glUseProgram(mProgram);
3946 drawQuad(mProgram, "position", 0.5f);
3947 ASSERT_GL_NO_ERROR();
3948
3949 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3950 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3951 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3952 actual.data());
3953 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3954 EXPECT_EQ(expected, actual);
3955}
3956
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003957template <typename T>
3958T UNorm(double value)
3959{
3960 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3961}
3962
3963// Test rendering a depth texture with mipmaps.
3964TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3965{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003966 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3967 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
Jiawei Shaoaf0f31d2018-09-27 15:42:31 +08003968 // http://anglebug.com/1706
3969 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Corentin Walleze731d8a2016-09-07 10:56:25 -04003970
Jamie Madill24980272019-04-03 09:03:51 -04003971 // Seems to fail on AMD D3D11. Possibly driver bug. http://anglebug.com/3342
3972 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsD3D11());
3973
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003974 const int size = getWindowWidth();
3975
3976 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003977 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003978
3979 glActiveTexture(GL_TEXTURE0);
3980 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3981 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3982 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3983 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3984 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3985 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3986 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3987 ASSERT_GL_NO_ERROR();
3988
3989 glUseProgram(mProgram);
3990 glUniform1i(mTexture2DUniformLocation, 0);
3991
3992 std::vector<unsigned char> expected;
3993
3994 for (int level = 0; level < levels; ++level)
3995 {
3996 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3997 expected.push_back(UNorm<unsigned char>(value));
3998
3999 int levelDim = dim(level);
4000
4001 ASSERT_GT(levelDim, 0);
4002
4003 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
4004 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
4005 GL_UNSIGNED_INT, initData.data());
4006 }
4007 ASSERT_GL_NO_ERROR();
4008
4009 for (int level = 0; level < levels; ++level)
4010 {
4011 glViewport(0, 0, dim(level), dim(level));
4012 drawQuad(mProgram, "position", 0.5f);
4013 GLColor actual = ReadColor(0, 0);
4014 EXPECT_NEAR(expected[level], actual.R, 10u);
4015 }
4016
4017 ASSERT_GL_NO_ERROR();
4018}
4019
Jamie Madill7ffdda92016-09-08 13:26:51 -04004020// Tests unpacking into the unsized GL_ALPHA format.
4021TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
4022{
Jamie Madill7ffdda92016-09-08 13:26:51 -04004023 // Initialize the texure.
4024 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4025 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
4026 GL_UNSIGNED_BYTE, nullptr);
4027 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4028 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4029
4030 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
4031
4032 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04004033 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04004034 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4035 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4036 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
4037 GL_STATIC_DRAW);
4038
4039 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
4040 GL_UNSIGNED_BYTE, nullptr);
4041
4042 // Clear to a weird color to make sure we're drawing something.
4043 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
4044 glClear(GL_COLOR_BUFFER_BIT);
4045
4046 // Draw with the alpha texture and verify.
4047 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04004048
4049 ASSERT_GL_NO_ERROR();
4050 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
4051}
4052
Jamie Madill2e600342016-09-19 13:56:40 -04004053// Ensure stale unpack data doesn't propagate in D3D11.
4054TEST_P(Texture2DTestES3, StaleUnpackData)
4055{
4056 // Init unpack buffer.
4057 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
4058 std::vector<GLColor> pixels(pixelCount, GLColor::red);
4059
4060 GLBuffer unpackBuffer;
4061 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4062 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4063 GLsizei bufferSize = pixelCount * sizeof(GLColor);
4064 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
4065
4066 // Create from unpack buffer.
4067 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4068 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
4069 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4070 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4071 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4072
4073 drawQuad(mProgram, "position", 0.5f);
4074
4075 ASSERT_GL_NO_ERROR();
4076 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4077
4078 // Fill unpack with green, recreating buffer.
4079 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
4080 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
4081 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
4082
4083 // Reinit texture with green.
4084 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
4085 GL_UNSIGNED_BYTE, nullptr);
4086
4087 drawQuad(mProgram, "position", 0.5f);
4088
4089 ASSERT_GL_NO_ERROR();
4090 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
4091}
4092
Geoff Langfb7685f2017-11-13 11:44:11 -05004093// Ensure that texture parameters passed as floats that are converted to ints are rounded before
4094// validating they are less than 0.
4095TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
4096{
4097 GLTexture texture;
4098 glBindTexture(GL_TEXTURE_2D, texture);
4099
4100 // Use a negative number that will round to zero when converted to an integer
4101 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
4102 // "Validation of values performed by state-setting commands is performed after conversion,
4103 // unless specified otherwise for a specific command."
4104 GLfloat param = -7.30157126e-07f;
4105 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
4106 EXPECT_GL_NO_ERROR();
4107
4108 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
4109 EXPECT_GL_NO_ERROR();
4110}
4111
Jamie Madillf097e232016-11-05 00:44:15 -04004112// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
4113// being properly checked, and the texture storage of the previous texture format was persisting.
4114// This would result in an ASSERT in debug and incorrect rendering in release.
4115// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
4116TEST_P(Texture3DTestES3, FormatRedefinitionBug)
4117{
4118 GLTexture tex;
4119 glBindTexture(GL_TEXTURE_3D, tex.get());
4120 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4121
4122 GLFramebuffer framebuffer;
4123 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
4124 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
4125
4126 glCheckFramebufferStatus(GL_FRAMEBUFFER);
4127
4128 std::vector<uint8_t> pixelData(100, 0);
4129
4130 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
4131 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
4132 pixelData.data());
4133
4134 ASSERT_GL_NO_ERROR();
4135}
4136
Corentin Wallezd2627992017-04-28 17:17:03 -04004137// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
4138TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
4139{
4140 // 2D tests
4141 {
4142 GLTexture tex;
4143 glBindTexture(GL_TEXTURE_2D, tex.get());
4144
4145 GLBuffer pbo;
4146 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4147
4148 // Test OOB
4149 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
4150 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4151 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4152
4153 // Test OOB
4154 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
4155 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4156 ASSERT_GL_NO_ERROR();
4157 }
4158
4159 // 3D tests
4160 {
4161 GLTexture tex;
4162 glBindTexture(GL_TEXTURE_3D, tex.get());
4163
4164 GLBuffer pbo;
4165 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4166
4167 // Test OOB
4168 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
4169 GL_STATIC_DRAW);
4170 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4171 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4172
4173 // Test OOB
4174 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
4175 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4176 ASSERT_GL_NO_ERROR();
4177 }
4178}
4179
Jamie Madill3ed60422017-09-07 11:32:52 -04004180// Tests behaviour with a single texture and multiple sampler objects.
4181TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
4182{
4183 GLint maxTextureUnits = 0;
4184 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
4185 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
4186
4187 constexpr int kSize = 16;
4188
4189 // Make a single-level texture, fill it with red.
4190 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
4191 GLTexture tex;
4192 glBindTexture(GL_TEXTURE_2D, tex);
4193 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4194 redColors.data());
4195 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4196 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4197
4198 // Simple sanity check.
4199 draw2DTexturedQuad(0.5f, 1.0f, true);
4200 ASSERT_GL_NO_ERROR();
4201 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4202
4203 // Bind texture to unit 1 with a sampler object making it incomplete.
4204 GLSampler sampler;
4205 glBindSampler(0, sampler);
4206 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4207 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4208
4209 // Make a mipmap texture, fill it with blue.
4210 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
4211 GLTexture mipmapTex;
4212 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4213 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4214 blueColors.data());
4215 glGenerateMipmap(GL_TEXTURE_2D);
4216
4217 // Draw with the sampler, expect blue.
4218 draw2DTexturedQuad(0.5f, 1.0f, true);
4219 ASSERT_GL_NO_ERROR();
4220 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
4221
4222 // Simple multitexturing program.
Jamie Madill35cd7332018-12-02 12:03:33 -05004223 constexpr char kVS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004224 "#version 300 es\n"
4225 "in vec2 position;\n"
4226 "out vec2 texCoord;\n"
4227 "void main()\n"
4228 "{\n"
4229 " gl_Position = vec4(position, 0, 1);\n"
4230 " texCoord = position * 0.5 + vec2(0.5);\n"
4231 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05004232
4233 constexpr char kFS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004234 "#version 300 es\n"
4235 "precision mediump float;\n"
4236 "in vec2 texCoord;\n"
4237 "uniform sampler2D tex1;\n"
4238 "uniform sampler2D tex2;\n"
4239 "uniform sampler2D tex3;\n"
4240 "uniform sampler2D tex4;\n"
4241 "out vec4 color;\n"
4242 "void main()\n"
4243 "{\n"
4244 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
4245 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
4246 "}";
4247
Jamie Madill35cd7332018-12-02 12:03:33 -05004248 ANGLE_GL_PROGRAM(program, kVS, kFS);
Jamie Madill3ed60422017-09-07 11:32:52 -04004249
4250 std::array<GLint, 4> texLocations = {
4251 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
4252 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
4253 for (GLint location : texLocations)
4254 {
4255 ASSERT_NE(-1, location);
4256 }
4257
4258 // Init the uniform data.
4259 glUseProgram(program);
4260 for (GLint location = 0; location < 4; ++location)
4261 {
4262 glUniform1i(texLocations[location], location);
4263 }
4264
4265 // Initialize four samplers
4266 GLSampler samplers[4];
4267
4268 // 0: non-mipped.
4269 glBindSampler(0, samplers[0]);
4270 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4271 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4272
4273 // 1: mipped.
4274 glBindSampler(1, samplers[1]);
4275 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4276 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4277
4278 // 2: non-mipped.
4279 glBindSampler(2, samplers[2]);
4280 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4281 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4282
4283 // 3: mipped.
4284 glBindSampler(3, samplers[3]);
4285 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4286 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4287
4288 // Bind two blue mipped textures and two single layer textures, should all draw.
4289 glActiveTexture(GL_TEXTURE0);
4290 glBindTexture(GL_TEXTURE_2D, tex);
4291
4292 glActiveTexture(GL_TEXTURE1);
4293 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4294
4295 glActiveTexture(GL_TEXTURE2);
4296 glBindTexture(GL_TEXTURE_2D, tex);
4297
4298 glActiveTexture(GL_TEXTURE3);
4299 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4300
4301 ASSERT_GL_NO_ERROR();
4302
4303 drawQuad(program, "position", 0.5f);
4304 ASSERT_GL_NO_ERROR();
4305 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
4306
4307 // Bind four single layer textures, two should be incomplete.
4308 glActiveTexture(GL_TEXTURE1);
4309 glBindTexture(GL_TEXTURE_2D, tex);
4310
4311 glActiveTexture(GL_TEXTURE3);
4312 glBindTexture(GL_TEXTURE_2D, tex);
4313
4314 drawQuad(program, "position", 0.5f);
4315 ASSERT_GL_NO_ERROR();
4316 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
4317}
4318
Martin Radev7e2c0d32017-09-15 14:25:42 +03004319// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
4320// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
4321// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
4322// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
4323// samples the cubemap using a direction vector (1,1,1).
4324TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
4325{
Yunchao He2f23f352018-02-11 22:11:37 +08004326 // Check http://anglebug.com/2155.
4327 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
4328
Jamie Madill35cd7332018-12-02 12:03:33 -05004329 constexpr char kVS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004330 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004331 precision mediump float;
4332 in vec3 pos;
4333 void main() {
4334 gl_Position = vec4(pos, 1.0);
4335 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03004336
Jamie Madill35cd7332018-12-02 12:03:33 -05004337 constexpr char kFS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004338 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004339 precision mediump float;
4340 out vec4 color;
4341 uniform samplerCube uTex;
4342 void main(){
4343 color = texture(uTex, vec3(1.0));
4344 })";
Jamie Madill35cd7332018-12-02 12:03:33 -05004345
4346 ANGLE_GL_PROGRAM(program, kVS, kFS);
Martin Radev7e2c0d32017-09-15 14:25:42 +03004347 glUseProgram(program);
4348
4349 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
4350 glActiveTexture(GL_TEXTURE0);
4351
4352 GLTexture cubeTex;
4353 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
4354
4355 const int kFaceWidth = 1;
4356 const int kFaceHeight = 1;
4357 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
4358 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4359 GL_UNSIGNED_BYTE, texData.data());
4360 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4361 GL_UNSIGNED_BYTE, texData.data());
4362 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4363 GL_UNSIGNED_BYTE, texData.data());
4364 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4365 GL_UNSIGNED_BYTE, texData.data());
4366 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4367 GL_UNSIGNED_BYTE, texData.data());
4368 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4369 GL_UNSIGNED_BYTE, texData.data());
4370 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4371 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4372 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
4373 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
4374 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
4375 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
4376
4377 drawQuad(program, "pos", 0.5f, 1.0f, true);
4378 ASSERT_GL_NO_ERROR();
4379
4380 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4381}
4382
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08004383// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
4384TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
4385{
4386 GLuint texture = create2DTexture();
4387
4388 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
4389 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4390
4391 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
4392 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4393
4394 glDeleteTextures(1, &texture);
4395 EXPECT_GL_NO_ERROR();
4396}
4397
Olli Etuaho023371b2018-04-24 17:43:32 +03004398// Test setting base level after calling generateMipmap on a LUMA texture.
4399// Covers http://anglebug.com/2498
4400TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA)
4401{
4402 glActiveTexture(GL_TEXTURE0);
4403 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4404
4405 constexpr const GLsizei kWidth = 8;
4406 constexpr const GLsizei kHeight = 8;
4407 std::array<GLubyte, kWidth * kHeight * 2> whiteData;
4408 whiteData.fill(255u);
4409
4410 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA,
4411 GL_UNSIGNED_BYTE, whiteData.data());
4412 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
4413 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4414 glGenerateMipmap(GL_TEXTURE_2D);
4415 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
4416 EXPECT_GL_NO_ERROR();
4417
4418 drawQuad(mProgram, "position", 0.5f);
4419 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4420}
4421
Till Rathmannc1551dc2018-08-15 17:04:49 +02004422// Covers a bug in the D3D11 backend: http://anglebug.com/2772
4423// When using a sampler the texture was created as if it has mipmaps,
4424// regardless what you specified in GL_TEXTURE_MIN_FILTER via
4425// glSamplerParameteri() -- mistakenly the default value
4426// GL_NEAREST_MIPMAP_LINEAR or the value set via glTexParameteri() was
4427// evaluated.
4428// If you didn't provide mipmaps and didn't let the driver generate them
4429// this led to not sampling your texture data when minification occurred.
4430TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping)
4431{
Jamie Madill35cd7332018-12-02 12:03:33 -05004432 constexpr char kVS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004433 "#version 300 es\n"
4434 "out vec2 texcoord;\n"
4435 "in vec4 position;\n"
4436 "void main()\n"
4437 "{\n"
4438 " gl_Position = vec4(position.xy * 0.1, 0.0, 1.0);\n"
4439 " texcoord = (position.xy * 0.5) + 0.5;\n"
4440 "}\n";
4441
Jamie Madill35cd7332018-12-02 12:03:33 -05004442 constexpr char kFS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004443 "#version 300 es\n"
4444 "precision highp float;\n"
4445 "uniform highp sampler2D tex;\n"
4446 "in vec2 texcoord;\n"
4447 "out vec4 fragColor;\n"
4448 "void main()\n"
4449 "{\n"
4450 " fragColor = texture(tex, texcoord);\n"
4451 "}\n";
Jamie Madill35cd7332018-12-02 12:03:33 -05004452
4453 ANGLE_GL_PROGRAM(program, kVS, kFS);
Till Rathmannc1551dc2018-08-15 17:04:49 +02004454
4455 GLSampler sampler;
4456 glBindSampler(0, sampler);
4457 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4458 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4459
4460 glActiveTexture(GL_TEXTURE0);
4461 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4462
4463 const GLsizei texWidth = getWindowWidth();
4464 const GLsizei texHeight = getWindowHeight();
4465 const std::vector<GLColor> whiteData(texWidth * texHeight, GLColor::white);
4466
4467 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4468 whiteData.data());
4469 EXPECT_GL_NO_ERROR();
4470
4471 drawQuad(program, "position", 0.5f);
4472 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, angle::GLColor::white);
4473}
4474
Anders Leinof6cbe442019-04-18 15:32:07 +03004475// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4476// texture is output.
4477TEST_P(Texture2DIntegerTestES3, IntegerTextureNonZeroBaseLevel)
4478{
4479 glActiveTexture(GL_TEXTURE0);
4480 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4481 int width = getWindowWidth();
4482 int height = getWindowHeight();
4483 GLColor color = GLColor::green;
4484 std::vector<GLColor> pixels(width * height, color);
4485 GLint baseLevel = 1;
4486 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
4487 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4488 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4489 glTexImage2D(GL_TEXTURE_2D, baseLevel, GL_RGBA8UI, width, height, 0, GL_RGBA_INTEGER,
4490 GL_UNSIGNED_BYTE, pixels.data());
4491
4492 setUpProgram();
4493 glUseProgram(mProgram);
4494 glUniform1i(mTexture2DUniformLocation, 0);
4495 drawQuad(mProgram, "position", 0.5f);
4496
4497 EXPECT_GL_NO_ERROR();
4498 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4499 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4500}
4501
Jamie Madill50cf2be2018-06-15 09:46:57 -04004502// Use this to select which configurations (e.g. which renderer, which GLES major version) these
4503// tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -05004504ANGLE_INSTANTIATE_TEST(Texture2DTest,
4505 ES2_D3D9(),
4506 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004507 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05004508 ES2_OPENGLES(),
4509 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004510ANGLE_INSTANTIATE_TEST(TextureCubeTest,
4511 ES2_D3D9(),
4512 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004513 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004514 ES2_OPENGLES(),
4515 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004516ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
4517 ES2_D3D9(),
4518 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004519 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004520 ES2_OPENGLES(),
4521 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004522ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
4523 ES2_D3D9(),
4524 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004525 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004526 ES2_OPENGLES(),
4527 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004528ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
4529 ES2_D3D9(),
4530 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004531 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004532 ES2_OPENGLES(),
4533 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004534ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
4535 ES2_D3D9(),
4536 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004537 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004538 ES2_OPENGLES(),
4539 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004540ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02004541ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02004542ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4543ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
4544 ES3_D3D11(),
4545 ES3_OPENGL(),
4546 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004547ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
4548 ES3_D3D11(),
4549 ES3_OPENGL(),
4550 ES3_OPENGLES());
4551ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4552ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02004553ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02004554ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
4555 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004556 ES2_D3D9(),
4557 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004558 ES2_OPENGLES(),
4559 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004560ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
4561 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004562 ES2_D3D9(),
4563 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004564 ES2_OPENGLES(),
4565 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004566ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
4567 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004568 ES2_D3D9(),
4569 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004570 ES2_OPENGLES(),
4571 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004572ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
4573 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004574 ES2_D3D9(),
4575 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004576 ES2_OPENGLES(),
4577 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004578ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
4579 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004580 ES2_D3D9(),
4581 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004582 ES2_OPENGLES(),
4583 ES2_VULKAN());
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05004584ANGLE_INSTANTIATE_TEST(TextureAnisotropyTest,
4585 ES2_D3D11(),
4586 ES2_D3D9(),
4587 ES2_OPENGL(),
4588 ES2_OPENGLES(),
4589 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02004590ANGLE_INSTANTIATE_TEST(TextureBorderClampTest,
4591 ES2_D3D11(),
4592 ES2_D3D9(),
4593 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004594 ES2_OPENGLES(),
4595 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02004596ANGLE_INSTANTIATE_TEST(TextureBorderClampTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4597ANGLE_INSTANTIATE_TEST(TextureBorderClampIntegerTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Luc Ferronaf883622018-06-08 15:57:31 -04004598ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN());
Vincent Lang25ab4512016-05-13 18:13:59 +02004599ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03004600ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Anders Leinof6cbe442019-04-18 15:32:07 +03004601ANGLE_INSTANTIATE_TEST(Texture2DIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Jamie Madillfa05f602015-05-07 13:47:11 -04004602
Jamie Madill7ffdda92016-09-08 13:26:51 -04004603} // anonymous namespace