blob: 64720b802745889e1497797d46903292a29e2328 [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{
Jamie Madillb8149072019-04-30 16:14:44 -04003441 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003442
3443 setUpProgram();
3444
3445 uploadTexture();
3446
3447 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3448 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3449 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3450 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3451
3452 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3453 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3454
3455 EXPECT_GL_NO_ERROR();
3456
3457 drawQuad(mProgram, "position", 0.5f);
3458
3459 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3460 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3461 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3462}
3463
3464// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3465// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3466TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger2)
3467{
Jamie Madillb8149072019-04-30 16:14:44 -04003468 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003469
3470 setUpProgram();
3471
3472 uploadTexture();
3473
3474 GLSampler sampler;
3475 glBindSampler(0, sampler);
3476 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3477 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3478 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3479 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3480
3481 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3482 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3483
3484 EXPECT_GL_NO_ERROR();
3485
3486 drawQuad(mProgram, "position", 0.5f);
3487
3488 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3489 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3490 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3491}
3492
3493// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3494// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIuivOES).
3495TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned)
3496{
Jamie Madillb8149072019-04-30 16:14:44 -04003497 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003498
3499 isUnsignedIntTest = true;
3500
3501 setUpProgram();
3502
3503 uploadTexture();
3504
3505 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3506 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3507 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3508 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3509
3510 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3511 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3512
3513 EXPECT_GL_NO_ERROR();
3514
3515 drawQuad(mProgram, "position", 0.5f);
3516
3517 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3518 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3519 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3520}
3521
3522// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3523// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with
3524// glSamplerParameterIuivOES).
3525TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned2)
3526{
Jamie Madillb8149072019-04-30 16:14:44 -04003527 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003528
3529 isUnsignedIntTest = true;
3530
3531 setUpProgram();
3532
3533 uploadTexture();
3534
3535 GLSampler sampler;
3536 glBindSampler(0, sampler);
3537 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3538 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3539 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3540 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3541
3542 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3543 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3544
3545 EXPECT_GL_NO_ERROR();
3546
3547 drawQuad(mProgram, "position", 0.5f);
3548
3549 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3550 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3551 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3552}
3553
3554// ~GL_OES_texture_border_clamp
3555
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003556class TextureLimitsTest : public ANGLETest
3557{
3558 protected:
3559 struct RGBA8
3560 {
3561 uint8_t R, G, B, A;
3562 };
3563
3564 TextureLimitsTest()
3565 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
3566 {
3567 setWindowWidth(128);
3568 setWindowHeight(128);
3569 setConfigRedBits(8);
3570 setConfigGreenBits(8);
3571 setConfigBlueBits(8);
3572 setConfigAlphaBits(8);
3573 }
3574
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003575 void testSetUp() override
Jamie Madill0fdb9562018-09-17 17:18:43 -04003576 {
Jamie Madill0fdb9562018-09-17 17:18:43 -04003577 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
3578 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
3579 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
3580
3581 ASSERT_GL_NO_ERROR();
3582 }
3583
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003584 void testTearDown() override
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003585 {
3586 if (mProgram != 0)
3587 {
3588 glDeleteProgram(mProgram);
3589 mProgram = 0;
3590
3591 if (!mTextures.empty())
3592 {
3593 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
3594 }
3595 }
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003596 }
3597
3598 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
3599 GLint vertexTextureCount,
3600 GLint vertexActiveTextureCount,
3601 const std::string &fragPrefix,
3602 GLint fragmentTextureCount,
3603 GLint fragmentActiveTextureCount)
3604 {
3605 std::stringstream vertexShaderStr;
3606 vertexShaderStr << "attribute vec2 position;\n"
3607 << "varying vec4 color;\n"
3608 << "varying vec2 texCoord;\n";
3609
3610 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
3611 {
3612 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
3613 }
3614
3615 vertexShaderStr << "void main() {\n"
3616 << " gl_Position = vec4(position, 0, 1);\n"
3617 << " texCoord = (position * 0.5) + 0.5;\n"
3618 << " color = vec4(0);\n";
3619
3620 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
3621 {
3622 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
3623 << ", texCoord);\n";
3624 }
3625
3626 vertexShaderStr << "}";
3627
3628 std::stringstream fragmentShaderStr;
3629 fragmentShaderStr << "varying mediump vec4 color;\n"
3630 << "varying mediump vec2 texCoord;\n";
3631
3632 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
3633 {
3634 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
3635 }
3636
3637 fragmentShaderStr << "void main() {\n"
3638 << " gl_FragColor = color;\n";
3639
3640 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
3641 {
3642 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
3643 << ", texCoord);\n";
3644 }
3645
3646 fragmentShaderStr << "}";
3647
3648 const std::string &vertexShaderSource = vertexShaderStr.str();
3649 const std::string &fragmentShaderSource = fragmentShaderStr.str();
3650
Jamie Madill35cd7332018-12-02 12:03:33 -05003651 mProgram = CompileProgram(vertexShaderSource.c_str(), fragmentShaderSource.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003652 }
3653
3654 RGBA8 getPixel(GLint texIndex)
3655 {
3656 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3657 0, 255u};
3658 return pixel;
3659 }
3660
3661 void initTextures(GLint tex2DCount, GLint texCubeCount)
3662 {
3663 GLint totalCount = tex2DCount + texCubeCount;
3664 mTextures.assign(totalCount, 0);
3665 glGenTextures(totalCount, &mTextures[0]);
3666 ASSERT_GL_NO_ERROR();
3667
3668 std::vector<RGBA8> texData(16 * 16);
3669
3670 GLint texIndex = 0;
3671 for (; texIndex < tex2DCount; ++texIndex)
3672 {
3673 texData.assign(texData.size(), getPixel(texIndex));
3674 glActiveTexture(GL_TEXTURE0 + texIndex);
3675 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3676 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3677 &texData[0]);
3678 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3679 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3680 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3681 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3682 }
3683
3684 ASSERT_GL_NO_ERROR();
3685
3686 for (; texIndex < texCubeCount; ++texIndex)
3687 {
3688 texData.assign(texData.size(), getPixel(texIndex));
3689 glActiveTexture(GL_TEXTURE0 + texIndex);
3690 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3691 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3692 GL_UNSIGNED_BYTE, &texData[0]);
3693 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3694 GL_UNSIGNED_BYTE, &texData[0]);
3695 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3696 GL_UNSIGNED_BYTE, &texData[0]);
3697 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3698 GL_UNSIGNED_BYTE, &texData[0]);
3699 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3700 GL_UNSIGNED_BYTE, &texData[0]);
3701 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3702 GL_UNSIGNED_BYTE, &texData[0]);
3703 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3704 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3705 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3706 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3707 }
3708
3709 ASSERT_GL_NO_ERROR();
3710 }
3711
3712 void testWithTextures(GLint vertexTextureCount,
3713 const std::string &vertexTexturePrefix,
3714 GLint fragmentTextureCount,
3715 const std::string &fragmentTexturePrefix)
3716 {
3717 // Generate textures
3718 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3719
3720 glUseProgram(mProgram);
3721 RGBA8 expectedSum = {0};
3722 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3723 {
3724 std::stringstream uniformNameStr;
3725 uniformNameStr << vertexTexturePrefix << texIndex;
3726 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003727 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003728 ASSERT_NE(-1, location);
3729
3730 glUniform1i(location, texIndex);
3731 RGBA8 contribution = getPixel(texIndex);
3732 expectedSum.R += contribution.R;
3733 expectedSum.G += contribution.G;
3734 }
3735
3736 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3737 {
3738 std::stringstream uniformNameStr;
3739 uniformNameStr << fragmentTexturePrefix << texIndex;
3740 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003741 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003742 ASSERT_NE(-1, location);
3743
3744 glUniform1i(location, texIndex + vertexTextureCount);
3745 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3746 expectedSum.R += contribution.R;
3747 expectedSum.G += contribution.G;
3748 }
3749
3750 ASSERT_GE(256u, expectedSum.G);
3751
3752 drawQuad(mProgram, "position", 0.5f);
3753 ASSERT_GL_NO_ERROR();
3754 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3755 }
3756
3757 GLuint mProgram;
3758 std::vector<GLuint> mTextures;
3759 GLint mMaxVertexTextures;
3760 GLint mMaxFragmentTextures;
3761 GLint mMaxCombinedTextures;
3762};
3763
3764// Test rendering with the maximum vertex texture units.
3765TEST_P(TextureLimitsTest, MaxVertexTextures)
3766{
3767 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3768 ASSERT_NE(0u, mProgram);
3769 ASSERT_GL_NO_ERROR();
3770
3771 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3772}
3773
3774// Test rendering with the maximum fragment texture units.
3775TEST_P(TextureLimitsTest, MaxFragmentTextures)
3776{
3777 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3778 ASSERT_NE(0u, mProgram);
3779 ASSERT_GL_NO_ERROR();
3780
3781 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3782}
3783
3784// Test rendering with maximum combined texture units.
3785TEST_P(TextureLimitsTest, MaxCombinedTextures)
3786{
3787 GLint vertexTextures = mMaxVertexTextures;
3788
3789 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3790 {
3791 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3792 }
3793
3794 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3795 mMaxFragmentTextures, mMaxFragmentTextures);
3796 ASSERT_NE(0u, mProgram);
3797 ASSERT_GL_NO_ERROR();
3798
3799 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3800}
3801
3802// Negative test for exceeding the number of vertex textures
3803TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3804{
3805 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3806 0);
3807 ASSERT_EQ(0u, mProgram);
3808}
3809
3810// Negative test for exceeding the number of fragment textures
3811TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3812{
3813 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3814 mMaxFragmentTextures + 1);
3815 ASSERT_EQ(0u, mProgram);
3816}
3817
3818// Test active vertex textures under the limit, but excessive textures specified.
3819TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3820{
3821 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3822 ASSERT_NE(0u, mProgram);
3823 ASSERT_GL_NO_ERROR();
3824
3825 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3826}
3827
3828// Test active fragment textures under the limit, but excessive textures specified.
3829TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3830{
3831 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3832 mMaxFragmentTextures);
3833 ASSERT_NE(0u, mProgram);
3834 ASSERT_GL_NO_ERROR();
3835
3836 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3837}
3838
3839// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003840// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003841TEST_P(TextureLimitsTest, TextureTypeConflict)
3842{
Jamie Madill35cd7332018-12-02 12:03:33 -05003843 constexpr char kVS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003844 "attribute vec2 position;\n"
3845 "varying float color;\n"
3846 "uniform sampler2D tex2D;\n"
3847 "uniform samplerCube texCube;\n"
3848 "void main() {\n"
3849 " gl_Position = vec4(position, 0, 1);\n"
3850 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3851 " color = texture2D(tex2D, texCoord).x;\n"
3852 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3853 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05003854 constexpr char kFS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003855 "varying mediump float color;\n"
3856 "void main() {\n"
3857 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3858 "}";
3859
Jamie Madill35cd7332018-12-02 12:03:33 -05003860 mProgram = CompileProgram(kVS, kFS);
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003861 ASSERT_NE(0u, mProgram);
3862
3863 initTextures(1, 0);
3864
3865 glUseProgram(mProgram);
3866 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3867 ASSERT_NE(-1, tex2DLocation);
3868 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3869 ASSERT_NE(-1, texCubeLocation);
3870
3871 glUniform1i(tex2DLocation, 0);
3872 glUniform1i(texCubeLocation, 0);
3873 ASSERT_GL_NO_ERROR();
3874
3875 drawQuad(mProgram, "position", 0.5f);
3876 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3877}
3878
Vincent Lang25ab4512016-05-13 18:13:59 +02003879class Texture2DNorm16TestES3 : public Texture2DTestES3
3880{
3881 protected:
3882 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3883
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003884 void testSetUp() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003885 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003886 Texture2DTestES3::testSetUp();
Vincent Lang25ab4512016-05-13 18:13:59 +02003887
3888 glActiveTexture(GL_TEXTURE0);
3889 glGenTextures(3, mTextures);
3890 glGenFramebuffers(1, &mFBO);
3891 glGenRenderbuffers(1, &mRenderbuffer);
3892
3893 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3894 {
3895 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3896 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3897 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3898 }
3899
3900 glBindTexture(GL_TEXTURE_2D, 0);
3901
3902 ASSERT_GL_NO_ERROR();
3903 }
3904
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003905 void testTearDown() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003906 {
3907 glDeleteTextures(3, mTextures);
3908 glDeleteFramebuffers(1, &mFBO);
3909 glDeleteRenderbuffers(1, &mRenderbuffer);
3910
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003911 Texture2DTestES3::testTearDown();
Vincent Lang25ab4512016-05-13 18:13:59 +02003912 }
3913
3914 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3915 {
Geoff Langf607c602016-09-21 11:46:48 -04003916 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3917 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003918
3919 setUpProgram();
3920
3921 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3922 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3923 0);
3924
3925 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3926 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3927
3928 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003929 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003930
3931 EXPECT_GL_NO_ERROR();
3932
3933 drawQuad(mProgram, "position", 0.5f);
3934
Geoff Langf607c602016-09-21 11:46:48 -04003935 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003936
Jamie Madill50cf2be2018-06-15 09:46:57 -04003937 EXPECT_PIXEL_COLOR_EQ(0, 0,
3938 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3939 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003940
3941 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3942
3943 ASSERT_GL_NO_ERROR();
3944 }
3945
3946 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3947 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04003948 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003949 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003950
3951 setUpProgram();
3952
3953 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3954 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3955
3956 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3957 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3958 0);
3959
3960 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003961 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003962
3963 EXPECT_GL_NO_ERROR();
3964
3965 drawQuad(mProgram, "position", 0.5f);
3966
Geoff Langf607c602016-09-21 11:46:48 -04003967 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
Jamie Madill50cf2be2018-06-15 09:46:57 -04003968 EXPECT_PIXEL_COLOR_EQ(0, 0,
3969 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3970 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003971
3972 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3973 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3974 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3975 mRenderbuffer);
3976 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3977 EXPECT_GL_NO_ERROR();
3978
3979 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3980 glClear(GL_COLOR_BUFFER_BIT);
3981
3982 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3983
Geoff Langf607c602016-09-21 11:46:48 -04003984 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003985
3986 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3987
3988 ASSERT_GL_NO_ERROR();
3989 }
3990
3991 GLuint mTextures[3];
3992 GLuint mFBO;
3993 GLuint mRenderbuffer;
3994};
3995
3996// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3997TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3998{
Jamie Madillb8149072019-04-30 16:14:44 -04003999 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02004000
4001 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
4002 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
4003 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
4004 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
4005 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
4006 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
4007 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
4008 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
4009
4010 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
4011 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
4012 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
4013}
4014
Mohan Maiya8f1169e2019-06-27 15:32:32 -07004015class Texture2DRGTest : public Texture2DTest
4016{
4017 protected:
4018 Texture2DRGTest()
4019 : Texture2DTest(), mRenderableTexture(0), mTestTexture(0), mFBO(0), mRenderbuffer(0)
4020 {}
4021
4022 void testSetUp() override
4023 {
4024 Texture2DTest::testSetUp();
4025
4026 glActiveTexture(GL_TEXTURE0);
4027 glGenTextures(1, &mRenderableTexture);
4028 glGenTextures(1, &mTestTexture);
4029 glGenFramebuffers(1, &mFBO);
4030 glGenRenderbuffers(1, &mRenderbuffer);
4031
4032 glBindTexture(GL_TEXTURE_2D, mRenderableTexture);
4033 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4034 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4035 glBindTexture(GL_TEXTURE_2D, mTestTexture);
4036 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4037 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4038
4039 glBindTexture(GL_TEXTURE_2D, 0);
4040
4041 setUpProgram();
4042 glUseProgram(mProgram);
4043 glUniform1i(mTexture2DUniformLocation, 0);
4044
4045 ASSERT_GL_NO_ERROR();
4046 }
4047
4048 void testTearDown() override
4049 {
4050 glDeleteTextures(1, &mRenderableTexture);
4051 glDeleteTextures(1, &mTestTexture);
4052 glDeleteFramebuffers(1, &mFBO);
4053 glDeleteRenderbuffers(1, &mRenderbuffer);
4054
4055 Texture2DTest::testTearDown();
4056 }
4057
4058 void setupFormatTextures(GLenum internalformat, GLenum format, GLenum type, GLvoid *imageData)
4059 {
4060 glBindTexture(GL_TEXTURE_2D, mRenderableTexture);
4061 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4062
4063 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
4064 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
4065 mRenderableTexture, 0);
4066
4067 glBindTexture(GL_TEXTURE_2D, mTestTexture);
4068 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
4069
4070 EXPECT_GL_NO_ERROR();
4071 }
4072
4073 void testRGTexture(GLColor expectedColor)
4074 {
4075 drawQuad(mProgram, "position", 0.5f);
4076
4077 EXPECT_GL_NO_ERROR();
4078 EXPECT_PIXEL_COLOR_NEAR(0, 0, expectedColor, kPixelTolerance);
4079 }
4080
4081 void testRGRender(GLenum internalformat, GLenum format)
4082 {
4083 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
4084 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
4085 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
4086 mRenderbuffer);
4087 glBindRenderbuffer(GL_RENDERBUFFER, 0);
4088 EXPECT_GL_NO_ERROR();
4089
4090 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
4091 glClear(GL_COLOR_BUFFER_BIT);
4092
4093 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
4094
4095 ASSERT_GL_NO_ERROR();
4096 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor(255u, 255u, 255u, 255u)));
4097 }
4098
4099 GLuint mRenderableTexture;
4100 GLuint mTestTexture;
4101 GLuint mFBO;
4102 GLuint mRenderbuffer;
4103};
4104
4105// Test unorm texture formats enabled by the GL_EXT_texture_rg extension.
4106TEST_P(Texture2DRGTest, TextureRGUNormTest)
4107{
4108 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_rg"));
4109
4110 GLubyte pixelValue = 0xab;
4111 GLubyte imageData[] = {pixelValue, pixelValue};
4112
4113 setupFormatTextures(GL_RED_EXT, GL_RED_EXT, GL_UNSIGNED_BYTE, imageData);
4114 testRGTexture(
4115 SliceFormatColor(GL_RED_EXT, GLColor(pixelValue, pixelValue, pixelValue, pixelValue)));
4116 testRGRender(GL_R8_EXT, GL_RED_EXT);
4117
4118 setupFormatTextures(GL_RG_EXT, GL_RG_EXT, GL_UNSIGNED_BYTE, imageData);
4119 testRGTexture(
4120 SliceFormatColor(GL_RG_EXT, GLColor(pixelValue, pixelValue, pixelValue, pixelValue)));
4121 testRGRender(GL_RG8_EXT, GL_RG_EXT);
4122}
4123
4124// Test float texture formats enabled by the GL_EXT_texture_rg extension.
4125TEST_P(Texture2DRGTest, TextureRGFloatTest)
4126{
4127 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_rg"));
4128 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
4129
4130 GLfloat pixelValue = 0.54321;
4131 GLfloat imageData[] = {pixelValue, pixelValue};
4132
4133 GLubyte expectedValue = static_cast<GLubyte>(pixelValue * 255.0f);
4134 GLColor expectedColor = GLColor(expectedValue, expectedValue, expectedValue, expectedValue);
4135
4136 setupFormatTextures(GL_RED_EXT, GL_RED_EXT, GL_FLOAT, imageData);
4137 testRGTexture(SliceFormatColor(GL_RED_EXT, expectedColor));
4138
4139 setupFormatTextures(GL_RG_EXT, GL_RG_EXT, GL_FLOAT, imageData);
4140 testRGTexture(SliceFormatColor(GL_RG_EXT, expectedColor));
4141}
4142
4143// Test half-float texture formats enabled by the GL_EXT_texture_rg extension.
4144TEST_P(Texture2DRGTest, TextureRGFHalfFloatTest)
4145{
4146 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_rg"));
4147 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_half_float"));
4148
4149 GLfloat pixelValueFloat = 0.543f;
4150 GLhalf pixelValue = 0x3858;
4151 GLhalf imageData[] = {pixelValue, pixelValue};
4152
4153 GLubyte expectedValue = static_cast<GLubyte>(pixelValueFloat * 255.0f);
4154 GLColor expectedColor = GLColor(expectedValue, expectedValue, expectedValue, expectedValue);
4155
4156 setupFormatTextures(GL_RED_EXT, GL_RED_EXT, GL_HALF_FLOAT_OES, imageData);
4157 testRGTexture(SliceFormatColor(GL_RED_EXT, expectedColor));
4158
4159 setupFormatTextures(GL_RG_EXT, GL_RG_EXT, GL_HALF_FLOAT_OES, imageData);
4160 testRGTexture(SliceFormatColor(GL_RG_EXT, expectedColor));
4161}
4162
Olli Etuaho95faa232016-06-07 14:01:53 -07004163// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
4164// GLES 3.0.4 section 3.8.3.
4165TEST_P(Texture2DTestES3, UnpackSkipImages2D)
4166{
Yuly Novikovd18c0482019-04-04 19:56:43 -04004167 // Crashes on Nexus 5X due to a driver bug. http://anglebug.com/1429
4168 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07004169
4170 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4171 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4172 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4173 ASSERT_GL_NO_ERROR();
4174
4175 // SKIP_IMAGES should not have an effect on uploading 2D textures
4176 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
4177 ASSERT_GL_NO_ERROR();
4178
4179 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
4180
4181 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4182 pixelsGreen.data());
4183 ASSERT_GL_NO_ERROR();
4184
4185 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
4186 pixelsGreen.data());
4187 ASSERT_GL_NO_ERROR();
4188
4189 glUseProgram(mProgram);
4190 drawQuad(mProgram, "position", 0.5f);
4191 ASSERT_GL_NO_ERROR();
4192
4193 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
4194}
4195
Olli Etuaho989cac32016-06-08 16:18:49 -07004196// Test that skip defined in unpack parameters is taken into account when determining whether
4197// unpacking source extends outside unpack buffer bounds.
4198TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
4199{
4200 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4201 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4202 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4203 ASSERT_GL_NO_ERROR();
4204
4205 GLBuffer buf;
4206 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
4207 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
4208 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
4209 GL_DYNAMIC_COPY);
4210 ASSERT_GL_NO_ERROR();
4211
4212 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4213 ASSERT_GL_NO_ERROR();
4214
4215 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
4216 ASSERT_GL_NO_ERROR();
4217
4218 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4219 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4220
4221 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
4222 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
4223 ASSERT_GL_NO_ERROR();
4224
4225 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4226 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4227}
4228
Olli Etuaho218cf9e2016-05-20 13:55:24 +03004229// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
4230TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
4231{
Yunchao He9550c602018-02-13 14:47:05 +08004232 ANGLE_SKIP_TEST_IF(IsD3D11());
4233
4234 // Incorrect rendering results seen on OSX AMD.
4235 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03004236
4237 const GLuint width = 8u;
4238 const GLuint height = 8u;
4239 const GLuint unpackRowLength = 5u;
4240 const GLuint unpackSkipPixels = 1u;
4241
4242 setWindowWidth(width);
4243 setWindowHeight(height);
4244
4245 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4246 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4247 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4248 ASSERT_GL_NO_ERROR();
4249
4250 GLBuffer buf;
4251 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
4252 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
4253 GLColor::green);
4254
4255 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
4256 {
4257 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
4258 }
4259
4260 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
4261 GL_DYNAMIC_COPY);
4262 ASSERT_GL_NO_ERROR();
4263
4264 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
4265 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
4266 ASSERT_GL_NO_ERROR();
4267
4268 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4269 ASSERT_GL_NO_ERROR();
4270
4271 glUseProgram(mProgram);
4272 drawQuad(mProgram, "position", 0.5f);
4273 ASSERT_GL_NO_ERROR();
4274
4275 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
4276 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
4277 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
4278 actual.data());
4279 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
4280 EXPECT_EQ(expected, actual);
4281}
4282
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004283template <typename T>
4284T UNorm(double value)
4285{
4286 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
4287}
4288
4289// Test rendering a depth texture with mipmaps.
4290TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
4291{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08004292 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
4293 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
Jiawei Shaoaf0f31d2018-09-27 15:42:31 +08004294 // http://anglebug.com/1706
4295 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Corentin Walleze731d8a2016-09-07 10:56:25 -04004296
Jamie Madill24980272019-04-03 09:03:51 -04004297 // Seems to fail on AMD D3D11. Possibly driver bug. http://anglebug.com/3342
4298 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsD3D11());
4299
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004300 const int size = getWindowWidth();
4301
4302 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04004303 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004304
4305 glActiveTexture(GL_TEXTURE0);
4306 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4307 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
4308 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4309 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4310 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
4311 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
4312 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4313 ASSERT_GL_NO_ERROR();
4314
4315 glUseProgram(mProgram);
4316 glUniform1i(mTexture2DUniformLocation, 0);
4317
4318 std::vector<unsigned char> expected;
4319
4320 for (int level = 0; level < levels; ++level)
4321 {
4322 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
4323 expected.push_back(UNorm<unsigned char>(value));
4324
4325 int levelDim = dim(level);
4326
4327 ASSERT_GT(levelDim, 0);
4328
4329 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
4330 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
4331 GL_UNSIGNED_INT, initData.data());
4332 }
4333 ASSERT_GL_NO_ERROR();
4334
4335 for (int level = 0; level < levels; ++level)
4336 {
4337 glViewport(0, 0, dim(level), dim(level));
4338 drawQuad(mProgram, "position", 0.5f);
4339 GLColor actual = ReadColor(0, 0);
4340 EXPECT_NEAR(expected[level], actual.R, 10u);
4341 }
4342
4343 ASSERT_GL_NO_ERROR();
4344}
4345
Jamie Madill7ffdda92016-09-08 13:26:51 -04004346// Tests unpacking into the unsized GL_ALPHA format.
4347TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
4348{
Jamie Madill7ffdda92016-09-08 13:26:51 -04004349 // Initialize the texure.
4350 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4351 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
4352 GL_UNSIGNED_BYTE, nullptr);
4353 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4354 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4355
4356 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
4357
4358 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04004359 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04004360 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4361 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4362 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
4363 GL_STATIC_DRAW);
4364
4365 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
4366 GL_UNSIGNED_BYTE, nullptr);
4367
4368 // Clear to a weird color to make sure we're drawing something.
4369 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
4370 glClear(GL_COLOR_BUFFER_BIT);
4371
4372 // Draw with the alpha texture and verify.
4373 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04004374
4375 ASSERT_GL_NO_ERROR();
4376 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
4377}
4378
Jamie Madill2e600342016-09-19 13:56:40 -04004379// Ensure stale unpack data doesn't propagate in D3D11.
4380TEST_P(Texture2DTestES3, StaleUnpackData)
4381{
4382 // Init unpack buffer.
4383 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
4384 std::vector<GLColor> pixels(pixelCount, GLColor::red);
4385
4386 GLBuffer unpackBuffer;
4387 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4388 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4389 GLsizei bufferSize = pixelCount * sizeof(GLColor);
4390 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
4391
4392 // Create from unpack buffer.
4393 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4394 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
4395 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4396 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4397 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4398
4399 drawQuad(mProgram, "position", 0.5f);
4400
4401 ASSERT_GL_NO_ERROR();
4402 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4403
4404 // Fill unpack with green, recreating buffer.
4405 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
4406 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
4407 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
4408
4409 // Reinit texture with green.
4410 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
4411 GL_UNSIGNED_BYTE, nullptr);
4412
4413 drawQuad(mProgram, "position", 0.5f);
4414
4415 ASSERT_GL_NO_ERROR();
4416 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
4417}
4418
Geoff Langfb7685f2017-11-13 11:44:11 -05004419// Ensure that texture parameters passed as floats that are converted to ints are rounded before
4420// validating they are less than 0.
4421TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
4422{
4423 GLTexture texture;
4424 glBindTexture(GL_TEXTURE_2D, texture);
4425
4426 // Use a negative number that will round to zero when converted to an integer
4427 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
4428 // "Validation of values performed by state-setting commands is performed after conversion,
4429 // unless specified otherwise for a specific command."
4430 GLfloat param = -7.30157126e-07f;
4431 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
4432 EXPECT_GL_NO_ERROR();
4433
4434 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
4435 EXPECT_GL_NO_ERROR();
4436}
4437
Jamie Madillf097e232016-11-05 00:44:15 -04004438// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
4439// being properly checked, and the texture storage of the previous texture format was persisting.
4440// This would result in an ASSERT in debug and incorrect rendering in release.
4441// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
4442TEST_P(Texture3DTestES3, FormatRedefinitionBug)
4443{
4444 GLTexture tex;
4445 glBindTexture(GL_TEXTURE_3D, tex.get());
4446 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4447
4448 GLFramebuffer framebuffer;
4449 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
4450 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
4451
4452 glCheckFramebufferStatus(GL_FRAMEBUFFER);
4453
4454 std::vector<uint8_t> pixelData(100, 0);
4455
4456 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
4457 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
4458 pixelData.data());
4459
4460 ASSERT_GL_NO_ERROR();
4461}
4462
Corentin Wallezd2627992017-04-28 17:17:03 -04004463// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
4464TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
4465{
4466 // 2D tests
4467 {
4468 GLTexture tex;
4469 glBindTexture(GL_TEXTURE_2D, tex.get());
4470
4471 GLBuffer pbo;
4472 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4473
4474 // Test OOB
4475 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
4476 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4477 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4478
4479 // Test OOB
4480 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
4481 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4482 ASSERT_GL_NO_ERROR();
4483 }
4484
4485 // 3D tests
4486 {
4487 GLTexture tex;
4488 glBindTexture(GL_TEXTURE_3D, tex.get());
4489
4490 GLBuffer pbo;
4491 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4492
4493 // Test OOB
4494 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
4495 GL_STATIC_DRAW);
4496 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4497 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4498
4499 // Test OOB
4500 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
4501 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4502 ASSERT_GL_NO_ERROR();
4503 }
4504}
4505
Jamie Madill3ed60422017-09-07 11:32:52 -04004506// Tests behaviour with a single texture and multiple sampler objects.
4507TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
4508{
4509 GLint maxTextureUnits = 0;
4510 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
4511 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
4512
4513 constexpr int kSize = 16;
4514
4515 // Make a single-level texture, fill it with red.
4516 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
4517 GLTexture tex;
4518 glBindTexture(GL_TEXTURE_2D, tex);
4519 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4520 redColors.data());
4521 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4522 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4523
4524 // Simple sanity check.
4525 draw2DTexturedQuad(0.5f, 1.0f, true);
4526 ASSERT_GL_NO_ERROR();
4527 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4528
4529 // Bind texture to unit 1 with a sampler object making it incomplete.
4530 GLSampler sampler;
4531 glBindSampler(0, sampler);
4532 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4533 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4534
4535 // Make a mipmap texture, fill it with blue.
4536 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
4537 GLTexture mipmapTex;
4538 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4539 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4540 blueColors.data());
4541 glGenerateMipmap(GL_TEXTURE_2D);
4542
4543 // Draw with the sampler, expect blue.
4544 draw2DTexturedQuad(0.5f, 1.0f, true);
4545 ASSERT_GL_NO_ERROR();
4546 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
4547
4548 // Simple multitexturing program.
Jamie Madill35cd7332018-12-02 12:03:33 -05004549 constexpr char kVS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004550 "#version 300 es\n"
4551 "in vec2 position;\n"
4552 "out vec2 texCoord;\n"
4553 "void main()\n"
4554 "{\n"
4555 " gl_Position = vec4(position, 0, 1);\n"
4556 " texCoord = position * 0.5 + vec2(0.5);\n"
4557 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05004558
4559 constexpr char kFS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004560 "#version 300 es\n"
4561 "precision mediump float;\n"
4562 "in vec2 texCoord;\n"
4563 "uniform sampler2D tex1;\n"
4564 "uniform sampler2D tex2;\n"
4565 "uniform sampler2D tex3;\n"
4566 "uniform sampler2D tex4;\n"
4567 "out vec4 color;\n"
4568 "void main()\n"
4569 "{\n"
4570 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
4571 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
4572 "}";
4573
Jamie Madill35cd7332018-12-02 12:03:33 -05004574 ANGLE_GL_PROGRAM(program, kVS, kFS);
Jamie Madill3ed60422017-09-07 11:32:52 -04004575
4576 std::array<GLint, 4> texLocations = {
4577 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
4578 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
4579 for (GLint location : texLocations)
4580 {
4581 ASSERT_NE(-1, location);
4582 }
4583
4584 // Init the uniform data.
4585 glUseProgram(program);
4586 for (GLint location = 0; location < 4; ++location)
4587 {
4588 glUniform1i(texLocations[location], location);
4589 }
4590
4591 // Initialize four samplers
4592 GLSampler samplers[4];
4593
4594 // 0: non-mipped.
4595 glBindSampler(0, samplers[0]);
4596 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4597 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4598
4599 // 1: mipped.
4600 glBindSampler(1, samplers[1]);
4601 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4602 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4603
4604 // 2: non-mipped.
4605 glBindSampler(2, samplers[2]);
4606 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4607 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4608
4609 // 3: mipped.
4610 glBindSampler(3, samplers[3]);
4611 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4612 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4613
4614 // Bind two blue mipped textures and two single layer textures, should all draw.
4615 glActiveTexture(GL_TEXTURE0);
4616 glBindTexture(GL_TEXTURE_2D, tex);
4617
4618 glActiveTexture(GL_TEXTURE1);
4619 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4620
4621 glActiveTexture(GL_TEXTURE2);
4622 glBindTexture(GL_TEXTURE_2D, tex);
4623
4624 glActiveTexture(GL_TEXTURE3);
4625 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4626
4627 ASSERT_GL_NO_ERROR();
4628
4629 drawQuad(program, "position", 0.5f);
4630 ASSERT_GL_NO_ERROR();
4631 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
4632
4633 // Bind four single layer textures, two should be incomplete.
4634 glActiveTexture(GL_TEXTURE1);
4635 glBindTexture(GL_TEXTURE_2D, tex);
4636
4637 glActiveTexture(GL_TEXTURE3);
4638 glBindTexture(GL_TEXTURE_2D, tex);
4639
4640 drawQuad(program, "position", 0.5f);
4641 ASSERT_GL_NO_ERROR();
4642 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
4643}
4644
Martin Radev7e2c0d32017-09-15 14:25:42 +03004645// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
4646// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
4647// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
4648// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
4649// samples the cubemap using a direction vector (1,1,1).
4650TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
4651{
Yunchao He2f23f352018-02-11 22:11:37 +08004652 // Check http://anglebug.com/2155.
4653 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
4654
Jamie Madill35cd7332018-12-02 12:03:33 -05004655 constexpr char kVS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004656 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004657 precision mediump float;
4658 in vec3 pos;
4659 void main() {
4660 gl_Position = vec4(pos, 1.0);
4661 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03004662
Jamie Madill35cd7332018-12-02 12:03:33 -05004663 constexpr char kFS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004664 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004665 precision mediump float;
4666 out vec4 color;
4667 uniform samplerCube uTex;
4668 void main(){
4669 color = texture(uTex, vec3(1.0));
4670 })";
Jamie Madill35cd7332018-12-02 12:03:33 -05004671
4672 ANGLE_GL_PROGRAM(program, kVS, kFS);
Martin Radev7e2c0d32017-09-15 14:25:42 +03004673 glUseProgram(program);
4674
4675 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
4676 glActiveTexture(GL_TEXTURE0);
4677
4678 GLTexture cubeTex;
4679 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
4680
4681 const int kFaceWidth = 1;
4682 const int kFaceHeight = 1;
4683 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
4684 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4685 GL_UNSIGNED_BYTE, texData.data());
4686 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4687 GL_UNSIGNED_BYTE, texData.data());
4688 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4689 GL_UNSIGNED_BYTE, texData.data());
4690 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4691 GL_UNSIGNED_BYTE, texData.data());
4692 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4693 GL_UNSIGNED_BYTE, texData.data());
4694 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4695 GL_UNSIGNED_BYTE, texData.data());
4696 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4697 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4698 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
4699 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
4700 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
4701 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
4702
4703 drawQuad(program, "pos", 0.5f, 1.0f, true);
4704 ASSERT_GL_NO_ERROR();
4705
4706 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4707}
4708
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08004709// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
4710TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
4711{
4712 GLuint texture = create2DTexture();
4713
4714 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
4715 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4716
4717 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
4718 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4719
4720 glDeleteTextures(1, &texture);
4721 EXPECT_GL_NO_ERROR();
4722}
4723
Olli Etuaho023371b2018-04-24 17:43:32 +03004724// Test setting base level after calling generateMipmap on a LUMA texture.
4725// Covers http://anglebug.com/2498
4726TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA)
4727{
4728 glActiveTexture(GL_TEXTURE0);
4729 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4730
4731 constexpr const GLsizei kWidth = 8;
4732 constexpr const GLsizei kHeight = 8;
4733 std::array<GLubyte, kWidth * kHeight * 2> whiteData;
4734 whiteData.fill(255u);
4735
4736 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA,
4737 GL_UNSIGNED_BYTE, whiteData.data());
4738 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
4739 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4740 glGenerateMipmap(GL_TEXTURE_2D);
4741 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
4742 EXPECT_GL_NO_ERROR();
4743
4744 drawQuad(mProgram, "position", 0.5f);
4745 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4746}
4747
Till Rathmannc1551dc2018-08-15 17:04:49 +02004748// Covers a bug in the D3D11 backend: http://anglebug.com/2772
4749// When using a sampler the texture was created as if it has mipmaps,
4750// regardless what you specified in GL_TEXTURE_MIN_FILTER via
4751// glSamplerParameteri() -- mistakenly the default value
4752// GL_NEAREST_MIPMAP_LINEAR or the value set via glTexParameteri() was
4753// evaluated.
4754// If you didn't provide mipmaps and didn't let the driver generate them
4755// this led to not sampling your texture data when minification occurred.
4756TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping)
4757{
Jamie Madill35cd7332018-12-02 12:03:33 -05004758 constexpr char kVS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004759 "#version 300 es\n"
4760 "out vec2 texcoord;\n"
4761 "in vec4 position;\n"
4762 "void main()\n"
4763 "{\n"
4764 " gl_Position = vec4(position.xy * 0.1, 0.0, 1.0);\n"
4765 " texcoord = (position.xy * 0.5) + 0.5;\n"
4766 "}\n";
4767
Jamie Madill35cd7332018-12-02 12:03:33 -05004768 constexpr char kFS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004769 "#version 300 es\n"
4770 "precision highp float;\n"
4771 "uniform highp sampler2D tex;\n"
4772 "in vec2 texcoord;\n"
4773 "out vec4 fragColor;\n"
4774 "void main()\n"
4775 "{\n"
4776 " fragColor = texture(tex, texcoord);\n"
4777 "}\n";
Jamie Madill35cd7332018-12-02 12:03:33 -05004778
4779 ANGLE_GL_PROGRAM(program, kVS, kFS);
Till Rathmannc1551dc2018-08-15 17:04:49 +02004780
4781 GLSampler sampler;
4782 glBindSampler(0, sampler);
4783 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4784 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4785
4786 glActiveTexture(GL_TEXTURE0);
4787 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4788
4789 const GLsizei texWidth = getWindowWidth();
4790 const GLsizei texHeight = getWindowHeight();
4791 const std::vector<GLColor> whiteData(texWidth * texHeight, GLColor::white);
4792
4793 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4794 whiteData.data());
4795 EXPECT_GL_NO_ERROR();
4796
4797 drawQuad(program, "position", 0.5f);
4798 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, angle::GLColor::white);
4799}
4800
Anders Leinof6cbe442019-04-18 15:32:07 +03004801// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4802// texture is output.
4803TEST_P(Texture2DIntegerTestES3, IntegerTextureNonZeroBaseLevel)
4804{
Yuly Novikovd2683452019-05-23 16:11:19 -04004805 // http://anglebug.com/3478
4806 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsDesktopOpenGL());
4807
Anders Leinof6cbe442019-04-18 15:32:07 +03004808 glActiveTexture(GL_TEXTURE0);
4809 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4810 int width = getWindowWidth();
4811 int height = getWindowHeight();
4812 GLColor color = GLColor::green;
4813 std::vector<GLColor> pixels(width * height, color);
4814 GLint baseLevel = 1;
4815 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
4816 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4817 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4818 glTexImage2D(GL_TEXTURE_2D, baseLevel, GL_RGBA8UI, width, height, 0, GL_RGBA_INTEGER,
4819 GL_UNSIGNED_BYTE, pixels.data());
4820
4821 setUpProgram();
4822 glUseProgram(mProgram);
4823 glUniform1i(mTexture2DUniformLocation, 0);
4824 drawQuad(mProgram, "position", 0.5f);
4825
4826 EXPECT_GL_NO_ERROR();
4827 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4828 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4829}
4830
Anders Leino60cc7512019-05-06 09:25:27 +03004831// Draw a quad with an integer cube texture with a non-zero base level, and test that the color of
4832// the texture is output.
4833TEST_P(TextureCubeIntegerTestES3, IntegerCubeTextureNonZeroBaseLevel)
4834{
4835 // All output checks returned black, rather than the texture color.
4836 ANGLE_SKIP_TEST_IF(IsOSX() && IsOpenGL());
4837
4838 glActiveTexture(GL_TEXTURE0);
4839
4840 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
4841 GLint baseLevel = 1;
4842 int width = getWindowWidth();
4843 int height = getWindowHeight();
4844 GLColor color = GLColor::green;
4845 std::vector<GLColor> pixels(width * height, color);
4846 for (GLenum faceIndex = 0; faceIndex < 6; faceIndex++)
4847 {
4848 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, baseLevel, GL_RGBA8UI, width,
4849 height, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
4850 EXPECT_GL_NO_ERROR();
4851 }
4852 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, baseLevel);
4853 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4854 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4855
4856 glUseProgram(mProgram);
4857 glUniform1i(mTextureCubeUniformLocation, 0);
4858 drawQuad(mProgram, "position", 0.5f);
4859
4860 EXPECT_GL_NO_ERROR();
4861 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4862 EXPECT_PIXEL_COLOR_EQ(width - 1, 0, color);
4863 EXPECT_PIXEL_COLOR_EQ(0, height - 1, color);
4864 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4865}
4866
Anders Leinoe4452442019-05-09 13:29:49 +03004867// This test sets up a cube map with four distincly colored MIP levels.
4868// The size of the texture and the geometry is chosen such that levels 1 or 2 should be chosen at
4869// the corners of the screen.
4870TEST_P(TextureCubeIntegerEdgeTestES3, IntegerCubeTextureCorner)
4871{
4872 glActiveTexture(GL_TEXTURE0);
4873
4874 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
4875 int width = getWindowWidth();
4876 int height = getWindowHeight();
4877 ASSERT_EQ(width, height);
4878 GLColor color[4] = {GLColor::white, GLColor::green, GLColor::blue, GLColor::red};
4879 for (GLint level = 0; level < 4; level++)
4880 {
4881 for (GLenum faceIndex = 0; faceIndex < 6; faceIndex++)
4882 {
4883 int levelWidth = (2 * width) >> level;
4884 int levelHeight = (2 * height) >> level;
4885 std::vector<GLColor> pixels(levelWidth * levelHeight, color[level]);
4886 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, level, GL_RGBA8UI, levelWidth,
4887 levelHeight, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
4888 EXPECT_GL_NO_ERROR();
4889 }
4890 }
4891 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4892 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4893 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 3);
4894
4895 glUseProgram(mProgram);
4896 glUniform1i(mTextureCubeUniformLocation, 0);
4897 drawQuad(mProgram, "position", 0.5f);
4898
4899 ASSERT_GL_NO_ERROR();
4900 // Check that we do not read from levels 0 or 3. Levels 1 and 2 are both acceptable.
4901 EXPECT_EQ(ReadColor(0, 0).R, 0);
4902 EXPECT_EQ(ReadColor(width - 1, 0).R, 0);
4903 EXPECT_EQ(ReadColor(0, height - 1).R, 0);
4904 EXPECT_EQ(ReadColor(width - 1, height - 1).R, 0);
4905}
4906
Anders Leino1b6aded2019-05-20 12:56:34 +03004907// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4908// texture is output.
4909TEST_P(Texture2DIntegerProjectiveOffsetTestES3, NonZeroBaseLevel)
4910{
Jamie Madill29ac2742019-05-28 15:53:00 -04004911 // Fails on AMD: http://crbug.com/967796
Jamie Madill06055b52019-05-29 14:31:42 -04004912 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsOpenGL());
Jamie Madill29ac2742019-05-28 15:53:00 -04004913
Anders Leino1b6aded2019-05-20 12:56:34 +03004914 glActiveTexture(GL_TEXTURE0);
4915 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4916 int width = getWindowWidth();
4917 int height = getWindowHeight();
4918 GLColor color = GLColor::green;
4919 std::vector<GLColor> pixels(width * height, color);
4920 GLint baseLevel = 1;
4921 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
4922 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4923 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4924 glTexImage2D(GL_TEXTURE_2D, baseLevel, GL_RGBA8UI, width, height, 0, GL_RGBA_INTEGER,
4925 GL_UNSIGNED_BYTE, pixels.data());
4926
4927 setUpProgram();
4928 glUseProgram(mProgram);
4929 glUniform1i(mTexture2DUniformLocation, 0);
4930 drawQuad(mProgram, "position", 0.5f);
4931
4932 EXPECT_GL_NO_ERROR();
4933 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4934 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4935}
4936
Anders Leino69d04932019-05-20 14:04:13 +03004937// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4938// texture is output.
4939TEST_P(Texture2DArrayIntegerTestES3, NonZeroBaseLevel)
4940{
4941 glActiveTexture(GL_TEXTURE0);
4942 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
4943 int width = getWindowWidth();
4944 int height = getWindowHeight();
4945 int depth = 2;
4946 GLColor color = GLColor::green;
4947 std::vector<GLColor> pixels(width * height * depth, color);
4948 GLint baseLevel = 1;
4949 glTexImage3D(GL_TEXTURE_2D_ARRAY, baseLevel, GL_RGBA8UI, width, height, depth, 0,
4950 GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
4951 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, baseLevel);
4952 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4953 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4954
4955 drawQuad(mProgram, "position", 0.5f);
4956
4957 EXPECT_GL_NO_ERROR();
4958 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4959 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4960}
4961
Anders Leino262e2822019-05-20 14:24:40 +03004962// Draw a quad with an integer 3D texture with a non-zero base level, and test that the color of the
4963// texture is output.
4964TEST_P(Texture3DIntegerTestES3, NonZeroBaseLevel)
4965{
4966 glActiveTexture(GL_TEXTURE0);
4967 glBindTexture(GL_TEXTURE_3D, mTexture3D);
4968 int width = getWindowWidth();
4969 int height = getWindowHeight();
4970 int depth = 2;
4971 GLColor color = GLColor::green;
4972 std::vector<GLColor> pixels(width * height * depth, color);
4973 GLint baseLevel = 1;
4974 glTexImage3D(GL_TEXTURE_3D, baseLevel, GL_RGBA8UI, width, height, depth, 0, GL_RGBA_INTEGER,
4975 GL_UNSIGNED_BYTE, pixels.data());
4976 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, baseLevel);
4977 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4978 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4979
4980 drawQuad(mProgram, "position", 0.5f);
4981
4982 EXPECT_GL_NO_ERROR();
4983 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4984 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4985}
4986
Jamie Madill50cf2be2018-06-15 09:46:57 -04004987// Use this to select which configurations (e.g. which renderer, which GLES major version) these
4988// tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -05004989ANGLE_INSTANTIATE_TEST(Texture2DTest,
4990 ES2_D3D9(),
4991 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004992 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05004993 ES2_OPENGLES(),
4994 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004995ANGLE_INSTANTIATE_TEST(TextureCubeTest,
4996 ES2_D3D9(),
4997 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004998 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004999 ES2_OPENGLES(),
5000 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02005001ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
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(Sampler2DAsFunctionParameterTest,
5008 ES2_D3D9(),
5009 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05005010 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005011 ES2_OPENGLES(),
5012 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05005013ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
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(SamplerArrayAsFunctionParameterTest,
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(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02005026ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
James Dong8bb6baa2019-06-18 15:30:16 -06005027ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3,
5028 ES3_D3D11(),
5029 ES3_OPENGL(),
5030 ES3_OPENGLES(),
5031 ES3_VULKAN());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02005032ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
5033 ES3_D3D11(),
5034 ES3_OPENGL(),
James Dong8bb6baa2019-06-18 15:30:16 -06005035 ES3_OPENGLES(),
5036 ES3_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05005037ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
5038 ES3_D3D11(),
5039 ES3_OPENGL(),
5040 ES3_OPENGLES());
James Dong8bb6baa2019-06-18 15:30:16 -06005041ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3,
5042 ES3_D3D11(),
5043 ES3_OPENGL(),
5044 ES3_OPENGLES(),
5045 ES3_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05005046ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02005047ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02005048ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
5049 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02005050 ES2_D3D9(),
5051 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005052 ES2_OPENGLES(),
5053 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02005054ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
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(SamplerInStructArrayAsFunctionParameterTest,
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(SamplerInNestedStructAsFunctionParameterTest,
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(SamplerInStructAndOtherVariableTest,
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());
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05005078ANGLE_INSTANTIATE_TEST(TextureAnisotropyTest,
5079 ES2_D3D11(),
5080 ES2_D3D9(),
5081 ES2_OPENGL(),
5082 ES2_OPENGLES(),
5083 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02005084ANGLE_INSTANTIATE_TEST(TextureBorderClampTest,
5085 ES2_D3D11(),
5086 ES2_D3D9(),
5087 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005088 ES2_OPENGLES(),
5089 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02005090ANGLE_INSTANTIATE_TEST(TextureBorderClampTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
5091ANGLE_INSTANTIATE_TEST(TextureBorderClampIntegerTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Luc Ferronaf883622018-06-08 15:57:31 -04005092ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN());
Vincent Lang25ab4512016-05-13 18:13:59 +02005093ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Mohan Maiya8f1169e2019-06-27 15:32:32 -07005094ANGLE_INSTANTIATE_TEST(Texture2DRGTest,
5095 ES2_D3D11(),
5096 ES3_D3D11(),
5097 ES2_OPENGL(),
5098 ES3_OPENGL(),
5099 ES2_OPENGLES(),
5100 ES3_OPENGLES(),
5101 ES2_VULKAN(),
5102 ES3_VULKAN());
Martin Radev7e2c0d32017-09-15 14:25:42 +03005103ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Anders Leinof6cbe442019-04-18 15:32:07 +03005104ANGLE_INSTANTIATE_TEST(Texture2DIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino60cc7512019-05-06 09:25:27 +03005105ANGLE_INSTANTIATE_TEST(TextureCubeIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leinoe4452442019-05-09 13:29:49 +03005106ANGLE_INSTANTIATE_TEST(TextureCubeIntegerEdgeTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino1b6aded2019-05-20 12:56:34 +03005107ANGLE_INSTANTIATE_TEST(Texture2DIntegerProjectiveOffsetTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino69d04932019-05-20 14:04:13 +03005108ANGLE_INSTANTIATE_TEST(Texture2DArrayIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino262e2822019-05-20 14:24:40 +03005109ANGLE_INSTANTIATE_TEST(Texture3DIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Jamie Madillfa05f602015-05-07 13:47:11 -04005110
Jamie Madill7ffdda92016-09-08 13:26:51 -04005111} // anonymous namespace