blob: 01f58e281e65403ca034785ccef955a4d93ab294 [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{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001240 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001241 EXPECT_GL_ERROR(GL_NO_ERROR);
1242
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001243 setUpProgram();
1244
Geoff Langc41e42d2014-04-28 10:58:16 -04001245 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001246 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001247 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001248 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001249
1250 const GLubyte *pixel[4] = { 0 };
1251
1252 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1253 EXPECT_GL_NO_ERROR();
1254
1255 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1256 EXPECT_GL_NO_ERROR();
1257
1258 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1259 EXPECT_GL_NO_ERROR();
1260}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001261
1262// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001263TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001264{
1265 glActiveTexture(GL_TEXTURE0);
1266 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1267 glActiveTexture(GL_TEXTURE1);
1268 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1269 EXPECT_GL_ERROR(GL_NO_ERROR);
1270
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001271 glUseProgram(mProgram);
1272 glUniform1i(mTexture2DUniformLocation, 0);
1273 glUniform1i(mTextureCubeUniformLocation, 1);
1274 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001275 EXPECT_GL_NO_ERROR();
1276}
Jamie Madill9aca0592014-10-06 16:26:59 -04001277
Olli Etuaho53a2da12016-01-11 15:43:32 +02001278// Test drawing with two texture types accessed from the same shader and check that the result of
1279// drawing is correct.
1280TEST_P(TextureCubeTest, CubeMapDraw)
1281{
1282 GLubyte texData[4];
1283 texData[0] = 0;
1284 texData[1] = 60;
1285 texData[2] = 0;
1286 texData[3] = 255;
1287
1288 glActiveTexture(GL_TEXTURE0);
1289 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1290 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1291
1292 glActiveTexture(GL_TEXTURE1);
1293 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1294 texData[1] = 120;
1295 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1296 texData);
1297 EXPECT_GL_ERROR(GL_NO_ERROR);
1298
1299 glUseProgram(mProgram);
1300 glUniform1i(mTexture2DUniformLocation, 0);
1301 glUniform1i(mTextureCubeUniformLocation, 1);
1302 drawQuad(mProgram, "position", 0.5f);
1303 EXPECT_GL_NO_ERROR();
1304
1305 int px = getWindowWidth() - 1;
1306 int py = 0;
1307 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1308}
1309
Olli Etuaho4644a202016-01-12 15:12:53 +02001310TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1311{
1312 glActiveTexture(GL_TEXTURE0);
1313 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1314 GLubyte texData[4];
1315 texData[0] = 0;
1316 texData[1] = 128;
1317 texData[2] = 0;
1318 texData[3] = 255;
1319 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1320 glUseProgram(mProgram);
1321 glUniform1i(mTexture2DUniformLocation, 0);
1322 drawQuad(mProgram, "position", 0.5f);
1323 EXPECT_GL_NO_ERROR();
1324
1325 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1326}
1327
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001328// Test drawing with two textures passed to the shader in a sampler array.
1329TEST_P(SamplerArrayTest, SamplerArrayDraw)
1330{
1331 testSamplerArrayDraw();
1332}
1333
1334// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1335// user-defined function in the shader.
1336TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1337{
1338 testSamplerArrayDraw();
1339}
1340
Jamie Madill9aca0592014-10-06 16:26:59 -04001341// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001342TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001343{
1344 int px = getWindowWidth() / 2;
1345 int py = getWindowHeight() / 2;
1346
1347 glActiveTexture(GL_TEXTURE0);
1348 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1349
Olli Etuahoa314b612016-03-10 16:43:00 +02001350 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001351
Olli Etuahoa314b612016-03-10 16:43:00 +02001352 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001353 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1354 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1355 glGenerateMipmap(GL_TEXTURE_2D);
1356
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001357 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001358 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001359 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1360 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001361 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001362 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001363
Olli Etuahoa314b612016-03-10 16:43:00 +02001364 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001365
Olli Etuahoa314b612016-03-10 16:43:00 +02001366 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1367 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001368 glGenerateMipmap(GL_TEXTURE_2D);
1369
Olli Etuahoa314b612016-03-10 16:43:00 +02001370 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001371
Olli Etuahoa314b612016-03-10 16:43:00 +02001372 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1373 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001374 glGenerateMipmap(GL_TEXTURE_2D);
1375
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001376 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001377
1378 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001379 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001380}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001381
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001382// Test creating a FBO with a cube map render target, to test an ANGLE bug
1383// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001384TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001385{
1386 GLuint fbo;
1387 glGenFramebuffers(1, &fbo);
1388 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1389
1390 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1391 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mTextureCube, 0);
1392
Corentin Wallez322653b2015-06-17 18:33:56 +02001393 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001394
1395 glDeleteFramebuffers(1, &fbo);
1396
1397 EXPECT_GL_NO_ERROR();
1398}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001399
1400// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001401TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001402{
Yunchao He9550c602018-02-13 14:47:05 +08001403 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -04001404
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001405 int width = getWindowWidth();
1406 int height = getWindowHeight();
1407
1408 GLuint tex2D;
1409 glGenTextures(1, &tex2D);
1410 glActiveTexture(GL_TEXTURE0);
1411 glBindTexture(GL_TEXTURE_2D, tex2D);
1412
1413 // Fill with red
1414 std::vector<GLubyte> pixels(3 * 16 * 16);
1415 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1416 {
1417 pixels[pixelId * 3 + 0] = 255;
1418 pixels[pixelId * 3 + 1] = 0;
1419 pixels[pixelId * 3 + 2] = 0;
1420 }
1421
1422 // ANGLE internally uses RGBA as the DirectX format for RGB images
1423 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1424 // The data is kept in a CPU-side image and the image is marked as dirty.
Geoff Langc4e93662017-05-01 10:45:59 -04001425 if (getClientMajorVersion() >= 3)
1426 {
1427 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1428 }
1429 else
1430 {
1431 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1432 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001433
1434 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1435 // glTexSubImage2D should take into account that the image is dirty.
1436 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1437 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1438 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1439
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001440 setUpProgram();
1441
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001442 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001443 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001444 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001445 glDeleteTextures(1, &tex2D);
1446 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001447 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001448
1449 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001450 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1451 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001452}
1453
1454// 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 +02001455TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001456{
1457 if (extensionEnabled("NV_pixel_buffer_object"))
1458 {
1459 int width = getWindowWidth();
1460 int height = getWindowHeight();
1461
1462 GLuint tex2D;
1463 glGenTextures(1, &tex2D);
1464 glActiveTexture(GL_TEXTURE0);
1465 glBindTexture(GL_TEXTURE_2D, tex2D);
1466
1467 // Fill with red
1468 std::vector<GLubyte> pixels(3 * 16 * 16);
1469 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1470 {
1471 pixels[pixelId * 3 + 0] = 255;
1472 pixels[pixelId * 3 + 1] = 0;
1473 pixels[pixelId * 3 + 2] = 0;
1474 }
1475
1476 // Read 16x16 region from red backbuffer to PBO
1477 GLuint pbo;
1478 glGenBuffers(1, &pbo);
1479 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1480 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1481
1482 // ANGLE internally uses RGBA as the DirectX format for RGB images
1483 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1484 // The data is kept in a CPU-side image and the image is marked as dirty.
1485 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1486
1487 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1488 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001489 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 +00001490 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1491 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1492
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001493 setUpProgram();
1494
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001495 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001496 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001497 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001498 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001499 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001500 EXPECT_GL_NO_ERROR();
1501 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1502 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1503 }
1504}
Jamie Madillbc393df2015-01-29 13:46:07 -05001505
1506// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001507TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001508{
1509 testFloatCopySubImage(1, 1);
1510}
1511
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001512TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001513{
1514 testFloatCopySubImage(2, 1);
1515}
1516
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001517TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001518{
1519 testFloatCopySubImage(2, 2);
1520}
1521
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001522TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001523{
1524 testFloatCopySubImage(3, 1);
1525}
1526
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001527TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001528{
1529 testFloatCopySubImage(3, 2);
1530}
1531
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001532TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001533{
Yunchao He9550c602018-02-13 14:47:05 +08001534 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1535 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001536
Yunchao He9550c602018-02-13 14:47:05 +08001537 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1538 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001539
Jamie Madillbc393df2015-01-29 13:46:07 -05001540 testFloatCopySubImage(3, 3);
1541}
1542
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001543TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001544{
1545 testFloatCopySubImage(4, 1);
1546}
1547
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001548TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001549{
1550 testFloatCopySubImage(4, 2);
1551}
1552
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001553TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001554{
Yunchao He9550c602018-02-13 14:47:05 +08001555 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1556 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001557
Jamie Madillbc393df2015-01-29 13:46:07 -05001558 testFloatCopySubImage(4, 3);
1559}
1560
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001561TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001562{
Yunchao He9550c602018-02-13 14:47:05 +08001563 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1564 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001565
Jamie Madillbc393df2015-01-29 13:46:07 -05001566 testFloatCopySubImage(4, 4);
1567}
Austin Kinross07285142015-03-26 11:36:16 -07001568
1569// Port of https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1570// 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 +02001571TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001572{
1573 const int npotTexSize = 5;
1574 const int potTexSize = 4; // Should be less than npotTexSize
1575 GLuint tex2D;
1576
1577 if (extensionEnabled("GL_OES_texture_npot"))
1578 {
1579 // This test isn't applicable if texture_npot is enabled
1580 return;
1581 }
1582
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001583 setUpProgram();
1584
Austin Kinross07285142015-03-26 11:36:16 -07001585 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1586
Austin Kinross5faa15b2016-01-11 13:32:48 -08001587 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1588 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1589
Austin Kinross07285142015-03-26 11:36:16 -07001590 glActiveTexture(GL_TEXTURE0);
1591 glGenTextures(1, &tex2D);
1592 glBindTexture(GL_TEXTURE_2D, tex2D);
1593
1594 std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize);
1595 for (size_t pixelId = 0; pixelId < npotTexSize * npotTexSize; ++pixelId)
1596 {
1597 pixels[pixelId] = 64;
1598 }
1599
1600 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1601 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1602
1603 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
1604 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1605 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1606
1607 // Check that an NPOT texture on level 0 succeeds
1608 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1609 EXPECT_GL_NO_ERROR();
1610
1611 // Check that generateMipmap fails on NPOT
1612 glGenerateMipmap(GL_TEXTURE_2D);
1613 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1614
1615 // Check that nothing is drawn if filtering is not correct for NPOT
1616 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1617 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1618 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1619 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1620 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001621 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001622 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1623
1624 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1625 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1626 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1627 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1628 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001629 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001630 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1631
1632 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1633 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1634 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001635 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001636 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1637
1638 // Check that glTexImage2D for POT texture succeeds
1639 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1640 EXPECT_GL_NO_ERROR();
1641
1642 // Check that generateMipmap for an POT texture succeeds
1643 glGenerateMipmap(GL_TEXTURE_2D);
1644 EXPECT_GL_NO_ERROR();
1645
1646 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1647 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1648 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1649 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1650 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1651 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001652 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001653 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1654 EXPECT_GL_NO_ERROR();
1655}
Jamie Madillfa05f602015-05-07 13:47:11 -04001656
Austin Kinross08528e12015-10-07 16:24:40 -07001657// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1658// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001659TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001660{
1661 glActiveTexture(GL_TEXTURE0);
1662 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1663
1664 // Create an 8x8 (i.e. power-of-two) texture.
1665 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1666 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1667 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1668 glGenerateMipmap(GL_TEXTURE_2D);
1669
1670 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1671 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001672 std::array<GLColor, 3 * 3> data;
1673 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001674
1675 EXPECT_GL_NO_ERROR();
1676}
1677
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001678// Test to check that texture completeness is determined correctly when the texture base level is
1679// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1680TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1681{
1682 glActiveTexture(GL_TEXTURE0);
1683 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001684
1685 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1686 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1687 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1688 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1689 texDataGreen.data());
1690 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1691 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001692 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1693 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1694 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1695
1696 EXPECT_GL_NO_ERROR();
1697
1698 drawQuad(mProgram, "position", 0.5f);
1699
Olli Etuahoa314b612016-03-10 16:43:00 +02001700 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1701}
1702
1703// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1704// have images defined.
1705TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1706{
Yunchao He9550c602018-02-13 14:47:05 +08001707 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1708 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1709
Olli Etuahoa314b612016-03-10 16:43:00 +02001710 glActiveTexture(GL_TEXTURE0);
1711 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1712 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1713 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1714 texDataGreen.data());
1715 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1716 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1717 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1718 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1719
1720 EXPECT_GL_NO_ERROR();
1721
1722 drawQuad(mProgram, "position", 0.5f);
1723
1724 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1725}
1726
Olli Etuahoe8528d82016-05-16 17:50:52 +03001727// Test that drawing works correctly when level 0 is undefined and base level is 1.
1728TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1729{
Yunchao He9550c602018-02-13 14:47:05 +08001730 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1731 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1732
Olli Etuahoe8528d82016-05-16 17:50:52 +03001733 glActiveTexture(GL_TEXTURE0);
1734 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1735 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1736 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1737 texDataGreen.data());
1738 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1739 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1740 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1741 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1742
1743 EXPECT_GL_NO_ERROR();
1744
1745 // Texture is incomplete.
1746 drawQuad(mProgram, "position", 0.5f);
1747 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1748
1749 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1750 texDataGreen.data());
1751
1752 // Texture is now complete.
1753 drawQuad(mProgram, "position", 0.5f);
1754 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1755}
1756
Olli Etuahoa314b612016-03-10 16:43:00 +02001757// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1758// dimensions that don't fit the images inside the range.
1759// GLES 3.0.4 section 3.8.13 Texture completeness
1760TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1761{
Olli Etuahoa314b612016-03-10 16:43:00 +02001762 glActiveTexture(GL_TEXTURE0);
1763 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1764 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1765 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1766 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1767
1768 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1769 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1770
1771 // Two levels that are initially unused.
1772 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1773 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1774 texDataCyan.data());
1775
1776 // One level that is used - only this level should affect completeness.
1777 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1778 texDataGreen.data());
1779
1780 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1781 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1782
1783 EXPECT_GL_NO_ERROR();
1784
1785 drawQuad(mProgram, "position", 0.5f);
1786
1787 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1788
Yunchao He2f23f352018-02-11 22:11:37 +08001789 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001790
1791 // Switch the level that is being used to the cyan level 2.
1792 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1793 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1794
1795 EXPECT_GL_NO_ERROR();
1796
1797 drawQuad(mProgram, "position", 0.5f);
1798
1799 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1800}
1801
1802// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1803// have images defined.
1804TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1805{
Olli Etuahoa314b612016-03-10 16:43:00 +02001806 glActiveTexture(GL_TEXTURE0);
1807 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1808 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1809 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1810 texDataGreen.data());
1811 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1812 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1813 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1814 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1815
1816 EXPECT_GL_NO_ERROR();
1817
1818 drawQuad(mProgram, "position", 0.5f);
1819
1820 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1821}
1822
1823// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1824// dimensions that don't fit the images inside the range.
1825// GLES 3.0.4 section 3.8.13 Texture completeness
1826TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1827{
Olli Etuahoa314b612016-03-10 16:43:00 +02001828 glActiveTexture(GL_TEXTURE0);
1829 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1830 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1831 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1832 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1833
1834 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1835 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1836
1837 // Two levels that are initially unused.
1838 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1839 texDataRed.data());
1840 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1841 texDataCyan.data());
1842
1843 // One level that is used - only this level should affect completeness.
1844 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1845 texDataGreen.data());
1846
1847 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1848 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1849
1850 EXPECT_GL_NO_ERROR();
1851
1852 drawQuad(mProgram, "position", 0.5f);
1853
1854 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1855
Yunchao He2f23f352018-02-11 22:11:37 +08001856 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001857
1858 // Switch the level that is being used to the cyan level 2.
1859 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
1860 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
1861
1862 EXPECT_GL_NO_ERROR();
1863
1864 drawQuad(mProgram, "position", 0.5f);
1865
1866 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1867}
1868
1869// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1870// have images defined.
1871TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
1872{
Olli Etuahoa314b612016-03-10 16:43:00 +02001873 glActiveTexture(GL_TEXTURE0);
1874 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
1875 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1876 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1877 texDataGreen.data());
1878 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1879 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1880 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1881 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1882
1883 EXPECT_GL_NO_ERROR();
1884
1885 drawQuad(mProgram, "position", 0.5f);
1886
1887 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1888}
1889
1890// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1891// dimensions that don't fit the images inside the range.
1892// GLES 3.0.4 section 3.8.13 Texture completeness
1893TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1894{
Olli Etuahoa314b612016-03-10 16:43:00 +02001895 glActiveTexture(GL_TEXTURE0);
1896 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
1897 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1898 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1899 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1900
1901 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1902 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1903
1904 // Two levels that are initially unused.
1905 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1906 texDataRed.data());
1907 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1908 texDataCyan.data());
1909
1910 // One level that is used - only this level should affect completeness.
1911 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1912 texDataGreen.data());
1913
1914 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1915 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1916
1917 EXPECT_GL_NO_ERROR();
1918
1919 drawQuad(mProgram, "position", 0.5f);
1920
1921 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1922
Yunchao He2f23f352018-02-11 22:11:37 +08001923 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
1924
Yunchao He9550c602018-02-13 14:47:05 +08001925 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
1926 // level was changed.
1927 ANGLE_SKIP_TEST_IF(IsNVIDIA() && (IsOpenGL() || IsOpenGLES()));
Olli Etuahoa314b612016-03-10 16:43:00 +02001928
1929 // Switch the level that is being used to the cyan level 2.
1930 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
1931 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
1932
1933 EXPECT_GL_NO_ERROR();
1934
1935 drawQuad(mProgram, "position", 0.5f);
1936
1937 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1938}
1939
1940// Test that texture completeness is updated if texture max level changes.
1941// GLES 3.0.4 section 3.8.13 Texture completeness
1942TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
1943{
Olli Etuahoa314b612016-03-10 16:43:00 +02001944 glActiveTexture(GL_TEXTURE0);
1945 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1946 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
1947
1948 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1949 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1950
1951 // A level that is initially unused.
1952 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1953 texDataGreen.data());
1954
1955 // One level that is initially used - only this level should affect completeness.
1956 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1957 texDataGreen.data());
1958
1959 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
1960 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
1961
1962 EXPECT_GL_NO_ERROR();
1963
1964 drawQuad(mProgram, "position", 0.5f);
1965
1966 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1967
1968 // Switch the max level to level 1. The levels within the used range now have inconsistent
1969 // dimensions and the texture should be incomplete.
1970 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1971
1972 EXPECT_GL_NO_ERROR();
1973
1974 drawQuad(mProgram, "position", 0.5f);
1975
1976 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1977}
1978
1979// Test that 3D texture completeness is updated if texture max level changes.
1980// GLES 3.0.4 section 3.8.13 Texture completeness
1981TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
1982{
Olli Etuahoa314b612016-03-10 16:43:00 +02001983 glActiveTexture(GL_TEXTURE0);
1984 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1985 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1986
1987 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1988 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1989
1990 // A level that is initially unused.
1991 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1992 texDataGreen.data());
1993
1994 // One level that is initially used - only this level should affect completeness.
1995 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1996 texDataGreen.data());
1997
1998 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
1999 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2000
2001 EXPECT_GL_NO_ERROR();
2002
2003 drawQuad(mProgram, "position", 0.5f);
2004
2005 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2006
2007 // Switch the max level to level 1. The levels within the used range now have inconsistent
2008 // dimensions and the texture should be incomplete.
2009 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2010
2011 EXPECT_GL_NO_ERROR();
2012
2013 drawQuad(mProgram, "position", 0.5f);
2014
2015 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2016}
2017
2018// Test that texture completeness is updated if texture base level changes.
2019// GLES 3.0.4 section 3.8.13 Texture completeness
2020TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2021{
Olli Etuahoa314b612016-03-10 16:43:00 +02002022 glActiveTexture(GL_TEXTURE0);
2023 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2024 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2025
2026 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2027 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2028
2029 // Two levels that are initially unused.
2030 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2031 texDataGreen.data());
2032 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2033 texDataGreen.data());
2034
2035 // One level that is initially used - only this level should affect completeness.
2036 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2037 texDataGreen.data());
2038
2039 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2040 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2041
2042 EXPECT_GL_NO_ERROR();
2043
2044 drawQuad(mProgram, "position", 0.5f);
2045
2046 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2047
2048 // Switch the base level to level 1. The levels within the used range now have inconsistent
2049 // dimensions and the texture should be incomplete.
2050 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2051
2052 EXPECT_GL_NO_ERROR();
2053
2054 drawQuad(mProgram, "position", 0.5f);
2055
2056 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2057}
2058
2059// Test that texture is not complete if base level is greater than max level.
2060// GLES 3.0.4 section 3.8.13 Texture completeness
2061TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2062{
Olli Etuahoa314b612016-03-10 16:43:00 +02002063 glActiveTexture(GL_TEXTURE0);
2064 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2065
2066 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2067 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2068
2069 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2070
2071 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2072 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2073
2074 EXPECT_GL_NO_ERROR();
2075
2076 drawQuad(mProgram, "position", 0.5f);
2077
2078 // Texture should be incomplete.
2079 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2080}
2081
2082// Test that immutable texture base level and max level are clamped.
2083// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2084TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2085{
Olli Etuahoa314b612016-03-10 16:43:00 +02002086 glActiveTexture(GL_TEXTURE0);
2087 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2088
2089 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2090 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2091
2092 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2093
2094 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2095
2096 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2097 // should be clamped to [base_level, levels - 1].
2098 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2099 // In the case of this test, those rules make the effective base level and max level 0.
2100 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2101 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2102
2103 EXPECT_GL_NO_ERROR();
2104
2105 drawQuad(mProgram, "position", 0.5f);
2106
2107 // Texture should be complete.
2108 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2109}
2110
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002111// Test that changing base level works when it affects the format of the texture.
2112TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2113{
Yunchao He9550c602018-02-13 14:47:05 +08002114 // Observed rendering corruption on NVIDIA OpenGL.
2115 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL());
2116
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002117 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002118
2119 // Observed incorrect rendering on AMD OpenGL.
2120 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002121
2122 glActiveTexture(GL_TEXTURE0);
2123 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2124 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2125 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2126
2127 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2128 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2129
2130 // RGBA8 level that's initially unused.
2131 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2132 texDataCyan.data());
2133
2134 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2135 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2136
2137 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2138 // format. It reads green channel data from the green and alpha channels of texDataGreen
2139 // (this is a bit hacky but works).
2140 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2141
2142 EXPECT_GL_NO_ERROR();
2143
2144 drawQuad(mProgram, "position", 0.5f);
2145
2146 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2147
2148 // Switch the texture to use the cyan level 0 with the RGBA format.
2149 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2150 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2151
2152 EXPECT_GL_NO_ERROR();
2153
2154 drawQuad(mProgram, "position", 0.5f);
2155
2156 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2157}
2158
Olli Etuahoa314b612016-03-10 16:43:00 +02002159// Test that setting a texture image works when base level is out of range.
2160TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2161{
2162 glActiveTexture(GL_TEXTURE0);
2163 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2164
2165 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2166 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2167
2168 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2169 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2170
2171 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2172
2173 EXPECT_GL_NO_ERROR();
2174
2175 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2176
2177 drawQuad(mProgram, "position", 0.5f);
2178
2179 // Texture should be complete.
2180 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002181}
2182
Jamie Madill2453dbc2015-07-14 11:35:42 -04002183// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG RBA->RGBA8, with 1.0
2184// in the alpha channel. This test covers a bug where redefining array textures with these formats does not work as
2185// expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002186TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002187{
2188 std::vector<GLubyte> pixelData;
2189 for (size_t count = 0; count < 5000; count++)
2190 {
2191 pixelData.push_back(0u);
2192 pixelData.push_back(255u);
2193 pixelData.push_back(0u);
2194 }
2195
2196 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002197 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002198 glUniform1i(mTextureArrayLocation, 0);
2199
2200 // The first draw worked correctly.
2201 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
2202
2203 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2204 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2205 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2206 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002207 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002208 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002209
2210 // The dimension of the respecification must match the original exactly to trigger the bug.
2211 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 +02002212 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002213 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002214
2215 ASSERT_GL_NO_ERROR();
2216}
2217
Olli Etuaho1a679902016-01-14 12:21:47 +02002218// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2219// This test is needed especially to confirm that sampler registers get assigned correctly on
2220// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2221TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2222{
2223 glActiveTexture(GL_TEXTURE0);
2224 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2225 GLubyte texData[4];
2226 texData[0] = 0;
2227 texData[1] = 60;
2228 texData[2] = 0;
2229 texData[3] = 255;
2230 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2231
2232 glActiveTexture(GL_TEXTURE1);
2233 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2234 GLfloat depthTexData[1];
2235 depthTexData[0] = 0.5f;
2236 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2237 depthTexData);
2238
2239 glUseProgram(mProgram);
2240 glUniform1f(mDepthRefUniformLocation, 0.3f);
2241 glUniform1i(mTexture3DUniformLocation, 0);
2242 glUniform1i(mTextureShadowUniformLocation, 1);
2243
2244 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2245 drawQuad(mProgram, "position", 0.5f);
2246 EXPECT_GL_NO_ERROR();
2247 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2248 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2249
2250 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2251 drawQuad(mProgram, "position", 0.5f);
2252 EXPECT_GL_NO_ERROR();
2253 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2254 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2255}
2256
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002257// Test multiple different sampler types in the same shader.
2258// This test makes sure that even if sampler / texture registers get grouped together based on type
2259// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2260// still has the right register index information for each ESSL sampler.
2261// The tested ESSL samplers have the following types in D3D11 HLSL:
2262// sampler2D: Texture2D + SamplerState
2263// samplerCube: TextureCube + SamplerState
2264// sampler2DShadow: Texture2D + SamplerComparisonState
2265// samplerCubeShadow: TextureCube + SamplerComparisonState
2266TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2267{
2268 glActiveTexture(GL_TEXTURE0);
2269 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2270 GLubyte texData[4];
2271 texData[0] = 0;
2272 texData[1] = 0;
2273 texData[2] = 120;
2274 texData[3] = 255;
2275 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2276
2277 glActiveTexture(GL_TEXTURE1);
2278 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2279 texData[0] = 0;
2280 texData[1] = 90;
2281 texData[2] = 0;
2282 texData[3] = 255;
2283 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2284 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2285 texData);
2286
2287 glActiveTexture(GL_TEXTURE2);
2288 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2289 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2290 GLfloat depthTexData[1];
2291 depthTexData[0] = 0.5f;
2292 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2293 depthTexData);
2294
2295 glActiveTexture(GL_TEXTURE3);
2296 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2297 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2298 depthTexData[0] = 0.2f;
2299 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2300 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2301 depthTexData);
2302
2303 EXPECT_GL_NO_ERROR();
2304
2305 glUseProgram(mProgram);
2306 glUniform1f(mDepthRefUniformLocation, 0.3f);
2307 glUniform1i(mTexture2DUniformLocation, 0);
2308 glUniform1i(mTextureCubeUniformLocation, 1);
2309 glUniform1i(mTexture2DShadowUniformLocation, 2);
2310 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2311
2312 drawQuad(mProgram, "position", 0.5f);
2313 EXPECT_GL_NO_ERROR();
2314 // The shader writes:
2315 // <texture 2d color> +
2316 // <cube map color> +
2317 // 0.25 * <comparison result (1.0)> +
2318 // 0.125 * <comparison result (0.0)>
2319 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2320}
2321
Olli Etuahobce743a2016-01-15 17:18:28 +02002322// Test different base levels on textures accessed through the same sampler array.
2323// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2324TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2325{
Yunchao He9550c602018-02-13 14:47:05 +08002326 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2327
Olli Etuahobce743a2016-01-15 17:18:28 +02002328 glActiveTexture(GL_TEXTURE0);
2329 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2330 GLsizei size = 64;
2331 for (GLint level = 0; level < 7; ++level)
2332 {
2333 ASSERT_LT(0, size);
2334 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2335 nullptr);
2336 size = size / 2;
2337 }
2338 ASSERT_EQ(0, size);
2339 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2340
2341 glActiveTexture(GL_TEXTURE1);
2342 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2343 size = 128;
2344 for (GLint level = 0; level < 8; ++level)
2345 {
2346 ASSERT_LT(0, size);
2347 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2348 nullptr);
2349 size = size / 2;
2350 }
2351 ASSERT_EQ(0, size);
2352 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2353 EXPECT_GL_NO_ERROR();
2354
2355 glUseProgram(mProgram);
2356 glUniform1i(mTexture0Location, 0);
2357 glUniform1i(mTexture1Location, 1);
2358
2359 drawQuad(mProgram, "position", 0.5f);
2360 EXPECT_GL_NO_ERROR();
2361 // Red channel: width of level 1 of texture A: 32.
2362 // Green channel: width of level 3 of texture B: 16.
2363 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2364}
2365
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002366// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2367// ES 3.0.4 table 3.24
2368TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2369{
2370 glActiveTexture(GL_TEXTURE0);
2371 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2372 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2373 EXPECT_GL_NO_ERROR();
2374
2375 drawQuad(mProgram, "position", 0.5f);
2376
2377 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2378}
2379
2380// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2381// ES 3.0.4 table 3.24
2382TEST_P(Texture2DTestES3, TextureLuminanceImplicitAlpha1)
2383{
2384 glActiveTexture(GL_TEXTURE0);
2385 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2386 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2387 EXPECT_GL_NO_ERROR();
2388
2389 drawQuad(mProgram, "position", 0.5f);
2390
2391 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2392}
2393
2394// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2395// ES 3.0.4 table 3.24
2396TEST_P(Texture2DTestES3, TextureLuminance32ImplicitAlpha1)
2397{
2398 if (extensionEnabled("GL_OES_texture_float"))
2399 {
2400 glActiveTexture(GL_TEXTURE0);
2401 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2402 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2403 EXPECT_GL_NO_ERROR();
2404
2405 drawQuad(mProgram, "position", 0.5f);
2406
2407 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2408 }
2409}
2410
2411// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2412// ES 3.0.4 table 3.24
2413TEST_P(Texture2DTestES3, TextureLuminance16ImplicitAlpha1)
2414{
2415 if (extensionEnabled("GL_OES_texture_half_float"))
2416 {
Yunchao He9550c602018-02-13 14:47:05 +08002417 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES());
2418
Yuly Novikovafcec832016-06-21 22:19:51 -04002419 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002420 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Yuly Novikovafcec832016-06-21 22:19:51 -04002421
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002422 glActiveTexture(GL_TEXTURE0);
2423 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2424 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES,
2425 nullptr);
2426 EXPECT_GL_NO_ERROR();
2427
2428 drawQuad(mProgram, "position", 0.5f);
2429
2430 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2431 }
2432}
2433
2434// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2435// ES 3.0.4 table 3.24
2436TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2437{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002438 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2439
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002440 glActiveTexture(GL_TEXTURE0);
2441 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2442 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2443 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2444 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2445 EXPECT_GL_NO_ERROR();
2446
2447 drawQuad(mProgram, "position", 0.5f);
2448
2449 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2450}
2451
2452// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2453// ES 3.0.4 table 3.24
2454TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2455{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002456 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2457
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002458 glActiveTexture(GL_TEXTURE0);
2459 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2460
2461 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2462 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2463 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2464 EXPECT_GL_NO_ERROR();
2465
2466 drawQuad(mProgram, "position", 0.5f);
2467
2468 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2469}
2470
2471// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2472// ES 3.0.4 table 3.24
2473TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2474{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002475 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2476
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002477 glActiveTexture(GL_TEXTURE0);
2478 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2479 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2480 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2481 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2482 EXPECT_GL_NO_ERROR();
2483
2484 drawQuad(mProgram, "position", 0.5f);
2485
2486 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2487}
2488
2489// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2490// ES 3.0.4 table 3.24
2491TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2492{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002493 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2494
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002495 glActiveTexture(GL_TEXTURE0);
2496 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2497 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2498 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2499 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2500 EXPECT_GL_NO_ERROR();
2501
2502 drawQuad(mProgram, "position", 0.5f);
2503
2504 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2505}
2506
2507// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2508// ES 3.0.4 table 3.24
2509TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2510{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002511 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2512
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002513 glActiveTexture(GL_TEXTURE0);
2514 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2515 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2516 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2517 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2518 EXPECT_GL_NO_ERROR();
2519
2520 drawQuad(mProgram, "position", 0.5f);
2521
2522 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2523}
2524
2525// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2526// ES 3.0.4 table 3.24
2527TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2528{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002529 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2530
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002531 glActiveTexture(GL_TEXTURE0);
2532 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2533 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2534 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2535 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2536 EXPECT_GL_NO_ERROR();
2537
2538 drawQuad(mProgram, "position", 0.5f);
2539
2540 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2541}
2542
2543// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2544// ES 3.0.4 table 3.24
2545TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2546{
2547 glActiveTexture(GL_TEXTURE0);
2548 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2549 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2550 EXPECT_GL_NO_ERROR();
2551
2552 drawQuad(mProgram, "position", 0.5f);
2553
2554 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2555}
2556
2557// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2558// ES 3.0.4 table 3.24
2559TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2560{
2561 glActiveTexture(GL_TEXTURE0);
2562 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2563 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2564 nullptr);
2565 EXPECT_GL_NO_ERROR();
2566
2567 drawQuad(mProgram, "position", 0.5f);
2568
2569 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2570}
2571
2572// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2573// ES 3.0.4 table 3.24
2574TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2575{
Yunchao He9550c602018-02-13 14:47:05 +08002576 // Seems to fail on OSX 10.12 Intel.
2577 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Jamie Madillbb1db482017-01-10 10:48:32 -05002578
Yuly Novikov49886892018-01-23 21:18:27 -05002579 // http://anglebug.com/2190
2580 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2581
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002582 glActiveTexture(GL_TEXTURE0);
2583 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2584 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2585 EXPECT_GL_NO_ERROR();
2586
2587 drawQuad(mProgram, "position", 0.5f);
2588
2589 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2590}
2591
2592// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2593// ES 3.0.4 table 3.24
2594TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2595{
Yunchao He9550c602018-02-13 14:47:05 +08002596 // Seems to fail on OSX 10.12 Intel.
2597 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002598
Yuly Novikov49886892018-01-23 21:18:27 -05002599 // http://anglebug.com/2190
2600 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2601
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002602 glActiveTexture(GL_TEXTURE0);
2603 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2604 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2605 EXPECT_GL_NO_ERROR();
2606
2607 drawQuad(mProgram, "position", 0.5f);
2608
2609 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2610}
2611
Olli Etuaho96963162016-03-21 11:54:33 +02002612// Use a sampler in a uniform struct.
2613TEST_P(SamplerInStructTest, SamplerInStruct)
2614{
2615 runSamplerInStructTest();
2616}
2617
2618// Use a sampler in a uniform struct that's passed as a function parameter.
2619TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2620{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002621 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002622 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002623
Olli Etuaho96963162016-03-21 11:54:33 +02002624 runSamplerInStructTest();
2625}
2626
2627// Use a sampler in a uniform struct array with a struct from the array passed as a function
2628// parameter.
2629TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2630{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002631 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002632 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
2633
Olli Etuaho96963162016-03-21 11:54:33 +02002634 runSamplerInStructTest();
2635}
2636
2637// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2638// parameter.
2639TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2640{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002641 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002642 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
2643
Olli Etuaho96963162016-03-21 11:54:33 +02002644 runSamplerInStructTest();
2645}
2646
2647// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2648// similarly named uniform.
2649TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2650{
2651 runSamplerInStructTest();
2652}
2653
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002654class TextureLimitsTest : public ANGLETest
2655{
2656 protected:
2657 struct RGBA8
2658 {
2659 uint8_t R, G, B, A;
2660 };
2661
2662 TextureLimitsTest()
2663 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
2664 {
2665 setWindowWidth(128);
2666 setWindowHeight(128);
2667 setConfigRedBits(8);
2668 setConfigGreenBits(8);
2669 setConfigBlueBits(8);
2670 setConfigAlphaBits(8);
2671 }
2672
2673 ~TextureLimitsTest()
2674 {
2675 if (mProgram != 0)
2676 {
2677 glDeleteProgram(mProgram);
2678 mProgram = 0;
2679
2680 if (!mTextures.empty())
2681 {
2682 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
2683 }
2684 }
2685 }
2686
2687 void SetUp() override
2688 {
2689 ANGLETest::SetUp();
2690
2691 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
2692 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
2693 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
2694
2695 ASSERT_GL_NO_ERROR();
2696 }
2697
2698 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
2699 GLint vertexTextureCount,
2700 GLint vertexActiveTextureCount,
2701 const std::string &fragPrefix,
2702 GLint fragmentTextureCount,
2703 GLint fragmentActiveTextureCount)
2704 {
2705 std::stringstream vertexShaderStr;
2706 vertexShaderStr << "attribute vec2 position;\n"
2707 << "varying vec4 color;\n"
2708 << "varying vec2 texCoord;\n";
2709
2710 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
2711 {
2712 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
2713 }
2714
2715 vertexShaderStr << "void main() {\n"
2716 << " gl_Position = vec4(position, 0, 1);\n"
2717 << " texCoord = (position * 0.5) + 0.5;\n"
2718 << " color = vec4(0);\n";
2719
2720 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
2721 {
2722 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
2723 << ", texCoord);\n";
2724 }
2725
2726 vertexShaderStr << "}";
2727
2728 std::stringstream fragmentShaderStr;
2729 fragmentShaderStr << "varying mediump vec4 color;\n"
2730 << "varying mediump vec2 texCoord;\n";
2731
2732 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
2733 {
2734 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
2735 }
2736
2737 fragmentShaderStr << "void main() {\n"
2738 << " gl_FragColor = color;\n";
2739
2740 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
2741 {
2742 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
2743 << ", texCoord);\n";
2744 }
2745
2746 fragmentShaderStr << "}";
2747
2748 const std::string &vertexShaderSource = vertexShaderStr.str();
2749 const std::string &fragmentShaderSource = fragmentShaderStr.str();
2750
2751 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
2752 }
2753
2754 RGBA8 getPixel(GLint texIndex)
2755 {
2756 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
2757 0, 255u};
2758 return pixel;
2759 }
2760
2761 void initTextures(GLint tex2DCount, GLint texCubeCount)
2762 {
2763 GLint totalCount = tex2DCount + texCubeCount;
2764 mTextures.assign(totalCount, 0);
2765 glGenTextures(totalCount, &mTextures[0]);
2766 ASSERT_GL_NO_ERROR();
2767
2768 std::vector<RGBA8> texData(16 * 16);
2769
2770 GLint texIndex = 0;
2771 for (; texIndex < tex2DCount; ++texIndex)
2772 {
2773 texData.assign(texData.size(), getPixel(texIndex));
2774 glActiveTexture(GL_TEXTURE0 + texIndex);
2775 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
2776 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2777 &texData[0]);
2778 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2779 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2780 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2781 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2782 }
2783
2784 ASSERT_GL_NO_ERROR();
2785
2786 for (; texIndex < texCubeCount; ++texIndex)
2787 {
2788 texData.assign(texData.size(), getPixel(texIndex));
2789 glActiveTexture(GL_TEXTURE0 + texIndex);
2790 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
2791 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2792 GL_UNSIGNED_BYTE, &texData[0]);
2793 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2794 GL_UNSIGNED_BYTE, &texData[0]);
2795 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2796 GL_UNSIGNED_BYTE, &texData[0]);
2797 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2798 GL_UNSIGNED_BYTE, &texData[0]);
2799 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2800 GL_UNSIGNED_BYTE, &texData[0]);
2801 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2802 GL_UNSIGNED_BYTE, &texData[0]);
2803 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2804 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2805 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2806 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2807 }
2808
2809 ASSERT_GL_NO_ERROR();
2810 }
2811
2812 void testWithTextures(GLint vertexTextureCount,
2813 const std::string &vertexTexturePrefix,
2814 GLint fragmentTextureCount,
2815 const std::string &fragmentTexturePrefix)
2816 {
2817 // Generate textures
2818 initTextures(vertexTextureCount + fragmentTextureCount, 0);
2819
2820 glUseProgram(mProgram);
2821 RGBA8 expectedSum = {0};
2822 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
2823 {
2824 std::stringstream uniformNameStr;
2825 uniformNameStr << vertexTexturePrefix << texIndex;
2826 const std::string &uniformName = uniformNameStr.str();
2827 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
2828 ASSERT_NE(-1, location);
2829
2830 glUniform1i(location, texIndex);
2831 RGBA8 contribution = getPixel(texIndex);
2832 expectedSum.R += contribution.R;
2833 expectedSum.G += contribution.G;
2834 }
2835
2836 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
2837 {
2838 std::stringstream uniformNameStr;
2839 uniformNameStr << fragmentTexturePrefix << texIndex;
2840 const std::string &uniformName = uniformNameStr.str();
2841 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
2842 ASSERT_NE(-1, location);
2843
2844 glUniform1i(location, texIndex + vertexTextureCount);
2845 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
2846 expectedSum.R += contribution.R;
2847 expectedSum.G += contribution.G;
2848 }
2849
2850 ASSERT_GE(256u, expectedSum.G);
2851
2852 drawQuad(mProgram, "position", 0.5f);
2853 ASSERT_GL_NO_ERROR();
2854 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
2855 }
2856
2857 GLuint mProgram;
2858 std::vector<GLuint> mTextures;
2859 GLint mMaxVertexTextures;
2860 GLint mMaxFragmentTextures;
2861 GLint mMaxCombinedTextures;
2862};
2863
2864// Test rendering with the maximum vertex texture units.
2865TEST_P(TextureLimitsTest, MaxVertexTextures)
2866{
2867 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
2868 ASSERT_NE(0u, mProgram);
2869 ASSERT_GL_NO_ERROR();
2870
2871 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
2872}
2873
2874// Test rendering with the maximum fragment texture units.
2875TEST_P(TextureLimitsTest, MaxFragmentTextures)
2876{
2877 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
2878 ASSERT_NE(0u, mProgram);
2879 ASSERT_GL_NO_ERROR();
2880
2881 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
2882}
2883
2884// Test rendering with maximum combined texture units.
2885TEST_P(TextureLimitsTest, MaxCombinedTextures)
2886{
2887 GLint vertexTextures = mMaxVertexTextures;
2888
2889 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
2890 {
2891 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
2892 }
2893
2894 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
2895 mMaxFragmentTextures, mMaxFragmentTextures);
2896 ASSERT_NE(0u, mProgram);
2897 ASSERT_GL_NO_ERROR();
2898
2899 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
2900}
2901
2902// Negative test for exceeding the number of vertex textures
2903TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
2904{
2905 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
2906 0);
2907 ASSERT_EQ(0u, mProgram);
2908}
2909
2910// Negative test for exceeding the number of fragment textures
2911TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
2912{
2913 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
2914 mMaxFragmentTextures + 1);
2915 ASSERT_EQ(0u, mProgram);
2916}
2917
2918// Test active vertex textures under the limit, but excessive textures specified.
2919TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
2920{
2921 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
2922 ASSERT_NE(0u, mProgram);
2923 ASSERT_GL_NO_ERROR();
2924
2925 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
2926}
2927
2928// Test active fragment textures under the limit, but excessive textures specified.
2929TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
2930{
2931 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
2932 mMaxFragmentTextures);
2933 ASSERT_NE(0u, mProgram);
2934 ASSERT_GL_NO_ERROR();
2935
2936 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
2937}
2938
2939// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002940// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002941TEST_P(TextureLimitsTest, TextureTypeConflict)
2942{
2943 const std::string &vertexShader =
2944 "attribute vec2 position;\n"
2945 "varying float color;\n"
2946 "uniform sampler2D tex2D;\n"
2947 "uniform samplerCube texCube;\n"
2948 "void main() {\n"
2949 " gl_Position = vec4(position, 0, 1);\n"
2950 " vec2 texCoord = (position * 0.5) + 0.5;\n"
2951 " color = texture2D(tex2D, texCoord).x;\n"
2952 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
2953 "}";
2954 const std::string &fragmentShader =
2955 "varying mediump float color;\n"
2956 "void main() {\n"
2957 " gl_FragColor = vec4(color, 0, 0, 1);\n"
2958 "}";
2959
2960 mProgram = CompileProgram(vertexShader, fragmentShader);
2961 ASSERT_NE(0u, mProgram);
2962
2963 initTextures(1, 0);
2964
2965 glUseProgram(mProgram);
2966 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
2967 ASSERT_NE(-1, tex2DLocation);
2968 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
2969 ASSERT_NE(-1, texCubeLocation);
2970
2971 glUniform1i(tex2DLocation, 0);
2972 glUniform1i(texCubeLocation, 0);
2973 ASSERT_GL_NO_ERROR();
2974
2975 drawQuad(mProgram, "position", 0.5f);
2976 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2977}
2978
Vincent Lang25ab4512016-05-13 18:13:59 +02002979class Texture2DNorm16TestES3 : public Texture2DTestES3
2980{
2981 protected:
2982 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
2983
2984 void SetUp() override
2985 {
2986 Texture2DTestES3::SetUp();
2987
2988 glActiveTexture(GL_TEXTURE0);
2989 glGenTextures(3, mTextures);
2990 glGenFramebuffers(1, &mFBO);
2991 glGenRenderbuffers(1, &mRenderbuffer);
2992
2993 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
2994 {
2995 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
2996 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
2997 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2998 }
2999
3000 glBindTexture(GL_TEXTURE_2D, 0);
3001
3002 ASSERT_GL_NO_ERROR();
3003 }
3004
3005 void TearDown() override
3006 {
3007 glDeleteTextures(3, mTextures);
3008 glDeleteFramebuffers(1, &mFBO);
3009 glDeleteRenderbuffers(1, &mRenderbuffer);
3010
3011 Texture2DTestES3::TearDown();
3012 }
3013
3014 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3015 {
Geoff Langf607c602016-09-21 11:46:48 -04003016 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3017 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003018
3019 setUpProgram();
3020
3021 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3022 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3023 0);
3024
3025 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3026 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3027
3028 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003029 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003030
3031 EXPECT_GL_NO_ERROR();
3032
3033 drawQuad(mProgram, "position", 0.5f);
3034
Geoff Langf607c602016-09-21 11:46:48 -04003035 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003036
Geoff Langf607c602016-09-21 11:46:48 -04003037 EXPECT_PIXEL_COLOR_EQ(
3038 0, 0, SliceFormatColor(
3039 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003040
3041 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3042
3043 ASSERT_GL_NO_ERROR();
3044 }
3045
3046 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3047 {
3048 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003049 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003050
3051 setUpProgram();
3052
3053 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3054 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3055
3056 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3057 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3058 0);
3059
3060 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003061 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003062
3063 EXPECT_GL_NO_ERROR();
3064
3065 drawQuad(mProgram, "position", 0.5f);
3066
Geoff Langf607c602016-09-21 11:46:48 -04003067 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
3068 EXPECT_PIXEL_COLOR_EQ(
3069 0, 0, SliceFormatColor(
3070 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003071
3072 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3073 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3074 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3075 mRenderbuffer);
3076 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3077 EXPECT_GL_NO_ERROR();
3078
3079 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3080 glClear(GL_COLOR_BUFFER_BIT);
3081
3082 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3083
Geoff Langf607c602016-09-21 11:46:48 -04003084 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003085
3086 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3087
3088 ASSERT_GL_NO_ERROR();
3089 }
3090
3091 GLuint mTextures[3];
3092 GLuint mFBO;
3093 GLuint mRenderbuffer;
3094};
3095
3096// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3097TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3098{
Yunchao He9550c602018-02-13 14:47:05 +08003099 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02003100
3101 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3102 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3103 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3104 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3105 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3106 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3107 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3108 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3109
3110 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3111 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3112 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3113}
3114
Olli Etuaho95faa232016-06-07 14:01:53 -07003115// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3116// GLES 3.0.4 section 3.8.3.
3117TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3118{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08003119 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
3120
Yuly Novikov3c754192016-06-27 19:36:41 -04003121 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1429 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08003122 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07003123
3124 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3125 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3126 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3127 ASSERT_GL_NO_ERROR();
3128
3129 // SKIP_IMAGES should not have an effect on uploading 2D textures
3130 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3131 ASSERT_GL_NO_ERROR();
3132
3133 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3134
3135 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3136 pixelsGreen.data());
3137 ASSERT_GL_NO_ERROR();
3138
3139 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3140 pixelsGreen.data());
3141 ASSERT_GL_NO_ERROR();
3142
3143 glUseProgram(mProgram);
3144 drawQuad(mProgram, "position", 0.5f);
3145 ASSERT_GL_NO_ERROR();
3146
3147 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3148}
3149
Olli Etuaho989cac32016-06-08 16:18:49 -07003150// Test that skip defined in unpack parameters is taken into account when determining whether
3151// unpacking source extends outside unpack buffer bounds.
3152TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3153{
3154 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3155 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3156 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3157 ASSERT_GL_NO_ERROR();
3158
3159 GLBuffer buf;
3160 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3161 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3162 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3163 GL_DYNAMIC_COPY);
3164 ASSERT_GL_NO_ERROR();
3165
3166 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3167 ASSERT_GL_NO_ERROR();
3168
3169 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3170 ASSERT_GL_NO_ERROR();
3171
3172 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3173 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3174
3175 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3176 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3177 ASSERT_GL_NO_ERROR();
3178
3179 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3180 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3181}
3182
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003183// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3184TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3185{
Yunchao He9550c602018-02-13 14:47:05 +08003186 ANGLE_SKIP_TEST_IF(IsD3D11());
3187
3188 // Incorrect rendering results seen on OSX AMD.
3189 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003190
3191 const GLuint width = 8u;
3192 const GLuint height = 8u;
3193 const GLuint unpackRowLength = 5u;
3194 const GLuint unpackSkipPixels = 1u;
3195
3196 setWindowWidth(width);
3197 setWindowHeight(height);
3198
3199 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3200 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3201 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3202 ASSERT_GL_NO_ERROR();
3203
3204 GLBuffer buf;
3205 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3206 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3207 GLColor::green);
3208
3209 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3210 {
3211 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3212 }
3213
3214 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3215 GL_DYNAMIC_COPY);
3216 ASSERT_GL_NO_ERROR();
3217
3218 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3219 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3220 ASSERT_GL_NO_ERROR();
3221
3222 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3223 ASSERT_GL_NO_ERROR();
3224
3225 glUseProgram(mProgram);
3226 drawQuad(mProgram, "position", 0.5f);
3227 ASSERT_GL_NO_ERROR();
3228
3229 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3230 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3231 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3232 actual.data());
3233 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3234 EXPECT_EQ(expected, actual);
3235}
3236
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003237template <typename T>
3238T UNorm(double value)
3239{
3240 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3241}
3242
3243// Test rendering a depth texture with mipmaps.
3244TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3245{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003246 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3247 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
3248 // http://anglebugs.com/1706
Yunchao He9550c602018-02-13 14:47:05 +08003249 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows());
Corentin Walleze731d8a2016-09-07 10:56:25 -04003250
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003251 const int size = getWindowWidth();
3252
3253 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003254 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003255
3256 glActiveTexture(GL_TEXTURE0);
3257 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3258 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3259 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3260 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3261 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3262 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3263 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3264 ASSERT_GL_NO_ERROR();
3265
3266 glUseProgram(mProgram);
3267 glUniform1i(mTexture2DUniformLocation, 0);
3268
3269 std::vector<unsigned char> expected;
3270
3271 for (int level = 0; level < levels; ++level)
3272 {
3273 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3274 expected.push_back(UNorm<unsigned char>(value));
3275
3276 int levelDim = dim(level);
3277
3278 ASSERT_GT(levelDim, 0);
3279
3280 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3281 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3282 GL_UNSIGNED_INT, initData.data());
3283 }
3284 ASSERT_GL_NO_ERROR();
3285
3286 for (int level = 0; level < levels; ++level)
3287 {
3288 glViewport(0, 0, dim(level), dim(level));
3289 drawQuad(mProgram, "position", 0.5f);
3290 GLColor actual = ReadColor(0, 0);
3291 EXPECT_NEAR(expected[level], actual.R, 10u);
3292 }
3293
3294 ASSERT_GL_NO_ERROR();
3295}
3296
Jamie Madill7ffdda92016-09-08 13:26:51 -04003297// Tests unpacking into the unsized GL_ALPHA format.
3298TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3299{
Jamie Madill7ffdda92016-09-08 13:26:51 -04003300 // Initialize the texure.
3301 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3302 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3303 GL_UNSIGNED_BYTE, nullptr);
3304 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3305 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3306
3307 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3308
3309 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04003310 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04003311 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3312 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3313 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
3314 GL_STATIC_DRAW);
3315
3316 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
3317 GL_UNSIGNED_BYTE, nullptr);
3318
3319 // Clear to a weird color to make sure we're drawing something.
3320 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
3321 glClear(GL_COLOR_BUFFER_BIT);
3322
3323 // Draw with the alpha texture and verify.
3324 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04003325
3326 ASSERT_GL_NO_ERROR();
3327 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
3328}
3329
Jamie Madill2e600342016-09-19 13:56:40 -04003330// Ensure stale unpack data doesn't propagate in D3D11.
3331TEST_P(Texture2DTestES3, StaleUnpackData)
3332{
3333 // Init unpack buffer.
3334 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
3335 std::vector<GLColor> pixels(pixelCount, GLColor::red);
3336
3337 GLBuffer unpackBuffer;
3338 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3339 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3340 GLsizei bufferSize = pixelCount * sizeof(GLColor);
3341 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
3342
3343 // Create from unpack buffer.
3344 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3345 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
3346 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3347 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3348 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3349
3350 drawQuad(mProgram, "position", 0.5f);
3351
3352 ASSERT_GL_NO_ERROR();
3353 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3354
3355 // Fill unpack with green, recreating buffer.
3356 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
3357 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
3358 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
3359
3360 // Reinit texture with green.
3361 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
3362 GL_UNSIGNED_BYTE, nullptr);
3363
3364 drawQuad(mProgram, "position", 0.5f);
3365
3366 ASSERT_GL_NO_ERROR();
3367 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3368}
3369
Geoff Langfb7685f2017-11-13 11:44:11 -05003370// Ensure that texture parameters passed as floats that are converted to ints are rounded before
3371// validating they are less than 0.
3372TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
3373{
3374 GLTexture texture;
3375 glBindTexture(GL_TEXTURE_2D, texture);
3376
3377 // Use a negative number that will round to zero when converted to an integer
3378 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
3379 // "Validation of values performed by state-setting commands is performed after conversion,
3380 // unless specified otherwise for a specific command."
3381 GLfloat param = -7.30157126e-07f;
3382 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
3383 EXPECT_GL_NO_ERROR();
3384
3385 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
3386 EXPECT_GL_NO_ERROR();
3387}
3388
Jamie Madillf097e232016-11-05 00:44:15 -04003389// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
3390// being properly checked, and the texture storage of the previous texture format was persisting.
3391// This would result in an ASSERT in debug and incorrect rendering in release.
3392// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
3393TEST_P(Texture3DTestES3, FormatRedefinitionBug)
3394{
3395 GLTexture tex;
3396 glBindTexture(GL_TEXTURE_3D, tex.get());
3397 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3398
3399 GLFramebuffer framebuffer;
3400 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3401 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
3402
3403 glCheckFramebufferStatus(GL_FRAMEBUFFER);
3404
3405 std::vector<uint8_t> pixelData(100, 0);
3406
3407 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
3408 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
3409 pixelData.data());
3410
3411 ASSERT_GL_NO_ERROR();
3412}
3413
Corentin Wallezd2627992017-04-28 17:17:03 -04003414// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
3415TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
3416{
3417 // 2D tests
3418 {
3419 GLTexture tex;
3420 glBindTexture(GL_TEXTURE_2D, tex.get());
3421
3422 GLBuffer pbo;
3423 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3424
3425 // Test OOB
3426 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
3427 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3428 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3429
3430 // Test OOB
3431 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
3432 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3433 ASSERT_GL_NO_ERROR();
3434 }
3435
3436 // 3D tests
3437 {
3438 GLTexture tex;
3439 glBindTexture(GL_TEXTURE_3D, tex.get());
3440
3441 GLBuffer pbo;
3442 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3443
3444 // Test OOB
3445 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
3446 GL_STATIC_DRAW);
3447 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3448 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3449
3450 // Test OOB
3451 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
3452 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3453 ASSERT_GL_NO_ERROR();
3454 }
3455}
3456
Jamie Madill3ed60422017-09-07 11:32:52 -04003457// Tests behaviour with a single texture and multiple sampler objects.
3458TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
3459{
3460 GLint maxTextureUnits = 0;
3461 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
3462 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
3463
3464 constexpr int kSize = 16;
3465
3466 // Make a single-level texture, fill it with red.
3467 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
3468 GLTexture tex;
3469 glBindTexture(GL_TEXTURE_2D, tex);
3470 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3471 redColors.data());
3472 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3473 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3474
3475 // Simple sanity check.
3476 draw2DTexturedQuad(0.5f, 1.0f, true);
3477 ASSERT_GL_NO_ERROR();
3478 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3479
3480 // Bind texture to unit 1 with a sampler object making it incomplete.
3481 GLSampler sampler;
3482 glBindSampler(0, sampler);
3483 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3484 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3485
3486 // Make a mipmap texture, fill it with blue.
3487 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
3488 GLTexture mipmapTex;
3489 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3490 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3491 blueColors.data());
3492 glGenerateMipmap(GL_TEXTURE_2D);
3493
3494 // Draw with the sampler, expect blue.
3495 draw2DTexturedQuad(0.5f, 1.0f, true);
3496 ASSERT_GL_NO_ERROR();
3497 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
3498
3499 // Simple multitexturing program.
3500 const std::string vs =
3501 "#version 300 es\n"
3502 "in vec2 position;\n"
3503 "out vec2 texCoord;\n"
3504 "void main()\n"
3505 "{\n"
3506 " gl_Position = vec4(position, 0, 1);\n"
3507 " texCoord = position * 0.5 + vec2(0.5);\n"
3508 "}";
3509 const std::string fs =
3510 "#version 300 es\n"
3511 "precision mediump float;\n"
3512 "in vec2 texCoord;\n"
3513 "uniform sampler2D tex1;\n"
3514 "uniform sampler2D tex2;\n"
3515 "uniform sampler2D tex3;\n"
3516 "uniform sampler2D tex4;\n"
3517 "out vec4 color;\n"
3518 "void main()\n"
3519 "{\n"
3520 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
3521 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
3522 "}";
3523
3524 ANGLE_GL_PROGRAM(program, vs, fs);
3525
3526 std::array<GLint, 4> texLocations = {
3527 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
3528 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
3529 for (GLint location : texLocations)
3530 {
3531 ASSERT_NE(-1, location);
3532 }
3533
3534 // Init the uniform data.
3535 glUseProgram(program);
3536 for (GLint location = 0; location < 4; ++location)
3537 {
3538 glUniform1i(texLocations[location], location);
3539 }
3540
3541 // Initialize four samplers
3542 GLSampler samplers[4];
3543
3544 // 0: non-mipped.
3545 glBindSampler(0, samplers[0]);
3546 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3547 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3548
3549 // 1: mipped.
3550 glBindSampler(1, samplers[1]);
3551 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3552 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3553
3554 // 2: non-mipped.
3555 glBindSampler(2, samplers[2]);
3556 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3557 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3558
3559 // 3: mipped.
3560 glBindSampler(3, samplers[3]);
3561 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3562 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3563
3564 // Bind two blue mipped textures and two single layer textures, should all draw.
3565 glActiveTexture(GL_TEXTURE0);
3566 glBindTexture(GL_TEXTURE_2D, tex);
3567
3568 glActiveTexture(GL_TEXTURE1);
3569 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3570
3571 glActiveTexture(GL_TEXTURE2);
3572 glBindTexture(GL_TEXTURE_2D, tex);
3573
3574 glActiveTexture(GL_TEXTURE3);
3575 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3576
3577 ASSERT_GL_NO_ERROR();
3578
3579 drawQuad(program, "position", 0.5f);
3580 ASSERT_GL_NO_ERROR();
3581 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
3582
3583 // Bind four single layer textures, two should be incomplete.
3584 glActiveTexture(GL_TEXTURE1);
3585 glBindTexture(GL_TEXTURE_2D, tex);
3586
3587 glActiveTexture(GL_TEXTURE3);
3588 glBindTexture(GL_TEXTURE_2D, tex);
3589
3590 drawQuad(program, "position", 0.5f);
3591 ASSERT_GL_NO_ERROR();
3592 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
3593}
3594
Martin Radev7e2c0d32017-09-15 14:25:42 +03003595// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
3596// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
3597// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
3598// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
3599// samples the cubemap using a direction vector (1,1,1).
3600TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
3601{
Yunchao He2f23f352018-02-11 22:11:37 +08003602 // Check http://anglebug.com/2155.
3603 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
3604
Martin Radev7e2c0d32017-09-15 14:25:42 +03003605 const std::string vs =
3606 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003607 precision mediump float;
3608 in vec3 pos;
3609 void main() {
3610 gl_Position = vec4(pos, 1.0);
3611 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003612
3613 const std::string fs =
3614 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003615 precision mediump float;
3616 out vec4 color;
3617 uniform samplerCube uTex;
3618 void main(){
3619 color = texture(uTex, vec3(1.0));
3620 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003621 ANGLE_GL_PROGRAM(program, vs, fs);
3622 glUseProgram(program);
3623
3624 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
3625 glActiveTexture(GL_TEXTURE0);
3626
3627 GLTexture cubeTex;
3628 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
3629
3630 const int kFaceWidth = 1;
3631 const int kFaceHeight = 1;
3632 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
3633 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3634 GL_UNSIGNED_BYTE, texData.data());
3635 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3636 GL_UNSIGNED_BYTE, texData.data());
3637 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3638 GL_UNSIGNED_BYTE, texData.data());
3639 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3640 GL_UNSIGNED_BYTE, texData.data());
3641 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3642 GL_UNSIGNED_BYTE, texData.data());
3643 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3644 GL_UNSIGNED_BYTE, texData.data());
3645 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3646 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3647 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
3648 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
3649 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
3650 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
3651
3652 drawQuad(program, "pos", 0.5f, 1.0f, true);
3653 ASSERT_GL_NO_ERROR();
3654
3655 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
3656}
3657
Jamie Madillfa05f602015-05-07 13:47:11 -04003658// 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 +02003659// TODO(oetuaho): Enable all below tests on OpenGL. Requires a fix for ANGLE bug 1278.
Geoff Lange0cc2a42016-01-20 10:58:17 -05003660ANGLE_INSTANTIATE_TEST(Texture2DTest,
3661 ES2_D3D9(),
3662 ES2_D3D11(),
3663 ES2_D3D11_FL9_3(),
3664 ES2_OPENGL(),
3665 ES2_OPENGLES());
3666ANGLE_INSTANTIATE_TEST(TextureCubeTest,
3667 ES2_D3D9(),
3668 ES2_D3D11(),
Geoff Langf7480ad2017-10-24 11:46:02 -04003669 ES2_D3D11_FL10_0(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003670 ES2_D3D11_FL9_3(),
3671 ES2_OPENGL(),
3672 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003673ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
3674 ES2_D3D9(),
3675 ES2_D3D11(),
3676 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003677 ES2_OPENGL(),
3678 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003679ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
3680 ES2_D3D9(),
3681 ES2_D3D11(),
3682 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003683 ES2_OPENGL(),
3684 ES2_OPENGLES());
3685ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
3686 ES2_D3D9(),
3687 ES2_D3D11(),
3688 ES2_D3D11_FL9_3(),
3689 ES2_OPENGL(),
3690 ES2_OPENGLES());
3691ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
3692 ES2_D3D9(),
3693 ES2_D3D11(),
3694 ES2_D3D11_FL9_3(),
3695 ES2_OPENGL(),
3696 ES2_OPENGLES());
3697ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02003698ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003699ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3700ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
3701 ES3_D3D11(),
3702 ES3_OPENGL(),
3703 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003704ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
3705 ES3_D3D11(),
3706 ES3_OPENGL(),
3707 ES3_OPENGLES());
3708ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3709ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02003710ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02003711ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
3712 ES2_D3D11(),
3713 ES2_D3D11_FL9_3(),
3714 ES2_D3D9(),
3715 ES2_OPENGL(),
3716 ES2_OPENGLES());
3717ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
3718 ES2_D3D11(),
3719 ES2_D3D11_FL9_3(),
3720 ES2_D3D9(),
3721 ES2_OPENGL(),
3722 ES2_OPENGLES());
3723ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
3724 ES2_D3D11(),
3725 ES2_D3D11_FL9_3(),
3726 ES2_D3D9(),
3727 ES2_OPENGL(),
3728 ES2_OPENGLES());
3729ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
3730 ES2_D3D11(),
3731 ES2_D3D11_FL9_3(),
3732 ES2_D3D9(),
3733 ES2_OPENGL(),
3734 ES2_OPENGLES());
3735ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
3736 ES2_D3D11(),
3737 ES2_D3D11_FL9_3(),
3738 ES2_D3D9(),
3739 ES2_OPENGL(),
3740 ES2_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003741ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES());
Vincent Lang25ab4512016-05-13 18:13:59 +02003742ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03003743ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04003744
Jamie Madill7ffdda92016-09-08 13:26:51 -04003745} // anonymous namespace