blob: 1e3f80d862f470139771057d1972884a106a4e93 [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
Mohan Maiya8f1169e2019-06-27 15:32:32 -070016constexpr unsigned int kPixelTolerance = 1u;
17
Vincent Lang25ab4512016-05-13 18:13:59 +020018// Take a pixel, and reset the components not covered by the format to default
Geoff Langf607c602016-09-21 11:46:48 -040019// values. In particular, the default value for the alpha component is 255
Vincent Lang25ab4512016-05-13 18:13:59 +020020// (1.0 as unsigned normalized fixed point value).
Geoff Langf607c602016-09-21 11:46:48 -040021GLColor SliceFormatColor(GLenum format, GLColor full)
Vincent Lang25ab4512016-05-13 18:13:59 +020022{
23 switch (format)
24 {
25 case GL_RED:
Geoff Langf607c602016-09-21 11:46:48 -040026 return GLColor(full.R, 0, 0, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020027 case GL_RG:
Geoff Langf607c602016-09-21 11:46:48 -040028 return GLColor(full.R, full.G, 0, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020029 case GL_RGB:
Geoff Langf607c602016-09-21 11:46:48 -040030 return GLColor(full.R, full.G, full.B, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020031 case GL_RGBA:
32 return full;
33 default:
Jamie Madille1faacb2016-12-13 12:42:14 -050034 EXPECT_TRUE(false);
Geoff Langf607c602016-09-21 11:46:48 -040035 return GLColor::white;
Vincent Lang25ab4512016-05-13 18:13:59 +020036 }
Vincent Lang25ab4512016-05-13 18:13:59 +020037}
38
Olli Etuaho4a8329f2016-01-11 17:12:57 +020039class TexCoordDrawTest : public ANGLETest
Jamie Madillf67115c2014-04-22 13:14:05 -040040{
Jamie Madillbc393df2015-01-29 13:46:07 -050041 protected:
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020042 TexCoordDrawTest() : ANGLETest(), mProgram(0), mFramebuffer(0), mFramebufferColorTexture(0)
Jamie Madillf67115c2014-04-22 13:14:05 -040043 {
44 setWindowWidth(128);
45 setWindowHeight(128);
46 setConfigRedBits(8);
47 setConfigGreenBits(8);
48 setConfigBlueBits(8);
49 setConfigAlphaBits(8);
50 }
51
Jamie Madill35cd7332018-12-02 12:03:33 -050052 virtual const char *getVertexShaderSource()
Jamie Madillf67115c2014-04-22 13:14:05 -040053 {
Jamie Madill35cd7332018-12-02 12:03:33 -050054 return R"(precision highp float;
55attribute vec4 position;
56varying vec2 texcoord;
Geoff Langc41e42d2014-04-28 10:58:16 -040057
Jamie Madill35cd7332018-12-02 12:03:33 -050058void main()
59{
60 gl_Position = vec4(position.xy, 0.0, 1.0);
61 texcoord = (position.xy * 0.5) + 0.5;
62})";
Olli Etuaho4a8329f2016-01-11 17:12:57 +020063 }
Geoff Langc41e42d2014-04-28 10:58:16 -040064
Jamie Madill35cd7332018-12-02 12:03:33 -050065 virtual const char *getFragmentShaderSource() = 0;
Olli Etuaho4a8329f2016-01-11 17:12:57 +020066
Olli Etuahoa1c917f2016-04-06 13:50:03 +030067 virtual void setUpProgram()
Olli Etuaho4a8329f2016-01-11 17:12:57 +020068 {
Jamie Madill35cd7332018-12-02 12:03:33 -050069 const char *vertexShaderSource = getVertexShaderSource();
70 const char *fragmentShaderSource = getFragmentShaderSource();
Olli Etuaho4a8329f2016-01-11 17:12:57 +020071
72 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
73 ASSERT_NE(0u, mProgram);
74 ASSERT_GL_NO_ERROR();
Olli Etuahoa1c917f2016-04-06 13:50:03 +030075 }
76
Jamie Madill5cbaa3f2019-05-07 15:49:22 -040077 void testSetUp() override { setUpFramebuffer(); }
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020078
Jamie Madill5cbaa3f2019-05-07 15:49:22 -040079 void testTearDown() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +020080 {
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020081 glBindFramebuffer(GL_FRAMEBUFFER, 0);
82 glDeleteFramebuffers(1, &mFramebuffer);
83 glDeleteTextures(1, &mFramebufferColorTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +020084 glDeleteProgram(mProgram);
Olli Etuaho4a8329f2016-01-11 17:12:57 +020085 }
86
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020087 void setUpFramebuffer()
88 {
89 // We use an FBO to work around an issue where the default framebuffer applies SRGB
90 // conversion (particularly known to happen incorrectly on Intel GL drivers). It's not
91 // clear whether this issue can even be fixed on all backends. For example GLES 3.0.4 spec
92 // section 4.4 says that the format of the default framebuffer is entirely up to the window
93 // system, so it might be SRGB, and GLES 3.0 doesn't have a "FRAMEBUFFER_SRGB" to turn off
94 // SRGB conversion like desktop GL does.
95 // TODO(oetuaho): Get rid of this if the underlying issue is fixed.
96 glGenFramebuffers(1, &mFramebuffer);
97 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
98
99 glGenTextures(1, &mFramebufferColorTexture);
100 glBindTexture(GL_TEXTURE_2D, mFramebufferColorTexture);
101 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
102 GL_UNSIGNED_BYTE, nullptr);
103 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
104 mFramebufferColorTexture, 0);
105 ASSERT_GL_NO_ERROR();
106 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
107 glBindTexture(GL_TEXTURE_2D, 0);
108 }
109
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200110 // Returns the created texture ID.
111 GLuint create2DTexture()
112 {
113 GLuint texture2D;
114 glGenTextures(1, &texture2D);
115 glBindTexture(GL_TEXTURE_2D, texture2D);
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800116 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200117 EXPECT_GL_NO_ERROR();
118 return texture2D;
119 }
120
121 GLuint mProgram;
Olli Etuaho51f1c0f2016-01-13 16:16:24 +0200122 GLuint mFramebuffer;
123
124 private:
125 GLuint mFramebufferColorTexture;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200126};
127
128class Texture2DTest : public TexCoordDrawTest
129{
130 protected:
131 Texture2DTest() : TexCoordDrawTest(), mTexture2D(0), mTexture2DUniformLocation(-1) {}
132
Jamie Madill35cd7332018-12-02 12:03:33 -0500133 const char *getFragmentShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200134 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500135 return R"(precision highp float;
136uniform sampler2D tex;
137varying vec2 texcoord;
Geoff Langc41e42d2014-04-28 10:58:16 -0400138
Jamie Madill35cd7332018-12-02 12:03:33 -0500139void main()
140{
141 gl_FragColor = texture2D(tex, texcoord);
142})";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200143 }
Geoff Langc41e42d2014-04-28 10:58:16 -0400144
Olli Etuaho96963162016-03-21 11:54:33 +0200145 virtual const char *getTextureUniformName() { return "tex"; }
146
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300147 void setUpProgram() override
148 {
149 TexCoordDrawTest::setUpProgram();
150 mTexture2DUniformLocation = glGetUniformLocation(mProgram, getTextureUniformName());
151 ASSERT_NE(-1, mTexture2DUniformLocation);
152 }
153
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400154 void testSetUp() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200155 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400156 TexCoordDrawTest::testSetUp();
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200157 mTexture2D = create2DTexture();
Jamie Madilld4cfa572014-07-08 10:00:32 -0400158
Jamie Madill9aca0592014-10-06 16:26:59 -0400159 ASSERT_GL_NO_ERROR();
Jamie Madillf67115c2014-04-22 13:14:05 -0400160 }
161
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400162 void testTearDown() override
Jamie Madillf67115c2014-04-22 13:14:05 -0400163 {
Jamie Madilld4cfa572014-07-08 10:00:32 -0400164 glDeleteTextures(1, &mTexture2D);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400165 TexCoordDrawTest::testTearDown();
Jamie Madillf67115c2014-04-22 13:14:05 -0400166 }
167
Jamie Madillbc393df2015-01-29 13:46:07 -0500168 // Tests CopyTexSubImage with floating point textures of various formats.
169 void testFloatCopySubImage(int sourceImageChannels, int destImageChannels)
170 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300171 setUpProgram();
172
Martin Radev1be913c2016-07-11 17:59:16 +0300173 if (getClientMajorVersion() < 3)
Geoff Langfbfa47c2015-03-31 11:26:00 -0400174 {
Jamie Madillb8149072019-04-30 16:14:44 -0400175 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_storage") ||
176 !IsGLExtensionEnabled("GL_OES_texture_float"));
Geoff Langc4e93662017-05-01 10:45:59 -0400177
Yunchao He9550c602018-02-13 14:47:05 +0800178 ANGLE_SKIP_TEST_IF((sourceImageChannels < 3 || destImageChannels < 3) &&
Jamie Madillb8149072019-04-30 16:14:44 -0400179 !IsGLExtensionEnabled("GL_EXT_texture_rg"));
Geoff Langfbfa47c2015-03-31 11:26:00 -0400180
Yunchao He9550c602018-02-13 14:47:05 +0800181 ANGLE_SKIP_TEST_IF(destImageChannels == 3 &&
Jamie Madillb8149072019-04-30 16:14:44 -0400182 !IsGLExtensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400183
Yunchao He9550c602018-02-13 14:47:05 +0800184 ANGLE_SKIP_TEST_IF(destImageChannels == 4 &&
Jamie Madillb8149072019-04-30 16:14:44 -0400185 !IsGLExtensionEnabled("GL_CHROMIUM_color_buffer_float_rgba"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400186
Yunchao He9550c602018-02-13 14:47:05 +0800187 ANGLE_SKIP_TEST_IF(destImageChannels <= 2);
Geoff Lang677bb6f2017-04-05 12:40:40 -0400188 }
189 else
190 {
Jamie Madillb8149072019-04-30 16:14:44 -0400191 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_color_buffer_float"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400192
Yunchao He9550c602018-02-13 14:47:05 +0800193 ANGLE_SKIP_TEST_IF(destImageChannels == 3 &&
Jamie Madillb8149072019-04-30 16:14:44 -0400194 !IsGLExtensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"));
Geoff Langfbfa47c2015-03-31 11:26:00 -0400195 }
196
Jamie Madill50cf2be2018-06-15 09:46:57 -0400197 // clang-format off
Jamie Madillbc393df2015-01-29 13:46:07 -0500198 GLfloat sourceImageData[4][16] =
199 {
200 { // R
201 1.0f,
202 0.0f,
203 0.0f,
204 1.0f
205 },
206 { // RG
207 1.0f, 0.0f,
208 0.0f, 1.0f,
209 0.0f, 0.0f,
210 1.0f, 1.0f
211 },
212 { // RGB
213 1.0f, 0.0f, 0.0f,
214 0.0f, 1.0f, 0.0f,
215 0.0f, 0.0f, 1.0f,
216 1.0f, 1.0f, 0.0f
217 },
218 { // RGBA
219 1.0f, 0.0f, 0.0f, 1.0f,
220 0.0f, 1.0f, 0.0f, 1.0f,
221 0.0f, 0.0f, 1.0f, 1.0f,
222 1.0f, 1.0f, 0.0f, 1.0f
223 },
224 };
Jamie Madill50cf2be2018-06-15 09:46:57 -0400225 // clang-format on
Jamie Madillbc393df2015-01-29 13:46:07 -0500226
Jamie Madill50cf2be2018-06-15 09:46:57 -0400227 GLenum imageFormats[] = {
Jamie Madillb980c562018-11-27 11:34:27 -0500228 GL_R32F,
229 GL_RG32F,
230 GL_RGB32F,
231 GL_RGBA32F,
Jamie Madillbc393df2015-01-29 13:46:07 -0500232 };
233
Jamie Madill50cf2be2018-06-15 09:46:57 -0400234 GLenum sourceUnsizedFormats[] = {
Jamie Madillb980c562018-11-27 11:34:27 -0500235 GL_RED,
236 GL_RG,
237 GL_RGB,
238 GL_RGBA,
Jamie Madillbc393df2015-01-29 13:46:07 -0500239 };
240
241 GLuint textures[2];
242
243 glGenTextures(2, textures);
244
Jamie Madill50cf2be2018-06-15 09:46:57 -0400245 GLfloat *imageData = sourceImageData[sourceImageChannels - 1];
246 GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1];
Jamie Madillbc393df2015-01-29 13:46:07 -0500247 GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1];
Jamie Madill50cf2be2018-06-15 09:46:57 -0400248 GLenum destImageFormat = imageFormats[destImageChannels - 1];
Jamie Madillbc393df2015-01-29 13:46:07 -0500249
250 glBindTexture(GL_TEXTURE_2D, textures[0]);
Geoff Langc4e93662017-05-01 10:45:59 -0400251 if (getClientMajorVersion() >= 3)
252 {
253 glTexStorage2D(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
254 }
255 else
256 {
257 glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
258 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500259 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
260 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
261 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData);
262
Jamie Madillb8149072019-04-30 16:14:44 -0400263 if (sourceImageChannels < 3 && !IsGLExtensionEnabled("GL_EXT_texture_rg"))
Jamie Madillbc393df2015-01-29 13:46:07 -0500264 {
265 // This is not supported
266 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
267 }
268 else
269 {
270 ASSERT_GL_NO_ERROR();
271 }
272
273 GLuint fbo;
274 glGenFramebuffers(1, &fbo);
275 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
276 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
277
278 glBindTexture(GL_TEXTURE_2D, textures[1]);
Geoff Langc4e93662017-05-01 10:45:59 -0400279 if (getClientMajorVersion() >= 3)
280 {
281 glTexStorage2D(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
282 }
283 else
284 {
285 glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
286 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500287 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
288 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
289
290 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
291 ASSERT_GL_NO_ERROR();
292
293 glBindFramebuffer(GL_FRAMEBUFFER, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200294 drawQuad(mProgram, "position", 0.5f);
Jamie Madillbc393df2015-01-29 13:46:07 -0500295
296 int testImageChannels = std::min(sourceImageChannels, destImageChannels);
297
Olli Etuahoa314b612016-03-10 16:43:00 +0200298 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Jamie Madillbc393df2015-01-29 13:46:07 -0500299 if (testImageChannels > 1)
300 {
301 EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255);
302 EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255);
303 if (testImageChannels > 2)
304 {
305 EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255);
306 }
307 }
308
309 glDeleteFramebuffers(1, &fbo);
310 glDeleteTextures(2, textures);
311
312 ASSERT_GL_NO_ERROR();
313 }
314
Jamie Madilld4cfa572014-07-08 10:00:32 -0400315 GLuint mTexture2D;
Jamie Madilld4cfa572014-07-08 10:00:32 -0400316 GLint mTexture2DUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400317};
318
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200319class Texture2DTestES3 : public Texture2DTest
320{
321 protected:
322 Texture2DTestES3() : Texture2DTest() {}
323
Jamie Madill35cd7332018-12-02 12:03:33 -0500324 const char *getVertexShaderSource() override
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200325 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500326 return "#version 300 es\n"
327 "out vec2 texcoord;\n"
328 "in vec4 position;\n"
329 "void main()\n"
330 "{\n"
331 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
332 " texcoord = (position.xy * 0.5) + 0.5;\n"
333 "}\n";
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200334 }
335
Jamie Madill35cd7332018-12-02 12:03:33 -0500336 const char *getFragmentShaderSource() override
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200337 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500338 return "#version 300 es\n"
339 "precision highp float;\n"
340 "uniform highp sampler2D tex;\n"
341 "in vec2 texcoord;\n"
342 "out vec4 fragColor;\n"
343 "void main()\n"
344 "{\n"
345 " fragColor = texture(tex, texcoord);\n"
346 "}\n";
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200347 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300348
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400349 void testSetUp() override
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300350 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400351 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300352 setUpProgram();
353 }
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200354};
355
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200356class Texture2DIntegerAlpha1TestES3 : public Texture2DTest
357{
358 protected:
359 Texture2DIntegerAlpha1TestES3() : Texture2DTest() {}
360
Jamie Madill35cd7332018-12-02 12:03:33 -0500361 const char *getVertexShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200362 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500363 return "#version 300 es\n"
364 "out vec2 texcoord;\n"
365 "in vec4 position;\n"
366 "void main()\n"
367 "{\n"
368 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
369 " texcoord = (position.xy * 0.5) + 0.5;\n"
370 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200371 }
372
Jamie Madill35cd7332018-12-02 12:03:33 -0500373 const char *getFragmentShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200374 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500375 return "#version 300 es\n"
376 "precision highp float;\n"
377 "uniform highp isampler2D tex;\n"
378 "in vec2 texcoord;\n"
379 "out vec4 fragColor;\n"
380 "void main()\n"
381 "{\n"
382 " vec4 green = vec4(0, 1, 0, 1);\n"
383 " vec4 black = vec4(0, 0, 0, 0);\n"
384 " fragColor = (texture(tex, texcoord).a == 1) ? green : black;\n"
385 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200386 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300387
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400388 void testSetUp() override
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300389 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400390 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300391 setUpProgram();
392 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200393};
394
395class Texture2DUnsignedIntegerAlpha1TestES3 : public Texture2DTest
396{
397 protected:
398 Texture2DUnsignedIntegerAlpha1TestES3() : Texture2DTest() {}
399
Jamie Madill35cd7332018-12-02 12:03:33 -0500400 const char *getVertexShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200401 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500402 return "#version 300 es\n"
403 "out vec2 texcoord;\n"
404 "in vec4 position;\n"
405 "void main()\n"
406 "{\n"
407 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
408 " texcoord = (position.xy * 0.5) + 0.5;\n"
409 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200410 }
411
Jamie Madill35cd7332018-12-02 12:03:33 -0500412 const char *getFragmentShaderSource() override
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200413 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500414 return "#version 300 es\n"
415 "precision highp float;\n"
416 "uniform highp usampler2D tex;\n"
417 "in vec2 texcoord;\n"
418 "out vec4 fragColor;\n"
419 "void main()\n"
420 "{\n"
421 " vec4 green = vec4(0, 1, 0, 1);\n"
422 " vec4 black = vec4(0, 0, 0, 0);\n"
423 " fragColor = (texture(tex, texcoord).a == 1u) ? green : black;\n"
424 "}\n";
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200425 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300426
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400427 void testSetUp() override
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300428 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400429 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300430 setUpProgram();
431 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200432};
433
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200434class Texture2DTestWithDrawScale : public Texture2DTest
Jamie Madill2453dbc2015-07-14 11:35:42 -0400435{
436 protected:
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200437 Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {}
438
Jamie Madill35cd7332018-12-02 12:03:33 -0500439 const char *getVertexShaderSource() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400440 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300441 return
442 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200443 attribute vec4 position;
444 varying vec2 texcoord;
445
446 uniform vec2 drawScale;
447
448 void main()
449 {
450 gl_Position = vec4(position.xy * drawScale, 0.0, 1.0);
451 texcoord = (position.xy * 0.5) + 0.5;
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300452 })";
Jamie Madill2453dbc2015-07-14 11:35:42 -0400453 }
454
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400455 void testSetUp() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400456 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400457 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300458
459 setUpProgram();
460
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200461 mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale");
462 ASSERT_NE(-1, mDrawScaleUniformLocation);
Jamie Madill2453dbc2015-07-14 11:35:42 -0400463
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200464 glUseProgram(mProgram);
465 glUniform2f(mDrawScaleUniformLocation, 1.0f, 1.0f);
466 glUseProgram(0);
467 ASSERT_GL_NO_ERROR();
468 }
469
470 GLint mDrawScaleUniformLocation;
471};
472
Olli Etuaho4644a202016-01-12 15:12:53 +0200473class Sampler2DAsFunctionParameterTest : public Texture2DTest
474{
475 protected:
476 Sampler2DAsFunctionParameterTest() : Texture2DTest() {}
477
Jamie Madill35cd7332018-12-02 12:03:33 -0500478 const char *getFragmentShaderSource() override
Olli Etuaho4644a202016-01-12 15:12:53 +0200479 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300480 return
481 R"(precision highp float;
Olli Etuaho4644a202016-01-12 15:12:53 +0200482 uniform sampler2D tex;
483 varying vec2 texcoord;
484
485 vec4 computeFragColor(sampler2D aTex)
486 {
487 return texture2D(aTex, texcoord);
488 }
489
490 void main()
491 {
492 gl_FragColor = computeFragColor(tex);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300493 })";
Olli Etuaho4644a202016-01-12 15:12:53 +0200494 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300495
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400496 void testSetUp() override
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300497 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400498 Texture2DTest::testSetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300499 setUpProgram();
500 }
Olli Etuaho4644a202016-01-12 15:12:53 +0200501};
502
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200503class TextureCubeTest : public TexCoordDrawTest
504{
505 protected:
506 TextureCubeTest()
507 : TexCoordDrawTest(),
508 mTexture2D(0),
509 mTextureCube(0),
510 mTexture2DUniformLocation(-1),
511 mTextureCubeUniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500512 {}
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200513
Jamie Madill35cd7332018-12-02 12:03:33 -0500514 const char *getFragmentShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200515 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300516 return
517 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200518 uniform sampler2D tex2D;
519 uniform samplerCube texCube;
520 varying vec2 texcoord;
521
522 void main()
523 {
524 gl_FragColor = texture2D(tex2D, texcoord);
525 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300526 })";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200527 }
528
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400529 void testSetUp() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200530 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400531 TexCoordDrawTest::testSetUp();
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200532
533 glGenTextures(1, &mTextureCube);
534 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Geoff Langc4e93662017-05-01 10:45:59 -0400535 for (GLenum face = 0; face < 6; face++)
536 {
537 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
538 GL_UNSIGNED_BYTE, nullptr);
539 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200540 EXPECT_GL_NO_ERROR();
541
542 mTexture2D = create2DTexture();
543
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300544 setUpProgram();
545
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200546 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
547 ASSERT_NE(-1, mTexture2DUniformLocation);
548 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
549 ASSERT_NE(-1, mTextureCubeUniformLocation);
550 }
551
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400552 void testTearDown() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200553 {
554 glDeleteTextures(1, &mTextureCube);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400555 TexCoordDrawTest::testTearDown();
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200556 }
557
558 GLuint mTexture2D;
559 GLuint mTextureCube;
560 GLint mTexture2DUniformLocation;
561 GLint mTextureCubeUniformLocation;
562};
563
Martin Radev7e2c0d32017-09-15 14:25:42 +0300564class TextureCubeTestES3 : public ANGLETest
565{
566 protected:
567 TextureCubeTestES3() {}
568};
569
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200570class SamplerArrayTest : public TexCoordDrawTest
571{
572 protected:
573 SamplerArrayTest()
574 : TexCoordDrawTest(),
575 mTexture2DA(0),
576 mTexture2DB(0),
577 mTexture0UniformLocation(-1),
578 mTexture1UniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500579 {}
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200580
Jamie Madill35cd7332018-12-02 12:03:33 -0500581 const char *getFragmentShaderSource() override
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200582 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300583 return
584 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200585 uniform highp sampler2D tex2DArray[2];
586 varying vec2 texcoord;
587 void main()
588 {
589 gl_FragColor = texture2D(tex2DArray[0], texcoord);
590 gl_FragColor += texture2D(tex2DArray[1], texcoord);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300591 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200592 }
593
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400594 void testSetUp() override
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200595 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400596 TexCoordDrawTest::testSetUp();
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200597
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300598 setUpProgram();
599
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200600 mTexture0UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[0]");
601 ASSERT_NE(-1, mTexture0UniformLocation);
602 mTexture1UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[1]");
603 ASSERT_NE(-1, mTexture1UniformLocation);
604
605 mTexture2DA = create2DTexture();
606 mTexture2DB = create2DTexture();
607 ASSERT_GL_NO_ERROR();
608 }
609
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400610 void testTearDown() override
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200611 {
612 glDeleteTextures(1, &mTexture2DA);
613 glDeleteTextures(1, &mTexture2DB);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400614 TexCoordDrawTest::testTearDown();
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200615 }
616
617 void testSamplerArrayDraw()
618 {
619 GLubyte texData[4];
620 texData[0] = 0;
621 texData[1] = 60;
622 texData[2] = 0;
623 texData[3] = 255;
624
625 glActiveTexture(GL_TEXTURE0);
626 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
627 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
628
629 texData[1] = 120;
630 glActiveTexture(GL_TEXTURE1);
631 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
632 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
633 EXPECT_GL_ERROR(GL_NO_ERROR);
634
635 glUseProgram(mProgram);
636 glUniform1i(mTexture0UniformLocation, 0);
637 glUniform1i(mTexture1UniformLocation, 1);
638 drawQuad(mProgram, "position", 0.5f);
639 EXPECT_GL_NO_ERROR();
640
641 EXPECT_PIXEL_NEAR(0, 0, 0, 180, 0, 255, 2);
642 }
643
644 GLuint mTexture2DA;
645 GLuint mTexture2DB;
646 GLint mTexture0UniformLocation;
647 GLint mTexture1UniformLocation;
648};
649
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200650class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest
651{
652 protected:
653 SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {}
654
Jamie Madill35cd7332018-12-02 12:03:33 -0500655 const char *getFragmentShaderSource() override
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200656 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300657 return
658 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200659 uniform highp sampler2D tex2DArray[2];
660 varying vec2 texcoord;
661
662 vec4 computeFragColor(highp sampler2D aTex2DArray[2])
663 {
664 return texture2D(aTex2DArray[0], texcoord) + texture2D(aTex2DArray[1], texcoord);
665 }
666
667 void main()
668 {
669 gl_FragColor = computeFragColor(tex2DArray);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300670 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200671 }
672};
673
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200674class Texture2DArrayTestES3 : public TexCoordDrawTest
675{
676 protected:
677 Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {}
678
Jamie Madill35cd7332018-12-02 12:03:33 -0500679 const char *getVertexShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200680 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500681 return "#version 300 es\n"
682 "out vec2 texcoord;\n"
683 "in vec4 position;\n"
684 "void main()\n"
685 "{\n"
686 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
687 " texcoord = (position.xy * 0.5) + 0.5;\n"
688 "}\n";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200689 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400690
Jamie Madill35cd7332018-12-02 12:03:33 -0500691 const char *getFragmentShaderSource() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200692 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500693 return "#version 300 es\n"
694 "precision highp float;\n"
695 "uniform highp sampler2DArray tex2DArray;\n"
696 "in vec2 texcoord;\n"
697 "out vec4 fragColor;\n"
698 "void main()\n"
699 "{\n"
700 " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n"
701 "}\n";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200702 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400703
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400704 void testSetUp() override
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200705 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400706 TexCoordDrawTest::testSetUp();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400707
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300708 setUpProgram();
709
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200710 mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray");
Jamie Madill2453dbc2015-07-14 11:35:42 -0400711 ASSERT_NE(-1, mTextureArrayLocation);
712
713 glGenTextures(1, &m2DArrayTexture);
714 ASSERT_GL_NO_ERROR();
715 }
716
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400717 void testTearDown() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400718 {
719 glDeleteTextures(1, &m2DArrayTexture);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400720 TexCoordDrawTest::testTearDown();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400721 }
722
723 GLuint m2DArrayTexture;
Jamie Madill2453dbc2015-07-14 11:35:42 -0400724 GLint mTextureArrayLocation;
725};
726
Olli Etuahobce743a2016-01-15 17:18:28 +0200727class TextureSizeTextureArrayTest : public TexCoordDrawTest
728{
729 protected:
730 TextureSizeTextureArrayTest()
731 : TexCoordDrawTest(),
732 mTexture2DA(0),
733 mTexture2DB(0),
734 mTexture0Location(-1),
735 mTexture1Location(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500736 {}
Olli Etuahobce743a2016-01-15 17:18:28 +0200737
Jamie Madill35cd7332018-12-02 12:03:33 -0500738 const char *getVertexShaderSource() override { return essl3_shaders::vs::Simple(); }
Olli Etuahobce743a2016-01-15 17:18:28 +0200739
Jamie Madill35cd7332018-12-02 12:03:33 -0500740 const char *getFragmentShaderSource() override
Olli Etuahobce743a2016-01-15 17:18:28 +0200741 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500742 return "#version 300 es\n"
743 "precision highp float;\n"
744 "uniform highp sampler2D tex2DArray[2];\n"
745 "out vec4 fragColor;\n"
746 "void main()\n"
747 "{\n"
748 " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n"
749 " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n"
750 " fragColor = vec4(red, green, 0.0, 1.0);\n"
751 "}\n";
Olli Etuahobce743a2016-01-15 17:18:28 +0200752 }
753
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400754 void testSetUp() override
Olli Etuahobce743a2016-01-15 17:18:28 +0200755 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400756 TexCoordDrawTest::testSetUp();
Olli Etuahobce743a2016-01-15 17:18:28 +0200757
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300758 setUpProgram();
759
Olli Etuahobce743a2016-01-15 17:18:28 +0200760 mTexture0Location = glGetUniformLocation(mProgram, "tex2DArray[0]");
761 ASSERT_NE(-1, mTexture0Location);
762 mTexture1Location = glGetUniformLocation(mProgram, "tex2DArray[1]");
763 ASSERT_NE(-1, mTexture1Location);
764
765 mTexture2DA = create2DTexture();
766 mTexture2DB = create2DTexture();
767 ASSERT_GL_NO_ERROR();
768 }
769
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400770 void testTearDown() override
Olli Etuahobce743a2016-01-15 17:18:28 +0200771 {
772 glDeleteTextures(1, &mTexture2DA);
773 glDeleteTextures(1, &mTexture2DB);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400774 TexCoordDrawTest::testTearDown();
Olli Etuahobce743a2016-01-15 17:18:28 +0200775 }
776
777 GLuint mTexture2DA;
778 GLuint mTexture2DB;
779 GLint mTexture0Location;
780 GLint mTexture1Location;
781};
782
Olli Etuahoa314b612016-03-10 16:43:00 +0200783class Texture3DTestES3 : public TexCoordDrawTest
784{
785 protected:
786 Texture3DTestES3() : TexCoordDrawTest(), mTexture3D(0), mTexture3DUniformLocation(-1) {}
787
Jamie Madill35cd7332018-12-02 12:03:33 -0500788 const char *getVertexShaderSource() override
Olli Etuahoa314b612016-03-10 16:43:00 +0200789 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500790 return "#version 300 es\n"
791 "out vec2 texcoord;\n"
792 "in vec4 position;\n"
793 "void main()\n"
794 "{\n"
795 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
796 " texcoord = (position.xy * 0.5) + 0.5;\n"
797 "}\n";
Olli Etuahoa314b612016-03-10 16:43:00 +0200798 }
799
Jamie Madill35cd7332018-12-02 12:03:33 -0500800 const char *getFragmentShaderSource() override
Olli Etuahoa314b612016-03-10 16:43:00 +0200801 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500802 return "#version 300 es\n"
803 "precision highp float;\n"
804 "uniform highp sampler3D tex3D;\n"
805 "in vec2 texcoord;\n"
806 "out vec4 fragColor;\n"
807 "void main()\n"
808 "{\n"
809 " fragColor = texture(tex3D, vec3(texcoord, 0.0));\n"
810 "}\n";
Olli Etuahoa314b612016-03-10 16:43:00 +0200811 }
812
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400813 void testSetUp() override
Olli Etuahoa314b612016-03-10 16:43:00 +0200814 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400815 TexCoordDrawTest::testSetUp();
Olli Etuahoa314b612016-03-10 16:43:00 +0200816
817 glGenTextures(1, &mTexture3D);
818
819 setUpProgram();
820
821 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
822 ASSERT_NE(-1, mTexture3DUniformLocation);
823 }
824
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400825 void testTearDown() override
Olli Etuahoa314b612016-03-10 16:43:00 +0200826 {
827 glDeleteTextures(1, &mTexture3D);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400828 TexCoordDrawTest::testTearDown();
Olli Etuahoa314b612016-03-10 16:43:00 +0200829 }
830
831 GLuint mTexture3D;
832 GLint mTexture3DUniformLocation;
833};
834
Olli Etuaho1a679902016-01-14 12:21:47 +0200835class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest
836{
837 protected:
838 ShadowSamplerPlusSampler3DTestES3()
839 : TexCoordDrawTest(),
840 mTextureShadow(0),
841 mTexture3D(0),
842 mTextureShadowUniformLocation(-1),
843 mTexture3DUniformLocation(-1),
844 mDepthRefUniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500845 {}
Olli Etuaho1a679902016-01-14 12:21:47 +0200846
Jamie Madill35cd7332018-12-02 12:03:33 -0500847 const char *getVertexShaderSource() override
Olli Etuaho1a679902016-01-14 12:21:47 +0200848 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500849 return "#version 300 es\n"
850 "out vec2 texcoord;\n"
851 "in vec4 position;\n"
852 "void main()\n"
853 "{\n"
854 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
855 " texcoord = (position.xy * 0.5) + 0.5;\n"
856 "}\n";
Olli Etuaho1a679902016-01-14 12:21:47 +0200857 }
858
Jamie Madill35cd7332018-12-02 12:03:33 -0500859 const char *getFragmentShaderSource() override
Olli Etuaho1a679902016-01-14 12:21:47 +0200860 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500861 return "#version 300 es\n"
862 "precision highp float;\n"
863 "uniform highp sampler2DShadow tex2DShadow;\n"
864 "uniform highp sampler3D tex3D;\n"
865 "in vec2 texcoord;\n"
866 "uniform float depthRef;\n"
867 "out vec4 fragColor;\n"
868 "void main()\n"
869 "{\n"
870 " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n"
871 " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n"
872 "}\n";
Olli Etuaho1a679902016-01-14 12:21:47 +0200873 }
874
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400875 void testSetUp() override
Olli Etuaho1a679902016-01-14 12:21:47 +0200876 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400877 TexCoordDrawTest::testSetUp();
Olli Etuaho1a679902016-01-14 12:21:47 +0200878
879 glGenTextures(1, &mTexture3D);
880
881 glGenTextures(1, &mTextureShadow);
882 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
883 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
884
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300885 setUpProgram();
886
Olli Etuaho1a679902016-01-14 12:21:47 +0200887 mTextureShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
888 ASSERT_NE(-1, mTextureShadowUniformLocation);
889 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
890 ASSERT_NE(-1, mTexture3DUniformLocation);
891 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
892 ASSERT_NE(-1, mDepthRefUniformLocation);
893 }
894
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400895 void testTearDown() override
Olli Etuaho1a679902016-01-14 12:21:47 +0200896 {
897 glDeleteTextures(1, &mTextureShadow);
898 glDeleteTextures(1, &mTexture3D);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400899 TexCoordDrawTest::testTearDown();
Olli Etuaho1a679902016-01-14 12:21:47 +0200900 }
901
902 GLuint mTextureShadow;
903 GLuint mTexture3D;
904 GLint mTextureShadowUniformLocation;
905 GLint mTexture3DUniformLocation;
906 GLint mDepthRefUniformLocation;
907};
908
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200909class SamplerTypeMixTestES3 : public TexCoordDrawTest
910{
911 protected:
912 SamplerTypeMixTestES3()
913 : TexCoordDrawTest(),
914 mTexture2D(0),
915 mTextureCube(0),
916 mTexture2DShadow(0),
917 mTextureCubeShadow(0),
918 mTexture2DUniformLocation(-1),
919 mTextureCubeUniformLocation(-1),
920 mTexture2DShadowUniformLocation(-1),
921 mTextureCubeShadowUniformLocation(-1),
922 mDepthRefUniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500923 {}
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200924
Jamie Madill35cd7332018-12-02 12:03:33 -0500925 const char *getVertexShaderSource() override
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200926 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500927 return "#version 300 es\n"
928 "out vec2 texcoord;\n"
929 "in vec4 position;\n"
930 "void main()\n"
931 "{\n"
932 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
933 " texcoord = (position.xy * 0.5) + 0.5;\n"
934 "}\n";
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200935 }
936
Jamie Madill35cd7332018-12-02 12:03:33 -0500937 const char *getFragmentShaderSource() override
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200938 {
Jamie Madill35cd7332018-12-02 12:03:33 -0500939 return "#version 300 es\n"
940 "precision highp float;\n"
941 "uniform highp sampler2D tex2D;\n"
942 "uniform highp samplerCube texCube;\n"
943 "uniform highp sampler2DShadow tex2DShadow;\n"
944 "uniform highp samplerCubeShadow texCubeShadow;\n"
945 "in vec2 texcoord;\n"
946 "uniform float depthRef;\n"
947 "out vec4 fragColor;\n"
948 "void main()\n"
949 "{\n"
950 " fragColor = texture(tex2D, texcoord);\n"
951 " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n"
952 " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n"
953 " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * "
954 "0.125);\n"
955 "}\n";
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200956 }
957
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400958 void testSetUp() override
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200959 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400960 TexCoordDrawTest::testSetUp();
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200961
962 glGenTextures(1, &mTexture2D);
963 glGenTextures(1, &mTextureCube);
964
965 glGenTextures(1, &mTexture2DShadow);
966 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
967 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
968
969 glGenTextures(1, &mTextureCubeShadow);
970 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
971 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
972
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300973 setUpProgram();
974
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200975 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
976 ASSERT_NE(-1, mTexture2DUniformLocation);
977 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
978 ASSERT_NE(-1, mTextureCubeUniformLocation);
979 mTexture2DShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
980 ASSERT_NE(-1, mTexture2DShadowUniformLocation);
981 mTextureCubeShadowUniformLocation = glGetUniformLocation(mProgram, "texCubeShadow");
982 ASSERT_NE(-1, mTextureCubeShadowUniformLocation);
983 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
984 ASSERT_NE(-1, mDepthRefUniformLocation);
985
986 ASSERT_GL_NO_ERROR();
987 }
988
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400989 void testTearDown() override
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200990 {
991 glDeleteTextures(1, &mTexture2D);
992 glDeleteTextures(1, &mTextureCube);
993 glDeleteTextures(1, &mTexture2DShadow);
994 glDeleteTextures(1, &mTextureCubeShadow);
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400995 TexCoordDrawTest::testTearDown();
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200996 }
997
998 GLuint mTexture2D;
999 GLuint mTextureCube;
1000 GLuint mTexture2DShadow;
1001 GLuint mTextureCubeShadow;
1002 GLint mTexture2DUniformLocation;
1003 GLint mTextureCubeUniformLocation;
1004 GLint mTexture2DShadowUniformLocation;
1005 GLint mTextureCubeShadowUniformLocation;
1006 GLint mDepthRefUniformLocation;
1007};
1008
Olli Etuaho96963162016-03-21 11:54:33 +02001009class SamplerInStructTest : public Texture2DTest
1010{
1011 protected:
1012 SamplerInStructTest() : Texture2DTest() {}
1013
1014 const char *getTextureUniformName() override { return "us.tex"; }
1015
Jamie Madill35cd7332018-12-02 12:03:33 -05001016 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001017 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001018 return "precision highp float;\n"
1019 "struct S\n"
1020 "{\n"
1021 " vec4 a;\n"
1022 " highp sampler2D tex;\n"
1023 "};\n"
1024 "uniform S us;\n"
1025 "varying vec2 texcoord;\n"
1026 "void main()\n"
1027 "{\n"
1028 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x);\n"
1029 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001030 }
1031
1032 void runSamplerInStructTest()
1033 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001034 setUpProgram();
1035
Olli Etuaho96963162016-03-21 11:54:33 +02001036 glActiveTexture(GL_TEXTURE0);
1037 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001038 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1039 &GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001040 drawQuad(mProgram, "position", 0.5f);
Olli Etuahoa314b612016-03-10 16:43:00 +02001041 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001042 }
1043};
1044
1045class SamplerInStructAsFunctionParameterTest : public SamplerInStructTest
1046{
1047 protected:
1048 SamplerInStructAsFunctionParameterTest() : SamplerInStructTest() {}
1049
Jamie Madill35cd7332018-12-02 12:03:33 -05001050 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001051 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001052 return "precision highp float;\n"
1053 "struct S\n"
1054 "{\n"
1055 " vec4 a;\n"
1056 " highp sampler2D tex;\n"
1057 "};\n"
1058 "uniform S us;\n"
1059 "varying vec2 texcoord;\n"
1060 "vec4 sampleFrom(S s) {\n"
1061 " return texture2D(s.tex, texcoord + s.a.x);\n"
1062 "}\n"
1063 "void main()\n"
1064 "{\n"
1065 " gl_FragColor = sampleFrom(us);\n"
1066 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001067 }
1068};
1069
1070class SamplerInStructArrayAsFunctionParameterTest : public SamplerInStructTest
1071{
1072 protected:
1073 SamplerInStructArrayAsFunctionParameterTest() : SamplerInStructTest() {}
1074
1075 const char *getTextureUniformName() override { return "us[0].tex"; }
1076
Jamie Madill35cd7332018-12-02 12:03:33 -05001077 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001078 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001079 return "precision highp float;\n"
1080 "struct S\n"
1081 "{\n"
1082 " vec4 a;\n"
1083 " highp sampler2D tex;\n"
1084 "};\n"
1085 "uniform S us[1];\n"
1086 "varying vec2 texcoord;\n"
1087 "vec4 sampleFrom(S s) {\n"
1088 " return texture2D(s.tex, texcoord + s.a.x);\n"
1089 "}\n"
1090 "void main()\n"
1091 "{\n"
1092 " gl_FragColor = sampleFrom(us[0]);\n"
1093 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001094 }
1095};
1096
1097class SamplerInNestedStructAsFunctionParameterTest : public SamplerInStructTest
1098{
1099 protected:
1100 SamplerInNestedStructAsFunctionParameterTest() : SamplerInStructTest() {}
1101
1102 const char *getTextureUniformName() override { return "us[0].sub.tex"; }
1103
Jamie Madill35cd7332018-12-02 12:03:33 -05001104 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001105 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001106 return "precision highp float;\n"
1107 "struct SUB\n"
1108 "{\n"
1109 " vec4 a;\n"
1110 " highp sampler2D tex;\n"
1111 "};\n"
1112 "struct S\n"
1113 "{\n"
1114 " SUB sub;\n"
1115 "};\n"
1116 "uniform S us[1];\n"
1117 "varying vec2 texcoord;\n"
1118 "vec4 sampleFrom(SUB s) {\n"
1119 " return texture2D(s.tex, texcoord + s.a.x);\n"
1120 "}\n"
1121 "void main()\n"
1122 "{\n"
1123 " gl_FragColor = sampleFrom(us[0].sub);\n"
1124 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001125 }
1126};
1127
1128class SamplerInStructAndOtherVariableTest : public SamplerInStructTest
1129{
1130 protected:
1131 SamplerInStructAndOtherVariableTest() : SamplerInStructTest() {}
1132
Jamie Madill35cd7332018-12-02 12:03:33 -05001133 const char *getFragmentShaderSource() override
Olli Etuaho96963162016-03-21 11:54:33 +02001134 {
Jamie Madill35cd7332018-12-02 12:03:33 -05001135 return "precision highp float;\n"
1136 "struct S\n"
1137 "{\n"
1138 " vec4 a;\n"
1139 " highp sampler2D tex;\n"
1140 "};\n"
1141 "uniform S us;\n"
1142 "uniform float us_tex;\n"
1143 "varying vec2 texcoord;\n"
1144 "void main()\n"
1145 "{\n"
1146 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x + us_tex);\n"
1147 "}\n";
Olli Etuaho96963162016-03-21 11:54:33 +02001148 }
1149};
1150
Anders Leinof6cbe442019-04-18 15:32:07 +03001151class Texture2DIntegerTestES3 : public Texture2DTest
1152{
1153 protected:
1154 Texture2DIntegerTestES3() : Texture2DTest() {}
1155
1156 const char *getVertexShaderSource() override
1157 {
1158 return "#version 300 es\n"
1159 "out vec2 texcoord;\n"
1160 "in vec4 position;\n"
1161 "void main()\n"
1162 "{\n"
1163 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1164 " texcoord = (position.xy * 0.5) + 0.5;\n"
1165 "}\n";
1166 }
1167
1168 const char *getFragmentShaderSource() override
1169 {
1170 return "#version 300 es\n"
1171 "precision highp float;\n"
1172 "precision highp usampler2D;\n"
1173 "uniform usampler2D tex;\n"
1174 "in vec2 texcoord;\n"
1175 "out vec4 fragColor;\n"
1176 "void main()\n"
1177 "{\n"
Anders Leino8224a582019-05-20 12:39:29 +03001178 " fragColor = vec4(texture(tex, texcoord))/255.0;\n"
Anders Leinof6cbe442019-04-18 15:32:07 +03001179 "}\n";
1180 }
1181};
1182
Anders Leino60cc7512019-05-06 09:25:27 +03001183class TextureCubeIntegerTestES3 : public TexCoordDrawTest
1184{
1185 protected:
1186 TextureCubeIntegerTestES3()
1187 : TexCoordDrawTest(), mTextureCube(0), mTextureCubeUniformLocation(-1)
1188 {}
1189
1190 const char *getVertexShaderSource() override
1191 {
1192 return "#version 300 es\n"
1193 "out vec2 texcoord;\n"
1194 "in vec4 position;\n"
1195 "void main()\n"
1196 "{\n"
1197 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1198 " texcoord = 0.5*position.xy;\n"
1199 "}\n";
1200 }
1201
1202 const char *getFragmentShaderSource() override
1203 {
1204 return "#version 300 es\n"
1205 "precision highp float;\n"
1206 "precision highp usamplerCube;\n"
1207 "uniform usamplerCube texCube;\n"
1208 "in vec2 texcoord;\n"
1209 "out vec4 fragColor;\n"
1210 "void main()\n"
1211 "{\n"
1212 " fragColor = vec4(texture(texCube, vec3(texcoord, 1)))/255.0;\n"
1213 "}\n";
1214 }
1215
1216 void testSetUp() override
1217 {
1218 TexCoordDrawTest::testSetUp();
1219 glGenTextures(1, &mTextureCube);
1220 setUpProgram();
1221
1222 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
1223 ASSERT_NE(-1, mTextureCubeUniformLocation);
1224 }
1225
1226 void testTearDown() override
1227 {
1228 glDeleteTextures(1, &mTextureCube);
1229 TexCoordDrawTest::testTearDown();
1230 }
1231
1232 GLuint mTextureCube;
1233 GLint mTextureCubeUniformLocation;
1234};
1235
Anders Leinoe4452442019-05-09 13:29:49 +03001236class TextureCubeIntegerEdgeTestES3 : public TextureCubeIntegerTestES3
1237{
1238 protected:
1239 TextureCubeIntegerEdgeTestES3() : TextureCubeIntegerTestES3() {}
1240
1241 const char *getVertexShaderSource() override
1242 {
1243 return "#version 300 es\n"
1244 "out vec2 texcoord;\n"
1245 "in vec4 position;\n"
1246 "void main()\n"
1247 "{\n"
1248 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1249 " texcoord = position.xy;\n"
1250 "}\n";
1251 }
1252
1253 const char *getFragmentShaderSource() override
1254 {
1255 return "#version 300 es\n"
1256 "precision highp float;\n"
1257 "precision highp usamplerCube;\n"
1258 "uniform usamplerCube texCube;\n"
1259 "in vec2 texcoord;\n"
1260 "out vec4 fragColor;\n"
1261 "void main()\n"
1262 "{\n"
1263 " fragColor = vec4(texture(texCube, vec3(texcoord, 0)))/255.0;\n"
1264 "}\n";
1265 }
1266};
1267
Anders Leino1b6aded2019-05-20 12:56:34 +03001268class Texture2DIntegerProjectiveOffsetTestES3 : public Texture2DTest
1269{
1270 protected:
1271 Texture2DIntegerProjectiveOffsetTestES3() : Texture2DTest() {}
1272
1273 const char *getVertexShaderSource() override
1274 {
1275 return "#version 300 es\n"
1276 "out vec2 texcoord;\n"
1277 "in vec4 position;\n"
1278 "void main()\n"
1279 "{\n"
1280 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1281 " texcoord = 0.5*position.xy + vec2(0.5, 0.5);\n"
1282 "}\n";
1283 }
1284
1285 const char *getFragmentShaderSource() override
1286 {
1287 return "#version 300 es\n"
1288 "precision highp float;\n"
1289 "precision highp usampler2D;\n"
1290 "uniform usampler2D tex;\n"
1291 "in vec2 texcoord;\n"
1292 "out vec4 fragColor;\n"
1293 "void main()\n"
1294 "{\n"
1295 " fragColor = vec4(textureProjOffset(tex, vec3(texcoord, 1), ivec2(0,0), "
1296 "0.0))/255.0;\n"
1297 "}\n";
1298 }
1299};
1300
Anders Leino69d04932019-05-20 14:04:13 +03001301class Texture2DArrayIntegerTestES3 : public Texture2DArrayTestES3
1302{
1303 protected:
1304 Texture2DArrayIntegerTestES3() : Texture2DArrayTestES3() {}
1305
1306 const char *getVertexShaderSource() override
1307 {
1308 return "#version 300 es\n"
1309 "out vec2 texcoord;\n"
1310 "in vec4 position;\n"
1311 "void main()\n"
1312 "{\n"
1313 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1314 " texcoord = (position.xy * 0.5) + 0.5;\n"
1315 "}\n";
1316 }
1317
1318 const char *getFragmentShaderSource() override
1319 {
1320 return "#version 300 es\n"
1321 "precision highp float;\n"
1322 "uniform highp usampler2DArray tex2DArray;\n"
1323 "in vec2 texcoord;\n"
1324 "out vec4 fragColor;\n"
1325 "void main()\n"
1326 "{\n"
1327 " fragColor = vec4(texture(tex2DArray, vec3(texcoord.x, texcoord.y, "
1328 "0.0)))/255.0;\n"
1329 "}\n";
1330 }
1331};
1332
Anders Leino262e2822019-05-20 14:24:40 +03001333class Texture3DIntegerTestES3 : public Texture3DTestES3
1334{
1335 protected:
1336 Texture3DIntegerTestES3() : Texture3DTestES3() {}
1337
1338 const char *getVertexShaderSource() override
1339 {
1340 return "#version 300 es\n"
1341 "out vec2 texcoord;\n"
1342 "in vec4 position;\n"
1343 "void main()\n"
1344 "{\n"
1345 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1346 " texcoord = (position.xy * 0.5) + 0.5;\n"
1347 "}\n";
1348 }
1349
1350 const char *getFragmentShaderSource() override
1351 {
1352 return "#version 300 es\n"
1353 "precision highp float;\n"
1354 "uniform highp usampler3D tex3D;\n"
1355 "in vec2 texcoord;\n"
1356 "out vec4 fragColor;\n"
1357 "void main()\n"
1358 "{\n"
1359 " fragColor = vec4(texture(tex3D, vec3(texcoord, 0.0)))/255.0;\n"
1360 "}\n";
1361 }
1362};
1363
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001364TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001365{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001366 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001367 EXPECT_GL_ERROR(GL_NO_ERROR);
1368
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001369 setUpProgram();
1370
Jamie Madill50cf2be2018-06-15 09:46:57 -04001371 const GLubyte *pixels[20] = {0};
Jamie Madillf67115c2014-04-22 13:14:05 -04001372 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1373 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001374
Jamie Madillb8149072019-04-30 16:14:44 -04001375 if (IsGLExtensionEnabled("GL_EXT_texture_storage"))
Geoff Langc51642b2016-11-14 16:18:26 -05001376 {
1377 // Create a 1-level immutable texture.
1378 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1379
1380 // Try calling sub image on the second level.
1381 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1382 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1383 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001384}
Geoff Langc41e42d2014-04-28 10:58:16 -04001385
John Bauman18319182016-09-28 14:22:27 -07001386// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1387TEST_P(Texture2DTest, QueryBinding)
1388{
1389 glBindTexture(GL_TEXTURE_2D, 0);
1390 EXPECT_GL_ERROR(GL_NO_ERROR);
1391
1392 GLint textureBinding;
1393 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1394 EXPECT_GL_NO_ERROR();
1395 EXPECT_EQ(0, textureBinding);
1396
1397 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
Jamie Madillb8149072019-04-30 16:14:44 -04001398 if (IsGLExtensionEnabled("GL_OES_EGL_image_external") ||
1399 IsGLExtensionEnabled("GL_NV_EGL_stream_consumer_external"))
John Bauman18319182016-09-28 14:22:27 -07001400 {
1401 EXPECT_GL_NO_ERROR();
1402 EXPECT_EQ(0, textureBinding);
1403 }
1404 else
1405 {
1406 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1407 }
1408}
1409
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001410TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001411{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001412 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001413 EXPECT_GL_ERROR(GL_NO_ERROR);
1414
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001415 setUpProgram();
1416
Geoff Langc41e42d2014-04-28 10:58:16 -04001417 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001418 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001419 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001420 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001421
Jamie Madill50cf2be2018-06-15 09:46:57 -04001422 const GLubyte *pixel[4] = {0};
Geoff Langc41e42d2014-04-28 10:58:16 -04001423
1424 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1425 EXPECT_GL_NO_ERROR();
1426
1427 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1428 EXPECT_GL_NO_ERROR();
1429
1430 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1431 EXPECT_GL_NO_ERROR();
1432}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001433
1434// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001435TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001436{
1437 glActiveTexture(GL_TEXTURE0);
1438 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1439 glActiveTexture(GL_TEXTURE1);
1440 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1441 EXPECT_GL_ERROR(GL_NO_ERROR);
1442
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001443 glUseProgram(mProgram);
1444 glUniform1i(mTexture2DUniformLocation, 0);
1445 glUniform1i(mTextureCubeUniformLocation, 1);
1446 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001447 EXPECT_GL_NO_ERROR();
1448}
Jamie Madill9aca0592014-10-06 16:26:59 -04001449
Olli Etuaho53a2da12016-01-11 15:43:32 +02001450// Test drawing with two texture types accessed from the same shader and check that the result of
1451// drawing is correct.
1452TEST_P(TextureCubeTest, CubeMapDraw)
1453{
1454 GLubyte texData[4];
1455 texData[0] = 0;
1456 texData[1] = 60;
1457 texData[2] = 0;
1458 texData[3] = 255;
1459
1460 glActiveTexture(GL_TEXTURE0);
1461 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1462 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1463
1464 glActiveTexture(GL_TEXTURE1);
1465 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1466 texData[1] = 120;
1467 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1468 texData);
1469 EXPECT_GL_ERROR(GL_NO_ERROR);
1470
1471 glUseProgram(mProgram);
1472 glUniform1i(mTexture2DUniformLocation, 0);
1473 glUniform1i(mTextureCubeUniformLocation, 1);
1474 drawQuad(mProgram, "position", 0.5f);
1475 EXPECT_GL_NO_ERROR();
1476
1477 int px = getWindowWidth() - 1;
1478 int py = 0;
1479 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1480}
1481
Olli Etuaho4644a202016-01-12 15:12:53 +02001482TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1483{
1484 glActiveTexture(GL_TEXTURE0);
1485 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1486 GLubyte texData[4];
1487 texData[0] = 0;
1488 texData[1] = 128;
1489 texData[2] = 0;
1490 texData[3] = 255;
1491 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1492 glUseProgram(mProgram);
1493 glUniform1i(mTexture2DUniformLocation, 0);
1494 drawQuad(mProgram, "position", 0.5f);
1495 EXPECT_GL_NO_ERROR();
1496
1497 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1498}
1499
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001500// Test drawing with two textures passed to the shader in a sampler array.
1501TEST_P(SamplerArrayTest, SamplerArrayDraw)
1502{
1503 testSamplerArrayDraw();
1504}
1505
1506// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1507// user-defined function in the shader.
1508TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1509{
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05001510 // TODO: Diagnose and fix. http://anglebug.com/2955
1511 ANGLE_SKIP_TEST_IF(IsVulkan() && IsAndroid());
1512
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001513 testSamplerArrayDraw();
1514}
1515
Jamie Madill9aca0592014-10-06 16:26:59 -04001516// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001517TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001518{
1519 int px = getWindowWidth() / 2;
1520 int py = getWindowHeight() / 2;
1521
1522 glActiveTexture(GL_TEXTURE0);
1523 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1524
Olli Etuahoa314b612016-03-10 16:43:00 +02001525 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001526
Olli Etuahoa314b612016-03-10 16:43:00 +02001527 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001528 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1529 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1530 glGenerateMipmap(GL_TEXTURE_2D);
1531
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001532 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001533 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001534 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1535 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001536 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001537 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001538
Olli Etuahoa314b612016-03-10 16:43:00 +02001539 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001540
Olli Etuahoa314b612016-03-10 16:43:00 +02001541 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1542 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001543 glGenerateMipmap(GL_TEXTURE_2D);
1544
Olli Etuahoa314b612016-03-10 16:43:00 +02001545 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001546
Olli Etuahoa314b612016-03-10 16:43:00 +02001547 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1548 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001549 glGenerateMipmap(GL_TEXTURE_2D);
1550
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001551 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001552
1553 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001554 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001555}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001556
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001557// Test creating a FBO with a cube map render target, to test an ANGLE bug
1558// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001559TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001560{
Michael Spangd8506c72019-01-29 15:35:09 -05001561 // http://anglebug.com/3145
1562 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
1563
Shahbaz Youssefi0c128e12019-03-25 23:50:14 -04001564 // http://anglebug.com/2822
1565 ANGLE_SKIP_TEST_IF(IsWindows() && IsIntel() && IsVulkan());
1566
Jamie Madill3f3b3582018-09-14 10:38:44 -04001567 GLFramebuffer fbo;
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001568 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1569
1570 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Jamie Madill50cf2be2018-06-15 09:46:57 -04001571 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1572 mTextureCube, 0);
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001573
Corentin Wallez322653b2015-06-17 18:33:56 +02001574 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001575 EXPECT_GL_NO_ERROR();
Jamie Madill3f3b3582018-09-14 10:38:44 -04001576
1577 // Test clearing the six mip faces individually.
1578 std::array<GLColor, 6> faceColors = {{GLColor::red, GLColor::green, GLColor::blue,
1579 GLColor::yellow, GLColor::cyan, GLColor::magenta}};
1580
1581 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1582 {
1583 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1584 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1585
1586 Vector4 clearColorF = faceColors[faceIndex].toNormalizedVector();
1587 glClearColor(clearColorF.x(), clearColorF.y(), clearColorF.z(), clearColorF.w());
1588 glClear(GL_COLOR_BUFFER_BIT);
1589
1590 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex]);
1591 }
1592
1593 // Iterate the faces again to make sure the colors haven't changed.
1594 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1595 {
1596 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1597 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1598 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex])
1599 << "face color " << faceIndex << " shouldn't change";
1600 }
1601}
1602
1603// Tests clearing a cube map with a scissor enabled.
1604TEST_P(TextureCubeTest, CubeMapFBOScissoredClear)
1605{
1606 // TODO(jie.a.chen): Diagnose and fix. http://anglebug.com/2822
1607 ANGLE_SKIP_TEST_IF(IsVulkan() && IsIntel() && IsWindows());
1608
Michael Spangd8506c72019-01-29 15:35:09 -05001609 // http://anglebug.com/3145
1610 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
1611
Jamie Madill3f3b3582018-09-14 10:38:44 -04001612 constexpr size_t kSize = 16;
1613
1614 GLFramebuffer fbo;
1615 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1616 glViewport(0, 0, kSize, kSize);
1617
1618 GLTexture texcube;
1619 glBindTexture(GL_TEXTURE_CUBE_MAP, texcube);
1620 for (GLenum face = 0; face < 6; face++)
1621 {
1622 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA,
1623 GL_UNSIGNED_BYTE, nullptr);
1624 }
1625 ASSERT_GL_NO_ERROR();
1626
1627 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1628 texcube, 0);
1629
1630 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1631 ASSERT_GL_NO_ERROR();
1632
1633 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1634 glClear(GL_COLOR_BUFFER_BIT);
1635 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1636
1637 glEnable(GL_SCISSOR_TEST);
1638 glScissor(kSize / 2, 0, kSize / 2, kSize);
1639 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
1640 glClear(GL_COLOR_BUFFER_BIT);
1641
1642 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1643 EXPECT_PIXEL_COLOR_EQ(kSize / 2 + 1, 0, GLColor::green);
1644
1645 ASSERT_GL_NO_ERROR();
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001646}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001647
Jamie Madill50cf2be2018-06-15 09:46:57 -04001648// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a
1649// default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001650TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001651{
Jamie Madillb8149072019-04-30 16:14:44 -04001652 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 &&
1653 !IsGLExtensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -04001654
Jamie Madill50cf2be2018-06-15 09:46:57 -04001655 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001656 int height = getWindowHeight();
1657
1658 GLuint tex2D;
1659 glGenTextures(1, &tex2D);
1660 glActiveTexture(GL_TEXTURE0);
1661 glBindTexture(GL_TEXTURE_2D, tex2D);
1662
1663 // Fill with red
1664 std::vector<GLubyte> pixels(3 * 16 * 16);
1665 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1666 {
1667 pixels[pixelId * 3 + 0] = 255;
1668 pixels[pixelId * 3 + 1] = 0;
1669 pixels[pixelId * 3 + 2] = 0;
1670 }
1671
1672 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001673 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1674 // 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 -04001675 if (getClientMajorVersion() >= 3)
1676 {
1677 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1678 }
1679 else
1680 {
1681 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1682 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001683
1684 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1685 // glTexSubImage2D should take into account that the image is dirty.
1686 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1687 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1688 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1689
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001690 setUpProgram();
1691
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001692 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001693 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001694 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001695 glDeleteTextures(1, &tex2D);
1696 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001697 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001698
1699 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001700 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1701 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001702}
1703
Jamie Madill50cf2be2018-06-15 09:46:57 -04001704// Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has
1705// initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001706TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001707{
Jamie Madillb8149072019-04-30 16:14:44 -04001708 if (IsGLExtensionEnabled("NV_pixel_buffer_object"))
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001709 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04001710 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001711 int height = getWindowHeight();
1712
1713 GLuint tex2D;
1714 glGenTextures(1, &tex2D);
1715 glActiveTexture(GL_TEXTURE0);
1716 glBindTexture(GL_TEXTURE_2D, tex2D);
1717
1718 // Fill with red
1719 std::vector<GLubyte> pixels(3 * 16 * 16);
1720 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1721 {
1722 pixels[pixelId * 3 + 0] = 255;
1723 pixels[pixelId * 3 + 1] = 0;
1724 pixels[pixelId * 3 + 2] = 0;
1725 }
1726
1727 // Read 16x16 region from red backbuffer to PBO
1728 GLuint pbo;
1729 glGenBuffers(1, &pbo);
1730 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1731 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1732
1733 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001734 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1735 // 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 +00001736 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1737
1738 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1739 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001740 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 +00001741 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1742 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1743
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001744 setUpProgram();
1745
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001746 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001747 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001748 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001749 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001750 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001751 EXPECT_GL_NO_ERROR();
1752 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1753 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1754 }
1755}
Jamie Madillbc393df2015-01-29 13:46:07 -05001756
1757// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001758TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001759{
1760 testFloatCopySubImage(1, 1);
1761}
1762
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001763TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001764{
1765 testFloatCopySubImage(2, 1);
1766}
1767
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001768TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001769{
1770 testFloatCopySubImage(2, 2);
1771}
1772
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001773TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001774{
1775 testFloatCopySubImage(3, 1);
1776}
1777
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001778TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001779{
1780 testFloatCopySubImage(3, 2);
1781}
1782
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001783TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001784{
Yunchao He9550c602018-02-13 14:47:05 +08001785 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1786 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001787
Yunchao He9550c602018-02-13 14:47:05 +08001788 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1789 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001790
Jamie Madillbc393df2015-01-29 13:46:07 -05001791 testFloatCopySubImage(3, 3);
1792}
1793
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001794TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001795{
1796 testFloatCopySubImage(4, 1);
1797}
1798
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001799TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001800{
1801 testFloatCopySubImage(4, 2);
1802}
1803
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001804TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001805{
Yunchao He9550c602018-02-13 14:47:05 +08001806 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1807 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001808
Jamie Madillbc393df2015-01-29 13:46:07 -05001809 testFloatCopySubImage(4, 3);
1810}
1811
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001812TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001813{
Luc Ferronf786b702018-07-10 11:01:43 -04001814 // TODO(lucferron): This test fails only on linux and intel.
1815 // http://anglebug.com/2726
1816 ANGLE_SKIP_TEST_IF(IsVulkan() && IsLinux() && IsIntel());
1817
Yunchao He9550c602018-02-13 14:47:05 +08001818 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1819 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001820
Jamie Madillbc393df2015-01-29 13:46:07 -05001821 testFloatCopySubImage(4, 4);
1822}
Austin Kinross07285142015-03-26 11:36:16 -07001823
Jamie Madill50cf2be2018-06-15 09:46:57 -04001824// Port of
1825// https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1826// Run against GL_ALPHA/UNSIGNED_BYTE format, to ensure that D3D11 Feature Level 9_3 correctly
1827// handles GL_ALPHA
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001828TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001829{
1830 const int npotTexSize = 5;
Jamie Madill50cf2be2018-06-15 09:46:57 -04001831 const int potTexSize = 4; // Should be less than npotTexSize
Austin Kinross07285142015-03-26 11:36:16 -07001832 GLuint tex2D;
1833
Jamie Madillb8149072019-04-30 16:14:44 -04001834 if (IsGLExtensionEnabled("GL_OES_texture_npot"))
Austin Kinross07285142015-03-26 11:36:16 -07001835 {
1836 // This test isn't applicable if texture_npot is enabled
1837 return;
1838 }
1839
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001840 setUpProgram();
1841
Austin Kinross07285142015-03-26 11:36:16 -07001842 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1843
Austin Kinross5faa15b2016-01-11 13:32:48 -08001844 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1845 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1846
Austin Kinross07285142015-03-26 11:36:16 -07001847 glActiveTexture(GL_TEXTURE0);
1848 glGenTextures(1, &tex2D);
1849 glBindTexture(GL_TEXTURE_2D, tex2D);
1850
Till Rathmannc1551dc2018-08-15 17:04:49 +02001851 const std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize, 64);
Austin Kinross07285142015-03-26 11:36:16 -07001852
1853 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1854 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1855
1856 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
Jamie Madill50cf2be2018-06-15 09:46:57 -04001857 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1858 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001859 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1860
1861 // Check that an NPOT texture on level 0 succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001862 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1863 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001864 EXPECT_GL_NO_ERROR();
1865
1866 // Check that generateMipmap fails on NPOT
1867 glGenerateMipmap(GL_TEXTURE_2D);
1868 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1869
1870 // Check that nothing is drawn if filtering is not correct for NPOT
1871 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1872 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1873 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1874 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1875 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001876 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001877 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1878
1879 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1880 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1881 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1882 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1883 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001884 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001885 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1886
1887 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1888 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1889 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001890 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001891 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1892
1893 // Check that glTexImage2D for POT texture succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001894 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE,
1895 pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001896 EXPECT_GL_NO_ERROR();
1897
1898 // Check that generateMipmap for an POT texture succeeds
1899 glGenerateMipmap(GL_TEXTURE_2D);
1900 EXPECT_GL_NO_ERROR();
1901
1902 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1903 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1904 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1905 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1906 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1907 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001908 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001909 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1910 EXPECT_GL_NO_ERROR();
1911}
Jamie Madillfa05f602015-05-07 13:47:11 -04001912
Austin Kinross08528e12015-10-07 16:24:40 -07001913// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1914// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001915TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001916{
1917 glActiveTexture(GL_TEXTURE0);
1918 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1919
1920 // Create an 8x8 (i.e. power-of-two) texture.
1921 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1922 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1923 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1924 glGenerateMipmap(GL_TEXTURE_2D);
1925
1926 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1927 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001928 std::array<GLColor, 3 * 3> data;
1929 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001930
1931 EXPECT_GL_NO_ERROR();
1932}
1933
Geoff Lang3702d8c2019-04-08 13:44:06 -04001934// Regression test for http://crbug.com/949985 to make sure dirty bits are propagated up from
1935// TextureImpl and the texture is synced before being used in a draw call.
1936TEST_P(Texture2DTestES3, TextureImplPropogatesDirtyBits)
1937{
1938 ANGLE_SKIP_TEST_IF(IsIntel() && IsOpenGL());
Yuly Novikove6b23e42019-04-10 17:19:15 -04001939 // Flaky hangs on Win10 AMD RX 550 GL. http://anglebug.com/3371
1940 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsOpenGL());
Yuly Novikovbd4ff472019-07-19 22:08:17 +00001941 // D3D Debug device reports an error. http://anglebug.com/3501
1942 ANGLE_SKIP_TEST_IF(IsWindows() && IsD3D11());
Geoff Lang3702d8c2019-04-08 13:44:06 -04001943
1944 // The workaround in the GL backend required to trigger this bug generates driver warning
1945 // messages.
1946 ScopedIgnorePlatformMessages ignoreMessages;
1947
1948 setUpProgram();
1949 glUseProgram(mProgram);
1950 glActiveTexture(GL_TEXTURE0 + mTexture2DUniformLocation);
1951
1952 GLTexture dest;
1953 glBindTexture(GL_TEXTURE_2D, dest);
1954
1955 GLTexture source;
1956 glBindTexture(GL_TEXTURE_2D, source);
1957
1958 // Put data in mip 0 and 1
1959 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1960 GLColor::red.data());
1961 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1962 GLColor::green.data());
1963
1964 // Disable mipmapping so source is complete
1965 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1966 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1967
1968 // Force the dirty bits to be synchronized in source
1969 drawQuad(mProgram, "position", 1.0f);
1970
1971 // Copy from mip 1 of the source. In the GL backend this internally sets the base level to mip
1972 // 1 and sets a dirty bit.
1973 glCopyTextureCHROMIUM(source, 1, GL_TEXTURE_2D, dest, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_FALSE,
1974 GL_FALSE, GL_FALSE);
1975
1976 // Draw again, assertions are generated if the texture has internal dirty bits at draw time
1977 drawQuad(mProgram, "position", 1.0f);
1978}
1979
Geoff Lang6f691fb2019-04-25 11:01:52 -04001980// This test case changes the base level of a texture that's attached to a framebuffer, clears every
1981// level to green, and then samples the texture when rendering. Test is taken from
1982// https://www.khronos.org/registry/webgl/sdk/tests/conformance2/rendering/framebuffer-texture-changing-base-level.html
1983TEST_P(Texture2DTestES3, FramebufferTextureChangingBaselevel)
1984{
1985 // TODO(geofflang): Investigate on D3D11. http://anglebug.com/2291
1986 ANGLE_SKIP_TEST_IF(IsD3D11());
1987
1988 setUpProgram();
1989
1990 constexpr GLint width = 8;
1991 constexpr GLint height = 4;
1992
1993 GLTexture texture;
1994 glBindTexture(GL_TEXTURE_2D, texture);
1995 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1996 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1997 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1998 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1999
2000 // Create all mipmap levels for the texture from level 0 to the 1x1 pixel level.
2001 GLint level = 0;
2002 GLint levelW = width;
2003 GLint levelH = height;
2004 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, levelW, levelH, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2005 nullptr);
2006 while (levelW > 1 || levelH > 1)
2007 {
2008 ++level;
2009 levelW = static_cast<GLint>(std::max(1.0, std::floor(width / std::pow(2, level))));
2010 levelH = static_cast<GLint>(std::max(1.0, std::floor(height / std::pow(2, level))));
2011 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, levelW, levelH, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2012 nullptr);
2013 }
2014
2015 // Clear each level of the texture using an FBO. Change the base level to match the level used
2016 // for the FBO on each iteration.
2017 GLFramebuffer fbo;
2018 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
2019 level = 0;
2020 levelW = width;
2021 levelH = height;
2022 while (levelW > 1 || levelH > 1)
2023 {
2024 levelW = static_cast<GLint>(std::floor(width / std::pow(2, level)));
2025 levelH = static_cast<GLint>(std::floor(height / std::pow(2, level)));
2026
2027 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, level);
2028 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, level);
2029
2030 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2031 EXPECT_GL_NO_ERROR();
2032
2033 glClearColor(0, 1, 0, 1);
2034 glClear(GL_COLOR_BUFFER_BIT);
2035
2036 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2037
2038 ++level;
2039 }
2040
2041 glBindFramebuffer(GL_FRAMEBUFFER, 0);
2042 glViewport(0, 0, 16, 16);
2043 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2044
2045 drawQuad(mProgram, "position", 0.5f);
2046
2047 EXPECT_GL_NO_ERROR();
2048 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2049}
2050
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002051// Test to check that texture completeness is determined correctly when the texture base level is
2052// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
2053TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
2054{
2055 glActiveTexture(GL_TEXTURE0);
2056 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02002057
2058 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
2059 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
2060 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2061 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2062 texDataGreen.data());
2063 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2064 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002065 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2066 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2067 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2068
2069 EXPECT_GL_NO_ERROR();
2070
2071 drawQuad(mProgram, "position", 0.5f);
2072
Olli Etuahoa314b612016-03-10 16:43:00 +02002073 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2074}
2075
2076// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2077// have images defined.
2078TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
2079{
Yunchao He9550c602018-02-13 14:47:05 +08002080 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
2081 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
2082
Olli Etuahoa314b612016-03-10 16:43:00 +02002083 glActiveTexture(GL_TEXTURE0);
2084 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2085 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2086 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2087 texDataGreen.data());
2088 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2089 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2090 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2091 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2092
2093 EXPECT_GL_NO_ERROR();
2094
2095 drawQuad(mProgram, "position", 0.5f);
2096
2097 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2098}
2099
Olli Etuahoe8528d82016-05-16 17:50:52 +03002100// Test that drawing works correctly when level 0 is undefined and base level is 1.
2101TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
2102{
Yunchao He9550c602018-02-13 14:47:05 +08002103 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
2104 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
2105
Olli Etuahoe8528d82016-05-16 17:50:52 +03002106 glActiveTexture(GL_TEXTURE0);
2107 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2108 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2109 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2110 texDataGreen.data());
2111 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2112 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2113 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2114 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2115
2116 EXPECT_GL_NO_ERROR();
2117
2118 // Texture is incomplete.
2119 drawQuad(mProgram, "position", 0.5f);
2120 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2121
2122 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2123 texDataGreen.data());
2124
2125 // Texture is now complete.
2126 drawQuad(mProgram, "position", 0.5f);
2127 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2128}
2129
Olli Etuahoa314b612016-03-10 16:43:00 +02002130// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2131// dimensions that don't fit the images inside the range.
2132// GLES 3.0.4 section 3.8.13 Texture completeness
2133TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2134{
Olli Etuahoa314b612016-03-10 16:43:00 +02002135 glActiveTexture(GL_TEXTURE0);
2136 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2137 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
2138 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
2139 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
2140
2141 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2142 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2143
2144 // Two levels that are initially unused.
2145 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
2146 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2147 texDataCyan.data());
2148
2149 // One level that is used - only this level should affect completeness.
2150 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2151 texDataGreen.data());
2152
2153 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2154 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2155
2156 EXPECT_GL_NO_ERROR();
2157
2158 drawQuad(mProgram, "position", 0.5f);
2159
2160 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2161
Yunchao He2f23f352018-02-11 22:11:37 +08002162 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02002163
2164 // Switch the level that is being used to the cyan level 2.
2165 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2166 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2167
2168 EXPECT_GL_NO_ERROR();
2169
2170 drawQuad(mProgram, "position", 0.5f);
2171
2172 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2173}
2174
2175// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2176// have images defined.
2177TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
2178{
Olli Etuahoa314b612016-03-10 16:43:00 +02002179 glActiveTexture(GL_TEXTURE0);
2180 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2181 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2182 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2183 texDataGreen.data());
2184 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2185 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2186 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
2187 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2188
2189 EXPECT_GL_NO_ERROR();
2190
2191 drawQuad(mProgram, "position", 0.5f);
2192
2193 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2194}
2195
2196// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2197// dimensions that don't fit the images inside the range.
2198// GLES 3.0.4 section 3.8.13 Texture completeness
2199TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2200{
Yuly Novikovc5da7992019-06-27 12:57:13 -04002201 // Crashes on Intel Ubuntu 19.04 Mesa 19.0.2 GL. http://anglebug.com/2782
2202 ANGLE_SKIP_TEST_IF(IsLinux() && IsIntel() && IsDesktopOpenGL());
2203
Olli Etuahoa314b612016-03-10 16:43:00 +02002204 glActiveTexture(GL_TEXTURE0);
2205 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2206 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2207 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2208 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2209
2210 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2211 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2212
2213 // Two levels that are initially unused.
2214 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2215 texDataRed.data());
2216 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2217 texDataCyan.data());
2218
2219 // One level that is used - only this level should affect completeness.
2220 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2221 texDataGreen.data());
2222
2223 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
2224 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2225
2226 EXPECT_GL_NO_ERROR();
2227
2228 drawQuad(mProgram, "position", 0.5f);
2229
2230 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2231
Yunchao He2f23f352018-02-11 22:11:37 +08002232 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02002233
2234 // Switch the level that is being used to the cyan level 2.
2235 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
2236 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
2237
2238 EXPECT_GL_NO_ERROR();
2239
2240 drawQuad(mProgram, "position", 0.5f);
2241
2242 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2243}
2244
2245// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2246// have images defined.
2247TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
2248{
Olli Etuahoa314b612016-03-10 16:43:00 +02002249 glActiveTexture(GL_TEXTURE0);
2250 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
2251 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2252 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2253 texDataGreen.data());
2254 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2255 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2256 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2257 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2258
2259 EXPECT_GL_NO_ERROR();
2260
2261 drawQuad(mProgram, "position", 0.5f);
2262
2263 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2264}
2265
2266// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2267// dimensions that don't fit the images inside the range.
2268// GLES 3.0.4 section 3.8.13 Texture completeness
2269TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2270{
Corentin Wallez566c2e32019-08-28 18:37:58 +02002271 // TODO(crbug.com/998505): Test failing on Android FYI Release (NVIDIA Shield TV)
2272 ANGLE_SKIP_TEST_IF(IsNVIDIAShield());
2273
Olli Etuahoa314b612016-03-10 16:43:00 +02002274 glActiveTexture(GL_TEXTURE0);
2275 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
2276 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2277 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2278 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2279
2280 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2281 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2282
2283 // Two levels that are initially unused.
2284 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2285 texDataRed.data());
2286 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2287 texDataCyan.data());
2288
2289 // One level that is used - only this level should affect completeness.
2290 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2291 texDataGreen.data());
2292
2293 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2294 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2295
2296 EXPECT_GL_NO_ERROR();
2297
2298 drawQuad(mProgram, "position", 0.5f);
2299
2300 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2301
Yunchao He2f23f352018-02-11 22:11:37 +08002302 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
2303
Olli Etuahoa314b612016-03-10 16:43:00 +02002304 // Switch the level that is being used to the cyan level 2.
2305 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2306 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2307
2308 EXPECT_GL_NO_ERROR();
2309
2310 drawQuad(mProgram, "position", 0.5f);
2311
2312 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2313}
2314
2315// Test that texture completeness is updated if texture max level changes.
2316// GLES 3.0.4 section 3.8.13 Texture completeness
2317TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2318{
Olli Etuahoa314b612016-03-10 16:43:00 +02002319 glActiveTexture(GL_TEXTURE0);
2320 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2321 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2322
2323 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2324 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2325
2326 // A level that is initially unused.
2327 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2328 texDataGreen.data());
2329
2330 // One level that is initially used - only this level should affect completeness.
2331 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2332 texDataGreen.data());
2333
2334 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2335 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2336
2337 EXPECT_GL_NO_ERROR();
2338
2339 drawQuad(mProgram, "position", 0.5f);
2340
2341 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2342
2343 // Switch the max level to level 1. The levels within the used range now have inconsistent
2344 // dimensions and the texture should be incomplete.
2345 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2346
2347 EXPECT_GL_NO_ERROR();
2348
2349 drawQuad(mProgram, "position", 0.5f);
2350
2351 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2352}
2353
2354// Test that 3D texture completeness is updated if texture max level changes.
2355// GLES 3.0.4 section 3.8.13 Texture completeness
2356TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2357{
Olli Etuahoa314b612016-03-10 16:43:00 +02002358 glActiveTexture(GL_TEXTURE0);
2359 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2360 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2361
2362 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2363 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2364
2365 // A level that is initially unused.
2366 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2367 texDataGreen.data());
2368
2369 // One level that is initially used - only this level should affect completeness.
2370 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2371 texDataGreen.data());
2372
2373 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2374 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2375
2376 EXPECT_GL_NO_ERROR();
2377
2378 drawQuad(mProgram, "position", 0.5f);
2379
2380 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2381
2382 // Switch the max level to level 1. The levels within the used range now have inconsistent
2383 // dimensions and the texture should be incomplete.
2384 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2385
2386 EXPECT_GL_NO_ERROR();
2387
2388 drawQuad(mProgram, "position", 0.5f);
2389
2390 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2391}
2392
2393// Test that texture completeness is updated if texture base level changes.
2394// GLES 3.0.4 section 3.8.13 Texture completeness
2395TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2396{
Olli Etuahoa314b612016-03-10 16:43:00 +02002397 glActiveTexture(GL_TEXTURE0);
2398 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2399 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2400
2401 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2402 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2403
2404 // Two levels that are initially unused.
2405 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2406 texDataGreen.data());
2407 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2408 texDataGreen.data());
2409
2410 // One level that is initially used - only this level should affect completeness.
2411 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2412 texDataGreen.data());
2413
2414 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2415 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2416
2417 EXPECT_GL_NO_ERROR();
2418
2419 drawQuad(mProgram, "position", 0.5f);
2420
2421 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2422
2423 // Switch the base level to level 1. The levels within the used range now have inconsistent
2424 // dimensions and the texture should be incomplete.
2425 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2426
2427 EXPECT_GL_NO_ERROR();
2428
2429 drawQuad(mProgram, "position", 0.5f);
2430
2431 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2432}
2433
2434// Test that texture is not complete if base level is greater than max level.
2435// GLES 3.0.4 section 3.8.13 Texture completeness
2436TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2437{
Olli Etuahoa314b612016-03-10 16:43:00 +02002438 glActiveTexture(GL_TEXTURE0);
2439 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2440
2441 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2442 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2443
2444 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2445
2446 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2447 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2448
2449 EXPECT_GL_NO_ERROR();
2450
2451 drawQuad(mProgram, "position", 0.5f);
2452
2453 // Texture should be incomplete.
2454 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2455}
2456
2457// Test that immutable texture base level and max level are clamped.
2458// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2459TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2460{
Olli Etuahoa314b612016-03-10 16:43:00 +02002461 glActiveTexture(GL_TEXTURE0);
2462 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2463
2464 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2465 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2466
2467 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2468
2469 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2470
2471 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2472 // should be clamped to [base_level, levels - 1].
2473 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2474 // In the case of this test, those rules make the effective base level and max level 0.
2475 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2476 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2477
2478 EXPECT_GL_NO_ERROR();
2479
2480 drawQuad(mProgram, "position", 0.5f);
2481
2482 // Texture should be complete.
2483 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2484}
2485
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002486// Test that changing base level works when it affects the format of the texture.
2487TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2488{
Corentin Wallez7f00d332019-08-28 15:19:16 +02002489 // TODO(crbug.com/998505): Test failing on Android FYI Release (NVIDIA Shield TV)
2490 ANGLE_SKIP_TEST_IF(IsNVIDIAShield());
2491
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002492 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002493
2494 // Observed incorrect rendering on AMD OpenGL.
2495 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002496
2497 glActiveTexture(GL_TEXTURE0);
2498 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2499 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2500 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2501
2502 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2503 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2504
2505 // RGBA8 level that's initially unused.
2506 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2507 texDataCyan.data());
2508
2509 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2510 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2511
2512 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2513 // format. It reads green channel data from the green and alpha channels of texDataGreen
2514 // (this is a bit hacky but works).
2515 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2516
2517 EXPECT_GL_NO_ERROR();
2518
2519 drawQuad(mProgram, "position", 0.5f);
2520
2521 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2522
2523 // Switch the texture to use the cyan level 0 with the RGBA format.
2524 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2525 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2526
2527 EXPECT_GL_NO_ERROR();
2528
2529 drawQuad(mProgram, "position", 0.5f);
2530
2531 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2532}
2533
Olli Etuahoa314b612016-03-10 16:43:00 +02002534// Test that setting a texture image works when base level is out of range.
2535TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2536{
2537 glActiveTexture(GL_TEXTURE0);
2538 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2539
2540 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2541 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2542
2543 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2544 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2545
2546 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2547
2548 EXPECT_GL_NO_ERROR();
2549
2550 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2551
2552 drawQuad(mProgram, "position", 0.5f);
2553
2554 // Texture should be complete.
2555 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002556}
2557
Jamie Madill50cf2be2018-06-15 09:46:57 -04002558// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG
2559// RBA->RGBA8, with 1.0 in the alpha channel. This test covers a bug where redefining array textures
2560// with these formats does not work as expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002561TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002562{
2563 std::vector<GLubyte> pixelData;
2564 for (size_t count = 0; count < 5000; count++)
2565 {
2566 pixelData.push_back(0u);
2567 pixelData.push_back(255u);
2568 pixelData.push_back(0u);
2569 }
2570
2571 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002572 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002573 glUniform1i(mTextureArrayLocation, 0);
2574
2575 // The first draw worked correctly.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002576 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2577 &pixelData[0]);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002578
2579 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2580 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2581 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2582 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002583 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002584 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002585
2586 // The dimension of the respecification must match the original exactly to trigger the bug.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002587 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2588 &pixelData[0]);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002589 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002590 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002591
2592 ASSERT_GL_NO_ERROR();
2593}
2594
Olli Etuaho1a679902016-01-14 12:21:47 +02002595// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2596// This test is needed especially to confirm that sampler registers get assigned correctly on
2597// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2598TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2599{
2600 glActiveTexture(GL_TEXTURE0);
2601 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2602 GLubyte texData[4];
2603 texData[0] = 0;
2604 texData[1] = 60;
2605 texData[2] = 0;
2606 texData[3] = 255;
2607 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2608
2609 glActiveTexture(GL_TEXTURE1);
2610 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2611 GLfloat depthTexData[1];
2612 depthTexData[0] = 0.5f;
2613 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2614 depthTexData);
2615
2616 glUseProgram(mProgram);
2617 glUniform1f(mDepthRefUniformLocation, 0.3f);
2618 glUniform1i(mTexture3DUniformLocation, 0);
2619 glUniform1i(mTextureShadowUniformLocation, 1);
2620
2621 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2622 drawQuad(mProgram, "position", 0.5f);
2623 EXPECT_GL_NO_ERROR();
2624 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2625 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2626
2627 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2628 drawQuad(mProgram, "position", 0.5f);
2629 EXPECT_GL_NO_ERROR();
2630 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2631 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2632}
2633
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002634// Test multiple different sampler types in the same shader.
2635// This test makes sure that even if sampler / texture registers get grouped together based on type
2636// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2637// still has the right register index information for each ESSL sampler.
2638// The tested ESSL samplers have the following types in D3D11 HLSL:
2639// sampler2D: Texture2D + SamplerState
2640// samplerCube: TextureCube + SamplerState
2641// sampler2DShadow: Texture2D + SamplerComparisonState
2642// samplerCubeShadow: TextureCube + SamplerComparisonState
2643TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2644{
2645 glActiveTexture(GL_TEXTURE0);
2646 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2647 GLubyte texData[4];
2648 texData[0] = 0;
2649 texData[1] = 0;
2650 texData[2] = 120;
2651 texData[3] = 255;
2652 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2653
2654 glActiveTexture(GL_TEXTURE1);
2655 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2656 texData[0] = 0;
2657 texData[1] = 90;
2658 texData[2] = 0;
2659 texData[3] = 255;
2660 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2661 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2662 texData);
2663
2664 glActiveTexture(GL_TEXTURE2);
2665 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2666 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2667 GLfloat depthTexData[1];
2668 depthTexData[0] = 0.5f;
2669 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2670 depthTexData);
2671
2672 glActiveTexture(GL_TEXTURE3);
2673 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2674 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2675 depthTexData[0] = 0.2f;
2676 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2677 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2678 depthTexData);
2679
2680 EXPECT_GL_NO_ERROR();
2681
2682 glUseProgram(mProgram);
2683 glUniform1f(mDepthRefUniformLocation, 0.3f);
2684 glUniform1i(mTexture2DUniformLocation, 0);
2685 glUniform1i(mTextureCubeUniformLocation, 1);
2686 glUniform1i(mTexture2DShadowUniformLocation, 2);
2687 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2688
2689 drawQuad(mProgram, "position", 0.5f);
2690 EXPECT_GL_NO_ERROR();
2691 // The shader writes:
2692 // <texture 2d color> +
2693 // <cube map color> +
2694 // 0.25 * <comparison result (1.0)> +
2695 // 0.125 * <comparison result (0.0)>
2696 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2697}
2698
Olli Etuahobce743a2016-01-15 17:18:28 +02002699// Test different base levels on textures accessed through the same sampler array.
2700// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2701TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2702{
Yunchao He9550c602018-02-13 14:47:05 +08002703 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2704
Olli Etuahobce743a2016-01-15 17:18:28 +02002705 glActiveTexture(GL_TEXTURE0);
2706 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2707 GLsizei size = 64;
2708 for (GLint level = 0; level < 7; ++level)
2709 {
2710 ASSERT_LT(0, size);
2711 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2712 nullptr);
2713 size = size / 2;
2714 }
2715 ASSERT_EQ(0, size);
2716 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2717
2718 glActiveTexture(GL_TEXTURE1);
2719 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2720 size = 128;
2721 for (GLint level = 0; level < 8; ++level)
2722 {
2723 ASSERT_LT(0, size);
2724 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2725 nullptr);
2726 size = size / 2;
2727 }
2728 ASSERT_EQ(0, size);
2729 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2730 EXPECT_GL_NO_ERROR();
2731
2732 glUseProgram(mProgram);
2733 glUniform1i(mTexture0Location, 0);
2734 glUniform1i(mTexture1Location, 1);
2735
Olli Etuaho5804dc82018-04-13 14:11:46 +03002736 drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
Olli Etuahobce743a2016-01-15 17:18:28 +02002737 EXPECT_GL_NO_ERROR();
2738 // Red channel: width of level 1 of texture A: 32.
2739 // Green channel: width of level 3 of texture B: 16.
2740 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2741}
2742
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002743// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2744// ES 3.0.4 table 3.24
2745TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2746{
2747 glActiveTexture(GL_TEXTURE0);
2748 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2749 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2750 EXPECT_GL_NO_ERROR();
2751
2752 drawQuad(mProgram, "position", 0.5f);
2753
2754 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2755}
2756
2757// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2758// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002759TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002760{
Luc Ferron5164b792018-03-06 09:10:12 -05002761 setUpProgram();
2762
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002763 glActiveTexture(GL_TEXTURE0);
2764 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2765 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2766 EXPECT_GL_NO_ERROR();
2767
2768 drawQuad(mProgram, "position", 0.5f);
2769
2770 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2771}
2772
Luc Ferron5164b792018-03-06 09:10:12 -05002773// Validate that every component of the pixel will be equal to the luminance value we've set
2774// and that the alpha channel will be 1 (or 255 to be exact).
2775TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2776{
2777 setUpProgram();
2778
2779 glActiveTexture(GL_TEXTURE0);
2780 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2781 uint8_t pixel = 50;
2782 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2783 EXPECT_GL_NO_ERROR();
2784
2785 drawQuad(mProgram, "position", 0.5f);
2786
2787 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2788}
2789
2790// Validate that every component of the pixel will be equal to the luminance value we've set
2791// and that the alpha channel will be the second component.
2792TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2793{
2794 setUpProgram();
2795
2796 glActiveTexture(GL_TEXTURE0);
2797 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2798 uint8_t pixel[] = {50, 25};
2799 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2800 GL_UNSIGNED_BYTE, pixel);
2801 EXPECT_GL_NO_ERROR();
2802
2803 drawQuad(mProgram, "position", 0.5f);
2804
2805 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2806}
2807
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002808// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2809// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002810TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002811{
Jamie Madillb8149072019-04-30 16:14:44 -04002812 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002813 ANGLE_SKIP_TEST_IF(IsD3D9());
2814 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002815
2816 setUpProgram();
2817
Luc Ferrond8c632c2018-04-10 12:31:44 -04002818 glActiveTexture(GL_TEXTURE0);
2819 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2820 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2821 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002822
Luc Ferrond8c632c2018-04-10 12:31:44 -04002823 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002824
Luc Ferrond8c632c2018-04-10 12:31:44 -04002825 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002826}
2827
2828// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2829// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002830TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002831{
Jamie Madillb8149072019-04-30 16:14:44 -04002832 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002833 ANGLE_SKIP_TEST_IF(IsD3D9());
2834 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferrond8c632c2018-04-10 12:31:44 -04002835 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2836 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002837
Luc Ferrond8c632c2018-04-10 12:31:44 -04002838 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002839
Luc Ferrond8c632c2018-04-10 12:31:44 -04002840 glActiveTexture(GL_TEXTURE0);
2841 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2842 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2843 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002844
Luc Ferrond8c632c2018-04-10 12:31:44 -04002845 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002846
Luc Ferrond8c632c2018-04-10 12:31:44 -04002847 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002848}
2849
2850// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2851// ES 3.0.4 table 3.24
2852TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2853{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002854 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2855
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002856 glActiveTexture(GL_TEXTURE0);
2857 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2858 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2859 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2860 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2861 EXPECT_GL_NO_ERROR();
2862
2863 drawQuad(mProgram, "position", 0.5f);
2864
2865 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2866}
2867
2868// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2869// ES 3.0.4 table 3.24
2870TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2871{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002872 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2873
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002874 glActiveTexture(GL_TEXTURE0);
2875 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2876
2877 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2878 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2879 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2880 EXPECT_GL_NO_ERROR();
2881
2882 drawQuad(mProgram, "position", 0.5f);
2883
2884 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2885}
2886
2887// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2888// ES 3.0.4 table 3.24
2889TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2890{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002891 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2892
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002893 glActiveTexture(GL_TEXTURE0);
2894 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2895 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2896 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2897 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2898 EXPECT_GL_NO_ERROR();
2899
2900 drawQuad(mProgram, "position", 0.5f);
2901
2902 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2903}
2904
2905// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2906// ES 3.0.4 table 3.24
2907TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2908{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002909 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2910
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002911 glActiveTexture(GL_TEXTURE0);
2912 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2913 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2914 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2915 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2916 EXPECT_GL_NO_ERROR();
2917
2918 drawQuad(mProgram, "position", 0.5f);
2919
2920 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2921}
2922
2923// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2924// ES 3.0.4 table 3.24
2925TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2926{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002927 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2928
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002929 glActiveTexture(GL_TEXTURE0);
2930 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2931 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2932 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2933 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2934 EXPECT_GL_NO_ERROR();
2935
2936 drawQuad(mProgram, "position", 0.5f);
2937
2938 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2939}
2940
2941// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2942// ES 3.0.4 table 3.24
2943TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2944{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002945 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2946
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002947 glActiveTexture(GL_TEXTURE0);
2948 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2949 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2950 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2951 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2952 EXPECT_GL_NO_ERROR();
2953
2954 drawQuad(mProgram, "position", 0.5f);
2955
2956 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2957}
2958
2959// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2960// ES 3.0.4 table 3.24
2961TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2962{
2963 glActiveTexture(GL_TEXTURE0);
2964 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2965 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2966 EXPECT_GL_NO_ERROR();
2967
2968 drawQuad(mProgram, "position", 0.5f);
2969
2970 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2971}
2972
2973// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2974// ES 3.0.4 table 3.24
2975TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2976{
2977 glActiveTexture(GL_TEXTURE0);
2978 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2979 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2980 nullptr);
2981 EXPECT_GL_NO_ERROR();
2982
2983 drawQuad(mProgram, "position", 0.5f);
2984
2985 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2986}
2987
2988// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2989// ES 3.0.4 table 3.24
2990TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2991{
Geoff Lang2a19c592019-08-23 14:10:24 -04002992 // ETC texture formats are not supported on Mac OpenGL. http://anglebug.com/3853
2993 ANGLE_SKIP_TEST_IF(IsOSX() && IsDesktopOpenGL());
Yuly Novikov49886892018-01-23 21:18:27 -05002994
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002995 glActiveTexture(GL_TEXTURE0);
2996 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2997 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2998 EXPECT_GL_NO_ERROR();
2999
3000 drawQuad(mProgram, "position", 0.5f);
3001
3002 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
3003}
3004
3005// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
3006// ES 3.0.4 table 3.24
3007TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
3008{
Geoff Lang2a19c592019-08-23 14:10:24 -04003009 // ETC texture formats are not supported on Mac OpenGL. http://anglebug.com/3853
3010 ANGLE_SKIP_TEST_IF(IsOSX() && IsDesktopOpenGL());
Yuly Novikov49886892018-01-23 21:18:27 -05003011
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003012 glActiveTexture(GL_TEXTURE0);
3013 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3014 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
3015 EXPECT_GL_NO_ERROR();
3016
3017 drawQuad(mProgram, "position", 0.5f);
3018
3019 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
3020}
3021
Olli Etuaho96963162016-03-21 11:54:33 +02003022// Use a sampler in a uniform struct.
3023TEST_P(SamplerInStructTest, SamplerInStruct)
3024{
3025 runSamplerInStructTest();
3026}
3027
3028// Use a sampler in a uniform struct that's passed as a function parameter.
3029TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
3030{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003031 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
3032 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04003033
Olli Etuaho96963162016-03-21 11:54:33 +02003034 runSamplerInStructTest();
3035}
3036
3037// Use a sampler in a uniform struct array with a struct from the array passed as a function
3038// parameter.
3039TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
3040{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003041 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
3042 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08003043
Olli Etuaho96963162016-03-21 11:54:33 +02003044 runSamplerInStructTest();
3045}
3046
3047// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
3048// parameter.
3049TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
3050{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003051 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
3052 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08003053
Olli Etuaho96963162016-03-21 11:54:33 +02003054 runSamplerInStructTest();
3055}
3056
3057// Make sure that there isn't a name conflict between sampler extracted from a struct and a
3058// similarly named uniform.
3059TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
3060{
3061 runSamplerInStructTest();
3062}
3063
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05003064// GL_EXT_texture_filter_anisotropic
3065class TextureAnisotropyTest : public Texture2DTest
3066{
3067 protected:
3068 void uploadTexture()
3069 {
3070 glActiveTexture(GL_TEXTURE0);
3071 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3072 GLColor texDataRed[1] = {GLColor::red};
3073 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed);
3074 EXPECT_GL_NO_ERROR();
3075 }
3076};
3077
3078// Tests that setting anisotropic filtering doesn't cause failures at draw time.
3079TEST_P(TextureAnisotropyTest, AnisotropyFunctional)
3080{
Jamie Madillb8149072019-04-30 16:14:44 -04003081 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_filter_anisotropic"));
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05003082
3083 setUpProgram();
3084
3085 uploadTexture();
3086
3087 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3088 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3089 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f);
3090 EXPECT_GL_NO_ERROR();
3091
3092 drawQuad(mProgram, "position", 0.5f);
3093
3094 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3095 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3096 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::red);
3097}
3098
Till Rathmannb8543632018-10-02 19:46:14 +02003099// GL_OES_texture_border_clamp
3100class TextureBorderClampTest : public Texture2DTest
3101{
3102 protected:
3103 TextureBorderClampTest() : Texture2DTest() {}
3104
Jamie Madill35cd7332018-12-02 12:03:33 -05003105 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003106 {
3107 return
3108 R"(precision highp float;
3109 attribute vec4 position;
3110 varying vec2 texcoord;
3111
3112 void main()
3113 {
3114 gl_Position = vec4(position.xy, 0.0, 1.0);
3115 // texcoords in [-0.5, 1.5]
3116 texcoord = (position.xy) + 0.5;
3117 })";
3118 }
3119
3120 void uploadTexture()
3121 {
3122 glActiveTexture(GL_TEXTURE0);
3123 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3124 std::vector<GLColor> texDataRed(1, GLColor::red);
3125 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3126 texDataRed.data());
3127 EXPECT_GL_NO_ERROR();
3128 }
3129};
3130
3131// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3132// GL_CLAMP_TO_BORDER wrap mode (set with glTexParameter).
3133TEST_P(TextureBorderClampTest, TextureBorderClampFunctional)
3134{
Jamie Madillb8149072019-04-30 16:14:44 -04003135 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003136
3137 setUpProgram();
3138
3139 uploadTexture();
3140
3141 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3142 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3143 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3144 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3145 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3146 EXPECT_GL_NO_ERROR();
3147
3148 drawQuad(mProgram, "position", 0.5f);
3149
3150 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3151 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3152 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3153}
3154
3155// Test reading back GL_TEXTURE_BORDER_COLOR by glGetTexParameter.
3156TEST_P(TextureBorderClampTest, TextureBorderClampFunctional2)
3157{
Jamie Madillb8149072019-04-30 16:14:44 -04003158 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003159
3160 glActiveTexture(GL_TEXTURE0);
3161 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3162
3163 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3164
3165 GLint colorFixedPoint[4] = {0};
3166 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3167 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3168 std::numeric_limits<GLint>::max()};
3169 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3170 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3171 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3172 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3173
3174 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3175 std::numeric_limits<GLint>::max()};
3176 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3177
3178 GLfloat color[4] = {0.0f};
3179 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
3180 EXPECT_EQ(color[0], kFloatBlue.R);
3181 EXPECT_EQ(color[1], kFloatBlue.G);
3182 EXPECT_EQ(color[2], kFloatBlue.B);
3183 EXPECT_EQ(color[3], kFloatBlue.A);
3184}
3185
3186// Test GL_TEXTURE_BORDER_COLOR parameter validation at glTexParameter.
3187TEST_P(TextureBorderClampTest, TextureBorderClampValidation)
3188{
Jamie Madillb8149072019-04-30 16:14:44 -04003189 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003190
3191 glActiveTexture(GL_TEXTURE0);
3192 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3193
3194 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, 1.0f);
3195 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3196
3197 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3198 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3199
3200 glTexParameterfv(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3201 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3202
3203 GLint colorInt[4] = {0};
3204 glTexParameteriv(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_BORDER_COLOR, colorInt);
3205 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3206
3207 if (getClientMajorVersion() < 3)
3208 {
3209 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3210 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3211 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3212 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3213
3214 GLuint colorUInt[4] = {0};
3215 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3216 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3217 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3218 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3219
3220 GLSampler sampler;
3221 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3222 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3223 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3224 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3225
3226 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3227 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3228 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3229 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3230 }
3231}
3232
3233class TextureBorderClampTestES3 : public TextureBorderClampTest
3234{
3235 protected:
3236 TextureBorderClampTestES3() : TextureBorderClampTest() {}
3237};
3238
3239// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3240// GL_CLAMP_TO_BORDER wrap mode (set with glSamplerParameter).
3241TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional)
3242{
Jamie Madillb8149072019-04-30 16:14:44 -04003243 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003244
3245 setUpProgram();
3246
3247 uploadTexture();
3248
3249 GLSampler sampler;
3250 glBindSampler(0, sampler);
3251 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3252 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3253 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3254 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3255 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3256 EXPECT_GL_NO_ERROR();
3257
3258 drawQuad(mProgram, "position", 0.5f);
3259
3260 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3261 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3262 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3263}
3264
3265// Test reading back GL_TEXTURE_BORDER_COLOR by glGetSamplerParameter.
3266TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional2)
3267{
Jamie Madillb8149072019-04-30 16:14:44 -04003268 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003269
3270 glActiveTexture(GL_TEXTURE0);
3271
3272 GLSampler sampler;
3273 glBindSampler(0, sampler);
3274
3275 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3276
3277 GLint colorFixedPoint[4] = {0};
3278 glGetSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3279 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3280 std::numeric_limits<GLint>::max()};
3281 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3282 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3283 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3284 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3285
3286 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3287 std::numeric_limits<GLint>::max()};
3288 glSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3289
3290 GLfloat color[4] = {0.0f};
3291 glGetSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, color);
3292 EXPECT_EQ(color[0], kFloatBlue.R);
3293 EXPECT_EQ(color[1], kFloatBlue.G);
3294 EXPECT_EQ(color[2], kFloatBlue.B);
3295 EXPECT_EQ(color[3], kFloatBlue.A);
3296
3297 constexpr GLint colorSomewhatRedInt[4] = {500000, 0, 0, std::numeric_limits<GLint>::max()};
3298 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedInt);
3299 GLint colorInt[4] = {0};
3300 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3301 EXPECT_EQ(colorInt[0], colorSomewhatRedInt[0]);
3302 EXPECT_EQ(colorInt[1], colorSomewhatRedInt[1]);
3303 EXPECT_EQ(colorInt[2], colorSomewhatRedInt[2]);
3304 EXPECT_EQ(colorInt[3], colorSomewhatRedInt[3]);
3305
3306 constexpr GLuint colorSomewhatRedUInt[4] = {500000, 0, 0, std::numeric_limits<GLuint>::max()};
3307 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedUInt);
3308 GLuint colorUInt[4] = {0};
3309 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3310 EXPECT_EQ(colorUInt[0], colorSomewhatRedUInt[0]);
3311 EXPECT_EQ(colorUInt[1], colorSomewhatRedUInt[1]);
3312 EXPECT_EQ(colorUInt[2], colorSomewhatRedUInt[2]);
3313 EXPECT_EQ(colorUInt[3], colorSomewhatRedUInt[3]);
3314
3315 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3316
3317 constexpr GLint colorSomewhatGreenInt[4] = {0, 500000, 0, std::numeric_limits<GLint>::max()};
3318 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenInt);
3319 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3320 EXPECT_EQ(colorInt[0], colorSomewhatGreenInt[0]);
3321 EXPECT_EQ(colorInt[1], colorSomewhatGreenInt[1]);
3322 EXPECT_EQ(colorInt[2], colorSomewhatGreenInt[2]);
3323 EXPECT_EQ(colorInt[3], colorSomewhatGreenInt[3]);
3324
3325 constexpr GLuint colorSomewhatGreenUInt[4] = {0, 500000, 0, std::numeric_limits<GLuint>::max()};
3326 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenUInt);
3327 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3328 EXPECT_EQ(colorUInt[0], colorSomewhatGreenUInt[0]);
3329 EXPECT_EQ(colorUInt[1], colorSomewhatGreenUInt[1]);
3330 EXPECT_EQ(colorUInt[2], colorSomewhatGreenUInt[2]);
3331 EXPECT_EQ(colorUInt[3], colorSomewhatGreenUInt[3]);
3332}
3333
3334// Test GL_TEXTURE_BORDER_COLOR parameter validation at glSamplerParameter.
3335TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Validation)
3336{
Jamie Madillb8149072019-04-30 16:14:44 -04003337 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003338
3339 glActiveTexture(GL_TEXTURE0);
3340
3341 GLSampler sampler;
3342 glBindSampler(0, sampler);
3343
3344 glSamplerParameterf(sampler, GL_TEXTURE_BORDER_COLOR, 1.0f);
3345 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3346
3347 glSamplerParameteri(sampler, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3348 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3349}
3350
3351class TextureBorderClampIntegerTestES3 : public Texture2DTest
3352{
3353 protected:
3354 TextureBorderClampIntegerTestES3() : Texture2DTest(), isUnsignedIntTest(false) {}
3355
Jamie Madill35cd7332018-12-02 12:03:33 -05003356 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003357 {
3358 return
3359 R"(#version 300 es
3360 out vec2 texcoord;
3361 in vec4 position;
3362
3363 void main()
3364 {
3365 gl_Position = vec4(position.xy, 0.0, 1.0);
3366 // texcoords in [-0.5, 1.5]
3367 texcoord = (position.xy) + 0.5;
3368 })";
3369 }
3370
Jamie Madillba319ba2018-12-29 10:29:33 -05003371 const char *getFragmentShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003372 {
Jamie Madill35cd7332018-12-02 12:03:33 -05003373 if (isUnsignedIntTest)
3374 {
3375 return "#version 300 es\n"
3376 "precision highp float;\n"
3377 "uniform highp usampler2D tex;\n"
3378 "in vec2 texcoord;\n"
3379 "out vec4 fragColor;\n"
Till Rathmannb8543632018-10-02 19:46:14 +02003380
Jamie Madill35cd7332018-12-02 12:03:33 -05003381 "void main()\n"
3382 "{\n"
3383 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3384 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3385 "fragColor = (texture(tex, texcoord).r == 150u)"
3386 " ? green : red;\n"
3387 "}\n";
3388 }
3389 else
3390 {
3391 return "#version 300 es\n"
3392 "precision highp float;\n"
3393 "uniform highp isampler2D tex;\n"
3394 "in vec2 texcoord;\n"
3395 "out vec4 fragColor;\n"
3396
3397 "void main()\n"
3398 "{\n"
3399 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3400 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3401 "fragColor = (texture(tex, texcoord).r == -50)"
3402 " ? green : red;\n"
3403 "}\n";
3404 }
Till Rathmannb8543632018-10-02 19:46:14 +02003405 }
3406
3407 void uploadTexture()
3408 {
3409 glActiveTexture(GL_TEXTURE0);
3410 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3411 if (isUnsignedIntTest)
3412 {
3413 std::vector<GLubyte> texData(4, 100);
3414 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE,
3415 texData.data());
3416 }
3417 else
3418 {
3419 std::vector<GLbyte> texData(4, 100);
3420 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8I, 1, 1, 0, GL_RGBA_INTEGER, GL_BYTE,
3421 texData.data());
3422 }
3423 EXPECT_GL_NO_ERROR();
3424 }
3425
3426 bool isUnsignedIntTest;
3427};
3428
3429// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3430// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3431TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger)
3432{
Yuly Novikov1dbbc7b2019-07-31 17:49:39 -04003433 // Fails on Win10 FYI x64 Release (AMD RX 550). http://anglebug.com/3760
3434 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsDesktopOpenGL());
3435
Jamie Madillb8149072019-04-30 16:14:44 -04003436 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003437
3438 setUpProgram();
3439
3440 uploadTexture();
3441
3442 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3443 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3444 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3445 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3446
3447 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3448 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3449
3450 EXPECT_GL_NO_ERROR();
3451
3452 drawQuad(mProgram, "position", 0.5f);
3453
3454 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3455 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3456 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3457}
3458
3459// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3460// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3461TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger2)
3462{
Yuly Novikov1dbbc7b2019-07-31 17:49:39 -04003463 // Fails on Win10 FYI x64 Release (AMD RX 550). http://anglebug.com/3760
3464 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsDesktopOpenGL());
3465
Jamie Madillb8149072019-04-30 16:14:44 -04003466 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003467
3468 setUpProgram();
3469
3470 uploadTexture();
3471
3472 GLSampler sampler;
3473 glBindSampler(0, sampler);
3474 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3475 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3476 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3477 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3478
3479 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3480 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3481
3482 EXPECT_GL_NO_ERROR();
3483
3484 drawQuad(mProgram, "position", 0.5f);
3485
3486 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3487 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3488 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3489}
3490
3491// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3492// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIuivOES).
3493TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned)
3494{
Jamie Madillb8149072019-04-30 16:14:44 -04003495 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003496
3497 isUnsignedIntTest = true;
3498
3499 setUpProgram();
3500
3501 uploadTexture();
3502
3503 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3504 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3505 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3506 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3507
3508 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3509 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3510
3511 EXPECT_GL_NO_ERROR();
3512
3513 drawQuad(mProgram, "position", 0.5f);
3514
3515 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3516 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3517 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3518}
3519
3520// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3521// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with
3522// glSamplerParameterIuivOES).
3523TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned2)
3524{
Jamie Madillb8149072019-04-30 16:14:44 -04003525 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003526
3527 isUnsignedIntTest = true;
3528
3529 setUpProgram();
3530
3531 uploadTexture();
3532
3533 GLSampler sampler;
3534 glBindSampler(0, sampler);
3535 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3536 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3537 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3538 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3539
3540 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3541 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3542
3543 EXPECT_GL_NO_ERROR();
3544
3545 drawQuad(mProgram, "position", 0.5f);
3546
3547 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3548 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3549 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3550}
3551
3552// ~GL_OES_texture_border_clamp
3553
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003554class TextureLimitsTest : public ANGLETest
3555{
3556 protected:
3557 struct RGBA8
3558 {
3559 uint8_t R, G, B, A;
3560 };
3561
3562 TextureLimitsTest()
3563 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
3564 {
3565 setWindowWidth(128);
3566 setWindowHeight(128);
3567 setConfigRedBits(8);
3568 setConfigGreenBits(8);
3569 setConfigBlueBits(8);
3570 setConfigAlphaBits(8);
3571 }
3572
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003573 void testSetUp() override
Jamie Madill0fdb9562018-09-17 17:18:43 -04003574 {
Jamie Madill0fdb9562018-09-17 17:18:43 -04003575 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
3576 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
3577 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
3578
3579 ASSERT_GL_NO_ERROR();
3580 }
3581
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003582 void testTearDown() override
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003583 {
3584 if (mProgram != 0)
3585 {
3586 glDeleteProgram(mProgram);
3587 mProgram = 0;
3588
3589 if (!mTextures.empty())
3590 {
3591 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
3592 }
3593 }
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003594 }
3595
3596 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
3597 GLint vertexTextureCount,
3598 GLint vertexActiveTextureCount,
3599 const std::string &fragPrefix,
3600 GLint fragmentTextureCount,
3601 GLint fragmentActiveTextureCount)
3602 {
3603 std::stringstream vertexShaderStr;
3604 vertexShaderStr << "attribute vec2 position;\n"
3605 << "varying vec4 color;\n"
3606 << "varying vec2 texCoord;\n";
3607
3608 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
3609 {
3610 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
3611 }
3612
3613 vertexShaderStr << "void main() {\n"
3614 << " gl_Position = vec4(position, 0, 1);\n"
3615 << " texCoord = (position * 0.5) + 0.5;\n"
3616 << " color = vec4(0);\n";
3617
3618 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
3619 {
3620 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
3621 << ", texCoord);\n";
3622 }
3623
3624 vertexShaderStr << "}";
3625
3626 std::stringstream fragmentShaderStr;
3627 fragmentShaderStr << "varying mediump vec4 color;\n"
3628 << "varying mediump vec2 texCoord;\n";
3629
3630 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
3631 {
3632 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
3633 }
3634
3635 fragmentShaderStr << "void main() {\n"
3636 << " gl_FragColor = color;\n";
3637
3638 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
3639 {
3640 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
3641 << ", texCoord);\n";
3642 }
3643
3644 fragmentShaderStr << "}";
3645
3646 const std::string &vertexShaderSource = vertexShaderStr.str();
3647 const std::string &fragmentShaderSource = fragmentShaderStr.str();
3648
Jamie Madill35cd7332018-12-02 12:03:33 -05003649 mProgram = CompileProgram(vertexShaderSource.c_str(), fragmentShaderSource.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003650 }
3651
3652 RGBA8 getPixel(GLint texIndex)
3653 {
3654 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3655 0, 255u};
3656 return pixel;
3657 }
3658
3659 void initTextures(GLint tex2DCount, GLint texCubeCount)
3660 {
3661 GLint totalCount = tex2DCount + texCubeCount;
3662 mTextures.assign(totalCount, 0);
3663 glGenTextures(totalCount, &mTextures[0]);
3664 ASSERT_GL_NO_ERROR();
3665
3666 std::vector<RGBA8> texData(16 * 16);
3667
3668 GLint texIndex = 0;
3669 for (; texIndex < tex2DCount; ++texIndex)
3670 {
3671 texData.assign(texData.size(), getPixel(texIndex));
3672 glActiveTexture(GL_TEXTURE0 + texIndex);
3673 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3674 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3675 &texData[0]);
3676 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3677 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3678 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3679 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3680 }
3681
3682 ASSERT_GL_NO_ERROR();
3683
3684 for (; texIndex < texCubeCount; ++texIndex)
3685 {
3686 texData.assign(texData.size(), getPixel(texIndex));
3687 glActiveTexture(GL_TEXTURE0 + texIndex);
3688 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3689 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3690 GL_UNSIGNED_BYTE, &texData[0]);
3691 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3692 GL_UNSIGNED_BYTE, &texData[0]);
3693 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3694 GL_UNSIGNED_BYTE, &texData[0]);
3695 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3696 GL_UNSIGNED_BYTE, &texData[0]);
3697 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3698 GL_UNSIGNED_BYTE, &texData[0]);
3699 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3700 GL_UNSIGNED_BYTE, &texData[0]);
3701 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3702 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3703 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3704 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3705 }
3706
3707 ASSERT_GL_NO_ERROR();
3708 }
3709
3710 void testWithTextures(GLint vertexTextureCount,
3711 const std::string &vertexTexturePrefix,
3712 GLint fragmentTextureCount,
3713 const std::string &fragmentTexturePrefix)
3714 {
3715 // Generate textures
3716 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3717
3718 glUseProgram(mProgram);
3719 RGBA8 expectedSum = {0};
3720 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3721 {
3722 std::stringstream uniformNameStr;
3723 uniformNameStr << vertexTexturePrefix << texIndex;
3724 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003725 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003726 ASSERT_NE(-1, location);
3727
3728 glUniform1i(location, texIndex);
3729 RGBA8 contribution = getPixel(texIndex);
3730 expectedSum.R += contribution.R;
3731 expectedSum.G += contribution.G;
3732 }
3733
3734 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3735 {
3736 std::stringstream uniformNameStr;
3737 uniformNameStr << fragmentTexturePrefix << texIndex;
3738 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003739 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003740 ASSERT_NE(-1, location);
3741
3742 glUniform1i(location, texIndex + vertexTextureCount);
3743 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3744 expectedSum.R += contribution.R;
3745 expectedSum.G += contribution.G;
3746 }
3747
3748 ASSERT_GE(256u, expectedSum.G);
3749
3750 drawQuad(mProgram, "position", 0.5f);
3751 ASSERT_GL_NO_ERROR();
3752 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3753 }
3754
3755 GLuint mProgram;
3756 std::vector<GLuint> mTextures;
3757 GLint mMaxVertexTextures;
3758 GLint mMaxFragmentTextures;
3759 GLint mMaxCombinedTextures;
3760};
3761
3762// Test rendering with the maximum vertex texture units.
3763TEST_P(TextureLimitsTest, MaxVertexTextures)
3764{
3765 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3766 ASSERT_NE(0u, mProgram);
3767 ASSERT_GL_NO_ERROR();
3768
3769 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3770}
3771
3772// Test rendering with the maximum fragment texture units.
3773TEST_P(TextureLimitsTest, MaxFragmentTextures)
3774{
3775 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3776 ASSERT_NE(0u, mProgram);
3777 ASSERT_GL_NO_ERROR();
3778
3779 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3780}
3781
3782// Test rendering with maximum combined texture units.
3783TEST_P(TextureLimitsTest, MaxCombinedTextures)
3784{
3785 GLint vertexTextures = mMaxVertexTextures;
3786
3787 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3788 {
3789 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3790 }
3791
3792 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3793 mMaxFragmentTextures, mMaxFragmentTextures);
3794 ASSERT_NE(0u, mProgram);
3795 ASSERT_GL_NO_ERROR();
3796
3797 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3798}
3799
3800// Negative test for exceeding the number of vertex textures
3801TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3802{
3803 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3804 0);
3805 ASSERT_EQ(0u, mProgram);
3806}
3807
3808// Negative test for exceeding the number of fragment textures
3809TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3810{
3811 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3812 mMaxFragmentTextures + 1);
3813 ASSERT_EQ(0u, mProgram);
3814}
3815
3816// Test active vertex textures under the limit, but excessive textures specified.
3817TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3818{
3819 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3820 ASSERT_NE(0u, mProgram);
3821 ASSERT_GL_NO_ERROR();
3822
3823 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3824}
3825
3826// Test active fragment textures under the limit, but excessive textures specified.
3827TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3828{
3829 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3830 mMaxFragmentTextures);
3831 ASSERT_NE(0u, mProgram);
3832 ASSERT_GL_NO_ERROR();
3833
3834 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3835}
3836
3837// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003838// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003839TEST_P(TextureLimitsTest, TextureTypeConflict)
3840{
Jamie Madill35cd7332018-12-02 12:03:33 -05003841 constexpr char kVS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003842 "attribute vec2 position;\n"
3843 "varying float color;\n"
3844 "uniform sampler2D tex2D;\n"
3845 "uniform samplerCube texCube;\n"
3846 "void main() {\n"
3847 " gl_Position = vec4(position, 0, 1);\n"
3848 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3849 " color = texture2D(tex2D, texCoord).x;\n"
3850 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3851 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05003852 constexpr char kFS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003853 "varying mediump float color;\n"
3854 "void main() {\n"
3855 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3856 "}";
3857
Jamie Madill35cd7332018-12-02 12:03:33 -05003858 mProgram = CompileProgram(kVS, kFS);
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003859 ASSERT_NE(0u, mProgram);
3860
3861 initTextures(1, 0);
3862
3863 glUseProgram(mProgram);
3864 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3865 ASSERT_NE(-1, tex2DLocation);
3866 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3867 ASSERT_NE(-1, texCubeLocation);
3868
3869 glUniform1i(tex2DLocation, 0);
3870 glUniform1i(texCubeLocation, 0);
3871 ASSERT_GL_NO_ERROR();
3872
3873 drawQuad(mProgram, "position", 0.5f);
3874 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3875}
3876
Vincent Lang25ab4512016-05-13 18:13:59 +02003877class Texture2DNorm16TestES3 : public Texture2DTestES3
3878{
3879 protected:
3880 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3881
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003882 void testSetUp() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003883 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003884 Texture2DTestES3::testSetUp();
Vincent Lang25ab4512016-05-13 18:13:59 +02003885
3886 glActiveTexture(GL_TEXTURE0);
3887 glGenTextures(3, mTextures);
3888 glGenFramebuffers(1, &mFBO);
3889 glGenRenderbuffers(1, &mRenderbuffer);
3890
3891 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3892 {
3893 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3894 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3895 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3896 }
3897
3898 glBindTexture(GL_TEXTURE_2D, 0);
3899
3900 ASSERT_GL_NO_ERROR();
3901 }
3902
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003903 void testTearDown() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003904 {
3905 glDeleteTextures(3, mTextures);
3906 glDeleteFramebuffers(1, &mFBO);
3907 glDeleteRenderbuffers(1, &mRenderbuffer);
3908
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003909 Texture2DTestES3::testTearDown();
Vincent Lang25ab4512016-05-13 18:13:59 +02003910 }
3911
3912 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3913 {
Geoff Langf607c602016-09-21 11:46:48 -04003914 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3915 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003916
3917 setUpProgram();
3918
3919 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3920 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3921 0);
3922
3923 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3924 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3925
3926 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003927 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003928
3929 EXPECT_GL_NO_ERROR();
3930
3931 drawQuad(mProgram, "position", 0.5f);
3932
Geoff Langf607c602016-09-21 11:46:48 -04003933 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003934
Jamie Madill50cf2be2018-06-15 09:46:57 -04003935 EXPECT_PIXEL_COLOR_EQ(0, 0,
3936 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3937 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003938
3939 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3940
3941 ASSERT_GL_NO_ERROR();
3942 }
3943
3944 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3945 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04003946 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003947 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003948
3949 setUpProgram();
3950
3951 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3952 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3953
3954 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3955 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3956 0);
3957
3958 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003959 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003960
3961 EXPECT_GL_NO_ERROR();
3962
3963 drawQuad(mProgram, "position", 0.5f);
3964
Geoff Langf607c602016-09-21 11:46:48 -04003965 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
Jamie Madill50cf2be2018-06-15 09:46:57 -04003966 EXPECT_PIXEL_COLOR_EQ(0, 0,
3967 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3968 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003969
3970 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3971 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3972 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3973 mRenderbuffer);
3974 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3975 EXPECT_GL_NO_ERROR();
3976
3977 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3978 glClear(GL_COLOR_BUFFER_BIT);
3979
3980 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3981
Geoff Langf607c602016-09-21 11:46:48 -04003982 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003983
3984 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3985
3986 ASSERT_GL_NO_ERROR();
3987 }
3988
3989 GLuint mTextures[3];
3990 GLuint mFBO;
3991 GLuint mRenderbuffer;
3992};
3993
3994// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3995TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3996{
Jamie Madillb8149072019-04-30 16:14:44 -04003997 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02003998
3999 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
4000 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
4001 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
4002 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
4003 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
4004 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
4005 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
4006 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
4007
4008 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
4009 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
4010 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
4011}
4012
Mohan Maiya8f1169e2019-06-27 15:32:32 -07004013class Texture2DRGTest : public Texture2DTest
4014{
4015 protected:
4016 Texture2DRGTest()
4017 : Texture2DTest(), mRenderableTexture(0), mTestTexture(0), mFBO(0), mRenderbuffer(0)
4018 {}
4019
4020 void testSetUp() override
4021 {
4022 Texture2DTest::testSetUp();
4023
4024 glActiveTexture(GL_TEXTURE0);
4025 glGenTextures(1, &mRenderableTexture);
4026 glGenTextures(1, &mTestTexture);
4027 glGenFramebuffers(1, &mFBO);
4028 glGenRenderbuffers(1, &mRenderbuffer);
4029
4030 glBindTexture(GL_TEXTURE_2D, mRenderableTexture);
4031 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4032 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4033 glBindTexture(GL_TEXTURE_2D, mTestTexture);
4034 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4035 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4036
4037 glBindTexture(GL_TEXTURE_2D, 0);
4038
4039 setUpProgram();
4040 glUseProgram(mProgram);
4041 glUniform1i(mTexture2DUniformLocation, 0);
4042
4043 ASSERT_GL_NO_ERROR();
4044 }
4045
4046 void testTearDown() override
4047 {
4048 glDeleteTextures(1, &mRenderableTexture);
4049 glDeleteTextures(1, &mTestTexture);
4050 glDeleteFramebuffers(1, &mFBO);
4051 glDeleteRenderbuffers(1, &mRenderbuffer);
4052
4053 Texture2DTest::testTearDown();
4054 }
4055
4056 void setupFormatTextures(GLenum internalformat, GLenum format, GLenum type, GLvoid *imageData)
4057 {
4058 glBindTexture(GL_TEXTURE_2D, mRenderableTexture);
4059 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4060
4061 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
4062 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
4063 mRenderableTexture, 0);
4064
4065 glBindTexture(GL_TEXTURE_2D, mTestTexture);
4066 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
4067
4068 EXPECT_GL_NO_ERROR();
4069 }
4070
4071 void testRGTexture(GLColor expectedColor)
4072 {
4073 drawQuad(mProgram, "position", 0.5f);
4074
4075 EXPECT_GL_NO_ERROR();
4076 EXPECT_PIXEL_COLOR_NEAR(0, 0, expectedColor, kPixelTolerance);
4077 }
4078
4079 void testRGRender(GLenum internalformat, GLenum format)
4080 {
4081 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
4082 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
4083 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
4084 mRenderbuffer);
4085 glBindRenderbuffer(GL_RENDERBUFFER, 0);
4086 EXPECT_GL_NO_ERROR();
4087
4088 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
4089 glClear(GL_COLOR_BUFFER_BIT);
4090
4091 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
4092
4093 ASSERT_GL_NO_ERROR();
4094 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor(255u, 255u, 255u, 255u)));
4095 }
4096
4097 GLuint mRenderableTexture;
4098 GLuint mTestTexture;
4099 GLuint mFBO;
4100 GLuint mRenderbuffer;
4101};
4102
4103// Test unorm texture formats enabled by the GL_EXT_texture_rg extension.
4104TEST_P(Texture2DRGTest, TextureRGUNormTest)
4105{
4106 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_rg"));
4107
4108 GLubyte pixelValue = 0xab;
4109 GLubyte imageData[] = {pixelValue, pixelValue};
4110
4111 setupFormatTextures(GL_RED_EXT, GL_RED_EXT, GL_UNSIGNED_BYTE, imageData);
4112 testRGTexture(
4113 SliceFormatColor(GL_RED_EXT, GLColor(pixelValue, pixelValue, pixelValue, pixelValue)));
4114 testRGRender(GL_R8_EXT, GL_RED_EXT);
4115
4116 setupFormatTextures(GL_RG_EXT, GL_RG_EXT, GL_UNSIGNED_BYTE, imageData);
4117 testRGTexture(
4118 SliceFormatColor(GL_RG_EXT, GLColor(pixelValue, pixelValue, pixelValue, pixelValue)));
4119 testRGRender(GL_RG8_EXT, GL_RG_EXT);
4120}
4121
4122// Test float texture formats enabled by the GL_EXT_texture_rg extension.
4123TEST_P(Texture2DRGTest, TextureRGFloatTest)
4124{
4125 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_rg"));
4126 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
4127
4128 GLfloat pixelValue = 0.54321;
4129 GLfloat imageData[] = {pixelValue, pixelValue};
4130
4131 GLubyte expectedValue = static_cast<GLubyte>(pixelValue * 255.0f);
4132 GLColor expectedColor = GLColor(expectedValue, expectedValue, expectedValue, expectedValue);
4133
4134 setupFormatTextures(GL_RED_EXT, GL_RED_EXT, GL_FLOAT, imageData);
4135 testRGTexture(SliceFormatColor(GL_RED_EXT, expectedColor));
4136
4137 setupFormatTextures(GL_RG_EXT, GL_RG_EXT, GL_FLOAT, imageData);
4138 testRGTexture(SliceFormatColor(GL_RG_EXT, expectedColor));
4139}
4140
4141// Test half-float texture formats enabled by the GL_EXT_texture_rg extension.
4142TEST_P(Texture2DRGTest, TextureRGFHalfFloatTest)
4143{
4144 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_rg"));
4145 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_half_float"));
4146
4147 GLfloat pixelValueFloat = 0.543f;
4148 GLhalf pixelValue = 0x3858;
4149 GLhalf imageData[] = {pixelValue, pixelValue};
4150
4151 GLubyte expectedValue = static_cast<GLubyte>(pixelValueFloat * 255.0f);
4152 GLColor expectedColor = GLColor(expectedValue, expectedValue, expectedValue, expectedValue);
4153
4154 setupFormatTextures(GL_RED_EXT, GL_RED_EXT, GL_HALF_FLOAT_OES, imageData);
4155 testRGTexture(SliceFormatColor(GL_RED_EXT, expectedColor));
4156
4157 setupFormatTextures(GL_RG_EXT, GL_RG_EXT, GL_HALF_FLOAT_OES, imageData);
4158 testRGTexture(SliceFormatColor(GL_RG_EXT, expectedColor));
4159}
4160
Olli Etuaho95faa232016-06-07 14:01:53 -07004161// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
4162// GLES 3.0.4 section 3.8.3.
4163TEST_P(Texture2DTestES3, UnpackSkipImages2D)
4164{
Yuly Novikovd18c0482019-04-04 19:56:43 -04004165 // Crashes on Nexus 5X due to a driver bug. http://anglebug.com/1429
4166 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07004167
4168 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4169 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4170 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4171 ASSERT_GL_NO_ERROR();
4172
4173 // SKIP_IMAGES should not have an effect on uploading 2D textures
4174 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
4175 ASSERT_GL_NO_ERROR();
4176
4177 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
4178
4179 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4180 pixelsGreen.data());
4181 ASSERT_GL_NO_ERROR();
4182
4183 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
4184 pixelsGreen.data());
4185 ASSERT_GL_NO_ERROR();
4186
4187 glUseProgram(mProgram);
4188 drawQuad(mProgram, "position", 0.5f);
4189 ASSERT_GL_NO_ERROR();
4190
4191 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
4192}
4193
Olli Etuaho989cac32016-06-08 16:18:49 -07004194// Test that skip defined in unpack parameters is taken into account when determining whether
4195// unpacking source extends outside unpack buffer bounds.
4196TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
4197{
4198 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4199 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4200 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4201 ASSERT_GL_NO_ERROR();
4202
4203 GLBuffer buf;
4204 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
4205 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
4206 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
4207 GL_DYNAMIC_COPY);
4208 ASSERT_GL_NO_ERROR();
4209
4210 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4211 ASSERT_GL_NO_ERROR();
4212
4213 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
4214 ASSERT_GL_NO_ERROR();
4215
4216 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4217 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4218
4219 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
4220 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
4221 ASSERT_GL_NO_ERROR();
4222
4223 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4224 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4225}
4226
Olli Etuaho218cf9e2016-05-20 13:55:24 +03004227// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
4228TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
4229{
Yunchao He9550c602018-02-13 14:47:05 +08004230 ANGLE_SKIP_TEST_IF(IsD3D11());
4231
4232 // Incorrect rendering results seen on OSX AMD.
4233 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03004234
4235 const GLuint width = 8u;
4236 const GLuint height = 8u;
4237 const GLuint unpackRowLength = 5u;
4238 const GLuint unpackSkipPixels = 1u;
4239
4240 setWindowWidth(width);
4241 setWindowHeight(height);
4242
4243 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4244 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4245 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4246 ASSERT_GL_NO_ERROR();
4247
4248 GLBuffer buf;
4249 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
4250 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
4251 GLColor::green);
4252
4253 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
4254 {
4255 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
4256 }
4257
4258 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
4259 GL_DYNAMIC_COPY);
4260 ASSERT_GL_NO_ERROR();
4261
4262 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
4263 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
4264 ASSERT_GL_NO_ERROR();
4265
4266 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4267 ASSERT_GL_NO_ERROR();
4268
4269 glUseProgram(mProgram);
4270 drawQuad(mProgram, "position", 0.5f);
4271 ASSERT_GL_NO_ERROR();
4272
4273 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
4274 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
4275 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
4276 actual.data());
4277 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
4278 EXPECT_EQ(expected, actual);
4279}
4280
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004281template <typename T>
4282T UNorm(double value)
4283{
4284 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
4285}
4286
4287// Test rendering a depth texture with mipmaps.
4288TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
4289{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08004290 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
4291 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
Jiawei Shaoaf0f31d2018-09-27 15:42:31 +08004292 // http://anglebug.com/1706
4293 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Corentin Walleze731d8a2016-09-07 10:56:25 -04004294
Jamie Madill24980272019-04-03 09:03:51 -04004295 // Seems to fail on AMD D3D11. Possibly driver bug. http://anglebug.com/3342
4296 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsD3D11());
4297
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004298 const int size = getWindowWidth();
4299
4300 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04004301 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004302
4303 glActiveTexture(GL_TEXTURE0);
4304 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4305 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
4306 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4307 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4308 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
4309 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
4310 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4311 ASSERT_GL_NO_ERROR();
4312
4313 glUseProgram(mProgram);
4314 glUniform1i(mTexture2DUniformLocation, 0);
4315
4316 std::vector<unsigned char> expected;
4317
4318 for (int level = 0; level < levels; ++level)
4319 {
4320 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
4321 expected.push_back(UNorm<unsigned char>(value));
4322
4323 int levelDim = dim(level);
4324
4325 ASSERT_GT(levelDim, 0);
4326
4327 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
4328 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
4329 GL_UNSIGNED_INT, initData.data());
4330 }
4331 ASSERT_GL_NO_ERROR();
4332
4333 for (int level = 0; level < levels; ++level)
4334 {
4335 glViewport(0, 0, dim(level), dim(level));
4336 drawQuad(mProgram, "position", 0.5f);
4337 GLColor actual = ReadColor(0, 0);
4338 EXPECT_NEAR(expected[level], actual.R, 10u);
4339 }
4340
4341 ASSERT_GL_NO_ERROR();
4342}
4343
Courtney Goeltzenleuchter1f2782e2019-08-29 14:19:23 -06004344class Texture2DDepthTest : public Texture2DTest
4345{
4346 protected:
4347 Texture2DDepthTest() : Texture2DTest() {}
4348
4349 const char *getVertexShaderSource() override
4350 {
4351 return "attribute vec4 vPosition;\n"
4352 "void main() {\n"
4353 " gl_Position = vPosition;\n"
4354 "}\n";
4355 }
4356
4357 const char *getFragmentShaderSource() override
4358 {
4359 return "precision mediump float;\n"
4360 "uniform sampler2D ShadowMap;"
4361 "void main() {\n"
4362 " vec4 shadow_value = texture2D(ShadowMap, vec2(0.5, 0.5));"
4363 " if (shadow_value.x == shadow_value.z && shadow_value.x != 0.0) {"
4364 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);"
4365 " } else {"
4366 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
4367 " }"
4368 "}\n";
4369 }
4370
4371 bool checkTexImageFormatSupport(GLenum format, GLenum internalformat, GLenum type)
4372 {
4373 EXPECT_GL_NO_ERROR();
4374
4375 GLTexture tex;
4376 glBindTexture(GL_TEXTURE_2D, tex);
4377 glTexImage2D(GL_TEXTURE_2D, 0, format, 1, 1, 0, format, type, nullptr);
4378
4379 return (glGetError() == GL_NO_ERROR);
4380 }
4381
4382 void testBehavior(bool useSizedComponent)
4383 {
4384 int w = getWindowWidth();
4385 int h = getWindowHeight();
4386 GLuint format = GL_DEPTH_COMPONENT;
4387 GLuint internalFormat = GL_DEPTH_COMPONENT;
4388
4389 if (useSizedComponent)
4390 {
4391 internalFormat = GL_DEPTH_COMPONENT24;
4392 }
4393
4394 GLFramebuffer fbo;
4395 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
4396 ASSERT_GL_NO_ERROR();
4397
4398 GLTexture depthTexture;
4399 glBindTexture(GL_TEXTURE_2D, depthTexture);
4400 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4401 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4402 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
4403 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
4404
4405 TexCoordDrawTest::setUpProgram();
4406 GLint shadowMapLocation = glGetUniformLocation(mProgram, "ShadowMap");
4407 ASSERT_NE(-1, shadowMapLocation);
4408
4409 GLint positionLocation = glGetAttribLocation(mProgram, "vPosition");
4410 ASSERT_NE(-1, positionLocation);
4411
4412 ANGLE_SKIP_TEST_IF(!checkTexImageFormatSupport(format, internalFormat, GL_UNSIGNED_INT));
4413 glBindTexture(GL_TEXTURE_2D, depthTexture);
4414 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, w, h, 0, format, GL_UNSIGNED_INT, nullptr);
4415 ASSERT_GL_NO_ERROR();
4416
4417 // try adding a color buffer.
4418 GLuint colorTex = 0;
4419 glGenTextures(1, &colorTex);
4420 glBindTexture(GL_TEXTURE_2D, colorTex);
4421 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
4422 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
4423 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4424 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4425 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4426 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTex, 0);
4427 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture, 0);
4428 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
4429 ASSERT_GL_NO_ERROR();
4430
4431 glViewport(0, 0, w, h);
4432 // Fill depthTexture with 0.75
4433 glClearDepthf(0.75);
4434 glClear(GL_DEPTH_BUFFER_BIT);
4435
4436 // Revert to normal framebuffer to test depth shader
4437 glBindFramebuffer(GL_FRAMEBUFFER, 0);
4438 glViewport(0, 0, w, h);
4439 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
4440 glClearDepthf(0.0f);
4441 ASSERT_GL_NO_ERROR();
4442
4443 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
4444 ASSERT_GL_NO_ERROR();
4445
4446 glActiveTexture(GL_TEXTURE0);
4447 glBindTexture(GL_TEXTURE_2D, depthTexture);
4448
4449 glUseProgram(mProgram);
4450 ASSERT_GL_NO_ERROR();
4451
4452 glUniform1i(shadowMapLocation, 0);
4453
4454 const GLfloat gTriangleVertices[] = {-0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, 0.5f};
4455
4456 glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, 0, gTriangleVertices);
4457 ASSERT_GL_NO_ERROR();
4458 glEnableVertexAttribArray(positionLocation);
4459 ASSERT_GL_NO_ERROR();
4460 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
4461 ASSERT_GL_NO_ERROR();
4462
4463 GLuint pixels[1];
4464 glReadPixels(w / 2, h / 2, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
4465 ASSERT_GL_NO_ERROR();
4466
4467 // The GLES 3.x spec says that the depth texture sample can be found in the RED component.
4468 // However, the OES_depth_texture indicates that the depth value is treated as luminance and
4469 // is in all the color components. Multiple implementations implement a workaround that
4470 // follows the OES_depth_texture behavior if the internalformat given at glTexImage2D was a
4471 // unsized format (e.g. DEPTH_COMPONENT) and the GLES 3.x behavior if it was a sized
4472 // internalformat such as GL_DEPTH_COMPONENT24. The shader will write out a different color
4473 // depending on if it sees the texture sample in only the RED component.
4474 if (useSizedComponent)
4475 {
4476 ASSERT_NE(pixels[0], 0xff0000ff);
4477 }
4478 else
4479 {
4480 ASSERT_EQ(pixels[0], 0xff0000ff);
4481 }
4482
4483 glBindFramebuffer(GL_FRAMEBUFFER, 0);
4484 glDeleteProgram(mProgram);
4485 }
4486};
4487
4488// Test depth texture compatibility with OES_depth_texture. Uses unsized internformat.
4489TEST_P(Texture2DDepthTest, DepthTextureES2Compatibility)
4490{
4491 ANGLE_SKIP_TEST_IF(IsD3D11());
4492 ANGLE_SKIP_TEST_IF(IsIntel() && IsD3D9());
4493
4494 // When the depth texture is specified with unsized internalformat implementations follow
4495 // OES_depth_texture behavior. Otherwise they follow GLES 3.0 behavior.
4496 testBehavior(false);
4497}
4498
4499// Test depth texture compatibility with GLES3 using sized internalformat.
4500TEST_P(Texture2DDepthTest, DepthTextureES3Compatibility)
4501{
4502 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3);
4503
4504 testBehavior(true);
4505}
4506
Jamie Madill7ffdda92016-09-08 13:26:51 -04004507// Tests unpacking into the unsized GL_ALPHA format.
4508TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
4509{
Jamie Madill7ffdda92016-09-08 13:26:51 -04004510 // Initialize the texure.
4511 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4512 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
4513 GL_UNSIGNED_BYTE, nullptr);
4514 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4515 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4516
4517 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
4518
4519 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04004520 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04004521 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4522 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4523 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
4524 GL_STATIC_DRAW);
4525
4526 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
4527 GL_UNSIGNED_BYTE, nullptr);
4528
4529 // Clear to a weird color to make sure we're drawing something.
4530 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
4531 glClear(GL_COLOR_BUFFER_BIT);
4532
4533 // Draw with the alpha texture and verify.
4534 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04004535
4536 ASSERT_GL_NO_ERROR();
4537 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
4538}
4539
Jamie Madill2e600342016-09-19 13:56:40 -04004540// Ensure stale unpack data doesn't propagate in D3D11.
4541TEST_P(Texture2DTestES3, StaleUnpackData)
4542{
4543 // Init unpack buffer.
4544 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
4545 std::vector<GLColor> pixels(pixelCount, GLColor::red);
4546
4547 GLBuffer unpackBuffer;
4548 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4549 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4550 GLsizei bufferSize = pixelCount * sizeof(GLColor);
4551 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
4552
4553 // Create from unpack buffer.
4554 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4555 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
4556 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4557 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4558 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4559
4560 drawQuad(mProgram, "position", 0.5f);
4561
4562 ASSERT_GL_NO_ERROR();
4563 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4564
4565 // Fill unpack with green, recreating buffer.
4566 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
4567 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
4568 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
4569
4570 // Reinit texture with green.
4571 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
4572 GL_UNSIGNED_BYTE, nullptr);
4573
4574 drawQuad(mProgram, "position", 0.5f);
4575
4576 ASSERT_GL_NO_ERROR();
4577 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
4578}
4579
Geoff Langfb7685f2017-11-13 11:44:11 -05004580// Ensure that texture parameters passed as floats that are converted to ints are rounded before
4581// validating they are less than 0.
4582TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
4583{
4584 GLTexture texture;
4585 glBindTexture(GL_TEXTURE_2D, texture);
4586
4587 // Use a negative number that will round to zero when converted to an integer
4588 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
4589 // "Validation of values performed by state-setting commands is performed after conversion,
4590 // unless specified otherwise for a specific command."
4591 GLfloat param = -7.30157126e-07f;
4592 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
4593 EXPECT_GL_NO_ERROR();
4594
4595 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
4596 EXPECT_GL_NO_ERROR();
4597}
4598
Jamie Madillf097e232016-11-05 00:44:15 -04004599// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
4600// being properly checked, and the texture storage of the previous texture format was persisting.
4601// This would result in an ASSERT in debug and incorrect rendering in release.
4602// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
4603TEST_P(Texture3DTestES3, FormatRedefinitionBug)
4604{
4605 GLTexture tex;
4606 glBindTexture(GL_TEXTURE_3D, tex.get());
4607 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4608
4609 GLFramebuffer framebuffer;
4610 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
4611 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
4612
4613 glCheckFramebufferStatus(GL_FRAMEBUFFER);
4614
4615 std::vector<uint8_t> pixelData(100, 0);
4616
4617 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
4618 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
4619 pixelData.data());
4620
4621 ASSERT_GL_NO_ERROR();
4622}
4623
Corentin Wallezd2627992017-04-28 17:17:03 -04004624// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
4625TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
4626{
4627 // 2D tests
4628 {
4629 GLTexture tex;
4630 glBindTexture(GL_TEXTURE_2D, tex.get());
4631
4632 GLBuffer pbo;
4633 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4634
4635 // Test OOB
4636 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
4637 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4638 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4639
4640 // Test OOB
4641 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
4642 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4643 ASSERT_GL_NO_ERROR();
4644 }
4645
4646 // 3D tests
4647 {
4648 GLTexture tex;
4649 glBindTexture(GL_TEXTURE_3D, tex.get());
4650
4651 GLBuffer pbo;
4652 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4653
4654 // Test OOB
4655 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
4656 GL_STATIC_DRAW);
4657 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4658 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4659
4660 // Test OOB
4661 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
4662 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4663 ASSERT_GL_NO_ERROR();
4664 }
4665}
4666
Jamie Madill3ed60422017-09-07 11:32:52 -04004667// Tests behaviour with a single texture and multiple sampler objects.
4668TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
4669{
4670 GLint maxTextureUnits = 0;
4671 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
4672 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
4673
4674 constexpr int kSize = 16;
4675
4676 // Make a single-level texture, fill it with red.
4677 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
4678 GLTexture tex;
4679 glBindTexture(GL_TEXTURE_2D, tex);
4680 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4681 redColors.data());
4682 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4683 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4684
4685 // Simple sanity check.
4686 draw2DTexturedQuad(0.5f, 1.0f, true);
4687 ASSERT_GL_NO_ERROR();
4688 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4689
4690 // Bind texture to unit 1 with a sampler object making it incomplete.
4691 GLSampler sampler;
4692 glBindSampler(0, sampler);
4693 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4694 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4695
4696 // Make a mipmap texture, fill it with blue.
4697 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
4698 GLTexture mipmapTex;
4699 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4700 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4701 blueColors.data());
4702 glGenerateMipmap(GL_TEXTURE_2D);
4703
4704 // Draw with the sampler, expect blue.
4705 draw2DTexturedQuad(0.5f, 1.0f, true);
4706 ASSERT_GL_NO_ERROR();
4707 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
4708
4709 // Simple multitexturing program.
Jamie Madill35cd7332018-12-02 12:03:33 -05004710 constexpr char kVS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004711 "#version 300 es\n"
4712 "in vec2 position;\n"
4713 "out vec2 texCoord;\n"
4714 "void main()\n"
4715 "{\n"
4716 " gl_Position = vec4(position, 0, 1);\n"
4717 " texCoord = position * 0.5 + vec2(0.5);\n"
4718 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05004719
4720 constexpr char kFS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004721 "#version 300 es\n"
4722 "precision mediump float;\n"
4723 "in vec2 texCoord;\n"
4724 "uniform sampler2D tex1;\n"
4725 "uniform sampler2D tex2;\n"
4726 "uniform sampler2D tex3;\n"
4727 "uniform sampler2D tex4;\n"
4728 "out vec4 color;\n"
4729 "void main()\n"
4730 "{\n"
4731 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
4732 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
4733 "}";
4734
Jamie Madill35cd7332018-12-02 12:03:33 -05004735 ANGLE_GL_PROGRAM(program, kVS, kFS);
Jamie Madill3ed60422017-09-07 11:32:52 -04004736
4737 std::array<GLint, 4> texLocations = {
4738 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
4739 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
4740 for (GLint location : texLocations)
4741 {
4742 ASSERT_NE(-1, location);
4743 }
4744
4745 // Init the uniform data.
4746 glUseProgram(program);
4747 for (GLint location = 0; location < 4; ++location)
4748 {
4749 glUniform1i(texLocations[location], location);
4750 }
4751
4752 // Initialize four samplers
4753 GLSampler samplers[4];
4754
4755 // 0: non-mipped.
4756 glBindSampler(0, samplers[0]);
4757 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4758 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4759
4760 // 1: mipped.
4761 glBindSampler(1, samplers[1]);
4762 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4763 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4764
4765 // 2: non-mipped.
4766 glBindSampler(2, samplers[2]);
4767 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4768 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4769
4770 // 3: mipped.
4771 glBindSampler(3, samplers[3]);
4772 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4773 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4774
4775 // Bind two blue mipped textures and two single layer textures, should all draw.
4776 glActiveTexture(GL_TEXTURE0);
4777 glBindTexture(GL_TEXTURE_2D, tex);
4778
4779 glActiveTexture(GL_TEXTURE1);
4780 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4781
4782 glActiveTexture(GL_TEXTURE2);
4783 glBindTexture(GL_TEXTURE_2D, tex);
4784
4785 glActiveTexture(GL_TEXTURE3);
4786 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4787
4788 ASSERT_GL_NO_ERROR();
4789
4790 drawQuad(program, "position", 0.5f);
4791 ASSERT_GL_NO_ERROR();
4792 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
4793
4794 // Bind four single layer textures, two should be incomplete.
4795 glActiveTexture(GL_TEXTURE1);
4796 glBindTexture(GL_TEXTURE_2D, tex);
4797
4798 glActiveTexture(GL_TEXTURE3);
4799 glBindTexture(GL_TEXTURE_2D, tex);
4800
4801 drawQuad(program, "position", 0.5f);
4802 ASSERT_GL_NO_ERROR();
4803 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
4804}
4805
Martin Radev7e2c0d32017-09-15 14:25:42 +03004806// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
4807// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
4808// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
4809// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
4810// samples the cubemap using a direction vector (1,1,1).
4811TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
4812{
Yunchao He2f23f352018-02-11 22:11:37 +08004813 // Check http://anglebug.com/2155.
4814 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
4815
Jamie Madill35cd7332018-12-02 12:03:33 -05004816 constexpr char kVS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004817 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004818 precision mediump float;
4819 in vec3 pos;
4820 void main() {
4821 gl_Position = vec4(pos, 1.0);
4822 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03004823
Jamie Madill35cd7332018-12-02 12:03:33 -05004824 constexpr char kFS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004825 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004826 precision mediump float;
4827 out vec4 color;
4828 uniform samplerCube uTex;
4829 void main(){
4830 color = texture(uTex, vec3(1.0));
4831 })";
Jamie Madill35cd7332018-12-02 12:03:33 -05004832
4833 ANGLE_GL_PROGRAM(program, kVS, kFS);
Martin Radev7e2c0d32017-09-15 14:25:42 +03004834 glUseProgram(program);
4835
4836 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
4837 glActiveTexture(GL_TEXTURE0);
4838
4839 GLTexture cubeTex;
4840 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
4841
4842 const int kFaceWidth = 1;
4843 const int kFaceHeight = 1;
4844 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
4845 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4846 GL_UNSIGNED_BYTE, texData.data());
4847 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4848 GL_UNSIGNED_BYTE, texData.data());
4849 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4850 GL_UNSIGNED_BYTE, texData.data());
4851 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4852 GL_UNSIGNED_BYTE, texData.data());
4853 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4854 GL_UNSIGNED_BYTE, texData.data());
4855 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4856 GL_UNSIGNED_BYTE, texData.data());
4857 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4858 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4859 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
4860 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
4861 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
4862 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
4863
4864 drawQuad(program, "pos", 0.5f, 1.0f, true);
4865 ASSERT_GL_NO_ERROR();
4866
4867 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4868}
4869
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08004870// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
4871TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
4872{
4873 GLuint texture = create2DTexture();
4874
4875 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
4876 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4877
4878 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
4879 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4880
4881 glDeleteTextures(1, &texture);
4882 EXPECT_GL_NO_ERROR();
4883}
4884
Olli Etuaho023371b2018-04-24 17:43:32 +03004885// Test setting base level after calling generateMipmap on a LUMA texture.
4886// Covers http://anglebug.com/2498
4887TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA)
4888{
4889 glActiveTexture(GL_TEXTURE0);
4890 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4891
4892 constexpr const GLsizei kWidth = 8;
4893 constexpr const GLsizei kHeight = 8;
4894 std::array<GLubyte, kWidth * kHeight * 2> whiteData;
4895 whiteData.fill(255u);
4896
4897 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA,
4898 GL_UNSIGNED_BYTE, whiteData.data());
4899 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
4900 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4901 glGenerateMipmap(GL_TEXTURE_2D);
4902 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
4903 EXPECT_GL_NO_ERROR();
4904
4905 drawQuad(mProgram, "position", 0.5f);
4906 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4907}
4908
Till Rathmannc1551dc2018-08-15 17:04:49 +02004909// Covers a bug in the D3D11 backend: http://anglebug.com/2772
4910// When using a sampler the texture was created as if it has mipmaps,
4911// regardless what you specified in GL_TEXTURE_MIN_FILTER via
4912// glSamplerParameteri() -- mistakenly the default value
4913// GL_NEAREST_MIPMAP_LINEAR or the value set via glTexParameteri() was
4914// evaluated.
4915// If you didn't provide mipmaps and didn't let the driver generate them
4916// this led to not sampling your texture data when minification occurred.
4917TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping)
4918{
Jamie Madill35cd7332018-12-02 12:03:33 -05004919 constexpr char kVS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004920 "#version 300 es\n"
4921 "out vec2 texcoord;\n"
4922 "in vec4 position;\n"
4923 "void main()\n"
4924 "{\n"
4925 " gl_Position = vec4(position.xy * 0.1, 0.0, 1.0);\n"
4926 " texcoord = (position.xy * 0.5) + 0.5;\n"
4927 "}\n";
4928
Jamie Madill35cd7332018-12-02 12:03:33 -05004929 constexpr char kFS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004930 "#version 300 es\n"
4931 "precision highp float;\n"
4932 "uniform highp sampler2D tex;\n"
4933 "in vec2 texcoord;\n"
4934 "out vec4 fragColor;\n"
4935 "void main()\n"
4936 "{\n"
4937 " fragColor = texture(tex, texcoord);\n"
4938 "}\n";
Jamie Madill35cd7332018-12-02 12:03:33 -05004939
4940 ANGLE_GL_PROGRAM(program, kVS, kFS);
Till Rathmannc1551dc2018-08-15 17:04:49 +02004941
4942 GLSampler sampler;
4943 glBindSampler(0, sampler);
4944 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4945 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4946
4947 glActiveTexture(GL_TEXTURE0);
4948 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4949
4950 const GLsizei texWidth = getWindowWidth();
4951 const GLsizei texHeight = getWindowHeight();
4952 const std::vector<GLColor> whiteData(texWidth * texHeight, GLColor::white);
4953
4954 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4955 whiteData.data());
4956 EXPECT_GL_NO_ERROR();
4957
4958 drawQuad(program, "position", 0.5f);
4959 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, angle::GLColor::white);
4960}
4961
Anders Leinof6cbe442019-04-18 15:32:07 +03004962// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4963// texture is output.
4964TEST_P(Texture2DIntegerTestES3, IntegerTextureNonZeroBaseLevel)
4965{
Yuly Novikovd2683452019-05-23 16:11:19 -04004966 // http://anglebug.com/3478
4967 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsDesktopOpenGL());
4968
Anders Leinof6cbe442019-04-18 15:32:07 +03004969 glActiveTexture(GL_TEXTURE0);
4970 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4971 int width = getWindowWidth();
4972 int height = getWindowHeight();
4973 GLColor color = GLColor::green;
4974 std::vector<GLColor> pixels(width * height, color);
4975 GLint baseLevel = 1;
4976 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
4977 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4978 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4979 glTexImage2D(GL_TEXTURE_2D, baseLevel, GL_RGBA8UI, width, height, 0, GL_RGBA_INTEGER,
4980 GL_UNSIGNED_BYTE, pixels.data());
4981
4982 setUpProgram();
4983 glUseProgram(mProgram);
4984 glUniform1i(mTexture2DUniformLocation, 0);
4985 drawQuad(mProgram, "position", 0.5f);
4986
4987 EXPECT_GL_NO_ERROR();
4988 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4989 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4990}
4991
Anders Leino60cc7512019-05-06 09:25:27 +03004992// Draw a quad with an integer cube texture with a non-zero base level, and test that the color of
4993// the texture is output.
4994TEST_P(TextureCubeIntegerTestES3, IntegerCubeTextureNonZeroBaseLevel)
4995{
4996 // All output checks returned black, rather than the texture color.
4997 ANGLE_SKIP_TEST_IF(IsOSX() && IsOpenGL());
4998
4999 glActiveTexture(GL_TEXTURE0);
5000
5001 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
5002 GLint baseLevel = 1;
5003 int width = getWindowWidth();
5004 int height = getWindowHeight();
5005 GLColor color = GLColor::green;
5006 std::vector<GLColor> pixels(width * height, color);
5007 for (GLenum faceIndex = 0; faceIndex < 6; faceIndex++)
5008 {
5009 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, baseLevel, GL_RGBA8UI, width,
5010 height, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
5011 EXPECT_GL_NO_ERROR();
5012 }
5013 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, baseLevel);
5014 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5015 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5016
5017 glUseProgram(mProgram);
5018 glUniform1i(mTextureCubeUniformLocation, 0);
5019 drawQuad(mProgram, "position", 0.5f);
5020
5021 EXPECT_GL_NO_ERROR();
5022 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
5023 EXPECT_PIXEL_COLOR_EQ(width - 1, 0, color);
5024 EXPECT_PIXEL_COLOR_EQ(0, height - 1, color);
5025 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
5026}
5027
Anders Leinoe4452442019-05-09 13:29:49 +03005028// This test sets up a cube map with four distincly colored MIP levels.
5029// The size of the texture and the geometry is chosen such that levels 1 or 2 should be chosen at
5030// the corners of the screen.
5031TEST_P(TextureCubeIntegerEdgeTestES3, IntegerCubeTextureCorner)
5032{
5033 glActiveTexture(GL_TEXTURE0);
5034
5035 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
5036 int width = getWindowWidth();
5037 int height = getWindowHeight();
5038 ASSERT_EQ(width, height);
5039 GLColor color[4] = {GLColor::white, GLColor::green, GLColor::blue, GLColor::red};
5040 for (GLint level = 0; level < 4; level++)
5041 {
5042 for (GLenum faceIndex = 0; faceIndex < 6; faceIndex++)
5043 {
5044 int levelWidth = (2 * width) >> level;
5045 int levelHeight = (2 * height) >> level;
5046 std::vector<GLColor> pixels(levelWidth * levelHeight, color[level]);
5047 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, level, GL_RGBA8UI, levelWidth,
5048 levelHeight, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
5049 EXPECT_GL_NO_ERROR();
5050 }
5051 }
5052 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
5053 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5054 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 3);
5055
5056 glUseProgram(mProgram);
5057 glUniform1i(mTextureCubeUniformLocation, 0);
5058 drawQuad(mProgram, "position", 0.5f);
5059
5060 ASSERT_GL_NO_ERROR();
5061 // Check that we do not read from levels 0 or 3. Levels 1 and 2 are both acceptable.
5062 EXPECT_EQ(ReadColor(0, 0).R, 0);
5063 EXPECT_EQ(ReadColor(width - 1, 0).R, 0);
5064 EXPECT_EQ(ReadColor(0, height - 1).R, 0);
5065 EXPECT_EQ(ReadColor(width - 1, height - 1).R, 0);
5066}
5067
Anders Leino1b6aded2019-05-20 12:56:34 +03005068// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
5069// texture is output.
5070TEST_P(Texture2DIntegerProjectiveOffsetTestES3, NonZeroBaseLevel)
5071{
Jamie Madill29ac2742019-05-28 15:53:00 -04005072 // Fails on AMD: http://crbug.com/967796
Jamie Madill06055b52019-05-29 14:31:42 -04005073 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsOpenGL());
Jamie Madill29ac2742019-05-28 15:53:00 -04005074
Anders Leino1b6aded2019-05-20 12:56:34 +03005075 glActiveTexture(GL_TEXTURE0);
5076 glBindTexture(GL_TEXTURE_2D, mTexture2D);
5077 int width = getWindowWidth();
5078 int height = getWindowHeight();
5079 GLColor color = GLColor::green;
5080 std::vector<GLColor> pixels(width * height, color);
5081 GLint baseLevel = 1;
5082 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
5083 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5084 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5085 glTexImage2D(GL_TEXTURE_2D, baseLevel, GL_RGBA8UI, width, height, 0, GL_RGBA_INTEGER,
5086 GL_UNSIGNED_BYTE, pixels.data());
5087
5088 setUpProgram();
5089 glUseProgram(mProgram);
5090 glUniform1i(mTexture2DUniformLocation, 0);
5091 drawQuad(mProgram, "position", 0.5f);
5092
5093 EXPECT_GL_NO_ERROR();
5094 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
5095 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
5096}
5097
Anders Leino69d04932019-05-20 14:04:13 +03005098// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
5099// texture is output.
5100TEST_P(Texture2DArrayIntegerTestES3, NonZeroBaseLevel)
5101{
5102 glActiveTexture(GL_TEXTURE0);
5103 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
5104 int width = getWindowWidth();
5105 int height = getWindowHeight();
5106 int depth = 2;
5107 GLColor color = GLColor::green;
5108 std::vector<GLColor> pixels(width * height * depth, color);
5109 GLint baseLevel = 1;
5110 glTexImage3D(GL_TEXTURE_2D_ARRAY, baseLevel, GL_RGBA8UI, width, height, depth, 0,
5111 GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
5112 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, baseLevel);
5113 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5114 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5115
5116 drawQuad(mProgram, "position", 0.5f);
5117
5118 EXPECT_GL_NO_ERROR();
5119 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
5120 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
5121}
5122
Anders Leino262e2822019-05-20 14:24:40 +03005123// Draw a quad with an integer 3D texture with a non-zero base level, and test that the color of the
5124// texture is output.
5125TEST_P(Texture3DIntegerTestES3, NonZeroBaseLevel)
5126{
5127 glActiveTexture(GL_TEXTURE0);
5128 glBindTexture(GL_TEXTURE_3D, mTexture3D);
5129 int width = getWindowWidth();
5130 int height = getWindowHeight();
5131 int depth = 2;
5132 GLColor color = GLColor::green;
5133 std::vector<GLColor> pixels(width * height * depth, color);
5134 GLint baseLevel = 1;
5135 glTexImage3D(GL_TEXTURE_3D, baseLevel, GL_RGBA8UI, width, height, depth, 0, GL_RGBA_INTEGER,
5136 GL_UNSIGNED_BYTE, pixels.data());
5137 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, baseLevel);
5138 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5139 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5140
5141 drawQuad(mProgram, "position", 0.5f);
5142
5143 EXPECT_GL_NO_ERROR();
5144 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
5145 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
5146}
5147
Jamie Madill50cf2be2018-06-15 09:46:57 -04005148// Use this to select which configurations (e.g. which renderer, which GLES major version) these
5149// tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -05005150ANGLE_INSTANTIATE_TEST(Texture2DTest,
5151 ES2_D3D9(),
5152 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05005153 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05005154 ES2_OPENGLES(),
5155 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05005156ANGLE_INSTANTIATE_TEST(TextureCubeTest,
5157 ES2_D3D9(),
5158 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05005159 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04005160 ES2_OPENGLES(),
5161 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02005162ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
5163 ES2_D3D9(),
5164 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05005165 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04005166 ES2_OPENGLES(),
5167 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02005168ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
5169 ES2_D3D9(),
5170 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05005171 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005172 ES2_OPENGLES(),
5173 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05005174ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
5175 ES2_D3D9(),
5176 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05005177 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005178 ES2_OPENGLES(),
5179 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05005180ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
5181 ES2_D3D9(),
5182 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05005183 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005184 ES2_OPENGLES(),
5185 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05005186ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02005187ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
James Dong8bb6baa2019-06-18 15:30:16 -06005188ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3,
5189 ES3_D3D11(),
5190 ES3_OPENGL(),
5191 ES3_OPENGLES(),
5192 ES3_VULKAN());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02005193ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
5194 ES3_D3D11(),
5195 ES3_OPENGL(),
James Dong8bb6baa2019-06-18 15:30:16 -06005196 ES3_OPENGLES(),
5197 ES3_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05005198ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
5199 ES3_D3D11(),
5200 ES3_OPENGL(),
5201 ES3_OPENGLES());
James Dong8bb6baa2019-06-18 15:30:16 -06005202ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3,
5203 ES3_D3D11(),
5204 ES3_OPENGL(),
5205 ES3_OPENGLES(),
5206 ES3_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05005207ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02005208ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02005209ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
5210 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02005211 ES2_D3D9(),
5212 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005213 ES2_OPENGLES(),
5214 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02005215ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
5216 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02005217 ES2_D3D9(),
5218 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005219 ES2_OPENGLES(),
5220 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02005221ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
5222 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02005223 ES2_D3D9(),
5224 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005225 ES2_OPENGLES(),
5226 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02005227ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
5228 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02005229 ES2_D3D9(),
5230 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005231 ES2_OPENGLES(),
5232 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02005233ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
5234 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02005235 ES2_D3D9(),
5236 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005237 ES2_OPENGLES(),
5238 ES2_VULKAN());
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05005239ANGLE_INSTANTIATE_TEST(TextureAnisotropyTest,
5240 ES2_D3D11(),
5241 ES2_D3D9(),
5242 ES2_OPENGL(),
5243 ES2_OPENGLES(),
5244 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02005245ANGLE_INSTANTIATE_TEST(TextureBorderClampTest,
5246 ES2_D3D11(),
5247 ES2_D3D9(),
5248 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005249 ES2_OPENGLES(),
5250 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02005251ANGLE_INSTANTIATE_TEST(TextureBorderClampTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
5252ANGLE_INSTANTIATE_TEST(TextureBorderClampIntegerTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Luc Ferronaf883622018-06-08 15:57:31 -04005253ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN());
Vincent Lang25ab4512016-05-13 18:13:59 +02005254ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Mohan Maiya8f1169e2019-06-27 15:32:32 -07005255ANGLE_INSTANTIATE_TEST(Texture2DRGTest,
5256 ES2_D3D11(),
5257 ES3_D3D11(),
5258 ES2_OPENGL(),
5259 ES3_OPENGL(),
5260 ES2_OPENGLES(),
5261 ES3_OPENGLES(),
5262 ES2_VULKAN(),
5263 ES3_VULKAN());
Martin Radev7e2c0d32017-09-15 14:25:42 +03005264ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Anders Leinof6cbe442019-04-18 15:32:07 +03005265ANGLE_INSTANTIATE_TEST(Texture2DIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino60cc7512019-05-06 09:25:27 +03005266ANGLE_INSTANTIATE_TEST(TextureCubeIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leinoe4452442019-05-09 13:29:49 +03005267ANGLE_INSTANTIATE_TEST(TextureCubeIntegerEdgeTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino1b6aded2019-05-20 12:56:34 +03005268ANGLE_INSTANTIATE_TEST(Texture2DIntegerProjectiveOffsetTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino69d04932019-05-20 14:04:13 +03005269ANGLE_INSTANTIATE_TEST(Texture2DArrayIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino262e2822019-05-20 14:24:40 +03005270ANGLE_INSTANTIATE_TEST(Texture3DIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Courtney Goeltzenleuchter1f2782e2019-08-29 14:19:23 -06005271ANGLE_INSTANTIATE_TEST(Texture2DDepthTest,
5272 ES2_D3D9(),
5273 ES2_D3D11(),
5274 ES2_OPENGL(),
5275 ES2_OPENGLES(),
5276 ES2_VULKAN(),
5277 ES3_VULKAN());
Jamie Madillfa05f602015-05-07 13:47:11 -04005278
Jamie Madill7ffdda92016-09-08 13:26:51 -04005279} // anonymous namespace