blob: 6798dea5ad64615894c42f9745e31bf058104bd0 [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
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001299TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001300{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001301 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001302 EXPECT_GL_ERROR(GL_NO_ERROR);
1303
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001304 setUpProgram();
1305
Jamie Madill50cf2be2018-06-15 09:46:57 -04001306 const GLubyte *pixels[20] = {0};
Jamie Madillf67115c2014-04-22 13:14:05 -04001307 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1308 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001309
Jamie Madillb8149072019-04-30 16:14:44 -04001310 if (IsGLExtensionEnabled("GL_EXT_texture_storage"))
Geoff Langc51642b2016-11-14 16:18:26 -05001311 {
1312 // Create a 1-level immutable texture.
1313 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1314
1315 // Try calling sub image on the second level.
1316 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1317 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1318 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001319}
Geoff Langc41e42d2014-04-28 10:58:16 -04001320
John Bauman18319182016-09-28 14:22:27 -07001321// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1322TEST_P(Texture2DTest, QueryBinding)
1323{
1324 glBindTexture(GL_TEXTURE_2D, 0);
1325 EXPECT_GL_ERROR(GL_NO_ERROR);
1326
1327 GLint textureBinding;
1328 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1329 EXPECT_GL_NO_ERROR();
1330 EXPECT_EQ(0, textureBinding);
1331
1332 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
Jamie Madillb8149072019-04-30 16:14:44 -04001333 if (IsGLExtensionEnabled("GL_OES_EGL_image_external") ||
1334 IsGLExtensionEnabled("GL_NV_EGL_stream_consumer_external"))
John Bauman18319182016-09-28 14:22:27 -07001335 {
1336 EXPECT_GL_NO_ERROR();
1337 EXPECT_EQ(0, textureBinding);
1338 }
1339 else
1340 {
1341 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1342 }
1343}
1344
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001345TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001346{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001347 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001348 EXPECT_GL_ERROR(GL_NO_ERROR);
1349
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001350 setUpProgram();
1351
Geoff Langc41e42d2014-04-28 10:58:16 -04001352 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001353 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001354 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001355 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001356
Jamie Madill50cf2be2018-06-15 09:46:57 -04001357 const GLubyte *pixel[4] = {0};
Geoff Langc41e42d2014-04-28 10:58:16 -04001358
1359 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1360 EXPECT_GL_NO_ERROR();
1361
1362 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1363 EXPECT_GL_NO_ERROR();
1364
1365 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1366 EXPECT_GL_NO_ERROR();
1367}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001368
1369// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001370TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001371{
1372 glActiveTexture(GL_TEXTURE0);
1373 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1374 glActiveTexture(GL_TEXTURE1);
1375 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1376 EXPECT_GL_ERROR(GL_NO_ERROR);
1377
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001378 glUseProgram(mProgram);
1379 glUniform1i(mTexture2DUniformLocation, 0);
1380 glUniform1i(mTextureCubeUniformLocation, 1);
1381 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001382 EXPECT_GL_NO_ERROR();
1383}
Jamie Madill9aca0592014-10-06 16:26:59 -04001384
Olli Etuaho53a2da12016-01-11 15:43:32 +02001385// Test drawing with two texture types accessed from the same shader and check that the result of
1386// drawing is correct.
1387TEST_P(TextureCubeTest, CubeMapDraw)
1388{
1389 GLubyte texData[4];
1390 texData[0] = 0;
1391 texData[1] = 60;
1392 texData[2] = 0;
1393 texData[3] = 255;
1394
1395 glActiveTexture(GL_TEXTURE0);
1396 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1397 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1398
1399 glActiveTexture(GL_TEXTURE1);
1400 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1401 texData[1] = 120;
1402 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1403 texData);
1404 EXPECT_GL_ERROR(GL_NO_ERROR);
1405
1406 glUseProgram(mProgram);
1407 glUniform1i(mTexture2DUniformLocation, 0);
1408 glUniform1i(mTextureCubeUniformLocation, 1);
1409 drawQuad(mProgram, "position", 0.5f);
1410 EXPECT_GL_NO_ERROR();
1411
1412 int px = getWindowWidth() - 1;
1413 int py = 0;
1414 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1415}
1416
Olli Etuaho4644a202016-01-12 15:12:53 +02001417TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1418{
1419 glActiveTexture(GL_TEXTURE0);
1420 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1421 GLubyte texData[4];
1422 texData[0] = 0;
1423 texData[1] = 128;
1424 texData[2] = 0;
1425 texData[3] = 255;
1426 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1427 glUseProgram(mProgram);
1428 glUniform1i(mTexture2DUniformLocation, 0);
1429 drawQuad(mProgram, "position", 0.5f);
1430 EXPECT_GL_NO_ERROR();
1431
1432 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1433}
1434
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001435// Test drawing with two textures passed to the shader in a sampler array.
1436TEST_P(SamplerArrayTest, SamplerArrayDraw)
1437{
1438 testSamplerArrayDraw();
1439}
1440
1441// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1442// user-defined function in the shader.
1443TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1444{
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05001445 // TODO: Diagnose and fix. http://anglebug.com/2955
1446 ANGLE_SKIP_TEST_IF(IsVulkan() && IsAndroid());
1447
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001448 testSamplerArrayDraw();
1449}
1450
Jamie Madill9aca0592014-10-06 16:26:59 -04001451// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001452TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001453{
1454 int px = getWindowWidth() / 2;
1455 int py = getWindowHeight() / 2;
1456
1457 glActiveTexture(GL_TEXTURE0);
1458 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1459
Olli Etuahoa314b612016-03-10 16:43:00 +02001460 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001461
Olli Etuahoa314b612016-03-10 16:43:00 +02001462 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001463 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1464 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1465 glGenerateMipmap(GL_TEXTURE_2D);
1466
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001467 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001468 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001469 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1470 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001471 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001472 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001473
Olli Etuahoa314b612016-03-10 16:43:00 +02001474 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001475
Olli Etuahoa314b612016-03-10 16:43:00 +02001476 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1477 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001478 glGenerateMipmap(GL_TEXTURE_2D);
1479
Olli Etuahoa314b612016-03-10 16:43:00 +02001480 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001481
Olli Etuahoa314b612016-03-10 16:43:00 +02001482 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1483 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001484 glGenerateMipmap(GL_TEXTURE_2D);
1485
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001486 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001487
1488 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001489 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001490}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001491
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001492// Test creating a FBO with a cube map render target, to test an ANGLE bug
1493// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001494TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001495{
Michael Spangd8506c72019-01-29 15:35:09 -05001496 // http://anglebug.com/3145
1497 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
1498
Shahbaz Youssefi0c128e12019-03-25 23:50:14 -04001499 // http://anglebug.com/2822
1500 ANGLE_SKIP_TEST_IF(IsWindows() && IsIntel() && IsVulkan());
1501
Jamie Madill3f3b3582018-09-14 10:38:44 -04001502 GLFramebuffer fbo;
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001503 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1504
1505 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Jamie Madill50cf2be2018-06-15 09:46:57 -04001506 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1507 mTextureCube, 0);
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001508
Corentin Wallez322653b2015-06-17 18:33:56 +02001509 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001510 EXPECT_GL_NO_ERROR();
Jamie Madill3f3b3582018-09-14 10:38:44 -04001511
1512 // Test clearing the six mip faces individually.
1513 std::array<GLColor, 6> faceColors = {{GLColor::red, GLColor::green, GLColor::blue,
1514 GLColor::yellow, GLColor::cyan, GLColor::magenta}};
1515
1516 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1517 {
1518 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1519 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1520
1521 Vector4 clearColorF = faceColors[faceIndex].toNormalizedVector();
1522 glClearColor(clearColorF.x(), clearColorF.y(), clearColorF.z(), clearColorF.w());
1523 glClear(GL_COLOR_BUFFER_BIT);
1524
1525 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex]);
1526 }
1527
1528 // Iterate the faces again to make sure the colors haven't changed.
1529 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1530 {
1531 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1532 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1533 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex])
1534 << "face color " << faceIndex << " shouldn't change";
1535 }
1536}
1537
1538// Tests clearing a cube map with a scissor enabled.
1539TEST_P(TextureCubeTest, CubeMapFBOScissoredClear)
1540{
1541 // TODO(jie.a.chen): Diagnose and fix. http://anglebug.com/2822
1542 ANGLE_SKIP_TEST_IF(IsVulkan() && IsIntel() && IsWindows());
1543
Michael Spangd8506c72019-01-29 15:35:09 -05001544 // http://anglebug.com/3145
1545 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
1546
Jamie Madill3f3b3582018-09-14 10:38:44 -04001547 constexpr size_t kSize = 16;
1548
1549 GLFramebuffer fbo;
1550 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1551 glViewport(0, 0, kSize, kSize);
1552
1553 GLTexture texcube;
1554 glBindTexture(GL_TEXTURE_CUBE_MAP, texcube);
1555 for (GLenum face = 0; face < 6; face++)
1556 {
1557 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA,
1558 GL_UNSIGNED_BYTE, nullptr);
1559 }
1560 ASSERT_GL_NO_ERROR();
1561
1562 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1563 texcube, 0);
1564
1565 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1566 ASSERT_GL_NO_ERROR();
1567
1568 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1569 glClear(GL_COLOR_BUFFER_BIT);
1570 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1571
1572 glEnable(GL_SCISSOR_TEST);
1573 glScissor(kSize / 2, 0, kSize / 2, kSize);
1574 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
1575 glClear(GL_COLOR_BUFFER_BIT);
1576
1577 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1578 EXPECT_PIXEL_COLOR_EQ(kSize / 2 + 1, 0, GLColor::green);
1579
1580 ASSERT_GL_NO_ERROR();
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001581}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001582
Jamie Madill50cf2be2018-06-15 09:46:57 -04001583// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a
1584// default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001585TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001586{
Jamie Madillb8149072019-04-30 16:14:44 -04001587 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 &&
1588 !IsGLExtensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -04001589
Jamie Madill50cf2be2018-06-15 09:46:57 -04001590 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001591 int height = getWindowHeight();
1592
1593 GLuint tex2D;
1594 glGenTextures(1, &tex2D);
1595 glActiveTexture(GL_TEXTURE0);
1596 glBindTexture(GL_TEXTURE_2D, tex2D);
1597
1598 // Fill with red
1599 std::vector<GLubyte> pixels(3 * 16 * 16);
1600 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1601 {
1602 pixels[pixelId * 3 + 0] = 255;
1603 pixels[pixelId * 3 + 1] = 0;
1604 pixels[pixelId * 3 + 2] = 0;
1605 }
1606
1607 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001608 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1609 // 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 -04001610 if (getClientMajorVersion() >= 3)
1611 {
1612 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1613 }
1614 else
1615 {
1616 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1617 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001618
1619 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1620 // glTexSubImage2D should take into account that the image is dirty.
1621 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1622 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1623 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1624
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001625 setUpProgram();
1626
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001627 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001628 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001629 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001630 glDeleteTextures(1, &tex2D);
1631 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001632 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001633
1634 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001635 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1636 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001637}
1638
Jamie Madill50cf2be2018-06-15 09:46:57 -04001639// Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has
1640// initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001641TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001642{
Jamie Madillb8149072019-04-30 16:14:44 -04001643 if (IsGLExtensionEnabled("NV_pixel_buffer_object"))
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001644 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04001645 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001646 int height = getWindowHeight();
1647
1648 GLuint tex2D;
1649 glGenTextures(1, &tex2D);
1650 glActiveTexture(GL_TEXTURE0);
1651 glBindTexture(GL_TEXTURE_2D, tex2D);
1652
1653 // Fill with red
1654 std::vector<GLubyte> pixels(3 * 16 * 16);
1655 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1656 {
1657 pixels[pixelId * 3 + 0] = 255;
1658 pixels[pixelId * 3 + 1] = 0;
1659 pixels[pixelId * 3 + 2] = 0;
1660 }
1661
1662 // Read 16x16 region from red backbuffer to PBO
1663 GLuint pbo;
1664 glGenBuffers(1, &pbo);
1665 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1666 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1667
1668 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001669 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1670 // 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 +00001671 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1672
1673 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1674 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001675 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 +00001676 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1677 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1678
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001679 setUpProgram();
1680
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001681 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001682 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001683 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001684 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001685 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001686 EXPECT_GL_NO_ERROR();
1687 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1688 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1689 }
1690}
Jamie Madillbc393df2015-01-29 13:46:07 -05001691
1692// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001693TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001694{
1695 testFloatCopySubImage(1, 1);
1696}
1697
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001698TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001699{
1700 testFloatCopySubImage(2, 1);
1701}
1702
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001703TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001704{
1705 testFloatCopySubImage(2, 2);
1706}
1707
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001708TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001709{
1710 testFloatCopySubImage(3, 1);
1711}
1712
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001713TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001714{
1715 testFloatCopySubImage(3, 2);
1716}
1717
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001718TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001719{
Yunchao He9550c602018-02-13 14:47:05 +08001720 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1721 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001722
Yunchao He9550c602018-02-13 14:47:05 +08001723 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1724 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001725
Jamie Madillbc393df2015-01-29 13:46:07 -05001726 testFloatCopySubImage(3, 3);
1727}
1728
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001729TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001730{
1731 testFloatCopySubImage(4, 1);
1732}
1733
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001734TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001735{
1736 testFloatCopySubImage(4, 2);
1737}
1738
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001739TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001740{
Yunchao He9550c602018-02-13 14:47:05 +08001741 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1742 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001743
Jamie Madillbc393df2015-01-29 13:46:07 -05001744 testFloatCopySubImage(4, 3);
1745}
1746
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001747TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001748{
Luc Ferronf786b702018-07-10 11:01:43 -04001749 // TODO(lucferron): This test fails only on linux and intel.
1750 // http://anglebug.com/2726
1751 ANGLE_SKIP_TEST_IF(IsVulkan() && IsLinux() && IsIntel());
1752
Yunchao He9550c602018-02-13 14:47:05 +08001753 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1754 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001755
Jamie Madillbc393df2015-01-29 13:46:07 -05001756 testFloatCopySubImage(4, 4);
1757}
Austin Kinross07285142015-03-26 11:36:16 -07001758
Jamie Madill50cf2be2018-06-15 09:46:57 -04001759// Port of
1760// https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1761// Run against GL_ALPHA/UNSIGNED_BYTE format, to ensure that D3D11 Feature Level 9_3 correctly
1762// handles GL_ALPHA
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001763TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001764{
1765 const int npotTexSize = 5;
Jamie Madill50cf2be2018-06-15 09:46:57 -04001766 const int potTexSize = 4; // Should be less than npotTexSize
Austin Kinross07285142015-03-26 11:36:16 -07001767 GLuint tex2D;
1768
Jamie Madillb8149072019-04-30 16:14:44 -04001769 if (IsGLExtensionEnabled("GL_OES_texture_npot"))
Austin Kinross07285142015-03-26 11:36:16 -07001770 {
1771 // This test isn't applicable if texture_npot is enabled
1772 return;
1773 }
1774
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001775 setUpProgram();
1776
Austin Kinross07285142015-03-26 11:36:16 -07001777 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1778
Austin Kinross5faa15b2016-01-11 13:32:48 -08001779 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1780 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1781
Austin Kinross07285142015-03-26 11:36:16 -07001782 glActiveTexture(GL_TEXTURE0);
1783 glGenTextures(1, &tex2D);
1784 glBindTexture(GL_TEXTURE_2D, tex2D);
1785
Till Rathmannc1551dc2018-08-15 17:04:49 +02001786 const std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize, 64);
Austin Kinross07285142015-03-26 11:36:16 -07001787
1788 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1789 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1790
1791 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
Jamie Madill50cf2be2018-06-15 09:46:57 -04001792 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1793 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001794 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1795
1796 // Check that an NPOT texture on level 0 succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001797 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1798 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001799 EXPECT_GL_NO_ERROR();
1800
1801 // Check that generateMipmap fails on NPOT
1802 glGenerateMipmap(GL_TEXTURE_2D);
1803 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1804
1805 // Check that nothing is drawn if filtering is not correct for NPOT
1806 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1807 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1808 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1809 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1810 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001811 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001812 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1813
1814 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1815 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1816 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1817 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1818 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001819 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001820 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1821
1822 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1823 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1824 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001825 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001826 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1827
1828 // Check that glTexImage2D for POT texture succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001829 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE,
1830 pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001831 EXPECT_GL_NO_ERROR();
1832
1833 // Check that generateMipmap for an POT texture succeeds
1834 glGenerateMipmap(GL_TEXTURE_2D);
1835 EXPECT_GL_NO_ERROR();
1836
1837 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1838 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1839 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
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, 64);
1845 EXPECT_GL_NO_ERROR();
1846}
Jamie Madillfa05f602015-05-07 13:47:11 -04001847
Austin Kinross08528e12015-10-07 16:24:40 -07001848// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1849// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001850TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001851{
1852 glActiveTexture(GL_TEXTURE0);
1853 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1854
1855 // Create an 8x8 (i.e. power-of-two) texture.
1856 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1857 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1858 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1859 glGenerateMipmap(GL_TEXTURE_2D);
1860
1861 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1862 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001863 std::array<GLColor, 3 * 3> data;
1864 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001865
1866 EXPECT_GL_NO_ERROR();
1867}
1868
Geoff Lang3702d8c2019-04-08 13:44:06 -04001869// Regression test for http://crbug.com/949985 to make sure dirty bits are propagated up from
1870// TextureImpl and the texture is synced before being used in a draw call.
1871TEST_P(Texture2DTestES3, TextureImplPropogatesDirtyBits)
1872{
1873 ANGLE_SKIP_TEST_IF(IsIntel() && IsOpenGL());
Yuly Novikove6b23e42019-04-10 17:19:15 -04001874 // Flaky hangs on Win10 AMD RX 550 GL. http://anglebug.com/3371
1875 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsOpenGL());
Geoff Lang3702d8c2019-04-08 13:44:06 -04001876
1877 // The workaround in the GL backend required to trigger this bug generates driver warning
1878 // messages.
1879 ScopedIgnorePlatformMessages ignoreMessages;
1880
1881 setUpProgram();
1882 glUseProgram(mProgram);
1883 glActiveTexture(GL_TEXTURE0 + mTexture2DUniformLocation);
1884
1885 GLTexture dest;
1886 glBindTexture(GL_TEXTURE_2D, dest);
1887
1888 GLTexture source;
1889 glBindTexture(GL_TEXTURE_2D, source);
1890
1891 // Put data in mip 0 and 1
1892 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1893 GLColor::red.data());
1894 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1895 GLColor::green.data());
1896
1897 // Disable mipmapping so source is complete
1898 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1899 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1900
1901 // Force the dirty bits to be synchronized in source
1902 drawQuad(mProgram, "position", 1.0f);
1903
1904 // Copy from mip 1 of the source. In the GL backend this internally sets the base level to mip
1905 // 1 and sets a dirty bit.
1906 glCopyTextureCHROMIUM(source, 1, GL_TEXTURE_2D, dest, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_FALSE,
1907 GL_FALSE, GL_FALSE);
1908
1909 // Draw again, assertions are generated if the texture has internal dirty bits at draw time
1910 drawQuad(mProgram, "position", 1.0f);
1911}
1912
Geoff Lang6f691fb2019-04-25 11:01:52 -04001913// This test case changes the base level of a texture that's attached to a framebuffer, clears every
1914// level to green, and then samples the texture when rendering. Test is taken from
1915// https://www.khronos.org/registry/webgl/sdk/tests/conformance2/rendering/framebuffer-texture-changing-base-level.html
1916TEST_P(Texture2DTestES3, FramebufferTextureChangingBaselevel)
1917{
1918 // TODO(geofflang): Investigate on D3D11. http://anglebug.com/2291
1919 ANGLE_SKIP_TEST_IF(IsD3D11());
1920
1921 setUpProgram();
1922
1923 constexpr GLint width = 8;
1924 constexpr GLint height = 4;
1925
1926 GLTexture texture;
1927 glBindTexture(GL_TEXTURE_2D, texture);
1928 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1929 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1930 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1931 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1932
1933 // Create all mipmap levels for the texture from level 0 to the 1x1 pixel level.
1934 GLint level = 0;
1935 GLint levelW = width;
1936 GLint levelH = height;
1937 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, levelW, levelH, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1938 nullptr);
1939 while (levelW > 1 || levelH > 1)
1940 {
1941 ++level;
1942 levelW = static_cast<GLint>(std::max(1.0, std::floor(width / std::pow(2, level))));
1943 levelH = static_cast<GLint>(std::max(1.0, std::floor(height / std::pow(2, level))));
1944 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, levelW, levelH, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1945 nullptr);
1946 }
1947
1948 // Clear each level of the texture using an FBO. Change the base level to match the level used
1949 // for the FBO on each iteration.
1950 GLFramebuffer fbo;
1951 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1952 level = 0;
1953 levelW = width;
1954 levelH = height;
1955 while (levelW > 1 || levelH > 1)
1956 {
1957 levelW = static_cast<GLint>(std::floor(width / std::pow(2, level)));
1958 levelH = static_cast<GLint>(std::floor(height / std::pow(2, level)));
1959
1960 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, level);
1961 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, level);
1962
1963 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1964 EXPECT_GL_NO_ERROR();
1965
1966 glClearColor(0, 1, 0, 1);
1967 glClear(GL_COLOR_BUFFER_BIT);
1968
1969 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1970
1971 ++level;
1972 }
1973
1974 glBindFramebuffer(GL_FRAMEBUFFER, 0);
1975 glViewport(0, 0, 16, 16);
1976 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
1977
1978 drawQuad(mProgram, "position", 0.5f);
1979
1980 EXPECT_GL_NO_ERROR();
1981 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1982}
1983
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001984// Test to check that texture completeness is determined correctly when the texture base level is
1985// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1986TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1987{
1988 glActiveTexture(GL_TEXTURE0);
1989 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001990
1991 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1992 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1993 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1994 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1995 texDataGreen.data());
1996 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1997 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001998 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1999 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2000 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2001
2002 EXPECT_GL_NO_ERROR();
2003
2004 drawQuad(mProgram, "position", 0.5f);
2005
Olli Etuahoa314b612016-03-10 16:43:00 +02002006 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2007}
2008
2009// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2010// have images defined.
2011TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
2012{
Yunchao He9550c602018-02-13 14:47:05 +08002013 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
2014 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
2015
Olli Etuahoa314b612016-03-10 16:43:00 +02002016 glActiveTexture(GL_TEXTURE0);
2017 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2018 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2019 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2020 texDataGreen.data());
2021 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2022 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2023 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2024 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2025
2026 EXPECT_GL_NO_ERROR();
2027
2028 drawQuad(mProgram, "position", 0.5f);
2029
2030 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2031}
2032
Olli Etuahoe8528d82016-05-16 17:50:52 +03002033// Test that drawing works correctly when level 0 is undefined and base level is 1.
2034TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
2035{
Yunchao He9550c602018-02-13 14:47:05 +08002036 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
2037 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
2038
Olli Etuahoe8528d82016-05-16 17:50:52 +03002039 glActiveTexture(GL_TEXTURE0);
2040 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2041 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2042 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2043 texDataGreen.data());
2044 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2045 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2046 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2047 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2048
2049 EXPECT_GL_NO_ERROR();
2050
2051 // Texture is incomplete.
2052 drawQuad(mProgram, "position", 0.5f);
2053 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2054
2055 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2056 texDataGreen.data());
2057
2058 // Texture is now complete.
2059 drawQuad(mProgram, "position", 0.5f);
2060 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2061}
2062
Olli Etuahoa314b612016-03-10 16:43:00 +02002063// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2064// dimensions that don't fit the images inside the range.
2065// GLES 3.0.4 section 3.8.13 Texture completeness
2066TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2067{
Olli Etuahoa314b612016-03-10 16:43:00 +02002068 glActiveTexture(GL_TEXTURE0);
2069 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2070 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
2071 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2072 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
2073
2074 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2075 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2076
2077 // Two levels that are initially unused.
2078 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
2079 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2080 texDataCyan.data());
2081
2082 // One level that is used - only this level should affect completeness.
2083 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2084 texDataGreen.data());
2085
2086 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2087 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2088
2089 EXPECT_GL_NO_ERROR();
2090
2091 drawQuad(mProgram, "position", 0.5f);
2092
2093 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2094
Yunchao He2f23f352018-02-11 22:11:37 +08002095 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02002096
2097 // Switch the level that is being used to the cyan level 2.
2098 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2099 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2100
2101 EXPECT_GL_NO_ERROR();
2102
2103 drawQuad(mProgram, "position", 0.5f);
2104
2105 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2106}
2107
2108// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2109// have images defined.
2110TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
2111{
Olli Etuahoa314b612016-03-10 16:43:00 +02002112 glActiveTexture(GL_TEXTURE0);
2113 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2114 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2115 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2116 texDataGreen.data());
2117 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2118 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2119 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
2120 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2121
2122 EXPECT_GL_NO_ERROR();
2123
2124 drawQuad(mProgram, "position", 0.5f);
2125
2126 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2127}
2128
2129// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2130// dimensions that don't fit the images inside the range.
2131// GLES 3.0.4 section 3.8.13 Texture completeness
2132TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2133{
Olli Etuahoa314b612016-03-10 16:43:00 +02002134 glActiveTexture(GL_TEXTURE0);
2135 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2136 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2137 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2138 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2139
2140 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2141 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2142
2143 // Two levels that are initially unused.
2144 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2145 texDataRed.data());
2146 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2147 texDataCyan.data());
2148
2149 // One level that is used - only this level should affect completeness.
2150 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2151 texDataGreen.data());
2152
2153 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
2154 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2155
2156 EXPECT_GL_NO_ERROR();
2157
2158 drawQuad(mProgram, "position", 0.5f);
2159
2160 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2161
Yunchao He2f23f352018-02-11 22:11:37 +08002162 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02002163
2164 // Switch the level that is being used to the cyan level 2.
2165 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
2166 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
2167
2168 EXPECT_GL_NO_ERROR();
2169
2170 drawQuad(mProgram, "position", 0.5f);
2171
2172 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2173}
2174
2175// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2176// have images defined.
2177TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
2178{
Olli Etuahoa314b612016-03-10 16:43:00 +02002179 glActiveTexture(GL_TEXTURE0);
2180 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
2181 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2182 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2183 texDataGreen.data());
2184 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2185 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2186 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2187 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2188
2189 EXPECT_GL_NO_ERROR();
2190
2191 drawQuad(mProgram, "position", 0.5f);
2192
2193 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2194}
2195
2196// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2197// dimensions that don't fit the images inside the range.
2198// GLES 3.0.4 section 3.8.13 Texture completeness
2199TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2200{
Olli Etuahoa314b612016-03-10 16:43:00 +02002201 glActiveTexture(GL_TEXTURE0);
2202 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
2203 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2204 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2205 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2206
2207 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2208 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2209
2210 // Two levels that are initially unused.
2211 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2212 texDataRed.data());
2213 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2214 texDataCyan.data());
2215
2216 // One level that is used - only this level should affect completeness.
2217 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2218 texDataGreen.data());
2219
2220 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2221 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2222
2223 EXPECT_GL_NO_ERROR();
2224
2225 drawQuad(mProgram, "position", 0.5f);
2226
2227 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2228
Yunchao He2f23f352018-02-11 22:11:37 +08002229 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
2230
Yunchao He9550c602018-02-13 14:47:05 +08002231 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
2232 // level was changed.
2233 ANGLE_SKIP_TEST_IF(IsNVIDIA() && (IsOpenGL() || IsOpenGLES()));
Olli Etuahoa314b612016-03-10 16:43:00 +02002234
2235 // Switch the level that is being used to the cyan level 2.
2236 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2237 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2238
2239 EXPECT_GL_NO_ERROR();
2240
2241 drawQuad(mProgram, "position", 0.5f);
2242
2243 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2244}
2245
2246// Test that texture completeness is updated if texture max level changes.
2247// GLES 3.0.4 section 3.8.13 Texture completeness
2248TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2249{
Olli Etuahoa314b612016-03-10 16:43:00 +02002250 glActiveTexture(GL_TEXTURE0);
2251 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2252 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2253
2254 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2255 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2256
2257 // A level that is initially unused.
2258 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2259 texDataGreen.data());
2260
2261 // One level that is initially used - only this level should affect completeness.
2262 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2263 texDataGreen.data());
2264
2265 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2266 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2267
2268 EXPECT_GL_NO_ERROR();
2269
2270 drawQuad(mProgram, "position", 0.5f);
2271
2272 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2273
2274 // Switch the max level to level 1. The levels within the used range now have inconsistent
2275 // dimensions and the texture should be incomplete.
2276 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2277
2278 EXPECT_GL_NO_ERROR();
2279
2280 drawQuad(mProgram, "position", 0.5f);
2281
2282 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2283}
2284
2285// Test that 3D texture completeness is updated if texture max level changes.
2286// GLES 3.0.4 section 3.8.13 Texture completeness
2287TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2288{
Olli Etuahoa314b612016-03-10 16:43:00 +02002289 glActiveTexture(GL_TEXTURE0);
2290 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2291 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2292
2293 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2294 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2295
2296 // A level that is initially unused.
2297 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2298 texDataGreen.data());
2299
2300 // One level that is initially used - only this level should affect completeness.
2301 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2302 texDataGreen.data());
2303
2304 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2305 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2306
2307 EXPECT_GL_NO_ERROR();
2308
2309 drawQuad(mProgram, "position", 0.5f);
2310
2311 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2312
2313 // Switch the max level to level 1. The levels within the used range now have inconsistent
2314 // dimensions and the texture should be incomplete.
2315 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2316
2317 EXPECT_GL_NO_ERROR();
2318
2319 drawQuad(mProgram, "position", 0.5f);
2320
2321 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2322}
2323
2324// Test that texture completeness is updated if texture base level changes.
2325// GLES 3.0.4 section 3.8.13 Texture completeness
2326TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2327{
Olli Etuahoa314b612016-03-10 16:43:00 +02002328 glActiveTexture(GL_TEXTURE0);
2329 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2330 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2331
2332 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2333 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2334
2335 // Two levels that are initially unused.
2336 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2337 texDataGreen.data());
2338 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2339 texDataGreen.data());
2340
2341 // One level that is initially used - only this level should affect completeness.
2342 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2343 texDataGreen.data());
2344
2345 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2346 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2347
2348 EXPECT_GL_NO_ERROR();
2349
2350 drawQuad(mProgram, "position", 0.5f);
2351
2352 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2353
2354 // Switch the base level to level 1. The levels within the used range now have inconsistent
2355 // dimensions and the texture should be incomplete.
2356 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2357
2358 EXPECT_GL_NO_ERROR();
2359
2360 drawQuad(mProgram, "position", 0.5f);
2361
2362 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2363}
2364
2365// Test that texture is not complete if base level is greater than max level.
2366// GLES 3.0.4 section 3.8.13 Texture completeness
2367TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2368{
Olli Etuahoa314b612016-03-10 16:43:00 +02002369 glActiveTexture(GL_TEXTURE0);
2370 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2371
2372 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2373 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2374
2375 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2376
2377 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2378 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2379
2380 EXPECT_GL_NO_ERROR();
2381
2382 drawQuad(mProgram, "position", 0.5f);
2383
2384 // Texture should be incomplete.
2385 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2386}
2387
2388// Test that immutable texture base level and max level are clamped.
2389// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2390TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2391{
Olli Etuahoa314b612016-03-10 16:43:00 +02002392 glActiveTexture(GL_TEXTURE0);
2393 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2394
2395 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2396 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2397
2398 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2399
2400 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2401
2402 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2403 // should be clamped to [base_level, levels - 1].
2404 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2405 // In the case of this test, those rules make the effective base level and max level 0.
2406 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2407 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2408
2409 EXPECT_GL_NO_ERROR();
2410
2411 drawQuad(mProgram, "position", 0.5f);
2412
2413 // Texture should be complete.
2414 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2415}
2416
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002417// Test that changing base level works when it affects the format of the texture.
2418TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2419{
Yunchao He9550c602018-02-13 14:47:05 +08002420 // Observed rendering corruption on NVIDIA OpenGL.
2421 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL());
2422
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002423 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002424
2425 // Observed incorrect rendering on AMD OpenGL.
2426 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002427
2428 glActiveTexture(GL_TEXTURE0);
2429 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2430 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2431 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2432
2433 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2434 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2435
2436 // RGBA8 level that's initially unused.
2437 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2438 texDataCyan.data());
2439
2440 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2441 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2442
2443 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2444 // format. It reads green channel data from the green and alpha channels of texDataGreen
2445 // (this is a bit hacky but works).
2446 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2447
2448 EXPECT_GL_NO_ERROR();
2449
2450 drawQuad(mProgram, "position", 0.5f);
2451
2452 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2453
2454 // Switch the texture to use the cyan level 0 with the RGBA format.
2455 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2456 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2457
2458 EXPECT_GL_NO_ERROR();
2459
2460 drawQuad(mProgram, "position", 0.5f);
2461
2462 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2463}
2464
Olli Etuahoa314b612016-03-10 16:43:00 +02002465// Test that setting a texture image works when base level is out of range.
2466TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2467{
2468 glActiveTexture(GL_TEXTURE0);
2469 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2470
2471 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2472 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2473
2474 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2475 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2476
2477 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2478
2479 EXPECT_GL_NO_ERROR();
2480
2481 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2482
2483 drawQuad(mProgram, "position", 0.5f);
2484
2485 // Texture should be complete.
2486 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002487}
2488
Jamie Madill50cf2be2018-06-15 09:46:57 -04002489// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG
2490// RBA->RGBA8, with 1.0 in the alpha channel. This test covers a bug where redefining array textures
2491// with these formats does not work as expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002492TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002493{
2494 std::vector<GLubyte> pixelData;
2495 for (size_t count = 0; count < 5000; count++)
2496 {
2497 pixelData.push_back(0u);
2498 pixelData.push_back(255u);
2499 pixelData.push_back(0u);
2500 }
2501
2502 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002503 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002504 glUniform1i(mTextureArrayLocation, 0);
2505
2506 // The first draw worked correctly.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002507 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2508 &pixelData[0]);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002509
2510 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2511 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2512 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2513 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002514 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002515 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002516
2517 // The dimension of the respecification must match the original exactly to trigger the bug.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002518 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2519 &pixelData[0]);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002520 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002521 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002522
2523 ASSERT_GL_NO_ERROR();
2524}
2525
Olli Etuaho1a679902016-01-14 12:21:47 +02002526// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2527// This test is needed especially to confirm that sampler registers get assigned correctly on
2528// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2529TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2530{
2531 glActiveTexture(GL_TEXTURE0);
2532 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2533 GLubyte texData[4];
2534 texData[0] = 0;
2535 texData[1] = 60;
2536 texData[2] = 0;
2537 texData[3] = 255;
2538 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2539
2540 glActiveTexture(GL_TEXTURE1);
2541 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2542 GLfloat depthTexData[1];
2543 depthTexData[0] = 0.5f;
2544 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2545 depthTexData);
2546
2547 glUseProgram(mProgram);
2548 glUniform1f(mDepthRefUniformLocation, 0.3f);
2549 glUniform1i(mTexture3DUniformLocation, 0);
2550 glUniform1i(mTextureShadowUniformLocation, 1);
2551
2552 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2553 drawQuad(mProgram, "position", 0.5f);
2554 EXPECT_GL_NO_ERROR();
2555 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2556 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2557
2558 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2559 drawQuad(mProgram, "position", 0.5f);
2560 EXPECT_GL_NO_ERROR();
2561 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2562 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2563}
2564
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002565// Test multiple different sampler types in the same shader.
2566// This test makes sure that even if sampler / texture registers get grouped together based on type
2567// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2568// still has the right register index information for each ESSL sampler.
2569// The tested ESSL samplers have the following types in D3D11 HLSL:
2570// sampler2D: Texture2D + SamplerState
2571// samplerCube: TextureCube + SamplerState
2572// sampler2DShadow: Texture2D + SamplerComparisonState
2573// samplerCubeShadow: TextureCube + SamplerComparisonState
2574TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2575{
2576 glActiveTexture(GL_TEXTURE0);
2577 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2578 GLubyte texData[4];
2579 texData[0] = 0;
2580 texData[1] = 0;
2581 texData[2] = 120;
2582 texData[3] = 255;
2583 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2584
2585 glActiveTexture(GL_TEXTURE1);
2586 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2587 texData[0] = 0;
2588 texData[1] = 90;
2589 texData[2] = 0;
2590 texData[3] = 255;
2591 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2592 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2593 texData);
2594
2595 glActiveTexture(GL_TEXTURE2);
2596 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2597 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2598 GLfloat depthTexData[1];
2599 depthTexData[0] = 0.5f;
2600 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2601 depthTexData);
2602
2603 glActiveTexture(GL_TEXTURE3);
2604 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2605 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2606 depthTexData[0] = 0.2f;
2607 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2608 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2609 depthTexData);
2610
2611 EXPECT_GL_NO_ERROR();
2612
2613 glUseProgram(mProgram);
2614 glUniform1f(mDepthRefUniformLocation, 0.3f);
2615 glUniform1i(mTexture2DUniformLocation, 0);
2616 glUniform1i(mTextureCubeUniformLocation, 1);
2617 glUniform1i(mTexture2DShadowUniformLocation, 2);
2618 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2619
2620 drawQuad(mProgram, "position", 0.5f);
2621 EXPECT_GL_NO_ERROR();
2622 // The shader writes:
2623 // <texture 2d color> +
2624 // <cube map color> +
2625 // 0.25 * <comparison result (1.0)> +
2626 // 0.125 * <comparison result (0.0)>
2627 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2628}
2629
Olli Etuahobce743a2016-01-15 17:18:28 +02002630// Test different base levels on textures accessed through the same sampler array.
2631// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2632TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2633{
Yunchao He9550c602018-02-13 14:47:05 +08002634 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2635
Olli Etuahobce743a2016-01-15 17:18:28 +02002636 glActiveTexture(GL_TEXTURE0);
2637 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2638 GLsizei size = 64;
2639 for (GLint level = 0; level < 7; ++level)
2640 {
2641 ASSERT_LT(0, size);
2642 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2643 nullptr);
2644 size = size / 2;
2645 }
2646 ASSERT_EQ(0, size);
2647 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2648
2649 glActiveTexture(GL_TEXTURE1);
2650 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2651 size = 128;
2652 for (GLint level = 0; level < 8; ++level)
2653 {
2654 ASSERT_LT(0, size);
2655 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2656 nullptr);
2657 size = size / 2;
2658 }
2659 ASSERT_EQ(0, size);
2660 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2661 EXPECT_GL_NO_ERROR();
2662
2663 glUseProgram(mProgram);
2664 glUniform1i(mTexture0Location, 0);
2665 glUniform1i(mTexture1Location, 1);
2666
Olli Etuaho5804dc82018-04-13 14:11:46 +03002667 drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
Olli Etuahobce743a2016-01-15 17:18:28 +02002668 EXPECT_GL_NO_ERROR();
2669 // Red channel: width of level 1 of texture A: 32.
2670 // Green channel: width of level 3 of texture B: 16.
2671 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2672}
2673
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002674// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2675// ES 3.0.4 table 3.24
2676TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2677{
2678 glActiveTexture(GL_TEXTURE0);
2679 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2680 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2681 EXPECT_GL_NO_ERROR();
2682
2683 drawQuad(mProgram, "position", 0.5f);
2684
2685 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2686}
2687
2688// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2689// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002690TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002691{
Luc Ferron5164b792018-03-06 09:10:12 -05002692 setUpProgram();
2693
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002694 glActiveTexture(GL_TEXTURE0);
2695 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2696 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2697 EXPECT_GL_NO_ERROR();
2698
2699 drawQuad(mProgram, "position", 0.5f);
2700
2701 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2702}
2703
Luc Ferron5164b792018-03-06 09:10:12 -05002704// Validate that every component of the pixel will be equal to the luminance value we've set
2705// and that the alpha channel will be 1 (or 255 to be exact).
2706TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2707{
2708 setUpProgram();
2709
2710 glActiveTexture(GL_TEXTURE0);
2711 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2712 uint8_t pixel = 50;
2713 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2714 EXPECT_GL_NO_ERROR();
2715
2716 drawQuad(mProgram, "position", 0.5f);
2717
2718 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2719}
2720
2721// Validate that every component of the pixel will be equal to the luminance value we've set
2722// and that the alpha channel will be the second component.
2723TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2724{
2725 setUpProgram();
2726
2727 glActiveTexture(GL_TEXTURE0);
2728 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2729 uint8_t pixel[] = {50, 25};
2730 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2731 GL_UNSIGNED_BYTE, pixel);
2732 EXPECT_GL_NO_ERROR();
2733
2734 drawQuad(mProgram, "position", 0.5f);
2735
2736 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2737}
2738
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002739// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2740// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002741TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002742{
Jamie Madillb8149072019-04-30 16:14:44 -04002743 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002744 ANGLE_SKIP_TEST_IF(IsD3D9());
2745 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002746
2747 setUpProgram();
2748
Luc Ferrond8c632c2018-04-10 12:31:44 -04002749 glActiveTexture(GL_TEXTURE0);
2750 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2751 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2752 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002753
Luc Ferrond8c632c2018-04-10 12:31:44 -04002754 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002755
Luc Ferrond8c632c2018-04-10 12:31:44 -04002756 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002757}
2758
2759// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2760// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002761TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002762{
Jamie Madillb8149072019-04-30 16:14:44 -04002763 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002764 ANGLE_SKIP_TEST_IF(IsD3D9());
2765 ANGLE_SKIP_TEST_IF(IsVulkan());
2766 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES());
2767 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2768 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002769
Luc Ferrond8c632c2018-04-10 12:31:44 -04002770 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002771
Luc Ferrond8c632c2018-04-10 12:31:44 -04002772 glActiveTexture(GL_TEXTURE0);
2773 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2774 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2775 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002776
Luc Ferrond8c632c2018-04-10 12:31:44 -04002777 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002778
Luc Ferrond8c632c2018-04-10 12:31:44 -04002779 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002780}
2781
2782// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2783// ES 3.0.4 table 3.24
2784TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2785{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002786 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2787
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002788 glActiveTexture(GL_TEXTURE0);
2789 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2790 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2791 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2792 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2793 EXPECT_GL_NO_ERROR();
2794
2795 drawQuad(mProgram, "position", 0.5f);
2796
2797 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2798}
2799
2800// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2801// ES 3.0.4 table 3.24
2802TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2803{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002804 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2805
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002806 glActiveTexture(GL_TEXTURE0);
2807 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2808
2809 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2810 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2811 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2812 EXPECT_GL_NO_ERROR();
2813
2814 drawQuad(mProgram, "position", 0.5f);
2815
2816 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2817}
2818
2819// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2820// ES 3.0.4 table 3.24
2821TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2822{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002823 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2824
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002825 glActiveTexture(GL_TEXTURE0);
2826 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2827 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2828 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2829 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2830 EXPECT_GL_NO_ERROR();
2831
2832 drawQuad(mProgram, "position", 0.5f);
2833
2834 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2835}
2836
2837// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2838// ES 3.0.4 table 3.24
2839TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2840{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002841 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2842
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002843 glActiveTexture(GL_TEXTURE0);
2844 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2845 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2846 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2847 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2848 EXPECT_GL_NO_ERROR();
2849
2850 drawQuad(mProgram, "position", 0.5f);
2851
2852 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2853}
2854
2855// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2856// ES 3.0.4 table 3.24
2857TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2858{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002859 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2860
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002861 glActiveTexture(GL_TEXTURE0);
2862 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2863 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2864 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2865 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2866 EXPECT_GL_NO_ERROR();
2867
2868 drawQuad(mProgram, "position", 0.5f);
2869
2870 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2871}
2872
2873// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2874// ES 3.0.4 table 3.24
2875TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2876{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002877 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2878
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002879 glActiveTexture(GL_TEXTURE0);
2880 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2881 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2882 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2883 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2884 EXPECT_GL_NO_ERROR();
2885
2886 drawQuad(mProgram, "position", 0.5f);
2887
2888 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2889}
2890
2891// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2892// ES 3.0.4 table 3.24
2893TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2894{
2895 glActiveTexture(GL_TEXTURE0);
2896 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2897 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
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(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2908{
2909 glActiveTexture(GL_TEXTURE0);
2910 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2911 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2912 nullptr);
2913 EXPECT_GL_NO_ERROR();
2914
2915 drawQuad(mProgram, "position", 0.5f);
2916
2917 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2918}
2919
2920// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2921// ES 3.0.4 table 3.24
2922TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2923{
Yunchao He9550c602018-02-13 14:47:05 +08002924 // Seems to fail on OSX 10.12 Intel.
2925 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Jamie Madillbb1db482017-01-10 10:48:32 -05002926
Yuly Novikov49886892018-01-23 21:18:27 -05002927 // http://anglebug.com/2190
2928 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2929
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002930 glActiveTexture(GL_TEXTURE0);
2931 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2932 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2933 EXPECT_GL_NO_ERROR();
2934
2935 drawQuad(mProgram, "position", 0.5f);
2936
2937 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2938}
2939
2940// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2941// ES 3.0.4 table 3.24
2942TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2943{
Yunchao He9550c602018-02-13 14:47:05 +08002944 // Seems to fail on OSX 10.12 Intel.
2945 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002946
Yuly Novikov49886892018-01-23 21:18:27 -05002947 // http://anglebug.com/2190
2948 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2949
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002950 glActiveTexture(GL_TEXTURE0);
2951 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2952 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2953 EXPECT_GL_NO_ERROR();
2954
2955 drawQuad(mProgram, "position", 0.5f);
2956
2957 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2958}
2959
Olli Etuaho96963162016-03-21 11:54:33 +02002960// Use a sampler in a uniform struct.
2961TEST_P(SamplerInStructTest, SamplerInStruct)
2962{
2963 runSamplerInStructTest();
2964}
2965
2966// Use a sampler in a uniform struct that's passed as a function parameter.
2967TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2968{
Yuly Novikovd18c0482019-04-04 19:56:43 -04002969 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
2970 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002971
Olli Etuaho96963162016-03-21 11:54:33 +02002972 runSamplerInStructTest();
2973}
2974
2975// Use a sampler in a uniform struct array with a struct from the array passed as a function
2976// parameter.
2977TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2978{
Yuly Novikovd18c0482019-04-04 19:56:43 -04002979 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
2980 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08002981
Olli Etuaho96963162016-03-21 11:54:33 +02002982 runSamplerInStructTest();
2983}
2984
2985// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2986// parameter.
2987TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2988{
Yuly Novikovd18c0482019-04-04 19:56:43 -04002989 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
2990 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08002991
Olli Etuaho96963162016-03-21 11:54:33 +02002992 runSamplerInStructTest();
2993}
2994
2995// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2996// similarly named uniform.
2997TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2998{
2999 runSamplerInStructTest();
3000}
3001
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05003002// GL_EXT_texture_filter_anisotropic
3003class TextureAnisotropyTest : public Texture2DTest
3004{
3005 protected:
3006 void uploadTexture()
3007 {
3008 glActiveTexture(GL_TEXTURE0);
3009 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3010 GLColor texDataRed[1] = {GLColor::red};
3011 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed);
3012 EXPECT_GL_NO_ERROR();
3013 }
3014};
3015
3016// Tests that setting anisotropic filtering doesn't cause failures at draw time.
3017TEST_P(TextureAnisotropyTest, AnisotropyFunctional)
3018{
Jamie Madillb8149072019-04-30 16:14:44 -04003019 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_filter_anisotropic"));
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05003020
3021 setUpProgram();
3022
3023 uploadTexture();
3024
3025 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3026 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3027 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f);
3028 EXPECT_GL_NO_ERROR();
3029
3030 drawQuad(mProgram, "position", 0.5f);
3031
3032 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3033 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3034 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::red);
3035}
3036
Till Rathmannb8543632018-10-02 19:46:14 +02003037// GL_OES_texture_border_clamp
3038class TextureBorderClampTest : public Texture2DTest
3039{
3040 protected:
3041 TextureBorderClampTest() : Texture2DTest() {}
3042
Jamie Madill35cd7332018-12-02 12:03:33 -05003043 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003044 {
3045 return
3046 R"(precision highp float;
3047 attribute vec4 position;
3048 varying vec2 texcoord;
3049
3050 void main()
3051 {
3052 gl_Position = vec4(position.xy, 0.0, 1.0);
3053 // texcoords in [-0.5, 1.5]
3054 texcoord = (position.xy) + 0.5;
3055 })";
3056 }
3057
3058 void uploadTexture()
3059 {
3060 glActiveTexture(GL_TEXTURE0);
3061 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3062 std::vector<GLColor> texDataRed(1, GLColor::red);
3063 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3064 texDataRed.data());
3065 EXPECT_GL_NO_ERROR();
3066 }
3067};
3068
3069// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3070// GL_CLAMP_TO_BORDER wrap mode (set with glTexParameter).
3071TEST_P(TextureBorderClampTest, TextureBorderClampFunctional)
3072{
Jamie Madillb8149072019-04-30 16:14:44 -04003073 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003074
3075 setUpProgram();
3076
3077 uploadTexture();
3078
3079 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3080 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3081 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3082 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3083 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3084 EXPECT_GL_NO_ERROR();
3085
3086 drawQuad(mProgram, "position", 0.5f);
3087
3088 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3089 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3090 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3091}
3092
3093// Test reading back GL_TEXTURE_BORDER_COLOR by glGetTexParameter.
3094TEST_P(TextureBorderClampTest, TextureBorderClampFunctional2)
3095{
Jamie Madillb8149072019-04-30 16:14:44 -04003096 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003097
3098 glActiveTexture(GL_TEXTURE0);
3099 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3100
3101 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3102
3103 GLint colorFixedPoint[4] = {0};
3104 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3105 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3106 std::numeric_limits<GLint>::max()};
3107 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3108 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3109 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3110 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3111
3112 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3113 std::numeric_limits<GLint>::max()};
3114 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3115
3116 GLfloat color[4] = {0.0f};
3117 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
3118 EXPECT_EQ(color[0], kFloatBlue.R);
3119 EXPECT_EQ(color[1], kFloatBlue.G);
3120 EXPECT_EQ(color[2], kFloatBlue.B);
3121 EXPECT_EQ(color[3], kFloatBlue.A);
3122}
3123
3124// Test GL_TEXTURE_BORDER_COLOR parameter validation at glTexParameter.
3125TEST_P(TextureBorderClampTest, TextureBorderClampValidation)
3126{
Jamie Madillb8149072019-04-30 16:14:44 -04003127 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003128
3129 glActiveTexture(GL_TEXTURE0);
3130 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3131
3132 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, 1.0f);
3133 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3134
3135 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3136 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3137
3138 glTexParameterfv(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3139 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3140
3141 GLint colorInt[4] = {0};
3142 glTexParameteriv(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_BORDER_COLOR, colorInt);
3143 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3144
3145 if (getClientMajorVersion() < 3)
3146 {
3147 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3148 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3149 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3150 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3151
3152 GLuint colorUInt[4] = {0};
3153 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3154 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3155 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3156 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3157
3158 GLSampler sampler;
3159 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3160 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3161 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3162 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3163
3164 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3165 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3166 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3167 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3168 }
3169}
3170
3171class TextureBorderClampTestES3 : public TextureBorderClampTest
3172{
3173 protected:
3174 TextureBorderClampTestES3() : TextureBorderClampTest() {}
3175};
3176
3177// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3178// GL_CLAMP_TO_BORDER wrap mode (set with glSamplerParameter).
3179TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional)
3180{
Jamie Madillb8149072019-04-30 16:14:44 -04003181 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003182
3183 setUpProgram();
3184
3185 uploadTexture();
3186
3187 GLSampler sampler;
3188 glBindSampler(0, sampler);
3189 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3190 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3191 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3192 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3193 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3194 EXPECT_GL_NO_ERROR();
3195
3196 drawQuad(mProgram, "position", 0.5f);
3197
3198 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3199 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3200 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3201}
3202
3203// Test reading back GL_TEXTURE_BORDER_COLOR by glGetSamplerParameter.
3204TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional2)
3205{
Jamie Madillb8149072019-04-30 16:14:44 -04003206 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003207
3208 glActiveTexture(GL_TEXTURE0);
3209
3210 GLSampler sampler;
3211 glBindSampler(0, sampler);
3212
3213 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3214
3215 GLint colorFixedPoint[4] = {0};
3216 glGetSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3217 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3218 std::numeric_limits<GLint>::max()};
3219 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3220 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3221 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3222 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3223
3224 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3225 std::numeric_limits<GLint>::max()};
3226 glSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3227
3228 GLfloat color[4] = {0.0f};
3229 glGetSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, color);
3230 EXPECT_EQ(color[0], kFloatBlue.R);
3231 EXPECT_EQ(color[1], kFloatBlue.G);
3232 EXPECT_EQ(color[2], kFloatBlue.B);
3233 EXPECT_EQ(color[3], kFloatBlue.A);
3234
3235 constexpr GLint colorSomewhatRedInt[4] = {500000, 0, 0, std::numeric_limits<GLint>::max()};
3236 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedInt);
3237 GLint colorInt[4] = {0};
3238 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3239 EXPECT_EQ(colorInt[0], colorSomewhatRedInt[0]);
3240 EXPECT_EQ(colorInt[1], colorSomewhatRedInt[1]);
3241 EXPECT_EQ(colorInt[2], colorSomewhatRedInt[2]);
3242 EXPECT_EQ(colorInt[3], colorSomewhatRedInt[3]);
3243
3244 constexpr GLuint colorSomewhatRedUInt[4] = {500000, 0, 0, std::numeric_limits<GLuint>::max()};
3245 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedUInt);
3246 GLuint colorUInt[4] = {0};
3247 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3248 EXPECT_EQ(colorUInt[0], colorSomewhatRedUInt[0]);
3249 EXPECT_EQ(colorUInt[1], colorSomewhatRedUInt[1]);
3250 EXPECT_EQ(colorUInt[2], colorSomewhatRedUInt[2]);
3251 EXPECT_EQ(colorUInt[3], colorSomewhatRedUInt[3]);
3252
3253 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3254
3255 constexpr GLint colorSomewhatGreenInt[4] = {0, 500000, 0, std::numeric_limits<GLint>::max()};
3256 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenInt);
3257 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3258 EXPECT_EQ(colorInt[0], colorSomewhatGreenInt[0]);
3259 EXPECT_EQ(colorInt[1], colorSomewhatGreenInt[1]);
3260 EXPECT_EQ(colorInt[2], colorSomewhatGreenInt[2]);
3261 EXPECT_EQ(colorInt[3], colorSomewhatGreenInt[3]);
3262
3263 constexpr GLuint colorSomewhatGreenUInt[4] = {0, 500000, 0, std::numeric_limits<GLuint>::max()};
3264 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenUInt);
3265 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3266 EXPECT_EQ(colorUInt[0], colorSomewhatGreenUInt[0]);
3267 EXPECT_EQ(colorUInt[1], colorSomewhatGreenUInt[1]);
3268 EXPECT_EQ(colorUInt[2], colorSomewhatGreenUInt[2]);
3269 EXPECT_EQ(colorUInt[3], colorSomewhatGreenUInt[3]);
3270}
3271
3272// Test GL_TEXTURE_BORDER_COLOR parameter validation at glSamplerParameter.
3273TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Validation)
3274{
Jamie Madillb8149072019-04-30 16:14:44 -04003275 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003276
3277 glActiveTexture(GL_TEXTURE0);
3278
3279 GLSampler sampler;
3280 glBindSampler(0, sampler);
3281
3282 glSamplerParameterf(sampler, GL_TEXTURE_BORDER_COLOR, 1.0f);
3283 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3284
3285 glSamplerParameteri(sampler, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3286 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3287}
3288
3289class TextureBorderClampIntegerTestES3 : public Texture2DTest
3290{
3291 protected:
3292 TextureBorderClampIntegerTestES3() : Texture2DTest(), isUnsignedIntTest(false) {}
3293
Jamie Madill35cd7332018-12-02 12:03:33 -05003294 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003295 {
3296 return
3297 R"(#version 300 es
3298 out vec2 texcoord;
3299 in vec4 position;
3300
3301 void main()
3302 {
3303 gl_Position = vec4(position.xy, 0.0, 1.0);
3304 // texcoords in [-0.5, 1.5]
3305 texcoord = (position.xy) + 0.5;
3306 })";
3307 }
3308
Jamie Madillba319ba2018-12-29 10:29:33 -05003309 const char *getFragmentShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003310 {
Jamie Madill35cd7332018-12-02 12:03:33 -05003311 if (isUnsignedIntTest)
3312 {
3313 return "#version 300 es\n"
3314 "precision highp float;\n"
3315 "uniform highp usampler2D tex;\n"
3316 "in vec2 texcoord;\n"
3317 "out vec4 fragColor;\n"
Till Rathmannb8543632018-10-02 19:46:14 +02003318
Jamie Madill35cd7332018-12-02 12:03:33 -05003319 "void main()\n"
3320 "{\n"
3321 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3322 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3323 "fragColor = (texture(tex, texcoord).r == 150u)"
3324 " ? green : red;\n"
3325 "}\n";
3326 }
3327 else
3328 {
3329 return "#version 300 es\n"
3330 "precision highp float;\n"
3331 "uniform highp isampler2D tex;\n"
3332 "in vec2 texcoord;\n"
3333 "out vec4 fragColor;\n"
3334
3335 "void main()\n"
3336 "{\n"
3337 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3338 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3339 "fragColor = (texture(tex, texcoord).r == -50)"
3340 " ? green : red;\n"
3341 "}\n";
3342 }
Till Rathmannb8543632018-10-02 19:46:14 +02003343 }
3344
3345 void uploadTexture()
3346 {
3347 glActiveTexture(GL_TEXTURE0);
3348 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3349 if (isUnsignedIntTest)
3350 {
3351 std::vector<GLubyte> texData(4, 100);
3352 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE,
3353 texData.data());
3354 }
3355 else
3356 {
3357 std::vector<GLbyte> texData(4, 100);
3358 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8I, 1, 1, 0, GL_RGBA_INTEGER, GL_BYTE,
3359 texData.data());
3360 }
3361 EXPECT_GL_NO_ERROR();
3362 }
3363
3364 bool isUnsignedIntTest;
3365};
3366
3367// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3368// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3369TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger)
3370{
Jamie Madillb8149072019-04-30 16:14:44 -04003371 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003372
3373 setUpProgram();
3374
3375 uploadTexture();
3376
3377 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3378 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3379 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3380 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3381
3382 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3383 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3384
3385 EXPECT_GL_NO_ERROR();
3386
3387 drawQuad(mProgram, "position", 0.5f);
3388
3389 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3390 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3391 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3392}
3393
3394// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3395// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3396TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger2)
3397{
Jamie Madillb8149072019-04-30 16:14:44 -04003398 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003399
3400 setUpProgram();
3401
3402 uploadTexture();
3403
3404 GLSampler sampler;
3405 glBindSampler(0, sampler);
3406 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3407 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3408 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3409 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3410
3411 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3412 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3413
3414 EXPECT_GL_NO_ERROR();
3415
3416 drawQuad(mProgram, "position", 0.5f);
3417
3418 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3419 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3420 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3421}
3422
3423// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3424// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIuivOES).
3425TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned)
3426{
Jamie Madillb8149072019-04-30 16:14:44 -04003427 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003428
3429 isUnsignedIntTest = true;
3430
3431 setUpProgram();
3432
3433 uploadTexture();
3434
3435 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3436 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3437 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3438 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3439
3440 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3441 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3442
3443 EXPECT_GL_NO_ERROR();
3444
3445 drawQuad(mProgram, "position", 0.5f);
3446
3447 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3448 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3449 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3450}
3451
3452// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3453// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with
3454// glSamplerParameterIuivOES).
3455TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned2)
3456{
Jamie Madillb8149072019-04-30 16:14:44 -04003457 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003458
3459 isUnsignedIntTest = true;
3460
3461 setUpProgram();
3462
3463 uploadTexture();
3464
3465 GLSampler sampler;
3466 glBindSampler(0, sampler);
3467 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3468 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3469 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3470 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3471
3472 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3473 glSamplerParameterIuivOES(sampler, 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// ~GL_OES_texture_border_clamp
3485
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003486class TextureLimitsTest : public ANGLETest
3487{
3488 protected:
3489 struct RGBA8
3490 {
3491 uint8_t R, G, B, A;
3492 };
3493
3494 TextureLimitsTest()
3495 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
3496 {
3497 setWindowWidth(128);
3498 setWindowHeight(128);
3499 setConfigRedBits(8);
3500 setConfigGreenBits(8);
3501 setConfigBlueBits(8);
3502 setConfigAlphaBits(8);
3503 }
3504
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003505 void testSetUp() override
Jamie Madill0fdb9562018-09-17 17:18:43 -04003506 {
Jamie Madill0fdb9562018-09-17 17:18:43 -04003507 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
3508 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
3509 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
3510
3511 ASSERT_GL_NO_ERROR();
3512 }
3513
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003514 void testTearDown() override
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003515 {
3516 if (mProgram != 0)
3517 {
3518 glDeleteProgram(mProgram);
3519 mProgram = 0;
3520
3521 if (!mTextures.empty())
3522 {
3523 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
3524 }
3525 }
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003526 }
3527
3528 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
3529 GLint vertexTextureCount,
3530 GLint vertexActiveTextureCount,
3531 const std::string &fragPrefix,
3532 GLint fragmentTextureCount,
3533 GLint fragmentActiveTextureCount)
3534 {
3535 std::stringstream vertexShaderStr;
3536 vertexShaderStr << "attribute vec2 position;\n"
3537 << "varying vec4 color;\n"
3538 << "varying vec2 texCoord;\n";
3539
3540 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
3541 {
3542 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
3543 }
3544
3545 vertexShaderStr << "void main() {\n"
3546 << " gl_Position = vec4(position, 0, 1);\n"
3547 << " texCoord = (position * 0.5) + 0.5;\n"
3548 << " color = vec4(0);\n";
3549
3550 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
3551 {
3552 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
3553 << ", texCoord);\n";
3554 }
3555
3556 vertexShaderStr << "}";
3557
3558 std::stringstream fragmentShaderStr;
3559 fragmentShaderStr << "varying mediump vec4 color;\n"
3560 << "varying mediump vec2 texCoord;\n";
3561
3562 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
3563 {
3564 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
3565 }
3566
3567 fragmentShaderStr << "void main() {\n"
3568 << " gl_FragColor = color;\n";
3569
3570 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
3571 {
3572 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
3573 << ", texCoord);\n";
3574 }
3575
3576 fragmentShaderStr << "}";
3577
3578 const std::string &vertexShaderSource = vertexShaderStr.str();
3579 const std::string &fragmentShaderSource = fragmentShaderStr.str();
3580
Jamie Madill35cd7332018-12-02 12:03:33 -05003581 mProgram = CompileProgram(vertexShaderSource.c_str(), fragmentShaderSource.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003582 }
3583
3584 RGBA8 getPixel(GLint texIndex)
3585 {
3586 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3587 0, 255u};
3588 return pixel;
3589 }
3590
3591 void initTextures(GLint tex2DCount, GLint texCubeCount)
3592 {
3593 GLint totalCount = tex2DCount + texCubeCount;
3594 mTextures.assign(totalCount, 0);
3595 glGenTextures(totalCount, &mTextures[0]);
3596 ASSERT_GL_NO_ERROR();
3597
3598 std::vector<RGBA8> texData(16 * 16);
3599
3600 GLint texIndex = 0;
3601 for (; texIndex < tex2DCount; ++texIndex)
3602 {
3603 texData.assign(texData.size(), getPixel(texIndex));
3604 glActiveTexture(GL_TEXTURE0 + texIndex);
3605 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3606 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3607 &texData[0]);
3608 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3609 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3610 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3611 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3612 }
3613
3614 ASSERT_GL_NO_ERROR();
3615
3616 for (; texIndex < texCubeCount; ++texIndex)
3617 {
3618 texData.assign(texData.size(), getPixel(texIndex));
3619 glActiveTexture(GL_TEXTURE0 + texIndex);
3620 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3621 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3622 GL_UNSIGNED_BYTE, &texData[0]);
3623 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3624 GL_UNSIGNED_BYTE, &texData[0]);
3625 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3626 GL_UNSIGNED_BYTE, &texData[0]);
3627 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3628 GL_UNSIGNED_BYTE, &texData[0]);
3629 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3630 GL_UNSIGNED_BYTE, &texData[0]);
3631 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3632 GL_UNSIGNED_BYTE, &texData[0]);
3633 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3634 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3635 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3636 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3637 }
3638
3639 ASSERT_GL_NO_ERROR();
3640 }
3641
3642 void testWithTextures(GLint vertexTextureCount,
3643 const std::string &vertexTexturePrefix,
3644 GLint fragmentTextureCount,
3645 const std::string &fragmentTexturePrefix)
3646 {
3647 // Generate textures
3648 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3649
3650 glUseProgram(mProgram);
3651 RGBA8 expectedSum = {0};
3652 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3653 {
3654 std::stringstream uniformNameStr;
3655 uniformNameStr << vertexTexturePrefix << texIndex;
3656 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003657 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003658 ASSERT_NE(-1, location);
3659
3660 glUniform1i(location, texIndex);
3661 RGBA8 contribution = getPixel(texIndex);
3662 expectedSum.R += contribution.R;
3663 expectedSum.G += contribution.G;
3664 }
3665
3666 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3667 {
3668 std::stringstream uniformNameStr;
3669 uniformNameStr << fragmentTexturePrefix << texIndex;
3670 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003671 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003672 ASSERT_NE(-1, location);
3673
3674 glUniform1i(location, texIndex + vertexTextureCount);
3675 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3676 expectedSum.R += contribution.R;
3677 expectedSum.G += contribution.G;
3678 }
3679
3680 ASSERT_GE(256u, expectedSum.G);
3681
3682 drawQuad(mProgram, "position", 0.5f);
3683 ASSERT_GL_NO_ERROR();
3684 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3685 }
3686
3687 GLuint mProgram;
3688 std::vector<GLuint> mTextures;
3689 GLint mMaxVertexTextures;
3690 GLint mMaxFragmentTextures;
3691 GLint mMaxCombinedTextures;
3692};
3693
3694// Test rendering with the maximum vertex texture units.
3695TEST_P(TextureLimitsTest, MaxVertexTextures)
3696{
3697 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3698 ASSERT_NE(0u, mProgram);
3699 ASSERT_GL_NO_ERROR();
3700
3701 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3702}
3703
3704// Test rendering with the maximum fragment texture units.
3705TEST_P(TextureLimitsTest, MaxFragmentTextures)
3706{
3707 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3708 ASSERT_NE(0u, mProgram);
3709 ASSERT_GL_NO_ERROR();
3710
3711 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3712}
3713
3714// Test rendering with maximum combined texture units.
3715TEST_P(TextureLimitsTest, MaxCombinedTextures)
3716{
3717 GLint vertexTextures = mMaxVertexTextures;
3718
3719 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3720 {
3721 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3722 }
3723
3724 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3725 mMaxFragmentTextures, mMaxFragmentTextures);
3726 ASSERT_NE(0u, mProgram);
3727 ASSERT_GL_NO_ERROR();
3728
3729 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3730}
3731
3732// Negative test for exceeding the number of vertex textures
3733TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3734{
3735 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3736 0);
3737 ASSERT_EQ(0u, mProgram);
3738}
3739
3740// Negative test for exceeding the number of fragment textures
3741TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3742{
3743 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3744 mMaxFragmentTextures + 1);
3745 ASSERT_EQ(0u, mProgram);
3746}
3747
3748// Test active vertex textures under the limit, but excessive textures specified.
3749TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3750{
3751 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3752 ASSERT_NE(0u, mProgram);
3753 ASSERT_GL_NO_ERROR();
3754
3755 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3756}
3757
3758// Test active fragment textures under the limit, but excessive textures specified.
3759TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3760{
3761 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3762 mMaxFragmentTextures);
3763 ASSERT_NE(0u, mProgram);
3764 ASSERT_GL_NO_ERROR();
3765
3766 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3767}
3768
3769// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003770// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003771TEST_P(TextureLimitsTest, TextureTypeConflict)
3772{
Jamie Madill35cd7332018-12-02 12:03:33 -05003773 constexpr char kVS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003774 "attribute vec2 position;\n"
3775 "varying float color;\n"
3776 "uniform sampler2D tex2D;\n"
3777 "uniform samplerCube texCube;\n"
3778 "void main() {\n"
3779 " gl_Position = vec4(position, 0, 1);\n"
3780 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3781 " color = texture2D(tex2D, texCoord).x;\n"
3782 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3783 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05003784 constexpr char kFS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003785 "varying mediump float color;\n"
3786 "void main() {\n"
3787 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3788 "}";
3789
Jamie Madill35cd7332018-12-02 12:03:33 -05003790 mProgram = CompileProgram(kVS, kFS);
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003791 ASSERT_NE(0u, mProgram);
3792
3793 initTextures(1, 0);
3794
3795 glUseProgram(mProgram);
3796 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3797 ASSERT_NE(-1, tex2DLocation);
3798 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3799 ASSERT_NE(-1, texCubeLocation);
3800
3801 glUniform1i(tex2DLocation, 0);
3802 glUniform1i(texCubeLocation, 0);
3803 ASSERT_GL_NO_ERROR();
3804
3805 drawQuad(mProgram, "position", 0.5f);
3806 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3807}
3808
Vincent Lang25ab4512016-05-13 18:13:59 +02003809class Texture2DNorm16TestES3 : public Texture2DTestES3
3810{
3811 protected:
3812 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3813
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003814 void testSetUp() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003815 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003816 Texture2DTestES3::testSetUp();
Vincent Lang25ab4512016-05-13 18:13:59 +02003817
3818 glActiveTexture(GL_TEXTURE0);
3819 glGenTextures(3, mTextures);
3820 glGenFramebuffers(1, &mFBO);
3821 glGenRenderbuffers(1, &mRenderbuffer);
3822
3823 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3824 {
3825 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3826 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3827 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3828 }
3829
3830 glBindTexture(GL_TEXTURE_2D, 0);
3831
3832 ASSERT_GL_NO_ERROR();
3833 }
3834
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003835 void testTearDown() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003836 {
3837 glDeleteTextures(3, mTextures);
3838 glDeleteFramebuffers(1, &mFBO);
3839 glDeleteRenderbuffers(1, &mRenderbuffer);
3840
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003841 Texture2DTestES3::testTearDown();
Vincent Lang25ab4512016-05-13 18:13:59 +02003842 }
3843
3844 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3845 {
Geoff Langf607c602016-09-21 11:46:48 -04003846 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3847 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003848
3849 setUpProgram();
3850
3851 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3852 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3853 0);
3854
3855 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3856 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3857
3858 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003859 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003860
3861 EXPECT_GL_NO_ERROR();
3862
3863 drawQuad(mProgram, "position", 0.5f);
3864
Geoff Langf607c602016-09-21 11:46:48 -04003865 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003866
Jamie Madill50cf2be2018-06-15 09:46:57 -04003867 EXPECT_PIXEL_COLOR_EQ(0, 0,
3868 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3869 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003870
3871 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3872
3873 ASSERT_GL_NO_ERROR();
3874 }
3875
3876 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3877 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04003878 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003879 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003880
3881 setUpProgram();
3882
3883 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3884 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3885
3886 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3887 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3888 0);
3889
3890 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
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 = static_cast<GLubyte>(pixelValue >> 8);
Jamie Madill50cf2be2018-06-15 09:46:57 -04003898 EXPECT_PIXEL_COLOR_EQ(0, 0,
3899 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3900 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003901
3902 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3903 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3904 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3905 mRenderbuffer);
3906 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3907 EXPECT_GL_NO_ERROR();
3908
3909 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3910 glClear(GL_COLOR_BUFFER_BIT);
3911
3912 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3913
Geoff Langf607c602016-09-21 11:46:48 -04003914 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003915
3916 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3917
3918 ASSERT_GL_NO_ERROR();
3919 }
3920
3921 GLuint mTextures[3];
3922 GLuint mFBO;
3923 GLuint mRenderbuffer;
3924};
3925
3926// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3927TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3928{
Jamie Madillb8149072019-04-30 16:14:44 -04003929 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02003930
3931 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3932 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3933 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3934 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3935 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3936 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3937 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3938 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3939
3940 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3941 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3942 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3943}
3944
Olli Etuaho95faa232016-06-07 14:01:53 -07003945// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3946// GLES 3.0.4 section 3.8.3.
3947TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3948{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003949 // Crashes on Nexus 5X due to a driver bug. http://anglebug.com/1429
3950 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07003951
3952 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3953 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3954 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3955 ASSERT_GL_NO_ERROR();
3956
3957 // SKIP_IMAGES should not have an effect on uploading 2D textures
3958 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3959 ASSERT_GL_NO_ERROR();
3960
3961 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3962
3963 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3964 pixelsGreen.data());
3965 ASSERT_GL_NO_ERROR();
3966
3967 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3968 pixelsGreen.data());
3969 ASSERT_GL_NO_ERROR();
3970
3971 glUseProgram(mProgram);
3972 drawQuad(mProgram, "position", 0.5f);
3973 ASSERT_GL_NO_ERROR();
3974
3975 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3976}
3977
Olli Etuaho989cac32016-06-08 16:18:49 -07003978// Test that skip defined in unpack parameters is taken into account when determining whether
3979// unpacking source extends outside unpack buffer bounds.
3980TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3981{
3982 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3983 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3984 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3985 ASSERT_GL_NO_ERROR();
3986
3987 GLBuffer buf;
3988 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3989 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3990 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3991 GL_DYNAMIC_COPY);
3992 ASSERT_GL_NO_ERROR();
3993
3994 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3995 ASSERT_GL_NO_ERROR();
3996
3997 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3998 ASSERT_GL_NO_ERROR();
3999
4000 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4001 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4002
4003 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
4004 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
4005 ASSERT_GL_NO_ERROR();
4006
4007 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4008 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4009}
4010
Olli Etuaho218cf9e2016-05-20 13:55:24 +03004011// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
4012TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
4013{
Yunchao He9550c602018-02-13 14:47:05 +08004014 ANGLE_SKIP_TEST_IF(IsD3D11());
4015
4016 // Incorrect rendering results seen on OSX AMD.
4017 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03004018
4019 const GLuint width = 8u;
4020 const GLuint height = 8u;
4021 const GLuint unpackRowLength = 5u;
4022 const GLuint unpackSkipPixels = 1u;
4023
4024 setWindowWidth(width);
4025 setWindowHeight(height);
4026
4027 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4028 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4029 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4030 ASSERT_GL_NO_ERROR();
4031
4032 GLBuffer buf;
4033 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
4034 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
4035 GLColor::green);
4036
4037 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
4038 {
4039 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
4040 }
4041
4042 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
4043 GL_DYNAMIC_COPY);
4044 ASSERT_GL_NO_ERROR();
4045
4046 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
4047 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
4048 ASSERT_GL_NO_ERROR();
4049
4050 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4051 ASSERT_GL_NO_ERROR();
4052
4053 glUseProgram(mProgram);
4054 drawQuad(mProgram, "position", 0.5f);
4055 ASSERT_GL_NO_ERROR();
4056
4057 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
4058 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
4059 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
4060 actual.data());
4061 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
4062 EXPECT_EQ(expected, actual);
4063}
4064
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004065template <typename T>
4066T UNorm(double value)
4067{
4068 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
4069}
4070
4071// Test rendering a depth texture with mipmaps.
4072TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
4073{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08004074 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
4075 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
Jiawei Shaoaf0f31d2018-09-27 15:42:31 +08004076 // http://anglebug.com/1706
4077 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Corentin Walleze731d8a2016-09-07 10:56:25 -04004078
Jamie Madill24980272019-04-03 09:03:51 -04004079 // Seems to fail on AMD D3D11. Possibly driver bug. http://anglebug.com/3342
4080 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsD3D11());
4081
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004082 const int size = getWindowWidth();
4083
4084 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04004085 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004086
4087 glActiveTexture(GL_TEXTURE0);
4088 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4089 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
4090 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4091 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4092 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
4093 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
4094 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4095 ASSERT_GL_NO_ERROR();
4096
4097 glUseProgram(mProgram);
4098 glUniform1i(mTexture2DUniformLocation, 0);
4099
4100 std::vector<unsigned char> expected;
4101
4102 for (int level = 0; level < levels; ++level)
4103 {
4104 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
4105 expected.push_back(UNorm<unsigned char>(value));
4106
4107 int levelDim = dim(level);
4108
4109 ASSERT_GT(levelDim, 0);
4110
4111 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
4112 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
4113 GL_UNSIGNED_INT, initData.data());
4114 }
4115 ASSERT_GL_NO_ERROR();
4116
4117 for (int level = 0; level < levels; ++level)
4118 {
4119 glViewport(0, 0, dim(level), dim(level));
4120 drawQuad(mProgram, "position", 0.5f);
4121 GLColor actual = ReadColor(0, 0);
4122 EXPECT_NEAR(expected[level], actual.R, 10u);
4123 }
4124
4125 ASSERT_GL_NO_ERROR();
4126}
4127
Jamie Madill7ffdda92016-09-08 13:26:51 -04004128// Tests unpacking into the unsized GL_ALPHA format.
4129TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
4130{
Jamie Madill7ffdda92016-09-08 13:26:51 -04004131 // Initialize the texure.
4132 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4133 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
4134 GL_UNSIGNED_BYTE, nullptr);
4135 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4136 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4137
4138 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
4139
4140 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04004141 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04004142 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4143 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4144 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
4145 GL_STATIC_DRAW);
4146
4147 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
4148 GL_UNSIGNED_BYTE, nullptr);
4149
4150 // Clear to a weird color to make sure we're drawing something.
4151 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
4152 glClear(GL_COLOR_BUFFER_BIT);
4153
4154 // Draw with the alpha texture and verify.
4155 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04004156
4157 ASSERT_GL_NO_ERROR();
4158 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
4159}
4160
Jamie Madill2e600342016-09-19 13:56:40 -04004161// Ensure stale unpack data doesn't propagate in D3D11.
4162TEST_P(Texture2DTestES3, StaleUnpackData)
4163{
4164 // Init unpack buffer.
4165 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
4166 std::vector<GLColor> pixels(pixelCount, GLColor::red);
4167
4168 GLBuffer unpackBuffer;
4169 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4170 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4171 GLsizei bufferSize = pixelCount * sizeof(GLColor);
4172 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
4173
4174 // Create from unpack buffer.
4175 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4176 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
4177 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4178 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4179 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4180
4181 drawQuad(mProgram, "position", 0.5f);
4182
4183 ASSERT_GL_NO_ERROR();
4184 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4185
4186 // Fill unpack with green, recreating buffer.
4187 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
4188 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
4189 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
4190
4191 // Reinit texture with green.
4192 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
4193 GL_UNSIGNED_BYTE, nullptr);
4194
4195 drawQuad(mProgram, "position", 0.5f);
4196
4197 ASSERT_GL_NO_ERROR();
4198 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
4199}
4200
Geoff Langfb7685f2017-11-13 11:44:11 -05004201// Ensure that texture parameters passed as floats that are converted to ints are rounded before
4202// validating they are less than 0.
4203TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
4204{
4205 GLTexture texture;
4206 glBindTexture(GL_TEXTURE_2D, texture);
4207
4208 // Use a negative number that will round to zero when converted to an integer
4209 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
4210 // "Validation of values performed by state-setting commands is performed after conversion,
4211 // unless specified otherwise for a specific command."
4212 GLfloat param = -7.30157126e-07f;
4213 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
4214 EXPECT_GL_NO_ERROR();
4215
4216 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
4217 EXPECT_GL_NO_ERROR();
4218}
4219
Jamie Madillf097e232016-11-05 00:44:15 -04004220// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
4221// being properly checked, and the texture storage of the previous texture format was persisting.
4222// This would result in an ASSERT in debug and incorrect rendering in release.
4223// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
4224TEST_P(Texture3DTestES3, FormatRedefinitionBug)
4225{
4226 GLTexture tex;
4227 glBindTexture(GL_TEXTURE_3D, tex.get());
4228 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4229
4230 GLFramebuffer framebuffer;
4231 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
4232 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
4233
4234 glCheckFramebufferStatus(GL_FRAMEBUFFER);
4235
4236 std::vector<uint8_t> pixelData(100, 0);
4237
4238 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
4239 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
4240 pixelData.data());
4241
4242 ASSERT_GL_NO_ERROR();
4243}
4244
Corentin Wallezd2627992017-04-28 17:17:03 -04004245// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
4246TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
4247{
4248 // 2D tests
4249 {
4250 GLTexture tex;
4251 glBindTexture(GL_TEXTURE_2D, tex.get());
4252
4253 GLBuffer pbo;
4254 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4255
4256 // Test OOB
4257 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
4258 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4259 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4260
4261 // Test OOB
4262 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
4263 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4264 ASSERT_GL_NO_ERROR();
4265 }
4266
4267 // 3D tests
4268 {
4269 GLTexture tex;
4270 glBindTexture(GL_TEXTURE_3D, tex.get());
4271
4272 GLBuffer pbo;
4273 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4274
4275 // Test OOB
4276 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
4277 GL_STATIC_DRAW);
4278 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4279 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4280
4281 // Test OOB
4282 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
4283 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4284 ASSERT_GL_NO_ERROR();
4285 }
4286}
4287
Jamie Madill3ed60422017-09-07 11:32:52 -04004288// Tests behaviour with a single texture and multiple sampler objects.
4289TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
4290{
4291 GLint maxTextureUnits = 0;
4292 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
4293 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
4294
4295 constexpr int kSize = 16;
4296
4297 // Make a single-level texture, fill it with red.
4298 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
4299 GLTexture tex;
4300 glBindTexture(GL_TEXTURE_2D, tex);
4301 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4302 redColors.data());
4303 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4304 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4305
4306 // Simple sanity check.
4307 draw2DTexturedQuad(0.5f, 1.0f, true);
4308 ASSERT_GL_NO_ERROR();
4309 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4310
4311 // Bind texture to unit 1 with a sampler object making it incomplete.
4312 GLSampler sampler;
4313 glBindSampler(0, sampler);
4314 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4315 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4316
4317 // Make a mipmap texture, fill it with blue.
4318 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
4319 GLTexture mipmapTex;
4320 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4321 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4322 blueColors.data());
4323 glGenerateMipmap(GL_TEXTURE_2D);
4324
4325 // Draw with the sampler, expect blue.
4326 draw2DTexturedQuad(0.5f, 1.0f, true);
4327 ASSERT_GL_NO_ERROR();
4328 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
4329
4330 // Simple multitexturing program.
Jamie Madill35cd7332018-12-02 12:03:33 -05004331 constexpr char kVS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004332 "#version 300 es\n"
4333 "in vec2 position;\n"
4334 "out vec2 texCoord;\n"
4335 "void main()\n"
4336 "{\n"
4337 " gl_Position = vec4(position, 0, 1);\n"
4338 " texCoord = position * 0.5 + vec2(0.5);\n"
4339 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05004340
4341 constexpr char kFS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004342 "#version 300 es\n"
4343 "precision mediump float;\n"
4344 "in vec2 texCoord;\n"
4345 "uniform sampler2D tex1;\n"
4346 "uniform sampler2D tex2;\n"
4347 "uniform sampler2D tex3;\n"
4348 "uniform sampler2D tex4;\n"
4349 "out vec4 color;\n"
4350 "void main()\n"
4351 "{\n"
4352 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
4353 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
4354 "}";
4355
Jamie Madill35cd7332018-12-02 12:03:33 -05004356 ANGLE_GL_PROGRAM(program, kVS, kFS);
Jamie Madill3ed60422017-09-07 11:32:52 -04004357
4358 std::array<GLint, 4> texLocations = {
4359 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
4360 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
4361 for (GLint location : texLocations)
4362 {
4363 ASSERT_NE(-1, location);
4364 }
4365
4366 // Init the uniform data.
4367 glUseProgram(program);
4368 for (GLint location = 0; location < 4; ++location)
4369 {
4370 glUniform1i(texLocations[location], location);
4371 }
4372
4373 // Initialize four samplers
4374 GLSampler samplers[4];
4375
4376 // 0: non-mipped.
4377 glBindSampler(0, samplers[0]);
4378 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4379 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4380
4381 // 1: mipped.
4382 glBindSampler(1, samplers[1]);
4383 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4384 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4385
4386 // 2: non-mipped.
4387 glBindSampler(2, samplers[2]);
4388 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4389 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4390
4391 // 3: mipped.
4392 glBindSampler(3, samplers[3]);
4393 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4394 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4395
4396 // Bind two blue mipped textures and two single layer textures, should all draw.
4397 glActiveTexture(GL_TEXTURE0);
4398 glBindTexture(GL_TEXTURE_2D, tex);
4399
4400 glActiveTexture(GL_TEXTURE1);
4401 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4402
4403 glActiveTexture(GL_TEXTURE2);
4404 glBindTexture(GL_TEXTURE_2D, tex);
4405
4406 glActiveTexture(GL_TEXTURE3);
4407 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4408
4409 ASSERT_GL_NO_ERROR();
4410
4411 drawQuad(program, "position", 0.5f);
4412 ASSERT_GL_NO_ERROR();
4413 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
4414
4415 // Bind four single layer textures, two should be incomplete.
4416 glActiveTexture(GL_TEXTURE1);
4417 glBindTexture(GL_TEXTURE_2D, tex);
4418
4419 glActiveTexture(GL_TEXTURE3);
4420 glBindTexture(GL_TEXTURE_2D, tex);
4421
4422 drawQuad(program, "position", 0.5f);
4423 ASSERT_GL_NO_ERROR();
4424 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
4425}
4426
Martin Radev7e2c0d32017-09-15 14:25:42 +03004427// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
4428// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
4429// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
4430// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
4431// samples the cubemap using a direction vector (1,1,1).
4432TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
4433{
Yunchao He2f23f352018-02-11 22:11:37 +08004434 // Check http://anglebug.com/2155.
4435 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
4436
Jamie Madill35cd7332018-12-02 12:03:33 -05004437 constexpr char kVS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004438 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004439 precision mediump float;
4440 in vec3 pos;
4441 void main() {
4442 gl_Position = vec4(pos, 1.0);
4443 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03004444
Jamie Madill35cd7332018-12-02 12:03:33 -05004445 constexpr char kFS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004446 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004447 precision mediump float;
4448 out vec4 color;
4449 uniform samplerCube uTex;
4450 void main(){
4451 color = texture(uTex, vec3(1.0));
4452 })";
Jamie Madill35cd7332018-12-02 12:03:33 -05004453
4454 ANGLE_GL_PROGRAM(program, kVS, kFS);
Martin Radev7e2c0d32017-09-15 14:25:42 +03004455 glUseProgram(program);
4456
4457 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
4458 glActiveTexture(GL_TEXTURE0);
4459
4460 GLTexture cubeTex;
4461 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
4462
4463 const int kFaceWidth = 1;
4464 const int kFaceHeight = 1;
4465 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
4466 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4467 GL_UNSIGNED_BYTE, texData.data());
4468 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4469 GL_UNSIGNED_BYTE, texData.data());
4470 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4471 GL_UNSIGNED_BYTE, texData.data());
4472 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4473 GL_UNSIGNED_BYTE, texData.data());
4474 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4475 GL_UNSIGNED_BYTE, texData.data());
4476 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4477 GL_UNSIGNED_BYTE, texData.data());
4478 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4479 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4480 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
4481 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
4482 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
4483 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
4484
4485 drawQuad(program, "pos", 0.5f, 1.0f, true);
4486 ASSERT_GL_NO_ERROR();
4487
4488 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4489}
4490
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08004491// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
4492TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
4493{
4494 GLuint texture = create2DTexture();
4495
4496 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
4497 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4498
4499 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
4500 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4501
4502 glDeleteTextures(1, &texture);
4503 EXPECT_GL_NO_ERROR();
4504}
4505
Olli Etuaho023371b2018-04-24 17:43:32 +03004506// Test setting base level after calling generateMipmap on a LUMA texture.
4507// Covers http://anglebug.com/2498
4508TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA)
4509{
4510 glActiveTexture(GL_TEXTURE0);
4511 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4512
4513 constexpr const GLsizei kWidth = 8;
4514 constexpr const GLsizei kHeight = 8;
4515 std::array<GLubyte, kWidth * kHeight * 2> whiteData;
4516 whiteData.fill(255u);
4517
4518 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA,
4519 GL_UNSIGNED_BYTE, whiteData.data());
4520 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
4521 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4522 glGenerateMipmap(GL_TEXTURE_2D);
4523 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
4524 EXPECT_GL_NO_ERROR();
4525
4526 drawQuad(mProgram, "position", 0.5f);
4527 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4528}
4529
Till Rathmannc1551dc2018-08-15 17:04:49 +02004530// Covers a bug in the D3D11 backend: http://anglebug.com/2772
4531// When using a sampler the texture was created as if it has mipmaps,
4532// regardless what you specified in GL_TEXTURE_MIN_FILTER via
4533// glSamplerParameteri() -- mistakenly the default value
4534// GL_NEAREST_MIPMAP_LINEAR or the value set via glTexParameteri() was
4535// evaluated.
4536// If you didn't provide mipmaps and didn't let the driver generate them
4537// this led to not sampling your texture data when minification occurred.
4538TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping)
4539{
Jamie Madill35cd7332018-12-02 12:03:33 -05004540 constexpr char kVS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004541 "#version 300 es\n"
4542 "out vec2 texcoord;\n"
4543 "in vec4 position;\n"
4544 "void main()\n"
4545 "{\n"
4546 " gl_Position = vec4(position.xy * 0.1, 0.0, 1.0);\n"
4547 " texcoord = (position.xy * 0.5) + 0.5;\n"
4548 "}\n";
4549
Jamie Madill35cd7332018-12-02 12:03:33 -05004550 constexpr char kFS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004551 "#version 300 es\n"
4552 "precision highp float;\n"
4553 "uniform highp sampler2D tex;\n"
4554 "in vec2 texcoord;\n"
4555 "out vec4 fragColor;\n"
4556 "void main()\n"
4557 "{\n"
4558 " fragColor = texture(tex, texcoord);\n"
4559 "}\n";
Jamie Madill35cd7332018-12-02 12:03:33 -05004560
4561 ANGLE_GL_PROGRAM(program, kVS, kFS);
Till Rathmannc1551dc2018-08-15 17:04:49 +02004562
4563 GLSampler sampler;
4564 glBindSampler(0, sampler);
4565 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4566 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4567
4568 glActiveTexture(GL_TEXTURE0);
4569 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4570
4571 const GLsizei texWidth = getWindowWidth();
4572 const GLsizei texHeight = getWindowHeight();
4573 const std::vector<GLColor> whiteData(texWidth * texHeight, GLColor::white);
4574
4575 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4576 whiteData.data());
4577 EXPECT_GL_NO_ERROR();
4578
4579 drawQuad(program, "position", 0.5f);
4580 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, angle::GLColor::white);
4581}
4582
Anders Leinof6cbe442019-04-18 15:32:07 +03004583// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4584// texture is output.
4585TEST_P(Texture2DIntegerTestES3, IntegerTextureNonZeroBaseLevel)
4586{
Yuly Novikovd2683452019-05-23 16:11:19 -04004587 // http://anglebug.com/3478
4588 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsDesktopOpenGL());
4589
Anders Leinof6cbe442019-04-18 15:32:07 +03004590 glActiveTexture(GL_TEXTURE0);
4591 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4592 int width = getWindowWidth();
4593 int height = getWindowHeight();
4594 GLColor color = GLColor::green;
4595 std::vector<GLColor> pixels(width * height, color);
4596 GLint baseLevel = 1;
4597 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
4598 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4599 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4600 glTexImage2D(GL_TEXTURE_2D, baseLevel, GL_RGBA8UI, width, height, 0, GL_RGBA_INTEGER,
4601 GL_UNSIGNED_BYTE, pixels.data());
4602
4603 setUpProgram();
4604 glUseProgram(mProgram);
4605 glUniform1i(mTexture2DUniformLocation, 0);
4606 drawQuad(mProgram, "position", 0.5f);
4607
4608 EXPECT_GL_NO_ERROR();
4609 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4610 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4611}
4612
Anders Leino60cc7512019-05-06 09:25:27 +03004613// Draw a quad with an integer cube texture with a non-zero base level, and test that the color of
4614// the texture is output.
4615TEST_P(TextureCubeIntegerTestES3, IntegerCubeTextureNonZeroBaseLevel)
4616{
4617 // All output checks returned black, rather than the texture color.
4618 ANGLE_SKIP_TEST_IF(IsOSX() && IsOpenGL());
4619
4620 glActiveTexture(GL_TEXTURE0);
4621
4622 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
4623 GLint baseLevel = 1;
4624 int width = getWindowWidth();
4625 int height = getWindowHeight();
4626 GLColor color = GLColor::green;
4627 std::vector<GLColor> pixels(width * height, color);
4628 for (GLenum faceIndex = 0; faceIndex < 6; faceIndex++)
4629 {
4630 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, baseLevel, GL_RGBA8UI, width,
4631 height, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
4632 EXPECT_GL_NO_ERROR();
4633 }
4634 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, baseLevel);
4635 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4636 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4637
4638 glUseProgram(mProgram);
4639 glUniform1i(mTextureCubeUniformLocation, 0);
4640 drawQuad(mProgram, "position", 0.5f);
4641
4642 EXPECT_GL_NO_ERROR();
4643 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4644 EXPECT_PIXEL_COLOR_EQ(width - 1, 0, color);
4645 EXPECT_PIXEL_COLOR_EQ(0, height - 1, color);
4646 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4647}
4648
Anders Leinoe4452442019-05-09 13:29:49 +03004649// This test sets up a cube map with four distincly colored MIP levels.
4650// The size of the texture and the geometry is chosen such that levels 1 or 2 should be chosen at
4651// the corners of the screen.
4652TEST_P(TextureCubeIntegerEdgeTestES3, IntegerCubeTextureCorner)
4653{
4654 glActiveTexture(GL_TEXTURE0);
4655
4656 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
4657 int width = getWindowWidth();
4658 int height = getWindowHeight();
4659 ASSERT_EQ(width, height);
4660 GLColor color[4] = {GLColor::white, GLColor::green, GLColor::blue, GLColor::red};
4661 for (GLint level = 0; level < 4; level++)
4662 {
4663 for (GLenum faceIndex = 0; faceIndex < 6; faceIndex++)
4664 {
4665 int levelWidth = (2 * width) >> level;
4666 int levelHeight = (2 * height) >> level;
4667 std::vector<GLColor> pixels(levelWidth * levelHeight, color[level]);
4668 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, level, GL_RGBA8UI, levelWidth,
4669 levelHeight, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
4670 EXPECT_GL_NO_ERROR();
4671 }
4672 }
4673 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4674 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4675 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 3);
4676
4677 glUseProgram(mProgram);
4678 glUniform1i(mTextureCubeUniformLocation, 0);
4679 drawQuad(mProgram, "position", 0.5f);
4680
4681 ASSERT_GL_NO_ERROR();
4682 // Check that we do not read from levels 0 or 3. Levels 1 and 2 are both acceptable.
4683 EXPECT_EQ(ReadColor(0, 0).R, 0);
4684 EXPECT_EQ(ReadColor(width - 1, 0).R, 0);
4685 EXPECT_EQ(ReadColor(0, height - 1).R, 0);
4686 EXPECT_EQ(ReadColor(width - 1, height - 1).R, 0);
4687}
4688
Anders Leino1b6aded2019-05-20 12:56:34 +03004689// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4690// texture is output.
4691TEST_P(Texture2DIntegerProjectiveOffsetTestES3, NonZeroBaseLevel)
4692{
4693 glActiveTexture(GL_TEXTURE0);
4694 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4695 int width = getWindowWidth();
4696 int height = getWindowHeight();
4697 GLColor color = GLColor::green;
4698 std::vector<GLColor> pixels(width * height, color);
4699 GLint baseLevel = 1;
4700 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
4701 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4702 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4703 glTexImage2D(GL_TEXTURE_2D, baseLevel, GL_RGBA8UI, width, height, 0, GL_RGBA_INTEGER,
4704 GL_UNSIGNED_BYTE, pixels.data());
4705
4706 setUpProgram();
4707 glUseProgram(mProgram);
4708 glUniform1i(mTexture2DUniformLocation, 0);
4709 drawQuad(mProgram, "position", 0.5f);
4710
4711 EXPECT_GL_NO_ERROR();
4712 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4713 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4714}
4715
Jamie Madill50cf2be2018-06-15 09:46:57 -04004716// Use this to select which configurations (e.g. which renderer, which GLES major version) these
4717// tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -05004718ANGLE_INSTANTIATE_TEST(Texture2DTest,
4719 ES2_D3D9(),
4720 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004721 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05004722 ES2_OPENGLES(),
4723 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004724ANGLE_INSTANTIATE_TEST(TextureCubeTest,
4725 ES2_D3D9(),
4726 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004727 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004728 ES2_OPENGLES(),
4729 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004730ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
4731 ES2_D3D9(),
4732 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004733 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004734 ES2_OPENGLES(),
4735 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004736ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
4737 ES2_D3D9(),
4738 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004739 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004740 ES2_OPENGLES(),
4741 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004742ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
4743 ES2_D3D9(),
4744 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004745 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004746 ES2_OPENGLES(),
4747 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004748ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
4749 ES2_D3D9(),
4750 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004751 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004752 ES2_OPENGLES(),
4753 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004754ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02004755ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02004756ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4757ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
4758 ES3_D3D11(),
4759 ES3_OPENGL(),
4760 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004761ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
4762 ES3_D3D11(),
4763 ES3_OPENGL(),
4764 ES3_OPENGLES());
4765ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4766ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02004767ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02004768ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
4769 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004770 ES2_D3D9(),
4771 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004772 ES2_OPENGLES(),
4773 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004774ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
4775 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004776 ES2_D3D9(),
4777 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004778 ES2_OPENGLES(),
4779 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004780ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
4781 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004782 ES2_D3D9(),
4783 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004784 ES2_OPENGLES(),
4785 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004786ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
4787 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004788 ES2_D3D9(),
4789 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004790 ES2_OPENGLES(),
4791 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004792ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
4793 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004794 ES2_D3D9(),
4795 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004796 ES2_OPENGLES(),
4797 ES2_VULKAN());
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05004798ANGLE_INSTANTIATE_TEST(TextureAnisotropyTest,
4799 ES2_D3D11(),
4800 ES2_D3D9(),
4801 ES2_OPENGL(),
4802 ES2_OPENGLES(),
4803 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02004804ANGLE_INSTANTIATE_TEST(TextureBorderClampTest,
4805 ES2_D3D11(),
4806 ES2_D3D9(),
4807 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004808 ES2_OPENGLES(),
4809 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02004810ANGLE_INSTANTIATE_TEST(TextureBorderClampTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4811ANGLE_INSTANTIATE_TEST(TextureBorderClampIntegerTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Luc Ferronaf883622018-06-08 15:57:31 -04004812ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN());
Vincent Lang25ab4512016-05-13 18:13:59 +02004813ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03004814ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Anders Leinof6cbe442019-04-18 15:32:07 +03004815ANGLE_INSTANTIATE_TEST(Texture2DIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino60cc7512019-05-06 09:25:27 +03004816ANGLE_INSTANTIATE_TEST(TextureCubeIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leinoe4452442019-05-09 13:29:49 +03004817ANGLE_INSTANTIATE_TEST(TextureCubeIntegerEdgeTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino1b6aded2019-05-20 12:56:34 +03004818ANGLE_INSTANTIATE_TEST(Texture2DIntegerProjectiveOffsetTestES3, ES3_D3D11(), ES3_OPENGL());
Jamie Madillfa05f602015-05-07 13:47:11 -04004819
Jamie Madill7ffdda92016-09-08 13:26:51 -04004820} // anonymous namespace