blob: 0c089fc16a8f71b1f5721fef5a6dcc3ef43a78e2 [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"
Anders Leino8224a582019-05-20 12:39:29 +03001176 " fragColor = vec4(texture(tex, texcoord))/255.0;\n"
Anders Leinof6cbe442019-04-18 15:32:07 +03001177 "}\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
Anders Leinoe4452442019-05-09 13:29:49 +03001234class TextureCubeIntegerEdgeTestES3 : public TextureCubeIntegerTestES3
1235{
1236 protected:
1237 TextureCubeIntegerEdgeTestES3() : TextureCubeIntegerTestES3() {}
1238
1239 const char *getVertexShaderSource() override
1240 {
1241 return "#version 300 es\n"
1242 "out vec2 texcoord;\n"
1243 "in vec4 position;\n"
1244 "void main()\n"
1245 "{\n"
1246 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1247 " texcoord = position.xy;\n"
1248 "}\n";
1249 }
1250
1251 const char *getFragmentShaderSource() override
1252 {
1253 return "#version 300 es\n"
1254 "precision highp float;\n"
1255 "precision highp usamplerCube;\n"
1256 "uniform usamplerCube texCube;\n"
1257 "in vec2 texcoord;\n"
1258 "out vec4 fragColor;\n"
1259 "void main()\n"
1260 "{\n"
1261 " fragColor = vec4(texture(texCube, vec3(texcoord, 0)))/255.0;\n"
1262 "}\n";
1263 }
1264};
1265
Anders Leino1b6aded2019-05-20 12:56:34 +03001266class Texture2DIntegerProjectiveOffsetTestES3 : public Texture2DTest
1267{
1268 protected:
1269 Texture2DIntegerProjectiveOffsetTestES3() : Texture2DTest() {}
1270
1271 const char *getVertexShaderSource() override
1272 {
1273 return "#version 300 es\n"
1274 "out vec2 texcoord;\n"
1275 "in vec4 position;\n"
1276 "void main()\n"
1277 "{\n"
1278 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1279 " texcoord = 0.5*position.xy + vec2(0.5, 0.5);\n"
1280 "}\n";
1281 }
1282
1283 const char *getFragmentShaderSource() override
1284 {
1285 return "#version 300 es\n"
1286 "precision highp float;\n"
1287 "precision highp usampler2D;\n"
1288 "uniform usampler2D tex;\n"
1289 "in vec2 texcoord;\n"
1290 "out vec4 fragColor;\n"
1291 "void main()\n"
1292 "{\n"
1293 " fragColor = vec4(textureProjOffset(tex, vec3(texcoord, 1), ivec2(0,0), "
1294 "0.0))/255.0;\n"
1295 "}\n";
1296 }
1297};
1298
Anders Leino69d04932019-05-20 14:04:13 +03001299class Texture2DArrayIntegerTestES3 : public Texture2DArrayTestES3
1300{
1301 protected:
1302 Texture2DArrayIntegerTestES3() : Texture2DArrayTestES3() {}
1303
1304 const char *getVertexShaderSource() override
1305 {
1306 return "#version 300 es\n"
1307 "out vec2 texcoord;\n"
1308 "in vec4 position;\n"
1309 "void main()\n"
1310 "{\n"
1311 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1312 " texcoord = (position.xy * 0.5) + 0.5;\n"
1313 "}\n";
1314 }
1315
1316 const char *getFragmentShaderSource() override
1317 {
1318 return "#version 300 es\n"
1319 "precision highp float;\n"
1320 "uniform highp usampler2DArray tex2DArray;\n"
1321 "in vec2 texcoord;\n"
1322 "out vec4 fragColor;\n"
1323 "void main()\n"
1324 "{\n"
1325 " fragColor = vec4(texture(tex2DArray, vec3(texcoord.x, texcoord.y, "
1326 "0.0)))/255.0;\n"
1327 "}\n";
1328 }
1329};
1330
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001331TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001332{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001333 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001334 EXPECT_GL_ERROR(GL_NO_ERROR);
1335
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001336 setUpProgram();
1337
Jamie Madill50cf2be2018-06-15 09:46:57 -04001338 const GLubyte *pixels[20] = {0};
Jamie Madillf67115c2014-04-22 13:14:05 -04001339 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1340 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001341
Jamie Madillb8149072019-04-30 16:14:44 -04001342 if (IsGLExtensionEnabled("GL_EXT_texture_storage"))
Geoff Langc51642b2016-11-14 16:18:26 -05001343 {
1344 // Create a 1-level immutable texture.
1345 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1346
1347 // Try calling sub image on the second level.
1348 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1349 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1350 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001351}
Geoff Langc41e42d2014-04-28 10:58:16 -04001352
John Bauman18319182016-09-28 14:22:27 -07001353// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1354TEST_P(Texture2DTest, QueryBinding)
1355{
1356 glBindTexture(GL_TEXTURE_2D, 0);
1357 EXPECT_GL_ERROR(GL_NO_ERROR);
1358
1359 GLint textureBinding;
1360 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1361 EXPECT_GL_NO_ERROR();
1362 EXPECT_EQ(0, textureBinding);
1363
1364 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
Jamie Madillb8149072019-04-30 16:14:44 -04001365 if (IsGLExtensionEnabled("GL_OES_EGL_image_external") ||
1366 IsGLExtensionEnabled("GL_NV_EGL_stream_consumer_external"))
John Bauman18319182016-09-28 14:22:27 -07001367 {
1368 EXPECT_GL_NO_ERROR();
1369 EXPECT_EQ(0, textureBinding);
1370 }
1371 else
1372 {
1373 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1374 }
1375}
1376
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001377TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001378{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001379 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001380 EXPECT_GL_ERROR(GL_NO_ERROR);
1381
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001382 setUpProgram();
1383
Geoff Langc41e42d2014-04-28 10:58:16 -04001384 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001385 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001386 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001387 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001388
Jamie Madill50cf2be2018-06-15 09:46:57 -04001389 const GLubyte *pixel[4] = {0};
Geoff Langc41e42d2014-04-28 10:58:16 -04001390
1391 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1392 EXPECT_GL_NO_ERROR();
1393
1394 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1395 EXPECT_GL_NO_ERROR();
1396
1397 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1398 EXPECT_GL_NO_ERROR();
1399}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001400
1401// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001402TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001403{
1404 glActiveTexture(GL_TEXTURE0);
1405 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1406 glActiveTexture(GL_TEXTURE1);
1407 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1408 EXPECT_GL_ERROR(GL_NO_ERROR);
1409
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001410 glUseProgram(mProgram);
1411 glUniform1i(mTexture2DUniformLocation, 0);
1412 glUniform1i(mTextureCubeUniformLocation, 1);
1413 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001414 EXPECT_GL_NO_ERROR();
1415}
Jamie Madill9aca0592014-10-06 16:26:59 -04001416
Olli Etuaho53a2da12016-01-11 15:43:32 +02001417// Test drawing with two texture types accessed from the same shader and check that the result of
1418// drawing is correct.
1419TEST_P(TextureCubeTest, CubeMapDraw)
1420{
1421 GLubyte texData[4];
1422 texData[0] = 0;
1423 texData[1] = 60;
1424 texData[2] = 0;
1425 texData[3] = 255;
1426
1427 glActiveTexture(GL_TEXTURE0);
1428 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1429 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1430
1431 glActiveTexture(GL_TEXTURE1);
1432 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1433 texData[1] = 120;
1434 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1435 texData);
1436 EXPECT_GL_ERROR(GL_NO_ERROR);
1437
1438 glUseProgram(mProgram);
1439 glUniform1i(mTexture2DUniformLocation, 0);
1440 glUniform1i(mTextureCubeUniformLocation, 1);
1441 drawQuad(mProgram, "position", 0.5f);
1442 EXPECT_GL_NO_ERROR();
1443
1444 int px = getWindowWidth() - 1;
1445 int py = 0;
1446 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1447}
1448
Olli Etuaho4644a202016-01-12 15:12:53 +02001449TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1450{
1451 glActiveTexture(GL_TEXTURE0);
1452 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1453 GLubyte texData[4];
1454 texData[0] = 0;
1455 texData[1] = 128;
1456 texData[2] = 0;
1457 texData[3] = 255;
1458 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1459 glUseProgram(mProgram);
1460 glUniform1i(mTexture2DUniformLocation, 0);
1461 drawQuad(mProgram, "position", 0.5f);
1462 EXPECT_GL_NO_ERROR();
1463
1464 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1465}
1466
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001467// Test drawing with two textures passed to the shader in a sampler array.
1468TEST_P(SamplerArrayTest, SamplerArrayDraw)
1469{
1470 testSamplerArrayDraw();
1471}
1472
1473// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1474// user-defined function in the shader.
1475TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1476{
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05001477 // TODO: Diagnose and fix. http://anglebug.com/2955
1478 ANGLE_SKIP_TEST_IF(IsVulkan() && IsAndroid());
1479
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001480 testSamplerArrayDraw();
1481}
1482
Jamie Madill9aca0592014-10-06 16:26:59 -04001483// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001484TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001485{
1486 int px = getWindowWidth() / 2;
1487 int py = getWindowHeight() / 2;
1488
1489 glActiveTexture(GL_TEXTURE0);
1490 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1491
Olli Etuahoa314b612016-03-10 16:43:00 +02001492 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001493
Olli Etuahoa314b612016-03-10 16:43:00 +02001494 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001495 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1496 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1497 glGenerateMipmap(GL_TEXTURE_2D);
1498
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001499 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001500 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001501 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1502 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001503 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001504 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001505
Olli Etuahoa314b612016-03-10 16:43:00 +02001506 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001507
Olli Etuahoa314b612016-03-10 16:43:00 +02001508 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1509 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001510 glGenerateMipmap(GL_TEXTURE_2D);
1511
Olli Etuahoa314b612016-03-10 16:43:00 +02001512 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001513
Olli Etuahoa314b612016-03-10 16:43:00 +02001514 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1515 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001516 glGenerateMipmap(GL_TEXTURE_2D);
1517
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001518 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001519
1520 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001521 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001522}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001523
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001524// Test creating a FBO with a cube map render target, to test an ANGLE bug
1525// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001526TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001527{
Michael Spangd8506c72019-01-29 15:35:09 -05001528 // http://anglebug.com/3145
1529 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
1530
Shahbaz Youssefi0c128e12019-03-25 23:50:14 -04001531 // http://anglebug.com/2822
1532 ANGLE_SKIP_TEST_IF(IsWindows() && IsIntel() && IsVulkan());
1533
Jamie Madill3f3b3582018-09-14 10:38:44 -04001534 GLFramebuffer fbo;
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001535 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1536
1537 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Jamie Madill50cf2be2018-06-15 09:46:57 -04001538 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1539 mTextureCube, 0);
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001540
Corentin Wallez322653b2015-06-17 18:33:56 +02001541 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001542 EXPECT_GL_NO_ERROR();
Jamie Madill3f3b3582018-09-14 10:38:44 -04001543
1544 // Test clearing the six mip faces individually.
1545 std::array<GLColor, 6> faceColors = {{GLColor::red, GLColor::green, GLColor::blue,
1546 GLColor::yellow, GLColor::cyan, GLColor::magenta}};
1547
1548 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1549 {
1550 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1551 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1552
1553 Vector4 clearColorF = faceColors[faceIndex].toNormalizedVector();
1554 glClearColor(clearColorF.x(), clearColorF.y(), clearColorF.z(), clearColorF.w());
1555 glClear(GL_COLOR_BUFFER_BIT);
1556
1557 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex]);
1558 }
1559
1560 // Iterate the faces again to make sure the colors haven't changed.
1561 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1562 {
1563 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1564 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1565 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex])
1566 << "face color " << faceIndex << " shouldn't change";
1567 }
1568}
1569
1570// Tests clearing a cube map with a scissor enabled.
1571TEST_P(TextureCubeTest, CubeMapFBOScissoredClear)
1572{
1573 // TODO(jie.a.chen): Diagnose and fix. http://anglebug.com/2822
1574 ANGLE_SKIP_TEST_IF(IsVulkan() && IsIntel() && IsWindows());
1575
Michael Spangd8506c72019-01-29 15:35:09 -05001576 // http://anglebug.com/3145
1577 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
1578
Jamie Madill3f3b3582018-09-14 10:38:44 -04001579 constexpr size_t kSize = 16;
1580
1581 GLFramebuffer fbo;
1582 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1583 glViewport(0, 0, kSize, kSize);
1584
1585 GLTexture texcube;
1586 glBindTexture(GL_TEXTURE_CUBE_MAP, texcube);
1587 for (GLenum face = 0; face < 6; face++)
1588 {
1589 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA,
1590 GL_UNSIGNED_BYTE, nullptr);
1591 }
1592 ASSERT_GL_NO_ERROR();
1593
1594 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1595 texcube, 0);
1596
1597 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1598 ASSERT_GL_NO_ERROR();
1599
1600 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1601 glClear(GL_COLOR_BUFFER_BIT);
1602 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1603
1604 glEnable(GL_SCISSOR_TEST);
1605 glScissor(kSize / 2, 0, kSize / 2, kSize);
1606 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
1607 glClear(GL_COLOR_BUFFER_BIT);
1608
1609 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1610 EXPECT_PIXEL_COLOR_EQ(kSize / 2 + 1, 0, GLColor::green);
1611
1612 ASSERT_GL_NO_ERROR();
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001613}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001614
Jamie Madill50cf2be2018-06-15 09:46:57 -04001615// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a
1616// default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001617TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001618{
Jamie Madillb8149072019-04-30 16:14:44 -04001619 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 &&
1620 !IsGLExtensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -04001621
Jamie Madill50cf2be2018-06-15 09:46:57 -04001622 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001623 int height = getWindowHeight();
1624
1625 GLuint tex2D;
1626 glGenTextures(1, &tex2D);
1627 glActiveTexture(GL_TEXTURE0);
1628 glBindTexture(GL_TEXTURE_2D, tex2D);
1629
1630 // Fill with red
1631 std::vector<GLubyte> pixels(3 * 16 * 16);
1632 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1633 {
1634 pixels[pixelId * 3 + 0] = 255;
1635 pixels[pixelId * 3 + 1] = 0;
1636 pixels[pixelId * 3 + 2] = 0;
1637 }
1638
1639 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001640 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1641 // 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 -04001642 if (getClientMajorVersion() >= 3)
1643 {
1644 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1645 }
1646 else
1647 {
1648 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1649 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001650
1651 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1652 // glTexSubImage2D should take into account that the image is dirty.
1653 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1654 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1655 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1656
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001657 setUpProgram();
1658
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001659 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001660 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001661 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001662 glDeleteTextures(1, &tex2D);
1663 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001664 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001665
1666 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001667 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1668 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001669}
1670
Jamie Madill50cf2be2018-06-15 09:46:57 -04001671// Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has
1672// initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001673TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001674{
Jamie Madillb8149072019-04-30 16:14:44 -04001675 if (IsGLExtensionEnabled("NV_pixel_buffer_object"))
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001676 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04001677 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001678 int height = getWindowHeight();
1679
1680 GLuint tex2D;
1681 glGenTextures(1, &tex2D);
1682 glActiveTexture(GL_TEXTURE0);
1683 glBindTexture(GL_TEXTURE_2D, tex2D);
1684
1685 // Fill with red
1686 std::vector<GLubyte> pixels(3 * 16 * 16);
1687 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1688 {
1689 pixels[pixelId * 3 + 0] = 255;
1690 pixels[pixelId * 3 + 1] = 0;
1691 pixels[pixelId * 3 + 2] = 0;
1692 }
1693
1694 // Read 16x16 region from red backbuffer to PBO
1695 GLuint pbo;
1696 glGenBuffers(1, &pbo);
1697 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1698 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1699
1700 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001701 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1702 // 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 +00001703 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1704
1705 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1706 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001707 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 +00001708 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1709 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1710
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001711 setUpProgram();
1712
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001713 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001714 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001715 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001716 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001717 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001718 EXPECT_GL_NO_ERROR();
1719 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1720 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1721 }
1722}
Jamie Madillbc393df2015-01-29 13:46:07 -05001723
1724// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001725TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001726{
1727 testFloatCopySubImage(1, 1);
1728}
1729
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001730TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001731{
1732 testFloatCopySubImage(2, 1);
1733}
1734
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001735TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001736{
1737 testFloatCopySubImage(2, 2);
1738}
1739
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001740TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001741{
1742 testFloatCopySubImage(3, 1);
1743}
1744
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001745TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001746{
1747 testFloatCopySubImage(3, 2);
1748}
1749
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001750TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001751{
Yunchao He9550c602018-02-13 14:47:05 +08001752 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1753 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001754
Yunchao He9550c602018-02-13 14:47:05 +08001755 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1756 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001757
Jamie Madillbc393df2015-01-29 13:46:07 -05001758 testFloatCopySubImage(3, 3);
1759}
1760
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001761TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001762{
1763 testFloatCopySubImage(4, 1);
1764}
1765
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001766TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001767{
1768 testFloatCopySubImage(4, 2);
1769}
1770
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001771TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001772{
Yunchao He9550c602018-02-13 14:47:05 +08001773 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1774 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001775
Jamie Madillbc393df2015-01-29 13:46:07 -05001776 testFloatCopySubImage(4, 3);
1777}
1778
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001779TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001780{
Luc Ferronf786b702018-07-10 11:01:43 -04001781 // TODO(lucferron): This test fails only on linux and intel.
1782 // http://anglebug.com/2726
1783 ANGLE_SKIP_TEST_IF(IsVulkan() && IsLinux() && IsIntel());
1784
Yunchao He9550c602018-02-13 14:47:05 +08001785 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1786 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001787
Jamie Madillbc393df2015-01-29 13:46:07 -05001788 testFloatCopySubImage(4, 4);
1789}
Austin Kinross07285142015-03-26 11:36:16 -07001790
Jamie Madill50cf2be2018-06-15 09:46:57 -04001791// Port of
1792// https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1793// Run against GL_ALPHA/UNSIGNED_BYTE format, to ensure that D3D11 Feature Level 9_3 correctly
1794// handles GL_ALPHA
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001795TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001796{
1797 const int npotTexSize = 5;
Jamie Madill50cf2be2018-06-15 09:46:57 -04001798 const int potTexSize = 4; // Should be less than npotTexSize
Austin Kinross07285142015-03-26 11:36:16 -07001799 GLuint tex2D;
1800
Jamie Madillb8149072019-04-30 16:14:44 -04001801 if (IsGLExtensionEnabled("GL_OES_texture_npot"))
Austin Kinross07285142015-03-26 11:36:16 -07001802 {
1803 // This test isn't applicable if texture_npot is enabled
1804 return;
1805 }
1806
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001807 setUpProgram();
1808
Austin Kinross07285142015-03-26 11:36:16 -07001809 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1810
Austin Kinross5faa15b2016-01-11 13:32:48 -08001811 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1812 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1813
Austin Kinross07285142015-03-26 11:36:16 -07001814 glActiveTexture(GL_TEXTURE0);
1815 glGenTextures(1, &tex2D);
1816 glBindTexture(GL_TEXTURE_2D, tex2D);
1817
Till Rathmannc1551dc2018-08-15 17:04:49 +02001818 const std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize, 64);
Austin Kinross07285142015-03-26 11:36:16 -07001819
1820 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1821 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1822
1823 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
Jamie Madill50cf2be2018-06-15 09:46:57 -04001824 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1825 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001826 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1827
1828 // Check that an NPOT texture on level 0 succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001829 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1830 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001831 EXPECT_GL_NO_ERROR();
1832
1833 // Check that generateMipmap fails on NPOT
1834 glGenerateMipmap(GL_TEXTURE_2D);
1835 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1836
1837 // Check that nothing is drawn if filtering is not correct for NPOT
1838 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1839 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1840 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1841 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1842 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001843 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001844 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1845
1846 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1847 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1848 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1849 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1850 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001851 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001852 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1853
1854 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1855 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1856 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001857 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001858 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1859
1860 // Check that glTexImage2D for POT texture succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001861 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE,
1862 pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001863 EXPECT_GL_NO_ERROR();
1864
1865 // Check that generateMipmap for an POT texture succeeds
1866 glGenerateMipmap(GL_TEXTURE_2D);
1867 EXPECT_GL_NO_ERROR();
1868
1869 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1870 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1871 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1872 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1873 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1874 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001875 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001876 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1877 EXPECT_GL_NO_ERROR();
1878}
Jamie Madillfa05f602015-05-07 13:47:11 -04001879
Austin Kinross08528e12015-10-07 16:24:40 -07001880// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1881// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001882TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001883{
1884 glActiveTexture(GL_TEXTURE0);
1885 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1886
1887 // Create an 8x8 (i.e. power-of-two) texture.
1888 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1889 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1890 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1891 glGenerateMipmap(GL_TEXTURE_2D);
1892
1893 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1894 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001895 std::array<GLColor, 3 * 3> data;
1896 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001897
1898 EXPECT_GL_NO_ERROR();
1899}
1900
Geoff Lang3702d8c2019-04-08 13:44:06 -04001901// Regression test for http://crbug.com/949985 to make sure dirty bits are propagated up from
1902// TextureImpl and the texture is synced before being used in a draw call.
1903TEST_P(Texture2DTestES3, TextureImplPropogatesDirtyBits)
1904{
1905 ANGLE_SKIP_TEST_IF(IsIntel() && IsOpenGL());
Yuly Novikove6b23e42019-04-10 17:19:15 -04001906 // Flaky hangs on Win10 AMD RX 550 GL. http://anglebug.com/3371
1907 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsOpenGL());
Geoff Lang3702d8c2019-04-08 13:44:06 -04001908
1909 // The workaround in the GL backend required to trigger this bug generates driver warning
1910 // messages.
1911 ScopedIgnorePlatformMessages ignoreMessages;
1912
1913 setUpProgram();
1914 glUseProgram(mProgram);
1915 glActiveTexture(GL_TEXTURE0 + mTexture2DUniformLocation);
1916
1917 GLTexture dest;
1918 glBindTexture(GL_TEXTURE_2D, dest);
1919
1920 GLTexture source;
1921 glBindTexture(GL_TEXTURE_2D, source);
1922
1923 // Put data in mip 0 and 1
1924 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1925 GLColor::red.data());
1926 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1927 GLColor::green.data());
1928
1929 // Disable mipmapping so source is complete
1930 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1931 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1932
1933 // Force the dirty bits to be synchronized in source
1934 drawQuad(mProgram, "position", 1.0f);
1935
1936 // Copy from mip 1 of the source. In the GL backend this internally sets the base level to mip
1937 // 1 and sets a dirty bit.
1938 glCopyTextureCHROMIUM(source, 1, GL_TEXTURE_2D, dest, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_FALSE,
1939 GL_FALSE, GL_FALSE);
1940
1941 // Draw again, assertions are generated if the texture has internal dirty bits at draw time
1942 drawQuad(mProgram, "position", 1.0f);
1943}
1944
Geoff Lang6f691fb2019-04-25 11:01:52 -04001945// This test case changes the base level of a texture that's attached to a framebuffer, clears every
1946// level to green, and then samples the texture when rendering. Test is taken from
1947// https://www.khronos.org/registry/webgl/sdk/tests/conformance2/rendering/framebuffer-texture-changing-base-level.html
1948TEST_P(Texture2DTestES3, FramebufferTextureChangingBaselevel)
1949{
1950 // TODO(geofflang): Investigate on D3D11. http://anglebug.com/2291
1951 ANGLE_SKIP_TEST_IF(IsD3D11());
1952
1953 setUpProgram();
1954
1955 constexpr GLint width = 8;
1956 constexpr GLint height = 4;
1957
1958 GLTexture texture;
1959 glBindTexture(GL_TEXTURE_2D, texture);
1960 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1961 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1962 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1963 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1964
1965 // Create all mipmap levels for the texture from level 0 to the 1x1 pixel level.
1966 GLint level = 0;
1967 GLint levelW = width;
1968 GLint levelH = height;
1969 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, levelW, levelH, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1970 nullptr);
1971 while (levelW > 1 || levelH > 1)
1972 {
1973 ++level;
1974 levelW = static_cast<GLint>(std::max(1.0, std::floor(width / std::pow(2, level))));
1975 levelH = static_cast<GLint>(std::max(1.0, std::floor(height / std::pow(2, level))));
1976 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, levelW, levelH, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1977 nullptr);
1978 }
1979
1980 // Clear each level of the texture using an FBO. Change the base level to match the level used
1981 // for the FBO on each iteration.
1982 GLFramebuffer fbo;
1983 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1984 level = 0;
1985 levelW = width;
1986 levelH = height;
1987 while (levelW > 1 || levelH > 1)
1988 {
1989 levelW = static_cast<GLint>(std::floor(width / std::pow(2, level)));
1990 levelH = static_cast<GLint>(std::floor(height / std::pow(2, level)));
1991
1992 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, level);
1993 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, level);
1994
1995 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1996 EXPECT_GL_NO_ERROR();
1997
1998 glClearColor(0, 1, 0, 1);
1999 glClear(GL_COLOR_BUFFER_BIT);
2000
2001 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2002
2003 ++level;
2004 }
2005
2006 glBindFramebuffer(GL_FRAMEBUFFER, 0);
2007 glViewport(0, 0, 16, 16);
2008 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2009
2010 drawQuad(mProgram, "position", 0.5f);
2011
2012 EXPECT_GL_NO_ERROR();
2013 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2014}
2015
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002016// Test to check that texture completeness is determined correctly when the texture base level is
2017// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
2018TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
2019{
2020 glActiveTexture(GL_TEXTURE0);
2021 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02002022
2023 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
2024 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
2025 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2026 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2027 texDataGreen.data());
2028 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2029 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002030 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2031 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2032 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2033
2034 EXPECT_GL_NO_ERROR();
2035
2036 drawQuad(mProgram, "position", 0.5f);
2037
Olli Etuahoa314b612016-03-10 16:43:00 +02002038 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2039}
2040
2041// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2042// have images defined.
2043TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
2044{
Yunchao He9550c602018-02-13 14:47:05 +08002045 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
2046 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
2047
Olli Etuahoa314b612016-03-10 16:43:00 +02002048 glActiveTexture(GL_TEXTURE0);
2049 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2050 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2051 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2052 texDataGreen.data());
2053 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2054 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2055 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2056 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2057
2058 EXPECT_GL_NO_ERROR();
2059
2060 drawQuad(mProgram, "position", 0.5f);
2061
2062 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2063}
2064
Olli Etuahoe8528d82016-05-16 17:50:52 +03002065// Test that drawing works correctly when level 0 is undefined and base level is 1.
2066TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
2067{
Yunchao He9550c602018-02-13 14:47:05 +08002068 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
2069 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
2070
Olli Etuahoe8528d82016-05-16 17:50:52 +03002071 glActiveTexture(GL_TEXTURE0);
2072 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2073 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2074 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2075 texDataGreen.data());
2076 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2077 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2078 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2079 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2080
2081 EXPECT_GL_NO_ERROR();
2082
2083 // Texture is incomplete.
2084 drawQuad(mProgram, "position", 0.5f);
2085 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2086
2087 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2088 texDataGreen.data());
2089
2090 // Texture is now complete.
2091 drawQuad(mProgram, "position", 0.5f);
2092 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2093}
2094
Olli Etuahoa314b612016-03-10 16:43:00 +02002095// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2096// dimensions that don't fit the images inside the range.
2097// GLES 3.0.4 section 3.8.13 Texture completeness
2098TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2099{
Olli Etuahoa314b612016-03-10 16:43:00 +02002100 glActiveTexture(GL_TEXTURE0);
2101 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2102 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
2103 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2104 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
2105
2106 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2107 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2108
2109 // Two levels that are initially unused.
2110 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
2111 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2112 texDataCyan.data());
2113
2114 // One level that is used - only this level should affect completeness.
2115 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2116 texDataGreen.data());
2117
2118 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2119 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2120
2121 EXPECT_GL_NO_ERROR();
2122
2123 drawQuad(mProgram, "position", 0.5f);
2124
2125 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2126
Yunchao He2f23f352018-02-11 22:11:37 +08002127 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02002128
2129 // Switch the level that is being used to the cyan level 2.
2130 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2131 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2132
2133 EXPECT_GL_NO_ERROR();
2134
2135 drawQuad(mProgram, "position", 0.5f);
2136
2137 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2138}
2139
2140// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2141// have images defined.
2142TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
2143{
Olli Etuahoa314b612016-03-10 16:43:00 +02002144 glActiveTexture(GL_TEXTURE0);
2145 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2146 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2147 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2148 texDataGreen.data());
2149 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2150 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2151 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
2152 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2153
2154 EXPECT_GL_NO_ERROR();
2155
2156 drawQuad(mProgram, "position", 0.5f);
2157
2158 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2159}
2160
2161// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2162// dimensions that don't fit the images inside the range.
2163// GLES 3.0.4 section 3.8.13 Texture completeness
2164TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2165{
Olli Etuahoa314b612016-03-10 16:43:00 +02002166 glActiveTexture(GL_TEXTURE0);
2167 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2168 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2169 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2170 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2171
2172 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2173 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2174
2175 // Two levels that are initially unused.
2176 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2177 texDataRed.data());
2178 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2179 texDataCyan.data());
2180
2181 // One level that is used - only this level should affect completeness.
2182 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2183 texDataGreen.data());
2184
2185 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
2186 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2187
2188 EXPECT_GL_NO_ERROR();
2189
2190 drawQuad(mProgram, "position", 0.5f);
2191
2192 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2193
Yunchao He2f23f352018-02-11 22:11:37 +08002194 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02002195
2196 // Switch the level that is being used to the cyan level 2.
2197 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
2198 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
2199
2200 EXPECT_GL_NO_ERROR();
2201
2202 drawQuad(mProgram, "position", 0.5f);
2203
2204 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2205}
2206
2207// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2208// have images defined.
2209TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
2210{
Olli Etuahoa314b612016-03-10 16:43:00 +02002211 glActiveTexture(GL_TEXTURE0);
2212 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
2213 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2214 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2215 texDataGreen.data());
2216 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2217 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2218 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2219 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2220
2221 EXPECT_GL_NO_ERROR();
2222
2223 drawQuad(mProgram, "position", 0.5f);
2224
2225 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2226}
2227
2228// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2229// dimensions that don't fit the images inside the range.
2230// GLES 3.0.4 section 3.8.13 Texture completeness
2231TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2232{
Olli Etuahoa314b612016-03-10 16:43:00 +02002233 glActiveTexture(GL_TEXTURE0);
2234 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
2235 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2236 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2237 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2238
2239 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2240 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2241
2242 // Two levels that are initially unused.
2243 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2244 texDataRed.data());
2245 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2246 texDataCyan.data());
2247
2248 // One level that is used - only this level should affect completeness.
2249 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2250 texDataGreen.data());
2251
2252 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2253 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2254
2255 EXPECT_GL_NO_ERROR();
2256
2257 drawQuad(mProgram, "position", 0.5f);
2258
2259 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2260
Yunchao He2f23f352018-02-11 22:11:37 +08002261 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
2262
Yunchao He9550c602018-02-13 14:47:05 +08002263 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
2264 // level was changed.
2265 ANGLE_SKIP_TEST_IF(IsNVIDIA() && (IsOpenGL() || IsOpenGLES()));
Olli Etuahoa314b612016-03-10 16:43:00 +02002266
2267 // Switch the level that is being used to the cyan level 2.
2268 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2269 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2270
2271 EXPECT_GL_NO_ERROR();
2272
2273 drawQuad(mProgram, "position", 0.5f);
2274
2275 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2276}
2277
2278// Test that texture completeness is updated if texture max level changes.
2279// GLES 3.0.4 section 3.8.13 Texture completeness
2280TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2281{
Olli Etuahoa314b612016-03-10 16:43:00 +02002282 glActiveTexture(GL_TEXTURE0);
2283 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2284 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2285
2286 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2287 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2288
2289 // A level that is initially unused.
2290 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2291 texDataGreen.data());
2292
2293 // One level that is initially used - only this level should affect completeness.
2294 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2295 texDataGreen.data());
2296
2297 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2298 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2299
2300 EXPECT_GL_NO_ERROR();
2301
2302 drawQuad(mProgram, "position", 0.5f);
2303
2304 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2305
2306 // Switch the max level to level 1. The levels within the used range now have inconsistent
2307 // dimensions and the texture should be incomplete.
2308 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2309
2310 EXPECT_GL_NO_ERROR();
2311
2312 drawQuad(mProgram, "position", 0.5f);
2313
2314 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2315}
2316
2317// Test that 3D texture completeness is updated if texture max level changes.
2318// GLES 3.0.4 section 3.8.13 Texture completeness
2319TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2320{
Olli Etuahoa314b612016-03-10 16:43:00 +02002321 glActiveTexture(GL_TEXTURE0);
2322 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2323 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2324
2325 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2326 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2327
2328 // A level that is initially unused.
2329 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2330 texDataGreen.data());
2331
2332 // One level that is initially used - only this level should affect completeness.
2333 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2334 texDataGreen.data());
2335
2336 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2337 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2338
2339 EXPECT_GL_NO_ERROR();
2340
2341 drawQuad(mProgram, "position", 0.5f);
2342
2343 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2344
2345 // Switch the max level to level 1. The levels within the used range now have inconsistent
2346 // dimensions and the texture should be incomplete.
2347 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2348
2349 EXPECT_GL_NO_ERROR();
2350
2351 drawQuad(mProgram, "position", 0.5f);
2352
2353 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2354}
2355
2356// Test that texture completeness is updated if texture base level changes.
2357// GLES 3.0.4 section 3.8.13 Texture completeness
2358TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2359{
Olli Etuahoa314b612016-03-10 16:43:00 +02002360 glActiveTexture(GL_TEXTURE0);
2361 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2362 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2363
2364 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2365 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2366
2367 // Two levels that are initially unused.
2368 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2369 texDataGreen.data());
2370 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2371 texDataGreen.data());
2372
2373 // One level that is initially used - only this level should affect completeness.
2374 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2375 texDataGreen.data());
2376
2377 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2378 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2379
2380 EXPECT_GL_NO_ERROR();
2381
2382 drawQuad(mProgram, "position", 0.5f);
2383
2384 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2385
2386 // Switch the base level to level 1. The levels within the used range now have inconsistent
2387 // dimensions and the texture should be incomplete.
2388 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2389
2390 EXPECT_GL_NO_ERROR();
2391
2392 drawQuad(mProgram, "position", 0.5f);
2393
2394 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2395}
2396
2397// Test that texture is not complete if base level is greater than max level.
2398// GLES 3.0.4 section 3.8.13 Texture completeness
2399TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2400{
Olli Etuahoa314b612016-03-10 16:43:00 +02002401 glActiveTexture(GL_TEXTURE0);
2402 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2403
2404 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2405 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2406
2407 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2408
2409 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2410 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2411
2412 EXPECT_GL_NO_ERROR();
2413
2414 drawQuad(mProgram, "position", 0.5f);
2415
2416 // Texture should be incomplete.
2417 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2418}
2419
2420// Test that immutable texture base level and max level are clamped.
2421// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2422TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2423{
Olli Etuahoa314b612016-03-10 16:43:00 +02002424 glActiveTexture(GL_TEXTURE0);
2425 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2426
2427 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2428 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2429
2430 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2431
2432 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2433
2434 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2435 // should be clamped to [base_level, levels - 1].
2436 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2437 // In the case of this test, those rules make the effective base level and max level 0.
2438 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2439 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2440
2441 EXPECT_GL_NO_ERROR();
2442
2443 drawQuad(mProgram, "position", 0.5f);
2444
2445 // Texture should be complete.
2446 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2447}
2448
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002449// Test that changing base level works when it affects the format of the texture.
2450TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2451{
Yunchao He9550c602018-02-13 14:47:05 +08002452 // Observed rendering corruption on NVIDIA OpenGL.
2453 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL());
2454
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002455 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002456
2457 // Observed incorrect rendering on AMD OpenGL.
2458 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002459
2460 glActiveTexture(GL_TEXTURE0);
2461 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2462 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2463 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2464
2465 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2466 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2467
2468 // RGBA8 level that's initially unused.
2469 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2470 texDataCyan.data());
2471
2472 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2473 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2474
2475 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2476 // format. It reads green channel data from the green and alpha channels of texDataGreen
2477 // (this is a bit hacky but works).
2478 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2479
2480 EXPECT_GL_NO_ERROR();
2481
2482 drawQuad(mProgram, "position", 0.5f);
2483
2484 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2485
2486 // Switch the texture to use the cyan level 0 with the RGBA format.
2487 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2488 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2489
2490 EXPECT_GL_NO_ERROR();
2491
2492 drawQuad(mProgram, "position", 0.5f);
2493
2494 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2495}
2496
Olli Etuahoa314b612016-03-10 16:43:00 +02002497// Test that setting a texture image works when base level is out of range.
2498TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2499{
2500 glActiveTexture(GL_TEXTURE0);
2501 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2502
2503 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2504 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2505
2506 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2507 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2508
2509 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2510
2511 EXPECT_GL_NO_ERROR();
2512
2513 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2514
2515 drawQuad(mProgram, "position", 0.5f);
2516
2517 // Texture should be complete.
2518 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002519}
2520
Jamie Madill50cf2be2018-06-15 09:46:57 -04002521// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG
2522// RBA->RGBA8, with 1.0 in the alpha channel. This test covers a bug where redefining array textures
2523// with these formats does not work as expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002524TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002525{
2526 std::vector<GLubyte> pixelData;
2527 for (size_t count = 0; count < 5000; count++)
2528 {
2529 pixelData.push_back(0u);
2530 pixelData.push_back(255u);
2531 pixelData.push_back(0u);
2532 }
2533
2534 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002535 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002536 glUniform1i(mTextureArrayLocation, 0);
2537
2538 // The first draw worked correctly.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002539 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2540 &pixelData[0]);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002541
2542 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2543 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2544 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2545 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002546 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002547 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002548
2549 // The dimension of the respecification must match the original exactly to trigger the bug.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002550 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2551 &pixelData[0]);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002552 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002553 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002554
2555 ASSERT_GL_NO_ERROR();
2556}
2557
Olli Etuaho1a679902016-01-14 12:21:47 +02002558// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2559// This test is needed especially to confirm that sampler registers get assigned correctly on
2560// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2561TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2562{
2563 glActiveTexture(GL_TEXTURE0);
2564 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2565 GLubyte texData[4];
2566 texData[0] = 0;
2567 texData[1] = 60;
2568 texData[2] = 0;
2569 texData[3] = 255;
2570 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2571
2572 glActiveTexture(GL_TEXTURE1);
2573 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2574 GLfloat depthTexData[1];
2575 depthTexData[0] = 0.5f;
2576 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2577 depthTexData);
2578
2579 glUseProgram(mProgram);
2580 glUniform1f(mDepthRefUniformLocation, 0.3f);
2581 glUniform1i(mTexture3DUniformLocation, 0);
2582 glUniform1i(mTextureShadowUniformLocation, 1);
2583
2584 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2585 drawQuad(mProgram, "position", 0.5f);
2586 EXPECT_GL_NO_ERROR();
2587 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2588 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2589
2590 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2591 drawQuad(mProgram, "position", 0.5f);
2592 EXPECT_GL_NO_ERROR();
2593 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2594 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2595}
2596
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002597// Test multiple different sampler types in the same shader.
2598// This test makes sure that even if sampler / texture registers get grouped together based on type
2599// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2600// still has the right register index information for each ESSL sampler.
2601// The tested ESSL samplers have the following types in D3D11 HLSL:
2602// sampler2D: Texture2D + SamplerState
2603// samplerCube: TextureCube + SamplerState
2604// sampler2DShadow: Texture2D + SamplerComparisonState
2605// samplerCubeShadow: TextureCube + SamplerComparisonState
2606TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2607{
2608 glActiveTexture(GL_TEXTURE0);
2609 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2610 GLubyte texData[4];
2611 texData[0] = 0;
2612 texData[1] = 0;
2613 texData[2] = 120;
2614 texData[3] = 255;
2615 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2616
2617 glActiveTexture(GL_TEXTURE1);
2618 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2619 texData[0] = 0;
2620 texData[1] = 90;
2621 texData[2] = 0;
2622 texData[3] = 255;
2623 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2624 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2625 texData);
2626
2627 glActiveTexture(GL_TEXTURE2);
2628 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2629 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2630 GLfloat depthTexData[1];
2631 depthTexData[0] = 0.5f;
2632 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2633 depthTexData);
2634
2635 glActiveTexture(GL_TEXTURE3);
2636 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2637 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2638 depthTexData[0] = 0.2f;
2639 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2640 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2641 depthTexData);
2642
2643 EXPECT_GL_NO_ERROR();
2644
2645 glUseProgram(mProgram);
2646 glUniform1f(mDepthRefUniformLocation, 0.3f);
2647 glUniform1i(mTexture2DUniformLocation, 0);
2648 glUniform1i(mTextureCubeUniformLocation, 1);
2649 glUniform1i(mTexture2DShadowUniformLocation, 2);
2650 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2651
2652 drawQuad(mProgram, "position", 0.5f);
2653 EXPECT_GL_NO_ERROR();
2654 // The shader writes:
2655 // <texture 2d color> +
2656 // <cube map color> +
2657 // 0.25 * <comparison result (1.0)> +
2658 // 0.125 * <comparison result (0.0)>
2659 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2660}
2661
Olli Etuahobce743a2016-01-15 17:18:28 +02002662// Test different base levels on textures accessed through the same sampler array.
2663// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2664TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2665{
Yunchao He9550c602018-02-13 14:47:05 +08002666 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2667
Olli Etuahobce743a2016-01-15 17:18:28 +02002668 glActiveTexture(GL_TEXTURE0);
2669 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2670 GLsizei size = 64;
2671 for (GLint level = 0; level < 7; ++level)
2672 {
2673 ASSERT_LT(0, size);
2674 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2675 nullptr);
2676 size = size / 2;
2677 }
2678 ASSERT_EQ(0, size);
2679 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2680
2681 glActiveTexture(GL_TEXTURE1);
2682 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2683 size = 128;
2684 for (GLint level = 0; level < 8; ++level)
2685 {
2686 ASSERT_LT(0, size);
2687 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2688 nullptr);
2689 size = size / 2;
2690 }
2691 ASSERT_EQ(0, size);
2692 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2693 EXPECT_GL_NO_ERROR();
2694
2695 glUseProgram(mProgram);
2696 glUniform1i(mTexture0Location, 0);
2697 glUniform1i(mTexture1Location, 1);
2698
Olli Etuaho5804dc82018-04-13 14:11:46 +03002699 drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
Olli Etuahobce743a2016-01-15 17:18:28 +02002700 EXPECT_GL_NO_ERROR();
2701 // Red channel: width of level 1 of texture A: 32.
2702 // Green channel: width of level 3 of texture B: 16.
2703 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2704}
2705
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002706// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2707// ES 3.0.4 table 3.24
2708TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2709{
2710 glActiveTexture(GL_TEXTURE0);
2711 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2712 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2713 EXPECT_GL_NO_ERROR();
2714
2715 drawQuad(mProgram, "position", 0.5f);
2716
2717 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2718}
2719
2720// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2721// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002722TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002723{
Luc Ferron5164b792018-03-06 09:10:12 -05002724 setUpProgram();
2725
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002726 glActiveTexture(GL_TEXTURE0);
2727 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2728 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2729 EXPECT_GL_NO_ERROR();
2730
2731 drawQuad(mProgram, "position", 0.5f);
2732
2733 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2734}
2735
Luc Ferron5164b792018-03-06 09:10:12 -05002736// Validate that every component of the pixel will be equal to the luminance value we've set
2737// and that the alpha channel will be 1 (or 255 to be exact).
2738TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2739{
2740 setUpProgram();
2741
2742 glActiveTexture(GL_TEXTURE0);
2743 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2744 uint8_t pixel = 50;
2745 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2746 EXPECT_GL_NO_ERROR();
2747
2748 drawQuad(mProgram, "position", 0.5f);
2749
2750 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2751}
2752
2753// Validate that every component of the pixel will be equal to the luminance value we've set
2754// and that the alpha channel will be the second component.
2755TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2756{
2757 setUpProgram();
2758
2759 glActiveTexture(GL_TEXTURE0);
2760 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2761 uint8_t pixel[] = {50, 25};
2762 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2763 GL_UNSIGNED_BYTE, pixel);
2764 EXPECT_GL_NO_ERROR();
2765
2766 drawQuad(mProgram, "position", 0.5f);
2767
2768 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2769}
2770
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002771// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2772// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002773TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002774{
Jamie Madillb8149072019-04-30 16:14:44 -04002775 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002776 ANGLE_SKIP_TEST_IF(IsD3D9());
2777 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002778
2779 setUpProgram();
2780
Luc Ferrond8c632c2018-04-10 12:31:44 -04002781 glActiveTexture(GL_TEXTURE0);
2782 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2783 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2784 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002785
Luc Ferrond8c632c2018-04-10 12:31:44 -04002786 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002787
Luc Ferrond8c632c2018-04-10 12:31:44 -04002788 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002789}
2790
2791// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2792// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002793TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002794{
Jamie Madillb8149072019-04-30 16:14:44 -04002795 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002796 ANGLE_SKIP_TEST_IF(IsD3D9());
2797 ANGLE_SKIP_TEST_IF(IsVulkan());
2798 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES());
2799 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2800 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002801
Luc Ferrond8c632c2018-04-10 12:31:44 -04002802 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002803
Luc Ferrond8c632c2018-04-10 12:31:44 -04002804 glActiveTexture(GL_TEXTURE0);
2805 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2806 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2807 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002808
Luc Ferrond8c632c2018-04-10 12:31:44 -04002809 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002810
Luc Ferrond8c632c2018-04-10 12:31:44 -04002811 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002812}
2813
2814// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2815// ES 3.0.4 table 3.24
2816TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2817{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002818 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2819
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002820 glActiveTexture(GL_TEXTURE0);
2821 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2822 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2823 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2824 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2825 EXPECT_GL_NO_ERROR();
2826
2827 drawQuad(mProgram, "position", 0.5f);
2828
2829 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2830}
2831
2832// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2833// ES 3.0.4 table 3.24
2834TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2835{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002836 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2837
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002838 glActiveTexture(GL_TEXTURE0);
2839 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2840
2841 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2842 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2843 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2844 EXPECT_GL_NO_ERROR();
2845
2846 drawQuad(mProgram, "position", 0.5f);
2847
2848 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2849}
2850
2851// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2852// ES 3.0.4 table 3.24
2853TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2854{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002855 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2856
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002857 glActiveTexture(GL_TEXTURE0);
2858 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2859 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2860 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2861 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2862 EXPECT_GL_NO_ERROR();
2863
2864 drawQuad(mProgram, "position", 0.5f);
2865
2866 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2867}
2868
2869// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2870// ES 3.0.4 table 3.24
2871TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2872{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002873 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2874
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002875 glActiveTexture(GL_TEXTURE0);
2876 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2877 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2878 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2879 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2880 EXPECT_GL_NO_ERROR();
2881
2882 drawQuad(mProgram, "position", 0.5f);
2883
2884 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2885}
2886
2887// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2888// ES 3.0.4 table 3.24
2889TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2890{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002891 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2892
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002893 glActiveTexture(GL_TEXTURE0);
2894 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2895 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2896 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2897 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2898 EXPECT_GL_NO_ERROR();
2899
2900 drawQuad(mProgram, "position", 0.5f);
2901
2902 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2903}
2904
2905// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2906// ES 3.0.4 table 3.24
2907TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2908{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002909 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2910
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002911 glActiveTexture(GL_TEXTURE0);
2912 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2913 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2914 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2915 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2916 EXPECT_GL_NO_ERROR();
2917
2918 drawQuad(mProgram, "position", 0.5f);
2919
2920 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2921}
2922
2923// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2924// ES 3.0.4 table 3.24
2925TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2926{
2927 glActiveTexture(GL_TEXTURE0);
2928 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2929 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2930 EXPECT_GL_NO_ERROR();
2931
2932 drawQuad(mProgram, "position", 0.5f);
2933
2934 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2935}
2936
2937// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2938// ES 3.0.4 table 3.24
2939TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2940{
2941 glActiveTexture(GL_TEXTURE0);
2942 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2943 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2944 nullptr);
2945 EXPECT_GL_NO_ERROR();
2946
2947 drawQuad(mProgram, "position", 0.5f);
2948
2949 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2950}
2951
2952// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2953// ES 3.0.4 table 3.24
2954TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2955{
Yunchao He9550c602018-02-13 14:47:05 +08002956 // Seems to fail on OSX 10.12 Intel.
2957 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Jamie Madillbb1db482017-01-10 10:48:32 -05002958
Yuly Novikov49886892018-01-23 21:18:27 -05002959 // http://anglebug.com/2190
2960 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2961
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002962 glActiveTexture(GL_TEXTURE0);
2963 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2964 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2965 EXPECT_GL_NO_ERROR();
2966
2967 drawQuad(mProgram, "position", 0.5f);
2968
2969 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2970}
2971
2972// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2973// ES 3.0.4 table 3.24
2974TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2975{
Yunchao He9550c602018-02-13 14:47:05 +08002976 // Seems to fail on OSX 10.12 Intel.
2977 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002978
Yuly Novikov49886892018-01-23 21:18:27 -05002979 // http://anglebug.com/2190
2980 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2981
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002982 glActiveTexture(GL_TEXTURE0);
2983 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2984 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2985 EXPECT_GL_NO_ERROR();
2986
2987 drawQuad(mProgram, "position", 0.5f);
2988
2989 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2990}
2991
Olli Etuaho96963162016-03-21 11:54:33 +02002992// Use a sampler in a uniform struct.
2993TEST_P(SamplerInStructTest, SamplerInStruct)
2994{
2995 runSamplerInStructTest();
2996}
2997
2998// Use a sampler in a uniform struct that's passed as a function parameter.
2999TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
3000{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003001 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
3002 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04003003
Olli Etuaho96963162016-03-21 11:54:33 +02003004 runSamplerInStructTest();
3005}
3006
3007// Use a sampler in a uniform struct array with a struct from the array passed as a function
3008// parameter.
3009TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
3010{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003011 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
3012 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08003013
Olli Etuaho96963162016-03-21 11:54:33 +02003014 runSamplerInStructTest();
3015}
3016
3017// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
3018// parameter.
3019TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
3020{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003021 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
3022 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08003023
Olli Etuaho96963162016-03-21 11:54:33 +02003024 runSamplerInStructTest();
3025}
3026
3027// Make sure that there isn't a name conflict between sampler extracted from a struct and a
3028// similarly named uniform.
3029TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
3030{
3031 runSamplerInStructTest();
3032}
3033
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05003034// GL_EXT_texture_filter_anisotropic
3035class TextureAnisotropyTest : public Texture2DTest
3036{
3037 protected:
3038 void uploadTexture()
3039 {
3040 glActiveTexture(GL_TEXTURE0);
3041 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3042 GLColor texDataRed[1] = {GLColor::red};
3043 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed);
3044 EXPECT_GL_NO_ERROR();
3045 }
3046};
3047
3048// Tests that setting anisotropic filtering doesn't cause failures at draw time.
3049TEST_P(TextureAnisotropyTest, AnisotropyFunctional)
3050{
Jamie Madillb8149072019-04-30 16:14:44 -04003051 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_filter_anisotropic"));
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05003052
3053 setUpProgram();
3054
3055 uploadTexture();
3056
3057 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3058 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3059 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f);
3060 EXPECT_GL_NO_ERROR();
3061
3062 drawQuad(mProgram, "position", 0.5f);
3063
3064 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3065 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3066 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::red);
3067}
3068
Till Rathmannb8543632018-10-02 19:46:14 +02003069// GL_OES_texture_border_clamp
3070class TextureBorderClampTest : public Texture2DTest
3071{
3072 protected:
3073 TextureBorderClampTest() : Texture2DTest() {}
3074
Jamie Madill35cd7332018-12-02 12:03:33 -05003075 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003076 {
3077 return
3078 R"(precision highp float;
3079 attribute vec4 position;
3080 varying vec2 texcoord;
3081
3082 void main()
3083 {
3084 gl_Position = vec4(position.xy, 0.0, 1.0);
3085 // texcoords in [-0.5, 1.5]
3086 texcoord = (position.xy) + 0.5;
3087 })";
3088 }
3089
3090 void uploadTexture()
3091 {
3092 glActiveTexture(GL_TEXTURE0);
3093 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3094 std::vector<GLColor> texDataRed(1, GLColor::red);
3095 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3096 texDataRed.data());
3097 EXPECT_GL_NO_ERROR();
3098 }
3099};
3100
3101// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3102// GL_CLAMP_TO_BORDER wrap mode (set with glTexParameter).
3103TEST_P(TextureBorderClampTest, TextureBorderClampFunctional)
3104{
Jamie Madillb8149072019-04-30 16:14:44 -04003105 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003106
3107 setUpProgram();
3108
3109 uploadTexture();
3110
3111 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3112 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3113 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3114 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3115 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3116 EXPECT_GL_NO_ERROR();
3117
3118 drawQuad(mProgram, "position", 0.5f);
3119
3120 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3121 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3122 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3123}
3124
3125// Test reading back GL_TEXTURE_BORDER_COLOR by glGetTexParameter.
3126TEST_P(TextureBorderClampTest, TextureBorderClampFunctional2)
3127{
Jamie Madillb8149072019-04-30 16:14:44 -04003128 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003129
3130 glActiveTexture(GL_TEXTURE0);
3131 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3132
3133 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3134
3135 GLint colorFixedPoint[4] = {0};
3136 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3137 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3138 std::numeric_limits<GLint>::max()};
3139 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3140 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3141 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3142 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3143
3144 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3145 std::numeric_limits<GLint>::max()};
3146 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3147
3148 GLfloat color[4] = {0.0f};
3149 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
3150 EXPECT_EQ(color[0], kFloatBlue.R);
3151 EXPECT_EQ(color[1], kFloatBlue.G);
3152 EXPECT_EQ(color[2], kFloatBlue.B);
3153 EXPECT_EQ(color[3], kFloatBlue.A);
3154}
3155
3156// Test GL_TEXTURE_BORDER_COLOR parameter validation at glTexParameter.
3157TEST_P(TextureBorderClampTest, TextureBorderClampValidation)
3158{
Jamie Madillb8149072019-04-30 16:14:44 -04003159 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003160
3161 glActiveTexture(GL_TEXTURE0);
3162 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3163
3164 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, 1.0f);
3165 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3166
3167 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3168 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3169
3170 glTexParameterfv(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3171 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3172
3173 GLint colorInt[4] = {0};
3174 glTexParameteriv(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_BORDER_COLOR, colorInt);
3175 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3176
3177 if (getClientMajorVersion() < 3)
3178 {
3179 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3180 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3181 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3182 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3183
3184 GLuint colorUInt[4] = {0};
3185 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3186 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3187 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3188 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3189
3190 GLSampler sampler;
3191 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3192 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3193 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3194 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3195
3196 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3197 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3198 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3199 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3200 }
3201}
3202
3203class TextureBorderClampTestES3 : public TextureBorderClampTest
3204{
3205 protected:
3206 TextureBorderClampTestES3() : TextureBorderClampTest() {}
3207};
3208
3209// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3210// GL_CLAMP_TO_BORDER wrap mode (set with glSamplerParameter).
3211TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional)
3212{
Jamie Madillb8149072019-04-30 16:14:44 -04003213 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003214
3215 setUpProgram();
3216
3217 uploadTexture();
3218
3219 GLSampler sampler;
3220 glBindSampler(0, sampler);
3221 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3222 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3223 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3224 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3225 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3226 EXPECT_GL_NO_ERROR();
3227
3228 drawQuad(mProgram, "position", 0.5f);
3229
3230 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3231 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3232 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3233}
3234
3235// Test reading back GL_TEXTURE_BORDER_COLOR by glGetSamplerParameter.
3236TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional2)
3237{
Jamie Madillb8149072019-04-30 16:14:44 -04003238 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003239
3240 glActiveTexture(GL_TEXTURE0);
3241
3242 GLSampler sampler;
3243 glBindSampler(0, sampler);
3244
3245 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3246
3247 GLint colorFixedPoint[4] = {0};
3248 glGetSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3249 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3250 std::numeric_limits<GLint>::max()};
3251 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3252 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3253 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3254 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3255
3256 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3257 std::numeric_limits<GLint>::max()};
3258 glSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3259
3260 GLfloat color[4] = {0.0f};
3261 glGetSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, color);
3262 EXPECT_EQ(color[0], kFloatBlue.R);
3263 EXPECT_EQ(color[1], kFloatBlue.G);
3264 EXPECT_EQ(color[2], kFloatBlue.B);
3265 EXPECT_EQ(color[3], kFloatBlue.A);
3266
3267 constexpr GLint colorSomewhatRedInt[4] = {500000, 0, 0, std::numeric_limits<GLint>::max()};
3268 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedInt);
3269 GLint colorInt[4] = {0};
3270 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3271 EXPECT_EQ(colorInt[0], colorSomewhatRedInt[0]);
3272 EXPECT_EQ(colorInt[1], colorSomewhatRedInt[1]);
3273 EXPECT_EQ(colorInt[2], colorSomewhatRedInt[2]);
3274 EXPECT_EQ(colorInt[3], colorSomewhatRedInt[3]);
3275
3276 constexpr GLuint colorSomewhatRedUInt[4] = {500000, 0, 0, std::numeric_limits<GLuint>::max()};
3277 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedUInt);
3278 GLuint colorUInt[4] = {0};
3279 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3280 EXPECT_EQ(colorUInt[0], colorSomewhatRedUInt[0]);
3281 EXPECT_EQ(colorUInt[1], colorSomewhatRedUInt[1]);
3282 EXPECT_EQ(colorUInt[2], colorSomewhatRedUInt[2]);
3283 EXPECT_EQ(colorUInt[3], colorSomewhatRedUInt[3]);
3284
3285 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3286
3287 constexpr GLint colorSomewhatGreenInt[4] = {0, 500000, 0, std::numeric_limits<GLint>::max()};
3288 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenInt);
3289 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3290 EXPECT_EQ(colorInt[0], colorSomewhatGreenInt[0]);
3291 EXPECT_EQ(colorInt[1], colorSomewhatGreenInt[1]);
3292 EXPECT_EQ(colorInt[2], colorSomewhatGreenInt[2]);
3293 EXPECT_EQ(colorInt[3], colorSomewhatGreenInt[3]);
3294
3295 constexpr GLuint colorSomewhatGreenUInt[4] = {0, 500000, 0, std::numeric_limits<GLuint>::max()};
3296 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenUInt);
3297 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3298 EXPECT_EQ(colorUInt[0], colorSomewhatGreenUInt[0]);
3299 EXPECT_EQ(colorUInt[1], colorSomewhatGreenUInt[1]);
3300 EXPECT_EQ(colorUInt[2], colorSomewhatGreenUInt[2]);
3301 EXPECT_EQ(colorUInt[3], colorSomewhatGreenUInt[3]);
3302}
3303
3304// Test GL_TEXTURE_BORDER_COLOR parameter validation at glSamplerParameter.
3305TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Validation)
3306{
Jamie Madillb8149072019-04-30 16:14:44 -04003307 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003308
3309 glActiveTexture(GL_TEXTURE0);
3310
3311 GLSampler sampler;
3312 glBindSampler(0, sampler);
3313
3314 glSamplerParameterf(sampler, GL_TEXTURE_BORDER_COLOR, 1.0f);
3315 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3316
3317 glSamplerParameteri(sampler, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3318 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3319}
3320
3321class TextureBorderClampIntegerTestES3 : public Texture2DTest
3322{
3323 protected:
3324 TextureBorderClampIntegerTestES3() : Texture2DTest(), isUnsignedIntTest(false) {}
3325
Jamie Madill35cd7332018-12-02 12:03:33 -05003326 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003327 {
3328 return
3329 R"(#version 300 es
3330 out vec2 texcoord;
3331 in vec4 position;
3332
3333 void main()
3334 {
3335 gl_Position = vec4(position.xy, 0.0, 1.0);
3336 // texcoords in [-0.5, 1.5]
3337 texcoord = (position.xy) + 0.5;
3338 })";
3339 }
3340
Jamie Madillba319ba2018-12-29 10:29:33 -05003341 const char *getFragmentShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003342 {
Jamie Madill35cd7332018-12-02 12:03:33 -05003343 if (isUnsignedIntTest)
3344 {
3345 return "#version 300 es\n"
3346 "precision highp float;\n"
3347 "uniform highp usampler2D tex;\n"
3348 "in vec2 texcoord;\n"
3349 "out vec4 fragColor;\n"
Till Rathmannb8543632018-10-02 19:46:14 +02003350
Jamie Madill35cd7332018-12-02 12:03:33 -05003351 "void main()\n"
3352 "{\n"
3353 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3354 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3355 "fragColor = (texture(tex, texcoord).r == 150u)"
3356 " ? green : red;\n"
3357 "}\n";
3358 }
3359 else
3360 {
3361 return "#version 300 es\n"
3362 "precision highp float;\n"
3363 "uniform highp isampler2D tex;\n"
3364 "in vec2 texcoord;\n"
3365 "out vec4 fragColor;\n"
3366
3367 "void main()\n"
3368 "{\n"
3369 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3370 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3371 "fragColor = (texture(tex, texcoord).r == -50)"
3372 " ? green : red;\n"
3373 "}\n";
3374 }
Till Rathmannb8543632018-10-02 19:46:14 +02003375 }
3376
3377 void uploadTexture()
3378 {
3379 glActiveTexture(GL_TEXTURE0);
3380 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3381 if (isUnsignedIntTest)
3382 {
3383 std::vector<GLubyte> texData(4, 100);
3384 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE,
3385 texData.data());
3386 }
3387 else
3388 {
3389 std::vector<GLbyte> texData(4, 100);
3390 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8I, 1, 1, 0, GL_RGBA_INTEGER, GL_BYTE,
3391 texData.data());
3392 }
3393 EXPECT_GL_NO_ERROR();
3394 }
3395
3396 bool isUnsignedIntTest;
3397};
3398
3399// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3400// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3401TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger)
3402{
Jamie Madillb8149072019-04-30 16:14:44 -04003403 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003404
3405 setUpProgram();
3406
3407 uploadTexture();
3408
3409 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3410 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3411 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3412 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3413
3414 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3415 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3416
3417 EXPECT_GL_NO_ERROR();
3418
3419 drawQuad(mProgram, "position", 0.5f);
3420
3421 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3422 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3423 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3424}
3425
3426// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3427// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3428TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger2)
3429{
Jamie Madillb8149072019-04-30 16:14:44 -04003430 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003431
3432 setUpProgram();
3433
3434 uploadTexture();
3435
3436 GLSampler sampler;
3437 glBindSampler(0, sampler);
3438 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3439 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3440 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3441 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3442
3443 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3444 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3445
3446 EXPECT_GL_NO_ERROR();
3447
3448 drawQuad(mProgram, "position", 0.5f);
3449
3450 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3451 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3452 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3453}
3454
3455// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3456// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIuivOES).
3457TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned)
3458{
Jamie Madillb8149072019-04-30 16:14:44 -04003459 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003460
3461 isUnsignedIntTest = true;
3462
3463 setUpProgram();
3464
3465 uploadTexture();
3466
3467 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3468 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3469 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3470 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3471
3472 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3473 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3474
3475 EXPECT_GL_NO_ERROR();
3476
3477 drawQuad(mProgram, "position", 0.5f);
3478
3479 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3480 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3481 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3482}
3483
3484// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3485// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with
3486// glSamplerParameterIuivOES).
3487TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned2)
3488{
Jamie Madillb8149072019-04-30 16:14:44 -04003489 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003490
3491 isUnsignedIntTest = true;
3492
3493 setUpProgram();
3494
3495 uploadTexture();
3496
3497 GLSampler sampler;
3498 glBindSampler(0, sampler);
3499 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3500 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3501 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3502 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3503
3504 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3505 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3506
3507 EXPECT_GL_NO_ERROR();
3508
3509 drawQuad(mProgram, "position", 0.5f);
3510
3511 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3512 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3513 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3514}
3515
3516// ~GL_OES_texture_border_clamp
3517
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003518class TextureLimitsTest : public ANGLETest
3519{
3520 protected:
3521 struct RGBA8
3522 {
3523 uint8_t R, G, B, A;
3524 };
3525
3526 TextureLimitsTest()
3527 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
3528 {
3529 setWindowWidth(128);
3530 setWindowHeight(128);
3531 setConfigRedBits(8);
3532 setConfigGreenBits(8);
3533 setConfigBlueBits(8);
3534 setConfigAlphaBits(8);
3535 }
3536
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003537 void testSetUp() override
Jamie Madill0fdb9562018-09-17 17:18:43 -04003538 {
Jamie Madill0fdb9562018-09-17 17:18:43 -04003539 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
3540 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
3541 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
3542
3543 ASSERT_GL_NO_ERROR();
3544 }
3545
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003546 void testTearDown() override
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003547 {
3548 if (mProgram != 0)
3549 {
3550 glDeleteProgram(mProgram);
3551 mProgram = 0;
3552
3553 if (!mTextures.empty())
3554 {
3555 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
3556 }
3557 }
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003558 }
3559
3560 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
3561 GLint vertexTextureCount,
3562 GLint vertexActiveTextureCount,
3563 const std::string &fragPrefix,
3564 GLint fragmentTextureCount,
3565 GLint fragmentActiveTextureCount)
3566 {
3567 std::stringstream vertexShaderStr;
3568 vertexShaderStr << "attribute vec2 position;\n"
3569 << "varying vec4 color;\n"
3570 << "varying vec2 texCoord;\n";
3571
3572 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
3573 {
3574 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
3575 }
3576
3577 vertexShaderStr << "void main() {\n"
3578 << " gl_Position = vec4(position, 0, 1);\n"
3579 << " texCoord = (position * 0.5) + 0.5;\n"
3580 << " color = vec4(0);\n";
3581
3582 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
3583 {
3584 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
3585 << ", texCoord);\n";
3586 }
3587
3588 vertexShaderStr << "}";
3589
3590 std::stringstream fragmentShaderStr;
3591 fragmentShaderStr << "varying mediump vec4 color;\n"
3592 << "varying mediump vec2 texCoord;\n";
3593
3594 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
3595 {
3596 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
3597 }
3598
3599 fragmentShaderStr << "void main() {\n"
3600 << " gl_FragColor = color;\n";
3601
3602 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
3603 {
3604 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
3605 << ", texCoord);\n";
3606 }
3607
3608 fragmentShaderStr << "}";
3609
3610 const std::string &vertexShaderSource = vertexShaderStr.str();
3611 const std::string &fragmentShaderSource = fragmentShaderStr.str();
3612
Jamie Madill35cd7332018-12-02 12:03:33 -05003613 mProgram = CompileProgram(vertexShaderSource.c_str(), fragmentShaderSource.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003614 }
3615
3616 RGBA8 getPixel(GLint texIndex)
3617 {
3618 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3619 0, 255u};
3620 return pixel;
3621 }
3622
3623 void initTextures(GLint tex2DCount, GLint texCubeCount)
3624 {
3625 GLint totalCount = tex2DCount + texCubeCount;
3626 mTextures.assign(totalCount, 0);
3627 glGenTextures(totalCount, &mTextures[0]);
3628 ASSERT_GL_NO_ERROR();
3629
3630 std::vector<RGBA8> texData(16 * 16);
3631
3632 GLint texIndex = 0;
3633 for (; texIndex < tex2DCount; ++texIndex)
3634 {
3635 texData.assign(texData.size(), getPixel(texIndex));
3636 glActiveTexture(GL_TEXTURE0 + texIndex);
3637 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3638 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3639 &texData[0]);
3640 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3641 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3642 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3643 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3644 }
3645
3646 ASSERT_GL_NO_ERROR();
3647
3648 for (; texIndex < texCubeCount; ++texIndex)
3649 {
3650 texData.assign(texData.size(), getPixel(texIndex));
3651 glActiveTexture(GL_TEXTURE0 + texIndex);
3652 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3653 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3654 GL_UNSIGNED_BYTE, &texData[0]);
3655 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3656 GL_UNSIGNED_BYTE, &texData[0]);
3657 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3658 GL_UNSIGNED_BYTE, &texData[0]);
3659 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3660 GL_UNSIGNED_BYTE, &texData[0]);
3661 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3662 GL_UNSIGNED_BYTE, &texData[0]);
3663 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3664 GL_UNSIGNED_BYTE, &texData[0]);
3665 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3666 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3667 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3668 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3669 }
3670
3671 ASSERT_GL_NO_ERROR();
3672 }
3673
3674 void testWithTextures(GLint vertexTextureCount,
3675 const std::string &vertexTexturePrefix,
3676 GLint fragmentTextureCount,
3677 const std::string &fragmentTexturePrefix)
3678 {
3679 // Generate textures
3680 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3681
3682 glUseProgram(mProgram);
3683 RGBA8 expectedSum = {0};
3684 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3685 {
3686 std::stringstream uniformNameStr;
3687 uniformNameStr << vertexTexturePrefix << texIndex;
3688 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003689 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003690 ASSERT_NE(-1, location);
3691
3692 glUniform1i(location, texIndex);
3693 RGBA8 contribution = getPixel(texIndex);
3694 expectedSum.R += contribution.R;
3695 expectedSum.G += contribution.G;
3696 }
3697
3698 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3699 {
3700 std::stringstream uniformNameStr;
3701 uniformNameStr << fragmentTexturePrefix << texIndex;
3702 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003703 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003704 ASSERT_NE(-1, location);
3705
3706 glUniform1i(location, texIndex + vertexTextureCount);
3707 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3708 expectedSum.R += contribution.R;
3709 expectedSum.G += contribution.G;
3710 }
3711
3712 ASSERT_GE(256u, expectedSum.G);
3713
3714 drawQuad(mProgram, "position", 0.5f);
3715 ASSERT_GL_NO_ERROR();
3716 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3717 }
3718
3719 GLuint mProgram;
3720 std::vector<GLuint> mTextures;
3721 GLint mMaxVertexTextures;
3722 GLint mMaxFragmentTextures;
3723 GLint mMaxCombinedTextures;
3724};
3725
3726// Test rendering with the maximum vertex texture units.
3727TEST_P(TextureLimitsTest, MaxVertexTextures)
3728{
3729 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3730 ASSERT_NE(0u, mProgram);
3731 ASSERT_GL_NO_ERROR();
3732
3733 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3734}
3735
3736// Test rendering with the maximum fragment texture units.
3737TEST_P(TextureLimitsTest, MaxFragmentTextures)
3738{
3739 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3740 ASSERT_NE(0u, mProgram);
3741 ASSERT_GL_NO_ERROR();
3742
3743 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3744}
3745
3746// Test rendering with maximum combined texture units.
3747TEST_P(TextureLimitsTest, MaxCombinedTextures)
3748{
3749 GLint vertexTextures = mMaxVertexTextures;
3750
3751 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3752 {
3753 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3754 }
3755
3756 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3757 mMaxFragmentTextures, mMaxFragmentTextures);
3758 ASSERT_NE(0u, mProgram);
3759 ASSERT_GL_NO_ERROR();
3760
3761 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3762}
3763
3764// Negative test for exceeding the number of vertex textures
3765TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3766{
3767 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3768 0);
3769 ASSERT_EQ(0u, mProgram);
3770}
3771
3772// Negative test for exceeding the number of fragment textures
3773TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3774{
3775 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3776 mMaxFragmentTextures + 1);
3777 ASSERT_EQ(0u, mProgram);
3778}
3779
3780// Test active vertex textures under the limit, but excessive textures specified.
3781TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3782{
3783 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3784 ASSERT_NE(0u, mProgram);
3785 ASSERT_GL_NO_ERROR();
3786
3787 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3788}
3789
3790// Test active fragment textures under the limit, but excessive textures specified.
3791TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3792{
3793 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3794 mMaxFragmentTextures);
3795 ASSERT_NE(0u, mProgram);
3796 ASSERT_GL_NO_ERROR();
3797
3798 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3799}
3800
3801// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003802// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003803TEST_P(TextureLimitsTest, TextureTypeConflict)
3804{
Jamie Madill35cd7332018-12-02 12:03:33 -05003805 constexpr char kVS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003806 "attribute vec2 position;\n"
3807 "varying float color;\n"
3808 "uniform sampler2D tex2D;\n"
3809 "uniform samplerCube texCube;\n"
3810 "void main() {\n"
3811 " gl_Position = vec4(position, 0, 1);\n"
3812 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3813 " color = texture2D(tex2D, texCoord).x;\n"
3814 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3815 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05003816 constexpr char kFS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003817 "varying mediump float color;\n"
3818 "void main() {\n"
3819 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3820 "}";
3821
Jamie Madill35cd7332018-12-02 12:03:33 -05003822 mProgram = CompileProgram(kVS, kFS);
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003823 ASSERT_NE(0u, mProgram);
3824
3825 initTextures(1, 0);
3826
3827 glUseProgram(mProgram);
3828 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3829 ASSERT_NE(-1, tex2DLocation);
3830 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3831 ASSERT_NE(-1, texCubeLocation);
3832
3833 glUniform1i(tex2DLocation, 0);
3834 glUniform1i(texCubeLocation, 0);
3835 ASSERT_GL_NO_ERROR();
3836
3837 drawQuad(mProgram, "position", 0.5f);
3838 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3839}
3840
Vincent Lang25ab4512016-05-13 18:13:59 +02003841class Texture2DNorm16TestES3 : public Texture2DTestES3
3842{
3843 protected:
3844 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3845
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003846 void testSetUp() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003847 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003848 Texture2DTestES3::testSetUp();
Vincent Lang25ab4512016-05-13 18:13:59 +02003849
3850 glActiveTexture(GL_TEXTURE0);
3851 glGenTextures(3, mTextures);
3852 glGenFramebuffers(1, &mFBO);
3853 glGenRenderbuffers(1, &mRenderbuffer);
3854
3855 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3856 {
3857 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3858 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3859 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3860 }
3861
3862 glBindTexture(GL_TEXTURE_2D, 0);
3863
3864 ASSERT_GL_NO_ERROR();
3865 }
3866
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003867 void testTearDown() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003868 {
3869 glDeleteTextures(3, mTextures);
3870 glDeleteFramebuffers(1, &mFBO);
3871 glDeleteRenderbuffers(1, &mRenderbuffer);
3872
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003873 Texture2DTestES3::testTearDown();
Vincent Lang25ab4512016-05-13 18:13:59 +02003874 }
3875
3876 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3877 {
Geoff Langf607c602016-09-21 11:46:48 -04003878 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3879 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003880
3881 setUpProgram();
3882
3883 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3884 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3885 0);
3886
3887 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3888 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3889
3890 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003891 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003892
3893 EXPECT_GL_NO_ERROR();
3894
3895 drawQuad(mProgram, "position", 0.5f);
3896
Geoff Langf607c602016-09-21 11:46:48 -04003897 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003898
Jamie Madill50cf2be2018-06-15 09:46:57 -04003899 EXPECT_PIXEL_COLOR_EQ(0, 0,
3900 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3901 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003902
3903 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3904
3905 ASSERT_GL_NO_ERROR();
3906 }
3907
3908 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3909 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04003910 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003911 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003912
3913 setUpProgram();
3914
3915 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3916 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3917
3918 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3919 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3920 0);
3921
3922 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003923 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003924
3925 EXPECT_GL_NO_ERROR();
3926
3927 drawQuad(mProgram, "position", 0.5f);
3928
Geoff Langf607c602016-09-21 11:46:48 -04003929 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
Jamie Madill50cf2be2018-06-15 09:46:57 -04003930 EXPECT_PIXEL_COLOR_EQ(0, 0,
3931 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3932 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003933
3934 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3935 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3936 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3937 mRenderbuffer);
3938 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3939 EXPECT_GL_NO_ERROR();
3940
3941 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3942 glClear(GL_COLOR_BUFFER_BIT);
3943
3944 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3945
Geoff Langf607c602016-09-21 11:46:48 -04003946 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003947
3948 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3949
3950 ASSERT_GL_NO_ERROR();
3951 }
3952
3953 GLuint mTextures[3];
3954 GLuint mFBO;
3955 GLuint mRenderbuffer;
3956};
3957
3958// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3959TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3960{
Jamie Madillb8149072019-04-30 16:14:44 -04003961 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02003962
3963 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3964 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3965 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3966 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3967 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3968 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3969 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3970 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3971
3972 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3973 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3974 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3975}
3976
Olli Etuaho95faa232016-06-07 14:01:53 -07003977// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3978// GLES 3.0.4 section 3.8.3.
3979TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3980{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003981 // Crashes on Nexus 5X due to a driver bug. http://anglebug.com/1429
3982 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07003983
3984 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3985 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3986 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3987 ASSERT_GL_NO_ERROR();
3988
3989 // SKIP_IMAGES should not have an effect on uploading 2D textures
3990 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3991 ASSERT_GL_NO_ERROR();
3992
3993 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3994
3995 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3996 pixelsGreen.data());
3997 ASSERT_GL_NO_ERROR();
3998
3999 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
4000 pixelsGreen.data());
4001 ASSERT_GL_NO_ERROR();
4002
4003 glUseProgram(mProgram);
4004 drawQuad(mProgram, "position", 0.5f);
4005 ASSERT_GL_NO_ERROR();
4006
4007 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
4008}
4009
Olli Etuaho989cac32016-06-08 16:18:49 -07004010// Test that skip defined in unpack parameters is taken into account when determining whether
4011// unpacking source extends outside unpack buffer bounds.
4012TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
4013{
4014 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4015 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4016 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4017 ASSERT_GL_NO_ERROR();
4018
4019 GLBuffer buf;
4020 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
4021 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
4022 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
4023 GL_DYNAMIC_COPY);
4024 ASSERT_GL_NO_ERROR();
4025
4026 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4027 ASSERT_GL_NO_ERROR();
4028
4029 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
4030 ASSERT_GL_NO_ERROR();
4031
4032 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4033 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4034
4035 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
4036 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
4037 ASSERT_GL_NO_ERROR();
4038
4039 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4040 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4041}
4042
Olli Etuaho218cf9e2016-05-20 13:55:24 +03004043// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
4044TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
4045{
Yunchao He9550c602018-02-13 14:47:05 +08004046 ANGLE_SKIP_TEST_IF(IsD3D11());
4047
4048 // Incorrect rendering results seen on OSX AMD.
4049 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03004050
4051 const GLuint width = 8u;
4052 const GLuint height = 8u;
4053 const GLuint unpackRowLength = 5u;
4054 const GLuint unpackSkipPixels = 1u;
4055
4056 setWindowWidth(width);
4057 setWindowHeight(height);
4058
4059 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4060 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4061 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4062 ASSERT_GL_NO_ERROR();
4063
4064 GLBuffer buf;
4065 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
4066 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
4067 GLColor::green);
4068
4069 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
4070 {
4071 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
4072 }
4073
4074 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
4075 GL_DYNAMIC_COPY);
4076 ASSERT_GL_NO_ERROR();
4077
4078 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
4079 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
4080 ASSERT_GL_NO_ERROR();
4081
4082 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4083 ASSERT_GL_NO_ERROR();
4084
4085 glUseProgram(mProgram);
4086 drawQuad(mProgram, "position", 0.5f);
4087 ASSERT_GL_NO_ERROR();
4088
4089 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
4090 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
4091 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
4092 actual.data());
4093 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
4094 EXPECT_EQ(expected, actual);
4095}
4096
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004097template <typename T>
4098T UNorm(double value)
4099{
4100 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
4101}
4102
4103// Test rendering a depth texture with mipmaps.
4104TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
4105{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08004106 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
4107 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
Jiawei Shaoaf0f31d2018-09-27 15:42:31 +08004108 // http://anglebug.com/1706
4109 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Corentin Walleze731d8a2016-09-07 10:56:25 -04004110
Jamie Madill24980272019-04-03 09:03:51 -04004111 // Seems to fail on AMD D3D11. Possibly driver bug. http://anglebug.com/3342
4112 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsD3D11());
4113
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004114 const int size = getWindowWidth();
4115
4116 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04004117 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004118
4119 glActiveTexture(GL_TEXTURE0);
4120 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4121 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
4122 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4123 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4124 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
4125 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
4126 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4127 ASSERT_GL_NO_ERROR();
4128
4129 glUseProgram(mProgram);
4130 glUniform1i(mTexture2DUniformLocation, 0);
4131
4132 std::vector<unsigned char> expected;
4133
4134 for (int level = 0; level < levels; ++level)
4135 {
4136 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
4137 expected.push_back(UNorm<unsigned char>(value));
4138
4139 int levelDim = dim(level);
4140
4141 ASSERT_GT(levelDim, 0);
4142
4143 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
4144 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
4145 GL_UNSIGNED_INT, initData.data());
4146 }
4147 ASSERT_GL_NO_ERROR();
4148
4149 for (int level = 0; level < levels; ++level)
4150 {
4151 glViewport(0, 0, dim(level), dim(level));
4152 drawQuad(mProgram, "position", 0.5f);
4153 GLColor actual = ReadColor(0, 0);
4154 EXPECT_NEAR(expected[level], actual.R, 10u);
4155 }
4156
4157 ASSERT_GL_NO_ERROR();
4158}
4159
Jamie Madill7ffdda92016-09-08 13:26:51 -04004160// Tests unpacking into the unsized GL_ALPHA format.
4161TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
4162{
Jamie Madill7ffdda92016-09-08 13:26:51 -04004163 // Initialize the texure.
4164 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4165 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
4166 GL_UNSIGNED_BYTE, nullptr);
4167 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4168 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4169
4170 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
4171
4172 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04004173 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04004174 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4175 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4176 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
4177 GL_STATIC_DRAW);
4178
4179 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
4180 GL_UNSIGNED_BYTE, nullptr);
4181
4182 // Clear to a weird color to make sure we're drawing something.
4183 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
4184 glClear(GL_COLOR_BUFFER_BIT);
4185
4186 // Draw with the alpha texture and verify.
4187 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04004188
4189 ASSERT_GL_NO_ERROR();
4190 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
4191}
4192
Jamie Madill2e600342016-09-19 13:56:40 -04004193// Ensure stale unpack data doesn't propagate in D3D11.
4194TEST_P(Texture2DTestES3, StaleUnpackData)
4195{
4196 // Init unpack buffer.
4197 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
4198 std::vector<GLColor> pixels(pixelCount, GLColor::red);
4199
4200 GLBuffer unpackBuffer;
4201 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4202 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4203 GLsizei bufferSize = pixelCount * sizeof(GLColor);
4204 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
4205
4206 // Create from unpack buffer.
4207 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4208 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
4209 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4210 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4211 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4212
4213 drawQuad(mProgram, "position", 0.5f);
4214
4215 ASSERT_GL_NO_ERROR();
4216 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4217
4218 // Fill unpack with green, recreating buffer.
4219 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
4220 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
4221 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
4222
4223 // Reinit texture with green.
4224 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
4225 GL_UNSIGNED_BYTE, nullptr);
4226
4227 drawQuad(mProgram, "position", 0.5f);
4228
4229 ASSERT_GL_NO_ERROR();
4230 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
4231}
4232
Geoff Langfb7685f2017-11-13 11:44:11 -05004233// Ensure that texture parameters passed as floats that are converted to ints are rounded before
4234// validating they are less than 0.
4235TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
4236{
4237 GLTexture texture;
4238 glBindTexture(GL_TEXTURE_2D, texture);
4239
4240 // Use a negative number that will round to zero when converted to an integer
4241 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
4242 // "Validation of values performed by state-setting commands is performed after conversion,
4243 // unless specified otherwise for a specific command."
4244 GLfloat param = -7.30157126e-07f;
4245 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
4246 EXPECT_GL_NO_ERROR();
4247
4248 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
4249 EXPECT_GL_NO_ERROR();
4250}
4251
Jamie Madillf097e232016-11-05 00:44:15 -04004252// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
4253// being properly checked, and the texture storage of the previous texture format was persisting.
4254// This would result in an ASSERT in debug and incorrect rendering in release.
4255// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
4256TEST_P(Texture3DTestES3, FormatRedefinitionBug)
4257{
4258 GLTexture tex;
4259 glBindTexture(GL_TEXTURE_3D, tex.get());
4260 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4261
4262 GLFramebuffer framebuffer;
4263 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
4264 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
4265
4266 glCheckFramebufferStatus(GL_FRAMEBUFFER);
4267
4268 std::vector<uint8_t> pixelData(100, 0);
4269
4270 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
4271 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
4272 pixelData.data());
4273
4274 ASSERT_GL_NO_ERROR();
4275}
4276
Corentin Wallezd2627992017-04-28 17:17:03 -04004277// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
4278TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
4279{
4280 // 2D tests
4281 {
4282 GLTexture tex;
4283 glBindTexture(GL_TEXTURE_2D, tex.get());
4284
4285 GLBuffer pbo;
4286 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4287
4288 // Test OOB
4289 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
4290 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4291 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4292
4293 // Test OOB
4294 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
4295 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4296 ASSERT_GL_NO_ERROR();
4297 }
4298
4299 // 3D tests
4300 {
4301 GLTexture tex;
4302 glBindTexture(GL_TEXTURE_3D, tex.get());
4303
4304 GLBuffer pbo;
4305 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4306
4307 // Test OOB
4308 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
4309 GL_STATIC_DRAW);
4310 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4311 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4312
4313 // Test OOB
4314 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
4315 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4316 ASSERT_GL_NO_ERROR();
4317 }
4318}
4319
Jamie Madill3ed60422017-09-07 11:32:52 -04004320// Tests behaviour with a single texture and multiple sampler objects.
4321TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
4322{
4323 GLint maxTextureUnits = 0;
4324 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
4325 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
4326
4327 constexpr int kSize = 16;
4328
4329 // Make a single-level texture, fill it with red.
4330 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
4331 GLTexture tex;
4332 glBindTexture(GL_TEXTURE_2D, tex);
4333 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4334 redColors.data());
4335 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4336 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4337
4338 // Simple sanity check.
4339 draw2DTexturedQuad(0.5f, 1.0f, true);
4340 ASSERT_GL_NO_ERROR();
4341 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4342
4343 // Bind texture to unit 1 with a sampler object making it incomplete.
4344 GLSampler sampler;
4345 glBindSampler(0, sampler);
4346 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4347 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4348
4349 // Make a mipmap texture, fill it with blue.
4350 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
4351 GLTexture mipmapTex;
4352 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4353 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4354 blueColors.data());
4355 glGenerateMipmap(GL_TEXTURE_2D);
4356
4357 // Draw with the sampler, expect blue.
4358 draw2DTexturedQuad(0.5f, 1.0f, true);
4359 ASSERT_GL_NO_ERROR();
4360 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
4361
4362 // Simple multitexturing program.
Jamie Madill35cd7332018-12-02 12:03:33 -05004363 constexpr char kVS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004364 "#version 300 es\n"
4365 "in vec2 position;\n"
4366 "out vec2 texCoord;\n"
4367 "void main()\n"
4368 "{\n"
4369 " gl_Position = vec4(position, 0, 1);\n"
4370 " texCoord = position * 0.5 + vec2(0.5);\n"
4371 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05004372
4373 constexpr char kFS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004374 "#version 300 es\n"
4375 "precision mediump float;\n"
4376 "in vec2 texCoord;\n"
4377 "uniform sampler2D tex1;\n"
4378 "uniform sampler2D tex2;\n"
4379 "uniform sampler2D tex3;\n"
4380 "uniform sampler2D tex4;\n"
4381 "out vec4 color;\n"
4382 "void main()\n"
4383 "{\n"
4384 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
4385 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
4386 "}";
4387
Jamie Madill35cd7332018-12-02 12:03:33 -05004388 ANGLE_GL_PROGRAM(program, kVS, kFS);
Jamie Madill3ed60422017-09-07 11:32:52 -04004389
4390 std::array<GLint, 4> texLocations = {
4391 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
4392 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
4393 for (GLint location : texLocations)
4394 {
4395 ASSERT_NE(-1, location);
4396 }
4397
4398 // Init the uniform data.
4399 glUseProgram(program);
4400 for (GLint location = 0; location < 4; ++location)
4401 {
4402 glUniform1i(texLocations[location], location);
4403 }
4404
4405 // Initialize four samplers
4406 GLSampler samplers[4];
4407
4408 // 0: non-mipped.
4409 glBindSampler(0, samplers[0]);
4410 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4411 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4412
4413 // 1: mipped.
4414 glBindSampler(1, samplers[1]);
4415 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4416 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4417
4418 // 2: non-mipped.
4419 glBindSampler(2, samplers[2]);
4420 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4421 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4422
4423 // 3: mipped.
4424 glBindSampler(3, samplers[3]);
4425 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4426 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4427
4428 // Bind two blue mipped textures and two single layer textures, should all draw.
4429 glActiveTexture(GL_TEXTURE0);
4430 glBindTexture(GL_TEXTURE_2D, tex);
4431
4432 glActiveTexture(GL_TEXTURE1);
4433 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4434
4435 glActiveTexture(GL_TEXTURE2);
4436 glBindTexture(GL_TEXTURE_2D, tex);
4437
4438 glActiveTexture(GL_TEXTURE3);
4439 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4440
4441 ASSERT_GL_NO_ERROR();
4442
4443 drawQuad(program, "position", 0.5f);
4444 ASSERT_GL_NO_ERROR();
4445 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
4446
4447 // Bind four single layer textures, two should be incomplete.
4448 glActiveTexture(GL_TEXTURE1);
4449 glBindTexture(GL_TEXTURE_2D, tex);
4450
4451 glActiveTexture(GL_TEXTURE3);
4452 glBindTexture(GL_TEXTURE_2D, tex);
4453
4454 drawQuad(program, "position", 0.5f);
4455 ASSERT_GL_NO_ERROR();
4456 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
4457}
4458
Martin Radev7e2c0d32017-09-15 14:25:42 +03004459// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
4460// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
4461// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
4462// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
4463// samples the cubemap using a direction vector (1,1,1).
4464TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
4465{
Yunchao He2f23f352018-02-11 22:11:37 +08004466 // Check http://anglebug.com/2155.
4467 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
4468
Jamie Madill35cd7332018-12-02 12:03:33 -05004469 constexpr char kVS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004470 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004471 precision mediump float;
4472 in vec3 pos;
4473 void main() {
4474 gl_Position = vec4(pos, 1.0);
4475 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03004476
Jamie Madill35cd7332018-12-02 12:03:33 -05004477 constexpr char kFS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004478 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004479 precision mediump float;
4480 out vec4 color;
4481 uniform samplerCube uTex;
4482 void main(){
4483 color = texture(uTex, vec3(1.0));
4484 })";
Jamie Madill35cd7332018-12-02 12:03:33 -05004485
4486 ANGLE_GL_PROGRAM(program, kVS, kFS);
Martin Radev7e2c0d32017-09-15 14:25:42 +03004487 glUseProgram(program);
4488
4489 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
4490 glActiveTexture(GL_TEXTURE0);
4491
4492 GLTexture cubeTex;
4493 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
4494
4495 const int kFaceWidth = 1;
4496 const int kFaceHeight = 1;
4497 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
4498 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4499 GL_UNSIGNED_BYTE, texData.data());
4500 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4501 GL_UNSIGNED_BYTE, texData.data());
4502 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4503 GL_UNSIGNED_BYTE, texData.data());
4504 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4505 GL_UNSIGNED_BYTE, texData.data());
4506 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4507 GL_UNSIGNED_BYTE, texData.data());
4508 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4509 GL_UNSIGNED_BYTE, texData.data());
4510 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4511 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4512 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
4513 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
4514 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
4515 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
4516
4517 drawQuad(program, "pos", 0.5f, 1.0f, true);
4518 ASSERT_GL_NO_ERROR();
4519
4520 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4521}
4522
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08004523// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
4524TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
4525{
4526 GLuint texture = create2DTexture();
4527
4528 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
4529 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4530
4531 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
4532 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4533
4534 glDeleteTextures(1, &texture);
4535 EXPECT_GL_NO_ERROR();
4536}
4537
Olli Etuaho023371b2018-04-24 17:43:32 +03004538// Test setting base level after calling generateMipmap on a LUMA texture.
4539// Covers http://anglebug.com/2498
4540TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA)
4541{
4542 glActiveTexture(GL_TEXTURE0);
4543 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4544
4545 constexpr const GLsizei kWidth = 8;
4546 constexpr const GLsizei kHeight = 8;
4547 std::array<GLubyte, kWidth * kHeight * 2> whiteData;
4548 whiteData.fill(255u);
4549
4550 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA,
4551 GL_UNSIGNED_BYTE, whiteData.data());
4552 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
4553 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4554 glGenerateMipmap(GL_TEXTURE_2D);
4555 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
4556 EXPECT_GL_NO_ERROR();
4557
4558 drawQuad(mProgram, "position", 0.5f);
4559 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4560}
4561
Till Rathmannc1551dc2018-08-15 17:04:49 +02004562// Covers a bug in the D3D11 backend: http://anglebug.com/2772
4563// When using a sampler the texture was created as if it has mipmaps,
4564// regardless what you specified in GL_TEXTURE_MIN_FILTER via
4565// glSamplerParameteri() -- mistakenly the default value
4566// GL_NEAREST_MIPMAP_LINEAR or the value set via glTexParameteri() was
4567// evaluated.
4568// If you didn't provide mipmaps and didn't let the driver generate them
4569// this led to not sampling your texture data when minification occurred.
4570TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping)
4571{
Jamie Madill35cd7332018-12-02 12:03:33 -05004572 constexpr char kVS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004573 "#version 300 es\n"
4574 "out vec2 texcoord;\n"
4575 "in vec4 position;\n"
4576 "void main()\n"
4577 "{\n"
4578 " gl_Position = vec4(position.xy * 0.1, 0.0, 1.0);\n"
4579 " texcoord = (position.xy * 0.5) + 0.5;\n"
4580 "}\n";
4581
Jamie Madill35cd7332018-12-02 12:03:33 -05004582 constexpr char kFS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004583 "#version 300 es\n"
4584 "precision highp float;\n"
4585 "uniform highp sampler2D tex;\n"
4586 "in vec2 texcoord;\n"
4587 "out vec4 fragColor;\n"
4588 "void main()\n"
4589 "{\n"
4590 " fragColor = texture(tex, texcoord);\n"
4591 "}\n";
Jamie Madill35cd7332018-12-02 12:03:33 -05004592
4593 ANGLE_GL_PROGRAM(program, kVS, kFS);
Till Rathmannc1551dc2018-08-15 17:04:49 +02004594
4595 GLSampler sampler;
4596 glBindSampler(0, sampler);
4597 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4598 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4599
4600 glActiveTexture(GL_TEXTURE0);
4601 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4602
4603 const GLsizei texWidth = getWindowWidth();
4604 const GLsizei texHeight = getWindowHeight();
4605 const std::vector<GLColor> whiteData(texWidth * texHeight, GLColor::white);
4606
4607 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4608 whiteData.data());
4609 EXPECT_GL_NO_ERROR();
4610
4611 drawQuad(program, "position", 0.5f);
4612 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, angle::GLColor::white);
4613}
4614
Anders Leinof6cbe442019-04-18 15:32:07 +03004615// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4616// texture is output.
4617TEST_P(Texture2DIntegerTestES3, IntegerTextureNonZeroBaseLevel)
4618{
Yuly Novikovd2683452019-05-23 16:11:19 -04004619 // http://anglebug.com/3478
4620 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsDesktopOpenGL());
4621
Anders Leinof6cbe442019-04-18 15:32:07 +03004622 glActiveTexture(GL_TEXTURE0);
4623 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4624 int width = getWindowWidth();
4625 int height = getWindowHeight();
4626 GLColor color = GLColor::green;
4627 std::vector<GLColor> pixels(width * height, color);
4628 GLint baseLevel = 1;
4629 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
4630 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4631 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4632 glTexImage2D(GL_TEXTURE_2D, baseLevel, GL_RGBA8UI, width, height, 0, GL_RGBA_INTEGER,
4633 GL_UNSIGNED_BYTE, pixels.data());
4634
4635 setUpProgram();
4636 glUseProgram(mProgram);
4637 glUniform1i(mTexture2DUniformLocation, 0);
4638 drawQuad(mProgram, "position", 0.5f);
4639
4640 EXPECT_GL_NO_ERROR();
4641 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4642 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4643}
4644
Anders Leino60cc7512019-05-06 09:25:27 +03004645// Draw a quad with an integer cube texture with a non-zero base level, and test that the color of
4646// the texture is output.
4647TEST_P(TextureCubeIntegerTestES3, IntegerCubeTextureNonZeroBaseLevel)
4648{
4649 // All output checks returned black, rather than the texture color.
4650 ANGLE_SKIP_TEST_IF(IsOSX() && IsOpenGL());
4651
4652 glActiveTexture(GL_TEXTURE0);
4653
4654 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
4655 GLint baseLevel = 1;
4656 int width = getWindowWidth();
4657 int height = getWindowHeight();
4658 GLColor color = GLColor::green;
4659 std::vector<GLColor> pixels(width * height, color);
4660 for (GLenum faceIndex = 0; faceIndex < 6; faceIndex++)
4661 {
4662 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, baseLevel, GL_RGBA8UI, width,
4663 height, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
4664 EXPECT_GL_NO_ERROR();
4665 }
4666 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, baseLevel);
4667 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4668 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4669
4670 glUseProgram(mProgram);
4671 glUniform1i(mTextureCubeUniformLocation, 0);
4672 drawQuad(mProgram, "position", 0.5f);
4673
4674 EXPECT_GL_NO_ERROR();
4675 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4676 EXPECT_PIXEL_COLOR_EQ(width - 1, 0, color);
4677 EXPECT_PIXEL_COLOR_EQ(0, height - 1, color);
4678 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4679}
4680
Anders Leinoe4452442019-05-09 13:29:49 +03004681// This test sets up a cube map with four distincly colored MIP levels.
4682// The size of the texture and the geometry is chosen such that levels 1 or 2 should be chosen at
4683// the corners of the screen.
4684TEST_P(TextureCubeIntegerEdgeTestES3, IntegerCubeTextureCorner)
4685{
4686 glActiveTexture(GL_TEXTURE0);
4687
4688 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
4689 int width = getWindowWidth();
4690 int height = getWindowHeight();
4691 ASSERT_EQ(width, height);
4692 GLColor color[4] = {GLColor::white, GLColor::green, GLColor::blue, GLColor::red};
4693 for (GLint level = 0; level < 4; level++)
4694 {
4695 for (GLenum faceIndex = 0; faceIndex < 6; faceIndex++)
4696 {
4697 int levelWidth = (2 * width) >> level;
4698 int levelHeight = (2 * height) >> level;
4699 std::vector<GLColor> pixels(levelWidth * levelHeight, color[level]);
4700 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, level, GL_RGBA8UI, levelWidth,
4701 levelHeight, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
4702 EXPECT_GL_NO_ERROR();
4703 }
4704 }
4705 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4706 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4707 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 3);
4708
4709 glUseProgram(mProgram);
4710 glUniform1i(mTextureCubeUniformLocation, 0);
4711 drawQuad(mProgram, "position", 0.5f);
4712
4713 ASSERT_GL_NO_ERROR();
4714 // Check that we do not read from levels 0 or 3. Levels 1 and 2 are both acceptable.
4715 EXPECT_EQ(ReadColor(0, 0).R, 0);
4716 EXPECT_EQ(ReadColor(width - 1, 0).R, 0);
4717 EXPECT_EQ(ReadColor(0, height - 1).R, 0);
4718 EXPECT_EQ(ReadColor(width - 1, height - 1).R, 0);
4719}
4720
Anders Leino1b6aded2019-05-20 12:56:34 +03004721// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4722// texture is output.
4723TEST_P(Texture2DIntegerProjectiveOffsetTestES3, NonZeroBaseLevel)
4724{
Jamie Madill29ac2742019-05-28 15:53:00 -04004725 // Fails on AMD: http://crbug.com/967796
4726 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsD3D11());
4727
Anders Leino1b6aded2019-05-20 12:56:34 +03004728 glActiveTexture(GL_TEXTURE0);
4729 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4730 int width = getWindowWidth();
4731 int height = getWindowHeight();
4732 GLColor color = GLColor::green;
4733 std::vector<GLColor> pixels(width * height, color);
4734 GLint baseLevel = 1;
4735 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
4736 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4737 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4738 glTexImage2D(GL_TEXTURE_2D, baseLevel, GL_RGBA8UI, width, height, 0, GL_RGBA_INTEGER,
4739 GL_UNSIGNED_BYTE, pixels.data());
4740
4741 setUpProgram();
4742 glUseProgram(mProgram);
4743 glUniform1i(mTexture2DUniformLocation, 0);
4744 drawQuad(mProgram, "position", 0.5f);
4745
4746 EXPECT_GL_NO_ERROR();
4747 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4748 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4749}
4750
Anders Leino69d04932019-05-20 14:04:13 +03004751// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4752// texture is output.
4753TEST_P(Texture2DArrayIntegerTestES3, NonZeroBaseLevel)
4754{
4755 glActiveTexture(GL_TEXTURE0);
4756 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
4757 int width = getWindowWidth();
4758 int height = getWindowHeight();
4759 int depth = 2;
4760 GLColor color = GLColor::green;
4761 std::vector<GLColor> pixels(width * height * depth, color);
4762 GLint baseLevel = 1;
4763 glTexImage3D(GL_TEXTURE_2D_ARRAY, baseLevel, GL_RGBA8UI, width, height, depth, 0,
4764 GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
4765 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, baseLevel);
4766 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4767 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4768
4769 drawQuad(mProgram, "position", 0.5f);
4770
4771 EXPECT_GL_NO_ERROR();
4772 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4773 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4774}
4775
Jamie Madill50cf2be2018-06-15 09:46:57 -04004776// Use this to select which configurations (e.g. which renderer, which GLES major version) these
4777// tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -05004778ANGLE_INSTANTIATE_TEST(Texture2DTest,
4779 ES2_D3D9(),
4780 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004781 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05004782 ES2_OPENGLES(),
4783 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004784ANGLE_INSTANTIATE_TEST(TextureCubeTest,
4785 ES2_D3D9(),
4786 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004787 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004788 ES2_OPENGLES(),
4789 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004790ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
4791 ES2_D3D9(),
4792 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004793 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004794 ES2_OPENGLES(),
4795 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004796ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
4797 ES2_D3D9(),
4798 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004799 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004800 ES2_OPENGLES(),
4801 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004802ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
4803 ES2_D3D9(),
4804 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004805 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004806 ES2_OPENGLES(),
4807 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004808ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
4809 ES2_D3D9(),
4810 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004811 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004812 ES2_OPENGLES(),
4813 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004814ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02004815ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02004816ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4817ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
4818 ES3_D3D11(),
4819 ES3_OPENGL(),
4820 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004821ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
4822 ES3_D3D11(),
4823 ES3_OPENGL(),
4824 ES3_OPENGLES());
4825ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4826ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02004827ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02004828ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
4829 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004830 ES2_D3D9(),
4831 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004832 ES2_OPENGLES(),
4833 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004834ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
4835 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004836 ES2_D3D9(),
4837 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004838 ES2_OPENGLES(),
4839 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004840ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
4841 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004842 ES2_D3D9(),
4843 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004844 ES2_OPENGLES(),
4845 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004846ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
4847 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004848 ES2_D3D9(),
4849 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004850 ES2_OPENGLES(),
4851 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004852ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
4853 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004854 ES2_D3D9(),
4855 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004856 ES2_OPENGLES(),
4857 ES2_VULKAN());
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05004858ANGLE_INSTANTIATE_TEST(TextureAnisotropyTest,
4859 ES2_D3D11(),
4860 ES2_D3D9(),
4861 ES2_OPENGL(),
4862 ES2_OPENGLES(),
4863 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02004864ANGLE_INSTANTIATE_TEST(TextureBorderClampTest,
4865 ES2_D3D11(),
4866 ES2_D3D9(),
4867 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004868 ES2_OPENGLES(),
4869 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02004870ANGLE_INSTANTIATE_TEST(TextureBorderClampTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4871ANGLE_INSTANTIATE_TEST(TextureBorderClampIntegerTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Luc Ferronaf883622018-06-08 15:57:31 -04004872ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN());
Vincent Lang25ab4512016-05-13 18:13:59 +02004873ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03004874ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Anders Leinof6cbe442019-04-18 15:32:07 +03004875ANGLE_INSTANTIATE_TEST(Texture2DIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino60cc7512019-05-06 09:25:27 +03004876ANGLE_INSTANTIATE_TEST(TextureCubeIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leinoe4452442019-05-09 13:29:49 +03004877ANGLE_INSTANTIATE_TEST(TextureCubeIntegerEdgeTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino1b6aded2019-05-20 12:56:34 +03004878ANGLE_INSTANTIATE_TEST(Texture2DIntegerProjectiveOffsetTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino69d04932019-05-20 14:04:13 +03004879ANGLE_INSTANTIATE_TEST(Texture2DArrayIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Jamie Madillfa05f602015-05-07 13:47:11 -04004880
Jamie Madill7ffdda92016-09-08 13:26:51 -04004881} // anonymous namespace