blob: f57be09d5ec3de830e7848af01b16ab9e1ca2bb3 [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
Anders Leino60cc7512019-05-06 09:25:27 +03001181class TextureCubeIntegerTestES3 : public TexCoordDrawTest
1182{
1183 protected:
1184 TextureCubeIntegerTestES3()
1185 : TexCoordDrawTest(), mTextureCube(0), mTextureCubeUniformLocation(-1)
1186 {}
1187
1188 const char *getVertexShaderSource() override
1189 {
1190 return "#version 300 es\n"
1191 "out vec2 texcoord;\n"
1192 "in vec4 position;\n"
1193 "void main()\n"
1194 "{\n"
1195 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1196 " texcoord = 0.5*position.xy;\n"
1197 "}\n";
1198 }
1199
1200 const char *getFragmentShaderSource() override
1201 {
1202 return "#version 300 es\n"
1203 "precision highp float;\n"
1204 "precision highp usamplerCube;\n"
1205 "uniform usamplerCube texCube;\n"
1206 "in vec2 texcoord;\n"
1207 "out vec4 fragColor;\n"
1208 "void main()\n"
1209 "{\n"
1210 " fragColor = vec4(texture(texCube, vec3(texcoord, 1)))/255.0;\n"
1211 "}\n";
1212 }
1213
1214 void testSetUp() override
1215 {
1216 TexCoordDrawTest::testSetUp();
1217 glGenTextures(1, &mTextureCube);
1218 setUpProgram();
1219
1220 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
1221 ASSERT_NE(-1, mTextureCubeUniformLocation);
1222 }
1223
1224 void testTearDown() override
1225 {
1226 glDeleteTextures(1, &mTextureCube);
1227 TexCoordDrawTest::testTearDown();
1228 }
1229
1230 GLuint mTextureCube;
1231 GLint mTextureCubeUniformLocation;
1232};
1233
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001234TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001235{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001236 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001237 EXPECT_GL_ERROR(GL_NO_ERROR);
1238
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001239 setUpProgram();
1240
Jamie Madill50cf2be2018-06-15 09:46:57 -04001241 const GLubyte *pixels[20] = {0};
Jamie Madillf67115c2014-04-22 13:14:05 -04001242 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1243 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001244
Jamie Madillb8149072019-04-30 16:14:44 -04001245 if (IsGLExtensionEnabled("GL_EXT_texture_storage"))
Geoff Langc51642b2016-11-14 16:18:26 -05001246 {
1247 // Create a 1-level immutable texture.
1248 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1249
1250 // Try calling sub image on the second level.
1251 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1252 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1253 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001254}
Geoff Langc41e42d2014-04-28 10:58:16 -04001255
John Bauman18319182016-09-28 14:22:27 -07001256// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1257TEST_P(Texture2DTest, QueryBinding)
1258{
1259 glBindTexture(GL_TEXTURE_2D, 0);
1260 EXPECT_GL_ERROR(GL_NO_ERROR);
1261
1262 GLint textureBinding;
1263 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1264 EXPECT_GL_NO_ERROR();
1265 EXPECT_EQ(0, textureBinding);
1266
1267 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
Jamie Madillb8149072019-04-30 16:14:44 -04001268 if (IsGLExtensionEnabled("GL_OES_EGL_image_external") ||
1269 IsGLExtensionEnabled("GL_NV_EGL_stream_consumer_external"))
John Bauman18319182016-09-28 14:22:27 -07001270 {
1271 EXPECT_GL_NO_ERROR();
1272 EXPECT_EQ(0, textureBinding);
1273 }
1274 else
1275 {
1276 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1277 }
1278}
1279
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001280TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001281{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001282 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001283 EXPECT_GL_ERROR(GL_NO_ERROR);
1284
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001285 setUpProgram();
1286
Geoff Langc41e42d2014-04-28 10:58:16 -04001287 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001288 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001289 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001290 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001291
Jamie Madill50cf2be2018-06-15 09:46:57 -04001292 const GLubyte *pixel[4] = {0};
Geoff Langc41e42d2014-04-28 10:58:16 -04001293
1294 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1295 EXPECT_GL_NO_ERROR();
1296
1297 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1298 EXPECT_GL_NO_ERROR();
1299
1300 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1301 EXPECT_GL_NO_ERROR();
1302}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001303
1304// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001305TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001306{
1307 glActiveTexture(GL_TEXTURE0);
1308 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1309 glActiveTexture(GL_TEXTURE1);
1310 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1311 EXPECT_GL_ERROR(GL_NO_ERROR);
1312
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001313 glUseProgram(mProgram);
1314 glUniform1i(mTexture2DUniformLocation, 0);
1315 glUniform1i(mTextureCubeUniformLocation, 1);
1316 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001317 EXPECT_GL_NO_ERROR();
1318}
Jamie Madill9aca0592014-10-06 16:26:59 -04001319
Olli Etuaho53a2da12016-01-11 15:43:32 +02001320// Test drawing with two texture types accessed from the same shader and check that the result of
1321// drawing is correct.
1322TEST_P(TextureCubeTest, CubeMapDraw)
1323{
1324 GLubyte texData[4];
1325 texData[0] = 0;
1326 texData[1] = 60;
1327 texData[2] = 0;
1328 texData[3] = 255;
1329
1330 glActiveTexture(GL_TEXTURE0);
1331 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1332 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1333
1334 glActiveTexture(GL_TEXTURE1);
1335 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1336 texData[1] = 120;
1337 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1338 texData);
1339 EXPECT_GL_ERROR(GL_NO_ERROR);
1340
1341 glUseProgram(mProgram);
1342 glUniform1i(mTexture2DUniformLocation, 0);
1343 glUniform1i(mTextureCubeUniformLocation, 1);
1344 drawQuad(mProgram, "position", 0.5f);
1345 EXPECT_GL_NO_ERROR();
1346
1347 int px = getWindowWidth() - 1;
1348 int py = 0;
1349 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1350}
1351
Olli Etuaho4644a202016-01-12 15:12:53 +02001352TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1353{
1354 glActiveTexture(GL_TEXTURE0);
1355 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1356 GLubyte texData[4];
1357 texData[0] = 0;
1358 texData[1] = 128;
1359 texData[2] = 0;
1360 texData[3] = 255;
1361 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1362 glUseProgram(mProgram);
1363 glUniform1i(mTexture2DUniformLocation, 0);
1364 drawQuad(mProgram, "position", 0.5f);
1365 EXPECT_GL_NO_ERROR();
1366
1367 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1368}
1369
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001370// Test drawing with two textures passed to the shader in a sampler array.
1371TEST_P(SamplerArrayTest, SamplerArrayDraw)
1372{
1373 testSamplerArrayDraw();
1374}
1375
1376// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1377// user-defined function in the shader.
1378TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1379{
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05001380 // TODO: Diagnose and fix. http://anglebug.com/2955
1381 ANGLE_SKIP_TEST_IF(IsVulkan() && IsAndroid());
1382
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001383 testSamplerArrayDraw();
1384}
1385
Jamie Madill9aca0592014-10-06 16:26:59 -04001386// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001387TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001388{
1389 int px = getWindowWidth() / 2;
1390 int py = getWindowHeight() / 2;
1391
1392 glActiveTexture(GL_TEXTURE0);
1393 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1394
Olli Etuahoa314b612016-03-10 16:43:00 +02001395 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001396
Olli Etuahoa314b612016-03-10 16:43:00 +02001397 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001398 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1399 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1400 glGenerateMipmap(GL_TEXTURE_2D);
1401
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001402 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001403 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001404 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1405 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001406 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001407 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001408
Olli Etuahoa314b612016-03-10 16:43:00 +02001409 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001410
Olli Etuahoa314b612016-03-10 16:43:00 +02001411 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1412 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001413 glGenerateMipmap(GL_TEXTURE_2D);
1414
Olli Etuahoa314b612016-03-10 16:43:00 +02001415 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001416
Olli Etuahoa314b612016-03-10 16:43:00 +02001417 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1418 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001419 glGenerateMipmap(GL_TEXTURE_2D);
1420
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001421 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001422
1423 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001424 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001425}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001426
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001427// Test creating a FBO with a cube map render target, to test an ANGLE bug
1428// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001429TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001430{
Michael Spangd8506c72019-01-29 15:35:09 -05001431 // http://anglebug.com/3145
1432 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
1433
Shahbaz Youssefi0c128e12019-03-25 23:50:14 -04001434 // http://anglebug.com/2822
1435 ANGLE_SKIP_TEST_IF(IsWindows() && IsIntel() && IsVulkan());
1436
Jamie Madill3f3b3582018-09-14 10:38:44 -04001437 GLFramebuffer fbo;
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001438 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1439
1440 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Jamie Madill50cf2be2018-06-15 09:46:57 -04001441 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1442 mTextureCube, 0);
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001443
Corentin Wallez322653b2015-06-17 18:33:56 +02001444 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001445 EXPECT_GL_NO_ERROR();
Jamie Madill3f3b3582018-09-14 10:38:44 -04001446
1447 // Test clearing the six mip faces individually.
1448 std::array<GLColor, 6> faceColors = {{GLColor::red, GLColor::green, GLColor::blue,
1449 GLColor::yellow, GLColor::cyan, GLColor::magenta}};
1450
1451 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1452 {
1453 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1454 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1455
1456 Vector4 clearColorF = faceColors[faceIndex].toNormalizedVector();
1457 glClearColor(clearColorF.x(), clearColorF.y(), clearColorF.z(), clearColorF.w());
1458 glClear(GL_COLOR_BUFFER_BIT);
1459
1460 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex]);
1461 }
1462
1463 // Iterate the faces again to make sure the colors haven't changed.
1464 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1465 {
1466 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1467 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1468 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex])
1469 << "face color " << faceIndex << " shouldn't change";
1470 }
1471}
1472
1473// Tests clearing a cube map with a scissor enabled.
1474TEST_P(TextureCubeTest, CubeMapFBOScissoredClear)
1475{
1476 // TODO(jie.a.chen): Diagnose and fix. http://anglebug.com/2822
1477 ANGLE_SKIP_TEST_IF(IsVulkan() && IsIntel() && IsWindows());
1478
Michael Spangd8506c72019-01-29 15:35:09 -05001479 // http://anglebug.com/3145
1480 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
1481
Jamie Madill3f3b3582018-09-14 10:38:44 -04001482 constexpr size_t kSize = 16;
1483
1484 GLFramebuffer fbo;
1485 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1486 glViewport(0, 0, kSize, kSize);
1487
1488 GLTexture texcube;
1489 glBindTexture(GL_TEXTURE_CUBE_MAP, texcube);
1490 for (GLenum face = 0; face < 6; face++)
1491 {
1492 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA,
1493 GL_UNSIGNED_BYTE, nullptr);
1494 }
1495 ASSERT_GL_NO_ERROR();
1496
1497 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1498 texcube, 0);
1499
1500 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1501 ASSERT_GL_NO_ERROR();
1502
1503 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1504 glClear(GL_COLOR_BUFFER_BIT);
1505 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1506
1507 glEnable(GL_SCISSOR_TEST);
1508 glScissor(kSize / 2, 0, kSize / 2, kSize);
1509 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
1510 glClear(GL_COLOR_BUFFER_BIT);
1511
1512 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1513 EXPECT_PIXEL_COLOR_EQ(kSize / 2 + 1, 0, GLColor::green);
1514
1515 ASSERT_GL_NO_ERROR();
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001516}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001517
Jamie Madill50cf2be2018-06-15 09:46:57 -04001518// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a
1519// default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001520TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001521{
Jamie Madillb8149072019-04-30 16:14:44 -04001522 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 &&
1523 !IsGLExtensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -04001524
Jamie Madill50cf2be2018-06-15 09:46:57 -04001525 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001526 int height = getWindowHeight();
1527
1528 GLuint tex2D;
1529 glGenTextures(1, &tex2D);
1530 glActiveTexture(GL_TEXTURE0);
1531 glBindTexture(GL_TEXTURE_2D, tex2D);
1532
1533 // Fill with red
1534 std::vector<GLubyte> pixels(3 * 16 * 16);
1535 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1536 {
1537 pixels[pixelId * 3 + 0] = 255;
1538 pixels[pixelId * 3 + 1] = 0;
1539 pixels[pixelId * 3 + 2] = 0;
1540 }
1541
1542 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001543 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1544 // 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 -04001545 if (getClientMajorVersion() >= 3)
1546 {
1547 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1548 }
1549 else
1550 {
1551 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1552 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001553
1554 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1555 // glTexSubImage2D should take into account that the image is dirty.
1556 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1557 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1558 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1559
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001560 setUpProgram();
1561
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001562 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001563 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001564 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001565 glDeleteTextures(1, &tex2D);
1566 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001567 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001568
1569 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001570 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1571 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001572}
1573
Jamie Madill50cf2be2018-06-15 09:46:57 -04001574// Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has
1575// initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001576TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001577{
Jamie Madillb8149072019-04-30 16:14:44 -04001578 if (IsGLExtensionEnabled("NV_pixel_buffer_object"))
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001579 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04001580 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001581 int height = getWindowHeight();
1582
1583 GLuint tex2D;
1584 glGenTextures(1, &tex2D);
1585 glActiveTexture(GL_TEXTURE0);
1586 glBindTexture(GL_TEXTURE_2D, tex2D);
1587
1588 // Fill with red
1589 std::vector<GLubyte> pixels(3 * 16 * 16);
1590 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1591 {
1592 pixels[pixelId * 3 + 0] = 255;
1593 pixels[pixelId * 3 + 1] = 0;
1594 pixels[pixelId * 3 + 2] = 0;
1595 }
1596
1597 // Read 16x16 region from red backbuffer to PBO
1598 GLuint pbo;
1599 glGenBuffers(1, &pbo);
1600 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1601 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1602
1603 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001604 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1605 // 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 +00001606 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1607
1608 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1609 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001610 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 +00001611 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1612 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1613
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001614 setUpProgram();
1615
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001616 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001617 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001618 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001619 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001620 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001621 EXPECT_GL_NO_ERROR();
1622 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1623 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1624 }
1625}
Jamie Madillbc393df2015-01-29 13:46:07 -05001626
1627// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001628TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001629{
1630 testFloatCopySubImage(1, 1);
1631}
1632
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001633TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001634{
1635 testFloatCopySubImage(2, 1);
1636}
1637
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001638TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001639{
1640 testFloatCopySubImage(2, 2);
1641}
1642
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001643TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001644{
1645 testFloatCopySubImage(3, 1);
1646}
1647
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001648TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001649{
1650 testFloatCopySubImage(3, 2);
1651}
1652
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001653TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001654{
Yunchao He9550c602018-02-13 14:47:05 +08001655 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1656 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001657
Yunchao He9550c602018-02-13 14:47:05 +08001658 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1659 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001660
Jamie Madillbc393df2015-01-29 13:46:07 -05001661 testFloatCopySubImage(3, 3);
1662}
1663
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001664TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001665{
1666 testFloatCopySubImage(4, 1);
1667}
1668
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001669TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001670{
1671 testFloatCopySubImage(4, 2);
1672}
1673
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001674TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001675{
Yunchao He9550c602018-02-13 14:47:05 +08001676 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1677 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001678
Jamie Madillbc393df2015-01-29 13:46:07 -05001679 testFloatCopySubImage(4, 3);
1680}
1681
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001682TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001683{
Luc Ferronf786b702018-07-10 11:01:43 -04001684 // TODO(lucferron): This test fails only on linux and intel.
1685 // http://anglebug.com/2726
1686 ANGLE_SKIP_TEST_IF(IsVulkan() && IsLinux() && IsIntel());
1687
Yunchao He9550c602018-02-13 14:47:05 +08001688 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1689 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001690
Jamie Madillbc393df2015-01-29 13:46:07 -05001691 testFloatCopySubImage(4, 4);
1692}
Austin Kinross07285142015-03-26 11:36:16 -07001693
Jamie Madill50cf2be2018-06-15 09:46:57 -04001694// Port of
1695// https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1696// Run against GL_ALPHA/UNSIGNED_BYTE format, to ensure that D3D11 Feature Level 9_3 correctly
1697// handles GL_ALPHA
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001698TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001699{
1700 const int npotTexSize = 5;
Jamie Madill50cf2be2018-06-15 09:46:57 -04001701 const int potTexSize = 4; // Should be less than npotTexSize
Austin Kinross07285142015-03-26 11:36:16 -07001702 GLuint tex2D;
1703
Jamie Madillb8149072019-04-30 16:14:44 -04001704 if (IsGLExtensionEnabled("GL_OES_texture_npot"))
Austin Kinross07285142015-03-26 11:36:16 -07001705 {
1706 // This test isn't applicable if texture_npot is enabled
1707 return;
1708 }
1709
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001710 setUpProgram();
1711
Austin Kinross07285142015-03-26 11:36:16 -07001712 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1713
Austin Kinross5faa15b2016-01-11 13:32:48 -08001714 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1715 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1716
Austin Kinross07285142015-03-26 11:36:16 -07001717 glActiveTexture(GL_TEXTURE0);
1718 glGenTextures(1, &tex2D);
1719 glBindTexture(GL_TEXTURE_2D, tex2D);
1720
Till Rathmannc1551dc2018-08-15 17:04:49 +02001721 const std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize, 64);
Austin Kinross07285142015-03-26 11:36:16 -07001722
1723 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1724 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1725
1726 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
Jamie Madill50cf2be2018-06-15 09:46:57 -04001727 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1728 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001729 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1730
1731 // Check that an NPOT texture on level 0 succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001732 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1733 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001734 EXPECT_GL_NO_ERROR();
1735
1736 // Check that generateMipmap fails on NPOT
1737 glGenerateMipmap(GL_TEXTURE_2D);
1738 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1739
1740 // Check that nothing is drawn if filtering is not correct for NPOT
1741 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1742 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1743 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1744 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1745 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001746 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001747 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1748
1749 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1750 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1751 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1752 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1753 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001754 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001755 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1756
1757 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1758 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1759 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001760 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001761 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1762
1763 // Check that glTexImage2D for POT texture succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001764 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE,
1765 pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001766 EXPECT_GL_NO_ERROR();
1767
1768 // Check that generateMipmap for an POT texture succeeds
1769 glGenerateMipmap(GL_TEXTURE_2D);
1770 EXPECT_GL_NO_ERROR();
1771
1772 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1773 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1774 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1775 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1776 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1777 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001778 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001779 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1780 EXPECT_GL_NO_ERROR();
1781}
Jamie Madillfa05f602015-05-07 13:47:11 -04001782
Austin Kinross08528e12015-10-07 16:24:40 -07001783// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1784// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001785TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001786{
1787 glActiveTexture(GL_TEXTURE0);
1788 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1789
1790 // Create an 8x8 (i.e. power-of-two) texture.
1791 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1792 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1793 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1794 glGenerateMipmap(GL_TEXTURE_2D);
1795
1796 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1797 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001798 std::array<GLColor, 3 * 3> data;
1799 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001800
1801 EXPECT_GL_NO_ERROR();
1802}
1803
Geoff Lang3702d8c2019-04-08 13:44:06 -04001804// Regression test for http://crbug.com/949985 to make sure dirty bits are propagated up from
1805// TextureImpl and the texture is synced before being used in a draw call.
1806TEST_P(Texture2DTestES3, TextureImplPropogatesDirtyBits)
1807{
1808 ANGLE_SKIP_TEST_IF(IsIntel() && IsOpenGL());
Yuly Novikove6b23e42019-04-10 17:19:15 -04001809 // Flaky hangs on Win10 AMD RX 550 GL. http://anglebug.com/3371
1810 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsOpenGL());
Geoff Lang3702d8c2019-04-08 13:44:06 -04001811
1812 // The workaround in the GL backend required to trigger this bug generates driver warning
1813 // messages.
1814 ScopedIgnorePlatformMessages ignoreMessages;
1815
1816 setUpProgram();
1817 glUseProgram(mProgram);
1818 glActiveTexture(GL_TEXTURE0 + mTexture2DUniformLocation);
1819
1820 GLTexture dest;
1821 glBindTexture(GL_TEXTURE_2D, dest);
1822
1823 GLTexture source;
1824 glBindTexture(GL_TEXTURE_2D, source);
1825
1826 // Put data in mip 0 and 1
1827 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1828 GLColor::red.data());
1829 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1830 GLColor::green.data());
1831
1832 // Disable mipmapping so source is complete
1833 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1834 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1835
1836 // Force the dirty bits to be synchronized in source
1837 drawQuad(mProgram, "position", 1.0f);
1838
1839 // Copy from mip 1 of the source. In the GL backend this internally sets the base level to mip
1840 // 1 and sets a dirty bit.
1841 glCopyTextureCHROMIUM(source, 1, GL_TEXTURE_2D, dest, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_FALSE,
1842 GL_FALSE, GL_FALSE);
1843
1844 // Draw again, assertions are generated if the texture has internal dirty bits at draw time
1845 drawQuad(mProgram, "position", 1.0f);
1846}
1847
Geoff Lang6f691fb2019-04-25 11:01:52 -04001848// This test case changes the base level of a texture that's attached to a framebuffer, clears every
1849// level to green, and then samples the texture when rendering. Test is taken from
1850// https://www.khronos.org/registry/webgl/sdk/tests/conformance2/rendering/framebuffer-texture-changing-base-level.html
1851TEST_P(Texture2DTestES3, FramebufferTextureChangingBaselevel)
1852{
1853 // TODO(geofflang): Investigate on D3D11. http://anglebug.com/2291
1854 ANGLE_SKIP_TEST_IF(IsD3D11());
1855
1856 setUpProgram();
1857
1858 constexpr GLint width = 8;
1859 constexpr GLint height = 4;
1860
1861 GLTexture texture;
1862 glBindTexture(GL_TEXTURE_2D, texture);
1863 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1864 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1865 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1866 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1867
1868 // Create all mipmap levels for the texture from level 0 to the 1x1 pixel level.
1869 GLint level = 0;
1870 GLint levelW = width;
1871 GLint levelH = height;
1872 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, levelW, levelH, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1873 nullptr);
1874 while (levelW > 1 || levelH > 1)
1875 {
1876 ++level;
1877 levelW = static_cast<GLint>(std::max(1.0, std::floor(width / std::pow(2, level))));
1878 levelH = static_cast<GLint>(std::max(1.0, std::floor(height / std::pow(2, level))));
1879 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, levelW, levelH, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1880 nullptr);
1881 }
1882
1883 // Clear each level of the texture using an FBO. Change the base level to match the level used
1884 // for the FBO on each iteration.
1885 GLFramebuffer fbo;
1886 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1887 level = 0;
1888 levelW = width;
1889 levelH = height;
1890 while (levelW > 1 || levelH > 1)
1891 {
1892 levelW = static_cast<GLint>(std::floor(width / std::pow(2, level)));
1893 levelH = static_cast<GLint>(std::floor(height / std::pow(2, level)));
1894
1895 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, level);
1896 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, level);
1897
1898 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1899 EXPECT_GL_NO_ERROR();
1900
1901 glClearColor(0, 1, 0, 1);
1902 glClear(GL_COLOR_BUFFER_BIT);
1903
1904 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1905
1906 ++level;
1907 }
1908
1909 glBindFramebuffer(GL_FRAMEBUFFER, 0);
1910 glViewport(0, 0, 16, 16);
1911 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
1912
1913 drawQuad(mProgram, "position", 0.5f);
1914
1915 EXPECT_GL_NO_ERROR();
1916 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1917}
1918
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001919// Test to check that texture completeness is determined correctly when the texture base level is
1920// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1921TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1922{
1923 glActiveTexture(GL_TEXTURE0);
1924 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001925
1926 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1927 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1928 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1929 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1930 texDataGreen.data());
1931 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1932 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001933 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1934 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1935 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1936
1937 EXPECT_GL_NO_ERROR();
1938
1939 drawQuad(mProgram, "position", 0.5f);
1940
Olli Etuahoa314b612016-03-10 16:43:00 +02001941 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1942}
1943
1944// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1945// have images defined.
1946TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1947{
Yunchao He9550c602018-02-13 14:47:05 +08001948 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1949 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1950
Olli Etuahoa314b612016-03-10 16:43:00 +02001951 glActiveTexture(GL_TEXTURE0);
1952 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1953 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1954 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1955 texDataGreen.data());
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 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1959 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1960
1961 EXPECT_GL_NO_ERROR();
1962
1963 drawQuad(mProgram, "position", 0.5f);
1964
1965 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1966}
1967
Olli Etuahoe8528d82016-05-16 17:50:52 +03001968// Test that drawing works correctly when level 0 is undefined and base level is 1.
1969TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1970{
Yunchao He9550c602018-02-13 14:47:05 +08001971 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1972 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1973
Olli Etuahoe8528d82016-05-16 17:50:52 +03001974 glActiveTexture(GL_TEXTURE0);
1975 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1976 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1977 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1978 texDataGreen.data());
1979 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1980 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1981 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1982 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1983
1984 EXPECT_GL_NO_ERROR();
1985
1986 // Texture is incomplete.
1987 drawQuad(mProgram, "position", 0.5f);
1988 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1989
1990 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1991 texDataGreen.data());
1992
1993 // Texture is now complete.
1994 drawQuad(mProgram, "position", 0.5f);
1995 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1996}
1997
Olli Etuahoa314b612016-03-10 16:43:00 +02001998// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1999// dimensions that don't fit the images inside the range.
2000// GLES 3.0.4 section 3.8.13 Texture completeness
2001TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2002{
Olli Etuahoa314b612016-03-10 16:43:00 +02002003 glActiveTexture(GL_TEXTURE0);
2004 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2005 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
2006 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2007 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
2008
2009 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2010 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2011
2012 // Two levels that are initially unused.
2013 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
2014 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2015 texDataCyan.data());
2016
2017 // One level that is used - only this level should affect completeness.
2018 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2019 texDataGreen.data());
2020
2021 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2022 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2023
2024 EXPECT_GL_NO_ERROR();
2025
2026 drawQuad(mProgram, "position", 0.5f);
2027
2028 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2029
Yunchao He2f23f352018-02-11 22:11:37 +08002030 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02002031
2032 // Switch the level that is being used to the cyan level 2.
2033 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2034 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2035
2036 EXPECT_GL_NO_ERROR();
2037
2038 drawQuad(mProgram, "position", 0.5f);
2039
2040 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2041}
2042
2043// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2044// have images defined.
2045TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
2046{
Olli Etuahoa314b612016-03-10 16:43:00 +02002047 glActiveTexture(GL_TEXTURE0);
2048 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2049 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2050 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2051 texDataGreen.data());
2052 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2053 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2054 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
2055 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2056
2057 EXPECT_GL_NO_ERROR();
2058
2059 drawQuad(mProgram, "position", 0.5f);
2060
2061 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2062}
2063
2064// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2065// dimensions that don't fit the images inside the range.
2066// GLES 3.0.4 section 3.8.13 Texture completeness
2067TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2068{
Olli Etuahoa314b612016-03-10 16:43:00 +02002069 glActiveTexture(GL_TEXTURE0);
2070 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2071 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2072 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2073 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2074
2075 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2076 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2077
2078 // Two levels that are initially unused.
2079 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2080 texDataRed.data());
2081 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2082 texDataCyan.data());
2083
2084 // One level that is used - only this level should affect completeness.
2085 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2086 texDataGreen.data());
2087
2088 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
2089 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2090
2091 EXPECT_GL_NO_ERROR();
2092
2093 drawQuad(mProgram, "position", 0.5f);
2094
2095 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2096
Yunchao He2f23f352018-02-11 22:11:37 +08002097 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02002098
2099 // Switch the level that is being used to the cyan level 2.
2100 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
2101 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
2102
2103 EXPECT_GL_NO_ERROR();
2104
2105 drawQuad(mProgram, "position", 0.5f);
2106
2107 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2108}
2109
2110// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2111// have images defined.
2112TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
2113{
Olli Etuahoa314b612016-03-10 16:43:00 +02002114 glActiveTexture(GL_TEXTURE0);
2115 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
2116 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2117 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2118 texDataGreen.data());
2119 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2120 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2121 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2122 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2123
2124 EXPECT_GL_NO_ERROR();
2125
2126 drawQuad(mProgram, "position", 0.5f);
2127
2128 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2129}
2130
2131// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2132// dimensions that don't fit the images inside the range.
2133// GLES 3.0.4 section 3.8.13 Texture completeness
2134TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2135{
Olli Etuahoa314b612016-03-10 16:43:00 +02002136 glActiveTexture(GL_TEXTURE0);
2137 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
2138 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2139 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2140 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2141
2142 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2143 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2144
2145 // Two levels that are initially unused.
2146 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2147 texDataRed.data());
2148 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2149 texDataCyan.data());
2150
2151 // One level that is used - only this level should affect completeness.
2152 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2153 texDataGreen.data());
2154
2155 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2156 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2157
2158 EXPECT_GL_NO_ERROR();
2159
2160 drawQuad(mProgram, "position", 0.5f);
2161
2162 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2163
Yunchao He2f23f352018-02-11 22:11:37 +08002164 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
2165
Yunchao He9550c602018-02-13 14:47:05 +08002166 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
2167 // level was changed.
2168 ANGLE_SKIP_TEST_IF(IsNVIDIA() && (IsOpenGL() || IsOpenGLES()));
Olli Etuahoa314b612016-03-10 16:43:00 +02002169
2170 // Switch the level that is being used to the cyan level 2.
2171 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2172 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2173
2174 EXPECT_GL_NO_ERROR();
2175
2176 drawQuad(mProgram, "position", 0.5f);
2177
2178 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2179}
2180
2181// Test that texture completeness is updated if texture max level changes.
2182// GLES 3.0.4 section 3.8.13 Texture completeness
2183TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2184{
Olli Etuahoa314b612016-03-10 16:43:00 +02002185 glActiveTexture(GL_TEXTURE0);
2186 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2187 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2188
2189 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2190 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2191
2192 // A level that is initially unused.
2193 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2194 texDataGreen.data());
2195
2196 // One level that is initially used - only this level should affect completeness.
2197 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2198 texDataGreen.data());
2199
2200 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2201 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2202
2203 EXPECT_GL_NO_ERROR();
2204
2205 drawQuad(mProgram, "position", 0.5f);
2206
2207 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2208
2209 // Switch the max level to level 1. The levels within the used range now have inconsistent
2210 // dimensions and the texture should be incomplete.
2211 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2212
2213 EXPECT_GL_NO_ERROR();
2214
2215 drawQuad(mProgram, "position", 0.5f);
2216
2217 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2218}
2219
2220// Test that 3D texture completeness is updated if texture max level changes.
2221// GLES 3.0.4 section 3.8.13 Texture completeness
2222TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2223{
Olli Etuahoa314b612016-03-10 16:43:00 +02002224 glActiveTexture(GL_TEXTURE0);
2225 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2226 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2227
2228 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2229 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2230
2231 // A level that is initially unused.
2232 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2233 texDataGreen.data());
2234
2235 // One level that is initially used - only this level should affect completeness.
2236 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2237 texDataGreen.data());
2238
2239 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2240 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2241
2242 EXPECT_GL_NO_ERROR();
2243
2244 drawQuad(mProgram, "position", 0.5f);
2245
2246 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2247
2248 // Switch the max level to level 1. The levels within the used range now have inconsistent
2249 // dimensions and the texture should be incomplete.
2250 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2251
2252 EXPECT_GL_NO_ERROR();
2253
2254 drawQuad(mProgram, "position", 0.5f);
2255
2256 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2257}
2258
2259// Test that texture completeness is updated if texture base level changes.
2260// GLES 3.0.4 section 3.8.13 Texture completeness
2261TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2262{
Olli Etuahoa314b612016-03-10 16:43:00 +02002263 glActiveTexture(GL_TEXTURE0);
2264 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2265 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2266
2267 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2268 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2269
2270 // Two levels that are initially unused.
2271 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2272 texDataGreen.data());
2273 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2274 texDataGreen.data());
2275
2276 // One level that is initially used - only this level should affect completeness.
2277 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2278 texDataGreen.data());
2279
2280 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2281 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2282
2283 EXPECT_GL_NO_ERROR();
2284
2285 drawQuad(mProgram, "position", 0.5f);
2286
2287 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2288
2289 // Switch the base level to level 1. The levels within the used range now have inconsistent
2290 // dimensions and the texture should be incomplete.
2291 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2292
2293 EXPECT_GL_NO_ERROR();
2294
2295 drawQuad(mProgram, "position", 0.5f);
2296
2297 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2298}
2299
2300// Test that texture is not complete if base level is greater than max level.
2301// GLES 3.0.4 section 3.8.13 Texture completeness
2302TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2303{
Olli Etuahoa314b612016-03-10 16:43:00 +02002304 glActiveTexture(GL_TEXTURE0);
2305 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2306
2307 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2308 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2309
2310 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2311
2312 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2313 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2314
2315 EXPECT_GL_NO_ERROR();
2316
2317 drawQuad(mProgram, "position", 0.5f);
2318
2319 // Texture should be incomplete.
2320 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2321}
2322
2323// Test that immutable texture base level and max level are clamped.
2324// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2325TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2326{
Olli Etuahoa314b612016-03-10 16:43:00 +02002327 glActiveTexture(GL_TEXTURE0);
2328 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2329
2330 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2331 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2332
2333 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2334
2335 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2336
2337 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2338 // should be clamped to [base_level, levels - 1].
2339 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2340 // In the case of this test, those rules make the effective base level and max level 0.
2341 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2342 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2343
2344 EXPECT_GL_NO_ERROR();
2345
2346 drawQuad(mProgram, "position", 0.5f);
2347
2348 // Texture should be complete.
2349 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2350}
2351
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002352// Test that changing base level works when it affects the format of the texture.
2353TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2354{
Yunchao He9550c602018-02-13 14:47:05 +08002355 // Observed rendering corruption on NVIDIA OpenGL.
2356 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL());
2357
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002358 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002359
2360 // Observed incorrect rendering on AMD OpenGL.
2361 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002362
2363 glActiveTexture(GL_TEXTURE0);
2364 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2365 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2366 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2367
2368 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2369 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2370
2371 // RGBA8 level that's initially unused.
2372 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2373 texDataCyan.data());
2374
2375 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2376 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2377
2378 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2379 // format. It reads green channel data from the green and alpha channels of texDataGreen
2380 // (this is a bit hacky but works).
2381 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2382
2383 EXPECT_GL_NO_ERROR();
2384
2385 drawQuad(mProgram, "position", 0.5f);
2386
2387 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2388
2389 // Switch the texture to use the cyan level 0 with the RGBA format.
2390 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2391 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2392
2393 EXPECT_GL_NO_ERROR();
2394
2395 drawQuad(mProgram, "position", 0.5f);
2396
2397 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2398}
2399
Olli Etuahoa314b612016-03-10 16:43:00 +02002400// Test that setting a texture image works when base level is out of range.
2401TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2402{
2403 glActiveTexture(GL_TEXTURE0);
2404 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2405
2406 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2407 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2408
2409 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2410 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2411
2412 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2413
2414 EXPECT_GL_NO_ERROR();
2415
2416 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2417
2418 drawQuad(mProgram, "position", 0.5f);
2419
2420 // Texture should be complete.
2421 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002422}
2423
Jamie Madill50cf2be2018-06-15 09:46:57 -04002424// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG
2425// RBA->RGBA8, with 1.0 in the alpha channel. This test covers a bug where redefining array textures
2426// with these formats does not work as expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002427TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002428{
2429 std::vector<GLubyte> pixelData;
2430 for (size_t count = 0; count < 5000; count++)
2431 {
2432 pixelData.push_back(0u);
2433 pixelData.push_back(255u);
2434 pixelData.push_back(0u);
2435 }
2436
2437 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002438 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002439 glUniform1i(mTextureArrayLocation, 0);
2440
2441 // The first draw worked correctly.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002442 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2443 &pixelData[0]);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002444
2445 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2446 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2447 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2448 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002449 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002450 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002451
2452 // The dimension of the respecification must match the original exactly to trigger the bug.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002453 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2454 &pixelData[0]);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002455 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002456 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002457
2458 ASSERT_GL_NO_ERROR();
2459}
2460
Olli Etuaho1a679902016-01-14 12:21:47 +02002461// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2462// This test is needed especially to confirm that sampler registers get assigned correctly on
2463// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2464TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2465{
2466 glActiveTexture(GL_TEXTURE0);
2467 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2468 GLubyte texData[4];
2469 texData[0] = 0;
2470 texData[1] = 60;
2471 texData[2] = 0;
2472 texData[3] = 255;
2473 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2474
2475 glActiveTexture(GL_TEXTURE1);
2476 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2477 GLfloat depthTexData[1];
2478 depthTexData[0] = 0.5f;
2479 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2480 depthTexData);
2481
2482 glUseProgram(mProgram);
2483 glUniform1f(mDepthRefUniformLocation, 0.3f);
2484 glUniform1i(mTexture3DUniformLocation, 0);
2485 glUniform1i(mTextureShadowUniformLocation, 1);
2486
2487 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2488 drawQuad(mProgram, "position", 0.5f);
2489 EXPECT_GL_NO_ERROR();
2490 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2491 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2492
2493 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2494 drawQuad(mProgram, "position", 0.5f);
2495 EXPECT_GL_NO_ERROR();
2496 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2497 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2498}
2499
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002500// Test multiple different sampler types in the same shader.
2501// This test makes sure that even if sampler / texture registers get grouped together based on type
2502// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2503// still has the right register index information for each ESSL sampler.
2504// The tested ESSL samplers have the following types in D3D11 HLSL:
2505// sampler2D: Texture2D + SamplerState
2506// samplerCube: TextureCube + SamplerState
2507// sampler2DShadow: Texture2D + SamplerComparisonState
2508// samplerCubeShadow: TextureCube + SamplerComparisonState
2509TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2510{
2511 glActiveTexture(GL_TEXTURE0);
2512 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2513 GLubyte texData[4];
2514 texData[0] = 0;
2515 texData[1] = 0;
2516 texData[2] = 120;
2517 texData[3] = 255;
2518 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2519
2520 glActiveTexture(GL_TEXTURE1);
2521 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2522 texData[0] = 0;
2523 texData[1] = 90;
2524 texData[2] = 0;
2525 texData[3] = 255;
2526 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2527 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2528 texData);
2529
2530 glActiveTexture(GL_TEXTURE2);
2531 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2532 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2533 GLfloat depthTexData[1];
2534 depthTexData[0] = 0.5f;
2535 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2536 depthTexData);
2537
2538 glActiveTexture(GL_TEXTURE3);
2539 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2540 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2541 depthTexData[0] = 0.2f;
2542 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2543 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2544 depthTexData);
2545
2546 EXPECT_GL_NO_ERROR();
2547
2548 glUseProgram(mProgram);
2549 glUniform1f(mDepthRefUniformLocation, 0.3f);
2550 glUniform1i(mTexture2DUniformLocation, 0);
2551 glUniform1i(mTextureCubeUniformLocation, 1);
2552 glUniform1i(mTexture2DShadowUniformLocation, 2);
2553 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2554
2555 drawQuad(mProgram, "position", 0.5f);
2556 EXPECT_GL_NO_ERROR();
2557 // The shader writes:
2558 // <texture 2d color> +
2559 // <cube map color> +
2560 // 0.25 * <comparison result (1.0)> +
2561 // 0.125 * <comparison result (0.0)>
2562 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2563}
2564
Olli Etuahobce743a2016-01-15 17:18:28 +02002565// Test different base levels on textures accessed through the same sampler array.
2566// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2567TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2568{
Yunchao He9550c602018-02-13 14:47:05 +08002569 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2570
Olli Etuahobce743a2016-01-15 17:18:28 +02002571 glActiveTexture(GL_TEXTURE0);
2572 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2573 GLsizei size = 64;
2574 for (GLint level = 0; level < 7; ++level)
2575 {
2576 ASSERT_LT(0, size);
2577 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2578 nullptr);
2579 size = size / 2;
2580 }
2581 ASSERT_EQ(0, size);
2582 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2583
2584 glActiveTexture(GL_TEXTURE1);
2585 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2586 size = 128;
2587 for (GLint level = 0; level < 8; ++level)
2588 {
2589 ASSERT_LT(0, size);
2590 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2591 nullptr);
2592 size = size / 2;
2593 }
2594 ASSERT_EQ(0, size);
2595 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2596 EXPECT_GL_NO_ERROR();
2597
2598 glUseProgram(mProgram);
2599 glUniform1i(mTexture0Location, 0);
2600 glUniform1i(mTexture1Location, 1);
2601
Olli Etuaho5804dc82018-04-13 14:11:46 +03002602 drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
Olli Etuahobce743a2016-01-15 17:18:28 +02002603 EXPECT_GL_NO_ERROR();
2604 // Red channel: width of level 1 of texture A: 32.
2605 // Green channel: width of level 3 of texture B: 16.
2606 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2607}
2608
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002609// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2610// ES 3.0.4 table 3.24
2611TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2612{
2613 glActiveTexture(GL_TEXTURE0);
2614 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2615 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2616 EXPECT_GL_NO_ERROR();
2617
2618 drawQuad(mProgram, "position", 0.5f);
2619
2620 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2621}
2622
2623// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2624// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002625TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002626{
Luc Ferron5164b792018-03-06 09:10:12 -05002627 setUpProgram();
2628
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002629 glActiveTexture(GL_TEXTURE0);
2630 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2631 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2632 EXPECT_GL_NO_ERROR();
2633
2634 drawQuad(mProgram, "position", 0.5f);
2635
2636 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2637}
2638
Luc Ferron5164b792018-03-06 09:10:12 -05002639// Validate that every component of the pixel will be equal to the luminance value we've set
2640// and that the alpha channel will be 1 (or 255 to be exact).
2641TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2642{
2643 setUpProgram();
2644
2645 glActiveTexture(GL_TEXTURE0);
2646 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2647 uint8_t pixel = 50;
2648 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2649 EXPECT_GL_NO_ERROR();
2650
2651 drawQuad(mProgram, "position", 0.5f);
2652
2653 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2654}
2655
2656// Validate that every component of the pixel will be equal to the luminance value we've set
2657// and that the alpha channel will be the second component.
2658TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2659{
2660 setUpProgram();
2661
2662 glActiveTexture(GL_TEXTURE0);
2663 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2664 uint8_t pixel[] = {50, 25};
2665 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2666 GL_UNSIGNED_BYTE, pixel);
2667 EXPECT_GL_NO_ERROR();
2668
2669 drawQuad(mProgram, "position", 0.5f);
2670
2671 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2672}
2673
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002674// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2675// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002676TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002677{
Jamie Madillb8149072019-04-30 16:14:44 -04002678 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002679 ANGLE_SKIP_TEST_IF(IsD3D9());
2680 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002681
2682 setUpProgram();
2683
Luc Ferrond8c632c2018-04-10 12:31:44 -04002684 glActiveTexture(GL_TEXTURE0);
2685 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2686 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2687 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002688
Luc Ferrond8c632c2018-04-10 12:31:44 -04002689 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002690
Luc Ferrond8c632c2018-04-10 12:31:44 -04002691 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002692}
2693
2694// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2695// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002696TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002697{
Jamie Madillb8149072019-04-30 16:14:44 -04002698 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002699 ANGLE_SKIP_TEST_IF(IsD3D9());
2700 ANGLE_SKIP_TEST_IF(IsVulkan());
2701 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES());
2702 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2703 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002704
Luc Ferrond8c632c2018-04-10 12:31:44 -04002705 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002706
Luc Ferrond8c632c2018-04-10 12:31:44 -04002707 glActiveTexture(GL_TEXTURE0);
2708 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2709 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2710 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002711
Luc Ferrond8c632c2018-04-10 12:31:44 -04002712 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002713
Luc Ferrond8c632c2018-04-10 12:31:44 -04002714 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002715}
2716
2717// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2718// ES 3.0.4 table 3.24
2719TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2720{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002721 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2722
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002723 glActiveTexture(GL_TEXTURE0);
2724 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2725 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2726 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2727 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2728 EXPECT_GL_NO_ERROR();
2729
2730 drawQuad(mProgram, "position", 0.5f);
2731
2732 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2733}
2734
2735// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2736// ES 3.0.4 table 3.24
2737TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2738{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002739 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2740
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002741 glActiveTexture(GL_TEXTURE0);
2742 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2743
2744 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2745 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2746 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2747 EXPECT_GL_NO_ERROR();
2748
2749 drawQuad(mProgram, "position", 0.5f);
2750
2751 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2752}
2753
2754// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2755// ES 3.0.4 table 3.24
2756TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2757{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002758 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2759
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002760 glActiveTexture(GL_TEXTURE0);
2761 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2762 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2763 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2764 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2765 EXPECT_GL_NO_ERROR();
2766
2767 drawQuad(mProgram, "position", 0.5f);
2768
2769 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2770}
2771
2772// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2773// ES 3.0.4 table 3.24
2774TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2775{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002776 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2777
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002778 glActiveTexture(GL_TEXTURE0);
2779 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2780 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2781 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2782 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2783 EXPECT_GL_NO_ERROR();
2784
2785 drawQuad(mProgram, "position", 0.5f);
2786
2787 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2788}
2789
2790// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2791// ES 3.0.4 table 3.24
2792TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2793{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002794 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2795
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002796 glActiveTexture(GL_TEXTURE0);
2797 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2798 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2799 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2800 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2801 EXPECT_GL_NO_ERROR();
2802
2803 drawQuad(mProgram, "position", 0.5f);
2804
2805 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2806}
2807
2808// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2809// ES 3.0.4 table 3.24
2810TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2811{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002812 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2813
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002814 glActiveTexture(GL_TEXTURE0);
2815 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2816 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2817 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2818 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2819 EXPECT_GL_NO_ERROR();
2820
2821 drawQuad(mProgram, "position", 0.5f);
2822
2823 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2824}
2825
2826// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2827// ES 3.0.4 table 3.24
2828TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2829{
2830 glActiveTexture(GL_TEXTURE0);
2831 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2832 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2833 EXPECT_GL_NO_ERROR();
2834
2835 drawQuad(mProgram, "position", 0.5f);
2836
2837 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2838}
2839
2840// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2841// ES 3.0.4 table 3.24
2842TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2843{
2844 glActiveTexture(GL_TEXTURE0);
2845 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2846 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2847 nullptr);
2848 EXPECT_GL_NO_ERROR();
2849
2850 drawQuad(mProgram, "position", 0.5f);
2851
2852 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2853}
2854
2855// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2856// ES 3.0.4 table 3.24
2857TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2858{
Yunchao He9550c602018-02-13 14:47:05 +08002859 // Seems to fail on OSX 10.12 Intel.
2860 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Jamie Madillbb1db482017-01-10 10:48:32 -05002861
Yuly Novikov49886892018-01-23 21:18:27 -05002862 // http://anglebug.com/2190
2863 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2864
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002865 glActiveTexture(GL_TEXTURE0);
2866 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2867 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2868 EXPECT_GL_NO_ERROR();
2869
2870 drawQuad(mProgram, "position", 0.5f);
2871
2872 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2873}
2874
2875// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2876// ES 3.0.4 table 3.24
2877TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2878{
Yunchao He9550c602018-02-13 14:47:05 +08002879 // Seems to fail on OSX 10.12 Intel.
2880 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002881
Yuly Novikov49886892018-01-23 21:18:27 -05002882 // http://anglebug.com/2190
2883 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2884
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002885 glActiveTexture(GL_TEXTURE0);
2886 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2887 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2888 EXPECT_GL_NO_ERROR();
2889
2890 drawQuad(mProgram, "position", 0.5f);
2891
2892 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2893}
2894
Olli Etuaho96963162016-03-21 11:54:33 +02002895// Use a sampler in a uniform struct.
2896TEST_P(SamplerInStructTest, SamplerInStruct)
2897{
2898 runSamplerInStructTest();
2899}
2900
2901// Use a sampler in a uniform struct that's passed as a function parameter.
2902TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2903{
Yuly Novikovd18c0482019-04-04 19:56:43 -04002904 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
2905 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002906
Olli Etuaho96963162016-03-21 11:54:33 +02002907 runSamplerInStructTest();
2908}
2909
2910// Use a sampler in a uniform struct array with a struct from the array passed as a function
2911// parameter.
2912TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2913{
Yuly Novikovd18c0482019-04-04 19:56:43 -04002914 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
2915 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08002916
Olli Etuaho96963162016-03-21 11:54:33 +02002917 runSamplerInStructTest();
2918}
2919
2920// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2921// parameter.
2922TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2923{
Yuly Novikovd18c0482019-04-04 19:56:43 -04002924 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
2925 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08002926
Olli Etuaho96963162016-03-21 11:54:33 +02002927 runSamplerInStructTest();
2928}
2929
2930// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2931// similarly named uniform.
2932TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2933{
2934 runSamplerInStructTest();
2935}
2936
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05002937// GL_EXT_texture_filter_anisotropic
2938class TextureAnisotropyTest : public Texture2DTest
2939{
2940 protected:
2941 void uploadTexture()
2942 {
2943 glActiveTexture(GL_TEXTURE0);
2944 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2945 GLColor texDataRed[1] = {GLColor::red};
2946 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed);
2947 EXPECT_GL_NO_ERROR();
2948 }
2949};
2950
2951// Tests that setting anisotropic filtering doesn't cause failures at draw time.
2952TEST_P(TextureAnisotropyTest, AnisotropyFunctional)
2953{
Jamie Madillb8149072019-04-30 16:14:44 -04002954 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_filter_anisotropic"));
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05002955
2956 setUpProgram();
2957
2958 uploadTexture();
2959
2960 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2961 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2962 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f);
2963 EXPECT_GL_NO_ERROR();
2964
2965 drawQuad(mProgram, "position", 0.5f);
2966
2967 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
2968 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
2969 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::red);
2970}
2971
Till Rathmannb8543632018-10-02 19:46:14 +02002972// GL_OES_texture_border_clamp
2973class TextureBorderClampTest : public Texture2DTest
2974{
2975 protected:
2976 TextureBorderClampTest() : Texture2DTest() {}
2977
Jamie Madill35cd7332018-12-02 12:03:33 -05002978 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02002979 {
2980 return
2981 R"(precision highp float;
2982 attribute vec4 position;
2983 varying vec2 texcoord;
2984
2985 void main()
2986 {
2987 gl_Position = vec4(position.xy, 0.0, 1.0);
2988 // texcoords in [-0.5, 1.5]
2989 texcoord = (position.xy) + 0.5;
2990 })";
2991 }
2992
2993 void uploadTexture()
2994 {
2995 glActiveTexture(GL_TEXTURE0);
2996 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2997 std::vector<GLColor> texDataRed(1, GLColor::red);
2998 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2999 texDataRed.data());
3000 EXPECT_GL_NO_ERROR();
3001 }
3002};
3003
3004// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3005// GL_CLAMP_TO_BORDER wrap mode (set with glTexParameter).
3006TEST_P(TextureBorderClampTest, TextureBorderClampFunctional)
3007{
Jamie Madillb8149072019-04-30 16:14:44 -04003008 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003009
3010 setUpProgram();
3011
3012 uploadTexture();
3013
3014 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3015 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3016 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3017 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3018 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3019 EXPECT_GL_NO_ERROR();
3020
3021 drawQuad(mProgram, "position", 0.5f);
3022
3023 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3024 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3025 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3026}
3027
3028// Test reading back GL_TEXTURE_BORDER_COLOR by glGetTexParameter.
3029TEST_P(TextureBorderClampTest, TextureBorderClampFunctional2)
3030{
Jamie Madillb8149072019-04-30 16:14:44 -04003031 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003032
3033 glActiveTexture(GL_TEXTURE0);
3034 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3035
3036 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3037
3038 GLint colorFixedPoint[4] = {0};
3039 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3040 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3041 std::numeric_limits<GLint>::max()};
3042 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3043 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3044 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3045 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3046
3047 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3048 std::numeric_limits<GLint>::max()};
3049 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3050
3051 GLfloat color[4] = {0.0f};
3052 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
3053 EXPECT_EQ(color[0], kFloatBlue.R);
3054 EXPECT_EQ(color[1], kFloatBlue.G);
3055 EXPECT_EQ(color[2], kFloatBlue.B);
3056 EXPECT_EQ(color[3], kFloatBlue.A);
3057}
3058
3059// Test GL_TEXTURE_BORDER_COLOR parameter validation at glTexParameter.
3060TEST_P(TextureBorderClampTest, TextureBorderClampValidation)
3061{
Jamie Madillb8149072019-04-30 16:14:44 -04003062 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003063
3064 glActiveTexture(GL_TEXTURE0);
3065 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3066
3067 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, 1.0f);
3068 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3069
3070 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3071 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3072
3073 glTexParameterfv(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3074 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3075
3076 GLint colorInt[4] = {0};
3077 glTexParameteriv(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_BORDER_COLOR, colorInt);
3078 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3079
3080 if (getClientMajorVersion() < 3)
3081 {
3082 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3083 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3084 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3085 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3086
3087 GLuint colorUInt[4] = {0};
3088 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3089 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3090 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3091 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3092
3093 GLSampler sampler;
3094 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3095 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3096 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3097 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3098
3099 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3100 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3101 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3102 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3103 }
3104}
3105
3106class TextureBorderClampTestES3 : public TextureBorderClampTest
3107{
3108 protected:
3109 TextureBorderClampTestES3() : TextureBorderClampTest() {}
3110};
3111
3112// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3113// GL_CLAMP_TO_BORDER wrap mode (set with glSamplerParameter).
3114TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional)
3115{
Jamie Madillb8149072019-04-30 16:14:44 -04003116 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003117
3118 setUpProgram();
3119
3120 uploadTexture();
3121
3122 GLSampler sampler;
3123 glBindSampler(0, sampler);
3124 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3125 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3126 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3127 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3128 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3129 EXPECT_GL_NO_ERROR();
3130
3131 drawQuad(mProgram, "position", 0.5f);
3132
3133 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3134 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3135 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3136}
3137
3138// Test reading back GL_TEXTURE_BORDER_COLOR by glGetSamplerParameter.
3139TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional2)
3140{
Jamie Madillb8149072019-04-30 16:14:44 -04003141 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003142
3143 glActiveTexture(GL_TEXTURE0);
3144
3145 GLSampler sampler;
3146 glBindSampler(0, sampler);
3147
3148 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3149
3150 GLint colorFixedPoint[4] = {0};
3151 glGetSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3152 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3153 std::numeric_limits<GLint>::max()};
3154 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3155 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3156 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3157 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3158
3159 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3160 std::numeric_limits<GLint>::max()};
3161 glSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3162
3163 GLfloat color[4] = {0.0f};
3164 glGetSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, color);
3165 EXPECT_EQ(color[0], kFloatBlue.R);
3166 EXPECT_EQ(color[1], kFloatBlue.G);
3167 EXPECT_EQ(color[2], kFloatBlue.B);
3168 EXPECT_EQ(color[3], kFloatBlue.A);
3169
3170 constexpr GLint colorSomewhatRedInt[4] = {500000, 0, 0, std::numeric_limits<GLint>::max()};
3171 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedInt);
3172 GLint colorInt[4] = {0};
3173 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3174 EXPECT_EQ(colorInt[0], colorSomewhatRedInt[0]);
3175 EXPECT_EQ(colorInt[1], colorSomewhatRedInt[1]);
3176 EXPECT_EQ(colorInt[2], colorSomewhatRedInt[2]);
3177 EXPECT_EQ(colorInt[3], colorSomewhatRedInt[3]);
3178
3179 constexpr GLuint colorSomewhatRedUInt[4] = {500000, 0, 0, std::numeric_limits<GLuint>::max()};
3180 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedUInt);
3181 GLuint colorUInt[4] = {0};
3182 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3183 EXPECT_EQ(colorUInt[0], colorSomewhatRedUInt[0]);
3184 EXPECT_EQ(colorUInt[1], colorSomewhatRedUInt[1]);
3185 EXPECT_EQ(colorUInt[2], colorSomewhatRedUInt[2]);
3186 EXPECT_EQ(colorUInt[3], colorSomewhatRedUInt[3]);
3187
3188 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3189
3190 constexpr GLint colorSomewhatGreenInt[4] = {0, 500000, 0, std::numeric_limits<GLint>::max()};
3191 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenInt);
3192 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3193 EXPECT_EQ(colorInt[0], colorSomewhatGreenInt[0]);
3194 EXPECT_EQ(colorInt[1], colorSomewhatGreenInt[1]);
3195 EXPECT_EQ(colorInt[2], colorSomewhatGreenInt[2]);
3196 EXPECT_EQ(colorInt[3], colorSomewhatGreenInt[3]);
3197
3198 constexpr GLuint colorSomewhatGreenUInt[4] = {0, 500000, 0, std::numeric_limits<GLuint>::max()};
3199 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenUInt);
3200 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3201 EXPECT_EQ(colorUInt[0], colorSomewhatGreenUInt[0]);
3202 EXPECT_EQ(colorUInt[1], colorSomewhatGreenUInt[1]);
3203 EXPECT_EQ(colorUInt[2], colorSomewhatGreenUInt[2]);
3204 EXPECT_EQ(colorUInt[3], colorSomewhatGreenUInt[3]);
3205}
3206
3207// Test GL_TEXTURE_BORDER_COLOR parameter validation at glSamplerParameter.
3208TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Validation)
3209{
Jamie Madillb8149072019-04-30 16:14:44 -04003210 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003211
3212 glActiveTexture(GL_TEXTURE0);
3213
3214 GLSampler sampler;
3215 glBindSampler(0, sampler);
3216
3217 glSamplerParameterf(sampler, GL_TEXTURE_BORDER_COLOR, 1.0f);
3218 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3219
3220 glSamplerParameteri(sampler, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3221 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3222}
3223
3224class TextureBorderClampIntegerTestES3 : public Texture2DTest
3225{
3226 protected:
3227 TextureBorderClampIntegerTestES3() : Texture2DTest(), isUnsignedIntTest(false) {}
3228
Jamie Madill35cd7332018-12-02 12:03:33 -05003229 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003230 {
3231 return
3232 R"(#version 300 es
3233 out vec2 texcoord;
3234 in vec4 position;
3235
3236 void main()
3237 {
3238 gl_Position = vec4(position.xy, 0.0, 1.0);
3239 // texcoords in [-0.5, 1.5]
3240 texcoord = (position.xy) + 0.5;
3241 })";
3242 }
3243
Jamie Madillba319ba2018-12-29 10:29:33 -05003244 const char *getFragmentShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003245 {
Jamie Madill35cd7332018-12-02 12:03:33 -05003246 if (isUnsignedIntTest)
3247 {
3248 return "#version 300 es\n"
3249 "precision highp float;\n"
3250 "uniform highp usampler2D tex;\n"
3251 "in vec2 texcoord;\n"
3252 "out vec4 fragColor;\n"
Till Rathmannb8543632018-10-02 19:46:14 +02003253
Jamie Madill35cd7332018-12-02 12:03:33 -05003254 "void main()\n"
3255 "{\n"
3256 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3257 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3258 "fragColor = (texture(tex, texcoord).r == 150u)"
3259 " ? green : red;\n"
3260 "}\n";
3261 }
3262 else
3263 {
3264 return "#version 300 es\n"
3265 "precision highp float;\n"
3266 "uniform highp isampler2D tex;\n"
3267 "in vec2 texcoord;\n"
3268 "out vec4 fragColor;\n"
3269
3270 "void main()\n"
3271 "{\n"
3272 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3273 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3274 "fragColor = (texture(tex, texcoord).r == -50)"
3275 " ? green : red;\n"
3276 "}\n";
3277 }
Till Rathmannb8543632018-10-02 19:46:14 +02003278 }
3279
3280 void uploadTexture()
3281 {
3282 glActiveTexture(GL_TEXTURE0);
3283 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3284 if (isUnsignedIntTest)
3285 {
3286 std::vector<GLubyte> texData(4, 100);
3287 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE,
3288 texData.data());
3289 }
3290 else
3291 {
3292 std::vector<GLbyte> texData(4, 100);
3293 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8I, 1, 1, 0, GL_RGBA_INTEGER, GL_BYTE,
3294 texData.data());
3295 }
3296 EXPECT_GL_NO_ERROR();
3297 }
3298
3299 bool isUnsignedIntTest;
3300};
3301
3302// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3303// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3304TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger)
3305{
Jamie Madillb8149072019-04-30 16:14:44 -04003306 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003307
3308 setUpProgram();
3309
3310 uploadTexture();
3311
3312 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3313 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3314 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3315 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3316
3317 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3318 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3319
3320 EXPECT_GL_NO_ERROR();
3321
3322 drawQuad(mProgram, "position", 0.5f);
3323
3324 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3325 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3326 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3327}
3328
3329// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3330// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3331TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger2)
3332{
Jamie Madillb8149072019-04-30 16:14:44 -04003333 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003334
3335 setUpProgram();
3336
3337 uploadTexture();
3338
3339 GLSampler sampler;
3340 glBindSampler(0, sampler);
3341 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3342 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3343 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3344 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3345
3346 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3347 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3348
3349 EXPECT_GL_NO_ERROR();
3350
3351 drawQuad(mProgram, "position", 0.5f);
3352
3353 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3354 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3355 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3356}
3357
3358// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3359// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIuivOES).
3360TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned)
3361{
Jamie Madillb8149072019-04-30 16:14:44 -04003362 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003363
3364 isUnsignedIntTest = true;
3365
3366 setUpProgram();
3367
3368 uploadTexture();
3369
3370 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3371 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3372 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3373 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3374
3375 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3376 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3377
3378 EXPECT_GL_NO_ERROR();
3379
3380 drawQuad(mProgram, "position", 0.5f);
3381
3382 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3383 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3384 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3385}
3386
3387// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3388// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with
3389// glSamplerParameterIuivOES).
3390TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned2)
3391{
Jamie Madillb8149072019-04-30 16:14:44 -04003392 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003393
3394 isUnsignedIntTest = true;
3395
3396 setUpProgram();
3397
3398 uploadTexture();
3399
3400 GLSampler sampler;
3401 glBindSampler(0, sampler);
3402 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3403 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3404 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3405 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3406
3407 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3408 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3409
3410 EXPECT_GL_NO_ERROR();
3411
3412 drawQuad(mProgram, "position", 0.5f);
3413
3414 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3415 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3416 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3417}
3418
3419// ~GL_OES_texture_border_clamp
3420
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003421class TextureLimitsTest : public ANGLETest
3422{
3423 protected:
3424 struct RGBA8
3425 {
3426 uint8_t R, G, B, A;
3427 };
3428
3429 TextureLimitsTest()
3430 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
3431 {
3432 setWindowWidth(128);
3433 setWindowHeight(128);
3434 setConfigRedBits(8);
3435 setConfigGreenBits(8);
3436 setConfigBlueBits(8);
3437 setConfigAlphaBits(8);
3438 }
3439
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003440 void testSetUp() override
Jamie Madill0fdb9562018-09-17 17:18:43 -04003441 {
Jamie Madill0fdb9562018-09-17 17:18:43 -04003442 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
3443 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
3444 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
3445
3446 ASSERT_GL_NO_ERROR();
3447 }
3448
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003449 void testTearDown() override
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003450 {
3451 if (mProgram != 0)
3452 {
3453 glDeleteProgram(mProgram);
3454 mProgram = 0;
3455
3456 if (!mTextures.empty())
3457 {
3458 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
3459 }
3460 }
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003461 }
3462
3463 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
3464 GLint vertexTextureCount,
3465 GLint vertexActiveTextureCount,
3466 const std::string &fragPrefix,
3467 GLint fragmentTextureCount,
3468 GLint fragmentActiveTextureCount)
3469 {
3470 std::stringstream vertexShaderStr;
3471 vertexShaderStr << "attribute vec2 position;\n"
3472 << "varying vec4 color;\n"
3473 << "varying vec2 texCoord;\n";
3474
3475 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
3476 {
3477 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
3478 }
3479
3480 vertexShaderStr << "void main() {\n"
3481 << " gl_Position = vec4(position, 0, 1);\n"
3482 << " texCoord = (position * 0.5) + 0.5;\n"
3483 << " color = vec4(0);\n";
3484
3485 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
3486 {
3487 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
3488 << ", texCoord);\n";
3489 }
3490
3491 vertexShaderStr << "}";
3492
3493 std::stringstream fragmentShaderStr;
3494 fragmentShaderStr << "varying mediump vec4 color;\n"
3495 << "varying mediump vec2 texCoord;\n";
3496
3497 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
3498 {
3499 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
3500 }
3501
3502 fragmentShaderStr << "void main() {\n"
3503 << " gl_FragColor = color;\n";
3504
3505 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
3506 {
3507 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
3508 << ", texCoord);\n";
3509 }
3510
3511 fragmentShaderStr << "}";
3512
3513 const std::string &vertexShaderSource = vertexShaderStr.str();
3514 const std::string &fragmentShaderSource = fragmentShaderStr.str();
3515
Jamie Madill35cd7332018-12-02 12:03:33 -05003516 mProgram = CompileProgram(vertexShaderSource.c_str(), fragmentShaderSource.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003517 }
3518
3519 RGBA8 getPixel(GLint texIndex)
3520 {
3521 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3522 0, 255u};
3523 return pixel;
3524 }
3525
3526 void initTextures(GLint tex2DCount, GLint texCubeCount)
3527 {
3528 GLint totalCount = tex2DCount + texCubeCount;
3529 mTextures.assign(totalCount, 0);
3530 glGenTextures(totalCount, &mTextures[0]);
3531 ASSERT_GL_NO_ERROR();
3532
3533 std::vector<RGBA8> texData(16 * 16);
3534
3535 GLint texIndex = 0;
3536 for (; texIndex < tex2DCount; ++texIndex)
3537 {
3538 texData.assign(texData.size(), getPixel(texIndex));
3539 glActiveTexture(GL_TEXTURE0 + texIndex);
3540 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3541 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3542 &texData[0]);
3543 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3544 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3545 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3546 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3547 }
3548
3549 ASSERT_GL_NO_ERROR();
3550
3551 for (; texIndex < texCubeCount; ++texIndex)
3552 {
3553 texData.assign(texData.size(), getPixel(texIndex));
3554 glActiveTexture(GL_TEXTURE0 + texIndex);
3555 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3556 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3557 GL_UNSIGNED_BYTE, &texData[0]);
3558 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3559 GL_UNSIGNED_BYTE, &texData[0]);
3560 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3561 GL_UNSIGNED_BYTE, &texData[0]);
3562 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3563 GL_UNSIGNED_BYTE, &texData[0]);
3564 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3565 GL_UNSIGNED_BYTE, &texData[0]);
3566 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3567 GL_UNSIGNED_BYTE, &texData[0]);
3568 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3569 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3570 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3571 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3572 }
3573
3574 ASSERT_GL_NO_ERROR();
3575 }
3576
3577 void testWithTextures(GLint vertexTextureCount,
3578 const std::string &vertexTexturePrefix,
3579 GLint fragmentTextureCount,
3580 const std::string &fragmentTexturePrefix)
3581 {
3582 // Generate textures
3583 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3584
3585 glUseProgram(mProgram);
3586 RGBA8 expectedSum = {0};
3587 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3588 {
3589 std::stringstream uniformNameStr;
3590 uniformNameStr << vertexTexturePrefix << texIndex;
3591 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003592 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003593 ASSERT_NE(-1, location);
3594
3595 glUniform1i(location, texIndex);
3596 RGBA8 contribution = getPixel(texIndex);
3597 expectedSum.R += contribution.R;
3598 expectedSum.G += contribution.G;
3599 }
3600
3601 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3602 {
3603 std::stringstream uniformNameStr;
3604 uniformNameStr << fragmentTexturePrefix << texIndex;
3605 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003606 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003607 ASSERT_NE(-1, location);
3608
3609 glUniform1i(location, texIndex + vertexTextureCount);
3610 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3611 expectedSum.R += contribution.R;
3612 expectedSum.G += contribution.G;
3613 }
3614
3615 ASSERT_GE(256u, expectedSum.G);
3616
3617 drawQuad(mProgram, "position", 0.5f);
3618 ASSERT_GL_NO_ERROR();
3619 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3620 }
3621
3622 GLuint mProgram;
3623 std::vector<GLuint> mTextures;
3624 GLint mMaxVertexTextures;
3625 GLint mMaxFragmentTextures;
3626 GLint mMaxCombinedTextures;
3627};
3628
3629// Test rendering with the maximum vertex texture units.
3630TEST_P(TextureLimitsTest, MaxVertexTextures)
3631{
3632 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3633 ASSERT_NE(0u, mProgram);
3634 ASSERT_GL_NO_ERROR();
3635
3636 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3637}
3638
3639// Test rendering with the maximum fragment texture units.
3640TEST_P(TextureLimitsTest, MaxFragmentTextures)
3641{
3642 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3643 ASSERT_NE(0u, mProgram);
3644 ASSERT_GL_NO_ERROR();
3645
3646 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3647}
3648
3649// Test rendering with maximum combined texture units.
3650TEST_P(TextureLimitsTest, MaxCombinedTextures)
3651{
3652 GLint vertexTextures = mMaxVertexTextures;
3653
3654 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3655 {
3656 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3657 }
3658
3659 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3660 mMaxFragmentTextures, mMaxFragmentTextures);
3661 ASSERT_NE(0u, mProgram);
3662 ASSERT_GL_NO_ERROR();
3663
3664 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3665}
3666
3667// Negative test for exceeding the number of vertex textures
3668TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3669{
3670 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3671 0);
3672 ASSERT_EQ(0u, mProgram);
3673}
3674
3675// Negative test for exceeding the number of fragment textures
3676TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3677{
3678 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3679 mMaxFragmentTextures + 1);
3680 ASSERT_EQ(0u, mProgram);
3681}
3682
3683// Test active vertex textures under the limit, but excessive textures specified.
3684TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3685{
3686 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3687 ASSERT_NE(0u, mProgram);
3688 ASSERT_GL_NO_ERROR();
3689
3690 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3691}
3692
3693// Test active fragment textures under the limit, but excessive textures specified.
3694TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3695{
3696 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3697 mMaxFragmentTextures);
3698 ASSERT_NE(0u, mProgram);
3699 ASSERT_GL_NO_ERROR();
3700
3701 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3702}
3703
3704// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003705// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003706TEST_P(TextureLimitsTest, TextureTypeConflict)
3707{
Jamie Madill35cd7332018-12-02 12:03:33 -05003708 constexpr char kVS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003709 "attribute vec2 position;\n"
3710 "varying float color;\n"
3711 "uniform sampler2D tex2D;\n"
3712 "uniform samplerCube texCube;\n"
3713 "void main() {\n"
3714 " gl_Position = vec4(position, 0, 1);\n"
3715 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3716 " color = texture2D(tex2D, texCoord).x;\n"
3717 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3718 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05003719 constexpr char kFS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003720 "varying mediump float color;\n"
3721 "void main() {\n"
3722 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3723 "}";
3724
Jamie Madill35cd7332018-12-02 12:03:33 -05003725 mProgram = CompileProgram(kVS, kFS);
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003726 ASSERT_NE(0u, mProgram);
3727
3728 initTextures(1, 0);
3729
3730 glUseProgram(mProgram);
3731 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3732 ASSERT_NE(-1, tex2DLocation);
3733 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3734 ASSERT_NE(-1, texCubeLocation);
3735
3736 glUniform1i(tex2DLocation, 0);
3737 glUniform1i(texCubeLocation, 0);
3738 ASSERT_GL_NO_ERROR();
3739
3740 drawQuad(mProgram, "position", 0.5f);
3741 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3742}
3743
Vincent Lang25ab4512016-05-13 18:13:59 +02003744class Texture2DNorm16TestES3 : public Texture2DTestES3
3745{
3746 protected:
3747 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3748
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003749 void testSetUp() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003750 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003751 Texture2DTestES3::testSetUp();
Vincent Lang25ab4512016-05-13 18:13:59 +02003752
3753 glActiveTexture(GL_TEXTURE0);
3754 glGenTextures(3, mTextures);
3755 glGenFramebuffers(1, &mFBO);
3756 glGenRenderbuffers(1, &mRenderbuffer);
3757
3758 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3759 {
3760 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3761 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3762 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3763 }
3764
3765 glBindTexture(GL_TEXTURE_2D, 0);
3766
3767 ASSERT_GL_NO_ERROR();
3768 }
3769
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003770 void testTearDown() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003771 {
3772 glDeleteTextures(3, mTextures);
3773 glDeleteFramebuffers(1, &mFBO);
3774 glDeleteRenderbuffers(1, &mRenderbuffer);
3775
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003776 Texture2DTestES3::testTearDown();
Vincent Lang25ab4512016-05-13 18:13:59 +02003777 }
3778
3779 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3780 {
Geoff Langf607c602016-09-21 11:46:48 -04003781 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3782 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003783
3784 setUpProgram();
3785
3786 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3787 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3788 0);
3789
3790 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3791 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3792
3793 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003794 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003795
3796 EXPECT_GL_NO_ERROR();
3797
3798 drawQuad(mProgram, "position", 0.5f);
3799
Geoff Langf607c602016-09-21 11:46:48 -04003800 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003801
Jamie Madill50cf2be2018-06-15 09:46:57 -04003802 EXPECT_PIXEL_COLOR_EQ(0, 0,
3803 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3804 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003805
3806 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3807
3808 ASSERT_GL_NO_ERROR();
3809 }
3810
3811 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3812 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04003813 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003814 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003815
3816 setUpProgram();
3817
3818 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3819 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3820
3821 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3822 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3823 0);
3824
3825 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003826 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003827
3828 EXPECT_GL_NO_ERROR();
3829
3830 drawQuad(mProgram, "position", 0.5f);
3831
Geoff Langf607c602016-09-21 11:46:48 -04003832 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
Jamie Madill50cf2be2018-06-15 09:46:57 -04003833 EXPECT_PIXEL_COLOR_EQ(0, 0,
3834 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3835 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003836
3837 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3838 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3839 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3840 mRenderbuffer);
3841 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3842 EXPECT_GL_NO_ERROR();
3843
3844 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3845 glClear(GL_COLOR_BUFFER_BIT);
3846
3847 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3848
Geoff Langf607c602016-09-21 11:46:48 -04003849 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003850
3851 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3852
3853 ASSERT_GL_NO_ERROR();
3854 }
3855
3856 GLuint mTextures[3];
3857 GLuint mFBO;
3858 GLuint mRenderbuffer;
3859};
3860
3861// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3862TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3863{
Jamie Madillb8149072019-04-30 16:14:44 -04003864 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02003865
3866 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3867 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3868 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3869 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3870 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3871 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3872 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3873 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3874
3875 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3876 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3877 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3878}
3879
Olli Etuaho95faa232016-06-07 14:01:53 -07003880// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3881// GLES 3.0.4 section 3.8.3.
3882TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3883{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003884 // Crashes on Nexus 5X due to a driver bug. http://anglebug.com/1429
3885 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07003886
3887 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3888 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3889 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3890 ASSERT_GL_NO_ERROR();
3891
3892 // SKIP_IMAGES should not have an effect on uploading 2D textures
3893 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3894 ASSERT_GL_NO_ERROR();
3895
3896 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3897
3898 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3899 pixelsGreen.data());
3900 ASSERT_GL_NO_ERROR();
3901
3902 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3903 pixelsGreen.data());
3904 ASSERT_GL_NO_ERROR();
3905
3906 glUseProgram(mProgram);
3907 drawQuad(mProgram, "position", 0.5f);
3908 ASSERT_GL_NO_ERROR();
3909
3910 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3911}
3912
Olli Etuaho989cac32016-06-08 16:18:49 -07003913// Test that skip defined in unpack parameters is taken into account when determining whether
3914// unpacking source extends outside unpack buffer bounds.
3915TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3916{
3917 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3918 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3919 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3920 ASSERT_GL_NO_ERROR();
3921
3922 GLBuffer buf;
3923 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3924 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3925 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3926 GL_DYNAMIC_COPY);
3927 ASSERT_GL_NO_ERROR();
3928
3929 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3930 ASSERT_GL_NO_ERROR();
3931
3932 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3933 ASSERT_GL_NO_ERROR();
3934
3935 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3936 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3937
3938 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3939 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3940 ASSERT_GL_NO_ERROR();
3941
3942 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3943 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3944}
3945
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003946// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3947TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3948{
Yunchao He9550c602018-02-13 14:47:05 +08003949 ANGLE_SKIP_TEST_IF(IsD3D11());
3950
3951 // Incorrect rendering results seen on OSX AMD.
3952 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003953
3954 const GLuint width = 8u;
3955 const GLuint height = 8u;
3956 const GLuint unpackRowLength = 5u;
3957 const GLuint unpackSkipPixels = 1u;
3958
3959 setWindowWidth(width);
3960 setWindowHeight(height);
3961
3962 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3963 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3964 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3965 ASSERT_GL_NO_ERROR();
3966
3967 GLBuffer buf;
3968 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3969 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3970 GLColor::green);
3971
3972 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3973 {
3974 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3975 }
3976
3977 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3978 GL_DYNAMIC_COPY);
3979 ASSERT_GL_NO_ERROR();
3980
3981 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3982 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3983 ASSERT_GL_NO_ERROR();
3984
3985 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3986 ASSERT_GL_NO_ERROR();
3987
3988 glUseProgram(mProgram);
3989 drawQuad(mProgram, "position", 0.5f);
3990 ASSERT_GL_NO_ERROR();
3991
3992 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3993 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3994 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3995 actual.data());
3996 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3997 EXPECT_EQ(expected, actual);
3998}
3999
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004000template <typename T>
4001T UNorm(double value)
4002{
4003 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
4004}
4005
4006// Test rendering a depth texture with mipmaps.
4007TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
4008{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08004009 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
4010 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
Jiawei Shaoaf0f31d2018-09-27 15:42:31 +08004011 // http://anglebug.com/1706
4012 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Corentin Walleze731d8a2016-09-07 10:56:25 -04004013
Jamie Madill24980272019-04-03 09:03:51 -04004014 // Seems to fail on AMD D3D11. Possibly driver bug. http://anglebug.com/3342
4015 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsD3D11());
4016
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004017 const int size = getWindowWidth();
4018
4019 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04004020 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004021
4022 glActiveTexture(GL_TEXTURE0);
4023 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4024 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
4025 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4026 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4027 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
4028 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
4029 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4030 ASSERT_GL_NO_ERROR();
4031
4032 glUseProgram(mProgram);
4033 glUniform1i(mTexture2DUniformLocation, 0);
4034
4035 std::vector<unsigned char> expected;
4036
4037 for (int level = 0; level < levels; ++level)
4038 {
4039 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
4040 expected.push_back(UNorm<unsigned char>(value));
4041
4042 int levelDim = dim(level);
4043
4044 ASSERT_GT(levelDim, 0);
4045
4046 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
4047 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
4048 GL_UNSIGNED_INT, initData.data());
4049 }
4050 ASSERT_GL_NO_ERROR();
4051
4052 for (int level = 0; level < levels; ++level)
4053 {
4054 glViewport(0, 0, dim(level), dim(level));
4055 drawQuad(mProgram, "position", 0.5f);
4056 GLColor actual = ReadColor(0, 0);
4057 EXPECT_NEAR(expected[level], actual.R, 10u);
4058 }
4059
4060 ASSERT_GL_NO_ERROR();
4061}
4062
Jamie Madill7ffdda92016-09-08 13:26:51 -04004063// Tests unpacking into the unsized GL_ALPHA format.
4064TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
4065{
Jamie Madill7ffdda92016-09-08 13:26:51 -04004066 // Initialize the texure.
4067 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4068 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
4069 GL_UNSIGNED_BYTE, nullptr);
4070 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4071 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4072
4073 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
4074
4075 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04004076 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04004077 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4078 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4079 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
4080 GL_STATIC_DRAW);
4081
4082 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
4083 GL_UNSIGNED_BYTE, nullptr);
4084
4085 // Clear to a weird color to make sure we're drawing something.
4086 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
4087 glClear(GL_COLOR_BUFFER_BIT);
4088
4089 // Draw with the alpha texture and verify.
4090 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04004091
4092 ASSERT_GL_NO_ERROR();
4093 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
4094}
4095
Jamie Madill2e600342016-09-19 13:56:40 -04004096// Ensure stale unpack data doesn't propagate in D3D11.
4097TEST_P(Texture2DTestES3, StaleUnpackData)
4098{
4099 // Init unpack buffer.
4100 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
4101 std::vector<GLColor> pixels(pixelCount, GLColor::red);
4102
4103 GLBuffer unpackBuffer;
4104 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4105 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4106 GLsizei bufferSize = pixelCount * sizeof(GLColor);
4107 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
4108
4109 // Create from unpack buffer.
4110 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4111 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
4112 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4113 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4114 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4115
4116 drawQuad(mProgram, "position", 0.5f);
4117
4118 ASSERT_GL_NO_ERROR();
4119 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4120
4121 // Fill unpack with green, recreating buffer.
4122 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
4123 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
4124 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
4125
4126 // Reinit texture with green.
4127 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
4128 GL_UNSIGNED_BYTE, nullptr);
4129
4130 drawQuad(mProgram, "position", 0.5f);
4131
4132 ASSERT_GL_NO_ERROR();
4133 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
4134}
4135
Geoff Langfb7685f2017-11-13 11:44:11 -05004136// Ensure that texture parameters passed as floats that are converted to ints are rounded before
4137// validating they are less than 0.
4138TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
4139{
4140 GLTexture texture;
4141 glBindTexture(GL_TEXTURE_2D, texture);
4142
4143 // Use a negative number that will round to zero when converted to an integer
4144 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
4145 // "Validation of values performed by state-setting commands is performed after conversion,
4146 // unless specified otherwise for a specific command."
4147 GLfloat param = -7.30157126e-07f;
4148 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
4149 EXPECT_GL_NO_ERROR();
4150
4151 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
4152 EXPECT_GL_NO_ERROR();
4153}
4154
Jamie Madillf097e232016-11-05 00:44:15 -04004155// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
4156// being properly checked, and the texture storage of the previous texture format was persisting.
4157// This would result in an ASSERT in debug and incorrect rendering in release.
4158// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
4159TEST_P(Texture3DTestES3, FormatRedefinitionBug)
4160{
4161 GLTexture tex;
4162 glBindTexture(GL_TEXTURE_3D, tex.get());
4163 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4164
4165 GLFramebuffer framebuffer;
4166 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
4167 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
4168
4169 glCheckFramebufferStatus(GL_FRAMEBUFFER);
4170
4171 std::vector<uint8_t> pixelData(100, 0);
4172
4173 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
4174 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
4175 pixelData.data());
4176
4177 ASSERT_GL_NO_ERROR();
4178}
4179
Corentin Wallezd2627992017-04-28 17:17:03 -04004180// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
4181TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
4182{
4183 // 2D tests
4184 {
4185 GLTexture tex;
4186 glBindTexture(GL_TEXTURE_2D, tex.get());
4187
4188 GLBuffer pbo;
4189 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4190
4191 // Test OOB
4192 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
4193 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4194 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4195
4196 // Test OOB
4197 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
4198 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4199 ASSERT_GL_NO_ERROR();
4200 }
4201
4202 // 3D tests
4203 {
4204 GLTexture tex;
4205 glBindTexture(GL_TEXTURE_3D, tex.get());
4206
4207 GLBuffer pbo;
4208 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4209
4210 // Test OOB
4211 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
4212 GL_STATIC_DRAW);
4213 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4214 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4215
4216 // Test OOB
4217 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
4218 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4219 ASSERT_GL_NO_ERROR();
4220 }
4221}
4222
Jamie Madill3ed60422017-09-07 11:32:52 -04004223// Tests behaviour with a single texture and multiple sampler objects.
4224TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
4225{
4226 GLint maxTextureUnits = 0;
4227 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
4228 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
4229
4230 constexpr int kSize = 16;
4231
4232 // Make a single-level texture, fill it with red.
4233 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
4234 GLTexture tex;
4235 glBindTexture(GL_TEXTURE_2D, tex);
4236 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4237 redColors.data());
4238 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4239 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4240
4241 // Simple sanity check.
4242 draw2DTexturedQuad(0.5f, 1.0f, true);
4243 ASSERT_GL_NO_ERROR();
4244 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4245
4246 // Bind texture to unit 1 with a sampler object making it incomplete.
4247 GLSampler sampler;
4248 glBindSampler(0, sampler);
4249 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4250 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4251
4252 // Make a mipmap texture, fill it with blue.
4253 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
4254 GLTexture mipmapTex;
4255 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4256 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4257 blueColors.data());
4258 glGenerateMipmap(GL_TEXTURE_2D);
4259
4260 // Draw with the sampler, expect blue.
4261 draw2DTexturedQuad(0.5f, 1.0f, true);
4262 ASSERT_GL_NO_ERROR();
4263 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
4264
4265 // Simple multitexturing program.
Jamie Madill35cd7332018-12-02 12:03:33 -05004266 constexpr char kVS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004267 "#version 300 es\n"
4268 "in vec2 position;\n"
4269 "out vec2 texCoord;\n"
4270 "void main()\n"
4271 "{\n"
4272 " gl_Position = vec4(position, 0, 1);\n"
4273 " texCoord = position * 0.5 + vec2(0.5);\n"
4274 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05004275
4276 constexpr char kFS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004277 "#version 300 es\n"
4278 "precision mediump float;\n"
4279 "in vec2 texCoord;\n"
4280 "uniform sampler2D tex1;\n"
4281 "uniform sampler2D tex2;\n"
4282 "uniform sampler2D tex3;\n"
4283 "uniform sampler2D tex4;\n"
4284 "out vec4 color;\n"
4285 "void main()\n"
4286 "{\n"
4287 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
4288 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
4289 "}";
4290
Jamie Madill35cd7332018-12-02 12:03:33 -05004291 ANGLE_GL_PROGRAM(program, kVS, kFS);
Jamie Madill3ed60422017-09-07 11:32:52 -04004292
4293 std::array<GLint, 4> texLocations = {
4294 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
4295 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
4296 for (GLint location : texLocations)
4297 {
4298 ASSERT_NE(-1, location);
4299 }
4300
4301 // Init the uniform data.
4302 glUseProgram(program);
4303 for (GLint location = 0; location < 4; ++location)
4304 {
4305 glUniform1i(texLocations[location], location);
4306 }
4307
4308 // Initialize four samplers
4309 GLSampler samplers[4];
4310
4311 // 0: non-mipped.
4312 glBindSampler(0, samplers[0]);
4313 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4314 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4315
4316 // 1: mipped.
4317 glBindSampler(1, samplers[1]);
4318 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4319 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4320
4321 // 2: non-mipped.
4322 glBindSampler(2, samplers[2]);
4323 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4324 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4325
4326 // 3: mipped.
4327 glBindSampler(3, samplers[3]);
4328 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4329 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4330
4331 // Bind two blue mipped textures and two single layer textures, should all draw.
4332 glActiveTexture(GL_TEXTURE0);
4333 glBindTexture(GL_TEXTURE_2D, tex);
4334
4335 glActiveTexture(GL_TEXTURE1);
4336 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4337
4338 glActiveTexture(GL_TEXTURE2);
4339 glBindTexture(GL_TEXTURE_2D, tex);
4340
4341 glActiveTexture(GL_TEXTURE3);
4342 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4343
4344 ASSERT_GL_NO_ERROR();
4345
4346 drawQuad(program, "position", 0.5f);
4347 ASSERT_GL_NO_ERROR();
4348 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
4349
4350 // Bind four single layer textures, two should be incomplete.
4351 glActiveTexture(GL_TEXTURE1);
4352 glBindTexture(GL_TEXTURE_2D, tex);
4353
4354 glActiveTexture(GL_TEXTURE3);
4355 glBindTexture(GL_TEXTURE_2D, tex);
4356
4357 drawQuad(program, "position", 0.5f);
4358 ASSERT_GL_NO_ERROR();
4359 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
4360}
4361
Martin Radev7e2c0d32017-09-15 14:25:42 +03004362// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
4363// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
4364// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
4365// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
4366// samples the cubemap using a direction vector (1,1,1).
4367TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
4368{
Yunchao He2f23f352018-02-11 22:11:37 +08004369 // Check http://anglebug.com/2155.
4370 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
4371
Jamie Madill35cd7332018-12-02 12:03:33 -05004372 constexpr char kVS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004373 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004374 precision mediump float;
4375 in vec3 pos;
4376 void main() {
4377 gl_Position = vec4(pos, 1.0);
4378 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03004379
Jamie Madill35cd7332018-12-02 12:03:33 -05004380 constexpr char kFS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004381 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004382 precision mediump float;
4383 out vec4 color;
4384 uniform samplerCube uTex;
4385 void main(){
4386 color = texture(uTex, vec3(1.0));
4387 })";
Jamie Madill35cd7332018-12-02 12:03:33 -05004388
4389 ANGLE_GL_PROGRAM(program, kVS, kFS);
Martin Radev7e2c0d32017-09-15 14:25:42 +03004390 glUseProgram(program);
4391
4392 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
4393 glActiveTexture(GL_TEXTURE0);
4394
4395 GLTexture cubeTex;
4396 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
4397
4398 const int kFaceWidth = 1;
4399 const int kFaceHeight = 1;
4400 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
4401 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4402 GL_UNSIGNED_BYTE, texData.data());
4403 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4404 GL_UNSIGNED_BYTE, texData.data());
4405 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4406 GL_UNSIGNED_BYTE, texData.data());
4407 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4408 GL_UNSIGNED_BYTE, texData.data());
4409 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4410 GL_UNSIGNED_BYTE, texData.data());
4411 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4412 GL_UNSIGNED_BYTE, texData.data());
4413 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4414 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4415 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
4416 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
4417 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
4418 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
4419
4420 drawQuad(program, "pos", 0.5f, 1.0f, true);
4421 ASSERT_GL_NO_ERROR();
4422
4423 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4424}
4425
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08004426// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
4427TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
4428{
4429 GLuint texture = create2DTexture();
4430
4431 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
4432 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4433
4434 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
4435 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4436
4437 glDeleteTextures(1, &texture);
4438 EXPECT_GL_NO_ERROR();
4439}
4440
Olli Etuaho023371b2018-04-24 17:43:32 +03004441// Test setting base level after calling generateMipmap on a LUMA texture.
4442// Covers http://anglebug.com/2498
4443TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA)
4444{
4445 glActiveTexture(GL_TEXTURE0);
4446 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4447
4448 constexpr const GLsizei kWidth = 8;
4449 constexpr const GLsizei kHeight = 8;
4450 std::array<GLubyte, kWidth * kHeight * 2> whiteData;
4451 whiteData.fill(255u);
4452
4453 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA,
4454 GL_UNSIGNED_BYTE, whiteData.data());
4455 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
4456 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4457 glGenerateMipmap(GL_TEXTURE_2D);
4458 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
4459 EXPECT_GL_NO_ERROR();
4460
4461 drawQuad(mProgram, "position", 0.5f);
4462 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4463}
4464
Till Rathmannc1551dc2018-08-15 17:04:49 +02004465// Covers a bug in the D3D11 backend: http://anglebug.com/2772
4466// When using a sampler the texture was created as if it has mipmaps,
4467// regardless what you specified in GL_TEXTURE_MIN_FILTER via
4468// glSamplerParameteri() -- mistakenly the default value
4469// GL_NEAREST_MIPMAP_LINEAR or the value set via glTexParameteri() was
4470// evaluated.
4471// If you didn't provide mipmaps and didn't let the driver generate them
4472// this led to not sampling your texture data when minification occurred.
4473TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping)
4474{
Jamie Madill35cd7332018-12-02 12:03:33 -05004475 constexpr char kVS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004476 "#version 300 es\n"
4477 "out vec2 texcoord;\n"
4478 "in vec4 position;\n"
4479 "void main()\n"
4480 "{\n"
4481 " gl_Position = vec4(position.xy * 0.1, 0.0, 1.0);\n"
4482 " texcoord = (position.xy * 0.5) + 0.5;\n"
4483 "}\n";
4484
Jamie Madill35cd7332018-12-02 12:03:33 -05004485 constexpr char kFS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004486 "#version 300 es\n"
4487 "precision highp float;\n"
4488 "uniform highp sampler2D tex;\n"
4489 "in vec2 texcoord;\n"
4490 "out vec4 fragColor;\n"
4491 "void main()\n"
4492 "{\n"
4493 " fragColor = texture(tex, texcoord);\n"
4494 "}\n";
Jamie Madill35cd7332018-12-02 12:03:33 -05004495
4496 ANGLE_GL_PROGRAM(program, kVS, kFS);
Till Rathmannc1551dc2018-08-15 17:04:49 +02004497
4498 GLSampler sampler;
4499 glBindSampler(0, sampler);
4500 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4501 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4502
4503 glActiveTexture(GL_TEXTURE0);
4504 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4505
4506 const GLsizei texWidth = getWindowWidth();
4507 const GLsizei texHeight = getWindowHeight();
4508 const std::vector<GLColor> whiteData(texWidth * texHeight, GLColor::white);
4509
4510 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4511 whiteData.data());
4512 EXPECT_GL_NO_ERROR();
4513
4514 drawQuad(program, "position", 0.5f);
4515 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, angle::GLColor::white);
4516}
4517
Anders Leinof6cbe442019-04-18 15:32:07 +03004518// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4519// texture is output.
4520TEST_P(Texture2DIntegerTestES3, IntegerTextureNonZeroBaseLevel)
4521{
Jamie Madill36f47162019-05-15 15:36:06 -04004522 // Flaky on Windows OpenGL drivers. http://crbug.com/963595
4523 ANGLE_SKIP_TEST_IF(IsOpenGL() && IsWindows());
4524
Anders Leinof6cbe442019-04-18 15:32:07 +03004525 glActiveTexture(GL_TEXTURE0);
4526 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4527 int width = getWindowWidth();
4528 int height = getWindowHeight();
4529 GLColor color = GLColor::green;
4530 std::vector<GLColor> pixels(width * height, color);
4531 GLint baseLevel = 1;
4532 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
4533 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4534 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4535 glTexImage2D(GL_TEXTURE_2D, baseLevel, GL_RGBA8UI, width, height, 0, GL_RGBA_INTEGER,
4536 GL_UNSIGNED_BYTE, pixels.data());
4537
4538 setUpProgram();
4539 glUseProgram(mProgram);
4540 glUniform1i(mTexture2DUniformLocation, 0);
4541 drawQuad(mProgram, "position", 0.5f);
4542
4543 EXPECT_GL_NO_ERROR();
4544 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4545 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4546}
4547
Anders Leino60cc7512019-05-06 09:25:27 +03004548// Draw a quad with an integer cube texture with a non-zero base level, and test that the color of
4549// the texture is output.
4550TEST_P(TextureCubeIntegerTestES3, IntegerCubeTextureNonZeroBaseLevel)
4551{
4552 // All output checks returned black, rather than the texture color.
4553 ANGLE_SKIP_TEST_IF(IsOSX() && IsOpenGL());
4554
4555 glActiveTexture(GL_TEXTURE0);
4556
4557 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
4558 GLint baseLevel = 1;
4559 int width = getWindowWidth();
4560 int height = getWindowHeight();
4561 GLColor color = GLColor::green;
4562 std::vector<GLColor> pixels(width * height, color);
4563 for (GLenum faceIndex = 0; faceIndex < 6; faceIndex++)
4564 {
4565 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, baseLevel, GL_RGBA8UI, width,
4566 height, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
4567 EXPECT_GL_NO_ERROR();
4568 }
4569 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, baseLevel);
4570 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4571 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4572
4573 glUseProgram(mProgram);
4574 glUniform1i(mTextureCubeUniformLocation, 0);
4575 drawQuad(mProgram, "position", 0.5f);
4576
4577 EXPECT_GL_NO_ERROR();
4578 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4579 EXPECT_PIXEL_COLOR_EQ(width - 1, 0, color);
4580 EXPECT_PIXEL_COLOR_EQ(0, height - 1, color);
4581 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4582}
4583
Jamie Madill50cf2be2018-06-15 09:46:57 -04004584// Use this to select which configurations (e.g. which renderer, which GLES major version) these
4585// tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -05004586ANGLE_INSTANTIATE_TEST(Texture2DTest,
4587 ES2_D3D9(),
4588 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004589 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05004590 ES2_OPENGLES(),
4591 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004592ANGLE_INSTANTIATE_TEST(TextureCubeTest,
4593 ES2_D3D9(),
4594 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004595 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004596 ES2_OPENGLES(),
4597 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004598ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
4599 ES2_D3D9(),
4600 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004601 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004602 ES2_OPENGLES(),
4603 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004604ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
4605 ES2_D3D9(),
4606 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004607 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004608 ES2_OPENGLES(),
4609 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004610ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
4611 ES2_D3D9(),
4612 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004613 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004614 ES2_OPENGLES(),
4615 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004616ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
4617 ES2_D3D9(),
4618 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004619 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004620 ES2_OPENGLES(),
4621 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004622ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02004623ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02004624ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4625ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
4626 ES3_D3D11(),
4627 ES3_OPENGL(),
4628 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004629ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
4630 ES3_D3D11(),
4631 ES3_OPENGL(),
4632 ES3_OPENGLES());
4633ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4634ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02004635ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02004636ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
4637 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004638 ES2_D3D9(),
4639 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004640 ES2_OPENGLES(),
4641 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004642ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
4643 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004644 ES2_D3D9(),
4645 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004646 ES2_OPENGLES(),
4647 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004648ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
4649 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004650 ES2_D3D9(),
4651 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004652 ES2_OPENGLES(),
4653 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004654ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
4655 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004656 ES2_D3D9(),
4657 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004658 ES2_OPENGLES(),
4659 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004660ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
4661 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004662 ES2_D3D9(),
4663 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004664 ES2_OPENGLES(),
4665 ES2_VULKAN());
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05004666ANGLE_INSTANTIATE_TEST(TextureAnisotropyTest,
4667 ES2_D3D11(),
4668 ES2_D3D9(),
4669 ES2_OPENGL(),
4670 ES2_OPENGLES(),
4671 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02004672ANGLE_INSTANTIATE_TEST(TextureBorderClampTest,
4673 ES2_D3D11(),
4674 ES2_D3D9(),
4675 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004676 ES2_OPENGLES(),
4677 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02004678ANGLE_INSTANTIATE_TEST(TextureBorderClampTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4679ANGLE_INSTANTIATE_TEST(TextureBorderClampIntegerTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Luc Ferronaf883622018-06-08 15:57:31 -04004680ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN());
Vincent Lang25ab4512016-05-13 18:13:59 +02004681ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03004682ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Anders Leinof6cbe442019-04-18 15:32:07 +03004683ANGLE_INSTANTIATE_TEST(Texture2DIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino60cc7512019-05-06 09:25:27 +03004684ANGLE_INSTANTIATE_TEST(TextureCubeIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Jamie Madillfa05f602015-05-07 13:47:11 -04004685
Jamie Madill7ffdda92016-09-08 13:26:51 -04004686} // anonymous namespace