blob: 639018752e81bb74bad456a646537de8c043d502 [file] [log] [blame]
Jamie Madillfa05f602015-05-07 13:47:11 -04001//
2// Copyright 2015 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Jamie Madill14718762016-09-06 15:56:54 -04007#include "common/mathutil.h"
Corentin Wallezd3970de2015-05-14 11:07:48 -04008#include "test_utils/ANGLETest.h"
Olli Etuaho989cac32016-06-08 16:18:49 -07009#include "test_utils/gl_raii.h"
Jamie Madillf67115c2014-04-22 13:14:05 -040010
Jamie Madillfa05f602015-05-07 13:47:11 -040011using namespace angle;
Austin Kinross18b931d2014-09-29 12:58:31 -070012
Jamie Madillfa05f602015-05-07 13:47:11 -040013namespace
14{
15
Vincent Lang25ab4512016-05-13 18:13:59 +020016// Take a pixel, and reset the components not covered by the format to default
Geoff Langf607c602016-09-21 11:46:48 -040017// values. In particular, the default value for the alpha component is 255
Vincent Lang25ab4512016-05-13 18:13:59 +020018// (1.0 as unsigned normalized fixed point value).
Geoff Langf607c602016-09-21 11:46:48 -040019GLColor SliceFormatColor(GLenum format, GLColor full)
Vincent Lang25ab4512016-05-13 18:13:59 +020020{
21 switch (format)
22 {
23 case GL_RED:
Geoff Langf607c602016-09-21 11:46:48 -040024 return GLColor(full.R, 0, 0, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020025 case GL_RG:
Geoff Langf607c602016-09-21 11:46:48 -040026 return GLColor(full.R, full.G, 0, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020027 case GL_RGB:
Geoff Langf607c602016-09-21 11:46:48 -040028 return GLColor(full.R, full.G, full.B, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020029 case GL_RGBA:
30 return full;
31 default:
Jamie Madille1faacb2016-12-13 12:42:14 -050032 EXPECT_TRUE(false);
Geoff Langf607c602016-09-21 11:46:48 -040033 return GLColor::white;
Vincent Lang25ab4512016-05-13 18:13:59 +020034 }
Vincent Lang25ab4512016-05-13 18:13:59 +020035}
36
Olli Etuaho4a8329f2016-01-11 17:12:57 +020037class TexCoordDrawTest : public ANGLETest
Jamie Madillf67115c2014-04-22 13:14:05 -040038{
Jamie Madillbc393df2015-01-29 13:46:07 -050039 protected:
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020040 TexCoordDrawTest() : ANGLETest(), mProgram(0), mFramebuffer(0), mFramebufferColorTexture(0)
Jamie Madillf67115c2014-04-22 13:14:05 -040041 {
42 setWindowWidth(128);
43 setWindowHeight(128);
44 setConfigRedBits(8);
45 setConfigGreenBits(8);
46 setConfigBlueBits(8);
47 setConfigAlphaBits(8);
48 }
49
Jamie Madill35cd7332018-12-02 12:03:33 -050050 virtual const char *getVertexShaderSource()
Jamie Madillf67115c2014-04-22 13:14:05 -040051 {
Jamie Madill35cd7332018-12-02 12:03:33 -050052 return R"(precision highp float;
53attribute vec4 position;
54varying vec2 texcoord;
Geoff Langc41e42d2014-04-28 10:58:16 -040055
Jamie Madill35cd7332018-12-02 12:03:33 -050056void main()
57{
58 gl_Position = vec4(position.xy, 0.0, 1.0);
59 texcoord = (position.xy * 0.5) + 0.5;
60})";
Olli Etuaho4a8329f2016-01-11 17:12:57 +020061 }
Geoff Langc41e42d2014-04-28 10:58:16 -040062
Jamie Madill35cd7332018-12-02 12:03:33 -050063 virtual const char *getFragmentShaderSource() = 0;
Olli Etuaho4a8329f2016-01-11 17:12:57 +020064
Olli Etuahoa1c917f2016-04-06 13:50:03 +030065 virtual void setUpProgram()
Olli Etuaho4a8329f2016-01-11 17:12:57 +020066 {
Jamie Madill35cd7332018-12-02 12:03:33 -050067 const char *vertexShaderSource = getVertexShaderSource();
68 const char *fragmentShaderSource = getFragmentShaderSource();
Olli Etuaho4a8329f2016-01-11 17:12:57 +020069
70 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
71 ASSERT_NE(0u, mProgram);
72 ASSERT_GL_NO_ERROR();
Olli Etuahoa1c917f2016-04-06 13:50:03 +030073 }
74
Jamie Madill5cbaa3f2019-05-07 15:49:22 -040075 void testSetUp() override { setUpFramebuffer(); }
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020076
Jamie Madill5cbaa3f2019-05-07 15:49:22 -040077 void testTearDown() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +020078 {
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020079 glBindFramebuffer(GL_FRAMEBUFFER, 0);
80 glDeleteFramebuffers(1, &mFramebuffer);
81 glDeleteTextures(1, &mFramebufferColorTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +020082 glDeleteProgram(mProgram);
Olli Etuaho4a8329f2016-01-11 17:12:57 +020083 }
84
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020085 void setUpFramebuffer()
86 {
87 // We use an FBO to work around an issue where the default framebuffer applies SRGB
88 // conversion (particularly known to happen incorrectly on Intel GL drivers). It's not
89 // clear whether this issue can even be fixed on all backends. For example GLES 3.0.4 spec
90 // section 4.4 says that the format of the default framebuffer is entirely up to the window
91 // system, so it might be SRGB, and GLES 3.0 doesn't have a "FRAMEBUFFER_SRGB" to turn off
92 // SRGB conversion like desktop GL does.
93 // TODO(oetuaho): Get rid of this if the underlying issue is fixed.
94 glGenFramebuffers(1, &mFramebuffer);
95 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
96
97 glGenTextures(1, &mFramebufferColorTexture);
98 glBindTexture(GL_TEXTURE_2D, mFramebufferColorTexture);
99 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
100 GL_UNSIGNED_BYTE, nullptr);
101 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
102 mFramebufferColorTexture, 0);
103 ASSERT_GL_NO_ERROR();
104 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
105 glBindTexture(GL_TEXTURE_2D, 0);
106 }
107
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200108 // Returns the created texture ID.
109 GLuint create2DTexture()
110 {
111 GLuint texture2D;
112 glGenTextures(1, &texture2D);
113 glBindTexture(GL_TEXTURE_2D, texture2D);
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800114 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200115 EXPECT_GL_NO_ERROR();
116 return texture2D;
117 }
118
119 GLuint mProgram;
Olli Etuaho51f1c0f2016-01-13 16:16:24 +0200120 GLuint mFramebuffer;
121
122 private:
123 GLuint mFramebufferColorTexture;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200124};
125
126class Texture2DTest : public TexCoordDrawTest
127{
128 protected:
129 Texture2DTest() : TexCoordDrawTest(), mTexture2D(0), mTexture2DUniformLocation(-1) {}
130
Jamie Madill35cd7332018-12-02 12:03:33 -0500131 const char *getFragmentShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200132 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500133 return R"(precision highp float;
134uniform sampler2D tex;
135varying vec2 texcoord;
Geoff Langc41e42d2014-04-28 10:58:16 -0400136
Jamie Madill35cd7332018-12-02 12:03:33 -0500137void main()
138{
139 gl_FragColor = texture2D(tex, texcoord);
140})";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200141 }
Geoff Langc41e42d2014-04-28 10:58:16 -0400142
Olli Etuaho96963162016-03-21 11:54:33 +0200143 virtual const char *getTextureUniformName() { return "tex"; }
144
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300145 void setUpProgram() override
146 {
147 TexCoordDrawTest::setUpProgram();
148 mTexture2DUniformLocation = glGetUniformLocation(mProgram, getTextureUniformName());
149 ASSERT_NE(-1, mTexture2DUniformLocation);
150 }
151
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400152 void testSetUp() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200153 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400154 TexCoordDrawTest::testSetUp();
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200155 mTexture2D = create2DTexture();
Jamie Madilld4cfa572014-07-08 10:00:32 -0400156
Jamie Madill9aca0592014-10-06 16:26:59 -0400157 ASSERT_GL_NO_ERROR();
Jamie Madillf67115c2014-04-22 13:14:05 -0400158 }
159
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400160 void testTearDown() override
Jamie Madillf67115c2014-04-22 13:14:05 -0400161 {
Jamie Madilld4cfa572014-07-08 10:00:32 -0400162 glDeleteTextures(1, &mTexture2D);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400163 TexCoordDrawTest::testTearDown();
Jamie Madillf67115c2014-04-22 13:14:05 -0400164 }
165
Jamie Madillbc393df2015-01-29 13:46:07 -0500166 // Tests CopyTexSubImage with floating point textures of various formats.
167 void testFloatCopySubImage(int sourceImageChannels, int destImageChannels)
168 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300169 setUpProgram();
170
Martin Radev1be913c2016-07-11 17:59:16 +0300171 if (getClientMajorVersion() < 3)
Geoff Langfbfa47c2015-03-31 11:26:00 -0400172 {
Jamie Madillb8149072019-04-30 16:14:44 -0400173 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_storage") ||
174 !IsGLExtensionEnabled("GL_OES_texture_float"));
Geoff Langc4e93662017-05-01 10:45:59 -0400175
Yunchao He9550c602018-02-13 14:47:05 +0800176 ANGLE_SKIP_TEST_IF((sourceImageChannels < 3 || destImageChannels < 3) &&
Jamie Madillb8149072019-04-30 16:14:44 -0400177 !IsGLExtensionEnabled("GL_EXT_texture_rg"));
Geoff Langfbfa47c2015-03-31 11:26:00 -0400178
Yunchao He9550c602018-02-13 14:47:05 +0800179 ANGLE_SKIP_TEST_IF(destImageChannels == 3 &&
Jamie Madillb8149072019-04-30 16:14:44 -0400180 !IsGLExtensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400181
Yunchao He9550c602018-02-13 14:47:05 +0800182 ANGLE_SKIP_TEST_IF(destImageChannels == 4 &&
Jamie Madillb8149072019-04-30 16:14:44 -0400183 !IsGLExtensionEnabled("GL_CHROMIUM_color_buffer_float_rgba"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400184
Yunchao He9550c602018-02-13 14:47:05 +0800185 ANGLE_SKIP_TEST_IF(destImageChannels <= 2);
Geoff Lang677bb6f2017-04-05 12:40:40 -0400186 }
187 else
188 {
Jamie Madillb8149072019-04-30 16:14:44 -0400189 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_color_buffer_float"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400190
Yunchao He9550c602018-02-13 14:47:05 +0800191 ANGLE_SKIP_TEST_IF(destImageChannels == 3 &&
Jamie Madillb8149072019-04-30 16:14:44 -0400192 !IsGLExtensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"));
Geoff Langfbfa47c2015-03-31 11:26:00 -0400193 }
194
Jamie Madill50cf2be2018-06-15 09:46:57 -0400195 // clang-format off
Jamie Madillbc393df2015-01-29 13:46:07 -0500196 GLfloat sourceImageData[4][16] =
197 {
198 { // R
199 1.0f,
200 0.0f,
201 0.0f,
202 1.0f
203 },
204 { // RG
205 1.0f, 0.0f,
206 0.0f, 1.0f,
207 0.0f, 0.0f,
208 1.0f, 1.0f
209 },
210 { // RGB
211 1.0f, 0.0f, 0.0f,
212 0.0f, 1.0f, 0.0f,
213 0.0f, 0.0f, 1.0f,
214 1.0f, 1.0f, 0.0f
215 },
216 { // RGBA
217 1.0f, 0.0f, 0.0f, 1.0f,
218 0.0f, 1.0f, 0.0f, 1.0f,
219 0.0f, 0.0f, 1.0f, 1.0f,
220 1.0f, 1.0f, 0.0f, 1.0f
221 },
222 };
Jamie Madill50cf2be2018-06-15 09:46:57 -0400223 // clang-format on
Jamie Madillbc393df2015-01-29 13:46:07 -0500224
Jamie Madill50cf2be2018-06-15 09:46:57 -0400225 GLenum imageFormats[] = {
Jamie Madillb980c562018-11-27 11:34:27 -0500226 GL_R32F,
227 GL_RG32F,
228 GL_RGB32F,
229 GL_RGBA32F,
Jamie Madillbc393df2015-01-29 13:46:07 -0500230 };
231
Jamie Madill50cf2be2018-06-15 09:46:57 -0400232 GLenum sourceUnsizedFormats[] = {
Jamie Madillb980c562018-11-27 11:34:27 -0500233 GL_RED,
234 GL_RG,
235 GL_RGB,
236 GL_RGBA,
Jamie Madillbc393df2015-01-29 13:46:07 -0500237 };
238
239 GLuint textures[2];
240
241 glGenTextures(2, textures);
242
Jamie Madill50cf2be2018-06-15 09:46:57 -0400243 GLfloat *imageData = sourceImageData[sourceImageChannels - 1];
244 GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1];
Jamie Madillbc393df2015-01-29 13:46:07 -0500245 GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1];
Jamie Madill50cf2be2018-06-15 09:46:57 -0400246 GLenum destImageFormat = imageFormats[destImageChannels - 1];
Jamie Madillbc393df2015-01-29 13:46:07 -0500247
248 glBindTexture(GL_TEXTURE_2D, textures[0]);
Geoff Langc4e93662017-05-01 10:45:59 -0400249 if (getClientMajorVersion() >= 3)
250 {
251 glTexStorage2D(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
252 }
253 else
254 {
255 glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
256 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500257 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
258 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
259 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData);
260
Jamie Madillb8149072019-04-30 16:14:44 -0400261 if (sourceImageChannels < 3 && !IsGLExtensionEnabled("GL_EXT_texture_rg"))
Jamie Madillbc393df2015-01-29 13:46:07 -0500262 {
263 // This is not supported
264 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
265 }
266 else
267 {
268 ASSERT_GL_NO_ERROR();
269 }
270
271 GLuint fbo;
272 glGenFramebuffers(1, &fbo);
273 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
274 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
275
276 glBindTexture(GL_TEXTURE_2D, textures[1]);
Geoff Langc4e93662017-05-01 10:45:59 -0400277 if (getClientMajorVersion() >= 3)
278 {
279 glTexStorage2D(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
280 }
281 else
282 {
283 glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
284 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500285 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
286 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
287
288 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
289 ASSERT_GL_NO_ERROR();
290
291 glBindFramebuffer(GL_FRAMEBUFFER, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200292 drawQuad(mProgram, "position", 0.5f);
Jamie Madillbc393df2015-01-29 13:46:07 -0500293
294 int testImageChannels = std::min(sourceImageChannels, destImageChannels);
295
Olli Etuahoa314b612016-03-10 16:43:00 +0200296 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Jamie Madillbc393df2015-01-29 13:46:07 -0500297 if (testImageChannels > 1)
298 {
299 EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255);
300 EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255);
301 if (testImageChannels > 2)
302 {
303 EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255);
304 }
305 }
306
307 glDeleteFramebuffers(1, &fbo);
308 glDeleteTextures(2, textures);
309
310 ASSERT_GL_NO_ERROR();
311 }
312
Jamie Madilld4cfa572014-07-08 10:00:32 -0400313 GLuint mTexture2D;
Jamie Madilld4cfa572014-07-08 10:00:32 -0400314 GLint mTexture2DUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400315};
316
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200317class Texture2DTestES3 : public Texture2DTest
318{
319 protected:
320 Texture2DTestES3() : Texture2DTest() {}
321
Jamie Madill35cd7332018-12-02 12:03:33 -0500322 const char *getVertexShaderSource() override
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200323 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500324 return "#version 300 es\n"
325 "out vec2 texcoord;\n"
326 "in vec4 position;\n"
327 "void main()\n"
328 "{\n"
329 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
330 " texcoord = (position.xy * 0.5) + 0.5;\n"
331 "}\n";
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200332 }
333
Jamie Madill35cd7332018-12-02 12:03:33 -0500334 const char *getFragmentShaderSource() override
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200335 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500336 return "#version 300 es\n"
337 "precision highp float;\n"
338 "uniform highp sampler2D tex;\n"
339 "in vec2 texcoord;\n"
340 "out vec4 fragColor;\n"
341 "void main()\n"
342 "{\n"
343 " fragColor = texture(tex, texcoord);\n"
344 "}\n";
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200345 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300346
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400347 void testSetUp() override
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300348 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400349 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300350 setUpProgram();
351 }
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200352};
353
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200354class Texture2DIntegerAlpha1TestES3 : public Texture2DTest
355{
356 protected:
357 Texture2DIntegerAlpha1TestES3() : Texture2DTest() {}
358
Jamie Madill35cd7332018-12-02 12:03:33 -0500359 const char *getVertexShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200360 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500361 return "#version 300 es\n"
362 "out vec2 texcoord;\n"
363 "in vec4 position;\n"
364 "void main()\n"
365 "{\n"
366 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
367 " texcoord = (position.xy * 0.5) + 0.5;\n"
368 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200369 }
370
Jamie Madill35cd7332018-12-02 12:03:33 -0500371 const char *getFragmentShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200372 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500373 return "#version 300 es\n"
374 "precision highp float;\n"
375 "uniform highp isampler2D tex;\n"
376 "in vec2 texcoord;\n"
377 "out vec4 fragColor;\n"
378 "void main()\n"
379 "{\n"
380 " vec4 green = vec4(0, 1, 0, 1);\n"
381 " vec4 black = vec4(0, 0, 0, 0);\n"
382 " fragColor = (texture(tex, texcoord).a == 1) ? green : black;\n"
383 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200384 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300385
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400386 void testSetUp() override
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300387 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400388 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300389 setUpProgram();
390 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200391};
392
393class Texture2DUnsignedIntegerAlpha1TestES3 : public Texture2DTest
394{
395 protected:
396 Texture2DUnsignedIntegerAlpha1TestES3() : Texture2DTest() {}
397
Jamie Madill35cd7332018-12-02 12:03:33 -0500398 const char *getVertexShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200399 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500400 return "#version 300 es\n"
401 "out vec2 texcoord;\n"
402 "in vec4 position;\n"
403 "void main()\n"
404 "{\n"
405 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
406 " texcoord = (position.xy * 0.5) + 0.5;\n"
407 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200408 }
409
Jamie Madill35cd7332018-12-02 12:03:33 -0500410 const char *getFragmentShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200411 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500412 return "#version 300 es\n"
413 "precision highp float;\n"
414 "uniform highp usampler2D tex;\n"
415 "in vec2 texcoord;\n"
416 "out vec4 fragColor;\n"
417 "void main()\n"
418 "{\n"
419 " vec4 green = vec4(0, 1, 0, 1);\n"
420 " vec4 black = vec4(0, 0, 0, 0);\n"
421 " fragColor = (texture(tex, texcoord).a == 1u) ? green : black;\n"
422 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200423 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300424
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400425 void testSetUp() override
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300426 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400427 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300428 setUpProgram();
429 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200430};
431
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200432class Texture2DTestWithDrawScale : public Texture2DTest
Jamie Madill2453dbc2015-07-14 11:35:42 -0400433{
434 protected:
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200435 Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {}
436
Jamie Madill35cd7332018-12-02 12:03:33 -0500437 const char *getVertexShaderSource() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400438 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300439 return
440 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200441 attribute vec4 position;
442 varying vec2 texcoord;
443
444 uniform vec2 drawScale;
445
446 void main()
447 {
448 gl_Position = vec4(position.xy * drawScale, 0.0, 1.0);
449 texcoord = (position.xy * 0.5) + 0.5;
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300450 })";
Jamie Madill2453dbc2015-07-14 11:35:42 -0400451 }
452
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400453 void testSetUp() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400454 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400455 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300456
457 setUpProgram();
458
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200459 mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale");
460 ASSERT_NE(-1, mDrawScaleUniformLocation);
Jamie Madill2453dbc2015-07-14 11:35:42 -0400461
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200462 glUseProgram(mProgram);
463 glUniform2f(mDrawScaleUniformLocation, 1.0f, 1.0f);
464 glUseProgram(0);
465 ASSERT_GL_NO_ERROR();
466 }
467
468 GLint mDrawScaleUniformLocation;
469};
470
Olli Etuaho4644a202016-01-12 15:12:53 +0200471class Sampler2DAsFunctionParameterTest : public Texture2DTest
472{
473 protected:
474 Sampler2DAsFunctionParameterTest() : Texture2DTest() {}
475
Jamie Madill35cd7332018-12-02 12:03:33 -0500476 const char *getFragmentShaderSource() override
Olli Etuaho4644a202016-01-12 15:12:53 +0200477 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300478 return
479 R"(precision highp float;
Olli Etuaho4644a202016-01-12 15:12:53 +0200480 uniform sampler2D tex;
481 varying vec2 texcoord;
482
483 vec4 computeFragColor(sampler2D aTex)
484 {
485 return texture2D(aTex, texcoord);
486 }
487
488 void main()
489 {
490 gl_FragColor = computeFragColor(tex);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300491 })";
Olli Etuaho4644a202016-01-12 15:12:53 +0200492 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300493
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400494 void testSetUp() override
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300495 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400496 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300497 setUpProgram();
498 }
Olli Etuaho4644a202016-01-12 15:12:53 +0200499};
500
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200501class TextureCubeTest : public TexCoordDrawTest
502{
503 protected:
504 TextureCubeTest()
505 : TexCoordDrawTest(),
506 mTexture2D(0),
507 mTextureCube(0),
508 mTexture2DUniformLocation(-1),
509 mTextureCubeUniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500510 {}
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200511
Jamie Madill35cd7332018-12-02 12:03:33 -0500512 const char *getFragmentShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200513 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300514 return
515 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200516 uniform sampler2D tex2D;
517 uniform samplerCube texCube;
518 varying vec2 texcoord;
519
520 void main()
521 {
522 gl_FragColor = texture2D(tex2D, texcoord);
523 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300524 })";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200525 }
526
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400527 void testSetUp() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200528 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400529 TexCoordDrawTest::testSetUp();
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200530
531 glGenTextures(1, &mTextureCube);
532 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Geoff Langc4e93662017-05-01 10:45:59 -0400533 for (GLenum face = 0; face < 6; face++)
534 {
535 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
536 GL_UNSIGNED_BYTE, nullptr);
537 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200538 EXPECT_GL_NO_ERROR();
539
540 mTexture2D = create2DTexture();
541
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300542 setUpProgram();
543
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200544 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
545 ASSERT_NE(-1, mTexture2DUniformLocation);
546 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
547 ASSERT_NE(-1, mTextureCubeUniformLocation);
548 }
549
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400550 void testTearDown() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200551 {
552 glDeleteTextures(1, &mTextureCube);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400553 TexCoordDrawTest::testTearDown();
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200554 }
555
556 GLuint mTexture2D;
557 GLuint mTextureCube;
558 GLint mTexture2DUniformLocation;
559 GLint mTextureCubeUniformLocation;
560};
561
Martin Radev7e2c0d32017-09-15 14:25:42 +0300562class TextureCubeTestES3 : public ANGLETest
563{
564 protected:
565 TextureCubeTestES3() {}
566};
567
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200568class SamplerArrayTest : public TexCoordDrawTest
569{
570 protected:
571 SamplerArrayTest()
572 : TexCoordDrawTest(),
573 mTexture2DA(0),
574 mTexture2DB(0),
575 mTexture0UniformLocation(-1),
576 mTexture1UniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500577 {}
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200578
Jamie Madill35cd7332018-12-02 12:03:33 -0500579 const char *getFragmentShaderSource() override
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200580 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300581 return
582 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200583 uniform highp sampler2D tex2DArray[2];
584 varying vec2 texcoord;
585 void main()
586 {
587 gl_FragColor = texture2D(tex2DArray[0], texcoord);
588 gl_FragColor += texture2D(tex2DArray[1], texcoord);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300589 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200590 }
591
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400592 void testSetUp() override
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200593 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400594 TexCoordDrawTest::testSetUp();
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200595
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300596 setUpProgram();
597
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200598 mTexture0UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[0]");
599 ASSERT_NE(-1, mTexture0UniformLocation);
600 mTexture1UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[1]");
601 ASSERT_NE(-1, mTexture1UniformLocation);
602
603 mTexture2DA = create2DTexture();
604 mTexture2DB = create2DTexture();
605 ASSERT_GL_NO_ERROR();
606 }
607
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400608 void testTearDown() override
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200609 {
610 glDeleteTextures(1, &mTexture2DA);
611 glDeleteTextures(1, &mTexture2DB);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400612 TexCoordDrawTest::testTearDown();
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200613 }
614
615 void testSamplerArrayDraw()
616 {
617 GLubyte texData[4];
618 texData[0] = 0;
619 texData[1] = 60;
620 texData[2] = 0;
621 texData[3] = 255;
622
623 glActiveTexture(GL_TEXTURE0);
624 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
625 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
626
627 texData[1] = 120;
628 glActiveTexture(GL_TEXTURE1);
629 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
630 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
631 EXPECT_GL_ERROR(GL_NO_ERROR);
632
633 glUseProgram(mProgram);
634 glUniform1i(mTexture0UniformLocation, 0);
635 glUniform1i(mTexture1UniformLocation, 1);
636 drawQuad(mProgram, "position", 0.5f);
637 EXPECT_GL_NO_ERROR();
638
639 EXPECT_PIXEL_NEAR(0, 0, 0, 180, 0, 255, 2);
640 }
641
642 GLuint mTexture2DA;
643 GLuint mTexture2DB;
644 GLint mTexture0UniformLocation;
645 GLint mTexture1UniformLocation;
646};
647
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200648class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest
649{
650 protected:
651 SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {}
652
Jamie Madill35cd7332018-12-02 12:03:33 -0500653 const char *getFragmentShaderSource() override
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200654 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300655 return
656 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200657 uniform highp sampler2D tex2DArray[2];
658 varying vec2 texcoord;
659
660 vec4 computeFragColor(highp sampler2D aTex2DArray[2])
661 {
662 return texture2D(aTex2DArray[0], texcoord) + texture2D(aTex2DArray[1], texcoord);
663 }
664
665 void main()
666 {
667 gl_FragColor = computeFragColor(tex2DArray);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300668 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200669 }
670};
671
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200672class Texture2DArrayTestES3 : public TexCoordDrawTest
673{
674 protected:
675 Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {}
676
Jamie Madill35cd7332018-12-02 12:03:33 -0500677 const char *getVertexShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200678 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500679 return "#version 300 es\n"
680 "out vec2 texcoord;\n"
681 "in vec4 position;\n"
682 "void main()\n"
683 "{\n"
684 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
685 " texcoord = (position.xy * 0.5) + 0.5;\n"
686 "}\n";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200687 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400688
Jamie Madill35cd7332018-12-02 12:03:33 -0500689 const char *getFragmentShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200690 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500691 return "#version 300 es\n"
692 "precision highp float;\n"
693 "uniform highp sampler2DArray tex2DArray;\n"
694 "in vec2 texcoord;\n"
695 "out vec4 fragColor;\n"
696 "void main()\n"
697 "{\n"
698 " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n"
699 "}\n";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200700 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400701
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400702 void testSetUp() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200703 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400704 TexCoordDrawTest::testSetUp();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400705
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300706 setUpProgram();
707
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200708 mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray");
Jamie Madill2453dbc2015-07-14 11:35:42 -0400709 ASSERT_NE(-1, mTextureArrayLocation);
710
711 glGenTextures(1, &m2DArrayTexture);
712 ASSERT_GL_NO_ERROR();
713 }
714
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400715 void testTearDown() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400716 {
717 glDeleteTextures(1, &m2DArrayTexture);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400718 TexCoordDrawTest::testTearDown();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400719 }
720
721 GLuint m2DArrayTexture;
Jamie Madill2453dbc2015-07-14 11:35:42 -0400722 GLint mTextureArrayLocation;
723};
724
Olli Etuahobce743a2016-01-15 17:18:28 +0200725class TextureSizeTextureArrayTest : public TexCoordDrawTest
726{
727 protected:
728 TextureSizeTextureArrayTest()
729 : TexCoordDrawTest(),
730 mTexture2DA(0),
731 mTexture2DB(0),
732 mTexture0Location(-1),
733 mTexture1Location(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500734 {}
Olli Etuahobce743a2016-01-15 17:18:28 +0200735
Jamie Madill35cd7332018-12-02 12:03:33 -0500736 const char *getVertexShaderSource() override { return essl3_shaders::vs::Simple(); }
Olli Etuahobce743a2016-01-15 17:18:28 +0200737
Jamie Madill35cd7332018-12-02 12:03:33 -0500738 const char *getFragmentShaderSource() override
Olli Etuahobce743a2016-01-15 17:18:28 +0200739 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500740 return "#version 300 es\n"
741 "precision highp float;\n"
742 "uniform highp sampler2D tex2DArray[2];\n"
743 "out vec4 fragColor;\n"
744 "void main()\n"
745 "{\n"
746 " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n"
747 " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n"
748 " fragColor = vec4(red, green, 0.0, 1.0);\n"
749 "}\n";
Olli Etuahobce743a2016-01-15 17:18:28 +0200750 }
751
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400752 void testSetUp() override
Olli Etuahobce743a2016-01-15 17:18:28 +0200753 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400754 TexCoordDrawTest::testSetUp();
Olli Etuahobce743a2016-01-15 17:18:28 +0200755
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300756 setUpProgram();
757
Olli Etuahobce743a2016-01-15 17:18:28 +0200758 mTexture0Location = glGetUniformLocation(mProgram, "tex2DArray[0]");
759 ASSERT_NE(-1, mTexture0Location);
760 mTexture1Location = glGetUniformLocation(mProgram, "tex2DArray[1]");
761 ASSERT_NE(-1, mTexture1Location);
762
763 mTexture2DA = create2DTexture();
764 mTexture2DB = create2DTexture();
765 ASSERT_GL_NO_ERROR();
766 }
767
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400768 void testTearDown() override
Olli Etuahobce743a2016-01-15 17:18:28 +0200769 {
770 glDeleteTextures(1, &mTexture2DA);
771 glDeleteTextures(1, &mTexture2DB);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400772 TexCoordDrawTest::testTearDown();
Olli Etuahobce743a2016-01-15 17:18:28 +0200773 }
774
775 GLuint mTexture2DA;
776 GLuint mTexture2DB;
777 GLint mTexture0Location;
778 GLint mTexture1Location;
779};
780
Olli Etuahoa314b612016-03-10 16:43:00 +0200781class Texture3DTestES3 : public TexCoordDrawTest
782{
783 protected:
784 Texture3DTestES3() : TexCoordDrawTest(), mTexture3D(0), mTexture3DUniformLocation(-1) {}
785
Jamie Madill35cd7332018-12-02 12:03:33 -0500786 const char *getVertexShaderSource() override
Olli Etuahoa314b612016-03-10 16:43:00 +0200787 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500788 return "#version 300 es\n"
789 "out vec2 texcoord;\n"
790 "in vec4 position;\n"
791 "void main()\n"
792 "{\n"
793 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
794 " texcoord = (position.xy * 0.5) + 0.5;\n"
795 "}\n";
Olli Etuahoa314b612016-03-10 16:43:00 +0200796 }
797
Jamie Madill35cd7332018-12-02 12:03:33 -0500798 const char *getFragmentShaderSource() override
Olli Etuahoa314b612016-03-10 16:43:00 +0200799 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500800 return "#version 300 es\n"
801 "precision highp float;\n"
802 "uniform highp sampler3D tex3D;\n"
803 "in vec2 texcoord;\n"
804 "out vec4 fragColor;\n"
805 "void main()\n"
806 "{\n"
807 " fragColor = texture(tex3D, vec3(texcoord, 0.0));\n"
808 "}\n";
Olli Etuahoa314b612016-03-10 16:43:00 +0200809 }
810
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400811 void testSetUp() override
Olli Etuahoa314b612016-03-10 16:43:00 +0200812 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400813 TexCoordDrawTest::testSetUp();
Olli Etuahoa314b612016-03-10 16:43:00 +0200814
815 glGenTextures(1, &mTexture3D);
816
817 setUpProgram();
818
819 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
820 ASSERT_NE(-1, mTexture3DUniformLocation);
821 }
822
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400823 void testTearDown() override
Olli Etuahoa314b612016-03-10 16:43:00 +0200824 {
825 glDeleteTextures(1, &mTexture3D);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400826 TexCoordDrawTest::testTearDown();
Olli Etuahoa314b612016-03-10 16:43:00 +0200827 }
828
829 GLuint mTexture3D;
830 GLint mTexture3DUniformLocation;
831};
832
Olli Etuaho1a679902016-01-14 12:21:47 +0200833class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest
834{
835 protected:
836 ShadowSamplerPlusSampler3DTestES3()
837 : TexCoordDrawTest(),
838 mTextureShadow(0),
839 mTexture3D(0),
840 mTextureShadowUniformLocation(-1),
841 mTexture3DUniformLocation(-1),
842 mDepthRefUniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500843 {}
Olli Etuaho1a679902016-01-14 12:21:47 +0200844
Jamie Madill35cd7332018-12-02 12:03:33 -0500845 const char *getVertexShaderSource() override
Olli Etuaho1a679902016-01-14 12:21:47 +0200846 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500847 return "#version 300 es\n"
848 "out vec2 texcoord;\n"
849 "in vec4 position;\n"
850 "void main()\n"
851 "{\n"
852 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
853 " texcoord = (position.xy * 0.5) + 0.5;\n"
854 "}\n";
Olli Etuaho1a679902016-01-14 12:21:47 +0200855 }
856
Jamie Madill35cd7332018-12-02 12:03:33 -0500857 const char *getFragmentShaderSource() override
Olli Etuaho1a679902016-01-14 12:21:47 +0200858 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500859 return "#version 300 es\n"
860 "precision highp float;\n"
861 "uniform highp sampler2DShadow tex2DShadow;\n"
862 "uniform highp sampler3D tex3D;\n"
863 "in vec2 texcoord;\n"
864 "uniform float depthRef;\n"
865 "out vec4 fragColor;\n"
866 "void main()\n"
867 "{\n"
868 " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n"
869 " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n"
870 "}\n";
Olli Etuaho1a679902016-01-14 12:21:47 +0200871 }
872
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400873 void testSetUp() override
Olli Etuaho1a679902016-01-14 12:21:47 +0200874 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400875 TexCoordDrawTest::testSetUp();
Olli Etuaho1a679902016-01-14 12:21:47 +0200876
877 glGenTextures(1, &mTexture3D);
878
879 glGenTextures(1, &mTextureShadow);
880 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
881 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
882
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300883 setUpProgram();
884
Olli Etuaho1a679902016-01-14 12:21:47 +0200885 mTextureShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
886 ASSERT_NE(-1, mTextureShadowUniformLocation);
887 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
888 ASSERT_NE(-1, mTexture3DUniformLocation);
889 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
890 ASSERT_NE(-1, mDepthRefUniformLocation);
891 }
892
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400893 void testTearDown() override
Olli Etuaho1a679902016-01-14 12:21:47 +0200894 {
895 glDeleteTextures(1, &mTextureShadow);
896 glDeleteTextures(1, &mTexture3D);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400897 TexCoordDrawTest::testTearDown();
Olli Etuaho1a679902016-01-14 12:21:47 +0200898 }
899
900 GLuint mTextureShadow;
901 GLuint mTexture3D;
902 GLint mTextureShadowUniformLocation;
903 GLint mTexture3DUniformLocation;
904 GLint mDepthRefUniformLocation;
905};
906
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200907class SamplerTypeMixTestES3 : public TexCoordDrawTest
908{
909 protected:
910 SamplerTypeMixTestES3()
911 : TexCoordDrawTest(),
912 mTexture2D(0),
913 mTextureCube(0),
914 mTexture2DShadow(0),
915 mTextureCubeShadow(0),
916 mTexture2DUniformLocation(-1),
917 mTextureCubeUniformLocation(-1),
918 mTexture2DShadowUniformLocation(-1),
919 mTextureCubeShadowUniformLocation(-1),
920 mDepthRefUniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500921 {}
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200922
Jamie Madill35cd7332018-12-02 12:03:33 -0500923 const char *getVertexShaderSource() override
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200924 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500925 return "#version 300 es\n"
926 "out vec2 texcoord;\n"
927 "in vec4 position;\n"
928 "void main()\n"
929 "{\n"
930 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
931 " texcoord = (position.xy * 0.5) + 0.5;\n"
932 "}\n";
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200933 }
934
Jamie Madill35cd7332018-12-02 12:03:33 -0500935 const char *getFragmentShaderSource() override
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200936 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500937 return "#version 300 es\n"
938 "precision highp float;\n"
939 "uniform highp sampler2D tex2D;\n"
940 "uniform highp samplerCube texCube;\n"
941 "uniform highp sampler2DShadow tex2DShadow;\n"
942 "uniform highp samplerCubeShadow texCubeShadow;\n"
943 "in vec2 texcoord;\n"
944 "uniform float depthRef;\n"
945 "out vec4 fragColor;\n"
946 "void main()\n"
947 "{\n"
948 " fragColor = texture(tex2D, texcoord);\n"
949 " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n"
950 " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n"
951 " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * "
952 "0.125);\n"
953 "}\n";
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200954 }
955
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400956 void testSetUp() override
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200957 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400958 TexCoordDrawTest::testSetUp();
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200959
960 glGenTextures(1, &mTexture2D);
961 glGenTextures(1, &mTextureCube);
962
963 glGenTextures(1, &mTexture2DShadow);
964 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
965 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
966
967 glGenTextures(1, &mTextureCubeShadow);
968 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
969 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
970
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300971 setUpProgram();
972
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200973 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
974 ASSERT_NE(-1, mTexture2DUniformLocation);
975 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
976 ASSERT_NE(-1, mTextureCubeUniformLocation);
977 mTexture2DShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
978 ASSERT_NE(-1, mTexture2DShadowUniformLocation);
979 mTextureCubeShadowUniformLocation = glGetUniformLocation(mProgram, "texCubeShadow");
980 ASSERT_NE(-1, mTextureCubeShadowUniformLocation);
981 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
982 ASSERT_NE(-1, mDepthRefUniformLocation);
983
984 ASSERT_GL_NO_ERROR();
985 }
986
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400987 void testTearDown() override
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200988 {
989 glDeleteTextures(1, &mTexture2D);
990 glDeleteTextures(1, &mTextureCube);
991 glDeleteTextures(1, &mTexture2DShadow);
992 glDeleteTextures(1, &mTextureCubeShadow);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400993 TexCoordDrawTest::testTearDown();
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200994 }
995
996 GLuint mTexture2D;
997 GLuint mTextureCube;
998 GLuint mTexture2DShadow;
999 GLuint mTextureCubeShadow;
1000 GLint mTexture2DUniformLocation;
1001 GLint mTextureCubeUniformLocation;
1002 GLint mTexture2DShadowUniformLocation;
1003 GLint mTextureCubeShadowUniformLocation;
1004 GLint mDepthRefUniformLocation;
1005};
1006
Olli Etuaho96963162016-03-21 11:54:33 +02001007class SamplerInStructTest : public Texture2DTest
1008{
1009 protected:
1010 SamplerInStructTest() : Texture2DTest() {}
1011
1012 const char *getTextureUniformName() override { return "us.tex"; }
1013
Jamie Madill35cd7332018-12-02 12:03:33 -05001014 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001015 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001016 return "precision highp float;\n"
1017 "struct S\n"
1018 "{\n"
1019 " vec4 a;\n"
1020 " highp sampler2D tex;\n"
1021 "};\n"
1022 "uniform S us;\n"
1023 "varying vec2 texcoord;\n"
1024 "void main()\n"
1025 "{\n"
1026 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x);\n"
1027 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001028 }
1029
1030 void runSamplerInStructTest()
1031 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001032 setUpProgram();
1033
Olli Etuaho96963162016-03-21 11:54:33 +02001034 glActiveTexture(GL_TEXTURE0);
1035 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001036 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1037 &GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001038 drawQuad(mProgram, "position", 0.5f);
Olli Etuahoa314b612016-03-10 16:43:00 +02001039 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001040 }
1041};
1042
1043class SamplerInStructAsFunctionParameterTest : public SamplerInStructTest
1044{
1045 protected:
1046 SamplerInStructAsFunctionParameterTest() : SamplerInStructTest() {}
1047
Jamie Madill35cd7332018-12-02 12:03:33 -05001048 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001049 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001050 return "precision highp float;\n"
1051 "struct S\n"
1052 "{\n"
1053 " vec4 a;\n"
1054 " highp sampler2D tex;\n"
1055 "};\n"
1056 "uniform S us;\n"
1057 "varying vec2 texcoord;\n"
1058 "vec4 sampleFrom(S s) {\n"
1059 " return texture2D(s.tex, texcoord + s.a.x);\n"
1060 "}\n"
1061 "void main()\n"
1062 "{\n"
1063 " gl_FragColor = sampleFrom(us);\n"
1064 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001065 }
1066};
1067
1068class SamplerInStructArrayAsFunctionParameterTest : public SamplerInStructTest
1069{
1070 protected:
1071 SamplerInStructArrayAsFunctionParameterTest() : SamplerInStructTest() {}
1072
1073 const char *getTextureUniformName() override { return "us[0].tex"; }
1074
Jamie Madill35cd7332018-12-02 12:03:33 -05001075 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001076 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001077 return "precision highp float;\n"
1078 "struct S\n"
1079 "{\n"
1080 " vec4 a;\n"
1081 " highp sampler2D tex;\n"
1082 "};\n"
1083 "uniform S us[1];\n"
1084 "varying vec2 texcoord;\n"
1085 "vec4 sampleFrom(S s) {\n"
1086 " return texture2D(s.tex, texcoord + s.a.x);\n"
1087 "}\n"
1088 "void main()\n"
1089 "{\n"
1090 " gl_FragColor = sampleFrom(us[0]);\n"
1091 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001092 }
1093};
1094
1095class SamplerInNestedStructAsFunctionParameterTest : public SamplerInStructTest
1096{
1097 protected:
1098 SamplerInNestedStructAsFunctionParameterTest() : SamplerInStructTest() {}
1099
1100 const char *getTextureUniformName() override { return "us[0].sub.tex"; }
1101
Jamie Madill35cd7332018-12-02 12:03:33 -05001102 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001103 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001104 return "precision highp float;\n"
1105 "struct SUB\n"
1106 "{\n"
1107 " vec4 a;\n"
1108 " highp sampler2D tex;\n"
1109 "};\n"
1110 "struct S\n"
1111 "{\n"
1112 " SUB sub;\n"
1113 "};\n"
1114 "uniform S us[1];\n"
1115 "varying vec2 texcoord;\n"
1116 "vec4 sampleFrom(SUB s) {\n"
1117 " return texture2D(s.tex, texcoord + s.a.x);\n"
1118 "}\n"
1119 "void main()\n"
1120 "{\n"
1121 " gl_FragColor = sampleFrom(us[0].sub);\n"
1122 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001123 }
1124};
1125
1126class SamplerInStructAndOtherVariableTest : public SamplerInStructTest
1127{
1128 protected:
1129 SamplerInStructAndOtherVariableTest() : SamplerInStructTest() {}
1130
Jamie Madill35cd7332018-12-02 12:03:33 -05001131 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001132 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001133 return "precision highp float;\n"
1134 "struct S\n"
1135 "{\n"
1136 " vec4 a;\n"
1137 " highp sampler2D tex;\n"
1138 "};\n"
1139 "uniform S us;\n"
1140 "uniform float us_tex;\n"
1141 "varying vec2 texcoord;\n"
1142 "void main()\n"
1143 "{\n"
1144 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x + us_tex);\n"
1145 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001146 }
1147};
1148
Anders Leinof6cbe442019-04-18 15:32:07 +03001149class Texture2DIntegerTestES3 : public Texture2DTest
1150{
1151 protected:
1152 Texture2DIntegerTestES3() : Texture2DTest() {}
1153
1154 const char *getVertexShaderSource() override
1155 {
1156 return "#version 300 es\n"
1157 "out vec2 texcoord;\n"
1158 "in vec4 position;\n"
1159 "void main()\n"
1160 "{\n"
1161 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1162 " texcoord = (position.xy * 0.5) + 0.5;\n"
1163 "}\n";
1164 }
1165
1166 const char *getFragmentShaderSource() override
1167 {
1168 return "#version 300 es\n"
1169 "precision highp float;\n"
1170 "precision highp usampler2D;\n"
1171 "uniform usampler2D tex;\n"
1172 "in vec2 texcoord;\n"
1173 "out vec4 fragColor;\n"
1174 "void main()\n"
1175 "{\n"
Anders Leino8224a582019-05-20 12:39:29 +03001176 " fragColor = vec4(texture(tex, texcoord))/255.0;\n"
Anders Leinof6cbe442019-04-18 15:32:07 +03001177 "}\n";
1178 }
1179};
1180
Anders Leino60cc7512019-05-06 09:25:27 +03001181class TextureCubeIntegerTestES3 : public TexCoordDrawTest
1182{
1183 protected:
1184 TextureCubeIntegerTestES3()
1185 : TexCoordDrawTest(), mTextureCube(0), mTextureCubeUniformLocation(-1)
1186 {}
1187
1188 const char *getVertexShaderSource() override
1189 {
1190 return "#version 300 es\n"
1191 "out vec2 texcoord;\n"
1192 "in vec4 position;\n"
1193 "void main()\n"
1194 "{\n"
1195 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1196 " texcoord = 0.5*position.xy;\n"
1197 "}\n";
1198 }
1199
1200 const char *getFragmentShaderSource() override
1201 {
1202 return "#version 300 es\n"
1203 "precision highp float;\n"
1204 "precision highp usamplerCube;\n"
1205 "uniform usamplerCube texCube;\n"
1206 "in vec2 texcoord;\n"
1207 "out vec4 fragColor;\n"
1208 "void main()\n"
1209 "{\n"
1210 " fragColor = vec4(texture(texCube, vec3(texcoord, 1)))/255.0;\n"
1211 "}\n";
1212 }
1213
1214 void testSetUp() override
1215 {
1216 TexCoordDrawTest::testSetUp();
1217 glGenTextures(1, &mTextureCube);
1218 setUpProgram();
1219
1220 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
1221 ASSERT_NE(-1, mTextureCubeUniformLocation);
1222 }
1223
1224 void testTearDown() override
1225 {
1226 glDeleteTextures(1, &mTextureCube);
1227 TexCoordDrawTest::testTearDown();
1228 }
1229
1230 GLuint mTextureCube;
1231 GLint mTextureCubeUniformLocation;
1232};
1233
Anders Leinoe4452442019-05-09 13:29:49 +03001234class TextureCubeIntegerEdgeTestES3 : public TextureCubeIntegerTestES3
1235{
1236 protected:
1237 TextureCubeIntegerEdgeTestES3() : TextureCubeIntegerTestES3() {}
1238
1239 const char *getVertexShaderSource() override
1240 {
1241 return "#version 300 es\n"
1242 "out vec2 texcoord;\n"
1243 "in vec4 position;\n"
1244 "void main()\n"
1245 "{\n"
1246 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1247 " texcoord = position.xy;\n"
1248 "}\n";
1249 }
1250
1251 const char *getFragmentShaderSource() override
1252 {
1253 return "#version 300 es\n"
1254 "precision highp float;\n"
1255 "precision highp usamplerCube;\n"
1256 "uniform usamplerCube texCube;\n"
1257 "in vec2 texcoord;\n"
1258 "out vec4 fragColor;\n"
1259 "void main()\n"
1260 "{\n"
1261 " fragColor = vec4(texture(texCube, vec3(texcoord, 0)))/255.0;\n"
1262 "}\n";
1263 }
1264};
1265
Anders Leino1b6aded2019-05-20 12:56:34 +03001266class Texture2DIntegerProjectiveOffsetTestES3 : public Texture2DTest
1267{
1268 protected:
1269 Texture2DIntegerProjectiveOffsetTestES3() : Texture2DTest() {}
1270
1271 const char *getVertexShaderSource() override
1272 {
1273 return "#version 300 es\n"
1274 "out vec2 texcoord;\n"
1275 "in vec4 position;\n"
1276 "void main()\n"
1277 "{\n"
1278 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1279 " texcoord = 0.5*position.xy + vec2(0.5, 0.5);\n"
1280 "}\n";
1281 }
1282
1283 const char *getFragmentShaderSource() override
1284 {
1285 return "#version 300 es\n"
1286 "precision highp float;\n"
1287 "precision highp usampler2D;\n"
1288 "uniform usampler2D tex;\n"
1289 "in vec2 texcoord;\n"
1290 "out vec4 fragColor;\n"
1291 "void main()\n"
1292 "{\n"
1293 " fragColor = vec4(textureProjOffset(tex, vec3(texcoord, 1), ivec2(0,0), "
1294 "0.0))/255.0;\n"
1295 "}\n";
1296 }
1297};
1298
Anders Leino69d04932019-05-20 14:04:13 +03001299class Texture2DArrayIntegerTestES3 : public Texture2DArrayTestES3
1300{
1301 protected:
1302 Texture2DArrayIntegerTestES3() : Texture2DArrayTestES3() {}
1303
1304 const char *getVertexShaderSource() override
1305 {
1306 return "#version 300 es\n"
1307 "out vec2 texcoord;\n"
1308 "in vec4 position;\n"
1309 "void main()\n"
1310 "{\n"
1311 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1312 " texcoord = (position.xy * 0.5) + 0.5;\n"
1313 "}\n";
1314 }
1315
1316 const char *getFragmentShaderSource() override
1317 {
1318 return "#version 300 es\n"
1319 "precision highp float;\n"
1320 "uniform highp usampler2DArray tex2DArray;\n"
1321 "in vec2 texcoord;\n"
1322 "out vec4 fragColor;\n"
1323 "void main()\n"
1324 "{\n"
1325 " fragColor = vec4(texture(tex2DArray, vec3(texcoord.x, texcoord.y, "
1326 "0.0)))/255.0;\n"
1327 "}\n";
1328 }
1329};
1330
Anders Leino262e2822019-05-20 14:24:40 +03001331class Texture3DIntegerTestES3 : public Texture3DTestES3
1332{
1333 protected:
1334 Texture3DIntegerTestES3() : Texture3DTestES3() {}
1335
1336 const char *getVertexShaderSource() override
1337 {
1338 return "#version 300 es\n"
1339 "out vec2 texcoord;\n"
1340 "in vec4 position;\n"
1341 "void main()\n"
1342 "{\n"
1343 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1344 " texcoord = (position.xy * 0.5) + 0.5;\n"
1345 "}\n";
1346 }
1347
1348 const char *getFragmentShaderSource() override
1349 {
1350 return "#version 300 es\n"
1351 "precision highp float;\n"
1352 "uniform highp usampler3D tex3D;\n"
1353 "in vec2 texcoord;\n"
1354 "out vec4 fragColor;\n"
1355 "void main()\n"
1356 "{\n"
1357 " fragColor = vec4(texture(tex3D, vec3(texcoord, 0.0)))/255.0;\n"
1358 "}\n";
1359 }
1360};
1361
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001362TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001363{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001364 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001365 EXPECT_GL_ERROR(GL_NO_ERROR);
1366
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001367 setUpProgram();
1368
Jamie Madill50cf2be2018-06-15 09:46:57 -04001369 const GLubyte *pixels[20] = {0};
Jamie Madillf67115c2014-04-22 13:14:05 -04001370 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1371 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001372
Jamie Madillb8149072019-04-30 16:14:44 -04001373 if (IsGLExtensionEnabled("GL_EXT_texture_storage"))
Geoff Langc51642b2016-11-14 16:18:26 -05001374 {
1375 // Create a 1-level immutable texture.
1376 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1377
1378 // Try calling sub image on the second level.
1379 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1380 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1381 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001382}
Geoff Langc41e42d2014-04-28 10:58:16 -04001383
John Bauman18319182016-09-28 14:22:27 -07001384// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1385TEST_P(Texture2DTest, QueryBinding)
1386{
1387 glBindTexture(GL_TEXTURE_2D, 0);
1388 EXPECT_GL_ERROR(GL_NO_ERROR);
1389
1390 GLint textureBinding;
1391 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1392 EXPECT_GL_NO_ERROR();
1393 EXPECT_EQ(0, textureBinding);
1394
1395 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
Jamie Madillb8149072019-04-30 16:14:44 -04001396 if (IsGLExtensionEnabled("GL_OES_EGL_image_external") ||
1397 IsGLExtensionEnabled("GL_NV_EGL_stream_consumer_external"))
John Bauman18319182016-09-28 14:22:27 -07001398 {
1399 EXPECT_GL_NO_ERROR();
1400 EXPECT_EQ(0, textureBinding);
1401 }
1402 else
1403 {
1404 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1405 }
1406}
1407
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001408TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001409{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001410 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001411 EXPECT_GL_ERROR(GL_NO_ERROR);
1412
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001413 setUpProgram();
1414
Geoff Langc41e42d2014-04-28 10:58:16 -04001415 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001416 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001417 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001418 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001419
Jamie Madill50cf2be2018-06-15 09:46:57 -04001420 const GLubyte *pixel[4] = {0};
Geoff Langc41e42d2014-04-28 10:58:16 -04001421
1422 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1423 EXPECT_GL_NO_ERROR();
1424
1425 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1426 EXPECT_GL_NO_ERROR();
1427
1428 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1429 EXPECT_GL_NO_ERROR();
1430}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001431
1432// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001433TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001434{
1435 glActiveTexture(GL_TEXTURE0);
1436 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1437 glActiveTexture(GL_TEXTURE1);
1438 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1439 EXPECT_GL_ERROR(GL_NO_ERROR);
1440
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001441 glUseProgram(mProgram);
1442 glUniform1i(mTexture2DUniformLocation, 0);
1443 glUniform1i(mTextureCubeUniformLocation, 1);
1444 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001445 EXPECT_GL_NO_ERROR();
1446}
Jamie Madill9aca0592014-10-06 16:26:59 -04001447
Olli Etuaho53a2da12016-01-11 15:43:32 +02001448// Test drawing with two texture types accessed from the same shader and check that the result of
1449// drawing is correct.
1450TEST_P(TextureCubeTest, CubeMapDraw)
1451{
1452 GLubyte texData[4];
1453 texData[0] = 0;
1454 texData[1] = 60;
1455 texData[2] = 0;
1456 texData[3] = 255;
1457
1458 glActiveTexture(GL_TEXTURE0);
1459 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1460 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1461
1462 glActiveTexture(GL_TEXTURE1);
1463 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1464 texData[1] = 120;
1465 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1466 texData);
1467 EXPECT_GL_ERROR(GL_NO_ERROR);
1468
1469 glUseProgram(mProgram);
1470 glUniform1i(mTexture2DUniformLocation, 0);
1471 glUniform1i(mTextureCubeUniformLocation, 1);
1472 drawQuad(mProgram, "position", 0.5f);
1473 EXPECT_GL_NO_ERROR();
1474
1475 int px = getWindowWidth() - 1;
1476 int py = 0;
1477 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1478}
1479
Olli Etuaho4644a202016-01-12 15:12:53 +02001480TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1481{
1482 glActiveTexture(GL_TEXTURE0);
1483 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1484 GLubyte texData[4];
1485 texData[0] = 0;
1486 texData[1] = 128;
1487 texData[2] = 0;
1488 texData[3] = 255;
1489 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1490 glUseProgram(mProgram);
1491 glUniform1i(mTexture2DUniformLocation, 0);
1492 drawQuad(mProgram, "position", 0.5f);
1493 EXPECT_GL_NO_ERROR();
1494
1495 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1496}
1497
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001498// Test drawing with two textures passed to the shader in a sampler array.
1499TEST_P(SamplerArrayTest, SamplerArrayDraw)
1500{
1501 testSamplerArrayDraw();
1502}
1503
1504// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1505// user-defined function in the shader.
1506TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1507{
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05001508 // TODO: Diagnose and fix. http://anglebug.com/2955
1509 ANGLE_SKIP_TEST_IF(IsVulkan() && IsAndroid());
1510
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001511 testSamplerArrayDraw();
1512}
1513
Jamie Madill9aca0592014-10-06 16:26:59 -04001514// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001515TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001516{
1517 int px = getWindowWidth() / 2;
1518 int py = getWindowHeight() / 2;
1519
1520 glActiveTexture(GL_TEXTURE0);
1521 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1522
Olli Etuahoa314b612016-03-10 16:43:00 +02001523 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001524
Olli Etuahoa314b612016-03-10 16:43:00 +02001525 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001526 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1527 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1528 glGenerateMipmap(GL_TEXTURE_2D);
1529
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001530 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001531 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001532 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1533 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001534 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001535 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001536
Olli Etuahoa314b612016-03-10 16:43:00 +02001537 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001538
Olli Etuahoa314b612016-03-10 16:43:00 +02001539 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1540 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001541 glGenerateMipmap(GL_TEXTURE_2D);
1542
Olli Etuahoa314b612016-03-10 16:43:00 +02001543 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001544
Olli Etuahoa314b612016-03-10 16:43:00 +02001545 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1546 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001547 glGenerateMipmap(GL_TEXTURE_2D);
1548
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001549 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001550
1551 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001552 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001553}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001554
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001555// Test creating a FBO with a cube map render target, to test an ANGLE bug
1556// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001557TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001558{
Michael Spangd8506c72019-01-29 15:35:09 -05001559 // http://anglebug.com/3145
1560 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
1561
Shahbaz Youssefi0c128e12019-03-25 23:50:14 -04001562 // http://anglebug.com/2822
1563 ANGLE_SKIP_TEST_IF(IsWindows() && IsIntel() && IsVulkan());
1564
Jamie Madill3f3b3582018-09-14 10:38:44 -04001565 GLFramebuffer fbo;
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001566 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1567
1568 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Jamie Madill50cf2be2018-06-15 09:46:57 -04001569 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1570 mTextureCube, 0);
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001571
Corentin Wallez322653b2015-06-17 18:33:56 +02001572 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001573 EXPECT_GL_NO_ERROR();
Jamie Madill3f3b3582018-09-14 10:38:44 -04001574
1575 // Test clearing the six mip faces individually.
1576 std::array<GLColor, 6> faceColors = {{GLColor::red, GLColor::green, GLColor::blue,
1577 GLColor::yellow, GLColor::cyan, GLColor::magenta}};
1578
1579 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1580 {
1581 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1582 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1583
1584 Vector4 clearColorF = faceColors[faceIndex].toNormalizedVector();
1585 glClearColor(clearColorF.x(), clearColorF.y(), clearColorF.z(), clearColorF.w());
1586 glClear(GL_COLOR_BUFFER_BIT);
1587
1588 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex]);
1589 }
1590
1591 // Iterate the faces again to make sure the colors haven't changed.
1592 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1593 {
1594 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1595 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1596 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex])
1597 << "face color " << faceIndex << " shouldn't change";
1598 }
1599}
1600
1601// Tests clearing a cube map with a scissor enabled.
1602TEST_P(TextureCubeTest, CubeMapFBOScissoredClear)
1603{
1604 // TODO(jie.a.chen): Diagnose and fix. http://anglebug.com/2822
1605 ANGLE_SKIP_TEST_IF(IsVulkan() && IsIntel() && IsWindows());
1606
Michael Spangd8506c72019-01-29 15:35:09 -05001607 // http://anglebug.com/3145
1608 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
1609
Jamie Madill3f3b3582018-09-14 10:38:44 -04001610 constexpr size_t kSize = 16;
1611
1612 GLFramebuffer fbo;
1613 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1614 glViewport(0, 0, kSize, kSize);
1615
1616 GLTexture texcube;
1617 glBindTexture(GL_TEXTURE_CUBE_MAP, texcube);
1618 for (GLenum face = 0; face < 6; face++)
1619 {
1620 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA,
1621 GL_UNSIGNED_BYTE, nullptr);
1622 }
1623 ASSERT_GL_NO_ERROR();
1624
1625 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1626 texcube, 0);
1627
1628 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1629 ASSERT_GL_NO_ERROR();
1630
1631 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1632 glClear(GL_COLOR_BUFFER_BIT);
1633 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1634
1635 glEnable(GL_SCISSOR_TEST);
1636 glScissor(kSize / 2, 0, kSize / 2, kSize);
1637 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
1638 glClear(GL_COLOR_BUFFER_BIT);
1639
1640 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1641 EXPECT_PIXEL_COLOR_EQ(kSize / 2 + 1, 0, GLColor::green);
1642
1643 ASSERT_GL_NO_ERROR();
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001644}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001645
Jamie Madill50cf2be2018-06-15 09:46:57 -04001646// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a
1647// default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001648TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001649{
Jamie Madillb8149072019-04-30 16:14:44 -04001650 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 &&
1651 !IsGLExtensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -04001652
Jamie Madill50cf2be2018-06-15 09:46:57 -04001653 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001654 int height = getWindowHeight();
1655
1656 GLuint tex2D;
1657 glGenTextures(1, &tex2D);
1658 glActiveTexture(GL_TEXTURE0);
1659 glBindTexture(GL_TEXTURE_2D, tex2D);
1660
1661 // Fill with red
1662 std::vector<GLubyte> pixels(3 * 16 * 16);
1663 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1664 {
1665 pixels[pixelId * 3 + 0] = 255;
1666 pixels[pixelId * 3 + 1] = 0;
1667 pixels[pixelId * 3 + 2] = 0;
1668 }
1669
1670 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001671 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1672 // 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 -04001673 if (getClientMajorVersion() >= 3)
1674 {
1675 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1676 }
1677 else
1678 {
1679 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1680 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001681
1682 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1683 // glTexSubImage2D should take into account that the image is dirty.
1684 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1685 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1686 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1687
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001688 setUpProgram();
1689
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001690 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001691 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001692 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001693 glDeleteTextures(1, &tex2D);
1694 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001695 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001696
1697 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001698 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1699 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001700}
1701
Jamie Madill50cf2be2018-06-15 09:46:57 -04001702// Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has
1703// initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001704TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001705{
Jamie Madillb8149072019-04-30 16:14:44 -04001706 if (IsGLExtensionEnabled("NV_pixel_buffer_object"))
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001707 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04001708 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001709 int height = getWindowHeight();
1710
1711 GLuint tex2D;
1712 glGenTextures(1, &tex2D);
1713 glActiveTexture(GL_TEXTURE0);
1714 glBindTexture(GL_TEXTURE_2D, tex2D);
1715
1716 // Fill with red
1717 std::vector<GLubyte> pixels(3 * 16 * 16);
1718 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1719 {
1720 pixels[pixelId * 3 + 0] = 255;
1721 pixels[pixelId * 3 + 1] = 0;
1722 pixels[pixelId * 3 + 2] = 0;
1723 }
1724
1725 // Read 16x16 region from red backbuffer to PBO
1726 GLuint pbo;
1727 glGenBuffers(1, &pbo);
1728 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1729 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1730
1731 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001732 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1733 // 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 +00001734 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1735
1736 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1737 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001738 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 +00001739 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1740 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1741
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001742 setUpProgram();
1743
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001744 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001745 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001746 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001747 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001748 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001749 EXPECT_GL_NO_ERROR();
1750 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1751 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1752 }
1753}
Jamie Madillbc393df2015-01-29 13:46:07 -05001754
1755// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001756TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001757{
1758 testFloatCopySubImage(1, 1);
1759}
1760
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001761TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001762{
1763 testFloatCopySubImage(2, 1);
1764}
1765
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001766TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001767{
1768 testFloatCopySubImage(2, 2);
1769}
1770
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001771TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001772{
1773 testFloatCopySubImage(3, 1);
1774}
1775
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001776TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001777{
1778 testFloatCopySubImage(3, 2);
1779}
1780
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001781TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001782{
Yunchao He9550c602018-02-13 14:47:05 +08001783 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1784 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001785
Yunchao He9550c602018-02-13 14:47:05 +08001786 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1787 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001788
Jamie Madillbc393df2015-01-29 13:46:07 -05001789 testFloatCopySubImage(3, 3);
1790}
1791
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001792TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001793{
1794 testFloatCopySubImage(4, 1);
1795}
1796
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001797TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001798{
1799 testFloatCopySubImage(4, 2);
1800}
1801
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001802TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001803{
Yunchao He9550c602018-02-13 14:47:05 +08001804 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1805 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001806
Jamie Madillbc393df2015-01-29 13:46:07 -05001807 testFloatCopySubImage(4, 3);
1808}
1809
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001810TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001811{
Luc Ferronf786b702018-07-10 11:01:43 -04001812 // TODO(lucferron): This test fails only on linux and intel.
1813 // http://anglebug.com/2726
1814 ANGLE_SKIP_TEST_IF(IsVulkan() && IsLinux() && IsIntel());
1815
Yunchao He9550c602018-02-13 14:47:05 +08001816 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1817 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001818
Jamie Madillbc393df2015-01-29 13:46:07 -05001819 testFloatCopySubImage(4, 4);
1820}
Austin Kinross07285142015-03-26 11:36:16 -07001821
Jamie Madill50cf2be2018-06-15 09:46:57 -04001822// Port of
1823// https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1824// Run against GL_ALPHA/UNSIGNED_BYTE format, to ensure that D3D11 Feature Level 9_3 correctly
1825// handles GL_ALPHA
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001826TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001827{
1828 const int npotTexSize = 5;
Jamie Madill50cf2be2018-06-15 09:46:57 -04001829 const int potTexSize = 4; // Should be less than npotTexSize
Austin Kinross07285142015-03-26 11:36:16 -07001830 GLuint tex2D;
1831
Jamie Madillb8149072019-04-30 16:14:44 -04001832 if (IsGLExtensionEnabled("GL_OES_texture_npot"))
Austin Kinross07285142015-03-26 11:36:16 -07001833 {
1834 // This test isn't applicable if texture_npot is enabled
1835 return;
1836 }
1837
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001838 setUpProgram();
1839
Austin Kinross07285142015-03-26 11:36:16 -07001840 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1841
Austin Kinross5faa15b2016-01-11 13:32:48 -08001842 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1843 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1844
Austin Kinross07285142015-03-26 11:36:16 -07001845 glActiveTexture(GL_TEXTURE0);
1846 glGenTextures(1, &tex2D);
1847 glBindTexture(GL_TEXTURE_2D, tex2D);
1848
Till Rathmannc1551dc2018-08-15 17:04:49 +02001849 const std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize, 64);
Austin Kinross07285142015-03-26 11:36:16 -07001850
1851 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1852 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1853
1854 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
Jamie Madill50cf2be2018-06-15 09:46:57 -04001855 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1856 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001857 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1858
1859 // Check that an NPOT texture on level 0 succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001860 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1861 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001862 EXPECT_GL_NO_ERROR();
1863
1864 // Check that generateMipmap fails on NPOT
1865 glGenerateMipmap(GL_TEXTURE_2D);
1866 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1867
1868 // Check that nothing is drawn if filtering is not correct for NPOT
1869 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1870 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1871 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1872 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1873 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001874 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001875 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1876
1877 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1878 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1879 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1880 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1881 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001882 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001883 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1884
1885 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1886 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1887 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001888 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001889 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1890
1891 // Check that glTexImage2D for POT texture succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001892 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE,
1893 pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001894 EXPECT_GL_NO_ERROR();
1895
1896 // Check that generateMipmap for an POT texture succeeds
1897 glGenerateMipmap(GL_TEXTURE_2D);
1898 EXPECT_GL_NO_ERROR();
1899
1900 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1901 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1902 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1903 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1904 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1905 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001906 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001907 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1908 EXPECT_GL_NO_ERROR();
1909}
Jamie Madillfa05f602015-05-07 13:47:11 -04001910
Austin Kinross08528e12015-10-07 16:24:40 -07001911// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1912// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001913TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001914{
1915 glActiveTexture(GL_TEXTURE0);
1916 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1917
1918 // Create an 8x8 (i.e. power-of-two) texture.
1919 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1920 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1921 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1922 glGenerateMipmap(GL_TEXTURE_2D);
1923
1924 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1925 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001926 std::array<GLColor, 3 * 3> data;
1927 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001928
1929 EXPECT_GL_NO_ERROR();
1930}
1931
Geoff Lang3702d8c2019-04-08 13:44:06 -04001932// Regression test for http://crbug.com/949985 to make sure dirty bits are propagated up from
1933// TextureImpl and the texture is synced before being used in a draw call.
1934TEST_P(Texture2DTestES3, TextureImplPropogatesDirtyBits)
1935{
1936 ANGLE_SKIP_TEST_IF(IsIntel() && IsOpenGL());
Yuly Novikove6b23e42019-04-10 17:19:15 -04001937 // Flaky hangs on Win10 AMD RX 550 GL. http://anglebug.com/3371
1938 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsOpenGL());
Geoff Lang3702d8c2019-04-08 13:44:06 -04001939
1940 // The workaround in the GL backend required to trigger this bug generates driver warning
1941 // messages.
1942 ScopedIgnorePlatformMessages ignoreMessages;
1943
1944 setUpProgram();
1945 glUseProgram(mProgram);
1946 glActiveTexture(GL_TEXTURE0 + mTexture2DUniformLocation);
1947
1948 GLTexture dest;
1949 glBindTexture(GL_TEXTURE_2D, dest);
1950
1951 GLTexture source;
1952 glBindTexture(GL_TEXTURE_2D, source);
1953
1954 // Put data in mip 0 and 1
1955 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1956 GLColor::red.data());
1957 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1958 GLColor::green.data());
1959
1960 // Disable mipmapping so source is complete
1961 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1962 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1963
1964 // Force the dirty bits to be synchronized in source
1965 drawQuad(mProgram, "position", 1.0f);
1966
1967 // Copy from mip 1 of the source. In the GL backend this internally sets the base level to mip
1968 // 1 and sets a dirty bit.
1969 glCopyTextureCHROMIUM(source, 1, GL_TEXTURE_2D, dest, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_FALSE,
1970 GL_FALSE, GL_FALSE);
1971
1972 // Draw again, assertions are generated if the texture has internal dirty bits at draw time
1973 drawQuad(mProgram, "position", 1.0f);
1974}
1975
Geoff Lang6f691fb2019-04-25 11:01:52 -04001976// This test case changes the base level of a texture that's attached to a framebuffer, clears every
1977// level to green, and then samples the texture when rendering. Test is taken from
1978// https://www.khronos.org/registry/webgl/sdk/tests/conformance2/rendering/framebuffer-texture-changing-base-level.html
1979TEST_P(Texture2DTestES3, FramebufferTextureChangingBaselevel)
1980{
1981 // TODO(geofflang): Investigate on D3D11. http://anglebug.com/2291
1982 ANGLE_SKIP_TEST_IF(IsD3D11());
1983
1984 setUpProgram();
1985
1986 constexpr GLint width = 8;
1987 constexpr GLint height = 4;
1988
1989 GLTexture texture;
1990 glBindTexture(GL_TEXTURE_2D, texture);
1991 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1992 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1993 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1994 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1995
1996 // Create all mipmap levels for the texture from level 0 to the 1x1 pixel level.
1997 GLint level = 0;
1998 GLint levelW = width;
1999 GLint levelH = height;
2000 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, levelW, levelH, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2001 nullptr);
2002 while (levelW > 1 || levelH > 1)
2003 {
2004 ++level;
2005 levelW = static_cast<GLint>(std::max(1.0, std::floor(width / std::pow(2, level))));
2006 levelH = static_cast<GLint>(std::max(1.0, std::floor(height / std::pow(2, level))));
2007 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, levelW, levelH, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2008 nullptr);
2009 }
2010
2011 // Clear each level of the texture using an FBO. Change the base level to match the level used
2012 // for the FBO on each iteration.
2013 GLFramebuffer fbo;
2014 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
2015 level = 0;
2016 levelW = width;
2017 levelH = height;
2018 while (levelW > 1 || levelH > 1)
2019 {
2020 levelW = static_cast<GLint>(std::floor(width / std::pow(2, level)));
2021 levelH = static_cast<GLint>(std::floor(height / std::pow(2, level)));
2022
2023 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, level);
2024 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, level);
2025
2026 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2027 EXPECT_GL_NO_ERROR();
2028
2029 glClearColor(0, 1, 0, 1);
2030 glClear(GL_COLOR_BUFFER_BIT);
2031
2032 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2033
2034 ++level;
2035 }
2036
2037 glBindFramebuffer(GL_FRAMEBUFFER, 0);
2038 glViewport(0, 0, 16, 16);
2039 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2040
2041 drawQuad(mProgram, "position", 0.5f);
2042
2043 EXPECT_GL_NO_ERROR();
2044 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2045}
2046
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002047// Test to check that texture completeness is determined correctly when the texture base level is
2048// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
2049TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
2050{
2051 glActiveTexture(GL_TEXTURE0);
2052 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02002053
2054 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
2055 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
2056 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2057 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2058 texDataGreen.data());
2059 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2060 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002061 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2062 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2063 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2064
2065 EXPECT_GL_NO_ERROR();
2066
2067 drawQuad(mProgram, "position", 0.5f);
2068
Olli Etuahoa314b612016-03-10 16:43:00 +02002069 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2070}
2071
2072// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2073// have images defined.
2074TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
2075{
Yunchao He9550c602018-02-13 14:47:05 +08002076 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
2077 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
2078
Olli Etuahoa314b612016-03-10 16:43:00 +02002079 glActiveTexture(GL_TEXTURE0);
2080 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2081 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2082 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2083 texDataGreen.data());
2084 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2085 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2086 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2087 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2088
2089 EXPECT_GL_NO_ERROR();
2090
2091 drawQuad(mProgram, "position", 0.5f);
2092
2093 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2094}
2095
Olli Etuahoe8528d82016-05-16 17:50:52 +03002096// Test that drawing works correctly when level 0 is undefined and base level is 1.
2097TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
2098{
Yunchao He9550c602018-02-13 14:47:05 +08002099 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
2100 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
2101
Olli Etuahoe8528d82016-05-16 17:50:52 +03002102 glActiveTexture(GL_TEXTURE0);
2103 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2104 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2105 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2106 texDataGreen.data());
2107 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2108 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2109 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2110 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2111
2112 EXPECT_GL_NO_ERROR();
2113
2114 // Texture is incomplete.
2115 drawQuad(mProgram, "position", 0.5f);
2116 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2117
2118 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2119 texDataGreen.data());
2120
2121 // Texture is now complete.
2122 drawQuad(mProgram, "position", 0.5f);
2123 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2124}
2125
Olli Etuahoa314b612016-03-10 16:43:00 +02002126// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2127// dimensions that don't fit the images inside the range.
2128// GLES 3.0.4 section 3.8.13 Texture completeness
2129TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2130{
Olli Etuahoa314b612016-03-10 16:43:00 +02002131 glActiveTexture(GL_TEXTURE0);
2132 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2133 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
2134 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2135 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
2136
2137 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2138 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2139
2140 // Two levels that are initially unused.
2141 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
2142 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2143 texDataCyan.data());
2144
2145 // One level that is used - only this level should affect completeness.
2146 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2147 texDataGreen.data());
2148
2149 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2150 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2151
2152 EXPECT_GL_NO_ERROR();
2153
2154 drawQuad(mProgram, "position", 0.5f);
2155
2156 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2157
Yunchao He2f23f352018-02-11 22:11:37 +08002158 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02002159
2160 // Switch the level that is being used to the cyan level 2.
2161 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2162 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2163
2164 EXPECT_GL_NO_ERROR();
2165
2166 drawQuad(mProgram, "position", 0.5f);
2167
2168 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2169}
2170
2171// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2172// have images defined.
2173TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
2174{
Olli Etuahoa314b612016-03-10 16:43:00 +02002175 glActiveTexture(GL_TEXTURE0);
2176 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2177 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2178 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2179 texDataGreen.data());
2180 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2181 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2182 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
2183 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2184
2185 EXPECT_GL_NO_ERROR();
2186
2187 drawQuad(mProgram, "position", 0.5f);
2188
2189 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2190}
2191
2192// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2193// dimensions that don't fit the images inside the range.
2194// GLES 3.0.4 section 3.8.13 Texture completeness
2195TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2196{
Olli Etuahoa314b612016-03-10 16:43:00 +02002197 glActiveTexture(GL_TEXTURE0);
2198 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2199 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2200 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2201 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2202
2203 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2204 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2205
2206 // Two levels that are initially unused.
2207 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2208 texDataRed.data());
2209 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2210 texDataCyan.data());
2211
2212 // One level that is used - only this level should affect completeness.
2213 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2214 texDataGreen.data());
2215
2216 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
2217 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2218
2219 EXPECT_GL_NO_ERROR();
2220
2221 drawQuad(mProgram, "position", 0.5f);
2222
2223 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2224
Yunchao He2f23f352018-02-11 22:11:37 +08002225 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02002226
2227 // Switch the level that is being used to the cyan level 2.
2228 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
2229 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
2230
2231 EXPECT_GL_NO_ERROR();
2232
2233 drawQuad(mProgram, "position", 0.5f);
2234
2235 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2236}
2237
2238// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2239// have images defined.
2240TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
2241{
Olli Etuahoa314b612016-03-10 16:43:00 +02002242 glActiveTexture(GL_TEXTURE0);
2243 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
2244 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2245 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2246 texDataGreen.data());
2247 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2248 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2249 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2250 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2251
2252 EXPECT_GL_NO_ERROR();
2253
2254 drawQuad(mProgram, "position", 0.5f);
2255
2256 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2257}
2258
2259// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2260// dimensions that don't fit the images inside the range.
2261// GLES 3.0.4 section 3.8.13 Texture completeness
2262TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2263{
Olli Etuahoa314b612016-03-10 16:43:00 +02002264 glActiveTexture(GL_TEXTURE0);
2265 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
2266 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2267 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2268 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2269
2270 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2271 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2272
2273 // Two levels that are initially unused.
2274 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2275 texDataRed.data());
2276 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2277 texDataCyan.data());
2278
2279 // One level that is used - only this level should affect completeness.
2280 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2281 texDataGreen.data());
2282
2283 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2284 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2285
2286 EXPECT_GL_NO_ERROR();
2287
2288 drawQuad(mProgram, "position", 0.5f);
2289
2290 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2291
Yunchao He2f23f352018-02-11 22:11:37 +08002292 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
2293
Yunchao He9550c602018-02-13 14:47:05 +08002294 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
2295 // level was changed.
2296 ANGLE_SKIP_TEST_IF(IsNVIDIA() && (IsOpenGL() || IsOpenGLES()));
Olli Etuahoa314b612016-03-10 16:43:00 +02002297
2298 // Switch the level that is being used to the cyan level 2.
2299 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2300 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2301
2302 EXPECT_GL_NO_ERROR();
2303
2304 drawQuad(mProgram, "position", 0.5f);
2305
2306 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2307}
2308
2309// Test that texture completeness is updated if texture max level changes.
2310// GLES 3.0.4 section 3.8.13 Texture completeness
2311TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2312{
Olli Etuahoa314b612016-03-10 16:43:00 +02002313 glActiveTexture(GL_TEXTURE0);
2314 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2315 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2316
2317 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2318 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2319
2320 // A level that is initially unused.
2321 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2322 texDataGreen.data());
2323
2324 // One level that is initially used - only this level should affect completeness.
2325 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2326 texDataGreen.data());
2327
2328 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2329 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2330
2331 EXPECT_GL_NO_ERROR();
2332
2333 drawQuad(mProgram, "position", 0.5f);
2334
2335 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2336
2337 // Switch the max level to level 1. The levels within the used range now have inconsistent
2338 // dimensions and the texture should be incomplete.
2339 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2340
2341 EXPECT_GL_NO_ERROR();
2342
2343 drawQuad(mProgram, "position", 0.5f);
2344
2345 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2346}
2347
2348// Test that 3D texture completeness is updated if texture max level changes.
2349// GLES 3.0.4 section 3.8.13 Texture completeness
2350TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2351{
Olli Etuahoa314b612016-03-10 16:43:00 +02002352 glActiveTexture(GL_TEXTURE0);
2353 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2354 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2355
2356 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2357 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2358
2359 // A level that is initially unused.
2360 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2361 texDataGreen.data());
2362
2363 // One level that is initially used - only this level should affect completeness.
2364 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2365 texDataGreen.data());
2366
2367 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2368 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2369
2370 EXPECT_GL_NO_ERROR();
2371
2372 drawQuad(mProgram, "position", 0.5f);
2373
2374 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2375
2376 // Switch the max level to level 1. The levels within the used range now have inconsistent
2377 // dimensions and the texture should be incomplete.
2378 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2379
2380 EXPECT_GL_NO_ERROR();
2381
2382 drawQuad(mProgram, "position", 0.5f);
2383
2384 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2385}
2386
2387// Test that texture completeness is updated if texture base level changes.
2388// GLES 3.0.4 section 3.8.13 Texture completeness
2389TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2390{
Olli Etuahoa314b612016-03-10 16:43:00 +02002391 glActiveTexture(GL_TEXTURE0);
2392 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2393 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2394
2395 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2396 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2397
2398 // Two levels that are initially unused.
2399 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2400 texDataGreen.data());
2401 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2402 texDataGreen.data());
2403
2404 // One level that is initially used - only this level should affect completeness.
2405 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2406 texDataGreen.data());
2407
2408 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2409 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2410
2411 EXPECT_GL_NO_ERROR();
2412
2413 drawQuad(mProgram, "position", 0.5f);
2414
2415 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2416
2417 // Switch the base level to level 1. The levels within the used range now have inconsistent
2418 // dimensions and the texture should be incomplete.
2419 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2420
2421 EXPECT_GL_NO_ERROR();
2422
2423 drawQuad(mProgram, "position", 0.5f);
2424
2425 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2426}
2427
2428// Test that texture is not complete if base level is greater than max level.
2429// GLES 3.0.4 section 3.8.13 Texture completeness
2430TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2431{
Olli Etuahoa314b612016-03-10 16:43:00 +02002432 glActiveTexture(GL_TEXTURE0);
2433 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2434
2435 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2436 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2437
2438 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2439
2440 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2441 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2442
2443 EXPECT_GL_NO_ERROR();
2444
2445 drawQuad(mProgram, "position", 0.5f);
2446
2447 // Texture should be incomplete.
2448 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2449}
2450
2451// Test that immutable texture base level and max level are clamped.
2452// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2453TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2454{
Olli Etuahoa314b612016-03-10 16:43:00 +02002455 glActiveTexture(GL_TEXTURE0);
2456 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2457
2458 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2459 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2460
2461 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2462
2463 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2464
2465 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2466 // should be clamped to [base_level, levels - 1].
2467 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2468 // In the case of this test, those rules make the effective base level and max level 0.
2469 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2470 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2471
2472 EXPECT_GL_NO_ERROR();
2473
2474 drawQuad(mProgram, "position", 0.5f);
2475
2476 // Texture should be complete.
2477 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2478}
2479
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002480// Test that changing base level works when it affects the format of the texture.
2481TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2482{
Yunchao He9550c602018-02-13 14:47:05 +08002483 // Observed rendering corruption on NVIDIA OpenGL.
2484 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL());
2485
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002486 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002487
2488 // Observed incorrect rendering on AMD OpenGL.
2489 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002490
2491 glActiveTexture(GL_TEXTURE0);
2492 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2493 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2494 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2495
2496 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2497 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2498
2499 // RGBA8 level that's initially unused.
2500 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2501 texDataCyan.data());
2502
2503 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2504 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2505
2506 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2507 // format. It reads green channel data from the green and alpha channels of texDataGreen
2508 // (this is a bit hacky but works).
2509 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2510
2511 EXPECT_GL_NO_ERROR();
2512
2513 drawQuad(mProgram, "position", 0.5f);
2514
2515 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2516
2517 // Switch the texture to use the cyan level 0 with the RGBA format.
2518 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2519 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2520
2521 EXPECT_GL_NO_ERROR();
2522
2523 drawQuad(mProgram, "position", 0.5f);
2524
2525 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2526}
2527
Olli Etuahoa314b612016-03-10 16:43:00 +02002528// Test that setting a texture image works when base level is out of range.
2529TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2530{
2531 glActiveTexture(GL_TEXTURE0);
2532 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2533
2534 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2535 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2536
2537 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2538 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2539
2540 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2541
2542 EXPECT_GL_NO_ERROR();
2543
2544 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2545
2546 drawQuad(mProgram, "position", 0.5f);
2547
2548 // Texture should be complete.
2549 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002550}
2551
Jamie Madill50cf2be2018-06-15 09:46:57 -04002552// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG
2553// RBA->RGBA8, with 1.0 in the alpha channel. This test covers a bug where redefining array textures
2554// with these formats does not work as expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002555TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002556{
2557 std::vector<GLubyte> pixelData;
2558 for (size_t count = 0; count < 5000; count++)
2559 {
2560 pixelData.push_back(0u);
2561 pixelData.push_back(255u);
2562 pixelData.push_back(0u);
2563 }
2564
2565 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002566 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002567 glUniform1i(mTextureArrayLocation, 0);
2568
2569 // The first draw worked correctly.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002570 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2571 &pixelData[0]);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002572
2573 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2574 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2575 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2576 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002577 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002578 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002579
2580 // The dimension of the respecification must match the original exactly to trigger the bug.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002581 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2582 &pixelData[0]);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002583 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002584 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002585
2586 ASSERT_GL_NO_ERROR();
2587}
2588
Olli Etuaho1a679902016-01-14 12:21:47 +02002589// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2590// This test is needed especially to confirm that sampler registers get assigned correctly on
2591// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2592TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2593{
2594 glActiveTexture(GL_TEXTURE0);
2595 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2596 GLubyte texData[4];
2597 texData[0] = 0;
2598 texData[1] = 60;
2599 texData[2] = 0;
2600 texData[3] = 255;
2601 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2602
2603 glActiveTexture(GL_TEXTURE1);
2604 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2605 GLfloat depthTexData[1];
2606 depthTexData[0] = 0.5f;
2607 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2608 depthTexData);
2609
2610 glUseProgram(mProgram);
2611 glUniform1f(mDepthRefUniformLocation, 0.3f);
2612 glUniform1i(mTexture3DUniformLocation, 0);
2613 glUniform1i(mTextureShadowUniformLocation, 1);
2614
2615 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2616 drawQuad(mProgram, "position", 0.5f);
2617 EXPECT_GL_NO_ERROR();
2618 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2619 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2620
2621 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2622 drawQuad(mProgram, "position", 0.5f);
2623 EXPECT_GL_NO_ERROR();
2624 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2625 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2626}
2627
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002628// Test multiple different sampler types in the same shader.
2629// This test makes sure that even if sampler / texture registers get grouped together based on type
2630// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2631// still has the right register index information for each ESSL sampler.
2632// The tested ESSL samplers have the following types in D3D11 HLSL:
2633// sampler2D: Texture2D + SamplerState
2634// samplerCube: TextureCube + SamplerState
2635// sampler2DShadow: Texture2D + SamplerComparisonState
2636// samplerCubeShadow: TextureCube + SamplerComparisonState
2637TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2638{
2639 glActiveTexture(GL_TEXTURE0);
2640 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2641 GLubyte texData[4];
2642 texData[0] = 0;
2643 texData[1] = 0;
2644 texData[2] = 120;
2645 texData[3] = 255;
2646 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2647
2648 glActiveTexture(GL_TEXTURE1);
2649 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2650 texData[0] = 0;
2651 texData[1] = 90;
2652 texData[2] = 0;
2653 texData[3] = 255;
2654 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2655 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2656 texData);
2657
2658 glActiveTexture(GL_TEXTURE2);
2659 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2660 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2661 GLfloat depthTexData[1];
2662 depthTexData[0] = 0.5f;
2663 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2664 depthTexData);
2665
2666 glActiveTexture(GL_TEXTURE3);
2667 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2668 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2669 depthTexData[0] = 0.2f;
2670 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2671 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2672 depthTexData);
2673
2674 EXPECT_GL_NO_ERROR();
2675
2676 glUseProgram(mProgram);
2677 glUniform1f(mDepthRefUniformLocation, 0.3f);
2678 glUniform1i(mTexture2DUniformLocation, 0);
2679 glUniform1i(mTextureCubeUniformLocation, 1);
2680 glUniform1i(mTexture2DShadowUniformLocation, 2);
2681 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2682
2683 drawQuad(mProgram, "position", 0.5f);
2684 EXPECT_GL_NO_ERROR();
2685 // The shader writes:
2686 // <texture 2d color> +
2687 // <cube map color> +
2688 // 0.25 * <comparison result (1.0)> +
2689 // 0.125 * <comparison result (0.0)>
2690 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2691}
2692
Olli Etuahobce743a2016-01-15 17:18:28 +02002693// Test different base levels on textures accessed through the same sampler array.
2694// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2695TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2696{
Yunchao He9550c602018-02-13 14:47:05 +08002697 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2698
Olli Etuahobce743a2016-01-15 17:18:28 +02002699 glActiveTexture(GL_TEXTURE0);
2700 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2701 GLsizei size = 64;
2702 for (GLint level = 0; level < 7; ++level)
2703 {
2704 ASSERT_LT(0, size);
2705 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2706 nullptr);
2707 size = size / 2;
2708 }
2709 ASSERT_EQ(0, size);
2710 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2711
2712 glActiveTexture(GL_TEXTURE1);
2713 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2714 size = 128;
2715 for (GLint level = 0; level < 8; ++level)
2716 {
2717 ASSERT_LT(0, size);
2718 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2719 nullptr);
2720 size = size / 2;
2721 }
2722 ASSERT_EQ(0, size);
2723 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2724 EXPECT_GL_NO_ERROR();
2725
2726 glUseProgram(mProgram);
2727 glUniform1i(mTexture0Location, 0);
2728 glUniform1i(mTexture1Location, 1);
2729
Olli Etuaho5804dc82018-04-13 14:11:46 +03002730 drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
Olli Etuahobce743a2016-01-15 17:18:28 +02002731 EXPECT_GL_NO_ERROR();
2732 // Red channel: width of level 1 of texture A: 32.
2733 // Green channel: width of level 3 of texture B: 16.
2734 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2735}
2736
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002737// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2738// ES 3.0.4 table 3.24
2739TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2740{
2741 glActiveTexture(GL_TEXTURE0);
2742 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2743 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2744 EXPECT_GL_NO_ERROR();
2745
2746 drawQuad(mProgram, "position", 0.5f);
2747
2748 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2749}
2750
2751// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2752// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002753TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002754{
Luc Ferron5164b792018-03-06 09:10:12 -05002755 setUpProgram();
2756
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002757 glActiveTexture(GL_TEXTURE0);
2758 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2759 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2760 EXPECT_GL_NO_ERROR();
2761
2762 drawQuad(mProgram, "position", 0.5f);
2763
2764 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2765}
2766
Luc Ferron5164b792018-03-06 09:10:12 -05002767// Validate that every component of the pixel will be equal to the luminance value we've set
2768// and that the alpha channel will be 1 (or 255 to be exact).
2769TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2770{
2771 setUpProgram();
2772
2773 glActiveTexture(GL_TEXTURE0);
2774 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2775 uint8_t pixel = 50;
2776 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2777 EXPECT_GL_NO_ERROR();
2778
2779 drawQuad(mProgram, "position", 0.5f);
2780
2781 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2782}
2783
2784// Validate that every component of the pixel will be equal to the luminance value we've set
2785// and that the alpha channel will be the second component.
2786TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2787{
2788 setUpProgram();
2789
2790 glActiveTexture(GL_TEXTURE0);
2791 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2792 uint8_t pixel[] = {50, 25};
2793 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2794 GL_UNSIGNED_BYTE, pixel);
2795 EXPECT_GL_NO_ERROR();
2796
2797 drawQuad(mProgram, "position", 0.5f);
2798
2799 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2800}
2801
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002802// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2803// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002804TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002805{
Jamie Madillb8149072019-04-30 16:14:44 -04002806 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002807 ANGLE_SKIP_TEST_IF(IsD3D9());
2808 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002809
2810 setUpProgram();
2811
Luc Ferrond8c632c2018-04-10 12:31:44 -04002812 glActiveTexture(GL_TEXTURE0);
2813 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2814 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2815 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002816
Luc Ferrond8c632c2018-04-10 12:31:44 -04002817 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002818
Luc Ferrond8c632c2018-04-10 12:31:44 -04002819 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002820}
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
Luc Ferron5164b792018-03-06 09:10:12 -05002824TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002825{
Jamie Madillb8149072019-04-30 16:14:44 -04002826 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002827 ANGLE_SKIP_TEST_IF(IsD3D9());
2828 ANGLE_SKIP_TEST_IF(IsVulkan());
2829 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES());
2830 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2831 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002832
Luc Ferrond8c632c2018-04-10 12:31:44 -04002833 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002834
Luc Ferrond8c632c2018-04-10 12:31:44 -04002835 glActiveTexture(GL_TEXTURE0);
2836 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2837 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2838 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002839
Luc Ferrond8c632c2018-04-10 12:31:44 -04002840 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002841
Luc Ferrond8c632c2018-04-10 12:31:44 -04002842 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002843}
2844
2845// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2846// ES 3.0.4 table 3.24
2847TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2848{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002849 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2850
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002851 glActiveTexture(GL_TEXTURE0);
2852 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2853 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2854 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2855 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2856 EXPECT_GL_NO_ERROR();
2857
2858 drawQuad(mProgram, "position", 0.5f);
2859
2860 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2861}
2862
2863// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2864// ES 3.0.4 table 3.24
2865TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2866{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002867 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2868
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002869 glActiveTexture(GL_TEXTURE0);
2870 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2871
2872 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2873 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2874 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2875 EXPECT_GL_NO_ERROR();
2876
2877 drawQuad(mProgram, "position", 0.5f);
2878
2879 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2880}
2881
2882// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2883// ES 3.0.4 table 3.24
2884TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2885{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002886 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2887
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002888 glActiveTexture(GL_TEXTURE0);
2889 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2890 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2891 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2892 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2893 EXPECT_GL_NO_ERROR();
2894
2895 drawQuad(mProgram, "position", 0.5f);
2896
2897 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2898}
2899
2900// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2901// ES 3.0.4 table 3.24
2902TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2903{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002904 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2905
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002906 glActiveTexture(GL_TEXTURE0);
2907 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2908 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2909 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2910 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2911 EXPECT_GL_NO_ERROR();
2912
2913 drawQuad(mProgram, "position", 0.5f);
2914
2915 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2916}
2917
2918// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2919// ES 3.0.4 table 3.24
2920TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2921{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002922 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2923
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002924 glActiveTexture(GL_TEXTURE0);
2925 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2926 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2927 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2928 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2929 EXPECT_GL_NO_ERROR();
2930
2931 drawQuad(mProgram, "position", 0.5f);
2932
2933 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2934}
2935
2936// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2937// ES 3.0.4 table 3.24
2938TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2939{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002940 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2941
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002942 glActiveTexture(GL_TEXTURE0);
2943 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2944 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2945 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2946 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2947 EXPECT_GL_NO_ERROR();
2948
2949 drawQuad(mProgram, "position", 0.5f);
2950
2951 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2952}
2953
2954// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2955// ES 3.0.4 table 3.24
2956TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2957{
2958 glActiveTexture(GL_TEXTURE0);
2959 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2960 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2961 EXPECT_GL_NO_ERROR();
2962
2963 drawQuad(mProgram, "position", 0.5f);
2964
2965 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2966}
2967
2968// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2969// ES 3.0.4 table 3.24
2970TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2971{
2972 glActiveTexture(GL_TEXTURE0);
2973 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2974 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2975 nullptr);
2976 EXPECT_GL_NO_ERROR();
2977
2978 drawQuad(mProgram, "position", 0.5f);
2979
2980 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2981}
2982
2983// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2984// ES 3.0.4 table 3.24
2985TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2986{
Yunchao He9550c602018-02-13 14:47:05 +08002987 // Seems to fail on OSX 10.12 Intel.
2988 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Jamie Madillbb1db482017-01-10 10:48:32 -05002989
Yuly Novikov49886892018-01-23 21:18:27 -05002990 // http://anglebug.com/2190
2991 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2992
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002993 glActiveTexture(GL_TEXTURE0);
2994 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2995 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2996 EXPECT_GL_NO_ERROR();
2997
2998 drawQuad(mProgram, "position", 0.5f);
2999
3000 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
3001}
3002
3003// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
3004// ES 3.0.4 table 3.24
3005TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
3006{
Yunchao He9550c602018-02-13 14:47:05 +08003007 // Seems to fail on OSX 10.12 Intel.
3008 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04003009
Yuly Novikov49886892018-01-23 21:18:27 -05003010 // http://anglebug.com/2190
3011 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
3012
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003013 glActiveTexture(GL_TEXTURE0);
3014 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3015 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
3016 EXPECT_GL_NO_ERROR();
3017
3018 drawQuad(mProgram, "position", 0.5f);
3019
3020 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
3021}
3022
Olli Etuaho96963162016-03-21 11:54:33 +02003023// Use a sampler in a uniform struct.
3024TEST_P(SamplerInStructTest, SamplerInStruct)
3025{
3026 runSamplerInStructTest();
3027}
3028
3029// Use a sampler in a uniform struct that's passed as a function parameter.
3030TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
3031{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003032 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
3033 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04003034
Olli Etuaho96963162016-03-21 11:54:33 +02003035 runSamplerInStructTest();
3036}
3037
3038// Use a sampler in a uniform struct array with a struct from the array passed as a function
3039// parameter.
3040TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
3041{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003042 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
3043 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08003044
Olli Etuaho96963162016-03-21 11:54:33 +02003045 runSamplerInStructTest();
3046}
3047
3048// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
3049// parameter.
3050TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
3051{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003052 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
3053 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08003054
Olli Etuaho96963162016-03-21 11:54:33 +02003055 runSamplerInStructTest();
3056}
3057
3058// Make sure that there isn't a name conflict between sampler extracted from a struct and a
3059// similarly named uniform.
3060TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
3061{
3062 runSamplerInStructTest();
3063}
3064
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05003065// GL_EXT_texture_filter_anisotropic
3066class TextureAnisotropyTest : public Texture2DTest
3067{
3068 protected:
3069 void uploadTexture()
3070 {
3071 glActiveTexture(GL_TEXTURE0);
3072 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3073 GLColor texDataRed[1] = {GLColor::red};
3074 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed);
3075 EXPECT_GL_NO_ERROR();
3076 }
3077};
3078
3079// Tests that setting anisotropic filtering doesn't cause failures at draw time.
3080TEST_P(TextureAnisotropyTest, AnisotropyFunctional)
3081{
Jamie Madillb8149072019-04-30 16:14:44 -04003082 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_filter_anisotropic"));
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05003083
3084 setUpProgram();
3085
3086 uploadTexture();
3087
3088 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3089 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3090 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f);
3091 EXPECT_GL_NO_ERROR();
3092
3093 drawQuad(mProgram, "position", 0.5f);
3094
3095 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3096 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3097 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::red);
3098}
3099
Till Rathmannb8543632018-10-02 19:46:14 +02003100// GL_OES_texture_border_clamp
3101class TextureBorderClampTest : public Texture2DTest
3102{
3103 protected:
3104 TextureBorderClampTest() : Texture2DTest() {}
3105
Jamie Madill35cd7332018-12-02 12:03:33 -05003106 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003107 {
3108 return
3109 R"(precision highp float;
3110 attribute vec4 position;
3111 varying vec2 texcoord;
3112
3113 void main()
3114 {
3115 gl_Position = vec4(position.xy, 0.0, 1.0);
3116 // texcoords in [-0.5, 1.5]
3117 texcoord = (position.xy) + 0.5;
3118 })";
3119 }
3120
3121 void uploadTexture()
3122 {
3123 glActiveTexture(GL_TEXTURE0);
3124 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3125 std::vector<GLColor> texDataRed(1, GLColor::red);
3126 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3127 texDataRed.data());
3128 EXPECT_GL_NO_ERROR();
3129 }
3130};
3131
3132// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3133// GL_CLAMP_TO_BORDER wrap mode (set with glTexParameter).
3134TEST_P(TextureBorderClampTest, TextureBorderClampFunctional)
3135{
Jamie Madillb8149072019-04-30 16:14:44 -04003136 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003137
3138 setUpProgram();
3139
3140 uploadTexture();
3141
3142 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3143 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3144 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3145 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3146 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3147 EXPECT_GL_NO_ERROR();
3148
3149 drawQuad(mProgram, "position", 0.5f);
3150
3151 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3152 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3153 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3154}
3155
3156// Test reading back GL_TEXTURE_BORDER_COLOR by glGetTexParameter.
3157TEST_P(TextureBorderClampTest, TextureBorderClampFunctional2)
3158{
Jamie Madillb8149072019-04-30 16:14:44 -04003159 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003160
3161 glActiveTexture(GL_TEXTURE0);
3162 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3163
3164 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3165
3166 GLint colorFixedPoint[4] = {0};
3167 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3168 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3169 std::numeric_limits<GLint>::max()};
3170 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3171 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3172 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3173 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3174
3175 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3176 std::numeric_limits<GLint>::max()};
3177 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3178
3179 GLfloat color[4] = {0.0f};
3180 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
3181 EXPECT_EQ(color[0], kFloatBlue.R);
3182 EXPECT_EQ(color[1], kFloatBlue.G);
3183 EXPECT_EQ(color[2], kFloatBlue.B);
3184 EXPECT_EQ(color[3], kFloatBlue.A);
3185}
3186
3187// Test GL_TEXTURE_BORDER_COLOR parameter validation at glTexParameter.
3188TEST_P(TextureBorderClampTest, TextureBorderClampValidation)
3189{
Jamie Madillb8149072019-04-30 16:14:44 -04003190 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003191
3192 glActiveTexture(GL_TEXTURE0);
3193 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3194
3195 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, 1.0f);
3196 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3197
3198 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3199 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3200
3201 glTexParameterfv(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3202 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3203
3204 GLint colorInt[4] = {0};
3205 glTexParameteriv(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_BORDER_COLOR, colorInt);
3206 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3207
3208 if (getClientMajorVersion() < 3)
3209 {
3210 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3211 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3212 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3213 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3214
3215 GLuint colorUInt[4] = {0};
3216 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3217 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3218 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3219 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3220
3221 GLSampler sampler;
3222 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3223 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3224 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3225 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3226
3227 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3228 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3229 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3230 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3231 }
3232}
3233
3234class TextureBorderClampTestES3 : public TextureBorderClampTest
3235{
3236 protected:
3237 TextureBorderClampTestES3() : TextureBorderClampTest() {}
3238};
3239
3240// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3241// GL_CLAMP_TO_BORDER wrap mode (set with glSamplerParameter).
3242TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional)
3243{
Jamie Madillb8149072019-04-30 16:14:44 -04003244 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003245
3246 setUpProgram();
3247
3248 uploadTexture();
3249
3250 GLSampler sampler;
3251 glBindSampler(0, sampler);
3252 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3253 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3254 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3255 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3256 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3257 EXPECT_GL_NO_ERROR();
3258
3259 drawQuad(mProgram, "position", 0.5f);
3260
3261 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3262 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3263 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3264}
3265
3266// Test reading back GL_TEXTURE_BORDER_COLOR by glGetSamplerParameter.
3267TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional2)
3268{
Jamie Madillb8149072019-04-30 16:14:44 -04003269 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003270
3271 glActiveTexture(GL_TEXTURE0);
3272
3273 GLSampler sampler;
3274 glBindSampler(0, sampler);
3275
3276 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3277
3278 GLint colorFixedPoint[4] = {0};
3279 glGetSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3280 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3281 std::numeric_limits<GLint>::max()};
3282 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3283 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3284 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3285 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3286
3287 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3288 std::numeric_limits<GLint>::max()};
3289 glSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3290
3291 GLfloat color[4] = {0.0f};
3292 glGetSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, color);
3293 EXPECT_EQ(color[0], kFloatBlue.R);
3294 EXPECT_EQ(color[1], kFloatBlue.G);
3295 EXPECT_EQ(color[2], kFloatBlue.B);
3296 EXPECT_EQ(color[3], kFloatBlue.A);
3297
3298 constexpr GLint colorSomewhatRedInt[4] = {500000, 0, 0, std::numeric_limits<GLint>::max()};
3299 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedInt);
3300 GLint colorInt[4] = {0};
3301 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3302 EXPECT_EQ(colorInt[0], colorSomewhatRedInt[0]);
3303 EXPECT_EQ(colorInt[1], colorSomewhatRedInt[1]);
3304 EXPECT_EQ(colorInt[2], colorSomewhatRedInt[2]);
3305 EXPECT_EQ(colorInt[3], colorSomewhatRedInt[3]);
3306
3307 constexpr GLuint colorSomewhatRedUInt[4] = {500000, 0, 0, std::numeric_limits<GLuint>::max()};
3308 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedUInt);
3309 GLuint colorUInt[4] = {0};
3310 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3311 EXPECT_EQ(colorUInt[0], colorSomewhatRedUInt[0]);
3312 EXPECT_EQ(colorUInt[1], colorSomewhatRedUInt[1]);
3313 EXPECT_EQ(colorUInt[2], colorSomewhatRedUInt[2]);
3314 EXPECT_EQ(colorUInt[3], colorSomewhatRedUInt[3]);
3315
3316 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3317
3318 constexpr GLint colorSomewhatGreenInt[4] = {0, 500000, 0, std::numeric_limits<GLint>::max()};
3319 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenInt);
3320 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3321 EXPECT_EQ(colorInt[0], colorSomewhatGreenInt[0]);
3322 EXPECT_EQ(colorInt[1], colorSomewhatGreenInt[1]);
3323 EXPECT_EQ(colorInt[2], colorSomewhatGreenInt[2]);
3324 EXPECT_EQ(colorInt[3], colorSomewhatGreenInt[3]);
3325
3326 constexpr GLuint colorSomewhatGreenUInt[4] = {0, 500000, 0, std::numeric_limits<GLuint>::max()};
3327 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenUInt);
3328 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3329 EXPECT_EQ(colorUInt[0], colorSomewhatGreenUInt[0]);
3330 EXPECT_EQ(colorUInt[1], colorSomewhatGreenUInt[1]);
3331 EXPECT_EQ(colorUInt[2], colorSomewhatGreenUInt[2]);
3332 EXPECT_EQ(colorUInt[3], colorSomewhatGreenUInt[3]);
3333}
3334
3335// Test GL_TEXTURE_BORDER_COLOR parameter validation at glSamplerParameter.
3336TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Validation)
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 glActiveTexture(GL_TEXTURE0);
3341
3342 GLSampler sampler;
3343 glBindSampler(0, sampler);
3344
3345 glSamplerParameterf(sampler, GL_TEXTURE_BORDER_COLOR, 1.0f);
3346 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3347
3348 glSamplerParameteri(sampler, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3349 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3350}
3351
3352class TextureBorderClampIntegerTestES3 : public Texture2DTest
3353{
3354 protected:
3355 TextureBorderClampIntegerTestES3() : Texture2DTest(), isUnsignedIntTest(false) {}
3356
Jamie Madill35cd7332018-12-02 12:03:33 -05003357 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003358 {
3359 return
3360 R"(#version 300 es
3361 out vec2 texcoord;
3362 in vec4 position;
3363
3364 void main()
3365 {
3366 gl_Position = vec4(position.xy, 0.0, 1.0);
3367 // texcoords in [-0.5, 1.5]
3368 texcoord = (position.xy) + 0.5;
3369 })";
3370 }
3371
Jamie Madillba319ba2018-12-29 10:29:33 -05003372 const char *getFragmentShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003373 {
Jamie Madill35cd7332018-12-02 12:03:33 -05003374 if (isUnsignedIntTest)
3375 {
3376 return "#version 300 es\n"
3377 "precision highp float;\n"
3378 "uniform highp usampler2D tex;\n"
3379 "in vec2 texcoord;\n"
3380 "out vec4 fragColor;\n"
Till Rathmannb8543632018-10-02 19:46:14 +02003381
Jamie Madill35cd7332018-12-02 12:03:33 -05003382 "void main()\n"
3383 "{\n"
3384 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3385 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3386 "fragColor = (texture(tex, texcoord).r == 150u)"
3387 " ? green : red;\n"
3388 "}\n";
3389 }
3390 else
3391 {
3392 return "#version 300 es\n"
3393 "precision highp float;\n"
3394 "uniform highp isampler2D tex;\n"
3395 "in vec2 texcoord;\n"
3396 "out vec4 fragColor;\n"
3397
3398 "void main()\n"
3399 "{\n"
3400 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3401 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3402 "fragColor = (texture(tex, texcoord).r == -50)"
3403 " ? green : red;\n"
3404 "}\n";
3405 }
Till Rathmannb8543632018-10-02 19:46:14 +02003406 }
3407
3408 void uploadTexture()
3409 {
3410 glActiveTexture(GL_TEXTURE0);
3411 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3412 if (isUnsignedIntTest)
3413 {
3414 std::vector<GLubyte> texData(4, 100);
3415 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE,
3416 texData.data());
3417 }
3418 else
3419 {
3420 std::vector<GLbyte> texData(4, 100);
3421 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8I, 1, 1, 0, GL_RGBA_INTEGER, GL_BYTE,
3422 texData.data());
3423 }
3424 EXPECT_GL_NO_ERROR();
3425 }
3426
3427 bool isUnsignedIntTest;
3428};
3429
3430// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3431// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3432TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger)
3433{
Jamie Madillb8149072019-04-30 16:14:44 -04003434 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003435
3436 setUpProgram();
3437
3438 uploadTexture();
3439
3440 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3441 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3442 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3443 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3444
3445 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3446 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3447
3448 EXPECT_GL_NO_ERROR();
3449
3450 drawQuad(mProgram, "position", 0.5f);
3451
3452 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3453 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3454 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3455}
3456
3457// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3458// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3459TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger2)
3460{
Jamie Madillb8149072019-04-30 16:14:44 -04003461 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003462
3463 setUpProgram();
3464
3465 uploadTexture();
3466
3467 GLSampler sampler;
3468 glBindSampler(0, sampler);
3469 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3470 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3471 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3472 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3473
3474 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3475 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3476
3477 EXPECT_GL_NO_ERROR();
3478
3479 drawQuad(mProgram, "position", 0.5f);
3480
3481 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3482 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3483 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3484}
3485
3486// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3487// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIuivOES).
3488TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned)
3489{
Jamie Madillb8149072019-04-30 16:14:44 -04003490 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003491
3492 isUnsignedIntTest = true;
3493
3494 setUpProgram();
3495
3496 uploadTexture();
3497
3498 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3499 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3500 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3501 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3502
3503 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3504 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3505
3506 EXPECT_GL_NO_ERROR();
3507
3508 drawQuad(mProgram, "position", 0.5f);
3509
3510 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3511 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3512 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3513}
3514
3515// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3516// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with
3517// glSamplerParameterIuivOES).
3518TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned2)
3519{
Jamie Madillb8149072019-04-30 16:14:44 -04003520 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003521
3522 isUnsignedIntTest = true;
3523
3524 setUpProgram();
3525
3526 uploadTexture();
3527
3528 GLSampler sampler;
3529 glBindSampler(0, sampler);
3530 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3531 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3532 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3533 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3534
3535 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3536 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3537
3538 EXPECT_GL_NO_ERROR();
3539
3540 drawQuad(mProgram, "position", 0.5f);
3541
3542 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3543 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3544 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3545}
3546
3547// ~GL_OES_texture_border_clamp
3548
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003549class TextureLimitsTest : public ANGLETest
3550{
3551 protected:
3552 struct RGBA8
3553 {
3554 uint8_t R, G, B, A;
3555 };
3556
3557 TextureLimitsTest()
3558 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
3559 {
3560 setWindowWidth(128);
3561 setWindowHeight(128);
3562 setConfigRedBits(8);
3563 setConfigGreenBits(8);
3564 setConfigBlueBits(8);
3565 setConfigAlphaBits(8);
3566 }
3567
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003568 void testSetUp() override
Jamie Madill0fdb9562018-09-17 17:18:43 -04003569 {
Jamie Madill0fdb9562018-09-17 17:18:43 -04003570 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
3571 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
3572 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
3573
3574 ASSERT_GL_NO_ERROR();
3575 }
3576
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003577 void testTearDown() override
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003578 {
3579 if (mProgram != 0)
3580 {
3581 glDeleteProgram(mProgram);
3582 mProgram = 0;
3583
3584 if (!mTextures.empty())
3585 {
3586 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
3587 }
3588 }
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003589 }
3590
3591 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
3592 GLint vertexTextureCount,
3593 GLint vertexActiveTextureCount,
3594 const std::string &fragPrefix,
3595 GLint fragmentTextureCount,
3596 GLint fragmentActiveTextureCount)
3597 {
3598 std::stringstream vertexShaderStr;
3599 vertexShaderStr << "attribute vec2 position;\n"
3600 << "varying vec4 color;\n"
3601 << "varying vec2 texCoord;\n";
3602
3603 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
3604 {
3605 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
3606 }
3607
3608 vertexShaderStr << "void main() {\n"
3609 << " gl_Position = vec4(position, 0, 1);\n"
3610 << " texCoord = (position * 0.5) + 0.5;\n"
3611 << " color = vec4(0);\n";
3612
3613 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
3614 {
3615 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
3616 << ", texCoord);\n";
3617 }
3618
3619 vertexShaderStr << "}";
3620
3621 std::stringstream fragmentShaderStr;
3622 fragmentShaderStr << "varying mediump vec4 color;\n"
3623 << "varying mediump vec2 texCoord;\n";
3624
3625 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
3626 {
3627 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
3628 }
3629
3630 fragmentShaderStr << "void main() {\n"
3631 << " gl_FragColor = color;\n";
3632
3633 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
3634 {
3635 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
3636 << ", texCoord);\n";
3637 }
3638
3639 fragmentShaderStr << "}";
3640
3641 const std::string &vertexShaderSource = vertexShaderStr.str();
3642 const std::string &fragmentShaderSource = fragmentShaderStr.str();
3643
Jamie Madill35cd7332018-12-02 12:03:33 -05003644 mProgram = CompileProgram(vertexShaderSource.c_str(), fragmentShaderSource.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003645 }
3646
3647 RGBA8 getPixel(GLint texIndex)
3648 {
3649 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3650 0, 255u};
3651 return pixel;
3652 }
3653
3654 void initTextures(GLint tex2DCount, GLint texCubeCount)
3655 {
3656 GLint totalCount = tex2DCount + texCubeCount;
3657 mTextures.assign(totalCount, 0);
3658 glGenTextures(totalCount, &mTextures[0]);
3659 ASSERT_GL_NO_ERROR();
3660
3661 std::vector<RGBA8> texData(16 * 16);
3662
3663 GLint texIndex = 0;
3664 for (; texIndex < tex2DCount; ++texIndex)
3665 {
3666 texData.assign(texData.size(), getPixel(texIndex));
3667 glActiveTexture(GL_TEXTURE0 + texIndex);
3668 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3669 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3670 &texData[0]);
3671 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3672 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3673 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3674 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3675 }
3676
3677 ASSERT_GL_NO_ERROR();
3678
3679 for (; texIndex < texCubeCount; ++texIndex)
3680 {
3681 texData.assign(texData.size(), getPixel(texIndex));
3682 glActiveTexture(GL_TEXTURE0 + texIndex);
3683 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3684 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3685 GL_UNSIGNED_BYTE, &texData[0]);
3686 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3687 GL_UNSIGNED_BYTE, &texData[0]);
3688 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3689 GL_UNSIGNED_BYTE, &texData[0]);
3690 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3691 GL_UNSIGNED_BYTE, &texData[0]);
3692 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3693 GL_UNSIGNED_BYTE, &texData[0]);
3694 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3695 GL_UNSIGNED_BYTE, &texData[0]);
3696 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3697 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3698 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3699 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3700 }
3701
3702 ASSERT_GL_NO_ERROR();
3703 }
3704
3705 void testWithTextures(GLint vertexTextureCount,
3706 const std::string &vertexTexturePrefix,
3707 GLint fragmentTextureCount,
3708 const std::string &fragmentTexturePrefix)
3709 {
3710 // Generate textures
3711 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3712
3713 glUseProgram(mProgram);
3714 RGBA8 expectedSum = {0};
3715 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3716 {
3717 std::stringstream uniformNameStr;
3718 uniformNameStr << vertexTexturePrefix << texIndex;
3719 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003720 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003721 ASSERT_NE(-1, location);
3722
3723 glUniform1i(location, texIndex);
3724 RGBA8 contribution = getPixel(texIndex);
3725 expectedSum.R += contribution.R;
3726 expectedSum.G += contribution.G;
3727 }
3728
3729 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3730 {
3731 std::stringstream uniformNameStr;
3732 uniformNameStr << fragmentTexturePrefix << texIndex;
3733 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003734 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003735 ASSERT_NE(-1, location);
3736
3737 glUniform1i(location, texIndex + vertexTextureCount);
3738 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3739 expectedSum.R += contribution.R;
3740 expectedSum.G += contribution.G;
3741 }
3742
3743 ASSERT_GE(256u, expectedSum.G);
3744
3745 drawQuad(mProgram, "position", 0.5f);
3746 ASSERT_GL_NO_ERROR();
3747 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3748 }
3749
3750 GLuint mProgram;
3751 std::vector<GLuint> mTextures;
3752 GLint mMaxVertexTextures;
3753 GLint mMaxFragmentTextures;
3754 GLint mMaxCombinedTextures;
3755};
3756
3757// Test rendering with the maximum vertex texture units.
3758TEST_P(TextureLimitsTest, MaxVertexTextures)
3759{
3760 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3761 ASSERT_NE(0u, mProgram);
3762 ASSERT_GL_NO_ERROR();
3763
3764 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3765}
3766
3767// Test rendering with the maximum fragment texture units.
3768TEST_P(TextureLimitsTest, MaxFragmentTextures)
3769{
3770 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3771 ASSERT_NE(0u, mProgram);
3772 ASSERT_GL_NO_ERROR();
3773
3774 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3775}
3776
3777// Test rendering with maximum combined texture units.
3778TEST_P(TextureLimitsTest, MaxCombinedTextures)
3779{
3780 GLint vertexTextures = mMaxVertexTextures;
3781
3782 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3783 {
3784 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3785 }
3786
3787 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3788 mMaxFragmentTextures, mMaxFragmentTextures);
3789 ASSERT_NE(0u, mProgram);
3790 ASSERT_GL_NO_ERROR();
3791
3792 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3793}
3794
3795// Negative test for exceeding the number of vertex textures
3796TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3797{
3798 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3799 0);
3800 ASSERT_EQ(0u, mProgram);
3801}
3802
3803// Negative test for exceeding the number of fragment textures
3804TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3805{
3806 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3807 mMaxFragmentTextures + 1);
3808 ASSERT_EQ(0u, mProgram);
3809}
3810
3811// Test active vertex textures under the limit, but excessive textures specified.
3812TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3813{
3814 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3815 ASSERT_NE(0u, mProgram);
3816 ASSERT_GL_NO_ERROR();
3817
3818 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3819}
3820
3821// Test active fragment textures under the limit, but excessive textures specified.
3822TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3823{
3824 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3825 mMaxFragmentTextures);
3826 ASSERT_NE(0u, mProgram);
3827 ASSERT_GL_NO_ERROR();
3828
3829 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3830}
3831
3832// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003833// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003834TEST_P(TextureLimitsTest, TextureTypeConflict)
3835{
Jamie Madill35cd7332018-12-02 12:03:33 -05003836 constexpr char kVS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003837 "attribute vec2 position;\n"
3838 "varying float color;\n"
3839 "uniform sampler2D tex2D;\n"
3840 "uniform samplerCube texCube;\n"
3841 "void main() {\n"
3842 " gl_Position = vec4(position, 0, 1);\n"
3843 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3844 " color = texture2D(tex2D, texCoord).x;\n"
3845 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3846 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05003847 constexpr char kFS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003848 "varying mediump float color;\n"
3849 "void main() {\n"
3850 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3851 "}";
3852
Jamie Madill35cd7332018-12-02 12:03:33 -05003853 mProgram = CompileProgram(kVS, kFS);
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003854 ASSERT_NE(0u, mProgram);
3855
3856 initTextures(1, 0);
3857
3858 glUseProgram(mProgram);
3859 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3860 ASSERT_NE(-1, tex2DLocation);
3861 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3862 ASSERT_NE(-1, texCubeLocation);
3863
3864 glUniform1i(tex2DLocation, 0);
3865 glUniform1i(texCubeLocation, 0);
3866 ASSERT_GL_NO_ERROR();
3867
3868 drawQuad(mProgram, "position", 0.5f);
3869 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3870}
3871
Vincent Lang25ab4512016-05-13 18:13:59 +02003872class Texture2DNorm16TestES3 : public Texture2DTestES3
3873{
3874 protected:
3875 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3876
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003877 void testSetUp() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003878 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003879 Texture2DTestES3::testSetUp();
Vincent Lang25ab4512016-05-13 18:13:59 +02003880
3881 glActiveTexture(GL_TEXTURE0);
3882 glGenTextures(3, mTextures);
3883 glGenFramebuffers(1, &mFBO);
3884 glGenRenderbuffers(1, &mRenderbuffer);
3885
3886 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3887 {
3888 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3889 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3890 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3891 }
3892
3893 glBindTexture(GL_TEXTURE_2D, 0);
3894
3895 ASSERT_GL_NO_ERROR();
3896 }
3897
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003898 void testTearDown() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003899 {
3900 glDeleteTextures(3, mTextures);
3901 glDeleteFramebuffers(1, &mFBO);
3902 glDeleteRenderbuffers(1, &mRenderbuffer);
3903
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003904 Texture2DTestES3::testTearDown();
Vincent Lang25ab4512016-05-13 18:13:59 +02003905 }
3906
3907 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3908 {
Geoff Langf607c602016-09-21 11:46:48 -04003909 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3910 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003911
3912 setUpProgram();
3913
3914 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3915 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3916 0);
3917
3918 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3919 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3920
3921 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003922 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003923
3924 EXPECT_GL_NO_ERROR();
3925
3926 drawQuad(mProgram, "position", 0.5f);
3927
Geoff Langf607c602016-09-21 11:46:48 -04003928 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003929
Jamie Madill50cf2be2018-06-15 09:46:57 -04003930 EXPECT_PIXEL_COLOR_EQ(0, 0,
3931 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3932 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003933
3934 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3935
3936 ASSERT_GL_NO_ERROR();
3937 }
3938
3939 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3940 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04003941 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003942 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003943
3944 setUpProgram();
3945
3946 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3947 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3948
3949 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3950 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3951 0);
3952
3953 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003954 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003955
3956 EXPECT_GL_NO_ERROR();
3957
3958 drawQuad(mProgram, "position", 0.5f);
3959
Geoff Langf607c602016-09-21 11:46:48 -04003960 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
Jamie Madill50cf2be2018-06-15 09:46:57 -04003961 EXPECT_PIXEL_COLOR_EQ(0, 0,
3962 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3963 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003964
3965 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3966 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3967 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3968 mRenderbuffer);
3969 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3970 EXPECT_GL_NO_ERROR();
3971
3972 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3973 glClear(GL_COLOR_BUFFER_BIT);
3974
3975 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3976
Geoff Langf607c602016-09-21 11:46:48 -04003977 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003978
3979 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3980
3981 ASSERT_GL_NO_ERROR();
3982 }
3983
3984 GLuint mTextures[3];
3985 GLuint mFBO;
3986 GLuint mRenderbuffer;
3987};
3988
3989// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3990TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3991{
Jamie Madillb8149072019-04-30 16:14:44 -04003992 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02003993
3994 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3995 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3996 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3997 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3998 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3999 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
4000 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
4001 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
4002
4003 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
4004 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
4005 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
4006}
4007
Olli Etuaho95faa232016-06-07 14:01:53 -07004008// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
4009// GLES 3.0.4 section 3.8.3.
4010TEST_P(Texture2DTestES3, UnpackSkipImages2D)
4011{
Yuly Novikovd18c0482019-04-04 19:56:43 -04004012 // Crashes on Nexus 5X due to a driver bug. http://anglebug.com/1429
4013 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07004014
4015 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4016 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4017 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4018 ASSERT_GL_NO_ERROR();
4019
4020 // SKIP_IMAGES should not have an effect on uploading 2D textures
4021 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
4022 ASSERT_GL_NO_ERROR();
4023
4024 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
4025
4026 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4027 pixelsGreen.data());
4028 ASSERT_GL_NO_ERROR();
4029
4030 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
4031 pixelsGreen.data());
4032 ASSERT_GL_NO_ERROR();
4033
4034 glUseProgram(mProgram);
4035 drawQuad(mProgram, "position", 0.5f);
4036 ASSERT_GL_NO_ERROR();
4037
4038 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
4039}
4040
Olli Etuaho989cac32016-06-08 16:18:49 -07004041// Test that skip defined in unpack parameters is taken into account when determining whether
4042// unpacking source extends outside unpack buffer bounds.
4043TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
4044{
4045 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4046 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4047 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4048 ASSERT_GL_NO_ERROR();
4049
4050 GLBuffer buf;
4051 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
4052 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
4053 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
4054 GL_DYNAMIC_COPY);
4055 ASSERT_GL_NO_ERROR();
4056
4057 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4058 ASSERT_GL_NO_ERROR();
4059
4060 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
4061 ASSERT_GL_NO_ERROR();
4062
4063 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4064 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4065
4066 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
4067 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
4068 ASSERT_GL_NO_ERROR();
4069
4070 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4071 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4072}
4073
Olli Etuaho218cf9e2016-05-20 13:55:24 +03004074// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
4075TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
4076{
Yunchao He9550c602018-02-13 14:47:05 +08004077 ANGLE_SKIP_TEST_IF(IsD3D11());
4078
4079 // Incorrect rendering results seen on OSX AMD.
4080 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03004081
4082 const GLuint width = 8u;
4083 const GLuint height = 8u;
4084 const GLuint unpackRowLength = 5u;
4085 const GLuint unpackSkipPixels = 1u;
4086
4087 setWindowWidth(width);
4088 setWindowHeight(height);
4089
4090 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4091 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4092 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4093 ASSERT_GL_NO_ERROR();
4094
4095 GLBuffer buf;
4096 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
4097 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
4098 GLColor::green);
4099
4100 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
4101 {
4102 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
4103 }
4104
4105 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
4106 GL_DYNAMIC_COPY);
4107 ASSERT_GL_NO_ERROR();
4108
4109 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
4110 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
4111 ASSERT_GL_NO_ERROR();
4112
4113 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4114 ASSERT_GL_NO_ERROR();
4115
4116 glUseProgram(mProgram);
4117 drawQuad(mProgram, "position", 0.5f);
4118 ASSERT_GL_NO_ERROR();
4119
4120 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
4121 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
4122 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
4123 actual.data());
4124 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
4125 EXPECT_EQ(expected, actual);
4126}
4127
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004128template <typename T>
4129T UNorm(double value)
4130{
4131 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
4132}
4133
4134// Test rendering a depth texture with mipmaps.
4135TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
4136{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08004137 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
4138 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
Jiawei Shaoaf0f31d2018-09-27 15:42:31 +08004139 // http://anglebug.com/1706
4140 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Corentin Walleze731d8a2016-09-07 10:56:25 -04004141
Jamie Madill24980272019-04-03 09:03:51 -04004142 // Seems to fail on AMD D3D11. Possibly driver bug. http://anglebug.com/3342
4143 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsD3D11());
4144
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004145 const int size = getWindowWidth();
4146
4147 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04004148 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004149
4150 glActiveTexture(GL_TEXTURE0);
4151 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4152 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
4153 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4154 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4155 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
4156 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
4157 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4158 ASSERT_GL_NO_ERROR();
4159
4160 glUseProgram(mProgram);
4161 glUniform1i(mTexture2DUniformLocation, 0);
4162
4163 std::vector<unsigned char> expected;
4164
4165 for (int level = 0; level < levels; ++level)
4166 {
4167 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
4168 expected.push_back(UNorm<unsigned char>(value));
4169
4170 int levelDim = dim(level);
4171
4172 ASSERT_GT(levelDim, 0);
4173
4174 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
4175 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
4176 GL_UNSIGNED_INT, initData.data());
4177 }
4178 ASSERT_GL_NO_ERROR();
4179
4180 for (int level = 0; level < levels; ++level)
4181 {
4182 glViewport(0, 0, dim(level), dim(level));
4183 drawQuad(mProgram, "position", 0.5f);
4184 GLColor actual = ReadColor(0, 0);
4185 EXPECT_NEAR(expected[level], actual.R, 10u);
4186 }
4187
4188 ASSERT_GL_NO_ERROR();
4189}
4190
Jamie Madill7ffdda92016-09-08 13:26:51 -04004191// Tests unpacking into the unsized GL_ALPHA format.
4192TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
4193{
Jamie Madill7ffdda92016-09-08 13:26:51 -04004194 // Initialize the texure.
4195 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4196 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
4197 GL_UNSIGNED_BYTE, nullptr);
4198 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4199 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4200
4201 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
4202
4203 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04004204 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04004205 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4206 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4207 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
4208 GL_STATIC_DRAW);
4209
4210 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
4211 GL_UNSIGNED_BYTE, nullptr);
4212
4213 // Clear to a weird color to make sure we're drawing something.
4214 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
4215 glClear(GL_COLOR_BUFFER_BIT);
4216
4217 // Draw with the alpha texture and verify.
4218 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04004219
4220 ASSERT_GL_NO_ERROR();
4221 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
4222}
4223
Jamie Madill2e600342016-09-19 13:56:40 -04004224// Ensure stale unpack data doesn't propagate in D3D11.
4225TEST_P(Texture2DTestES3, StaleUnpackData)
4226{
4227 // Init unpack buffer.
4228 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
4229 std::vector<GLColor> pixels(pixelCount, GLColor::red);
4230
4231 GLBuffer unpackBuffer;
4232 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4233 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4234 GLsizei bufferSize = pixelCount * sizeof(GLColor);
4235 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
4236
4237 // Create from unpack buffer.
4238 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4239 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
4240 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4241 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4242 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4243
4244 drawQuad(mProgram, "position", 0.5f);
4245
4246 ASSERT_GL_NO_ERROR();
4247 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4248
4249 // Fill unpack with green, recreating buffer.
4250 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
4251 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
4252 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
4253
4254 // Reinit texture with green.
4255 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
4256 GL_UNSIGNED_BYTE, nullptr);
4257
4258 drawQuad(mProgram, "position", 0.5f);
4259
4260 ASSERT_GL_NO_ERROR();
4261 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
4262}
4263
Geoff Langfb7685f2017-11-13 11:44:11 -05004264// Ensure that texture parameters passed as floats that are converted to ints are rounded before
4265// validating they are less than 0.
4266TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
4267{
4268 GLTexture texture;
4269 glBindTexture(GL_TEXTURE_2D, texture);
4270
4271 // Use a negative number that will round to zero when converted to an integer
4272 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
4273 // "Validation of values performed by state-setting commands is performed after conversion,
4274 // unless specified otherwise for a specific command."
4275 GLfloat param = -7.30157126e-07f;
4276 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
4277 EXPECT_GL_NO_ERROR();
4278
4279 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
4280 EXPECT_GL_NO_ERROR();
4281}
4282
Jamie Madillf097e232016-11-05 00:44:15 -04004283// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
4284// being properly checked, and the texture storage of the previous texture format was persisting.
4285// This would result in an ASSERT in debug and incorrect rendering in release.
4286// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
4287TEST_P(Texture3DTestES3, FormatRedefinitionBug)
4288{
4289 GLTexture tex;
4290 glBindTexture(GL_TEXTURE_3D, tex.get());
4291 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4292
4293 GLFramebuffer framebuffer;
4294 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
4295 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
4296
4297 glCheckFramebufferStatus(GL_FRAMEBUFFER);
4298
4299 std::vector<uint8_t> pixelData(100, 0);
4300
4301 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
4302 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
4303 pixelData.data());
4304
4305 ASSERT_GL_NO_ERROR();
4306}
4307
Corentin Wallezd2627992017-04-28 17:17:03 -04004308// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
4309TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
4310{
4311 // 2D tests
4312 {
4313 GLTexture tex;
4314 glBindTexture(GL_TEXTURE_2D, tex.get());
4315
4316 GLBuffer pbo;
4317 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4318
4319 // Test OOB
4320 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
4321 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4322 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4323
4324 // Test OOB
4325 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
4326 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4327 ASSERT_GL_NO_ERROR();
4328 }
4329
4330 // 3D tests
4331 {
4332 GLTexture tex;
4333 glBindTexture(GL_TEXTURE_3D, tex.get());
4334
4335 GLBuffer pbo;
4336 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4337
4338 // Test OOB
4339 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
4340 GL_STATIC_DRAW);
4341 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4342 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4343
4344 // Test OOB
4345 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
4346 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4347 ASSERT_GL_NO_ERROR();
4348 }
4349}
4350
Jamie Madill3ed60422017-09-07 11:32:52 -04004351// Tests behaviour with a single texture and multiple sampler objects.
4352TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
4353{
4354 GLint maxTextureUnits = 0;
4355 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
4356 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
4357
4358 constexpr int kSize = 16;
4359
4360 // Make a single-level texture, fill it with red.
4361 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
4362 GLTexture tex;
4363 glBindTexture(GL_TEXTURE_2D, tex);
4364 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4365 redColors.data());
4366 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4367 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4368
4369 // Simple sanity check.
4370 draw2DTexturedQuad(0.5f, 1.0f, true);
4371 ASSERT_GL_NO_ERROR();
4372 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4373
4374 // Bind texture to unit 1 with a sampler object making it incomplete.
4375 GLSampler sampler;
4376 glBindSampler(0, sampler);
4377 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4378 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4379
4380 // Make a mipmap texture, fill it with blue.
4381 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
4382 GLTexture mipmapTex;
4383 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4384 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4385 blueColors.data());
4386 glGenerateMipmap(GL_TEXTURE_2D);
4387
4388 // Draw with the sampler, expect blue.
4389 draw2DTexturedQuad(0.5f, 1.0f, true);
4390 ASSERT_GL_NO_ERROR();
4391 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
4392
4393 // Simple multitexturing program.
Jamie Madill35cd7332018-12-02 12:03:33 -05004394 constexpr char kVS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004395 "#version 300 es\n"
4396 "in vec2 position;\n"
4397 "out vec2 texCoord;\n"
4398 "void main()\n"
4399 "{\n"
4400 " gl_Position = vec4(position, 0, 1);\n"
4401 " texCoord = position * 0.5 + vec2(0.5);\n"
4402 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05004403
4404 constexpr char kFS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004405 "#version 300 es\n"
4406 "precision mediump float;\n"
4407 "in vec2 texCoord;\n"
4408 "uniform sampler2D tex1;\n"
4409 "uniform sampler2D tex2;\n"
4410 "uniform sampler2D tex3;\n"
4411 "uniform sampler2D tex4;\n"
4412 "out vec4 color;\n"
4413 "void main()\n"
4414 "{\n"
4415 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
4416 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
4417 "}";
4418
Jamie Madill35cd7332018-12-02 12:03:33 -05004419 ANGLE_GL_PROGRAM(program, kVS, kFS);
Jamie Madill3ed60422017-09-07 11:32:52 -04004420
4421 std::array<GLint, 4> texLocations = {
4422 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
4423 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
4424 for (GLint location : texLocations)
4425 {
4426 ASSERT_NE(-1, location);
4427 }
4428
4429 // Init the uniform data.
4430 glUseProgram(program);
4431 for (GLint location = 0; location < 4; ++location)
4432 {
4433 glUniform1i(texLocations[location], location);
4434 }
4435
4436 // Initialize four samplers
4437 GLSampler samplers[4];
4438
4439 // 0: non-mipped.
4440 glBindSampler(0, samplers[0]);
4441 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4442 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4443
4444 // 1: mipped.
4445 glBindSampler(1, samplers[1]);
4446 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4447 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4448
4449 // 2: non-mipped.
4450 glBindSampler(2, samplers[2]);
4451 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4452 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4453
4454 // 3: mipped.
4455 glBindSampler(3, samplers[3]);
4456 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4457 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4458
4459 // Bind two blue mipped textures and two single layer textures, should all draw.
4460 glActiveTexture(GL_TEXTURE0);
4461 glBindTexture(GL_TEXTURE_2D, tex);
4462
4463 glActiveTexture(GL_TEXTURE1);
4464 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4465
4466 glActiveTexture(GL_TEXTURE2);
4467 glBindTexture(GL_TEXTURE_2D, tex);
4468
4469 glActiveTexture(GL_TEXTURE3);
4470 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4471
4472 ASSERT_GL_NO_ERROR();
4473
4474 drawQuad(program, "position", 0.5f);
4475 ASSERT_GL_NO_ERROR();
4476 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
4477
4478 // Bind four single layer textures, two should be incomplete.
4479 glActiveTexture(GL_TEXTURE1);
4480 glBindTexture(GL_TEXTURE_2D, tex);
4481
4482 glActiveTexture(GL_TEXTURE3);
4483 glBindTexture(GL_TEXTURE_2D, tex);
4484
4485 drawQuad(program, "position", 0.5f);
4486 ASSERT_GL_NO_ERROR();
4487 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
4488}
4489
Martin Radev7e2c0d32017-09-15 14:25:42 +03004490// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
4491// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
4492// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
4493// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
4494// samples the cubemap using a direction vector (1,1,1).
4495TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
4496{
Yunchao He2f23f352018-02-11 22:11:37 +08004497 // Check http://anglebug.com/2155.
4498 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
4499
Jamie Madill35cd7332018-12-02 12:03:33 -05004500 constexpr char kVS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004501 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004502 precision mediump float;
4503 in vec3 pos;
4504 void main() {
4505 gl_Position = vec4(pos, 1.0);
4506 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03004507
Jamie Madill35cd7332018-12-02 12:03:33 -05004508 constexpr char kFS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004509 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004510 precision mediump float;
4511 out vec4 color;
4512 uniform samplerCube uTex;
4513 void main(){
4514 color = texture(uTex, vec3(1.0));
4515 })";
Jamie Madill35cd7332018-12-02 12:03:33 -05004516
4517 ANGLE_GL_PROGRAM(program, kVS, kFS);
Martin Radev7e2c0d32017-09-15 14:25:42 +03004518 glUseProgram(program);
4519
4520 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
4521 glActiveTexture(GL_TEXTURE0);
4522
4523 GLTexture cubeTex;
4524 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
4525
4526 const int kFaceWidth = 1;
4527 const int kFaceHeight = 1;
4528 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
4529 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4530 GL_UNSIGNED_BYTE, texData.data());
4531 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4532 GL_UNSIGNED_BYTE, texData.data());
4533 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4534 GL_UNSIGNED_BYTE, texData.data());
4535 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4536 GL_UNSIGNED_BYTE, texData.data());
4537 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4538 GL_UNSIGNED_BYTE, texData.data());
4539 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4540 GL_UNSIGNED_BYTE, texData.data());
4541 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4542 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4543 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
4544 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
4545 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
4546 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
4547
4548 drawQuad(program, "pos", 0.5f, 1.0f, true);
4549 ASSERT_GL_NO_ERROR();
4550
4551 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4552}
4553
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08004554// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
4555TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
4556{
4557 GLuint texture = create2DTexture();
4558
4559 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
4560 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4561
4562 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
4563 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4564
4565 glDeleteTextures(1, &texture);
4566 EXPECT_GL_NO_ERROR();
4567}
4568
Olli Etuaho023371b2018-04-24 17:43:32 +03004569// Test setting base level after calling generateMipmap on a LUMA texture.
4570// Covers http://anglebug.com/2498
4571TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA)
4572{
4573 glActiveTexture(GL_TEXTURE0);
4574 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4575
4576 constexpr const GLsizei kWidth = 8;
4577 constexpr const GLsizei kHeight = 8;
4578 std::array<GLubyte, kWidth * kHeight * 2> whiteData;
4579 whiteData.fill(255u);
4580
4581 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA,
4582 GL_UNSIGNED_BYTE, whiteData.data());
4583 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
4584 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4585 glGenerateMipmap(GL_TEXTURE_2D);
4586 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
4587 EXPECT_GL_NO_ERROR();
4588
4589 drawQuad(mProgram, "position", 0.5f);
4590 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4591}
4592
Till Rathmannc1551dc2018-08-15 17:04:49 +02004593// Covers a bug in the D3D11 backend: http://anglebug.com/2772
4594// When using a sampler the texture was created as if it has mipmaps,
4595// regardless what you specified in GL_TEXTURE_MIN_FILTER via
4596// glSamplerParameteri() -- mistakenly the default value
4597// GL_NEAREST_MIPMAP_LINEAR or the value set via glTexParameteri() was
4598// evaluated.
4599// If you didn't provide mipmaps and didn't let the driver generate them
4600// this led to not sampling your texture data when minification occurred.
4601TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping)
4602{
Jamie Madill35cd7332018-12-02 12:03:33 -05004603 constexpr char kVS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004604 "#version 300 es\n"
4605 "out vec2 texcoord;\n"
4606 "in vec4 position;\n"
4607 "void main()\n"
4608 "{\n"
4609 " gl_Position = vec4(position.xy * 0.1, 0.0, 1.0);\n"
4610 " texcoord = (position.xy * 0.5) + 0.5;\n"
4611 "}\n";
4612
Jamie Madill35cd7332018-12-02 12:03:33 -05004613 constexpr char kFS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004614 "#version 300 es\n"
4615 "precision highp float;\n"
4616 "uniform highp sampler2D tex;\n"
4617 "in vec2 texcoord;\n"
4618 "out vec4 fragColor;\n"
4619 "void main()\n"
4620 "{\n"
4621 " fragColor = texture(tex, texcoord);\n"
4622 "}\n";
Jamie Madill35cd7332018-12-02 12:03:33 -05004623
4624 ANGLE_GL_PROGRAM(program, kVS, kFS);
Till Rathmannc1551dc2018-08-15 17:04:49 +02004625
4626 GLSampler sampler;
4627 glBindSampler(0, sampler);
4628 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4629 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4630
4631 glActiveTexture(GL_TEXTURE0);
4632 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4633
4634 const GLsizei texWidth = getWindowWidth();
4635 const GLsizei texHeight = getWindowHeight();
4636 const std::vector<GLColor> whiteData(texWidth * texHeight, GLColor::white);
4637
4638 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4639 whiteData.data());
4640 EXPECT_GL_NO_ERROR();
4641
4642 drawQuad(program, "position", 0.5f);
4643 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, angle::GLColor::white);
4644}
4645
Anders Leinof6cbe442019-04-18 15:32:07 +03004646// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4647// texture is output.
4648TEST_P(Texture2DIntegerTestES3, IntegerTextureNonZeroBaseLevel)
4649{
Yuly Novikovd2683452019-05-23 16:11:19 -04004650 // http://anglebug.com/3478
4651 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsDesktopOpenGL());
4652
Anders Leinof6cbe442019-04-18 15:32:07 +03004653 glActiveTexture(GL_TEXTURE0);
4654 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4655 int width = getWindowWidth();
4656 int height = getWindowHeight();
4657 GLColor color = GLColor::green;
4658 std::vector<GLColor> pixels(width * height, color);
4659 GLint baseLevel = 1;
4660 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
4661 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4662 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4663 glTexImage2D(GL_TEXTURE_2D, baseLevel, GL_RGBA8UI, width, height, 0, GL_RGBA_INTEGER,
4664 GL_UNSIGNED_BYTE, pixels.data());
4665
4666 setUpProgram();
4667 glUseProgram(mProgram);
4668 glUniform1i(mTexture2DUniformLocation, 0);
4669 drawQuad(mProgram, "position", 0.5f);
4670
4671 EXPECT_GL_NO_ERROR();
4672 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4673 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4674}
4675
Anders Leino60cc7512019-05-06 09:25:27 +03004676// Draw a quad with an integer cube texture with a non-zero base level, and test that the color of
4677// the texture is output.
4678TEST_P(TextureCubeIntegerTestES3, IntegerCubeTextureNonZeroBaseLevel)
4679{
4680 // All output checks returned black, rather than the texture color.
4681 ANGLE_SKIP_TEST_IF(IsOSX() && IsOpenGL());
4682
4683 glActiveTexture(GL_TEXTURE0);
4684
4685 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
4686 GLint baseLevel = 1;
4687 int width = getWindowWidth();
4688 int height = getWindowHeight();
4689 GLColor color = GLColor::green;
4690 std::vector<GLColor> pixels(width * height, color);
4691 for (GLenum faceIndex = 0; faceIndex < 6; faceIndex++)
4692 {
4693 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, baseLevel, GL_RGBA8UI, width,
4694 height, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
4695 EXPECT_GL_NO_ERROR();
4696 }
4697 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, baseLevel);
4698 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4699 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4700
4701 glUseProgram(mProgram);
4702 glUniform1i(mTextureCubeUniformLocation, 0);
4703 drawQuad(mProgram, "position", 0.5f);
4704
4705 EXPECT_GL_NO_ERROR();
4706 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4707 EXPECT_PIXEL_COLOR_EQ(width - 1, 0, color);
4708 EXPECT_PIXEL_COLOR_EQ(0, height - 1, color);
4709 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4710}
4711
Anders Leinoe4452442019-05-09 13:29:49 +03004712// This test sets up a cube map with four distincly colored MIP levels.
4713// The size of the texture and the geometry is chosen such that levels 1 or 2 should be chosen at
4714// the corners of the screen.
4715TEST_P(TextureCubeIntegerEdgeTestES3, IntegerCubeTextureCorner)
4716{
4717 glActiveTexture(GL_TEXTURE0);
4718
4719 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
4720 int width = getWindowWidth();
4721 int height = getWindowHeight();
4722 ASSERT_EQ(width, height);
4723 GLColor color[4] = {GLColor::white, GLColor::green, GLColor::blue, GLColor::red};
4724 for (GLint level = 0; level < 4; level++)
4725 {
4726 for (GLenum faceIndex = 0; faceIndex < 6; faceIndex++)
4727 {
4728 int levelWidth = (2 * width) >> level;
4729 int levelHeight = (2 * height) >> level;
4730 std::vector<GLColor> pixels(levelWidth * levelHeight, color[level]);
4731 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, level, GL_RGBA8UI, levelWidth,
4732 levelHeight, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
4733 EXPECT_GL_NO_ERROR();
4734 }
4735 }
4736 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4737 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4738 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 3);
4739
4740 glUseProgram(mProgram);
4741 glUniform1i(mTextureCubeUniformLocation, 0);
4742 drawQuad(mProgram, "position", 0.5f);
4743
4744 ASSERT_GL_NO_ERROR();
4745 // Check that we do not read from levels 0 or 3. Levels 1 and 2 are both acceptable.
4746 EXPECT_EQ(ReadColor(0, 0).R, 0);
4747 EXPECT_EQ(ReadColor(width - 1, 0).R, 0);
4748 EXPECT_EQ(ReadColor(0, height - 1).R, 0);
4749 EXPECT_EQ(ReadColor(width - 1, height - 1).R, 0);
4750}
4751
Anders Leino1b6aded2019-05-20 12:56:34 +03004752// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4753// texture is output.
4754TEST_P(Texture2DIntegerProjectiveOffsetTestES3, NonZeroBaseLevel)
4755{
Jamie Madill29ac2742019-05-28 15:53:00 -04004756 // Fails on AMD: http://crbug.com/967796
Jamie Madill06055b52019-05-29 14:31:42 -04004757 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsOpenGL());
Jamie Madill29ac2742019-05-28 15:53:00 -04004758
Anders Leino1b6aded2019-05-20 12:56:34 +03004759 glActiveTexture(GL_TEXTURE0);
4760 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4761 int width = getWindowWidth();
4762 int height = getWindowHeight();
4763 GLColor color = GLColor::green;
4764 std::vector<GLColor> pixels(width * height, color);
4765 GLint baseLevel = 1;
4766 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
4767 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4768 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4769 glTexImage2D(GL_TEXTURE_2D, baseLevel, GL_RGBA8UI, width, height, 0, GL_RGBA_INTEGER,
4770 GL_UNSIGNED_BYTE, pixels.data());
4771
4772 setUpProgram();
4773 glUseProgram(mProgram);
4774 glUniform1i(mTexture2DUniformLocation, 0);
4775 drawQuad(mProgram, "position", 0.5f);
4776
4777 EXPECT_GL_NO_ERROR();
4778 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4779 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4780}
4781
Anders Leino69d04932019-05-20 14:04:13 +03004782// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4783// texture is output.
4784TEST_P(Texture2DArrayIntegerTestES3, NonZeroBaseLevel)
4785{
4786 glActiveTexture(GL_TEXTURE0);
4787 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
4788 int width = getWindowWidth();
4789 int height = getWindowHeight();
4790 int depth = 2;
4791 GLColor color = GLColor::green;
4792 std::vector<GLColor> pixels(width * height * depth, color);
4793 GLint baseLevel = 1;
4794 glTexImage3D(GL_TEXTURE_2D_ARRAY, baseLevel, GL_RGBA8UI, width, height, depth, 0,
4795 GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
4796 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, baseLevel);
4797 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4798 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4799
4800 drawQuad(mProgram, "position", 0.5f);
4801
4802 EXPECT_GL_NO_ERROR();
4803 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4804 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4805}
4806
Anders Leino262e2822019-05-20 14:24:40 +03004807// Draw a quad with an integer 3D texture with a non-zero base level, and test that the color of the
4808// texture is output.
4809TEST_P(Texture3DIntegerTestES3, NonZeroBaseLevel)
4810{
4811 glActiveTexture(GL_TEXTURE0);
4812 glBindTexture(GL_TEXTURE_3D, mTexture3D);
4813 int width = getWindowWidth();
4814 int height = getWindowHeight();
4815 int depth = 2;
4816 GLColor color = GLColor::green;
4817 std::vector<GLColor> pixels(width * height * depth, color);
4818 GLint baseLevel = 1;
4819 glTexImage3D(GL_TEXTURE_3D, baseLevel, GL_RGBA8UI, width, height, depth, 0, GL_RGBA_INTEGER,
4820 GL_UNSIGNED_BYTE, pixels.data());
4821 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, baseLevel);
4822 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4823 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4824
4825 drawQuad(mProgram, "position", 0.5f);
4826
4827 EXPECT_GL_NO_ERROR();
4828 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4829 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4830}
4831
Jamie Madill50cf2be2018-06-15 09:46:57 -04004832// Use this to select which configurations (e.g. which renderer, which GLES major version) these
4833// tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -05004834ANGLE_INSTANTIATE_TEST(Texture2DTest,
4835 ES2_D3D9(),
4836 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004837 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05004838 ES2_OPENGLES(),
4839 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004840ANGLE_INSTANTIATE_TEST(TextureCubeTest,
4841 ES2_D3D9(),
4842 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004843 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004844 ES2_OPENGLES(),
4845 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004846ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
4847 ES2_D3D9(),
4848 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004849 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004850 ES2_OPENGLES(),
4851 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004852ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
4853 ES2_D3D9(),
4854 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004855 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004856 ES2_OPENGLES(),
4857 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004858ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
4859 ES2_D3D9(),
4860 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004861 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004862 ES2_OPENGLES(),
4863 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004864ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
4865 ES2_D3D9(),
4866 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004867 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004868 ES2_OPENGLES(),
4869 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004870ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02004871ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02004872ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4873ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
4874 ES3_D3D11(),
4875 ES3_OPENGL(),
4876 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004877ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
4878 ES3_D3D11(),
4879 ES3_OPENGL(),
4880 ES3_OPENGLES());
4881ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4882ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02004883ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02004884ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
4885 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004886 ES2_D3D9(),
4887 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004888 ES2_OPENGLES(),
4889 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004890ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
4891 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004892 ES2_D3D9(),
4893 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004894 ES2_OPENGLES(),
4895 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004896ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
4897 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004898 ES2_D3D9(),
4899 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004900 ES2_OPENGLES(),
4901 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004902ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
4903 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004904 ES2_D3D9(),
4905 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004906 ES2_OPENGLES(),
4907 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004908ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
4909 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004910 ES2_D3D9(),
4911 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004912 ES2_OPENGLES(),
4913 ES2_VULKAN());
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05004914ANGLE_INSTANTIATE_TEST(TextureAnisotropyTest,
4915 ES2_D3D11(),
4916 ES2_D3D9(),
4917 ES2_OPENGL(),
4918 ES2_OPENGLES(),
4919 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02004920ANGLE_INSTANTIATE_TEST(TextureBorderClampTest,
4921 ES2_D3D11(),
4922 ES2_D3D9(),
4923 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004924 ES2_OPENGLES(),
4925 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02004926ANGLE_INSTANTIATE_TEST(TextureBorderClampTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4927ANGLE_INSTANTIATE_TEST(TextureBorderClampIntegerTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Luc Ferronaf883622018-06-08 15:57:31 -04004928ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN());
Vincent Lang25ab4512016-05-13 18:13:59 +02004929ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03004930ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Anders Leinof6cbe442019-04-18 15:32:07 +03004931ANGLE_INSTANTIATE_TEST(Texture2DIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino60cc7512019-05-06 09:25:27 +03004932ANGLE_INSTANTIATE_TEST(TextureCubeIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leinoe4452442019-05-09 13:29:49 +03004933ANGLE_INSTANTIATE_TEST(TextureCubeIntegerEdgeTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino1b6aded2019-05-20 12:56:34 +03004934ANGLE_INSTANTIATE_TEST(Texture2DIntegerProjectiveOffsetTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino69d04932019-05-20 14:04:13 +03004935ANGLE_INSTANTIATE_TEST(Texture2DArrayIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino262e2822019-05-20 14:24:40 +03004936ANGLE_INSTANTIATE_TEST(Texture3DIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Jamie Madillfa05f602015-05-07 13:47:11 -04004937
Jamie Madill7ffdda92016-09-08 13:26:51 -04004938} // anonymous namespace