blob: cb7a1db49eb53a09d5ddc5250ffdc2556636c906 [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{
Yuly Novikovc5da7992019-06-27 12:57:13 -04002197 // Crashes on Intel Ubuntu 19.04 Mesa 19.0.2 GL. http://anglebug.com/2782
2198 ANGLE_SKIP_TEST_IF(IsLinux() && IsIntel() && IsDesktopOpenGL());
2199
Olli Etuahoa314b612016-03-10 16:43:00 +02002200 glActiveTexture(GL_TEXTURE0);
2201 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2202 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2203 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2204 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2205
2206 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2207 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2208
2209 // Two levels that are initially unused.
2210 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2211 texDataRed.data());
2212 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2213 texDataCyan.data());
2214
2215 // One level that is used - only this level should affect completeness.
2216 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2217 texDataGreen.data());
2218
2219 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
2220 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2221
2222 EXPECT_GL_NO_ERROR();
2223
2224 drawQuad(mProgram, "position", 0.5f);
2225
2226 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2227
Yunchao He2f23f352018-02-11 22:11:37 +08002228 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02002229
2230 // Switch the level that is being used to the cyan level 2.
2231 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
2232 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
2233
2234 EXPECT_GL_NO_ERROR();
2235
2236 drawQuad(mProgram, "position", 0.5f);
2237
2238 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2239}
2240
2241// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2242// have images defined.
2243TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
2244{
Olli Etuahoa314b612016-03-10 16:43:00 +02002245 glActiveTexture(GL_TEXTURE0);
2246 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
2247 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2248 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2249 texDataGreen.data());
2250 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2251 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2252 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2253 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2254
2255 EXPECT_GL_NO_ERROR();
2256
2257 drawQuad(mProgram, "position", 0.5f);
2258
2259 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2260}
2261
2262// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2263// dimensions that don't fit the images inside the range.
2264// GLES 3.0.4 section 3.8.13 Texture completeness
2265TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2266{
Olli Etuahoa314b612016-03-10 16:43:00 +02002267 glActiveTexture(GL_TEXTURE0);
2268 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
2269 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2270 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2271 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2272
2273 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2274 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2275
2276 // Two levels that are initially unused.
2277 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2278 texDataRed.data());
2279 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2280 texDataCyan.data());
2281
2282 // One level that is used - only this level should affect completeness.
2283 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2284 texDataGreen.data());
2285
2286 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2287 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2288
2289 EXPECT_GL_NO_ERROR();
2290
2291 drawQuad(mProgram, "position", 0.5f);
2292
2293 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2294
Yunchao He2f23f352018-02-11 22:11:37 +08002295 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
2296
Yunchao He9550c602018-02-13 14:47:05 +08002297 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
2298 // level was changed.
2299 ANGLE_SKIP_TEST_IF(IsNVIDIA() && (IsOpenGL() || IsOpenGLES()));
Olli Etuahoa314b612016-03-10 16:43:00 +02002300
2301 // Switch the level that is being used to the cyan level 2.
2302 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2303 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2304
2305 EXPECT_GL_NO_ERROR();
2306
2307 drawQuad(mProgram, "position", 0.5f);
2308
2309 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2310}
2311
2312// Test that texture completeness is updated if texture max level changes.
2313// GLES 3.0.4 section 3.8.13 Texture completeness
2314TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2315{
Olli Etuahoa314b612016-03-10 16:43:00 +02002316 glActiveTexture(GL_TEXTURE0);
2317 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2318 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2319
2320 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2321 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2322
2323 // A level that is initially unused.
2324 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2325 texDataGreen.data());
2326
2327 // One level that is initially used - only this level should affect completeness.
2328 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2329 texDataGreen.data());
2330
2331 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2332 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2333
2334 EXPECT_GL_NO_ERROR();
2335
2336 drawQuad(mProgram, "position", 0.5f);
2337
2338 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2339
2340 // Switch the max level to level 1. The levels within the used range now have inconsistent
2341 // dimensions and the texture should be incomplete.
2342 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2343
2344 EXPECT_GL_NO_ERROR();
2345
2346 drawQuad(mProgram, "position", 0.5f);
2347
2348 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2349}
2350
2351// Test that 3D texture completeness is updated if texture max level changes.
2352// GLES 3.0.4 section 3.8.13 Texture completeness
2353TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2354{
Olli Etuahoa314b612016-03-10 16:43:00 +02002355 glActiveTexture(GL_TEXTURE0);
2356 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2357 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2358
2359 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2360 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2361
2362 // A level that is initially unused.
2363 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2364 texDataGreen.data());
2365
2366 // One level that is initially used - only this level should affect completeness.
2367 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2368 texDataGreen.data());
2369
2370 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2371 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2372
2373 EXPECT_GL_NO_ERROR();
2374
2375 drawQuad(mProgram, "position", 0.5f);
2376
2377 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2378
2379 // Switch the max level to level 1. The levels within the used range now have inconsistent
2380 // dimensions and the texture should be incomplete.
2381 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2382
2383 EXPECT_GL_NO_ERROR();
2384
2385 drawQuad(mProgram, "position", 0.5f);
2386
2387 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2388}
2389
2390// Test that texture completeness is updated if texture base level changes.
2391// GLES 3.0.4 section 3.8.13 Texture completeness
2392TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2393{
Olli Etuahoa314b612016-03-10 16:43:00 +02002394 glActiveTexture(GL_TEXTURE0);
2395 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2396 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2397
2398 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2399 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2400
2401 // Two levels that are initially unused.
2402 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2403 texDataGreen.data());
2404 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2405 texDataGreen.data());
2406
2407 // One level that is initially used - only this level should affect completeness.
2408 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2409 texDataGreen.data());
2410
2411 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2412 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2413
2414 EXPECT_GL_NO_ERROR();
2415
2416 drawQuad(mProgram, "position", 0.5f);
2417
2418 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2419
2420 // Switch the base level to level 1. The levels within the used range now have inconsistent
2421 // dimensions and the texture should be incomplete.
2422 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2423
2424 EXPECT_GL_NO_ERROR();
2425
2426 drawQuad(mProgram, "position", 0.5f);
2427
2428 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2429}
2430
2431// Test that texture is not complete if base level is greater than max level.
2432// GLES 3.0.4 section 3.8.13 Texture completeness
2433TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2434{
Olli Etuahoa314b612016-03-10 16:43:00 +02002435 glActiveTexture(GL_TEXTURE0);
2436 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2437
2438 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2439 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2440
2441 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2442
2443 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2444 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2445
2446 EXPECT_GL_NO_ERROR();
2447
2448 drawQuad(mProgram, "position", 0.5f);
2449
2450 // Texture should be incomplete.
2451 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2452}
2453
2454// Test that immutable texture base level and max level are clamped.
2455// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2456TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2457{
Olli Etuahoa314b612016-03-10 16:43:00 +02002458 glActiveTexture(GL_TEXTURE0);
2459 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2460
2461 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2462 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2463
2464 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2465
2466 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2467
2468 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2469 // should be clamped to [base_level, levels - 1].
2470 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2471 // In the case of this test, those rules make the effective base level and max level 0.
2472 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2473 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2474
2475 EXPECT_GL_NO_ERROR();
2476
2477 drawQuad(mProgram, "position", 0.5f);
2478
2479 // Texture should be complete.
2480 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2481}
2482
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002483// Test that changing base level works when it affects the format of the texture.
2484TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2485{
Yunchao He9550c602018-02-13 14:47:05 +08002486 // Observed rendering corruption on NVIDIA OpenGL.
2487 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL());
2488
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002489 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002490
2491 // Observed incorrect rendering on AMD OpenGL.
2492 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002493
2494 glActiveTexture(GL_TEXTURE0);
2495 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2496 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2497 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2498
2499 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2500 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2501
2502 // RGBA8 level that's initially unused.
2503 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2504 texDataCyan.data());
2505
2506 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2507 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2508
2509 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2510 // format. It reads green channel data from the green and alpha channels of texDataGreen
2511 // (this is a bit hacky but works).
2512 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2513
2514 EXPECT_GL_NO_ERROR();
2515
2516 drawQuad(mProgram, "position", 0.5f);
2517
2518 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2519
2520 // Switch the texture to use the cyan level 0 with the RGBA format.
2521 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2522 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2523
2524 EXPECT_GL_NO_ERROR();
2525
2526 drawQuad(mProgram, "position", 0.5f);
2527
2528 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2529}
2530
Olli Etuahoa314b612016-03-10 16:43:00 +02002531// Test that setting a texture image works when base level is out of range.
2532TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2533{
2534 glActiveTexture(GL_TEXTURE0);
2535 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2536
2537 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2538 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2539
2540 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2541 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2542
2543 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2544
2545 EXPECT_GL_NO_ERROR();
2546
2547 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2548
2549 drawQuad(mProgram, "position", 0.5f);
2550
2551 // Texture should be complete.
2552 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002553}
2554
Jamie Madill50cf2be2018-06-15 09:46:57 -04002555// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG
2556// RBA->RGBA8, with 1.0 in the alpha channel. This test covers a bug where redefining array textures
2557// with these formats does not work as expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002558TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002559{
2560 std::vector<GLubyte> pixelData;
2561 for (size_t count = 0; count < 5000; count++)
2562 {
2563 pixelData.push_back(0u);
2564 pixelData.push_back(255u);
2565 pixelData.push_back(0u);
2566 }
2567
2568 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002569 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002570 glUniform1i(mTextureArrayLocation, 0);
2571
2572 // The first draw worked correctly.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002573 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2574 &pixelData[0]);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002575
2576 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2577 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2578 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2579 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002580 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002581 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002582
2583 // The dimension of the respecification must match the original exactly to trigger the bug.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002584 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2585 &pixelData[0]);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002586 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002587 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002588
2589 ASSERT_GL_NO_ERROR();
2590}
2591
Olli Etuaho1a679902016-01-14 12:21:47 +02002592// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2593// This test is needed especially to confirm that sampler registers get assigned correctly on
2594// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2595TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2596{
2597 glActiveTexture(GL_TEXTURE0);
2598 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2599 GLubyte texData[4];
2600 texData[0] = 0;
2601 texData[1] = 60;
2602 texData[2] = 0;
2603 texData[3] = 255;
2604 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2605
2606 glActiveTexture(GL_TEXTURE1);
2607 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2608 GLfloat depthTexData[1];
2609 depthTexData[0] = 0.5f;
2610 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2611 depthTexData);
2612
2613 glUseProgram(mProgram);
2614 glUniform1f(mDepthRefUniformLocation, 0.3f);
2615 glUniform1i(mTexture3DUniformLocation, 0);
2616 glUniform1i(mTextureShadowUniformLocation, 1);
2617
2618 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2619 drawQuad(mProgram, "position", 0.5f);
2620 EXPECT_GL_NO_ERROR();
2621 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2622 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2623
2624 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2625 drawQuad(mProgram, "position", 0.5f);
2626 EXPECT_GL_NO_ERROR();
2627 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2628 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2629}
2630
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002631// Test multiple different sampler types in the same shader.
2632// This test makes sure that even if sampler / texture registers get grouped together based on type
2633// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2634// still has the right register index information for each ESSL sampler.
2635// The tested ESSL samplers have the following types in D3D11 HLSL:
2636// sampler2D: Texture2D + SamplerState
2637// samplerCube: TextureCube + SamplerState
2638// sampler2DShadow: Texture2D + SamplerComparisonState
2639// samplerCubeShadow: TextureCube + SamplerComparisonState
2640TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2641{
2642 glActiveTexture(GL_TEXTURE0);
2643 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2644 GLubyte texData[4];
2645 texData[0] = 0;
2646 texData[1] = 0;
2647 texData[2] = 120;
2648 texData[3] = 255;
2649 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2650
2651 glActiveTexture(GL_TEXTURE1);
2652 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2653 texData[0] = 0;
2654 texData[1] = 90;
2655 texData[2] = 0;
2656 texData[3] = 255;
2657 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2658 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2659 texData);
2660
2661 glActiveTexture(GL_TEXTURE2);
2662 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2663 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2664 GLfloat depthTexData[1];
2665 depthTexData[0] = 0.5f;
2666 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2667 depthTexData);
2668
2669 glActiveTexture(GL_TEXTURE3);
2670 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2671 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2672 depthTexData[0] = 0.2f;
2673 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2674 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2675 depthTexData);
2676
2677 EXPECT_GL_NO_ERROR();
2678
2679 glUseProgram(mProgram);
2680 glUniform1f(mDepthRefUniformLocation, 0.3f);
2681 glUniform1i(mTexture2DUniformLocation, 0);
2682 glUniform1i(mTextureCubeUniformLocation, 1);
2683 glUniform1i(mTexture2DShadowUniformLocation, 2);
2684 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2685
2686 drawQuad(mProgram, "position", 0.5f);
2687 EXPECT_GL_NO_ERROR();
2688 // The shader writes:
2689 // <texture 2d color> +
2690 // <cube map color> +
2691 // 0.25 * <comparison result (1.0)> +
2692 // 0.125 * <comparison result (0.0)>
2693 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2694}
2695
Olli Etuahobce743a2016-01-15 17:18:28 +02002696// Test different base levels on textures accessed through the same sampler array.
2697// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2698TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2699{
Yunchao He9550c602018-02-13 14:47:05 +08002700 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2701
Olli Etuahobce743a2016-01-15 17:18:28 +02002702 glActiveTexture(GL_TEXTURE0);
2703 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2704 GLsizei size = 64;
2705 for (GLint level = 0; level < 7; ++level)
2706 {
2707 ASSERT_LT(0, size);
2708 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2709 nullptr);
2710 size = size / 2;
2711 }
2712 ASSERT_EQ(0, size);
2713 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2714
2715 glActiveTexture(GL_TEXTURE1);
2716 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2717 size = 128;
2718 for (GLint level = 0; level < 8; ++level)
2719 {
2720 ASSERT_LT(0, size);
2721 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2722 nullptr);
2723 size = size / 2;
2724 }
2725 ASSERT_EQ(0, size);
2726 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2727 EXPECT_GL_NO_ERROR();
2728
2729 glUseProgram(mProgram);
2730 glUniform1i(mTexture0Location, 0);
2731 glUniform1i(mTexture1Location, 1);
2732
Olli Etuaho5804dc82018-04-13 14:11:46 +03002733 drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
Olli Etuahobce743a2016-01-15 17:18:28 +02002734 EXPECT_GL_NO_ERROR();
2735 // Red channel: width of level 1 of texture A: 32.
2736 // Green channel: width of level 3 of texture B: 16.
2737 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2738}
2739
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002740// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2741// ES 3.0.4 table 3.24
2742TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2743{
2744 glActiveTexture(GL_TEXTURE0);
2745 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2746 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2747 EXPECT_GL_NO_ERROR();
2748
2749 drawQuad(mProgram, "position", 0.5f);
2750
2751 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2752}
2753
2754// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2755// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002756TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002757{
Luc Ferron5164b792018-03-06 09:10:12 -05002758 setUpProgram();
2759
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002760 glActiveTexture(GL_TEXTURE0);
2761 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2762 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2763 EXPECT_GL_NO_ERROR();
2764
2765 drawQuad(mProgram, "position", 0.5f);
2766
2767 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2768}
2769
Luc Ferron5164b792018-03-06 09:10:12 -05002770// Validate that every component of the pixel will be equal to the luminance value we've set
2771// and that the alpha channel will be 1 (or 255 to be exact).
2772TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2773{
2774 setUpProgram();
2775
2776 glActiveTexture(GL_TEXTURE0);
2777 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2778 uint8_t pixel = 50;
2779 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2780 EXPECT_GL_NO_ERROR();
2781
2782 drawQuad(mProgram, "position", 0.5f);
2783
2784 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2785}
2786
2787// Validate that every component of the pixel will be equal to the luminance value we've set
2788// and that the alpha channel will be the second component.
2789TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2790{
2791 setUpProgram();
2792
2793 glActiveTexture(GL_TEXTURE0);
2794 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2795 uint8_t pixel[] = {50, 25};
2796 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2797 GL_UNSIGNED_BYTE, pixel);
2798 EXPECT_GL_NO_ERROR();
2799
2800 drawQuad(mProgram, "position", 0.5f);
2801
2802 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2803}
2804
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002805// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2806// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002807TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002808{
Jamie Madillb8149072019-04-30 16:14:44 -04002809 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002810 ANGLE_SKIP_TEST_IF(IsD3D9());
2811 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002812
2813 setUpProgram();
2814
Luc Ferrond8c632c2018-04-10 12:31:44 -04002815 glActiveTexture(GL_TEXTURE0);
2816 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2817 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2818 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002819
Luc Ferrond8c632c2018-04-10 12:31:44 -04002820 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002821
Luc Ferrond8c632c2018-04-10 12:31:44 -04002822 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002823}
2824
2825// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2826// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002827TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002828{
Jamie Madillb8149072019-04-30 16:14:44 -04002829 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002830 ANGLE_SKIP_TEST_IF(IsD3D9());
2831 ANGLE_SKIP_TEST_IF(IsVulkan());
2832 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES());
2833 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2834 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002835
Luc Ferrond8c632c2018-04-10 12:31:44 -04002836 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002837
Luc Ferrond8c632c2018-04-10 12:31:44 -04002838 glActiveTexture(GL_TEXTURE0);
2839 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2840 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2841 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002842
Luc Ferrond8c632c2018-04-10 12:31:44 -04002843 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002844
Luc Ferrond8c632c2018-04-10 12:31:44 -04002845 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002846}
2847
2848// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2849// ES 3.0.4 table 3.24
2850TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2851{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002852 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2853
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002854 glActiveTexture(GL_TEXTURE0);
2855 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2856 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2857 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2858 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2859 EXPECT_GL_NO_ERROR();
2860
2861 drawQuad(mProgram, "position", 0.5f);
2862
2863 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2864}
2865
2866// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2867// ES 3.0.4 table 3.24
2868TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2869{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002870 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2871
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002872 glActiveTexture(GL_TEXTURE0);
2873 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2874
2875 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2876 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2877 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2878 EXPECT_GL_NO_ERROR();
2879
2880 drawQuad(mProgram, "position", 0.5f);
2881
2882 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2883}
2884
2885// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2886// ES 3.0.4 table 3.24
2887TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2888{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002889 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2890
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002891 glActiveTexture(GL_TEXTURE0);
2892 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2893 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2894 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2895 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2896 EXPECT_GL_NO_ERROR();
2897
2898 drawQuad(mProgram, "position", 0.5f);
2899
2900 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2901}
2902
2903// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2904// ES 3.0.4 table 3.24
2905TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2906{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002907 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2908
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002909 glActiveTexture(GL_TEXTURE0);
2910 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2911 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2912 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2913 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2914 EXPECT_GL_NO_ERROR();
2915
2916 drawQuad(mProgram, "position", 0.5f);
2917
2918 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2919}
2920
2921// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2922// ES 3.0.4 table 3.24
2923TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2924{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002925 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2926
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002927 glActiveTexture(GL_TEXTURE0);
2928 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2929 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2930 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2931 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2932 EXPECT_GL_NO_ERROR();
2933
2934 drawQuad(mProgram, "position", 0.5f);
2935
2936 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2937}
2938
2939// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2940// ES 3.0.4 table 3.24
2941TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2942{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002943 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2944
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002945 glActiveTexture(GL_TEXTURE0);
2946 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2947 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2948 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2949 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2950 EXPECT_GL_NO_ERROR();
2951
2952 drawQuad(mProgram, "position", 0.5f);
2953
2954 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2955}
2956
2957// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2958// ES 3.0.4 table 3.24
2959TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2960{
2961 glActiveTexture(GL_TEXTURE0);
2962 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2963 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2964 EXPECT_GL_NO_ERROR();
2965
2966 drawQuad(mProgram, "position", 0.5f);
2967
2968 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2969}
2970
2971// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2972// ES 3.0.4 table 3.24
2973TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2974{
2975 glActiveTexture(GL_TEXTURE0);
2976 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2977 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2978 nullptr);
2979 EXPECT_GL_NO_ERROR();
2980
2981 drawQuad(mProgram, "position", 0.5f);
2982
2983 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2984}
2985
2986// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2987// ES 3.0.4 table 3.24
2988TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2989{
Yunchao He9550c602018-02-13 14:47:05 +08002990 // Seems to fail on OSX 10.12 Intel.
2991 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Jamie Madillbb1db482017-01-10 10:48:32 -05002992
Yuly Novikov49886892018-01-23 21:18:27 -05002993 // http://anglebug.com/2190
2994 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2995
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002996 glActiveTexture(GL_TEXTURE0);
2997 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2998 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2999 EXPECT_GL_NO_ERROR();
3000
3001 drawQuad(mProgram, "position", 0.5f);
3002
3003 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
3004}
3005
3006// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
3007// ES 3.0.4 table 3.24
3008TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
3009{
Yunchao He9550c602018-02-13 14:47:05 +08003010 // Seems to fail on OSX 10.12 Intel.
3011 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04003012
Yuly Novikov49886892018-01-23 21:18:27 -05003013 // http://anglebug.com/2190
3014 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
3015
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003016 glActiveTexture(GL_TEXTURE0);
3017 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3018 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
3019 EXPECT_GL_NO_ERROR();
3020
3021 drawQuad(mProgram, "position", 0.5f);
3022
3023 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
3024}
3025
Olli Etuaho96963162016-03-21 11:54:33 +02003026// Use a sampler in a uniform struct.
3027TEST_P(SamplerInStructTest, SamplerInStruct)
3028{
3029 runSamplerInStructTest();
3030}
3031
3032// Use a sampler in a uniform struct that's passed as a function parameter.
3033TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
3034{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003035 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
3036 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04003037
Olli Etuaho96963162016-03-21 11:54:33 +02003038 runSamplerInStructTest();
3039}
3040
3041// Use a sampler in a uniform struct array with a struct from the array passed as a function
3042// parameter.
3043TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
3044{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003045 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
3046 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08003047
Olli Etuaho96963162016-03-21 11:54:33 +02003048 runSamplerInStructTest();
3049}
3050
3051// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
3052// parameter.
3053TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
3054{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003055 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
3056 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08003057
Olli Etuaho96963162016-03-21 11:54:33 +02003058 runSamplerInStructTest();
3059}
3060
3061// Make sure that there isn't a name conflict between sampler extracted from a struct and a
3062// similarly named uniform.
3063TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
3064{
3065 runSamplerInStructTest();
3066}
3067
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05003068// GL_EXT_texture_filter_anisotropic
3069class TextureAnisotropyTest : public Texture2DTest
3070{
3071 protected:
3072 void uploadTexture()
3073 {
3074 glActiveTexture(GL_TEXTURE0);
3075 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3076 GLColor texDataRed[1] = {GLColor::red};
3077 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed);
3078 EXPECT_GL_NO_ERROR();
3079 }
3080};
3081
3082// Tests that setting anisotropic filtering doesn't cause failures at draw time.
3083TEST_P(TextureAnisotropyTest, AnisotropyFunctional)
3084{
Jamie Madillb8149072019-04-30 16:14:44 -04003085 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_filter_anisotropic"));
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05003086
3087 setUpProgram();
3088
3089 uploadTexture();
3090
3091 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3092 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3093 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f);
3094 EXPECT_GL_NO_ERROR();
3095
3096 drawQuad(mProgram, "position", 0.5f);
3097
3098 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3099 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3100 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::red);
3101}
3102
Till Rathmannb8543632018-10-02 19:46:14 +02003103// GL_OES_texture_border_clamp
3104class TextureBorderClampTest : public Texture2DTest
3105{
3106 protected:
3107 TextureBorderClampTest() : Texture2DTest() {}
3108
Jamie Madill35cd7332018-12-02 12:03:33 -05003109 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003110 {
3111 return
3112 R"(precision highp float;
3113 attribute vec4 position;
3114 varying vec2 texcoord;
3115
3116 void main()
3117 {
3118 gl_Position = vec4(position.xy, 0.0, 1.0);
3119 // texcoords in [-0.5, 1.5]
3120 texcoord = (position.xy) + 0.5;
3121 })";
3122 }
3123
3124 void uploadTexture()
3125 {
3126 glActiveTexture(GL_TEXTURE0);
3127 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3128 std::vector<GLColor> texDataRed(1, GLColor::red);
3129 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3130 texDataRed.data());
3131 EXPECT_GL_NO_ERROR();
3132 }
3133};
3134
3135// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3136// GL_CLAMP_TO_BORDER wrap mode (set with glTexParameter).
3137TEST_P(TextureBorderClampTest, TextureBorderClampFunctional)
3138{
Jamie Madillb8149072019-04-30 16:14:44 -04003139 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003140
3141 setUpProgram();
3142
3143 uploadTexture();
3144
3145 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3146 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3147 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3148 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3149 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3150 EXPECT_GL_NO_ERROR();
3151
3152 drawQuad(mProgram, "position", 0.5f);
3153
3154 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3155 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3156 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3157}
3158
3159// Test reading back GL_TEXTURE_BORDER_COLOR by glGetTexParameter.
3160TEST_P(TextureBorderClampTest, TextureBorderClampFunctional2)
3161{
Jamie Madillb8149072019-04-30 16:14:44 -04003162 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003163
3164 glActiveTexture(GL_TEXTURE0);
3165 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3166
3167 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3168
3169 GLint colorFixedPoint[4] = {0};
3170 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3171 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3172 std::numeric_limits<GLint>::max()};
3173 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3174 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3175 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3176 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3177
3178 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3179 std::numeric_limits<GLint>::max()};
3180 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3181
3182 GLfloat color[4] = {0.0f};
3183 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
3184 EXPECT_EQ(color[0], kFloatBlue.R);
3185 EXPECT_EQ(color[1], kFloatBlue.G);
3186 EXPECT_EQ(color[2], kFloatBlue.B);
3187 EXPECT_EQ(color[3], kFloatBlue.A);
3188}
3189
3190// Test GL_TEXTURE_BORDER_COLOR parameter validation at glTexParameter.
3191TEST_P(TextureBorderClampTest, TextureBorderClampValidation)
3192{
Jamie Madillb8149072019-04-30 16:14:44 -04003193 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003194
3195 glActiveTexture(GL_TEXTURE0);
3196 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3197
3198 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, 1.0f);
3199 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3200
3201 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3202 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3203
3204 glTexParameterfv(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3205 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3206
3207 GLint colorInt[4] = {0};
3208 glTexParameteriv(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_BORDER_COLOR, colorInt);
3209 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3210
3211 if (getClientMajorVersion() < 3)
3212 {
3213 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3214 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3215 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3216 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3217
3218 GLuint colorUInt[4] = {0};
3219 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3220 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3221 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3222 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3223
3224 GLSampler sampler;
3225 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3226 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3227 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3228 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3229
3230 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3231 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3232 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3233 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3234 }
3235}
3236
3237class TextureBorderClampTestES3 : public TextureBorderClampTest
3238{
3239 protected:
3240 TextureBorderClampTestES3() : TextureBorderClampTest() {}
3241};
3242
3243// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3244// GL_CLAMP_TO_BORDER wrap mode (set with glSamplerParameter).
3245TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional)
3246{
Jamie Madillb8149072019-04-30 16:14:44 -04003247 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003248
3249 setUpProgram();
3250
3251 uploadTexture();
3252
3253 GLSampler sampler;
3254 glBindSampler(0, sampler);
3255 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3256 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3257 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3258 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3259 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3260 EXPECT_GL_NO_ERROR();
3261
3262 drawQuad(mProgram, "position", 0.5f);
3263
3264 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3265 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3266 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3267}
3268
3269// Test reading back GL_TEXTURE_BORDER_COLOR by glGetSamplerParameter.
3270TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional2)
3271{
Jamie Madillb8149072019-04-30 16:14:44 -04003272 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003273
3274 glActiveTexture(GL_TEXTURE0);
3275
3276 GLSampler sampler;
3277 glBindSampler(0, sampler);
3278
3279 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3280
3281 GLint colorFixedPoint[4] = {0};
3282 glGetSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3283 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3284 std::numeric_limits<GLint>::max()};
3285 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3286 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3287 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3288 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3289
3290 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3291 std::numeric_limits<GLint>::max()};
3292 glSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3293
3294 GLfloat color[4] = {0.0f};
3295 glGetSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, color);
3296 EXPECT_EQ(color[0], kFloatBlue.R);
3297 EXPECT_EQ(color[1], kFloatBlue.G);
3298 EXPECT_EQ(color[2], kFloatBlue.B);
3299 EXPECT_EQ(color[3], kFloatBlue.A);
3300
3301 constexpr GLint colorSomewhatRedInt[4] = {500000, 0, 0, std::numeric_limits<GLint>::max()};
3302 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedInt);
3303 GLint colorInt[4] = {0};
3304 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3305 EXPECT_EQ(colorInt[0], colorSomewhatRedInt[0]);
3306 EXPECT_EQ(colorInt[1], colorSomewhatRedInt[1]);
3307 EXPECT_EQ(colorInt[2], colorSomewhatRedInt[2]);
3308 EXPECT_EQ(colorInt[3], colorSomewhatRedInt[3]);
3309
3310 constexpr GLuint colorSomewhatRedUInt[4] = {500000, 0, 0, std::numeric_limits<GLuint>::max()};
3311 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedUInt);
3312 GLuint colorUInt[4] = {0};
3313 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3314 EXPECT_EQ(colorUInt[0], colorSomewhatRedUInt[0]);
3315 EXPECT_EQ(colorUInt[1], colorSomewhatRedUInt[1]);
3316 EXPECT_EQ(colorUInt[2], colorSomewhatRedUInt[2]);
3317 EXPECT_EQ(colorUInt[3], colorSomewhatRedUInt[3]);
3318
3319 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3320
3321 constexpr GLint colorSomewhatGreenInt[4] = {0, 500000, 0, std::numeric_limits<GLint>::max()};
3322 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenInt);
3323 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3324 EXPECT_EQ(colorInt[0], colorSomewhatGreenInt[0]);
3325 EXPECT_EQ(colorInt[1], colorSomewhatGreenInt[1]);
3326 EXPECT_EQ(colorInt[2], colorSomewhatGreenInt[2]);
3327 EXPECT_EQ(colorInt[3], colorSomewhatGreenInt[3]);
3328
3329 constexpr GLuint colorSomewhatGreenUInt[4] = {0, 500000, 0, std::numeric_limits<GLuint>::max()};
3330 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenUInt);
3331 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3332 EXPECT_EQ(colorUInt[0], colorSomewhatGreenUInt[0]);
3333 EXPECT_EQ(colorUInt[1], colorSomewhatGreenUInt[1]);
3334 EXPECT_EQ(colorUInt[2], colorSomewhatGreenUInt[2]);
3335 EXPECT_EQ(colorUInt[3], colorSomewhatGreenUInt[3]);
3336}
3337
3338// Test GL_TEXTURE_BORDER_COLOR parameter validation at glSamplerParameter.
3339TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Validation)
3340{
Jamie Madillb8149072019-04-30 16:14:44 -04003341 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003342
3343 glActiveTexture(GL_TEXTURE0);
3344
3345 GLSampler sampler;
3346 glBindSampler(0, sampler);
3347
3348 glSamplerParameterf(sampler, GL_TEXTURE_BORDER_COLOR, 1.0f);
3349 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3350
3351 glSamplerParameteri(sampler, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3352 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3353}
3354
3355class TextureBorderClampIntegerTestES3 : public Texture2DTest
3356{
3357 protected:
3358 TextureBorderClampIntegerTestES3() : Texture2DTest(), isUnsignedIntTest(false) {}
3359
Jamie Madill35cd7332018-12-02 12:03:33 -05003360 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003361 {
3362 return
3363 R"(#version 300 es
3364 out vec2 texcoord;
3365 in vec4 position;
3366
3367 void main()
3368 {
3369 gl_Position = vec4(position.xy, 0.0, 1.0);
3370 // texcoords in [-0.5, 1.5]
3371 texcoord = (position.xy) + 0.5;
3372 })";
3373 }
3374
Jamie Madillba319ba2018-12-29 10:29:33 -05003375 const char *getFragmentShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003376 {
Jamie Madill35cd7332018-12-02 12:03:33 -05003377 if (isUnsignedIntTest)
3378 {
3379 return "#version 300 es\n"
3380 "precision highp float;\n"
3381 "uniform highp usampler2D tex;\n"
3382 "in vec2 texcoord;\n"
3383 "out vec4 fragColor;\n"
Till Rathmannb8543632018-10-02 19:46:14 +02003384
Jamie Madill35cd7332018-12-02 12:03:33 -05003385 "void main()\n"
3386 "{\n"
3387 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3388 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3389 "fragColor = (texture(tex, texcoord).r == 150u)"
3390 " ? green : red;\n"
3391 "}\n";
3392 }
3393 else
3394 {
3395 return "#version 300 es\n"
3396 "precision highp float;\n"
3397 "uniform highp isampler2D tex;\n"
3398 "in vec2 texcoord;\n"
3399 "out vec4 fragColor;\n"
3400
3401 "void main()\n"
3402 "{\n"
3403 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3404 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3405 "fragColor = (texture(tex, texcoord).r == -50)"
3406 " ? green : red;\n"
3407 "}\n";
3408 }
Till Rathmannb8543632018-10-02 19:46:14 +02003409 }
3410
3411 void uploadTexture()
3412 {
3413 glActiveTexture(GL_TEXTURE0);
3414 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3415 if (isUnsignedIntTest)
3416 {
3417 std::vector<GLubyte> texData(4, 100);
3418 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE,
3419 texData.data());
3420 }
3421 else
3422 {
3423 std::vector<GLbyte> texData(4, 100);
3424 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8I, 1, 1, 0, GL_RGBA_INTEGER, GL_BYTE,
3425 texData.data());
3426 }
3427 EXPECT_GL_NO_ERROR();
3428 }
3429
3430 bool isUnsignedIntTest;
3431};
3432
3433// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3434// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3435TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger)
3436{
Jamie Madillb8149072019-04-30 16:14:44 -04003437 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003438
3439 setUpProgram();
3440
3441 uploadTexture();
3442
3443 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3444 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3445 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3446 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3447
3448 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3449 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3450
3451 EXPECT_GL_NO_ERROR();
3452
3453 drawQuad(mProgram, "position", 0.5f);
3454
3455 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3456 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3457 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3458}
3459
3460// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3461// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3462TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger2)
3463{
Jamie Madillb8149072019-04-30 16:14:44 -04003464 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003465
3466 setUpProgram();
3467
3468 uploadTexture();
3469
3470 GLSampler sampler;
3471 glBindSampler(0, sampler);
3472 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3473 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3474 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3475 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3476
3477 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3478 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3479
3480 EXPECT_GL_NO_ERROR();
3481
3482 drawQuad(mProgram, "position", 0.5f);
3483
3484 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3485 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3486 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3487}
3488
3489// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3490// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIuivOES).
3491TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned)
3492{
Jamie Madillb8149072019-04-30 16:14:44 -04003493 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003494
3495 isUnsignedIntTest = true;
3496
3497 setUpProgram();
3498
3499 uploadTexture();
3500
3501 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3502 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3503 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3504 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3505
3506 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3507 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3508
3509 EXPECT_GL_NO_ERROR();
3510
3511 drawQuad(mProgram, "position", 0.5f);
3512
3513 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3514 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3515 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3516}
3517
3518// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3519// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with
3520// glSamplerParameterIuivOES).
3521TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned2)
3522{
Jamie Madillb8149072019-04-30 16:14:44 -04003523 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003524
3525 isUnsignedIntTest = true;
3526
3527 setUpProgram();
3528
3529 uploadTexture();
3530
3531 GLSampler sampler;
3532 glBindSampler(0, sampler);
3533 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3534 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3535 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3536 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3537
3538 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3539 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3540
3541 EXPECT_GL_NO_ERROR();
3542
3543 drawQuad(mProgram, "position", 0.5f);
3544
3545 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3546 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3547 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3548}
3549
3550// ~GL_OES_texture_border_clamp
3551
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003552class TextureLimitsTest : public ANGLETest
3553{
3554 protected:
3555 struct RGBA8
3556 {
3557 uint8_t R, G, B, A;
3558 };
3559
3560 TextureLimitsTest()
3561 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
3562 {
3563 setWindowWidth(128);
3564 setWindowHeight(128);
3565 setConfigRedBits(8);
3566 setConfigGreenBits(8);
3567 setConfigBlueBits(8);
3568 setConfigAlphaBits(8);
3569 }
3570
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003571 void testSetUp() override
Jamie Madill0fdb9562018-09-17 17:18:43 -04003572 {
Jamie Madill0fdb9562018-09-17 17:18:43 -04003573 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
3574 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
3575 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
3576
3577 ASSERT_GL_NO_ERROR();
3578 }
3579
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003580 void testTearDown() override
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003581 {
3582 if (mProgram != 0)
3583 {
3584 glDeleteProgram(mProgram);
3585 mProgram = 0;
3586
3587 if (!mTextures.empty())
3588 {
3589 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
3590 }
3591 }
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003592 }
3593
3594 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
3595 GLint vertexTextureCount,
3596 GLint vertexActiveTextureCount,
3597 const std::string &fragPrefix,
3598 GLint fragmentTextureCount,
3599 GLint fragmentActiveTextureCount)
3600 {
3601 std::stringstream vertexShaderStr;
3602 vertexShaderStr << "attribute vec2 position;\n"
3603 << "varying vec4 color;\n"
3604 << "varying vec2 texCoord;\n";
3605
3606 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
3607 {
3608 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
3609 }
3610
3611 vertexShaderStr << "void main() {\n"
3612 << " gl_Position = vec4(position, 0, 1);\n"
3613 << " texCoord = (position * 0.5) + 0.5;\n"
3614 << " color = vec4(0);\n";
3615
3616 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
3617 {
3618 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
3619 << ", texCoord);\n";
3620 }
3621
3622 vertexShaderStr << "}";
3623
3624 std::stringstream fragmentShaderStr;
3625 fragmentShaderStr << "varying mediump vec4 color;\n"
3626 << "varying mediump vec2 texCoord;\n";
3627
3628 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
3629 {
3630 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
3631 }
3632
3633 fragmentShaderStr << "void main() {\n"
3634 << " gl_FragColor = color;\n";
3635
3636 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
3637 {
3638 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
3639 << ", texCoord);\n";
3640 }
3641
3642 fragmentShaderStr << "}";
3643
3644 const std::string &vertexShaderSource = vertexShaderStr.str();
3645 const std::string &fragmentShaderSource = fragmentShaderStr.str();
3646
Jamie Madill35cd7332018-12-02 12:03:33 -05003647 mProgram = CompileProgram(vertexShaderSource.c_str(), fragmentShaderSource.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003648 }
3649
3650 RGBA8 getPixel(GLint texIndex)
3651 {
3652 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3653 0, 255u};
3654 return pixel;
3655 }
3656
3657 void initTextures(GLint tex2DCount, GLint texCubeCount)
3658 {
3659 GLint totalCount = tex2DCount + texCubeCount;
3660 mTextures.assign(totalCount, 0);
3661 glGenTextures(totalCount, &mTextures[0]);
3662 ASSERT_GL_NO_ERROR();
3663
3664 std::vector<RGBA8> texData(16 * 16);
3665
3666 GLint texIndex = 0;
3667 for (; texIndex < tex2DCount; ++texIndex)
3668 {
3669 texData.assign(texData.size(), getPixel(texIndex));
3670 glActiveTexture(GL_TEXTURE0 + texIndex);
3671 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3672 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3673 &texData[0]);
3674 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3675 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3676 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3677 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3678 }
3679
3680 ASSERT_GL_NO_ERROR();
3681
3682 for (; texIndex < texCubeCount; ++texIndex)
3683 {
3684 texData.assign(texData.size(), getPixel(texIndex));
3685 glActiveTexture(GL_TEXTURE0 + texIndex);
3686 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3687 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3688 GL_UNSIGNED_BYTE, &texData[0]);
3689 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3690 GL_UNSIGNED_BYTE, &texData[0]);
3691 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3692 GL_UNSIGNED_BYTE, &texData[0]);
3693 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3694 GL_UNSIGNED_BYTE, &texData[0]);
3695 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3696 GL_UNSIGNED_BYTE, &texData[0]);
3697 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3698 GL_UNSIGNED_BYTE, &texData[0]);
3699 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3700 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3701 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3702 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3703 }
3704
3705 ASSERT_GL_NO_ERROR();
3706 }
3707
3708 void testWithTextures(GLint vertexTextureCount,
3709 const std::string &vertexTexturePrefix,
3710 GLint fragmentTextureCount,
3711 const std::string &fragmentTexturePrefix)
3712 {
3713 // Generate textures
3714 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3715
3716 glUseProgram(mProgram);
3717 RGBA8 expectedSum = {0};
3718 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3719 {
3720 std::stringstream uniformNameStr;
3721 uniformNameStr << vertexTexturePrefix << texIndex;
3722 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003723 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003724 ASSERT_NE(-1, location);
3725
3726 glUniform1i(location, texIndex);
3727 RGBA8 contribution = getPixel(texIndex);
3728 expectedSum.R += contribution.R;
3729 expectedSum.G += contribution.G;
3730 }
3731
3732 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3733 {
3734 std::stringstream uniformNameStr;
3735 uniformNameStr << fragmentTexturePrefix << texIndex;
3736 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003737 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003738 ASSERT_NE(-1, location);
3739
3740 glUniform1i(location, texIndex + vertexTextureCount);
3741 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3742 expectedSum.R += contribution.R;
3743 expectedSum.G += contribution.G;
3744 }
3745
3746 ASSERT_GE(256u, expectedSum.G);
3747
3748 drawQuad(mProgram, "position", 0.5f);
3749 ASSERT_GL_NO_ERROR();
3750 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3751 }
3752
3753 GLuint mProgram;
3754 std::vector<GLuint> mTextures;
3755 GLint mMaxVertexTextures;
3756 GLint mMaxFragmentTextures;
3757 GLint mMaxCombinedTextures;
3758};
3759
3760// Test rendering with the maximum vertex texture units.
3761TEST_P(TextureLimitsTest, MaxVertexTextures)
3762{
3763 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3764 ASSERT_NE(0u, mProgram);
3765 ASSERT_GL_NO_ERROR();
3766
3767 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3768}
3769
3770// Test rendering with the maximum fragment texture units.
3771TEST_P(TextureLimitsTest, MaxFragmentTextures)
3772{
3773 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3774 ASSERT_NE(0u, mProgram);
3775 ASSERT_GL_NO_ERROR();
3776
3777 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3778}
3779
3780// Test rendering with maximum combined texture units.
3781TEST_P(TextureLimitsTest, MaxCombinedTextures)
3782{
3783 GLint vertexTextures = mMaxVertexTextures;
3784
3785 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3786 {
3787 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3788 }
3789
3790 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3791 mMaxFragmentTextures, mMaxFragmentTextures);
3792 ASSERT_NE(0u, mProgram);
3793 ASSERT_GL_NO_ERROR();
3794
3795 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3796}
3797
3798// Negative test for exceeding the number of vertex textures
3799TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3800{
3801 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3802 0);
3803 ASSERT_EQ(0u, mProgram);
3804}
3805
3806// Negative test for exceeding the number of fragment textures
3807TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3808{
3809 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3810 mMaxFragmentTextures + 1);
3811 ASSERT_EQ(0u, mProgram);
3812}
3813
3814// Test active vertex textures under the limit, but excessive textures specified.
3815TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3816{
3817 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3818 ASSERT_NE(0u, mProgram);
3819 ASSERT_GL_NO_ERROR();
3820
3821 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3822}
3823
3824// Test active fragment textures under the limit, but excessive textures specified.
3825TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3826{
3827 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3828 mMaxFragmentTextures);
3829 ASSERT_NE(0u, mProgram);
3830 ASSERT_GL_NO_ERROR();
3831
3832 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3833}
3834
3835// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003836// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003837TEST_P(TextureLimitsTest, TextureTypeConflict)
3838{
Jamie Madill35cd7332018-12-02 12:03:33 -05003839 constexpr char kVS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003840 "attribute vec2 position;\n"
3841 "varying float color;\n"
3842 "uniform sampler2D tex2D;\n"
3843 "uniform samplerCube texCube;\n"
3844 "void main() {\n"
3845 " gl_Position = vec4(position, 0, 1);\n"
3846 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3847 " color = texture2D(tex2D, texCoord).x;\n"
3848 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3849 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05003850 constexpr char kFS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003851 "varying mediump float color;\n"
3852 "void main() {\n"
3853 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3854 "}";
3855
Jamie Madill35cd7332018-12-02 12:03:33 -05003856 mProgram = CompileProgram(kVS, kFS);
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003857 ASSERT_NE(0u, mProgram);
3858
3859 initTextures(1, 0);
3860
3861 glUseProgram(mProgram);
3862 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3863 ASSERT_NE(-1, tex2DLocation);
3864 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3865 ASSERT_NE(-1, texCubeLocation);
3866
3867 glUniform1i(tex2DLocation, 0);
3868 glUniform1i(texCubeLocation, 0);
3869 ASSERT_GL_NO_ERROR();
3870
3871 drawQuad(mProgram, "position", 0.5f);
3872 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3873}
3874
Vincent Lang25ab4512016-05-13 18:13:59 +02003875class Texture2DNorm16TestES3 : public Texture2DTestES3
3876{
3877 protected:
3878 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3879
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003880 void testSetUp() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003881 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003882 Texture2DTestES3::testSetUp();
Vincent Lang25ab4512016-05-13 18:13:59 +02003883
3884 glActiveTexture(GL_TEXTURE0);
3885 glGenTextures(3, mTextures);
3886 glGenFramebuffers(1, &mFBO);
3887 glGenRenderbuffers(1, &mRenderbuffer);
3888
3889 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3890 {
3891 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3892 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3893 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3894 }
3895
3896 glBindTexture(GL_TEXTURE_2D, 0);
3897
3898 ASSERT_GL_NO_ERROR();
3899 }
3900
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003901 void testTearDown() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003902 {
3903 glDeleteTextures(3, mTextures);
3904 glDeleteFramebuffers(1, &mFBO);
3905 glDeleteRenderbuffers(1, &mRenderbuffer);
3906
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003907 Texture2DTestES3::testTearDown();
Vincent Lang25ab4512016-05-13 18:13:59 +02003908 }
3909
3910 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3911 {
Geoff Langf607c602016-09-21 11:46:48 -04003912 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3913 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003914
3915 setUpProgram();
3916
3917 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3918 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3919 0);
3920
3921 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3922 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3923
3924 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003925 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003926
3927 EXPECT_GL_NO_ERROR();
3928
3929 drawQuad(mProgram, "position", 0.5f);
3930
Geoff Langf607c602016-09-21 11:46:48 -04003931 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003932
Jamie Madill50cf2be2018-06-15 09:46:57 -04003933 EXPECT_PIXEL_COLOR_EQ(0, 0,
3934 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3935 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003936
3937 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3938
3939 ASSERT_GL_NO_ERROR();
3940 }
3941
3942 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3943 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04003944 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003945 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003946
3947 setUpProgram();
3948
3949 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3950 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3951
3952 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3953 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3954 0);
3955
3956 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003957 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003958
3959 EXPECT_GL_NO_ERROR();
3960
3961 drawQuad(mProgram, "position", 0.5f);
3962
Geoff Langf607c602016-09-21 11:46:48 -04003963 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
Jamie Madill50cf2be2018-06-15 09:46:57 -04003964 EXPECT_PIXEL_COLOR_EQ(0, 0,
3965 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3966 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003967
3968 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3969 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3970 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3971 mRenderbuffer);
3972 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3973 EXPECT_GL_NO_ERROR();
3974
3975 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3976 glClear(GL_COLOR_BUFFER_BIT);
3977
3978 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3979
Geoff Langf607c602016-09-21 11:46:48 -04003980 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003981
3982 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3983
3984 ASSERT_GL_NO_ERROR();
3985 }
3986
3987 GLuint mTextures[3];
3988 GLuint mFBO;
3989 GLuint mRenderbuffer;
3990};
3991
3992// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3993TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3994{
Jamie Madillb8149072019-04-30 16:14:44 -04003995 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02003996
3997 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3998 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3999 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
4000 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
4001 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
4002 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
4003 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
4004 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
4005
4006 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
4007 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
4008 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
4009}
4010
Olli Etuaho95faa232016-06-07 14:01:53 -07004011// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
4012// GLES 3.0.4 section 3.8.3.
4013TEST_P(Texture2DTestES3, UnpackSkipImages2D)
4014{
Yuly Novikovd18c0482019-04-04 19:56:43 -04004015 // Crashes on Nexus 5X due to a driver bug. http://anglebug.com/1429
4016 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07004017
4018 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4019 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4020 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4021 ASSERT_GL_NO_ERROR();
4022
4023 // SKIP_IMAGES should not have an effect on uploading 2D textures
4024 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
4025 ASSERT_GL_NO_ERROR();
4026
4027 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
4028
4029 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4030 pixelsGreen.data());
4031 ASSERT_GL_NO_ERROR();
4032
4033 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
4034 pixelsGreen.data());
4035 ASSERT_GL_NO_ERROR();
4036
4037 glUseProgram(mProgram);
4038 drawQuad(mProgram, "position", 0.5f);
4039 ASSERT_GL_NO_ERROR();
4040
4041 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
4042}
4043
Olli Etuaho989cac32016-06-08 16:18:49 -07004044// Test that skip defined in unpack parameters is taken into account when determining whether
4045// unpacking source extends outside unpack buffer bounds.
4046TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
4047{
4048 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4049 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4050 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4051 ASSERT_GL_NO_ERROR();
4052
4053 GLBuffer buf;
4054 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
4055 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
4056 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
4057 GL_DYNAMIC_COPY);
4058 ASSERT_GL_NO_ERROR();
4059
4060 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4061 ASSERT_GL_NO_ERROR();
4062
4063 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
4064 ASSERT_GL_NO_ERROR();
4065
4066 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4067 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4068
4069 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
4070 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
4071 ASSERT_GL_NO_ERROR();
4072
4073 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4074 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4075}
4076
Olli Etuaho218cf9e2016-05-20 13:55:24 +03004077// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
4078TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
4079{
Yunchao He9550c602018-02-13 14:47:05 +08004080 ANGLE_SKIP_TEST_IF(IsD3D11());
4081
4082 // Incorrect rendering results seen on OSX AMD.
4083 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03004084
4085 const GLuint width = 8u;
4086 const GLuint height = 8u;
4087 const GLuint unpackRowLength = 5u;
4088 const GLuint unpackSkipPixels = 1u;
4089
4090 setWindowWidth(width);
4091 setWindowHeight(height);
4092
4093 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4094 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4095 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4096 ASSERT_GL_NO_ERROR();
4097
4098 GLBuffer buf;
4099 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
4100 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
4101 GLColor::green);
4102
4103 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
4104 {
4105 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
4106 }
4107
4108 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
4109 GL_DYNAMIC_COPY);
4110 ASSERT_GL_NO_ERROR();
4111
4112 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
4113 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
4114 ASSERT_GL_NO_ERROR();
4115
4116 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4117 ASSERT_GL_NO_ERROR();
4118
4119 glUseProgram(mProgram);
4120 drawQuad(mProgram, "position", 0.5f);
4121 ASSERT_GL_NO_ERROR();
4122
4123 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
4124 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
4125 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
4126 actual.data());
4127 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
4128 EXPECT_EQ(expected, actual);
4129}
4130
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004131template <typename T>
4132T UNorm(double value)
4133{
4134 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
4135}
4136
4137// Test rendering a depth texture with mipmaps.
4138TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
4139{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08004140 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
4141 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
Jiawei Shaoaf0f31d2018-09-27 15:42:31 +08004142 // http://anglebug.com/1706
4143 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Corentin Walleze731d8a2016-09-07 10:56:25 -04004144
Jamie Madill24980272019-04-03 09:03:51 -04004145 // Seems to fail on AMD D3D11. Possibly driver bug. http://anglebug.com/3342
4146 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsD3D11());
4147
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004148 const int size = getWindowWidth();
4149
4150 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04004151 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004152
4153 glActiveTexture(GL_TEXTURE0);
4154 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4155 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
4156 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4157 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4158 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
4159 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
4160 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4161 ASSERT_GL_NO_ERROR();
4162
4163 glUseProgram(mProgram);
4164 glUniform1i(mTexture2DUniformLocation, 0);
4165
4166 std::vector<unsigned char> expected;
4167
4168 for (int level = 0; level < levels; ++level)
4169 {
4170 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
4171 expected.push_back(UNorm<unsigned char>(value));
4172
4173 int levelDim = dim(level);
4174
4175 ASSERT_GT(levelDim, 0);
4176
4177 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
4178 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
4179 GL_UNSIGNED_INT, initData.data());
4180 }
4181 ASSERT_GL_NO_ERROR();
4182
4183 for (int level = 0; level < levels; ++level)
4184 {
4185 glViewport(0, 0, dim(level), dim(level));
4186 drawQuad(mProgram, "position", 0.5f);
4187 GLColor actual = ReadColor(0, 0);
4188 EXPECT_NEAR(expected[level], actual.R, 10u);
4189 }
4190
4191 ASSERT_GL_NO_ERROR();
4192}
4193
Jamie Madill7ffdda92016-09-08 13:26:51 -04004194// Tests unpacking into the unsized GL_ALPHA format.
4195TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
4196{
Jamie Madill7ffdda92016-09-08 13:26:51 -04004197 // Initialize the texure.
4198 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4199 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
4200 GL_UNSIGNED_BYTE, nullptr);
4201 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4202 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4203
4204 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
4205
4206 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04004207 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04004208 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4209 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4210 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
4211 GL_STATIC_DRAW);
4212
4213 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
4214 GL_UNSIGNED_BYTE, nullptr);
4215
4216 // Clear to a weird color to make sure we're drawing something.
4217 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
4218 glClear(GL_COLOR_BUFFER_BIT);
4219
4220 // Draw with the alpha texture and verify.
4221 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04004222
4223 ASSERT_GL_NO_ERROR();
4224 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
4225}
4226
Jamie Madill2e600342016-09-19 13:56:40 -04004227// Ensure stale unpack data doesn't propagate in D3D11.
4228TEST_P(Texture2DTestES3, StaleUnpackData)
4229{
4230 // Init unpack buffer.
4231 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
4232 std::vector<GLColor> pixels(pixelCount, GLColor::red);
4233
4234 GLBuffer unpackBuffer;
4235 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4236 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4237 GLsizei bufferSize = pixelCount * sizeof(GLColor);
4238 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
4239
4240 // Create from unpack buffer.
4241 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4242 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
4243 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4244 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4245 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4246
4247 drawQuad(mProgram, "position", 0.5f);
4248
4249 ASSERT_GL_NO_ERROR();
4250 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4251
4252 // Fill unpack with green, recreating buffer.
4253 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
4254 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
4255 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
4256
4257 // Reinit texture with green.
4258 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
4259 GL_UNSIGNED_BYTE, nullptr);
4260
4261 drawQuad(mProgram, "position", 0.5f);
4262
4263 ASSERT_GL_NO_ERROR();
4264 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
4265}
4266
Geoff Langfb7685f2017-11-13 11:44:11 -05004267// Ensure that texture parameters passed as floats that are converted to ints are rounded before
4268// validating they are less than 0.
4269TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
4270{
4271 GLTexture texture;
4272 glBindTexture(GL_TEXTURE_2D, texture);
4273
4274 // Use a negative number that will round to zero when converted to an integer
4275 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
4276 // "Validation of values performed by state-setting commands is performed after conversion,
4277 // unless specified otherwise for a specific command."
4278 GLfloat param = -7.30157126e-07f;
4279 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
4280 EXPECT_GL_NO_ERROR();
4281
4282 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
4283 EXPECT_GL_NO_ERROR();
4284}
4285
Jamie Madillf097e232016-11-05 00:44:15 -04004286// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
4287// being properly checked, and the texture storage of the previous texture format was persisting.
4288// This would result in an ASSERT in debug and incorrect rendering in release.
4289// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
4290TEST_P(Texture3DTestES3, FormatRedefinitionBug)
4291{
4292 GLTexture tex;
4293 glBindTexture(GL_TEXTURE_3D, tex.get());
4294 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4295
4296 GLFramebuffer framebuffer;
4297 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
4298 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
4299
4300 glCheckFramebufferStatus(GL_FRAMEBUFFER);
4301
4302 std::vector<uint8_t> pixelData(100, 0);
4303
4304 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
4305 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
4306 pixelData.data());
4307
4308 ASSERT_GL_NO_ERROR();
4309}
4310
Corentin Wallezd2627992017-04-28 17:17:03 -04004311// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
4312TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
4313{
4314 // 2D tests
4315 {
4316 GLTexture tex;
4317 glBindTexture(GL_TEXTURE_2D, tex.get());
4318
4319 GLBuffer pbo;
4320 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4321
4322 // Test OOB
4323 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
4324 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4325 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4326
4327 // Test OOB
4328 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
4329 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4330 ASSERT_GL_NO_ERROR();
4331 }
4332
4333 // 3D tests
4334 {
4335 GLTexture tex;
4336 glBindTexture(GL_TEXTURE_3D, tex.get());
4337
4338 GLBuffer pbo;
4339 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4340
4341 // Test OOB
4342 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
4343 GL_STATIC_DRAW);
4344 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4345 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4346
4347 // Test OOB
4348 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
4349 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4350 ASSERT_GL_NO_ERROR();
4351 }
4352}
4353
Jamie Madill3ed60422017-09-07 11:32:52 -04004354// Tests behaviour with a single texture and multiple sampler objects.
4355TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
4356{
4357 GLint maxTextureUnits = 0;
4358 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
4359 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
4360
4361 constexpr int kSize = 16;
4362
4363 // Make a single-level texture, fill it with red.
4364 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
4365 GLTexture tex;
4366 glBindTexture(GL_TEXTURE_2D, tex);
4367 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4368 redColors.data());
4369 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4370 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4371
4372 // Simple sanity check.
4373 draw2DTexturedQuad(0.5f, 1.0f, true);
4374 ASSERT_GL_NO_ERROR();
4375 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4376
4377 // Bind texture to unit 1 with a sampler object making it incomplete.
4378 GLSampler sampler;
4379 glBindSampler(0, sampler);
4380 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4381 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4382
4383 // Make a mipmap texture, fill it with blue.
4384 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
4385 GLTexture mipmapTex;
4386 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4387 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4388 blueColors.data());
4389 glGenerateMipmap(GL_TEXTURE_2D);
4390
4391 // Draw with the sampler, expect blue.
4392 draw2DTexturedQuad(0.5f, 1.0f, true);
4393 ASSERT_GL_NO_ERROR();
4394 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
4395
4396 // Simple multitexturing program.
Jamie Madill35cd7332018-12-02 12:03:33 -05004397 constexpr char kVS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004398 "#version 300 es\n"
4399 "in vec2 position;\n"
4400 "out vec2 texCoord;\n"
4401 "void main()\n"
4402 "{\n"
4403 " gl_Position = vec4(position, 0, 1);\n"
4404 " texCoord = position * 0.5 + vec2(0.5);\n"
4405 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05004406
4407 constexpr char kFS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004408 "#version 300 es\n"
4409 "precision mediump float;\n"
4410 "in vec2 texCoord;\n"
4411 "uniform sampler2D tex1;\n"
4412 "uniform sampler2D tex2;\n"
4413 "uniform sampler2D tex3;\n"
4414 "uniform sampler2D tex4;\n"
4415 "out vec4 color;\n"
4416 "void main()\n"
4417 "{\n"
4418 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
4419 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
4420 "}";
4421
Jamie Madill35cd7332018-12-02 12:03:33 -05004422 ANGLE_GL_PROGRAM(program, kVS, kFS);
Jamie Madill3ed60422017-09-07 11:32:52 -04004423
4424 std::array<GLint, 4> texLocations = {
4425 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
4426 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
4427 for (GLint location : texLocations)
4428 {
4429 ASSERT_NE(-1, location);
4430 }
4431
4432 // Init the uniform data.
4433 glUseProgram(program);
4434 for (GLint location = 0; location < 4; ++location)
4435 {
4436 glUniform1i(texLocations[location], location);
4437 }
4438
4439 // Initialize four samplers
4440 GLSampler samplers[4];
4441
4442 // 0: non-mipped.
4443 glBindSampler(0, samplers[0]);
4444 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4445 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4446
4447 // 1: mipped.
4448 glBindSampler(1, samplers[1]);
4449 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4450 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4451
4452 // 2: non-mipped.
4453 glBindSampler(2, samplers[2]);
4454 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4455 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4456
4457 // 3: mipped.
4458 glBindSampler(3, samplers[3]);
4459 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4460 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4461
4462 // Bind two blue mipped textures and two single layer textures, should all draw.
4463 glActiveTexture(GL_TEXTURE0);
4464 glBindTexture(GL_TEXTURE_2D, tex);
4465
4466 glActiveTexture(GL_TEXTURE1);
4467 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4468
4469 glActiveTexture(GL_TEXTURE2);
4470 glBindTexture(GL_TEXTURE_2D, tex);
4471
4472 glActiveTexture(GL_TEXTURE3);
4473 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4474
4475 ASSERT_GL_NO_ERROR();
4476
4477 drawQuad(program, "position", 0.5f);
4478 ASSERT_GL_NO_ERROR();
4479 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
4480
4481 // Bind four single layer textures, two should be incomplete.
4482 glActiveTexture(GL_TEXTURE1);
4483 glBindTexture(GL_TEXTURE_2D, tex);
4484
4485 glActiveTexture(GL_TEXTURE3);
4486 glBindTexture(GL_TEXTURE_2D, tex);
4487
4488 drawQuad(program, "position", 0.5f);
4489 ASSERT_GL_NO_ERROR();
4490 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
4491}
4492
Martin Radev7e2c0d32017-09-15 14:25:42 +03004493// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
4494// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
4495// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
4496// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
4497// samples the cubemap using a direction vector (1,1,1).
4498TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
4499{
Yunchao He2f23f352018-02-11 22:11:37 +08004500 // Check http://anglebug.com/2155.
4501 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
4502
Jamie Madill35cd7332018-12-02 12:03:33 -05004503 constexpr char kVS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004504 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004505 precision mediump float;
4506 in vec3 pos;
4507 void main() {
4508 gl_Position = vec4(pos, 1.0);
4509 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03004510
Jamie Madill35cd7332018-12-02 12:03:33 -05004511 constexpr char kFS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004512 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004513 precision mediump float;
4514 out vec4 color;
4515 uniform samplerCube uTex;
4516 void main(){
4517 color = texture(uTex, vec3(1.0));
4518 })";
Jamie Madill35cd7332018-12-02 12:03:33 -05004519
4520 ANGLE_GL_PROGRAM(program, kVS, kFS);
Martin Radev7e2c0d32017-09-15 14:25:42 +03004521 glUseProgram(program);
4522
4523 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
4524 glActiveTexture(GL_TEXTURE0);
4525
4526 GLTexture cubeTex;
4527 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
4528
4529 const int kFaceWidth = 1;
4530 const int kFaceHeight = 1;
4531 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
4532 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4533 GL_UNSIGNED_BYTE, texData.data());
4534 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4535 GL_UNSIGNED_BYTE, texData.data());
4536 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4537 GL_UNSIGNED_BYTE, texData.data());
4538 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4539 GL_UNSIGNED_BYTE, texData.data());
4540 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4541 GL_UNSIGNED_BYTE, texData.data());
4542 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4543 GL_UNSIGNED_BYTE, texData.data());
4544 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4545 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4546 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
4547 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
4548 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
4549 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
4550
4551 drawQuad(program, "pos", 0.5f, 1.0f, true);
4552 ASSERT_GL_NO_ERROR();
4553
4554 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4555}
4556
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08004557// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
4558TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
4559{
4560 GLuint texture = create2DTexture();
4561
4562 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
4563 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4564
4565 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
4566 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4567
4568 glDeleteTextures(1, &texture);
4569 EXPECT_GL_NO_ERROR();
4570}
4571
Olli Etuaho023371b2018-04-24 17:43:32 +03004572// Test setting base level after calling generateMipmap on a LUMA texture.
4573// Covers http://anglebug.com/2498
4574TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA)
4575{
4576 glActiveTexture(GL_TEXTURE0);
4577 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4578
4579 constexpr const GLsizei kWidth = 8;
4580 constexpr const GLsizei kHeight = 8;
4581 std::array<GLubyte, kWidth * kHeight * 2> whiteData;
4582 whiteData.fill(255u);
4583
4584 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA,
4585 GL_UNSIGNED_BYTE, whiteData.data());
4586 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
4587 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4588 glGenerateMipmap(GL_TEXTURE_2D);
4589 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
4590 EXPECT_GL_NO_ERROR();
4591
4592 drawQuad(mProgram, "position", 0.5f);
4593 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4594}
4595
Till Rathmannc1551dc2018-08-15 17:04:49 +02004596// Covers a bug in the D3D11 backend: http://anglebug.com/2772
4597// When using a sampler the texture was created as if it has mipmaps,
4598// regardless what you specified in GL_TEXTURE_MIN_FILTER via
4599// glSamplerParameteri() -- mistakenly the default value
4600// GL_NEAREST_MIPMAP_LINEAR or the value set via glTexParameteri() was
4601// evaluated.
4602// If you didn't provide mipmaps and didn't let the driver generate them
4603// this led to not sampling your texture data when minification occurred.
4604TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping)
4605{
Jamie Madill35cd7332018-12-02 12:03:33 -05004606 constexpr char kVS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004607 "#version 300 es\n"
4608 "out vec2 texcoord;\n"
4609 "in vec4 position;\n"
4610 "void main()\n"
4611 "{\n"
4612 " gl_Position = vec4(position.xy * 0.1, 0.0, 1.0);\n"
4613 " texcoord = (position.xy * 0.5) + 0.5;\n"
4614 "}\n";
4615
Jamie Madill35cd7332018-12-02 12:03:33 -05004616 constexpr char kFS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004617 "#version 300 es\n"
4618 "precision highp float;\n"
4619 "uniform highp sampler2D tex;\n"
4620 "in vec2 texcoord;\n"
4621 "out vec4 fragColor;\n"
4622 "void main()\n"
4623 "{\n"
4624 " fragColor = texture(tex, texcoord);\n"
4625 "}\n";
Jamie Madill35cd7332018-12-02 12:03:33 -05004626
4627 ANGLE_GL_PROGRAM(program, kVS, kFS);
Till Rathmannc1551dc2018-08-15 17:04:49 +02004628
4629 GLSampler sampler;
4630 glBindSampler(0, sampler);
4631 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4632 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4633
4634 glActiveTexture(GL_TEXTURE0);
4635 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4636
4637 const GLsizei texWidth = getWindowWidth();
4638 const GLsizei texHeight = getWindowHeight();
4639 const std::vector<GLColor> whiteData(texWidth * texHeight, GLColor::white);
4640
4641 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4642 whiteData.data());
4643 EXPECT_GL_NO_ERROR();
4644
4645 drawQuad(program, "position", 0.5f);
4646 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, angle::GLColor::white);
4647}
4648
Anders Leinof6cbe442019-04-18 15:32:07 +03004649// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4650// texture is output.
4651TEST_P(Texture2DIntegerTestES3, IntegerTextureNonZeroBaseLevel)
4652{
Yuly Novikovd2683452019-05-23 16:11:19 -04004653 // http://anglebug.com/3478
4654 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsDesktopOpenGL());
4655
Anders Leinof6cbe442019-04-18 15:32:07 +03004656 glActiveTexture(GL_TEXTURE0);
4657 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4658 int width = getWindowWidth();
4659 int height = getWindowHeight();
4660 GLColor color = GLColor::green;
4661 std::vector<GLColor> pixels(width * height, color);
4662 GLint baseLevel = 1;
4663 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
4664 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4665 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4666 glTexImage2D(GL_TEXTURE_2D, baseLevel, GL_RGBA8UI, width, height, 0, GL_RGBA_INTEGER,
4667 GL_UNSIGNED_BYTE, pixels.data());
4668
4669 setUpProgram();
4670 glUseProgram(mProgram);
4671 glUniform1i(mTexture2DUniformLocation, 0);
4672 drawQuad(mProgram, "position", 0.5f);
4673
4674 EXPECT_GL_NO_ERROR();
4675 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4676 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4677}
4678
Anders Leino60cc7512019-05-06 09:25:27 +03004679// Draw a quad with an integer cube texture with a non-zero base level, and test that the color of
4680// the texture is output.
4681TEST_P(TextureCubeIntegerTestES3, IntegerCubeTextureNonZeroBaseLevel)
4682{
4683 // All output checks returned black, rather than the texture color.
4684 ANGLE_SKIP_TEST_IF(IsOSX() && IsOpenGL());
4685
4686 glActiveTexture(GL_TEXTURE0);
4687
4688 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
4689 GLint baseLevel = 1;
4690 int width = getWindowWidth();
4691 int height = getWindowHeight();
4692 GLColor color = GLColor::green;
4693 std::vector<GLColor> pixels(width * height, color);
4694 for (GLenum faceIndex = 0; faceIndex < 6; faceIndex++)
4695 {
4696 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, baseLevel, GL_RGBA8UI, width,
4697 height, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
4698 EXPECT_GL_NO_ERROR();
4699 }
4700 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, baseLevel);
4701 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4702 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4703
4704 glUseProgram(mProgram);
4705 glUniform1i(mTextureCubeUniformLocation, 0);
4706 drawQuad(mProgram, "position", 0.5f);
4707
4708 EXPECT_GL_NO_ERROR();
4709 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4710 EXPECT_PIXEL_COLOR_EQ(width - 1, 0, color);
4711 EXPECT_PIXEL_COLOR_EQ(0, height - 1, color);
4712 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4713}
4714
Anders Leinoe4452442019-05-09 13:29:49 +03004715// This test sets up a cube map with four distincly colored MIP levels.
4716// The size of the texture and the geometry is chosen such that levels 1 or 2 should be chosen at
4717// the corners of the screen.
4718TEST_P(TextureCubeIntegerEdgeTestES3, IntegerCubeTextureCorner)
4719{
4720 glActiveTexture(GL_TEXTURE0);
4721
4722 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
4723 int width = getWindowWidth();
4724 int height = getWindowHeight();
4725 ASSERT_EQ(width, height);
4726 GLColor color[4] = {GLColor::white, GLColor::green, GLColor::blue, GLColor::red};
4727 for (GLint level = 0; level < 4; level++)
4728 {
4729 for (GLenum faceIndex = 0; faceIndex < 6; faceIndex++)
4730 {
4731 int levelWidth = (2 * width) >> level;
4732 int levelHeight = (2 * height) >> level;
4733 std::vector<GLColor> pixels(levelWidth * levelHeight, color[level]);
4734 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, level, GL_RGBA8UI, levelWidth,
4735 levelHeight, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
4736 EXPECT_GL_NO_ERROR();
4737 }
4738 }
4739 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4740 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4741 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 3);
4742
4743 glUseProgram(mProgram);
4744 glUniform1i(mTextureCubeUniformLocation, 0);
4745 drawQuad(mProgram, "position", 0.5f);
4746
4747 ASSERT_GL_NO_ERROR();
4748 // Check that we do not read from levels 0 or 3. Levels 1 and 2 are both acceptable.
4749 EXPECT_EQ(ReadColor(0, 0).R, 0);
4750 EXPECT_EQ(ReadColor(width - 1, 0).R, 0);
4751 EXPECT_EQ(ReadColor(0, height - 1).R, 0);
4752 EXPECT_EQ(ReadColor(width - 1, height - 1).R, 0);
4753}
4754
Anders Leino1b6aded2019-05-20 12:56:34 +03004755// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4756// texture is output.
4757TEST_P(Texture2DIntegerProjectiveOffsetTestES3, NonZeroBaseLevel)
4758{
Jamie Madill29ac2742019-05-28 15:53:00 -04004759 // Fails on AMD: http://crbug.com/967796
Jamie Madill06055b52019-05-29 14:31:42 -04004760 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsOpenGL());
Jamie Madill29ac2742019-05-28 15:53:00 -04004761
Anders Leino1b6aded2019-05-20 12:56:34 +03004762 glActiveTexture(GL_TEXTURE0);
4763 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4764 int width = getWindowWidth();
4765 int height = getWindowHeight();
4766 GLColor color = GLColor::green;
4767 std::vector<GLColor> pixels(width * height, color);
4768 GLint baseLevel = 1;
4769 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
4770 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4771 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4772 glTexImage2D(GL_TEXTURE_2D, baseLevel, GL_RGBA8UI, width, height, 0, GL_RGBA_INTEGER,
4773 GL_UNSIGNED_BYTE, pixels.data());
4774
4775 setUpProgram();
4776 glUseProgram(mProgram);
4777 glUniform1i(mTexture2DUniformLocation, 0);
4778 drawQuad(mProgram, "position", 0.5f);
4779
4780 EXPECT_GL_NO_ERROR();
4781 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4782 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4783}
4784
Anders Leino69d04932019-05-20 14:04:13 +03004785// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4786// texture is output.
4787TEST_P(Texture2DArrayIntegerTestES3, NonZeroBaseLevel)
4788{
4789 glActiveTexture(GL_TEXTURE0);
4790 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
4791 int width = getWindowWidth();
4792 int height = getWindowHeight();
4793 int depth = 2;
4794 GLColor color = GLColor::green;
4795 std::vector<GLColor> pixels(width * height * depth, color);
4796 GLint baseLevel = 1;
4797 glTexImage3D(GL_TEXTURE_2D_ARRAY, baseLevel, GL_RGBA8UI, width, height, depth, 0,
4798 GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
4799 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, baseLevel);
4800 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4801 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4802
4803 drawQuad(mProgram, "position", 0.5f);
4804
4805 EXPECT_GL_NO_ERROR();
4806 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4807 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4808}
4809
Anders Leino262e2822019-05-20 14:24:40 +03004810// Draw a quad with an integer 3D texture with a non-zero base level, and test that the color of the
4811// texture is output.
4812TEST_P(Texture3DIntegerTestES3, NonZeroBaseLevel)
4813{
4814 glActiveTexture(GL_TEXTURE0);
4815 glBindTexture(GL_TEXTURE_3D, mTexture3D);
4816 int width = getWindowWidth();
4817 int height = getWindowHeight();
4818 int depth = 2;
4819 GLColor color = GLColor::green;
4820 std::vector<GLColor> pixels(width * height * depth, color);
4821 GLint baseLevel = 1;
4822 glTexImage3D(GL_TEXTURE_3D, baseLevel, GL_RGBA8UI, width, height, depth, 0, GL_RGBA_INTEGER,
4823 GL_UNSIGNED_BYTE, pixels.data());
4824 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, baseLevel);
4825 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4826 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4827
4828 drawQuad(mProgram, "position", 0.5f);
4829
4830 EXPECT_GL_NO_ERROR();
4831 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4832 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4833}
4834
Jamie Madill50cf2be2018-06-15 09:46:57 -04004835// Use this to select which configurations (e.g. which renderer, which GLES major version) these
4836// tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -05004837ANGLE_INSTANTIATE_TEST(Texture2DTest,
4838 ES2_D3D9(),
4839 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004840 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05004841 ES2_OPENGLES(),
4842 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004843ANGLE_INSTANTIATE_TEST(TextureCubeTest,
4844 ES2_D3D9(),
4845 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004846 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004847 ES2_OPENGLES(),
4848 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004849ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
4850 ES2_D3D9(),
4851 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004852 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004853 ES2_OPENGLES(),
4854 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004855ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
4856 ES2_D3D9(),
4857 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004858 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004859 ES2_OPENGLES(),
4860 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004861ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
4862 ES2_D3D9(),
4863 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004864 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004865 ES2_OPENGLES(),
4866 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004867ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
4868 ES2_D3D9(),
4869 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004870 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004871 ES2_OPENGLES(),
4872 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004873ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02004874ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02004875ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4876ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
4877 ES3_D3D11(),
4878 ES3_OPENGL(),
4879 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004880ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
4881 ES3_D3D11(),
4882 ES3_OPENGL(),
4883 ES3_OPENGLES());
4884ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4885ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02004886ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02004887ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
4888 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004889 ES2_D3D9(),
4890 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004891 ES2_OPENGLES(),
4892 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004893ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
4894 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004895 ES2_D3D9(),
4896 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004897 ES2_OPENGLES(),
4898 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004899ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
4900 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004901 ES2_D3D9(),
4902 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004903 ES2_OPENGLES(),
4904 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004905ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
4906 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004907 ES2_D3D9(),
4908 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004909 ES2_OPENGLES(),
4910 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004911ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
4912 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02004913 ES2_D3D9(),
4914 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004915 ES2_OPENGLES(),
4916 ES2_VULKAN());
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05004917ANGLE_INSTANTIATE_TEST(TextureAnisotropyTest,
4918 ES2_D3D11(),
4919 ES2_D3D9(),
4920 ES2_OPENGL(),
4921 ES2_OPENGLES(),
4922 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02004923ANGLE_INSTANTIATE_TEST(TextureBorderClampTest,
4924 ES2_D3D11(),
4925 ES2_D3D9(),
4926 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004927 ES2_OPENGLES(),
4928 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02004929ANGLE_INSTANTIATE_TEST(TextureBorderClampTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4930ANGLE_INSTANTIATE_TEST(TextureBorderClampIntegerTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Luc Ferronaf883622018-06-08 15:57:31 -04004931ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN());
Vincent Lang25ab4512016-05-13 18:13:59 +02004932ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03004933ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Anders Leinof6cbe442019-04-18 15:32:07 +03004934ANGLE_INSTANTIATE_TEST(Texture2DIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino60cc7512019-05-06 09:25:27 +03004935ANGLE_INSTANTIATE_TEST(TextureCubeIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leinoe4452442019-05-09 13:29:49 +03004936ANGLE_INSTANTIATE_TEST(TextureCubeIntegerEdgeTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino1b6aded2019-05-20 12:56:34 +03004937ANGLE_INSTANTIATE_TEST(Texture2DIntegerProjectiveOffsetTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino69d04932019-05-20 14:04:13 +03004938ANGLE_INSTANTIATE_TEST(Texture2DArrayIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino262e2822019-05-20 14:24:40 +03004939ANGLE_INSTANTIATE_TEST(Texture3DIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Jamie Madillfa05f602015-05-07 13:47:11 -04004940
Jamie Madill7ffdda92016-09-08 13:26:51 -04004941} // anonymous namespace