blob: 7e7a3cd8b2fdf36b84bc06bc456b03f7367b33aa [file] [log] [blame]
Jamie Madillfa05f602015-05-07 13:47:11 -04001//
2// Copyright 2015 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Jamie Madill14718762016-09-06 15:56:54 -04007#include "common/mathutil.h"
Corentin Wallezd3970de2015-05-14 11:07:48 -04008#include "test_utils/ANGLETest.h"
Olli Etuaho989cac32016-06-08 16:18:49 -07009#include "test_utils/gl_raii.h"
Jamie Madillf67115c2014-04-22 13:14:05 -040010
Jamie Madillfa05f602015-05-07 13:47:11 -040011using namespace angle;
Austin Kinross18b931d2014-09-29 12:58:31 -070012
Jamie Madillfa05f602015-05-07 13:47:11 -040013namespace
14{
15
Vincent Lang25ab4512016-05-13 18:13:59 +020016// Take a pixel, and reset the components not covered by the format to default
Geoff Langf607c602016-09-21 11:46:48 -040017// values. In particular, the default value for the alpha component is 255
Vincent Lang25ab4512016-05-13 18:13:59 +020018// (1.0 as unsigned normalized fixed point value).
Geoff Langf607c602016-09-21 11:46:48 -040019GLColor SliceFormatColor(GLenum format, GLColor full)
Vincent Lang25ab4512016-05-13 18:13:59 +020020{
21 switch (format)
22 {
23 case GL_RED:
Geoff Langf607c602016-09-21 11:46:48 -040024 return GLColor(full.R, 0, 0, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020025 case GL_RG:
Geoff Langf607c602016-09-21 11:46:48 -040026 return GLColor(full.R, full.G, 0, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020027 case GL_RGB:
Geoff Langf607c602016-09-21 11:46:48 -040028 return GLColor(full.R, full.G, full.B, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020029 case GL_RGBA:
30 return full;
31 default:
Jamie Madille1faacb2016-12-13 12:42:14 -050032 EXPECT_TRUE(false);
Geoff Langf607c602016-09-21 11:46:48 -040033 return GLColor::white;
Vincent Lang25ab4512016-05-13 18:13:59 +020034 }
Vincent Lang25ab4512016-05-13 18:13:59 +020035}
36
Olli Etuaho4a8329f2016-01-11 17:12:57 +020037class TexCoordDrawTest : public ANGLETest
Jamie Madillf67115c2014-04-22 13:14:05 -040038{
Jamie Madillbc393df2015-01-29 13:46:07 -050039 protected:
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020040 TexCoordDrawTest() : ANGLETest(), mProgram(0), mFramebuffer(0), mFramebufferColorTexture(0)
Jamie Madillf67115c2014-04-22 13:14:05 -040041 {
42 setWindowWidth(128);
43 setWindowHeight(128);
44 setConfigRedBits(8);
45 setConfigGreenBits(8);
46 setConfigBlueBits(8);
47 setConfigAlphaBits(8);
48 }
49
Olli Etuaho4a8329f2016-01-11 17:12:57 +020050 virtual std::string getVertexShaderSource()
Jamie Madillf67115c2014-04-22 13:14:05 -040051 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +030052 return
53 R"(precision highp float;
Geoff Langc41e42d2014-04-28 10:58:16 -040054 attribute vec4 position;
55 varying vec2 texcoord;
56
57 void main()
58 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +020059 gl_Position = vec4(position.xy, 0.0, 1.0);
Geoff Langc41e42d2014-04-28 10:58:16 -040060 texcoord = (position.xy * 0.5) + 0.5;
Olli Etuahoa20af6d2017-09-18 13:32:29 +030061 })";
Olli Etuaho4a8329f2016-01-11 17:12:57 +020062 }
Geoff Langc41e42d2014-04-28 10:58:16 -040063
Olli Etuaho4a8329f2016-01-11 17:12:57 +020064 virtual std::string getFragmentShaderSource() = 0;
65
Olli Etuahoa1c917f2016-04-06 13:50:03 +030066 virtual void setUpProgram()
Olli Etuaho4a8329f2016-01-11 17:12:57 +020067 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +020068 const std::string vertexShaderSource = getVertexShaderSource();
69 const std::string fragmentShaderSource = getFragmentShaderSource();
70
71 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
72 ASSERT_NE(0u, mProgram);
73 ASSERT_GL_NO_ERROR();
Olli Etuahoa1c917f2016-04-06 13:50:03 +030074 }
75
76 void SetUp() override
77 {
78 ANGLETest::SetUp();
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020079
80 setUpFramebuffer();
Olli Etuaho4a8329f2016-01-11 17:12:57 +020081 }
82
83 void TearDown() override
84 {
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020085 glBindFramebuffer(GL_FRAMEBUFFER, 0);
86 glDeleteFramebuffers(1, &mFramebuffer);
87 glDeleteTextures(1, &mFramebufferColorTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +020088 glDeleteProgram(mProgram);
89 ANGLETest::TearDown();
90 }
91
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020092 void setUpFramebuffer()
93 {
94 // We use an FBO to work around an issue where the default framebuffer applies SRGB
95 // conversion (particularly known to happen incorrectly on Intel GL drivers). It's not
96 // clear whether this issue can even be fixed on all backends. For example GLES 3.0.4 spec
97 // section 4.4 says that the format of the default framebuffer is entirely up to the window
98 // system, so it might be SRGB, and GLES 3.0 doesn't have a "FRAMEBUFFER_SRGB" to turn off
99 // SRGB conversion like desktop GL does.
100 // TODO(oetuaho): Get rid of this if the underlying issue is fixed.
101 glGenFramebuffers(1, &mFramebuffer);
102 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
103
104 glGenTextures(1, &mFramebufferColorTexture);
105 glBindTexture(GL_TEXTURE_2D, mFramebufferColorTexture);
106 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
107 GL_UNSIGNED_BYTE, nullptr);
108 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
109 mFramebufferColorTexture, 0);
110 ASSERT_GL_NO_ERROR();
111 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
112 glBindTexture(GL_TEXTURE_2D, 0);
113 }
114
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200115 // Returns the created texture ID.
116 GLuint create2DTexture()
117 {
118 GLuint texture2D;
119 glGenTextures(1, &texture2D);
120 glBindTexture(GL_TEXTURE_2D, texture2D);
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800121 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200122 EXPECT_GL_NO_ERROR();
123 return texture2D;
124 }
125
126 GLuint mProgram;
Olli Etuaho51f1c0f2016-01-13 16:16:24 +0200127 GLuint mFramebuffer;
128
129 private:
130 GLuint mFramebufferColorTexture;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200131};
132
133class Texture2DTest : public TexCoordDrawTest
134{
135 protected:
136 Texture2DTest() : TexCoordDrawTest(), mTexture2D(0), mTexture2DUniformLocation(-1) {}
137
138 std::string getFragmentShaderSource() override
139 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300140 return
141 R"(precision highp float;
Geoff Langc41e42d2014-04-28 10:58:16 -0400142 uniform sampler2D tex;
143 varying vec2 texcoord;
144
145 void main()
146 {
147 gl_FragColor = texture2D(tex, texcoord);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300148 })";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200149 }
Geoff Langc41e42d2014-04-28 10:58:16 -0400150
Olli Etuaho96963162016-03-21 11:54:33 +0200151 virtual const char *getTextureUniformName() { return "tex"; }
152
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300153 void setUpProgram() override
154 {
155 TexCoordDrawTest::setUpProgram();
156 mTexture2DUniformLocation = glGetUniformLocation(mProgram, getTextureUniformName());
157 ASSERT_NE(-1, mTexture2DUniformLocation);
158 }
159
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200160 void SetUp() override
161 {
162 TexCoordDrawTest::SetUp();
163 mTexture2D = create2DTexture();
Jamie Madilld4cfa572014-07-08 10:00:32 -0400164
Jamie Madill9aca0592014-10-06 16:26:59 -0400165 ASSERT_GL_NO_ERROR();
Jamie Madillf67115c2014-04-22 13:14:05 -0400166 }
167
Jamie Madillfa05f602015-05-07 13:47:11 -0400168 void TearDown() override
Jamie Madillf67115c2014-04-22 13:14:05 -0400169 {
Jamie Madilld4cfa572014-07-08 10:00:32 -0400170 glDeleteTextures(1, &mTexture2D);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200171 TexCoordDrawTest::TearDown();
Jamie Madillf67115c2014-04-22 13:14:05 -0400172 }
173
Jamie Madillbc393df2015-01-29 13:46:07 -0500174 // Tests CopyTexSubImage with floating point textures of various formats.
175 void testFloatCopySubImage(int sourceImageChannels, int destImageChannels)
176 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300177 setUpProgram();
178
Martin Radev1be913c2016-07-11 17:59:16 +0300179 if (getClientMajorVersion() < 3)
Geoff Langfbfa47c2015-03-31 11:26:00 -0400180 {
Yunchao He9550c602018-02-13 14:47:05 +0800181 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_storage") ||
182 !extensionEnabled("GL_OES_texture_float"));
Geoff Langc4e93662017-05-01 10:45:59 -0400183
Yunchao He9550c602018-02-13 14:47:05 +0800184 ANGLE_SKIP_TEST_IF((sourceImageChannels < 3 || destImageChannels < 3) &&
185 !extensionEnabled("GL_EXT_texture_rg"));
Geoff Langfbfa47c2015-03-31 11:26:00 -0400186
Yunchao He9550c602018-02-13 14:47:05 +0800187 ANGLE_SKIP_TEST_IF(destImageChannels == 3 &&
188 !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400189
Yunchao He9550c602018-02-13 14:47:05 +0800190 ANGLE_SKIP_TEST_IF(destImageChannels == 4 &&
191 !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400192
Yunchao He9550c602018-02-13 14:47:05 +0800193 ANGLE_SKIP_TEST_IF(destImageChannels <= 2);
Geoff Lang677bb6f2017-04-05 12:40:40 -0400194 }
195 else
196 {
Yunchao He9550c602018-02-13 14:47:05 +0800197 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_color_buffer_float"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400198
Yunchao He9550c602018-02-13 14:47:05 +0800199 ANGLE_SKIP_TEST_IF(destImageChannels == 3 &&
200 !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"));
Geoff Langfbfa47c2015-03-31 11:26:00 -0400201 }
202
Jamie Madill50cf2be2018-06-15 09:46:57 -0400203 // clang-format off
Jamie Madillbc393df2015-01-29 13:46:07 -0500204 GLfloat sourceImageData[4][16] =
205 {
206 { // R
207 1.0f,
208 0.0f,
209 0.0f,
210 1.0f
211 },
212 { // RG
213 1.0f, 0.0f,
214 0.0f, 1.0f,
215 0.0f, 0.0f,
216 1.0f, 1.0f
217 },
218 { // RGB
219 1.0f, 0.0f, 0.0f,
220 0.0f, 1.0f, 0.0f,
221 0.0f, 0.0f, 1.0f,
222 1.0f, 1.0f, 0.0f
223 },
224 { // RGBA
225 1.0f, 0.0f, 0.0f, 1.0f,
226 0.0f, 1.0f, 0.0f, 1.0f,
227 0.0f, 0.0f, 1.0f, 1.0f,
228 1.0f, 1.0f, 0.0f, 1.0f
229 },
230 };
Jamie Madill50cf2be2018-06-15 09:46:57 -0400231 // clang-format on
Jamie Madillbc393df2015-01-29 13:46:07 -0500232
Jamie Madill50cf2be2018-06-15 09:46:57 -0400233 GLenum imageFormats[] = {
Jamie Madillb980c562018-11-27 11:34:27 -0500234 GL_R32F,
235 GL_RG32F,
236 GL_RGB32F,
237 GL_RGBA32F,
Jamie Madillbc393df2015-01-29 13:46:07 -0500238 };
239
Jamie Madill50cf2be2018-06-15 09:46:57 -0400240 GLenum sourceUnsizedFormats[] = {
Jamie Madillb980c562018-11-27 11:34:27 -0500241 GL_RED,
242 GL_RG,
243 GL_RGB,
244 GL_RGBA,
Jamie Madillbc393df2015-01-29 13:46:07 -0500245 };
246
247 GLuint textures[2];
248
249 glGenTextures(2, textures);
250
Jamie Madill50cf2be2018-06-15 09:46:57 -0400251 GLfloat *imageData = sourceImageData[sourceImageChannels - 1];
252 GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1];
Jamie Madillbc393df2015-01-29 13:46:07 -0500253 GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1];
Jamie Madill50cf2be2018-06-15 09:46:57 -0400254 GLenum destImageFormat = imageFormats[destImageChannels - 1];
Jamie Madillbc393df2015-01-29 13:46:07 -0500255
256 glBindTexture(GL_TEXTURE_2D, textures[0]);
Geoff Langc4e93662017-05-01 10:45:59 -0400257 if (getClientMajorVersion() >= 3)
258 {
259 glTexStorage2D(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
260 }
261 else
262 {
263 glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
264 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500265 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
266 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
267 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData);
268
hendrikwb27f79a2015-03-04 11:26:46 -0800269 if (sourceImageChannels < 3 && !extensionEnabled("GL_EXT_texture_rg"))
Jamie Madillbc393df2015-01-29 13:46:07 -0500270 {
271 // This is not supported
272 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
273 }
274 else
275 {
276 ASSERT_GL_NO_ERROR();
277 }
278
279 GLuint fbo;
280 glGenFramebuffers(1, &fbo);
281 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
282 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
283
284 glBindTexture(GL_TEXTURE_2D, textures[1]);
Geoff Langc4e93662017-05-01 10:45:59 -0400285 if (getClientMajorVersion() >= 3)
286 {
287 glTexStorage2D(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
288 }
289 else
290 {
291 glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
292 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500293 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
294 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
295
296 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
297 ASSERT_GL_NO_ERROR();
298
299 glBindFramebuffer(GL_FRAMEBUFFER, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200300 drawQuad(mProgram, "position", 0.5f);
Jamie Madillbc393df2015-01-29 13:46:07 -0500301
302 int testImageChannels = std::min(sourceImageChannels, destImageChannels);
303
Olli Etuahoa314b612016-03-10 16:43:00 +0200304 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Jamie Madillbc393df2015-01-29 13:46:07 -0500305 if (testImageChannels > 1)
306 {
307 EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255);
308 EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255);
309 if (testImageChannels > 2)
310 {
311 EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255);
312 }
313 }
314
315 glDeleteFramebuffers(1, &fbo);
316 glDeleteTextures(2, textures);
317
318 ASSERT_GL_NO_ERROR();
319 }
320
Jamie Madilld4cfa572014-07-08 10:00:32 -0400321 GLuint mTexture2D;
Jamie Madilld4cfa572014-07-08 10:00:32 -0400322 GLint mTexture2DUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400323};
324
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200325class Texture2DTestES3 : public Texture2DTest
326{
327 protected:
328 Texture2DTestES3() : Texture2DTest() {}
329
330 std::string getVertexShaderSource() override
331 {
332 return std::string(
333 "#version 300 es\n"
334 "out vec2 texcoord;\n"
335 "in vec4 position;\n"
336 "void main()\n"
337 "{\n"
338 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
339 " texcoord = (position.xy * 0.5) + 0.5;\n"
340 "}\n");
341 }
342
343 std::string getFragmentShaderSource() override
344 {
345 return std::string(
346 "#version 300 es\n"
347 "precision highp float;\n"
348 "uniform highp sampler2D tex;\n"
349 "in vec2 texcoord;\n"
350 "out vec4 fragColor;\n"
351 "void main()\n"
352 "{\n"
353 " fragColor = texture(tex, texcoord);\n"
354 "}\n");
355 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300356
357 void SetUp() override
358 {
359 Texture2DTest::SetUp();
360 setUpProgram();
361 }
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200362};
363
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200364class Texture2DIntegerAlpha1TestES3 : public Texture2DTest
365{
366 protected:
367 Texture2DIntegerAlpha1TestES3() : Texture2DTest() {}
368
369 std::string getVertexShaderSource() override
370 {
371 return std::string(
372 "#version 300 es\n"
373 "out vec2 texcoord;\n"
374 "in vec4 position;\n"
375 "void main()\n"
376 "{\n"
377 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
378 " texcoord = (position.xy * 0.5) + 0.5;\n"
379 "}\n");
380 }
381
382 std::string getFragmentShaderSource() override
383 {
384 return std::string(
385 "#version 300 es\n"
386 "precision highp float;\n"
387 "uniform highp isampler2D tex;\n"
388 "in vec2 texcoord;\n"
389 "out vec4 fragColor;\n"
390 "void main()\n"
391 "{\n"
392 " vec4 green = vec4(0, 1, 0, 1);\n"
393 " vec4 black = vec4(0, 0, 0, 0);\n"
394 " fragColor = (texture(tex, texcoord).a == 1) ? green : black;\n"
395 "}\n");
396 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300397
398 void SetUp() override
399 {
400 Texture2DTest::SetUp();
401 setUpProgram();
402 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200403};
404
405class Texture2DUnsignedIntegerAlpha1TestES3 : public Texture2DTest
406{
407 protected:
408 Texture2DUnsignedIntegerAlpha1TestES3() : Texture2DTest() {}
409
410 std::string getVertexShaderSource() override
411 {
412 return std::string(
413 "#version 300 es\n"
414 "out vec2 texcoord;\n"
415 "in vec4 position;\n"
416 "void main()\n"
417 "{\n"
418 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
419 " texcoord = (position.xy * 0.5) + 0.5;\n"
420 "}\n");
421 }
422
423 std::string getFragmentShaderSource() override
424 {
425 return std::string(
426 "#version 300 es\n"
427 "precision highp float;\n"
428 "uniform highp usampler2D tex;\n"
429 "in vec2 texcoord;\n"
430 "out vec4 fragColor;\n"
431 "void main()\n"
432 "{\n"
433 " vec4 green = vec4(0, 1, 0, 1);\n"
434 " vec4 black = vec4(0, 0, 0, 0);\n"
435 " fragColor = (texture(tex, texcoord).a == 1u) ? green : black;\n"
436 "}\n");
437 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300438
439 void SetUp() override
440 {
441 Texture2DTest::SetUp();
442 setUpProgram();
443 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200444};
445
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200446class Texture2DTestWithDrawScale : public Texture2DTest
Jamie Madill2453dbc2015-07-14 11:35:42 -0400447{
448 protected:
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200449 Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {}
450
451 std::string getVertexShaderSource() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400452 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300453 return
454 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200455 attribute vec4 position;
456 varying vec2 texcoord;
457
458 uniform vec2 drawScale;
459
460 void main()
461 {
462 gl_Position = vec4(position.xy * drawScale, 0.0, 1.0);
463 texcoord = (position.xy * 0.5) + 0.5;
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300464 })";
Jamie Madill2453dbc2015-07-14 11:35:42 -0400465 }
466
467 void SetUp() override
468 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200469 Texture2DTest::SetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300470
471 setUpProgram();
472
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200473 mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale");
474 ASSERT_NE(-1, mDrawScaleUniformLocation);
Jamie Madill2453dbc2015-07-14 11:35:42 -0400475
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200476 glUseProgram(mProgram);
477 glUniform2f(mDrawScaleUniformLocation, 1.0f, 1.0f);
478 glUseProgram(0);
479 ASSERT_GL_NO_ERROR();
480 }
481
482 GLint mDrawScaleUniformLocation;
483};
484
Olli Etuaho4644a202016-01-12 15:12:53 +0200485class Sampler2DAsFunctionParameterTest : public Texture2DTest
486{
487 protected:
488 Sampler2DAsFunctionParameterTest() : Texture2DTest() {}
489
490 std::string getFragmentShaderSource() override
491 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300492 return
493 R"(precision highp float;
Olli Etuaho4644a202016-01-12 15:12:53 +0200494 uniform sampler2D tex;
495 varying vec2 texcoord;
496
497 vec4 computeFragColor(sampler2D aTex)
498 {
499 return texture2D(aTex, texcoord);
500 }
501
502 void main()
503 {
504 gl_FragColor = computeFragColor(tex);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300505 })";
Olli Etuaho4644a202016-01-12 15:12:53 +0200506 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300507
508 void SetUp() override
509 {
510 Texture2DTest::SetUp();
511 setUpProgram();
512 }
Olli Etuaho4644a202016-01-12 15:12:53 +0200513};
514
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200515class TextureCubeTest : public TexCoordDrawTest
516{
517 protected:
518 TextureCubeTest()
519 : TexCoordDrawTest(),
520 mTexture2D(0),
521 mTextureCube(0),
522 mTexture2DUniformLocation(-1),
523 mTextureCubeUniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500524 {}
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200525
526 std::string getFragmentShaderSource() override
527 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300528 return
529 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200530 uniform sampler2D tex2D;
531 uniform samplerCube texCube;
532 varying vec2 texcoord;
533
534 void main()
535 {
536 gl_FragColor = texture2D(tex2D, texcoord);
537 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300538 })";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200539 }
540
541 void SetUp() override
542 {
543 TexCoordDrawTest::SetUp();
544
545 glGenTextures(1, &mTextureCube);
546 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Geoff Langc4e93662017-05-01 10:45:59 -0400547 for (GLenum face = 0; face < 6; face++)
548 {
549 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
550 GL_UNSIGNED_BYTE, nullptr);
551 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200552 EXPECT_GL_NO_ERROR();
553
554 mTexture2D = create2DTexture();
555
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300556 setUpProgram();
557
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200558 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
559 ASSERT_NE(-1, mTexture2DUniformLocation);
560 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
561 ASSERT_NE(-1, mTextureCubeUniformLocation);
562 }
563
564 void TearDown() override
565 {
566 glDeleteTextures(1, &mTextureCube);
567 TexCoordDrawTest::TearDown();
568 }
569
570 GLuint mTexture2D;
571 GLuint mTextureCube;
572 GLint mTexture2DUniformLocation;
573 GLint mTextureCubeUniformLocation;
574};
575
Martin Radev7e2c0d32017-09-15 14:25:42 +0300576class TextureCubeTestES3 : public ANGLETest
577{
578 protected:
579 TextureCubeTestES3() {}
580};
581
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200582class SamplerArrayTest : public TexCoordDrawTest
583{
584 protected:
585 SamplerArrayTest()
586 : TexCoordDrawTest(),
587 mTexture2DA(0),
588 mTexture2DB(0),
589 mTexture0UniformLocation(-1),
590 mTexture1UniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500591 {}
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200592
593 std::string getFragmentShaderSource() override
594 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300595 return
596 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200597 uniform highp sampler2D tex2DArray[2];
598 varying vec2 texcoord;
599 void main()
600 {
601 gl_FragColor = texture2D(tex2DArray[0], texcoord);
602 gl_FragColor += texture2D(tex2DArray[1], texcoord);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300603 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200604 }
605
606 void SetUp() override
607 {
608 TexCoordDrawTest::SetUp();
609
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300610 setUpProgram();
611
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200612 mTexture0UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[0]");
613 ASSERT_NE(-1, mTexture0UniformLocation);
614 mTexture1UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[1]");
615 ASSERT_NE(-1, mTexture1UniformLocation);
616
617 mTexture2DA = create2DTexture();
618 mTexture2DB = create2DTexture();
619 ASSERT_GL_NO_ERROR();
620 }
621
622 void TearDown() override
623 {
624 glDeleteTextures(1, &mTexture2DA);
625 glDeleteTextures(1, &mTexture2DB);
626 TexCoordDrawTest::TearDown();
627 }
628
629 void testSamplerArrayDraw()
630 {
631 GLubyte texData[4];
632 texData[0] = 0;
633 texData[1] = 60;
634 texData[2] = 0;
635 texData[3] = 255;
636
637 glActiveTexture(GL_TEXTURE0);
638 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
639 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
640
641 texData[1] = 120;
642 glActiveTexture(GL_TEXTURE1);
643 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
644 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
645 EXPECT_GL_ERROR(GL_NO_ERROR);
646
647 glUseProgram(mProgram);
648 glUniform1i(mTexture0UniformLocation, 0);
649 glUniform1i(mTexture1UniformLocation, 1);
650 drawQuad(mProgram, "position", 0.5f);
651 EXPECT_GL_NO_ERROR();
652
653 EXPECT_PIXEL_NEAR(0, 0, 0, 180, 0, 255, 2);
654 }
655
656 GLuint mTexture2DA;
657 GLuint mTexture2DB;
658 GLint mTexture0UniformLocation;
659 GLint mTexture1UniformLocation;
660};
661
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200662class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest
663{
664 protected:
665 SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {}
666
667 std::string getFragmentShaderSource() override
668 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300669 return
670 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200671 uniform highp sampler2D tex2DArray[2];
672 varying vec2 texcoord;
673
674 vec4 computeFragColor(highp sampler2D aTex2DArray[2])
675 {
676 return texture2D(aTex2DArray[0], texcoord) + texture2D(aTex2DArray[1], texcoord);
677 }
678
679 void main()
680 {
681 gl_FragColor = computeFragColor(tex2DArray);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300682 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200683 }
684};
685
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200686class Texture2DArrayTestES3 : public TexCoordDrawTest
687{
688 protected:
689 Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {}
690
691 std::string getVertexShaderSource() override
692 {
693 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400694 "#version 300 es\n"
695 "out vec2 texcoord;\n"
696 "in vec4 position;\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200697 "void main()\n"
698 "{\n"
699 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
700 " texcoord = (position.xy * 0.5) + 0.5;\n"
701 "}\n");
702 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400703
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200704 std::string getFragmentShaderSource() override
705 {
706 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400707 "#version 300 es\n"
708 "precision highp float;\n"
Olli Etuaho183d7e22015-11-20 15:59:09 +0200709 "uniform highp sampler2DArray tex2DArray;\n"
Jamie Madill2453dbc2015-07-14 11:35:42 -0400710 "in vec2 texcoord;\n"
711 "out vec4 fragColor;\n"
712 "void main()\n"
713 "{\n"
714 " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200715 "}\n");
716 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400717
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200718 void SetUp() override
719 {
720 TexCoordDrawTest::SetUp();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400721
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300722 setUpProgram();
723
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200724 mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray");
Jamie Madill2453dbc2015-07-14 11:35:42 -0400725 ASSERT_NE(-1, mTextureArrayLocation);
726
727 glGenTextures(1, &m2DArrayTexture);
728 ASSERT_GL_NO_ERROR();
729 }
730
731 void TearDown() override
732 {
733 glDeleteTextures(1, &m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200734 TexCoordDrawTest::TearDown();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400735 }
736
737 GLuint m2DArrayTexture;
Jamie Madill2453dbc2015-07-14 11:35:42 -0400738 GLint mTextureArrayLocation;
739};
740
Olli Etuahobce743a2016-01-15 17:18:28 +0200741class TextureSizeTextureArrayTest : public TexCoordDrawTest
742{
743 protected:
744 TextureSizeTextureArrayTest()
745 : TexCoordDrawTest(),
746 mTexture2DA(0),
747 mTexture2DB(0),
748 mTexture0Location(-1),
749 mTexture1Location(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500750 {}
Olli Etuahobce743a2016-01-15 17:18:28 +0200751
752 std::string getVertexShaderSource() override
753 {
Olli Etuaho5804dc82018-04-13 14:11:46 +0300754 return std::string(essl3_shaders::vs::Simple());
Olli Etuahobce743a2016-01-15 17:18:28 +0200755 }
756
757 std::string getFragmentShaderSource() override
758 {
759 return std::string(
760 "#version 300 es\n"
761 "precision highp float;\n"
762 "uniform highp sampler2D tex2DArray[2];\n"
763 "out vec4 fragColor;\n"
764 "void main()\n"
765 "{\n"
766 " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n"
767 " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n"
768 " fragColor = vec4(red, green, 0.0, 1.0);\n"
769 "}\n");
770 }
771
772 void SetUp() override
773 {
774 TexCoordDrawTest::SetUp();
775
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300776 setUpProgram();
777
Olli Etuahobce743a2016-01-15 17:18:28 +0200778 mTexture0Location = glGetUniformLocation(mProgram, "tex2DArray[0]");
779 ASSERT_NE(-1, mTexture0Location);
780 mTexture1Location = glGetUniformLocation(mProgram, "tex2DArray[1]");
781 ASSERT_NE(-1, mTexture1Location);
782
783 mTexture2DA = create2DTexture();
784 mTexture2DB = create2DTexture();
785 ASSERT_GL_NO_ERROR();
786 }
787
788 void TearDown() override
789 {
790 glDeleteTextures(1, &mTexture2DA);
791 glDeleteTextures(1, &mTexture2DB);
792 TexCoordDrawTest::TearDown();
793 }
794
795 GLuint mTexture2DA;
796 GLuint mTexture2DB;
797 GLint mTexture0Location;
798 GLint mTexture1Location;
799};
800
Olli Etuahoa314b612016-03-10 16:43:00 +0200801class Texture3DTestES3 : public TexCoordDrawTest
802{
803 protected:
804 Texture3DTestES3() : TexCoordDrawTest(), mTexture3D(0), mTexture3DUniformLocation(-1) {}
805
806 std::string getVertexShaderSource() override
807 {
808 return std::string(
809 "#version 300 es\n"
810 "out vec2 texcoord;\n"
811 "in vec4 position;\n"
812 "void main()\n"
813 "{\n"
814 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
815 " texcoord = (position.xy * 0.5) + 0.5;\n"
816 "}\n");
817 }
818
819 std::string getFragmentShaderSource() override
820 {
821 return std::string(
822 "#version 300 es\n"
823 "precision highp float;\n"
824 "uniform highp sampler3D tex3D;\n"
825 "in vec2 texcoord;\n"
826 "out vec4 fragColor;\n"
827 "void main()\n"
828 "{\n"
829 " fragColor = texture(tex3D, vec3(texcoord, 0.0));\n"
830 "}\n");
831 }
832
833 void SetUp() override
834 {
835 TexCoordDrawTest::SetUp();
836
837 glGenTextures(1, &mTexture3D);
838
839 setUpProgram();
840
841 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
842 ASSERT_NE(-1, mTexture3DUniformLocation);
843 }
844
845 void TearDown() override
846 {
847 glDeleteTextures(1, &mTexture3D);
848 TexCoordDrawTest::TearDown();
849 }
850
851 GLuint mTexture3D;
852 GLint mTexture3DUniformLocation;
853};
854
Olli Etuaho1a679902016-01-14 12:21:47 +0200855class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest
856{
857 protected:
858 ShadowSamplerPlusSampler3DTestES3()
859 : TexCoordDrawTest(),
860 mTextureShadow(0),
861 mTexture3D(0),
862 mTextureShadowUniformLocation(-1),
863 mTexture3DUniformLocation(-1),
864 mDepthRefUniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500865 {}
Olli Etuaho1a679902016-01-14 12:21:47 +0200866
867 std::string getVertexShaderSource() override
868 {
869 return std::string(
870 "#version 300 es\n"
871 "out vec2 texcoord;\n"
872 "in vec4 position;\n"
873 "void main()\n"
874 "{\n"
875 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
876 " texcoord = (position.xy * 0.5) + 0.5;\n"
877 "}\n");
878 }
879
880 std::string getFragmentShaderSource() override
881 {
882 return std::string(
883 "#version 300 es\n"
884 "precision highp float;\n"
885 "uniform highp sampler2DShadow tex2DShadow;\n"
886 "uniform highp sampler3D tex3D;\n"
887 "in vec2 texcoord;\n"
888 "uniform float depthRef;\n"
889 "out vec4 fragColor;\n"
890 "void main()\n"
891 "{\n"
892 " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n"
893 " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n"
894 "}\n");
895 }
896
897 void SetUp() override
898 {
899 TexCoordDrawTest::SetUp();
900
901 glGenTextures(1, &mTexture3D);
902
903 glGenTextures(1, &mTextureShadow);
904 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
905 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
906
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300907 setUpProgram();
908
Olli Etuaho1a679902016-01-14 12:21:47 +0200909 mTextureShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
910 ASSERT_NE(-1, mTextureShadowUniformLocation);
911 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
912 ASSERT_NE(-1, mTexture3DUniformLocation);
913 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
914 ASSERT_NE(-1, mDepthRefUniformLocation);
915 }
916
917 void TearDown() override
918 {
919 glDeleteTextures(1, &mTextureShadow);
920 glDeleteTextures(1, &mTexture3D);
921 TexCoordDrawTest::TearDown();
922 }
923
924 GLuint mTextureShadow;
925 GLuint mTexture3D;
926 GLint mTextureShadowUniformLocation;
927 GLint mTexture3DUniformLocation;
928 GLint mDepthRefUniformLocation;
929};
930
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200931class SamplerTypeMixTestES3 : public TexCoordDrawTest
932{
933 protected:
934 SamplerTypeMixTestES3()
935 : TexCoordDrawTest(),
936 mTexture2D(0),
937 mTextureCube(0),
938 mTexture2DShadow(0),
939 mTextureCubeShadow(0),
940 mTexture2DUniformLocation(-1),
941 mTextureCubeUniformLocation(-1),
942 mTexture2DShadowUniformLocation(-1),
943 mTextureCubeShadowUniformLocation(-1),
944 mDepthRefUniformLocation(-1)
Jamie Madillb980c562018-11-27 11:34:27 -0500945 {}
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200946
947 std::string getVertexShaderSource() override
948 {
949 return std::string(
950 "#version 300 es\n"
951 "out vec2 texcoord;\n"
952 "in vec4 position;\n"
953 "void main()\n"
954 "{\n"
955 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
956 " texcoord = (position.xy * 0.5) + 0.5;\n"
957 "}\n");
958 }
959
960 std::string getFragmentShaderSource() override
961 {
962 return std::string(
963 "#version 300 es\n"
964 "precision highp float;\n"
965 "uniform highp sampler2D tex2D;\n"
966 "uniform highp samplerCube texCube;\n"
967 "uniform highp sampler2DShadow tex2DShadow;\n"
968 "uniform highp samplerCubeShadow texCubeShadow;\n"
969 "in vec2 texcoord;\n"
970 "uniform float depthRef;\n"
971 "out vec4 fragColor;\n"
972 "void main()\n"
973 "{\n"
974 " fragColor = texture(tex2D, texcoord);\n"
975 " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n"
976 " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n"
977 " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * "
978 "0.125);\n"
979 "}\n");
980 }
981
982 void SetUp() override
983 {
984 TexCoordDrawTest::SetUp();
985
986 glGenTextures(1, &mTexture2D);
987 glGenTextures(1, &mTextureCube);
988
989 glGenTextures(1, &mTexture2DShadow);
990 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
991 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
992
993 glGenTextures(1, &mTextureCubeShadow);
994 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
995 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
996
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300997 setUpProgram();
998
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200999 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
1000 ASSERT_NE(-1, mTexture2DUniformLocation);
1001 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
1002 ASSERT_NE(-1, mTextureCubeUniformLocation);
1003 mTexture2DShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
1004 ASSERT_NE(-1, mTexture2DShadowUniformLocation);
1005 mTextureCubeShadowUniformLocation = glGetUniformLocation(mProgram, "texCubeShadow");
1006 ASSERT_NE(-1, mTextureCubeShadowUniformLocation);
1007 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
1008 ASSERT_NE(-1, mDepthRefUniformLocation);
1009
1010 ASSERT_GL_NO_ERROR();
1011 }
1012
1013 void TearDown() override
1014 {
1015 glDeleteTextures(1, &mTexture2D);
1016 glDeleteTextures(1, &mTextureCube);
1017 glDeleteTextures(1, &mTexture2DShadow);
1018 glDeleteTextures(1, &mTextureCubeShadow);
1019 TexCoordDrawTest::TearDown();
1020 }
1021
1022 GLuint mTexture2D;
1023 GLuint mTextureCube;
1024 GLuint mTexture2DShadow;
1025 GLuint mTextureCubeShadow;
1026 GLint mTexture2DUniformLocation;
1027 GLint mTextureCubeUniformLocation;
1028 GLint mTexture2DShadowUniformLocation;
1029 GLint mTextureCubeShadowUniformLocation;
1030 GLint mDepthRefUniformLocation;
1031};
1032
Olli Etuaho96963162016-03-21 11:54:33 +02001033class SamplerInStructTest : public Texture2DTest
1034{
1035 protected:
1036 SamplerInStructTest() : Texture2DTest() {}
1037
1038 const char *getTextureUniformName() override { return "us.tex"; }
1039
1040 std::string getFragmentShaderSource() override
1041 {
1042 return std::string(
1043 "precision highp float;\n"
1044 "struct S\n"
1045 "{\n"
1046 " vec4 a;\n"
1047 " highp sampler2D tex;\n"
1048 "};\n"
1049 "uniform S us;\n"
1050 "varying vec2 texcoord;\n"
1051 "void main()\n"
1052 "{\n"
1053 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x);\n"
1054 "}\n");
1055 }
1056
1057 void runSamplerInStructTest()
1058 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001059 setUpProgram();
1060
Olli Etuaho96963162016-03-21 11:54:33 +02001061 glActiveTexture(GL_TEXTURE0);
1062 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001063 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1064 &GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001065 drawQuad(mProgram, "position", 0.5f);
Olli Etuahoa314b612016-03-10 16:43:00 +02001066 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001067 }
1068};
1069
1070class SamplerInStructAsFunctionParameterTest : public SamplerInStructTest
1071{
1072 protected:
1073 SamplerInStructAsFunctionParameterTest() : SamplerInStructTest() {}
1074
1075 std::string getFragmentShaderSource() override
1076 {
1077 return std::string(
1078 "precision highp float;\n"
1079 "struct S\n"
1080 "{\n"
1081 " vec4 a;\n"
1082 " highp sampler2D tex;\n"
1083 "};\n"
1084 "uniform S us;\n"
1085 "varying vec2 texcoord;\n"
1086 "vec4 sampleFrom(S s) {\n"
1087 " return texture2D(s.tex, texcoord + s.a.x);\n"
1088 "}\n"
1089 "void main()\n"
1090 "{\n"
1091 " gl_FragColor = sampleFrom(us);\n"
1092 "}\n");
1093 }
1094};
1095
1096class SamplerInStructArrayAsFunctionParameterTest : public SamplerInStructTest
1097{
1098 protected:
1099 SamplerInStructArrayAsFunctionParameterTest() : SamplerInStructTest() {}
1100
1101 const char *getTextureUniformName() override { return "us[0].tex"; }
1102
1103 std::string getFragmentShaderSource() override
1104 {
1105 return std::string(
1106 "precision highp float;\n"
1107 "struct S\n"
1108 "{\n"
1109 " vec4 a;\n"
1110 " highp sampler2D tex;\n"
1111 "};\n"
1112 "uniform S us[1];\n"
1113 "varying vec2 texcoord;\n"
1114 "vec4 sampleFrom(S s) {\n"
1115 " return texture2D(s.tex, texcoord + s.a.x);\n"
1116 "}\n"
1117 "void main()\n"
1118 "{\n"
1119 " gl_FragColor = sampleFrom(us[0]);\n"
1120 "}\n");
1121 }
1122};
1123
1124class SamplerInNestedStructAsFunctionParameterTest : public SamplerInStructTest
1125{
1126 protected:
1127 SamplerInNestedStructAsFunctionParameterTest() : SamplerInStructTest() {}
1128
1129 const char *getTextureUniformName() override { return "us[0].sub.tex"; }
1130
1131 std::string getFragmentShaderSource() override
1132 {
1133 return std::string(
1134 "precision highp float;\n"
1135 "struct SUB\n"
1136 "{\n"
1137 " vec4 a;\n"
1138 " highp sampler2D tex;\n"
1139 "};\n"
1140 "struct S\n"
1141 "{\n"
1142 " SUB sub;\n"
1143 "};\n"
1144 "uniform S us[1];\n"
1145 "varying vec2 texcoord;\n"
1146 "vec4 sampleFrom(SUB s) {\n"
1147 " return texture2D(s.tex, texcoord + s.a.x);\n"
1148 "}\n"
1149 "void main()\n"
1150 "{\n"
1151 " gl_FragColor = sampleFrom(us[0].sub);\n"
1152 "}\n");
1153 }
1154};
1155
1156class SamplerInStructAndOtherVariableTest : public SamplerInStructTest
1157{
1158 protected:
1159 SamplerInStructAndOtherVariableTest() : SamplerInStructTest() {}
1160
1161 std::string getFragmentShaderSource() override
1162 {
1163 return std::string(
1164 "precision highp float;\n"
1165 "struct S\n"
1166 "{\n"
1167 " vec4 a;\n"
1168 " highp sampler2D tex;\n"
1169 "};\n"
1170 "uniform S us;\n"
1171 "uniform float us_tex;\n"
1172 "varying vec2 texcoord;\n"
1173 "void main()\n"
1174 "{\n"
1175 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x + us_tex);\n"
1176 "}\n");
1177 }
1178};
1179
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001180TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001181{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001182 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001183 EXPECT_GL_ERROR(GL_NO_ERROR);
1184
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001185 setUpProgram();
1186
Jamie Madill50cf2be2018-06-15 09:46:57 -04001187 const GLubyte *pixels[20] = {0};
Jamie Madillf67115c2014-04-22 13:14:05 -04001188 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1189 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001190
1191 if (extensionEnabled("GL_EXT_texture_storage"))
1192 {
1193 // Create a 1-level immutable texture.
1194 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1195
1196 // Try calling sub image on the second level.
1197 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1198 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1199 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001200}
Geoff Langc41e42d2014-04-28 10:58:16 -04001201
John Bauman18319182016-09-28 14:22:27 -07001202// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1203TEST_P(Texture2DTest, QueryBinding)
1204{
1205 glBindTexture(GL_TEXTURE_2D, 0);
1206 EXPECT_GL_ERROR(GL_NO_ERROR);
1207
1208 GLint textureBinding;
1209 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1210 EXPECT_GL_NO_ERROR();
1211 EXPECT_EQ(0, textureBinding);
1212
1213 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
1214 if (extensionEnabled("GL_OES_EGL_image_external") ||
1215 extensionEnabled("GL_NV_EGL_stream_consumer_external"))
1216 {
1217 EXPECT_GL_NO_ERROR();
1218 EXPECT_EQ(0, textureBinding);
1219 }
1220 else
1221 {
1222 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1223 }
1224}
1225
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001226TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001227{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001228 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001229 EXPECT_GL_ERROR(GL_NO_ERROR);
1230
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001231 setUpProgram();
1232
Geoff Langc41e42d2014-04-28 10:58:16 -04001233 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001234 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001235 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001236 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001237
Jamie Madill50cf2be2018-06-15 09:46:57 -04001238 const GLubyte *pixel[4] = {0};
Geoff Langc41e42d2014-04-28 10:58:16 -04001239
1240 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1241 EXPECT_GL_NO_ERROR();
1242
1243 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1244 EXPECT_GL_NO_ERROR();
1245
1246 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1247 EXPECT_GL_NO_ERROR();
1248}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001249
1250// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001251TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001252{
1253 glActiveTexture(GL_TEXTURE0);
1254 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1255 glActiveTexture(GL_TEXTURE1);
1256 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1257 EXPECT_GL_ERROR(GL_NO_ERROR);
1258
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001259 glUseProgram(mProgram);
1260 glUniform1i(mTexture2DUniformLocation, 0);
1261 glUniform1i(mTextureCubeUniformLocation, 1);
1262 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001263 EXPECT_GL_NO_ERROR();
1264}
Jamie Madill9aca0592014-10-06 16:26:59 -04001265
Olli Etuaho53a2da12016-01-11 15:43:32 +02001266// Test drawing with two texture types accessed from the same shader and check that the result of
1267// drawing is correct.
1268TEST_P(TextureCubeTest, CubeMapDraw)
1269{
1270 GLubyte texData[4];
1271 texData[0] = 0;
1272 texData[1] = 60;
1273 texData[2] = 0;
1274 texData[3] = 255;
1275
1276 glActiveTexture(GL_TEXTURE0);
1277 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1278 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1279
1280 glActiveTexture(GL_TEXTURE1);
1281 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1282 texData[1] = 120;
1283 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1284 texData);
1285 EXPECT_GL_ERROR(GL_NO_ERROR);
1286
1287 glUseProgram(mProgram);
1288 glUniform1i(mTexture2DUniformLocation, 0);
1289 glUniform1i(mTextureCubeUniformLocation, 1);
1290 drawQuad(mProgram, "position", 0.5f);
1291 EXPECT_GL_NO_ERROR();
1292
1293 int px = getWindowWidth() - 1;
1294 int py = 0;
1295 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1296}
1297
Olli Etuaho4644a202016-01-12 15:12:53 +02001298TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1299{
1300 glActiveTexture(GL_TEXTURE0);
1301 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1302 GLubyte texData[4];
1303 texData[0] = 0;
1304 texData[1] = 128;
1305 texData[2] = 0;
1306 texData[3] = 255;
1307 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1308 glUseProgram(mProgram);
1309 glUniform1i(mTexture2DUniformLocation, 0);
1310 drawQuad(mProgram, "position", 0.5f);
1311 EXPECT_GL_NO_ERROR();
1312
1313 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1314}
1315
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001316// Test drawing with two textures passed to the shader in a sampler array.
1317TEST_P(SamplerArrayTest, SamplerArrayDraw)
1318{
1319 testSamplerArrayDraw();
1320}
1321
1322// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1323// user-defined function in the shader.
1324TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1325{
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05001326 // TODO: Diagnose and fix. http://anglebug.com/2955
1327 ANGLE_SKIP_TEST_IF(IsVulkan() && IsAndroid());
1328
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001329 testSamplerArrayDraw();
1330}
1331
Jamie Madill9aca0592014-10-06 16:26:59 -04001332// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001333TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001334{
1335 int px = getWindowWidth() / 2;
1336 int py = getWindowHeight() / 2;
1337
1338 glActiveTexture(GL_TEXTURE0);
1339 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1340
Olli Etuahoa314b612016-03-10 16:43:00 +02001341 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001342
Olli Etuahoa314b612016-03-10 16:43:00 +02001343 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001344 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1345 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1346 glGenerateMipmap(GL_TEXTURE_2D);
1347
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001348 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001349 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001350 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1351 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001352 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001353 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001354
Olli Etuahoa314b612016-03-10 16:43:00 +02001355 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001356
Olli Etuahoa314b612016-03-10 16:43:00 +02001357 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1358 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001359 glGenerateMipmap(GL_TEXTURE_2D);
1360
Olli Etuahoa314b612016-03-10 16:43:00 +02001361 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001362
Olli Etuahoa314b612016-03-10 16:43:00 +02001363 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1364 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001365 glGenerateMipmap(GL_TEXTURE_2D);
1366
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001367 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001368
1369 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001370 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001371}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001372
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001373// Test creating a FBO with a cube map render target, to test an ANGLE bug
1374// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001375TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001376{
Jamie Madill3f3b3582018-09-14 10:38:44 -04001377 GLFramebuffer fbo;
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001378 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1379
1380 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Jamie Madill50cf2be2018-06-15 09:46:57 -04001381 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1382 mTextureCube, 0);
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001383
Corentin Wallez322653b2015-06-17 18:33:56 +02001384 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001385 EXPECT_GL_NO_ERROR();
Jamie Madill3f3b3582018-09-14 10:38:44 -04001386
1387 // Test clearing the six mip faces individually.
1388 std::array<GLColor, 6> faceColors = {{GLColor::red, GLColor::green, GLColor::blue,
1389 GLColor::yellow, GLColor::cyan, GLColor::magenta}};
1390
1391 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1392 {
1393 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1394 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1395
1396 Vector4 clearColorF = faceColors[faceIndex].toNormalizedVector();
1397 glClearColor(clearColorF.x(), clearColorF.y(), clearColorF.z(), clearColorF.w());
1398 glClear(GL_COLOR_BUFFER_BIT);
1399
1400 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex]);
1401 }
1402
1403 // Iterate the faces again to make sure the colors haven't changed.
1404 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1405 {
1406 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1407 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1408 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex])
1409 << "face color " << faceIndex << " shouldn't change";
1410 }
1411}
1412
1413// Tests clearing a cube map with a scissor enabled.
1414TEST_P(TextureCubeTest, CubeMapFBOScissoredClear)
1415{
1416 // TODO(jie.a.chen): Diagnose and fix. http://anglebug.com/2822
1417 ANGLE_SKIP_TEST_IF(IsVulkan() && IsIntel() && IsWindows());
1418
1419 constexpr size_t kSize = 16;
1420
1421 GLFramebuffer fbo;
1422 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1423 glViewport(0, 0, kSize, kSize);
1424
1425 GLTexture texcube;
1426 glBindTexture(GL_TEXTURE_CUBE_MAP, texcube);
1427 for (GLenum face = 0; face < 6; face++)
1428 {
1429 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA,
1430 GL_UNSIGNED_BYTE, nullptr);
1431 }
1432 ASSERT_GL_NO_ERROR();
1433
1434 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1435 texcube, 0);
1436
1437 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1438 ASSERT_GL_NO_ERROR();
1439
1440 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1441 glClear(GL_COLOR_BUFFER_BIT);
1442 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1443
1444 glEnable(GL_SCISSOR_TEST);
1445 glScissor(kSize / 2, 0, kSize / 2, kSize);
1446 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
1447 glClear(GL_COLOR_BUFFER_BIT);
1448
1449 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1450 EXPECT_PIXEL_COLOR_EQ(kSize / 2 + 1, 0, GLColor::green);
1451
1452 ASSERT_GL_NO_ERROR();
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001453}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001454
Jamie Madill50cf2be2018-06-15 09:46:57 -04001455// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a
1456// default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001457TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001458{
Luc Ferron7348fc52018-05-09 07:17:16 -04001459 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -04001460
Jamie Madill50cf2be2018-06-15 09:46:57 -04001461 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001462 int height = getWindowHeight();
1463
1464 GLuint tex2D;
1465 glGenTextures(1, &tex2D);
1466 glActiveTexture(GL_TEXTURE0);
1467 glBindTexture(GL_TEXTURE_2D, tex2D);
1468
1469 // Fill with red
1470 std::vector<GLubyte> pixels(3 * 16 * 16);
1471 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1472 {
1473 pixels[pixelId * 3 + 0] = 255;
1474 pixels[pixelId * 3 + 1] = 0;
1475 pixels[pixelId * 3 + 2] = 0;
1476 }
1477
1478 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001479 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1480 // 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 -04001481 if (getClientMajorVersion() >= 3)
1482 {
1483 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1484 }
1485 else
1486 {
1487 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1488 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001489
1490 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1491 // glTexSubImage2D should take into account that the image is dirty.
1492 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1493 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1494 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1495
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001496 setUpProgram();
1497
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001498 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001499 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001500 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001501 glDeleteTextures(1, &tex2D);
1502 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001503 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001504
1505 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001506 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1507 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001508}
1509
Jamie Madill50cf2be2018-06-15 09:46:57 -04001510// Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has
1511// initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001512TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001513{
1514 if (extensionEnabled("NV_pixel_buffer_object"))
1515 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04001516 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001517 int height = getWindowHeight();
1518
1519 GLuint tex2D;
1520 glGenTextures(1, &tex2D);
1521 glActiveTexture(GL_TEXTURE0);
1522 glBindTexture(GL_TEXTURE_2D, tex2D);
1523
1524 // Fill with red
1525 std::vector<GLubyte> pixels(3 * 16 * 16);
1526 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1527 {
1528 pixels[pixelId * 3 + 0] = 255;
1529 pixels[pixelId * 3 + 1] = 0;
1530 pixels[pixelId * 3 + 2] = 0;
1531 }
1532
1533 // Read 16x16 region from red backbuffer to PBO
1534 GLuint pbo;
1535 glGenBuffers(1, &pbo);
1536 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1537 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1538
1539 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001540 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1541 // 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 +00001542 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1543
1544 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1545 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001546 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 +00001547 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1548 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1549
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001550 setUpProgram();
1551
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001552 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001553 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001554 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001555 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001556 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001557 EXPECT_GL_NO_ERROR();
1558 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1559 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1560 }
1561}
Jamie Madillbc393df2015-01-29 13:46:07 -05001562
1563// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001564TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001565{
1566 testFloatCopySubImage(1, 1);
1567}
1568
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001569TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001570{
1571 testFloatCopySubImage(2, 1);
1572}
1573
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001574TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001575{
1576 testFloatCopySubImage(2, 2);
1577}
1578
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001579TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001580{
1581 testFloatCopySubImage(3, 1);
1582}
1583
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001584TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001585{
1586 testFloatCopySubImage(3, 2);
1587}
1588
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001589TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001590{
Yunchao He9550c602018-02-13 14:47:05 +08001591 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1592 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001593
Yunchao He9550c602018-02-13 14:47:05 +08001594 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1595 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001596
Jamie Madillbc393df2015-01-29 13:46:07 -05001597 testFloatCopySubImage(3, 3);
1598}
1599
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001600TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001601{
1602 testFloatCopySubImage(4, 1);
1603}
1604
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001605TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001606{
1607 testFloatCopySubImage(4, 2);
1608}
1609
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001610TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001611{
Yunchao He9550c602018-02-13 14:47:05 +08001612 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1613 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001614
Jamie Madillbc393df2015-01-29 13:46:07 -05001615 testFloatCopySubImage(4, 3);
1616}
1617
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001618TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001619{
Luc Ferronf786b702018-07-10 11:01:43 -04001620 // TODO(lucferron): This test fails only on linux and intel.
1621 // http://anglebug.com/2726
1622 ANGLE_SKIP_TEST_IF(IsVulkan() && IsLinux() && IsIntel());
1623
Yunchao He9550c602018-02-13 14:47:05 +08001624 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1625 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001626
Jamie Madillbc393df2015-01-29 13:46:07 -05001627 testFloatCopySubImage(4, 4);
1628}
Austin Kinross07285142015-03-26 11:36:16 -07001629
Jamie Madill50cf2be2018-06-15 09:46:57 -04001630// Port of
1631// https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1632// Run against GL_ALPHA/UNSIGNED_BYTE format, to ensure that D3D11 Feature Level 9_3 correctly
1633// handles GL_ALPHA
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001634TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001635{
1636 const int npotTexSize = 5;
Jamie Madill50cf2be2018-06-15 09:46:57 -04001637 const int potTexSize = 4; // Should be less than npotTexSize
Austin Kinross07285142015-03-26 11:36:16 -07001638 GLuint tex2D;
1639
1640 if (extensionEnabled("GL_OES_texture_npot"))
1641 {
1642 // This test isn't applicable if texture_npot is enabled
1643 return;
1644 }
1645
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001646 setUpProgram();
1647
Austin Kinross07285142015-03-26 11:36:16 -07001648 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1649
Austin Kinross5faa15b2016-01-11 13:32:48 -08001650 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1651 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1652
Austin Kinross07285142015-03-26 11:36:16 -07001653 glActiveTexture(GL_TEXTURE0);
1654 glGenTextures(1, &tex2D);
1655 glBindTexture(GL_TEXTURE_2D, tex2D);
1656
Till Rathmannc1551dc2018-08-15 17:04:49 +02001657 const std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize, 64);
Austin Kinross07285142015-03-26 11:36:16 -07001658
1659 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1660 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1661
1662 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
Jamie Madill50cf2be2018-06-15 09:46:57 -04001663 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1664 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001665 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1666
1667 // Check that an NPOT texture on level 0 succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001668 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1669 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001670 EXPECT_GL_NO_ERROR();
1671
1672 // Check that generateMipmap fails on NPOT
1673 glGenerateMipmap(GL_TEXTURE_2D);
1674 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1675
1676 // Check that nothing is drawn if filtering is not correct for NPOT
1677 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1678 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1679 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1680 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1681 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001682 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001683 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1684
1685 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1686 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1687 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1688 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1689 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001690 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001691 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1692
1693 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1694 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1695 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001696 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001697 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1698
1699 // Check that glTexImage2D for POT texture succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001700 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE,
1701 pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001702 EXPECT_GL_NO_ERROR();
1703
1704 // Check that generateMipmap for an POT texture succeeds
1705 glGenerateMipmap(GL_TEXTURE_2D);
1706 EXPECT_GL_NO_ERROR();
1707
1708 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1709 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1710 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1711 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1712 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1713 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001714 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001715 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1716 EXPECT_GL_NO_ERROR();
1717}
Jamie Madillfa05f602015-05-07 13:47:11 -04001718
Austin Kinross08528e12015-10-07 16:24:40 -07001719// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1720// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001721TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001722{
1723 glActiveTexture(GL_TEXTURE0);
1724 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1725
1726 // Create an 8x8 (i.e. power-of-two) texture.
1727 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1728 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1729 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1730 glGenerateMipmap(GL_TEXTURE_2D);
1731
1732 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1733 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001734 std::array<GLColor, 3 * 3> data;
1735 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001736
1737 EXPECT_GL_NO_ERROR();
1738}
1739
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001740// Test to check that texture completeness is determined correctly when the texture base level is
1741// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1742TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1743{
1744 glActiveTexture(GL_TEXTURE0);
1745 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001746
1747 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1748 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1749 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1750 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1751 texDataGreen.data());
1752 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1753 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001754 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1755 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1756 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1757
1758 EXPECT_GL_NO_ERROR();
1759
1760 drawQuad(mProgram, "position", 0.5f);
1761
Olli Etuahoa314b612016-03-10 16:43:00 +02001762 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1763}
1764
1765// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1766// have images defined.
1767TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1768{
Yunchao He9550c602018-02-13 14:47:05 +08001769 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1770 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1771
Olli Etuahoa314b612016-03-10 16:43:00 +02001772 glActiveTexture(GL_TEXTURE0);
1773 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1774 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1775 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1776 texDataGreen.data());
1777 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1778 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1779 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1780 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1781
1782 EXPECT_GL_NO_ERROR();
1783
1784 drawQuad(mProgram, "position", 0.5f);
1785
1786 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1787}
1788
Olli Etuahoe8528d82016-05-16 17:50:52 +03001789// Test that drawing works correctly when level 0 is undefined and base level is 1.
1790TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1791{
Yunchao He9550c602018-02-13 14:47:05 +08001792 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1793 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1794
Olli Etuahoe8528d82016-05-16 17:50:52 +03001795 glActiveTexture(GL_TEXTURE0);
1796 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1797 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1798 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1799 texDataGreen.data());
1800 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1801 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1802 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1803 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1804
1805 EXPECT_GL_NO_ERROR();
1806
1807 // Texture is incomplete.
1808 drawQuad(mProgram, "position", 0.5f);
1809 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1810
1811 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1812 texDataGreen.data());
1813
1814 // Texture is now complete.
1815 drawQuad(mProgram, "position", 0.5f);
1816 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1817}
1818
Olli Etuahoa314b612016-03-10 16:43:00 +02001819// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1820// dimensions that don't fit the images inside the range.
1821// GLES 3.0.4 section 3.8.13 Texture completeness
1822TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1823{
Olli Etuahoa314b612016-03-10 16:43:00 +02001824 glActiveTexture(GL_TEXTURE0);
1825 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1826 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1827 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1828 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1829
1830 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1831 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1832
1833 // Two levels that are initially unused.
1834 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1835 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1836 texDataCyan.data());
1837
1838 // One level that is used - only this level should affect completeness.
1839 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1840 texDataGreen.data());
1841
1842 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1843 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1844
1845 EXPECT_GL_NO_ERROR();
1846
1847 drawQuad(mProgram, "position", 0.5f);
1848
1849 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1850
Yunchao He2f23f352018-02-11 22:11:37 +08001851 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001852
1853 // Switch the level that is being used to the cyan level 2.
1854 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1855 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1856
1857 EXPECT_GL_NO_ERROR();
1858
1859 drawQuad(mProgram, "position", 0.5f);
1860
1861 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1862}
1863
1864// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1865// have images defined.
1866TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1867{
Olli Etuahoa314b612016-03-10 16:43:00 +02001868 glActiveTexture(GL_TEXTURE0);
1869 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1870 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1871 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1872 texDataGreen.data());
1873 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1874 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1875 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1876 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1877
1878 EXPECT_GL_NO_ERROR();
1879
1880 drawQuad(mProgram, "position", 0.5f);
1881
1882 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1883}
1884
1885// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1886// dimensions that don't fit the images inside the range.
1887// GLES 3.0.4 section 3.8.13 Texture completeness
1888TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1889{
Olli Etuahoa314b612016-03-10 16:43:00 +02001890 glActiveTexture(GL_TEXTURE0);
1891 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1892 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1893 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1894 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1895
1896 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1897 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1898
1899 // Two levels that are initially unused.
1900 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1901 texDataRed.data());
1902 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1903 texDataCyan.data());
1904
1905 // One level that is used - only this level should affect completeness.
1906 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1907 texDataGreen.data());
1908
1909 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1910 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1911
1912 EXPECT_GL_NO_ERROR();
1913
1914 drawQuad(mProgram, "position", 0.5f);
1915
1916 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1917
Yunchao He2f23f352018-02-11 22:11:37 +08001918 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001919
1920 // Switch the level that is being used to the cyan level 2.
1921 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
1922 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
1923
1924 EXPECT_GL_NO_ERROR();
1925
1926 drawQuad(mProgram, "position", 0.5f);
1927
1928 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1929}
1930
1931// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1932// have images defined.
1933TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
1934{
Olli Etuahoa314b612016-03-10 16:43:00 +02001935 glActiveTexture(GL_TEXTURE0);
1936 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
1937 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1938 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1939 texDataGreen.data());
1940 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1941 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1942 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1943 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1944
1945 EXPECT_GL_NO_ERROR();
1946
1947 drawQuad(mProgram, "position", 0.5f);
1948
1949 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1950}
1951
1952// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1953// dimensions that don't fit the images inside the range.
1954// GLES 3.0.4 section 3.8.13 Texture completeness
1955TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1956{
Olli Etuahoa314b612016-03-10 16:43:00 +02001957 glActiveTexture(GL_TEXTURE0);
1958 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
1959 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1960 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1961 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1962
1963 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1964 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1965
1966 // Two levels that are initially unused.
1967 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1968 texDataRed.data());
1969 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1970 texDataCyan.data());
1971
1972 // One level that is used - only this level should affect completeness.
1973 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1974 texDataGreen.data());
1975
1976 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1977 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1978
1979 EXPECT_GL_NO_ERROR();
1980
1981 drawQuad(mProgram, "position", 0.5f);
1982
1983 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1984
Yunchao He2f23f352018-02-11 22:11:37 +08001985 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
1986
Yunchao He9550c602018-02-13 14:47:05 +08001987 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
1988 // level was changed.
1989 ANGLE_SKIP_TEST_IF(IsNVIDIA() && (IsOpenGL() || IsOpenGLES()));
Olli Etuahoa314b612016-03-10 16:43:00 +02001990
1991 // Switch the level that is being used to the cyan level 2.
1992 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
1993 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
1994
1995 EXPECT_GL_NO_ERROR();
1996
1997 drawQuad(mProgram, "position", 0.5f);
1998
1999 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2000}
2001
2002// Test that texture completeness is updated if texture max level changes.
2003// GLES 3.0.4 section 3.8.13 Texture completeness
2004TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2005{
Olli Etuahoa314b612016-03-10 16:43:00 +02002006 glActiveTexture(GL_TEXTURE0);
2007 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2008 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2009
2010 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2011 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2012
2013 // A level that is initially unused.
2014 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2015 texDataGreen.data());
2016
2017 // One level that is initially used - only this level should affect completeness.
2018 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2019 texDataGreen.data());
2020
2021 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2022 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2023
2024 EXPECT_GL_NO_ERROR();
2025
2026 drawQuad(mProgram, "position", 0.5f);
2027
2028 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2029
2030 // Switch the max level to level 1. The levels within the used range now have inconsistent
2031 // dimensions and the texture should be incomplete.
2032 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2033
2034 EXPECT_GL_NO_ERROR();
2035
2036 drawQuad(mProgram, "position", 0.5f);
2037
2038 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2039}
2040
2041// Test that 3D texture completeness is updated if texture max level changes.
2042// GLES 3.0.4 section 3.8.13 Texture completeness
2043TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2044{
Olli Etuahoa314b612016-03-10 16:43:00 +02002045 glActiveTexture(GL_TEXTURE0);
2046 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2047 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2048
2049 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2050 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2051
2052 // A level that is initially unused.
2053 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2054 texDataGreen.data());
2055
2056 // One level that is initially used - only this level should affect completeness.
2057 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2058 texDataGreen.data());
2059
2060 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2061 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2062
2063 EXPECT_GL_NO_ERROR();
2064
2065 drawQuad(mProgram, "position", 0.5f);
2066
2067 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2068
2069 // Switch the max level to level 1. The levels within the used range now have inconsistent
2070 // dimensions and the texture should be incomplete.
2071 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2072
2073 EXPECT_GL_NO_ERROR();
2074
2075 drawQuad(mProgram, "position", 0.5f);
2076
2077 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2078}
2079
2080// Test that texture completeness is updated if texture base level changes.
2081// GLES 3.0.4 section 3.8.13 Texture completeness
2082TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2083{
Olli Etuahoa314b612016-03-10 16:43:00 +02002084 glActiveTexture(GL_TEXTURE0);
2085 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2086 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2087
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
2091 // Two levels that are initially unused.
2092 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2093 texDataGreen.data());
2094 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2095 texDataGreen.data());
2096
2097 // One level that is initially used - only this level should affect completeness.
2098 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2099 texDataGreen.data());
2100
2101 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2102 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2103
2104 EXPECT_GL_NO_ERROR();
2105
2106 drawQuad(mProgram, "position", 0.5f);
2107
2108 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2109
2110 // Switch the base level to level 1. The levels within the used range now have inconsistent
2111 // dimensions and the texture should be incomplete.
2112 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2113
2114 EXPECT_GL_NO_ERROR();
2115
2116 drawQuad(mProgram, "position", 0.5f);
2117
2118 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2119}
2120
2121// Test that texture is not complete if base level is greater than max level.
2122// GLES 3.0.4 section 3.8.13 Texture completeness
2123TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2124{
Olli Etuahoa314b612016-03-10 16:43:00 +02002125 glActiveTexture(GL_TEXTURE0);
2126 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2127
2128 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2129 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2130
2131 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2132
2133 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2134 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2135
2136 EXPECT_GL_NO_ERROR();
2137
2138 drawQuad(mProgram, "position", 0.5f);
2139
2140 // Texture should be incomplete.
2141 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2142}
2143
2144// Test that immutable texture base level and max level are clamped.
2145// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2146TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2147{
Olli Etuahoa314b612016-03-10 16:43:00 +02002148 glActiveTexture(GL_TEXTURE0);
2149 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2150
2151 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2152 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2153
2154 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2155
2156 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2157
2158 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2159 // should be clamped to [base_level, levels - 1].
2160 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2161 // In the case of this test, those rules make the effective base level and max level 0.
2162 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2163 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2164
2165 EXPECT_GL_NO_ERROR();
2166
2167 drawQuad(mProgram, "position", 0.5f);
2168
2169 // Texture should be complete.
2170 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2171}
2172
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002173// Test that changing base level works when it affects the format of the texture.
2174TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2175{
Yunchao He9550c602018-02-13 14:47:05 +08002176 // Observed rendering corruption on NVIDIA OpenGL.
2177 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL());
2178
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002179 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002180
2181 // Observed incorrect rendering on AMD OpenGL.
2182 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002183
2184 glActiveTexture(GL_TEXTURE0);
2185 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2186 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2187 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2188
2189 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2190 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2191
2192 // RGBA8 level that's initially unused.
2193 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2194 texDataCyan.data());
2195
2196 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2197 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2198
2199 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2200 // format. It reads green channel data from the green and alpha channels of texDataGreen
2201 // (this is a bit hacky but works).
2202 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2203
2204 EXPECT_GL_NO_ERROR();
2205
2206 drawQuad(mProgram, "position", 0.5f);
2207
2208 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2209
2210 // Switch the texture to use the cyan level 0 with the RGBA format.
2211 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2212 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2213
2214 EXPECT_GL_NO_ERROR();
2215
2216 drawQuad(mProgram, "position", 0.5f);
2217
2218 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2219}
2220
Olli Etuahoa314b612016-03-10 16:43:00 +02002221// Test that setting a texture image works when base level is out of range.
2222TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2223{
2224 glActiveTexture(GL_TEXTURE0);
2225 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2226
2227 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2228 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2229
2230 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2231 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2232
2233 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2234
2235 EXPECT_GL_NO_ERROR();
2236
2237 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2238
2239 drawQuad(mProgram, "position", 0.5f);
2240
2241 // Texture should be complete.
2242 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002243}
2244
Jamie Madill50cf2be2018-06-15 09:46:57 -04002245// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG
2246// RBA->RGBA8, with 1.0 in the alpha channel. This test covers a bug where redefining array textures
2247// with these formats does not work as expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002248TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002249{
2250 std::vector<GLubyte> pixelData;
2251 for (size_t count = 0; count < 5000; count++)
2252 {
2253 pixelData.push_back(0u);
2254 pixelData.push_back(255u);
2255 pixelData.push_back(0u);
2256 }
2257
2258 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002259 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002260 glUniform1i(mTextureArrayLocation, 0);
2261
2262 // The first draw worked correctly.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002263 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2264 &pixelData[0]);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002265
2266 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2267 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2268 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2269 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002270 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002271 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002272
2273 // The dimension of the respecification must match the original exactly to trigger the bug.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002274 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2275 &pixelData[0]);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002276 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002277 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002278
2279 ASSERT_GL_NO_ERROR();
2280}
2281
Olli Etuaho1a679902016-01-14 12:21:47 +02002282// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2283// This test is needed especially to confirm that sampler registers get assigned correctly on
2284// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2285TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2286{
2287 glActiveTexture(GL_TEXTURE0);
2288 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2289 GLubyte texData[4];
2290 texData[0] = 0;
2291 texData[1] = 60;
2292 texData[2] = 0;
2293 texData[3] = 255;
2294 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2295
2296 glActiveTexture(GL_TEXTURE1);
2297 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2298 GLfloat depthTexData[1];
2299 depthTexData[0] = 0.5f;
2300 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2301 depthTexData);
2302
2303 glUseProgram(mProgram);
2304 glUniform1f(mDepthRefUniformLocation, 0.3f);
2305 glUniform1i(mTexture3DUniformLocation, 0);
2306 glUniform1i(mTextureShadowUniformLocation, 1);
2307
2308 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2309 drawQuad(mProgram, "position", 0.5f);
2310 EXPECT_GL_NO_ERROR();
2311 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2312 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2313
2314 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2315 drawQuad(mProgram, "position", 0.5f);
2316 EXPECT_GL_NO_ERROR();
2317 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2318 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2319}
2320
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002321// Test multiple different sampler types in the same shader.
2322// This test makes sure that even if sampler / texture registers get grouped together based on type
2323// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2324// still has the right register index information for each ESSL sampler.
2325// The tested ESSL samplers have the following types in D3D11 HLSL:
2326// sampler2D: Texture2D + SamplerState
2327// samplerCube: TextureCube + SamplerState
2328// sampler2DShadow: Texture2D + SamplerComparisonState
2329// samplerCubeShadow: TextureCube + SamplerComparisonState
2330TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2331{
2332 glActiveTexture(GL_TEXTURE0);
2333 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2334 GLubyte texData[4];
2335 texData[0] = 0;
2336 texData[1] = 0;
2337 texData[2] = 120;
2338 texData[3] = 255;
2339 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2340
2341 glActiveTexture(GL_TEXTURE1);
2342 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2343 texData[0] = 0;
2344 texData[1] = 90;
2345 texData[2] = 0;
2346 texData[3] = 255;
2347 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2348 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2349 texData);
2350
2351 glActiveTexture(GL_TEXTURE2);
2352 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2353 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2354 GLfloat depthTexData[1];
2355 depthTexData[0] = 0.5f;
2356 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2357 depthTexData);
2358
2359 glActiveTexture(GL_TEXTURE3);
2360 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2361 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2362 depthTexData[0] = 0.2f;
2363 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2364 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2365 depthTexData);
2366
2367 EXPECT_GL_NO_ERROR();
2368
2369 glUseProgram(mProgram);
2370 glUniform1f(mDepthRefUniformLocation, 0.3f);
2371 glUniform1i(mTexture2DUniformLocation, 0);
2372 glUniform1i(mTextureCubeUniformLocation, 1);
2373 glUniform1i(mTexture2DShadowUniformLocation, 2);
2374 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2375
2376 drawQuad(mProgram, "position", 0.5f);
2377 EXPECT_GL_NO_ERROR();
2378 // The shader writes:
2379 // <texture 2d color> +
2380 // <cube map color> +
2381 // 0.25 * <comparison result (1.0)> +
2382 // 0.125 * <comparison result (0.0)>
2383 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2384}
2385
Olli Etuahobce743a2016-01-15 17:18:28 +02002386// Test different base levels on textures accessed through the same sampler array.
2387// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2388TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2389{
Yunchao He9550c602018-02-13 14:47:05 +08002390 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2391
Olli Etuahobce743a2016-01-15 17:18:28 +02002392 glActiveTexture(GL_TEXTURE0);
2393 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2394 GLsizei size = 64;
2395 for (GLint level = 0; level < 7; ++level)
2396 {
2397 ASSERT_LT(0, size);
2398 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2399 nullptr);
2400 size = size / 2;
2401 }
2402 ASSERT_EQ(0, size);
2403 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2404
2405 glActiveTexture(GL_TEXTURE1);
2406 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2407 size = 128;
2408 for (GLint level = 0; level < 8; ++level)
2409 {
2410 ASSERT_LT(0, size);
2411 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2412 nullptr);
2413 size = size / 2;
2414 }
2415 ASSERT_EQ(0, size);
2416 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2417 EXPECT_GL_NO_ERROR();
2418
2419 glUseProgram(mProgram);
2420 glUniform1i(mTexture0Location, 0);
2421 glUniform1i(mTexture1Location, 1);
2422
Olli Etuaho5804dc82018-04-13 14:11:46 +03002423 drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
Olli Etuahobce743a2016-01-15 17:18:28 +02002424 EXPECT_GL_NO_ERROR();
2425 // Red channel: width of level 1 of texture A: 32.
2426 // Green channel: width of level 3 of texture B: 16.
2427 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2428}
2429
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002430// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2431// ES 3.0.4 table 3.24
2432TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2433{
2434 glActiveTexture(GL_TEXTURE0);
2435 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2436 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2437 EXPECT_GL_NO_ERROR();
2438
2439 drawQuad(mProgram, "position", 0.5f);
2440
2441 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2442}
2443
2444// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2445// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002446TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002447{
Luc Ferron5164b792018-03-06 09:10:12 -05002448 setUpProgram();
2449
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002450 glActiveTexture(GL_TEXTURE0);
2451 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2452 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2453 EXPECT_GL_NO_ERROR();
2454
2455 drawQuad(mProgram, "position", 0.5f);
2456
2457 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2458}
2459
Luc Ferron5164b792018-03-06 09:10:12 -05002460// Validate that every component of the pixel will be equal to the luminance value we've set
2461// and that the alpha channel will be 1 (or 255 to be exact).
2462TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2463{
2464 setUpProgram();
2465
2466 glActiveTexture(GL_TEXTURE0);
2467 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2468 uint8_t pixel = 50;
2469 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2470 EXPECT_GL_NO_ERROR();
2471
2472 drawQuad(mProgram, "position", 0.5f);
2473
2474 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2475}
2476
2477// Validate that every component of the pixel will be equal to the luminance value we've set
2478// and that the alpha channel will be the second component.
2479TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2480{
2481 setUpProgram();
2482
2483 glActiveTexture(GL_TEXTURE0);
2484 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2485 uint8_t pixel[] = {50, 25};
2486 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2487 GL_UNSIGNED_BYTE, pixel);
2488 EXPECT_GL_NO_ERROR();
2489
2490 drawQuad(mProgram, "position", 0.5f);
2491
2492 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2493}
2494
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002495// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2496// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002497TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002498{
Luc Ferrond8c632c2018-04-10 12:31:44 -04002499 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
2500 ANGLE_SKIP_TEST_IF(IsD3D9());
2501 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002502
2503 setUpProgram();
2504
Luc Ferrond8c632c2018-04-10 12:31:44 -04002505 glActiveTexture(GL_TEXTURE0);
2506 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2507 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2508 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002509
Luc Ferrond8c632c2018-04-10 12:31:44 -04002510 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002511
Luc Ferrond8c632c2018-04-10 12:31:44 -04002512 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002513}
2514
2515// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2516// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002517TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002518{
Luc Ferrond8c632c2018-04-10 12:31:44 -04002519 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
2520 ANGLE_SKIP_TEST_IF(IsD3D9());
2521 ANGLE_SKIP_TEST_IF(IsVulkan());
2522 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES());
2523 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2524 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002525
Luc Ferrond8c632c2018-04-10 12:31:44 -04002526 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002527
Luc Ferrond8c632c2018-04-10 12:31:44 -04002528 glActiveTexture(GL_TEXTURE0);
2529 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2530 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2531 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002532
Luc Ferrond8c632c2018-04-10 12:31:44 -04002533 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002534
Luc Ferrond8c632c2018-04-10 12:31:44 -04002535 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002536}
2537
2538// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2539// ES 3.0.4 table 3.24
2540TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2541{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002542 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2543
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002544 glActiveTexture(GL_TEXTURE0);
2545 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2546 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2547 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2548 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2549 EXPECT_GL_NO_ERROR();
2550
2551 drawQuad(mProgram, "position", 0.5f);
2552
2553 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2554}
2555
2556// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2557// ES 3.0.4 table 3.24
2558TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2559{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002560 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2561
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002562 glActiveTexture(GL_TEXTURE0);
2563 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2564
2565 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2566 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2567 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2568 EXPECT_GL_NO_ERROR();
2569
2570 drawQuad(mProgram, "position", 0.5f);
2571
2572 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2573}
2574
2575// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2576// ES 3.0.4 table 3.24
2577TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2578{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002579 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2580
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002581 glActiveTexture(GL_TEXTURE0);
2582 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2583 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2584 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2585 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2586 EXPECT_GL_NO_ERROR();
2587
2588 drawQuad(mProgram, "position", 0.5f);
2589
2590 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2591}
2592
2593// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2594// ES 3.0.4 table 3.24
2595TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2596{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002597 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2598
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002599 glActiveTexture(GL_TEXTURE0);
2600 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2601 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2602 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2603 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2604 EXPECT_GL_NO_ERROR();
2605
2606 drawQuad(mProgram, "position", 0.5f);
2607
2608 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2609}
2610
2611// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2612// ES 3.0.4 table 3.24
2613TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2614{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002615 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2616
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002617 glActiveTexture(GL_TEXTURE0);
2618 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2619 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2620 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2621 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2622 EXPECT_GL_NO_ERROR();
2623
2624 drawQuad(mProgram, "position", 0.5f);
2625
2626 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2627}
2628
2629// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2630// ES 3.0.4 table 3.24
2631TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2632{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002633 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2634
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002635 glActiveTexture(GL_TEXTURE0);
2636 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2637 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2638 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2639 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2640 EXPECT_GL_NO_ERROR();
2641
2642 drawQuad(mProgram, "position", 0.5f);
2643
2644 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2645}
2646
2647// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2648// ES 3.0.4 table 3.24
2649TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2650{
2651 glActiveTexture(GL_TEXTURE0);
2652 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2653 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2654 EXPECT_GL_NO_ERROR();
2655
2656 drawQuad(mProgram, "position", 0.5f);
2657
2658 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2659}
2660
2661// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2662// ES 3.0.4 table 3.24
2663TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2664{
2665 glActiveTexture(GL_TEXTURE0);
2666 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2667 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2668 nullptr);
2669 EXPECT_GL_NO_ERROR();
2670
2671 drawQuad(mProgram, "position", 0.5f);
2672
2673 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2674}
2675
2676// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2677// ES 3.0.4 table 3.24
2678TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2679{
Yunchao He9550c602018-02-13 14:47:05 +08002680 // Seems to fail on OSX 10.12 Intel.
2681 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Jamie Madillbb1db482017-01-10 10:48:32 -05002682
Yuly Novikov49886892018-01-23 21:18:27 -05002683 // http://anglebug.com/2190
2684 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2685
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002686 glActiveTexture(GL_TEXTURE0);
2687 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2688 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2689 EXPECT_GL_NO_ERROR();
2690
2691 drawQuad(mProgram, "position", 0.5f);
2692
2693 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2694}
2695
2696// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2697// ES 3.0.4 table 3.24
2698TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2699{
Yunchao He9550c602018-02-13 14:47:05 +08002700 // Seems to fail on OSX 10.12 Intel.
2701 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002702
Yuly Novikov49886892018-01-23 21:18:27 -05002703 // http://anglebug.com/2190
2704 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2705
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002706 glActiveTexture(GL_TEXTURE0);
2707 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2708 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2709 EXPECT_GL_NO_ERROR();
2710
2711 drawQuad(mProgram, "position", 0.5f);
2712
2713 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2714}
2715
Olli Etuaho96963162016-03-21 11:54:33 +02002716// Use a sampler in a uniform struct.
2717TEST_P(SamplerInStructTest, SamplerInStruct)
2718{
2719 runSamplerInStructTest();
2720}
2721
2722// Use a sampler in a uniform struct that's passed as a function parameter.
2723TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2724{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002725 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002726 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002727
Olli Etuaho96963162016-03-21 11:54:33 +02002728 runSamplerInStructTest();
2729}
2730
2731// Use a sampler in a uniform struct array with a struct from the array passed as a function
2732// parameter.
2733TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2734{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002735 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002736 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
2737
Olli Etuaho96963162016-03-21 11:54:33 +02002738 runSamplerInStructTest();
2739}
2740
2741// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2742// parameter.
2743TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2744{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002745 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002746 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
2747
Olli Etuaho96963162016-03-21 11:54:33 +02002748 runSamplerInStructTest();
2749}
2750
2751// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2752// similarly named uniform.
2753TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2754{
2755 runSamplerInStructTest();
2756}
2757
Till Rathmannb8543632018-10-02 19:46:14 +02002758// GL_OES_texture_border_clamp
2759class TextureBorderClampTest : public Texture2DTest
2760{
2761 protected:
2762 TextureBorderClampTest() : Texture2DTest() {}
2763
2764 std::string getVertexShaderSource() override
2765 {
2766 return
2767 R"(precision highp float;
2768 attribute vec4 position;
2769 varying vec2 texcoord;
2770
2771 void main()
2772 {
2773 gl_Position = vec4(position.xy, 0.0, 1.0);
2774 // texcoords in [-0.5, 1.5]
2775 texcoord = (position.xy) + 0.5;
2776 })";
2777 }
2778
2779 void uploadTexture()
2780 {
2781 glActiveTexture(GL_TEXTURE0);
2782 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2783 std::vector<GLColor> texDataRed(1, GLColor::red);
2784 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2785 texDataRed.data());
2786 EXPECT_GL_NO_ERROR();
2787 }
2788};
2789
2790// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
2791// GL_CLAMP_TO_BORDER wrap mode (set with glTexParameter).
2792TEST_P(TextureBorderClampTest, TextureBorderClampFunctional)
2793{
2794 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
2795
2796 setUpProgram();
2797
2798 uploadTexture();
2799
2800 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
2801 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
2802 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2803 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2804 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2805 EXPECT_GL_NO_ERROR();
2806
2807 drawQuad(mProgram, "position", 0.5f);
2808
2809 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
2810 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2811 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
2812}
2813
2814// Test reading back GL_TEXTURE_BORDER_COLOR by glGetTexParameter.
2815TEST_P(TextureBorderClampTest, TextureBorderClampFunctional2)
2816{
2817 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
2818
2819 glActiveTexture(GL_TEXTURE0);
2820 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2821
2822 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2823
2824 GLint colorFixedPoint[4] = {0};
2825 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
2826 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
2827 std::numeric_limits<GLint>::max()};
2828 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
2829 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
2830 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
2831 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
2832
2833 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
2834 std::numeric_limits<GLint>::max()};
2835 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
2836
2837 GLfloat color[4] = {0.0f};
2838 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
2839 EXPECT_EQ(color[0], kFloatBlue.R);
2840 EXPECT_EQ(color[1], kFloatBlue.G);
2841 EXPECT_EQ(color[2], kFloatBlue.B);
2842 EXPECT_EQ(color[3], kFloatBlue.A);
2843}
2844
2845// Test GL_TEXTURE_BORDER_COLOR parameter validation at glTexParameter.
2846TEST_P(TextureBorderClampTest, TextureBorderClampValidation)
2847{
2848 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
2849
2850 glActiveTexture(GL_TEXTURE0);
2851 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2852
2853 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, 1.0f);
2854 EXPECT_GL_ERROR(GL_INVALID_ENUM);
2855
2856 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
2857 EXPECT_GL_ERROR(GL_INVALID_ENUM);
2858
2859 glTexParameterfv(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2860 EXPECT_GL_ERROR(GL_INVALID_ENUM);
2861
2862 GLint colorInt[4] = {0};
2863 glTexParameteriv(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_BORDER_COLOR, colorInt);
2864 EXPECT_GL_ERROR(GL_INVALID_ENUM);
2865
2866 if (getClientMajorVersion() < 3)
2867 {
2868 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
2869 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2870 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
2871 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2872
2873 GLuint colorUInt[4] = {0};
2874 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
2875 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2876 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
2877 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2878
2879 GLSampler sampler;
2880 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
2881 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2882 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
2883 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2884
2885 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
2886 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2887 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
2888 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2889 }
2890}
2891
2892class TextureBorderClampTestES3 : public TextureBorderClampTest
2893{
2894 protected:
2895 TextureBorderClampTestES3() : TextureBorderClampTest() {}
2896};
2897
2898// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
2899// GL_CLAMP_TO_BORDER wrap mode (set with glSamplerParameter).
2900TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional)
2901{
2902 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
2903
2904 setUpProgram();
2905
2906 uploadTexture();
2907
2908 GLSampler sampler;
2909 glBindSampler(0, sampler);
2910 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
2911 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
2912 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2913 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2914 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2915 EXPECT_GL_NO_ERROR();
2916
2917 drawQuad(mProgram, "position", 0.5f);
2918
2919 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
2920 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2921 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
2922}
2923
2924// Test reading back GL_TEXTURE_BORDER_COLOR by glGetSamplerParameter.
2925TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional2)
2926{
2927 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
2928
2929 glActiveTexture(GL_TEXTURE0);
2930
2931 GLSampler sampler;
2932 glBindSampler(0, sampler);
2933
2934 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2935
2936 GLint colorFixedPoint[4] = {0};
2937 glGetSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
2938 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
2939 std::numeric_limits<GLint>::max()};
2940 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
2941 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
2942 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
2943 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
2944
2945 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
2946 std::numeric_limits<GLint>::max()};
2947 glSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
2948
2949 GLfloat color[4] = {0.0f};
2950 glGetSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, color);
2951 EXPECT_EQ(color[0], kFloatBlue.R);
2952 EXPECT_EQ(color[1], kFloatBlue.G);
2953 EXPECT_EQ(color[2], kFloatBlue.B);
2954 EXPECT_EQ(color[3], kFloatBlue.A);
2955
2956 constexpr GLint colorSomewhatRedInt[4] = {500000, 0, 0, std::numeric_limits<GLint>::max()};
2957 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedInt);
2958 GLint colorInt[4] = {0};
2959 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
2960 EXPECT_EQ(colorInt[0], colorSomewhatRedInt[0]);
2961 EXPECT_EQ(colorInt[1], colorSomewhatRedInt[1]);
2962 EXPECT_EQ(colorInt[2], colorSomewhatRedInt[2]);
2963 EXPECT_EQ(colorInt[3], colorSomewhatRedInt[3]);
2964
2965 constexpr GLuint colorSomewhatRedUInt[4] = {500000, 0, 0, std::numeric_limits<GLuint>::max()};
2966 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedUInt);
2967 GLuint colorUInt[4] = {0};
2968 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
2969 EXPECT_EQ(colorUInt[0], colorSomewhatRedUInt[0]);
2970 EXPECT_EQ(colorUInt[1], colorSomewhatRedUInt[1]);
2971 EXPECT_EQ(colorUInt[2], colorSomewhatRedUInt[2]);
2972 EXPECT_EQ(colorUInt[3], colorSomewhatRedUInt[3]);
2973
2974 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2975
2976 constexpr GLint colorSomewhatGreenInt[4] = {0, 500000, 0, std::numeric_limits<GLint>::max()};
2977 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenInt);
2978 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
2979 EXPECT_EQ(colorInt[0], colorSomewhatGreenInt[0]);
2980 EXPECT_EQ(colorInt[1], colorSomewhatGreenInt[1]);
2981 EXPECT_EQ(colorInt[2], colorSomewhatGreenInt[2]);
2982 EXPECT_EQ(colorInt[3], colorSomewhatGreenInt[3]);
2983
2984 constexpr GLuint colorSomewhatGreenUInt[4] = {0, 500000, 0, std::numeric_limits<GLuint>::max()};
2985 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenUInt);
2986 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
2987 EXPECT_EQ(colorUInt[0], colorSomewhatGreenUInt[0]);
2988 EXPECT_EQ(colorUInt[1], colorSomewhatGreenUInt[1]);
2989 EXPECT_EQ(colorUInt[2], colorSomewhatGreenUInt[2]);
2990 EXPECT_EQ(colorUInt[3], colorSomewhatGreenUInt[3]);
2991}
2992
2993// Test GL_TEXTURE_BORDER_COLOR parameter validation at glSamplerParameter.
2994TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Validation)
2995{
2996 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
2997
2998 glActiveTexture(GL_TEXTURE0);
2999
3000 GLSampler sampler;
3001 glBindSampler(0, sampler);
3002
3003 glSamplerParameterf(sampler, GL_TEXTURE_BORDER_COLOR, 1.0f);
3004 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3005
3006 glSamplerParameteri(sampler, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3007 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3008}
3009
3010class TextureBorderClampIntegerTestES3 : public Texture2DTest
3011{
3012 protected:
3013 TextureBorderClampIntegerTestES3() : Texture2DTest(), isUnsignedIntTest(false) {}
3014
3015 std::string getVertexShaderSource() override
3016 {
3017 return
3018 R"(#version 300 es
3019 out vec2 texcoord;
3020 in vec4 position;
3021
3022 void main()
3023 {
3024 gl_Position = vec4(position.xy, 0.0, 1.0);
3025 // texcoords in [-0.5, 1.5]
3026 texcoord = (position.xy) + 0.5;
3027 })";
3028 }
3029
3030 std::string getFragmentShaderSource()
3031 {
3032 // clang-format off
3033 return std::string(
3034 "#version 300 es\n"
3035 "precision highp float;\n"
3036 "uniform highp ") + (isUnsignedIntTest ? "usampler2D" : "isampler2D") + " tex;\n"
3037 "in vec2 texcoord;\n"
3038 "out vec4 fragColor;\n"
3039
3040 "void main()\n"
3041 "{\n"
3042 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3043 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3044 "fragColor = (texture(tex, texcoord).r == " + (isUnsignedIntTest ? "150u" : "-50") + ")"
3045 " ? green : red;\n"
3046 "}\n";
3047 // clang-format on
3048 }
3049
3050 void uploadTexture()
3051 {
3052 glActiveTexture(GL_TEXTURE0);
3053 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3054 if (isUnsignedIntTest)
3055 {
3056 std::vector<GLubyte> texData(4, 100);
3057 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE,
3058 texData.data());
3059 }
3060 else
3061 {
3062 std::vector<GLbyte> texData(4, 100);
3063 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8I, 1, 1, 0, GL_RGBA_INTEGER, GL_BYTE,
3064 texData.data());
3065 }
3066 EXPECT_GL_NO_ERROR();
3067 }
3068
3069 bool isUnsignedIntTest;
3070};
3071
3072// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3073// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3074TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger)
3075{
3076 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
3077
3078 setUpProgram();
3079
3080 uploadTexture();
3081
3082 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3083 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3084 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3085 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3086
3087 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3088 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3089
3090 EXPECT_GL_NO_ERROR();
3091
3092 drawQuad(mProgram, "position", 0.5f);
3093
3094 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3095 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3096 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3097}
3098
3099// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3100// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3101TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger2)
3102{
3103 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
3104
3105 setUpProgram();
3106
3107 uploadTexture();
3108
3109 GLSampler sampler;
3110 glBindSampler(0, sampler);
3111 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3112 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3113 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3114 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3115
3116 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3117 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3118
3119 EXPECT_GL_NO_ERROR();
3120
3121 drawQuad(mProgram, "position", 0.5f);
3122
3123 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3124 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3125 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3126}
3127
3128// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3129// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIuivOES).
3130TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned)
3131{
3132 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
3133
3134 isUnsignedIntTest = true;
3135
3136 setUpProgram();
3137
3138 uploadTexture();
3139
3140 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3141 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3142 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3143 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3144
3145 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3146 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3147
3148 EXPECT_GL_NO_ERROR();
3149
3150 drawQuad(mProgram, "position", 0.5f);
3151
3152 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3153 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3154 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3155}
3156
3157// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3158// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with
3159// glSamplerParameterIuivOES).
3160TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned2)
3161{
3162 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
3163
3164 isUnsignedIntTest = true;
3165
3166 setUpProgram();
3167
3168 uploadTexture();
3169
3170 GLSampler sampler;
3171 glBindSampler(0, sampler);
3172 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3173 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3174 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3175 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3176
3177 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3178 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3179
3180 EXPECT_GL_NO_ERROR();
3181
3182 drawQuad(mProgram, "position", 0.5f);
3183
3184 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3185 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3186 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3187}
3188
3189// ~GL_OES_texture_border_clamp
3190
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003191class TextureLimitsTest : public ANGLETest
3192{
3193 protected:
3194 struct RGBA8
3195 {
3196 uint8_t R, G, B, A;
3197 };
3198
3199 TextureLimitsTest()
3200 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
3201 {
3202 setWindowWidth(128);
3203 setWindowHeight(128);
3204 setConfigRedBits(8);
3205 setConfigGreenBits(8);
3206 setConfigBlueBits(8);
3207 setConfigAlphaBits(8);
3208 }
3209
Jamie Madill0fdb9562018-09-17 17:18:43 -04003210 void SetUp() override
3211 {
3212 ANGLETest::SetUp();
3213
3214 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
3215 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
3216 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
3217
3218 ASSERT_GL_NO_ERROR();
3219 }
3220
3221 void TearDown() override
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003222 {
3223 if (mProgram != 0)
3224 {
3225 glDeleteProgram(mProgram);
3226 mProgram = 0;
3227
3228 if (!mTextures.empty())
3229 {
3230 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
3231 }
3232 }
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003233
Jamie Madill0fdb9562018-09-17 17:18:43 -04003234 ANGLETest::TearDown();
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003235 }
3236
3237 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
3238 GLint vertexTextureCount,
3239 GLint vertexActiveTextureCount,
3240 const std::string &fragPrefix,
3241 GLint fragmentTextureCount,
3242 GLint fragmentActiveTextureCount)
3243 {
3244 std::stringstream vertexShaderStr;
3245 vertexShaderStr << "attribute vec2 position;\n"
3246 << "varying vec4 color;\n"
3247 << "varying vec2 texCoord;\n";
3248
3249 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
3250 {
3251 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
3252 }
3253
3254 vertexShaderStr << "void main() {\n"
3255 << " gl_Position = vec4(position, 0, 1);\n"
3256 << " texCoord = (position * 0.5) + 0.5;\n"
3257 << " color = vec4(0);\n";
3258
3259 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
3260 {
3261 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
3262 << ", texCoord);\n";
3263 }
3264
3265 vertexShaderStr << "}";
3266
3267 std::stringstream fragmentShaderStr;
3268 fragmentShaderStr << "varying mediump vec4 color;\n"
3269 << "varying mediump vec2 texCoord;\n";
3270
3271 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
3272 {
3273 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
3274 }
3275
3276 fragmentShaderStr << "void main() {\n"
3277 << " gl_FragColor = color;\n";
3278
3279 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
3280 {
3281 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
3282 << ", texCoord);\n";
3283 }
3284
3285 fragmentShaderStr << "}";
3286
3287 const std::string &vertexShaderSource = vertexShaderStr.str();
3288 const std::string &fragmentShaderSource = fragmentShaderStr.str();
3289
3290 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
3291 }
3292
3293 RGBA8 getPixel(GLint texIndex)
3294 {
3295 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3296 0, 255u};
3297 return pixel;
3298 }
3299
3300 void initTextures(GLint tex2DCount, GLint texCubeCount)
3301 {
3302 GLint totalCount = tex2DCount + texCubeCount;
3303 mTextures.assign(totalCount, 0);
3304 glGenTextures(totalCount, &mTextures[0]);
3305 ASSERT_GL_NO_ERROR();
3306
3307 std::vector<RGBA8> texData(16 * 16);
3308
3309 GLint texIndex = 0;
3310 for (; texIndex < tex2DCount; ++texIndex)
3311 {
3312 texData.assign(texData.size(), getPixel(texIndex));
3313 glActiveTexture(GL_TEXTURE0 + texIndex);
3314 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3315 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3316 &texData[0]);
3317 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3318 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3319 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3320 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3321 }
3322
3323 ASSERT_GL_NO_ERROR();
3324
3325 for (; texIndex < texCubeCount; ++texIndex)
3326 {
3327 texData.assign(texData.size(), getPixel(texIndex));
3328 glActiveTexture(GL_TEXTURE0 + texIndex);
3329 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3330 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3331 GL_UNSIGNED_BYTE, &texData[0]);
3332 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3333 GL_UNSIGNED_BYTE, &texData[0]);
3334 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3335 GL_UNSIGNED_BYTE, &texData[0]);
3336 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3337 GL_UNSIGNED_BYTE, &texData[0]);
3338 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3339 GL_UNSIGNED_BYTE, &texData[0]);
3340 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3341 GL_UNSIGNED_BYTE, &texData[0]);
3342 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3343 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3344 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3345 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3346 }
3347
3348 ASSERT_GL_NO_ERROR();
3349 }
3350
3351 void testWithTextures(GLint vertexTextureCount,
3352 const std::string &vertexTexturePrefix,
3353 GLint fragmentTextureCount,
3354 const std::string &fragmentTexturePrefix)
3355 {
3356 // Generate textures
3357 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3358
3359 glUseProgram(mProgram);
3360 RGBA8 expectedSum = {0};
3361 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3362 {
3363 std::stringstream uniformNameStr;
3364 uniformNameStr << vertexTexturePrefix << texIndex;
3365 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003366 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003367 ASSERT_NE(-1, location);
3368
3369 glUniform1i(location, texIndex);
3370 RGBA8 contribution = getPixel(texIndex);
3371 expectedSum.R += contribution.R;
3372 expectedSum.G += contribution.G;
3373 }
3374
3375 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3376 {
3377 std::stringstream uniformNameStr;
3378 uniformNameStr << fragmentTexturePrefix << texIndex;
3379 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003380 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003381 ASSERT_NE(-1, location);
3382
3383 glUniform1i(location, texIndex + vertexTextureCount);
3384 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3385 expectedSum.R += contribution.R;
3386 expectedSum.G += contribution.G;
3387 }
3388
3389 ASSERT_GE(256u, expectedSum.G);
3390
3391 drawQuad(mProgram, "position", 0.5f);
3392 ASSERT_GL_NO_ERROR();
3393 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3394 }
3395
3396 GLuint mProgram;
3397 std::vector<GLuint> mTextures;
3398 GLint mMaxVertexTextures;
3399 GLint mMaxFragmentTextures;
3400 GLint mMaxCombinedTextures;
3401};
3402
3403// Test rendering with the maximum vertex texture units.
3404TEST_P(TextureLimitsTest, MaxVertexTextures)
3405{
3406 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3407 ASSERT_NE(0u, mProgram);
3408 ASSERT_GL_NO_ERROR();
3409
3410 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3411}
3412
3413// Test rendering with the maximum fragment texture units.
3414TEST_P(TextureLimitsTest, MaxFragmentTextures)
3415{
3416 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3417 ASSERT_NE(0u, mProgram);
3418 ASSERT_GL_NO_ERROR();
3419
3420 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3421}
3422
3423// Test rendering with maximum combined texture units.
3424TEST_P(TextureLimitsTest, MaxCombinedTextures)
3425{
3426 GLint vertexTextures = mMaxVertexTextures;
3427
3428 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3429 {
3430 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3431 }
3432
3433 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3434 mMaxFragmentTextures, mMaxFragmentTextures);
3435 ASSERT_NE(0u, mProgram);
3436 ASSERT_GL_NO_ERROR();
3437
3438 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3439}
3440
3441// Negative test for exceeding the number of vertex textures
3442TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3443{
3444 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3445 0);
3446 ASSERT_EQ(0u, mProgram);
3447}
3448
3449// Negative test for exceeding the number of fragment textures
3450TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3451{
3452 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3453 mMaxFragmentTextures + 1);
3454 ASSERT_EQ(0u, mProgram);
3455}
3456
3457// Test active vertex textures under the limit, but excessive textures specified.
3458TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3459{
3460 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3461 ASSERT_NE(0u, mProgram);
3462 ASSERT_GL_NO_ERROR();
3463
3464 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3465}
3466
3467// Test active fragment textures under the limit, but excessive textures specified.
3468TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3469{
3470 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3471 mMaxFragmentTextures);
3472 ASSERT_NE(0u, mProgram);
3473 ASSERT_GL_NO_ERROR();
3474
3475 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3476}
3477
3478// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003479// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003480TEST_P(TextureLimitsTest, TextureTypeConflict)
3481{
3482 const std::string &vertexShader =
3483 "attribute vec2 position;\n"
3484 "varying float color;\n"
3485 "uniform sampler2D tex2D;\n"
3486 "uniform samplerCube texCube;\n"
3487 "void main() {\n"
3488 " gl_Position = vec4(position, 0, 1);\n"
3489 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3490 " color = texture2D(tex2D, texCoord).x;\n"
3491 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3492 "}";
3493 const std::string &fragmentShader =
3494 "varying mediump float color;\n"
3495 "void main() {\n"
3496 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3497 "}";
3498
3499 mProgram = CompileProgram(vertexShader, fragmentShader);
3500 ASSERT_NE(0u, mProgram);
3501
3502 initTextures(1, 0);
3503
3504 glUseProgram(mProgram);
3505 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3506 ASSERT_NE(-1, tex2DLocation);
3507 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3508 ASSERT_NE(-1, texCubeLocation);
3509
3510 glUniform1i(tex2DLocation, 0);
3511 glUniform1i(texCubeLocation, 0);
3512 ASSERT_GL_NO_ERROR();
3513
3514 drawQuad(mProgram, "position", 0.5f);
3515 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3516}
3517
Vincent Lang25ab4512016-05-13 18:13:59 +02003518class Texture2DNorm16TestES3 : public Texture2DTestES3
3519{
3520 protected:
3521 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3522
3523 void SetUp() override
3524 {
3525 Texture2DTestES3::SetUp();
3526
3527 glActiveTexture(GL_TEXTURE0);
3528 glGenTextures(3, mTextures);
3529 glGenFramebuffers(1, &mFBO);
3530 glGenRenderbuffers(1, &mRenderbuffer);
3531
3532 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3533 {
3534 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3535 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3536 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3537 }
3538
3539 glBindTexture(GL_TEXTURE_2D, 0);
3540
3541 ASSERT_GL_NO_ERROR();
3542 }
3543
3544 void TearDown() override
3545 {
3546 glDeleteTextures(3, mTextures);
3547 glDeleteFramebuffers(1, &mFBO);
3548 glDeleteRenderbuffers(1, &mRenderbuffer);
3549
3550 Texture2DTestES3::TearDown();
3551 }
3552
3553 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3554 {
Geoff Langf607c602016-09-21 11:46:48 -04003555 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3556 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003557
3558 setUpProgram();
3559
3560 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3561 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3562 0);
3563
3564 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3565 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3566
3567 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003568 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003569
3570 EXPECT_GL_NO_ERROR();
3571
3572 drawQuad(mProgram, "position", 0.5f);
3573
Geoff Langf607c602016-09-21 11:46:48 -04003574 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003575
Jamie Madill50cf2be2018-06-15 09:46:57 -04003576 EXPECT_PIXEL_COLOR_EQ(0, 0,
3577 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3578 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003579
3580 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3581
3582 ASSERT_GL_NO_ERROR();
3583 }
3584
3585 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3586 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04003587 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003588 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003589
3590 setUpProgram();
3591
3592 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3593 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3594
3595 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3596 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3597 0);
3598
3599 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003600 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003601
3602 EXPECT_GL_NO_ERROR();
3603
3604 drawQuad(mProgram, "position", 0.5f);
3605
Geoff Langf607c602016-09-21 11:46:48 -04003606 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
Jamie Madill50cf2be2018-06-15 09:46:57 -04003607 EXPECT_PIXEL_COLOR_EQ(0, 0,
3608 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3609 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003610
3611 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3612 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3613 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3614 mRenderbuffer);
3615 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3616 EXPECT_GL_NO_ERROR();
3617
3618 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3619 glClear(GL_COLOR_BUFFER_BIT);
3620
3621 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3622
Geoff Langf607c602016-09-21 11:46:48 -04003623 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003624
3625 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3626
3627 ASSERT_GL_NO_ERROR();
3628 }
3629
3630 GLuint mTextures[3];
3631 GLuint mFBO;
3632 GLuint mRenderbuffer;
3633};
3634
3635// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3636TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3637{
Yunchao He9550c602018-02-13 14:47:05 +08003638 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02003639
3640 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3641 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3642 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3643 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3644 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3645 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3646 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3647 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3648
3649 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3650 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3651 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3652}
3653
Olli Etuaho95faa232016-06-07 14:01:53 -07003654// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3655// GLES 3.0.4 section 3.8.3.
3656TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3657{
Yuly Novikov3c754192016-06-27 19:36:41 -04003658 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1429 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08003659 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07003660
3661 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3662 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3663 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3664 ASSERT_GL_NO_ERROR();
3665
3666 // SKIP_IMAGES should not have an effect on uploading 2D textures
3667 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3668 ASSERT_GL_NO_ERROR();
3669
3670 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3671
3672 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3673 pixelsGreen.data());
3674 ASSERT_GL_NO_ERROR();
3675
3676 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3677 pixelsGreen.data());
3678 ASSERT_GL_NO_ERROR();
3679
3680 glUseProgram(mProgram);
3681 drawQuad(mProgram, "position", 0.5f);
3682 ASSERT_GL_NO_ERROR();
3683
3684 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3685}
3686
Olli Etuaho989cac32016-06-08 16:18:49 -07003687// Test that skip defined in unpack parameters is taken into account when determining whether
3688// unpacking source extends outside unpack buffer bounds.
3689TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3690{
3691 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3692 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3693 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3694 ASSERT_GL_NO_ERROR();
3695
3696 GLBuffer buf;
3697 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3698 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3699 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3700 GL_DYNAMIC_COPY);
3701 ASSERT_GL_NO_ERROR();
3702
3703 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3704 ASSERT_GL_NO_ERROR();
3705
3706 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3707 ASSERT_GL_NO_ERROR();
3708
3709 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3710 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3711
3712 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3713 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3714 ASSERT_GL_NO_ERROR();
3715
3716 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3717 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3718}
3719
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003720// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3721TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3722{
Yunchao He9550c602018-02-13 14:47:05 +08003723 ANGLE_SKIP_TEST_IF(IsD3D11());
3724
3725 // Incorrect rendering results seen on OSX AMD.
3726 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003727
3728 const GLuint width = 8u;
3729 const GLuint height = 8u;
3730 const GLuint unpackRowLength = 5u;
3731 const GLuint unpackSkipPixels = 1u;
3732
3733 setWindowWidth(width);
3734 setWindowHeight(height);
3735
3736 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3737 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3738 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3739 ASSERT_GL_NO_ERROR();
3740
3741 GLBuffer buf;
3742 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3743 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3744 GLColor::green);
3745
3746 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3747 {
3748 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3749 }
3750
3751 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3752 GL_DYNAMIC_COPY);
3753 ASSERT_GL_NO_ERROR();
3754
3755 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3756 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3757 ASSERT_GL_NO_ERROR();
3758
3759 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3760 ASSERT_GL_NO_ERROR();
3761
3762 glUseProgram(mProgram);
3763 drawQuad(mProgram, "position", 0.5f);
3764 ASSERT_GL_NO_ERROR();
3765
3766 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3767 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3768 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3769 actual.data());
3770 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3771 EXPECT_EQ(expected, actual);
3772}
3773
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003774template <typename T>
3775T UNorm(double value)
3776{
3777 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3778}
3779
3780// Test rendering a depth texture with mipmaps.
3781TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3782{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003783 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3784 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
Jiawei Shaoaf0f31d2018-09-27 15:42:31 +08003785 // http://anglebug.com/1706
3786 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Corentin Walleze731d8a2016-09-07 10:56:25 -04003787
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003788 const int size = getWindowWidth();
3789
3790 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003791 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003792
3793 glActiveTexture(GL_TEXTURE0);
3794 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3795 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3796 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3797 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3798 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3799 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3800 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3801 ASSERT_GL_NO_ERROR();
3802
3803 glUseProgram(mProgram);
3804 glUniform1i(mTexture2DUniformLocation, 0);
3805
3806 std::vector<unsigned char> expected;
3807
3808 for (int level = 0; level < levels; ++level)
3809 {
3810 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3811 expected.push_back(UNorm<unsigned char>(value));
3812
3813 int levelDim = dim(level);
3814
3815 ASSERT_GT(levelDim, 0);
3816
3817 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3818 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3819 GL_UNSIGNED_INT, initData.data());
3820 }
3821 ASSERT_GL_NO_ERROR();
3822
3823 for (int level = 0; level < levels; ++level)
3824 {
3825 glViewport(0, 0, dim(level), dim(level));
3826 drawQuad(mProgram, "position", 0.5f);
3827 GLColor actual = ReadColor(0, 0);
3828 EXPECT_NEAR(expected[level], actual.R, 10u);
3829 }
3830
3831 ASSERT_GL_NO_ERROR();
3832}
3833
Jamie Madill7ffdda92016-09-08 13:26:51 -04003834// Tests unpacking into the unsized GL_ALPHA format.
3835TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3836{
Jamie Madill7ffdda92016-09-08 13:26:51 -04003837 // Initialize the texure.
3838 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3839 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3840 GL_UNSIGNED_BYTE, nullptr);
3841 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3842 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3843
3844 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3845
3846 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04003847 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04003848 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3849 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3850 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
3851 GL_STATIC_DRAW);
3852
3853 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
3854 GL_UNSIGNED_BYTE, nullptr);
3855
3856 // Clear to a weird color to make sure we're drawing something.
3857 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
3858 glClear(GL_COLOR_BUFFER_BIT);
3859
3860 // Draw with the alpha texture and verify.
3861 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04003862
3863 ASSERT_GL_NO_ERROR();
3864 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
3865}
3866
Jamie Madill2e600342016-09-19 13:56:40 -04003867// Ensure stale unpack data doesn't propagate in D3D11.
3868TEST_P(Texture2DTestES3, StaleUnpackData)
3869{
3870 // Init unpack buffer.
3871 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
3872 std::vector<GLColor> pixels(pixelCount, GLColor::red);
3873
3874 GLBuffer unpackBuffer;
3875 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3876 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3877 GLsizei bufferSize = pixelCount * sizeof(GLColor);
3878 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
3879
3880 // Create from unpack buffer.
3881 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3882 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
3883 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3884 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3885 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3886
3887 drawQuad(mProgram, "position", 0.5f);
3888
3889 ASSERT_GL_NO_ERROR();
3890 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3891
3892 // Fill unpack with green, recreating buffer.
3893 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
3894 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
3895 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
3896
3897 // Reinit texture with green.
3898 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
3899 GL_UNSIGNED_BYTE, nullptr);
3900
3901 drawQuad(mProgram, "position", 0.5f);
3902
3903 ASSERT_GL_NO_ERROR();
3904 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3905}
3906
Geoff Langfb7685f2017-11-13 11:44:11 -05003907// Ensure that texture parameters passed as floats that are converted to ints are rounded before
3908// validating they are less than 0.
3909TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
3910{
3911 GLTexture texture;
3912 glBindTexture(GL_TEXTURE_2D, texture);
3913
3914 // Use a negative number that will round to zero when converted to an integer
3915 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
3916 // "Validation of values performed by state-setting commands is performed after conversion,
3917 // unless specified otherwise for a specific command."
3918 GLfloat param = -7.30157126e-07f;
3919 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
3920 EXPECT_GL_NO_ERROR();
3921
3922 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
3923 EXPECT_GL_NO_ERROR();
3924}
3925
Jamie Madillf097e232016-11-05 00:44:15 -04003926// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
3927// being properly checked, and the texture storage of the previous texture format was persisting.
3928// This would result in an ASSERT in debug and incorrect rendering in release.
3929// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
3930TEST_P(Texture3DTestES3, FormatRedefinitionBug)
3931{
3932 GLTexture tex;
3933 glBindTexture(GL_TEXTURE_3D, tex.get());
3934 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3935
3936 GLFramebuffer framebuffer;
3937 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3938 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
3939
3940 glCheckFramebufferStatus(GL_FRAMEBUFFER);
3941
3942 std::vector<uint8_t> pixelData(100, 0);
3943
3944 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
3945 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
3946 pixelData.data());
3947
3948 ASSERT_GL_NO_ERROR();
3949}
3950
Corentin Wallezd2627992017-04-28 17:17:03 -04003951// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
3952TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
3953{
3954 // 2D tests
3955 {
3956 GLTexture tex;
3957 glBindTexture(GL_TEXTURE_2D, tex.get());
3958
3959 GLBuffer pbo;
3960 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3961
3962 // Test OOB
3963 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
3964 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3965 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3966
3967 // Test OOB
3968 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
3969 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3970 ASSERT_GL_NO_ERROR();
3971 }
3972
3973 // 3D tests
3974 {
3975 GLTexture tex;
3976 glBindTexture(GL_TEXTURE_3D, tex.get());
3977
3978 GLBuffer pbo;
3979 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3980
3981 // Test OOB
3982 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
3983 GL_STATIC_DRAW);
3984 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3985 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3986
3987 // Test OOB
3988 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
3989 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3990 ASSERT_GL_NO_ERROR();
3991 }
3992}
3993
Jamie Madill3ed60422017-09-07 11:32:52 -04003994// Tests behaviour with a single texture and multiple sampler objects.
3995TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
3996{
3997 GLint maxTextureUnits = 0;
3998 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
3999 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
4000
4001 constexpr int kSize = 16;
4002
4003 // Make a single-level texture, fill it with red.
4004 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
4005 GLTexture tex;
4006 glBindTexture(GL_TEXTURE_2D, tex);
4007 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4008 redColors.data());
4009 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4010 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4011
4012 // Simple sanity check.
4013 draw2DTexturedQuad(0.5f, 1.0f, true);
4014 ASSERT_GL_NO_ERROR();
4015 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4016
4017 // Bind texture to unit 1 with a sampler object making it incomplete.
4018 GLSampler sampler;
4019 glBindSampler(0, sampler);
4020 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4021 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4022
4023 // Make a mipmap texture, fill it with blue.
4024 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
4025 GLTexture mipmapTex;
4026 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4027 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4028 blueColors.data());
4029 glGenerateMipmap(GL_TEXTURE_2D);
4030
4031 // Draw with the sampler, expect blue.
4032 draw2DTexturedQuad(0.5f, 1.0f, true);
4033 ASSERT_GL_NO_ERROR();
4034 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
4035
4036 // Simple multitexturing program.
4037 const std::string vs =
4038 "#version 300 es\n"
4039 "in vec2 position;\n"
4040 "out vec2 texCoord;\n"
4041 "void main()\n"
4042 "{\n"
4043 " gl_Position = vec4(position, 0, 1);\n"
4044 " texCoord = position * 0.5 + vec2(0.5);\n"
4045 "}";
4046 const std::string fs =
4047 "#version 300 es\n"
4048 "precision mediump float;\n"
4049 "in vec2 texCoord;\n"
4050 "uniform sampler2D tex1;\n"
4051 "uniform sampler2D tex2;\n"
4052 "uniform sampler2D tex3;\n"
4053 "uniform sampler2D tex4;\n"
4054 "out vec4 color;\n"
4055 "void main()\n"
4056 "{\n"
4057 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
4058 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
4059 "}";
4060
4061 ANGLE_GL_PROGRAM(program, vs, fs);
4062
4063 std::array<GLint, 4> texLocations = {
4064 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
4065 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
4066 for (GLint location : texLocations)
4067 {
4068 ASSERT_NE(-1, location);
4069 }
4070
4071 // Init the uniform data.
4072 glUseProgram(program);
4073 for (GLint location = 0; location < 4; ++location)
4074 {
4075 glUniform1i(texLocations[location], location);
4076 }
4077
4078 // Initialize four samplers
4079 GLSampler samplers[4];
4080
4081 // 0: non-mipped.
4082 glBindSampler(0, samplers[0]);
4083 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4084 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4085
4086 // 1: mipped.
4087 glBindSampler(1, samplers[1]);
4088 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4089 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4090
4091 // 2: non-mipped.
4092 glBindSampler(2, samplers[2]);
4093 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4094 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4095
4096 // 3: mipped.
4097 glBindSampler(3, samplers[3]);
4098 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4099 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4100
4101 // Bind two blue mipped textures and two single layer textures, should all draw.
4102 glActiveTexture(GL_TEXTURE0);
4103 glBindTexture(GL_TEXTURE_2D, tex);
4104
4105 glActiveTexture(GL_TEXTURE1);
4106 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4107
4108 glActiveTexture(GL_TEXTURE2);
4109 glBindTexture(GL_TEXTURE_2D, tex);
4110
4111 glActiveTexture(GL_TEXTURE3);
4112 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4113
4114 ASSERT_GL_NO_ERROR();
4115
4116 drawQuad(program, "position", 0.5f);
4117 ASSERT_GL_NO_ERROR();
4118 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
4119
4120 // Bind four single layer textures, two should be incomplete.
4121 glActiveTexture(GL_TEXTURE1);
4122 glBindTexture(GL_TEXTURE_2D, tex);
4123
4124 glActiveTexture(GL_TEXTURE3);
4125 glBindTexture(GL_TEXTURE_2D, tex);
4126
4127 drawQuad(program, "position", 0.5f);
4128 ASSERT_GL_NO_ERROR();
4129 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
4130}
4131
Martin Radev7e2c0d32017-09-15 14:25:42 +03004132// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
4133// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
4134// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
4135// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
4136// samples the cubemap using a direction vector (1,1,1).
4137TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
4138{
Yunchao He2f23f352018-02-11 22:11:37 +08004139 // Check http://anglebug.com/2155.
4140 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
4141
Martin Radev7e2c0d32017-09-15 14:25:42 +03004142 const std::string vs =
4143 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004144 precision mediump float;
4145 in vec3 pos;
4146 void main() {
4147 gl_Position = vec4(pos, 1.0);
4148 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03004149
4150 const std::string fs =
4151 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004152 precision mediump float;
4153 out vec4 color;
4154 uniform samplerCube uTex;
4155 void main(){
4156 color = texture(uTex, vec3(1.0));
4157 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03004158 ANGLE_GL_PROGRAM(program, vs, fs);
4159 glUseProgram(program);
4160
4161 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
4162 glActiveTexture(GL_TEXTURE0);
4163
4164 GLTexture cubeTex;
4165 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
4166
4167 const int kFaceWidth = 1;
4168 const int kFaceHeight = 1;
4169 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
4170 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4171 GL_UNSIGNED_BYTE, texData.data());
4172 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4173 GL_UNSIGNED_BYTE, texData.data());
4174 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4175 GL_UNSIGNED_BYTE, texData.data());
4176 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4177 GL_UNSIGNED_BYTE, texData.data());
4178 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4179 GL_UNSIGNED_BYTE, texData.data());
4180 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4181 GL_UNSIGNED_BYTE, texData.data());
4182 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4183 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4184 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
4185 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
4186 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
4187 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
4188
4189 drawQuad(program, "pos", 0.5f, 1.0f, true);
4190 ASSERT_GL_NO_ERROR();
4191
4192 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4193}
4194
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08004195// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
4196TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
4197{
4198 GLuint texture = create2DTexture();
4199
4200 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
4201 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4202
4203 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
4204 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4205
4206 glDeleteTextures(1, &texture);
4207 EXPECT_GL_NO_ERROR();
4208}
4209
Olli Etuaho023371b2018-04-24 17:43:32 +03004210// Test setting base level after calling generateMipmap on a LUMA texture.
4211// Covers http://anglebug.com/2498
4212TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA)
4213{
4214 glActiveTexture(GL_TEXTURE0);
4215 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4216
4217 constexpr const GLsizei kWidth = 8;
4218 constexpr const GLsizei kHeight = 8;
4219 std::array<GLubyte, kWidth * kHeight * 2> whiteData;
4220 whiteData.fill(255u);
4221
4222 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA,
4223 GL_UNSIGNED_BYTE, whiteData.data());
4224 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
4225 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4226 glGenerateMipmap(GL_TEXTURE_2D);
4227 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
4228 EXPECT_GL_NO_ERROR();
4229
4230 drawQuad(mProgram, "position", 0.5f);
4231 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4232}
4233
Till Rathmannc1551dc2018-08-15 17:04:49 +02004234// Covers a bug in the D3D11 backend: http://anglebug.com/2772
4235// When using a sampler the texture was created as if it has mipmaps,
4236// regardless what you specified in GL_TEXTURE_MIN_FILTER via
4237// glSamplerParameteri() -- mistakenly the default value
4238// GL_NEAREST_MIPMAP_LINEAR or the value set via glTexParameteri() was
4239// evaluated.
4240// If you didn't provide mipmaps and didn't let the driver generate them
4241// this led to not sampling your texture data when minification occurred.
4242TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping)
4243{
4244 const std::string vs =
4245 "#version 300 es\n"
4246 "out vec2 texcoord;\n"
4247 "in vec4 position;\n"
4248 "void main()\n"
4249 "{\n"
4250 " gl_Position = vec4(position.xy * 0.1, 0.0, 1.0);\n"
4251 " texcoord = (position.xy * 0.5) + 0.5;\n"
4252 "}\n";
4253
4254 const std::string fs =
4255 "#version 300 es\n"
4256 "precision highp float;\n"
4257 "uniform highp sampler2D tex;\n"
4258 "in vec2 texcoord;\n"
4259 "out vec4 fragColor;\n"
4260 "void main()\n"
4261 "{\n"
4262 " fragColor = texture(tex, texcoord);\n"
4263 "}\n";
4264 ANGLE_GL_PROGRAM(program, vs, fs);
4265
4266 GLSampler sampler;
4267 glBindSampler(0, sampler);
4268 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4269 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4270
4271 glActiveTexture(GL_TEXTURE0);
4272 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4273
4274 const GLsizei texWidth = getWindowWidth();
4275 const GLsizei texHeight = getWindowHeight();
4276 const std::vector<GLColor> whiteData(texWidth * texHeight, GLColor::white);
4277
4278 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4279 whiteData.data());
4280 EXPECT_GL_NO_ERROR();
4281
4282 drawQuad(program, "position", 0.5f);
4283 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, angle::GLColor::white);
4284}
4285
Jamie Madill50cf2be2018-06-15 09:46:57 -04004286// Use this to select which configurations (e.g. which renderer, which GLES major version) these
4287// tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -05004288ANGLE_INSTANTIATE_TEST(Texture2DTest,
4289 ES2_D3D9(),
4290 ES2_D3D11(),
4291 ES2_D3D11_FL9_3(),
4292 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05004293 ES2_OPENGLES(),
4294 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004295ANGLE_INSTANTIATE_TEST(TextureCubeTest,
4296 ES2_D3D9(),
4297 ES2_D3D11(),
Geoff Langf7480ad2017-10-24 11:46:02 -04004298 ES2_D3D11_FL10_0(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004299 ES2_D3D11_FL9_3(),
4300 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004301 ES2_OPENGLES(),
4302 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004303ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
4304 ES2_D3D9(),
4305 ES2_D3D11(),
4306 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004307 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004308 ES2_OPENGLES(),
4309 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004310ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
4311 ES2_D3D9(),
4312 ES2_D3D11(),
4313 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004314 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004315 ES2_OPENGLES(),
4316 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004317ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
4318 ES2_D3D9(),
4319 ES2_D3D11(),
4320 ES2_D3D11_FL9_3(),
4321 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004322 ES2_OPENGLES(),
4323 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004324ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
4325 ES2_D3D9(),
4326 ES2_D3D11(),
4327 ES2_D3D11_FL9_3(),
4328 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004329 ES2_OPENGLES(),
4330 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004331ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02004332ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02004333ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4334ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
4335 ES3_D3D11(),
4336 ES3_OPENGL(),
4337 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004338ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
4339 ES3_D3D11(),
4340 ES3_OPENGL(),
4341 ES3_OPENGLES());
4342ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4343ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02004344ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02004345ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
4346 ES2_D3D11(),
4347 ES2_D3D11_FL9_3(),
4348 ES2_D3D9(),
4349 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004350 ES2_OPENGLES(),
4351 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004352ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
4353 ES2_D3D11(),
4354 ES2_D3D11_FL9_3(),
4355 ES2_D3D9(),
4356 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004357 ES2_OPENGLES(),
4358 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004359ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
4360 ES2_D3D11(),
4361 ES2_D3D11_FL9_3(),
4362 ES2_D3D9(),
4363 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004364 ES2_OPENGLES(),
4365 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004366ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
4367 ES2_D3D11(),
4368 ES2_D3D11_FL9_3(),
4369 ES2_D3D9(),
4370 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004371 ES2_OPENGLES(),
4372 ES2_VULKAN());
Olli Etuaho96963162016-03-21 11:54:33 +02004373ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
4374 ES2_D3D11(),
4375 ES2_D3D11_FL9_3(),
4376 ES2_D3D9(),
4377 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004378 ES2_OPENGLES(),
4379 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02004380ANGLE_INSTANTIATE_TEST(TextureBorderClampTest,
4381 ES2_D3D11(),
4382 ES2_D3D9(),
4383 ES2_OPENGL(),
Shahbaz Youssefi0864a7a2018-11-07 15:50:15 -05004384 ES2_OPENGLES(),
4385 ES2_VULKAN());
Till Rathmannb8543632018-10-02 19:46:14 +02004386ANGLE_INSTANTIATE_TEST(TextureBorderClampTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4387ANGLE_INSTANTIATE_TEST(TextureBorderClampIntegerTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Luc Ferronaf883622018-06-08 15:57:31 -04004388ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN());
Vincent Lang25ab4512016-05-13 18:13:59 +02004389ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03004390ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04004391
Jamie Madill7ffdda92016-09-08 13:26:51 -04004392} // anonymous namespace