blob: e46b6305e4f98afbf778911c46eb75c1bd0398c4 [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 {
Geoff Langbde666a2015-04-07 17:17:08 -0400177 // TODO(jmadill): Figure out why this is broken on Intel D3D11
Jamie Madill518b9fa2016-03-02 11:26:02 -0500178 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
Geoff Langbde666a2015-04-07 17:17:08 -0400179 {
180 std::cout << "Test skipped on Intel D3D11." << std::endl;
181 return;
182 }
183
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300184 setUpProgram();
185
Martin Radev1be913c2016-07-11 17:59:16 +0300186 if (getClientMajorVersion() < 3)
Geoff Langfbfa47c2015-03-31 11:26:00 -0400187 {
Geoff Langc4e93662017-05-01 10:45:59 -0400188 if (!extensionEnabled("GL_EXT_texture_storage"))
189 {
190 std::cout << "Test skipped due to missing GL_EXT_texture_storage." << std::endl;
191 return;
192 }
193
Geoff Langfbfa47c2015-03-31 11:26:00 -0400194 if (!extensionEnabled("GL_OES_texture_float"))
195 {
196 std::cout << "Test skipped due to missing GL_OES_texture_float." << std::endl;
197 return;
198 }
199
200 if ((sourceImageChannels < 3 || destImageChannels < 3) && !extensionEnabled("GL_EXT_texture_rg"))
201 {
202 std::cout << "Test skipped due to missing GL_EXT_texture_rg." << std::endl;
203 return;
204 }
Geoff Lang677bb6f2017-04-05 12:40:40 -0400205
206 if (destImageChannels == 3 && !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"))
207 {
208 std::cout << "Test skipped due to missing GL_CHROMIUM_color_buffer_float_rgb."
209 << std::endl;
210 return;
211 }
212
213 if (destImageChannels == 4 && !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba"))
214 {
215 std::cout << "Test skipped due to missing GL_CHROMIUM_color_buffer_float_rgb."
216 << std::endl;
217 return;
218 }
219
220 if (destImageChannels <= 2)
221 {
222 std::cout << "Test skipped because no extensions grant renderability to 1 and 2 "
223 "channel floating point textures."
224 << std::endl;
225 return;
226 }
227 }
228 else
229 {
230 if (!extensionEnabled("GL_color_buffer_float"))
231 {
232 std::cout << "Test skipped due to missing GL_color_buffer_float." << std::endl;
233 return;
234 }
235
236 if (destImageChannels == 3 && !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"))
237 {
238 std::cout << "Test skipped due to missing GL_CHROMIUM_color_buffer_float_rgb."
239 << std::endl;
240 return;
241 }
Geoff Langfbfa47c2015-03-31 11:26:00 -0400242 }
243
Jamie Madillbc393df2015-01-29 13:46:07 -0500244 GLfloat sourceImageData[4][16] =
245 {
246 { // R
247 1.0f,
248 0.0f,
249 0.0f,
250 1.0f
251 },
252 { // RG
253 1.0f, 0.0f,
254 0.0f, 1.0f,
255 0.0f, 0.0f,
256 1.0f, 1.0f
257 },
258 { // RGB
259 1.0f, 0.0f, 0.0f,
260 0.0f, 1.0f, 0.0f,
261 0.0f, 0.0f, 1.0f,
262 1.0f, 1.0f, 0.0f
263 },
264 { // RGBA
265 1.0f, 0.0f, 0.0f, 1.0f,
266 0.0f, 1.0f, 0.0f, 1.0f,
267 0.0f, 0.0f, 1.0f, 1.0f,
268 1.0f, 1.0f, 0.0f, 1.0f
269 },
270 };
271
272 GLenum imageFormats[] =
273 {
274 GL_R32F,
275 GL_RG32F,
276 GL_RGB32F,
277 GL_RGBA32F,
278 };
279
280 GLenum sourceUnsizedFormats[] =
281 {
282 GL_RED,
283 GL_RG,
284 GL_RGB,
285 GL_RGBA,
286 };
287
288 GLuint textures[2];
289
290 glGenTextures(2, textures);
291
292 GLfloat *imageData = sourceImageData[sourceImageChannels - 1];
293 GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1];
294 GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1];
295 GLenum destImageFormat = imageFormats[destImageChannels - 1];
296
297 glBindTexture(GL_TEXTURE_2D, textures[0]);
Geoff Langc4e93662017-05-01 10:45:59 -0400298 if (getClientMajorVersion() >= 3)
299 {
300 glTexStorage2D(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
301 }
302 else
303 {
304 glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
305 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500306 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
307 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
308 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData);
309
hendrikwb27f79a2015-03-04 11:26:46 -0800310 if (sourceImageChannels < 3 && !extensionEnabled("GL_EXT_texture_rg"))
Jamie Madillbc393df2015-01-29 13:46:07 -0500311 {
312 // This is not supported
313 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
314 }
315 else
316 {
317 ASSERT_GL_NO_ERROR();
318 }
319
320 GLuint fbo;
321 glGenFramebuffers(1, &fbo);
322 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
323 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
324
325 glBindTexture(GL_TEXTURE_2D, textures[1]);
Geoff Langc4e93662017-05-01 10:45:59 -0400326 if (getClientMajorVersion() >= 3)
327 {
328 glTexStorage2D(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
329 }
330 else
331 {
332 glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
333 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500334 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
335 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
336
337 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
338 ASSERT_GL_NO_ERROR();
339
340 glBindFramebuffer(GL_FRAMEBUFFER, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200341 drawQuad(mProgram, "position", 0.5f);
Jamie Madillbc393df2015-01-29 13:46:07 -0500342
343 int testImageChannels = std::min(sourceImageChannels, destImageChannels);
344
Olli Etuahoa314b612016-03-10 16:43:00 +0200345 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Jamie Madillbc393df2015-01-29 13:46:07 -0500346 if (testImageChannels > 1)
347 {
348 EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255);
349 EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255);
350 if (testImageChannels > 2)
351 {
352 EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255);
353 }
354 }
355
356 glDeleteFramebuffers(1, &fbo);
357 glDeleteTextures(2, textures);
358
359 ASSERT_GL_NO_ERROR();
360 }
361
Jamie Madilld4cfa572014-07-08 10:00:32 -0400362 GLuint mTexture2D;
Jamie Madilld4cfa572014-07-08 10:00:32 -0400363 GLint mTexture2DUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400364};
365
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200366class Texture2DTestES3 : public Texture2DTest
367{
368 protected:
369 Texture2DTestES3() : Texture2DTest() {}
370
371 std::string getVertexShaderSource() override
372 {
373 return std::string(
374 "#version 300 es\n"
375 "out vec2 texcoord;\n"
376 "in vec4 position;\n"
377 "void main()\n"
378 "{\n"
379 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
380 " texcoord = (position.xy * 0.5) + 0.5;\n"
381 "}\n");
382 }
383
384 std::string getFragmentShaderSource() override
385 {
386 return std::string(
387 "#version 300 es\n"
388 "precision highp float;\n"
389 "uniform highp sampler2D tex;\n"
390 "in vec2 texcoord;\n"
391 "out vec4 fragColor;\n"
392 "void main()\n"
393 "{\n"
394 " fragColor = texture(tex, texcoord);\n"
395 "}\n");
396 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300397
398 void SetUp() override
399 {
400 Texture2DTest::SetUp();
401 setUpProgram();
402 }
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200403};
404
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200405class Texture2DIntegerAlpha1TestES3 : public Texture2DTest
406{
407 protected:
408 Texture2DIntegerAlpha1TestES3() : 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 isampler2D 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 == 1) ? 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
446class Texture2DUnsignedIntegerAlpha1TestES3 : public Texture2DTest
447{
448 protected:
449 Texture2DUnsignedIntegerAlpha1TestES3() : Texture2DTest() {}
450
451 std::string getVertexShaderSource() override
452 {
453 return std::string(
454 "#version 300 es\n"
455 "out vec2 texcoord;\n"
456 "in vec4 position;\n"
457 "void main()\n"
458 "{\n"
459 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
460 " texcoord = (position.xy * 0.5) + 0.5;\n"
461 "}\n");
462 }
463
464 std::string getFragmentShaderSource() override
465 {
466 return std::string(
467 "#version 300 es\n"
468 "precision highp float;\n"
469 "uniform highp usampler2D tex;\n"
470 "in vec2 texcoord;\n"
471 "out vec4 fragColor;\n"
472 "void main()\n"
473 "{\n"
474 " vec4 green = vec4(0, 1, 0, 1);\n"
475 " vec4 black = vec4(0, 0, 0, 0);\n"
476 " fragColor = (texture(tex, texcoord).a == 1u) ? green : black;\n"
477 "}\n");
478 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300479
480 void SetUp() override
481 {
482 Texture2DTest::SetUp();
483 setUpProgram();
484 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200485};
486
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200487class Texture2DTestWithDrawScale : public Texture2DTest
Jamie Madill2453dbc2015-07-14 11:35:42 -0400488{
489 protected:
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200490 Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {}
491
492 std::string getVertexShaderSource() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400493 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300494 return
495 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200496 attribute vec4 position;
497 varying vec2 texcoord;
498
499 uniform vec2 drawScale;
500
501 void main()
502 {
503 gl_Position = vec4(position.xy * drawScale, 0.0, 1.0);
504 texcoord = (position.xy * 0.5) + 0.5;
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300505 })";
Jamie Madill2453dbc2015-07-14 11:35:42 -0400506 }
507
508 void SetUp() override
509 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200510 Texture2DTest::SetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300511
512 setUpProgram();
513
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200514 mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale");
515 ASSERT_NE(-1, mDrawScaleUniformLocation);
Jamie Madill2453dbc2015-07-14 11:35:42 -0400516
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200517 glUseProgram(mProgram);
518 glUniform2f(mDrawScaleUniformLocation, 1.0f, 1.0f);
519 glUseProgram(0);
520 ASSERT_GL_NO_ERROR();
521 }
522
523 GLint mDrawScaleUniformLocation;
524};
525
Olli Etuaho4644a202016-01-12 15:12:53 +0200526class Sampler2DAsFunctionParameterTest : public Texture2DTest
527{
528 protected:
529 Sampler2DAsFunctionParameterTest() : Texture2DTest() {}
530
531 std::string getFragmentShaderSource() override
532 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300533 return
534 R"(precision highp float;
Olli Etuaho4644a202016-01-12 15:12:53 +0200535 uniform sampler2D tex;
536 varying vec2 texcoord;
537
538 vec4 computeFragColor(sampler2D aTex)
539 {
540 return texture2D(aTex, texcoord);
541 }
542
543 void main()
544 {
545 gl_FragColor = computeFragColor(tex);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300546 })";
Olli Etuaho4644a202016-01-12 15:12:53 +0200547 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300548
549 void SetUp() override
550 {
551 Texture2DTest::SetUp();
552 setUpProgram();
553 }
Olli Etuaho4644a202016-01-12 15:12:53 +0200554};
555
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200556class TextureCubeTest : public TexCoordDrawTest
557{
558 protected:
559 TextureCubeTest()
560 : TexCoordDrawTest(),
561 mTexture2D(0),
562 mTextureCube(0),
563 mTexture2DUniformLocation(-1),
564 mTextureCubeUniformLocation(-1)
565 {
566 }
567
568 std::string getFragmentShaderSource() override
569 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300570 return
571 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200572 uniform sampler2D tex2D;
573 uniform samplerCube texCube;
574 varying vec2 texcoord;
575
576 void main()
577 {
578 gl_FragColor = texture2D(tex2D, texcoord);
579 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300580 })";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200581 }
582
583 void SetUp() override
584 {
585 TexCoordDrawTest::SetUp();
586
587 glGenTextures(1, &mTextureCube);
588 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Geoff Langc4e93662017-05-01 10:45:59 -0400589 for (GLenum face = 0; face < 6; face++)
590 {
591 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
592 GL_UNSIGNED_BYTE, nullptr);
593 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200594 EXPECT_GL_NO_ERROR();
595
596 mTexture2D = create2DTexture();
597
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300598 setUpProgram();
599
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200600 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
601 ASSERT_NE(-1, mTexture2DUniformLocation);
602 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
603 ASSERT_NE(-1, mTextureCubeUniformLocation);
604 }
605
606 void TearDown() override
607 {
608 glDeleteTextures(1, &mTextureCube);
609 TexCoordDrawTest::TearDown();
610 }
611
612 GLuint mTexture2D;
613 GLuint mTextureCube;
614 GLint mTexture2DUniformLocation;
615 GLint mTextureCubeUniformLocation;
616};
617
Martin Radev7e2c0d32017-09-15 14:25:42 +0300618class TextureCubeTestES3 : public ANGLETest
619{
620 protected:
621 TextureCubeTestES3() {}
622};
623
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200624class SamplerArrayTest : public TexCoordDrawTest
625{
626 protected:
627 SamplerArrayTest()
628 : TexCoordDrawTest(),
629 mTexture2DA(0),
630 mTexture2DB(0),
631 mTexture0UniformLocation(-1),
632 mTexture1UniformLocation(-1)
633 {
634 }
635
636 std::string getFragmentShaderSource() override
637 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300638 return
639 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200640 uniform highp sampler2D tex2DArray[2];
641 varying vec2 texcoord;
642 void main()
643 {
644 gl_FragColor = texture2D(tex2DArray[0], texcoord);
645 gl_FragColor += texture2D(tex2DArray[1], texcoord);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300646 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200647 }
648
649 void SetUp() override
650 {
651 TexCoordDrawTest::SetUp();
652
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300653 setUpProgram();
654
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200655 mTexture0UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[0]");
656 ASSERT_NE(-1, mTexture0UniformLocation);
657 mTexture1UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[1]");
658 ASSERT_NE(-1, mTexture1UniformLocation);
659
660 mTexture2DA = create2DTexture();
661 mTexture2DB = create2DTexture();
662 ASSERT_GL_NO_ERROR();
663 }
664
665 void TearDown() override
666 {
667 glDeleteTextures(1, &mTexture2DA);
668 glDeleteTextures(1, &mTexture2DB);
669 TexCoordDrawTest::TearDown();
670 }
671
672 void testSamplerArrayDraw()
673 {
674 GLubyte texData[4];
675 texData[0] = 0;
676 texData[1] = 60;
677 texData[2] = 0;
678 texData[3] = 255;
679
680 glActiveTexture(GL_TEXTURE0);
681 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
682 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
683
684 texData[1] = 120;
685 glActiveTexture(GL_TEXTURE1);
686 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
687 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
688 EXPECT_GL_ERROR(GL_NO_ERROR);
689
690 glUseProgram(mProgram);
691 glUniform1i(mTexture0UniformLocation, 0);
692 glUniform1i(mTexture1UniformLocation, 1);
693 drawQuad(mProgram, "position", 0.5f);
694 EXPECT_GL_NO_ERROR();
695
696 EXPECT_PIXEL_NEAR(0, 0, 0, 180, 0, 255, 2);
697 }
698
699 GLuint mTexture2DA;
700 GLuint mTexture2DB;
701 GLint mTexture0UniformLocation;
702 GLint mTexture1UniformLocation;
703};
704
705
706class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest
707{
708 protected:
709 SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {}
710
711 std::string getFragmentShaderSource() override
712 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300713 return
714 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200715 uniform highp sampler2D tex2DArray[2];
716 varying vec2 texcoord;
717
718 vec4 computeFragColor(highp sampler2D aTex2DArray[2])
719 {
720 return texture2D(aTex2DArray[0], texcoord) + texture2D(aTex2DArray[1], texcoord);
721 }
722
723 void main()
724 {
725 gl_FragColor = computeFragColor(tex2DArray);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300726 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200727 }
728};
729
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200730class Texture2DArrayTestES3 : public TexCoordDrawTest
731{
732 protected:
733 Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {}
734
735 std::string getVertexShaderSource() override
736 {
737 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400738 "#version 300 es\n"
739 "out vec2 texcoord;\n"
740 "in vec4 position;\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200741 "void main()\n"
742 "{\n"
743 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
744 " texcoord = (position.xy * 0.5) + 0.5;\n"
745 "}\n");
746 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400747
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200748 std::string getFragmentShaderSource() override
749 {
750 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400751 "#version 300 es\n"
752 "precision highp float;\n"
Olli Etuaho183d7e22015-11-20 15:59:09 +0200753 "uniform highp sampler2DArray tex2DArray;\n"
Jamie Madill2453dbc2015-07-14 11:35:42 -0400754 "in vec2 texcoord;\n"
755 "out vec4 fragColor;\n"
756 "void main()\n"
757 "{\n"
758 " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200759 "}\n");
760 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400761
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200762 void SetUp() override
763 {
764 TexCoordDrawTest::SetUp();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400765
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300766 setUpProgram();
767
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200768 mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray");
Jamie Madill2453dbc2015-07-14 11:35:42 -0400769 ASSERT_NE(-1, mTextureArrayLocation);
770
771 glGenTextures(1, &m2DArrayTexture);
772 ASSERT_GL_NO_ERROR();
773 }
774
775 void TearDown() override
776 {
777 glDeleteTextures(1, &m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200778 TexCoordDrawTest::TearDown();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400779 }
780
781 GLuint m2DArrayTexture;
Jamie Madill2453dbc2015-07-14 11:35:42 -0400782 GLint mTextureArrayLocation;
783};
784
Olli Etuahobce743a2016-01-15 17:18:28 +0200785class TextureSizeTextureArrayTest : public TexCoordDrawTest
786{
787 protected:
788 TextureSizeTextureArrayTest()
789 : TexCoordDrawTest(),
790 mTexture2DA(0),
791 mTexture2DB(0),
792 mTexture0Location(-1),
793 mTexture1Location(-1)
794 {
795 }
796
797 std::string getVertexShaderSource() override
798 {
799 return std::string(
800 "#version 300 es\n"
801 "in vec4 position;\n"
802 "void main()\n"
803 "{\n"
804 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
805 "}\n");
806 }
807
808 std::string getFragmentShaderSource() override
809 {
810 return std::string(
811 "#version 300 es\n"
812 "precision highp float;\n"
813 "uniform highp sampler2D tex2DArray[2];\n"
814 "out vec4 fragColor;\n"
815 "void main()\n"
816 "{\n"
817 " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n"
818 " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n"
819 " fragColor = vec4(red, green, 0.0, 1.0);\n"
820 "}\n");
821 }
822
823 void SetUp() override
824 {
825 TexCoordDrawTest::SetUp();
826
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300827 setUpProgram();
828
Olli Etuahobce743a2016-01-15 17:18:28 +0200829 mTexture0Location = glGetUniformLocation(mProgram, "tex2DArray[0]");
830 ASSERT_NE(-1, mTexture0Location);
831 mTexture1Location = glGetUniformLocation(mProgram, "tex2DArray[1]");
832 ASSERT_NE(-1, mTexture1Location);
833
834 mTexture2DA = create2DTexture();
835 mTexture2DB = create2DTexture();
836 ASSERT_GL_NO_ERROR();
837 }
838
839 void TearDown() override
840 {
841 glDeleteTextures(1, &mTexture2DA);
842 glDeleteTextures(1, &mTexture2DB);
843 TexCoordDrawTest::TearDown();
844 }
845
846 GLuint mTexture2DA;
847 GLuint mTexture2DB;
848 GLint mTexture0Location;
849 GLint mTexture1Location;
850};
851
Olli Etuahoa314b612016-03-10 16:43:00 +0200852class Texture3DTestES3 : public TexCoordDrawTest
853{
854 protected:
855 Texture3DTestES3() : TexCoordDrawTest(), mTexture3D(0), mTexture3DUniformLocation(-1) {}
856
857 std::string getVertexShaderSource() override
858 {
859 return std::string(
860 "#version 300 es\n"
861 "out vec2 texcoord;\n"
862 "in vec4 position;\n"
863 "void main()\n"
864 "{\n"
865 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
866 " texcoord = (position.xy * 0.5) + 0.5;\n"
867 "}\n");
868 }
869
870 std::string getFragmentShaderSource() override
871 {
872 return std::string(
873 "#version 300 es\n"
874 "precision highp float;\n"
875 "uniform highp sampler3D tex3D;\n"
876 "in vec2 texcoord;\n"
877 "out vec4 fragColor;\n"
878 "void main()\n"
879 "{\n"
880 " fragColor = texture(tex3D, vec3(texcoord, 0.0));\n"
881 "}\n");
882 }
883
884 void SetUp() override
885 {
886 TexCoordDrawTest::SetUp();
887
888 glGenTextures(1, &mTexture3D);
889
890 setUpProgram();
891
892 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
893 ASSERT_NE(-1, mTexture3DUniformLocation);
894 }
895
896 void TearDown() override
897 {
898 glDeleteTextures(1, &mTexture3D);
899 TexCoordDrawTest::TearDown();
900 }
901
902 GLuint mTexture3D;
903 GLint mTexture3DUniformLocation;
904};
905
Olli Etuaho1a679902016-01-14 12:21:47 +0200906class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest
907{
908 protected:
909 ShadowSamplerPlusSampler3DTestES3()
910 : TexCoordDrawTest(),
911 mTextureShadow(0),
912 mTexture3D(0),
913 mTextureShadowUniformLocation(-1),
914 mTexture3DUniformLocation(-1),
915 mDepthRefUniformLocation(-1)
916 {
917 }
918
919 std::string getVertexShaderSource() override
920 {
921 return std::string(
922 "#version 300 es\n"
923 "out vec2 texcoord;\n"
924 "in vec4 position;\n"
925 "void main()\n"
926 "{\n"
927 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
928 " texcoord = (position.xy * 0.5) + 0.5;\n"
929 "}\n");
930 }
931
932 std::string getFragmentShaderSource() override
933 {
934 return std::string(
935 "#version 300 es\n"
936 "precision highp float;\n"
937 "uniform highp sampler2DShadow tex2DShadow;\n"
938 "uniform highp sampler3D tex3D;\n"
939 "in vec2 texcoord;\n"
940 "uniform float depthRef;\n"
941 "out vec4 fragColor;\n"
942 "void main()\n"
943 "{\n"
944 " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n"
945 " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n"
946 "}\n");
947 }
948
949 void SetUp() override
950 {
951 TexCoordDrawTest::SetUp();
952
953 glGenTextures(1, &mTexture3D);
954
955 glGenTextures(1, &mTextureShadow);
956 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
957 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
958
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300959 setUpProgram();
960
Olli Etuaho1a679902016-01-14 12:21:47 +0200961 mTextureShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
962 ASSERT_NE(-1, mTextureShadowUniformLocation);
963 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
964 ASSERT_NE(-1, mTexture3DUniformLocation);
965 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
966 ASSERT_NE(-1, mDepthRefUniformLocation);
967 }
968
969 void TearDown() override
970 {
971 glDeleteTextures(1, &mTextureShadow);
972 glDeleteTextures(1, &mTexture3D);
973 TexCoordDrawTest::TearDown();
974 }
975
976 GLuint mTextureShadow;
977 GLuint mTexture3D;
978 GLint mTextureShadowUniformLocation;
979 GLint mTexture3DUniformLocation;
980 GLint mDepthRefUniformLocation;
981};
982
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200983class SamplerTypeMixTestES3 : public TexCoordDrawTest
984{
985 protected:
986 SamplerTypeMixTestES3()
987 : TexCoordDrawTest(),
988 mTexture2D(0),
989 mTextureCube(0),
990 mTexture2DShadow(0),
991 mTextureCubeShadow(0),
992 mTexture2DUniformLocation(-1),
993 mTextureCubeUniformLocation(-1),
994 mTexture2DShadowUniformLocation(-1),
995 mTextureCubeShadowUniformLocation(-1),
996 mDepthRefUniformLocation(-1)
997 {
998 }
999
1000 std::string getVertexShaderSource() override
1001 {
1002 return std::string(
1003 "#version 300 es\n"
1004 "out vec2 texcoord;\n"
1005 "in vec4 position;\n"
1006 "void main()\n"
1007 "{\n"
1008 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1009 " texcoord = (position.xy * 0.5) + 0.5;\n"
1010 "}\n");
1011 }
1012
1013 std::string getFragmentShaderSource() override
1014 {
1015 return std::string(
1016 "#version 300 es\n"
1017 "precision highp float;\n"
1018 "uniform highp sampler2D tex2D;\n"
1019 "uniform highp samplerCube texCube;\n"
1020 "uniform highp sampler2DShadow tex2DShadow;\n"
1021 "uniform highp samplerCubeShadow texCubeShadow;\n"
1022 "in vec2 texcoord;\n"
1023 "uniform float depthRef;\n"
1024 "out vec4 fragColor;\n"
1025 "void main()\n"
1026 "{\n"
1027 " fragColor = texture(tex2D, texcoord);\n"
1028 " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n"
1029 " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n"
1030 " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * "
1031 "0.125);\n"
1032 "}\n");
1033 }
1034
1035 void SetUp() override
1036 {
1037 TexCoordDrawTest::SetUp();
1038
1039 glGenTextures(1, &mTexture2D);
1040 glGenTextures(1, &mTextureCube);
1041
1042 glGenTextures(1, &mTexture2DShadow);
1043 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
1044 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
1045
1046 glGenTextures(1, &mTextureCubeShadow);
1047 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
1048 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
1049
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001050 setUpProgram();
1051
Olli Etuahoc8c99a02016-01-14 16:47:22 +02001052 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
1053 ASSERT_NE(-1, mTexture2DUniformLocation);
1054 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
1055 ASSERT_NE(-1, mTextureCubeUniformLocation);
1056 mTexture2DShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
1057 ASSERT_NE(-1, mTexture2DShadowUniformLocation);
1058 mTextureCubeShadowUniformLocation = glGetUniformLocation(mProgram, "texCubeShadow");
1059 ASSERT_NE(-1, mTextureCubeShadowUniformLocation);
1060 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
1061 ASSERT_NE(-1, mDepthRefUniformLocation);
1062
1063 ASSERT_GL_NO_ERROR();
1064 }
1065
1066 void TearDown() override
1067 {
1068 glDeleteTextures(1, &mTexture2D);
1069 glDeleteTextures(1, &mTextureCube);
1070 glDeleteTextures(1, &mTexture2DShadow);
1071 glDeleteTextures(1, &mTextureCubeShadow);
1072 TexCoordDrawTest::TearDown();
1073 }
1074
1075 GLuint mTexture2D;
1076 GLuint mTextureCube;
1077 GLuint mTexture2DShadow;
1078 GLuint mTextureCubeShadow;
1079 GLint mTexture2DUniformLocation;
1080 GLint mTextureCubeUniformLocation;
1081 GLint mTexture2DShadowUniformLocation;
1082 GLint mTextureCubeShadowUniformLocation;
1083 GLint mDepthRefUniformLocation;
1084};
1085
Olli Etuaho96963162016-03-21 11:54:33 +02001086class SamplerInStructTest : public Texture2DTest
1087{
1088 protected:
1089 SamplerInStructTest() : Texture2DTest() {}
1090
1091 const char *getTextureUniformName() override { return "us.tex"; }
1092
1093 std::string getFragmentShaderSource() override
1094 {
1095 return std::string(
1096 "precision highp float;\n"
1097 "struct S\n"
1098 "{\n"
1099 " vec4 a;\n"
1100 " highp sampler2D tex;\n"
1101 "};\n"
1102 "uniform S us;\n"
1103 "varying vec2 texcoord;\n"
1104 "void main()\n"
1105 "{\n"
1106 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x);\n"
1107 "}\n");
1108 }
1109
1110 void runSamplerInStructTest()
1111 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001112 setUpProgram();
1113
Olli Etuaho96963162016-03-21 11:54:33 +02001114 glActiveTexture(GL_TEXTURE0);
1115 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001116 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1117 &GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001118 drawQuad(mProgram, "position", 0.5f);
Olli Etuahoa314b612016-03-10 16:43:00 +02001119 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001120 }
1121};
1122
1123class SamplerInStructAsFunctionParameterTest : public SamplerInStructTest
1124{
1125 protected:
1126 SamplerInStructAsFunctionParameterTest() : SamplerInStructTest() {}
1127
1128 std::string getFragmentShaderSource() override
1129 {
1130 return std::string(
1131 "precision highp float;\n"
1132 "struct S\n"
1133 "{\n"
1134 " vec4 a;\n"
1135 " highp sampler2D tex;\n"
1136 "};\n"
1137 "uniform S us;\n"
1138 "varying vec2 texcoord;\n"
1139 "vec4 sampleFrom(S s) {\n"
1140 " return texture2D(s.tex, texcoord + s.a.x);\n"
1141 "}\n"
1142 "void main()\n"
1143 "{\n"
1144 " gl_FragColor = sampleFrom(us);\n"
1145 "}\n");
1146 }
1147};
1148
1149class SamplerInStructArrayAsFunctionParameterTest : public SamplerInStructTest
1150{
1151 protected:
1152 SamplerInStructArrayAsFunctionParameterTest() : SamplerInStructTest() {}
1153
1154 const char *getTextureUniformName() override { return "us[0].tex"; }
1155
1156 std::string getFragmentShaderSource() override
1157 {
1158 return std::string(
1159 "precision highp float;\n"
1160 "struct S\n"
1161 "{\n"
1162 " vec4 a;\n"
1163 " highp sampler2D tex;\n"
1164 "};\n"
1165 "uniform S us[1];\n"
1166 "varying vec2 texcoord;\n"
1167 "vec4 sampleFrom(S s) {\n"
1168 " return texture2D(s.tex, texcoord + s.a.x);\n"
1169 "}\n"
1170 "void main()\n"
1171 "{\n"
1172 " gl_FragColor = sampleFrom(us[0]);\n"
1173 "}\n");
1174 }
1175};
1176
1177class SamplerInNestedStructAsFunctionParameterTest : public SamplerInStructTest
1178{
1179 protected:
1180 SamplerInNestedStructAsFunctionParameterTest() : SamplerInStructTest() {}
1181
1182 const char *getTextureUniformName() override { return "us[0].sub.tex"; }
1183
1184 std::string getFragmentShaderSource() override
1185 {
1186 return std::string(
1187 "precision highp float;\n"
1188 "struct SUB\n"
1189 "{\n"
1190 " vec4 a;\n"
1191 " highp sampler2D tex;\n"
1192 "};\n"
1193 "struct S\n"
1194 "{\n"
1195 " SUB sub;\n"
1196 "};\n"
1197 "uniform S us[1];\n"
1198 "varying vec2 texcoord;\n"
1199 "vec4 sampleFrom(SUB s) {\n"
1200 " return texture2D(s.tex, texcoord + s.a.x);\n"
1201 "}\n"
1202 "void main()\n"
1203 "{\n"
1204 " gl_FragColor = sampleFrom(us[0].sub);\n"
1205 "}\n");
1206 }
1207};
1208
1209class SamplerInStructAndOtherVariableTest : public SamplerInStructTest
1210{
1211 protected:
1212 SamplerInStructAndOtherVariableTest() : SamplerInStructTest() {}
1213
1214 std::string getFragmentShaderSource() override
1215 {
1216 return std::string(
1217 "precision highp float;\n"
1218 "struct S\n"
1219 "{\n"
1220 " vec4 a;\n"
1221 " highp sampler2D tex;\n"
1222 "};\n"
1223 "uniform S us;\n"
1224 "uniform float us_tex;\n"
1225 "varying vec2 texcoord;\n"
1226 "void main()\n"
1227 "{\n"
1228 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x + us_tex);\n"
1229 "}\n");
1230 }
1231};
1232
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001233TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001234{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001235 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001236 EXPECT_GL_ERROR(GL_NO_ERROR);
1237
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001238 setUpProgram();
1239
Jamie Madillf67115c2014-04-22 13:14:05 -04001240 const GLubyte *pixels[20] = { 0 };
1241 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1242 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001243
1244 if (extensionEnabled("GL_EXT_texture_storage"))
1245 {
1246 // Create a 1-level immutable texture.
1247 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1248
1249 // Try calling sub image on the second level.
1250 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1251 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1252 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001253}
Geoff Langc41e42d2014-04-28 10:58:16 -04001254
John Bauman18319182016-09-28 14:22:27 -07001255// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1256TEST_P(Texture2DTest, QueryBinding)
1257{
1258 glBindTexture(GL_TEXTURE_2D, 0);
1259 EXPECT_GL_ERROR(GL_NO_ERROR);
1260
1261 GLint textureBinding;
1262 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1263 EXPECT_GL_NO_ERROR();
1264 EXPECT_EQ(0, textureBinding);
1265
1266 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
1267 if (extensionEnabled("GL_OES_EGL_image_external") ||
1268 extensionEnabled("GL_NV_EGL_stream_consumer_external"))
1269 {
1270 EXPECT_GL_NO_ERROR();
1271 EXPECT_EQ(0, textureBinding);
1272 }
1273 else
1274 {
1275 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1276 }
1277}
1278
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001279TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001280{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001281 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001282 EXPECT_GL_ERROR(GL_NO_ERROR);
1283
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001284 setUpProgram();
1285
Geoff Langc41e42d2014-04-28 10:58:16 -04001286 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001287 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001288 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001289 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001290
1291 const GLubyte *pixel[4] = { 0 };
1292
1293 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1294 EXPECT_GL_NO_ERROR();
1295
1296 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1297 EXPECT_GL_NO_ERROR();
1298
1299 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1300 EXPECT_GL_NO_ERROR();
1301}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001302
1303// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001304TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001305{
1306 glActiveTexture(GL_TEXTURE0);
1307 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1308 glActiveTexture(GL_TEXTURE1);
1309 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1310 EXPECT_GL_ERROR(GL_NO_ERROR);
1311
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001312 glUseProgram(mProgram);
1313 glUniform1i(mTexture2DUniformLocation, 0);
1314 glUniform1i(mTextureCubeUniformLocation, 1);
1315 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001316 EXPECT_GL_NO_ERROR();
1317}
Jamie Madill9aca0592014-10-06 16:26:59 -04001318
Olli Etuaho53a2da12016-01-11 15:43:32 +02001319// Test drawing with two texture types accessed from the same shader and check that the result of
1320// drawing is correct.
1321TEST_P(TextureCubeTest, CubeMapDraw)
1322{
1323 GLubyte texData[4];
1324 texData[0] = 0;
1325 texData[1] = 60;
1326 texData[2] = 0;
1327 texData[3] = 255;
1328
1329 glActiveTexture(GL_TEXTURE0);
1330 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1331 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1332
1333 glActiveTexture(GL_TEXTURE1);
1334 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1335 texData[1] = 120;
1336 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1337 texData);
1338 EXPECT_GL_ERROR(GL_NO_ERROR);
1339
1340 glUseProgram(mProgram);
1341 glUniform1i(mTexture2DUniformLocation, 0);
1342 glUniform1i(mTextureCubeUniformLocation, 1);
1343 drawQuad(mProgram, "position", 0.5f);
1344 EXPECT_GL_NO_ERROR();
1345
1346 int px = getWindowWidth() - 1;
1347 int py = 0;
1348 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1349}
1350
Olli Etuaho4644a202016-01-12 15:12:53 +02001351TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1352{
1353 glActiveTexture(GL_TEXTURE0);
1354 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1355 GLubyte texData[4];
1356 texData[0] = 0;
1357 texData[1] = 128;
1358 texData[2] = 0;
1359 texData[3] = 255;
1360 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1361 glUseProgram(mProgram);
1362 glUniform1i(mTexture2DUniformLocation, 0);
1363 drawQuad(mProgram, "position", 0.5f);
1364 EXPECT_GL_NO_ERROR();
1365
1366 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1367}
1368
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001369// Test drawing with two textures passed to the shader in a sampler array.
1370TEST_P(SamplerArrayTest, SamplerArrayDraw)
1371{
1372 testSamplerArrayDraw();
1373}
1374
1375// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1376// user-defined function in the shader.
1377TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1378{
1379 testSamplerArrayDraw();
1380}
1381
Jamie Madill9aca0592014-10-06 16:26:59 -04001382// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001383TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001384{
1385 int px = getWindowWidth() / 2;
1386 int py = getWindowHeight() / 2;
1387
1388 glActiveTexture(GL_TEXTURE0);
1389 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1390
Olli Etuahoa314b612016-03-10 16:43:00 +02001391 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001392
Olli Etuahoa314b612016-03-10 16:43:00 +02001393 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001394 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1395 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1396 glGenerateMipmap(GL_TEXTURE_2D);
1397
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001398 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001399 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001400 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1401 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001402 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001403 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001404
Olli Etuahoa314b612016-03-10 16:43:00 +02001405 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001406
Olli Etuahoa314b612016-03-10 16:43:00 +02001407 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1408 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001409 glGenerateMipmap(GL_TEXTURE_2D);
1410
Olli Etuahoa314b612016-03-10 16:43:00 +02001411 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001412
Olli Etuahoa314b612016-03-10 16:43:00 +02001413 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1414 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001415 glGenerateMipmap(GL_TEXTURE_2D);
1416
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001417 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001418
1419 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001420 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001421}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001422
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001423// Test creating a FBO with a cube map render target, to test an ANGLE bug
1424// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001425TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001426{
1427 GLuint fbo;
1428 glGenFramebuffers(1, &fbo);
1429 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1430
1431 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1432 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mTextureCube, 0);
1433
Corentin Wallez322653b2015-06-17 18:33:56 +02001434 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001435
1436 glDeleteFramebuffers(1, &fbo);
1437
1438 EXPECT_GL_NO_ERROR();
1439}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001440
1441// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001442TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001443{
Geoff Langc4e93662017-05-01 10:45:59 -04001444 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_texture_storage"))
1445 {
1446 std::cout << "Test skipped because ES3 or GL_EXT_texture_storage not available."
1447 << std::endl;
1448 return;
1449 }
1450
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001451 int width = getWindowWidth();
1452 int height = getWindowHeight();
1453
1454 GLuint tex2D;
1455 glGenTextures(1, &tex2D);
1456 glActiveTexture(GL_TEXTURE0);
1457 glBindTexture(GL_TEXTURE_2D, tex2D);
1458
1459 // Fill with red
1460 std::vector<GLubyte> pixels(3 * 16 * 16);
1461 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1462 {
1463 pixels[pixelId * 3 + 0] = 255;
1464 pixels[pixelId * 3 + 1] = 0;
1465 pixels[pixelId * 3 + 2] = 0;
1466 }
1467
1468 // ANGLE internally uses RGBA as the DirectX format for RGB images
1469 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1470 // The data is kept in a CPU-side image and the image is marked as dirty.
Geoff Langc4e93662017-05-01 10:45:59 -04001471 if (getClientMajorVersion() >= 3)
1472 {
1473 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1474 }
1475 else
1476 {
1477 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1478 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001479
1480 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1481 // glTexSubImage2D should take into account that the image is dirty.
1482 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1483 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1484 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1485
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001486 setUpProgram();
1487
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001488 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001489 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001490 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001491 glDeleteTextures(1, &tex2D);
1492 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001493 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001494
1495 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001496 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1497 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001498}
1499
1500// 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 +02001501TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001502{
1503 if (extensionEnabled("NV_pixel_buffer_object"))
1504 {
1505 int width = getWindowWidth();
1506 int height = getWindowHeight();
1507
1508 GLuint tex2D;
1509 glGenTextures(1, &tex2D);
1510 glActiveTexture(GL_TEXTURE0);
1511 glBindTexture(GL_TEXTURE_2D, tex2D);
1512
1513 // Fill with red
1514 std::vector<GLubyte> pixels(3 * 16 * 16);
1515 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1516 {
1517 pixels[pixelId * 3 + 0] = 255;
1518 pixels[pixelId * 3 + 1] = 0;
1519 pixels[pixelId * 3 + 2] = 0;
1520 }
1521
1522 // Read 16x16 region from red backbuffer to PBO
1523 GLuint pbo;
1524 glGenBuffers(1, &pbo);
1525 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1526 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1527
1528 // ANGLE internally uses RGBA as the DirectX format for RGB images
1529 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1530 // The data is kept in a CPU-side image and the image is marked as dirty.
1531 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1532
1533 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1534 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001535 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 +00001536 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1537 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1538
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001539 setUpProgram();
1540
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001541 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001542 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001543 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001544 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001545 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001546 EXPECT_GL_NO_ERROR();
1547 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1548 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1549 }
1550}
Jamie Madillbc393df2015-01-29 13:46:07 -05001551
1552// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001553TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001554{
1555 testFloatCopySubImage(1, 1);
1556}
1557
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001558TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001559{
1560 testFloatCopySubImage(2, 1);
1561}
1562
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001563TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001564{
1565 testFloatCopySubImage(2, 2);
1566}
1567
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001568TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001569{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001570 if (IsIntel() && IsLinux())
1571 {
1572 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1573 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1574 return;
1575 }
1576
Jamie Madillbc393df2015-01-29 13:46:07 -05001577 testFloatCopySubImage(3, 1);
1578}
1579
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001580TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001581{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001582 if (IsIntel() && IsLinux())
1583 {
1584 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1585 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1586 return;
1587 }
1588
Jamie Madillbc393df2015-01-29 13:46:07 -05001589 testFloatCopySubImage(3, 2);
1590}
1591
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001592TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001593{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001594 if (IsIntel() && IsLinux())
1595 {
1596 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1597 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1598 return;
1599 }
1600
Austin Kinrossd544cc92016-01-11 15:26:42 -08001601 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001602 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001603 {
1604 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1605 return;
1606 }
1607
Jamie Madillbc393df2015-01-29 13:46:07 -05001608 testFloatCopySubImage(3, 3);
1609}
1610
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001611TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001612{
1613 testFloatCopySubImage(4, 1);
1614}
1615
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001616TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001617{
1618 testFloatCopySubImage(4, 2);
1619}
1620
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001621TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001622{
Austin Kinrossd544cc92016-01-11 15:26:42 -08001623 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001624 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001625 {
1626 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1627 return;
1628 }
1629
Jamie Madillbc393df2015-01-29 13:46:07 -05001630 testFloatCopySubImage(4, 3);
1631}
1632
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001633TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001634{
Austin Kinrossd544cc92016-01-11 15:26:42 -08001635 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001636 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001637 {
1638 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1639 return;
1640 }
1641
Jamie Madillbc393df2015-01-29 13:46:07 -05001642 testFloatCopySubImage(4, 4);
1643}
Austin Kinross07285142015-03-26 11:36:16 -07001644
1645// Port of https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1646// 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 +02001647TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001648{
1649 const int npotTexSize = 5;
1650 const int potTexSize = 4; // Should be less than npotTexSize
1651 GLuint tex2D;
1652
1653 if (extensionEnabled("GL_OES_texture_npot"))
1654 {
1655 // This test isn't applicable if texture_npot is enabled
1656 return;
1657 }
1658
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001659 setUpProgram();
1660
Austin Kinross07285142015-03-26 11:36:16 -07001661 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1662
Austin Kinross5faa15b2016-01-11 13:32:48 -08001663 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1664 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1665
Austin Kinross07285142015-03-26 11:36:16 -07001666 glActiveTexture(GL_TEXTURE0);
1667 glGenTextures(1, &tex2D);
1668 glBindTexture(GL_TEXTURE_2D, tex2D);
1669
1670 std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize);
1671 for (size_t pixelId = 0; pixelId < npotTexSize * npotTexSize; ++pixelId)
1672 {
1673 pixels[pixelId] = 64;
1674 }
1675
1676 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1677 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1678
1679 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
1680 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1681 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1682
1683 // Check that an NPOT texture on level 0 succeeds
1684 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1685 EXPECT_GL_NO_ERROR();
1686
1687 // Check that generateMipmap fails on NPOT
1688 glGenerateMipmap(GL_TEXTURE_2D);
1689 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1690
1691 // Check that nothing is drawn if filtering is not correct for NPOT
1692 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1693 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1694 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1695 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1696 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001697 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001698 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1699
1700 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1701 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1702 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1703 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1704 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001705 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001706 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1707
1708 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1709 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1710 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001711 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001712 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1713
1714 // Check that glTexImage2D for POT texture succeeds
1715 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1716 EXPECT_GL_NO_ERROR();
1717
1718 // Check that generateMipmap for an POT texture succeeds
1719 glGenerateMipmap(GL_TEXTURE_2D);
1720 EXPECT_GL_NO_ERROR();
1721
1722 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1723 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1724 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1725 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1726 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1727 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001728 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001729 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1730 EXPECT_GL_NO_ERROR();
1731}
Jamie Madillfa05f602015-05-07 13:47:11 -04001732
Austin Kinross08528e12015-10-07 16:24:40 -07001733// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1734// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001735TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001736{
Geoff Lange0cc2a42016-01-20 10:58:17 -05001737 // TODO(geofflang): Allow the GL backend to accept SubImage calls with a null data ptr. (bug
1738 // 1278)
1739 if (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
1740 getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE)
1741 {
1742 std::cout << "Test disabled on OpenGL." << std::endl;
1743 return;
1744 }
1745
Austin Kinross08528e12015-10-07 16:24:40 -07001746 glActiveTexture(GL_TEXTURE0);
1747 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1748
1749 // Create an 8x8 (i.e. power-of-two) texture.
1750 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1751 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1752 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1753 glGenerateMipmap(GL_TEXTURE_2D);
1754
1755 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1756 // This should always work, even if GL_OES_texture_npot isn't active.
1757 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1758
1759 EXPECT_GL_NO_ERROR();
1760}
1761
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001762// Test to check that texture completeness is determined correctly when the texture base level is
1763// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1764TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1765{
1766 glActiveTexture(GL_TEXTURE0);
1767 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001768
1769 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1770 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1771 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1772 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1773 texDataGreen.data());
1774 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1775 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001776 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1777 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1778 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1779
1780 EXPECT_GL_NO_ERROR();
1781
1782 drawQuad(mProgram, "position", 0.5f);
1783
Olli Etuahoa314b612016-03-10 16:43:00 +02001784 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1785}
1786
1787// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1788// have images defined.
1789TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1790{
1791 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1792 {
1793 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1794 std::cout << "Test skipped on AMD OpenGL." << std::endl;
1795 return;
1796 }
1797 if (IsOSX())
1798 {
1799 // Observed incorrect rendering on OSX.
1800 std::cout << "Test skipped on OSX." << std::endl;
1801 return;
1802 }
1803 glActiveTexture(GL_TEXTURE0);
1804 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1805 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1806 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1807 texDataGreen.data());
1808 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1809 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1810 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1811 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1812
1813 EXPECT_GL_NO_ERROR();
1814
1815 drawQuad(mProgram, "position", 0.5f);
1816
1817 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1818}
1819
Olli Etuahoe8528d82016-05-16 17:50:52 +03001820// Test that drawing works correctly when level 0 is undefined and base level is 1.
1821TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1822{
1823 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1824 {
1825 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1826 std::cout << "Test skipped on AMD OpenGL." << std::endl;
1827 return;
1828 }
1829 if (IsOSX())
1830 {
1831 // Observed incorrect rendering on OSX.
1832 std::cout << "Test skipped on OSX." << std::endl;
1833 return;
1834 }
1835 glActiveTexture(GL_TEXTURE0);
1836 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1837 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1838 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1839 texDataGreen.data());
1840 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1841 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1842 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1843 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1844
1845 EXPECT_GL_NO_ERROR();
1846
1847 // Texture is incomplete.
1848 drawQuad(mProgram, "position", 0.5f);
1849 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1850
1851 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1852 texDataGreen.data());
1853
1854 // Texture is now complete.
1855 drawQuad(mProgram, "position", 0.5f);
1856 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1857}
1858
Olli Etuahoa314b612016-03-10 16:43:00 +02001859// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1860// dimensions that don't fit the images inside the range.
1861// GLES 3.0.4 section 3.8.13 Texture completeness
1862TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1863{
1864 if (IsOSX())
1865 {
1866 // Observed incorrect rendering on OSX.
1867 std::cout << "Test skipped on OSX." << std::endl;
1868 return;
1869 }
1870 glActiveTexture(GL_TEXTURE0);
1871 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1872 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1873 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1874 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1875
1876 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1877 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1878
1879 // Two levels that are initially unused.
1880 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1881 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1882 texDataCyan.data());
1883
1884 // One level that is used - only this level should affect completeness.
1885 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1886 texDataGreen.data());
1887
1888 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1889 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1890
1891 EXPECT_GL_NO_ERROR();
1892
1893 drawQuad(mProgram, "position", 0.5f);
1894
1895 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1896
1897 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1898 {
1899 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
1900 // level was changed.
1901 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
1902 return;
1903 }
1904
1905 // Switch the level that is being used to the cyan level 2.
1906 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1907 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1908
1909 EXPECT_GL_NO_ERROR();
1910
1911 drawQuad(mProgram, "position", 0.5f);
1912
1913 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1914}
1915
1916// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1917// have images defined.
1918TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1919{
1920 if (IsOSX())
1921 {
1922 // Observed incorrect rendering on OSX.
1923 std::cout << "Test skipped on OSX." << std::endl;
1924 return;
1925 }
1926 glActiveTexture(GL_TEXTURE0);
1927 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1928 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1929 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1930 texDataGreen.data());
1931 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1932 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1933 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1934 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1935
1936 EXPECT_GL_NO_ERROR();
1937
1938 drawQuad(mProgram, "position", 0.5f);
1939
1940 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1941}
1942
1943// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1944// dimensions that don't fit the images inside the range.
1945// GLES 3.0.4 section 3.8.13 Texture completeness
1946TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1947{
1948 if (IsOSX())
1949 {
1950 // Observed incorrect rendering on OSX.
1951 std::cout << "Test skipped on OSX." << std::endl;
1952 return;
1953 }
1954 glActiveTexture(GL_TEXTURE0);
1955 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1956 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1957 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1958 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1959
1960 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1961 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1962
1963 // Two levels that are initially unused.
1964 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1965 texDataRed.data());
1966 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1967 texDataCyan.data());
1968
1969 // One level that is used - only this level should affect completeness.
1970 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1971 texDataGreen.data());
1972
1973 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1974 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1975
1976 EXPECT_GL_NO_ERROR();
1977
1978 drawQuad(mProgram, "position", 0.5f);
1979
1980 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1981
1982 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1983 {
1984 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
1985 // level was changed.
1986 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
1987 return;
1988 }
1989
1990 // Switch the level that is being used to the cyan level 2.
1991 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
1992 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
1993
1994 EXPECT_GL_NO_ERROR();
1995
1996 drawQuad(mProgram, "position", 0.5f);
1997
1998 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1999}
2000
2001// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2002// have images defined.
2003TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
2004{
2005 if (IsOSX())
2006 {
2007 // Observed incorrect rendering on OSX.
2008 std::cout << "Test skipped on OSX." << std::endl;
2009 return;
2010 }
2011 glActiveTexture(GL_TEXTURE0);
2012 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
2013 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2014 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2015 texDataGreen.data());
2016 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2017 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2018 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2019 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2020
2021 EXPECT_GL_NO_ERROR();
2022
2023 drawQuad(mProgram, "position", 0.5f);
2024
2025 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2026}
2027
2028// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2029// dimensions that don't fit the images inside the range.
2030// GLES 3.0.4 section 3.8.13 Texture completeness
2031TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2032{
2033 if (IsOSX())
2034 {
2035 // Observed incorrect rendering on OSX.
2036 std::cout << "Test skipped on OSX." << std::endl;
2037 return;
2038 }
2039 glActiveTexture(GL_TEXTURE0);
2040 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
2041 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2042 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2043 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2044
2045 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2046 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2047
2048 // Two levels that are initially unused.
2049 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2050 texDataRed.data());
2051 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2052 texDataCyan.data());
2053
2054 // One level that is used - only this level should affect completeness.
2055 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2056 texDataGreen.data());
2057
2058 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2059 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2060
2061 EXPECT_GL_NO_ERROR();
2062
2063 drawQuad(mProgram, "position", 0.5f);
2064
2065 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2066
2067 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2068 {
2069 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
2070 // level was changed.
2071 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
2072 return;
2073 }
2074 if (IsNVIDIA() && (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
2075 getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE))
2076 {
2077 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
2078 // level was changed.
2079 std::cout << "Test partially skipped on NVIDIA OpenGL." << std::endl;
2080 return;
2081 }
2082
2083 // Switch the level that is being used to the cyan level 2.
2084 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2085 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2086
2087 EXPECT_GL_NO_ERROR();
2088
2089 drawQuad(mProgram, "position", 0.5f);
2090
2091 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2092}
2093
2094// Test that texture completeness is updated if texture max level changes.
2095// GLES 3.0.4 section 3.8.13 Texture completeness
2096TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2097{
2098 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2099 {
2100 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2101 // the base level.
2102 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2103 return;
2104 }
2105 if (IsOSX())
2106 {
2107 // Observed incorrect rendering on OSX.
2108 std::cout << "Test skipped on OSX." << std::endl;
2109 return;
2110 }
2111
2112 glActiveTexture(GL_TEXTURE0);
2113 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2114 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2115
2116 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2117 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2118
2119 // A level that is initially unused.
2120 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2121 texDataGreen.data());
2122
2123 // One level that is initially used - only this level should affect completeness.
2124 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2125 texDataGreen.data());
2126
2127 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2128 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2129
2130 EXPECT_GL_NO_ERROR();
2131
2132 drawQuad(mProgram, "position", 0.5f);
2133
2134 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2135
2136 // Switch the max level to level 1. The levels within the used range now have inconsistent
2137 // dimensions and the texture should be incomplete.
2138 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2139
2140 EXPECT_GL_NO_ERROR();
2141
2142 drawQuad(mProgram, "position", 0.5f);
2143
2144 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2145}
2146
2147// Test that 3D texture completeness is updated if texture max level changes.
2148// GLES 3.0.4 section 3.8.13 Texture completeness
2149TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2150{
2151 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2152 {
2153 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2154 // the base level.
2155 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2156 return;
2157 }
2158 if (IsOSX())
2159 {
2160 // Observed incorrect rendering on OSX.
2161 std::cout << "Test skipped on OSX." << std::endl;
2162 return;
2163 }
2164
2165 glActiveTexture(GL_TEXTURE0);
2166 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2167 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2168
2169 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2170 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2171
2172 // A level that is initially unused.
2173 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2174 texDataGreen.data());
2175
2176 // One level that is initially used - only this level should affect completeness.
2177 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2178 texDataGreen.data());
2179
2180 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2181 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2182
2183 EXPECT_GL_NO_ERROR();
2184
2185 drawQuad(mProgram, "position", 0.5f);
2186
2187 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2188
2189 // Switch the max level to level 1. The levels within the used range now have inconsistent
2190 // dimensions and the texture should be incomplete.
2191 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2192
2193 EXPECT_GL_NO_ERROR();
2194
2195 drawQuad(mProgram, "position", 0.5f);
2196
2197 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2198}
2199
2200// Test that texture completeness is updated if texture base level changes.
2201// GLES 3.0.4 section 3.8.13 Texture completeness
2202TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2203{
2204 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2205 {
2206 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2207 // the base level.
2208 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2209 return;
2210 }
2211
2212 glActiveTexture(GL_TEXTURE0);
2213 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2214 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2215
2216 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2217 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2218
2219 // Two levels that are initially unused.
2220 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2221 texDataGreen.data());
2222 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2223 texDataGreen.data());
2224
2225 // One level that is initially used - only this level should affect completeness.
2226 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2227 texDataGreen.data());
2228
2229 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2230 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2231
2232 EXPECT_GL_NO_ERROR();
2233
2234 drawQuad(mProgram, "position", 0.5f);
2235
2236 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2237
2238 // Switch the base level to level 1. The levels within the used range now have inconsistent
2239 // dimensions and the texture should be incomplete.
2240 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2241
2242 EXPECT_GL_NO_ERROR();
2243
2244 drawQuad(mProgram, "position", 0.5f);
2245
2246 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2247}
2248
2249// Test that texture is not complete if base level is greater than max level.
2250// GLES 3.0.4 section 3.8.13 Texture completeness
2251TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2252{
2253 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2254 {
2255 // Intel Windows OpenGL driver crashes if the base level of a non-immutable texture is out
2256 // of range.
2257 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2258 return;
2259 }
2260
2261 glActiveTexture(GL_TEXTURE0);
2262 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2263
2264 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2265 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2266
2267 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2268
2269 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2270 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2271
2272 EXPECT_GL_NO_ERROR();
2273
2274 drawQuad(mProgram, "position", 0.5f);
2275
2276 // Texture should be incomplete.
2277 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2278}
2279
2280// Test that immutable texture base level and max level are clamped.
2281// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2282TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2283{
Olli Etuahoa314b612016-03-10 16:43:00 +02002284 glActiveTexture(GL_TEXTURE0);
2285 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2286
2287 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2288 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2289
2290 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2291
2292 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2293
2294 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2295 // should be clamped to [base_level, levels - 1].
2296 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2297 // In the case of this test, those rules make the effective base level and max level 0.
2298 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2299 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2300
2301 EXPECT_GL_NO_ERROR();
2302
2303 drawQuad(mProgram, "position", 0.5f);
2304
2305 // Texture should be complete.
2306 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2307}
2308
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002309// Test that changing base level works when it affects the format of the texture.
2310TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2311{
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002312 if (IsNVIDIA() && IsOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002313 {
2314 // Observed rendering corruption on NVIDIA OpenGL.
2315 std::cout << "Test skipped on NVIDIA OpenGL." << std::endl;
2316 return;
2317 }
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002318 if (IsIntel() && IsDesktopOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002319 {
2320 // Observed incorrect rendering on Intel OpenGL.
2321 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2322 return;
2323 }
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002324 if (IsAMD() && IsDesktopOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002325 {
2326 // Observed incorrect rendering on AMD OpenGL.
2327 std::cout << "Test skipped on AMD OpenGL." << std::endl;
2328 return;
2329 }
2330
2331 glActiveTexture(GL_TEXTURE0);
2332 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2333 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2334 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2335
2336 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2337 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2338
2339 // RGBA8 level that's initially unused.
2340 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2341 texDataCyan.data());
2342
2343 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2344 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2345
2346 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2347 // format. It reads green channel data from the green and alpha channels of texDataGreen
2348 // (this is a bit hacky but works).
2349 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2350
2351 EXPECT_GL_NO_ERROR();
2352
2353 drawQuad(mProgram, "position", 0.5f);
2354
2355 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2356
2357 // Switch the texture to use the cyan level 0 with the RGBA format.
2358 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2359 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2360
2361 EXPECT_GL_NO_ERROR();
2362
2363 drawQuad(mProgram, "position", 0.5f);
2364
2365 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2366}
2367
Olli Etuahoa314b612016-03-10 16:43:00 +02002368// Test that setting a texture image works when base level is out of range.
2369TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2370{
2371 glActiveTexture(GL_TEXTURE0);
2372 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2373
2374 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2375 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2376
2377 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2378 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2379
2380 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2381
2382 EXPECT_GL_NO_ERROR();
2383
2384 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2385
2386 drawQuad(mProgram, "position", 0.5f);
2387
2388 // Texture should be complete.
2389 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002390}
2391
Jamie Madill2453dbc2015-07-14 11:35:42 -04002392// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG RBA->RGBA8, with 1.0
2393// in the alpha channel. This test covers a bug where redefining array textures with these formats does not work as
2394// expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002395TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002396{
2397 std::vector<GLubyte> pixelData;
2398 for (size_t count = 0; count < 5000; count++)
2399 {
2400 pixelData.push_back(0u);
2401 pixelData.push_back(255u);
2402 pixelData.push_back(0u);
2403 }
2404
2405 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002406 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002407 glUniform1i(mTextureArrayLocation, 0);
2408
2409 // The first draw worked correctly.
2410 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
2411
2412 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2413 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2414 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2415 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002416 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002417 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002418
2419 // The dimension of the respecification must match the original exactly to trigger the bug.
2420 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 +02002421 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002422 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002423
2424 ASSERT_GL_NO_ERROR();
2425}
2426
Olli Etuaho1a679902016-01-14 12:21:47 +02002427// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2428// This test is needed especially to confirm that sampler registers get assigned correctly on
2429// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2430TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2431{
2432 glActiveTexture(GL_TEXTURE0);
2433 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2434 GLubyte texData[4];
2435 texData[0] = 0;
2436 texData[1] = 60;
2437 texData[2] = 0;
2438 texData[3] = 255;
2439 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2440
2441 glActiveTexture(GL_TEXTURE1);
2442 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2443 GLfloat depthTexData[1];
2444 depthTexData[0] = 0.5f;
2445 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2446 depthTexData);
2447
2448 glUseProgram(mProgram);
2449 glUniform1f(mDepthRefUniformLocation, 0.3f);
2450 glUniform1i(mTexture3DUniformLocation, 0);
2451 glUniform1i(mTextureShadowUniformLocation, 1);
2452
2453 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2454 drawQuad(mProgram, "position", 0.5f);
2455 EXPECT_GL_NO_ERROR();
2456 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2457 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2458
2459 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2460 drawQuad(mProgram, "position", 0.5f);
2461 EXPECT_GL_NO_ERROR();
2462 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2463 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2464}
2465
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002466// Test multiple different sampler types in the same shader.
2467// This test makes sure that even if sampler / texture registers get grouped together based on type
2468// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2469// still has the right register index information for each ESSL sampler.
2470// The tested ESSL samplers have the following types in D3D11 HLSL:
2471// sampler2D: Texture2D + SamplerState
2472// samplerCube: TextureCube + SamplerState
2473// sampler2DShadow: Texture2D + SamplerComparisonState
2474// samplerCubeShadow: TextureCube + SamplerComparisonState
2475TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2476{
2477 glActiveTexture(GL_TEXTURE0);
2478 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2479 GLubyte texData[4];
2480 texData[0] = 0;
2481 texData[1] = 0;
2482 texData[2] = 120;
2483 texData[3] = 255;
2484 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2485
2486 glActiveTexture(GL_TEXTURE1);
2487 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2488 texData[0] = 0;
2489 texData[1] = 90;
2490 texData[2] = 0;
2491 texData[3] = 255;
2492 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2493 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2494 texData);
2495
2496 glActiveTexture(GL_TEXTURE2);
2497 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2498 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2499 GLfloat depthTexData[1];
2500 depthTexData[0] = 0.5f;
2501 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2502 depthTexData);
2503
2504 glActiveTexture(GL_TEXTURE3);
2505 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2506 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2507 depthTexData[0] = 0.2f;
2508 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2509 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2510 depthTexData);
2511
2512 EXPECT_GL_NO_ERROR();
2513
2514 glUseProgram(mProgram);
2515 glUniform1f(mDepthRefUniformLocation, 0.3f);
2516 glUniform1i(mTexture2DUniformLocation, 0);
2517 glUniform1i(mTextureCubeUniformLocation, 1);
2518 glUniform1i(mTexture2DShadowUniformLocation, 2);
2519 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2520
2521 drawQuad(mProgram, "position", 0.5f);
2522 EXPECT_GL_NO_ERROR();
2523 // The shader writes:
2524 // <texture 2d color> +
2525 // <cube map color> +
2526 // 0.25 * <comparison result (1.0)> +
2527 // 0.125 * <comparison result (0.0)>
2528 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2529}
2530
Olli Etuahobce743a2016-01-15 17:18:28 +02002531// Test different base levels on textures accessed through the same sampler array.
2532// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2533TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2534{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002535 if ((IsAMD() || IsIntel()) && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
Olli Etuahobce743a2016-01-15 17:18:28 +02002536 {
2537 std::cout << "Test skipped on Intel and AMD D3D." << std::endl;
2538 return;
2539 }
2540 glActiveTexture(GL_TEXTURE0);
2541 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2542 GLsizei size = 64;
2543 for (GLint level = 0; level < 7; ++level)
2544 {
2545 ASSERT_LT(0, size);
2546 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2547 nullptr);
2548 size = size / 2;
2549 }
2550 ASSERT_EQ(0, size);
2551 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2552
2553 glActiveTexture(GL_TEXTURE1);
2554 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2555 size = 128;
2556 for (GLint level = 0; level < 8; ++level)
2557 {
2558 ASSERT_LT(0, size);
2559 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2560 nullptr);
2561 size = size / 2;
2562 }
2563 ASSERT_EQ(0, size);
2564 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2565 EXPECT_GL_NO_ERROR();
2566
2567 glUseProgram(mProgram);
2568 glUniform1i(mTexture0Location, 0);
2569 glUniform1i(mTexture1Location, 1);
2570
2571 drawQuad(mProgram, "position", 0.5f);
2572 EXPECT_GL_NO_ERROR();
2573 // Red channel: width of level 1 of texture A: 32.
2574 // Green channel: width of level 3 of texture B: 16.
2575 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2576}
2577
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002578// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2579// ES 3.0.4 table 3.24
2580TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2581{
2582 glActiveTexture(GL_TEXTURE0);
2583 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2584 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2585 EXPECT_GL_NO_ERROR();
2586
2587 drawQuad(mProgram, "position", 0.5f);
2588
2589 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2590}
2591
2592// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2593// ES 3.0.4 table 3.24
2594TEST_P(Texture2DTestES3, TextureLuminanceImplicitAlpha1)
2595{
2596 glActiveTexture(GL_TEXTURE0);
2597 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2598 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2599 EXPECT_GL_NO_ERROR();
2600
2601 drawQuad(mProgram, "position", 0.5f);
2602
2603 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2604}
2605
2606// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2607// ES 3.0.4 table 3.24
2608TEST_P(Texture2DTestES3, TextureLuminance32ImplicitAlpha1)
2609{
2610 if (extensionEnabled("GL_OES_texture_float"))
2611 {
2612 glActiveTexture(GL_TEXTURE0);
2613 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2614 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2615 EXPECT_GL_NO_ERROR();
2616
2617 drawQuad(mProgram, "position", 0.5f);
2618
2619 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2620 }
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, TextureLuminance16ImplicitAlpha1)
2626{
2627 if (extensionEnabled("GL_OES_texture_half_float"))
2628 {
Yuly Novikovafcec832016-06-21 22:19:51 -04002629 if (IsNVIDIA() && IsOpenGLES())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002630 {
2631 std::cout << "Test skipped on NVIDIA" << std::endl;
2632 return;
2633 }
Yuly Novikovafcec832016-06-21 22:19:51 -04002634 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2635 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2636 {
2637 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2638 return;
2639 }
2640
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002641 glActiveTexture(GL_TEXTURE0);
2642 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2643 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES,
2644 nullptr);
2645 EXPECT_GL_NO_ERROR();
2646
2647 drawQuad(mProgram, "position", 0.5f);
2648
2649 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2650 }
2651}
2652
2653// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2654// ES 3.0.4 table 3.24
2655TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2656{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002657 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002658 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002659 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002660 return;
2661 }
2662 glActiveTexture(GL_TEXTURE0);
2663 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2664 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2665 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2666 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2667 EXPECT_GL_NO_ERROR();
2668
2669 drawQuad(mProgram, "position", 0.5f);
2670
2671 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2672}
2673
2674// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2675// ES 3.0.4 table 3.24
2676TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2677{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002678 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002679 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002680 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002681 return;
2682 }
2683 glActiveTexture(GL_TEXTURE0);
2684 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2685
2686 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2687 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2688 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2689 EXPECT_GL_NO_ERROR();
2690
2691 drawQuad(mProgram, "position", 0.5f);
2692
2693 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2694}
2695
2696// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2697// ES 3.0.4 table 3.24
2698TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2699{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002700 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002701 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002702 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002703 return;
2704 }
2705 glActiveTexture(GL_TEXTURE0);
2706 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2707 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2708 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2709 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2710 EXPECT_GL_NO_ERROR();
2711
2712 drawQuad(mProgram, "position", 0.5f);
2713
2714 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2715}
2716
2717// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2718// ES 3.0.4 table 3.24
2719TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2720{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002721 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002722 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002723 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002724 return;
2725 }
2726 glActiveTexture(GL_TEXTURE0);
2727 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2728 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2729 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2730 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2731 EXPECT_GL_NO_ERROR();
2732
2733 drawQuad(mProgram, "position", 0.5f);
2734
2735 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2736}
2737
2738// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2739// ES 3.0.4 table 3.24
2740TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2741{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002742 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002743 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002744 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002745 return;
2746 }
2747 glActiveTexture(GL_TEXTURE0);
2748 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2749 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2750 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2751 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2752 EXPECT_GL_NO_ERROR();
2753
2754 drawQuad(mProgram, "position", 0.5f);
2755
2756 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2757}
2758
2759// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2760// ES 3.0.4 table 3.24
2761TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2762{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002763 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002764 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002765 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002766 return;
2767 }
2768 glActiveTexture(GL_TEXTURE0);
2769 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2770 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2771 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2772 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2773 EXPECT_GL_NO_ERROR();
2774
2775 drawQuad(mProgram, "position", 0.5f);
2776
2777 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2778}
2779
2780// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2781// ES 3.0.4 table 3.24
2782TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2783{
2784 glActiveTexture(GL_TEXTURE0);
2785 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2786 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2787 EXPECT_GL_NO_ERROR();
2788
2789 drawQuad(mProgram, "position", 0.5f);
2790
2791 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2792}
2793
2794// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2795// ES 3.0.4 table 3.24
2796TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2797{
2798 glActiveTexture(GL_TEXTURE0);
2799 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2800 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2801 nullptr);
2802 EXPECT_GL_NO_ERROR();
2803
2804 drawQuad(mProgram, "position", 0.5f);
2805
2806 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2807}
2808
2809// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2810// ES 3.0.4 table 3.24
2811TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2812{
Jamie Madillbb1db482017-01-10 10:48:32 -05002813 if (IsOSX() && IsIntel() && IsOpenGL())
2814 {
2815 // Seems to fail on OSX 10.12 Intel.
2816 std::cout << "Test skipped on OSX Intel." << std::endl;
2817 return;
2818 }
2819
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002820 glActiveTexture(GL_TEXTURE0);
2821 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2822 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2823 EXPECT_GL_NO_ERROR();
2824
2825 drawQuad(mProgram, "position", 0.5f);
2826
2827 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2828}
2829
2830// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2831// ES 3.0.4 table 3.24
2832TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2833{
Jamie Madillbb1db482017-01-10 10:48:32 -05002834 if (IsIntel() && IsOpenGL() && (IsLinux() || IsOSX()))
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002835 {
2836 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
Jamie Madillbb1db482017-01-10 10:48:32 -05002837 // Also seems to fail on OSX 10.12 Intel.
2838 std::cout << "Test disabled on Linux and OSX Intel OpenGL." << std::endl;
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002839 return;
2840 }
2841
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002842 glActiveTexture(GL_TEXTURE0);
2843 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2844 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2845 EXPECT_GL_NO_ERROR();
2846
2847 drawQuad(mProgram, "position", 0.5f);
2848
2849 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2850}
2851
Olli Etuaho96963162016-03-21 11:54:33 +02002852// Use a sampler in a uniform struct.
2853TEST_P(SamplerInStructTest, SamplerInStruct)
2854{
2855 runSamplerInStructTest();
2856}
2857
2858// Use a sampler in a uniform struct that's passed as a function parameter.
2859TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2860{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002861 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2862 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2863 {
2864 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2865 return;
2866 }
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002867
2868 if (IsWindows() && IsIntel() && IsOpenGL())
2869 {
2870 std::cout << "Test skipped on Windows OpenGL on Intel." << std::endl;
2871 return;
2872 }
2873
Olli Etuaho96963162016-03-21 11:54:33 +02002874 runSamplerInStructTest();
2875}
2876
2877// Use a sampler in a uniform struct array with a struct from the array passed as a function
2878// parameter.
2879TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2880{
Olli Etuahoa1c917f2016-04-06 13:50:03 +03002881 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2882 {
2883 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2884 return;
2885 }
Yuly Novikovad6c0452016-06-24 22:24:37 -04002886 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2887 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2888 {
2889 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2890 return;
2891 }
Olli Etuaho96963162016-03-21 11:54:33 +02002892 runSamplerInStructTest();
2893}
2894
2895// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2896// parameter.
2897TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2898{
Olli Etuahoa1c917f2016-04-06 13:50:03 +03002899 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2900 {
2901 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2902 return;
2903 }
Yuly Novikovad6c0452016-06-24 22:24:37 -04002904 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2905 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2906 {
2907 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2908 return;
2909 }
Olli Etuaho96963162016-03-21 11:54:33 +02002910 runSamplerInStructTest();
2911}
2912
2913// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2914// similarly named uniform.
2915TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2916{
2917 runSamplerInStructTest();
2918}
2919
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002920class TextureLimitsTest : public ANGLETest
2921{
2922 protected:
2923 struct RGBA8
2924 {
2925 uint8_t R, G, B, A;
2926 };
2927
2928 TextureLimitsTest()
2929 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
2930 {
2931 setWindowWidth(128);
2932 setWindowHeight(128);
2933 setConfigRedBits(8);
2934 setConfigGreenBits(8);
2935 setConfigBlueBits(8);
2936 setConfigAlphaBits(8);
2937 }
2938
2939 ~TextureLimitsTest()
2940 {
2941 if (mProgram != 0)
2942 {
2943 glDeleteProgram(mProgram);
2944 mProgram = 0;
2945
2946 if (!mTextures.empty())
2947 {
2948 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
2949 }
2950 }
2951 }
2952
2953 void SetUp() override
2954 {
2955 ANGLETest::SetUp();
2956
2957 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
2958 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
2959 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
2960
2961 ASSERT_GL_NO_ERROR();
2962 }
2963
2964 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
2965 GLint vertexTextureCount,
2966 GLint vertexActiveTextureCount,
2967 const std::string &fragPrefix,
2968 GLint fragmentTextureCount,
2969 GLint fragmentActiveTextureCount)
2970 {
2971 std::stringstream vertexShaderStr;
2972 vertexShaderStr << "attribute vec2 position;\n"
2973 << "varying vec4 color;\n"
2974 << "varying vec2 texCoord;\n";
2975
2976 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
2977 {
2978 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
2979 }
2980
2981 vertexShaderStr << "void main() {\n"
2982 << " gl_Position = vec4(position, 0, 1);\n"
2983 << " texCoord = (position * 0.5) + 0.5;\n"
2984 << " color = vec4(0);\n";
2985
2986 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
2987 {
2988 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
2989 << ", texCoord);\n";
2990 }
2991
2992 vertexShaderStr << "}";
2993
2994 std::stringstream fragmentShaderStr;
2995 fragmentShaderStr << "varying mediump vec4 color;\n"
2996 << "varying mediump vec2 texCoord;\n";
2997
2998 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
2999 {
3000 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
3001 }
3002
3003 fragmentShaderStr << "void main() {\n"
3004 << " gl_FragColor = color;\n";
3005
3006 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
3007 {
3008 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
3009 << ", texCoord);\n";
3010 }
3011
3012 fragmentShaderStr << "}";
3013
3014 const std::string &vertexShaderSource = vertexShaderStr.str();
3015 const std::string &fragmentShaderSource = fragmentShaderStr.str();
3016
3017 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
3018 }
3019
3020 RGBA8 getPixel(GLint texIndex)
3021 {
3022 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3023 0, 255u};
3024 return pixel;
3025 }
3026
3027 void initTextures(GLint tex2DCount, GLint texCubeCount)
3028 {
3029 GLint totalCount = tex2DCount + texCubeCount;
3030 mTextures.assign(totalCount, 0);
3031 glGenTextures(totalCount, &mTextures[0]);
3032 ASSERT_GL_NO_ERROR();
3033
3034 std::vector<RGBA8> texData(16 * 16);
3035
3036 GLint texIndex = 0;
3037 for (; texIndex < tex2DCount; ++texIndex)
3038 {
3039 texData.assign(texData.size(), getPixel(texIndex));
3040 glActiveTexture(GL_TEXTURE0 + texIndex);
3041 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3042 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3043 &texData[0]);
3044 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3045 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3046 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3047 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3048 }
3049
3050 ASSERT_GL_NO_ERROR();
3051
3052 for (; texIndex < texCubeCount; ++texIndex)
3053 {
3054 texData.assign(texData.size(), getPixel(texIndex));
3055 glActiveTexture(GL_TEXTURE0 + texIndex);
3056 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3057 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3058 GL_UNSIGNED_BYTE, &texData[0]);
3059 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3060 GL_UNSIGNED_BYTE, &texData[0]);
3061 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3062 GL_UNSIGNED_BYTE, &texData[0]);
3063 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3064 GL_UNSIGNED_BYTE, &texData[0]);
3065 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3066 GL_UNSIGNED_BYTE, &texData[0]);
3067 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3068 GL_UNSIGNED_BYTE, &texData[0]);
3069 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3070 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3071 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3072 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3073 }
3074
3075 ASSERT_GL_NO_ERROR();
3076 }
3077
3078 void testWithTextures(GLint vertexTextureCount,
3079 const std::string &vertexTexturePrefix,
3080 GLint fragmentTextureCount,
3081 const std::string &fragmentTexturePrefix)
3082 {
3083 // Generate textures
3084 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3085
3086 glUseProgram(mProgram);
3087 RGBA8 expectedSum = {0};
3088 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3089 {
3090 std::stringstream uniformNameStr;
3091 uniformNameStr << vertexTexturePrefix << texIndex;
3092 const std::string &uniformName = uniformNameStr.str();
3093 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
3094 ASSERT_NE(-1, location);
3095
3096 glUniform1i(location, texIndex);
3097 RGBA8 contribution = getPixel(texIndex);
3098 expectedSum.R += contribution.R;
3099 expectedSum.G += contribution.G;
3100 }
3101
3102 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3103 {
3104 std::stringstream uniformNameStr;
3105 uniformNameStr << fragmentTexturePrefix << texIndex;
3106 const std::string &uniformName = uniformNameStr.str();
3107 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
3108 ASSERT_NE(-1, location);
3109
3110 glUniform1i(location, texIndex + vertexTextureCount);
3111 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3112 expectedSum.R += contribution.R;
3113 expectedSum.G += contribution.G;
3114 }
3115
3116 ASSERT_GE(256u, expectedSum.G);
3117
3118 drawQuad(mProgram, "position", 0.5f);
3119 ASSERT_GL_NO_ERROR();
3120 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3121 }
3122
3123 GLuint mProgram;
3124 std::vector<GLuint> mTextures;
3125 GLint mMaxVertexTextures;
3126 GLint mMaxFragmentTextures;
3127 GLint mMaxCombinedTextures;
3128};
3129
3130// Test rendering with the maximum vertex texture units.
3131TEST_P(TextureLimitsTest, MaxVertexTextures)
3132{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003133 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003134 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003135 {
3136 std::cout << "Test skipped on Intel." << std::endl;
3137 return;
3138 }
3139
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003140 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3141 ASSERT_NE(0u, mProgram);
3142 ASSERT_GL_NO_ERROR();
3143
3144 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3145}
3146
3147// Test rendering with the maximum fragment texture units.
3148TEST_P(TextureLimitsTest, MaxFragmentTextures)
3149{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003150 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003151 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003152 {
3153 std::cout << "Test skipped on Intel." << std::endl;
3154 return;
3155 }
3156
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003157 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3158 ASSERT_NE(0u, mProgram);
3159 ASSERT_GL_NO_ERROR();
3160
3161 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3162}
3163
3164// Test rendering with maximum combined texture units.
3165TEST_P(TextureLimitsTest, MaxCombinedTextures)
3166{
Jamie Madill412f17d2015-09-25 08:43:54 -04003167 // TODO(jmadill): Investigate workaround.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003168 if (IsIntel() && GetParam() == ES2_OPENGL())
Jamie Madill412f17d2015-09-25 08:43:54 -04003169 {
3170 std::cout << "Test skipped on Intel." << std::endl;
3171 return;
3172 }
3173
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003174 GLint vertexTextures = mMaxVertexTextures;
3175
3176 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3177 {
3178 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3179 }
3180
3181 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3182 mMaxFragmentTextures, mMaxFragmentTextures);
3183 ASSERT_NE(0u, mProgram);
3184 ASSERT_GL_NO_ERROR();
3185
3186 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3187}
3188
3189// Negative test for exceeding the number of vertex textures
3190TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3191{
3192 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3193 0);
3194 ASSERT_EQ(0u, mProgram);
3195}
3196
3197// Negative test for exceeding the number of fragment textures
3198TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3199{
3200 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3201 mMaxFragmentTextures + 1);
3202 ASSERT_EQ(0u, mProgram);
3203}
3204
3205// Test active vertex textures under the limit, but excessive textures specified.
3206TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3207{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003208 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003209 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003210 {
3211 std::cout << "Test skipped on Intel." << std::endl;
3212 return;
3213 }
3214
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003215 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3216 ASSERT_NE(0u, mProgram);
3217 ASSERT_GL_NO_ERROR();
3218
3219 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3220}
3221
3222// Test active fragment textures under the limit, but excessive textures specified.
3223TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3224{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003225 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003226 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003227 {
3228 std::cout << "Test skipped on Intel." << std::endl;
3229 return;
3230 }
3231
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003232 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3233 mMaxFragmentTextures);
3234 ASSERT_NE(0u, mProgram);
3235 ASSERT_GL_NO_ERROR();
3236
3237 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3238}
3239
3240// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003241// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003242TEST_P(TextureLimitsTest, TextureTypeConflict)
3243{
3244 const std::string &vertexShader =
3245 "attribute vec2 position;\n"
3246 "varying float color;\n"
3247 "uniform sampler2D tex2D;\n"
3248 "uniform samplerCube texCube;\n"
3249 "void main() {\n"
3250 " gl_Position = vec4(position, 0, 1);\n"
3251 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3252 " color = texture2D(tex2D, texCoord).x;\n"
3253 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3254 "}";
3255 const std::string &fragmentShader =
3256 "varying mediump float color;\n"
3257 "void main() {\n"
3258 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3259 "}";
3260
3261 mProgram = CompileProgram(vertexShader, fragmentShader);
3262 ASSERT_NE(0u, mProgram);
3263
3264 initTextures(1, 0);
3265
3266 glUseProgram(mProgram);
3267 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3268 ASSERT_NE(-1, tex2DLocation);
3269 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3270 ASSERT_NE(-1, texCubeLocation);
3271
3272 glUniform1i(tex2DLocation, 0);
3273 glUniform1i(texCubeLocation, 0);
3274 ASSERT_GL_NO_ERROR();
3275
3276 drawQuad(mProgram, "position", 0.5f);
3277 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3278}
3279
Vincent Lang25ab4512016-05-13 18:13:59 +02003280class Texture2DNorm16TestES3 : public Texture2DTestES3
3281{
3282 protected:
3283 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3284
3285 void SetUp() override
3286 {
3287 Texture2DTestES3::SetUp();
3288
3289 glActiveTexture(GL_TEXTURE0);
3290 glGenTextures(3, mTextures);
3291 glGenFramebuffers(1, &mFBO);
3292 glGenRenderbuffers(1, &mRenderbuffer);
3293
3294 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3295 {
3296 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3297 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3298 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3299 }
3300
3301 glBindTexture(GL_TEXTURE_2D, 0);
3302
3303 ASSERT_GL_NO_ERROR();
3304 }
3305
3306 void TearDown() override
3307 {
3308 glDeleteTextures(3, mTextures);
3309 glDeleteFramebuffers(1, &mFBO);
3310 glDeleteRenderbuffers(1, &mRenderbuffer);
3311
3312 Texture2DTestES3::TearDown();
3313 }
3314
3315 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3316 {
Geoff Langf607c602016-09-21 11:46:48 -04003317 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3318 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003319
3320 setUpProgram();
3321
3322 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3323 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3324 0);
3325
3326 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3327 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3328
3329 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003330 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003331
3332 EXPECT_GL_NO_ERROR();
3333
3334 drawQuad(mProgram, "position", 0.5f);
3335
Geoff Langf607c602016-09-21 11:46:48 -04003336 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003337
Geoff Langf607c602016-09-21 11:46:48 -04003338 EXPECT_PIXEL_COLOR_EQ(
3339 0, 0, SliceFormatColor(
3340 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003341
3342 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3343
3344 ASSERT_GL_NO_ERROR();
3345 }
3346
3347 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3348 {
3349 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003350 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003351
3352 setUpProgram();
3353
3354 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3355 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3356
3357 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3358 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3359 0);
3360
3361 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003362 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003363
3364 EXPECT_GL_NO_ERROR();
3365
3366 drawQuad(mProgram, "position", 0.5f);
3367
Geoff Langf607c602016-09-21 11:46:48 -04003368 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
3369 EXPECT_PIXEL_COLOR_EQ(
3370 0, 0, SliceFormatColor(
3371 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003372
3373 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3374 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3375 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3376 mRenderbuffer);
3377 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3378 EXPECT_GL_NO_ERROR();
3379
3380 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3381 glClear(GL_COLOR_BUFFER_BIT);
3382
3383 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3384
Geoff Langf607c602016-09-21 11:46:48 -04003385 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003386
3387 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3388
3389 ASSERT_GL_NO_ERROR();
3390 }
3391
3392 GLuint mTextures[3];
3393 GLuint mFBO;
3394 GLuint mRenderbuffer;
3395};
3396
3397// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3398TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3399{
3400 if (!extensionEnabled("GL_EXT_texture_norm16"))
3401 {
3402 std::cout << "Test skipped due to missing GL_EXT_texture_norm16." << std::endl;
3403 return;
3404 }
3405
3406 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3407 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3408 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3409 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3410 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3411 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3412 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3413 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3414
3415 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3416 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3417 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3418}
3419
Olli Etuaho95faa232016-06-07 14:01:53 -07003420// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3421// GLES 3.0.4 section 3.8.3.
3422TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3423{
Corentin Wallezc7f59d02016-06-20 10:12:08 -04003424 if (IsIntel() && IsDesktopOpenGL())
Olli Etuaho95faa232016-06-07 14:01:53 -07003425 {
3426 std::cout << "Test skipped on Intel OpenGL." << std::endl;
3427 return;
3428 }
Yuly Novikov3c754192016-06-27 19:36:41 -04003429 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1429 is fixed
3430 if (IsAndroid() && IsAdreno() && IsOpenGLES())
3431 {
3432 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
3433 return;
3434 }
Olli Etuaho95faa232016-06-07 14:01:53 -07003435
3436 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3437 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3438 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3439 ASSERT_GL_NO_ERROR();
3440
3441 // SKIP_IMAGES should not have an effect on uploading 2D textures
3442 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3443 ASSERT_GL_NO_ERROR();
3444
3445 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3446
3447 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3448 pixelsGreen.data());
3449 ASSERT_GL_NO_ERROR();
3450
3451 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3452 pixelsGreen.data());
3453 ASSERT_GL_NO_ERROR();
3454
3455 glUseProgram(mProgram);
3456 drawQuad(mProgram, "position", 0.5f);
3457 ASSERT_GL_NO_ERROR();
3458
3459 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3460}
3461
Olli Etuaho989cac32016-06-08 16:18:49 -07003462// Test that skip defined in unpack parameters is taken into account when determining whether
3463// unpacking source extends outside unpack buffer bounds.
3464TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3465{
3466 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3467 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3468 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3469 ASSERT_GL_NO_ERROR();
3470
3471 GLBuffer buf;
3472 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3473 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3474 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3475 GL_DYNAMIC_COPY);
3476 ASSERT_GL_NO_ERROR();
3477
3478 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3479 ASSERT_GL_NO_ERROR();
3480
3481 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3482 ASSERT_GL_NO_ERROR();
3483
3484 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3485 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3486
3487 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3488 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3489 ASSERT_GL_NO_ERROR();
3490
3491 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3492 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3493}
3494
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003495// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3496TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3497{
3498 if (IsD3D11())
3499 {
3500 std::cout << "Test skipped on D3D." << std::endl;
3501 return;
3502 }
3503 if (IsOSX() && IsAMD())
3504 {
3505 // Incorrect rendering results seen on OSX AMD.
3506 std::cout << "Test skipped on OSX AMD." << std::endl;
3507 return;
3508 }
3509
3510 const GLuint width = 8u;
3511 const GLuint height = 8u;
3512 const GLuint unpackRowLength = 5u;
3513 const GLuint unpackSkipPixels = 1u;
3514
3515 setWindowWidth(width);
3516 setWindowHeight(height);
3517
3518 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3519 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3520 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3521 ASSERT_GL_NO_ERROR();
3522
3523 GLBuffer buf;
3524 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3525 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3526 GLColor::green);
3527
3528 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3529 {
3530 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3531 }
3532
3533 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3534 GL_DYNAMIC_COPY);
3535 ASSERT_GL_NO_ERROR();
3536
3537 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3538 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3539 ASSERT_GL_NO_ERROR();
3540
3541 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3542 ASSERT_GL_NO_ERROR();
3543
3544 glUseProgram(mProgram);
3545 drawQuad(mProgram, "position", 0.5f);
3546 ASSERT_GL_NO_ERROR();
3547
3548 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3549 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3550 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3551 actual.data());
3552 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3553 EXPECT_EQ(expected, actual);
3554}
3555
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003556template <typename T>
3557T UNorm(double value)
3558{
3559 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3560}
3561
3562// Test rendering a depth texture with mipmaps.
3563TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3564{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003565 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3566 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
3567 // http://anglebugs.com/1706
3568 if (IsIntel() && IsWindows())
Corentin Walleze731d8a2016-09-07 10:56:25 -04003569 {
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003570 std::cout << "Test skipped on Win Intel." << std::endl;
Corentin Walleze731d8a2016-09-07 10:56:25 -04003571 return;
3572 }
3573
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003574 const int size = getWindowWidth();
3575
3576 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003577 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003578
3579 glActiveTexture(GL_TEXTURE0);
3580 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3581 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3582 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3583 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3584 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3585 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3586 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3587 ASSERT_GL_NO_ERROR();
3588
3589 glUseProgram(mProgram);
3590 glUniform1i(mTexture2DUniformLocation, 0);
3591
3592 std::vector<unsigned char> expected;
3593
3594 for (int level = 0; level < levels; ++level)
3595 {
3596 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3597 expected.push_back(UNorm<unsigned char>(value));
3598
3599 int levelDim = dim(level);
3600
3601 ASSERT_GT(levelDim, 0);
3602
3603 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3604 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3605 GL_UNSIGNED_INT, initData.data());
3606 }
3607 ASSERT_GL_NO_ERROR();
3608
3609 for (int level = 0; level < levels; ++level)
3610 {
3611 glViewport(0, 0, dim(level), dim(level));
3612 drawQuad(mProgram, "position", 0.5f);
3613 GLColor actual = ReadColor(0, 0);
3614 EXPECT_NEAR(expected[level], actual.R, 10u);
3615 }
3616
3617 ASSERT_GL_NO_ERROR();
3618}
3619
Jamie Madill7ffdda92016-09-08 13:26:51 -04003620// Tests unpacking into the unsized GL_ALPHA format.
3621TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3622{
3623 // TODO(jmadill): Figure out why this fails on OSX.
3624 ANGLE_SKIP_TEST_IF(IsOSX());
3625
3626 // Initialize the texure.
3627 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3628 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3629 GL_UNSIGNED_BYTE, nullptr);
3630 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3631 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3632
3633 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3634
3635 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04003636 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04003637 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3638 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3639 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
3640 GL_STATIC_DRAW);
3641
3642 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
3643 GL_UNSIGNED_BYTE, nullptr);
3644
3645 // Clear to a weird color to make sure we're drawing something.
3646 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
3647 glClear(GL_COLOR_BUFFER_BIT);
3648
3649 // Draw with the alpha texture and verify.
3650 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04003651
3652 ASSERT_GL_NO_ERROR();
3653 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
3654}
3655
Jamie Madill2e600342016-09-19 13:56:40 -04003656// Ensure stale unpack data doesn't propagate in D3D11.
3657TEST_P(Texture2DTestES3, StaleUnpackData)
3658{
3659 // Init unpack buffer.
3660 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
3661 std::vector<GLColor> pixels(pixelCount, GLColor::red);
3662
3663 GLBuffer unpackBuffer;
3664 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3665 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3666 GLsizei bufferSize = pixelCount * sizeof(GLColor);
3667 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
3668
3669 // Create from unpack buffer.
3670 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3671 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
3672 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3673 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3674 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3675
3676 drawQuad(mProgram, "position", 0.5f);
3677
3678 ASSERT_GL_NO_ERROR();
3679 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3680
3681 // Fill unpack with green, recreating buffer.
3682 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
3683 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
3684 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
3685
3686 // Reinit texture with green.
3687 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
3688 GL_UNSIGNED_BYTE, nullptr);
3689
3690 drawQuad(mProgram, "position", 0.5f);
3691
3692 ASSERT_GL_NO_ERROR();
3693 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3694}
3695
Jamie Madillf097e232016-11-05 00:44:15 -04003696// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
3697// being properly checked, and the texture storage of the previous texture format was persisting.
3698// This would result in an ASSERT in debug and incorrect rendering in release.
3699// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
3700TEST_P(Texture3DTestES3, FormatRedefinitionBug)
3701{
3702 GLTexture tex;
3703 glBindTexture(GL_TEXTURE_3D, tex.get());
3704 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3705
3706 GLFramebuffer framebuffer;
3707 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3708 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
3709
3710 glCheckFramebufferStatus(GL_FRAMEBUFFER);
3711
3712 std::vector<uint8_t> pixelData(100, 0);
3713
3714 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
3715 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
3716 pixelData.data());
3717
3718 ASSERT_GL_NO_ERROR();
3719}
3720
Corentin Wallezd2627992017-04-28 17:17:03 -04003721// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
3722TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
3723{
3724 // 2D tests
3725 {
3726 GLTexture tex;
3727 glBindTexture(GL_TEXTURE_2D, tex.get());
3728
3729 GLBuffer pbo;
3730 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3731
3732 // Test OOB
3733 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
3734 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3735 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3736
3737 // Test OOB
3738 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
3739 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3740 ASSERT_GL_NO_ERROR();
3741 }
3742
3743 // 3D tests
3744 {
3745 GLTexture tex;
3746 glBindTexture(GL_TEXTURE_3D, tex.get());
3747
3748 GLBuffer pbo;
3749 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3750
3751 // Test OOB
3752 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
3753 GL_STATIC_DRAW);
3754 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3755 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3756
3757 // Test OOB
3758 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
3759 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3760 ASSERT_GL_NO_ERROR();
3761 }
3762}
3763
Jamie Madill3ed60422017-09-07 11:32:52 -04003764// Tests behaviour with a single texture and multiple sampler objects.
3765TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
3766{
3767 GLint maxTextureUnits = 0;
3768 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
3769 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
3770
3771 constexpr int kSize = 16;
3772
3773 // Make a single-level texture, fill it with red.
3774 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
3775 GLTexture tex;
3776 glBindTexture(GL_TEXTURE_2D, tex);
3777 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3778 redColors.data());
3779 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3780 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3781
3782 // Simple sanity check.
3783 draw2DTexturedQuad(0.5f, 1.0f, true);
3784 ASSERT_GL_NO_ERROR();
3785 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3786
3787 // Bind texture to unit 1 with a sampler object making it incomplete.
3788 GLSampler sampler;
3789 glBindSampler(0, sampler);
3790 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3791 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3792
3793 // Make a mipmap texture, fill it with blue.
3794 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
3795 GLTexture mipmapTex;
3796 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3797 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3798 blueColors.data());
3799 glGenerateMipmap(GL_TEXTURE_2D);
3800
3801 // Draw with the sampler, expect blue.
3802 draw2DTexturedQuad(0.5f, 1.0f, true);
3803 ASSERT_GL_NO_ERROR();
3804 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
3805
3806 // Simple multitexturing program.
3807 const std::string vs =
3808 "#version 300 es\n"
3809 "in vec2 position;\n"
3810 "out vec2 texCoord;\n"
3811 "void main()\n"
3812 "{\n"
3813 " gl_Position = vec4(position, 0, 1);\n"
3814 " texCoord = position * 0.5 + vec2(0.5);\n"
3815 "}";
3816 const std::string fs =
3817 "#version 300 es\n"
3818 "precision mediump float;\n"
3819 "in vec2 texCoord;\n"
3820 "uniform sampler2D tex1;\n"
3821 "uniform sampler2D tex2;\n"
3822 "uniform sampler2D tex3;\n"
3823 "uniform sampler2D tex4;\n"
3824 "out vec4 color;\n"
3825 "void main()\n"
3826 "{\n"
3827 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
3828 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
3829 "}";
3830
3831 ANGLE_GL_PROGRAM(program, vs, fs);
3832
3833 std::array<GLint, 4> texLocations = {
3834 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
3835 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
3836 for (GLint location : texLocations)
3837 {
3838 ASSERT_NE(-1, location);
3839 }
3840
3841 // Init the uniform data.
3842 glUseProgram(program);
3843 for (GLint location = 0; location < 4; ++location)
3844 {
3845 glUniform1i(texLocations[location], location);
3846 }
3847
3848 // Initialize four samplers
3849 GLSampler samplers[4];
3850
3851 // 0: non-mipped.
3852 glBindSampler(0, samplers[0]);
3853 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3854 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3855
3856 // 1: mipped.
3857 glBindSampler(1, samplers[1]);
3858 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3859 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3860
3861 // 2: non-mipped.
3862 glBindSampler(2, samplers[2]);
3863 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3864 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3865
3866 // 3: mipped.
3867 glBindSampler(3, samplers[3]);
3868 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3869 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3870
3871 // Bind two blue mipped textures and two single layer textures, should all draw.
3872 glActiveTexture(GL_TEXTURE0);
3873 glBindTexture(GL_TEXTURE_2D, tex);
3874
3875 glActiveTexture(GL_TEXTURE1);
3876 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3877
3878 glActiveTexture(GL_TEXTURE2);
3879 glBindTexture(GL_TEXTURE_2D, tex);
3880
3881 glActiveTexture(GL_TEXTURE3);
3882 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3883
3884 ASSERT_GL_NO_ERROR();
3885
3886 drawQuad(program, "position", 0.5f);
3887 ASSERT_GL_NO_ERROR();
3888 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
3889
3890 // Bind four single layer textures, two should be incomplete.
3891 glActiveTexture(GL_TEXTURE1);
3892 glBindTexture(GL_TEXTURE_2D, tex);
3893
3894 glActiveTexture(GL_TEXTURE3);
3895 glBindTexture(GL_TEXTURE_2D, tex);
3896
3897 drawQuad(program, "position", 0.5f);
3898 ASSERT_GL_NO_ERROR();
3899 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
3900}
3901
Martin Radev7e2c0d32017-09-15 14:25:42 +03003902// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
3903// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
3904// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
3905// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
3906// samples the cubemap using a direction vector (1,1,1).
3907TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
3908{
3909 if (IsOSX())
3910 {
3911 // Check http://anglebug.com/2155.
3912 std::cout << "Test skipped on OSX." << std::endl;
3913 return;
3914 }
3915 const std::string vs =
3916 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003917 precision mediump float;
3918 in vec3 pos;
3919 void main() {
3920 gl_Position = vec4(pos, 1.0);
3921 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003922
3923 const std::string fs =
3924 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003925 precision mediump float;
3926 out vec4 color;
3927 uniform samplerCube uTex;
3928 void main(){
3929 color = texture(uTex, vec3(1.0));
3930 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003931 ANGLE_GL_PROGRAM(program, vs, fs);
3932 glUseProgram(program);
3933
3934 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
3935 glActiveTexture(GL_TEXTURE0);
3936
3937 GLTexture cubeTex;
3938 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
3939
3940 const int kFaceWidth = 1;
3941 const int kFaceHeight = 1;
3942 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
3943 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3944 GL_UNSIGNED_BYTE, texData.data());
3945 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3946 GL_UNSIGNED_BYTE, texData.data());
3947 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3948 GL_UNSIGNED_BYTE, texData.data());
3949 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3950 GL_UNSIGNED_BYTE, texData.data());
3951 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3952 GL_UNSIGNED_BYTE, texData.data());
3953 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3954 GL_UNSIGNED_BYTE, texData.data());
3955 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3956 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3957 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
3958 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
3959 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
3960 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
3961
3962 drawQuad(program, "pos", 0.5f, 1.0f, true);
3963 ASSERT_GL_NO_ERROR();
3964
3965 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
3966}
3967
Jamie Madillfa05f602015-05-07 13:47:11 -04003968// 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 +02003969// TODO(oetuaho): Enable all below tests on OpenGL. Requires a fix for ANGLE bug 1278.
Geoff Lange0cc2a42016-01-20 10:58:17 -05003970ANGLE_INSTANTIATE_TEST(Texture2DTest,
3971 ES2_D3D9(),
3972 ES2_D3D11(),
3973 ES2_D3D11_FL9_3(),
3974 ES2_OPENGL(),
3975 ES2_OPENGLES());
3976ANGLE_INSTANTIATE_TEST(TextureCubeTest,
3977 ES2_D3D9(),
3978 ES2_D3D11(),
3979 ES2_D3D11_FL9_3(),
3980 ES2_OPENGL(),
3981 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003982ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
3983 ES2_D3D9(),
3984 ES2_D3D11(),
3985 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003986 ES2_OPENGL(),
3987 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003988ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
3989 ES2_D3D9(),
3990 ES2_D3D11(),
3991 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003992 ES2_OPENGL(),
3993 ES2_OPENGLES());
3994ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
3995 ES2_D3D9(),
3996 ES2_D3D11(),
3997 ES2_D3D11_FL9_3(),
3998 ES2_OPENGL(),
3999 ES2_OPENGLES());
4000ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
4001 ES2_D3D9(),
4002 ES2_D3D11(),
4003 ES2_D3D11_FL9_3(),
4004 ES2_OPENGL(),
4005 ES2_OPENGLES());
4006ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02004007ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02004008ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4009ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
4010 ES3_D3D11(),
4011 ES3_OPENGL(),
4012 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004013ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
4014 ES3_D3D11(),
4015 ES3_OPENGL(),
4016 ES3_OPENGLES());
4017ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4018ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02004019ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02004020ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
4021 ES2_D3D11(),
4022 ES2_D3D11_FL9_3(),
4023 ES2_D3D9(),
4024 ES2_OPENGL(),
4025 ES2_OPENGLES());
4026ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
4027 ES2_D3D11(),
4028 ES2_D3D11_FL9_3(),
4029 ES2_D3D9(),
4030 ES2_OPENGL(),
4031 ES2_OPENGLES());
4032ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
4033 ES2_D3D11(),
4034 ES2_D3D11_FL9_3(),
4035 ES2_D3D9(),
4036 ES2_OPENGL(),
4037 ES2_OPENGLES());
4038ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
4039 ES2_D3D11(),
4040 ES2_D3D11_FL9_3(),
4041 ES2_D3D9(),
4042 ES2_OPENGL(),
4043 ES2_OPENGLES());
4044ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
4045 ES2_D3D11(),
4046 ES2_D3D11_FL9_3(),
4047 ES2_D3D9(),
4048 ES2_OPENGL(),
4049 ES2_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004050ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES());
Vincent Lang25ab4512016-05-13 18:13:59 +02004051ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03004052ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04004053
Jamie Madill7ffdda92016-09-08 13:26:51 -04004054} // anonymous namespace