blob: 70edd59c7d36f7cec82c73c9cdbfa1d1b21cca23 [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{
Luc Ferrond8c632c2018-04-10 12:31:44 -04001234 // TODO(lucferron): Enable this test on Vulkan after Sampler Arrays are implemented.
1235 // http://anglebug.com/2462
Luc Ferron5164b792018-03-06 09:10:12 -05001236 ANGLE_SKIP_TEST_IF(IsVulkan());
1237
Jamie Madilld4cfa572014-07-08 10:00:32 -04001238 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001239 EXPECT_GL_ERROR(GL_NO_ERROR);
1240
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001241 setUpProgram();
1242
Geoff Langc41e42d2014-04-28 10:58:16 -04001243 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001244 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001245 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001246 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001247
1248 const GLubyte *pixel[4] = { 0 };
1249
1250 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1251 EXPECT_GL_NO_ERROR();
1252
1253 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1254 EXPECT_GL_NO_ERROR();
1255
1256 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1257 EXPECT_GL_NO_ERROR();
1258}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001259
1260// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001261TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001262{
1263 glActiveTexture(GL_TEXTURE0);
1264 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1265 glActiveTexture(GL_TEXTURE1);
1266 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1267 EXPECT_GL_ERROR(GL_NO_ERROR);
1268
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001269 glUseProgram(mProgram);
1270 glUniform1i(mTexture2DUniformLocation, 0);
1271 glUniform1i(mTextureCubeUniformLocation, 1);
1272 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001273 EXPECT_GL_NO_ERROR();
1274}
Jamie Madill9aca0592014-10-06 16:26:59 -04001275
Olli Etuaho53a2da12016-01-11 15:43:32 +02001276// Test drawing with two texture types accessed from the same shader and check that the result of
1277// drawing is correct.
1278TEST_P(TextureCubeTest, CubeMapDraw)
1279{
1280 GLubyte texData[4];
1281 texData[0] = 0;
1282 texData[1] = 60;
1283 texData[2] = 0;
1284 texData[3] = 255;
1285
1286 glActiveTexture(GL_TEXTURE0);
1287 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1288 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1289
1290 glActiveTexture(GL_TEXTURE1);
1291 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1292 texData[1] = 120;
1293 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1294 texData);
1295 EXPECT_GL_ERROR(GL_NO_ERROR);
1296
1297 glUseProgram(mProgram);
1298 glUniform1i(mTexture2DUniformLocation, 0);
1299 glUniform1i(mTextureCubeUniformLocation, 1);
1300 drawQuad(mProgram, "position", 0.5f);
1301 EXPECT_GL_NO_ERROR();
1302
1303 int px = getWindowWidth() - 1;
1304 int py = 0;
1305 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1306}
1307
Olli Etuaho4644a202016-01-12 15:12:53 +02001308TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1309{
1310 glActiveTexture(GL_TEXTURE0);
1311 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1312 GLubyte texData[4];
1313 texData[0] = 0;
1314 texData[1] = 128;
1315 texData[2] = 0;
1316 texData[3] = 255;
1317 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1318 glUseProgram(mProgram);
1319 glUniform1i(mTexture2DUniformLocation, 0);
1320 drawQuad(mProgram, "position", 0.5f);
1321 EXPECT_GL_NO_ERROR();
1322
1323 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1324}
1325
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001326// Test drawing with two textures passed to the shader in a sampler array.
1327TEST_P(SamplerArrayTest, SamplerArrayDraw)
1328{
1329 testSamplerArrayDraw();
1330}
1331
1332// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1333// user-defined function in the shader.
1334TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1335{
1336 testSamplerArrayDraw();
1337}
1338
Jamie Madill9aca0592014-10-06 16:26:59 -04001339// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001340TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001341{
1342 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{
1384 GLuint fbo;
1385 glGenFramebuffers(1, &fbo);
1386 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1387
1388 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1389 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mTextureCube, 0);
1390
Corentin Wallez322653b2015-06-17 18:33:56 +02001391 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001392
1393 glDeleteFramebuffers(1, &fbo);
1394
1395 EXPECT_GL_NO_ERROR();
1396}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001397
1398// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001399TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001400{
Luc Ferron7348fc52018-05-09 07:17:16 -04001401 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -04001402
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001403 int width = getWindowWidth();
1404 int height = getWindowHeight();
1405
1406 GLuint tex2D;
1407 glGenTextures(1, &tex2D);
1408 glActiveTexture(GL_TEXTURE0);
1409 glBindTexture(GL_TEXTURE_2D, tex2D);
1410
1411 // Fill with red
1412 std::vector<GLubyte> pixels(3 * 16 * 16);
1413 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1414 {
1415 pixels[pixelId * 3 + 0] = 255;
1416 pixels[pixelId * 3 + 1] = 0;
1417 pixels[pixelId * 3 + 2] = 0;
1418 }
1419
1420 // ANGLE internally uses RGBA as the DirectX format for RGB images
1421 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1422 // The data is kept in a CPU-side image and the image is marked as dirty.
Geoff Langc4e93662017-05-01 10:45:59 -04001423 if (getClientMajorVersion() >= 3)
1424 {
1425 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1426 }
1427 else
1428 {
1429 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1430 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001431
1432 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1433 // glTexSubImage2D should take into account that the image is dirty.
1434 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1435 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1436 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1437
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001438 setUpProgram();
1439
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001440 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001441 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001442 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001443 glDeleteTextures(1, &tex2D);
1444 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001445 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001446
1447 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001448 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1449 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001450}
1451
1452// 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 +02001453TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001454{
1455 if (extensionEnabled("NV_pixel_buffer_object"))
1456 {
1457 int width = getWindowWidth();
1458 int height = getWindowHeight();
1459
1460 GLuint tex2D;
1461 glGenTextures(1, &tex2D);
1462 glActiveTexture(GL_TEXTURE0);
1463 glBindTexture(GL_TEXTURE_2D, tex2D);
1464
1465 // Fill with red
1466 std::vector<GLubyte> pixels(3 * 16 * 16);
1467 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1468 {
1469 pixels[pixelId * 3 + 0] = 255;
1470 pixels[pixelId * 3 + 1] = 0;
1471 pixels[pixelId * 3 + 2] = 0;
1472 }
1473
1474 // Read 16x16 region from red backbuffer to PBO
1475 GLuint pbo;
1476 glGenBuffers(1, &pbo);
1477 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1478 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1479
1480 // ANGLE internally uses RGBA as the DirectX format for RGB images
1481 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1482 // The data is kept in a CPU-side image and the image is marked as dirty.
1483 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1484
1485 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1486 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001487 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 +00001488 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1489 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1490
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001491 setUpProgram();
1492
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001493 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001494 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001495 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001496 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001497 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001498 EXPECT_GL_NO_ERROR();
1499 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1500 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1501 }
1502}
Jamie Madillbc393df2015-01-29 13:46:07 -05001503
1504// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001505TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001506{
1507 testFloatCopySubImage(1, 1);
1508}
1509
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001510TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001511{
1512 testFloatCopySubImage(2, 1);
1513}
1514
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001515TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001516{
1517 testFloatCopySubImage(2, 2);
1518}
1519
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001520TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001521{
1522 testFloatCopySubImage(3, 1);
1523}
1524
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001525TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001526{
1527 testFloatCopySubImage(3, 2);
1528}
1529
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001530TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001531{
Yunchao He9550c602018-02-13 14:47:05 +08001532 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1533 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001534
Yunchao He9550c602018-02-13 14:47:05 +08001535 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1536 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001537
Jamie Madillbc393df2015-01-29 13:46:07 -05001538 testFloatCopySubImage(3, 3);
1539}
1540
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001541TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001542{
1543 testFloatCopySubImage(4, 1);
1544}
1545
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001546TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001547{
1548 testFloatCopySubImage(4, 2);
1549}
1550
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001551TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001552{
Yunchao He9550c602018-02-13 14:47:05 +08001553 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1554 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001555
Jamie Madillbc393df2015-01-29 13:46:07 -05001556 testFloatCopySubImage(4, 3);
1557}
1558
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001559TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001560{
Luc Ferronfa7503c2018-05-08 11:25:06 -04001561 // TODO(lucferron): copySubImage isn't implemented yet.
1562 // http://anglebug.com/2501
1563 ANGLE_SKIP_TEST_IF(IsVulkan());
1564
Yunchao He9550c602018-02-13 14:47:05 +08001565 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1566 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001567
Jamie Madillbc393df2015-01-29 13:46:07 -05001568 testFloatCopySubImage(4, 4);
1569}
Austin Kinross07285142015-03-26 11:36:16 -07001570
1571// Port of https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1572// 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 +02001573TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001574{
Luc Ferron5164b792018-03-06 09:10:12 -05001575 // TODO(lucferron): DIRTY_BIT_UNPACK_STATE isn't implemented on Vulkan yet.
1576 ANGLE_SKIP_TEST_IF(IsVulkan());
1577
Austin Kinross07285142015-03-26 11:36:16 -07001578 const int npotTexSize = 5;
1579 const int potTexSize = 4; // Should be less than npotTexSize
1580 GLuint tex2D;
1581
1582 if (extensionEnabled("GL_OES_texture_npot"))
1583 {
1584 // This test isn't applicable if texture_npot is enabled
1585 return;
1586 }
1587
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001588 setUpProgram();
1589
Austin Kinross07285142015-03-26 11:36:16 -07001590 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1591
Austin Kinross5faa15b2016-01-11 13:32:48 -08001592 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1593 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1594
Austin Kinross07285142015-03-26 11:36:16 -07001595 glActiveTexture(GL_TEXTURE0);
1596 glGenTextures(1, &tex2D);
1597 glBindTexture(GL_TEXTURE_2D, tex2D);
1598
1599 std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize);
1600 for (size_t pixelId = 0; pixelId < npotTexSize * npotTexSize; ++pixelId)
1601 {
1602 pixels[pixelId] = 64;
1603 }
1604
1605 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1606 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1607
1608 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
1609 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1610 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1611
1612 // Check that an NPOT texture on level 0 succeeds
1613 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1614 EXPECT_GL_NO_ERROR();
1615
1616 // Check that generateMipmap fails on NPOT
1617 glGenerateMipmap(GL_TEXTURE_2D);
1618 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1619
1620 // Check that nothing is drawn if filtering is not correct for NPOT
1621 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1622 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1623 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1624 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1625 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001626 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001627 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1628
1629 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1630 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1631 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1632 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1633 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001634 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001635 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1636
1637 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1638 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1639 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001640 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001641 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1642
1643 // Check that glTexImage2D for POT texture succeeds
1644 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1645 EXPECT_GL_NO_ERROR();
1646
1647 // Check that generateMipmap for an POT texture succeeds
1648 glGenerateMipmap(GL_TEXTURE_2D);
1649 EXPECT_GL_NO_ERROR();
1650
1651 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1652 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1653 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1654 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1655 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1656 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001657 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001658 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1659 EXPECT_GL_NO_ERROR();
1660}
Jamie Madillfa05f602015-05-07 13:47:11 -04001661
Austin Kinross08528e12015-10-07 16:24:40 -07001662// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1663// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001664TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001665{
Luc Ferron5164b792018-03-06 09:10:12 -05001666 // TODO(lucferron): Generate mipmap on vulkan isn't implemented yet. Re-enable this when it
1667 // is.
1668 ANGLE_SKIP_TEST_IF(IsVulkan());
1669
Austin Kinross08528e12015-10-07 16:24:40 -07001670 glActiveTexture(GL_TEXTURE0);
1671 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1672
1673 // Create an 8x8 (i.e. power-of-two) texture.
1674 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1675 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1676 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1677 glGenerateMipmap(GL_TEXTURE_2D);
1678
1679 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1680 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001681 std::array<GLColor, 3 * 3> data;
1682 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001683
1684 EXPECT_GL_NO_ERROR();
1685}
1686
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001687// Test to check that texture completeness is determined correctly when the texture base level is
1688// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1689TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1690{
1691 glActiveTexture(GL_TEXTURE0);
1692 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001693
1694 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1695 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1696 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1697 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1698 texDataGreen.data());
1699 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1700 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001701 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1702 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1703 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1704
1705 EXPECT_GL_NO_ERROR();
1706
1707 drawQuad(mProgram, "position", 0.5f);
1708
Olli Etuahoa314b612016-03-10 16:43:00 +02001709 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1710}
1711
1712// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1713// have images defined.
1714TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1715{
Yunchao He9550c602018-02-13 14:47:05 +08001716 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1717 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1718
Olli Etuahoa314b612016-03-10 16:43:00 +02001719 glActiveTexture(GL_TEXTURE0);
1720 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1721 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1722 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1723 texDataGreen.data());
1724 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1725 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1726 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1727 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1728
1729 EXPECT_GL_NO_ERROR();
1730
1731 drawQuad(mProgram, "position", 0.5f);
1732
1733 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1734}
1735
Olli Etuahoe8528d82016-05-16 17:50:52 +03001736// Test that drawing works correctly when level 0 is undefined and base level is 1.
1737TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1738{
Yunchao He9550c602018-02-13 14:47:05 +08001739 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1740 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1741
Olli Etuahoe8528d82016-05-16 17:50:52 +03001742 glActiveTexture(GL_TEXTURE0);
1743 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1744 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1745 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1746 texDataGreen.data());
1747 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1748 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1749 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1750 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1751
1752 EXPECT_GL_NO_ERROR();
1753
1754 // Texture is incomplete.
1755 drawQuad(mProgram, "position", 0.5f);
1756 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1757
1758 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1759 texDataGreen.data());
1760
1761 // Texture is now complete.
1762 drawQuad(mProgram, "position", 0.5f);
1763 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1764}
1765
Olli Etuahoa314b612016-03-10 16:43:00 +02001766// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1767// dimensions that don't fit the images inside the range.
1768// GLES 3.0.4 section 3.8.13 Texture completeness
1769TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1770{
Olli Etuahoa314b612016-03-10 16:43:00 +02001771 glActiveTexture(GL_TEXTURE0);
1772 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1773 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1774 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1775 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1776
1777 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1778 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1779
1780 // Two levels that are initially unused.
1781 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1782 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1783 texDataCyan.data());
1784
1785 // One level that is used - only this level should affect completeness.
1786 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1787 texDataGreen.data());
1788
1789 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1790 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1791
1792 EXPECT_GL_NO_ERROR();
1793
1794 drawQuad(mProgram, "position", 0.5f);
1795
1796 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1797
Yunchao He2f23f352018-02-11 22:11:37 +08001798 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001799
1800 // Switch the level that is being used to the cyan level 2.
1801 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1802 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1803
1804 EXPECT_GL_NO_ERROR();
1805
1806 drawQuad(mProgram, "position", 0.5f);
1807
1808 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1809}
1810
1811// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1812// have images defined.
1813TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1814{
Olli Etuahoa314b612016-03-10 16:43:00 +02001815 glActiveTexture(GL_TEXTURE0);
1816 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1817 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1818 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1819 texDataGreen.data());
1820 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1821 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1822 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1823 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1824
1825 EXPECT_GL_NO_ERROR();
1826
1827 drawQuad(mProgram, "position", 0.5f);
1828
1829 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1830}
1831
1832// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1833// dimensions that don't fit the images inside the range.
1834// GLES 3.0.4 section 3.8.13 Texture completeness
1835TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1836{
Olli Etuahoa314b612016-03-10 16:43:00 +02001837 glActiveTexture(GL_TEXTURE0);
1838 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1839 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1840 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1841 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1842
1843 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1844 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1845
1846 // Two levels that are initially unused.
1847 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1848 texDataRed.data());
1849 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1850 texDataCyan.data());
1851
1852 // One level that is used - only this level should affect completeness.
1853 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1854 texDataGreen.data());
1855
1856 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1857 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1858
1859 EXPECT_GL_NO_ERROR();
1860
1861 drawQuad(mProgram, "position", 0.5f);
1862
1863 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1864
Yunchao He2f23f352018-02-11 22:11:37 +08001865 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001866
1867 // Switch the level that is being used to the cyan level 2.
1868 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
1869 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
1870
1871 EXPECT_GL_NO_ERROR();
1872
1873 drawQuad(mProgram, "position", 0.5f);
1874
1875 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1876}
1877
1878// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1879// have images defined.
1880TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
1881{
Olli Etuahoa314b612016-03-10 16:43:00 +02001882 glActiveTexture(GL_TEXTURE0);
1883 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
1884 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1885 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1886 texDataGreen.data());
1887 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1888 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1889 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1890 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1891
1892 EXPECT_GL_NO_ERROR();
1893
1894 drawQuad(mProgram, "position", 0.5f);
1895
1896 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1897}
1898
1899// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1900// dimensions that don't fit the images inside the range.
1901// GLES 3.0.4 section 3.8.13 Texture completeness
1902TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1903{
Olli Etuahoa314b612016-03-10 16:43:00 +02001904 glActiveTexture(GL_TEXTURE0);
1905 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
1906 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1907 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1908 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1909
1910 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1911 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1912
1913 // Two levels that are initially unused.
1914 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1915 texDataRed.data());
1916 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1917 texDataCyan.data());
1918
1919 // One level that is used - only this level should affect completeness.
1920 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1921 texDataGreen.data());
1922
1923 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1924 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1925
1926 EXPECT_GL_NO_ERROR();
1927
1928 drawQuad(mProgram, "position", 0.5f);
1929
1930 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1931
Yunchao He2f23f352018-02-11 22:11:37 +08001932 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
1933
Yunchao He9550c602018-02-13 14:47:05 +08001934 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
1935 // level was changed.
1936 ANGLE_SKIP_TEST_IF(IsNVIDIA() && (IsOpenGL() || IsOpenGLES()));
Olli Etuahoa314b612016-03-10 16:43:00 +02001937
1938 // Switch the level that is being used to the cyan level 2.
1939 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
1940 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
1941
1942 EXPECT_GL_NO_ERROR();
1943
1944 drawQuad(mProgram, "position", 0.5f);
1945
1946 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1947}
1948
1949// Test that texture completeness is updated if texture max level changes.
1950// GLES 3.0.4 section 3.8.13 Texture completeness
1951TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
1952{
Olli Etuahoa314b612016-03-10 16:43:00 +02001953 glActiveTexture(GL_TEXTURE0);
1954 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1955 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
1956
1957 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1958 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1959
1960 // A level that is initially unused.
1961 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1962 texDataGreen.data());
1963
1964 // One level that is initially used - only this level should affect completeness.
1965 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1966 texDataGreen.data());
1967
1968 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
1969 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
1970
1971 EXPECT_GL_NO_ERROR();
1972
1973 drawQuad(mProgram, "position", 0.5f);
1974
1975 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1976
1977 // Switch the max level to level 1. The levels within the used range now have inconsistent
1978 // dimensions and the texture should be incomplete.
1979 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1980
1981 EXPECT_GL_NO_ERROR();
1982
1983 drawQuad(mProgram, "position", 0.5f);
1984
1985 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1986}
1987
1988// Test that 3D texture completeness is updated if texture max level changes.
1989// GLES 3.0.4 section 3.8.13 Texture completeness
1990TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
1991{
Olli Etuahoa314b612016-03-10 16:43:00 +02001992 glActiveTexture(GL_TEXTURE0);
1993 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1994 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1995
1996 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1997 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1998
1999 // A level that is initially unused.
2000 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2001 texDataGreen.data());
2002
2003 // One level that is initially used - only this level should affect completeness.
2004 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2005 texDataGreen.data());
2006
2007 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2008 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2009
2010 EXPECT_GL_NO_ERROR();
2011
2012 drawQuad(mProgram, "position", 0.5f);
2013
2014 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2015
2016 // Switch the max level to level 1. The levels within the used range now have inconsistent
2017 // dimensions and the texture should be incomplete.
2018 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2019
2020 EXPECT_GL_NO_ERROR();
2021
2022 drawQuad(mProgram, "position", 0.5f);
2023
2024 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2025}
2026
2027// Test that texture completeness is updated if texture base level changes.
2028// GLES 3.0.4 section 3.8.13 Texture completeness
2029TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2030{
Olli Etuahoa314b612016-03-10 16:43:00 +02002031 glActiveTexture(GL_TEXTURE0);
2032 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2033 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2034
2035 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2036 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2037
2038 // Two levels that are initially unused.
2039 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2040 texDataGreen.data());
2041 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2042 texDataGreen.data());
2043
2044 // One level that is initially used - only this level should affect completeness.
2045 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2046 texDataGreen.data());
2047
2048 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2049 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2050
2051 EXPECT_GL_NO_ERROR();
2052
2053 drawQuad(mProgram, "position", 0.5f);
2054
2055 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2056
2057 // Switch the base level to level 1. The levels within the used range now have inconsistent
2058 // dimensions and the texture should be incomplete.
2059 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2060
2061 EXPECT_GL_NO_ERROR();
2062
2063 drawQuad(mProgram, "position", 0.5f);
2064
2065 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2066}
2067
2068// Test that texture is not complete if base level is greater than max level.
2069// GLES 3.0.4 section 3.8.13 Texture completeness
2070TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2071{
Olli Etuahoa314b612016-03-10 16:43:00 +02002072 glActiveTexture(GL_TEXTURE0);
2073 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2074
2075 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2076 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2077
2078 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2079
2080 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2081 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2082
2083 EXPECT_GL_NO_ERROR();
2084
2085 drawQuad(mProgram, "position", 0.5f);
2086
2087 // Texture should be incomplete.
2088 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2089}
2090
2091// Test that immutable texture base level and max level are clamped.
2092// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2093TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2094{
Olli Etuahoa314b612016-03-10 16:43:00 +02002095 glActiveTexture(GL_TEXTURE0);
2096 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2097
2098 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2099 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2100
2101 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2102
2103 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2104
2105 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2106 // should be clamped to [base_level, levels - 1].
2107 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2108 // In the case of this test, those rules make the effective base level and max level 0.
2109 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2110 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2111
2112 EXPECT_GL_NO_ERROR();
2113
2114 drawQuad(mProgram, "position", 0.5f);
2115
2116 // Texture should be complete.
2117 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2118}
2119
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002120// Test that changing base level works when it affects the format of the texture.
2121TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2122{
Yunchao He9550c602018-02-13 14:47:05 +08002123 // Observed rendering corruption on NVIDIA OpenGL.
2124 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL());
2125
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002126 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002127
2128 // Observed incorrect rendering on AMD OpenGL.
2129 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002130
2131 glActiveTexture(GL_TEXTURE0);
2132 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2133 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2134 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2135
2136 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2137 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2138
2139 // RGBA8 level that's initially unused.
2140 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2141 texDataCyan.data());
2142
2143 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2144 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2145
2146 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2147 // format. It reads green channel data from the green and alpha channels of texDataGreen
2148 // (this is a bit hacky but works).
2149 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2150
2151 EXPECT_GL_NO_ERROR();
2152
2153 drawQuad(mProgram, "position", 0.5f);
2154
2155 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2156
2157 // Switch the texture to use the cyan level 0 with the RGBA format.
2158 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2159 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2160
2161 EXPECT_GL_NO_ERROR();
2162
2163 drawQuad(mProgram, "position", 0.5f);
2164
2165 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2166}
2167
Olli Etuahoa314b612016-03-10 16:43:00 +02002168// Test that setting a texture image works when base level is out of range.
2169TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2170{
2171 glActiveTexture(GL_TEXTURE0);
2172 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2173
2174 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2175 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2176
2177 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2178 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2179
2180 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2181
2182 EXPECT_GL_NO_ERROR();
2183
2184 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2185
2186 drawQuad(mProgram, "position", 0.5f);
2187
2188 // Texture should be complete.
2189 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002190}
2191
Jamie Madill2453dbc2015-07-14 11:35:42 -04002192// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG RBA->RGBA8, with 1.0
2193// in the alpha channel. This test covers a bug where redefining array textures with these formats does not work as
2194// expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002195TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002196{
2197 std::vector<GLubyte> pixelData;
2198 for (size_t count = 0; count < 5000; count++)
2199 {
2200 pixelData.push_back(0u);
2201 pixelData.push_back(255u);
2202 pixelData.push_back(0u);
2203 }
2204
2205 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002206 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002207 glUniform1i(mTextureArrayLocation, 0);
2208
2209 // The first draw worked correctly.
2210 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
2211
2212 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2213 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2214 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2215 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002216 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002217 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002218
2219 // The dimension of the respecification must match the original exactly to trigger the bug.
2220 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 +02002221 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002222 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002223
2224 ASSERT_GL_NO_ERROR();
2225}
2226
Olli Etuaho1a679902016-01-14 12:21:47 +02002227// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2228// This test is needed especially to confirm that sampler registers get assigned correctly on
2229// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2230TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2231{
2232 glActiveTexture(GL_TEXTURE0);
2233 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2234 GLubyte texData[4];
2235 texData[0] = 0;
2236 texData[1] = 60;
2237 texData[2] = 0;
2238 texData[3] = 255;
2239 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2240
2241 glActiveTexture(GL_TEXTURE1);
2242 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2243 GLfloat depthTexData[1];
2244 depthTexData[0] = 0.5f;
2245 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2246 depthTexData);
2247
2248 glUseProgram(mProgram);
2249 glUniform1f(mDepthRefUniformLocation, 0.3f);
2250 glUniform1i(mTexture3DUniformLocation, 0);
2251 glUniform1i(mTextureShadowUniformLocation, 1);
2252
2253 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2254 drawQuad(mProgram, "position", 0.5f);
2255 EXPECT_GL_NO_ERROR();
2256 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2257 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2258
2259 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2260 drawQuad(mProgram, "position", 0.5f);
2261 EXPECT_GL_NO_ERROR();
2262 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2263 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2264}
2265
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002266// Test multiple different sampler types in the same shader.
2267// This test makes sure that even if sampler / texture registers get grouped together based on type
2268// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2269// still has the right register index information for each ESSL sampler.
2270// The tested ESSL samplers have the following types in D3D11 HLSL:
2271// sampler2D: Texture2D + SamplerState
2272// samplerCube: TextureCube + SamplerState
2273// sampler2DShadow: Texture2D + SamplerComparisonState
2274// samplerCubeShadow: TextureCube + SamplerComparisonState
2275TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2276{
2277 glActiveTexture(GL_TEXTURE0);
2278 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2279 GLubyte texData[4];
2280 texData[0] = 0;
2281 texData[1] = 0;
2282 texData[2] = 120;
2283 texData[3] = 255;
2284 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2285
2286 glActiveTexture(GL_TEXTURE1);
2287 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2288 texData[0] = 0;
2289 texData[1] = 90;
2290 texData[2] = 0;
2291 texData[3] = 255;
2292 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2293 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2294 texData);
2295
2296 glActiveTexture(GL_TEXTURE2);
2297 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2298 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2299 GLfloat depthTexData[1];
2300 depthTexData[0] = 0.5f;
2301 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2302 depthTexData);
2303
2304 glActiveTexture(GL_TEXTURE3);
2305 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2306 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2307 depthTexData[0] = 0.2f;
2308 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2309 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2310 depthTexData);
2311
2312 EXPECT_GL_NO_ERROR();
2313
2314 glUseProgram(mProgram);
2315 glUniform1f(mDepthRefUniformLocation, 0.3f);
2316 glUniform1i(mTexture2DUniformLocation, 0);
2317 glUniform1i(mTextureCubeUniformLocation, 1);
2318 glUniform1i(mTexture2DShadowUniformLocation, 2);
2319 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2320
2321 drawQuad(mProgram, "position", 0.5f);
2322 EXPECT_GL_NO_ERROR();
2323 // The shader writes:
2324 // <texture 2d color> +
2325 // <cube map color> +
2326 // 0.25 * <comparison result (1.0)> +
2327 // 0.125 * <comparison result (0.0)>
2328 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2329}
2330
Olli Etuahobce743a2016-01-15 17:18:28 +02002331// Test different base levels on textures accessed through the same sampler array.
2332// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2333TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2334{
Yunchao He9550c602018-02-13 14:47:05 +08002335 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2336
Olli Etuahobce743a2016-01-15 17:18:28 +02002337 glActiveTexture(GL_TEXTURE0);
2338 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2339 GLsizei size = 64;
2340 for (GLint level = 0; level < 7; ++level)
2341 {
2342 ASSERT_LT(0, size);
2343 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2344 nullptr);
2345 size = size / 2;
2346 }
2347 ASSERT_EQ(0, size);
2348 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2349
2350 glActiveTexture(GL_TEXTURE1);
2351 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2352 size = 128;
2353 for (GLint level = 0; level < 8; ++level)
2354 {
2355 ASSERT_LT(0, size);
2356 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2357 nullptr);
2358 size = size / 2;
2359 }
2360 ASSERT_EQ(0, size);
2361 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2362 EXPECT_GL_NO_ERROR();
2363
2364 glUseProgram(mProgram);
2365 glUniform1i(mTexture0Location, 0);
2366 glUniform1i(mTexture1Location, 1);
2367
Olli Etuaho5804dc82018-04-13 14:11:46 +03002368 drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
Olli Etuahobce743a2016-01-15 17:18:28 +02002369 EXPECT_GL_NO_ERROR();
2370 // Red channel: width of level 1 of texture A: 32.
2371 // Green channel: width of level 3 of texture B: 16.
2372 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2373}
2374
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002375// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2376// ES 3.0.4 table 3.24
2377TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2378{
2379 glActiveTexture(GL_TEXTURE0);
2380 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2381 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2382 EXPECT_GL_NO_ERROR();
2383
2384 drawQuad(mProgram, "position", 0.5f);
2385
2386 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2387}
2388
2389// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2390// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002391TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002392{
Luc Ferron5164b792018-03-06 09:10:12 -05002393 setUpProgram();
2394
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002395 glActiveTexture(GL_TEXTURE0);
2396 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2397 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2398 EXPECT_GL_NO_ERROR();
2399
2400 drawQuad(mProgram, "position", 0.5f);
2401
2402 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2403}
2404
Luc Ferron5164b792018-03-06 09:10:12 -05002405// Validate that every component of the pixel will be equal to the luminance value we've set
2406// and that the alpha channel will be 1 (or 255 to be exact).
2407TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2408{
2409 setUpProgram();
2410
2411 glActiveTexture(GL_TEXTURE0);
2412 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2413 uint8_t pixel = 50;
2414 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2415 EXPECT_GL_NO_ERROR();
2416
2417 drawQuad(mProgram, "position", 0.5f);
2418
2419 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2420}
2421
2422// Validate that every component of the pixel will be equal to the luminance value we've set
2423// and that the alpha channel will be the second component.
2424TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2425{
2426 setUpProgram();
2427
2428 glActiveTexture(GL_TEXTURE0);
2429 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2430 uint8_t pixel[] = {50, 25};
2431 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2432 GL_UNSIGNED_BYTE, pixel);
2433 EXPECT_GL_NO_ERROR();
2434
2435 drawQuad(mProgram, "position", 0.5f);
2436
2437 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2438}
2439
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002440// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2441// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002442TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002443{
Luc Ferrond8c632c2018-04-10 12:31:44 -04002444 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
2445 ANGLE_SKIP_TEST_IF(IsD3D9());
2446 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002447
2448 setUpProgram();
2449
Luc Ferrond8c632c2018-04-10 12:31:44 -04002450 glActiveTexture(GL_TEXTURE0);
2451 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2452 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2453 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002454
Luc Ferrond8c632c2018-04-10 12:31:44 -04002455 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002456
Luc Ferrond8c632c2018-04-10 12:31:44 -04002457 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002458}
2459
2460// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2461// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002462TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002463{
Luc Ferrond8c632c2018-04-10 12:31:44 -04002464 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
2465 ANGLE_SKIP_TEST_IF(IsD3D9());
2466 ANGLE_SKIP_TEST_IF(IsVulkan());
2467 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES());
2468 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2469 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002470
Luc Ferrond8c632c2018-04-10 12:31:44 -04002471 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002472
Luc Ferrond8c632c2018-04-10 12:31:44 -04002473 glActiveTexture(GL_TEXTURE0);
2474 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2475 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2476 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002477
Luc Ferrond8c632c2018-04-10 12:31:44 -04002478 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002479
Luc Ferrond8c632c2018-04-10 12:31:44 -04002480 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002481}
2482
2483// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2484// ES 3.0.4 table 3.24
2485TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2486{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002487 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2488
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002489 glActiveTexture(GL_TEXTURE0);
2490 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2491 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2492 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2493 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2494 EXPECT_GL_NO_ERROR();
2495
2496 drawQuad(mProgram, "position", 0.5f);
2497
2498 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2499}
2500
2501// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2502// ES 3.0.4 table 3.24
2503TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2504{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002505 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2506
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002507 glActiveTexture(GL_TEXTURE0);
2508 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2509
2510 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2511 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2512 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2513 EXPECT_GL_NO_ERROR();
2514
2515 drawQuad(mProgram, "position", 0.5f);
2516
2517 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2518}
2519
2520// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2521// ES 3.0.4 table 3.24
2522TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2523{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002524 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2525
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002526 glActiveTexture(GL_TEXTURE0);
2527 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2528 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2529 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2530 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2531 EXPECT_GL_NO_ERROR();
2532
2533 drawQuad(mProgram, "position", 0.5f);
2534
2535 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2536}
2537
2538// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2539// ES 3.0.4 table 3.24
2540TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2541{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002542 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2543
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002544 glActiveTexture(GL_TEXTURE0);
2545 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2546 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2547 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2548 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2549 EXPECT_GL_NO_ERROR();
2550
2551 drawQuad(mProgram, "position", 0.5f);
2552
2553 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2554}
2555
2556// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2557// ES 3.0.4 table 3.24
2558TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2559{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002560 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2561
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002562 glActiveTexture(GL_TEXTURE0);
2563 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2564 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2565 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2566 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2567 EXPECT_GL_NO_ERROR();
2568
2569 drawQuad(mProgram, "position", 0.5f);
2570
2571 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2572}
2573
2574// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2575// ES 3.0.4 table 3.24
2576TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2577{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002578 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2579
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002580 glActiveTexture(GL_TEXTURE0);
2581 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2582 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2583 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2584 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2585 EXPECT_GL_NO_ERROR();
2586
2587 drawQuad(mProgram, "position", 0.5f);
2588
2589 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2590}
2591
2592// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2593// ES 3.0.4 table 3.24
2594TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2595{
2596 glActiveTexture(GL_TEXTURE0);
2597 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2598 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2599 EXPECT_GL_NO_ERROR();
2600
2601 drawQuad(mProgram, "position", 0.5f);
2602
2603 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2604}
2605
2606// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2607// ES 3.0.4 table 3.24
2608TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2609{
2610 glActiveTexture(GL_TEXTURE0);
2611 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2612 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2613 nullptr);
2614 EXPECT_GL_NO_ERROR();
2615
2616 drawQuad(mProgram, "position", 0.5f);
2617
2618 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2619}
2620
2621// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2622// ES 3.0.4 table 3.24
2623TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2624{
Yunchao He9550c602018-02-13 14:47:05 +08002625 // Seems to fail on OSX 10.12 Intel.
2626 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Jamie Madillbb1db482017-01-10 10:48:32 -05002627
Yuly Novikov49886892018-01-23 21:18:27 -05002628 // http://anglebug.com/2190
2629 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2630
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002631 glActiveTexture(GL_TEXTURE0);
2632 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2633 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2634 EXPECT_GL_NO_ERROR();
2635
2636 drawQuad(mProgram, "position", 0.5f);
2637
2638 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2639}
2640
2641// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2642// ES 3.0.4 table 3.24
2643TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2644{
Yunchao He9550c602018-02-13 14:47:05 +08002645 // Seems to fail on OSX 10.12 Intel.
2646 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002647
Yuly Novikov49886892018-01-23 21:18:27 -05002648 // http://anglebug.com/2190
2649 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2650
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002651 glActiveTexture(GL_TEXTURE0);
2652 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2653 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2654 EXPECT_GL_NO_ERROR();
2655
2656 drawQuad(mProgram, "position", 0.5f);
2657
2658 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2659}
2660
Olli Etuaho96963162016-03-21 11:54:33 +02002661// Use a sampler in a uniform struct.
2662TEST_P(SamplerInStructTest, SamplerInStruct)
2663{
2664 runSamplerInStructTest();
2665}
2666
2667// Use a sampler in a uniform struct that's passed as a function parameter.
2668TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2669{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002670 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002671 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002672
Olli Etuaho96963162016-03-21 11:54:33 +02002673 runSamplerInStructTest();
2674}
2675
2676// Use a sampler in a uniform struct array with a struct from the array passed as a function
2677// parameter.
2678TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2679{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002680 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002681 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
2682
Olli Etuaho96963162016-03-21 11:54:33 +02002683 runSamplerInStructTest();
2684}
2685
2686// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2687// parameter.
2688TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2689{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002690 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002691 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
2692
Olli Etuaho96963162016-03-21 11:54:33 +02002693 runSamplerInStructTest();
2694}
2695
2696// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2697// similarly named uniform.
2698TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2699{
2700 runSamplerInStructTest();
2701}
2702
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002703class TextureLimitsTest : public ANGLETest
2704{
2705 protected:
2706 struct RGBA8
2707 {
2708 uint8_t R, G, B, A;
2709 };
2710
2711 TextureLimitsTest()
2712 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
2713 {
2714 setWindowWidth(128);
2715 setWindowHeight(128);
2716 setConfigRedBits(8);
2717 setConfigGreenBits(8);
2718 setConfigBlueBits(8);
2719 setConfigAlphaBits(8);
2720 }
2721
2722 ~TextureLimitsTest()
2723 {
2724 if (mProgram != 0)
2725 {
2726 glDeleteProgram(mProgram);
2727 mProgram = 0;
2728
2729 if (!mTextures.empty())
2730 {
2731 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
2732 }
2733 }
2734 }
2735
2736 void SetUp() override
2737 {
2738 ANGLETest::SetUp();
2739
2740 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
2741 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
2742 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
2743
2744 ASSERT_GL_NO_ERROR();
2745 }
2746
2747 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
2748 GLint vertexTextureCount,
2749 GLint vertexActiveTextureCount,
2750 const std::string &fragPrefix,
2751 GLint fragmentTextureCount,
2752 GLint fragmentActiveTextureCount)
2753 {
2754 std::stringstream vertexShaderStr;
2755 vertexShaderStr << "attribute vec2 position;\n"
2756 << "varying vec4 color;\n"
2757 << "varying vec2 texCoord;\n";
2758
2759 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
2760 {
2761 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
2762 }
2763
2764 vertexShaderStr << "void main() {\n"
2765 << " gl_Position = vec4(position, 0, 1);\n"
2766 << " texCoord = (position * 0.5) + 0.5;\n"
2767 << " color = vec4(0);\n";
2768
2769 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
2770 {
2771 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
2772 << ", texCoord);\n";
2773 }
2774
2775 vertexShaderStr << "}";
2776
2777 std::stringstream fragmentShaderStr;
2778 fragmentShaderStr << "varying mediump vec4 color;\n"
2779 << "varying mediump vec2 texCoord;\n";
2780
2781 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
2782 {
2783 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
2784 }
2785
2786 fragmentShaderStr << "void main() {\n"
2787 << " gl_FragColor = color;\n";
2788
2789 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
2790 {
2791 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
2792 << ", texCoord);\n";
2793 }
2794
2795 fragmentShaderStr << "}";
2796
2797 const std::string &vertexShaderSource = vertexShaderStr.str();
2798 const std::string &fragmentShaderSource = fragmentShaderStr.str();
2799
2800 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
2801 }
2802
2803 RGBA8 getPixel(GLint texIndex)
2804 {
2805 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
2806 0, 255u};
2807 return pixel;
2808 }
2809
2810 void initTextures(GLint tex2DCount, GLint texCubeCount)
2811 {
2812 GLint totalCount = tex2DCount + texCubeCount;
2813 mTextures.assign(totalCount, 0);
2814 glGenTextures(totalCount, &mTextures[0]);
2815 ASSERT_GL_NO_ERROR();
2816
2817 std::vector<RGBA8> texData(16 * 16);
2818
2819 GLint texIndex = 0;
2820 for (; texIndex < tex2DCount; ++texIndex)
2821 {
2822 texData.assign(texData.size(), getPixel(texIndex));
2823 glActiveTexture(GL_TEXTURE0 + texIndex);
2824 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
2825 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2826 &texData[0]);
2827 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2828 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2829 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2830 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2831 }
2832
2833 ASSERT_GL_NO_ERROR();
2834
2835 for (; texIndex < texCubeCount; ++texIndex)
2836 {
2837 texData.assign(texData.size(), getPixel(texIndex));
2838 glActiveTexture(GL_TEXTURE0 + texIndex);
2839 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
2840 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2841 GL_UNSIGNED_BYTE, &texData[0]);
2842 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2843 GL_UNSIGNED_BYTE, &texData[0]);
2844 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2845 GL_UNSIGNED_BYTE, &texData[0]);
2846 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2847 GL_UNSIGNED_BYTE, &texData[0]);
2848 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2849 GL_UNSIGNED_BYTE, &texData[0]);
2850 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2851 GL_UNSIGNED_BYTE, &texData[0]);
2852 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2853 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2854 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2855 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2856 }
2857
2858 ASSERT_GL_NO_ERROR();
2859 }
2860
2861 void testWithTextures(GLint vertexTextureCount,
2862 const std::string &vertexTexturePrefix,
2863 GLint fragmentTextureCount,
2864 const std::string &fragmentTexturePrefix)
2865 {
2866 // Generate textures
2867 initTextures(vertexTextureCount + fragmentTextureCount, 0);
2868
2869 glUseProgram(mProgram);
2870 RGBA8 expectedSum = {0};
2871 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
2872 {
2873 std::stringstream uniformNameStr;
2874 uniformNameStr << vertexTexturePrefix << texIndex;
2875 const std::string &uniformName = uniformNameStr.str();
2876 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
2877 ASSERT_NE(-1, location);
2878
2879 glUniform1i(location, texIndex);
2880 RGBA8 contribution = getPixel(texIndex);
2881 expectedSum.R += contribution.R;
2882 expectedSum.G += contribution.G;
2883 }
2884
2885 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
2886 {
2887 std::stringstream uniformNameStr;
2888 uniformNameStr << fragmentTexturePrefix << texIndex;
2889 const std::string &uniformName = uniformNameStr.str();
2890 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
2891 ASSERT_NE(-1, location);
2892
2893 glUniform1i(location, texIndex + vertexTextureCount);
2894 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
2895 expectedSum.R += contribution.R;
2896 expectedSum.G += contribution.G;
2897 }
2898
2899 ASSERT_GE(256u, expectedSum.G);
2900
2901 drawQuad(mProgram, "position", 0.5f);
2902 ASSERT_GL_NO_ERROR();
2903 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
2904 }
2905
2906 GLuint mProgram;
2907 std::vector<GLuint> mTextures;
2908 GLint mMaxVertexTextures;
2909 GLint mMaxFragmentTextures;
2910 GLint mMaxCombinedTextures;
2911};
2912
2913// Test rendering with the maximum vertex texture units.
2914TEST_P(TextureLimitsTest, MaxVertexTextures)
2915{
2916 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
2917 ASSERT_NE(0u, mProgram);
2918 ASSERT_GL_NO_ERROR();
2919
2920 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
2921}
2922
2923// Test rendering with the maximum fragment texture units.
2924TEST_P(TextureLimitsTest, MaxFragmentTextures)
2925{
2926 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
2927 ASSERT_NE(0u, mProgram);
2928 ASSERT_GL_NO_ERROR();
2929
2930 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
2931}
2932
2933// Test rendering with maximum combined texture units.
2934TEST_P(TextureLimitsTest, MaxCombinedTextures)
2935{
2936 GLint vertexTextures = mMaxVertexTextures;
2937
2938 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
2939 {
2940 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
2941 }
2942
2943 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
2944 mMaxFragmentTextures, mMaxFragmentTextures);
2945 ASSERT_NE(0u, mProgram);
2946 ASSERT_GL_NO_ERROR();
2947
2948 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
2949}
2950
2951// Negative test for exceeding the number of vertex textures
2952TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
2953{
2954 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
2955 0);
2956 ASSERT_EQ(0u, mProgram);
2957}
2958
2959// Negative test for exceeding the number of fragment textures
2960TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
2961{
2962 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
2963 mMaxFragmentTextures + 1);
2964 ASSERT_EQ(0u, mProgram);
2965}
2966
2967// Test active vertex textures under the limit, but excessive textures specified.
2968TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
2969{
2970 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
2971 ASSERT_NE(0u, mProgram);
2972 ASSERT_GL_NO_ERROR();
2973
2974 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
2975}
2976
2977// Test active fragment textures under the limit, but excessive textures specified.
2978TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
2979{
2980 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
2981 mMaxFragmentTextures);
2982 ASSERT_NE(0u, mProgram);
2983 ASSERT_GL_NO_ERROR();
2984
2985 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
2986}
2987
2988// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002989// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002990TEST_P(TextureLimitsTest, TextureTypeConflict)
2991{
2992 const std::string &vertexShader =
2993 "attribute vec2 position;\n"
2994 "varying float color;\n"
2995 "uniform sampler2D tex2D;\n"
2996 "uniform samplerCube texCube;\n"
2997 "void main() {\n"
2998 " gl_Position = vec4(position, 0, 1);\n"
2999 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3000 " color = texture2D(tex2D, texCoord).x;\n"
3001 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3002 "}";
3003 const std::string &fragmentShader =
3004 "varying mediump float color;\n"
3005 "void main() {\n"
3006 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3007 "}";
3008
3009 mProgram = CompileProgram(vertexShader, fragmentShader);
3010 ASSERT_NE(0u, mProgram);
3011
3012 initTextures(1, 0);
3013
3014 glUseProgram(mProgram);
3015 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3016 ASSERT_NE(-1, tex2DLocation);
3017 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3018 ASSERT_NE(-1, texCubeLocation);
3019
3020 glUniform1i(tex2DLocation, 0);
3021 glUniform1i(texCubeLocation, 0);
3022 ASSERT_GL_NO_ERROR();
3023
3024 drawQuad(mProgram, "position", 0.5f);
3025 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3026}
3027
Vincent Lang25ab4512016-05-13 18:13:59 +02003028class Texture2DNorm16TestES3 : public Texture2DTestES3
3029{
3030 protected:
3031 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3032
3033 void SetUp() override
3034 {
3035 Texture2DTestES3::SetUp();
3036
3037 glActiveTexture(GL_TEXTURE0);
3038 glGenTextures(3, mTextures);
3039 glGenFramebuffers(1, &mFBO);
3040 glGenRenderbuffers(1, &mRenderbuffer);
3041
3042 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3043 {
3044 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3045 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3046 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3047 }
3048
3049 glBindTexture(GL_TEXTURE_2D, 0);
3050
3051 ASSERT_GL_NO_ERROR();
3052 }
3053
3054 void TearDown() override
3055 {
3056 glDeleteTextures(3, mTextures);
3057 glDeleteFramebuffers(1, &mFBO);
3058 glDeleteRenderbuffers(1, &mRenderbuffer);
3059
3060 Texture2DTestES3::TearDown();
3061 }
3062
3063 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3064 {
Geoff Langf607c602016-09-21 11:46:48 -04003065 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3066 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003067
3068 setUpProgram();
3069
3070 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3071 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3072 0);
3073
3074 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3075 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3076
3077 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003078 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003079
3080 EXPECT_GL_NO_ERROR();
3081
3082 drawQuad(mProgram, "position", 0.5f);
3083
Geoff Langf607c602016-09-21 11:46:48 -04003084 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003085
Geoff Langf607c602016-09-21 11:46:48 -04003086 EXPECT_PIXEL_COLOR_EQ(
3087 0, 0, SliceFormatColor(
3088 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003089
3090 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3091
3092 ASSERT_GL_NO_ERROR();
3093 }
3094
3095 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3096 {
3097 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003098 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003099
3100 setUpProgram();
3101
3102 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3103 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3104
3105 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3106 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3107 0);
3108
3109 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003110 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003111
3112 EXPECT_GL_NO_ERROR();
3113
3114 drawQuad(mProgram, "position", 0.5f);
3115
Geoff Langf607c602016-09-21 11:46:48 -04003116 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
3117 EXPECT_PIXEL_COLOR_EQ(
3118 0, 0, SliceFormatColor(
3119 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003120
3121 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3122 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3123 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3124 mRenderbuffer);
3125 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3126 EXPECT_GL_NO_ERROR();
3127
3128 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3129 glClear(GL_COLOR_BUFFER_BIT);
3130
3131 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3132
Geoff Langf607c602016-09-21 11:46:48 -04003133 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003134
3135 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3136
3137 ASSERT_GL_NO_ERROR();
3138 }
3139
3140 GLuint mTextures[3];
3141 GLuint mFBO;
3142 GLuint mRenderbuffer;
3143};
3144
3145// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3146TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3147{
Yunchao He9550c602018-02-13 14:47:05 +08003148 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02003149
3150 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3151 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3152 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3153 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3154 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3155 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3156 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3157 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3158
3159 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3160 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3161 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3162}
3163
Olli Etuaho95faa232016-06-07 14:01:53 -07003164// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3165// GLES 3.0.4 section 3.8.3.
3166TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3167{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08003168 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
3169
Yuly Novikov3c754192016-06-27 19:36:41 -04003170 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1429 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08003171 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07003172
3173 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3174 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3175 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3176 ASSERT_GL_NO_ERROR();
3177
3178 // SKIP_IMAGES should not have an effect on uploading 2D textures
3179 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3180 ASSERT_GL_NO_ERROR();
3181
3182 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3183
3184 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3185 pixelsGreen.data());
3186 ASSERT_GL_NO_ERROR();
3187
3188 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3189 pixelsGreen.data());
3190 ASSERT_GL_NO_ERROR();
3191
3192 glUseProgram(mProgram);
3193 drawQuad(mProgram, "position", 0.5f);
3194 ASSERT_GL_NO_ERROR();
3195
3196 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3197}
3198
Olli Etuaho989cac32016-06-08 16:18:49 -07003199// Test that skip defined in unpack parameters is taken into account when determining whether
3200// unpacking source extends outside unpack buffer bounds.
3201TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3202{
3203 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3204 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3205 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3206 ASSERT_GL_NO_ERROR();
3207
3208 GLBuffer buf;
3209 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3210 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3211 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3212 GL_DYNAMIC_COPY);
3213 ASSERT_GL_NO_ERROR();
3214
3215 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3216 ASSERT_GL_NO_ERROR();
3217
3218 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3219 ASSERT_GL_NO_ERROR();
3220
3221 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3222 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3223
3224 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3225 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3226 ASSERT_GL_NO_ERROR();
3227
3228 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3229 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3230}
3231
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003232// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3233TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3234{
Yunchao He9550c602018-02-13 14:47:05 +08003235 ANGLE_SKIP_TEST_IF(IsD3D11());
3236
3237 // Incorrect rendering results seen on OSX AMD.
3238 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003239
3240 const GLuint width = 8u;
3241 const GLuint height = 8u;
3242 const GLuint unpackRowLength = 5u;
3243 const GLuint unpackSkipPixels = 1u;
3244
3245 setWindowWidth(width);
3246 setWindowHeight(height);
3247
3248 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3249 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3250 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3251 ASSERT_GL_NO_ERROR();
3252
3253 GLBuffer buf;
3254 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3255 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3256 GLColor::green);
3257
3258 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3259 {
3260 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3261 }
3262
3263 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3264 GL_DYNAMIC_COPY);
3265 ASSERT_GL_NO_ERROR();
3266
3267 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3268 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3269 ASSERT_GL_NO_ERROR();
3270
3271 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3272 ASSERT_GL_NO_ERROR();
3273
3274 glUseProgram(mProgram);
3275 drawQuad(mProgram, "position", 0.5f);
3276 ASSERT_GL_NO_ERROR();
3277
3278 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3279 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3280 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3281 actual.data());
3282 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3283 EXPECT_EQ(expected, actual);
3284}
3285
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003286template <typename T>
3287T UNorm(double value)
3288{
3289 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3290}
3291
3292// Test rendering a depth texture with mipmaps.
3293TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3294{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003295 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3296 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
3297 // http://anglebugs.com/1706
Yunchao He9550c602018-02-13 14:47:05 +08003298 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows());
Corentin Walleze731d8a2016-09-07 10:56:25 -04003299
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003300 const int size = getWindowWidth();
3301
3302 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003303 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003304
3305 glActiveTexture(GL_TEXTURE0);
3306 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3307 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3308 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3309 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3310 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3311 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3312 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3313 ASSERT_GL_NO_ERROR();
3314
3315 glUseProgram(mProgram);
3316 glUniform1i(mTexture2DUniformLocation, 0);
3317
3318 std::vector<unsigned char> expected;
3319
3320 for (int level = 0; level < levels; ++level)
3321 {
3322 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3323 expected.push_back(UNorm<unsigned char>(value));
3324
3325 int levelDim = dim(level);
3326
3327 ASSERT_GT(levelDim, 0);
3328
3329 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3330 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3331 GL_UNSIGNED_INT, initData.data());
3332 }
3333 ASSERT_GL_NO_ERROR();
3334
3335 for (int level = 0; level < levels; ++level)
3336 {
3337 glViewport(0, 0, dim(level), dim(level));
3338 drawQuad(mProgram, "position", 0.5f);
3339 GLColor actual = ReadColor(0, 0);
3340 EXPECT_NEAR(expected[level], actual.R, 10u);
3341 }
3342
3343 ASSERT_GL_NO_ERROR();
3344}
3345
Jamie Madill7ffdda92016-09-08 13:26:51 -04003346// Tests unpacking into the unsized GL_ALPHA format.
3347TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3348{
Jamie Madill7ffdda92016-09-08 13:26:51 -04003349 // Initialize the texure.
3350 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3351 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3352 GL_UNSIGNED_BYTE, nullptr);
3353 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3354 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3355
3356 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3357
3358 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04003359 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04003360 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3361 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3362 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
3363 GL_STATIC_DRAW);
3364
3365 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
3366 GL_UNSIGNED_BYTE, nullptr);
3367
3368 // Clear to a weird color to make sure we're drawing something.
3369 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
3370 glClear(GL_COLOR_BUFFER_BIT);
3371
3372 // Draw with the alpha texture and verify.
3373 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04003374
3375 ASSERT_GL_NO_ERROR();
3376 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
3377}
3378
Jamie Madill2e600342016-09-19 13:56:40 -04003379// Ensure stale unpack data doesn't propagate in D3D11.
3380TEST_P(Texture2DTestES3, StaleUnpackData)
3381{
3382 // Init unpack buffer.
3383 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
3384 std::vector<GLColor> pixels(pixelCount, GLColor::red);
3385
3386 GLBuffer unpackBuffer;
3387 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3388 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3389 GLsizei bufferSize = pixelCount * sizeof(GLColor);
3390 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
3391
3392 // Create from unpack buffer.
3393 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3394 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
3395 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3396 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3397 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3398
3399 drawQuad(mProgram, "position", 0.5f);
3400
3401 ASSERT_GL_NO_ERROR();
3402 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3403
3404 // Fill unpack with green, recreating buffer.
3405 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
3406 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
3407 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
3408
3409 // Reinit texture with green.
3410 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
3411 GL_UNSIGNED_BYTE, nullptr);
3412
3413 drawQuad(mProgram, "position", 0.5f);
3414
3415 ASSERT_GL_NO_ERROR();
3416 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3417}
3418
Geoff Langfb7685f2017-11-13 11:44:11 -05003419// Ensure that texture parameters passed as floats that are converted to ints are rounded before
3420// validating they are less than 0.
3421TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
3422{
3423 GLTexture texture;
3424 glBindTexture(GL_TEXTURE_2D, texture);
3425
3426 // Use a negative number that will round to zero when converted to an integer
3427 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
3428 // "Validation of values performed by state-setting commands is performed after conversion,
3429 // unless specified otherwise for a specific command."
3430 GLfloat param = -7.30157126e-07f;
3431 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
3432 EXPECT_GL_NO_ERROR();
3433
3434 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
3435 EXPECT_GL_NO_ERROR();
3436}
3437
Jamie Madillf097e232016-11-05 00:44:15 -04003438// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
3439// being properly checked, and the texture storage of the previous texture format was persisting.
3440// This would result in an ASSERT in debug and incorrect rendering in release.
3441// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
3442TEST_P(Texture3DTestES3, FormatRedefinitionBug)
3443{
3444 GLTexture tex;
3445 glBindTexture(GL_TEXTURE_3D, tex.get());
3446 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3447
3448 GLFramebuffer framebuffer;
3449 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3450 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
3451
3452 glCheckFramebufferStatus(GL_FRAMEBUFFER);
3453
3454 std::vector<uint8_t> pixelData(100, 0);
3455
3456 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
3457 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
3458 pixelData.data());
3459
3460 ASSERT_GL_NO_ERROR();
3461}
3462
Corentin Wallezd2627992017-04-28 17:17:03 -04003463// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
3464TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
3465{
3466 // 2D tests
3467 {
3468 GLTexture tex;
3469 glBindTexture(GL_TEXTURE_2D, tex.get());
3470
3471 GLBuffer pbo;
3472 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3473
3474 // Test OOB
3475 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
3476 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3477 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3478
3479 // Test OOB
3480 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
3481 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3482 ASSERT_GL_NO_ERROR();
3483 }
3484
3485 // 3D tests
3486 {
3487 GLTexture tex;
3488 glBindTexture(GL_TEXTURE_3D, tex.get());
3489
3490 GLBuffer pbo;
3491 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3492
3493 // Test OOB
3494 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
3495 GL_STATIC_DRAW);
3496 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3497 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3498
3499 // Test OOB
3500 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
3501 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3502 ASSERT_GL_NO_ERROR();
3503 }
3504}
3505
Jamie Madill3ed60422017-09-07 11:32:52 -04003506// Tests behaviour with a single texture and multiple sampler objects.
3507TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
3508{
3509 GLint maxTextureUnits = 0;
3510 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
3511 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
3512
3513 constexpr int kSize = 16;
3514
3515 // Make a single-level texture, fill it with red.
3516 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
3517 GLTexture tex;
3518 glBindTexture(GL_TEXTURE_2D, tex);
3519 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3520 redColors.data());
3521 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3522 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3523
3524 // Simple sanity check.
3525 draw2DTexturedQuad(0.5f, 1.0f, true);
3526 ASSERT_GL_NO_ERROR();
3527 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3528
3529 // Bind texture to unit 1 with a sampler object making it incomplete.
3530 GLSampler sampler;
3531 glBindSampler(0, sampler);
3532 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3533 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3534
3535 // Make a mipmap texture, fill it with blue.
3536 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
3537 GLTexture mipmapTex;
3538 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3539 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3540 blueColors.data());
3541 glGenerateMipmap(GL_TEXTURE_2D);
3542
3543 // Draw with the sampler, expect blue.
3544 draw2DTexturedQuad(0.5f, 1.0f, true);
3545 ASSERT_GL_NO_ERROR();
3546 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
3547
3548 // Simple multitexturing program.
3549 const std::string vs =
3550 "#version 300 es\n"
3551 "in vec2 position;\n"
3552 "out vec2 texCoord;\n"
3553 "void main()\n"
3554 "{\n"
3555 " gl_Position = vec4(position, 0, 1);\n"
3556 " texCoord = position * 0.5 + vec2(0.5);\n"
3557 "}";
3558 const std::string fs =
3559 "#version 300 es\n"
3560 "precision mediump float;\n"
3561 "in vec2 texCoord;\n"
3562 "uniform sampler2D tex1;\n"
3563 "uniform sampler2D tex2;\n"
3564 "uniform sampler2D tex3;\n"
3565 "uniform sampler2D tex4;\n"
3566 "out vec4 color;\n"
3567 "void main()\n"
3568 "{\n"
3569 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
3570 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
3571 "}";
3572
3573 ANGLE_GL_PROGRAM(program, vs, fs);
3574
3575 std::array<GLint, 4> texLocations = {
3576 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
3577 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
3578 for (GLint location : texLocations)
3579 {
3580 ASSERT_NE(-1, location);
3581 }
3582
3583 // Init the uniform data.
3584 glUseProgram(program);
3585 for (GLint location = 0; location < 4; ++location)
3586 {
3587 glUniform1i(texLocations[location], location);
3588 }
3589
3590 // Initialize four samplers
3591 GLSampler samplers[4];
3592
3593 // 0: non-mipped.
3594 glBindSampler(0, samplers[0]);
3595 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3596 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3597
3598 // 1: mipped.
3599 glBindSampler(1, samplers[1]);
3600 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3601 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3602
3603 // 2: non-mipped.
3604 glBindSampler(2, samplers[2]);
3605 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3606 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3607
3608 // 3: mipped.
3609 glBindSampler(3, samplers[3]);
3610 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3611 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3612
3613 // Bind two blue mipped textures and two single layer textures, should all draw.
3614 glActiveTexture(GL_TEXTURE0);
3615 glBindTexture(GL_TEXTURE_2D, tex);
3616
3617 glActiveTexture(GL_TEXTURE1);
3618 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3619
3620 glActiveTexture(GL_TEXTURE2);
3621 glBindTexture(GL_TEXTURE_2D, tex);
3622
3623 glActiveTexture(GL_TEXTURE3);
3624 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3625
3626 ASSERT_GL_NO_ERROR();
3627
3628 drawQuad(program, "position", 0.5f);
3629 ASSERT_GL_NO_ERROR();
3630 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
3631
3632 // Bind four single layer textures, two should be incomplete.
3633 glActiveTexture(GL_TEXTURE1);
3634 glBindTexture(GL_TEXTURE_2D, tex);
3635
3636 glActiveTexture(GL_TEXTURE3);
3637 glBindTexture(GL_TEXTURE_2D, tex);
3638
3639 drawQuad(program, "position", 0.5f);
3640 ASSERT_GL_NO_ERROR();
3641 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
3642}
3643
Martin Radev7e2c0d32017-09-15 14:25:42 +03003644// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
3645// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
3646// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
3647// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
3648// samples the cubemap using a direction vector (1,1,1).
3649TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
3650{
Yunchao He2f23f352018-02-11 22:11:37 +08003651 // Check http://anglebug.com/2155.
3652 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
3653
Martin Radev7e2c0d32017-09-15 14:25:42 +03003654 const std::string vs =
3655 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003656 precision mediump float;
3657 in vec3 pos;
3658 void main() {
3659 gl_Position = vec4(pos, 1.0);
3660 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003661
3662 const std::string fs =
3663 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003664 precision mediump float;
3665 out vec4 color;
3666 uniform samplerCube uTex;
3667 void main(){
3668 color = texture(uTex, vec3(1.0));
3669 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003670 ANGLE_GL_PROGRAM(program, vs, fs);
3671 glUseProgram(program);
3672
3673 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
3674 glActiveTexture(GL_TEXTURE0);
3675
3676 GLTexture cubeTex;
3677 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
3678
3679 const int kFaceWidth = 1;
3680 const int kFaceHeight = 1;
3681 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
3682 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3683 GL_UNSIGNED_BYTE, texData.data());
3684 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3685 GL_UNSIGNED_BYTE, texData.data());
3686 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3687 GL_UNSIGNED_BYTE, texData.data());
3688 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3689 GL_UNSIGNED_BYTE, texData.data());
3690 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3691 GL_UNSIGNED_BYTE, texData.data());
3692 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3693 GL_UNSIGNED_BYTE, texData.data());
3694 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3695 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3696 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
3697 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
3698 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
3699 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
3700
3701 drawQuad(program, "pos", 0.5f, 1.0f, true);
3702 ASSERT_GL_NO_ERROR();
3703
3704 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
3705}
3706
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08003707// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
3708TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
3709{
3710 GLuint texture = create2DTexture();
3711
3712 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
3713 EXPECT_GL_ERROR(GL_INVALID_VALUE);
3714
3715 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
3716 EXPECT_GL_ERROR(GL_INVALID_VALUE);
3717
3718 glDeleteTextures(1, &texture);
3719 EXPECT_GL_NO_ERROR();
3720}
3721
Olli Etuaho023371b2018-04-24 17:43:32 +03003722// Test setting base level after calling generateMipmap on a LUMA texture.
3723// Covers http://anglebug.com/2498
3724TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA)
3725{
3726 glActiveTexture(GL_TEXTURE0);
3727 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3728
3729 constexpr const GLsizei kWidth = 8;
3730 constexpr const GLsizei kHeight = 8;
3731 std::array<GLubyte, kWidth * kHeight * 2> whiteData;
3732 whiteData.fill(255u);
3733
3734 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA,
3735 GL_UNSIGNED_BYTE, whiteData.data());
3736 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
3737 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3738 glGenerateMipmap(GL_TEXTURE_2D);
3739 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
3740 EXPECT_GL_NO_ERROR();
3741
3742 drawQuad(mProgram, "position", 0.5f);
3743 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
3744}
3745
Jamie Madillfa05f602015-05-07 13:47:11 -04003746// 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 -05003747ANGLE_INSTANTIATE_TEST(Texture2DTest,
3748 ES2_D3D9(),
3749 ES2_D3D11(),
3750 ES2_D3D11_FL9_3(),
3751 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05003752 ES2_OPENGLES(),
3753 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003754ANGLE_INSTANTIATE_TEST(TextureCubeTest,
3755 ES2_D3D9(),
3756 ES2_D3D11(),
Geoff Langf7480ad2017-10-24 11:46:02 -04003757 ES2_D3D11_FL10_0(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003758 ES2_D3D11_FL9_3(),
3759 ES2_OPENGL(),
3760 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003761ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
3762 ES2_D3D9(),
3763 ES2_D3D11(),
3764 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003765 ES2_OPENGL(),
3766 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003767ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
3768 ES2_D3D9(),
3769 ES2_D3D11(),
3770 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003771 ES2_OPENGL(),
3772 ES2_OPENGLES());
3773ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
3774 ES2_D3D9(),
3775 ES2_D3D11(),
3776 ES2_D3D11_FL9_3(),
3777 ES2_OPENGL(),
3778 ES2_OPENGLES());
3779ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
3780 ES2_D3D9(),
3781 ES2_D3D11(),
3782 ES2_D3D11_FL9_3(),
3783 ES2_OPENGL(),
3784 ES2_OPENGLES());
3785ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02003786ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003787ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3788ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
3789 ES3_D3D11(),
3790 ES3_OPENGL(),
3791 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003792ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
3793 ES3_D3D11(),
3794 ES3_OPENGL(),
3795 ES3_OPENGLES());
3796ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3797ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02003798ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02003799ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
3800 ES2_D3D11(),
3801 ES2_D3D11_FL9_3(),
3802 ES2_D3D9(),
3803 ES2_OPENGL(),
3804 ES2_OPENGLES());
3805ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
3806 ES2_D3D11(),
3807 ES2_D3D11_FL9_3(),
3808 ES2_D3D9(),
3809 ES2_OPENGL(),
3810 ES2_OPENGLES());
3811ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
3812 ES2_D3D11(),
3813 ES2_D3D11_FL9_3(),
3814 ES2_D3D9(),
3815 ES2_OPENGL(),
3816 ES2_OPENGLES());
3817ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
3818 ES2_D3D11(),
3819 ES2_D3D11_FL9_3(),
3820 ES2_D3D9(),
3821 ES2_OPENGL(),
3822 ES2_OPENGLES());
3823ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
3824 ES2_D3D11(),
3825 ES2_D3D11_FL9_3(),
3826 ES2_D3D9(),
3827 ES2_OPENGL(),
3828 ES2_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003829ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES());
Vincent Lang25ab4512016-05-13 18:13:59 +02003830ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03003831ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04003832
Jamie Madill7ffdda92016-09-08 13:26:51 -04003833} // anonymous namespace