blob: 587d02d13e92113118d35dfb72042a186728b6ed [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
Mohan Maiya6caa2652019-09-11 08:06:13 -070016constexpr GLuint kPixelTolerance = 1u;
17constexpr GLfloat kPixelTolerance32F = 0.01f;
Mohan Maiya8f1169e2019-06-27 15:32:32 -070018
Vincent Lang25ab4512016-05-13 18:13:59 +020019// Take a pixel, and reset the components not covered by the format to default
Geoff Langf607c602016-09-21 11:46:48 -040020// values. In particular, the default value for the alpha component is 255
Vincent Lang25ab4512016-05-13 18:13:59 +020021// (1.0 as unsigned normalized fixed point value).
Mohan Maiya6caa2652019-09-11 08:06:13 -070022// For legacy formats, the components may be reordered to match the color that
23// would be created if a pixel of that format was initialized from the given color
Geoff Langf607c602016-09-21 11:46:48 -040024GLColor SliceFormatColor(GLenum format, GLColor full)
Vincent Lang25ab4512016-05-13 18:13:59 +020025{
26 switch (format)
27 {
28 case GL_RED:
Geoff Langf607c602016-09-21 11:46:48 -040029 return GLColor(full.R, 0, 0, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020030 case GL_RG:
Geoff Langf607c602016-09-21 11:46:48 -040031 return GLColor(full.R, full.G, 0, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020032 case GL_RGB:
Geoff Langf607c602016-09-21 11:46:48 -040033 return GLColor(full.R, full.G, full.B, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020034 case GL_RGBA:
35 return full;
Mohan Maiya6caa2652019-09-11 08:06:13 -070036 case GL_LUMINANCE:
37 return GLColor(full.R, full.R, full.R, 255u);
38 case GL_ALPHA:
39 return GLColor(0, 0, 0, full.R);
40 case GL_LUMINANCE_ALPHA:
41 return GLColor(full.R, full.R, full.R, full.G);
Vincent Lang25ab4512016-05-13 18:13:59 +020042 default:
Jamie Madille1faacb2016-12-13 12:42:14 -050043 EXPECT_TRUE(false);
Geoff Langf607c602016-09-21 11:46:48 -040044 return GLColor::white;
Vincent Lang25ab4512016-05-13 18:13:59 +020045 }
Vincent Lang25ab4512016-05-13 18:13:59 +020046}
47
Mohan Maiya6caa2652019-09-11 08:06:13 -070048// As above, for 32F colors
49GLColor32F SliceFormatColor32F(GLenum format, GLColor32F full)
50{
51 switch (format)
52 {
53 case GL_RED:
54 return GLColor32F(full.R, 0.0f, 0.0f, 1.0f);
55 case GL_RG:
56 return GLColor32F(full.R, full.G, 0.0f, 1.0f);
57 case GL_RGB:
58 return GLColor32F(full.R, full.G, full.B, 1.0f);
59 case GL_RGBA:
60 return full;
61 case GL_LUMINANCE:
62 return GLColor32F(full.R, full.R, full.R, 1.0f);
63 case GL_ALPHA:
64 return GLColor32F(0.0f, 0.0f, 0.0f, full.R);
65 case GL_LUMINANCE_ALPHA:
66 return GLColor32F(full.R, full.R, full.R, full.G);
67 default:
68 EXPECT_TRUE(false);
69 return GLColor32F(1.0f, 1.0f, 1.0f, 1.0f);
70 }
71}
72
Olli Etuaho4a8329f2016-01-11 17:12:57 +020073class TexCoordDrawTest : public ANGLETest
Jamie Madillf67115c2014-04-22 13:14:05 -040074{
Jamie Madillbc393df2015-01-29 13:46:07 -050075 protected:
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020076 TexCoordDrawTest() : ANGLETest(), mProgram(0), mFramebuffer(0), mFramebufferColorTexture(0)
Jamie Madillf67115c2014-04-22 13:14:05 -040077 {
78 setWindowWidth(128);
79 setWindowHeight(128);
80 setConfigRedBits(8);
81 setConfigGreenBits(8);
82 setConfigBlueBits(8);
83 setConfigAlphaBits(8);
84 }
85
Jamie Madill35cd7332018-12-02 12:03:33 -050086 virtual const char *getVertexShaderSource()
Jamie Madillf67115c2014-04-22 13:14:05 -040087 {
Jamie Madill35cd7332018-12-02 12:03:33 -050088 return R"(precision highp float;
89attribute vec4 position;
90varying vec2 texcoord;
Geoff Langc41e42d2014-04-28 10:58:16 -040091
Jamie Madill35cd7332018-12-02 12:03:33 -050092void main()
93{
94 gl_Position = vec4(position.xy, 0.0, 1.0);
95 texcoord = (position.xy * 0.5) + 0.5;
96})";
Olli Etuaho4a8329f2016-01-11 17:12:57 +020097 }
Geoff Langc41e42d2014-04-28 10:58:16 -040098
Jamie Madill35cd7332018-12-02 12:03:33 -050099 virtual const char *getFragmentShaderSource() = 0;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200100
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300101 virtual void setUpProgram()
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200102 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500103 const char *vertexShaderSource = getVertexShaderSource();
104 const char *fragmentShaderSource = getFragmentShaderSource();
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200105
106 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
107 ASSERT_NE(0u, mProgram);
108 ASSERT_GL_NO_ERROR();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300109 }
110
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400111 void testSetUp() override { setUpFramebuffer(); }
Olli Etuaho51f1c0f2016-01-13 16:16:24 +0200112
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400113 void testTearDown() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200114 {
Olli Etuaho51f1c0f2016-01-13 16:16:24 +0200115 glBindFramebuffer(GL_FRAMEBUFFER, 0);
116 glDeleteFramebuffers(1, &mFramebuffer);
117 glDeleteTextures(1, &mFramebufferColorTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200118 glDeleteProgram(mProgram);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200119 }
120
Olli Etuaho51f1c0f2016-01-13 16:16:24 +0200121 void setUpFramebuffer()
122 {
123 // We use an FBO to work around an issue where the default framebuffer applies SRGB
124 // conversion (particularly known to happen incorrectly on Intel GL drivers). It's not
125 // clear whether this issue can even be fixed on all backends. For example GLES 3.0.4 spec
126 // section 4.4 says that the format of the default framebuffer is entirely up to the window
127 // system, so it might be SRGB, and GLES 3.0 doesn't have a "FRAMEBUFFER_SRGB" to turn off
128 // SRGB conversion like desktop GL does.
129 // TODO(oetuaho): Get rid of this if the underlying issue is fixed.
130 glGenFramebuffers(1, &mFramebuffer);
131 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
132
133 glGenTextures(1, &mFramebufferColorTexture);
134 glBindTexture(GL_TEXTURE_2D, mFramebufferColorTexture);
135 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
136 GL_UNSIGNED_BYTE, nullptr);
137 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
138 mFramebufferColorTexture, 0);
139 ASSERT_GL_NO_ERROR();
140 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
141 glBindTexture(GL_TEXTURE_2D, 0);
142 }
143
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200144 // Returns the created texture ID.
145 GLuint create2DTexture()
146 {
147 GLuint texture2D;
148 glGenTextures(1, &texture2D);
149 glBindTexture(GL_TEXTURE_2D, texture2D);
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800150 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200151 EXPECT_GL_NO_ERROR();
152 return texture2D;
153 }
154
155 GLuint mProgram;
Olli Etuaho51f1c0f2016-01-13 16:16:24 +0200156 GLuint mFramebuffer;
157
158 private:
159 GLuint mFramebufferColorTexture;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200160};
161
162class Texture2DTest : public TexCoordDrawTest
163{
164 protected:
165 Texture2DTest() : TexCoordDrawTest(), mTexture2D(0), mTexture2DUniformLocation(-1) {}
166
Jamie Madill35cd7332018-12-02 12:03:33 -0500167 const char *getFragmentShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200168 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500169 return R"(precision highp float;
170uniform sampler2D tex;
171varying vec2 texcoord;
Geoff Langc41e42d2014-04-28 10:58:16 -0400172
Jamie Madill35cd7332018-12-02 12:03:33 -0500173void main()
174{
175 gl_FragColor = texture2D(tex, texcoord);
176})";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200177 }
Geoff Langc41e42d2014-04-28 10:58:16 -0400178
Olli Etuaho96963162016-03-21 11:54:33 +0200179 virtual const char *getTextureUniformName() { return "tex"; }
180
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300181 void setUpProgram() override
182 {
183 TexCoordDrawTest::setUpProgram();
184 mTexture2DUniformLocation = glGetUniformLocation(mProgram, getTextureUniformName());
185 ASSERT_NE(-1, mTexture2DUniformLocation);
186 }
187
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400188 void testSetUp() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200189 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400190 TexCoordDrawTest::testSetUp();
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200191 mTexture2D = create2DTexture();
Jamie Madilld4cfa572014-07-08 10:00:32 -0400192
Jamie Madill9aca0592014-10-06 16:26:59 -0400193 ASSERT_GL_NO_ERROR();
Jamie Madillf67115c2014-04-22 13:14:05 -0400194 }
195
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400196 void testTearDown() override
Jamie Madillf67115c2014-04-22 13:14:05 -0400197 {
Jamie Madilld4cfa572014-07-08 10:00:32 -0400198 glDeleteTextures(1, &mTexture2D);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400199 TexCoordDrawTest::testTearDown();
Jamie Madillf67115c2014-04-22 13:14:05 -0400200 }
201
Jamie Madillbc393df2015-01-29 13:46:07 -0500202 // Tests CopyTexSubImage with floating point textures of various formats.
203 void testFloatCopySubImage(int sourceImageChannels, int destImageChannels)
204 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300205 setUpProgram();
206
Martin Radev1be913c2016-07-11 17:59:16 +0300207 if (getClientMajorVersion() < 3)
Geoff Langfbfa47c2015-03-31 11:26:00 -0400208 {
Jamie Madillb8149072019-04-30 16:14:44 -0400209 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_storage") ||
210 !IsGLExtensionEnabled("GL_OES_texture_float"));
Geoff Langc4e93662017-05-01 10:45:59 -0400211
Yunchao He9550c602018-02-13 14:47:05 +0800212 ANGLE_SKIP_TEST_IF((sourceImageChannels < 3 || destImageChannels < 3) &&
Jamie Madillb8149072019-04-30 16:14:44 -0400213 !IsGLExtensionEnabled("GL_EXT_texture_rg"));
Geoff Langfbfa47c2015-03-31 11:26:00 -0400214
Yunchao He9550c602018-02-13 14:47:05 +0800215 ANGLE_SKIP_TEST_IF(destImageChannels == 3 &&
Jamie Madillb8149072019-04-30 16:14:44 -0400216 !IsGLExtensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400217
Yunchao He9550c602018-02-13 14:47:05 +0800218 ANGLE_SKIP_TEST_IF(destImageChannels == 4 &&
Jamie Madillb8149072019-04-30 16:14:44 -0400219 !IsGLExtensionEnabled("GL_CHROMIUM_color_buffer_float_rgba"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400220
Yunchao He9550c602018-02-13 14:47:05 +0800221 ANGLE_SKIP_TEST_IF(destImageChannels <= 2);
Geoff Lang677bb6f2017-04-05 12:40:40 -0400222 }
223 else
224 {
Jamie Madillb8149072019-04-30 16:14:44 -0400225 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_color_buffer_float"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400226
Yunchao He9550c602018-02-13 14:47:05 +0800227 ANGLE_SKIP_TEST_IF(destImageChannels == 3 &&
Jamie Madillb8149072019-04-30 16:14:44 -0400228 !IsGLExtensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"));
Geoff Langfbfa47c2015-03-31 11:26:00 -0400229 }
230
Jamie Madill50cf2be2018-06-15 09:46:57 -0400231 // clang-format off
Jamie Madillbc393df2015-01-29 13:46:07 -0500232 GLfloat sourceImageData[4][16] =
233 {
234 { // R
235 1.0f,
236 0.0f,
237 0.0f,
238 1.0f
239 },
240 { // RG
241 1.0f, 0.0f,
242 0.0f, 1.0f,
243 0.0f, 0.0f,
244 1.0f, 1.0f
245 },
246 { // RGB
247 1.0f, 0.0f, 0.0f,
248 0.0f, 1.0f, 0.0f,
249 0.0f, 0.0f, 1.0f,
250 1.0f, 1.0f, 0.0f
251 },
252 { // RGBA
253 1.0f, 0.0f, 0.0f, 1.0f,
254 0.0f, 1.0f, 0.0f, 1.0f,
255 0.0f, 0.0f, 1.0f, 1.0f,
256 1.0f, 1.0f, 0.0f, 1.0f
257 },
258 };
Jamie Madill50cf2be2018-06-15 09:46:57 -0400259 // clang-format on
Jamie Madillbc393df2015-01-29 13:46:07 -0500260
Jamie Madill50cf2be2018-06-15 09:46:57 -0400261 GLenum imageFormats[] = {
Jamie Madillb980c562018-11-27 11:34:27 -0500262 GL_R32F,
263 GL_RG32F,
264 GL_RGB32F,
265 GL_RGBA32F,
Jamie Madillbc393df2015-01-29 13:46:07 -0500266 };
267
Jamie Madill50cf2be2018-06-15 09:46:57 -0400268 GLenum sourceUnsizedFormats[] = {
Jamie Madillb980c562018-11-27 11:34:27 -0500269 GL_RED,
270 GL_RG,
271 GL_RGB,
272 GL_RGBA,
Jamie Madillbc393df2015-01-29 13:46:07 -0500273 };
274
275 GLuint textures[2];
276
277 glGenTextures(2, textures);
278
Jamie Madill50cf2be2018-06-15 09:46:57 -0400279 GLfloat *imageData = sourceImageData[sourceImageChannels - 1];
280 GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1];
Jamie Madillbc393df2015-01-29 13:46:07 -0500281 GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1];
Jamie Madill50cf2be2018-06-15 09:46:57 -0400282 GLenum destImageFormat = imageFormats[destImageChannels - 1];
Jamie Madillbc393df2015-01-29 13:46:07 -0500283
284 glBindTexture(GL_TEXTURE_2D, textures[0]);
Geoff Langc4e93662017-05-01 10:45:59 -0400285 if (getClientMajorVersion() >= 3)
286 {
287 glTexStorage2D(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
288 }
289 else
290 {
291 glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
292 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500293 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
294 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
295 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData);
296
Jamie Madillb8149072019-04-30 16:14:44 -0400297 if (sourceImageChannels < 3 && !IsGLExtensionEnabled("GL_EXT_texture_rg"))
Jamie Madillbc393df2015-01-29 13:46:07 -0500298 {
299 // This is not supported
300 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
301 }
302 else
303 {
304 ASSERT_GL_NO_ERROR();
305 }
306
307 GLuint fbo;
308 glGenFramebuffers(1, &fbo);
309 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
310 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
311
312 glBindTexture(GL_TEXTURE_2D, textures[1]);
Geoff Langc4e93662017-05-01 10:45:59 -0400313 if (getClientMajorVersion() >= 3)
314 {
315 glTexStorage2D(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
316 }
317 else
318 {
319 glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
320 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500321 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
322 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
323
324 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
325 ASSERT_GL_NO_ERROR();
326
327 glBindFramebuffer(GL_FRAMEBUFFER, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200328 drawQuad(mProgram, "position", 0.5f);
Jamie Madillbc393df2015-01-29 13:46:07 -0500329
330 int testImageChannels = std::min(sourceImageChannels, destImageChannels);
331
Olli Etuahoa314b612016-03-10 16:43:00 +0200332 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Jamie Madillbc393df2015-01-29 13:46:07 -0500333 if (testImageChannels > 1)
334 {
335 EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255);
336 EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255);
337 if (testImageChannels > 2)
338 {
339 EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255);
340 }
341 }
342
343 glDeleteFramebuffers(1, &fbo);
344 glDeleteTextures(2, textures);
345
346 ASSERT_GL_NO_ERROR();
347 }
348
Jamie Madilld4cfa572014-07-08 10:00:32 -0400349 GLuint mTexture2D;
Jamie Madilld4cfa572014-07-08 10:00:32 -0400350 GLint mTexture2DUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400351};
352
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200353class Texture2DTestES3 : public Texture2DTest
354{
355 protected:
356 Texture2DTestES3() : Texture2DTest() {}
357
Jamie Madill35cd7332018-12-02 12:03:33 -0500358 const char *getVertexShaderSource() override
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200359 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500360 return "#version 300 es\n"
361 "out vec2 texcoord;\n"
362 "in vec4 position;\n"
363 "void main()\n"
364 "{\n"
365 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
366 " texcoord = (position.xy * 0.5) + 0.5;\n"
367 "}\n";
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200368 }
369
Jamie Madill35cd7332018-12-02 12:03:33 -0500370 const char *getFragmentShaderSource() override
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200371 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500372 return "#version 300 es\n"
373 "precision highp float;\n"
374 "uniform highp sampler2D tex;\n"
375 "in vec2 texcoord;\n"
376 "out vec4 fragColor;\n"
377 "void main()\n"
378 "{\n"
379 " fragColor = texture(tex, texcoord);\n"
380 "}\n";
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200381 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300382
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400383 void testSetUp() override
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300384 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400385 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300386 setUpProgram();
387 }
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200388};
389
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200390class Texture2DIntegerAlpha1TestES3 : public Texture2DTest
391{
392 protected:
393 Texture2DIntegerAlpha1TestES3() : Texture2DTest() {}
394
Jamie Madill35cd7332018-12-02 12:03:33 -0500395 const char *getVertexShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200396 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500397 return "#version 300 es\n"
398 "out vec2 texcoord;\n"
399 "in vec4 position;\n"
400 "void main()\n"
401 "{\n"
402 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
403 " texcoord = (position.xy * 0.5) + 0.5;\n"
404 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200405 }
406
Jamie Madill35cd7332018-12-02 12:03:33 -0500407 const char *getFragmentShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200408 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500409 return "#version 300 es\n"
410 "precision highp float;\n"
411 "uniform highp isampler2D tex;\n"
412 "in vec2 texcoord;\n"
413 "out vec4 fragColor;\n"
414 "void main()\n"
415 "{\n"
416 " vec4 green = vec4(0, 1, 0, 1);\n"
417 " vec4 black = vec4(0, 0, 0, 0);\n"
418 " fragColor = (texture(tex, texcoord).a == 1) ? green : black;\n"
419 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200420 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300421
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400422 void testSetUp() override
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300423 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400424 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300425 setUpProgram();
426 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200427};
428
429class Texture2DUnsignedIntegerAlpha1TestES3 : public Texture2DTest
430{
431 protected:
432 Texture2DUnsignedIntegerAlpha1TestES3() : Texture2DTest() {}
433
Jamie Madill35cd7332018-12-02 12:03:33 -0500434 const char *getVertexShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200435 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500436 return "#version 300 es\n"
437 "out vec2 texcoord;\n"
438 "in vec4 position;\n"
439 "void main()\n"
440 "{\n"
441 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
442 " texcoord = (position.xy * 0.5) + 0.5;\n"
443 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200444 }
445
Jamie Madill35cd7332018-12-02 12:03:33 -0500446 const char *getFragmentShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200447 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500448 return "#version 300 es\n"
449 "precision highp float;\n"
450 "uniform highp usampler2D tex;\n"
451 "in vec2 texcoord;\n"
452 "out vec4 fragColor;\n"
453 "void main()\n"
454 "{\n"
455 " vec4 green = vec4(0, 1, 0, 1);\n"
456 " vec4 black = vec4(0, 0, 0, 0);\n"
457 " fragColor = (texture(tex, texcoord).a == 1u) ? green : black;\n"
458 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200459 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300460
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400461 void testSetUp() override
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300462 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400463 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300464 setUpProgram();
465 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200466};
467
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200468class Texture2DTestWithDrawScale : public Texture2DTest
Jamie Madill2453dbc2015-07-14 11:35:42 -0400469{
470 protected:
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200471 Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {}
472
Jamie Madill35cd7332018-12-02 12:03:33 -0500473 const char *getVertexShaderSource() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400474 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300475 return
476 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200477 attribute vec4 position;
478 varying vec2 texcoord;
479
480 uniform vec2 drawScale;
481
482 void main()
483 {
484 gl_Position = vec4(position.xy * drawScale, 0.0, 1.0);
485 texcoord = (position.xy * 0.5) + 0.5;
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300486 })";
Jamie Madill2453dbc2015-07-14 11:35:42 -0400487 }
488
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400489 void testSetUp() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400490 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400491 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300492
493 setUpProgram();
494
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200495 mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale");
496 ASSERT_NE(-1, mDrawScaleUniformLocation);
Jamie Madill2453dbc2015-07-14 11:35:42 -0400497
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200498 glUseProgram(mProgram);
499 glUniform2f(mDrawScaleUniformLocation, 1.0f, 1.0f);
500 glUseProgram(0);
501 ASSERT_GL_NO_ERROR();
502 }
503
504 GLint mDrawScaleUniformLocation;
505};
506
Olli Etuaho4644a202016-01-12 15:12:53 +0200507class Sampler2DAsFunctionParameterTest : public Texture2DTest
508{
509 protected:
510 Sampler2DAsFunctionParameterTest() : Texture2DTest() {}
511
Jamie Madill35cd7332018-12-02 12:03:33 -0500512 const char *getFragmentShaderSource() override
Olli Etuaho4644a202016-01-12 15:12:53 +0200513 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300514 return
515 R"(precision highp float;
Olli Etuaho4644a202016-01-12 15:12:53 +0200516 uniform sampler2D tex;
517 varying vec2 texcoord;
518
519 vec4 computeFragColor(sampler2D aTex)
520 {
521 return texture2D(aTex, texcoord);
522 }
523
524 void main()
525 {
526 gl_FragColor = computeFragColor(tex);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300527 })";
Olli Etuaho4644a202016-01-12 15:12:53 +0200528 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300529
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400530 void testSetUp() override
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300531 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400532 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300533 setUpProgram();
534 }
Olli Etuaho4644a202016-01-12 15:12:53 +0200535};
536
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200537class TextureCubeTest : public TexCoordDrawTest
538{
539 protected:
540 TextureCubeTest()
541 : TexCoordDrawTest(),
542 mTexture2D(0),
543 mTextureCube(0),
544 mTexture2DUniformLocation(-1),
545 mTextureCubeUniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500546 {}
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200547
Jamie Madill35cd7332018-12-02 12:03:33 -0500548 const char *getFragmentShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200549 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300550 return
551 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200552 uniform sampler2D tex2D;
553 uniform samplerCube texCube;
554 varying vec2 texcoord;
555
556 void main()
557 {
558 gl_FragColor = texture2D(tex2D, texcoord);
559 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300560 })";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200561 }
562
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400563 void testSetUp() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200564 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400565 TexCoordDrawTest::testSetUp();
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200566
567 glGenTextures(1, &mTextureCube);
568 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Geoff Langc4e93662017-05-01 10:45:59 -0400569 for (GLenum face = 0; face < 6; face++)
570 {
571 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
572 GL_UNSIGNED_BYTE, nullptr);
573 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200574 EXPECT_GL_NO_ERROR();
575
576 mTexture2D = create2DTexture();
577
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300578 setUpProgram();
579
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200580 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
581 ASSERT_NE(-1, mTexture2DUniformLocation);
582 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
583 ASSERT_NE(-1, mTextureCubeUniformLocation);
584 }
585
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400586 void testTearDown() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200587 {
588 glDeleteTextures(1, &mTextureCube);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400589 TexCoordDrawTest::testTearDown();
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200590 }
591
592 GLuint mTexture2D;
593 GLuint mTextureCube;
594 GLint mTexture2DUniformLocation;
595 GLint mTextureCubeUniformLocation;
596};
597
Martin Radev7e2c0d32017-09-15 14:25:42 +0300598class TextureCubeTestES3 : public ANGLETest
599{
600 protected:
601 TextureCubeTestES3() {}
602};
603
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200604class SamplerArrayTest : public TexCoordDrawTest
605{
606 protected:
607 SamplerArrayTest()
608 : TexCoordDrawTest(),
609 mTexture2DA(0),
610 mTexture2DB(0),
611 mTexture0UniformLocation(-1),
612 mTexture1UniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500613 {}
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200614
Jamie Madill35cd7332018-12-02 12:03:33 -0500615 const char *getFragmentShaderSource() override
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200616 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300617 return
618 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200619 uniform highp sampler2D tex2DArray[2];
620 varying vec2 texcoord;
621 void main()
622 {
623 gl_FragColor = texture2D(tex2DArray[0], texcoord);
624 gl_FragColor += texture2D(tex2DArray[1], texcoord);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300625 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200626 }
627
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400628 void testSetUp() override
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200629 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400630 TexCoordDrawTest::testSetUp();
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200631
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300632 setUpProgram();
633
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200634 mTexture0UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[0]");
635 ASSERT_NE(-1, mTexture0UniformLocation);
636 mTexture1UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[1]");
637 ASSERT_NE(-1, mTexture1UniformLocation);
638
639 mTexture2DA = create2DTexture();
640 mTexture2DB = create2DTexture();
641 ASSERT_GL_NO_ERROR();
642 }
643
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400644 void testTearDown() override
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200645 {
646 glDeleteTextures(1, &mTexture2DA);
647 glDeleteTextures(1, &mTexture2DB);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400648 TexCoordDrawTest::testTearDown();
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200649 }
650
651 void testSamplerArrayDraw()
652 {
653 GLubyte texData[4];
654 texData[0] = 0;
655 texData[1] = 60;
656 texData[2] = 0;
657 texData[3] = 255;
658
659 glActiveTexture(GL_TEXTURE0);
660 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
661 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
662
663 texData[1] = 120;
664 glActiveTexture(GL_TEXTURE1);
665 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
666 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
667 EXPECT_GL_ERROR(GL_NO_ERROR);
668
669 glUseProgram(mProgram);
670 glUniform1i(mTexture0UniformLocation, 0);
671 glUniform1i(mTexture1UniformLocation, 1);
672 drawQuad(mProgram, "position", 0.5f);
673 EXPECT_GL_NO_ERROR();
674
675 EXPECT_PIXEL_NEAR(0, 0, 0, 180, 0, 255, 2);
676 }
677
678 GLuint mTexture2DA;
679 GLuint mTexture2DB;
680 GLint mTexture0UniformLocation;
681 GLint mTexture1UniformLocation;
682};
683
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200684class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest
685{
686 protected:
687 SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {}
688
Jamie Madill35cd7332018-12-02 12:03:33 -0500689 const char *getFragmentShaderSource() override
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200690 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300691 return
692 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200693 uniform highp sampler2D tex2DArray[2];
694 varying vec2 texcoord;
695
696 vec4 computeFragColor(highp sampler2D aTex2DArray[2])
697 {
698 return texture2D(aTex2DArray[0], texcoord) + texture2D(aTex2DArray[1], texcoord);
699 }
700
701 void main()
702 {
703 gl_FragColor = computeFragColor(tex2DArray);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300704 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200705 }
706};
707
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200708class Texture2DArrayTestES3 : public TexCoordDrawTest
709{
710 protected:
711 Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {}
712
Jamie Madill35cd7332018-12-02 12:03:33 -0500713 const char *getVertexShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200714 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500715 return "#version 300 es\n"
716 "out vec2 texcoord;\n"
717 "in vec4 position;\n"
718 "void main()\n"
719 "{\n"
720 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
721 " texcoord = (position.xy * 0.5) + 0.5;\n"
722 "}\n";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200723 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400724
Jamie Madill35cd7332018-12-02 12:03:33 -0500725 const char *getFragmentShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200726 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500727 return "#version 300 es\n"
728 "precision highp float;\n"
729 "uniform highp sampler2DArray tex2DArray;\n"
730 "in vec2 texcoord;\n"
731 "out vec4 fragColor;\n"
732 "void main()\n"
733 "{\n"
734 " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n"
735 "}\n";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200736 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400737
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400738 void testSetUp() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200739 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400740 TexCoordDrawTest::testSetUp();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400741
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300742 setUpProgram();
743
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200744 mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray");
Jamie Madill2453dbc2015-07-14 11:35:42 -0400745 ASSERT_NE(-1, mTextureArrayLocation);
746
747 glGenTextures(1, &m2DArrayTexture);
748 ASSERT_GL_NO_ERROR();
749 }
750
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400751 void testTearDown() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400752 {
753 glDeleteTextures(1, &m2DArrayTexture);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400754 TexCoordDrawTest::testTearDown();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400755 }
756
757 GLuint m2DArrayTexture;
Jamie Madill2453dbc2015-07-14 11:35:42 -0400758 GLint mTextureArrayLocation;
759};
760
Olli Etuahobce743a2016-01-15 17:18:28 +0200761class TextureSizeTextureArrayTest : public TexCoordDrawTest
762{
763 protected:
764 TextureSizeTextureArrayTest()
765 : TexCoordDrawTest(),
766 mTexture2DA(0),
767 mTexture2DB(0),
768 mTexture0Location(-1),
769 mTexture1Location(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500770 {}
Olli Etuahobce743a2016-01-15 17:18:28 +0200771
Jamie Madill35cd7332018-12-02 12:03:33 -0500772 const char *getVertexShaderSource() override { return essl3_shaders::vs::Simple(); }
Olli Etuahobce743a2016-01-15 17:18:28 +0200773
Jamie Madill35cd7332018-12-02 12:03:33 -0500774 const char *getFragmentShaderSource() override
Olli Etuahobce743a2016-01-15 17:18:28 +0200775 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500776 return "#version 300 es\n"
777 "precision highp float;\n"
778 "uniform highp sampler2D tex2DArray[2];\n"
779 "out vec4 fragColor;\n"
780 "void main()\n"
781 "{\n"
782 " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n"
783 " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n"
784 " fragColor = vec4(red, green, 0.0, 1.0);\n"
785 "}\n";
Olli Etuahobce743a2016-01-15 17:18:28 +0200786 }
787
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400788 void testSetUp() override
Olli Etuahobce743a2016-01-15 17:18:28 +0200789 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400790 TexCoordDrawTest::testSetUp();
Olli Etuahobce743a2016-01-15 17:18:28 +0200791
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300792 setUpProgram();
793
Olli Etuahobce743a2016-01-15 17:18:28 +0200794 mTexture0Location = glGetUniformLocation(mProgram, "tex2DArray[0]");
795 ASSERT_NE(-1, mTexture0Location);
796 mTexture1Location = glGetUniformLocation(mProgram, "tex2DArray[1]");
797 ASSERT_NE(-1, mTexture1Location);
798
799 mTexture2DA = create2DTexture();
800 mTexture2DB = create2DTexture();
801 ASSERT_GL_NO_ERROR();
802 }
803
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400804 void testTearDown() override
Olli Etuahobce743a2016-01-15 17:18:28 +0200805 {
806 glDeleteTextures(1, &mTexture2DA);
807 glDeleteTextures(1, &mTexture2DB);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400808 TexCoordDrawTest::testTearDown();
Olli Etuahobce743a2016-01-15 17:18:28 +0200809 }
810
811 GLuint mTexture2DA;
812 GLuint mTexture2DB;
813 GLint mTexture0Location;
814 GLint mTexture1Location;
815};
816
Olli Etuahoa314b612016-03-10 16:43:00 +0200817class Texture3DTestES3 : public TexCoordDrawTest
818{
819 protected:
820 Texture3DTestES3() : TexCoordDrawTest(), mTexture3D(0), mTexture3DUniformLocation(-1) {}
821
Jamie Madill35cd7332018-12-02 12:03:33 -0500822 const char *getVertexShaderSource() override
Olli Etuahoa314b612016-03-10 16:43:00 +0200823 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500824 return "#version 300 es\n"
825 "out vec2 texcoord;\n"
826 "in vec4 position;\n"
827 "void main()\n"
828 "{\n"
829 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
830 " texcoord = (position.xy * 0.5) + 0.5;\n"
831 "}\n";
Olli Etuahoa314b612016-03-10 16:43:00 +0200832 }
833
Jamie Madill35cd7332018-12-02 12:03:33 -0500834 const char *getFragmentShaderSource() override
Olli Etuahoa314b612016-03-10 16:43:00 +0200835 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500836 return "#version 300 es\n"
837 "precision highp float;\n"
838 "uniform highp sampler3D tex3D;\n"
839 "in vec2 texcoord;\n"
840 "out vec4 fragColor;\n"
841 "void main()\n"
842 "{\n"
843 " fragColor = texture(tex3D, vec3(texcoord, 0.0));\n"
844 "}\n";
Olli Etuahoa314b612016-03-10 16:43:00 +0200845 }
846
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400847 void testSetUp() override
Olli Etuahoa314b612016-03-10 16:43:00 +0200848 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400849 TexCoordDrawTest::testSetUp();
Olli Etuahoa314b612016-03-10 16:43:00 +0200850
851 glGenTextures(1, &mTexture3D);
852
853 setUpProgram();
854
855 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
856 ASSERT_NE(-1, mTexture3DUniformLocation);
857 }
858
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400859 void testTearDown() override
Olli Etuahoa314b612016-03-10 16:43:00 +0200860 {
861 glDeleteTextures(1, &mTexture3D);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400862 TexCoordDrawTest::testTearDown();
Olli Etuahoa314b612016-03-10 16:43:00 +0200863 }
864
865 GLuint mTexture3D;
866 GLint mTexture3DUniformLocation;
867};
868
Olli Etuaho1a679902016-01-14 12:21:47 +0200869class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest
870{
871 protected:
872 ShadowSamplerPlusSampler3DTestES3()
873 : TexCoordDrawTest(),
874 mTextureShadow(0),
875 mTexture3D(0),
876 mTextureShadowUniformLocation(-1),
877 mTexture3DUniformLocation(-1),
878 mDepthRefUniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500879 {}
Olli Etuaho1a679902016-01-14 12:21:47 +0200880
Jamie Madill35cd7332018-12-02 12:03:33 -0500881 const char *getVertexShaderSource() override
Olli Etuaho1a679902016-01-14 12:21:47 +0200882 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500883 return "#version 300 es\n"
884 "out vec2 texcoord;\n"
885 "in vec4 position;\n"
886 "void main()\n"
887 "{\n"
888 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
889 " texcoord = (position.xy * 0.5) + 0.5;\n"
890 "}\n";
Olli Etuaho1a679902016-01-14 12:21:47 +0200891 }
892
Jamie Madill35cd7332018-12-02 12:03:33 -0500893 const char *getFragmentShaderSource() override
Olli Etuaho1a679902016-01-14 12:21:47 +0200894 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500895 return "#version 300 es\n"
896 "precision highp float;\n"
897 "uniform highp sampler2DShadow tex2DShadow;\n"
898 "uniform highp sampler3D tex3D;\n"
899 "in vec2 texcoord;\n"
900 "uniform float depthRef;\n"
901 "out vec4 fragColor;\n"
902 "void main()\n"
903 "{\n"
904 " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n"
905 " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n"
906 "}\n";
Olli Etuaho1a679902016-01-14 12:21:47 +0200907 }
908
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400909 void testSetUp() override
Olli Etuaho1a679902016-01-14 12:21:47 +0200910 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400911 TexCoordDrawTest::testSetUp();
Olli Etuaho1a679902016-01-14 12:21:47 +0200912
913 glGenTextures(1, &mTexture3D);
914
915 glGenTextures(1, &mTextureShadow);
916 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
917 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
918
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300919 setUpProgram();
920
Olli Etuaho1a679902016-01-14 12:21:47 +0200921 mTextureShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
922 ASSERT_NE(-1, mTextureShadowUniformLocation);
923 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
924 ASSERT_NE(-1, mTexture3DUniformLocation);
925 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
926 ASSERT_NE(-1, mDepthRefUniformLocation);
927 }
928
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400929 void testTearDown() override
Olli Etuaho1a679902016-01-14 12:21:47 +0200930 {
931 glDeleteTextures(1, &mTextureShadow);
932 glDeleteTextures(1, &mTexture3D);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400933 TexCoordDrawTest::testTearDown();
Olli Etuaho1a679902016-01-14 12:21:47 +0200934 }
935
936 GLuint mTextureShadow;
937 GLuint mTexture3D;
938 GLint mTextureShadowUniformLocation;
939 GLint mTexture3DUniformLocation;
940 GLint mDepthRefUniformLocation;
941};
942
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200943class SamplerTypeMixTestES3 : public TexCoordDrawTest
944{
945 protected:
946 SamplerTypeMixTestES3()
947 : TexCoordDrawTest(),
948 mTexture2D(0),
949 mTextureCube(0),
950 mTexture2DShadow(0),
951 mTextureCubeShadow(0),
952 mTexture2DUniformLocation(-1),
953 mTextureCubeUniformLocation(-1),
954 mTexture2DShadowUniformLocation(-1),
955 mTextureCubeShadowUniformLocation(-1),
956 mDepthRefUniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500957 {}
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200958
Jamie Madill35cd7332018-12-02 12:03:33 -0500959 const char *getVertexShaderSource() override
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200960 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500961 return "#version 300 es\n"
962 "out vec2 texcoord;\n"
963 "in vec4 position;\n"
964 "void main()\n"
965 "{\n"
966 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
967 " texcoord = (position.xy * 0.5) + 0.5;\n"
968 "}\n";
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200969 }
970
Jamie Madill35cd7332018-12-02 12:03:33 -0500971 const char *getFragmentShaderSource() override
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200972 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500973 return "#version 300 es\n"
974 "precision highp float;\n"
975 "uniform highp sampler2D tex2D;\n"
976 "uniform highp samplerCube texCube;\n"
977 "uniform highp sampler2DShadow tex2DShadow;\n"
978 "uniform highp samplerCubeShadow texCubeShadow;\n"
979 "in vec2 texcoord;\n"
980 "uniform float depthRef;\n"
981 "out vec4 fragColor;\n"
982 "void main()\n"
983 "{\n"
984 " fragColor = texture(tex2D, texcoord);\n"
985 " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n"
986 " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n"
987 " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * "
988 "0.125);\n"
989 "}\n";
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200990 }
991
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400992 void testSetUp() override
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200993 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400994 TexCoordDrawTest::testSetUp();
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200995
996 glGenTextures(1, &mTexture2D);
997 glGenTextures(1, &mTextureCube);
998
999 glGenTextures(1, &mTexture2DShadow);
1000 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
1001 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
1002
1003 glGenTextures(1, &mTextureCubeShadow);
1004 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
1005 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
1006
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001007 setUpProgram();
1008
Olli Etuahoc8c99a02016-01-14 16:47:22 +02001009 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
1010 ASSERT_NE(-1, mTexture2DUniformLocation);
1011 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
1012 ASSERT_NE(-1, mTextureCubeUniformLocation);
1013 mTexture2DShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
1014 ASSERT_NE(-1, mTexture2DShadowUniformLocation);
1015 mTextureCubeShadowUniformLocation = glGetUniformLocation(mProgram, "texCubeShadow");
1016 ASSERT_NE(-1, mTextureCubeShadowUniformLocation);
1017 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
1018 ASSERT_NE(-1, mDepthRefUniformLocation);
1019
1020 ASSERT_GL_NO_ERROR();
1021 }
1022
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04001023 void testTearDown() override
Olli Etuahoc8c99a02016-01-14 16:47:22 +02001024 {
1025 glDeleteTextures(1, &mTexture2D);
1026 glDeleteTextures(1, &mTextureCube);
1027 glDeleteTextures(1, &mTexture2DShadow);
1028 glDeleteTextures(1, &mTextureCubeShadow);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04001029 TexCoordDrawTest::testTearDown();
Olli Etuahoc8c99a02016-01-14 16:47:22 +02001030 }
1031
1032 GLuint mTexture2D;
1033 GLuint mTextureCube;
1034 GLuint mTexture2DShadow;
1035 GLuint mTextureCubeShadow;
1036 GLint mTexture2DUniformLocation;
1037 GLint mTextureCubeUniformLocation;
1038 GLint mTexture2DShadowUniformLocation;
1039 GLint mTextureCubeShadowUniformLocation;
1040 GLint mDepthRefUniformLocation;
1041};
1042
Olli Etuaho96963162016-03-21 11:54:33 +02001043class SamplerInStructTest : public Texture2DTest
1044{
1045 protected:
1046 SamplerInStructTest() : Texture2DTest() {}
1047
1048 const char *getTextureUniformName() override { return "us.tex"; }
1049
Jamie Madill35cd7332018-12-02 12:03:33 -05001050 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001051 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001052 return "precision highp float;\n"
1053 "struct S\n"
1054 "{\n"
1055 " vec4 a;\n"
1056 " highp sampler2D tex;\n"
1057 "};\n"
1058 "uniform S us;\n"
1059 "varying vec2 texcoord;\n"
1060 "void main()\n"
1061 "{\n"
1062 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x);\n"
1063 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001064 }
1065
1066 void runSamplerInStructTest()
1067 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001068 setUpProgram();
1069
Olli Etuaho96963162016-03-21 11:54:33 +02001070 glActiveTexture(GL_TEXTURE0);
1071 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001072 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1073 &GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001074 drawQuad(mProgram, "position", 0.5f);
Olli Etuahoa314b612016-03-10 16:43:00 +02001075 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001076 }
1077};
1078
1079class SamplerInStructAsFunctionParameterTest : public SamplerInStructTest
1080{
1081 protected:
1082 SamplerInStructAsFunctionParameterTest() : SamplerInStructTest() {}
1083
Jamie Madill35cd7332018-12-02 12:03:33 -05001084 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001085 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001086 return "precision highp float;\n"
1087 "struct S\n"
1088 "{\n"
1089 " vec4 a;\n"
1090 " highp sampler2D tex;\n"
1091 "};\n"
1092 "uniform S us;\n"
1093 "varying vec2 texcoord;\n"
1094 "vec4 sampleFrom(S s) {\n"
1095 " return texture2D(s.tex, texcoord + s.a.x);\n"
1096 "}\n"
1097 "void main()\n"
1098 "{\n"
1099 " gl_FragColor = sampleFrom(us);\n"
1100 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001101 }
1102};
1103
1104class SamplerInStructArrayAsFunctionParameterTest : public SamplerInStructTest
1105{
1106 protected:
1107 SamplerInStructArrayAsFunctionParameterTest() : SamplerInStructTest() {}
1108
1109 const char *getTextureUniformName() override { return "us[0].tex"; }
1110
Jamie Madill35cd7332018-12-02 12:03:33 -05001111 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001112 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001113 return "precision highp float;\n"
1114 "struct S\n"
1115 "{\n"
1116 " vec4 a;\n"
1117 " highp sampler2D tex;\n"
1118 "};\n"
1119 "uniform S us[1];\n"
1120 "varying vec2 texcoord;\n"
1121 "vec4 sampleFrom(S s) {\n"
1122 " return texture2D(s.tex, texcoord + s.a.x);\n"
1123 "}\n"
1124 "void main()\n"
1125 "{\n"
1126 " gl_FragColor = sampleFrom(us[0]);\n"
1127 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001128 }
1129};
1130
1131class SamplerInNestedStructAsFunctionParameterTest : public SamplerInStructTest
1132{
1133 protected:
1134 SamplerInNestedStructAsFunctionParameterTest() : SamplerInStructTest() {}
1135
1136 const char *getTextureUniformName() override { return "us[0].sub.tex"; }
1137
Jamie Madill35cd7332018-12-02 12:03:33 -05001138 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001139 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001140 return "precision highp float;\n"
1141 "struct SUB\n"
1142 "{\n"
1143 " vec4 a;\n"
1144 " highp sampler2D tex;\n"
1145 "};\n"
1146 "struct S\n"
1147 "{\n"
1148 " SUB sub;\n"
1149 "};\n"
1150 "uniform S us[1];\n"
1151 "varying vec2 texcoord;\n"
1152 "vec4 sampleFrom(SUB s) {\n"
1153 " return texture2D(s.tex, texcoord + s.a.x);\n"
1154 "}\n"
1155 "void main()\n"
1156 "{\n"
1157 " gl_FragColor = sampleFrom(us[0].sub);\n"
1158 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001159 }
1160};
1161
1162class SamplerInStructAndOtherVariableTest : public SamplerInStructTest
1163{
1164 protected:
1165 SamplerInStructAndOtherVariableTest() : SamplerInStructTest() {}
1166
Jamie Madill35cd7332018-12-02 12:03:33 -05001167 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001168 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001169 return "precision highp float;\n"
1170 "struct S\n"
1171 "{\n"
1172 " vec4 a;\n"
1173 " highp sampler2D tex;\n"
1174 "};\n"
1175 "uniform S us;\n"
1176 "uniform float us_tex;\n"
1177 "varying vec2 texcoord;\n"
1178 "void main()\n"
1179 "{\n"
1180 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x + us_tex);\n"
1181 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001182 }
1183};
1184
Anders Leinof6cbe442019-04-18 15:32:07 +03001185class Texture2DIntegerTestES3 : public Texture2DTest
1186{
1187 protected:
1188 Texture2DIntegerTestES3() : Texture2DTest() {}
1189
1190 const char *getVertexShaderSource() override
1191 {
1192 return "#version 300 es\n"
1193 "out vec2 texcoord;\n"
1194 "in vec4 position;\n"
1195 "void main()\n"
1196 "{\n"
1197 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1198 " texcoord = (position.xy * 0.5) + 0.5;\n"
1199 "}\n";
1200 }
1201
1202 const char *getFragmentShaderSource() override
1203 {
1204 return "#version 300 es\n"
1205 "precision highp float;\n"
1206 "precision highp usampler2D;\n"
1207 "uniform usampler2D tex;\n"
1208 "in vec2 texcoord;\n"
1209 "out vec4 fragColor;\n"
1210 "void main()\n"
1211 "{\n"
Anders Leino8224a582019-05-20 12:39:29 +03001212 " fragColor = vec4(texture(tex, texcoord))/255.0;\n"
Anders Leinof6cbe442019-04-18 15:32:07 +03001213 "}\n";
1214 }
1215};
1216
Anders Leino60cc7512019-05-06 09:25:27 +03001217class TextureCubeIntegerTestES3 : public TexCoordDrawTest
1218{
1219 protected:
1220 TextureCubeIntegerTestES3()
1221 : TexCoordDrawTest(), mTextureCube(0), mTextureCubeUniformLocation(-1)
1222 {}
1223
1224 const char *getVertexShaderSource() override
1225 {
1226 return "#version 300 es\n"
1227 "out vec2 texcoord;\n"
1228 "in vec4 position;\n"
1229 "void main()\n"
1230 "{\n"
1231 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1232 " texcoord = 0.5*position.xy;\n"
1233 "}\n";
1234 }
1235
1236 const char *getFragmentShaderSource() override
1237 {
1238 return "#version 300 es\n"
1239 "precision highp float;\n"
1240 "precision highp usamplerCube;\n"
1241 "uniform usamplerCube texCube;\n"
1242 "in vec2 texcoord;\n"
1243 "out vec4 fragColor;\n"
1244 "void main()\n"
1245 "{\n"
1246 " fragColor = vec4(texture(texCube, vec3(texcoord, 1)))/255.0;\n"
1247 "}\n";
1248 }
1249
1250 void testSetUp() override
1251 {
1252 TexCoordDrawTest::testSetUp();
1253 glGenTextures(1, &mTextureCube);
1254 setUpProgram();
1255
1256 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
1257 ASSERT_NE(-1, mTextureCubeUniformLocation);
1258 }
1259
1260 void testTearDown() override
1261 {
1262 glDeleteTextures(1, &mTextureCube);
1263 TexCoordDrawTest::testTearDown();
1264 }
1265
1266 GLuint mTextureCube;
1267 GLint mTextureCubeUniformLocation;
1268};
1269
Anders Leinoe4452442019-05-09 13:29:49 +03001270class TextureCubeIntegerEdgeTestES3 : public TextureCubeIntegerTestES3
1271{
1272 protected:
1273 TextureCubeIntegerEdgeTestES3() : TextureCubeIntegerTestES3() {}
1274
1275 const char *getVertexShaderSource() override
1276 {
1277 return "#version 300 es\n"
1278 "out vec2 texcoord;\n"
1279 "in vec4 position;\n"
1280 "void main()\n"
1281 "{\n"
1282 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1283 " texcoord = position.xy;\n"
1284 "}\n";
1285 }
1286
1287 const char *getFragmentShaderSource() override
1288 {
1289 return "#version 300 es\n"
1290 "precision highp float;\n"
1291 "precision highp usamplerCube;\n"
1292 "uniform usamplerCube texCube;\n"
1293 "in vec2 texcoord;\n"
1294 "out vec4 fragColor;\n"
1295 "void main()\n"
1296 "{\n"
1297 " fragColor = vec4(texture(texCube, vec3(texcoord, 0)))/255.0;\n"
1298 "}\n";
1299 }
1300};
1301
Anders Leino1b6aded2019-05-20 12:56:34 +03001302class Texture2DIntegerProjectiveOffsetTestES3 : public Texture2DTest
1303{
1304 protected:
1305 Texture2DIntegerProjectiveOffsetTestES3() : Texture2DTest() {}
1306
1307 const char *getVertexShaderSource() override
1308 {
1309 return "#version 300 es\n"
1310 "out vec2 texcoord;\n"
1311 "in vec4 position;\n"
1312 "void main()\n"
1313 "{\n"
1314 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1315 " texcoord = 0.5*position.xy + vec2(0.5, 0.5);\n"
1316 "}\n";
1317 }
1318
1319 const char *getFragmentShaderSource() override
1320 {
1321 return "#version 300 es\n"
1322 "precision highp float;\n"
1323 "precision highp usampler2D;\n"
1324 "uniform usampler2D tex;\n"
1325 "in vec2 texcoord;\n"
1326 "out vec4 fragColor;\n"
1327 "void main()\n"
1328 "{\n"
1329 " fragColor = vec4(textureProjOffset(tex, vec3(texcoord, 1), ivec2(0,0), "
1330 "0.0))/255.0;\n"
1331 "}\n";
1332 }
1333};
1334
Anders Leino69d04932019-05-20 14:04:13 +03001335class Texture2DArrayIntegerTestES3 : public Texture2DArrayTestES3
1336{
1337 protected:
1338 Texture2DArrayIntegerTestES3() : Texture2DArrayTestES3() {}
1339
1340 const char *getVertexShaderSource() override
1341 {
1342 return "#version 300 es\n"
1343 "out vec2 texcoord;\n"
1344 "in vec4 position;\n"
1345 "void main()\n"
1346 "{\n"
1347 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1348 " texcoord = (position.xy * 0.5) + 0.5;\n"
1349 "}\n";
1350 }
1351
1352 const char *getFragmentShaderSource() override
1353 {
1354 return "#version 300 es\n"
1355 "precision highp float;\n"
1356 "uniform highp usampler2DArray tex2DArray;\n"
1357 "in vec2 texcoord;\n"
1358 "out vec4 fragColor;\n"
1359 "void main()\n"
1360 "{\n"
1361 " fragColor = vec4(texture(tex2DArray, vec3(texcoord.x, texcoord.y, "
1362 "0.0)))/255.0;\n"
1363 "}\n";
1364 }
1365};
1366
Anders Leino262e2822019-05-20 14:24:40 +03001367class Texture3DIntegerTestES3 : public Texture3DTestES3
1368{
1369 protected:
1370 Texture3DIntegerTestES3() : Texture3DTestES3() {}
1371
1372 const char *getVertexShaderSource() override
1373 {
1374 return "#version 300 es\n"
1375 "out vec2 texcoord;\n"
1376 "in vec4 position;\n"
1377 "void main()\n"
1378 "{\n"
1379 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1380 " texcoord = (position.xy * 0.5) + 0.5;\n"
1381 "}\n";
1382 }
1383
1384 const char *getFragmentShaderSource() override
1385 {
1386 return "#version 300 es\n"
1387 "precision highp float;\n"
1388 "uniform highp usampler3D tex3D;\n"
1389 "in vec2 texcoord;\n"
1390 "out vec4 fragColor;\n"
1391 "void main()\n"
1392 "{\n"
1393 " fragColor = vec4(texture(tex3D, vec3(texcoord, 0.0)))/255.0;\n"
1394 "}\n";
1395 }
1396};
1397
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001398TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001399{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001400 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001401 EXPECT_GL_ERROR(GL_NO_ERROR);
1402
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001403 setUpProgram();
1404
Jamie Madill50cf2be2018-06-15 09:46:57 -04001405 const GLubyte *pixels[20] = {0};
Jamie Madillf67115c2014-04-22 13:14:05 -04001406 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1407 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001408
Jamie Madillb8149072019-04-30 16:14:44 -04001409 if (IsGLExtensionEnabled("GL_EXT_texture_storage"))
Geoff Langc51642b2016-11-14 16:18:26 -05001410 {
1411 // Create a 1-level immutable texture.
1412 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1413
1414 // Try calling sub image on the second level.
1415 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1416 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1417 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001418}
Geoff Langc41e42d2014-04-28 10:58:16 -04001419
John Bauman18319182016-09-28 14:22:27 -07001420// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1421TEST_P(Texture2DTest, QueryBinding)
1422{
1423 glBindTexture(GL_TEXTURE_2D, 0);
1424 EXPECT_GL_ERROR(GL_NO_ERROR);
1425
1426 GLint textureBinding;
1427 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1428 EXPECT_GL_NO_ERROR();
1429 EXPECT_EQ(0, textureBinding);
1430
1431 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
Jamie Madillb8149072019-04-30 16:14:44 -04001432 if (IsGLExtensionEnabled("GL_OES_EGL_image_external") ||
1433 IsGLExtensionEnabled("GL_NV_EGL_stream_consumer_external"))
John Bauman18319182016-09-28 14:22:27 -07001434 {
1435 EXPECT_GL_NO_ERROR();
1436 EXPECT_EQ(0, textureBinding);
1437 }
1438 else
1439 {
1440 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1441 }
1442}
1443
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001444TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001445{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001446 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001447 EXPECT_GL_ERROR(GL_NO_ERROR);
1448
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001449 setUpProgram();
1450
Geoff Langc41e42d2014-04-28 10:58:16 -04001451 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001452 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001453 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001454 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001455
Jamie Madill50cf2be2018-06-15 09:46:57 -04001456 const GLubyte *pixel[4] = {0};
Geoff Langc41e42d2014-04-28 10:58:16 -04001457
1458 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1459 EXPECT_GL_NO_ERROR();
1460
1461 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1462 EXPECT_GL_NO_ERROR();
1463
1464 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1465 EXPECT_GL_NO_ERROR();
1466}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001467
1468// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001469TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001470{
1471 glActiveTexture(GL_TEXTURE0);
1472 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1473 glActiveTexture(GL_TEXTURE1);
1474 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1475 EXPECT_GL_ERROR(GL_NO_ERROR);
1476
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001477 glUseProgram(mProgram);
1478 glUniform1i(mTexture2DUniformLocation, 0);
1479 glUniform1i(mTextureCubeUniformLocation, 1);
1480 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001481 EXPECT_GL_NO_ERROR();
1482}
Jamie Madill9aca0592014-10-06 16:26:59 -04001483
Olli Etuaho53a2da12016-01-11 15:43:32 +02001484// Test drawing with two texture types accessed from the same shader and check that the result of
1485// drawing is correct.
1486TEST_P(TextureCubeTest, CubeMapDraw)
1487{
1488 GLubyte texData[4];
1489 texData[0] = 0;
1490 texData[1] = 60;
1491 texData[2] = 0;
1492 texData[3] = 255;
1493
1494 glActiveTexture(GL_TEXTURE0);
1495 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1496 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1497
1498 glActiveTexture(GL_TEXTURE1);
1499 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1500 texData[1] = 120;
1501 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1502 texData);
1503 EXPECT_GL_ERROR(GL_NO_ERROR);
1504
1505 glUseProgram(mProgram);
1506 glUniform1i(mTexture2DUniformLocation, 0);
1507 glUniform1i(mTextureCubeUniformLocation, 1);
1508 drawQuad(mProgram, "position", 0.5f);
1509 EXPECT_GL_NO_ERROR();
1510
1511 int px = getWindowWidth() - 1;
1512 int py = 0;
1513 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1514}
1515
Olli Etuaho4644a202016-01-12 15:12:53 +02001516TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1517{
1518 glActiveTexture(GL_TEXTURE0);
1519 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1520 GLubyte texData[4];
1521 texData[0] = 0;
1522 texData[1] = 128;
1523 texData[2] = 0;
1524 texData[3] = 255;
1525 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1526 glUseProgram(mProgram);
1527 glUniform1i(mTexture2DUniformLocation, 0);
1528 drawQuad(mProgram, "position", 0.5f);
1529 EXPECT_GL_NO_ERROR();
1530
1531 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1532}
1533
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001534// Test drawing with two textures passed to the shader in a sampler array.
1535TEST_P(SamplerArrayTest, SamplerArrayDraw)
1536{
1537 testSamplerArrayDraw();
1538}
1539
1540// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1541// user-defined function in the shader.
1542TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1543{
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05001544 // TODO: Diagnose and fix. http://anglebug.com/2955
1545 ANGLE_SKIP_TEST_IF(IsVulkan() && IsAndroid());
1546
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001547 testSamplerArrayDraw();
1548}
1549
Jamie Madill9aca0592014-10-06 16:26:59 -04001550// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001551TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001552{
1553 int px = getWindowWidth() / 2;
1554 int py = getWindowHeight() / 2;
1555
1556 glActiveTexture(GL_TEXTURE0);
1557 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1558
Olli Etuahoa314b612016-03-10 16:43:00 +02001559 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001560
Olli Etuahoa314b612016-03-10 16:43:00 +02001561 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001562 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1563 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1564 glGenerateMipmap(GL_TEXTURE_2D);
1565
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001566 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001567 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001568 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1569 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001570 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001571 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001572
Olli Etuahoa314b612016-03-10 16:43:00 +02001573 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001574
Olli Etuahoa314b612016-03-10 16:43:00 +02001575 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1576 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001577 glGenerateMipmap(GL_TEXTURE_2D);
1578
Olli Etuahoa314b612016-03-10 16:43:00 +02001579 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001580
Olli Etuahoa314b612016-03-10 16:43:00 +02001581 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1582 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001583 glGenerateMipmap(GL_TEXTURE_2D);
1584
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001585 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001586
1587 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001588 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001589}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001590
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001591// Test creating a FBO with a cube map render target, to test an ANGLE bug
1592// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001593TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001594{
Michael Spangd8506c72019-01-29 15:35:09 -05001595 // http://anglebug.com/3145
1596 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
1597
Shahbaz Youssefi0c128e12019-03-25 23:50:14 -04001598 // http://anglebug.com/2822
1599 ANGLE_SKIP_TEST_IF(IsWindows() && IsIntel() && IsVulkan());
1600
Jamie Madill3f3b3582018-09-14 10:38:44 -04001601 GLFramebuffer fbo;
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001602 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1603
1604 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Jamie Madill50cf2be2018-06-15 09:46:57 -04001605 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1606 mTextureCube, 0);
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001607
Corentin Wallez322653b2015-06-17 18:33:56 +02001608 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001609 EXPECT_GL_NO_ERROR();
Jamie Madill3f3b3582018-09-14 10:38:44 -04001610
1611 // Test clearing the six mip faces individually.
1612 std::array<GLColor, 6> faceColors = {{GLColor::red, GLColor::green, GLColor::blue,
1613 GLColor::yellow, GLColor::cyan, GLColor::magenta}};
1614
1615 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1616 {
1617 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1618 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1619
1620 Vector4 clearColorF = faceColors[faceIndex].toNormalizedVector();
1621 glClearColor(clearColorF.x(), clearColorF.y(), clearColorF.z(), clearColorF.w());
1622 glClear(GL_COLOR_BUFFER_BIT);
1623
1624 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex]);
1625 }
1626
1627 // Iterate the faces again to make sure the colors haven't changed.
1628 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1629 {
1630 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1631 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1632 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex])
1633 << "face color " << faceIndex << " shouldn't change";
1634 }
1635}
1636
1637// Tests clearing a cube map with a scissor enabled.
1638TEST_P(TextureCubeTest, CubeMapFBOScissoredClear)
1639{
1640 // TODO(jie.a.chen): Diagnose and fix. http://anglebug.com/2822
1641 ANGLE_SKIP_TEST_IF(IsVulkan() && IsIntel() && IsWindows());
1642
Michael Spangd8506c72019-01-29 15:35:09 -05001643 // http://anglebug.com/3145
1644 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
1645
Jamie Madill3f3b3582018-09-14 10:38:44 -04001646 constexpr size_t kSize = 16;
1647
1648 GLFramebuffer fbo;
1649 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1650 glViewport(0, 0, kSize, kSize);
1651
1652 GLTexture texcube;
1653 glBindTexture(GL_TEXTURE_CUBE_MAP, texcube);
1654 for (GLenum face = 0; face < 6; face++)
1655 {
1656 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA,
1657 GL_UNSIGNED_BYTE, nullptr);
1658 }
1659 ASSERT_GL_NO_ERROR();
1660
1661 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1662 texcube, 0);
1663
1664 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1665 ASSERT_GL_NO_ERROR();
1666
1667 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1668 glClear(GL_COLOR_BUFFER_BIT);
1669 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1670
1671 glEnable(GL_SCISSOR_TEST);
1672 glScissor(kSize / 2, 0, kSize / 2, kSize);
1673 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
1674 glClear(GL_COLOR_BUFFER_BIT);
1675
1676 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1677 EXPECT_PIXEL_COLOR_EQ(kSize / 2 + 1, 0, GLColor::green);
1678
1679 ASSERT_GL_NO_ERROR();
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001680}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001681
Jamie Madill50cf2be2018-06-15 09:46:57 -04001682// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a
1683// default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001684TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001685{
Jamie Madillb8149072019-04-30 16:14:44 -04001686 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 &&
1687 !IsGLExtensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -04001688
Jamie Madill50cf2be2018-06-15 09:46:57 -04001689 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001690 int height = getWindowHeight();
1691
1692 GLuint tex2D;
1693 glGenTextures(1, &tex2D);
1694 glActiveTexture(GL_TEXTURE0);
1695 glBindTexture(GL_TEXTURE_2D, tex2D);
1696
1697 // Fill with red
1698 std::vector<GLubyte> pixels(3 * 16 * 16);
1699 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1700 {
1701 pixels[pixelId * 3 + 0] = 255;
1702 pixels[pixelId * 3 + 1] = 0;
1703 pixels[pixelId * 3 + 2] = 0;
1704 }
1705
1706 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001707 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1708 // 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 -04001709 if (getClientMajorVersion() >= 3)
1710 {
1711 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1712 }
1713 else
1714 {
1715 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1716 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001717
1718 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1719 // glTexSubImage2D should take into account that the image is dirty.
1720 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1721 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1722 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1723
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001724 setUpProgram();
1725
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001726 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001727 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001728 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001729 glDeleteTextures(1, &tex2D);
1730 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001731 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001732
1733 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001734 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1735 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001736}
1737
Jamie Madill50cf2be2018-06-15 09:46:57 -04001738// Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has
1739// initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001740TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001741{
Jamie Madillb8149072019-04-30 16:14:44 -04001742 if (IsGLExtensionEnabled("NV_pixel_buffer_object"))
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001743 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04001744 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001745 int height = getWindowHeight();
1746
1747 GLuint tex2D;
1748 glGenTextures(1, &tex2D);
1749 glActiveTexture(GL_TEXTURE0);
1750 glBindTexture(GL_TEXTURE_2D, tex2D);
1751
1752 // Fill with red
1753 std::vector<GLubyte> pixels(3 * 16 * 16);
1754 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1755 {
1756 pixels[pixelId * 3 + 0] = 255;
1757 pixels[pixelId * 3 + 1] = 0;
1758 pixels[pixelId * 3 + 2] = 0;
1759 }
1760
1761 // Read 16x16 region from red backbuffer to PBO
1762 GLuint pbo;
1763 glGenBuffers(1, &pbo);
1764 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1765 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1766
1767 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001768 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1769 // 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 +00001770 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1771
1772 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1773 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001774 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 +00001775 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1776 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1777
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001778 setUpProgram();
1779
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001780 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001781 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001782 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001783 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001784 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001785 EXPECT_GL_NO_ERROR();
1786 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1787 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1788 }
1789}
Jamie Madillbc393df2015-01-29 13:46:07 -05001790
Mohan Maiya6caa2652019-09-11 08:06:13 -07001791// Tests CopySubImage for float formats
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001792TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001793{
1794 testFloatCopySubImage(1, 1);
1795}
1796
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001797TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001798{
1799 testFloatCopySubImage(2, 1);
1800}
1801
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001802TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001803{
1804 testFloatCopySubImage(2, 2);
1805}
1806
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001807TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001808{
1809 testFloatCopySubImage(3, 1);
1810}
1811
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001812TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001813{
1814 testFloatCopySubImage(3, 2);
1815}
1816
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001817TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001818{
Yunchao He9550c602018-02-13 14:47:05 +08001819 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
Mohan Maiya6caa2652019-09-11 08:06:13 -07001820 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001821
Yunchao He9550c602018-02-13 14:47:05 +08001822 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1823 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001824
Jamie Madillbc393df2015-01-29 13:46:07 -05001825 testFloatCopySubImage(3, 3);
1826}
1827
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001828TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001829{
1830 testFloatCopySubImage(4, 1);
1831}
1832
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001833TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001834{
1835 testFloatCopySubImage(4, 2);
1836}
1837
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001838TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001839{
Yunchao He9550c602018-02-13 14:47:05 +08001840 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1841 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001842
Jamie Madillbc393df2015-01-29 13:46:07 -05001843 testFloatCopySubImage(4, 3);
1844}
1845
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001846TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001847{
Yunchao He9550c602018-02-13 14:47:05 +08001848 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1849 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001850
Jamie Madillbc393df2015-01-29 13:46:07 -05001851 testFloatCopySubImage(4, 4);
1852}
Austin Kinross07285142015-03-26 11:36:16 -07001853
Jamie Madill50cf2be2018-06-15 09:46:57 -04001854// Port of
1855// https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1856// Run against GL_ALPHA/UNSIGNED_BYTE format, to ensure that D3D11 Feature Level 9_3 correctly
1857// handles GL_ALPHA
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001858TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001859{
1860 const int npotTexSize = 5;
Jamie Madill50cf2be2018-06-15 09:46:57 -04001861 const int potTexSize = 4; // Should be less than npotTexSize
Austin Kinross07285142015-03-26 11:36:16 -07001862 GLuint tex2D;
1863
Jamie Madillb8149072019-04-30 16:14:44 -04001864 if (IsGLExtensionEnabled("GL_OES_texture_npot"))
Austin Kinross07285142015-03-26 11:36:16 -07001865 {
1866 // This test isn't applicable if texture_npot is enabled
1867 return;
1868 }
1869
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001870 setUpProgram();
1871
Austin Kinross07285142015-03-26 11:36:16 -07001872 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1873
Austin Kinross5faa15b2016-01-11 13:32:48 -08001874 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1875 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1876
Austin Kinross07285142015-03-26 11:36:16 -07001877 glActiveTexture(GL_TEXTURE0);
1878 glGenTextures(1, &tex2D);
1879 glBindTexture(GL_TEXTURE_2D, tex2D);
1880
Till Rathmannc1551dc2018-08-15 17:04:49 +02001881 const std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize, 64);
Austin Kinross07285142015-03-26 11:36:16 -07001882
1883 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1884 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1885
1886 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
Jamie Madill50cf2be2018-06-15 09:46:57 -04001887 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1888 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001889 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1890
1891 // Check that an NPOT texture on level 0 succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001892 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1893 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001894 EXPECT_GL_NO_ERROR();
1895
1896 // Check that generateMipmap fails on NPOT
1897 glGenerateMipmap(GL_TEXTURE_2D);
1898 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1899
1900 // Check that nothing is drawn if filtering is not correct for NPOT
1901 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1902 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1903 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1904 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1905 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001906 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001907 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1908
1909 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1910 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1911 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1912 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1913 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001914 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001915 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1916
1917 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1918 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1919 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001920 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001921 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1922
1923 // Check that glTexImage2D for POT texture succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001924 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE,
1925 pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001926 EXPECT_GL_NO_ERROR();
1927
1928 // Check that generateMipmap for an POT texture succeeds
1929 glGenerateMipmap(GL_TEXTURE_2D);
1930 EXPECT_GL_NO_ERROR();
1931
1932 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1933 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1934 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1935 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1936 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1937 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001938 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001939 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1940 EXPECT_GL_NO_ERROR();
1941}
Jamie Madillfa05f602015-05-07 13:47:11 -04001942
Austin Kinross08528e12015-10-07 16:24:40 -07001943// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1944// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001945TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001946{
1947 glActiveTexture(GL_TEXTURE0);
1948 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1949
1950 // Create an 8x8 (i.e. power-of-two) texture.
1951 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1952 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1953 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1954 glGenerateMipmap(GL_TEXTURE_2D);
1955
1956 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1957 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001958 std::array<GLColor, 3 * 3> data;
1959 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001960
1961 EXPECT_GL_NO_ERROR();
1962}
1963
Geoff Lang3702d8c2019-04-08 13:44:06 -04001964// Regression test for http://crbug.com/949985 to make sure dirty bits are propagated up from
1965// TextureImpl and the texture is synced before being used in a draw call.
1966TEST_P(Texture2DTestES3, TextureImplPropogatesDirtyBits)
1967{
1968 ANGLE_SKIP_TEST_IF(IsIntel() && IsOpenGL());
Yuly Novikove6b23e42019-04-10 17:19:15 -04001969 // Flaky hangs on Win10 AMD RX 550 GL. http://anglebug.com/3371
1970 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsOpenGL());
Yuly Novikovbd4ff472019-07-19 22:08:17 +00001971 // D3D Debug device reports an error. http://anglebug.com/3501
1972 ANGLE_SKIP_TEST_IF(IsWindows() && IsD3D11());
Cody Northrop988f7172019-09-30 15:52:37 -06001973 // TODO(cnorthrop): Needs triage on Vulkan backend. http://anglebug.com/3950
Cody Northropcb16fb52019-08-29 16:53:55 -06001974 ANGLE_SKIP_TEST_IF(IsVulkan());
Geoff Lang3702d8c2019-04-08 13:44:06 -04001975
1976 // The workaround in the GL backend required to trigger this bug generates driver warning
1977 // messages.
1978 ScopedIgnorePlatformMessages ignoreMessages;
1979
1980 setUpProgram();
1981 glUseProgram(mProgram);
1982 glActiveTexture(GL_TEXTURE0 + mTexture2DUniformLocation);
1983
1984 GLTexture dest;
1985 glBindTexture(GL_TEXTURE_2D, dest);
1986
1987 GLTexture source;
1988 glBindTexture(GL_TEXTURE_2D, source);
1989
1990 // Put data in mip 0 and 1
1991 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1992 GLColor::red.data());
1993 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1994 GLColor::green.data());
1995
1996 // Disable mipmapping so source is complete
1997 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1998 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1999
2000 // Force the dirty bits to be synchronized in source
2001 drawQuad(mProgram, "position", 1.0f);
2002
2003 // Copy from mip 1 of the source. In the GL backend this internally sets the base level to mip
2004 // 1 and sets a dirty bit.
2005 glCopyTextureCHROMIUM(source, 1, GL_TEXTURE_2D, dest, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_FALSE,
2006 GL_FALSE, GL_FALSE);
2007
2008 // Draw again, assertions are generated if the texture has internal dirty bits at draw time
2009 drawQuad(mProgram, "position", 1.0f);
2010}
2011
Geoff Lang6f691fb2019-04-25 11:01:52 -04002012// This test case changes the base level of a texture that's attached to a framebuffer, clears every
2013// level to green, and then samples the texture when rendering. Test is taken from
2014// https://www.khronos.org/registry/webgl/sdk/tests/conformance2/rendering/framebuffer-texture-changing-base-level.html
2015TEST_P(Texture2DTestES3, FramebufferTextureChangingBaselevel)
2016{
2017 // TODO(geofflang): Investigate on D3D11. http://anglebug.com/2291
2018 ANGLE_SKIP_TEST_IF(IsD3D11());
2019
Cody Northropd192e932019-09-27 10:27:10 -06002020 // TODO(cnorthrop): Failing on Vulkan/Windows/AMD. http://anglebug.com/3996
2021 ANGLE_SKIP_TEST_IF(IsVulkan() && IsWindows() && IsAMD());
Cody Northropcb16fb52019-08-29 16:53:55 -06002022
Geoff Lang6f691fb2019-04-25 11:01:52 -04002023 setUpProgram();
2024
2025 constexpr GLint width = 8;
2026 constexpr GLint height = 4;
2027
2028 GLTexture texture;
2029 glBindTexture(GL_TEXTURE_2D, texture);
2030 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2031 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2032 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2033 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2034
2035 // Create all mipmap levels for the texture from level 0 to the 1x1 pixel level.
2036 GLint level = 0;
2037 GLint levelW = width;
2038 GLint levelH = height;
2039 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, levelW, levelH, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2040 nullptr);
2041 while (levelW > 1 || levelH > 1)
2042 {
2043 ++level;
2044 levelW = static_cast<GLint>(std::max(1.0, std::floor(width / std::pow(2, level))));
2045 levelH = static_cast<GLint>(std::max(1.0, std::floor(height / std::pow(2, level))));
2046 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, levelW, levelH, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2047 nullptr);
2048 }
2049
2050 // Clear each level of the texture using an FBO. Change the base level to match the level used
2051 // for the FBO on each iteration.
2052 GLFramebuffer fbo;
2053 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
2054 level = 0;
2055 levelW = width;
2056 levelH = height;
2057 while (levelW > 1 || levelH > 1)
2058 {
2059 levelW = static_cast<GLint>(std::floor(width / std::pow(2, level)));
2060 levelH = static_cast<GLint>(std::floor(height / std::pow(2, level)));
2061
2062 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, level);
2063 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, level);
2064
2065 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2066 EXPECT_GL_NO_ERROR();
2067
2068 glClearColor(0, 1, 0, 1);
2069 glClear(GL_COLOR_BUFFER_BIT);
2070
2071 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2072
2073 ++level;
2074 }
2075
2076 glBindFramebuffer(GL_FRAMEBUFFER, 0);
2077 glViewport(0, 0, 16, 16);
2078 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2079
2080 drawQuad(mProgram, "position", 0.5f);
2081
2082 EXPECT_GL_NO_ERROR();
2083 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2084}
2085
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002086// Test to check that texture completeness is determined correctly when the texture base level is
2087// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
2088TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
2089{
2090 glActiveTexture(GL_TEXTURE0);
2091 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02002092
2093 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
2094 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
2095 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2096 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2097 texDataGreen.data());
2098 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2099 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002100 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2101 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2102 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2103
2104 EXPECT_GL_NO_ERROR();
2105
2106 drawQuad(mProgram, "position", 0.5f);
2107
Olli Etuahoa314b612016-03-10 16:43:00 +02002108 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2109}
2110
2111// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2112// have images defined.
2113TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
2114{
Yunchao He9550c602018-02-13 14:47:05 +08002115 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
2116 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
2117
Olli Etuahoa314b612016-03-10 16:43:00 +02002118 glActiveTexture(GL_TEXTURE0);
2119 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2120 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2121 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2122 texDataGreen.data());
2123 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2124 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2125 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2126 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2127
2128 EXPECT_GL_NO_ERROR();
2129
2130 drawQuad(mProgram, "position", 0.5f);
2131
2132 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2133}
2134
Olli Etuahoe8528d82016-05-16 17:50:52 +03002135// Test that drawing works correctly when level 0 is undefined and base level is 1.
2136TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
2137{
Yunchao He9550c602018-02-13 14:47:05 +08002138 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
2139 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
2140
Olli Etuahoe8528d82016-05-16 17:50:52 +03002141 glActiveTexture(GL_TEXTURE0);
2142 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2143 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2144 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2145 texDataGreen.data());
2146 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2147 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2148 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2149 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2150
2151 EXPECT_GL_NO_ERROR();
2152
2153 // Texture is incomplete.
2154 drawQuad(mProgram, "position", 0.5f);
2155 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2156
2157 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2158 texDataGreen.data());
2159
2160 // Texture is now complete.
2161 drawQuad(mProgram, "position", 0.5f);
2162 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2163}
2164
Olli Etuahoa314b612016-03-10 16:43:00 +02002165// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2166// dimensions that don't fit the images inside the range.
2167// GLES 3.0.4 section 3.8.13 Texture completeness
2168TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2169{
Olli Etuahoa314b612016-03-10 16:43:00 +02002170 glActiveTexture(GL_TEXTURE0);
2171 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2172 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
2173 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2174 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
2175
2176 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2177 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2178
2179 // Two levels that are initially unused.
2180 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
2181 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2182 texDataCyan.data());
2183
2184 // One level that is used - only this level should affect completeness.
2185 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2186 texDataGreen.data());
2187
2188 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2189 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2190
2191 EXPECT_GL_NO_ERROR();
2192
2193 drawQuad(mProgram, "position", 0.5f);
2194
2195 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2196
Yunchao He2f23f352018-02-11 22:11:37 +08002197 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02002198
2199 // Switch the level that is being used to the cyan level 2.
2200 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2201 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2202
2203 EXPECT_GL_NO_ERROR();
2204
2205 drawQuad(mProgram, "position", 0.5f);
2206
2207 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2208}
2209
2210// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2211// have images defined.
2212TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
2213{
Olli Etuahoa314b612016-03-10 16:43:00 +02002214 glActiveTexture(GL_TEXTURE0);
2215 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2216 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2217 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2218 texDataGreen.data());
2219 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2220 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2221 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
2222 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2223
2224 EXPECT_GL_NO_ERROR();
2225
2226 drawQuad(mProgram, "position", 0.5f);
2227
2228 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2229}
2230
2231// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2232// dimensions that don't fit the images inside the range.
2233// GLES 3.0.4 section 3.8.13 Texture completeness
2234TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2235{
Yuly Novikovc5da7992019-06-27 12:57:13 -04002236 // Crashes on Intel Ubuntu 19.04 Mesa 19.0.2 GL. http://anglebug.com/2782
2237 ANGLE_SKIP_TEST_IF(IsLinux() && IsIntel() && IsDesktopOpenGL());
2238
Olli Etuahoa314b612016-03-10 16:43:00 +02002239 glActiveTexture(GL_TEXTURE0);
2240 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2241 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2242 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2243 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2244
2245 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2246 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2247
2248 // Two levels that are initially unused.
2249 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2250 texDataRed.data());
2251 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2252 texDataCyan.data());
2253
2254 // One level that is used - only this level should affect completeness.
2255 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2256 texDataGreen.data());
2257
2258 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
2259 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2260
2261 EXPECT_GL_NO_ERROR();
2262
2263 drawQuad(mProgram, "position", 0.5f);
2264
2265 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2266
Yunchao He2f23f352018-02-11 22:11:37 +08002267 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02002268
2269 // Switch the level that is being used to the cyan level 2.
2270 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
2271 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
2272
2273 EXPECT_GL_NO_ERROR();
2274
2275 drawQuad(mProgram, "position", 0.5f);
2276
2277 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2278}
2279
2280// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2281// have images defined.
2282TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
2283{
Olli Etuahoa314b612016-03-10 16:43:00 +02002284 glActiveTexture(GL_TEXTURE0);
2285 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
2286 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2287 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2288 texDataGreen.data());
2289 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2290 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2291 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2292 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2293
2294 EXPECT_GL_NO_ERROR();
2295
2296 drawQuad(mProgram, "position", 0.5f);
2297
2298 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2299}
2300
2301// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2302// dimensions that don't fit the images inside the range.
2303// GLES 3.0.4 section 3.8.13 Texture completeness
2304TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2305{
Corentin Wallez566c2e32019-08-28 18:37:58 +02002306 // TODO(crbug.com/998505): Test failing on Android FYI Release (NVIDIA Shield TV)
2307 ANGLE_SKIP_TEST_IF(IsNVIDIAShield());
2308
Olli Etuahoa314b612016-03-10 16:43:00 +02002309 glActiveTexture(GL_TEXTURE0);
2310 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
2311 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2312 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2313 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2314
2315 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2316 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2317
2318 // Two levels that are initially unused.
2319 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2320 texDataRed.data());
2321 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2322 texDataCyan.data());
2323
2324 // One level that is used - only this level should affect completeness.
2325 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2326 texDataGreen.data());
2327
2328 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2329 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2330
2331 EXPECT_GL_NO_ERROR();
2332
2333 drawQuad(mProgram, "position", 0.5f);
2334
2335 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2336
Yunchao He2f23f352018-02-11 22:11:37 +08002337 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
2338
Olli Etuahoa314b612016-03-10 16:43:00 +02002339 // Switch the level that is being used to the cyan level 2.
2340 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2341 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2342
2343 EXPECT_GL_NO_ERROR();
2344
2345 drawQuad(mProgram, "position", 0.5f);
2346
2347 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2348}
2349
2350// Test that texture completeness is updated if texture max level changes.
2351// GLES 3.0.4 section 3.8.13 Texture completeness
2352TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2353{
Olli Etuahoa314b612016-03-10 16:43:00 +02002354 glActiveTexture(GL_TEXTURE0);
2355 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2356 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2357
2358 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2359 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2360
2361 // A level that is initially unused.
2362 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2363 texDataGreen.data());
2364
2365 // One level that is initially used - only this level should affect completeness.
2366 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2367 texDataGreen.data());
2368
2369 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2370 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2371
2372 EXPECT_GL_NO_ERROR();
2373
2374 drawQuad(mProgram, "position", 0.5f);
2375
2376 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2377
2378 // Switch the max level to level 1. The levels within the used range now have inconsistent
2379 // dimensions and the texture should be incomplete.
2380 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2381
2382 EXPECT_GL_NO_ERROR();
2383
2384 drawQuad(mProgram, "position", 0.5f);
2385
2386 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2387}
2388
2389// Test that 3D texture completeness is updated if texture max level changes.
2390// GLES 3.0.4 section 3.8.13 Texture completeness
2391TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2392{
Olli Etuahoa314b612016-03-10 16:43:00 +02002393 glActiveTexture(GL_TEXTURE0);
2394 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2395 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2396
2397 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2398 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2399
2400 // A level that is initially unused.
2401 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2402 texDataGreen.data());
2403
2404 // One level that is initially used - only this level should affect completeness.
2405 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2406 texDataGreen.data());
2407
2408 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2409 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2410
2411 EXPECT_GL_NO_ERROR();
2412
2413 drawQuad(mProgram, "position", 0.5f);
2414
2415 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2416
2417 // Switch the max level to level 1. The levels within the used range now have inconsistent
2418 // dimensions and the texture should be incomplete.
2419 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2420
2421 EXPECT_GL_NO_ERROR();
2422
2423 drawQuad(mProgram, "position", 0.5f);
2424
2425 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2426}
2427
2428// Test that texture completeness is updated if texture base level changes.
2429// GLES 3.0.4 section 3.8.13 Texture completeness
2430TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2431{
Olli Etuahoa314b612016-03-10 16:43:00 +02002432 glActiveTexture(GL_TEXTURE0);
2433 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2434 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2435
2436 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2437 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2438
2439 // Two levels that are initially unused.
2440 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2441 texDataGreen.data());
2442 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2443 texDataGreen.data());
2444
2445 // One level that is initially used - only this level should affect completeness.
2446 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2447 texDataGreen.data());
2448
2449 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2450 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2451
2452 EXPECT_GL_NO_ERROR();
2453
2454 drawQuad(mProgram, "position", 0.5f);
2455
2456 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2457
2458 // Switch the base level to level 1. The levels within the used range now have inconsistent
2459 // dimensions and the texture should be incomplete.
2460 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2461
2462 EXPECT_GL_NO_ERROR();
2463
2464 drawQuad(mProgram, "position", 0.5f);
2465
2466 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2467}
2468
2469// Test that texture is not complete if base level is greater than max level.
2470// GLES 3.0.4 section 3.8.13 Texture completeness
2471TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2472{
Olli Etuahoa314b612016-03-10 16:43:00 +02002473 glActiveTexture(GL_TEXTURE0);
2474 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2475
2476 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2477 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2478
2479 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2480
2481 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2482 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2483
2484 EXPECT_GL_NO_ERROR();
2485
2486 drawQuad(mProgram, "position", 0.5f);
2487
2488 // Texture should be incomplete.
2489 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2490}
2491
2492// Test that immutable texture base level and max level are clamped.
2493// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2494TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2495{
Olli Etuahoa314b612016-03-10 16:43:00 +02002496 glActiveTexture(GL_TEXTURE0);
2497 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2498
2499 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2500 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2501
2502 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2503
2504 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2505
2506 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2507 // should be clamped to [base_level, levels - 1].
2508 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2509 // In the case of this test, those rules make the effective base level and max level 0.
2510 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2511 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2512
2513 EXPECT_GL_NO_ERROR();
2514
2515 drawQuad(mProgram, "position", 0.5f);
2516
2517 // Texture should be complete.
2518 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2519}
2520
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002521// Test that changing base level works when it affects the format of the texture.
2522TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2523{
Corentin Wallez7f00d332019-08-28 15:19:16 +02002524 // TODO(crbug.com/998505): Test failing on Android FYI Release (NVIDIA Shield TV)
2525 ANGLE_SKIP_TEST_IF(IsNVIDIAShield());
2526
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002527 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002528
2529 // Observed incorrect rendering on AMD OpenGL.
2530 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002531
2532 glActiveTexture(GL_TEXTURE0);
2533 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2534 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2535 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2536
2537 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2538 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2539
2540 // RGBA8 level that's initially unused.
2541 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2542 texDataCyan.data());
2543
2544 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2545 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2546
2547 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2548 // format. It reads green channel data from the green and alpha channels of texDataGreen
2549 // (this is a bit hacky but works).
2550 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2551
2552 EXPECT_GL_NO_ERROR();
2553
2554 drawQuad(mProgram, "position", 0.5f);
2555
2556 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2557
2558 // Switch the texture to use the cyan level 0 with the RGBA format.
2559 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2560 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2561
2562 EXPECT_GL_NO_ERROR();
2563
2564 drawQuad(mProgram, "position", 0.5f);
2565
2566 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2567}
2568
Olli Etuahoa314b612016-03-10 16:43:00 +02002569// Test that setting a texture image works when base level is out of range.
2570TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2571{
2572 glActiveTexture(GL_TEXTURE0);
2573 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2574
2575 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2576 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2577
2578 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2579 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2580
2581 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2582
2583 EXPECT_GL_NO_ERROR();
2584
2585 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2586
2587 drawQuad(mProgram, "position", 0.5f);
2588
2589 // Texture should be complete.
2590 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002591}
2592
Jamie Madill50cf2be2018-06-15 09:46:57 -04002593// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG
2594// RBA->RGBA8, with 1.0 in the alpha channel. This test covers a bug where redefining array textures
2595// with these formats does not work as expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002596TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002597{
2598 std::vector<GLubyte> pixelData;
2599 for (size_t count = 0; count < 5000; count++)
2600 {
2601 pixelData.push_back(0u);
2602 pixelData.push_back(255u);
2603 pixelData.push_back(0u);
2604 }
2605
2606 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002607 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002608 glUniform1i(mTextureArrayLocation, 0);
2609
2610 // The first draw worked correctly.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002611 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2612 &pixelData[0]);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002613
2614 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2615 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2616 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2617 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002618 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002619 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002620
2621 // The dimension of the respecification must match the original exactly to trigger the bug.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002622 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2623 &pixelData[0]);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002624 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002625 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002626
2627 ASSERT_GL_NO_ERROR();
2628}
2629
Olli Etuaho1a679902016-01-14 12:21:47 +02002630// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2631// This test is needed especially to confirm that sampler registers get assigned correctly on
2632// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2633TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2634{
2635 glActiveTexture(GL_TEXTURE0);
2636 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2637 GLubyte texData[4];
2638 texData[0] = 0;
2639 texData[1] = 60;
2640 texData[2] = 0;
2641 texData[3] = 255;
2642 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2643
2644 glActiveTexture(GL_TEXTURE1);
2645 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2646 GLfloat depthTexData[1];
2647 depthTexData[0] = 0.5f;
2648 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2649 depthTexData);
2650
2651 glUseProgram(mProgram);
2652 glUniform1f(mDepthRefUniformLocation, 0.3f);
2653 glUniform1i(mTexture3DUniformLocation, 0);
2654 glUniform1i(mTextureShadowUniformLocation, 1);
2655
2656 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2657 drawQuad(mProgram, "position", 0.5f);
2658 EXPECT_GL_NO_ERROR();
2659 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2660 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2661
2662 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2663 drawQuad(mProgram, "position", 0.5f);
2664 EXPECT_GL_NO_ERROR();
2665 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2666 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2667}
2668
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002669// Test multiple different sampler types in the same shader.
2670// This test makes sure that even if sampler / texture registers get grouped together based on type
2671// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2672// still has the right register index information for each ESSL sampler.
2673// The tested ESSL samplers have the following types in D3D11 HLSL:
2674// sampler2D: Texture2D + SamplerState
2675// samplerCube: TextureCube + SamplerState
2676// sampler2DShadow: Texture2D + SamplerComparisonState
2677// samplerCubeShadow: TextureCube + SamplerComparisonState
2678TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2679{
2680 glActiveTexture(GL_TEXTURE0);
2681 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2682 GLubyte texData[4];
2683 texData[0] = 0;
2684 texData[1] = 0;
2685 texData[2] = 120;
2686 texData[3] = 255;
2687 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2688
2689 glActiveTexture(GL_TEXTURE1);
2690 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2691 texData[0] = 0;
2692 texData[1] = 90;
2693 texData[2] = 0;
2694 texData[3] = 255;
2695 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2696 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2697 texData);
2698
2699 glActiveTexture(GL_TEXTURE2);
2700 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2701 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2702 GLfloat depthTexData[1];
2703 depthTexData[0] = 0.5f;
2704 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2705 depthTexData);
2706
2707 glActiveTexture(GL_TEXTURE3);
2708 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2709 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2710 depthTexData[0] = 0.2f;
2711 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2712 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2713 depthTexData);
2714
Tobin Ehlisbbf0ce22019-10-11 06:55:36 -06002715 // http://anglebug.com/3949: TODO: Add a DS texture case
2716
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002717 EXPECT_GL_NO_ERROR();
2718
2719 glUseProgram(mProgram);
2720 glUniform1f(mDepthRefUniformLocation, 0.3f);
2721 glUniform1i(mTexture2DUniformLocation, 0);
2722 glUniform1i(mTextureCubeUniformLocation, 1);
2723 glUniform1i(mTexture2DShadowUniformLocation, 2);
2724 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2725
2726 drawQuad(mProgram, "position", 0.5f);
2727 EXPECT_GL_NO_ERROR();
2728 // The shader writes:
2729 // <texture 2d color> +
2730 // <cube map color> +
2731 // 0.25 * <comparison result (1.0)> +
2732 // 0.125 * <comparison result (0.0)>
2733 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2734}
2735
Olli Etuahobce743a2016-01-15 17:18:28 +02002736// Test different base levels on textures accessed through the same sampler array.
2737// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2738TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2739{
Yunchao He9550c602018-02-13 14:47:05 +08002740 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2741
Olli Etuahobce743a2016-01-15 17:18:28 +02002742 glActiveTexture(GL_TEXTURE0);
2743 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2744 GLsizei size = 64;
2745 for (GLint level = 0; level < 7; ++level)
2746 {
2747 ASSERT_LT(0, size);
2748 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2749 nullptr);
2750 size = size / 2;
2751 }
2752 ASSERT_EQ(0, size);
2753 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2754
2755 glActiveTexture(GL_TEXTURE1);
2756 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2757 size = 128;
2758 for (GLint level = 0; level < 8; ++level)
2759 {
2760 ASSERT_LT(0, size);
2761 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2762 nullptr);
2763 size = size / 2;
2764 }
2765 ASSERT_EQ(0, size);
2766 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2767 EXPECT_GL_NO_ERROR();
2768
2769 glUseProgram(mProgram);
2770 glUniform1i(mTexture0Location, 0);
2771 glUniform1i(mTexture1Location, 1);
2772
Olli Etuaho5804dc82018-04-13 14:11:46 +03002773 drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
Olli Etuahobce743a2016-01-15 17:18:28 +02002774 EXPECT_GL_NO_ERROR();
2775 // Red channel: width of level 1 of texture A: 32.
2776 // Green channel: width of level 3 of texture B: 16.
2777 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2778}
2779
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002780// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2781// ES 3.0.4 table 3.24
2782TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2783{
2784 glActiveTexture(GL_TEXTURE0);
2785 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2786 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2787 EXPECT_GL_NO_ERROR();
2788
2789 drawQuad(mProgram, "position", 0.5f);
2790
2791 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2792}
2793
2794// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2795// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002796TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002797{
Luc Ferron5164b792018-03-06 09:10:12 -05002798 setUpProgram();
2799
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002800 glActiveTexture(GL_TEXTURE0);
2801 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2802 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2803 EXPECT_GL_NO_ERROR();
2804
2805 drawQuad(mProgram, "position", 0.5f);
2806
2807 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2808}
2809
Luc Ferron5164b792018-03-06 09:10:12 -05002810// Validate that every component of the pixel will be equal to the luminance value we've set
2811// and that the alpha channel will be 1 (or 255 to be exact).
2812TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2813{
2814 setUpProgram();
2815
2816 glActiveTexture(GL_TEXTURE0);
2817 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2818 uint8_t pixel = 50;
2819 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2820 EXPECT_GL_NO_ERROR();
2821
2822 drawQuad(mProgram, "position", 0.5f);
2823
2824 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2825}
2826
2827// Validate that every component of the pixel will be equal to the luminance value we've set
2828// and that the alpha channel will be the second component.
2829TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2830{
2831 setUpProgram();
2832
2833 glActiveTexture(GL_TEXTURE0);
2834 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2835 uint8_t pixel[] = {50, 25};
2836 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2837 GL_UNSIGNED_BYTE, pixel);
2838 EXPECT_GL_NO_ERROR();
2839
2840 drawQuad(mProgram, "position", 0.5f);
2841
2842 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2843}
2844
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002845// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2846// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002847TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002848{
Jamie Madillb8149072019-04-30 16:14:44 -04002849 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002850 ANGLE_SKIP_TEST_IF(IsD3D9());
2851 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002852
2853 setUpProgram();
2854
Luc Ferrond8c632c2018-04-10 12:31:44 -04002855 glActiveTexture(GL_TEXTURE0);
2856 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2857 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2858 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002859
Luc Ferrond8c632c2018-04-10 12:31:44 -04002860 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002861
Luc Ferrond8c632c2018-04-10 12:31:44 -04002862 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002863}
2864
2865// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2866// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002867TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002868{
Jamie Madillb8149072019-04-30 16:14:44 -04002869 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002870 ANGLE_SKIP_TEST_IF(IsD3D9());
2871 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferrond8c632c2018-04-10 12:31:44 -04002872 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2873 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002874
Luc Ferrond8c632c2018-04-10 12:31:44 -04002875 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002876
Luc Ferrond8c632c2018-04-10 12:31:44 -04002877 glActiveTexture(GL_TEXTURE0);
2878 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2879 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2880 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002881
Luc Ferrond8c632c2018-04-10 12:31:44 -04002882 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002883
Luc Ferrond8c632c2018-04-10 12:31:44 -04002884 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002885}
2886
2887// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2888// ES 3.0.4 table 3.24
2889TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2890{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002891 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2892
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002893 glActiveTexture(GL_TEXTURE0);
2894 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2895 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2896 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2897 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2898 EXPECT_GL_NO_ERROR();
2899
2900 drawQuad(mProgram, "position", 0.5f);
2901
2902 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2903}
2904
2905// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2906// ES 3.0.4 table 3.24
2907TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2908{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002909 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2910
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002911 glActiveTexture(GL_TEXTURE0);
2912 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2913
2914 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2915 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2916 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2917 EXPECT_GL_NO_ERROR();
2918
2919 drawQuad(mProgram, "position", 0.5f);
2920
2921 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2922}
2923
2924// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2925// ES 3.0.4 table 3.24
2926TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2927{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002928 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2929
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002930 glActiveTexture(GL_TEXTURE0);
2931 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2932 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2933 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2934 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2935 EXPECT_GL_NO_ERROR();
2936
2937 drawQuad(mProgram, "position", 0.5f);
2938
2939 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2940}
2941
2942// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2943// ES 3.0.4 table 3.24
2944TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2945{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002946 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2947
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002948 glActiveTexture(GL_TEXTURE0);
2949 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2950 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2951 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2952 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2953 EXPECT_GL_NO_ERROR();
2954
2955 drawQuad(mProgram, "position", 0.5f);
2956
2957 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2958}
2959
2960// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2961// ES 3.0.4 table 3.24
2962TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2963{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002964 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2965
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002966 glActiveTexture(GL_TEXTURE0);
2967 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2968 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2969 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2970 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2971 EXPECT_GL_NO_ERROR();
2972
2973 drawQuad(mProgram, "position", 0.5f);
2974
2975 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2976}
2977
2978// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2979// ES 3.0.4 table 3.24
2980TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2981{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002982 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2983
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002984 glActiveTexture(GL_TEXTURE0);
2985 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2986 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2987 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2988 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2989 EXPECT_GL_NO_ERROR();
2990
2991 drawQuad(mProgram, "position", 0.5f);
2992
2993 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2994}
2995
2996// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2997// ES 3.0.4 table 3.24
2998TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2999{
3000 glActiveTexture(GL_TEXTURE0);
3001 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3002 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
3003 EXPECT_GL_NO_ERROR();
3004
3005 drawQuad(mProgram, "position", 0.5f);
3006
3007 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
3008}
3009
3010// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
3011// ES 3.0.4 table 3.24
3012TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
3013{
3014 glActiveTexture(GL_TEXTURE0);
3015 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3016 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
3017 nullptr);
3018 EXPECT_GL_NO_ERROR();
3019
3020 drawQuad(mProgram, "position", 0.5f);
3021
3022 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
3023}
3024
3025// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
3026// ES 3.0.4 table 3.24
3027TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
3028{
Geoff Lang2a19c592019-08-23 14:10:24 -04003029 // ETC texture formats are not supported on Mac OpenGL. http://anglebug.com/3853
3030 ANGLE_SKIP_TEST_IF(IsOSX() && IsDesktopOpenGL());
Yuly Novikov49886892018-01-23 21:18:27 -05003031
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003032 glActiveTexture(GL_TEXTURE0);
3033 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3034 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
3035 EXPECT_GL_NO_ERROR();
3036
3037 drawQuad(mProgram, "position", 0.5f);
3038
3039 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
3040}
3041
3042// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
3043// ES 3.0.4 table 3.24
3044TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
3045{
Geoff Lang2a19c592019-08-23 14:10:24 -04003046 // ETC texture formats are not supported on Mac OpenGL. http://anglebug.com/3853
3047 ANGLE_SKIP_TEST_IF(IsOSX() && IsDesktopOpenGL());
Yuly Novikov49886892018-01-23 21:18:27 -05003048
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003049 glActiveTexture(GL_TEXTURE0);
3050 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3051 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
3052 EXPECT_GL_NO_ERROR();
3053
3054 drawQuad(mProgram, "position", 0.5f);
3055
3056 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
3057}
3058
Olli Etuaho96963162016-03-21 11:54:33 +02003059// Use a sampler in a uniform struct.
3060TEST_P(SamplerInStructTest, SamplerInStruct)
3061{
3062 runSamplerInStructTest();
3063}
3064
3065// Use a sampler in a uniform struct that's passed as a function parameter.
3066TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
3067{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003068 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
3069 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04003070
Olli Etuaho96963162016-03-21 11:54:33 +02003071 runSamplerInStructTest();
3072}
3073
3074// Use a sampler in a uniform struct array with a struct from the array passed as a function
3075// parameter.
3076TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
3077{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003078 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
3079 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08003080
Olli Etuaho96963162016-03-21 11:54:33 +02003081 runSamplerInStructTest();
3082}
3083
3084// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
3085// parameter.
3086TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
3087{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003088 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
3089 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08003090
Olli Etuaho96963162016-03-21 11:54:33 +02003091 runSamplerInStructTest();
3092}
3093
3094// Make sure that there isn't a name conflict between sampler extracted from a struct and a
3095// similarly named uniform.
3096TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
3097{
3098 runSamplerInStructTest();
3099}
3100
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05003101// GL_EXT_texture_filter_anisotropic
3102class TextureAnisotropyTest : public Texture2DTest
3103{
3104 protected:
3105 void uploadTexture()
3106 {
3107 glActiveTexture(GL_TEXTURE0);
3108 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3109 GLColor texDataRed[1] = {GLColor::red};
3110 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed);
3111 EXPECT_GL_NO_ERROR();
3112 }
3113};
3114
3115// Tests that setting anisotropic filtering doesn't cause failures at draw time.
3116TEST_P(TextureAnisotropyTest, AnisotropyFunctional)
3117{
Jamie Madillb8149072019-04-30 16:14:44 -04003118 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_filter_anisotropic"));
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05003119
3120 setUpProgram();
3121
3122 uploadTexture();
3123
3124 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3125 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3126 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f);
3127 EXPECT_GL_NO_ERROR();
3128
3129 drawQuad(mProgram, "position", 0.5f);
3130
3131 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3132 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3133 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::red);
3134}
3135
Till Rathmannb8543632018-10-02 19:46:14 +02003136// GL_OES_texture_border_clamp
3137class TextureBorderClampTest : public Texture2DTest
3138{
3139 protected:
3140 TextureBorderClampTest() : Texture2DTest() {}
3141
Jamie Madill35cd7332018-12-02 12:03:33 -05003142 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003143 {
3144 return
3145 R"(precision highp float;
3146 attribute vec4 position;
3147 varying vec2 texcoord;
3148
3149 void main()
3150 {
3151 gl_Position = vec4(position.xy, 0.0, 1.0);
3152 // texcoords in [-0.5, 1.5]
3153 texcoord = (position.xy) + 0.5;
3154 })";
3155 }
3156
3157 void uploadTexture()
3158 {
3159 glActiveTexture(GL_TEXTURE0);
3160 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3161 std::vector<GLColor> texDataRed(1, GLColor::red);
3162 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3163 texDataRed.data());
3164 EXPECT_GL_NO_ERROR();
3165 }
3166};
3167
3168// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3169// GL_CLAMP_TO_BORDER wrap mode (set with glTexParameter).
3170TEST_P(TextureBorderClampTest, TextureBorderClampFunctional)
3171{
Jamie Madillb8149072019-04-30 16:14:44 -04003172 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003173
3174 setUpProgram();
3175
3176 uploadTexture();
3177
3178 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3179 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3180 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3181 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3182 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3183 EXPECT_GL_NO_ERROR();
3184
3185 drawQuad(mProgram, "position", 0.5f);
3186
3187 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3188 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3189 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3190}
3191
3192// Test reading back GL_TEXTURE_BORDER_COLOR by glGetTexParameter.
3193TEST_P(TextureBorderClampTest, TextureBorderClampFunctional2)
3194{
Jamie Madillb8149072019-04-30 16:14:44 -04003195 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003196
3197 glActiveTexture(GL_TEXTURE0);
3198 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3199
3200 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3201
3202 GLint colorFixedPoint[4] = {0};
3203 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3204 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3205 std::numeric_limits<GLint>::max()};
3206 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3207 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3208 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3209 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3210
3211 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3212 std::numeric_limits<GLint>::max()};
3213 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3214
3215 GLfloat color[4] = {0.0f};
3216 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
3217 EXPECT_EQ(color[0], kFloatBlue.R);
3218 EXPECT_EQ(color[1], kFloatBlue.G);
3219 EXPECT_EQ(color[2], kFloatBlue.B);
3220 EXPECT_EQ(color[3], kFloatBlue.A);
3221}
3222
3223// Test GL_TEXTURE_BORDER_COLOR parameter validation at glTexParameter.
3224TEST_P(TextureBorderClampTest, TextureBorderClampValidation)
3225{
Jamie Madillb8149072019-04-30 16:14:44 -04003226 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003227
3228 glActiveTexture(GL_TEXTURE0);
3229 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3230
3231 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, 1.0f);
3232 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3233
3234 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3235 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3236
3237 glTexParameterfv(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3238 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3239
3240 GLint colorInt[4] = {0};
3241 glTexParameteriv(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_BORDER_COLOR, colorInt);
3242 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3243
3244 if (getClientMajorVersion() < 3)
3245 {
3246 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3247 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3248 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3249 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3250
3251 GLuint colorUInt[4] = {0};
3252 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3253 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3254 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3255 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3256
3257 GLSampler sampler;
3258 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3259 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3260 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3261 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3262
3263 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3264 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3265 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3266 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3267 }
3268}
3269
3270class TextureBorderClampTestES3 : public TextureBorderClampTest
3271{
3272 protected:
3273 TextureBorderClampTestES3() : TextureBorderClampTest() {}
3274};
3275
3276// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3277// GL_CLAMP_TO_BORDER wrap mode (set with glSamplerParameter).
3278TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional)
3279{
Jamie Madillb8149072019-04-30 16:14:44 -04003280 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003281
3282 setUpProgram();
3283
3284 uploadTexture();
3285
3286 GLSampler sampler;
3287 glBindSampler(0, sampler);
3288 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3289 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3290 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3291 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3292 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3293 EXPECT_GL_NO_ERROR();
3294
3295 drawQuad(mProgram, "position", 0.5f);
3296
3297 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3298 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3299 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3300}
3301
3302// Test reading back GL_TEXTURE_BORDER_COLOR by glGetSamplerParameter.
3303TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional2)
3304{
Jamie Madillb8149072019-04-30 16:14:44 -04003305 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003306
3307 glActiveTexture(GL_TEXTURE0);
3308
3309 GLSampler sampler;
3310 glBindSampler(0, sampler);
3311
3312 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3313
3314 GLint colorFixedPoint[4] = {0};
3315 glGetSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3316 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3317 std::numeric_limits<GLint>::max()};
3318 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3319 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3320 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3321 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3322
3323 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3324 std::numeric_limits<GLint>::max()};
3325 glSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3326
3327 GLfloat color[4] = {0.0f};
3328 glGetSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, color);
3329 EXPECT_EQ(color[0], kFloatBlue.R);
3330 EXPECT_EQ(color[1], kFloatBlue.G);
3331 EXPECT_EQ(color[2], kFloatBlue.B);
3332 EXPECT_EQ(color[3], kFloatBlue.A);
3333
3334 constexpr GLint colorSomewhatRedInt[4] = {500000, 0, 0, std::numeric_limits<GLint>::max()};
3335 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedInt);
3336 GLint colorInt[4] = {0};
3337 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3338 EXPECT_EQ(colorInt[0], colorSomewhatRedInt[0]);
3339 EXPECT_EQ(colorInt[1], colorSomewhatRedInt[1]);
3340 EXPECT_EQ(colorInt[2], colorSomewhatRedInt[2]);
3341 EXPECT_EQ(colorInt[3], colorSomewhatRedInt[3]);
3342
3343 constexpr GLuint colorSomewhatRedUInt[4] = {500000, 0, 0, std::numeric_limits<GLuint>::max()};
3344 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedUInt);
3345 GLuint colorUInt[4] = {0};
3346 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3347 EXPECT_EQ(colorUInt[0], colorSomewhatRedUInt[0]);
3348 EXPECT_EQ(colorUInt[1], colorSomewhatRedUInt[1]);
3349 EXPECT_EQ(colorUInt[2], colorSomewhatRedUInt[2]);
3350 EXPECT_EQ(colorUInt[3], colorSomewhatRedUInt[3]);
3351
3352 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3353
3354 constexpr GLint colorSomewhatGreenInt[4] = {0, 500000, 0, std::numeric_limits<GLint>::max()};
3355 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenInt);
3356 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3357 EXPECT_EQ(colorInt[0], colorSomewhatGreenInt[0]);
3358 EXPECT_EQ(colorInt[1], colorSomewhatGreenInt[1]);
3359 EXPECT_EQ(colorInt[2], colorSomewhatGreenInt[2]);
3360 EXPECT_EQ(colorInt[3], colorSomewhatGreenInt[3]);
3361
3362 constexpr GLuint colorSomewhatGreenUInt[4] = {0, 500000, 0, std::numeric_limits<GLuint>::max()};
3363 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenUInt);
3364 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3365 EXPECT_EQ(colorUInt[0], colorSomewhatGreenUInt[0]);
3366 EXPECT_EQ(colorUInt[1], colorSomewhatGreenUInt[1]);
3367 EXPECT_EQ(colorUInt[2], colorSomewhatGreenUInt[2]);
3368 EXPECT_EQ(colorUInt[3], colorSomewhatGreenUInt[3]);
3369}
3370
3371// Test GL_TEXTURE_BORDER_COLOR parameter validation at glSamplerParameter.
3372TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Validation)
3373{
Jamie Madillb8149072019-04-30 16:14:44 -04003374 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003375
3376 glActiveTexture(GL_TEXTURE0);
3377
3378 GLSampler sampler;
3379 glBindSampler(0, sampler);
3380
3381 glSamplerParameterf(sampler, GL_TEXTURE_BORDER_COLOR, 1.0f);
3382 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3383
3384 glSamplerParameteri(sampler, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3385 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3386}
3387
3388class TextureBorderClampIntegerTestES3 : public Texture2DTest
3389{
3390 protected:
3391 TextureBorderClampIntegerTestES3() : Texture2DTest(), isUnsignedIntTest(false) {}
3392
Jamie Madill35cd7332018-12-02 12:03:33 -05003393 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003394 {
3395 return
3396 R"(#version 300 es
3397 out vec2 texcoord;
3398 in vec4 position;
3399
3400 void main()
3401 {
3402 gl_Position = vec4(position.xy, 0.0, 1.0);
3403 // texcoords in [-0.5, 1.5]
3404 texcoord = (position.xy) + 0.5;
3405 })";
3406 }
3407
Jamie Madillba319ba2018-12-29 10:29:33 -05003408 const char *getFragmentShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003409 {
Jamie Madill35cd7332018-12-02 12:03:33 -05003410 if (isUnsignedIntTest)
3411 {
3412 return "#version 300 es\n"
3413 "precision highp float;\n"
3414 "uniform highp usampler2D tex;\n"
3415 "in vec2 texcoord;\n"
3416 "out vec4 fragColor;\n"
Till Rathmannb8543632018-10-02 19:46:14 +02003417
Jamie Madill35cd7332018-12-02 12:03:33 -05003418 "void main()\n"
3419 "{\n"
3420 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3421 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3422 "fragColor = (texture(tex, texcoord).r == 150u)"
3423 " ? green : red;\n"
3424 "}\n";
3425 }
3426 else
3427 {
3428 return "#version 300 es\n"
3429 "precision highp float;\n"
3430 "uniform highp isampler2D tex;\n"
3431 "in vec2 texcoord;\n"
3432 "out vec4 fragColor;\n"
3433
3434 "void main()\n"
3435 "{\n"
3436 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3437 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3438 "fragColor = (texture(tex, texcoord).r == -50)"
3439 " ? green : red;\n"
3440 "}\n";
3441 }
Till Rathmannb8543632018-10-02 19:46:14 +02003442 }
3443
3444 void uploadTexture()
3445 {
3446 glActiveTexture(GL_TEXTURE0);
3447 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3448 if (isUnsignedIntTest)
3449 {
3450 std::vector<GLubyte> texData(4, 100);
3451 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE,
3452 texData.data());
3453 }
3454 else
3455 {
3456 std::vector<GLbyte> texData(4, 100);
3457 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8I, 1, 1, 0, GL_RGBA_INTEGER, GL_BYTE,
3458 texData.data());
3459 }
3460 EXPECT_GL_NO_ERROR();
3461 }
3462
3463 bool isUnsignedIntTest;
3464};
3465
3466// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3467// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3468TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger)
3469{
Yuly Novikov1dbbc7b2019-07-31 17:49:39 -04003470 // Fails on Win10 FYI x64 Release (AMD RX 550). http://anglebug.com/3760
3471 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsDesktopOpenGL());
3472
Jamie Madillb8149072019-04-30 16:14:44 -04003473 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003474
3475 setUpProgram();
3476
3477 uploadTexture();
3478
3479 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3480 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3481 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3482 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3483
3484 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3485 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3486
3487 EXPECT_GL_NO_ERROR();
3488
3489 drawQuad(mProgram, "position", 0.5f);
3490
3491 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3492 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3493 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3494}
3495
3496// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3497// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3498TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger2)
3499{
Yuly Novikov1dbbc7b2019-07-31 17:49:39 -04003500 // Fails on Win10 FYI x64 Release (AMD RX 550). http://anglebug.com/3760
3501 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsDesktopOpenGL());
3502
Jamie Madillb8149072019-04-30 16:14:44 -04003503 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003504
3505 setUpProgram();
3506
3507 uploadTexture();
3508
3509 GLSampler sampler;
3510 glBindSampler(0, sampler);
3511 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3512 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3513 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3514 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3515
3516 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3517 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3518
3519 EXPECT_GL_NO_ERROR();
3520
3521 drawQuad(mProgram, "position", 0.5f);
3522
3523 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3524 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3525 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3526}
3527
3528// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3529// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIuivOES).
3530TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned)
3531{
Jamie Madillb8149072019-04-30 16:14:44 -04003532 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003533
3534 isUnsignedIntTest = true;
3535
3536 setUpProgram();
3537
3538 uploadTexture();
3539
3540 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3541 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3542 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3543 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3544
3545 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3546 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3547
3548 EXPECT_GL_NO_ERROR();
3549
3550 drawQuad(mProgram, "position", 0.5f);
3551
3552 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3553 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3554 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3555}
3556
3557// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3558// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with
3559// glSamplerParameterIuivOES).
3560TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned2)
3561{
Jamie Madillb8149072019-04-30 16:14:44 -04003562 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003563
3564 isUnsignedIntTest = true;
3565
3566 setUpProgram();
3567
3568 uploadTexture();
3569
3570 GLSampler sampler;
3571 glBindSampler(0, sampler);
3572 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3573 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3574 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3575 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3576
3577 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3578 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3579
3580 EXPECT_GL_NO_ERROR();
3581
3582 drawQuad(mProgram, "position", 0.5f);
3583
3584 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3585 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3586 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3587}
3588
3589// ~GL_OES_texture_border_clamp
3590
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003591class TextureLimitsTest : public ANGLETest
3592{
3593 protected:
3594 struct RGBA8
3595 {
3596 uint8_t R, G, B, A;
3597 };
3598
3599 TextureLimitsTest()
3600 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
3601 {
3602 setWindowWidth(128);
3603 setWindowHeight(128);
3604 setConfigRedBits(8);
3605 setConfigGreenBits(8);
3606 setConfigBlueBits(8);
3607 setConfigAlphaBits(8);
3608 }
3609
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003610 void testSetUp() override
Jamie Madill0fdb9562018-09-17 17:18:43 -04003611 {
Jamie Madill0fdb9562018-09-17 17:18:43 -04003612 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
3613 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
3614 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
3615
3616 ASSERT_GL_NO_ERROR();
3617 }
3618
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003619 void testTearDown() override
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003620 {
3621 if (mProgram != 0)
3622 {
3623 glDeleteProgram(mProgram);
3624 mProgram = 0;
3625
3626 if (!mTextures.empty())
3627 {
3628 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
3629 }
3630 }
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003631 }
3632
3633 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
3634 GLint vertexTextureCount,
3635 GLint vertexActiveTextureCount,
3636 const std::string &fragPrefix,
3637 GLint fragmentTextureCount,
3638 GLint fragmentActiveTextureCount)
3639 {
3640 std::stringstream vertexShaderStr;
3641 vertexShaderStr << "attribute vec2 position;\n"
3642 << "varying vec4 color;\n"
3643 << "varying vec2 texCoord;\n";
3644
3645 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
3646 {
3647 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
3648 }
3649
3650 vertexShaderStr << "void main() {\n"
3651 << " gl_Position = vec4(position, 0, 1);\n"
3652 << " texCoord = (position * 0.5) + 0.5;\n"
3653 << " color = vec4(0);\n";
3654
3655 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
3656 {
3657 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
3658 << ", texCoord);\n";
3659 }
3660
3661 vertexShaderStr << "}";
3662
3663 std::stringstream fragmentShaderStr;
3664 fragmentShaderStr << "varying mediump vec4 color;\n"
3665 << "varying mediump vec2 texCoord;\n";
3666
3667 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
3668 {
3669 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
3670 }
3671
3672 fragmentShaderStr << "void main() {\n"
3673 << " gl_FragColor = color;\n";
3674
3675 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
3676 {
3677 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
3678 << ", texCoord);\n";
3679 }
3680
3681 fragmentShaderStr << "}";
3682
3683 const std::string &vertexShaderSource = vertexShaderStr.str();
3684 const std::string &fragmentShaderSource = fragmentShaderStr.str();
3685
Jamie Madill35cd7332018-12-02 12:03:33 -05003686 mProgram = CompileProgram(vertexShaderSource.c_str(), fragmentShaderSource.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003687 }
3688
3689 RGBA8 getPixel(GLint texIndex)
3690 {
3691 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3692 0, 255u};
3693 return pixel;
3694 }
3695
3696 void initTextures(GLint tex2DCount, GLint texCubeCount)
3697 {
3698 GLint totalCount = tex2DCount + texCubeCount;
3699 mTextures.assign(totalCount, 0);
3700 glGenTextures(totalCount, &mTextures[0]);
3701 ASSERT_GL_NO_ERROR();
3702
3703 std::vector<RGBA8> texData(16 * 16);
3704
3705 GLint texIndex = 0;
3706 for (; texIndex < tex2DCount; ++texIndex)
3707 {
3708 texData.assign(texData.size(), getPixel(texIndex));
3709 glActiveTexture(GL_TEXTURE0 + texIndex);
3710 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3711 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3712 &texData[0]);
3713 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3714 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3715 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3716 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3717 }
3718
3719 ASSERT_GL_NO_ERROR();
3720
3721 for (; texIndex < texCubeCount; ++texIndex)
3722 {
3723 texData.assign(texData.size(), getPixel(texIndex));
3724 glActiveTexture(GL_TEXTURE0 + texIndex);
3725 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3726 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3727 GL_UNSIGNED_BYTE, &texData[0]);
3728 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3729 GL_UNSIGNED_BYTE, &texData[0]);
3730 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3731 GL_UNSIGNED_BYTE, &texData[0]);
3732 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3733 GL_UNSIGNED_BYTE, &texData[0]);
3734 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3735 GL_UNSIGNED_BYTE, &texData[0]);
3736 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3737 GL_UNSIGNED_BYTE, &texData[0]);
3738 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3739 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3740 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3741 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3742 }
3743
3744 ASSERT_GL_NO_ERROR();
3745 }
3746
3747 void testWithTextures(GLint vertexTextureCount,
3748 const std::string &vertexTexturePrefix,
3749 GLint fragmentTextureCount,
3750 const std::string &fragmentTexturePrefix)
3751 {
3752 // Generate textures
3753 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3754
3755 glUseProgram(mProgram);
3756 RGBA8 expectedSum = {0};
3757 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3758 {
3759 std::stringstream uniformNameStr;
3760 uniformNameStr << vertexTexturePrefix << texIndex;
3761 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003762 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003763 ASSERT_NE(-1, location);
3764
3765 glUniform1i(location, texIndex);
3766 RGBA8 contribution = getPixel(texIndex);
3767 expectedSum.R += contribution.R;
3768 expectedSum.G += contribution.G;
3769 }
3770
3771 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3772 {
3773 std::stringstream uniformNameStr;
3774 uniformNameStr << fragmentTexturePrefix << texIndex;
3775 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003776 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003777 ASSERT_NE(-1, location);
3778
3779 glUniform1i(location, texIndex + vertexTextureCount);
3780 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3781 expectedSum.R += contribution.R;
3782 expectedSum.G += contribution.G;
3783 }
3784
3785 ASSERT_GE(256u, expectedSum.G);
3786
3787 drawQuad(mProgram, "position", 0.5f);
3788 ASSERT_GL_NO_ERROR();
3789 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3790 }
3791
3792 GLuint mProgram;
3793 std::vector<GLuint> mTextures;
3794 GLint mMaxVertexTextures;
3795 GLint mMaxFragmentTextures;
3796 GLint mMaxCombinedTextures;
3797};
3798
3799// Test rendering with the maximum vertex texture units.
3800TEST_P(TextureLimitsTest, MaxVertexTextures)
3801{
3802 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3803 ASSERT_NE(0u, mProgram);
3804 ASSERT_GL_NO_ERROR();
3805
3806 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3807}
3808
3809// Test rendering with the maximum fragment texture units.
3810TEST_P(TextureLimitsTest, MaxFragmentTextures)
3811{
3812 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3813 ASSERT_NE(0u, mProgram);
3814 ASSERT_GL_NO_ERROR();
3815
3816 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3817}
3818
3819// Test rendering with maximum combined texture units.
3820TEST_P(TextureLimitsTest, MaxCombinedTextures)
3821{
3822 GLint vertexTextures = mMaxVertexTextures;
3823
3824 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3825 {
3826 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3827 }
3828
3829 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3830 mMaxFragmentTextures, mMaxFragmentTextures);
3831 ASSERT_NE(0u, mProgram);
3832 ASSERT_GL_NO_ERROR();
3833
3834 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3835}
3836
3837// Negative test for exceeding the number of vertex textures
3838TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3839{
3840 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3841 0);
3842 ASSERT_EQ(0u, mProgram);
3843}
3844
3845// Negative test for exceeding the number of fragment textures
3846TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3847{
3848 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3849 mMaxFragmentTextures + 1);
3850 ASSERT_EQ(0u, mProgram);
3851}
3852
3853// Test active vertex textures under the limit, but excessive textures specified.
3854TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3855{
3856 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3857 ASSERT_NE(0u, mProgram);
3858 ASSERT_GL_NO_ERROR();
3859
3860 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3861}
3862
3863// Test active fragment textures under the limit, but excessive textures specified.
3864TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3865{
3866 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3867 mMaxFragmentTextures);
3868 ASSERT_NE(0u, mProgram);
3869 ASSERT_GL_NO_ERROR();
3870
3871 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3872}
3873
3874// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003875// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003876TEST_P(TextureLimitsTest, TextureTypeConflict)
3877{
Jamie Madill35cd7332018-12-02 12:03:33 -05003878 constexpr char kVS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003879 "attribute vec2 position;\n"
3880 "varying float color;\n"
3881 "uniform sampler2D tex2D;\n"
3882 "uniform samplerCube texCube;\n"
3883 "void main() {\n"
3884 " gl_Position = vec4(position, 0, 1);\n"
3885 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3886 " color = texture2D(tex2D, texCoord).x;\n"
3887 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3888 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05003889 constexpr char kFS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003890 "varying mediump float color;\n"
3891 "void main() {\n"
3892 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3893 "}";
3894
Jamie Madill35cd7332018-12-02 12:03:33 -05003895 mProgram = CompileProgram(kVS, kFS);
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003896 ASSERT_NE(0u, mProgram);
3897
3898 initTextures(1, 0);
3899
3900 glUseProgram(mProgram);
3901 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3902 ASSERT_NE(-1, tex2DLocation);
3903 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3904 ASSERT_NE(-1, texCubeLocation);
3905
3906 glUniform1i(tex2DLocation, 0);
3907 glUniform1i(texCubeLocation, 0);
3908 ASSERT_GL_NO_ERROR();
3909
3910 drawQuad(mProgram, "position", 0.5f);
3911 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3912}
3913
Vincent Lang25ab4512016-05-13 18:13:59 +02003914class Texture2DNorm16TestES3 : public Texture2DTestES3
3915{
3916 protected:
3917 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3918
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003919 void testSetUp() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003920 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003921 Texture2DTestES3::testSetUp();
Vincent Lang25ab4512016-05-13 18:13:59 +02003922
3923 glActiveTexture(GL_TEXTURE0);
3924 glGenTextures(3, mTextures);
3925 glGenFramebuffers(1, &mFBO);
3926 glGenRenderbuffers(1, &mRenderbuffer);
3927
3928 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3929 {
3930 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3931 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3932 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3933 }
3934
3935 glBindTexture(GL_TEXTURE_2D, 0);
3936
3937 ASSERT_GL_NO_ERROR();
3938 }
3939
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003940 void testTearDown() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003941 {
3942 glDeleteTextures(3, mTextures);
3943 glDeleteFramebuffers(1, &mFBO);
3944 glDeleteRenderbuffers(1, &mRenderbuffer);
3945
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003946 Texture2DTestES3::testTearDown();
Vincent Lang25ab4512016-05-13 18:13:59 +02003947 }
3948
3949 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3950 {
Geoff Langf607c602016-09-21 11:46:48 -04003951 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3952 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003953
3954 setUpProgram();
3955
3956 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3957 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3958 0);
3959
3960 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3961 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3962
3963 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003964 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003965
3966 EXPECT_GL_NO_ERROR();
3967
3968 drawQuad(mProgram, "position", 0.5f);
3969
Geoff Langf607c602016-09-21 11:46:48 -04003970 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003971
Jamie Madill50cf2be2018-06-15 09:46:57 -04003972 EXPECT_PIXEL_COLOR_EQ(0, 0,
3973 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3974 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003975
3976 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3977
3978 ASSERT_GL_NO_ERROR();
3979 }
3980
3981 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3982 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04003983 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003984 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003985
3986 setUpProgram();
3987
3988 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3989 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3990
3991 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3992 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3993 0);
3994
3995 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003996 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003997
3998 EXPECT_GL_NO_ERROR();
3999
4000 drawQuad(mProgram, "position", 0.5f);
4001
Geoff Langf607c602016-09-21 11:46:48 -04004002 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
Jamie Madill50cf2be2018-06-15 09:46:57 -04004003 EXPECT_PIXEL_COLOR_EQ(0, 0,
4004 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
4005 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02004006
4007 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
4008 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
4009 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
4010 mRenderbuffer);
4011 glBindRenderbuffer(GL_RENDERBUFFER, 0);
4012 EXPECT_GL_NO_ERROR();
4013
4014 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
4015 glClear(GL_COLOR_BUFFER_BIT);
4016
shrekshaoe33c1582019-11-06 16:55:29 -08004017 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
4018
4019 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Vincent Lang25ab4512016-05-13 18:13:59 +02004020 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
4021
shrekshaoe33c1582019-11-06 16:55:29 -08004022 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
4023 0);
Geoff Langf607c602016-09-21 11:46:48 -04004024 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02004025
4026 glBindFramebuffer(GL_FRAMEBUFFER, 0);
4027
4028 ASSERT_GL_NO_ERROR();
4029 }
4030
4031 GLuint mTextures[3];
4032 GLuint mFBO;
4033 GLuint mRenderbuffer;
4034};
4035
4036// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
4037TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
4038{
shrekshaoe33c1582019-11-06 16:55:29 -08004039 // TODO(crbug.com/angleproject/4089) Fails on Nexus5X Adreno
4040 ANGLE_SKIP_TEST_IF(IsNexus5X());
4041 // TODO(crbug.com/angleproject/4089) Fails on Win Intel OpenGL driver
4042 ANGLE_SKIP_TEST_IF(IsIntel() && IsOpenGL());
4043
Jamie Madillb8149072019-04-30 16:14:44 -04004044 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02004045
4046 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
4047 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
4048 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
4049 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
4050 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
4051 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
4052 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
4053 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
4054
4055 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
4056 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
4057 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
4058}
4059
Mohan Maiya8f1169e2019-06-27 15:32:32 -07004060class Texture2DRGTest : public Texture2DTest
4061{
4062 protected:
4063 Texture2DRGTest()
4064 : Texture2DTest(), mRenderableTexture(0), mTestTexture(0), mFBO(0), mRenderbuffer(0)
4065 {}
4066
4067 void testSetUp() override
4068 {
4069 Texture2DTest::testSetUp();
4070
4071 glActiveTexture(GL_TEXTURE0);
4072 glGenTextures(1, &mRenderableTexture);
4073 glGenTextures(1, &mTestTexture);
4074 glGenFramebuffers(1, &mFBO);
4075 glGenRenderbuffers(1, &mRenderbuffer);
4076
4077 glBindTexture(GL_TEXTURE_2D, mRenderableTexture);
Mohan Maiya6caa2652019-09-11 08:06:13 -07004078 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4079 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
Mohan Maiya8f1169e2019-06-27 15:32:32 -07004080 glBindTexture(GL_TEXTURE_2D, mTestTexture);
Mohan Maiya6caa2652019-09-11 08:06:13 -07004081 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4082 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
Mohan Maiya8f1169e2019-06-27 15:32:32 -07004083
4084 glBindTexture(GL_TEXTURE_2D, 0);
4085
4086 setUpProgram();
4087 glUseProgram(mProgram);
4088 glUniform1i(mTexture2DUniformLocation, 0);
4089
4090 ASSERT_GL_NO_ERROR();
4091 }
4092
4093 void testTearDown() override
4094 {
4095 glDeleteTextures(1, &mRenderableTexture);
4096 glDeleteTextures(1, &mTestTexture);
4097 glDeleteFramebuffers(1, &mFBO);
4098 glDeleteRenderbuffers(1, &mRenderbuffer);
4099
4100 Texture2DTest::testTearDown();
4101 }
4102
4103 void setupFormatTextures(GLenum internalformat, GLenum format, GLenum type, GLvoid *imageData)
4104 {
4105 glBindTexture(GL_TEXTURE_2D, mRenderableTexture);
4106 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4107
4108 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
4109 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
4110 mRenderableTexture, 0);
4111
4112 glBindTexture(GL_TEXTURE_2D, mTestTexture);
4113 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
4114
4115 EXPECT_GL_NO_ERROR();
4116 }
4117
4118 void testRGTexture(GLColor expectedColor)
4119 {
4120 drawQuad(mProgram, "position", 0.5f);
4121
4122 EXPECT_GL_NO_ERROR();
4123 EXPECT_PIXEL_COLOR_NEAR(0, 0, expectedColor, kPixelTolerance);
4124 }
4125
4126 void testRGRender(GLenum internalformat, GLenum format)
4127 {
4128 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
4129 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
4130 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
4131 mRenderbuffer);
4132 glBindRenderbuffer(GL_RENDERBUFFER, 0);
4133 EXPECT_GL_NO_ERROR();
4134
4135 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
4136 glClear(GL_COLOR_BUFFER_BIT);
4137
4138 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
4139
4140 ASSERT_GL_NO_ERROR();
4141 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor(255u, 255u, 255u, 255u)));
4142 }
4143
4144 GLuint mRenderableTexture;
4145 GLuint mTestTexture;
4146 GLuint mFBO;
4147 GLuint mRenderbuffer;
4148};
4149
4150// Test unorm texture formats enabled by the GL_EXT_texture_rg extension.
4151TEST_P(Texture2DRGTest, TextureRGUNormTest)
4152{
4153 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_rg"));
4154
4155 GLubyte pixelValue = 0xab;
4156 GLubyte imageData[] = {pixelValue, pixelValue};
4157
4158 setupFormatTextures(GL_RED_EXT, GL_RED_EXT, GL_UNSIGNED_BYTE, imageData);
4159 testRGTexture(
4160 SliceFormatColor(GL_RED_EXT, GLColor(pixelValue, pixelValue, pixelValue, pixelValue)));
4161 testRGRender(GL_R8_EXT, GL_RED_EXT);
4162
4163 setupFormatTextures(GL_RG_EXT, GL_RG_EXT, GL_UNSIGNED_BYTE, imageData);
4164 testRGTexture(
4165 SliceFormatColor(GL_RG_EXT, GLColor(pixelValue, pixelValue, pixelValue, pixelValue)));
4166 testRGRender(GL_RG8_EXT, GL_RG_EXT);
4167}
4168
4169// Test float texture formats enabled by the GL_EXT_texture_rg extension.
4170TEST_P(Texture2DRGTest, TextureRGFloatTest)
4171{
4172 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_rg"));
4173 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
4174
4175 GLfloat pixelValue = 0.54321;
4176 GLfloat imageData[] = {pixelValue, pixelValue};
4177
4178 GLubyte expectedValue = static_cast<GLubyte>(pixelValue * 255.0f);
4179 GLColor expectedColor = GLColor(expectedValue, expectedValue, expectedValue, expectedValue);
4180
4181 setupFormatTextures(GL_RED_EXT, GL_RED_EXT, GL_FLOAT, imageData);
4182 testRGTexture(SliceFormatColor(GL_RED_EXT, expectedColor));
4183
4184 setupFormatTextures(GL_RG_EXT, GL_RG_EXT, GL_FLOAT, imageData);
4185 testRGTexture(SliceFormatColor(GL_RG_EXT, expectedColor));
4186}
4187
4188// Test half-float texture formats enabled by the GL_EXT_texture_rg extension.
Mohan Maiya6caa2652019-09-11 08:06:13 -07004189TEST_P(Texture2DRGTest, TextureRGHalfFloatTest)
Mohan Maiya8f1169e2019-06-27 15:32:32 -07004190{
4191 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_rg"));
4192 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_half_float"));
4193
4194 GLfloat pixelValueFloat = 0.543f;
4195 GLhalf pixelValue = 0x3858;
4196 GLhalf imageData[] = {pixelValue, pixelValue};
4197
4198 GLubyte expectedValue = static_cast<GLubyte>(pixelValueFloat * 255.0f);
4199 GLColor expectedColor = GLColor(expectedValue, expectedValue, expectedValue, expectedValue);
4200
4201 setupFormatTextures(GL_RED_EXT, GL_RED_EXT, GL_HALF_FLOAT_OES, imageData);
4202 testRGTexture(SliceFormatColor(GL_RED_EXT, expectedColor));
4203
4204 setupFormatTextures(GL_RG_EXT, GL_RG_EXT, GL_HALF_FLOAT_OES, imageData);
4205 testRGTexture(SliceFormatColor(GL_RG_EXT, expectedColor));
4206}
4207
Mohan Maiya6caa2652019-09-11 08:06:13 -07004208class Texture2DFloatTest : public Texture2DTest
4209{
4210 protected:
4211 Texture2DFloatTest()
4212 : Texture2DTest(), mRenderableTexture(0), mTestTexture(0), mFBO(0), mRenderbuffer(0)
4213 {}
4214
4215 void testSetUp() override
4216 {
4217 Texture2DTest::testSetUp();
4218
4219 glActiveTexture(GL_TEXTURE0);
4220 glGenTextures(1, &mRenderableTexture);
4221 glGenTextures(1, &mTestTexture);
4222 glGenFramebuffers(1, &mFBO);
4223 glGenRenderbuffers(1, &mRenderbuffer);
4224
4225 setUpProgram();
4226 glUseProgram(mProgram);
4227 glUniform1i(mTexture2DUniformLocation, 0);
4228
4229 glBindTexture(GL_TEXTURE_2D, mRenderableTexture);
4230 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4231
4232 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
4233 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
4234 mRenderableTexture, 0);
4235
4236 ASSERT_GL_NO_ERROR();
4237 }
4238
4239 void testTearDown() override
4240 {
4241 glDeleteTextures(1, &mRenderableTexture);
4242 glDeleteTextures(1, &mTestTexture);
4243 glDeleteFramebuffers(1, &mFBO);
4244 glDeleteRenderbuffers(1, &mRenderbuffer);
4245
4246 Texture2DTest::testTearDown();
4247 }
4248
4249 void testFloatTextureSample(GLenum internalFormat, GLenum format, GLenum type)
4250 {
4251 constexpr GLfloat imageDataFloat[] = {
4252 0.2f,
4253 0.3f,
4254 0.4f,
4255 0.5f,
4256 };
4257 constexpr GLhalf imageDataHalf[] = {
4258 0x3266,
4259 0x34CD,
4260 0x3666,
4261 0x3800,
4262 };
4263 GLColor expectedValue;
4264 for (int i = 0; i < 4; i++)
4265 {
4266 expectedValue[i] = static_cast<GLubyte>(imageDataFloat[i] * 255.0f);
4267 }
4268
4269 const GLvoid *imageData;
4270 switch (type)
4271 {
4272 case GL_FLOAT:
4273 imageData = imageDataFloat;
4274 break;
4275 case GL_HALF_FLOAT:
4276 case GL_HALF_FLOAT_OES:
4277 imageData = imageDataHalf;
4278 break;
4279 default:
4280 imageData = nullptr;
4281 }
4282 ASSERT(imageData != nullptr);
4283
4284 glBindTexture(GL_TEXTURE_2D, mTestTexture);
4285 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, 1, 1, 0, format, type, imageData);
4286
4287 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4288 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4289
4290 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
4291 drawQuad(mProgram, "position", 0.5f);
4292
4293 EXPECT_GL_NO_ERROR();
4294 EXPECT_PIXEL_COLOR_NEAR(0, 0, SliceFormatColor(format, expectedValue), kPixelTolerance);
4295 }
4296
4297 void testFloatTextureLinear(GLenum internalFormat, GLenum format, GLenum type)
4298 {
4299 int numComponents;
4300 switch (format)
4301 {
4302 case GL_RGBA:
4303 numComponents = 4;
4304 break;
4305 case GL_RGB:
4306 numComponents = 3;
4307 break;
4308 case GL_LUMINANCE_ALPHA:
4309 numComponents = 2;
4310 break;
4311 case GL_LUMINANCE:
4312 case GL_ALPHA:
4313 numComponents = 1;
4314 break;
4315 default:
4316 numComponents = 0;
4317 }
4318 ASSERT(numComponents > 0);
4319
4320 constexpr GLfloat pixelIntensitiesFloat[] = {0.0f, 1.0f, 0.0f, 1.0f};
4321 constexpr GLhalf pixelIntensitiesHalf[] = {0x0000, 0x3C00, 0x0000, 0x3C00};
4322
4323 GLfloat imageDataFloat[16];
4324 GLhalf imageDataHalf[16];
4325 for (int i = 0; i < 4; i++)
4326 {
4327 for (int c = 0; c < numComponents; c++)
4328 {
4329 imageDataFloat[i * numComponents + c] = pixelIntensitiesFloat[i];
4330 imageDataHalf[i * numComponents + c] = pixelIntensitiesHalf[i];
4331 }
4332 }
4333
4334 const GLvoid *imageData;
4335 switch (type)
4336 {
4337 case GL_FLOAT:
4338 imageData = imageDataFloat;
4339 break;
4340 case GL_HALF_FLOAT:
4341 case GL_HALF_FLOAT_OES:
4342 imageData = imageDataHalf;
4343 break;
4344 default:
4345 imageData = nullptr;
4346 }
4347 ASSERT(imageData != nullptr);
4348
4349 glBindTexture(GL_TEXTURE_2D, mTestTexture);
4350 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, 2, 2, 0, format, type, imageData);
4351
4352 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4353 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4354
4355 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
4356 drawQuad(mProgram, "position", 0.5f);
4357
4358 EXPECT_GL_NO_ERROR();
4359 // Source texture contains 2 black pixels and 2 white pixels, we sample in the center so we
4360 // should expect the final value to be gray (halfway in-between)
4361 EXPECT_PIXEL_COLOR_NEAR(0, 0, SliceFormatColor(format, GLColor(127u, 127u, 127u, 127u)),
4362 kPixelTolerance);
4363 }
4364
4365 bool performFloatTextureRender(GLenum internalFormat,
4366 GLenum renderBufferFormat,
4367 GLenum format,
4368 GLenum type)
4369 {
4370 glBindTexture(GL_TEXTURE_2D, mTestTexture);
4371 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, 1, 1, 0, format, type, nullptr);
4372 glBindTexture(GL_TEXTURE_2D, 0);
4373
4374 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
4375 glRenderbufferStorage(GL_RENDERBUFFER, renderBufferFormat, 1, 1);
4376 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
4377 mRenderbuffer);
4378 glBindRenderbuffer(GL_RENDERBUFFER, 0);
4379 EXPECT_GL_NO_ERROR();
4380
4381 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
4382 {
4383 return false;
4384 }
4385
4386 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
4387
4388 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
4389 glClear(GL_COLOR_BUFFER_BIT);
4390
4391 EXPECT_GL_NO_ERROR();
4392 return true;
4393 }
4394
4395 GLuint mRenderableTexture;
4396 GLuint mTestTexture;
4397 GLuint mFBO;
4398 GLuint mRenderbuffer;
4399};
4400
4401class Texture2DFloatTestES3 : public Texture2DFloatTest
4402{
4403 protected:
4404 void testFloatTextureRender(GLenum internalFormat, GLenum format, GLenum type)
4405 {
4406 bool framebufferComplete =
4407 performFloatTextureRender(internalFormat, internalFormat, format, type);
4408 EXPECT_TRUE(framebufferComplete);
4409 EXPECT_PIXEL_COLOR32F_NEAR(0, 0,
4410 SliceFormatColor32F(format, GLColor32F(1.0f, 1.0f, 1.0f, 1.0f)),
4411 kPixelTolerance32F);
4412 }
4413};
4414
4415class Texture2DFloatTestES2 : public Texture2DFloatTest
4416{
4417 protected:
4418 bool checkFloatTextureRender(GLenum renderBufferFormat, GLenum format, GLenum type)
4419 {
4420 bool framebufferComplete =
4421 performFloatTextureRender(format, renderBufferFormat, format, type);
4422
4423 if (!framebufferComplete)
4424 {
4425 return false;
4426 }
4427
4428 EXPECT_PIXEL_COLOR32F_NEAR(0, 0,
4429 SliceFormatColor32F(format, GLColor32F(1.0f, 1.0f, 1.0f, 1.0f)),
4430 kPixelTolerance32F);
4431 return true;
4432 }
4433};
4434
4435// Test texture sampling for ES3 float texture formats
4436TEST_P(Texture2DFloatTestES3, TextureFloatSampleBasicTest)
4437{
4438 testFloatTextureSample(GL_RGBA32F, GL_RGBA, GL_FLOAT);
4439 testFloatTextureSample(GL_RGB32F, GL_RGB, GL_FLOAT);
4440}
4441
4442// Test texture sampling for ES2 float texture formats
4443TEST_P(Texture2DFloatTestES2, TextureFloatSampleBasicTest)
4444{
4445 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
4446 testFloatTextureSample(GL_RGBA, GL_RGBA, GL_FLOAT);
4447 testFloatTextureSample(GL_RGB, GL_RGB, GL_FLOAT);
4448}
4449
4450// Test texture sampling for ES3 half float texture formats
4451TEST_P(Texture2DFloatTestES3, TextureHalfFloatSampleBasicTest)
4452{
4453 testFloatTextureSample(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT);
4454 testFloatTextureSample(GL_RGB16F, GL_RGB, GL_HALF_FLOAT);
4455}
4456
4457// Test texture sampling for ES2 half float texture formats
4458TEST_P(Texture2DFloatTestES2, TextureHalfFloatSampleBasicTest)
4459{
4460 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_half_float"));
4461 testFloatTextureSample(GL_RGBA, GL_RGBA, GL_HALF_FLOAT_OES);
4462 testFloatTextureSample(GL_RGB, GL_RGB, GL_HALF_FLOAT_OES);
4463}
4464
4465// Test texture sampling for legacy GLES 2.0 float texture formats in ES3
4466TEST_P(Texture2DFloatTestES3, TextureFloatSampleLegacyTest)
4467{
4468 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
4469
4470 testFloatTextureSample(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT);
4471 testFloatTextureSample(GL_ALPHA, GL_ALPHA, GL_FLOAT);
4472 testFloatTextureSample(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT);
4473
4474 if (IsGLExtensionEnabled("GL_EXT_texture_storage"))
4475 {
4476 testFloatTextureSample(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT);
4477 testFloatTextureSample(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT);
4478 testFloatTextureSample(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT);
4479 }
4480}
4481
4482// Test texture sampling for legacy GLES 2.0 float texture formats in ES2
4483TEST_P(Texture2DFloatTestES2, TextureFloatSampleLegacyTest)
4484{
4485 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
4486
4487 testFloatTextureSample(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT);
4488 testFloatTextureSample(GL_ALPHA, GL_ALPHA, GL_FLOAT);
4489 testFloatTextureSample(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT);
4490}
4491
4492// Test texture sampling for legacy GLES 2.0 half float texture formats in ES3
4493TEST_P(Texture2DFloatTestES3, TextureHalfFloatSampleLegacyTest)
4494{
4495 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_half_float"));
4496
4497 testFloatTextureSample(GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT_OES);
4498 testFloatTextureSample(GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT_OES);
4499 testFloatTextureSample(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES);
4500
4501 if (IsGLExtensionEnabled("GL_EXT_texture_storage"))
4502 {
4503 testFloatTextureSample(GL_LUMINANCE16F_EXT, GL_LUMINANCE, GL_HALF_FLOAT);
4504 testFloatTextureSample(GL_ALPHA16F_EXT, GL_ALPHA, GL_HALF_FLOAT);
4505 testFloatTextureSample(GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT);
4506 }
4507}
4508// Test texture sampling for legacy GLES 2.0 half float texture formats in ES2
4509TEST_P(Texture2DFloatTestES2, TextureHalfFloatSampleLegacyTest)
4510{
4511 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_half_float"));
4512
4513 testFloatTextureSample(GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT_OES);
4514 testFloatTextureSample(GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT_OES);
4515 testFloatTextureSample(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES);
4516}
4517
4518// Test linear sampling for ES3 32F formats
4519TEST_P(Texture2DFloatTestES3, TextureFloatLinearTest)
4520{
4521 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float_linear"));
4522
4523 testFloatTextureLinear(GL_RGBA32F, GL_RGBA, GL_FLOAT);
4524 testFloatTextureLinear(GL_RGB32F, GL_RGB, GL_FLOAT);
4525}
4526// Test linear sampling for ES2 32F formats
4527TEST_P(Texture2DFloatTestES2, TextureFloatLinearTest)
4528{
4529 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float_linear"));
4530
4531 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
4532
4533 testFloatTextureLinear(GL_RGBA, GL_RGBA, GL_FLOAT);
4534}
4535
4536// Test linear sampling for ES3 16F formats
4537TEST_P(Texture2DFloatTestES3, TextureHalfFloatLinearTest)
4538{
4539 // Half float formats must be linearly filterable in GLES 3.0 core
4540 testFloatTextureLinear(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT);
4541 testFloatTextureLinear(GL_RGB16F, GL_RGB, GL_HALF_FLOAT);
4542}
4543// Test linear sampling for ES2 16F formats
4544TEST_P(Texture2DFloatTestES2, TextureHalfFloatLinearTest)
4545{
4546 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_half_float_linear"));
4547 testFloatTextureLinear(GL_RGBA, GL_RGBA, GL_HALF_FLOAT_OES);
4548 testFloatTextureLinear(GL_RGB, GL_RGB, GL_HALF_FLOAT_OES);
4549}
4550
4551// Test linear sampling for legacy GLES 2.0 32F formats in ES3
4552TEST_P(Texture2DFloatTestES3, TextureFloatLinearLegacyTest)
4553{
4554 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
4555 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float_linear"));
4556
4557 testFloatTextureLinear(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT);
4558 testFloatTextureLinear(GL_ALPHA, GL_ALPHA, GL_FLOAT);
4559 testFloatTextureLinear(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT);
4560
4561 if (IsGLExtensionEnabled("GL_EXT_texture_storage"))
4562 {
4563 testFloatTextureLinear(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT);
4564 testFloatTextureLinear(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT);
4565 testFloatTextureLinear(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT);
4566 }
4567}
4568// Test linear sampling for legacy GLES 2.0 32F formats in ES2
4569TEST_P(Texture2DFloatTestES2, TextureFloatLinearLegacyTest)
4570{
4571 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
4572 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float_linear"));
4573
4574 testFloatTextureLinear(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT);
4575 testFloatTextureLinear(GL_ALPHA, GL_ALPHA, GL_FLOAT);
4576 testFloatTextureLinear(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT);
4577}
4578
4579// Test linear sampling for legacy GLES 2.0 16F formats in ES3
4580TEST_P(Texture2DFloatTestES3, TextureHalfFloatLinearLegacyTest)
4581{
4582 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_half_float"));
4583 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_half_float_linear"));
4584
4585 testFloatTextureLinear(GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT_OES);
4586 testFloatTextureLinear(GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT_OES);
4587 testFloatTextureLinear(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES);
4588
4589 if (IsGLExtensionEnabled("GL_EXT_texture_storage"))
4590 {
4591 testFloatTextureLinear(GL_LUMINANCE16F_EXT, GL_LUMINANCE, GL_HALF_FLOAT);
4592 testFloatTextureLinear(GL_ALPHA16F_EXT, GL_ALPHA, GL_HALF_FLOAT);
4593 testFloatTextureLinear(GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT);
4594 }
4595}
4596// Test linear sampling for legacy GLES 2.0 16F formats in ES2
4597TEST_P(Texture2DFloatTestES2, TextureHalfFloatLinearLegacyTest)
4598{
4599 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_half_float"));
4600 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_half_float_linear"));
4601
4602 testFloatTextureLinear(GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT_OES);
4603 testFloatTextureLinear(GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT_OES);
4604 testFloatTextureLinear(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES);
4605}
4606
4607// Test color-renderability for ES3 float and half float textures
4608TEST_P(Texture2DFloatTestES3, TextureFloatRenderTest)
4609{
Tobin Ehlis1a01b4b2019-11-11 16:41:07 -07004610 // http://anglebug.com/4092
4611 ANGLE_SKIP_TEST_IF(IsD3D9());
Mohan Maiya6caa2652019-09-11 08:06:13 -07004612 // EXT_color_buffer_float covers float, half float, and 11-11-10 float formats
4613 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_color_buffer_float"));
4614
4615 testFloatTextureRender(GL_R32F, GL_RED, GL_FLOAT);
4616 testFloatTextureRender(GL_RG32F, GL_RG, GL_FLOAT);
4617 testFloatTextureRender(GL_RGBA32F, GL_RGBA, GL_FLOAT);
4618
4619 testFloatTextureRender(GL_R16F, GL_RED, GL_HALF_FLOAT);
4620 testFloatTextureRender(GL_RG16F, GL_RG, GL_HALF_FLOAT);
4621 testFloatTextureRender(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT);
4622
4623 testFloatTextureRender(GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT);
4624}
4625
4626// Test color-renderability for ES2 half float textures
4627TEST_P(Texture2DFloatTestES2, TextureFloatRenderTest)
4628{
4629 // EXT_color_buffer_half_float requires at least one format to be renderable, but does not
4630 // require a specific one
4631 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_color_buffer_half_float"));
Zhenyao Mo20bb47d2019-09-16 12:55:30 -07004632 // https://crbug.com/1003971
4633 ANGLE_SKIP_TEST_IF(IsOzone());
Tobin Ehlis1a01b4b2019-11-11 16:41:07 -07004634 // http://anglebug.com/4092
4635 ANGLE_SKIP_TEST_IF(IsD3D9());
Mohan Maiya6caa2652019-09-11 08:06:13 -07004636
4637 bool atLeastOneSupported = false;
4638
4639 if (IsGLExtensionEnabled("GL_OES_texture_half_float") ||
4640 IsGLExtensionEnabled("GL_OES_texture_half_float"))
4641 {
4642 atLeastOneSupported |= checkFloatTextureRender(GL_R16F_EXT, GL_RED_EXT, GL_HALF_FLOAT_OES);
4643 atLeastOneSupported |= checkFloatTextureRender(GL_RG16F_EXT, GL_RG_EXT, GL_HALF_FLOAT_OES);
4644 }
4645 if (IsGLExtensionEnabled("GL_OES_texture_half_float"))
4646 {
4647 atLeastOneSupported |= checkFloatTextureRender(GL_RGB16F_EXT, GL_RGB, GL_HALF_FLOAT_OES);
4648
4649 // If OES_texture_half_float is supported, then RGBA half float textures must be renderable
4650 bool rgbaSupported = checkFloatTextureRender(GL_RGBA16F_EXT, GL_RGBA, GL_HALF_FLOAT_OES);
4651 EXPECT_TRUE(rgbaSupported);
4652 atLeastOneSupported |= rgbaSupported;
4653 }
4654
4655 EXPECT_TRUE(atLeastOneSupported);
4656}
4657
Olli Etuaho95faa232016-06-07 14:01:53 -07004658// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
4659// GLES 3.0.4 section 3.8.3.
4660TEST_P(Texture2DTestES3, UnpackSkipImages2D)
4661{
Yuly Novikovd18c0482019-04-04 19:56:43 -04004662 // Crashes on Nexus 5X due to a driver bug. http://anglebug.com/1429
4663 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07004664
4665 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4666 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4667 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4668 ASSERT_GL_NO_ERROR();
4669
4670 // SKIP_IMAGES should not have an effect on uploading 2D textures
4671 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
4672 ASSERT_GL_NO_ERROR();
4673
4674 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
4675
4676 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4677 pixelsGreen.data());
4678 ASSERT_GL_NO_ERROR();
4679
4680 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
4681 pixelsGreen.data());
4682 ASSERT_GL_NO_ERROR();
4683
4684 glUseProgram(mProgram);
4685 drawQuad(mProgram, "position", 0.5f);
4686 ASSERT_GL_NO_ERROR();
4687
4688 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
4689}
4690
Olli Etuaho989cac32016-06-08 16:18:49 -07004691// Test that skip defined in unpack parameters is taken into account when determining whether
4692// unpacking source extends outside unpack buffer bounds.
4693TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
4694{
4695 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4696 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4697 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4698 ASSERT_GL_NO_ERROR();
4699
4700 GLBuffer buf;
4701 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
4702 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
4703 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
4704 GL_DYNAMIC_COPY);
4705 ASSERT_GL_NO_ERROR();
4706
4707 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4708 ASSERT_GL_NO_ERROR();
4709
4710 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
4711 ASSERT_GL_NO_ERROR();
4712
4713 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4714 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4715
4716 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
4717 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
4718 ASSERT_GL_NO_ERROR();
4719
4720 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4721 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4722}
4723
Olli Etuaho218cf9e2016-05-20 13:55:24 +03004724// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
4725TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
4726{
Yunchao He9550c602018-02-13 14:47:05 +08004727 ANGLE_SKIP_TEST_IF(IsD3D11());
4728
4729 // Incorrect rendering results seen on OSX AMD.
4730 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03004731
4732 const GLuint width = 8u;
4733 const GLuint height = 8u;
4734 const GLuint unpackRowLength = 5u;
4735 const GLuint unpackSkipPixels = 1u;
4736
4737 setWindowWidth(width);
4738 setWindowHeight(height);
4739
4740 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4741 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4742 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4743 ASSERT_GL_NO_ERROR();
4744
4745 GLBuffer buf;
4746 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
4747 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
4748 GLColor::green);
4749
4750 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
4751 {
4752 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
4753 }
4754
4755 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
4756 GL_DYNAMIC_COPY);
4757 ASSERT_GL_NO_ERROR();
4758
4759 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
4760 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
4761 ASSERT_GL_NO_ERROR();
4762
4763 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4764 ASSERT_GL_NO_ERROR();
4765
4766 glUseProgram(mProgram);
4767 drawQuad(mProgram, "position", 0.5f);
4768 ASSERT_GL_NO_ERROR();
4769
4770 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
4771 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
4772 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
4773 actual.data());
4774 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
4775 EXPECT_EQ(expected, actual);
4776}
4777
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004778template <typename T>
4779T UNorm(double value)
4780{
4781 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
4782}
4783
4784// Test rendering a depth texture with mipmaps.
4785TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
4786{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08004787 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
4788 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
Jiawei Shaoaf0f31d2018-09-27 15:42:31 +08004789 // http://anglebug.com/1706
4790 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Corentin Walleze731d8a2016-09-07 10:56:25 -04004791
Jamie Madill24980272019-04-03 09:03:51 -04004792 // Seems to fail on AMD D3D11. Possibly driver bug. http://anglebug.com/3342
4793 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsD3D11());
4794
Cody Northrop988f7172019-09-30 15:52:37 -06004795 // TODO(cnorthrop): Also failing on Vulkan/Windows/AMD. http://anglebug.com/3950
Cody Northropcb16fb52019-08-29 16:53:55 -06004796 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsVulkan());
4797
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004798 const int size = getWindowWidth();
4799
4800 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04004801 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004802
4803 glActiveTexture(GL_TEXTURE0);
4804 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4805 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
4806 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4807 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4808 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
4809 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
4810 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4811 ASSERT_GL_NO_ERROR();
4812
4813 glUseProgram(mProgram);
4814 glUniform1i(mTexture2DUniformLocation, 0);
4815
4816 std::vector<unsigned char> expected;
4817
4818 for (int level = 0; level < levels; ++level)
4819 {
4820 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
4821 expected.push_back(UNorm<unsigned char>(value));
4822
4823 int levelDim = dim(level);
4824
4825 ASSERT_GT(levelDim, 0);
4826
4827 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
4828 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
4829 GL_UNSIGNED_INT, initData.data());
4830 }
4831 ASSERT_GL_NO_ERROR();
4832
4833 for (int level = 0; level < levels; ++level)
4834 {
4835 glViewport(0, 0, dim(level), dim(level));
4836 drawQuad(mProgram, "position", 0.5f);
4837 GLColor actual = ReadColor(0, 0);
4838 EXPECT_NEAR(expected[level], actual.R, 10u);
4839 }
4840
4841 ASSERT_GL_NO_ERROR();
4842}
4843
Courtney Goeltzenleuchter1f2782e2019-08-29 14:19:23 -06004844class Texture2DDepthTest : public Texture2DTest
4845{
4846 protected:
4847 Texture2DDepthTest() : Texture2DTest() {}
4848
4849 const char *getVertexShaderSource() override
4850 {
4851 return "attribute vec4 vPosition;\n"
4852 "void main() {\n"
4853 " gl_Position = vPosition;\n"
4854 "}\n";
4855 }
4856
4857 const char *getFragmentShaderSource() override
4858 {
4859 return "precision mediump float;\n"
4860 "uniform sampler2D ShadowMap;"
4861 "void main() {\n"
4862 " vec4 shadow_value = texture2D(ShadowMap, vec2(0.5, 0.5));"
4863 " if (shadow_value.x == shadow_value.z && shadow_value.x != 0.0) {"
4864 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);"
4865 " } else {"
4866 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
4867 " }"
4868 "}\n";
4869 }
4870
4871 bool checkTexImageFormatSupport(GLenum format, GLenum internalformat, GLenum type)
4872 {
4873 EXPECT_GL_NO_ERROR();
4874
4875 GLTexture tex;
4876 glBindTexture(GL_TEXTURE_2D, tex);
4877 glTexImage2D(GL_TEXTURE_2D, 0, format, 1, 1, 0, format, type, nullptr);
4878
4879 return (glGetError() == GL_NO_ERROR);
4880 }
4881
4882 void testBehavior(bool useSizedComponent)
4883 {
4884 int w = getWindowWidth();
4885 int h = getWindowHeight();
4886 GLuint format = GL_DEPTH_COMPONENT;
4887 GLuint internalFormat = GL_DEPTH_COMPONENT;
4888
4889 if (useSizedComponent)
4890 {
4891 internalFormat = GL_DEPTH_COMPONENT24;
4892 }
4893
4894 GLFramebuffer fbo;
4895 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
4896 ASSERT_GL_NO_ERROR();
4897
4898 GLTexture depthTexture;
4899 glBindTexture(GL_TEXTURE_2D, depthTexture);
4900 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4901 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4902 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
4903 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
4904
4905 TexCoordDrawTest::setUpProgram();
4906 GLint shadowMapLocation = glGetUniformLocation(mProgram, "ShadowMap");
4907 ASSERT_NE(-1, shadowMapLocation);
4908
4909 GLint positionLocation = glGetAttribLocation(mProgram, "vPosition");
4910 ASSERT_NE(-1, positionLocation);
4911
4912 ANGLE_SKIP_TEST_IF(!checkTexImageFormatSupport(format, internalFormat, GL_UNSIGNED_INT));
4913 glBindTexture(GL_TEXTURE_2D, depthTexture);
4914 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, w, h, 0, format, GL_UNSIGNED_INT, nullptr);
4915 ASSERT_GL_NO_ERROR();
4916
4917 // try adding a color buffer.
4918 GLuint colorTex = 0;
4919 glGenTextures(1, &colorTex);
4920 glBindTexture(GL_TEXTURE_2D, colorTex);
4921 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
4922 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
4923 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4924 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4925 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4926 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTex, 0);
4927 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture, 0);
4928 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
4929 ASSERT_GL_NO_ERROR();
4930
4931 glViewport(0, 0, w, h);
4932 // Fill depthTexture with 0.75
4933 glClearDepthf(0.75);
4934 glClear(GL_DEPTH_BUFFER_BIT);
4935
4936 // Revert to normal framebuffer to test depth shader
4937 glBindFramebuffer(GL_FRAMEBUFFER, 0);
4938 glViewport(0, 0, w, h);
4939 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
4940 glClearDepthf(0.0f);
4941 ASSERT_GL_NO_ERROR();
4942
4943 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
4944 ASSERT_GL_NO_ERROR();
4945
4946 glActiveTexture(GL_TEXTURE0);
4947 glBindTexture(GL_TEXTURE_2D, depthTexture);
4948
4949 glUseProgram(mProgram);
4950 ASSERT_GL_NO_ERROR();
4951
4952 glUniform1i(shadowMapLocation, 0);
4953
4954 const GLfloat gTriangleVertices[] = {-0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, 0.5f};
4955
4956 glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, 0, gTriangleVertices);
4957 ASSERT_GL_NO_ERROR();
4958 glEnableVertexAttribArray(positionLocation);
4959 ASSERT_GL_NO_ERROR();
4960 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
4961 ASSERT_GL_NO_ERROR();
4962
4963 GLuint pixels[1];
4964 glReadPixels(w / 2, h / 2, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
4965 ASSERT_GL_NO_ERROR();
4966
4967 // The GLES 3.x spec says that the depth texture sample can be found in the RED component.
4968 // However, the OES_depth_texture indicates that the depth value is treated as luminance and
4969 // is in all the color components. Multiple implementations implement a workaround that
4970 // follows the OES_depth_texture behavior if the internalformat given at glTexImage2D was a
4971 // unsized format (e.g. DEPTH_COMPONENT) and the GLES 3.x behavior if it was a sized
4972 // internalformat such as GL_DEPTH_COMPONENT24. The shader will write out a different color
4973 // depending on if it sees the texture sample in only the RED component.
4974 if (useSizedComponent)
4975 {
4976 ASSERT_NE(pixels[0], 0xff0000ff);
4977 }
4978 else
4979 {
4980 ASSERT_EQ(pixels[0], 0xff0000ff);
4981 }
4982
4983 glBindFramebuffer(GL_FRAMEBUFFER, 0);
4984 glDeleteProgram(mProgram);
4985 }
4986};
4987
4988// Test depth texture compatibility with OES_depth_texture. Uses unsized internformat.
4989TEST_P(Texture2DDepthTest, DepthTextureES2Compatibility)
4990{
4991 ANGLE_SKIP_TEST_IF(IsD3D11());
4992 ANGLE_SKIP_TEST_IF(IsIntel() && IsD3D9());
Tobin Ehlis7af26762019-10-23 16:18:57 -06004993 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_ANGLE_depth_texture") &&
4994 !IsGLExtensionEnabled("GL_OES_depth_texture"));
Tobin Ehlis1a01b4b2019-11-11 16:41:07 -07004995 // http://anglebug.com/4092
4996 ANGLE_SKIP_TEST_IF(IsOpenGL() || IsOpenGLES());
Courtney Goeltzenleuchter1f2782e2019-08-29 14:19:23 -06004997
4998 // When the depth texture is specified with unsized internalformat implementations follow
4999 // OES_depth_texture behavior. Otherwise they follow GLES 3.0 behavior.
5000 testBehavior(false);
5001}
5002
5003// Test depth texture compatibility with GLES3 using sized internalformat.
5004TEST_P(Texture2DDepthTest, DepthTextureES3Compatibility)
5005{
5006 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3);
5007
5008 testBehavior(true);
5009}
5010
Jamie Madill7ffdda92016-09-08 13:26:51 -04005011// Tests unpacking into the unsized GL_ALPHA format.
5012TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
5013{
Jamie Madill7ffdda92016-09-08 13:26:51 -04005014 // Initialize the texure.
5015 glBindTexture(GL_TEXTURE_2D, mTexture2D);
5016 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
5017 GL_UNSIGNED_BYTE, nullptr);
5018 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5019 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5020
5021 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
5022
5023 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04005024 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04005025 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
5026 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
5027 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
5028 GL_STATIC_DRAW);
5029
5030 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
5031 GL_UNSIGNED_BYTE, nullptr);
5032
5033 // Clear to a weird color to make sure we're drawing something.
5034 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
5035 glClear(GL_COLOR_BUFFER_BIT);
5036
5037 // Draw with the alpha texture and verify.
5038 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04005039
5040 ASSERT_GL_NO_ERROR();
5041 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
5042}
5043
Jamie Madill2e600342016-09-19 13:56:40 -04005044// Ensure stale unpack data doesn't propagate in D3D11.
5045TEST_P(Texture2DTestES3, StaleUnpackData)
5046{
5047 // Init unpack buffer.
5048 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
5049 std::vector<GLColor> pixels(pixelCount, GLColor::red);
5050
5051 GLBuffer unpackBuffer;
5052 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
5053 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
5054 GLsizei bufferSize = pixelCount * sizeof(GLColor);
5055 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
5056
5057 // Create from unpack buffer.
5058 glBindTexture(GL_TEXTURE_2D, mTexture2D);
5059 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
5060 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
5061 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5062 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5063
5064 drawQuad(mProgram, "position", 0.5f);
5065
5066 ASSERT_GL_NO_ERROR();
5067 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
5068
5069 // Fill unpack with green, recreating buffer.
5070 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
5071 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
5072 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
5073
5074 // Reinit texture with green.
5075 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
5076 GL_UNSIGNED_BYTE, nullptr);
5077
5078 drawQuad(mProgram, "position", 0.5f);
5079
5080 ASSERT_GL_NO_ERROR();
5081 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
5082}
5083
Geoff Langfb7685f2017-11-13 11:44:11 -05005084// Ensure that texture parameters passed as floats that are converted to ints are rounded before
5085// validating they are less than 0.
5086TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
5087{
5088 GLTexture texture;
5089 glBindTexture(GL_TEXTURE_2D, texture);
5090
5091 // Use a negative number that will round to zero when converted to an integer
5092 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
5093 // "Validation of values performed by state-setting commands is performed after conversion,
5094 // unless specified otherwise for a specific command."
5095 GLfloat param = -7.30157126e-07f;
5096 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
5097 EXPECT_GL_NO_ERROR();
5098
5099 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
5100 EXPECT_GL_NO_ERROR();
5101}
5102
Jamie Madillf097e232016-11-05 00:44:15 -04005103// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
5104// being properly checked, and the texture storage of the previous texture format was persisting.
5105// This would result in an ASSERT in debug and incorrect rendering in release.
5106// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
5107TEST_P(Texture3DTestES3, FormatRedefinitionBug)
5108{
5109 GLTexture tex;
5110 glBindTexture(GL_TEXTURE_3D, tex.get());
5111 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
5112
5113 GLFramebuffer framebuffer;
5114 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
5115 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
5116
5117 glCheckFramebufferStatus(GL_FRAMEBUFFER);
5118
5119 std::vector<uint8_t> pixelData(100, 0);
5120
5121 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
5122 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
5123 pixelData.data());
5124
5125 ASSERT_GL_NO_ERROR();
5126}
5127
Corentin Wallezd2627992017-04-28 17:17:03 -04005128// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
5129TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
5130{
5131 // 2D tests
5132 {
5133 GLTexture tex;
5134 glBindTexture(GL_TEXTURE_2D, tex.get());
5135
5136 GLBuffer pbo;
5137 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
5138
5139 // Test OOB
5140 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
5141 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
5142 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
5143
5144 // Test OOB
5145 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
5146 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
5147 ASSERT_GL_NO_ERROR();
5148 }
5149
5150 // 3D tests
5151 {
5152 GLTexture tex;
5153 glBindTexture(GL_TEXTURE_3D, tex.get());
5154
5155 GLBuffer pbo;
5156 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
5157
5158 // Test OOB
5159 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
5160 GL_STATIC_DRAW);
5161 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
5162 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
5163
5164 // Test OOB
5165 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
5166 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
5167 ASSERT_GL_NO_ERROR();
5168 }
5169}
5170
Jamie Madill3ed60422017-09-07 11:32:52 -04005171// Tests behaviour with a single texture and multiple sampler objects.
5172TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
5173{
5174 GLint maxTextureUnits = 0;
5175 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
5176 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
5177
5178 constexpr int kSize = 16;
5179
5180 // Make a single-level texture, fill it with red.
5181 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
5182 GLTexture tex;
5183 glBindTexture(GL_TEXTURE_2D, tex);
5184 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
5185 redColors.data());
5186 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5187 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5188
5189 // Simple sanity check.
5190 draw2DTexturedQuad(0.5f, 1.0f, true);
5191 ASSERT_GL_NO_ERROR();
5192 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
5193
5194 // Bind texture to unit 1 with a sampler object making it incomplete.
5195 GLSampler sampler;
5196 glBindSampler(0, sampler);
5197 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
5198 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5199
5200 // Make a mipmap texture, fill it with blue.
5201 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
5202 GLTexture mipmapTex;
5203 glBindTexture(GL_TEXTURE_2D, mipmapTex);
5204 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
5205 blueColors.data());
5206 glGenerateMipmap(GL_TEXTURE_2D);
5207
5208 // Draw with the sampler, expect blue.
5209 draw2DTexturedQuad(0.5f, 1.0f, true);
5210 ASSERT_GL_NO_ERROR();
5211 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
5212
5213 // Simple multitexturing program.
Jamie Madill35cd7332018-12-02 12:03:33 -05005214 constexpr char kVS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04005215 "#version 300 es\n"
5216 "in vec2 position;\n"
5217 "out vec2 texCoord;\n"
5218 "void main()\n"
5219 "{\n"
5220 " gl_Position = vec4(position, 0, 1);\n"
5221 " texCoord = position * 0.5 + vec2(0.5);\n"
5222 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05005223
5224 constexpr char kFS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04005225 "#version 300 es\n"
5226 "precision mediump float;\n"
5227 "in vec2 texCoord;\n"
5228 "uniform sampler2D tex1;\n"
5229 "uniform sampler2D tex2;\n"
5230 "uniform sampler2D tex3;\n"
5231 "uniform sampler2D tex4;\n"
5232 "out vec4 color;\n"
5233 "void main()\n"
5234 "{\n"
5235 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
5236 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
5237 "}";
5238
Jamie Madill35cd7332018-12-02 12:03:33 -05005239 ANGLE_GL_PROGRAM(program, kVS, kFS);
Jamie Madill3ed60422017-09-07 11:32:52 -04005240
5241 std::array<GLint, 4> texLocations = {
5242 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
5243 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
5244 for (GLint location : texLocations)
5245 {
5246 ASSERT_NE(-1, location);
5247 }
5248
5249 // Init the uniform data.
5250 glUseProgram(program);
5251 for (GLint location = 0; location < 4; ++location)
5252 {
5253 glUniform1i(texLocations[location], location);
5254 }
5255
5256 // Initialize four samplers
5257 GLSampler samplers[4];
5258
5259 // 0: non-mipped.
5260 glBindSampler(0, samplers[0]);
5261 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5262 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5263
5264 // 1: mipped.
5265 glBindSampler(1, samplers[1]);
5266 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
5267 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5268
5269 // 2: non-mipped.
5270 glBindSampler(2, samplers[2]);
5271 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5272 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5273
5274 // 3: mipped.
5275 glBindSampler(3, samplers[3]);
5276 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
5277 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5278
5279 // Bind two blue mipped textures and two single layer textures, should all draw.
5280 glActiveTexture(GL_TEXTURE0);
5281 glBindTexture(GL_TEXTURE_2D, tex);
5282
5283 glActiveTexture(GL_TEXTURE1);
5284 glBindTexture(GL_TEXTURE_2D, mipmapTex);
5285
5286 glActiveTexture(GL_TEXTURE2);
5287 glBindTexture(GL_TEXTURE_2D, tex);
5288
5289 glActiveTexture(GL_TEXTURE3);
5290 glBindTexture(GL_TEXTURE_2D, mipmapTex);
5291
5292 ASSERT_GL_NO_ERROR();
5293
5294 drawQuad(program, "position", 0.5f);
5295 ASSERT_GL_NO_ERROR();
5296 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
5297
5298 // Bind four single layer textures, two should be incomplete.
5299 glActiveTexture(GL_TEXTURE1);
5300 glBindTexture(GL_TEXTURE_2D, tex);
5301
5302 glActiveTexture(GL_TEXTURE3);
5303 glBindTexture(GL_TEXTURE_2D, tex);
5304
5305 drawQuad(program, "position", 0.5f);
5306 ASSERT_GL_NO_ERROR();
5307 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
5308}
5309
Martin Radev7e2c0d32017-09-15 14:25:42 +03005310// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
5311// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
5312// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
5313// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
5314// samples the cubemap using a direction vector (1,1,1).
5315TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
5316{
Yunchao He2f23f352018-02-11 22:11:37 +08005317 // Check http://anglebug.com/2155.
5318 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
5319
Jamie Madill35cd7332018-12-02 12:03:33 -05005320 constexpr char kVS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03005321 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03005322 precision mediump float;
5323 in vec3 pos;
5324 void main() {
5325 gl_Position = vec4(pos, 1.0);
5326 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03005327
Jamie Madill35cd7332018-12-02 12:03:33 -05005328 constexpr char kFS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03005329 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03005330 precision mediump float;
5331 out vec4 color;
5332 uniform samplerCube uTex;
5333 void main(){
5334 color = texture(uTex, vec3(1.0));
5335 })";
Jamie Madill35cd7332018-12-02 12:03:33 -05005336
5337 ANGLE_GL_PROGRAM(program, kVS, kFS);
Martin Radev7e2c0d32017-09-15 14:25:42 +03005338 glUseProgram(program);
5339
5340 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
5341 glActiveTexture(GL_TEXTURE0);
5342
5343 GLTexture cubeTex;
5344 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
5345
5346 const int kFaceWidth = 1;
5347 const int kFaceHeight = 1;
5348 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
5349 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
5350 GL_UNSIGNED_BYTE, texData.data());
5351 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
5352 GL_UNSIGNED_BYTE, texData.data());
5353 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
5354 GL_UNSIGNED_BYTE, texData.data());
5355 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
5356 GL_UNSIGNED_BYTE, texData.data());
5357 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
5358 GL_UNSIGNED_BYTE, texData.data());
5359 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
5360 GL_UNSIGNED_BYTE, texData.data());
5361 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5362 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5363 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
5364 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
5365 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
5366 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
5367
5368 drawQuad(program, "pos", 0.5f, 1.0f, true);
5369 ASSERT_GL_NO_ERROR();
5370
5371 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
5372}
5373
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08005374// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
5375TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
5376{
5377 GLuint texture = create2DTexture();
5378
5379 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
5380 EXPECT_GL_ERROR(GL_INVALID_VALUE);
5381
5382 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
5383 EXPECT_GL_ERROR(GL_INVALID_VALUE);
5384
5385 glDeleteTextures(1, &texture);
5386 EXPECT_GL_NO_ERROR();
5387}
5388
Olli Etuaho023371b2018-04-24 17:43:32 +03005389// Test setting base level after calling generateMipmap on a LUMA texture.
5390// Covers http://anglebug.com/2498
5391TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA)
5392{
5393 glActiveTexture(GL_TEXTURE0);
5394 glBindTexture(GL_TEXTURE_2D, mTexture2D);
5395
5396 constexpr const GLsizei kWidth = 8;
5397 constexpr const GLsizei kHeight = 8;
5398 std::array<GLubyte, kWidth * kHeight * 2> whiteData;
5399 whiteData.fill(255u);
5400
5401 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA,
5402 GL_UNSIGNED_BYTE, whiteData.data());
5403 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
5404 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
5405 glGenerateMipmap(GL_TEXTURE_2D);
5406 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
5407 EXPECT_GL_NO_ERROR();
5408
5409 drawQuad(mProgram, "position", 0.5f);
5410 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
5411}
5412
Till Rathmannc1551dc2018-08-15 17:04:49 +02005413// Covers a bug in the D3D11 backend: http://anglebug.com/2772
5414// When using a sampler the texture was created as if it has mipmaps,
5415// regardless what you specified in GL_TEXTURE_MIN_FILTER via
5416// glSamplerParameteri() -- mistakenly the default value
5417// GL_NEAREST_MIPMAP_LINEAR or the value set via glTexParameteri() was
5418// evaluated.
5419// If you didn't provide mipmaps and didn't let the driver generate them
5420// this led to not sampling your texture data when minification occurred.
5421TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping)
5422{
Cody Northrop988f7172019-09-30 15:52:37 -06005423 // TODO: Triage this failure on Vulkan: http://anglebug.com/3950
Cody Northropcb16fb52019-08-29 16:53:55 -06005424 ANGLE_SKIP_TEST_IF(IsVulkan());
5425
Jamie Madill35cd7332018-12-02 12:03:33 -05005426 constexpr char kVS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02005427 "#version 300 es\n"
5428 "out vec2 texcoord;\n"
5429 "in vec4 position;\n"
5430 "void main()\n"
5431 "{\n"
5432 " gl_Position = vec4(position.xy * 0.1, 0.0, 1.0);\n"
5433 " texcoord = (position.xy * 0.5) + 0.5;\n"
5434 "}\n";
5435
Jamie Madill35cd7332018-12-02 12:03:33 -05005436 constexpr char kFS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02005437 "#version 300 es\n"
5438 "precision highp float;\n"
5439 "uniform highp sampler2D tex;\n"
5440 "in vec2 texcoord;\n"
5441 "out vec4 fragColor;\n"
5442 "void main()\n"
5443 "{\n"
5444 " fragColor = texture(tex, texcoord);\n"
5445 "}\n";
Jamie Madill35cd7332018-12-02 12:03:33 -05005446
5447 ANGLE_GL_PROGRAM(program, kVS, kFS);
Till Rathmannc1551dc2018-08-15 17:04:49 +02005448
5449 GLSampler sampler;
5450 glBindSampler(0, sampler);
5451 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
5452 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
5453
5454 glActiveTexture(GL_TEXTURE0);
5455 glBindTexture(GL_TEXTURE_2D, mTexture2D);
5456
5457 const GLsizei texWidth = getWindowWidth();
5458 const GLsizei texHeight = getWindowHeight();
5459 const std::vector<GLColor> whiteData(texWidth * texHeight, GLColor::white);
5460
5461 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
5462 whiteData.data());
5463 EXPECT_GL_NO_ERROR();
5464
5465 drawQuad(program, "position", 0.5f);
5466 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, angle::GLColor::white);
5467}
5468
Anders Leinof6cbe442019-04-18 15:32:07 +03005469// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
5470// texture is output.
5471TEST_P(Texture2DIntegerTestES3, IntegerTextureNonZeroBaseLevel)
5472{
Yuly Novikovd2683452019-05-23 16:11:19 -04005473 // http://anglebug.com/3478
5474 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsDesktopOpenGL());
5475
Anders Leinof6cbe442019-04-18 15:32:07 +03005476 glActiveTexture(GL_TEXTURE0);
5477 glBindTexture(GL_TEXTURE_2D, mTexture2D);
5478 int width = getWindowWidth();
5479 int height = getWindowHeight();
5480 GLColor color = GLColor::green;
5481 std::vector<GLColor> pixels(width * height, color);
5482 GLint baseLevel = 1;
5483 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
5484 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5485 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5486 glTexImage2D(GL_TEXTURE_2D, baseLevel, GL_RGBA8UI, width, height, 0, GL_RGBA_INTEGER,
5487 GL_UNSIGNED_BYTE, pixels.data());
5488
5489 setUpProgram();
5490 glUseProgram(mProgram);
5491 glUniform1i(mTexture2DUniformLocation, 0);
5492 drawQuad(mProgram, "position", 0.5f);
5493
5494 EXPECT_GL_NO_ERROR();
5495 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
5496 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
5497}
5498
Anders Leino60cc7512019-05-06 09:25:27 +03005499// Draw a quad with an integer cube texture with a non-zero base level, and test that the color of
5500// the texture is output.
5501TEST_P(TextureCubeIntegerTestES3, IntegerCubeTextureNonZeroBaseLevel)
5502{
5503 // All output checks returned black, rather than the texture color.
5504 ANGLE_SKIP_TEST_IF(IsOSX() && IsOpenGL());
5505
5506 glActiveTexture(GL_TEXTURE0);
5507
5508 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
5509 GLint baseLevel = 1;
5510 int width = getWindowWidth();
5511 int height = getWindowHeight();
5512 GLColor color = GLColor::green;
5513 std::vector<GLColor> pixels(width * height, color);
5514 for (GLenum faceIndex = 0; faceIndex < 6; faceIndex++)
5515 {
5516 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, baseLevel, GL_RGBA8UI, width,
5517 height, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
5518 EXPECT_GL_NO_ERROR();
5519 }
5520 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, baseLevel);
5521 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5522 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5523
5524 glUseProgram(mProgram);
5525 glUniform1i(mTextureCubeUniformLocation, 0);
5526 drawQuad(mProgram, "position", 0.5f);
5527
5528 EXPECT_GL_NO_ERROR();
5529 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
5530 EXPECT_PIXEL_COLOR_EQ(width - 1, 0, color);
5531 EXPECT_PIXEL_COLOR_EQ(0, height - 1, color);
5532 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
5533}
5534
Anders Leinoe4452442019-05-09 13:29:49 +03005535// This test sets up a cube map with four distincly colored MIP levels.
5536// The size of the texture and the geometry is chosen such that levels 1 or 2 should be chosen at
5537// the corners of the screen.
5538TEST_P(TextureCubeIntegerEdgeTestES3, IntegerCubeTextureCorner)
5539{
5540 glActiveTexture(GL_TEXTURE0);
5541
5542 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
5543 int width = getWindowWidth();
5544 int height = getWindowHeight();
5545 ASSERT_EQ(width, height);
5546 GLColor color[4] = {GLColor::white, GLColor::green, GLColor::blue, GLColor::red};
5547 for (GLint level = 0; level < 4; level++)
5548 {
5549 for (GLenum faceIndex = 0; faceIndex < 6; faceIndex++)
5550 {
5551 int levelWidth = (2 * width) >> level;
5552 int levelHeight = (2 * height) >> level;
5553 std::vector<GLColor> pixels(levelWidth * levelHeight, color[level]);
5554 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, level, GL_RGBA8UI, levelWidth,
5555 levelHeight, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
5556 EXPECT_GL_NO_ERROR();
5557 }
5558 }
5559 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
5560 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5561 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 3);
5562
5563 glUseProgram(mProgram);
5564 glUniform1i(mTextureCubeUniformLocation, 0);
5565 drawQuad(mProgram, "position", 0.5f);
5566
5567 ASSERT_GL_NO_ERROR();
5568 // Check that we do not read from levels 0 or 3. Levels 1 and 2 are both acceptable.
5569 EXPECT_EQ(ReadColor(0, 0).R, 0);
5570 EXPECT_EQ(ReadColor(width - 1, 0).R, 0);
5571 EXPECT_EQ(ReadColor(0, height - 1).R, 0);
5572 EXPECT_EQ(ReadColor(width - 1, height - 1).R, 0);
5573}
5574
Anders Leino1b6aded2019-05-20 12:56:34 +03005575// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
5576// texture is output.
5577TEST_P(Texture2DIntegerProjectiveOffsetTestES3, NonZeroBaseLevel)
5578{
Jamie Madill29ac2742019-05-28 15:53:00 -04005579 // Fails on AMD: http://crbug.com/967796
Jamie Madill06055b52019-05-29 14:31:42 -04005580 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsOpenGL());
Jamie Madill29ac2742019-05-28 15:53:00 -04005581
Anders Leino1b6aded2019-05-20 12:56:34 +03005582 glActiveTexture(GL_TEXTURE0);
5583 glBindTexture(GL_TEXTURE_2D, mTexture2D);
5584 int width = getWindowWidth();
5585 int height = getWindowHeight();
5586 GLColor color = GLColor::green;
5587 std::vector<GLColor> pixels(width * height, color);
5588 GLint baseLevel = 1;
5589 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
5590 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5591 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5592 glTexImage2D(GL_TEXTURE_2D, baseLevel, GL_RGBA8UI, width, height, 0, GL_RGBA_INTEGER,
5593 GL_UNSIGNED_BYTE, pixels.data());
5594
5595 setUpProgram();
5596 glUseProgram(mProgram);
5597 glUniform1i(mTexture2DUniformLocation, 0);
5598 drawQuad(mProgram, "position", 0.5f);
5599
5600 EXPECT_GL_NO_ERROR();
5601 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
5602 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
5603}
5604
Anders Leino69d04932019-05-20 14:04:13 +03005605// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
5606// texture is output.
5607TEST_P(Texture2DArrayIntegerTestES3, NonZeroBaseLevel)
5608{
5609 glActiveTexture(GL_TEXTURE0);
5610 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
5611 int width = getWindowWidth();
5612 int height = getWindowHeight();
5613 int depth = 2;
5614 GLColor color = GLColor::green;
5615 std::vector<GLColor> pixels(width * height * depth, color);
5616 GLint baseLevel = 1;
5617 glTexImage3D(GL_TEXTURE_2D_ARRAY, baseLevel, GL_RGBA8UI, width, height, depth, 0,
5618 GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
5619 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, baseLevel);
5620 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5621 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5622
5623 drawQuad(mProgram, "position", 0.5f);
5624
5625 EXPECT_GL_NO_ERROR();
5626 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
5627 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
5628}
5629
Anders Leino262e2822019-05-20 14:24:40 +03005630// Draw a quad with an integer 3D texture with a non-zero base level, and test that the color of the
5631// texture is output.
5632TEST_P(Texture3DIntegerTestES3, NonZeroBaseLevel)
5633{
5634 glActiveTexture(GL_TEXTURE0);
5635 glBindTexture(GL_TEXTURE_3D, mTexture3D);
5636 int width = getWindowWidth();
5637 int height = getWindowHeight();
5638 int depth = 2;
5639 GLColor color = GLColor::green;
5640 std::vector<GLColor> pixels(width * height * depth, color);
5641 GLint baseLevel = 1;
5642 glTexImage3D(GL_TEXTURE_3D, baseLevel, GL_RGBA8UI, width, height, depth, 0, GL_RGBA_INTEGER,
5643 GL_UNSIGNED_BYTE, pixels.data());
5644 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, baseLevel);
5645 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5646 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5647
5648 drawQuad(mProgram, "position", 0.5f);
5649
5650 EXPECT_GL_NO_ERROR();
5651 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
5652 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
5653}
5654
Jamie Madill50cf2be2018-06-15 09:46:57 -04005655// Use this to select which configurations (e.g. which renderer, which GLES major version) these
5656// tests should be run against.
Tobin Ehlis1a01b4b2019-11-11 16:41:07 -07005657ANGLE_INSTANTIATE_TEST_ES2(Texture2DTest);
5658ANGLE_INSTANTIATE_TEST_ES2(TextureCubeTest);
5659ANGLE_INSTANTIATE_TEST_ES2(Texture2DTestWithDrawScale);
5660ANGLE_INSTANTIATE_TEST_ES2(Sampler2DAsFunctionParameterTest);
5661ANGLE_INSTANTIATE_TEST_ES2(SamplerArrayTest);
5662ANGLE_INSTANTIATE_TEST_ES2(SamplerArrayAsFunctionParameterTest);
5663ANGLE_INSTANTIATE_TEST_ES3(Texture2DTestES3);
5664ANGLE_INSTANTIATE_TEST_ES3(Texture3DTestES3);
5665ANGLE_INSTANTIATE_TEST_ES3(Texture2DIntegerAlpha1TestES3);
5666ANGLE_INSTANTIATE_TEST_ES3(Texture2DUnsignedIntegerAlpha1TestES3);
5667ANGLE_INSTANTIATE_TEST_ES3(ShadowSamplerPlusSampler3DTestES3);
5668ANGLE_INSTANTIATE_TEST_ES3(SamplerTypeMixTestES3);
5669ANGLE_INSTANTIATE_TEST_ES3(Texture2DArrayTestES3);
5670ANGLE_INSTANTIATE_TEST_ES3(TextureSizeTextureArrayTest);
5671ANGLE_INSTANTIATE_TEST_ES2(SamplerInStructTest);
5672ANGLE_INSTANTIATE_TEST_ES2(SamplerInStructAsFunctionParameterTest);
5673ANGLE_INSTANTIATE_TEST_ES2(SamplerInStructArrayAsFunctionParameterTest);
5674ANGLE_INSTANTIATE_TEST_ES2(SamplerInNestedStructAsFunctionParameterTest);
5675ANGLE_INSTANTIATE_TEST_ES2(SamplerInStructAndOtherVariableTest);
5676ANGLE_INSTANTIATE_TEST_ES2(TextureAnisotropyTest);
5677ANGLE_INSTANTIATE_TEST_ES2(TextureBorderClampTest);
5678ANGLE_INSTANTIATE_TEST_ES3(TextureBorderClampTestES3);
5679ANGLE_INSTANTIATE_TEST_ES3(TextureBorderClampIntegerTestES3);
5680ANGLE_INSTANTIATE_TEST_ES2(TextureLimitsTest);
5681ANGLE_INSTANTIATE_TEST_ES3(Texture2DNorm16TestES3);
5682ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(Texture2DRGTest);
5683ANGLE_INSTANTIATE_TEST_ES3(Texture2DFloatTestES3);
5684ANGLE_INSTANTIATE_TEST_ES2(Texture2DFloatTestES2);
5685ANGLE_INSTANTIATE_TEST_ES3(TextureCubeTestES3);
5686ANGLE_INSTANTIATE_TEST_ES3(Texture2DIntegerTestES3);
5687ANGLE_INSTANTIATE_TEST_ES3(TextureCubeIntegerTestES3);
5688ANGLE_INSTANTIATE_TEST_ES3(TextureCubeIntegerEdgeTestES3);
5689ANGLE_INSTANTIATE_TEST_ES3(Texture2DIntegerProjectiveOffsetTestES3);
5690ANGLE_INSTANTIATE_TEST_ES3(Texture2DArrayIntegerTestES3);
5691ANGLE_INSTANTIATE_TEST_ES3(Texture3DIntegerTestES3);
5692ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(Texture2DDepthTest);
Jamie Madillfa05f602015-05-07 13:47:11 -04005693
Jamie Madill7ffdda92016-09-08 13:26:51 -04005694} // anonymous namespace