blob: 9193a52f3c26f5ff57e8705c4339617975abcca4 [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
shrekshaofb1c2fe2019-11-13 11:10:39 -080048GLColor16UI SliceFormatColor16UI(GLenum format, GLColor16UI full)
49{
50 switch (format)
51 {
52 case GL_RED:
53 return GLColor16UI(full.R, 0, 0, 0xFFFF);
54 case GL_RG:
55 return GLColor16UI(full.R, full.G, 0, 0xFFFF);
56 case GL_RGB:
57 return GLColor16UI(full.R, full.G, full.B, 0xFFFF);
58 case GL_RGBA:
59 return full;
60 case GL_LUMINANCE:
61 return GLColor16UI(full.R, full.R, full.R, 0xFFFF);
62 case GL_ALPHA:
63 return GLColor16UI(0, 0, 0, full.R);
64 case GL_LUMINANCE_ALPHA:
65 return GLColor16UI(full.R, full.R, full.R, full.G);
66 default:
67 EXPECT_TRUE(false);
68 return GLColor16UI(0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF);
69 }
70}
71
Mohan Maiya6caa2652019-09-11 08:06:13 -070072// As above, for 32F colors
73GLColor32F SliceFormatColor32F(GLenum format, GLColor32F full)
74{
75 switch (format)
76 {
77 case GL_RED:
78 return GLColor32F(full.R, 0.0f, 0.0f, 1.0f);
79 case GL_RG:
80 return GLColor32F(full.R, full.G, 0.0f, 1.0f);
81 case GL_RGB:
82 return GLColor32F(full.R, full.G, full.B, 1.0f);
83 case GL_RGBA:
84 return full;
85 case GL_LUMINANCE:
86 return GLColor32F(full.R, full.R, full.R, 1.0f);
87 case GL_ALPHA:
88 return GLColor32F(0.0f, 0.0f, 0.0f, full.R);
89 case GL_LUMINANCE_ALPHA:
90 return GLColor32F(full.R, full.R, full.R, full.G);
91 default:
92 EXPECT_TRUE(false);
93 return GLColor32F(1.0f, 1.0f, 1.0f, 1.0f);
94 }
95}
96
Olli Etuaho4a8329f2016-01-11 17:12:57 +020097class TexCoordDrawTest : public ANGLETest
Jamie Madillf67115c2014-04-22 13:14:05 -040098{
Jamie Madillbc393df2015-01-29 13:46:07 -050099 protected:
Olli Etuaho51f1c0f2016-01-13 16:16:24 +0200100 TexCoordDrawTest() : ANGLETest(), mProgram(0), mFramebuffer(0), mFramebufferColorTexture(0)
Jamie Madillf67115c2014-04-22 13:14:05 -0400101 {
102 setWindowWidth(128);
103 setWindowHeight(128);
104 setConfigRedBits(8);
105 setConfigGreenBits(8);
106 setConfigBlueBits(8);
107 setConfigAlphaBits(8);
108 }
109
Jamie Madill35cd7332018-12-02 12:03:33 -0500110 virtual const char *getVertexShaderSource()
Jamie Madillf67115c2014-04-22 13:14:05 -0400111 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500112 return R"(precision highp float;
113attribute vec4 position;
114varying vec2 texcoord;
Geoff Langc41e42d2014-04-28 10:58:16 -0400115
Jamie Madill35cd7332018-12-02 12:03:33 -0500116void main()
117{
118 gl_Position = vec4(position.xy, 0.0, 1.0);
119 texcoord = (position.xy * 0.5) + 0.5;
120})";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200121 }
Geoff Langc41e42d2014-04-28 10:58:16 -0400122
Jamie Madill35cd7332018-12-02 12:03:33 -0500123 virtual const char *getFragmentShaderSource() = 0;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200124
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300125 virtual void setUpProgram()
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200126 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500127 const char *vertexShaderSource = getVertexShaderSource();
128 const char *fragmentShaderSource = getFragmentShaderSource();
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200129
130 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
131 ASSERT_NE(0u, mProgram);
132 ASSERT_GL_NO_ERROR();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300133 }
134
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400135 void testSetUp() override { setUpFramebuffer(); }
Olli Etuaho51f1c0f2016-01-13 16:16:24 +0200136
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400137 void testTearDown() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200138 {
Olli Etuaho51f1c0f2016-01-13 16:16:24 +0200139 glBindFramebuffer(GL_FRAMEBUFFER, 0);
140 glDeleteFramebuffers(1, &mFramebuffer);
141 glDeleteTextures(1, &mFramebufferColorTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200142 glDeleteProgram(mProgram);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200143 }
144
Olli Etuaho51f1c0f2016-01-13 16:16:24 +0200145 void setUpFramebuffer()
146 {
147 // We use an FBO to work around an issue where the default framebuffer applies SRGB
148 // conversion (particularly known to happen incorrectly on Intel GL drivers). It's not
149 // clear whether this issue can even be fixed on all backends. For example GLES 3.0.4 spec
150 // section 4.4 says that the format of the default framebuffer is entirely up to the window
151 // system, so it might be SRGB, and GLES 3.0 doesn't have a "FRAMEBUFFER_SRGB" to turn off
152 // SRGB conversion like desktop GL does.
153 // TODO(oetuaho): Get rid of this if the underlying issue is fixed.
154 glGenFramebuffers(1, &mFramebuffer);
155 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
156
157 glGenTextures(1, &mFramebufferColorTexture);
158 glBindTexture(GL_TEXTURE_2D, mFramebufferColorTexture);
159 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
160 GL_UNSIGNED_BYTE, nullptr);
161 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
162 mFramebufferColorTexture, 0);
163 ASSERT_GL_NO_ERROR();
164 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
165 glBindTexture(GL_TEXTURE_2D, 0);
166 }
167
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200168 // Returns the created texture ID.
169 GLuint create2DTexture()
170 {
171 GLuint texture2D;
172 glGenTextures(1, &texture2D);
173 glBindTexture(GL_TEXTURE_2D, texture2D);
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800174 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200175 EXPECT_GL_NO_ERROR();
176 return texture2D;
177 }
178
179 GLuint mProgram;
Olli Etuaho51f1c0f2016-01-13 16:16:24 +0200180 GLuint mFramebuffer;
181
182 private:
183 GLuint mFramebufferColorTexture;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200184};
185
186class Texture2DTest : public TexCoordDrawTest
187{
188 protected:
189 Texture2DTest() : TexCoordDrawTest(), mTexture2D(0), mTexture2DUniformLocation(-1) {}
190
Jamie Madill35cd7332018-12-02 12:03:33 -0500191 const char *getFragmentShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200192 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500193 return R"(precision highp float;
194uniform sampler2D tex;
195varying vec2 texcoord;
Geoff Langc41e42d2014-04-28 10:58:16 -0400196
Jamie Madill35cd7332018-12-02 12:03:33 -0500197void main()
198{
199 gl_FragColor = texture2D(tex, texcoord);
200})";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200201 }
Geoff Langc41e42d2014-04-28 10:58:16 -0400202
Olli Etuaho96963162016-03-21 11:54:33 +0200203 virtual const char *getTextureUniformName() { return "tex"; }
204
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300205 void setUpProgram() override
206 {
207 TexCoordDrawTest::setUpProgram();
208 mTexture2DUniformLocation = glGetUniformLocation(mProgram, getTextureUniformName());
209 ASSERT_NE(-1, mTexture2DUniformLocation);
210 }
211
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400212 void testSetUp() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200213 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400214 TexCoordDrawTest::testSetUp();
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200215 mTexture2D = create2DTexture();
Jamie Madilld4cfa572014-07-08 10:00:32 -0400216
Jamie Madill9aca0592014-10-06 16:26:59 -0400217 ASSERT_GL_NO_ERROR();
Jamie Madillf67115c2014-04-22 13:14:05 -0400218 }
219
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400220 void testTearDown() override
Jamie Madillf67115c2014-04-22 13:14:05 -0400221 {
Jamie Madilld4cfa572014-07-08 10:00:32 -0400222 glDeleteTextures(1, &mTexture2D);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400223 TexCoordDrawTest::testTearDown();
Jamie Madillf67115c2014-04-22 13:14:05 -0400224 }
225
Jamie Madillbc393df2015-01-29 13:46:07 -0500226 // Tests CopyTexSubImage with floating point textures of various formats.
227 void testFloatCopySubImage(int sourceImageChannels, int destImageChannels)
228 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300229 setUpProgram();
230
Martin Radev1be913c2016-07-11 17:59:16 +0300231 if (getClientMajorVersion() < 3)
Geoff Langfbfa47c2015-03-31 11:26:00 -0400232 {
Jamie Madillb8149072019-04-30 16:14:44 -0400233 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_storage") ||
234 !IsGLExtensionEnabled("GL_OES_texture_float"));
Geoff Langc4e93662017-05-01 10:45:59 -0400235
Yunchao He9550c602018-02-13 14:47:05 +0800236 ANGLE_SKIP_TEST_IF((sourceImageChannels < 3 || destImageChannels < 3) &&
Jamie Madillb8149072019-04-30 16:14:44 -0400237 !IsGLExtensionEnabled("GL_EXT_texture_rg"));
Geoff Langfbfa47c2015-03-31 11:26:00 -0400238
Yunchao He9550c602018-02-13 14:47:05 +0800239 ANGLE_SKIP_TEST_IF(destImageChannels == 3 &&
Jamie Madillb8149072019-04-30 16:14:44 -0400240 !IsGLExtensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400241
Yunchao He9550c602018-02-13 14:47:05 +0800242 ANGLE_SKIP_TEST_IF(destImageChannels == 4 &&
Jamie Madillb8149072019-04-30 16:14:44 -0400243 !IsGLExtensionEnabled("GL_CHROMIUM_color_buffer_float_rgba"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400244
Yunchao He9550c602018-02-13 14:47:05 +0800245 ANGLE_SKIP_TEST_IF(destImageChannels <= 2);
Geoff Lang677bb6f2017-04-05 12:40:40 -0400246 }
247 else
248 {
Jamie Madillb8149072019-04-30 16:14:44 -0400249 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_color_buffer_float"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400250
Yunchao He9550c602018-02-13 14:47:05 +0800251 ANGLE_SKIP_TEST_IF(destImageChannels == 3 &&
Jamie Madillb8149072019-04-30 16:14:44 -0400252 !IsGLExtensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"));
Geoff Langfbfa47c2015-03-31 11:26:00 -0400253 }
254
Jamie Madill50cf2be2018-06-15 09:46:57 -0400255 // clang-format off
Jamie Madillbc393df2015-01-29 13:46:07 -0500256 GLfloat sourceImageData[4][16] =
257 {
258 { // R
259 1.0f,
260 0.0f,
261 0.0f,
262 1.0f
263 },
264 { // RG
265 1.0f, 0.0f,
266 0.0f, 1.0f,
267 0.0f, 0.0f,
268 1.0f, 1.0f
269 },
270 { // RGB
271 1.0f, 0.0f, 0.0f,
272 0.0f, 1.0f, 0.0f,
273 0.0f, 0.0f, 1.0f,
274 1.0f, 1.0f, 0.0f
275 },
276 { // RGBA
277 1.0f, 0.0f, 0.0f, 1.0f,
278 0.0f, 1.0f, 0.0f, 1.0f,
279 0.0f, 0.0f, 1.0f, 1.0f,
280 1.0f, 1.0f, 0.0f, 1.0f
281 },
282 };
Jamie Madill50cf2be2018-06-15 09:46:57 -0400283 // clang-format on
Jamie Madillbc393df2015-01-29 13:46:07 -0500284
Jamie Madill50cf2be2018-06-15 09:46:57 -0400285 GLenum imageFormats[] = {
Jamie Madillb980c562018-11-27 11:34:27 -0500286 GL_R32F,
287 GL_RG32F,
288 GL_RGB32F,
289 GL_RGBA32F,
Jamie Madillbc393df2015-01-29 13:46:07 -0500290 };
291
Jamie Madill50cf2be2018-06-15 09:46:57 -0400292 GLenum sourceUnsizedFormats[] = {
Jamie Madillb980c562018-11-27 11:34:27 -0500293 GL_RED,
294 GL_RG,
295 GL_RGB,
296 GL_RGBA,
Jamie Madillbc393df2015-01-29 13:46:07 -0500297 };
298
299 GLuint textures[2];
300
301 glGenTextures(2, textures);
302
Jamie Madill50cf2be2018-06-15 09:46:57 -0400303 GLfloat *imageData = sourceImageData[sourceImageChannels - 1];
304 GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1];
Jamie Madillbc393df2015-01-29 13:46:07 -0500305 GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1];
Jamie Madill50cf2be2018-06-15 09:46:57 -0400306 GLenum destImageFormat = imageFormats[destImageChannels - 1];
Jamie Madillbc393df2015-01-29 13:46:07 -0500307
308 glBindTexture(GL_TEXTURE_2D, textures[0]);
Geoff Langc4e93662017-05-01 10:45:59 -0400309 if (getClientMajorVersion() >= 3)
310 {
311 glTexStorage2D(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
312 }
313 else
314 {
315 glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
316 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500317 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
318 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
319 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData);
320
Jamie Madillb8149072019-04-30 16:14:44 -0400321 if (sourceImageChannels < 3 && !IsGLExtensionEnabled("GL_EXT_texture_rg"))
Jamie Madillbc393df2015-01-29 13:46:07 -0500322 {
323 // This is not supported
324 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
325 }
326 else
327 {
328 ASSERT_GL_NO_ERROR();
329 }
330
331 GLuint fbo;
332 glGenFramebuffers(1, &fbo);
333 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
334 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
335
336 glBindTexture(GL_TEXTURE_2D, textures[1]);
Geoff Langc4e93662017-05-01 10:45:59 -0400337 if (getClientMajorVersion() >= 3)
338 {
339 glTexStorage2D(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
340 }
341 else
342 {
343 glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
344 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500345 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
346 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
347
348 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
349 ASSERT_GL_NO_ERROR();
350
351 glBindFramebuffer(GL_FRAMEBUFFER, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200352 drawQuad(mProgram, "position", 0.5f);
Jamie Madillbc393df2015-01-29 13:46:07 -0500353
354 int testImageChannels = std::min(sourceImageChannels, destImageChannels);
355
Olli Etuahoa314b612016-03-10 16:43:00 +0200356 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Jamie Madillbc393df2015-01-29 13:46:07 -0500357 if (testImageChannels > 1)
358 {
359 EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255);
360 EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255);
361 if (testImageChannels > 2)
362 {
363 EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255);
364 }
365 }
366
367 glDeleteFramebuffers(1, &fbo);
368 glDeleteTextures(2, textures);
369
370 ASSERT_GL_NO_ERROR();
371 }
372
Jamie Madilld4cfa572014-07-08 10:00:32 -0400373 GLuint mTexture2D;
Jamie Madilld4cfa572014-07-08 10:00:32 -0400374 GLint mTexture2DUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400375};
376
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200377class Texture2DTestES3 : public Texture2DTest
378{
379 protected:
380 Texture2DTestES3() : Texture2DTest() {}
381
Jamie Madill35cd7332018-12-02 12:03:33 -0500382 const char *getVertexShaderSource() override
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200383 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500384 return "#version 300 es\n"
385 "out vec2 texcoord;\n"
386 "in vec4 position;\n"
387 "void main()\n"
388 "{\n"
389 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
390 " texcoord = (position.xy * 0.5) + 0.5;\n"
391 "}\n";
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200392 }
393
Jamie Madill35cd7332018-12-02 12:03:33 -0500394 const char *getFragmentShaderSource() override
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200395 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500396 return "#version 300 es\n"
397 "precision highp float;\n"
398 "uniform highp sampler2D tex;\n"
399 "in vec2 texcoord;\n"
400 "out vec4 fragColor;\n"
401 "void main()\n"
402 "{\n"
403 " fragColor = texture(tex, texcoord);\n"
404 "}\n";
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200405 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300406
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400407 void testSetUp() override
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300408 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400409 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300410 setUpProgram();
411 }
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200412};
413
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200414class Texture2DIntegerAlpha1TestES3 : public Texture2DTest
415{
416 protected:
417 Texture2DIntegerAlpha1TestES3() : Texture2DTest() {}
418
Jamie Madill35cd7332018-12-02 12:03:33 -0500419 const char *getVertexShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200420 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500421 return "#version 300 es\n"
422 "out vec2 texcoord;\n"
423 "in vec4 position;\n"
424 "void main()\n"
425 "{\n"
426 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
427 " texcoord = (position.xy * 0.5) + 0.5;\n"
428 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200429 }
430
Jamie Madill35cd7332018-12-02 12:03:33 -0500431 const char *getFragmentShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200432 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500433 return "#version 300 es\n"
434 "precision highp float;\n"
435 "uniform highp isampler2D tex;\n"
436 "in vec2 texcoord;\n"
437 "out vec4 fragColor;\n"
438 "void main()\n"
439 "{\n"
440 " vec4 green = vec4(0, 1, 0, 1);\n"
441 " vec4 black = vec4(0, 0, 0, 0);\n"
442 " fragColor = (texture(tex, texcoord).a == 1) ? green : black;\n"
443 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200444 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300445
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400446 void testSetUp() override
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300447 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400448 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300449 setUpProgram();
450 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200451};
452
453class Texture2DUnsignedIntegerAlpha1TestES3 : public Texture2DTest
454{
455 protected:
456 Texture2DUnsignedIntegerAlpha1TestES3() : Texture2DTest() {}
457
Jamie Madill35cd7332018-12-02 12:03:33 -0500458 const char *getVertexShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200459 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500460 return "#version 300 es\n"
461 "out vec2 texcoord;\n"
462 "in vec4 position;\n"
463 "void main()\n"
464 "{\n"
465 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
466 " texcoord = (position.xy * 0.5) + 0.5;\n"
467 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200468 }
469
Jamie Madill35cd7332018-12-02 12:03:33 -0500470 const char *getFragmentShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200471 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500472 return "#version 300 es\n"
473 "precision highp float;\n"
474 "uniform highp usampler2D tex;\n"
475 "in vec2 texcoord;\n"
476 "out vec4 fragColor;\n"
477 "void main()\n"
478 "{\n"
479 " vec4 green = vec4(0, 1, 0, 1);\n"
480 " vec4 black = vec4(0, 0, 0, 0);\n"
481 " fragColor = (texture(tex, texcoord).a == 1u) ? green : black;\n"
482 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200483 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300484
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400485 void testSetUp() override
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300486 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400487 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300488 setUpProgram();
489 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200490};
491
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200492class Texture2DTestWithDrawScale : public Texture2DTest
Jamie Madill2453dbc2015-07-14 11:35:42 -0400493{
494 protected:
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200495 Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {}
496
Jamie Madill35cd7332018-12-02 12:03:33 -0500497 const char *getVertexShaderSource() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400498 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300499 return
500 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200501 attribute vec4 position;
502 varying vec2 texcoord;
503
504 uniform vec2 drawScale;
505
506 void main()
507 {
508 gl_Position = vec4(position.xy * drawScale, 0.0, 1.0);
509 texcoord = (position.xy * 0.5) + 0.5;
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300510 })";
Jamie Madill2453dbc2015-07-14 11:35:42 -0400511 }
512
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400513 void testSetUp() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400514 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400515 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300516
517 setUpProgram();
518
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200519 mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale");
520 ASSERT_NE(-1, mDrawScaleUniformLocation);
Jamie Madill2453dbc2015-07-14 11:35:42 -0400521
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200522 glUseProgram(mProgram);
523 glUniform2f(mDrawScaleUniformLocation, 1.0f, 1.0f);
524 glUseProgram(0);
525 ASSERT_GL_NO_ERROR();
526 }
527
528 GLint mDrawScaleUniformLocation;
529};
530
Olli Etuaho4644a202016-01-12 15:12:53 +0200531class Sampler2DAsFunctionParameterTest : public Texture2DTest
532{
533 protected:
534 Sampler2DAsFunctionParameterTest() : Texture2DTest() {}
535
Jamie Madill35cd7332018-12-02 12:03:33 -0500536 const char *getFragmentShaderSource() override
Olli Etuaho4644a202016-01-12 15:12:53 +0200537 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300538 return
539 R"(precision highp float;
Olli Etuaho4644a202016-01-12 15:12:53 +0200540 uniform sampler2D tex;
541 varying vec2 texcoord;
542
543 vec4 computeFragColor(sampler2D aTex)
544 {
545 return texture2D(aTex, texcoord);
546 }
547
548 void main()
549 {
550 gl_FragColor = computeFragColor(tex);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300551 })";
Olli Etuaho4644a202016-01-12 15:12:53 +0200552 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300553
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400554 void testSetUp() override
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300555 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400556 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300557 setUpProgram();
558 }
Olli Etuaho4644a202016-01-12 15:12:53 +0200559};
560
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200561class TextureCubeTest : public TexCoordDrawTest
562{
563 protected:
564 TextureCubeTest()
565 : TexCoordDrawTest(),
566 mTexture2D(0),
567 mTextureCube(0),
568 mTexture2DUniformLocation(-1),
569 mTextureCubeUniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500570 {}
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200571
Jamie Madill35cd7332018-12-02 12:03:33 -0500572 const char *getFragmentShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200573 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300574 return
575 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200576 uniform sampler2D tex2D;
577 uniform samplerCube texCube;
578 varying vec2 texcoord;
579
580 void main()
581 {
582 gl_FragColor = texture2D(tex2D, texcoord);
583 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300584 })";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200585 }
586
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400587 void testSetUp() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200588 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400589 TexCoordDrawTest::testSetUp();
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200590
591 glGenTextures(1, &mTextureCube);
592 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Geoff Langc4e93662017-05-01 10:45:59 -0400593 for (GLenum face = 0; face < 6; face++)
594 {
595 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
596 GL_UNSIGNED_BYTE, nullptr);
597 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200598 EXPECT_GL_NO_ERROR();
599
600 mTexture2D = create2DTexture();
601
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300602 setUpProgram();
603
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200604 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
605 ASSERT_NE(-1, mTexture2DUniformLocation);
606 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
607 ASSERT_NE(-1, mTextureCubeUniformLocation);
608 }
609
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400610 void testTearDown() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200611 {
612 glDeleteTextures(1, &mTextureCube);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400613 TexCoordDrawTest::testTearDown();
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200614 }
615
616 GLuint mTexture2D;
617 GLuint mTextureCube;
618 GLint mTexture2DUniformLocation;
619 GLint mTextureCubeUniformLocation;
620};
621
Martin Radev7e2c0d32017-09-15 14:25:42 +0300622class TextureCubeTestES3 : public ANGLETest
623{
624 protected:
625 TextureCubeTestES3() {}
626};
627
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200628class SamplerArrayTest : public TexCoordDrawTest
629{
630 protected:
631 SamplerArrayTest()
632 : TexCoordDrawTest(),
633 mTexture2DA(0),
634 mTexture2DB(0),
635 mTexture0UniformLocation(-1),
636 mTexture1UniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500637 {}
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200638
Jamie Madill35cd7332018-12-02 12:03:33 -0500639 const char *getFragmentShaderSource() override
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200640 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300641 return
642 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200643 uniform highp sampler2D tex2DArray[2];
644 varying vec2 texcoord;
645 void main()
646 {
647 gl_FragColor = texture2D(tex2DArray[0], texcoord);
648 gl_FragColor += texture2D(tex2DArray[1], texcoord);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300649 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200650 }
651
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400652 void testSetUp() override
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200653 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400654 TexCoordDrawTest::testSetUp();
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200655
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300656 setUpProgram();
657
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200658 mTexture0UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[0]");
659 ASSERT_NE(-1, mTexture0UniformLocation);
660 mTexture1UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[1]");
661 ASSERT_NE(-1, mTexture1UniformLocation);
662
663 mTexture2DA = create2DTexture();
664 mTexture2DB = create2DTexture();
665 ASSERT_GL_NO_ERROR();
666 }
667
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400668 void testTearDown() override
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200669 {
670 glDeleteTextures(1, &mTexture2DA);
671 glDeleteTextures(1, &mTexture2DB);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400672 TexCoordDrawTest::testTearDown();
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200673 }
674
675 void testSamplerArrayDraw()
676 {
677 GLubyte texData[4];
678 texData[0] = 0;
679 texData[1] = 60;
680 texData[2] = 0;
681 texData[3] = 255;
682
683 glActiveTexture(GL_TEXTURE0);
684 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
685 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
686
687 texData[1] = 120;
688 glActiveTexture(GL_TEXTURE1);
689 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
690 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
691 EXPECT_GL_ERROR(GL_NO_ERROR);
692
693 glUseProgram(mProgram);
694 glUniform1i(mTexture0UniformLocation, 0);
695 glUniform1i(mTexture1UniformLocation, 1);
696 drawQuad(mProgram, "position", 0.5f);
697 EXPECT_GL_NO_ERROR();
698
699 EXPECT_PIXEL_NEAR(0, 0, 0, 180, 0, 255, 2);
700 }
701
702 GLuint mTexture2DA;
703 GLuint mTexture2DB;
704 GLint mTexture0UniformLocation;
705 GLint mTexture1UniformLocation;
706};
707
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200708class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest
709{
710 protected:
711 SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {}
712
Jamie Madill35cd7332018-12-02 12:03:33 -0500713 const char *getFragmentShaderSource() override
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200714 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300715 return
716 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200717 uniform highp sampler2D tex2DArray[2];
718 varying vec2 texcoord;
719
720 vec4 computeFragColor(highp sampler2D aTex2DArray[2])
721 {
722 return texture2D(aTex2DArray[0], texcoord) + texture2D(aTex2DArray[1], texcoord);
723 }
724
725 void main()
726 {
727 gl_FragColor = computeFragColor(tex2DArray);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300728 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200729 }
730};
731
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200732class Texture2DArrayTestES3 : public TexCoordDrawTest
733{
734 protected:
735 Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {}
736
Jamie Madill35cd7332018-12-02 12:03:33 -0500737 const char *getVertexShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200738 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500739 return "#version 300 es\n"
740 "out vec2 texcoord;\n"
741 "in vec4 position;\n"
742 "void main()\n"
743 "{\n"
744 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
745 " texcoord = (position.xy * 0.5) + 0.5;\n"
746 "}\n";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200747 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400748
Jamie Madill35cd7332018-12-02 12:03:33 -0500749 const char *getFragmentShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200750 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500751 return "#version 300 es\n"
752 "precision highp float;\n"
753 "uniform highp sampler2DArray tex2DArray;\n"
754 "in vec2 texcoord;\n"
755 "out vec4 fragColor;\n"
756 "void main()\n"
757 "{\n"
758 " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n"
759 "}\n";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200760 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400761
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400762 void testSetUp() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200763 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400764 TexCoordDrawTest::testSetUp();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400765
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300766 setUpProgram();
767
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200768 mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray");
Jamie Madill2453dbc2015-07-14 11:35:42 -0400769 ASSERT_NE(-1, mTextureArrayLocation);
770
771 glGenTextures(1, &m2DArrayTexture);
772 ASSERT_GL_NO_ERROR();
773 }
774
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400775 void testTearDown() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400776 {
777 glDeleteTextures(1, &m2DArrayTexture);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400778 TexCoordDrawTest::testTearDown();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400779 }
780
781 GLuint m2DArrayTexture;
Jamie Madill2453dbc2015-07-14 11:35:42 -0400782 GLint mTextureArrayLocation;
783};
784
Olli Etuahobce743a2016-01-15 17:18:28 +0200785class TextureSizeTextureArrayTest : public TexCoordDrawTest
786{
787 protected:
788 TextureSizeTextureArrayTest()
789 : TexCoordDrawTest(),
790 mTexture2DA(0),
791 mTexture2DB(0),
792 mTexture0Location(-1),
793 mTexture1Location(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500794 {}
Olli Etuahobce743a2016-01-15 17:18:28 +0200795
Jamie Madill35cd7332018-12-02 12:03:33 -0500796 const char *getVertexShaderSource() override { return essl3_shaders::vs::Simple(); }
Olli Etuahobce743a2016-01-15 17:18:28 +0200797
Jamie Madill35cd7332018-12-02 12:03:33 -0500798 const char *getFragmentShaderSource() override
Olli Etuahobce743a2016-01-15 17:18:28 +0200799 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500800 return "#version 300 es\n"
801 "precision highp float;\n"
802 "uniform highp sampler2D tex2DArray[2];\n"
803 "out vec4 fragColor;\n"
804 "void main()\n"
805 "{\n"
806 " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n"
807 " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n"
808 " fragColor = vec4(red, green, 0.0, 1.0);\n"
809 "}\n";
Olli Etuahobce743a2016-01-15 17:18:28 +0200810 }
811
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400812 void testSetUp() override
Olli Etuahobce743a2016-01-15 17:18:28 +0200813 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400814 TexCoordDrawTest::testSetUp();
Olli Etuahobce743a2016-01-15 17:18:28 +0200815
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300816 setUpProgram();
817
Olli Etuahobce743a2016-01-15 17:18:28 +0200818 mTexture0Location = glGetUniformLocation(mProgram, "tex2DArray[0]");
819 ASSERT_NE(-1, mTexture0Location);
820 mTexture1Location = glGetUniformLocation(mProgram, "tex2DArray[1]");
821 ASSERT_NE(-1, mTexture1Location);
822
823 mTexture2DA = create2DTexture();
824 mTexture2DB = create2DTexture();
825 ASSERT_GL_NO_ERROR();
826 }
827
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400828 void testTearDown() override
Olli Etuahobce743a2016-01-15 17:18:28 +0200829 {
830 glDeleteTextures(1, &mTexture2DA);
831 glDeleteTextures(1, &mTexture2DB);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400832 TexCoordDrawTest::testTearDown();
Olli Etuahobce743a2016-01-15 17:18:28 +0200833 }
834
835 GLuint mTexture2DA;
836 GLuint mTexture2DB;
837 GLint mTexture0Location;
838 GLint mTexture1Location;
839};
840
Olli Etuahoa314b612016-03-10 16:43:00 +0200841class Texture3DTestES3 : public TexCoordDrawTest
842{
843 protected:
844 Texture3DTestES3() : TexCoordDrawTest(), mTexture3D(0), mTexture3DUniformLocation(-1) {}
845
Jamie Madill35cd7332018-12-02 12:03:33 -0500846 const char *getVertexShaderSource() override
Olli Etuahoa314b612016-03-10 16:43:00 +0200847 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500848 return "#version 300 es\n"
849 "out vec2 texcoord;\n"
850 "in vec4 position;\n"
851 "void main()\n"
852 "{\n"
853 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
854 " texcoord = (position.xy * 0.5) + 0.5;\n"
855 "}\n";
Olli Etuahoa314b612016-03-10 16:43:00 +0200856 }
857
Jamie Madill35cd7332018-12-02 12:03:33 -0500858 const char *getFragmentShaderSource() override
Olli Etuahoa314b612016-03-10 16:43:00 +0200859 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500860 return "#version 300 es\n"
861 "precision highp float;\n"
862 "uniform highp sampler3D tex3D;\n"
863 "in vec2 texcoord;\n"
864 "out vec4 fragColor;\n"
865 "void main()\n"
866 "{\n"
867 " fragColor = texture(tex3D, vec3(texcoord, 0.0));\n"
868 "}\n";
Olli Etuahoa314b612016-03-10 16:43:00 +0200869 }
870
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400871 void testSetUp() override
Olli Etuahoa314b612016-03-10 16:43:00 +0200872 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400873 TexCoordDrawTest::testSetUp();
Olli Etuahoa314b612016-03-10 16:43:00 +0200874
875 glGenTextures(1, &mTexture3D);
876
877 setUpProgram();
878
879 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
880 ASSERT_NE(-1, mTexture3DUniformLocation);
881 }
882
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400883 void testTearDown() override
Olli Etuahoa314b612016-03-10 16:43:00 +0200884 {
885 glDeleteTextures(1, &mTexture3D);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400886 TexCoordDrawTest::testTearDown();
Olli Etuahoa314b612016-03-10 16:43:00 +0200887 }
888
889 GLuint mTexture3D;
890 GLint mTexture3DUniformLocation;
891};
892
Olli Etuaho1a679902016-01-14 12:21:47 +0200893class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest
894{
895 protected:
896 ShadowSamplerPlusSampler3DTestES3()
897 : TexCoordDrawTest(),
898 mTextureShadow(0),
899 mTexture3D(0),
900 mTextureShadowUniformLocation(-1),
901 mTexture3DUniformLocation(-1),
902 mDepthRefUniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500903 {}
Olli Etuaho1a679902016-01-14 12:21:47 +0200904
Jamie Madill35cd7332018-12-02 12:03:33 -0500905 const char *getVertexShaderSource() override
Olli Etuaho1a679902016-01-14 12:21:47 +0200906 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500907 return "#version 300 es\n"
908 "out vec2 texcoord;\n"
909 "in vec4 position;\n"
910 "void main()\n"
911 "{\n"
912 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
913 " texcoord = (position.xy * 0.5) + 0.5;\n"
914 "}\n";
Olli Etuaho1a679902016-01-14 12:21:47 +0200915 }
916
Jamie Madill35cd7332018-12-02 12:03:33 -0500917 const char *getFragmentShaderSource() override
Olli Etuaho1a679902016-01-14 12:21:47 +0200918 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500919 return "#version 300 es\n"
920 "precision highp float;\n"
921 "uniform highp sampler2DShadow tex2DShadow;\n"
922 "uniform highp sampler3D tex3D;\n"
923 "in vec2 texcoord;\n"
924 "uniform float depthRef;\n"
925 "out vec4 fragColor;\n"
926 "void main()\n"
927 "{\n"
928 " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n"
929 " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n"
930 "}\n";
Olli Etuaho1a679902016-01-14 12:21:47 +0200931 }
932
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400933 void testSetUp() override
Olli Etuaho1a679902016-01-14 12:21:47 +0200934 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400935 TexCoordDrawTest::testSetUp();
Olli Etuaho1a679902016-01-14 12:21:47 +0200936
937 glGenTextures(1, &mTexture3D);
938
939 glGenTextures(1, &mTextureShadow);
940 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
941 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
942
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300943 setUpProgram();
944
Olli Etuaho1a679902016-01-14 12:21:47 +0200945 mTextureShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
946 ASSERT_NE(-1, mTextureShadowUniformLocation);
947 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
948 ASSERT_NE(-1, mTexture3DUniformLocation);
949 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
950 ASSERT_NE(-1, mDepthRefUniformLocation);
951 }
952
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400953 void testTearDown() override
Olli Etuaho1a679902016-01-14 12:21:47 +0200954 {
955 glDeleteTextures(1, &mTextureShadow);
956 glDeleteTextures(1, &mTexture3D);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400957 TexCoordDrawTest::testTearDown();
Olli Etuaho1a679902016-01-14 12:21:47 +0200958 }
959
960 GLuint mTextureShadow;
961 GLuint mTexture3D;
962 GLint mTextureShadowUniformLocation;
963 GLint mTexture3DUniformLocation;
964 GLint mDepthRefUniformLocation;
965};
966
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200967class SamplerTypeMixTestES3 : public TexCoordDrawTest
968{
969 protected:
970 SamplerTypeMixTestES3()
971 : TexCoordDrawTest(),
972 mTexture2D(0),
973 mTextureCube(0),
974 mTexture2DShadow(0),
975 mTextureCubeShadow(0),
976 mTexture2DUniformLocation(-1),
977 mTextureCubeUniformLocation(-1),
978 mTexture2DShadowUniformLocation(-1),
979 mTextureCubeShadowUniformLocation(-1),
980 mDepthRefUniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500981 {}
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200982
Jamie Madill35cd7332018-12-02 12:03:33 -0500983 const char *getVertexShaderSource() override
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200984 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500985 return "#version 300 es\n"
986 "out vec2 texcoord;\n"
987 "in vec4 position;\n"
988 "void main()\n"
989 "{\n"
990 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
991 " texcoord = (position.xy * 0.5) + 0.5;\n"
992 "}\n";
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200993 }
994
Jamie Madill35cd7332018-12-02 12:03:33 -0500995 const char *getFragmentShaderSource() override
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200996 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500997 return "#version 300 es\n"
998 "precision highp float;\n"
999 "uniform highp sampler2D tex2D;\n"
1000 "uniform highp samplerCube texCube;\n"
1001 "uniform highp sampler2DShadow tex2DShadow;\n"
1002 "uniform highp samplerCubeShadow texCubeShadow;\n"
1003 "in vec2 texcoord;\n"
1004 "uniform float depthRef;\n"
1005 "out vec4 fragColor;\n"
1006 "void main()\n"
1007 "{\n"
1008 " fragColor = texture(tex2D, texcoord);\n"
1009 " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n"
1010 " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n"
1011 " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * "
1012 "0.125);\n"
1013 "}\n";
Olli Etuahoc8c99a02016-01-14 16:47:22 +02001014 }
1015
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04001016 void testSetUp() override
Olli Etuahoc8c99a02016-01-14 16:47:22 +02001017 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04001018 TexCoordDrawTest::testSetUp();
Olli Etuahoc8c99a02016-01-14 16:47:22 +02001019
1020 glGenTextures(1, &mTexture2D);
1021 glGenTextures(1, &mTextureCube);
1022
1023 glGenTextures(1, &mTexture2DShadow);
1024 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
1025 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
1026
1027 glGenTextures(1, &mTextureCubeShadow);
1028 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
1029 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
1030
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001031 setUpProgram();
1032
Olli Etuahoc8c99a02016-01-14 16:47:22 +02001033 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
1034 ASSERT_NE(-1, mTexture2DUniformLocation);
1035 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
1036 ASSERT_NE(-1, mTextureCubeUniformLocation);
1037 mTexture2DShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
1038 ASSERT_NE(-1, mTexture2DShadowUniformLocation);
1039 mTextureCubeShadowUniformLocation = glGetUniformLocation(mProgram, "texCubeShadow");
1040 ASSERT_NE(-1, mTextureCubeShadowUniformLocation);
1041 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
1042 ASSERT_NE(-1, mDepthRefUniformLocation);
1043
1044 ASSERT_GL_NO_ERROR();
1045 }
1046
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04001047 void testTearDown() override
Olli Etuahoc8c99a02016-01-14 16:47:22 +02001048 {
1049 glDeleteTextures(1, &mTexture2D);
1050 glDeleteTextures(1, &mTextureCube);
1051 glDeleteTextures(1, &mTexture2DShadow);
1052 glDeleteTextures(1, &mTextureCubeShadow);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04001053 TexCoordDrawTest::testTearDown();
Olli Etuahoc8c99a02016-01-14 16:47:22 +02001054 }
1055
1056 GLuint mTexture2D;
1057 GLuint mTextureCube;
1058 GLuint mTexture2DShadow;
1059 GLuint mTextureCubeShadow;
1060 GLint mTexture2DUniformLocation;
1061 GLint mTextureCubeUniformLocation;
1062 GLint mTexture2DShadowUniformLocation;
1063 GLint mTextureCubeShadowUniformLocation;
1064 GLint mDepthRefUniformLocation;
1065};
1066
Olli Etuaho96963162016-03-21 11:54:33 +02001067class SamplerInStructTest : public Texture2DTest
1068{
1069 protected:
1070 SamplerInStructTest() : Texture2DTest() {}
1071
1072 const char *getTextureUniformName() override { return "us.tex"; }
1073
Jamie Madill35cd7332018-12-02 12:03:33 -05001074 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001075 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001076 return "precision highp float;\n"
1077 "struct S\n"
1078 "{\n"
1079 " vec4 a;\n"
1080 " highp sampler2D tex;\n"
1081 "};\n"
1082 "uniform S us;\n"
1083 "varying vec2 texcoord;\n"
1084 "void main()\n"
1085 "{\n"
1086 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x);\n"
1087 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001088 }
1089
1090 void runSamplerInStructTest()
1091 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001092 setUpProgram();
1093
Olli Etuaho96963162016-03-21 11:54:33 +02001094 glActiveTexture(GL_TEXTURE0);
1095 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001096 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1097 &GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001098 drawQuad(mProgram, "position", 0.5f);
Olli Etuahoa314b612016-03-10 16:43:00 +02001099 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001100 }
1101};
1102
1103class SamplerInStructAsFunctionParameterTest : public SamplerInStructTest
1104{
1105 protected:
1106 SamplerInStructAsFunctionParameterTest() : SamplerInStructTest() {}
1107
Jamie Madill35cd7332018-12-02 12:03:33 -05001108 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001109 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001110 return "precision highp float;\n"
1111 "struct S\n"
1112 "{\n"
1113 " vec4 a;\n"
1114 " highp sampler2D tex;\n"
1115 "};\n"
1116 "uniform S us;\n"
1117 "varying vec2 texcoord;\n"
1118 "vec4 sampleFrom(S s) {\n"
1119 " return texture2D(s.tex, texcoord + s.a.x);\n"
1120 "}\n"
1121 "void main()\n"
1122 "{\n"
1123 " gl_FragColor = sampleFrom(us);\n"
1124 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001125 }
1126};
1127
1128class SamplerInStructArrayAsFunctionParameterTest : public SamplerInStructTest
1129{
1130 protected:
1131 SamplerInStructArrayAsFunctionParameterTest() : SamplerInStructTest() {}
1132
1133 const char *getTextureUniformName() override { return "us[0].tex"; }
1134
Jamie Madill35cd7332018-12-02 12:03:33 -05001135 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001136 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001137 return "precision highp float;\n"
1138 "struct S\n"
1139 "{\n"
1140 " vec4 a;\n"
1141 " highp sampler2D tex;\n"
1142 "};\n"
1143 "uniform S us[1];\n"
1144 "varying vec2 texcoord;\n"
1145 "vec4 sampleFrom(S s) {\n"
1146 " return texture2D(s.tex, texcoord + s.a.x);\n"
1147 "}\n"
1148 "void main()\n"
1149 "{\n"
1150 " gl_FragColor = sampleFrom(us[0]);\n"
1151 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001152 }
1153};
1154
1155class SamplerInNestedStructAsFunctionParameterTest : public SamplerInStructTest
1156{
1157 protected:
1158 SamplerInNestedStructAsFunctionParameterTest() : SamplerInStructTest() {}
1159
1160 const char *getTextureUniformName() override { return "us[0].sub.tex"; }
1161
Jamie Madill35cd7332018-12-02 12:03:33 -05001162 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001163 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001164 return "precision highp float;\n"
1165 "struct SUB\n"
1166 "{\n"
1167 " vec4 a;\n"
1168 " highp sampler2D tex;\n"
1169 "};\n"
1170 "struct S\n"
1171 "{\n"
1172 " SUB sub;\n"
1173 "};\n"
1174 "uniform S us[1];\n"
1175 "varying vec2 texcoord;\n"
1176 "vec4 sampleFrom(SUB s) {\n"
1177 " return texture2D(s.tex, texcoord + s.a.x);\n"
1178 "}\n"
1179 "void main()\n"
1180 "{\n"
1181 " gl_FragColor = sampleFrom(us[0].sub);\n"
1182 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001183 }
1184};
1185
1186class SamplerInStructAndOtherVariableTest : public SamplerInStructTest
1187{
1188 protected:
1189 SamplerInStructAndOtherVariableTest() : SamplerInStructTest() {}
1190
Jamie Madill35cd7332018-12-02 12:03:33 -05001191 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001192 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001193 return "precision highp float;\n"
1194 "struct S\n"
1195 "{\n"
1196 " vec4 a;\n"
1197 " highp sampler2D tex;\n"
1198 "};\n"
1199 "uniform S us;\n"
1200 "uniform float us_tex;\n"
1201 "varying vec2 texcoord;\n"
1202 "void main()\n"
1203 "{\n"
1204 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x + us_tex);\n"
1205 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001206 }
1207};
1208
Anders Leinof6cbe442019-04-18 15:32:07 +03001209class Texture2DIntegerTestES3 : public Texture2DTest
1210{
1211 protected:
1212 Texture2DIntegerTestES3() : Texture2DTest() {}
1213
1214 const char *getVertexShaderSource() override
1215 {
1216 return "#version 300 es\n"
1217 "out vec2 texcoord;\n"
1218 "in vec4 position;\n"
1219 "void main()\n"
1220 "{\n"
1221 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1222 " texcoord = (position.xy * 0.5) + 0.5;\n"
1223 "}\n";
1224 }
1225
1226 const char *getFragmentShaderSource() override
1227 {
1228 return "#version 300 es\n"
1229 "precision highp float;\n"
1230 "precision highp usampler2D;\n"
1231 "uniform usampler2D tex;\n"
1232 "in vec2 texcoord;\n"
1233 "out vec4 fragColor;\n"
1234 "void main()\n"
1235 "{\n"
Anders Leino8224a582019-05-20 12:39:29 +03001236 " fragColor = vec4(texture(tex, texcoord))/255.0;\n"
Anders Leinof6cbe442019-04-18 15:32:07 +03001237 "}\n";
1238 }
1239};
1240
Anders Leino60cc7512019-05-06 09:25:27 +03001241class TextureCubeIntegerTestES3 : public TexCoordDrawTest
1242{
1243 protected:
1244 TextureCubeIntegerTestES3()
1245 : TexCoordDrawTest(), mTextureCube(0), mTextureCubeUniformLocation(-1)
1246 {}
1247
1248 const char *getVertexShaderSource() override
1249 {
1250 return "#version 300 es\n"
1251 "out vec2 texcoord;\n"
1252 "in vec4 position;\n"
1253 "void main()\n"
1254 "{\n"
1255 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1256 " texcoord = 0.5*position.xy;\n"
1257 "}\n";
1258 }
1259
1260 const char *getFragmentShaderSource() override
1261 {
1262 return "#version 300 es\n"
1263 "precision highp float;\n"
1264 "precision highp usamplerCube;\n"
1265 "uniform usamplerCube texCube;\n"
1266 "in vec2 texcoord;\n"
1267 "out vec4 fragColor;\n"
1268 "void main()\n"
1269 "{\n"
1270 " fragColor = vec4(texture(texCube, vec3(texcoord, 1)))/255.0;\n"
1271 "}\n";
1272 }
1273
1274 void testSetUp() override
1275 {
1276 TexCoordDrawTest::testSetUp();
1277 glGenTextures(1, &mTextureCube);
1278 setUpProgram();
1279
1280 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
1281 ASSERT_NE(-1, mTextureCubeUniformLocation);
1282 }
1283
1284 void testTearDown() override
1285 {
1286 glDeleteTextures(1, &mTextureCube);
1287 TexCoordDrawTest::testTearDown();
1288 }
1289
1290 GLuint mTextureCube;
1291 GLint mTextureCubeUniformLocation;
1292};
1293
Anders Leinoe4452442019-05-09 13:29:49 +03001294class TextureCubeIntegerEdgeTestES3 : public TextureCubeIntegerTestES3
1295{
1296 protected:
1297 TextureCubeIntegerEdgeTestES3() : TextureCubeIntegerTestES3() {}
1298
1299 const char *getVertexShaderSource() override
1300 {
1301 return "#version 300 es\n"
1302 "out vec2 texcoord;\n"
1303 "in vec4 position;\n"
1304 "void main()\n"
1305 "{\n"
1306 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1307 " texcoord = position.xy;\n"
1308 "}\n";
1309 }
1310
1311 const char *getFragmentShaderSource() override
1312 {
1313 return "#version 300 es\n"
1314 "precision highp float;\n"
1315 "precision highp usamplerCube;\n"
1316 "uniform usamplerCube texCube;\n"
1317 "in vec2 texcoord;\n"
1318 "out vec4 fragColor;\n"
1319 "void main()\n"
1320 "{\n"
1321 " fragColor = vec4(texture(texCube, vec3(texcoord, 0)))/255.0;\n"
1322 "}\n";
1323 }
1324};
1325
Anders Leino1b6aded2019-05-20 12:56:34 +03001326class Texture2DIntegerProjectiveOffsetTestES3 : public Texture2DTest
1327{
1328 protected:
1329 Texture2DIntegerProjectiveOffsetTestES3() : Texture2DTest() {}
1330
1331 const char *getVertexShaderSource() override
1332 {
1333 return "#version 300 es\n"
1334 "out vec2 texcoord;\n"
1335 "in vec4 position;\n"
1336 "void main()\n"
1337 "{\n"
1338 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1339 " texcoord = 0.5*position.xy + vec2(0.5, 0.5);\n"
1340 "}\n";
1341 }
1342
1343 const char *getFragmentShaderSource() override
1344 {
1345 return "#version 300 es\n"
1346 "precision highp float;\n"
1347 "precision highp usampler2D;\n"
1348 "uniform usampler2D tex;\n"
1349 "in vec2 texcoord;\n"
1350 "out vec4 fragColor;\n"
1351 "void main()\n"
1352 "{\n"
1353 " fragColor = vec4(textureProjOffset(tex, vec3(texcoord, 1), ivec2(0,0), "
1354 "0.0))/255.0;\n"
1355 "}\n";
1356 }
1357};
1358
Anders Leino69d04932019-05-20 14:04:13 +03001359class Texture2DArrayIntegerTestES3 : public Texture2DArrayTestES3
1360{
1361 protected:
1362 Texture2DArrayIntegerTestES3() : Texture2DArrayTestES3() {}
1363
1364 const char *getVertexShaderSource() override
1365 {
1366 return "#version 300 es\n"
1367 "out vec2 texcoord;\n"
1368 "in vec4 position;\n"
1369 "void main()\n"
1370 "{\n"
1371 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1372 " texcoord = (position.xy * 0.5) + 0.5;\n"
1373 "}\n";
1374 }
1375
1376 const char *getFragmentShaderSource() override
1377 {
1378 return "#version 300 es\n"
1379 "precision highp float;\n"
1380 "uniform highp usampler2DArray tex2DArray;\n"
1381 "in vec2 texcoord;\n"
1382 "out vec4 fragColor;\n"
1383 "void main()\n"
1384 "{\n"
1385 " fragColor = vec4(texture(tex2DArray, vec3(texcoord.x, texcoord.y, "
1386 "0.0)))/255.0;\n"
1387 "}\n";
1388 }
1389};
1390
Anders Leino262e2822019-05-20 14:24:40 +03001391class Texture3DIntegerTestES3 : public Texture3DTestES3
1392{
1393 protected:
1394 Texture3DIntegerTestES3() : Texture3DTestES3() {}
1395
1396 const char *getVertexShaderSource() override
1397 {
1398 return "#version 300 es\n"
1399 "out vec2 texcoord;\n"
1400 "in vec4 position;\n"
1401 "void main()\n"
1402 "{\n"
1403 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1404 " texcoord = (position.xy * 0.5) + 0.5;\n"
1405 "}\n";
1406 }
1407
1408 const char *getFragmentShaderSource() override
1409 {
1410 return "#version 300 es\n"
1411 "precision highp float;\n"
1412 "uniform highp usampler3D tex3D;\n"
1413 "in vec2 texcoord;\n"
1414 "out vec4 fragColor;\n"
1415 "void main()\n"
1416 "{\n"
1417 " fragColor = vec4(texture(tex3D, vec3(texcoord, 0.0)))/255.0;\n"
1418 "}\n";
1419 }
1420};
1421
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001422TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001423{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001424 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001425 EXPECT_GL_ERROR(GL_NO_ERROR);
1426
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001427 setUpProgram();
1428
Jamie Madill50cf2be2018-06-15 09:46:57 -04001429 const GLubyte *pixels[20] = {0};
Jamie Madillf67115c2014-04-22 13:14:05 -04001430 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1431 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001432
Jamie Madillb8149072019-04-30 16:14:44 -04001433 if (IsGLExtensionEnabled("GL_EXT_texture_storage"))
Geoff Langc51642b2016-11-14 16:18:26 -05001434 {
1435 // Create a 1-level immutable texture.
1436 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1437
1438 // Try calling sub image on the second level.
1439 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1440 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1441 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001442}
Geoff Langc41e42d2014-04-28 10:58:16 -04001443
John Bauman18319182016-09-28 14:22:27 -07001444// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1445TEST_P(Texture2DTest, QueryBinding)
1446{
1447 glBindTexture(GL_TEXTURE_2D, 0);
1448 EXPECT_GL_ERROR(GL_NO_ERROR);
1449
1450 GLint textureBinding;
1451 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1452 EXPECT_GL_NO_ERROR();
1453 EXPECT_EQ(0, textureBinding);
1454
1455 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
Jamie Madillb8149072019-04-30 16:14:44 -04001456 if (IsGLExtensionEnabled("GL_OES_EGL_image_external") ||
1457 IsGLExtensionEnabled("GL_NV_EGL_stream_consumer_external"))
John Bauman18319182016-09-28 14:22:27 -07001458 {
1459 EXPECT_GL_NO_ERROR();
1460 EXPECT_EQ(0, textureBinding);
1461 }
1462 else
1463 {
1464 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1465 }
1466}
1467
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001468TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001469{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001470 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001471 EXPECT_GL_ERROR(GL_NO_ERROR);
1472
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001473 setUpProgram();
1474
Geoff Langc41e42d2014-04-28 10:58:16 -04001475 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001476 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001477 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001478 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001479
Jamie Madill50cf2be2018-06-15 09:46:57 -04001480 const GLubyte *pixel[4] = {0};
Geoff Langc41e42d2014-04-28 10:58:16 -04001481
1482 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1483 EXPECT_GL_NO_ERROR();
1484
1485 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1486 EXPECT_GL_NO_ERROR();
1487
1488 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1489 EXPECT_GL_NO_ERROR();
1490}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001491
1492// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001493TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001494{
1495 glActiveTexture(GL_TEXTURE0);
1496 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1497 glActiveTexture(GL_TEXTURE1);
1498 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1499 EXPECT_GL_ERROR(GL_NO_ERROR);
1500
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001501 glUseProgram(mProgram);
1502 glUniform1i(mTexture2DUniformLocation, 0);
1503 glUniform1i(mTextureCubeUniformLocation, 1);
1504 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001505 EXPECT_GL_NO_ERROR();
1506}
Jamie Madill9aca0592014-10-06 16:26:59 -04001507
Olli Etuaho53a2da12016-01-11 15:43:32 +02001508// Test drawing with two texture types accessed from the same shader and check that the result of
1509// drawing is correct.
1510TEST_P(TextureCubeTest, CubeMapDraw)
1511{
1512 GLubyte texData[4];
1513 texData[0] = 0;
1514 texData[1] = 60;
1515 texData[2] = 0;
1516 texData[3] = 255;
1517
1518 glActiveTexture(GL_TEXTURE0);
1519 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1520 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1521
1522 glActiveTexture(GL_TEXTURE1);
1523 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1524 texData[1] = 120;
1525 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1526 texData);
1527 EXPECT_GL_ERROR(GL_NO_ERROR);
1528
1529 glUseProgram(mProgram);
1530 glUniform1i(mTexture2DUniformLocation, 0);
1531 glUniform1i(mTextureCubeUniformLocation, 1);
1532 drawQuad(mProgram, "position", 0.5f);
1533 EXPECT_GL_NO_ERROR();
1534
1535 int px = getWindowWidth() - 1;
1536 int py = 0;
1537 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1538}
1539
Olli Etuaho4644a202016-01-12 15:12:53 +02001540TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1541{
1542 glActiveTexture(GL_TEXTURE0);
1543 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1544 GLubyte texData[4];
1545 texData[0] = 0;
1546 texData[1] = 128;
1547 texData[2] = 0;
1548 texData[3] = 255;
1549 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1550 glUseProgram(mProgram);
1551 glUniform1i(mTexture2DUniformLocation, 0);
1552 drawQuad(mProgram, "position", 0.5f);
1553 EXPECT_GL_NO_ERROR();
1554
1555 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1556}
1557
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001558// Test drawing with two textures passed to the shader in a sampler array.
1559TEST_P(SamplerArrayTest, SamplerArrayDraw)
1560{
1561 testSamplerArrayDraw();
1562}
1563
1564// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1565// user-defined function in the shader.
1566TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1567{
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05001568 // TODO: Diagnose and fix. http://anglebug.com/2955
1569 ANGLE_SKIP_TEST_IF(IsVulkan() && IsAndroid());
1570
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001571 testSamplerArrayDraw();
1572}
1573
Jamie Madill9aca0592014-10-06 16:26:59 -04001574// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001575TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001576{
1577 int px = getWindowWidth() / 2;
1578 int py = getWindowHeight() / 2;
1579
1580 glActiveTexture(GL_TEXTURE0);
1581 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1582
Olli Etuahoa314b612016-03-10 16:43:00 +02001583 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001584
Olli Etuahoa314b612016-03-10 16:43:00 +02001585 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001586 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1587 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1588 glGenerateMipmap(GL_TEXTURE_2D);
1589
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001590 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001591 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001592 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1593 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001594 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001595 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001596
Olli Etuahoa314b612016-03-10 16:43:00 +02001597 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001598
Olli Etuahoa314b612016-03-10 16:43:00 +02001599 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1600 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001601 glGenerateMipmap(GL_TEXTURE_2D);
1602
Olli Etuahoa314b612016-03-10 16:43:00 +02001603 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001604
Olli Etuahoa314b612016-03-10 16:43:00 +02001605 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1606 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001607 glGenerateMipmap(GL_TEXTURE_2D);
1608
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001609 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001610
1611 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001612 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001613}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001614
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001615// Test creating a FBO with a cube map render target, to test an ANGLE bug
1616// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001617TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001618{
Michael Spangd8506c72019-01-29 15:35:09 -05001619 // http://anglebug.com/3145
1620 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
1621
Shahbaz Youssefi0c128e12019-03-25 23:50:14 -04001622 // http://anglebug.com/2822
1623 ANGLE_SKIP_TEST_IF(IsWindows() && IsIntel() && IsVulkan());
1624
Jamie Madill3f3b3582018-09-14 10:38:44 -04001625 GLFramebuffer fbo;
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001626 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1627
1628 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Jamie Madill50cf2be2018-06-15 09:46:57 -04001629 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1630 mTextureCube, 0);
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001631
Corentin Wallez322653b2015-06-17 18:33:56 +02001632 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001633 EXPECT_GL_NO_ERROR();
Jamie Madill3f3b3582018-09-14 10:38:44 -04001634
1635 // Test clearing the six mip faces individually.
1636 std::array<GLColor, 6> faceColors = {{GLColor::red, GLColor::green, GLColor::blue,
1637 GLColor::yellow, GLColor::cyan, GLColor::magenta}};
1638
1639 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1640 {
1641 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1642 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1643
1644 Vector4 clearColorF = faceColors[faceIndex].toNormalizedVector();
1645 glClearColor(clearColorF.x(), clearColorF.y(), clearColorF.z(), clearColorF.w());
1646 glClear(GL_COLOR_BUFFER_BIT);
1647
1648 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex]);
1649 }
1650
1651 // Iterate the faces again to make sure the colors haven't changed.
1652 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1653 {
1654 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1655 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1656 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex])
1657 << "face color " << faceIndex << " shouldn't change";
1658 }
1659}
1660
1661// Tests clearing a cube map with a scissor enabled.
1662TEST_P(TextureCubeTest, CubeMapFBOScissoredClear)
1663{
1664 // TODO(jie.a.chen): Diagnose and fix. http://anglebug.com/2822
1665 ANGLE_SKIP_TEST_IF(IsVulkan() && IsIntel() && IsWindows());
1666
Michael Spangd8506c72019-01-29 15:35:09 -05001667 // http://anglebug.com/3145
1668 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
1669
Jamie Madill3f3b3582018-09-14 10:38:44 -04001670 constexpr size_t kSize = 16;
1671
1672 GLFramebuffer fbo;
1673 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1674 glViewport(0, 0, kSize, kSize);
1675
1676 GLTexture texcube;
1677 glBindTexture(GL_TEXTURE_CUBE_MAP, texcube);
1678 for (GLenum face = 0; face < 6; face++)
1679 {
1680 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA,
1681 GL_UNSIGNED_BYTE, nullptr);
1682 }
1683 ASSERT_GL_NO_ERROR();
1684
1685 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1686 texcube, 0);
1687
1688 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1689 ASSERT_GL_NO_ERROR();
1690
1691 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1692 glClear(GL_COLOR_BUFFER_BIT);
1693 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1694
1695 glEnable(GL_SCISSOR_TEST);
1696 glScissor(kSize / 2, 0, kSize / 2, kSize);
1697 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
1698 glClear(GL_COLOR_BUFFER_BIT);
1699
1700 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1701 EXPECT_PIXEL_COLOR_EQ(kSize / 2 + 1, 0, GLColor::green);
1702
1703 ASSERT_GL_NO_ERROR();
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001704}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001705
Jamie Madill50cf2be2018-06-15 09:46:57 -04001706// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a
1707// default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001708TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001709{
Jamie Madillb8149072019-04-30 16:14:44 -04001710 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 &&
1711 !IsGLExtensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -04001712
Jamie Madill50cf2be2018-06-15 09:46:57 -04001713 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001714 int height = getWindowHeight();
1715
1716 GLuint tex2D;
1717 glGenTextures(1, &tex2D);
1718 glActiveTexture(GL_TEXTURE0);
1719 glBindTexture(GL_TEXTURE_2D, tex2D);
1720
1721 // Fill with red
1722 std::vector<GLubyte> pixels(3 * 16 * 16);
1723 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1724 {
1725 pixels[pixelId * 3 + 0] = 255;
1726 pixels[pixelId * 3 + 1] = 0;
1727 pixels[pixelId * 3 + 2] = 0;
1728 }
1729
1730 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001731 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1732 // 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 -04001733 if (getClientMajorVersion() >= 3)
1734 {
1735 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1736 }
1737 else
1738 {
1739 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1740 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001741
1742 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1743 // glTexSubImage2D should take into account that the image is dirty.
1744 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1745 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1746 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1747
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001748 setUpProgram();
1749
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001750 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001751 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001752 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001753 glDeleteTextures(1, &tex2D);
1754 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001755 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001756
1757 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001758 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1759 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001760}
1761
Jamie Madill50cf2be2018-06-15 09:46:57 -04001762// Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has
1763// initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001764TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001765{
Jamie Madill27d3c932019-11-27 11:39:41 +00001766 if (IsGLExtensionEnabled("NV_pixel_buffer_object"))
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001767 {
Jamie Madill27d3c932019-11-27 11:39:41 +00001768 int width = getWindowWidth();
1769 int height = getWindowHeight();
1770
1771 GLuint tex2D;
1772 glGenTextures(1, &tex2D);
1773 glActiveTexture(GL_TEXTURE0);
1774 glBindTexture(GL_TEXTURE_2D, tex2D);
1775
1776 // Fill with red
1777 std::vector<GLubyte> pixels(3 * 16 * 16);
1778 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1779 {
1780 pixels[pixelId * 3 + 0] = 255;
1781 pixels[pixelId * 3 + 1] = 0;
1782 pixels[pixelId * 3 + 2] = 0;
1783 }
1784
1785 // Read 16x16 region from red backbuffer to PBO
1786 GLuint pbo;
1787 glGenBuffers(1, &pbo);
1788 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1789 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1790
1791 // ANGLE internally uses RGBA as the DirectX format for RGB images
1792 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1793 // alpha color. The data is kept in a CPU-side image and the image is marked as dirty.
1794 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1795
1796 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1797 // glTexSubImage2D should take into account that the image is dirty.
1798 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
1799 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1800 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1801
1802 setUpProgram();
1803
1804 glUseProgram(mProgram);
1805 glUniform1i(mTexture2DUniformLocation, 0);
1806 drawQuad(mProgram, "position", 0.5f);
1807 glDeleteTextures(1, &tex2D);
1808 glDeleteBuffers(1, &pbo);
1809 EXPECT_GL_NO_ERROR();
1810 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1811 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001812 }
1813}
Jamie Madillbc393df2015-01-29 13:46:07 -05001814
Mohan Maiya6caa2652019-09-11 08:06:13 -07001815// Tests CopySubImage for float formats
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001816TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001817{
1818 testFloatCopySubImage(1, 1);
1819}
1820
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001821TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001822{
1823 testFloatCopySubImage(2, 1);
1824}
1825
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001826TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001827{
1828 testFloatCopySubImage(2, 2);
1829}
1830
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001831TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001832{
1833 testFloatCopySubImage(3, 1);
1834}
1835
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001836TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001837{
1838 testFloatCopySubImage(3, 2);
1839}
1840
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001841TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001842{
Yunchao He9550c602018-02-13 14:47:05 +08001843 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
Mohan Maiya6caa2652019-09-11 08:06:13 -07001844 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001845
Yunchao He9550c602018-02-13 14:47:05 +08001846 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1847 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001848
Jamie Madillbc393df2015-01-29 13:46:07 -05001849 testFloatCopySubImage(3, 3);
1850}
1851
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001852TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001853{
1854 testFloatCopySubImage(4, 1);
1855}
1856
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001857TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001858{
1859 testFloatCopySubImage(4, 2);
1860}
1861
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001862TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001863{
Yunchao He9550c602018-02-13 14:47:05 +08001864 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1865 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001866
Jamie Madillbc393df2015-01-29 13:46:07 -05001867 testFloatCopySubImage(4, 3);
1868}
1869
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001870TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001871{
Yunchao He9550c602018-02-13 14:47:05 +08001872 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1873 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001874
Jamie Madillbc393df2015-01-29 13:46:07 -05001875 testFloatCopySubImage(4, 4);
1876}
Austin Kinross07285142015-03-26 11:36:16 -07001877
Jamie Madill50cf2be2018-06-15 09:46:57 -04001878// Port of
1879// https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1880// Run against GL_ALPHA/UNSIGNED_BYTE format, to ensure that D3D11 Feature Level 9_3 correctly
1881// handles GL_ALPHA
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001882TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001883{
1884 const int npotTexSize = 5;
Jamie Madill50cf2be2018-06-15 09:46:57 -04001885 const int potTexSize = 4; // Should be less than npotTexSize
Austin Kinross07285142015-03-26 11:36:16 -07001886 GLuint tex2D;
1887
Jamie Madillb8149072019-04-30 16:14:44 -04001888 if (IsGLExtensionEnabled("GL_OES_texture_npot"))
Austin Kinross07285142015-03-26 11:36:16 -07001889 {
1890 // This test isn't applicable if texture_npot is enabled
1891 return;
1892 }
1893
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001894 setUpProgram();
1895
Austin Kinross07285142015-03-26 11:36:16 -07001896 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1897
Austin Kinross5faa15b2016-01-11 13:32:48 -08001898 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1899 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1900
Austin Kinross07285142015-03-26 11:36:16 -07001901 glActiveTexture(GL_TEXTURE0);
1902 glGenTextures(1, &tex2D);
1903 glBindTexture(GL_TEXTURE_2D, tex2D);
1904
Till Rathmannc1551dc2018-08-15 17:04:49 +02001905 const std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize, 64);
Austin Kinross07285142015-03-26 11:36:16 -07001906
1907 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1908 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1909
1910 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
Jamie Madill50cf2be2018-06-15 09:46:57 -04001911 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1912 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001913 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1914
1915 // Check that an NPOT texture on level 0 succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001916 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1917 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001918 EXPECT_GL_NO_ERROR();
1919
1920 // Check that generateMipmap fails on NPOT
1921 glGenerateMipmap(GL_TEXTURE_2D);
1922 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1923
1924 // Check that nothing is drawn if filtering is not correct for NPOT
1925 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1926 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1927 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1928 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1929 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001930 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001931 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1932
1933 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1934 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1935 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1936 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
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, 255);
1940
1941 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1942 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1943 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001944 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001945 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1946
1947 // Check that glTexImage2D for POT texture succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001948 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE,
1949 pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001950 EXPECT_GL_NO_ERROR();
1951
1952 // Check that generateMipmap for an POT texture succeeds
1953 glGenerateMipmap(GL_TEXTURE_2D);
1954 EXPECT_GL_NO_ERROR();
1955
1956 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1957 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1958 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1959 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1960 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1961 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001962 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001963 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1964 EXPECT_GL_NO_ERROR();
1965}
Jamie Madillfa05f602015-05-07 13:47:11 -04001966
Austin Kinross08528e12015-10-07 16:24:40 -07001967// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1968// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001969TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001970{
1971 glActiveTexture(GL_TEXTURE0);
1972 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1973
1974 // Create an 8x8 (i.e. power-of-two) texture.
1975 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1976 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1977 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1978 glGenerateMipmap(GL_TEXTURE_2D);
1979
1980 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1981 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001982 std::array<GLColor, 3 * 3> data;
1983 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001984
1985 EXPECT_GL_NO_ERROR();
1986}
1987
Geoff Lang3702d8c2019-04-08 13:44:06 -04001988// Regression test for http://crbug.com/949985 to make sure dirty bits are propagated up from
1989// TextureImpl and the texture is synced before being used in a draw call.
1990TEST_P(Texture2DTestES3, TextureImplPropogatesDirtyBits)
1991{
1992 ANGLE_SKIP_TEST_IF(IsIntel() && IsOpenGL());
Yuly Novikove6b23e42019-04-10 17:19:15 -04001993 // Flaky hangs on Win10 AMD RX 550 GL. http://anglebug.com/3371
1994 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsOpenGL());
Yuly Novikovbd4ff472019-07-19 22:08:17 +00001995 // D3D Debug device reports an error. http://anglebug.com/3501
1996 ANGLE_SKIP_TEST_IF(IsWindows() && IsD3D11());
Cody Northrop988f7172019-09-30 15:52:37 -06001997 // TODO(cnorthrop): Needs triage on Vulkan backend. http://anglebug.com/3950
Cody Northropcb16fb52019-08-29 16:53:55 -06001998 ANGLE_SKIP_TEST_IF(IsVulkan());
Geoff Lang3702d8c2019-04-08 13:44:06 -04001999
2000 // The workaround in the GL backend required to trigger this bug generates driver warning
2001 // messages.
2002 ScopedIgnorePlatformMessages ignoreMessages;
2003
2004 setUpProgram();
2005 glUseProgram(mProgram);
2006 glActiveTexture(GL_TEXTURE0 + mTexture2DUniformLocation);
2007
2008 GLTexture dest;
2009 glBindTexture(GL_TEXTURE_2D, dest);
2010
2011 GLTexture source;
2012 glBindTexture(GL_TEXTURE_2D, source);
2013
2014 // Put data in mip 0 and 1
2015 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2016 GLColor::red.data());
2017 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2018 GLColor::green.data());
2019
2020 // Disable mipmapping so source is complete
2021 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
2022 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2023
2024 // Force the dirty bits to be synchronized in source
2025 drawQuad(mProgram, "position", 1.0f);
2026
2027 // Copy from mip 1 of the source. In the GL backend this internally sets the base level to mip
2028 // 1 and sets a dirty bit.
2029 glCopyTextureCHROMIUM(source, 1, GL_TEXTURE_2D, dest, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_FALSE,
2030 GL_FALSE, GL_FALSE);
2031
2032 // Draw again, assertions are generated if the texture has internal dirty bits at draw time
2033 drawQuad(mProgram, "position", 1.0f);
2034}
2035
Geoff Lang6f691fb2019-04-25 11:01:52 -04002036// This test case changes the base level of a texture that's attached to a framebuffer, clears every
2037// level to green, and then samples the texture when rendering. Test is taken from
2038// https://www.khronos.org/registry/webgl/sdk/tests/conformance2/rendering/framebuffer-texture-changing-base-level.html
2039TEST_P(Texture2DTestES3, FramebufferTextureChangingBaselevel)
2040{
2041 // TODO(geofflang): Investigate on D3D11. http://anglebug.com/2291
2042 ANGLE_SKIP_TEST_IF(IsD3D11());
2043
Cody Northropd192e932019-09-27 10:27:10 -06002044 // TODO(cnorthrop): Failing on Vulkan/Windows/AMD. http://anglebug.com/3996
2045 ANGLE_SKIP_TEST_IF(IsVulkan() && IsWindows() && IsAMD());
Cody Northropcb16fb52019-08-29 16:53:55 -06002046
Geoff Lang6f691fb2019-04-25 11:01:52 -04002047 setUpProgram();
2048
2049 constexpr GLint width = 8;
2050 constexpr GLint height = 4;
2051
2052 GLTexture texture;
2053 glBindTexture(GL_TEXTURE_2D, texture);
2054 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2055 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2056 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2057 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2058
2059 // Create all mipmap levels for the texture from level 0 to the 1x1 pixel level.
2060 GLint level = 0;
2061 GLint levelW = width;
2062 GLint levelH = height;
2063 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, levelW, levelH, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2064 nullptr);
2065 while (levelW > 1 || levelH > 1)
2066 {
2067 ++level;
2068 levelW = static_cast<GLint>(std::max(1.0, std::floor(width / std::pow(2, level))));
2069 levelH = static_cast<GLint>(std::max(1.0, std::floor(height / std::pow(2, level))));
2070 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, levelW, levelH, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2071 nullptr);
2072 }
2073
2074 // Clear each level of the texture using an FBO. Change the base level to match the level used
2075 // for the FBO on each iteration.
2076 GLFramebuffer fbo;
2077 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
2078 level = 0;
2079 levelW = width;
2080 levelH = height;
2081 while (levelW > 1 || levelH > 1)
2082 {
2083 levelW = static_cast<GLint>(std::floor(width / std::pow(2, level)));
2084 levelH = static_cast<GLint>(std::floor(height / std::pow(2, level)));
2085
2086 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, level);
2087 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, level);
2088
2089 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2090 EXPECT_GL_NO_ERROR();
2091
2092 glClearColor(0, 1, 0, 1);
2093 glClear(GL_COLOR_BUFFER_BIT);
2094
2095 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2096
2097 ++level;
2098 }
2099
2100 glBindFramebuffer(GL_FRAMEBUFFER, 0);
2101 glViewport(0, 0, 16, 16);
2102 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2103
2104 drawQuad(mProgram, "position", 0.5f);
2105
2106 EXPECT_GL_NO_ERROR();
2107 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2108}
2109
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002110// Test to check that texture completeness is determined correctly when the texture base level is
2111// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
2112TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
2113{
2114 glActiveTexture(GL_TEXTURE0);
2115 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02002116
2117 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
2118 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
2119 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2120 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2121 texDataGreen.data());
2122 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2123 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002124 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2125 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2126 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2127
2128 EXPECT_GL_NO_ERROR();
2129
2130 drawQuad(mProgram, "position", 0.5f);
2131
Olli Etuahoa314b612016-03-10 16:43:00 +02002132 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2133}
2134
2135// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2136// have images defined.
2137TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
2138{
Yunchao He9550c602018-02-13 14:47:05 +08002139 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
2140 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
2141
Olli Etuahoa314b612016-03-10 16:43:00 +02002142 glActiveTexture(GL_TEXTURE0);
2143 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2144 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2145 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2146 texDataGreen.data());
2147 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2148 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2149 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2150 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2151
2152 EXPECT_GL_NO_ERROR();
2153
2154 drawQuad(mProgram, "position", 0.5f);
2155
2156 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2157}
2158
Olli Etuahoe8528d82016-05-16 17:50:52 +03002159// Test that drawing works correctly when level 0 is undefined and base level is 1.
2160TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
2161{
Yunchao He9550c602018-02-13 14:47:05 +08002162 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
2163 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
2164
Olli Etuahoe8528d82016-05-16 17:50:52 +03002165 glActiveTexture(GL_TEXTURE0);
2166 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2167 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2168 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2169 texDataGreen.data());
2170 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2171 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2172 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2173 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2174
2175 EXPECT_GL_NO_ERROR();
2176
2177 // Texture is incomplete.
2178 drawQuad(mProgram, "position", 0.5f);
2179 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2180
2181 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2182 texDataGreen.data());
2183
2184 // Texture is now complete.
2185 drawQuad(mProgram, "position", 0.5f);
2186 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2187}
2188
Olli Etuahoa314b612016-03-10 16:43:00 +02002189// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2190// dimensions that don't fit the images inside the range.
2191// GLES 3.0.4 section 3.8.13 Texture completeness
2192TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2193{
Olli Etuahoa314b612016-03-10 16:43:00 +02002194 glActiveTexture(GL_TEXTURE0);
2195 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2196 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
2197 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2198 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
2199
2200 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2201 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2202
2203 // Two levels that are initially unused.
2204 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
2205 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2206 texDataCyan.data());
2207
2208 // One level that is used - only this level should affect completeness.
2209 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2210 texDataGreen.data());
2211
2212 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2213 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2214
2215 EXPECT_GL_NO_ERROR();
2216
2217 drawQuad(mProgram, "position", 0.5f);
2218
2219 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2220
Yunchao He2f23f352018-02-11 22:11:37 +08002221 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02002222
2223 // Switch the level that is being used to the cyan level 2.
2224 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2225 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2226
2227 EXPECT_GL_NO_ERROR();
2228
2229 drawQuad(mProgram, "position", 0.5f);
2230
2231 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2232}
2233
2234// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2235// have images defined.
2236TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
2237{
Olli Etuahoa314b612016-03-10 16:43:00 +02002238 glActiveTexture(GL_TEXTURE0);
2239 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2240 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2241 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2242 texDataGreen.data());
2243 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2244 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2245 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
2246 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2247
2248 EXPECT_GL_NO_ERROR();
2249
2250 drawQuad(mProgram, "position", 0.5f);
2251
2252 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2253}
2254
2255// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2256// dimensions that don't fit the images inside the range.
2257// GLES 3.0.4 section 3.8.13 Texture completeness
2258TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2259{
Yuly Novikovc5da7992019-06-27 12:57:13 -04002260 // Crashes on Intel Ubuntu 19.04 Mesa 19.0.2 GL. http://anglebug.com/2782
2261 ANGLE_SKIP_TEST_IF(IsLinux() && IsIntel() && IsDesktopOpenGL());
2262
Olli Etuahoa314b612016-03-10 16:43:00 +02002263 glActiveTexture(GL_TEXTURE0);
2264 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2265 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2266 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2267 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2268
2269 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2270 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2271
2272 // Two levels that are initially unused.
2273 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2274 texDataRed.data());
2275 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2276 texDataCyan.data());
2277
2278 // One level that is used - only this level should affect completeness.
2279 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2280 texDataGreen.data());
2281
2282 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
2283 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2284
2285 EXPECT_GL_NO_ERROR();
2286
2287 drawQuad(mProgram, "position", 0.5f);
2288
2289 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2290
Yunchao He2f23f352018-02-11 22:11:37 +08002291 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02002292
2293 // Switch the level that is being used to the cyan level 2.
2294 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
2295 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
2296
2297 EXPECT_GL_NO_ERROR();
2298
2299 drawQuad(mProgram, "position", 0.5f);
2300
2301 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2302}
2303
2304// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2305// have images defined.
2306TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
2307{
Olli Etuahoa314b612016-03-10 16:43:00 +02002308 glActiveTexture(GL_TEXTURE0);
2309 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
2310 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2311 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2312 texDataGreen.data());
2313 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2314 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2315 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2316 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2317
2318 EXPECT_GL_NO_ERROR();
2319
2320 drawQuad(mProgram, "position", 0.5f);
2321
2322 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2323}
2324
2325// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2326// dimensions that don't fit the images inside the range.
2327// GLES 3.0.4 section 3.8.13 Texture completeness
2328TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2329{
Corentin Wallez566c2e32019-08-28 18:37:58 +02002330 // TODO(crbug.com/998505): Test failing on Android FYI Release (NVIDIA Shield TV)
2331 ANGLE_SKIP_TEST_IF(IsNVIDIAShield());
2332
Olli Etuahoa314b612016-03-10 16:43:00 +02002333 glActiveTexture(GL_TEXTURE0);
2334 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
2335 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2336 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2337 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2338
2339 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2340 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2341
2342 // Two levels that are initially unused.
2343 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2344 texDataRed.data());
2345 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2346 texDataCyan.data());
2347
2348 // One level that is used - only this level should affect completeness.
2349 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2350 texDataGreen.data());
2351
2352 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2353 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2354
2355 EXPECT_GL_NO_ERROR();
2356
2357 drawQuad(mProgram, "position", 0.5f);
2358
2359 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2360
Yunchao He2f23f352018-02-11 22:11:37 +08002361 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
2362
Olli Etuahoa314b612016-03-10 16:43:00 +02002363 // Switch the level that is being used to the cyan level 2.
2364 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2365 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2366
2367 EXPECT_GL_NO_ERROR();
2368
2369 drawQuad(mProgram, "position", 0.5f);
2370
2371 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2372}
2373
2374// Test that texture completeness is updated if texture max level changes.
2375// GLES 3.0.4 section 3.8.13 Texture completeness
2376TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2377{
Olli Etuahoa314b612016-03-10 16:43:00 +02002378 glActiveTexture(GL_TEXTURE0);
2379 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2380 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2381
2382 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2383 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2384
2385 // A level that is initially unused.
2386 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2387 texDataGreen.data());
2388
2389 // One level that is initially used - only this level should affect completeness.
2390 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2391 texDataGreen.data());
2392
2393 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2394 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2395
2396 EXPECT_GL_NO_ERROR();
2397
2398 drawQuad(mProgram, "position", 0.5f);
2399
2400 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2401
2402 // Switch the max level to level 1. The levels within the used range now have inconsistent
2403 // dimensions and the texture should be incomplete.
2404 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2405
2406 EXPECT_GL_NO_ERROR();
2407
2408 drawQuad(mProgram, "position", 0.5f);
2409
2410 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2411}
2412
2413// Test that 3D texture completeness is updated if texture max level changes.
2414// GLES 3.0.4 section 3.8.13 Texture completeness
2415TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2416{
Olli Etuahoa314b612016-03-10 16:43:00 +02002417 glActiveTexture(GL_TEXTURE0);
2418 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2419 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2420
2421 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2422 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2423
2424 // A level that is initially unused.
2425 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2426 texDataGreen.data());
2427
2428 // One level that is initially used - only this level should affect completeness.
2429 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2430 texDataGreen.data());
2431
2432 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2433 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2434
2435 EXPECT_GL_NO_ERROR();
2436
2437 drawQuad(mProgram, "position", 0.5f);
2438
2439 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2440
2441 // Switch the max level to level 1. The levels within the used range now have inconsistent
2442 // dimensions and the texture should be incomplete.
2443 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2444
2445 EXPECT_GL_NO_ERROR();
2446
2447 drawQuad(mProgram, "position", 0.5f);
2448
2449 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2450}
2451
2452// Test that texture completeness is updated if texture base level changes.
2453// GLES 3.0.4 section 3.8.13 Texture completeness
2454TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2455{
Olli Etuahoa314b612016-03-10 16:43:00 +02002456 glActiveTexture(GL_TEXTURE0);
2457 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2458 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2459
2460 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2461 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2462
2463 // Two levels that are initially unused.
2464 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2465 texDataGreen.data());
2466 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2467 texDataGreen.data());
2468
2469 // One level that is initially used - only this level should affect completeness.
2470 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2471 texDataGreen.data());
2472
2473 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2474 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2475
2476 EXPECT_GL_NO_ERROR();
2477
2478 drawQuad(mProgram, "position", 0.5f);
2479
2480 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2481
2482 // Switch the base level to level 1. The levels within the used range now have inconsistent
2483 // dimensions and the texture should be incomplete.
2484 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2485
2486 EXPECT_GL_NO_ERROR();
2487
2488 drawQuad(mProgram, "position", 0.5f);
2489
2490 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2491}
2492
2493// Test that texture is not complete if base level is greater than max level.
2494// GLES 3.0.4 section 3.8.13 Texture completeness
2495TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2496{
Olli Etuahoa314b612016-03-10 16:43:00 +02002497 glActiveTexture(GL_TEXTURE0);
2498 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2499
2500 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2501 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2502
2503 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2504
2505 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2506 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2507
2508 EXPECT_GL_NO_ERROR();
2509
2510 drawQuad(mProgram, "position", 0.5f);
2511
2512 // Texture should be incomplete.
2513 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2514}
2515
2516// Test that immutable texture base level and max level are clamped.
2517// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2518TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2519{
Olli Etuahoa314b612016-03-10 16:43:00 +02002520 glActiveTexture(GL_TEXTURE0);
2521 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2522
2523 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2524 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2525
2526 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2527
2528 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2529
2530 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2531 // should be clamped to [base_level, levels - 1].
2532 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2533 // In the case of this test, those rules make the effective base level and max level 0.
2534 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2535 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2536
2537 EXPECT_GL_NO_ERROR();
2538
2539 drawQuad(mProgram, "position", 0.5f);
2540
2541 // Texture should be complete.
2542 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2543}
2544
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002545// Test that changing base level works when it affects the format of the texture.
2546TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2547{
Corentin Wallez7f00d332019-08-28 15:19:16 +02002548 // TODO(crbug.com/998505): Test failing on Android FYI Release (NVIDIA Shield TV)
2549 ANGLE_SKIP_TEST_IF(IsNVIDIAShield());
2550
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002551 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002552
2553 // Observed incorrect rendering on AMD OpenGL.
2554 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002555
2556 glActiveTexture(GL_TEXTURE0);
2557 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2558 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2559 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2560
2561 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2562 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2563
2564 // RGBA8 level that's initially unused.
2565 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2566 texDataCyan.data());
2567
2568 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2569 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2570
2571 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2572 // format. It reads green channel data from the green and alpha channels of texDataGreen
2573 // (this is a bit hacky but works).
2574 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2575
2576 EXPECT_GL_NO_ERROR();
2577
2578 drawQuad(mProgram, "position", 0.5f);
2579
2580 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2581
2582 // Switch the texture to use the cyan level 0 with the RGBA format.
2583 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2584 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2585
2586 EXPECT_GL_NO_ERROR();
2587
2588 drawQuad(mProgram, "position", 0.5f);
2589
2590 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2591}
2592
Olli Etuahoa314b612016-03-10 16:43:00 +02002593// Test that setting a texture image works when base level is out of range.
2594TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2595{
2596 glActiveTexture(GL_TEXTURE0);
2597 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2598
2599 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2600 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2601
2602 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2603 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2604
2605 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2606
2607 EXPECT_GL_NO_ERROR();
2608
2609 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2610
2611 drawQuad(mProgram, "position", 0.5f);
2612
2613 // Texture should be complete.
2614 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002615}
2616
Jamie Madill50cf2be2018-06-15 09:46:57 -04002617// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG
2618// RBA->RGBA8, with 1.0 in the alpha channel. This test covers a bug where redefining array textures
2619// with these formats does not work as expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002620TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002621{
2622 std::vector<GLubyte> pixelData;
2623 for (size_t count = 0; count < 5000; count++)
2624 {
2625 pixelData.push_back(0u);
2626 pixelData.push_back(255u);
2627 pixelData.push_back(0u);
2628 }
2629
2630 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002631 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002632 glUniform1i(mTextureArrayLocation, 0);
2633
2634 // The first draw worked correctly.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002635 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2636 &pixelData[0]);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002637
2638 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2639 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2640 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2641 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002642 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002643 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002644
2645 // The dimension of the respecification must match the original exactly to trigger the bug.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002646 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2647 &pixelData[0]);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002648 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002649 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002650
2651 ASSERT_GL_NO_ERROR();
2652}
2653
Olli Etuaho1a679902016-01-14 12:21:47 +02002654// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2655// This test is needed especially to confirm that sampler registers get assigned correctly on
2656// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2657TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2658{
2659 glActiveTexture(GL_TEXTURE0);
2660 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2661 GLubyte texData[4];
2662 texData[0] = 0;
2663 texData[1] = 60;
2664 texData[2] = 0;
2665 texData[3] = 255;
2666 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2667
2668 glActiveTexture(GL_TEXTURE1);
2669 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2670 GLfloat depthTexData[1];
2671 depthTexData[0] = 0.5f;
2672 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2673 depthTexData);
2674
2675 glUseProgram(mProgram);
2676 glUniform1f(mDepthRefUniformLocation, 0.3f);
2677 glUniform1i(mTexture3DUniformLocation, 0);
2678 glUniform1i(mTextureShadowUniformLocation, 1);
2679
2680 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2681 drawQuad(mProgram, "position", 0.5f);
2682 EXPECT_GL_NO_ERROR();
2683 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2684 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2685
2686 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2687 drawQuad(mProgram, "position", 0.5f);
2688 EXPECT_GL_NO_ERROR();
2689 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2690 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2691}
2692
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002693// Test multiple different sampler types in the same shader.
2694// This test makes sure that even if sampler / texture registers get grouped together based on type
2695// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2696// still has the right register index information for each ESSL sampler.
2697// The tested ESSL samplers have the following types in D3D11 HLSL:
2698// sampler2D: Texture2D + SamplerState
2699// samplerCube: TextureCube + SamplerState
2700// sampler2DShadow: Texture2D + SamplerComparisonState
2701// samplerCubeShadow: TextureCube + SamplerComparisonState
2702TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2703{
2704 glActiveTexture(GL_TEXTURE0);
2705 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2706 GLubyte texData[4];
2707 texData[0] = 0;
2708 texData[1] = 0;
2709 texData[2] = 120;
2710 texData[3] = 255;
2711 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2712
2713 glActiveTexture(GL_TEXTURE1);
2714 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2715 texData[0] = 0;
2716 texData[1] = 90;
2717 texData[2] = 0;
2718 texData[3] = 255;
2719 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2720 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2721 texData);
2722
2723 glActiveTexture(GL_TEXTURE2);
2724 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2725 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2726 GLfloat depthTexData[1];
2727 depthTexData[0] = 0.5f;
2728 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2729 depthTexData);
2730
2731 glActiveTexture(GL_TEXTURE3);
2732 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2733 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2734 depthTexData[0] = 0.2f;
2735 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2736 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2737 depthTexData);
2738
Tobin Ehlisbbf0ce22019-10-11 06:55:36 -06002739 // http://anglebug.com/3949: TODO: Add a DS texture case
2740
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002741 EXPECT_GL_NO_ERROR();
2742
2743 glUseProgram(mProgram);
2744 glUniform1f(mDepthRefUniformLocation, 0.3f);
2745 glUniform1i(mTexture2DUniformLocation, 0);
2746 glUniform1i(mTextureCubeUniformLocation, 1);
2747 glUniform1i(mTexture2DShadowUniformLocation, 2);
2748 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2749
2750 drawQuad(mProgram, "position", 0.5f);
2751 EXPECT_GL_NO_ERROR();
2752 // The shader writes:
2753 // <texture 2d color> +
2754 // <cube map color> +
2755 // 0.25 * <comparison result (1.0)> +
2756 // 0.125 * <comparison result (0.0)>
2757 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2758}
2759
Olli Etuahobce743a2016-01-15 17:18:28 +02002760// Test different base levels on textures accessed through the same sampler array.
2761// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2762TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2763{
Yunchao He9550c602018-02-13 14:47:05 +08002764 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2765
Olli Etuahobce743a2016-01-15 17:18:28 +02002766 glActiveTexture(GL_TEXTURE0);
2767 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2768 GLsizei size = 64;
2769 for (GLint level = 0; level < 7; ++level)
2770 {
2771 ASSERT_LT(0, size);
2772 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2773 nullptr);
2774 size = size / 2;
2775 }
2776 ASSERT_EQ(0, size);
2777 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2778
2779 glActiveTexture(GL_TEXTURE1);
2780 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2781 size = 128;
2782 for (GLint level = 0; level < 8; ++level)
2783 {
2784 ASSERT_LT(0, size);
2785 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2786 nullptr);
2787 size = size / 2;
2788 }
2789 ASSERT_EQ(0, size);
2790 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2791 EXPECT_GL_NO_ERROR();
2792
2793 glUseProgram(mProgram);
2794 glUniform1i(mTexture0Location, 0);
2795 glUniform1i(mTexture1Location, 1);
2796
Olli Etuaho5804dc82018-04-13 14:11:46 +03002797 drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
Olli Etuahobce743a2016-01-15 17:18:28 +02002798 EXPECT_GL_NO_ERROR();
2799 // Red channel: width of level 1 of texture A: 32.
2800 // Green channel: width of level 3 of texture B: 16.
2801 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2802}
2803
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002804// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2805// ES 3.0.4 table 3.24
2806TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2807{
2808 glActiveTexture(GL_TEXTURE0);
2809 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2810 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2811 EXPECT_GL_NO_ERROR();
2812
2813 drawQuad(mProgram, "position", 0.5f);
2814
2815 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2816}
2817
2818// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2819// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002820TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002821{
Luc Ferron5164b792018-03-06 09:10:12 -05002822 setUpProgram();
2823
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002824 glActiveTexture(GL_TEXTURE0);
2825 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2826 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2827 EXPECT_GL_NO_ERROR();
2828
2829 drawQuad(mProgram, "position", 0.5f);
2830
2831 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2832}
2833
Luc Ferron5164b792018-03-06 09:10:12 -05002834// Validate that every component of the pixel will be equal to the luminance value we've set
2835// and that the alpha channel will be 1 (or 255 to be exact).
2836TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2837{
2838 setUpProgram();
2839
2840 glActiveTexture(GL_TEXTURE0);
2841 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2842 uint8_t pixel = 50;
2843 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2844 EXPECT_GL_NO_ERROR();
2845
2846 drawQuad(mProgram, "position", 0.5f);
2847
2848 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2849}
2850
2851// Validate that every component of the pixel will be equal to the luminance value we've set
2852// and that the alpha channel will be the second component.
2853TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2854{
2855 setUpProgram();
2856
2857 glActiveTexture(GL_TEXTURE0);
2858 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2859 uint8_t pixel[] = {50, 25};
2860 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2861 GL_UNSIGNED_BYTE, pixel);
2862 EXPECT_GL_NO_ERROR();
2863
2864 drawQuad(mProgram, "position", 0.5f);
2865
2866 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2867}
2868
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002869// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2870// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002871TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002872{
Jamie Madillb8149072019-04-30 16:14:44 -04002873 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002874 ANGLE_SKIP_TEST_IF(IsD3D9());
2875 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002876
2877 setUpProgram();
2878
Luc Ferrond8c632c2018-04-10 12:31:44 -04002879 glActiveTexture(GL_TEXTURE0);
2880 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2881 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2882 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002883
Luc Ferrond8c632c2018-04-10 12:31:44 -04002884 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002885
Luc Ferrond8c632c2018-04-10 12:31:44 -04002886 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002887}
2888
2889// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2890// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002891TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002892{
Jamie Madillb8149072019-04-30 16:14:44 -04002893 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002894 ANGLE_SKIP_TEST_IF(IsD3D9());
2895 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferrond8c632c2018-04-10 12:31:44 -04002896 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2897 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002898
Luc Ferrond8c632c2018-04-10 12:31:44 -04002899 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002900
Luc Ferrond8c632c2018-04-10 12:31:44 -04002901 glActiveTexture(GL_TEXTURE0);
2902 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2903 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2904 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002905
Luc Ferrond8c632c2018-04-10 12:31:44 -04002906 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002907
Luc Ferrond8c632c2018-04-10 12:31:44 -04002908 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002909}
2910
2911// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2912// ES 3.0.4 table 3.24
2913TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2914{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002915 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2916
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002917 glActiveTexture(GL_TEXTURE0);
2918 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2919 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2920 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2921 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2922 EXPECT_GL_NO_ERROR();
2923
2924 drawQuad(mProgram, "position", 0.5f);
2925
2926 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2927}
2928
2929// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2930// ES 3.0.4 table 3.24
2931TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2932{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002933 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2934
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002935 glActiveTexture(GL_TEXTURE0);
2936 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2937
2938 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2939 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2940 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2941 EXPECT_GL_NO_ERROR();
2942
2943 drawQuad(mProgram, "position", 0.5f);
2944
2945 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2946}
2947
2948// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2949// ES 3.0.4 table 3.24
2950TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2951{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002952 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2953
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002954 glActiveTexture(GL_TEXTURE0);
2955 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2956 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2957 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2958 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2959 EXPECT_GL_NO_ERROR();
2960
2961 drawQuad(mProgram, "position", 0.5f);
2962
2963 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2964}
2965
2966// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2967// ES 3.0.4 table 3.24
2968TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2969{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002970 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2971
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002972 glActiveTexture(GL_TEXTURE0);
2973 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2974 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2975 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2976 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2977 EXPECT_GL_NO_ERROR();
2978
2979 drawQuad(mProgram, "position", 0.5f);
2980
2981 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2982}
2983
2984// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2985// ES 3.0.4 table 3.24
2986TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2987{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002988 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2989
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002990 glActiveTexture(GL_TEXTURE0);
2991 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2992 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2993 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2994 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2995 EXPECT_GL_NO_ERROR();
2996
2997 drawQuad(mProgram, "position", 0.5f);
2998
2999 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
3000}
3001
3002// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
3003// ES 3.0.4 table 3.24
3004TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
3005{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08003006 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
3007
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003008 glActiveTexture(GL_TEXTURE0);
3009 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3010 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
3011 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3012 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3013 EXPECT_GL_NO_ERROR();
3014
3015 drawQuad(mProgram, "position", 0.5f);
3016
3017 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
3018}
3019
3020// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
3021// ES 3.0.4 table 3.24
3022TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
3023{
3024 glActiveTexture(GL_TEXTURE0);
3025 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3026 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
3027 EXPECT_GL_NO_ERROR();
3028
3029 drawQuad(mProgram, "position", 0.5f);
3030
3031 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
3032}
3033
3034// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
3035// ES 3.0.4 table 3.24
3036TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
3037{
3038 glActiveTexture(GL_TEXTURE0);
3039 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3040 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
3041 nullptr);
3042 EXPECT_GL_NO_ERROR();
3043
3044 drawQuad(mProgram, "position", 0.5f);
3045
3046 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
3047}
3048
3049// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
3050// ES 3.0.4 table 3.24
3051TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
3052{
Geoff Lang2a19c592019-08-23 14:10:24 -04003053 // ETC texture formats are not supported on Mac OpenGL. http://anglebug.com/3853
3054 ANGLE_SKIP_TEST_IF(IsOSX() && IsDesktopOpenGL());
Yuly Novikov49886892018-01-23 21:18:27 -05003055
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003056 glActiveTexture(GL_TEXTURE0);
3057 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3058 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
3059 EXPECT_GL_NO_ERROR();
3060
3061 drawQuad(mProgram, "position", 0.5f);
3062
3063 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
3064}
3065
3066// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
3067// ES 3.0.4 table 3.24
3068TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
3069{
Geoff Lang2a19c592019-08-23 14:10:24 -04003070 // ETC texture formats are not supported on Mac OpenGL. http://anglebug.com/3853
3071 ANGLE_SKIP_TEST_IF(IsOSX() && IsDesktopOpenGL());
Yuly Novikov49886892018-01-23 21:18:27 -05003072
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003073 glActiveTexture(GL_TEXTURE0);
3074 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3075 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
3076 EXPECT_GL_NO_ERROR();
3077
3078 drawQuad(mProgram, "position", 0.5f);
3079
3080 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
3081}
3082
Olli Etuaho96963162016-03-21 11:54:33 +02003083// Use a sampler in a uniform struct.
3084TEST_P(SamplerInStructTest, SamplerInStruct)
3085{
3086 runSamplerInStructTest();
3087}
3088
3089// Use a sampler in a uniform struct that's passed as a function parameter.
3090TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
3091{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003092 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
3093 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04003094
Olli Etuaho96963162016-03-21 11:54:33 +02003095 runSamplerInStructTest();
3096}
3097
3098// Use a sampler in a uniform struct array with a struct from the array passed as a function
3099// parameter.
3100TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
3101{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003102 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
3103 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08003104
Olli Etuaho96963162016-03-21 11:54:33 +02003105 runSamplerInStructTest();
3106}
3107
3108// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
3109// parameter.
3110TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
3111{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003112 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
3113 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08003114
Olli Etuaho96963162016-03-21 11:54:33 +02003115 runSamplerInStructTest();
3116}
3117
3118// Make sure that there isn't a name conflict between sampler extracted from a struct and a
3119// similarly named uniform.
3120TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
3121{
3122 runSamplerInStructTest();
3123}
3124
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05003125// GL_EXT_texture_filter_anisotropic
3126class TextureAnisotropyTest : public Texture2DTest
3127{
3128 protected:
3129 void uploadTexture()
3130 {
3131 glActiveTexture(GL_TEXTURE0);
3132 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3133 GLColor texDataRed[1] = {GLColor::red};
3134 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed);
3135 EXPECT_GL_NO_ERROR();
3136 }
3137};
3138
3139// Tests that setting anisotropic filtering doesn't cause failures at draw time.
3140TEST_P(TextureAnisotropyTest, AnisotropyFunctional)
3141{
Jamie Madillb8149072019-04-30 16:14:44 -04003142 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_filter_anisotropic"));
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05003143
3144 setUpProgram();
3145
3146 uploadTexture();
3147
3148 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3149 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3150 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f);
3151 EXPECT_GL_NO_ERROR();
3152
3153 drawQuad(mProgram, "position", 0.5f);
3154
3155 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3156 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3157 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::red);
3158}
3159
Till Rathmannb8543632018-10-02 19:46:14 +02003160// GL_OES_texture_border_clamp
3161class TextureBorderClampTest : public Texture2DTest
3162{
3163 protected:
3164 TextureBorderClampTest() : Texture2DTest() {}
3165
Jamie Madill35cd7332018-12-02 12:03:33 -05003166 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003167 {
3168 return
3169 R"(precision highp float;
3170 attribute vec4 position;
3171 varying vec2 texcoord;
3172
3173 void main()
3174 {
3175 gl_Position = vec4(position.xy, 0.0, 1.0);
3176 // texcoords in [-0.5, 1.5]
3177 texcoord = (position.xy) + 0.5;
3178 })";
3179 }
3180
3181 void uploadTexture()
3182 {
3183 glActiveTexture(GL_TEXTURE0);
3184 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3185 std::vector<GLColor> texDataRed(1, GLColor::red);
3186 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3187 texDataRed.data());
3188 EXPECT_GL_NO_ERROR();
3189 }
3190};
3191
3192// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3193// GL_CLAMP_TO_BORDER wrap mode (set with glTexParameter).
3194TEST_P(TextureBorderClampTest, TextureBorderClampFunctional)
3195{
Jamie Madillb8149072019-04-30 16:14:44 -04003196 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003197
3198 setUpProgram();
3199
3200 uploadTexture();
3201
3202 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3203 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3204 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3205 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3206 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3207 EXPECT_GL_NO_ERROR();
3208
3209 drawQuad(mProgram, "position", 0.5f);
3210
3211 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3212 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3213 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3214}
3215
3216// Test reading back GL_TEXTURE_BORDER_COLOR by glGetTexParameter.
3217TEST_P(TextureBorderClampTest, TextureBorderClampFunctional2)
3218{
Jamie Madillb8149072019-04-30 16:14:44 -04003219 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003220
3221 glActiveTexture(GL_TEXTURE0);
3222 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3223
3224 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3225
3226 GLint colorFixedPoint[4] = {0};
3227 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3228 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3229 std::numeric_limits<GLint>::max()};
3230 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3231 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3232 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3233 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3234
3235 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3236 std::numeric_limits<GLint>::max()};
3237 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3238
3239 GLfloat color[4] = {0.0f};
3240 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
3241 EXPECT_EQ(color[0], kFloatBlue.R);
3242 EXPECT_EQ(color[1], kFloatBlue.G);
3243 EXPECT_EQ(color[2], kFloatBlue.B);
3244 EXPECT_EQ(color[3], kFloatBlue.A);
3245}
3246
3247// Test GL_TEXTURE_BORDER_COLOR parameter validation at glTexParameter.
3248TEST_P(TextureBorderClampTest, TextureBorderClampValidation)
3249{
Jamie Madillb8149072019-04-30 16:14:44 -04003250 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003251
3252 glActiveTexture(GL_TEXTURE0);
3253 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3254
3255 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, 1.0f);
3256 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3257
3258 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3259 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3260
3261 glTexParameterfv(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3262 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3263
3264 GLint colorInt[4] = {0};
3265 glTexParameteriv(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_BORDER_COLOR, colorInt);
3266 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3267
3268 if (getClientMajorVersion() < 3)
3269 {
3270 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3271 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3272 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3273 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3274
3275 GLuint colorUInt[4] = {0};
3276 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3277 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3278 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3279 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3280
3281 GLSampler sampler;
3282 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3283 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3284 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3285 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3286
3287 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3288 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3289 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3290 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3291 }
3292}
3293
3294class TextureBorderClampTestES3 : public TextureBorderClampTest
3295{
3296 protected:
3297 TextureBorderClampTestES3() : TextureBorderClampTest() {}
3298};
3299
3300// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3301// GL_CLAMP_TO_BORDER wrap mode (set with glSamplerParameter).
3302TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional)
3303{
Jamie Madillb8149072019-04-30 16:14:44 -04003304 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003305
3306 setUpProgram();
3307
3308 uploadTexture();
3309
3310 GLSampler sampler;
3311 glBindSampler(0, sampler);
3312 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3313 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3314 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3315 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3316 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3317 EXPECT_GL_NO_ERROR();
3318
3319 drawQuad(mProgram, "position", 0.5f);
3320
3321 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3322 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3323 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3324}
3325
3326// Test reading back GL_TEXTURE_BORDER_COLOR by glGetSamplerParameter.
3327TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional2)
3328{
Jamie Madillb8149072019-04-30 16:14:44 -04003329 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003330
3331 glActiveTexture(GL_TEXTURE0);
3332
3333 GLSampler sampler;
3334 glBindSampler(0, sampler);
3335
3336 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3337
3338 GLint colorFixedPoint[4] = {0};
3339 glGetSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3340 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3341 std::numeric_limits<GLint>::max()};
3342 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3343 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3344 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3345 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3346
3347 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3348 std::numeric_limits<GLint>::max()};
3349 glSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3350
3351 GLfloat color[4] = {0.0f};
3352 glGetSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, color);
3353 EXPECT_EQ(color[0], kFloatBlue.R);
3354 EXPECT_EQ(color[1], kFloatBlue.G);
3355 EXPECT_EQ(color[2], kFloatBlue.B);
3356 EXPECT_EQ(color[3], kFloatBlue.A);
3357
3358 constexpr GLint colorSomewhatRedInt[4] = {500000, 0, 0, std::numeric_limits<GLint>::max()};
3359 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedInt);
3360 GLint colorInt[4] = {0};
3361 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3362 EXPECT_EQ(colorInt[0], colorSomewhatRedInt[0]);
3363 EXPECT_EQ(colorInt[1], colorSomewhatRedInt[1]);
3364 EXPECT_EQ(colorInt[2], colorSomewhatRedInt[2]);
3365 EXPECT_EQ(colorInt[3], colorSomewhatRedInt[3]);
3366
3367 constexpr GLuint colorSomewhatRedUInt[4] = {500000, 0, 0, std::numeric_limits<GLuint>::max()};
3368 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedUInt);
3369 GLuint colorUInt[4] = {0};
3370 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3371 EXPECT_EQ(colorUInt[0], colorSomewhatRedUInt[0]);
3372 EXPECT_EQ(colorUInt[1], colorSomewhatRedUInt[1]);
3373 EXPECT_EQ(colorUInt[2], colorSomewhatRedUInt[2]);
3374 EXPECT_EQ(colorUInt[3], colorSomewhatRedUInt[3]);
3375
3376 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3377
3378 constexpr GLint colorSomewhatGreenInt[4] = {0, 500000, 0, std::numeric_limits<GLint>::max()};
3379 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenInt);
3380 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3381 EXPECT_EQ(colorInt[0], colorSomewhatGreenInt[0]);
3382 EXPECT_EQ(colorInt[1], colorSomewhatGreenInt[1]);
3383 EXPECT_EQ(colorInt[2], colorSomewhatGreenInt[2]);
3384 EXPECT_EQ(colorInt[3], colorSomewhatGreenInt[3]);
3385
3386 constexpr GLuint colorSomewhatGreenUInt[4] = {0, 500000, 0, std::numeric_limits<GLuint>::max()};
3387 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenUInt);
3388 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3389 EXPECT_EQ(colorUInt[0], colorSomewhatGreenUInt[0]);
3390 EXPECT_EQ(colorUInt[1], colorSomewhatGreenUInt[1]);
3391 EXPECT_EQ(colorUInt[2], colorSomewhatGreenUInt[2]);
3392 EXPECT_EQ(colorUInt[3], colorSomewhatGreenUInt[3]);
3393}
3394
3395// Test GL_TEXTURE_BORDER_COLOR parameter validation at glSamplerParameter.
3396TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Validation)
3397{
Jamie Madillb8149072019-04-30 16:14:44 -04003398 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003399
3400 glActiveTexture(GL_TEXTURE0);
3401
3402 GLSampler sampler;
3403 glBindSampler(0, sampler);
3404
3405 glSamplerParameterf(sampler, GL_TEXTURE_BORDER_COLOR, 1.0f);
3406 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3407
3408 glSamplerParameteri(sampler, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3409 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3410}
3411
3412class TextureBorderClampIntegerTestES3 : public Texture2DTest
3413{
3414 protected:
3415 TextureBorderClampIntegerTestES3() : Texture2DTest(), isUnsignedIntTest(false) {}
3416
Jamie Madill35cd7332018-12-02 12:03:33 -05003417 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003418 {
3419 return
3420 R"(#version 300 es
3421 out vec2 texcoord;
3422 in vec4 position;
3423
3424 void main()
3425 {
3426 gl_Position = vec4(position.xy, 0.0, 1.0);
3427 // texcoords in [-0.5, 1.5]
3428 texcoord = (position.xy) + 0.5;
3429 })";
3430 }
3431
Jamie Madillba319ba2018-12-29 10:29:33 -05003432 const char *getFragmentShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003433 {
Jamie Madill35cd7332018-12-02 12:03:33 -05003434 if (isUnsignedIntTest)
3435 {
3436 return "#version 300 es\n"
3437 "precision highp float;\n"
3438 "uniform highp usampler2D tex;\n"
3439 "in vec2 texcoord;\n"
3440 "out vec4 fragColor;\n"
Till Rathmannb8543632018-10-02 19:46:14 +02003441
Jamie Madill35cd7332018-12-02 12:03:33 -05003442 "void main()\n"
3443 "{\n"
3444 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3445 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3446 "fragColor = (texture(tex, texcoord).r == 150u)"
3447 " ? green : red;\n"
3448 "}\n";
3449 }
3450 else
3451 {
3452 return "#version 300 es\n"
3453 "precision highp float;\n"
3454 "uniform highp isampler2D tex;\n"
3455 "in vec2 texcoord;\n"
3456 "out vec4 fragColor;\n"
3457
3458 "void main()\n"
3459 "{\n"
3460 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3461 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3462 "fragColor = (texture(tex, texcoord).r == -50)"
3463 " ? green : red;\n"
3464 "}\n";
3465 }
Till Rathmannb8543632018-10-02 19:46:14 +02003466 }
3467
3468 void uploadTexture()
3469 {
3470 glActiveTexture(GL_TEXTURE0);
3471 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3472 if (isUnsignedIntTest)
3473 {
3474 std::vector<GLubyte> texData(4, 100);
3475 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE,
3476 texData.data());
3477 }
3478 else
3479 {
3480 std::vector<GLbyte> texData(4, 100);
3481 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8I, 1, 1, 0, GL_RGBA_INTEGER, GL_BYTE,
3482 texData.data());
3483 }
3484 EXPECT_GL_NO_ERROR();
3485 }
3486
3487 bool isUnsignedIntTest;
3488};
3489
3490// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3491// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3492TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger)
3493{
Yuly Novikov1dbbc7b2019-07-31 17:49:39 -04003494 // Fails on Win10 FYI x64 Release (AMD RX 550). http://anglebug.com/3760
3495 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsDesktopOpenGL());
3496
Jamie Madillb8149072019-04-30 16:14:44 -04003497 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003498
3499 setUpProgram();
3500
3501 uploadTexture();
3502
3503 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3504 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3505 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3506 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3507
3508 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3509 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3510
3511 EXPECT_GL_NO_ERROR();
3512
3513 drawQuad(mProgram, "position", 0.5f);
3514
3515 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3516 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3517 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3518}
3519
3520// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3521// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3522TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger2)
3523{
Yuly Novikov1dbbc7b2019-07-31 17:49:39 -04003524 // Fails on Win10 FYI x64 Release (AMD RX 550). http://anglebug.com/3760
3525 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsDesktopOpenGL());
3526
Jamie Madillb8149072019-04-30 16:14:44 -04003527 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003528
3529 setUpProgram();
3530
3531 uploadTexture();
3532
3533 GLSampler sampler;
3534 glBindSampler(0, sampler);
3535 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3536 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3537 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3538 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3539
3540 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3541 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3542
3543 EXPECT_GL_NO_ERROR();
3544
3545 drawQuad(mProgram, "position", 0.5f);
3546
3547 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3548 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3549 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3550}
3551
3552// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3553// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIuivOES).
3554TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned)
3555{
Jamie Madillb8149072019-04-30 16:14:44 -04003556 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003557
3558 isUnsignedIntTest = true;
3559
3560 setUpProgram();
3561
3562 uploadTexture();
3563
3564 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3565 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3566 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3567 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3568
3569 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3570 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3571
3572 EXPECT_GL_NO_ERROR();
3573
3574 drawQuad(mProgram, "position", 0.5f);
3575
3576 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3577 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3578 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3579}
3580
3581// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3582// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with
3583// glSamplerParameterIuivOES).
3584TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned2)
3585{
Jamie Madillb8149072019-04-30 16:14:44 -04003586 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003587
3588 isUnsignedIntTest = true;
3589
3590 setUpProgram();
3591
3592 uploadTexture();
3593
3594 GLSampler sampler;
3595 glBindSampler(0, sampler);
3596 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3597 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3598 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3599 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3600
3601 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3602 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3603
3604 EXPECT_GL_NO_ERROR();
3605
3606 drawQuad(mProgram, "position", 0.5f);
3607
3608 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3609 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3610 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3611}
3612
3613// ~GL_OES_texture_border_clamp
3614
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003615class TextureLimitsTest : public ANGLETest
3616{
3617 protected:
3618 struct RGBA8
3619 {
3620 uint8_t R, G, B, A;
3621 };
3622
3623 TextureLimitsTest()
3624 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
3625 {
3626 setWindowWidth(128);
3627 setWindowHeight(128);
3628 setConfigRedBits(8);
3629 setConfigGreenBits(8);
3630 setConfigBlueBits(8);
3631 setConfigAlphaBits(8);
3632 }
3633
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003634 void testSetUp() override
Jamie Madill0fdb9562018-09-17 17:18:43 -04003635 {
Jamie Madill0fdb9562018-09-17 17:18:43 -04003636 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
3637 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
3638 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
3639
3640 ASSERT_GL_NO_ERROR();
3641 }
3642
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003643 void testTearDown() override
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003644 {
3645 if (mProgram != 0)
3646 {
3647 glDeleteProgram(mProgram);
3648 mProgram = 0;
3649
3650 if (!mTextures.empty())
3651 {
3652 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
3653 }
3654 }
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003655 }
3656
3657 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
3658 GLint vertexTextureCount,
3659 GLint vertexActiveTextureCount,
3660 const std::string &fragPrefix,
3661 GLint fragmentTextureCount,
3662 GLint fragmentActiveTextureCount)
3663 {
3664 std::stringstream vertexShaderStr;
3665 vertexShaderStr << "attribute vec2 position;\n"
3666 << "varying vec4 color;\n"
3667 << "varying vec2 texCoord;\n";
3668
3669 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
3670 {
3671 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
3672 }
3673
3674 vertexShaderStr << "void main() {\n"
3675 << " gl_Position = vec4(position, 0, 1);\n"
3676 << " texCoord = (position * 0.5) + 0.5;\n"
3677 << " color = vec4(0);\n";
3678
3679 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
3680 {
3681 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
3682 << ", texCoord);\n";
3683 }
3684
3685 vertexShaderStr << "}";
3686
3687 std::stringstream fragmentShaderStr;
3688 fragmentShaderStr << "varying mediump vec4 color;\n"
3689 << "varying mediump vec2 texCoord;\n";
3690
3691 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
3692 {
3693 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
3694 }
3695
3696 fragmentShaderStr << "void main() {\n"
3697 << " gl_FragColor = color;\n";
3698
3699 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
3700 {
3701 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
3702 << ", texCoord);\n";
3703 }
3704
3705 fragmentShaderStr << "}";
3706
3707 const std::string &vertexShaderSource = vertexShaderStr.str();
3708 const std::string &fragmentShaderSource = fragmentShaderStr.str();
3709
Jamie Madill35cd7332018-12-02 12:03:33 -05003710 mProgram = CompileProgram(vertexShaderSource.c_str(), fragmentShaderSource.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003711 }
3712
3713 RGBA8 getPixel(GLint texIndex)
3714 {
3715 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3716 0, 255u};
3717 return pixel;
3718 }
3719
3720 void initTextures(GLint tex2DCount, GLint texCubeCount)
3721 {
3722 GLint totalCount = tex2DCount + texCubeCount;
3723 mTextures.assign(totalCount, 0);
3724 glGenTextures(totalCount, &mTextures[0]);
3725 ASSERT_GL_NO_ERROR();
3726
3727 std::vector<RGBA8> texData(16 * 16);
3728
3729 GLint texIndex = 0;
3730 for (; texIndex < tex2DCount; ++texIndex)
3731 {
3732 texData.assign(texData.size(), getPixel(texIndex));
3733 glActiveTexture(GL_TEXTURE0 + texIndex);
3734 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3735 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3736 &texData[0]);
3737 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3738 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3739 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3740 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3741 }
3742
3743 ASSERT_GL_NO_ERROR();
3744
3745 for (; texIndex < texCubeCount; ++texIndex)
3746 {
3747 texData.assign(texData.size(), getPixel(texIndex));
3748 glActiveTexture(GL_TEXTURE0 + texIndex);
3749 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3750 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3751 GL_UNSIGNED_BYTE, &texData[0]);
3752 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3753 GL_UNSIGNED_BYTE, &texData[0]);
3754 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3755 GL_UNSIGNED_BYTE, &texData[0]);
3756 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3757 GL_UNSIGNED_BYTE, &texData[0]);
3758 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3759 GL_UNSIGNED_BYTE, &texData[0]);
3760 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3761 GL_UNSIGNED_BYTE, &texData[0]);
3762 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3763 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3764 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3765 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3766 }
3767
3768 ASSERT_GL_NO_ERROR();
3769 }
3770
3771 void testWithTextures(GLint vertexTextureCount,
3772 const std::string &vertexTexturePrefix,
3773 GLint fragmentTextureCount,
3774 const std::string &fragmentTexturePrefix)
3775 {
3776 // Generate textures
3777 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3778
3779 glUseProgram(mProgram);
3780 RGBA8 expectedSum = {0};
3781 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3782 {
3783 std::stringstream uniformNameStr;
3784 uniformNameStr << vertexTexturePrefix << texIndex;
3785 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003786 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003787 ASSERT_NE(-1, location);
3788
3789 glUniform1i(location, texIndex);
3790 RGBA8 contribution = getPixel(texIndex);
3791 expectedSum.R += contribution.R;
3792 expectedSum.G += contribution.G;
3793 }
3794
3795 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3796 {
3797 std::stringstream uniformNameStr;
3798 uniformNameStr << fragmentTexturePrefix << texIndex;
3799 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003800 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003801 ASSERT_NE(-1, location);
3802
3803 glUniform1i(location, texIndex + vertexTextureCount);
3804 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3805 expectedSum.R += contribution.R;
3806 expectedSum.G += contribution.G;
3807 }
3808
3809 ASSERT_GE(256u, expectedSum.G);
3810
3811 drawQuad(mProgram, "position", 0.5f);
3812 ASSERT_GL_NO_ERROR();
3813 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3814 }
3815
3816 GLuint mProgram;
3817 std::vector<GLuint> mTextures;
3818 GLint mMaxVertexTextures;
3819 GLint mMaxFragmentTextures;
3820 GLint mMaxCombinedTextures;
3821};
3822
3823// Test rendering with the maximum vertex texture units.
3824TEST_P(TextureLimitsTest, MaxVertexTextures)
3825{
3826 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3827 ASSERT_NE(0u, mProgram);
3828 ASSERT_GL_NO_ERROR();
3829
3830 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3831}
3832
3833// Test rendering with the maximum fragment texture units.
3834TEST_P(TextureLimitsTest, MaxFragmentTextures)
3835{
3836 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3837 ASSERT_NE(0u, mProgram);
3838 ASSERT_GL_NO_ERROR();
3839
3840 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3841}
3842
3843// Test rendering with maximum combined texture units.
3844TEST_P(TextureLimitsTest, MaxCombinedTextures)
3845{
3846 GLint vertexTextures = mMaxVertexTextures;
3847
3848 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3849 {
3850 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3851 }
3852
3853 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3854 mMaxFragmentTextures, mMaxFragmentTextures);
3855 ASSERT_NE(0u, mProgram);
3856 ASSERT_GL_NO_ERROR();
3857
3858 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3859}
3860
3861// Negative test for exceeding the number of vertex textures
3862TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3863{
3864 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3865 0);
3866 ASSERT_EQ(0u, mProgram);
3867}
3868
3869// Negative test for exceeding the number of fragment textures
3870TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3871{
3872 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3873 mMaxFragmentTextures + 1);
3874 ASSERT_EQ(0u, mProgram);
3875}
3876
3877// Test active vertex textures under the limit, but excessive textures specified.
3878TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3879{
3880 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3881 ASSERT_NE(0u, mProgram);
3882 ASSERT_GL_NO_ERROR();
3883
3884 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3885}
3886
3887// Test active fragment textures under the limit, but excessive textures specified.
3888TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3889{
3890 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3891 mMaxFragmentTextures);
3892 ASSERT_NE(0u, mProgram);
3893 ASSERT_GL_NO_ERROR();
3894
3895 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3896}
3897
3898// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003899// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003900TEST_P(TextureLimitsTest, TextureTypeConflict)
3901{
Jamie Madill35cd7332018-12-02 12:03:33 -05003902 constexpr char kVS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003903 "attribute vec2 position;\n"
3904 "varying float color;\n"
3905 "uniform sampler2D tex2D;\n"
3906 "uniform samplerCube texCube;\n"
3907 "void main() {\n"
3908 " gl_Position = vec4(position, 0, 1);\n"
3909 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3910 " color = texture2D(tex2D, texCoord).x;\n"
3911 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3912 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05003913 constexpr char kFS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003914 "varying mediump float color;\n"
3915 "void main() {\n"
3916 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3917 "}";
3918
Jamie Madill35cd7332018-12-02 12:03:33 -05003919 mProgram = CompileProgram(kVS, kFS);
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003920 ASSERT_NE(0u, mProgram);
3921
3922 initTextures(1, 0);
3923
3924 glUseProgram(mProgram);
3925 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3926 ASSERT_NE(-1, tex2DLocation);
3927 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3928 ASSERT_NE(-1, texCubeLocation);
3929
3930 glUniform1i(tex2DLocation, 0);
3931 glUniform1i(texCubeLocation, 0);
3932 ASSERT_GL_NO_ERROR();
3933
3934 drawQuad(mProgram, "position", 0.5f);
3935 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3936}
3937
Vincent Lang25ab4512016-05-13 18:13:59 +02003938class Texture2DNorm16TestES3 : public Texture2DTestES3
3939{
3940 protected:
3941 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3942
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003943 void testSetUp() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003944 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003945 Texture2DTestES3::testSetUp();
Vincent Lang25ab4512016-05-13 18:13:59 +02003946
3947 glActiveTexture(GL_TEXTURE0);
3948 glGenTextures(3, mTextures);
3949 glGenFramebuffers(1, &mFBO);
3950 glGenRenderbuffers(1, &mRenderbuffer);
3951
3952 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3953 {
3954 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3955 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3956 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3957 }
3958
3959 glBindTexture(GL_TEXTURE_2D, 0);
3960
3961 ASSERT_GL_NO_ERROR();
3962 }
3963
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003964 void testTearDown() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003965 {
3966 glDeleteTextures(3, mTextures);
3967 glDeleteFramebuffers(1, &mFBO);
3968 glDeleteRenderbuffers(1, &mRenderbuffer);
3969
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003970 Texture2DTestES3::testTearDown();
Vincent Lang25ab4512016-05-13 18:13:59 +02003971 }
3972
3973 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3974 {
Geoff Langf607c602016-09-21 11:46:48 -04003975 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3976 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003977
3978 setUpProgram();
3979
3980 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3981 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3982 0);
3983
3984 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3985 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3986
3987 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003988 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003989
3990 EXPECT_GL_NO_ERROR();
3991
3992 drawQuad(mProgram, "position", 0.5f);
3993
Geoff Langf607c602016-09-21 11:46:48 -04003994 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003995
Jamie Madill50cf2be2018-06-15 09:46:57 -04003996 EXPECT_PIXEL_COLOR_EQ(0, 0,
3997 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3998 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003999
4000 glBindFramebuffer(GL_FRAMEBUFFER, 0);
4001
4002 ASSERT_GL_NO_ERROR();
4003 }
4004
4005 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
4006 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04004007 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04004008 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02004009
4010 setUpProgram();
4011
4012 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
4013 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
4014
4015 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
4016 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
4017 0);
4018
4019 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04004020 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02004021
4022 EXPECT_GL_NO_ERROR();
4023
4024 drawQuad(mProgram, "position", 0.5f);
4025
shrekshaofb1c2fe2019-11-13 11:10:39 -08004026 EXPECT_PIXEL_16UI_COLOR(0, 0,
4027 SliceFormatColor16UI(format, GLColor16UI(pixelValue, pixelValue,
4028 pixelValue, pixelValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02004029
4030 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
4031 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
4032 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
4033 mRenderbuffer);
4034 glBindRenderbuffer(GL_RENDERBUFFER, 0);
4035 EXPECT_GL_NO_ERROR();
4036
4037 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
4038 glClear(GL_COLOR_BUFFER_BIT);
4039
shrekshaofb1c2fe2019-11-13 11:10:39 -08004040 EXPECT_PIXEL_16UI_COLOR(
4041 0, 0, SliceFormatColor16UI(format, GLColor16UI(0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF)));
shrekshaoe33c1582019-11-06 16:55:29 -08004042
4043 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Vincent Lang25ab4512016-05-13 18:13:59 +02004044 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
4045
shrekshaoe33c1582019-11-06 16:55:29 -08004046 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
4047 0);
shrekshaofb1c2fe2019-11-13 11:10:39 -08004048 EXPECT_PIXEL_16UI_COLOR(
4049 0, 0, SliceFormatColor16UI(format, GLColor16UI(0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF)));
Vincent Lang25ab4512016-05-13 18:13:59 +02004050
4051 ASSERT_GL_NO_ERROR();
shrekshaofb1c2fe2019-11-13 11:10:39 -08004052
4053 glBindFramebuffer(GL_FRAMEBUFFER, 0);
Vincent Lang25ab4512016-05-13 18:13:59 +02004054 }
4055
4056 GLuint mTextures[3];
4057 GLuint mFBO;
4058 GLuint mRenderbuffer;
4059};
4060
4061// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
4062TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
4063{
shrekshaoe33c1582019-11-06 16:55:29 -08004064 // TODO(crbug.com/angleproject/4089) Fails on Nexus5X Adreno
shrekshao91075772019-11-18 15:00:29 -08004065 // TODO(crbug.com/1024387) Fails on Nexus6P
4066 ANGLE_SKIP_TEST_IF(IsNexus5X() || IsNexus6P());
shrekshaoe33c1582019-11-06 16:55:29 -08004067 // TODO(crbug.com/angleproject/4089) Fails on Win Intel OpenGL driver
4068 ANGLE_SKIP_TEST_IF(IsIntel() && IsOpenGL());
4069
Jamie Madillb8149072019-04-30 16:14:44 -04004070 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02004071
4072 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
4073 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
4074 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
4075 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
4076 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
4077 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
4078 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
4079 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
4080
Vincent Lang25ab4512016-05-13 18:13:59 +02004081 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
4082}
4083
Mohan Maiya8f1169e2019-06-27 15:32:32 -07004084class Texture2DRGTest : public Texture2DTest
4085{
4086 protected:
4087 Texture2DRGTest()
4088 : Texture2DTest(), mRenderableTexture(0), mTestTexture(0), mFBO(0), mRenderbuffer(0)
4089 {}
4090
4091 void testSetUp() override
4092 {
4093 Texture2DTest::testSetUp();
4094
4095 glActiveTexture(GL_TEXTURE0);
4096 glGenTextures(1, &mRenderableTexture);
4097 glGenTextures(1, &mTestTexture);
4098 glGenFramebuffers(1, &mFBO);
4099 glGenRenderbuffers(1, &mRenderbuffer);
4100
4101 glBindTexture(GL_TEXTURE_2D, mRenderableTexture);
Mohan Maiya6caa2652019-09-11 08:06:13 -07004102 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4103 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
Mohan Maiya8f1169e2019-06-27 15:32:32 -07004104 glBindTexture(GL_TEXTURE_2D, mTestTexture);
Mohan Maiya6caa2652019-09-11 08:06:13 -07004105 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4106 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
Mohan Maiya8f1169e2019-06-27 15:32:32 -07004107
4108 glBindTexture(GL_TEXTURE_2D, 0);
4109
4110 setUpProgram();
4111 glUseProgram(mProgram);
4112 glUniform1i(mTexture2DUniformLocation, 0);
4113
4114 ASSERT_GL_NO_ERROR();
4115 }
4116
4117 void testTearDown() override
4118 {
4119 glDeleteTextures(1, &mRenderableTexture);
4120 glDeleteTextures(1, &mTestTexture);
4121 glDeleteFramebuffers(1, &mFBO);
4122 glDeleteRenderbuffers(1, &mRenderbuffer);
4123
4124 Texture2DTest::testTearDown();
4125 }
4126
4127 void setupFormatTextures(GLenum internalformat, GLenum format, GLenum type, GLvoid *imageData)
4128 {
4129 glBindTexture(GL_TEXTURE_2D, mRenderableTexture);
4130 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4131
4132 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
4133 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
4134 mRenderableTexture, 0);
4135
4136 glBindTexture(GL_TEXTURE_2D, mTestTexture);
4137 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
4138
4139 EXPECT_GL_NO_ERROR();
4140 }
4141
4142 void testRGTexture(GLColor expectedColor)
4143 {
4144 drawQuad(mProgram, "position", 0.5f);
4145
4146 EXPECT_GL_NO_ERROR();
4147 EXPECT_PIXEL_COLOR_NEAR(0, 0, expectedColor, kPixelTolerance);
4148 }
4149
4150 void testRGRender(GLenum internalformat, GLenum format)
4151 {
4152 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
4153 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
4154 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
4155 mRenderbuffer);
4156 glBindRenderbuffer(GL_RENDERBUFFER, 0);
4157 EXPECT_GL_NO_ERROR();
4158
4159 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
4160 glClear(GL_COLOR_BUFFER_BIT);
4161
4162 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
4163
4164 ASSERT_GL_NO_ERROR();
4165 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor(255u, 255u, 255u, 255u)));
4166 }
4167
4168 GLuint mRenderableTexture;
4169 GLuint mTestTexture;
4170 GLuint mFBO;
4171 GLuint mRenderbuffer;
4172};
4173
4174// Test unorm texture formats enabled by the GL_EXT_texture_rg extension.
4175TEST_P(Texture2DRGTest, TextureRGUNormTest)
4176{
4177 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_rg"));
4178
4179 GLubyte pixelValue = 0xab;
4180 GLubyte imageData[] = {pixelValue, pixelValue};
4181
4182 setupFormatTextures(GL_RED_EXT, GL_RED_EXT, GL_UNSIGNED_BYTE, imageData);
4183 testRGTexture(
4184 SliceFormatColor(GL_RED_EXT, GLColor(pixelValue, pixelValue, pixelValue, pixelValue)));
4185 testRGRender(GL_R8_EXT, GL_RED_EXT);
4186
4187 setupFormatTextures(GL_RG_EXT, GL_RG_EXT, GL_UNSIGNED_BYTE, imageData);
4188 testRGTexture(
4189 SliceFormatColor(GL_RG_EXT, GLColor(pixelValue, pixelValue, pixelValue, pixelValue)));
4190 testRGRender(GL_RG8_EXT, GL_RG_EXT);
4191}
4192
4193// Test float texture formats enabled by the GL_EXT_texture_rg extension.
4194TEST_P(Texture2DRGTest, TextureRGFloatTest)
4195{
4196 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_rg"));
4197 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
4198
4199 GLfloat pixelValue = 0.54321;
4200 GLfloat imageData[] = {pixelValue, pixelValue};
4201
4202 GLubyte expectedValue = static_cast<GLubyte>(pixelValue * 255.0f);
4203 GLColor expectedColor = GLColor(expectedValue, expectedValue, expectedValue, expectedValue);
4204
4205 setupFormatTextures(GL_RED_EXT, GL_RED_EXT, GL_FLOAT, imageData);
4206 testRGTexture(SliceFormatColor(GL_RED_EXT, expectedColor));
4207
4208 setupFormatTextures(GL_RG_EXT, GL_RG_EXT, GL_FLOAT, imageData);
4209 testRGTexture(SliceFormatColor(GL_RG_EXT, expectedColor));
4210}
4211
4212// Test half-float texture formats enabled by the GL_EXT_texture_rg extension.
Mohan Maiya6caa2652019-09-11 08:06:13 -07004213TEST_P(Texture2DRGTest, TextureRGHalfFloatTest)
Mohan Maiya8f1169e2019-06-27 15:32:32 -07004214{
4215 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_rg"));
4216 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_half_float"));
4217
4218 GLfloat pixelValueFloat = 0.543f;
4219 GLhalf pixelValue = 0x3858;
4220 GLhalf imageData[] = {pixelValue, pixelValue};
4221
4222 GLubyte expectedValue = static_cast<GLubyte>(pixelValueFloat * 255.0f);
4223 GLColor expectedColor = GLColor(expectedValue, expectedValue, expectedValue, expectedValue);
4224
4225 setupFormatTextures(GL_RED_EXT, GL_RED_EXT, GL_HALF_FLOAT_OES, imageData);
4226 testRGTexture(SliceFormatColor(GL_RED_EXT, expectedColor));
4227
4228 setupFormatTextures(GL_RG_EXT, GL_RG_EXT, GL_HALF_FLOAT_OES, imageData);
4229 testRGTexture(SliceFormatColor(GL_RG_EXT, expectedColor));
4230}
4231
Mohan Maiya6caa2652019-09-11 08:06:13 -07004232class Texture2DFloatTest : public Texture2DTest
4233{
4234 protected:
4235 Texture2DFloatTest()
4236 : Texture2DTest(), mRenderableTexture(0), mTestTexture(0), mFBO(0), mRenderbuffer(0)
4237 {}
4238
4239 void testSetUp() override
4240 {
4241 Texture2DTest::testSetUp();
4242
4243 glActiveTexture(GL_TEXTURE0);
4244 glGenTextures(1, &mRenderableTexture);
4245 glGenTextures(1, &mTestTexture);
4246 glGenFramebuffers(1, &mFBO);
4247 glGenRenderbuffers(1, &mRenderbuffer);
4248
4249 setUpProgram();
4250 glUseProgram(mProgram);
4251 glUniform1i(mTexture2DUniformLocation, 0);
4252
4253 glBindTexture(GL_TEXTURE_2D, mRenderableTexture);
4254 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4255
4256 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
4257 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
4258 mRenderableTexture, 0);
4259
4260 ASSERT_GL_NO_ERROR();
4261 }
4262
4263 void testTearDown() override
4264 {
4265 glDeleteTextures(1, &mRenderableTexture);
4266 glDeleteTextures(1, &mTestTexture);
4267 glDeleteFramebuffers(1, &mFBO);
4268 glDeleteRenderbuffers(1, &mRenderbuffer);
4269
4270 Texture2DTest::testTearDown();
4271 }
4272
4273 void testFloatTextureSample(GLenum internalFormat, GLenum format, GLenum type)
4274 {
4275 constexpr GLfloat imageDataFloat[] = {
4276 0.2f,
4277 0.3f,
4278 0.4f,
4279 0.5f,
4280 };
4281 constexpr GLhalf imageDataHalf[] = {
4282 0x3266,
4283 0x34CD,
4284 0x3666,
4285 0x3800,
4286 };
4287 GLColor expectedValue;
4288 for (int i = 0; i < 4; i++)
4289 {
4290 expectedValue[i] = static_cast<GLubyte>(imageDataFloat[i] * 255.0f);
4291 }
4292
4293 const GLvoid *imageData;
4294 switch (type)
4295 {
4296 case GL_FLOAT:
4297 imageData = imageDataFloat;
4298 break;
4299 case GL_HALF_FLOAT:
4300 case GL_HALF_FLOAT_OES:
4301 imageData = imageDataHalf;
4302 break;
4303 default:
4304 imageData = nullptr;
4305 }
4306 ASSERT(imageData != nullptr);
4307
4308 glBindTexture(GL_TEXTURE_2D, mTestTexture);
4309 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, 1, 1, 0, format, type, imageData);
4310
4311 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4312 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4313
4314 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
4315 drawQuad(mProgram, "position", 0.5f);
4316
4317 EXPECT_GL_NO_ERROR();
4318 EXPECT_PIXEL_COLOR_NEAR(0, 0, SliceFormatColor(format, expectedValue), kPixelTolerance);
4319 }
4320
4321 void testFloatTextureLinear(GLenum internalFormat, GLenum format, GLenum type)
4322 {
4323 int numComponents;
4324 switch (format)
4325 {
4326 case GL_RGBA:
4327 numComponents = 4;
4328 break;
4329 case GL_RGB:
4330 numComponents = 3;
4331 break;
4332 case GL_LUMINANCE_ALPHA:
4333 numComponents = 2;
4334 break;
4335 case GL_LUMINANCE:
4336 case GL_ALPHA:
4337 numComponents = 1;
4338 break;
4339 default:
4340 numComponents = 0;
4341 }
4342 ASSERT(numComponents > 0);
4343
4344 constexpr GLfloat pixelIntensitiesFloat[] = {0.0f, 1.0f, 0.0f, 1.0f};
4345 constexpr GLhalf pixelIntensitiesHalf[] = {0x0000, 0x3C00, 0x0000, 0x3C00};
4346
4347 GLfloat imageDataFloat[16];
4348 GLhalf imageDataHalf[16];
4349 for (int i = 0; i < 4; i++)
4350 {
4351 for (int c = 0; c < numComponents; c++)
4352 {
4353 imageDataFloat[i * numComponents + c] = pixelIntensitiesFloat[i];
4354 imageDataHalf[i * numComponents + c] = pixelIntensitiesHalf[i];
4355 }
4356 }
4357
4358 const GLvoid *imageData;
4359 switch (type)
4360 {
4361 case GL_FLOAT:
4362 imageData = imageDataFloat;
4363 break;
4364 case GL_HALF_FLOAT:
4365 case GL_HALF_FLOAT_OES:
4366 imageData = imageDataHalf;
4367 break;
4368 default:
4369 imageData = nullptr;
4370 }
4371 ASSERT(imageData != nullptr);
4372
4373 glBindTexture(GL_TEXTURE_2D, mTestTexture);
4374 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, 2, 2, 0, format, type, imageData);
4375
4376 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4377 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4378
4379 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
4380 drawQuad(mProgram, "position", 0.5f);
4381
4382 EXPECT_GL_NO_ERROR();
4383 // Source texture contains 2 black pixels and 2 white pixels, we sample in the center so we
4384 // should expect the final value to be gray (halfway in-between)
4385 EXPECT_PIXEL_COLOR_NEAR(0, 0, SliceFormatColor(format, GLColor(127u, 127u, 127u, 127u)),
4386 kPixelTolerance);
4387 }
4388
4389 bool performFloatTextureRender(GLenum internalFormat,
4390 GLenum renderBufferFormat,
4391 GLenum format,
4392 GLenum type)
4393 {
4394 glBindTexture(GL_TEXTURE_2D, mTestTexture);
4395 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, 1, 1, 0, format, type, nullptr);
4396 glBindTexture(GL_TEXTURE_2D, 0);
4397
4398 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
4399 glRenderbufferStorage(GL_RENDERBUFFER, renderBufferFormat, 1, 1);
4400 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
4401 mRenderbuffer);
4402 glBindRenderbuffer(GL_RENDERBUFFER, 0);
4403 EXPECT_GL_NO_ERROR();
4404
4405 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
4406 {
4407 return false;
4408 }
4409
4410 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
4411
4412 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
4413 glClear(GL_COLOR_BUFFER_BIT);
4414
4415 EXPECT_GL_NO_ERROR();
4416 return true;
4417 }
4418
4419 GLuint mRenderableTexture;
4420 GLuint mTestTexture;
4421 GLuint mFBO;
4422 GLuint mRenderbuffer;
4423};
4424
4425class Texture2DFloatTestES3 : public Texture2DFloatTest
4426{
4427 protected:
4428 void testFloatTextureRender(GLenum internalFormat, GLenum format, GLenum type)
4429 {
4430 bool framebufferComplete =
4431 performFloatTextureRender(internalFormat, internalFormat, format, type);
4432 EXPECT_TRUE(framebufferComplete);
4433 EXPECT_PIXEL_COLOR32F_NEAR(0, 0,
4434 SliceFormatColor32F(format, GLColor32F(1.0f, 1.0f, 1.0f, 1.0f)),
4435 kPixelTolerance32F);
4436 }
4437};
4438
4439class Texture2DFloatTestES2 : public Texture2DFloatTest
4440{
4441 protected:
4442 bool checkFloatTextureRender(GLenum renderBufferFormat, GLenum format, GLenum type)
4443 {
4444 bool framebufferComplete =
4445 performFloatTextureRender(format, renderBufferFormat, format, type);
4446
4447 if (!framebufferComplete)
4448 {
4449 return false;
4450 }
4451
4452 EXPECT_PIXEL_COLOR32F_NEAR(0, 0,
4453 SliceFormatColor32F(format, GLColor32F(1.0f, 1.0f, 1.0f, 1.0f)),
4454 kPixelTolerance32F);
4455 return true;
4456 }
4457};
4458
4459// Test texture sampling for ES3 float texture formats
4460TEST_P(Texture2DFloatTestES3, TextureFloatSampleBasicTest)
4461{
4462 testFloatTextureSample(GL_RGBA32F, GL_RGBA, GL_FLOAT);
4463 testFloatTextureSample(GL_RGB32F, GL_RGB, GL_FLOAT);
4464}
4465
4466// Test texture sampling for ES2 float texture formats
4467TEST_P(Texture2DFloatTestES2, TextureFloatSampleBasicTest)
4468{
4469 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
4470 testFloatTextureSample(GL_RGBA, GL_RGBA, GL_FLOAT);
4471 testFloatTextureSample(GL_RGB, GL_RGB, GL_FLOAT);
4472}
4473
4474// Test texture sampling for ES3 half float texture formats
4475TEST_P(Texture2DFloatTestES3, TextureHalfFloatSampleBasicTest)
4476{
4477 testFloatTextureSample(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT);
4478 testFloatTextureSample(GL_RGB16F, GL_RGB, GL_HALF_FLOAT);
4479}
4480
4481// Test texture sampling for ES2 half float texture formats
4482TEST_P(Texture2DFloatTestES2, TextureHalfFloatSampleBasicTest)
4483{
4484 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_half_float"));
4485 testFloatTextureSample(GL_RGBA, GL_RGBA, GL_HALF_FLOAT_OES);
4486 testFloatTextureSample(GL_RGB, GL_RGB, GL_HALF_FLOAT_OES);
4487}
4488
4489// Test texture sampling for legacy GLES 2.0 float texture formats in ES3
4490TEST_P(Texture2DFloatTestES3, TextureFloatSampleLegacyTest)
4491{
4492 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
4493
4494 testFloatTextureSample(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT);
4495 testFloatTextureSample(GL_ALPHA, GL_ALPHA, GL_FLOAT);
4496 testFloatTextureSample(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT);
4497
4498 if (IsGLExtensionEnabled("GL_EXT_texture_storage"))
4499 {
4500 testFloatTextureSample(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT);
4501 testFloatTextureSample(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT);
4502 testFloatTextureSample(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT);
4503 }
4504}
4505
4506// Test texture sampling for legacy GLES 2.0 float texture formats in ES2
4507TEST_P(Texture2DFloatTestES2, TextureFloatSampleLegacyTest)
4508{
4509 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
4510
4511 testFloatTextureSample(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT);
4512 testFloatTextureSample(GL_ALPHA, GL_ALPHA, GL_FLOAT);
4513 testFloatTextureSample(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT);
4514}
4515
4516// Test texture sampling for legacy GLES 2.0 half float texture formats in ES3
4517TEST_P(Texture2DFloatTestES3, TextureHalfFloatSampleLegacyTest)
4518{
4519 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_half_float"));
4520
4521 testFloatTextureSample(GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT_OES);
4522 testFloatTextureSample(GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT_OES);
4523 testFloatTextureSample(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES);
4524
4525 if (IsGLExtensionEnabled("GL_EXT_texture_storage"))
4526 {
4527 testFloatTextureSample(GL_LUMINANCE16F_EXT, GL_LUMINANCE, GL_HALF_FLOAT);
4528 testFloatTextureSample(GL_ALPHA16F_EXT, GL_ALPHA, GL_HALF_FLOAT);
4529 testFloatTextureSample(GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT);
4530 }
4531}
4532// Test texture sampling for legacy GLES 2.0 half float texture formats in ES2
4533TEST_P(Texture2DFloatTestES2, TextureHalfFloatSampleLegacyTest)
4534{
4535 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_half_float"));
4536
4537 testFloatTextureSample(GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT_OES);
4538 testFloatTextureSample(GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT_OES);
4539 testFloatTextureSample(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES);
4540}
4541
4542// Test linear sampling for ES3 32F formats
4543TEST_P(Texture2DFloatTestES3, TextureFloatLinearTest)
4544{
4545 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float_linear"));
4546
4547 testFloatTextureLinear(GL_RGBA32F, GL_RGBA, GL_FLOAT);
4548 testFloatTextureLinear(GL_RGB32F, GL_RGB, GL_FLOAT);
4549}
4550// Test linear sampling for ES2 32F formats
4551TEST_P(Texture2DFloatTestES2, TextureFloatLinearTest)
4552{
4553 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float_linear"));
4554
4555 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
4556
4557 testFloatTextureLinear(GL_RGBA, GL_RGBA, GL_FLOAT);
4558}
4559
4560// Test linear sampling for ES3 16F formats
4561TEST_P(Texture2DFloatTestES3, TextureHalfFloatLinearTest)
4562{
4563 // Half float formats must be linearly filterable in GLES 3.0 core
4564 testFloatTextureLinear(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT);
4565 testFloatTextureLinear(GL_RGB16F, GL_RGB, GL_HALF_FLOAT);
4566}
4567// Test linear sampling for ES2 16F formats
4568TEST_P(Texture2DFloatTestES2, TextureHalfFloatLinearTest)
4569{
4570 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_half_float_linear"));
4571 testFloatTextureLinear(GL_RGBA, GL_RGBA, GL_HALF_FLOAT_OES);
4572 testFloatTextureLinear(GL_RGB, GL_RGB, GL_HALF_FLOAT_OES);
4573}
4574
4575// Test linear sampling for legacy GLES 2.0 32F formats in ES3
4576TEST_P(Texture2DFloatTestES3, TextureFloatLinearLegacyTest)
4577{
4578 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
4579 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float_linear"));
4580
4581 testFloatTextureLinear(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT);
4582 testFloatTextureLinear(GL_ALPHA, GL_ALPHA, GL_FLOAT);
4583 testFloatTextureLinear(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT);
4584
4585 if (IsGLExtensionEnabled("GL_EXT_texture_storage"))
4586 {
4587 testFloatTextureLinear(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT);
4588 testFloatTextureLinear(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT);
4589 testFloatTextureLinear(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT);
4590 }
4591}
4592// Test linear sampling for legacy GLES 2.0 32F formats in ES2
4593TEST_P(Texture2DFloatTestES2, TextureFloatLinearLegacyTest)
4594{
4595 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
4596 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float_linear"));
4597
4598 testFloatTextureLinear(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT);
4599 testFloatTextureLinear(GL_ALPHA, GL_ALPHA, GL_FLOAT);
4600 testFloatTextureLinear(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT);
4601}
4602
4603// Test linear sampling for legacy GLES 2.0 16F formats in ES3
4604TEST_P(Texture2DFloatTestES3, TextureHalfFloatLinearLegacyTest)
4605{
4606 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_half_float"));
4607 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_half_float_linear"));
4608
4609 testFloatTextureLinear(GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT_OES);
4610 testFloatTextureLinear(GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT_OES);
4611 testFloatTextureLinear(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES);
4612
4613 if (IsGLExtensionEnabled("GL_EXT_texture_storage"))
4614 {
4615 testFloatTextureLinear(GL_LUMINANCE16F_EXT, GL_LUMINANCE, GL_HALF_FLOAT);
4616 testFloatTextureLinear(GL_ALPHA16F_EXT, GL_ALPHA, GL_HALF_FLOAT);
4617 testFloatTextureLinear(GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT);
4618 }
4619}
4620// Test linear sampling for legacy GLES 2.0 16F formats in ES2
4621TEST_P(Texture2DFloatTestES2, TextureHalfFloatLinearLegacyTest)
4622{
4623 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_half_float"));
4624 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_half_float_linear"));
4625
4626 testFloatTextureLinear(GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT_OES);
4627 testFloatTextureLinear(GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT_OES);
4628 testFloatTextureLinear(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES);
4629}
4630
4631// Test color-renderability for ES3 float and half float textures
4632TEST_P(Texture2DFloatTestES3, TextureFloatRenderTest)
4633{
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 // EXT_color_buffer_float covers float, half float, and 11-11-10 float formats
4637 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_color_buffer_float"));
4638
4639 testFloatTextureRender(GL_R32F, GL_RED, GL_FLOAT);
4640 testFloatTextureRender(GL_RG32F, GL_RG, GL_FLOAT);
4641 testFloatTextureRender(GL_RGBA32F, GL_RGBA, GL_FLOAT);
4642
4643 testFloatTextureRender(GL_R16F, GL_RED, GL_HALF_FLOAT);
4644 testFloatTextureRender(GL_RG16F, GL_RG, GL_HALF_FLOAT);
4645 testFloatTextureRender(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT);
4646
4647 testFloatTextureRender(GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT);
4648}
4649
4650// Test color-renderability for ES2 half float textures
4651TEST_P(Texture2DFloatTestES2, TextureFloatRenderTest)
4652{
4653 // EXT_color_buffer_half_float requires at least one format to be renderable, but does not
4654 // require a specific one
4655 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_color_buffer_half_float"));
Zhenyao Mo20bb47d2019-09-16 12:55:30 -07004656 // https://crbug.com/1003971
4657 ANGLE_SKIP_TEST_IF(IsOzone());
Tobin Ehlis1a01b4b2019-11-11 16:41:07 -07004658 // http://anglebug.com/4092
4659 ANGLE_SKIP_TEST_IF(IsD3D9());
Mohan Maiya6caa2652019-09-11 08:06:13 -07004660
4661 bool atLeastOneSupported = false;
4662
4663 if (IsGLExtensionEnabled("GL_OES_texture_half_float") ||
4664 IsGLExtensionEnabled("GL_OES_texture_half_float"))
4665 {
4666 atLeastOneSupported |= checkFloatTextureRender(GL_R16F_EXT, GL_RED_EXT, GL_HALF_FLOAT_OES);
4667 atLeastOneSupported |= checkFloatTextureRender(GL_RG16F_EXT, GL_RG_EXT, GL_HALF_FLOAT_OES);
4668 }
4669 if (IsGLExtensionEnabled("GL_OES_texture_half_float"))
4670 {
4671 atLeastOneSupported |= checkFloatTextureRender(GL_RGB16F_EXT, GL_RGB, GL_HALF_FLOAT_OES);
4672
4673 // If OES_texture_half_float is supported, then RGBA half float textures must be renderable
4674 bool rgbaSupported = checkFloatTextureRender(GL_RGBA16F_EXT, GL_RGBA, GL_HALF_FLOAT_OES);
4675 EXPECT_TRUE(rgbaSupported);
4676 atLeastOneSupported |= rgbaSupported;
4677 }
4678
4679 EXPECT_TRUE(atLeastOneSupported);
4680}
4681
Olli Etuaho95faa232016-06-07 14:01:53 -07004682// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
4683// GLES 3.0.4 section 3.8.3.
4684TEST_P(Texture2DTestES3, UnpackSkipImages2D)
4685{
Yuly Novikovd18c0482019-04-04 19:56:43 -04004686 // Crashes on Nexus 5X due to a driver bug. http://anglebug.com/1429
4687 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07004688
4689 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4690 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4691 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4692 ASSERT_GL_NO_ERROR();
4693
4694 // SKIP_IMAGES should not have an effect on uploading 2D textures
4695 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
4696 ASSERT_GL_NO_ERROR();
4697
4698 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
4699
4700 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4701 pixelsGreen.data());
4702 ASSERT_GL_NO_ERROR();
4703
4704 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
4705 pixelsGreen.data());
4706 ASSERT_GL_NO_ERROR();
4707
4708 glUseProgram(mProgram);
4709 drawQuad(mProgram, "position", 0.5f);
4710 ASSERT_GL_NO_ERROR();
4711
4712 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
4713}
4714
Olli Etuaho989cac32016-06-08 16:18:49 -07004715// Test that skip defined in unpack parameters is taken into account when determining whether
4716// unpacking source extends outside unpack buffer bounds.
4717TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
4718{
4719 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4720 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4721 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4722 ASSERT_GL_NO_ERROR();
4723
4724 GLBuffer buf;
4725 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
4726 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
4727 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
4728 GL_DYNAMIC_COPY);
4729 ASSERT_GL_NO_ERROR();
4730
4731 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4732 ASSERT_GL_NO_ERROR();
4733
4734 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
4735 ASSERT_GL_NO_ERROR();
4736
4737 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4738 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4739
4740 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
4741 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
4742 ASSERT_GL_NO_ERROR();
4743
4744 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4745 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4746}
4747
Olli Etuaho218cf9e2016-05-20 13:55:24 +03004748// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
4749TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
4750{
Yunchao He9550c602018-02-13 14:47:05 +08004751 ANGLE_SKIP_TEST_IF(IsD3D11());
4752
4753 // Incorrect rendering results seen on OSX AMD.
4754 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03004755
4756 const GLuint width = 8u;
4757 const GLuint height = 8u;
4758 const GLuint unpackRowLength = 5u;
4759 const GLuint unpackSkipPixels = 1u;
4760
4761 setWindowWidth(width);
4762 setWindowHeight(height);
4763
4764 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4765 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4766 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4767 ASSERT_GL_NO_ERROR();
4768
4769 GLBuffer buf;
4770 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
4771 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
4772 GLColor::green);
4773
4774 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
4775 {
4776 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
4777 }
4778
4779 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
4780 GL_DYNAMIC_COPY);
4781 ASSERT_GL_NO_ERROR();
4782
4783 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
4784 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
4785 ASSERT_GL_NO_ERROR();
4786
4787 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4788 ASSERT_GL_NO_ERROR();
4789
4790 glUseProgram(mProgram);
4791 drawQuad(mProgram, "position", 0.5f);
4792 ASSERT_GL_NO_ERROR();
4793
4794 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
4795 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
4796 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
4797 actual.data());
4798 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
4799 EXPECT_EQ(expected, actual);
4800}
4801
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004802template <typename T>
4803T UNorm(double value)
4804{
4805 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
4806}
4807
4808// Test rendering a depth texture with mipmaps.
4809TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
4810{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08004811 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
4812 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
Jiawei Shaoaf0f31d2018-09-27 15:42:31 +08004813 // http://anglebug.com/1706
4814 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Corentin Walleze731d8a2016-09-07 10:56:25 -04004815
Jamie Madill24980272019-04-03 09:03:51 -04004816 // Seems to fail on AMD D3D11. Possibly driver bug. http://anglebug.com/3342
4817 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsD3D11());
4818
Cody Northrop988f7172019-09-30 15:52:37 -06004819 // TODO(cnorthrop): Also failing on Vulkan/Windows/AMD. http://anglebug.com/3950
Cody Northropcb16fb52019-08-29 16:53:55 -06004820 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsVulkan());
4821
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004822 const int size = getWindowWidth();
4823
4824 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04004825 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004826
4827 glActiveTexture(GL_TEXTURE0);
4828 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4829 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
4830 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4831 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4832 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
4833 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
4834 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4835 ASSERT_GL_NO_ERROR();
4836
4837 glUseProgram(mProgram);
4838 glUniform1i(mTexture2DUniformLocation, 0);
4839
4840 std::vector<unsigned char> expected;
4841
4842 for (int level = 0; level < levels; ++level)
4843 {
4844 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
4845 expected.push_back(UNorm<unsigned char>(value));
4846
4847 int levelDim = dim(level);
4848
4849 ASSERT_GT(levelDim, 0);
4850
4851 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
4852 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
4853 GL_UNSIGNED_INT, initData.data());
4854 }
4855 ASSERT_GL_NO_ERROR();
4856
4857 for (int level = 0; level < levels; ++level)
4858 {
4859 glViewport(0, 0, dim(level), dim(level));
4860 drawQuad(mProgram, "position", 0.5f);
4861 GLColor actual = ReadColor(0, 0);
4862 EXPECT_NEAR(expected[level], actual.R, 10u);
4863 }
4864
4865 ASSERT_GL_NO_ERROR();
4866}
4867
Courtney Goeltzenleuchter1f2782e2019-08-29 14:19:23 -06004868class Texture2DDepthTest : public Texture2DTest
4869{
4870 protected:
4871 Texture2DDepthTest() : Texture2DTest() {}
4872
4873 const char *getVertexShaderSource() override
4874 {
4875 return "attribute vec4 vPosition;\n"
4876 "void main() {\n"
4877 " gl_Position = vPosition;\n"
4878 "}\n";
4879 }
4880
4881 const char *getFragmentShaderSource() override
4882 {
4883 return "precision mediump float;\n"
4884 "uniform sampler2D ShadowMap;"
4885 "void main() {\n"
4886 " vec4 shadow_value = texture2D(ShadowMap, vec2(0.5, 0.5));"
4887 " if (shadow_value.x == shadow_value.z && shadow_value.x != 0.0) {"
4888 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);"
4889 " } else {"
4890 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
4891 " }"
4892 "}\n";
4893 }
4894
4895 bool checkTexImageFormatSupport(GLenum format, GLenum internalformat, GLenum type)
4896 {
4897 EXPECT_GL_NO_ERROR();
4898
4899 GLTexture tex;
4900 glBindTexture(GL_TEXTURE_2D, tex);
4901 glTexImage2D(GL_TEXTURE_2D, 0, format, 1, 1, 0, format, type, nullptr);
4902
4903 return (glGetError() == GL_NO_ERROR);
4904 }
4905
4906 void testBehavior(bool useSizedComponent)
4907 {
4908 int w = getWindowWidth();
4909 int h = getWindowHeight();
4910 GLuint format = GL_DEPTH_COMPONENT;
4911 GLuint internalFormat = GL_DEPTH_COMPONENT;
4912
4913 if (useSizedComponent)
4914 {
4915 internalFormat = GL_DEPTH_COMPONENT24;
4916 }
4917
4918 GLFramebuffer fbo;
4919 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
4920 ASSERT_GL_NO_ERROR();
4921
4922 GLTexture depthTexture;
4923 glBindTexture(GL_TEXTURE_2D, depthTexture);
4924 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4925 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4926 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
4927 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
4928
4929 TexCoordDrawTest::setUpProgram();
4930 GLint shadowMapLocation = glGetUniformLocation(mProgram, "ShadowMap");
4931 ASSERT_NE(-1, shadowMapLocation);
4932
4933 GLint positionLocation = glGetAttribLocation(mProgram, "vPosition");
4934 ASSERT_NE(-1, positionLocation);
4935
4936 ANGLE_SKIP_TEST_IF(!checkTexImageFormatSupport(format, internalFormat, GL_UNSIGNED_INT));
4937 glBindTexture(GL_TEXTURE_2D, depthTexture);
4938 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, w, h, 0, format, GL_UNSIGNED_INT, nullptr);
4939 ASSERT_GL_NO_ERROR();
4940
4941 // try adding a color buffer.
4942 GLuint colorTex = 0;
4943 glGenTextures(1, &colorTex);
4944 glBindTexture(GL_TEXTURE_2D, colorTex);
4945 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
4946 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
4947 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4948 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4949 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4950 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTex, 0);
4951 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture, 0);
4952 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
4953 ASSERT_GL_NO_ERROR();
4954
4955 glViewport(0, 0, w, h);
4956 // Fill depthTexture with 0.75
4957 glClearDepthf(0.75);
4958 glClear(GL_DEPTH_BUFFER_BIT);
4959
4960 // Revert to normal framebuffer to test depth shader
4961 glBindFramebuffer(GL_FRAMEBUFFER, 0);
4962 glViewport(0, 0, w, h);
4963 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
4964 glClearDepthf(0.0f);
4965 ASSERT_GL_NO_ERROR();
4966
4967 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
4968 ASSERT_GL_NO_ERROR();
4969
4970 glActiveTexture(GL_TEXTURE0);
4971 glBindTexture(GL_TEXTURE_2D, depthTexture);
4972
4973 glUseProgram(mProgram);
4974 ASSERT_GL_NO_ERROR();
4975
4976 glUniform1i(shadowMapLocation, 0);
4977
4978 const GLfloat gTriangleVertices[] = {-0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, 0.5f};
4979
4980 glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, 0, gTriangleVertices);
4981 ASSERT_GL_NO_ERROR();
4982 glEnableVertexAttribArray(positionLocation);
4983 ASSERT_GL_NO_ERROR();
4984 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
4985 ASSERT_GL_NO_ERROR();
4986
4987 GLuint pixels[1];
4988 glReadPixels(w / 2, h / 2, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
4989 ASSERT_GL_NO_ERROR();
4990
4991 // The GLES 3.x spec says that the depth texture sample can be found in the RED component.
4992 // However, the OES_depth_texture indicates that the depth value is treated as luminance and
4993 // is in all the color components. Multiple implementations implement a workaround that
4994 // follows the OES_depth_texture behavior if the internalformat given at glTexImage2D was a
4995 // unsized format (e.g. DEPTH_COMPONENT) and the GLES 3.x behavior if it was a sized
4996 // internalformat such as GL_DEPTH_COMPONENT24. The shader will write out a different color
4997 // depending on if it sees the texture sample in only the RED component.
4998 if (useSizedComponent)
4999 {
5000 ASSERT_NE(pixels[0], 0xff0000ff);
5001 }
5002 else
5003 {
5004 ASSERT_EQ(pixels[0], 0xff0000ff);
5005 }
5006
5007 glBindFramebuffer(GL_FRAMEBUFFER, 0);
5008 glDeleteProgram(mProgram);
5009 }
5010};
5011
5012// Test depth texture compatibility with OES_depth_texture. Uses unsized internformat.
5013TEST_P(Texture2DDepthTest, DepthTextureES2Compatibility)
5014{
5015 ANGLE_SKIP_TEST_IF(IsD3D11());
5016 ANGLE_SKIP_TEST_IF(IsIntel() && IsD3D9());
Tobin Ehlis7af26762019-10-23 16:18:57 -06005017 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_ANGLE_depth_texture") &&
5018 !IsGLExtensionEnabled("GL_OES_depth_texture"));
Tobin Ehlis1a01b4b2019-11-11 16:41:07 -07005019 // http://anglebug.com/4092
5020 ANGLE_SKIP_TEST_IF(IsOpenGL() || IsOpenGLES());
Courtney Goeltzenleuchter1f2782e2019-08-29 14:19:23 -06005021
5022 // When the depth texture is specified with unsized internalformat implementations follow
5023 // OES_depth_texture behavior. Otherwise they follow GLES 3.0 behavior.
5024 testBehavior(false);
5025}
5026
5027// Test depth texture compatibility with GLES3 using sized internalformat.
5028TEST_P(Texture2DDepthTest, DepthTextureES3Compatibility)
5029{
5030 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3);
5031
5032 testBehavior(true);
5033}
5034
Jamie Madill7ffdda92016-09-08 13:26:51 -04005035// Tests unpacking into the unsized GL_ALPHA format.
5036TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
5037{
Jamie Madill7ffdda92016-09-08 13:26:51 -04005038 // Initialize the texure.
5039 glBindTexture(GL_TEXTURE_2D, mTexture2D);
5040 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
5041 GL_UNSIGNED_BYTE, nullptr);
5042 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5043 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5044
5045 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
5046
5047 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04005048 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04005049 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
5050 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
5051 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
5052 GL_STATIC_DRAW);
5053
5054 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
5055 GL_UNSIGNED_BYTE, nullptr);
5056
5057 // Clear to a weird color to make sure we're drawing something.
5058 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
5059 glClear(GL_COLOR_BUFFER_BIT);
5060
5061 // Draw with the alpha texture and verify.
5062 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04005063
5064 ASSERT_GL_NO_ERROR();
5065 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
5066}
5067
Jamie Madill2e600342016-09-19 13:56:40 -04005068// Ensure stale unpack data doesn't propagate in D3D11.
5069TEST_P(Texture2DTestES3, StaleUnpackData)
5070{
5071 // Init unpack buffer.
5072 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
5073 std::vector<GLColor> pixels(pixelCount, GLColor::red);
5074
5075 GLBuffer unpackBuffer;
5076 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
5077 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
5078 GLsizei bufferSize = pixelCount * sizeof(GLColor);
5079 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
5080
5081 // Create from unpack buffer.
5082 glBindTexture(GL_TEXTURE_2D, mTexture2D);
5083 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
5084 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
5085 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5086 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5087
5088 drawQuad(mProgram, "position", 0.5f);
5089
5090 ASSERT_GL_NO_ERROR();
5091 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
5092
5093 // Fill unpack with green, recreating buffer.
5094 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
5095 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
5096 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
5097
5098 // Reinit texture with green.
5099 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
5100 GL_UNSIGNED_BYTE, nullptr);
5101
5102 drawQuad(mProgram, "position", 0.5f);
5103
5104 ASSERT_GL_NO_ERROR();
5105 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
5106}
5107
Geoff Langfb7685f2017-11-13 11:44:11 -05005108// Ensure that texture parameters passed as floats that are converted to ints are rounded before
5109// validating they are less than 0.
5110TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
5111{
5112 GLTexture texture;
5113 glBindTexture(GL_TEXTURE_2D, texture);
5114
5115 // Use a negative number that will round to zero when converted to an integer
5116 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
5117 // "Validation of values performed by state-setting commands is performed after conversion,
5118 // unless specified otherwise for a specific command."
5119 GLfloat param = -7.30157126e-07f;
5120 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
5121 EXPECT_GL_NO_ERROR();
5122
5123 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
5124 EXPECT_GL_NO_ERROR();
5125}
5126
Jamie Madillf097e232016-11-05 00:44:15 -04005127// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
5128// being properly checked, and the texture storage of the previous texture format was persisting.
5129// This would result in an ASSERT in debug and incorrect rendering in release.
5130// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
5131TEST_P(Texture3DTestES3, FormatRedefinitionBug)
5132{
5133 GLTexture tex;
5134 glBindTexture(GL_TEXTURE_3D, tex.get());
5135 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
5136
5137 GLFramebuffer framebuffer;
5138 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
5139 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
5140
5141 glCheckFramebufferStatus(GL_FRAMEBUFFER);
5142
5143 std::vector<uint8_t> pixelData(100, 0);
5144
5145 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
5146 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
5147 pixelData.data());
5148
5149 ASSERT_GL_NO_ERROR();
5150}
5151
Corentin Wallezd2627992017-04-28 17:17:03 -04005152// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
5153TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
5154{
5155 // 2D tests
5156 {
5157 GLTexture tex;
5158 glBindTexture(GL_TEXTURE_2D, tex.get());
5159
5160 GLBuffer pbo;
5161 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
5162
5163 // Test OOB
5164 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
5165 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
5166 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
5167
5168 // Test OOB
5169 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
5170 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
5171 ASSERT_GL_NO_ERROR();
5172 }
5173
5174 // 3D tests
5175 {
5176 GLTexture tex;
5177 glBindTexture(GL_TEXTURE_3D, tex.get());
5178
5179 GLBuffer pbo;
5180 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
5181
5182 // Test OOB
5183 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
5184 GL_STATIC_DRAW);
5185 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
5186 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
5187
5188 // Test OOB
5189 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
5190 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
5191 ASSERT_GL_NO_ERROR();
5192 }
5193}
5194
Jamie Madill3ed60422017-09-07 11:32:52 -04005195// Tests behaviour with a single texture and multiple sampler objects.
5196TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
5197{
5198 GLint maxTextureUnits = 0;
5199 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
5200 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
5201
5202 constexpr int kSize = 16;
5203
5204 // Make a single-level texture, fill it with red.
5205 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
5206 GLTexture tex;
5207 glBindTexture(GL_TEXTURE_2D, tex);
5208 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
5209 redColors.data());
5210 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5211 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5212
5213 // Simple sanity check.
5214 draw2DTexturedQuad(0.5f, 1.0f, true);
5215 ASSERT_GL_NO_ERROR();
5216 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
5217
5218 // Bind texture to unit 1 with a sampler object making it incomplete.
5219 GLSampler sampler;
5220 glBindSampler(0, sampler);
5221 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
5222 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5223
5224 // Make a mipmap texture, fill it with blue.
5225 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
5226 GLTexture mipmapTex;
5227 glBindTexture(GL_TEXTURE_2D, mipmapTex);
5228 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
5229 blueColors.data());
5230 glGenerateMipmap(GL_TEXTURE_2D);
5231
5232 // Draw with the sampler, expect blue.
5233 draw2DTexturedQuad(0.5f, 1.0f, true);
5234 ASSERT_GL_NO_ERROR();
5235 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
5236
5237 // Simple multitexturing program.
Jamie Madill35cd7332018-12-02 12:03:33 -05005238 constexpr char kVS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04005239 "#version 300 es\n"
5240 "in vec2 position;\n"
5241 "out vec2 texCoord;\n"
5242 "void main()\n"
5243 "{\n"
5244 " gl_Position = vec4(position, 0, 1);\n"
5245 " texCoord = position * 0.5 + vec2(0.5);\n"
5246 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05005247
5248 constexpr char kFS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04005249 "#version 300 es\n"
5250 "precision mediump float;\n"
5251 "in vec2 texCoord;\n"
5252 "uniform sampler2D tex1;\n"
5253 "uniform sampler2D tex2;\n"
5254 "uniform sampler2D tex3;\n"
5255 "uniform sampler2D tex4;\n"
5256 "out vec4 color;\n"
5257 "void main()\n"
5258 "{\n"
5259 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
5260 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
5261 "}";
5262
Jamie Madill35cd7332018-12-02 12:03:33 -05005263 ANGLE_GL_PROGRAM(program, kVS, kFS);
Jamie Madill3ed60422017-09-07 11:32:52 -04005264
5265 std::array<GLint, 4> texLocations = {
5266 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
5267 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
5268 for (GLint location : texLocations)
5269 {
5270 ASSERT_NE(-1, location);
5271 }
5272
5273 // Init the uniform data.
5274 glUseProgram(program);
5275 for (GLint location = 0; location < 4; ++location)
5276 {
5277 glUniform1i(texLocations[location], location);
5278 }
5279
5280 // Initialize four samplers
5281 GLSampler samplers[4];
5282
5283 // 0: non-mipped.
5284 glBindSampler(0, samplers[0]);
5285 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5286 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5287
5288 // 1: mipped.
5289 glBindSampler(1, samplers[1]);
5290 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
5291 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5292
5293 // 2: non-mipped.
5294 glBindSampler(2, samplers[2]);
5295 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5296 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5297
5298 // 3: mipped.
5299 glBindSampler(3, samplers[3]);
5300 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
5301 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5302
5303 // Bind two blue mipped textures and two single layer textures, should all draw.
5304 glActiveTexture(GL_TEXTURE0);
5305 glBindTexture(GL_TEXTURE_2D, tex);
5306
5307 glActiveTexture(GL_TEXTURE1);
5308 glBindTexture(GL_TEXTURE_2D, mipmapTex);
5309
5310 glActiveTexture(GL_TEXTURE2);
5311 glBindTexture(GL_TEXTURE_2D, tex);
5312
5313 glActiveTexture(GL_TEXTURE3);
5314 glBindTexture(GL_TEXTURE_2D, mipmapTex);
5315
5316 ASSERT_GL_NO_ERROR();
5317
5318 drawQuad(program, "position", 0.5f);
5319 ASSERT_GL_NO_ERROR();
5320 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
5321
5322 // Bind four single layer textures, two should be incomplete.
5323 glActiveTexture(GL_TEXTURE1);
5324 glBindTexture(GL_TEXTURE_2D, tex);
5325
5326 glActiveTexture(GL_TEXTURE3);
5327 glBindTexture(GL_TEXTURE_2D, tex);
5328
5329 drawQuad(program, "position", 0.5f);
5330 ASSERT_GL_NO_ERROR();
5331 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
5332}
5333
Martin Radev7e2c0d32017-09-15 14:25:42 +03005334// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
5335// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
5336// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
5337// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
5338// samples the cubemap using a direction vector (1,1,1).
5339TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
5340{
Yunchao He2f23f352018-02-11 22:11:37 +08005341 // Check http://anglebug.com/2155.
5342 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
5343
Jamie Madill35cd7332018-12-02 12:03:33 -05005344 constexpr char kVS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03005345 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03005346 precision mediump float;
5347 in vec3 pos;
5348 void main() {
5349 gl_Position = vec4(pos, 1.0);
5350 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03005351
Jamie Madill35cd7332018-12-02 12:03:33 -05005352 constexpr char kFS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03005353 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03005354 precision mediump float;
5355 out vec4 color;
5356 uniform samplerCube uTex;
5357 void main(){
5358 color = texture(uTex, vec3(1.0));
5359 })";
Jamie Madill35cd7332018-12-02 12:03:33 -05005360
5361 ANGLE_GL_PROGRAM(program, kVS, kFS);
Martin Radev7e2c0d32017-09-15 14:25:42 +03005362 glUseProgram(program);
5363
5364 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
5365 glActiveTexture(GL_TEXTURE0);
5366
5367 GLTexture cubeTex;
5368 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
5369
5370 const int kFaceWidth = 1;
5371 const int kFaceHeight = 1;
5372 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
5373 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
5374 GL_UNSIGNED_BYTE, texData.data());
5375 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
5376 GL_UNSIGNED_BYTE, texData.data());
5377 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
5378 GL_UNSIGNED_BYTE, texData.data());
5379 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
5380 GL_UNSIGNED_BYTE, texData.data());
5381 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
5382 GL_UNSIGNED_BYTE, texData.data());
5383 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
5384 GL_UNSIGNED_BYTE, texData.data());
5385 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5386 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5387 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
5388 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
5389 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
5390 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
5391
5392 drawQuad(program, "pos", 0.5f, 1.0f, true);
5393 ASSERT_GL_NO_ERROR();
5394
5395 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
5396}
5397
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08005398// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
5399TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
5400{
5401 GLuint texture = create2DTexture();
5402
5403 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
5404 EXPECT_GL_ERROR(GL_INVALID_VALUE);
5405
5406 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
5407 EXPECT_GL_ERROR(GL_INVALID_VALUE);
5408
5409 glDeleteTextures(1, &texture);
5410 EXPECT_GL_NO_ERROR();
5411}
5412
Olli Etuaho023371b2018-04-24 17:43:32 +03005413// Test setting base level after calling generateMipmap on a LUMA texture.
5414// Covers http://anglebug.com/2498
5415TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA)
5416{
5417 glActiveTexture(GL_TEXTURE0);
5418 glBindTexture(GL_TEXTURE_2D, mTexture2D);
5419
5420 constexpr const GLsizei kWidth = 8;
5421 constexpr const GLsizei kHeight = 8;
5422 std::array<GLubyte, kWidth * kHeight * 2> whiteData;
5423 whiteData.fill(255u);
5424
5425 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA,
5426 GL_UNSIGNED_BYTE, whiteData.data());
5427 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
5428 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
5429 glGenerateMipmap(GL_TEXTURE_2D);
5430 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
5431 EXPECT_GL_NO_ERROR();
5432
5433 drawQuad(mProgram, "position", 0.5f);
5434 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
5435}
5436
Till Rathmannc1551dc2018-08-15 17:04:49 +02005437// Covers a bug in the D3D11 backend: http://anglebug.com/2772
5438// When using a sampler the texture was created as if it has mipmaps,
5439// regardless what you specified in GL_TEXTURE_MIN_FILTER via
5440// glSamplerParameteri() -- mistakenly the default value
5441// GL_NEAREST_MIPMAP_LINEAR or the value set via glTexParameteri() was
5442// evaluated.
5443// If you didn't provide mipmaps and didn't let the driver generate them
5444// this led to not sampling your texture data when minification occurred.
5445TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping)
5446{
Cody Northrop988f7172019-09-30 15:52:37 -06005447 // TODO: Triage this failure on Vulkan: http://anglebug.com/3950
Cody Northropcb16fb52019-08-29 16:53:55 -06005448 ANGLE_SKIP_TEST_IF(IsVulkan());
5449
Jamie Madill35cd7332018-12-02 12:03:33 -05005450 constexpr char kVS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02005451 "#version 300 es\n"
5452 "out vec2 texcoord;\n"
5453 "in vec4 position;\n"
5454 "void main()\n"
5455 "{\n"
5456 " gl_Position = vec4(position.xy * 0.1, 0.0, 1.0);\n"
5457 " texcoord = (position.xy * 0.5) + 0.5;\n"
5458 "}\n";
5459
Jamie Madill35cd7332018-12-02 12:03:33 -05005460 constexpr char kFS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02005461 "#version 300 es\n"
5462 "precision highp float;\n"
5463 "uniform highp sampler2D tex;\n"
5464 "in vec2 texcoord;\n"
5465 "out vec4 fragColor;\n"
5466 "void main()\n"
5467 "{\n"
5468 " fragColor = texture(tex, texcoord);\n"
5469 "}\n";
Jamie Madill35cd7332018-12-02 12:03:33 -05005470
5471 ANGLE_GL_PROGRAM(program, kVS, kFS);
Till Rathmannc1551dc2018-08-15 17:04:49 +02005472
5473 GLSampler sampler;
5474 glBindSampler(0, sampler);
5475 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
5476 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
5477
5478 glActiveTexture(GL_TEXTURE0);
5479 glBindTexture(GL_TEXTURE_2D, mTexture2D);
5480
5481 const GLsizei texWidth = getWindowWidth();
5482 const GLsizei texHeight = getWindowHeight();
5483 const std::vector<GLColor> whiteData(texWidth * texHeight, GLColor::white);
5484
5485 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
5486 whiteData.data());
5487 EXPECT_GL_NO_ERROR();
5488
5489 drawQuad(program, "position", 0.5f);
5490 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, angle::GLColor::white);
5491}
5492
Anders Leinof6cbe442019-04-18 15:32:07 +03005493// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
5494// texture is output.
5495TEST_P(Texture2DIntegerTestES3, IntegerTextureNonZeroBaseLevel)
5496{
Yuly Novikovd2683452019-05-23 16:11:19 -04005497 // http://anglebug.com/3478
5498 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsDesktopOpenGL());
5499
Anders Leinof6cbe442019-04-18 15:32:07 +03005500 glActiveTexture(GL_TEXTURE0);
5501 glBindTexture(GL_TEXTURE_2D, mTexture2D);
5502 int width = getWindowWidth();
5503 int height = getWindowHeight();
5504 GLColor color = GLColor::green;
5505 std::vector<GLColor> pixels(width * height, color);
5506 GLint baseLevel = 1;
5507 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
5508 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5509 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5510 glTexImage2D(GL_TEXTURE_2D, baseLevel, GL_RGBA8UI, width, height, 0, GL_RGBA_INTEGER,
5511 GL_UNSIGNED_BYTE, pixels.data());
5512
5513 setUpProgram();
5514 glUseProgram(mProgram);
5515 glUniform1i(mTexture2DUniformLocation, 0);
5516 drawQuad(mProgram, "position", 0.5f);
5517
5518 EXPECT_GL_NO_ERROR();
5519 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
5520 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
5521}
5522
Anders Leino60cc7512019-05-06 09:25:27 +03005523// Draw a quad with an integer cube texture with a non-zero base level, and test that the color of
5524// the texture is output.
5525TEST_P(TextureCubeIntegerTestES3, IntegerCubeTextureNonZeroBaseLevel)
5526{
5527 // All output checks returned black, rather than the texture color.
5528 ANGLE_SKIP_TEST_IF(IsOSX() && IsOpenGL());
5529
5530 glActiveTexture(GL_TEXTURE0);
5531
5532 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
5533 GLint baseLevel = 1;
5534 int width = getWindowWidth();
5535 int height = getWindowHeight();
5536 GLColor color = GLColor::green;
5537 std::vector<GLColor> pixels(width * height, color);
5538 for (GLenum faceIndex = 0; faceIndex < 6; faceIndex++)
5539 {
5540 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, baseLevel, GL_RGBA8UI, width,
5541 height, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
5542 EXPECT_GL_NO_ERROR();
5543 }
5544 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, baseLevel);
5545 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5546 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5547
5548 glUseProgram(mProgram);
5549 glUniform1i(mTextureCubeUniformLocation, 0);
5550 drawQuad(mProgram, "position", 0.5f);
5551
5552 EXPECT_GL_NO_ERROR();
5553 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
5554 EXPECT_PIXEL_COLOR_EQ(width - 1, 0, color);
5555 EXPECT_PIXEL_COLOR_EQ(0, height - 1, color);
5556 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
5557}
5558
Anders Leinoe4452442019-05-09 13:29:49 +03005559// This test sets up a cube map with four distincly colored MIP levels.
5560// The size of the texture and the geometry is chosen such that levels 1 or 2 should be chosen at
5561// the corners of the screen.
5562TEST_P(TextureCubeIntegerEdgeTestES3, IntegerCubeTextureCorner)
5563{
5564 glActiveTexture(GL_TEXTURE0);
5565
5566 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
5567 int width = getWindowWidth();
5568 int height = getWindowHeight();
5569 ASSERT_EQ(width, height);
5570 GLColor color[4] = {GLColor::white, GLColor::green, GLColor::blue, GLColor::red};
5571 for (GLint level = 0; level < 4; level++)
5572 {
5573 for (GLenum faceIndex = 0; faceIndex < 6; faceIndex++)
5574 {
5575 int levelWidth = (2 * width) >> level;
5576 int levelHeight = (2 * height) >> level;
5577 std::vector<GLColor> pixels(levelWidth * levelHeight, color[level]);
5578 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, level, GL_RGBA8UI, levelWidth,
5579 levelHeight, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
5580 EXPECT_GL_NO_ERROR();
5581 }
5582 }
5583 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
5584 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5585 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 3);
5586
5587 glUseProgram(mProgram);
5588 glUniform1i(mTextureCubeUniformLocation, 0);
5589 drawQuad(mProgram, "position", 0.5f);
5590
5591 ASSERT_GL_NO_ERROR();
5592 // Check that we do not read from levels 0 or 3. Levels 1 and 2 are both acceptable.
5593 EXPECT_EQ(ReadColor(0, 0).R, 0);
5594 EXPECT_EQ(ReadColor(width - 1, 0).R, 0);
5595 EXPECT_EQ(ReadColor(0, height - 1).R, 0);
5596 EXPECT_EQ(ReadColor(width - 1, height - 1).R, 0);
5597}
5598
Anders Leino1b6aded2019-05-20 12:56:34 +03005599// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
5600// texture is output.
5601TEST_P(Texture2DIntegerProjectiveOffsetTestES3, NonZeroBaseLevel)
5602{
Jamie Madill29ac2742019-05-28 15:53:00 -04005603 // Fails on AMD: http://crbug.com/967796
Jamie Madill06055b52019-05-29 14:31:42 -04005604 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsOpenGL());
Jamie Madill29ac2742019-05-28 15:53:00 -04005605
Anders Leino1b6aded2019-05-20 12:56:34 +03005606 glActiveTexture(GL_TEXTURE0);
5607 glBindTexture(GL_TEXTURE_2D, mTexture2D);
5608 int width = getWindowWidth();
5609 int height = getWindowHeight();
5610 GLColor color = GLColor::green;
5611 std::vector<GLColor> pixels(width * height, color);
5612 GLint baseLevel = 1;
5613 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
5614 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5615 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5616 glTexImage2D(GL_TEXTURE_2D, baseLevel, GL_RGBA8UI, width, height, 0, GL_RGBA_INTEGER,
5617 GL_UNSIGNED_BYTE, pixels.data());
5618
5619 setUpProgram();
5620 glUseProgram(mProgram);
5621 glUniform1i(mTexture2DUniformLocation, 0);
5622 drawQuad(mProgram, "position", 0.5f);
5623
5624 EXPECT_GL_NO_ERROR();
5625 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
5626 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
5627}
5628
Anders Leino69d04932019-05-20 14:04:13 +03005629// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
5630// texture is output.
5631TEST_P(Texture2DArrayIntegerTestES3, NonZeroBaseLevel)
5632{
5633 glActiveTexture(GL_TEXTURE0);
5634 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
5635 int width = getWindowWidth();
5636 int height = getWindowHeight();
5637 int depth = 2;
5638 GLColor color = GLColor::green;
5639 std::vector<GLColor> pixels(width * height * depth, color);
5640 GLint baseLevel = 1;
5641 glTexImage3D(GL_TEXTURE_2D_ARRAY, baseLevel, GL_RGBA8UI, width, height, depth, 0,
5642 GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
5643 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, baseLevel);
5644 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5645 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5646
5647 drawQuad(mProgram, "position", 0.5f);
5648
5649 EXPECT_GL_NO_ERROR();
5650 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
5651 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
5652}
5653
Anders Leino262e2822019-05-20 14:24:40 +03005654// Draw a quad with an integer 3D texture with a non-zero base level, and test that the color of the
5655// texture is output.
5656TEST_P(Texture3DIntegerTestES3, NonZeroBaseLevel)
5657{
5658 glActiveTexture(GL_TEXTURE0);
5659 glBindTexture(GL_TEXTURE_3D, mTexture3D);
5660 int width = getWindowWidth();
5661 int height = getWindowHeight();
5662 int depth = 2;
5663 GLColor color = GLColor::green;
5664 std::vector<GLColor> pixels(width * height * depth, color);
5665 GLint baseLevel = 1;
5666 glTexImage3D(GL_TEXTURE_3D, baseLevel, GL_RGBA8UI, width, height, depth, 0, GL_RGBA_INTEGER,
5667 GL_UNSIGNED_BYTE, pixels.data());
5668 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, baseLevel);
5669 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5670 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5671
5672 drawQuad(mProgram, "position", 0.5f);
5673
5674 EXPECT_GL_NO_ERROR();
5675 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
5676 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
5677}
5678
Jamie Madill50cf2be2018-06-15 09:46:57 -04005679// Use this to select which configurations (e.g. which renderer, which GLES major version) these
5680// tests should be run against.
Tobin Ehlis1a01b4b2019-11-11 16:41:07 -07005681ANGLE_INSTANTIATE_TEST_ES2(Texture2DTest);
5682ANGLE_INSTANTIATE_TEST_ES2(TextureCubeTest);
5683ANGLE_INSTANTIATE_TEST_ES2(Texture2DTestWithDrawScale);
5684ANGLE_INSTANTIATE_TEST_ES2(Sampler2DAsFunctionParameterTest);
5685ANGLE_INSTANTIATE_TEST_ES2(SamplerArrayTest);
5686ANGLE_INSTANTIATE_TEST_ES2(SamplerArrayAsFunctionParameterTest);
5687ANGLE_INSTANTIATE_TEST_ES3(Texture2DTestES3);
5688ANGLE_INSTANTIATE_TEST_ES3(Texture3DTestES3);
5689ANGLE_INSTANTIATE_TEST_ES3(Texture2DIntegerAlpha1TestES3);
5690ANGLE_INSTANTIATE_TEST_ES3(Texture2DUnsignedIntegerAlpha1TestES3);
5691ANGLE_INSTANTIATE_TEST_ES3(ShadowSamplerPlusSampler3DTestES3);
5692ANGLE_INSTANTIATE_TEST_ES3(SamplerTypeMixTestES3);
5693ANGLE_INSTANTIATE_TEST_ES3(Texture2DArrayTestES3);
5694ANGLE_INSTANTIATE_TEST_ES3(TextureSizeTextureArrayTest);
5695ANGLE_INSTANTIATE_TEST_ES2(SamplerInStructTest);
5696ANGLE_INSTANTIATE_TEST_ES2(SamplerInStructAsFunctionParameterTest);
5697ANGLE_INSTANTIATE_TEST_ES2(SamplerInStructArrayAsFunctionParameterTest);
5698ANGLE_INSTANTIATE_TEST_ES2(SamplerInNestedStructAsFunctionParameterTest);
5699ANGLE_INSTANTIATE_TEST_ES2(SamplerInStructAndOtherVariableTest);
5700ANGLE_INSTANTIATE_TEST_ES2(TextureAnisotropyTest);
5701ANGLE_INSTANTIATE_TEST_ES2(TextureBorderClampTest);
5702ANGLE_INSTANTIATE_TEST_ES3(TextureBorderClampTestES3);
5703ANGLE_INSTANTIATE_TEST_ES3(TextureBorderClampIntegerTestES3);
5704ANGLE_INSTANTIATE_TEST_ES2(TextureLimitsTest);
5705ANGLE_INSTANTIATE_TEST_ES3(Texture2DNorm16TestES3);
5706ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(Texture2DRGTest);
5707ANGLE_INSTANTIATE_TEST_ES3(Texture2DFloatTestES3);
5708ANGLE_INSTANTIATE_TEST_ES2(Texture2DFloatTestES2);
5709ANGLE_INSTANTIATE_TEST_ES3(TextureCubeTestES3);
5710ANGLE_INSTANTIATE_TEST_ES3(Texture2DIntegerTestES3);
5711ANGLE_INSTANTIATE_TEST_ES3(TextureCubeIntegerTestES3);
5712ANGLE_INSTANTIATE_TEST_ES3(TextureCubeIntegerEdgeTestES3);
5713ANGLE_INSTANTIATE_TEST_ES3(Texture2DIntegerProjectiveOffsetTestES3);
5714ANGLE_INSTANTIATE_TEST_ES3(Texture2DArrayIntegerTestES3);
5715ANGLE_INSTANTIATE_TEST_ES3(Texture3DIntegerTestES3);
5716ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(Texture2DDepthTest);
Jamie Madillfa05f602015-05-07 13:47:11 -04005717
Jamie Madill7ffdda92016-09-08 13:26:51 -04005718} // anonymous namespace