blob: eecc591dad0daabf05d7b276d67957652046bf51 [file] [log] [blame]
Jamie Madillfa05f602015-05-07 13:47:11 -04001//
2// Copyright 2015 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Jamie Madill14718762016-09-06 15:56:54 -04007#include "common/mathutil.h"
Corentin Wallezd3970de2015-05-14 11:07:48 -04008#include "test_utils/ANGLETest.h"
Olli Etuaho989cac32016-06-08 16:18:49 -07009#include "test_utils/gl_raii.h"
Jamie Madillf67115c2014-04-22 13:14:05 -040010
Jamie Madillfa05f602015-05-07 13:47:11 -040011using namespace angle;
Austin Kinross18b931d2014-09-29 12:58:31 -070012
Jamie Madillfa05f602015-05-07 13:47:11 -040013namespace
14{
15
Vincent Lang25ab4512016-05-13 18:13:59 +020016// Take a pixel, and reset the components not covered by the format to default
Geoff Langf607c602016-09-21 11:46:48 -040017// values. In particular, the default value for the alpha component is 255
Vincent Lang25ab4512016-05-13 18:13:59 +020018// (1.0 as unsigned normalized fixed point value).
Geoff Langf607c602016-09-21 11:46:48 -040019GLColor SliceFormatColor(GLenum format, GLColor full)
Vincent Lang25ab4512016-05-13 18:13:59 +020020{
21 switch (format)
22 {
23 case GL_RED:
Geoff Langf607c602016-09-21 11:46:48 -040024 return GLColor(full.R, 0, 0, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020025 case GL_RG:
Geoff Langf607c602016-09-21 11:46:48 -040026 return GLColor(full.R, full.G, 0, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020027 case GL_RGB:
Geoff Langf607c602016-09-21 11:46:48 -040028 return GLColor(full.R, full.G, full.B, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020029 case GL_RGBA:
30 return full;
31 default:
Jamie Madille1faacb2016-12-13 12:42:14 -050032 EXPECT_TRUE(false);
Geoff Langf607c602016-09-21 11:46:48 -040033 return GLColor::white;
Vincent Lang25ab4512016-05-13 18:13:59 +020034 }
Vincent Lang25ab4512016-05-13 18:13:59 +020035}
36
Olli Etuaho4a8329f2016-01-11 17:12:57 +020037class TexCoordDrawTest : public ANGLETest
Jamie Madillf67115c2014-04-22 13:14:05 -040038{
Jamie Madillbc393df2015-01-29 13:46:07 -050039 protected:
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020040 TexCoordDrawTest() : ANGLETest(), mProgram(0), mFramebuffer(0), mFramebufferColorTexture(0)
Jamie Madillf67115c2014-04-22 13:14:05 -040041 {
42 setWindowWidth(128);
43 setWindowHeight(128);
44 setConfigRedBits(8);
45 setConfigGreenBits(8);
46 setConfigBlueBits(8);
47 setConfigAlphaBits(8);
48 }
49
Olli Etuaho4a8329f2016-01-11 17:12:57 +020050 virtual std::string getVertexShaderSource()
Jamie Madillf67115c2014-04-22 13:14:05 -040051 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +030052 return
53 R"(precision highp float;
Geoff Langc41e42d2014-04-28 10:58:16 -040054 attribute vec4 position;
55 varying vec2 texcoord;
56
57 void main()
58 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +020059 gl_Position = vec4(position.xy, 0.0, 1.0);
Geoff Langc41e42d2014-04-28 10:58:16 -040060 texcoord = (position.xy * 0.5) + 0.5;
Olli Etuahoa20af6d2017-09-18 13:32:29 +030061 })";
Olli Etuaho4a8329f2016-01-11 17:12:57 +020062 }
Geoff Langc41e42d2014-04-28 10:58:16 -040063
Olli Etuaho4a8329f2016-01-11 17:12:57 +020064 virtual std::string getFragmentShaderSource() = 0;
65
Olli Etuahoa1c917f2016-04-06 13:50:03 +030066 virtual void setUpProgram()
Olli Etuaho4a8329f2016-01-11 17:12:57 +020067 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +020068 const std::string vertexShaderSource = getVertexShaderSource();
69 const std::string fragmentShaderSource = getFragmentShaderSource();
70
71 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
72 ASSERT_NE(0u, mProgram);
73 ASSERT_GL_NO_ERROR();
Olli Etuahoa1c917f2016-04-06 13:50:03 +030074 }
75
76 void SetUp() override
77 {
78 ANGLETest::SetUp();
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020079
80 setUpFramebuffer();
Olli Etuaho4a8329f2016-01-11 17:12:57 +020081 }
82
83 void TearDown() override
84 {
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020085 glBindFramebuffer(GL_FRAMEBUFFER, 0);
86 glDeleteFramebuffers(1, &mFramebuffer);
87 glDeleteTextures(1, &mFramebufferColorTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +020088 glDeleteProgram(mProgram);
89 ANGLETest::TearDown();
90 }
91
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020092 void setUpFramebuffer()
93 {
94 // We use an FBO to work around an issue where the default framebuffer applies SRGB
95 // conversion (particularly known to happen incorrectly on Intel GL drivers). It's not
96 // clear whether this issue can even be fixed on all backends. For example GLES 3.0.4 spec
97 // section 4.4 says that the format of the default framebuffer is entirely up to the window
98 // system, so it might be SRGB, and GLES 3.0 doesn't have a "FRAMEBUFFER_SRGB" to turn off
99 // SRGB conversion like desktop GL does.
100 // TODO(oetuaho): Get rid of this if the underlying issue is fixed.
101 glGenFramebuffers(1, &mFramebuffer);
102 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
103
104 glGenTextures(1, &mFramebufferColorTexture);
105 glBindTexture(GL_TEXTURE_2D, mFramebufferColorTexture);
106 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
107 GL_UNSIGNED_BYTE, nullptr);
108 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
109 mFramebufferColorTexture, 0);
110 ASSERT_GL_NO_ERROR();
111 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
112 glBindTexture(GL_TEXTURE_2D, 0);
113 }
114
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200115 // Returns the created texture ID.
116 GLuint create2DTexture()
117 {
118 GLuint texture2D;
119 glGenTextures(1, &texture2D);
120 glBindTexture(GL_TEXTURE_2D, texture2D);
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800121 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200122 EXPECT_GL_NO_ERROR();
123 return texture2D;
124 }
125
126 GLuint mProgram;
Olli Etuaho51f1c0f2016-01-13 16:16:24 +0200127 GLuint mFramebuffer;
128
129 private:
130 GLuint mFramebufferColorTexture;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200131};
132
133class Texture2DTest : public TexCoordDrawTest
134{
135 protected:
136 Texture2DTest() : TexCoordDrawTest(), mTexture2D(0), mTexture2DUniformLocation(-1) {}
137
138 std::string getFragmentShaderSource() override
139 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300140 return
141 R"(precision highp float;
Geoff Langc41e42d2014-04-28 10:58:16 -0400142 uniform sampler2D tex;
143 varying vec2 texcoord;
144
145 void main()
146 {
147 gl_FragColor = texture2D(tex, texcoord);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300148 })";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200149 }
Geoff Langc41e42d2014-04-28 10:58:16 -0400150
Olli Etuaho96963162016-03-21 11:54:33 +0200151 virtual const char *getTextureUniformName() { return "tex"; }
152
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300153 void setUpProgram() override
154 {
155 TexCoordDrawTest::setUpProgram();
156 mTexture2DUniformLocation = glGetUniformLocation(mProgram, getTextureUniformName());
157 ASSERT_NE(-1, mTexture2DUniformLocation);
158 }
159
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200160 void SetUp() override
161 {
162 TexCoordDrawTest::SetUp();
163 mTexture2D = create2DTexture();
Jamie Madilld4cfa572014-07-08 10:00:32 -0400164
Jamie Madill9aca0592014-10-06 16:26:59 -0400165 ASSERT_GL_NO_ERROR();
Jamie Madillf67115c2014-04-22 13:14:05 -0400166 }
167
Jamie Madillfa05f602015-05-07 13:47:11 -0400168 void TearDown() override
Jamie Madillf67115c2014-04-22 13:14:05 -0400169 {
Jamie Madilld4cfa572014-07-08 10:00:32 -0400170 glDeleteTextures(1, &mTexture2D);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200171 TexCoordDrawTest::TearDown();
Jamie Madillf67115c2014-04-22 13:14:05 -0400172 }
173
Jamie Madillbc393df2015-01-29 13:46:07 -0500174 // Tests CopyTexSubImage with floating point textures of various formats.
175 void testFloatCopySubImage(int sourceImageChannels, int destImageChannels)
176 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300177 setUpProgram();
178
Martin Radev1be913c2016-07-11 17:59:16 +0300179 if (getClientMajorVersion() < 3)
Geoff Langfbfa47c2015-03-31 11:26:00 -0400180 {
Yunchao He9550c602018-02-13 14:47:05 +0800181 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_storage") ||
182 !extensionEnabled("GL_OES_texture_float"));
Geoff Langc4e93662017-05-01 10:45:59 -0400183
Yunchao He9550c602018-02-13 14:47:05 +0800184 ANGLE_SKIP_TEST_IF((sourceImageChannels < 3 || destImageChannels < 3) &&
185 !extensionEnabled("GL_EXT_texture_rg"));
Geoff Langfbfa47c2015-03-31 11:26:00 -0400186
Yunchao He9550c602018-02-13 14:47:05 +0800187 ANGLE_SKIP_TEST_IF(destImageChannels == 3 &&
188 !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400189
Yunchao He9550c602018-02-13 14:47:05 +0800190 ANGLE_SKIP_TEST_IF(destImageChannels == 4 &&
191 !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400192
Yunchao He9550c602018-02-13 14:47:05 +0800193 ANGLE_SKIP_TEST_IF(destImageChannels <= 2);
Geoff Lang677bb6f2017-04-05 12:40:40 -0400194 }
195 else
196 {
Yunchao He9550c602018-02-13 14:47:05 +0800197 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_color_buffer_float"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400198
Yunchao He9550c602018-02-13 14:47:05 +0800199 ANGLE_SKIP_TEST_IF(destImageChannels == 3 &&
200 !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"));
Geoff Langfbfa47c2015-03-31 11:26:00 -0400201 }
202
Jamie Madillbc393df2015-01-29 13:46:07 -0500203 GLfloat sourceImageData[4][16] =
204 {
205 { // R
206 1.0f,
207 0.0f,
208 0.0f,
209 1.0f
210 },
211 { // RG
212 1.0f, 0.0f,
213 0.0f, 1.0f,
214 0.0f, 0.0f,
215 1.0f, 1.0f
216 },
217 { // RGB
218 1.0f, 0.0f, 0.0f,
219 0.0f, 1.0f, 0.0f,
220 0.0f, 0.0f, 1.0f,
221 1.0f, 1.0f, 0.0f
222 },
223 { // RGBA
224 1.0f, 0.0f, 0.0f, 1.0f,
225 0.0f, 1.0f, 0.0f, 1.0f,
226 0.0f, 0.0f, 1.0f, 1.0f,
227 1.0f, 1.0f, 0.0f, 1.0f
228 },
229 };
230
231 GLenum imageFormats[] =
232 {
233 GL_R32F,
234 GL_RG32F,
235 GL_RGB32F,
236 GL_RGBA32F,
237 };
238
239 GLenum sourceUnsizedFormats[] =
240 {
241 GL_RED,
242 GL_RG,
243 GL_RGB,
244 GL_RGBA,
245 };
246
247 GLuint textures[2];
248
249 glGenTextures(2, textures);
250
251 GLfloat *imageData = sourceImageData[sourceImageChannels - 1];
252 GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1];
253 GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1];
254 GLenum destImageFormat = imageFormats[destImageChannels - 1];
255
256 glBindTexture(GL_TEXTURE_2D, textures[0]);
Geoff Langc4e93662017-05-01 10:45:59 -0400257 if (getClientMajorVersion() >= 3)
258 {
259 glTexStorage2D(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
260 }
261 else
262 {
263 glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
264 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500265 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
266 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
267 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData);
268
hendrikwb27f79a2015-03-04 11:26:46 -0800269 if (sourceImageChannels < 3 && !extensionEnabled("GL_EXT_texture_rg"))
Jamie Madillbc393df2015-01-29 13:46:07 -0500270 {
271 // This is not supported
272 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
273 }
274 else
275 {
276 ASSERT_GL_NO_ERROR();
277 }
278
279 GLuint fbo;
280 glGenFramebuffers(1, &fbo);
281 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
282 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
283
284 glBindTexture(GL_TEXTURE_2D, textures[1]);
Geoff Langc4e93662017-05-01 10:45:59 -0400285 if (getClientMajorVersion() >= 3)
286 {
287 glTexStorage2D(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
288 }
289 else
290 {
291 glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
292 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500293 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
294 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
295
296 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
297 ASSERT_GL_NO_ERROR();
298
299 glBindFramebuffer(GL_FRAMEBUFFER, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200300 drawQuad(mProgram, "position", 0.5f);
Jamie Madillbc393df2015-01-29 13:46:07 -0500301
302 int testImageChannels = std::min(sourceImageChannels, destImageChannels);
303
Olli Etuahoa314b612016-03-10 16:43:00 +0200304 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Jamie Madillbc393df2015-01-29 13:46:07 -0500305 if (testImageChannels > 1)
306 {
307 EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255);
308 EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255);
309 if (testImageChannels > 2)
310 {
311 EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255);
312 }
313 }
314
315 glDeleteFramebuffers(1, &fbo);
316 glDeleteTextures(2, textures);
317
318 ASSERT_GL_NO_ERROR();
319 }
320
Jamie Madilld4cfa572014-07-08 10:00:32 -0400321 GLuint mTexture2D;
Jamie Madilld4cfa572014-07-08 10:00:32 -0400322 GLint mTexture2DUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400323};
324
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200325class Texture2DTestES3 : public Texture2DTest
326{
327 protected:
328 Texture2DTestES3() : Texture2DTest() {}
329
330 std::string getVertexShaderSource() override
331 {
332 return std::string(
333 "#version 300 es\n"
334 "out vec2 texcoord;\n"
335 "in vec4 position;\n"
336 "void main()\n"
337 "{\n"
338 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
339 " texcoord = (position.xy * 0.5) + 0.5;\n"
340 "}\n");
341 }
342
343 std::string getFragmentShaderSource() override
344 {
345 return std::string(
346 "#version 300 es\n"
347 "precision highp float;\n"
348 "uniform highp sampler2D tex;\n"
349 "in vec2 texcoord;\n"
350 "out vec4 fragColor;\n"
351 "void main()\n"
352 "{\n"
353 " fragColor = texture(tex, texcoord);\n"
354 "}\n");
355 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300356
357 void SetUp() override
358 {
359 Texture2DTest::SetUp();
360 setUpProgram();
361 }
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200362};
363
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200364class Texture2DIntegerAlpha1TestES3 : public Texture2DTest
365{
366 protected:
367 Texture2DIntegerAlpha1TestES3() : Texture2DTest() {}
368
369 std::string getVertexShaderSource() override
370 {
371 return std::string(
372 "#version 300 es\n"
373 "out vec2 texcoord;\n"
374 "in vec4 position;\n"
375 "void main()\n"
376 "{\n"
377 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
378 " texcoord = (position.xy * 0.5) + 0.5;\n"
379 "}\n");
380 }
381
382 std::string getFragmentShaderSource() override
383 {
384 return std::string(
385 "#version 300 es\n"
386 "precision highp float;\n"
387 "uniform highp isampler2D tex;\n"
388 "in vec2 texcoord;\n"
389 "out vec4 fragColor;\n"
390 "void main()\n"
391 "{\n"
392 " vec4 green = vec4(0, 1, 0, 1);\n"
393 " vec4 black = vec4(0, 0, 0, 0);\n"
394 " fragColor = (texture(tex, texcoord).a == 1) ? green : black;\n"
395 "}\n");
396 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300397
398 void SetUp() override
399 {
400 Texture2DTest::SetUp();
401 setUpProgram();
402 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200403};
404
405class Texture2DUnsignedIntegerAlpha1TestES3 : public Texture2DTest
406{
407 protected:
408 Texture2DUnsignedIntegerAlpha1TestES3() : Texture2DTest() {}
409
410 std::string getVertexShaderSource() override
411 {
412 return std::string(
413 "#version 300 es\n"
414 "out vec2 texcoord;\n"
415 "in vec4 position;\n"
416 "void main()\n"
417 "{\n"
418 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
419 " texcoord = (position.xy * 0.5) + 0.5;\n"
420 "}\n");
421 }
422
423 std::string getFragmentShaderSource() override
424 {
425 return std::string(
426 "#version 300 es\n"
427 "precision highp float;\n"
428 "uniform highp usampler2D tex;\n"
429 "in vec2 texcoord;\n"
430 "out vec4 fragColor;\n"
431 "void main()\n"
432 "{\n"
433 " vec4 green = vec4(0, 1, 0, 1);\n"
434 " vec4 black = vec4(0, 0, 0, 0);\n"
435 " fragColor = (texture(tex, texcoord).a == 1u) ? green : black;\n"
436 "}\n");
437 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300438
439 void SetUp() override
440 {
441 Texture2DTest::SetUp();
442 setUpProgram();
443 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200444};
445
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200446class Texture2DTestWithDrawScale : public Texture2DTest
Jamie Madill2453dbc2015-07-14 11:35:42 -0400447{
448 protected:
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200449 Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {}
450
451 std::string getVertexShaderSource() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400452 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300453 return
454 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200455 attribute vec4 position;
456 varying vec2 texcoord;
457
458 uniform vec2 drawScale;
459
460 void main()
461 {
462 gl_Position = vec4(position.xy * drawScale, 0.0, 1.0);
463 texcoord = (position.xy * 0.5) + 0.5;
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300464 })";
Jamie Madill2453dbc2015-07-14 11:35:42 -0400465 }
466
467 void SetUp() override
468 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200469 Texture2DTest::SetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300470
471 setUpProgram();
472
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200473 mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale");
474 ASSERT_NE(-1, mDrawScaleUniformLocation);
Jamie Madill2453dbc2015-07-14 11:35:42 -0400475
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200476 glUseProgram(mProgram);
477 glUniform2f(mDrawScaleUniformLocation, 1.0f, 1.0f);
478 glUseProgram(0);
479 ASSERT_GL_NO_ERROR();
480 }
481
482 GLint mDrawScaleUniformLocation;
483};
484
Olli Etuaho4644a202016-01-12 15:12:53 +0200485class Sampler2DAsFunctionParameterTest : public Texture2DTest
486{
487 protected:
488 Sampler2DAsFunctionParameterTest() : Texture2DTest() {}
489
490 std::string getFragmentShaderSource() override
491 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300492 return
493 R"(precision highp float;
Olli Etuaho4644a202016-01-12 15:12:53 +0200494 uniform sampler2D tex;
495 varying vec2 texcoord;
496
497 vec4 computeFragColor(sampler2D aTex)
498 {
499 return texture2D(aTex, texcoord);
500 }
501
502 void main()
503 {
504 gl_FragColor = computeFragColor(tex);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300505 })";
Olli Etuaho4644a202016-01-12 15:12:53 +0200506 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300507
508 void SetUp() override
509 {
510 Texture2DTest::SetUp();
511 setUpProgram();
512 }
Olli Etuaho4644a202016-01-12 15:12:53 +0200513};
514
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200515class TextureCubeTest : public TexCoordDrawTest
516{
517 protected:
518 TextureCubeTest()
519 : TexCoordDrawTest(),
520 mTexture2D(0),
521 mTextureCube(0),
522 mTexture2DUniformLocation(-1),
523 mTextureCubeUniformLocation(-1)
524 {
525 }
526
527 std::string getFragmentShaderSource() override
528 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300529 return
530 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200531 uniform sampler2D tex2D;
532 uniform samplerCube texCube;
533 varying vec2 texcoord;
534
535 void main()
536 {
537 gl_FragColor = texture2D(tex2D, texcoord);
538 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300539 })";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200540 }
541
542 void SetUp() override
543 {
544 TexCoordDrawTest::SetUp();
545
546 glGenTextures(1, &mTextureCube);
547 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Geoff Langc4e93662017-05-01 10:45:59 -0400548 for (GLenum face = 0; face < 6; face++)
549 {
550 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
551 GL_UNSIGNED_BYTE, nullptr);
552 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200553 EXPECT_GL_NO_ERROR();
554
555 mTexture2D = create2DTexture();
556
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300557 setUpProgram();
558
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200559 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
560 ASSERT_NE(-1, mTexture2DUniformLocation);
561 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
562 ASSERT_NE(-1, mTextureCubeUniformLocation);
563 }
564
565 void TearDown() override
566 {
567 glDeleteTextures(1, &mTextureCube);
568 TexCoordDrawTest::TearDown();
569 }
570
571 GLuint mTexture2D;
572 GLuint mTextureCube;
573 GLint mTexture2DUniformLocation;
574 GLint mTextureCubeUniformLocation;
575};
576
Martin Radev7e2c0d32017-09-15 14:25:42 +0300577class TextureCubeTestES3 : public ANGLETest
578{
579 protected:
580 TextureCubeTestES3() {}
581};
582
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200583class SamplerArrayTest : public TexCoordDrawTest
584{
585 protected:
586 SamplerArrayTest()
587 : TexCoordDrawTest(),
588 mTexture2DA(0),
589 mTexture2DB(0),
590 mTexture0UniformLocation(-1),
591 mTexture1UniformLocation(-1)
592 {
593 }
594
595 std::string getFragmentShaderSource() override
596 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300597 return
598 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200599 uniform highp sampler2D tex2DArray[2];
600 varying vec2 texcoord;
601 void main()
602 {
603 gl_FragColor = texture2D(tex2DArray[0], texcoord);
604 gl_FragColor += texture2D(tex2DArray[1], texcoord);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300605 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200606 }
607
608 void SetUp() override
609 {
610 TexCoordDrawTest::SetUp();
611
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300612 setUpProgram();
613
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200614 mTexture0UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[0]");
615 ASSERT_NE(-1, mTexture0UniformLocation);
616 mTexture1UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[1]");
617 ASSERT_NE(-1, mTexture1UniformLocation);
618
619 mTexture2DA = create2DTexture();
620 mTexture2DB = create2DTexture();
621 ASSERT_GL_NO_ERROR();
622 }
623
624 void TearDown() override
625 {
626 glDeleteTextures(1, &mTexture2DA);
627 glDeleteTextures(1, &mTexture2DB);
628 TexCoordDrawTest::TearDown();
629 }
630
631 void testSamplerArrayDraw()
632 {
633 GLubyte texData[4];
634 texData[0] = 0;
635 texData[1] = 60;
636 texData[2] = 0;
637 texData[3] = 255;
638
639 glActiveTexture(GL_TEXTURE0);
640 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
641 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
642
643 texData[1] = 120;
644 glActiveTexture(GL_TEXTURE1);
645 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
646 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
647 EXPECT_GL_ERROR(GL_NO_ERROR);
648
649 glUseProgram(mProgram);
650 glUniform1i(mTexture0UniformLocation, 0);
651 glUniform1i(mTexture1UniformLocation, 1);
652 drawQuad(mProgram, "position", 0.5f);
653 EXPECT_GL_NO_ERROR();
654
655 EXPECT_PIXEL_NEAR(0, 0, 0, 180, 0, 255, 2);
656 }
657
658 GLuint mTexture2DA;
659 GLuint mTexture2DB;
660 GLint mTexture0UniformLocation;
661 GLint mTexture1UniformLocation;
662};
663
664
665class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest
666{
667 protected:
668 SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {}
669
670 std::string getFragmentShaderSource() override
671 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300672 return
673 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200674 uniform highp sampler2D tex2DArray[2];
675 varying vec2 texcoord;
676
677 vec4 computeFragColor(highp sampler2D aTex2DArray[2])
678 {
679 return texture2D(aTex2DArray[0], texcoord) + texture2D(aTex2DArray[1], texcoord);
680 }
681
682 void main()
683 {
684 gl_FragColor = computeFragColor(tex2DArray);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300685 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200686 }
687};
688
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200689class Texture2DArrayTestES3 : public TexCoordDrawTest
690{
691 protected:
692 Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {}
693
694 std::string getVertexShaderSource() override
695 {
696 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400697 "#version 300 es\n"
698 "out vec2 texcoord;\n"
699 "in vec4 position;\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200700 "void main()\n"
701 "{\n"
702 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
703 " texcoord = (position.xy * 0.5) + 0.5;\n"
704 "}\n");
705 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400706
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200707 std::string getFragmentShaderSource() override
708 {
709 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400710 "#version 300 es\n"
711 "precision highp float;\n"
Olli Etuaho183d7e22015-11-20 15:59:09 +0200712 "uniform highp sampler2DArray tex2DArray;\n"
Jamie Madill2453dbc2015-07-14 11:35:42 -0400713 "in vec2 texcoord;\n"
714 "out vec4 fragColor;\n"
715 "void main()\n"
716 "{\n"
717 " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200718 "}\n");
719 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400720
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200721 void SetUp() override
722 {
723 TexCoordDrawTest::SetUp();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400724
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300725 setUpProgram();
726
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200727 mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray");
Jamie Madill2453dbc2015-07-14 11:35:42 -0400728 ASSERT_NE(-1, mTextureArrayLocation);
729
730 glGenTextures(1, &m2DArrayTexture);
731 ASSERT_GL_NO_ERROR();
732 }
733
734 void TearDown() override
735 {
736 glDeleteTextures(1, &m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200737 TexCoordDrawTest::TearDown();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400738 }
739
740 GLuint m2DArrayTexture;
Jamie Madill2453dbc2015-07-14 11:35:42 -0400741 GLint mTextureArrayLocation;
742};
743
Olli Etuahobce743a2016-01-15 17:18:28 +0200744class TextureSizeTextureArrayTest : public TexCoordDrawTest
745{
746 protected:
747 TextureSizeTextureArrayTest()
748 : TexCoordDrawTest(),
749 mTexture2DA(0),
750 mTexture2DB(0),
751 mTexture0Location(-1),
752 mTexture1Location(-1)
753 {
754 }
755
756 std::string getVertexShaderSource() override
757 {
758 return std::string(
759 "#version 300 es\n"
760 "in vec4 position;\n"
761 "void main()\n"
762 "{\n"
763 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
764 "}\n");
765 }
766
767 std::string getFragmentShaderSource() override
768 {
769 return std::string(
770 "#version 300 es\n"
771 "precision highp float;\n"
772 "uniform highp sampler2D tex2DArray[2];\n"
773 "out vec4 fragColor;\n"
774 "void main()\n"
775 "{\n"
776 " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n"
777 " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n"
778 " fragColor = vec4(red, green, 0.0, 1.0);\n"
779 "}\n");
780 }
781
782 void SetUp() override
783 {
784 TexCoordDrawTest::SetUp();
785
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300786 setUpProgram();
787
Olli Etuahobce743a2016-01-15 17:18:28 +0200788 mTexture0Location = glGetUniformLocation(mProgram, "tex2DArray[0]");
789 ASSERT_NE(-1, mTexture0Location);
790 mTexture1Location = glGetUniformLocation(mProgram, "tex2DArray[1]");
791 ASSERT_NE(-1, mTexture1Location);
792
793 mTexture2DA = create2DTexture();
794 mTexture2DB = create2DTexture();
795 ASSERT_GL_NO_ERROR();
796 }
797
798 void TearDown() override
799 {
800 glDeleteTextures(1, &mTexture2DA);
801 glDeleteTextures(1, &mTexture2DB);
802 TexCoordDrawTest::TearDown();
803 }
804
805 GLuint mTexture2DA;
806 GLuint mTexture2DB;
807 GLint mTexture0Location;
808 GLint mTexture1Location;
809};
810
Olli Etuahoa314b612016-03-10 16:43:00 +0200811class Texture3DTestES3 : public TexCoordDrawTest
812{
813 protected:
814 Texture3DTestES3() : TexCoordDrawTest(), mTexture3D(0), mTexture3DUniformLocation(-1) {}
815
816 std::string getVertexShaderSource() override
817 {
818 return std::string(
819 "#version 300 es\n"
820 "out vec2 texcoord;\n"
821 "in vec4 position;\n"
822 "void main()\n"
823 "{\n"
824 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
825 " texcoord = (position.xy * 0.5) + 0.5;\n"
826 "}\n");
827 }
828
829 std::string getFragmentShaderSource() override
830 {
831 return std::string(
832 "#version 300 es\n"
833 "precision highp float;\n"
834 "uniform highp sampler3D tex3D;\n"
835 "in vec2 texcoord;\n"
836 "out vec4 fragColor;\n"
837 "void main()\n"
838 "{\n"
839 " fragColor = texture(tex3D, vec3(texcoord, 0.0));\n"
840 "}\n");
841 }
842
843 void SetUp() override
844 {
845 TexCoordDrawTest::SetUp();
846
847 glGenTextures(1, &mTexture3D);
848
849 setUpProgram();
850
851 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
852 ASSERT_NE(-1, mTexture3DUniformLocation);
853 }
854
855 void TearDown() override
856 {
857 glDeleteTextures(1, &mTexture3D);
858 TexCoordDrawTest::TearDown();
859 }
860
861 GLuint mTexture3D;
862 GLint mTexture3DUniformLocation;
863};
864
Olli Etuaho1a679902016-01-14 12:21:47 +0200865class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest
866{
867 protected:
868 ShadowSamplerPlusSampler3DTestES3()
869 : TexCoordDrawTest(),
870 mTextureShadow(0),
871 mTexture3D(0),
872 mTextureShadowUniformLocation(-1),
873 mTexture3DUniformLocation(-1),
874 mDepthRefUniformLocation(-1)
875 {
876 }
877
878 std::string getVertexShaderSource() override
879 {
880 return std::string(
881 "#version 300 es\n"
882 "out vec2 texcoord;\n"
883 "in vec4 position;\n"
884 "void main()\n"
885 "{\n"
886 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
887 " texcoord = (position.xy * 0.5) + 0.5;\n"
888 "}\n");
889 }
890
891 std::string getFragmentShaderSource() override
892 {
893 return std::string(
894 "#version 300 es\n"
895 "precision highp float;\n"
896 "uniform highp sampler2DShadow tex2DShadow;\n"
897 "uniform highp sampler3D tex3D;\n"
898 "in vec2 texcoord;\n"
899 "uniform float depthRef;\n"
900 "out vec4 fragColor;\n"
901 "void main()\n"
902 "{\n"
903 " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n"
904 " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n"
905 "}\n");
906 }
907
908 void SetUp() override
909 {
910 TexCoordDrawTest::SetUp();
911
912 glGenTextures(1, &mTexture3D);
913
914 glGenTextures(1, &mTextureShadow);
915 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
916 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
917
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300918 setUpProgram();
919
Olli Etuaho1a679902016-01-14 12:21:47 +0200920 mTextureShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
921 ASSERT_NE(-1, mTextureShadowUniformLocation);
922 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
923 ASSERT_NE(-1, mTexture3DUniformLocation);
924 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
925 ASSERT_NE(-1, mDepthRefUniformLocation);
926 }
927
928 void TearDown() override
929 {
930 glDeleteTextures(1, &mTextureShadow);
931 glDeleteTextures(1, &mTexture3D);
932 TexCoordDrawTest::TearDown();
933 }
934
935 GLuint mTextureShadow;
936 GLuint mTexture3D;
937 GLint mTextureShadowUniformLocation;
938 GLint mTexture3DUniformLocation;
939 GLint mDepthRefUniformLocation;
940};
941
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200942class SamplerTypeMixTestES3 : public TexCoordDrawTest
943{
944 protected:
945 SamplerTypeMixTestES3()
946 : TexCoordDrawTest(),
947 mTexture2D(0),
948 mTextureCube(0),
949 mTexture2DShadow(0),
950 mTextureCubeShadow(0),
951 mTexture2DUniformLocation(-1),
952 mTextureCubeUniformLocation(-1),
953 mTexture2DShadowUniformLocation(-1),
954 mTextureCubeShadowUniformLocation(-1),
955 mDepthRefUniformLocation(-1)
956 {
957 }
958
959 std::string getVertexShaderSource() override
960 {
961 return std::string(
962 "#version 300 es\n"
963 "out vec2 texcoord;\n"
964 "in vec4 position;\n"
965 "void main()\n"
966 "{\n"
967 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
968 " texcoord = (position.xy * 0.5) + 0.5;\n"
969 "}\n");
970 }
971
972 std::string getFragmentShaderSource() override
973 {
974 return std::string(
975 "#version 300 es\n"
976 "precision highp float;\n"
977 "uniform highp sampler2D tex2D;\n"
978 "uniform highp samplerCube texCube;\n"
979 "uniform highp sampler2DShadow tex2DShadow;\n"
980 "uniform highp samplerCubeShadow texCubeShadow;\n"
981 "in vec2 texcoord;\n"
982 "uniform float depthRef;\n"
983 "out vec4 fragColor;\n"
984 "void main()\n"
985 "{\n"
986 " fragColor = texture(tex2D, texcoord);\n"
987 " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n"
988 " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n"
989 " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * "
990 "0.125);\n"
991 "}\n");
992 }
993
994 void SetUp() override
995 {
996 TexCoordDrawTest::SetUp();
997
998 glGenTextures(1, &mTexture2D);
999 glGenTextures(1, &mTextureCube);
1000
1001 glGenTextures(1, &mTexture2DShadow);
1002 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
1003 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
1004
1005 glGenTextures(1, &mTextureCubeShadow);
1006 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
1007 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
1008
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001009 setUpProgram();
1010
Olli Etuahoc8c99a02016-01-14 16:47:22 +02001011 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
1012 ASSERT_NE(-1, mTexture2DUniformLocation);
1013 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
1014 ASSERT_NE(-1, mTextureCubeUniformLocation);
1015 mTexture2DShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
1016 ASSERT_NE(-1, mTexture2DShadowUniformLocation);
1017 mTextureCubeShadowUniformLocation = glGetUniformLocation(mProgram, "texCubeShadow");
1018 ASSERT_NE(-1, mTextureCubeShadowUniformLocation);
1019 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
1020 ASSERT_NE(-1, mDepthRefUniformLocation);
1021
1022 ASSERT_GL_NO_ERROR();
1023 }
1024
1025 void TearDown() override
1026 {
1027 glDeleteTextures(1, &mTexture2D);
1028 glDeleteTextures(1, &mTextureCube);
1029 glDeleteTextures(1, &mTexture2DShadow);
1030 glDeleteTextures(1, &mTextureCubeShadow);
1031 TexCoordDrawTest::TearDown();
1032 }
1033
1034 GLuint mTexture2D;
1035 GLuint mTextureCube;
1036 GLuint mTexture2DShadow;
1037 GLuint mTextureCubeShadow;
1038 GLint mTexture2DUniformLocation;
1039 GLint mTextureCubeUniformLocation;
1040 GLint mTexture2DShadowUniformLocation;
1041 GLint mTextureCubeShadowUniformLocation;
1042 GLint mDepthRefUniformLocation;
1043};
1044
Olli Etuaho96963162016-03-21 11:54:33 +02001045class SamplerInStructTest : public Texture2DTest
1046{
1047 protected:
1048 SamplerInStructTest() : Texture2DTest() {}
1049
1050 const char *getTextureUniformName() override { return "us.tex"; }
1051
1052 std::string getFragmentShaderSource() override
1053 {
1054 return std::string(
1055 "precision highp float;\n"
1056 "struct S\n"
1057 "{\n"
1058 " vec4 a;\n"
1059 " highp sampler2D tex;\n"
1060 "};\n"
1061 "uniform S us;\n"
1062 "varying vec2 texcoord;\n"
1063 "void main()\n"
1064 "{\n"
1065 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x);\n"
1066 "}\n");
1067 }
1068
1069 void runSamplerInStructTest()
1070 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001071 setUpProgram();
1072
Olli Etuaho96963162016-03-21 11:54:33 +02001073 glActiveTexture(GL_TEXTURE0);
1074 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001075 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1076 &GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001077 drawQuad(mProgram, "position", 0.5f);
Olli Etuahoa314b612016-03-10 16:43:00 +02001078 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001079 }
1080};
1081
1082class SamplerInStructAsFunctionParameterTest : public SamplerInStructTest
1083{
1084 protected:
1085 SamplerInStructAsFunctionParameterTest() : SamplerInStructTest() {}
1086
1087 std::string getFragmentShaderSource() override
1088 {
1089 return std::string(
1090 "precision highp float;\n"
1091 "struct S\n"
1092 "{\n"
1093 " vec4 a;\n"
1094 " highp sampler2D tex;\n"
1095 "};\n"
1096 "uniform S us;\n"
1097 "varying vec2 texcoord;\n"
1098 "vec4 sampleFrom(S s) {\n"
1099 " return texture2D(s.tex, texcoord + s.a.x);\n"
1100 "}\n"
1101 "void main()\n"
1102 "{\n"
1103 " gl_FragColor = sampleFrom(us);\n"
1104 "}\n");
1105 }
1106};
1107
1108class SamplerInStructArrayAsFunctionParameterTest : public SamplerInStructTest
1109{
1110 protected:
1111 SamplerInStructArrayAsFunctionParameterTest() : SamplerInStructTest() {}
1112
1113 const char *getTextureUniformName() override { return "us[0].tex"; }
1114
1115 std::string getFragmentShaderSource() override
1116 {
1117 return std::string(
1118 "precision highp float;\n"
1119 "struct S\n"
1120 "{\n"
1121 " vec4 a;\n"
1122 " highp sampler2D tex;\n"
1123 "};\n"
1124 "uniform S us[1];\n"
1125 "varying vec2 texcoord;\n"
1126 "vec4 sampleFrom(S s) {\n"
1127 " return texture2D(s.tex, texcoord + s.a.x);\n"
1128 "}\n"
1129 "void main()\n"
1130 "{\n"
1131 " gl_FragColor = sampleFrom(us[0]);\n"
1132 "}\n");
1133 }
1134};
1135
1136class SamplerInNestedStructAsFunctionParameterTest : public SamplerInStructTest
1137{
1138 protected:
1139 SamplerInNestedStructAsFunctionParameterTest() : SamplerInStructTest() {}
1140
1141 const char *getTextureUniformName() override { return "us[0].sub.tex"; }
1142
1143 std::string getFragmentShaderSource() override
1144 {
1145 return std::string(
1146 "precision highp float;\n"
1147 "struct SUB\n"
1148 "{\n"
1149 " vec4 a;\n"
1150 " highp sampler2D tex;\n"
1151 "};\n"
1152 "struct S\n"
1153 "{\n"
1154 " SUB sub;\n"
1155 "};\n"
1156 "uniform S us[1];\n"
1157 "varying vec2 texcoord;\n"
1158 "vec4 sampleFrom(SUB s) {\n"
1159 " return texture2D(s.tex, texcoord + s.a.x);\n"
1160 "}\n"
1161 "void main()\n"
1162 "{\n"
1163 " gl_FragColor = sampleFrom(us[0].sub);\n"
1164 "}\n");
1165 }
1166};
1167
1168class SamplerInStructAndOtherVariableTest : public SamplerInStructTest
1169{
1170 protected:
1171 SamplerInStructAndOtherVariableTest() : SamplerInStructTest() {}
1172
1173 std::string getFragmentShaderSource() override
1174 {
1175 return std::string(
1176 "precision highp float;\n"
1177 "struct S\n"
1178 "{\n"
1179 " vec4 a;\n"
1180 " highp sampler2D tex;\n"
1181 "};\n"
1182 "uniform S us;\n"
1183 "uniform float us_tex;\n"
1184 "varying vec2 texcoord;\n"
1185 "void main()\n"
1186 "{\n"
1187 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x + us_tex);\n"
1188 "}\n");
1189 }
1190};
1191
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001192TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001193{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001194 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001195 EXPECT_GL_ERROR(GL_NO_ERROR);
1196
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001197 setUpProgram();
1198
Jamie Madillf67115c2014-04-22 13:14:05 -04001199 const GLubyte *pixels[20] = { 0 };
1200 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1201 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001202
1203 if (extensionEnabled("GL_EXT_texture_storage"))
1204 {
1205 // Create a 1-level immutable texture.
1206 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1207
1208 // Try calling sub image on the second level.
1209 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1210 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1211 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001212}
Geoff Langc41e42d2014-04-28 10:58:16 -04001213
John Bauman18319182016-09-28 14:22:27 -07001214// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1215TEST_P(Texture2DTest, QueryBinding)
1216{
1217 glBindTexture(GL_TEXTURE_2D, 0);
1218 EXPECT_GL_ERROR(GL_NO_ERROR);
1219
1220 GLint textureBinding;
1221 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1222 EXPECT_GL_NO_ERROR();
1223 EXPECT_EQ(0, textureBinding);
1224
1225 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
1226 if (extensionEnabled("GL_OES_EGL_image_external") ||
1227 extensionEnabled("GL_NV_EGL_stream_consumer_external"))
1228 {
1229 EXPECT_GL_NO_ERROR();
1230 EXPECT_EQ(0, textureBinding);
1231 }
1232 else
1233 {
1234 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1235 }
1236}
1237
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001238TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001239{
Luc Ferrond8c632c2018-04-10 12:31:44 -04001240 // TODO(lucferron): Enable this test on Vulkan after Sampler Arrays are implemented.
1241 // http://anglebug.com/2462
Luc Ferron5164b792018-03-06 09:10:12 -05001242 ANGLE_SKIP_TEST_IF(IsVulkan());
1243
Jamie Madilld4cfa572014-07-08 10:00:32 -04001244 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001245 EXPECT_GL_ERROR(GL_NO_ERROR);
1246
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001247 setUpProgram();
1248
Geoff Langc41e42d2014-04-28 10:58:16 -04001249 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001250 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001251 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001252 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001253
1254 const GLubyte *pixel[4] = { 0 };
1255
1256 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1257 EXPECT_GL_NO_ERROR();
1258
1259 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1260 EXPECT_GL_NO_ERROR();
1261
1262 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1263 EXPECT_GL_NO_ERROR();
1264}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001265
1266// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001267TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001268{
1269 glActiveTexture(GL_TEXTURE0);
1270 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1271 glActiveTexture(GL_TEXTURE1);
1272 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1273 EXPECT_GL_ERROR(GL_NO_ERROR);
1274
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001275 glUseProgram(mProgram);
1276 glUniform1i(mTexture2DUniformLocation, 0);
1277 glUniform1i(mTextureCubeUniformLocation, 1);
1278 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001279 EXPECT_GL_NO_ERROR();
1280}
Jamie Madill9aca0592014-10-06 16:26:59 -04001281
Olli Etuaho53a2da12016-01-11 15:43:32 +02001282// Test drawing with two texture types accessed from the same shader and check that the result of
1283// drawing is correct.
1284TEST_P(TextureCubeTest, CubeMapDraw)
1285{
1286 GLubyte texData[4];
1287 texData[0] = 0;
1288 texData[1] = 60;
1289 texData[2] = 0;
1290 texData[3] = 255;
1291
1292 glActiveTexture(GL_TEXTURE0);
1293 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1294 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1295
1296 glActiveTexture(GL_TEXTURE1);
1297 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1298 texData[1] = 120;
1299 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1300 texData);
1301 EXPECT_GL_ERROR(GL_NO_ERROR);
1302
1303 glUseProgram(mProgram);
1304 glUniform1i(mTexture2DUniformLocation, 0);
1305 glUniform1i(mTextureCubeUniformLocation, 1);
1306 drawQuad(mProgram, "position", 0.5f);
1307 EXPECT_GL_NO_ERROR();
1308
1309 int px = getWindowWidth() - 1;
1310 int py = 0;
1311 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1312}
1313
Olli Etuaho4644a202016-01-12 15:12:53 +02001314TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1315{
1316 glActiveTexture(GL_TEXTURE0);
1317 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1318 GLubyte texData[4];
1319 texData[0] = 0;
1320 texData[1] = 128;
1321 texData[2] = 0;
1322 texData[3] = 255;
1323 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1324 glUseProgram(mProgram);
1325 glUniform1i(mTexture2DUniformLocation, 0);
1326 drawQuad(mProgram, "position", 0.5f);
1327 EXPECT_GL_NO_ERROR();
1328
1329 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1330}
1331
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001332// Test drawing with two textures passed to the shader in a sampler array.
1333TEST_P(SamplerArrayTest, SamplerArrayDraw)
1334{
1335 testSamplerArrayDraw();
1336}
1337
1338// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1339// user-defined function in the shader.
1340TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1341{
1342 testSamplerArrayDraw();
1343}
1344
Jamie Madill9aca0592014-10-06 16:26:59 -04001345// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001346TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001347{
1348 int px = getWindowWidth() / 2;
1349 int py = getWindowHeight() / 2;
1350
1351 glActiveTexture(GL_TEXTURE0);
1352 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1353
Olli Etuahoa314b612016-03-10 16:43:00 +02001354 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001355
Olli Etuahoa314b612016-03-10 16:43:00 +02001356 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001357 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1358 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1359 glGenerateMipmap(GL_TEXTURE_2D);
1360
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001361 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001362 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001363 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1364 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001365 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001366 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001367
Olli Etuahoa314b612016-03-10 16:43:00 +02001368 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001369
Olli Etuahoa314b612016-03-10 16:43:00 +02001370 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1371 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001372 glGenerateMipmap(GL_TEXTURE_2D);
1373
Olli Etuahoa314b612016-03-10 16:43:00 +02001374 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001375
Olli Etuahoa314b612016-03-10 16:43:00 +02001376 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1377 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001378 glGenerateMipmap(GL_TEXTURE_2D);
1379
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001380 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001381
1382 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001383 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001384}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001385
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001386// Test creating a FBO with a cube map render target, to test an ANGLE bug
1387// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001388TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001389{
1390 GLuint fbo;
1391 glGenFramebuffers(1, &fbo);
1392 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1393
1394 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1395 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mTextureCube, 0);
1396
Corentin Wallez322653b2015-06-17 18:33:56 +02001397 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001398
1399 glDeleteFramebuffers(1, &fbo);
1400
1401 EXPECT_GL_NO_ERROR();
1402}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001403
1404// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001405TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001406{
Yunchao He9550c602018-02-13 14:47:05 +08001407 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -04001408
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001409 int width = getWindowWidth();
1410 int height = getWindowHeight();
1411
1412 GLuint tex2D;
1413 glGenTextures(1, &tex2D);
1414 glActiveTexture(GL_TEXTURE0);
1415 glBindTexture(GL_TEXTURE_2D, tex2D);
1416
1417 // Fill with red
1418 std::vector<GLubyte> pixels(3 * 16 * 16);
1419 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1420 {
1421 pixels[pixelId * 3 + 0] = 255;
1422 pixels[pixelId * 3 + 1] = 0;
1423 pixels[pixelId * 3 + 2] = 0;
1424 }
1425
1426 // ANGLE internally uses RGBA as the DirectX format for RGB images
1427 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1428 // The data is kept in a CPU-side image and the image is marked as dirty.
Geoff Langc4e93662017-05-01 10:45:59 -04001429 if (getClientMajorVersion() >= 3)
1430 {
1431 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1432 }
1433 else
1434 {
1435 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1436 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001437
1438 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1439 // glTexSubImage2D should take into account that the image is dirty.
1440 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1441 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1442 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1443
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001444 setUpProgram();
1445
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001446 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001447 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001448 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001449 glDeleteTextures(1, &tex2D);
1450 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001451 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001452
1453 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001454 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1455 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001456}
1457
1458// Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001459TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001460{
1461 if (extensionEnabled("NV_pixel_buffer_object"))
1462 {
1463 int width = getWindowWidth();
1464 int height = getWindowHeight();
1465
1466 GLuint tex2D;
1467 glGenTextures(1, &tex2D);
1468 glActiveTexture(GL_TEXTURE0);
1469 glBindTexture(GL_TEXTURE_2D, tex2D);
1470
1471 // Fill with red
1472 std::vector<GLubyte> pixels(3 * 16 * 16);
1473 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1474 {
1475 pixels[pixelId * 3 + 0] = 255;
1476 pixels[pixelId * 3 + 1] = 0;
1477 pixels[pixelId * 3 + 2] = 0;
1478 }
1479
1480 // Read 16x16 region from red backbuffer to PBO
1481 GLuint pbo;
1482 glGenBuffers(1, &pbo);
1483 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1484 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1485
1486 // ANGLE internally uses RGBA as the DirectX format for RGB images
1487 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1488 // The data is kept in a CPU-side image and the image is marked as dirty.
1489 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1490
1491 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1492 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001493 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001494 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1495 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1496
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001497 setUpProgram();
1498
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001499 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001500 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001501 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001502 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001503 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001504 EXPECT_GL_NO_ERROR();
1505 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1506 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1507 }
1508}
Jamie Madillbc393df2015-01-29 13:46:07 -05001509
1510// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001511TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001512{
1513 testFloatCopySubImage(1, 1);
1514}
1515
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001516TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001517{
1518 testFloatCopySubImage(2, 1);
1519}
1520
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001521TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001522{
1523 testFloatCopySubImage(2, 2);
1524}
1525
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001526TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001527{
1528 testFloatCopySubImage(3, 1);
1529}
1530
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001531TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001532{
1533 testFloatCopySubImage(3, 2);
1534}
1535
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001536TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001537{
Yunchao He9550c602018-02-13 14:47:05 +08001538 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1539 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001540
Yunchao He9550c602018-02-13 14:47:05 +08001541 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1542 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001543
Jamie Madillbc393df2015-01-29 13:46:07 -05001544 testFloatCopySubImage(3, 3);
1545}
1546
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001547TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001548{
1549 testFloatCopySubImage(4, 1);
1550}
1551
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001552TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001553{
1554 testFloatCopySubImage(4, 2);
1555}
1556
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001557TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001558{
Yunchao He9550c602018-02-13 14:47:05 +08001559 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1560 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001561
Jamie Madillbc393df2015-01-29 13:46:07 -05001562 testFloatCopySubImage(4, 3);
1563}
1564
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001565TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001566{
Yunchao He9550c602018-02-13 14:47:05 +08001567 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1568 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001569
Jamie Madillbc393df2015-01-29 13:46:07 -05001570 testFloatCopySubImage(4, 4);
1571}
Austin Kinross07285142015-03-26 11:36:16 -07001572
1573// Port of https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1574// Run against GL_ALPHA/UNSIGNED_BYTE format, to ensure that D3D11 Feature Level 9_3 correctly handles GL_ALPHA
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001575TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001576{
Luc Ferron5164b792018-03-06 09:10:12 -05001577 // TODO(lucferron): DIRTY_BIT_UNPACK_STATE isn't implemented on Vulkan yet.
1578 ANGLE_SKIP_TEST_IF(IsVulkan());
1579
Austin Kinross07285142015-03-26 11:36:16 -07001580 const int npotTexSize = 5;
1581 const int potTexSize = 4; // Should be less than npotTexSize
1582 GLuint tex2D;
1583
1584 if (extensionEnabled("GL_OES_texture_npot"))
1585 {
1586 // This test isn't applicable if texture_npot is enabled
1587 return;
1588 }
1589
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001590 setUpProgram();
1591
Austin Kinross07285142015-03-26 11:36:16 -07001592 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1593
Austin Kinross5faa15b2016-01-11 13:32:48 -08001594 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1595 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1596
Austin Kinross07285142015-03-26 11:36:16 -07001597 glActiveTexture(GL_TEXTURE0);
1598 glGenTextures(1, &tex2D);
1599 glBindTexture(GL_TEXTURE_2D, tex2D);
1600
1601 std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize);
1602 for (size_t pixelId = 0; pixelId < npotTexSize * npotTexSize; ++pixelId)
1603 {
1604 pixels[pixelId] = 64;
1605 }
1606
1607 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1608 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1609
1610 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
1611 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1612 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1613
1614 // Check that an NPOT texture on level 0 succeeds
1615 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1616 EXPECT_GL_NO_ERROR();
1617
1618 // Check that generateMipmap fails on NPOT
1619 glGenerateMipmap(GL_TEXTURE_2D);
1620 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1621
1622 // Check that nothing is drawn if filtering is not correct for NPOT
1623 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1624 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1625 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1626 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1627 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001628 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001629 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1630
1631 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1632 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1633 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1634 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1635 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001636 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001637 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1638
1639 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1640 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1641 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001642 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001643 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1644
1645 // Check that glTexImage2D for POT texture succeeds
1646 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1647 EXPECT_GL_NO_ERROR();
1648
1649 // Check that generateMipmap for an POT texture succeeds
1650 glGenerateMipmap(GL_TEXTURE_2D);
1651 EXPECT_GL_NO_ERROR();
1652
1653 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1654 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1655 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1656 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1657 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1658 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001659 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001660 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1661 EXPECT_GL_NO_ERROR();
1662}
Jamie Madillfa05f602015-05-07 13:47:11 -04001663
Austin Kinross08528e12015-10-07 16:24:40 -07001664// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1665// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001666TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001667{
Luc Ferron5164b792018-03-06 09:10:12 -05001668 // TODO(lucferron): Generate mipmap on vulkan isn't implemented yet. Re-enable this when it
1669 // is.
1670 ANGLE_SKIP_TEST_IF(IsVulkan());
1671
Austin Kinross08528e12015-10-07 16:24:40 -07001672 glActiveTexture(GL_TEXTURE0);
1673 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1674
1675 // Create an 8x8 (i.e. power-of-two) texture.
1676 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1677 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1678 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1679 glGenerateMipmap(GL_TEXTURE_2D);
1680
1681 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1682 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001683 std::array<GLColor, 3 * 3> data;
1684 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001685
1686 EXPECT_GL_NO_ERROR();
1687}
1688
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001689// Test to check that texture completeness is determined correctly when the texture base level is
1690// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1691TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1692{
1693 glActiveTexture(GL_TEXTURE0);
1694 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001695
1696 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1697 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1698 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1699 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1700 texDataGreen.data());
1701 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1702 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001703 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1704 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1705 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1706
1707 EXPECT_GL_NO_ERROR();
1708
1709 drawQuad(mProgram, "position", 0.5f);
1710
Olli Etuahoa314b612016-03-10 16:43:00 +02001711 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1712}
1713
1714// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1715// have images defined.
1716TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1717{
Yunchao He9550c602018-02-13 14:47:05 +08001718 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1719 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1720
Olli Etuahoa314b612016-03-10 16:43:00 +02001721 glActiveTexture(GL_TEXTURE0);
1722 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1723 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1724 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1725 texDataGreen.data());
1726 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1727 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1728 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1729 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1730
1731 EXPECT_GL_NO_ERROR();
1732
1733 drawQuad(mProgram, "position", 0.5f);
1734
1735 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1736}
1737
Olli Etuahoe8528d82016-05-16 17:50:52 +03001738// Test that drawing works correctly when level 0 is undefined and base level is 1.
1739TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1740{
Yunchao He9550c602018-02-13 14:47:05 +08001741 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1742 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1743
Olli Etuahoe8528d82016-05-16 17:50:52 +03001744 glActiveTexture(GL_TEXTURE0);
1745 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1746 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1747 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1748 texDataGreen.data());
1749 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1750 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1751 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1752 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1753
1754 EXPECT_GL_NO_ERROR();
1755
1756 // Texture is incomplete.
1757 drawQuad(mProgram, "position", 0.5f);
1758 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1759
1760 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1761 texDataGreen.data());
1762
1763 // Texture is now complete.
1764 drawQuad(mProgram, "position", 0.5f);
1765 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1766}
1767
Olli Etuahoa314b612016-03-10 16:43:00 +02001768// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1769// dimensions that don't fit the images inside the range.
1770// GLES 3.0.4 section 3.8.13 Texture completeness
1771TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1772{
Olli Etuahoa314b612016-03-10 16:43:00 +02001773 glActiveTexture(GL_TEXTURE0);
1774 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1775 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1776 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1777 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1778
1779 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1780 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1781
1782 // Two levels that are initially unused.
1783 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1784 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1785 texDataCyan.data());
1786
1787 // One level that is used - only this level should affect completeness.
1788 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1789 texDataGreen.data());
1790
1791 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1792 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1793
1794 EXPECT_GL_NO_ERROR();
1795
1796 drawQuad(mProgram, "position", 0.5f);
1797
1798 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1799
Yunchao He2f23f352018-02-11 22:11:37 +08001800 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001801
1802 // Switch the level that is being used to the cyan level 2.
1803 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1804 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1805
1806 EXPECT_GL_NO_ERROR();
1807
1808 drawQuad(mProgram, "position", 0.5f);
1809
1810 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1811}
1812
1813// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1814// have images defined.
1815TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1816{
Olli Etuahoa314b612016-03-10 16:43:00 +02001817 glActiveTexture(GL_TEXTURE0);
1818 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1819 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1820 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1821 texDataGreen.data());
1822 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1823 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1824 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1825 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1826
1827 EXPECT_GL_NO_ERROR();
1828
1829 drawQuad(mProgram, "position", 0.5f);
1830
1831 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1832}
1833
1834// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1835// dimensions that don't fit the images inside the range.
1836// GLES 3.0.4 section 3.8.13 Texture completeness
1837TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1838{
Olli Etuahoa314b612016-03-10 16:43:00 +02001839 glActiveTexture(GL_TEXTURE0);
1840 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1841 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1842 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1843 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1844
1845 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1846 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1847
1848 // Two levels that are initially unused.
1849 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1850 texDataRed.data());
1851 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1852 texDataCyan.data());
1853
1854 // One level that is used - only this level should affect completeness.
1855 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1856 texDataGreen.data());
1857
1858 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1859 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1860
1861 EXPECT_GL_NO_ERROR();
1862
1863 drawQuad(mProgram, "position", 0.5f);
1864
1865 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1866
Yunchao He2f23f352018-02-11 22:11:37 +08001867 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001868
1869 // Switch the level that is being used to the cyan level 2.
1870 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
1871 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
1872
1873 EXPECT_GL_NO_ERROR();
1874
1875 drawQuad(mProgram, "position", 0.5f);
1876
1877 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1878}
1879
1880// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1881// have images defined.
1882TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
1883{
Olli Etuahoa314b612016-03-10 16:43:00 +02001884 glActiveTexture(GL_TEXTURE0);
1885 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
1886 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1887 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1888 texDataGreen.data());
1889 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1890 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1891 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1892 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1893
1894 EXPECT_GL_NO_ERROR();
1895
1896 drawQuad(mProgram, "position", 0.5f);
1897
1898 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1899}
1900
1901// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1902// dimensions that don't fit the images inside the range.
1903// GLES 3.0.4 section 3.8.13 Texture completeness
1904TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1905{
Olli Etuahoa314b612016-03-10 16:43:00 +02001906 glActiveTexture(GL_TEXTURE0);
1907 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
1908 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1909 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1910 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1911
1912 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1913 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1914
1915 // Two levels that are initially unused.
1916 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1917 texDataRed.data());
1918 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1919 texDataCyan.data());
1920
1921 // One level that is used - only this level should affect completeness.
1922 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1923 texDataGreen.data());
1924
1925 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1926 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1927
1928 EXPECT_GL_NO_ERROR();
1929
1930 drawQuad(mProgram, "position", 0.5f);
1931
1932 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1933
Yunchao He2f23f352018-02-11 22:11:37 +08001934 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
1935
Yunchao He9550c602018-02-13 14:47:05 +08001936 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
1937 // level was changed.
1938 ANGLE_SKIP_TEST_IF(IsNVIDIA() && (IsOpenGL() || IsOpenGLES()));
Olli Etuahoa314b612016-03-10 16:43:00 +02001939
1940 // Switch the level that is being used to the cyan level 2.
1941 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
1942 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
1943
1944 EXPECT_GL_NO_ERROR();
1945
1946 drawQuad(mProgram, "position", 0.5f);
1947
1948 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1949}
1950
1951// Test that texture completeness is updated if texture max level changes.
1952// GLES 3.0.4 section 3.8.13 Texture completeness
1953TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
1954{
Olli Etuahoa314b612016-03-10 16:43:00 +02001955 glActiveTexture(GL_TEXTURE0);
1956 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1957 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
1958
1959 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1960 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1961
1962 // A level that is initially unused.
1963 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1964 texDataGreen.data());
1965
1966 // One level that is initially used - only this level should affect completeness.
1967 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1968 texDataGreen.data());
1969
1970 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
1971 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
1972
1973 EXPECT_GL_NO_ERROR();
1974
1975 drawQuad(mProgram, "position", 0.5f);
1976
1977 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1978
1979 // Switch the max level to level 1. The levels within the used range now have inconsistent
1980 // dimensions and the texture should be incomplete.
1981 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1982
1983 EXPECT_GL_NO_ERROR();
1984
1985 drawQuad(mProgram, "position", 0.5f);
1986
1987 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1988}
1989
1990// Test that 3D texture completeness is updated if texture max level changes.
1991// GLES 3.0.4 section 3.8.13 Texture completeness
1992TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
1993{
Olli Etuahoa314b612016-03-10 16:43:00 +02001994 glActiveTexture(GL_TEXTURE0);
1995 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1996 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1997
1998 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1999 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2000
2001 // A level that is initially unused.
2002 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2003 texDataGreen.data());
2004
2005 // One level that is initially used - only this level should affect completeness.
2006 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2007 texDataGreen.data());
2008
2009 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2010 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2011
2012 EXPECT_GL_NO_ERROR();
2013
2014 drawQuad(mProgram, "position", 0.5f);
2015
2016 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2017
2018 // Switch the max level to level 1. The levels within the used range now have inconsistent
2019 // dimensions and the texture should be incomplete.
2020 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2021
2022 EXPECT_GL_NO_ERROR();
2023
2024 drawQuad(mProgram, "position", 0.5f);
2025
2026 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2027}
2028
2029// Test that texture completeness is updated if texture base level changes.
2030// GLES 3.0.4 section 3.8.13 Texture completeness
2031TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2032{
Olli Etuahoa314b612016-03-10 16:43:00 +02002033 glActiveTexture(GL_TEXTURE0);
2034 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2035 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2036
2037 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2038 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2039
2040 // Two levels that are initially unused.
2041 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2042 texDataGreen.data());
2043 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2044 texDataGreen.data());
2045
2046 // One level that is initially used - only this level should affect completeness.
2047 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2048 texDataGreen.data());
2049
2050 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2051 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2052
2053 EXPECT_GL_NO_ERROR();
2054
2055 drawQuad(mProgram, "position", 0.5f);
2056
2057 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2058
2059 // Switch the base level to level 1. The levels within the used range now have inconsistent
2060 // dimensions and the texture should be incomplete.
2061 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2062
2063 EXPECT_GL_NO_ERROR();
2064
2065 drawQuad(mProgram, "position", 0.5f);
2066
2067 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2068}
2069
2070// Test that texture is not complete if base level is greater than max level.
2071// GLES 3.0.4 section 3.8.13 Texture completeness
2072TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2073{
Olli Etuahoa314b612016-03-10 16:43:00 +02002074 glActiveTexture(GL_TEXTURE0);
2075 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2076
2077 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2078 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2079
2080 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2081
2082 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2083 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2084
2085 EXPECT_GL_NO_ERROR();
2086
2087 drawQuad(mProgram, "position", 0.5f);
2088
2089 // Texture should be incomplete.
2090 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2091}
2092
2093// Test that immutable texture base level and max level are clamped.
2094// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2095TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2096{
Olli Etuahoa314b612016-03-10 16:43:00 +02002097 glActiveTexture(GL_TEXTURE0);
2098 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2099
2100 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2101 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2102
2103 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2104
2105 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2106
2107 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2108 // should be clamped to [base_level, levels - 1].
2109 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2110 // In the case of this test, those rules make the effective base level and max level 0.
2111 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2112 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2113
2114 EXPECT_GL_NO_ERROR();
2115
2116 drawQuad(mProgram, "position", 0.5f);
2117
2118 // Texture should be complete.
2119 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2120}
2121
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002122// Test that changing base level works when it affects the format of the texture.
2123TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2124{
Yunchao He9550c602018-02-13 14:47:05 +08002125 // Observed rendering corruption on NVIDIA OpenGL.
2126 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL());
2127
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002128 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002129
2130 // Observed incorrect rendering on AMD OpenGL.
2131 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002132
2133 glActiveTexture(GL_TEXTURE0);
2134 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2135 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2136 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2137
2138 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2139 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2140
2141 // RGBA8 level that's initially unused.
2142 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2143 texDataCyan.data());
2144
2145 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2146 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2147
2148 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2149 // format. It reads green channel data from the green and alpha channels of texDataGreen
2150 // (this is a bit hacky but works).
2151 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2152
2153 EXPECT_GL_NO_ERROR();
2154
2155 drawQuad(mProgram, "position", 0.5f);
2156
2157 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2158
2159 // Switch the texture to use the cyan level 0 with the RGBA format.
2160 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2161 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2162
2163 EXPECT_GL_NO_ERROR();
2164
2165 drawQuad(mProgram, "position", 0.5f);
2166
2167 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2168}
2169
Olli Etuahoa314b612016-03-10 16:43:00 +02002170// Test that setting a texture image works when base level is out of range.
2171TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2172{
2173 glActiveTexture(GL_TEXTURE0);
2174 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2175
2176 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2177 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2178
2179 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2180 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2181
2182 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2183
2184 EXPECT_GL_NO_ERROR();
2185
2186 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2187
2188 drawQuad(mProgram, "position", 0.5f);
2189
2190 // Texture should be complete.
2191 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002192}
2193
Jamie Madill2453dbc2015-07-14 11:35:42 -04002194// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG RBA->RGBA8, with 1.0
2195// in the alpha channel. This test covers a bug where redefining array textures with these formats does not work as
2196// expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002197TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002198{
2199 std::vector<GLubyte> pixelData;
2200 for (size_t count = 0; count < 5000; count++)
2201 {
2202 pixelData.push_back(0u);
2203 pixelData.push_back(255u);
2204 pixelData.push_back(0u);
2205 }
2206
2207 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002208 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002209 glUniform1i(mTextureArrayLocation, 0);
2210
2211 // The first draw worked correctly.
2212 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
2213
2214 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2215 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2216 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2217 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002218 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002219 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002220
2221 // The dimension of the respecification must match the original exactly to trigger the bug.
2222 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002223 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002224 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002225
2226 ASSERT_GL_NO_ERROR();
2227}
2228
Olli Etuaho1a679902016-01-14 12:21:47 +02002229// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2230// This test is needed especially to confirm that sampler registers get assigned correctly on
2231// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2232TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2233{
2234 glActiveTexture(GL_TEXTURE0);
2235 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2236 GLubyte texData[4];
2237 texData[0] = 0;
2238 texData[1] = 60;
2239 texData[2] = 0;
2240 texData[3] = 255;
2241 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2242
2243 glActiveTexture(GL_TEXTURE1);
2244 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2245 GLfloat depthTexData[1];
2246 depthTexData[0] = 0.5f;
2247 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2248 depthTexData);
2249
2250 glUseProgram(mProgram);
2251 glUniform1f(mDepthRefUniformLocation, 0.3f);
2252 glUniform1i(mTexture3DUniformLocation, 0);
2253 glUniform1i(mTextureShadowUniformLocation, 1);
2254
2255 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2256 drawQuad(mProgram, "position", 0.5f);
2257 EXPECT_GL_NO_ERROR();
2258 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2259 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2260
2261 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2262 drawQuad(mProgram, "position", 0.5f);
2263 EXPECT_GL_NO_ERROR();
2264 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2265 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2266}
2267
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002268// Test multiple different sampler types in the same shader.
2269// This test makes sure that even if sampler / texture registers get grouped together based on type
2270// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2271// still has the right register index information for each ESSL sampler.
2272// The tested ESSL samplers have the following types in D3D11 HLSL:
2273// sampler2D: Texture2D + SamplerState
2274// samplerCube: TextureCube + SamplerState
2275// sampler2DShadow: Texture2D + SamplerComparisonState
2276// samplerCubeShadow: TextureCube + SamplerComparisonState
2277TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2278{
2279 glActiveTexture(GL_TEXTURE0);
2280 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2281 GLubyte texData[4];
2282 texData[0] = 0;
2283 texData[1] = 0;
2284 texData[2] = 120;
2285 texData[3] = 255;
2286 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2287
2288 glActiveTexture(GL_TEXTURE1);
2289 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2290 texData[0] = 0;
2291 texData[1] = 90;
2292 texData[2] = 0;
2293 texData[3] = 255;
2294 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2295 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2296 texData);
2297
2298 glActiveTexture(GL_TEXTURE2);
2299 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2300 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2301 GLfloat depthTexData[1];
2302 depthTexData[0] = 0.5f;
2303 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2304 depthTexData);
2305
2306 glActiveTexture(GL_TEXTURE3);
2307 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2308 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2309 depthTexData[0] = 0.2f;
2310 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2311 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2312 depthTexData);
2313
2314 EXPECT_GL_NO_ERROR();
2315
2316 glUseProgram(mProgram);
2317 glUniform1f(mDepthRefUniformLocation, 0.3f);
2318 glUniform1i(mTexture2DUniformLocation, 0);
2319 glUniform1i(mTextureCubeUniformLocation, 1);
2320 glUniform1i(mTexture2DShadowUniformLocation, 2);
2321 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2322
2323 drawQuad(mProgram, "position", 0.5f);
2324 EXPECT_GL_NO_ERROR();
2325 // The shader writes:
2326 // <texture 2d color> +
2327 // <cube map color> +
2328 // 0.25 * <comparison result (1.0)> +
2329 // 0.125 * <comparison result (0.0)>
2330 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2331}
2332
Olli Etuahobce743a2016-01-15 17:18:28 +02002333// Test different base levels on textures accessed through the same sampler array.
2334// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2335TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2336{
Yunchao He9550c602018-02-13 14:47:05 +08002337 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2338
Olli Etuahobce743a2016-01-15 17:18:28 +02002339 glActiveTexture(GL_TEXTURE0);
2340 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2341 GLsizei size = 64;
2342 for (GLint level = 0; level < 7; ++level)
2343 {
2344 ASSERT_LT(0, size);
2345 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2346 nullptr);
2347 size = size / 2;
2348 }
2349 ASSERT_EQ(0, size);
2350 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2351
2352 glActiveTexture(GL_TEXTURE1);
2353 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2354 size = 128;
2355 for (GLint level = 0; level < 8; ++level)
2356 {
2357 ASSERT_LT(0, size);
2358 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2359 nullptr);
2360 size = size / 2;
2361 }
2362 ASSERT_EQ(0, size);
2363 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2364 EXPECT_GL_NO_ERROR();
2365
2366 glUseProgram(mProgram);
2367 glUniform1i(mTexture0Location, 0);
2368 glUniform1i(mTexture1Location, 1);
2369
2370 drawQuad(mProgram, "position", 0.5f);
2371 EXPECT_GL_NO_ERROR();
2372 // Red channel: width of level 1 of texture A: 32.
2373 // Green channel: width of level 3 of texture B: 16.
2374 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2375}
2376
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002377// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2378// ES 3.0.4 table 3.24
2379TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2380{
2381 glActiveTexture(GL_TEXTURE0);
2382 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2383 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2384 EXPECT_GL_NO_ERROR();
2385
2386 drawQuad(mProgram, "position", 0.5f);
2387
2388 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2389}
2390
2391// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2392// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002393TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002394{
Luc Ferron5164b792018-03-06 09:10:12 -05002395 setUpProgram();
2396
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002397 glActiveTexture(GL_TEXTURE0);
2398 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2399 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2400 EXPECT_GL_NO_ERROR();
2401
2402 drawQuad(mProgram, "position", 0.5f);
2403
2404 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2405}
2406
Luc Ferron5164b792018-03-06 09:10:12 -05002407// Validate that every component of the pixel will be equal to the luminance value we've set
2408// and that the alpha channel will be 1 (or 255 to be exact).
2409TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2410{
2411 setUpProgram();
2412
2413 glActiveTexture(GL_TEXTURE0);
2414 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2415 uint8_t pixel = 50;
2416 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2417 EXPECT_GL_NO_ERROR();
2418
2419 drawQuad(mProgram, "position", 0.5f);
2420
2421 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2422}
2423
2424// Validate that every component of the pixel will be equal to the luminance value we've set
2425// and that the alpha channel will be the second component.
2426TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2427{
2428 setUpProgram();
2429
2430 glActiveTexture(GL_TEXTURE0);
2431 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2432 uint8_t pixel[] = {50, 25};
2433 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2434 GL_UNSIGNED_BYTE, pixel);
2435 EXPECT_GL_NO_ERROR();
2436
2437 drawQuad(mProgram, "position", 0.5f);
2438
2439 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2440}
2441
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002442// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2443// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002444TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002445{
Luc Ferrond8c632c2018-04-10 12:31:44 -04002446 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
2447 ANGLE_SKIP_TEST_IF(IsD3D9());
2448 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002449
2450 setUpProgram();
2451
Luc Ferrond8c632c2018-04-10 12:31:44 -04002452 glActiveTexture(GL_TEXTURE0);
2453 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2454 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2455 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002456
Luc Ferrond8c632c2018-04-10 12:31:44 -04002457 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002458
Luc Ferrond8c632c2018-04-10 12:31:44 -04002459 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002460}
2461
2462// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2463// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002464TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002465{
Luc Ferrond8c632c2018-04-10 12:31:44 -04002466 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
2467 ANGLE_SKIP_TEST_IF(IsD3D9());
2468 ANGLE_SKIP_TEST_IF(IsVulkan());
2469 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES());
2470 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2471 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002472
Luc Ferrond8c632c2018-04-10 12:31:44 -04002473 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002474
Luc Ferrond8c632c2018-04-10 12:31:44 -04002475 glActiveTexture(GL_TEXTURE0);
2476 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2477 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2478 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002479
Luc Ferrond8c632c2018-04-10 12:31:44 -04002480 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002481
Luc Ferrond8c632c2018-04-10 12:31:44 -04002482 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002483}
2484
2485// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2486// ES 3.0.4 table 3.24
2487TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2488{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002489 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2490
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002491 glActiveTexture(GL_TEXTURE0);
2492 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2493 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2494 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2495 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2496 EXPECT_GL_NO_ERROR();
2497
2498 drawQuad(mProgram, "position", 0.5f);
2499
2500 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2501}
2502
2503// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2504// ES 3.0.4 table 3.24
2505TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2506{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002507 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2508
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002509 glActiveTexture(GL_TEXTURE0);
2510 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2511
2512 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2513 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2514 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2515 EXPECT_GL_NO_ERROR();
2516
2517 drawQuad(mProgram, "position", 0.5f);
2518
2519 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2520}
2521
2522// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2523// ES 3.0.4 table 3.24
2524TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2525{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002526 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2527
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002528 glActiveTexture(GL_TEXTURE0);
2529 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2530 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2531 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2532 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2533 EXPECT_GL_NO_ERROR();
2534
2535 drawQuad(mProgram, "position", 0.5f);
2536
2537 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2538}
2539
2540// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2541// ES 3.0.4 table 3.24
2542TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2543{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002544 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2545
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002546 glActiveTexture(GL_TEXTURE0);
2547 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2548 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2549 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2550 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2551 EXPECT_GL_NO_ERROR();
2552
2553 drawQuad(mProgram, "position", 0.5f);
2554
2555 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2556}
2557
2558// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2559// ES 3.0.4 table 3.24
2560TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2561{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002562 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2563
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002564 glActiveTexture(GL_TEXTURE0);
2565 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2566 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2567 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2568 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2569 EXPECT_GL_NO_ERROR();
2570
2571 drawQuad(mProgram, "position", 0.5f);
2572
2573 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2574}
2575
2576// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2577// ES 3.0.4 table 3.24
2578TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2579{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002580 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2581
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002582 glActiveTexture(GL_TEXTURE0);
2583 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2584 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2585 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2586 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2587 EXPECT_GL_NO_ERROR();
2588
2589 drawQuad(mProgram, "position", 0.5f);
2590
2591 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2592}
2593
2594// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2595// ES 3.0.4 table 3.24
2596TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2597{
2598 glActiveTexture(GL_TEXTURE0);
2599 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2600 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2601 EXPECT_GL_NO_ERROR();
2602
2603 drawQuad(mProgram, "position", 0.5f);
2604
2605 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2606}
2607
2608// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2609// ES 3.0.4 table 3.24
2610TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2611{
2612 glActiveTexture(GL_TEXTURE0);
2613 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2614 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2615 nullptr);
2616 EXPECT_GL_NO_ERROR();
2617
2618 drawQuad(mProgram, "position", 0.5f);
2619
2620 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2621}
2622
2623// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2624// ES 3.0.4 table 3.24
2625TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2626{
Yunchao He9550c602018-02-13 14:47:05 +08002627 // Seems to fail on OSX 10.12 Intel.
2628 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Jamie Madillbb1db482017-01-10 10:48:32 -05002629
Yuly Novikov49886892018-01-23 21:18:27 -05002630 // http://anglebug.com/2190
2631 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2632
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002633 glActiveTexture(GL_TEXTURE0);
2634 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2635 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2636 EXPECT_GL_NO_ERROR();
2637
2638 drawQuad(mProgram, "position", 0.5f);
2639
2640 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2641}
2642
2643// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2644// ES 3.0.4 table 3.24
2645TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2646{
Yunchao He9550c602018-02-13 14:47:05 +08002647 // Seems to fail on OSX 10.12 Intel.
2648 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002649
Yuly Novikov49886892018-01-23 21:18:27 -05002650 // http://anglebug.com/2190
2651 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2652
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002653 glActiveTexture(GL_TEXTURE0);
2654 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2655 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2656 EXPECT_GL_NO_ERROR();
2657
2658 drawQuad(mProgram, "position", 0.5f);
2659
2660 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2661}
2662
Olli Etuaho96963162016-03-21 11:54:33 +02002663// Use a sampler in a uniform struct.
2664TEST_P(SamplerInStructTest, SamplerInStruct)
2665{
2666 runSamplerInStructTest();
2667}
2668
2669// Use a sampler in a uniform struct that's passed as a function parameter.
2670TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2671{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002672 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002673 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002674
Olli Etuaho96963162016-03-21 11:54:33 +02002675 runSamplerInStructTest();
2676}
2677
2678// Use a sampler in a uniform struct array with a struct from the array passed as a function
2679// parameter.
2680TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2681{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002682 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002683 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
2684
Olli Etuaho96963162016-03-21 11:54:33 +02002685 runSamplerInStructTest();
2686}
2687
2688// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2689// parameter.
2690TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2691{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002692 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002693 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
2694
Olli Etuaho96963162016-03-21 11:54:33 +02002695 runSamplerInStructTest();
2696}
2697
2698// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2699// similarly named uniform.
2700TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2701{
2702 runSamplerInStructTest();
2703}
2704
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002705class TextureLimitsTest : public ANGLETest
2706{
2707 protected:
2708 struct RGBA8
2709 {
2710 uint8_t R, G, B, A;
2711 };
2712
2713 TextureLimitsTest()
2714 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
2715 {
2716 setWindowWidth(128);
2717 setWindowHeight(128);
2718 setConfigRedBits(8);
2719 setConfigGreenBits(8);
2720 setConfigBlueBits(8);
2721 setConfigAlphaBits(8);
2722 }
2723
2724 ~TextureLimitsTest()
2725 {
2726 if (mProgram != 0)
2727 {
2728 glDeleteProgram(mProgram);
2729 mProgram = 0;
2730
2731 if (!mTextures.empty())
2732 {
2733 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
2734 }
2735 }
2736 }
2737
2738 void SetUp() override
2739 {
2740 ANGLETest::SetUp();
2741
2742 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
2743 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
2744 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
2745
2746 ASSERT_GL_NO_ERROR();
2747 }
2748
2749 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
2750 GLint vertexTextureCount,
2751 GLint vertexActiveTextureCount,
2752 const std::string &fragPrefix,
2753 GLint fragmentTextureCount,
2754 GLint fragmentActiveTextureCount)
2755 {
2756 std::stringstream vertexShaderStr;
2757 vertexShaderStr << "attribute vec2 position;\n"
2758 << "varying vec4 color;\n"
2759 << "varying vec2 texCoord;\n";
2760
2761 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
2762 {
2763 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
2764 }
2765
2766 vertexShaderStr << "void main() {\n"
2767 << " gl_Position = vec4(position, 0, 1);\n"
2768 << " texCoord = (position * 0.5) + 0.5;\n"
2769 << " color = vec4(0);\n";
2770
2771 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
2772 {
2773 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
2774 << ", texCoord);\n";
2775 }
2776
2777 vertexShaderStr << "}";
2778
2779 std::stringstream fragmentShaderStr;
2780 fragmentShaderStr << "varying mediump vec4 color;\n"
2781 << "varying mediump vec2 texCoord;\n";
2782
2783 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
2784 {
2785 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
2786 }
2787
2788 fragmentShaderStr << "void main() {\n"
2789 << " gl_FragColor = color;\n";
2790
2791 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
2792 {
2793 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
2794 << ", texCoord);\n";
2795 }
2796
2797 fragmentShaderStr << "}";
2798
2799 const std::string &vertexShaderSource = vertexShaderStr.str();
2800 const std::string &fragmentShaderSource = fragmentShaderStr.str();
2801
2802 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
2803 }
2804
2805 RGBA8 getPixel(GLint texIndex)
2806 {
2807 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
2808 0, 255u};
2809 return pixel;
2810 }
2811
2812 void initTextures(GLint tex2DCount, GLint texCubeCount)
2813 {
2814 GLint totalCount = tex2DCount + texCubeCount;
2815 mTextures.assign(totalCount, 0);
2816 glGenTextures(totalCount, &mTextures[0]);
2817 ASSERT_GL_NO_ERROR();
2818
2819 std::vector<RGBA8> texData(16 * 16);
2820
2821 GLint texIndex = 0;
2822 for (; texIndex < tex2DCount; ++texIndex)
2823 {
2824 texData.assign(texData.size(), getPixel(texIndex));
2825 glActiveTexture(GL_TEXTURE0 + texIndex);
2826 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
2827 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2828 &texData[0]);
2829 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2830 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2831 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2832 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2833 }
2834
2835 ASSERT_GL_NO_ERROR();
2836
2837 for (; texIndex < texCubeCount; ++texIndex)
2838 {
2839 texData.assign(texData.size(), getPixel(texIndex));
2840 glActiveTexture(GL_TEXTURE0 + texIndex);
2841 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
2842 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2843 GL_UNSIGNED_BYTE, &texData[0]);
2844 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2845 GL_UNSIGNED_BYTE, &texData[0]);
2846 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2847 GL_UNSIGNED_BYTE, &texData[0]);
2848 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2849 GL_UNSIGNED_BYTE, &texData[0]);
2850 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2851 GL_UNSIGNED_BYTE, &texData[0]);
2852 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2853 GL_UNSIGNED_BYTE, &texData[0]);
2854 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2855 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2856 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2857 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2858 }
2859
2860 ASSERT_GL_NO_ERROR();
2861 }
2862
2863 void testWithTextures(GLint vertexTextureCount,
2864 const std::string &vertexTexturePrefix,
2865 GLint fragmentTextureCount,
2866 const std::string &fragmentTexturePrefix)
2867 {
2868 // Generate textures
2869 initTextures(vertexTextureCount + fragmentTextureCount, 0);
2870
2871 glUseProgram(mProgram);
2872 RGBA8 expectedSum = {0};
2873 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
2874 {
2875 std::stringstream uniformNameStr;
2876 uniformNameStr << vertexTexturePrefix << texIndex;
2877 const std::string &uniformName = uniformNameStr.str();
2878 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
2879 ASSERT_NE(-1, location);
2880
2881 glUniform1i(location, texIndex);
2882 RGBA8 contribution = getPixel(texIndex);
2883 expectedSum.R += contribution.R;
2884 expectedSum.G += contribution.G;
2885 }
2886
2887 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
2888 {
2889 std::stringstream uniformNameStr;
2890 uniformNameStr << fragmentTexturePrefix << texIndex;
2891 const std::string &uniformName = uniformNameStr.str();
2892 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
2893 ASSERT_NE(-1, location);
2894
2895 glUniform1i(location, texIndex + vertexTextureCount);
2896 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
2897 expectedSum.R += contribution.R;
2898 expectedSum.G += contribution.G;
2899 }
2900
2901 ASSERT_GE(256u, expectedSum.G);
2902
2903 drawQuad(mProgram, "position", 0.5f);
2904 ASSERT_GL_NO_ERROR();
2905 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
2906 }
2907
2908 GLuint mProgram;
2909 std::vector<GLuint> mTextures;
2910 GLint mMaxVertexTextures;
2911 GLint mMaxFragmentTextures;
2912 GLint mMaxCombinedTextures;
2913};
2914
2915// Test rendering with the maximum vertex texture units.
2916TEST_P(TextureLimitsTest, MaxVertexTextures)
2917{
2918 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
2919 ASSERT_NE(0u, mProgram);
2920 ASSERT_GL_NO_ERROR();
2921
2922 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
2923}
2924
2925// Test rendering with the maximum fragment texture units.
2926TEST_P(TextureLimitsTest, MaxFragmentTextures)
2927{
2928 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
2929 ASSERT_NE(0u, mProgram);
2930 ASSERT_GL_NO_ERROR();
2931
2932 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
2933}
2934
2935// Test rendering with maximum combined texture units.
2936TEST_P(TextureLimitsTest, MaxCombinedTextures)
2937{
2938 GLint vertexTextures = mMaxVertexTextures;
2939
2940 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
2941 {
2942 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
2943 }
2944
2945 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
2946 mMaxFragmentTextures, mMaxFragmentTextures);
2947 ASSERT_NE(0u, mProgram);
2948 ASSERT_GL_NO_ERROR();
2949
2950 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
2951}
2952
2953// Negative test for exceeding the number of vertex textures
2954TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
2955{
2956 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
2957 0);
2958 ASSERT_EQ(0u, mProgram);
2959}
2960
2961// Negative test for exceeding the number of fragment textures
2962TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
2963{
2964 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
2965 mMaxFragmentTextures + 1);
2966 ASSERT_EQ(0u, mProgram);
2967}
2968
2969// Test active vertex textures under the limit, but excessive textures specified.
2970TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
2971{
2972 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
2973 ASSERT_NE(0u, mProgram);
2974 ASSERT_GL_NO_ERROR();
2975
2976 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
2977}
2978
2979// Test active fragment textures under the limit, but excessive textures specified.
2980TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
2981{
2982 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
2983 mMaxFragmentTextures);
2984 ASSERT_NE(0u, mProgram);
2985 ASSERT_GL_NO_ERROR();
2986
2987 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
2988}
2989
2990// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002991// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002992TEST_P(TextureLimitsTest, TextureTypeConflict)
2993{
2994 const std::string &vertexShader =
2995 "attribute vec2 position;\n"
2996 "varying float color;\n"
2997 "uniform sampler2D tex2D;\n"
2998 "uniform samplerCube texCube;\n"
2999 "void main() {\n"
3000 " gl_Position = vec4(position, 0, 1);\n"
3001 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3002 " color = texture2D(tex2D, texCoord).x;\n"
3003 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3004 "}";
3005 const std::string &fragmentShader =
3006 "varying mediump float color;\n"
3007 "void main() {\n"
3008 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3009 "}";
3010
3011 mProgram = CompileProgram(vertexShader, fragmentShader);
3012 ASSERT_NE(0u, mProgram);
3013
3014 initTextures(1, 0);
3015
3016 glUseProgram(mProgram);
3017 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3018 ASSERT_NE(-1, tex2DLocation);
3019 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3020 ASSERT_NE(-1, texCubeLocation);
3021
3022 glUniform1i(tex2DLocation, 0);
3023 glUniform1i(texCubeLocation, 0);
3024 ASSERT_GL_NO_ERROR();
3025
3026 drawQuad(mProgram, "position", 0.5f);
3027 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3028}
3029
Vincent Lang25ab4512016-05-13 18:13:59 +02003030class Texture2DNorm16TestES3 : public Texture2DTestES3
3031{
3032 protected:
3033 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3034
3035 void SetUp() override
3036 {
3037 Texture2DTestES3::SetUp();
3038
3039 glActiveTexture(GL_TEXTURE0);
3040 glGenTextures(3, mTextures);
3041 glGenFramebuffers(1, &mFBO);
3042 glGenRenderbuffers(1, &mRenderbuffer);
3043
3044 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3045 {
3046 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3047 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3048 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3049 }
3050
3051 glBindTexture(GL_TEXTURE_2D, 0);
3052
3053 ASSERT_GL_NO_ERROR();
3054 }
3055
3056 void TearDown() override
3057 {
3058 glDeleteTextures(3, mTextures);
3059 glDeleteFramebuffers(1, &mFBO);
3060 glDeleteRenderbuffers(1, &mRenderbuffer);
3061
3062 Texture2DTestES3::TearDown();
3063 }
3064
3065 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3066 {
Geoff Langf607c602016-09-21 11:46:48 -04003067 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3068 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003069
3070 setUpProgram();
3071
3072 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3073 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3074 0);
3075
3076 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3077 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3078
3079 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003080 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003081
3082 EXPECT_GL_NO_ERROR();
3083
3084 drawQuad(mProgram, "position", 0.5f);
3085
Geoff Langf607c602016-09-21 11:46:48 -04003086 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003087
Geoff Langf607c602016-09-21 11:46:48 -04003088 EXPECT_PIXEL_COLOR_EQ(
3089 0, 0, SliceFormatColor(
3090 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003091
3092 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3093
3094 ASSERT_GL_NO_ERROR();
3095 }
3096
3097 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3098 {
3099 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003100 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003101
3102 setUpProgram();
3103
3104 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3105 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3106
3107 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3108 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3109 0);
3110
3111 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003112 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003113
3114 EXPECT_GL_NO_ERROR();
3115
3116 drawQuad(mProgram, "position", 0.5f);
3117
Geoff Langf607c602016-09-21 11:46:48 -04003118 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
3119 EXPECT_PIXEL_COLOR_EQ(
3120 0, 0, SliceFormatColor(
3121 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003122
3123 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3124 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3125 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3126 mRenderbuffer);
3127 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3128 EXPECT_GL_NO_ERROR();
3129
3130 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3131 glClear(GL_COLOR_BUFFER_BIT);
3132
3133 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3134
Geoff Langf607c602016-09-21 11:46:48 -04003135 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003136
3137 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3138
3139 ASSERT_GL_NO_ERROR();
3140 }
3141
3142 GLuint mTextures[3];
3143 GLuint mFBO;
3144 GLuint mRenderbuffer;
3145};
3146
3147// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3148TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3149{
Yunchao He9550c602018-02-13 14:47:05 +08003150 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02003151
3152 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3153 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3154 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3155 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3156 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3157 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3158 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3159 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3160
3161 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3162 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3163 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3164}
3165
Olli Etuaho95faa232016-06-07 14:01:53 -07003166// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3167// GLES 3.0.4 section 3.8.3.
3168TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3169{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08003170 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
3171
Yuly Novikov3c754192016-06-27 19:36:41 -04003172 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1429 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08003173 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07003174
3175 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3176 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3177 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3178 ASSERT_GL_NO_ERROR();
3179
3180 // SKIP_IMAGES should not have an effect on uploading 2D textures
3181 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3182 ASSERT_GL_NO_ERROR();
3183
3184 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3185
3186 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3187 pixelsGreen.data());
3188 ASSERT_GL_NO_ERROR();
3189
3190 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3191 pixelsGreen.data());
3192 ASSERT_GL_NO_ERROR();
3193
3194 glUseProgram(mProgram);
3195 drawQuad(mProgram, "position", 0.5f);
3196 ASSERT_GL_NO_ERROR();
3197
3198 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3199}
3200
Olli Etuaho989cac32016-06-08 16:18:49 -07003201// Test that skip defined in unpack parameters is taken into account when determining whether
3202// unpacking source extends outside unpack buffer bounds.
3203TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3204{
3205 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3206 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3207 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3208 ASSERT_GL_NO_ERROR();
3209
3210 GLBuffer buf;
3211 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3212 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3213 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3214 GL_DYNAMIC_COPY);
3215 ASSERT_GL_NO_ERROR();
3216
3217 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3218 ASSERT_GL_NO_ERROR();
3219
3220 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3221 ASSERT_GL_NO_ERROR();
3222
3223 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3224 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3225
3226 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3227 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3228 ASSERT_GL_NO_ERROR();
3229
3230 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3231 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3232}
3233
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003234// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3235TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3236{
Yunchao He9550c602018-02-13 14:47:05 +08003237 ANGLE_SKIP_TEST_IF(IsD3D11());
3238
3239 // Incorrect rendering results seen on OSX AMD.
3240 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003241
3242 const GLuint width = 8u;
3243 const GLuint height = 8u;
3244 const GLuint unpackRowLength = 5u;
3245 const GLuint unpackSkipPixels = 1u;
3246
3247 setWindowWidth(width);
3248 setWindowHeight(height);
3249
3250 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3251 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3252 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3253 ASSERT_GL_NO_ERROR();
3254
3255 GLBuffer buf;
3256 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3257 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3258 GLColor::green);
3259
3260 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3261 {
3262 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3263 }
3264
3265 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3266 GL_DYNAMIC_COPY);
3267 ASSERT_GL_NO_ERROR();
3268
3269 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3270 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3271 ASSERT_GL_NO_ERROR();
3272
3273 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3274 ASSERT_GL_NO_ERROR();
3275
3276 glUseProgram(mProgram);
3277 drawQuad(mProgram, "position", 0.5f);
3278 ASSERT_GL_NO_ERROR();
3279
3280 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3281 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3282 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3283 actual.data());
3284 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3285 EXPECT_EQ(expected, actual);
3286}
3287
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003288template <typename T>
3289T UNorm(double value)
3290{
3291 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3292}
3293
3294// Test rendering a depth texture with mipmaps.
3295TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3296{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003297 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3298 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
3299 // http://anglebugs.com/1706
Yunchao He9550c602018-02-13 14:47:05 +08003300 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows());
Corentin Walleze731d8a2016-09-07 10:56:25 -04003301
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003302 const int size = getWindowWidth();
3303
3304 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003305 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003306
3307 glActiveTexture(GL_TEXTURE0);
3308 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3309 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3310 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3311 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3312 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3313 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3314 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3315 ASSERT_GL_NO_ERROR();
3316
3317 glUseProgram(mProgram);
3318 glUniform1i(mTexture2DUniformLocation, 0);
3319
3320 std::vector<unsigned char> expected;
3321
3322 for (int level = 0; level < levels; ++level)
3323 {
3324 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3325 expected.push_back(UNorm<unsigned char>(value));
3326
3327 int levelDim = dim(level);
3328
3329 ASSERT_GT(levelDim, 0);
3330
3331 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3332 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3333 GL_UNSIGNED_INT, initData.data());
3334 }
3335 ASSERT_GL_NO_ERROR();
3336
3337 for (int level = 0; level < levels; ++level)
3338 {
3339 glViewport(0, 0, dim(level), dim(level));
3340 drawQuad(mProgram, "position", 0.5f);
3341 GLColor actual = ReadColor(0, 0);
3342 EXPECT_NEAR(expected[level], actual.R, 10u);
3343 }
3344
3345 ASSERT_GL_NO_ERROR();
3346}
3347
Jamie Madill7ffdda92016-09-08 13:26:51 -04003348// Tests unpacking into the unsized GL_ALPHA format.
3349TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3350{
Jamie Madill7ffdda92016-09-08 13:26:51 -04003351 // Initialize the texure.
3352 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3353 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3354 GL_UNSIGNED_BYTE, nullptr);
3355 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3356 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3357
3358 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3359
3360 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04003361 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04003362 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3363 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3364 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
3365 GL_STATIC_DRAW);
3366
3367 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
3368 GL_UNSIGNED_BYTE, nullptr);
3369
3370 // Clear to a weird color to make sure we're drawing something.
3371 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
3372 glClear(GL_COLOR_BUFFER_BIT);
3373
3374 // Draw with the alpha texture and verify.
3375 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04003376
3377 ASSERT_GL_NO_ERROR();
3378 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
3379}
3380
Jamie Madill2e600342016-09-19 13:56:40 -04003381// Ensure stale unpack data doesn't propagate in D3D11.
3382TEST_P(Texture2DTestES3, StaleUnpackData)
3383{
3384 // Init unpack buffer.
3385 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
3386 std::vector<GLColor> pixels(pixelCount, GLColor::red);
3387
3388 GLBuffer unpackBuffer;
3389 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3390 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3391 GLsizei bufferSize = pixelCount * sizeof(GLColor);
3392 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
3393
3394 // Create from unpack buffer.
3395 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3396 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
3397 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3398 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3399 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3400
3401 drawQuad(mProgram, "position", 0.5f);
3402
3403 ASSERT_GL_NO_ERROR();
3404 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3405
3406 // Fill unpack with green, recreating buffer.
3407 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
3408 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
3409 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
3410
3411 // Reinit texture with green.
3412 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
3413 GL_UNSIGNED_BYTE, nullptr);
3414
3415 drawQuad(mProgram, "position", 0.5f);
3416
3417 ASSERT_GL_NO_ERROR();
3418 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3419}
3420
Geoff Langfb7685f2017-11-13 11:44:11 -05003421// Ensure that texture parameters passed as floats that are converted to ints are rounded before
3422// validating they are less than 0.
3423TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
3424{
3425 GLTexture texture;
3426 glBindTexture(GL_TEXTURE_2D, texture);
3427
3428 // Use a negative number that will round to zero when converted to an integer
3429 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
3430 // "Validation of values performed by state-setting commands is performed after conversion,
3431 // unless specified otherwise for a specific command."
3432 GLfloat param = -7.30157126e-07f;
3433 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
3434 EXPECT_GL_NO_ERROR();
3435
3436 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
3437 EXPECT_GL_NO_ERROR();
3438}
3439
Jamie Madillf097e232016-11-05 00:44:15 -04003440// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
3441// being properly checked, and the texture storage of the previous texture format was persisting.
3442// This would result in an ASSERT in debug and incorrect rendering in release.
3443// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
3444TEST_P(Texture3DTestES3, FormatRedefinitionBug)
3445{
3446 GLTexture tex;
3447 glBindTexture(GL_TEXTURE_3D, tex.get());
3448 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3449
3450 GLFramebuffer framebuffer;
3451 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3452 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
3453
3454 glCheckFramebufferStatus(GL_FRAMEBUFFER);
3455
3456 std::vector<uint8_t> pixelData(100, 0);
3457
3458 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
3459 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
3460 pixelData.data());
3461
3462 ASSERT_GL_NO_ERROR();
3463}
3464
Corentin Wallezd2627992017-04-28 17:17:03 -04003465// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
3466TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
3467{
3468 // 2D tests
3469 {
3470 GLTexture tex;
3471 glBindTexture(GL_TEXTURE_2D, tex.get());
3472
3473 GLBuffer pbo;
3474 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3475
3476 // Test OOB
3477 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
3478 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3479 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3480
3481 // Test OOB
3482 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
3483 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3484 ASSERT_GL_NO_ERROR();
3485 }
3486
3487 // 3D tests
3488 {
3489 GLTexture tex;
3490 glBindTexture(GL_TEXTURE_3D, tex.get());
3491
3492 GLBuffer pbo;
3493 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3494
3495 // Test OOB
3496 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
3497 GL_STATIC_DRAW);
3498 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3499 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3500
3501 // Test OOB
3502 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
3503 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3504 ASSERT_GL_NO_ERROR();
3505 }
3506}
3507
Jamie Madill3ed60422017-09-07 11:32:52 -04003508// Tests behaviour with a single texture and multiple sampler objects.
3509TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
3510{
3511 GLint maxTextureUnits = 0;
3512 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
3513 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
3514
3515 constexpr int kSize = 16;
3516
3517 // Make a single-level texture, fill it with red.
3518 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
3519 GLTexture tex;
3520 glBindTexture(GL_TEXTURE_2D, tex);
3521 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3522 redColors.data());
3523 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3524 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3525
3526 // Simple sanity check.
3527 draw2DTexturedQuad(0.5f, 1.0f, true);
3528 ASSERT_GL_NO_ERROR();
3529 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3530
3531 // Bind texture to unit 1 with a sampler object making it incomplete.
3532 GLSampler sampler;
3533 glBindSampler(0, sampler);
3534 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3535 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3536
3537 // Make a mipmap texture, fill it with blue.
3538 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
3539 GLTexture mipmapTex;
3540 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3541 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3542 blueColors.data());
3543 glGenerateMipmap(GL_TEXTURE_2D);
3544
3545 // Draw with the sampler, expect blue.
3546 draw2DTexturedQuad(0.5f, 1.0f, true);
3547 ASSERT_GL_NO_ERROR();
3548 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
3549
3550 // Simple multitexturing program.
3551 const std::string vs =
3552 "#version 300 es\n"
3553 "in vec2 position;\n"
3554 "out vec2 texCoord;\n"
3555 "void main()\n"
3556 "{\n"
3557 " gl_Position = vec4(position, 0, 1);\n"
3558 " texCoord = position * 0.5 + vec2(0.5);\n"
3559 "}";
3560 const std::string fs =
3561 "#version 300 es\n"
3562 "precision mediump float;\n"
3563 "in vec2 texCoord;\n"
3564 "uniform sampler2D tex1;\n"
3565 "uniform sampler2D tex2;\n"
3566 "uniform sampler2D tex3;\n"
3567 "uniform sampler2D tex4;\n"
3568 "out vec4 color;\n"
3569 "void main()\n"
3570 "{\n"
3571 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
3572 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
3573 "}";
3574
3575 ANGLE_GL_PROGRAM(program, vs, fs);
3576
3577 std::array<GLint, 4> texLocations = {
3578 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
3579 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
3580 for (GLint location : texLocations)
3581 {
3582 ASSERT_NE(-1, location);
3583 }
3584
3585 // Init the uniform data.
3586 glUseProgram(program);
3587 for (GLint location = 0; location < 4; ++location)
3588 {
3589 glUniform1i(texLocations[location], location);
3590 }
3591
3592 // Initialize four samplers
3593 GLSampler samplers[4];
3594
3595 // 0: non-mipped.
3596 glBindSampler(0, samplers[0]);
3597 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3598 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3599
3600 // 1: mipped.
3601 glBindSampler(1, samplers[1]);
3602 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3603 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3604
3605 // 2: non-mipped.
3606 glBindSampler(2, samplers[2]);
3607 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3608 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3609
3610 // 3: mipped.
3611 glBindSampler(3, samplers[3]);
3612 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3613 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3614
3615 // Bind two blue mipped textures and two single layer textures, should all draw.
3616 glActiveTexture(GL_TEXTURE0);
3617 glBindTexture(GL_TEXTURE_2D, tex);
3618
3619 glActiveTexture(GL_TEXTURE1);
3620 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3621
3622 glActiveTexture(GL_TEXTURE2);
3623 glBindTexture(GL_TEXTURE_2D, tex);
3624
3625 glActiveTexture(GL_TEXTURE3);
3626 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3627
3628 ASSERT_GL_NO_ERROR();
3629
3630 drawQuad(program, "position", 0.5f);
3631 ASSERT_GL_NO_ERROR();
3632 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
3633
3634 // Bind four single layer textures, two should be incomplete.
3635 glActiveTexture(GL_TEXTURE1);
3636 glBindTexture(GL_TEXTURE_2D, tex);
3637
3638 glActiveTexture(GL_TEXTURE3);
3639 glBindTexture(GL_TEXTURE_2D, tex);
3640
3641 drawQuad(program, "position", 0.5f);
3642 ASSERT_GL_NO_ERROR();
3643 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
3644}
3645
Martin Radev7e2c0d32017-09-15 14:25:42 +03003646// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
3647// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
3648// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
3649// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
3650// samples the cubemap using a direction vector (1,1,1).
3651TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
3652{
Yunchao He2f23f352018-02-11 22:11:37 +08003653 // Check http://anglebug.com/2155.
3654 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
3655
Martin Radev7e2c0d32017-09-15 14:25:42 +03003656 const std::string vs =
3657 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003658 precision mediump float;
3659 in vec3 pos;
3660 void main() {
3661 gl_Position = vec4(pos, 1.0);
3662 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003663
3664 const std::string fs =
3665 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003666 precision mediump float;
3667 out vec4 color;
3668 uniform samplerCube uTex;
3669 void main(){
3670 color = texture(uTex, vec3(1.0));
3671 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003672 ANGLE_GL_PROGRAM(program, vs, fs);
3673 glUseProgram(program);
3674
3675 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
3676 glActiveTexture(GL_TEXTURE0);
3677
3678 GLTexture cubeTex;
3679 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
3680
3681 const int kFaceWidth = 1;
3682 const int kFaceHeight = 1;
3683 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
3684 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3685 GL_UNSIGNED_BYTE, texData.data());
3686 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3687 GL_UNSIGNED_BYTE, texData.data());
3688 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3689 GL_UNSIGNED_BYTE, texData.data());
3690 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3691 GL_UNSIGNED_BYTE, texData.data());
3692 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3693 GL_UNSIGNED_BYTE, texData.data());
3694 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3695 GL_UNSIGNED_BYTE, texData.data());
3696 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3697 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3698 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
3699 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
3700 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
3701 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
3702
3703 drawQuad(program, "pos", 0.5f, 1.0f, true);
3704 ASSERT_GL_NO_ERROR();
3705
3706 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
3707}
3708
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08003709// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
3710TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
3711{
3712 GLuint texture = create2DTexture();
3713
3714 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
3715 EXPECT_GL_ERROR(GL_INVALID_VALUE);
3716
3717 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
3718 EXPECT_GL_ERROR(GL_INVALID_VALUE);
3719
3720 glDeleteTextures(1, &texture);
3721 EXPECT_GL_NO_ERROR();
3722}
3723
Jamie Madillfa05f602015-05-07 13:47:11 -04003724// 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 +02003725// TODO(oetuaho): Enable all below tests on OpenGL. Requires a fix for ANGLE bug 1278.
Geoff Lange0cc2a42016-01-20 10:58:17 -05003726ANGLE_INSTANTIATE_TEST(Texture2DTest,
3727 ES2_D3D9(),
3728 ES2_D3D11(),
3729 ES2_D3D11_FL9_3(),
3730 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05003731 ES2_OPENGLES(),
3732 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003733ANGLE_INSTANTIATE_TEST(TextureCubeTest,
3734 ES2_D3D9(),
3735 ES2_D3D11(),
Geoff Langf7480ad2017-10-24 11:46:02 -04003736 ES2_D3D11_FL10_0(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003737 ES2_D3D11_FL9_3(),
3738 ES2_OPENGL(),
3739 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003740ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
3741 ES2_D3D9(),
3742 ES2_D3D11(),
3743 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003744 ES2_OPENGL(),
3745 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003746ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
3747 ES2_D3D9(),
3748 ES2_D3D11(),
3749 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003750 ES2_OPENGL(),
3751 ES2_OPENGLES());
3752ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
3753 ES2_D3D9(),
3754 ES2_D3D11(),
3755 ES2_D3D11_FL9_3(),
3756 ES2_OPENGL(),
3757 ES2_OPENGLES());
3758ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
3759 ES2_D3D9(),
3760 ES2_D3D11(),
3761 ES2_D3D11_FL9_3(),
3762 ES2_OPENGL(),
3763 ES2_OPENGLES());
3764ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02003765ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003766ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3767ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
3768 ES3_D3D11(),
3769 ES3_OPENGL(),
3770 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003771ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
3772 ES3_D3D11(),
3773 ES3_OPENGL(),
3774 ES3_OPENGLES());
3775ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3776ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02003777ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02003778ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
3779 ES2_D3D11(),
3780 ES2_D3D11_FL9_3(),
3781 ES2_D3D9(),
3782 ES2_OPENGL(),
3783 ES2_OPENGLES());
3784ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
3785 ES2_D3D11(),
3786 ES2_D3D11_FL9_3(),
3787 ES2_D3D9(),
3788 ES2_OPENGL(),
3789 ES2_OPENGLES());
3790ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
3791 ES2_D3D11(),
3792 ES2_D3D11_FL9_3(),
3793 ES2_D3D9(),
3794 ES2_OPENGL(),
3795 ES2_OPENGLES());
3796ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
3797 ES2_D3D11(),
3798 ES2_D3D11_FL9_3(),
3799 ES2_D3D9(),
3800 ES2_OPENGL(),
3801 ES2_OPENGLES());
3802ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
3803 ES2_D3D11(),
3804 ES2_D3D11_FL9_3(),
3805 ES2_D3D9(),
3806 ES2_OPENGL(),
3807 ES2_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003808ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES());
Vincent Lang25ab4512016-05-13 18:13:59 +02003809ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03003810ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04003811
Jamie Madill7ffdda92016-09-08 13:26:51 -04003812} // anonymous namespace