blob: 4315839998199d3f16de054fbb9f1c677317b292 [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
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001266TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001267{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001268 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001269 EXPECT_GL_ERROR(GL_NO_ERROR);
1270
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001271 setUpProgram();
1272
Jamie Madill50cf2be2018-06-15 09:46:57 -04001273 const GLubyte *pixels[20] = {0};
Jamie Madillf67115c2014-04-22 13:14:05 -04001274 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1275 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001276
Jamie Madillb8149072019-04-30 16:14:44 -04001277 if (IsGLExtensionEnabled("GL_EXT_texture_storage"))
Geoff Langc51642b2016-11-14 16:18:26 -05001278 {
1279 // Create a 1-level immutable texture.
1280 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1281
1282 // Try calling sub image on the second level.
1283 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1284 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1285 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001286}
Geoff Langc41e42d2014-04-28 10:58:16 -04001287
John Bauman18319182016-09-28 14:22:27 -07001288// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1289TEST_P(Texture2DTest, QueryBinding)
1290{
1291 glBindTexture(GL_TEXTURE_2D, 0);
1292 EXPECT_GL_ERROR(GL_NO_ERROR);
1293
1294 GLint textureBinding;
1295 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1296 EXPECT_GL_NO_ERROR();
1297 EXPECT_EQ(0, textureBinding);
1298
1299 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
Jamie Madillb8149072019-04-30 16:14:44 -04001300 if (IsGLExtensionEnabled("GL_OES_EGL_image_external") ||
1301 IsGLExtensionEnabled("GL_NV_EGL_stream_consumer_external"))
John Bauman18319182016-09-28 14:22:27 -07001302 {
1303 EXPECT_GL_NO_ERROR();
1304 EXPECT_EQ(0, textureBinding);
1305 }
1306 else
1307 {
1308 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1309 }
1310}
1311
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001312TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001313{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001314 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001315 EXPECT_GL_ERROR(GL_NO_ERROR);
1316
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001317 setUpProgram();
1318
Geoff Langc41e42d2014-04-28 10:58:16 -04001319 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001320 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001321 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001322 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001323
Jamie Madill50cf2be2018-06-15 09:46:57 -04001324 const GLubyte *pixel[4] = {0};
Geoff Langc41e42d2014-04-28 10:58:16 -04001325
1326 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1327 EXPECT_GL_NO_ERROR();
1328
1329 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1330 EXPECT_GL_NO_ERROR();
1331
1332 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1333 EXPECT_GL_NO_ERROR();
1334}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001335
1336// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001337TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001338{
1339 glActiveTexture(GL_TEXTURE0);
1340 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1341 glActiveTexture(GL_TEXTURE1);
1342 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1343 EXPECT_GL_ERROR(GL_NO_ERROR);
1344
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001345 glUseProgram(mProgram);
1346 glUniform1i(mTexture2DUniformLocation, 0);
1347 glUniform1i(mTextureCubeUniformLocation, 1);
1348 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001349 EXPECT_GL_NO_ERROR();
1350}
Jamie Madill9aca0592014-10-06 16:26:59 -04001351
Olli Etuaho53a2da12016-01-11 15:43:32 +02001352// Test drawing with two texture types accessed from the same shader and check that the result of
1353// drawing is correct.
1354TEST_P(TextureCubeTest, CubeMapDraw)
1355{
1356 GLubyte texData[4];
1357 texData[0] = 0;
1358 texData[1] = 60;
1359 texData[2] = 0;
1360 texData[3] = 255;
1361
1362 glActiveTexture(GL_TEXTURE0);
1363 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1364 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1365
1366 glActiveTexture(GL_TEXTURE1);
1367 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1368 texData[1] = 120;
1369 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1370 texData);
1371 EXPECT_GL_ERROR(GL_NO_ERROR);
1372
1373 glUseProgram(mProgram);
1374 glUniform1i(mTexture2DUniformLocation, 0);
1375 glUniform1i(mTextureCubeUniformLocation, 1);
1376 drawQuad(mProgram, "position", 0.5f);
1377 EXPECT_GL_NO_ERROR();
1378
1379 int px = getWindowWidth() - 1;
1380 int py = 0;
1381 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1382}
1383
Olli Etuaho4644a202016-01-12 15:12:53 +02001384TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1385{
1386 glActiveTexture(GL_TEXTURE0);
1387 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1388 GLubyte texData[4];
1389 texData[0] = 0;
1390 texData[1] = 128;
1391 texData[2] = 0;
1392 texData[3] = 255;
1393 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1394 glUseProgram(mProgram);
1395 glUniform1i(mTexture2DUniformLocation, 0);
1396 drawQuad(mProgram, "position", 0.5f);
1397 EXPECT_GL_NO_ERROR();
1398
1399 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1400}
1401
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001402// Test drawing with two textures passed to the shader in a sampler array.
1403TEST_P(SamplerArrayTest, SamplerArrayDraw)
1404{
1405 testSamplerArrayDraw();
1406}
1407
1408// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1409// user-defined function in the shader.
1410TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1411{
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05001412 // TODO: Diagnose and fix. http://anglebug.com/2955
1413 ANGLE_SKIP_TEST_IF(IsVulkan() && IsAndroid());
1414
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001415 testSamplerArrayDraw();
1416}
1417
Jamie Madill9aca0592014-10-06 16:26:59 -04001418// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001419TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001420{
1421 int px = getWindowWidth() / 2;
1422 int py = getWindowHeight() / 2;
1423
1424 glActiveTexture(GL_TEXTURE0);
1425 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1426
Olli Etuahoa314b612016-03-10 16:43:00 +02001427 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001428
Olli Etuahoa314b612016-03-10 16:43:00 +02001429 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001430 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1431 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1432 glGenerateMipmap(GL_TEXTURE_2D);
1433
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001434 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001435 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001436 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1437 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001438 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001439 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001440
Olli Etuahoa314b612016-03-10 16:43:00 +02001441 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001442
Olli Etuahoa314b612016-03-10 16:43:00 +02001443 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1444 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001445 glGenerateMipmap(GL_TEXTURE_2D);
1446
Olli Etuahoa314b612016-03-10 16:43:00 +02001447 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001448
Olli Etuahoa314b612016-03-10 16:43:00 +02001449 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1450 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001451 glGenerateMipmap(GL_TEXTURE_2D);
1452
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001453 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001454
1455 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001456 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001457}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001458
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001459// Test creating a FBO with a cube map render target, to test an ANGLE bug
1460// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001461TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001462{
Michael Spangd8506c72019-01-29 15:35:09 -05001463 // http://anglebug.com/3145
1464 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
1465
Shahbaz Youssefi0c128e12019-03-25 23:50:14 -04001466 // http://anglebug.com/2822
1467 ANGLE_SKIP_TEST_IF(IsWindows() && IsIntel() && IsVulkan());
1468
Jamie Madill3f3b3582018-09-14 10:38:44 -04001469 GLFramebuffer fbo;
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001470 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1471
1472 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Jamie Madill50cf2be2018-06-15 09:46:57 -04001473 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1474 mTextureCube, 0);
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001475
Corentin Wallez322653b2015-06-17 18:33:56 +02001476 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001477 EXPECT_GL_NO_ERROR();
Jamie Madill3f3b3582018-09-14 10:38:44 -04001478
1479 // Test clearing the six mip faces individually.
1480 std::array<GLColor, 6> faceColors = {{GLColor::red, GLColor::green, GLColor::blue,
1481 GLColor::yellow, GLColor::cyan, GLColor::magenta}};
1482
1483 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1484 {
1485 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1486 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1487
1488 Vector4 clearColorF = faceColors[faceIndex].toNormalizedVector();
1489 glClearColor(clearColorF.x(), clearColorF.y(), clearColorF.z(), clearColorF.w());
1490 glClear(GL_COLOR_BUFFER_BIT);
1491
1492 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex]);
1493 }
1494
1495 // Iterate the faces again to make sure the colors haven't changed.
1496 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1497 {
1498 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1499 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1500 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex])
1501 << "face color " << faceIndex << " shouldn't change";
1502 }
1503}
1504
1505// Tests clearing a cube map with a scissor enabled.
1506TEST_P(TextureCubeTest, CubeMapFBOScissoredClear)
1507{
1508 // TODO(jie.a.chen): Diagnose and fix. http://anglebug.com/2822
1509 ANGLE_SKIP_TEST_IF(IsVulkan() && IsIntel() && IsWindows());
1510
Michael Spangd8506c72019-01-29 15:35:09 -05001511 // http://anglebug.com/3145
1512 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
1513
Jamie Madill3f3b3582018-09-14 10:38:44 -04001514 constexpr size_t kSize = 16;
1515
1516 GLFramebuffer fbo;
1517 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1518 glViewport(0, 0, kSize, kSize);
1519
1520 GLTexture texcube;
1521 glBindTexture(GL_TEXTURE_CUBE_MAP, texcube);
1522 for (GLenum face = 0; face < 6; face++)
1523 {
1524 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA,
1525 GL_UNSIGNED_BYTE, nullptr);
1526 }
1527 ASSERT_GL_NO_ERROR();
1528
1529 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1530 texcube, 0);
1531
1532 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1533 ASSERT_GL_NO_ERROR();
1534
1535 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1536 glClear(GL_COLOR_BUFFER_BIT);
1537 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1538
1539 glEnable(GL_SCISSOR_TEST);
1540 glScissor(kSize / 2, 0, kSize / 2, kSize);
1541 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
1542 glClear(GL_COLOR_BUFFER_BIT);
1543
1544 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1545 EXPECT_PIXEL_COLOR_EQ(kSize / 2 + 1, 0, GLColor::green);
1546
1547 ASSERT_GL_NO_ERROR();
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001548}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001549
Jamie Madill50cf2be2018-06-15 09:46:57 -04001550// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a
1551// default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001552TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001553{
Jamie Madillb8149072019-04-30 16:14:44 -04001554 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 &&
1555 !IsGLExtensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -04001556
Jamie Madill50cf2be2018-06-15 09:46:57 -04001557 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001558 int height = getWindowHeight();
1559
1560 GLuint tex2D;
1561 glGenTextures(1, &tex2D);
1562 glActiveTexture(GL_TEXTURE0);
1563 glBindTexture(GL_TEXTURE_2D, tex2D);
1564
1565 // Fill with red
1566 std::vector<GLubyte> pixels(3 * 16 * 16);
1567 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1568 {
1569 pixels[pixelId * 3 + 0] = 255;
1570 pixels[pixelId * 3 + 1] = 0;
1571 pixels[pixelId * 3 + 2] = 0;
1572 }
1573
1574 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001575 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1576 // 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 -04001577 if (getClientMajorVersion() >= 3)
1578 {
1579 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1580 }
1581 else
1582 {
1583 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1584 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001585
1586 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1587 // glTexSubImage2D should take into account that the image is dirty.
1588 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1589 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1590 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1591
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001592 setUpProgram();
1593
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001594 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001595 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001596 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001597 glDeleteTextures(1, &tex2D);
1598 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001599 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001600
1601 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001602 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1603 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001604}
1605
Jamie Madill50cf2be2018-06-15 09:46:57 -04001606// Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has
1607// initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001608TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001609{
Jamie Madillb8149072019-04-30 16:14:44 -04001610 if (IsGLExtensionEnabled("NV_pixel_buffer_object"))
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001611 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04001612 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001613 int height = getWindowHeight();
1614
1615 GLuint tex2D;
1616 glGenTextures(1, &tex2D);
1617 glActiveTexture(GL_TEXTURE0);
1618 glBindTexture(GL_TEXTURE_2D, tex2D);
1619
1620 // Fill with red
1621 std::vector<GLubyte> pixels(3 * 16 * 16);
1622 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1623 {
1624 pixels[pixelId * 3 + 0] = 255;
1625 pixels[pixelId * 3 + 1] = 0;
1626 pixels[pixelId * 3 + 2] = 0;
1627 }
1628
1629 // Read 16x16 region from red backbuffer to PBO
1630 GLuint pbo;
1631 glGenBuffers(1, &pbo);
1632 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1633 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1634
1635 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001636 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1637 // 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 +00001638 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1639
1640 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1641 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001642 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 +00001643 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1644 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1645
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001646 setUpProgram();
1647
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001648 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001649 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001650 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001651 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001652 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001653 EXPECT_GL_NO_ERROR();
1654 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1655 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1656 }
1657}
Jamie Madillbc393df2015-01-29 13:46:07 -05001658
1659// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001660TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001661{
1662 testFloatCopySubImage(1, 1);
1663}
1664
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001665TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001666{
1667 testFloatCopySubImage(2, 1);
1668}
1669
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001670TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001671{
1672 testFloatCopySubImage(2, 2);
1673}
1674
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001675TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001676{
1677 testFloatCopySubImage(3, 1);
1678}
1679
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001680TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001681{
1682 testFloatCopySubImage(3, 2);
1683}
1684
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001685TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001686{
Yunchao He9550c602018-02-13 14:47:05 +08001687 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1688 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001689
Yunchao He9550c602018-02-13 14:47:05 +08001690 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1691 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001692
Jamie Madillbc393df2015-01-29 13:46:07 -05001693 testFloatCopySubImage(3, 3);
1694}
1695
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001696TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001697{
1698 testFloatCopySubImage(4, 1);
1699}
1700
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001701TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001702{
1703 testFloatCopySubImage(4, 2);
1704}
1705
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001706TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001707{
Yunchao He9550c602018-02-13 14:47:05 +08001708 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1709 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001710
Jamie Madillbc393df2015-01-29 13:46:07 -05001711 testFloatCopySubImage(4, 3);
1712}
1713
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001714TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001715{
Luc Ferronf786b702018-07-10 11:01:43 -04001716 // TODO(lucferron): This test fails only on linux and intel.
1717 // http://anglebug.com/2726
1718 ANGLE_SKIP_TEST_IF(IsVulkan() && IsLinux() && IsIntel());
1719
Yunchao He9550c602018-02-13 14:47:05 +08001720 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1721 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001722
Jamie Madillbc393df2015-01-29 13:46:07 -05001723 testFloatCopySubImage(4, 4);
1724}
Austin Kinross07285142015-03-26 11:36:16 -07001725
Jamie Madill50cf2be2018-06-15 09:46:57 -04001726// Port of
1727// https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1728// Run against GL_ALPHA/UNSIGNED_BYTE format, to ensure that D3D11 Feature Level 9_3 correctly
1729// handles GL_ALPHA
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001730TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001731{
1732 const int npotTexSize = 5;
Jamie Madill50cf2be2018-06-15 09:46:57 -04001733 const int potTexSize = 4; // Should be less than npotTexSize
Austin Kinross07285142015-03-26 11:36:16 -07001734 GLuint tex2D;
1735
Jamie Madillb8149072019-04-30 16:14:44 -04001736 if (IsGLExtensionEnabled("GL_OES_texture_npot"))
Austin Kinross07285142015-03-26 11:36:16 -07001737 {
1738 // This test isn't applicable if texture_npot is enabled
1739 return;
1740 }
1741
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001742 setUpProgram();
1743
Austin Kinross07285142015-03-26 11:36:16 -07001744 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1745
Austin Kinross5faa15b2016-01-11 13:32:48 -08001746 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1747 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1748
Austin Kinross07285142015-03-26 11:36:16 -07001749 glActiveTexture(GL_TEXTURE0);
1750 glGenTextures(1, &tex2D);
1751 glBindTexture(GL_TEXTURE_2D, tex2D);
1752
Till Rathmannc1551dc2018-08-15 17:04:49 +02001753 const std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize, 64);
Austin Kinross07285142015-03-26 11:36:16 -07001754
1755 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1756 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1757
1758 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
Jamie Madill50cf2be2018-06-15 09:46:57 -04001759 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1760 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001761 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1762
1763 // Check that an NPOT texture on level 0 succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001764 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1765 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001766 EXPECT_GL_NO_ERROR();
1767
1768 // Check that generateMipmap fails on NPOT
1769 glGenerateMipmap(GL_TEXTURE_2D);
1770 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1771
1772 // Check that nothing is drawn if filtering is not correct for NPOT
1773 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1774 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1775 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1776 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1777 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001778 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001779 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1780
1781 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1782 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1783 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1784 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1785 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001786 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001787 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1788
1789 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1790 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1791 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001792 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001793 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1794
1795 // Check that glTexImage2D for POT texture succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001796 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE,
1797 pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001798 EXPECT_GL_NO_ERROR();
1799
1800 // Check that generateMipmap for an POT texture succeeds
1801 glGenerateMipmap(GL_TEXTURE_2D);
1802 EXPECT_GL_NO_ERROR();
1803
1804 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1805 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1806 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1807 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1808 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1809 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001810 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001811 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1812 EXPECT_GL_NO_ERROR();
1813}
Jamie Madillfa05f602015-05-07 13:47:11 -04001814
Austin Kinross08528e12015-10-07 16:24:40 -07001815// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1816// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001817TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001818{
1819 glActiveTexture(GL_TEXTURE0);
1820 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1821
1822 // Create an 8x8 (i.e. power-of-two) texture.
1823 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1824 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1825 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1826 glGenerateMipmap(GL_TEXTURE_2D);
1827
1828 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1829 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001830 std::array<GLColor, 3 * 3> data;
1831 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001832
1833 EXPECT_GL_NO_ERROR();
1834}
1835
Geoff Lang3702d8c2019-04-08 13:44:06 -04001836// Regression test for http://crbug.com/949985 to make sure dirty bits are propagated up from
1837// TextureImpl and the texture is synced before being used in a draw call.
1838TEST_P(Texture2DTestES3, TextureImplPropogatesDirtyBits)
1839{
1840 ANGLE_SKIP_TEST_IF(IsIntel() && IsOpenGL());
Yuly Novikove6b23e42019-04-10 17:19:15 -04001841 // Flaky hangs on Win10 AMD RX 550 GL. http://anglebug.com/3371
1842 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsOpenGL());
Geoff Lang3702d8c2019-04-08 13:44:06 -04001843
1844 // The workaround in the GL backend required to trigger this bug generates driver warning
1845 // messages.
1846 ScopedIgnorePlatformMessages ignoreMessages;
1847
1848 setUpProgram();
1849 glUseProgram(mProgram);
1850 glActiveTexture(GL_TEXTURE0 + mTexture2DUniformLocation);
1851
1852 GLTexture dest;
1853 glBindTexture(GL_TEXTURE_2D, dest);
1854
1855 GLTexture source;
1856 glBindTexture(GL_TEXTURE_2D, source);
1857
1858 // Put data in mip 0 and 1
1859 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1860 GLColor::red.data());
1861 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1862 GLColor::green.data());
1863
1864 // Disable mipmapping so source is complete
1865 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1866 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1867
1868 // Force the dirty bits to be synchronized in source
1869 drawQuad(mProgram, "position", 1.0f);
1870
1871 // Copy from mip 1 of the source. In the GL backend this internally sets the base level to mip
1872 // 1 and sets a dirty bit.
1873 glCopyTextureCHROMIUM(source, 1, GL_TEXTURE_2D, dest, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_FALSE,
1874 GL_FALSE, GL_FALSE);
1875
1876 // Draw again, assertions are generated if the texture has internal dirty bits at draw time
1877 drawQuad(mProgram, "position", 1.0f);
1878}
1879
Geoff Lang6f691fb2019-04-25 11:01:52 -04001880// This test case changes the base level of a texture that's attached to a framebuffer, clears every
1881// level to green, and then samples the texture when rendering. Test is taken from
1882// https://www.khronos.org/registry/webgl/sdk/tests/conformance2/rendering/framebuffer-texture-changing-base-level.html
1883TEST_P(Texture2DTestES3, FramebufferTextureChangingBaselevel)
1884{
1885 // TODO(geofflang): Investigate on D3D11. http://anglebug.com/2291
1886 ANGLE_SKIP_TEST_IF(IsD3D11());
1887
1888 setUpProgram();
1889
1890 constexpr GLint width = 8;
1891 constexpr GLint height = 4;
1892
1893 GLTexture texture;
1894 glBindTexture(GL_TEXTURE_2D, texture);
1895 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1896 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1897 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1898 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1899
1900 // Create all mipmap levels for the texture from level 0 to the 1x1 pixel level.
1901 GLint level = 0;
1902 GLint levelW = width;
1903 GLint levelH = height;
1904 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, levelW, levelH, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1905 nullptr);
1906 while (levelW > 1 || levelH > 1)
1907 {
1908 ++level;
1909 levelW = static_cast<GLint>(std::max(1.0, std::floor(width / std::pow(2, level))));
1910 levelH = static_cast<GLint>(std::max(1.0, std::floor(height / std::pow(2, level))));
1911 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, levelW, levelH, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1912 nullptr);
1913 }
1914
1915 // Clear each level of the texture using an FBO. Change the base level to match the level used
1916 // for the FBO on each iteration.
1917 GLFramebuffer fbo;
1918 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1919 level = 0;
1920 levelW = width;
1921 levelH = height;
1922 while (levelW > 1 || levelH > 1)
1923 {
1924 levelW = static_cast<GLint>(std::floor(width / std::pow(2, level)));
1925 levelH = static_cast<GLint>(std::floor(height / std::pow(2, level)));
1926
1927 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, level);
1928 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, level);
1929
1930 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1931 EXPECT_GL_NO_ERROR();
1932
1933 glClearColor(0, 1, 0, 1);
1934 glClear(GL_COLOR_BUFFER_BIT);
1935
1936 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1937
1938 ++level;
1939 }
1940
1941 glBindFramebuffer(GL_FRAMEBUFFER, 0);
1942 glViewport(0, 0, 16, 16);
1943 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
1944
1945 drawQuad(mProgram, "position", 0.5f);
1946
1947 EXPECT_GL_NO_ERROR();
1948 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1949}
1950
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001951// Test to check that texture completeness is determined correctly when the texture base level is
1952// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1953TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1954{
1955 glActiveTexture(GL_TEXTURE0);
1956 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001957
1958 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1959 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1960 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1961 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1962 texDataGreen.data());
1963 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1964 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001965 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1966 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1967 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1968
1969 EXPECT_GL_NO_ERROR();
1970
1971 drawQuad(mProgram, "position", 0.5f);
1972
Olli Etuahoa314b612016-03-10 16:43:00 +02001973 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1974}
1975
1976// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1977// have images defined.
1978TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1979{
Yunchao He9550c602018-02-13 14:47:05 +08001980 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1981 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1982
Olli Etuahoa314b612016-03-10 16:43:00 +02001983 glActiveTexture(GL_TEXTURE0);
1984 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1985 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1986 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1987 texDataGreen.data());
1988 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1989 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1990 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1991 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1992
1993 EXPECT_GL_NO_ERROR();
1994
1995 drawQuad(mProgram, "position", 0.5f);
1996
1997 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1998}
1999
Olli Etuahoe8528d82016-05-16 17:50:52 +03002000// Test that drawing works correctly when level 0 is undefined and base level is 1.
2001TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
2002{
Yunchao He9550c602018-02-13 14:47:05 +08002003 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
2004 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
2005
Olli Etuahoe8528d82016-05-16 17:50:52 +03002006 glActiveTexture(GL_TEXTURE0);
2007 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2008 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2009 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2010 texDataGreen.data());
2011 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2012 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2013 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2014 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2015
2016 EXPECT_GL_NO_ERROR();
2017
2018 // Texture is incomplete.
2019 drawQuad(mProgram, "position", 0.5f);
2020 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2021
2022 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2023 texDataGreen.data());
2024
2025 // Texture is now complete.
2026 drawQuad(mProgram, "position", 0.5f);
2027 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2028}
2029
Olli Etuahoa314b612016-03-10 16:43:00 +02002030// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2031// dimensions that don't fit the images inside the range.
2032// GLES 3.0.4 section 3.8.13 Texture completeness
2033TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2034{
Olli Etuahoa314b612016-03-10 16:43:00 +02002035 glActiveTexture(GL_TEXTURE0);
2036 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2037 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
2038 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2039 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
2040
2041 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2042 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2043
2044 // Two levels that are initially unused.
2045 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
2046 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2047 texDataCyan.data());
2048
2049 // One level that is used - only this level should affect completeness.
2050 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2051 texDataGreen.data());
2052
2053 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2054 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2055
2056 EXPECT_GL_NO_ERROR();
2057
2058 drawQuad(mProgram, "position", 0.5f);
2059
2060 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2061
Yunchao He2f23f352018-02-11 22:11:37 +08002062 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02002063
2064 // Switch the level that is being used to the cyan level 2.
2065 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2066 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2067
2068 EXPECT_GL_NO_ERROR();
2069
2070 drawQuad(mProgram, "position", 0.5f);
2071
2072 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2073}
2074
2075// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2076// have images defined.
2077TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
2078{
Olli Etuahoa314b612016-03-10 16:43:00 +02002079 glActiveTexture(GL_TEXTURE0);
2080 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2081 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2082 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2083 texDataGreen.data());
2084 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2085 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2086 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
2087 glTexParameteri(GL_TEXTURE_3D, 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}
2095
2096// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2097// dimensions that don't fit the images inside the range.
2098// GLES 3.0.4 section 3.8.13 Texture completeness
2099TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2100{
Olli Etuahoa314b612016-03-10 16:43:00 +02002101 glActiveTexture(GL_TEXTURE0);
2102 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2103 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2104 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2105 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2106
2107 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2108 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2109
2110 // Two levels that are initially unused.
2111 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2112 texDataRed.data());
2113 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2114 texDataCyan.data());
2115
2116 // One level that is used - only this level should affect completeness.
2117 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2118 texDataGreen.data());
2119
2120 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
2121 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2122
2123 EXPECT_GL_NO_ERROR();
2124
2125 drawQuad(mProgram, "position", 0.5f);
2126
2127 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2128
Yunchao He2f23f352018-02-11 22:11:37 +08002129 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02002130
2131 // Switch the level that is being used to the cyan level 2.
2132 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
2133 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
2134
2135 EXPECT_GL_NO_ERROR();
2136
2137 drawQuad(mProgram, "position", 0.5f);
2138
2139 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2140}
2141
2142// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2143// have images defined.
2144TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
2145{
Olli Etuahoa314b612016-03-10 16:43:00 +02002146 glActiveTexture(GL_TEXTURE0);
2147 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
2148 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2149 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2150 texDataGreen.data());
2151 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2152 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2153 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2154 glTexParameteri(GL_TEXTURE_2D_ARRAY, 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}
2162
2163// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2164// dimensions that don't fit the images inside the range.
2165// GLES 3.0.4 section 3.8.13 Texture completeness
2166TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2167{
Olli Etuahoa314b612016-03-10 16:43:00 +02002168 glActiveTexture(GL_TEXTURE0);
2169 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
2170 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2171 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2172 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2173
2174 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2175 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2176
2177 // Two levels that are initially unused.
2178 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2179 texDataRed.data());
2180 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2181 texDataCyan.data());
2182
2183 // One level that is used - only this level should affect completeness.
2184 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2185 texDataGreen.data());
2186
2187 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2188 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2189
2190 EXPECT_GL_NO_ERROR();
2191
2192 drawQuad(mProgram, "position", 0.5f);
2193
2194 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2195
Yunchao He2f23f352018-02-11 22:11:37 +08002196 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
2197
Yunchao He9550c602018-02-13 14:47:05 +08002198 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
2199 // level was changed.
2200 ANGLE_SKIP_TEST_IF(IsNVIDIA() && (IsOpenGL() || IsOpenGLES()));
Olli Etuahoa314b612016-03-10 16:43:00 +02002201
2202 // Switch the level that is being used to the cyan level 2.
2203 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2204 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2205
2206 EXPECT_GL_NO_ERROR();
2207
2208 drawQuad(mProgram, "position", 0.5f);
2209
2210 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2211}
2212
2213// Test that texture completeness is updated if texture max level changes.
2214// GLES 3.0.4 section 3.8.13 Texture completeness
2215TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2216{
Olli Etuahoa314b612016-03-10 16:43:00 +02002217 glActiveTexture(GL_TEXTURE0);
2218 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2219 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2220
2221 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2222 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2223
2224 // A level that is initially unused.
2225 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2226 texDataGreen.data());
2227
2228 // One level that is initially used - only this level should affect completeness.
2229 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2230 texDataGreen.data());
2231
2232 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2233 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2234
2235 EXPECT_GL_NO_ERROR();
2236
2237 drawQuad(mProgram, "position", 0.5f);
2238
2239 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2240
2241 // Switch the max level to level 1. The levels within the used range now have inconsistent
2242 // dimensions and the texture should be incomplete.
2243 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2244
2245 EXPECT_GL_NO_ERROR();
2246
2247 drawQuad(mProgram, "position", 0.5f);
2248
2249 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2250}
2251
2252// Test that 3D texture completeness is updated if texture max level changes.
2253// GLES 3.0.4 section 3.8.13 Texture completeness
2254TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2255{
Olli Etuahoa314b612016-03-10 16:43:00 +02002256 glActiveTexture(GL_TEXTURE0);
2257 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2258 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2259
2260 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2261 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2262
2263 // A level that is initially unused.
2264 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2265 texDataGreen.data());
2266
2267 // One level that is initially used - only this level should affect completeness.
2268 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2269 texDataGreen.data());
2270
2271 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2272 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2273
2274 EXPECT_GL_NO_ERROR();
2275
2276 drawQuad(mProgram, "position", 0.5f);
2277
2278 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2279
2280 // Switch the max level to level 1. The levels within the used range now have inconsistent
2281 // dimensions and the texture should be incomplete.
2282 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2283
2284 EXPECT_GL_NO_ERROR();
2285
2286 drawQuad(mProgram, "position", 0.5f);
2287
2288 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2289}
2290
2291// Test that texture completeness is updated if texture base level changes.
2292// GLES 3.0.4 section 3.8.13 Texture completeness
2293TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2294{
Olli Etuahoa314b612016-03-10 16:43:00 +02002295 glActiveTexture(GL_TEXTURE0);
2296 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2297 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2298
2299 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2300 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2301
2302 // Two levels that are initially unused.
2303 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2304 texDataGreen.data());
2305 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2306 texDataGreen.data());
2307
2308 // One level that is initially used - only this level should affect completeness.
2309 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2310 texDataGreen.data());
2311
2312 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2313 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2314
2315 EXPECT_GL_NO_ERROR();
2316
2317 drawQuad(mProgram, "position", 0.5f);
2318
2319 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2320
2321 // Switch the base level to level 1. The levels within the used range now have inconsistent
2322 // dimensions and the texture should be incomplete.
2323 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2324
2325 EXPECT_GL_NO_ERROR();
2326
2327 drawQuad(mProgram, "position", 0.5f);
2328
2329 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2330}
2331
2332// Test that texture is not complete if base level is greater than max level.
2333// GLES 3.0.4 section 3.8.13 Texture completeness
2334TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2335{
Olli Etuahoa314b612016-03-10 16:43:00 +02002336 glActiveTexture(GL_TEXTURE0);
2337 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2338
2339 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2340 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2341
2342 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2343
2344 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2345 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2346
2347 EXPECT_GL_NO_ERROR();
2348
2349 drawQuad(mProgram, "position", 0.5f);
2350
2351 // Texture should be incomplete.
2352 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2353}
2354
2355// Test that immutable texture base level and max level are clamped.
2356// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2357TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2358{
Olli Etuahoa314b612016-03-10 16:43:00 +02002359 glActiveTexture(GL_TEXTURE0);
2360 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2361
2362 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2363 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2364
2365 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2366
2367 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2368
2369 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2370 // should be clamped to [base_level, levels - 1].
2371 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2372 // In the case of this test, those rules make the effective base level and max level 0.
2373 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2374 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2375
2376 EXPECT_GL_NO_ERROR();
2377
2378 drawQuad(mProgram, "position", 0.5f);
2379
2380 // Texture should be complete.
2381 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2382}
2383
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002384// Test that changing base level works when it affects the format of the texture.
2385TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2386{
Yunchao He9550c602018-02-13 14:47:05 +08002387 // Observed rendering corruption on NVIDIA OpenGL.
2388 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL());
2389
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002390 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002391
2392 // Observed incorrect rendering on AMD OpenGL.
2393 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002394
2395 glActiveTexture(GL_TEXTURE0);
2396 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2397 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2398 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2399
2400 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2401 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2402
2403 // RGBA8 level that's initially unused.
2404 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2405 texDataCyan.data());
2406
2407 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2408 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2409
2410 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2411 // format. It reads green channel data from the green and alpha channels of texDataGreen
2412 // (this is a bit hacky but works).
2413 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2414
2415 EXPECT_GL_NO_ERROR();
2416
2417 drawQuad(mProgram, "position", 0.5f);
2418
2419 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2420
2421 // Switch the texture to use the cyan level 0 with the RGBA format.
2422 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2423 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2424
2425 EXPECT_GL_NO_ERROR();
2426
2427 drawQuad(mProgram, "position", 0.5f);
2428
2429 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2430}
2431
Olli Etuahoa314b612016-03-10 16:43:00 +02002432// Test that setting a texture image works when base level is out of range.
2433TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2434{
2435 glActiveTexture(GL_TEXTURE0);
2436 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2437
2438 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2439 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2440
2441 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2442 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2443
2444 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2445
2446 EXPECT_GL_NO_ERROR();
2447
2448 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2449
2450 drawQuad(mProgram, "position", 0.5f);
2451
2452 // Texture should be complete.
2453 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002454}
2455
Jamie Madill50cf2be2018-06-15 09:46:57 -04002456// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG
2457// RBA->RGBA8, with 1.0 in the alpha channel. This test covers a bug where redefining array textures
2458// with these formats does not work as expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002459TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002460{
2461 std::vector<GLubyte> pixelData;
2462 for (size_t count = 0; count < 5000; count++)
2463 {
2464 pixelData.push_back(0u);
2465 pixelData.push_back(255u);
2466 pixelData.push_back(0u);
2467 }
2468
2469 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002470 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002471 glUniform1i(mTextureArrayLocation, 0);
2472
2473 // The first draw worked correctly.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002474 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2475 &pixelData[0]);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002476
2477 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2478 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2479 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2480 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002481 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002482 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002483
2484 // The dimension of the respecification must match the original exactly to trigger the bug.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002485 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2486 &pixelData[0]);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002487 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002488 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002489
2490 ASSERT_GL_NO_ERROR();
2491}
2492
Olli Etuaho1a679902016-01-14 12:21:47 +02002493// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2494// This test is needed especially to confirm that sampler registers get assigned correctly on
2495// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2496TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2497{
2498 glActiveTexture(GL_TEXTURE0);
2499 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2500 GLubyte texData[4];
2501 texData[0] = 0;
2502 texData[1] = 60;
2503 texData[2] = 0;
2504 texData[3] = 255;
2505 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2506
2507 glActiveTexture(GL_TEXTURE1);
2508 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2509 GLfloat depthTexData[1];
2510 depthTexData[0] = 0.5f;
2511 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2512 depthTexData);
2513
2514 glUseProgram(mProgram);
2515 glUniform1f(mDepthRefUniformLocation, 0.3f);
2516 glUniform1i(mTexture3DUniformLocation, 0);
2517 glUniform1i(mTextureShadowUniformLocation, 1);
2518
2519 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2520 drawQuad(mProgram, "position", 0.5f);
2521 EXPECT_GL_NO_ERROR();
2522 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2523 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2524
2525 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2526 drawQuad(mProgram, "position", 0.5f);
2527 EXPECT_GL_NO_ERROR();
2528 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2529 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2530}
2531
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002532// Test multiple different sampler types in the same shader.
2533// This test makes sure that even if sampler / texture registers get grouped together based on type
2534// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2535// still has the right register index information for each ESSL sampler.
2536// The tested ESSL samplers have the following types in D3D11 HLSL:
2537// sampler2D: Texture2D + SamplerState
2538// samplerCube: TextureCube + SamplerState
2539// sampler2DShadow: Texture2D + SamplerComparisonState
2540// samplerCubeShadow: TextureCube + SamplerComparisonState
2541TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2542{
2543 glActiveTexture(GL_TEXTURE0);
2544 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2545 GLubyte texData[4];
2546 texData[0] = 0;
2547 texData[1] = 0;
2548 texData[2] = 120;
2549 texData[3] = 255;
2550 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2551
2552 glActiveTexture(GL_TEXTURE1);
2553 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2554 texData[0] = 0;
2555 texData[1] = 90;
2556 texData[2] = 0;
2557 texData[3] = 255;
2558 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2559 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2560 texData);
2561
2562 glActiveTexture(GL_TEXTURE2);
2563 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2564 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2565 GLfloat depthTexData[1];
2566 depthTexData[0] = 0.5f;
2567 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2568 depthTexData);
2569
2570 glActiveTexture(GL_TEXTURE3);
2571 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2572 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2573 depthTexData[0] = 0.2f;
2574 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2575 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2576 depthTexData);
2577
2578 EXPECT_GL_NO_ERROR();
2579
2580 glUseProgram(mProgram);
2581 glUniform1f(mDepthRefUniformLocation, 0.3f);
2582 glUniform1i(mTexture2DUniformLocation, 0);
2583 glUniform1i(mTextureCubeUniformLocation, 1);
2584 glUniform1i(mTexture2DShadowUniformLocation, 2);
2585 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2586
2587 drawQuad(mProgram, "position", 0.5f);
2588 EXPECT_GL_NO_ERROR();
2589 // The shader writes:
2590 // <texture 2d color> +
2591 // <cube map color> +
2592 // 0.25 * <comparison result (1.0)> +
2593 // 0.125 * <comparison result (0.0)>
2594 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2595}
2596
Olli Etuahobce743a2016-01-15 17:18:28 +02002597// Test different base levels on textures accessed through the same sampler array.
2598// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2599TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2600{
Yunchao He9550c602018-02-13 14:47:05 +08002601 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2602
Olli Etuahobce743a2016-01-15 17:18:28 +02002603 glActiveTexture(GL_TEXTURE0);
2604 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2605 GLsizei size = 64;
2606 for (GLint level = 0; level < 7; ++level)
2607 {
2608 ASSERT_LT(0, size);
2609 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2610 nullptr);
2611 size = size / 2;
2612 }
2613 ASSERT_EQ(0, size);
2614 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2615
2616 glActiveTexture(GL_TEXTURE1);
2617 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2618 size = 128;
2619 for (GLint level = 0; level < 8; ++level)
2620 {
2621 ASSERT_LT(0, size);
2622 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2623 nullptr);
2624 size = size / 2;
2625 }
2626 ASSERT_EQ(0, size);
2627 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2628 EXPECT_GL_NO_ERROR();
2629
2630 glUseProgram(mProgram);
2631 glUniform1i(mTexture0Location, 0);
2632 glUniform1i(mTexture1Location, 1);
2633
Olli Etuaho5804dc82018-04-13 14:11:46 +03002634 drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
Olli Etuahobce743a2016-01-15 17:18:28 +02002635 EXPECT_GL_NO_ERROR();
2636 // Red channel: width of level 1 of texture A: 32.
2637 // Green channel: width of level 3 of texture B: 16.
2638 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2639}
2640
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002641// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2642// ES 3.0.4 table 3.24
2643TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2644{
2645 glActiveTexture(GL_TEXTURE0);
2646 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2647 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2648 EXPECT_GL_NO_ERROR();
2649
2650 drawQuad(mProgram, "position", 0.5f);
2651
2652 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2653}
2654
2655// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2656// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002657TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002658{
Luc Ferron5164b792018-03-06 09:10:12 -05002659 setUpProgram();
2660
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002661 glActiveTexture(GL_TEXTURE0);
2662 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2663 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2664 EXPECT_GL_NO_ERROR();
2665
2666 drawQuad(mProgram, "position", 0.5f);
2667
2668 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2669}
2670
Luc Ferron5164b792018-03-06 09:10:12 -05002671// Validate that every component of the pixel will be equal to the luminance value we've set
2672// and that the alpha channel will be 1 (or 255 to be exact).
2673TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2674{
2675 setUpProgram();
2676
2677 glActiveTexture(GL_TEXTURE0);
2678 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2679 uint8_t pixel = 50;
2680 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2681 EXPECT_GL_NO_ERROR();
2682
2683 drawQuad(mProgram, "position", 0.5f);
2684
2685 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2686}
2687
2688// Validate that every component of the pixel will be equal to the luminance value we've set
2689// and that the alpha channel will be the second component.
2690TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2691{
2692 setUpProgram();
2693
2694 glActiveTexture(GL_TEXTURE0);
2695 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2696 uint8_t pixel[] = {50, 25};
2697 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2698 GL_UNSIGNED_BYTE, pixel);
2699 EXPECT_GL_NO_ERROR();
2700
2701 drawQuad(mProgram, "position", 0.5f);
2702
2703 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2704}
2705
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002706// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2707// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002708TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002709{
Jamie Madillb8149072019-04-30 16:14:44 -04002710 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002711 ANGLE_SKIP_TEST_IF(IsD3D9());
2712 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002713
2714 setUpProgram();
2715
Luc Ferrond8c632c2018-04-10 12:31:44 -04002716 glActiveTexture(GL_TEXTURE0);
2717 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2718 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2719 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002720
Luc Ferrond8c632c2018-04-10 12:31:44 -04002721 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002722
Luc Ferrond8c632c2018-04-10 12:31:44 -04002723 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002724}
2725
2726// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2727// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002728TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002729{
Jamie Madillb8149072019-04-30 16:14:44 -04002730 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002731 ANGLE_SKIP_TEST_IF(IsD3D9());
2732 ANGLE_SKIP_TEST_IF(IsVulkan());
2733 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES());
2734 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2735 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002736
Luc Ferrond8c632c2018-04-10 12:31:44 -04002737 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002738
Luc Ferrond8c632c2018-04-10 12:31:44 -04002739 glActiveTexture(GL_TEXTURE0);
2740 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2741 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2742 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002743
Luc Ferrond8c632c2018-04-10 12:31:44 -04002744 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002745
Luc Ferrond8c632c2018-04-10 12:31:44 -04002746 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002747}
2748
2749// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2750// ES 3.0.4 table 3.24
2751TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2752{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002753 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2754
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002755 glActiveTexture(GL_TEXTURE0);
2756 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2757 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2758 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2759 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2760 EXPECT_GL_NO_ERROR();
2761
2762 drawQuad(mProgram, "position", 0.5f);
2763
2764 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2765}
2766
2767// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2768// ES 3.0.4 table 3.24
2769TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2770{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002771 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2772
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002773 glActiveTexture(GL_TEXTURE0);
2774 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2775
2776 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2777 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2778 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2779 EXPECT_GL_NO_ERROR();
2780
2781 drawQuad(mProgram, "position", 0.5f);
2782
2783 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2784}
2785
2786// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2787// ES 3.0.4 table 3.24
2788TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2789{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002790 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2791
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002792 glActiveTexture(GL_TEXTURE0);
2793 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2794 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2795 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2796 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2797 EXPECT_GL_NO_ERROR();
2798
2799 drawQuad(mProgram, "position", 0.5f);
2800
2801 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2802}
2803
2804// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2805// ES 3.0.4 table 3.24
2806TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2807{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002808 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2809
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002810 glActiveTexture(GL_TEXTURE0);
2811 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2812 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2813 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2814 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2815 EXPECT_GL_NO_ERROR();
2816
2817 drawQuad(mProgram, "position", 0.5f);
2818
2819 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2820}
2821
2822// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2823// ES 3.0.4 table 3.24
2824TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2825{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002826 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2827
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002828 glActiveTexture(GL_TEXTURE0);
2829 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2830 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2831 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2832 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2833 EXPECT_GL_NO_ERROR();
2834
2835 drawQuad(mProgram, "position", 0.5f);
2836
2837 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2838}
2839
2840// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2841// ES 3.0.4 table 3.24
2842TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2843{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002844 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2845
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002846 glActiveTexture(GL_TEXTURE0);
2847 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2848 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2849 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2850 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2851 EXPECT_GL_NO_ERROR();
2852
2853 drawQuad(mProgram, "position", 0.5f);
2854
2855 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2856}
2857
2858// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2859// ES 3.0.4 table 3.24
2860TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2861{
2862 glActiveTexture(GL_TEXTURE0);
2863 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2864 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2865 EXPECT_GL_NO_ERROR();
2866
2867 drawQuad(mProgram, "position", 0.5f);
2868
2869 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2870}
2871
2872// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2873// ES 3.0.4 table 3.24
2874TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2875{
2876 glActiveTexture(GL_TEXTURE0);
2877 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2878 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2879 nullptr);
2880 EXPECT_GL_NO_ERROR();
2881
2882 drawQuad(mProgram, "position", 0.5f);
2883
2884 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2885}
2886
2887// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2888// ES 3.0.4 table 3.24
2889TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2890{
Yunchao He9550c602018-02-13 14:47:05 +08002891 // Seems to fail on OSX 10.12 Intel.
2892 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Jamie Madillbb1db482017-01-10 10:48:32 -05002893
Yuly Novikov49886892018-01-23 21:18:27 -05002894 // http://anglebug.com/2190
2895 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2896
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002897 glActiveTexture(GL_TEXTURE0);
2898 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2899 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2900 EXPECT_GL_NO_ERROR();
2901
2902 drawQuad(mProgram, "position", 0.5f);
2903
2904 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2905}
2906
2907// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2908// ES 3.0.4 table 3.24
2909TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2910{
Yunchao He9550c602018-02-13 14:47:05 +08002911 // Seems to fail on OSX 10.12 Intel.
2912 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002913
Yuly Novikov49886892018-01-23 21:18:27 -05002914 // http://anglebug.com/2190
2915 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2916
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002917 glActiveTexture(GL_TEXTURE0);
2918 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2919 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2920 EXPECT_GL_NO_ERROR();
2921
2922 drawQuad(mProgram, "position", 0.5f);
2923
2924 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2925}
2926
Olli Etuaho96963162016-03-21 11:54:33 +02002927// Use a sampler in a uniform struct.
2928TEST_P(SamplerInStructTest, SamplerInStruct)
2929{
2930 runSamplerInStructTest();
2931}
2932
2933// Use a sampler in a uniform struct that's passed as a function parameter.
2934TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2935{
Yuly Novikovd18c0482019-04-04 19:56:43 -04002936 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
2937 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002938
Olli Etuaho96963162016-03-21 11:54:33 +02002939 runSamplerInStructTest();
2940}
2941
2942// Use a sampler in a uniform struct array with a struct from the array passed as a function
2943// parameter.
2944TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2945{
Yuly Novikovd18c0482019-04-04 19:56:43 -04002946 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
2947 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08002948
Olli Etuaho96963162016-03-21 11:54:33 +02002949 runSamplerInStructTest();
2950}
2951
2952// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2953// parameter.
2954TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2955{
Yuly Novikovd18c0482019-04-04 19:56:43 -04002956 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
2957 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08002958
Olli Etuaho96963162016-03-21 11:54:33 +02002959 runSamplerInStructTest();
2960}
2961
2962// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2963// similarly named uniform.
2964TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2965{
2966 runSamplerInStructTest();
2967}
2968
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05002969// GL_EXT_texture_filter_anisotropic
2970class TextureAnisotropyTest : public Texture2DTest
2971{
2972 protected:
2973 void uploadTexture()
2974 {
2975 glActiveTexture(GL_TEXTURE0);
2976 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2977 GLColor texDataRed[1] = {GLColor::red};
2978 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed);
2979 EXPECT_GL_NO_ERROR();
2980 }
2981};
2982
2983// Tests that setting anisotropic filtering doesn't cause failures at draw time.
2984TEST_P(TextureAnisotropyTest, AnisotropyFunctional)
2985{
Jamie Madillb8149072019-04-30 16:14:44 -04002986 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_filter_anisotropic"));
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05002987
2988 setUpProgram();
2989
2990 uploadTexture();
2991
2992 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2993 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2994 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f);
2995 EXPECT_GL_NO_ERROR();
2996
2997 drawQuad(mProgram, "position", 0.5f);
2998
2999 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3000 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3001 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::red);
3002}
3003
Till Rathmannb8543632018-10-02 19:46:14 +02003004// GL_OES_texture_border_clamp
3005class TextureBorderClampTest : public Texture2DTest
3006{
3007 protected:
3008 TextureBorderClampTest() : Texture2DTest() {}
3009
Jamie Madill35cd7332018-12-02 12:03:33 -05003010 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003011 {
3012 return
3013 R"(precision highp float;
3014 attribute vec4 position;
3015 varying vec2 texcoord;
3016
3017 void main()
3018 {
3019 gl_Position = vec4(position.xy, 0.0, 1.0);
3020 // texcoords in [-0.5, 1.5]
3021 texcoord = (position.xy) + 0.5;
3022 })";
3023 }
3024
3025 void uploadTexture()
3026 {
3027 glActiveTexture(GL_TEXTURE0);
3028 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3029 std::vector<GLColor> texDataRed(1, GLColor::red);
3030 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3031 texDataRed.data());
3032 EXPECT_GL_NO_ERROR();
3033 }
3034};
3035
3036// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3037// GL_CLAMP_TO_BORDER wrap mode (set with glTexParameter).
3038TEST_P(TextureBorderClampTest, TextureBorderClampFunctional)
3039{
Jamie Madillb8149072019-04-30 16:14:44 -04003040 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003041
3042 setUpProgram();
3043
3044 uploadTexture();
3045
3046 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3047 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3048 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3049 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3050 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3051 EXPECT_GL_NO_ERROR();
3052
3053 drawQuad(mProgram, "position", 0.5f);
3054
3055 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3056 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3057 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3058}
3059
3060// Test reading back GL_TEXTURE_BORDER_COLOR by glGetTexParameter.
3061TEST_P(TextureBorderClampTest, TextureBorderClampFunctional2)
3062{
Jamie Madillb8149072019-04-30 16:14:44 -04003063 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003064
3065 glActiveTexture(GL_TEXTURE0);
3066 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3067
3068 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3069
3070 GLint colorFixedPoint[4] = {0};
3071 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3072 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3073 std::numeric_limits<GLint>::max()};
3074 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3075 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3076 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3077 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3078
3079 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3080 std::numeric_limits<GLint>::max()};
3081 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3082
3083 GLfloat color[4] = {0.0f};
3084 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
3085 EXPECT_EQ(color[0], kFloatBlue.R);
3086 EXPECT_EQ(color[1], kFloatBlue.G);
3087 EXPECT_EQ(color[2], kFloatBlue.B);
3088 EXPECT_EQ(color[3], kFloatBlue.A);
3089}
3090
3091// Test GL_TEXTURE_BORDER_COLOR parameter validation at glTexParameter.
3092TEST_P(TextureBorderClampTest, TextureBorderClampValidation)
3093{
Jamie Madillb8149072019-04-30 16:14:44 -04003094 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003095
3096 glActiveTexture(GL_TEXTURE0);
3097 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3098
3099 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, 1.0f);
3100 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3101
3102 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3103 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3104
3105 glTexParameterfv(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3106 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3107
3108 GLint colorInt[4] = {0};
3109 glTexParameteriv(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_BORDER_COLOR, colorInt);
3110 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3111
3112 if (getClientMajorVersion() < 3)
3113 {
3114 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3115 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3116 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3117 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3118
3119 GLuint colorUInt[4] = {0};
3120 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3121 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3122 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3123 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3124
3125 GLSampler sampler;
3126 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3127 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3128 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3129 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3130
3131 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3132 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3133 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3134 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3135 }
3136}
3137
3138class TextureBorderClampTestES3 : public TextureBorderClampTest
3139{
3140 protected:
3141 TextureBorderClampTestES3() : TextureBorderClampTest() {}
3142};
3143
3144// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3145// GL_CLAMP_TO_BORDER wrap mode (set with glSamplerParameter).
3146TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional)
3147{
Jamie Madillb8149072019-04-30 16:14:44 -04003148 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003149
3150 setUpProgram();
3151
3152 uploadTexture();
3153
3154 GLSampler sampler;
3155 glBindSampler(0, sampler);
3156 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3157 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3158 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3159 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3160 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3161 EXPECT_GL_NO_ERROR();
3162
3163 drawQuad(mProgram, "position", 0.5f);
3164
3165 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3166 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3167 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3168}
3169
3170// Test reading back GL_TEXTURE_BORDER_COLOR by glGetSamplerParameter.
3171TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional2)
3172{
Jamie Madillb8149072019-04-30 16:14:44 -04003173 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003174
3175 glActiveTexture(GL_TEXTURE0);
3176
3177 GLSampler sampler;
3178 glBindSampler(0, sampler);
3179
3180 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3181
3182 GLint colorFixedPoint[4] = {0};
3183 glGetSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3184 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3185 std::numeric_limits<GLint>::max()};
3186 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3187 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3188 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3189 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3190
3191 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3192 std::numeric_limits<GLint>::max()};
3193 glSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3194
3195 GLfloat color[4] = {0.0f};
3196 glGetSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, color);
3197 EXPECT_EQ(color[0], kFloatBlue.R);
3198 EXPECT_EQ(color[1], kFloatBlue.G);
3199 EXPECT_EQ(color[2], kFloatBlue.B);
3200 EXPECT_EQ(color[3], kFloatBlue.A);
3201
3202 constexpr GLint colorSomewhatRedInt[4] = {500000, 0, 0, std::numeric_limits<GLint>::max()};
3203 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedInt);
3204 GLint colorInt[4] = {0};
3205 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3206 EXPECT_EQ(colorInt[0], colorSomewhatRedInt[0]);
3207 EXPECT_EQ(colorInt[1], colorSomewhatRedInt[1]);
3208 EXPECT_EQ(colorInt[2], colorSomewhatRedInt[2]);
3209 EXPECT_EQ(colorInt[3], colorSomewhatRedInt[3]);
3210
3211 constexpr GLuint colorSomewhatRedUInt[4] = {500000, 0, 0, std::numeric_limits<GLuint>::max()};
3212 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedUInt);
3213 GLuint colorUInt[4] = {0};
3214 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3215 EXPECT_EQ(colorUInt[0], colorSomewhatRedUInt[0]);
3216 EXPECT_EQ(colorUInt[1], colorSomewhatRedUInt[1]);
3217 EXPECT_EQ(colorUInt[2], colorSomewhatRedUInt[2]);
3218 EXPECT_EQ(colorUInt[3], colorSomewhatRedUInt[3]);
3219
3220 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3221
3222 constexpr GLint colorSomewhatGreenInt[4] = {0, 500000, 0, std::numeric_limits<GLint>::max()};
3223 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenInt);
3224 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3225 EXPECT_EQ(colorInt[0], colorSomewhatGreenInt[0]);
3226 EXPECT_EQ(colorInt[1], colorSomewhatGreenInt[1]);
3227 EXPECT_EQ(colorInt[2], colorSomewhatGreenInt[2]);
3228 EXPECT_EQ(colorInt[3], colorSomewhatGreenInt[3]);
3229
3230 constexpr GLuint colorSomewhatGreenUInt[4] = {0, 500000, 0, std::numeric_limits<GLuint>::max()};
3231 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenUInt);
3232 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3233 EXPECT_EQ(colorUInt[0], colorSomewhatGreenUInt[0]);
3234 EXPECT_EQ(colorUInt[1], colorSomewhatGreenUInt[1]);
3235 EXPECT_EQ(colorUInt[2], colorSomewhatGreenUInt[2]);
3236 EXPECT_EQ(colorUInt[3], colorSomewhatGreenUInt[3]);
3237}
3238
3239// Test GL_TEXTURE_BORDER_COLOR parameter validation at glSamplerParameter.
3240TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Validation)
3241{
Jamie Madillb8149072019-04-30 16:14:44 -04003242 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003243
3244 glActiveTexture(GL_TEXTURE0);
3245
3246 GLSampler sampler;
3247 glBindSampler(0, sampler);
3248
3249 glSamplerParameterf(sampler, GL_TEXTURE_BORDER_COLOR, 1.0f);
3250 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3251
3252 glSamplerParameteri(sampler, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3253 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3254}
3255
3256class TextureBorderClampIntegerTestES3 : public Texture2DTest
3257{
3258 protected:
3259 TextureBorderClampIntegerTestES3() : Texture2DTest(), isUnsignedIntTest(false) {}
3260
Jamie Madill35cd7332018-12-02 12:03:33 -05003261 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003262 {
3263 return
3264 R"(#version 300 es
3265 out vec2 texcoord;
3266 in vec4 position;
3267
3268 void main()
3269 {
3270 gl_Position = vec4(position.xy, 0.0, 1.0);
3271 // texcoords in [-0.5, 1.5]
3272 texcoord = (position.xy) + 0.5;
3273 })";
3274 }
3275
Jamie Madillba319ba2018-12-29 10:29:33 -05003276 const char *getFragmentShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003277 {
Jamie Madill35cd7332018-12-02 12:03:33 -05003278 if (isUnsignedIntTest)
3279 {
3280 return "#version 300 es\n"
3281 "precision highp float;\n"
3282 "uniform highp usampler2D tex;\n"
3283 "in vec2 texcoord;\n"
3284 "out vec4 fragColor;\n"
Till Rathmannb8543632018-10-02 19:46:14 +02003285
Jamie Madill35cd7332018-12-02 12:03:33 -05003286 "void main()\n"
3287 "{\n"
3288 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3289 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3290 "fragColor = (texture(tex, texcoord).r == 150u)"
3291 " ? green : red;\n"
3292 "}\n";
3293 }
3294 else
3295 {
3296 return "#version 300 es\n"
3297 "precision highp float;\n"
3298 "uniform highp isampler2D tex;\n"
3299 "in vec2 texcoord;\n"
3300 "out vec4 fragColor;\n"
3301
3302 "void main()\n"
3303 "{\n"
3304 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3305 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3306 "fragColor = (texture(tex, texcoord).r == -50)"
3307 " ? green : red;\n"
3308 "}\n";
3309 }
Till Rathmannb8543632018-10-02 19:46:14 +02003310 }
3311
3312 void uploadTexture()
3313 {
3314 glActiveTexture(GL_TEXTURE0);
3315 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3316 if (isUnsignedIntTest)
3317 {
3318 std::vector<GLubyte> texData(4, 100);
3319 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE,
3320 texData.data());
3321 }
3322 else
3323 {
3324 std::vector<GLbyte> texData(4, 100);
3325 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8I, 1, 1, 0, GL_RGBA_INTEGER, GL_BYTE,
3326 texData.data());
3327 }
3328 EXPECT_GL_NO_ERROR();
3329 }
3330
3331 bool isUnsignedIntTest;
3332};
3333
3334// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3335// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3336TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger)
3337{
Jamie Madillb8149072019-04-30 16:14:44 -04003338 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003339
3340 setUpProgram();
3341
3342 uploadTexture();
3343
3344 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3345 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3346 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3347 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3348
3349 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3350 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3351
3352 EXPECT_GL_NO_ERROR();
3353
3354 drawQuad(mProgram, "position", 0.5f);
3355
3356 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3357 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3358 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3359}
3360
3361// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3362// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3363TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger2)
3364{
Jamie Madillb8149072019-04-30 16:14:44 -04003365 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003366
3367 setUpProgram();
3368
3369 uploadTexture();
3370
3371 GLSampler sampler;
3372 glBindSampler(0, sampler);
3373 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3374 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3375 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3376 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3377
3378 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3379 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3380
3381 EXPECT_GL_NO_ERROR();
3382
3383 drawQuad(mProgram, "position", 0.5f);
3384
3385 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3386 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3387 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3388}
3389
3390// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3391// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIuivOES).
3392TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned)
3393{
Jamie Madillb8149072019-04-30 16:14:44 -04003394 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003395
3396 isUnsignedIntTest = true;
3397
3398 setUpProgram();
3399
3400 uploadTexture();
3401
3402 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3403 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3404 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3405 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3406
3407 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3408 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3409
3410 EXPECT_GL_NO_ERROR();
3411
3412 drawQuad(mProgram, "position", 0.5f);
3413
3414 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3415 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3416 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3417}
3418
3419// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3420// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with
3421// glSamplerParameterIuivOES).
3422TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned2)
3423{
Jamie Madillb8149072019-04-30 16:14:44 -04003424 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003425
3426 isUnsignedIntTest = true;
3427
3428 setUpProgram();
3429
3430 uploadTexture();
3431
3432 GLSampler sampler;
3433 glBindSampler(0, sampler);
3434 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3435 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3436 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3437 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3438
3439 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3440 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3441
3442 EXPECT_GL_NO_ERROR();
3443
3444 drawQuad(mProgram, "position", 0.5f);
3445
3446 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3447 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3448 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3449}
3450
3451// ~GL_OES_texture_border_clamp
3452
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003453class TextureLimitsTest : public ANGLETest
3454{
3455 protected:
3456 struct RGBA8
3457 {
3458 uint8_t R, G, B, A;
3459 };
3460
3461 TextureLimitsTest()
3462 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
3463 {
3464 setWindowWidth(128);
3465 setWindowHeight(128);
3466 setConfigRedBits(8);
3467 setConfigGreenBits(8);
3468 setConfigBlueBits(8);
3469 setConfigAlphaBits(8);
3470 }
3471
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003472 void testSetUp() override
Jamie Madill0fdb9562018-09-17 17:18:43 -04003473 {
Jamie Madill0fdb9562018-09-17 17:18:43 -04003474 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
3475 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
3476 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
3477
3478 ASSERT_GL_NO_ERROR();
3479 }
3480
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003481 void testTearDown() override
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003482 {
3483 if (mProgram != 0)
3484 {
3485 glDeleteProgram(mProgram);
3486 mProgram = 0;
3487
3488 if (!mTextures.empty())
3489 {
3490 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
3491 }
3492 }
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003493 }
3494
3495 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
3496 GLint vertexTextureCount,
3497 GLint vertexActiveTextureCount,
3498 const std::string &fragPrefix,
3499 GLint fragmentTextureCount,
3500 GLint fragmentActiveTextureCount)
3501 {
3502 std::stringstream vertexShaderStr;
3503 vertexShaderStr << "attribute vec2 position;\n"
3504 << "varying vec4 color;\n"
3505 << "varying vec2 texCoord;\n";
3506
3507 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
3508 {
3509 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
3510 }
3511
3512 vertexShaderStr << "void main() {\n"
3513 << " gl_Position = vec4(position, 0, 1);\n"
3514 << " texCoord = (position * 0.5) + 0.5;\n"
3515 << " color = vec4(0);\n";
3516
3517 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
3518 {
3519 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
3520 << ", texCoord);\n";
3521 }
3522
3523 vertexShaderStr << "}";
3524
3525 std::stringstream fragmentShaderStr;
3526 fragmentShaderStr << "varying mediump vec4 color;\n"
3527 << "varying mediump vec2 texCoord;\n";
3528
3529 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
3530 {
3531 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
3532 }
3533
3534 fragmentShaderStr << "void main() {\n"
3535 << " gl_FragColor = color;\n";
3536
3537 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
3538 {
3539 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
3540 << ", texCoord);\n";
3541 }
3542
3543 fragmentShaderStr << "}";
3544
3545 const std::string &vertexShaderSource = vertexShaderStr.str();
3546 const std::string &fragmentShaderSource = fragmentShaderStr.str();
3547
Jamie Madill35cd7332018-12-02 12:03:33 -05003548 mProgram = CompileProgram(vertexShaderSource.c_str(), fragmentShaderSource.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003549 }
3550
3551 RGBA8 getPixel(GLint texIndex)
3552 {
3553 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3554 0, 255u};
3555 return pixel;
3556 }
3557
3558 void initTextures(GLint tex2DCount, GLint texCubeCount)
3559 {
3560 GLint totalCount = tex2DCount + texCubeCount;
3561 mTextures.assign(totalCount, 0);
3562 glGenTextures(totalCount, &mTextures[0]);
3563 ASSERT_GL_NO_ERROR();
3564
3565 std::vector<RGBA8> texData(16 * 16);
3566
3567 GLint texIndex = 0;
3568 for (; texIndex < tex2DCount; ++texIndex)
3569 {
3570 texData.assign(texData.size(), getPixel(texIndex));
3571 glActiveTexture(GL_TEXTURE0 + texIndex);
3572 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3573 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3574 &texData[0]);
3575 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3576 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3577 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3578 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3579 }
3580
3581 ASSERT_GL_NO_ERROR();
3582
3583 for (; texIndex < texCubeCount; ++texIndex)
3584 {
3585 texData.assign(texData.size(), getPixel(texIndex));
3586 glActiveTexture(GL_TEXTURE0 + texIndex);
3587 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3588 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3589 GL_UNSIGNED_BYTE, &texData[0]);
3590 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3591 GL_UNSIGNED_BYTE, &texData[0]);
3592 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3593 GL_UNSIGNED_BYTE, &texData[0]);
3594 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3595 GL_UNSIGNED_BYTE, &texData[0]);
3596 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3597 GL_UNSIGNED_BYTE, &texData[0]);
3598 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3599 GL_UNSIGNED_BYTE, &texData[0]);
3600 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3601 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3602 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3603 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3604 }
3605
3606 ASSERT_GL_NO_ERROR();
3607 }
3608
3609 void testWithTextures(GLint vertexTextureCount,
3610 const std::string &vertexTexturePrefix,
3611 GLint fragmentTextureCount,
3612 const std::string &fragmentTexturePrefix)
3613 {
3614 // Generate textures
3615 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3616
3617 glUseProgram(mProgram);
3618 RGBA8 expectedSum = {0};
3619 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3620 {
3621 std::stringstream uniformNameStr;
3622 uniformNameStr << vertexTexturePrefix << texIndex;
3623 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003624 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003625 ASSERT_NE(-1, location);
3626
3627 glUniform1i(location, texIndex);
3628 RGBA8 contribution = getPixel(texIndex);
3629 expectedSum.R += contribution.R;
3630 expectedSum.G += contribution.G;
3631 }
3632
3633 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3634 {
3635 std::stringstream uniformNameStr;
3636 uniformNameStr << fragmentTexturePrefix << texIndex;
3637 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003638 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003639 ASSERT_NE(-1, location);
3640
3641 glUniform1i(location, texIndex + vertexTextureCount);
3642 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3643 expectedSum.R += contribution.R;
3644 expectedSum.G += contribution.G;
3645 }
3646
3647 ASSERT_GE(256u, expectedSum.G);
3648
3649 drawQuad(mProgram, "position", 0.5f);
3650 ASSERT_GL_NO_ERROR();
3651 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3652 }
3653
3654 GLuint mProgram;
3655 std::vector<GLuint> mTextures;
3656 GLint mMaxVertexTextures;
3657 GLint mMaxFragmentTextures;
3658 GLint mMaxCombinedTextures;
3659};
3660
3661// Test rendering with the maximum vertex texture units.
3662TEST_P(TextureLimitsTest, MaxVertexTextures)
3663{
3664 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3665 ASSERT_NE(0u, mProgram);
3666 ASSERT_GL_NO_ERROR();
3667
3668 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3669}
3670
3671// Test rendering with the maximum fragment texture units.
3672TEST_P(TextureLimitsTest, MaxFragmentTextures)
3673{
3674 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3675 ASSERT_NE(0u, mProgram);
3676 ASSERT_GL_NO_ERROR();
3677
3678 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3679}
3680
3681// Test rendering with maximum combined texture units.
3682TEST_P(TextureLimitsTest, MaxCombinedTextures)
3683{
3684 GLint vertexTextures = mMaxVertexTextures;
3685
3686 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3687 {
3688 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3689 }
3690
3691 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3692 mMaxFragmentTextures, mMaxFragmentTextures);
3693 ASSERT_NE(0u, mProgram);
3694 ASSERT_GL_NO_ERROR();
3695
3696 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3697}
3698
3699// Negative test for exceeding the number of vertex textures
3700TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3701{
3702 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3703 0);
3704 ASSERT_EQ(0u, mProgram);
3705}
3706
3707// Negative test for exceeding the number of fragment textures
3708TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3709{
3710 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3711 mMaxFragmentTextures + 1);
3712 ASSERT_EQ(0u, mProgram);
3713}
3714
3715// Test active vertex textures under the limit, but excessive textures specified.
3716TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3717{
3718 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3719 ASSERT_NE(0u, mProgram);
3720 ASSERT_GL_NO_ERROR();
3721
3722 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3723}
3724
3725// Test active fragment textures under the limit, but excessive textures specified.
3726TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3727{
3728 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3729 mMaxFragmentTextures);
3730 ASSERT_NE(0u, mProgram);
3731 ASSERT_GL_NO_ERROR();
3732
3733 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3734}
3735
3736// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003737// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003738TEST_P(TextureLimitsTest, TextureTypeConflict)
3739{
Jamie Madill35cd7332018-12-02 12:03:33 -05003740 constexpr char kVS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003741 "attribute vec2 position;\n"
3742 "varying float color;\n"
3743 "uniform sampler2D tex2D;\n"
3744 "uniform samplerCube texCube;\n"
3745 "void main() {\n"
3746 " gl_Position = vec4(position, 0, 1);\n"
3747 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3748 " color = texture2D(tex2D, texCoord).x;\n"
3749 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3750 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05003751 constexpr char kFS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003752 "varying mediump float color;\n"
3753 "void main() {\n"
3754 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3755 "}";
3756
Jamie Madill35cd7332018-12-02 12:03:33 -05003757 mProgram = CompileProgram(kVS, kFS);
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003758 ASSERT_NE(0u, mProgram);
3759
3760 initTextures(1, 0);
3761
3762 glUseProgram(mProgram);
3763 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3764 ASSERT_NE(-1, tex2DLocation);
3765 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3766 ASSERT_NE(-1, texCubeLocation);
3767
3768 glUniform1i(tex2DLocation, 0);
3769 glUniform1i(texCubeLocation, 0);
3770 ASSERT_GL_NO_ERROR();
3771
3772 drawQuad(mProgram, "position", 0.5f);
3773 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3774}
3775
Vincent Lang25ab4512016-05-13 18:13:59 +02003776class Texture2DNorm16TestES3 : public Texture2DTestES3
3777{
3778 protected:
3779 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3780
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003781 void testSetUp() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003782 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003783 Texture2DTestES3::testSetUp();
Vincent Lang25ab4512016-05-13 18:13:59 +02003784
3785 glActiveTexture(GL_TEXTURE0);
3786 glGenTextures(3, mTextures);
3787 glGenFramebuffers(1, &mFBO);
3788 glGenRenderbuffers(1, &mRenderbuffer);
3789
3790 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3791 {
3792 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3793 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3794 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3795 }
3796
3797 glBindTexture(GL_TEXTURE_2D, 0);
3798
3799 ASSERT_GL_NO_ERROR();
3800 }
3801
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003802 void testTearDown() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003803 {
3804 glDeleteTextures(3, mTextures);
3805 glDeleteFramebuffers(1, &mFBO);
3806 glDeleteRenderbuffers(1, &mRenderbuffer);
3807
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003808 Texture2DTestES3::testTearDown();
Vincent Lang25ab4512016-05-13 18:13:59 +02003809 }
3810
3811 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3812 {
Geoff Langf607c602016-09-21 11:46:48 -04003813 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3814 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003815
3816 setUpProgram();
3817
3818 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3819 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3820 0);
3821
3822 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3823 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3824
3825 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003826 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003827
3828 EXPECT_GL_NO_ERROR();
3829
3830 drawQuad(mProgram, "position", 0.5f);
3831
Geoff Langf607c602016-09-21 11:46:48 -04003832 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003833
Jamie Madill50cf2be2018-06-15 09:46:57 -04003834 EXPECT_PIXEL_COLOR_EQ(0, 0,
3835 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3836 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003837
3838 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3839
3840 ASSERT_GL_NO_ERROR();
3841 }
3842
3843 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3844 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04003845 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003846 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003847
3848 setUpProgram();
3849
3850 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3851 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3852
3853 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3854 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3855 0);
3856
3857 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003858 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003859
3860 EXPECT_GL_NO_ERROR();
3861
3862 drawQuad(mProgram, "position", 0.5f);
3863
Geoff Langf607c602016-09-21 11:46:48 -04003864 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
Jamie Madill50cf2be2018-06-15 09:46:57 -04003865 EXPECT_PIXEL_COLOR_EQ(0, 0,
3866 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3867 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003868
3869 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3870 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3871 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3872 mRenderbuffer);
3873 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3874 EXPECT_GL_NO_ERROR();
3875
3876 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3877 glClear(GL_COLOR_BUFFER_BIT);
3878
3879 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3880
Geoff Langf607c602016-09-21 11:46:48 -04003881 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003882
3883 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3884
3885 ASSERT_GL_NO_ERROR();
3886 }
3887
3888 GLuint mTextures[3];
3889 GLuint mFBO;
3890 GLuint mRenderbuffer;
3891};
3892
3893// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3894TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3895{
Jamie Madillb8149072019-04-30 16:14:44 -04003896 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02003897
3898 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3899 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3900 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3901 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3902 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3903 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3904 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3905 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3906
3907 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3908 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3909 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3910}
3911
Olli Etuaho95faa232016-06-07 14:01:53 -07003912// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3913// GLES 3.0.4 section 3.8.3.
3914TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3915{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003916 // Crashes on Nexus 5X due to a driver bug. http://anglebug.com/1429
3917 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07003918
3919 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3920 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3921 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3922 ASSERT_GL_NO_ERROR();
3923
3924 // SKIP_IMAGES should not have an effect on uploading 2D textures
3925 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3926 ASSERT_GL_NO_ERROR();
3927
3928 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3929
3930 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3931 pixelsGreen.data());
3932 ASSERT_GL_NO_ERROR();
3933
3934 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3935 pixelsGreen.data());
3936 ASSERT_GL_NO_ERROR();
3937
3938 glUseProgram(mProgram);
3939 drawQuad(mProgram, "position", 0.5f);
3940 ASSERT_GL_NO_ERROR();
3941
3942 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3943}
3944
Olli Etuaho989cac32016-06-08 16:18:49 -07003945// Test that skip defined in unpack parameters is taken into account when determining whether
3946// unpacking source extends outside unpack buffer bounds.
3947TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3948{
3949 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3950 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3951 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3952 ASSERT_GL_NO_ERROR();
3953
3954 GLBuffer buf;
3955 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3956 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3957 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3958 GL_DYNAMIC_COPY);
3959 ASSERT_GL_NO_ERROR();
3960
3961 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3962 ASSERT_GL_NO_ERROR();
3963
3964 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3965 ASSERT_GL_NO_ERROR();
3966
3967 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3968 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3969
3970 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3971 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3972 ASSERT_GL_NO_ERROR();
3973
3974 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3975 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3976}
3977
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003978// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3979TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3980{
Yunchao He9550c602018-02-13 14:47:05 +08003981 ANGLE_SKIP_TEST_IF(IsD3D11());
3982
3983 // Incorrect rendering results seen on OSX AMD.
3984 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003985
3986 const GLuint width = 8u;
3987 const GLuint height = 8u;
3988 const GLuint unpackRowLength = 5u;
3989 const GLuint unpackSkipPixels = 1u;
3990
3991 setWindowWidth(width);
3992 setWindowHeight(height);
3993
3994 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3995 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3996 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3997 ASSERT_GL_NO_ERROR();
3998
3999 GLBuffer buf;
4000 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
4001 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
4002 GLColor::green);
4003
4004 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
4005 {
4006 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
4007 }
4008
4009 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
4010 GL_DYNAMIC_COPY);
4011 ASSERT_GL_NO_ERROR();
4012
4013 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
4014 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
4015 ASSERT_GL_NO_ERROR();
4016
4017 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4018 ASSERT_GL_NO_ERROR();
4019
4020 glUseProgram(mProgram);
4021 drawQuad(mProgram, "position", 0.5f);
4022 ASSERT_GL_NO_ERROR();
4023
4024 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
4025 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
4026 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
4027 actual.data());
4028 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
4029 EXPECT_EQ(expected, actual);
4030}
4031
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004032template <typename T>
4033T UNorm(double value)
4034{
4035 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
4036}
4037
4038// Test rendering a depth texture with mipmaps.
4039TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
4040{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08004041 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
4042 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
Jiawei Shaoaf0f31d2018-09-27 15:42:31 +08004043 // http://anglebug.com/1706
4044 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Corentin Walleze731d8a2016-09-07 10:56:25 -04004045
Jamie Madill24980272019-04-03 09:03:51 -04004046 // Seems to fail on AMD D3D11. Possibly driver bug. http://anglebug.com/3342
4047 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsD3D11());
4048
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004049 const int size = getWindowWidth();
4050
4051 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04004052 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004053
4054 glActiveTexture(GL_TEXTURE0);
4055 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4056 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
4057 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4058 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4059 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
4060 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
4061 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4062 ASSERT_GL_NO_ERROR();
4063
4064 glUseProgram(mProgram);
4065 glUniform1i(mTexture2DUniformLocation, 0);
4066
4067 std::vector<unsigned char> expected;
4068
4069 for (int level = 0; level < levels; ++level)
4070 {
4071 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
4072 expected.push_back(UNorm<unsigned char>(value));
4073
4074 int levelDim = dim(level);
4075
4076 ASSERT_GT(levelDim, 0);
4077
4078 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
4079 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
4080 GL_UNSIGNED_INT, initData.data());
4081 }
4082 ASSERT_GL_NO_ERROR();
4083
4084 for (int level = 0; level < levels; ++level)
4085 {
4086 glViewport(0, 0, dim(level), dim(level));
4087 drawQuad(mProgram, "position", 0.5f);
4088 GLColor actual = ReadColor(0, 0);
4089 EXPECT_NEAR(expected[level], actual.R, 10u);
4090 }
4091
4092 ASSERT_GL_NO_ERROR();
4093}
4094
Jamie Madill7ffdda92016-09-08 13:26:51 -04004095// Tests unpacking into the unsized GL_ALPHA format.
4096TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
4097{
Jamie Madill7ffdda92016-09-08 13:26:51 -04004098 // Initialize the texure.
4099 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4100 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
4101 GL_UNSIGNED_BYTE, nullptr);
4102 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4103 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4104
4105 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
4106
4107 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04004108 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04004109 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4110 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4111 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
4112 GL_STATIC_DRAW);
4113
4114 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
4115 GL_UNSIGNED_BYTE, nullptr);
4116
4117 // Clear to a weird color to make sure we're drawing something.
4118 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
4119 glClear(GL_COLOR_BUFFER_BIT);
4120
4121 // Draw with the alpha texture and verify.
4122 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04004123
4124 ASSERT_GL_NO_ERROR();
4125 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
4126}
4127
Jamie Madill2e600342016-09-19 13:56:40 -04004128// Ensure stale unpack data doesn't propagate in D3D11.
4129TEST_P(Texture2DTestES3, StaleUnpackData)
4130{
4131 // Init unpack buffer.
4132 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
4133 std::vector<GLColor> pixels(pixelCount, GLColor::red);
4134
4135 GLBuffer unpackBuffer;
4136 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4137 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4138 GLsizei bufferSize = pixelCount * sizeof(GLColor);
4139 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
4140
4141 // Create from unpack buffer.
4142 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4143 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
4144 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4145 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4146 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4147
4148 drawQuad(mProgram, "position", 0.5f);
4149
4150 ASSERT_GL_NO_ERROR();
4151 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4152
4153 // Fill unpack with green, recreating buffer.
4154 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
4155 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
4156 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
4157
4158 // Reinit texture with green.
4159 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
4160 GL_UNSIGNED_BYTE, nullptr);
4161
4162 drawQuad(mProgram, "position", 0.5f);
4163
4164 ASSERT_GL_NO_ERROR();
4165 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
4166}
4167
Geoff Langfb7685f2017-11-13 11:44:11 -05004168// Ensure that texture parameters passed as floats that are converted to ints are rounded before
4169// validating they are less than 0.
4170TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
4171{
4172 GLTexture texture;
4173 glBindTexture(GL_TEXTURE_2D, texture);
4174
4175 // Use a negative number that will round to zero when converted to an integer
4176 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
4177 // "Validation of values performed by state-setting commands is performed after conversion,
4178 // unless specified otherwise for a specific command."
4179 GLfloat param = -7.30157126e-07f;
4180 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
4181 EXPECT_GL_NO_ERROR();
4182
4183 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
4184 EXPECT_GL_NO_ERROR();
4185}
4186
Jamie Madillf097e232016-11-05 00:44:15 -04004187// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
4188// being properly checked, and the texture storage of the previous texture format was persisting.
4189// This would result in an ASSERT in debug and incorrect rendering in release.
4190// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
4191TEST_P(Texture3DTestES3, FormatRedefinitionBug)
4192{
4193 GLTexture tex;
4194 glBindTexture(GL_TEXTURE_3D, tex.get());
4195 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4196
4197 GLFramebuffer framebuffer;
4198 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
4199 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
4200
4201 glCheckFramebufferStatus(GL_FRAMEBUFFER);
4202
4203 std::vector<uint8_t> pixelData(100, 0);
4204
4205 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
4206 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
4207 pixelData.data());
4208
4209 ASSERT_GL_NO_ERROR();
4210}
4211
Corentin Wallezd2627992017-04-28 17:17:03 -04004212// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
4213TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
4214{
4215 // 2D tests
4216 {
4217 GLTexture tex;
4218 glBindTexture(GL_TEXTURE_2D, tex.get());
4219
4220 GLBuffer pbo;
4221 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4222
4223 // Test OOB
4224 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
4225 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4226 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4227
4228 // Test OOB
4229 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
4230 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4231 ASSERT_GL_NO_ERROR();
4232 }
4233
4234 // 3D tests
4235 {
4236 GLTexture tex;
4237 glBindTexture(GL_TEXTURE_3D, tex.get());
4238
4239 GLBuffer pbo;
4240 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4241
4242 // Test OOB
4243 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
4244 GL_STATIC_DRAW);
4245 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4246 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4247
4248 // Test OOB
4249 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
4250 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4251 ASSERT_GL_NO_ERROR();
4252 }
4253}
4254
Jamie Madill3ed60422017-09-07 11:32:52 -04004255// Tests behaviour with a single texture and multiple sampler objects.
4256TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
4257{
4258 GLint maxTextureUnits = 0;
4259 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
4260 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
4261
4262 constexpr int kSize = 16;
4263
4264 // Make a single-level texture, fill it with red.
4265 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
4266 GLTexture tex;
4267 glBindTexture(GL_TEXTURE_2D, tex);
4268 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4269 redColors.data());
4270 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4271 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4272
4273 // Simple sanity check.
4274 draw2DTexturedQuad(0.5f, 1.0f, true);
4275 ASSERT_GL_NO_ERROR();
4276 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4277
4278 // Bind texture to unit 1 with a sampler object making it incomplete.
4279 GLSampler sampler;
4280 glBindSampler(0, sampler);
4281 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4282 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4283
4284 // Make a mipmap texture, fill it with blue.
4285 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
4286 GLTexture mipmapTex;
4287 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4288 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4289 blueColors.data());
4290 glGenerateMipmap(GL_TEXTURE_2D);
4291
4292 // Draw with the sampler, expect blue.
4293 draw2DTexturedQuad(0.5f, 1.0f, true);
4294 ASSERT_GL_NO_ERROR();
4295 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
4296
4297 // Simple multitexturing program.
Jamie Madill35cd7332018-12-02 12:03:33 -05004298 constexpr char kVS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004299 "#version 300 es\n"
4300 "in vec2 position;\n"
4301 "out vec2 texCoord;\n"
4302 "void main()\n"
4303 "{\n"
4304 " gl_Position = vec4(position, 0, 1);\n"
4305 " texCoord = position * 0.5 + vec2(0.5);\n"
4306 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05004307
4308 constexpr char kFS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004309 "#version 300 es\n"
4310 "precision mediump float;\n"
4311 "in vec2 texCoord;\n"
4312 "uniform sampler2D tex1;\n"
4313 "uniform sampler2D tex2;\n"
4314 "uniform sampler2D tex3;\n"
4315 "uniform sampler2D tex4;\n"
4316 "out vec4 color;\n"
4317 "void main()\n"
4318 "{\n"
4319 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
4320 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
4321 "}";
4322
Jamie Madill35cd7332018-12-02 12:03:33 -05004323 ANGLE_GL_PROGRAM(program, kVS, kFS);
Jamie Madill3ed60422017-09-07 11:32:52 -04004324
4325 std::array<GLint, 4> texLocations = {
4326 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
4327 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
4328 for (GLint location : texLocations)
4329 {
4330 ASSERT_NE(-1, location);
4331 }
4332
4333 // Init the uniform data.
4334 glUseProgram(program);
4335 for (GLint location = 0; location < 4; ++location)
4336 {
4337 glUniform1i(texLocations[location], location);
4338 }
4339
4340 // Initialize four samplers
4341 GLSampler samplers[4];
4342
4343 // 0: non-mipped.
4344 glBindSampler(0, samplers[0]);
4345 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4346 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4347
4348 // 1: mipped.
4349 glBindSampler(1, samplers[1]);
4350 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4351 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4352
4353 // 2: non-mipped.
4354 glBindSampler(2, samplers[2]);
4355 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4356 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4357
4358 // 3: mipped.
4359 glBindSampler(3, samplers[3]);
4360 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4361 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4362
4363 // Bind two blue mipped textures and two single layer textures, should all draw.
4364 glActiveTexture(GL_TEXTURE0);
4365 glBindTexture(GL_TEXTURE_2D, tex);
4366
4367 glActiveTexture(GL_TEXTURE1);
4368 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4369
4370 glActiveTexture(GL_TEXTURE2);
4371 glBindTexture(GL_TEXTURE_2D, tex);
4372
4373 glActiveTexture(GL_TEXTURE3);
4374 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4375
4376 ASSERT_GL_NO_ERROR();
4377
4378 drawQuad(program, "position", 0.5f);
4379 ASSERT_GL_NO_ERROR();
4380 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
4381
4382 // Bind four single layer textures, two should be incomplete.
4383 glActiveTexture(GL_TEXTURE1);
4384 glBindTexture(GL_TEXTURE_2D, tex);
4385
4386 glActiveTexture(GL_TEXTURE3);
4387 glBindTexture(GL_TEXTURE_2D, tex);
4388
4389 drawQuad(program, "position", 0.5f);
4390 ASSERT_GL_NO_ERROR();
4391 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
4392}
4393
Martin Radev7e2c0d32017-09-15 14:25:42 +03004394// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
4395// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
4396// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
4397// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
4398// samples the cubemap using a direction vector (1,1,1).
4399TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
4400{
Yunchao He2f23f352018-02-11 22:11:37 +08004401 // Check http://anglebug.com/2155.
4402 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
4403
Jamie Madill35cd7332018-12-02 12:03:33 -05004404 constexpr char kVS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004405 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004406 precision mediump float;
4407 in vec3 pos;
4408 void main() {
4409 gl_Position = vec4(pos, 1.0);
4410 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03004411
Jamie Madill35cd7332018-12-02 12:03:33 -05004412 constexpr char kFS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004413 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004414 precision mediump float;
4415 out vec4 color;
4416 uniform samplerCube uTex;
4417 void main(){
4418 color = texture(uTex, vec3(1.0));
4419 })";
Jamie Madill35cd7332018-12-02 12:03:33 -05004420
4421 ANGLE_GL_PROGRAM(program, kVS, kFS);
Martin Radev7e2c0d32017-09-15 14:25:42 +03004422 glUseProgram(program);
4423
4424 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
4425 glActiveTexture(GL_TEXTURE0);
4426
4427 GLTexture cubeTex;
4428 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
4429
4430 const int kFaceWidth = 1;
4431 const int kFaceHeight = 1;
4432 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
4433 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4434 GL_UNSIGNED_BYTE, texData.data());
4435 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4436 GL_UNSIGNED_BYTE, texData.data());
4437 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4438 GL_UNSIGNED_BYTE, texData.data());
4439 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4440 GL_UNSIGNED_BYTE, texData.data());
4441 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4442 GL_UNSIGNED_BYTE, texData.data());
4443 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4444 GL_UNSIGNED_BYTE, texData.data());
4445 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4446 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4447 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
4448 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
4449 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
4450 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
4451
4452 drawQuad(program, "pos", 0.5f, 1.0f, true);
4453 ASSERT_GL_NO_ERROR();
4454
4455 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4456}
4457
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08004458// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
4459TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
4460{
4461 GLuint texture = create2DTexture();
4462
4463 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
4464 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4465
4466 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
4467 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4468
4469 glDeleteTextures(1, &texture);
4470 EXPECT_GL_NO_ERROR();
4471}
4472
Olli Etuaho023371b2018-04-24 17:43:32 +03004473// Test setting base level after calling generateMipmap on a LUMA texture.
4474// Covers http://anglebug.com/2498
4475TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA)
4476{
4477 glActiveTexture(GL_TEXTURE0);
4478 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4479
4480 constexpr const GLsizei kWidth = 8;
4481 constexpr const GLsizei kHeight = 8;
4482 std::array<GLubyte, kWidth * kHeight * 2> whiteData;
4483 whiteData.fill(255u);
4484
4485 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA,
4486 GL_UNSIGNED_BYTE, whiteData.data());
4487 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
4488 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4489 glGenerateMipmap(GL_TEXTURE_2D);
4490 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
4491 EXPECT_GL_NO_ERROR();
4492
4493 drawQuad(mProgram, "position", 0.5f);
4494 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4495}
4496
Till Rathmannc1551dc2018-08-15 17:04:49 +02004497// Covers a bug in the D3D11 backend: http://anglebug.com/2772
4498// When using a sampler the texture was created as if it has mipmaps,
4499// regardless what you specified in GL_TEXTURE_MIN_FILTER via
4500// glSamplerParameteri() -- mistakenly the default value
4501// GL_NEAREST_MIPMAP_LINEAR or the value set via glTexParameteri() was
4502// evaluated.
4503// If you didn't provide mipmaps and didn't let the driver generate them
4504// this led to not sampling your texture data when minification occurred.
4505TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping)
4506{
Jamie Madill35cd7332018-12-02 12:03:33 -05004507 constexpr char kVS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004508 "#version 300 es\n"
4509 "out vec2 texcoord;\n"
4510 "in vec4 position;\n"
4511 "void main()\n"
4512 "{\n"
4513 " gl_Position = vec4(position.xy * 0.1, 0.0, 1.0);\n"
4514 " texcoord = (position.xy * 0.5) + 0.5;\n"
4515 "}\n";
4516
Jamie Madill35cd7332018-12-02 12:03:33 -05004517 constexpr char kFS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004518 "#version 300 es\n"
4519 "precision highp float;\n"
4520 "uniform highp sampler2D tex;\n"
4521 "in vec2 texcoord;\n"
4522 "out vec4 fragColor;\n"
4523 "void main()\n"
4524 "{\n"
4525 " fragColor = texture(tex, texcoord);\n"
4526 "}\n";
Jamie Madill35cd7332018-12-02 12:03:33 -05004527
4528 ANGLE_GL_PROGRAM(program, kVS, kFS);
Till Rathmannc1551dc2018-08-15 17:04:49 +02004529
4530 GLSampler sampler;
4531 glBindSampler(0, sampler);
4532 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4533 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4534
4535 glActiveTexture(GL_TEXTURE0);
4536 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4537
4538 const GLsizei texWidth = getWindowWidth();
4539 const GLsizei texHeight = getWindowHeight();
4540 const std::vector<GLColor> whiteData(texWidth * texHeight, GLColor::white);
4541
4542 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4543 whiteData.data());
4544 EXPECT_GL_NO_ERROR();
4545
4546 drawQuad(program, "position", 0.5f);
4547 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, angle::GLColor::white);
4548}
4549
Anders Leinof6cbe442019-04-18 15:32:07 +03004550// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4551// texture is output.
4552TEST_P(Texture2DIntegerTestES3, IntegerTextureNonZeroBaseLevel)
4553{
Yuly Novikovd2683452019-05-23 16:11:19 -04004554 // http://anglebug.com/3478
4555 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsDesktopOpenGL());
4556
Anders Leinof6cbe442019-04-18 15:32:07 +03004557 glActiveTexture(GL_TEXTURE0);
4558 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4559 int width = getWindowWidth();
4560 int height = getWindowHeight();
4561 GLColor color = GLColor::green;
4562 std::vector<GLColor> pixels(width * height, color);
4563 GLint baseLevel = 1;
4564 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
4565 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4566 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4567 glTexImage2D(GL_TEXTURE_2D, baseLevel, GL_RGBA8UI, width, height, 0, GL_RGBA_INTEGER,
4568 GL_UNSIGNED_BYTE, pixels.data());
4569
4570 setUpProgram();
4571 glUseProgram(mProgram);
4572 glUniform1i(mTexture2DUniformLocation, 0);
4573 drawQuad(mProgram, "position", 0.5f);
4574
4575 EXPECT_GL_NO_ERROR();
4576 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4577 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4578}
4579
Anders Leino60cc7512019-05-06 09:25:27 +03004580// Draw a quad with an integer cube texture with a non-zero base level, and test that the color of
4581// the texture is output.
4582TEST_P(TextureCubeIntegerTestES3, IntegerCubeTextureNonZeroBaseLevel)
4583{
4584 // All output checks returned black, rather than the texture color.
4585 ANGLE_SKIP_TEST_IF(IsOSX() && IsOpenGL());
4586
4587 glActiveTexture(GL_TEXTURE0);
4588
4589 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
4590 GLint baseLevel = 1;
4591 int width = getWindowWidth();
4592 int height = getWindowHeight();
4593 GLColor color = GLColor::green;
4594 std::vector<GLColor> pixels(width * height, color);
4595 for (GLenum faceIndex = 0; faceIndex < 6; faceIndex++)
4596 {
4597 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, baseLevel, GL_RGBA8UI, width,
4598 height, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
4599 EXPECT_GL_NO_ERROR();
4600 }
4601 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, baseLevel);
4602 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4603 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4604
4605 glUseProgram(mProgram);
4606 glUniform1i(mTextureCubeUniformLocation, 0);
4607 drawQuad(mProgram, "position", 0.5f);
4608
4609 EXPECT_GL_NO_ERROR();
4610 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4611 EXPECT_PIXEL_COLOR_EQ(width - 1, 0, color);
4612 EXPECT_PIXEL_COLOR_EQ(0, height - 1, color);
4613 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4614}
4615
Anders Leinoe4452442019-05-09 13:29:49 +03004616// This test sets up a cube map with four distincly colored MIP levels.
4617// The size of the texture and the geometry is chosen such that levels 1 or 2 should be chosen at
4618// the corners of the screen.
4619TEST_P(TextureCubeIntegerEdgeTestES3, IntegerCubeTextureCorner)
4620{
4621 glActiveTexture(GL_TEXTURE0);
4622
4623 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
4624 int width = getWindowWidth();
4625 int height = getWindowHeight();
4626 ASSERT_EQ(width, height);
4627 GLColor color[4] = {GLColor::white, GLColor::green, GLColor::blue, GLColor::red};
4628 for (GLint level = 0; level < 4; level++)
4629 {
4630 for (GLenum faceIndex = 0; faceIndex < 6; faceIndex++)
4631 {
4632 int levelWidth = (2 * width) >> level;
4633 int levelHeight = (2 * height) >> level;
4634 std::vector<GLColor> pixels(levelWidth * levelHeight, color[level]);
4635 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, level, GL_RGBA8UI, levelWidth,
4636 levelHeight, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
4637 EXPECT_GL_NO_ERROR();
4638 }
4639 }
4640 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4641 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4642 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 3);
4643
4644 glUseProgram(mProgram);
4645 glUniform1i(mTextureCubeUniformLocation, 0);
4646 drawQuad(mProgram, "position", 0.5f);
4647
4648 ASSERT_GL_NO_ERROR();
4649 // Check that we do not read from levels 0 or 3. Levels 1 and 2 are both acceptable.
4650 EXPECT_EQ(ReadColor(0, 0).R, 0);
4651 EXPECT_EQ(ReadColor(width - 1, 0).R, 0);
4652 EXPECT_EQ(ReadColor(0, height - 1).R, 0);
4653 EXPECT_EQ(ReadColor(width - 1, height - 1).R, 0);
4654}
4655
Jamie Madill50cf2be2018-06-15 09:46:57 -04004656// Use this to select which configurations (e.g. which renderer, which GLES major version) these
4657// tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -05004658ANGLE_INSTANTIATE_TEST(Texture2DTest,
4659 ES2_D3D9(),
4660 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004661 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05004662 ES2_OPENGLES(),
4663 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004664ANGLE_INSTANTIATE_TEST(TextureCubeTest,
4665 ES2_D3D9(),
4666 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004667 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004668 ES2_OPENGLES(),
4669 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004670ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
4671 ES2_D3D9(),
4672 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004673 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004674 ES2_OPENGLES(),
4675 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004676ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
4677 ES2_D3D9(),
4678 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004679 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004680 ES2_OPENGLES(),
4681 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004682ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
4683 ES2_D3D9(),
4684 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004685 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004686 ES2_OPENGLES(),
4687 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004688ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
4689 ES2_D3D9(),
4690 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004691 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004692 ES2_OPENGLES(),
4693 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004694ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02004695ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02004696ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4697ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
4698 ES3_D3D11(),
4699 ES3_OPENGL(),
4700 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004701ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
4702 ES3_D3D11(),
4703 ES3_OPENGL(),
4704 ES3_OPENGLES());
4705ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4706ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02004707ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02004708ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
4709 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004710 ES2_D3D9(),
4711 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004712 ES2_OPENGLES(),
4713 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004714ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
4715 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004716 ES2_D3D9(),
4717 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004718 ES2_OPENGLES(),
4719 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004720ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
4721 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004722 ES2_D3D9(),
4723 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004724 ES2_OPENGLES(),
4725 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004726ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
4727 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004728 ES2_D3D9(),
4729 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004730 ES2_OPENGLES(),
4731 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004732ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
4733 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004734 ES2_D3D9(),
4735 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004736 ES2_OPENGLES(),
4737 ES2_VULKAN());
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05004738ANGLE_INSTANTIATE_TEST(TextureAnisotropyTest,
4739 ES2_D3D11(),
4740 ES2_D3D9(),
4741 ES2_OPENGL(),
4742 ES2_OPENGLES(),
4743 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02004744ANGLE_INSTANTIATE_TEST(TextureBorderClampTest,
4745 ES2_D3D11(),
4746 ES2_D3D9(),
4747 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004748 ES2_OPENGLES(),
4749 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02004750ANGLE_INSTANTIATE_TEST(TextureBorderClampTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4751ANGLE_INSTANTIATE_TEST(TextureBorderClampIntegerTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Luc Ferronaf883622018-06-08 15:57:31 -04004752ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN());
Vincent Lang25ab4512016-05-13 18:13:59 +02004753ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03004754ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Anders Leinof6cbe442019-04-18 15:32:07 +03004755ANGLE_INSTANTIATE_TEST(Texture2DIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino60cc7512019-05-06 09:25:27 +03004756ANGLE_INSTANTIATE_TEST(TextureCubeIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leinoe4452442019-05-09 13:29:49 +03004757ANGLE_INSTANTIATE_TEST(TextureCubeIntegerEdgeTestES3, ES3_D3D11(), ES3_OPENGL());
Jamie Madillfa05f602015-05-07 13:47:11 -04004758
Jamie Madill7ffdda92016-09-08 13:26:51 -04004759} // anonymous namespace