blob: f2c6645536443659201081f8c524f474c2236907 [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{
Olli Etuahoa314b612016-03-10 16:43:00 +02002271 glActiveTexture(GL_TEXTURE0);
2272 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
2273 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2274 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2275 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2276
2277 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2278 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2279
2280 // Two levels that are initially unused.
2281 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2282 texDataRed.data());
2283 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2284 texDataCyan.data());
2285
2286 // One level that is used - only this level should affect completeness.
2287 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2288 texDataGreen.data());
2289
2290 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2291 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2292
2293 EXPECT_GL_NO_ERROR();
2294
2295 drawQuad(mProgram, "position", 0.5f);
2296
2297 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2298
Yunchao He2f23f352018-02-11 22:11:37 +08002299 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
2300
Yunchao He9550c602018-02-13 14:47:05 +08002301 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
2302 // level was changed.
2303 ANGLE_SKIP_TEST_IF(IsNVIDIA() && (IsOpenGL() || IsOpenGLES()));
Olli Etuahoa314b612016-03-10 16:43:00 +02002304
2305 // Switch the level that is being used to the cyan level 2.
2306 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2307 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2308
2309 EXPECT_GL_NO_ERROR();
2310
2311 drawQuad(mProgram, "position", 0.5f);
2312
2313 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2314}
2315
2316// Test that texture completeness is updated if texture max level changes.
2317// GLES 3.0.4 section 3.8.13 Texture completeness
2318TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2319{
Olli Etuahoa314b612016-03-10 16:43:00 +02002320 glActiveTexture(GL_TEXTURE0);
2321 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2322 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2323
2324 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2325 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2326
2327 // A level that is initially unused.
2328 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2329 texDataGreen.data());
2330
2331 // One level that is initially used - only this level should affect completeness.
2332 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2333 texDataGreen.data());
2334
2335 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2336 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2337
2338 EXPECT_GL_NO_ERROR();
2339
2340 drawQuad(mProgram, "position", 0.5f);
2341
2342 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2343
2344 // Switch the max level to level 1. The levels within the used range now have inconsistent
2345 // dimensions and the texture should be incomplete.
2346 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2347
2348 EXPECT_GL_NO_ERROR();
2349
2350 drawQuad(mProgram, "position", 0.5f);
2351
2352 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2353}
2354
2355// Test that 3D texture completeness is updated if texture max level changes.
2356// GLES 3.0.4 section 3.8.13 Texture completeness
2357TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2358{
Olli Etuahoa314b612016-03-10 16:43:00 +02002359 glActiveTexture(GL_TEXTURE0);
2360 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2361 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2362
2363 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2364 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2365
2366 // A level that is initially unused.
2367 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2368 texDataGreen.data());
2369
2370 // One level that is initially used - only this level should affect completeness.
2371 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2372 texDataGreen.data());
2373
2374 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2375 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2376
2377 EXPECT_GL_NO_ERROR();
2378
2379 drawQuad(mProgram, "position", 0.5f);
2380
2381 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2382
2383 // Switch the max level to level 1. The levels within the used range now have inconsistent
2384 // dimensions and the texture should be incomplete.
2385 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2386
2387 EXPECT_GL_NO_ERROR();
2388
2389 drawQuad(mProgram, "position", 0.5f);
2390
2391 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2392}
2393
2394// Test that texture completeness is updated if texture base level changes.
2395// GLES 3.0.4 section 3.8.13 Texture completeness
2396TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2397{
Olli Etuahoa314b612016-03-10 16:43:00 +02002398 glActiveTexture(GL_TEXTURE0);
2399 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2400 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2401
2402 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2403 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2404
2405 // Two levels that are initially unused.
2406 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2407 texDataGreen.data());
2408 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2409 texDataGreen.data());
2410
2411 // One level that is initially used - only this level should affect completeness.
2412 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2413 texDataGreen.data());
2414
2415 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2416 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2417
2418 EXPECT_GL_NO_ERROR();
2419
2420 drawQuad(mProgram, "position", 0.5f);
2421
2422 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2423
2424 // Switch the base level to level 1. The levels within the used range now have inconsistent
2425 // dimensions and the texture should be incomplete.
2426 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2427
2428 EXPECT_GL_NO_ERROR();
2429
2430 drawQuad(mProgram, "position", 0.5f);
2431
2432 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2433}
2434
2435// Test that texture is not complete if base level is greater than max level.
2436// GLES 3.0.4 section 3.8.13 Texture completeness
2437TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2438{
Olli Etuahoa314b612016-03-10 16:43:00 +02002439 glActiveTexture(GL_TEXTURE0);
2440 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2441
2442 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2443 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2444
2445 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2446
2447 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2448 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2449
2450 EXPECT_GL_NO_ERROR();
2451
2452 drawQuad(mProgram, "position", 0.5f);
2453
2454 // Texture should be incomplete.
2455 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2456}
2457
2458// Test that immutable texture base level and max level are clamped.
2459// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2460TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2461{
Olli Etuahoa314b612016-03-10 16:43:00 +02002462 glActiveTexture(GL_TEXTURE0);
2463 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2464
2465 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2466 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2467
2468 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2469
2470 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2471
2472 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2473 // should be clamped to [base_level, levels - 1].
2474 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2475 // In the case of this test, those rules make the effective base level and max level 0.
2476 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2477 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2478
2479 EXPECT_GL_NO_ERROR();
2480
2481 drawQuad(mProgram, "position", 0.5f);
2482
2483 // Texture should be complete.
2484 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2485}
2486
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002487// Test that changing base level works when it affects the format of the texture.
2488TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2489{
Yunchao He9550c602018-02-13 14:47:05 +08002490 // Observed rendering corruption on NVIDIA OpenGL.
2491 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL());
2492
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002493 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002494
2495 // Observed incorrect rendering on AMD OpenGL.
2496 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002497
2498 glActiveTexture(GL_TEXTURE0);
2499 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2500 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2501 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2502
2503 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2504 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2505
2506 // RGBA8 level that's initially unused.
2507 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2508 texDataCyan.data());
2509
2510 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2511 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2512
2513 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2514 // format. It reads green channel data from the green and alpha channels of texDataGreen
2515 // (this is a bit hacky but works).
2516 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2517
2518 EXPECT_GL_NO_ERROR();
2519
2520 drawQuad(mProgram, "position", 0.5f);
2521
2522 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2523
2524 // Switch the texture to use the cyan level 0 with the RGBA format.
2525 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2526 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2527
2528 EXPECT_GL_NO_ERROR();
2529
2530 drawQuad(mProgram, "position", 0.5f);
2531
2532 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2533}
2534
Olli Etuahoa314b612016-03-10 16:43:00 +02002535// Test that setting a texture image works when base level is out of range.
2536TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2537{
2538 glActiveTexture(GL_TEXTURE0);
2539 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2540
2541 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2542 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2543
2544 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2545 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2546
2547 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2548
2549 EXPECT_GL_NO_ERROR();
2550
2551 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2552
2553 drawQuad(mProgram, "position", 0.5f);
2554
2555 // Texture should be complete.
2556 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002557}
2558
Jamie Madill50cf2be2018-06-15 09:46:57 -04002559// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG
2560// RBA->RGBA8, with 1.0 in the alpha channel. This test covers a bug where redefining array textures
2561// with these formats does not work as expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002562TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002563{
2564 std::vector<GLubyte> pixelData;
2565 for (size_t count = 0; count < 5000; count++)
2566 {
2567 pixelData.push_back(0u);
2568 pixelData.push_back(255u);
2569 pixelData.push_back(0u);
2570 }
2571
2572 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002573 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002574 glUniform1i(mTextureArrayLocation, 0);
2575
2576 // The first draw worked correctly.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002577 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2578 &pixelData[0]);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002579
2580 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2581 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2582 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2583 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002584 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002585 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002586
2587 // The dimension of the respecification must match the original exactly to trigger the bug.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002588 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2589 &pixelData[0]);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002590 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002591 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002592
2593 ASSERT_GL_NO_ERROR();
2594}
2595
Olli Etuaho1a679902016-01-14 12:21:47 +02002596// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2597// This test is needed especially to confirm that sampler registers get assigned correctly on
2598// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2599TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2600{
2601 glActiveTexture(GL_TEXTURE0);
2602 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2603 GLubyte texData[4];
2604 texData[0] = 0;
2605 texData[1] = 60;
2606 texData[2] = 0;
2607 texData[3] = 255;
2608 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2609
2610 glActiveTexture(GL_TEXTURE1);
2611 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2612 GLfloat depthTexData[1];
2613 depthTexData[0] = 0.5f;
2614 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2615 depthTexData);
2616
2617 glUseProgram(mProgram);
2618 glUniform1f(mDepthRefUniformLocation, 0.3f);
2619 glUniform1i(mTexture3DUniformLocation, 0);
2620 glUniform1i(mTextureShadowUniformLocation, 1);
2621
2622 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2623 drawQuad(mProgram, "position", 0.5f);
2624 EXPECT_GL_NO_ERROR();
2625 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2626 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2627
2628 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2629 drawQuad(mProgram, "position", 0.5f);
2630 EXPECT_GL_NO_ERROR();
2631 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2632 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2633}
2634
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002635// Test multiple different sampler types in the same shader.
2636// This test makes sure that even if sampler / texture registers get grouped together based on type
2637// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2638// still has the right register index information for each ESSL sampler.
2639// The tested ESSL samplers have the following types in D3D11 HLSL:
2640// sampler2D: Texture2D + SamplerState
2641// samplerCube: TextureCube + SamplerState
2642// sampler2DShadow: Texture2D + SamplerComparisonState
2643// samplerCubeShadow: TextureCube + SamplerComparisonState
2644TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2645{
2646 glActiveTexture(GL_TEXTURE0);
2647 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2648 GLubyte texData[4];
2649 texData[0] = 0;
2650 texData[1] = 0;
2651 texData[2] = 120;
2652 texData[3] = 255;
2653 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2654
2655 glActiveTexture(GL_TEXTURE1);
2656 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2657 texData[0] = 0;
2658 texData[1] = 90;
2659 texData[2] = 0;
2660 texData[3] = 255;
2661 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2662 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2663 texData);
2664
2665 glActiveTexture(GL_TEXTURE2);
2666 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2667 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2668 GLfloat depthTexData[1];
2669 depthTexData[0] = 0.5f;
2670 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2671 depthTexData);
2672
2673 glActiveTexture(GL_TEXTURE3);
2674 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2675 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2676 depthTexData[0] = 0.2f;
2677 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2678 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2679 depthTexData);
2680
2681 EXPECT_GL_NO_ERROR();
2682
2683 glUseProgram(mProgram);
2684 glUniform1f(mDepthRefUniformLocation, 0.3f);
2685 glUniform1i(mTexture2DUniformLocation, 0);
2686 glUniform1i(mTextureCubeUniformLocation, 1);
2687 glUniform1i(mTexture2DShadowUniformLocation, 2);
2688 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2689
2690 drawQuad(mProgram, "position", 0.5f);
2691 EXPECT_GL_NO_ERROR();
2692 // The shader writes:
2693 // <texture 2d color> +
2694 // <cube map color> +
2695 // 0.25 * <comparison result (1.0)> +
2696 // 0.125 * <comparison result (0.0)>
2697 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2698}
2699
Olli Etuahobce743a2016-01-15 17:18:28 +02002700// Test different base levels on textures accessed through the same sampler array.
2701// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2702TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2703{
Yunchao He9550c602018-02-13 14:47:05 +08002704 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2705
Olli Etuahobce743a2016-01-15 17:18:28 +02002706 glActiveTexture(GL_TEXTURE0);
2707 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2708 GLsizei size = 64;
2709 for (GLint level = 0; level < 7; ++level)
2710 {
2711 ASSERT_LT(0, size);
2712 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2713 nullptr);
2714 size = size / 2;
2715 }
2716 ASSERT_EQ(0, size);
2717 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2718
2719 glActiveTexture(GL_TEXTURE1);
2720 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2721 size = 128;
2722 for (GLint level = 0; level < 8; ++level)
2723 {
2724 ASSERT_LT(0, size);
2725 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2726 nullptr);
2727 size = size / 2;
2728 }
2729 ASSERT_EQ(0, size);
2730 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2731 EXPECT_GL_NO_ERROR();
2732
2733 glUseProgram(mProgram);
2734 glUniform1i(mTexture0Location, 0);
2735 glUniform1i(mTexture1Location, 1);
2736
Olli Etuaho5804dc82018-04-13 14:11:46 +03002737 drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
Olli Etuahobce743a2016-01-15 17:18:28 +02002738 EXPECT_GL_NO_ERROR();
2739 // Red channel: width of level 1 of texture A: 32.
2740 // Green channel: width of level 3 of texture B: 16.
2741 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2742}
2743
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002744// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2745// ES 3.0.4 table 3.24
2746TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2747{
2748 glActiveTexture(GL_TEXTURE0);
2749 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2750 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2751 EXPECT_GL_NO_ERROR();
2752
2753 drawQuad(mProgram, "position", 0.5f);
2754
2755 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2756}
2757
2758// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2759// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002760TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002761{
Luc Ferron5164b792018-03-06 09:10:12 -05002762 setUpProgram();
2763
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002764 glActiveTexture(GL_TEXTURE0);
2765 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2766 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2767 EXPECT_GL_NO_ERROR();
2768
2769 drawQuad(mProgram, "position", 0.5f);
2770
2771 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2772}
2773
Luc Ferron5164b792018-03-06 09:10:12 -05002774// Validate that every component of the pixel will be equal to the luminance value we've set
2775// and that the alpha channel will be 1 (or 255 to be exact).
2776TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2777{
2778 setUpProgram();
2779
2780 glActiveTexture(GL_TEXTURE0);
2781 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2782 uint8_t pixel = 50;
2783 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2784 EXPECT_GL_NO_ERROR();
2785
2786 drawQuad(mProgram, "position", 0.5f);
2787
2788 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2789}
2790
2791// Validate that every component of the pixel will be equal to the luminance value we've set
2792// and that the alpha channel will be the second component.
2793TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2794{
2795 setUpProgram();
2796
2797 glActiveTexture(GL_TEXTURE0);
2798 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2799 uint8_t pixel[] = {50, 25};
2800 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2801 GL_UNSIGNED_BYTE, pixel);
2802 EXPECT_GL_NO_ERROR();
2803
2804 drawQuad(mProgram, "position", 0.5f);
2805
2806 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2807}
2808
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002809// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2810// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002811TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002812{
Jamie Madillb8149072019-04-30 16:14:44 -04002813 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002814 ANGLE_SKIP_TEST_IF(IsD3D9());
2815 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002816
2817 setUpProgram();
2818
Luc Ferrond8c632c2018-04-10 12:31:44 -04002819 glActiveTexture(GL_TEXTURE0);
2820 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2821 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2822 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002823
Luc Ferrond8c632c2018-04-10 12:31:44 -04002824 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002825
Luc Ferrond8c632c2018-04-10 12:31:44 -04002826 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002827}
2828
2829// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2830// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002831TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002832{
Jamie Madillb8149072019-04-30 16:14:44 -04002833 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002834 ANGLE_SKIP_TEST_IF(IsD3D9());
2835 ANGLE_SKIP_TEST_IF(IsVulkan());
2836 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES());
2837 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2838 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002839
Luc Ferrond8c632c2018-04-10 12:31:44 -04002840 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002841
Luc Ferrond8c632c2018-04-10 12:31:44 -04002842 glActiveTexture(GL_TEXTURE0);
2843 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2844 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2845 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002846
Luc Ferrond8c632c2018-04-10 12:31:44 -04002847 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002848
Luc Ferrond8c632c2018-04-10 12:31:44 -04002849 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002850}
2851
2852// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2853// ES 3.0.4 table 3.24
2854TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2855{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002856 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2857
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002858 glActiveTexture(GL_TEXTURE0);
2859 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2860 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2861 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2862 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2863 EXPECT_GL_NO_ERROR();
2864
2865 drawQuad(mProgram, "position", 0.5f);
2866
2867 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2868}
2869
2870// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2871// ES 3.0.4 table 3.24
2872TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2873{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002874 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2875
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002876 glActiveTexture(GL_TEXTURE0);
2877 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2878
2879 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2880 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2881 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2882 EXPECT_GL_NO_ERROR();
2883
2884 drawQuad(mProgram, "position", 0.5f);
2885
2886 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2887}
2888
2889// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2890// ES 3.0.4 table 3.24
2891TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2892{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002893 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2894
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002895 glActiveTexture(GL_TEXTURE0);
2896 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2897 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2898 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2899 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2900 EXPECT_GL_NO_ERROR();
2901
2902 drawQuad(mProgram, "position", 0.5f);
2903
2904 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2905}
2906
2907// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2908// ES 3.0.4 table 3.24
2909TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2910{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002911 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2912
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002913 glActiveTexture(GL_TEXTURE0);
2914 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2915 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2916 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2917 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2918 EXPECT_GL_NO_ERROR();
2919
2920 drawQuad(mProgram, "position", 0.5f);
2921
2922 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2923}
2924
2925// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2926// ES 3.0.4 table 3.24
2927TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2928{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002929 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2930
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002931 glActiveTexture(GL_TEXTURE0);
2932 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2933 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2934 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2935 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2936 EXPECT_GL_NO_ERROR();
2937
2938 drawQuad(mProgram, "position", 0.5f);
2939
2940 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2941}
2942
2943// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2944// ES 3.0.4 table 3.24
2945TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2946{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002947 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2948
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002949 glActiveTexture(GL_TEXTURE0);
2950 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2951 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2952 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2953 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2954 EXPECT_GL_NO_ERROR();
2955
2956 drawQuad(mProgram, "position", 0.5f);
2957
2958 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2959}
2960
2961// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2962// ES 3.0.4 table 3.24
2963TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2964{
2965 glActiveTexture(GL_TEXTURE0);
2966 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2967 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2968 EXPECT_GL_NO_ERROR();
2969
2970 drawQuad(mProgram, "position", 0.5f);
2971
2972 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2973}
2974
2975// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2976// ES 3.0.4 table 3.24
2977TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2978{
2979 glActiveTexture(GL_TEXTURE0);
2980 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2981 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2982 nullptr);
2983 EXPECT_GL_NO_ERROR();
2984
2985 drawQuad(mProgram, "position", 0.5f);
2986
2987 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2988}
2989
2990// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2991// ES 3.0.4 table 3.24
2992TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2993{
Yunchao He9550c602018-02-13 14:47:05 +08002994 // Seems to fail on OSX 10.12 Intel.
2995 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Jamie Madillbb1db482017-01-10 10:48:32 -05002996
Yuly Novikov49886892018-01-23 21:18:27 -05002997 // http://anglebug.com/2190
2998 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2999
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003000 glActiveTexture(GL_TEXTURE0);
3001 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3002 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
3003 EXPECT_GL_NO_ERROR();
3004
3005 drawQuad(mProgram, "position", 0.5f);
3006
3007 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
3008}
3009
3010// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
3011// ES 3.0.4 table 3.24
3012TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
3013{
Yunchao He9550c602018-02-13 14:47:05 +08003014 // Seems to fail on OSX 10.12 Intel.
3015 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04003016
Yuly Novikov49886892018-01-23 21:18:27 -05003017 // http://anglebug.com/2190
3018 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
3019
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003020 glActiveTexture(GL_TEXTURE0);
3021 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3022 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
3023 EXPECT_GL_NO_ERROR();
3024
3025 drawQuad(mProgram, "position", 0.5f);
3026
3027 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
3028}
3029
Olli Etuaho96963162016-03-21 11:54:33 +02003030// Use a sampler in a uniform struct.
3031TEST_P(SamplerInStructTest, SamplerInStruct)
3032{
3033 runSamplerInStructTest();
3034}
3035
3036// Use a sampler in a uniform struct that's passed as a function parameter.
3037TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
3038{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003039 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
3040 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04003041
Olli Etuaho96963162016-03-21 11:54:33 +02003042 runSamplerInStructTest();
3043}
3044
3045// Use a sampler in a uniform struct array with a struct from the array passed as a function
3046// parameter.
3047TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
3048{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003049 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
3050 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08003051
Olli Etuaho96963162016-03-21 11:54:33 +02003052 runSamplerInStructTest();
3053}
3054
3055// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
3056// parameter.
3057TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
3058{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003059 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
3060 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08003061
Olli Etuaho96963162016-03-21 11:54:33 +02003062 runSamplerInStructTest();
3063}
3064
3065// Make sure that there isn't a name conflict between sampler extracted from a struct and a
3066// similarly named uniform.
3067TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
3068{
3069 runSamplerInStructTest();
3070}
3071
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05003072// GL_EXT_texture_filter_anisotropic
3073class TextureAnisotropyTest : public Texture2DTest
3074{
3075 protected:
3076 void uploadTexture()
3077 {
3078 glActiveTexture(GL_TEXTURE0);
3079 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3080 GLColor texDataRed[1] = {GLColor::red};
3081 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed);
3082 EXPECT_GL_NO_ERROR();
3083 }
3084};
3085
3086// Tests that setting anisotropic filtering doesn't cause failures at draw time.
3087TEST_P(TextureAnisotropyTest, AnisotropyFunctional)
3088{
Jamie Madillb8149072019-04-30 16:14:44 -04003089 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_filter_anisotropic"));
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05003090
3091 setUpProgram();
3092
3093 uploadTexture();
3094
3095 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3096 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3097 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f);
3098 EXPECT_GL_NO_ERROR();
3099
3100 drawQuad(mProgram, "position", 0.5f);
3101
3102 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3103 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3104 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::red);
3105}
3106
Till Rathmannb8543632018-10-02 19:46:14 +02003107// GL_OES_texture_border_clamp
3108class TextureBorderClampTest : public Texture2DTest
3109{
3110 protected:
3111 TextureBorderClampTest() : Texture2DTest() {}
3112
Jamie Madill35cd7332018-12-02 12:03:33 -05003113 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003114 {
3115 return
3116 R"(precision highp float;
3117 attribute vec4 position;
3118 varying vec2 texcoord;
3119
3120 void main()
3121 {
3122 gl_Position = vec4(position.xy, 0.0, 1.0);
3123 // texcoords in [-0.5, 1.5]
3124 texcoord = (position.xy) + 0.5;
3125 })";
3126 }
3127
3128 void uploadTexture()
3129 {
3130 glActiveTexture(GL_TEXTURE0);
3131 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3132 std::vector<GLColor> texDataRed(1, GLColor::red);
3133 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3134 texDataRed.data());
3135 EXPECT_GL_NO_ERROR();
3136 }
3137};
3138
3139// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3140// GL_CLAMP_TO_BORDER wrap mode (set with glTexParameter).
3141TEST_P(TextureBorderClampTest, TextureBorderClampFunctional)
3142{
Jamie Madillb8149072019-04-30 16:14:44 -04003143 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003144
3145 setUpProgram();
3146
3147 uploadTexture();
3148
3149 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3150 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3151 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3152 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3153 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3154 EXPECT_GL_NO_ERROR();
3155
3156 drawQuad(mProgram, "position", 0.5f);
3157
3158 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3159 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3160 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3161}
3162
3163// Test reading back GL_TEXTURE_BORDER_COLOR by glGetTexParameter.
3164TEST_P(TextureBorderClampTest, TextureBorderClampFunctional2)
3165{
Jamie Madillb8149072019-04-30 16:14:44 -04003166 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003167
3168 glActiveTexture(GL_TEXTURE0);
3169 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3170
3171 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3172
3173 GLint colorFixedPoint[4] = {0};
3174 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3175 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3176 std::numeric_limits<GLint>::max()};
3177 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3178 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3179 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3180 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3181
3182 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3183 std::numeric_limits<GLint>::max()};
3184 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3185
3186 GLfloat color[4] = {0.0f};
3187 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
3188 EXPECT_EQ(color[0], kFloatBlue.R);
3189 EXPECT_EQ(color[1], kFloatBlue.G);
3190 EXPECT_EQ(color[2], kFloatBlue.B);
3191 EXPECT_EQ(color[3], kFloatBlue.A);
3192}
3193
3194// Test GL_TEXTURE_BORDER_COLOR parameter validation at glTexParameter.
3195TEST_P(TextureBorderClampTest, TextureBorderClampValidation)
3196{
Jamie Madillb8149072019-04-30 16:14:44 -04003197 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003198
3199 glActiveTexture(GL_TEXTURE0);
3200 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3201
3202 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, 1.0f);
3203 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3204
3205 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3206 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3207
3208 glTexParameterfv(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3209 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3210
3211 GLint colorInt[4] = {0};
3212 glTexParameteriv(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_BORDER_COLOR, colorInt);
3213 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3214
3215 if (getClientMajorVersion() < 3)
3216 {
3217 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3218 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3219 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3220 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3221
3222 GLuint colorUInt[4] = {0};
3223 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3224 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3225 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3226 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3227
3228 GLSampler sampler;
3229 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3230 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3231 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3232 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3233
3234 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3235 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3236 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3237 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3238 }
3239}
3240
3241class TextureBorderClampTestES3 : public TextureBorderClampTest
3242{
3243 protected:
3244 TextureBorderClampTestES3() : TextureBorderClampTest() {}
3245};
3246
3247// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3248// GL_CLAMP_TO_BORDER wrap mode (set with glSamplerParameter).
3249TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional)
3250{
Jamie Madillb8149072019-04-30 16:14:44 -04003251 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003252
3253 setUpProgram();
3254
3255 uploadTexture();
3256
3257 GLSampler sampler;
3258 glBindSampler(0, sampler);
3259 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3260 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3261 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3262 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3263 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3264 EXPECT_GL_NO_ERROR();
3265
3266 drawQuad(mProgram, "position", 0.5f);
3267
3268 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3269 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3270 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3271}
3272
3273// Test reading back GL_TEXTURE_BORDER_COLOR by glGetSamplerParameter.
3274TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional2)
3275{
Jamie Madillb8149072019-04-30 16:14:44 -04003276 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003277
3278 glActiveTexture(GL_TEXTURE0);
3279
3280 GLSampler sampler;
3281 glBindSampler(0, sampler);
3282
3283 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3284
3285 GLint colorFixedPoint[4] = {0};
3286 glGetSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3287 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3288 std::numeric_limits<GLint>::max()};
3289 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3290 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3291 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3292 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3293
3294 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3295 std::numeric_limits<GLint>::max()};
3296 glSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3297
3298 GLfloat color[4] = {0.0f};
3299 glGetSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, color);
3300 EXPECT_EQ(color[0], kFloatBlue.R);
3301 EXPECT_EQ(color[1], kFloatBlue.G);
3302 EXPECT_EQ(color[2], kFloatBlue.B);
3303 EXPECT_EQ(color[3], kFloatBlue.A);
3304
3305 constexpr GLint colorSomewhatRedInt[4] = {500000, 0, 0, std::numeric_limits<GLint>::max()};
3306 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedInt);
3307 GLint colorInt[4] = {0};
3308 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3309 EXPECT_EQ(colorInt[0], colorSomewhatRedInt[0]);
3310 EXPECT_EQ(colorInt[1], colorSomewhatRedInt[1]);
3311 EXPECT_EQ(colorInt[2], colorSomewhatRedInt[2]);
3312 EXPECT_EQ(colorInt[3], colorSomewhatRedInt[3]);
3313
3314 constexpr GLuint colorSomewhatRedUInt[4] = {500000, 0, 0, std::numeric_limits<GLuint>::max()};
3315 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedUInt);
3316 GLuint colorUInt[4] = {0};
3317 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3318 EXPECT_EQ(colorUInt[0], colorSomewhatRedUInt[0]);
3319 EXPECT_EQ(colorUInt[1], colorSomewhatRedUInt[1]);
3320 EXPECT_EQ(colorUInt[2], colorSomewhatRedUInt[2]);
3321 EXPECT_EQ(colorUInt[3], colorSomewhatRedUInt[3]);
3322
3323 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3324
3325 constexpr GLint colorSomewhatGreenInt[4] = {0, 500000, 0, std::numeric_limits<GLint>::max()};
3326 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenInt);
3327 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3328 EXPECT_EQ(colorInt[0], colorSomewhatGreenInt[0]);
3329 EXPECT_EQ(colorInt[1], colorSomewhatGreenInt[1]);
3330 EXPECT_EQ(colorInt[2], colorSomewhatGreenInt[2]);
3331 EXPECT_EQ(colorInt[3], colorSomewhatGreenInt[3]);
3332
3333 constexpr GLuint colorSomewhatGreenUInt[4] = {0, 500000, 0, std::numeric_limits<GLuint>::max()};
3334 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenUInt);
3335 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3336 EXPECT_EQ(colorUInt[0], colorSomewhatGreenUInt[0]);
3337 EXPECT_EQ(colorUInt[1], colorSomewhatGreenUInt[1]);
3338 EXPECT_EQ(colorUInt[2], colorSomewhatGreenUInt[2]);
3339 EXPECT_EQ(colorUInt[3], colorSomewhatGreenUInt[3]);
3340}
3341
3342// Test GL_TEXTURE_BORDER_COLOR parameter validation at glSamplerParameter.
3343TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Validation)
3344{
Jamie Madillb8149072019-04-30 16:14:44 -04003345 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003346
3347 glActiveTexture(GL_TEXTURE0);
3348
3349 GLSampler sampler;
3350 glBindSampler(0, sampler);
3351
3352 glSamplerParameterf(sampler, GL_TEXTURE_BORDER_COLOR, 1.0f);
3353 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3354
3355 glSamplerParameteri(sampler, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3356 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3357}
3358
3359class TextureBorderClampIntegerTestES3 : public Texture2DTest
3360{
3361 protected:
3362 TextureBorderClampIntegerTestES3() : Texture2DTest(), isUnsignedIntTest(false) {}
3363
Jamie Madill35cd7332018-12-02 12:03:33 -05003364 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003365 {
3366 return
3367 R"(#version 300 es
3368 out vec2 texcoord;
3369 in vec4 position;
3370
3371 void main()
3372 {
3373 gl_Position = vec4(position.xy, 0.0, 1.0);
3374 // texcoords in [-0.5, 1.5]
3375 texcoord = (position.xy) + 0.5;
3376 })";
3377 }
3378
Jamie Madillba319ba2018-12-29 10:29:33 -05003379 const char *getFragmentShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003380 {
Jamie Madill35cd7332018-12-02 12:03:33 -05003381 if (isUnsignedIntTest)
3382 {
3383 return "#version 300 es\n"
3384 "precision highp float;\n"
3385 "uniform highp usampler2D tex;\n"
3386 "in vec2 texcoord;\n"
3387 "out vec4 fragColor;\n"
Till Rathmannb8543632018-10-02 19:46:14 +02003388
Jamie Madill35cd7332018-12-02 12:03:33 -05003389 "void main()\n"
3390 "{\n"
3391 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3392 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3393 "fragColor = (texture(tex, texcoord).r == 150u)"
3394 " ? green : red;\n"
3395 "}\n";
3396 }
3397 else
3398 {
3399 return "#version 300 es\n"
3400 "precision highp float;\n"
3401 "uniform highp isampler2D tex;\n"
3402 "in vec2 texcoord;\n"
3403 "out vec4 fragColor;\n"
3404
3405 "void main()\n"
3406 "{\n"
3407 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3408 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3409 "fragColor = (texture(tex, texcoord).r == -50)"
3410 " ? green : red;\n"
3411 "}\n";
3412 }
Till Rathmannb8543632018-10-02 19:46:14 +02003413 }
3414
3415 void uploadTexture()
3416 {
3417 glActiveTexture(GL_TEXTURE0);
3418 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3419 if (isUnsignedIntTest)
3420 {
3421 std::vector<GLubyte> texData(4, 100);
3422 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE,
3423 texData.data());
3424 }
3425 else
3426 {
3427 std::vector<GLbyte> texData(4, 100);
3428 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8I, 1, 1, 0, GL_RGBA_INTEGER, GL_BYTE,
3429 texData.data());
3430 }
3431 EXPECT_GL_NO_ERROR();
3432 }
3433
3434 bool isUnsignedIntTest;
3435};
3436
3437// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3438// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3439TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger)
3440{
Yuly Novikov1dbbc7b2019-07-31 17:49:39 -04003441 // Fails on Win10 FYI x64 Release (AMD RX 550). http://anglebug.com/3760
3442 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsDesktopOpenGL());
3443
Jamie Madillb8149072019-04-30 16:14:44 -04003444 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003445
3446 setUpProgram();
3447
3448 uploadTexture();
3449
3450 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3451 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3452 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3453 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3454
3455 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3456 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3457
3458 EXPECT_GL_NO_ERROR();
3459
3460 drawQuad(mProgram, "position", 0.5f);
3461
3462 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3463 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3464 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3465}
3466
3467// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3468// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3469TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger2)
3470{
Yuly Novikov1dbbc7b2019-07-31 17:49:39 -04003471 // Fails on Win10 FYI x64 Release (AMD RX 550). http://anglebug.com/3760
3472 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsDesktopOpenGL());
3473
Jamie Madillb8149072019-04-30 16:14:44 -04003474 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003475
3476 setUpProgram();
3477
3478 uploadTexture();
3479
3480 GLSampler sampler;
3481 glBindSampler(0, sampler);
3482 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3483 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3484 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3485 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3486
3487 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3488 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3489
3490 EXPECT_GL_NO_ERROR();
3491
3492 drawQuad(mProgram, "position", 0.5f);
3493
3494 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3495 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3496 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3497}
3498
3499// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3500// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIuivOES).
3501TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned)
3502{
Jamie Madillb8149072019-04-30 16:14:44 -04003503 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003504
3505 isUnsignedIntTest = true;
3506
3507 setUpProgram();
3508
3509 uploadTexture();
3510
3511 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3512 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3513 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3514 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3515
3516 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3517 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3518
3519 EXPECT_GL_NO_ERROR();
3520
3521 drawQuad(mProgram, "position", 0.5f);
3522
3523 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3524 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3525 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3526}
3527
3528// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3529// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with
3530// glSamplerParameterIuivOES).
3531TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned2)
3532{
Jamie Madillb8149072019-04-30 16:14:44 -04003533 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003534
3535 isUnsignedIntTest = true;
3536
3537 setUpProgram();
3538
3539 uploadTexture();
3540
3541 GLSampler sampler;
3542 glBindSampler(0, sampler);
3543 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3544 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3545 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3546 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3547
3548 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3549 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3550
3551 EXPECT_GL_NO_ERROR();
3552
3553 drawQuad(mProgram, "position", 0.5f);
3554
3555 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3556 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3557 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3558}
3559
3560// ~GL_OES_texture_border_clamp
3561
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003562class TextureLimitsTest : public ANGLETest
3563{
3564 protected:
3565 struct RGBA8
3566 {
3567 uint8_t R, G, B, A;
3568 };
3569
3570 TextureLimitsTest()
3571 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
3572 {
3573 setWindowWidth(128);
3574 setWindowHeight(128);
3575 setConfigRedBits(8);
3576 setConfigGreenBits(8);
3577 setConfigBlueBits(8);
3578 setConfigAlphaBits(8);
3579 }
3580
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003581 void testSetUp() override
Jamie Madill0fdb9562018-09-17 17:18:43 -04003582 {
Jamie Madill0fdb9562018-09-17 17:18:43 -04003583 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
3584 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
3585 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
3586
3587 ASSERT_GL_NO_ERROR();
3588 }
3589
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003590 void testTearDown() override
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003591 {
3592 if (mProgram != 0)
3593 {
3594 glDeleteProgram(mProgram);
3595 mProgram = 0;
3596
3597 if (!mTextures.empty())
3598 {
3599 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
3600 }
3601 }
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003602 }
3603
3604 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
3605 GLint vertexTextureCount,
3606 GLint vertexActiveTextureCount,
3607 const std::string &fragPrefix,
3608 GLint fragmentTextureCount,
3609 GLint fragmentActiveTextureCount)
3610 {
3611 std::stringstream vertexShaderStr;
3612 vertexShaderStr << "attribute vec2 position;\n"
3613 << "varying vec4 color;\n"
3614 << "varying vec2 texCoord;\n";
3615
3616 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
3617 {
3618 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
3619 }
3620
3621 vertexShaderStr << "void main() {\n"
3622 << " gl_Position = vec4(position, 0, 1);\n"
3623 << " texCoord = (position * 0.5) + 0.5;\n"
3624 << " color = vec4(0);\n";
3625
3626 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
3627 {
3628 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
3629 << ", texCoord);\n";
3630 }
3631
3632 vertexShaderStr << "}";
3633
3634 std::stringstream fragmentShaderStr;
3635 fragmentShaderStr << "varying mediump vec4 color;\n"
3636 << "varying mediump vec2 texCoord;\n";
3637
3638 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
3639 {
3640 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
3641 }
3642
3643 fragmentShaderStr << "void main() {\n"
3644 << " gl_FragColor = color;\n";
3645
3646 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
3647 {
3648 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
3649 << ", texCoord);\n";
3650 }
3651
3652 fragmentShaderStr << "}";
3653
3654 const std::string &vertexShaderSource = vertexShaderStr.str();
3655 const std::string &fragmentShaderSource = fragmentShaderStr.str();
3656
Jamie Madill35cd7332018-12-02 12:03:33 -05003657 mProgram = CompileProgram(vertexShaderSource.c_str(), fragmentShaderSource.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003658 }
3659
3660 RGBA8 getPixel(GLint texIndex)
3661 {
3662 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3663 0, 255u};
3664 return pixel;
3665 }
3666
3667 void initTextures(GLint tex2DCount, GLint texCubeCount)
3668 {
3669 GLint totalCount = tex2DCount + texCubeCount;
3670 mTextures.assign(totalCount, 0);
3671 glGenTextures(totalCount, &mTextures[0]);
3672 ASSERT_GL_NO_ERROR();
3673
3674 std::vector<RGBA8> texData(16 * 16);
3675
3676 GLint texIndex = 0;
3677 for (; texIndex < tex2DCount; ++texIndex)
3678 {
3679 texData.assign(texData.size(), getPixel(texIndex));
3680 glActiveTexture(GL_TEXTURE0 + texIndex);
3681 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3682 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3683 &texData[0]);
3684 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3685 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3686 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3687 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3688 }
3689
3690 ASSERT_GL_NO_ERROR();
3691
3692 for (; texIndex < texCubeCount; ++texIndex)
3693 {
3694 texData.assign(texData.size(), getPixel(texIndex));
3695 glActiveTexture(GL_TEXTURE0 + texIndex);
3696 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3697 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3698 GL_UNSIGNED_BYTE, &texData[0]);
3699 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3700 GL_UNSIGNED_BYTE, &texData[0]);
3701 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3702 GL_UNSIGNED_BYTE, &texData[0]);
3703 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3704 GL_UNSIGNED_BYTE, &texData[0]);
3705 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3706 GL_UNSIGNED_BYTE, &texData[0]);
3707 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3708 GL_UNSIGNED_BYTE, &texData[0]);
3709 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3710 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3711 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3712 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3713 }
3714
3715 ASSERT_GL_NO_ERROR();
3716 }
3717
3718 void testWithTextures(GLint vertexTextureCount,
3719 const std::string &vertexTexturePrefix,
3720 GLint fragmentTextureCount,
3721 const std::string &fragmentTexturePrefix)
3722 {
3723 // Generate textures
3724 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3725
3726 glUseProgram(mProgram);
3727 RGBA8 expectedSum = {0};
3728 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3729 {
3730 std::stringstream uniformNameStr;
3731 uniformNameStr << vertexTexturePrefix << texIndex;
3732 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003733 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003734 ASSERT_NE(-1, location);
3735
3736 glUniform1i(location, texIndex);
3737 RGBA8 contribution = getPixel(texIndex);
3738 expectedSum.R += contribution.R;
3739 expectedSum.G += contribution.G;
3740 }
3741
3742 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3743 {
3744 std::stringstream uniformNameStr;
3745 uniformNameStr << fragmentTexturePrefix << texIndex;
3746 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003747 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003748 ASSERT_NE(-1, location);
3749
3750 glUniform1i(location, texIndex + vertexTextureCount);
3751 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3752 expectedSum.R += contribution.R;
3753 expectedSum.G += contribution.G;
3754 }
3755
3756 ASSERT_GE(256u, expectedSum.G);
3757
3758 drawQuad(mProgram, "position", 0.5f);
3759 ASSERT_GL_NO_ERROR();
3760 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3761 }
3762
3763 GLuint mProgram;
3764 std::vector<GLuint> mTextures;
3765 GLint mMaxVertexTextures;
3766 GLint mMaxFragmentTextures;
3767 GLint mMaxCombinedTextures;
3768};
3769
3770// Test rendering with the maximum vertex texture units.
3771TEST_P(TextureLimitsTest, MaxVertexTextures)
3772{
3773 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3774 ASSERT_NE(0u, mProgram);
3775 ASSERT_GL_NO_ERROR();
3776
3777 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3778}
3779
3780// Test rendering with the maximum fragment texture units.
3781TEST_P(TextureLimitsTest, MaxFragmentTextures)
3782{
3783 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3784 ASSERT_NE(0u, mProgram);
3785 ASSERT_GL_NO_ERROR();
3786
3787 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3788}
3789
3790// Test rendering with maximum combined texture units.
3791TEST_P(TextureLimitsTest, MaxCombinedTextures)
3792{
3793 GLint vertexTextures = mMaxVertexTextures;
3794
3795 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3796 {
3797 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3798 }
3799
3800 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3801 mMaxFragmentTextures, mMaxFragmentTextures);
3802 ASSERT_NE(0u, mProgram);
3803 ASSERT_GL_NO_ERROR();
3804
3805 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3806}
3807
3808// Negative test for exceeding the number of vertex textures
3809TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3810{
3811 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3812 0);
3813 ASSERT_EQ(0u, mProgram);
3814}
3815
3816// Negative test for exceeding the number of fragment textures
3817TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3818{
3819 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3820 mMaxFragmentTextures + 1);
3821 ASSERT_EQ(0u, mProgram);
3822}
3823
3824// Test active vertex textures under the limit, but excessive textures specified.
3825TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3826{
3827 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3828 ASSERT_NE(0u, mProgram);
3829 ASSERT_GL_NO_ERROR();
3830
3831 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3832}
3833
3834// Test active fragment textures under the limit, but excessive textures specified.
3835TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3836{
3837 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3838 mMaxFragmentTextures);
3839 ASSERT_NE(0u, mProgram);
3840 ASSERT_GL_NO_ERROR();
3841
3842 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3843}
3844
3845// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003846// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003847TEST_P(TextureLimitsTest, TextureTypeConflict)
3848{
Jamie Madill35cd7332018-12-02 12:03:33 -05003849 constexpr char kVS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003850 "attribute vec2 position;\n"
3851 "varying float color;\n"
3852 "uniform sampler2D tex2D;\n"
3853 "uniform samplerCube texCube;\n"
3854 "void main() {\n"
3855 " gl_Position = vec4(position, 0, 1);\n"
3856 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3857 " color = texture2D(tex2D, texCoord).x;\n"
3858 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3859 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05003860 constexpr char kFS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003861 "varying mediump float color;\n"
3862 "void main() {\n"
3863 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3864 "}";
3865
Jamie Madill35cd7332018-12-02 12:03:33 -05003866 mProgram = CompileProgram(kVS, kFS);
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003867 ASSERT_NE(0u, mProgram);
3868
3869 initTextures(1, 0);
3870
3871 glUseProgram(mProgram);
3872 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3873 ASSERT_NE(-1, tex2DLocation);
3874 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3875 ASSERT_NE(-1, texCubeLocation);
3876
3877 glUniform1i(tex2DLocation, 0);
3878 glUniform1i(texCubeLocation, 0);
3879 ASSERT_GL_NO_ERROR();
3880
3881 drawQuad(mProgram, "position", 0.5f);
3882 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3883}
3884
Vincent Lang25ab4512016-05-13 18:13:59 +02003885class Texture2DNorm16TestES3 : public Texture2DTestES3
3886{
3887 protected:
3888 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3889
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003890 void testSetUp() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003891 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003892 Texture2DTestES3::testSetUp();
Vincent Lang25ab4512016-05-13 18:13:59 +02003893
3894 glActiveTexture(GL_TEXTURE0);
3895 glGenTextures(3, mTextures);
3896 glGenFramebuffers(1, &mFBO);
3897 glGenRenderbuffers(1, &mRenderbuffer);
3898
3899 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3900 {
3901 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3902 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3903 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3904 }
3905
3906 glBindTexture(GL_TEXTURE_2D, 0);
3907
3908 ASSERT_GL_NO_ERROR();
3909 }
3910
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003911 void testTearDown() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003912 {
3913 glDeleteTextures(3, mTextures);
3914 glDeleteFramebuffers(1, &mFBO);
3915 glDeleteRenderbuffers(1, &mRenderbuffer);
3916
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003917 Texture2DTestES3::testTearDown();
Vincent Lang25ab4512016-05-13 18:13:59 +02003918 }
3919
3920 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3921 {
Geoff Langf607c602016-09-21 11:46:48 -04003922 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3923 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003924
3925 setUpProgram();
3926
3927 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3928 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3929 0);
3930
3931 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3932 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3933
3934 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003935 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003936
3937 EXPECT_GL_NO_ERROR();
3938
3939 drawQuad(mProgram, "position", 0.5f);
3940
Geoff Langf607c602016-09-21 11:46:48 -04003941 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003942
Jamie Madill50cf2be2018-06-15 09:46:57 -04003943 EXPECT_PIXEL_COLOR_EQ(0, 0,
3944 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3945 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003946
3947 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3948
3949 ASSERT_GL_NO_ERROR();
3950 }
3951
3952 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3953 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04003954 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003955 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003956
3957 setUpProgram();
3958
3959 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3960 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3961
3962 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3963 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3964 0);
3965
3966 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003967 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003968
3969 EXPECT_GL_NO_ERROR();
3970
3971 drawQuad(mProgram, "position", 0.5f);
3972
Geoff Langf607c602016-09-21 11:46:48 -04003973 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
Jamie Madill50cf2be2018-06-15 09:46:57 -04003974 EXPECT_PIXEL_COLOR_EQ(0, 0,
3975 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3976 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003977
3978 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3979 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3980 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3981 mRenderbuffer);
3982 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3983 EXPECT_GL_NO_ERROR();
3984
3985 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3986 glClear(GL_COLOR_BUFFER_BIT);
3987
3988 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3989
Geoff Langf607c602016-09-21 11:46:48 -04003990 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003991
3992 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3993
3994 ASSERT_GL_NO_ERROR();
3995 }
3996
3997 GLuint mTextures[3];
3998 GLuint mFBO;
3999 GLuint mRenderbuffer;
4000};
4001
4002// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
4003TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
4004{
Jamie Madillb8149072019-04-30 16:14:44 -04004005 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02004006
4007 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
4008 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
4009 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
4010 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
4011 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
4012 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
4013 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
4014 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
4015
4016 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
4017 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
4018 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
4019}
4020
Mohan Maiya8f1169e2019-06-27 15:32:32 -07004021class Texture2DRGTest : public Texture2DTest
4022{
4023 protected:
4024 Texture2DRGTest()
4025 : Texture2DTest(), mRenderableTexture(0), mTestTexture(0), mFBO(0), mRenderbuffer(0)
4026 {}
4027
4028 void testSetUp() override
4029 {
4030 Texture2DTest::testSetUp();
4031
4032 glActiveTexture(GL_TEXTURE0);
4033 glGenTextures(1, &mRenderableTexture);
4034 glGenTextures(1, &mTestTexture);
4035 glGenFramebuffers(1, &mFBO);
4036 glGenRenderbuffers(1, &mRenderbuffer);
4037
4038 glBindTexture(GL_TEXTURE_2D, mRenderableTexture);
4039 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4040 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4041 glBindTexture(GL_TEXTURE_2D, mTestTexture);
4042 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4043 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4044
4045 glBindTexture(GL_TEXTURE_2D, 0);
4046
4047 setUpProgram();
4048 glUseProgram(mProgram);
4049 glUniform1i(mTexture2DUniformLocation, 0);
4050
4051 ASSERT_GL_NO_ERROR();
4052 }
4053
4054 void testTearDown() override
4055 {
4056 glDeleteTextures(1, &mRenderableTexture);
4057 glDeleteTextures(1, &mTestTexture);
4058 glDeleteFramebuffers(1, &mFBO);
4059 glDeleteRenderbuffers(1, &mRenderbuffer);
4060
4061 Texture2DTest::testTearDown();
4062 }
4063
4064 void setupFormatTextures(GLenum internalformat, GLenum format, GLenum type, GLvoid *imageData)
4065 {
4066 glBindTexture(GL_TEXTURE_2D, mRenderableTexture);
4067 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4068
4069 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
4070 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
4071 mRenderableTexture, 0);
4072
4073 glBindTexture(GL_TEXTURE_2D, mTestTexture);
4074 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
4075
4076 EXPECT_GL_NO_ERROR();
4077 }
4078
4079 void testRGTexture(GLColor expectedColor)
4080 {
4081 drawQuad(mProgram, "position", 0.5f);
4082
4083 EXPECT_GL_NO_ERROR();
4084 EXPECT_PIXEL_COLOR_NEAR(0, 0, expectedColor, kPixelTolerance);
4085 }
4086
4087 void testRGRender(GLenum internalformat, GLenum format)
4088 {
4089 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
4090 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
4091 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
4092 mRenderbuffer);
4093 glBindRenderbuffer(GL_RENDERBUFFER, 0);
4094 EXPECT_GL_NO_ERROR();
4095
4096 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
4097 glClear(GL_COLOR_BUFFER_BIT);
4098
4099 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
4100
4101 ASSERT_GL_NO_ERROR();
4102 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor(255u, 255u, 255u, 255u)));
4103 }
4104
4105 GLuint mRenderableTexture;
4106 GLuint mTestTexture;
4107 GLuint mFBO;
4108 GLuint mRenderbuffer;
4109};
4110
4111// Test unorm texture formats enabled by the GL_EXT_texture_rg extension.
4112TEST_P(Texture2DRGTest, TextureRGUNormTest)
4113{
4114 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_rg"));
4115
4116 GLubyte pixelValue = 0xab;
4117 GLubyte imageData[] = {pixelValue, pixelValue};
4118
4119 setupFormatTextures(GL_RED_EXT, GL_RED_EXT, GL_UNSIGNED_BYTE, imageData);
4120 testRGTexture(
4121 SliceFormatColor(GL_RED_EXT, GLColor(pixelValue, pixelValue, pixelValue, pixelValue)));
4122 testRGRender(GL_R8_EXT, GL_RED_EXT);
4123
4124 setupFormatTextures(GL_RG_EXT, GL_RG_EXT, GL_UNSIGNED_BYTE, imageData);
4125 testRGTexture(
4126 SliceFormatColor(GL_RG_EXT, GLColor(pixelValue, pixelValue, pixelValue, pixelValue)));
4127 testRGRender(GL_RG8_EXT, GL_RG_EXT);
4128}
4129
4130// Test float texture formats enabled by the GL_EXT_texture_rg extension.
4131TEST_P(Texture2DRGTest, TextureRGFloatTest)
4132{
4133 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_rg"));
4134 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
4135
4136 GLfloat pixelValue = 0.54321;
4137 GLfloat imageData[] = {pixelValue, pixelValue};
4138
4139 GLubyte expectedValue = static_cast<GLubyte>(pixelValue * 255.0f);
4140 GLColor expectedColor = GLColor(expectedValue, expectedValue, expectedValue, expectedValue);
4141
4142 setupFormatTextures(GL_RED_EXT, GL_RED_EXT, GL_FLOAT, imageData);
4143 testRGTexture(SliceFormatColor(GL_RED_EXT, expectedColor));
4144
4145 setupFormatTextures(GL_RG_EXT, GL_RG_EXT, GL_FLOAT, imageData);
4146 testRGTexture(SliceFormatColor(GL_RG_EXT, expectedColor));
4147}
4148
4149// Test half-float texture formats enabled by the GL_EXT_texture_rg extension.
4150TEST_P(Texture2DRGTest, TextureRGFHalfFloatTest)
4151{
4152 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_rg"));
4153 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_half_float"));
4154
4155 GLfloat pixelValueFloat = 0.543f;
4156 GLhalf pixelValue = 0x3858;
4157 GLhalf imageData[] = {pixelValue, pixelValue};
4158
4159 GLubyte expectedValue = static_cast<GLubyte>(pixelValueFloat * 255.0f);
4160 GLColor expectedColor = GLColor(expectedValue, expectedValue, expectedValue, expectedValue);
4161
4162 setupFormatTextures(GL_RED_EXT, GL_RED_EXT, GL_HALF_FLOAT_OES, imageData);
4163 testRGTexture(SliceFormatColor(GL_RED_EXT, expectedColor));
4164
4165 setupFormatTextures(GL_RG_EXT, GL_RG_EXT, GL_HALF_FLOAT_OES, imageData);
4166 testRGTexture(SliceFormatColor(GL_RG_EXT, expectedColor));
4167}
4168
Olli Etuaho95faa232016-06-07 14:01:53 -07004169// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
4170// GLES 3.0.4 section 3.8.3.
4171TEST_P(Texture2DTestES3, UnpackSkipImages2D)
4172{
Yuly Novikovd18c0482019-04-04 19:56:43 -04004173 // Crashes on Nexus 5X due to a driver bug. http://anglebug.com/1429
4174 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07004175
4176 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4177 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4178 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4179 ASSERT_GL_NO_ERROR();
4180
4181 // SKIP_IMAGES should not have an effect on uploading 2D textures
4182 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
4183 ASSERT_GL_NO_ERROR();
4184
4185 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
4186
4187 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4188 pixelsGreen.data());
4189 ASSERT_GL_NO_ERROR();
4190
4191 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
4192 pixelsGreen.data());
4193 ASSERT_GL_NO_ERROR();
4194
4195 glUseProgram(mProgram);
4196 drawQuad(mProgram, "position", 0.5f);
4197 ASSERT_GL_NO_ERROR();
4198
4199 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
4200}
4201
Olli Etuaho989cac32016-06-08 16:18:49 -07004202// Test that skip defined in unpack parameters is taken into account when determining whether
4203// unpacking source extends outside unpack buffer bounds.
4204TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
4205{
4206 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4207 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4208 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4209 ASSERT_GL_NO_ERROR();
4210
4211 GLBuffer buf;
4212 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
4213 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
4214 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
4215 GL_DYNAMIC_COPY);
4216 ASSERT_GL_NO_ERROR();
4217
4218 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4219 ASSERT_GL_NO_ERROR();
4220
4221 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
4222 ASSERT_GL_NO_ERROR();
4223
4224 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4225 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4226
4227 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
4228 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
4229 ASSERT_GL_NO_ERROR();
4230
4231 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4232 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4233}
4234
Olli Etuaho218cf9e2016-05-20 13:55:24 +03004235// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
4236TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
4237{
Yunchao He9550c602018-02-13 14:47:05 +08004238 ANGLE_SKIP_TEST_IF(IsD3D11());
4239
4240 // Incorrect rendering results seen on OSX AMD.
4241 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03004242
4243 const GLuint width = 8u;
4244 const GLuint height = 8u;
4245 const GLuint unpackRowLength = 5u;
4246 const GLuint unpackSkipPixels = 1u;
4247
4248 setWindowWidth(width);
4249 setWindowHeight(height);
4250
4251 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4252 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4253 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4254 ASSERT_GL_NO_ERROR();
4255
4256 GLBuffer buf;
4257 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
4258 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
4259 GLColor::green);
4260
4261 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
4262 {
4263 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
4264 }
4265
4266 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
4267 GL_DYNAMIC_COPY);
4268 ASSERT_GL_NO_ERROR();
4269
4270 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
4271 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
4272 ASSERT_GL_NO_ERROR();
4273
4274 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4275 ASSERT_GL_NO_ERROR();
4276
4277 glUseProgram(mProgram);
4278 drawQuad(mProgram, "position", 0.5f);
4279 ASSERT_GL_NO_ERROR();
4280
4281 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
4282 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
4283 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
4284 actual.data());
4285 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
4286 EXPECT_EQ(expected, actual);
4287}
4288
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004289template <typename T>
4290T UNorm(double value)
4291{
4292 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
4293}
4294
4295// Test rendering a depth texture with mipmaps.
4296TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
4297{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08004298 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
4299 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
Jiawei Shaoaf0f31d2018-09-27 15:42:31 +08004300 // http://anglebug.com/1706
4301 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Corentin Walleze731d8a2016-09-07 10:56:25 -04004302
Jamie Madill24980272019-04-03 09:03:51 -04004303 // Seems to fail on AMD D3D11. Possibly driver bug. http://anglebug.com/3342
4304 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsD3D11());
4305
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004306 const int size = getWindowWidth();
4307
4308 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04004309 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004310
4311 glActiveTexture(GL_TEXTURE0);
4312 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4313 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
4314 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4315 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4316 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
4317 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
4318 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4319 ASSERT_GL_NO_ERROR();
4320
4321 glUseProgram(mProgram);
4322 glUniform1i(mTexture2DUniformLocation, 0);
4323
4324 std::vector<unsigned char> expected;
4325
4326 for (int level = 0; level < levels; ++level)
4327 {
4328 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
4329 expected.push_back(UNorm<unsigned char>(value));
4330
4331 int levelDim = dim(level);
4332
4333 ASSERT_GT(levelDim, 0);
4334
4335 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
4336 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
4337 GL_UNSIGNED_INT, initData.data());
4338 }
4339 ASSERT_GL_NO_ERROR();
4340
4341 for (int level = 0; level < levels; ++level)
4342 {
4343 glViewport(0, 0, dim(level), dim(level));
4344 drawQuad(mProgram, "position", 0.5f);
4345 GLColor actual = ReadColor(0, 0);
4346 EXPECT_NEAR(expected[level], actual.R, 10u);
4347 }
4348
4349 ASSERT_GL_NO_ERROR();
4350}
4351
Jamie Madill7ffdda92016-09-08 13:26:51 -04004352// Tests unpacking into the unsized GL_ALPHA format.
4353TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
4354{
Jamie Madill7ffdda92016-09-08 13:26:51 -04004355 // Initialize the texure.
4356 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4357 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
4358 GL_UNSIGNED_BYTE, nullptr);
4359 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4360 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4361
4362 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
4363
4364 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04004365 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04004366 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4367 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4368 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
4369 GL_STATIC_DRAW);
4370
4371 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
4372 GL_UNSIGNED_BYTE, nullptr);
4373
4374 // Clear to a weird color to make sure we're drawing something.
4375 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
4376 glClear(GL_COLOR_BUFFER_BIT);
4377
4378 // Draw with the alpha texture and verify.
4379 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04004380
4381 ASSERT_GL_NO_ERROR();
4382 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
4383}
4384
Jamie Madill2e600342016-09-19 13:56:40 -04004385// Ensure stale unpack data doesn't propagate in D3D11.
4386TEST_P(Texture2DTestES3, StaleUnpackData)
4387{
4388 // Init unpack buffer.
4389 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
4390 std::vector<GLColor> pixels(pixelCount, GLColor::red);
4391
4392 GLBuffer unpackBuffer;
4393 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4394 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4395 GLsizei bufferSize = pixelCount * sizeof(GLColor);
4396 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
4397
4398 // Create from unpack buffer.
4399 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4400 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
4401 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4402 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4403 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4404
4405 drawQuad(mProgram, "position", 0.5f);
4406
4407 ASSERT_GL_NO_ERROR();
4408 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4409
4410 // Fill unpack with green, recreating buffer.
4411 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
4412 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
4413 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
4414
4415 // Reinit texture with green.
4416 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
4417 GL_UNSIGNED_BYTE, nullptr);
4418
4419 drawQuad(mProgram, "position", 0.5f);
4420
4421 ASSERT_GL_NO_ERROR();
4422 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
4423}
4424
Geoff Langfb7685f2017-11-13 11:44:11 -05004425// Ensure that texture parameters passed as floats that are converted to ints are rounded before
4426// validating they are less than 0.
4427TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
4428{
4429 GLTexture texture;
4430 glBindTexture(GL_TEXTURE_2D, texture);
4431
4432 // Use a negative number that will round to zero when converted to an integer
4433 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
4434 // "Validation of values performed by state-setting commands is performed after conversion,
4435 // unless specified otherwise for a specific command."
4436 GLfloat param = -7.30157126e-07f;
4437 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
4438 EXPECT_GL_NO_ERROR();
4439
4440 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
4441 EXPECT_GL_NO_ERROR();
4442}
4443
Jamie Madillf097e232016-11-05 00:44:15 -04004444// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
4445// being properly checked, and the texture storage of the previous texture format was persisting.
4446// This would result in an ASSERT in debug and incorrect rendering in release.
4447// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
4448TEST_P(Texture3DTestES3, FormatRedefinitionBug)
4449{
4450 GLTexture tex;
4451 glBindTexture(GL_TEXTURE_3D, tex.get());
4452 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4453
4454 GLFramebuffer framebuffer;
4455 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
4456 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
4457
4458 glCheckFramebufferStatus(GL_FRAMEBUFFER);
4459
4460 std::vector<uint8_t> pixelData(100, 0);
4461
4462 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
4463 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
4464 pixelData.data());
4465
4466 ASSERT_GL_NO_ERROR();
4467}
4468
Corentin Wallezd2627992017-04-28 17:17:03 -04004469// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
4470TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
4471{
4472 // 2D tests
4473 {
4474 GLTexture tex;
4475 glBindTexture(GL_TEXTURE_2D, tex.get());
4476
4477 GLBuffer pbo;
4478 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4479
4480 // Test OOB
4481 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
4482 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4483 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4484
4485 // Test OOB
4486 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
4487 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4488 ASSERT_GL_NO_ERROR();
4489 }
4490
4491 // 3D tests
4492 {
4493 GLTexture tex;
4494 glBindTexture(GL_TEXTURE_3D, tex.get());
4495
4496 GLBuffer pbo;
4497 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4498
4499 // Test OOB
4500 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
4501 GL_STATIC_DRAW);
4502 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4503 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4504
4505 // Test OOB
4506 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
4507 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4508 ASSERT_GL_NO_ERROR();
4509 }
4510}
4511
Jamie Madill3ed60422017-09-07 11:32:52 -04004512// Tests behaviour with a single texture and multiple sampler objects.
4513TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
4514{
4515 GLint maxTextureUnits = 0;
4516 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
4517 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
4518
4519 constexpr int kSize = 16;
4520
4521 // Make a single-level texture, fill it with red.
4522 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
4523 GLTexture tex;
4524 glBindTexture(GL_TEXTURE_2D, tex);
4525 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4526 redColors.data());
4527 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4528 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4529
4530 // Simple sanity check.
4531 draw2DTexturedQuad(0.5f, 1.0f, true);
4532 ASSERT_GL_NO_ERROR();
4533 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4534
4535 // Bind texture to unit 1 with a sampler object making it incomplete.
4536 GLSampler sampler;
4537 glBindSampler(0, sampler);
4538 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4539 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4540
4541 // Make a mipmap texture, fill it with blue.
4542 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
4543 GLTexture mipmapTex;
4544 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4545 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4546 blueColors.data());
4547 glGenerateMipmap(GL_TEXTURE_2D);
4548
4549 // Draw with the sampler, expect blue.
4550 draw2DTexturedQuad(0.5f, 1.0f, true);
4551 ASSERT_GL_NO_ERROR();
4552 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
4553
4554 // Simple multitexturing program.
Jamie Madill35cd7332018-12-02 12:03:33 -05004555 constexpr char kVS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004556 "#version 300 es\n"
4557 "in vec2 position;\n"
4558 "out vec2 texCoord;\n"
4559 "void main()\n"
4560 "{\n"
4561 " gl_Position = vec4(position, 0, 1);\n"
4562 " texCoord = position * 0.5 + vec2(0.5);\n"
4563 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05004564
4565 constexpr char kFS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004566 "#version 300 es\n"
4567 "precision mediump float;\n"
4568 "in vec2 texCoord;\n"
4569 "uniform sampler2D tex1;\n"
4570 "uniform sampler2D tex2;\n"
4571 "uniform sampler2D tex3;\n"
4572 "uniform sampler2D tex4;\n"
4573 "out vec4 color;\n"
4574 "void main()\n"
4575 "{\n"
4576 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
4577 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
4578 "}";
4579
Jamie Madill35cd7332018-12-02 12:03:33 -05004580 ANGLE_GL_PROGRAM(program, kVS, kFS);
Jamie Madill3ed60422017-09-07 11:32:52 -04004581
4582 std::array<GLint, 4> texLocations = {
4583 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
4584 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
4585 for (GLint location : texLocations)
4586 {
4587 ASSERT_NE(-1, location);
4588 }
4589
4590 // Init the uniform data.
4591 glUseProgram(program);
4592 for (GLint location = 0; location < 4; ++location)
4593 {
4594 glUniform1i(texLocations[location], location);
4595 }
4596
4597 // Initialize four samplers
4598 GLSampler samplers[4];
4599
4600 // 0: non-mipped.
4601 glBindSampler(0, samplers[0]);
4602 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4603 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4604
4605 // 1: mipped.
4606 glBindSampler(1, samplers[1]);
4607 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4608 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4609
4610 // 2: non-mipped.
4611 glBindSampler(2, samplers[2]);
4612 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4613 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4614
4615 // 3: mipped.
4616 glBindSampler(3, samplers[3]);
4617 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4618 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4619
4620 // Bind two blue mipped textures and two single layer textures, should all draw.
4621 glActiveTexture(GL_TEXTURE0);
4622 glBindTexture(GL_TEXTURE_2D, tex);
4623
4624 glActiveTexture(GL_TEXTURE1);
4625 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4626
4627 glActiveTexture(GL_TEXTURE2);
4628 glBindTexture(GL_TEXTURE_2D, tex);
4629
4630 glActiveTexture(GL_TEXTURE3);
4631 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4632
4633 ASSERT_GL_NO_ERROR();
4634
4635 drawQuad(program, "position", 0.5f);
4636 ASSERT_GL_NO_ERROR();
4637 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
4638
4639 // Bind four single layer textures, two should be incomplete.
4640 glActiveTexture(GL_TEXTURE1);
4641 glBindTexture(GL_TEXTURE_2D, tex);
4642
4643 glActiveTexture(GL_TEXTURE3);
4644 glBindTexture(GL_TEXTURE_2D, tex);
4645
4646 drawQuad(program, "position", 0.5f);
4647 ASSERT_GL_NO_ERROR();
4648 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
4649}
4650
Martin Radev7e2c0d32017-09-15 14:25:42 +03004651// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
4652// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
4653// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
4654// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
4655// samples the cubemap using a direction vector (1,1,1).
4656TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
4657{
Yunchao He2f23f352018-02-11 22:11:37 +08004658 // Check http://anglebug.com/2155.
4659 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
4660
Jamie Madill35cd7332018-12-02 12:03:33 -05004661 constexpr char kVS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004662 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004663 precision mediump float;
4664 in vec3 pos;
4665 void main() {
4666 gl_Position = vec4(pos, 1.0);
4667 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03004668
Jamie Madill35cd7332018-12-02 12:03:33 -05004669 constexpr char kFS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004670 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004671 precision mediump float;
4672 out vec4 color;
4673 uniform samplerCube uTex;
4674 void main(){
4675 color = texture(uTex, vec3(1.0));
4676 })";
Jamie Madill35cd7332018-12-02 12:03:33 -05004677
4678 ANGLE_GL_PROGRAM(program, kVS, kFS);
Martin Radev7e2c0d32017-09-15 14:25:42 +03004679 glUseProgram(program);
4680
4681 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
4682 glActiveTexture(GL_TEXTURE0);
4683
4684 GLTexture cubeTex;
4685 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
4686
4687 const int kFaceWidth = 1;
4688 const int kFaceHeight = 1;
4689 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
4690 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4691 GL_UNSIGNED_BYTE, texData.data());
4692 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4693 GL_UNSIGNED_BYTE, texData.data());
4694 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4695 GL_UNSIGNED_BYTE, texData.data());
4696 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4697 GL_UNSIGNED_BYTE, texData.data());
4698 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4699 GL_UNSIGNED_BYTE, texData.data());
4700 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4701 GL_UNSIGNED_BYTE, texData.data());
4702 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4703 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4704 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
4705 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
4706 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
4707 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
4708
4709 drawQuad(program, "pos", 0.5f, 1.0f, true);
4710 ASSERT_GL_NO_ERROR();
4711
4712 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4713}
4714
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08004715// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
4716TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
4717{
4718 GLuint texture = create2DTexture();
4719
4720 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
4721 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4722
4723 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
4724 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4725
4726 glDeleteTextures(1, &texture);
4727 EXPECT_GL_NO_ERROR();
4728}
4729
Olli Etuaho023371b2018-04-24 17:43:32 +03004730// Test setting base level after calling generateMipmap on a LUMA texture.
4731// Covers http://anglebug.com/2498
4732TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA)
4733{
4734 glActiveTexture(GL_TEXTURE0);
4735 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4736
4737 constexpr const GLsizei kWidth = 8;
4738 constexpr const GLsizei kHeight = 8;
4739 std::array<GLubyte, kWidth * kHeight * 2> whiteData;
4740 whiteData.fill(255u);
4741
4742 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA,
4743 GL_UNSIGNED_BYTE, whiteData.data());
4744 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
4745 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4746 glGenerateMipmap(GL_TEXTURE_2D);
4747 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
4748 EXPECT_GL_NO_ERROR();
4749
4750 drawQuad(mProgram, "position", 0.5f);
4751 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4752}
4753
Till Rathmannc1551dc2018-08-15 17:04:49 +02004754// Covers a bug in the D3D11 backend: http://anglebug.com/2772
4755// When using a sampler the texture was created as if it has mipmaps,
4756// regardless what you specified in GL_TEXTURE_MIN_FILTER via
4757// glSamplerParameteri() -- mistakenly the default value
4758// GL_NEAREST_MIPMAP_LINEAR or the value set via glTexParameteri() was
4759// evaluated.
4760// If you didn't provide mipmaps and didn't let the driver generate them
4761// this led to not sampling your texture data when minification occurred.
4762TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping)
4763{
Jamie Madill35cd7332018-12-02 12:03:33 -05004764 constexpr char kVS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004765 "#version 300 es\n"
4766 "out vec2 texcoord;\n"
4767 "in vec4 position;\n"
4768 "void main()\n"
4769 "{\n"
4770 " gl_Position = vec4(position.xy * 0.1, 0.0, 1.0);\n"
4771 " texcoord = (position.xy * 0.5) + 0.5;\n"
4772 "}\n";
4773
Jamie Madill35cd7332018-12-02 12:03:33 -05004774 constexpr char kFS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004775 "#version 300 es\n"
4776 "precision highp float;\n"
4777 "uniform highp sampler2D tex;\n"
4778 "in vec2 texcoord;\n"
4779 "out vec4 fragColor;\n"
4780 "void main()\n"
4781 "{\n"
4782 " fragColor = texture(tex, texcoord);\n"
4783 "}\n";
Jamie Madill35cd7332018-12-02 12:03:33 -05004784
4785 ANGLE_GL_PROGRAM(program, kVS, kFS);
Till Rathmannc1551dc2018-08-15 17:04:49 +02004786
4787 GLSampler sampler;
4788 glBindSampler(0, sampler);
4789 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4790 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4791
4792 glActiveTexture(GL_TEXTURE0);
4793 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4794
4795 const GLsizei texWidth = getWindowWidth();
4796 const GLsizei texHeight = getWindowHeight();
4797 const std::vector<GLColor> whiteData(texWidth * texHeight, GLColor::white);
4798
4799 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4800 whiteData.data());
4801 EXPECT_GL_NO_ERROR();
4802
4803 drawQuad(program, "position", 0.5f);
4804 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, angle::GLColor::white);
4805}
4806
Anders Leinof6cbe442019-04-18 15:32:07 +03004807// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4808// texture is output.
4809TEST_P(Texture2DIntegerTestES3, IntegerTextureNonZeroBaseLevel)
4810{
Yuly Novikovd2683452019-05-23 16:11:19 -04004811 // http://anglebug.com/3478
4812 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsDesktopOpenGL());
4813
Anders Leinof6cbe442019-04-18 15:32:07 +03004814 glActiveTexture(GL_TEXTURE0);
4815 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4816 int width = getWindowWidth();
4817 int height = getWindowHeight();
4818 GLColor color = GLColor::green;
4819 std::vector<GLColor> pixels(width * height, color);
4820 GLint baseLevel = 1;
4821 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
4822 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4823 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4824 glTexImage2D(GL_TEXTURE_2D, baseLevel, GL_RGBA8UI, width, height, 0, GL_RGBA_INTEGER,
4825 GL_UNSIGNED_BYTE, pixels.data());
4826
4827 setUpProgram();
4828 glUseProgram(mProgram);
4829 glUniform1i(mTexture2DUniformLocation, 0);
4830 drawQuad(mProgram, "position", 0.5f);
4831
4832 EXPECT_GL_NO_ERROR();
4833 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4834 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4835}
4836
Anders Leino60cc7512019-05-06 09:25:27 +03004837// Draw a quad with an integer cube texture with a non-zero base level, and test that the color of
4838// the texture is output.
4839TEST_P(TextureCubeIntegerTestES3, IntegerCubeTextureNonZeroBaseLevel)
4840{
4841 // All output checks returned black, rather than the texture color.
4842 ANGLE_SKIP_TEST_IF(IsOSX() && IsOpenGL());
4843
4844 glActiveTexture(GL_TEXTURE0);
4845
4846 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
4847 GLint baseLevel = 1;
4848 int width = getWindowWidth();
4849 int height = getWindowHeight();
4850 GLColor color = GLColor::green;
4851 std::vector<GLColor> pixels(width * height, color);
4852 for (GLenum faceIndex = 0; faceIndex < 6; faceIndex++)
4853 {
4854 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, baseLevel, GL_RGBA8UI, width,
4855 height, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
4856 EXPECT_GL_NO_ERROR();
4857 }
4858 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, baseLevel);
4859 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4860 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4861
4862 glUseProgram(mProgram);
4863 glUniform1i(mTextureCubeUniformLocation, 0);
4864 drawQuad(mProgram, "position", 0.5f);
4865
4866 EXPECT_GL_NO_ERROR();
4867 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4868 EXPECT_PIXEL_COLOR_EQ(width - 1, 0, color);
4869 EXPECT_PIXEL_COLOR_EQ(0, height - 1, color);
4870 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4871}
4872
Anders Leinoe4452442019-05-09 13:29:49 +03004873// This test sets up a cube map with four distincly colored MIP levels.
4874// The size of the texture and the geometry is chosen such that levels 1 or 2 should be chosen at
4875// the corners of the screen.
4876TEST_P(TextureCubeIntegerEdgeTestES3, IntegerCubeTextureCorner)
4877{
4878 glActiveTexture(GL_TEXTURE0);
4879
4880 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
4881 int width = getWindowWidth();
4882 int height = getWindowHeight();
4883 ASSERT_EQ(width, height);
4884 GLColor color[4] = {GLColor::white, GLColor::green, GLColor::blue, GLColor::red};
4885 for (GLint level = 0; level < 4; level++)
4886 {
4887 for (GLenum faceIndex = 0; faceIndex < 6; faceIndex++)
4888 {
4889 int levelWidth = (2 * width) >> level;
4890 int levelHeight = (2 * height) >> level;
4891 std::vector<GLColor> pixels(levelWidth * levelHeight, color[level]);
4892 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, level, GL_RGBA8UI, levelWidth,
4893 levelHeight, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
4894 EXPECT_GL_NO_ERROR();
4895 }
4896 }
4897 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4898 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4899 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 3);
4900
4901 glUseProgram(mProgram);
4902 glUniform1i(mTextureCubeUniformLocation, 0);
4903 drawQuad(mProgram, "position", 0.5f);
4904
4905 ASSERT_GL_NO_ERROR();
4906 // Check that we do not read from levels 0 or 3. Levels 1 and 2 are both acceptable.
4907 EXPECT_EQ(ReadColor(0, 0).R, 0);
4908 EXPECT_EQ(ReadColor(width - 1, 0).R, 0);
4909 EXPECT_EQ(ReadColor(0, height - 1).R, 0);
4910 EXPECT_EQ(ReadColor(width - 1, height - 1).R, 0);
4911}
4912
Anders Leino1b6aded2019-05-20 12:56:34 +03004913// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4914// texture is output.
4915TEST_P(Texture2DIntegerProjectiveOffsetTestES3, NonZeroBaseLevel)
4916{
Jamie Madill29ac2742019-05-28 15:53:00 -04004917 // Fails on AMD: http://crbug.com/967796
Jamie Madill06055b52019-05-29 14:31:42 -04004918 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsOpenGL());
Jamie Madill29ac2742019-05-28 15:53:00 -04004919
Anders Leino1b6aded2019-05-20 12:56:34 +03004920 glActiveTexture(GL_TEXTURE0);
4921 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4922 int width = getWindowWidth();
4923 int height = getWindowHeight();
4924 GLColor color = GLColor::green;
4925 std::vector<GLColor> pixels(width * height, color);
4926 GLint baseLevel = 1;
4927 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
4928 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4929 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4930 glTexImage2D(GL_TEXTURE_2D, baseLevel, GL_RGBA8UI, width, height, 0, GL_RGBA_INTEGER,
4931 GL_UNSIGNED_BYTE, pixels.data());
4932
4933 setUpProgram();
4934 glUseProgram(mProgram);
4935 glUniform1i(mTexture2DUniformLocation, 0);
4936 drawQuad(mProgram, "position", 0.5f);
4937
4938 EXPECT_GL_NO_ERROR();
4939 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4940 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4941}
4942
Anders Leino69d04932019-05-20 14:04:13 +03004943// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4944// texture is output.
4945TEST_P(Texture2DArrayIntegerTestES3, NonZeroBaseLevel)
4946{
4947 glActiveTexture(GL_TEXTURE0);
4948 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
4949 int width = getWindowWidth();
4950 int height = getWindowHeight();
4951 int depth = 2;
4952 GLColor color = GLColor::green;
4953 std::vector<GLColor> pixels(width * height * depth, color);
4954 GLint baseLevel = 1;
4955 glTexImage3D(GL_TEXTURE_2D_ARRAY, baseLevel, GL_RGBA8UI, width, height, depth, 0,
4956 GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
4957 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, baseLevel);
4958 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4959 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4960
4961 drawQuad(mProgram, "position", 0.5f);
4962
4963 EXPECT_GL_NO_ERROR();
4964 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4965 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4966}
4967
Anders Leino262e2822019-05-20 14:24:40 +03004968// Draw a quad with an integer 3D texture with a non-zero base level, and test that the color of the
4969// texture is output.
4970TEST_P(Texture3DIntegerTestES3, NonZeroBaseLevel)
4971{
4972 glActiveTexture(GL_TEXTURE0);
4973 glBindTexture(GL_TEXTURE_3D, mTexture3D);
4974 int width = getWindowWidth();
4975 int height = getWindowHeight();
4976 int depth = 2;
4977 GLColor color = GLColor::green;
4978 std::vector<GLColor> pixels(width * height * depth, color);
4979 GLint baseLevel = 1;
4980 glTexImage3D(GL_TEXTURE_3D, baseLevel, GL_RGBA8UI, width, height, depth, 0, GL_RGBA_INTEGER,
4981 GL_UNSIGNED_BYTE, pixels.data());
4982 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, baseLevel);
4983 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4984 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4985
4986 drawQuad(mProgram, "position", 0.5f);
4987
4988 EXPECT_GL_NO_ERROR();
4989 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4990 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4991}
4992
Jamie Madill50cf2be2018-06-15 09:46:57 -04004993// Use this to select which configurations (e.g. which renderer, which GLES major version) these
4994// tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -05004995ANGLE_INSTANTIATE_TEST(Texture2DTest,
4996 ES2_D3D9(),
4997 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004998 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05004999 ES2_OPENGLES(),
5000 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05005001ANGLE_INSTANTIATE_TEST(TextureCubeTest,
5002 ES2_D3D9(),
5003 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05005004 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04005005 ES2_OPENGLES(),
5006 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02005007ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
5008 ES2_D3D9(),
5009 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05005010 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04005011 ES2_OPENGLES(),
5012 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02005013ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
5014 ES2_D3D9(),
5015 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05005016 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005017 ES2_OPENGLES(),
5018 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05005019ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
5020 ES2_D3D9(),
5021 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05005022 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005023 ES2_OPENGLES(),
5024 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05005025ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
5026 ES2_D3D9(),
5027 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05005028 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005029 ES2_OPENGLES(),
5030 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05005031ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02005032ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
James Dong8bb6baa2019-06-18 15:30:16 -06005033ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3,
5034 ES3_D3D11(),
5035 ES3_OPENGL(),
5036 ES3_OPENGLES(),
5037 ES3_VULKAN());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02005038ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
5039 ES3_D3D11(),
5040 ES3_OPENGL(),
James Dong8bb6baa2019-06-18 15:30:16 -06005041 ES3_OPENGLES(),
5042 ES3_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05005043ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
5044 ES3_D3D11(),
5045 ES3_OPENGL(),
5046 ES3_OPENGLES());
James Dong8bb6baa2019-06-18 15:30:16 -06005047ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3,
5048 ES3_D3D11(),
5049 ES3_OPENGL(),
5050 ES3_OPENGLES(),
5051 ES3_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05005052ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02005053ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02005054ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
5055 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02005056 ES2_D3D9(),
5057 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005058 ES2_OPENGLES(),
5059 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02005060ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
5061 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02005062 ES2_D3D9(),
5063 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005064 ES2_OPENGLES(),
5065 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02005066ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
5067 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02005068 ES2_D3D9(),
5069 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005070 ES2_OPENGLES(),
5071 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02005072ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
5073 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02005074 ES2_D3D9(),
5075 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005076 ES2_OPENGLES(),
5077 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02005078ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
5079 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02005080 ES2_D3D9(),
5081 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005082 ES2_OPENGLES(),
5083 ES2_VULKAN());
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05005084ANGLE_INSTANTIATE_TEST(TextureAnisotropyTest,
5085 ES2_D3D11(),
5086 ES2_D3D9(),
5087 ES2_OPENGL(),
5088 ES2_OPENGLES(),
5089 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02005090ANGLE_INSTANTIATE_TEST(TextureBorderClampTest,
5091 ES2_D3D11(),
5092 ES2_D3D9(),
5093 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005094 ES2_OPENGLES(),
5095 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02005096ANGLE_INSTANTIATE_TEST(TextureBorderClampTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
5097ANGLE_INSTANTIATE_TEST(TextureBorderClampIntegerTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Luc Ferronaf883622018-06-08 15:57:31 -04005098ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN());
Vincent Lang25ab4512016-05-13 18:13:59 +02005099ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Mohan Maiya8f1169e2019-06-27 15:32:32 -07005100ANGLE_INSTANTIATE_TEST(Texture2DRGTest,
5101 ES2_D3D11(),
5102 ES3_D3D11(),
5103 ES2_OPENGL(),
5104 ES3_OPENGL(),
5105 ES2_OPENGLES(),
5106 ES3_OPENGLES(),
5107 ES2_VULKAN(),
5108 ES3_VULKAN());
Martin Radev7e2c0d32017-09-15 14:25:42 +03005109ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Anders Leinof6cbe442019-04-18 15:32:07 +03005110ANGLE_INSTANTIATE_TEST(Texture2DIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino60cc7512019-05-06 09:25:27 +03005111ANGLE_INSTANTIATE_TEST(TextureCubeIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leinoe4452442019-05-09 13:29:49 +03005112ANGLE_INSTANTIATE_TEST(TextureCubeIntegerEdgeTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino1b6aded2019-05-20 12:56:34 +03005113ANGLE_INSTANTIATE_TEST(Texture2DIntegerProjectiveOffsetTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino69d04932019-05-20 14:04:13 +03005114ANGLE_INSTANTIATE_TEST(Texture2DArrayIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino262e2822019-05-20 14:24:40 +03005115ANGLE_INSTANTIATE_TEST(Texture3DIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Jamie Madillfa05f602015-05-07 13:47:11 -04005116
Jamie Madill7ffdda92016-09-08 13:26:51 -04005117} // anonymous namespace