blob: e6c94b5f891bb4888886d6ebf72e46e200be2bb4 [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[] = {
234 GL_R32F, GL_RG32F, GL_RGB32F, GL_RGBA32F,
Jamie Madillbc393df2015-01-29 13:46:07 -0500235 };
236
Jamie Madill50cf2be2018-06-15 09:46:57 -0400237 GLenum sourceUnsizedFormats[] = {
238 GL_RED, GL_RG, GL_RGB, GL_RGBA,
Jamie Madillbc393df2015-01-29 13:46:07 -0500239 };
240
241 GLuint textures[2];
242
243 glGenTextures(2, textures);
244
Jamie Madill50cf2be2018-06-15 09:46:57 -0400245 GLfloat *imageData = sourceImageData[sourceImageChannels - 1];
246 GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1];
Jamie Madillbc393df2015-01-29 13:46:07 -0500247 GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1];
Jamie Madill50cf2be2018-06-15 09:46:57 -0400248 GLenum destImageFormat = imageFormats[destImageChannels - 1];
Jamie Madillbc393df2015-01-29 13:46:07 -0500249
250 glBindTexture(GL_TEXTURE_2D, textures[0]);
Geoff Langc4e93662017-05-01 10:45:59 -0400251 if (getClientMajorVersion() >= 3)
252 {
253 glTexStorage2D(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
254 }
255 else
256 {
257 glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
258 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500259 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
260 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
261 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData);
262
hendrikwb27f79a2015-03-04 11:26:46 -0800263 if (sourceImageChannels < 3 && !extensionEnabled("GL_EXT_texture_rg"))
Jamie Madillbc393df2015-01-29 13:46:07 -0500264 {
265 // This is not supported
266 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
267 }
268 else
269 {
270 ASSERT_GL_NO_ERROR();
271 }
272
273 GLuint fbo;
274 glGenFramebuffers(1, &fbo);
275 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
276 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
277
278 glBindTexture(GL_TEXTURE_2D, textures[1]);
Geoff Langc4e93662017-05-01 10:45:59 -0400279 if (getClientMajorVersion() >= 3)
280 {
281 glTexStorage2D(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
282 }
283 else
284 {
285 glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
286 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500287 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
288 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
289
290 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
291 ASSERT_GL_NO_ERROR();
292
293 glBindFramebuffer(GL_FRAMEBUFFER, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200294 drawQuad(mProgram, "position", 0.5f);
Jamie Madillbc393df2015-01-29 13:46:07 -0500295
296 int testImageChannels = std::min(sourceImageChannels, destImageChannels);
297
Olli Etuahoa314b612016-03-10 16:43:00 +0200298 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Jamie Madillbc393df2015-01-29 13:46:07 -0500299 if (testImageChannels > 1)
300 {
301 EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255);
302 EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255);
303 if (testImageChannels > 2)
304 {
305 EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255);
306 }
307 }
308
309 glDeleteFramebuffers(1, &fbo);
310 glDeleteTextures(2, textures);
311
312 ASSERT_GL_NO_ERROR();
313 }
314
Jamie Madilld4cfa572014-07-08 10:00:32 -0400315 GLuint mTexture2D;
Jamie Madilld4cfa572014-07-08 10:00:32 -0400316 GLint mTexture2DUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400317};
318
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200319class Texture2DTestES3 : public Texture2DTest
320{
321 protected:
322 Texture2DTestES3() : Texture2DTest() {}
323
324 std::string getVertexShaderSource() override
325 {
326 return std::string(
327 "#version 300 es\n"
328 "out vec2 texcoord;\n"
329 "in vec4 position;\n"
330 "void main()\n"
331 "{\n"
332 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
333 " texcoord = (position.xy * 0.5) + 0.5;\n"
334 "}\n");
335 }
336
337 std::string getFragmentShaderSource() override
338 {
339 return std::string(
340 "#version 300 es\n"
341 "precision highp float;\n"
342 "uniform highp sampler2D tex;\n"
343 "in vec2 texcoord;\n"
344 "out vec4 fragColor;\n"
345 "void main()\n"
346 "{\n"
347 " fragColor = texture(tex, texcoord);\n"
348 "}\n");
349 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300350
351 void SetUp() override
352 {
353 Texture2DTest::SetUp();
354 setUpProgram();
355 }
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200356};
357
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200358class Texture2DIntegerAlpha1TestES3 : public Texture2DTest
359{
360 protected:
361 Texture2DIntegerAlpha1TestES3() : Texture2DTest() {}
362
363 std::string getVertexShaderSource() override
364 {
365 return std::string(
366 "#version 300 es\n"
367 "out vec2 texcoord;\n"
368 "in vec4 position;\n"
369 "void main()\n"
370 "{\n"
371 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
372 " texcoord = (position.xy * 0.5) + 0.5;\n"
373 "}\n");
374 }
375
376 std::string getFragmentShaderSource() override
377 {
378 return std::string(
379 "#version 300 es\n"
380 "precision highp float;\n"
381 "uniform highp isampler2D tex;\n"
382 "in vec2 texcoord;\n"
383 "out vec4 fragColor;\n"
384 "void main()\n"
385 "{\n"
386 " vec4 green = vec4(0, 1, 0, 1);\n"
387 " vec4 black = vec4(0, 0, 0, 0);\n"
388 " fragColor = (texture(tex, texcoord).a == 1) ? green : black;\n"
389 "}\n");
390 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300391
392 void SetUp() override
393 {
394 Texture2DTest::SetUp();
395 setUpProgram();
396 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200397};
398
399class Texture2DUnsignedIntegerAlpha1TestES3 : public Texture2DTest
400{
401 protected:
402 Texture2DUnsignedIntegerAlpha1TestES3() : Texture2DTest() {}
403
404 std::string getVertexShaderSource() override
405 {
406 return std::string(
407 "#version 300 es\n"
408 "out vec2 texcoord;\n"
409 "in vec4 position;\n"
410 "void main()\n"
411 "{\n"
412 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
413 " texcoord = (position.xy * 0.5) + 0.5;\n"
414 "}\n");
415 }
416
417 std::string getFragmentShaderSource() override
418 {
419 return std::string(
420 "#version 300 es\n"
421 "precision highp float;\n"
422 "uniform highp usampler2D tex;\n"
423 "in vec2 texcoord;\n"
424 "out vec4 fragColor;\n"
425 "void main()\n"
426 "{\n"
427 " vec4 green = vec4(0, 1, 0, 1);\n"
428 " vec4 black = vec4(0, 0, 0, 0);\n"
429 " fragColor = (texture(tex, texcoord).a == 1u) ? green : black;\n"
430 "}\n");
431 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300432
433 void SetUp() override
434 {
435 Texture2DTest::SetUp();
436 setUpProgram();
437 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200438};
439
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200440class Texture2DTestWithDrawScale : public Texture2DTest
Jamie Madill2453dbc2015-07-14 11:35:42 -0400441{
442 protected:
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200443 Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {}
444
445 std::string getVertexShaderSource() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400446 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300447 return
448 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200449 attribute vec4 position;
450 varying vec2 texcoord;
451
452 uniform vec2 drawScale;
453
454 void main()
455 {
456 gl_Position = vec4(position.xy * drawScale, 0.0, 1.0);
457 texcoord = (position.xy * 0.5) + 0.5;
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300458 })";
Jamie Madill2453dbc2015-07-14 11:35:42 -0400459 }
460
461 void SetUp() override
462 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200463 Texture2DTest::SetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300464
465 setUpProgram();
466
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200467 mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale");
468 ASSERT_NE(-1, mDrawScaleUniformLocation);
Jamie Madill2453dbc2015-07-14 11:35:42 -0400469
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200470 glUseProgram(mProgram);
471 glUniform2f(mDrawScaleUniformLocation, 1.0f, 1.0f);
472 glUseProgram(0);
473 ASSERT_GL_NO_ERROR();
474 }
475
476 GLint mDrawScaleUniformLocation;
477};
478
Olli Etuaho4644a202016-01-12 15:12:53 +0200479class Sampler2DAsFunctionParameterTest : public Texture2DTest
480{
481 protected:
482 Sampler2DAsFunctionParameterTest() : Texture2DTest() {}
483
484 std::string getFragmentShaderSource() override
485 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300486 return
487 R"(precision highp float;
Olli Etuaho4644a202016-01-12 15:12:53 +0200488 uniform sampler2D tex;
489 varying vec2 texcoord;
490
491 vec4 computeFragColor(sampler2D aTex)
492 {
493 return texture2D(aTex, texcoord);
494 }
495
496 void main()
497 {
498 gl_FragColor = computeFragColor(tex);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300499 })";
Olli Etuaho4644a202016-01-12 15:12:53 +0200500 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300501
502 void SetUp() override
503 {
504 Texture2DTest::SetUp();
505 setUpProgram();
506 }
Olli Etuaho4644a202016-01-12 15:12:53 +0200507};
508
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200509class TextureCubeTest : public TexCoordDrawTest
510{
511 protected:
512 TextureCubeTest()
513 : TexCoordDrawTest(),
514 mTexture2D(0),
515 mTextureCube(0),
516 mTexture2DUniformLocation(-1),
517 mTextureCubeUniformLocation(-1)
518 {
519 }
520
521 std::string getFragmentShaderSource() override
522 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300523 return
524 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200525 uniform sampler2D tex2D;
526 uniform samplerCube texCube;
527 varying vec2 texcoord;
528
529 void main()
530 {
531 gl_FragColor = texture2D(tex2D, texcoord);
532 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300533 })";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200534 }
535
536 void SetUp() override
537 {
538 TexCoordDrawTest::SetUp();
539
540 glGenTextures(1, &mTextureCube);
541 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Geoff Langc4e93662017-05-01 10:45:59 -0400542 for (GLenum face = 0; face < 6; face++)
543 {
544 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
545 GL_UNSIGNED_BYTE, nullptr);
546 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200547 EXPECT_GL_NO_ERROR();
548
549 mTexture2D = create2DTexture();
550
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300551 setUpProgram();
552
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200553 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
554 ASSERT_NE(-1, mTexture2DUniformLocation);
555 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
556 ASSERT_NE(-1, mTextureCubeUniformLocation);
557 }
558
559 void TearDown() override
560 {
561 glDeleteTextures(1, &mTextureCube);
562 TexCoordDrawTest::TearDown();
563 }
564
565 GLuint mTexture2D;
566 GLuint mTextureCube;
567 GLint mTexture2DUniformLocation;
568 GLint mTextureCubeUniformLocation;
569};
570
Martin Radev7e2c0d32017-09-15 14:25:42 +0300571class TextureCubeTestES3 : public ANGLETest
572{
573 protected:
574 TextureCubeTestES3() {}
575};
576
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200577class SamplerArrayTest : public TexCoordDrawTest
578{
579 protected:
580 SamplerArrayTest()
581 : TexCoordDrawTest(),
582 mTexture2DA(0),
583 mTexture2DB(0),
584 mTexture0UniformLocation(-1),
585 mTexture1UniformLocation(-1)
586 {
587 }
588
589 std::string getFragmentShaderSource() override
590 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300591 return
592 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200593 uniform highp sampler2D tex2DArray[2];
594 varying vec2 texcoord;
595 void main()
596 {
597 gl_FragColor = texture2D(tex2DArray[0], texcoord);
598 gl_FragColor += texture2D(tex2DArray[1], texcoord);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300599 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200600 }
601
602 void SetUp() override
603 {
604 TexCoordDrawTest::SetUp();
605
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300606 setUpProgram();
607
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200608 mTexture0UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[0]");
609 ASSERT_NE(-1, mTexture0UniformLocation);
610 mTexture1UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[1]");
611 ASSERT_NE(-1, mTexture1UniformLocation);
612
613 mTexture2DA = create2DTexture();
614 mTexture2DB = create2DTexture();
615 ASSERT_GL_NO_ERROR();
616 }
617
618 void TearDown() override
619 {
620 glDeleteTextures(1, &mTexture2DA);
621 glDeleteTextures(1, &mTexture2DB);
622 TexCoordDrawTest::TearDown();
623 }
624
625 void testSamplerArrayDraw()
626 {
627 GLubyte texData[4];
628 texData[0] = 0;
629 texData[1] = 60;
630 texData[2] = 0;
631 texData[3] = 255;
632
633 glActiveTexture(GL_TEXTURE0);
634 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
635 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
636
637 texData[1] = 120;
638 glActiveTexture(GL_TEXTURE1);
639 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
640 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
641 EXPECT_GL_ERROR(GL_NO_ERROR);
642
643 glUseProgram(mProgram);
644 glUniform1i(mTexture0UniformLocation, 0);
645 glUniform1i(mTexture1UniformLocation, 1);
646 drawQuad(mProgram, "position", 0.5f);
647 EXPECT_GL_NO_ERROR();
648
649 EXPECT_PIXEL_NEAR(0, 0, 0, 180, 0, 255, 2);
650 }
651
652 GLuint mTexture2DA;
653 GLuint mTexture2DB;
654 GLint mTexture0UniformLocation;
655 GLint mTexture1UniformLocation;
656};
657
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200658class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest
659{
660 protected:
661 SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {}
662
663 std::string getFragmentShaderSource() override
664 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300665 return
666 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200667 uniform highp sampler2D tex2DArray[2];
668 varying vec2 texcoord;
669
670 vec4 computeFragColor(highp sampler2D aTex2DArray[2])
671 {
672 return texture2D(aTex2DArray[0], texcoord) + texture2D(aTex2DArray[1], texcoord);
673 }
674
675 void main()
676 {
677 gl_FragColor = computeFragColor(tex2DArray);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300678 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200679 }
680};
681
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200682class Texture2DArrayTestES3 : public TexCoordDrawTest
683{
684 protected:
685 Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {}
686
687 std::string getVertexShaderSource() override
688 {
689 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400690 "#version 300 es\n"
691 "out vec2 texcoord;\n"
692 "in vec4 position;\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200693 "void main()\n"
694 "{\n"
695 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
696 " texcoord = (position.xy * 0.5) + 0.5;\n"
697 "}\n");
698 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400699
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200700 std::string getFragmentShaderSource() override
701 {
702 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400703 "#version 300 es\n"
704 "precision highp float;\n"
Olli Etuaho183d7e22015-11-20 15:59:09 +0200705 "uniform highp sampler2DArray tex2DArray;\n"
Jamie Madill2453dbc2015-07-14 11:35:42 -0400706 "in vec2 texcoord;\n"
707 "out vec4 fragColor;\n"
708 "void main()\n"
709 "{\n"
710 " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200711 "}\n");
712 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400713
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200714 void SetUp() override
715 {
716 TexCoordDrawTest::SetUp();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400717
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300718 setUpProgram();
719
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200720 mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray");
Jamie Madill2453dbc2015-07-14 11:35:42 -0400721 ASSERT_NE(-1, mTextureArrayLocation);
722
723 glGenTextures(1, &m2DArrayTexture);
724 ASSERT_GL_NO_ERROR();
725 }
726
727 void TearDown() override
728 {
729 glDeleteTextures(1, &m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200730 TexCoordDrawTest::TearDown();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400731 }
732
733 GLuint m2DArrayTexture;
Jamie Madill2453dbc2015-07-14 11:35:42 -0400734 GLint mTextureArrayLocation;
735};
736
Olli Etuahobce743a2016-01-15 17:18:28 +0200737class TextureSizeTextureArrayTest : public TexCoordDrawTest
738{
739 protected:
740 TextureSizeTextureArrayTest()
741 : TexCoordDrawTest(),
742 mTexture2DA(0),
743 mTexture2DB(0),
744 mTexture0Location(-1),
745 mTexture1Location(-1)
746 {
747 }
748
749 std::string getVertexShaderSource() override
750 {
Olli Etuaho5804dc82018-04-13 14:11:46 +0300751 return std::string(essl3_shaders::vs::Simple());
Olli Etuahobce743a2016-01-15 17:18:28 +0200752 }
753
754 std::string getFragmentShaderSource() override
755 {
756 return std::string(
757 "#version 300 es\n"
758 "precision highp float;\n"
759 "uniform highp sampler2D tex2DArray[2];\n"
760 "out vec4 fragColor;\n"
761 "void main()\n"
762 "{\n"
763 " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n"
764 " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n"
765 " fragColor = vec4(red, green, 0.0, 1.0);\n"
766 "}\n");
767 }
768
769 void SetUp() override
770 {
771 TexCoordDrawTest::SetUp();
772
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300773 setUpProgram();
774
Olli Etuahobce743a2016-01-15 17:18:28 +0200775 mTexture0Location = glGetUniformLocation(mProgram, "tex2DArray[0]");
776 ASSERT_NE(-1, mTexture0Location);
777 mTexture1Location = glGetUniformLocation(mProgram, "tex2DArray[1]");
778 ASSERT_NE(-1, mTexture1Location);
779
780 mTexture2DA = create2DTexture();
781 mTexture2DB = create2DTexture();
782 ASSERT_GL_NO_ERROR();
783 }
784
785 void TearDown() override
786 {
787 glDeleteTextures(1, &mTexture2DA);
788 glDeleteTextures(1, &mTexture2DB);
789 TexCoordDrawTest::TearDown();
790 }
791
792 GLuint mTexture2DA;
793 GLuint mTexture2DB;
794 GLint mTexture0Location;
795 GLint mTexture1Location;
796};
797
Olli Etuahoa314b612016-03-10 16:43:00 +0200798class Texture3DTestES3 : public TexCoordDrawTest
799{
800 protected:
801 Texture3DTestES3() : TexCoordDrawTest(), mTexture3D(0), mTexture3DUniformLocation(-1) {}
802
803 std::string getVertexShaderSource() override
804 {
805 return std::string(
806 "#version 300 es\n"
807 "out vec2 texcoord;\n"
808 "in vec4 position;\n"
809 "void main()\n"
810 "{\n"
811 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
812 " texcoord = (position.xy * 0.5) + 0.5;\n"
813 "}\n");
814 }
815
816 std::string getFragmentShaderSource() override
817 {
818 return std::string(
819 "#version 300 es\n"
820 "precision highp float;\n"
821 "uniform highp sampler3D tex3D;\n"
822 "in vec2 texcoord;\n"
823 "out vec4 fragColor;\n"
824 "void main()\n"
825 "{\n"
826 " fragColor = texture(tex3D, vec3(texcoord, 0.0));\n"
827 "}\n");
828 }
829
830 void SetUp() override
831 {
832 TexCoordDrawTest::SetUp();
833
834 glGenTextures(1, &mTexture3D);
835
836 setUpProgram();
837
838 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
839 ASSERT_NE(-1, mTexture3DUniformLocation);
840 }
841
842 void TearDown() override
843 {
844 glDeleteTextures(1, &mTexture3D);
845 TexCoordDrawTest::TearDown();
846 }
847
848 GLuint mTexture3D;
849 GLint mTexture3DUniformLocation;
850};
851
Olli Etuaho1a679902016-01-14 12:21:47 +0200852class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest
853{
854 protected:
855 ShadowSamplerPlusSampler3DTestES3()
856 : TexCoordDrawTest(),
857 mTextureShadow(0),
858 mTexture3D(0),
859 mTextureShadowUniformLocation(-1),
860 mTexture3DUniformLocation(-1),
861 mDepthRefUniformLocation(-1)
862 {
863 }
864
865 std::string getVertexShaderSource() override
866 {
867 return std::string(
868 "#version 300 es\n"
869 "out vec2 texcoord;\n"
870 "in vec4 position;\n"
871 "void main()\n"
872 "{\n"
873 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
874 " texcoord = (position.xy * 0.5) + 0.5;\n"
875 "}\n");
876 }
877
878 std::string getFragmentShaderSource() override
879 {
880 return std::string(
881 "#version 300 es\n"
882 "precision highp float;\n"
883 "uniform highp sampler2DShadow tex2DShadow;\n"
884 "uniform highp sampler3D tex3D;\n"
885 "in vec2 texcoord;\n"
886 "uniform float depthRef;\n"
887 "out vec4 fragColor;\n"
888 "void main()\n"
889 "{\n"
890 " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n"
891 " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n"
892 "}\n");
893 }
894
895 void SetUp() override
896 {
897 TexCoordDrawTest::SetUp();
898
899 glGenTextures(1, &mTexture3D);
900
901 glGenTextures(1, &mTextureShadow);
902 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
903 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
904
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300905 setUpProgram();
906
Olli Etuaho1a679902016-01-14 12:21:47 +0200907 mTextureShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
908 ASSERT_NE(-1, mTextureShadowUniformLocation);
909 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
910 ASSERT_NE(-1, mTexture3DUniformLocation);
911 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
912 ASSERT_NE(-1, mDepthRefUniformLocation);
913 }
914
915 void TearDown() override
916 {
917 glDeleteTextures(1, &mTextureShadow);
918 glDeleteTextures(1, &mTexture3D);
919 TexCoordDrawTest::TearDown();
920 }
921
922 GLuint mTextureShadow;
923 GLuint mTexture3D;
924 GLint mTextureShadowUniformLocation;
925 GLint mTexture3DUniformLocation;
926 GLint mDepthRefUniformLocation;
927};
928
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200929class SamplerTypeMixTestES3 : public TexCoordDrawTest
930{
931 protected:
932 SamplerTypeMixTestES3()
933 : TexCoordDrawTest(),
934 mTexture2D(0),
935 mTextureCube(0),
936 mTexture2DShadow(0),
937 mTextureCubeShadow(0),
938 mTexture2DUniformLocation(-1),
939 mTextureCubeUniformLocation(-1),
940 mTexture2DShadowUniformLocation(-1),
941 mTextureCubeShadowUniformLocation(-1),
942 mDepthRefUniformLocation(-1)
943 {
944 }
945
946 std::string getVertexShaderSource() override
947 {
948 return std::string(
949 "#version 300 es\n"
950 "out vec2 texcoord;\n"
951 "in vec4 position;\n"
952 "void main()\n"
953 "{\n"
954 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
955 " texcoord = (position.xy * 0.5) + 0.5;\n"
956 "}\n");
957 }
958
959 std::string getFragmentShaderSource() override
960 {
961 return std::string(
962 "#version 300 es\n"
963 "precision highp float;\n"
964 "uniform highp sampler2D tex2D;\n"
965 "uniform highp samplerCube texCube;\n"
966 "uniform highp sampler2DShadow tex2DShadow;\n"
967 "uniform highp samplerCubeShadow texCubeShadow;\n"
968 "in vec2 texcoord;\n"
969 "uniform float depthRef;\n"
970 "out vec4 fragColor;\n"
971 "void main()\n"
972 "{\n"
973 " fragColor = texture(tex2D, texcoord);\n"
974 " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n"
975 " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n"
976 " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * "
977 "0.125);\n"
978 "}\n");
979 }
980
981 void SetUp() override
982 {
983 TexCoordDrawTest::SetUp();
984
985 glGenTextures(1, &mTexture2D);
986 glGenTextures(1, &mTextureCube);
987
988 glGenTextures(1, &mTexture2DShadow);
989 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
990 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
991
992 glGenTextures(1, &mTextureCubeShadow);
993 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
994 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
995
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300996 setUpProgram();
997
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200998 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
999 ASSERT_NE(-1, mTexture2DUniformLocation);
1000 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
1001 ASSERT_NE(-1, mTextureCubeUniformLocation);
1002 mTexture2DShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
1003 ASSERT_NE(-1, mTexture2DShadowUniformLocation);
1004 mTextureCubeShadowUniformLocation = glGetUniformLocation(mProgram, "texCubeShadow");
1005 ASSERT_NE(-1, mTextureCubeShadowUniformLocation);
1006 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
1007 ASSERT_NE(-1, mDepthRefUniformLocation);
1008
1009 ASSERT_GL_NO_ERROR();
1010 }
1011
1012 void TearDown() override
1013 {
1014 glDeleteTextures(1, &mTexture2D);
1015 glDeleteTextures(1, &mTextureCube);
1016 glDeleteTextures(1, &mTexture2DShadow);
1017 glDeleteTextures(1, &mTextureCubeShadow);
1018 TexCoordDrawTest::TearDown();
1019 }
1020
1021 GLuint mTexture2D;
1022 GLuint mTextureCube;
1023 GLuint mTexture2DShadow;
1024 GLuint mTextureCubeShadow;
1025 GLint mTexture2DUniformLocation;
1026 GLint mTextureCubeUniformLocation;
1027 GLint mTexture2DShadowUniformLocation;
1028 GLint mTextureCubeShadowUniformLocation;
1029 GLint mDepthRefUniformLocation;
1030};
1031
Olli Etuaho96963162016-03-21 11:54:33 +02001032class SamplerInStructTest : public Texture2DTest
1033{
1034 protected:
1035 SamplerInStructTest() : Texture2DTest() {}
1036
1037 const char *getTextureUniformName() override { return "us.tex"; }
1038
1039 std::string getFragmentShaderSource() override
1040 {
1041 return std::string(
1042 "precision highp float;\n"
1043 "struct S\n"
1044 "{\n"
1045 " vec4 a;\n"
1046 " highp sampler2D tex;\n"
1047 "};\n"
1048 "uniform S us;\n"
1049 "varying vec2 texcoord;\n"
1050 "void main()\n"
1051 "{\n"
1052 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x);\n"
1053 "}\n");
1054 }
1055
1056 void runSamplerInStructTest()
1057 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001058 setUpProgram();
1059
Olli Etuaho96963162016-03-21 11:54:33 +02001060 glActiveTexture(GL_TEXTURE0);
1061 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001062 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1063 &GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001064 drawQuad(mProgram, "position", 0.5f);
Olli Etuahoa314b612016-03-10 16:43:00 +02001065 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001066 }
1067};
1068
1069class SamplerInStructAsFunctionParameterTest : public SamplerInStructTest
1070{
1071 protected:
1072 SamplerInStructAsFunctionParameterTest() : SamplerInStructTest() {}
1073
1074 std::string getFragmentShaderSource() override
1075 {
1076 return std::string(
1077 "precision highp float;\n"
1078 "struct S\n"
1079 "{\n"
1080 " vec4 a;\n"
1081 " highp sampler2D tex;\n"
1082 "};\n"
1083 "uniform S us;\n"
1084 "varying vec2 texcoord;\n"
1085 "vec4 sampleFrom(S s) {\n"
1086 " return texture2D(s.tex, texcoord + s.a.x);\n"
1087 "}\n"
1088 "void main()\n"
1089 "{\n"
1090 " gl_FragColor = sampleFrom(us);\n"
1091 "}\n");
1092 }
1093};
1094
1095class SamplerInStructArrayAsFunctionParameterTest : public SamplerInStructTest
1096{
1097 protected:
1098 SamplerInStructArrayAsFunctionParameterTest() : SamplerInStructTest() {}
1099
1100 const char *getTextureUniformName() override { return "us[0].tex"; }
1101
1102 std::string getFragmentShaderSource() override
1103 {
1104 return std::string(
1105 "precision highp float;\n"
1106 "struct S\n"
1107 "{\n"
1108 " vec4 a;\n"
1109 " highp sampler2D tex;\n"
1110 "};\n"
1111 "uniform S us[1];\n"
1112 "varying vec2 texcoord;\n"
1113 "vec4 sampleFrom(S s) {\n"
1114 " return texture2D(s.tex, texcoord + s.a.x);\n"
1115 "}\n"
1116 "void main()\n"
1117 "{\n"
1118 " gl_FragColor = sampleFrom(us[0]);\n"
1119 "}\n");
1120 }
1121};
1122
1123class SamplerInNestedStructAsFunctionParameterTest : public SamplerInStructTest
1124{
1125 protected:
1126 SamplerInNestedStructAsFunctionParameterTest() : SamplerInStructTest() {}
1127
1128 const char *getTextureUniformName() override { return "us[0].sub.tex"; }
1129
1130 std::string getFragmentShaderSource() override
1131 {
1132 return std::string(
1133 "precision highp float;\n"
1134 "struct SUB\n"
1135 "{\n"
1136 " vec4 a;\n"
1137 " highp sampler2D tex;\n"
1138 "};\n"
1139 "struct S\n"
1140 "{\n"
1141 " SUB sub;\n"
1142 "};\n"
1143 "uniform S us[1];\n"
1144 "varying vec2 texcoord;\n"
1145 "vec4 sampleFrom(SUB s) {\n"
1146 " return texture2D(s.tex, texcoord + s.a.x);\n"
1147 "}\n"
1148 "void main()\n"
1149 "{\n"
1150 " gl_FragColor = sampleFrom(us[0].sub);\n"
1151 "}\n");
1152 }
1153};
1154
1155class SamplerInStructAndOtherVariableTest : public SamplerInStructTest
1156{
1157 protected:
1158 SamplerInStructAndOtherVariableTest() : SamplerInStructTest() {}
1159
1160 std::string getFragmentShaderSource() override
1161 {
1162 return std::string(
1163 "precision highp float;\n"
1164 "struct S\n"
1165 "{\n"
1166 " vec4 a;\n"
1167 " highp sampler2D tex;\n"
1168 "};\n"
1169 "uniform S us;\n"
1170 "uniform float us_tex;\n"
1171 "varying vec2 texcoord;\n"
1172 "void main()\n"
1173 "{\n"
1174 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x + us_tex);\n"
1175 "}\n");
1176 }
1177};
1178
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001179TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001180{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001181 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001182 EXPECT_GL_ERROR(GL_NO_ERROR);
1183
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001184 setUpProgram();
1185
Jamie Madill50cf2be2018-06-15 09:46:57 -04001186 const GLubyte *pixels[20] = {0};
Jamie Madillf67115c2014-04-22 13:14:05 -04001187 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1188 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001189
1190 if (extensionEnabled("GL_EXT_texture_storage"))
1191 {
1192 // Create a 1-level immutable texture.
1193 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1194
1195 // Try calling sub image on the second level.
1196 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1197 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1198 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001199}
Geoff Langc41e42d2014-04-28 10:58:16 -04001200
John Bauman18319182016-09-28 14:22:27 -07001201// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1202TEST_P(Texture2DTest, QueryBinding)
1203{
1204 glBindTexture(GL_TEXTURE_2D, 0);
1205 EXPECT_GL_ERROR(GL_NO_ERROR);
1206
1207 GLint textureBinding;
1208 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1209 EXPECT_GL_NO_ERROR();
1210 EXPECT_EQ(0, textureBinding);
1211
1212 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
1213 if (extensionEnabled("GL_OES_EGL_image_external") ||
1214 extensionEnabled("GL_NV_EGL_stream_consumer_external"))
1215 {
1216 EXPECT_GL_NO_ERROR();
1217 EXPECT_EQ(0, textureBinding);
1218 }
1219 else
1220 {
1221 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1222 }
1223}
1224
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001225TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001226{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001227 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001228 EXPECT_GL_ERROR(GL_NO_ERROR);
1229
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001230 setUpProgram();
1231
Geoff Langc41e42d2014-04-28 10:58:16 -04001232 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001233 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001234 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001235 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001236
Jamie Madill50cf2be2018-06-15 09:46:57 -04001237 const GLubyte *pixel[4] = {0};
Geoff Langc41e42d2014-04-28 10:58:16 -04001238
1239 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1240 EXPECT_GL_NO_ERROR();
1241
1242 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1243 EXPECT_GL_NO_ERROR();
1244
1245 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1246 EXPECT_GL_NO_ERROR();
1247}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001248
1249// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001250TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001251{
1252 glActiveTexture(GL_TEXTURE0);
1253 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1254 glActiveTexture(GL_TEXTURE1);
1255 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1256 EXPECT_GL_ERROR(GL_NO_ERROR);
1257
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001258 glUseProgram(mProgram);
1259 glUniform1i(mTexture2DUniformLocation, 0);
1260 glUniform1i(mTextureCubeUniformLocation, 1);
1261 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001262 EXPECT_GL_NO_ERROR();
1263}
Jamie Madill9aca0592014-10-06 16:26:59 -04001264
Olli Etuaho53a2da12016-01-11 15:43:32 +02001265// Test drawing with two texture types accessed from the same shader and check that the result of
1266// drawing is correct.
1267TEST_P(TextureCubeTest, CubeMapDraw)
1268{
1269 GLubyte texData[4];
1270 texData[0] = 0;
1271 texData[1] = 60;
1272 texData[2] = 0;
1273 texData[3] = 255;
1274
1275 glActiveTexture(GL_TEXTURE0);
1276 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1277 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1278
1279 glActiveTexture(GL_TEXTURE1);
1280 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1281 texData[1] = 120;
1282 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1283 texData);
1284 EXPECT_GL_ERROR(GL_NO_ERROR);
1285
1286 glUseProgram(mProgram);
1287 glUniform1i(mTexture2DUniformLocation, 0);
1288 glUniform1i(mTextureCubeUniformLocation, 1);
1289 drawQuad(mProgram, "position", 0.5f);
1290 EXPECT_GL_NO_ERROR();
1291
1292 int px = getWindowWidth() - 1;
1293 int py = 0;
1294 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1295}
1296
Olli Etuaho4644a202016-01-12 15:12:53 +02001297TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1298{
1299 glActiveTexture(GL_TEXTURE0);
1300 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1301 GLubyte texData[4];
1302 texData[0] = 0;
1303 texData[1] = 128;
1304 texData[2] = 0;
1305 texData[3] = 255;
1306 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1307 glUseProgram(mProgram);
1308 glUniform1i(mTexture2DUniformLocation, 0);
1309 drawQuad(mProgram, "position", 0.5f);
1310 EXPECT_GL_NO_ERROR();
1311
1312 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1313}
1314
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001315// Test drawing with two textures passed to the shader in a sampler array.
1316TEST_P(SamplerArrayTest, SamplerArrayDraw)
1317{
1318 testSamplerArrayDraw();
1319}
1320
1321// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1322// user-defined function in the shader.
1323TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1324{
1325 testSamplerArrayDraw();
1326}
1327
Jamie Madill9aca0592014-10-06 16:26:59 -04001328// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001329TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001330{
1331 int px = getWindowWidth() / 2;
1332 int py = getWindowHeight() / 2;
1333
1334 glActiveTexture(GL_TEXTURE0);
1335 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1336
Olli Etuahoa314b612016-03-10 16:43:00 +02001337 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001338
Olli Etuahoa314b612016-03-10 16:43:00 +02001339 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001340 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1341 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1342 glGenerateMipmap(GL_TEXTURE_2D);
1343
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001344 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001345 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001346 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1347 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001348 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001349 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001350
Olli Etuahoa314b612016-03-10 16:43:00 +02001351 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001352
Olli Etuahoa314b612016-03-10 16:43:00 +02001353 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1354 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001355 glGenerateMipmap(GL_TEXTURE_2D);
1356
Olli Etuahoa314b612016-03-10 16:43:00 +02001357 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001358
Olli Etuahoa314b612016-03-10 16:43:00 +02001359 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1360 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001361 glGenerateMipmap(GL_TEXTURE_2D);
1362
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001363 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001364
1365 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001366 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001367}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001368
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001369// Test creating a FBO with a cube map render target, to test an ANGLE bug
1370// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001371TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001372{
Jamie Madill3f3b3582018-09-14 10:38:44 -04001373 GLFramebuffer fbo;
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001374 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1375
1376 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Jamie Madill50cf2be2018-06-15 09:46:57 -04001377 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1378 mTextureCube, 0);
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001379
Corentin Wallez322653b2015-06-17 18:33:56 +02001380 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001381 EXPECT_GL_NO_ERROR();
Jamie Madill3f3b3582018-09-14 10:38:44 -04001382
1383 // Test clearing the six mip faces individually.
1384 std::array<GLColor, 6> faceColors = {{GLColor::red, GLColor::green, GLColor::blue,
1385 GLColor::yellow, GLColor::cyan, GLColor::magenta}};
1386
1387 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1388 {
1389 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1390 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1391
1392 Vector4 clearColorF = faceColors[faceIndex].toNormalizedVector();
1393 glClearColor(clearColorF.x(), clearColorF.y(), clearColorF.z(), clearColorF.w());
1394 glClear(GL_COLOR_BUFFER_BIT);
1395
1396 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex]);
1397 }
1398
1399 // Iterate the faces again to make sure the colors haven't changed.
1400 for (size_t faceIndex = 0; faceIndex < 6; ++faceIndex)
1401 {
1402 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1403 GL_TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, mTextureCube, 0);
1404 EXPECT_PIXEL_COLOR_EQ(0, 0, faceColors[faceIndex])
1405 << "face color " << faceIndex << " shouldn't change";
1406 }
1407}
1408
1409// Tests clearing a cube map with a scissor enabled.
1410TEST_P(TextureCubeTest, CubeMapFBOScissoredClear)
1411{
1412 // TODO(jie.a.chen): Diagnose and fix. http://anglebug.com/2822
1413 ANGLE_SKIP_TEST_IF(IsVulkan() && IsIntel() && IsWindows());
1414
1415 constexpr size_t kSize = 16;
1416
1417 GLFramebuffer fbo;
1418 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1419 glViewport(0, 0, kSize, kSize);
1420
1421 GLTexture texcube;
1422 glBindTexture(GL_TEXTURE_CUBE_MAP, texcube);
1423 for (GLenum face = 0; face < 6; face++)
1424 {
1425 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA,
1426 GL_UNSIGNED_BYTE, nullptr);
1427 }
1428 ASSERT_GL_NO_ERROR();
1429
1430 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1431 texcube, 0);
1432
1433 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1434 ASSERT_GL_NO_ERROR();
1435
1436 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1437 glClear(GL_COLOR_BUFFER_BIT);
1438 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1439
1440 glEnable(GL_SCISSOR_TEST);
1441 glScissor(kSize / 2, 0, kSize / 2, kSize);
1442 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
1443 glClear(GL_COLOR_BUFFER_BIT);
1444
1445 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1446 EXPECT_PIXEL_COLOR_EQ(kSize / 2 + 1, 0, GLColor::green);
1447
1448 ASSERT_GL_NO_ERROR();
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001449}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001450
Jamie Madill50cf2be2018-06-15 09:46:57 -04001451// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a
1452// default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001453TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001454{
Luc Ferron7348fc52018-05-09 07:17:16 -04001455 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -04001456
Jamie Madill50cf2be2018-06-15 09:46:57 -04001457 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001458 int height = getWindowHeight();
1459
1460 GLuint tex2D;
1461 glGenTextures(1, &tex2D);
1462 glActiveTexture(GL_TEXTURE0);
1463 glBindTexture(GL_TEXTURE_2D, tex2D);
1464
1465 // Fill with red
1466 std::vector<GLubyte> pixels(3 * 16 * 16);
1467 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1468 {
1469 pixels[pixelId * 3 + 0] = 255;
1470 pixels[pixelId * 3 + 1] = 0;
1471 pixels[pixelId * 3 + 2] = 0;
1472 }
1473
1474 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001475 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1476 // 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 -04001477 if (getClientMajorVersion() >= 3)
1478 {
1479 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1480 }
1481 else
1482 {
1483 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1484 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001485
1486 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1487 // glTexSubImage2D should take into account that the image is dirty.
1488 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1489 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1490 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1491
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001492 setUpProgram();
1493
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001494 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001495 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001496 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001497 glDeleteTextures(1, &tex2D);
1498 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001499 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001500
1501 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001502 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1503 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001504}
1505
Jamie Madill50cf2be2018-06-15 09:46:57 -04001506// Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has
1507// initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001508TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001509{
1510 if (extensionEnabled("NV_pixel_buffer_object"))
1511 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04001512 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001513 int height = getWindowHeight();
1514
1515 GLuint tex2D;
1516 glGenTextures(1, &tex2D);
1517 glActiveTexture(GL_TEXTURE0);
1518 glBindTexture(GL_TEXTURE_2D, tex2D);
1519
1520 // Fill with red
1521 std::vector<GLubyte> pixels(3 * 16 * 16);
1522 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1523 {
1524 pixels[pixelId * 3 + 0] = 255;
1525 pixels[pixelId * 3 + 1] = 0;
1526 pixels[pixelId * 3 + 2] = 0;
1527 }
1528
1529 // Read 16x16 region from red backbuffer to PBO
1530 GLuint pbo;
1531 glGenBuffers(1, &pbo);
1532 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1533 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1534
1535 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001536 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1537 // 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 +00001538 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1539
1540 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1541 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001542 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 +00001543 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1544 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1545
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001546 setUpProgram();
1547
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001548 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001549 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001550 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001551 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001552 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001553 EXPECT_GL_NO_ERROR();
1554 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1555 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1556 }
1557}
Jamie Madillbc393df2015-01-29 13:46:07 -05001558
1559// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001560TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001561{
1562 testFloatCopySubImage(1, 1);
1563}
1564
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001565TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001566{
1567 testFloatCopySubImage(2, 1);
1568}
1569
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001570TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001571{
1572 testFloatCopySubImage(2, 2);
1573}
1574
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001575TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001576{
1577 testFloatCopySubImage(3, 1);
1578}
1579
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001580TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001581{
1582 testFloatCopySubImage(3, 2);
1583}
1584
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001585TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001586{
Yunchao He9550c602018-02-13 14:47:05 +08001587 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1588 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001589
Yunchao He9550c602018-02-13 14:47:05 +08001590 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1591 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001592
Jamie Madillbc393df2015-01-29 13:46:07 -05001593 testFloatCopySubImage(3, 3);
1594}
1595
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001596TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001597{
1598 testFloatCopySubImage(4, 1);
1599}
1600
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001601TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001602{
1603 testFloatCopySubImage(4, 2);
1604}
1605
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001606TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001607{
Yunchao He9550c602018-02-13 14:47:05 +08001608 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1609 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001610
Jamie Madillbc393df2015-01-29 13:46:07 -05001611 testFloatCopySubImage(4, 3);
1612}
1613
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001614TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001615{
Luc Ferronf786b702018-07-10 11:01:43 -04001616 // TODO(lucferron): This test fails only on linux and intel.
1617 // http://anglebug.com/2726
1618 ANGLE_SKIP_TEST_IF(IsVulkan() && IsLinux() && IsIntel());
1619
Yunchao He9550c602018-02-13 14:47:05 +08001620 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1621 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001622
Jamie Madillbc393df2015-01-29 13:46:07 -05001623 testFloatCopySubImage(4, 4);
1624}
Austin Kinross07285142015-03-26 11:36:16 -07001625
Jamie Madill50cf2be2018-06-15 09:46:57 -04001626// Port of
1627// https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1628// Run against GL_ALPHA/UNSIGNED_BYTE format, to ensure that D3D11 Feature Level 9_3 correctly
1629// handles GL_ALPHA
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001630TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001631{
1632 const int npotTexSize = 5;
Jamie Madill50cf2be2018-06-15 09:46:57 -04001633 const int potTexSize = 4; // Should be less than npotTexSize
Austin Kinross07285142015-03-26 11:36:16 -07001634 GLuint tex2D;
1635
1636 if (extensionEnabled("GL_OES_texture_npot"))
1637 {
1638 // This test isn't applicable if texture_npot is enabled
1639 return;
1640 }
1641
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001642 setUpProgram();
1643
Austin Kinross07285142015-03-26 11:36:16 -07001644 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1645
Austin Kinross5faa15b2016-01-11 13:32:48 -08001646 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1647 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1648
Austin Kinross07285142015-03-26 11:36:16 -07001649 glActiveTexture(GL_TEXTURE0);
1650 glGenTextures(1, &tex2D);
1651 glBindTexture(GL_TEXTURE_2D, tex2D);
1652
Till Rathmannc1551dc2018-08-15 17:04:49 +02001653 const std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize, 64);
Austin Kinross07285142015-03-26 11:36:16 -07001654
1655 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1656 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1657
1658 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
Jamie Madill50cf2be2018-06-15 09:46:57 -04001659 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1660 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001661 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1662
1663 // Check that an NPOT texture on level 0 succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001664 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1665 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001666 EXPECT_GL_NO_ERROR();
1667
1668 // Check that generateMipmap fails on NPOT
1669 glGenerateMipmap(GL_TEXTURE_2D);
1670 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1671
1672 // Check that nothing is drawn if filtering is not correct for NPOT
1673 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1674 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1675 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1676 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1677 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001678 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001679 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1680
1681 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1682 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1683 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1684 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1685 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001686 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001687 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1688
1689 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1690 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1691 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001692 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001693 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1694
1695 // Check that glTexImage2D for POT texture succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001696 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE,
1697 pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001698 EXPECT_GL_NO_ERROR();
1699
1700 // Check that generateMipmap for an POT texture succeeds
1701 glGenerateMipmap(GL_TEXTURE_2D);
1702 EXPECT_GL_NO_ERROR();
1703
1704 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1705 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1706 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1707 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1708 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1709 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001710 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001711 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1712 EXPECT_GL_NO_ERROR();
1713}
Jamie Madillfa05f602015-05-07 13:47:11 -04001714
Austin Kinross08528e12015-10-07 16:24:40 -07001715// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1716// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001717TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001718{
1719 glActiveTexture(GL_TEXTURE0);
1720 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1721
1722 // Create an 8x8 (i.e. power-of-two) texture.
1723 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1724 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1725 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1726 glGenerateMipmap(GL_TEXTURE_2D);
1727
1728 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1729 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001730 std::array<GLColor, 3 * 3> data;
1731 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001732
1733 EXPECT_GL_NO_ERROR();
1734}
1735
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001736// Test to check that texture completeness is determined correctly when the texture base level is
1737// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1738TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1739{
1740 glActiveTexture(GL_TEXTURE0);
1741 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001742
1743 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1744 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1745 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1746 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1747 texDataGreen.data());
1748 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1749 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001750 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1751 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1752 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1753
1754 EXPECT_GL_NO_ERROR();
1755
1756 drawQuad(mProgram, "position", 0.5f);
1757
Olli Etuahoa314b612016-03-10 16:43:00 +02001758 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1759}
1760
1761// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1762// have images defined.
1763TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1764{
Yunchao He9550c602018-02-13 14:47:05 +08001765 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1766 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1767
Olli Etuahoa314b612016-03-10 16:43:00 +02001768 glActiveTexture(GL_TEXTURE0);
1769 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1770 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1771 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1772 texDataGreen.data());
1773 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1774 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1775 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1776 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1777
1778 EXPECT_GL_NO_ERROR();
1779
1780 drawQuad(mProgram, "position", 0.5f);
1781
1782 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1783}
1784
Olli Etuahoe8528d82016-05-16 17:50:52 +03001785// Test that drawing works correctly when level 0 is undefined and base level is 1.
1786TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1787{
Yunchao He9550c602018-02-13 14:47:05 +08001788 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1789 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1790
Olli Etuahoe8528d82016-05-16 17:50:52 +03001791 glActiveTexture(GL_TEXTURE0);
1792 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1793 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1794 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1795 texDataGreen.data());
1796 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1797 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1798 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1799 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1800
1801 EXPECT_GL_NO_ERROR();
1802
1803 // Texture is incomplete.
1804 drawQuad(mProgram, "position", 0.5f);
1805 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1806
1807 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1808 texDataGreen.data());
1809
1810 // Texture is now complete.
1811 drawQuad(mProgram, "position", 0.5f);
1812 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1813}
1814
Olli Etuahoa314b612016-03-10 16:43:00 +02001815// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1816// dimensions that don't fit the images inside the range.
1817// GLES 3.0.4 section 3.8.13 Texture completeness
1818TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1819{
Olli Etuahoa314b612016-03-10 16:43:00 +02001820 glActiveTexture(GL_TEXTURE0);
1821 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1822 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1823 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1824 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1825
1826 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1827 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1828
1829 // Two levels that are initially unused.
1830 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1831 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1832 texDataCyan.data());
1833
1834 // One level that is used - only this level should affect completeness.
1835 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1836 texDataGreen.data());
1837
1838 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1839 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1840
1841 EXPECT_GL_NO_ERROR();
1842
1843 drawQuad(mProgram, "position", 0.5f);
1844
1845 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1846
Yunchao He2f23f352018-02-11 22:11:37 +08001847 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001848
1849 // Switch the level that is being used to the cyan level 2.
1850 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1851 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1852
1853 EXPECT_GL_NO_ERROR();
1854
1855 drawQuad(mProgram, "position", 0.5f);
1856
1857 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1858}
1859
1860// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1861// have images defined.
1862TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1863{
Olli Etuahoa314b612016-03-10 16:43:00 +02001864 glActiveTexture(GL_TEXTURE0);
1865 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1866 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1867 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1868 texDataGreen.data());
1869 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1870 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1871 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1872 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1873
1874 EXPECT_GL_NO_ERROR();
1875
1876 drawQuad(mProgram, "position", 0.5f);
1877
1878 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1879}
1880
1881// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1882// dimensions that don't fit the images inside the range.
1883// GLES 3.0.4 section 3.8.13 Texture completeness
1884TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1885{
Olli Etuahoa314b612016-03-10 16:43:00 +02001886 glActiveTexture(GL_TEXTURE0);
1887 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1888 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1889 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1890 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1891
1892 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1893 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1894
1895 // Two levels that are initially unused.
1896 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1897 texDataRed.data());
1898 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1899 texDataCyan.data());
1900
1901 // One level that is used - only this level should affect completeness.
1902 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1903 texDataGreen.data());
1904
1905 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1906 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1907
1908 EXPECT_GL_NO_ERROR();
1909
1910 drawQuad(mProgram, "position", 0.5f);
1911
1912 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1913
Yunchao He2f23f352018-02-11 22:11:37 +08001914 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001915
1916 // Switch the level that is being used to the cyan level 2.
1917 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
1918 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
1919
1920 EXPECT_GL_NO_ERROR();
1921
1922 drawQuad(mProgram, "position", 0.5f);
1923
1924 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1925}
1926
1927// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1928// have images defined.
1929TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
1930{
Olli Etuahoa314b612016-03-10 16:43:00 +02001931 glActiveTexture(GL_TEXTURE0);
1932 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
1933 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1934 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1935 texDataGreen.data());
1936 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1937 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1938 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1939 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1940
1941 EXPECT_GL_NO_ERROR();
1942
1943 drawQuad(mProgram, "position", 0.5f);
1944
1945 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1946}
1947
1948// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1949// dimensions that don't fit the images inside the range.
1950// GLES 3.0.4 section 3.8.13 Texture completeness
1951TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1952{
Olli Etuahoa314b612016-03-10 16:43:00 +02001953 glActiveTexture(GL_TEXTURE0);
1954 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
1955 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1956 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1957 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1958
1959 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1960 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1961
1962 // Two levels that are initially unused.
1963 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1964 texDataRed.data());
1965 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1966 texDataCyan.data());
1967
1968 // One level that is used - only this level should affect completeness.
1969 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1970 texDataGreen.data());
1971
1972 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1973 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1974
1975 EXPECT_GL_NO_ERROR();
1976
1977 drawQuad(mProgram, "position", 0.5f);
1978
1979 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1980
Yunchao He2f23f352018-02-11 22:11:37 +08001981 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
1982
Yunchao He9550c602018-02-13 14:47:05 +08001983 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
1984 // level was changed.
1985 ANGLE_SKIP_TEST_IF(IsNVIDIA() && (IsOpenGL() || IsOpenGLES()));
Olli Etuahoa314b612016-03-10 16:43:00 +02001986
1987 // Switch the level that is being used to the cyan level 2.
1988 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
1989 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
1990
1991 EXPECT_GL_NO_ERROR();
1992
1993 drawQuad(mProgram, "position", 0.5f);
1994
1995 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1996}
1997
1998// Test that texture completeness is updated if texture max level changes.
1999// GLES 3.0.4 section 3.8.13 Texture completeness
2000TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2001{
Olli Etuahoa314b612016-03-10 16:43:00 +02002002 glActiveTexture(GL_TEXTURE0);
2003 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2004 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2005
2006 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2007 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2008
2009 // A level that is initially unused.
2010 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2011 texDataGreen.data());
2012
2013 // One level that is initially used - only this level should affect completeness.
2014 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2015 texDataGreen.data());
2016
2017 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2018 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2019
2020 EXPECT_GL_NO_ERROR();
2021
2022 drawQuad(mProgram, "position", 0.5f);
2023
2024 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2025
2026 // Switch the max level to level 1. The levels within the used range now have inconsistent
2027 // dimensions and the texture should be incomplete.
2028 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2029
2030 EXPECT_GL_NO_ERROR();
2031
2032 drawQuad(mProgram, "position", 0.5f);
2033
2034 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2035}
2036
2037// Test that 3D texture completeness is updated if texture max level changes.
2038// GLES 3.0.4 section 3.8.13 Texture completeness
2039TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2040{
Olli Etuahoa314b612016-03-10 16:43:00 +02002041 glActiveTexture(GL_TEXTURE0);
2042 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2043 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2044
2045 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2046 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2047
2048 // A level that is initially unused.
2049 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2050 texDataGreen.data());
2051
2052 // One level that is initially used - only this level should affect completeness.
2053 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2054 texDataGreen.data());
2055
2056 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2057 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2058
2059 EXPECT_GL_NO_ERROR();
2060
2061 drawQuad(mProgram, "position", 0.5f);
2062
2063 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2064
2065 // Switch the max level to level 1. The levels within the used range now have inconsistent
2066 // dimensions and the texture should be incomplete.
2067 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2068
2069 EXPECT_GL_NO_ERROR();
2070
2071 drawQuad(mProgram, "position", 0.5f);
2072
2073 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2074}
2075
2076// Test that texture completeness is updated if texture base level changes.
2077// GLES 3.0.4 section 3.8.13 Texture completeness
2078TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2079{
Olli Etuahoa314b612016-03-10 16:43:00 +02002080 glActiveTexture(GL_TEXTURE0);
2081 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2082 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2083
2084 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2085 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2086
2087 // Two levels that are initially unused.
2088 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2089 texDataGreen.data());
2090 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2091 texDataGreen.data());
2092
2093 // One level that is initially used - only this level should affect completeness.
2094 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2095 texDataGreen.data());
2096
2097 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2098 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2099
2100 EXPECT_GL_NO_ERROR();
2101
2102 drawQuad(mProgram, "position", 0.5f);
2103
2104 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2105
2106 // Switch the base level to level 1. The levels within the used range now have inconsistent
2107 // dimensions and the texture should be incomplete.
2108 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2109
2110 EXPECT_GL_NO_ERROR();
2111
2112 drawQuad(mProgram, "position", 0.5f);
2113
2114 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2115}
2116
2117// Test that texture is not complete if base level is greater than max level.
2118// GLES 3.0.4 section 3.8.13 Texture completeness
2119TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2120{
Olli Etuahoa314b612016-03-10 16:43:00 +02002121 glActiveTexture(GL_TEXTURE0);
2122 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2123
2124 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2125 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2126
2127 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2128
2129 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2130 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2131
2132 EXPECT_GL_NO_ERROR();
2133
2134 drawQuad(mProgram, "position", 0.5f);
2135
2136 // Texture should be incomplete.
2137 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2138}
2139
2140// Test that immutable texture base level and max level are clamped.
2141// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2142TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2143{
Olli Etuahoa314b612016-03-10 16:43:00 +02002144 glActiveTexture(GL_TEXTURE0);
2145 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2146
2147 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2148 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2149
2150 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2151
2152 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2153
2154 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2155 // should be clamped to [base_level, levels - 1].
2156 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2157 // In the case of this test, those rules make the effective base level and max level 0.
2158 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2159 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2160
2161 EXPECT_GL_NO_ERROR();
2162
2163 drawQuad(mProgram, "position", 0.5f);
2164
2165 // Texture should be complete.
2166 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2167}
2168
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002169// Test that changing base level works when it affects the format of the texture.
2170TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2171{
Yunchao He9550c602018-02-13 14:47:05 +08002172 // Observed rendering corruption on NVIDIA OpenGL.
2173 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL());
2174
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002175 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002176
2177 // Observed incorrect rendering on AMD OpenGL.
2178 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002179
2180 glActiveTexture(GL_TEXTURE0);
2181 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2182 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2183 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2184
2185 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2186 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2187
2188 // RGBA8 level that's initially unused.
2189 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2190 texDataCyan.data());
2191
2192 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2193 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2194
2195 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2196 // format. It reads green channel data from the green and alpha channels of texDataGreen
2197 // (this is a bit hacky but works).
2198 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2199
2200 EXPECT_GL_NO_ERROR();
2201
2202 drawQuad(mProgram, "position", 0.5f);
2203
2204 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2205
2206 // Switch the texture to use the cyan level 0 with the RGBA format.
2207 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2208 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2209
2210 EXPECT_GL_NO_ERROR();
2211
2212 drawQuad(mProgram, "position", 0.5f);
2213
2214 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2215}
2216
Olli Etuahoa314b612016-03-10 16:43:00 +02002217// Test that setting a texture image works when base level is out of range.
2218TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2219{
2220 glActiveTexture(GL_TEXTURE0);
2221 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2222
2223 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2224 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2225
2226 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2227 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2228
2229 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2230
2231 EXPECT_GL_NO_ERROR();
2232
2233 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2234
2235 drawQuad(mProgram, "position", 0.5f);
2236
2237 // Texture should be complete.
2238 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002239}
2240
Jamie Madill50cf2be2018-06-15 09:46:57 -04002241// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG
2242// RBA->RGBA8, with 1.0 in the alpha channel. This test covers a bug where redefining array textures
2243// with these formats does not work as expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002244TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002245{
2246 std::vector<GLubyte> pixelData;
2247 for (size_t count = 0; count < 5000; count++)
2248 {
2249 pixelData.push_back(0u);
2250 pixelData.push_back(255u);
2251 pixelData.push_back(0u);
2252 }
2253
2254 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002255 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002256 glUniform1i(mTextureArrayLocation, 0);
2257
2258 // The first draw worked correctly.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002259 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2260 &pixelData[0]);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002261
2262 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2263 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2264 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2265 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002266 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002267 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002268
2269 // The dimension of the respecification must match the original exactly to trigger the bug.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002270 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2271 &pixelData[0]);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002272 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002273 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002274
2275 ASSERT_GL_NO_ERROR();
2276}
2277
Olli Etuaho1a679902016-01-14 12:21:47 +02002278// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2279// This test is needed especially to confirm that sampler registers get assigned correctly on
2280// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2281TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2282{
2283 glActiveTexture(GL_TEXTURE0);
2284 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2285 GLubyte texData[4];
2286 texData[0] = 0;
2287 texData[1] = 60;
2288 texData[2] = 0;
2289 texData[3] = 255;
2290 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2291
2292 glActiveTexture(GL_TEXTURE1);
2293 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2294 GLfloat depthTexData[1];
2295 depthTexData[0] = 0.5f;
2296 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2297 depthTexData);
2298
2299 glUseProgram(mProgram);
2300 glUniform1f(mDepthRefUniformLocation, 0.3f);
2301 glUniform1i(mTexture3DUniformLocation, 0);
2302 glUniform1i(mTextureShadowUniformLocation, 1);
2303
2304 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2305 drawQuad(mProgram, "position", 0.5f);
2306 EXPECT_GL_NO_ERROR();
2307 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2308 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2309
2310 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2311 drawQuad(mProgram, "position", 0.5f);
2312 EXPECT_GL_NO_ERROR();
2313 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2314 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2315}
2316
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002317// Test multiple different sampler types in the same shader.
2318// This test makes sure that even if sampler / texture registers get grouped together based on type
2319// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2320// still has the right register index information for each ESSL sampler.
2321// The tested ESSL samplers have the following types in D3D11 HLSL:
2322// sampler2D: Texture2D + SamplerState
2323// samplerCube: TextureCube + SamplerState
2324// sampler2DShadow: Texture2D + SamplerComparisonState
2325// samplerCubeShadow: TextureCube + SamplerComparisonState
2326TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2327{
2328 glActiveTexture(GL_TEXTURE0);
2329 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2330 GLubyte texData[4];
2331 texData[0] = 0;
2332 texData[1] = 0;
2333 texData[2] = 120;
2334 texData[3] = 255;
2335 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2336
2337 glActiveTexture(GL_TEXTURE1);
2338 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2339 texData[0] = 0;
2340 texData[1] = 90;
2341 texData[2] = 0;
2342 texData[3] = 255;
2343 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2344 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2345 texData);
2346
2347 glActiveTexture(GL_TEXTURE2);
2348 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2349 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2350 GLfloat depthTexData[1];
2351 depthTexData[0] = 0.5f;
2352 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2353 depthTexData);
2354
2355 glActiveTexture(GL_TEXTURE3);
2356 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2357 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2358 depthTexData[0] = 0.2f;
2359 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2360 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2361 depthTexData);
2362
2363 EXPECT_GL_NO_ERROR();
2364
2365 glUseProgram(mProgram);
2366 glUniform1f(mDepthRefUniformLocation, 0.3f);
2367 glUniform1i(mTexture2DUniformLocation, 0);
2368 glUniform1i(mTextureCubeUniformLocation, 1);
2369 glUniform1i(mTexture2DShadowUniformLocation, 2);
2370 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2371
2372 drawQuad(mProgram, "position", 0.5f);
2373 EXPECT_GL_NO_ERROR();
2374 // The shader writes:
2375 // <texture 2d color> +
2376 // <cube map color> +
2377 // 0.25 * <comparison result (1.0)> +
2378 // 0.125 * <comparison result (0.0)>
2379 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2380}
2381
Olli Etuahobce743a2016-01-15 17:18:28 +02002382// Test different base levels on textures accessed through the same sampler array.
2383// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2384TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2385{
Yunchao He9550c602018-02-13 14:47:05 +08002386 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2387
Olli Etuahobce743a2016-01-15 17:18:28 +02002388 glActiveTexture(GL_TEXTURE0);
2389 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2390 GLsizei size = 64;
2391 for (GLint level = 0; level < 7; ++level)
2392 {
2393 ASSERT_LT(0, size);
2394 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2395 nullptr);
2396 size = size / 2;
2397 }
2398 ASSERT_EQ(0, size);
2399 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2400
2401 glActiveTexture(GL_TEXTURE1);
2402 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2403 size = 128;
2404 for (GLint level = 0; level < 8; ++level)
2405 {
2406 ASSERT_LT(0, size);
2407 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2408 nullptr);
2409 size = size / 2;
2410 }
2411 ASSERT_EQ(0, size);
2412 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2413 EXPECT_GL_NO_ERROR();
2414
2415 glUseProgram(mProgram);
2416 glUniform1i(mTexture0Location, 0);
2417 glUniform1i(mTexture1Location, 1);
2418
Olli Etuaho5804dc82018-04-13 14:11:46 +03002419 drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
Olli Etuahobce743a2016-01-15 17:18:28 +02002420 EXPECT_GL_NO_ERROR();
2421 // Red channel: width of level 1 of texture A: 32.
2422 // Green channel: width of level 3 of texture B: 16.
2423 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2424}
2425
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002426// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2427// ES 3.0.4 table 3.24
2428TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2429{
2430 glActiveTexture(GL_TEXTURE0);
2431 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2432 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2433 EXPECT_GL_NO_ERROR();
2434
2435 drawQuad(mProgram, "position", 0.5f);
2436
2437 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2438}
2439
2440// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2441// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002442TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002443{
Luc Ferron5164b792018-03-06 09:10:12 -05002444 setUpProgram();
2445
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002446 glActiveTexture(GL_TEXTURE0);
2447 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2448 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2449 EXPECT_GL_NO_ERROR();
2450
2451 drawQuad(mProgram, "position", 0.5f);
2452
2453 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2454}
2455
Luc Ferron5164b792018-03-06 09:10:12 -05002456// Validate that every component of the pixel will be equal to the luminance value we've set
2457// and that the alpha channel will be 1 (or 255 to be exact).
2458TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2459{
2460 setUpProgram();
2461
2462 glActiveTexture(GL_TEXTURE0);
2463 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2464 uint8_t pixel = 50;
2465 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2466 EXPECT_GL_NO_ERROR();
2467
2468 drawQuad(mProgram, "position", 0.5f);
2469
2470 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2471}
2472
2473// Validate that every component of the pixel will be equal to the luminance value we've set
2474// and that the alpha channel will be the second component.
2475TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2476{
2477 setUpProgram();
2478
2479 glActiveTexture(GL_TEXTURE0);
2480 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2481 uint8_t pixel[] = {50, 25};
2482 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2483 GL_UNSIGNED_BYTE, pixel);
2484 EXPECT_GL_NO_ERROR();
2485
2486 drawQuad(mProgram, "position", 0.5f);
2487
2488 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2489}
2490
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002491// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2492// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002493TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002494{
Luc Ferrond8c632c2018-04-10 12:31:44 -04002495 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
2496 ANGLE_SKIP_TEST_IF(IsD3D9());
2497 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002498
2499 setUpProgram();
2500
Luc Ferrond8c632c2018-04-10 12:31:44 -04002501 glActiveTexture(GL_TEXTURE0);
2502 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2503 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2504 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002505
Luc Ferrond8c632c2018-04-10 12:31:44 -04002506 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002507
Luc Ferrond8c632c2018-04-10 12:31:44 -04002508 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002509}
2510
2511// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2512// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002513TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002514{
Luc Ferrond8c632c2018-04-10 12:31:44 -04002515 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
2516 ANGLE_SKIP_TEST_IF(IsD3D9());
2517 ANGLE_SKIP_TEST_IF(IsVulkan());
2518 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES());
2519 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2520 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002521
Luc Ferrond8c632c2018-04-10 12:31:44 -04002522 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002523
Luc Ferrond8c632c2018-04-10 12:31:44 -04002524 glActiveTexture(GL_TEXTURE0);
2525 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2526 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2527 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002528
Luc Ferrond8c632c2018-04-10 12:31:44 -04002529 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002530
Luc Ferrond8c632c2018-04-10 12:31:44 -04002531 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002532}
2533
2534// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2535// ES 3.0.4 table 3.24
2536TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2537{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002538 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2539
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002540 glActiveTexture(GL_TEXTURE0);
2541 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2542 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2543 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2544 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2545 EXPECT_GL_NO_ERROR();
2546
2547 drawQuad(mProgram, "position", 0.5f);
2548
2549 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2550}
2551
2552// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2553// ES 3.0.4 table 3.24
2554TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2555{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002556 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2557
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002558 glActiveTexture(GL_TEXTURE0);
2559 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2560
2561 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2562 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2563 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2564 EXPECT_GL_NO_ERROR();
2565
2566 drawQuad(mProgram, "position", 0.5f);
2567
2568 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2569}
2570
2571// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2572// ES 3.0.4 table 3.24
2573TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2574{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002575 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2576
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002577 glActiveTexture(GL_TEXTURE0);
2578 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2579 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2580 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2581 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2582 EXPECT_GL_NO_ERROR();
2583
2584 drawQuad(mProgram, "position", 0.5f);
2585
2586 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2587}
2588
2589// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2590// ES 3.0.4 table 3.24
2591TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2592{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002593 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2594
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002595 glActiveTexture(GL_TEXTURE0);
2596 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2597 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2598 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2599 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2600 EXPECT_GL_NO_ERROR();
2601
2602 drawQuad(mProgram, "position", 0.5f);
2603
2604 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2605}
2606
2607// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2608// ES 3.0.4 table 3.24
2609TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2610{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002611 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2612
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002613 glActiveTexture(GL_TEXTURE0);
2614 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2615 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2616 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2617 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2618 EXPECT_GL_NO_ERROR();
2619
2620 drawQuad(mProgram, "position", 0.5f);
2621
2622 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2623}
2624
2625// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2626// ES 3.0.4 table 3.24
2627TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2628{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002629 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2630
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002631 glActiveTexture(GL_TEXTURE0);
2632 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2633 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2634 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2635 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2636 EXPECT_GL_NO_ERROR();
2637
2638 drawQuad(mProgram, "position", 0.5f);
2639
2640 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2641}
2642
2643// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2644// ES 3.0.4 table 3.24
2645TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2646{
2647 glActiveTexture(GL_TEXTURE0);
2648 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2649 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2650 EXPECT_GL_NO_ERROR();
2651
2652 drawQuad(mProgram, "position", 0.5f);
2653
2654 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2655}
2656
2657// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2658// ES 3.0.4 table 3.24
2659TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2660{
2661 glActiveTexture(GL_TEXTURE0);
2662 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2663 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2664 nullptr);
2665 EXPECT_GL_NO_ERROR();
2666
2667 drawQuad(mProgram, "position", 0.5f);
2668
2669 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2670}
2671
2672// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2673// ES 3.0.4 table 3.24
2674TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2675{
Yunchao He9550c602018-02-13 14:47:05 +08002676 // Seems to fail on OSX 10.12 Intel.
2677 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Jamie Madillbb1db482017-01-10 10:48:32 -05002678
Yuly Novikov49886892018-01-23 21:18:27 -05002679 // http://anglebug.com/2190
2680 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2681
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002682 glActiveTexture(GL_TEXTURE0);
2683 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2684 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2685 EXPECT_GL_NO_ERROR();
2686
2687 drawQuad(mProgram, "position", 0.5f);
2688
2689 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2690}
2691
2692// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2693// ES 3.0.4 table 3.24
2694TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2695{
Yunchao He9550c602018-02-13 14:47:05 +08002696 // Seems to fail on OSX 10.12 Intel.
2697 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002698
Yuly Novikov49886892018-01-23 21:18:27 -05002699 // http://anglebug.com/2190
2700 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2701
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002702 glActiveTexture(GL_TEXTURE0);
2703 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2704 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2705 EXPECT_GL_NO_ERROR();
2706
2707 drawQuad(mProgram, "position", 0.5f);
2708
2709 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2710}
2711
Olli Etuaho96963162016-03-21 11:54:33 +02002712// Use a sampler in a uniform struct.
2713TEST_P(SamplerInStructTest, SamplerInStruct)
2714{
2715 runSamplerInStructTest();
2716}
2717
2718// Use a sampler in a uniform struct that's passed as a function parameter.
2719TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2720{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002721 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002722 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002723
Olli Etuaho96963162016-03-21 11:54:33 +02002724 runSamplerInStructTest();
2725}
2726
2727// Use a sampler in a uniform struct array with a struct from the array passed as a function
2728// parameter.
2729TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2730{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002731 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002732 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
2733
Olli Etuaho96963162016-03-21 11:54:33 +02002734 runSamplerInStructTest();
2735}
2736
2737// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2738// parameter.
2739TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2740{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002741 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002742 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
2743
Olli Etuaho96963162016-03-21 11:54:33 +02002744 runSamplerInStructTest();
2745}
2746
2747// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2748// similarly named uniform.
2749TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2750{
2751 runSamplerInStructTest();
2752}
2753
Till Rathmannb8543632018-10-02 19:46:14 +02002754// GL_OES_texture_border_clamp
2755class TextureBorderClampTest : public Texture2DTest
2756{
2757 protected:
2758 TextureBorderClampTest() : Texture2DTest() {}
2759
2760 std::string getVertexShaderSource() override
2761 {
2762 return
2763 R"(precision highp float;
2764 attribute vec4 position;
2765 varying vec2 texcoord;
2766
2767 void main()
2768 {
2769 gl_Position = vec4(position.xy, 0.0, 1.0);
2770 // texcoords in [-0.5, 1.5]
2771 texcoord = (position.xy) + 0.5;
2772 })";
2773 }
2774
2775 void uploadTexture()
2776 {
2777 glActiveTexture(GL_TEXTURE0);
2778 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2779 std::vector<GLColor> texDataRed(1, GLColor::red);
2780 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2781 texDataRed.data());
2782 EXPECT_GL_NO_ERROR();
2783 }
2784};
2785
2786// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
2787// GL_CLAMP_TO_BORDER wrap mode (set with glTexParameter).
2788TEST_P(TextureBorderClampTest, TextureBorderClampFunctional)
2789{
2790 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
2791
2792 setUpProgram();
2793
2794 uploadTexture();
2795
2796 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
2797 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
2798 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2799 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2800 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2801 EXPECT_GL_NO_ERROR();
2802
2803 drawQuad(mProgram, "position", 0.5f);
2804
2805 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
2806 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2807 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
2808}
2809
2810// Test reading back GL_TEXTURE_BORDER_COLOR by glGetTexParameter.
2811TEST_P(TextureBorderClampTest, TextureBorderClampFunctional2)
2812{
2813 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
2814
2815 glActiveTexture(GL_TEXTURE0);
2816 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2817
2818 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2819
2820 GLint colorFixedPoint[4] = {0};
2821 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
2822 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
2823 std::numeric_limits<GLint>::max()};
2824 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
2825 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
2826 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
2827 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
2828
2829 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
2830 std::numeric_limits<GLint>::max()};
2831 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
2832
2833 GLfloat color[4] = {0.0f};
2834 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
2835 EXPECT_EQ(color[0], kFloatBlue.R);
2836 EXPECT_EQ(color[1], kFloatBlue.G);
2837 EXPECT_EQ(color[2], kFloatBlue.B);
2838 EXPECT_EQ(color[3], kFloatBlue.A);
2839}
2840
2841// Test GL_TEXTURE_BORDER_COLOR parameter validation at glTexParameter.
2842TEST_P(TextureBorderClampTest, TextureBorderClampValidation)
2843{
2844 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
2845
2846 glActiveTexture(GL_TEXTURE0);
2847 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2848
2849 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, 1.0f);
2850 EXPECT_GL_ERROR(GL_INVALID_ENUM);
2851
2852 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
2853 EXPECT_GL_ERROR(GL_INVALID_ENUM);
2854
2855 glTexParameterfv(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2856 EXPECT_GL_ERROR(GL_INVALID_ENUM);
2857
2858 GLint colorInt[4] = {0};
2859 glTexParameteriv(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_BORDER_COLOR, colorInt);
2860 EXPECT_GL_ERROR(GL_INVALID_ENUM);
2861
2862 if (getClientMajorVersion() < 3)
2863 {
2864 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
2865 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2866 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
2867 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2868
2869 GLuint colorUInt[4] = {0};
2870 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
2871 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2872 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
2873 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2874
2875 GLSampler sampler;
2876 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
2877 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2878 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
2879 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2880
2881 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
2882 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2883 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
2884 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2885 }
2886}
2887
2888class TextureBorderClampTestES3 : public TextureBorderClampTest
2889{
2890 protected:
2891 TextureBorderClampTestES3() : TextureBorderClampTest() {}
2892};
2893
2894// Test if the color set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the texture in
2895// GL_CLAMP_TO_BORDER wrap mode (set with glSamplerParameter).
2896TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional)
2897{
2898 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
2899
2900 setUpProgram();
2901
2902 uploadTexture();
2903
2904 GLSampler sampler;
2905 glBindSampler(0, sampler);
2906 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
2907 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
2908 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2909 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2910 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2911 EXPECT_GL_NO_ERROR();
2912
2913 drawQuad(mProgram, "position", 0.5f);
2914
2915 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
2916 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2917 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
2918}
2919
2920// Test reading back GL_TEXTURE_BORDER_COLOR by glGetSamplerParameter.
2921TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Functional2)
2922{
2923 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
2924
2925 glActiveTexture(GL_TEXTURE0);
2926
2927 GLSampler sampler;
2928 glBindSampler(0, sampler);
2929
2930 glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, &kFloatGreen.R);
2931
2932 GLint colorFixedPoint[4] = {0};
2933 glGetSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorFixedPoint);
2934 constexpr GLint colorGreenFixedPoint[4] = {0, std::numeric_limits<GLint>::max(), 0,
2935 std::numeric_limits<GLint>::max()};
2936 EXPECT_EQ(colorFixedPoint[0], colorGreenFixedPoint[0]);
2937 EXPECT_EQ(colorFixedPoint[1], colorGreenFixedPoint[1]);
2938 EXPECT_EQ(colorFixedPoint[2], colorGreenFixedPoint[2]);
2939 EXPECT_EQ(colorFixedPoint[3], colorGreenFixedPoint[3]);
2940
2941 constexpr GLint colorBlueFixedPoint[4] = {0, 0, std::numeric_limits<GLint>::max(),
2942 std::numeric_limits<GLint>::max()};
2943 glSamplerParameteriv(sampler, GL_TEXTURE_BORDER_COLOR, colorBlueFixedPoint);
2944
2945 GLfloat color[4] = {0.0f};
2946 glGetSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, color);
2947 EXPECT_EQ(color[0], kFloatBlue.R);
2948 EXPECT_EQ(color[1], kFloatBlue.G);
2949 EXPECT_EQ(color[2], kFloatBlue.B);
2950 EXPECT_EQ(color[3], kFloatBlue.A);
2951
2952 constexpr GLint colorSomewhatRedInt[4] = {500000, 0, 0, std::numeric_limits<GLint>::max()};
2953 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedInt);
2954 GLint colorInt[4] = {0};
2955 glGetSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorInt);
2956 EXPECT_EQ(colorInt[0], colorSomewhatRedInt[0]);
2957 EXPECT_EQ(colorInt[1], colorSomewhatRedInt[1]);
2958 EXPECT_EQ(colorInt[2], colorSomewhatRedInt[2]);
2959 EXPECT_EQ(colorInt[3], colorSomewhatRedInt[3]);
2960
2961 constexpr GLuint colorSomewhatRedUInt[4] = {500000, 0, 0, std::numeric_limits<GLuint>::max()};
2962 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorSomewhatRedUInt);
2963 GLuint colorUInt[4] = {0};
2964 glGetSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, colorUInt);
2965 EXPECT_EQ(colorUInt[0], colorSomewhatRedUInt[0]);
2966 EXPECT_EQ(colorUInt[1], colorSomewhatRedUInt[1]);
2967 EXPECT_EQ(colorUInt[2], colorSomewhatRedUInt[2]);
2968 EXPECT_EQ(colorUInt[3], colorSomewhatRedUInt[3]);
2969
2970 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2971
2972 constexpr GLint colorSomewhatGreenInt[4] = {0, 500000, 0, std::numeric_limits<GLint>::max()};
2973 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenInt);
2974 glGetTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorInt);
2975 EXPECT_EQ(colorInt[0], colorSomewhatGreenInt[0]);
2976 EXPECT_EQ(colorInt[1], colorSomewhatGreenInt[1]);
2977 EXPECT_EQ(colorInt[2], colorSomewhatGreenInt[2]);
2978 EXPECT_EQ(colorInt[3], colorSomewhatGreenInt[3]);
2979
2980 constexpr GLuint colorSomewhatGreenUInt[4] = {0, 500000, 0, std::numeric_limits<GLuint>::max()};
2981 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorSomewhatGreenUInt);
2982 glGetTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorUInt);
2983 EXPECT_EQ(colorUInt[0], colorSomewhatGreenUInt[0]);
2984 EXPECT_EQ(colorUInt[1], colorSomewhatGreenUInt[1]);
2985 EXPECT_EQ(colorUInt[2], colorSomewhatGreenUInt[2]);
2986 EXPECT_EQ(colorUInt[3], colorSomewhatGreenUInt[3]);
2987}
2988
2989// Test GL_TEXTURE_BORDER_COLOR parameter validation at glSamplerParameter.
2990TEST_P(TextureBorderClampTestES3, TextureBorderClampES3Validation)
2991{
2992 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
2993
2994 glActiveTexture(GL_TEXTURE0);
2995
2996 GLSampler sampler;
2997 glBindSampler(0, sampler);
2998
2999 glSamplerParameterf(sampler, GL_TEXTURE_BORDER_COLOR, 1.0f);
3000 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3001
3002 glSamplerParameteri(sampler, GL_TEXTURE_BORDER_COLOR, std::numeric_limits<GLint>::max());
3003 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3004}
3005
3006class TextureBorderClampIntegerTestES3 : public Texture2DTest
3007{
3008 protected:
3009 TextureBorderClampIntegerTestES3() : Texture2DTest(), isUnsignedIntTest(false) {}
3010
3011 std::string getVertexShaderSource() override
3012 {
3013 return
3014 R"(#version 300 es
3015 out vec2 texcoord;
3016 in vec4 position;
3017
3018 void main()
3019 {
3020 gl_Position = vec4(position.xy, 0.0, 1.0);
3021 // texcoords in [-0.5, 1.5]
3022 texcoord = (position.xy) + 0.5;
3023 })";
3024 }
3025
3026 std::string getFragmentShaderSource()
3027 {
3028 // clang-format off
3029 return std::string(
3030 "#version 300 es\n"
3031 "precision highp float;\n"
3032 "uniform highp ") + (isUnsignedIntTest ? "usampler2D" : "isampler2D") + " tex;\n"
3033 "in vec2 texcoord;\n"
3034 "out vec4 fragColor;\n"
3035
3036 "void main()\n"
3037 "{\n"
3038 "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3039 "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3040 "fragColor = (texture(tex, texcoord).r == " + (isUnsignedIntTest ? "150u" : "-50") + ")"
3041 " ? green : red;\n"
3042 "}\n";
3043 // clang-format on
3044 }
3045
3046 void uploadTexture()
3047 {
3048 glActiveTexture(GL_TEXTURE0);
3049 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3050 if (isUnsignedIntTest)
3051 {
3052 std::vector<GLubyte> texData(4, 100);
3053 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE,
3054 texData.data());
3055 }
3056 else
3057 {
3058 std::vector<GLbyte> texData(4, 100);
3059 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8I, 1, 1, 0, GL_RGBA_INTEGER, GL_BYTE,
3060 texData.data());
3061 }
3062 EXPECT_GL_NO_ERROR();
3063 }
3064
3065 bool isUnsignedIntTest;
3066};
3067
3068// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3069// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3070TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger)
3071{
3072 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
3073
3074 setUpProgram();
3075
3076 uploadTexture();
3077
3078 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3079 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3080 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3081 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3082
3083 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3084 glTexParameterIivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3085
3086 EXPECT_GL_NO_ERROR();
3087
3088 drawQuad(mProgram, "position", 0.5f);
3089
3090 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3091 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3092 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3093}
3094
3095// Test if the integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside of the
3096// integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIivOES).
3097TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampInteger2)
3098{
3099 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
3100
3101 setUpProgram();
3102
3103 uploadTexture();
3104
3105 GLSampler sampler;
3106 glBindSampler(0, sampler);
3107 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3108 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3109 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3110 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3111
3112 constexpr GLint borderColor[4] = {-50, -50, -50, -50};
3113 glSamplerParameterIivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3114
3115 EXPECT_GL_NO_ERROR();
3116
3117 drawQuad(mProgram, "position", 0.5f);
3118
3119 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3120 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3121 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3122}
3123
3124// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3125// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with glTexParameterIuivOES).
3126TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned)
3127{
3128 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
3129
3130 isUnsignedIntTest = true;
3131
3132 setUpProgram();
3133
3134 uploadTexture();
3135
3136 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3137 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3138 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3139 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3140
3141 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3142 glTexParameterIuivOES(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
3143
3144 EXPECT_GL_NO_ERROR();
3145
3146 drawQuad(mProgram, "position", 0.5f);
3147
3148 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3149 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3150 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3151}
3152
3153// Test if the unsigned integer values set as GL_TEXTURE_BORDER_COLOR is used when sampling outside
3154// of the unsigned integer texture in GL_CLAMP_TO_BORDER wrap mode (set with
3155// glSamplerParameterIuivOES).
3156TEST_P(TextureBorderClampIntegerTestES3, TextureBorderClampIntegerUnsigned2)
3157{
3158 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_border_clamp"));
3159
3160 isUnsignedIntTest = true;
3161
3162 setUpProgram();
3163
3164 uploadTexture();
3165
3166 GLSampler sampler;
3167 glBindSampler(0, sampler);
3168 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
3169 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
3170 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3171 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3172
3173 constexpr GLuint borderColor[4] = {150, 150, 150, 150};
3174 glSamplerParameterIuivOES(sampler, GL_TEXTURE_BORDER_COLOR, borderColor);
3175
3176 EXPECT_GL_NO_ERROR();
3177
3178 drawQuad(mProgram, "position", 0.5f);
3179
3180 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
3181 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3182 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
3183}
3184
3185// ~GL_OES_texture_border_clamp
3186
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003187class TextureLimitsTest : public ANGLETest
3188{
3189 protected:
3190 struct RGBA8
3191 {
3192 uint8_t R, G, B, A;
3193 };
3194
3195 TextureLimitsTest()
3196 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
3197 {
3198 setWindowWidth(128);
3199 setWindowHeight(128);
3200 setConfigRedBits(8);
3201 setConfigGreenBits(8);
3202 setConfigBlueBits(8);
3203 setConfigAlphaBits(8);
3204 }
3205
Jamie Madill0fdb9562018-09-17 17:18:43 -04003206 void SetUp() override
3207 {
3208 ANGLETest::SetUp();
3209
3210 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
3211 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
3212 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
3213
3214 ASSERT_GL_NO_ERROR();
3215 }
3216
3217 void TearDown() override
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003218 {
3219 if (mProgram != 0)
3220 {
3221 glDeleteProgram(mProgram);
3222 mProgram = 0;
3223
3224 if (!mTextures.empty())
3225 {
3226 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
3227 }
3228 }
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003229
Jamie Madill0fdb9562018-09-17 17:18:43 -04003230 ANGLETest::TearDown();
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003231 }
3232
3233 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
3234 GLint vertexTextureCount,
3235 GLint vertexActiveTextureCount,
3236 const std::string &fragPrefix,
3237 GLint fragmentTextureCount,
3238 GLint fragmentActiveTextureCount)
3239 {
3240 std::stringstream vertexShaderStr;
3241 vertexShaderStr << "attribute vec2 position;\n"
3242 << "varying vec4 color;\n"
3243 << "varying vec2 texCoord;\n";
3244
3245 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
3246 {
3247 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
3248 }
3249
3250 vertexShaderStr << "void main() {\n"
3251 << " gl_Position = vec4(position, 0, 1);\n"
3252 << " texCoord = (position * 0.5) + 0.5;\n"
3253 << " color = vec4(0);\n";
3254
3255 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
3256 {
3257 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
3258 << ", texCoord);\n";
3259 }
3260
3261 vertexShaderStr << "}";
3262
3263 std::stringstream fragmentShaderStr;
3264 fragmentShaderStr << "varying mediump vec4 color;\n"
3265 << "varying mediump vec2 texCoord;\n";
3266
3267 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
3268 {
3269 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
3270 }
3271
3272 fragmentShaderStr << "void main() {\n"
3273 << " gl_FragColor = color;\n";
3274
3275 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
3276 {
3277 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
3278 << ", texCoord);\n";
3279 }
3280
3281 fragmentShaderStr << "}";
3282
3283 const std::string &vertexShaderSource = vertexShaderStr.str();
3284 const std::string &fragmentShaderSource = fragmentShaderStr.str();
3285
3286 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
3287 }
3288
3289 RGBA8 getPixel(GLint texIndex)
3290 {
3291 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3292 0, 255u};
3293 return pixel;
3294 }
3295
3296 void initTextures(GLint tex2DCount, GLint texCubeCount)
3297 {
3298 GLint totalCount = tex2DCount + texCubeCount;
3299 mTextures.assign(totalCount, 0);
3300 glGenTextures(totalCount, &mTextures[0]);
3301 ASSERT_GL_NO_ERROR();
3302
3303 std::vector<RGBA8> texData(16 * 16);
3304
3305 GLint texIndex = 0;
3306 for (; texIndex < tex2DCount; ++texIndex)
3307 {
3308 texData.assign(texData.size(), getPixel(texIndex));
3309 glActiveTexture(GL_TEXTURE0 + texIndex);
3310 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3311 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3312 &texData[0]);
3313 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3314 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3315 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3316 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3317 }
3318
3319 ASSERT_GL_NO_ERROR();
3320
3321 for (; texIndex < texCubeCount; ++texIndex)
3322 {
3323 texData.assign(texData.size(), getPixel(texIndex));
3324 glActiveTexture(GL_TEXTURE0 + texIndex);
3325 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3326 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3327 GL_UNSIGNED_BYTE, &texData[0]);
3328 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3329 GL_UNSIGNED_BYTE, &texData[0]);
3330 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3331 GL_UNSIGNED_BYTE, &texData[0]);
3332 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3333 GL_UNSIGNED_BYTE, &texData[0]);
3334 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3335 GL_UNSIGNED_BYTE, &texData[0]);
3336 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3337 GL_UNSIGNED_BYTE, &texData[0]);
3338 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3339 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3340 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3341 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3342 }
3343
3344 ASSERT_GL_NO_ERROR();
3345 }
3346
3347 void testWithTextures(GLint vertexTextureCount,
3348 const std::string &vertexTexturePrefix,
3349 GLint fragmentTextureCount,
3350 const std::string &fragmentTexturePrefix)
3351 {
3352 // Generate textures
3353 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3354
3355 glUseProgram(mProgram);
3356 RGBA8 expectedSum = {0};
3357 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3358 {
3359 std::stringstream uniformNameStr;
3360 uniformNameStr << vertexTexturePrefix << texIndex;
3361 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003362 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003363 ASSERT_NE(-1, location);
3364
3365 glUniform1i(location, texIndex);
3366 RGBA8 contribution = getPixel(texIndex);
3367 expectedSum.R += contribution.R;
3368 expectedSum.G += contribution.G;
3369 }
3370
3371 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3372 {
3373 std::stringstream uniformNameStr;
3374 uniformNameStr << fragmentTexturePrefix << texIndex;
3375 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04003376 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003377 ASSERT_NE(-1, location);
3378
3379 glUniform1i(location, texIndex + vertexTextureCount);
3380 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3381 expectedSum.R += contribution.R;
3382 expectedSum.G += contribution.G;
3383 }
3384
3385 ASSERT_GE(256u, expectedSum.G);
3386
3387 drawQuad(mProgram, "position", 0.5f);
3388 ASSERT_GL_NO_ERROR();
3389 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3390 }
3391
3392 GLuint mProgram;
3393 std::vector<GLuint> mTextures;
3394 GLint mMaxVertexTextures;
3395 GLint mMaxFragmentTextures;
3396 GLint mMaxCombinedTextures;
3397};
3398
3399// Test rendering with the maximum vertex texture units.
3400TEST_P(TextureLimitsTest, MaxVertexTextures)
3401{
3402 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3403 ASSERT_NE(0u, mProgram);
3404 ASSERT_GL_NO_ERROR();
3405
3406 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3407}
3408
3409// Test rendering with the maximum fragment texture units.
3410TEST_P(TextureLimitsTest, MaxFragmentTextures)
3411{
3412 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3413 ASSERT_NE(0u, mProgram);
3414 ASSERT_GL_NO_ERROR();
3415
3416 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3417}
3418
3419// Test rendering with maximum combined texture units.
3420TEST_P(TextureLimitsTest, MaxCombinedTextures)
3421{
3422 GLint vertexTextures = mMaxVertexTextures;
3423
3424 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3425 {
3426 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3427 }
3428
3429 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3430 mMaxFragmentTextures, mMaxFragmentTextures);
3431 ASSERT_NE(0u, mProgram);
3432 ASSERT_GL_NO_ERROR();
3433
3434 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3435}
3436
3437// Negative test for exceeding the number of vertex textures
3438TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3439{
3440 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3441 0);
3442 ASSERT_EQ(0u, mProgram);
3443}
3444
3445// Negative test for exceeding the number of fragment textures
3446TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3447{
3448 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3449 mMaxFragmentTextures + 1);
3450 ASSERT_EQ(0u, mProgram);
3451}
3452
3453// Test active vertex textures under the limit, but excessive textures specified.
3454TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3455{
3456 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3457 ASSERT_NE(0u, mProgram);
3458 ASSERT_GL_NO_ERROR();
3459
3460 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3461}
3462
3463// Test active fragment textures under the limit, but excessive textures specified.
3464TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3465{
3466 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3467 mMaxFragmentTextures);
3468 ASSERT_NE(0u, mProgram);
3469 ASSERT_GL_NO_ERROR();
3470
3471 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3472}
3473
3474// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003475// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003476TEST_P(TextureLimitsTest, TextureTypeConflict)
3477{
3478 const std::string &vertexShader =
3479 "attribute vec2 position;\n"
3480 "varying float color;\n"
3481 "uniform sampler2D tex2D;\n"
3482 "uniform samplerCube texCube;\n"
3483 "void main() {\n"
3484 " gl_Position = vec4(position, 0, 1);\n"
3485 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3486 " color = texture2D(tex2D, texCoord).x;\n"
3487 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3488 "}";
3489 const std::string &fragmentShader =
3490 "varying mediump float color;\n"
3491 "void main() {\n"
3492 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3493 "}";
3494
3495 mProgram = CompileProgram(vertexShader, fragmentShader);
3496 ASSERT_NE(0u, mProgram);
3497
3498 initTextures(1, 0);
3499
3500 glUseProgram(mProgram);
3501 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3502 ASSERT_NE(-1, tex2DLocation);
3503 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3504 ASSERT_NE(-1, texCubeLocation);
3505
3506 glUniform1i(tex2DLocation, 0);
3507 glUniform1i(texCubeLocation, 0);
3508 ASSERT_GL_NO_ERROR();
3509
3510 drawQuad(mProgram, "position", 0.5f);
3511 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3512}
3513
Vincent Lang25ab4512016-05-13 18:13:59 +02003514class Texture2DNorm16TestES3 : public Texture2DTestES3
3515{
3516 protected:
3517 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3518
3519 void SetUp() override
3520 {
3521 Texture2DTestES3::SetUp();
3522
3523 glActiveTexture(GL_TEXTURE0);
3524 glGenTextures(3, mTextures);
3525 glGenFramebuffers(1, &mFBO);
3526 glGenRenderbuffers(1, &mRenderbuffer);
3527
3528 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3529 {
3530 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3531 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3532 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3533 }
3534
3535 glBindTexture(GL_TEXTURE_2D, 0);
3536
3537 ASSERT_GL_NO_ERROR();
3538 }
3539
3540 void TearDown() override
3541 {
3542 glDeleteTextures(3, mTextures);
3543 glDeleteFramebuffers(1, &mFBO);
3544 glDeleteRenderbuffers(1, &mRenderbuffer);
3545
3546 Texture2DTestES3::TearDown();
3547 }
3548
3549 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3550 {
Geoff Langf607c602016-09-21 11:46:48 -04003551 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3552 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003553
3554 setUpProgram();
3555
3556 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3557 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3558 0);
3559
3560 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3561 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3562
3563 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003564 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003565
3566 EXPECT_GL_NO_ERROR();
3567
3568 drawQuad(mProgram, "position", 0.5f);
3569
Geoff Langf607c602016-09-21 11:46:48 -04003570 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003571
Jamie Madill50cf2be2018-06-15 09:46:57 -04003572 EXPECT_PIXEL_COLOR_EQ(0, 0,
3573 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3574 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003575
3576 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3577
3578 ASSERT_GL_NO_ERROR();
3579 }
3580
3581 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3582 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04003583 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003584 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003585
3586 setUpProgram();
3587
3588 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3589 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3590
3591 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3592 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3593 0);
3594
3595 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003596 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003597
3598 EXPECT_GL_NO_ERROR();
3599
3600 drawQuad(mProgram, "position", 0.5f);
3601
Geoff Langf607c602016-09-21 11:46:48 -04003602 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
Jamie Madill50cf2be2018-06-15 09:46:57 -04003603 EXPECT_PIXEL_COLOR_EQ(0, 0,
3604 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3605 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003606
3607 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3608 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3609 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3610 mRenderbuffer);
3611 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3612 EXPECT_GL_NO_ERROR();
3613
3614 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3615 glClear(GL_COLOR_BUFFER_BIT);
3616
3617 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3618
Geoff Langf607c602016-09-21 11:46:48 -04003619 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003620
3621 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3622
3623 ASSERT_GL_NO_ERROR();
3624 }
3625
3626 GLuint mTextures[3];
3627 GLuint mFBO;
3628 GLuint mRenderbuffer;
3629};
3630
3631// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3632TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3633{
Yunchao He9550c602018-02-13 14:47:05 +08003634 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02003635
3636 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3637 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3638 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3639 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3640 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3641 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3642 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3643 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3644
3645 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3646 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3647 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3648}
3649
Olli Etuaho95faa232016-06-07 14:01:53 -07003650// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3651// GLES 3.0.4 section 3.8.3.
3652TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3653{
Yuly Novikov3c754192016-06-27 19:36:41 -04003654 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1429 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08003655 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07003656
3657 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3658 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3659 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3660 ASSERT_GL_NO_ERROR();
3661
3662 // SKIP_IMAGES should not have an effect on uploading 2D textures
3663 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3664 ASSERT_GL_NO_ERROR();
3665
3666 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3667
3668 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3669 pixelsGreen.data());
3670 ASSERT_GL_NO_ERROR();
3671
3672 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3673 pixelsGreen.data());
3674 ASSERT_GL_NO_ERROR();
3675
3676 glUseProgram(mProgram);
3677 drawQuad(mProgram, "position", 0.5f);
3678 ASSERT_GL_NO_ERROR();
3679
3680 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3681}
3682
Olli Etuaho989cac32016-06-08 16:18:49 -07003683// Test that skip defined in unpack parameters is taken into account when determining whether
3684// unpacking source extends outside unpack buffer bounds.
3685TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3686{
3687 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3688 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3689 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3690 ASSERT_GL_NO_ERROR();
3691
3692 GLBuffer buf;
3693 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3694 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3695 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3696 GL_DYNAMIC_COPY);
3697 ASSERT_GL_NO_ERROR();
3698
3699 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3700 ASSERT_GL_NO_ERROR();
3701
3702 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3703 ASSERT_GL_NO_ERROR();
3704
3705 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3706 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3707
3708 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3709 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3710 ASSERT_GL_NO_ERROR();
3711
3712 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3713 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3714}
3715
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003716// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3717TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3718{
Yunchao He9550c602018-02-13 14:47:05 +08003719 ANGLE_SKIP_TEST_IF(IsD3D11());
3720
3721 // Incorrect rendering results seen on OSX AMD.
3722 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003723
3724 const GLuint width = 8u;
3725 const GLuint height = 8u;
3726 const GLuint unpackRowLength = 5u;
3727 const GLuint unpackSkipPixels = 1u;
3728
3729 setWindowWidth(width);
3730 setWindowHeight(height);
3731
3732 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3733 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3734 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3735 ASSERT_GL_NO_ERROR();
3736
3737 GLBuffer buf;
3738 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3739 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3740 GLColor::green);
3741
3742 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3743 {
3744 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3745 }
3746
3747 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3748 GL_DYNAMIC_COPY);
3749 ASSERT_GL_NO_ERROR();
3750
3751 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3752 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3753 ASSERT_GL_NO_ERROR();
3754
3755 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3756 ASSERT_GL_NO_ERROR();
3757
3758 glUseProgram(mProgram);
3759 drawQuad(mProgram, "position", 0.5f);
3760 ASSERT_GL_NO_ERROR();
3761
3762 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3763 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3764 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3765 actual.data());
3766 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3767 EXPECT_EQ(expected, actual);
3768}
3769
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003770template <typename T>
3771T UNorm(double value)
3772{
3773 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3774}
3775
3776// Test rendering a depth texture with mipmaps.
3777TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3778{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003779 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3780 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
Jiawei Shaoaf0f31d2018-09-27 15:42:31 +08003781 // http://anglebug.com/1706
3782 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Corentin Walleze731d8a2016-09-07 10:56:25 -04003783
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003784 const int size = getWindowWidth();
3785
3786 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003787 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003788
3789 glActiveTexture(GL_TEXTURE0);
3790 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3791 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3792 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3793 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3794 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3795 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3796 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3797 ASSERT_GL_NO_ERROR();
3798
3799 glUseProgram(mProgram);
3800 glUniform1i(mTexture2DUniformLocation, 0);
3801
3802 std::vector<unsigned char> expected;
3803
3804 for (int level = 0; level < levels; ++level)
3805 {
3806 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3807 expected.push_back(UNorm<unsigned char>(value));
3808
3809 int levelDim = dim(level);
3810
3811 ASSERT_GT(levelDim, 0);
3812
3813 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3814 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3815 GL_UNSIGNED_INT, initData.data());
3816 }
3817 ASSERT_GL_NO_ERROR();
3818
3819 for (int level = 0; level < levels; ++level)
3820 {
3821 glViewport(0, 0, dim(level), dim(level));
3822 drawQuad(mProgram, "position", 0.5f);
3823 GLColor actual = ReadColor(0, 0);
3824 EXPECT_NEAR(expected[level], actual.R, 10u);
3825 }
3826
3827 ASSERT_GL_NO_ERROR();
3828}
3829
Jamie Madill7ffdda92016-09-08 13:26:51 -04003830// Tests unpacking into the unsized GL_ALPHA format.
3831TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3832{
Jamie Madill7ffdda92016-09-08 13:26:51 -04003833 // Initialize the texure.
3834 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3835 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3836 GL_UNSIGNED_BYTE, nullptr);
3837 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3838 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3839
3840 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3841
3842 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04003843 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04003844 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3845 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3846 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
3847 GL_STATIC_DRAW);
3848
3849 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
3850 GL_UNSIGNED_BYTE, nullptr);
3851
3852 // Clear to a weird color to make sure we're drawing something.
3853 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
3854 glClear(GL_COLOR_BUFFER_BIT);
3855
3856 // Draw with the alpha texture and verify.
3857 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04003858
3859 ASSERT_GL_NO_ERROR();
3860 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
3861}
3862
Jamie Madill2e600342016-09-19 13:56:40 -04003863// Ensure stale unpack data doesn't propagate in D3D11.
3864TEST_P(Texture2DTestES3, StaleUnpackData)
3865{
3866 // Init unpack buffer.
3867 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
3868 std::vector<GLColor> pixels(pixelCount, GLColor::red);
3869
3870 GLBuffer unpackBuffer;
3871 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3872 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3873 GLsizei bufferSize = pixelCount * sizeof(GLColor);
3874 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
3875
3876 // Create from unpack buffer.
3877 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3878 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
3879 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3880 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3881 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3882
3883 drawQuad(mProgram, "position", 0.5f);
3884
3885 ASSERT_GL_NO_ERROR();
3886 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3887
3888 // Fill unpack with green, recreating buffer.
3889 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
3890 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
3891 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
3892
3893 // Reinit texture with green.
3894 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
3895 GL_UNSIGNED_BYTE, nullptr);
3896
3897 drawQuad(mProgram, "position", 0.5f);
3898
3899 ASSERT_GL_NO_ERROR();
3900 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3901}
3902
Geoff Langfb7685f2017-11-13 11:44:11 -05003903// Ensure that texture parameters passed as floats that are converted to ints are rounded before
3904// validating they are less than 0.
3905TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
3906{
3907 GLTexture texture;
3908 glBindTexture(GL_TEXTURE_2D, texture);
3909
3910 // Use a negative number that will round to zero when converted to an integer
3911 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
3912 // "Validation of values performed by state-setting commands is performed after conversion,
3913 // unless specified otherwise for a specific command."
3914 GLfloat param = -7.30157126e-07f;
3915 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
3916 EXPECT_GL_NO_ERROR();
3917
3918 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
3919 EXPECT_GL_NO_ERROR();
3920}
3921
Jamie Madillf097e232016-11-05 00:44:15 -04003922// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
3923// being properly checked, and the texture storage of the previous texture format was persisting.
3924// This would result in an ASSERT in debug and incorrect rendering in release.
3925// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
3926TEST_P(Texture3DTestES3, FormatRedefinitionBug)
3927{
3928 GLTexture tex;
3929 glBindTexture(GL_TEXTURE_3D, tex.get());
3930 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3931
3932 GLFramebuffer framebuffer;
3933 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3934 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
3935
3936 glCheckFramebufferStatus(GL_FRAMEBUFFER);
3937
3938 std::vector<uint8_t> pixelData(100, 0);
3939
3940 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
3941 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
3942 pixelData.data());
3943
3944 ASSERT_GL_NO_ERROR();
3945}
3946
Corentin Wallezd2627992017-04-28 17:17:03 -04003947// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
3948TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
3949{
3950 // 2D tests
3951 {
3952 GLTexture tex;
3953 glBindTexture(GL_TEXTURE_2D, tex.get());
3954
3955 GLBuffer pbo;
3956 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3957
3958 // Test OOB
3959 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
3960 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3961 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3962
3963 // Test OOB
3964 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
3965 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3966 ASSERT_GL_NO_ERROR();
3967 }
3968
3969 // 3D tests
3970 {
3971 GLTexture tex;
3972 glBindTexture(GL_TEXTURE_3D, tex.get());
3973
3974 GLBuffer pbo;
3975 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3976
3977 // Test OOB
3978 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
3979 GL_STATIC_DRAW);
3980 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3981 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3982
3983 // Test OOB
3984 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
3985 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3986 ASSERT_GL_NO_ERROR();
3987 }
3988}
3989
Jamie Madill3ed60422017-09-07 11:32:52 -04003990// Tests behaviour with a single texture and multiple sampler objects.
3991TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
3992{
3993 GLint maxTextureUnits = 0;
3994 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
3995 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
3996
3997 constexpr int kSize = 16;
3998
3999 // Make a single-level texture, fill it with red.
4000 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
4001 GLTexture tex;
4002 glBindTexture(GL_TEXTURE_2D, tex);
4003 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4004 redColors.data());
4005 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4006 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4007
4008 // Simple sanity check.
4009 draw2DTexturedQuad(0.5f, 1.0f, true);
4010 ASSERT_GL_NO_ERROR();
4011 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
4012
4013 // Bind texture to unit 1 with a sampler object making it incomplete.
4014 GLSampler sampler;
4015 glBindSampler(0, sampler);
4016 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4017 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4018
4019 // Make a mipmap texture, fill it with blue.
4020 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
4021 GLTexture mipmapTex;
4022 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4023 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4024 blueColors.data());
4025 glGenerateMipmap(GL_TEXTURE_2D);
4026
4027 // Draw with the sampler, expect blue.
4028 draw2DTexturedQuad(0.5f, 1.0f, true);
4029 ASSERT_GL_NO_ERROR();
4030 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
4031
4032 // Simple multitexturing program.
4033 const std::string vs =
4034 "#version 300 es\n"
4035 "in vec2 position;\n"
4036 "out vec2 texCoord;\n"
4037 "void main()\n"
4038 "{\n"
4039 " gl_Position = vec4(position, 0, 1);\n"
4040 " texCoord = position * 0.5 + vec2(0.5);\n"
4041 "}";
4042 const std::string fs =
4043 "#version 300 es\n"
4044 "precision mediump float;\n"
4045 "in vec2 texCoord;\n"
4046 "uniform sampler2D tex1;\n"
4047 "uniform sampler2D tex2;\n"
4048 "uniform sampler2D tex3;\n"
4049 "uniform sampler2D tex4;\n"
4050 "out vec4 color;\n"
4051 "void main()\n"
4052 "{\n"
4053 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
4054 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
4055 "}";
4056
4057 ANGLE_GL_PROGRAM(program, vs, fs);
4058
4059 std::array<GLint, 4> texLocations = {
4060 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
4061 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
4062 for (GLint location : texLocations)
4063 {
4064 ASSERT_NE(-1, location);
4065 }
4066
4067 // Init the uniform data.
4068 glUseProgram(program);
4069 for (GLint location = 0; location < 4; ++location)
4070 {
4071 glUniform1i(texLocations[location], location);
4072 }
4073
4074 // Initialize four samplers
4075 GLSampler samplers[4];
4076
4077 // 0: non-mipped.
4078 glBindSampler(0, samplers[0]);
4079 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4080 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4081
4082 // 1: mipped.
4083 glBindSampler(1, samplers[1]);
4084 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4085 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4086
4087 // 2: non-mipped.
4088 glBindSampler(2, samplers[2]);
4089 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4090 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4091
4092 // 3: mipped.
4093 glBindSampler(3, samplers[3]);
4094 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
4095 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4096
4097 // Bind two blue mipped textures and two single layer textures, should all draw.
4098 glActiveTexture(GL_TEXTURE0);
4099 glBindTexture(GL_TEXTURE_2D, tex);
4100
4101 glActiveTexture(GL_TEXTURE1);
4102 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4103
4104 glActiveTexture(GL_TEXTURE2);
4105 glBindTexture(GL_TEXTURE_2D, tex);
4106
4107 glActiveTexture(GL_TEXTURE3);
4108 glBindTexture(GL_TEXTURE_2D, mipmapTex);
4109
4110 ASSERT_GL_NO_ERROR();
4111
4112 drawQuad(program, "position", 0.5f);
4113 ASSERT_GL_NO_ERROR();
4114 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
4115
4116 // Bind four single layer textures, two should be incomplete.
4117 glActiveTexture(GL_TEXTURE1);
4118 glBindTexture(GL_TEXTURE_2D, tex);
4119
4120 glActiveTexture(GL_TEXTURE3);
4121 glBindTexture(GL_TEXTURE_2D, tex);
4122
4123 drawQuad(program, "position", 0.5f);
4124 ASSERT_GL_NO_ERROR();
4125 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
4126}
4127
Martin Radev7e2c0d32017-09-15 14:25:42 +03004128// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
4129// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
4130// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
4131// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
4132// samples the cubemap using a direction vector (1,1,1).
4133TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
4134{
Yunchao He2f23f352018-02-11 22:11:37 +08004135 // Check http://anglebug.com/2155.
4136 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
4137
Martin Radev7e2c0d32017-09-15 14:25:42 +03004138 const std::string vs =
4139 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004140 precision mediump float;
4141 in vec3 pos;
4142 void main() {
4143 gl_Position = vec4(pos, 1.0);
4144 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03004145
4146 const std::string fs =
4147 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03004148 precision mediump float;
4149 out vec4 color;
4150 uniform samplerCube uTex;
4151 void main(){
4152 color = texture(uTex, vec3(1.0));
4153 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03004154 ANGLE_GL_PROGRAM(program, vs, fs);
4155 glUseProgram(program);
4156
4157 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
4158 glActiveTexture(GL_TEXTURE0);
4159
4160 GLTexture cubeTex;
4161 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
4162
4163 const int kFaceWidth = 1;
4164 const int kFaceHeight = 1;
4165 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
4166 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4167 GL_UNSIGNED_BYTE, texData.data());
4168 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4169 GL_UNSIGNED_BYTE, texData.data());
4170 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4171 GL_UNSIGNED_BYTE, texData.data());
4172 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4173 GL_UNSIGNED_BYTE, texData.data());
4174 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4175 GL_UNSIGNED_BYTE, texData.data());
4176 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
4177 GL_UNSIGNED_BYTE, texData.data());
4178 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4179 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4180 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
4181 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
4182 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
4183 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
4184
4185 drawQuad(program, "pos", 0.5f, 1.0f, true);
4186 ASSERT_GL_NO_ERROR();
4187
4188 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4189}
4190
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08004191// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
4192TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
4193{
4194 GLuint texture = create2DTexture();
4195
4196 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
4197 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4198
4199 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
4200 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4201
4202 glDeleteTextures(1, &texture);
4203 EXPECT_GL_NO_ERROR();
4204}
4205
Olli Etuaho023371b2018-04-24 17:43:32 +03004206// Test setting base level after calling generateMipmap on a LUMA texture.
4207// Covers http://anglebug.com/2498
4208TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA)
4209{
4210 glActiveTexture(GL_TEXTURE0);
4211 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4212
4213 constexpr const GLsizei kWidth = 8;
4214 constexpr const GLsizei kHeight = 8;
4215 std::array<GLubyte, kWidth * kHeight * 2> whiteData;
4216 whiteData.fill(255u);
4217
4218 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA,
4219 GL_UNSIGNED_BYTE, whiteData.data());
4220 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
4221 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4222 glGenerateMipmap(GL_TEXTURE_2D);
4223 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
4224 EXPECT_GL_NO_ERROR();
4225
4226 drawQuad(mProgram, "position", 0.5f);
4227 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
4228}
4229
Till Rathmannc1551dc2018-08-15 17:04:49 +02004230// Covers a bug in the D3D11 backend: http://anglebug.com/2772
4231// When using a sampler the texture was created as if it has mipmaps,
4232// regardless what you specified in GL_TEXTURE_MIN_FILTER via
4233// glSamplerParameteri() -- mistakenly the default value
4234// GL_NEAREST_MIPMAP_LINEAR or the value set via glTexParameteri() was
4235// evaluated.
4236// If you didn't provide mipmaps and didn't let the driver generate them
4237// this led to not sampling your texture data when minification occurred.
4238TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping)
4239{
4240 const std::string vs =
4241 "#version 300 es\n"
4242 "out vec2 texcoord;\n"
4243 "in vec4 position;\n"
4244 "void main()\n"
4245 "{\n"
4246 " gl_Position = vec4(position.xy * 0.1, 0.0, 1.0);\n"
4247 " texcoord = (position.xy * 0.5) + 0.5;\n"
4248 "}\n";
4249
4250 const std::string fs =
4251 "#version 300 es\n"
4252 "precision highp float;\n"
4253 "uniform highp sampler2D tex;\n"
4254 "in vec2 texcoord;\n"
4255 "out vec4 fragColor;\n"
4256 "void main()\n"
4257 "{\n"
4258 " fragColor = texture(tex, texcoord);\n"
4259 "}\n";
4260 ANGLE_GL_PROGRAM(program, vs, fs);
4261
4262 GLSampler sampler;
4263 glBindSampler(0, sampler);
4264 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4265 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4266
4267 glActiveTexture(GL_TEXTURE0);
4268 glBindTexture(GL_TEXTURE_2D, mTexture2D);
4269
4270 const GLsizei texWidth = getWindowWidth();
4271 const GLsizei texHeight = getWindowHeight();
4272 const std::vector<GLColor> whiteData(texWidth * texHeight, GLColor::white);
4273
4274 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
4275 whiteData.data());
4276 EXPECT_GL_NO_ERROR();
4277
4278 drawQuad(program, "position", 0.5f);
4279 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, angle::GLColor::white);
4280}
4281
Jamie Madill50cf2be2018-06-15 09:46:57 -04004282// Use this to select which configurations (e.g. which renderer, which GLES major version) these
4283// tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -05004284ANGLE_INSTANTIATE_TEST(Texture2DTest,
4285 ES2_D3D9(),
4286 ES2_D3D11(),
4287 ES2_D3D11_FL9_3(),
4288 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05004289 ES2_OPENGLES(),
4290 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004291ANGLE_INSTANTIATE_TEST(TextureCubeTest,
4292 ES2_D3D9(),
4293 ES2_D3D11(),
Geoff Langf7480ad2017-10-24 11:46:02 -04004294 ES2_D3D11_FL10_0(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004295 ES2_D3D11_FL9_3(),
4296 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004297 ES2_OPENGLES(),
4298 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004299ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
4300 ES2_D3D9(),
4301 ES2_D3D11(),
4302 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004303 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04004304 ES2_OPENGLES(),
4305 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004306ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
4307 ES2_D3D9(),
4308 ES2_D3D11(),
4309 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004310 ES2_OPENGL(),
4311 ES2_OPENGLES());
4312ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
4313 ES2_D3D9(),
4314 ES2_D3D11(),
4315 ES2_D3D11_FL9_3(),
4316 ES2_OPENGL(),
4317 ES2_OPENGLES());
4318ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
4319 ES2_D3D9(),
4320 ES2_D3D11(),
4321 ES2_D3D11_FL9_3(),
4322 ES2_OPENGL(),
4323 ES2_OPENGLES());
4324ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02004325ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02004326ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4327ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
4328 ES3_D3D11(),
4329 ES3_OPENGL(),
4330 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004331ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
4332 ES3_D3D11(),
4333 ES3_OPENGL(),
4334 ES3_OPENGLES());
4335ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4336ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02004337ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02004338ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
4339 ES2_D3D11(),
4340 ES2_D3D11_FL9_3(),
4341 ES2_D3D9(),
4342 ES2_OPENGL(),
4343 ES2_OPENGLES());
4344ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
4345 ES2_D3D11(),
4346 ES2_D3D11_FL9_3(),
4347 ES2_D3D9(),
4348 ES2_OPENGL(),
4349 ES2_OPENGLES());
4350ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
4351 ES2_D3D11(),
4352 ES2_D3D11_FL9_3(),
4353 ES2_D3D9(),
4354 ES2_OPENGL(),
4355 ES2_OPENGLES());
4356ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
4357 ES2_D3D11(),
4358 ES2_D3D11_FL9_3(),
4359 ES2_D3D9(),
4360 ES2_OPENGL(),
4361 ES2_OPENGLES());
4362ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
4363 ES2_D3D11(),
4364 ES2_D3D11_FL9_3(),
4365 ES2_D3D9(),
4366 ES2_OPENGL(),
4367 ES2_OPENGLES());
Till Rathmannb8543632018-10-02 19:46:14 +02004368ANGLE_INSTANTIATE_TEST(TextureBorderClampTest,
4369 ES2_D3D11(),
4370 ES2_D3D9(),
4371 ES2_OPENGL(),
4372 ES2_OPENGLES());
4373ANGLE_INSTANTIATE_TEST(TextureBorderClampTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4374ANGLE_INSTANTIATE_TEST(TextureBorderClampIntegerTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Luc Ferronaf883622018-06-08 15:57:31 -04004375ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN());
Vincent Lang25ab4512016-05-13 18:13:59 +02004376ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03004377ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04004378
Jamie Madill7ffdda92016-09-08 13:26:51 -04004379} // anonymous namespace