blob: 3aa810c3b8145032ca697f3e5fc12df0fd48685a [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
Olli Etuahoa314b612016-03-10 16:43:00 +02002301 // Switch the level that is being used to the cyan level 2.
2302 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2303 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2304
2305 EXPECT_GL_NO_ERROR();
2306
2307 drawQuad(mProgram, "position", 0.5f);
2308
2309 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2310}
2311
2312// Test that texture completeness is updated if texture max level changes.
2313// GLES 3.0.4 section 3.8.13 Texture completeness
2314TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2315{
Olli Etuahoa314b612016-03-10 16:43:00 +02002316 glActiveTexture(GL_TEXTURE0);
2317 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2318 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2319
2320 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2321 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2322
2323 // A level that is initially unused.
2324 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2325 texDataGreen.data());
2326
2327 // One level that is initially used - only this level should affect completeness.
2328 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2329 texDataGreen.data());
2330
2331 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2332 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2333
2334 EXPECT_GL_NO_ERROR();
2335
2336 drawQuad(mProgram, "position", 0.5f);
2337
2338 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2339
2340 // Switch the max level to level 1. The levels within the used range now have inconsistent
2341 // dimensions and the texture should be incomplete.
2342 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2343
2344 EXPECT_GL_NO_ERROR();
2345
2346 drawQuad(mProgram, "position", 0.5f);
2347
2348 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2349}
2350
2351// Test that 3D texture completeness is updated if texture max level changes.
2352// GLES 3.0.4 section 3.8.13 Texture completeness
2353TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2354{
Olli Etuahoa314b612016-03-10 16:43:00 +02002355 glActiveTexture(GL_TEXTURE0);
2356 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2357 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2358
2359 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2360 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2361
2362 // A level that is initially unused.
2363 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2364 texDataGreen.data());
2365
2366 // One level that is initially used - only this level should affect completeness.
2367 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2368 texDataGreen.data());
2369
2370 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2371 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2372
2373 EXPECT_GL_NO_ERROR();
2374
2375 drawQuad(mProgram, "position", 0.5f);
2376
2377 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2378
2379 // Switch the max level to level 1. The levels within the used range now have inconsistent
2380 // dimensions and the texture should be incomplete.
2381 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2382
2383 EXPECT_GL_NO_ERROR();
2384
2385 drawQuad(mProgram, "position", 0.5f);
2386
2387 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2388}
2389
2390// Test that texture completeness is updated if texture base level changes.
2391// GLES 3.0.4 section 3.8.13 Texture completeness
2392TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2393{
Olli Etuahoa314b612016-03-10 16:43:00 +02002394 glActiveTexture(GL_TEXTURE0);
2395 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2396 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2397
2398 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2399 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2400
2401 // Two levels that are initially unused.
2402 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2403 texDataGreen.data());
2404 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2405 texDataGreen.data());
2406
2407 // One level that is initially used - only this level should affect completeness.
2408 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2409 texDataGreen.data());
2410
2411 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2412 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2413
2414 EXPECT_GL_NO_ERROR();
2415
2416 drawQuad(mProgram, "position", 0.5f);
2417
2418 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2419
2420 // Switch the base level to level 1. The levels within the used range now have inconsistent
2421 // dimensions and the texture should be incomplete.
2422 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2423
2424 EXPECT_GL_NO_ERROR();
2425
2426 drawQuad(mProgram, "position", 0.5f);
2427
2428 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2429}
2430
2431// Test that texture is not complete if base level is greater than max level.
2432// GLES 3.0.4 section 3.8.13 Texture completeness
2433TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2434{
Olli Etuahoa314b612016-03-10 16:43:00 +02002435 glActiveTexture(GL_TEXTURE0);
2436 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2437
2438 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2439 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2440
2441 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2442
2443 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2444 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2445
2446 EXPECT_GL_NO_ERROR();
2447
2448 drawQuad(mProgram, "position", 0.5f);
2449
2450 // Texture should be incomplete.
2451 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2452}
2453
2454// Test that immutable texture base level and max level are clamped.
2455// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2456TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2457{
Olli Etuahoa314b612016-03-10 16:43:00 +02002458 glActiveTexture(GL_TEXTURE0);
2459 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2460
2461 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2462 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2463
2464 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2465
2466 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2467
2468 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2469 // should be clamped to [base_level, levels - 1].
2470 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2471 // In the case of this test, those rules make the effective base level and max level 0.
2472 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2473 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2474
2475 EXPECT_GL_NO_ERROR();
2476
2477 drawQuad(mProgram, "position", 0.5f);
2478
2479 // Texture should be complete.
2480 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2481}
2482
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002483// Test that changing base level works when it affects the format of the texture.
2484TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2485{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002486 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002487
2488 // Observed incorrect rendering on AMD OpenGL.
2489 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002490
2491 glActiveTexture(GL_TEXTURE0);
2492 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2493 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2494 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2495
2496 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2497 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2498
2499 // RGBA8 level that's initially unused.
2500 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2501 texDataCyan.data());
2502
2503 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2504 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2505
2506 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2507 // format. It reads green channel data from the green and alpha channels of texDataGreen
2508 // (this is a bit hacky but works).
2509 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2510
2511 EXPECT_GL_NO_ERROR();
2512
2513 drawQuad(mProgram, "position", 0.5f);
2514
2515 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2516
2517 // Switch the texture to use the cyan level 0 with the RGBA format.
2518 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2519 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2520
2521 EXPECT_GL_NO_ERROR();
2522
2523 drawQuad(mProgram, "position", 0.5f);
2524
2525 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2526}
2527
Olli Etuahoa314b612016-03-10 16:43:00 +02002528// Test that setting a texture image works when base level is out of range.
2529TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2530{
2531 glActiveTexture(GL_TEXTURE0);
2532 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2533
2534 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2535 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2536
2537 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2538 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2539
2540 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2541
2542 EXPECT_GL_NO_ERROR();
2543
2544 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2545
2546 drawQuad(mProgram, "position", 0.5f);
2547
2548 // Texture should be complete.
2549 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002550}
2551
Jamie Madill50cf2be2018-06-15 09:46:57 -04002552// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG
2553// RBA->RGBA8, with 1.0 in the alpha channel. This test covers a bug where redefining array textures
2554// with these formats does not work as expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002555TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002556{
2557 std::vector<GLubyte> pixelData;
2558 for (size_t count = 0; count < 5000; count++)
2559 {
2560 pixelData.push_back(0u);
2561 pixelData.push_back(255u);
2562 pixelData.push_back(0u);
2563 }
2564
2565 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002566 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002567 glUniform1i(mTextureArrayLocation, 0);
2568
2569 // The first draw worked correctly.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002570 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2571 &pixelData[0]);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002572
2573 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2574 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2575 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2576 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002577 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002578 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002579
2580 // The dimension of the respecification must match the original exactly to trigger the bug.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002581 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2582 &pixelData[0]);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002583 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002584 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002585
2586 ASSERT_GL_NO_ERROR();
2587}
2588
Olli Etuaho1a679902016-01-14 12:21:47 +02002589// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2590// This test is needed especially to confirm that sampler registers get assigned correctly on
2591// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2592TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2593{
2594 glActiveTexture(GL_TEXTURE0);
2595 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2596 GLubyte texData[4];
2597 texData[0] = 0;
2598 texData[1] = 60;
2599 texData[2] = 0;
2600 texData[3] = 255;
2601 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2602
2603 glActiveTexture(GL_TEXTURE1);
2604 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2605 GLfloat depthTexData[1];
2606 depthTexData[0] = 0.5f;
2607 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2608 depthTexData);
2609
2610 glUseProgram(mProgram);
2611 glUniform1f(mDepthRefUniformLocation, 0.3f);
2612 glUniform1i(mTexture3DUniformLocation, 0);
2613 glUniform1i(mTextureShadowUniformLocation, 1);
2614
2615 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2616 drawQuad(mProgram, "position", 0.5f);
2617 EXPECT_GL_NO_ERROR();
2618 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2619 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2620
2621 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2622 drawQuad(mProgram, "position", 0.5f);
2623 EXPECT_GL_NO_ERROR();
2624 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2625 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2626}
2627
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002628// Test multiple different sampler types in the same shader.
2629// This test makes sure that even if sampler / texture registers get grouped together based on type
2630// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2631// still has the right register index information for each ESSL sampler.
2632// The tested ESSL samplers have the following types in D3D11 HLSL:
2633// sampler2D: Texture2D + SamplerState
2634// samplerCube: TextureCube + SamplerState
2635// sampler2DShadow: Texture2D + SamplerComparisonState
2636// samplerCubeShadow: TextureCube + SamplerComparisonState
2637TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2638{
2639 glActiveTexture(GL_TEXTURE0);
2640 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2641 GLubyte texData[4];
2642 texData[0] = 0;
2643 texData[1] = 0;
2644 texData[2] = 120;
2645 texData[3] = 255;
2646 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2647
2648 glActiveTexture(GL_TEXTURE1);
2649 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2650 texData[0] = 0;
2651 texData[1] = 90;
2652 texData[2] = 0;
2653 texData[3] = 255;
2654 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2655 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2656 texData);
2657
2658 glActiveTexture(GL_TEXTURE2);
2659 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2660 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2661 GLfloat depthTexData[1];
2662 depthTexData[0] = 0.5f;
2663 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2664 depthTexData);
2665
2666 glActiveTexture(GL_TEXTURE3);
2667 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2668 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2669 depthTexData[0] = 0.2f;
2670 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2671 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2672 depthTexData);
2673
2674 EXPECT_GL_NO_ERROR();
2675
2676 glUseProgram(mProgram);
2677 glUniform1f(mDepthRefUniformLocation, 0.3f);
2678 glUniform1i(mTexture2DUniformLocation, 0);
2679 glUniform1i(mTextureCubeUniformLocation, 1);
2680 glUniform1i(mTexture2DShadowUniformLocation, 2);
2681 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2682
2683 drawQuad(mProgram, "position", 0.5f);
2684 EXPECT_GL_NO_ERROR();
2685 // The shader writes:
2686 // <texture 2d color> +
2687 // <cube map color> +
2688 // 0.25 * <comparison result (1.0)> +
2689 // 0.125 * <comparison result (0.0)>
2690 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2691}
2692
Olli Etuahobce743a2016-01-15 17:18:28 +02002693// Test different base levels on textures accessed through the same sampler array.
2694// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2695TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2696{
Yunchao He9550c602018-02-13 14:47:05 +08002697 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2698
Olli Etuahobce743a2016-01-15 17:18:28 +02002699 glActiveTexture(GL_TEXTURE0);
2700 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2701 GLsizei size = 64;
2702 for (GLint level = 0; level < 7; ++level)
2703 {
2704 ASSERT_LT(0, size);
2705 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2706 nullptr);
2707 size = size / 2;
2708 }
2709 ASSERT_EQ(0, size);
2710 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2711
2712 glActiveTexture(GL_TEXTURE1);
2713 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2714 size = 128;
2715 for (GLint level = 0; level < 8; ++level)
2716 {
2717 ASSERT_LT(0, size);
2718 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2719 nullptr);
2720 size = size / 2;
2721 }
2722 ASSERT_EQ(0, size);
2723 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2724 EXPECT_GL_NO_ERROR();
2725
2726 glUseProgram(mProgram);
2727 glUniform1i(mTexture0Location, 0);
2728 glUniform1i(mTexture1Location, 1);
2729
Olli Etuaho5804dc82018-04-13 14:11:46 +03002730 drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
Olli Etuahobce743a2016-01-15 17:18:28 +02002731 EXPECT_GL_NO_ERROR();
2732 // Red channel: width of level 1 of texture A: 32.
2733 // Green channel: width of level 3 of texture B: 16.
2734 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2735}
2736
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002737// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2738// ES 3.0.4 table 3.24
2739TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2740{
2741 glActiveTexture(GL_TEXTURE0);
2742 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2743 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2744 EXPECT_GL_NO_ERROR();
2745
2746 drawQuad(mProgram, "position", 0.5f);
2747
2748 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2749}
2750
2751// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2752// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002753TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002754{
Luc Ferron5164b792018-03-06 09:10:12 -05002755 setUpProgram();
2756
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002757 glActiveTexture(GL_TEXTURE0);
2758 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2759 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2760 EXPECT_GL_NO_ERROR();
2761
2762 drawQuad(mProgram, "position", 0.5f);
2763
2764 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2765}
2766
Luc Ferron5164b792018-03-06 09:10:12 -05002767// Validate that every component of the pixel will be equal to the luminance value we've set
2768// and that the alpha channel will be 1 (or 255 to be exact).
2769TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2770{
2771 setUpProgram();
2772
2773 glActiveTexture(GL_TEXTURE0);
2774 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2775 uint8_t pixel = 50;
2776 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2777 EXPECT_GL_NO_ERROR();
2778
2779 drawQuad(mProgram, "position", 0.5f);
2780
2781 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2782}
2783
2784// Validate that every component of the pixel will be equal to the luminance value we've set
2785// and that the alpha channel will be the second component.
2786TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2787{
2788 setUpProgram();
2789
2790 glActiveTexture(GL_TEXTURE0);
2791 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2792 uint8_t pixel[] = {50, 25};
2793 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2794 GL_UNSIGNED_BYTE, pixel);
2795 EXPECT_GL_NO_ERROR();
2796
2797 drawQuad(mProgram, "position", 0.5f);
2798
2799 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2800}
2801
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002802// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2803// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002804TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002805{
Jamie Madillb8149072019-04-30 16:14:44 -04002806 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002807 ANGLE_SKIP_TEST_IF(IsD3D9());
2808 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002809
2810 setUpProgram();
2811
Luc Ferrond8c632c2018-04-10 12:31:44 -04002812 glActiveTexture(GL_TEXTURE0);
2813 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2814 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2815 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002816
Luc Ferrond8c632c2018-04-10 12:31:44 -04002817 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002818
Luc Ferrond8c632c2018-04-10 12:31:44 -04002819 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002820}
2821
2822// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2823// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002824TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002825{
Jamie Madillb8149072019-04-30 16:14:44 -04002826 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
Luc Ferrond8c632c2018-04-10 12:31:44 -04002827 ANGLE_SKIP_TEST_IF(IsD3D9());
2828 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferrond8c632c2018-04-10 12:31:44 -04002829 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2830 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002831
Luc Ferrond8c632c2018-04-10 12:31:44 -04002832 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002833
Luc Ferrond8c632c2018-04-10 12:31:44 -04002834 glActiveTexture(GL_TEXTURE0);
2835 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2836 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2837 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002838
Luc Ferrond8c632c2018-04-10 12:31:44 -04002839 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002840
Luc Ferrond8c632c2018-04-10 12:31:44 -04002841 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002842}
2843
2844// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2845// ES 3.0.4 table 3.24
2846TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2847{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002848 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2849
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002850 glActiveTexture(GL_TEXTURE0);
2851 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2852 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2853 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2854 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2855 EXPECT_GL_NO_ERROR();
2856
2857 drawQuad(mProgram, "position", 0.5f);
2858
2859 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2860}
2861
2862// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2863// ES 3.0.4 table 3.24
2864TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2865{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002866 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2867
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002868 glActiveTexture(GL_TEXTURE0);
2869 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2870
2871 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2872 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2873 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2874 EXPECT_GL_NO_ERROR();
2875
2876 drawQuad(mProgram, "position", 0.5f);
2877
2878 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2879}
2880
2881// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2882// ES 3.0.4 table 3.24
2883TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2884{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002885 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2886
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002887 glActiveTexture(GL_TEXTURE0);
2888 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2889 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2890 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2891 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2892 EXPECT_GL_NO_ERROR();
2893
2894 drawQuad(mProgram, "position", 0.5f);
2895
2896 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2897}
2898
2899// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2900// ES 3.0.4 table 3.24
2901TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2902{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002903 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2904
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002905 glActiveTexture(GL_TEXTURE0);
2906 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2907 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2908 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2909 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2910 EXPECT_GL_NO_ERROR();
2911
2912 drawQuad(mProgram, "position", 0.5f);
2913
2914 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2915}
2916
2917// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2918// ES 3.0.4 table 3.24
2919TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2920{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002921 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2922
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002923 glActiveTexture(GL_TEXTURE0);
2924 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2925 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2926 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2927 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2928 EXPECT_GL_NO_ERROR();
2929
2930 drawQuad(mProgram, "position", 0.5f);
2931
2932 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2933}
2934
2935// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2936// ES 3.0.4 table 3.24
2937TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2938{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002939 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2940
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002941 glActiveTexture(GL_TEXTURE0);
2942 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2943 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2944 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2945 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2946 EXPECT_GL_NO_ERROR();
2947
2948 drawQuad(mProgram, "position", 0.5f);
2949
2950 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2951}
2952
2953// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2954// ES 3.0.4 table 3.24
2955TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2956{
2957 glActiveTexture(GL_TEXTURE0);
2958 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2959 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2960 EXPECT_GL_NO_ERROR();
2961
2962 drawQuad(mProgram, "position", 0.5f);
2963
2964 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2965}
2966
2967// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2968// ES 3.0.4 table 3.24
2969TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2970{
2971 glActiveTexture(GL_TEXTURE0);
2972 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2973 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2974 nullptr);
2975 EXPECT_GL_NO_ERROR();
2976
2977 drawQuad(mProgram, "position", 0.5f);
2978
2979 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2980}
2981
2982// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2983// ES 3.0.4 table 3.24
2984TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2985{
Geoff Lang2a19c592019-08-23 14:10:24 -04002986 // ETC texture formats are not supported on Mac OpenGL. http://anglebug.com/3853
2987 ANGLE_SKIP_TEST_IF(IsOSX() && IsDesktopOpenGL());
Yuly Novikov49886892018-01-23 21:18:27 -05002988
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002989 glActiveTexture(GL_TEXTURE0);
2990 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2991 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2992 EXPECT_GL_NO_ERROR();
2993
2994 drawQuad(mProgram, "position", 0.5f);
2995
2996 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2997}
2998
2999// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
3000// ES 3.0.4 table 3.24
3001TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
3002{
Geoff Lang2a19c592019-08-23 14:10:24 -04003003 // ETC texture formats are not supported on Mac OpenGL. http://anglebug.com/3853
3004 ANGLE_SKIP_TEST_IF(IsOSX() && IsDesktopOpenGL());
Yuly Novikov49886892018-01-23 21:18:27 -05003005
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003006 glActiveTexture(GL_TEXTURE0);
3007 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3008 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
3009 EXPECT_GL_NO_ERROR();
3010
3011 drawQuad(mProgram, "position", 0.5f);
3012
3013 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
3014}
3015
Olli Etuaho96963162016-03-21 11:54:33 +02003016// Use a sampler in a uniform struct.
3017TEST_P(SamplerInStructTest, SamplerInStruct)
3018{
3019 runSamplerInStructTest();
3020}
3021
3022// Use a sampler in a uniform struct that's passed as a function parameter.
3023TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
3024{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003025 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
3026 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04003027
Olli Etuaho96963162016-03-21 11:54:33 +02003028 runSamplerInStructTest();
3029}
3030
3031// Use a sampler in a uniform struct array with a struct from the array passed as a function
3032// parameter.
3033TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
3034{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003035 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
3036 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08003037
Olli Etuaho96963162016-03-21 11:54:33 +02003038 runSamplerInStructTest();
3039}
3040
3041// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
3042// parameter.
3043TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
3044{
Yuly Novikovd18c0482019-04-04 19:56:43 -04003045 // Fails on Nexus 5X due to a driver bug. http://anglebug.com/1427
3046 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Yunchao He9550c602018-02-13 14:47:05 +08003047
Olli Etuaho96963162016-03-21 11:54:33 +02003048 runSamplerInStructTest();
3049}
3050
3051// Make sure that there isn't a name conflict between sampler extracted from a struct and a
3052// similarly named uniform.
3053TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
3054{
3055 runSamplerInStructTest();
3056}
3057
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05003058// GL_EXT_texture_filter_anisotropic
3059class TextureAnisotropyTest : public Texture2DTest
3060{
3061 protected:
3062 void uploadTexture()
3063 {
3064 glActiveTexture(GL_TEXTURE0);
3065 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3066 GLColor texDataRed[1] = {GLColor::red};
3067 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed);
3068 EXPECT_GL_NO_ERROR();
3069 }
3070};
3071
3072// Tests that setting anisotropic filtering doesn't cause failures at draw time.
3073TEST_P(TextureAnisotropyTest, AnisotropyFunctional)
3074{
Jamie Madillb8149072019-04-30 16:14:44 -04003075 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_filter_anisotropic"));
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05003076
3077 setUpProgram();
3078
3079 uploadTexture();
3080
3081 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3082 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3083 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f);
3084 EXPECT_GL_NO_ERROR();
3085
3086 drawQuad(mProgram, "position", 0.5f);
3087
3088 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3089 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3090 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::red);
3091}
3092
Till Rathmannb8543632018-10-02 19:46:14 +02003093// GL_OES_texture_border_clamp
3094class TextureBorderClampTest : public Texture2DTest
3095{
3096 protected:
3097 TextureBorderClampTest() : Texture2DTest() {}
3098
Jamie Madill35cd7332018-12-02 12:03:33 -05003099 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003100 {
3101 return
3102 R"(precision highp float;
3103 attribute vec4 position;
3104 varying vec2 texcoord;
3105
3106 void main()
3107 {
3108 gl_Position = vec4(position.xy, 0.0, 1.0);
3109 // texcoords in [-0.5, 1.5]
3110 texcoord = (position.xy) + 0.5;
3111 })";
3112 }
3113
3114 void uploadTexture()
3115 {
3116 glActiveTexture(GL_TEXTURE0);
3117 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3118 std::vector<GLColor> texDataRed(1, GLColor::red);
3119 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3120 texDataRed.data());
3121 EXPECT_GL_NO_ERROR();
3122 }
3123};
3124
3125// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3126// GL_CLAMP_TO_BORDER wrap mode (set with glTexParameter).
3127TEST_P(TextureBorderClampTest, TextureBorderClampFunctional)
3128{
Jamie Madillb8149072019-04-30 16:14:44 -04003129 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003130
3131 setUpProgram();
3132
3133 uploadTexture();
3134
3135 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3136 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3137 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3138 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3139 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3140 EXPECT_GL_NO_ERROR();
3141
3142 drawQuad(mProgram, "position", 0.5f);
3143
3144 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3145 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3146 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3147}
3148
3149// Test reading back GL_TEXTURE_BORDER_COLOR by glGetTexParameter.
3150TEST_P(TextureBorderClampTest, TextureBorderClampFunctional2)
3151{
Jamie Madillb8149072019-04-30 16:14:44 -04003152 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003153
3154 glActiveTexture(GL_TEXTURE0);
3155 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3156
3157 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3158
3159 GLint colorFixedPoint[4] = {0};
3160 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3161 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3162 std::numeric_limits<GLint>::max()};
3163 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3164 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3165 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3166 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3167
3168 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3169 std::numeric_limits<GLint>::max()};
3170 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3171
3172 GLfloat color[4] = {0.0f};
3173 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
3174 EXPECT_EQ(color[0], kFloatBlue.R);
3175 EXPECT_EQ(color[1], kFloatBlue.G);
3176 EXPECT_EQ(color[2], kFloatBlue.B);
3177 EXPECT_EQ(color[3], kFloatBlue.A);
3178}
3179
3180// Test GL_TEXTURE_BORDER_COLOR parameter validation at glTexParameter.
3181TEST_P(TextureBorderClampTest, TextureBorderClampValidation)
3182{
Jamie Madillb8149072019-04-30 16:14:44 -04003183 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003184
3185 glActiveTexture(GL_TEXTURE0);
3186 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3187
3188 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, 1.0f);
3189 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3190
3191 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3192 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3193
3194 glTexParameterfv(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3195 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3196
3197 GLint colorInt[4] = {0};
3198 glTexParameteriv(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_BORDER_COLOR, colorInt);
3199 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3200
3201 if (getClientMajorVersion() < 3)
3202 {
3203 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3204 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3205 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3206 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3207
3208 GLuint colorUInt[4] = {0};
3209 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3210 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3211 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3212 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3213
3214 GLSampler sampler;
3215 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3216 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3217 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3218 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3219
3220 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3221 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3222 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3223 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3224 }
3225}
3226
3227class TextureBorderClampTestES3 : public TextureBorderClampTest
3228{
3229 protected:
3230 TextureBorderClampTestES3() : TextureBorderClampTest() {}
3231};
3232
3233// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
3234// GL_CLAMP_TO_BORDER wrap mode (set with glSamplerParameter).
3235TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional)
3236{
Jamie Madillb8149072019-04-30 16:14:44 -04003237 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003238
3239 setUpProgram();
3240
3241 uploadTexture();
3242
3243 GLSampler sampler;
3244 glBindSampler(0, sampler);
3245 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3246 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3247 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3248 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3249 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3250 EXPECT_GL_NO_ERROR();
3251
3252 drawQuad(mProgram, "position", 0.5f);
3253
3254 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3255 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3256 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3257}
3258
3259// Test reading back GL_TEXTURE_BORDER_COLOR by glGetSamplerParameter.
3260TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional2)
3261{
Jamie Madillb8149072019-04-30 16:14:44 -04003262 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003263
3264 glActiveTexture(GL_TEXTURE0);
3265
3266 GLSampler sampler;
3267 glBindSampler(0, sampler);
3268
3269 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
3270
3271 GLint colorFixedPoint[4] = {0};
3272 glGetSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
3273 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
3274 std::numeric_limits<GLint>::max()};
3275 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
3276 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
3277 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
3278 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
3279
3280 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
3281 std::numeric_limits<GLint>::max()};
3282 glSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
3283
3284 GLfloat color[4] = {0.0f};
3285 glGetSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, color);
3286 EXPECT_EQ(color[0], kFloatBlue.R);
3287 EXPECT_EQ(color[1], kFloatBlue.G);
3288 EXPECT_EQ(color[2], kFloatBlue.B);
3289 EXPECT_EQ(color[3], kFloatBlue.A);
3290
3291 constexpr GLint colorSomewhatRedInt[4] = {500000, 0, 0, std::numeric_limits<GLint>::max()};
3292 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedInt);
3293 GLint colorInt[4] = {0};
3294 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
3295 EXPECT_EQ(colorInt[0], colorSomewhatRedInt[0]);
3296 EXPECT_EQ(colorInt[1], colorSomewhatRedInt[1]);
3297 EXPECT_EQ(colorInt[2], colorSomewhatRedInt[2]);
3298 EXPECT_EQ(colorInt[3], colorSomewhatRedInt[3]);
3299
3300 constexpr GLuint colorSomewhatRedUInt[4] = {500000, 0, 0, std::numeric_limits<GLuint>::max()};
3301 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedUInt);
3302 GLuint colorUInt[4] = {0};
3303 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
3304 EXPECT_EQ(colorUInt[0], colorSomewhatRedUInt[0]);
3305 EXPECT_EQ(colorUInt[1], colorSomewhatRedUInt[1]);
3306 EXPECT_EQ(colorUInt[2], colorSomewhatRedUInt[2]);
3307 EXPECT_EQ(colorUInt[3], colorSomewhatRedUInt[3]);
3308
3309 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3310
3311 constexpr GLint colorSomewhatGreenInt[4] = {0, 500000, 0, std::numeric_limits<GLint>::max()};
3312 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenInt);
3313 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
3314 EXPECT_EQ(colorInt[0], colorSomewhatGreenInt[0]);
3315 EXPECT_EQ(colorInt[1], colorSomewhatGreenInt[1]);
3316 EXPECT_EQ(colorInt[2], colorSomewhatGreenInt[2]);
3317 EXPECT_EQ(colorInt[3], colorSomewhatGreenInt[3]);
3318
3319 constexpr GLuint colorSomewhatGreenUInt[4] = {0, 500000, 0, std::numeric_limits<GLuint>::max()};
3320 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenUInt);
3321 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
3322 EXPECT_EQ(colorUInt[0], colorSomewhatGreenUInt[0]);
3323 EXPECT_EQ(colorUInt[1], colorSomewhatGreenUInt[1]);
3324 EXPECT_EQ(colorUInt[2], colorSomewhatGreenUInt[2]);
3325 EXPECT_EQ(colorUInt[3], colorSomewhatGreenUInt[3]);
3326}
3327
3328// Test GL_TEXTURE_BORDER_COLOR parameter validation at glSamplerParameter.
3329TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Validation)
3330{
Jamie Madillb8149072019-04-30 16:14:44 -04003331 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003332
3333 glActiveTexture(GL_TEXTURE0);
3334
3335 GLSampler sampler;
3336 glBindSampler(0, sampler);
3337
3338 glSamplerParameterf(sampler, GL_TEXTURE_BORDER_COLOR, 1.0f);
3339 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3340
3341 glSamplerParameteri(sampler, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3342 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3343}
3344
3345class TextureBorderClampIntegerTestES3 : public Texture2DTest
3346{
3347 protected:
3348 TextureBorderClampIntegerTestES3() : Texture2DTest(), isUnsignedIntTest(false) {}
3349
Jamie Madill35cd7332018-12-02 12:03:33 -05003350 const char *getVertexShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003351 {
3352 return
3353 R"(#version 300 es
3354 out vec2 texcoord;
3355 in vec4 position;
3356
3357 void main()
3358 {
3359 gl_Position = vec4(position.xy, 0.0, 1.0);
3360 // texcoords in [-0.5, 1.5]
3361 texcoord = (position.xy) + 0.5;
3362 })";
3363 }
3364
Jamie Madillba319ba2018-12-29 10:29:33 -05003365 const char *getFragmentShaderSource() override
Till Rathmannb8543632018-10-02 19:46:14 +02003366 {
Jamie Madill35cd7332018-12-02 12:03:33 -05003367 if (isUnsignedIntTest)
3368 {
3369 return "#version 300 es\n"
3370 "precision highp float;\n"
3371 "uniform highp usampler2D tex;\n"
3372 "in vec2 texcoord;\n"
3373 "out vec4 fragColor;\n"
Till Rathmannb8543632018-10-02 19:46:14 +02003374
Jamie Madill35cd7332018-12-02 12:03:33 -05003375 "void main()\n"
3376 "{\n"
3377 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3378 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3379 "fragColor = (texture(tex, texcoord).r == 150u)"
3380 " ? green : red;\n"
3381 "}\n";
3382 }
3383 else
3384 {
3385 return "#version 300 es\n"
3386 "precision highp float;\n"
3387 "uniform highp isampler2D tex;\n"
3388 "in vec2 texcoord;\n"
3389 "out vec4 fragColor;\n"
3390
3391 "void main()\n"
3392 "{\n"
3393 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3394 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3395 "fragColor = (texture(tex, texcoord).r == -50)"
3396 " ? green : red;\n"
3397 "}\n";
3398 }
Till Rathmannb8543632018-10-02 19:46:14 +02003399 }
3400
3401 void uploadTexture()
3402 {
3403 glActiveTexture(GL_TEXTURE0);
3404 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3405 if (isUnsignedIntTest)
3406 {
3407 std::vector<GLubyte> texData(4, 100);
3408 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE,
3409 texData.data());
3410 }
3411 else
3412 {
3413 std::vector<GLbyte> texData(4, 100);
3414 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8I, 1, 1, 0, GL_RGBA_INTEGER, GL_BYTE,
3415 texData.data());
3416 }
3417 EXPECT_GL_NO_ERROR();
3418 }
3419
3420 bool isUnsignedIntTest;
3421};
3422
3423// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3424// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3425TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger)
3426{
Yuly Novikov1dbbc7b2019-07-31 17:49:39 -04003427 // Fails on Win10 FYI x64 Release (AMD RX 550). http://anglebug.com/3760
3428 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsDesktopOpenGL());
3429
Jamie Madillb8149072019-04-30 16:14:44 -04003430 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003431
3432 setUpProgram();
3433
3434 uploadTexture();
3435
3436 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3437 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3438 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3439 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3440
3441 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3442 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3443
3444 EXPECT_GL_NO_ERROR();
3445
3446 drawQuad(mProgram, "position", 0.5f);
3447
3448 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3449 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3450 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3451}
3452
3453// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3454// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3455TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger2)
3456{
Yuly Novikov1dbbc7b2019-07-31 17:49:39 -04003457 // Fails on Win10 FYI x64 Release (AMD RX 550). http://anglebug.com/3760
3458 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsDesktopOpenGL());
3459
Jamie Madillb8149072019-04-30 16:14:44 -04003460 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003461
3462 setUpProgram();
3463
3464 uploadTexture();
3465
3466 GLSampler sampler;
3467 glBindSampler(0, sampler);
3468 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3469 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3470 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3471 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3472
3473 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3474 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3475
3476 EXPECT_GL_NO_ERROR();
3477
3478 drawQuad(mProgram, "position", 0.5f);
3479
3480 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3481 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3482 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3483}
3484
3485// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3486// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIuivOES).
3487TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned)
3488{
Jamie Madillb8149072019-04-30 16:14:44 -04003489 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003490
3491 isUnsignedIntTest = true;
3492
3493 setUpProgram();
3494
3495 uploadTexture();
3496
3497 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3498 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3499 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3500 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3501
3502 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3503 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3504
3505 EXPECT_GL_NO_ERROR();
3506
3507 drawQuad(mProgram, "position", 0.5f);
3508
3509 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3510 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3511 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3512}
3513
3514// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3515// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with
3516// glSamplerParameterIuivOES).
3517TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned2)
3518{
Jamie Madillb8149072019-04-30 16:14:44 -04003519 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_border_clamp"));
Till Rathmannb8543632018-10-02 19:46:14 +02003520
3521 isUnsignedIntTest = true;
3522
3523 setUpProgram();
3524
3525 uploadTexture();
3526
3527 GLSampler sampler;
3528 glBindSampler(0, sampler);
3529 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3530 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3531 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3532 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3533
3534 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3535 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3536
3537 EXPECT_GL_NO_ERROR();
3538
3539 drawQuad(mProgram, "position", 0.5f);
3540
3541 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3542 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3543 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3544}
3545
3546// ~GL_OES_texture_border_clamp
3547
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003548class TextureLimitsTest : public ANGLETest
3549{
3550 protected:
3551 struct RGBA8
3552 {
3553 uint8_t R, G, B, A;
3554 };
3555
3556 TextureLimitsTest()
3557 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
3558 {
3559 setWindowWidth(128);
3560 setWindowHeight(128);
3561 setConfigRedBits(8);
3562 setConfigGreenBits(8);
3563 setConfigBlueBits(8);
3564 setConfigAlphaBits(8);
3565 }
3566
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003567 void testSetUp() override
Jamie Madill0fdb9562018-09-17 17:18:43 -04003568 {
Jamie Madill0fdb9562018-09-17 17:18:43 -04003569 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
3570 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
3571 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
3572
3573 ASSERT_GL_NO_ERROR();
3574 }
3575
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003576 void testTearDown() override
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003577 {
3578 if (mProgram != 0)
3579 {
3580 glDeleteProgram(mProgram);
3581 mProgram = 0;
3582
3583 if (!mTextures.empty())
3584 {
3585 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
3586 }
3587 }
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003588 }
3589
3590 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
3591 GLint vertexTextureCount,
3592 GLint vertexActiveTextureCount,
3593 const std::string &fragPrefix,
3594 GLint fragmentTextureCount,
3595 GLint fragmentActiveTextureCount)
3596 {
3597 std::stringstream vertexShaderStr;
3598 vertexShaderStr << "attribute vec2 position;\n"
3599 << "varying vec4 color;\n"
3600 << "varying vec2 texCoord;\n";
3601
3602 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
3603 {
3604 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
3605 }
3606
3607 vertexShaderStr << "void main() {\n"
3608 << " gl_Position = vec4(position, 0, 1);\n"
3609 << " texCoord = (position * 0.5) + 0.5;\n"
3610 << " color = vec4(0);\n";
3611
3612 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
3613 {
3614 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
3615 << ", texCoord);\n";
3616 }
3617
3618 vertexShaderStr << "}";
3619
3620 std::stringstream fragmentShaderStr;
3621 fragmentShaderStr << "varying mediump vec4 color;\n"
3622 << "varying mediump vec2 texCoord;\n";
3623
3624 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
3625 {
3626 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
3627 }
3628
3629 fragmentShaderStr << "void main() {\n"
3630 << " gl_FragColor = color;\n";
3631
3632 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
3633 {
3634 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
3635 << ", texCoord);\n";
3636 }
3637
3638 fragmentShaderStr << "}";
3639
3640 const std::string &vertexShaderSource = vertexShaderStr.str();
3641 const std::string &fragmentShaderSource = fragmentShaderStr.str();
3642
Jamie Madill35cd7332018-12-02 12:03:33 -05003643 mProgram = CompileProgram(vertexShaderSource.c_str(), fragmentShaderSource.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003644 }
3645
3646 RGBA8 getPixel(GLint texIndex)
3647 {
3648 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3649 0, 255u};
3650 return pixel;
3651 }
3652
3653 void initTextures(GLint tex2DCount, GLint texCubeCount)
3654 {
3655 GLint totalCount = tex2DCount + texCubeCount;
3656 mTextures.assign(totalCount, 0);
3657 glGenTextures(totalCount, &mTextures[0]);
3658 ASSERT_GL_NO_ERROR();
3659
3660 std::vector<RGBA8> texData(16 * 16);
3661
3662 GLint texIndex = 0;
3663 for (; texIndex < tex2DCount; ++texIndex)
3664 {
3665 texData.assign(texData.size(), getPixel(texIndex));
3666 glActiveTexture(GL_TEXTURE0 + texIndex);
3667 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3668 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3669 &texData[0]);
3670 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3671 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3672 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3673 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3674 }
3675
3676 ASSERT_GL_NO_ERROR();
3677
3678 for (; texIndex < texCubeCount; ++texIndex)
3679 {
3680 texData.assign(texData.size(), getPixel(texIndex));
3681 glActiveTexture(GL_TEXTURE0 + texIndex);
3682 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3683 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3684 GL_UNSIGNED_BYTE, &texData[0]);
3685 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3686 GL_UNSIGNED_BYTE, &texData[0]);
3687 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3688 GL_UNSIGNED_BYTE, &texData[0]);
3689 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3690 GL_UNSIGNED_BYTE, &texData[0]);
3691 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3692 GL_UNSIGNED_BYTE, &texData[0]);
3693 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3694 GL_UNSIGNED_BYTE, &texData[0]);
3695 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3696 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3697 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3698 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3699 }
3700
3701 ASSERT_GL_NO_ERROR();
3702 }
3703
3704 void testWithTextures(GLint vertexTextureCount,
3705 const std::string &vertexTexturePrefix,
3706 GLint fragmentTextureCount,
3707 const std::string &fragmentTexturePrefix)
3708 {
3709 // Generate textures
3710 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3711
3712 glUseProgram(mProgram);
3713 RGBA8 expectedSum = {0};
3714 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3715 {
3716 std::stringstream uniformNameStr;
3717 uniformNameStr << vertexTexturePrefix << texIndex;
3718 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003719 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003720 ASSERT_NE(-1, location);
3721
3722 glUniform1i(location, texIndex);
3723 RGBA8 contribution = getPixel(texIndex);
3724 expectedSum.R += contribution.R;
3725 expectedSum.G += contribution.G;
3726 }
3727
3728 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3729 {
3730 std::stringstream uniformNameStr;
3731 uniformNameStr << fragmentTexturePrefix << texIndex;
3732 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003733 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003734 ASSERT_NE(-1, location);
3735
3736 glUniform1i(location, texIndex + vertexTextureCount);
3737 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3738 expectedSum.R += contribution.R;
3739 expectedSum.G += contribution.G;
3740 }
3741
3742 ASSERT_GE(256u, expectedSum.G);
3743
3744 drawQuad(mProgram, "position", 0.5f);
3745 ASSERT_GL_NO_ERROR();
3746 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3747 }
3748
3749 GLuint mProgram;
3750 std::vector<GLuint> mTextures;
3751 GLint mMaxVertexTextures;
3752 GLint mMaxFragmentTextures;
3753 GLint mMaxCombinedTextures;
3754};
3755
3756// Test rendering with the maximum vertex texture units.
3757TEST_P(TextureLimitsTest, MaxVertexTextures)
3758{
3759 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3760 ASSERT_NE(0u, mProgram);
3761 ASSERT_GL_NO_ERROR();
3762
3763 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3764}
3765
3766// Test rendering with the maximum fragment texture units.
3767TEST_P(TextureLimitsTest, MaxFragmentTextures)
3768{
3769 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3770 ASSERT_NE(0u, mProgram);
3771 ASSERT_GL_NO_ERROR();
3772
3773 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3774}
3775
3776// Test rendering with maximum combined texture units.
3777TEST_P(TextureLimitsTest, MaxCombinedTextures)
3778{
3779 GLint vertexTextures = mMaxVertexTextures;
3780
3781 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3782 {
3783 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3784 }
3785
3786 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3787 mMaxFragmentTextures, mMaxFragmentTextures);
3788 ASSERT_NE(0u, mProgram);
3789 ASSERT_GL_NO_ERROR();
3790
3791 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3792}
3793
3794// Negative test for exceeding the number of vertex textures
3795TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3796{
3797 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3798 0);
3799 ASSERT_EQ(0u, mProgram);
3800}
3801
3802// Negative test for exceeding the number of fragment textures
3803TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3804{
3805 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3806 mMaxFragmentTextures + 1);
3807 ASSERT_EQ(0u, mProgram);
3808}
3809
3810// Test active vertex textures under the limit, but excessive textures specified.
3811TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3812{
3813 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3814 ASSERT_NE(0u, mProgram);
3815 ASSERT_GL_NO_ERROR();
3816
3817 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3818}
3819
3820// Test active fragment textures under the limit, but excessive textures specified.
3821TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3822{
3823 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3824 mMaxFragmentTextures);
3825 ASSERT_NE(0u, mProgram);
3826 ASSERT_GL_NO_ERROR();
3827
3828 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3829}
3830
3831// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003832// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003833TEST_P(TextureLimitsTest, TextureTypeConflict)
3834{
Jamie Madill35cd7332018-12-02 12:03:33 -05003835 constexpr char kVS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003836 "attribute vec2 position;\n"
3837 "varying float color;\n"
3838 "uniform sampler2D tex2D;\n"
3839 "uniform samplerCube texCube;\n"
3840 "void main() {\n"
3841 " gl_Position = vec4(position, 0, 1);\n"
3842 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3843 " color = texture2D(tex2D, texCoord).x;\n"
3844 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3845 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05003846 constexpr char kFS[] =
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003847 "varying mediump float color;\n"
3848 "void main() {\n"
3849 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3850 "}";
3851
Jamie Madill35cd7332018-12-02 12:03:33 -05003852 mProgram = CompileProgram(kVS, kFS);
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003853 ASSERT_NE(0u, mProgram);
3854
3855 initTextures(1, 0);
3856
3857 glUseProgram(mProgram);
3858 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3859 ASSERT_NE(-1, tex2DLocation);
3860 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3861 ASSERT_NE(-1, texCubeLocation);
3862
3863 glUniform1i(tex2DLocation, 0);
3864 glUniform1i(texCubeLocation, 0);
3865 ASSERT_GL_NO_ERROR();
3866
3867 drawQuad(mProgram, "position", 0.5f);
3868 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3869}
3870
Vincent Lang25ab4512016-05-13 18:13:59 +02003871class Texture2DNorm16TestES3 : public Texture2DTestES3
3872{
3873 protected:
3874 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3875
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003876 void testSetUp() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003877 {
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003878 Texture2DTestES3::testSetUp();
Vincent Lang25ab4512016-05-13 18:13:59 +02003879
3880 glActiveTexture(GL_TEXTURE0);
3881 glGenTextures(3, mTextures);
3882 glGenFramebuffers(1, &mFBO);
3883 glGenRenderbuffers(1, &mRenderbuffer);
3884
3885 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3886 {
3887 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3888 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3889 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3890 }
3891
3892 glBindTexture(GL_TEXTURE_2D, 0);
3893
3894 ASSERT_GL_NO_ERROR();
3895 }
3896
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003897 void testTearDown() override
Vincent Lang25ab4512016-05-13 18:13:59 +02003898 {
3899 glDeleteTextures(3, mTextures);
3900 glDeleteFramebuffers(1, &mFBO);
3901 glDeleteRenderbuffers(1, &mRenderbuffer);
3902
Jamie Madill5cbaa3f2019-05-07 15:49:22 -04003903 Texture2DTestES3::testTearDown();
Vincent Lang25ab4512016-05-13 18:13:59 +02003904 }
3905
3906 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3907 {
Geoff Langf607c602016-09-21 11:46:48 -04003908 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3909 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003910
3911 setUpProgram();
3912
3913 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3914 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3915 0);
3916
3917 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3918 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3919
3920 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003921 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003922
3923 EXPECT_GL_NO_ERROR();
3924
3925 drawQuad(mProgram, "position", 0.5f);
3926
Geoff Langf607c602016-09-21 11:46:48 -04003927 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003928
Jamie Madill50cf2be2018-06-15 09:46:57 -04003929 EXPECT_PIXEL_COLOR_EQ(0, 0,
3930 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3931 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003932
3933 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3934
3935 ASSERT_GL_NO_ERROR();
3936 }
3937
3938 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3939 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04003940 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003941 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003942
3943 setUpProgram();
3944
3945 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3946 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3947
3948 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3949 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3950 0);
3951
3952 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003953 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003954
3955 EXPECT_GL_NO_ERROR();
3956
3957 drawQuad(mProgram, "position", 0.5f);
3958
Geoff Langf607c602016-09-21 11:46:48 -04003959 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
Jamie Madill50cf2be2018-06-15 09:46:57 -04003960 EXPECT_PIXEL_COLOR_EQ(0, 0,
3961 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3962 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003963
3964 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3965 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3966 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3967 mRenderbuffer);
3968 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3969 EXPECT_GL_NO_ERROR();
3970
3971 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3972 glClear(GL_COLOR_BUFFER_BIT);
3973
3974 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3975
Geoff Langf607c602016-09-21 11:46:48 -04003976 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003977
3978 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3979
3980 ASSERT_GL_NO_ERROR();
3981 }
3982
3983 GLuint mTextures[3];
3984 GLuint mFBO;
3985 GLuint mRenderbuffer;
3986};
3987
3988// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3989TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3990{
Jamie Madillb8149072019-04-30 16:14:44 -04003991 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02003992
3993 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3994 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3995 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3996 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3997 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3998 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3999 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
4000 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
4001
4002 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
4003 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
4004 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
4005}
4006
Mohan Maiya8f1169e2019-06-27 15:32:32 -07004007class Texture2DRGTest : public Texture2DTest
4008{
4009 protected:
4010 Texture2DRGTest()
4011 : Texture2DTest(), mRenderableTexture(0), mTestTexture(0), mFBO(0), mRenderbuffer(0)
4012 {}
4013
4014 void testSetUp() override
4015 {
4016 Texture2DTest::testSetUp();
4017
4018 glActiveTexture(GL_TEXTURE0);
4019 glGenTextures(1, &mRenderableTexture);
4020 glGenTextures(1, &mTestTexture);
4021 glGenFramebuffers(1, &mFBO);
4022 glGenRenderbuffers(1, &mRenderbuffer);
4023
4024 glBindTexture(GL_TEXTURE_2D, mRenderableTexture);
4025 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4026 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4027 glBindTexture(GL_TEXTURE_2D, mTestTexture);
4028 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4029 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4030
4031 glBindTexture(GL_TEXTURE_2D, 0);
4032
4033 setUpProgram();
4034 glUseProgram(mProgram);
4035 glUniform1i(mTexture2DUniformLocation, 0);
4036
4037 ASSERT_GL_NO_ERROR();
4038 }
4039
4040 void testTearDown() override
4041 {
4042 glDeleteTextures(1, &mRenderableTexture);
4043 glDeleteTextures(1, &mTestTexture);
4044 glDeleteFramebuffers(1, &mFBO);
4045 glDeleteRenderbuffers(1, &mRenderbuffer);
4046
4047 Texture2DTest::testTearDown();
4048 }
4049
4050 void setupFormatTextures(GLenum internalformat, GLenum format, GLenum type, GLvoid *imageData)
4051 {
4052 glBindTexture(GL_TEXTURE_2D, mRenderableTexture);
4053 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4054
4055 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
4056 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
4057 mRenderableTexture, 0);
4058
4059 glBindTexture(GL_TEXTURE_2D, mTestTexture);
4060 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
4061
4062 EXPECT_GL_NO_ERROR();
4063 }
4064
4065 void testRGTexture(GLColor expectedColor)
4066 {
4067 drawQuad(mProgram, "position", 0.5f);
4068
4069 EXPECT_GL_NO_ERROR();
4070 EXPECT_PIXEL_COLOR_NEAR(0, 0, expectedColor, kPixelTolerance);
4071 }
4072
4073 void testRGRender(GLenum internalformat, GLenum format)
4074 {
4075 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
4076 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
4077 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
4078 mRenderbuffer);
4079 glBindRenderbuffer(GL_RENDERBUFFER, 0);
4080 EXPECT_GL_NO_ERROR();
4081
4082 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
4083 glClear(GL_COLOR_BUFFER_BIT);
4084
4085 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
4086
4087 ASSERT_GL_NO_ERROR();
4088 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor(255u, 255u, 255u, 255u)));
4089 }
4090
4091 GLuint mRenderableTexture;
4092 GLuint mTestTexture;
4093 GLuint mFBO;
4094 GLuint mRenderbuffer;
4095};
4096
4097// Test unorm texture formats enabled by the GL_EXT_texture_rg extension.
4098TEST_P(Texture2DRGTest, TextureRGUNormTest)
4099{
4100 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_rg"));
4101
4102 GLubyte pixelValue = 0xab;
4103 GLubyte imageData[] = {pixelValue, pixelValue};
4104
4105 setupFormatTextures(GL_RED_EXT, GL_RED_EXT, GL_UNSIGNED_BYTE, imageData);
4106 testRGTexture(
4107 SliceFormatColor(GL_RED_EXT, GLColor(pixelValue, pixelValue, pixelValue, pixelValue)));
4108 testRGRender(GL_R8_EXT, GL_RED_EXT);
4109
4110 setupFormatTextures(GL_RG_EXT, GL_RG_EXT, GL_UNSIGNED_BYTE, imageData);
4111 testRGTexture(
4112 SliceFormatColor(GL_RG_EXT, GLColor(pixelValue, pixelValue, pixelValue, pixelValue)));
4113 testRGRender(GL_RG8_EXT, GL_RG_EXT);
4114}
4115
4116// Test float texture formats enabled by the GL_EXT_texture_rg extension.
4117TEST_P(Texture2DRGTest, TextureRGFloatTest)
4118{
4119 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_rg"));
4120 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_float"));
4121
4122 GLfloat pixelValue = 0.54321;
4123 GLfloat imageData[] = {pixelValue, pixelValue};
4124
4125 GLubyte expectedValue = static_cast<GLubyte>(pixelValue * 255.0f);
4126 GLColor expectedColor = GLColor(expectedValue, expectedValue, expectedValue, expectedValue);
4127
4128 setupFormatTextures(GL_RED_EXT, GL_RED_EXT, GL_FLOAT, imageData);
4129 testRGTexture(SliceFormatColor(GL_RED_EXT, expectedColor));
4130
4131 setupFormatTextures(GL_RG_EXT, GL_RG_EXT, GL_FLOAT, imageData);
4132 testRGTexture(SliceFormatColor(GL_RG_EXT, expectedColor));
4133}
4134
4135// Test half-float texture formats enabled by the GL_EXT_texture_rg extension.
4136TEST_P(Texture2DRGTest, TextureRGFHalfFloatTest)
4137{
4138 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_rg"));
4139 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_texture_half_float"));
4140
4141 GLfloat pixelValueFloat = 0.543f;
4142 GLhalf pixelValue = 0x3858;
4143 GLhalf imageData[] = {pixelValue, pixelValue};
4144
4145 GLubyte expectedValue = static_cast<GLubyte>(pixelValueFloat * 255.0f);
4146 GLColor expectedColor = GLColor(expectedValue, expectedValue, expectedValue, expectedValue);
4147
4148 setupFormatTextures(GL_RED_EXT, GL_RED_EXT, GL_HALF_FLOAT_OES, imageData);
4149 testRGTexture(SliceFormatColor(GL_RED_EXT, expectedColor));
4150
4151 setupFormatTextures(GL_RG_EXT, GL_RG_EXT, GL_HALF_FLOAT_OES, imageData);
4152 testRGTexture(SliceFormatColor(GL_RG_EXT, expectedColor));
4153}
4154
Olli Etuaho95faa232016-06-07 14:01:53 -07004155// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
4156// GLES 3.0.4 section 3.8.3.
4157TEST_P(Texture2DTestES3, UnpackSkipImages2D)
4158{
Yuly Novikovd18c0482019-04-04 19:56:43 -04004159 // Crashes on Nexus 5X due to a driver bug. http://anglebug.com/1429
4160 ANGLE_SKIP_TEST_IF((IsNexus5X() || IsNexus6P()) && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07004161
4162 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4163 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4164 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4165 ASSERT_GL_NO_ERROR();
4166
4167 // SKIP_IMAGES should not have an effect on uploading 2D textures
4168 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
4169 ASSERT_GL_NO_ERROR();
4170
4171 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
4172
4173 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4174 pixelsGreen.data());
4175 ASSERT_GL_NO_ERROR();
4176
4177 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
4178 pixelsGreen.data());
4179 ASSERT_GL_NO_ERROR();
4180
4181 glUseProgram(mProgram);
4182 drawQuad(mProgram, "position", 0.5f);
4183 ASSERT_GL_NO_ERROR();
4184
4185 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
4186}
4187
Olli Etuaho989cac32016-06-08 16:18:49 -07004188// Test that skip defined in unpack parameters is taken into account when determining whether
4189// unpacking source extends outside unpack buffer bounds.
4190TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
4191{
4192 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4193 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4194 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4195 ASSERT_GL_NO_ERROR();
4196
4197 GLBuffer buf;
4198 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
4199 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
4200 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
4201 GL_DYNAMIC_COPY);
4202 ASSERT_GL_NO_ERROR();
4203
4204 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4205 ASSERT_GL_NO_ERROR();
4206
4207 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
4208 ASSERT_GL_NO_ERROR();
4209
4210 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4211 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4212
4213 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
4214 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
4215 ASSERT_GL_NO_ERROR();
4216
4217 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4218 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4219}
4220
Olli Etuaho218cf9e2016-05-20 13:55:24 +03004221// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
4222TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
4223{
Yunchao He9550c602018-02-13 14:47:05 +08004224 ANGLE_SKIP_TEST_IF(IsD3D11());
4225
4226 // Incorrect rendering results seen on OSX AMD.
4227 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03004228
4229 const GLuint width = 8u;
4230 const GLuint height = 8u;
4231 const GLuint unpackRowLength = 5u;
4232 const GLuint unpackSkipPixels = 1u;
4233
4234 setWindowWidth(width);
4235 setWindowHeight(height);
4236
4237 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4238 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4239 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4240 ASSERT_GL_NO_ERROR();
4241
4242 GLBuffer buf;
4243 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
4244 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
4245 GLColor::green);
4246
4247 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
4248 {
4249 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
4250 }
4251
4252 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
4253 GL_DYNAMIC_COPY);
4254 ASSERT_GL_NO_ERROR();
4255
4256 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
4257 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
4258 ASSERT_GL_NO_ERROR();
4259
4260 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
4261 ASSERT_GL_NO_ERROR();
4262
4263 glUseProgram(mProgram);
4264 drawQuad(mProgram, "position", 0.5f);
4265 ASSERT_GL_NO_ERROR();
4266
4267 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
4268 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
4269 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
4270 actual.data());
4271 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
4272 EXPECT_EQ(expected, actual);
4273}
4274
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004275template <typename T>
4276T UNorm(double value)
4277{
4278 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
4279}
4280
4281// Test rendering a depth texture with mipmaps.
4282TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
4283{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08004284 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
4285 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
Jiawei Shaoaf0f31d2018-09-27 15:42:31 +08004286 // http://anglebug.com/1706
4287 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Corentin Walleze731d8a2016-09-07 10:56:25 -04004288
Jamie Madill24980272019-04-03 09:03:51 -04004289 // Seems to fail on AMD D3D11. Possibly driver bug. http://anglebug.com/3342
4290 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsD3D11());
4291
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004292 const int size = getWindowWidth();
4293
4294 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04004295 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04004296
4297 glActiveTexture(GL_TEXTURE0);
4298 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4299 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
4300 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4301 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4302 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
4303 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
4304 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4305 ASSERT_GL_NO_ERROR();
4306
4307 glUseProgram(mProgram);
4308 glUniform1i(mTexture2DUniformLocation, 0);
4309
4310 std::vector<unsigned char> expected;
4311
4312 for (int level = 0; level < levels; ++level)
4313 {
4314 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
4315 expected.push_back(UNorm<unsigned char>(value));
4316
4317 int levelDim = dim(level);
4318
4319 ASSERT_GT(levelDim, 0);
4320
4321 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
4322 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
4323 GL_UNSIGNED_INT, initData.data());
4324 }
4325 ASSERT_GL_NO_ERROR();
4326
4327 for (int level = 0; level < levels; ++level)
4328 {
4329 glViewport(0, 0, dim(level), dim(level));
4330 drawQuad(mProgram, "position", 0.5f);
4331 GLColor actual = ReadColor(0, 0);
4332 EXPECT_NEAR(expected[level], actual.R, 10u);
4333 }
4334
4335 ASSERT_GL_NO_ERROR();
4336}
4337
Jamie Madill7ffdda92016-09-08 13:26:51 -04004338// Tests unpacking into the unsized GL_ALPHA format.
4339TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
4340{
Jamie Madill7ffdda92016-09-08 13:26:51 -04004341 // Initialize the texure.
4342 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4343 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
4344 GL_UNSIGNED_BYTE, nullptr);
4345 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4346 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4347
4348 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
4349
4350 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04004351 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04004352 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4353 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4354 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
4355 GL_STATIC_DRAW);
4356
4357 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
4358 GL_UNSIGNED_BYTE, nullptr);
4359
4360 // Clear to a weird color to make sure we're drawing something.
4361 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
4362 glClear(GL_COLOR_BUFFER_BIT);
4363
4364 // Draw with the alpha texture and verify.
4365 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04004366
4367 ASSERT_GL_NO_ERROR();
4368 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
4369}
4370
Jamie Madill2e600342016-09-19 13:56:40 -04004371// Ensure stale unpack data doesn't propagate in D3D11.
4372TEST_P(Texture2DTestES3, StaleUnpackData)
4373{
4374 // Init unpack buffer.
4375 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
4376 std::vector<GLColor> pixels(pixelCount, GLColor::red);
4377
4378 GLBuffer unpackBuffer;
4379 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
4380 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
4381 GLsizei bufferSize = pixelCount * sizeof(GLColor);
4382 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
4383
4384 // Create from unpack buffer.
4385 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4386 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
4387 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4388 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4389 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4390
4391 drawQuad(mProgram, "position", 0.5f);
4392
4393 ASSERT_GL_NO_ERROR();
4394 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4395
4396 // Fill unpack with green, recreating buffer.
4397 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
4398 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
4399 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
4400
4401 // Reinit texture with green.
4402 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
4403 GL_UNSIGNED_BYTE, nullptr);
4404
4405 drawQuad(mProgram, "position", 0.5f);
4406
4407 ASSERT_GL_NO_ERROR();
4408 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
4409}
4410
Geoff Langfb7685f2017-11-13 11:44:11 -05004411// Ensure that texture parameters passed as floats that are converted to ints are rounded before
4412// validating they are less than 0.
4413TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
4414{
4415 GLTexture texture;
4416 glBindTexture(GL_TEXTURE_2D, texture);
4417
4418 // Use a negative number that will round to zero when converted to an integer
4419 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
4420 // "Validation of values performed by state-setting commands is performed after conversion,
4421 // unless specified otherwise for a specific command."
4422 GLfloat param = -7.30157126e-07f;
4423 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
4424 EXPECT_GL_NO_ERROR();
4425
4426 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
4427 EXPECT_GL_NO_ERROR();
4428}
4429
Jamie Madillf097e232016-11-05 00:44:15 -04004430// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
4431// being properly checked, and the texture storage of the previous texture format was persisting.
4432// This would result in an ASSERT in debug and incorrect rendering in release.
4433// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
4434TEST_P(Texture3DTestES3, FormatRedefinitionBug)
4435{
4436 GLTexture tex;
4437 glBindTexture(GL_TEXTURE_3D, tex.get());
4438 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4439
4440 GLFramebuffer framebuffer;
4441 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
4442 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
4443
4444 glCheckFramebufferStatus(GL_FRAMEBUFFER);
4445
4446 std::vector<uint8_t> pixelData(100, 0);
4447
4448 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
4449 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
4450 pixelData.data());
4451
4452 ASSERT_GL_NO_ERROR();
4453}
4454
Corentin Wallezd2627992017-04-28 17:17:03 -04004455// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
4456TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
4457{
4458 // 2D tests
4459 {
4460 GLTexture tex;
4461 glBindTexture(GL_TEXTURE_2D, tex.get());
4462
4463 GLBuffer pbo;
4464 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4465
4466 // Test OOB
4467 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
4468 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4469 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4470
4471 // Test OOB
4472 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
4473 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4474 ASSERT_GL_NO_ERROR();
4475 }
4476
4477 // 3D tests
4478 {
4479 GLTexture tex;
4480 glBindTexture(GL_TEXTURE_3D, tex.get());
4481
4482 GLBuffer pbo;
4483 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
4484
4485 // Test OOB
4486 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
4487 GL_STATIC_DRAW);
4488 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4489 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
4490
4491 // Test OOB
4492 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
4493 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4494 ASSERT_GL_NO_ERROR();
4495 }
4496}
4497
Jamie Madill3ed60422017-09-07 11:32:52 -04004498// Tests behaviour with a single texture and multiple sampler objects.
4499TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
4500{
4501 GLint maxTextureUnits = 0;
4502 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
4503 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
4504
4505 constexpr int kSize = 16;
4506
4507 // Make a single-level texture, fill it with red.
4508 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
4509 GLTexture tex;
4510 glBindTexture(GL_TEXTURE_2D, tex);
4511 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4512 redColors.data());
4513 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4514 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4515
4516 // Simple sanity check.
4517 draw2DTexturedQuad(0.5f, 1.0f, true);
4518 ASSERT_GL_NO_ERROR();
4519 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4520
4521 // Bind texture to unit 1 with a sampler object making it incomplete.
4522 GLSampler sampler;
4523 glBindSampler(0, sampler);
4524 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4525 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4526
4527 // Make a mipmap texture, fill it with blue.
4528 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
4529 GLTexture mipmapTex;
4530 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4531 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4532 blueColors.data());
4533 glGenerateMipmap(GL_TEXTURE_2D);
4534
4535 // Draw with the sampler, expect blue.
4536 draw2DTexturedQuad(0.5f, 1.0f, true);
4537 ASSERT_GL_NO_ERROR();
4538 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
4539
4540 // Simple multitexturing program.
Jamie Madill35cd7332018-12-02 12:03:33 -05004541 constexpr char kVS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004542 "#version 300 es\n"
4543 "in vec2 position;\n"
4544 "out vec2 texCoord;\n"
4545 "void main()\n"
4546 "{\n"
4547 " gl_Position = vec4(position, 0, 1);\n"
4548 " texCoord = position * 0.5 + vec2(0.5);\n"
4549 "}";
Jamie Madill35cd7332018-12-02 12:03:33 -05004550
4551 constexpr char kFS[] =
Jamie Madill3ed60422017-09-07 11:32:52 -04004552 "#version 300 es\n"
4553 "precision mediump float;\n"
4554 "in vec2 texCoord;\n"
4555 "uniform sampler2D tex1;\n"
4556 "uniform sampler2D tex2;\n"
4557 "uniform sampler2D tex3;\n"
4558 "uniform sampler2D tex4;\n"
4559 "out vec4 color;\n"
4560 "void main()\n"
4561 "{\n"
4562 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
4563 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
4564 "}";
4565
Jamie Madill35cd7332018-12-02 12:03:33 -05004566 ANGLE_GL_PROGRAM(program, kVS, kFS);
Jamie Madill3ed60422017-09-07 11:32:52 -04004567
4568 std::array<GLint, 4> texLocations = {
4569 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
4570 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
4571 for (GLint location : texLocations)
4572 {
4573 ASSERT_NE(-1, location);
4574 }
4575
4576 // Init the uniform data.
4577 glUseProgram(program);
4578 for (GLint location = 0; location < 4; ++location)
4579 {
4580 glUniform1i(texLocations[location], location);
4581 }
4582
4583 // Initialize four samplers
4584 GLSampler samplers[4];
4585
4586 // 0: non-mipped.
4587 glBindSampler(0, samplers[0]);
4588 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4589 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4590
4591 // 1: mipped.
4592 glBindSampler(1, samplers[1]);
4593 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4594 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4595
4596 // 2: non-mipped.
4597 glBindSampler(2, samplers[2]);
4598 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4599 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4600
4601 // 3: mipped.
4602 glBindSampler(3, samplers[3]);
4603 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4604 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4605
4606 // Bind two blue mipped textures and two single layer textures, should all draw.
4607 glActiveTexture(GL_TEXTURE0);
4608 glBindTexture(GL_TEXTURE_2D, tex);
4609
4610 glActiveTexture(GL_TEXTURE1);
4611 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4612
4613 glActiveTexture(GL_TEXTURE2);
4614 glBindTexture(GL_TEXTURE_2D, tex);
4615
4616 glActiveTexture(GL_TEXTURE3);
4617 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4618
4619 ASSERT_GL_NO_ERROR();
4620
4621 drawQuad(program, "position", 0.5f);
4622 ASSERT_GL_NO_ERROR();
4623 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
4624
4625 // Bind four single layer textures, two should be incomplete.
4626 glActiveTexture(GL_TEXTURE1);
4627 glBindTexture(GL_TEXTURE_2D, tex);
4628
4629 glActiveTexture(GL_TEXTURE3);
4630 glBindTexture(GL_TEXTURE_2D, tex);
4631
4632 drawQuad(program, "position", 0.5f);
4633 ASSERT_GL_NO_ERROR();
4634 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
4635}
4636
Martin Radev7e2c0d32017-09-15 14:25:42 +03004637// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
4638// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
4639// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
4640// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
4641// samples the cubemap using a direction vector (1,1,1).
4642TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
4643{
Yunchao He2f23f352018-02-11 22:11:37 +08004644 // Check http://anglebug.com/2155.
4645 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
4646
Jamie Madill35cd7332018-12-02 12:03:33 -05004647 constexpr char kVS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004648 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004649 precision mediump float;
4650 in vec3 pos;
4651 void main() {
4652 gl_Position = vec4(pos, 1.0);
4653 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03004654
Jamie Madill35cd7332018-12-02 12:03:33 -05004655 constexpr char kFS[] =
Martin Radev7e2c0d32017-09-15 14:25:42 +03004656 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004657 precision mediump float;
4658 out vec4 color;
4659 uniform samplerCube uTex;
4660 void main(){
4661 color = texture(uTex, vec3(1.0));
4662 })";
Jamie Madill35cd7332018-12-02 12:03:33 -05004663
4664 ANGLE_GL_PROGRAM(program, kVS, kFS);
Martin Radev7e2c0d32017-09-15 14:25:42 +03004665 glUseProgram(program);
4666
4667 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
4668 glActiveTexture(GL_TEXTURE0);
4669
4670 GLTexture cubeTex;
4671 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
4672
4673 const int kFaceWidth = 1;
4674 const int kFaceHeight = 1;
4675 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
4676 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4677 GL_UNSIGNED_BYTE, texData.data());
4678 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4679 GL_UNSIGNED_BYTE, texData.data());
4680 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4681 GL_UNSIGNED_BYTE, texData.data());
4682 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4683 GL_UNSIGNED_BYTE, texData.data());
4684 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4685 GL_UNSIGNED_BYTE, texData.data());
4686 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4687 GL_UNSIGNED_BYTE, texData.data());
4688 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4689 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4690 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
4691 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
4692 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
4693 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
4694
4695 drawQuad(program, "pos", 0.5f, 1.0f, true);
4696 ASSERT_GL_NO_ERROR();
4697
4698 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4699}
4700
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08004701// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
4702TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
4703{
4704 GLuint texture = create2DTexture();
4705
4706 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
4707 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4708
4709 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
4710 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4711
4712 glDeleteTextures(1, &texture);
4713 EXPECT_GL_NO_ERROR();
4714}
4715
Olli Etuaho023371b2018-04-24 17:43:32 +03004716// Test setting base level after calling generateMipmap on a LUMA texture.
4717// Covers http://anglebug.com/2498
4718TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA)
4719{
4720 glActiveTexture(GL_TEXTURE0);
4721 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4722
4723 constexpr const GLsizei kWidth = 8;
4724 constexpr const GLsizei kHeight = 8;
4725 std::array<GLubyte, kWidth * kHeight * 2> whiteData;
4726 whiteData.fill(255u);
4727
4728 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA,
4729 GL_UNSIGNED_BYTE, whiteData.data());
4730 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
4731 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4732 glGenerateMipmap(GL_TEXTURE_2D);
4733 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
4734 EXPECT_GL_NO_ERROR();
4735
4736 drawQuad(mProgram, "position", 0.5f);
4737 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4738}
4739
Till Rathmannc1551dc2018-08-15 17:04:49 +02004740// Covers a bug in the D3D11 backend: http://anglebug.com/2772
4741// When using a sampler the texture was created as if it has mipmaps,
4742// regardless what you specified in GL_TEXTURE_MIN_FILTER via
4743// glSamplerParameteri() -- mistakenly the default value
4744// GL_NEAREST_MIPMAP_LINEAR or the value set via glTexParameteri() was
4745// evaluated.
4746// If you didn't provide mipmaps and didn't let the driver generate them
4747// this led to not sampling your texture data when minification occurred.
4748TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping)
4749{
Jamie Madill35cd7332018-12-02 12:03:33 -05004750 constexpr char kVS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004751 "#version 300 es\n"
4752 "out vec2 texcoord;\n"
4753 "in vec4 position;\n"
4754 "void main()\n"
4755 "{\n"
4756 " gl_Position = vec4(position.xy * 0.1, 0.0, 1.0);\n"
4757 " texcoord = (position.xy * 0.5) + 0.5;\n"
4758 "}\n";
4759
Jamie Madill35cd7332018-12-02 12:03:33 -05004760 constexpr char kFS[] =
Till Rathmannc1551dc2018-08-15 17:04:49 +02004761 "#version 300 es\n"
4762 "precision highp float;\n"
4763 "uniform highp sampler2D tex;\n"
4764 "in vec2 texcoord;\n"
4765 "out vec4 fragColor;\n"
4766 "void main()\n"
4767 "{\n"
4768 " fragColor = texture(tex, texcoord);\n"
4769 "}\n";
Jamie Madill35cd7332018-12-02 12:03:33 -05004770
4771 ANGLE_GL_PROGRAM(program, kVS, kFS);
Till Rathmannc1551dc2018-08-15 17:04:49 +02004772
4773 GLSampler sampler;
4774 glBindSampler(0, sampler);
4775 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4776 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4777
4778 glActiveTexture(GL_TEXTURE0);
4779 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4780
4781 const GLsizei texWidth = getWindowWidth();
4782 const GLsizei texHeight = getWindowHeight();
4783 const std::vector<GLColor> whiteData(texWidth * texHeight, GLColor::white);
4784
4785 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4786 whiteData.data());
4787 EXPECT_GL_NO_ERROR();
4788
4789 drawQuad(program, "position", 0.5f);
4790 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, angle::GLColor::white);
4791}
4792
Anders Leinof6cbe442019-04-18 15:32:07 +03004793// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4794// texture is output.
4795TEST_P(Texture2DIntegerTestES3, IntegerTextureNonZeroBaseLevel)
4796{
Yuly Novikovd2683452019-05-23 16:11:19 -04004797 // http://anglebug.com/3478
4798 ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsDesktopOpenGL());
4799
Anders Leinof6cbe442019-04-18 15:32:07 +03004800 glActiveTexture(GL_TEXTURE0);
4801 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4802 int width = getWindowWidth();
4803 int height = getWindowHeight();
4804 GLColor color = GLColor::green;
4805 std::vector<GLColor> pixels(width * height, color);
4806 GLint baseLevel = 1;
4807 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
4808 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4809 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4810 glTexImage2D(GL_TEXTURE_2D, baseLevel, GL_RGBA8UI, width, height, 0, GL_RGBA_INTEGER,
4811 GL_UNSIGNED_BYTE, pixels.data());
4812
4813 setUpProgram();
4814 glUseProgram(mProgram);
4815 glUniform1i(mTexture2DUniformLocation, 0);
4816 drawQuad(mProgram, "position", 0.5f);
4817
4818 EXPECT_GL_NO_ERROR();
4819 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4820 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4821}
4822
Anders Leino60cc7512019-05-06 09:25:27 +03004823// Draw a quad with an integer cube texture with a non-zero base level, and test that the color of
4824// the texture is output.
4825TEST_P(TextureCubeIntegerTestES3, IntegerCubeTextureNonZeroBaseLevel)
4826{
4827 // All output checks returned black, rather than the texture color.
4828 ANGLE_SKIP_TEST_IF(IsOSX() && IsOpenGL());
4829
4830 glActiveTexture(GL_TEXTURE0);
4831
4832 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
4833 GLint baseLevel = 1;
4834 int width = getWindowWidth();
4835 int height = getWindowHeight();
4836 GLColor color = GLColor::green;
4837 std::vector<GLColor> pixels(width * height, color);
4838 for (GLenum faceIndex = 0; faceIndex < 6; faceIndex++)
4839 {
4840 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, baseLevel, GL_RGBA8UI, width,
4841 height, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
4842 EXPECT_GL_NO_ERROR();
4843 }
4844 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, baseLevel);
4845 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4846 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4847
4848 glUseProgram(mProgram);
4849 glUniform1i(mTextureCubeUniformLocation, 0);
4850 drawQuad(mProgram, "position", 0.5f);
4851
4852 EXPECT_GL_NO_ERROR();
4853 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4854 EXPECT_PIXEL_COLOR_EQ(width - 1, 0, color);
4855 EXPECT_PIXEL_COLOR_EQ(0, height - 1, color);
4856 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4857}
4858
Anders Leinoe4452442019-05-09 13:29:49 +03004859// This test sets up a cube map with four distincly colored MIP levels.
4860// The size of the texture and the geometry is chosen such that levels 1 or 2 should be chosen at
4861// the corners of the screen.
4862TEST_P(TextureCubeIntegerEdgeTestES3, IntegerCubeTextureCorner)
4863{
4864 glActiveTexture(GL_TEXTURE0);
4865
4866 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
4867 int width = getWindowWidth();
4868 int height = getWindowHeight();
4869 ASSERT_EQ(width, height);
4870 GLColor color[4] = {GLColor::white, GLColor::green, GLColor::blue, GLColor::red};
4871 for (GLint level = 0; level < 4; level++)
4872 {
4873 for (GLenum faceIndex = 0; faceIndex < 6; faceIndex++)
4874 {
4875 int levelWidth = (2 * width) >> level;
4876 int levelHeight = (2 * height) >> level;
4877 std::vector<GLColor> pixels(levelWidth * levelHeight, color[level]);
4878 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, level, GL_RGBA8UI, levelWidth,
4879 levelHeight, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
4880 EXPECT_GL_NO_ERROR();
4881 }
4882 }
4883 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4884 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4885 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 3);
4886
4887 glUseProgram(mProgram);
4888 glUniform1i(mTextureCubeUniformLocation, 0);
4889 drawQuad(mProgram, "position", 0.5f);
4890
4891 ASSERT_GL_NO_ERROR();
4892 // Check that we do not read from levels 0 or 3. Levels 1 and 2 are both acceptable.
4893 EXPECT_EQ(ReadColor(0, 0).R, 0);
4894 EXPECT_EQ(ReadColor(width - 1, 0).R, 0);
4895 EXPECT_EQ(ReadColor(0, height - 1).R, 0);
4896 EXPECT_EQ(ReadColor(width - 1, height - 1).R, 0);
4897}
4898
Anders Leino1b6aded2019-05-20 12:56:34 +03004899// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4900// texture is output.
4901TEST_P(Texture2DIntegerProjectiveOffsetTestES3, NonZeroBaseLevel)
4902{
Jamie Madill29ac2742019-05-28 15:53:00 -04004903 // Fails on AMD: http://crbug.com/967796
Jamie Madill06055b52019-05-29 14:31:42 -04004904 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsOpenGL());
Jamie Madill29ac2742019-05-28 15:53:00 -04004905
Anders Leino1b6aded2019-05-20 12:56:34 +03004906 glActiveTexture(GL_TEXTURE0);
4907 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4908 int width = getWindowWidth();
4909 int height = getWindowHeight();
4910 GLColor color = GLColor::green;
4911 std::vector<GLColor> pixels(width * height, color);
4912 GLint baseLevel = 1;
4913 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
4914 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4915 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4916 glTexImage2D(GL_TEXTURE_2D, baseLevel, GL_RGBA8UI, width, height, 0, GL_RGBA_INTEGER,
4917 GL_UNSIGNED_BYTE, pixels.data());
4918
4919 setUpProgram();
4920 glUseProgram(mProgram);
4921 glUniform1i(mTexture2DUniformLocation, 0);
4922 drawQuad(mProgram, "position", 0.5f);
4923
4924 EXPECT_GL_NO_ERROR();
4925 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4926 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4927}
4928
Anders Leino69d04932019-05-20 14:04:13 +03004929// Draw a quad with an integer texture with a non-zero base level, and test that the color of the
4930// texture is output.
4931TEST_P(Texture2DArrayIntegerTestES3, NonZeroBaseLevel)
4932{
4933 glActiveTexture(GL_TEXTURE0);
4934 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
4935 int width = getWindowWidth();
4936 int height = getWindowHeight();
4937 int depth = 2;
4938 GLColor color = GLColor::green;
4939 std::vector<GLColor> pixels(width * height * depth, color);
4940 GLint baseLevel = 1;
4941 glTexImage3D(GL_TEXTURE_2D_ARRAY, baseLevel, GL_RGBA8UI, width, height, depth, 0,
4942 GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, pixels.data());
4943 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, baseLevel);
4944 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4945 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4946
4947 drawQuad(mProgram, "position", 0.5f);
4948
4949 EXPECT_GL_NO_ERROR();
4950 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4951 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4952}
4953
Anders Leino262e2822019-05-20 14:24:40 +03004954// Draw a quad with an integer 3D texture with a non-zero base level, and test that the color of the
4955// texture is output.
4956TEST_P(Texture3DIntegerTestES3, NonZeroBaseLevel)
4957{
4958 glActiveTexture(GL_TEXTURE0);
4959 glBindTexture(GL_TEXTURE_3D, mTexture3D);
4960 int width = getWindowWidth();
4961 int height = getWindowHeight();
4962 int depth = 2;
4963 GLColor color = GLColor::green;
4964 std::vector<GLColor> pixels(width * height * depth, color);
4965 GLint baseLevel = 1;
4966 glTexImage3D(GL_TEXTURE_3D, baseLevel, GL_RGBA8UI, width, height, depth, 0, GL_RGBA_INTEGER,
4967 GL_UNSIGNED_BYTE, pixels.data());
4968 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, baseLevel);
4969 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4970 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4971
4972 drawQuad(mProgram, "position", 0.5f);
4973
4974 EXPECT_GL_NO_ERROR();
4975 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
4976 EXPECT_PIXEL_COLOR_EQ(width - 1, height - 1, color);
4977}
4978
Jamie Madill50cf2be2018-06-15 09:46:57 -04004979// Use this to select which configurations (e.g. which renderer, which GLES major version) these
4980// tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -05004981ANGLE_INSTANTIATE_TEST(Texture2DTest,
4982 ES2_D3D9(),
4983 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004984 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05004985 ES2_OPENGLES(),
4986 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004987ANGLE_INSTANTIATE_TEST(TextureCubeTest,
4988 ES2_D3D9(),
4989 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004990 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004991 ES2_OPENGLES(),
4992 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004993ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
4994 ES2_D3D9(),
4995 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004996 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004997 ES2_OPENGLES(),
4998 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004999ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
5000 ES2_D3D9(),
5001 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05005002 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005003 ES2_OPENGLES(),
5004 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05005005ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
5006 ES2_D3D9(),
5007 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05005008 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005009 ES2_OPENGLES(),
5010 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05005011ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
5012 ES2_D3D9(),
5013 ES2_D3D11(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05005014 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005015 ES2_OPENGLES(),
5016 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05005017ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02005018ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
James Dong8bb6baa2019-06-18 15:30:16 -06005019ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3,
5020 ES3_D3D11(),
5021 ES3_OPENGL(),
5022 ES3_OPENGLES(),
5023 ES3_VULKAN());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02005024ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
5025 ES3_D3D11(),
5026 ES3_OPENGL(),
James Dong8bb6baa2019-06-18 15:30:16 -06005027 ES3_OPENGLES(),
5028 ES3_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05005029ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
5030 ES3_D3D11(),
5031 ES3_OPENGL(),
5032 ES3_OPENGLES());
James Dong8bb6baa2019-06-18 15:30:16 -06005033ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3,
5034 ES3_D3D11(),
5035 ES3_OPENGL(),
5036 ES3_OPENGLES(),
5037 ES3_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05005038ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02005039ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02005040ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
5041 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02005042 ES2_D3D9(),
5043 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005044 ES2_OPENGLES(),
5045 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02005046ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
5047 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02005048 ES2_D3D9(),
5049 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005050 ES2_OPENGLES(),
5051 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02005052ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
5053 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02005054 ES2_D3D9(),
5055 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005056 ES2_OPENGLES(),
5057 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02005058ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
5059 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02005060 ES2_D3D9(),
5061 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005062 ES2_OPENGLES(),
5063 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02005064ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
5065 ES2_D3D11(),
Olli Etuaho96963162016-03-21 11:54:33 +02005066 ES2_D3D9(),
5067 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005068 ES2_OPENGLES(),
5069 ES2_VULKAN());
Shahbaz Youssefi962c2222019-02-20 15:43:41 -05005070ANGLE_INSTANTIATE_TEST(TextureAnisotropyTest,
5071 ES2_D3D11(),
5072 ES2_D3D9(),
5073 ES2_OPENGL(),
5074 ES2_OPENGLES(),
5075 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02005076ANGLE_INSTANTIATE_TEST(TextureBorderClampTest,
5077 ES2_D3D11(),
5078 ES2_D3D9(),
5079 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05005080 ES2_OPENGLES(),
5081 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02005082ANGLE_INSTANTIATE_TEST(TextureBorderClampTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
5083ANGLE_INSTANTIATE_TEST(TextureBorderClampIntegerTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Luc Ferronaf883622018-06-08 15:57:31 -04005084ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN());
Vincent Lang25ab4512016-05-13 18:13:59 +02005085ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Mohan Maiya8f1169e2019-06-27 15:32:32 -07005086ANGLE_INSTANTIATE_TEST(Texture2DRGTest,
5087 ES2_D3D11(),
5088 ES3_D3D11(),
5089 ES2_OPENGL(),
5090 ES3_OPENGL(),
5091 ES2_OPENGLES(),
5092 ES3_OPENGLES(),
5093 ES2_VULKAN(),
5094 ES3_VULKAN());
Martin Radev7e2c0d32017-09-15 14:25:42 +03005095ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Anders Leinof6cbe442019-04-18 15:32:07 +03005096ANGLE_INSTANTIATE_TEST(Texture2DIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino60cc7512019-05-06 09:25:27 +03005097ANGLE_INSTANTIATE_TEST(TextureCubeIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leinoe4452442019-05-09 13:29:49 +03005098ANGLE_INSTANTIATE_TEST(TextureCubeIntegerEdgeTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino1b6aded2019-05-20 12:56:34 +03005099ANGLE_INSTANTIATE_TEST(Texture2DIntegerProjectiveOffsetTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino69d04932019-05-20 14:04:13 +03005100ANGLE_INSTANTIATE_TEST(Texture2DArrayIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Anders Leino262e2822019-05-20 14:24:40 +03005101ANGLE_INSTANTIATE_TEST(Texture3DIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
Jamie Madillfa05f602015-05-07 13:47:11 -04005102
Jamie Madill7ffdda92016-09-08 13:26:51 -04005103} // anonymous namespace