blob: 5f689c9c6bacfd58c953e78d7f4ee4fd2f91a873 [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 Etuaho4a8329f2016-01-11 17:12:57 +020052 return std::string(SHADER_SOURCE
Geoff Langc41e42d2014-04-28 10:58:16 -040053 (
54 precision highp float;
55 attribute vec4 position;
56 varying vec2 texcoord;
57
58 void main()
59 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +020060 gl_Position = vec4(position.xy, 0.0, 1.0);
Geoff Langc41e42d2014-04-28 10:58:16 -040061 texcoord = (position.xy * 0.5) + 0.5;
62 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +020063 )
Geoff Langc41e42d2014-04-28 10:58:16 -040064 );
Olli Etuaho4a8329f2016-01-11 17:12:57 +020065 }
Geoff Langc41e42d2014-04-28 10:58:16 -040066
Olli Etuaho4a8329f2016-01-11 17:12:57 +020067 virtual std::string getFragmentShaderSource() = 0;
68
Olli Etuahoa1c917f2016-04-06 13:50:03 +030069 virtual void setUpProgram()
Olli Etuaho4a8329f2016-01-11 17:12:57 +020070 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +020071 const std::string vertexShaderSource = getVertexShaderSource();
72 const std::string fragmentShaderSource = getFragmentShaderSource();
73
74 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
75 ASSERT_NE(0u, mProgram);
76 ASSERT_GL_NO_ERROR();
Olli Etuahoa1c917f2016-04-06 13:50:03 +030077 }
78
79 void SetUp() override
80 {
81 ANGLETest::SetUp();
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020082
83 setUpFramebuffer();
Olli Etuaho4a8329f2016-01-11 17:12:57 +020084 }
85
86 void TearDown() override
87 {
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020088 glBindFramebuffer(GL_FRAMEBUFFER, 0);
89 glDeleteFramebuffers(1, &mFramebuffer);
90 glDeleteTextures(1, &mFramebufferColorTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +020091 glDeleteProgram(mProgram);
92 ANGLETest::TearDown();
93 }
94
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020095 void setUpFramebuffer()
96 {
97 // We use an FBO to work around an issue where the default framebuffer applies SRGB
98 // conversion (particularly known to happen incorrectly on Intel GL drivers). It's not
99 // clear whether this issue can even be fixed on all backends. For example GLES 3.0.4 spec
100 // section 4.4 says that the format of the default framebuffer is entirely up to the window
101 // system, so it might be SRGB, and GLES 3.0 doesn't have a "FRAMEBUFFER_SRGB" to turn off
102 // SRGB conversion like desktop GL does.
103 // TODO(oetuaho): Get rid of this if the underlying issue is fixed.
104 glGenFramebuffers(1, &mFramebuffer);
105 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
106
107 glGenTextures(1, &mFramebufferColorTexture);
108 glBindTexture(GL_TEXTURE_2D, mFramebufferColorTexture);
109 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
110 GL_UNSIGNED_BYTE, nullptr);
111 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
112 mFramebufferColorTexture, 0);
113 ASSERT_GL_NO_ERROR();
114 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
115 glBindTexture(GL_TEXTURE_2D, 0);
116 }
117
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200118 // Returns the created texture ID.
119 GLuint create2DTexture()
120 {
121 GLuint texture2D;
122 glGenTextures(1, &texture2D);
123 glBindTexture(GL_TEXTURE_2D, texture2D);
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800124 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200125 EXPECT_GL_NO_ERROR();
126 return texture2D;
127 }
128
129 GLuint mProgram;
Olli Etuaho51f1c0f2016-01-13 16:16:24 +0200130 GLuint mFramebuffer;
131
132 private:
133 GLuint mFramebufferColorTexture;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200134};
135
136class Texture2DTest : public TexCoordDrawTest
137{
138 protected:
139 Texture2DTest() : TexCoordDrawTest(), mTexture2D(0), mTexture2DUniformLocation(-1) {}
140
141 std::string getFragmentShaderSource() override
142 {
143 return std::string(SHADER_SOURCE
Geoff Langc41e42d2014-04-28 10:58:16 -0400144 (
145 precision highp float;
146 uniform sampler2D tex;
147 varying vec2 texcoord;
148
149 void main()
150 {
151 gl_FragColor = texture2D(tex, texcoord);
152 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200153 )
Geoff Langc41e42d2014-04-28 10:58:16 -0400154 );
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200155 }
Geoff Langc41e42d2014-04-28 10:58:16 -0400156
Olli Etuaho96963162016-03-21 11:54:33 +0200157 virtual const char *getTextureUniformName() { return "tex"; }
158
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300159 void setUpProgram() override
160 {
161 TexCoordDrawTest::setUpProgram();
162 mTexture2DUniformLocation = glGetUniformLocation(mProgram, getTextureUniformName());
163 ASSERT_NE(-1, mTexture2DUniformLocation);
164 }
165
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200166 void SetUp() override
167 {
168 TexCoordDrawTest::SetUp();
169 mTexture2D = create2DTexture();
Jamie Madilld4cfa572014-07-08 10:00:32 -0400170
Jamie Madill9aca0592014-10-06 16:26:59 -0400171 ASSERT_GL_NO_ERROR();
Jamie Madillf67115c2014-04-22 13:14:05 -0400172 }
173
Jamie Madillfa05f602015-05-07 13:47:11 -0400174 void TearDown() override
Jamie Madillf67115c2014-04-22 13:14:05 -0400175 {
Jamie Madilld4cfa572014-07-08 10:00:32 -0400176 glDeleteTextures(1, &mTexture2D);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200177 TexCoordDrawTest::TearDown();
Jamie Madillf67115c2014-04-22 13:14:05 -0400178 }
179
Jamie Madillbc393df2015-01-29 13:46:07 -0500180 // Tests CopyTexSubImage with floating point textures of various formats.
181 void testFloatCopySubImage(int sourceImageChannels, int destImageChannels)
182 {
Geoff Langbde666a2015-04-07 17:17:08 -0400183 // TODO(jmadill): Figure out why this is broken on Intel D3D11
Jamie Madill518b9fa2016-03-02 11:26:02 -0500184 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
Geoff Langbde666a2015-04-07 17:17:08 -0400185 {
186 std::cout << "Test skipped on Intel D3D11." << std::endl;
187 return;
188 }
189
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300190 setUpProgram();
191
Martin Radev1be913c2016-07-11 17:59:16 +0300192 if (getClientMajorVersion() < 3)
Geoff Langfbfa47c2015-03-31 11:26:00 -0400193 {
Geoff Langc4e93662017-05-01 10:45:59 -0400194 if (!extensionEnabled("GL_EXT_texture_storage"))
195 {
196 std::cout << "Test skipped due to missing GL_EXT_texture_storage." << std::endl;
197 return;
198 }
199
Geoff Langfbfa47c2015-03-31 11:26:00 -0400200 if (!extensionEnabled("GL_OES_texture_float"))
201 {
202 std::cout << "Test skipped due to missing GL_OES_texture_float." << std::endl;
203 return;
204 }
205
206 if ((sourceImageChannels < 3 || destImageChannels < 3) && !extensionEnabled("GL_EXT_texture_rg"))
207 {
208 std::cout << "Test skipped due to missing GL_EXT_texture_rg." << std::endl;
209 return;
210 }
Geoff Lang677bb6f2017-04-05 12:40:40 -0400211
212 if (destImageChannels == 3 && !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"))
213 {
214 std::cout << "Test skipped due to missing GL_CHROMIUM_color_buffer_float_rgb."
215 << std::endl;
216 return;
217 }
218
219 if (destImageChannels == 4 && !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba"))
220 {
221 std::cout << "Test skipped due to missing GL_CHROMIUM_color_buffer_float_rgb."
222 << std::endl;
223 return;
224 }
225
226 if (destImageChannels <= 2)
227 {
228 std::cout << "Test skipped because no extensions grant renderability to 1 and 2 "
229 "channel floating point textures."
230 << std::endl;
231 return;
232 }
233 }
234 else
235 {
236 if (!extensionEnabled("GL_color_buffer_float"))
237 {
238 std::cout << "Test skipped due to missing GL_color_buffer_float." << std::endl;
239 return;
240 }
241
242 if (destImageChannels == 3 && !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"))
243 {
244 std::cout << "Test skipped due to missing GL_CHROMIUM_color_buffer_float_rgb."
245 << std::endl;
246 return;
247 }
Geoff Langfbfa47c2015-03-31 11:26:00 -0400248 }
249
Jamie Madillbc393df2015-01-29 13:46:07 -0500250 GLfloat sourceImageData[4][16] =
251 {
252 { // R
253 1.0f,
254 0.0f,
255 0.0f,
256 1.0f
257 },
258 { // RG
259 1.0f, 0.0f,
260 0.0f, 1.0f,
261 0.0f, 0.0f,
262 1.0f, 1.0f
263 },
264 { // RGB
265 1.0f, 0.0f, 0.0f,
266 0.0f, 1.0f, 0.0f,
267 0.0f, 0.0f, 1.0f,
268 1.0f, 1.0f, 0.0f
269 },
270 { // RGBA
271 1.0f, 0.0f, 0.0f, 1.0f,
272 0.0f, 1.0f, 0.0f, 1.0f,
273 0.0f, 0.0f, 1.0f, 1.0f,
274 1.0f, 1.0f, 0.0f, 1.0f
275 },
276 };
277
278 GLenum imageFormats[] =
279 {
280 GL_R32F,
281 GL_RG32F,
282 GL_RGB32F,
283 GL_RGBA32F,
284 };
285
286 GLenum sourceUnsizedFormats[] =
287 {
288 GL_RED,
289 GL_RG,
290 GL_RGB,
291 GL_RGBA,
292 };
293
294 GLuint textures[2];
295
296 glGenTextures(2, textures);
297
298 GLfloat *imageData = sourceImageData[sourceImageChannels - 1];
299 GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1];
300 GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1];
301 GLenum destImageFormat = imageFormats[destImageChannels - 1];
302
303 glBindTexture(GL_TEXTURE_2D, textures[0]);
Geoff Langc4e93662017-05-01 10:45:59 -0400304 if (getClientMajorVersion() >= 3)
305 {
306 glTexStorage2D(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
307 }
308 else
309 {
310 glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
311 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500312 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
313 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
314 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData);
315
hendrikwb27f79a2015-03-04 11:26:46 -0800316 if (sourceImageChannels < 3 && !extensionEnabled("GL_EXT_texture_rg"))
Jamie Madillbc393df2015-01-29 13:46:07 -0500317 {
318 // This is not supported
319 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
320 }
321 else
322 {
323 ASSERT_GL_NO_ERROR();
324 }
325
326 GLuint fbo;
327 glGenFramebuffers(1, &fbo);
328 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
329 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
330
331 glBindTexture(GL_TEXTURE_2D, textures[1]);
Geoff Langc4e93662017-05-01 10:45:59 -0400332 if (getClientMajorVersion() >= 3)
333 {
334 glTexStorage2D(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
335 }
336 else
337 {
338 glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
339 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500340 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
341 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
342
343 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
344 ASSERT_GL_NO_ERROR();
345
346 glBindFramebuffer(GL_FRAMEBUFFER, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200347 drawQuad(mProgram, "position", 0.5f);
Jamie Madillbc393df2015-01-29 13:46:07 -0500348
349 int testImageChannels = std::min(sourceImageChannels, destImageChannels);
350
Olli Etuahoa314b612016-03-10 16:43:00 +0200351 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Jamie Madillbc393df2015-01-29 13:46:07 -0500352 if (testImageChannels > 1)
353 {
354 EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255);
355 EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255);
356 if (testImageChannels > 2)
357 {
358 EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255);
359 }
360 }
361
362 glDeleteFramebuffers(1, &fbo);
363 glDeleteTextures(2, textures);
364
365 ASSERT_GL_NO_ERROR();
366 }
367
Jamie Madilld4cfa572014-07-08 10:00:32 -0400368 GLuint mTexture2D;
Jamie Madilld4cfa572014-07-08 10:00:32 -0400369 GLint mTexture2DUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400370};
371
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200372class Texture2DTestES3 : public Texture2DTest
373{
374 protected:
375 Texture2DTestES3() : Texture2DTest() {}
376
377 std::string getVertexShaderSource() override
378 {
379 return std::string(
380 "#version 300 es\n"
381 "out vec2 texcoord;\n"
382 "in vec4 position;\n"
383 "void main()\n"
384 "{\n"
385 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
386 " texcoord = (position.xy * 0.5) + 0.5;\n"
387 "}\n");
388 }
389
390 std::string getFragmentShaderSource() override
391 {
392 return std::string(
393 "#version 300 es\n"
394 "precision highp float;\n"
395 "uniform highp sampler2D tex;\n"
396 "in vec2 texcoord;\n"
397 "out vec4 fragColor;\n"
398 "void main()\n"
399 "{\n"
400 " fragColor = texture(tex, texcoord);\n"
401 "}\n");
402 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300403
404 void SetUp() override
405 {
406 Texture2DTest::SetUp();
407 setUpProgram();
408 }
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200409};
410
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200411class Texture2DIntegerAlpha1TestES3 : public Texture2DTest
412{
413 protected:
414 Texture2DIntegerAlpha1TestES3() : Texture2DTest() {}
415
416 std::string getVertexShaderSource() override
417 {
418 return std::string(
419 "#version 300 es\n"
420 "out vec2 texcoord;\n"
421 "in vec4 position;\n"
422 "void main()\n"
423 "{\n"
424 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
425 " texcoord = (position.xy * 0.5) + 0.5;\n"
426 "}\n");
427 }
428
429 std::string getFragmentShaderSource() override
430 {
431 return std::string(
432 "#version 300 es\n"
433 "precision highp float;\n"
434 "uniform highp isampler2D tex;\n"
435 "in vec2 texcoord;\n"
436 "out vec4 fragColor;\n"
437 "void main()\n"
438 "{\n"
439 " vec4 green = vec4(0, 1, 0, 1);\n"
440 " vec4 black = vec4(0, 0, 0, 0);\n"
441 " fragColor = (texture(tex, texcoord).a == 1) ? green : black;\n"
442 "}\n");
443 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300444
445 void SetUp() override
446 {
447 Texture2DTest::SetUp();
448 setUpProgram();
449 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200450};
451
452class Texture2DUnsignedIntegerAlpha1TestES3 : public Texture2DTest
453{
454 protected:
455 Texture2DUnsignedIntegerAlpha1TestES3() : Texture2DTest() {}
456
457 std::string getVertexShaderSource() override
458 {
459 return std::string(
460 "#version 300 es\n"
461 "out vec2 texcoord;\n"
462 "in vec4 position;\n"
463 "void main()\n"
464 "{\n"
465 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
466 " texcoord = (position.xy * 0.5) + 0.5;\n"
467 "}\n");
468 }
469
470 std::string getFragmentShaderSource() override
471 {
472 return std::string(
473 "#version 300 es\n"
474 "precision highp float;\n"
475 "uniform highp usampler2D tex;\n"
476 "in vec2 texcoord;\n"
477 "out vec4 fragColor;\n"
478 "void main()\n"
479 "{\n"
480 " vec4 green = vec4(0, 1, 0, 1);\n"
481 " vec4 black = vec4(0, 0, 0, 0);\n"
482 " fragColor = (texture(tex, texcoord).a == 1u) ? green : black;\n"
483 "}\n");
484 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300485
486 void SetUp() override
487 {
488 Texture2DTest::SetUp();
489 setUpProgram();
490 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200491};
492
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200493class Texture2DTestWithDrawScale : public Texture2DTest
Jamie Madill2453dbc2015-07-14 11:35:42 -0400494{
495 protected:
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200496 Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {}
497
498 std::string getVertexShaderSource() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400499 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200500 return std::string(SHADER_SOURCE
501 (
502 precision highp float;
503 attribute vec4 position;
504 varying vec2 texcoord;
505
506 uniform vec2 drawScale;
507
508 void main()
509 {
510 gl_Position = vec4(position.xy * drawScale, 0.0, 1.0);
511 texcoord = (position.xy * 0.5) + 0.5;
512 }
513 )
514 );
Jamie Madill2453dbc2015-07-14 11:35:42 -0400515 }
516
517 void SetUp() override
518 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200519 Texture2DTest::SetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300520
521 setUpProgram();
522
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200523 mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale");
524 ASSERT_NE(-1, mDrawScaleUniformLocation);
Jamie Madill2453dbc2015-07-14 11:35:42 -0400525
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200526 glUseProgram(mProgram);
527 glUniform2f(mDrawScaleUniformLocation, 1.0f, 1.0f);
528 glUseProgram(0);
529 ASSERT_GL_NO_ERROR();
530 }
531
532 GLint mDrawScaleUniformLocation;
533};
534
Olli Etuaho4644a202016-01-12 15:12:53 +0200535class Sampler2DAsFunctionParameterTest : public Texture2DTest
536{
537 protected:
538 Sampler2DAsFunctionParameterTest() : Texture2DTest() {}
539
540 std::string getFragmentShaderSource() override
541 {
542 return std::string(SHADER_SOURCE
543 (
544 precision highp float;
545 uniform sampler2D tex;
546 varying vec2 texcoord;
547
548 vec4 computeFragColor(sampler2D aTex)
549 {
550 return texture2D(aTex, texcoord);
551 }
552
553 void main()
554 {
555 gl_FragColor = computeFragColor(tex);
556 }
557 )
558 );
559 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300560
561 void SetUp() override
562 {
563 Texture2DTest::SetUp();
564 setUpProgram();
565 }
Olli Etuaho4644a202016-01-12 15:12:53 +0200566};
567
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200568class TextureCubeTest : public TexCoordDrawTest
569{
570 protected:
571 TextureCubeTest()
572 : TexCoordDrawTest(),
573 mTexture2D(0),
574 mTextureCube(0),
575 mTexture2DUniformLocation(-1),
576 mTextureCubeUniformLocation(-1)
577 {
578 }
579
580 std::string getFragmentShaderSource() override
581 {
582 return std::string(SHADER_SOURCE
583 (
584 precision highp float;
585 uniform sampler2D tex2D;
586 uniform samplerCube texCube;
587 varying vec2 texcoord;
588
589 void main()
590 {
591 gl_FragColor = texture2D(tex2D, texcoord);
592 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
593 }
594 )
595 );
596 }
597
598 void SetUp() override
599 {
600 TexCoordDrawTest::SetUp();
601
602 glGenTextures(1, &mTextureCube);
603 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Geoff Langc4e93662017-05-01 10:45:59 -0400604 for (GLenum face = 0; face < 6; face++)
605 {
606 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
607 GL_UNSIGNED_BYTE, nullptr);
608 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200609 EXPECT_GL_NO_ERROR();
610
611 mTexture2D = create2DTexture();
612
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300613 setUpProgram();
614
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200615 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
616 ASSERT_NE(-1, mTexture2DUniformLocation);
617 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
618 ASSERT_NE(-1, mTextureCubeUniformLocation);
619 }
620
621 void TearDown() override
622 {
623 glDeleteTextures(1, &mTextureCube);
624 TexCoordDrawTest::TearDown();
625 }
626
627 GLuint mTexture2D;
628 GLuint mTextureCube;
629 GLint mTexture2DUniformLocation;
630 GLint mTextureCubeUniformLocation;
631};
632
Martin Radev7e2c0d32017-09-15 14:25:42 +0300633class TextureCubeTestES3 : public ANGLETest
634{
635 protected:
636 TextureCubeTestES3() {}
637};
638
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200639class SamplerArrayTest : public TexCoordDrawTest
640{
641 protected:
642 SamplerArrayTest()
643 : TexCoordDrawTest(),
644 mTexture2DA(0),
645 mTexture2DB(0),
646 mTexture0UniformLocation(-1),
647 mTexture1UniformLocation(-1)
648 {
649 }
650
651 std::string getFragmentShaderSource() override
652 {
653 return std::string(SHADER_SOURCE
654 (
655 precision mediump float;
656 uniform highp sampler2D tex2DArray[2];
657 varying vec2 texcoord;
658 void main()
659 {
660 gl_FragColor = texture2D(tex2DArray[0], texcoord);
661 gl_FragColor += texture2D(tex2DArray[1], texcoord);
662 }
663 )
664 );
665 }
666
667 void SetUp() override
668 {
669 TexCoordDrawTest::SetUp();
670
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300671 setUpProgram();
672
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200673 mTexture0UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[0]");
674 ASSERT_NE(-1, mTexture0UniformLocation);
675 mTexture1UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[1]");
676 ASSERT_NE(-1, mTexture1UniformLocation);
677
678 mTexture2DA = create2DTexture();
679 mTexture2DB = create2DTexture();
680 ASSERT_GL_NO_ERROR();
681 }
682
683 void TearDown() override
684 {
685 glDeleteTextures(1, &mTexture2DA);
686 glDeleteTextures(1, &mTexture2DB);
687 TexCoordDrawTest::TearDown();
688 }
689
690 void testSamplerArrayDraw()
691 {
692 GLubyte texData[4];
693 texData[0] = 0;
694 texData[1] = 60;
695 texData[2] = 0;
696 texData[3] = 255;
697
698 glActiveTexture(GL_TEXTURE0);
699 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
700 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
701
702 texData[1] = 120;
703 glActiveTexture(GL_TEXTURE1);
704 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
705 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
706 EXPECT_GL_ERROR(GL_NO_ERROR);
707
708 glUseProgram(mProgram);
709 glUniform1i(mTexture0UniformLocation, 0);
710 glUniform1i(mTexture1UniformLocation, 1);
711 drawQuad(mProgram, "position", 0.5f);
712 EXPECT_GL_NO_ERROR();
713
714 EXPECT_PIXEL_NEAR(0, 0, 0, 180, 0, 255, 2);
715 }
716
717 GLuint mTexture2DA;
718 GLuint mTexture2DB;
719 GLint mTexture0UniformLocation;
720 GLint mTexture1UniformLocation;
721};
722
723
724class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest
725{
726 protected:
727 SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {}
728
729 std::string getFragmentShaderSource() override
730 {
731 return std::string(SHADER_SOURCE
732 (
733 precision mediump float;
734 uniform highp sampler2D tex2DArray[2];
735 varying vec2 texcoord;
736
737 vec4 computeFragColor(highp sampler2D aTex2DArray[2])
738 {
739 return texture2D(aTex2DArray[0], texcoord) + texture2D(aTex2DArray[1], texcoord);
740 }
741
742 void main()
743 {
744 gl_FragColor = computeFragColor(tex2DArray);
745 }
746 )
747 );
748 }
749};
750
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200751class Texture2DArrayTestES3 : public TexCoordDrawTest
752{
753 protected:
754 Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {}
755
756 std::string getVertexShaderSource() override
757 {
758 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400759 "#version 300 es\n"
760 "out vec2 texcoord;\n"
761 "in vec4 position;\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200762 "void main()\n"
763 "{\n"
764 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
765 " texcoord = (position.xy * 0.5) + 0.5;\n"
766 "}\n");
767 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400768
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200769 std::string getFragmentShaderSource() override
770 {
771 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400772 "#version 300 es\n"
773 "precision highp float;\n"
Olli Etuaho183d7e22015-11-20 15:59:09 +0200774 "uniform highp sampler2DArray tex2DArray;\n"
Jamie Madill2453dbc2015-07-14 11:35:42 -0400775 "in vec2 texcoord;\n"
776 "out vec4 fragColor;\n"
777 "void main()\n"
778 "{\n"
779 " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200780 "}\n");
781 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400782
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200783 void SetUp() override
784 {
785 TexCoordDrawTest::SetUp();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400786
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300787 setUpProgram();
788
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200789 mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray");
Jamie Madill2453dbc2015-07-14 11:35:42 -0400790 ASSERT_NE(-1, mTextureArrayLocation);
791
792 glGenTextures(1, &m2DArrayTexture);
793 ASSERT_GL_NO_ERROR();
794 }
795
796 void TearDown() override
797 {
798 glDeleteTextures(1, &m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200799 TexCoordDrawTest::TearDown();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400800 }
801
802 GLuint m2DArrayTexture;
Jamie Madill2453dbc2015-07-14 11:35:42 -0400803 GLint mTextureArrayLocation;
804};
805
Olli Etuahobce743a2016-01-15 17:18:28 +0200806class TextureSizeTextureArrayTest : public TexCoordDrawTest
807{
808 protected:
809 TextureSizeTextureArrayTest()
810 : TexCoordDrawTest(),
811 mTexture2DA(0),
812 mTexture2DB(0),
813 mTexture0Location(-1),
814 mTexture1Location(-1)
815 {
816 }
817
818 std::string getVertexShaderSource() override
819 {
820 return std::string(
821 "#version 300 es\n"
822 "in vec4 position;\n"
823 "void main()\n"
824 "{\n"
825 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
826 "}\n");
827 }
828
829 std::string getFragmentShaderSource() override
830 {
831 return std::string(
832 "#version 300 es\n"
833 "precision highp float;\n"
834 "uniform highp sampler2D tex2DArray[2];\n"
835 "out vec4 fragColor;\n"
836 "void main()\n"
837 "{\n"
838 " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n"
839 " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n"
840 " fragColor = vec4(red, green, 0.0, 1.0);\n"
841 "}\n");
842 }
843
844 void SetUp() override
845 {
846 TexCoordDrawTest::SetUp();
847
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300848 setUpProgram();
849
Olli Etuahobce743a2016-01-15 17:18:28 +0200850 mTexture0Location = glGetUniformLocation(mProgram, "tex2DArray[0]");
851 ASSERT_NE(-1, mTexture0Location);
852 mTexture1Location = glGetUniformLocation(mProgram, "tex2DArray[1]");
853 ASSERT_NE(-1, mTexture1Location);
854
855 mTexture2DA = create2DTexture();
856 mTexture2DB = create2DTexture();
857 ASSERT_GL_NO_ERROR();
858 }
859
860 void TearDown() override
861 {
862 glDeleteTextures(1, &mTexture2DA);
863 glDeleteTextures(1, &mTexture2DB);
864 TexCoordDrawTest::TearDown();
865 }
866
867 GLuint mTexture2DA;
868 GLuint mTexture2DB;
869 GLint mTexture0Location;
870 GLint mTexture1Location;
871};
872
Olli Etuahoa314b612016-03-10 16:43:00 +0200873class Texture3DTestES3 : public TexCoordDrawTest
874{
875 protected:
876 Texture3DTestES3() : TexCoordDrawTest(), mTexture3D(0), mTexture3DUniformLocation(-1) {}
877
878 std::string getVertexShaderSource() override
879 {
880 return std::string(
881 "#version 300 es\n"
882 "out vec2 texcoord;\n"
883 "in vec4 position;\n"
884 "void main()\n"
885 "{\n"
886 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
887 " texcoord = (position.xy * 0.5) + 0.5;\n"
888 "}\n");
889 }
890
891 std::string getFragmentShaderSource() override
892 {
893 return std::string(
894 "#version 300 es\n"
895 "precision highp float;\n"
896 "uniform highp sampler3D tex3D;\n"
897 "in vec2 texcoord;\n"
898 "out vec4 fragColor;\n"
899 "void main()\n"
900 "{\n"
901 " fragColor = texture(tex3D, vec3(texcoord, 0.0));\n"
902 "}\n");
903 }
904
905 void SetUp() override
906 {
907 TexCoordDrawTest::SetUp();
908
909 glGenTextures(1, &mTexture3D);
910
911 setUpProgram();
912
913 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
914 ASSERT_NE(-1, mTexture3DUniformLocation);
915 }
916
917 void TearDown() override
918 {
919 glDeleteTextures(1, &mTexture3D);
920 TexCoordDrawTest::TearDown();
921 }
922
923 GLuint mTexture3D;
924 GLint mTexture3DUniformLocation;
925};
926
Olli Etuaho1a679902016-01-14 12:21:47 +0200927class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest
928{
929 protected:
930 ShadowSamplerPlusSampler3DTestES3()
931 : TexCoordDrawTest(),
932 mTextureShadow(0),
933 mTexture3D(0),
934 mTextureShadowUniformLocation(-1),
935 mTexture3DUniformLocation(-1),
936 mDepthRefUniformLocation(-1)
937 {
938 }
939
940 std::string getVertexShaderSource() override
941 {
942 return std::string(
943 "#version 300 es\n"
944 "out vec2 texcoord;\n"
945 "in vec4 position;\n"
946 "void main()\n"
947 "{\n"
948 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
949 " texcoord = (position.xy * 0.5) + 0.5;\n"
950 "}\n");
951 }
952
953 std::string getFragmentShaderSource() override
954 {
955 return std::string(
956 "#version 300 es\n"
957 "precision highp float;\n"
958 "uniform highp sampler2DShadow tex2DShadow;\n"
959 "uniform highp sampler3D tex3D;\n"
960 "in vec2 texcoord;\n"
961 "uniform float depthRef;\n"
962 "out vec4 fragColor;\n"
963 "void main()\n"
964 "{\n"
965 " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n"
966 " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n"
967 "}\n");
968 }
969
970 void SetUp() override
971 {
972 TexCoordDrawTest::SetUp();
973
974 glGenTextures(1, &mTexture3D);
975
976 glGenTextures(1, &mTextureShadow);
977 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
978 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
979
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300980 setUpProgram();
981
Olli Etuaho1a679902016-01-14 12:21:47 +0200982 mTextureShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
983 ASSERT_NE(-1, mTextureShadowUniformLocation);
984 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
985 ASSERT_NE(-1, mTexture3DUniformLocation);
986 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
987 ASSERT_NE(-1, mDepthRefUniformLocation);
988 }
989
990 void TearDown() override
991 {
992 glDeleteTextures(1, &mTextureShadow);
993 glDeleteTextures(1, &mTexture3D);
994 TexCoordDrawTest::TearDown();
995 }
996
997 GLuint mTextureShadow;
998 GLuint mTexture3D;
999 GLint mTextureShadowUniformLocation;
1000 GLint mTexture3DUniformLocation;
1001 GLint mDepthRefUniformLocation;
1002};
1003
Olli Etuahoc8c99a02016-01-14 16:47:22 +02001004class SamplerTypeMixTestES3 : public TexCoordDrawTest
1005{
1006 protected:
1007 SamplerTypeMixTestES3()
1008 : TexCoordDrawTest(),
1009 mTexture2D(0),
1010 mTextureCube(0),
1011 mTexture2DShadow(0),
1012 mTextureCubeShadow(0),
1013 mTexture2DUniformLocation(-1),
1014 mTextureCubeUniformLocation(-1),
1015 mTexture2DShadowUniformLocation(-1),
1016 mTextureCubeShadowUniformLocation(-1),
1017 mDepthRefUniformLocation(-1)
1018 {
1019 }
1020
1021 std::string getVertexShaderSource() override
1022 {
1023 return std::string(
1024 "#version 300 es\n"
1025 "out vec2 texcoord;\n"
1026 "in vec4 position;\n"
1027 "void main()\n"
1028 "{\n"
1029 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1030 " texcoord = (position.xy * 0.5) + 0.5;\n"
1031 "}\n");
1032 }
1033
1034 std::string getFragmentShaderSource() override
1035 {
1036 return std::string(
1037 "#version 300 es\n"
1038 "precision highp float;\n"
1039 "uniform highp sampler2D tex2D;\n"
1040 "uniform highp samplerCube texCube;\n"
1041 "uniform highp sampler2DShadow tex2DShadow;\n"
1042 "uniform highp samplerCubeShadow texCubeShadow;\n"
1043 "in vec2 texcoord;\n"
1044 "uniform float depthRef;\n"
1045 "out vec4 fragColor;\n"
1046 "void main()\n"
1047 "{\n"
1048 " fragColor = texture(tex2D, texcoord);\n"
1049 " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n"
1050 " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n"
1051 " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * "
1052 "0.125);\n"
1053 "}\n");
1054 }
1055
1056 void SetUp() override
1057 {
1058 TexCoordDrawTest::SetUp();
1059
1060 glGenTextures(1, &mTexture2D);
1061 glGenTextures(1, &mTextureCube);
1062
1063 glGenTextures(1, &mTexture2DShadow);
1064 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
1065 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
1066
1067 glGenTextures(1, &mTextureCubeShadow);
1068 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
1069 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
1070
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001071 setUpProgram();
1072
Olli Etuahoc8c99a02016-01-14 16:47:22 +02001073 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
1074 ASSERT_NE(-1, mTexture2DUniformLocation);
1075 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
1076 ASSERT_NE(-1, mTextureCubeUniformLocation);
1077 mTexture2DShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
1078 ASSERT_NE(-1, mTexture2DShadowUniformLocation);
1079 mTextureCubeShadowUniformLocation = glGetUniformLocation(mProgram, "texCubeShadow");
1080 ASSERT_NE(-1, mTextureCubeShadowUniformLocation);
1081 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
1082 ASSERT_NE(-1, mDepthRefUniformLocation);
1083
1084 ASSERT_GL_NO_ERROR();
1085 }
1086
1087 void TearDown() override
1088 {
1089 glDeleteTextures(1, &mTexture2D);
1090 glDeleteTextures(1, &mTextureCube);
1091 glDeleteTextures(1, &mTexture2DShadow);
1092 glDeleteTextures(1, &mTextureCubeShadow);
1093 TexCoordDrawTest::TearDown();
1094 }
1095
1096 GLuint mTexture2D;
1097 GLuint mTextureCube;
1098 GLuint mTexture2DShadow;
1099 GLuint mTextureCubeShadow;
1100 GLint mTexture2DUniformLocation;
1101 GLint mTextureCubeUniformLocation;
1102 GLint mTexture2DShadowUniformLocation;
1103 GLint mTextureCubeShadowUniformLocation;
1104 GLint mDepthRefUniformLocation;
1105};
1106
Olli Etuaho96963162016-03-21 11:54:33 +02001107class SamplerInStructTest : public Texture2DTest
1108{
1109 protected:
1110 SamplerInStructTest() : Texture2DTest() {}
1111
1112 const char *getTextureUniformName() override { return "us.tex"; }
1113
1114 std::string getFragmentShaderSource() override
1115 {
1116 return std::string(
1117 "precision highp float;\n"
1118 "struct S\n"
1119 "{\n"
1120 " vec4 a;\n"
1121 " highp sampler2D tex;\n"
1122 "};\n"
1123 "uniform S us;\n"
1124 "varying vec2 texcoord;\n"
1125 "void main()\n"
1126 "{\n"
1127 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x);\n"
1128 "}\n");
1129 }
1130
1131 void runSamplerInStructTest()
1132 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001133 setUpProgram();
1134
Olli Etuaho96963162016-03-21 11:54:33 +02001135 glActiveTexture(GL_TEXTURE0);
1136 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001137 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1138 &GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001139 drawQuad(mProgram, "position", 0.5f);
Olli Etuahoa314b612016-03-10 16:43:00 +02001140 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001141 }
1142};
1143
1144class SamplerInStructAsFunctionParameterTest : public SamplerInStructTest
1145{
1146 protected:
1147 SamplerInStructAsFunctionParameterTest() : SamplerInStructTest() {}
1148
1149 std::string getFragmentShaderSource() override
1150 {
1151 return std::string(
1152 "precision highp float;\n"
1153 "struct S\n"
1154 "{\n"
1155 " vec4 a;\n"
1156 " highp sampler2D tex;\n"
1157 "};\n"
1158 "uniform S us;\n"
1159 "varying vec2 texcoord;\n"
1160 "vec4 sampleFrom(S s) {\n"
1161 " return texture2D(s.tex, texcoord + s.a.x);\n"
1162 "}\n"
1163 "void main()\n"
1164 "{\n"
1165 " gl_FragColor = sampleFrom(us);\n"
1166 "}\n");
1167 }
1168};
1169
1170class SamplerInStructArrayAsFunctionParameterTest : public SamplerInStructTest
1171{
1172 protected:
1173 SamplerInStructArrayAsFunctionParameterTest() : SamplerInStructTest() {}
1174
1175 const char *getTextureUniformName() override { return "us[0].tex"; }
1176
1177 std::string getFragmentShaderSource() override
1178 {
1179 return std::string(
1180 "precision highp float;\n"
1181 "struct S\n"
1182 "{\n"
1183 " vec4 a;\n"
1184 " highp sampler2D tex;\n"
1185 "};\n"
1186 "uniform S us[1];\n"
1187 "varying vec2 texcoord;\n"
1188 "vec4 sampleFrom(S s) {\n"
1189 " return texture2D(s.tex, texcoord + s.a.x);\n"
1190 "}\n"
1191 "void main()\n"
1192 "{\n"
1193 " gl_FragColor = sampleFrom(us[0]);\n"
1194 "}\n");
1195 }
1196};
1197
1198class SamplerInNestedStructAsFunctionParameterTest : public SamplerInStructTest
1199{
1200 protected:
1201 SamplerInNestedStructAsFunctionParameterTest() : SamplerInStructTest() {}
1202
1203 const char *getTextureUniformName() override { return "us[0].sub.tex"; }
1204
1205 std::string getFragmentShaderSource() override
1206 {
1207 return std::string(
1208 "precision highp float;\n"
1209 "struct SUB\n"
1210 "{\n"
1211 " vec4 a;\n"
1212 " highp sampler2D tex;\n"
1213 "};\n"
1214 "struct S\n"
1215 "{\n"
1216 " SUB sub;\n"
1217 "};\n"
1218 "uniform S us[1];\n"
1219 "varying vec2 texcoord;\n"
1220 "vec4 sampleFrom(SUB s) {\n"
1221 " return texture2D(s.tex, texcoord + s.a.x);\n"
1222 "}\n"
1223 "void main()\n"
1224 "{\n"
1225 " gl_FragColor = sampleFrom(us[0].sub);\n"
1226 "}\n");
1227 }
1228};
1229
1230class SamplerInStructAndOtherVariableTest : public SamplerInStructTest
1231{
1232 protected:
1233 SamplerInStructAndOtherVariableTest() : SamplerInStructTest() {}
1234
1235 std::string getFragmentShaderSource() override
1236 {
1237 return std::string(
1238 "precision highp float;\n"
1239 "struct S\n"
1240 "{\n"
1241 " vec4 a;\n"
1242 " highp sampler2D tex;\n"
1243 "};\n"
1244 "uniform S us;\n"
1245 "uniform float us_tex;\n"
1246 "varying vec2 texcoord;\n"
1247 "void main()\n"
1248 "{\n"
1249 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x + us_tex);\n"
1250 "}\n");
1251 }
1252};
1253
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001254TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001255{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001256 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001257 EXPECT_GL_ERROR(GL_NO_ERROR);
1258
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001259 setUpProgram();
1260
Jamie Madillf67115c2014-04-22 13:14:05 -04001261 const GLubyte *pixels[20] = { 0 };
1262 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1263 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001264
1265 if (extensionEnabled("GL_EXT_texture_storage"))
1266 {
1267 // Create a 1-level immutable texture.
1268 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1269
1270 // Try calling sub image on the second level.
1271 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1272 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1273 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001274}
Geoff Langc41e42d2014-04-28 10:58:16 -04001275
John Bauman18319182016-09-28 14:22:27 -07001276// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1277TEST_P(Texture2DTest, QueryBinding)
1278{
1279 glBindTexture(GL_TEXTURE_2D, 0);
1280 EXPECT_GL_ERROR(GL_NO_ERROR);
1281
1282 GLint textureBinding;
1283 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1284 EXPECT_GL_NO_ERROR();
1285 EXPECT_EQ(0, textureBinding);
1286
1287 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
1288 if (extensionEnabled("GL_OES_EGL_image_external") ||
1289 extensionEnabled("GL_NV_EGL_stream_consumer_external"))
1290 {
1291 EXPECT_GL_NO_ERROR();
1292 EXPECT_EQ(0, textureBinding);
1293 }
1294 else
1295 {
1296 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1297 }
1298}
1299
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001300TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001301{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001302 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001303 EXPECT_GL_ERROR(GL_NO_ERROR);
1304
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001305 setUpProgram();
1306
Geoff Langc41e42d2014-04-28 10:58:16 -04001307 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001308 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001309 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001310 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001311
1312 const GLubyte *pixel[4] = { 0 };
1313
1314 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1315 EXPECT_GL_NO_ERROR();
1316
1317 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1318 EXPECT_GL_NO_ERROR();
1319
1320 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1321 EXPECT_GL_NO_ERROR();
1322}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001323
1324// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001325TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001326{
1327 glActiveTexture(GL_TEXTURE0);
1328 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1329 glActiveTexture(GL_TEXTURE1);
1330 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1331 EXPECT_GL_ERROR(GL_NO_ERROR);
1332
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001333 glUseProgram(mProgram);
1334 glUniform1i(mTexture2DUniformLocation, 0);
1335 glUniform1i(mTextureCubeUniformLocation, 1);
1336 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001337 EXPECT_GL_NO_ERROR();
1338}
Jamie Madill9aca0592014-10-06 16:26:59 -04001339
Olli Etuaho53a2da12016-01-11 15:43:32 +02001340// Test drawing with two texture types accessed from the same shader and check that the result of
1341// drawing is correct.
1342TEST_P(TextureCubeTest, CubeMapDraw)
1343{
1344 GLubyte texData[4];
1345 texData[0] = 0;
1346 texData[1] = 60;
1347 texData[2] = 0;
1348 texData[3] = 255;
1349
1350 glActiveTexture(GL_TEXTURE0);
1351 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1352 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1353
1354 glActiveTexture(GL_TEXTURE1);
1355 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1356 texData[1] = 120;
1357 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1358 texData);
1359 EXPECT_GL_ERROR(GL_NO_ERROR);
1360
1361 glUseProgram(mProgram);
1362 glUniform1i(mTexture2DUniformLocation, 0);
1363 glUniform1i(mTextureCubeUniformLocation, 1);
1364 drawQuad(mProgram, "position", 0.5f);
1365 EXPECT_GL_NO_ERROR();
1366
1367 int px = getWindowWidth() - 1;
1368 int py = 0;
1369 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1370}
1371
Olli Etuaho4644a202016-01-12 15:12:53 +02001372TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1373{
1374 glActiveTexture(GL_TEXTURE0);
1375 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1376 GLubyte texData[4];
1377 texData[0] = 0;
1378 texData[1] = 128;
1379 texData[2] = 0;
1380 texData[3] = 255;
1381 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1382 glUseProgram(mProgram);
1383 glUniform1i(mTexture2DUniformLocation, 0);
1384 drawQuad(mProgram, "position", 0.5f);
1385 EXPECT_GL_NO_ERROR();
1386
1387 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1388}
1389
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001390// Test drawing with two textures passed to the shader in a sampler array.
1391TEST_P(SamplerArrayTest, SamplerArrayDraw)
1392{
1393 testSamplerArrayDraw();
1394}
1395
1396// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1397// user-defined function in the shader.
1398TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1399{
1400 testSamplerArrayDraw();
1401}
1402
Jamie Madill9aca0592014-10-06 16:26:59 -04001403// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001404TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001405{
1406 int px = getWindowWidth() / 2;
1407 int py = getWindowHeight() / 2;
1408
1409 glActiveTexture(GL_TEXTURE0);
1410 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1411
Olli Etuahoa314b612016-03-10 16:43:00 +02001412 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001413
Olli Etuahoa314b612016-03-10 16:43:00 +02001414 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001415 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1416 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1417 glGenerateMipmap(GL_TEXTURE_2D);
1418
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001419 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001420 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001421 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1422 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001423 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001424 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001425
Olli Etuahoa314b612016-03-10 16:43:00 +02001426 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001427
Olli Etuahoa314b612016-03-10 16:43:00 +02001428 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1429 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001430 glGenerateMipmap(GL_TEXTURE_2D);
1431
Olli Etuahoa314b612016-03-10 16:43:00 +02001432 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001433
Olli Etuahoa314b612016-03-10 16:43:00 +02001434 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1435 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001436 glGenerateMipmap(GL_TEXTURE_2D);
1437
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001438 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001439
1440 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001441 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001442}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001443
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001444// Test creating a FBO with a cube map render target, to test an ANGLE bug
1445// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001446TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001447{
1448 GLuint fbo;
1449 glGenFramebuffers(1, &fbo);
1450 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1451
1452 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1453 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mTextureCube, 0);
1454
Corentin Wallez322653b2015-06-17 18:33:56 +02001455 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001456
1457 glDeleteFramebuffers(1, &fbo);
1458
1459 EXPECT_GL_NO_ERROR();
1460}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001461
1462// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001463TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001464{
Geoff Langc4e93662017-05-01 10:45:59 -04001465 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_texture_storage"))
1466 {
1467 std::cout << "Test skipped because ES3 or GL_EXT_texture_storage not available."
1468 << std::endl;
1469 return;
1470 }
1471
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001472 int width = getWindowWidth();
1473 int height = getWindowHeight();
1474
1475 GLuint tex2D;
1476 glGenTextures(1, &tex2D);
1477 glActiveTexture(GL_TEXTURE0);
1478 glBindTexture(GL_TEXTURE_2D, tex2D);
1479
1480 // Fill with red
1481 std::vector<GLubyte> pixels(3 * 16 * 16);
1482 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1483 {
1484 pixels[pixelId * 3 + 0] = 255;
1485 pixels[pixelId * 3 + 1] = 0;
1486 pixels[pixelId * 3 + 2] = 0;
1487 }
1488
1489 // ANGLE internally uses RGBA as the DirectX format for RGB images
1490 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1491 // The data is kept in a CPU-side image and the image is marked as dirty.
Geoff Langc4e93662017-05-01 10:45:59 -04001492 if (getClientMajorVersion() >= 3)
1493 {
1494 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1495 }
1496 else
1497 {
1498 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1499 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001500
1501 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1502 // glTexSubImage2D should take into account that the image is dirty.
1503 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1504 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1505 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1506
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001507 setUpProgram();
1508
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001509 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001510 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001511 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001512 glDeleteTextures(1, &tex2D);
1513 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001514 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001515
1516 // Validate that the region of the texture without data has an alpha of 1.0
1517 GLubyte pixel[4];
1518 glReadPixels(3 * width / 4, 3 * height / 4, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1519 EXPECT_EQ(pixel[3], 255);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001520}
1521
1522// 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 +02001523TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001524{
1525 if (extensionEnabled("NV_pixel_buffer_object"))
1526 {
1527 int width = getWindowWidth();
1528 int height = getWindowHeight();
1529
1530 GLuint tex2D;
1531 glGenTextures(1, &tex2D);
1532 glActiveTexture(GL_TEXTURE0);
1533 glBindTexture(GL_TEXTURE_2D, tex2D);
1534
1535 // Fill with red
1536 std::vector<GLubyte> pixels(3 * 16 * 16);
1537 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1538 {
1539 pixels[pixelId * 3 + 0] = 255;
1540 pixels[pixelId * 3 + 1] = 0;
1541 pixels[pixelId * 3 + 2] = 0;
1542 }
1543
1544 // Read 16x16 region from red backbuffer to PBO
1545 GLuint pbo;
1546 glGenBuffers(1, &pbo);
1547 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1548 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1549
1550 // ANGLE internally uses RGBA as the DirectX format for RGB images
1551 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1552 // The data is kept in a CPU-side image and the image is marked as dirty.
1553 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1554
1555 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1556 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001557 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 +00001558 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1559 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1560
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001561 setUpProgram();
1562
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001563 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001564 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001565 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001566 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001567 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001568 EXPECT_GL_NO_ERROR();
1569 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1570 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1571 }
1572}
Jamie Madillbc393df2015-01-29 13:46:07 -05001573
1574// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001575TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001576{
1577 testFloatCopySubImage(1, 1);
1578}
1579
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001580TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001581{
1582 testFloatCopySubImage(2, 1);
1583}
1584
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001585TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001586{
1587 testFloatCopySubImage(2, 2);
1588}
1589
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001590TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001591{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001592 if (IsIntel() && IsLinux())
1593 {
1594 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1595 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1596 return;
1597 }
1598
Jamie Madillbc393df2015-01-29 13:46:07 -05001599 testFloatCopySubImage(3, 1);
1600}
1601
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001602TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001603{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001604 if (IsIntel() && IsLinux())
1605 {
1606 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1607 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1608 return;
1609 }
1610
Jamie Madillbc393df2015-01-29 13:46:07 -05001611 testFloatCopySubImage(3, 2);
1612}
1613
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001614TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001615{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001616 if (IsIntel() && IsLinux())
1617 {
1618 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1619 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1620 return;
1621 }
1622
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(3, 3);
1631}
1632
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001633TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001634{
1635 testFloatCopySubImage(4, 1);
1636}
1637
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001638TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001639{
1640 testFloatCopySubImage(4, 2);
1641}
1642
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001643TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001644{
Austin Kinrossd544cc92016-01-11 15:26:42 -08001645 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001646 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001647 {
1648 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1649 return;
1650 }
1651
Jamie Madillbc393df2015-01-29 13:46:07 -05001652 testFloatCopySubImage(4, 3);
1653}
1654
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001655TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001656{
Austin Kinrossd544cc92016-01-11 15:26:42 -08001657 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001658 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001659 {
1660 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1661 return;
1662 }
1663
Jamie Madillbc393df2015-01-29 13:46:07 -05001664 testFloatCopySubImage(4, 4);
1665}
Austin Kinross07285142015-03-26 11:36:16 -07001666
1667// Port of https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1668// 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 +02001669TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001670{
1671 const int npotTexSize = 5;
1672 const int potTexSize = 4; // Should be less than npotTexSize
1673 GLuint tex2D;
1674
1675 if (extensionEnabled("GL_OES_texture_npot"))
1676 {
1677 // This test isn't applicable if texture_npot is enabled
1678 return;
1679 }
1680
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001681 setUpProgram();
1682
Austin Kinross07285142015-03-26 11:36:16 -07001683 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1684
Austin Kinross5faa15b2016-01-11 13:32:48 -08001685 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1686 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1687
Austin Kinross07285142015-03-26 11:36:16 -07001688 glActiveTexture(GL_TEXTURE0);
1689 glGenTextures(1, &tex2D);
1690 glBindTexture(GL_TEXTURE_2D, tex2D);
1691
1692 std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize);
1693 for (size_t pixelId = 0; pixelId < npotTexSize * npotTexSize; ++pixelId)
1694 {
1695 pixels[pixelId] = 64;
1696 }
1697
1698 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1699 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1700
1701 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
1702 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1703 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1704
1705 // Check that an NPOT texture on level 0 succeeds
1706 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1707 EXPECT_GL_NO_ERROR();
1708
1709 // Check that generateMipmap fails on NPOT
1710 glGenerateMipmap(GL_TEXTURE_2D);
1711 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1712
1713 // Check that nothing is drawn if filtering is not correct for NPOT
1714 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1715 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1716 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1717 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1718 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001719 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001720 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1721
1722 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1723 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1724 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1725 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1726 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001727 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001728 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1729
1730 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1731 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1732 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001733 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001734 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1735
1736 // Check that glTexImage2D for POT texture succeeds
1737 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1738 EXPECT_GL_NO_ERROR();
1739
1740 // Check that generateMipmap for an POT texture succeeds
1741 glGenerateMipmap(GL_TEXTURE_2D);
1742 EXPECT_GL_NO_ERROR();
1743
1744 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1745 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1746 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1747 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1748 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1749 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001750 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001751 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1752 EXPECT_GL_NO_ERROR();
1753}
Jamie Madillfa05f602015-05-07 13:47:11 -04001754
Austin Kinross08528e12015-10-07 16:24:40 -07001755// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1756// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001757TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001758{
Geoff Lange0cc2a42016-01-20 10:58:17 -05001759 // TODO(geofflang): Allow the GL backend to accept SubImage calls with a null data ptr. (bug
1760 // 1278)
1761 if (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
1762 getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE)
1763 {
1764 std::cout << "Test disabled on OpenGL." << std::endl;
1765 return;
1766 }
1767
Austin Kinross08528e12015-10-07 16:24:40 -07001768 glActiveTexture(GL_TEXTURE0);
1769 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1770
1771 // Create an 8x8 (i.e. power-of-two) texture.
1772 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1773 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1774 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1775 glGenerateMipmap(GL_TEXTURE_2D);
1776
1777 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1778 // This should always work, even if GL_OES_texture_npot isn't active.
1779 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1780
1781 EXPECT_GL_NO_ERROR();
1782}
1783
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001784// Test to check that texture completeness is determined correctly when the texture base level is
1785// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1786TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1787{
1788 glActiveTexture(GL_TEXTURE0);
1789 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001790
1791 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1792 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1793 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1794 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1795 texDataGreen.data());
1796 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1797 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001798 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1799 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1800 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1801
1802 EXPECT_GL_NO_ERROR();
1803
1804 drawQuad(mProgram, "position", 0.5f);
1805
Olli Etuahoa314b612016-03-10 16:43:00 +02001806 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1807}
1808
1809// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1810// have images defined.
1811TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1812{
1813 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1814 {
1815 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1816 std::cout << "Test skipped on AMD OpenGL." << std::endl;
1817 return;
1818 }
1819 if (IsOSX())
1820 {
1821 // Observed incorrect rendering on OSX.
1822 std::cout << "Test skipped on OSX." << std::endl;
1823 return;
1824 }
1825 glActiveTexture(GL_TEXTURE0);
1826 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1827 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1828 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1829 texDataGreen.data());
1830 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1831 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1832 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1833 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1834
1835 EXPECT_GL_NO_ERROR();
1836
1837 drawQuad(mProgram, "position", 0.5f);
1838
1839 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1840}
1841
Olli Etuahoe8528d82016-05-16 17:50:52 +03001842// Test that drawing works correctly when level 0 is undefined and base level is 1.
1843TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1844{
1845 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1846 {
1847 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1848 std::cout << "Test skipped on AMD OpenGL." << std::endl;
1849 return;
1850 }
1851 if (IsOSX())
1852 {
1853 // Observed incorrect rendering on OSX.
1854 std::cout << "Test skipped on OSX." << std::endl;
1855 return;
1856 }
1857 glActiveTexture(GL_TEXTURE0);
1858 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1859 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1860 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1861 texDataGreen.data());
1862 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1863 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1864 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1865 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1866
1867 EXPECT_GL_NO_ERROR();
1868
1869 // Texture is incomplete.
1870 drawQuad(mProgram, "position", 0.5f);
1871 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1872
1873 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1874 texDataGreen.data());
1875
1876 // Texture is now complete.
1877 drawQuad(mProgram, "position", 0.5f);
1878 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1879}
1880
Olli Etuahoa314b612016-03-10 16:43:00 +02001881// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1882// dimensions that don't fit the images inside the range.
1883// GLES 3.0.4 section 3.8.13 Texture completeness
1884TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1885{
1886 if (IsOSX())
1887 {
1888 // Observed incorrect rendering on OSX.
1889 std::cout << "Test skipped on OSX." << std::endl;
1890 return;
1891 }
1892 glActiveTexture(GL_TEXTURE0);
1893 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1894 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1895 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1896 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1897
1898 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1899 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1900
1901 // Two levels that are initially unused.
1902 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1903 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1904 texDataCyan.data());
1905
1906 // One level that is used - only this level should affect completeness.
1907 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1908 texDataGreen.data());
1909
1910 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1911 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1912
1913 EXPECT_GL_NO_ERROR();
1914
1915 drawQuad(mProgram, "position", 0.5f);
1916
1917 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1918
1919 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1920 {
1921 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
1922 // level was changed.
1923 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
1924 return;
1925 }
1926
1927 // Switch the level that is being used to the cyan level 2.
1928 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1929 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1930
1931 EXPECT_GL_NO_ERROR();
1932
1933 drawQuad(mProgram, "position", 0.5f);
1934
1935 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1936}
1937
1938// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1939// have images defined.
1940TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1941{
1942 if (IsOSX())
1943 {
1944 // Observed incorrect rendering on OSX.
1945 std::cout << "Test skipped on OSX." << std::endl;
1946 return;
1947 }
1948 glActiveTexture(GL_TEXTURE0);
1949 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1950 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1951 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1952 texDataGreen.data());
1953 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1954 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1955 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1956 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1957
1958 EXPECT_GL_NO_ERROR();
1959
1960 drawQuad(mProgram, "position", 0.5f);
1961
1962 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1963}
1964
1965// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1966// dimensions that don't fit the images inside the range.
1967// GLES 3.0.4 section 3.8.13 Texture completeness
1968TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1969{
1970 if (IsOSX())
1971 {
1972 // Observed incorrect rendering on OSX.
1973 std::cout << "Test skipped on OSX." << std::endl;
1974 return;
1975 }
1976 glActiveTexture(GL_TEXTURE0);
1977 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1978 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1979 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1980 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1981
1982 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1983 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1984
1985 // Two levels that are initially unused.
1986 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1987 texDataRed.data());
1988 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1989 texDataCyan.data());
1990
1991 // One level that is used - only this level should affect completeness.
1992 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1993 texDataGreen.data());
1994
1995 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1996 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1997
1998 EXPECT_GL_NO_ERROR();
1999
2000 drawQuad(mProgram, "position", 0.5f);
2001
2002 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2003
2004 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2005 {
2006 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
2007 // level was changed.
2008 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
2009 return;
2010 }
2011
2012 // Switch the level that is being used to the cyan level 2.
2013 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
2014 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
2015
2016 EXPECT_GL_NO_ERROR();
2017
2018 drawQuad(mProgram, "position", 0.5f);
2019
2020 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2021}
2022
2023// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2024// have images defined.
2025TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
2026{
2027 if (IsOSX())
2028 {
2029 // Observed incorrect rendering on OSX.
2030 std::cout << "Test skipped on OSX." << std::endl;
2031 return;
2032 }
2033 glActiveTexture(GL_TEXTURE0);
2034 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
2035 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2036 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2037 texDataGreen.data());
2038 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2039 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2040 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2041 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2042
2043 EXPECT_GL_NO_ERROR();
2044
2045 drawQuad(mProgram, "position", 0.5f);
2046
2047 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2048}
2049
2050// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2051// dimensions that don't fit the images inside the range.
2052// GLES 3.0.4 section 3.8.13 Texture completeness
2053TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2054{
2055 if (IsOSX())
2056 {
2057 // Observed incorrect rendering on OSX.
2058 std::cout << "Test skipped on OSX." << std::endl;
2059 return;
2060 }
2061 glActiveTexture(GL_TEXTURE0);
2062 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
2063 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2064 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2065 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2066
2067 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2068 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2069
2070 // Two levels that are initially unused.
2071 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2072 texDataRed.data());
2073 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2074 texDataCyan.data());
2075
2076 // One level that is used - only this level should affect completeness.
2077 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2078 texDataGreen.data());
2079
2080 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2081 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2082
2083 EXPECT_GL_NO_ERROR();
2084
2085 drawQuad(mProgram, "position", 0.5f);
2086
2087 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2088
2089 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2090 {
2091 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
2092 // level was changed.
2093 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
2094 return;
2095 }
2096 if (IsNVIDIA() && (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
2097 getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE))
2098 {
2099 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
2100 // level was changed.
2101 std::cout << "Test partially skipped on NVIDIA OpenGL." << std::endl;
2102 return;
2103 }
2104
2105 // Switch the level that is being used to the cyan level 2.
2106 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2107 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2108
2109 EXPECT_GL_NO_ERROR();
2110
2111 drawQuad(mProgram, "position", 0.5f);
2112
2113 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2114}
2115
2116// Test that texture completeness is updated if texture max level changes.
2117// GLES 3.0.4 section 3.8.13 Texture completeness
2118TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2119{
2120 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2121 {
2122 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2123 // the base level.
2124 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2125 return;
2126 }
2127 if (IsOSX())
2128 {
2129 // Observed incorrect rendering on OSX.
2130 std::cout << "Test skipped on OSX." << std::endl;
2131 return;
2132 }
2133
2134 glActiveTexture(GL_TEXTURE0);
2135 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2136 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2137
2138 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2139 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2140
2141 // A level that is initially unused.
2142 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2143 texDataGreen.data());
2144
2145 // One level that is initially used - only this level should affect completeness.
2146 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2147 texDataGreen.data());
2148
2149 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2150 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2151
2152 EXPECT_GL_NO_ERROR();
2153
2154 drawQuad(mProgram, "position", 0.5f);
2155
2156 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2157
2158 // Switch the max level to level 1. The levels within the used range now have inconsistent
2159 // dimensions and the texture should be incomplete.
2160 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2161
2162 EXPECT_GL_NO_ERROR();
2163
2164 drawQuad(mProgram, "position", 0.5f);
2165
2166 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2167}
2168
2169// Test that 3D texture completeness is updated if texture max level changes.
2170// GLES 3.0.4 section 3.8.13 Texture completeness
2171TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2172{
2173 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2174 {
2175 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2176 // the base level.
2177 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2178 return;
2179 }
2180 if (IsOSX())
2181 {
2182 // Observed incorrect rendering on OSX.
2183 std::cout << "Test skipped on OSX." << std::endl;
2184 return;
2185 }
2186
2187 glActiveTexture(GL_TEXTURE0);
2188 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2189 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2190
2191 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2192 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2193
2194 // A level that is initially unused.
2195 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2196 texDataGreen.data());
2197
2198 // One level that is initially used - only this level should affect completeness.
2199 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2200 texDataGreen.data());
2201
2202 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2203 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2204
2205 EXPECT_GL_NO_ERROR();
2206
2207 drawQuad(mProgram, "position", 0.5f);
2208
2209 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2210
2211 // Switch the max level to level 1. The levels within the used range now have inconsistent
2212 // dimensions and the texture should be incomplete.
2213 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2214
2215 EXPECT_GL_NO_ERROR();
2216
2217 drawQuad(mProgram, "position", 0.5f);
2218
2219 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2220}
2221
2222// Test that texture completeness is updated if texture base level changes.
2223// GLES 3.0.4 section 3.8.13 Texture completeness
2224TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2225{
2226 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2227 {
2228 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2229 // the base level.
2230 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2231 return;
2232 }
2233
2234 glActiveTexture(GL_TEXTURE0);
2235 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2236 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2237
2238 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2239 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2240
2241 // Two levels that are initially unused.
2242 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2243 texDataGreen.data());
2244 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2245 texDataGreen.data());
2246
2247 // One level that is initially used - only this level should affect completeness.
2248 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2249 texDataGreen.data());
2250
2251 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2252 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2253
2254 EXPECT_GL_NO_ERROR();
2255
2256 drawQuad(mProgram, "position", 0.5f);
2257
2258 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2259
2260 // Switch the base level to level 1. The levels within the used range now have inconsistent
2261 // dimensions and the texture should be incomplete.
2262 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2263
2264 EXPECT_GL_NO_ERROR();
2265
2266 drawQuad(mProgram, "position", 0.5f);
2267
2268 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2269}
2270
2271// Test that texture is not complete if base level is greater than max level.
2272// GLES 3.0.4 section 3.8.13 Texture completeness
2273TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2274{
2275 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2276 {
2277 // Intel Windows OpenGL driver crashes if the base level of a non-immutable texture is out
2278 // of range.
2279 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2280 return;
2281 }
2282
2283 glActiveTexture(GL_TEXTURE0);
2284 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2285
2286 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2287 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2288
2289 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2290
2291 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2292 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2293
2294 EXPECT_GL_NO_ERROR();
2295
2296 drawQuad(mProgram, "position", 0.5f);
2297
2298 // Texture should be incomplete.
2299 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2300}
2301
2302// Test that immutable texture base level and max level are clamped.
2303// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2304TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2305{
Olli Etuahoa314b612016-03-10 16:43:00 +02002306 glActiveTexture(GL_TEXTURE0);
2307 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2308
2309 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2310 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2311
2312 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2313
2314 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2315
2316 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2317 // should be clamped to [base_level, levels - 1].
2318 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2319 // In the case of this test, those rules make the effective base level and max level 0.
2320 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2321 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2322
2323 EXPECT_GL_NO_ERROR();
2324
2325 drawQuad(mProgram, "position", 0.5f);
2326
2327 // Texture should be complete.
2328 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2329}
2330
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002331// Test that changing base level works when it affects the format of the texture.
2332TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2333{
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002334 if (IsNVIDIA() && IsOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002335 {
2336 // Observed rendering corruption on NVIDIA OpenGL.
2337 std::cout << "Test skipped on NVIDIA OpenGL." << std::endl;
2338 return;
2339 }
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002340 if (IsIntel() && IsDesktopOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002341 {
2342 // Observed incorrect rendering on Intel OpenGL.
2343 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2344 return;
2345 }
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002346 if (IsAMD() && IsDesktopOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002347 {
2348 // Observed incorrect rendering on AMD OpenGL.
2349 std::cout << "Test skipped on AMD OpenGL." << std::endl;
2350 return;
2351 }
2352
2353 glActiveTexture(GL_TEXTURE0);
2354 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2355 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2356 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2357
2358 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2359 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2360
2361 // RGBA8 level that's initially unused.
2362 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2363 texDataCyan.data());
2364
2365 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2366 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2367
2368 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2369 // format. It reads green channel data from the green and alpha channels of texDataGreen
2370 // (this is a bit hacky but works).
2371 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2372
2373 EXPECT_GL_NO_ERROR();
2374
2375 drawQuad(mProgram, "position", 0.5f);
2376
2377 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2378
2379 // Switch the texture to use the cyan level 0 with the RGBA format.
2380 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2381 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2382
2383 EXPECT_GL_NO_ERROR();
2384
2385 drawQuad(mProgram, "position", 0.5f);
2386
2387 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2388}
2389
Olli Etuahoa314b612016-03-10 16:43:00 +02002390// Test that setting a texture image works when base level is out of range.
2391TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2392{
2393 glActiveTexture(GL_TEXTURE0);
2394 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2395
2396 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2397 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2398
2399 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2400 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2401
2402 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2403
2404 EXPECT_GL_NO_ERROR();
2405
2406 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2407
2408 drawQuad(mProgram, "position", 0.5f);
2409
2410 // Texture should be complete.
2411 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002412}
2413
Jamie Madill2453dbc2015-07-14 11:35:42 -04002414// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG RBA->RGBA8, with 1.0
2415// in the alpha channel. This test covers a bug where redefining array textures with these formats does not work as
2416// expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002417TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002418{
2419 std::vector<GLubyte> pixelData;
2420 for (size_t count = 0; count < 5000; count++)
2421 {
2422 pixelData.push_back(0u);
2423 pixelData.push_back(255u);
2424 pixelData.push_back(0u);
2425 }
2426
2427 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002428 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002429 glUniform1i(mTextureArrayLocation, 0);
2430
2431 // The first draw worked correctly.
2432 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
2433
2434 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2435 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2436 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2437 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002438 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002439 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002440
2441 // The dimension of the respecification must match the original exactly to trigger the bug.
2442 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 +02002443 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002444 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002445
2446 ASSERT_GL_NO_ERROR();
2447}
2448
Olli Etuaho1a679902016-01-14 12:21:47 +02002449// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2450// This test is needed especially to confirm that sampler registers get assigned correctly on
2451// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2452TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2453{
2454 glActiveTexture(GL_TEXTURE0);
2455 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2456 GLubyte texData[4];
2457 texData[0] = 0;
2458 texData[1] = 60;
2459 texData[2] = 0;
2460 texData[3] = 255;
2461 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2462
2463 glActiveTexture(GL_TEXTURE1);
2464 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2465 GLfloat depthTexData[1];
2466 depthTexData[0] = 0.5f;
2467 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2468 depthTexData);
2469
2470 glUseProgram(mProgram);
2471 glUniform1f(mDepthRefUniformLocation, 0.3f);
2472 glUniform1i(mTexture3DUniformLocation, 0);
2473 glUniform1i(mTextureShadowUniformLocation, 1);
2474
2475 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2476 drawQuad(mProgram, "position", 0.5f);
2477 EXPECT_GL_NO_ERROR();
2478 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2479 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2480
2481 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2482 drawQuad(mProgram, "position", 0.5f);
2483 EXPECT_GL_NO_ERROR();
2484 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2485 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2486}
2487
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002488// Test multiple different sampler types in the same shader.
2489// This test makes sure that even if sampler / texture registers get grouped together based on type
2490// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2491// still has the right register index information for each ESSL sampler.
2492// The tested ESSL samplers have the following types in D3D11 HLSL:
2493// sampler2D: Texture2D + SamplerState
2494// samplerCube: TextureCube + SamplerState
2495// sampler2DShadow: Texture2D + SamplerComparisonState
2496// samplerCubeShadow: TextureCube + SamplerComparisonState
2497TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2498{
2499 glActiveTexture(GL_TEXTURE0);
2500 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2501 GLubyte texData[4];
2502 texData[0] = 0;
2503 texData[1] = 0;
2504 texData[2] = 120;
2505 texData[3] = 255;
2506 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2507
2508 glActiveTexture(GL_TEXTURE1);
2509 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2510 texData[0] = 0;
2511 texData[1] = 90;
2512 texData[2] = 0;
2513 texData[3] = 255;
2514 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2515 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2516 texData);
2517
2518 glActiveTexture(GL_TEXTURE2);
2519 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2520 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2521 GLfloat depthTexData[1];
2522 depthTexData[0] = 0.5f;
2523 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2524 depthTexData);
2525
2526 glActiveTexture(GL_TEXTURE3);
2527 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2528 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2529 depthTexData[0] = 0.2f;
2530 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2531 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2532 depthTexData);
2533
2534 EXPECT_GL_NO_ERROR();
2535
2536 glUseProgram(mProgram);
2537 glUniform1f(mDepthRefUniformLocation, 0.3f);
2538 glUniform1i(mTexture2DUniformLocation, 0);
2539 glUniform1i(mTextureCubeUniformLocation, 1);
2540 glUniform1i(mTexture2DShadowUniformLocation, 2);
2541 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2542
2543 drawQuad(mProgram, "position", 0.5f);
2544 EXPECT_GL_NO_ERROR();
2545 // The shader writes:
2546 // <texture 2d color> +
2547 // <cube map color> +
2548 // 0.25 * <comparison result (1.0)> +
2549 // 0.125 * <comparison result (0.0)>
2550 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2551}
2552
Olli Etuahobce743a2016-01-15 17:18:28 +02002553// Test different base levels on textures accessed through the same sampler array.
2554// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2555TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2556{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002557 if ((IsAMD() || IsIntel()) && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
Olli Etuahobce743a2016-01-15 17:18:28 +02002558 {
2559 std::cout << "Test skipped on Intel and AMD D3D." << std::endl;
2560 return;
2561 }
2562 glActiveTexture(GL_TEXTURE0);
2563 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2564 GLsizei size = 64;
2565 for (GLint level = 0; level < 7; ++level)
2566 {
2567 ASSERT_LT(0, size);
2568 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2569 nullptr);
2570 size = size / 2;
2571 }
2572 ASSERT_EQ(0, size);
2573 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2574
2575 glActiveTexture(GL_TEXTURE1);
2576 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2577 size = 128;
2578 for (GLint level = 0; level < 8; ++level)
2579 {
2580 ASSERT_LT(0, size);
2581 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2582 nullptr);
2583 size = size / 2;
2584 }
2585 ASSERT_EQ(0, size);
2586 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2587 EXPECT_GL_NO_ERROR();
2588
2589 glUseProgram(mProgram);
2590 glUniform1i(mTexture0Location, 0);
2591 glUniform1i(mTexture1Location, 1);
2592
2593 drawQuad(mProgram, "position", 0.5f);
2594 EXPECT_GL_NO_ERROR();
2595 // Red channel: width of level 1 of texture A: 32.
2596 // Green channel: width of level 3 of texture B: 16.
2597 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2598}
2599
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002600// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2601// ES 3.0.4 table 3.24
2602TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2603{
2604 glActiveTexture(GL_TEXTURE0);
2605 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2606 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2607 EXPECT_GL_NO_ERROR();
2608
2609 drawQuad(mProgram, "position", 0.5f);
2610
2611 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2612}
2613
2614// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2615// ES 3.0.4 table 3.24
2616TEST_P(Texture2DTestES3, TextureLuminanceImplicitAlpha1)
2617{
2618 glActiveTexture(GL_TEXTURE0);
2619 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2620 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2621 EXPECT_GL_NO_ERROR();
2622
2623 drawQuad(mProgram, "position", 0.5f);
2624
2625 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2626}
2627
2628// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2629// ES 3.0.4 table 3.24
2630TEST_P(Texture2DTestES3, TextureLuminance32ImplicitAlpha1)
2631{
2632 if (extensionEnabled("GL_OES_texture_float"))
2633 {
2634 glActiveTexture(GL_TEXTURE0);
2635 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2636 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2637 EXPECT_GL_NO_ERROR();
2638
2639 drawQuad(mProgram, "position", 0.5f);
2640
2641 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2642 }
2643}
2644
2645// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2646// ES 3.0.4 table 3.24
2647TEST_P(Texture2DTestES3, TextureLuminance16ImplicitAlpha1)
2648{
2649 if (extensionEnabled("GL_OES_texture_half_float"))
2650 {
Yuly Novikovafcec832016-06-21 22:19:51 -04002651 if (IsNVIDIA() && IsOpenGLES())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002652 {
2653 std::cout << "Test skipped on NVIDIA" << std::endl;
2654 return;
2655 }
Yuly Novikovafcec832016-06-21 22:19:51 -04002656 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2657 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2658 {
2659 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2660 return;
2661 }
2662
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002663 glActiveTexture(GL_TEXTURE0);
2664 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2665 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES,
2666 nullptr);
2667 EXPECT_GL_NO_ERROR();
2668
2669 drawQuad(mProgram, "position", 0.5f);
2670
2671 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2672 }
2673}
2674
2675// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2676// ES 3.0.4 table 3.24
2677TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2678{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002679 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002680 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002681 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002682 return;
2683 }
2684 glActiveTexture(GL_TEXTURE0);
2685 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2686 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_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(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
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
2708 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2709 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2710 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2711 EXPECT_GL_NO_ERROR();
2712
2713 drawQuad(mProgram, "position", 0.5f);
2714
2715 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2716}
2717
2718// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2719// ES 3.0.4 table 3.24
2720TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2721{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002722 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002723 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002724 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002725 return;
2726 }
2727 glActiveTexture(GL_TEXTURE0);
2728 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2729 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2730 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2731 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2732 EXPECT_GL_NO_ERROR();
2733
2734 drawQuad(mProgram, "position", 0.5f);
2735
2736 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2737}
2738
2739// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2740// ES 3.0.4 table 3.24
2741TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2742{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002743 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002744 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002745 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002746 return;
2747 }
2748 glActiveTexture(GL_TEXTURE0);
2749 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2750 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2751 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2752 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2753 EXPECT_GL_NO_ERROR();
2754
2755 drawQuad(mProgram, "position", 0.5f);
2756
2757 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2758}
2759
2760// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2761// ES 3.0.4 table 3.24
2762TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2763{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002764 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002765 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002766 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002767 return;
2768 }
2769 glActiveTexture(GL_TEXTURE0);
2770 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2771 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2772 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2773 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2774 EXPECT_GL_NO_ERROR();
2775
2776 drawQuad(mProgram, "position", 0.5f);
2777
2778 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2779}
2780
2781// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2782// ES 3.0.4 table 3.24
2783TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2784{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002785 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002786 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002787 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002788 return;
2789 }
2790 glActiveTexture(GL_TEXTURE0);
2791 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2792 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2793 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2794 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2795 EXPECT_GL_NO_ERROR();
2796
2797 drawQuad(mProgram, "position", 0.5f);
2798
2799 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2800}
2801
2802// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2803// ES 3.0.4 table 3.24
2804TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2805{
2806 glActiveTexture(GL_TEXTURE0);
2807 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2808 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2809 EXPECT_GL_NO_ERROR();
2810
2811 drawQuad(mProgram, "position", 0.5f);
2812
2813 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2814}
2815
2816// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2817// ES 3.0.4 table 3.24
2818TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2819{
2820 glActiveTexture(GL_TEXTURE0);
2821 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2822 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2823 nullptr);
2824 EXPECT_GL_NO_ERROR();
2825
2826 drawQuad(mProgram, "position", 0.5f);
2827
2828 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2829}
2830
2831// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2832// ES 3.0.4 table 3.24
2833TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2834{
Jamie Madillbb1db482017-01-10 10:48:32 -05002835 if (IsOSX() && IsIntel() && IsOpenGL())
2836 {
2837 // Seems to fail on OSX 10.12 Intel.
2838 std::cout << "Test skipped on OSX Intel." << std::endl;
2839 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_RGB8_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
2852// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2853// ES 3.0.4 table 3.24
2854TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2855{
Jamie Madillbb1db482017-01-10 10:48:32 -05002856 if (IsIntel() && IsOpenGL() && (IsLinux() || IsOSX()))
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002857 {
2858 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
Jamie Madillbb1db482017-01-10 10:48:32 -05002859 // Also seems to fail on OSX 10.12 Intel.
2860 std::cout << "Test disabled on Linux and OSX Intel OpenGL." << std::endl;
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002861 return;
2862 }
2863
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002864 glActiveTexture(GL_TEXTURE0);
2865 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2866 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2867 EXPECT_GL_NO_ERROR();
2868
2869 drawQuad(mProgram, "position", 0.5f);
2870
2871 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2872}
2873
Olli Etuaho96963162016-03-21 11:54:33 +02002874// Use a sampler in a uniform struct.
2875TEST_P(SamplerInStructTest, SamplerInStruct)
2876{
2877 runSamplerInStructTest();
2878}
2879
2880// Use a sampler in a uniform struct that's passed as a function parameter.
2881TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2882{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002883 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2884 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2885 {
2886 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2887 return;
2888 }
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002889
2890 if (IsWindows() && IsIntel() && IsOpenGL())
2891 {
2892 std::cout << "Test skipped on Windows OpenGL on Intel." << std::endl;
2893 return;
2894 }
2895
Olli Etuaho96963162016-03-21 11:54:33 +02002896 runSamplerInStructTest();
2897}
2898
2899// Use a sampler in a uniform struct array with a struct from the array passed as a function
2900// parameter.
2901TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2902{
Olli Etuahoa1c917f2016-04-06 13:50:03 +03002903 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2904 {
2905 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2906 return;
2907 }
Yuly Novikovad6c0452016-06-24 22:24:37 -04002908 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2909 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2910 {
2911 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2912 return;
2913 }
Olli Etuaho96963162016-03-21 11:54:33 +02002914 runSamplerInStructTest();
2915}
2916
2917// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2918// parameter.
2919TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2920{
Olli Etuahoa1c917f2016-04-06 13:50:03 +03002921 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2922 {
2923 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2924 return;
2925 }
Yuly Novikovad6c0452016-06-24 22:24:37 -04002926 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2927 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2928 {
2929 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2930 return;
2931 }
Olli Etuaho96963162016-03-21 11:54:33 +02002932 runSamplerInStructTest();
2933}
2934
2935// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2936// similarly named uniform.
2937TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2938{
2939 runSamplerInStructTest();
2940}
2941
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002942class TextureLimitsTest : public ANGLETest
2943{
2944 protected:
2945 struct RGBA8
2946 {
2947 uint8_t R, G, B, A;
2948 };
2949
2950 TextureLimitsTest()
2951 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
2952 {
2953 setWindowWidth(128);
2954 setWindowHeight(128);
2955 setConfigRedBits(8);
2956 setConfigGreenBits(8);
2957 setConfigBlueBits(8);
2958 setConfigAlphaBits(8);
2959 }
2960
2961 ~TextureLimitsTest()
2962 {
2963 if (mProgram != 0)
2964 {
2965 glDeleteProgram(mProgram);
2966 mProgram = 0;
2967
2968 if (!mTextures.empty())
2969 {
2970 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
2971 }
2972 }
2973 }
2974
2975 void SetUp() override
2976 {
2977 ANGLETest::SetUp();
2978
2979 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
2980 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
2981 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
2982
2983 ASSERT_GL_NO_ERROR();
2984 }
2985
2986 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
2987 GLint vertexTextureCount,
2988 GLint vertexActiveTextureCount,
2989 const std::string &fragPrefix,
2990 GLint fragmentTextureCount,
2991 GLint fragmentActiveTextureCount)
2992 {
2993 std::stringstream vertexShaderStr;
2994 vertexShaderStr << "attribute vec2 position;\n"
2995 << "varying vec4 color;\n"
2996 << "varying vec2 texCoord;\n";
2997
2998 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
2999 {
3000 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
3001 }
3002
3003 vertexShaderStr << "void main() {\n"
3004 << " gl_Position = vec4(position, 0, 1);\n"
3005 << " texCoord = (position * 0.5) + 0.5;\n"
3006 << " color = vec4(0);\n";
3007
3008 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
3009 {
3010 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
3011 << ", texCoord);\n";
3012 }
3013
3014 vertexShaderStr << "}";
3015
3016 std::stringstream fragmentShaderStr;
3017 fragmentShaderStr << "varying mediump vec4 color;\n"
3018 << "varying mediump vec2 texCoord;\n";
3019
3020 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
3021 {
3022 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
3023 }
3024
3025 fragmentShaderStr << "void main() {\n"
3026 << " gl_FragColor = color;\n";
3027
3028 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
3029 {
3030 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
3031 << ", texCoord);\n";
3032 }
3033
3034 fragmentShaderStr << "}";
3035
3036 const std::string &vertexShaderSource = vertexShaderStr.str();
3037 const std::string &fragmentShaderSource = fragmentShaderStr.str();
3038
3039 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
3040 }
3041
3042 RGBA8 getPixel(GLint texIndex)
3043 {
3044 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3045 0, 255u};
3046 return pixel;
3047 }
3048
3049 void initTextures(GLint tex2DCount, GLint texCubeCount)
3050 {
3051 GLint totalCount = tex2DCount + texCubeCount;
3052 mTextures.assign(totalCount, 0);
3053 glGenTextures(totalCount, &mTextures[0]);
3054 ASSERT_GL_NO_ERROR();
3055
3056 std::vector<RGBA8> texData(16 * 16);
3057
3058 GLint texIndex = 0;
3059 for (; texIndex < tex2DCount; ++texIndex)
3060 {
3061 texData.assign(texData.size(), getPixel(texIndex));
3062 glActiveTexture(GL_TEXTURE0 + texIndex);
3063 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3064 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3065 &texData[0]);
3066 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3067 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3068 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3069 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3070 }
3071
3072 ASSERT_GL_NO_ERROR();
3073
3074 for (; texIndex < texCubeCount; ++texIndex)
3075 {
3076 texData.assign(texData.size(), getPixel(texIndex));
3077 glActiveTexture(GL_TEXTURE0 + texIndex);
3078 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3079 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3080 GL_UNSIGNED_BYTE, &texData[0]);
3081 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3082 GL_UNSIGNED_BYTE, &texData[0]);
3083 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3084 GL_UNSIGNED_BYTE, &texData[0]);
3085 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3086 GL_UNSIGNED_BYTE, &texData[0]);
3087 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3088 GL_UNSIGNED_BYTE, &texData[0]);
3089 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3090 GL_UNSIGNED_BYTE, &texData[0]);
3091 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3092 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3093 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3094 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3095 }
3096
3097 ASSERT_GL_NO_ERROR();
3098 }
3099
3100 void testWithTextures(GLint vertexTextureCount,
3101 const std::string &vertexTexturePrefix,
3102 GLint fragmentTextureCount,
3103 const std::string &fragmentTexturePrefix)
3104 {
3105 // Generate textures
3106 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3107
3108 glUseProgram(mProgram);
3109 RGBA8 expectedSum = {0};
3110 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3111 {
3112 std::stringstream uniformNameStr;
3113 uniformNameStr << vertexTexturePrefix << texIndex;
3114 const std::string &uniformName = uniformNameStr.str();
3115 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
3116 ASSERT_NE(-1, location);
3117
3118 glUniform1i(location, texIndex);
3119 RGBA8 contribution = getPixel(texIndex);
3120 expectedSum.R += contribution.R;
3121 expectedSum.G += contribution.G;
3122 }
3123
3124 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3125 {
3126 std::stringstream uniformNameStr;
3127 uniformNameStr << fragmentTexturePrefix << texIndex;
3128 const std::string &uniformName = uniformNameStr.str();
3129 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
3130 ASSERT_NE(-1, location);
3131
3132 glUniform1i(location, texIndex + vertexTextureCount);
3133 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3134 expectedSum.R += contribution.R;
3135 expectedSum.G += contribution.G;
3136 }
3137
3138 ASSERT_GE(256u, expectedSum.G);
3139
3140 drawQuad(mProgram, "position", 0.5f);
3141 ASSERT_GL_NO_ERROR();
3142 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3143 }
3144
3145 GLuint mProgram;
3146 std::vector<GLuint> mTextures;
3147 GLint mMaxVertexTextures;
3148 GLint mMaxFragmentTextures;
3149 GLint mMaxCombinedTextures;
3150};
3151
3152// Test rendering with the maximum vertex texture units.
3153TEST_P(TextureLimitsTest, MaxVertexTextures)
3154{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003155 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003156 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003157 {
3158 std::cout << "Test skipped on Intel." << std::endl;
3159 return;
3160 }
3161
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003162 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3163 ASSERT_NE(0u, mProgram);
3164 ASSERT_GL_NO_ERROR();
3165
3166 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3167}
3168
3169// Test rendering with the maximum fragment texture units.
3170TEST_P(TextureLimitsTest, MaxFragmentTextures)
3171{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003172 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003173 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003174 {
3175 std::cout << "Test skipped on Intel." << std::endl;
3176 return;
3177 }
3178
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003179 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3180 ASSERT_NE(0u, mProgram);
3181 ASSERT_GL_NO_ERROR();
3182
3183 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3184}
3185
3186// Test rendering with maximum combined texture units.
3187TEST_P(TextureLimitsTest, MaxCombinedTextures)
3188{
Jamie Madill412f17d2015-09-25 08:43:54 -04003189 // TODO(jmadill): Investigate workaround.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003190 if (IsIntel() && GetParam() == ES2_OPENGL())
Jamie Madill412f17d2015-09-25 08:43:54 -04003191 {
3192 std::cout << "Test skipped on Intel." << std::endl;
3193 return;
3194 }
3195
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003196 GLint vertexTextures = mMaxVertexTextures;
3197
3198 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3199 {
3200 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3201 }
3202
3203 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3204 mMaxFragmentTextures, mMaxFragmentTextures);
3205 ASSERT_NE(0u, mProgram);
3206 ASSERT_GL_NO_ERROR();
3207
3208 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3209}
3210
3211// Negative test for exceeding the number of vertex textures
3212TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3213{
3214 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3215 0);
3216 ASSERT_EQ(0u, mProgram);
3217}
3218
3219// Negative test for exceeding the number of fragment textures
3220TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3221{
3222 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3223 mMaxFragmentTextures + 1);
3224 ASSERT_EQ(0u, mProgram);
3225}
3226
3227// Test active vertex textures under the limit, but excessive textures specified.
3228TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3229{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003230 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003231 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003232 {
3233 std::cout << "Test skipped on Intel." << std::endl;
3234 return;
3235 }
3236
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003237 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3238 ASSERT_NE(0u, mProgram);
3239 ASSERT_GL_NO_ERROR();
3240
3241 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3242}
3243
3244// Test active fragment textures under the limit, but excessive textures specified.
3245TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3246{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003247 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003248 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003249 {
3250 std::cout << "Test skipped on Intel." << std::endl;
3251 return;
3252 }
3253
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003254 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3255 mMaxFragmentTextures);
3256 ASSERT_NE(0u, mProgram);
3257 ASSERT_GL_NO_ERROR();
3258
3259 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3260}
3261
3262// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003263// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003264TEST_P(TextureLimitsTest, TextureTypeConflict)
3265{
3266 const std::string &vertexShader =
3267 "attribute vec2 position;\n"
3268 "varying float color;\n"
3269 "uniform sampler2D tex2D;\n"
3270 "uniform samplerCube texCube;\n"
3271 "void main() {\n"
3272 " gl_Position = vec4(position, 0, 1);\n"
3273 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3274 " color = texture2D(tex2D, texCoord).x;\n"
3275 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3276 "}";
3277 const std::string &fragmentShader =
3278 "varying mediump float color;\n"
3279 "void main() {\n"
3280 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3281 "}";
3282
3283 mProgram = CompileProgram(vertexShader, fragmentShader);
3284 ASSERT_NE(0u, mProgram);
3285
3286 initTextures(1, 0);
3287
3288 glUseProgram(mProgram);
3289 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3290 ASSERT_NE(-1, tex2DLocation);
3291 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3292 ASSERT_NE(-1, texCubeLocation);
3293
3294 glUniform1i(tex2DLocation, 0);
3295 glUniform1i(texCubeLocation, 0);
3296 ASSERT_GL_NO_ERROR();
3297
3298 drawQuad(mProgram, "position", 0.5f);
3299 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3300}
3301
Vincent Lang25ab4512016-05-13 18:13:59 +02003302class Texture2DNorm16TestES3 : public Texture2DTestES3
3303{
3304 protected:
3305 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3306
3307 void SetUp() override
3308 {
3309 Texture2DTestES3::SetUp();
3310
3311 glActiveTexture(GL_TEXTURE0);
3312 glGenTextures(3, mTextures);
3313 glGenFramebuffers(1, &mFBO);
3314 glGenRenderbuffers(1, &mRenderbuffer);
3315
3316 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3317 {
3318 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3319 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3320 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3321 }
3322
3323 glBindTexture(GL_TEXTURE_2D, 0);
3324
3325 ASSERT_GL_NO_ERROR();
3326 }
3327
3328 void TearDown() override
3329 {
3330 glDeleteTextures(3, mTextures);
3331 glDeleteFramebuffers(1, &mFBO);
3332 glDeleteRenderbuffers(1, &mRenderbuffer);
3333
3334 Texture2DTestES3::TearDown();
3335 }
3336
3337 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3338 {
Geoff Langf607c602016-09-21 11:46:48 -04003339 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3340 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003341
3342 setUpProgram();
3343
3344 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3345 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3346 0);
3347
3348 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3349 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3350
3351 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003352 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003353
3354 EXPECT_GL_NO_ERROR();
3355
3356 drawQuad(mProgram, "position", 0.5f);
3357
Geoff Langf607c602016-09-21 11:46:48 -04003358 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003359
Geoff Langf607c602016-09-21 11:46:48 -04003360 EXPECT_PIXEL_COLOR_EQ(
3361 0, 0, SliceFormatColor(
3362 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003363
3364 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3365
3366 ASSERT_GL_NO_ERROR();
3367 }
3368
3369 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3370 {
3371 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003372 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003373
3374 setUpProgram();
3375
3376 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3377 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3378
3379 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3380 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3381 0);
3382
3383 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003384 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003385
3386 EXPECT_GL_NO_ERROR();
3387
3388 drawQuad(mProgram, "position", 0.5f);
3389
Geoff Langf607c602016-09-21 11:46:48 -04003390 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
3391 EXPECT_PIXEL_COLOR_EQ(
3392 0, 0, SliceFormatColor(
3393 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003394
3395 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3396 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3397 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3398 mRenderbuffer);
3399 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3400 EXPECT_GL_NO_ERROR();
3401
3402 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3403 glClear(GL_COLOR_BUFFER_BIT);
3404
3405 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3406
Geoff Langf607c602016-09-21 11:46:48 -04003407 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003408
3409 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3410
3411 ASSERT_GL_NO_ERROR();
3412 }
3413
3414 GLuint mTextures[3];
3415 GLuint mFBO;
3416 GLuint mRenderbuffer;
3417};
3418
3419// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3420TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3421{
3422 if (!extensionEnabled("GL_EXT_texture_norm16"))
3423 {
3424 std::cout << "Test skipped due to missing GL_EXT_texture_norm16." << std::endl;
3425 return;
3426 }
3427
3428 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3429 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3430 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3431 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3432 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3433 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3434 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3435 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3436
3437 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3438 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3439 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3440}
3441
Olli Etuaho95faa232016-06-07 14:01:53 -07003442// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3443// GLES 3.0.4 section 3.8.3.
3444TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3445{
Corentin Wallezc7f59d02016-06-20 10:12:08 -04003446 if (IsIntel() && IsDesktopOpenGL())
Olli Etuaho95faa232016-06-07 14:01:53 -07003447 {
3448 std::cout << "Test skipped on Intel OpenGL." << std::endl;
3449 return;
3450 }
Yuly Novikov3c754192016-06-27 19:36:41 -04003451 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1429 is fixed
3452 if (IsAndroid() && IsAdreno() && IsOpenGLES())
3453 {
3454 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
3455 return;
3456 }
Olli Etuaho95faa232016-06-07 14:01:53 -07003457
3458 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3459 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3460 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3461 ASSERT_GL_NO_ERROR();
3462
3463 // SKIP_IMAGES should not have an effect on uploading 2D textures
3464 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3465 ASSERT_GL_NO_ERROR();
3466
3467 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3468
3469 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3470 pixelsGreen.data());
3471 ASSERT_GL_NO_ERROR();
3472
3473 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3474 pixelsGreen.data());
3475 ASSERT_GL_NO_ERROR();
3476
3477 glUseProgram(mProgram);
3478 drawQuad(mProgram, "position", 0.5f);
3479 ASSERT_GL_NO_ERROR();
3480
3481 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3482}
3483
Olli Etuaho989cac32016-06-08 16:18:49 -07003484// Test that skip defined in unpack parameters is taken into account when determining whether
3485// unpacking source extends outside unpack buffer bounds.
3486TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3487{
3488 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3489 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3490 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3491 ASSERT_GL_NO_ERROR();
3492
3493 GLBuffer buf;
3494 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3495 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3496 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3497 GL_DYNAMIC_COPY);
3498 ASSERT_GL_NO_ERROR();
3499
3500 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3501 ASSERT_GL_NO_ERROR();
3502
3503 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3504 ASSERT_GL_NO_ERROR();
3505
3506 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3507 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3508
3509 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3510 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3511 ASSERT_GL_NO_ERROR();
3512
3513 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3514 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3515}
3516
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003517// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3518TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3519{
3520 if (IsD3D11())
3521 {
3522 std::cout << "Test skipped on D3D." << std::endl;
3523 return;
3524 }
3525 if (IsOSX() && IsAMD())
3526 {
3527 // Incorrect rendering results seen on OSX AMD.
3528 std::cout << "Test skipped on OSX AMD." << std::endl;
3529 return;
3530 }
3531
3532 const GLuint width = 8u;
3533 const GLuint height = 8u;
3534 const GLuint unpackRowLength = 5u;
3535 const GLuint unpackSkipPixels = 1u;
3536
3537 setWindowWidth(width);
3538 setWindowHeight(height);
3539
3540 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3541 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3542 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3543 ASSERT_GL_NO_ERROR();
3544
3545 GLBuffer buf;
3546 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3547 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3548 GLColor::green);
3549
3550 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3551 {
3552 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3553 }
3554
3555 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3556 GL_DYNAMIC_COPY);
3557 ASSERT_GL_NO_ERROR();
3558
3559 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3560 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3561 ASSERT_GL_NO_ERROR();
3562
3563 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3564 ASSERT_GL_NO_ERROR();
3565
3566 glUseProgram(mProgram);
3567 drawQuad(mProgram, "position", 0.5f);
3568 ASSERT_GL_NO_ERROR();
3569
3570 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3571 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3572 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3573 actual.data());
3574 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3575 EXPECT_EQ(expected, actual);
3576}
3577
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003578template <typename T>
3579T UNorm(double value)
3580{
3581 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3582}
3583
3584// Test rendering a depth texture with mipmaps.
3585TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3586{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003587 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3588 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
3589 // http://anglebugs.com/1706
3590 if (IsIntel() && IsWindows())
Corentin Walleze731d8a2016-09-07 10:56:25 -04003591 {
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003592 std::cout << "Test skipped on Win Intel." << std::endl;
Corentin Walleze731d8a2016-09-07 10:56:25 -04003593 return;
3594 }
3595
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003596 const int size = getWindowWidth();
3597
3598 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003599 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003600
3601 glActiveTexture(GL_TEXTURE0);
3602 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3603 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3604 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3605 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3606 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3607 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3608 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3609 ASSERT_GL_NO_ERROR();
3610
3611 glUseProgram(mProgram);
3612 glUniform1i(mTexture2DUniformLocation, 0);
3613
3614 std::vector<unsigned char> expected;
3615
3616 for (int level = 0; level < levels; ++level)
3617 {
3618 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3619 expected.push_back(UNorm<unsigned char>(value));
3620
3621 int levelDim = dim(level);
3622
3623 ASSERT_GT(levelDim, 0);
3624
3625 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3626 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3627 GL_UNSIGNED_INT, initData.data());
3628 }
3629 ASSERT_GL_NO_ERROR();
3630
3631 for (int level = 0; level < levels; ++level)
3632 {
3633 glViewport(0, 0, dim(level), dim(level));
3634 drawQuad(mProgram, "position", 0.5f);
3635 GLColor actual = ReadColor(0, 0);
3636 EXPECT_NEAR(expected[level], actual.R, 10u);
3637 }
3638
3639 ASSERT_GL_NO_ERROR();
3640}
3641
Jamie Madill7ffdda92016-09-08 13:26:51 -04003642// Tests unpacking into the unsized GL_ALPHA format.
3643TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3644{
3645 // TODO(jmadill): Figure out why this fails on OSX.
3646 ANGLE_SKIP_TEST_IF(IsOSX());
3647
3648 // Initialize the texure.
3649 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3650 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3651 GL_UNSIGNED_BYTE, nullptr);
3652 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3653 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3654
3655 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3656
3657 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04003658 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04003659 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3660 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3661 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
3662 GL_STATIC_DRAW);
3663
3664 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
3665 GL_UNSIGNED_BYTE, nullptr);
3666
3667 // Clear to a weird color to make sure we're drawing something.
3668 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
3669 glClear(GL_COLOR_BUFFER_BIT);
3670
3671 // Draw with the alpha texture and verify.
3672 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04003673
3674 ASSERT_GL_NO_ERROR();
3675 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
3676}
3677
Jamie Madill2e600342016-09-19 13:56:40 -04003678// Ensure stale unpack data doesn't propagate in D3D11.
3679TEST_P(Texture2DTestES3, StaleUnpackData)
3680{
3681 // Init unpack buffer.
3682 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
3683 std::vector<GLColor> pixels(pixelCount, GLColor::red);
3684
3685 GLBuffer unpackBuffer;
3686 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3687 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3688 GLsizei bufferSize = pixelCount * sizeof(GLColor);
3689 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
3690
3691 // Create from unpack buffer.
3692 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3693 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
3694 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3695 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3696 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3697
3698 drawQuad(mProgram, "position", 0.5f);
3699
3700 ASSERT_GL_NO_ERROR();
3701 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3702
3703 // Fill unpack with green, recreating buffer.
3704 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
3705 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
3706 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
3707
3708 // Reinit texture with green.
3709 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
3710 GL_UNSIGNED_BYTE, nullptr);
3711
3712 drawQuad(mProgram, "position", 0.5f);
3713
3714 ASSERT_GL_NO_ERROR();
3715 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3716}
3717
Jamie Madillf097e232016-11-05 00:44:15 -04003718// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
3719// being properly checked, and the texture storage of the previous texture format was persisting.
3720// This would result in an ASSERT in debug and incorrect rendering in release.
3721// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
3722TEST_P(Texture3DTestES3, FormatRedefinitionBug)
3723{
3724 GLTexture tex;
3725 glBindTexture(GL_TEXTURE_3D, tex.get());
3726 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3727
3728 GLFramebuffer framebuffer;
3729 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3730 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
3731
3732 glCheckFramebufferStatus(GL_FRAMEBUFFER);
3733
3734 std::vector<uint8_t> pixelData(100, 0);
3735
3736 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
3737 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
3738 pixelData.data());
3739
3740 ASSERT_GL_NO_ERROR();
3741}
3742
Corentin Wallezd2627992017-04-28 17:17:03 -04003743// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
3744TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
3745{
3746 // 2D tests
3747 {
3748 GLTexture tex;
3749 glBindTexture(GL_TEXTURE_2D, tex.get());
3750
3751 GLBuffer pbo;
3752 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3753
3754 // Test OOB
3755 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
3756 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3757 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3758
3759 // Test OOB
3760 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
3761 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3762 ASSERT_GL_NO_ERROR();
3763 }
3764
3765 // 3D tests
3766 {
3767 GLTexture tex;
3768 glBindTexture(GL_TEXTURE_3D, tex.get());
3769
3770 GLBuffer pbo;
3771 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3772
3773 // Test OOB
3774 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
3775 GL_STATIC_DRAW);
3776 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3777 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3778
3779 // Test OOB
3780 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
3781 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3782 ASSERT_GL_NO_ERROR();
3783 }
3784}
3785
Jamie Madill3ed60422017-09-07 11:32:52 -04003786// Tests behaviour with a single texture and multiple sampler objects.
3787TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
3788{
3789 GLint maxTextureUnits = 0;
3790 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
3791 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
3792
3793 constexpr int kSize = 16;
3794
3795 // Make a single-level texture, fill it with red.
3796 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
3797 GLTexture tex;
3798 glBindTexture(GL_TEXTURE_2D, tex);
3799 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3800 redColors.data());
3801 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3802 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3803
3804 // Simple sanity check.
3805 draw2DTexturedQuad(0.5f, 1.0f, true);
3806 ASSERT_GL_NO_ERROR();
3807 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3808
3809 // Bind texture to unit 1 with a sampler object making it incomplete.
3810 GLSampler sampler;
3811 glBindSampler(0, sampler);
3812 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3813 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3814
3815 // Make a mipmap texture, fill it with blue.
3816 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
3817 GLTexture mipmapTex;
3818 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3819 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3820 blueColors.data());
3821 glGenerateMipmap(GL_TEXTURE_2D);
3822
3823 // Draw with the sampler, expect blue.
3824 draw2DTexturedQuad(0.5f, 1.0f, true);
3825 ASSERT_GL_NO_ERROR();
3826 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
3827
3828 // Simple multitexturing program.
3829 const std::string vs =
3830 "#version 300 es\n"
3831 "in vec2 position;\n"
3832 "out vec2 texCoord;\n"
3833 "void main()\n"
3834 "{\n"
3835 " gl_Position = vec4(position, 0, 1);\n"
3836 " texCoord = position * 0.5 + vec2(0.5);\n"
3837 "}";
3838 const std::string fs =
3839 "#version 300 es\n"
3840 "precision mediump float;\n"
3841 "in vec2 texCoord;\n"
3842 "uniform sampler2D tex1;\n"
3843 "uniform sampler2D tex2;\n"
3844 "uniform sampler2D tex3;\n"
3845 "uniform sampler2D tex4;\n"
3846 "out vec4 color;\n"
3847 "void main()\n"
3848 "{\n"
3849 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
3850 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
3851 "}";
3852
3853 ANGLE_GL_PROGRAM(program, vs, fs);
3854
3855 std::array<GLint, 4> texLocations = {
3856 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
3857 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
3858 for (GLint location : texLocations)
3859 {
3860 ASSERT_NE(-1, location);
3861 }
3862
3863 // Init the uniform data.
3864 glUseProgram(program);
3865 for (GLint location = 0; location < 4; ++location)
3866 {
3867 glUniform1i(texLocations[location], location);
3868 }
3869
3870 // Initialize four samplers
3871 GLSampler samplers[4];
3872
3873 // 0: non-mipped.
3874 glBindSampler(0, samplers[0]);
3875 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3876 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3877
3878 // 1: mipped.
3879 glBindSampler(1, samplers[1]);
3880 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3881 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3882
3883 // 2: non-mipped.
3884 glBindSampler(2, samplers[2]);
3885 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3886 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3887
3888 // 3: mipped.
3889 glBindSampler(3, samplers[3]);
3890 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3891 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3892
3893 // Bind two blue mipped textures and two single layer textures, should all draw.
3894 glActiveTexture(GL_TEXTURE0);
3895 glBindTexture(GL_TEXTURE_2D, tex);
3896
3897 glActiveTexture(GL_TEXTURE1);
3898 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3899
3900 glActiveTexture(GL_TEXTURE2);
3901 glBindTexture(GL_TEXTURE_2D, tex);
3902
3903 glActiveTexture(GL_TEXTURE3);
3904 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3905
3906 ASSERT_GL_NO_ERROR();
3907
3908 drawQuad(program, "position", 0.5f);
3909 ASSERT_GL_NO_ERROR();
3910 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
3911
3912 // Bind four single layer textures, two should be incomplete.
3913 glActiveTexture(GL_TEXTURE1);
3914 glBindTexture(GL_TEXTURE_2D, tex);
3915
3916 glActiveTexture(GL_TEXTURE3);
3917 glBindTexture(GL_TEXTURE_2D, tex);
3918
3919 drawQuad(program, "position", 0.5f);
3920 ASSERT_GL_NO_ERROR();
3921 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
3922}
3923
Martin Radev7e2c0d32017-09-15 14:25:42 +03003924// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
3925// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
3926// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
3927// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
3928// samples the cubemap using a direction vector (1,1,1).
3929TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
3930{
3931 if (IsOSX())
3932 {
3933 // Check http://anglebug.com/2155.
3934 std::cout << "Test skipped on OSX." << std::endl;
3935 return;
3936 }
3937 const std::string vs =
3938 R"(#version 300 es
3939 precision mediump float;
3940 in vec3 pos;
3941 void main() {
3942 gl_Position = vec4(pos, 1.0);
3943 })";
3944
3945 const std::string fs =
3946 R"(#version 300 es
3947 precision mediump float;
3948 out vec4 color;
3949 uniform samplerCube uTex;
3950 void main(){
3951 color = texture(uTex, vec3(1.0));
3952 })";
3953 ANGLE_GL_PROGRAM(program, vs, fs);
3954 glUseProgram(program);
3955
3956 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
3957 glActiveTexture(GL_TEXTURE0);
3958
3959 GLTexture cubeTex;
3960 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
3961
3962 const int kFaceWidth = 1;
3963 const int kFaceHeight = 1;
3964 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
3965 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3966 GL_UNSIGNED_BYTE, texData.data());
3967 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3968 GL_UNSIGNED_BYTE, texData.data());
3969 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3970 GL_UNSIGNED_BYTE, texData.data());
3971 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3972 GL_UNSIGNED_BYTE, texData.data());
3973 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3974 GL_UNSIGNED_BYTE, texData.data());
3975 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3976 GL_UNSIGNED_BYTE, texData.data());
3977 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3978 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3979 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
3980 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
3981 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
3982 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
3983
3984 drawQuad(program, "pos", 0.5f, 1.0f, true);
3985 ASSERT_GL_NO_ERROR();
3986
3987 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
3988}
3989
Jamie Madillfa05f602015-05-07 13:47:11 -04003990// 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 +02003991// TODO(oetuaho): Enable all below tests on OpenGL. Requires a fix for ANGLE bug 1278.
Geoff Lange0cc2a42016-01-20 10:58:17 -05003992ANGLE_INSTANTIATE_TEST(Texture2DTest,
3993 ES2_D3D9(),
3994 ES2_D3D11(),
3995 ES2_D3D11_FL9_3(),
3996 ES2_OPENGL(),
3997 ES2_OPENGLES());
3998ANGLE_INSTANTIATE_TEST(TextureCubeTest,
3999 ES2_D3D9(),
4000 ES2_D3D11(),
4001 ES2_D3D11_FL9_3(),
4002 ES2_OPENGL(),
4003 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004004ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
4005 ES2_D3D9(),
4006 ES2_D3D11(),
4007 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004008 ES2_OPENGL(),
4009 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02004010ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
4011 ES2_D3D9(),
4012 ES2_D3D11(),
4013 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05004014 ES2_OPENGL(),
4015 ES2_OPENGLES());
4016ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
4017 ES2_D3D9(),
4018 ES2_D3D11(),
4019 ES2_D3D11_FL9_3(),
4020 ES2_OPENGL(),
4021 ES2_OPENGLES());
4022ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
4023 ES2_D3D9(),
4024 ES2_D3D11(),
4025 ES2_D3D11_FL9_3(),
4026 ES2_OPENGL(),
4027 ES2_OPENGLES());
4028ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02004029ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02004030ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4031ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
4032 ES3_D3D11(),
4033 ES3_OPENGL(),
4034 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004035ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
4036 ES3_D3D11(),
4037 ES3_OPENGL(),
4038 ES3_OPENGLES());
4039ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
4040ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02004041ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02004042ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
4043 ES2_D3D11(),
4044 ES2_D3D11_FL9_3(),
4045 ES2_D3D9(),
4046 ES2_OPENGL(),
4047 ES2_OPENGLES());
4048ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
4049 ES2_D3D11(),
4050 ES2_D3D11_FL9_3(),
4051 ES2_D3D9(),
4052 ES2_OPENGL(),
4053 ES2_OPENGLES());
4054ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
4055 ES2_D3D11(),
4056 ES2_D3D11_FL9_3(),
4057 ES2_D3D9(),
4058 ES2_OPENGL(),
4059 ES2_OPENGLES());
4060ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
4061 ES2_D3D11(),
4062 ES2_D3D11_FL9_3(),
4063 ES2_D3D9(),
4064 ES2_OPENGL(),
4065 ES2_OPENGLES());
4066ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
4067 ES2_D3D11(),
4068 ES2_D3D11_FL9_3(),
4069 ES2_D3D9(),
4070 ES2_OPENGL(),
4071 ES2_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004072ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES());
Vincent Lang25ab4512016-05-13 18:13:59 +02004073ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03004074ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04004075
Jamie Madill7ffdda92016-09-08 13:26:51 -04004076} // anonymous namespace