blob: a436e50bfa2c8ffb875309a5658ede90589ac840 [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
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001155TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001156{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001157 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001158 EXPECT_GL_ERROR(GL_NO_ERROR);
1159
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001160 setUpProgram();
1161
Jamie Madill50cf2be2018-06-15 09:46:57 -04001162 const GLubyte *pixels[20] = {0};
Jamie Madillf67115c2014-04-22 13:14:05 -04001163 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1164 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001165
Jamie Madillb8149072019-04-30 16:14:44 -04001166 if (IsGLExtensionEnabled("GL_EXT_texture_storage"))
Geoff Langc51642b2016-11-14 16:18:26 -05001167 {
1168 // Create a 1-level immutable texture.
1169 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1170
1171 // Try calling sub image on the second level.
1172 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1173 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1174 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001175}
Geoff Langc41e42d2014-04-28 10:58:16 -04001176
John Bauman18319182016-09-28 14:22:27 -07001177// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1178TEST_P(Texture2DTest, QueryBinding)
1179{
1180 glBindTexture(GL_TEXTURE_2D, 0);
1181 EXPECT_GL_ERROR(GL_NO_ERROR);
1182
1183 GLint textureBinding;
1184 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1185 EXPECT_GL_NO_ERROR();
1186 EXPECT_EQ(0, textureBinding);
1187
1188 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
Jamie Madillb8149072019-04-30 16:14:44 -04001189 if (IsGLExtensionEnabled("GL_OES_EGL_image_external") ||
1190 IsGLExtensionEnabled("GL_NV_EGL_stream_consumer_external"))
John Bauman18319182016-09-28 14:22:27 -07001191 {
1192 EXPECT_GL_NO_ERROR();
1193 EXPECT_EQ(0, textureBinding);
1194 }
1195 else
1196 {
1197 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1198 }
1199}
1200
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001201TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001202{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001203 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001204 EXPECT_GL_ERROR(GL_NO_ERROR);
1205
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001206 setUpProgram();
1207
Geoff Langc41e42d2014-04-28 10:58:16 -04001208 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001209 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001210 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001211 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001212
Jamie Madill50cf2be2018-06-15 09:46:57 -04001213 const GLubyte *pixel[4] = {0};
Geoff Langc41e42d2014-04-28 10:58:16 -04001214
1215 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1216 EXPECT_GL_NO_ERROR();
1217
1218 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1219 EXPECT_GL_NO_ERROR();
1220
1221 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1222 EXPECT_GL_NO_ERROR();
1223}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001224
1225// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001226TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001227{
1228 glActiveTexture(GL_TEXTURE0);
1229 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1230 glActiveTexture(GL_TEXTURE1);
1231 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1232 EXPECT_GL_ERROR(GL_NO_ERROR);
1233
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001234 glUseProgram(mProgram);
1235 glUniform1i(mTexture2DUniformLocation, 0);
1236 glUniform1i(mTextureCubeUniformLocation, 1);
1237 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001238 EXPECT_GL_NO_ERROR();
1239}
Jamie Madill9aca0592014-10-06 16:26:59 -04001240
Olli Etuaho53a2da12016-01-11 15:43:32 +02001241// Test drawing with two texture types accessed from the same shader and check that the result of
1242// drawing is correct.
1243TEST_P(TextureCubeTest, CubeMapDraw)
1244{
1245 GLubyte texData[4];
1246 texData[0] = 0;
1247 texData[1] = 60;
1248 texData[2] = 0;
1249 texData[3] = 255;
1250
1251 glActiveTexture(GL_TEXTURE0);
1252 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1253 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1254
1255 glActiveTexture(GL_TEXTURE1);
1256 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1257 texData[1] = 120;
1258 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1259 texData);
1260 EXPECT_GL_ERROR(GL_NO_ERROR);
1261
1262 glUseProgram(mProgram);
1263 glUniform1i(mTexture2DUniformLocation, 0);
1264 glUniform1i(mTextureCubeUniformLocation, 1);
1265 drawQuad(mProgram, "position", 0.5f);
1266 EXPECT_GL_NO_ERROR();
1267
1268 int px = getWindowWidth() - 1;
1269 int py = 0;
1270 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1271}
1272
Olli Etuaho4644a202016-01-12 15:12:53 +02001273TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1274{
1275 glActiveTexture(GL_TEXTURE0);
1276 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1277 GLubyte texData[4];
1278 texData[0] = 0;
1279 texData[1] = 128;
1280 texData[2] = 0;
1281 texData[3] = 255;
1282 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1283 glUseProgram(mProgram);
1284 glUniform1i(mTexture2DUniformLocation, 0);
1285 drawQuad(mProgram, "position", 0.5f);
1286 EXPECT_GL_NO_ERROR();
1287
1288 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1289}
1290
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001291// Test drawing with two textures passed to the shader in a sampler array.
1292TEST_P(SamplerArrayTest, SamplerArrayDraw)
1293{
1294 testSamplerArrayDraw();
1295}
1296
1297// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1298// user-defined function in the shader.
1299TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1300{
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05001301 // TODO: Diagnose and fix. http://anglebug.com/2955
1302 ANGLE_SKIP_TEST_IF(IsVulkan() && IsAndroid());
1303
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001304 testSamplerArrayDraw();
1305}
1306
Jamie Madill9aca0592014-10-06 16:26:59 -04001307// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001308TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001309{
1310 int px = getWindowWidth() / 2;
1311 int py = getWindowHeight() / 2;
1312
1313 glActiveTexture(GL_TEXTURE0);
1314 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1315
Olli Etuahoa314b612016-03-10 16:43:00 +02001316 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001317
Olli Etuahoa314b612016-03-10 16:43:00 +02001318 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001319 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1320 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1321 glGenerateMipmap(GL_TEXTURE_2D);
1322
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001323 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001324 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001325 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1326 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001327 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001328 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001329
Olli Etuahoa314b612016-03-10 16:43:00 +02001330 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001331
Olli Etuahoa314b612016-03-10 16:43:00 +02001332 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1333 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001334 glGenerateMipmap(GL_TEXTURE_2D);
1335
Olli Etuahoa314b612016-03-10 16:43:00 +02001336 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001337
Olli Etuahoa314b612016-03-10 16:43:00 +02001338 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1339 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001340 glGenerateMipmap(GL_TEXTURE_2D);
1341
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001342 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001343
1344 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001345 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001346}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001347
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001348// Test creating a FBO with a cube map render target, to test an ANGLE bug
1349// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001350TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001351{
Michael Spangd8506c72019-01-29 15:35:09 -05001352 // http://anglebug.com/3145
1353 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
1354
Shahbaz Youssefi0c128e12019-03-25 23:50:14 -04001355 // http://anglebug.com/2822
1356 ANGLE_SKIP_TEST_IF(IsWindows() && IsIntel() && IsVulkan());
1357
Jamie Madill3f3b3582018-09-14 10:38:44 -04001358 GLFramebuffer fbo;
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001359 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1360
1361 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Jamie Madill50cf2be2018-06-15 09:46:57 -04001362 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1363 mTextureCube, 0);
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001364
Corentin Wallez322653b2015-06-17 18:33:56 +02001365 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001366 EXPECT_GL_NO_ERROR();
Jamie Madill3f3b3582018-09-14 10:38:44 -04001367
1368 // Test clearing the six mip faces individually.
1369 std::array<GLColor, 6> faceColors = {{GLColor::red, GLColor::green, GLColor::blue,
1370 GLColor::yellow, GLColor::cyan, GLColor::magenta}};
1371
1372 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1373 {
1374 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1375 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1376
1377 Vector4 clearColorF = faceColors[faceIndex].toNormalizedVector();
1378 glClearColor(clearColorF.x(), clearColorF.y(), clearColorF.z(), clearColorF.w());
1379 glClear(GL_COLOR_BUFFER_BIT);
1380
1381 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex]);
1382 }
1383
1384 // Iterate the faces again to make sure the colors haven't changed.
1385 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1386 {
1387 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1388 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1389 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex])
1390 << "face color " << faceIndex << " shouldn't change";
1391 }
1392}
1393
1394// Tests clearing a cube map with a scissor enabled.
1395TEST_P(TextureCubeTest, CubeMapFBOScissoredClear)
1396{
1397 // TODO(jie.a.chen): Diagnose and fix. http://anglebug.com/2822
1398 ANGLE_SKIP_TEST_IF(IsVulkan() && IsIntel() && IsWindows());
1399
Michael Spangd8506c72019-01-29 15:35:09 -05001400 // http://anglebug.com/3145
1401 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
1402
Jamie Madill3f3b3582018-09-14 10:38:44 -04001403 constexpr size_t kSize = 16;
1404
1405 GLFramebuffer fbo;
1406 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1407 glViewport(0, 0, kSize, kSize);
1408
1409 GLTexture texcube;
1410 glBindTexture(GL_TEXTURE_CUBE_MAP, texcube);
1411 for (GLenum face = 0; face < 6; face++)
1412 {
1413 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA,
1414 GL_UNSIGNED_BYTE, nullptr);
1415 }
1416 ASSERT_GL_NO_ERROR();
1417
1418 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1419 texcube, 0);
1420
1421 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1422 ASSERT_GL_NO_ERROR();
1423
1424 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1425 glClear(GL_COLOR_BUFFER_BIT);
1426 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1427
1428 glEnable(GL_SCISSOR_TEST);
1429 glScissor(kSize / 2, 0, kSize / 2, kSize);
1430 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
1431 glClear(GL_COLOR_BUFFER_BIT);
1432
1433 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1434 EXPECT_PIXEL_COLOR_EQ(kSize / 2 + 1, 0, GLColor::green);
1435
1436 ASSERT_GL_NO_ERROR();
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001437}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001438
Jamie Madill50cf2be2018-06-15 09:46:57 -04001439// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a
1440// default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001441TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001442{
Jamie Madillb8149072019-04-30 16:14:44 -04001443 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 &&
1444 !IsGLExtensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -04001445
Jamie Madill50cf2be2018-06-15 09:46:57 -04001446 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001447 int height = getWindowHeight();
1448
1449 GLuint tex2D;
1450 glGenTextures(1, &tex2D);
1451 glActiveTexture(GL_TEXTURE0);
1452 glBindTexture(GL_TEXTURE_2D, tex2D);
1453
1454 // Fill with red
1455 std::vector<GLubyte> pixels(3 * 16 * 16);
1456 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1457 {
1458 pixels[pixelId * 3 + 0] = 255;
1459 pixels[pixelId * 3 + 1] = 0;
1460 pixels[pixelId * 3 + 2] = 0;
1461 }
1462
1463 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001464 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1465 // 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 -04001466 if (getClientMajorVersion() >= 3)
1467 {
1468 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1469 }
1470 else
1471 {
1472 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1473 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001474
1475 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1476 // glTexSubImage2D should take into account that the image is dirty.
1477 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1478 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1479 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1480
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001481 setUpProgram();
1482
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001483 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001484 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001485 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001486 glDeleteTextures(1, &tex2D);
1487 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001488 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001489
1490 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001491 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1492 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001493}
1494
Jamie Madill50cf2be2018-06-15 09:46:57 -04001495// Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has
1496// initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001497TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001498{
Jamie Madillb8149072019-04-30 16:14:44 -04001499 if (IsGLExtensionEnabled("NV_pixel_buffer_object"))
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001500 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04001501 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001502 int height = getWindowHeight();
1503
1504 GLuint tex2D;
1505 glGenTextures(1, &tex2D);
1506 glActiveTexture(GL_TEXTURE0);
1507 glBindTexture(GL_TEXTURE_2D, tex2D);
1508
1509 // Fill with red
1510 std::vector<GLubyte> pixels(3 * 16 * 16);
1511 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1512 {
1513 pixels[pixelId * 3 + 0] = 255;
1514 pixels[pixelId * 3 + 1] = 0;
1515 pixels[pixelId * 3 + 2] = 0;
1516 }
1517
1518 // Read 16x16 region from red backbuffer to PBO
1519 GLuint pbo;
1520 glGenBuffers(1, &pbo);
1521 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1522 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1523
1524 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001525 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1526 // 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 +00001527 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1528
1529 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1530 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001531 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 +00001532 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1533 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1534
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001535 setUpProgram();
1536
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001537 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001538 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001539 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001540 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001541 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001542 EXPECT_GL_NO_ERROR();
1543 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1544 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1545 }
1546}
Jamie Madillbc393df2015-01-29 13:46:07 -05001547
1548// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001549TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001550{
1551 testFloatCopySubImage(1, 1);
1552}
1553
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001554TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001555{
1556 testFloatCopySubImage(2, 1);
1557}
1558
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001559TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001560{
1561 testFloatCopySubImage(2, 2);
1562}
1563
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001564TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001565{
1566 testFloatCopySubImage(3, 1);
1567}
1568
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001569TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001570{
1571 testFloatCopySubImage(3, 2);
1572}
1573
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001574TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001575{
Yunchao He9550c602018-02-13 14:47:05 +08001576 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1577 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001578
Yunchao He9550c602018-02-13 14:47:05 +08001579 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1580 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001581
Jamie Madillbc393df2015-01-29 13:46:07 -05001582 testFloatCopySubImage(3, 3);
1583}
1584
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001585TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001586{
1587 testFloatCopySubImage(4, 1);
1588}
1589
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001590TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001591{
1592 testFloatCopySubImage(4, 2);
1593}
1594
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001595TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001596{
Yunchao He9550c602018-02-13 14:47:05 +08001597 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1598 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001599
Jamie Madillbc393df2015-01-29 13:46:07 -05001600 testFloatCopySubImage(4, 3);
1601}
1602
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001603TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001604{
Luc Ferronf786b702018-07-10 11:01:43 -04001605 // TODO(lucferron): This test fails only on linux and intel.
1606 // http://anglebug.com/2726
1607 ANGLE_SKIP_TEST_IF(IsVulkan() && IsLinux() && IsIntel());
1608
Yunchao He9550c602018-02-13 14:47:05 +08001609 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1610 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001611
Jamie Madillbc393df2015-01-29 13:46:07 -05001612 testFloatCopySubImage(4, 4);
1613}
Austin Kinross07285142015-03-26 11:36:16 -07001614
Jamie Madill50cf2be2018-06-15 09:46:57 -04001615// Port of
1616// https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1617// Run against GL_ALPHA/UNSIGNED_BYTE format, to ensure that D3D11 Feature Level 9_3 correctly
1618// handles GL_ALPHA
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001619TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001620{
1621 const int npotTexSize = 5;
Jamie Madill50cf2be2018-06-15 09:46:57 -04001622 const int potTexSize = 4; // Should be less than npotTexSize
Austin Kinross07285142015-03-26 11:36:16 -07001623 GLuint tex2D;
1624
Jamie Madillb8149072019-04-30 16:14:44 -04001625 if (IsGLExtensionEnabled("GL_OES_texture_npot"))
Austin Kinross07285142015-03-26 11:36:16 -07001626 {
1627 // This test isn't applicable if texture_npot is enabled
1628 return;
1629 }
1630
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001631 setUpProgram();
1632
Austin Kinross07285142015-03-26 11:36:16 -07001633 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1634
Austin Kinross5faa15b2016-01-11 13:32:48 -08001635 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1636 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1637
Austin Kinross07285142015-03-26 11:36:16 -07001638 glActiveTexture(GL_TEXTURE0);
1639 glGenTextures(1, &tex2D);
1640 glBindTexture(GL_TEXTURE_2D, tex2D);
1641
Till Rathmannc1551dc2018-08-15 17:04:49 +02001642 const std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize, 64);
Austin Kinross07285142015-03-26 11:36:16 -07001643
1644 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1645 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1646
1647 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
Jamie Madill50cf2be2018-06-15 09:46:57 -04001648 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1649 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001650 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1651
1652 // Check that an NPOT texture on level 0 succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001653 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1654 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001655 EXPECT_GL_NO_ERROR();
1656
1657 // Check that generateMipmap fails on NPOT
1658 glGenerateMipmap(GL_TEXTURE_2D);
1659 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1660
1661 // Check that nothing is drawn if filtering is not correct for NPOT
1662 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1663 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1664 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1665 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1666 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001667 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001668 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1669
1670 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1671 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1672 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1673 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1674 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001675 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001676 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1677
1678 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1679 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1680 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001681 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001682 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1683
1684 // Check that glTexImage2D for POT texture succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001685 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE,
1686 pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001687 EXPECT_GL_NO_ERROR();
1688
1689 // Check that generateMipmap for an POT texture succeeds
1690 glGenerateMipmap(GL_TEXTURE_2D);
1691 EXPECT_GL_NO_ERROR();
1692
1693 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1694 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1695 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
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, 64);
1701 EXPECT_GL_NO_ERROR();
1702}
Jamie Madillfa05f602015-05-07 13:47:11 -04001703
Austin Kinross08528e12015-10-07 16:24:40 -07001704// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1705// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001706TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001707{
1708 glActiveTexture(GL_TEXTURE0);
1709 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1710
1711 // Create an 8x8 (i.e. power-of-two) texture.
1712 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1713 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1714 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1715 glGenerateMipmap(GL_TEXTURE_2D);
1716
1717 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1718 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001719 std::array<GLColor, 3 * 3> data;
1720 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001721
1722 EXPECT_GL_NO_ERROR();
1723}
1724
Geoff Lang3702d8c2019-04-08 13:44:06 -04001725// Regression test for http://crbug.com/949985 to make sure dirty bits are propagated up from
1726// TextureImpl and the texture is synced before being used in a draw call.
1727TEST_P(Texture2DTestES3, TextureImplPropogatesDirtyBits)
1728{
1729 ANGLE_SKIP_TEST_IF(IsIntel() && IsOpenGL());
Yuly Novikove6b23e42019-04-10 17:19:15 -04001730 // Flaky hangs on Win10 AMD RX 550 GL. http://anglebug.com/3371
1731 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsOpenGL());
Geoff Lang3702d8c2019-04-08 13:44:06 -04001732
1733 // The workaround in the GL backend required to trigger this bug generates driver warning
1734 // messages.
1735 ScopedIgnorePlatformMessages ignoreMessages;
1736
1737 setUpProgram();
1738 glUseProgram(mProgram);
1739 glActiveTexture(GL_TEXTURE0 + mTexture2DUniformLocation);
1740
1741 GLTexture dest;
1742 glBindTexture(GL_TEXTURE_2D, dest);
1743
1744 GLTexture source;
1745 glBindTexture(GL_TEXTURE_2D, source);
1746
1747 // Put data in mip 0 and 1
1748 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1749 GLColor::red.data());
1750 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1751 GLColor::green.data());
1752
1753 // Disable mipmapping so source is complete
1754 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1755 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1756
1757 // Force the dirty bits to be synchronized in source
1758 drawQuad(mProgram, "position", 1.0f);
1759
1760 // Copy from mip 1 of the source. In the GL backend this internally sets the base level to mip
1761 // 1 and sets a dirty bit.
1762 glCopyTextureCHROMIUM(source, 1, GL_TEXTURE_2D, dest, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_FALSE,
1763 GL_FALSE, GL_FALSE);
1764
1765 // Draw again, assertions are generated if the texture has internal dirty bits at draw time
1766 drawQuad(mProgram, "position", 1.0f);
1767}
1768
Geoff Lang6f691fb2019-04-25 11:01:52 -04001769// This test case changes the base level of a texture that's attached to a framebuffer, clears every
1770// level to green, and then samples the texture when rendering. Test is taken from
1771// https://www.khronos.org/registry/webgl/sdk/tests/conformance2/rendering/framebuffer-texture-changing-base-level.html
1772TEST_P(Texture2DTestES3, FramebufferTextureChangingBaselevel)
1773{
1774 // TODO(geofflang): Investigate on D3D11. http://anglebug.com/2291
1775 ANGLE_SKIP_TEST_IF(IsD3D11());
1776
1777 setUpProgram();
1778
1779 constexpr GLint width = 8;
1780 constexpr GLint height = 4;
1781
1782 GLTexture texture;
1783 glBindTexture(GL_TEXTURE_2D, texture);
1784 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1785 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1786 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1787 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1788
1789 // Create all mipmap levels for the texture from level 0 to the 1x1 pixel level.
1790 GLint level = 0;
1791 GLint levelW = width;
1792 GLint levelH = height;
1793 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, levelW, levelH, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1794 nullptr);
1795 while (levelW > 1 || levelH > 1)
1796 {
1797 ++level;
1798 levelW = static_cast<GLint>(std::max(1.0, std::floor(width / std::pow(2, level))));
1799 levelH = static_cast<GLint>(std::max(1.0, std::floor(height / std::pow(2, level))));
1800 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, levelW, levelH, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1801 nullptr);
1802 }
1803
1804 // Clear each level of the texture using an FBO. Change the base level to match the level used
1805 // for the FBO on each iteration.
1806 GLFramebuffer fbo;
1807 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1808 level = 0;
1809 levelW = width;
1810 levelH = height;
1811 while (levelW > 1 || levelH > 1)
1812 {
1813 levelW = static_cast<GLint>(std::floor(width / std::pow(2, level)));
1814 levelH = static_cast<GLint>(std::floor(height / std::pow(2, level)));
1815
1816 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, level);
1817 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, level);
1818
1819 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1820 EXPECT_GL_NO_ERROR();
1821
1822 glClearColor(0, 1, 0, 1);
1823 glClear(GL_COLOR_BUFFER_BIT);
1824
1825 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1826
1827 ++level;
1828 }
1829
1830 glBindFramebuffer(GL_FRAMEBUFFER, 0);
1831 glViewport(0, 0, 16, 16);
1832 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
1833
1834 drawQuad(mProgram, "position", 0.5f);
1835
1836 EXPECT_GL_NO_ERROR();
1837 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1838}
1839
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001840// Test to check that texture completeness is determined correctly when the texture base level is
1841// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1842TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1843{
1844 glActiveTexture(GL_TEXTURE0);
1845 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001846
1847 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1848 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1849 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1850 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1851 texDataGreen.data());
1852 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1853 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001854 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1855 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1856 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1857
1858 EXPECT_GL_NO_ERROR();
1859
1860 drawQuad(mProgram, "position", 0.5f);
1861
Olli Etuahoa314b612016-03-10 16:43:00 +02001862 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1863}
1864
1865// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1866// have images defined.
1867TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1868{
Yunchao He9550c602018-02-13 14:47:05 +08001869 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1870 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1871
Olli Etuahoa314b612016-03-10 16:43:00 +02001872 glActiveTexture(GL_TEXTURE0);
1873 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1874 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1875 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1876 texDataGreen.data());
1877 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1878 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1879 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1880 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1881
1882 EXPECT_GL_NO_ERROR();
1883
1884 drawQuad(mProgram, "position", 0.5f);
1885
1886 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1887}
1888
Olli Etuahoe8528d82016-05-16 17:50:52 +03001889// Test that drawing works correctly when level 0 is undefined and base level is 1.
1890TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1891{
Yunchao He9550c602018-02-13 14:47:05 +08001892 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1893 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1894
Olli Etuahoe8528d82016-05-16 17:50:52 +03001895 glActiveTexture(GL_TEXTURE0);
1896 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1897 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1898 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1899 texDataGreen.data());
1900 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1901 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1902 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1903 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1904
1905 EXPECT_GL_NO_ERROR();
1906
1907 // Texture is incomplete.
1908 drawQuad(mProgram, "position", 0.5f);
1909 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1910
1911 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1912 texDataGreen.data());
1913
1914 // Texture is now complete.
1915 drawQuad(mProgram, "position", 0.5f);
1916 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1917}
1918
Olli Etuahoa314b612016-03-10 16:43:00 +02001919// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1920// dimensions that don't fit the images inside the range.
1921// GLES 3.0.4 section 3.8.13 Texture completeness
1922TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1923{
Olli Etuahoa314b612016-03-10 16:43:00 +02001924 glActiveTexture(GL_TEXTURE0);
1925 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1926 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1927 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1928 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1929
1930 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1931 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1932
1933 // Two levels that are initially unused.
1934 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1935 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1936 texDataCyan.data());
1937
1938 // One level that is used - only this level should affect completeness.
1939 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1940 texDataGreen.data());
1941
1942 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1943 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1944
1945 EXPECT_GL_NO_ERROR();
1946
1947 drawQuad(mProgram, "position", 0.5f);
1948
1949 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1950
Yunchao He2f23f352018-02-11 22:11:37 +08001951 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001952
1953 // Switch the level that is being used to the cyan level 2.
1954 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1955 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1956
1957 EXPECT_GL_NO_ERROR();
1958
1959 drawQuad(mProgram, "position", 0.5f);
1960
1961 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1962}
1963
1964// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1965// have images defined.
1966TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1967{
Olli Etuahoa314b612016-03-10 16:43:00 +02001968 glActiveTexture(GL_TEXTURE0);
1969 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1970 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1971 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1972 texDataGreen.data());
1973 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1974 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1975 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1976 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1977
1978 EXPECT_GL_NO_ERROR();
1979
1980 drawQuad(mProgram, "position", 0.5f);
1981
1982 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1983}
1984
1985// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1986// dimensions that don't fit the images inside the range.
1987// GLES 3.0.4 section 3.8.13 Texture completeness
1988TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1989{
Olli Etuahoa314b612016-03-10 16:43:00 +02001990 glActiveTexture(GL_TEXTURE0);
1991 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1992 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1993 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1994 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1995
1996 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1997 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1998
1999 // Two levels that are initially unused.
2000 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2001 texDataRed.data());
2002 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2003 texDataCyan.data());
2004
2005 // One level that is used - only this level should affect completeness.
2006 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2007 texDataGreen.data());
2008
2009 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
2010 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2011
2012 EXPECT_GL_NO_ERROR();
2013
2014 drawQuad(mProgram, "position", 0.5f);
2015
2016 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2017
Yunchao He2f23f352018-02-11 22:11:37 +08002018 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02002019
2020 // Switch the level that is being used to the cyan level 2.
2021 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
2022 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
2023
2024 EXPECT_GL_NO_ERROR();
2025
2026 drawQuad(mProgram, "position", 0.5f);
2027
2028 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2029}
2030
2031// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2032// have images defined.
2033TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
2034{
Olli Etuahoa314b612016-03-10 16:43:00 +02002035 glActiveTexture(GL_TEXTURE0);
2036 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
2037 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2038 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2039 texDataGreen.data());
2040 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2041 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2042 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2043 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2044
2045 EXPECT_GL_NO_ERROR();
2046
2047 drawQuad(mProgram, "position", 0.5f);
2048
2049 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2050}
2051
2052// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2053// dimensions that don't fit the images inside the range.
2054// GLES 3.0.4 section 3.8.13 Texture completeness
2055TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2056{
Olli Etuahoa314b612016-03-10 16:43:00 +02002057 glActiveTexture(GL_TEXTURE0);
2058 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
2059 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2060 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2061 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2062
2063 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2064 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2065
2066 // Two levels that are initially unused.
2067 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2068 texDataRed.data());
2069 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2070 texDataCyan.data());
2071
2072 // One level that is used - only this level should affect completeness.
2073 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2074 texDataGreen.data());
2075
2076 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2077 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2078
2079 EXPECT_GL_NO_ERROR();
2080
2081 drawQuad(mProgram, "position", 0.5f);
2082
2083 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2084
Yunchao He2f23f352018-02-11 22:11:37 +08002085 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
2086
Yunchao He9550c602018-02-13 14:47:05 +08002087 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
2088 // level was changed.
2089 ANGLE_SKIP_TEST_IF(IsNVIDIA() && (IsOpenGL() || IsOpenGLES()));
Olli Etuahoa314b612016-03-10 16:43:00 +02002090
2091 // Switch the level that is being used to the cyan level 2.
2092 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2093 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2094
2095 EXPECT_GL_NO_ERROR();
2096
2097 drawQuad(mProgram, "position", 0.5f);
2098
2099 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2100}
2101
2102// Test that texture completeness is updated if texture max level changes.
2103// GLES 3.0.4 section 3.8.13 Texture completeness
2104TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2105{
Olli Etuahoa314b612016-03-10 16:43:00 +02002106 glActiveTexture(GL_TEXTURE0);
2107 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2108 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2109
2110 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2111 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2112
2113 // A level that is initially unused.
2114 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2115 texDataGreen.data());
2116
2117 // One level that is initially used - only this level should affect completeness.
2118 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2119 texDataGreen.data());
2120
2121 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2122 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2123
2124 EXPECT_GL_NO_ERROR();
2125
2126 drawQuad(mProgram, "position", 0.5f);
2127
2128 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2129
2130 // Switch the max level to level 1. The levels within the used range now have inconsistent
2131 // dimensions and the texture should be incomplete.
2132 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2133
2134 EXPECT_GL_NO_ERROR();
2135
2136 drawQuad(mProgram, "position", 0.5f);
2137
2138 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2139}
2140
2141// Test that 3D texture completeness is updated if texture max level changes.
2142// GLES 3.0.4 section 3.8.13 Texture completeness
2143TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2144{
Olli Etuahoa314b612016-03-10 16:43:00 +02002145 glActiveTexture(GL_TEXTURE0);
2146 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2147 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2148
2149 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2150 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2151
2152 // A level that is initially unused.
2153 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2154 texDataGreen.data());
2155
2156 // One level that is initially used - only this level should affect completeness.
2157 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2158 texDataGreen.data());
2159
2160 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2161 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2162
2163 EXPECT_GL_NO_ERROR();
2164
2165 drawQuad(mProgram, "position", 0.5f);
2166
2167 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2168
2169 // Switch the max level to level 1. The levels within the used range now have inconsistent
2170 // dimensions and the texture should be incomplete.
2171 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2172
2173 EXPECT_GL_NO_ERROR();
2174
2175 drawQuad(mProgram, "position", 0.5f);
2176
2177 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2178}
2179
2180// Test that texture completeness is updated if texture base level changes.
2181// GLES 3.0.4 section 3.8.13 Texture completeness
2182TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2183{
Olli Etuahoa314b612016-03-10 16:43:00 +02002184 glActiveTexture(GL_TEXTURE0);
2185 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2186 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2187
2188 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2189 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2190
2191 // Two levels that are initially unused.
2192 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2193 texDataGreen.data());
2194 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2195 texDataGreen.data());
2196
2197 // One level that is initially used - only this level should affect completeness.
2198 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2199 texDataGreen.data());
2200
2201 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2202 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2203
2204 EXPECT_GL_NO_ERROR();
2205
2206 drawQuad(mProgram, "position", 0.5f);
2207
2208 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2209
2210 // Switch the base level to level 1. The levels within the used range now have inconsistent
2211 // dimensions and the texture should be incomplete.
2212 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2213
2214 EXPECT_GL_NO_ERROR();
2215
2216 drawQuad(mProgram, "position", 0.5f);
2217
2218 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2219}
2220
2221// Test that texture is not complete if base level is greater than max level.
2222// GLES 3.0.4 section 3.8.13 Texture completeness
2223TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2224{
Olli Etuahoa314b612016-03-10 16:43:00 +02002225 glActiveTexture(GL_TEXTURE0);
2226 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2227
2228 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2229 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2230
2231 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2232
2233 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2234 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2235
2236 EXPECT_GL_NO_ERROR();
2237
2238 drawQuad(mProgram, "position", 0.5f);
2239
2240 // Texture should be incomplete.
2241 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2242}
2243
2244// Test that immutable texture base level and max level are clamped.
2245// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2246TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2247{
Olli Etuahoa314b612016-03-10 16:43:00 +02002248 glActiveTexture(GL_TEXTURE0);
2249 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2250
2251 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2252 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2253
2254 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2255
2256 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2257
2258 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2259 // should be clamped to [base_level, levels - 1].
2260 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2261 // In the case of this test, those rules make the effective base level and max level 0.
2262 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2263 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2264
2265 EXPECT_GL_NO_ERROR();
2266
2267 drawQuad(mProgram, "position", 0.5f);
2268
2269 // Texture should be complete.
2270 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2271}
2272
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002273// Test that changing base level works when it affects the format of the texture.
2274TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2275{
Yunchao He9550c602018-02-13 14:47:05 +08002276 // Observed rendering corruption on NVIDIA OpenGL.
2277 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL());
2278
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002279 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002280
2281 // Observed incorrect rendering on AMD OpenGL.
2282 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002283
2284 glActiveTexture(GL_TEXTURE0);
2285 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2286 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2287 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2288
2289 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2290 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2291
2292 // RGBA8 level that's initially unused.
2293 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2294 texDataCyan.data());
2295
2296 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2297 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2298
2299 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2300 // format. It reads green channel data from the green and alpha channels of texDataGreen
2301 // (this is a bit hacky but works).
2302 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2303
2304 EXPECT_GL_NO_ERROR();
2305
2306 drawQuad(mProgram, "position", 0.5f);
2307
2308 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2309
2310 // Switch the texture to use the cyan level 0 with the RGBA format.
2311 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2312 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2313
2314 EXPECT_GL_NO_ERROR();
2315
2316 drawQuad(mProgram, "position", 0.5f);
2317
2318 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2319}
2320
Olli Etuahoa314b612016-03-10 16:43:00 +02002321// Test that setting a texture image works when base level is out of range.
2322TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2323{
2324 glActiveTexture(GL_TEXTURE0);
2325 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2326
2327 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2328 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2329
2330 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2331 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2332
2333 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2334
2335 EXPECT_GL_NO_ERROR();
2336
2337 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2338
2339 drawQuad(mProgram, "position", 0.5f);
2340
2341 // Texture should be complete.
2342 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002343}
2344
Jamie Madill50cf2be2018-06-15 09:46:57 -04002345// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG
2346// RBA->RGBA8, with 1.0 in the alpha channel. This test covers a bug where redefining array textures
2347// with these formats does not work as expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002348TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002349{
2350 std::vector<GLubyte> pixelData;
2351 for (size_t count = 0; count < 5000; count++)
2352 {
2353 pixelData.push_back(0u);
2354 pixelData.push_back(255u);
2355 pixelData.push_back(0u);
2356 }
2357
2358 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002359 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002360 glUniform1i(mTextureArrayLocation, 0);
2361
2362 // The first draw worked correctly.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002363 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2364 &pixelData[0]);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002365
2366 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2367 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2368 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2369 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002370 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002371 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002372
2373 // The dimension of the respecification must match the original exactly to trigger the bug.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002374 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2375 &pixelData[0]);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002376 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002377 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002378
2379 ASSERT_GL_NO_ERROR();
2380}
2381
Olli Etuaho1a679902016-01-14 12:21:47 +02002382// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2383// This test is needed especially to confirm that sampler registers get assigned correctly on
2384// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2385TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2386{
2387 glActiveTexture(GL_TEXTURE0);
2388 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2389 GLubyte texData[4];
2390 texData[0] = 0;
2391 texData[1] = 60;
2392 texData[2] = 0;
2393 texData[3] = 255;
2394 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2395
2396 glActiveTexture(GL_TEXTURE1);
2397 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2398 GLfloat depthTexData[1];
2399 depthTexData[0] = 0.5f;
2400 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2401 depthTexData);
2402
2403 glUseProgram(mProgram);
2404 glUniform1f(mDepthRefUniformLocation, 0.3f);
2405 glUniform1i(mTexture3DUniformLocation, 0);
2406 glUniform1i(mTextureShadowUniformLocation, 1);
2407
2408 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2409 drawQuad(mProgram, "position", 0.5f);
2410 EXPECT_GL_NO_ERROR();
2411 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2412 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2413
2414 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2415 drawQuad(mProgram, "position", 0.5f);
2416 EXPECT_GL_NO_ERROR();
2417 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2418 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2419}
2420
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002421// Test multiple different sampler types in the same shader.
2422// This test makes sure that even if sampler / texture registers get grouped together based on type
2423// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2424// still has the right register index information for each ESSL sampler.
2425// The tested ESSL samplers have the following types in D3D11 HLSL:
2426// sampler2D: Texture2D + SamplerState
2427// samplerCube: TextureCube + SamplerState
2428// sampler2DShadow: Texture2D + SamplerComparisonState
2429// samplerCubeShadow: TextureCube + SamplerComparisonState
2430TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2431{
2432 glActiveTexture(GL_TEXTURE0);
2433 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2434 GLubyte texData[4];
2435 texData[0] = 0;
2436 texData[1] = 0;
2437 texData[2] = 120;
2438 texData[3] = 255;
2439 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2440
2441 glActiveTexture(GL_TEXTURE1);
2442 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2443 texData[0] = 0;
2444 texData[1] = 90;
2445 texData[2] = 0;
2446 texData[3] = 255;
2447 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2448 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2449 texData);
2450
2451 glActiveTexture(GL_TEXTURE2);
2452 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2453 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2454 GLfloat depthTexData[1];
2455 depthTexData[0] = 0.5f;
2456 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2457 depthTexData);
2458
2459 glActiveTexture(GL_TEXTURE3);
2460 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2461 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2462 depthTexData[0] = 0.2f;
2463 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2464 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2465 depthTexData);
2466
2467 EXPECT_GL_NO_ERROR();
2468
2469 glUseProgram(mProgram);
2470 glUniform1f(mDepthRefUniformLocation, 0.3f);
2471 glUniform1i(mTexture2DUniformLocation, 0);
2472 glUniform1i(mTextureCubeUniformLocation, 1);
2473 glUniform1i(mTexture2DShadowUniformLocation, 2);
2474 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2475
2476 drawQuad(mProgram, "position", 0.5f);
2477 EXPECT_GL_NO_ERROR();
2478 // The shader writes:
2479 // <texture 2d color> +
2480 // <cube map color> +
2481 // 0.25 * <comparison result (1.0)> +
2482 // 0.125 * <comparison result (0.0)>
2483 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2484}
2485
Olli Etuahobce743a2016-01-15 17:18:28 +02002486// Test different base levels on textures accessed through the same sampler array.
2487// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2488TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2489{
Yunchao He9550c602018-02-13 14:47:05 +08002490 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2491
Olli Etuahobce743a2016-01-15 17:18:28 +02002492 glActiveTexture(GL_TEXTURE0);
2493 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2494 GLsizei size = 64;
2495 for (GLint level = 0; level < 7; ++level)
2496 {
2497 ASSERT_LT(0, size);
2498 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2499 nullptr);
2500 size = size / 2;
2501 }
2502 ASSERT_EQ(0, size);
2503 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2504
2505 glActiveTexture(GL_TEXTURE1);
2506 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2507 size = 128;
2508 for (GLint level = 0; level < 8; ++level)
2509 {
2510 ASSERT_LT(0, size);
2511 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2512 nullptr);
2513 size = size / 2;
2514 }
2515 ASSERT_EQ(0, size);
2516 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2517 EXPECT_GL_NO_ERROR();
2518
2519 glUseProgram(mProgram);
2520 glUniform1i(mTexture0Location, 0);
2521 glUniform1i(mTexture1Location, 1);
2522
Olli Etuaho5804dc82018-04-13 14:11:46 +03002523 drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
Olli Etuahobce743a2016-01-15 17:18:28 +02002524 EXPECT_GL_NO_ERROR();
2525 // Red channel: width of level 1 of texture A: 32.
2526 // Green channel: width of level 3 of texture B: 16.
2527 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2528}
2529
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002530// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2531// ES 3.0.4 table 3.24
2532TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2533{
2534 glActiveTexture(GL_TEXTURE0);
2535 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2536 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2537 EXPECT_GL_NO_ERROR();
2538
2539 drawQuad(mProgram, "position", 0.5f);
2540
2541 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2542}
2543
2544// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2545// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002546TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002547{
Luc Ferron5164b792018-03-06 09:10:12 -05002548 setUpProgram();
2549
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002550 glActiveTexture(GL_TEXTURE0);
2551 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2552 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2553 EXPECT_GL_NO_ERROR();
2554
2555 drawQuad(mProgram, "position", 0.5f);
2556
2557 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2558}
2559
Luc Ferron5164b792018-03-06 09:10:12 -05002560// Validate that every component of the pixel will be equal to the luminance value we've set
2561// and that the alpha channel will be 1 (or 255 to be exact).
2562TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2563{
2564 setUpProgram();
2565
2566 glActiveTexture(GL_TEXTURE0);
2567 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2568 uint8_t pixel = 50;
2569 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2570 EXPECT_GL_NO_ERROR();
2571
2572 drawQuad(mProgram, "position", 0.5f);
2573
2574 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2575}
2576
2577// Validate that every component of the pixel will be equal to the luminance value we've set
2578// and that the alpha channel will be the second component.
2579TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2580{
2581 setUpProgram();
2582
2583 glActiveTexture(GL_TEXTURE0);
2584 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2585 uint8_t pixel[] = {50, 25};
2586 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2587 GL_UNSIGNED_BYTE, pixel);
2588 EXPECT_GL_NO_ERROR();
2589
2590 drawQuad(mProgram, "position", 0.5f);
2591
2592 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2593}
2594
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002595// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2596// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002597TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002598{
Jamie Madillb8149072019-04-30 16:14:44 -04002599 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002600 ANGLE_SKIP_TEST_IF(IsD3D9());
2601 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002602
2603 setUpProgram();
2604
Luc Ferrond8c632c2018-04-10 12:31:44 -04002605 glActiveTexture(GL_TEXTURE0);
2606 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2607 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2608 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002609
Luc Ferrond8c632c2018-04-10 12:31:44 -04002610 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002611
Luc Ferrond8c632c2018-04-10 12:31:44 -04002612 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002613}
2614
2615// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2616// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002617TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002618{
Jamie Madillb8149072019-04-30 16:14:44 -04002619 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002620 ANGLE_SKIP_TEST_IF(IsD3D9());
2621 ANGLE_SKIP_TEST_IF(IsVulkan());
2622 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES());
2623 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2624 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002625
Luc Ferrond8c632c2018-04-10 12:31:44 -04002626 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002627
Luc Ferrond8c632c2018-04-10 12:31:44 -04002628 glActiveTexture(GL_TEXTURE0);
2629 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2630 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2631 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002632
Luc Ferrond8c632c2018-04-10 12:31:44 -04002633 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002634
Luc Ferrond8c632c2018-04-10 12:31:44 -04002635 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002636}
2637
2638// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2639// ES 3.0.4 table 3.24
2640TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2641{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002642 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2643
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002644 glActiveTexture(GL_TEXTURE0);
2645 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2646 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2647 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2648 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2649 EXPECT_GL_NO_ERROR();
2650
2651 drawQuad(mProgram, "position", 0.5f);
2652
2653 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2654}
2655
2656// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2657// ES 3.0.4 table 3.24
2658TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2659{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002660 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2661
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002662 glActiveTexture(GL_TEXTURE0);
2663 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2664
2665 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2666 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2667 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2668 EXPECT_GL_NO_ERROR();
2669
2670 drawQuad(mProgram, "position", 0.5f);
2671
2672 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2673}
2674
2675// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2676// ES 3.0.4 table 3.24
2677TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2678{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002679 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2680
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002681 glActiveTexture(GL_TEXTURE0);
2682 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2683 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2684 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2685 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2686 EXPECT_GL_NO_ERROR();
2687
2688 drawQuad(mProgram, "position", 0.5f);
2689
2690 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2691}
2692
2693// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2694// ES 3.0.4 table 3.24
2695TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2696{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002697 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2698
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002699 glActiveTexture(GL_TEXTURE0);
2700 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2701 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2702 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2703 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2704 EXPECT_GL_NO_ERROR();
2705
2706 drawQuad(mProgram, "position", 0.5f);
2707
2708 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2709}
2710
2711// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2712// ES 3.0.4 table 3.24
2713TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2714{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002715 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2716
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002717 glActiveTexture(GL_TEXTURE0);
2718 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2719 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2720 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2721 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2722 EXPECT_GL_NO_ERROR();
2723
2724 drawQuad(mProgram, "position", 0.5f);
2725
2726 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2727}
2728
2729// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2730// ES 3.0.4 table 3.24
2731TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2732{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002733 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2734
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002735 glActiveTexture(GL_TEXTURE0);
2736 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2737 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2738 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2739 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2740 EXPECT_GL_NO_ERROR();
2741
2742 drawQuad(mProgram, "position", 0.5f);
2743
2744 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2745}
2746
2747// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2748// ES 3.0.4 table 3.24
2749TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2750{
2751 glActiveTexture(GL_TEXTURE0);
2752 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2753 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
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(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2764{
2765 glActiveTexture(GL_TEXTURE0);
2766 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2767 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2768 nullptr);
2769 EXPECT_GL_NO_ERROR();
2770
2771 drawQuad(mProgram, "position", 0.5f);
2772
2773 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2774}
2775
2776// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2777// ES 3.0.4 table 3.24
2778TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2779{
Yunchao He9550c602018-02-13 14:47:05 +08002780 // Seems to fail on OSX 10.12 Intel.
2781 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Jamie Madillbb1db482017-01-10 10:48:32 -05002782
Yuly Novikov49886892018-01-23 21:18:27 -05002783 // http://anglebug.com/2190
2784 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2785
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002786 glActiveTexture(GL_TEXTURE0);
2787 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2788 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2789 EXPECT_GL_NO_ERROR();
2790
2791 drawQuad(mProgram, "position", 0.5f);
2792
2793 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2794}
2795
2796// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2797// ES 3.0.4 table 3.24
2798TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2799{
Yunchao He9550c602018-02-13 14:47:05 +08002800 // Seems to fail on OSX 10.12 Intel.
2801 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002802
Yuly Novikov49886892018-01-23 21:18:27 -05002803 // http://anglebug.com/2190
2804 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2805
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002806 glActiveTexture(GL_TEXTURE0);
2807 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2808 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2809 EXPECT_GL_NO_ERROR();
2810
2811 drawQuad(mProgram, "position", 0.5f);
2812
2813 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2814}
2815
Olli Etuaho96963162016-03-21 11:54:33 +02002816// Use a sampler in a uniform struct.
2817TEST_P(SamplerInStructTest, SamplerInStruct)
2818{
2819 runSamplerInStructTest();
2820}
2821
2822// Use a sampler in a uniform struct that's passed as a function parameter.
2823TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2824{
Yuly Novikovd18c0482019-04-04 19:56:43 -04002825 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
2826 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002827
Olli Etuaho96963162016-03-21 11:54:33 +02002828 runSamplerInStructTest();
2829}
2830
2831// Use a sampler in a uniform struct array with a struct from the array passed as a function
2832// parameter.
2833TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2834{
Yuly Novikovd18c0482019-04-04 19:56:43 -04002835 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
2836 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08002837
Olli Etuaho96963162016-03-21 11:54:33 +02002838 runSamplerInStructTest();
2839}
2840
2841// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2842// parameter.
2843TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2844{
Yuly Novikovd18c0482019-04-04 19:56:43 -04002845 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
2846 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08002847
Olli Etuaho96963162016-03-21 11:54:33 +02002848 runSamplerInStructTest();
2849}
2850
2851// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2852// similarly named uniform.
2853TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2854{
2855 runSamplerInStructTest();
2856}
2857
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05002858// GL_EXT_texture_filter_anisotropic
2859class TextureAnisotropyTest : public Texture2DTest
2860{
2861 protected:
2862 void uploadTexture()
2863 {
2864 glActiveTexture(GL_TEXTURE0);
2865 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2866 GLColor texDataRed[1] = {GLColor::red};
2867 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed);
2868 EXPECT_GL_NO_ERROR();
2869 }
2870};
2871
2872// Tests that setting anisotropic filtering doesn't cause failures at draw time.
2873TEST_P(TextureAnisotropyTest, AnisotropyFunctional)
2874{
Jamie Madillb8149072019-04-30 16:14:44 -04002875 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_filter_anisotropic"));
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05002876
2877 setUpProgram();
2878
2879 uploadTexture();
2880
2881 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2882 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2883 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f);
2884 EXPECT_GL_NO_ERROR();
2885
2886 drawQuad(mProgram, "position", 0.5f);
2887
2888 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
2889 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
2890 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::red);
2891}
2892
Till Rathmannb8543632018-10-02 19:46:14 +02002893// GL_OES_texture_border_clamp
2894class TextureBorderClampTest : public Texture2DTest
2895{
2896 protected:
2897 TextureBorderClampTest() : Texture2DTest() {}
2898
Jamie Madill35cd7332018-12-02 12:03:33 -05002899 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02002900 {
2901 return
2902 R"(precision highp float;
2903 attribute vec4 position;
2904 varying vec2 texcoord;
2905
2906 void main()
2907 {
2908 gl_Position = vec4(position.xy, 0.0, 1.0);
2909 // texcoords in [-0.5, 1.5]
2910 texcoord = (position.xy) + 0.5;
2911 })";
2912 }
2913
2914 void uploadTexture()
2915 {
2916 glActiveTexture(GL_TEXTURE0);
2917 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2918 std::vector<GLColor> texDataRed(1, GLColor::red);
2919 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2920 texDataRed.data());
2921 EXPECT_GL_NO_ERROR();
2922 }
2923};
2924
2925// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
2926// GL_CLAMP_TO_BORDER wrap mode (set with glTexParameter).
2927TEST_P(TextureBorderClampTest, TextureBorderClampFunctional)
2928{
Jamie Madillb8149072019-04-30 16:14:44 -04002929 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02002930
2931 setUpProgram();
2932
2933 uploadTexture();
2934
2935 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
2936 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
2937 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2938 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2939 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2940 EXPECT_GL_NO_ERROR();
2941
2942 drawQuad(mProgram, "position", 0.5f);
2943
2944 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
2945 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2946 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
2947}
2948
2949// Test reading back GL_TEXTURE_BORDER_COLOR by glGetTexParameter.
2950TEST_P(TextureBorderClampTest, TextureBorderClampFunctional2)
2951{
Jamie Madillb8149072019-04-30 16:14:44 -04002952 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02002953
2954 glActiveTexture(GL_TEXTURE0);
2955 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2956
2957 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2958
2959 GLint colorFixedPoint[4] = {0};
2960 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
2961 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
2962 std::numeric_limits<GLint>::max()};
2963 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
2964 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
2965 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
2966 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
2967
2968 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
2969 std::numeric_limits<GLint>::max()};
2970 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
2971
2972 GLfloat color[4] = {0.0f};
2973 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
2974 EXPECT_EQ(color[0], kFloatBlue.R);
2975 EXPECT_EQ(color[1], kFloatBlue.G);
2976 EXPECT_EQ(color[2], kFloatBlue.B);
2977 EXPECT_EQ(color[3], kFloatBlue.A);
2978}
2979
2980// Test GL_TEXTURE_BORDER_COLOR parameter validation at glTexParameter.
2981TEST_P(TextureBorderClampTest, TextureBorderClampValidation)
2982{
Jamie Madillb8149072019-04-30 16:14:44 -04002983 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02002984
2985 glActiveTexture(GL_TEXTURE0);
2986 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2987
2988 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, 1.0f);
2989 EXPECT_GL_ERROR(GL_INVALID_ENUM);
2990
2991 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
2992 EXPECT_GL_ERROR(GL_INVALID_ENUM);
2993
2994 glTexParameterfv(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2995 EXPECT_GL_ERROR(GL_INVALID_ENUM);
2996
2997 GLint colorInt[4] = {0};
2998 glTexParameteriv(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_BORDER_COLOR, colorInt);
2999 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3000
3001 if (getClientMajorVersion() < 3)
3002 {
3003 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3004 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3005 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3006 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3007
3008 GLuint colorUInt[4] = {0};
3009 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3010 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3011 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3012 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3013
3014 GLSampler sampler;
3015 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3016 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3017 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3018 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3019
3020 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3021 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3022 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3023 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3024 }
3025}
3026
3027class TextureBorderClampTestES3 : public TextureBorderClampTest
3028{
3029 protected:
3030 TextureBorderClampTestES3() : TextureBorderClampTest() {}
3031};
3032
3033// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3034// GL_CLAMP_TO_BORDER wrap mode (set with glSamplerParameter).
3035TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional)
3036{
Jamie Madillb8149072019-04-30 16:14:44 -04003037 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003038
3039 setUpProgram();
3040
3041 uploadTexture();
3042
3043 GLSampler sampler;
3044 glBindSampler(0, sampler);
3045 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3046 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3047 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3048 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3049 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3050 EXPECT_GL_NO_ERROR();
3051
3052 drawQuad(mProgram, "position", 0.5f);
3053
3054 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3055 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3056 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3057}
3058
3059// Test reading back GL_TEXTURE_BORDER_COLOR by glGetSamplerParameter.
3060TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional2)
3061{
Jamie Madillb8149072019-04-30 16:14:44 -04003062 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003063
3064 glActiveTexture(GL_TEXTURE0);
3065
3066 GLSampler sampler;
3067 glBindSampler(0, sampler);
3068
3069 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3070
3071 GLint colorFixedPoint[4] = {0};
3072 glGetSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3073 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3074 std::numeric_limits<GLint>::max()};
3075 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3076 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3077 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3078 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3079
3080 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3081 std::numeric_limits<GLint>::max()};
3082 glSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3083
3084 GLfloat color[4] = {0.0f};
3085 glGetSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, color);
3086 EXPECT_EQ(color[0], kFloatBlue.R);
3087 EXPECT_EQ(color[1], kFloatBlue.G);
3088 EXPECT_EQ(color[2], kFloatBlue.B);
3089 EXPECT_EQ(color[3], kFloatBlue.A);
3090
3091 constexpr GLint colorSomewhatRedInt[4] = {500000, 0, 0, std::numeric_limits<GLint>::max()};
3092 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedInt);
3093 GLint colorInt[4] = {0};
3094 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3095 EXPECT_EQ(colorInt[0], colorSomewhatRedInt[0]);
3096 EXPECT_EQ(colorInt[1], colorSomewhatRedInt[1]);
3097 EXPECT_EQ(colorInt[2], colorSomewhatRedInt[2]);
3098 EXPECT_EQ(colorInt[3], colorSomewhatRedInt[3]);
3099
3100 constexpr GLuint colorSomewhatRedUInt[4] = {500000, 0, 0, std::numeric_limits<GLuint>::max()};
3101 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedUInt);
3102 GLuint colorUInt[4] = {0};
3103 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3104 EXPECT_EQ(colorUInt[0], colorSomewhatRedUInt[0]);
3105 EXPECT_EQ(colorUInt[1], colorSomewhatRedUInt[1]);
3106 EXPECT_EQ(colorUInt[2], colorSomewhatRedUInt[2]);
3107 EXPECT_EQ(colorUInt[3], colorSomewhatRedUInt[3]);
3108
3109 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3110
3111 constexpr GLint colorSomewhatGreenInt[4] = {0, 500000, 0, std::numeric_limits<GLint>::max()};
3112 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenInt);
3113 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3114 EXPECT_EQ(colorInt[0], colorSomewhatGreenInt[0]);
3115 EXPECT_EQ(colorInt[1], colorSomewhatGreenInt[1]);
3116 EXPECT_EQ(colorInt[2], colorSomewhatGreenInt[2]);
3117 EXPECT_EQ(colorInt[3], colorSomewhatGreenInt[3]);
3118
3119 constexpr GLuint colorSomewhatGreenUInt[4] = {0, 500000, 0, std::numeric_limits<GLuint>::max()};
3120 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenUInt);
3121 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3122 EXPECT_EQ(colorUInt[0], colorSomewhatGreenUInt[0]);
3123 EXPECT_EQ(colorUInt[1], colorSomewhatGreenUInt[1]);
3124 EXPECT_EQ(colorUInt[2], colorSomewhatGreenUInt[2]);
3125 EXPECT_EQ(colorUInt[3], colorSomewhatGreenUInt[3]);
3126}
3127
3128// Test GL_TEXTURE_BORDER_COLOR parameter validation at glSamplerParameter.
3129TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Validation)
3130{
Jamie Madillb8149072019-04-30 16:14:44 -04003131 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003132
3133 glActiveTexture(GL_TEXTURE0);
3134
3135 GLSampler sampler;
3136 glBindSampler(0, sampler);
3137
3138 glSamplerParameterf(sampler, GL_TEXTURE_BORDER_COLOR, 1.0f);
3139 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3140
3141 glSamplerParameteri(sampler, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3142 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3143}
3144
3145class TextureBorderClampIntegerTestES3 : public Texture2DTest
3146{
3147 protected:
3148 TextureBorderClampIntegerTestES3() : Texture2DTest(), isUnsignedIntTest(false) {}
3149
Jamie Madill35cd7332018-12-02 12:03:33 -05003150 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003151 {
3152 return
3153 R"(#version 300 es
3154 out vec2 texcoord;
3155 in vec4 position;
3156
3157 void main()
3158 {
3159 gl_Position = vec4(position.xy, 0.0, 1.0);
3160 // texcoords in [-0.5, 1.5]
3161 texcoord = (position.xy) + 0.5;
3162 })";
3163 }
3164
Jamie Madillba319ba2018-12-29 10:29:33 -05003165 const char *getFragmentShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003166 {
Jamie Madill35cd7332018-12-02 12:03:33 -05003167 if (isUnsignedIntTest)
3168 {
3169 return "#version 300 es\n"
3170 "precision highp float;\n"
3171 "uniform highp usampler2D tex;\n"
3172 "in vec2 texcoord;\n"
3173 "out vec4 fragColor;\n"
Till Rathmannb8543632018-10-02 19:46:14 +02003174
Jamie Madill35cd7332018-12-02 12:03:33 -05003175 "void main()\n"
3176 "{\n"
3177 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3178 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3179 "fragColor = (texture(tex, texcoord).r == 150u)"
3180 " ? green : red;\n"
3181 "}\n";
3182 }
3183 else
3184 {
3185 return "#version 300 es\n"
3186 "precision highp float;\n"
3187 "uniform highp isampler2D tex;\n"
3188 "in vec2 texcoord;\n"
3189 "out vec4 fragColor;\n"
3190
3191 "void main()\n"
3192 "{\n"
3193 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3194 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3195 "fragColor = (texture(tex, texcoord).r == -50)"
3196 " ? green : red;\n"
3197 "}\n";
3198 }
Till Rathmannb8543632018-10-02 19:46:14 +02003199 }
3200
3201 void uploadTexture()
3202 {
3203 glActiveTexture(GL_TEXTURE0);
3204 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3205 if (isUnsignedIntTest)
3206 {
3207 std::vector<GLubyte> texData(4, 100);
3208 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE,
3209 texData.data());
3210 }
3211 else
3212 {
3213 std::vector<GLbyte> texData(4, 100);
3214 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8I, 1, 1, 0, GL_RGBA_INTEGER, GL_BYTE,
3215 texData.data());
3216 }
3217 EXPECT_GL_NO_ERROR();
3218 }
3219
3220 bool isUnsignedIntTest;
3221};
3222
3223// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3224// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3225TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger)
3226{
Jamie Madillb8149072019-04-30 16:14:44 -04003227 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003228
3229 setUpProgram();
3230
3231 uploadTexture();
3232
3233 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3234 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3235 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3236 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3237
3238 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3239 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3240
3241 EXPECT_GL_NO_ERROR();
3242
3243 drawQuad(mProgram, "position", 0.5f);
3244
3245 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3246 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3247 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3248}
3249
3250// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3251// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3252TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger2)
3253{
Jamie Madillb8149072019-04-30 16:14:44 -04003254 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003255
3256 setUpProgram();
3257
3258 uploadTexture();
3259
3260 GLSampler sampler;
3261 glBindSampler(0, sampler);
3262 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3263 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3264 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3265 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3266
3267 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3268 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3269
3270 EXPECT_GL_NO_ERROR();
3271
3272 drawQuad(mProgram, "position", 0.5f);
3273
3274 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3275 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3276 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3277}
3278
3279// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3280// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIuivOES).
3281TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned)
3282{
Jamie Madillb8149072019-04-30 16:14:44 -04003283 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003284
3285 isUnsignedIntTest = true;
3286
3287 setUpProgram();
3288
3289 uploadTexture();
3290
3291 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3292 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3293 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3294 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3295
3296 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3297 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3298
3299 EXPECT_GL_NO_ERROR();
3300
3301 drawQuad(mProgram, "position", 0.5f);
3302
3303 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3304 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3305 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3306}
3307
3308// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3309// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with
3310// glSamplerParameterIuivOES).
3311TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned2)
3312{
Jamie Madillb8149072019-04-30 16:14:44 -04003313 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003314
3315 isUnsignedIntTest = true;
3316
3317 setUpProgram();
3318
3319 uploadTexture();
3320
3321 GLSampler sampler;
3322 glBindSampler(0, sampler);
3323 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3324 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3325 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3326 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3327
3328 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3329 glSamplerParameterIuivOES(sampler, 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// ~GL_OES_texture_border_clamp
3341
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003342class TextureLimitsTest : public ANGLETest
3343{
3344 protected:
3345 struct RGBA8
3346 {
3347 uint8_t R, G, B, A;
3348 };
3349
3350 TextureLimitsTest()
3351 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
3352 {
3353 setWindowWidth(128);
3354 setWindowHeight(128);
3355 setConfigRedBits(8);
3356 setConfigGreenBits(8);
3357 setConfigBlueBits(8);
3358 setConfigAlphaBits(8);
3359 }
3360
Jamie Madill0fdb9562018-09-17 17:18:43 -04003361 void SetUp() override
3362 {
3363 ANGLETest::SetUp();
3364
3365 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
3366 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
3367 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
3368
3369 ASSERT_GL_NO_ERROR();
3370 }
3371
3372 void TearDown() override
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003373 {
3374 if (mProgram != 0)
3375 {
3376 glDeleteProgram(mProgram);
3377 mProgram = 0;
3378
3379 if (!mTextures.empty())
3380 {
3381 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
3382 }
3383 }
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003384
Jamie Madill0fdb9562018-09-17 17:18:43 -04003385 ANGLETest::TearDown();
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003386 }
3387
3388 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
3389 GLint vertexTextureCount,
3390 GLint vertexActiveTextureCount,
3391 const std::string &fragPrefix,
3392 GLint fragmentTextureCount,
3393 GLint fragmentActiveTextureCount)
3394 {
3395 std::stringstream vertexShaderStr;
3396 vertexShaderStr << "attribute vec2 position;\n"
3397 << "varying vec4 color;\n"
3398 << "varying vec2 texCoord;\n";
3399
3400 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
3401 {
3402 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
3403 }
3404
3405 vertexShaderStr << "void main() {\n"
3406 << " gl_Position = vec4(position, 0, 1);\n"
3407 << " texCoord = (position * 0.5) + 0.5;\n"
3408 << " color = vec4(0);\n";
3409
3410 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
3411 {
3412 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
3413 << ", texCoord);\n";
3414 }
3415
3416 vertexShaderStr << "}";
3417
3418 std::stringstream fragmentShaderStr;
3419 fragmentShaderStr << "varying mediump vec4 color;\n"
3420 << "varying mediump vec2 texCoord;\n";
3421
3422 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
3423 {
3424 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
3425 }
3426
3427 fragmentShaderStr << "void main() {\n"
3428 << " gl_FragColor = color;\n";
3429
3430 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
3431 {
3432 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
3433 << ", texCoord);\n";
3434 }
3435
3436 fragmentShaderStr << "}";
3437
3438 const std::string &vertexShaderSource = vertexShaderStr.str();
3439 const std::string &fragmentShaderSource = fragmentShaderStr.str();
3440
Jamie Madill35cd7332018-12-02 12:03:33 -05003441 mProgram = CompileProgram(vertexShaderSource.c_str(), fragmentShaderSource.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003442 }
3443
3444 RGBA8 getPixel(GLint texIndex)
3445 {
3446 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3447 0, 255u};
3448 return pixel;
3449 }
3450
3451 void initTextures(GLint tex2DCount, GLint texCubeCount)
3452 {
3453 GLint totalCount = tex2DCount + texCubeCount;
3454 mTextures.assign(totalCount, 0);
3455 glGenTextures(totalCount, &mTextures[0]);
3456 ASSERT_GL_NO_ERROR();
3457
3458 std::vector<RGBA8> texData(16 * 16);
3459
3460 GLint texIndex = 0;
3461 for (; texIndex < tex2DCount; ++texIndex)
3462 {
3463 texData.assign(texData.size(), getPixel(texIndex));
3464 glActiveTexture(GL_TEXTURE0 + texIndex);
3465 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3466 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3467 &texData[0]);
3468 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3469 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3470 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3471 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3472 }
3473
3474 ASSERT_GL_NO_ERROR();
3475
3476 for (; texIndex < texCubeCount; ++texIndex)
3477 {
3478 texData.assign(texData.size(), getPixel(texIndex));
3479 glActiveTexture(GL_TEXTURE0 + texIndex);
3480 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3481 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3482 GL_UNSIGNED_BYTE, &texData[0]);
3483 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3484 GL_UNSIGNED_BYTE, &texData[0]);
3485 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3486 GL_UNSIGNED_BYTE, &texData[0]);
3487 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3488 GL_UNSIGNED_BYTE, &texData[0]);
3489 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3490 GL_UNSIGNED_BYTE, &texData[0]);
3491 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3492 GL_UNSIGNED_BYTE, &texData[0]);
3493 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3494 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3495 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3496 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3497 }
3498
3499 ASSERT_GL_NO_ERROR();
3500 }
3501
3502 void testWithTextures(GLint vertexTextureCount,
3503 const std::string &vertexTexturePrefix,
3504 GLint fragmentTextureCount,
3505 const std::string &fragmentTexturePrefix)
3506 {
3507 // Generate textures
3508 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3509
3510 glUseProgram(mProgram);
3511 RGBA8 expectedSum = {0};
3512 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3513 {
3514 std::stringstream uniformNameStr;
3515 uniformNameStr << vertexTexturePrefix << texIndex;
3516 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003517 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003518 ASSERT_NE(-1, location);
3519
3520 glUniform1i(location, texIndex);
3521 RGBA8 contribution = getPixel(texIndex);
3522 expectedSum.R += contribution.R;
3523 expectedSum.G += contribution.G;
3524 }
3525
3526 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3527 {
3528 std::stringstream uniformNameStr;
3529 uniformNameStr << fragmentTexturePrefix << texIndex;
3530 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003531 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003532 ASSERT_NE(-1, location);
3533
3534 glUniform1i(location, texIndex + vertexTextureCount);
3535 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3536 expectedSum.R += contribution.R;
3537 expectedSum.G += contribution.G;
3538 }
3539
3540 ASSERT_GE(256u, expectedSum.G);
3541
3542 drawQuad(mProgram, "position", 0.5f);
3543 ASSERT_GL_NO_ERROR();
3544 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3545 }
3546
3547 GLuint mProgram;
3548 std::vector<GLuint> mTextures;
3549 GLint mMaxVertexTextures;
3550 GLint mMaxFragmentTextures;
3551 GLint mMaxCombinedTextures;
3552};
3553
3554// Test rendering with the maximum vertex texture units.
3555TEST_P(TextureLimitsTest, MaxVertexTextures)
3556{
3557 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3558 ASSERT_NE(0u, mProgram);
3559 ASSERT_GL_NO_ERROR();
3560
3561 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3562}
3563
3564// Test rendering with the maximum fragment texture units.
3565TEST_P(TextureLimitsTest, MaxFragmentTextures)
3566{
3567 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3568 ASSERT_NE(0u, mProgram);
3569 ASSERT_GL_NO_ERROR();
3570
3571 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3572}
3573
3574// Test rendering with maximum combined texture units.
3575TEST_P(TextureLimitsTest, MaxCombinedTextures)
3576{
3577 GLint vertexTextures = mMaxVertexTextures;
3578
3579 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3580 {
3581 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3582 }
3583
3584 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3585 mMaxFragmentTextures, mMaxFragmentTextures);
3586 ASSERT_NE(0u, mProgram);
3587 ASSERT_GL_NO_ERROR();
3588
3589 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3590}
3591
3592// Negative test for exceeding the number of vertex textures
3593TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3594{
3595 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3596 0);
3597 ASSERT_EQ(0u, mProgram);
3598}
3599
3600// Negative test for exceeding the number of fragment textures
3601TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3602{
3603 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3604 mMaxFragmentTextures + 1);
3605 ASSERT_EQ(0u, mProgram);
3606}
3607
3608// Test active vertex textures under the limit, but excessive textures specified.
3609TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3610{
3611 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3612 ASSERT_NE(0u, mProgram);
3613 ASSERT_GL_NO_ERROR();
3614
3615 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3616}
3617
3618// Test active fragment textures under the limit, but excessive textures specified.
3619TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3620{
3621 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3622 mMaxFragmentTextures);
3623 ASSERT_NE(0u, mProgram);
3624 ASSERT_GL_NO_ERROR();
3625
3626 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3627}
3628
3629// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003630// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003631TEST_P(TextureLimitsTest, TextureTypeConflict)
3632{
Jamie Madill35cd7332018-12-02 12:03:33 -05003633 constexpr char kVS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003634 "attribute vec2 position;\n"
3635 "varying float color;\n"
3636 "uniform sampler2D tex2D;\n"
3637 "uniform samplerCube texCube;\n"
3638 "void main() {\n"
3639 " gl_Position = vec4(position, 0, 1);\n"
3640 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3641 " color = texture2D(tex2D, texCoord).x;\n"
3642 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3643 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05003644 constexpr char kFS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003645 "varying mediump float color;\n"
3646 "void main() {\n"
3647 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3648 "}";
3649
Jamie Madill35cd7332018-12-02 12:03:33 -05003650 mProgram = CompileProgram(kVS, kFS);
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003651 ASSERT_NE(0u, mProgram);
3652
3653 initTextures(1, 0);
3654
3655 glUseProgram(mProgram);
3656 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3657 ASSERT_NE(-1, tex2DLocation);
3658 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3659 ASSERT_NE(-1, texCubeLocation);
3660
3661 glUniform1i(tex2DLocation, 0);
3662 glUniform1i(texCubeLocation, 0);
3663 ASSERT_GL_NO_ERROR();
3664
3665 drawQuad(mProgram, "position", 0.5f);
3666 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3667}
3668
Vincent Lang25ab4512016-05-13 18:13:59 +02003669class Texture2DNorm16TestES3 : public Texture2DTestES3
3670{
3671 protected:
3672 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3673
3674 void SetUp() override
3675 {
3676 Texture2DTestES3::SetUp();
3677
3678 glActiveTexture(GL_TEXTURE0);
3679 glGenTextures(3, mTextures);
3680 glGenFramebuffers(1, &mFBO);
3681 glGenRenderbuffers(1, &mRenderbuffer);
3682
3683 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3684 {
3685 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3686 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3687 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3688 }
3689
3690 glBindTexture(GL_TEXTURE_2D, 0);
3691
3692 ASSERT_GL_NO_ERROR();
3693 }
3694
3695 void TearDown() override
3696 {
3697 glDeleteTextures(3, mTextures);
3698 glDeleteFramebuffers(1, &mFBO);
3699 glDeleteRenderbuffers(1, &mRenderbuffer);
3700
3701 Texture2DTestES3::TearDown();
3702 }
3703
3704 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3705 {
Geoff Langf607c602016-09-21 11:46:48 -04003706 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3707 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003708
3709 setUpProgram();
3710
3711 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3712 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3713 0);
3714
3715 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3716 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3717
3718 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003719 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003720
3721 EXPECT_GL_NO_ERROR();
3722
3723 drawQuad(mProgram, "position", 0.5f);
3724
Geoff Langf607c602016-09-21 11:46:48 -04003725 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003726
Jamie Madill50cf2be2018-06-15 09:46:57 -04003727 EXPECT_PIXEL_COLOR_EQ(0, 0,
3728 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3729 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003730
3731 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3732
3733 ASSERT_GL_NO_ERROR();
3734 }
3735
3736 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3737 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04003738 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003739 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003740
3741 setUpProgram();
3742
3743 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3744 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3745
3746 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3747 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3748 0);
3749
3750 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
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 = static_cast<GLubyte>(pixelValue >> 8);
Jamie Madill50cf2be2018-06-15 09:46:57 -04003758 EXPECT_PIXEL_COLOR_EQ(0, 0,
3759 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3760 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003761
3762 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3763 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3764 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3765 mRenderbuffer);
3766 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3767 EXPECT_GL_NO_ERROR();
3768
3769 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3770 glClear(GL_COLOR_BUFFER_BIT);
3771
3772 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3773
Geoff Langf607c602016-09-21 11:46:48 -04003774 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003775
3776 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3777
3778 ASSERT_GL_NO_ERROR();
3779 }
3780
3781 GLuint mTextures[3];
3782 GLuint mFBO;
3783 GLuint mRenderbuffer;
3784};
3785
3786// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3787TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3788{
Jamie Madillb8149072019-04-30 16:14:44 -04003789 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02003790
3791 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3792 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3793 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3794 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3795 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3796 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3797 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3798 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3799
3800 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3801 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3802 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3803}
3804
Olli Etuaho95faa232016-06-07 14:01:53 -07003805// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3806// GLES 3.0.4 section 3.8.3.
3807TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3808{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003809 // Crashes on Nexus 5X due to a driver bug. http://anglebug.com/1429
3810 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07003811
3812 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3813 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3814 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3815 ASSERT_GL_NO_ERROR();
3816
3817 // SKIP_IMAGES should not have an effect on uploading 2D textures
3818 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3819 ASSERT_GL_NO_ERROR();
3820
3821 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3822
3823 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3824 pixelsGreen.data());
3825 ASSERT_GL_NO_ERROR();
3826
3827 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3828 pixelsGreen.data());
3829 ASSERT_GL_NO_ERROR();
3830
3831 glUseProgram(mProgram);
3832 drawQuad(mProgram, "position", 0.5f);
3833 ASSERT_GL_NO_ERROR();
3834
3835 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3836}
3837
Olli Etuaho989cac32016-06-08 16:18:49 -07003838// Test that skip defined in unpack parameters is taken into account when determining whether
3839// unpacking source extends outside unpack buffer bounds.
3840TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3841{
3842 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3843 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3844 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3845 ASSERT_GL_NO_ERROR();
3846
3847 GLBuffer buf;
3848 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3849 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3850 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3851 GL_DYNAMIC_COPY);
3852 ASSERT_GL_NO_ERROR();
3853
3854 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3855 ASSERT_GL_NO_ERROR();
3856
3857 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3858 ASSERT_GL_NO_ERROR();
3859
3860 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3861 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3862
3863 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3864 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3865 ASSERT_GL_NO_ERROR();
3866
3867 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3868 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3869}
3870
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003871// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3872TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3873{
Yunchao He9550c602018-02-13 14:47:05 +08003874 ANGLE_SKIP_TEST_IF(IsD3D11());
3875
3876 // Incorrect rendering results seen on OSX AMD.
3877 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003878
3879 const GLuint width = 8u;
3880 const GLuint height = 8u;
3881 const GLuint unpackRowLength = 5u;
3882 const GLuint unpackSkipPixels = 1u;
3883
3884 setWindowWidth(width);
3885 setWindowHeight(height);
3886
3887 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3888 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3889 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3890 ASSERT_GL_NO_ERROR();
3891
3892 GLBuffer buf;
3893 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3894 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3895 GLColor::green);
3896
3897 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3898 {
3899 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3900 }
3901
3902 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3903 GL_DYNAMIC_COPY);
3904 ASSERT_GL_NO_ERROR();
3905
3906 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3907 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3908 ASSERT_GL_NO_ERROR();
3909
3910 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3911 ASSERT_GL_NO_ERROR();
3912
3913 glUseProgram(mProgram);
3914 drawQuad(mProgram, "position", 0.5f);
3915 ASSERT_GL_NO_ERROR();
3916
3917 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3918 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3919 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3920 actual.data());
3921 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3922 EXPECT_EQ(expected, actual);
3923}
3924
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003925template <typename T>
3926T UNorm(double value)
3927{
3928 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3929}
3930
3931// Test rendering a depth texture with mipmaps.
3932TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3933{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003934 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3935 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
Jiawei Shaoaf0f31d2018-09-27 15:42:31 +08003936 // http://anglebug.com/1706
3937 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Corentin Walleze731d8a2016-09-07 10:56:25 -04003938
Jamie Madill24980272019-04-03 09:03:51 -04003939 // Seems to fail on AMD D3D11. Possibly driver bug. http://anglebug.com/3342
3940 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsD3D11());
3941
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003942 const int size = getWindowWidth();
3943
3944 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003945 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003946
3947 glActiveTexture(GL_TEXTURE0);
3948 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3949 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3950 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3951 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3952 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3953 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3954 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3955 ASSERT_GL_NO_ERROR();
3956
3957 glUseProgram(mProgram);
3958 glUniform1i(mTexture2DUniformLocation, 0);
3959
3960 std::vector<unsigned char> expected;
3961
3962 for (int level = 0; level < levels; ++level)
3963 {
3964 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3965 expected.push_back(UNorm<unsigned char>(value));
3966
3967 int levelDim = dim(level);
3968
3969 ASSERT_GT(levelDim, 0);
3970
3971 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3972 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3973 GL_UNSIGNED_INT, initData.data());
3974 }
3975 ASSERT_GL_NO_ERROR();
3976
3977 for (int level = 0; level < levels; ++level)
3978 {
3979 glViewport(0, 0, dim(level), dim(level));
3980 drawQuad(mProgram, "position", 0.5f);
3981 GLColor actual = ReadColor(0, 0);
3982 EXPECT_NEAR(expected[level], actual.R, 10u);
3983 }
3984
3985 ASSERT_GL_NO_ERROR();
3986}
3987
Jamie Madill7ffdda92016-09-08 13:26:51 -04003988// Tests unpacking into the unsized GL_ALPHA format.
3989TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3990{
Jamie Madill7ffdda92016-09-08 13:26:51 -04003991 // Initialize the texure.
3992 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3993 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3994 GL_UNSIGNED_BYTE, nullptr);
3995 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3996 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3997
3998 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3999
4000 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04004001 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04004002 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4003 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4004 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
4005 GL_STATIC_DRAW);
4006
4007 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
4008 GL_UNSIGNED_BYTE, nullptr);
4009
4010 // Clear to a weird color to make sure we're drawing something.
4011 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
4012 glClear(GL_COLOR_BUFFER_BIT);
4013
4014 // Draw with the alpha texture and verify.
4015 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04004016
4017 ASSERT_GL_NO_ERROR();
4018 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
4019}
4020
Jamie Madill2e600342016-09-19 13:56:40 -04004021// Ensure stale unpack data doesn't propagate in D3D11.
4022TEST_P(Texture2DTestES3, StaleUnpackData)
4023{
4024 // Init unpack buffer.
4025 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
4026 std::vector<GLColor> pixels(pixelCount, GLColor::red);
4027
4028 GLBuffer unpackBuffer;
4029 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4030 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4031 GLsizei bufferSize = pixelCount * sizeof(GLColor);
4032 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
4033
4034 // Create from unpack buffer.
4035 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4036 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
4037 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4038 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4039 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4040
4041 drawQuad(mProgram, "position", 0.5f);
4042
4043 ASSERT_GL_NO_ERROR();
4044 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4045
4046 // Fill unpack with green, recreating buffer.
4047 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
4048 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
4049 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
4050
4051 // Reinit texture with green.
4052 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
4053 GL_UNSIGNED_BYTE, nullptr);
4054
4055 drawQuad(mProgram, "position", 0.5f);
4056
4057 ASSERT_GL_NO_ERROR();
4058 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
4059}
4060
Geoff Langfb7685f2017-11-13 11:44:11 -05004061// Ensure that texture parameters passed as floats that are converted to ints are rounded before
4062// validating they are less than 0.
4063TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
4064{
4065 GLTexture texture;
4066 glBindTexture(GL_TEXTURE_2D, texture);
4067
4068 // Use a negative number that will round to zero when converted to an integer
4069 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
4070 // "Validation of values performed by state-setting commands is performed after conversion,
4071 // unless specified otherwise for a specific command."
4072 GLfloat param = -7.30157126e-07f;
4073 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
4074 EXPECT_GL_NO_ERROR();
4075
4076 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
4077 EXPECT_GL_NO_ERROR();
4078}
4079
Jamie Madillf097e232016-11-05 00:44:15 -04004080// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
4081// being properly checked, and the texture storage of the previous texture format was persisting.
4082// This would result in an ASSERT in debug and incorrect rendering in release.
4083// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
4084TEST_P(Texture3DTestES3, FormatRedefinitionBug)
4085{
4086 GLTexture tex;
4087 glBindTexture(GL_TEXTURE_3D, tex.get());
4088 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4089
4090 GLFramebuffer framebuffer;
4091 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
4092 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
4093
4094 glCheckFramebufferStatus(GL_FRAMEBUFFER);
4095
4096 std::vector<uint8_t> pixelData(100, 0);
4097
4098 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
4099 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
4100 pixelData.data());
4101
4102 ASSERT_GL_NO_ERROR();
4103}
4104
Corentin Wallezd2627992017-04-28 17:17:03 -04004105// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
4106TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
4107{
4108 // 2D tests
4109 {
4110 GLTexture tex;
4111 glBindTexture(GL_TEXTURE_2D, tex.get());
4112
4113 GLBuffer pbo;
4114 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4115
4116 // Test OOB
4117 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
4118 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4119 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4120
4121 // Test OOB
4122 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
4123 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4124 ASSERT_GL_NO_ERROR();
4125 }
4126
4127 // 3D tests
4128 {
4129 GLTexture tex;
4130 glBindTexture(GL_TEXTURE_3D, tex.get());
4131
4132 GLBuffer pbo;
4133 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4134
4135 // Test OOB
4136 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
4137 GL_STATIC_DRAW);
4138 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4139 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4140
4141 // Test OOB
4142 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
4143 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4144 ASSERT_GL_NO_ERROR();
4145 }
4146}
4147
Jamie Madill3ed60422017-09-07 11:32:52 -04004148// Tests behaviour with a single texture and multiple sampler objects.
4149TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
4150{
4151 GLint maxTextureUnits = 0;
4152 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
4153 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
4154
4155 constexpr int kSize = 16;
4156
4157 // Make a single-level texture, fill it with red.
4158 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
4159 GLTexture tex;
4160 glBindTexture(GL_TEXTURE_2D, tex);
4161 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4162 redColors.data());
4163 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4164 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4165
4166 // Simple sanity check.
4167 draw2DTexturedQuad(0.5f, 1.0f, true);
4168 ASSERT_GL_NO_ERROR();
4169 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4170
4171 // Bind texture to unit 1 with a sampler object making it incomplete.
4172 GLSampler sampler;
4173 glBindSampler(0, sampler);
4174 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4175 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4176
4177 // Make a mipmap texture, fill it with blue.
4178 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
4179 GLTexture mipmapTex;
4180 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4181 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4182 blueColors.data());
4183 glGenerateMipmap(GL_TEXTURE_2D);
4184
4185 // Draw with the sampler, expect blue.
4186 draw2DTexturedQuad(0.5f, 1.0f, true);
4187 ASSERT_GL_NO_ERROR();
4188 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
4189
4190 // Simple multitexturing program.
Jamie Madill35cd7332018-12-02 12:03:33 -05004191 constexpr char kVS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004192 "#version 300 es\n"
4193 "in vec2 position;\n"
4194 "out vec2 texCoord;\n"
4195 "void main()\n"
4196 "{\n"
4197 " gl_Position = vec4(position, 0, 1);\n"
4198 " texCoord = position * 0.5 + vec2(0.5);\n"
4199 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05004200
4201 constexpr char kFS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004202 "#version 300 es\n"
4203 "precision mediump float;\n"
4204 "in vec2 texCoord;\n"
4205 "uniform sampler2D tex1;\n"
4206 "uniform sampler2D tex2;\n"
4207 "uniform sampler2D tex3;\n"
4208 "uniform sampler2D tex4;\n"
4209 "out vec4 color;\n"
4210 "void main()\n"
4211 "{\n"
4212 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
4213 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
4214 "}";
4215
Jamie Madill35cd7332018-12-02 12:03:33 -05004216 ANGLE_GL_PROGRAM(program, kVS, kFS);
Jamie Madill3ed60422017-09-07 11:32:52 -04004217
4218 std::array<GLint, 4> texLocations = {
4219 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
4220 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
4221 for (GLint location : texLocations)
4222 {
4223 ASSERT_NE(-1, location);
4224 }
4225
4226 // Init the uniform data.
4227 glUseProgram(program);
4228 for (GLint location = 0; location < 4; ++location)
4229 {
4230 glUniform1i(texLocations[location], location);
4231 }
4232
4233 // Initialize four samplers
4234 GLSampler samplers[4];
4235
4236 // 0: non-mipped.
4237 glBindSampler(0, samplers[0]);
4238 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4239 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4240
4241 // 1: mipped.
4242 glBindSampler(1, samplers[1]);
4243 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4244 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4245
4246 // 2: non-mipped.
4247 glBindSampler(2, samplers[2]);
4248 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4249 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4250
4251 // 3: mipped.
4252 glBindSampler(3, samplers[3]);
4253 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4254 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4255
4256 // Bind two blue mipped textures and two single layer textures, should all draw.
4257 glActiveTexture(GL_TEXTURE0);
4258 glBindTexture(GL_TEXTURE_2D, tex);
4259
4260 glActiveTexture(GL_TEXTURE1);
4261 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4262
4263 glActiveTexture(GL_TEXTURE2);
4264 glBindTexture(GL_TEXTURE_2D, tex);
4265
4266 glActiveTexture(GL_TEXTURE3);
4267 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4268
4269 ASSERT_GL_NO_ERROR();
4270
4271 drawQuad(program, "position", 0.5f);
4272 ASSERT_GL_NO_ERROR();
4273 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
4274
4275 // Bind four single layer textures, two should be incomplete.
4276 glActiveTexture(GL_TEXTURE1);
4277 glBindTexture(GL_TEXTURE_2D, tex);
4278
4279 glActiveTexture(GL_TEXTURE3);
4280 glBindTexture(GL_TEXTURE_2D, tex);
4281
4282 drawQuad(program, "position", 0.5f);
4283 ASSERT_GL_NO_ERROR();
4284 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
4285}
4286
Martin Radev7e2c0d32017-09-15 14:25:42 +03004287// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
4288// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
4289// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
4290// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
4291// samples the cubemap using a direction vector (1,1,1).
4292TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
4293{
Yunchao He2f23f352018-02-11 22:11:37 +08004294 // Check http://anglebug.com/2155.
4295 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
4296
Jamie Madill35cd7332018-12-02 12:03:33 -05004297 constexpr char kVS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004298 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004299 precision mediump float;
4300 in vec3 pos;
4301 void main() {
4302 gl_Position = vec4(pos, 1.0);
4303 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03004304
Jamie Madill35cd7332018-12-02 12:03:33 -05004305 constexpr char kFS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004306 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004307 precision mediump float;
4308 out vec4 color;
4309 uniform samplerCube uTex;
4310 void main(){
4311 color = texture(uTex, vec3(1.0));
4312 })";
Jamie Madill35cd7332018-12-02 12:03:33 -05004313
4314 ANGLE_GL_PROGRAM(program, kVS, kFS);
Martin Radev7e2c0d32017-09-15 14:25:42 +03004315 glUseProgram(program);
4316
4317 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
4318 glActiveTexture(GL_TEXTURE0);
4319
4320 GLTexture cubeTex;
4321 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
4322
4323 const int kFaceWidth = 1;
4324 const int kFaceHeight = 1;
4325 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
4326 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4327 GL_UNSIGNED_BYTE, texData.data());
4328 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4329 GL_UNSIGNED_BYTE, texData.data());
4330 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4331 GL_UNSIGNED_BYTE, texData.data());
4332 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4333 GL_UNSIGNED_BYTE, texData.data());
4334 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4335 GL_UNSIGNED_BYTE, texData.data());
4336 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4337 GL_UNSIGNED_BYTE, texData.data());
4338 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4339 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4340 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
4341 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
4342 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
4343 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
4344
4345 drawQuad(program, "pos", 0.5f, 1.0f, true);
4346 ASSERT_GL_NO_ERROR();
4347
4348 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4349}
4350
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08004351// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
4352TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
4353{
4354 GLuint texture = create2DTexture();
4355
4356 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
4357 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4358
4359 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
4360 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4361
4362 glDeleteTextures(1, &texture);
4363 EXPECT_GL_NO_ERROR();
4364}
4365
Olli Etuaho023371b2018-04-24 17:43:32 +03004366// Test setting base level after calling generateMipmap on a LUMA texture.
4367// Covers http://anglebug.com/2498
4368TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA)
4369{
4370 glActiveTexture(GL_TEXTURE0);
4371 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4372
4373 constexpr const GLsizei kWidth = 8;
4374 constexpr const GLsizei kHeight = 8;
4375 std::array<GLubyte, kWidth * kHeight * 2> whiteData;
4376 whiteData.fill(255u);
4377
4378 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA,
4379 GL_UNSIGNED_BYTE, whiteData.data());
4380 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
4381 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4382 glGenerateMipmap(GL_TEXTURE_2D);
4383 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
4384 EXPECT_GL_NO_ERROR();
4385
4386 drawQuad(mProgram, "position", 0.5f);
4387 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4388}
4389
Till Rathmannc1551dc2018-08-15 17:04:49 +02004390// Covers a bug in the D3D11 backend: http://anglebug.com/2772
4391// When using a sampler the texture was created as if it has mipmaps,
4392// regardless what you specified in GL_TEXTURE_MIN_FILTER via
4393// glSamplerParameteri() -- mistakenly the default value
4394// GL_NEAREST_MIPMAP_LINEAR or the value set via glTexParameteri() was
4395// evaluated.
4396// If you didn't provide mipmaps and didn't let the driver generate them
4397// this led to not sampling your texture data when minification occurred.
4398TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping)
4399{
Jamie Madill35cd7332018-12-02 12:03:33 -05004400 constexpr char kVS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004401 "#version 300 es\n"
4402 "out vec2 texcoord;\n"
4403 "in vec4 position;\n"
4404 "void main()\n"
4405 "{\n"
4406 " gl_Position = vec4(position.xy * 0.1, 0.0, 1.0);\n"
4407 " texcoord = (position.xy * 0.5) + 0.5;\n"
4408 "}\n";
4409
Jamie Madill35cd7332018-12-02 12:03:33 -05004410 constexpr char kFS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004411 "#version 300 es\n"
4412 "precision highp float;\n"
4413 "uniform highp sampler2D tex;\n"
4414 "in vec2 texcoord;\n"
4415 "out vec4 fragColor;\n"
4416 "void main()\n"
4417 "{\n"
4418 " fragColor = texture(tex, texcoord);\n"
4419 "}\n";
Jamie Madill35cd7332018-12-02 12:03:33 -05004420
4421 ANGLE_GL_PROGRAM(program, kVS, kFS);
Till Rathmannc1551dc2018-08-15 17:04:49 +02004422
4423 GLSampler sampler;
4424 glBindSampler(0, sampler);
4425 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4426 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4427
4428 glActiveTexture(GL_TEXTURE0);
4429 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4430
4431 const GLsizei texWidth = getWindowWidth();
4432 const GLsizei texHeight = getWindowHeight();
4433 const std::vector<GLColor> whiteData(texWidth * texHeight, GLColor::white);
4434
4435 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4436 whiteData.data());
4437 EXPECT_GL_NO_ERROR();
4438
4439 drawQuad(program, "position", 0.5f);
4440 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, angle::GLColor::white);
4441}
4442
Jamie Madill50cf2be2018-06-15 09:46:57 -04004443// Use this to select which configurations (e.g. which renderer, which GLES major version) these
4444// tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -05004445ANGLE_INSTANTIATE_TEST(Texture2DTest,
4446 ES2_D3D9(),
4447 ES2_D3D11(),
4448 ES2_D3D11_FL9_3(),
4449 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05004450 ES2_OPENGLES(),
4451 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004452ANGLE_INSTANTIATE_TEST(TextureCubeTest,
4453 ES2_D3D9(),
4454 ES2_D3D11(),
Geoff Langf7480ad2017-10-24 11:46:02 -04004455 ES2_D3D11_FL10_0(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004456 ES2_D3D11_FL9_3(),
4457 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004458 ES2_OPENGLES(),
4459 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004460ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
4461 ES2_D3D9(),
4462 ES2_D3D11(),
4463 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004464 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004465 ES2_OPENGLES(),
4466 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004467ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
4468 ES2_D3D9(),
4469 ES2_D3D11(),
4470 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004471 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004472 ES2_OPENGLES(),
4473 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004474ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
4475 ES2_D3D9(),
4476 ES2_D3D11(),
4477 ES2_D3D11_FL9_3(),
4478 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004479 ES2_OPENGLES(),
4480 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004481ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
4482 ES2_D3D9(),
4483 ES2_D3D11(),
4484 ES2_D3D11_FL9_3(),
4485 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004486 ES2_OPENGLES(),
4487 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004488ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02004489ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02004490ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4491ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
4492 ES3_D3D11(),
4493 ES3_OPENGL(),
4494 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004495ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
4496 ES3_D3D11(),
4497 ES3_OPENGL(),
4498 ES3_OPENGLES());
4499ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4500ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02004501ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02004502ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
4503 ES2_D3D11(),
4504 ES2_D3D11_FL9_3(),
4505 ES2_D3D9(),
4506 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004507 ES2_OPENGLES(),
4508 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004509ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
4510 ES2_D3D11(),
4511 ES2_D3D11_FL9_3(),
4512 ES2_D3D9(),
4513 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004514 ES2_OPENGLES(),
4515 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004516ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
4517 ES2_D3D11(),
4518 ES2_D3D11_FL9_3(),
4519 ES2_D3D9(),
4520 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004521 ES2_OPENGLES(),
4522 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004523ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
4524 ES2_D3D11(),
4525 ES2_D3D11_FL9_3(),
4526 ES2_D3D9(),
4527 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004528 ES2_OPENGLES(),
4529 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004530ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
4531 ES2_D3D11(),
4532 ES2_D3D11_FL9_3(),
4533 ES2_D3D9(),
4534 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004535 ES2_OPENGLES(),
4536 ES2_VULKAN());
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05004537ANGLE_INSTANTIATE_TEST(TextureAnisotropyTest,
4538 ES2_D3D11(),
4539 ES2_D3D9(),
4540 ES2_OPENGL(),
4541 ES2_OPENGLES(),
4542 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02004543ANGLE_INSTANTIATE_TEST(TextureBorderClampTest,
4544 ES2_D3D11(),
4545 ES2_D3D9(),
4546 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004547 ES2_OPENGLES(),
4548 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02004549ANGLE_INSTANTIATE_TEST(TextureBorderClampTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4550ANGLE_INSTANTIATE_TEST(TextureBorderClampIntegerTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Luc Ferronaf883622018-06-08 15:57:31 -04004551ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN());
Vincent Lang25ab4512016-05-13 18:13:59 +02004552ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03004553ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04004554
Jamie Madill7ffdda92016-09-08 13:26:51 -04004555} // anonymous namespace