blob: 0dfba605d883bf6e5f0bb4552fa584d72c4f6eab [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 {
758 return std::string(
759 "#version 300 es\n"
760 "in vec4 position;\n"
761 "void main()\n"
762 "{\n"
763 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
764 "}\n");
765 }
766
767 std::string getFragmentShaderSource() override
768 {
769 return std::string(
770 "#version 300 es\n"
771 "precision highp float;\n"
772 "uniform highp sampler2D tex2DArray[2];\n"
773 "out vec4 fragColor;\n"
774 "void main()\n"
775 "{\n"
776 " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n"
777 " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n"
778 " fragColor = vec4(red, green, 0.0, 1.0);\n"
779 "}\n");
780 }
781
782 void SetUp() override
783 {
784 TexCoordDrawTest::SetUp();
785
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300786 setUpProgram();
787
Olli Etuahobce743a2016-01-15 17:18:28 +0200788 mTexture0Location = glGetUniformLocation(mProgram, "tex2DArray[0]");
789 ASSERT_NE(-1, mTexture0Location);
790 mTexture1Location = glGetUniformLocation(mProgram, "tex2DArray[1]");
791 ASSERT_NE(-1, mTexture1Location);
792
793 mTexture2DA = create2DTexture();
794 mTexture2DB = create2DTexture();
795 ASSERT_GL_NO_ERROR();
796 }
797
798 void TearDown() override
799 {
800 glDeleteTextures(1, &mTexture2DA);
801 glDeleteTextures(1, &mTexture2DB);
802 TexCoordDrawTest::TearDown();
803 }
804
805 GLuint mTexture2DA;
806 GLuint mTexture2DB;
807 GLint mTexture0Location;
808 GLint mTexture1Location;
809};
810
Olli Etuahoa314b612016-03-10 16:43:00 +0200811class Texture3DTestES3 : public TexCoordDrawTest
812{
813 protected:
814 Texture3DTestES3() : TexCoordDrawTest(), mTexture3D(0), mTexture3DUniformLocation(-1) {}
815
816 std::string getVertexShaderSource() override
817 {
818 return std::string(
819 "#version 300 es\n"
820 "out vec2 texcoord;\n"
821 "in vec4 position;\n"
822 "void main()\n"
823 "{\n"
824 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
825 " texcoord = (position.xy * 0.5) + 0.5;\n"
826 "}\n");
827 }
828
829 std::string getFragmentShaderSource() override
830 {
831 return std::string(
832 "#version 300 es\n"
833 "precision highp float;\n"
834 "uniform highp sampler3D tex3D;\n"
835 "in vec2 texcoord;\n"
836 "out vec4 fragColor;\n"
837 "void main()\n"
838 "{\n"
839 " fragColor = texture(tex3D, vec3(texcoord, 0.0));\n"
840 "}\n");
841 }
842
843 void SetUp() override
844 {
845 TexCoordDrawTest::SetUp();
846
847 glGenTextures(1, &mTexture3D);
848
849 setUpProgram();
850
851 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
852 ASSERT_NE(-1, mTexture3DUniformLocation);
853 }
854
855 void TearDown() override
856 {
857 glDeleteTextures(1, &mTexture3D);
858 TexCoordDrawTest::TearDown();
859 }
860
861 GLuint mTexture3D;
862 GLint mTexture3DUniformLocation;
863};
864
Olli Etuaho1a679902016-01-14 12:21:47 +0200865class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest
866{
867 protected:
868 ShadowSamplerPlusSampler3DTestES3()
869 : TexCoordDrawTest(),
870 mTextureShadow(0),
871 mTexture3D(0),
872 mTextureShadowUniformLocation(-1),
873 mTexture3DUniformLocation(-1),
874 mDepthRefUniformLocation(-1)
875 {
876 }
877
878 std::string getVertexShaderSource() override
879 {
880 return std::string(
881 "#version 300 es\n"
882 "out vec2 texcoord;\n"
883 "in vec4 position;\n"
884 "void main()\n"
885 "{\n"
886 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
887 " texcoord = (position.xy * 0.5) + 0.5;\n"
888 "}\n");
889 }
890
891 std::string getFragmentShaderSource() override
892 {
893 return std::string(
894 "#version 300 es\n"
895 "precision highp float;\n"
896 "uniform highp sampler2DShadow tex2DShadow;\n"
897 "uniform highp sampler3D tex3D;\n"
898 "in vec2 texcoord;\n"
899 "uniform float depthRef;\n"
900 "out vec4 fragColor;\n"
901 "void main()\n"
902 "{\n"
903 " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n"
904 " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n"
905 "}\n");
906 }
907
908 void SetUp() override
909 {
910 TexCoordDrawTest::SetUp();
911
912 glGenTextures(1, &mTexture3D);
913
914 glGenTextures(1, &mTextureShadow);
915 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
916 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
917
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300918 setUpProgram();
919
Olli Etuaho1a679902016-01-14 12:21:47 +0200920 mTextureShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
921 ASSERT_NE(-1, mTextureShadowUniformLocation);
922 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
923 ASSERT_NE(-1, mTexture3DUniformLocation);
924 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
925 ASSERT_NE(-1, mDepthRefUniformLocation);
926 }
927
928 void TearDown() override
929 {
930 glDeleteTextures(1, &mTextureShadow);
931 glDeleteTextures(1, &mTexture3D);
932 TexCoordDrawTest::TearDown();
933 }
934
935 GLuint mTextureShadow;
936 GLuint mTexture3D;
937 GLint mTextureShadowUniformLocation;
938 GLint mTexture3DUniformLocation;
939 GLint mDepthRefUniformLocation;
940};
941
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200942class SamplerTypeMixTestES3 : public TexCoordDrawTest
943{
944 protected:
945 SamplerTypeMixTestES3()
946 : TexCoordDrawTest(),
947 mTexture2D(0),
948 mTextureCube(0),
949 mTexture2DShadow(0),
950 mTextureCubeShadow(0),
951 mTexture2DUniformLocation(-1),
952 mTextureCubeUniformLocation(-1),
953 mTexture2DShadowUniformLocation(-1),
954 mTextureCubeShadowUniformLocation(-1),
955 mDepthRefUniformLocation(-1)
956 {
957 }
958
959 std::string getVertexShaderSource() override
960 {
961 return std::string(
962 "#version 300 es\n"
963 "out vec2 texcoord;\n"
964 "in vec4 position;\n"
965 "void main()\n"
966 "{\n"
967 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
968 " texcoord = (position.xy * 0.5) + 0.5;\n"
969 "}\n");
970 }
971
972 std::string getFragmentShaderSource() override
973 {
974 return std::string(
975 "#version 300 es\n"
976 "precision highp float;\n"
977 "uniform highp sampler2D tex2D;\n"
978 "uniform highp samplerCube texCube;\n"
979 "uniform highp sampler2DShadow tex2DShadow;\n"
980 "uniform highp samplerCubeShadow texCubeShadow;\n"
981 "in vec2 texcoord;\n"
982 "uniform float depthRef;\n"
983 "out vec4 fragColor;\n"
984 "void main()\n"
985 "{\n"
986 " fragColor = texture(tex2D, texcoord);\n"
987 " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n"
988 " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n"
989 " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * "
990 "0.125);\n"
991 "}\n");
992 }
993
994 void SetUp() override
995 {
996 TexCoordDrawTest::SetUp();
997
998 glGenTextures(1, &mTexture2D);
999 glGenTextures(1, &mTextureCube);
1000
1001 glGenTextures(1, &mTexture2DShadow);
1002 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
1003 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
1004
1005 glGenTextures(1, &mTextureCubeShadow);
1006 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
1007 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
1008
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001009 setUpProgram();
1010
Olli Etuahoc8c99a02016-01-14 16:47:22 +02001011 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
1012 ASSERT_NE(-1, mTexture2DUniformLocation);
1013 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
1014 ASSERT_NE(-1, mTextureCubeUniformLocation);
1015 mTexture2DShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
1016 ASSERT_NE(-1, mTexture2DShadowUniformLocation);
1017 mTextureCubeShadowUniformLocation = glGetUniformLocation(mProgram, "texCubeShadow");
1018 ASSERT_NE(-1, mTextureCubeShadowUniformLocation);
1019 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
1020 ASSERT_NE(-1, mDepthRefUniformLocation);
1021
1022 ASSERT_GL_NO_ERROR();
1023 }
1024
1025 void TearDown() override
1026 {
1027 glDeleteTextures(1, &mTexture2D);
1028 glDeleteTextures(1, &mTextureCube);
1029 glDeleteTextures(1, &mTexture2DShadow);
1030 glDeleteTextures(1, &mTextureCubeShadow);
1031 TexCoordDrawTest::TearDown();
1032 }
1033
1034 GLuint mTexture2D;
1035 GLuint mTextureCube;
1036 GLuint mTexture2DShadow;
1037 GLuint mTextureCubeShadow;
1038 GLint mTexture2DUniformLocation;
1039 GLint mTextureCubeUniformLocation;
1040 GLint mTexture2DShadowUniformLocation;
1041 GLint mTextureCubeShadowUniformLocation;
1042 GLint mDepthRefUniformLocation;
1043};
1044
Olli Etuaho96963162016-03-21 11:54:33 +02001045class SamplerInStructTest : public Texture2DTest
1046{
1047 protected:
1048 SamplerInStructTest() : Texture2DTest() {}
1049
1050 const char *getTextureUniformName() override { return "us.tex"; }
1051
1052 std::string getFragmentShaderSource() override
1053 {
1054 return std::string(
1055 "precision highp float;\n"
1056 "struct S\n"
1057 "{\n"
1058 " vec4 a;\n"
1059 " highp sampler2D tex;\n"
1060 "};\n"
1061 "uniform S us;\n"
1062 "varying vec2 texcoord;\n"
1063 "void main()\n"
1064 "{\n"
1065 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x);\n"
1066 "}\n");
1067 }
1068
1069 void runSamplerInStructTest()
1070 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001071 setUpProgram();
1072
Olli Etuaho96963162016-03-21 11:54:33 +02001073 glActiveTexture(GL_TEXTURE0);
1074 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001075 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1076 &GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001077 drawQuad(mProgram, "position", 0.5f);
Olli Etuahoa314b612016-03-10 16:43:00 +02001078 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001079 }
1080};
1081
1082class SamplerInStructAsFunctionParameterTest : public SamplerInStructTest
1083{
1084 protected:
1085 SamplerInStructAsFunctionParameterTest() : SamplerInStructTest() {}
1086
1087 std::string getFragmentShaderSource() override
1088 {
1089 return std::string(
1090 "precision highp float;\n"
1091 "struct S\n"
1092 "{\n"
1093 " vec4 a;\n"
1094 " highp sampler2D tex;\n"
1095 "};\n"
1096 "uniform S us;\n"
1097 "varying vec2 texcoord;\n"
1098 "vec4 sampleFrom(S s) {\n"
1099 " return texture2D(s.tex, texcoord + s.a.x);\n"
1100 "}\n"
1101 "void main()\n"
1102 "{\n"
1103 " gl_FragColor = sampleFrom(us);\n"
1104 "}\n");
1105 }
1106};
1107
1108class SamplerInStructArrayAsFunctionParameterTest : public SamplerInStructTest
1109{
1110 protected:
1111 SamplerInStructArrayAsFunctionParameterTest() : SamplerInStructTest() {}
1112
1113 const char *getTextureUniformName() override { return "us[0].tex"; }
1114
1115 std::string getFragmentShaderSource() override
1116 {
1117 return std::string(
1118 "precision highp float;\n"
1119 "struct S\n"
1120 "{\n"
1121 " vec4 a;\n"
1122 " highp sampler2D tex;\n"
1123 "};\n"
1124 "uniform S us[1];\n"
1125 "varying vec2 texcoord;\n"
1126 "vec4 sampleFrom(S s) {\n"
1127 " return texture2D(s.tex, texcoord + s.a.x);\n"
1128 "}\n"
1129 "void main()\n"
1130 "{\n"
1131 " gl_FragColor = sampleFrom(us[0]);\n"
1132 "}\n");
1133 }
1134};
1135
1136class SamplerInNestedStructAsFunctionParameterTest : public SamplerInStructTest
1137{
1138 protected:
1139 SamplerInNestedStructAsFunctionParameterTest() : SamplerInStructTest() {}
1140
1141 const char *getTextureUniformName() override { return "us[0].sub.tex"; }
1142
1143 std::string getFragmentShaderSource() override
1144 {
1145 return std::string(
1146 "precision highp float;\n"
1147 "struct SUB\n"
1148 "{\n"
1149 " vec4 a;\n"
1150 " highp sampler2D tex;\n"
1151 "};\n"
1152 "struct S\n"
1153 "{\n"
1154 " SUB sub;\n"
1155 "};\n"
1156 "uniform S us[1];\n"
1157 "varying vec2 texcoord;\n"
1158 "vec4 sampleFrom(SUB s) {\n"
1159 " return texture2D(s.tex, texcoord + s.a.x);\n"
1160 "}\n"
1161 "void main()\n"
1162 "{\n"
1163 " gl_FragColor = sampleFrom(us[0].sub);\n"
1164 "}\n");
1165 }
1166};
1167
1168class SamplerInStructAndOtherVariableTest : public SamplerInStructTest
1169{
1170 protected:
1171 SamplerInStructAndOtherVariableTest() : SamplerInStructTest() {}
1172
1173 std::string getFragmentShaderSource() override
1174 {
1175 return std::string(
1176 "precision highp float;\n"
1177 "struct S\n"
1178 "{\n"
1179 " vec4 a;\n"
1180 " highp sampler2D tex;\n"
1181 "};\n"
1182 "uniform S us;\n"
1183 "uniform float us_tex;\n"
1184 "varying vec2 texcoord;\n"
1185 "void main()\n"
1186 "{\n"
1187 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x + us_tex);\n"
1188 "}\n");
1189 }
1190};
1191
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001192TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001193{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001194 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001195 EXPECT_GL_ERROR(GL_NO_ERROR);
1196
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001197 setUpProgram();
1198
Jamie Madillf67115c2014-04-22 13:14:05 -04001199 const GLubyte *pixels[20] = { 0 };
1200 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1201 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001202
1203 if (extensionEnabled("GL_EXT_texture_storage"))
1204 {
1205 // Create a 1-level immutable texture.
1206 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1207
1208 // Try calling sub image on the second level.
1209 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1210 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1211 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001212}
Geoff Langc41e42d2014-04-28 10:58:16 -04001213
John Bauman18319182016-09-28 14:22:27 -07001214// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1215TEST_P(Texture2DTest, QueryBinding)
1216{
1217 glBindTexture(GL_TEXTURE_2D, 0);
1218 EXPECT_GL_ERROR(GL_NO_ERROR);
1219
1220 GLint textureBinding;
1221 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1222 EXPECT_GL_NO_ERROR();
1223 EXPECT_EQ(0, textureBinding);
1224
1225 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
1226 if (extensionEnabled("GL_OES_EGL_image_external") ||
1227 extensionEnabled("GL_NV_EGL_stream_consumer_external"))
1228 {
1229 EXPECT_GL_NO_ERROR();
1230 EXPECT_EQ(0, textureBinding);
1231 }
1232 else
1233 {
1234 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1235 }
1236}
1237
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001238TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001239{
Luc Ferron5164b792018-03-06 09:10:12 -05001240 // TODO(lucferron): Enable this test on Vulkan after this bug is done.
1241 // http://anglebug.com/2392
1242 ANGLE_SKIP_TEST_IF(IsVulkan());
1243
Jamie Madilld4cfa572014-07-08 10:00:32 -04001244 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001245 EXPECT_GL_ERROR(GL_NO_ERROR);
1246
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001247 setUpProgram();
1248
Geoff Langc41e42d2014-04-28 10:58:16 -04001249 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001250 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001251 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001252 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001253
1254 const GLubyte *pixel[4] = { 0 };
1255
1256 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1257 EXPECT_GL_NO_ERROR();
1258
1259 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1260 EXPECT_GL_NO_ERROR();
1261
1262 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1263 EXPECT_GL_NO_ERROR();
1264}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001265
1266// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001267TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001268{
1269 glActiveTexture(GL_TEXTURE0);
1270 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1271 glActiveTexture(GL_TEXTURE1);
1272 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1273 EXPECT_GL_ERROR(GL_NO_ERROR);
1274
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001275 glUseProgram(mProgram);
1276 glUniform1i(mTexture2DUniformLocation, 0);
1277 glUniform1i(mTextureCubeUniformLocation, 1);
1278 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001279 EXPECT_GL_NO_ERROR();
1280}
Jamie Madill9aca0592014-10-06 16:26:59 -04001281
Olli Etuaho53a2da12016-01-11 15:43:32 +02001282// Test drawing with two texture types accessed from the same shader and check that the result of
1283// drawing is correct.
1284TEST_P(TextureCubeTest, CubeMapDraw)
1285{
1286 GLubyte texData[4];
1287 texData[0] = 0;
1288 texData[1] = 60;
1289 texData[2] = 0;
1290 texData[3] = 255;
1291
1292 glActiveTexture(GL_TEXTURE0);
1293 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1294 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1295
1296 glActiveTexture(GL_TEXTURE1);
1297 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1298 texData[1] = 120;
1299 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1300 texData);
1301 EXPECT_GL_ERROR(GL_NO_ERROR);
1302
1303 glUseProgram(mProgram);
1304 glUniform1i(mTexture2DUniformLocation, 0);
1305 glUniform1i(mTextureCubeUniformLocation, 1);
1306 drawQuad(mProgram, "position", 0.5f);
1307 EXPECT_GL_NO_ERROR();
1308
1309 int px = getWindowWidth() - 1;
1310 int py = 0;
1311 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1312}
1313
Olli Etuaho4644a202016-01-12 15:12:53 +02001314TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1315{
1316 glActiveTexture(GL_TEXTURE0);
1317 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1318 GLubyte texData[4];
1319 texData[0] = 0;
1320 texData[1] = 128;
1321 texData[2] = 0;
1322 texData[3] = 255;
1323 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1324 glUseProgram(mProgram);
1325 glUniform1i(mTexture2DUniformLocation, 0);
1326 drawQuad(mProgram, "position", 0.5f);
1327 EXPECT_GL_NO_ERROR();
1328
1329 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1330}
1331
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001332// Test drawing with two textures passed to the shader in a sampler array.
1333TEST_P(SamplerArrayTest, SamplerArrayDraw)
1334{
1335 testSamplerArrayDraw();
1336}
1337
1338// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1339// user-defined function in the shader.
1340TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1341{
1342 testSamplerArrayDraw();
1343}
1344
Jamie Madill9aca0592014-10-06 16:26:59 -04001345// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001346TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001347{
1348 int px = getWindowWidth() / 2;
1349 int py = getWindowHeight() / 2;
1350
1351 glActiveTexture(GL_TEXTURE0);
1352 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1353
Olli Etuahoa314b612016-03-10 16:43:00 +02001354 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001355
Olli Etuahoa314b612016-03-10 16:43:00 +02001356 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001357 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1358 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1359 glGenerateMipmap(GL_TEXTURE_2D);
1360
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001361 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001362 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001363 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1364 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001365 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001366 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001367
Olli Etuahoa314b612016-03-10 16:43:00 +02001368 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
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 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001372 glGenerateMipmap(GL_TEXTURE_2D);
1373
Olli Etuahoa314b612016-03-10 16:43:00 +02001374 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001375
Olli Etuahoa314b612016-03-10 16:43:00 +02001376 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1377 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001378 glGenerateMipmap(GL_TEXTURE_2D);
1379
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001380 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001381
1382 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001383 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001384}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001385
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001386// Test creating a FBO with a cube map render target, to test an ANGLE bug
1387// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001388TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001389{
1390 GLuint fbo;
1391 glGenFramebuffers(1, &fbo);
1392 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1393
1394 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1395 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mTextureCube, 0);
1396
Corentin Wallez322653b2015-06-17 18:33:56 +02001397 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001398
1399 glDeleteFramebuffers(1, &fbo);
1400
1401 EXPECT_GL_NO_ERROR();
1402}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001403
1404// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001405TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001406{
Yunchao He9550c602018-02-13 14:47:05 +08001407 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -04001408
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001409 int width = getWindowWidth();
1410 int height = getWindowHeight();
1411
1412 GLuint tex2D;
1413 glGenTextures(1, &tex2D);
1414 glActiveTexture(GL_TEXTURE0);
1415 glBindTexture(GL_TEXTURE_2D, tex2D);
1416
1417 // Fill with red
1418 std::vector<GLubyte> pixels(3 * 16 * 16);
1419 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1420 {
1421 pixels[pixelId * 3 + 0] = 255;
1422 pixels[pixelId * 3 + 1] = 0;
1423 pixels[pixelId * 3 + 2] = 0;
1424 }
1425
1426 // ANGLE internally uses RGBA as the DirectX format for RGB images
1427 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1428 // The data is kept in a CPU-side image and the image is marked as dirty.
Geoff Langc4e93662017-05-01 10:45:59 -04001429 if (getClientMajorVersion() >= 3)
1430 {
1431 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1432 }
1433 else
1434 {
1435 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1436 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001437
1438 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1439 // glTexSubImage2D should take into account that the image is dirty.
1440 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1441 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1442 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1443
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001444 setUpProgram();
1445
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001446 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001447 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001448 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001449 glDeleteTextures(1, &tex2D);
1450 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001451 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001452
1453 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001454 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1455 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001456}
1457
1458// 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 +02001459TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001460{
1461 if (extensionEnabled("NV_pixel_buffer_object"))
1462 {
1463 int width = getWindowWidth();
1464 int height = getWindowHeight();
1465
1466 GLuint tex2D;
1467 glGenTextures(1, &tex2D);
1468 glActiveTexture(GL_TEXTURE0);
1469 glBindTexture(GL_TEXTURE_2D, tex2D);
1470
1471 // Fill with red
1472 std::vector<GLubyte> pixels(3 * 16 * 16);
1473 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1474 {
1475 pixels[pixelId * 3 + 0] = 255;
1476 pixels[pixelId * 3 + 1] = 0;
1477 pixels[pixelId * 3 + 2] = 0;
1478 }
1479
1480 // Read 16x16 region from red backbuffer to PBO
1481 GLuint pbo;
1482 glGenBuffers(1, &pbo);
1483 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1484 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1485
1486 // ANGLE internally uses RGBA as the DirectX format for RGB images
1487 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1488 // The data is kept in a CPU-side image and the image is marked as dirty.
1489 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1490
1491 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1492 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001493 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 +00001494 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1495 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1496
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001497 setUpProgram();
1498
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001499 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001500 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001501 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001502 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001503 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001504 EXPECT_GL_NO_ERROR();
1505 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1506 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1507 }
1508}
Jamie Madillbc393df2015-01-29 13:46:07 -05001509
1510// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001511TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001512{
1513 testFloatCopySubImage(1, 1);
1514}
1515
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001516TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001517{
1518 testFloatCopySubImage(2, 1);
1519}
1520
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001521TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001522{
1523 testFloatCopySubImage(2, 2);
1524}
1525
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001526TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001527{
1528 testFloatCopySubImage(3, 1);
1529}
1530
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001531TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001532{
1533 testFloatCopySubImage(3, 2);
1534}
1535
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001536TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001537{
Yunchao He9550c602018-02-13 14:47:05 +08001538 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1539 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001540
Yunchao He9550c602018-02-13 14:47:05 +08001541 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1542 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001543
Jamie Madillbc393df2015-01-29 13:46:07 -05001544 testFloatCopySubImage(3, 3);
1545}
1546
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001547TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001548{
1549 testFloatCopySubImage(4, 1);
1550}
1551
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001552TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001553{
1554 testFloatCopySubImage(4, 2);
1555}
1556
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001557TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001558{
Yunchao He9550c602018-02-13 14:47:05 +08001559 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1560 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001561
Jamie Madillbc393df2015-01-29 13:46:07 -05001562 testFloatCopySubImage(4, 3);
1563}
1564
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001565TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001566{
Yunchao He9550c602018-02-13 14:47:05 +08001567 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1568 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001569
Jamie Madillbc393df2015-01-29 13:46:07 -05001570 testFloatCopySubImage(4, 4);
1571}
Austin Kinross07285142015-03-26 11:36:16 -07001572
1573// Port of https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1574// 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 +02001575TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001576{
Luc Ferron5164b792018-03-06 09:10:12 -05001577 // TODO(lucferron): DIRTY_BIT_UNPACK_STATE isn't implemented on Vulkan yet.
1578 ANGLE_SKIP_TEST_IF(IsVulkan());
1579
Austin Kinross07285142015-03-26 11:36:16 -07001580 const int npotTexSize = 5;
1581 const int potTexSize = 4; // Should be less than npotTexSize
1582 GLuint tex2D;
1583
1584 if (extensionEnabled("GL_OES_texture_npot"))
1585 {
1586 // This test isn't applicable if texture_npot is enabled
1587 return;
1588 }
1589
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001590 setUpProgram();
1591
Austin Kinross07285142015-03-26 11:36:16 -07001592 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1593
Austin Kinross5faa15b2016-01-11 13:32:48 -08001594 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1595 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1596
Austin Kinross07285142015-03-26 11:36:16 -07001597 glActiveTexture(GL_TEXTURE0);
1598 glGenTextures(1, &tex2D);
1599 glBindTexture(GL_TEXTURE_2D, tex2D);
1600
1601 std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize);
1602 for (size_t pixelId = 0; pixelId < npotTexSize * npotTexSize; ++pixelId)
1603 {
1604 pixels[pixelId] = 64;
1605 }
1606
1607 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1608 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1609
1610 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
1611 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1612 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1613
1614 // Check that an NPOT texture on level 0 succeeds
1615 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1616 EXPECT_GL_NO_ERROR();
1617
1618 // Check that generateMipmap fails on NPOT
1619 glGenerateMipmap(GL_TEXTURE_2D);
1620 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1621
1622 // Check that nothing is drawn if filtering is not correct for NPOT
1623 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1624 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1625 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1626 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1627 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001628 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001629 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1630
1631 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1632 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1633 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1634 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_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, 255);
1638
1639 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1640 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1641 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001642 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001643 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1644
1645 // Check that glTexImage2D for POT texture succeeds
1646 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1647 EXPECT_GL_NO_ERROR();
1648
1649 // Check that generateMipmap for an POT texture succeeds
1650 glGenerateMipmap(GL_TEXTURE_2D);
1651 EXPECT_GL_NO_ERROR();
1652
1653 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1654 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1655 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1656 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1657 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1658 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001659 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001660 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1661 EXPECT_GL_NO_ERROR();
1662}
Jamie Madillfa05f602015-05-07 13:47:11 -04001663
Austin Kinross08528e12015-10-07 16:24:40 -07001664// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1665// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001666TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001667{
Luc Ferron5164b792018-03-06 09:10:12 -05001668 // TODO(lucferron): Generate mipmap on vulkan isn't implemented yet. Re-enable this when it
1669 // is.
1670 ANGLE_SKIP_TEST_IF(IsVulkan());
1671
Austin Kinross08528e12015-10-07 16:24:40 -07001672 glActiveTexture(GL_TEXTURE0);
1673 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1674
1675 // Create an 8x8 (i.e. power-of-two) texture.
1676 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1677 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1678 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1679 glGenerateMipmap(GL_TEXTURE_2D);
1680
1681 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1682 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001683 std::array<GLColor, 3 * 3> data;
1684 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001685
1686 EXPECT_GL_NO_ERROR();
1687}
1688
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001689// Test to check that texture completeness is determined correctly when the texture base level is
1690// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1691TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1692{
1693 glActiveTexture(GL_TEXTURE0);
1694 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001695
1696 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1697 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1698 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1699 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1700 texDataGreen.data());
1701 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1702 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001703 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1704 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1705 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1706
1707 EXPECT_GL_NO_ERROR();
1708
1709 drawQuad(mProgram, "position", 0.5f);
1710
Olli Etuahoa314b612016-03-10 16:43:00 +02001711 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1712}
1713
1714// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1715// have images defined.
1716TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1717{
Yunchao He9550c602018-02-13 14:47:05 +08001718 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1719 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1720
Olli Etuahoa314b612016-03-10 16:43:00 +02001721 glActiveTexture(GL_TEXTURE0);
1722 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1723 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1724 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1725 texDataGreen.data());
1726 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1727 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1728 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1729 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1730
1731 EXPECT_GL_NO_ERROR();
1732
1733 drawQuad(mProgram, "position", 0.5f);
1734
1735 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1736}
1737
Olli Etuahoe8528d82016-05-16 17:50:52 +03001738// Test that drawing works correctly when level 0 is undefined and base level is 1.
1739TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1740{
Yunchao He9550c602018-02-13 14:47:05 +08001741 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1742 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1743
Olli Etuahoe8528d82016-05-16 17:50:52 +03001744 glActiveTexture(GL_TEXTURE0);
1745 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1746 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1747 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1748 texDataGreen.data());
1749 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1750 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1751 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1752 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1753
1754 EXPECT_GL_NO_ERROR();
1755
1756 // Texture is incomplete.
1757 drawQuad(mProgram, "position", 0.5f);
1758 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1759
1760 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1761 texDataGreen.data());
1762
1763 // Texture is now complete.
1764 drawQuad(mProgram, "position", 0.5f);
1765 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1766}
1767
Olli Etuahoa314b612016-03-10 16:43:00 +02001768// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1769// dimensions that don't fit the images inside the range.
1770// GLES 3.0.4 section 3.8.13 Texture completeness
1771TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1772{
Olli Etuahoa314b612016-03-10 16:43:00 +02001773 glActiveTexture(GL_TEXTURE0);
1774 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1775 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1776 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1777 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1778
1779 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1780 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1781
1782 // Two levels that are initially unused.
1783 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1784 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1785 texDataCyan.data());
1786
1787 // One level that is used - only this level should affect completeness.
1788 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1789 texDataGreen.data());
1790
1791 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1792 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1793
1794 EXPECT_GL_NO_ERROR();
1795
1796 drawQuad(mProgram, "position", 0.5f);
1797
1798 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1799
Yunchao He2f23f352018-02-11 22:11:37 +08001800 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001801
1802 // Switch the level that is being used to the cyan level 2.
1803 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1804 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1805
1806 EXPECT_GL_NO_ERROR();
1807
1808 drawQuad(mProgram, "position", 0.5f);
1809
1810 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1811}
1812
1813// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1814// have images defined.
1815TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1816{
Olli Etuahoa314b612016-03-10 16:43:00 +02001817 glActiveTexture(GL_TEXTURE0);
1818 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1819 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1820 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1821 texDataGreen.data());
1822 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1823 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1824 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1825 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1826
1827 EXPECT_GL_NO_ERROR();
1828
1829 drawQuad(mProgram, "position", 0.5f);
1830
1831 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1832}
1833
1834// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1835// dimensions that don't fit the images inside the range.
1836// GLES 3.0.4 section 3.8.13 Texture completeness
1837TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1838{
Olli Etuahoa314b612016-03-10 16:43:00 +02001839 glActiveTexture(GL_TEXTURE0);
1840 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1841 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1842 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1843 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1844
1845 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1846 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1847
1848 // Two levels that are initially unused.
1849 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1850 texDataRed.data());
1851 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1852 texDataCyan.data());
1853
1854 // One level that is used - only this level should affect completeness.
1855 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1856 texDataGreen.data());
1857
1858 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1859 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1860
1861 EXPECT_GL_NO_ERROR();
1862
1863 drawQuad(mProgram, "position", 0.5f);
1864
1865 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1866
Yunchao He2f23f352018-02-11 22:11:37 +08001867 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001868
1869 // Switch the level that is being used to the cyan level 2.
1870 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
1871 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
1872
1873 EXPECT_GL_NO_ERROR();
1874
1875 drawQuad(mProgram, "position", 0.5f);
1876
1877 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1878}
1879
1880// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1881// have images defined.
1882TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
1883{
Olli Etuahoa314b612016-03-10 16:43:00 +02001884 glActiveTexture(GL_TEXTURE0);
1885 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
1886 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1887 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1888 texDataGreen.data());
1889 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1890 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1891 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1892 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1893
1894 EXPECT_GL_NO_ERROR();
1895
1896 drawQuad(mProgram, "position", 0.5f);
1897
1898 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1899}
1900
1901// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1902// dimensions that don't fit the images inside the range.
1903// GLES 3.0.4 section 3.8.13 Texture completeness
1904TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1905{
Olli Etuahoa314b612016-03-10 16:43:00 +02001906 glActiveTexture(GL_TEXTURE0);
1907 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
1908 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1909 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1910 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1911
1912 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1913 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1914
1915 // Two levels that are initially unused.
1916 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1917 texDataRed.data());
1918 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1919 texDataCyan.data());
1920
1921 // One level that is used - only this level should affect completeness.
1922 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1923 texDataGreen.data());
1924
1925 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1926 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1927
1928 EXPECT_GL_NO_ERROR();
1929
1930 drawQuad(mProgram, "position", 0.5f);
1931
1932 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1933
Yunchao He2f23f352018-02-11 22:11:37 +08001934 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
1935
Yunchao He9550c602018-02-13 14:47:05 +08001936 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
1937 // level was changed.
1938 ANGLE_SKIP_TEST_IF(IsNVIDIA() && (IsOpenGL() || IsOpenGLES()));
Olli Etuahoa314b612016-03-10 16:43:00 +02001939
1940 // Switch the level that is being used to the cyan level 2.
1941 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
1942 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
1943
1944 EXPECT_GL_NO_ERROR();
1945
1946 drawQuad(mProgram, "position", 0.5f);
1947
1948 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1949}
1950
1951// Test that texture completeness is updated if texture max level changes.
1952// GLES 3.0.4 section 3.8.13 Texture completeness
1953TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
1954{
Olli Etuahoa314b612016-03-10 16:43:00 +02001955 glActiveTexture(GL_TEXTURE0);
1956 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1957 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
1958
1959 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1960 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1961
1962 // A level that is initially unused.
1963 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1964 texDataGreen.data());
1965
1966 // One level that is initially used - only this level should affect completeness.
1967 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1968 texDataGreen.data());
1969
1970 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
1971 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
1972
1973 EXPECT_GL_NO_ERROR();
1974
1975 drawQuad(mProgram, "position", 0.5f);
1976
1977 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1978
1979 // Switch the max level to level 1. The levels within the used range now have inconsistent
1980 // dimensions and the texture should be incomplete.
1981 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1982
1983 EXPECT_GL_NO_ERROR();
1984
1985 drawQuad(mProgram, "position", 0.5f);
1986
1987 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1988}
1989
1990// Test that 3D texture completeness is updated if texture max level changes.
1991// GLES 3.0.4 section 3.8.13 Texture completeness
1992TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
1993{
Olli Etuahoa314b612016-03-10 16:43:00 +02001994 glActiveTexture(GL_TEXTURE0);
1995 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1996 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1997
1998 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1999 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2000
2001 // A level that is initially unused.
2002 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2003 texDataGreen.data());
2004
2005 // One level that is initially used - only this level should affect completeness.
2006 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2007 texDataGreen.data());
2008
2009 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2010 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2011
2012 EXPECT_GL_NO_ERROR();
2013
2014 drawQuad(mProgram, "position", 0.5f);
2015
2016 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2017
2018 // Switch the max level to level 1. The levels within the used range now have inconsistent
2019 // dimensions and the texture should be incomplete.
2020 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2021
2022 EXPECT_GL_NO_ERROR();
2023
2024 drawQuad(mProgram, "position", 0.5f);
2025
2026 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2027}
2028
2029// Test that texture completeness is updated if texture base level changes.
2030// GLES 3.0.4 section 3.8.13 Texture completeness
2031TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2032{
Olli Etuahoa314b612016-03-10 16:43:00 +02002033 glActiveTexture(GL_TEXTURE0);
2034 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2035 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2036
2037 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2038 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2039
2040 // Two levels that are initially unused.
2041 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2042 texDataGreen.data());
2043 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2044 texDataGreen.data());
2045
2046 // One level that is initially used - only this level should affect completeness.
2047 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2048 texDataGreen.data());
2049
2050 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2051 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2052
2053 EXPECT_GL_NO_ERROR();
2054
2055 drawQuad(mProgram, "position", 0.5f);
2056
2057 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2058
2059 // Switch the base level to level 1. The levels within the used range now have inconsistent
2060 // dimensions and the texture should be incomplete.
2061 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2062
2063 EXPECT_GL_NO_ERROR();
2064
2065 drawQuad(mProgram, "position", 0.5f);
2066
2067 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2068}
2069
2070// Test that texture is not complete if base level is greater than max level.
2071// GLES 3.0.4 section 3.8.13 Texture completeness
2072TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2073{
Olli Etuahoa314b612016-03-10 16:43:00 +02002074 glActiveTexture(GL_TEXTURE0);
2075 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2076
2077 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2078 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2079
2080 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2081
2082 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2083 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2084
2085 EXPECT_GL_NO_ERROR();
2086
2087 drawQuad(mProgram, "position", 0.5f);
2088
2089 // Texture should be incomplete.
2090 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2091}
2092
2093// Test that immutable texture base level and max level are clamped.
2094// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2095TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2096{
Olli Etuahoa314b612016-03-10 16:43:00 +02002097 glActiveTexture(GL_TEXTURE0);
2098 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2099
2100 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2101 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2102
2103 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2104
2105 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2106
2107 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2108 // should be clamped to [base_level, levels - 1].
2109 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2110 // In the case of this test, those rules make the effective base level and max level 0.
2111 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2112 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2113
2114 EXPECT_GL_NO_ERROR();
2115
2116 drawQuad(mProgram, "position", 0.5f);
2117
2118 // Texture should be complete.
2119 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2120}
2121
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002122// Test that changing base level works when it affects the format of the texture.
2123TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2124{
Yunchao He9550c602018-02-13 14:47:05 +08002125 // Observed rendering corruption on NVIDIA OpenGL.
2126 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL());
2127
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002128 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002129
2130 // Observed incorrect rendering on AMD OpenGL.
2131 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002132
2133 glActiveTexture(GL_TEXTURE0);
2134 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2135 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2136 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2137
2138 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2139 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2140
2141 // RGBA8 level that's initially unused.
2142 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2143 texDataCyan.data());
2144
2145 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2146 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2147
2148 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2149 // format. It reads green channel data from the green and alpha channels of texDataGreen
2150 // (this is a bit hacky but works).
2151 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2152
2153 EXPECT_GL_NO_ERROR();
2154
2155 drawQuad(mProgram, "position", 0.5f);
2156
2157 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2158
2159 // Switch the texture to use the cyan level 0 with the RGBA format.
2160 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2161 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2162
2163 EXPECT_GL_NO_ERROR();
2164
2165 drawQuad(mProgram, "position", 0.5f);
2166
2167 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2168}
2169
Olli Etuahoa314b612016-03-10 16:43:00 +02002170// Test that setting a texture image works when base level is out of range.
2171TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2172{
2173 glActiveTexture(GL_TEXTURE0);
2174 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2175
2176 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2177 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2178
2179 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2180 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2181
2182 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2183
2184 EXPECT_GL_NO_ERROR();
2185
2186 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2187
2188 drawQuad(mProgram, "position", 0.5f);
2189
2190 // Texture should be complete.
2191 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002192}
2193
Jamie Madill2453dbc2015-07-14 11:35:42 -04002194// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG RBA->RGBA8, with 1.0
2195// in the alpha channel. This test covers a bug where redefining array textures with these formats does not work as
2196// expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002197TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002198{
2199 std::vector<GLubyte> pixelData;
2200 for (size_t count = 0; count < 5000; count++)
2201 {
2202 pixelData.push_back(0u);
2203 pixelData.push_back(255u);
2204 pixelData.push_back(0u);
2205 }
2206
2207 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002208 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002209 glUniform1i(mTextureArrayLocation, 0);
2210
2211 // The first draw worked correctly.
2212 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
2213
2214 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2215 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2216 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2217 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002218 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002219 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002220
2221 // The dimension of the respecification must match the original exactly to trigger the bug.
2222 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 +02002223 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002224 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002225
2226 ASSERT_GL_NO_ERROR();
2227}
2228
Olli Etuaho1a679902016-01-14 12:21:47 +02002229// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2230// This test is needed especially to confirm that sampler registers get assigned correctly on
2231// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2232TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2233{
2234 glActiveTexture(GL_TEXTURE0);
2235 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2236 GLubyte texData[4];
2237 texData[0] = 0;
2238 texData[1] = 60;
2239 texData[2] = 0;
2240 texData[3] = 255;
2241 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2242
2243 glActiveTexture(GL_TEXTURE1);
2244 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2245 GLfloat depthTexData[1];
2246 depthTexData[0] = 0.5f;
2247 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2248 depthTexData);
2249
2250 glUseProgram(mProgram);
2251 glUniform1f(mDepthRefUniformLocation, 0.3f);
2252 glUniform1i(mTexture3DUniformLocation, 0);
2253 glUniform1i(mTextureShadowUniformLocation, 1);
2254
2255 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2256 drawQuad(mProgram, "position", 0.5f);
2257 EXPECT_GL_NO_ERROR();
2258 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2259 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2260
2261 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2262 drawQuad(mProgram, "position", 0.5f);
2263 EXPECT_GL_NO_ERROR();
2264 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2265 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2266}
2267
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002268// Test multiple different sampler types in the same shader.
2269// This test makes sure that even if sampler / texture registers get grouped together based on type
2270// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2271// still has the right register index information for each ESSL sampler.
2272// The tested ESSL samplers have the following types in D3D11 HLSL:
2273// sampler2D: Texture2D + SamplerState
2274// samplerCube: TextureCube + SamplerState
2275// sampler2DShadow: Texture2D + SamplerComparisonState
2276// samplerCubeShadow: TextureCube + SamplerComparisonState
2277TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2278{
2279 glActiveTexture(GL_TEXTURE0);
2280 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2281 GLubyte texData[4];
2282 texData[0] = 0;
2283 texData[1] = 0;
2284 texData[2] = 120;
2285 texData[3] = 255;
2286 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2287
2288 glActiveTexture(GL_TEXTURE1);
2289 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2290 texData[0] = 0;
2291 texData[1] = 90;
2292 texData[2] = 0;
2293 texData[3] = 255;
2294 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2295 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2296 texData);
2297
2298 glActiveTexture(GL_TEXTURE2);
2299 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2300 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2301 GLfloat depthTexData[1];
2302 depthTexData[0] = 0.5f;
2303 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2304 depthTexData);
2305
2306 glActiveTexture(GL_TEXTURE3);
2307 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2308 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2309 depthTexData[0] = 0.2f;
2310 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2311 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2312 depthTexData);
2313
2314 EXPECT_GL_NO_ERROR();
2315
2316 glUseProgram(mProgram);
2317 glUniform1f(mDepthRefUniformLocation, 0.3f);
2318 glUniform1i(mTexture2DUniformLocation, 0);
2319 glUniform1i(mTextureCubeUniformLocation, 1);
2320 glUniform1i(mTexture2DShadowUniformLocation, 2);
2321 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2322
2323 drawQuad(mProgram, "position", 0.5f);
2324 EXPECT_GL_NO_ERROR();
2325 // The shader writes:
2326 // <texture 2d color> +
2327 // <cube map color> +
2328 // 0.25 * <comparison result (1.0)> +
2329 // 0.125 * <comparison result (0.0)>
2330 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2331}
2332
Olli Etuahobce743a2016-01-15 17:18:28 +02002333// Test different base levels on textures accessed through the same sampler array.
2334// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2335TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2336{
Yunchao He9550c602018-02-13 14:47:05 +08002337 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2338
Olli Etuahobce743a2016-01-15 17:18:28 +02002339 glActiveTexture(GL_TEXTURE0);
2340 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2341 GLsizei size = 64;
2342 for (GLint level = 0; level < 7; ++level)
2343 {
2344 ASSERT_LT(0, size);
2345 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2346 nullptr);
2347 size = size / 2;
2348 }
2349 ASSERT_EQ(0, size);
2350 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2351
2352 glActiveTexture(GL_TEXTURE1);
2353 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2354 size = 128;
2355 for (GLint level = 0; level < 8; ++level)
2356 {
2357 ASSERT_LT(0, size);
2358 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2359 nullptr);
2360 size = size / 2;
2361 }
2362 ASSERT_EQ(0, size);
2363 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2364 EXPECT_GL_NO_ERROR();
2365
2366 glUseProgram(mProgram);
2367 glUniform1i(mTexture0Location, 0);
2368 glUniform1i(mTexture1Location, 1);
2369
2370 drawQuad(mProgram, "position", 0.5f);
2371 EXPECT_GL_NO_ERROR();
2372 // Red channel: width of level 1 of texture A: 32.
2373 // Green channel: width of level 3 of texture B: 16.
2374 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2375}
2376
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002377// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2378// ES 3.0.4 table 3.24
2379TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2380{
2381 glActiveTexture(GL_TEXTURE0);
2382 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2383 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2384 EXPECT_GL_NO_ERROR();
2385
2386 drawQuad(mProgram, "position", 0.5f);
2387
2388 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2389}
2390
2391// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2392// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002393TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002394{
Luc Ferron5164b792018-03-06 09:10:12 -05002395 setUpProgram();
2396
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002397 glActiveTexture(GL_TEXTURE0);
2398 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2399 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2400 EXPECT_GL_NO_ERROR();
2401
2402 drawQuad(mProgram, "position", 0.5f);
2403
2404 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2405}
2406
Luc Ferron5164b792018-03-06 09:10:12 -05002407// Validate that every component of the pixel will be equal to the luminance value we've set
2408// and that the alpha channel will be 1 (or 255 to be exact).
2409TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2410{
2411 setUpProgram();
2412
2413 glActiveTexture(GL_TEXTURE0);
2414 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2415 uint8_t pixel = 50;
2416 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2417 EXPECT_GL_NO_ERROR();
2418
2419 drawQuad(mProgram, "position", 0.5f);
2420
2421 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2422}
2423
2424// Validate that every component of the pixel will be equal to the luminance value we've set
2425// and that the alpha channel will be the second component.
2426TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2427{
2428 setUpProgram();
2429
2430 glActiveTexture(GL_TEXTURE0);
2431 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2432 uint8_t pixel[] = {50, 25};
2433 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2434 GL_UNSIGNED_BYTE, pixel);
2435 EXPECT_GL_NO_ERROR();
2436
2437 drawQuad(mProgram, "position", 0.5f);
2438
2439 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2440}
2441
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002442// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2443// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002444TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002445{
Luc Ferron5164b792018-03-06 09:10:12 -05002446 // TODO(lucferron): Enable Vulkan when we implement float support in ES3.0.
2447 ANGLE_SKIP_TEST_IF(IsVulkan() || IsD3D9());
2448
2449 setUpProgram();
2450
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002451 if (extensionEnabled("GL_OES_texture_float"))
2452 {
2453 glActiveTexture(GL_TEXTURE0);
2454 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2455 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2456 EXPECT_GL_NO_ERROR();
2457
2458 drawQuad(mProgram, "position", 0.5f);
2459
2460 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2461 }
2462}
2463
2464// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2465// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002466TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002467{
Luc Ferron5164b792018-03-06 09:10:12 -05002468 // TODO(lucferron): Enable Vulkan when we implement float support in ES3.0.
2469 ANGLE_SKIP_TEST_IF(IsVulkan() || IsD3D9());
2470
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002471 if (extensionEnabled("GL_OES_texture_half_float"))
2472 {
Luc Ferron5164b792018-03-06 09:10:12 -05002473 setUpProgram();
2474
Yunchao He9550c602018-02-13 14:47:05 +08002475 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES());
2476
Yuly Novikovafcec832016-06-21 22:19:51 -04002477 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002478 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Yuly Novikovafcec832016-06-21 22:19:51 -04002479
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002480 glActiveTexture(GL_TEXTURE0);
2481 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2482 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES,
2483 nullptr);
2484 EXPECT_GL_NO_ERROR();
2485
2486 drawQuad(mProgram, "position", 0.5f);
2487
2488 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2489 }
2490}
2491
2492// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2493// ES 3.0.4 table 3.24
2494TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2495{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002496 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2497
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002498 glActiveTexture(GL_TEXTURE0);
2499 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2500 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2501 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2502 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2503 EXPECT_GL_NO_ERROR();
2504
2505 drawQuad(mProgram, "position", 0.5f);
2506
2507 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2508}
2509
2510// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2511// ES 3.0.4 table 3.24
2512TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2513{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002514 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2515
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002516 glActiveTexture(GL_TEXTURE0);
2517 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2518
2519 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2520 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2521 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2522 EXPECT_GL_NO_ERROR();
2523
2524 drawQuad(mProgram, "position", 0.5f);
2525
2526 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2527}
2528
2529// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2530// ES 3.0.4 table 3.24
2531TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2532{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002533 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2534
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002535 glActiveTexture(GL_TEXTURE0);
2536 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2537 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2538 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2539 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2540 EXPECT_GL_NO_ERROR();
2541
2542 drawQuad(mProgram, "position", 0.5f);
2543
2544 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2545}
2546
2547// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2548// ES 3.0.4 table 3.24
2549TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2550{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002551 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2552
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002553 glActiveTexture(GL_TEXTURE0);
2554 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2555 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2556 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2557 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2558 EXPECT_GL_NO_ERROR();
2559
2560 drawQuad(mProgram, "position", 0.5f);
2561
2562 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2563}
2564
2565// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2566// ES 3.0.4 table 3.24
2567TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2568{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002569 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2570
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002571 glActiveTexture(GL_TEXTURE0);
2572 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2573 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2574 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2575 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2576 EXPECT_GL_NO_ERROR();
2577
2578 drawQuad(mProgram, "position", 0.5f);
2579
2580 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2581}
2582
2583// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2584// ES 3.0.4 table 3.24
2585TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2586{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002587 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2588
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002589 glActiveTexture(GL_TEXTURE0);
2590 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2591 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2592 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2593 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2594 EXPECT_GL_NO_ERROR();
2595
2596 drawQuad(mProgram, "position", 0.5f);
2597
2598 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2599}
2600
2601// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2602// ES 3.0.4 table 3.24
2603TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2604{
2605 glActiveTexture(GL_TEXTURE0);
2606 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2607 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2608 EXPECT_GL_NO_ERROR();
2609
2610 drawQuad(mProgram, "position", 0.5f);
2611
2612 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2613}
2614
2615// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2616// ES 3.0.4 table 3.24
2617TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2618{
2619 glActiveTexture(GL_TEXTURE0);
2620 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2621 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2622 nullptr);
2623 EXPECT_GL_NO_ERROR();
2624
2625 drawQuad(mProgram, "position", 0.5f);
2626
2627 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2628}
2629
2630// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2631// ES 3.0.4 table 3.24
2632TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2633{
Yunchao He9550c602018-02-13 14:47:05 +08002634 // Seems to fail on OSX 10.12 Intel.
2635 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Jamie Madillbb1db482017-01-10 10:48:32 -05002636
Yuly Novikov49886892018-01-23 21:18:27 -05002637 // http://anglebug.com/2190
2638 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2639
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002640 glActiveTexture(GL_TEXTURE0);
2641 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2642 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2643 EXPECT_GL_NO_ERROR();
2644
2645 drawQuad(mProgram, "position", 0.5f);
2646
2647 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2648}
2649
2650// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2651// ES 3.0.4 table 3.24
2652TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2653{
Yunchao He9550c602018-02-13 14:47:05 +08002654 // Seems to fail on OSX 10.12 Intel.
2655 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002656
Yuly Novikov49886892018-01-23 21:18:27 -05002657 // http://anglebug.com/2190
2658 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2659
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002660 glActiveTexture(GL_TEXTURE0);
2661 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2662 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2663 EXPECT_GL_NO_ERROR();
2664
2665 drawQuad(mProgram, "position", 0.5f);
2666
2667 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2668}
2669
Olli Etuaho96963162016-03-21 11:54:33 +02002670// Use a sampler in a uniform struct.
2671TEST_P(SamplerInStructTest, SamplerInStruct)
2672{
2673 runSamplerInStructTest();
2674}
2675
2676// Use a sampler in a uniform struct that's passed as a function parameter.
2677TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2678{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002679 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002680 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002681
Olli Etuaho96963162016-03-21 11:54:33 +02002682 runSamplerInStructTest();
2683}
2684
2685// Use a sampler in a uniform struct array with a struct from the array passed as a function
2686// parameter.
2687TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2688{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002689 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002690 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
2691
Olli Etuaho96963162016-03-21 11:54:33 +02002692 runSamplerInStructTest();
2693}
2694
2695// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2696// parameter.
2697TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2698{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002699 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002700 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
2701
Olli Etuaho96963162016-03-21 11:54:33 +02002702 runSamplerInStructTest();
2703}
2704
2705// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2706// similarly named uniform.
2707TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2708{
2709 runSamplerInStructTest();
2710}
2711
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002712class TextureLimitsTest : public ANGLETest
2713{
2714 protected:
2715 struct RGBA8
2716 {
2717 uint8_t R, G, B, A;
2718 };
2719
2720 TextureLimitsTest()
2721 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
2722 {
2723 setWindowWidth(128);
2724 setWindowHeight(128);
2725 setConfigRedBits(8);
2726 setConfigGreenBits(8);
2727 setConfigBlueBits(8);
2728 setConfigAlphaBits(8);
2729 }
2730
2731 ~TextureLimitsTest()
2732 {
2733 if (mProgram != 0)
2734 {
2735 glDeleteProgram(mProgram);
2736 mProgram = 0;
2737
2738 if (!mTextures.empty())
2739 {
2740 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
2741 }
2742 }
2743 }
2744
2745 void SetUp() override
2746 {
2747 ANGLETest::SetUp();
2748
2749 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
2750 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
2751 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
2752
2753 ASSERT_GL_NO_ERROR();
2754 }
2755
2756 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
2757 GLint vertexTextureCount,
2758 GLint vertexActiveTextureCount,
2759 const std::string &fragPrefix,
2760 GLint fragmentTextureCount,
2761 GLint fragmentActiveTextureCount)
2762 {
2763 std::stringstream vertexShaderStr;
2764 vertexShaderStr << "attribute vec2 position;\n"
2765 << "varying vec4 color;\n"
2766 << "varying vec2 texCoord;\n";
2767
2768 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
2769 {
2770 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
2771 }
2772
2773 vertexShaderStr << "void main() {\n"
2774 << " gl_Position = vec4(position, 0, 1);\n"
2775 << " texCoord = (position * 0.5) + 0.5;\n"
2776 << " color = vec4(0);\n";
2777
2778 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
2779 {
2780 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
2781 << ", texCoord);\n";
2782 }
2783
2784 vertexShaderStr << "}";
2785
2786 std::stringstream fragmentShaderStr;
2787 fragmentShaderStr << "varying mediump vec4 color;\n"
2788 << "varying mediump vec2 texCoord;\n";
2789
2790 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
2791 {
2792 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
2793 }
2794
2795 fragmentShaderStr << "void main() {\n"
2796 << " gl_FragColor = color;\n";
2797
2798 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
2799 {
2800 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
2801 << ", texCoord);\n";
2802 }
2803
2804 fragmentShaderStr << "}";
2805
2806 const std::string &vertexShaderSource = vertexShaderStr.str();
2807 const std::string &fragmentShaderSource = fragmentShaderStr.str();
2808
2809 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
2810 }
2811
2812 RGBA8 getPixel(GLint texIndex)
2813 {
2814 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
2815 0, 255u};
2816 return pixel;
2817 }
2818
2819 void initTextures(GLint tex2DCount, GLint texCubeCount)
2820 {
2821 GLint totalCount = tex2DCount + texCubeCount;
2822 mTextures.assign(totalCount, 0);
2823 glGenTextures(totalCount, &mTextures[0]);
2824 ASSERT_GL_NO_ERROR();
2825
2826 std::vector<RGBA8> texData(16 * 16);
2827
2828 GLint texIndex = 0;
2829 for (; texIndex < tex2DCount; ++texIndex)
2830 {
2831 texData.assign(texData.size(), getPixel(texIndex));
2832 glActiveTexture(GL_TEXTURE0 + texIndex);
2833 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
2834 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2835 &texData[0]);
2836 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2837 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2838 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2839 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2840 }
2841
2842 ASSERT_GL_NO_ERROR();
2843
2844 for (; texIndex < texCubeCount; ++texIndex)
2845 {
2846 texData.assign(texData.size(), getPixel(texIndex));
2847 glActiveTexture(GL_TEXTURE0 + texIndex);
2848 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
2849 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2850 GL_UNSIGNED_BYTE, &texData[0]);
2851 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2852 GL_UNSIGNED_BYTE, &texData[0]);
2853 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2854 GL_UNSIGNED_BYTE, &texData[0]);
2855 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2856 GL_UNSIGNED_BYTE, &texData[0]);
2857 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2858 GL_UNSIGNED_BYTE, &texData[0]);
2859 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2860 GL_UNSIGNED_BYTE, &texData[0]);
2861 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2862 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2863 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2864 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2865 }
2866
2867 ASSERT_GL_NO_ERROR();
2868 }
2869
2870 void testWithTextures(GLint vertexTextureCount,
2871 const std::string &vertexTexturePrefix,
2872 GLint fragmentTextureCount,
2873 const std::string &fragmentTexturePrefix)
2874 {
2875 // Generate textures
2876 initTextures(vertexTextureCount + fragmentTextureCount, 0);
2877
2878 glUseProgram(mProgram);
2879 RGBA8 expectedSum = {0};
2880 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
2881 {
2882 std::stringstream uniformNameStr;
2883 uniformNameStr << vertexTexturePrefix << texIndex;
2884 const std::string &uniformName = uniformNameStr.str();
2885 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
2886 ASSERT_NE(-1, location);
2887
2888 glUniform1i(location, texIndex);
2889 RGBA8 contribution = getPixel(texIndex);
2890 expectedSum.R += contribution.R;
2891 expectedSum.G += contribution.G;
2892 }
2893
2894 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
2895 {
2896 std::stringstream uniformNameStr;
2897 uniformNameStr << fragmentTexturePrefix << texIndex;
2898 const std::string &uniformName = uniformNameStr.str();
2899 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
2900 ASSERT_NE(-1, location);
2901
2902 glUniform1i(location, texIndex + vertexTextureCount);
2903 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
2904 expectedSum.R += contribution.R;
2905 expectedSum.G += contribution.G;
2906 }
2907
2908 ASSERT_GE(256u, expectedSum.G);
2909
2910 drawQuad(mProgram, "position", 0.5f);
2911 ASSERT_GL_NO_ERROR();
2912 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
2913 }
2914
2915 GLuint mProgram;
2916 std::vector<GLuint> mTextures;
2917 GLint mMaxVertexTextures;
2918 GLint mMaxFragmentTextures;
2919 GLint mMaxCombinedTextures;
2920};
2921
2922// Test rendering with the maximum vertex texture units.
2923TEST_P(TextureLimitsTest, MaxVertexTextures)
2924{
2925 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
2926 ASSERT_NE(0u, mProgram);
2927 ASSERT_GL_NO_ERROR();
2928
2929 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
2930}
2931
2932// Test rendering with the maximum fragment texture units.
2933TEST_P(TextureLimitsTest, MaxFragmentTextures)
2934{
2935 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
2936 ASSERT_NE(0u, mProgram);
2937 ASSERT_GL_NO_ERROR();
2938
2939 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
2940}
2941
2942// Test rendering with maximum combined texture units.
2943TEST_P(TextureLimitsTest, MaxCombinedTextures)
2944{
2945 GLint vertexTextures = mMaxVertexTextures;
2946
2947 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
2948 {
2949 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
2950 }
2951
2952 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
2953 mMaxFragmentTextures, mMaxFragmentTextures);
2954 ASSERT_NE(0u, mProgram);
2955 ASSERT_GL_NO_ERROR();
2956
2957 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
2958}
2959
2960// Negative test for exceeding the number of vertex textures
2961TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
2962{
2963 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
2964 0);
2965 ASSERT_EQ(0u, mProgram);
2966}
2967
2968// Negative test for exceeding the number of fragment textures
2969TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
2970{
2971 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
2972 mMaxFragmentTextures + 1);
2973 ASSERT_EQ(0u, mProgram);
2974}
2975
2976// Test active vertex textures under the limit, but excessive textures specified.
2977TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
2978{
2979 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
2980 ASSERT_NE(0u, mProgram);
2981 ASSERT_GL_NO_ERROR();
2982
2983 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
2984}
2985
2986// Test active fragment textures under the limit, but excessive textures specified.
2987TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
2988{
2989 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
2990 mMaxFragmentTextures);
2991 ASSERT_NE(0u, mProgram);
2992 ASSERT_GL_NO_ERROR();
2993
2994 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
2995}
2996
2997// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002998// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002999TEST_P(TextureLimitsTest, TextureTypeConflict)
3000{
3001 const std::string &vertexShader =
3002 "attribute vec2 position;\n"
3003 "varying float color;\n"
3004 "uniform sampler2D tex2D;\n"
3005 "uniform samplerCube texCube;\n"
3006 "void main() {\n"
3007 " gl_Position = vec4(position, 0, 1);\n"
3008 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3009 " color = texture2D(tex2D, texCoord).x;\n"
3010 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3011 "}";
3012 const std::string &fragmentShader =
3013 "varying mediump float color;\n"
3014 "void main() {\n"
3015 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3016 "}";
3017
3018 mProgram = CompileProgram(vertexShader, fragmentShader);
3019 ASSERT_NE(0u, mProgram);
3020
3021 initTextures(1, 0);
3022
3023 glUseProgram(mProgram);
3024 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3025 ASSERT_NE(-1, tex2DLocation);
3026 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3027 ASSERT_NE(-1, texCubeLocation);
3028
3029 glUniform1i(tex2DLocation, 0);
3030 glUniform1i(texCubeLocation, 0);
3031 ASSERT_GL_NO_ERROR();
3032
3033 drawQuad(mProgram, "position", 0.5f);
3034 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3035}
3036
Vincent Lang25ab4512016-05-13 18:13:59 +02003037class Texture2DNorm16TestES3 : public Texture2DTestES3
3038{
3039 protected:
3040 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3041
3042 void SetUp() override
3043 {
3044 Texture2DTestES3::SetUp();
3045
3046 glActiveTexture(GL_TEXTURE0);
3047 glGenTextures(3, mTextures);
3048 glGenFramebuffers(1, &mFBO);
3049 glGenRenderbuffers(1, &mRenderbuffer);
3050
3051 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3052 {
3053 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3054 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3055 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3056 }
3057
3058 glBindTexture(GL_TEXTURE_2D, 0);
3059
3060 ASSERT_GL_NO_ERROR();
3061 }
3062
3063 void TearDown() override
3064 {
3065 glDeleteTextures(3, mTextures);
3066 glDeleteFramebuffers(1, &mFBO);
3067 glDeleteRenderbuffers(1, &mRenderbuffer);
3068
3069 Texture2DTestES3::TearDown();
3070 }
3071
3072 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3073 {
Geoff Langf607c602016-09-21 11:46:48 -04003074 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3075 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003076
3077 setUpProgram();
3078
3079 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3080 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3081 0);
3082
3083 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3084 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3085
3086 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003087 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003088
3089 EXPECT_GL_NO_ERROR();
3090
3091 drawQuad(mProgram, "position", 0.5f);
3092
Geoff Langf607c602016-09-21 11:46:48 -04003093 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003094
Geoff Langf607c602016-09-21 11:46:48 -04003095 EXPECT_PIXEL_COLOR_EQ(
3096 0, 0, SliceFormatColor(
3097 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003098
3099 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3100
3101 ASSERT_GL_NO_ERROR();
3102 }
3103
3104 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3105 {
3106 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003107 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003108
3109 setUpProgram();
3110
3111 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3112 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3113
3114 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3115 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3116 0);
3117
3118 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003119 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003120
3121 EXPECT_GL_NO_ERROR();
3122
3123 drawQuad(mProgram, "position", 0.5f);
3124
Geoff Langf607c602016-09-21 11:46:48 -04003125 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
3126 EXPECT_PIXEL_COLOR_EQ(
3127 0, 0, SliceFormatColor(
3128 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003129
3130 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3131 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3132 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3133 mRenderbuffer);
3134 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3135 EXPECT_GL_NO_ERROR();
3136
3137 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3138 glClear(GL_COLOR_BUFFER_BIT);
3139
3140 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3141
Geoff Langf607c602016-09-21 11:46:48 -04003142 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003143
3144 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3145
3146 ASSERT_GL_NO_ERROR();
3147 }
3148
3149 GLuint mTextures[3];
3150 GLuint mFBO;
3151 GLuint mRenderbuffer;
3152};
3153
3154// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3155TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3156{
Yunchao He9550c602018-02-13 14:47:05 +08003157 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02003158
3159 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3160 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3161 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3162 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3163 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3164 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3165 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3166 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3167
3168 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3169 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3170 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3171}
3172
Olli Etuaho95faa232016-06-07 14:01:53 -07003173// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3174// GLES 3.0.4 section 3.8.3.
3175TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3176{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08003177 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
3178
Yuly Novikov3c754192016-06-27 19:36:41 -04003179 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1429 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08003180 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07003181
3182 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3183 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3184 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3185 ASSERT_GL_NO_ERROR();
3186
3187 // SKIP_IMAGES should not have an effect on uploading 2D textures
3188 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3189 ASSERT_GL_NO_ERROR();
3190
3191 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3192
3193 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3194 pixelsGreen.data());
3195 ASSERT_GL_NO_ERROR();
3196
3197 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3198 pixelsGreen.data());
3199 ASSERT_GL_NO_ERROR();
3200
3201 glUseProgram(mProgram);
3202 drawQuad(mProgram, "position", 0.5f);
3203 ASSERT_GL_NO_ERROR();
3204
3205 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3206}
3207
Olli Etuaho989cac32016-06-08 16:18:49 -07003208// Test that skip defined in unpack parameters is taken into account when determining whether
3209// unpacking source extends outside unpack buffer bounds.
3210TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3211{
3212 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3213 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3214 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3215 ASSERT_GL_NO_ERROR();
3216
3217 GLBuffer buf;
3218 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3219 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3220 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3221 GL_DYNAMIC_COPY);
3222 ASSERT_GL_NO_ERROR();
3223
3224 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3225 ASSERT_GL_NO_ERROR();
3226
3227 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3228 ASSERT_GL_NO_ERROR();
3229
3230 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3231 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3232
3233 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3234 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3235 ASSERT_GL_NO_ERROR();
3236
3237 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3238 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3239}
3240
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003241// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3242TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3243{
Yunchao He9550c602018-02-13 14:47:05 +08003244 ANGLE_SKIP_TEST_IF(IsD3D11());
3245
3246 // Incorrect rendering results seen on OSX AMD.
3247 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003248
3249 const GLuint width = 8u;
3250 const GLuint height = 8u;
3251 const GLuint unpackRowLength = 5u;
3252 const GLuint unpackSkipPixels = 1u;
3253
3254 setWindowWidth(width);
3255 setWindowHeight(height);
3256
3257 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3258 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3259 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3260 ASSERT_GL_NO_ERROR();
3261
3262 GLBuffer buf;
3263 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3264 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3265 GLColor::green);
3266
3267 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3268 {
3269 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3270 }
3271
3272 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3273 GL_DYNAMIC_COPY);
3274 ASSERT_GL_NO_ERROR();
3275
3276 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3277 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3278 ASSERT_GL_NO_ERROR();
3279
3280 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3281 ASSERT_GL_NO_ERROR();
3282
3283 glUseProgram(mProgram);
3284 drawQuad(mProgram, "position", 0.5f);
3285 ASSERT_GL_NO_ERROR();
3286
3287 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3288 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3289 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3290 actual.data());
3291 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3292 EXPECT_EQ(expected, actual);
3293}
3294
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003295template <typename T>
3296T UNorm(double value)
3297{
3298 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3299}
3300
3301// Test rendering a depth texture with mipmaps.
3302TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3303{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003304 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3305 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
3306 // http://anglebugs.com/1706
Yunchao He9550c602018-02-13 14:47:05 +08003307 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows());
Corentin Walleze731d8a2016-09-07 10:56:25 -04003308
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003309 const int size = getWindowWidth();
3310
3311 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003312 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003313
3314 glActiveTexture(GL_TEXTURE0);
3315 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3316 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3317 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3318 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3319 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3320 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3321 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3322 ASSERT_GL_NO_ERROR();
3323
3324 glUseProgram(mProgram);
3325 glUniform1i(mTexture2DUniformLocation, 0);
3326
3327 std::vector<unsigned char> expected;
3328
3329 for (int level = 0; level < levels; ++level)
3330 {
3331 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3332 expected.push_back(UNorm<unsigned char>(value));
3333
3334 int levelDim = dim(level);
3335
3336 ASSERT_GT(levelDim, 0);
3337
3338 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3339 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3340 GL_UNSIGNED_INT, initData.data());
3341 }
3342 ASSERT_GL_NO_ERROR();
3343
3344 for (int level = 0; level < levels; ++level)
3345 {
3346 glViewport(0, 0, dim(level), dim(level));
3347 drawQuad(mProgram, "position", 0.5f);
3348 GLColor actual = ReadColor(0, 0);
3349 EXPECT_NEAR(expected[level], actual.R, 10u);
3350 }
3351
3352 ASSERT_GL_NO_ERROR();
3353}
3354
Jamie Madill7ffdda92016-09-08 13:26:51 -04003355// Tests unpacking into the unsized GL_ALPHA format.
3356TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3357{
Jamie Madill7ffdda92016-09-08 13:26:51 -04003358 // Initialize the texure.
3359 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3360 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3361 GL_UNSIGNED_BYTE, nullptr);
3362 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3363 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3364
3365 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3366
3367 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04003368 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04003369 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3370 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3371 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
3372 GL_STATIC_DRAW);
3373
3374 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
3375 GL_UNSIGNED_BYTE, nullptr);
3376
3377 // Clear to a weird color to make sure we're drawing something.
3378 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
3379 glClear(GL_COLOR_BUFFER_BIT);
3380
3381 // Draw with the alpha texture and verify.
3382 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04003383
3384 ASSERT_GL_NO_ERROR();
3385 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
3386}
3387
Jamie Madill2e600342016-09-19 13:56:40 -04003388// Ensure stale unpack data doesn't propagate in D3D11.
3389TEST_P(Texture2DTestES3, StaleUnpackData)
3390{
3391 // Init unpack buffer.
3392 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
3393 std::vector<GLColor> pixels(pixelCount, GLColor::red);
3394
3395 GLBuffer unpackBuffer;
3396 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3397 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3398 GLsizei bufferSize = pixelCount * sizeof(GLColor);
3399 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
3400
3401 // Create from unpack buffer.
3402 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3403 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
3404 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3405 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3406 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3407
3408 drawQuad(mProgram, "position", 0.5f);
3409
3410 ASSERT_GL_NO_ERROR();
3411 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3412
3413 // Fill unpack with green, recreating buffer.
3414 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
3415 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
3416 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
3417
3418 // Reinit texture with green.
3419 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
3420 GL_UNSIGNED_BYTE, nullptr);
3421
3422 drawQuad(mProgram, "position", 0.5f);
3423
3424 ASSERT_GL_NO_ERROR();
3425 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3426}
3427
Geoff Langfb7685f2017-11-13 11:44:11 -05003428// Ensure that texture parameters passed as floats that are converted to ints are rounded before
3429// validating they are less than 0.
3430TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
3431{
3432 GLTexture texture;
3433 glBindTexture(GL_TEXTURE_2D, texture);
3434
3435 // Use a negative number that will round to zero when converted to an integer
3436 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
3437 // "Validation of values performed by state-setting commands is performed after conversion,
3438 // unless specified otherwise for a specific command."
3439 GLfloat param = -7.30157126e-07f;
3440 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
3441 EXPECT_GL_NO_ERROR();
3442
3443 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
3444 EXPECT_GL_NO_ERROR();
3445}
3446
Jamie Madillf097e232016-11-05 00:44:15 -04003447// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
3448// being properly checked, and the texture storage of the previous texture format was persisting.
3449// This would result in an ASSERT in debug and incorrect rendering in release.
3450// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
3451TEST_P(Texture3DTestES3, FormatRedefinitionBug)
3452{
3453 GLTexture tex;
3454 glBindTexture(GL_TEXTURE_3D, tex.get());
3455 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3456
3457 GLFramebuffer framebuffer;
3458 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3459 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
3460
3461 glCheckFramebufferStatus(GL_FRAMEBUFFER);
3462
3463 std::vector<uint8_t> pixelData(100, 0);
3464
3465 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
3466 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
3467 pixelData.data());
3468
3469 ASSERT_GL_NO_ERROR();
3470}
3471
Corentin Wallezd2627992017-04-28 17:17:03 -04003472// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
3473TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
3474{
3475 // 2D tests
3476 {
3477 GLTexture tex;
3478 glBindTexture(GL_TEXTURE_2D, tex.get());
3479
3480 GLBuffer pbo;
3481 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3482
3483 // Test OOB
3484 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
3485 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3486 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3487
3488 // Test OOB
3489 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
3490 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3491 ASSERT_GL_NO_ERROR();
3492 }
3493
3494 // 3D tests
3495 {
3496 GLTexture tex;
3497 glBindTexture(GL_TEXTURE_3D, tex.get());
3498
3499 GLBuffer pbo;
3500 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3501
3502 // Test OOB
3503 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
3504 GL_STATIC_DRAW);
3505 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3506 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3507
3508 // Test OOB
3509 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
3510 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3511 ASSERT_GL_NO_ERROR();
3512 }
3513}
3514
Jamie Madill3ed60422017-09-07 11:32:52 -04003515// Tests behaviour with a single texture and multiple sampler objects.
3516TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
3517{
3518 GLint maxTextureUnits = 0;
3519 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
3520 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
3521
3522 constexpr int kSize = 16;
3523
3524 // Make a single-level texture, fill it with red.
3525 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
3526 GLTexture tex;
3527 glBindTexture(GL_TEXTURE_2D, tex);
3528 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3529 redColors.data());
3530 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3531 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3532
3533 // Simple sanity check.
3534 draw2DTexturedQuad(0.5f, 1.0f, true);
3535 ASSERT_GL_NO_ERROR();
3536 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3537
3538 // Bind texture to unit 1 with a sampler object making it incomplete.
3539 GLSampler sampler;
3540 glBindSampler(0, sampler);
3541 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3542 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3543
3544 // Make a mipmap texture, fill it with blue.
3545 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
3546 GLTexture mipmapTex;
3547 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3548 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3549 blueColors.data());
3550 glGenerateMipmap(GL_TEXTURE_2D);
3551
3552 // Draw with the sampler, expect blue.
3553 draw2DTexturedQuad(0.5f, 1.0f, true);
3554 ASSERT_GL_NO_ERROR();
3555 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
3556
3557 // Simple multitexturing program.
3558 const std::string vs =
3559 "#version 300 es\n"
3560 "in vec2 position;\n"
3561 "out vec2 texCoord;\n"
3562 "void main()\n"
3563 "{\n"
3564 " gl_Position = vec4(position, 0, 1);\n"
3565 " texCoord = position * 0.5 + vec2(0.5);\n"
3566 "}";
3567 const std::string fs =
3568 "#version 300 es\n"
3569 "precision mediump float;\n"
3570 "in vec2 texCoord;\n"
3571 "uniform sampler2D tex1;\n"
3572 "uniform sampler2D tex2;\n"
3573 "uniform sampler2D tex3;\n"
3574 "uniform sampler2D tex4;\n"
3575 "out vec4 color;\n"
3576 "void main()\n"
3577 "{\n"
3578 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
3579 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
3580 "}";
3581
3582 ANGLE_GL_PROGRAM(program, vs, fs);
3583
3584 std::array<GLint, 4> texLocations = {
3585 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
3586 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
3587 for (GLint location : texLocations)
3588 {
3589 ASSERT_NE(-1, location);
3590 }
3591
3592 // Init the uniform data.
3593 glUseProgram(program);
3594 for (GLint location = 0; location < 4; ++location)
3595 {
3596 glUniform1i(texLocations[location], location);
3597 }
3598
3599 // Initialize four samplers
3600 GLSampler samplers[4];
3601
3602 // 0: non-mipped.
3603 glBindSampler(0, samplers[0]);
3604 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3605 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3606
3607 // 1: mipped.
3608 glBindSampler(1, samplers[1]);
3609 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3610 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3611
3612 // 2: non-mipped.
3613 glBindSampler(2, samplers[2]);
3614 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3615 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3616
3617 // 3: mipped.
3618 glBindSampler(3, samplers[3]);
3619 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3620 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3621
3622 // Bind two blue mipped textures and two single layer textures, should all draw.
3623 glActiveTexture(GL_TEXTURE0);
3624 glBindTexture(GL_TEXTURE_2D, tex);
3625
3626 glActiveTexture(GL_TEXTURE1);
3627 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3628
3629 glActiveTexture(GL_TEXTURE2);
3630 glBindTexture(GL_TEXTURE_2D, tex);
3631
3632 glActiveTexture(GL_TEXTURE3);
3633 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3634
3635 ASSERT_GL_NO_ERROR();
3636
3637 drawQuad(program, "position", 0.5f);
3638 ASSERT_GL_NO_ERROR();
3639 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
3640
3641 // Bind four single layer textures, two should be incomplete.
3642 glActiveTexture(GL_TEXTURE1);
3643 glBindTexture(GL_TEXTURE_2D, tex);
3644
3645 glActiveTexture(GL_TEXTURE3);
3646 glBindTexture(GL_TEXTURE_2D, tex);
3647
3648 drawQuad(program, "position", 0.5f);
3649 ASSERT_GL_NO_ERROR();
3650 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
3651}
3652
Martin Radev7e2c0d32017-09-15 14:25:42 +03003653// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
3654// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
3655// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
3656// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
3657// samples the cubemap using a direction vector (1,1,1).
3658TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
3659{
Yunchao He2f23f352018-02-11 22:11:37 +08003660 // Check http://anglebug.com/2155.
3661 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
3662
Martin Radev7e2c0d32017-09-15 14:25:42 +03003663 const std::string vs =
3664 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003665 precision mediump float;
3666 in vec3 pos;
3667 void main() {
3668 gl_Position = vec4(pos, 1.0);
3669 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003670
3671 const std::string fs =
3672 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003673 precision mediump float;
3674 out vec4 color;
3675 uniform samplerCube uTex;
3676 void main(){
3677 color = texture(uTex, vec3(1.0));
3678 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003679 ANGLE_GL_PROGRAM(program, vs, fs);
3680 glUseProgram(program);
3681
3682 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
3683 glActiveTexture(GL_TEXTURE0);
3684
3685 GLTexture cubeTex;
3686 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
3687
3688 const int kFaceWidth = 1;
3689 const int kFaceHeight = 1;
3690 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
3691 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3692 GL_UNSIGNED_BYTE, texData.data());
3693 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3694 GL_UNSIGNED_BYTE, texData.data());
3695 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3696 GL_UNSIGNED_BYTE, texData.data());
3697 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3698 GL_UNSIGNED_BYTE, texData.data());
3699 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3700 GL_UNSIGNED_BYTE, texData.data());
3701 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3702 GL_UNSIGNED_BYTE, texData.data());
3703 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3704 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3705 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
3706 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
3707 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
3708 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
3709
3710 drawQuad(program, "pos", 0.5f, 1.0f, true);
3711 ASSERT_GL_NO_ERROR();
3712
3713 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
3714}
3715
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08003716// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
3717TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
3718{
3719 GLuint texture = create2DTexture();
3720
3721 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
3722 EXPECT_GL_ERROR(GL_INVALID_VALUE);
3723
3724 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
3725 EXPECT_GL_ERROR(GL_INVALID_VALUE);
3726
3727 glDeleteTextures(1, &texture);
3728 EXPECT_GL_NO_ERROR();
3729}
3730
Jamie Madillfa05f602015-05-07 13:47:11 -04003731// 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 +02003732// TODO(oetuaho): Enable all below tests on OpenGL. Requires a fix for ANGLE bug 1278.
Geoff Lange0cc2a42016-01-20 10:58:17 -05003733ANGLE_INSTANTIATE_TEST(Texture2DTest,
3734 ES2_D3D9(),
3735 ES2_D3D11(),
3736 ES2_D3D11_FL9_3(),
3737 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05003738 ES2_OPENGLES(),
3739 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003740ANGLE_INSTANTIATE_TEST(TextureCubeTest,
3741 ES2_D3D9(),
3742 ES2_D3D11(),
Geoff Langf7480ad2017-10-24 11:46:02 -04003743 ES2_D3D11_FL10_0(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003744 ES2_D3D11_FL9_3(),
3745 ES2_OPENGL(),
3746 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003747ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
3748 ES2_D3D9(),
3749 ES2_D3D11(),
3750 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003751 ES2_OPENGL(),
3752 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003753ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
3754 ES2_D3D9(),
3755 ES2_D3D11(),
3756 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003757 ES2_OPENGL(),
3758 ES2_OPENGLES());
3759ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
3760 ES2_D3D9(),
3761 ES2_D3D11(),
3762 ES2_D3D11_FL9_3(),
3763 ES2_OPENGL(),
3764 ES2_OPENGLES());
3765ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
3766 ES2_D3D9(),
3767 ES2_D3D11(),
3768 ES2_D3D11_FL9_3(),
3769 ES2_OPENGL(),
3770 ES2_OPENGLES());
3771ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02003772ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003773ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3774ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
3775 ES3_D3D11(),
3776 ES3_OPENGL(),
3777 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003778ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
3779 ES3_D3D11(),
3780 ES3_OPENGL(),
3781 ES3_OPENGLES());
3782ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3783ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02003784ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02003785ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
3786 ES2_D3D11(),
3787 ES2_D3D11_FL9_3(),
3788 ES2_D3D9(),
3789 ES2_OPENGL(),
3790 ES2_OPENGLES());
3791ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
3792 ES2_D3D11(),
3793 ES2_D3D11_FL9_3(),
3794 ES2_D3D9(),
3795 ES2_OPENGL(),
3796 ES2_OPENGLES());
3797ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
3798 ES2_D3D11(),
3799 ES2_D3D11_FL9_3(),
3800 ES2_D3D9(),
3801 ES2_OPENGL(),
3802 ES2_OPENGLES());
3803ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
3804 ES2_D3D11(),
3805 ES2_D3D11_FL9_3(),
3806 ES2_D3D9(),
3807 ES2_OPENGL(),
3808 ES2_OPENGLES());
3809ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
3810 ES2_D3D11(),
3811 ES2_D3D11_FL9_3(),
3812 ES2_D3D9(),
3813 ES2_OPENGL(),
3814 ES2_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003815ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES());
Vincent Lang25ab4512016-05-13 18:13:59 +02003816ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03003817ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04003818
Jamie Madill7ffdda92016-09-08 13:26:51 -04003819} // anonymous namespace