blob: 795cf81e1d8acad231171a1540ef65017e82db89 [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
Corentin Wallezd3970de2015-05-14 11:07:48 -04007#include "test_utils/ANGLETest.h"
Jamie Madillf67115c2014-04-22 13:14:05 -04008
Jamie Madillfa05f602015-05-07 13:47:11 -04009using namespace angle;
Austin Kinross18b931d2014-09-29 12:58:31 -070010
Jamie Madillfa05f602015-05-07 13:47:11 -040011namespace
12{
13
Vincent Lang25ab4512016-05-13 18:13:59 +020014// Take a pixel, and reset the components not covered by the format to default
15// values. In particular, the default value for the alpha component is 65535
16// (1.0 as unsigned normalized fixed point value).
17GLColor16 SliceFormatColor16(GLenum format, GLColor16 full)
18{
19 switch (format)
20 {
21 case GL_RED:
22 return GLColor16(full.R, 0, 0, 65535u);
23 case GL_RG:
24 return GLColor16(full.R, full.G, 0, 65535u);
25 case GL_RGB:
26 return GLColor16(full.R, full.G, full.B, 65535u);
27 case GL_RGBA:
28 return full;
29 default:
30 UNREACHABLE();
31 }
32 return GLColor16::white;
33}
34
Olli Etuaho4a8329f2016-01-11 17:12:57 +020035class TexCoordDrawTest : public ANGLETest
Jamie Madillf67115c2014-04-22 13:14:05 -040036{
Jamie Madillbc393df2015-01-29 13:46:07 -050037 protected:
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020038 TexCoordDrawTest() : ANGLETest(), mProgram(0), mFramebuffer(0), mFramebufferColorTexture(0)
Jamie Madillf67115c2014-04-22 13:14:05 -040039 {
40 setWindowWidth(128);
41 setWindowHeight(128);
42 setConfigRedBits(8);
43 setConfigGreenBits(8);
44 setConfigBlueBits(8);
45 setConfigAlphaBits(8);
46 }
47
Olli Etuaho4a8329f2016-01-11 17:12:57 +020048 virtual std::string getVertexShaderSource()
Jamie Madillf67115c2014-04-22 13:14:05 -040049 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +020050 return std::string(SHADER_SOURCE
Geoff Langc41e42d2014-04-28 10:58:16 -040051 (
52 precision highp float;
53 attribute vec4 position;
54 varying vec2 texcoord;
55
56 void main()
57 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +020058 gl_Position = vec4(position.xy, 0.0, 1.0);
Geoff Langc41e42d2014-04-28 10:58:16 -040059 texcoord = (position.xy * 0.5) + 0.5;
60 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +020061 )
Geoff Langc41e42d2014-04-28 10:58:16 -040062 );
Olli Etuaho4a8329f2016-01-11 17:12:57 +020063 }
Geoff Langc41e42d2014-04-28 10:58:16 -040064
Olli Etuaho4a8329f2016-01-11 17:12:57 +020065 virtual std::string getFragmentShaderSource() = 0;
66
Olli Etuahoa1c917f2016-04-06 13:50:03 +030067 virtual void setUpProgram()
Olli Etuaho4a8329f2016-01-11 17:12:57 +020068 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +020069 const std::string vertexShaderSource = getVertexShaderSource();
70 const std::string fragmentShaderSource = getFragmentShaderSource();
71
72 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
73 ASSERT_NE(0u, mProgram);
74 ASSERT_GL_NO_ERROR();
Olli Etuahoa1c917f2016-04-06 13:50:03 +030075 }
76
77 void SetUp() override
78 {
79 ANGLETest::SetUp();
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020080
81 setUpFramebuffer();
Olli Etuaho4a8329f2016-01-11 17:12:57 +020082 }
83
84 void TearDown() override
85 {
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020086 glBindFramebuffer(GL_FRAMEBUFFER, 0);
87 glDeleteFramebuffers(1, &mFramebuffer);
88 glDeleteTextures(1, &mFramebufferColorTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +020089 glDeleteProgram(mProgram);
90 ANGLETest::TearDown();
91 }
92
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020093 void setUpFramebuffer()
94 {
95 // We use an FBO to work around an issue where the default framebuffer applies SRGB
96 // conversion (particularly known to happen incorrectly on Intel GL drivers). It's not
97 // clear whether this issue can even be fixed on all backends. For example GLES 3.0.4 spec
98 // section 4.4 says that the format of the default framebuffer is entirely up to the window
99 // system, so it might be SRGB, and GLES 3.0 doesn't have a "FRAMEBUFFER_SRGB" to turn off
100 // SRGB conversion like desktop GL does.
101 // TODO(oetuaho): Get rid of this if the underlying issue is fixed.
102 glGenFramebuffers(1, &mFramebuffer);
103 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
104
105 glGenTextures(1, &mFramebufferColorTexture);
106 glBindTexture(GL_TEXTURE_2D, mFramebufferColorTexture);
107 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
108 GL_UNSIGNED_BYTE, nullptr);
109 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
110 mFramebufferColorTexture, 0);
111 ASSERT_GL_NO_ERROR();
112 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
113 glBindTexture(GL_TEXTURE_2D, 0);
114 }
115
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200116 // Returns the created texture ID.
117 GLuint create2DTexture()
118 {
119 GLuint texture2D;
120 glGenTextures(1, &texture2D);
121 glBindTexture(GL_TEXTURE_2D, texture2D);
122 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
123 EXPECT_GL_NO_ERROR();
124 return texture2D;
125 }
126
127 GLuint mProgram;
Olli Etuaho51f1c0f2016-01-13 16:16:24 +0200128 GLuint mFramebuffer;
129
130 private:
131 GLuint mFramebufferColorTexture;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200132};
133
134class Texture2DTest : public TexCoordDrawTest
135{
136 protected:
137 Texture2DTest() : TexCoordDrawTest(), mTexture2D(0), mTexture2DUniformLocation(-1) {}
138
139 std::string getFragmentShaderSource() override
140 {
141 return std::string(SHADER_SOURCE
Geoff Langc41e42d2014-04-28 10:58:16 -0400142 (
143 precision highp float;
144 uniform sampler2D tex;
145 varying vec2 texcoord;
146
147 void main()
148 {
149 gl_FragColor = texture2D(tex, texcoord);
150 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200151 )
Geoff Langc41e42d2014-04-28 10:58:16 -0400152 );
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200153 }
Geoff Langc41e42d2014-04-28 10:58:16 -0400154
Olli Etuaho96963162016-03-21 11:54:33 +0200155 virtual const char *getTextureUniformName() { return "tex"; }
156
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300157 void setUpProgram() override
158 {
159 TexCoordDrawTest::setUpProgram();
160 mTexture2DUniformLocation = glGetUniformLocation(mProgram, getTextureUniformName());
161 ASSERT_NE(-1, mTexture2DUniformLocation);
162 }
163
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200164 void SetUp() override
165 {
166 TexCoordDrawTest::SetUp();
167 mTexture2D = create2DTexture();
Jamie Madilld4cfa572014-07-08 10:00:32 -0400168
Jamie Madill9aca0592014-10-06 16:26:59 -0400169 ASSERT_GL_NO_ERROR();
Jamie Madillf67115c2014-04-22 13:14:05 -0400170 }
171
Jamie Madillfa05f602015-05-07 13:47:11 -0400172 void TearDown() override
Jamie Madillf67115c2014-04-22 13:14:05 -0400173 {
Jamie Madilld4cfa572014-07-08 10:00:32 -0400174 glDeleteTextures(1, &mTexture2D);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200175 TexCoordDrawTest::TearDown();
Jamie Madillf67115c2014-04-22 13:14:05 -0400176 }
177
Jamie Madillbc393df2015-01-29 13:46:07 -0500178 // Tests CopyTexSubImage with floating point textures of various formats.
179 void testFloatCopySubImage(int sourceImageChannels, int destImageChannels)
180 {
Geoff Langbde666a2015-04-07 17:17:08 -0400181 // TODO(jmadill): Figure out why this is broken on Intel D3D11
Jamie Madill518b9fa2016-03-02 11:26:02 -0500182 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
Geoff Langbde666a2015-04-07 17:17:08 -0400183 {
184 std::cout << "Test skipped on Intel D3D11." << std::endl;
185 return;
186 }
187
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300188 setUpProgram();
189
Geoff Langfbfa47c2015-03-31 11:26:00 -0400190 if (getClientVersion() < 3)
191 {
192 if (!extensionEnabled("GL_OES_texture_float"))
193 {
194 std::cout << "Test skipped due to missing GL_OES_texture_float." << std::endl;
195 return;
196 }
197
198 if ((sourceImageChannels < 3 || destImageChannels < 3) && !extensionEnabled("GL_EXT_texture_rg"))
199 {
200 std::cout << "Test skipped due to missing GL_EXT_texture_rg." << std::endl;
201 return;
202 }
203 }
204
Jamie Madillbc393df2015-01-29 13:46:07 -0500205 GLfloat sourceImageData[4][16] =
206 {
207 { // R
208 1.0f,
209 0.0f,
210 0.0f,
211 1.0f
212 },
213 { // RG
214 1.0f, 0.0f,
215 0.0f, 1.0f,
216 0.0f, 0.0f,
217 1.0f, 1.0f
218 },
219 { // RGB
220 1.0f, 0.0f, 0.0f,
221 0.0f, 1.0f, 0.0f,
222 0.0f, 0.0f, 1.0f,
223 1.0f, 1.0f, 0.0f
224 },
225 { // RGBA
226 1.0f, 0.0f, 0.0f, 1.0f,
227 0.0f, 1.0f, 0.0f, 1.0f,
228 0.0f, 0.0f, 1.0f, 1.0f,
229 1.0f, 1.0f, 0.0f, 1.0f
230 },
231 };
232
233 GLenum imageFormats[] =
234 {
235 GL_R32F,
236 GL_RG32F,
237 GL_RGB32F,
238 GL_RGBA32F,
239 };
240
241 GLenum sourceUnsizedFormats[] =
242 {
243 GL_RED,
244 GL_RG,
245 GL_RGB,
246 GL_RGBA,
247 };
248
249 GLuint textures[2];
250
251 glGenTextures(2, textures);
252
253 GLfloat *imageData = sourceImageData[sourceImageChannels - 1];
254 GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1];
255 GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1];
256 GLenum destImageFormat = imageFormats[destImageChannels - 1];
257
258 glBindTexture(GL_TEXTURE_2D, textures[0]);
259 glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
260 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
261 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
262 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData);
263
hendrikwb27f79a2015-03-04 11:26:46 -0800264 if (sourceImageChannels < 3 && !extensionEnabled("GL_EXT_texture_rg"))
Jamie Madillbc393df2015-01-29 13:46:07 -0500265 {
266 // This is not supported
267 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
268 }
269 else
270 {
271 ASSERT_GL_NO_ERROR();
272 }
273
274 GLuint fbo;
275 glGenFramebuffers(1, &fbo);
276 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
277 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
278
279 glBindTexture(GL_TEXTURE_2D, textures[1]);
280 glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
281 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
282 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
283
284 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
285 ASSERT_GL_NO_ERROR();
286
287 glBindFramebuffer(GL_FRAMEBUFFER, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200288 drawQuad(mProgram, "position", 0.5f);
Jamie Madillbc393df2015-01-29 13:46:07 -0500289
290 int testImageChannels = std::min(sourceImageChannels, destImageChannels);
291
Olli Etuahoa314b612016-03-10 16:43:00 +0200292 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Jamie Madillbc393df2015-01-29 13:46:07 -0500293 if (testImageChannels > 1)
294 {
295 EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255);
296 EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255);
297 if (testImageChannels > 2)
298 {
299 EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255);
300 }
301 }
302
303 glDeleteFramebuffers(1, &fbo);
304 glDeleteTextures(2, textures);
305
306 ASSERT_GL_NO_ERROR();
307 }
308
Jamie Madilld4cfa572014-07-08 10:00:32 -0400309 GLuint mTexture2D;
Jamie Madilld4cfa572014-07-08 10:00:32 -0400310 GLint mTexture2DUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400311};
312
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200313class Texture2DTestES3 : public Texture2DTest
314{
315 protected:
316 Texture2DTestES3() : Texture2DTest() {}
317
318 std::string getVertexShaderSource() override
319 {
320 return std::string(
321 "#version 300 es\n"
322 "out vec2 texcoord;\n"
323 "in vec4 position;\n"
324 "void main()\n"
325 "{\n"
326 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
327 " texcoord = (position.xy * 0.5) + 0.5;\n"
328 "}\n");
329 }
330
331 std::string getFragmentShaderSource() override
332 {
333 return std::string(
334 "#version 300 es\n"
335 "precision highp float;\n"
336 "uniform highp sampler2D tex;\n"
337 "in vec2 texcoord;\n"
338 "out vec4 fragColor;\n"
339 "void main()\n"
340 "{\n"
341 " fragColor = texture(tex, texcoord);\n"
342 "}\n");
343 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300344
345 void SetUp() override
346 {
347 Texture2DTest::SetUp();
348 setUpProgram();
349 }
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200350};
351
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200352class Texture2DIntegerAlpha1TestES3 : public Texture2DTest
353{
354 protected:
355 Texture2DIntegerAlpha1TestES3() : Texture2DTest() {}
356
357 std::string getVertexShaderSource() override
358 {
359 return std::string(
360 "#version 300 es\n"
361 "out vec2 texcoord;\n"
362 "in vec4 position;\n"
363 "void main()\n"
364 "{\n"
365 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
366 " texcoord = (position.xy * 0.5) + 0.5;\n"
367 "}\n");
368 }
369
370 std::string getFragmentShaderSource() override
371 {
372 return std::string(
373 "#version 300 es\n"
374 "precision highp float;\n"
375 "uniform highp isampler2D tex;\n"
376 "in vec2 texcoord;\n"
377 "out vec4 fragColor;\n"
378 "void main()\n"
379 "{\n"
380 " vec4 green = vec4(0, 1, 0, 1);\n"
381 " vec4 black = vec4(0, 0, 0, 0);\n"
382 " fragColor = (texture(tex, texcoord).a == 1) ? green : black;\n"
383 "}\n");
384 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300385
386 void SetUp() override
387 {
388 Texture2DTest::SetUp();
389 setUpProgram();
390 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200391};
392
393class Texture2DUnsignedIntegerAlpha1TestES3 : public Texture2DTest
394{
395 protected:
396 Texture2DUnsignedIntegerAlpha1TestES3() : Texture2DTest() {}
397
398 std::string getVertexShaderSource() override
399 {
400 return std::string(
401 "#version 300 es\n"
402 "out vec2 texcoord;\n"
403 "in vec4 position;\n"
404 "void main()\n"
405 "{\n"
406 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
407 " texcoord = (position.xy * 0.5) + 0.5;\n"
408 "}\n");
409 }
410
411 std::string getFragmentShaderSource() override
412 {
413 return std::string(
414 "#version 300 es\n"
415 "precision highp float;\n"
416 "uniform highp usampler2D tex;\n"
417 "in vec2 texcoord;\n"
418 "out vec4 fragColor;\n"
419 "void main()\n"
420 "{\n"
421 " vec4 green = vec4(0, 1, 0, 1);\n"
422 " vec4 black = vec4(0, 0, 0, 0);\n"
423 " fragColor = (texture(tex, texcoord).a == 1u) ? green : black;\n"
424 "}\n");
425 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300426
427 void SetUp() override
428 {
429 Texture2DTest::SetUp();
430 setUpProgram();
431 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200432};
433
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200434class Texture2DTestWithDrawScale : public Texture2DTest
Jamie Madill2453dbc2015-07-14 11:35:42 -0400435{
436 protected:
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200437 Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {}
438
439 std::string getVertexShaderSource() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400440 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200441 return std::string(SHADER_SOURCE
442 (
443 precision highp float;
444 attribute vec4 position;
445 varying vec2 texcoord;
446
447 uniform vec2 drawScale;
448
449 void main()
450 {
451 gl_Position = vec4(position.xy * drawScale, 0.0, 1.0);
452 texcoord = (position.xy * 0.5) + 0.5;
453 }
454 )
455 );
Jamie Madill2453dbc2015-07-14 11:35:42 -0400456 }
457
458 void SetUp() override
459 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200460 Texture2DTest::SetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300461
462 setUpProgram();
463
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200464 mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale");
465 ASSERT_NE(-1, mDrawScaleUniformLocation);
Jamie Madill2453dbc2015-07-14 11:35:42 -0400466
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200467 glUseProgram(mProgram);
468 glUniform2f(mDrawScaleUniformLocation, 1.0f, 1.0f);
469 glUseProgram(0);
470 ASSERT_GL_NO_ERROR();
471 }
472
473 GLint mDrawScaleUniformLocation;
474};
475
Olli Etuaho4644a202016-01-12 15:12:53 +0200476class Sampler2DAsFunctionParameterTest : public Texture2DTest
477{
478 protected:
479 Sampler2DAsFunctionParameterTest() : Texture2DTest() {}
480
481 std::string getFragmentShaderSource() override
482 {
483 return std::string(SHADER_SOURCE
484 (
485 precision highp float;
486 uniform sampler2D tex;
487 varying vec2 texcoord;
488
489 vec4 computeFragColor(sampler2D aTex)
490 {
491 return texture2D(aTex, texcoord);
492 }
493
494 void main()
495 {
496 gl_FragColor = computeFragColor(tex);
497 }
498 )
499 );
500 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300501
502 void SetUp() override
503 {
504 Texture2DTest::SetUp();
505 setUpProgram();
506 }
Olli Etuaho4644a202016-01-12 15:12:53 +0200507};
508
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200509class TextureCubeTest : public TexCoordDrawTest
510{
511 protected:
512 TextureCubeTest()
513 : TexCoordDrawTest(),
514 mTexture2D(0),
515 mTextureCube(0),
516 mTexture2DUniformLocation(-1),
517 mTextureCubeUniformLocation(-1)
518 {
519 }
520
521 std::string getFragmentShaderSource() override
522 {
523 return std::string(SHADER_SOURCE
524 (
525 precision highp float;
526 uniform sampler2D tex2D;
527 uniform samplerCube texCube;
528 varying vec2 texcoord;
529
530 void main()
531 {
532 gl_FragColor = texture2D(tex2D, texcoord);
533 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
534 }
535 )
536 );
537 }
538
539 void SetUp() override
540 {
541 TexCoordDrawTest::SetUp();
542
543 glGenTextures(1, &mTextureCube);
544 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
545 glTexStorage2DEXT(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
546 EXPECT_GL_NO_ERROR();
547
548 mTexture2D = create2DTexture();
549
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300550 setUpProgram();
551
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200552 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
553 ASSERT_NE(-1, mTexture2DUniformLocation);
554 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
555 ASSERT_NE(-1, mTextureCubeUniformLocation);
556 }
557
558 void TearDown() override
559 {
560 glDeleteTextures(1, &mTextureCube);
561 TexCoordDrawTest::TearDown();
562 }
563
564 GLuint mTexture2D;
565 GLuint mTextureCube;
566 GLint mTexture2DUniformLocation;
567 GLint mTextureCubeUniformLocation;
568};
569
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200570class SamplerArrayTest : public TexCoordDrawTest
571{
572 protected:
573 SamplerArrayTest()
574 : TexCoordDrawTest(),
575 mTexture2DA(0),
576 mTexture2DB(0),
577 mTexture0UniformLocation(-1),
578 mTexture1UniformLocation(-1)
579 {
580 }
581
582 std::string getFragmentShaderSource() override
583 {
584 return std::string(SHADER_SOURCE
585 (
586 precision mediump float;
587 uniform highp sampler2D tex2DArray[2];
588 varying vec2 texcoord;
589 void main()
590 {
591 gl_FragColor = texture2D(tex2DArray[0], texcoord);
592 gl_FragColor += texture2D(tex2DArray[1], texcoord);
593 }
594 )
595 );
596 }
597
598 void SetUp() override
599 {
600 TexCoordDrawTest::SetUp();
601
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300602 setUpProgram();
603
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200604 mTexture0UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[0]");
605 ASSERT_NE(-1, mTexture0UniformLocation);
606 mTexture1UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[1]");
607 ASSERT_NE(-1, mTexture1UniformLocation);
608
609 mTexture2DA = create2DTexture();
610 mTexture2DB = create2DTexture();
611 ASSERT_GL_NO_ERROR();
612 }
613
614 void TearDown() override
615 {
616 glDeleteTextures(1, &mTexture2DA);
617 glDeleteTextures(1, &mTexture2DB);
618 TexCoordDrawTest::TearDown();
619 }
620
621 void testSamplerArrayDraw()
622 {
623 GLubyte texData[4];
624 texData[0] = 0;
625 texData[1] = 60;
626 texData[2] = 0;
627 texData[3] = 255;
628
629 glActiveTexture(GL_TEXTURE0);
630 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
631 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
632
633 texData[1] = 120;
634 glActiveTexture(GL_TEXTURE1);
635 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
636 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
637 EXPECT_GL_ERROR(GL_NO_ERROR);
638
639 glUseProgram(mProgram);
640 glUniform1i(mTexture0UniformLocation, 0);
641 glUniform1i(mTexture1UniformLocation, 1);
642 drawQuad(mProgram, "position", 0.5f);
643 EXPECT_GL_NO_ERROR();
644
645 EXPECT_PIXEL_NEAR(0, 0, 0, 180, 0, 255, 2);
646 }
647
648 GLuint mTexture2DA;
649 GLuint mTexture2DB;
650 GLint mTexture0UniformLocation;
651 GLint mTexture1UniformLocation;
652};
653
654
655class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest
656{
657 protected:
658 SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {}
659
660 std::string getFragmentShaderSource() override
661 {
662 return std::string(SHADER_SOURCE
663 (
664 precision mediump float;
665 uniform highp sampler2D tex2DArray[2];
666 varying vec2 texcoord;
667
668 vec4 computeFragColor(highp sampler2D aTex2DArray[2])
669 {
670 return texture2D(aTex2DArray[0], texcoord) + texture2D(aTex2DArray[1], texcoord);
671 }
672
673 void main()
674 {
675 gl_FragColor = computeFragColor(tex2DArray);
676 }
677 )
678 );
679 }
680};
681
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200682class Texture2DArrayTestES3 : public TexCoordDrawTest
683{
684 protected:
685 Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {}
686
687 std::string getVertexShaderSource() override
688 {
689 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400690 "#version 300 es\n"
691 "out vec2 texcoord;\n"
692 "in vec4 position;\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200693 "void main()\n"
694 "{\n"
695 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
696 " texcoord = (position.xy * 0.5) + 0.5;\n"
697 "}\n");
698 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400699
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200700 std::string getFragmentShaderSource() override
701 {
702 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400703 "#version 300 es\n"
704 "precision highp float;\n"
Olli Etuaho183d7e22015-11-20 15:59:09 +0200705 "uniform highp sampler2DArray tex2DArray;\n"
Jamie Madill2453dbc2015-07-14 11:35:42 -0400706 "in vec2 texcoord;\n"
707 "out vec4 fragColor;\n"
708 "void main()\n"
709 "{\n"
710 " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200711 "}\n");
712 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400713
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200714 void SetUp() override
715 {
716 TexCoordDrawTest::SetUp();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400717
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300718 setUpProgram();
719
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200720 mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray");
Jamie Madill2453dbc2015-07-14 11:35:42 -0400721 ASSERT_NE(-1, mTextureArrayLocation);
722
723 glGenTextures(1, &m2DArrayTexture);
724 ASSERT_GL_NO_ERROR();
725 }
726
727 void TearDown() override
728 {
729 glDeleteTextures(1, &m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200730 TexCoordDrawTest::TearDown();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400731 }
732
733 GLuint m2DArrayTexture;
Jamie Madill2453dbc2015-07-14 11:35:42 -0400734 GLint mTextureArrayLocation;
735};
736
Olli Etuahobce743a2016-01-15 17:18:28 +0200737class TextureSizeTextureArrayTest : public TexCoordDrawTest
738{
739 protected:
740 TextureSizeTextureArrayTest()
741 : TexCoordDrawTest(),
742 mTexture2DA(0),
743 mTexture2DB(0),
744 mTexture0Location(-1),
745 mTexture1Location(-1)
746 {
747 }
748
749 std::string getVertexShaderSource() override
750 {
751 return std::string(
752 "#version 300 es\n"
753 "in vec4 position;\n"
754 "void main()\n"
755 "{\n"
756 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
757 "}\n");
758 }
759
760 std::string getFragmentShaderSource() override
761 {
762 return std::string(
763 "#version 300 es\n"
764 "precision highp float;\n"
765 "uniform highp sampler2D tex2DArray[2];\n"
766 "out vec4 fragColor;\n"
767 "void main()\n"
768 "{\n"
769 " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n"
770 " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n"
771 " fragColor = vec4(red, green, 0.0, 1.0);\n"
772 "}\n");
773 }
774
775 void SetUp() override
776 {
777 TexCoordDrawTest::SetUp();
778
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300779 setUpProgram();
780
Olli Etuahobce743a2016-01-15 17:18:28 +0200781 mTexture0Location = glGetUniformLocation(mProgram, "tex2DArray[0]");
782 ASSERT_NE(-1, mTexture0Location);
783 mTexture1Location = glGetUniformLocation(mProgram, "tex2DArray[1]");
784 ASSERT_NE(-1, mTexture1Location);
785
786 mTexture2DA = create2DTexture();
787 mTexture2DB = create2DTexture();
788 ASSERT_GL_NO_ERROR();
789 }
790
791 void TearDown() override
792 {
793 glDeleteTextures(1, &mTexture2DA);
794 glDeleteTextures(1, &mTexture2DB);
795 TexCoordDrawTest::TearDown();
796 }
797
798 GLuint mTexture2DA;
799 GLuint mTexture2DB;
800 GLint mTexture0Location;
801 GLint mTexture1Location;
802};
803
Olli Etuahoa314b612016-03-10 16:43:00 +0200804class Texture3DTestES3 : public TexCoordDrawTest
805{
806 protected:
807 Texture3DTestES3() : TexCoordDrawTest(), mTexture3D(0), mTexture3DUniformLocation(-1) {}
808
809 std::string getVertexShaderSource() override
810 {
811 return std::string(
812 "#version 300 es\n"
813 "out vec2 texcoord;\n"
814 "in vec4 position;\n"
815 "void main()\n"
816 "{\n"
817 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
818 " texcoord = (position.xy * 0.5) + 0.5;\n"
819 "}\n");
820 }
821
822 std::string getFragmentShaderSource() override
823 {
824 return std::string(
825 "#version 300 es\n"
826 "precision highp float;\n"
827 "uniform highp sampler3D tex3D;\n"
828 "in vec2 texcoord;\n"
829 "out vec4 fragColor;\n"
830 "void main()\n"
831 "{\n"
832 " fragColor = texture(tex3D, vec3(texcoord, 0.0));\n"
833 "}\n");
834 }
835
836 void SetUp() override
837 {
838 TexCoordDrawTest::SetUp();
839
840 glGenTextures(1, &mTexture3D);
841
842 setUpProgram();
843
844 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
845 ASSERT_NE(-1, mTexture3DUniformLocation);
846 }
847
848 void TearDown() override
849 {
850 glDeleteTextures(1, &mTexture3D);
851 TexCoordDrawTest::TearDown();
852 }
853
854 GLuint mTexture3D;
855 GLint mTexture3DUniformLocation;
856};
857
Olli Etuaho1a679902016-01-14 12:21:47 +0200858class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest
859{
860 protected:
861 ShadowSamplerPlusSampler3DTestES3()
862 : TexCoordDrawTest(),
863 mTextureShadow(0),
864 mTexture3D(0),
865 mTextureShadowUniformLocation(-1),
866 mTexture3DUniformLocation(-1),
867 mDepthRefUniformLocation(-1)
868 {
869 }
870
871 std::string getVertexShaderSource() override
872 {
873 return std::string(
874 "#version 300 es\n"
875 "out vec2 texcoord;\n"
876 "in vec4 position;\n"
877 "void main()\n"
878 "{\n"
879 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
880 " texcoord = (position.xy * 0.5) + 0.5;\n"
881 "}\n");
882 }
883
884 std::string getFragmentShaderSource() override
885 {
886 return std::string(
887 "#version 300 es\n"
888 "precision highp float;\n"
889 "uniform highp sampler2DShadow tex2DShadow;\n"
890 "uniform highp sampler3D tex3D;\n"
891 "in vec2 texcoord;\n"
892 "uniform float depthRef;\n"
893 "out vec4 fragColor;\n"
894 "void main()\n"
895 "{\n"
896 " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n"
897 " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n"
898 "}\n");
899 }
900
901 void SetUp() override
902 {
903 TexCoordDrawTest::SetUp();
904
905 glGenTextures(1, &mTexture3D);
906
907 glGenTextures(1, &mTextureShadow);
908 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
909 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
910
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300911 setUpProgram();
912
Olli Etuaho1a679902016-01-14 12:21:47 +0200913 mTextureShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
914 ASSERT_NE(-1, mTextureShadowUniformLocation);
915 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
916 ASSERT_NE(-1, mTexture3DUniformLocation);
917 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
918 ASSERT_NE(-1, mDepthRefUniformLocation);
919 }
920
921 void TearDown() override
922 {
923 glDeleteTextures(1, &mTextureShadow);
924 glDeleteTextures(1, &mTexture3D);
925 TexCoordDrawTest::TearDown();
926 }
927
928 GLuint mTextureShadow;
929 GLuint mTexture3D;
930 GLint mTextureShadowUniformLocation;
931 GLint mTexture3DUniformLocation;
932 GLint mDepthRefUniformLocation;
933};
934
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200935class SamplerTypeMixTestES3 : public TexCoordDrawTest
936{
937 protected:
938 SamplerTypeMixTestES3()
939 : TexCoordDrawTest(),
940 mTexture2D(0),
941 mTextureCube(0),
942 mTexture2DShadow(0),
943 mTextureCubeShadow(0),
944 mTexture2DUniformLocation(-1),
945 mTextureCubeUniformLocation(-1),
946 mTexture2DShadowUniformLocation(-1),
947 mTextureCubeShadowUniformLocation(-1),
948 mDepthRefUniformLocation(-1)
949 {
950 }
951
952 std::string getVertexShaderSource() override
953 {
954 return std::string(
955 "#version 300 es\n"
956 "out vec2 texcoord;\n"
957 "in vec4 position;\n"
958 "void main()\n"
959 "{\n"
960 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
961 " texcoord = (position.xy * 0.5) + 0.5;\n"
962 "}\n");
963 }
964
965 std::string getFragmentShaderSource() override
966 {
967 return std::string(
968 "#version 300 es\n"
969 "precision highp float;\n"
970 "uniform highp sampler2D tex2D;\n"
971 "uniform highp samplerCube texCube;\n"
972 "uniform highp sampler2DShadow tex2DShadow;\n"
973 "uniform highp samplerCubeShadow texCubeShadow;\n"
974 "in vec2 texcoord;\n"
975 "uniform float depthRef;\n"
976 "out vec4 fragColor;\n"
977 "void main()\n"
978 "{\n"
979 " fragColor = texture(tex2D, texcoord);\n"
980 " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n"
981 " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n"
982 " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * "
983 "0.125);\n"
984 "}\n");
985 }
986
987 void SetUp() override
988 {
989 TexCoordDrawTest::SetUp();
990
991 glGenTextures(1, &mTexture2D);
992 glGenTextures(1, &mTextureCube);
993
994 glGenTextures(1, &mTexture2DShadow);
995 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
996 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
997
998 glGenTextures(1, &mTextureCubeShadow);
999 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
1000 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
1001
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001002 setUpProgram();
1003
Olli Etuahoc8c99a02016-01-14 16:47:22 +02001004 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
1005 ASSERT_NE(-1, mTexture2DUniformLocation);
1006 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
1007 ASSERT_NE(-1, mTextureCubeUniformLocation);
1008 mTexture2DShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
1009 ASSERT_NE(-1, mTexture2DShadowUniformLocation);
1010 mTextureCubeShadowUniformLocation = glGetUniformLocation(mProgram, "texCubeShadow");
1011 ASSERT_NE(-1, mTextureCubeShadowUniformLocation);
1012 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
1013 ASSERT_NE(-1, mDepthRefUniformLocation);
1014
1015 ASSERT_GL_NO_ERROR();
1016 }
1017
1018 void TearDown() override
1019 {
1020 glDeleteTextures(1, &mTexture2D);
1021 glDeleteTextures(1, &mTextureCube);
1022 glDeleteTextures(1, &mTexture2DShadow);
1023 glDeleteTextures(1, &mTextureCubeShadow);
1024 TexCoordDrawTest::TearDown();
1025 }
1026
1027 GLuint mTexture2D;
1028 GLuint mTextureCube;
1029 GLuint mTexture2DShadow;
1030 GLuint mTextureCubeShadow;
1031 GLint mTexture2DUniformLocation;
1032 GLint mTextureCubeUniformLocation;
1033 GLint mTexture2DShadowUniformLocation;
1034 GLint mTextureCubeShadowUniformLocation;
1035 GLint mDepthRefUniformLocation;
1036};
1037
Olli Etuaho96963162016-03-21 11:54:33 +02001038class SamplerInStructTest : public Texture2DTest
1039{
1040 protected:
1041 SamplerInStructTest() : Texture2DTest() {}
1042
1043 const char *getTextureUniformName() override { return "us.tex"; }
1044
1045 std::string getFragmentShaderSource() override
1046 {
1047 return std::string(
1048 "precision highp float;\n"
1049 "struct S\n"
1050 "{\n"
1051 " vec4 a;\n"
1052 " highp sampler2D tex;\n"
1053 "};\n"
1054 "uniform S us;\n"
1055 "varying vec2 texcoord;\n"
1056 "void main()\n"
1057 "{\n"
1058 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x);\n"
1059 "}\n");
1060 }
1061
1062 void runSamplerInStructTest()
1063 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001064 setUpProgram();
1065
Olli Etuaho96963162016-03-21 11:54:33 +02001066 glActiveTexture(GL_TEXTURE0);
1067 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001068 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1069 &GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001070 drawQuad(mProgram, "position", 0.5f);
Olli Etuahoa314b612016-03-10 16:43:00 +02001071 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001072 }
1073};
1074
1075class SamplerInStructAsFunctionParameterTest : public SamplerInStructTest
1076{
1077 protected:
1078 SamplerInStructAsFunctionParameterTest() : SamplerInStructTest() {}
1079
1080 std::string getFragmentShaderSource() override
1081 {
1082 return std::string(
1083 "precision highp float;\n"
1084 "struct S\n"
1085 "{\n"
1086 " vec4 a;\n"
1087 " highp sampler2D tex;\n"
1088 "};\n"
1089 "uniform S us;\n"
1090 "varying vec2 texcoord;\n"
1091 "vec4 sampleFrom(S s) {\n"
1092 " return texture2D(s.tex, texcoord + s.a.x);\n"
1093 "}\n"
1094 "void main()\n"
1095 "{\n"
1096 " gl_FragColor = sampleFrom(us);\n"
1097 "}\n");
1098 }
1099};
1100
1101class SamplerInStructArrayAsFunctionParameterTest : public SamplerInStructTest
1102{
1103 protected:
1104 SamplerInStructArrayAsFunctionParameterTest() : SamplerInStructTest() {}
1105
1106 const char *getTextureUniformName() override { return "us[0].tex"; }
1107
1108 std::string getFragmentShaderSource() override
1109 {
1110 return std::string(
1111 "precision highp float;\n"
1112 "struct S\n"
1113 "{\n"
1114 " vec4 a;\n"
1115 " highp sampler2D tex;\n"
1116 "};\n"
1117 "uniform S us[1];\n"
1118 "varying vec2 texcoord;\n"
1119 "vec4 sampleFrom(S s) {\n"
1120 " return texture2D(s.tex, texcoord + s.a.x);\n"
1121 "}\n"
1122 "void main()\n"
1123 "{\n"
1124 " gl_FragColor = sampleFrom(us[0]);\n"
1125 "}\n");
1126 }
1127};
1128
1129class SamplerInNestedStructAsFunctionParameterTest : public SamplerInStructTest
1130{
1131 protected:
1132 SamplerInNestedStructAsFunctionParameterTest() : SamplerInStructTest() {}
1133
1134 const char *getTextureUniformName() override { return "us[0].sub.tex"; }
1135
1136 std::string getFragmentShaderSource() override
1137 {
1138 return std::string(
1139 "precision highp float;\n"
1140 "struct SUB\n"
1141 "{\n"
1142 " vec4 a;\n"
1143 " highp sampler2D tex;\n"
1144 "};\n"
1145 "struct S\n"
1146 "{\n"
1147 " SUB sub;\n"
1148 "};\n"
1149 "uniform S us[1];\n"
1150 "varying vec2 texcoord;\n"
1151 "vec4 sampleFrom(SUB s) {\n"
1152 " return texture2D(s.tex, texcoord + s.a.x);\n"
1153 "}\n"
1154 "void main()\n"
1155 "{\n"
1156 " gl_FragColor = sampleFrom(us[0].sub);\n"
1157 "}\n");
1158 }
1159};
1160
1161class SamplerInStructAndOtherVariableTest : public SamplerInStructTest
1162{
1163 protected:
1164 SamplerInStructAndOtherVariableTest() : SamplerInStructTest() {}
1165
1166 std::string getFragmentShaderSource() override
1167 {
1168 return std::string(
1169 "precision highp float;\n"
1170 "struct S\n"
1171 "{\n"
1172 " vec4 a;\n"
1173 " highp sampler2D tex;\n"
1174 "};\n"
1175 "uniform S us;\n"
1176 "uniform float us_tex;\n"
1177 "varying vec2 texcoord;\n"
1178 "void main()\n"
1179 "{\n"
1180 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x + us_tex);\n"
1181 "}\n");
1182 }
1183};
1184
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001185TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001186{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001187 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001188 EXPECT_GL_ERROR(GL_NO_ERROR);
1189
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001190 setUpProgram();
1191
Jamie Madillf67115c2014-04-22 13:14:05 -04001192 const GLubyte *pixels[20] = { 0 };
1193 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1194 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1195}
Geoff Langc41e42d2014-04-28 10:58:16 -04001196
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001197TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001198{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001199 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001200 EXPECT_GL_ERROR(GL_NO_ERROR);
1201
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001202 setUpProgram();
1203
Geoff Langc41e42d2014-04-28 10:58:16 -04001204 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001205 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001206 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001207 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001208
1209 const GLubyte *pixel[4] = { 0 };
1210
1211 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1212 EXPECT_GL_NO_ERROR();
1213
1214 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1215 EXPECT_GL_NO_ERROR();
1216
1217 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1218 EXPECT_GL_NO_ERROR();
1219}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001220
1221// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001222TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001223{
1224 glActiveTexture(GL_TEXTURE0);
1225 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1226 glActiveTexture(GL_TEXTURE1);
1227 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1228 EXPECT_GL_ERROR(GL_NO_ERROR);
1229
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001230 glUseProgram(mProgram);
1231 glUniform1i(mTexture2DUniformLocation, 0);
1232 glUniform1i(mTextureCubeUniformLocation, 1);
1233 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001234 EXPECT_GL_NO_ERROR();
1235}
Jamie Madill9aca0592014-10-06 16:26:59 -04001236
Olli Etuaho53a2da12016-01-11 15:43:32 +02001237// Test drawing with two texture types accessed from the same shader and check that the result of
1238// drawing is correct.
1239TEST_P(TextureCubeTest, CubeMapDraw)
1240{
1241 GLubyte texData[4];
1242 texData[0] = 0;
1243 texData[1] = 60;
1244 texData[2] = 0;
1245 texData[3] = 255;
1246
1247 glActiveTexture(GL_TEXTURE0);
1248 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1249 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1250
1251 glActiveTexture(GL_TEXTURE1);
1252 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1253 texData[1] = 120;
1254 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1255 texData);
1256 EXPECT_GL_ERROR(GL_NO_ERROR);
1257
1258 glUseProgram(mProgram);
1259 glUniform1i(mTexture2DUniformLocation, 0);
1260 glUniform1i(mTextureCubeUniformLocation, 1);
1261 drawQuad(mProgram, "position", 0.5f);
1262 EXPECT_GL_NO_ERROR();
1263
1264 int px = getWindowWidth() - 1;
1265 int py = 0;
1266 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1267}
1268
Olli Etuaho4644a202016-01-12 15:12:53 +02001269TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1270{
1271 glActiveTexture(GL_TEXTURE0);
1272 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1273 GLubyte texData[4];
1274 texData[0] = 0;
1275 texData[1] = 128;
1276 texData[2] = 0;
1277 texData[3] = 255;
1278 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1279 glUseProgram(mProgram);
1280 glUniform1i(mTexture2DUniformLocation, 0);
1281 drawQuad(mProgram, "position", 0.5f);
1282 EXPECT_GL_NO_ERROR();
1283
1284 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1285}
1286
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001287// Test drawing with two textures passed to the shader in a sampler array.
1288TEST_P(SamplerArrayTest, SamplerArrayDraw)
1289{
1290 testSamplerArrayDraw();
1291}
1292
1293// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1294// user-defined function in the shader.
1295TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1296{
1297 testSamplerArrayDraw();
1298}
1299
Jamie Madill9aca0592014-10-06 16:26:59 -04001300// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001301TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001302{
1303 int px = getWindowWidth() / 2;
1304 int py = getWindowHeight() / 2;
1305
1306 glActiveTexture(GL_TEXTURE0);
1307 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1308
Olli Etuahoa314b612016-03-10 16:43:00 +02001309 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001310
Olli Etuahoa314b612016-03-10 16:43:00 +02001311 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001312 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1313 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1314 glGenerateMipmap(GL_TEXTURE_2D);
1315
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001316 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001317 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001318 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1319 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001320 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001321 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001322
Olli Etuahoa314b612016-03-10 16:43:00 +02001323 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001324
Olli Etuahoa314b612016-03-10 16:43:00 +02001325 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1326 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001327 glGenerateMipmap(GL_TEXTURE_2D);
1328
Olli Etuahoa314b612016-03-10 16:43:00 +02001329 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001330
Olli Etuahoa314b612016-03-10 16:43:00 +02001331 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1332 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001333 glGenerateMipmap(GL_TEXTURE_2D);
1334
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001335 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001336
1337 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001338 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001339}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001340
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001341// Test creating a FBO with a cube map render target, to test an ANGLE bug
1342// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001343TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001344{
1345 GLuint fbo;
1346 glGenFramebuffers(1, &fbo);
1347 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1348
1349 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1350 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mTextureCube, 0);
1351
Corentin Wallez322653b2015-06-17 18:33:56 +02001352 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001353
1354 glDeleteFramebuffers(1, &fbo);
1355
1356 EXPECT_GL_NO_ERROR();
1357}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001358
1359// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001360TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001361{
1362 int width = getWindowWidth();
1363 int height = getWindowHeight();
1364
1365 GLuint tex2D;
1366 glGenTextures(1, &tex2D);
1367 glActiveTexture(GL_TEXTURE0);
1368 glBindTexture(GL_TEXTURE_2D, tex2D);
1369
1370 // Fill with red
1371 std::vector<GLubyte> pixels(3 * 16 * 16);
1372 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1373 {
1374 pixels[pixelId * 3 + 0] = 255;
1375 pixels[pixelId * 3 + 1] = 0;
1376 pixels[pixelId * 3 + 2] = 0;
1377 }
1378
1379 // ANGLE internally uses RGBA as the DirectX format for RGB images
1380 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1381 // The data is kept in a CPU-side image and the image is marked as dirty.
1382 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1383
1384 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1385 // glTexSubImage2D should take into account that the image is dirty.
1386 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1387 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1388 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1389
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001390 setUpProgram();
1391
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001392 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001393 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001394 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001395 glDeleteTextures(1, &tex2D);
1396 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001397 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001398
1399 // Validate that the region of the texture without data has an alpha of 1.0
1400 GLubyte pixel[4];
1401 glReadPixels(3 * width / 4, 3 * height / 4, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1402 EXPECT_EQ(pixel[3], 255);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001403}
1404
1405// 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 +02001406TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001407{
1408 if (extensionEnabled("NV_pixel_buffer_object"))
1409 {
1410 int width = getWindowWidth();
1411 int height = getWindowHeight();
1412
1413 GLuint tex2D;
1414 glGenTextures(1, &tex2D);
1415 glActiveTexture(GL_TEXTURE0);
1416 glBindTexture(GL_TEXTURE_2D, tex2D);
1417
1418 // Fill with red
1419 std::vector<GLubyte> pixels(3 * 16 * 16);
1420 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1421 {
1422 pixels[pixelId * 3 + 0] = 255;
1423 pixels[pixelId * 3 + 1] = 0;
1424 pixels[pixelId * 3 + 2] = 0;
1425 }
1426
1427 // Read 16x16 region from red backbuffer to PBO
1428 GLuint pbo;
1429 glGenBuffers(1, &pbo);
1430 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1431 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1432
1433 // ANGLE internally uses RGBA as the DirectX format for RGB images
1434 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1435 // The data is kept in a CPU-side image and the image is marked as dirty.
1436 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1437
1438 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1439 // glTexSubImage2D should take into account that the image is dirty.
1440 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, NULL);
1441 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1442 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1443
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001444 setUpProgram();
1445
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001446 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001447 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001448 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001449 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001450 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001451 EXPECT_GL_NO_ERROR();
1452 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1453 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1454 }
1455}
Jamie Madillbc393df2015-01-29 13:46:07 -05001456
1457// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001458TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001459{
1460 testFloatCopySubImage(1, 1);
1461}
1462
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001463TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001464{
1465 testFloatCopySubImage(2, 1);
1466}
1467
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001468TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001469{
1470 testFloatCopySubImage(2, 2);
1471}
1472
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001473TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001474{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001475 if (IsIntel() && IsLinux())
1476 {
1477 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1478 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1479 return;
1480 }
1481
Jamie Madillbc393df2015-01-29 13:46:07 -05001482 testFloatCopySubImage(3, 1);
1483}
1484
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001485TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001486{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001487 if (IsIntel() && IsLinux())
1488 {
1489 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1490 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1491 return;
1492 }
1493
Jamie Madillbc393df2015-01-29 13:46:07 -05001494 testFloatCopySubImage(3, 2);
1495}
1496
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001497TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001498{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001499 if (IsIntel() && IsLinux())
1500 {
1501 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1502 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1503 return;
1504 }
1505
Austin Kinrossd544cc92016-01-11 15:26:42 -08001506 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001507 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001508 {
1509 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1510 return;
1511 }
1512
Jamie Madillbc393df2015-01-29 13:46:07 -05001513 testFloatCopySubImage(3, 3);
1514}
1515
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001516TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001517{
1518 testFloatCopySubImage(4, 1);
1519}
1520
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001521TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001522{
1523 testFloatCopySubImage(4, 2);
1524}
1525
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001526TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001527{
Austin Kinrossd544cc92016-01-11 15:26:42 -08001528 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001529 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001530 {
1531 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1532 return;
1533 }
1534
Jamie Madillbc393df2015-01-29 13:46:07 -05001535 testFloatCopySubImage(4, 3);
1536}
1537
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001538TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001539{
Austin Kinrossd544cc92016-01-11 15:26:42 -08001540 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001541 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001542 {
1543 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1544 return;
1545 }
1546
Jamie Madillbc393df2015-01-29 13:46:07 -05001547 testFloatCopySubImage(4, 4);
1548}
Austin Kinross07285142015-03-26 11:36:16 -07001549
1550// Port of https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1551// 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 +02001552TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001553{
1554 const int npotTexSize = 5;
1555 const int potTexSize = 4; // Should be less than npotTexSize
1556 GLuint tex2D;
1557
1558 if (extensionEnabled("GL_OES_texture_npot"))
1559 {
1560 // This test isn't applicable if texture_npot is enabled
1561 return;
1562 }
1563
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001564 setUpProgram();
1565
Austin Kinross07285142015-03-26 11:36:16 -07001566 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1567
Austin Kinross5faa15b2016-01-11 13:32:48 -08001568 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1569 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1570
Austin Kinross07285142015-03-26 11:36:16 -07001571 glActiveTexture(GL_TEXTURE0);
1572 glGenTextures(1, &tex2D);
1573 glBindTexture(GL_TEXTURE_2D, tex2D);
1574
1575 std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize);
1576 for (size_t pixelId = 0; pixelId < npotTexSize * npotTexSize; ++pixelId)
1577 {
1578 pixels[pixelId] = 64;
1579 }
1580
1581 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1582 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1583
1584 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
1585 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1586 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1587
1588 // Check that an NPOT texture on level 0 succeeds
1589 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1590 EXPECT_GL_NO_ERROR();
1591
1592 // Check that generateMipmap fails on NPOT
1593 glGenerateMipmap(GL_TEXTURE_2D);
1594 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1595
1596 // Check that nothing is drawn if filtering is not correct for NPOT
1597 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1598 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1599 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1600 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1601 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001602 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001603 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1604
1605 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1606 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1607 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1608 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1609 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001610 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001611 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1612
1613 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1614 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1615 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001616 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001617 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1618
1619 // Check that glTexImage2D for POT texture succeeds
1620 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1621 EXPECT_GL_NO_ERROR();
1622
1623 // Check that generateMipmap for an POT texture succeeds
1624 glGenerateMipmap(GL_TEXTURE_2D);
1625 EXPECT_GL_NO_ERROR();
1626
1627 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1628 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1629 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1630 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1631 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1632 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001633 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001634 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1635 EXPECT_GL_NO_ERROR();
1636}
Jamie Madillfa05f602015-05-07 13:47:11 -04001637
Austin Kinross08528e12015-10-07 16:24:40 -07001638// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1639// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001640TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001641{
Geoff Lange0cc2a42016-01-20 10:58:17 -05001642 // TODO(geofflang): Allow the GL backend to accept SubImage calls with a null data ptr. (bug
1643 // 1278)
1644 if (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
1645 getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE)
1646 {
1647 std::cout << "Test disabled on OpenGL." << std::endl;
1648 return;
1649 }
1650
Austin Kinross08528e12015-10-07 16:24:40 -07001651 glActiveTexture(GL_TEXTURE0);
1652 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1653
1654 // Create an 8x8 (i.e. power-of-two) texture.
1655 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1656 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1657 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1658 glGenerateMipmap(GL_TEXTURE_2D);
1659
1660 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1661 // This should always work, even if GL_OES_texture_npot isn't active.
1662 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1663
1664 EXPECT_GL_NO_ERROR();
1665}
1666
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001667// Test to check that texture completeness is determined correctly when the texture base level is
1668// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1669TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1670{
1671 glActiveTexture(GL_TEXTURE0);
1672 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001673
1674 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1675 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1676 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1677 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1678 texDataGreen.data());
1679 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1680 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001681 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1682 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1683 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1684
1685 EXPECT_GL_NO_ERROR();
1686
1687 drawQuad(mProgram, "position", 0.5f);
1688
Olli Etuahoa314b612016-03-10 16:43:00 +02001689 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1690}
1691
1692// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1693// have images defined.
1694TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1695{
1696 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1697 {
1698 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1699 std::cout << "Test skipped on AMD OpenGL." << std::endl;
1700 return;
1701 }
1702 if (IsOSX())
1703 {
1704 // Observed incorrect rendering on OSX.
1705 std::cout << "Test skipped on OSX." << std::endl;
1706 return;
1707 }
1708 glActiveTexture(GL_TEXTURE0);
1709 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1710 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1711 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1712 texDataGreen.data());
1713 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1714 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1715 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1716 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1717
1718 EXPECT_GL_NO_ERROR();
1719
1720 drawQuad(mProgram, "position", 0.5f);
1721
1722 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1723}
1724
Olli Etuahoe8528d82016-05-16 17:50:52 +03001725// Test that drawing works correctly when level 0 is undefined and base level is 1.
1726TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1727{
1728 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1729 {
1730 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1731 std::cout << "Test skipped on AMD OpenGL." << std::endl;
1732 return;
1733 }
1734 if (IsOSX())
1735 {
1736 // Observed incorrect rendering on OSX.
1737 std::cout << "Test skipped on OSX." << std::endl;
1738 return;
1739 }
1740 glActiveTexture(GL_TEXTURE0);
1741 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1742 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1743 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1744 texDataGreen.data());
1745 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1746 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1747 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1748 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1749
1750 EXPECT_GL_NO_ERROR();
1751
1752 // Texture is incomplete.
1753 drawQuad(mProgram, "position", 0.5f);
1754 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1755
1756 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1757 texDataGreen.data());
1758
1759 // Texture is now complete.
1760 drawQuad(mProgram, "position", 0.5f);
1761 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1762}
1763
Olli Etuahoa314b612016-03-10 16:43:00 +02001764// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1765// dimensions that don't fit the images inside the range.
1766// GLES 3.0.4 section 3.8.13 Texture completeness
1767TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1768{
1769 if (IsOSX())
1770 {
1771 // Observed incorrect rendering on OSX.
1772 std::cout << "Test skipped on OSX." << std::endl;
1773 return;
1774 }
1775 glActiveTexture(GL_TEXTURE0);
1776 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1777 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1778 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1779 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1780
1781 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1782 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1783
1784 // Two levels that are initially unused.
1785 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1786 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1787 texDataCyan.data());
1788
1789 // One level that is used - only this level should affect completeness.
1790 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1791 texDataGreen.data());
1792
1793 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1794 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1795
1796 EXPECT_GL_NO_ERROR();
1797
1798 drawQuad(mProgram, "position", 0.5f);
1799
1800 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1801
1802 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1803 {
1804 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
1805 // level was changed.
1806 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
1807 return;
1808 }
1809
1810 // Switch the level that is being used to the cyan level 2.
1811 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1812 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1813
1814 EXPECT_GL_NO_ERROR();
1815
1816 drawQuad(mProgram, "position", 0.5f);
1817
1818 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1819}
1820
1821// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1822// have images defined.
1823TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1824{
1825 if (IsOSX())
1826 {
1827 // Observed incorrect rendering on OSX.
1828 std::cout << "Test skipped on OSX." << std::endl;
1829 return;
1830 }
1831 glActiveTexture(GL_TEXTURE0);
1832 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1833 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1834 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1835 texDataGreen.data());
1836 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1837 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1838 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1839 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1840
1841 EXPECT_GL_NO_ERROR();
1842
1843 drawQuad(mProgram, "position", 0.5f);
1844
1845 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1846}
1847
1848// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1849// dimensions that don't fit the images inside the range.
1850// GLES 3.0.4 section 3.8.13 Texture completeness
1851TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1852{
1853 if (IsOSX())
1854 {
1855 // Observed incorrect rendering on OSX.
1856 std::cout << "Test skipped on OSX." << std::endl;
1857 return;
1858 }
1859 glActiveTexture(GL_TEXTURE0);
1860 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1861 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1862 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1863 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1864
1865 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1866 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1867
1868 // Two levels that are initially unused.
1869 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1870 texDataRed.data());
1871 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1872 texDataCyan.data());
1873
1874 // One level that is used - only this level should affect completeness.
1875 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1876 texDataGreen.data());
1877
1878 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1879 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1880
1881 EXPECT_GL_NO_ERROR();
1882
1883 drawQuad(mProgram, "position", 0.5f);
1884
1885 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1886
1887 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1888 {
1889 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
1890 // level was changed.
1891 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
1892 return;
1893 }
1894
1895 // Switch the level that is being used to the cyan level 2.
1896 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
1897 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
1898
1899 EXPECT_GL_NO_ERROR();
1900
1901 drawQuad(mProgram, "position", 0.5f);
1902
1903 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1904}
1905
1906// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1907// have images defined.
1908TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
1909{
1910 if (IsOSX())
1911 {
1912 // Observed incorrect rendering on OSX.
1913 std::cout << "Test skipped on OSX." << std::endl;
1914 return;
1915 }
1916 glActiveTexture(GL_TEXTURE0);
1917 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
1918 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1919 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1920 texDataGreen.data());
1921 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1922 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1923 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1924 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1925
1926 EXPECT_GL_NO_ERROR();
1927
1928 drawQuad(mProgram, "position", 0.5f);
1929
1930 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1931}
1932
1933// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1934// dimensions that don't fit the images inside the range.
1935// GLES 3.0.4 section 3.8.13 Texture completeness
1936TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1937{
1938 if (IsOSX())
1939 {
1940 // Observed incorrect rendering on OSX.
1941 std::cout << "Test skipped on OSX." << std::endl;
1942 return;
1943 }
1944 glActiveTexture(GL_TEXTURE0);
1945 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
1946 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1947 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1948 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1949
1950 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1951 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1952
1953 // Two levels that are initially unused.
1954 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1955 texDataRed.data());
1956 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1957 texDataCyan.data());
1958
1959 // One level that is used - only this level should affect completeness.
1960 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1961 texDataGreen.data());
1962
1963 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1964 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1965
1966 EXPECT_GL_NO_ERROR();
1967
1968 drawQuad(mProgram, "position", 0.5f);
1969
1970 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1971
1972 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1973 {
1974 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
1975 // level was changed.
1976 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
1977 return;
1978 }
1979 if (IsNVIDIA() && (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
1980 getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE))
1981 {
1982 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
1983 // level was changed.
1984 std::cout << "Test partially skipped on NVIDIA OpenGL." << std::endl;
1985 return;
1986 }
1987
1988 // Switch the level that is being used to the cyan level 2.
1989 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
1990 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
1991
1992 EXPECT_GL_NO_ERROR();
1993
1994 drawQuad(mProgram, "position", 0.5f);
1995
1996 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1997}
1998
1999// Test that texture completeness is updated if texture max level changes.
2000// GLES 3.0.4 section 3.8.13 Texture completeness
2001TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2002{
2003 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2004 {
2005 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2006 // the base level.
2007 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2008 return;
2009 }
2010 if (IsOSX())
2011 {
2012 // Observed incorrect rendering on OSX.
2013 std::cout << "Test skipped on OSX." << std::endl;
2014 return;
2015 }
2016
2017 glActiveTexture(GL_TEXTURE0);
2018 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2019 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2020
2021 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2022 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2023
2024 // A level that is initially unused.
2025 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2026 texDataGreen.data());
2027
2028 // One level that is initially used - only this level should affect completeness.
2029 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2030 texDataGreen.data());
2031
2032 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2033 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2034
2035 EXPECT_GL_NO_ERROR();
2036
2037 drawQuad(mProgram, "position", 0.5f);
2038
2039 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2040
2041 // Switch the max level to level 1. The levels within the used range now have inconsistent
2042 // dimensions and the texture should be incomplete.
2043 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2044
2045 EXPECT_GL_NO_ERROR();
2046
2047 drawQuad(mProgram, "position", 0.5f);
2048
2049 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2050}
2051
2052// Test that 3D texture completeness is updated if texture max level changes.
2053// GLES 3.0.4 section 3.8.13 Texture completeness
2054TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2055{
2056 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2057 {
2058 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2059 // the base level.
2060 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2061 return;
2062 }
2063 if (IsOSX())
2064 {
2065 // Observed incorrect rendering on OSX.
2066 std::cout << "Test skipped on OSX." << std::endl;
2067 return;
2068 }
2069
2070 glActiveTexture(GL_TEXTURE0);
2071 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2072 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2073
2074 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2075 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2076
2077 // A level that is initially unused.
2078 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2079 texDataGreen.data());
2080
2081 // One level that is initially used - only this level should affect completeness.
2082 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2083 texDataGreen.data());
2084
2085 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2086 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2087
2088 EXPECT_GL_NO_ERROR();
2089
2090 drawQuad(mProgram, "position", 0.5f);
2091
2092 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2093
2094 // Switch the max level to level 1. The levels within the used range now have inconsistent
2095 // dimensions and the texture should be incomplete.
2096 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2097
2098 EXPECT_GL_NO_ERROR();
2099
2100 drawQuad(mProgram, "position", 0.5f);
2101
2102 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2103}
2104
2105// Test that texture completeness is updated if texture base level changes.
2106// GLES 3.0.4 section 3.8.13 Texture completeness
2107TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2108{
2109 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2110 {
2111 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2112 // the base level.
2113 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2114 return;
2115 }
2116
2117 glActiveTexture(GL_TEXTURE0);
2118 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2119 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2120
2121 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2122 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2123
2124 // Two levels that are initially unused.
2125 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2126 texDataGreen.data());
2127 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2128 texDataGreen.data());
2129
2130 // One level that is initially used - only this level should affect completeness.
2131 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2132 texDataGreen.data());
2133
2134 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2135 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2136
2137 EXPECT_GL_NO_ERROR();
2138
2139 drawQuad(mProgram, "position", 0.5f);
2140
2141 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2142
2143 // Switch the base level to level 1. The levels within the used range now have inconsistent
2144 // dimensions and the texture should be incomplete.
2145 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2146
2147 EXPECT_GL_NO_ERROR();
2148
2149 drawQuad(mProgram, "position", 0.5f);
2150
2151 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2152}
2153
2154// Test that texture is not complete if base level is greater than max level.
2155// GLES 3.0.4 section 3.8.13 Texture completeness
2156TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2157{
2158 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2159 {
2160 // Intel Windows OpenGL driver crashes if the base level of a non-immutable texture is out
2161 // of range.
2162 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2163 return;
2164 }
2165
2166 glActiveTexture(GL_TEXTURE0);
2167 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2168
2169 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2170 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2171
2172 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2173
2174 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2175 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2176
2177 EXPECT_GL_NO_ERROR();
2178
2179 drawQuad(mProgram, "position", 0.5f);
2180
2181 // Texture should be incomplete.
2182 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2183}
2184
2185// Test that immutable texture base level and max level are clamped.
2186// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2187TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2188{
Olli Etuahoa314b612016-03-10 16:43:00 +02002189 glActiveTexture(GL_TEXTURE0);
2190 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2191
2192 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2193 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2194
2195 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2196
2197 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2198
2199 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2200 // should be clamped to [base_level, levels - 1].
2201 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2202 // In the case of this test, those rules make the effective base level and max level 0.
2203 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2204 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2205
2206 EXPECT_GL_NO_ERROR();
2207
2208 drawQuad(mProgram, "position", 0.5f);
2209
2210 // Texture should be complete.
2211 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2212}
2213
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002214// Test that changing base level works when it affects the format of the texture.
2215TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2216{
2217 if (IsNVIDIA() && (isOpenGL() || isGLES()))
2218 {
2219 // Observed rendering corruption on NVIDIA OpenGL.
2220 std::cout << "Test skipped on NVIDIA OpenGL." << std::endl;
2221 return;
2222 }
2223 if (IsIntel() && isOpenGL())
2224 {
2225 // Observed incorrect rendering on Intel OpenGL.
2226 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2227 return;
2228 }
2229 if (IsAMD() && isOpenGL())
2230 {
2231 // Observed incorrect rendering on AMD OpenGL.
2232 std::cout << "Test skipped on AMD OpenGL." << std::endl;
2233 return;
2234 }
2235
2236 glActiveTexture(GL_TEXTURE0);
2237 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2238 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2239 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2240
2241 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2242 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2243
2244 // RGBA8 level that's initially unused.
2245 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2246 texDataCyan.data());
2247
2248 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2249 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2250
2251 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2252 // format. It reads green channel data from the green and alpha channels of texDataGreen
2253 // (this is a bit hacky but works).
2254 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2255
2256 EXPECT_GL_NO_ERROR();
2257
2258 drawQuad(mProgram, "position", 0.5f);
2259
2260 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2261
2262 // Switch the texture to use the cyan level 0 with the RGBA format.
2263 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2264 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2265
2266 EXPECT_GL_NO_ERROR();
2267
2268 drawQuad(mProgram, "position", 0.5f);
2269
2270 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2271}
2272
Olli Etuahoa314b612016-03-10 16:43:00 +02002273// Test that setting a texture image works when base level is out of range.
2274TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2275{
2276 glActiveTexture(GL_TEXTURE0);
2277 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2278
2279 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2280 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2281
2282 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2283 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2284
2285 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2286
2287 EXPECT_GL_NO_ERROR();
2288
2289 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2290
2291 drawQuad(mProgram, "position", 0.5f);
2292
2293 // Texture should be complete.
2294 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002295}
2296
Jamie Madill2453dbc2015-07-14 11:35:42 -04002297// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG RBA->RGBA8, with 1.0
2298// in the alpha channel. This test covers a bug where redefining array textures with these formats does not work as
2299// expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002300TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002301{
2302 std::vector<GLubyte> pixelData;
2303 for (size_t count = 0; count < 5000; count++)
2304 {
2305 pixelData.push_back(0u);
2306 pixelData.push_back(255u);
2307 pixelData.push_back(0u);
2308 }
2309
2310 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002311 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002312 glUniform1i(mTextureArrayLocation, 0);
2313
2314 // The first draw worked correctly.
2315 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
2316
2317 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2318 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2319 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2320 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002321 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002322 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002323
2324 // The dimension of the respecification must match the original exactly to trigger the bug.
2325 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 +02002326 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002327 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002328
2329 ASSERT_GL_NO_ERROR();
2330}
2331
Olli Etuaho1a679902016-01-14 12:21:47 +02002332// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2333// This test is needed especially to confirm that sampler registers get assigned correctly on
2334// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2335TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2336{
2337 glActiveTexture(GL_TEXTURE0);
2338 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2339 GLubyte texData[4];
2340 texData[0] = 0;
2341 texData[1] = 60;
2342 texData[2] = 0;
2343 texData[3] = 255;
2344 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2345
2346 glActiveTexture(GL_TEXTURE1);
2347 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2348 GLfloat depthTexData[1];
2349 depthTexData[0] = 0.5f;
2350 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2351 depthTexData);
2352
2353 glUseProgram(mProgram);
2354 glUniform1f(mDepthRefUniformLocation, 0.3f);
2355 glUniform1i(mTexture3DUniformLocation, 0);
2356 glUniform1i(mTextureShadowUniformLocation, 1);
2357
2358 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2359 drawQuad(mProgram, "position", 0.5f);
2360 EXPECT_GL_NO_ERROR();
2361 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2362 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2363
2364 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2365 drawQuad(mProgram, "position", 0.5f);
2366 EXPECT_GL_NO_ERROR();
2367 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2368 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2369}
2370
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002371// Test multiple different sampler types in the same shader.
2372// This test makes sure that even if sampler / texture registers get grouped together based on type
2373// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2374// still has the right register index information for each ESSL sampler.
2375// The tested ESSL samplers have the following types in D3D11 HLSL:
2376// sampler2D: Texture2D + SamplerState
2377// samplerCube: TextureCube + SamplerState
2378// sampler2DShadow: Texture2D + SamplerComparisonState
2379// samplerCubeShadow: TextureCube + SamplerComparisonState
2380TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2381{
2382 glActiveTexture(GL_TEXTURE0);
2383 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2384 GLubyte texData[4];
2385 texData[0] = 0;
2386 texData[1] = 0;
2387 texData[2] = 120;
2388 texData[3] = 255;
2389 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2390
2391 glActiveTexture(GL_TEXTURE1);
2392 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2393 texData[0] = 0;
2394 texData[1] = 90;
2395 texData[2] = 0;
2396 texData[3] = 255;
2397 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2398 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2399 texData);
2400
2401 glActiveTexture(GL_TEXTURE2);
2402 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2403 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2404 GLfloat depthTexData[1];
2405 depthTexData[0] = 0.5f;
2406 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2407 depthTexData);
2408
2409 glActiveTexture(GL_TEXTURE3);
2410 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2411 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2412 depthTexData[0] = 0.2f;
2413 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2414 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2415 depthTexData);
2416
2417 EXPECT_GL_NO_ERROR();
2418
2419 glUseProgram(mProgram);
2420 glUniform1f(mDepthRefUniformLocation, 0.3f);
2421 glUniform1i(mTexture2DUniformLocation, 0);
2422 glUniform1i(mTextureCubeUniformLocation, 1);
2423 glUniform1i(mTexture2DShadowUniformLocation, 2);
2424 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2425
2426 drawQuad(mProgram, "position", 0.5f);
2427 EXPECT_GL_NO_ERROR();
2428 // The shader writes:
2429 // <texture 2d color> +
2430 // <cube map color> +
2431 // 0.25 * <comparison result (1.0)> +
2432 // 0.125 * <comparison result (0.0)>
2433 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2434}
2435
Olli Etuahobce743a2016-01-15 17:18:28 +02002436// Test different base levels on textures accessed through the same sampler array.
2437// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2438TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2439{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002440 if ((IsAMD() || IsIntel()) && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
Olli Etuahobce743a2016-01-15 17:18:28 +02002441 {
2442 std::cout << "Test skipped on Intel and AMD D3D." << std::endl;
2443 return;
2444 }
2445 glActiveTexture(GL_TEXTURE0);
2446 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2447 GLsizei size = 64;
2448 for (GLint level = 0; level < 7; ++level)
2449 {
2450 ASSERT_LT(0, size);
2451 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2452 nullptr);
2453 size = size / 2;
2454 }
2455 ASSERT_EQ(0, size);
2456 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2457
2458 glActiveTexture(GL_TEXTURE1);
2459 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2460 size = 128;
2461 for (GLint level = 0; level < 8; ++level)
2462 {
2463 ASSERT_LT(0, size);
2464 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2465 nullptr);
2466 size = size / 2;
2467 }
2468 ASSERT_EQ(0, size);
2469 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2470 EXPECT_GL_NO_ERROR();
2471
2472 glUseProgram(mProgram);
2473 glUniform1i(mTexture0Location, 0);
2474 glUniform1i(mTexture1Location, 1);
2475
2476 drawQuad(mProgram, "position", 0.5f);
2477 EXPECT_GL_NO_ERROR();
2478 // Red channel: width of level 1 of texture A: 32.
2479 // Green channel: width of level 3 of texture B: 16.
2480 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2481}
2482
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002483// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2484// ES 3.0.4 table 3.24
2485TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2486{
2487 glActiveTexture(GL_TEXTURE0);
2488 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2489 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2490 EXPECT_GL_NO_ERROR();
2491
2492 drawQuad(mProgram, "position", 0.5f);
2493
2494 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2495}
2496
2497// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2498// ES 3.0.4 table 3.24
2499TEST_P(Texture2DTestES3, TextureLuminanceImplicitAlpha1)
2500{
2501 glActiveTexture(GL_TEXTURE0);
2502 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2503 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2504 EXPECT_GL_NO_ERROR();
2505
2506 drawQuad(mProgram, "position", 0.5f);
2507
2508 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2509}
2510
2511// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2512// ES 3.0.4 table 3.24
2513TEST_P(Texture2DTestES3, TextureLuminance32ImplicitAlpha1)
2514{
2515 if (extensionEnabled("GL_OES_texture_float"))
2516 {
2517 glActiveTexture(GL_TEXTURE0);
2518 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2519 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2520 EXPECT_GL_NO_ERROR();
2521
2522 drawQuad(mProgram, "position", 0.5f);
2523
2524 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2525 }
2526}
2527
2528// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2529// ES 3.0.4 table 3.24
2530TEST_P(Texture2DTestES3, TextureLuminance16ImplicitAlpha1)
2531{
2532 if (extensionEnabled("GL_OES_texture_half_float"))
2533 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002534 if (IsNVIDIA() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002535 {
2536 std::cout << "Test skipped on NVIDIA" << std::endl;
2537 return;
2538 }
2539 glActiveTexture(GL_TEXTURE0);
2540 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2541 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES,
2542 nullptr);
2543 EXPECT_GL_NO_ERROR();
2544
2545 drawQuad(mProgram, "position", 0.5f);
2546
2547 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2548 }
2549}
2550
2551// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2552// ES 3.0.4 table 3.24
2553TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2554{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002555 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002556 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002557 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002558 return;
2559 }
2560 glActiveTexture(GL_TEXTURE0);
2561 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2562 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2563 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2564 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2565 EXPECT_GL_NO_ERROR();
2566
2567 drawQuad(mProgram, "position", 0.5f);
2568
2569 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2570}
2571
2572// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2573// ES 3.0.4 table 3.24
2574TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2575{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002576 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002577 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002578 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002579 return;
2580 }
2581 glActiveTexture(GL_TEXTURE0);
2582 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2583
2584 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2585 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2586 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2587 EXPECT_GL_NO_ERROR();
2588
2589 drawQuad(mProgram, "position", 0.5f);
2590
2591 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2592}
2593
2594// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2595// ES 3.0.4 table 3.24
2596TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2597{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002598 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002599 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002600 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002601 return;
2602 }
2603 glActiveTexture(GL_TEXTURE0);
2604 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2605 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2606 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2607 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2608 EXPECT_GL_NO_ERROR();
2609
2610 drawQuad(mProgram, "position", 0.5f);
2611
2612 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2613}
2614
2615// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2616// ES 3.0.4 table 3.24
2617TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2618{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002619 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002620 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002621 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002622 return;
2623 }
2624 glActiveTexture(GL_TEXTURE0);
2625 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2626 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2627 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2628 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2629 EXPECT_GL_NO_ERROR();
2630
2631 drawQuad(mProgram, "position", 0.5f);
2632
2633 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2634}
2635
2636// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2637// ES 3.0.4 table 3.24
2638TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2639{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002640 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002641 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002642 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002643 return;
2644 }
2645 glActiveTexture(GL_TEXTURE0);
2646 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2647 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2648 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2649 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2650 EXPECT_GL_NO_ERROR();
2651
2652 drawQuad(mProgram, "position", 0.5f);
2653
2654 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2655}
2656
2657// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2658// ES 3.0.4 table 3.24
2659TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2660{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002661 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002662 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002663 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002664 return;
2665 }
2666 glActiveTexture(GL_TEXTURE0);
2667 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2668 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2669 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2670 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2671 EXPECT_GL_NO_ERROR();
2672
2673 drawQuad(mProgram, "position", 0.5f);
2674
2675 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2676}
2677
2678// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2679// ES 3.0.4 table 3.24
2680TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2681{
2682 glActiveTexture(GL_TEXTURE0);
2683 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2684 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2685 EXPECT_GL_NO_ERROR();
2686
2687 drawQuad(mProgram, "position", 0.5f);
2688
2689 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2690}
2691
2692// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2693// ES 3.0.4 table 3.24
2694TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2695{
2696 glActiveTexture(GL_TEXTURE0);
2697 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2698 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2699 nullptr);
2700 EXPECT_GL_NO_ERROR();
2701
2702 drawQuad(mProgram, "position", 0.5f);
2703
2704 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2705}
2706
2707// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2708// ES 3.0.4 table 3.24
2709TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2710{
2711 glActiveTexture(GL_TEXTURE0);
2712 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2713 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2714 EXPECT_GL_NO_ERROR();
2715
2716 drawQuad(mProgram, "position", 0.5f);
2717
2718 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2719}
2720
2721// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2722// ES 3.0.4 table 3.24
2723TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2724{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002725 if (IsIntel() && IsLinux())
2726 {
2727 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
2728 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
2729 return;
2730 }
2731
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002732 glActiveTexture(GL_TEXTURE0);
2733 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2734 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2735 EXPECT_GL_NO_ERROR();
2736
2737 drawQuad(mProgram, "position", 0.5f);
2738
2739 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2740}
2741
Olli Etuaho96963162016-03-21 11:54:33 +02002742// Use a sampler in a uniform struct.
2743TEST_P(SamplerInStructTest, SamplerInStruct)
2744{
2745 runSamplerInStructTest();
2746}
2747
2748// Use a sampler in a uniform struct that's passed as a function parameter.
2749TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2750{
2751 runSamplerInStructTest();
2752}
2753
2754// Use a sampler in a uniform struct array with a struct from the array passed as a function
2755// parameter.
2756TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2757{
Olli Etuahoa1c917f2016-04-06 13:50:03 +03002758 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2759 {
2760 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2761 return;
2762 }
Olli Etuaho96963162016-03-21 11:54:33 +02002763 runSamplerInStructTest();
2764}
2765
2766// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2767// parameter.
2768TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2769{
Olli Etuahoa1c917f2016-04-06 13:50:03 +03002770 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2771 {
2772 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2773 return;
2774 }
Olli Etuaho96963162016-03-21 11:54:33 +02002775 runSamplerInStructTest();
2776}
2777
2778// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2779// similarly named uniform.
2780TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2781{
2782 runSamplerInStructTest();
2783}
2784
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002785class TextureLimitsTest : public ANGLETest
2786{
2787 protected:
2788 struct RGBA8
2789 {
2790 uint8_t R, G, B, A;
2791 };
2792
2793 TextureLimitsTest()
2794 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
2795 {
2796 setWindowWidth(128);
2797 setWindowHeight(128);
2798 setConfigRedBits(8);
2799 setConfigGreenBits(8);
2800 setConfigBlueBits(8);
2801 setConfigAlphaBits(8);
2802 }
2803
2804 ~TextureLimitsTest()
2805 {
2806 if (mProgram != 0)
2807 {
2808 glDeleteProgram(mProgram);
2809 mProgram = 0;
2810
2811 if (!mTextures.empty())
2812 {
2813 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
2814 }
2815 }
2816 }
2817
2818 void SetUp() override
2819 {
2820 ANGLETest::SetUp();
2821
2822 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
2823 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
2824 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
2825
2826 ASSERT_GL_NO_ERROR();
2827 }
2828
2829 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
2830 GLint vertexTextureCount,
2831 GLint vertexActiveTextureCount,
2832 const std::string &fragPrefix,
2833 GLint fragmentTextureCount,
2834 GLint fragmentActiveTextureCount)
2835 {
2836 std::stringstream vertexShaderStr;
2837 vertexShaderStr << "attribute vec2 position;\n"
2838 << "varying vec4 color;\n"
2839 << "varying vec2 texCoord;\n";
2840
2841 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
2842 {
2843 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
2844 }
2845
2846 vertexShaderStr << "void main() {\n"
2847 << " gl_Position = vec4(position, 0, 1);\n"
2848 << " texCoord = (position * 0.5) + 0.5;\n"
2849 << " color = vec4(0);\n";
2850
2851 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
2852 {
2853 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
2854 << ", texCoord);\n";
2855 }
2856
2857 vertexShaderStr << "}";
2858
2859 std::stringstream fragmentShaderStr;
2860 fragmentShaderStr << "varying mediump vec4 color;\n"
2861 << "varying mediump vec2 texCoord;\n";
2862
2863 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
2864 {
2865 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
2866 }
2867
2868 fragmentShaderStr << "void main() {\n"
2869 << " gl_FragColor = color;\n";
2870
2871 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
2872 {
2873 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
2874 << ", texCoord);\n";
2875 }
2876
2877 fragmentShaderStr << "}";
2878
2879 const std::string &vertexShaderSource = vertexShaderStr.str();
2880 const std::string &fragmentShaderSource = fragmentShaderStr.str();
2881
2882 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
2883 }
2884
2885 RGBA8 getPixel(GLint texIndex)
2886 {
2887 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
2888 0, 255u};
2889 return pixel;
2890 }
2891
2892 void initTextures(GLint tex2DCount, GLint texCubeCount)
2893 {
2894 GLint totalCount = tex2DCount + texCubeCount;
2895 mTextures.assign(totalCount, 0);
2896 glGenTextures(totalCount, &mTextures[0]);
2897 ASSERT_GL_NO_ERROR();
2898
2899 std::vector<RGBA8> texData(16 * 16);
2900
2901 GLint texIndex = 0;
2902 for (; texIndex < tex2DCount; ++texIndex)
2903 {
2904 texData.assign(texData.size(), getPixel(texIndex));
2905 glActiveTexture(GL_TEXTURE0 + texIndex);
2906 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
2907 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2908 &texData[0]);
2909 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2910 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2911 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2912 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2913 }
2914
2915 ASSERT_GL_NO_ERROR();
2916
2917 for (; texIndex < texCubeCount; ++texIndex)
2918 {
2919 texData.assign(texData.size(), getPixel(texIndex));
2920 glActiveTexture(GL_TEXTURE0 + texIndex);
2921 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
2922 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2923 GL_UNSIGNED_BYTE, &texData[0]);
2924 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2925 GL_UNSIGNED_BYTE, &texData[0]);
2926 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2927 GL_UNSIGNED_BYTE, &texData[0]);
2928 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2929 GL_UNSIGNED_BYTE, &texData[0]);
2930 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2931 GL_UNSIGNED_BYTE, &texData[0]);
2932 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2933 GL_UNSIGNED_BYTE, &texData[0]);
2934 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2935 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2936 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2937 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2938 }
2939
2940 ASSERT_GL_NO_ERROR();
2941 }
2942
2943 void testWithTextures(GLint vertexTextureCount,
2944 const std::string &vertexTexturePrefix,
2945 GLint fragmentTextureCount,
2946 const std::string &fragmentTexturePrefix)
2947 {
2948 // Generate textures
2949 initTextures(vertexTextureCount + fragmentTextureCount, 0);
2950
2951 glUseProgram(mProgram);
2952 RGBA8 expectedSum = {0};
2953 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
2954 {
2955 std::stringstream uniformNameStr;
2956 uniformNameStr << vertexTexturePrefix << texIndex;
2957 const std::string &uniformName = uniformNameStr.str();
2958 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
2959 ASSERT_NE(-1, location);
2960
2961 glUniform1i(location, texIndex);
2962 RGBA8 contribution = getPixel(texIndex);
2963 expectedSum.R += contribution.R;
2964 expectedSum.G += contribution.G;
2965 }
2966
2967 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
2968 {
2969 std::stringstream uniformNameStr;
2970 uniformNameStr << fragmentTexturePrefix << texIndex;
2971 const std::string &uniformName = uniformNameStr.str();
2972 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
2973 ASSERT_NE(-1, location);
2974
2975 glUniform1i(location, texIndex + vertexTextureCount);
2976 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
2977 expectedSum.R += contribution.R;
2978 expectedSum.G += contribution.G;
2979 }
2980
2981 ASSERT_GE(256u, expectedSum.G);
2982
2983 drawQuad(mProgram, "position", 0.5f);
2984 ASSERT_GL_NO_ERROR();
2985 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
2986 }
2987
2988 GLuint mProgram;
2989 std::vector<GLuint> mTextures;
2990 GLint mMaxVertexTextures;
2991 GLint mMaxFragmentTextures;
2992 GLint mMaxCombinedTextures;
2993};
2994
2995// Test rendering with the maximum vertex texture units.
2996TEST_P(TextureLimitsTest, MaxVertexTextures)
2997{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04002998 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05002999 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003000 {
3001 std::cout << "Test skipped on Intel." << std::endl;
3002 return;
3003 }
3004
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003005 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3006 ASSERT_NE(0u, mProgram);
3007 ASSERT_GL_NO_ERROR();
3008
3009 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3010}
3011
3012// Test rendering with the maximum fragment texture units.
3013TEST_P(TextureLimitsTest, MaxFragmentTextures)
3014{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003015 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003016 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003017 {
3018 std::cout << "Test skipped on Intel." << std::endl;
3019 return;
3020 }
3021
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003022 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3023 ASSERT_NE(0u, mProgram);
3024 ASSERT_GL_NO_ERROR();
3025
3026 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3027}
3028
3029// Test rendering with maximum combined texture units.
3030TEST_P(TextureLimitsTest, MaxCombinedTextures)
3031{
Jamie Madill412f17d2015-09-25 08:43:54 -04003032 // TODO(jmadill): Investigate workaround.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003033 if (IsIntel() && GetParam() == ES2_OPENGL())
Jamie Madill412f17d2015-09-25 08:43:54 -04003034 {
3035 std::cout << "Test skipped on Intel." << std::endl;
3036 return;
3037 }
3038
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003039 GLint vertexTextures = mMaxVertexTextures;
3040
3041 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3042 {
3043 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3044 }
3045
3046 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3047 mMaxFragmentTextures, mMaxFragmentTextures);
3048 ASSERT_NE(0u, mProgram);
3049 ASSERT_GL_NO_ERROR();
3050
3051 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3052}
3053
3054// Negative test for exceeding the number of vertex textures
3055TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3056{
3057 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3058 0);
3059 ASSERT_EQ(0u, mProgram);
3060}
3061
3062// Negative test for exceeding the number of fragment textures
3063TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3064{
3065 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3066 mMaxFragmentTextures + 1);
3067 ASSERT_EQ(0u, mProgram);
3068}
3069
3070// Test active vertex textures under the limit, but excessive textures specified.
3071TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3072{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003073 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003074 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003075 {
3076 std::cout << "Test skipped on Intel." << std::endl;
3077 return;
3078 }
3079
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003080 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3081 ASSERT_NE(0u, mProgram);
3082 ASSERT_GL_NO_ERROR();
3083
3084 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3085}
3086
3087// Test active fragment textures under the limit, but excessive textures specified.
3088TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3089{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003090 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003091 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003092 {
3093 std::cout << "Test skipped on Intel." << std::endl;
3094 return;
3095 }
3096
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003097 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3098 mMaxFragmentTextures);
3099 ASSERT_NE(0u, mProgram);
3100 ASSERT_GL_NO_ERROR();
3101
3102 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3103}
3104
3105// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003106// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003107TEST_P(TextureLimitsTest, TextureTypeConflict)
3108{
3109 const std::string &vertexShader =
3110 "attribute vec2 position;\n"
3111 "varying float color;\n"
3112 "uniform sampler2D tex2D;\n"
3113 "uniform samplerCube texCube;\n"
3114 "void main() {\n"
3115 " gl_Position = vec4(position, 0, 1);\n"
3116 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3117 " color = texture2D(tex2D, texCoord).x;\n"
3118 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3119 "}";
3120 const std::string &fragmentShader =
3121 "varying mediump float color;\n"
3122 "void main() {\n"
3123 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3124 "}";
3125
3126 mProgram = CompileProgram(vertexShader, fragmentShader);
3127 ASSERT_NE(0u, mProgram);
3128
3129 initTextures(1, 0);
3130
3131 glUseProgram(mProgram);
3132 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3133 ASSERT_NE(-1, tex2DLocation);
3134 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3135 ASSERT_NE(-1, texCubeLocation);
3136
3137 glUniform1i(tex2DLocation, 0);
3138 glUniform1i(texCubeLocation, 0);
3139 ASSERT_GL_NO_ERROR();
3140
3141 drawQuad(mProgram, "position", 0.5f);
3142 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3143}
3144
3145// Negative test for rendering with texture outside the valid range.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003146// TODO(jmadill): Possibly adjust the test according to the spec:
3147// GLES 3.0.4 section 2.12.7 mentions that specifying an out-of-range sampler uniform value
3148// generates an INVALID_VALUE error - GLES 2.0 doesn't yet have this mention.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003149TEST_P(TextureLimitsTest, DrawWithTexturePastMaximum)
3150{
3151 const std::string &vertexShader =
3152 "attribute vec2 position;\n"
3153 "varying float color;\n"
3154 "uniform sampler2D tex2D;\n"
3155 "void main() {\n"
3156 " gl_Position = vec4(position, 0, 1);\n"
3157 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3158 " color = texture2D(tex2D, texCoord).x;\n"
3159 "}";
3160 const std::string &fragmentShader =
3161 "varying mediump float color;\n"
3162 "void main() {\n"
3163 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3164 "}";
3165
3166 mProgram = CompileProgram(vertexShader, fragmentShader);
3167 ASSERT_NE(0u, mProgram);
3168
3169 glUseProgram(mProgram);
3170 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3171 ASSERT_NE(-1, tex2DLocation);
3172
3173 glUniform1i(tex2DLocation, mMaxCombinedTextures);
3174 ASSERT_GL_NO_ERROR();
3175
3176 drawQuad(mProgram, "position", 0.5f);
3177 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3178}
3179
Vincent Lang25ab4512016-05-13 18:13:59 +02003180class Texture2DNorm16TestES3 : public Texture2DTestES3
3181{
3182 protected:
3183 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3184
3185 void SetUp() override
3186 {
3187 Texture2DTestES3::SetUp();
3188
3189 glActiveTexture(GL_TEXTURE0);
3190 glGenTextures(3, mTextures);
3191 glGenFramebuffers(1, &mFBO);
3192 glGenRenderbuffers(1, &mRenderbuffer);
3193
3194 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3195 {
3196 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3197 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3198 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3199 }
3200
3201 glBindTexture(GL_TEXTURE_2D, 0);
3202
3203 ASSERT_GL_NO_ERROR();
3204 }
3205
3206 void TearDown() override
3207 {
3208 glDeleteTextures(3, mTextures);
3209 glDeleteFramebuffers(1, &mFBO);
3210 glDeleteRenderbuffers(1, &mRenderbuffer);
3211
3212 Texture2DTestES3::TearDown();
3213 }
3214
3215 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3216 {
3217 GLushort pixelValue = type == GL_SHORT ? 0x7FFF : 0x6A35;
3218 GLColor16 imageData(pixelValue, pixelValue, pixelValue, pixelValue);
3219
3220 setUpProgram();
3221
3222 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3223 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3224 0);
3225
3226 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3227 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3228
3229 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3230 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, &imageData.R);
3231
3232 EXPECT_GL_NO_ERROR();
3233
3234 drawQuad(mProgram, "position", 0.5f);
3235
3236 GLColor16 expectedValue = imageData;
3237 if (type == GL_SHORT)
3238 {
3239 // sampled as signed value; then stored as unsigned value
3240 expectedValue = GLColor16::white;
3241 }
3242
3243 EXPECT_PIXEL_COLOR16_EQ(0, 0, SliceFormatColor16(format, expectedValue));
3244
3245 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3246
3247 ASSERT_GL_NO_ERROR();
3248 }
3249
3250 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3251 {
3252 GLushort pixelValue = 0x6A35;
3253 GLColor16 imageData(pixelValue, pixelValue, pixelValue, pixelValue);
3254
3255 setUpProgram();
3256
3257 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3258 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3259
3260 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3261 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3262 0);
3263
3264 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
3265 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, &imageData.R);
3266
3267 EXPECT_GL_NO_ERROR();
3268
3269 drawQuad(mProgram, "position", 0.5f);
3270
3271 EXPECT_PIXEL_COLOR16_EQ(0, 0, SliceFormatColor16(format, imageData));
3272
3273 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3274 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3275 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3276 mRenderbuffer);
3277 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3278 EXPECT_GL_NO_ERROR();
3279
3280 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3281 glClear(GL_COLOR_BUFFER_BIT);
3282
3283 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3284
3285 GLColor16 expectedValue = GLColor16::white;
3286 EXPECT_PIXEL_COLOR16_EQ(0, 0, SliceFormatColor16(format, expectedValue));
3287
3288 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3289
3290 ASSERT_GL_NO_ERROR();
3291 }
3292
3293 GLuint mTextures[3];
3294 GLuint mFBO;
3295 GLuint mRenderbuffer;
3296};
3297
3298// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3299TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3300{
3301 if (!extensionEnabled("GL_EXT_texture_norm16"))
3302 {
3303 std::cout << "Test skipped due to missing GL_EXT_texture_norm16." << std::endl;
3304 return;
3305 }
3306
3307 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3308 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3309 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3310 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3311 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3312 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3313 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3314 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3315
3316 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3317 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3318 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3319}
3320
Jamie Madillfa05f602015-05-07 13:47:11 -04003321// 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 +02003322// TODO(oetuaho): Enable all below tests on OpenGL. Requires a fix for ANGLE bug 1278.
Geoff Lange0cc2a42016-01-20 10:58:17 -05003323ANGLE_INSTANTIATE_TEST(Texture2DTest,
3324 ES2_D3D9(),
3325 ES2_D3D11(),
3326 ES2_D3D11_FL9_3(),
3327 ES2_OPENGL(),
3328 ES2_OPENGLES());
3329ANGLE_INSTANTIATE_TEST(TextureCubeTest,
3330 ES2_D3D9(),
3331 ES2_D3D11(),
3332 ES2_D3D11_FL9_3(),
3333 ES2_OPENGL(),
3334 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003335ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
3336 ES2_D3D9(),
3337 ES2_D3D11(),
3338 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003339 ES2_OPENGL(),
3340 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003341ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
3342 ES2_D3D9(),
3343 ES2_D3D11(),
3344 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003345 ES2_OPENGL(),
3346 ES2_OPENGLES());
3347ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
3348 ES2_D3D9(),
3349 ES2_D3D11(),
3350 ES2_D3D11_FL9_3(),
3351 ES2_OPENGL(),
3352 ES2_OPENGLES());
3353ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
3354 ES2_D3D9(),
3355 ES2_D3D11(),
3356 ES2_D3D11_FL9_3(),
3357 ES2_OPENGL(),
3358 ES2_OPENGLES());
3359ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02003360ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003361ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3362ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
3363 ES3_D3D11(),
3364 ES3_OPENGL(),
3365 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003366ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
3367 ES3_D3D11(),
3368 ES3_OPENGL(),
3369 ES3_OPENGLES());
3370ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3371ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02003372ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02003373ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
3374 ES2_D3D11(),
3375 ES2_D3D11_FL9_3(),
3376 ES2_D3D9(),
3377 ES2_OPENGL(),
3378 ES2_OPENGLES());
3379ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
3380 ES2_D3D11(),
3381 ES2_D3D11_FL9_3(),
3382 ES2_D3D9(),
3383 ES2_OPENGL(),
3384 ES2_OPENGLES());
3385ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
3386 ES2_D3D11(),
3387 ES2_D3D11_FL9_3(),
3388 ES2_D3D9(),
3389 ES2_OPENGL(),
3390 ES2_OPENGLES());
3391ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
3392 ES2_D3D11(),
3393 ES2_D3D11_FL9_3(),
3394 ES2_D3D9(),
3395 ES2_OPENGL(),
3396 ES2_OPENGLES());
3397ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
3398 ES2_D3D11(),
3399 ES2_D3D11_FL9_3(),
3400 ES2_D3D9(),
3401 ES2_OPENGL(),
3402 ES2_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003403ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES());
Vincent Lang25ab4512016-05-13 18:13:59 +02003404ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04003405
3406} // namespace