blob: f2a117c12968a8cc0f50ae8678be2dfb84e6de51 [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{
Luc Ferronaf883622018-06-08 15:57:31 -04001331 // TODO(lucferron): Diagnose and fix
1332 // http://anglebug.com/2653
1333 ANGLE_SKIP_TEST_IF(IsVulkan());
1334
Jamie Madill9aca0592014-10-06 16:26:59 -04001335 int px = getWindowWidth() / 2;
1336 int py = getWindowHeight() / 2;
1337
1338 glActiveTexture(GL_TEXTURE0);
1339 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1340
Olli Etuahoa314b612016-03-10 16:43:00 +02001341 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001342
Olli Etuahoa314b612016-03-10 16:43:00 +02001343 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001344 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1345 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1346 glGenerateMipmap(GL_TEXTURE_2D);
1347
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001348 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001349 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001350 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1351 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001352 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001353 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001354
Olli Etuahoa314b612016-03-10 16:43:00 +02001355 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001356
Olli Etuahoa314b612016-03-10 16:43:00 +02001357 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1358 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001359 glGenerateMipmap(GL_TEXTURE_2D);
1360
Olli Etuahoa314b612016-03-10 16:43:00 +02001361 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001362
Olli Etuahoa314b612016-03-10 16:43:00 +02001363 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1364 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001365 glGenerateMipmap(GL_TEXTURE_2D);
1366
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001367 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001368
1369 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001370 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001371}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001372
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001373// Test creating a FBO with a cube map render target, to test an ANGLE bug
1374// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001375TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001376{
1377 GLuint fbo;
1378 glGenFramebuffers(1, &fbo);
1379 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1380
1381 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Jamie Madill50cf2be2018-06-15 09:46:57 -04001382 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1383 mTextureCube, 0);
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001384
Corentin Wallez322653b2015-06-17 18:33:56 +02001385 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001386
1387 glDeleteFramebuffers(1, &fbo);
1388
1389 EXPECT_GL_NO_ERROR();
1390}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001391
Jamie Madill50cf2be2018-06-15 09:46:57 -04001392// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a
1393// default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001394TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001395{
Luc Ferron7348fc52018-05-09 07:17:16 -04001396 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -04001397
Jamie Madill50cf2be2018-06-15 09:46:57 -04001398 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001399 int height = getWindowHeight();
1400
1401 GLuint tex2D;
1402 glGenTextures(1, &tex2D);
1403 glActiveTexture(GL_TEXTURE0);
1404 glBindTexture(GL_TEXTURE_2D, tex2D);
1405
1406 // Fill with red
1407 std::vector<GLubyte> pixels(3 * 16 * 16);
1408 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1409 {
1410 pixels[pixelId * 3 + 0] = 255;
1411 pixels[pixelId * 3 + 1] = 0;
1412 pixels[pixelId * 3 + 2] = 0;
1413 }
1414
1415 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001416 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1417 // 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 -04001418 if (getClientMajorVersion() >= 3)
1419 {
1420 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1421 }
1422 else
1423 {
1424 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1425 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001426
1427 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1428 // glTexSubImage2D should take into account that the image is dirty.
1429 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1430 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1431 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1432
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001433 setUpProgram();
1434
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001435 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001436 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001437 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001438 glDeleteTextures(1, &tex2D);
1439 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001440 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001441
1442 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001443 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1444 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001445}
1446
Jamie Madill50cf2be2018-06-15 09:46:57 -04001447// Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has
1448// initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001449TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001450{
1451 if (extensionEnabled("NV_pixel_buffer_object"))
1452 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04001453 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001454 int height = getWindowHeight();
1455
1456 GLuint tex2D;
1457 glGenTextures(1, &tex2D);
1458 glActiveTexture(GL_TEXTURE0);
1459 glBindTexture(GL_TEXTURE_2D, tex2D);
1460
1461 // Fill with red
1462 std::vector<GLubyte> pixels(3 * 16 * 16);
1463 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1464 {
1465 pixels[pixelId * 3 + 0] = 255;
1466 pixels[pixelId * 3 + 1] = 0;
1467 pixels[pixelId * 3 + 2] = 0;
1468 }
1469
1470 // Read 16x16 region from red backbuffer to PBO
1471 GLuint pbo;
1472 glGenBuffers(1, &pbo);
1473 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1474 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1475
1476 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001477 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1478 // 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 +00001479 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1480
1481 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1482 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001483 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 +00001484 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1485 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1486
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001487 setUpProgram();
1488
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001489 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001490 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001491 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001492 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001493 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001494 EXPECT_GL_NO_ERROR();
1495 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1496 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1497 }
1498}
Jamie Madillbc393df2015-01-29 13:46:07 -05001499
1500// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001501TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001502{
1503 testFloatCopySubImage(1, 1);
1504}
1505
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001506TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001507{
1508 testFloatCopySubImage(2, 1);
1509}
1510
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001511TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001512{
1513 testFloatCopySubImage(2, 2);
1514}
1515
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001516TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001517{
1518 testFloatCopySubImage(3, 1);
1519}
1520
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001521TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001522{
1523 testFloatCopySubImage(3, 2);
1524}
1525
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001526TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001527{
Yunchao He9550c602018-02-13 14:47:05 +08001528 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1529 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001530
Yunchao He9550c602018-02-13 14:47:05 +08001531 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1532 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001533
Jamie Madillbc393df2015-01-29 13:46:07 -05001534 testFloatCopySubImage(3, 3);
1535}
1536
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001537TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001538{
1539 testFloatCopySubImage(4, 1);
1540}
1541
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001542TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001543{
1544 testFloatCopySubImage(4, 2);
1545}
1546
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001547TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001548{
Yunchao He9550c602018-02-13 14:47:05 +08001549 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1550 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001551
Jamie Madillbc393df2015-01-29 13:46:07 -05001552 testFloatCopySubImage(4, 3);
1553}
1554
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001555TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001556{
Luc Ferronf786b702018-07-10 11:01:43 -04001557 // TODO(lucferron): This test fails only on linux and intel.
1558 // http://anglebug.com/2726
1559 ANGLE_SKIP_TEST_IF(IsVulkan() && IsLinux() && IsIntel());
1560
Yunchao He9550c602018-02-13 14:47:05 +08001561 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1562 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001563
Jamie Madillbc393df2015-01-29 13:46:07 -05001564 testFloatCopySubImage(4, 4);
1565}
Austin Kinross07285142015-03-26 11:36:16 -07001566
Jamie Madill50cf2be2018-06-15 09:46:57 -04001567// Port of
1568// https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1569// Run against GL_ALPHA/UNSIGNED_BYTE format, to ensure that D3D11 Feature Level 9_3 correctly
1570// handles GL_ALPHA
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001571TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001572{
1573 const int npotTexSize = 5;
Jamie Madill50cf2be2018-06-15 09:46:57 -04001574 const int potTexSize = 4; // Should be less than npotTexSize
Austin Kinross07285142015-03-26 11:36:16 -07001575 GLuint tex2D;
1576
1577 if (extensionEnabled("GL_OES_texture_npot"))
1578 {
1579 // This test isn't applicable if texture_npot is enabled
1580 return;
1581 }
1582
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001583 setUpProgram();
1584
Austin Kinross07285142015-03-26 11:36:16 -07001585 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1586
Austin Kinross5faa15b2016-01-11 13:32:48 -08001587 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1588 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1589
Austin Kinross07285142015-03-26 11:36:16 -07001590 glActiveTexture(GL_TEXTURE0);
1591 glGenTextures(1, &tex2D);
1592 glBindTexture(GL_TEXTURE_2D, tex2D);
1593
Till Rathmannc1551dc2018-08-15 17:04:49 +02001594 const std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize, 64);
Austin Kinross07285142015-03-26 11:36:16 -07001595
1596 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1597 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1598
1599 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
Jamie Madill50cf2be2018-06-15 09:46:57 -04001600 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1601 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001602 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1603
1604 // Check that an NPOT texture on level 0 succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001605 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1606 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001607 EXPECT_GL_NO_ERROR();
1608
1609 // Check that generateMipmap fails on NPOT
1610 glGenerateMipmap(GL_TEXTURE_2D);
1611 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1612
1613 // Check that nothing is drawn if filtering is not correct for NPOT
1614 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1615 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1616 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1617 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1618 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001619 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001620 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1621
1622 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1623 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1624 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1625 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1626 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001627 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001628 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1629
1630 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1631 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1632 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001633 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001634 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1635
1636 // Check that glTexImage2D for POT texture succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001637 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE,
1638 pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001639 EXPECT_GL_NO_ERROR();
1640
1641 // Check that generateMipmap for an POT texture succeeds
1642 glGenerateMipmap(GL_TEXTURE_2D);
1643 EXPECT_GL_NO_ERROR();
1644
1645 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1646 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1647 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1648 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1649 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1650 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001651 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001652 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1653 EXPECT_GL_NO_ERROR();
1654}
Jamie Madillfa05f602015-05-07 13:47:11 -04001655
Austin Kinross08528e12015-10-07 16:24:40 -07001656// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1657// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001658TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001659{
1660 glActiveTexture(GL_TEXTURE0);
1661 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1662
1663 // Create an 8x8 (i.e. power-of-two) texture.
1664 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1665 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1666 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1667 glGenerateMipmap(GL_TEXTURE_2D);
1668
1669 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1670 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001671 std::array<GLColor, 3 * 3> data;
1672 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001673
1674 EXPECT_GL_NO_ERROR();
1675}
1676
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001677// Test to check that texture completeness is determined correctly when the texture base level is
1678// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1679TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1680{
1681 glActiveTexture(GL_TEXTURE0);
1682 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001683
1684 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1685 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1686 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1687 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1688 texDataGreen.data());
1689 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1690 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001691 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1692 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1693 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1694
1695 EXPECT_GL_NO_ERROR();
1696
1697 drawQuad(mProgram, "position", 0.5f);
1698
Olli Etuahoa314b612016-03-10 16:43:00 +02001699 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1700}
1701
1702// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1703// have images defined.
1704TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1705{
Yunchao He9550c602018-02-13 14:47:05 +08001706 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1707 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1708
Olli Etuahoa314b612016-03-10 16:43:00 +02001709 glActiveTexture(GL_TEXTURE0);
1710 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1711 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1712 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1713 texDataGreen.data());
1714 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1715 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1716 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1717 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1718
1719 EXPECT_GL_NO_ERROR();
1720
1721 drawQuad(mProgram, "position", 0.5f);
1722
1723 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1724}
1725
Olli Etuahoe8528d82016-05-16 17:50:52 +03001726// Test that drawing works correctly when level 0 is undefined and base level is 1.
1727TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1728{
Yunchao He9550c602018-02-13 14:47:05 +08001729 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1730 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1731
Olli Etuahoe8528d82016-05-16 17:50:52 +03001732 glActiveTexture(GL_TEXTURE0);
1733 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1734 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1735 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1736 texDataGreen.data());
1737 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1738 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1739 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1740 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1741
1742 EXPECT_GL_NO_ERROR();
1743
1744 // Texture is incomplete.
1745 drawQuad(mProgram, "position", 0.5f);
1746 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1747
1748 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1749 texDataGreen.data());
1750
1751 // Texture is now complete.
1752 drawQuad(mProgram, "position", 0.5f);
1753 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1754}
1755
Olli Etuahoa314b612016-03-10 16:43:00 +02001756// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1757// dimensions that don't fit the images inside the range.
1758// GLES 3.0.4 section 3.8.13 Texture completeness
1759TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1760{
Olli Etuahoa314b612016-03-10 16:43:00 +02001761 glActiveTexture(GL_TEXTURE0);
1762 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1763 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1764 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1765 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1766
1767 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1768 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1769
1770 // Two levels that are initially unused.
1771 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1772 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1773 texDataCyan.data());
1774
1775 // One level that is used - only this level should affect completeness.
1776 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1777 texDataGreen.data());
1778
1779 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1780 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1781
1782 EXPECT_GL_NO_ERROR();
1783
1784 drawQuad(mProgram, "position", 0.5f);
1785
1786 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1787
Yunchao He2f23f352018-02-11 22:11:37 +08001788 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001789
1790 // Switch the level that is being used to the cyan level 2.
1791 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1792 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1793
1794 EXPECT_GL_NO_ERROR();
1795
1796 drawQuad(mProgram, "position", 0.5f);
1797
1798 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1799}
1800
1801// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1802// have images defined.
1803TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1804{
Olli Etuahoa314b612016-03-10 16:43:00 +02001805 glActiveTexture(GL_TEXTURE0);
1806 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1807 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1808 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1809 texDataGreen.data());
1810 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1811 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1812 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1813 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1814
1815 EXPECT_GL_NO_ERROR();
1816
1817 drawQuad(mProgram, "position", 0.5f);
1818
1819 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1820}
1821
1822// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1823// dimensions that don't fit the images inside the range.
1824// GLES 3.0.4 section 3.8.13 Texture completeness
1825TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1826{
Olli Etuahoa314b612016-03-10 16:43:00 +02001827 glActiveTexture(GL_TEXTURE0);
1828 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1829 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1830 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1831 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1832
1833 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1834 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1835
1836 // Two levels that are initially unused.
1837 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1838 texDataRed.data());
1839 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1840 texDataCyan.data());
1841
1842 // One level that is used - only this level should affect completeness.
1843 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1844 texDataGreen.data());
1845
1846 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1847 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1848
1849 EXPECT_GL_NO_ERROR();
1850
1851 drawQuad(mProgram, "position", 0.5f);
1852
1853 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1854
Yunchao He2f23f352018-02-11 22:11:37 +08001855 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001856
1857 // Switch the level that is being used to the cyan level 2.
1858 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
1859 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
1860
1861 EXPECT_GL_NO_ERROR();
1862
1863 drawQuad(mProgram, "position", 0.5f);
1864
1865 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1866}
1867
1868// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1869// have images defined.
1870TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
1871{
Olli Etuahoa314b612016-03-10 16:43:00 +02001872 glActiveTexture(GL_TEXTURE0);
1873 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
1874 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1875 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1876 texDataGreen.data());
1877 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1878 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1879 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1880 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1881
1882 EXPECT_GL_NO_ERROR();
1883
1884 drawQuad(mProgram, "position", 0.5f);
1885
1886 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1887}
1888
1889// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1890// dimensions that don't fit the images inside the range.
1891// GLES 3.0.4 section 3.8.13 Texture completeness
1892TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1893{
Olli Etuahoa314b612016-03-10 16:43:00 +02001894 glActiveTexture(GL_TEXTURE0);
1895 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
1896 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1897 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1898 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1899
1900 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1901 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1902
1903 // Two levels that are initially unused.
1904 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1905 texDataRed.data());
1906 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1907 texDataCyan.data());
1908
1909 // One level that is used - only this level should affect completeness.
1910 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1911 texDataGreen.data());
1912
1913 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1914 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1915
1916 EXPECT_GL_NO_ERROR();
1917
1918 drawQuad(mProgram, "position", 0.5f);
1919
1920 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1921
Yunchao He2f23f352018-02-11 22:11:37 +08001922 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
1923
Yunchao He9550c602018-02-13 14:47:05 +08001924 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
1925 // level was changed.
1926 ANGLE_SKIP_TEST_IF(IsNVIDIA() && (IsOpenGL() || IsOpenGLES()));
Olli Etuahoa314b612016-03-10 16:43:00 +02001927
1928 // Switch the level that is being used to the cyan level 2.
1929 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
1930 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
1931
1932 EXPECT_GL_NO_ERROR();
1933
1934 drawQuad(mProgram, "position", 0.5f);
1935
1936 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1937}
1938
1939// Test that texture completeness is updated if texture max level changes.
1940// GLES 3.0.4 section 3.8.13 Texture completeness
1941TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
1942{
Olli Etuahoa314b612016-03-10 16:43:00 +02001943 glActiveTexture(GL_TEXTURE0);
1944 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1945 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
1946
1947 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1948 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1949
1950 // A level that is initially unused.
1951 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1952 texDataGreen.data());
1953
1954 // One level that is initially used - only this level should affect completeness.
1955 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1956 texDataGreen.data());
1957
1958 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
1959 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
1960
1961 EXPECT_GL_NO_ERROR();
1962
1963 drawQuad(mProgram, "position", 0.5f);
1964
1965 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1966
1967 // Switch the max level to level 1. The levels within the used range now have inconsistent
1968 // dimensions and the texture should be incomplete.
1969 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1970
1971 EXPECT_GL_NO_ERROR();
1972
1973 drawQuad(mProgram, "position", 0.5f);
1974
1975 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1976}
1977
1978// Test that 3D texture completeness is updated if texture max level changes.
1979// GLES 3.0.4 section 3.8.13 Texture completeness
1980TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
1981{
Olli Etuahoa314b612016-03-10 16:43:00 +02001982 glActiveTexture(GL_TEXTURE0);
1983 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1984 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1985
1986 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1987 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1988
1989 // A level that is initially unused.
1990 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1991 texDataGreen.data());
1992
1993 // One level that is initially used - only this level should affect completeness.
1994 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1995 texDataGreen.data());
1996
1997 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
1998 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
1999
2000 EXPECT_GL_NO_ERROR();
2001
2002 drawQuad(mProgram, "position", 0.5f);
2003
2004 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2005
2006 // Switch the max level to level 1. The levels within the used range now have inconsistent
2007 // dimensions and the texture should be incomplete.
2008 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2009
2010 EXPECT_GL_NO_ERROR();
2011
2012 drawQuad(mProgram, "position", 0.5f);
2013
2014 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2015}
2016
2017// Test that texture completeness is updated if texture base level changes.
2018// GLES 3.0.4 section 3.8.13 Texture completeness
2019TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2020{
Olli Etuahoa314b612016-03-10 16:43:00 +02002021 glActiveTexture(GL_TEXTURE0);
2022 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2023 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2024
2025 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2026 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2027
2028 // Two levels that are initially unused.
2029 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2030 texDataGreen.data());
2031 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2032 texDataGreen.data());
2033
2034 // One level that is initially used - only this level should affect completeness.
2035 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2036 texDataGreen.data());
2037
2038 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2039 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2040
2041 EXPECT_GL_NO_ERROR();
2042
2043 drawQuad(mProgram, "position", 0.5f);
2044
2045 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2046
2047 // Switch the base level to level 1. The levels within the used range now have inconsistent
2048 // dimensions and the texture should be incomplete.
2049 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2050
2051 EXPECT_GL_NO_ERROR();
2052
2053 drawQuad(mProgram, "position", 0.5f);
2054
2055 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2056}
2057
2058// Test that texture is not complete if base level is greater than max level.
2059// GLES 3.0.4 section 3.8.13 Texture completeness
2060TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2061{
Olli Etuahoa314b612016-03-10 16:43:00 +02002062 glActiveTexture(GL_TEXTURE0);
2063 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2064
2065 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2066 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2067
2068 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2069
2070 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2071 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2072
2073 EXPECT_GL_NO_ERROR();
2074
2075 drawQuad(mProgram, "position", 0.5f);
2076
2077 // Texture should be incomplete.
2078 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2079}
2080
2081// Test that immutable texture base level and max level are clamped.
2082// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2083TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2084{
Olli Etuahoa314b612016-03-10 16:43:00 +02002085 glActiveTexture(GL_TEXTURE0);
2086 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2087
2088 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2089 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2090
2091 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2092
2093 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2094
2095 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2096 // should be clamped to [base_level, levels - 1].
2097 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2098 // In the case of this test, those rules make the effective base level and max level 0.
2099 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2100 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2101
2102 EXPECT_GL_NO_ERROR();
2103
2104 drawQuad(mProgram, "position", 0.5f);
2105
2106 // Texture should be complete.
2107 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2108}
2109
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002110// Test that changing base level works when it affects the format of the texture.
2111TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2112{
Yunchao He9550c602018-02-13 14:47:05 +08002113 // Observed rendering corruption on NVIDIA OpenGL.
2114 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL());
2115
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002116 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002117
2118 // Observed incorrect rendering on AMD OpenGL.
2119 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002120
2121 glActiveTexture(GL_TEXTURE0);
2122 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2123 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2124 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2125
2126 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2127 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2128
2129 // RGBA8 level that's initially unused.
2130 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2131 texDataCyan.data());
2132
2133 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2134 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2135
2136 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2137 // format. It reads green channel data from the green and alpha channels of texDataGreen
2138 // (this is a bit hacky but works).
2139 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2140
2141 EXPECT_GL_NO_ERROR();
2142
2143 drawQuad(mProgram, "position", 0.5f);
2144
2145 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2146
2147 // Switch the texture to use the cyan level 0 with the RGBA format.
2148 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2149 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2150
2151 EXPECT_GL_NO_ERROR();
2152
2153 drawQuad(mProgram, "position", 0.5f);
2154
2155 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2156}
2157
Olli Etuahoa314b612016-03-10 16:43:00 +02002158// Test that setting a texture image works when base level is out of range.
2159TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2160{
2161 glActiveTexture(GL_TEXTURE0);
2162 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2163
2164 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2165 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2166
2167 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2168 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2169
2170 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2171
2172 EXPECT_GL_NO_ERROR();
2173
2174 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2175
2176 drawQuad(mProgram, "position", 0.5f);
2177
2178 // Texture should be complete.
2179 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002180}
2181
Jamie Madill50cf2be2018-06-15 09:46:57 -04002182// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG
2183// RBA->RGBA8, with 1.0 in the alpha channel. This test covers a bug where redefining array textures
2184// with these formats does not work as expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002185TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002186{
2187 std::vector<GLubyte> pixelData;
2188 for (size_t count = 0; count < 5000; count++)
2189 {
2190 pixelData.push_back(0u);
2191 pixelData.push_back(255u);
2192 pixelData.push_back(0u);
2193 }
2194
2195 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002196 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002197 glUniform1i(mTextureArrayLocation, 0);
2198
2199 // The first draw worked correctly.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002200 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2201 &pixelData[0]);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002202
2203 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2204 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2205 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2206 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002207 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002208 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002209
2210 // The dimension of the respecification must match the original exactly to trigger the bug.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002211 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2212 &pixelData[0]);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002213 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002214 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002215
2216 ASSERT_GL_NO_ERROR();
2217}
2218
Olli Etuaho1a679902016-01-14 12:21:47 +02002219// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2220// This test is needed especially to confirm that sampler registers get assigned correctly on
2221// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2222TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2223{
2224 glActiveTexture(GL_TEXTURE0);
2225 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2226 GLubyte texData[4];
2227 texData[0] = 0;
2228 texData[1] = 60;
2229 texData[2] = 0;
2230 texData[3] = 255;
2231 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2232
2233 glActiveTexture(GL_TEXTURE1);
2234 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2235 GLfloat depthTexData[1];
2236 depthTexData[0] = 0.5f;
2237 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2238 depthTexData);
2239
2240 glUseProgram(mProgram);
2241 glUniform1f(mDepthRefUniformLocation, 0.3f);
2242 glUniform1i(mTexture3DUniformLocation, 0);
2243 glUniform1i(mTextureShadowUniformLocation, 1);
2244
2245 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2246 drawQuad(mProgram, "position", 0.5f);
2247 EXPECT_GL_NO_ERROR();
2248 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2249 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2250
2251 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2252 drawQuad(mProgram, "position", 0.5f);
2253 EXPECT_GL_NO_ERROR();
2254 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2255 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2256}
2257
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002258// Test multiple different sampler types in the same shader.
2259// This test makes sure that even if sampler / texture registers get grouped together based on type
2260// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2261// still has the right register index information for each ESSL sampler.
2262// The tested ESSL samplers have the following types in D3D11 HLSL:
2263// sampler2D: Texture2D + SamplerState
2264// samplerCube: TextureCube + SamplerState
2265// sampler2DShadow: Texture2D + SamplerComparisonState
2266// samplerCubeShadow: TextureCube + SamplerComparisonState
2267TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2268{
2269 glActiveTexture(GL_TEXTURE0);
2270 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2271 GLubyte texData[4];
2272 texData[0] = 0;
2273 texData[1] = 0;
2274 texData[2] = 120;
2275 texData[3] = 255;
2276 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2277
2278 glActiveTexture(GL_TEXTURE1);
2279 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2280 texData[0] = 0;
2281 texData[1] = 90;
2282 texData[2] = 0;
2283 texData[3] = 255;
2284 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2285 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2286 texData);
2287
2288 glActiveTexture(GL_TEXTURE2);
2289 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2290 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2291 GLfloat depthTexData[1];
2292 depthTexData[0] = 0.5f;
2293 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2294 depthTexData);
2295
2296 glActiveTexture(GL_TEXTURE3);
2297 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2298 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2299 depthTexData[0] = 0.2f;
2300 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2301 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2302 depthTexData);
2303
2304 EXPECT_GL_NO_ERROR();
2305
2306 glUseProgram(mProgram);
2307 glUniform1f(mDepthRefUniformLocation, 0.3f);
2308 glUniform1i(mTexture2DUniformLocation, 0);
2309 glUniform1i(mTextureCubeUniformLocation, 1);
2310 glUniform1i(mTexture2DShadowUniformLocation, 2);
2311 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2312
2313 drawQuad(mProgram, "position", 0.5f);
2314 EXPECT_GL_NO_ERROR();
2315 // The shader writes:
2316 // <texture 2d color> +
2317 // <cube map color> +
2318 // 0.25 * <comparison result (1.0)> +
2319 // 0.125 * <comparison result (0.0)>
2320 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2321}
2322
Olli Etuahobce743a2016-01-15 17:18:28 +02002323// Test different base levels on textures accessed through the same sampler array.
2324// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2325TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2326{
Yunchao He9550c602018-02-13 14:47:05 +08002327 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2328
Olli Etuahobce743a2016-01-15 17:18:28 +02002329 glActiveTexture(GL_TEXTURE0);
2330 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2331 GLsizei size = 64;
2332 for (GLint level = 0; level < 7; ++level)
2333 {
2334 ASSERT_LT(0, size);
2335 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2336 nullptr);
2337 size = size / 2;
2338 }
2339 ASSERT_EQ(0, size);
2340 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2341
2342 glActiveTexture(GL_TEXTURE1);
2343 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2344 size = 128;
2345 for (GLint level = 0; level < 8; ++level)
2346 {
2347 ASSERT_LT(0, size);
2348 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2349 nullptr);
2350 size = size / 2;
2351 }
2352 ASSERT_EQ(0, size);
2353 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2354 EXPECT_GL_NO_ERROR();
2355
2356 glUseProgram(mProgram);
2357 glUniform1i(mTexture0Location, 0);
2358 glUniform1i(mTexture1Location, 1);
2359
Olli Etuaho5804dc82018-04-13 14:11:46 +03002360 drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
Olli Etuahobce743a2016-01-15 17:18:28 +02002361 EXPECT_GL_NO_ERROR();
2362 // Red channel: width of level 1 of texture A: 32.
2363 // Green channel: width of level 3 of texture B: 16.
2364 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2365}
2366
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002367// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2368// ES 3.0.4 table 3.24
2369TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2370{
2371 glActiveTexture(GL_TEXTURE0);
2372 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2373 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2374 EXPECT_GL_NO_ERROR();
2375
2376 drawQuad(mProgram, "position", 0.5f);
2377
2378 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2379}
2380
2381// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2382// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002383TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002384{
Luc Ferron5164b792018-03-06 09:10:12 -05002385 setUpProgram();
2386
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002387 glActiveTexture(GL_TEXTURE0);
2388 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2389 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2390 EXPECT_GL_NO_ERROR();
2391
2392 drawQuad(mProgram, "position", 0.5f);
2393
2394 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2395}
2396
Luc Ferron5164b792018-03-06 09:10:12 -05002397// Validate that every component of the pixel will be equal to the luminance value we've set
2398// and that the alpha channel will be 1 (or 255 to be exact).
2399TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2400{
2401 setUpProgram();
2402
2403 glActiveTexture(GL_TEXTURE0);
2404 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2405 uint8_t pixel = 50;
2406 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2407 EXPECT_GL_NO_ERROR();
2408
2409 drawQuad(mProgram, "position", 0.5f);
2410
2411 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2412}
2413
2414// Validate that every component of the pixel will be equal to the luminance value we've set
2415// and that the alpha channel will be the second component.
2416TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2417{
2418 setUpProgram();
2419
2420 glActiveTexture(GL_TEXTURE0);
2421 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2422 uint8_t pixel[] = {50, 25};
2423 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2424 GL_UNSIGNED_BYTE, pixel);
2425 EXPECT_GL_NO_ERROR();
2426
2427 drawQuad(mProgram, "position", 0.5f);
2428
2429 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2430}
2431
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002432// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2433// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002434TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002435{
Luc Ferrond8c632c2018-04-10 12:31:44 -04002436 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
2437 ANGLE_SKIP_TEST_IF(IsD3D9());
2438 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002439
2440 setUpProgram();
2441
Luc Ferrond8c632c2018-04-10 12:31:44 -04002442 glActiveTexture(GL_TEXTURE0);
2443 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2444 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2445 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002446
Luc Ferrond8c632c2018-04-10 12:31:44 -04002447 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002448
Luc Ferrond8c632c2018-04-10 12:31:44 -04002449 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002450}
2451
2452// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2453// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002454TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002455{
Luc Ferrond8c632c2018-04-10 12:31:44 -04002456 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
2457 ANGLE_SKIP_TEST_IF(IsD3D9());
2458 ANGLE_SKIP_TEST_IF(IsVulkan());
2459 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES());
2460 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2461 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002462
Luc Ferrond8c632c2018-04-10 12:31:44 -04002463 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002464
Luc Ferrond8c632c2018-04-10 12:31:44 -04002465 glActiveTexture(GL_TEXTURE0);
2466 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2467 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2468 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002469
Luc Ferrond8c632c2018-04-10 12:31:44 -04002470 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002471
Luc Ferrond8c632c2018-04-10 12:31:44 -04002472 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002473}
2474
2475// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2476// ES 3.0.4 table 3.24
2477TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2478{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002479 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2480
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002481 glActiveTexture(GL_TEXTURE0);
2482 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2483 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2484 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2485 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2486 EXPECT_GL_NO_ERROR();
2487
2488 drawQuad(mProgram, "position", 0.5f);
2489
2490 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2491}
2492
2493// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2494// ES 3.0.4 table 3.24
2495TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2496{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002497 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2498
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002499 glActiveTexture(GL_TEXTURE0);
2500 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2501
2502 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2503 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2504 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2505 EXPECT_GL_NO_ERROR();
2506
2507 drawQuad(mProgram, "position", 0.5f);
2508
2509 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2510}
2511
2512// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2513// ES 3.0.4 table 3.24
2514TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2515{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002516 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2517
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002518 glActiveTexture(GL_TEXTURE0);
2519 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2520 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2521 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2522 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2523 EXPECT_GL_NO_ERROR();
2524
2525 drawQuad(mProgram, "position", 0.5f);
2526
2527 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2528}
2529
2530// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2531// ES 3.0.4 table 3.24
2532TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2533{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002534 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2535
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002536 glActiveTexture(GL_TEXTURE0);
2537 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2538 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2539 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2540 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2541 EXPECT_GL_NO_ERROR();
2542
2543 drawQuad(mProgram, "position", 0.5f);
2544
2545 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2546}
2547
2548// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2549// ES 3.0.4 table 3.24
2550TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2551{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002552 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2553
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002554 glActiveTexture(GL_TEXTURE0);
2555 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2556 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2557 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2558 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2559 EXPECT_GL_NO_ERROR();
2560
2561 drawQuad(mProgram, "position", 0.5f);
2562
2563 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2564}
2565
2566// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2567// ES 3.0.4 table 3.24
2568TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2569{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002570 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2571
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002572 glActiveTexture(GL_TEXTURE0);
2573 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2574 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2575 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2576 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2577 EXPECT_GL_NO_ERROR();
2578
2579 drawQuad(mProgram, "position", 0.5f);
2580
2581 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2582}
2583
2584// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2585// ES 3.0.4 table 3.24
2586TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2587{
2588 glActiveTexture(GL_TEXTURE0);
2589 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2590 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2591 EXPECT_GL_NO_ERROR();
2592
2593 drawQuad(mProgram, "position", 0.5f);
2594
2595 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2596}
2597
2598// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2599// ES 3.0.4 table 3.24
2600TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2601{
2602 glActiveTexture(GL_TEXTURE0);
2603 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2604 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2605 nullptr);
2606 EXPECT_GL_NO_ERROR();
2607
2608 drawQuad(mProgram, "position", 0.5f);
2609
2610 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2611}
2612
2613// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2614// ES 3.0.4 table 3.24
2615TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2616{
Yunchao He9550c602018-02-13 14:47:05 +08002617 // Seems to fail on OSX 10.12 Intel.
2618 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Jamie Madillbb1db482017-01-10 10:48:32 -05002619
Yuly Novikov49886892018-01-23 21:18:27 -05002620 // http://anglebug.com/2190
2621 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2622
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002623 glActiveTexture(GL_TEXTURE0);
2624 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2625 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2626 EXPECT_GL_NO_ERROR();
2627
2628 drawQuad(mProgram, "position", 0.5f);
2629
2630 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2631}
2632
2633// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2634// ES 3.0.4 table 3.24
2635TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2636{
Yunchao He9550c602018-02-13 14:47:05 +08002637 // Seems to fail on OSX 10.12 Intel.
2638 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002639
Yuly Novikov49886892018-01-23 21:18:27 -05002640 // http://anglebug.com/2190
2641 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2642
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002643 glActiveTexture(GL_TEXTURE0);
2644 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2645 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2646 EXPECT_GL_NO_ERROR();
2647
2648 drawQuad(mProgram, "position", 0.5f);
2649
2650 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2651}
2652
Olli Etuaho96963162016-03-21 11:54:33 +02002653// Use a sampler in a uniform struct.
2654TEST_P(SamplerInStructTest, SamplerInStruct)
2655{
2656 runSamplerInStructTest();
2657}
2658
2659// Use a sampler in a uniform struct that's passed as a function parameter.
2660TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2661{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002662 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002663 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002664
Olli Etuaho96963162016-03-21 11:54:33 +02002665 runSamplerInStructTest();
2666}
2667
2668// Use a sampler in a uniform struct array with a struct from the array passed as a function
2669// parameter.
2670TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2671{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002672 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002673 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
2674
Olli Etuaho96963162016-03-21 11:54:33 +02002675 runSamplerInStructTest();
2676}
2677
2678// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2679// parameter.
2680TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2681{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002682 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002683 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
2684
Olli Etuaho96963162016-03-21 11:54:33 +02002685 runSamplerInStructTest();
2686}
2687
2688// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2689// similarly named uniform.
2690TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2691{
2692 runSamplerInStructTest();
2693}
2694
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002695class TextureLimitsTest : public ANGLETest
2696{
2697 protected:
2698 struct RGBA8
2699 {
2700 uint8_t R, G, B, A;
2701 };
2702
2703 TextureLimitsTest()
2704 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
2705 {
2706 setWindowWidth(128);
2707 setWindowHeight(128);
2708 setConfigRedBits(8);
2709 setConfigGreenBits(8);
2710 setConfigBlueBits(8);
2711 setConfigAlphaBits(8);
2712 }
2713
2714 ~TextureLimitsTest()
2715 {
2716 if (mProgram != 0)
2717 {
2718 glDeleteProgram(mProgram);
2719 mProgram = 0;
2720
2721 if (!mTextures.empty())
2722 {
2723 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
2724 }
2725 }
2726 }
2727
2728 void SetUp() override
2729 {
2730 ANGLETest::SetUp();
2731
2732 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
2733 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
2734 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
2735
2736 ASSERT_GL_NO_ERROR();
2737 }
2738
2739 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
2740 GLint vertexTextureCount,
2741 GLint vertexActiveTextureCount,
2742 const std::string &fragPrefix,
2743 GLint fragmentTextureCount,
2744 GLint fragmentActiveTextureCount)
2745 {
2746 std::stringstream vertexShaderStr;
2747 vertexShaderStr << "attribute vec2 position;\n"
2748 << "varying vec4 color;\n"
2749 << "varying vec2 texCoord;\n";
2750
2751 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
2752 {
2753 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
2754 }
2755
2756 vertexShaderStr << "void main() {\n"
2757 << " gl_Position = vec4(position, 0, 1);\n"
2758 << " texCoord = (position * 0.5) + 0.5;\n"
2759 << " color = vec4(0);\n";
2760
2761 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
2762 {
2763 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
2764 << ", texCoord);\n";
2765 }
2766
2767 vertexShaderStr << "}";
2768
2769 std::stringstream fragmentShaderStr;
2770 fragmentShaderStr << "varying mediump vec4 color;\n"
2771 << "varying mediump vec2 texCoord;\n";
2772
2773 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
2774 {
2775 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
2776 }
2777
2778 fragmentShaderStr << "void main() {\n"
2779 << " gl_FragColor = color;\n";
2780
2781 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
2782 {
2783 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
2784 << ", texCoord);\n";
2785 }
2786
2787 fragmentShaderStr << "}";
2788
2789 const std::string &vertexShaderSource = vertexShaderStr.str();
2790 const std::string &fragmentShaderSource = fragmentShaderStr.str();
2791
2792 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
2793 }
2794
2795 RGBA8 getPixel(GLint texIndex)
2796 {
2797 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
2798 0, 255u};
2799 return pixel;
2800 }
2801
2802 void initTextures(GLint tex2DCount, GLint texCubeCount)
2803 {
2804 GLint totalCount = tex2DCount + texCubeCount;
2805 mTextures.assign(totalCount, 0);
2806 glGenTextures(totalCount, &mTextures[0]);
2807 ASSERT_GL_NO_ERROR();
2808
2809 std::vector<RGBA8> texData(16 * 16);
2810
2811 GLint texIndex = 0;
2812 for (; texIndex < tex2DCount; ++texIndex)
2813 {
2814 texData.assign(texData.size(), getPixel(texIndex));
2815 glActiveTexture(GL_TEXTURE0 + texIndex);
2816 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
2817 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2818 &texData[0]);
2819 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2820 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2821 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2822 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2823 }
2824
2825 ASSERT_GL_NO_ERROR();
2826
2827 for (; texIndex < texCubeCount; ++texIndex)
2828 {
2829 texData.assign(texData.size(), getPixel(texIndex));
2830 glActiveTexture(GL_TEXTURE0 + texIndex);
2831 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
2832 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2833 GL_UNSIGNED_BYTE, &texData[0]);
2834 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2835 GL_UNSIGNED_BYTE, &texData[0]);
2836 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2837 GL_UNSIGNED_BYTE, &texData[0]);
2838 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2839 GL_UNSIGNED_BYTE, &texData[0]);
2840 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2841 GL_UNSIGNED_BYTE, &texData[0]);
2842 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2843 GL_UNSIGNED_BYTE, &texData[0]);
2844 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2845 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2846 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2847 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2848 }
2849
2850 ASSERT_GL_NO_ERROR();
2851 }
2852
2853 void testWithTextures(GLint vertexTextureCount,
2854 const std::string &vertexTexturePrefix,
2855 GLint fragmentTextureCount,
2856 const std::string &fragmentTexturePrefix)
2857 {
2858 // Generate textures
2859 initTextures(vertexTextureCount + fragmentTextureCount, 0);
2860
2861 glUseProgram(mProgram);
2862 RGBA8 expectedSum = {0};
2863 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
2864 {
2865 std::stringstream uniformNameStr;
2866 uniformNameStr << vertexTexturePrefix << texIndex;
2867 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04002868 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002869 ASSERT_NE(-1, location);
2870
2871 glUniform1i(location, texIndex);
2872 RGBA8 contribution = getPixel(texIndex);
2873 expectedSum.R += contribution.R;
2874 expectedSum.G += contribution.G;
2875 }
2876
2877 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
2878 {
2879 std::stringstream uniformNameStr;
2880 uniformNameStr << fragmentTexturePrefix << texIndex;
2881 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04002882 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002883 ASSERT_NE(-1, location);
2884
2885 glUniform1i(location, texIndex + vertexTextureCount);
2886 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
2887 expectedSum.R += contribution.R;
2888 expectedSum.G += contribution.G;
2889 }
2890
2891 ASSERT_GE(256u, expectedSum.G);
2892
2893 drawQuad(mProgram, "position", 0.5f);
2894 ASSERT_GL_NO_ERROR();
2895 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
2896 }
2897
2898 GLuint mProgram;
2899 std::vector<GLuint> mTextures;
2900 GLint mMaxVertexTextures;
2901 GLint mMaxFragmentTextures;
2902 GLint mMaxCombinedTextures;
2903};
2904
2905// Test rendering with the maximum vertex texture units.
2906TEST_P(TextureLimitsTest, MaxVertexTextures)
2907{
2908 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
2909 ASSERT_NE(0u, mProgram);
2910 ASSERT_GL_NO_ERROR();
2911
2912 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
2913}
2914
2915// Test rendering with the maximum fragment texture units.
2916TEST_P(TextureLimitsTest, MaxFragmentTextures)
2917{
2918 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
2919 ASSERT_NE(0u, mProgram);
2920 ASSERT_GL_NO_ERROR();
2921
2922 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
2923}
2924
2925// Test rendering with maximum combined texture units.
2926TEST_P(TextureLimitsTest, MaxCombinedTextures)
2927{
2928 GLint vertexTextures = mMaxVertexTextures;
2929
2930 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
2931 {
2932 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
2933 }
2934
2935 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
2936 mMaxFragmentTextures, mMaxFragmentTextures);
2937 ASSERT_NE(0u, mProgram);
2938 ASSERT_GL_NO_ERROR();
2939
2940 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
2941}
2942
2943// Negative test for exceeding the number of vertex textures
2944TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
2945{
2946 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
2947 0);
2948 ASSERT_EQ(0u, mProgram);
2949}
2950
2951// Negative test for exceeding the number of fragment textures
2952TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
2953{
2954 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
2955 mMaxFragmentTextures + 1);
2956 ASSERT_EQ(0u, mProgram);
2957}
2958
2959// Test active vertex textures under the limit, but excessive textures specified.
2960TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
2961{
2962 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
2963 ASSERT_NE(0u, mProgram);
2964 ASSERT_GL_NO_ERROR();
2965
2966 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
2967}
2968
2969// Test active fragment textures under the limit, but excessive textures specified.
2970TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
2971{
2972 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
2973 mMaxFragmentTextures);
2974 ASSERT_NE(0u, mProgram);
2975 ASSERT_GL_NO_ERROR();
2976
2977 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
2978}
2979
2980// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002981// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002982TEST_P(TextureLimitsTest, TextureTypeConflict)
2983{
2984 const std::string &vertexShader =
2985 "attribute vec2 position;\n"
2986 "varying float color;\n"
2987 "uniform sampler2D tex2D;\n"
2988 "uniform samplerCube texCube;\n"
2989 "void main() {\n"
2990 " gl_Position = vec4(position, 0, 1);\n"
2991 " vec2 texCoord = (position * 0.5) + 0.5;\n"
2992 " color = texture2D(tex2D, texCoord).x;\n"
2993 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
2994 "}";
2995 const std::string &fragmentShader =
2996 "varying mediump float color;\n"
2997 "void main() {\n"
2998 " gl_FragColor = vec4(color, 0, 0, 1);\n"
2999 "}";
3000
3001 mProgram = CompileProgram(vertexShader, fragmentShader);
3002 ASSERT_NE(0u, mProgram);
3003
3004 initTextures(1, 0);
3005
3006 glUseProgram(mProgram);
3007 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3008 ASSERT_NE(-1, tex2DLocation);
3009 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3010 ASSERT_NE(-1, texCubeLocation);
3011
3012 glUniform1i(tex2DLocation, 0);
3013 glUniform1i(texCubeLocation, 0);
3014 ASSERT_GL_NO_ERROR();
3015
3016 drawQuad(mProgram, "position", 0.5f);
3017 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3018}
3019
Vincent Lang25ab4512016-05-13 18:13:59 +02003020class Texture2DNorm16TestES3 : public Texture2DTestES3
3021{
3022 protected:
3023 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3024
3025 void SetUp() override
3026 {
3027 Texture2DTestES3::SetUp();
3028
3029 glActiveTexture(GL_TEXTURE0);
3030 glGenTextures(3, mTextures);
3031 glGenFramebuffers(1, &mFBO);
3032 glGenRenderbuffers(1, &mRenderbuffer);
3033
3034 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3035 {
3036 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3037 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3038 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3039 }
3040
3041 glBindTexture(GL_TEXTURE_2D, 0);
3042
3043 ASSERT_GL_NO_ERROR();
3044 }
3045
3046 void TearDown() override
3047 {
3048 glDeleteTextures(3, mTextures);
3049 glDeleteFramebuffers(1, &mFBO);
3050 glDeleteRenderbuffers(1, &mRenderbuffer);
3051
3052 Texture2DTestES3::TearDown();
3053 }
3054
3055 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3056 {
Geoff Langf607c602016-09-21 11:46:48 -04003057 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3058 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003059
3060 setUpProgram();
3061
3062 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3063 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3064 0);
3065
3066 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3067 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3068
3069 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003070 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003071
3072 EXPECT_GL_NO_ERROR();
3073
3074 drawQuad(mProgram, "position", 0.5f);
3075
Geoff Langf607c602016-09-21 11:46:48 -04003076 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003077
Jamie Madill50cf2be2018-06-15 09:46:57 -04003078 EXPECT_PIXEL_COLOR_EQ(0, 0,
3079 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3080 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003081
3082 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3083
3084 ASSERT_GL_NO_ERROR();
3085 }
3086
3087 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3088 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04003089 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003090 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003091
3092 setUpProgram();
3093
3094 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3095 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3096
3097 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3098 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3099 0);
3100
3101 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003102 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003103
3104 EXPECT_GL_NO_ERROR();
3105
3106 drawQuad(mProgram, "position", 0.5f);
3107
Geoff Langf607c602016-09-21 11:46:48 -04003108 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
Jamie Madill50cf2be2018-06-15 09:46:57 -04003109 EXPECT_PIXEL_COLOR_EQ(0, 0,
3110 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3111 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003112
3113 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3114 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3115 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3116 mRenderbuffer);
3117 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3118 EXPECT_GL_NO_ERROR();
3119
3120 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3121 glClear(GL_COLOR_BUFFER_BIT);
3122
3123 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3124
Geoff Langf607c602016-09-21 11:46:48 -04003125 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003126
3127 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3128
3129 ASSERT_GL_NO_ERROR();
3130 }
3131
3132 GLuint mTextures[3];
3133 GLuint mFBO;
3134 GLuint mRenderbuffer;
3135};
3136
3137// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3138TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3139{
Yunchao He9550c602018-02-13 14:47:05 +08003140 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02003141
3142 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3143 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3144 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3145 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3146 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3147 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3148 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3149 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3150
3151 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3152 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3153 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3154}
3155
Olli Etuaho95faa232016-06-07 14:01:53 -07003156// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3157// GLES 3.0.4 section 3.8.3.
3158TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3159{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08003160 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
3161
Yuly Novikov3c754192016-06-27 19:36:41 -04003162 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1429 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08003163 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07003164
3165 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3166 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3167 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3168 ASSERT_GL_NO_ERROR();
3169
3170 // SKIP_IMAGES should not have an effect on uploading 2D textures
3171 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3172 ASSERT_GL_NO_ERROR();
3173
3174 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3175
3176 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3177 pixelsGreen.data());
3178 ASSERT_GL_NO_ERROR();
3179
3180 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3181 pixelsGreen.data());
3182 ASSERT_GL_NO_ERROR();
3183
3184 glUseProgram(mProgram);
3185 drawQuad(mProgram, "position", 0.5f);
3186 ASSERT_GL_NO_ERROR();
3187
3188 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3189}
3190
Olli Etuaho989cac32016-06-08 16:18:49 -07003191// Test that skip defined in unpack parameters is taken into account when determining whether
3192// unpacking source extends outside unpack buffer bounds.
3193TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3194{
3195 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3196 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3197 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3198 ASSERT_GL_NO_ERROR();
3199
3200 GLBuffer buf;
3201 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3202 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3203 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3204 GL_DYNAMIC_COPY);
3205 ASSERT_GL_NO_ERROR();
3206
3207 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3208 ASSERT_GL_NO_ERROR();
3209
3210 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3211 ASSERT_GL_NO_ERROR();
3212
3213 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3214 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3215
3216 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3217 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3218 ASSERT_GL_NO_ERROR();
3219
3220 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3221 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3222}
3223
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003224// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3225TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3226{
Yunchao He9550c602018-02-13 14:47:05 +08003227 ANGLE_SKIP_TEST_IF(IsD3D11());
3228
3229 // Incorrect rendering results seen on OSX AMD.
3230 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003231
3232 const GLuint width = 8u;
3233 const GLuint height = 8u;
3234 const GLuint unpackRowLength = 5u;
3235 const GLuint unpackSkipPixels = 1u;
3236
3237 setWindowWidth(width);
3238 setWindowHeight(height);
3239
3240 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3241 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3242 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3243 ASSERT_GL_NO_ERROR();
3244
3245 GLBuffer buf;
3246 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3247 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3248 GLColor::green);
3249
3250 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3251 {
3252 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3253 }
3254
3255 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3256 GL_DYNAMIC_COPY);
3257 ASSERT_GL_NO_ERROR();
3258
3259 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3260 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3261 ASSERT_GL_NO_ERROR();
3262
3263 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3264 ASSERT_GL_NO_ERROR();
3265
3266 glUseProgram(mProgram);
3267 drawQuad(mProgram, "position", 0.5f);
3268 ASSERT_GL_NO_ERROR();
3269
3270 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3271 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3272 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3273 actual.data());
3274 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3275 EXPECT_EQ(expected, actual);
3276}
3277
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003278template <typename T>
3279T UNorm(double value)
3280{
3281 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3282}
3283
3284// Test rendering a depth texture with mipmaps.
3285TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3286{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003287 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3288 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
3289 // http://anglebugs.com/1706
Yunchao He9550c602018-02-13 14:47:05 +08003290 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows());
Corentin Walleze731d8a2016-09-07 10:56:25 -04003291
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003292 const int size = getWindowWidth();
3293
3294 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003295 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003296
3297 glActiveTexture(GL_TEXTURE0);
3298 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3299 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3300 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3301 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3302 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3303 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3304 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3305 ASSERT_GL_NO_ERROR();
3306
3307 glUseProgram(mProgram);
3308 glUniform1i(mTexture2DUniformLocation, 0);
3309
3310 std::vector<unsigned char> expected;
3311
3312 for (int level = 0; level < levels; ++level)
3313 {
3314 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3315 expected.push_back(UNorm<unsigned char>(value));
3316
3317 int levelDim = dim(level);
3318
3319 ASSERT_GT(levelDim, 0);
3320
3321 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3322 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3323 GL_UNSIGNED_INT, initData.data());
3324 }
3325 ASSERT_GL_NO_ERROR();
3326
3327 for (int level = 0; level < levels; ++level)
3328 {
3329 glViewport(0, 0, dim(level), dim(level));
3330 drawQuad(mProgram, "position", 0.5f);
3331 GLColor actual = ReadColor(0, 0);
3332 EXPECT_NEAR(expected[level], actual.R, 10u);
3333 }
3334
3335 ASSERT_GL_NO_ERROR();
3336}
3337
Jamie Madill7ffdda92016-09-08 13:26:51 -04003338// Tests unpacking into the unsized GL_ALPHA format.
3339TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3340{
Jamie Madill7ffdda92016-09-08 13:26:51 -04003341 // Initialize the texure.
3342 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3343 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3344 GL_UNSIGNED_BYTE, nullptr);
3345 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3346 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3347
3348 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3349
3350 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04003351 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04003352 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3353 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3354 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
3355 GL_STATIC_DRAW);
3356
3357 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
3358 GL_UNSIGNED_BYTE, nullptr);
3359
3360 // Clear to a weird color to make sure we're drawing something.
3361 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
3362 glClear(GL_COLOR_BUFFER_BIT);
3363
3364 // Draw with the alpha texture and verify.
3365 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04003366
3367 ASSERT_GL_NO_ERROR();
3368 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
3369}
3370
Jamie Madill2e600342016-09-19 13:56:40 -04003371// Ensure stale unpack data doesn't propagate in D3D11.
3372TEST_P(Texture2DTestES3, StaleUnpackData)
3373{
3374 // Init unpack buffer.
3375 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
3376 std::vector<GLColor> pixels(pixelCount, GLColor::red);
3377
3378 GLBuffer unpackBuffer;
3379 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3380 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3381 GLsizei bufferSize = pixelCount * sizeof(GLColor);
3382 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
3383
3384 // Create from unpack buffer.
3385 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3386 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
3387 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3388 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3389 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3390
3391 drawQuad(mProgram, "position", 0.5f);
3392
3393 ASSERT_GL_NO_ERROR();
3394 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3395
3396 // Fill unpack with green, recreating buffer.
3397 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
3398 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
3399 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
3400
3401 // Reinit texture with green.
3402 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
3403 GL_UNSIGNED_BYTE, nullptr);
3404
3405 drawQuad(mProgram, "position", 0.5f);
3406
3407 ASSERT_GL_NO_ERROR();
3408 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3409}
3410
Geoff Langfb7685f2017-11-13 11:44:11 -05003411// Ensure that texture parameters passed as floats that are converted to ints are rounded before
3412// validating they are less than 0.
3413TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
3414{
3415 GLTexture texture;
3416 glBindTexture(GL_TEXTURE_2D, texture);
3417
3418 // Use a negative number that will round to zero when converted to an integer
3419 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
3420 // "Validation of values performed by state-setting commands is performed after conversion,
3421 // unless specified otherwise for a specific command."
3422 GLfloat param = -7.30157126e-07f;
3423 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
3424 EXPECT_GL_NO_ERROR();
3425
3426 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
3427 EXPECT_GL_NO_ERROR();
3428}
3429
Jamie Madillf097e232016-11-05 00:44:15 -04003430// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
3431// being properly checked, and the texture storage of the previous texture format was persisting.
3432// This would result in an ASSERT in debug and incorrect rendering in release.
3433// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
3434TEST_P(Texture3DTestES3, FormatRedefinitionBug)
3435{
3436 GLTexture tex;
3437 glBindTexture(GL_TEXTURE_3D, tex.get());
3438 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3439
3440 GLFramebuffer framebuffer;
3441 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3442 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
3443
3444 glCheckFramebufferStatus(GL_FRAMEBUFFER);
3445
3446 std::vector<uint8_t> pixelData(100, 0);
3447
3448 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
3449 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
3450 pixelData.data());
3451
3452 ASSERT_GL_NO_ERROR();
3453}
3454
Corentin Wallezd2627992017-04-28 17:17:03 -04003455// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
3456TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
3457{
3458 // 2D tests
3459 {
3460 GLTexture tex;
3461 glBindTexture(GL_TEXTURE_2D, tex.get());
3462
3463 GLBuffer pbo;
3464 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3465
3466 // Test OOB
3467 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
3468 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3469 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3470
3471 // Test OOB
3472 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
3473 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3474 ASSERT_GL_NO_ERROR();
3475 }
3476
3477 // 3D tests
3478 {
3479 GLTexture tex;
3480 glBindTexture(GL_TEXTURE_3D, tex.get());
3481
3482 GLBuffer pbo;
3483 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3484
3485 // Test OOB
3486 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
3487 GL_STATIC_DRAW);
3488 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3489 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3490
3491 // Test OOB
3492 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
3493 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3494 ASSERT_GL_NO_ERROR();
3495 }
3496}
3497
Jamie Madill3ed60422017-09-07 11:32:52 -04003498// Tests behaviour with a single texture and multiple sampler objects.
3499TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
3500{
3501 GLint maxTextureUnits = 0;
3502 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
3503 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
3504
3505 constexpr int kSize = 16;
3506
3507 // Make a single-level texture, fill it with red.
3508 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
3509 GLTexture tex;
3510 glBindTexture(GL_TEXTURE_2D, tex);
3511 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3512 redColors.data());
3513 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3514 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3515
3516 // Simple sanity check.
3517 draw2DTexturedQuad(0.5f, 1.0f, true);
3518 ASSERT_GL_NO_ERROR();
3519 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3520
3521 // Bind texture to unit 1 with a sampler object making it incomplete.
3522 GLSampler sampler;
3523 glBindSampler(0, sampler);
3524 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3525 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3526
3527 // Make a mipmap texture, fill it with blue.
3528 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
3529 GLTexture mipmapTex;
3530 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3531 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3532 blueColors.data());
3533 glGenerateMipmap(GL_TEXTURE_2D);
3534
3535 // Draw with the sampler, expect blue.
3536 draw2DTexturedQuad(0.5f, 1.0f, true);
3537 ASSERT_GL_NO_ERROR();
3538 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
3539
3540 // Simple multitexturing program.
3541 const std::string vs =
3542 "#version 300 es\n"
3543 "in vec2 position;\n"
3544 "out vec2 texCoord;\n"
3545 "void main()\n"
3546 "{\n"
3547 " gl_Position = vec4(position, 0, 1);\n"
3548 " texCoord = position * 0.5 + vec2(0.5);\n"
3549 "}";
3550 const std::string fs =
3551 "#version 300 es\n"
3552 "precision mediump float;\n"
3553 "in vec2 texCoord;\n"
3554 "uniform sampler2D tex1;\n"
3555 "uniform sampler2D tex2;\n"
3556 "uniform sampler2D tex3;\n"
3557 "uniform sampler2D tex4;\n"
3558 "out vec4 color;\n"
3559 "void main()\n"
3560 "{\n"
3561 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
3562 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
3563 "}";
3564
3565 ANGLE_GL_PROGRAM(program, vs, fs);
3566
3567 std::array<GLint, 4> texLocations = {
3568 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
3569 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
3570 for (GLint location : texLocations)
3571 {
3572 ASSERT_NE(-1, location);
3573 }
3574
3575 // Init the uniform data.
3576 glUseProgram(program);
3577 for (GLint location = 0; location < 4; ++location)
3578 {
3579 glUniform1i(texLocations[location], location);
3580 }
3581
3582 // Initialize four samplers
3583 GLSampler samplers[4];
3584
3585 // 0: non-mipped.
3586 glBindSampler(0, samplers[0]);
3587 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3588 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3589
3590 // 1: mipped.
3591 glBindSampler(1, samplers[1]);
3592 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3593 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3594
3595 // 2: non-mipped.
3596 glBindSampler(2, samplers[2]);
3597 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3598 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3599
3600 // 3: mipped.
3601 glBindSampler(3, samplers[3]);
3602 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3603 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3604
3605 // Bind two blue mipped textures and two single layer textures, should all draw.
3606 glActiveTexture(GL_TEXTURE0);
3607 glBindTexture(GL_TEXTURE_2D, tex);
3608
3609 glActiveTexture(GL_TEXTURE1);
3610 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3611
3612 glActiveTexture(GL_TEXTURE2);
3613 glBindTexture(GL_TEXTURE_2D, tex);
3614
3615 glActiveTexture(GL_TEXTURE3);
3616 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3617
3618 ASSERT_GL_NO_ERROR();
3619
3620 drawQuad(program, "position", 0.5f);
3621 ASSERT_GL_NO_ERROR();
3622 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
3623
3624 // Bind four single layer textures, two should be incomplete.
3625 glActiveTexture(GL_TEXTURE1);
3626 glBindTexture(GL_TEXTURE_2D, tex);
3627
3628 glActiveTexture(GL_TEXTURE3);
3629 glBindTexture(GL_TEXTURE_2D, tex);
3630
3631 drawQuad(program, "position", 0.5f);
3632 ASSERT_GL_NO_ERROR();
3633 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
3634}
3635
Martin Radev7e2c0d32017-09-15 14:25:42 +03003636// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
3637// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
3638// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
3639// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
3640// samples the cubemap using a direction vector (1,1,1).
3641TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
3642{
Yunchao He2f23f352018-02-11 22:11:37 +08003643 // Check http://anglebug.com/2155.
3644 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
3645
Martin Radev7e2c0d32017-09-15 14:25:42 +03003646 const std::string vs =
3647 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003648 precision mediump float;
3649 in vec3 pos;
3650 void main() {
3651 gl_Position = vec4(pos, 1.0);
3652 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003653
3654 const std::string fs =
3655 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003656 precision mediump float;
3657 out vec4 color;
3658 uniform samplerCube uTex;
3659 void main(){
3660 color = texture(uTex, vec3(1.0));
3661 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003662 ANGLE_GL_PROGRAM(program, vs, fs);
3663 glUseProgram(program);
3664
3665 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
3666 glActiveTexture(GL_TEXTURE0);
3667
3668 GLTexture cubeTex;
3669 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
3670
3671 const int kFaceWidth = 1;
3672 const int kFaceHeight = 1;
3673 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
3674 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3675 GL_UNSIGNED_BYTE, texData.data());
3676 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3677 GL_UNSIGNED_BYTE, texData.data());
3678 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3679 GL_UNSIGNED_BYTE, texData.data());
3680 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3681 GL_UNSIGNED_BYTE, texData.data());
3682 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3683 GL_UNSIGNED_BYTE, texData.data());
3684 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3685 GL_UNSIGNED_BYTE, texData.data());
3686 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3687 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3688 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
3689 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
3690 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
3691 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
3692
3693 drawQuad(program, "pos", 0.5f, 1.0f, true);
3694 ASSERT_GL_NO_ERROR();
3695
3696 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
3697}
3698
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08003699// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
3700TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
3701{
3702 GLuint texture = create2DTexture();
3703
3704 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
3705 EXPECT_GL_ERROR(GL_INVALID_VALUE);
3706
3707 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
3708 EXPECT_GL_ERROR(GL_INVALID_VALUE);
3709
3710 glDeleteTextures(1, &texture);
3711 EXPECT_GL_NO_ERROR();
3712}
3713
Olli Etuaho023371b2018-04-24 17:43:32 +03003714// Test setting base level after calling generateMipmap on a LUMA texture.
3715// Covers http://anglebug.com/2498
3716TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA)
3717{
3718 glActiveTexture(GL_TEXTURE0);
3719 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3720
3721 constexpr const GLsizei kWidth = 8;
3722 constexpr const GLsizei kHeight = 8;
3723 std::array<GLubyte, kWidth * kHeight * 2> whiteData;
3724 whiteData.fill(255u);
3725
3726 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA,
3727 GL_UNSIGNED_BYTE, whiteData.data());
3728 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
3729 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3730 glGenerateMipmap(GL_TEXTURE_2D);
3731 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
3732 EXPECT_GL_NO_ERROR();
3733
3734 drawQuad(mProgram, "position", 0.5f);
3735 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
3736}
3737
Till Rathmannc1551dc2018-08-15 17:04:49 +02003738// Covers a bug in the D3D11 backend: http://anglebug.com/2772
3739// When using a sampler the texture was created as if it has mipmaps,
3740// regardless what you specified in GL_TEXTURE_MIN_FILTER via
3741// glSamplerParameteri() -- mistakenly the default value
3742// GL_NEAREST_MIPMAP_LINEAR or the value set via glTexParameteri() was
3743// evaluated.
3744// If you didn't provide mipmaps and didn't let the driver generate them
3745// this led to not sampling your texture data when minification occurred.
3746TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping)
3747{
3748 const std::string vs =
3749 "#version 300 es\n"
3750 "out vec2 texcoord;\n"
3751 "in vec4 position;\n"
3752 "void main()\n"
3753 "{\n"
3754 " gl_Position = vec4(position.xy * 0.1, 0.0, 1.0);\n"
3755 " texcoord = (position.xy * 0.5) + 0.5;\n"
3756 "}\n";
3757
3758 const std::string fs =
3759 "#version 300 es\n"
3760 "precision highp float;\n"
3761 "uniform highp sampler2D tex;\n"
3762 "in vec2 texcoord;\n"
3763 "out vec4 fragColor;\n"
3764 "void main()\n"
3765 "{\n"
3766 " fragColor = texture(tex, texcoord);\n"
3767 "}\n";
3768 ANGLE_GL_PROGRAM(program, vs, fs);
3769
3770 GLSampler sampler;
3771 glBindSampler(0, sampler);
3772 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3773 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3774
3775 glActiveTexture(GL_TEXTURE0);
3776 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3777
3778 const GLsizei texWidth = getWindowWidth();
3779 const GLsizei texHeight = getWindowHeight();
3780 const std::vector<GLColor> whiteData(texWidth * texHeight, GLColor::white);
3781
3782 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3783 whiteData.data());
3784 EXPECT_GL_NO_ERROR();
3785
3786 drawQuad(program, "position", 0.5f);
3787 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, angle::GLColor::white);
3788}
3789
Jamie Madill50cf2be2018-06-15 09:46:57 -04003790// Use this to select which configurations (e.g. which renderer, which GLES major version) these
3791// tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -05003792ANGLE_INSTANTIATE_TEST(Texture2DTest,
3793 ES2_D3D9(),
3794 ES2_D3D11(),
3795 ES2_D3D11_FL9_3(),
3796 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05003797 ES2_OPENGLES(),
3798 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003799ANGLE_INSTANTIATE_TEST(TextureCubeTest,
3800 ES2_D3D9(),
3801 ES2_D3D11(),
Geoff Langf7480ad2017-10-24 11:46:02 -04003802 ES2_D3D11_FL10_0(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003803 ES2_D3D11_FL9_3(),
3804 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04003805 ES2_OPENGLES(),
3806 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003807ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
3808 ES2_D3D9(),
3809 ES2_D3D11(),
3810 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003811 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04003812 ES2_OPENGLES(),
3813 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003814ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
3815 ES2_D3D9(),
3816 ES2_D3D11(),
3817 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003818 ES2_OPENGL(),
3819 ES2_OPENGLES());
3820ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
3821 ES2_D3D9(),
3822 ES2_D3D11(),
3823 ES2_D3D11_FL9_3(),
3824 ES2_OPENGL(),
3825 ES2_OPENGLES());
3826ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
3827 ES2_D3D9(),
3828 ES2_D3D11(),
3829 ES2_D3D11_FL9_3(),
3830 ES2_OPENGL(),
3831 ES2_OPENGLES());
3832ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02003833ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003834ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3835ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
3836 ES3_D3D11(),
3837 ES3_OPENGL(),
3838 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003839ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
3840 ES3_D3D11(),
3841 ES3_OPENGL(),
3842 ES3_OPENGLES());
3843ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3844ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02003845ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02003846ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
3847 ES2_D3D11(),
3848 ES2_D3D11_FL9_3(),
3849 ES2_D3D9(),
3850 ES2_OPENGL(),
3851 ES2_OPENGLES());
3852ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
3853 ES2_D3D11(),
3854 ES2_D3D11_FL9_3(),
3855 ES2_D3D9(),
3856 ES2_OPENGL(),
3857 ES2_OPENGLES());
3858ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
3859 ES2_D3D11(),
3860 ES2_D3D11_FL9_3(),
3861 ES2_D3D9(),
3862 ES2_OPENGL(),
3863 ES2_OPENGLES());
3864ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
3865 ES2_D3D11(),
3866 ES2_D3D11_FL9_3(),
3867 ES2_D3D9(),
3868 ES2_OPENGL(),
3869 ES2_OPENGLES());
3870ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
3871 ES2_D3D11(),
3872 ES2_D3D11_FL9_3(),
3873 ES2_D3D9(),
3874 ES2_OPENGL(),
3875 ES2_OPENGLES());
Luc Ferronaf883622018-06-08 15:57:31 -04003876ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN());
Vincent Lang25ab4512016-05-13 18:13:59 +02003877ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03003878ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04003879
Jamie Madill7ffdda92016-09-08 13:26:51 -04003880} // anonymous namespace