blob: 9de0ea0615dd851327b67b24924d8163c2fa4272 [file] [log] [blame]
Jamie Madillfa05f602015-05-07 13:47:11 -04001//
2// Copyright 2015 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Jamie Madill14718762016-09-06 15:56:54 -04007#include "common/mathutil.h"
Corentin Wallezd3970de2015-05-14 11:07:48 -04008#include "test_utils/ANGLETest.h"
Olli Etuaho989cac32016-06-08 16:18:49 -07009#include "test_utils/gl_raii.h"
Jamie Madillf67115c2014-04-22 13:14:05 -040010
Jamie Madillfa05f602015-05-07 13:47:11 -040011using namespace angle;
Austin Kinross18b931d2014-09-29 12:58:31 -070012
Jamie Madillfa05f602015-05-07 13:47:11 -040013namespace
14{
15
Vincent Lang25ab4512016-05-13 18:13:59 +020016// Take a pixel, and reset the components not covered by the format to default
Geoff Langf607c602016-09-21 11:46:48 -040017// values. In particular, the default value for the alpha component is 255
Vincent Lang25ab4512016-05-13 18:13:59 +020018// (1.0 as unsigned normalized fixed point value).
Geoff Langf607c602016-09-21 11:46:48 -040019GLColor SliceFormatColor(GLenum format, GLColor full)
Vincent Lang25ab4512016-05-13 18:13:59 +020020{
21 switch (format)
22 {
23 case GL_RED:
Geoff Langf607c602016-09-21 11:46:48 -040024 return GLColor(full.R, 0, 0, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020025 case GL_RG:
Geoff Langf607c602016-09-21 11:46:48 -040026 return GLColor(full.R, full.G, 0, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020027 case GL_RGB:
Geoff Langf607c602016-09-21 11:46:48 -040028 return GLColor(full.R, full.G, full.B, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020029 case GL_RGBA:
30 return full;
31 default:
Jamie Madille1faacb2016-12-13 12:42:14 -050032 EXPECT_TRUE(false);
Geoff Langf607c602016-09-21 11:46:48 -040033 return GLColor::white;
Vincent Lang25ab4512016-05-13 18:13:59 +020034 }
Vincent Lang25ab4512016-05-13 18:13:59 +020035}
36
Olli Etuaho4a8329f2016-01-11 17:12:57 +020037class TexCoordDrawTest : public ANGLETest
Jamie Madillf67115c2014-04-22 13:14:05 -040038{
Jamie Madillbc393df2015-01-29 13:46:07 -050039 protected:
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020040 TexCoordDrawTest() : ANGLETest(), mProgram(0), mFramebuffer(0), mFramebufferColorTexture(0)
Jamie Madillf67115c2014-04-22 13:14:05 -040041 {
42 setWindowWidth(128);
43 setWindowHeight(128);
44 setConfigRedBits(8);
45 setConfigGreenBits(8);
46 setConfigBlueBits(8);
47 setConfigAlphaBits(8);
48 }
49
Jamie Madill35cd7332018-12-02 12:03:33 -050050 virtual const char *getVertexShaderSource()
Jamie Madillf67115c2014-04-22 13:14:05 -040051 {
Jamie Madill35cd7332018-12-02 12:03:33 -050052 return R"(precision highp float;
53attribute vec4 position;
54varying vec2 texcoord;
Geoff Langc41e42d2014-04-28 10:58:16 -040055
Jamie Madill35cd7332018-12-02 12:03:33 -050056void main()
57{
58 gl_Position = vec4(position.xy, 0.0, 1.0);
59 texcoord = (position.xy * 0.5) + 0.5;
60})";
Olli Etuaho4a8329f2016-01-11 17:12:57 +020061 }
Geoff Langc41e42d2014-04-28 10:58:16 -040062
Jamie Madill35cd7332018-12-02 12:03:33 -050063 virtual const char *getFragmentShaderSource() = 0;
Olli Etuaho4a8329f2016-01-11 17:12:57 +020064
Olli Etuahoa1c917f2016-04-06 13:50:03 +030065 virtual void setUpProgram()
Olli Etuaho4a8329f2016-01-11 17:12:57 +020066 {
Jamie Madill35cd7332018-12-02 12:03:33 -050067 const char *vertexShaderSource = getVertexShaderSource();
68 const char *fragmentShaderSource = getFragmentShaderSource();
Olli Etuaho4a8329f2016-01-11 17:12:57 +020069
70 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
71 ASSERT_NE(0u, mProgram);
72 ASSERT_GL_NO_ERROR();
Olli Etuahoa1c917f2016-04-06 13:50:03 +030073 }
74
Jamie Madill5cbaa3f2019-05-07 15:49:22 -040075 void testSetUp() override { setUpFramebuffer(); }
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020076
Jamie Madill5cbaa3f2019-05-07 15:49:22 -040077 void testTearDown() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +020078 {
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020079 glBindFramebuffer(GL_FRAMEBUFFER, 0);
80 glDeleteFramebuffers(1, &mFramebuffer);
81 glDeleteTextures(1, &mFramebufferColorTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +020082 glDeleteProgram(mProgram);
Olli Etuaho4a8329f2016-01-11 17:12:57 +020083 }
84
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020085 void setUpFramebuffer()
86 {
87 // We use an FBO to work around an issue where the default framebuffer applies SRGB
88 // conversion (particularly known to happen incorrectly on Intel GL drivers). It's not
89 // clear whether this issue can even be fixed on all backends. For example GLES 3.0.4 spec
90 // section 4.4 says that the format of the default framebuffer is entirely up to the window
91 // system, so it might be SRGB, and GLES 3.0 doesn't have a "FRAMEBUFFER_SRGB" to turn off
92 // SRGB conversion like desktop GL does.
93 // TODO(oetuaho): Get rid of this if the underlying issue is fixed.
94 glGenFramebuffers(1, &mFramebuffer);
95 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
96
97 glGenTextures(1, &mFramebufferColorTexture);
98 glBindTexture(GL_TEXTURE_2D, mFramebufferColorTexture);
99 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
100 GL_UNSIGNED_BYTE, nullptr);
101 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
102 mFramebufferColorTexture, 0);
103 ASSERT_GL_NO_ERROR();
104 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
105 glBindTexture(GL_TEXTURE_2D, 0);
106 }
107
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200108 // Returns the created texture ID.
109 GLuint create2DTexture()
110 {
111 GLuint texture2D;
112 glGenTextures(1, &texture2D);
113 glBindTexture(GL_TEXTURE_2D, texture2D);
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800114 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200115 EXPECT_GL_NO_ERROR();
116 return texture2D;
117 }
118
119 GLuint mProgram;
Olli Etuaho51f1c0f2016-01-13 16:16:24 +0200120 GLuint mFramebuffer;
121
122 private:
123 GLuint mFramebufferColorTexture;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200124};
125
126class Texture2DTest : public TexCoordDrawTest
127{
128 protected:
129 Texture2DTest() : TexCoordDrawTest(), mTexture2D(0), mTexture2DUniformLocation(-1) {}
130
Jamie Madill35cd7332018-12-02 12:03:33 -0500131 const char *getFragmentShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200132 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500133 return R"(precision highp float;
134uniform sampler2D tex;
135varying vec2 texcoord;
Geoff Langc41e42d2014-04-28 10:58:16 -0400136
Jamie Madill35cd7332018-12-02 12:03:33 -0500137void main()
138{
139 gl_FragColor = texture2D(tex, texcoord);
140})";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200141 }
Geoff Langc41e42d2014-04-28 10:58:16 -0400142
Olli Etuaho96963162016-03-21 11:54:33 +0200143 virtual const char *getTextureUniformName() { return "tex"; }
144
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300145 void setUpProgram() override
146 {
147 TexCoordDrawTest::setUpProgram();
148 mTexture2DUniformLocation = glGetUniformLocation(mProgram, getTextureUniformName());
149 ASSERT_NE(-1, mTexture2DUniformLocation);
150 }
151
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400152 void testSetUp() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200153 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400154 TexCoordDrawTest::testSetUp();
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200155 mTexture2D = create2DTexture();
Jamie Madilld4cfa572014-07-08 10:00:32 -0400156
Jamie Madill9aca0592014-10-06 16:26:59 -0400157 ASSERT_GL_NO_ERROR();
Jamie Madillf67115c2014-04-22 13:14:05 -0400158 }
159
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400160 void testTearDown() override
Jamie Madillf67115c2014-04-22 13:14:05 -0400161 {
Jamie Madilld4cfa572014-07-08 10:00:32 -0400162 glDeleteTextures(1, &mTexture2D);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400163 TexCoordDrawTest::testTearDown();
Jamie Madillf67115c2014-04-22 13:14:05 -0400164 }
165
Jamie Madillbc393df2015-01-29 13:46:07 -0500166 // Tests CopyTexSubImage with floating point textures of various formats.
167 void testFloatCopySubImage(int sourceImageChannels, int destImageChannels)
168 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300169 setUpProgram();
170
Martin Radev1be913c2016-07-11 17:59:16 +0300171 if (getClientMajorVersion() < 3)
Geoff Langfbfa47c2015-03-31 11:26:00 -0400172 {
Jamie Madillb8149072019-04-30 16:14:44 -0400173 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_storage") ||
174 !IsGLExtensionEnabled("GL_OES_texture_float"));
Geoff Langc4e93662017-05-01 10:45:59 -0400175
Yunchao He9550c602018-02-13 14:47:05 +0800176 ANGLE_SKIP_TEST_IF((sourceImageChannels < 3 || destImageChannels < 3) &&
Jamie Madillb8149072019-04-30 16:14:44 -0400177 !IsGLExtensionEnabled("GL_EXT_texture_rg"));
Geoff Langfbfa47c2015-03-31 11:26:00 -0400178
Yunchao He9550c602018-02-13 14:47:05 +0800179 ANGLE_SKIP_TEST_IF(destImageChannels == 3 &&
Jamie Madillb8149072019-04-30 16:14:44 -0400180 !IsGLExtensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400181
Yunchao He9550c602018-02-13 14:47:05 +0800182 ANGLE_SKIP_TEST_IF(destImageChannels == 4 &&
Jamie Madillb8149072019-04-30 16:14:44 -0400183 !IsGLExtensionEnabled("GL_CHROMIUM_color_buffer_float_rgba"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400184
Yunchao He9550c602018-02-13 14:47:05 +0800185 ANGLE_SKIP_TEST_IF(destImageChannels <= 2);
Geoff Lang677bb6f2017-04-05 12:40:40 -0400186 }
187 else
188 {
Jamie Madillb8149072019-04-30 16:14:44 -0400189 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_color_buffer_float"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400190
Yunchao He9550c602018-02-13 14:47:05 +0800191 ANGLE_SKIP_TEST_IF(destImageChannels == 3 &&
Jamie Madillb8149072019-04-30 16:14:44 -0400192 !IsGLExtensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"));
Geoff Langfbfa47c2015-03-31 11:26:00 -0400193 }
194
Jamie Madill50cf2be2018-06-15 09:46:57 -0400195 // clang-format off
Jamie Madillbc393df2015-01-29 13:46:07 -0500196 GLfloat sourceImageData[4][16] =
197 {
198 { // R
199 1.0f,
200 0.0f,
201 0.0f,
202 1.0f
203 },
204 { // RG
205 1.0f, 0.0f,
206 0.0f, 1.0f,
207 0.0f, 0.0f,
208 1.0f, 1.0f
209 },
210 { // RGB
211 1.0f, 0.0f, 0.0f,
212 0.0f, 1.0f, 0.0f,
213 0.0f, 0.0f, 1.0f,
214 1.0f, 1.0f, 0.0f
215 },
216 { // RGBA
217 1.0f, 0.0f, 0.0f, 1.0f,
218 0.0f, 1.0f, 0.0f, 1.0f,
219 0.0f, 0.0f, 1.0f, 1.0f,
220 1.0f, 1.0f, 0.0f, 1.0f
221 },
222 };
Jamie Madill50cf2be2018-06-15 09:46:57 -0400223 // clang-format on
Jamie Madillbc393df2015-01-29 13:46:07 -0500224
Jamie Madill50cf2be2018-06-15 09:46:57 -0400225 GLenum imageFormats[] = {
Jamie Madillb980c562018-11-27 11:34:27 -0500226 GL_R32F,
227 GL_RG32F,
228 GL_RGB32F,
229 GL_RGBA32F,
Jamie Madillbc393df2015-01-29 13:46:07 -0500230 };
231
Jamie Madill50cf2be2018-06-15 09:46:57 -0400232 GLenum sourceUnsizedFormats[] = {
Jamie Madillb980c562018-11-27 11:34:27 -0500233 GL_RED,
234 GL_RG,
235 GL_RGB,
236 GL_RGBA,
Jamie Madillbc393df2015-01-29 13:46:07 -0500237 };
238
239 GLuint textures[2];
240
241 glGenTextures(2, textures);
242
Jamie Madill50cf2be2018-06-15 09:46:57 -0400243 GLfloat *imageData = sourceImageData[sourceImageChannels - 1];
244 GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1];
Jamie Madillbc393df2015-01-29 13:46:07 -0500245 GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1];
Jamie Madill50cf2be2018-06-15 09:46:57 -0400246 GLenum destImageFormat = imageFormats[destImageChannels - 1];
Jamie Madillbc393df2015-01-29 13:46:07 -0500247
248 glBindTexture(GL_TEXTURE_2D, textures[0]);
Geoff Langc4e93662017-05-01 10:45:59 -0400249 if (getClientMajorVersion() >= 3)
250 {
251 glTexStorage2D(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
252 }
253 else
254 {
255 glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
256 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500257 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
258 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
259 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData);
260
Jamie Madillb8149072019-04-30 16:14:44 -0400261 if (sourceImageChannels < 3 && !IsGLExtensionEnabled("GL_EXT_texture_rg"))
Jamie Madillbc393df2015-01-29 13:46:07 -0500262 {
263 // This is not supported
264 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
265 }
266 else
267 {
268 ASSERT_GL_NO_ERROR();
269 }
270
271 GLuint fbo;
272 glGenFramebuffers(1, &fbo);
273 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
274 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
275
276 glBindTexture(GL_TEXTURE_2D, textures[1]);
Geoff Langc4e93662017-05-01 10:45:59 -0400277 if (getClientMajorVersion() >= 3)
278 {
279 glTexStorage2D(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
280 }
281 else
282 {
283 glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
284 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500285 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
286 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
287
288 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
289 ASSERT_GL_NO_ERROR();
290
291 glBindFramebuffer(GL_FRAMEBUFFER, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200292 drawQuad(mProgram, "position", 0.5f);
Jamie Madillbc393df2015-01-29 13:46:07 -0500293
294 int testImageChannels = std::min(sourceImageChannels, destImageChannels);
295
Olli Etuahoa314b612016-03-10 16:43:00 +0200296 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Jamie Madillbc393df2015-01-29 13:46:07 -0500297 if (testImageChannels > 1)
298 {
299 EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255);
300 EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255);
301 if (testImageChannels > 2)
302 {
303 EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255);
304 }
305 }
306
307 glDeleteFramebuffers(1, &fbo);
308 glDeleteTextures(2, textures);
309
310 ASSERT_GL_NO_ERROR();
311 }
312
Jamie Madilld4cfa572014-07-08 10:00:32 -0400313 GLuint mTexture2D;
Jamie Madilld4cfa572014-07-08 10:00:32 -0400314 GLint mTexture2DUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400315};
316
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200317class Texture2DTestES3 : public Texture2DTest
318{
319 protected:
320 Texture2DTestES3() : Texture2DTest() {}
321
Jamie Madill35cd7332018-12-02 12:03:33 -0500322 const char *getVertexShaderSource() override
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200323 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500324 return "#version 300 es\n"
325 "out vec2 texcoord;\n"
326 "in vec4 position;\n"
327 "void main()\n"
328 "{\n"
329 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
330 " texcoord = (position.xy * 0.5) + 0.5;\n"
331 "}\n";
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200332 }
333
Jamie Madill35cd7332018-12-02 12:03:33 -0500334 const char *getFragmentShaderSource() override
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200335 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500336 return "#version 300 es\n"
337 "precision highp float;\n"
338 "uniform highp sampler2D tex;\n"
339 "in vec2 texcoord;\n"
340 "out vec4 fragColor;\n"
341 "void main()\n"
342 "{\n"
343 " fragColor = texture(tex, texcoord);\n"
344 "}\n";
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200345 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300346
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400347 void testSetUp() override
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300348 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400349 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300350 setUpProgram();
351 }
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200352};
353
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200354class Texture2DIntegerAlpha1TestES3 : public Texture2DTest
355{
356 protected:
357 Texture2DIntegerAlpha1TestES3() : Texture2DTest() {}
358
Jamie Madill35cd7332018-12-02 12:03:33 -0500359 const char *getVertexShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200360 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500361 return "#version 300 es\n"
362 "out vec2 texcoord;\n"
363 "in vec4 position;\n"
364 "void main()\n"
365 "{\n"
366 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
367 " texcoord = (position.xy * 0.5) + 0.5;\n"
368 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200369 }
370
Jamie Madill35cd7332018-12-02 12:03:33 -0500371 const char *getFragmentShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200372 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500373 return "#version 300 es\n"
374 "precision highp float;\n"
375 "uniform highp isampler2D tex;\n"
376 "in vec2 texcoord;\n"
377 "out vec4 fragColor;\n"
378 "void main()\n"
379 "{\n"
380 " vec4 green = vec4(0, 1, 0, 1);\n"
381 " vec4 black = vec4(0, 0, 0, 0);\n"
382 " fragColor = (texture(tex, texcoord).a == 1) ? green : black;\n"
383 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200384 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300385
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400386 void testSetUp() override
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300387 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400388 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300389 setUpProgram();
390 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200391};
392
393class Texture2DUnsignedIntegerAlpha1TestES3 : public Texture2DTest
394{
395 protected:
396 Texture2DUnsignedIntegerAlpha1TestES3() : Texture2DTest() {}
397
Jamie Madill35cd7332018-12-02 12:03:33 -0500398 const char *getVertexShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200399 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500400 return "#version 300 es\n"
401 "out vec2 texcoord;\n"
402 "in vec4 position;\n"
403 "void main()\n"
404 "{\n"
405 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
406 " texcoord = (position.xy * 0.5) + 0.5;\n"
407 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200408 }
409
Jamie Madill35cd7332018-12-02 12:03:33 -0500410 const char *getFragmentShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200411 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500412 return "#version 300 es\n"
413 "precision highp float;\n"
414 "uniform highp usampler2D tex;\n"
415 "in vec2 texcoord;\n"
416 "out vec4 fragColor;\n"
417 "void main()\n"
418 "{\n"
419 " vec4 green = vec4(0, 1, 0, 1);\n"
420 " vec4 black = vec4(0, 0, 0, 0);\n"
421 " fragColor = (texture(tex, texcoord).a == 1u) ? green : black;\n"
422 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200423 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300424
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400425 void testSetUp() override
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300426 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400427 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300428 setUpProgram();
429 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200430};
431
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200432class Texture2DTestWithDrawScale : public Texture2DTest
Jamie Madill2453dbc2015-07-14 11:35:42 -0400433{
434 protected:
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200435 Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {}
436
Jamie Madill35cd7332018-12-02 12:03:33 -0500437 const char *getVertexShaderSource() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400438 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300439 return
440 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200441 attribute vec4 position;
442 varying vec2 texcoord;
443
444 uniform vec2 drawScale;
445
446 void main()
447 {
448 gl_Position = vec4(position.xy * drawScale, 0.0, 1.0);
449 texcoord = (position.xy * 0.5) + 0.5;
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300450 })";
Jamie Madill2453dbc2015-07-14 11:35:42 -0400451 }
452
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400453 void testSetUp() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400454 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400455 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300456
457 setUpProgram();
458
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200459 mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale");
460 ASSERT_NE(-1, mDrawScaleUniformLocation);
Jamie Madill2453dbc2015-07-14 11:35:42 -0400461
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200462 glUseProgram(mProgram);
463 glUniform2f(mDrawScaleUniformLocation, 1.0f, 1.0f);
464 glUseProgram(0);
465 ASSERT_GL_NO_ERROR();
466 }
467
468 GLint mDrawScaleUniformLocation;
469};
470
Olli Etuaho4644a202016-01-12 15:12:53 +0200471class Sampler2DAsFunctionParameterTest : public Texture2DTest
472{
473 protected:
474 Sampler2DAsFunctionParameterTest() : Texture2DTest() {}
475
Jamie Madill35cd7332018-12-02 12:03:33 -0500476 const char *getFragmentShaderSource() override
Olli Etuaho4644a202016-01-12 15:12:53 +0200477 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300478 return
479 R"(precision highp float;
Olli Etuaho4644a202016-01-12 15:12:53 +0200480 uniform sampler2D tex;
481 varying vec2 texcoord;
482
483 vec4 computeFragColor(sampler2D aTex)
484 {
485 return texture2D(aTex, texcoord);
486 }
487
488 void main()
489 {
490 gl_FragColor = computeFragColor(tex);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300491 })";
Olli Etuaho4644a202016-01-12 15:12:53 +0200492 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300493
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400494 void testSetUp() override
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300495 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400496 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300497 setUpProgram();
498 }
Olli Etuaho4644a202016-01-12 15:12:53 +0200499};
500
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200501class TextureCubeTest : public TexCoordDrawTest
502{
503 protected:
504 TextureCubeTest()
505 : TexCoordDrawTest(),
506 mTexture2D(0),
507 mTextureCube(0),
508 mTexture2DUniformLocation(-1),
509 mTextureCubeUniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500510 {}
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200511
Jamie Madill35cd7332018-12-02 12:03:33 -0500512 const char *getFragmentShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200513 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300514 return
515 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200516 uniform sampler2D tex2D;
517 uniform samplerCube texCube;
518 varying vec2 texcoord;
519
520 void main()
521 {
522 gl_FragColor = texture2D(tex2D, texcoord);
523 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300524 })";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200525 }
526
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400527 void testSetUp() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200528 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400529 TexCoordDrawTest::testSetUp();
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200530
531 glGenTextures(1, &mTextureCube);
532 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Geoff Langc4e93662017-05-01 10:45:59 -0400533 for (GLenum face = 0; face < 6; face++)
534 {
535 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
536 GL_UNSIGNED_BYTE, nullptr);
537 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200538 EXPECT_GL_NO_ERROR();
539
540 mTexture2D = create2DTexture();
541
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300542 setUpProgram();
543
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200544 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
545 ASSERT_NE(-1, mTexture2DUniformLocation);
546 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
547 ASSERT_NE(-1, mTextureCubeUniformLocation);
548 }
549
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400550 void testTearDown() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200551 {
552 glDeleteTextures(1, &mTextureCube);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400553 TexCoordDrawTest::testTearDown();
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200554 }
555
556 GLuint mTexture2D;
557 GLuint mTextureCube;
558 GLint mTexture2DUniformLocation;
559 GLint mTextureCubeUniformLocation;
560};
561
Martin Radev7e2c0d32017-09-15 14:25:42 +0300562class TextureCubeTestES3 : public ANGLETest
563{
564 protected:
565 TextureCubeTestES3() {}
566};
567
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200568class SamplerArrayTest : public TexCoordDrawTest
569{
570 protected:
571 SamplerArrayTest()
572 : TexCoordDrawTest(),
573 mTexture2DA(0),
574 mTexture2DB(0),
575 mTexture0UniformLocation(-1),
576 mTexture1UniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500577 {}
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200578
Jamie Madill35cd7332018-12-02 12:03:33 -0500579 const char *getFragmentShaderSource() override
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200580 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300581 return
582 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200583 uniform highp sampler2D tex2DArray[2];
584 varying vec2 texcoord;
585 void main()
586 {
587 gl_FragColor = texture2D(tex2DArray[0], texcoord);
588 gl_FragColor += texture2D(tex2DArray[1], texcoord);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300589 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200590 }
591
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400592 void testSetUp() override
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200593 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400594 TexCoordDrawTest::testSetUp();
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200595
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300596 setUpProgram();
597
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200598 mTexture0UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[0]");
599 ASSERT_NE(-1, mTexture0UniformLocation);
600 mTexture1UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[1]");
601 ASSERT_NE(-1, mTexture1UniformLocation);
602
603 mTexture2DA = create2DTexture();
604 mTexture2DB = create2DTexture();
605 ASSERT_GL_NO_ERROR();
606 }
607
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400608 void testTearDown() override
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200609 {
610 glDeleteTextures(1, &mTexture2DA);
611 glDeleteTextures(1, &mTexture2DB);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400612 TexCoordDrawTest::testTearDown();
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200613 }
614
615 void testSamplerArrayDraw()
616 {
617 GLubyte texData[4];
618 texData[0] = 0;
619 texData[1] = 60;
620 texData[2] = 0;
621 texData[3] = 255;
622
623 glActiveTexture(GL_TEXTURE0);
624 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
625 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
626
627 texData[1] = 120;
628 glActiveTexture(GL_TEXTURE1);
629 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
630 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
631 EXPECT_GL_ERROR(GL_NO_ERROR);
632
633 glUseProgram(mProgram);
634 glUniform1i(mTexture0UniformLocation, 0);
635 glUniform1i(mTexture1UniformLocation, 1);
636 drawQuad(mProgram, "position", 0.5f);
637 EXPECT_GL_NO_ERROR();
638
639 EXPECT_PIXEL_NEAR(0, 0, 0, 180, 0, 255, 2);
640 }
641
642 GLuint mTexture2DA;
643 GLuint mTexture2DB;
644 GLint mTexture0UniformLocation;
645 GLint mTexture1UniformLocation;
646};
647
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200648class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest
649{
650 protected:
651 SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {}
652
Jamie Madill35cd7332018-12-02 12:03:33 -0500653 const char *getFragmentShaderSource() override
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200654 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300655 return
656 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200657 uniform highp sampler2D tex2DArray[2];
658 varying vec2 texcoord;
659
660 vec4 computeFragColor(highp sampler2D aTex2DArray[2])
661 {
662 return texture2D(aTex2DArray[0], texcoord) + texture2D(aTex2DArray[1], texcoord);
663 }
664
665 void main()
666 {
667 gl_FragColor = computeFragColor(tex2DArray);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300668 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200669 }
670};
671
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200672class Texture2DArrayTestES3 : public TexCoordDrawTest
673{
674 protected:
675 Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {}
676
Jamie Madill35cd7332018-12-02 12:03:33 -0500677 const char *getVertexShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200678 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500679 return "#version 300 es\n"
680 "out vec2 texcoord;\n"
681 "in vec4 position;\n"
682 "void main()\n"
683 "{\n"
684 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
685 " texcoord = (position.xy * 0.5) + 0.5;\n"
686 "}\n";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200687 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400688
Jamie Madill35cd7332018-12-02 12:03:33 -0500689 const char *getFragmentShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200690 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500691 return "#version 300 es\n"
692 "precision highp float;\n"
693 "uniform highp sampler2DArray tex2DArray;\n"
694 "in vec2 texcoord;\n"
695 "out vec4 fragColor;\n"
696 "void main()\n"
697 "{\n"
698 " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n"
699 "}\n";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200700 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400701
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400702 void testSetUp() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200703 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400704 TexCoordDrawTest::testSetUp();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400705
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300706 setUpProgram();
707
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200708 mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray");
Jamie Madill2453dbc2015-07-14 11:35:42 -0400709 ASSERT_NE(-1, mTextureArrayLocation);
710
711 glGenTextures(1, &m2DArrayTexture);
712 ASSERT_GL_NO_ERROR();
713 }
714
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400715 void testTearDown() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400716 {
717 glDeleteTextures(1, &m2DArrayTexture);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400718 TexCoordDrawTest::testTearDown();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400719 }
720
721 GLuint m2DArrayTexture;
Jamie Madill2453dbc2015-07-14 11:35:42 -0400722 GLint mTextureArrayLocation;
723};
724
Olli Etuahobce743a2016-01-15 17:18:28 +0200725class TextureSizeTextureArrayTest : public TexCoordDrawTest
726{
727 protected:
728 TextureSizeTextureArrayTest()
729 : TexCoordDrawTest(),
730 mTexture2DA(0),
731 mTexture2DB(0),
732 mTexture0Location(-1),
733 mTexture1Location(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500734 {}
Olli Etuahobce743a2016-01-15 17:18:28 +0200735
Jamie Madill35cd7332018-12-02 12:03:33 -0500736 const char *getVertexShaderSource() override { return essl3_shaders::vs::Simple(); }
Olli Etuahobce743a2016-01-15 17:18:28 +0200737
Jamie Madill35cd7332018-12-02 12:03:33 -0500738 const char *getFragmentShaderSource() override
Olli Etuahobce743a2016-01-15 17:18:28 +0200739 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500740 return "#version 300 es\n"
741 "precision highp float;\n"
742 "uniform highp sampler2D tex2DArray[2];\n"
743 "out vec4 fragColor;\n"
744 "void main()\n"
745 "{\n"
746 " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n"
747 " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n"
748 " fragColor = vec4(red, green, 0.0, 1.0);\n"
749 "}\n";
Olli Etuahobce743a2016-01-15 17:18:28 +0200750 }
751
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400752 void testSetUp() override
Olli Etuahobce743a2016-01-15 17:18:28 +0200753 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400754 TexCoordDrawTest::testSetUp();
Olli Etuahobce743a2016-01-15 17:18:28 +0200755
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300756 setUpProgram();
757
Olli Etuahobce743a2016-01-15 17:18:28 +0200758 mTexture0Location = glGetUniformLocation(mProgram, "tex2DArray[0]");
759 ASSERT_NE(-1, mTexture0Location);
760 mTexture1Location = glGetUniformLocation(mProgram, "tex2DArray[1]");
761 ASSERT_NE(-1, mTexture1Location);
762
763 mTexture2DA = create2DTexture();
764 mTexture2DB = create2DTexture();
765 ASSERT_GL_NO_ERROR();
766 }
767
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400768 void testTearDown() override
Olli Etuahobce743a2016-01-15 17:18:28 +0200769 {
770 glDeleteTextures(1, &mTexture2DA);
771 glDeleteTextures(1, &mTexture2DB);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400772 TexCoordDrawTest::testTearDown();
Olli Etuahobce743a2016-01-15 17:18:28 +0200773 }
774
775 GLuint mTexture2DA;
776 GLuint mTexture2DB;
777 GLint mTexture0Location;
778 GLint mTexture1Location;
779};
780
Olli Etuahoa314b612016-03-10 16:43:00 +0200781class Texture3DTestES3 : public TexCoordDrawTest
782{
783 protected:
784 Texture3DTestES3() : TexCoordDrawTest(), mTexture3D(0), mTexture3DUniformLocation(-1) {}
785
Jamie Madill35cd7332018-12-02 12:03:33 -0500786 const char *getVertexShaderSource() override
Olli Etuahoa314b612016-03-10 16:43:00 +0200787 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500788 return "#version 300 es\n"
789 "out vec2 texcoord;\n"
790 "in vec4 position;\n"
791 "void main()\n"
792 "{\n"
793 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
794 " texcoord = (position.xy * 0.5) + 0.5;\n"
795 "}\n";
Olli Etuahoa314b612016-03-10 16:43:00 +0200796 }
797
Jamie Madill35cd7332018-12-02 12:03:33 -0500798 const char *getFragmentShaderSource() override
Olli Etuahoa314b612016-03-10 16:43:00 +0200799 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500800 return "#version 300 es\n"
801 "precision highp float;\n"
802 "uniform highp sampler3D tex3D;\n"
803 "in vec2 texcoord;\n"
804 "out vec4 fragColor;\n"
805 "void main()\n"
806 "{\n"
807 " fragColor = texture(tex3D, vec3(texcoord, 0.0));\n"
808 "}\n";
Olli Etuahoa314b612016-03-10 16:43:00 +0200809 }
810
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400811 void testSetUp() override
Olli Etuahoa314b612016-03-10 16:43:00 +0200812 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400813 TexCoordDrawTest::testSetUp();
Olli Etuahoa314b612016-03-10 16:43:00 +0200814
815 glGenTextures(1, &mTexture3D);
816
817 setUpProgram();
818
819 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
820 ASSERT_NE(-1, mTexture3DUniformLocation);
821 }
822
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400823 void testTearDown() override
Olli Etuahoa314b612016-03-10 16:43:00 +0200824 {
825 glDeleteTextures(1, &mTexture3D);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400826 TexCoordDrawTest::testTearDown();
Olli Etuahoa314b612016-03-10 16:43:00 +0200827 }
828
829 GLuint mTexture3D;
830 GLint mTexture3DUniformLocation;
831};
832
Olli Etuaho1a679902016-01-14 12:21:47 +0200833class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest
834{
835 protected:
836 ShadowSamplerPlusSampler3DTestES3()
837 : TexCoordDrawTest(),
838 mTextureShadow(0),
839 mTexture3D(0),
840 mTextureShadowUniformLocation(-1),
841 mTexture3DUniformLocation(-1),
842 mDepthRefUniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500843 {}
Olli Etuaho1a679902016-01-14 12:21:47 +0200844
Jamie Madill35cd7332018-12-02 12:03:33 -0500845 const char *getVertexShaderSource() override
Olli Etuaho1a679902016-01-14 12:21:47 +0200846 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500847 return "#version 300 es\n"
848 "out vec2 texcoord;\n"
849 "in vec4 position;\n"
850 "void main()\n"
851 "{\n"
852 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
853 " texcoord = (position.xy * 0.5) + 0.5;\n"
854 "}\n";
Olli Etuaho1a679902016-01-14 12:21:47 +0200855 }
856
Jamie Madill35cd7332018-12-02 12:03:33 -0500857 const char *getFragmentShaderSource() override
Olli Etuaho1a679902016-01-14 12:21:47 +0200858 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500859 return "#version 300 es\n"
860 "precision highp float;\n"
861 "uniform highp sampler2DShadow tex2DShadow;\n"
862 "uniform highp sampler3D tex3D;\n"
863 "in vec2 texcoord;\n"
864 "uniform float depthRef;\n"
865 "out vec4 fragColor;\n"
866 "void main()\n"
867 "{\n"
868 " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n"
869 " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n"
870 "}\n";
Olli Etuaho1a679902016-01-14 12:21:47 +0200871 }
872
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400873 void testSetUp() override
Olli Etuaho1a679902016-01-14 12:21:47 +0200874 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400875 TexCoordDrawTest::testSetUp();
Olli Etuaho1a679902016-01-14 12:21:47 +0200876
877 glGenTextures(1, &mTexture3D);
878
879 glGenTextures(1, &mTextureShadow);
880 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
881 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
882
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300883 setUpProgram();
884
Olli Etuaho1a679902016-01-14 12:21:47 +0200885 mTextureShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
886 ASSERT_NE(-1, mTextureShadowUniformLocation);
887 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
888 ASSERT_NE(-1, mTexture3DUniformLocation);
889 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
890 ASSERT_NE(-1, mDepthRefUniformLocation);
891 }
892
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400893 void testTearDown() override
Olli Etuaho1a679902016-01-14 12:21:47 +0200894 {
895 glDeleteTextures(1, &mTextureShadow);
896 glDeleteTextures(1, &mTexture3D);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400897 TexCoordDrawTest::testTearDown();
Olli Etuaho1a679902016-01-14 12:21:47 +0200898 }
899
900 GLuint mTextureShadow;
901 GLuint mTexture3D;
902 GLint mTextureShadowUniformLocation;
903 GLint mTexture3DUniformLocation;
904 GLint mDepthRefUniformLocation;
905};
906
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200907class SamplerTypeMixTestES3 : public TexCoordDrawTest
908{
909 protected:
910 SamplerTypeMixTestES3()
911 : TexCoordDrawTest(),
912 mTexture2D(0),
913 mTextureCube(0),
914 mTexture2DShadow(0),
915 mTextureCubeShadow(0),
916 mTexture2DUniformLocation(-1),
917 mTextureCubeUniformLocation(-1),
918 mTexture2DShadowUniformLocation(-1),
919 mTextureCubeShadowUniformLocation(-1),
920 mDepthRefUniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500921 {}
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200922
Jamie Madill35cd7332018-12-02 12:03:33 -0500923 const char *getVertexShaderSource() override
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200924 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500925 return "#version 300 es\n"
926 "out vec2 texcoord;\n"
927 "in vec4 position;\n"
928 "void main()\n"
929 "{\n"
930 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
931 " texcoord = (position.xy * 0.5) + 0.5;\n"
932 "}\n";
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200933 }
934
Jamie Madill35cd7332018-12-02 12:03:33 -0500935 const char *getFragmentShaderSource() override
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200936 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500937 return "#version 300 es\n"
938 "precision highp float;\n"
939 "uniform highp sampler2D tex2D;\n"
940 "uniform highp samplerCube texCube;\n"
941 "uniform highp sampler2DShadow tex2DShadow;\n"
942 "uniform highp samplerCubeShadow texCubeShadow;\n"
943 "in vec2 texcoord;\n"
944 "uniform float depthRef;\n"
945 "out vec4 fragColor;\n"
946 "void main()\n"
947 "{\n"
948 " fragColor = texture(tex2D, texcoord);\n"
949 " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n"
950 " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n"
951 " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * "
952 "0.125);\n"
953 "}\n";
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200954 }
955
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400956 void testSetUp() override
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200957 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400958 TexCoordDrawTest::testSetUp();
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200959
960 glGenTextures(1, &mTexture2D);
961 glGenTextures(1, &mTextureCube);
962
963 glGenTextures(1, &mTexture2DShadow);
964 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
965 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
966
967 glGenTextures(1, &mTextureCubeShadow);
968 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
969 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
970
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300971 setUpProgram();
972
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200973 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
974 ASSERT_NE(-1, mTexture2DUniformLocation);
975 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
976 ASSERT_NE(-1, mTextureCubeUniformLocation);
977 mTexture2DShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
978 ASSERT_NE(-1, mTexture2DShadowUniformLocation);
979 mTextureCubeShadowUniformLocation = glGetUniformLocation(mProgram, "texCubeShadow");
980 ASSERT_NE(-1, mTextureCubeShadowUniformLocation);
981 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
982 ASSERT_NE(-1, mDepthRefUniformLocation);
983
984 ASSERT_GL_NO_ERROR();
985 }
986
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400987 void testTearDown() override
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200988 {
989 glDeleteTextures(1, &mTexture2D);
990 glDeleteTextures(1, &mTextureCube);
991 glDeleteTextures(1, &mTexture2DShadow);
992 glDeleteTextures(1, &mTextureCubeShadow);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400993 TexCoordDrawTest::testTearDown();
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200994 }
995
996 GLuint mTexture2D;
997 GLuint mTextureCube;
998 GLuint mTexture2DShadow;
999 GLuint mTextureCubeShadow;
1000 GLint mTexture2DUniformLocation;
1001 GLint mTextureCubeUniformLocation;
1002 GLint mTexture2DShadowUniformLocation;
1003 GLint mTextureCubeShadowUniformLocation;
1004 GLint mDepthRefUniformLocation;
1005};
1006
Olli Etuaho96963162016-03-21 11:54:33 +02001007class SamplerInStructTest : public Texture2DTest
1008{
1009 protected:
1010 SamplerInStructTest() : Texture2DTest() {}
1011
1012 const char *getTextureUniformName() override { return "us.tex"; }
1013
Jamie Madill35cd7332018-12-02 12:03:33 -05001014 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001015 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001016 return "precision highp float;\n"
1017 "struct S\n"
1018 "{\n"
1019 " vec4 a;\n"
1020 " highp sampler2D tex;\n"
1021 "};\n"
1022 "uniform S us;\n"
1023 "varying vec2 texcoord;\n"
1024 "void main()\n"
1025 "{\n"
1026 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x);\n"
1027 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001028 }
1029
1030 void runSamplerInStructTest()
1031 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001032 setUpProgram();
1033
Olli Etuaho96963162016-03-21 11:54:33 +02001034 glActiveTexture(GL_TEXTURE0);
1035 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001036 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1037 &GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001038 drawQuad(mProgram, "position", 0.5f);
Olli Etuahoa314b612016-03-10 16:43:00 +02001039 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001040 }
1041};
1042
1043class SamplerInStructAsFunctionParameterTest : public SamplerInStructTest
1044{
1045 protected:
1046 SamplerInStructAsFunctionParameterTest() : SamplerInStructTest() {}
1047
Jamie Madill35cd7332018-12-02 12:03:33 -05001048 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001049 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001050 return "precision highp float;\n"
1051 "struct S\n"
1052 "{\n"
1053 " vec4 a;\n"
1054 " highp sampler2D tex;\n"
1055 "};\n"
1056 "uniform S us;\n"
1057 "varying vec2 texcoord;\n"
1058 "vec4 sampleFrom(S s) {\n"
1059 " return texture2D(s.tex, texcoord + s.a.x);\n"
1060 "}\n"
1061 "void main()\n"
1062 "{\n"
1063 " gl_FragColor = sampleFrom(us);\n"
1064 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001065 }
1066};
1067
1068class SamplerInStructArrayAsFunctionParameterTest : public SamplerInStructTest
1069{
1070 protected:
1071 SamplerInStructArrayAsFunctionParameterTest() : SamplerInStructTest() {}
1072
1073 const char *getTextureUniformName() override { return "us[0].tex"; }
1074
Jamie Madill35cd7332018-12-02 12:03:33 -05001075 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001076 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001077 return "precision highp float;\n"
1078 "struct S\n"
1079 "{\n"
1080 " vec4 a;\n"
1081 " highp sampler2D tex;\n"
1082 "};\n"
1083 "uniform S us[1];\n"
1084 "varying vec2 texcoord;\n"
1085 "vec4 sampleFrom(S s) {\n"
1086 " return texture2D(s.tex, texcoord + s.a.x);\n"
1087 "}\n"
1088 "void main()\n"
1089 "{\n"
1090 " gl_FragColor = sampleFrom(us[0]);\n"
1091 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001092 }
1093};
1094
1095class SamplerInNestedStructAsFunctionParameterTest : public SamplerInStructTest
1096{
1097 protected:
1098 SamplerInNestedStructAsFunctionParameterTest() : SamplerInStructTest() {}
1099
1100 const char *getTextureUniformName() override { return "us[0].sub.tex"; }
1101
Jamie Madill35cd7332018-12-02 12:03:33 -05001102 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001103 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001104 return "precision highp float;\n"
1105 "struct SUB\n"
1106 "{\n"
1107 " vec4 a;\n"
1108 " highp sampler2D tex;\n"
1109 "};\n"
1110 "struct S\n"
1111 "{\n"
1112 " SUB sub;\n"
1113 "};\n"
1114 "uniform S us[1];\n"
1115 "varying vec2 texcoord;\n"
1116 "vec4 sampleFrom(SUB s) {\n"
1117 " return texture2D(s.tex, texcoord + s.a.x);\n"
1118 "}\n"
1119 "void main()\n"
1120 "{\n"
1121 " gl_FragColor = sampleFrom(us[0].sub);\n"
1122 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001123 }
1124};
1125
1126class SamplerInStructAndOtherVariableTest : public SamplerInStructTest
1127{
1128 protected:
1129 SamplerInStructAndOtherVariableTest() : SamplerInStructTest() {}
1130
Jamie Madill35cd7332018-12-02 12:03:33 -05001131 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001132 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001133 return "precision highp float;\n"
1134 "struct S\n"
1135 "{\n"
1136 " vec4 a;\n"
1137 " highp sampler2D tex;\n"
1138 "};\n"
1139 "uniform S us;\n"
1140 "uniform float us_tex;\n"
1141 "varying vec2 texcoord;\n"
1142 "void main()\n"
1143 "{\n"
1144 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x + us_tex);\n"
1145 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001146 }
1147};
1148
Anders Leinof6cbe442019-04-18 15:32:07 +03001149class Texture2DIntegerTestES3 : public Texture2DTest
1150{
1151 protected:
1152 Texture2DIntegerTestES3() : Texture2DTest() {}
1153
1154 const char *getVertexShaderSource() override
1155 {
1156 return "#version 300 es\n"
1157 "out vec2 texcoord;\n"
1158 "in vec4 position;\n"
1159 "void main()\n"
1160 "{\n"
1161 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1162 " texcoord = (position.xy * 0.5) + 0.5;\n"
1163 "}\n";
1164 }
1165
1166 const char *getFragmentShaderSource() override
1167 {
1168 return "#version 300 es\n"
1169 "precision highp float;\n"
1170 "precision highp usampler2D;\n"
1171 "uniform usampler2D tex;\n"
1172 "in vec2 texcoord;\n"
1173 "out vec4 fragColor;\n"
1174 "void main()\n"
1175 "{\n"
1176 " fragColor = vec4(texture(tex, texcoord));\n"
1177 "}\n";
1178 }
1179};
1180
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001181TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001182{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001183 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001184 EXPECT_GL_ERROR(GL_NO_ERROR);
1185
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001186 setUpProgram();
1187
Jamie Madill50cf2be2018-06-15 09:46:57 -04001188 const GLubyte *pixels[20] = {0};
Jamie Madillf67115c2014-04-22 13:14:05 -04001189 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1190 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001191
Jamie Madillb8149072019-04-30 16:14:44 -04001192 if (IsGLExtensionEnabled("GL_EXT_texture_storage"))
Geoff Langc51642b2016-11-14 16:18:26 -05001193 {
1194 // Create a 1-level immutable texture.
1195 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1196
1197 // Try calling sub image on the second level.
1198 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1199 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1200 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001201}
Geoff Langc41e42d2014-04-28 10:58:16 -04001202
John Bauman18319182016-09-28 14:22:27 -07001203// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1204TEST_P(Texture2DTest, QueryBinding)
1205{
1206 glBindTexture(GL_TEXTURE_2D, 0);
1207 EXPECT_GL_ERROR(GL_NO_ERROR);
1208
1209 GLint textureBinding;
1210 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1211 EXPECT_GL_NO_ERROR();
1212 EXPECT_EQ(0, textureBinding);
1213
1214 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
Jamie Madillb8149072019-04-30 16:14:44 -04001215 if (IsGLExtensionEnabled("GL_OES_EGL_image_external") ||
1216 IsGLExtensionEnabled("GL_NV_EGL_stream_consumer_external"))
John Bauman18319182016-09-28 14:22:27 -07001217 {
1218 EXPECT_GL_NO_ERROR();
1219 EXPECT_EQ(0, textureBinding);
1220 }
1221 else
1222 {
1223 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1224 }
1225}
1226
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001227TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001228{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001229 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001230 EXPECT_GL_ERROR(GL_NO_ERROR);
1231
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001232 setUpProgram();
1233
Geoff Langc41e42d2014-04-28 10:58:16 -04001234 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001235 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001236 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001237 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001238
Jamie Madill50cf2be2018-06-15 09:46:57 -04001239 const GLubyte *pixel[4] = {0};
Geoff Langc41e42d2014-04-28 10:58:16 -04001240
1241 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1242 EXPECT_GL_NO_ERROR();
1243
1244 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1245 EXPECT_GL_NO_ERROR();
1246
1247 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1248 EXPECT_GL_NO_ERROR();
1249}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001250
1251// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001252TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001253{
1254 glActiveTexture(GL_TEXTURE0);
1255 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1256 glActiveTexture(GL_TEXTURE1);
1257 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1258 EXPECT_GL_ERROR(GL_NO_ERROR);
1259
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001260 glUseProgram(mProgram);
1261 glUniform1i(mTexture2DUniformLocation, 0);
1262 glUniform1i(mTextureCubeUniformLocation, 1);
1263 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001264 EXPECT_GL_NO_ERROR();
1265}
Jamie Madill9aca0592014-10-06 16:26:59 -04001266
Olli Etuaho53a2da12016-01-11 15:43:32 +02001267// Test drawing with two texture types accessed from the same shader and check that the result of
1268// drawing is correct.
1269TEST_P(TextureCubeTest, CubeMapDraw)
1270{
1271 GLubyte texData[4];
1272 texData[0] = 0;
1273 texData[1] = 60;
1274 texData[2] = 0;
1275 texData[3] = 255;
1276
1277 glActiveTexture(GL_TEXTURE0);
1278 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1279 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1280
1281 glActiveTexture(GL_TEXTURE1);
1282 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1283 texData[1] = 120;
1284 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1285 texData);
1286 EXPECT_GL_ERROR(GL_NO_ERROR);
1287
1288 glUseProgram(mProgram);
1289 glUniform1i(mTexture2DUniformLocation, 0);
1290 glUniform1i(mTextureCubeUniformLocation, 1);
1291 drawQuad(mProgram, "position", 0.5f);
1292 EXPECT_GL_NO_ERROR();
1293
1294 int px = getWindowWidth() - 1;
1295 int py = 0;
1296 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1297}
1298
Olli Etuaho4644a202016-01-12 15:12:53 +02001299TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1300{
1301 glActiveTexture(GL_TEXTURE0);
1302 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1303 GLubyte texData[4];
1304 texData[0] = 0;
1305 texData[1] = 128;
1306 texData[2] = 0;
1307 texData[3] = 255;
1308 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1309 glUseProgram(mProgram);
1310 glUniform1i(mTexture2DUniformLocation, 0);
1311 drawQuad(mProgram, "position", 0.5f);
1312 EXPECT_GL_NO_ERROR();
1313
1314 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1315}
1316
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001317// Test drawing with two textures passed to the shader in a sampler array.
1318TEST_P(SamplerArrayTest, SamplerArrayDraw)
1319{
1320 testSamplerArrayDraw();
1321}
1322
1323// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1324// user-defined function in the shader.
1325TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1326{
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05001327 // TODO: Diagnose and fix. http://anglebug.com/2955
1328 ANGLE_SKIP_TEST_IF(IsVulkan() && IsAndroid());
1329
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001330 testSamplerArrayDraw();
1331}
1332
Jamie Madill9aca0592014-10-06 16:26:59 -04001333// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001334TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001335{
1336 int px = getWindowWidth() / 2;
1337 int py = getWindowHeight() / 2;
1338
1339 glActiveTexture(GL_TEXTURE0);
1340 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1341
Olli Etuahoa314b612016-03-10 16:43:00 +02001342 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001343
Olli Etuahoa314b612016-03-10 16:43:00 +02001344 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001345 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1346 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1347 glGenerateMipmap(GL_TEXTURE_2D);
1348
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001349 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001350 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001351 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1352 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001353 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001354 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001355
Olli Etuahoa314b612016-03-10 16:43:00 +02001356 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001357
Olli Etuahoa314b612016-03-10 16:43:00 +02001358 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1359 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001360 glGenerateMipmap(GL_TEXTURE_2D);
1361
Olli Etuahoa314b612016-03-10 16:43:00 +02001362 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001363
Olli Etuahoa314b612016-03-10 16:43:00 +02001364 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1365 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001366 glGenerateMipmap(GL_TEXTURE_2D);
1367
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001368 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001369
1370 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001371 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001372}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001373
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001374// Test creating a FBO with a cube map render target, to test an ANGLE bug
1375// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001376TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001377{
Michael Spangd8506c72019-01-29 15:35:09 -05001378 // http://anglebug.com/3145
1379 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
1380
Shahbaz Youssefi0c128e12019-03-25 23:50:14 -04001381 // http://anglebug.com/2822
1382 ANGLE_SKIP_TEST_IF(IsWindows() && IsIntel() && IsVulkan());
1383
Jamie Madill3f3b3582018-09-14 10:38:44 -04001384 GLFramebuffer fbo;
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001385 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1386
1387 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Jamie Madill50cf2be2018-06-15 09:46:57 -04001388 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1389 mTextureCube, 0);
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001390
Corentin Wallez322653b2015-06-17 18:33:56 +02001391 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001392 EXPECT_GL_NO_ERROR();
Jamie Madill3f3b3582018-09-14 10:38:44 -04001393
1394 // Test clearing the six mip faces individually.
1395 std::array<GLColor, 6> faceColors = {{GLColor::red, GLColor::green, GLColor::blue,
1396 GLColor::yellow, GLColor::cyan, GLColor::magenta}};
1397
1398 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1399 {
1400 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1401 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1402
1403 Vector4 clearColorF = faceColors[faceIndex].toNormalizedVector();
1404 glClearColor(clearColorF.x(), clearColorF.y(), clearColorF.z(), clearColorF.w());
1405 glClear(GL_COLOR_BUFFER_BIT);
1406
1407 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex]);
1408 }
1409
1410 // Iterate the faces again to make sure the colors haven't changed.
1411 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1412 {
1413 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1414 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1415 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex])
1416 << "face color " << faceIndex << " shouldn't change";
1417 }
1418}
1419
1420// Tests clearing a cube map with a scissor enabled.
1421TEST_P(TextureCubeTest, CubeMapFBOScissoredClear)
1422{
1423 // TODO(jie.a.chen): Diagnose and fix. http://anglebug.com/2822
1424 ANGLE_SKIP_TEST_IF(IsVulkan() && IsIntel() && IsWindows());
1425
Michael Spangd8506c72019-01-29 15:35:09 -05001426 // http://anglebug.com/3145
1427 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
1428
Jamie Madill3f3b3582018-09-14 10:38:44 -04001429 constexpr size_t kSize = 16;
1430
1431 GLFramebuffer fbo;
1432 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1433 glViewport(0, 0, kSize, kSize);
1434
1435 GLTexture texcube;
1436 glBindTexture(GL_TEXTURE_CUBE_MAP, texcube);
1437 for (GLenum face = 0; face < 6; face++)
1438 {
1439 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA,
1440 GL_UNSIGNED_BYTE, nullptr);
1441 }
1442 ASSERT_GL_NO_ERROR();
1443
1444 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1445 texcube, 0);
1446
1447 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1448 ASSERT_GL_NO_ERROR();
1449
1450 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1451 glClear(GL_COLOR_BUFFER_BIT);
1452 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1453
1454 glEnable(GL_SCISSOR_TEST);
1455 glScissor(kSize / 2, 0, kSize / 2, kSize);
1456 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
1457 glClear(GL_COLOR_BUFFER_BIT);
1458
1459 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1460 EXPECT_PIXEL_COLOR_EQ(kSize / 2 + 1, 0, GLColor::green);
1461
1462 ASSERT_GL_NO_ERROR();
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001463}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001464
Jamie Madill50cf2be2018-06-15 09:46:57 -04001465// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a
1466// default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001467TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001468{
Jamie Madillb8149072019-04-30 16:14:44 -04001469 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 &&
1470 !IsGLExtensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -04001471
Jamie Madill50cf2be2018-06-15 09:46:57 -04001472 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001473 int height = getWindowHeight();
1474
1475 GLuint tex2D;
1476 glGenTextures(1, &tex2D);
1477 glActiveTexture(GL_TEXTURE0);
1478 glBindTexture(GL_TEXTURE_2D, tex2D);
1479
1480 // Fill with red
1481 std::vector<GLubyte> pixels(3 * 16 * 16);
1482 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1483 {
1484 pixels[pixelId * 3 + 0] = 255;
1485 pixels[pixelId * 3 + 1] = 0;
1486 pixels[pixelId * 3 + 2] = 0;
1487 }
1488
1489 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001490 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1491 // 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 -04001492 if (getClientMajorVersion() >= 3)
1493 {
1494 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1495 }
1496 else
1497 {
1498 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1499 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001500
1501 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1502 // glTexSubImage2D should take into account that the image is dirty.
1503 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1504 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1505 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1506
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001507 setUpProgram();
1508
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001509 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001510 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001511 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001512 glDeleteTextures(1, &tex2D);
1513 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001514 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001515
1516 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001517 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1518 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001519}
1520
Jamie Madill50cf2be2018-06-15 09:46:57 -04001521// Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has
1522// initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001523TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001524{
Jamie Madillb8149072019-04-30 16:14:44 -04001525 if (IsGLExtensionEnabled("NV_pixel_buffer_object"))
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001526 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04001527 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001528 int height = getWindowHeight();
1529
1530 GLuint tex2D;
1531 glGenTextures(1, &tex2D);
1532 glActiveTexture(GL_TEXTURE0);
1533 glBindTexture(GL_TEXTURE_2D, tex2D);
1534
1535 // Fill with red
1536 std::vector<GLubyte> pixels(3 * 16 * 16);
1537 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1538 {
1539 pixels[pixelId * 3 + 0] = 255;
1540 pixels[pixelId * 3 + 1] = 0;
1541 pixels[pixelId * 3 + 2] = 0;
1542 }
1543
1544 // Read 16x16 region from red backbuffer to PBO
1545 GLuint pbo;
1546 glGenBuffers(1, &pbo);
1547 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1548 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1549
1550 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001551 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1552 // alpha color. The data is kept in a CPU-side image and the image is marked as dirty.
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001553 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1554
1555 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1556 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001557 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001558 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1559 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1560
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001561 setUpProgram();
1562
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001563 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001564 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001565 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001566 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001567 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001568 EXPECT_GL_NO_ERROR();
1569 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1570 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1571 }
1572}
Jamie Madillbc393df2015-01-29 13:46:07 -05001573
1574// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001575TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001576{
1577 testFloatCopySubImage(1, 1);
1578}
1579
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001580TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001581{
1582 testFloatCopySubImage(2, 1);
1583}
1584
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001585TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001586{
1587 testFloatCopySubImage(2, 2);
1588}
1589
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001590TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001591{
1592 testFloatCopySubImage(3, 1);
1593}
1594
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001595TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001596{
1597 testFloatCopySubImage(3, 2);
1598}
1599
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001600TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001601{
Yunchao He9550c602018-02-13 14:47:05 +08001602 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1603 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001604
Yunchao He9550c602018-02-13 14:47:05 +08001605 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1606 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001607
Jamie Madillbc393df2015-01-29 13:46:07 -05001608 testFloatCopySubImage(3, 3);
1609}
1610
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001611TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001612{
1613 testFloatCopySubImage(4, 1);
1614}
1615
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001616TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001617{
1618 testFloatCopySubImage(4, 2);
1619}
1620
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001621TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001622{
Yunchao He9550c602018-02-13 14:47:05 +08001623 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1624 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001625
Jamie Madillbc393df2015-01-29 13:46:07 -05001626 testFloatCopySubImage(4, 3);
1627}
1628
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001629TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001630{
Luc Ferronf786b702018-07-10 11:01:43 -04001631 // TODO(lucferron): This test fails only on linux and intel.
1632 // http://anglebug.com/2726
1633 ANGLE_SKIP_TEST_IF(IsVulkan() && IsLinux() && IsIntel());
1634
Yunchao He9550c602018-02-13 14:47:05 +08001635 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1636 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001637
Jamie Madillbc393df2015-01-29 13:46:07 -05001638 testFloatCopySubImage(4, 4);
1639}
Austin Kinross07285142015-03-26 11:36:16 -07001640
Jamie Madill50cf2be2018-06-15 09:46:57 -04001641// Port of
1642// https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1643// Run against GL_ALPHA/UNSIGNED_BYTE format, to ensure that D3D11 Feature Level 9_3 correctly
1644// handles GL_ALPHA
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001645TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001646{
1647 const int npotTexSize = 5;
Jamie Madill50cf2be2018-06-15 09:46:57 -04001648 const int potTexSize = 4; // Should be less than npotTexSize
Austin Kinross07285142015-03-26 11:36:16 -07001649 GLuint tex2D;
1650
Jamie Madillb8149072019-04-30 16:14:44 -04001651 if (IsGLExtensionEnabled("GL_OES_texture_npot"))
Austin Kinross07285142015-03-26 11:36:16 -07001652 {
1653 // This test isn't applicable if texture_npot is enabled
1654 return;
1655 }
1656
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001657 setUpProgram();
1658
Austin Kinross07285142015-03-26 11:36:16 -07001659 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1660
Austin Kinross5faa15b2016-01-11 13:32:48 -08001661 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1662 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1663
Austin Kinross07285142015-03-26 11:36:16 -07001664 glActiveTexture(GL_TEXTURE0);
1665 glGenTextures(1, &tex2D);
1666 glBindTexture(GL_TEXTURE_2D, tex2D);
1667
Till Rathmannc1551dc2018-08-15 17:04:49 +02001668 const std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize, 64);
Austin Kinross07285142015-03-26 11:36:16 -07001669
1670 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1671 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1672
1673 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
Jamie Madill50cf2be2018-06-15 09:46:57 -04001674 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1675 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001676 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1677
1678 // Check that an NPOT texture on level 0 succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001679 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1680 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001681 EXPECT_GL_NO_ERROR();
1682
1683 // Check that generateMipmap fails on NPOT
1684 glGenerateMipmap(GL_TEXTURE_2D);
1685 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1686
1687 // Check that nothing is drawn if filtering is not correct for NPOT
1688 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1689 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1690 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1691 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1692 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001693 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001694 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1695
1696 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1697 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1698 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1699 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1700 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001701 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001702 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1703
1704 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1705 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1706 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001707 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001708 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1709
1710 // Check that glTexImage2D for POT texture succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001711 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE,
1712 pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001713 EXPECT_GL_NO_ERROR();
1714
1715 // Check that generateMipmap for an POT texture succeeds
1716 glGenerateMipmap(GL_TEXTURE_2D);
1717 EXPECT_GL_NO_ERROR();
1718
1719 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1720 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1721 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1722 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1723 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1724 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001725 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001726 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1727 EXPECT_GL_NO_ERROR();
1728}
Jamie Madillfa05f602015-05-07 13:47:11 -04001729
Austin Kinross08528e12015-10-07 16:24:40 -07001730// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1731// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001732TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001733{
1734 glActiveTexture(GL_TEXTURE0);
1735 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1736
1737 // Create an 8x8 (i.e. power-of-two) texture.
1738 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1739 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1740 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1741 glGenerateMipmap(GL_TEXTURE_2D);
1742
1743 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1744 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001745 std::array<GLColor, 3 * 3> data;
1746 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001747
1748 EXPECT_GL_NO_ERROR();
1749}
1750
Geoff Lang3702d8c2019-04-08 13:44:06 -04001751// Regression test for http://crbug.com/949985 to make sure dirty bits are propagated up from
1752// TextureImpl and the texture is synced before being used in a draw call.
1753TEST_P(Texture2DTestES3, TextureImplPropogatesDirtyBits)
1754{
1755 ANGLE_SKIP_TEST_IF(IsIntel() && IsOpenGL());
Yuly Novikove6b23e42019-04-10 17:19:15 -04001756 // Flaky hangs on Win10 AMD RX 550 GL. http://anglebug.com/3371
1757 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsOpenGL());
Geoff Lang3702d8c2019-04-08 13:44:06 -04001758
1759 // The workaround in the GL backend required to trigger this bug generates driver warning
1760 // messages.
1761 ScopedIgnorePlatformMessages ignoreMessages;
1762
1763 setUpProgram();
1764 glUseProgram(mProgram);
1765 glActiveTexture(GL_TEXTURE0 + mTexture2DUniformLocation);
1766
1767 GLTexture dest;
1768 glBindTexture(GL_TEXTURE_2D, dest);
1769
1770 GLTexture source;
1771 glBindTexture(GL_TEXTURE_2D, source);
1772
1773 // Put data in mip 0 and 1
1774 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1775 GLColor::red.data());
1776 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1777 GLColor::green.data());
1778
1779 // Disable mipmapping so source is complete
1780 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1781 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1782
1783 // Force the dirty bits to be synchronized in source
1784 drawQuad(mProgram, "position", 1.0f);
1785
1786 // Copy from mip 1 of the source. In the GL backend this internally sets the base level to mip
1787 // 1 and sets a dirty bit.
1788 glCopyTextureCHROMIUM(source, 1, GL_TEXTURE_2D, dest, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_FALSE,
1789 GL_FALSE, GL_FALSE);
1790
1791 // Draw again, assertions are generated if the texture has internal dirty bits at draw time
1792 drawQuad(mProgram, "position", 1.0f);
1793}
1794
Geoff Lang6f691fb2019-04-25 11:01:52 -04001795// This test case changes the base level of a texture that's attached to a framebuffer, clears every
1796// level to green, and then samples the texture when rendering. Test is taken from
1797// https://www.khronos.org/registry/webgl/sdk/tests/conformance2/rendering/framebuffer-texture-changing-base-level.html
1798TEST_P(Texture2DTestES3, FramebufferTextureChangingBaselevel)
1799{
1800 // TODO(geofflang): Investigate on D3D11. http://anglebug.com/2291
1801 ANGLE_SKIP_TEST_IF(IsD3D11());
1802
1803 setUpProgram();
1804
1805 constexpr GLint width = 8;
1806 constexpr GLint height = 4;
1807
1808 GLTexture texture;
1809 glBindTexture(GL_TEXTURE_2D, texture);
1810 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1811 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1812 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1813 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1814
1815 // Create all mipmap levels for the texture from level 0 to the 1x1 pixel level.
1816 GLint level = 0;
1817 GLint levelW = width;
1818 GLint levelH = height;
1819 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, levelW, levelH, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1820 nullptr);
1821 while (levelW > 1 || levelH > 1)
1822 {
1823 ++level;
1824 levelW = static_cast<GLint>(std::max(1.0, std::floor(width / std::pow(2, level))));
1825 levelH = static_cast<GLint>(std::max(1.0, std::floor(height / std::pow(2, level))));
1826 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, levelW, levelH, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1827 nullptr);
1828 }
1829
1830 // Clear each level of the texture using an FBO. Change the base level to match the level used
1831 // for the FBO on each iteration.
1832 GLFramebuffer fbo;
1833 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1834 level = 0;
1835 levelW = width;
1836 levelH = height;
1837 while (levelW > 1 || levelH > 1)
1838 {
1839 levelW = static_cast<GLint>(std::floor(width / std::pow(2, level)));
1840 levelH = static_cast<GLint>(std::floor(height / std::pow(2, level)));
1841
1842 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, level);
1843 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, level);
1844
1845 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1846 EXPECT_GL_NO_ERROR();
1847
1848 glClearColor(0, 1, 0, 1);
1849 glClear(GL_COLOR_BUFFER_BIT);
1850
1851 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1852
1853 ++level;
1854 }
1855
1856 glBindFramebuffer(GL_FRAMEBUFFER, 0);
1857 glViewport(0, 0, 16, 16);
1858 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
1859
1860 drawQuad(mProgram, "position", 0.5f);
1861
1862 EXPECT_GL_NO_ERROR();
1863 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1864}
1865
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001866// Test to check that texture completeness is determined correctly when the texture base level is
1867// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1868TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1869{
1870 glActiveTexture(GL_TEXTURE0);
1871 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001872
1873 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1874 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1875 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1876 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1877 texDataGreen.data());
1878 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1879 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001880 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1881 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1882 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1883
1884 EXPECT_GL_NO_ERROR();
1885
1886 drawQuad(mProgram, "position", 0.5f);
1887
Olli Etuahoa314b612016-03-10 16:43:00 +02001888 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1889}
1890
1891// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1892// have images defined.
1893TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1894{
Yunchao He9550c602018-02-13 14:47:05 +08001895 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1896 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1897
Olli Etuahoa314b612016-03-10 16:43:00 +02001898 glActiveTexture(GL_TEXTURE0);
1899 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1900 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1901 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1902 texDataGreen.data());
1903 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1904 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1905 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1906 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1907
1908 EXPECT_GL_NO_ERROR();
1909
1910 drawQuad(mProgram, "position", 0.5f);
1911
1912 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1913}
1914
Olli Etuahoe8528d82016-05-16 17:50:52 +03001915// Test that drawing works correctly when level 0 is undefined and base level is 1.
1916TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1917{
Yunchao He9550c602018-02-13 14:47:05 +08001918 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1919 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1920
Olli Etuahoe8528d82016-05-16 17:50:52 +03001921 glActiveTexture(GL_TEXTURE0);
1922 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1923 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1924 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1925 texDataGreen.data());
1926 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1927 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1928 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1929 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1930
1931 EXPECT_GL_NO_ERROR();
1932
1933 // Texture is incomplete.
1934 drawQuad(mProgram, "position", 0.5f);
1935 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1936
1937 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1938 texDataGreen.data());
1939
1940 // Texture is now complete.
1941 drawQuad(mProgram, "position", 0.5f);
1942 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1943}
1944
Olli Etuahoa314b612016-03-10 16:43:00 +02001945// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1946// dimensions that don't fit the images inside the range.
1947// GLES 3.0.4 section 3.8.13 Texture completeness
1948TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1949{
Olli Etuahoa314b612016-03-10 16:43:00 +02001950 glActiveTexture(GL_TEXTURE0);
1951 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1952 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1953 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1954 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1955
1956 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1957 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1958
1959 // Two levels that are initially unused.
1960 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1961 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1962 texDataCyan.data());
1963
1964 // One level that is used - only this level should affect completeness.
1965 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1966 texDataGreen.data());
1967
1968 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1969 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1970
1971 EXPECT_GL_NO_ERROR();
1972
1973 drawQuad(mProgram, "position", 0.5f);
1974
1975 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1976
Yunchao He2f23f352018-02-11 22:11:37 +08001977 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001978
1979 // Switch the level that is being used to the cyan level 2.
1980 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1981 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1982
1983 EXPECT_GL_NO_ERROR();
1984
1985 drawQuad(mProgram, "position", 0.5f);
1986
1987 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1988}
1989
1990// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1991// have images defined.
1992TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1993{
Olli Etuahoa314b612016-03-10 16:43:00 +02001994 glActiveTexture(GL_TEXTURE0);
1995 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1996 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1997 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1998 texDataGreen.data());
1999 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2000 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2001 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
2002 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2003
2004 EXPECT_GL_NO_ERROR();
2005
2006 drawQuad(mProgram, "position", 0.5f);
2007
2008 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2009}
2010
2011// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2012// dimensions that don't fit the images inside the range.
2013// GLES 3.0.4 section 3.8.13 Texture completeness
2014TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2015{
Olli Etuahoa314b612016-03-10 16:43:00 +02002016 glActiveTexture(GL_TEXTURE0);
2017 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2018 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2019 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2020 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2021
2022 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2023 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2024
2025 // Two levels that are initially unused.
2026 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2027 texDataRed.data());
2028 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2029 texDataCyan.data());
2030
2031 // One level that is used - only this level should affect completeness.
2032 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2033 texDataGreen.data());
2034
2035 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
2036 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2037
2038 EXPECT_GL_NO_ERROR();
2039
2040 drawQuad(mProgram, "position", 0.5f);
2041
2042 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2043
Yunchao He2f23f352018-02-11 22:11:37 +08002044 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02002045
2046 // Switch the level that is being used to the cyan level 2.
2047 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
2048 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
2049
2050 EXPECT_GL_NO_ERROR();
2051
2052 drawQuad(mProgram, "position", 0.5f);
2053
2054 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2055}
2056
2057// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2058// have images defined.
2059TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
2060{
Olli Etuahoa314b612016-03-10 16:43:00 +02002061 glActiveTexture(GL_TEXTURE0);
2062 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
2063 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2064 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2065 texDataGreen.data());
2066 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2067 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2068 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2069 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2070
2071 EXPECT_GL_NO_ERROR();
2072
2073 drawQuad(mProgram, "position", 0.5f);
2074
2075 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2076}
2077
2078// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2079// dimensions that don't fit the images inside the range.
2080// GLES 3.0.4 section 3.8.13 Texture completeness
2081TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2082{
Olli Etuahoa314b612016-03-10 16:43:00 +02002083 glActiveTexture(GL_TEXTURE0);
2084 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
2085 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2086 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2087 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2088
2089 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2090 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2091
2092 // Two levels that are initially unused.
2093 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2094 texDataRed.data());
2095 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2096 texDataCyan.data());
2097
2098 // One level that is used - only this level should affect completeness.
2099 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2100 texDataGreen.data());
2101
2102 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2103 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2104
2105 EXPECT_GL_NO_ERROR();
2106
2107 drawQuad(mProgram, "position", 0.5f);
2108
2109 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2110
Yunchao He2f23f352018-02-11 22:11:37 +08002111 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
2112
Yunchao He9550c602018-02-13 14:47:05 +08002113 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
2114 // level was changed.
2115 ANGLE_SKIP_TEST_IF(IsNVIDIA() && (IsOpenGL() || IsOpenGLES()));
Olli Etuahoa314b612016-03-10 16:43:00 +02002116
2117 // Switch the level that is being used to the cyan level 2.
2118 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2119 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2120
2121 EXPECT_GL_NO_ERROR();
2122
2123 drawQuad(mProgram, "position", 0.5f);
2124
2125 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2126}
2127
2128// Test that texture completeness is updated if texture max level changes.
2129// GLES 3.0.4 section 3.8.13 Texture completeness
2130TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2131{
Olli Etuahoa314b612016-03-10 16:43:00 +02002132 glActiveTexture(GL_TEXTURE0);
2133 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2134 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2135
2136 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2137 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2138
2139 // A level that is initially unused.
2140 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2141 texDataGreen.data());
2142
2143 // One level that is initially used - only this level should affect completeness.
2144 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2145 texDataGreen.data());
2146
2147 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2148 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2149
2150 EXPECT_GL_NO_ERROR();
2151
2152 drawQuad(mProgram, "position", 0.5f);
2153
2154 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2155
2156 // Switch the max level to level 1. The levels within the used range now have inconsistent
2157 // dimensions and the texture should be incomplete.
2158 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2159
2160 EXPECT_GL_NO_ERROR();
2161
2162 drawQuad(mProgram, "position", 0.5f);
2163
2164 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2165}
2166
2167// Test that 3D texture completeness is updated if texture max level changes.
2168// GLES 3.0.4 section 3.8.13 Texture completeness
2169TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2170{
Olli Etuahoa314b612016-03-10 16:43:00 +02002171 glActiveTexture(GL_TEXTURE0);
2172 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2173 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2174
2175 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2176 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2177
2178 // A level that is initially unused.
2179 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2180 texDataGreen.data());
2181
2182 // One level that is initially used - only this level should affect completeness.
2183 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2184 texDataGreen.data());
2185
2186 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2187 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2188
2189 EXPECT_GL_NO_ERROR();
2190
2191 drawQuad(mProgram, "position", 0.5f);
2192
2193 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2194
2195 // Switch the max level to level 1. The levels within the used range now have inconsistent
2196 // dimensions and the texture should be incomplete.
2197 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2198
2199 EXPECT_GL_NO_ERROR();
2200
2201 drawQuad(mProgram, "position", 0.5f);
2202
2203 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2204}
2205
2206// Test that texture completeness is updated if texture base level changes.
2207// GLES 3.0.4 section 3.8.13 Texture completeness
2208TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2209{
Olli Etuahoa314b612016-03-10 16:43:00 +02002210 glActiveTexture(GL_TEXTURE0);
2211 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2212 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2213
2214 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2215 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2216
2217 // Two levels that are initially unused.
2218 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2219 texDataGreen.data());
2220 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2221 texDataGreen.data());
2222
2223 // One level that is initially used - only this level should affect completeness.
2224 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2225 texDataGreen.data());
2226
2227 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2228 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2229
2230 EXPECT_GL_NO_ERROR();
2231
2232 drawQuad(mProgram, "position", 0.5f);
2233
2234 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2235
2236 // Switch the base level to level 1. The levels within the used range now have inconsistent
2237 // dimensions and the texture should be incomplete.
2238 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2239
2240 EXPECT_GL_NO_ERROR();
2241
2242 drawQuad(mProgram, "position", 0.5f);
2243
2244 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2245}
2246
2247// Test that texture is not complete if base level is greater than max level.
2248// GLES 3.0.4 section 3.8.13 Texture completeness
2249TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2250{
Olli Etuahoa314b612016-03-10 16:43:00 +02002251 glActiveTexture(GL_TEXTURE0);
2252 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2253
2254 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2255 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2256
2257 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2258
2259 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2260 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2261
2262 EXPECT_GL_NO_ERROR();
2263
2264 drawQuad(mProgram, "position", 0.5f);
2265
2266 // Texture should be incomplete.
2267 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2268}
2269
2270// Test that immutable texture base level and max level are clamped.
2271// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2272TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2273{
Olli Etuahoa314b612016-03-10 16:43:00 +02002274 glActiveTexture(GL_TEXTURE0);
2275 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2276
2277 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2278 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2279
2280 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2281
2282 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2283
2284 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2285 // should be clamped to [base_level, levels - 1].
2286 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2287 // In the case of this test, those rules make the effective base level and max level 0.
2288 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2289 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2290
2291 EXPECT_GL_NO_ERROR();
2292
2293 drawQuad(mProgram, "position", 0.5f);
2294
2295 // Texture should be complete.
2296 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2297}
2298
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002299// Test that changing base level works when it affects the format of the texture.
2300TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2301{
Yunchao He9550c602018-02-13 14:47:05 +08002302 // Observed rendering corruption on NVIDIA OpenGL.
2303 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL());
2304
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002305 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002306
2307 // Observed incorrect rendering on AMD OpenGL.
2308 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002309
2310 glActiveTexture(GL_TEXTURE0);
2311 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2312 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2313 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2314
2315 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2316 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2317
2318 // RGBA8 level that's initially unused.
2319 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2320 texDataCyan.data());
2321
2322 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2323 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2324
2325 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2326 // format. It reads green channel data from the green and alpha channels of texDataGreen
2327 // (this is a bit hacky but works).
2328 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2329
2330 EXPECT_GL_NO_ERROR();
2331
2332 drawQuad(mProgram, "position", 0.5f);
2333
2334 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2335
2336 // Switch the texture to use the cyan level 0 with the RGBA format.
2337 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2338 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2339
2340 EXPECT_GL_NO_ERROR();
2341
2342 drawQuad(mProgram, "position", 0.5f);
2343
2344 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2345}
2346
Olli Etuahoa314b612016-03-10 16:43:00 +02002347// Test that setting a texture image works when base level is out of range.
2348TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2349{
2350 glActiveTexture(GL_TEXTURE0);
2351 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2352
2353 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2354 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2355
2356 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2357 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2358
2359 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2360
2361 EXPECT_GL_NO_ERROR();
2362
2363 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2364
2365 drawQuad(mProgram, "position", 0.5f);
2366
2367 // Texture should be complete.
2368 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002369}
2370
Jamie Madill50cf2be2018-06-15 09:46:57 -04002371// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG
2372// RBA->RGBA8, with 1.0 in the alpha channel. This test covers a bug where redefining array textures
2373// with these formats does not work as expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002374TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002375{
2376 std::vector<GLubyte> pixelData;
2377 for (size_t count = 0; count < 5000; count++)
2378 {
2379 pixelData.push_back(0u);
2380 pixelData.push_back(255u);
2381 pixelData.push_back(0u);
2382 }
2383
2384 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002385 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002386 glUniform1i(mTextureArrayLocation, 0);
2387
2388 // The first draw worked correctly.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002389 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2390 &pixelData[0]);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002391
2392 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2393 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2394 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2395 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002396 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002397 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002398
2399 // The dimension of the respecification must match the original exactly to trigger the bug.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002400 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2401 &pixelData[0]);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002402 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002403 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002404
2405 ASSERT_GL_NO_ERROR();
2406}
2407
Olli Etuaho1a679902016-01-14 12:21:47 +02002408// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2409// This test is needed especially to confirm that sampler registers get assigned correctly on
2410// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2411TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2412{
2413 glActiveTexture(GL_TEXTURE0);
2414 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2415 GLubyte texData[4];
2416 texData[0] = 0;
2417 texData[1] = 60;
2418 texData[2] = 0;
2419 texData[3] = 255;
2420 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2421
2422 glActiveTexture(GL_TEXTURE1);
2423 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2424 GLfloat depthTexData[1];
2425 depthTexData[0] = 0.5f;
2426 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2427 depthTexData);
2428
2429 glUseProgram(mProgram);
2430 glUniform1f(mDepthRefUniformLocation, 0.3f);
2431 glUniform1i(mTexture3DUniformLocation, 0);
2432 glUniform1i(mTextureShadowUniformLocation, 1);
2433
2434 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2435 drawQuad(mProgram, "position", 0.5f);
2436 EXPECT_GL_NO_ERROR();
2437 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2438 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2439
2440 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2441 drawQuad(mProgram, "position", 0.5f);
2442 EXPECT_GL_NO_ERROR();
2443 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2444 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2445}
2446
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002447// Test multiple different sampler types in the same shader.
2448// This test makes sure that even if sampler / texture registers get grouped together based on type
2449// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2450// still has the right register index information for each ESSL sampler.
2451// The tested ESSL samplers have the following types in D3D11 HLSL:
2452// sampler2D: Texture2D + SamplerState
2453// samplerCube: TextureCube + SamplerState
2454// sampler2DShadow: Texture2D + SamplerComparisonState
2455// samplerCubeShadow: TextureCube + SamplerComparisonState
2456TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2457{
2458 glActiveTexture(GL_TEXTURE0);
2459 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2460 GLubyte texData[4];
2461 texData[0] = 0;
2462 texData[1] = 0;
2463 texData[2] = 120;
2464 texData[3] = 255;
2465 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2466
2467 glActiveTexture(GL_TEXTURE1);
2468 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2469 texData[0] = 0;
2470 texData[1] = 90;
2471 texData[2] = 0;
2472 texData[3] = 255;
2473 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2474 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2475 texData);
2476
2477 glActiveTexture(GL_TEXTURE2);
2478 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2479 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2480 GLfloat depthTexData[1];
2481 depthTexData[0] = 0.5f;
2482 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2483 depthTexData);
2484
2485 glActiveTexture(GL_TEXTURE3);
2486 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2487 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2488 depthTexData[0] = 0.2f;
2489 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2490 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2491 depthTexData);
2492
2493 EXPECT_GL_NO_ERROR();
2494
2495 glUseProgram(mProgram);
2496 glUniform1f(mDepthRefUniformLocation, 0.3f);
2497 glUniform1i(mTexture2DUniformLocation, 0);
2498 glUniform1i(mTextureCubeUniformLocation, 1);
2499 glUniform1i(mTexture2DShadowUniformLocation, 2);
2500 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2501
2502 drawQuad(mProgram, "position", 0.5f);
2503 EXPECT_GL_NO_ERROR();
2504 // The shader writes:
2505 // <texture 2d color> +
2506 // <cube map color> +
2507 // 0.25 * <comparison result (1.0)> +
2508 // 0.125 * <comparison result (0.0)>
2509 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2510}
2511
Olli Etuahobce743a2016-01-15 17:18:28 +02002512// Test different base levels on textures accessed through the same sampler array.
2513// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2514TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2515{
Yunchao He9550c602018-02-13 14:47:05 +08002516 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2517
Olli Etuahobce743a2016-01-15 17:18:28 +02002518 glActiveTexture(GL_TEXTURE0);
2519 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2520 GLsizei size = 64;
2521 for (GLint level = 0; level < 7; ++level)
2522 {
2523 ASSERT_LT(0, size);
2524 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2525 nullptr);
2526 size = size / 2;
2527 }
2528 ASSERT_EQ(0, size);
2529 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2530
2531 glActiveTexture(GL_TEXTURE1);
2532 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2533 size = 128;
2534 for (GLint level = 0; level < 8; ++level)
2535 {
2536 ASSERT_LT(0, size);
2537 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2538 nullptr);
2539 size = size / 2;
2540 }
2541 ASSERT_EQ(0, size);
2542 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2543 EXPECT_GL_NO_ERROR();
2544
2545 glUseProgram(mProgram);
2546 glUniform1i(mTexture0Location, 0);
2547 glUniform1i(mTexture1Location, 1);
2548
Olli Etuaho5804dc82018-04-13 14:11:46 +03002549 drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
Olli Etuahobce743a2016-01-15 17:18:28 +02002550 EXPECT_GL_NO_ERROR();
2551 // Red channel: width of level 1 of texture A: 32.
2552 // Green channel: width of level 3 of texture B: 16.
2553 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2554}
2555
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002556// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2557// ES 3.0.4 table 3.24
2558TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2559{
2560 glActiveTexture(GL_TEXTURE0);
2561 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2562 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2563 EXPECT_GL_NO_ERROR();
2564
2565 drawQuad(mProgram, "position", 0.5f);
2566
2567 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2568}
2569
2570// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2571// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002572TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002573{
Luc Ferron5164b792018-03-06 09:10:12 -05002574 setUpProgram();
2575
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002576 glActiveTexture(GL_TEXTURE0);
2577 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2578 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2579 EXPECT_GL_NO_ERROR();
2580
2581 drawQuad(mProgram, "position", 0.5f);
2582
2583 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2584}
2585
Luc Ferron5164b792018-03-06 09:10:12 -05002586// Validate that every component of the pixel will be equal to the luminance value we've set
2587// and that the alpha channel will be 1 (or 255 to be exact).
2588TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2589{
2590 setUpProgram();
2591
2592 glActiveTexture(GL_TEXTURE0);
2593 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2594 uint8_t pixel = 50;
2595 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2596 EXPECT_GL_NO_ERROR();
2597
2598 drawQuad(mProgram, "position", 0.5f);
2599
2600 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2601}
2602
2603// Validate that every component of the pixel will be equal to the luminance value we've set
2604// and that the alpha channel will be the second component.
2605TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2606{
2607 setUpProgram();
2608
2609 glActiveTexture(GL_TEXTURE0);
2610 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2611 uint8_t pixel[] = {50, 25};
2612 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2613 GL_UNSIGNED_BYTE, pixel);
2614 EXPECT_GL_NO_ERROR();
2615
2616 drawQuad(mProgram, "position", 0.5f);
2617
2618 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2619}
2620
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002621// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2622// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002623TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002624{
Jamie Madillb8149072019-04-30 16:14:44 -04002625 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002626 ANGLE_SKIP_TEST_IF(IsD3D9());
2627 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002628
2629 setUpProgram();
2630
Luc Ferrond8c632c2018-04-10 12:31:44 -04002631 glActiveTexture(GL_TEXTURE0);
2632 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2633 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2634 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002635
Luc Ferrond8c632c2018-04-10 12:31:44 -04002636 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002637
Luc Ferrond8c632c2018-04-10 12:31:44 -04002638 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002639}
2640
2641// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2642// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002643TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002644{
Jamie Madillb8149072019-04-30 16:14:44 -04002645 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002646 ANGLE_SKIP_TEST_IF(IsD3D9());
2647 ANGLE_SKIP_TEST_IF(IsVulkan());
2648 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES());
2649 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2650 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002651
Luc Ferrond8c632c2018-04-10 12:31:44 -04002652 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002653
Luc Ferrond8c632c2018-04-10 12:31:44 -04002654 glActiveTexture(GL_TEXTURE0);
2655 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2656 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2657 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002658
Luc Ferrond8c632c2018-04-10 12:31:44 -04002659 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002660
Luc Ferrond8c632c2018-04-10 12:31:44 -04002661 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002662}
2663
2664// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2665// ES 3.0.4 table 3.24
2666TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2667{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002668 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2669
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002670 glActiveTexture(GL_TEXTURE0);
2671 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2672 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2673 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2674 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2675 EXPECT_GL_NO_ERROR();
2676
2677 drawQuad(mProgram, "position", 0.5f);
2678
2679 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2680}
2681
2682// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2683// ES 3.0.4 table 3.24
2684TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2685{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002686 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2687
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002688 glActiveTexture(GL_TEXTURE0);
2689 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2690
2691 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2692 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2693 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2694 EXPECT_GL_NO_ERROR();
2695
2696 drawQuad(mProgram, "position", 0.5f);
2697
2698 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2699}
2700
2701// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2702// ES 3.0.4 table 3.24
2703TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2704{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002705 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2706
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002707 glActiveTexture(GL_TEXTURE0);
2708 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2709 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2710 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2711 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2712 EXPECT_GL_NO_ERROR();
2713
2714 drawQuad(mProgram, "position", 0.5f);
2715
2716 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2717}
2718
2719// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2720// ES 3.0.4 table 3.24
2721TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2722{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002723 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2724
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002725 glActiveTexture(GL_TEXTURE0);
2726 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2727 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2728 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2729 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2730 EXPECT_GL_NO_ERROR();
2731
2732 drawQuad(mProgram, "position", 0.5f);
2733
2734 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2735}
2736
2737// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2738// ES 3.0.4 table 3.24
2739TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2740{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002741 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2742
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002743 glActiveTexture(GL_TEXTURE0);
2744 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2745 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2746 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2747 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2748 EXPECT_GL_NO_ERROR();
2749
2750 drawQuad(mProgram, "position", 0.5f);
2751
2752 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2753}
2754
2755// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2756// ES 3.0.4 table 3.24
2757TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2758{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002759 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2760
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002761 glActiveTexture(GL_TEXTURE0);
2762 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2763 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2764 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2765 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2766 EXPECT_GL_NO_ERROR();
2767
2768 drawQuad(mProgram, "position", 0.5f);
2769
2770 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2771}
2772
2773// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2774// ES 3.0.4 table 3.24
2775TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2776{
2777 glActiveTexture(GL_TEXTURE0);
2778 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2779 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2780 EXPECT_GL_NO_ERROR();
2781
2782 drawQuad(mProgram, "position", 0.5f);
2783
2784 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2785}
2786
2787// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2788// ES 3.0.4 table 3.24
2789TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2790{
2791 glActiveTexture(GL_TEXTURE0);
2792 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2793 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2794 nullptr);
2795 EXPECT_GL_NO_ERROR();
2796
2797 drawQuad(mProgram, "position", 0.5f);
2798
2799 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2800}
2801
2802// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2803// ES 3.0.4 table 3.24
2804TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2805{
Yunchao He9550c602018-02-13 14:47:05 +08002806 // Seems to fail on OSX 10.12 Intel.
2807 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Jamie Madillbb1db482017-01-10 10:48:32 -05002808
Yuly Novikov49886892018-01-23 21:18:27 -05002809 // http://anglebug.com/2190
2810 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2811
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002812 glActiveTexture(GL_TEXTURE0);
2813 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2814 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2815 EXPECT_GL_NO_ERROR();
2816
2817 drawQuad(mProgram, "position", 0.5f);
2818
2819 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2820}
2821
2822// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2823// ES 3.0.4 table 3.24
2824TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2825{
Yunchao He9550c602018-02-13 14:47:05 +08002826 // Seems to fail on OSX 10.12 Intel.
2827 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002828
Yuly Novikov49886892018-01-23 21:18:27 -05002829 // http://anglebug.com/2190
2830 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2831
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002832 glActiveTexture(GL_TEXTURE0);
2833 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2834 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2835 EXPECT_GL_NO_ERROR();
2836
2837 drawQuad(mProgram, "position", 0.5f);
2838
2839 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2840}
2841
Olli Etuaho96963162016-03-21 11:54:33 +02002842// Use a sampler in a uniform struct.
2843TEST_P(SamplerInStructTest, SamplerInStruct)
2844{
2845 runSamplerInStructTest();
2846}
2847
2848// Use a sampler in a uniform struct that's passed as a function parameter.
2849TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2850{
Yuly Novikovd18c0482019-04-04 19:56:43 -04002851 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
2852 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002853
Olli Etuaho96963162016-03-21 11:54:33 +02002854 runSamplerInStructTest();
2855}
2856
2857// Use a sampler in a uniform struct array with a struct from the array passed as a function
2858// parameter.
2859TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2860{
Yuly Novikovd18c0482019-04-04 19:56:43 -04002861 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
2862 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08002863
Olli Etuaho96963162016-03-21 11:54:33 +02002864 runSamplerInStructTest();
2865}
2866
2867// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2868// parameter.
2869TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2870{
Yuly Novikovd18c0482019-04-04 19:56:43 -04002871 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
2872 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08002873
Olli Etuaho96963162016-03-21 11:54:33 +02002874 runSamplerInStructTest();
2875}
2876
2877// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2878// similarly named uniform.
2879TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2880{
2881 runSamplerInStructTest();
2882}
2883
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05002884// GL_EXT_texture_filter_anisotropic
2885class TextureAnisotropyTest : public Texture2DTest
2886{
2887 protected:
2888 void uploadTexture()
2889 {
2890 glActiveTexture(GL_TEXTURE0);
2891 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2892 GLColor texDataRed[1] = {GLColor::red};
2893 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed);
2894 EXPECT_GL_NO_ERROR();
2895 }
2896};
2897
2898// Tests that setting anisotropic filtering doesn't cause failures at draw time.
2899TEST_P(TextureAnisotropyTest, AnisotropyFunctional)
2900{
Jamie Madillb8149072019-04-30 16:14:44 -04002901 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_filter_anisotropic"));
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05002902
2903 setUpProgram();
2904
2905 uploadTexture();
2906
2907 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2908 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2909 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f);
2910 EXPECT_GL_NO_ERROR();
2911
2912 drawQuad(mProgram, "position", 0.5f);
2913
2914 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
2915 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
2916 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::red);
2917}
2918
Till Rathmannb8543632018-10-02 19:46:14 +02002919// GL_OES_texture_border_clamp
2920class TextureBorderClampTest : public Texture2DTest
2921{
2922 protected:
2923 TextureBorderClampTest() : Texture2DTest() {}
2924
Jamie Madill35cd7332018-12-02 12:03:33 -05002925 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02002926 {
2927 return
2928 R"(precision highp float;
2929 attribute vec4 position;
2930 varying vec2 texcoord;
2931
2932 void main()
2933 {
2934 gl_Position = vec4(position.xy, 0.0, 1.0);
2935 // texcoords in [-0.5, 1.5]
2936 texcoord = (position.xy) + 0.5;
2937 })";
2938 }
2939
2940 void uploadTexture()
2941 {
2942 glActiveTexture(GL_TEXTURE0);
2943 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2944 std::vector<GLColor> texDataRed(1, GLColor::red);
2945 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2946 texDataRed.data());
2947 EXPECT_GL_NO_ERROR();
2948 }
2949};
2950
2951// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
2952// GL_CLAMP_TO_BORDER wrap mode (set with glTexParameter).
2953TEST_P(TextureBorderClampTest, TextureBorderClampFunctional)
2954{
Jamie Madillb8149072019-04-30 16:14:44 -04002955 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02002956
2957 setUpProgram();
2958
2959 uploadTexture();
2960
2961 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
2962 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
2963 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2964 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2965 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2966 EXPECT_GL_NO_ERROR();
2967
2968 drawQuad(mProgram, "position", 0.5f);
2969
2970 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
2971 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2972 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
2973}
2974
2975// Test reading back GL_TEXTURE_BORDER_COLOR by glGetTexParameter.
2976TEST_P(TextureBorderClampTest, TextureBorderClampFunctional2)
2977{
Jamie Madillb8149072019-04-30 16:14:44 -04002978 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02002979
2980 glActiveTexture(GL_TEXTURE0);
2981 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2982
2983 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2984
2985 GLint colorFixedPoint[4] = {0};
2986 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
2987 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
2988 std::numeric_limits<GLint>::max()};
2989 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
2990 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
2991 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
2992 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
2993
2994 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
2995 std::numeric_limits<GLint>::max()};
2996 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
2997
2998 GLfloat color[4] = {0.0f};
2999 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
3000 EXPECT_EQ(color[0], kFloatBlue.R);
3001 EXPECT_EQ(color[1], kFloatBlue.G);
3002 EXPECT_EQ(color[2], kFloatBlue.B);
3003 EXPECT_EQ(color[3], kFloatBlue.A);
3004}
3005
3006// Test GL_TEXTURE_BORDER_COLOR parameter validation at glTexParameter.
3007TEST_P(TextureBorderClampTest, TextureBorderClampValidation)
3008{
Jamie Madillb8149072019-04-30 16:14:44 -04003009 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003010
3011 glActiveTexture(GL_TEXTURE0);
3012 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3013
3014 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, 1.0f);
3015 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3016
3017 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3018 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3019
3020 glTexParameterfv(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3021 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3022
3023 GLint colorInt[4] = {0};
3024 glTexParameteriv(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_BORDER_COLOR, colorInt);
3025 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3026
3027 if (getClientMajorVersion() < 3)
3028 {
3029 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3030 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3031 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3032 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3033
3034 GLuint colorUInt[4] = {0};
3035 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3036 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3037 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3038 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3039
3040 GLSampler sampler;
3041 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3042 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3043 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3044 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3045
3046 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3047 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3048 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3049 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3050 }
3051}
3052
3053class TextureBorderClampTestES3 : public TextureBorderClampTest
3054{
3055 protected:
3056 TextureBorderClampTestES3() : TextureBorderClampTest() {}
3057};
3058
3059// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3060// GL_CLAMP_TO_BORDER wrap mode (set with glSamplerParameter).
3061TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional)
3062{
Jamie Madillb8149072019-04-30 16:14:44 -04003063 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003064
3065 setUpProgram();
3066
3067 uploadTexture();
3068
3069 GLSampler sampler;
3070 glBindSampler(0, sampler);
3071 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3072 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3073 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3074 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3075 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3076 EXPECT_GL_NO_ERROR();
3077
3078 drawQuad(mProgram, "position", 0.5f);
3079
3080 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3081 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3082 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3083}
3084
3085// Test reading back GL_TEXTURE_BORDER_COLOR by glGetSamplerParameter.
3086TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional2)
3087{
Jamie Madillb8149072019-04-30 16:14:44 -04003088 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003089
3090 glActiveTexture(GL_TEXTURE0);
3091
3092 GLSampler sampler;
3093 glBindSampler(0, sampler);
3094
3095 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3096
3097 GLint colorFixedPoint[4] = {0};
3098 glGetSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3099 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3100 std::numeric_limits<GLint>::max()};
3101 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3102 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3103 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3104 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3105
3106 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3107 std::numeric_limits<GLint>::max()};
3108 glSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3109
3110 GLfloat color[4] = {0.0f};
3111 glGetSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, color);
3112 EXPECT_EQ(color[0], kFloatBlue.R);
3113 EXPECT_EQ(color[1], kFloatBlue.G);
3114 EXPECT_EQ(color[2], kFloatBlue.B);
3115 EXPECT_EQ(color[3], kFloatBlue.A);
3116
3117 constexpr GLint colorSomewhatRedInt[4] = {500000, 0, 0, std::numeric_limits<GLint>::max()};
3118 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedInt);
3119 GLint colorInt[4] = {0};
3120 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3121 EXPECT_EQ(colorInt[0], colorSomewhatRedInt[0]);
3122 EXPECT_EQ(colorInt[1], colorSomewhatRedInt[1]);
3123 EXPECT_EQ(colorInt[2], colorSomewhatRedInt[2]);
3124 EXPECT_EQ(colorInt[3], colorSomewhatRedInt[3]);
3125
3126 constexpr GLuint colorSomewhatRedUInt[4] = {500000, 0, 0, std::numeric_limits<GLuint>::max()};
3127 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedUInt);
3128 GLuint colorUInt[4] = {0};
3129 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3130 EXPECT_EQ(colorUInt[0], colorSomewhatRedUInt[0]);
3131 EXPECT_EQ(colorUInt[1], colorSomewhatRedUInt[1]);
3132 EXPECT_EQ(colorUInt[2], colorSomewhatRedUInt[2]);
3133 EXPECT_EQ(colorUInt[3], colorSomewhatRedUInt[3]);
3134
3135 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3136
3137 constexpr GLint colorSomewhatGreenInt[4] = {0, 500000, 0, std::numeric_limits<GLint>::max()};
3138 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenInt);
3139 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3140 EXPECT_EQ(colorInt[0], colorSomewhatGreenInt[0]);
3141 EXPECT_EQ(colorInt[1], colorSomewhatGreenInt[1]);
3142 EXPECT_EQ(colorInt[2], colorSomewhatGreenInt[2]);
3143 EXPECT_EQ(colorInt[3], colorSomewhatGreenInt[3]);
3144
3145 constexpr GLuint colorSomewhatGreenUInt[4] = {0, 500000, 0, std::numeric_limits<GLuint>::max()};
3146 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenUInt);
3147 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3148 EXPECT_EQ(colorUInt[0], colorSomewhatGreenUInt[0]);
3149 EXPECT_EQ(colorUInt[1], colorSomewhatGreenUInt[1]);
3150 EXPECT_EQ(colorUInt[2], colorSomewhatGreenUInt[2]);
3151 EXPECT_EQ(colorUInt[3], colorSomewhatGreenUInt[3]);
3152}
3153
3154// Test GL_TEXTURE_BORDER_COLOR parameter validation at glSamplerParameter.
3155TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Validation)
3156{
Jamie Madillb8149072019-04-30 16:14:44 -04003157 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003158
3159 glActiveTexture(GL_TEXTURE0);
3160
3161 GLSampler sampler;
3162 glBindSampler(0, sampler);
3163
3164 glSamplerParameterf(sampler, GL_TEXTURE_BORDER_COLOR, 1.0f);
3165 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3166
3167 glSamplerParameteri(sampler, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3168 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3169}
3170
3171class TextureBorderClampIntegerTestES3 : public Texture2DTest
3172{
3173 protected:
3174 TextureBorderClampIntegerTestES3() : Texture2DTest(), isUnsignedIntTest(false) {}
3175
Jamie Madill35cd7332018-12-02 12:03:33 -05003176 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003177 {
3178 return
3179 R"(#version 300 es
3180 out vec2 texcoord;
3181 in vec4 position;
3182
3183 void main()
3184 {
3185 gl_Position = vec4(position.xy, 0.0, 1.0);
3186 // texcoords in [-0.5, 1.5]
3187 texcoord = (position.xy) + 0.5;
3188 })";
3189 }
3190
Jamie Madillba319ba2018-12-29 10:29:33 -05003191 const char *getFragmentShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003192 {
Jamie Madill35cd7332018-12-02 12:03:33 -05003193 if (isUnsignedIntTest)
3194 {
3195 return "#version 300 es\n"
3196 "precision highp float;\n"
3197 "uniform highp usampler2D tex;\n"
3198 "in vec2 texcoord;\n"
3199 "out vec4 fragColor;\n"
Till Rathmannb8543632018-10-02 19:46:14 +02003200
Jamie Madill35cd7332018-12-02 12:03:33 -05003201 "void main()\n"
3202 "{\n"
3203 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3204 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3205 "fragColor = (texture(tex, texcoord).r == 150u)"
3206 " ? green : red;\n"
3207 "}\n";
3208 }
3209 else
3210 {
3211 return "#version 300 es\n"
3212 "precision highp float;\n"
3213 "uniform highp isampler2D tex;\n"
3214 "in vec2 texcoord;\n"
3215 "out vec4 fragColor;\n"
3216
3217 "void main()\n"
3218 "{\n"
3219 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3220 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3221 "fragColor = (texture(tex, texcoord).r == -50)"
3222 " ? green : red;\n"
3223 "}\n";
3224 }
Till Rathmannb8543632018-10-02 19:46:14 +02003225 }
3226
3227 void uploadTexture()
3228 {
3229 glActiveTexture(GL_TEXTURE0);
3230 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3231 if (isUnsignedIntTest)
3232 {
3233 std::vector<GLubyte> texData(4, 100);
3234 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE,
3235 texData.data());
3236 }
3237 else
3238 {
3239 std::vector<GLbyte> texData(4, 100);
3240 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8I, 1, 1, 0, GL_RGBA_INTEGER, GL_BYTE,
3241 texData.data());
3242 }
3243 EXPECT_GL_NO_ERROR();
3244 }
3245
3246 bool isUnsignedIntTest;
3247};
3248
3249// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3250// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3251TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger)
3252{
Jamie Madillb8149072019-04-30 16:14:44 -04003253 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003254
3255 setUpProgram();
3256
3257 uploadTexture();
3258
3259 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3260 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3261 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3262 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3263
3264 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3265 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3266
3267 EXPECT_GL_NO_ERROR();
3268
3269 drawQuad(mProgram, "position", 0.5f);
3270
3271 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3272 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3273 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3274}
3275
3276// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3277// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3278TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger2)
3279{
Jamie Madillb8149072019-04-30 16:14:44 -04003280 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003281
3282 setUpProgram();
3283
3284 uploadTexture();
3285
3286 GLSampler sampler;
3287 glBindSampler(0, sampler);
3288 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3289 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3290 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3291 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3292
3293 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3294 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3295
3296 EXPECT_GL_NO_ERROR();
3297
3298 drawQuad(mProgram, "position", 0.5f);
3299
3300 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3301 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3302 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3303}
3304
3305// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3306// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIuivOES).
3307TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned)
3308{
Jamie Madillb8149072019-04-30 16:14:44 -04003309 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003310
3311 isUnsignedIntTest = true;
3312
3313 setUpProgram();
3314
3315 uploadTexture();
3316
3317 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3318 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3319 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3320 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3321
3322 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3323 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3324
3325 EXPECT_GL_NO_ERROR();
3326
3327 drawQuad(mProgram, "position", 0.5f);
3328
3329 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3330 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3331 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3332}
3333
3334// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3335// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with
3336// glSamplerParameterIuivOES).
3337TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned2)
3338{
Jamie Madillb8149072019-04-30 16:14:44 -04003339 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003340
3341 isUnsignedIntTest = true;
3342
3343 setUpProgram();
3344
3345 uploadTexture();
3346
3347 GLSampler sampler;
3348 glBindSampler(0, sampler);
3349 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3350 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3351 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3352 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3353
3354 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3355 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3356
3357 EXPECT_GL_NO_ERROR();
3358
3359 drawQuad(mProgram, "position", 0.5f);
3360
3361 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3362 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3363 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3364}
3365
3366// ~GL_OES_texture_border_clamp
3367
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003368class TextureLimitsTest : public ANGLETest
3369{
3370 protected:
3371 struct RGBA8
3372 {
3373 uint8_t R, G, B, A;
3374 };
3375
3376 TextureLimitsTest()
3377 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
3378 {
3379 setWindowWidth(128);
3380 setWindowHeight(128);
3381 setConfigRedBits(8);
3382 setConfigGreenBits(8);
3383 setConfigBlueBits(8);
3384 setConfigAlphaBits(8);
3385 }
3386
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003387 void testSetUp() override
Jamie Madill0fdb9562018-09-17 17:18:43 -04003388 {
Jamie Madill0fdb9562018-09-17 17:18:43 -04003389 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
3390 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
3391 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
3392
3393 ASSERT_GL_NO_ERROR();
3394 }
3395
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003396 void testTearDown() override
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003397 {
3398 if (mProgram != 0)
3399 {
3400 glDeleteProgram(mProgram);
3401 mProgram = 0;
3402
3403 if (!mTextures.empty())
3404 {
3405 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
3406 }
3407 }
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003408 }
3409
3410 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
3411 GLint vertexTextureCount,
3412 GLint vertexActiveTextureCount,
3413 const std::string &fragPrefix,
3414 GLint fragmentTextureCount,
3415 GLint fragmentActiveTextureCount)
3416 {
3417 std::stringstream vertexShaderStr;
3418 vertexShaderStr << "attribute vec2 position;\n"
3419 << "varying vec4 color;\n"
3420 << "varying vec2 texCoord;\n";
3421
3422 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
3423 {
3424 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
3425 }
3426
3427 vertexShaderStr << "void main() {\n"
3428 << " gl_Position = vec4(position, 0, 1);\n"
3429 << " texCoord = (position * 0.5) + 0.5;\n"
3430 << " color = vec4(0);\n";
3431
3432 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
3433 {
3434 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
3435 << ", texCoord);\n";
3436 }
3437
3438 vertexShaderStr << "}";
3439
3440 std::stringstream fragmentShaderStr;
3441 fragmentShaderStr << "varying mediump vec4 color;\n"
3442 << "varying mediump vec2 texCoord;\n";
3443
3444 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
3445 {
3446 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
3447 }
3448
3449 fragmentShaderStr << "void main() {\n"
3450 << " gl_FragColor = color;\n";
3451
3452 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
3453 {
3454 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
3455 << ", texCoord);\n";
3456 }
3457
3458 fragmentShaderStr << "}";
3459
3460 const std::string &vertexShaderSource = vertexShaderStr.str();
3461 const std::string &fragmentShaderSource = fragmentShaderStr.str();
3462
Jamie Madill35cd7332018-12-02 12:03:33 -05003463 mProgram = CompileProgram(vertexShaderSource.c_str(), fragmentShaderSource.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003464 }
3465
3466 RGBA8 getPixel(GLint texIndex)
3467 {
3468 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3469 0, 255u};
3470 return pixel;
3471 }
3472
3473 void initTextures(GLint tex2DCount, GLint texCubeCount)
3474 {
3475 GLint totalCount = tex2DCount + texCubeCount;
3476 mTextures.assign(totalCount, 0);
3477 glGenTextures(totalCount, &mTextures[0]);
3478 ASSERT_GL_NO_ERROR();
3479
3480 std::vector<RGBA8> texData(16 * 16);
3481
3482 GLint texIndex = 0;
3483 for (; texIndex < tex2DCount; ++texIndex)
3484 {
3485 texData.assign(texData.size(), getPixel(texIndex));
3486 glActiveTexture(GL_TEXTURE0 + texIndex);
3487 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3488 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3489 &texData[0]);
3490 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3491 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3492 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3493 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3494 }
3495
3496 ASSERT_GL_NO_ERROR();
3497
3498 for (; texIndex < texCubeCount; ++texIndex)
3499 {
3500 texData.assign(texData.size(), getPixel(texIndex));
3501 glActiveTexture(GL_TEXTURE0 + texIndex);
3502 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3503 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3504 GL_UNSIGNED_BYTE, &texData[0]);
3505 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3506 GL_UNSIGNED_BYTE, &texData[0]);
3507 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3508 GL_UNSIGNED_BYTE, &texData[0]);
3509 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3510 GL_UNSIGNED_BYTE, &texData[0]);
3511 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3512 GL_UNSIGNED_BYTE, &texData[0]);
3513 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3514 GL_UNSIGNED_BYTE, &texData[0]);
3515 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3516 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3517 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3518 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3519 }
3520
3521 ASSERT_GL_NO_ERROR();
3522 }
3523
3524 void testWithTextures(GLint vertexTextureCount,
3525 const std::string &vertexTexturePrefix,
3526 GLint fragmentTextureCount,
3527 const std::string &fragmentTexturePrefix)
3528 {
3529 // Generate textures
3530 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3531
3532 glUseProgram(mProgram);
3533 RGBA8 expectedSum = {0};
3534 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3535 {
3536 std::stringstream uniformNameStr;
3537 uniformNameStr << vertexTexturePrefix << texIndex;
3538 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003539 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003540 ASSERT_NE(-1, location);
3541
3542 glUniform1i(location, texIndex);
3543 RGBA8 contribution = getPixel(texIndex);
3544 expectedSum.R += contribution.R;
3545 expectedSum.G += contribution.G;
3546 }
3547
3548 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3549 {
3550 std::stringstream uniformNameStr;
3551 uniformNameStr << fragmentTexturePrefix << texIndex;
3552 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003553 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003554 ASSERT_NE(-1, location);
3555
3556 glUniform1i(location, texIndex + vertexTextureCount);
3557 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3558 expectedSum.R += contribution.R;
3559 expectedSum.G += contribution.G;
3560 }
3561
3562 ASSERT_GE(256u, expectedSum.G);
3563
3564 drawQuad(mProgram, "position", 0.5f);
3565 ASSERT_GL_NO_ERROR();
3566 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3567 }
3568
3569 GLuint mProgram;
3570 std::vector<GLuint> mTextures;
3571 GLint mMaxVertexTextures;
3572 GLint mMaxFragmentTextures;
3573 GLint mMaxCombinedTextures;
3574};
3575
3576// Test rendering with the maximum vertex texture units.
3577TEST_P(TextureLimitsTest, MaxVertexTextures)
3578{
3579 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3580 ASSERT_NE(0u, mProgram);
3581 ASSERT_GL_NO_ERROR();
3582
3583 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3584}
3585
3586// Test rendering with the maximum fragment texture units.
3587TEST_P(TextureLimitsTest, MaxFragmentTextures)
3588{
3589 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3590 ASSERT_NE(0u, mProgram);
3591 ASSERT_GL_NO_ERROR();
3592
3593 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3594}
3595
3596// Test rendering with maximum combined texture units.
3597TEST_P(TextureLimitsTest, MaxCombinedTextures)
3598{
3599 GLint vertexTextures = mMaxVertexTextures;
3600
3601 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3602 {
3603 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3604 }
3605
3606 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3607 mMaxFragmentTextures, mMaxFragmentTextures);
3608 ASSERT_NE(0u, mProgram);
3609 ASSERT_GL_NO_ERROR();
3610
3611 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3612}
3613
3614// Negative test for exceeding the number of vertex textures
3615TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3616{
3617 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3618 0);
3619 ASSERT_EQ(0u, mProgram);
3620}
3621
3622// Negative test for exceeding the number of fragment textures
3623TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3624{
3625 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3626 mMaxFragmentTextures + 1);
3627 ASSERT_EQ(0u, mProgram);
3628}
3629
3630// Test active vertex textures under the limit, but excessive textures specified.
3631TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3632{
3633 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3634 ASSERT_NE(0u, mProgram);
3635 ASSERT_GL_NO_ERROR();
3636
3637 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3638}
3639
3640// Test active fragment textures under the limit, but excessive textures specified.
3641TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3642{
3643 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3644 mMaxFragmentTextures);
3645 ASSERT_NE(0u, mProgram);
3646 ASSERT_GL_NO_ERROR();
3647
3648 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3649}
3650
3651// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003652// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003653TEST_P(TextureLimitsTest, TextureTypeConflict)
3654{
Jamie Madill35cd7332018-12-02 12:03:33 -05003655 constexpr char kVS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003656 "attribute vec2 position;\n"
3657 "varying float color;\n"
3658 "uniform sampler2D tex2D;\n"
3659 "uniform samplerCube texCube;\n"
3660 "void main() {\n"
3661 " gl_Position = vec4(position, 0, 1);\n"
3662 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3663 " color = texture2D(tex2D, texCoord).x;\n"
3664 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3665 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05003666 constexpr char kFS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003667 "varying mediump float color;\n"
3668 "void main() {\n"
3669 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3670 "}";
3671
Jamie Madill35cd7332018-12-02 12:03:33 -05003672 mProgram = CompileProgram(kVS, kFS);
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003673 ASSERT_NE(0u, mProgram);
3674
3675 initTextures(1, 0);
3676
3677 glUseProgram(mProgram);
3678 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3679 ASSERT_NE(-1, tex2DLocation);
3680 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3681 ASSERT_NE(-1, texCubeLocation);
3682
3683 glUniform1i(tex2DLocation, 0);
3684 glUniform1i(texCubeLocation, 0);
3685 ASSERT_GL_NO_ERROR();
3686
3687 drawQuad(mProgram, "position", 0.5f);
3688 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3689}
3690
Vincent Lang25ab4512016-05-13 18:13:59 +02003691class Texture2DNorm16TestES3 : public Texture2DTestES3
3692{
3693 protected:
3694 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3695
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003696 void testSetUp() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003697 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003698 Texture2DTestES3::testSetUp();
Vincent Lang25ab4512016-05-13 18:13:59 +02003699
3700 glActiveTexture(GL_TEXTURE0);
3701 glGenTextures(3, mTextures);
3702 glGenFramebuffers(1, &mFBO);
3703 glGenRenderbuffers(1, &mRenderbuffer);
3704
3705 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3706 {
3707 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3708 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3709 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3710 }
3711
3712 glBindTexture(GL_TEXTURE_2D, 0);
3713
3714 ASSERT_GL_NO_ERROR();
3715 }
3716
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003717 void testTearDown() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003718 {
3719 glDeleteTextures(3, mTextures);
3720 glDeleteFramebuffers(1, &mFBO);
3721 glDeleteRenderbuffers(1, &mRenderbuffer);
3722
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003723 Texture2DTestES3::testTearDown();
Vincent Lang25ab4512016-05-13 18:13:59 +02003724 }
3725
3726 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3727 {
Geoff Langf607c602016-09-21 11:46:48 -04003728 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3729 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003730
3731 setUpProgram();
3732
3733 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3734 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3735 0);
3736
3737 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3738 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3739
3740 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003741 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003742
3743 EXPECT_GL_NO_ERROR();
3744
3745 drawQuad(mProgram, "position", 0.5f);
3746
Geoff Langf607c602016-09-21 11:46:48 -04003747 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003748
Jamie Madill50cf2be2018-06-15 09:46:57 -04003749 EXPECT_PIXEL_COLOR_EQ(0, 0,
3750 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3751 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003752
3753 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3754
3755 ASSERT_GL_NO_ERROR();
3756 }
3757
3758 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3759 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04003760 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003761 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003762
3763 setUpProgram();
3764
3765 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3766 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3767
3768 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3769 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3770 0);
3771
3772 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003773 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003774
3775 EXPECT_GL_NO_ERROR();
3776
3777 drawQuad(mProgram, "position", 0.5f);
3778
Geoff Langf607c602016-09-21 11:46:48 -04003779 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
Jamie Madill50cf2be2018-06-15 09:46:57 -04003780 EXPECT_PIXEL_COLOR_EQ(0, 0,
3781 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3782 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003783
3784 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3785 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3786 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3787 mRenderbuffer);
3788 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3789 EXPECT_GL_NO_ERROR();
3790
3791 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3792 glClear(GL_COLOR_BUFFER_BIT);
3793
3794 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3795
Geoff Langf607c602016-09-21 11:46:48 -04003796 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003797
3798 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3799
3800 ASSERT_GL_NO_ERROR();
3801 }
3802
3803 GLuint mTextures[3];
3804 GLuint mFBO;
3805 GLuint mRenderbuffer;
3806};
3807
3808// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3809TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3810{
Jamie Madillb8149072019-04-30 16:14:44 -04003811 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02003812
3813 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3814 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3815 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3816 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3817 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3818 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3819 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3820 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3821
3822 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3823 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3824 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3825}
3826
Olli Etuaho95faa232016-06-07 14:01:53 -07003827// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3828// GLES 3.0.4 section 3.8.3.
3829TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3830{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003831 // Crashes on Nexus 5X due to a driver bug. http://anglebug.com/1429
3832 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07003833
3834 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3835 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3836 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3837 ASSERT_GL_NO_ERROR();
3838
3839 // SKIP_IMAGES should not have an effect on uploading 2D textures
3840 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3841 ASSERT_GL_NO_ERROR();
3842
3843 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3844
3845 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3846 pixelsGreen.data());
3847 ASSERT_GL_NO_ERROR();
3848
3849 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3850 pixelsGreen.data());
3851 ASSERT_GL_NO_ERROR();
3852
3853 glUseProgram(mProgram);
3854 drawQuad(mProgram, "position", 0.5f);
3855 ASSERT_GL_NO_ERROR();
3856
3857 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3858}
3859
Olli Etuaho989cac32016-06-08 16:18:49 -07003860// Test that skip defined in unpack parameters is taken into account when determining whether
3861// unpacking source extends outside unpack buffer bounds.
3862TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3863{
3864 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3865 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3866 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3867 ASSERT_GL_NO_ERROR();
3868
3869 GLBuffer buf;
3870 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3871 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3872 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3873 GL_DYNAMIC_COPY);
3874 ASSERT_GL_NO_ERROR();
3875
3876 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3877 ASSERT_GL_NO_ERROR();
3878
3879 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3880 ASSERT_GL_NO_ERROR();
3881
3882 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3883 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3884
3885 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3886 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3887 ASSERT_GL_NO_ERROR();
3888
3889 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3890 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3891}
3892
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003893// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3894TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3895{
Yunchao He9550c602018-02-13 14:47:05 +08003896 ANGLE_SKIP_TEST_IF(IsD3D11());
3897
3898 // Incorrect rendering results seen on OSX AMD.
3899 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003900
3901 const GLuint width = 8u;
3902 const GLuint height = 8u;
3903 const GLuint unpackRowLength = 5u;
3904 const GLuint unpackSkipPixels = 1u;
3905
3906 setWindowWidth(width);
3907 setWindowHeight(height);
3908
3909 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3910 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3911 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3912 ASSERT_GL_NO_ERROR();
3913
3914 GLBuffer buf;
3915 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3916 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3917 GLColor::green);
3918
3919 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3920 {
3921 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3922 }
3923
3924 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3925 GL_DYNAMIC_COPY);
3926 ASSERT_GL_NO_ERROR();
3927
3928 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3929 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3930 ASSERT_GL_NO_ERROR();
3931
3932 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3933 ASSERT_GL_NO_ERROR();
3934
3935 glUseProgram(mProgram);
3936 drawQuad(mProgram, "position", 0.5f);
3937 ASSERT_GL_NO_ERROR();
3938
3939 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3940 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3941 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3942 actual.data());
3943 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3944 EXPECT_EQ(expected, actual);
3945}
3946
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003947template <typename T>
3948T UNorm(double value)
3949{
3950 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3951}
3952
3953// Test rendering a depth texture with mipmaps.
3954TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3955{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003956 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3957 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
Jiawei Shaoaf0f31d2018-09-27 15:42:31 +08003958 // http://anglebug.com/1706
3959 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Corentin Walleze731d8a2016-09-07 10:56:25 -04003960
Jamie Madill24980272019-04-03 09:03:51 -04003961 // Seems to fail on AMD D3D11. Possibly driver bug. http://anglebug.com/3342
3962 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsD3D11());
3963
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003964 const int size = getWindowWidth();
3965
3966 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003967 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003968
3969 glActiveTexture(GL_TEXTURE0);
3970 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3971 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3972 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3973 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3974 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3975 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3976 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3977 ASSERT_GL_NO_ERROR();
3978
3979 glUseProgram(mProgram);
3980 glUniform1i(mTexture2DUniformLocation, 0);
3981
3982 std::vector<unsigned char> expected;
3983
3984 for (int level = 0; level < levels; ++level)
3985 {
3986 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3987 expected.push_back(UNorm<unsigned char>(value));
3988
3989 int levelDim = dim(level);
3990
3991 ASSERT_GT(levelDim, 0);
3992
3993 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3994 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3995 GL_UNSIGNED_INT, initData.data());
3996 }
3997 ASSERT_GL_NO_ERROR();
3998
3999 for (int level = 0; level < levels; ++level)
4000 {
4001 glViewport(0, 0, dim(level), dim(level));
4002 drawQuad(mProgram, "position", 0.5f);
4003 GLColor actual = ReadColor(0, 0);
4004 EXPECT_NEAR(expected[level], actual.R, 10u);
4005 }
4006
4007 ASSERT_GL_NO_ERROR();
4008}
4009
Jamie Madill7ffdda92016-09-08 13:26:51 -04004010// Tests unpacking into the unsized GL_ALPHA format.
4011TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
4012{
Jamie Madill7ffdda92016-09-08 13:26:51 -04004013 // Initialize the texure.
4014 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4015 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
4016 GL_UNSIGNED_BYTE, nullptr);
4017 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4018 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4019
4020 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
4021
4022 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04004023 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04004024 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4025 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4026 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
4027 GL_STATIC_DRAW);
4028
4029 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
4030 GL_UNSIGNED_BYTE, nullptr);
4031
4032 // Clear to a weird color to make sure we're drawing something.
4033 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
4034 glClear(GL_COLOR_BUFFER_BIT);
4035
4036 // Draw with the alpha texture and verify.
4037 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04004038
4039 ASSERT_GL_NO_ERROR();
4040 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
4041}
4042
Jamie Madill2e600342016-09-19 13:56:40 -04004043// Ensure stale unpack data doesn't propagate in D3D11.
4044TEST_P(Texture2DTestES3, StaleUnpackData)
4045{
4046 // Init unpack buffer.
4047 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
4048 std::vector<GLColor> pixels(pixelCount, GLColor::red);
4049
4050 GLBuffer unpackBuffer;
4051 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4052 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4053 GLsizei bufferSize = pixelCount * sizeof(GLColor);
4054 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
4055
4056 // Create from unpack buffer.
4057 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4058 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
4059 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4060 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4061 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4062
4063 drawQuad(mProgram, "position", 0.5f);
4064
4065 ASSERT_GL_NO_ERROR();
4066 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4067
4068 // Fill unpack with green, recreating buffer.
4069 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
4070 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
4071 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
4072
4073 // Reinit texture with green.
4074 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
4075 GL_UNSIGNED_BYTE, nullptr);
4076
4077 drawQuad(mProgram, "position", 0.5f);
4078
4079 ASSERT_GL_NO_ERROR();
4080 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
4081}
4082
Geoff Langfb7685f2017-11-13 11:44:11 -05004083// Ensure that texture parameters passed as floats that are converted to ints are rounded before
4084// validating they are less than 0.
4085TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
4086{
4087 GLTexture texture;
4088 glBindTexture(GL_TEXTURE_2D, texture);
4089
4090 // Use a negative number that will round to zero when converted to an integer
4091 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
4092 // "Validation of values performed by state-setting commands is performed after conversion,
4093 // unless specified otherwise for a specific command."
4094 GLfloat param = -7.30157126e-07f;
4095 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
4096 EXPECT_GL_NO_ERROR();
4097
4098 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
4099 EXPECT_GL_NO_ERROR();
4100}
4101
Jamie Madillf097e232016-11-05 00:44:15 -04004102// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
4103// being properly checked, and the texture storage of the previous texture format was persisting.
4104// This would result in an ASSERT in debug and incorrect rendering in release.
4105// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
4106TEST_P(Texture3DTestES3, FormatRedefinitionBug)
4107{
4108 GLTexture tex;
4109 glBindTexture(GL_TEXTURE_3D, tex.get());
4110 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4111
4112 GLFramebuffer framebuffer;
4113 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
4114 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
4115
4116 glCheckFramebufferStatus(GL_FRAMEBUFFER);
4117
4118 std::vector<uint8_t> pixelData(100, 0);
4119
4120 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
4121 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
4122 pixelData.data());
4123
4124 ASSERT_GL_NO_ERROR();
4125}
4126
Corentin Wallezd2627992017-04-28 17:17:03 -04004127// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
4128TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
4129{
4130 // 2D tests
4131 {
4132 GLTexture tex;
4133 glBindTexture(GL_TEXTURE_2D, tex.get());
4134
4135 GLBuffer pbo;
4136 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4137
4138 // Test OOB
4139 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
4140 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4141 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4142
4143 // Test OOB
4144 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
4145 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4146 ASSERT_GL_NO_ERROR();
4147 }
4148
4149 // 3D tests
4150 {
4151 GLTexture tex;
4152 glBindTexture(GL_TEXTURE_3D, tex.get());
4153
4154 GLBuffer pbo;
4155 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4156
4157 // Test OOB
4158 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
4159 GL_STATIC_DRAW);
4160 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4161 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4162
4163 // Test OOB
4164 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
4165 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4166 ASSERT_GL_NO_ERROR();
4167 }
4168}
4169
Jamie Madill3ed60422017-09-07 11:32:52 -04004170// Tests behaviour with a single texture and multiple sampler objects.
4171TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
4172{
4173 GLint maxTextureUnits = 0;
4174 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
4175 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
4176
4177 constexpr int kSize = 16;
4178
4179 // Make a single-level texture, fill it with red.
4180 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
4181 GLTexture tex;
4182 glBindTexture(GL_TEXTURE_2D, tex);
4183 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4184 redColors.data());
4185 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4186 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4187
4188 // Simple sanity check.
4189 draw2DTexturedQuad(0.5f, 1.0f, true);
4190 ASSERT_GL_NO_ERROR();
4191 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4192
4193 // Bind texture to unit 1 with a sampler object making it incomplete.
4194 GLSampler sampler;
4195 glBindSampler(0, sampler);
4196 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4197 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4198
4199 // Make a mipmap texture, fill it with blue.
4200 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
4201 GLTexture mipmapTex;
4202 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4203 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4204 blueColors.data());
4205 glGenerateMipmap(GL_TEXTURE_2D);
4206
4207 // Draw with the sampler, expect blue.
4208 draw2DTexturedQuad(0.5f, 1.0f, true);
4209 ASSERT_GL_NO_ERROR();
4210 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
4211
4212 // Simple multitexturing program.
Jamie Madill35cd7332018-12-02 12:03:33 -05004213 constexpr char kVS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004214 "#version 300 es\n"
4215 "in vec2 position;\n"
4216 "out vec2 texCoord;\n"
4217 "void main()\n"
4218 "{\n"
4219 " gl_Position = vec4(position, 0, 1);\n"
4220 " texCoord = position * 0.5 + vec2(0.5);\n"
4221 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05004222
4223 constexpr char kFS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004224 "#version 300 es\n"
4225 "precision mediump float;\n"
4226 "in vec2 texCoord;\n"
4227 "uniform sampler2D tex1;\n"
4228 "uniform sampler2D tex2;\n"
4229 "uniform sampler2D tex3;\n"
4230 "uniform sampler2D tex4;\n"
4231 "out vec4 color;\n"
4232 "void main()\n"
4233 "{\n"
4234 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
4235 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
4236 "}";
4237
Jamie Madill35cd7332018-12-02 12:03:33 -05004238 ANGLE_GL_PROGRAM(program, kVS, kFS);
Jamie Madill3ed60422017-09-07 11:32:52 -04004239
4240 std::array<GLint, 4> texLocations = {
4241 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
4242 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
4243 for (GLint location : texLocations)
4244 {
4245 ASSERT_NE(-1, location);
4246 }
4247
4248 // Init the uniform data.
4249 glUseProgram(program);
4250 for (GLint location = 0; location < 4; ++location)
4251 {
4252 glUniform1i(texLocations[location], location);
4253 }
4254
4255 // Initialize four samplers
4256 GLSampler samplers[4];
4257
4258 // 0: non-mipped.
4259 glBindSampler(0, samplers[0]);
4260 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4261 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4262
4263 // 1: mipped.
4264 glBindSampler(1, samplers[1]);
4265 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4266 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4267
4268 // 2: non-mipped.
4269 glBindSampler(2, samplers[2]);
4270 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4271 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4272
4273 // 3: mipped.
4274 glBindSampler(3, samplers[3]);
4275 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4276 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4277
4278 // Bind two blue mipped textures and two single layer textures, should all draw.
4279 glActiveTexture(GL_TEXTURE0);
4280 glBindTexture(GL_TEXTURE_2D, tex);
4281
4282 glActiveTexture(GL_TEXTURE1);
4283 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4284
4285 glActiveTexture(GL_TEXTURE2);
4286 glBindTexture(GL_TEXTURE_2D, tex);
4287
4288 glActiveTexture(GL_TEXTURE3);
4289 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4290
4291 ASSERT_GL_NO_ERROR();
4292
4293 drawQuad(program, "position", 0.5f);
4294 ASSERT_GL_NO_ERROR();
4295 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
4296
4297 // Bind four single layer textures, two should be incomplete.
4298 glActiveTexture(GL_TEXTURE1);
4299 glBindTexture(GL_TEXTURE_2D, tex);
4300
4301 glActiveTexture(GL_TEXTURE3);
4302 glBindTexture(GL_TEXTURE_2D, tex);
4303
4304 drawQuad(program, "position", 0.5f);
4305 ASSERT_GL_NO_ERROR();
4306 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
4307}
4308
Martin Radev7e2c0d32017-09-15 14:25:42 +03004309// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
4310// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
4311// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
4312// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
4313// samples the cubemap using a direction vector (1,1,1).
4314TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
4315{
Yunchao He2f23f352018-02-11 22:11:37 +08004316 // Check http://anglebug.com/2155.
4317 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
4318
Jamie Madill35cd7332018-12-02 12:03:33 -05004319 constexpr char kVS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004320 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004321 precision mediump float;
4322 in vec3 pos;
4323 void main() {
4324 gl_Position = vec4(pos, 1.0);
4325 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03004326
Jamie Madill35cd7332018-12-02 12:03:33 -05004327 constexpr char kFS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004328 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004329 precision mediump float;
4330 out vec4 color;
4331 uniform samplerCube uTex;
4332 void main(){
4333 color = texture(uTex, vec3(1.0));
4334 })";
Jamie Madill35cd7332018-12-02 12:03:33 -05004335
4336 ANGLE_GL_PROGRAM(program, kVS, kFS);
Martin Radev7e2c0d32017-09-15 14:25:42 +03004337 glUseProgram(program);
4338
4339 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
4340 glActiveTexture(GL_TEXTURE0);
4341
4342 GLTexture cubeTex;
4343 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
4344
4345 const int kFaceWidth = 1;
4346 const int kFaceHeight = 1;
4347 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
4348 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4349 GL_UNSIGNED_BYTE, texData.data());
4350 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4351 GL_UNSIGNED_BYTE, texData.data());
4352 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4353 GL_UNSIGNED_BYTE, texData.data());
4354 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4355 GL_UNSIGNED_BYTE, texData.data());
4356 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4357 GL_UNSIGNED_BYTE, texData.data());
4358 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4359 GL_UNSIGNED_BYTE, texData.data());
4360 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4361 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4362 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
4363 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
4364 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
4365 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
4366
4367 drawQuad(program, "pos", 0.5f, 1.0f, true);
4368 ASSERT_GL_NO_ERROR();
4369
4370 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4371}
4372
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08004373// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
4374TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
4375{
4376 GLuint texture = create2DTexture();
4377
4378 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
4379 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4380
4381 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
4382 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4383
4384 glDeleteTextures(1, &texture);
4385 EXPECT_GL_NO_ERROR();
4386}
4387
Olli Etuaho023371b2018-04-24 17:43:32 +03004388// Test setting base level after calling generateMipmap on a LUMA texture.
4389// Covers http://anglebug.com/2498
4390TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA)
4391{
4392 glActiveTexture(GL_TEXTURE0);
4393 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4394
4395 constexpr const GLsizei kWidth = 8;
4396 constexpr const GLsizei kHeight = 8;
4397 std::array<GLubyte, kWidth * kHeight * 2> whiteData;
4398 whiteData.fill(255u);
4399
4400 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA,
4401 GL_UNSIGNED_BYTE, whiteData.data());
4402 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
4403 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4404 glGenerateMipmap(GL_TEXTURE_2D);
4405 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
4406 EXPECT_GL_NO_ERROR();
4407
4408 drawQuad(mProgram, "position", 0.5f);
4409 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4410}
4411
Till Rathmannc1551dc2018-08-15 17:04:49 +02004412// Covers a bug in the D3D11 backend: http://anglebug.com/2772
4413// When using a sampler the texture was created as if it has mipmaps,
4414// regardless what you specified in GL_TEXTURE_MIN_FILTER via
4415// glSamplerParameteri() -- mistakenly the default value
4416// GL_NEAREST_MIPMAP_LINEAR or the value set via glTexParameteri() was
4417// evaluated.
4418// If you didn't provide mipmaps and didn't let the driver generate them
4419// this led to not sampling your texture data when minification occurred.
4420TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping)
4421{
Jamie Madill35cd7332018-12-02 12:03:33 -05004422 constexpr char kVS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004423 "#version 300 es\n"
4424 "out vec2 texcoord;\n"
4425 "in vec4 position;\n"
4426 "void main()\n"
4427 "{\n"
4428 " gl_Position = vec4(position.xy * 0.1, 0.0, 1.0);\n"
4429 " texcoord = (position.xy * 0.5) + 0.5;\n"
4430 "}\n";
4431
Jamie Madill35cd7332018-12-02 12:03:33 -05004432 constexpr char kFS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004433 "#version 300 es\n"
4434 "precision highp float;\n"
4435 "uniform highp sampler2D tex;\n"
4436 "in vec2 texcoord;\n"
4437 "out vec4 fragColor;\n"
4438 "void main()\n"
4439 "{\n"
4440 " fragColor = texture(tex, texcoord);\n"
4441 "}\n";
Jamie Madill35cd7332018-12-02 12:03:33 -05004442
4443 ANGLE_GL_PROGRAM(program, kVS, kFS);
Till Rathmannc1551dc2018-08-15 17:04:49 +02004444
4445 GLSampler sampler;
4446 glBindSampler(0, sampler);
4447 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4448 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4449
4450 glActiveTexture(GL_TEXTURE0);
4451 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4452
4453 const GLsizei texWidth = getWindowWidth();
4454 const GLsizei texHeight = getWindowHeight();
4455 const std::vector<GLColor> whiteData(texWidth * texHeight, GLColor::white);
4456
4457 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4458 whiteData.data());
4459 EXPECT_GL_NO_ERROR();
4460
4461 drawQuad(program, "position", 0.5f);
4462 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, angle::GLColor::white);
4463}
4464
Anders Leinof6cbe442019-04-18 15:32:07 +03004465// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4466// texture is output.
4467TEST_P(Texture2DIntegerTestES3, IntegerTextureNonZeroBaseLevel)
4468{
4469 glActiveTexture(GL_TEXTURE0);
4470 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4471 int width = getWindowWidth();
4472 int height = getWindowHeight();
4473 GLColor color = GLColor::green;
4474 std::vector<GLColor> pixels(width * height, color);
4475 GLint baseLevel = 1;
4476 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
4477 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4478 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4479 glTexImage2D(GL_TEXTURE_2D, baseLevel, GL_RGBA8UI, width, height, 0, GL_RGBA_INTEGER,
4480 GL_UNSIGNED_BYTE, pixels.data());
4481
4482 setUpProgram();
4483 glUseProgram(mProgram);
4484 glUniform1i(mTexture2DUniformLocation, 0);
4485 drawQuad(mProgram, "position", 0.5f);
4486
4487 EXPECT_GL_NO_ERROR();
4488 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4489 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4490}
4491
Jamie Madill50cf2be2018-06-15 09:46:57 -04004492// Use this to select which configurations (e.g. which renderer, which GLES major version) these
4493// tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -05004494ANGLE_INSTANTIATE_TEST(Texture2DTest,
4495 ES2_D3D9(),
4496 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004497 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05004498 ES2_OPENGLES(),
4499 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004500ANGLE_INSTANTIATE_TEST(TextureCubeTest,
4501 ES2_D3D9(),
4502 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004503 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004504 ES2_OPENGLES(),
4505 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004506ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
4507 ES2_D3D9(),
4508 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004509 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004510 ES2_OPENGLES(),
4511 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004512ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
4513 ES2_D3D9(),
4514 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004515 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004516 ES2_OPENGLES(),
4517 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004518ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
4519 ES2_D3D9(),
4520 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004521 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004522 ES2_OPENGLES(),
4523 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004524ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
4525 ES2_D3D9(),
4526 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004527 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004528 ES2_OPENGLES(),
4529 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004530ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02004531ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02004532ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4533ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
4534 ES3_D3D11(),
4535 ES3_OPENGL(),
4536 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004537ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
4538 ES3_D3D11(),
4539 ES3_OPENGL(),
4540 ES3_OPENGLES());
4541ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4542ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02004543ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02004544ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
4545 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004546 ES2_D3D9(),
4547 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004548 ES2_OPENGLES(),
4549 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004550ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
4551 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004552 ES2_D3D9(),
4553 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004554 ES2_OPENGLES(),
4555 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004556ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
4557 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004558 ES2_D3D9(),
4559 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004560 ES2_OPENGLES(),
4561 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004562ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
4563 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004564 ES2_D3D9(),
4565 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004566 ES2_OPENGLES(),
4567 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004568ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
4569 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004570 ES2_D3D9(),
4571 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004572 ES2_OPENGLES(),
4573 ES2_VULKAN());
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05004574ANGLE_INSTANTIATE_TEST(TextureAnisotropyTest,
4575 ES2_D3D11(),
4576 ES2_D3D9(),
4577 ES2_OPENGL(),
4578 ES2_OPENGLES(),
4579 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02004580ANGLE_INSTANTIATE_TEST(TextureBorderClampTest,
4581 ES2_D3D11(),
4582 ES2_D3D9(),
4583 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004584 ES2_OPENGLES(),
4585 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02004586ANGLE_INSTANTIATE_TEST(TextureBorderClampTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4587ANGLE_INSTANTIATE_TEST(TextureBorderClampIntegerTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Luc Ferronaf883622018-06-08 15:57:31 -04004588ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN());
Vincent Lang25ab4512016-05-13 18:13:59 +02004589ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03004590ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Anders Leinof6cbe442019-04-18 15:32:07 +03004591ANGLE_INSTANTIATE_TEST(Texture2DIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Jamie Madillfa05f602015-05-07 13:47:11 -04004592
Jamie Madill7ffdda92016-09-08 13:26:51 -04004593} // anonymous namespace