blob: 14464c95939317efcabe236697c7dfeb0a7a2d6a [file] [log] [blame]
Jamie Madillfa05f602015-05-07 13:47:11 -04001//
2// Copyright 2015 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Jamie Madill14718762016-09-06 15:56:54 -04007#include "common/mathutil.h"
Corentin Wallezd3970de2015-05-14 11:07:48 -04008#include "test_utils/ANGLETest.h"
Olli Etuaho989cac32016-06-08 16:18:49 -07009#include "test_utils/gl_raii.h"
Jamie Madillf67115c2014-04-22 13:14:05 -040010
Jamie Madillfa05f602015-05-07 13:47:11 -040011using namespace angle;
Austin Kinross18b931d2014-09-29 12:58:31 -070012
Jamie Madillfa05f602015-05-07 13:47:11 -040013namespace
14{
15
Vincent Lang25ab4512016-05-13 18:13:59 +020016// Take a pixel, and reset the components not covered by the format to default
Geoff Langf607c602016-09-21 11:46:48 -040017// values. In particular, the default value for the alpha component is 255
Vincent Lang25ab4512016-05-13 18:13:59 +020018// (1.0 as unsigned normalized fixed point value).
Geoff Langf607c602016-09-21 11:46:48 -040019GLColor SliceFormatColor(GLenum format, GLColor full)
Vincent Lang25ab4512016-05-13 18:13:59 +020020{
21 switch (format)
22 {
23 case GL_RED:
Geoff Langf607c602016-09-21 11:46:48 -040024 return GLColor(full.R, 0, 0, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020025 case GL_RG:
Geoff Langf607c602016-09-21 11:46:48 -040026 return GLColor(full.R, full.G, 0, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020027 case GL_RGB:
Geoff Langf607c602016-09-21 11:46:48 -040028 return GLColor(full.R, full.G, full.B, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020029 case GL_RGBA:
30 return full;
31 default:
Jamie Madille1faacb2016-12-13 12:42:14 -050032 EXPECT_TRUE(false);
Geoff Langf607c602016-09-21 11:46:48 -040033 return GLColor::white;
Vincent Lang25ab4512016-05-13 18:13:59 +020034 }
Vincent Lang25ab4512016-05-13 18:13:59 +020035}
36
Olli Etuaho4a8329f2016-01-11 17:12:57 +020037class TexCoordDrawTest : public ANGLETest
Jamie Madillf67115c2014-04-22 13:14:05 -040038{
Jamie Madillbc393df2015-01-29 13:46:07 -050039 protected:
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020040 TexCoordDrawTest() : ANGLETest(), mProgram(0), mFramebuffer(0), mFramebufferColorTexture(0)
Jamie Madillf67115c2014-04-22 13:14:05 -040041 {
42 setWindowWidth(128);
43 setWindowHeight(128);
44 setConfigRedBits(8);
45 setConfigGreenBits(8);
46 setConfigBlueBits(8);
47 setConfigAlphaBits(8);
48 }
49
Jamie Madill35cd7332018-12-02 12:03:33 -050050 virtual const char *getVertexShaderSource()
Jamie Madillf67115c2014-04-22 13:14:05 -040051 {
Jamie Madill35cd7332018-12-02 12:03:33 -050052 return R"(precision highp float;
53attribute vec4 position;
54varying vec2 texcoord;
Geoff Langc41e42d2014-04-28 10:58:16 -040055
Jamie Madill35cd7332018-12-02 12:03:33 -050056void main()
57{
58 gl_Position = vec4(position.xy, 0.0, 1.0);
59 texcoord = (position.xy * 0.5) + 0.5;
60})";
Olli Etuaho4a8329f2016-01-11 17:12:57 +020061 }
Geoff Langc41e42d2014-04-28 10:58:16 -040062
Jamie Madill35cd7332018-12-02 12:03:33 -050063 virtual const char *getFragmentShaderSource() = 0;
Olli Etuaho4a8329f2016-01-11 17:12:57 +020064
Olli Etuahoa1c917f2016-04-06 13:50:03 +030065 virtual void setUpProgram()
Olli Etuaho4a8329f2016-01-11 17:12:57 +020066 {
Jamie Madill35cd7332018-12-02 12:03:33 -050067 const char *vertexShaderSource = getVertexShaderSource();
68 const char *fragmentShaderSource = getFragmentShaderSource();
Olli Etuaho4a8329f2016-01-11 17:12:57 +020069
70 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
71 ASSERT_NE(0u, mProgram);
72 ASSERT_GL_NO_ERROR();
Olli Etuahoa1c917f2016-04-06 13:50:03 +030073 }
74
75 void SetUp() override
76 {
77 ANGLETest::SetUp();
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020078
79 setUpFramebuffer();
Olli Etuaho4a8329f2016-01-11 17:12:57 +020080 }
81
82 void TearDown() override
83 {
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020084 glBindFramebuffer(GL_FRAMEBUFFER, 0);
85 glDeleteFramebuffers(1, &mFramebuffer);
86 glDeleteTextures(1, &mFramebufferColorTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +020087 glDeleteProgram(mProgram);
88 ANGLETest::TearDown();
89 }
90
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020091 void setUpFramebuffer()
92 {
93 // We use an FBO to work around an issue where the default framebuffer applies SRGB
94 // conversion (particularly known to happen incorrectly on Intel GL drivers). It's not
95 // clear whether this issue can even be fixed on all backends. For example GLES 3.0.4 spec
96 // section 4.4 says that the format of the default framebuffer is entirely up to the window
97 // system, so it might be SRGB, and GLES 3.0 doesn't have a "FRAMEBUFFER_SRGB" to turn off
98 // SRGB conversion like desktop GL does.
99 // TODO(oetuaho): Get rid of this if the underlying issue is fixed.
100 glGenFramebuffers(1, &mFramebuffer);
101 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
102
103 glGenTextures(1, &mFramebufferColorTexture);
104 glBindTexture(GL_TEXTURE_2D, mFramebufferColorTexture);
105 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
106 GL_UNSIGNED_BYTE, nullptr);
107 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
108 mFramebufferColorTexture, 0);
109 ASSERT_GL_NO_ERROR();
110 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
111 glBindTexture(GL_TEXTURE_2D, 0);
112 }
113
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200114 // Returns the created texture ID.
115 GLuint create2DTexture()
116 {
117 GLuint texture2D;
118 glGenTextures(1, &texture2D);
119 glBindTexture(GL_TEXTURE_2D, texture2D);
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800120 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200121 EXPECT_GL_NO_ERROR();
122 return texture2D;
123 }
124
125 GLuint mProgram;
Olli Etuaho51f1c0f2016-01-13 16:16:24 +0200126 GLuint mFramebuffer;
127
128 private:
129 GLuint mFramebufferColorTexture;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200130};
131
132class Texture2DTest : public TexCoordDrawTest
133{
134 protected:
135 Texture2DTest() : TexCoordDrawTest(), mTexture2D(0), mTexture2DUniformLocation(-1) {}
136
Jamie Madill35cd7332018-12-02 12:03:33 -0500137 const char *getFragmentShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200138 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500139 return R"(precision highp float;
140uniform sampler2D tex;
141varying vec2 texcoord;
Geoff Langc41e42d2014-04-28 10:58:16 -0400142
Jamie Madill35cd7332018-12-02 12:03:33 -0500143void main()
144{
145 gl_FragColor = texture2D(tex, texcoord);
146})";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200147 }
Geoff Langc41e42d2014-04-28 10:58:16 -0400148
Olli Etuaho96963162016-03-21 11:54:33 +0200149 virtual const char *getTextureUniformName() { return "tex"; }
150
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300151 void setUpProgram() override
152 {
153 TexCoordDrawTest::setUpProgram();
154 mTexture2DUniformLocation = glGetUniformLocation(mProgram, getTextureUniformName());
155 ASSERT_NE(-1, mTexture2DUniformLocation);
156 }
157
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200158 void SetUp() override
159 {
160 TexCoordDrawTest::SetUp();
161 mTexture2D = create2DTexture();
Jamie Madilld4cfa572014-07-08 10:00:32 -0400162
Jamie Madill9aca0592014-10-06 16:26:59 -0400163 ASSERT_GL_NO_ERROR();
Jamie Madillf67115c2014-04-22 13:14:05 -0400164 }
165
Jamie Madillfa05f602015-05-07 13:47:11 -0400166 void TearDown() override
Jamie Madillf67115c2014-04-22 13:14:05 -0400167 {
Jamie Madilld4cfa572014-07-08 10:00:32 -0400168 glDeleteTextures(1, &mTexture2D);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200169 TexCoordDrawTest::TearDown();
Jamie Madillf67115c2014-04-22 13:14:05 -0400170 }
171
Jamie Madillbc393df2015-01-29 13:46:07 -0500172 // Tests CopyTexSubImage with floating point textures of various formats.
173 void testFloatCopySubImage(int sourceImageChannels, int destImageChannels)
174 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300175 setUpProgram();
176
Martin Radev1be913c2016-07-11 17:59:16 +0300177 if (getClientMajorVersion() < 3)
Geoff Langfbfa47c2015-03-31 11:26:00 -0400178 {
Yunchao He9550c602018-02-13 14:47:05 +0800179 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_storage") ||
180 !extensionEnabled("GL_OES_texture_float"));
Geoff Langc4e93662017-05-01 10:45:59 -0400181
Yunchao He9550c602018-02-13 14:47:05 +0800182 ANGLE_SKIP_TEST_IF((sourceImageChannels < 3 || destImageChannels < 3) &&
183 !extensionEnabled("GL_EXT_texture_rg"));
Geoff Langfbfa47c2015-03-31 11:26:00 -0400184
Yunchao He9550c602018-02-13 14:47:05 +0800185 ANGLE_SKIP_TEST_IF(destImageChannels == 3 &&
186 !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400187
Yunchao He9550c602018-02-13 14:47:05 +0800188 ANGLE_SKIP_TEST_IF(destImageChannels == 4 &&
189 !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400190
Yunchao He9550c602018-02-13 14:47:05 +0800191 ANGLE_SKIP_TEST_IF(destImageChannels <= 2);
Geoff Lang677bb6f2017-04-05 12:40:40 -0400192 }
193 else
194 {
Yunchao He9550c602018-02-13 14:47:05 +0800195 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_color_buffer_float"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400196
Yunchao He9550c602018-02-13 14:47:05 +0800197 ANGLE_SKIP_TEST_IF(destImageChannels == 3 &&
198 !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"));
Geoff Langfbfa47c2015-03-31 11:26:00 -0400199 }
200
Jamie Madill50cf2be2018-06-15 09:46:57 -0400201 // clang-format off
Jamie Madillbc393df2015-01-29 13:46:07 -0500202 GLfloat sourceImageData[4][16] =
203 {
204 { // R
205 1.0f,
206 0.0f,
207 0.0f,
208 1.0f
209 },
210 { // RG
211 1.0f, 0.0f,
212 0.0f, 1.0f,
213 0.0f, 0.0f,
214 1.0f, 1.0f
215 },
216 { // RGB
217 1.0f, 0.0f, 0.0f,
218 0.0f, 1.0f, 0.0f,
219 0.0f, 0.0f, 1.0f,
220 1.0f, 1.0f, 0.0f
221 },
222 { // RGBA
223 1.0f, 0.0f, 0.0f, 1.0f,
224 0.0f, 1.0f, 0.0f, 1.0f,
225 0.0f, 0.0f, 1.0f, 1.0f,
226 1.0f, 1.0f, 0.0f, 1.0f
227 },
228 };
Jamie Madill50cf2be2018-06-15 09:46:57 -0400229 // clang-format on
Jamie Madillbc393df2015-01-29 13:46:07 -0500230
Jamie Madill50cf2be2018-06-15 09:46:57 -0400231 GLenum imageFormats[] = {
Jamie Madillb980c562018-11-27 11:34:27 -0500232 GL_R32F,
233 GL_RG32F,
234 GL_RGB32F,
235 GL_RGBA32F,
Jamie Madillbc393df2015-01-29 13:46:07 -0500236 };
237
Jamie Madill50cf2be2018-06-15 09:46:57 -0400238 GLenum sourceUnsizedFormats[] = {
Jamie Madillb980c562018-11-27 11:34:27 -0500239 GL_RED,
240 GL_RG,
241 GL_RGB,
242 GL_RGBA,
Jamie Madillbc393df2015-01-29 13:46:07 -0500243 };
244
245 GLuint textures[2];
246
247 glGenTextures(2, textures);
248
Jamie Madill50cf2be2018-06-15 09:46:57 -0400249 GLfloat *imageData = sourceImageData[sourceImageChannels - 1];
250 GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1];
Jamie Madillbc393df2015-01-29 13:46:07 -0500251 GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1];
Jamie Madill50cf2be2018-06-15 09:46:57 -0400252 GLenum destImageFormat = imageFormats[destImageChannels - 1];
Jamie Madillbc393df2015-01-29 13:46:07 -0500253
254 glBindTexture(GL_TEXTURE_2D, textures[0]);
Geoff Langc4e93662017-05-01 10:45:59 -0400255 if (getClientMajorVersion() >= 3)
256 {
257 glTexStorage2D(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
258 }
259 else
260 {
261 glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
262 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500263 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
264 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
265 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData);
266
hendrikwb27f79a2015-03-04 11:26:46 -0800267 if (sourceImageChannels < 3 && !extensionEnabled("GL_EXT_texture_rg"))
Jamie Madillbc393df2015-01-29 13:46:07 -0500268 {
269 // This is not supported
270 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
271 }
272 else
273 {
274 ASSERT_GL_NO_ERROR();
275 }
276
277 GLuint fbo;
278 glGenFramebuffers(1, &fbo);
279 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
280 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
281
282 glBindTexture(GL_TEXTURE_2D, textures[1]);
Geoff Langc4e93662017-05-01 10:45:59 -0400283 if (getClientMajorVersion() >= 3)
284 {
285 glTexStorage2D(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
286 }
287 else
288 {
289 glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
290 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500291 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
292 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
293
294 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
295 ASSERT_GL_NO_ERROR();
296
297 glBindFramebuffer(GL_FRAMEBUFFER, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200298 drawQuad(mProgram, "position", 0.5f);
Jamie Madillbc393df2015-01-29 13:46:07 -0500299
300 int testImageChannels = std::min(sourceImageChannels, destImageChannels);
301
Olli Etuahoa314b612016-03-10 16:43:00 +0200302 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Jamie Madillbc393df2015-01-29 13:46:07 -0500303 if (testImageChannels > 1)
304 {
305 EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255);
306 EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255);
307 if (testImageChannels > 2)
308 {
309 EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255);
310 }
311 }
312
313 glDeleteFramebuffers(1, &fbo);
314 glDeleteTextures(2, textures);
315
316 ASSERT_GL_NO_ERROR();
317 }
318
Jamie Madilld4cfa572014-07-08 10:00:32 -0400319 GLuint mTexture2D;
Jamie Madilld4cfa572014-07-08 10:00:32 -0400320 GLint mTexture2DUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400321};
322
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200323class Texture2DTestES3 : public Texture2DTest
324{
325 protected:
326 Texture2DTestES3() : Texture2DTest() {}
327
Jamie Madill35cd7332018-12-02 12:03:33 -0500328 const char *getVertexShaderSource() override
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200329 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500330 return "#version 300 es\n"
331 "out vec2 texcoord;\n"
332 "in vec4 position;\n"
333 "void main()\n"
334 "{\n"
335 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
336 " texcoord = (position.xy * 0.5) + 0.5;\n"
337 "}\n";
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200338 }
339
Jamie Madill35cd7332018-12-02 12:03:33 -0500340 const char *getFragmentShaderSource() override
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200341 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500342 return "#version 300 es\n"
343 "precision highp float;\n"
344 "uniform highp sampler2D tex;\n"
345 "in vec2 texcoord;\n"
346 "out vec4 fragColor;\n"
347 "void main()\n"
348 "{\n"
349 " fragColor = texture(tex, texcoord);\n"
350 "}\n";
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200351 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300352
353 void SetUp() override
354 {
355 Texture2DTest::SetUp();
356 setUpProgram();
357 }
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200358};
359
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200360class Texture2DIntegerAlpha1TestES3 : public Texture2DTest
361{
362 protected:
363 Texture2DIntegerAlpha1TestES3() : Texture2DTest() {}
364
Jamie Madill35cd7332018-12-02 12:03:33 -0500365 const char *getVertexShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200366 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500367 return "#version 300 es\n"
368 "out vec2 texcoord;\n"
369 "in vec4 position;\n"
370 "void main()\n"
371 "{\n"
372 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
373 " texcoord = (position.xy * 0.5) + 0.5;\n"
374 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200375 }
376
Jamie Madill35cd7332018-12-02 12:03:33 -0500377 const char *getFragmentShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200378 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500379 return "#version 300 es\n"
380 "precision highp float;\n"
381 "uniform highp isampler2D tex;\n"
382 "in vec2 texcoord;\n"
383 "out vec4 fragColor;\n"
384 "void main()\n"
385 "{\n"
386 " vec4 green = vec4(0, 1, 0, 1);\n"
387 " vec4 black = vec4(0, 0, 0, 0);\n"
388 " fragColor = (texture(tex, texcoord).a == 1) ? green : black;\n"
389 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200390 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300391
392 void SetUp() override
393 {
394 Texture2DTest::SetUp();
395 setUpProgram();
396 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200397};
398
399class Texture2DUnsignedIntegerAlpha1TestES3 : public Texture2DTest
400{
401 protected:
402 Texture2DUnsignedIntegerAlpha1TestES3() : Texture2DTest() {}
403
Jamie Madill35cd7332018-12-02 12:03:33 -0500404 const char *getVertexShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200405 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500406 return "#version 300 es\n"
407 "out vec2 texcoord;\n"
408 "in vec4 position;\n"
409 "void main()\n"
410 "{\n"
411 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
412 " texcoord = (position.xy * 0.5) + 0.5;\n"
413 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200414 }
415
Jamie Madill35cd7332018-12-02 12:03:33 -0500416 const char *getFragmentShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200417 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500418 return "#version 300 es\n"
419 "precision highp float;\n"
420 "uniform highp usampler2D tex;\n"
421 "in vec2 texcoord;\n"
422 "out vec4 fragColor;\n"
423 "void main()\n"
424 "{\n"
425 " vec4 green = vec4(0, 1, 0, 1);\n"
426 " vec4 black = vec4(0, 0, 0, 0);\n"
427 " fragColor = (texture(tex, texcoord).a == 1u) ? green : black;\n"
428 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200429 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300430
431 void SetUp() override
432 {
433 Texture2DTest::SetUp();
434 setUpProgram();
435 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200436};
437
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200438class Texture2DTestWithDrawScale : public Texture2DTest
Jamie Madill2453dbc2015-07-14 11:35:42 -0400439{
440 protected:
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200441 Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {}
442
Jamie Madill35cd7332018-12-02 12:03:33 -0500443 const char *getVertexShaderSource() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400444 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300445 return
446 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200447 attribute vec4 position;
448 varying vec2 texcoord;
449
450 uniform vec2 drawScale;
451
452 void main()
453 {
454 gl_Position = vec4(position.xy * drawScale, 0.0, 1.0);
455 texcoord = (position.xy * 0.5) + 0.5;
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300456 })";
Jamie Madill2453dbc2015-07-14 11:35:42 -0400457 }
458
459 void SetUp() override
460 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200461 Texture2DTest::SetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300462
463 setUpProgram();
464
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200465 mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale");
466 ASSERT_NE(-1, mDrawScaleUniformLocation);
Jamie Madill2453dbc2015-07-14 11:35:42 -0400467
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200468 glUseProgram(mProgram);
469 glUniform2f(mDrawScaleUniformLocation, 1.0f, 1.0f);
470 glUseProgram(0);
471 ASSERT_GL_NO_ERROR();
472 }
473
474 GLint mDrawScaleUniformLocation;
475};
476
Olli Etuaho4644a202016-01-12 15:12:53 +0200477class Sampler2DAsFunctionParameterTest : public Texture2DTest
478{
479 protected:
480 Sampler2DAsFunctionParameterTest() : Texture2DTest() {}
481
Jamie Madill35cd7332018-12-02 12:03:33 -0500482 const char *getFragmentShaderSource() override
Olli Etuaho4644a202016-01-12 15:12:53 +0200483 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300484 return
485 R"(precision highp float;
Olli Etuaho4644a202016-01-12 15:12:53 +0200486 uniform sampler2D tex;
487 varying vec2 texcoord;
488
489 vec4 computeFragColor(sampler2D aTex)
490 {
491 return texture2D(aTex, texcoord);
492 }
493
494 void main()
495 {
496 gl_FragColor = computeFragColor(tex);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300497 })";
Olli Etuaho4644a202016-01-12 15:12:53 +0200498 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300499
500 void SetUp() override
501 {
502 Texture2DTest::SetUp();
503 setUpProgram();
504 }
Olli Etuaho4644a202016-01-12 15:12:53 +0200505};
506
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200507class TextureCubeTest : public TexCoordDrawTest
508{
509 protected:
510 TextureCubeTest()
511 : TexCoordDrawTest(),
512 mTexture2D(0),
513 mTextureCube(0),
514 mTexture2DUniformLocation(-1),
515 mTextureCubeUniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500516 {}
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200517
Jamie Madill35cd7332018-12-02 12:03:33 -0500518 const char *getFragmentShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200519 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300520 return
521 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200522 uniform sampler2D tex2D;
523 uniform samplerCube texCube;
524 varying vec2 texcoord;
525
526 void main()
527 {
528 gl_FragColor = texture2D(tex2D, texcoord);
529 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300530 })";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200531 }
532
533 void SetUp() override
534 {
535 TexCoordDrawTest::SetUp();
536
537 glGenTextures(1, &mTextureCube);
538 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Geoff Langc4e93662017-05-01 10:45:59 -0400539 for (GLenum face = 0; face < 6; face++)
540 {
541 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
542 GL_UNSIGNED_BYTE, nullptr);
543 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200544 EXPECT_GL_NO_ERROR();
545
546 mTexture2D = create2DTexture();
547
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300548 setUpProgram();
549
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200550 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
551 ASSERT_NE(-1, mTexture2DUniformLocation);
552 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
553 ASSERT_NE(-1, mTextureCubeUniformLocation);
554 }
555
556 void TearDown() override
557 {
558 glDeleteTextures(1, &mTextureCube);
559 TexCoordDrawTest::TearDown();
560 }
561
562 GLuint mTexture2D;
563 GLuint mTextureCube;
564 GLint mTexture2DUniformLocation;
565 GLint mTextureCubeUniformLocation;
566};
567
Martin Radev7e2c0d32017-09-15 14:25:42 +0300568class TextureCubeTestES3 : public ANGLETest
569{
570 protected:
571 TextureCubeTestES3() {}
572};
573
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200574class SamplerArrayTest : public TexCoordDrawTest
575{
576 protected:
577 SamplerArrayTest()
578 : TexCoordDrawTest(),
579 mTexture2DA(0),
580 mTexture2DB(0),
581 mTexture0UniformLocation(-1),
582 mTexture1UniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500583 {}
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200584
Jamie Madill35cd7332018-12-02 12:03:33 -0500585 const char *getFragmentShaderSource() override
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200586 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300587 return
588 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200589 uniform highp sampler2D tex2DArray[2];
590 varying vec2 texcoord;
591 void main()
592 {
593 gl_FragColor = texture2D(tex2DArray[0], texcoord);
594 gl_FragColor += texture2D(tex2DArray[1], texcoord);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300595 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200596 }
597
598 void SetUp() override
599 {
600 TexCoordDrawTest::SetUp();
601
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300602 setUpProgram();
603
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200604 mTexture0UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[0]");
605 ASSERT_NE(-1, mTexture0UniformLocation);
606 mTexture1UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[1]");
607 ASSERT_NE(-1, mTexture1UniformLocation);
608
609 mTexture2DA = create2DTexture();
610 mTexture2DB = create2DTexture();
611 ASSERT_GL_NO_ERROR();
612 }
613
614 void TearDown() override
615 {
616 glDeleteTextures(1, &mTexture2DA);
617 glDeleteTextures(1, &mTexture2DB);
618 TexCoordDrawTest::TearDown();
619 }
620
621 void testSamplerArrayDraw()
622 {
623 GLubyte texData[4];
624 texData[0] = 0;
625 texData[1] = 60;
626 texData[2] = 0;
627 texData[3] = 255;
628
629 glActiveTexture(GL_TEXTURE0);
630 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
631 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
632
633 texData[1] = 120;
634 glActiveTexture(GL_TEXTURE1);
635 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
636 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
637 EXPECT_GL_ERROR(GL_NO_ERROR);
638
639 glUseProgram(mProgram);
640 glUniform1i(mTexture0UniformLocation, 0);
641 glUniform1i(mTexture1UniformLocation, 1);
642 drawQuad(mProgram, "position", 0.5f);
643 EXPECT_GL_NO_ERROR();
644
645 EXPECT_PIXEL_NEAR(0, 0, 0, 180, 0, 255, 2);
646 }
647
648 GLuint mTexture2DA;
649 GLuint mTexture2DB;
650 GLint mTexture0UniformLocation;
651 GLint mTexture1UniformLocation;
652};
653
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200654class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest
655{
656 protected:
657 SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {}
658
Jamie Madill35cd7332018-12-02 12:03:33 -0500659 const char *getFragmentShaderSource() override
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200660 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300661 return
662 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200663 uniform highp sampler2D tex2DArray[2];
664 varying vec2 texcoord;
665
666 vec4 computeFragColor(highp sampler2D aTex2DArray[2])
667 {
668 return texture2D(aTex2DArray[0], texcoord) + texture2D(aTex2DArray[1], texcoord);
669 }
670
671 void main()
672 {
673 gl_FragColor = computeFragColor(tex2DArray);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300674 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200675 }
676};
677
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200678class Texture2DArrayTestES3 : public TexCoordDrawTest
679{
680 protected:
681 Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {}
682
Jamie Madill35cd7332018-12-02 12:03:33 -0500683 const char *getVertexShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200684 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500685 return "#version 300 es\n"
686 "out vec2 texcoord;\n"
687 "in vec4 position;\n"
688 "void main()\n"
689 "{\n"
690 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
691 " texcoord = (position.xy * 0.5) + 0.5;\n"
692 "}\n";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200693 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400694
Jamie Madill35cd7332018-12-02 12:03:33 -0500695 const char *getFragmentShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200696 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500697 return "#version 300 es\n"
698 "precision highp float;\n"
699 "uniform highp sampler2DArray tex2DArray;\n"
700 "in vec2 texcoord;\n"
701 "out vec4 fragColor;\n"
702 "void main()\n"
703 "{\n"
704 " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n"
705 "}\n";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200706 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400707
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200708 void SetUp() override
709 {
710 TexCoordDrawTest::SetUp();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400711
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300712 setUpProgram();
713
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200714 mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray");
Jamie Madill2453dbc2015-07-14 11:35:42 -0400715 ASSERT_NE(-1, mTextureArrayLocation);
716
717 glGenTextures(1, &m2DArrayTexture);
718 ASSERT_GL_NO_ERROR();
719 }
720
721 void TearDown() override
722 {
723 glDeleteTextures(1, &m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200724 TexCoordDrawTest::TearDown();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400725 }
726
727 GLuint m2DArrayTexture;
Jamie Madill2453dbc2015-07-14 11:35:42 -0400728 GLint mTextureArrayLocation;
729};
730
Olli Etuahobce743a2016-01-15 17:18:28 +0200731class TextureSizeTextureArrayTest : public TexCoordDrawTest
732{
733 protected:
734 TextureSizeTextureArrayTest()
735 : TexCoordDrawTest(),
736 mTexture2DA(0),
737 mTexture2DB(0),
738 mTexture0Location(-1),
739 mTexture1Location(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500740 {}
Olli Etuahobce743a2016-01-15 17:18:28 +0200741
Jamie Madill35cd7332018-12-02 12:03:33 -0500742 const char *getVertexShaderSource() override { return essl3_shaders::vs::Simple(); }
Olli Etuahobce743a2016-01-15 17:18:28 +0200743
Jamie Madill35cd7332018-12-02 12:03:33 -0500744 const char *getFragmentShaderSource() override
Olli Etuahobce743a2016-01-15 17:18:28 +0200745 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500746 return "#version 300 es\n"
747 "precision highp float;\n"
748 "uniform highp sampler2D tex2DArray[2];\n"
749 "out vec4 fragColor;\n"
750 "void main()\n"
751 "{\n"
752 " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n"
753 " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n"
754 " fragColor = vec4(red, green, 0.0, 1.0);\n"
755 "}\n";
Olli Etuahobce743a2016-01-15 17:18:28 +0200756 }
757
758 void SetUp() override
759 {
760 TexCoordDrawTest::SetUp();
761
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300762 setUpProgram();
763
Olli Etuahobce743a2016-01-15 17:18:28 +0200764 mTexture0Location = glGetUniformLocation(mProgram, "tex2DArray[0]");
765 ASSERT_NE(-1, mTexture0Location);
766 mTexture1Location = glGetUniformLocation(mProgram, "tex2DArray[1]");
767 ASSERT_NE(-1, mTexture1Location);
768
769 mTexture2DA = create2DTexture();
770 mTexture2DB = create2DTexture();
771 ASSERT_GL_NO_ERROR();
772 }
773
774 void TearDown() override
775 {
776 glDeleteTextures(1, &mTexture2DA);
777 glDeleteTextures(1, &mTexture2DB);
778 TexCoordDrawTest::TearDown();
779 }
780
781 GLuint mTexture2DA;
782 GLuint mTexture2DB;
783 GLint mTexture0Location;
784 GLint mTexture1Location;
785};
786
Olli Etuahoa314b612016-03-10 16:43:00 +0200787class Texture3DTestES3 : public TexCoordDrawTest
788{
789 protected:
790 Texture3DTestES3() : TexCoordDrawTest(), mTexture3D(0), mTexture3DUniformLocation(-1) {}
791
Jamie Madill35cd7332018-12-02 12:03:33 -0500792 const char *getVertexShaderSource() override
Olli Etuahoa314b612016-03-10 16:43:00 +0200793 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500794 return "#version 300 es\n"
795 "out vec2 texcoord;\n"
796 "in vec4 position;\n"
797 "void main()\n"
798 "{\n"
799 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
800 " texcoord = (position.xy * 0.5) + 0.5;\n"
801 "}\n";
Olli Etuahoa314b612016-03-10 16:43:00 +0200802 }
803
Jamie Madill35cd7332018-12-02 12:03:33 -0500804 const char *getFragmentShaderSource() override
Olli Etuahoa314b612016-03-10 16:43:00 +0200805 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500806 return "#version 300 es\n"
807 "precision highp float;\n"
808 "uniform highp sampler3D tex3D;\n"
809 "in vec2 texcoord;\n"
810 "out vec4 fragColor;\n"
811 "void main()\n"
812 "{\n"
813 " fragColor = texture(tex3D, vec3(texcoord, 0.0));\n"
814 "}\n";
Olli Etuahoa314b612016-03-10 16:43:00 +0200815 }
816
817 void SetUp() override
818 {
819 TexCoordDrawTest::SetUp();
820
821 glGenTextures(1, &mTexture3D);
822
823 setUpProgram();
824
825 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
826 ASSERT_NE(-1, mTexture3DUniformLocation);
827 }
828
829 void TearDown() override
830 {
831 glDeleteTextures(1, &mTexture3D);
832 TexCoordDrawTest::TearDown();
833 }
834
835 GLuint mTexture3D;
836 GLint mTexture3DUniformLocation;
837};
838
Olli Etuaho1a679902016-01-14 12:21:47 +0200839class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest
840{
841 protected:
842 ShadowSamplerPlusSampler3DTestES3()
843 : TexCoordDrawTest(),
844 mTextureShadow(0),
845 mTexture3D(0),
846 mTextureShadowUniformLocation(-1),
847 mTexture3DUniformLocation(-1),
848 mDepthRefUniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500849 {}
Olli Etuaho1a679902016-01-14 12:21:47 +0200850
Jamie Madill35cd7332018-12-02 12:03:33 -0500851 const char *getVertexShaderSource() override
Olli Etuaho1a679902016-01-14 12:21:47 +0200852 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500853 return "#version 300 es\n"
854 "out vec2 texcoord;\n"
855 "in vec4 position;\n"
856 "void main()\n"
857 "{\n"
858 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
859 " texcoord = (position.xy * 0.5) + 0.5;\n"
860 "}\n";
Olli Etuaho1a679902016-01-14 12:21:47 +0200861 }
862
Jamie Madill35cd7332018-12-02 12:03:33 -0500863 const char *getFragmentShaderSource() override
Olli Etuaho1a679902016-01-14 12:21:47 +0200864 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500865 return "#version 300 es\n"
866 "precision highp float;\n"
867 "uniform highp sampler2DShadow tex2DShadow;\n"
868 "uniform highp sampler3D tex3D;\n"
869 "in vec2 texcoord;\n"
870 "uniform float depthRef;\n"
871 "out vec4 fragColor;\n"
872 "void main()\n"
873 "{\n"
874 " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n"
875 " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n"
876 "}\n";
Olli Etuaho1a679902016-01-14 12:21:47 +0200877 }
878
879 void SetUp() override
880 {
881 TexCoordDrawTest::SetUp();
882
883 glGenTextures(1, &mTexture3D);
884
885 glGenTextures(1, &mTextureShadow);
886 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
887 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
888
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300889 setUpProgram();
890
Olli Etuaho1a679902016-01-14 12:21:47 +0200891 mTextureShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
892 ASSERT_NE(-1, mTextureShadowUniformLocation);
893 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
894 ASSERT_NE(-1, mTexture3DUniformLocation);
895 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
896 ASSERT_NE(-1, mDepthRefUniformLocation);
897 }
898
899 void TearDown() override
900 {
901 glDeleteTextures(1, &mTextureShadow);
902 glDeleteTextures(1, &mTexture3D);
903 TexCoordDrawTest::TearDown();
904 }
905
906 GLuint mTextureShadow;
907 GLuint mTexture3D;
908 GLint mTextureShadowUniformLocation;
909 GLint mTexture3DUniformLocation;
910 GLint mDepthRefUniformLocation;
911};
912
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200913class SamplerTypeMixTestES3 : public TexCoordDrawTest
914{
915 protected:
916 SamplerTypeMixTestES3()
917 : TexCoordDrawTest(),
918 mTexture2D(0),
919 mTextureCube(0),
920 mTexture2DShadow(0),
921 mTextureCubeShadow(0),
922 mTexture2DUniformLocation(-1),
923 mTextureCubeUniformLocation(-1),
924 mTexture2DShadowUniformLocation(-1),
925 mTextureCubeShadowUniformLocation(-1),
926 mDepthRefUniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500927 {}
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200928
Jamie Madill35cd7332018-12-02 12:03:33 -0500929 const char *getVertexShaderSource() override
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200930 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500931 return "#version 300 es\n"
932 "out vec2 texcoord;\n"
933 "in vec4 position;\n"
934 "void main()\n"
935 "{\n"
936 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
937 " texcoord = (position.xy * 0.5) + 0.5;\n"
938 "}\n";
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200939 }
940
Jamie Madill35cd7332018-12-02 12:03:33 -0500941 const char *getFragmentShaderSource() override
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200942 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500943 return "#version 300 es\n"
944 "precision highp float;\n"
945 "uniform highp sampler2D tex2D;\n"
946 "uniform highp samplerCube texCube;\n"
947 "uniform highp sampler2DShadow tex2DShadow;\n"
948 "uniform highp samplerCubeShadow texCubeShadow;\n"
949 "in vec2 texcoord;\n"
950 "uniform float depthRef;\n"
951 "out vec4 fragColor;\n"
952 "void main()\n"
953 "{\n"
954 " fragColor = texture(tex2D, texcoord);\n"
955 " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n"
956 " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n"
957 " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * "
958 "0.125);\n"
959 "}\n";
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200960 }
961
962 void SetUp() override
963 {
964 TexCoordDrawTest::SetUp();
965
966 glGenTextures(1, &mTexture2D);
967 glGenTextures(1, &mTextureCube);
968
969 glGenTextures(1, &mTexture2DShadow);
970 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
971 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
972
973 glGenTextures(1, &mTextureCubeShadow);
974 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
975 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
976
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300977 setUpProgram();
978
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200979 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
980 ASSERT_NE(-1, mTexture2DUniformLocation);
981 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
982 ASSERT_NE(-1, mTextureCubeUniformLocation);
983 mTexture2DShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
984 ASSERT_NE(-1, mTexture2DShadowUniformLocation);
985 mTextureCubeShadowUniformLocation = glGetUniformLocation(mProgram, "texCubeShadow");
986 ASSERT_NE(-1, mTextureCubeShadowUniformLocation);
987 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
988 ASSERT_NE(-1, mDepthRefUniformLocation);
989
990 ASSERT_GL_NO_ERROR();
991 }
992
993 void TearDown() override
994 {
995 glDeleteTextures(1, &mTexture2D);
996 glDeleteTextures(1, &mTextureCube);
997 glDeleteTextures(1, &mTexture2DShadow);
998 glDeleteTextures(1, &mTextureCubeShadow);
999 TexCoordDrawTest::TearDown();
1000 }
1001
1002 GLuint mTexture2D;
1003 GLuint mTextureCube;
1004 GLuint mTexture2DShadow;
1005 GLuint mTextureCubeShadow;
1006 GLint mTexture2DUniformLocation;
1007 GLint mTextureCubeUniformLocation;
1008 GLint mTexture2DShadowUniformLocation;
1009 GLint mTextureCubeShadowUniformLocation;
1010 GLint mDepthRefUniformLocation;
1011};
1012
Olli Etuaho96963162016-03-21 11:54:33 +02001013class SamplerInStructTest : public Texture2DTest
1014{
1015 protected:
1016 SamplerInStructTest() : Texture2DTest() {}
1017
1018 const char *getTextureUniformName() override { return "us.tex"; }
1019
Jamie Madill35cd7332018-12-02 12:03:33 -05001020 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001021 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001022 return "precision highp float;\n"
1023 "struct S\n"
1024 "{\n"
1025 " vec4 a;\n"
1026 " highp sampler2D tex;\n"
1027 "};\n"
1028 "uniform S us;\n"
1029 "varying vec2 texcoord;\n"
1030 "void main()\n"
1031 "{\n"
1032 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x);\n"
1033 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001034 }
1035
1036 void runSamplerInStructTest()
1037 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001038 setUpProgram();
1039
Olli Etuaho96963162016-03-21 11:54:33 +02001040 glActiveTexture(GL_TEXTURE0);
1041 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001042 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1043 &GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001044 drawQuad(mProgram, "position", 0.5f);
Olli Etuahoa314b612016-03-10 16:43:00 +02001045 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001046 }
1047};
1048
1049class SamplerInStructAsFunctionParameterTest : public SamplerInStructTest
1050{
1051 protected:
1052 SamplerInStructAsFunctionParameterTest() : SamplerInStructTest() {}
1053
Jamie Madill35cd7332018-12-02 12:03:33 -05001054 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001055 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001056 return "precision highp float;\n"
1057 "struct S\n"
1058 "{\n"
1059 " vec4 a;\n"
1060 " highp sampler2D tex;\n"
1061 "};\n"
1062 "uniform S us;\n"
1063 "varying vec2 texcoord;\n"
1064 "vec4 sampleFrom(S s) {\n"
1065 " return texture2D(s.tex, texcoord + s.a.x);\n"
1066 "}\n"
1067 "void main()\n"
1068 "{\n"
1069 " gl_FragColor = sampleFrom(us);\n"
1070 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001071 }
1072};
1073
1074class SamplerInStructArrayAsFunctionParameterTest : public SamplerInStructTest
1075{
1076 protected:
1077 SamplerInStructArrayAsFunctionParameterTest() : SamplerInStructTest() {}
1078
1079 const char *getTextureUniformName() override { return "us[0].tex"; }
1080
Jamie Madill35cd7332018-12-02 12:03:33 -05001081 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001082 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001083 return "precision highp float;\n"
1084 "struct S\n"
1085 "{\n"
1086 " vec4 a;\n"
1087 " highp sampler2D tex;\n"
1088 "};\n"
1089 "uniform S us[1];\n"
1090 "varying vec2 texcoord;\n"
1091 "vec4 sampleFrom(S s) {\n"
1092 " return texture2D(s.tex, texcoord + s.a.x);\n"
1093 "}\n"
1094 "void main()\n"
1095 "{\n"
1096 " gl_FragColor = sampleFrom(us[0]);\n"
1097 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001098 }
1099};
1100
1101class SamplerInNestedStructAsFunctionParameterTest : public SamplerInStructTest
1102{
1103 protected:
1104 SamplerInNestedStructAsFunctionParameterTest() : SamplerInStructTest() {}
1105
1106 const char *getTextureUniformName() override { return "us[0].sub.tex"; }
1107
Jamie Madill35cd7332018-12-02 12:03:33 -05001108 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001109 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001110 return "precision highp float;\n"
1111 "struct SUB\n"
1112 "{\n"
1113 " vec4 a;\n"
1114 " highp sampler2D tex;\n"
1115 "};\n"
1116 "struct S\n"
1117 "{\n"
1118 " SUB sub;\n"
1119 "};\n"
1120 "uniform S us[1];\n"
1121 "varying vec2 texcoord;\n"
1122 "vec4 sampleFrom(SUB s) {\n"
1123 " return texture2D(s.tex, texcoord + s.a.x);\n"
1124 "}\n"
1125 "void main()\n"
1126 "{\n"
1127 " gl_FragColor = sampleFrom(us[0].sub);\n"
1128 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001129 }
1130};
1131
1132class SamplerInStructAndOtherVariableTest : public SamplerInStructTest
1133{
1134 protected:
1135 SamplerInStructAndOtherVariableTest() : SamplerInStructTest() {}
1136
Jamie Madill35cd7332018-12-02 12:03:33 -05001137 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001138 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001139 return "precision highp float;\n"
1140 "struct S\n"
1141 "{\n"
1142 " vec4 a;\n"
1143 " highp sampler2D tex;\n"
1144 "};\n"
1145 "uniform S us;\n"
1146 "uniform float us_tex;\n"
1147 "varying vec2 texcoord;\n"
1148 "void main()\n"
1149 "{\n"
1150 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x + us_tex);\n"
1151 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001152 }
1153};
1154
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001155TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001156{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001157 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001158 EXPECT_GL_ERROR(GL_NO_ERROR);
1159
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001160 setUpProgram();
1161
Jamie Madill50cf2be2018-06-15 09:46:57 -04001162 const GLubyte *pixels[20] = {0};
Jamie Madillf67115c2014-04-22 13:14:05 -04001163 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1164 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001165
1166 if (extensionEnabled("GL_EXT_texture_storage"))
1167 {
1168 // Create a 1-level immutable texture.
1169 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1170
1171 // Try calling sub image on the second level.
1172 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1173 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1174 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001175}
Geoff Langc41e42d2014-04-28 10:58:16 -04001176
John Bauman18319182016-09-28 14:22:27 -07001177// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1178TEST_P(Texture2DTest, QueryBinding)
1179{
1180 glBindTexture(GL_TEXTURE_2D, 0);
1181 EXPECT_GL_ERROR(GL_NO_ERROR);
1182
1183 GLint textureBinding;
1184 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1185 EXPECT_GL_NO_ERROR();
1186 EXPECT_EQ(0, textureBinding);
1187
1188 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
1189 if (extensionEnabled("GL_OES_EGL_image_external") ||
1190 extensionEnabled("GL_NV_EGL_stream_consumer_external"))
1191 {
1192 EXPECT_GL_NO_ERROR();
1193 EXPECT_EQ(0, textureBinding);
1194 }
1195 else
1196 {
1197 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1198 }
1199}
1200
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001201TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001202{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001203 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001204 EXPECT_GL_ERROR(GL_NO_ERROR);
1205
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001206 setUpProgram();
1207
Geoff Langc41e42d2014-04-28 10:58:16 -04001208 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001209 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001210 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001211 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001212
Jamie Madill50cf2be2018-06-15 09:46:57 -04001213 const GLubyte *pixel[4] = {0};
Geoff Langc41e42d2014-04-28 10:58:16 -04001214
1215 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1216 EXPECT_GL_NO_ERROR();
1217
1218 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1219 EXPECT_GL_NO_ERROR();
1220
1221 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1222 EXPECT_GL_NO_ERROR();
1223}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001224
1225// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001226TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001227{
1228 glActiveTexture(GL_TEXTURE0);
1229 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1230 glActiveTexture(GL_TEXTURE1);
1231 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1232 EXPECT_GL_ERROR(GL_NO_ERROR);
1233
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001234 glUseProgram(mProgram);
1235 glUniform1i(mTexture2DUniformLocation, 0);
1236 glUniform1i(mTextureCubeUniformLocation, 1);
1237 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001238 EXPECT_GL_NO_ERROR();
1239}
Jamie Madill9aca0592014-10-06 16:26:59 -04001240
Olli Etuaho53a2da12016-01-11 15:43:32 +02001241// Test drawing with two texture types accessed from the same shader and check that the result of
1242// drawing is correct.
1243TEST_P(TextureCubeTest, CubeMapDraw)
1244{
1245 GLubyte texData[4];
1246 texData[0] = 0;
1247 texData[1] = 60;
1248 texData[2] = 0;
1249 texData[3] = 255;
1250
1251 glActiveTexture(GL_TEXTURE0);
1252 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1253 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1254
1255 glActiveTexture(GL_TEXTURE1);
1256 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1257 texData[1] = 120;
1258 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1259 texData);
1260 EXPECT_GL_ERROR(GL_NO_ERROR);
1261
1262 glUseProgram(mProgram);
1263 glUniform1i(mTexture2DUniformLocation, 0);
1264 glUniform1i(mTextureCubeUniformLocation, 1);
1265 drawQuad(mProgram, "position", 0.5f);
1266 EXPECT_GL_NO_ERROR();
1267
1268 int px = getWindowWidth() - 1;
1269 int py = 0;
1270 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1271}
1272
Olli Etuaho4644a202016-01-12 15:12:53 +02001273TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1274{
1275 glActiveTexture(GL_TEXTURE0);
1276 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1277 GLubyte texData[4];
1278 texData[0] = 0;
1279 texData[1] = 128;
1280 texData[2] = 0;
1281 texData[3] = 255;
1282 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1283 glUseProgram(mProgram);
1284 glUniform1i(mTexture2DUniformLocation, 0);
1285 drawQuad(mProgram, "position", 0.5f);
1286 EXPECT_GL_NO_ERROR();
1287
1288 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1289}
1290
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001291// Test drawing with two textures passed to the shader in a sampler array.
1292TEST_P(SamplerArrayTest, SamplerArrayDraw)
1293{
1294 testSamplerArrayDraw();
1295}
1296
1297// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1298// user-defined function in the shader.
1299TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1300{
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05001301 // TODO: Diagnose and fix. http://anglebug.com/2955
1302 ANGLE_SKIP_TEST_IF(IsVulkan() && IsAndroid());
1303
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001304 testSamplerArrayDraw();
1305}
1306
Jamie Madill9aca0592014-10-06 16:26:59 -04001307// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001308TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001309{
1310 int px = getWindowWidth() / 2;
1311 int py = getWindowHeight() / 2;
1312
1313 glActiveTexture(GL_TEXTURE0);
1314 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1315
Olli Etuahoa314b612016-03-10 16:43:00 +02001316 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001317
Olli Etuahoa314b612016-03-10 16:43:00 +02001318 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001319 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1320 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1321 glGenerateMipmap(GL_TEXTURE_2D);
1322
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001323 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001324 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001325 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1326 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001327 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001328 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001329
Olli Etuahoa314b612016-03-10 16:43:00 +02001330 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001331
Olli Etuahoa314b612016-03-10 16:43:00 +02001332 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1333 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001334 glGenerateMipmap(GL_TEXTURE_2D);
1335
Olli Etuahoa314b612016-03-10 16:43:00 +02001336 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001337
Olli Etuahoa314b612016-03-10 16:43:00 +02001338 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1339 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001340 glGenerateMipmap(GL_TEXTURE_2D);
1341
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001342 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001343
1344 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001345 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001346}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001347
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001348// Test creating a FBO with a cube map render target, to test an ANGLE bug
1349// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001350TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001351{
Jamie Madill3f3b3582018-09-14 10:38:44 -04001352 GLFramebuffer fbo;
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001353 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1354
1355 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Jamie Madill50cf2be2018-06-15 09:46:57 -04001356 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1357 mTextureCube, 0);
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001358
Corentin Wallez322653b2015-06-17 18:33:56 +02001359 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001360 EXPECT_GL_NO_ERROR();
Jamie Madill3f3b3582018-09-14 10:38:44 -04001361
1362 // Test clearing the six mip faces individually.
1363 std::array<GLColor, 6> faceColors = {{GLColor::red, GLColor::green, GLColor::blue,
1364 GLColor::yellow, GLColor::cyan, GLColor::magenta}};
1365
1366 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1367 {
1368 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1369 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1370
1371 Vector4 clearColorF = faceColors[faceIndex].toNormalizedVector();
1372 glClearColor(clearColorF.x(), clearColorF.y(), clearColorF.z(), clearColorF.w());
1373 glClear(GL_COLOR_BUFFER_BIT);
1374
1375 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex]);
1376 }
1377
1378 // Iterate the faces again to make sure the colors haven't changed.
1379 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1380 {
1381 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1382 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1383 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex])
1384 << "face color " << faceIndex << " shouldn't change";
1385 }
1386}
1387
1388// Tests clearing a cube map with a scissor enabled.
1389TEST_P(TextureCubeTest, CubeMapFBOScissoredClear)
1390{
1391 // TODO(jie.a.chen): Diagnose and fix. http://anglebug.com/2822
1392 ANGLE_SKIP_TEST_IF(IsVulkan() && IsIntel() && IsWindows());
1393
1394 constexpr size_t kSize = 16;
1395
1396 GLFramebuffer fbo;
1397 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1398 glViewport(0, 0, kSize, kSize);
1399
1400 GLTexture texcube;
1401 glBindTexture(GL_TEXTURE_CUBE_MAP, texcube);
1402 for (GLenum face = 0; face < 6; face++)
1403 {
1404 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA,
1405 GL_UNSIGNED_BYTE, nullptr);
1406 }
1407 ASSERT_GL_NO_ERROR();
1408
1409 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1410 texcube, 0);
1411
1412 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1413 ASSERT_GL_NO_ERROR();
1414
1415 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1416 glClear(GL_COLOR_BUFFER_BIT);
1417 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1418
1419 glEnable(GL_SCISSOR_TEST);
1420 glScissor(kSize / 2, 0, kSize / 2, kSize);
1421 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
1422 glClear(GL_COLOR_BUFFER_BIT);
1423
1424 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1425 EXPECT_PIXEL_COLOR_EQ(kSize / 2 + 1, 0, GLColor::green);
1426
1427 ASSERT_GL_NO_ERROR();
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001428}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001429
Jamie Madill50cf2be2018-06-15 09:46:57 -04001430// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a
1431// default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001432TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001433{
Luc Ferron7348fc52018-05-09 07:17:16 -04001434 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -04001435
Jamie Madill50cf2be2018-06-15 09:46:57 -04001436 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001437 int height = getWindowHeight();
1438
1439 GLuint tex2D;
1440 glGenTextures(1, &tex2D);
1441 glActiveTexture(GL_TEXTURE0);
1442 glBindTexture(GL_TEXTURE_2D, tex2D);
1443
1444 // Fill with red
1445 std::vector<GLubyte> pixels(3 * 16 * 16);
1446 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1447 {
1448 pixels[pixelId * 3 + 0] = 255;
1449 pixels[pixelId * 3 + 1] = 0;
1450 pixels[pixelId * 3 + 2] = 0;
1451 }
1452
1453 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001454 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1455 // 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 -04001456 if (getClientMajorVersion() >= 3)
1457 {
1458 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1459 }
1460 else
1461 {
1462 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1463 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001464
1465 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1466 // glTexSubImage2D should take into account that the image is dirty.
1467 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1468 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1469 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1470
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001471 setUpProgram();
1472
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001473 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001474 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001475 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001476 glDeleteTextures(1, &tex2D);
1477 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001478 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001479
1480 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001481 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1482 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001483}
1484
Jamie Madill50cf2be2018-06-15 09:46:57 -04001485// Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has
1486// initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001487TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001488{
1489 if (extensionEnabled("NV_pixel_buffer_object"))
1490 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04001491 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001492 int height = getWindowHeight();
1493
1494 GLuint tex2D;
1495 glGenTextures(1, &tex2D);
1496 glActiveTexture(GL_TEXTURE0);
1497 glBindTexture(GL_TEXTURE_2D, tex2D);
1498
1499 // Fill with red
1500 std::vector<GLubyte> pixels(3 * 16 * 16);
1501 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1502 {
1503 pixels[pixelId * 3 + 0] = 255;
1504 pixels[pixelId * 3 + 1] = 0;
1505 pixels[pixelId * 3 + 2] = 0;
1506 }
1507
1508 // Read 16x16 region from red backbuffer to PBO
1509 GLuint pbo;
1510 glGenBuffers(1, &pbo);
1511 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1512 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1513
1514 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001515 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1516 // 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 +00001517 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1518
1519 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1520 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001521 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 +00001522 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1523 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1524
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001525 setUpProgram();
1526
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001527 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001528 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001529 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001530 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001531 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001532 EXPECT_GL_NO_ERROR();
1533 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1534 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1535 }
1536}
Jamie Madillbc393df2015-01-29 13:46:07 -05001537
1538// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001539TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001540{
1541 testFloatCopySubImage(1, 1);
1542}
1543
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001544TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001545{
1546 testFloatCopySubImage(2, 1);
1547}
1548
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001549TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001550{
1551 testFloatCopySubImage(2, 2);
1552}
1553
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001554TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001555{
1556 testFloatCopySubImage(3, 1);
1557}
1558
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001559TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001560{
1561 testFloatCopySubImage(3, 2);
1562}
1563
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001564TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001565{
Yunchao He9550c602018-02-13 14:47:05 +08001566 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1567 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001568
Yunchao He9550c602018-02-13 14:47:05 +08001569 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1570 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001571
Jamie Madillbc393df2015-01-29 13:46:07 -05001572 testFloatCopySubImage(3, 3);
1573}
1574
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001575TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001576{
1577 testFloatCopySubImage(4, 1);
1578}
1579
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001580TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001581{
1582 testFloatCopySubImage(4, 2);
1583}
1584
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001585TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001586{
Yunchao He9550c602018-02-13 14:47:05 +08001587 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1588 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001589
Jamie Madillbc393df2015-01-29 13:46:07 -05001590 testFloatCopySubImage(4, 3);
1591}
1592
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001593TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001594{
Luc Ferronf786b702018-07-10 11:01:43 -04001595 // TODO(lucferron): This test fails only on linux and intel.
1596 // http://anglebug.com/2726
1597 ANGLE_SKIP_TEST_IF(IsVulkan() && IsLinux() && IsIntel());
1598
Yunchao He9550c602018-02-13 14:47:05 +08001599 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1600 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001601
Jamie Madillbc393df2015-01-29 13:46:07 -05001602 testFloatCopySubImage(4, 4);
1603}
Austin Kinross07285142015-03-26 11:36:16 -07001604
Jamie Madill50cf2be2018-06-15 09:46:57 -04001605// Port of
1606// https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1607// Run against GL_ALPHA/UNSIGNED_BYTE format, to ensure that D3D11 Feature Level 9_3 correctly
1608// handles GL_ALPHA
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001609TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001610{
1611 const int npotTexSize = 5;
Jamie Madill50cf2be2018-06-15 09:46:57 -04001612 const int potTexSize = 4; // Should be less than npotTexSize
Austin Kinross07285142015-03-26 11:36:16 -07001613 GLuint tex2D;
1614
1615 if (extensionEnabled("GL_OES_texture_npot"))
1616 {
1617 // This test isn't applicable if texture_npot is enabled
1618 return;
1619 }
1620
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001621 setUpProgram();
1622
Austin Kinross07285142015-03-26 11:36:16 -07001623 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1624
Austin Kinross5faa15b2016-01-11 13:32:48 -08001625 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1626 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1627
Austin Kinross07285142015-03-26 11:36:16 -07001628 glActiveTexture(GL_TEXTURE0);
1629 glGenTextures(1, &tex2D);
1630 glBindTexture(GL_TEXTURE_2D, tex2D);
1631
Till Rathmannc1551dc2018-08-15 17:04:49 +02001632 const std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize, 64);
Austin Kinross07285142015-03-26 11:36:16 -07001633
1634 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1635 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1636
1637 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
Jamie Madill50cf2be2018-06-15 09:46:57 -04001638 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1639 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001640 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1641
1642 // Check that an NPOT texture on level 0 succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001643 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1644 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001645 EXPECT_GL_NO_ERROR();
1646
1647 // Check that generateMipmap fails on NPOT
1648 glGenerateMipmap(GL_TEXTURE_2D);
1649 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1650
1651 // Check that nothing is drawn if filtering is not correct for NPOT
1652 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1653 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1654 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1655 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1656 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001657 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001658 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1659
1660 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1661 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1662 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1663 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1664 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001665 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001666 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1667
1668 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1669 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1670 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001671 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001672 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1673
1674 // Check that glTexImage2D for POT texture succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001675 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE,
1676 pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001677 EXPECT_GL_NO_ERROR();
1678
1679 // Check that generateMipmap for an POT texture succeeds
1680 glGenerateMipmap(GL_TEXTURE_2D);
1681 EXPECT_GL_NO_ERROR();
1682
1683 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1684 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1685 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1686 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1687 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1688 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001689 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001690 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1691 EXPECT_GL_NO_ERROR();
1692}
Jamie Madillfa05f602015-05-07 13:47:11 -04001693
Austin Kinross08528e12015-10-07 16:24:40 -07001694// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1695// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001696TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001697{
1698 glActiveTexture(GL_TEXTURE0);
1699 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1700
1701 // Create an 8x8 (i.e. power-of-two) texture.
1702 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1703 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1704 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1705 glGenerateMipmap(GL_TEXTURE_2D);
1706
1707 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1708 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001709 std::array<GLColor, 3 * 3> data;
1710 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001711
1712 EXPECT_GL_NO_ERROR();
1713}
1714
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001715// Test to check that texture completeness is determined correctly when the texture base level is
1716// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1717TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1718{
1719 glActiveTexture(GL_TEXTURE0);
1720 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001721
1722 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1723 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1724 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1725 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1726 texDataGreen.data());
1727 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1728 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001729 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1730 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1731 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1732
1733 EXPECT_GL_NO_ERROR();
1734
1735 drawQuad(mProgram, "position", 0.5f);
1736
Olli Etuahoa314b612016-03-10 16:43:00 +02001737 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1738}
1739
1740// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1741// have images defined.
1742TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1743{
Yunchao He9550c602018-02-13 14:47:05 +08001744 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1745 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1746
Olli Etuahoa314b612016-03-10 16:43:00 +02001747 glActiveTexture(GL_TEXTURE0);
1748 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1749 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1750 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1751 texDataGreen.data());
1752 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1753 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1754 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1755 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1756
1757 EXPECT_GL_NO_ERROR();
1758
1759 drawQuad(mProgram, "position", 0.5f);
1760
1761 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1762}
1763
Olli Etuahoe8528d82016-05-16 17:50:52 +03001764// Test that drawing works correctly when level 0 is undefined and base level is 1.
1765TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1766{
Yunchao He9550c602018-02-13 14:47:05 +08001767 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1768 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1769
Olli Etuahoe8528d82016-05-16 17:50:52 +03001770 glActiveTexture(GL_TEXTURE0);
1771 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1772 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1773 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1774 texDataGreen.data());
1775 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1776 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1777 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1778 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1779
1780 EXPECT_GL_NO_ERROR();
1781
1782 // Texture is incomplete.
1783 drawQuad(mProgram, "position", 0.5f);
1784 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1785
1786 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1787 texDataGreen.data());
1788
1789 // Texture is now complete.
1790 drawQuad(mProgram, "position", 0.5f);
1791 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1792}
1793
Olli Etuahoa314b612016-03-10 16:43:00 +02001794// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1795// dimensions that don't fit the images inside the range.
1796// GLES 3.0.4 section 3.8.13 Texture completeness
1797TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1798{
Olli Etuahoa314b612016-03-10 16:43:00 +02001799 glActiveTexture(GL_TEXTURE0);
1800 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1801 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1802 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1803 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1804
1805 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1806 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1807
1808 // Two levels that are initially unused.
1809 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1810 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1811 texDataCyan.data());
1812
1813 // One level that is used - only this level should affect completeness.
1814 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1815 texDataGreen.data());
1816
1817 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1818 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1819
1820 EXPECT_GL_NO_ERROR();
1821
1822 drawQuad(mProgram, "position", 0.5f);
1823
1824 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1825
Yunchao He2f23f352018-02-11 22:11:37 +08001826 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001827
1828 // Switch the level that is being used to the cyan level 2.
1829 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1830 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1831
1832 EXPECT_GL_NO_ERROR();
1833
1834 drawQuad(mProgram, "position", 0.5f);
1835
1836 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1837}
1838
1839// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1840// have images defined.
1841TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1842{
Olli Etuahoa314b612016-03-10 16:43:00 +02001843 glActiveTexture(GL_TEXTURE0);
1844 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1845 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1846 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1847 texDataGreen.data());
1848 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1849 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1850 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1851 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1852
1853 EXPECT_GL_NO_ERROR();
1854
1855 drawQuad(mProgram, "position", 0.5f);
1856
1857 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1858}
1859
1860// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1861// dimensions that don't fit the images inside the range.
1862// GLES 3.0.4 section 3.8.13 Texture completeness
1863TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1864{
Olli Etuahoa314b612016-03-10 16:43:00 +02001865 glActiveTexture(GL_TEXTURE0);
1866 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1867 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1868 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1869 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1870
1871 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1872 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1873
1874 // Two levels that are initially unused.
1875 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1876 texDataRed.data());
1877 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1878 texDataCyan.data());
1879
1880 // One level that is used - only this level should affect completeness.
1881 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1882 texDataGreen.data());
1883
1884 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1885 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1886
1887 EXPECT_GL_NO_ERROR();
1888
1889 drawQuad(mProgram, "position", 0.5f);
1890
1891 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1892
Yunchao He2f23f352018-02-11 22:11:37 +08001893 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001894
1895 // Switch the level that is being used to the cyan level 2.
1896 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
1897 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
1898
1899 EXPECT_GL_NO_ERROR();
1900
1901 drawQuad(mProgram, "position", 0.5f);
1902
1903 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1904}
1905
1906// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1907// have images defined.
1908TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
1909{
Olli Etuahoa314b612016-03-10 16:43:00 +02001910 glActiveTexture(GL_TEXTURE0);
1911 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
1912 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1913 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1914 texDataGreen.data());
1915 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1916 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1917 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1918 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1919
1920 EXPECT_GL_NO_ERROR();
1921
1922 drawQuad(mProgram, "position", 0.5f);
1923
1924 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1925}
1926
1927// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1928// dimensions that don't fit the images inside the range.
1929// GLES 3.0.4 section 3.8.13 Texture completeness
1930TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1931{
Olli Etuahoa314b612016-03-10 16:43:00 +02001932 glActiveTexture(GL_TEXTURE0);
1933 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
1934 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1935 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1936 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1937
1938 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1939 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1940
1941 // Two levels that are initially unused.
1942 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1943 texDataRed.data());
1944 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1945 texDataCyan.data());
1946
1947 // One level that is used - only this level should affect completeness.
1948 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1949 texDataGreen.data());
1950
1951 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1952 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1953
1954 EXPECT_GL_NO_ERROR();
1955
1956 drawQuad(mProgram, "position", 0.5f);
1957
1958 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1959
Yunchao He2f23f352018-02-11 22:11:37 +08001960 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
1961
Yunchao He9550c602018-02-13 14:47:05 +08001962 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
1963 // level was changed.
1964 ANGLE_SKIP_TEST_IF(IsNVIDIA() && (IsOpenGL() || IsOpenGLES()));
Olli Etuahoa314b612016-03-10 16:43:00 +02001965
1966 // Switch the level that is being used to the cyan level 2.
1967 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
1968 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
1969
1970 EXPECT_GL_NO_ERROR();
1971
1972 drawQuad(mProgram, "position", 0.5f);
1973
1974 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1975}
1976
1977// Test that texture completeness is updated if texture max level changes.
1978// GLES 3.0.4 section 3.8.13 Texture completeness
1979TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
1980{
Olli Etuahoa314b612016-03-10 16:43:00 +02001981 glActiveTexture(GL_TEXTURE0);
1982 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1983 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
1984
1985 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1986 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1987
1988 // A level that is initially unused.
1989 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1990 texDataGreen.data());
1991
1992 // One level that is initially used - only this level should affect completeness.
1993 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1994 texDataGreen.data());
1995
1996 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
1997 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
1998
1999 EXPECT_GL_NO_ERROR();
2000
2001 drawQuad(mProgram, "position", 0.5f);
2002
2003 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2004
2005 // Switch the max level to level 1. The levels within the used range now have inconsistent
2006 // dimensions and the texture should be incomplete.
2007 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2008
2009 EXPECT_GL_NO_ERROR();
2010
2011 drawQuad(mProgram, "position", 0.5f);
2012
2013 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2014}
2015
2016// Test that 3D texture completeness is updated if texture max level changes.
2017// GLES 3.0.4 section 3.8.13 Texture completeness
2018TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2019{
Olli Etuahoa314b612016-03-10 16:43:00 +02002020 glActiveTexture(GL_TEXTURE0);
2021 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2022 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2023
2024 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2025 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2026
2027 // A level that is initially unused.
2028 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2029 texDataGreen.data());
2030
2031 // One level that is initially used - only this level should affect completeness.
2032 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2033 texDataGreen.data());
2034
2035 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2036 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2037
2038 EXPECT_GL_NO_ERROR();
2039
2040 drawQuad(mProgram, "position", 0.5f);
2041
2042 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2043
2044 // Switch the max level to level 1. The levels within the used range now have inconsistent
2045 // dimensions and the texture should be incomplete.
2046 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2047
2048 EXPECT_GL_NO_ERROR();
2049
2050 drawQuad(mProgram, "position", 0.5f);
2051
2052 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2053}
2054
2055// Test that texture completeness is updated if texture base level changes.
2056// GLES 3.0.4 section 3.8.13 Texture completeness
2057TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2058{
Olli Etuahoa314b612016-03-10 16:43:00 +02002059 glActiveTexture(GL_TEXTURE0);
2060 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2061 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2062
2063 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2064 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2065
2066 // Two levels that are initially unused.
2067 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2068 texDataGreen.data());
2069 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2070 texDataGreen.data());
2071
2072 // One level that is initially used - only this level should affect completeness.
2073 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2074 texDataGreen.data());
2075
2076 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2077 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2078
2079 EXPECT_GL_NO_ERROR();
2080
2081 drawQuad(mProgram, "position", 0.5f);
2082
2083 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2084
2085 // Switch the base level to level 1. The levels within the used range now have inconsistent
2086 // dimensions and the texture should be incomplete.
2087 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2088
2089 EXPECT_GL_NO_ERROR();
2090
2091 drawQuad(mProgram, "position", 0.5f);
2092
2093 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2094}
2095
2096// Test that texture is not complete if base level is greater than max level.
2097// GLES 3.0.4 section 3.8.13 Texture completeness
2098TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2099{
Olli Etuahoa314b612016-03-10 16:43:00 +02002100 glActiveTexture(GL_TEXTURE0);
2101 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2102
2103 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2104 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2105
2106 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2107
2108 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2109 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2110
2111 EXPECT_GL_NO_ERROR();
2112
2113 drawQuad(mProgram, "position", 0.5f);
2114
2115 // Texture should be incomplete.
2116 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2117}
2118
2119// Test that immutable texture base level and max level are clamped.
2120// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2121TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2122{
Olli Etuahoa314b612016-03-10 16:43:00 +02002123 glActiveTexture(GL_TEXTURE0);
2124 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2125
2126 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2127 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2128
2129 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2130
2131 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2132
2133 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2134 // should be clamped to [base_level, levels - 1].
2135 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2136 // In the case of this test, those rules make the effective base level and max level 0.
2137 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2138 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2139
2140 EXPECT_GL_NO_ERROR();
2141
2142 drawQuad(mProgram, "position", 0.5f);
2143
2144 // Texture should be complete.
2145 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2146}
2147
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002148// Test that changing base level works when it affects the format of the texture.
2149TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2150{
Yunchao He9550c602018-02-13 14:47:05 +08002151 // Observed rendering corruption on NVIDIA OpenGL.
2152 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL());
2153
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002154 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002155
2156 // Observed incorrect rendering on AMD OpenGL.
2157 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002158
2159 glActiveTexture(GL_TEXTURE0);
2160 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2161 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2162 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2163
2164 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2165 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2166
2167 // RGBA8 level that's initially unused.
2168 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2169 texDataCyan.data());
2170
2171 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2172 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2173
2174 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2175 // format. It reads green channel data from the green and alpha channels of texDataGreen
2176 // (this is a bit hacky but works).
2177 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2178
2179 EXPECT_GL_NO_ERROR();
2180
2181 drawQuad(mProgram, "position", 0.5f);
2182
2183 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2184
2185 // Switch the texture to use the cyan level 0 with the RGBA format.
2186 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2187 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2188
2189 EXPECT_GL_NO_ERROR();
2190
2191 drawQuad(mProgram, "position", 0.5f);
2192
2193 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2194}
2195
Olli Etuahoa314b612016-03-10 16:43:00 +02002196// Test that setting a texture image works when base level is out of range.
2197TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2198{
2199 glActiveTexture(GL_TEXTURE0);
2200 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2201
2202 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2203 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2204
2205 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2206 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2207
2208 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2209
2210 EXPECT_GL_NO_ERROR();
2211
2212 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2213
2214 drawQuad(mProgram, "position", 0.5f);
2215
2216 // Texture should be complete.
2217 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002218}
2219
Jamie Madill50cf2be2018-06-15 09:46:57 -04002220// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG
2221// RBA->RGBA8, with 1.0 in the alpha channel. This test covers a bug where redefining array textures
2222// with these formats does not work as expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002223TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002224{
2225 std::vector<GLubyte> pixelData;
2226 for (size_t count = 0; count < 5000; count++)
2227 {
2228 pixelData.push_back(0u);
2229 pixelData.push_back(255u);
2230 pixelData.push_back(0u);
2231 }
2232
2233 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002234 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002235 glUniform1i(mTextureArrayLocation, 0);
2236
2237 // The first draw worked correctly.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002238 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2239 &pixelData[0]);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002240
2241 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2242 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2243 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2244 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002245 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002246 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002247
2248 // The dimension of the respecification must match the original exactly to trigger the bug.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002249 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2250 &pixelData[0]);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002251 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002252 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002253
2254 ASSERT_GL_NO_ERROR();
2255}
2256
Olli Etuaho1a679902016-01-14 12:21:47 +02002257// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2258// This test is needed especially to confirm that sampler registers get assigned correctly on
2259// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2260TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2261{
2262 glActiveTexture(GL_TEXTURE0);
2263 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2264 GLubyte texData[4];
2265 texData[0] = 0;
2266 texData[1] = 60;
2267 texData[2] = 0;
2268 texData[3] = 255;
2269 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2270
2271 glActiveTexture(GL_TEXTURE1);
2272 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2273 GLfloat depthTexData[1];
2274 depthTexData[0] = 0.5f;
2275 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2276 depthTexData);
2277
2278 glUseProgram(mProgram);
2279 glUniform1f(mDepthRefUniformLocation, 0.3f);
2280 glUniform1i(mTexture3DUniformLocation, 0);
2281 glUniform1i(mTextureShadowUniformLocation, 1);
2282
2283 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2284 drawQuad(mProgram, "position", 0.5f);
2285 EXPECT_GL_NO_ERROR();
2286 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2287 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2288
2289 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2290 drawQuad(mProgram, "position", 0.5f);
2291 EXPECT_GL_NO_ERROR();
2292 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2293 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2294}
2295
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002296// Test multiple different sampler types in the same shader.
2297// This test makes sure that even if sampler / texture registers get grouped together based on type
2298// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2299// still has the right register index information for each ESSL sampler.
2300// The tested ESSL samplers have the following types in D3D11 HLSL:
2301// sampler2D: Texture2D + SamplerState
2302// samplerCube: TextureCube + SamplerState
2303// sampler2DShadow: Texture2D + SamplerComparisonState
2304// samplerCubeShadow: TextureCube + SamplerComparisonState
2305TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2306{
2307 glActiveTexture(GL_TEXTURE0);
2308 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2309 GLubyte texData[4];
2310 texData[0] = 0;
2311 texData[1] = 0;
2312 texData[2] = 120;
2313 texData[3] = 255;
2314 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2315
2316 glActiveTexture(GL_TEXTURE1);
2317 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2318 texData[0] = 0;
2319 texData[1] = 90;
2320 texData[2] = 0;
2321 texData[3] = 255;
2322 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2323 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2324 texData);
2325
2326 glActiveTexture(GL_TEXTURE2);
2327 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2328 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2329 GLfloat depthTexData[1];
2330 depthTexData[0] = 0.5f;
2331 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2332 depthTexData);
2333
2334 glActiveTexture(GL_TEXTURE3);
2335 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2336 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2337 depthTexData[0] = 0.2f;
2338 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2339 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2340 depthTexData);
2341
2342 EXPECT_GL_NO_ERROR();
2343
2344 glUseProgram(mProgram);
2345 glUniform1f(mDepthRefUniformLocation, 0.3f);
2346 glUniform1i(mTexture2DUniformLocation, 0);
2347 glUniform1i(mTextureCubeUniformLocation, 1);
2348 glUniform1i(mTexture2DShadowUniformLocation, 2);
2349 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2350
2351 drawQuad(mProgram, "position", 0.5f);
2352 EXPECT_GL_NO_ERROR();
2353 // The shader writes:
2354 // <texture 2d color> +
2355 // <cube map color> +
2356 // 0.25 * <comparison result (1.0)> +
2357 // 0.125 * <comparison result (0.0)>
2358 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2359}
2360
Olli Etuahobce743a2016-01-15 17:18:28 +02002361// Test different base levels on textures accessed through the same sampler array.
2362// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2363TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2364{
Yunchao He9550c602018-02-13 14:47:05 +08002365 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2366
Olli Etuahobce743a2016-01-15 17:18:28 +02002367 glActiveTexture(GL_TEXTURE0);
2368 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2369 GLsizei size = 64;
2370 for (GLint level = 0; level < 7; ++level)
2371 {
2372 ASSERT_LT(0, size);
2373 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2374 nullptr);
2375 size = size / 2;
2376 }
2377 ASSERT_EQ(0, size);
2378 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2379
2380 glActiveTexture(GL_TEXTURE1);
2381 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2382 size = 128;
2383 for (GLint level = 0; level < 8; ++level)
2384 {
2385 ASSERT_LT(0, size);
2386 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2387 nullptr);
2388 size = size / 2;
2389 }
2390 ASSERT_EQ(0, size);
2391 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2392 EXPECT_GL_NO_ERROR();
2393
2394 glUseProgram(mProgram);
2395 glUniform1i(mTexture0Location, 0);
2396 glUniform1i(mTexture1Location, 1);
2397
Olli Etuaho5804dc82018-04-13 14:11:46 +03002398 drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
Olli Etuahobce743a2016-01-15 17:18:28 +02002399 EXPECT_GL_NO_ERROR();
2400 // Red channel: width of level 1 of texture A: 32.
2401 // Green channel: width of level 3 of texture B: 16.
2402 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2403}
2404
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002405// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2406// ES 3.0.4 table 3.24
2407TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2408{
2409 glActiveTexture(GL_TEXTURE0);
2410 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2411 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2412 EXPECT_GL_NO_ERROR();
2413
2414 drawQuad(mProgram, "position", 0.5f);
2415
2416 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2417}
2418
2419// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2420// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002421TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002422{
Luc Ferron5164b792018-03-06 09:10:12 -05002423 setUpProgram();
2424
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002425 glActiveTexture(GL_TEXTURE0);
2426 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2427 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2428 EXPECT_GL_NO_ERROR();
2429
2430 drawQuad(mProgram, "position", 0.5f);
2431
2432 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2433}
2434
Luc Ferron5164b792018-03-06 09:10:12 -05002435// Validate that every component of the pixel will be equal to the luminance value we've set
2436// and that the alpha channel will be 1 (or 255 to be exact).
2437TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2438{
2439 setUpProgram();
2440
2441 glActiveTexture(GL_TEXTURE0);
2442 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2443 uint8_t pixel = 50;
2444 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2445 EXPECT_GL_NO_ERROR();
2446
2447 drawQuad(mProgram, "position", 0.5f);
2448
2449 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2450}
2451
2452// Validate that every component of the pixel will be equal to the luminance value we've set
2453// and that the alpha channel will be the second component.
2454TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2455{
2456 setUpProgram();
2457
2458 glActiveTexture(GL_TEXTURE0);
2459 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2460 uint8_t pixel[] = {50, 25};
2461 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2462 GL_UNSIGNED_BYTE, pixel);
2463 EXPECT_GL_NO_ERROR();
2464
2465 drawQuad(mProgram, "position", 0.5f);
2466
2467 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2468}
2469
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002470// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2471// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002472TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002473{
Luc Ferrond8c632c2018-04-10 12:31:44 -04002474 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
2475 ANGLE_SKIP_TEST_IF(IsD3D9());
2476 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002477
2478 setUpProgram();
2479
Luc Ferrond8c632c2018-04-10 12:31:44 -04002480 glActiveTexture(GL_TEXTURE0);
2481 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2482 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2483 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002484
Luc Ferrond8c632c2018-04-10 12:31:44 -04002485 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002486
Luc Ferrond8c632c2018-04-10 12:31:44 -04002487 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002488}
2489
2490// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2491// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002492TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002493{
Luc Ferrond8c632c2018-04-10 12:31:44 -04002494 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
2495 ANGLE_SKIP_TEST_IF(IsD3D9());
2496 ANGLE_SKIP_TEST_IF(IsVulkan());
2497 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES());
2498 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2499 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002500
Luc Ferrond8c632c2018-04-10 12:31:44 -04002501 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002502
Luc Ferrond8c632c2018-04-10 12:31:44 -04002503 glActiveTexture(GL_TEXTURE0);
2504 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2505 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2506 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002507
Luc Ferrond8c632c2018-04-10 12:31:44 -04002508 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002509
Luc Ferrond8c632c2018-04-10 12:31:44 -04002510 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002511}
2512
2513// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2514// ES 3.0.4 table 3.24
2515TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2516{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002517 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2518
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002519 glActiveTexture(GL_TEXTURE0);
2520 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2521 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2522 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2523 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2524 EXPECT_GL_NO_ERROR();
2525
2526 drawQuad(mProgram, "position", 0.5f);
2527
2528 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2529}
2530
2531// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2532// ES 3.0.4 table 3.24
2533TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2534{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002535 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2536
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002537 glActiveTexture(GL_TEXTURE0);
2538 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2539
2540 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2541 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2542 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2543 EXPECT_GL_NO_ERROR();
2544
2545 drawQuad(mProgram, "position", 0.5f);
2546
2547 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2548}
2549
2550// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2551// ES 3.0.4 table 3.24
2552TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2553{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002554 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2555
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002556 glActiveTexture(GL_TEXTURE0);
2557 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2558 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2559 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2560 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2561 EXPECT_GL_NO_ERROR();
2562
2563 drawQuad(mProgram, "position", 0.5f);
2564
2565 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2566}
2567
2568// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2569// ES 3.0.4 table 3.24
2570TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2571{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002572 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2573
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002574 glActiveTexture(GL_TEXTURE0);
2575 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2576 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2577 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2578 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2579 EXPECT_GL_NO_ERROR();
2580
2581 drawQuad(mProgram, "position", 0.5f);
2582
2583 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2584}
2585
2586// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2587// ES 3.0.4 table 3.24
2588TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2589{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002590 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2591
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002592 glActiveTexture(GL_TEXTURE0);
2593 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2594 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2595 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2596 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2597 EXPECT_GL_NO_ERROR();
2598
2599 drawQuad(mProgram, "position", 0.5f);
2600
2601 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2602}
2603
2604// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2605// ES 3.0.4 table 3.24
2606TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2607{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002608 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2609
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002610 glActiveTexture(GL_TEXTURE0);
2611 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2612 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2613 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2614 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2615 EXPECT_GL_NO_ERROR();
2616
2617 drawQuad(mProgram, "position", 0.5f);
2618
2619 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2620}
2621
2622// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2623// ES 3.0.4 table 3.24
2624TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2625{
2626 glActiveTexture(GL_TEXTURE0);
2627 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2628 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2629 EXPECT_GL_NO_ERROR();
2630
2631 drawQuad(mProgram, "position", 0.5f);
2632
2633 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2634}
2635
2636// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2637// ES 3.0.4 table 3.24
2638TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2639{
2640 glActiveTexture(GL_TEXTURE0);
2641 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2642 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2643 nullptr);
2644 EXPECT_GL_NO_ERROR();
2645
2646 drawQuad(mProgram, "position", 0.5f);
2647
2648 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2649}
2650
2651// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2652// ES 3.0.4 table 3.24
2653TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2654{
Yunchao He9550c602018-02-13 14:47:05 +08002655 // Seems to fail on OSX 10.12 Intel.
2656 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Jamie Madillbb1db482017-01-10 10:48:32 -05002657
Yuly Novikov49886892018-01-23 21:18:27 -05002658 // http://anglebug.com/2190
2659 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2660
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002661 glActiveTexture(GL_TEXTURE0);
2662 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2663 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2664 EXPECT_GL_NO_ERROR();
2665
2666 drawQuad(mProgram, "position", 0.5f);
2667
2668 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2669}
2670
2671// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2672// ES 3.0.4 table 3.24
2673TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2674{
Yunchao He9550c602018-02-13 14:47:05 +08002675 // Seems to fail on OSX 10.12 Intel.
2676 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002677
Yuly Novikov49886892018-01-23 21:18:27 -05002678 // http://anglebug.com/2190
2679 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2680
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002681 glActiveTexture(GL_TEXTURE0);
2682 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2683 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2684 EXPECT_GL_NO_ERROR();
2685
2686 drawQuad(mProgram, "position", 0.5f);
2687
2688 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2689}
2690
Olli Etuaho96963162016-03-21 11:54:33 +02002691// Use a sampler in a uniform struct.
2692TEST_P(SamplerInStructTest, SamplerInStruct)
2693{
2694 runSamplerInStructTest();
2695}
2696
2697// Use a sampler in a uniform struct that's passed as a function parameter.
2698TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2699{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002700 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002701 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002702
Olli Etuaho96963162016-03-21 11:54:33 +02002703 runSamplerInStructTest();
2704}
2705
2706// Use a sampler in a uniform struct array with a struct from the array passed as a function
2707// parameter.
2708TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2709{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002710 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002711 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
2712
Olli Etuaho96963162016-03-21 11:54:33 +02002713 runSamplerInStructTest();
2714}
2715
2716// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2717// parameter.
2718TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2719{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002720 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002721 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
2722
Olli Etuaho96963162016-03-21 11:54:33 +02002723 runSamplerInStructTest();
2724}
2725
2726// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2727// similarly named uniform.
2728TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2729{
2730 runSamplerInStructTest();
2731}
2732
Till Rathmannb8543632018-10-02 19:46:14 +02002733// GL_OES_texture_border_clamp
2734class TextureBorderClampTest : public Texture2DTest
2735{
2736 protected:
2737 TextureBorderClampTest() : Texture2DTest() {}
2738
Jamie Madill35cd7332018-12-02 12:03:33 -05002739 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02002740 {
2741 return
2742 R"(precision highp float;
2743 attribute vec4 position;
2744 varying vec2 texcoord;
2745
2746 void main()
2747 {
2748 gl_Position = vec4(position.xy, 0.0, 1.0);
2749 // texcoords in [-0.5, 1.5]
2750 texcoord = (position.xy) + 0.5;
2751 })";
2752 }
2753
2754 void uploadTexture()
2755 {
2756 glActiveTexture(GL_TEXTURE0);
2757 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2758 std::vector<GLColor> texDataRed(1, GLColor::red);
2759 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2760 texDataRed.data());
2761 EXPECT_GL_NO_ERROR();
2762 }
2763};
2764
2765// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
2766// GL_CLAMP_TO_BORDER wrap mode (set with glTexParameter).
2767TEST_P(TextureBorderClampTest, TextureBorderClampFunctional)
2768{
2769 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
2770
2771 setUpProgram();
2772
2773 uploadTexture();
2774
2775 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
2776 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
2777 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2778 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2779 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2780 EXPECT_GL_NO_ERROR();
2781
2782 drawQuad(mProgram, "position", 0.5f);
2783
2784 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
2785 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2786 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
2787}
2788
2789// Test reading back GL_TEXTURE_BORDER_COLOR by glGetTexParameter.
2790TEST_P(TextureBorderClampTest, TextureBorderClampFunctional2)
2791{
2792 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
2793
2794 glActiveTexture(GL_TEXTURE0);
2795 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2796
2797 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2798
2799 GLint colorFixedPoint[4] = {0};
2800 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
2801 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
2802 std::numeric_limits<GLint>::max()};
2803 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
2804 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
2805 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
2806 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
2807
2808 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
2809 std::numeric_limits<GLint>::max()};
2810 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
2811
2812 GLfloat color[4] = {0.0f};
2813 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
2814 EXPECT_EQ(color[0], kFloatBlue.R);
2815 EXPECT_EQ(color[1], kFloatBlue.G);
2816 EXPECT_EQ(color[2], kFloatBlue.B);
2817 EXPECT_EQ(color[3], kFloatBlue.A);
2818}
2819
2820// Test GL_TEXTURE_BORDER_COLOR parameter validation at glTexParameter.
2821TEST_P(TextureBorderClampTest, TextureBorderClampValidation)
2822{
2823 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
2824
2825 glActiveTexture(GL_TEXTURE0);
2826 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2827
2828 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, 1.0f);
2829 EXPECT_GL_ERROR(GL_INVALID_ENUM);
2830
2831 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
2832 EXPECT_GL_ERROR(GL_INVALID_ENUM);
2833
2834 glTexParameterfv(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2835 EXPECT_GL_ERROR(GL_INVALID_ENUM);
2836
2837 GLint colorInt[4] = {0};
2838 glTexParameteriv(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_BORDER_COLOR, colorInt);
2839 EXPECT_GL_ERROR(GL_INVALID_ENUM);
2840
2841 if (getClientMajorVersion() < 3)
2842 {
2843 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
2844 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2845 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
2846 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2847
2848 GLuint colorUInt[4] = {0};
2849 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
2850 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2851 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
2852 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2853
2854 GLSampler sampler;
2855 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
2856 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2857 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
2858 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2859
2860 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
2861 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2862 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
2863 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2864 }
2865}
2866
2867class TextureBorderClampTestES3 : public TextureBorderClampTest
2868{
2869 protected:
2870 TextureBorderClampTestES3() : TextureBorderClampTest() {}
2871};
2872
2873// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
2874// GL_CLAMP_TO_BORDER wrap mode (set with glSamplerParameter).
2875TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional)
2876{
2877 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
2878
2879 setUpProgram();
2880
2881 uploadTexture();
2882
2883 GLSampler sampler;
2884 glBindSampler(0, sampler);
2885 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
2886 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
2887 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2888 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2889 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2890 EXPECT_GL_NO_ERROR();
2891
2892 drawQuad(mProgram, "position", 0.5f);
2893
2894 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
2895 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2896 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
2897}
2898
2899// Test reading back GL_TEXTURE_BORDER_COLOR by glGetSamplerParameter.
2900TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional2)
2901{
2902 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
2903
2904 glActiveTexture(GL_TEXTURE0);
2905
2906 GLSampler sampler;
2907 glBindSampler(0, sampler);
2908
2909 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2910
2911 GLint colorFixedPoint[4] = {0};
2912 glGetSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
2913 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
2914 std::numeric_limits<GLint>::max()};
2915 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
2916 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
2917 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
2918 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
2919
2920 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
2921 std::numeric_limits<GLint>::max()};
2922 glSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
2923
2924 GLfloat color[4] = {0.0f};
2925 glGetSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, color);
2926 EXPECT_EQ(color[0], kFloatBlue.R);
2927 EXPECT_EQ(color[1], kFloatBlue.G);
2928 EXPECT_EQ(color[2], kFloatBlue.B);
2929 EXPECT_EQ(color[3], kFloatBlue.A);
2930
2931 constexpr GLint colorSomewhatRedInt[4] = {500000, 0, 0, std::numeric_limits<GLint>::max()};
2932 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedInt);
2933 GLint colorInt[4] = {0};
2934 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
2935 EXPECT_EQ(colorInt[0], colorSomewhatRedInt[0]);
2936 EXPECT_EQ(colorInt[1], colorSomewhatRedInt[1]);
2937 EXPECT_EQ(colorInt[2], colorSomewhatRedInt[2]);
2938 EXPECT_EQ(colorInt[3], colorSomewhatRedInt[3]);
2939
2940 constexpr GLuint colorSomewhatRedUInt[4] = {500000, 0, 0, std::numeric_limits<GLuint>::max()};
2941 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedUInt);
2942 GLuint colorUInt[4] = {0};
2943 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
2944 EXPECT_EQ(colorUInt[0], colorSomewhatRedUInt[0]);
2945 EXPECT_EQ(colorUInt[1], colorSomewhatRedUInt[1]);
2946 EXPECT_EQ(colorUInt[2], colorSomewhatRedUInt[2]);
2947 EXPECT_EQ(colorUInt[3], colorSomewhatRedUInt[3]);
2948
2949 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2950
2951 constexpr GLint colorSomewhatGreenInt[4] = {0, 500000, 0, std::numeric_limits<GLint>::max()};
2952 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenInt);
2953 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
2954 EXPECT_EQ(colorInt[0], colorSomewhatGreenInt[0]);
2955 EXPECT_EQ(colorInt[1], colorSomewhatGreenInt[1]);
2956 EXPECT_EQ(colorInt[2], colorSomewhatGreenInt[2]);
2957 EXPECT_EQ(colorInt[3], colorSomewhatGreenInt[3]);
2958
2959 constexpr GLuint colorSomewhatGreenUInt[4] = {0, 500000, 0, std::numeric_limits<GLuint>::max()};
2960 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenUInt);
2961 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
2962 EXPECT_EQ(colorUInt[0], colorSomewhatGreenUInt[0]);
2963 EXPECT_EQ(colorUInt[1], colorSomewhatGreenUInt[1]);
2964 EXPECT_EQ(colorUInt[2], colorSomewhatGreenUInt[2]);
2965 EXPECT_EQ(colorUInt[3], colorSomewhatGreenUInt[3]);
2966}
2967
2968// Test GL_TEXTURE_BORDER_COLOR parameter validation at glSamplerParameter.
2969TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Validation)
2970{
2971 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
2972
2973 glActiveTexture(GL_TEXTURE0);
2974
2975 GLSampler sampler;
2976 glBindSampler(0, sampler);
2977
2978 glSamplerParameterf(sampler, GL_TEXTURE_BORDER_COLOR, 1.0f);
2979 EXPECT_GL_ERROR(GL_INVALID_ENUM);
2980
2981 glSamplerParameteri(sampler, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
2982 EXPECT_GL_ERROR(GL_INVALID_ENUM);
2983}
2984
2985class TextureBorderClampIntegerTestES3 : public Texture2DTest
2986{
2987 protected:
2988 TextureBorderClampIntegerTestES3() : Texture2DTest(), isUnsignedIntTest(false) {}
2989
Jamie Madill35cd7332018-12-02 12:03:33 -05002990 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02002991 {
2992 return
2993 R"(#version 300 es
2994 out vec2 texcoord;
2995 in vec4 position;
2996
2997 void main()
2998 {
2999 gl_Position = vec4(position.xy, 0.0, 1.0);
3000 // texcoords in [-0.5, 1.5]
3001 texcoord = (position.xy) + 0.5;
3002 })";
3003 }
3004
Jamie Madill35cd7332018-12-02 12:03:33 -05003005 const char *getFragmentShaderSource()
Till Rathmannb8543632018-10-02 19:46:14 +02003006 {
Jamie Madill35cd7332018-12-02 12:03:33 -05003007 if (isUnsignedIntTest)
3008 {
3009 return "#version 300 es\n"
3010 "precision highp float;\n"
3011 "uniform highp usampler2D tex;\n"
3012 "in vec2 texcoord;\n"
3013 "out vec4 fragColor;\n"
Till Rathmannb8543632018-10-02 19:46:14 +02003014
Jamie Madill35cd7332018-12-02 12:03:33 -05003015 "void main()\n"
3016 "{\n"
3017 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3018 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3019 "fragColor = (texture(tex, texcoord).r == 150u)"
3020 " ? green : red;\n"
3021 "}\n";
3022 }
3023 else
3024 {
3025 return "#version 300 es\n"
3026 "precision highp float;\n"
3027 "uniform highp isampler2D tex;\n"
3028 "in vec2 texcoord;\n"
3029 "out vec4 fragColor;\n"
3030
3031 "void main()\n"
3032 "{\n"
3033 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3034 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3035 "fragColor = (texture(tex, texcoord).r == -50)"
3036 " ? green : red;\n"
3037 "}\n";
3038 }
Till Rathmannb8543632018-10-02 19:46:14 +02003039 }
3040
3041 void uploadTexture()
3042 {
3043 glActiveTexture(GL_TEXTURE0);
3044 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3045 if (isUnsignedIntTest)
3046 {
3047 std::vector<GLubyte> texData(4, 100);
3048 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE,
3049 texData.data());
3050 }
3051 else
3052 {
3053 std::vector<GLbyte> texData(4, 100);
3054 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8I, 1, 1, 0, GL_RGBA_INTEGER, GL_BYTE,
3055 texData.data());
3056 }
3057 EXPECT_GL_NO_ERROR();
3058 }
3059
3060 bool isUnsignedIntTest;
3061};
3062
3063// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3064// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3065TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger)
3066{
3067 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
3068
3069 setUpProgram();
3070
3071 uploadTexture();
3072
3073 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3074 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3075 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3076 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3077
3078 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3079 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3080
3081 EXPECT_GL_NO_ERROR();
3082
3083 drawQuad(mProgram, "position", 0.5f);
3084
3085 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3086 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3087 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3088}
3089
3090// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3091// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3092TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger2)
3093{
3094 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
3095
3096 setUpProgram();
3097
3098 uploadTexture();
3099
3100 GLSampler sampler;
3101 glBindSampler(0, sampler);
3102 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3103 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3104 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3105 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3106
3107 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3108 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3109
3110 EXPECT_GL_NO_ERROR();
3111
3112 drawQuad(mProgram, "position", 0.5f);
3113
3114 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3115 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3116 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3117}
3118
3119// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3120// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIuivOES).
3121TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned)
3122{
3123 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
3124
3125 isUnsignedIntTest = true;
3126
3127 setUpProgram();
3128
3129 uploadTexture();
3130
3131 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3132 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3133 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3134 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3135
3136 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3137 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3138
3139 EXPECT_GL_NO_ERROR();
3140
3141 drawQuad(mProgram, "position", 0.5f);
3142
3143 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3144 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3145 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3146}
3147
3148// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3149// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with
3150// glSamplerParameterIuivOES).
3151TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned2)
3152{
3153 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
3154
3155 isUnsignedIntTest = true;
3156
3157 setUpProgram();
3158
3159 uploadTexture();
3160
3161 GLSampler sampler;
3162 glBindSampler(0, sampler);
3163 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3164 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3165 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3166 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3167
3168 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3169 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3170
3171 EXPECT_GL_NO_ERROR();
3172
3173 drawQuad(mProgram, "position", 0.5f);
3174
3175 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3176 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3177 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3178}
3179
3180// ~GL_OES_texture_border_clamp
3181
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003182class TextureLimitsTest : public ANGLETest
3183{
3184 protected:
3185 struct RGBA8
3186 {
3187 uint8_t R, G, B, A;
3188 };
3189
3190 TextureLimitsTest()
3191 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
3192 {
3193 setWindowWidth(128);
3194 setWindowHeight(128);
3195 setConfigRedBits(8);
3196 setConfigGreenBits(8);
3197 setConfigBlueBits(8);
3198 setConfigAlphaBits(8);
3199 }
3200
Jamie Madill0fdb9562018-09-17 17:18:43 -04003201 void SetUp() override
3202 {
3203 ANGLETest::SetUp();
3204
3205 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
3206 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
3207 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
3208
3209 ASSERT_GL_NO_ERROR();
3210 }
3211
3212 void TearDown() override
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003213 {
3214 if (mProgram != 0)
3215 {
3216 glDeleteProgram(mProgram);
3217 mProgram = 0;
3218
3219 if (!mTextures.empty())
3220 {
3221 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
3222 }
3223 }
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003224
Jamie Madill0fdb9562018-09-17 17:18:43 -04003225 ANGLETest::TearDown();
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003226 }
3227
3228 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
3229 GLint vertexTextureCount,
3230 GLint vertexActiveTextureCount,
3231 const std::string &fragPrefix,
3232 GLint fragmentTextureCount,
3233 GLint fragmentActiveTextureCount)
3234 {
3235 std::stringstream vertexShaderStr;
3236 vertexShaderStr << "attribute vec2 position;\n"
3237 << "varying vec4 color;\n"
3238 << "varying vec2 texCoord;\n";
3239
3240 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
3241 {
3242 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
3243 }
3244
3245 vertexShaderStr << "void main() {\n"
3246 << " gl_Position = vec4(position, 0, 1);\n"
3247 << " texCoord = (position * 0.5) + 0.5;\n"
3248 << " color = vec4(0);\n";
3249
3250 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
3251 {
3252 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
3253 << ", texCoord);\n";
3254 }
3255
3256 vertexShaderStr << "}";
3257
3258 std::stringstream fragmentShaderStr;
3259 fragmentShaderStr << "varying mediump vec4 color;\n"
3260 << "varying mediump vec2 texCoord;\n";
3261
3262 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
3263 {
3264 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
3265 }
3266
3267 fragmentShaderStr << "void main() {\n"
3268 << " gl_FragColor = color;\n";
3269
3270 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
3271 {
3272 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
3273 << ", texCoord);\n";
3274 }
3275
3276 fragmentShaderStr << "}";
3277
3278 const std::string &vertexShaderSource = vertexShaderStr.str();
3279 const std::string &fragmentShaderSource = fragmentShaderStr.str();
3280
Jamie Madill35cd7332018-12-02 12:03:33 -05003281 mProgram = CompileProgram(vertexShaderSource.c_str(), fragmentShaderSource.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003282 }
3283
3284 RGBA8 getPixel(GLint texIndex)
3285 {
3286 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3287 0, 255u};
3288 return pixel;
3289 }
3290
3291 void initTextures(GLint tex2DCount, GLint texCubeCount)
3292 {
3293 GLint totalCount = tex2DCount + texCubeCount;
3294 mTextures.assign(totalCount, 0);
3295 glGenTextures(totalCount, &mTextures[0]);
3296 ASSERT_GL_NO_ERROR();
3297
3298 std::vector<RGBA8> texData(16 * 16);
3299
3300 GLint texIndex = 0;
3301 for (; texIndex < tex2DCount; ++texIndex)
3302 {
3303 texData.assign(texData.size(), getPixel(texIndex));
3304 glActiveTexture(GL_TEXTURE0 + texIndex);
3305 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3306 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3307 &texData[0]);
3308 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3309 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3310 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3311 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3312 }
3313
3314 ASSERT_GL_NO_ERROR();
3315
3316 for (; texIndex < texCubeCount; ++texIndex)
3317 {
3318 texData.assign(texData.size(), getPixel(texIndex));
3319 glActiveTexture(GL_TEXTURE0 + texIndex);
3320 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3321 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3322 GL_UNSIGNED_BYTE, &texData[0]);
3323 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3324 GL_UNSIGNED_BYTE, &texData[0]);
3325 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3326 GL_UNSIGNED_BYTE, &texData[0]);
3327 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3328 GL_UNSIGNED_BYTE, &texData[0]);
3329 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3330 GL_UNSIGNED_BYTE, &texData[0]);
3331 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3332 GL_UNSIGNED_BYTE, &texData[0]);
3333 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3334 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3335 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3336 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3337 }
3338
3339 ASSERT_GL_NO_ERROR();
3340 }
3341
3342 void testWithTextures(GLint vertexTextureCount,
3343 const std::string &vertexTexturePrefix,
3344 GLint fragmentTextureCount,
3345 const std::string &fragmentTexturePrefix)
3346 {
3347 // Generate textures
3348 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3349
3350 glUseProgram(mProgram);
3351 RGBA8 expectedSum = {0};
3352 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3353 {
3354 std::stringstream uniformNameStr;
3355 uniformNameStr << vertexTexturePrefix << texIndex;
3356 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003357 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003358 ASSERT_NE(-1, location);
3359
3360 glUniform1i(location, texIndex);
3361 RGBA8 contribution = getPixel(texIndex);
3362 expectedSum.R += contribution.R;
3363 expectedSum.G += contribution.G;
3364 }
3365
3366 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3367 {
3368 std::stringstream uniformNameStr;
3369 uniformNameStr << fragmentTexturePrefix << texIndex;
3370 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003371 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003372 ASSERT_NE(-1, location);
3373
3374 glUniform1i(location, texIndex + vertexTextureCount);
3375 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3376 expectedSum.R += contribution.R;
3377 expectedSum.G += contribution.G;
3378 }
3379
3380 ASSERT_GE(256u, expectedSum.G);
3381
3382 drawQuad(mProgram, "position", 0.5f);
3383 ASSERT_GL_NO_ERROR();
3384 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3385 }
3386
3387 GLuint mProgram;
3388 std::vector<GLuint> mTextures;
3389 GLint mMaxVertexTextures;
3390 GLint mMaxFragmentTextures;
3391 GLint mMaxCombinedTextures;
3392};
3393
3394// Test rendering with the maximum vertex texture units.
3395TEST_P(TextureLimitsTest, MaxVertexTextures)
3396{
3397 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3398 ASSERT_NE(0u, mProgram);
3399 ASSERT_GL_NO_ERROR();
3400
3401 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3402}
3403
3404// Test rendering with the maximum fragment texture units.
3405TEST_P(TextureLimitsTest, MaxFragmentTextures)
3406{
3407 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3408 ASSERT_NE(0u, mProgram);
3409 ASSERT_GL_NO_ERROR();
3410
3411 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3412}
3413
3414// Test rendering with maximum combined texture units.
3415TEST_P(TextureLimitsTest, MaxCombinedTextures)
3416{
3417 GLint vertexTextures = mMaxVertexTextures;
3418
3419 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3420 {
3421 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3422 }
3423
3424 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3425 mMaxFragmentTextures, mMaxFragmentTextures);
3426 ASSERT_NE(0u, mProgram);
3427 ASSERT_GL_NO_ERROR();
3428
3429 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3430}
3431
3432// Negative test for exceeding the number of vertex textures
3433TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3434{
3435 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3436 0);
3437 ASSERT_EQ(0u, mProgram);
3438}
3439
3440// Negative test for exceeding the number of fragment textures
3441TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3442{
3443 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3444 mMaxFragmentTextures + 1);
3445 ASSERT_EQ(0u, mProgram);
3446}
3447
3448// Test active vertex textures under the limit, but excessive textures specified.
3449TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3450{
3451 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3452 ASSERT_NE(0u, mProgram);
3453 ASSERT_GL_NO_ERROR();
3454
3455 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3456}
3457
3458// Test active fragment textures under the limit, but excessive textures specified.
3459TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3460{
3461 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3462 mMaxFragmentTextures);
3463 ASSERT_NE(0u, mProgram);
3464 ASSERT_GL_NO_ERROR();
3465
3466 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3467}
3468
3469// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003470// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003471TEST_P(TextureLimitsTest, TextureTypeConflict)
3472{
Jamie Madill35cd7332018-12-02 12:03:33 -05003473 constexpr char kVS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003474 "attribute vec2 position;\n"
3475 "varying float color;\n"
3476 "uniform sampler2D tex2D;\n"
3477 "uniform samplerCube texCube;\n"
3478 "void main() {\n"
3479 " gl_Position = vec4(position, 0, 1);\n"
3480 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3481 " color = texture2D(tex2D, texCoord).x;\n"
3482 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3483 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05003484 constexpr char kFS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003485 "varying mediump float color;\n"
3486 "void main() {\n"
3487 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3488 "}";
3489
Jamie Madill35cd7332018-12-02 12:03:33 -05003490 mProgram = CompileProgram(kVS, kFS);
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003491 ASSERT_NE(0u, mProgram);
3492
3493 initTextures(1, 0);
3494
3495 glUseProgram(mProgram);
3496 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3497 ASSERT_NE(-1, tex2DLocation);
3498 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3499 ASSERT_NE(-1, texCubeLocation);
3500
3501 glUniform1i(tex2DLocation, 0);
3502 glUniform1i(texCubeLocation, 0);
3503 ASSERT_GL_NO_ERROR();
3504
3505 drawQuad(mProgram, "position", 0.5f);
3506 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3507}
3508
Vincent Lang25ab4512016-05-13 18:13:59 +02003509class Texture2DNorm16TestES3 : public Texture2DTestES3
3510{
3511 protected:
3512 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3513
3514 void SetUp() override
3515 {
3516 Texture2DTestES3::SetUp();
3517
3518 glActiveTexture(GL_TEXTURE0);
3519 glGenTextures(3, mTextures);
3520 glGenFramebuffers(1, &mFBO);
3521 glGenRenderbuffers(1, &mRenderbuffer);
3522
3523 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3524 {
3525 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3526 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3527 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3528 }
3529
3530 glBindTexture(GL_TEXTURE_2D, 0);
3531
3532 ASSERT_GL_NO_ERROR();
3533 }
3534
3535 void TearDown() override
3536 {
3537 glDeleteTextures(3, mTextures);
3538 glDeleteFramebuffers(1, &mFBO);
3539 glDeleteRenderbuffers(1, &mRenderbuffer);
3540
3541 Texture2DTestES3::TearDown();
3542 }
3543
3544 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3545 {
Geoff Langf607c602016-09-21 11:46:48 -04003546 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3547 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003548
3549 setUpProgram();
3550
3551 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3552 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3553 0);
3554
3555 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3556 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3557
3558 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003559 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003560
3561 EXPECT_GL_NO_ERROR();
3562
3563 drawQuad(mProgram, "position", 0.5f);
3564
Geoff Langf607c602016-09-21 11:46:48 -04003565 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003566
Jamie Madill50cf2be2018-06-15 09:46:57 -04003567 EXPECT_PIXEL_COLOR_EQ(0, 0,
3568 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3569 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003570
3571 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3572
3573 ASSERT_GL_NO_ERROR();
3574 }
3575
3576 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3577 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04003578 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003579 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003580
3581 setUpProgram();
3582
3583 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3584 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3585
3586 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3587 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3588 0);
3589
3590 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003591 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003592
3593 EXPECT_GL_NO_ERROR();
3594
3595 drawQuad(mProgram, "position", 0.5f);
3596
Geoff Langf607c602016-09-21 11:46:48 -04003597 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
Jamie Madill50cf2be2018-06-15 09:46:57 -04003598 EXPECT_PIXEL_COLOR_EQ(0, 0,
3599 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3600 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003601
3602 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3603 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3604 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3605 mRenderbuffer);
3606 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3607 EXPECT_GL_NO_ERROR();
3608
3609 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3610 glClear(GL_COLOR_BUFFER_BIT);
3611
3612 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3613
Geoff Langf607c602016-09-21 11:46:48 -04003614 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003615
3616 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3617
3618 ASSERT_GL_NO_ERROR();
3619 }
3620
3621 GLuint mTextures[3];
3622 GLuint mFBO;
3623 GLuint mRenderbuffer;
3624};
3625
3626// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3627TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3628{
Yunchao He9550c602018-02-13 14:47:05 +08003629 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02003630
3631 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3632 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3633 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3634 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3635 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3636 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3637 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3638 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3639
3640 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3641 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3642 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3643}
3644
Olli Etuaho95faa232016-06-07 14:01:53 -07003645// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3646// GLES 3.0.4 section 3.8.3.
3647TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3648{
Yuly Novikov3c754192016-06-27 19:36:41 -04003649 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1429 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08003650 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07003651
3652 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3653 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3654 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3655 ASSERT_GL_NO_ERROR();
3656
3657 // SKIP_IMAGES should not have an effect on uploading 2D textures
3658 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3659 ASSERT_GL_NO_ERROR();
3660
3661 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3662
3663 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3664 pixelsGreen.data());
3665 ASSERT_GL_NO_ERROR();
3666
3667 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3668 pixelsGreen.data());
3669 ASSERT_GL_NO_ERROR();
3670
3671 glUseProgram(mProgram);
3672 drawQuad(mProgram, "position", 0.5f);
3673 ASSERT_GL_NO_ERROR();
3674
3675 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3676}
3677
Olli Etuaho989cac32016-06-08 16:18:49 -07003678// Test that skip defined in unpack parameters is taken into account when determining whether
3679// unpacking source extends outside unpack buffer bounds.
3680TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3681{
3682 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3683 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3684 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3685 ASSERT_GL_NO_ERROR();
3686
3687 GLBuffer buf;
3688 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3689 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3690 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3691 GL_DYNAMIC_COPY);
3692 ASSERT_GL_NO_ERROR();
3693
3694 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3695 ASSERT_GL_NO_ERROR();
3696
3697 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3698 ASSERT_GL_NO_ERROR();
3699
3700 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3701 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3702
3703 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3704 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3705 ASSERT_GL_NO_ERROR();
3706
3707 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3708 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3709}
3710
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003711// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3712TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3713{
Yunchao He9550c602018-02-13 14:47:05 +08003714 ANGLE_SKIP_TEST_IF(IsD3D11());
3715
3716 // Incorrect rendering results seen on OSX AMD.
3717 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003718
3719 const GLuint width = 8u;
3720 const GLuint height = 8u;
3721 const GLuint unpackRowLength = 5u;
3722 const GLuint unpackSkipPixels = 1u;
3723
3724 setWindowWidth(width);
3725 setWindowHeight(height);
3726
3727 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3728 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3729 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3730 ASSERT_GL_NO_ERROR();
3731
3732 GLBuffer buf;
3733 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3734 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3735 GLColor::green);
3736
3737 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3738 {
3739 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3740 }
3741
3742 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3743 GL_DYNAMIC_COPY);
3744 ASSERT_GL_NO_ERROR();
3745
3746 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3747 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3748 ASSERT_GL_NO_ERROR();
3749
3750 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3751 ASSERT_GL_NO_ERROR();
3752
3753 glUseProgram(mProgram);
3754 drawQuad(mProgram, "position", 0.5f);
3755 ASSERT_GL_NO_ERROR();
3756
3757 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3758 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3759 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3760 actual.data());
3761 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3762 EXPECT_EQ(expected, actual);
3763}
3764
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003765template <typename T>
3766T UNorm(double value)
3767{
3768 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3769}
3770
3771// Test rendering a depth texture with mipmaps.
3772TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3773{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003774 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3775 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
Jiawei Shaoaf0f31d2018-09-27 15:42:31 +08003776 // http://anglebug.com/1706
3777 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Corentin Walleze731d8a2016-09-07 10:56:25 -04003778
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003779 const int size = getWindowWidth();
3780
3781 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003782 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003783
3784 glActiveTexture(GL_TEXTURE0);
3785 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3786 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3787 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3788 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3789 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3790 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3791 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3792 ASSERT_GL_NO_ERROR();
3793
3794 glUseProgram(mProgram);
3795 glUniform1i(mTexture2DUniformLocation, 0);
3796
3797 std::vector<unsigned char> expected;
3798
3799 for (int level = 0; level < levels; ++level)
3800 {
3801 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3802 expected.push_back(UNorm<unsigned char>(value));
3803
3804 int levelDim = dim(level);
3805
3806 ASSERT_GT(levelDim, 0);
3807
3808 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3809 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3810 GL_UNSIGNED_INT, initData.data());
3811 }
3812 ASSERT_GL_NO_ERROR();
3813
3814 for (int level = 0; level < levels; ++level)
3815 {
3816 glViewport(0, 0, dim(level), dim(level));
3817 drawQuad(mProgram, "position", 0.5f);
3818 GLColor actual = ReadColor(0, 0);
3819 EXPECT_NEAR(expected[level], actual.R, 10u);
3820 }
3821
3822 ASSERT_GL_NO_ERROR();
3823}
3824
Jamie Madill7ffdda92016-09-08 13:26:51 -04003825// Tests unpacking into the unsized GL_ALPHA format.
3826TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3827{
Jamie Madill7ffdda92016-09-08 13:26:51 -04003828 // Initialize the texure.
3829 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3830 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3831 GL_UNSIGNED_BYTE, nullptr);
3832 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3833 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3834
3835 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3836
3837 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04003838 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04003839 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3840 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3841 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
3842 GL_STATIC_DRAW);
3843
3844 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
3845 GL_UNSIGNED_BYTE, nullptr);
3846
3847 // Clear to a weird color to make sure we're drawing something.
3848 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
3849 glClear(GL_COLOR_BUFFER_BIT);
3850
3851 // Draw with the alpha texture and verify.
3852 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04003853
3854 ASSERT_GL_NO_ERROR();
3855 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
3856}
3857
Jamie Madill2e600342016-09-19 13:56:40 -04003858// Ensure stale unpack data doesn't propagate in D3D11.
3859TEST_P(Texture2DTestES3, StaleUnpackData)
3860{
3861 // Init unpack buffer.
3862 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
3863 std::vector<GLColor> pixels(pixelCount, GLColor::red);
3864
3865 GLBuffer unpackBuffer;
3866 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3867 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3868 GLsizei bufferSize = pixelCount * sizeof(GLColor);
3869 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
3870
3871 // Create from unpack buffer.
3872 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3873 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
3874 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3875 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3876 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3877
3878 drawQuad(mProgram, "position", 0.5f);
3879
3880 ASSERT_GL_NO_ERROR();
3881 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3882
3883 // Fill unpack with green, recreating buffer.
3884 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
3885 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
3886 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
3887
3888 // Reinit texture with green.
3889 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
3890 GL_UNSIGNED_BYTE, nullptr);
3891
3892 drawQuad(mProgram, "position", 0.5f);
3893
3894 ASSERT_GL_NO_ERROR();
3895 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3896}
3897
Geoff Langfb7685f2017-11-13 11:44:11 -05003898// Ensure that texture parameters passed as floats that are converted to ints are rounded before
3899// validating they are less than 0.
3900TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
3901{
3902 GLTexture texture;
3903 glBindTexture(GL_TEXTURE_2D, texture);
3904
3905 // Use a negative number that will round to zero when converted to an integer
3906 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
3907 // "Validation of values performed by state-setting commands is performed after conversion,
3908 // unless specified otherwise for a specific command."
3909 GLfloat param = -7.30157126e-07f;
3910 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
3911 EXPECT_GL_NO_ERROR();
3912
3913 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
3914 EXPECT_GL_NO_ERROR();
3915}
3916
Jamie Madillf097e232016-11-05 00:44:15 -04003917// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
3918// being properly checked, and the texture storage of the previous texture format was persisting.
3919// This would result in an ASSERT in debug and incorrect rendering in release.
3920// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
3921TEST_P(Texture3DTestES3, FormatRedefinitionBug)
3922{
3923 GLTexture tex;
3924 glBindTexture(GL_TEXTURE_3D, tex.get());
3925 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3926
3927 GLFramebuffer framebuffer;
3928 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3929 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
3930
3931 glCheckFramebufferStatus(GL_FRAMEBUFFER);
3932
3933 std::vector<uint8_t> pixelData(100, 0);
3934
3935 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
3936 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
3937 pixelData.data());
3938
3939 ASSERT_GL_NO_ERROR();
3940}
3941
Corentin Wallezd2627992017-04-28 17:17:03 -04003942// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
3943TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
3944{
3945 // 2D tests
3946 {
3947 GLTexture tex;
3948 glBindTexture(GL_TEXTURE_2D, tex.get());
3949
3950 GLBuffer pbo;
3951 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3952
3953 // Test OOB
3954 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
3955 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3956 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3957
3958 // Test OOB
3959 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
3960 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3961 ASSERT_GL_NO_ERROR();
3962 }
3963
3964 // 3D tests
3965 {
3966 GLTexture tex;
3967 glBindTexture(GL_TEXTURE_3D, tex.get());
3968
3969 GLBuffer pbo;
3970 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3971
3972 // Test OOB
3973 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
3974 GL_STATIC_DRAW);
3975 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3976 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3977
3978 // Test OOB
3979 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
3980 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3981 ASSERT_GL_NO_ERROR();
3982 }
3983}
3984
Jamie Madill3ed60422017-09-07 11:32:52 -04003985// Tests behaviour with a single texture and multiple sampler objects.
3986TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
3987{
3988 GLint maxTextureUnits = 0;
3989 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
3990 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
3991
3992 constexpr int kSize = 16;
3993
3994 // Make a single-level texture, fill it with red.
3995 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
3996 GLTexture tex;
3997 glBindTexture(GL_TEXTURE_2D, tex);
3998 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3999 redColors.data());
4000 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4001 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4002
4003 // Simple sanity check.
4004 draw2DTexturedQuad(0.5f, 1.0f, true);
4005 ASSERT_GL_NO_ERROR();
4006 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4007
4008 // Bind texture to unit 1 with a sampler object making it incomplete.
4009 GLSampler sampler;
4010 glBindSampler(0, sampler);
4011 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4012 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4013
4014 // Make a mipmap texture, fill it with blue.
4015 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
4016 GLTexture mipmapTex;
4017 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4018 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4019 blueColors.data());
4020 glGenerateMipmap(GL_TEXTURE_2D);
4021
4022 // Draw with the sampler, expect blue.
4023 draw2DTexturedQuad(0.5f, 1.0f, true);
4024 ASSERT_GL_NO_ERROR();
4025 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
4026
4027 // Simple multitexturing program.
Jamie Madill35cd7332018-12-02 12:03:33 -05004028 constexpr char kVS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004029 "#version 300 es\n"
4030 "in vec2 position;\n"
4031 "out vec2 texCoord;\n"
4032 "void main()\n"
4033 "{\n"
4034 " gl_Position = vec4(position, 0, 1);\n"
4035 " texCoord = position * 0.5 + vec2(0.5);\n"
4036 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05004037
4038 constexpr char kFS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004039 "#version 300 es\n"
4040 "precision mediump float;\n"
4041 "in vec2 texCoord;\n"
4042 "uniform sampler2D tex1;\n"
4043 "uniform sampler2D tex2;\n"
4044 "uniform sampler2D tex3;\n"
4045 "uniform sampler2D tex4;\n"
4046 "out vec4 color;\n"
4047 "void main()\n"
4048 "{\n"
4049 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
4050 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
4051 "}";
4052
Jamie Madill35cd7332018-12-02 12:03:33 -05004053 ANGLE_GL_PROGRAM(program, kVS, kFS);
Jamie Madill3ed60422017-09-07 11:32:52 -04004054
4055 std::array<GLint, 4> texLocations = {
4056 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
4057 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
4058 for (GLint location : texLocations)
4059 {
4060 ASSERT_NE(-1, location);
4061 }
4062
4063 // Init the uniform data.
4064 glUseProgram(program);
4065 for (GLint location = 0; location < 4; ++location)
4066 {
4067 glUniform1i(texLocations[location], location);
4068 }
4069
4070 // Initialize four samplers
4071 GLSampler samplers[4];
4072
4073 // 0: non-mipped.
4074 glBindSampler(0, samplers[0]);
4075 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4076 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4077
4078 // 1: mipped.
4079 glBindSampler(1, samplers[1]);
4080 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4081 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4082
4083 // 2: non-mipped.
4084 glBindSampler(2, samplers[2]);
4085 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4086 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4087
4088 // 3: mipped.
4089 glBindSampler(3, samplers[3]);
4090 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4091 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4092
4093 // Bind two blue mipped textures and two single layer textures, should all draw.
4094 glActiveTexture(GL_TEXTURE0);
4095 glBindTexture(GL_TEXTURE_2D, tex);
4096
4097 glActiveTexture(GL_TEXTURE1);
4098 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4099
4100 glActiveTexture(GL_TEXTURE2);
4101 glBindTexture(GL_TEXTURE_2D, tex);
4102
4103 glActiveTexture(GL_TEXTURE3);
4104 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4105
4106 ASSERT_GL_NO_ERROR();
4107
4108 drawQuad(program, "position", 0.5f);
4109 ASSERT_GL_NO_ERROR();
4110 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
4111
4112 // Bind four single layer textures, two should be incomplete.
4113 glActiveTexture(GL_TEXTURE1);
4114 glBindTexture(GL_TEXTURE_2D, tex);
4115
4116 glActiveTexture(GL_TEXTURE3);
4117 glBindTexture(GL_TEXTURE_2D, tex);
4118
4119 drawQuad(program, "position", 0.5f);
4120 ASSERT_GL_NO_ERROR();
4121 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
4122}
4123
Martin Radev7e2c0d32017-09-15 14:25:42 +03004124// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
4125// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
4126// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
4127// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
4128// samples the cubemap using a direction vector (1,1,1).
4129TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
4130{
Yunchao He2f23f352018-02-11 22:11:37 +08004131 // Check http://anglebug.com/2155.
4132 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
4133
Jamie Madill35cd7332018-12-02 12:03:33 -05004134 constexpr char kVS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004135 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004136 precision mediump float;
4137 in vec3 pos;
4138 void main() {
4139 gl_Position = vec4(pos, 1.0);
4140 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03004141
Jamie Madill35cd7332018-12-02 12:03:33 -05004142 constexpr char kFS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004143 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004144 precision mediump float;
4145 out vec4 color;
4146 uniform samplerCube uTex;
4147 void main(){
4148 color = texture(uTex, vec3(1.0));
4149 })";
Jamie Madill35cd7332018-12-02 12:03:33 -05004150
4151 ANGLE_GL_PROGRAM(program, kVS, kFS);
Martin Radev7e2c0d32017-09-15 14:25:42 +03004152 glUseProgram(program);
4153
4154 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
4155 glActiveTexture(GL_TEXTURE0);
4156
4157 GLTexture cubeTex;
4158 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
4159
4160 const int kFaceWidth = 1;
4161 const int kFaceHeight = 1;
4162 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
4163 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4164 GL_UNSIGNED_BYTE, texData.data());
4165 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4166 GL_UNSIGNED_BYTE, texData.data());
4167 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4168 GL_UNSIGNED_BYTE, texData.data());
4169 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4170 GL_UNSIGNED_BYTE, texData.data());
4171 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4172 GL_UNSIGNED_BYTE, texData.data());
4173 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4174 GL_UNSIGNED_BYTE, texData.data());
4175 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4176 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4177 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
4178 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
4179 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
4180 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
4181
4182 drawQuad(program, "pos", 0.5f, 1.0f, true);
4183 ASSERT_GL_NO_ERROR();
4184
4185 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4186}
4187
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08004188// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
4189TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
4190{
4191 GLuint texture = create2DTexture();
4192
4193 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
4194 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4195
4196 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
4197 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4198
4199 glDeleteTextures(1, &texture);
4200 EXPECT_GL_NO_ERROR();
4201}
4202
Olli Etuaho023371b2018-04-24 17:43:32 +03004203// Test setting base level after calling generateMipmap on a LUMA texture.
4204// Covers http://anglebug.com/2498
4205TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA)
4206{
4207 glActiveTexture(GL_TEXTURE0);
4208 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4209
4210 constexpr const GLsizei kWidth = 8;
4211 constexpr const GLsizei kHeight = 8;
4212 std::array<GLubyte, kWidth * kHeight * 2> whiteData;
4213 whiteData.fill(255u);
4214
4215 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA,
4216 GL_UNSIGNED_BYTE, whiteData.data());
4217 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
4218 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4219 glGenerateMipmap(GL_TEXTURE_2D);
4220 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
4221 EXPECT_GL_NO_ERROR();
4222
4223 drawQuad(mProgram, "position", 0.5f);
4224 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4225}
4226
Till Rathmannc1551dc2018-08-15 17:04:49 +02004227// Covers a bug in the D3D11 backend: http://anglebug.com/2772
4228// When using a sampler the texture was created as if it has mipmaps,
4229// regardless what you specified in GL_TEXTURE_MIN_FILTER via
4230// glSamplerParameteri() -- mistakenly the default value
4231// GL_NEAREST_MIPMAP_LINEAR or the value set via glTexParameteri() was
4232// evaluated.
4233// If you didn't provide mipmaps and didn't let the driver generate them
4234// this led to not sampling your texture data when minification occurred.
4235TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping)
4236{
Jamie Madill35cd7332018-12-02 12:03:33 -05004237 constexpr char kVS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004238 "#version 300 es\n"
4239 "out vec2 texcoord;\n"
4240 "in vec4 position;\n"
4241 "void main()\n"
4242 "{\n"
4243 " gl_Position = vec4(position.xy * 0.1, 0.0, 1.0);\n"
4244 " texcoord = (position.xy * 0.5) + 0.5;\n"
4245 "}\n";
4246
Jamie Madill35cd7332018-12-02 12:03:33 -05004247 constexpr char kFS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004248 "#version 300 es\n"
4249 "precision highp float;\n"
4250 "uniform highp sampler2D tex;\n"
4251 "in vec2 texcoord;\n"
4252 "out vec4 fragColor;\n"
4253 "void main()\n"
4254 "{\n"
4255 " fragColor = texture(tex, texcoord);\n"
4256 "}\n";
Jamie Madill35cd7332018-12-02 12:03:33 -05004257
4258 ANGLE_GL_PROGRAM(program, kVS, kFS);
Till Rathmannc1551dc2018-08-15 17:04:49 +02004259
4260 GLSampler sampler;
4261 glBindSampler(0, sampler);
4262 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4263 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4264
4265 glActiveTexture(GL_TEXTURE0);
4266 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4267
4268 const GLsizei texWidth = getWindowWidth();
4269 const GLsizei texHeight = getWindowHeight();
4270 const std::vector<GLColor> whiteData(texWidth * texHeight, GLColor::white);
4271
4272 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4273 whiteData.data());
4274 EXPECT_GL_NO_ERROR();
4275
4276 drawQuad(program, "position", 0.5f);
4277 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, angle::GLColor::white);
4278}
4279
Jamie Madill50cf2be2018-06-15 09:46:57 -04004280// Use this to select which configurations (e.g. which renderer, which GLES major version) these
4281// tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -05004282ANGLE_INSTANTIATE_TEST(Texture2DTest,
4283 ES2_D3D9(),
4284 ES2_D3D11(),
4285 ES2_D3D11_FL9_3(),
4286 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05004287 ES2_OPENGLES(),
4288 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004289ANGLE_INSTANTIATE_TEST(TextureCubeTest,
4290 ES2_D3D9(),
4291 ES2_D3D11(),
Geoff Langf7480ad2017-10-24 11:46:02 -04004292 ES2_D3D11_FL10_0(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004293 ES2_D3D11_FL9_3(),
4294 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004295 ES2_OPENGLES(),
4296 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004297ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
4298 ES2_D3D9(),
4299 ES2_D3D11(),
4300 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004301 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004302 ES2_OPENGLES(),
4303 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004304ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
4305 ES2_D3D9(),
4306 ES2_D3D11(),
4307 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004308 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004309 ES2_OPENGLES(),
4310 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004311ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
4312 ES2_D3D9(),
4313 ES2_D3D11(),
4314 ES2_D3D11_FL9_3(),
4315 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004316 ES2_OPENGLES(),
4317 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004318ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
4319 ES2_D3D9(),
4320 ES2_D3D11(),
4321 ES2_D3D11_FL9_3(),
4322 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004323 ES2_OPENGLES(),
4324 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004325ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02004326ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02004327ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4328ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
4329 ES3_D3D11(),
4330 ES3_OPENGL(),
4331 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004332ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
4333 ES3_D3D11(),
4334 ES3_OPENGL(),
4335 ES3_OPENGLES());
4336ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4337ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02004338ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02004339ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
4340 ES2_D3D11(),
4341 ES2_D3D11_FL9_3(),
4342 ES2_D3D9(),
4343 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004344 ES2_OPENGLES(),
4345 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004346ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
4347 ES2_D3D11(),
4348 ES2_D3D11_FL9_3(),
4349 ES2_D3D9(),
4350 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004351 ES2_OPENGLES(),
4352 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004353ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
4354 ES2_D3D11(),
4355 ES2_D3D11_FL9_3(),
4356 ES2_D3D9(),
4357 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004358 ES2_OPENGLES(),
4359 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004360ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
4361 ES2_D3D11(),
4362 ES2_D3D11_FL9_3(),
4363 ES2_D3D9(),
4364 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004365 ES2_OPENGLES(),
4366 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004367ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
4368 ES2_D3D11(),
4369 ES2_D3D11_FL9_3(),
4370 ES2_D3D9(),
4371 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004372 ES2_OPENGLES(),
4373 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02004374ANGLE_INSTANTIATE_TEST(TextureBorderClampTest,
4375 ES2_D3D11(),
4376 ES2_D3D9(),
4377 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004378 ES2_OPENGLES(),
4379 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02004380ANGLE_INSTANTIATE_TEST(TextureBorderClampTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4381ANGLE_INSTANTIATE_TEST(TextureBorderClampIntegerTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Luc Ferronaf883622018-06-08 15:57:31 -04004382ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN());
Vincent Lang25ab4512016-05-13 18:13:59 +02004383ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03004384ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04004385
Jamie Madill7ffdda92016-09-08 13:26:51 -04004386} // anonymous namespace