blob: 08730db1fba7c30395cdc523f92b4f78fc043058 [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{
Yunchao He9550c602018-02-13 14:47:05 +08001401 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{
Yunchao He9550c602018-02-13 14:47:05 +08001561 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1562 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001563
Jamie Madillbc393df2015-01-29 13:46:07 -05001564 testFloatCopySubImage(4, 4);
1565}
Austin Kinross07285142015-03-26 11:36:16 -07001566
1567// Port of https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1568// 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 +02001569TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001570{
Luc Ferron5164b792018-03-06 09:10:12 -05001571 // TODO(lucferron): DIRTY_BIT_UNPACK_STATE isn't implemented on Vulkan yet.
1572 ANGLE_SKIP_TEST_IF(IsVulkan());
1573
Austin Kinross07285142015-03-26 11:36:16 -07001574 const int npotTexSize = 5;
1575 const int potTexSize = 4; // Should be less than npotTexSize
1576 GLuint tex2D;
1577
1578 if (extensionEnabled("GL_OES_texture_npot"))
1579 {
1580 // This test isn't applicable if texture_npot is enabled
1581 return;
1582 }
1583
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001584 setUpProgram();
1585
Austin Kinross07285142015-03-26 11:36:16 -07001586 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1587
Austin Kinross5faa15b2016-01-11 13:32:48 -08001588 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1589 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1590
Austin Kinross07285142015-03-26 11:36:16 -07001591 glActiveTexture(GL_TEXTURE0);
1592 glGenTextures(1, &tex2D);
1593 glBindTexture(GL_TEXTURE_2D, tex2D);
1594
1595 std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize);
1596 for (size_t pixelId = 0; pixelId < npotTexSize * npotTexSize; ++pixelId)
1597 {
1598 pixels[pixelId] = 64;
1599 }
1600
1601 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1602 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1603
1604 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
1605 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1606 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1607
1608 // Check that an NPOT texture on level 0 succeeds
1609 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1610 EXPECT_GL_NO_ERROR();
1611
1612 // Check that generateMipmap fails on NPOT
1613 glGenerateMipmap(GL_TEXTURE_2D);
1614 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1615
1616 // Check that nothing is drawn if filtering is not correct for NPOT
1617 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1618 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1619 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1620 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1621 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001622 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001623 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1624
1625 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1626 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1627 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1628 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1629 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001630 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001631 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1632
1633 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1634 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1635 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001636 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001637 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1638
1639 // Check that glTexImage2D for POT texture succeeds
1640 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1641 EXPECT_GL_NO_ERROR();
1642
1643 // Check that generateMipmap for an POT texture succeeds
1644 glGenerateMipmap(GL_TEXTURE_2D);
1645 EXPECT_GL_NO_ERROR();
1646
1647 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1648 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1649 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1650 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1651 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1652 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001653 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001654 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1655 EXPECT_GL_NO_ERROR();
1656}
Jamie Madillfa05f602015-05-07 13:47:11 -04001657
Austin Kinross08528e12015-10-07 16:24:40 -07001658// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1659// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001660TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001661{
Luc Ferron5164b792018-03-06 09:10:12 -05001662 // TODO(lucferron): Generate mipmap on vulkan isn't implemented yet. Re-enable this when it
1663 // is.
1664 ANGLE_SKIP_TEST_IF(IsVulkan());
1665
Austin Kinross08528e12015-10-07 16:24:40 -07001666 glActiveTexture(GL_TEXTURE0);
1667 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1668
1669 // Create an 8x8 (i.e. power-of-two) texture.
1670 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1671 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1672 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1673 glGenerateMipmap(GL_TEXTURE_2D);
1674
1675 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1676 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001677 std::array<GLColor, 3 * 3> data;
1678 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001679
1680 EXPECT_GL_NO_ERROR();
1681}
1682
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001683// Test to check that texture completeness is determined correctly when the texture base level is
1684// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1685TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1686{
1687 glActiveTexture(GL_TEXTURE0);
1688 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001689
1690 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1691 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1692 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1693 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1694 texDataGreen.data());
1695 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1696 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001697 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1698 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1699 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1700
1701 EXPECT_GL_NO_ERROR();
1702
1703 drawQuad(mProgram, "position", 0.5f);
1704
Olli Etuahoa314b612016-03-10 16:43:00 +02001705 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1706}
1707
1708// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1709// have images defined.
1710TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1711{
Yunchao He9550c602018-02-13 14:47:05 +08001712 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1713 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1714
Olli Etuahoa314b612016-03-10 16:43:00 +02001715 glActiveTexture(GL_TEXTURE0);
1716 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1717 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1718 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1719 texDataGreen.data());
1720 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1721 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1722 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1723 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1724
1725 EXPECT_GL_NO_ERROR();
1726
1727 drawQuad(mProgram, "position", 0.5f);
1728
1729 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1730}
1731
Olli Etuahoe8528d82016-05-16 17:50:52 +03001732// Test that drawing works correctly when level 0 is undefined and base level is 1.
1733TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1734{
Yunchao He9550c602018-02-13 14:47:05 +08001735 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1736 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1737
Olli Etuahoe8528d82016-05-16 17:50:52 +03001738 glActiveTexture(GL_TEXTURE0);
1739 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1740 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1741 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1742 texDataGreen.data());
1743 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1744 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1745 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1746 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1747
1748 EXPECT_GL_NO_ERROR();
1749
1750 // Texture is incomplete.
1751 drawQuad(mProgram, "position", 0.5f);
1752 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1753
1754 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1755 texDataGreen.data());
1756
1757 // Texture is now complete.
1758 drawQuad(mProgram, "position", 0.5f);
1759 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1760}
1761
Olli Etuahoa314b612016-03-10 16:43:00 +02001762// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1763// dimensions that don't fit the images inside the range.
1764// GLES 3.0.4 section 3.8.13 Texture completeness
1765TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1766{
Olli Etuahoa314b612016-03-10 16:43:00 +02001767 glActiveTexture(GL_TEXTURE0);
1768 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1769 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1770 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1771 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1772
1773 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1774 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1775
1776 // Two levels that are initially unused.
1777 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1778 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1779 texDataCyan.data());
1780
1781 // One level that is used - only this level should affect completeness.
1782 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1783 texDataGreen.data());
1784
1785 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1786 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1787
1788 EXPECT_GL_NO_ERROR();
1789
1790 drawQuad(mProgram, "position", 0.5f);
1791
1792 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1793
Yunchao He2f23f352018-02-11 22:11:37 +08001794 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001795
1796 // Switch the level that is being used to the cyan level 2.
1797 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1798 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1799
1800 EXPECT_GL_NO_ERROR();
1801
1802 drawQuad(mProgram, "position", 0.5f);
1803
1804 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1805}
1806
1807// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1808// have images defined.
1809TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1810{
Olli Etuahoa314b612016-03-10 16:43:00 +02001811 glActiveTexture(GL_TEXTURE0);
1812 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1813 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1814 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1815 texDataGreen.data());
1816 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1817 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1818 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1819 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1820
1821 EXPECT_GL_NO_ERROR();
1822
1823 drawQuad(mProgram, "position", 0.5f);
1824
1825 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1826}
1827
1828// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1829// dimensions that don't fit the images inside the range.
1830// GLES 3.0.4 section 3.8.13 Texture completeness
1831TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1832{
Olli Etuahoa314b612016-03-10 16:43:00 +02001833 glActiveTexture(GL_TEXTURE0);
1834 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1835 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1836 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1837 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1838
1839 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1840 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1841
1842 // Two levels that are initially unused.
1843 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1844 texDataRed.data());
1845 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1846 texDataCyan.data());
1847
1848 // One level that is used - only this level should affect completeness.
1849 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1850 texDataGreen.data());
1851
1852 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1853 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1854
1855 EXPECT_GL_NO_ERROR();
1856
1857 drawQuad(mProgram, "position", 0.5f);
1858
1859 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1860
Yunchao He2f23f352018-02-11 22:11:37 +08001861 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001862
1863 // Switch the level that is being used to the cyan level 2.
1864 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
1865 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
1866
1867 EXPECT_GL_NO_ERROR();
1868
1869 drawQuad(mProgram, "position", 0.5f);
1870
1871 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1872}
1873
1874// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1875// have images defined.
1876TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
1877{
Olli Etuahoa314b612016-03-10 16:43:00 +02001878 glActiveTexture(GL_TEXTURE0);
1879 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
1880 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1881 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1882 texDataGreen.data());
1883 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1884 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1885 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1886 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1887
1888 EXPECT_GL_NO_ERROR();
1889
1890 drawQuad(mProgram, "position", 0.5f);
1891
1892 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1893}
1894
1895// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1896// dimensions that don't fit the images inside the range.
1897// GLES 3.0.4 section 3.8.13 Texture completeness
1898TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1899{
Olli Etuahoa314b612016-03-10 16:43:00 +02001900 glActiveTexture(GL_TEXTURE0);
1901 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
1902 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1903 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1904 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1905
1906 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1907 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1908
1909 // Two levels that are initially unused.
1910 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1911 texDataRed.data());
1912 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1913 texDataCyan.data());
1914
1915 // One level that is used - only this level should affect completeness.
1916 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1917 texDataGreen.data());
1918
1919 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1920 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1921
1922 EXPECT_GL_NO_ERROR();
1923
1924 drawQuad(mProgram, "position", 0.5f);
1925
1926 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1927
Yunchao He2f23f352018-02-11 22:11:37 +08001928 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
1929
Yunchao He9550c602018-02-13 14:47:05 +08001930 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
1931 // level was changed.
1932 ANGLE_SKIP_TEST_IF(IsNVIDIA() && (IsOpenGL() || IsOpenGLES()));
Olli Etuahoa314b612016-03-10 16:43:00 +02001933
1934 // Switch the level that is being used to the cyan level 2.
1935 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
1936 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
1937
1938 EXPECT_GL_NO_ERROR();
1939
1940 drawQuad(mProgram, "position", 0.5f);
1941
1942 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1943}
1944
1945// Test that texture completeness is updated if texture max level changes.
1946// GLES 3.0.4 section 3.8.13 Texture completeness
1947TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
1948{
Olli Etuahoa314b612016-03-10 16:43:00 +02001949 glActiveTexture(GL_TEXTURE0);
1950 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1951 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
1952
1953 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1954 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1955
1956 // A level that is initially unused.
1957 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1958 texDataGreen.data());
1959
1960 // One level that is initially used - only this level should affect completeness.
1961 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1962 texDataGreen.data());
1963
1964 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
1965 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
1966
1967 EXPECT_GL_NO_ERROR();
1968
1969 drawQuad(mProgram, "position", 0.5f);
1970
1971 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1972
1973 // Switch the max level to level 1. The levels within the used range now have inconsistent
1974 // dimensions and the texture should be incomplete.
1975 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1976
1977 EXPECT_GL_NO_ERROR();
1978
1979 drawQuad(mProgram, "position", 0.5f);
1980
1981 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1982}
1983
1984// Test that 3D texture completeness is updated if texture max level changes.
1985// GLES 3.0.4 section 3.8.13 Texture completeness
1986TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
1987{
Olli Etuahoa314b612016-03-10 16:43:00 +02001988 glActiveTexture(GL_TEXTURE0);
1989 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1990 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1991
1992 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1993 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1994
1995 // A level that is initially unused.
1996 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1997 texDataGreen.data());
1998
1999 // One level that is initially used - only this level should affect completeness.
2000 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2001 texDataGreen.data());
2002
2003 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2004 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2005
2006 EXPECT_GL_NO_ERROR();
2007
2008 drawQuad(mProgram, "position", 0.5f);
2009
2010 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2011
2012 // Switch the max level to level 1. The levels within the used range now have inconsistent
2013 // dimensions and the texture should be incomplete.
2014 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2015
2016 EXPECT_GL_NO_ERROR();
2017
2018 drawQuad(mProgram, "position", 0.5f);
2019
2020 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2021}
2022
2023// Test that texture completeness is updated if texture base level changes.
2024// GLES 3.0.4 section 3.8.13 Texture completeness
2025TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2026{
Olli Etuahoa314b612016-03-10 16:43:00 +02002027 glActiveTexture(GL_TEXTURE0);
2028 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2029 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2030
2031 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2032 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2033
2034 // Two levels that are initially unused.
2035 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2036 texDataGreen.data());
2037 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2038 texDataGreen.data());
2039
2040 // One level that is initially used - only this level should affect completeness.
2041 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2042 texDataGreen.data());
2043
2044 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2045 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2046
2047 EXPECT_GL_NO_ERROR();
2048
2049 drawQuad(mProgram, "position", 0.5f);
2050
2051 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2052
2053 // Switch the base level to level 1. The levels within the used range now have inconsistent
2054 // dimensions and the texture should be incomplete.
2055 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2056
2057 EXPECT_GL_NO_ERROR();
2058
2059 drawQuad(mProgram, "position", 0.5f);
2060
2061 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2062}
2063
2064// Test that texture is not complete if base level is greater than max level.
2065// GLES 3.0.4 section 3.8.13 Texture completeness
2066TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2067{
Olli Etuahoa314b612016-03-10 16:43:00 +02002068 glActiveTexture(GL_TEXTURE0);
2069 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2070
2071 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2072 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2073
2074 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2075
2076 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2077 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2078
2079 EXPECT_GL_NO_ERROR();
2080
2081 drawQuad(mProgram, "position", 0.5f);
2082
2083 // Texture should be incomplete.
2084 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2085}
2086
2087// Test that immutable texture base level and max level are clamped.
2088// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2089TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2090{
Olli Etuahoa314b612016-03-10 16:43:00 +02002091 glActiveTexture(GL_TEXTURE0);
2092 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2093
2094 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2095 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2096
2097 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2098
2099 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2100
2101 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2102 // should be clamped to [base_level, levels - 1].
2103 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2104 // In the case of this test, those rules make the effective base level and max level 0.
2105 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2106 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2107
2108 EXPECT_GL_NO_ERROR();
2109
2110 drawQuad(mProgram, "position", 0.5f);
2111
2112 // Texture should be complete.
2113 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2114}
2115
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002116// Test that changing base level works when it affects the format of the texture.
2117TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2118{
Yunchao He9550c602018-02-13 14:47:05 +08002119 // Observed rendering corruption on NVIDIA OpenGL.
2120 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL());
2121
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002122 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002123
2124 // Observed incorrect rendering on AMD OpenGL.
2125 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002126
2127 glActiveTexture(GL_TEXTURE0);
2128 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2129 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2130 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2131
2132 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2133 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2134
2135 // RGBA8 level that's initially unused.
2136 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2137 texDataCyan.data());
2138
2139 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2140 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2141
2142 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2143 // format. It reads green channel data from the green and alpha channels of texDataGreen
2144 // (this is a bit hacky but works).
2145 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2146
2147 EXPECT_GL_NO_ERROR();
2148
2149 drawQuad(mProgram, "position", 0.5f);
2150
2151 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2152
2153 // Switch the texture to use the cyan level 0 with the RGBA format.
2154 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2155 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2156
2157 EXPECT_GL_NO_ERROR();
2158
2159 drawQuad(mProgram, "position", 0.5f);
2160
2161 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2162}
2163
Olli Etuahoa314b612016-03-10 16:43:00 +02002164// Test that setting a texture image works when base level is out of range.
2165TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2166{
2167 glActiveTexture(GL_TEXTURE0);
2168 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2169
2170 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2171 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2172
2173 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2174 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2175
2176 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2177
2178 EXPECT_GL_NO_ERROR();
2179
2180 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2181
2182 drawQuad(mProgram, "position", 0.5f);
2183
2184 // Texture should be complete.
2185 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002186}
2187
Jamie Madill2453dbc2015-07-14 11:35:42 -04002188// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG RBA->RGBA8, with 1.0
2189// in the alpha channel. This test covers a bug where redefining array textures with these formats does not work as
2190// expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002191TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002192{
2193 std::vector<GLubyte> pixelData;
2194 for (size_t count = 0; count < 5000; count++)
2195 {
2196 pixelData.push_back(0u);
2197 pixelData.push_back(255u);
2198 pixelData.push_back(0u);
2199 }
2200
2201 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002202 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002203 glUniform1i(mTextureArrayLocation, 0);
2204
2205 // The first draw worked correctly.
2206 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
2207
2208 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2209 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2210 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2211 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002212 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002213 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002214
2215 // The dimension of the respecification must match the original exactly to trigger the bug.
2216 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 +02002217 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002218 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002219
2220 ASSERT_GL_NO_ERROR();
2221}
2222
Olli Etuaho1a679902016-01-14 12:21:47 +02002223// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2224// This test is needed especially to confirm that sampler registers get assigned correctly on
2225// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2226TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2227{
2228 glActiveTexture(GL_TEXTURE0);
2229 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2230 GLubyte texData[4];
2231 texData[0] = 0;
2232 texData[1] = 60;
2233 texData[2] = 0;
2234 texData[3] = 255;
2235 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2236
2237 glActiveTexture(GL_TEXTURE1);
2238 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2239 GLfloat depthTexData[1];
2240 depthTexData[0] = 0.5f;
2241 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2242 depthTexData);
2243
2244 glUseProgram(mProgram);
2245 glUniform1f(mDepthRefUniformLocation, 0.3f);
2246 glUniform1i(mTexture3DUniformLocation, 0);
2247 glUniform1i(mTextureShadowUniformLocation, 1);
2248
2249 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2250 drawQuad(mProgram, "position", 0.5f);
2251 EXPECT_GL_NO_ERROR();
2252 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2253 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2254
2255 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2256 drawQuad(mProgram, "position", 0.5f);
2257 EXPECT_GL_NO_ERROR();
2258 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2259 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2260}
2261
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002262// Test multiple different sampler types in the same shader.
2263// This test makes sure that even if sampler / texture registers get grouped together based on type
2264// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2265// still has the right register index information for each ESSL sampler.
2266// The tested ESSL samplers have the following types in D3D11 HLSL:
2267// sampler2D: Texture2D + SamplerState
2268// samplerCube: TextureCube + SamplerState
2269// sampler2DShadow: Texture2D + SamplerComparisonState
2270// samplerCubeShadow: TextureCube + SamplerComparisonState
2271TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2272{
2273 glActiveTexture(GL_TEXTURE0);
2274 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2275 GLubyte texData[4];
2276 texData[0] = 0;
2277 texData[1] = 0;
2278 texData[2] = 120;
2279 texData[3] = 255;
2280 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2281
2282 glActiveTexture(GL_TEXTURE1);
2283 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2284 texData[0] = 0;
2285 texData[1] = 90;
2286 texData[2] = 0;
2287 texData[3] = 255;
2288 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2289 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2290 texData);
2291
2292 glActiveTexture(GL_TEXTURE2);
2293 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2294 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2295 GLfloat depthTexData[1];
2296 depthTexData[0] = 0.5f;
2297 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2298 depthTexData);
2299
2300 glActiveTexture(GL_TEXTURE3);
2301 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2302 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2303 depthTexData[0] = 0.2f;
2304 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2305 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2306 depthTexData);
2307
2308 EXPECT_GL_NO_ERROR();
2309
2310 glUseProgram(mProgram);
2311 glUniform1f(mDepthRefUniformLocation, 0.3f);
2312 glUniform1i(mTexture2DUniformLocation, 0);
2313 glUniform1i(mTextureCubeUniformLocation, 1);
2314 glUniform1i(mTexture2DShadowUniformLocation, 2);
2315 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2316
2317 drawQuad(mProgram, "position", 0.5f);
2318 EXPECT_GL_NO_ERROR();
2319 // The shader writes:
2320 // <texture 2d color> +
2321 // <cube map color> +
2322 // 0.25 * <comparison result (1.0)> +
2323 // 0.125 * <comparison result (0.0)>
2324 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2325}
2326
Olli Etuahobce743a2016-01-15 17:18:28 +02002327// Test different base levels on textures accessed through the same sampler array.
2328// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2329TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2330{
Yunchao He9550c602018-02-13 14:47:05 +08002331 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2332
Olli Etuahobce743a2016-01-15 17:18:28 +02002333 glActiveTexture(GL_TEXTURE0);
2334 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2335 GLsizei size = 64;
2336 for (GLint level = 0; level < 7; ++level)
2337 {
2338 ASSERT_LT(0, size);
2339 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2340 nullptr);
2341 size = size / 2;
2342 }
2343 ASSERT_EQ(0, size);
2344 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2345
2346 glActiveTexture(GL_TEXTURE1);
2347 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2348 size = 128;
2349 for (GLint level = 0; level < 8; ++level)
2350 {
2351 ASSERT_LT(0, size);
2352 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2353 nullptr);
2354 size = size / 2;
2355 }
2356 ASSERT_EQ(0, size);
2357 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2358 EXPECT_GL_NO_ERROR();
2359
2360 glUseProgram(mProgram);
2361 glUniform1i(mTexture0Location, 0);
2362 glUniform1i(mTexture1Location, 1);
2363
Olli Etuaho5804dc82018-04-13 14:11:46 +03002364 drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
Olli Etuahobce743a2016-01-15 17:18:28 +02002365 EXPECT_GL_NO_ERROR();
2366 // Red channel: width of level 1 of texture A: 32.
2367 // Green channel: width of level 3 of texture B: 16.
2368 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2369}
2370
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002371// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2372// ES 3.0.4 table 3.24
2373TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2374{
2375 glActiveTexture(GL_TEXTURE0);
2376 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2377 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2378 EXPECT_GL_NO_ERROR();
2379
2380 drawQuad(mProgram, "position", 0.5f);
2381
2382 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2383}
2384
2385// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2386// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002387TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002388{
Luc Ferron5164b792018-03-06 09:10:12 -05002389 setUpProgram();
2390
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002391 glActiveTexture(GL_TEXTURE0);
2392 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2393 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2394 EXPECT_GL_NO_ERROR();
2395
2396 drawQuad(mProgram, "position", 0.5f);
2397
2398 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2399}
2400
Luc Ferron5164b792018-03-06 09:10:12 -05002401// Validate that every component of the pixel will be equal to the luminance value we've set
2402// and that the alpha channel will be 1 (or 255 to be exact).
2403TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2404{
2405 setUpProgram();
2406
2407 glActiveTexture(GL_TEXTURE0);
2408 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2409 uint8_t pixel = 50;
2410 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2411 EXPECT_GL_NO_ERROR();
2412
2413 drawQuad(mProgram, "position", 0.5f);
2414
2415 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2416}
2417
2418// Validate that every component of the pixel will be equal to the luminance value we've set
2419// and that the alpha channel will be the second component.
2420TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2421{
2422 setUpProgram();
2423
2424 glActiveTexture(GL_TEXTURE0);
2425 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2426 uint8_t pixel[] = {50, 25};
2427 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2428 GL_UNSIGNED_BYTE, pixel);
2429 EXPECT_GL_NO_ERROR();
2430
2431 drawQuad(mProgram, "position", 0.5f);
2432
2433 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2434}
2435
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002436// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2437// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002438TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002439{
Luc Ferrond8c632c2018-04-10 12:31:44 -04002440 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
2441 ANGLE_SKIP_TEST_IF(IsD3D9());
2442 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002443
2444 setUpProgram();
2445
Luc Ferrond8c632c2018-04-10 12:31:44 -04002446 glActiveTexture(GL_TEXTURE0);
2447 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2448 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2449 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002450
Luc Ferrond8c632c2018-04-10 12:31:44 -04002451 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002452
Luc Ferrond8c632c2018-04-10 12:31:44 -04002453 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002454}
2455
2456// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2457// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002458TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002459{
Luc Ferrond8c632c2018-04-10 12:31:44 -04002460 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
2461 ANGLE_SKIP_TEST_IF(IsD3D9());
2462 ANGLE_SKIP_TEST_IF(IsVulkan());
2463 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES());
2464 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2465 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002466
Luc Ferrond8c632c2018-04-10 12:31:44 -04002467 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002468
Luc Ferrond8c632c2018-04-10 12:31:44 -04002469 glActiveTexture(GL_TEXTURE0);
2470 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2471 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2472 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002473
Luc Ferrond8c632c2018-04-10 12:31:44 -04002474 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002475
Luc Ferrond8c632c2018-04-10 12:31:44 -04002476 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002477}
2478
2479// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2480// ES 3.0.4 table 3.24
2481TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2482{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002483 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2484
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002485 glActiveTexture(GL_TEXTURE0);
2486 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2487 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2488 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2489 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2490 EXPECT_GL_NO_ERROR();
2491
2492 drawQuad(mProgram, "position", 0.5f);
2493
2494 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2495}
2496
2497// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2498// ES 3.0.4 table 3.24
2499TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2500{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002501 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2502
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002503 glActiveTexture(GL_TEXTURE0);
2504 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2505
2506 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2507 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2508 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2509 EXPECT_GL_NO_ERROR();
2510
2511 drawQuad(mProgram, "position", 0.5f);
2512
2513 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2514}
2515
2516// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2517// ES 3.0.4 table 3.24
2518TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2519{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002520 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2521
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002522 glActiveTexture(GL_TEXTURE0);
2523 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2524 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2525 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2526 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2527 EXPECT_GL_NO_ERROR();
2528
2529 drawQuad(mProgram, "position", 0.5f);
2530
2531 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2532}
2533
2534// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2535// ES 3.0.4 table 3.24
2536TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2537{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002538 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2539
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002540 glActiveTexture(GL_TEXTURE0);
2541 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2542 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2543 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2544 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2545 EXPECT_GL_NO_ERROR();
2546
2547 drawQuad(mProgram, "position", 0.5f);
2548
2549 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2550}
2551
2552// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2553// ES 3.0.4 table 3.24
2554TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2555{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002556 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2557
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002558 glActiveTexture(GL_TEXTURE0);
2559 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2560 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2561 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2562 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2563 EXPECT_GL_NO_ERROR();
2564
2565 drawQuad(mProgram, "position", 0.5f);
2566
2567 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2568}
2569
2570// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2571// ES 3.0.4 table 3.24
2572TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2573{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002574 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2575
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002576 glActiveTexture(GL_TEXTURE0);
2577 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2578 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2579 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2580 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2581 EXPECT_GL_NO_ERROR();
2582
2583 drawQuad(mProgram, "position", 0.5f);
2584
2585 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2586}
2587
2588// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2589// ES 3.0.4 table 3.24
2590TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2591{
2592 glActiveTexture(GL_TEXTURE0);
2593 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2594 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2595 EXPECT_GL_NO_ERROR();
2596
2597 drawQuad(mProgram, "position", 0.5f);
2598
2599 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2600}
2601
2602// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2603// ES 3.0.4 table 3.24
2604TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2605{
2606 glActiveTexture(GL_TEXTURE0);
2607 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2608 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2609 nullptr);
2610 EXPECT_GL_NO_ERROR();
2611
2612 drawQuad(mProgram, "position", 0.5f);
2613
2614 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2615}
2616
2617// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2618// ES 3.0.4 table 3.24
2619TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2620{
Yunchao He9550c602018-02-13 14:47:05 +08002621 // Seems to fail on OSX 10.12 Intel.
2622 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Jamie Madillbb1db482017-01-10 10:48:32 -05002623
Yuly Novikov49886892018-01-23 21:18:27 -05002624 // http://anglebug.com/2190
2625 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2626
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002627 glActiveTexture(GL_TEXTURE0);
2628 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2629 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2630 EXPECT_GL_NO_ERROR();
2631
2632 drawQuad(mProgram, "position", 0.5f);
2633
2634 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2635}
2636
2637// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2638// ES 3.0.4 table 3.24
2639TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2640{
Yunchao He9550c602018-02-13 14:47:05 +08002641 // Seems to fail on OSX 10.12 Intel.
2642 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002643
Yuly Novikov49886892018-01-23 21:18:27 -05002644 // http://anglebug.com/2190
2645 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2646
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002647 glActiveTexture(GL_TEXTURE0);
2648 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2649 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2650 EXPECT_GL_NO_ERROR();
2651
2652 drawQuad(mProgram, "position", 0.5f);
2653
2654 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2655}
2656
Olli Etuaho96963162016-03-21 11:54:33 +02002657// Use a sampler in a uniform struct.
2658TEST_P(SamplerInStructTest, SamplerInStruct)
2659{
2660 runSamplerInStructTest();
2661}
2662
2663// Use a sampler in a uniform struct that's passed as a function parameter.
2664TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2665{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002666 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002667 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002668
Olli Etuaho96963162016-03-21 11:54:33 +02002669 runSamplerInStructTest();
2670}
2671
2672// Use a sampler in a uniform struct array with a struct from the array passed as a function
2673// parameter.
2674TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2675{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002676 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002677 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
2678
Olli Etuaho96963162016-03-21 11:54:33 +02002679 runSamplerInStructTest();
2680}
2681
2682// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2683// parameter.
2684TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2685{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002686 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002687 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
2688
Olli Etuaho96963162016-03-21 11:54:33 +02002689 runSamplerInStructTest();
2690}
2691
2692// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2693// similarly named uniform.
2694TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2695{
2696 runSamplerInStructTest();
2697}
2698
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002699class TextureLimitsTest : public ANGLETest
2700{
2701 protected:
2702 struct RGBA8
2703 {
2704 uint8_t R, G, B, A;
2705 };
2706
2707 TextureLimitsTest()
2708 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
2709 {
2710 setWindowWidth(128);
2711 setWindowHeight(128);
2712 setConfigRedBits(8);
2713 setConfigGreenBits(8);
2714 setConfigBlueBits(8);
2715 setConfigAlphaBits(8);
2716 }
2717
2718 ~TextureLimitsTest()
2719 {
2720 if (mProgram != 0)
2721 {
2722 glDeleteProgram(mProgram);
2723 mProgram = 0;
2724
2725 if (!mTextures.empty())
2726 {
2727 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
2728 }
2729 }
2730 }
2731
2732 void SetUp() override
2733 {
2734 ANGLETest::SetUp();
2735
2736 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
2737 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
2738 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
2739
2740 ASSERT_GL_NO_ERROR();
2741 }
2742
2743 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
2744 GLint vertexTextureCount,
2745 GLint vertexActiveTextureCount,
2746 const std::string &fragPrefix,
2747 GLint fragmentTextureCount,
2748 GLint fragmentActiveTextureCount)
2749 {
2750 std::stringstream vertexShaderStr;
2751 vertexShaderStr << "attribute vec2 position;\n"
2752 << "varying vec4 color;\n"
2753 << "varying vec2 texCoord;\n";
2754
2755 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
2756 {
2757 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
2758 }
2759
2760 vertexShaderStr << "void main() {\n"
2761 << " gl_Position = vec4(position, 0, 1);\n"
2762 << " texCoord = (position * 0.5) + 0.5;\n"
2763 << " color = vec4(0);\n";
2764
2765 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
2766 {
2767 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
2768 << ", texCoord);\n";
2769 }
2770
2771 vertexShaderStr << "}";
2772
2773 std::stringstream fragmentShaderStr;
2774 fragmentShaderStr << "varying mediump vec4 color;\n"
2775 << "varying mediump vec2 texCoord;\n";
2776
2777 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
2778 {
2779 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
2780 }
2781
2782 fragmentShaderStr << "void main() {\n"
2783 << " gl_FragColor = color;\n";
2784
2785 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
2786 {
2787 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
2788 << ", texCoord);\n";
2789 }
2790
2791 fragmentShaderStr << "}";
2792
2793 const std::string &vertexShaderSource = vertexShaderStr.str();
2794 const std::string &fragmentShaderSource = fragmentShaderStr.str();
2795
2796 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
2797 }
2798
2799 RGBA8 getPixel(GLint texIndex)
2800 {
2801 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
2802 0, 255u};
2803 return pixel;
2804 }
2805
2806 void initTextures(GLint tex2DCount, GLint texCubeCount)
2807 {
2808 GLint totalCount = tex2DCount + texCubeCount;
2809 mTextures.assign(totalCount, 0);
2810 glGenTextures(totalCount, &mTextures[0]);
2811 ASSERT_GL_NO_ERROR();
2812
2813 std::vector<RGBA8> texData(16 * 16);
2814
2815 GLint texIndex = 0;
2816 for (; texIndex < tex2DCount; ++texIndex)
2817 {
2818 texData.assign(texData.size(), getPixel(texIndex));
2819 glActiveTexture(GL_TEXTURE0 + texIndex);
2820 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
2821 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2822 &texData[0]);
2823 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2824 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2825 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2826 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2827 }
2828
2829 ASSERT_GL_NO_ERROR();
2830
2831 for (; texIndex < texCubeCount; ++texIndex)
2832 {
2833 texData.assign(texData.size(), getPixel(texIndex));
2834 glActiveTexture(GL_TEXTURE0 + texIndex);
2835 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
2836 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2837 GL_UNSIGNED_BYTE, &texData[0]);
2838 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2839 GL_UNSIGNED_BYTE, &texData[0]);
2840 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2841 GL_UNSIGNED_BYTE, &texData[0]);
2842 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2843 GL_UNSIGNED_BYTE, &texData[0]);
2844 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2845 GL_UNSIGNED_BYTE, &texData[0]);
2846 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2847 GL_UNSIGNED_BYTE, &texData[0]);
2848 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2849 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2850 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2851 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2852 }
2853
2854 ASSERT_GL_NO_ERROR();
2855 }
2856
2857 void testWithTextures(GLint vertexTextureCount,
2858 const std::string &vertexTexturePrefix,
2859 GLint fragmentTextureCount,
2860 const std::string &fragmentTexturePrefix)
2861 {
2862 // Generate textures
2863 initTextures(vertexTextureCount + fragmentTextureCount, 0);
2864
2865 glUseProgram(mProgram);
2866 RGBA8 expectedSum = {0};
2867 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
2868 {
2869 std::stringstream uniformNameStr;
2870 uniformNameStr << vertexTexturePrefix << texIndex;
2871 const std::string &uniformName = uniformNameStr.str();
2872 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
2873 ASSERT_NE(-1, location);
2874
2875 glUniform1i(location, texIndex);
2876 RGBA8 contribution = getPixel(texIndex);
2877 expectedSum.R += contribution.R;
2878 expectedSum.G += contribution.G;
2879 }
2880
2881 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
2882 {
2883 std::stringstream uniformNameStr;
2884 uniformNameStr << fragmentTexturePrefix << texIndex;
2885 const std::string &uniformName = uniformNameStr.str();
2886 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
2887 ASSERT_NE(-1, location);
2888
2889 glUniform1i(location, texIndex + vertexTextureCount);
2890 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
2891 expectedSum.R += contribution.R;
2892 expectedSum.G += contribution.G;
2893 }
2894
2895 ASSERT_GE(256u, expectedSum.G);
2896
2897 drawQuad(mProgram, "position", 0.5f);
2898 ASSERT_GL_NO_ERROR();
2899 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
2900 }
2901
2902 GLuint mProgram;
2903 std::vector<GLuint> mTextures;
2904 GLint mMaxVertexTextures;
2905 GLint mMaxFragmentTextures;
2906 GLint mMaxCombinedTextures;
2907};
2908
2909// Test rendering with the maximum vertex texture units.
2910TEST_P(TextureLimitsTest, MaxVertexTextures)
2911{
2912 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
2913 ASSERT_NE(0u, mProgram);
2914 ASSERT_GL_NO_ERROR();
2915
2916 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
2917}
2918
2919// Test rendering with the maximum fragment texture units.
2920TEST_P(TextureLimitsTest, MaxFragmentTextures)
2921{
2922 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
2923 ASSERT_NE(0u, mProgram);
2924 ASSERT_GL_NO_ERROR();
2925
2926 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
2927}
2928
2929// Test rendering with maximum combined texture units.
2930TEST_P(TextureLimitsTest, MaxCombinedTextures)
2931{
2932 GLint vertexTextures = mMaxVertexTextures;
2933
2934 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
2935 {
2936 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
2937 }
2938
2939 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
2940 mMaxFragmentTextures, mMaxFragmentTextures);
2941 ASSERT_NE(0u, mProgram);
2942 ASSERT_GL_NO_ERROR();
2943
2944 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
2945}
2946
2947// Negative test for exceeding the number of vertex textures
2948TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
2949{
2950 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
2951 0);
2952 ASSERT_EQ(0u, mProgram);
2953}
2954
2955// Negative test for exceeding the number of fragment textures
2956TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
2957{
2958 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
2959 mMaxFragmentTextures + 1);
2960 ASSERT_EQ(0u, mProgram);
2961}
2962
2963// Test active vertex textures under the limit, but excessive textures specified.
2964TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
2965{
2966 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
2967 ASSERT_NE(0u, mProgram);
2968 ASSERT_GL_NO_ERROR();
2969
2970 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
2971}
2972
2973// Test active fragment textures under the limit, but excessive textures specified.
2974TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
2975{
2976 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
2977 mMaxFragmentTextures);
2978 ASSERT_NE(0u, mProgram);
2979 ASSERT_GL_NO_ERROR();
2980
2981 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
2982}
2983
2984// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002985// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002986TEST_P(TextureLimitsTest, TextureTypeConflict)
2987{
2988 const std::string &vertexShader =
2989 "attribute vec2 position;\n"
2990 "varying float color;\n"
2991 "uniform sampler2D tex2D;\n"
2992 "uniform samplerCube texCube;\n"
2993 "void main() {\n"
2994 " gl_Position = vec4(position, 0, 1);\n"
2995 " vec2 texCoord = (position * 0.5) + 0.5;\n"
2996 " color = texture2D(tex2D, texCoord).x;\n"
2997 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
2998 "}";
2999 const std::string &fragmentShader =
3000 "varying mediump float color;\n"
3001 "void main() {\n"
3002 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3003 "}";
3004
3005 mProgram = CompileProgram(vertexShader, fragmentShader);
3006 ASSERT_NE(0u, mProgram);
3007
3008 initTextures(1, 0);
3009
3010 glUseProgram(mProgram);
3011 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3012 ASSERT_NE(-1, tex2DLocation);
3013 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3014 ASSERT_NE(-1, texCubeLocation);
3015
3016 glUniform1i(tex2DLocation, 0);
3017 glUniform1i(texCubeLocation, 0);
3018 ASSERT_GL_NO_ERROR();
3019
3020 drawQuad(mProgram, "position", 0.5f);
3021 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3022}
3023
Vincent Lang25ab4512016-05-13 18:13:59 +02003024class Texture2DNorm16TestES3 : public Texture2DTestES3
3025{
3026 protected:
3027 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3028
3029 void SetUp() override
3030 {
3031 Texture2DTestES3::SetUp();
3032
3033 glActiveTexture(GL_TEXTURE0);
3034 glGenTextures(3, mTextures);
3035 glGenFramebuffers(1, &mFBO);
3036 glGenRenderbuffers(1, &mRenderbuffer);
3037
3038 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3039 {
3040 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3041 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3042 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3043 }
3044
3045 glBindTexture(GL_TEXTURE_2D, 0);
3046
3047 ASSERT_GL_NO_ERROR();
3048 }
3049
3050 void TearDown() override
3051 {
3052 glDeleteTextures(3, mTextures);
3053 glDeleteFramebuffers(1, &mFBO);
3054 glDeleteRenderbuffers(1, &mRenderbuffer);
3055
3056 Texture2DTestES3::TearDown();
3057 }
3058
3059 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3060 {
Geoff Langf607c602016-09-21 11:46:48 -04003061 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3062 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003063
3064 setUpProgram();
3065
3066 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3067 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3068 0);
3069
3070 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3071 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3072
3073 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003074 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003075
3076 EXPECT_GL_NO_ERROR();
3077
3078 drawQuad(mProgram, "position", 0.5f);
3079
Geoff Langf607c602016-09-21 11:46:48 -04003080 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003081
Geoff Langf607c602016-09-21 11:46:48 -04003082 EXPECT_PIXEL_COLOR_EQ(
3083 0, 0, SliceFormatColor(
3084 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003085
3086 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3087
3088 ASSERT_GL_NO_ERROR();
3089 }
3090
3091 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3092 {
3093 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003094 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003095
3096 setUpProgram();
3097
3098 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3099 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3100
3101 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3102 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3103 0);
3104
3105 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003106 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003107
3108 EXPECT_GL_NO_ERROR();
3109
3110 drawQuad(mProgram, "position", 0.5f);
3111
Geoff Langf607c602016-09-21 11:46:48 -04003112 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
3113 EXPECT_PIXEL_COLOR_EQ(
3114 0, 0, SliceFormatColor(
3115 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003116
3117 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3118 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3119 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3120 mRenderbuffer);
3121 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3122 EXPECT_GL_NO_ERROR();
3123
3124 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3125 glClear(GL_COLOR_BUFFER_BIT);
3126
3127 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3128
Geoff Langf607c602016-09-21 11:46:48 -04003129 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003130
3131 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3132
3133 ASSERT_GL_NO_ERROR();
3134 }
3135
3136 GLuint mTextures[3];
3137 GLuint mFBO;
3138 GLuint mRenderbuffer;
3139};
3140
3141// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3142TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3143{
Yunchao He9550c602018-02-13 14:47:05 +08003144 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02003145
3146 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3147 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3148 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3149 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3150 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3151 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3152 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3153 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3154
3155 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3156 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3157 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3158}
3159
Olli Etuaho95faa232016-06-07 14:01:53 -07003160// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3161// GLES 3.0.4 section 3.8.3.
3162TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3163{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08003164 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
3165
Yuly Novikov3c754192016-06-27 19:36:41 -04003166 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1429 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08003167 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07003168
3169 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3170 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3171 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3172 ASSERT_GL_NO_ERROR();
3173
3174 // SKIP_IMAGES should not have an effect on uploading 2D textures
3175 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3176 ASSERT_GL_NO_ERROR();
3177
3178 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3179
3180 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3181 pixelsGreen.data());
3182 ASSERT_GL_NO_ERROR();
3183
3184 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3185 pixelsGreen.data());
3186 ASSERT_GL_NO_ERROR();
3187
3188 glUseProgram(mProgram);
3189 drawQuad(mProgram, "position", 0.5f);
3190 ASSERT_GL_NO_ERROR();
3191
3192 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3193}
3194
Olli Etuaho989cac32016-06-08 16:18:49 -07003195// Test that skip defined in unpack parameters is taken into account when determining whether
3196// unpacking source extends outside unpack buffer bounds.
3197TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3198{
3199 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3200 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3201 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3202 ASSERT_GL_NO_ERROR();
3203
3204 GLBuffer buf;
3205 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3206 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3207 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3208 GL_DYNAMIC_COPY);
3209 ASSERT_GL_NO_ERROR();
3210
3211 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3212 ASSERT_GL_NO_ERROR();
3213
3214 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3215 ASSERT_GL_NO_ERROR();
3216
3217 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3218 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3219
3220 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3221 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3222 ASSERT_GL_NO_ERROR();
3223
3224 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3225 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3226}
3227
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003228// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3229TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3230{
Yunchao He9550c602018-02-13 14:47:05 +08003231 ANGLE_SKIP_TEST_IF(IsD3D11());
3232
3233 // Incorrect rendering results seen on OSX AMD.
3234 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003235
3236 const GLuint width = 8u;
3237 const GLuint height = 8u;
3238 const GLuint unpackRowLength = 5u;
3239 const GLuint unpackSkipPixels = 1u;
3240
3241 setWindowWidth(width);
3242 setWindowHeight(height);
3243
3244 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3245 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3246 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3247 ASSERT_GL_NO_ERROR();
3248
3249 GLBuffer buf;
3250 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3251 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3252 GLColor::green);
3253
3254 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3255 {
3256 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3257 }
3258
3259 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3260 GL_DYNAMIC_COPY);
3261 ASSERT_GL_NO_ERROR();
3262
3263 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3264 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3265 ASSERT_GL_NO_ERROR();
3266
3267 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3268 ASSERT_GL_NO_ERROR();
3269
3270 glUseProgram(mProgram);
3271 drawQuad(mProgram, "position", 0.5f);
3272 ASSERT_GL_NO_ERROR();
3273
3274 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3275 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3276 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3277 actual.data());
3278 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3279 EXPECT_EQ(expected, actual);
3280}
3281
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003282template <typename T>
3283T UNorm(double value)
3284{
3285 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3286}
3287
3288// Test rendering a depth texture with mipmaps.
3289TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3290{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003291 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3292 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
3293 // http://anglebugs.com/1706
Yunchao He9550c602018-02-13 14:47:05 +08003294 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows());
Corentin Walleze731d8a2016-09-07 10:56:25 -04003295
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003296 const int size = getWindowWidth();
3297
3298 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003299 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003300
3301 glActiveTexture(GL_TEXTURE0);
3302 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3303 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3304 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3305 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3306 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3307 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3308 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3309 ASSERT_GL_NO_ERROR();
3310
3311 glUseProgram(mProgram);
3312 glUniform1i(mTexture2DUniformLocation, 0);
3313
3314 std::vector<unsigned char> expected;
3315
3316 for (int level = 0; level < levels; ++level)
3317 {
3318 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3319 expected.push_back(UNorm<unsigned char>(value));
3320
3321 int levelDim = dim(level);
3322
3323 ASSERT_GT(levelDim, 0);
3324
3325 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3326 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3327 GL_UNSIGNED_INT, initData.data());
3328 }
3329 ASSERT_GL_NO_ERROR();
3330
3331 for (int level = 0; level < levels; ++level)
3332 {
3333 glViewport(0, 0, dim(level), dim(level));
3334 drawQuad(mProgram, "position", 0.5f);
3335 GLColor actual = ReadColor(0, 0);
3336 EXPECT_NEAR(expected[level], actual.R, 10u);
3337 }
3338
3339 ASSERT_GL_NO_ERROR();
3340}
3341
Jamie Madill7ffdda92016-09-08 13:26:51 -04003342// Tests unpacking into the unsized GL_ALPHA format.
3343TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3344{
Jamie Madill7ffdda92016-09-08 13:26:51 -04003345 // Initialize the texure.
3346 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3347 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3348 GL_UNSIGNED_BYTE, nullptr);
3349 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3350 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3351
3352 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3353
3354 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04003355 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04003356 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3357 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3358 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
3359 GL_STATIC_DRAW);
3360
3361 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
3362 GL_UNSIGNED_BYTE, nullptr);
3363
3364 // Clear to a weird color to make sure we're drawing something.
3365 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
3366 glClear(GL_COLOR_BUFFER_BIT);
3367
3368 // Draw with the alpha texture and verify.
3369 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04003370
3371 ASSERT_GL_NO_ERROR();
3372 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
3373}
3374
Jamie Madill2e600342016-09-19 13:56:40 -04003375// Ensure stale unpack data doesn't propagate in D3D11.
3376TEST_P(Texture2DTestES3, StaleUnpackData)
3377{
3378 // Init unpack buffer.
3379 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
3380 std::vector<GLColor> pixels(pixelCount, GLColor::red);
3381
3382 GLBuffer unpackBuffer;
3383 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3384 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3385 GLsizei bufferSize = pixelCount * sizeof(GLColor);
3386 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
3387
3388 // Create from unpack buffer.
3389 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3390 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
3391 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3392 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3393 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3394
3395 drawQuad(mProgram, "position", 0.5f);
3396
3397 ASSERT_GL_NO_ERROR();
3398 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3399
3400 // Fill unpack with green, recreating buffer.
3401 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
3402 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
3403 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
3404
3405 // Reinit texture with green.
3406 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
3407 GL_UNSIGNED_BYTE, nullptr);
3408
3409 drawQuad(mProgram, "position", 0.5f);
3410
3411 ASSERT_GL_NO_ERROR();
3412 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3413}
3414
Geoff Langfb7685f2017-11-13 11:44:11 -05003415// Ensure that texture parameters passed as floats that are converted to ints are rounded before
3416// validating they are less than 0.
3417TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
3418{
3419 GLTexture texture;
3420 glBindTexture(GL_TEXTURE_2D, texture);
3421
3422 // Use a negative number that will round to zero when converted to an integer
3423 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
3424 // "Validation of values performed by state-setting commands is performed after conversion,
3425 // unless specified otherwise for a specific command."
3426 GLfloat param = -7.30157126e-07f;
3427 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
3428 EXPECT_GL_NO_ERROR();
3429
3430 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
3431 EXPECT_GL_NO_ERROR();
3432}
3433
Jamie Madillf097e232016-11-05 00:44:15 -04003434// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
3435// being properly checked, and the texture storage of the previous texture format was persisting.
3436// This would result in an ASSERT in debug and incorrect rendering in release.
3437// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
3438TEST_P(Texture3DTestES3, FormatRedefinitionBug)
3439{
3440 GLTexture tex;
3441 glBindTexture(GL_TEXTURE_3D, tex.get());
3442 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3443
3444 GLFramebuffer framebuffer;
3445 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3446 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
3447
3448 glCheckFramebufferStatus(GL_FRAMEBUFFER);
3449
3450 std::vector<uint8_t> pixelData(100, 0);
3451
3452 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
3453 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
3454 pixelData.data());
3455
3456 ASSERT_GL_NO_ERROR();
3457}
3458
Corentin Wallezd2627992017-04-28 17:17:03 -04003459// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
3460TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
3461{
3462 // 2D tests
3463 {
3464 GLTexture tex;
3465 glBindTexture(GL_TEXTURE_2D, tex.get());
3466
3467 GLBuffer pbo;
3468 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3469
3470 // Test OOB
3471 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
3472 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3473 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3474
3475 // Test OOB
3476 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
3477 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3478 ASSERT_GL_NO_ERROR();
3479 }
3480
3481 // 3D tests
3482 {
3483 GLTexture tex;
3484 glBindTexture(GL_TEXTURE_3D, tex.get());
3485
3486 GLBuffer pbo;
3487 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3488
3489 // Test OOB
3490 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
3491 GL_STATIC_DRAW);
3492 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3493 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3494
3495 // Test OOB
3496 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
3497 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3498 ASSERT_GL_NO_ERROR();
3499 }
3500}
3501
Jamie Madill3ed60422017-09-07 11:32:52 -04003502// Tests behaviour with a single texture and multiple sampler objects.
3503TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
3504{
3505 GLint maxTextureUnits = 0;
3506 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
3507 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
3508
3509 constexpr int kSize = 16;
3510
3511 // Make a single-level texture, fill it with red.
3512 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
3513 GLTexture tex;
3514 glBindTexture(GL_TEXTURE_2D, tex);
3515 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3516 redColors.data());
3517 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3518 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3519
3520 // Simple sanity check.
3521 draw2DTexturedQuad(0.5f, 1.0f, true);
3522 ASSERT_GL_NO_ERROR();
3523 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3524
3525 // Bind texture to unit 1 with a sampler object making it incomplete.
3526 GLSampler sampler;
3527 glBindSampler(0, sampler);
3528 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3529 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3530
3531 // Make a mipmap texture, fill it with blue.
3532 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
3533 GLTexture mipmapTex;
3534 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3535 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3536 blueColors.data());
3537 glGenerateMipmap(GL_TEXTURE_2D);
3538
3539 // Draw with the sampler, expect blue.
3540 draw2DTexturedQuad(0.5f, 1.0f, true);
3541 ASSERT_GL_NO_ERROR();
3542 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
3543
3544 // Simple multitexturing program.
3545 const std::string vs =
3546 "#version 300 es\n"
3547 "in vec2 position;\n"
3548 "out vec2 texCoord;\n"
3549 "void main()\n"
3550 "{\n"
3551 " gl_Position = vec4(position, 0, 1);\n"
3552 " texCoord = position * 0.5 + vec2(0.5);\n"
3553 "}";
3554 const std::string fs =
3555 "#version 300 es\n"
3556 "precision mediump float;\n"
3557 "in vec2 texCoord;\n"
3558 "uniform sampler2D tex1;\n"
3559 "uniform sampler2D tex2;\n"
3560 "uniform sampler2D tex3;\n"
3561 "uniform sampler2D tex4;\n"
3562 "out vec4 color;\n"
3563 "void main()\n"
3564 "{\n"
3565 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
3566 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
3567 "}";
3568
3569 ANGLE_GL_PROGRAM(program, vs, fs);
3570
3571 std::array<GLint, 4> texLocations = {
3572 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
3573 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
3574 for (GLint location : texLocations)
3575 {
3576 ASSERT_NE(-1, location);
3577 }
3578
3579 // Init the uniform data.
3580 glUseProgram(program);
3581 for (GLint location = 0; location < 4; ++location)
3582 {
3583 glUniform1i(texLocations[location], location);
3584 }
3585
3586 // Initialize four samplers
3587 GLSampler samplers[4];
3588
3589 // 0: non-mipped.
3590 glBindSampler(0, samplers[0]);
3591 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3592 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3593
3594 // 1: mipped.
3595 glBindSampler(1, samplers[1]);
3596 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3597 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3598
3599 // 2: non-mipped.
3600 glBindSampler(2, samplers[2]);
3601 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3602 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3603
3604 // 3: mipped.
3605 glBindSampler(3, samplers[3]);
3606 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3607 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3608
3609 // Bind two blue mipped textures and two single layer textures, should all draw.
3610 glActiveTexture(GL_TEXTURE0);
3611 glBindTexture(GL_TEXTURE_2D, tex);
3612
3613 glActiveTexture(GL_TEXTURE1);
3614 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3615
3616 glActiveTexture(GL_TEXTURE2);
3617 glBindTexture(GL_TEXTURE_2D, tex);
3618
3619 glActiveTexture(GL_TEXTURE3);
3620 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3621
3622 ASSERT_GL_NO_ERROR();
3623
3624 drawQuad(program, "position", 0.5f);
3625 ASSERT_GL_NO_ERROR();
3626 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
3627
3628 // Bind four single layer textures, two should be incomplete.
3629 glActiveTexture(GL_TEXTURE1);
3630 glBindTexture(GL_TEXTURE_2D, tex);
3631
3632 glActiveTexture(GL_TEXTURE3);
3633 glBindTexture(GL_TEXTURE_2D, tex);
3634
3635 drawQuad(program, "position", 0.5f);
3636 ASSERT_GL_NO_ERROR();
3637 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
3638}
3639
Martin Radev7e2c0d32017-09-15 14:25:42 +03003640// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
3641// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
3642// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
3643// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
3644// samples the cubemap using a direction vector (1,1,1).
3645TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
3646{
Yunchao He2f23f352018-02-11 22:11:37 +08003647 // Check http://anglebug.com/2155.
3648 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
3649
Martin Radev7e2c0d32017-09-15 14:25:42 +03003650 const std::string vs =
3651 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003652 precision mediump float;
3653 in vec3 pos;
3654 void main() {
3655 gl_Position = vec4(pos, 1.0);
3656 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003657
3658 const std::string fs =
3659 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003660 precision mediump float;
3661 out vec4 color;
3662 uniform samplerCube uTex;
3663 void main(){
3664 color = texture(uTex, vec3(1.0));
3665 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003666 ANGLE_GL_PROGRAM(program, vs, fs);
3667 glUseProgram(program);
3668
3669 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
3670 glActiveTexture(GL_TEXTURE0);
3671
3672 GLTexture cubeTex;
3673 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
3674
3675 const int kFaceWidth = 1;
3676 const int kFaceHeight = 1;
3677 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
3678 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3679 GL_UNSIGNED_BYTE, texData.data());
3680 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3681 GL_UNSIGNED_BYTE, texData.data());
3682 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3683 GL_UNSIGNED_BYTE, texData.data());
3684 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3685 GL_UNSIGNED_BYTE, texData.data());
3686 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3687 GL_UNSIGNED_BYTE, texData.data());
3688 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3689 GL_UNSIGNED_BYTE, texData.data());
3690 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3691 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3692 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
3693 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
3694 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
3695 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
3696
3697 drawQuad(program, "pos", 0.5f, 1.0f, true);
3698 ASSERT_GL_NO_ERROR();
3699
3700 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
3701}
3702
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08003703// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
3704TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
3705{
3706 GLuint texture = create2DTexture();
3707
3708 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
3709 EXPECT_GL_ERROR(GL_INVALID_VALUE);
3710
3711 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
3712 EXPECT_GL_ERROR(GL_INVALID_VALUE);
3713
3714 glDeleteTextures(1, &texture);
3715 EXPECT_GL_NO_ERROR();
3716}
3717
Jamie Madillfa05f602015-05-07 13:47:11 -04003718// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003719// TODO(oetuaho): Enable all below tests on OpenGL. Requires a fix for ANGLE bug 1278.
Geoff Lange0cc2a42016-01-20 10:58:17 -05003720ANGLE_INSTANTIATE_TEST(Texture2DTest,
3721 ES2_D3D9(),
3722 ES2_D3D11(),
3723 ES2_D3D11_FL9_3(),
3724 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05003725 ES2_OPENGLES(),
3726 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003727ANGLE_INSTANTIATE_TEST(TextureCubeTest,
3728 ES2_D3D9(),
3729 ES2_D3D11(),
Geoff Langf7480ad2017-10-24 11:46:02 -04003730 ES2_D3D11_FL10_0(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003731 ES2_D3D11_FL9_3(),
3732 ES2_OPENGL(),
3733 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003734ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
3735 ES2_D3D9(),
3736 ES2_D3D11(),
3737 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003738 ES2_OPENGL(),
3739 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003740ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
3741 ES2_D3D9(),
3742 ES2_D3D11(),
3743 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003744 ES2_OPENGL(),
3745 ES2_OPENGLES());
3746ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
3747 ES2_D3D9(),
3748 ES2_D3D11(),
3749 ES2_D3D11_FL9_3(),
3750 ES2_OPENGL(),
3751 ES2_OPENGLES());
3752ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
3753 ES2_D3D9(),
3754 ES2_D3D11(),
3755 ES2_D3D11_FL9_3(),
3756 ES2_OPENGL(),
3757 ES2_OPENGLES());
3758ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02003759ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003760ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3761ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
3762 ES3_D3D11(),
3763 ES3_OPENGL(),
3764 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003765ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
3766 ES3_D3D11(),
3767 ES3_OPENGL(),
3768 ES3_OPENGLES());
3769ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3770ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02003771ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02003772ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
3773 ES2_D3D11(),
3774 ES2_D3D11_FL9_3(),
3775 ES2_D3D9(),
3776 ES2_OPENGL(),
3777 ES2_OPENGLES());
3778ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
3779 ES2_D3D11(),
3780 ES2_D3D11_FL9_3(),
3781 ES2_D3D9(),
3782 ES2_OPENGL(),
3783 ES2_OPENGLES());
3784ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
3785 ES2_D3D11(),
3786 ES2_D3D11_FL9_3(),
3787 ES2_D3D9(),
3788 ES2_OPENGL(),
3789 ES2_OPENGLES());
3790ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
3791 ES2_D3D11(),
3792 ES2_D3D11_FL9_3(),
3793 ES2_D3D9(),
3794 ES2_OPENGL(),
3795 ES2_OPENGLES());
3796ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
3797 ES2_D3D11(),
3798 ES2_D3D11_FL9_3(),
3799 ES2_D3D9(),
3800 ES2_OPENGL(),
3801 ES2_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003802ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES());
Vincent Lang25ab4512016-05-13 18:13:59 +02003803ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03003804ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04003805
Jamie Madill7ffdda92016-09-08 13:26:51 -04003806} // anonymous namespace