blob: c64a053981350809eb9ec47fba357405368c1c57 [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 Madillbc393df2015-01-29 13:46:07 -0500203 GLfloat sourceImageData[4][16] =
204 {
205 { // R
206 1.0f,
207 0.0f,
208 0.0f,
209 1.0f
210 },
211 { // RG
212 1.0f, 0.0f,
213 0.0f, 1.0f,
214 0.0f, 0.0f,
215 1.0f, 1.0f
216 },
217 { // RGB
218 1.0f, 0.0f, 0.0f,
219 0.0f, 1.0f, 0.0f,
220 0.0f, 0.0f, 1.0f,
221 1.0f, 1.0f, 0.0f
222 },
223 { // RGBA
224 1.0f, 0.0f, 0.0f, 1.0f,
225 0.0f, 1.0f, 0.0f, 1.0f,
226 0.0f, 0.0f, 1.0f, 1.0f,
227 1.0f, 1.0f, 0.0f, 1.0f
228 },
229 };
230
231 GLenum imageFormats[] =
232 {
233 GL_R32F,
234 GL_RG32F,
235 GL_RGB32F,
236 GL_RGBA32F,
237 };
238
239 GLenum sourceUnsizedFormats[] =
240 {
241 GL_RED,
242 GL_RG,
243 GL_RGB,
244 GL_RGBA,
245 };
246
247 GLuint textures[2];
248
249 glGenTextures(2, textures);
250
251 GLfloat *imageData = sourceImageData[sourceImageChannels - 1];
252 GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1];
253 GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1];
254 GLenum destImageFormat = imageFormats[destImageChannels - 1];
255
256 glBindTexture(GL_TEXTURE_2D, textures[0]);
Geoff Langc4e93662017-05-01 10:45:59 -0400257 if (getClientMajorVersion() >= 3)
258 {
259 glTexStorage2D(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
260 }
261 else
262 {
263 glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
264 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500265 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
266 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
267 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData);
268
hendrikwb27f79a2015-03-04 11:26:46 -0800269 if (sourceImageChannels < 3 && !extensionEnabled("GL_EXT_texture_rg"))
Jamie Madillbc393df2015-01-29 13:46:07 -0500270 {
271 // This is not supported
272 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
273 }
274 else
275 {
276 ASSERT_GL_NO_ERROR();
277 }
278
279 GLuint fbo;
280 glGenFramebuffers(1, &fbo);
281 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
282 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
283
284 glBindTexture(GL_TEXTURE_2D, textures[1]);
Geoff Langc4e93662017-05-01 10:45:59 -0400285 if (getClientMajorVersion() >= 3)
286 {
287 glTexStorage2D(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
288 }
289 else
290 {
291 glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
292 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500293 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
294 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
295
296 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
297 ASSERT_GL_NO_ERROR();
298
299 glBindFramebuffer(GL_FRAMEBUFFER, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200300 drawQuad(mProgram, "position", 0.5f);
Jamie Madillbc393df2015-01-29 13:46:07 -0500301
302 int testImageChannels = std::min(sourceImageChannels, destImageChannels);
303
Olli Etuahoa314b612016-03-10 16:43:00 +0200304 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Jamie Madillbc393df2015-01-29 13:46:07 -0500305 if (testImageChannels > 1)
306 {
307 EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255);
308 EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255);
309 if (testImageChannels > 2)
310 {
311 EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255);
312 }
313 }
314
315 glDeleteFramebuffers(1, &fbo);
316 glDeleteTextures(2, textures);
317
318 ASSERT_GL_NO_ERROR();
319 }
320
Jamie Madilld4cfa572014-07-08 10:00:32 -0400321 GLuint mTexture2D;
Jamie Madilld4cfa572014-07-08 10:00:32 -0400322 GLint mTexture2DUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400323};
324
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200325class Texture2DTestES3 : public Texture2DTest
326{
327 protected:
328 Texture2DTestES3() : Texture2DTest() {}
329
330 std::string getVertexShaderSource() override
331 {
332 return std::string(
333 "#version 300 es\n"
334 "out vec2 texcoord;\n"
335 "in vec4 position;\n"
336 "void main()\n"
337 "{\n"
338 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
339 " texcoord = (position.xy * 0.5) + 0.5;\n"
340 "}\n");
341 }
342
343 std::string getFragmentShaderSource() override
344 {
345 return std::string(
346 "#version 300 es\n"
347 "precision highp float;\n"
348 "uniform highp sampler2D tex;\n"
349 "in vec2 texcoord;\n"
350 "out vec4 fragColor;\n"
351 "void main()\n"
352 "{\n"
353 " fragColor = texture(tex, texcoord);\n"
354 "}\n");
355 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300356
357 void SetUp() override
358 {
359 Texture2DTest::SetUp();
360 setUpProgram();
361 }
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200362};
363
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200364class Texture2DIntegerAlpha1TestES3 : public Texture2DTest
365{
366 protected:
367 Texture2DIntegerAlpha1TestES3() : Texture2DTest() {}
368
369 std::string getVertexShaderSource() override
370 {
371 return std::string(
372 "#version 300 es\n"
373 "out vec2 texcoord;\n"
374 "in vec4 position;\n"
375 "void main()\n"
376 "{\n"
377 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
378 " texcoord = (position.xy * 0.5) + 0.5;\n"
379 "}\n");
380 }
381
382 std::string getFragmentShaderSource() override
383 {
384 return std::string(
385 "#version 300 es\n"
386 "precision highp float;\n"
387 "uniform highp isampler2D tex;\n"
388 "in vec2 texcoord;\n"
389 "out vec4 fragColor;\n"
390 "void main()\n"
391 "{\n"
392 " vec4 green = vec4(0, 1, 0, 1);\n"
393 " vec4 black = vec4(0, 0, 0, 0);\n"
394 " fragColor = (texture(tex, texcoord).a == 1) ? green : black;\n"
395 "}\n");
396 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300397
398 void SetUp() override
399 {
400 Texture2DTest::SetUp();
401 setUpProgram();
402 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200403};
404
405class Texture2DUnsignedIntegerAlpha1TestES3 : public Texture2DTest
406{
407 protected:
408 Texture2DUnsignedIntegerAlpha1TestES3() : Texture2DTest() {}
409
410 std::string getVertexShaderSource() override
411 {
412 return std::string(
413 "#version 300 es\n"
414 "out vec2 texcoord;\n"
415 "in vec4 position;\n"
416 "void main()\n"
417 "{\n"
418 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
419 " texcoord = (position.xy * 0.5) + 0.5;\n"
420 "}\n");
421 }
422
423 std::string getFragmentShaderSource() override
424 {
425 return std::string(
426 "#version 300 es\n"
427 "precision highp float;\n"
428 "uniform highp usampler2D tex;\n"
429 "in vec2 texcoord;\n"
430 "out vec4 fragColor;\n"
431 "void main()\n"
432 "{\n"
433 " vec4 green = vec4(0, 1, 0, 1);\n"
434 " vec4 black = vec4(0, 0, 0, 0);\n"
435 " fragColor = (texture(tex, texcoord).a == 1u) ? green : black;\n"
436 "}\n");
437 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300438
439 void SetUp() override
440 {
441 Texture2DTest::SetUp();
442 setUpProgram();
443 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200444};
445
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200446class Texture2DTestWithDrawScale : public Texture2DTest
Jamie Madill2453dbc2015-07-14 11:35:42 -0400447{
448 protected:
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200449 Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {}
450
451 std::string getVertexShaderSource() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400452 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300453 return
454 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200455 attribute vec4 position;
456 varying vec2 texcoord;
457
458 uniform vec2 drawScale;
459
460 void main()
461 {
462 gl_Position = vec4(position.xy * drawScale, 0.0, 1.0);
463 texcoord = (position.xy * 0.5) + 0.5;
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300464 })";
Jamie Madill2453dbc2015-07-14 11:35:42 -0400465 }
466
467 void SetUp() override
468 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200469 Texture2DTest::SetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300470
471 setUpProgram();
472
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200473 mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale");
474 ASSERT_NE(-1, mDrawScaleUniformLocation);
Jamie Madill2453dbc2015-07-14 11:35:42 -0400475
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200476 glUseProgram(mProgram);
477 glUniform2f(mDrawScaleUniformLocation, 1.0f, 1.0f);
478 glUseProgram(0);
479 ASSERT_GL_NO_ERROR();
480 }
481
482 GLint mDrawScaleUniformLocation;
483};
484
Olli Etuaho4644a202016-01-12 15:12:53 +0200485class Sampler2DAsFunctionParameterTest : public Texture2DTest
486{
487 protected:
488 Sampler2DAsFunctionParameterTest() : Texture2DTest() {}
489
490 std::string getFragmentShaderSource() override
491 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300492 return
493 R"(precision highp float;
Olli Etuaho4644a202016-01-12 15:12:53 +0200494 uniform sampler2D tex;
495 varying vec2 texcoord;
496
497 vec4 computeFragColor(sampler2D aTex)
498 {
499 return texture2D(aTex, texcoord);
500 }
501
502 void main()
503 {
504 gl_FragColor = computeFragColor(tex);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300505 })";
Olli Etuaho4644a202016-01-12 15:12:53 +0200506 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300507
508 void SetUp() override
509 {
510 Texture2DTest::SetUp();
511 setUpProgram();
512 }
Olli Etuaho4644a202016-01-12 15:12:53 +0200513};
514
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200515class TextureCubeTest : public TexCoordDrawTest
516{
517 protected:
518 TextureCubeTest()
519 : TexCoordDrawTest(),
520 mTexture2D(0),
521 mTextureCube(0),
522 mTexture2DUniformLocation(-1),
523 mTextureCubeUniformLocation(-1)
524 {
525 }
526
527 std::string getFragmentShaderSource() override
528 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300529 return
530 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200531 uniform sampler2D tex2D;
532 uniform samplerCube texCube;
533 varying vec2 texcoord;
534
535 void main()
536 {
537 gl_FragColor = texture2D(tex2D, texcoord);
538 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300539 })";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200540 }
541
542 void SetUp() override
543 {
544 TexCoordDrawTest::SetUp();
545
546 glGenTextures(1, &mTextureCube);
547 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Geoff Langc4e93662017-05-01 10:45:59 -0400548 for (GLenum face = 0; face < 6; face++)
549 {
550 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
551 GL_UNSIGNED_BYTE, nullptr);
552 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200553 EXPECT_GL_NO_ERROR();
554
555 mTexture2D = create2DTexture();
556
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300557 setUpProgram();
558
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200559 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
560 ASSERT_NE(-1, mTexture2DUniformLocation);
561 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
562 ASSERT_NE(-1, mTextureCubeUniformLocation);
563 }
564
565 void TearDown() override
566 {
567 glDeleteTextures(1, &mTextureCube);
568 TexCoordDrawTest::TearDown();
569 }
570
571 GLuint mTexture2D;
572 GLuint mTextureCube;
573 GLint mTexture2DUniformLocation;
574 GLint mTextureCubeUniformLocation;
575};
576
Martin Radev7e2c0d32017-09-15 14:25:42 +0300577class TextureCubeTestES3 : public ANGLETest
578{
579 protected:
580 TextureCubeTestES3() {}
581};
582
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200583class SamplerArrayTest : public TexCoordDrawTest
584{
585 protected:
586 SamplerArrayTest()
587 : TexCoordDrawTest(),
588 mTexture2DA(0),
589 mTexture2DB(0),
590 mTexture0UniformLocation(-1),
591 mTexture1UniformLocation(-1)
592 {
593 }
594
595 std::string getFragmentShaderSource() override
596 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300597 return
598 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200599 uniform highp sampler2D tex2DArray[2];
600 varying vec2 texcoord;
601 void main()
602 {
603 gl_FragColor = texture2D(tex2DArray[0], texcoord);
604 gl_FragColor += texture2D(tex2DArray[1], texcoord);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300605 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200606 }
607
608 void SetUp() override
609 {
610 TexCoordDrawTest::SetUp();
611
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300612 setUpProgram();
613
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200614 mTexture0UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[0]");
615 ASSERT_NE(-1, mTexture0UniformLocation);
616 mTexture1UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[1]");
617 ASSERT_NE(-1, mTexture1UniformLocation);
618
619 mTexture2DA = create2DTexture();
620 mTexture2DB = create2DTexture();
621 ASSERT_GL_NO_ERROR();
622 }
623
624 void TearDown() override
625 {
626 glDeleteTextures(1, &mTexture2DA);
627 glDeleteTextures(1, &mTexture2DB);
628 TexCoordDrawTest::TearDown();
629 }
630
631 void testSamplerArrayDraw()
632 {
633 GLubyte texData[4];
634 texData[0] = 0;
635 texData[1] = 60;
636 texData[2] = 0;
637 texData[3] = 255;
638
639 glActiveTexture(GL_TEXTURE0);
640 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
641 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
642
643 texData[1] = 120;
644 glActiveTexture(GL_TEXTURE1);
645 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
646 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
647 EXPECT_GL_ERROR(GL_NO_ERROR);
648
649 glUseProgram(mProgram);
650 glUniform1i(mTexture0UniformLocation, 0);
651 glUniform1i(mTexture1UniformLocation, 1);
652 drawQuad(mProgram, "position", 0.5f);
653 EXPECT_GL_NO_ERROR();
654
655 EXPECT_PIXEL_NEAR(0, 0, 0, 180, 0, 255, 2);
656 }
657
658 GLuint mTexture2DA;
659 GLuint mTexture2DB;
660 GLint mTexture0UniformLocation;
661 GLint mTexture1UniformLocation;
662};
663
664
665class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest
666{
667 protected:
668 SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {}
669
670 std::string getFragmentShaderSource() override
671 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300672 return
673 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200674 uniform highp sampler2D tex2DArray[2];
675 varying vec2 texcoord;
676
677 vec4 computeFragColor(highp sampler2D aTex2DArray[2])
678 {
679 return texture2D(aTex2DArray[0], texcoord) + texture2D(aTex2DArray[1], texcoord);
680 }
681
682 void main()
683 {
684 gl_FragColor = computeFragColor(tex2DArray);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300685 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200686 }
687};
688
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200689class Texture2DArrayTestES3 : public TexCoordDrawTest
690{
691 protected:
692 Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {}
693
694 std::string getVertexShaderSource() override
695 {
696 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400697 "#version 300 es\n"
698 "out vec2 texcoord;\n"
699 "in vec4 position;\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200700 "void main()\n"
701 "{\n"
702 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
703 " texcoord = (position.xy * 0.5) + 0.5;\n"
704 "}\n");
705 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400706
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200707 std::string getFragmentShaderSource() override
708 {
709 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400710 "#version 300 es\n"
711 "precision highp float;\n"
Olli Etuaho183d7e22015-11-20 15:59:09 +0200712 "uniform highp sampler2DArray tex2DArray;\n"
Jamie Madill2453dbc2015-07-14 11:35:42 -0400713 "in vec2 texcoord;\n"
714 "out vec4 fragColor;\n"
715 "void main()\n"
716 "{\n"
717 " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200718 "}\n");
719 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400720
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200721 void SetUp() override
722 {
723 TexCoordDrawTest::SetUp();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400724
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300725 setUpProgram();
726
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200727 mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray");
Jamie Madill2453dbc2015-07-14 11:35:42 -0400728 ASSERT_NE(-1, mTextureArrayLocation);
729
730 glGenTextures(1, &m2DArrayTexture);
731 ASSERT_GL_NO_ERROR();
732 }
733
734 void TearDown() override
735 {
736 glDeleteTextures(1, &m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200737 TexCoordDrawTest::TearDown();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400738 }
739
740 GLuint m2DArrayTexture;
Jamie Madill2453dbc2015-07-14 11:35:42 -0400741 GLint mTextureArrayLocation;
742};
743
Olli Etuahobce743a2016-01-15 17:18:28 +0200744class TextureSizeTextureArrayTest : public TexCoordDrawTest
745{
746 protected:
747 TextureSizeTextureArrayTest()
748 : TexCoordDrawTest(),
749 mTexture2DA(0),
750 mTexture2DB(0),
751 mTexture0Location(-1),
752 mTexture1Location(-1)
753 {
754 }
755
756 std::string getVertexShaderSource() override
757 {
Olli Etuaho5804dc82018-04-13 14:11:46 +0300758 return std::string(essl3_shaders::vs::Simple());
Olli Etuahobce743a2016-01-15 17:18:28 +0200759 }
760
761 std::string getFragmentShaderSource() override
762 {
763 return std::string(
764 "#version 300 es\n"
765 "precision highp float;\n"
766 "uniform highp sampler2D tex2DArray[2];\n"
767 "out vec4 fragColor;\n"
768 "void main()\n"
769 "{\n"
770 " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n"
771 " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n"
772 " fragColor = vec4(red, green, 0.0, 1.0);\n"
773 "}\n");
774 }
775
776 void SetUp() override
777 {
778 TexCoordDrawTest::SetUp();
779
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300780 setUpProgram();
781
Olli Etuahobce743a2016-01-15 17:18:28 +0200782 mTexture0Location = glGetUniformLocation(mProgram, "tex2DArray[0]");
783 ASSERT_NE(-1, mTexture0Location);
784 mTexture1Location = glGetUniformLocation(mProgram, "tex2DArray[1]");
785 ASSERT_NE(-1, mTexture1Location);
786
787 mTexture2DA = create2DTexture();
788 mTexture2DB = create2DTexture();
789 ASSERT_GL_NO_ERROR();
790 }
791
792 void TearDown() override
793 {
794 glDeleteTextures(1, &mTexture2DA);
795 glDeleteTextures(1, &mTexture2DB);
796 TexCoordDrawTest::TearDown();
797 }
798
799 GLuint mTexture2DA;
800 GLuint mTexture2DB;
801 GLint mTexture0Location;
802 GLint mTexture1Location;
803};
804
Olli Etuahoa314b612016-03-10 16:43:00 +0200805class Texture3DTestES3 : public TexCoordDrawTest
806{
807 protected:
808 Texture3DTestES3() : TexCoordDrawTest(), mTexture3D(0), mTexture3DUniformLocation(-1) {}
809
810 std::string getVertexShaderSource() override
811 {
812 return std::string(
813 "#version 300 es\n"
814 "out vec2 texcoord;\n"
815 "in vec4 position;\n"
816 "void main()\n"
817 "{\n"
818 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
819 " texcoord = (position.xy * 0.5) + 0.5;\n"
820 "}\n");
821 }
822
823 std::string getFragmentShaderSource() override
824 {
825 return std::string(
826 "#version 300 es\n"
827 "precision highp float;\n"
828 "uniform highp sampler3D tex3D;\n"
829 "in vec2 texcoord;\n"
830 "out vec4 fragColor;\n"
831 "void main()\n"
832 "{\n"
833 " fragColor = texture(tex3D, vec3(texcoord, 0.0));\n"
834 "}\n");
835 }
836
837 void SetUp() override
838 {
839 TexCoordDrawTest::SetUp();
840
841 glGenTextures(1, &mTexture3D);
842
843 setUpProgram();
844
845 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
846 ASSERT_NE(-1, mTexture3DUniformLocation);
847 }
848
849 void TearDown() override
850 {
851 glDeleteTextures(1, &mTexture3D);
852 TexCoordDrawTest::TearDown();
853 }
854
855 GLuint mTexture3D;
856 GLint mTexture3DUniformLocation;
857};
858
Olli Etuaho1a679902016-01-14 12:21:47 +0200859class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest
860{
861 protected:
862 ShadowSamplerPlusSampler3DTestES3()
863 : TexCoordDrawTest(),
864 mTextureShadow(0),
865 mTexture3D(0),
866 mTextureShadowUniformLocation(-1),
867 mTexture3DUniformLocation(-1),
868 mDepthRefUniformLocation(-1)
869 {
870 }
871
872 std::string getVertexShaderSource() override
873 {
874 return std::string(
875 "#version 300 es\n"
876 "out vec2 texcoord;\n"
877 "in vec4 position;\n"
878 "void main()\n"
879 "{\n"
880 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
881 " texcoord = (position.xy * 0.5) + 0.5;\n"
882 "}\n");
883 }
884
885 std::string getFragmentShaderSource() override
886 {
887 return std::string(
888 "#version 300 es\n"
889 "precision highp float;\n"
890 "uniform highp sampler2DShadow tex2DShadow;\n"
891 "uniform highp sampler3D tex3D;\n"
892 "in vec2 texcoord;\n"
893 "uniform float depthRef;\n"
894 "out vec4 fragColor;\n"
895 "void main()\n"
896 "{\n"
897 " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n"
898 " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n"
899 "}\n");
900 }
901
902 void SetUp() override
903 {
904 TexCoordDrawTest::SetUp();
905
906 glGenTextures(1, &mTexture3D);
907
908 glGenTextures(1, &mTextureShadow);
909 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
910 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
911
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300912 setUpProgram();
913
Olli Etuaho1a679902016-01-14 12:21:47 +0200914 mTextureShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
915 ASSERT_NE(-1, mTextureShadowUniformLocation);
916 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
917 ASSERT_NE(-1, mTexture3DUniformLocation);
918 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
919 ASSERT_NE(-1, mDepthRefUniformLocation);
920 }
921
922 void TearDown() override
923 {
924 glDeleteTextures(1, &mTextureShadow);
925 glDeleteTextures(1, &mTexture3D);
926 TexCoordDrawTest::TearDown();
927 }
928
929 GLuint mTextureShadow;
930 GLuint mTexture3D;
931 GLint mTextureShadowUniformLocation;
932 GLint mTexture3DUniformLocation;
933 GLint mDepthRefUniformLocation;
934};
935
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200936class SamplerTypeMixTestES3 : public TexCoordDrawTest
937{
938 protected:
939 SamplerTypeMixTestES3()
940 : TexCoordDrawTest(),
941 mTexture2D(0),
942 mTextureCube(0),
943 mTexture2DShadow(0),
944 mTextureCubeShadow(0),
945 mTexture2DUniformLocation(-1),
946 mTextureCubeUniformLocation(-1),
947 mTexture2DShadowUniformLocation(-1),
948 mTextureCubeShadowUniformLocation(-1),
949 mDepthRefUniformLocation(-1)
950 {
951 }
952
953 std::string getVertexShaderSource() override
954 {
955 return std::string(
956 "#version 300 es\n"
957 "out vec2 texcoord;\n"
958 "in vec4 position;\n"
959 "void main()\n"
960 "{\n"
961 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
962 " texcoord = (position.xy * 0.5) + 0.5;\n"
963 "}\n");
964 }
965
966 std::string getFragmentShaderSource() override
967 {
968 return std::string(
969 "#version 300 es\n"
970 "precision highp float;\n"
971 "uniform highp sampler2D tex2D;\n"
972 "uniform highp samplerCube texCube;\n"
973 "uniform highp sampler2DShadow tex2DShadow;\n"
974 "uniform highp samplerCubeShadow texCubeShadow;\n"
975 "in vec2 texcoord;\n"
976 "uniform float depthRef;\n"
977 "out vec4 fragColor;\n"
978 "void main()\n"
979 "{\n"
980 " fragColor = texture(tex2D, texcoord);\n"
981 " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n"
982 " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n"
983 " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * "
984 "0.125);\n"
985 "}\n");
986 }
987
988 void SetUp() override
989 {
990 TexCoordDrawTest::SetUp();
991
992 glGenTextures(1, &mTexture2D);
993 glGenTextures(1, &mTextureCube);
994
995 glGenTextures(1, &mTexture2DShadow);
996 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
997 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
998
999 glGenTextures(1, &mTextureCubeShadow);
1000 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
1001 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
1002
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001003 setUpProgram();
1004
Olli Etuahoc8c99a02016-01-14 16:47:22 +02001005 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
1006 ASSERT_NE(-1, mTexture2DUniformLocation);
1007 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
1008 ASSERT_NE(-1, mTextureCubeUniformLocation);
1009 mTexture2DShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
1010 ASSERT_NE(-1, mTexture2DShadowUniformLocation);
1011 mTextureCubeShadowUniformLocation = glGetUniformLocation(mProgram, "texCubeShadow");
1012 ASSERT_NE(-1, mTextureCubeShadowUniformLocation);
1013 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
1014 ASSERT_NE(-1, mDepthRefUniformLocation);
1015
1016 ASSERT_GL_NO_ERROR();
1017 }
1018
1019 void TearDown() override
1020 {
1021 glDeleteTextures(1, &mTexture2D);
1022 glDeleteTextures(1, &mTextureCube);
1023 glDeleteTextures(1, &mTexture2DShadow);
1024 glDeleteTextures(1, &mTextureCubeShadow);
1025 TexCoordDrawTest::TearDown();
1026 }
1027
1028 GLuint mTexture2D;
1029 GLuint mTextureCube;
1030 GLuint mTexture2DShadow;
1031 GLuint mTextureCubeShadow;
1032 GLint mTexture2DUniformLocation;
1033 GLint mTextureCubeUniformLocation;
1034 GLint mTexture2DShadowUniformLocation;
1035 GLint mTextureCubeShadowUniformLocation;
1036 GLint mDepthRefUniformLocation;
1037};
1038
Olli Etuaho96963162016-03-21 11:54:33 +02001039class SamplerInStructTest : public Texture2DTest
1040{
1041 protected:
1042 SamplerInStructTest() : Texture2DTest() {}
1043
1044 const char *getTextureUniformName() override { return "us.tex"; }
1045
1046 std::string getFragmentShaderSource() override
1047 {
1048 return std::string(
1049 "precision highp float;\n"
1050 "struct S\n"
1051 "{\n"
1052 " vec4 a;\n"
1053 " highp sampler2D tex;\n"
1054 "};\n"
1055 "uniform S us;\n"
1056 "varying vec2 texcoord;\n"
1057 "void main()\n"
1058 "{\n"
1059 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x);\n"
1060 "}\n");
1061 }
1062
1063 void runSamplerInStructTest()
1064 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001065 setUpProgram();
1066
Olli Etuaho96963162016-03-21 11:54:33 +02001067 glActiveTexture(GL_TEXTURE0);
1068 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001069 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1070 &GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001071 drawQuad(mProgram, "position", 0.5f);
Olli Etuahoa314b612016-03-10 16:43:00 +02001072 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001073 }
1074};
1075
1076class SamplerInStructAsFunctionParameterTest : public SamplerInStructTest
1077{
1078 protected:
1079 SamplerInStructAsFunctionParameterTest() : SamplerInStructTest() {}
1080
1081 std::string getFragmentShaderSource() override
1082 {
1083 return std::string(
1084 "precision highp float;\n"
1085 "struct S\n"
1086 "{\n"
1087 " vec4 a;\n"
1088 " highp sampler2D tex;\n"
1089 "};\n"
1090 "uniform S us;\n"
1091 "varying vec2 texcoord;\n"
1092 "vec4 sampleFrom(S s) {\n"
1093 " return texture2D(s.tex, texcoord + s.a.x);\n"
1094 "}\n"
1095 "void main()\n"
1096 "{\n"
1097 " gl_FragColor = sampleFrom(us);\n"
1098 "}\n");
1099 }
1100};
1101
1102class SamplerInStructArrayAsFunctionParameterTest : public SamplerInStructTest
1103{
1104 protected:
1105 SamplerInStructArrayAsFunctionParameterTest() : SamplerInStructTest() {}
1106
1107 const char *getTextureUniformName() override { return "us[0].tex"; }
1108
1109 std::string getFragmentShaderSource() override
1110 {
1111 return std::string(
1112 "precision highp float;\n"
1113 "struct S\n"
1114 "{\n"
1115 " vec4 a;\n"
1116 " highp sampler2D tex;\n"
1117 "};\n"
1118 "uniform S us[1];\n"
1119 "varying vec2 texcoord;\n"
1120 "vec4 sampleFrom(S s) {\n"
1121 " return texture2D(s.tex, texcoord + s.a.x);\n"
1122 "}\n"
1123 "void main()\n"
1124 "{\n"
1125 " gl_FragColor = sampleFrom(us[0]);\n"
1126 "}\n");
1127 }
1128};
1129
1130class SamplerInNestedStructAsFunctionParameterTest : public SamplerInStructTest
1131{
1132 protected:
1133 SamplerInNestedStructAsFunctionParameterTest() : SamplerInStructTest() {}
1134
1135 const char *getTextureUniformName() override { return "us[0].sub.tex"; }
1136
1137 std::string getFragmentShaderSource() override
1138 {
1139 return std::string(
1140 "precision highp float;\n"
1141 "struct SUB\n"
1142 "{\n"
1143 " vec4 a;\n"
1144 " highp sampler2D tex;\n"
1145 "};\n"
1146 "struct S\n"
1147 "{\n"
1148 " SUB sub;\n"
1149 "};\n"
1150 "uniform S us[1];\n"
1151 "varying vec2 texcoord;\n"
1152 "vec4 sampleFrom(SUB s) {\n"
1153 " return texture2D(s.tex, texcoord + s.a.x);\n"
1154 "}\n"
1155 "void main()\n"
1156 "{\n"
1157 " gl_FragColor = sampleFrom(us[0].sub);\n"
1158 "}\n");
1159 }
1160};
1161
1162class SamplerInStructAndOtherVariableTest : public SamplerInStructTest
1163{
1164 protected:
1165 SamplerInStructAndOtherVariableTest() : SamplerInStructTest() {}
1166
1167 std::string getFragmentShaderSource() override
1168 {
1169 return std::string(
1170 "precision highp float;\n"
1171 "struct S\n"
1172 "{\n"
1173 " vec4 a;\n"
1174 " highp sampler2D tex;\n"
1175 "};\n"
1176 "uniform S us;\n"
1177 "uniform float us_tex;\n"
1178 "varying vec2 texcoord;\n"
1179 "void main()\n"
1180 "{\n"
1181 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x + us_tex);\n"
1182 "}\n");
1183 }
1184};
1185
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001186TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001187{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001188 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001189 EXPECT_GL_ERROR(GL_NO_ERROR);
1190
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001191 setUpProgram();
1192
Jamie Madillf67115c2014-04-22 13:14:05 -04001193 const GLubyte *pixels[20] = { 0 };
1194 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1195 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001196
1197 if (extensionEnabled("GL_EXT_texture_storage"))
1198 {
1199 // Create a 1-level immutable texture.
1200 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1201
1202 // Try calling sub image on the second level.
1203 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1204 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1205 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001206}
Geoff Langc41e42d2014-04-28 10:58:16 -04001207
John Bauman18319182016-09-28 14:22:27 -07001208// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1209TEST_P(Texture2DTest, QueryBinding)
1210{
1211 glBindTexture(GL_TEXTURE_2D, 0);
1212 EXPECT_GL_ERROR(GL_NO_ERROR);
1213
1214 GLint textureBinding;
1215 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1216 EXPECT_GL_NO_ERROR();
1217 EXPECT_EQ(0, textureBinding);
1218
1219 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
1220 if (extensionEnabled("GL_OES_EGL_image_external") ||
1221 extensionEnabled("GL_NV_EGL_stream_consumer_external"))
1222 {
1223 EXPECT_GL_NO_ERROR();
1224 EXPECT_EQ(0, textureBinding);
1225 }
1226 else
1227 {
1228 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1229 }
1230}
1231
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001232TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001233{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001234 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001235 EXPECT_GL_ERROR(GL_NO_ERROR);
1236
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001237 setUpProgram();
1238
Geoff Langc41e42d2014-04-28 10:58:16 -04001239 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001240 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001241 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001242 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001243
1244 const GLubyte *pixel[4] = { 0 };
1245
1246 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1247 EXPECT_GL_NO_ERROR();
1248
1249 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1250 EXPECT_GL_NO_ERROR();
1251
1252 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1253 EXPECT_GL_NO_ERROR();
1254}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001255
1256// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001257TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001258{
1259 glActiveTexture(GL_TEXTURE0);
1260 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1261 glActiveTexture(GL_TEXTURE1);
1262 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1263 EXPECT_GL_ERROR(GL_NO_ERROR);
1264
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001265 glUseProgram(mProgram);
1266 glUniform1i(mTexture2DUniformLocation, 0);
1267 glUniform1i(mTextureCubeUniformLocation, 1);
1268 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001269 EXPECT_GL_NO_ERROR();
1270}
Jamie Madill9aca0592014-10-06 16:26:59 -04001271
Olli Etuaho53a2da12016-01-11 15:43:32 +02001272// Test drawing with two texture types accessed from the same shader and check that the result of
1273// drawing is correct.
1274TEST_P(TextureCubeTest, CubeMapDraw)
1275{
1276 GLubyte texData[4];
1277 texData[0] = 0;
1278 texData[1] = 60;
1279 texData[2] = 0;
1280 texData[3] = 255;
1281
1282 glActiveTexture(GL_TEXTURE0);
1283 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1284 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1285
1286 glActiveTexture(GL_TEXTURE1);
1287 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1288 texData[1] = 120;
1289 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1290 texData);
1291 EXPECT_GL_ERROR(GL_NO_ERROR);
1292
1293 glUseProgram(mProgram);
1294 glUniform1i(mTexture2DUniformLocation, 0);
1295 glUniform1i(mTextureCubeUniformLocation, 1);
1296 drawQuad(mProgram, "position", 0.5f);
1297 EXPECT_GL_NO_ERROR();
1298
1299 int px = getWindowWidth() - 1;
1300 int py = 0;
1301 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1302}
1303
Olli Etuaho4644a202016-01-12 15:12:53 +02001304TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1305{
1306 glActiveTexture(GL_TEXTURE0);
1307 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1308 GLubyte texData[4];
1309 texData[0] = 0;
1310 texData[1] = 128;
1311 texData[2] = 0;
1312 texData[3] = 255;
1313 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1314 glUseProgram(mProgram);
1315 glUniform1i(mTexture2DUniformLocation, 0);
1316 drawQuad(mProgram, "position", 0.5f);
1317 EXPECT_GL_NO_ERROR();
1318
1319 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1320}
1321
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001322// Test drawing with two textures passed to the shader in a sampler array.
1323TEST_P(SamplerArrayTest, SamplerArrayDraw)
1324{
1325 testSamplerArrayDraw();
1326}
1327
1328// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1329// user-defined function in the shader.
1330TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1331{
1332 testSamplerArrayDraw();
1333}
1334
Jamie Madill9aca0592014-10-06 16:26:59 -04001335// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001336TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001337{
Luc Ferronaf883622018-06-08 15:57:31 -04001338 // TODO(lucferron): Diagnose and fix
1339 // http://anglebug.com/2653
1340 ANGLE_SKIP_TEST_IF(IsVulkan());
1341
Jamie Madill9aca0592014-10-06 16:26:59 -04001342 int px = getWindowWidth() / 2;
1343 int py = getWindowHeight() / 2;
1344
1345 glActiveTexture(GL_TEXTURE0);
1346 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1347
Olli Etuahoa314b612016-03-10 16:43:00 +02001348 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001349
Olli Etuahoa314b612016-03-10 16:43:00 +02001350 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001351 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1352 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1353 glGenerateMipmap(GL_TEXTURE_2D);
1354
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001355 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001356 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001357 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1358 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001359 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001360 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001361
Olli Etuahoa314b612016-03-10 16:43:00 +02001362 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001363
Olli Etuahoa314b612016-03-10 16:43:00 +02001364 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1365 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001366 glGenerateMipmap(GL_TEXTURE_2D);
1367
Olli Etuahoa314b612016-03-10 16:43:00 +02001368 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001369
Olli Etuahoa314b612016-03-10 16:43:00 +02001370 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1371 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001372 glGenerateMipmap(GL_TEXTURE_2D);
1373
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001374 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001375
1376 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001377 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001378}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001379
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001380// Test creating a FBO with a cube map render target, to test an ANGLE bug
1381// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001382TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001383{
Luc Ferronaf883622018-06-08 15:57:31 -04001384 // TODO(jmadill): Cube map render targets. http://anglebug.com/2470
1385 ANGLE_SKIP_TEST_IF(IsVulkan());
1386
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001387 GLuint fbo;
1388 glGenFramebuffers(1, &fbo);
1389 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1390
1391 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1392 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mTextureCube, 0);
1393
Corentin Wallez322653b2015-06-17 18:33:56 +02001394 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001395
1396 glDeleteFramebuffers(1, &fbo);
1397
1398 EXPECT_GL_NO_ERROR();
1399}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001400
1401// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001402TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001403{
Luc Ferron7348fc52018-05-09 07:17:16 -04001404 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -04001405
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001406 int width = getWindowWidth();
1407 int height = getWindowHeight();
1408
1409 GLuint tex2D;
1410 glGenTextures(1, &tex2D);
1411 glActiveTexture(GL_TEXTURE0);
1412 glBindTexture(GL_TEXTURE_2D, tex2D);
1413
1414 // Fill with red
1415 std::vector<GLubyte> pixels(3 * 16 * 16);
1416 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1417 {
1418 pixels[pixelId * 3 + 0] = 255;
1419 pixels[pixelId * 3 + 1] = 0;
1420 pixels[pixelId * 3 + 2] = 0;
1421 }
1422
1423 // ANGLE internally uses RGBA as the DirectX format for RGB images
1424 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1425 // The data is kept in a CPU-side image and the image is marked as dirty.
Geoff Langc4e93662017-05-01 10:45:59 -04001426 if (getClientMajorVersion() >= 3)
1427 {
1428 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1429 }
1430 else
1431 {
1432 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1433 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001434
1435 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1436 // glTexSubImage2D should take into account that the image is dirty.
1437 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1438 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1439 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1440
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001441 setUpProgram();
1442
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001443 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001444 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001445 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001446 glDeleteTextures(1, &tex2D);
1447 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001448 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001449
1450 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001451 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1452 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001453}
1454
1455// Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001456TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001457{
1458 if (extensionEnabled("NV_pixel_buffer_object"))
1459 {
1460 int width = getWindowWidth();
1461 int height = getWindowHeight();
1462
1463 GLuint tex2D;
1464 glGenTextures(1, &tex2D);
1465 glActiveTexture(GL_TEXTURE0);
1466 glBindTexture(GL_TEXTURE_2D, tex2D);
1467
1468 // Fill with red
1469 std::vector<GLubyte> pixels(3 * 16 * 16);
1470 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1471 {
1472 pixels[pixelId * 3 + 0] = 255;
1473 pixels[pixelId * 3 + 1] = 0;
1474 pixels[pixelId * 3 + 2] = 0;
1475 }
1476
1477 // Read 16x16 region from red backbuffer to PBO
1478 GLuint pbo;
1479 glGenBuffers(1, &pbo);
1480 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1481 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1482
1483 // ANGLE internally uses RGBA as the DirectX format for RGB images
1484 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1485 // The data is kept in a CPU-side image and the image is marked as dirty.
1486 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1487
1488 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1489 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001490 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 +00001491 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1492 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1493
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001494 setUpProgram();
1495
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001496 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001497 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001498 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001499 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001500 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001501 EXPECT_GL_NO_ERROR();
1502 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1503 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1504 }
1505}
Jamie Madillbc393df2015-01-29 13:46:07 -05001506
1507// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001508TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001509{
1510 testFloatCopySubImage(1, 1);
1511}
1512
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001513TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001514{
1515 testFloatCopySubImage(2, 1);
1516}
1517
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001518TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001519{
1520 testFloatCopySubImage(2, 2);
1521}
1522
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001523TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001524{
1525 testFloatCopySubImage(3, 1);
1526}
1527
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001528TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001529{
1530 testFloatCopySubImage(3, 2);
1531}
1532
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001533TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001534{
Yunchao He9550c602018-02-13 14:47:05 +08001535 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1536 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001537
Yunchao He9550c602018-02-13 14:47:05 +08001538 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1539 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001540
Jamie Madillbc393df2015-01-29 13:46:07 -05001541 testFloatCopySubImage(3, 3);
1542}
1543
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001544TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001545{
1546 testFloatCopySubImage(4, 1);
1547}
1548
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001549TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001550{
1551 testFloatCopySubImage(4, 2);
1552}
1553
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001554TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001555{
Yunchao He9550c602018-02-13 14:47:05 +08001556 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1557 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001558
Jamie Madillbc393df2015-01-29 13:46:07 -05001559 testFloatCopySubImage(4, 3);
1560}
1561
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001562TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001563{
Luc Ferronfa7503c2018-05-08 11:25:06 -04001564 // TODO(lucferron): copySubImage isn't implemented yet.
1565 // http://anglebug.com/2501
1566 ANGLE_SKIP_TEST_IF(IsVulkan());
1567
Yunchao He9550c602018-02-13 14:47:05 +08001568 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1569 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001570
Jamie Madillbc393df2015-01-29 13:46:07 -05001571 testFloatCopySubImage(4, 4);
1572}
Austin Kinross07285142015-03-26 11:36:16 -07001573
1574// Port of https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1575// Run against GL_ALPHA/UNSIGNED_BYTE format, to ensure that D3D11 Feature Level 9_3 correctly handles GL_ALPHA
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001576TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001577{
Luc Ferron5164b792018-03-06 09:10:12 -05001578 // TODO(lucferron): DIRTY_BIT_UNPACK_STATE isn't implemented on Vulkan yet.
1579 ANGLE_SKIP_TEST_IF(IsVulkan());
1580
Austin Kinross07285142015-03-26 11:36:16 -07001581 const int npotTexSize = 5;
1582 const int potTexSize = 4; // Should be less than npotTexSize
1583 GLuint tex2D;
1584
1585 if (extensionEnabled("GL_OES_texture_npot"))
1586 {
1587 // This test isn't applicable if texture_npot is enabled
1588 return;
1589 }
1590
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001591 setUpProgram();
1592
Austin Kinross07285142015-03-26 11:36:16 -07001593 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1594
Austin Kinross5faa15b2016-01-11 13:32:48 -08001595 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1596 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1597
Austin Kinross07285142015-03-26 11:36:16 -07001598 glActiveTexture(GL_TEXTURE0);
1599 glGenTextures(1, &tex2D);
1600 glBindTexture(GL_TEXTURE_2D, tex2D);
1601
1602 std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize);
1603 for (size_t pixelId = 0; pixelId < npotTexSize * npotTexSize; ++pixelId)
1604 {
1605 pixels[pixelId] = 64;
1606 }
1607
1608 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1609 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1610
1611 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
1612 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1613 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1614
1615 // Check that an NPOT texture on level 0 succeeds
1616 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1617 EXPECT_GL_NO_ERROR();
1618
1619 // Check that generateMipmap fails on NPOT
1620 glGenerateMipmap(GL_TEXTURE_2D);
1621 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1622
1623 // Check that nothing is drawn if filtering is not correct for NPOT
1624 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1625 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1626 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1627 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1628 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001629 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001630 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1631
1632 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1633 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1634 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1635 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1636 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001637 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001638 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1639
1640 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1641 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1642 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001643 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001644 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1645
1646 // Check that glTexImage2D for POT texture succeeds
1647 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1648 EXPECT_GL_NO_ERROR();
1649
1650 // Check that generateMipmap for an POT texture succeeds
1651 glGenerateMipmap(GL_TEXTURE_2D);
1652 EXPECT_GL_NO_ERROR();
1653
1654 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1655 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1656 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1657 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1658 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1659 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001660 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001661 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1662 EXPECT_GL_NO_ERROR();
1663}
Jamie Madillfa05f602015-05-07 13:47:11 -04001664
Austin Kinross08528e12015-10-07 16:24:40 -07001665// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1666// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001667TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001668{
Luc Ferron5164b792018-03-06 09:10:12 -05001669 // TODO(lucferron): Generate mipmap on vulkan isn't implemented yet. Re-enable this when it
1670 // is.
1671 ANGLE_SKIP_TEST_IF(IsVulkan());
1672
Austin Kinross08528e12015-10-07 16:24:40 -07001673 glActiveTexture(GL_TEXTURE0);
1674 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1675
1676 // Create an 8x8 (i.e. power-of-two) texture.
1677 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1678 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1679 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1680 glGenerateMipmap(GL_TEXTURE_2D);
1681
1682 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1683 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001684 std::array<GLColor, 3 * 3> data;
1685 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001686
1687 EXPECT_GL_NO_ERROR();
1688}
1689
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001690// Test to check that texture completeness is determined correctly when the texture base level is
1691// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1692TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1693{
1694 glActiveTexture(GL_TEXTURE0);
1695 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001696
1697 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1698 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1699 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1700 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1701 texDataGreen.data());
1702 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1703 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001704 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1705 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1706 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1707
1708 EXPECT_GL_NO_ERROR();
1709
1710 drawQuad(mProgram, "position", 0.5f);
1711
Olli Etuahoa314b612016-03-10 16:43:00 +02001712 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1713}
1714
1715// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1716// have images defined.
1717TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1718{
Yunchao He9550c602018-02-13 14:47:05 +08001719 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1720 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1721
Olli Etuahoa314b612016-03-10 16:43:00 +02001722 glActiveTexture(GL_TEXTURE0);
1723 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1724 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1725 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1726 texDataGreen.data());
1727 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1728 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1729 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1730 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1731
1732 EXPECT_GL_NO_ERROR();
1733
1734 drawQuad(mProgram, "position", 0.5f);
1735
1736 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1737}
1738
Olli Etuahoe8528d82016-05-16 17:50:52 +03001739// Test that drawing works correctly when level 0 is undefined and base level is 1.
1740TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1741{
Yunchao He9550c602018-02-13 14:47:05 +08001742 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1743 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1744
Olli Etuahoe8528d82016-05-16 17:50:52 +03001745 glActiveTexture(GL_TEXTURE0);
1746 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1747 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1748 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1749 texDataGreen.data());
1750 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1751 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1752 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1753 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1754
1755 EXPECT_GL_NO_ERROR();
1756
1757 // Texture is incomplete.
1758 drawQuad(mProgram, "position", 0.5f);
1759 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1760
1761 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1762 texDataGreen.data());
1763
1764 // Texture is now complete.
1765 drawQuad(mProgram, "position", 0.5f);
1766 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1767}
1768
Olli Etuahoa314b612016-03-10 16:43:00 +02001769// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1770// dimensions that don't fit the images inside the range.
1771// GLES 3.0.4 section 3.8.13 Texture completeness
1772TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1773{
Olli Etuahoa314b612016-03-10 16:43:00 +02001774 glActiveTexture(GL_TEXTURE0);
1775 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1776 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1777 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1778 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1779
1780 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1781 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1782
1783 // Two levels that are initially unused.
1784 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1785 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1786 texDataCyan.data());
1787
1788 // One level that is used - only this level should affect completeness.
1789 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1790 texDataGreen.data());
1791
1792 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1793 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1794
1795 EXPECT_GL_NO_ERROR();
1796
1797 drawQuad(mProgram, "position", 0.5f);
1798
1799 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1800
Yunchao He2f23f352018-02-11 22:11:37 +08001801 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001802
1803 // Switch the level that is being used to the cyan level 2.
1804 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1805 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1806
1807 EXPECT_GL_NO_ERROR();
1808
1809 drawQuad(mProgram, "position", 0.5f);
1810
1811 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1812}
1813
1814// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1815// have images defined.
1816TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1817{
Olli Etuahoa314b612016-03-10 16:43:00 +02001818 glActiveTexture(GL_TEXTURE0);
1819 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1820 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1821 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1822 texDataGreen.data());
1823 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1824 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1825 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1826 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1827
1828 EXPECT_GL_NO_ERROR();
1829
1830 drawQuad(mProgram, "position", 0.5f);
1831
1832 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1833}
1834
1835// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1836// dimensions that don't fit the images inside the range.
1837// GLES 3.0.4 section 3.8.13 Texture completeness
1838TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1839{
Olli Etuahoa314b612016-03-10 16:43:00 +02001840 glActiveTexture(GL_TEXTURE0);
1841 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1842 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1843 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1844 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1845
1846 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1847 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1848
1849 // Two levels that are initially unused.
1850 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1851 texDataRed.data());
1852 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1853 texDataCyan.data());
1854
1855 // One level that is used - only this level should affect completeness.
1856 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1857 texDataGreen.data());
1858
1859 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1860 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1861
1862 EXPECT_GL_NO_ERROR();
1863
1864 drawQuad(mProgram, "position", 0.5f);
1865
1866 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1867
Yunchao He2f23f352018-02-11 22:11:37 +08001868 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001869
1870 // Switch the level that is being used to the cyan level 2.
1871 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
1872 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
1873
1874 EXPECT_GL_NO_ERROR();
1875
1876 drawQuad(mProgram, "position", 0.5f);
1877
1878 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1879}
1880
1881// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1882// have images defined.
1883TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
1884{
Olli Etuahoa314b612016-03-10 16:43:00 +02001885 glActiveTexture(GL_TEXTURE0);
1886 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
1887 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1888 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1889 texDataGreen.data());
1890 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1891 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1892 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1893 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1894
1895 EXPECT_GL_NO_ERROR();
1896
1897 drawQuad(mProgram, "position", 0.5f);
1898
1899 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1900}
1901
1902// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1903// dimensions that don't fit the images inside the range.
1904// GLES 3.0.4 section 3.8.13 Texture completeness
1905TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1906{
Olli Etuahoa314b612016-03-10 16:43:00 +02001907 glActiveTexture(GL_TEXTURE0);
1908 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
1909 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1910 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1911 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1912
1913 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1914 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1915
1916 // Two levels that are initially unused.
1917 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1918 texDataRed.data());
1919 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1920 texDataCyan.data());
1921
1922 // One level that is used - only this level should affect completeness.
1923 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1924 texDataGreen.data());
1925
1926 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1927 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1928
1929 EXPECT_GL_NO_ERROR();
1930
1931 drawQuad(mProgram, "position", 0.5f);
1932
1933 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1934
Yunchao He2f23f352018-02-11 22:11:37 +08001935 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
1936
Yunchao He9550c602018-02-13 14:47:05 +08001937 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
1938 // level was changed.
1939 ANGLE_SKIP_TEST_IF(IsNVIDIA() && (IsOpenGL() || IsOpenGLES()));
Olli Etuahoa314b612016-03-10 16:43:00 +02001940
1941 // Switch the level that is being used to the cyan level 2.
1942 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
1943 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
1944
1945 EXPECT_GL_NO_ERROR();
1946
1947 drawQuad(mProgram, "position", 0.5f);
1948
1949 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1950}
1951
1952// Test that texture completeness is updated if texture max level changes.
1953// GLES 3.0.4 section 3.8.13 Texture completeness
1954TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
1955{
Olli Etuahoa314b612016-03-10 16:43:00 +02001956 glActiveTexture(GL_TEXTURE0);
1957 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1958 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
1959
1960 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1961 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1962
1963 // A level that is initially unused.
1964 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1965 texDataGreen.data());
1966
1967 // One level that is initially used - only this level should affect completeness.
1968 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1969 texDataGreen.data());
1970
1971 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
1972 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
1973
1974 EXPECT_GL_NO_ERROR();
1975
1976 drawQuad(mProgram, "position", 0.5f);
1977
1978 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1979
1980 // Switch the max level to level 1. The levels within the used range now have inconsistent
1981 // dimensions and the texture should be incomplete.
1982 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1983
1984 EXPECT_GL_NO_ERROR();
1985
1986 drawQuad(mProgram, "position", 0.5f);
1987
1988 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1989}
1990
1991// Test that 3D texture completeness is updated if texture max level changes.
1992// GLES 3.0.4 section 3.8.13 Texture completeness
1993TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
1994{
Olli Etuahoa314b612016-03-10 16:43:00 +02001995 glActiveTexture(GL_TEXTURE0);
1996 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1997 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1998
1999 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2000 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2001
2002 // A level that is initially unused.
2003 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2004 texDataGreen.data());
2005
2006 // One level that is initially used - only this level should affect completeness.
2007 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2008 texDataGreen.data());
2009
2010 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2011 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2012
2013 EXPECT_GL_NO_ERROR();
2014
2015 drawQuad(mProgram, "position", 0.5f);
2016
2017 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2018
2019 // Switch the max level to level 1. The levels within the used range now have inconsistent
2020 // dimensions and the texture should be incomplete.
2021 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2022
2023 EXPECT_GL_NO_ERROR();
2024
2025 drawQuad(mProgram, "position", 0.5f);
2026
2027 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2028}
2029
2030// Test that texture completeness is updated if texture base level changes.
2031// GLES 3.0.4 section 3.8.13 Texture completeness
2032TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2033{
Olli Etuahoa314b612016-03-10 16:43:00 +02002034 glActiveTexture(GL_TEXTURE0);
2035 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2036 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2037
2038 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2039 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2040
2041 // Two levels that are initially unused.
2042 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2043 texDataGreen.data());
2044 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2045 texDataGreen.data());
2046
2047 // One level that is initially used - only this level should affect completeness.
2048 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2049 texDataGreen.data());
2050
2051 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2052 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2053
2054 EXPECT_GL_NO_ERROR();
2055
2056 drawQuad(mProgram, "position", 0.5f);
2057
2058 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2059
2060 // Switch the base level to level 1. The levels within the used range now have inconsistent
2061 // dimensions and the texture should be incomplete.
2062 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2063
2064 EXPECT_GL_NO_ERROR();
2065
2066 drawQuad(mProgram, "position", 0.5f);
2067
2068 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2069}
2070
2071// Test that texture is not complete if base level is greater than max level.
2072// GLES 3.0.4 section 3.8.13 Texture completeness
2073TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2074{
Olli Etuahoa314b612016-03-10 16:43:00 +02002075 glActiveTexture(GL_TEXTURE0);
2076 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2077
2078 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2079 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2080
2081 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2082
2083 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2084 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2085
2086 EXPECT_GL_NO_ERROR();
2087
2088 drawQuad(mProgram, "position", 0.5f);
2089
2090 // Texture should be incomplete.
2091 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2092}
2093
2094// Test that immutable texture base level and max level are clamped.
2095// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2096TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2097{
Olli Etuahoa314b612016-03-10 16:43:00 +02002098 glActiveTexture(GL_TEXTURE0);
2099 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2100
2101 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2102 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2103
2104 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2105
2106 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2107
2108 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2109 // should be clamped to [base_level, levels - 1].
2110 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2111 // In the case of this test, those rules make the effective base level and max level 0.
2112 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2113 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2114
2115 EXPECT_GL_NO_ERROR();
2116
2117 drawQuad(mProgram, "position", 0.5f);
2118
2119 // Texture should be complete.
2120 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2121}
2122
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002123// Test that changing base level works when it affects the format of the texture.
2124TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2125{
Yunchao He9550c602018-02-13 14:47:05 +08002126 // Observed rendering corruption on NVIDIA OpenGL.
2127 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL());
2128
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002129 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002130
2131 // Observed incorrect rendering on AMD OpenGL.
2132 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002133
2134 glActiveTexture(GL_TEXTURE0);
2135 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2136 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2137 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2138
2139 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2140 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2141
2142 // RGBA8 level that's initially unused.
2143 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2144 texDataCyan.data());
2145
2146 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2147 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2148
2149 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2150 // format. It reads green channel data from the green and alpha channels of texDataGreen
2151 // (this is a bit hacky but works).
2152 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2153
2154 EXPECT_GL_NO_ERROR();
2155
2156 drawQuad(mProgram, "position", 0.5f);
2157
2158 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2159
2160 // Switch the texture to use the cyan level 0 with the RGBA format.
2161 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2162 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2163
2164 EXPECT_GL_NO_ERROR();
2165
2166 drawQuad(mProgram, "position", 0.5f);
2167
2168 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2169}
2170
Olli Etuahoa314b612016-03-10 16:43:00 +02002171// Test that setting a texture image works when base level is out of range.
2172TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2173{
2174 glActiveTexture(GL_TEXTURE0);
2175 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2176
2177 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2178 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2179
2180 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2181 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2182
2183 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2184
2185 EXPECT_GL_NO_ERROR();
2186
2187 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2188
2189 drawQuad(mProgram, "position", 0.5f);
2190
2191 // Texture should be complete.
2192 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002193}
2194
Jamie Madill2453dbc2015-07-14 11:35:42 -04002195// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG RBA->RGBA8, with 1.0
2196// in the alpha channel. This test covers a bug where redefining array textures with these formats does not work as
2197// expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002198TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002199{
2200 std::vector<GLubyte> pixelData;
2201 for (size_t count = 0; count < 5000; count++)
2202 {
2203 pixelData.push_back(0u);
2204 pixelData.push_back(255u);
2205 pixelData.push_back(0u);
2206 }
2207
2208 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002209 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002210 glUniform1i(mTextureArrayLocation, 0);
2211
2212 // The first draw worked correctly.
2213 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
2214
2215 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2216 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2217 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2218 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002219 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002220 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002221
2222 // The dimension of the respecification must match the original exactly to trigger the bug.
2223 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002224 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002225 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002226
2227 ASSERT_GL_NO_ERROR();
2228}
2229
Olli Etuaho1a679902016-01-14 12:21:47 +02002230// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2231// This test is needed especially to confirm that sampler registers get assigned correctly on
2232// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2233TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2234{
2235 glActiveTexture(GL_TEXTURE0);
2236 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2237 GLubyte texData[4];
2238 texData[0] = 0;
2239 texData[1] = 60;
2240 texData[2] = 0;
2241 texData[3] = 255;
2242 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2243
2244 glActiveTexture(GL_TEXTURE1);
2245 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2246 GLfloat depthTexData[1];
2247 depthTexData[0] = 0.5f;
2248 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2249 depthTexData);
2250
2251 glUseProgram(mProgram);
2252 glUniform1f(mDepthRefUniformLocation, 0.3f);
2253 glUniform1i(mTexture3DUniformLocation, 0);
2254 glUniform1i(mTextureShadowUniformLocation, 1);
2255
2256 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2257 drawQuad(mProgram, "position", 0.5f);
2258 EXPECT_GL_NO_ERROR();
2259 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2260 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2261
2262 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2263 drawQuad(mProgram, "position", 0.5f);
2264 EXPECT_GL_NO_ERROR();
2265 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2266 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2267}
2268
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002269// Test multiple different sampler types in the same shader.
2270// This test makes sure that even if sampler / texture registers get grouped together based on type
2271// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2272// still has the right register index information for each ESSL sampler.
2273// The tested ESSL samplers have the following types in D3D11 HLSL:
2274// sampler2D: Texture2D + SamplerState
2275// samplerCube: TextureCube + SamplerState
2276// sampler2DShadow: Texture2D + SamplerComparisonState
2277// samplerCubeShadow: TextureCube + SamplerComparisonState
2278TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2279{
2280 glActiveTexture(GL_TEXTURE0);
2281 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2282 GLubyte texData[4];
2283 texData[0] = 0;
2284 texData[1] = 0;
2285 texData[2] = 120;
2286 texData[3] = 255;
2287 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2288
2289 glActiveTexture(GL_TEXTURE1);
2290 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2291 texData[0] = 0;
2292 texData[1] = 90;
2293 texData[2] = 0;
2294 texData[3] = 255;
2295 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2296 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2297 texData);
2298
2299 glActiveTexture(GL_TEXTURE2);
2300 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2301 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2302 GLfloat depthTexData[1];
2303 depthTexData[0] = 0.5f;
2304 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2305 depthTexData);
2306
2307 glActiveTexture(GL_TEXTURE3);
2308 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2309 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2310 depthTexData[0] = 0.2f;
2311 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2312 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2313 depthTexData);
2314
2315 EXPECT_GL_NO_ERROR();
2316
2317 glUseProgram(mProgram);
2318 glUniform1f(mDepthRefUniformLocation, 0.3f);
2319 glUniform1i(mTexture2DUniformLocation, 0);
2320 glUniform1i(mTextureCubeUniformLocation, 1);
2321 glUniform1i(mTexture2DShadowUniformLocation, 2);
2322 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2323
2324 drawQuad(mProgram, "position", 0.5f);
2325 EXPECT_GL_NO_ERROR();
2326 // The shader writes:
2327 // <texture 2d color> +
2328 // <cube map color> +
2329 // 0.25 * <comparison result (1.0)> +
2330 // 0.125 * <comparison result (0.0)>
2331 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2332}
2333
Olli Etuahobce743a2016-01-15 17:18:28 +02002334// Test different base levels on textures accessed through the same sampler array.
2335// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2336TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2337{
Yunchao He9550c602018-02-13 14:47:05 +08002338 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2339
Olli Etuahobce743a2016-01-15 17:18:28 +02002340 glActiveTexture(GL_TEXTURE0);
2341 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2342 GLsizei size = 64;
2343 for (GLint level = 0; level < 7; ++level)
2344 {
2345 ASSERT_LT(0, size);
2346 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2347 nullptr);
2348 size = size / 2;
2349 }
2350 ASSERT_EQ(0, size);
2351 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2352
2353 glActiveTexture(GL_TEXTURE1);
2354 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2355 size = 128;
2356 for (GLint level = 0; level < 8; ++level)
2357 {
2358 ASSERT_LT(0, size);
2359 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2360 nullptr);
2361 size = size / 2;
2362 }
2363 ASSERT_EQ(0, size);
2364 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2365 EXPECT_GL_NO_ERROR();
2366
2367 glUseProgram(mProgram);
2368 glUniform1i(mTexture0Location, 0);
2369 glUniform1i(mTexture1Location, 1);
2370
Olli Etuaho5804dc82018-04-13 14:11:46 +03002371 drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
Olli Etuahobce743a2016-01-15 17:18:28 +02002372 EXPECT_GL_NO_ERROR();
2373 // Red channel: width of level 1 of texture A: 32.
2374 // Green channel: width of level 3 of texture B: 16.
2375 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2376}
2377
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002378// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2379// ES 3.0.4 table 3.24
2380TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2381{
2382 glActiveTexture(GL_TEXTURE0);
2383 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2384 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2385 EXPECT_GL_NO_ERROR();
2386
2387 drawQuad(mProgram, "position", 0.5f);
2388
2389 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2390}
2391
2392// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2393// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002394TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002395{
Luc Ferron5164b792018-03-06 09:10:12 -05002396 setUpProgram();
2397
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002398 glActiveTexture(GL_TEXTURE0);
2399 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2400 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2401 EXPECT_GL_NO_ERROR();
2402
2403 drawQuad(mProgram, "position", 0.5f);
2404
2405 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2406}
2407
Luc Ferron5164b792018-03-06 09:10:12 -05002408// Validate that every component of the pixel will be equal to the luminance value we've set
2409// and that the alpha channel will be 1 (or 255 to be exact).
2410TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2411{
2412 setUpProgram();
2413
2414 glActiveTexture(GL_TEXTURE0);
2415 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2416 uint8_t pixel = 50;
2417 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2418 EXPECT_GL_NO_ERROR();
2419
2420 drawQuad(mProgram, "position", 0.5f);
2421
2422 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2423}
2424
2425// Validate that every component of the pixel will be equal to the luminance value we've set
2426// and that the alpha channel will be the second component.
2427TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2428{
2429 setUpProgram();
2430
2431 glActiveTexture(GL_TEXTURE0);
2432 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2433 uint8_t pixel[] = {50, 25};
2434 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2435 GL_UNSIGNED_BYTE, pixel);
2436 EXPECT_GL_NO_ERROR();
2437
2438 drawQuad(mProgram, "position", 0.5f);
2439
2440 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2441}
2442
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002443// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2444// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002445TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002446{
Luc Ferrond8c632c2018-04-10 12:31:44 -04002447 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
2448 ANGLE_SKIP_TEST_IF(IsD3D9());
2449 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002450
2451 setUpProgram();
2452
Luc Ferrond8c632c2018-04-10 12:31:44 -04002453 glActiveTexture(GL_TEXTURE0);
2454 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2455 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2456 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002457
Luc Ferrond8c632c2018-04-10 12:31:44 -04002458 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002459
Luc Ferrond8c632c2018-04-10 12:31:44 -04002460 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002461}
2462
2463// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2464// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002465TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002466{
Luc Ferrond8c632c2018-04-10 12:31:44 -04002467 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
2468 ANGLE_SKIP_TEST_IF(IsD3D9());
2469 ANGLE_SKIP_TEST_IF(IsVulkan());
2470 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES());
2471 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2472 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002473
Luc Ferrond8c632c2018-04-10 12:31:44 -04002474 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002475
Luc Ferrond8c632c2018-04-10 12:31:44 -04002476 glActiveTexture(GL_TEXTURE0);
2477 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2478 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2479 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002480
Luc Ferrond8c632c2018-04-10 12:31:44 -04002481 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002482
Luc Ferrond8c632c2018-04-10 12:31:44 -04002483 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002484}
2485
2486// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2487// ES 3.0.4 table 3.24
2488TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2489{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002490 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2491
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002492 glActiveTexture(GL_TEXTURE0);
2493 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2494 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2495 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2496 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2497 EXPECT_GL_NO_ERROR();
2498
2499 drawQuad(mProgram, "position", 0.5f);
2500
2501 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2502}
2503
2504// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2505// ES 3.0.4 table 3.24
2506TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2507{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002508 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2509
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002510 glActiveTexture(GL_TEXTURE0);
2511 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2512
2513 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2514 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2515 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2516 EXPECT_GL_NO_ERROR();
2517
2518 drawQuad(mProgram, "position", 0.5f);
2519
2520 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2521}
2522
2523// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2524// ES 3.0.4 table 3.24
2525TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2526{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002527 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2528
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002529 glActiveTexture(GL_TEXTURE0);
2530 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2531 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2532 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2533 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2534 EXPECT_GL_NO_ERROR();
2535
2536 drawQuad(mProgram, "position", 0.5f);
2537
2538 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2539}
2540
2541// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2542// ES 3.0.4 table 3.24
2543TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2544{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002545 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2546
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002547 glActiveTexture(GL_TEXTURE0);
2548 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2549 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2550 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2551 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2552 EXPECT_GL_NO_ERROR();
2553
2554 drawQuad(mProgram, "position", 0.5f);
2555
2556 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2557}
2558
2559// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2560// ES 3.0.4 table 3.24
2561TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2562{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002563 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2564
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002565 glActiveTexture(GL_TEXTURE0);
2566 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2567 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2568 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2569 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2570 EXPECT_GL_NO_ERROR();
2571
2572 drawQuad(mProgram, "position", 0.5f);
2573
2574 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2575}
2576
2577// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2578// ES 3.0.4 table 3.24
2579TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2580{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002581 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2582
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002583 glActiveTexture(GL_TEXTURE0);
2584 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2585 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2586 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2587 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2588 EXPECT_GL_NO_ERROR();
2589
2590 drawQuad(mProgram, "position", 0.5f);
2591
2592 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2593}
2594
2595// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2596// ES 3.0.4 table 3.24
2597TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2598{
2599 glActiveTexture(GL_TEXTURE0);
2600 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2601 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2602 EXPECT_GL_NO_ERROR();
2603
2604 drawQuad(mProgram, "position", 0.5f);
2605
2606 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2607}
2608
2609// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2610// ES 3.0.4 table 3.24
2611TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2612{
2613 glActiveTexture(GL_TEXTURE0);
2614 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2615 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2616 nullptr);
2617 EXPECT_GL_NO_ERROR();
2618
2619 drawQuad(mProgram, "position", 0.5f);
2620
2621 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2622}
2623
2624// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2625// ES 3.0.4 table 3.24
2626TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2627{
Yunchao He9550c602018-02-13 14:47:05 +08002628 // Seems to fail on OSX 10.12 Intel.
2629 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Jamie Madillbb1db482017-01-10 10:48:32 -05002630
Yuly Novikov49886892018-01-23 21:18:27 -05002631 // http://anglebug.com/2190
2632 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2633
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002634 glActiveTexture(GL_TEXTURE0);
2635 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2636 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2637 EXPECT_GL_NO_ERROR();
2638
2639 drawQuad(mProgram, "position", 0.5f);
2640
2641 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2642}
2643
2644// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2645// ES 3.0.4 table 3.24
2646TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2647{
Yunchao He9550c602018-02-13 14:47:05 +08002648 // Seems to fail on OSX 10.12 Intel.
2649 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002650
Yuly Novikov49886892018-01-23 21:18:27 -05002651 // http://anglebug.com/2190
2652 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2653
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002654 glActiveTexture(GL_TEXTURE0);
2655 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2656 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2657 EXPECT_GL_NO_ERROR();
2658
2659 drawQuad(mProgram, "position", 0.5f);
2660
2661 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2662}
2663
Olli Etuaho96963162016-03-21 11:54:33 +02002664// Use a sampler in a uniform struct.
2665TEST_P(SamplerInStructTest, SamplerInStruct)
2666{
2667 runSamplerInStructTest();
2668}
2669
2670// Use a sampler in a uniform struct that's passed as a function parameter.
2671TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2672{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002673 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002674 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002675
Olli Etuaho96963162016-03-21 11:54:33 +02002676 runSamplerInStructTest();
2677}
2678
2679// Use a sampler in a uniform struct array with a struct from the array passed as a function
2680// parameter.
2681TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2682{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002683 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002684 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
2685
Olli Etuaho96963162016-03-21 11:54:33 +02002686 runSamplerInStructTest();
2687}
2688
2689// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2690// parameter.
2691TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2692{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002693 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002694 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
2695
Olli Etuaho96963162016-03-21 11:54:33 +02002696 runSamplerInStructTest();
2697}
2698
2699// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2700// similarly named uniform.
2701TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2702{
2703 runSamplerInStructTest();
2704}
2705
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002706class TextureLimitsTest : public ANGLETest
2707{
2708 protected:
2709 struct RGBA8
2710 {
2711 uint8_t R, G, B, A;
2712 };
2713
2714 TextureLimitsTest()
2715 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
2716 {
2717 setWindowWidth(128);
2718 setWindowHeight(128);
2719 setConfigRedBits(8);
2720 setConfigGreenBits(8);
2721 setConfigBlueBits(8);
2722 setConfigAlphaBits(8);
2723 }
2724
2725 ~TextureLimitsTest()
2726 {
2727 if (mProgram != 0)
2728 {
2729 glDeleteProgram(mProgram);
2730 mProgram = 0;
2731
2732 if (!mTextures.empty())
2733 {
2734 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
2735 }
2736 }
2737 }
2738
2739 void SetUp() override
2740 {
2741 ANGLETest::SetUp();
2742
2743 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
2744 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
2745 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
2746
2747 ASSERT_GL_NO_ERROR();
2748 }
2749
2750 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
2751 GLint vertexTextureCount,
2752 GLint vertexActiveTextureCount,
2753 const std::string &fragPrefix,
2754 GLint fragmentTextureCount,
2755 GLint fragmentActiveTextureCount)
2756 {
2757 std::stringstream vertexShaderStr;
2758 vertexShaderStr << "attribute vec2 position;\n"
2759 << "varying vec4 color;\n"
2760 << "varying vec2 texCoord;\n";
2761
2762 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
2763 {
2764 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
2765 }
2766
2767 vertexShaderStr << "void main() {\n"
2768 << " gl_Position = vec4(position, 0, 1);\n"
2769 << " texCoord = (position * 0.5) + 0.5;\n"
2770 << " color = vec4(0);\n";
2771
2772 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
2773 {
2774 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
2775 << ", texCoord);\n";
2776 }
2777
2778 vertexShaderStr << "}";
2779
2780 std::stringstream fragmentShaderStr;
2781 fragmentShaderStr << "varying mediump vec4 color;\n"
2782 << "varying mediump vec2 texCoord;\n";
2783
2784 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
2785 {
2786 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
2787 }
2788
2789 fragmentShaderStr << "void main() {\n"
2790 << " gl_FragColor = color;\n";
2791
2792 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
2793 {
2794 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
2795 << ", texCoord);\n";
2796 }
2797
2798 fragmentShaderStr << "}";
2799
2800 const std::string &vertexShaderSource = vertexShaderStr.str();
2801 const std::string &fragmentShaderSource = fragmentShaderStr.str();
2802
2803 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
2804 }
2805
2806 RGBA8 getPixel(GLint texIndex)
2807 {
2808 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
2809 0, 255u};
2810 return pixel;
2811 }
2812
2813 void initTextures(GLint tex2DCount, GLint texCubeCount)
2814 {
2815 GLint totalCount = tex2DCount + texCubeCount;
2816 mTextures.assign(totalCount, 0);
2817 glGenTextures(totalCount, &mTextures[0]);
2818 ASSERT_GL_NO_ERROR();
2819
2820 std::vector<RGBA8> texData(16 * 16);
2821
2822 GLint texIndex = 0;
2823 for (; texIndex < tex2DCount; ++texIndex)
2824 {
2825 texData.assign(texData.size(), getPixel(texIndex));
2826 glActiveTexture(GL_TEXTURE0 + texIndex);
2827 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
2828 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2829 &texData[0]);
2830 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2831 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2832 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2833 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2834 }
2835
2836 ASSERT_GL_NO_ERROR();
2837
2838 for (; texIndex < texCubeCount; ++texIndex)
2839 {
2840 texData.assign(texData.size(), getPixel(texIndex));
2841 glActiveTexture(GL_TEXTURE0 + texIndex);
2842 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
2843 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2844 GL_UNSIGNED_BYTE, &texData[0]);
2845 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2846 GL_UNSIGNED_BYTE, &texData[0]);
2847 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2848 GL_UNSIGNED_BYTE, &texData[0]);
2849 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2850 GL_UNSIGNED_BYTE, &texData[0]);
2851 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2852 GL_UNSIGNED_BYTE, &texData[0]);
2853 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2854 GL_UNSIGNED_BYTE, &texData[0]);
2855 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2856 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2857 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2858 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2859 }
2860
2861 ASSERT_GL_NO_ERROR();
2862 }
2863
2864 void testWithTextures(GLint vertexTextureCount,
2865 const std::string &vertexTexturePrefix,
2866 GLint fragmentTextureCount,
2867 const std::string &fragmentTexturePrefix)
2868 {
2869 // Generate textures
2870 initTextures(vertexTextureCount + fragmentTextureCount, 0);
2871
2872 glUseProgram(mProgram);
2873 RGBA8 expectedSum = {0};
2874 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
2875 {
2876 std::stringstream uniformNameStr;
2877 uniformNameStr << vertexTexturePrefix << texIndex;
2878 const std::string &uniformName = uniformNameStr.str();
2879 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
2880 ASSERT_NE(-1, location);
2881
2882 glUniform1i(location, texIndex);
2883 RGBA8 contribution = getPixel(texIndex);
2884 expectedSum.R += contribution.R;
2885 expectedSum.G += contribution.G;
2886 }
2887
2888 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
2889 {
2890 std::stringstream uniformNameStr;
2891 uniformNameStr << fragmentTexturePrefix << texIndex;
2892 const std::string &uniformName = uniformNameStr.str();
2893 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
2894 ASSERT_NE(-1, location);
2895
2896 glUniform1i(location, texIndex + vertexTextureCount);
2897 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
2898 expectedSum.R += contribution.R;
2899 expectedSum.G += contribution.G;
2900 }
2901
2902 ASSERT_GE(256u, expectedSum.G);
2903
2904 drawQuad(mProgram, "position", 0.5f);
2905 ASSERT_GL_NO_ERROR();
2906 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
2907 }
2908
2909 GLuint mProgram;
2910 std::vector<GLuint> mTextures;
2911 GLint mMaxVertexTextures;
2912 GLint mMaxFragmentTextures;
2913 GLint mMaxCombinedTextures;
2914};
2915
2916// Test rendering with the maximum vertex texture units.
2917TEST_P(TextureLimitsTest, MaxVertexTextures)
2918{
2919 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
2920 ASSERT_NE(0u, mProgram);
2921 ASSERT_GL_NO_ERROR();
2922
2923 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
2924}
2925
2926// Test rendering with the maximum fragment texture units.
2927TEST_P(TextureLimitsTest, MaxFragmentTextures)
2928{
2929 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
2930 ASSERT_NE(0u, mProgram);
2931 ASSERT_GL_NO_ERROR();
2932
2933 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
2934}
2935
2936// Test rendering with maximum combined texture units.
2937TEST_P(TextureLimitsTest, MaxCombinedTextures)
2938{
Luc Ferronaf883622018-06-08 15:57:31 -04002939 // TODO(lucferron): Diagnose and fix
2940 // http://anglebug.com/2654
2941 ANGLE_SKIP_TEST_IF(IsVulkan());
2942
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002943 GLint vertexTextures = mMaxVertexTextures;
2944
2945 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
2946 {
2947 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
2948 }
2949
2950 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
2951 mMaxFragmentTextures, mMaxFragmentTextures);
2952 ASSERT_NE(0u, mProgram);
2953 ASSERT_GL_NO_ERROR();
2954
2955 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
2956}
2957
2958// Negative test for exceeding the number of vertex textures
2959TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
2960{
2961 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
2962 0);
2963 ASSERT_EQ(0u, mProgram);
2964}
2965
2966// Negative test for exceeding the number of fragment textures
2967TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
2968{
2969 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
2970 mMaxFragmentTextures + 1);
2971 ASSERT_EQ(0u, mProgram);
2972}
2973
2974// Test active vertex textures under the limit, but excessive textures specified.
2975TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
2976{
Luc Ferronaf883622018-06-08 15:57:31 -04002977 // TODO(lucferron): Diagnose and fix
2978 // http://anglebug.com/2654
2979 ANGLE_SKIP_TEST_IF(IsVulkan());
2980
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002981 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
2982 ASSERT_NE(0u, mProgram);
2983 ASSERT_GL_NO_ERROR();
2984
2985 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
2986}
2987
2988// Test active fragment textures under the limit, but excessive textures specified.
2989TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
2990{
Luc Ferronaf883622018-06-08 15:57:31 -04002991 // TODO(lucferron): Diagnose and fix
2992 // http://anglebug.com/2654
2993 ANGLE_SKIP_TEST_IF(IsVulkan());
2994
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002995 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
2996 mMaxFragmentTextures);
2997 ASSERT_NE(0u, mProgram);
2998 ASSERT_GL_NO_ERROR();
2999
3000 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3001}
3002
3003// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003004// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003005TEST_P(TextureLimitsTest, TextureTypeConflict)
3006{
3007 const std::string &vertexShader =
3008 "attribute vec2 position;\n"
3009 "varying float color;\n"
3010 "uniform sampler2D tex2D;\n"
3011 "uniform samplerCube texCube;\n"
3012 "void main() {\n"
3013 " gl_Position = vec4(position, 0, 1);\n"
3014 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3015 " color = texture2D(tex2D, texCoord).x;\n"
3016 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3017 "}";
3018 const std::string &fragmentShader =
3019 "varying mediump float color;\n"
3020 "void main() {\n"
3021 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3022 "}";
3023
3024 mProgram = CompileProgram(vertexShader, fragmentShader);
3025 ASSERT_NE(0u, mProgram);
3026
3027 initTextures(1, 0);
3028
3029 glUseProgram(mProgram);
3030 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3031 ASSERT_NE(-1, tex2DLocation);
3032 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3033 ASSERT_NE(-1, texCubeLocation);
3034
3035 glUniform1i(tex2DLocation, 0);
3036 glUniform1i(texCubeLocation, 0);
3037 ASSERT_GL_NO_ERROR();
3038
3039 drawQuad(mProgram, "position", 0.5f);
3040 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3041}
3042
Vincent Lang25ab4512016-05-13 18:13:59 +02003043class Texture2DNorm16TestES3 : public Texture2DTestES3
3044{
3045 protected:
3046 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3047
3048 void SetUp() override
3049 {
3050 Texture2DTestES3::SetUp();
3051
3052 glActiveTexture(GL_TEXTURE0);
3053 glGenTextures(3, mTextures);
3054 glGenFramebuffers(1, &mFBO);
3055 glGenRenderbuffers(1, &mRenderbuffer);
3056
3057 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3058 {
3059 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3060 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3061 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3062 }
3063
3064 glBindTexture(GL_TEXTURE_2D, 0);
3065
3066 ASSERT_GL_NO_ERROR();
3067 }
3068
3069 void TearDown() override
3070 {
3071 glDeleteTextures(3, mTextures);
3072 glDeleteFramebuffers(1, &mFBO);
3073 glDeleteRenderbuffers(1, &mRenderbuffer);
3074
3075 Texture2DTestES3::TearDown();
3076 }
3077
3078 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3079 {
Geoff Langf607c602016-09-21 11:46:48 -04003080 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3081 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003082
3083 setUpProgram();
3084
3085 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3086 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3087 0);
3088
3089 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3090 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3091
3092 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003093 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003094
3095 EXPECT_GL_NO_ERROR();
3096
3097 drawQuad(mProgram, "position", 0.5f);
3098
Geoff Langf607c602016-09-21 11:46:48 -04003099 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003100
Geoff Langf607c602016-09-21 11:46:48 -04003101 EXPECT_PIXEL_COLOR_EQ(
3102 0, 0, SliceFormatColor(
3103 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003104
3105 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3106
3107 ASSERT_GL_NO_ERROR();
3108 }
3109
3110 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3111 {
3112 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003113 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003114
3115 setUpProgram();
3116
3117 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3118 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3119
3120 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3121 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3122 0);
3123
3124 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003125 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003126
3127 EXPECT_GL_NO_ERROR();
3128
3129 drawQuad(mProgram, "position", 0.5f);
3130
Geoff Langf607c602016-09-21 11:46:48 -04003131 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
3132 EXPECT_PIXEL_COLOR_EQ(
3133 0, 0, SliceFormatColor(
3134 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003135
3136 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3137 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3138 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3139 mRenderbuffer);
3140 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3141 EXPECT_GL_NO_ERROR();
3142
3143 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3144 glClear(GL_COLOR_BUFFER_BIT);
3145
3146 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3147
Geoff Langf607c602016-09-21 11:46:48 -04003148 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003149
3150 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3151
3152 ASSERT_GL_NO_ERROR();
3153 }
3154
3155 GLuint mTextures[3];
3156 GLuint mFBO;
3157 GLuint mRenderbuffer;
3158};
3159
3160// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3161TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3162{
Yunchao He9550c602018-02-13 14:47:05 +08003163 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02003164
3165 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3166 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3167 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3168 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3169 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3170 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3171 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3172 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3173
3174 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3175 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3176 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3177}
3178
Olli Etuaho95faa232016-06-07 14:01:53 -07003179// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3180// GLES 3.0.4 section 3.8.3.
3181TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3182{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08003183 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
3184
Yuly Novikov3c754192016-06-27 19:36:41 -04003185 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1429 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08003186 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07003187
3188 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3189 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3190 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3191 ASSERT_GL_NO_ERROR();
3192
3193 // SKIP_IMAGES should not have an effect on uploading 2D textures
3194 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3195 ASSERT_GL_NO_ERROR();
3196
3197 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3198
3199 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3200 pixelsGreen.data());
3201 ASSERT_GL_NO_ERROR();
3202
3203 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3204 pixelsGreen.data());
3205 ASSERT_GL_NO_ERROR();
3206
3207 glUseProgram(mProgram);
3208 drawQuad(mProgram, "position", 0.5f);
3209 ASSERT_GL_NO_ERROR();
3210
3211 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3212}
3213
Olli Etuaho989cac32016-06-08 16:18:49 -07003214// Test that skip defined in unpack parameters is taken into account when determining whether
3215// unpacking source extends outside unpack buffer bounds.
3216TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3217{
3218 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3219 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3220 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3221 ASSERT_GL_NO_ERROR();
3222
3223 GLBuffer buf;
3224 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3225 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3226 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3227 GL_DYNAMIC_COPY);
3228 ASSERT_GL_NO_ERROR();
3229
3230 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3231 ASSERT_GL_NO_ERROR();
3232
3233 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3234 ASSERT_GL_NO_ERROR();
3235
3236 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3237 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3238
3239 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3240 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3241 ASSERT_GL_NO_ERROR();
3242
3243 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3244 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3245}
3246
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003247// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3248TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3249{
Yunchao He9550c602018-02-13 14:47:05 +08003250 ANGLE_SKIP_TEST_IF(IsD3D11());
3251
3252 // Incorrect rendering results seen on OSX AMD.
3253 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003254
3255 const GLuint width = 8u;
3256 const GLuint height = 8u;
3257 const GLuint unpackRowLength = 5u;
3258 const GLuint unpackSkipPixels = 1u;
3259
3260 setWindowWidth(width);
3261 setWindowHeight(height);
3262
3263 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3264 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3265 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3266 ASSERT_GL_NO_ERROR();
3267
3268 GLBuffer buf;
3269 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3270 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3271 GLColor::green);
3272
3273 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3274 {
3275 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3276 }
3277
3278 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3279 GL_DYNAMIC_COPY);
3280 ASSERT_GL_NO_ERROR();
3281
3282 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3283 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3284 ASSERT_GL_NO_ERROR();
3285
3286 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3287 ASSERT_GL_NO_ERROR();
3288
3289 glUseProgram(mProgram);
3290 drawQuad(mProgram, "position", 0.5f);
3291 ASSERT_GL_NO_ERROR();
3292
3293 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3294 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3295 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3296 actual.data());
3297 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3298 EXPECT_EQ(expected, actual);
3299}
3300
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003301template <typename T>
3302T UNorm(double value)
3303{
3304 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3305}
3306
3307// Test rendering a depth texture with mipmaps.
3308TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3309{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003310 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3311 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
3312 // http://anglebugs.com/1706
Yunchao He9550c602018-02-13 14:47:05 +08003313 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows());
Corentin Walleze731d8a2016-09-07 10:56:25 -04003314
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003315 const int size = getWindowWidth();
3316
3317 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003318 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003319
3320 glActiveTexture(GL_TEXTURE0);
3321 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3322 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3323 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3324 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3325 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3326 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3327 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3328 ASSERT_GL_NO_ERROR();
3329
3330 glUseProgram(mProgram);
3331 glUniform1i(mTexture2DUniformLocation, 0);
3332
3333 std::vector<unsigned char> expected;
3334
3335 for (int level = 0; level < levels; ++level)
3336 {
3337 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3338 expected.push_back(UNorm<unsigned char>(value));
3339
3340 int levelDim = dim(level);
3341
3342 ASSERT_GT(levelDim, 0);
3343
3344 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3345 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3346 GL_UNSIGNED_INT, initData.data());
3347 }
3348 ASSERT_GL_NO_ERROR();
3349
3350 for (int level = 0; level < levels; ++level)
3351 {
3352 glViewport(0, 0, dim(level), dim(level));
3353 drawQuad(mProgram, "position", 0.5f);
3354 GLColor actual = ReadColor(0, 0);
3355 EXPECT_NEAR(expected[level], actual.R, 10u);
3356 }
3357
3358 ASSERT_GL_NO_ERROR();
3359}
3360
Jamie Madill7ffdda92016-09-08 13:26:51 -04003361// Tests unpacking into the unsized GL_ALPHA format.
3362TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3363{
Jamie Madill7ffdda92016-09-08 13:26:51 -04003364 // Initialize the texure.
3365 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3366 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3367 GL_UNSIGNED_BYTE, nullptr);
3368 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3369 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3370
3371 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3372
3373 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04003374 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04003375 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3376 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3377 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
3378 GL_STATIC_DRAW);
3379
3380 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
3381 GL_UNSIGNED_BYTE, nullptr);
3382
3383 // Clear to a weird color to make sure we're drawing something.
3384 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
3385 glClear(GL_COLOR_BUFFER_BIT);
3386
3387 // Draw with the alpha texture and verify.
3388 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04003389
3390 ASSERT_GL_NO_ERROR();
3391 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
3392}
3393
Jamie Madill2e600342016-09-19 13:56:40 -04003394// Ensure stale unpack data doesn't propagate in D3D11.
3395TEST_P(Texture2DTestES3, StaleUnpackData)
3396{
3397 // Init unpack buffer.
3398 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
3399 std::vector<GLColor> pixels(pixelCount, GLColor::red);
3400
3401 GLBuffer unpackBuffer;
3402 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3403 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3404 GLsizei bufferSize = pixelCount * sizeof(GLColor);
3405 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
3406
3407 // Create from unpack buffer.
3408 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3409 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
3410 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3411 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3412 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3413
3414 drawQuad(mProgram, "position", 0.5f);
3415
3416 ASSERT_GL_NO_ERROR();
3417 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3418
3419 // Fill unpack with green, recreating buffer.
3420 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
3421 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
3422 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
3423
3424 // Reinit texture with green.
3425 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
3426 GL_UNSIGNED_BYTE, nullptr);
3427
3428 drawQuad(mProgram, "position", 0.5f);
3429
3430 ASSERT_GL_NO_ERROR();
3431 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3432}
3433
Geoff Langfb7685f2017-11-13 11:44:11 -05003434// Ensure that texture parameters passed as floats that are converted to ints are rounded before
3435// validating they are less than 0.
3436TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
3437{
3438 GLTexture texture;
3439 glBindTexture(GL_TEXTURE_2D, texture);
3440
3441 // Use a negative number that will round to zero when converted to an integer
3442 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
3443 // "Validation of values performed by state-setting commands is performed after conversion,
3444 // unless specified otherwise for a specific command."
3445 GLfloat param = -7.30157126e-07f;
3446 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
3447 EXPECT_GL_NO_ERROR();
3448
3449 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
3450 EXPECT_GL_NO_ERROR();
3451}
3452
Jamie Madillf097e232016-11-05 00:44:15 -04003453// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
3454// being properly checked, and the texture storage of the previous texture format was persisting.
3455// This would result in an ASSERT in debug and incorrect rendering in release.
3456// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
3457TEST_P(Texture3DTestES3, FormatRedefinitionBug)
3458{
3459 GLTexture tex;
3460 glBindTexture(GL_TEXTURE_3D, tex.get());
3461 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3462
3463 GLFramebuffer framebuffer;
3464 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3465 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
3466
3467 glCheckFramebufferStatus(GL_FRAMEBUFFER);
3468
3469 std::vector<uint8_t> pixelData(100, 0);
3470
3471 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
3472 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
3473 pixelData.data());
3474
3475 ASSERT_GL_NO_ERROR();
3476}
3477
Corentin Wallezd2627992017-04-28 17:17:03 -04003478// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
3479TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
3480{
3481 // 2D tests
3482 {
3483 GLTexture tex;
3484 glBindTexture(GL_TEXTURE_2D, tex.get());
3485
3486 GLBuffer pbo;
3487 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3488
3489 // Test OOB
3490 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
3491 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3492 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3493
3494 // Test OOB
3495 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
3496 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3497 ASSERT_GL_NO_ERROR();
3498 }
3499
3500 // 3D tests
3501 {
3502 GLTexture tex;
3503 glBindTexture(GL_TEXTURE_3D, tex.get());
3504
3505 GLBuffer pbo;
3506 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3507
3508 // Test OOB
3509 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
3510 GL_STATIC_DRAW);
3511 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3512 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3513
3514 // Test OOB
3515 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
3516 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3517 ASSERT_GL_NO_ERROR();
3518 }
3519}
3520
Jamie Madill3ed60422017-09-07 11:32:52 -04003521// Tests behaviour with a single texture and multiple sampler objects.
3522TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
3523{
3524 GLint maxTextureUnits = 0;
3525 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
3526 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
3527
3528 constexpr int kSize = 16;
3529
3530 // Make a single-level texture, fill it with red.
3531 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
3532 GLTexture tex;
3533 glBindTexture(GL_TEXTURE_2D, tex);
3534 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3535 redColors.data());
3536 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3537 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3538
3539 // Simple sanity check.
3540 draw2DTexturedQuad(0.5f, 1.0f, true);
3541 ASSERT_GL_NO_ERROR();
3542 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3543
3544 // Bind texture to unit 1 with a sampler object making it incomplete.
3545 GLSampler sampler;
3546 glBindSampler(0, sampler);
3547 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3548 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3549
3550 // Make a mipmap texture, fill it with blue.
3551 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
3552 GLTexture mipmapTex;
3553 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3554 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3555 blueColors.data());
3556 glGenerateMipmap(GL_TEXTURE_2D);
3557
3558 // Draw with the sampler, expect blue.
3559 draw2DTexturedQuad(0.5f, 1.0f, true);
3560 ASSERT_GL_NO_ERROR();
3561 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
3562
3563 // Simple multitexturing program.
3564 const std::string vs =
3565 "#version 300 es\n"
3566 "in vec2 position;\n"
3567 "out vec2 texCoord;\n"
3568 "void main()\n"
3569 "{\n"
3570 " gl_Position = vec4(position, 0, 1);\n"
3571 " texCoord = position * 0.5 + vec2(0.5);\n"
3572 "}";
3573 const std::string fs =
3574 "#version 300 es\n"
3575 "precision mediump float;\n"
3576 "in vec2 texCoord;\n"
3577 "uniform sampler2D tex1;\n"
3578 "uniform sampler2D tex2;\n"
3579 "uniform sampler2D tex3;\n"
3580 "uniform sampler2D tex4;\n"
3581 "out vec4 color;\n"
3582 "void main()\n"
3583 "{\n"
3584 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
3585 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
3586 "}";
3587
3588 ANGLE_GL_PROGRAM(program, vs, fs);
3589
3590 std::array<GLint, 4> texLocations = {
3591 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
3592 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
3593 for (GLint location : texLocations)
3594 {
3595 ASSERT_NE(-1, location);
3596 }
3597
3598 // Init the uniform data.
3599 glUseProgram(program);
3600 for (GLint location = 0; location < 4; ++location)
3601 {
3602 glUniform1i(texLocations[location], location);
3603 }
3604
3605 // Initialize four samplers
3606 GLSampler samplers[4];
3607
3608 // 0: non-mipped.
3609 glBindSampler(0, samplers[0]);
3610 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3611 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3612
3613 // 1: mipped.
3614 glBindSampler(1, samplers[1]);
3615 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3616 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3617
3618 // 2: non-mipped.
3619 glBindSampler(2, samplers[2]);
3620 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3621 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3622
3623 // 3: mipped.
3624 glBindSampler(3, samplers[3]);
3625 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3626 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3627
3628 // Bind two blue mipped textures and two single layer textures, should all draw.
3629 glActiveTexture(GL_TEXTURE0);
3630 glBindTexture(GL_TEXTURE_2D, tex);
3631
3632 glActiveTexture(GL_TEXTURE1);
3633 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3634
3635 glActiveTexture(GL_TEXTURE2);
3636 glBindTexture(GL_TEXTURE_2D, tex);
3637
3638 glActiveTexture(GL_TEXTURE3);
3639 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3640
3641 ASSERT_GL_NO_ERROR();
3642
3643 drawQuad(program, "position", 0.5f);
3644 ASSERT_GL_NO_ERROR();
3645 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
3646
3647 // Bind four single layer textures, two should be incomplete.
3648 glActiveTexture(GL_TEXTURE1);
3649 glBindTexture(GL_TEXTURE_2D, tex);
3650
3651 glActiveTexture(GL_TEXTURE3);
3652 glBindTexture(GL_TEXTURE_2D, tex);
3653
3654 drawQuad(program, "position", 0.5f);
3655 ASSERT_GL_NO_ERROR();
3656 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
3657}
3658
Martin Radev7e2c0d32017-09-15 14:25:42 +03003659// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
3660// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
3661// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
3662// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
3663// samples the cubemap using a direction vector (1,1,1).
3664TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
3665{
Yunchao He2f23f352018-02-11 22:11:37 +08003666 // Check http://anglebug.com/2155.
3667 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
3668
Martin Radev7e2c0d32017-09-15 14:25:42 +03003669 const std::string vs =
3670 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003671 precision mediump float;
3672 in vec3 pos;
3673 void main() {
3674 gl_Position = vec4(pos, 1.0);
3675 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003676
3677 const std::string fs =
3678 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003679 precision mediump float;
3680 out vec4 color;
3681 uniform samplerCube uTex;
3682 void main(){
3683 color = texture(uTex, vec3(1.0));
3684 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003685 ANGLE_GL_PROGRAM(program, vs, fs);
3686 glUseProgram(program);
3687
3688 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
3689 glActiveTexture(GL_TEXTURE0);
3690
3691 GLTexture cubeTex;
3692 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
3693
3694 const int kFaceWidth = 1;
3695 const int kFaceHeight = 1;
3696 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
3697 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3698 GL_UNSIGNED_BYTE, texData.data());
3699 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3700 GL_UNSIGNED_BYTE, texData.data());
3701 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3702 GL_UNSIGNED_BYTE, texData.data());
3703 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3704 GL_UNSIGNED_BYTE, texData.data());
3705 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3706 GL_UNSIGNED_BYTE, texData.data());
3707 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3708 GL_UNSIGNED_BYTE, texData.data());
3709 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3710 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3711 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
3712 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
3713 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
3714 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
3715
3716 drawQuad(program, "pos", 0.5f, 1.0f, true);
3717 ASSERT_GL_NO_ERROR();
3718
3719 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
3720}
3721
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08003722// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
3723TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
3724{
3725 GLuint texture = create2DTexture();
3726
3727 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
3728 EXPECT_GL_ERROR(GL_INVALID_VALUE);
3729
3730 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
3731 EXPECT_GL_ERROR(GL_INVALID_VALUE);
3732
3733 glDeleteTextures(1, &texture);
3734 EXPECT_GL_NO_ERROR();
3735}
3736
Olli Etuaho023371b2018-04-24 17:43:32 +03003737// Test setting base level after calling generateMipmap on a LUMA texture.
3738// Covers http://anglebug.com/2498
3739TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA)
3740{
3741 glActiveTexture(GL_TEXTURE0);
3742 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3743
3744 constexpr const GLsizei kWidth = 8;
3745 constexpr const GLsizei kHeight = 8;
3746 std::array<GLubyte, kWidth * kHeight * 2> whiteData;
3747 whiteData.fill(255u);
3748
3749 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA,
3750 GL_UNSIGNED_BYTE, whiteData.data());
3751 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
3752 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3753 glGenerateMipmap(GL_TEXTURE_2D);
3754 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
3755 EXPECT_GL_NO_ERROR();
3756
3757 drawQuad(mProgram, "position", 0.5f);
3758 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
3759}
3760
Jamie Madillfa05f602015-05-07 13:47:11 -04003761// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -05003762ANGLE_INSTANTIATE_TEST(Texture2DTest,
3763 ES2_D3D9(),
3764 ES2_D3D11(),
3765 ES2_D3D11_FL9_3(),
3766 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05003767 ES2_OPENGLES(),
3768 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003769ANGLE_INSTANTIATE_TEST(TextureCubeTest,
3770 ES2_D3D9(),
3771 ES2_D3D11(),
Geoff Langf7480ad2017-10-24 11:46:02 -04003772 ES2_D3D11_FL10_0(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003773 ES2_D3D11_FL9_3(),
3774 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04003775 ES2_OPENGLES(),
3776 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003777ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
3778 ES2_D3D9(),
3779 ES2_D3D11(),
3780 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003781 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04003782 ES2_OPENGLES(),
3783 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003784ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
3785 ES2_D3D9(),
3786 ES2_D3D11(),
3787 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003788 ES2_OPENGL(),
3789 ES2_OPENGLES());
3790ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
3791 ES2_D3D9(),
3792 ES2_D3D11(),
3793 ES2_D3D11_FL9_3(),
3794 ES2_OPENGL(),
3795 ES2_OPENGLES());
3796ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
3797 ES2_D3D9(),
3798 ES2_D3D11(),
3799 ES2_D3D11_FL9_3(),
3800 ES2_OPENGL(),
3801 ES2_OPENGLES());
3802ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02003803ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003804ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3805ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
3806 ES3_D3D11(),
3807 ES3_OPENGL(),
3808 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003809ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
3810 ES3_D3D11(),
3811 ES3_OPENGL(),
3812 ES3_OPENGLES());
3813ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3814ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02003815ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02003816ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
3817 ES2_D3D11(),
3818 ES2_D3D11_FL9_3(),
3819 ES2_D3D9(),
3820 ES2_OPENGL(),
3821 ES2_OPENGLES());
3822ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
3823 ES2_D3D11(),
3824 ES2_D3D11_FL9_3(),
3825 ES2_D3D9(),
3826 ES2_OPENGL(),
3827 ES2_OPENGLES());
3828ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
3829 ES2_D3D11(),
3830 ES2_D3D11_FL9_3(),
3831 ES2_D3D9(),
3832 ES2_OPENGL(),
3833 ES2_OPENGLES());
3834ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
3835 ES2_D3D11(),
3836 ES2_D3D11_FL9_3(),
3837 ES2_D3D9(),
3838 ES2_OPENGL(),
3839 ES2_OPENGLES());
3840ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
3841 ES2_D3D11(),
3842 ES2_D3D11_FL9_3(),
3843 ES2_D3D9(),
3844 ES2_OPENGL(),
3845 ES2_OPENGLES());
Luc Ferronaf883622018-06-08 15:57:31 -04003846ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN());
Vincent Lang25ab4512016-05-13 18:13:59 +02003847ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03003848ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04003849
Jamie Madill7ffdda92016-09-08 13:26:51 -04003850} // anonymous namespace