blob: 914cfbaa00a061fe1b16e9596bdd3204da2e71f1 [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
Olli Etuaho4a8329f2016-01-11 17:12:57 +020014class TexCoordDrawTest : public ANGLETest
Jamie Madillf67115c2014-04-22 13:14:05 -040015{
Jamie Madillbc393df2015-01-29 13:46:07 -050016 protected:
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020017 TexCoordDrawTest() : ANGLETest(), mProgram(0), mFramebuffer(0), mFramebufferColorTexture(0)
Jamie Madillf67115c2014-04-22 13:14:05 -040018 {
19 setWindowWidth(128);
20 setWindowHeight(128);
21 setConfigRedBits(8);
22 setConfigGreenBits(8);
23 setConfigBlueBits(8);
24 setConfigAlphaBits(8);
25 }
26
Olli Etuaho4a8329f2016-01-11 17:12:57 +020027 virtual std::string getVertexShaderSource()
Jamie Madillf67115c2014-04-22 13:14:05 -040028 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +020029 return std::string(SHADER_SOURCE
Geoff Langc41e42d2014-04-28 10:58:16 -040030 (
31 precision highp float;
32 attribute vec4 position;
33 varying vec2 texcoord;
34
35 void main()
36 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +020037 gl_Position = vec4(position.xy, 0.0, 1.0);
Geoff Langc41e42d2014-04-28 10:58:16 -040038 texcoord = (position.xy * 0.5) + 0.5;
39 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +020040 )
Geoff Langc41e42d2014-04-28 10:58:16 -040041 );
Olli Etuaho4a8329f2016-01-11 17:12:57 +020042 }
Geoff Langc41e42d2014-04-28 10:58:16 -040043
Olli Etuaho4a8329f2016-01-11 17:12:57 +020044 virtual std::string getFragmentShaderSource() = 0;
45
46 void SetUp() override
47 {
48 ANGLETest::SetUp();
49 const std::string vertexShaderSource = getVertexShaderSource();
50 const std::string fragmentShaderSource = getFragmentShaderSource();
51
52 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
53 ASSERT_NE(0u, mProgram);
54 ASSERT_GL_NO_ERROR();
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020055
56 setUpFramebuffer();
Olli Etuaho4a8329f2016-01-11 17:12:57 +020057 }
58
59 void TearDown() override
60 {
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020061 glBindFramebuffer(GL_FRAMEBUFFER, 0);
62 glDeleteFramebuffers(1, &mFramebuffer);
63 glDeleteTextures(1, &mFramebufferColorTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +020064 glDeleteProgram(mProgram);
65 ANGLETest::TearDown();
66 }
67
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020068 void setUpFramebuffer()
69 {
70 // We use an FBO to work around an issue where the default framebuffer applies SRGB
71 // conversion (particularly known to happen incorrectly on Intel GL drivers). It's not
72 // clear whether this issue can even be fixed on all backends. For example GLES 3.0.4 spec
73 // section 4.4 says that the format of the default framebuffer is entirely up to the window
74 // system, so it might be SRGB, and GLES 3.0 doesn't have a "FRAMEBUFFER_SRGB" to turn off
75 // SRGB conversion like desktop GL does.
76 // TODO(oetuaho): Get rid of this if the underlying issue is fixed.
77 glGenFramebuffers(1, &mFramebuffer);
78 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
79
80 glGenTextures(1, &mFramebufferColorTexture);
81 glBindTexture(GL_TEXTURE_2D, mFramebufferColorTexture);
82 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
83 GL_UNSIGNED_BYTE, nullptr);
84 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
85 mFramebufferColorTexture, 0);
86 ASSERT_GL_NO_ERROR();
87 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
88 glBindTexture(GL_TEXTURE_2D, 0);
89 }
90
Olli Etuaho4a8329f2016-01-11 17:12:57 +020091 // Returns the created texture ID.
92 GLuint create2DTexture()
93 {
94 GLuint texture2D;
95 glGenTextures(1, &texture2D);
96 glBindTexture(GL_TEXTURE_2D, texture2D);
97 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
98 EXPECT_GL_NO_ERROR();
99 return texture2D;
100 }
101
102 GLuint mProgram;
Olli Etuaho51f1c0f2016-01-13 16:16:24 +0200103 GLuint mFramebuffer;
104
105 private:
106 GLuint mFramebufferColorTexture;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200107};
108
109class Texture2DTest : public TexCoordDrawTest
110{
111 protected:
112 Texture2DTest() : TexCoordDrawTest(), mTexture2D(0), mTexture2DUniformLocation(-1) {}
113
114 std::string getFragmentShaderSource() override
115 {
116 return std::string(SHADER_SOURCE
Geoff Langc41e42d2014-04-28 10:58:16 -0400117 (
118 precision highp float;
119 uniform sampler2D tex;
120 varying vec2 texcoord;
121
122 void main()
123 {
124 gl_FragColor = texture2D(tex, texcoord);
125 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200126 )
Geoff Langc41e42d2014-04-28 10:58:16 -0400127 );
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200128 }
Geoff Langc41e42d2014-04-28 10:58:16 -0400129
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200130 void SetUp() override
131 {
132 TexCoordDrawTest::SetUp();
133 mTexture2D = create2DTexture();
Jamie Madilld4cfa572014-07-08 10:00:32 -0400134
Jamie Madill9aca0592014-10-06 16:26:59 -0400135 ASSERT_GL_NO_ERROR();
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200136
137 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex");
138 ASSERT_NE(-1, mTexture2DUniformLocation);
Jamie Madillf67115c2014-04-22 13:14:05 -0400139 }
140
Jamie Madillfa05f602015-05-07 13:47:11 -0400141 void TearDown() override
Jamie Madillf67115c2014-04-22 13:14:05 -0400142 {
Jamie Madilld4cfa572014-07-08 10:00:32 -0400143 glDeleteTextures(1, &mTexture2D);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200144 TexCoordDrawTest::TearDown();
Jamie Madillf67115c2014-04-22 13:14:05 -0400145 }
146
Jamie Madillbc393df2015-01-29 13:46:07 -0500147 // Tests CopyTexSubImage with floating point textures of various formats.
148 void testFloatCopySubImage(int sourceImageChannels, int destImageChannels)
149 {
Geoff Langbde666a2015-04-07 17:17:08 -0400150 // TODO(jmadill): Figure out why this is broken on Intel D3D11
151 if (isIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
152 {
153 std::cout << "Test skipped on Intel D3D11." << std::endl;
154 return;
155 }
156
Geoff Langfbfa47c2015-03-31 11:26:00 -0400157 if (getClientVersion() < 3)
158 {
159 if (!extensionEnabled("GL_OES_texture_float"))
160 {
161 std::cout << "Test skipped due to missing GL_OES_texture_float." << std::endl;
162 return;
163 }
164
165 if ((sourceImageChannels < 3 || destImageChannels < 3) && !extensionEnabled("GL_EXT_texture_rg"))
166 {
167 std::cout << "Test skipped due to missing GL_EXT_texture_rg." << std::endl;
168 return;
169 }
170 }
171
Jamie Madillbc393df2015-01-29 13:46:07 -0500172 GLfloat sourceImageData[4][16] =
173 {
174 { // R
175 1.0f,
176 0.0f,
177 0.0f,
178 1.0f
179 },
180 { // RG
181 1.0f, 0.0f,
182 0.0f, 1.0f,
183 0.0f, 0.0f,
184 1.0f, 1.0f
185 },
186 { // RGB
187 1.0f, 0.0f, 0.0f,
188 0.0f, 1.0f, 0.0f,
189 0.0f, 0.0f, 1.0f,
190 1.0f, 1.0f, 0.0f
191 },
192 { // RGBA
193 1.0f, 0.0f, 0.0f, 1.0f,
194 0.0f, 1.0f, 0.0f, 1.0f,
195 0.0f, 0.0f, 1.0f, 1.0f,
196 1.0f, 1.0f, 0.0f, 1.0f
197 },
198 };
199
200 GLenum imageFormats[] =
201 {
202 GL_R32F,
203 GL_RG32F,
204 GL_RGB32F,
205 GL_RGBA32F,
206 };
207
208 GLenum sourceUnsizedFormats[] =
209 {
210 GL_RED,
211 GL_RG,
212 GL_RGB,
213 GL_RGBA,
214 };
215
216 GLuint textures[2];
217
218 glGenTextures(2, textures);
219
220 GLfloat *imageData = sourceImageData[sourceImageChannels - 1];
221 GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1];
222 GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1];
223 GLenum destImageFormat = imageFormats[destImageChannels - 1];
224
225 glBindTexture(GL_TEXTURE_2D, textures[0]);
226 glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
227 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
228 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
229 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData);
230
hendrikwb27f79a2015-03-04 11:26:46 -0800231 if (sourceImageChannels < 3 && !extensionEnabled("GL_EXT_texture_rg"))
Jamie Madillbc393df2015-01-29 13:46:07 -0500232 {
233 // This is not supported
234 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
235 }
236 else
237 {
238 ASSERT_GL_NO_ERROR();
239 }
240
241 GLuint fbo;
242 glGenFramebuffers(1, &fbo);
243 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
244 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
245
246 glBindTexture(GL_TEXTURE_2D, textures[1]);
247 glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
248 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
249 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
250
251 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
252 ASSERT_GL_NO_ERROR();
253
254 glBindFramebuffer(GL_FRAMEBUFFER, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200255 drawQuad(mProgram, "position", 0.5f);
Jamie Madillbc393df2015-01-29 13:46:07 -0500256
257 int testImageChannels = std::min(sourceImageChannels, destImageChannels);
258
259 EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
260 if (testImageChannels > 1)
261 {
262 EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255);
263 EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255);
264 if (testImageChannels > 2)
265 {
266 EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255);
267 }
268 }
269
270 glDeleteFramebuffers(1, &fbo);
271 glDeleteTextures(2, textures);
272
273 ASSERT_GL_NO_ERROR();
274 }
275
Jamie Madilld4cfa572014-07-08 10:00:32 -0400276 GLuint mTexture2D;
Jamie Madilld4cfa572014-07-08 10:00:32 -0400277 GLint mTexture2DUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400278};
279
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200280class Texture2DTestWithDrawScale : public Texture2DTest
Jamie Madill2453dbc2015-07-14 11:35:42 -0400281{
282 protected:
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200283 Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {}
284
285 std::string getVertexShaderSource() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400286 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200287 return std::string(SHADER_SOURCE
288 (
289 precision highp float;
290 attribute vec4 position;
291 varying vec2 texcoord;
292
293 uniform vec2 drawScale;
294
295 void main()
296 {
297 gl_Position = vec4(position.xy * drawScale, 0.0, 1.0);
298 texcoord = (position.xy * 0.5) + 0.5;
299 }
300 )
301 );
Jamie Madill2453dbc2015-07-14 11:35:42 -0400302 }
303
304 void SetUp() override
305 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200306 Texture2DTest::SetUp();
307 mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale");
308 ASSERT_NE(-1, mDrawScaleUniformLocation);
Jamie Madill2453dbc2015-07-14 11:35:42 -0400309
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200310 glUseProgram(mProgram);
311 glUniform2f(mDrawScaleUniformLocation, 1.0f, 1.0f);
312 glUseProgram(0);
313 ASSERT_GL_NO_ERROR();
314 }
315
316 GLint mDrawScaleUniformLocation;
317};
318
Olli Etuaho4644a202016-01-12 15:12:53 +0200319class Sampler2DAsFunctionParameterTest : public Texture2DTest
320{
321 protected:
322 Sampler2DAsFunctionParameterTest() : Texture2DTest() {}
323
324 std::string getFragmentShaderSource() override
325 {
326 return std::string(SHADER_SOURCE
327 (
328 precision highp float;
329 uniform sampler2D tex;
330 varying vec2 texcoord;
331
332 vec4 computeFragColor(sampler2D aTex)
333 {
334 return texture2D(aTex, texcoord);
335 }
336
337 void main()
338 {
339 gl_FragColor = computeFragColor(tex);
340 }
341 )
342 );
343 }
344};
345
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200346class TextureCubeTest : public TexCoordDrawTest
347{
348 protected:
349 TextureCubeTest()
350 : TexCoordDrawTest(),
351 mTexture2D(0),
352 mTextureCube(0),
353 mTexture2DUniformLocation(-1),
354 mTextureCubeUniformLocation(-1)
355 {
356 }
357
358 std::string getFragmentShaderSource() override
359 {
360 return std::string(SHADER_SOURCE
361 (
362 precision highp float;
363 uniform sampler2D tex2D;
364 uniform samplerCube texCube;
365 varying vec2 texcoord;
366
367 void main()
368 {
369 gl_FragColor = texture2D(tex2D, texcoord);
370 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
371 }
372 )
373 );
374 }
375
376 void SetUp() override
377 {
378 TexCoordDrawTest::SetUp();
379
380 glGenTextures(1, &mTextureCube);
381 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
382 glTexStorage2DEXT(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
383 EXPECT_GL_NO_ERROR();
384
385 mTexture2D = create2DTexture();
386
387 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
388 ASSERT_NE(-1, mTexture2DUniformLocation);
389 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
390 ASSERT_NE(-1, mTextureCubeUniformLocation);
391 }
392
393 void TearDown() override
394 {
395 glDeleteTextures(1, &mTextureCube);
396 TexCoordDrawTest::TearDown();
397 }
398
399 GLuint mTexture2D;
400 GLuint mTextureCube;
401 GLint mTexture2DUniformLocation;
402 GLint mTextureCubeUniformLocation;
403};
404
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200405class SamplerArrayTest : public TexCoordDrawTest
406{
407 protected:
408 SamplerArrayTest()
409 : TexCoordDrawTest(),
410 mTexture2DA(0),
411 mTexture2DB(0),
412 mTexture0UniformLocation(-1),
413 mTexture1UniformLocation(-1)
414 {
415 }
416
417 std::string getFragmentShaderSource() override
418 {
419 return std::string(SHADER_SOURCE
420 (
421 precision mediump float;
422 uniform highp sampler2D tex2DArray[2];
423 varying vec2 texcoord;
424 void main()
425 {
426 gl_FragColor = texture2D(tex2DArray[0], texcoord);
427 gl_FragColor += texture2D(tex2DArray[1], texcoord);
428 }
429 )
430 );
431 }
432
433 void SetUp() override
434 {
435 TexCoordDrawTest::SetUp();
436
437 mTexture0UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[0]");
438 ASSERT_NE(-1, mTexture0UniformLocation);
439 mTexture1UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[1]");
440 ASSERT_NE(-1, mTexture1UniformLocation);
441
442 mTexture2DA = create2DTexture();
443 mTexture2DB = create2DTexture();
444 ASSERT_GL_NO_ERROR();
445 }
446
447 void TearDown() override
448 {
449 glDeleteTextures(1, &mTexture2DA);
450 glDeleteTextures(1, &mTexture2DB);
451 TexCoordDrawTest::TearDown();
452 }
453
454 void testSamplerArrayDraw()
455 {
456 GLubyte texData[4];
457 texData[0] = 0;
458 texData[1] = 60;
459 texData[2] = 0;
460 texData[3] = 255;
461
462 glActiveTexture(GL_TEXTURE0);
463 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
464 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
465
466 texData[1] = 120;
467 glActiveTexture(GL_TEXTURE1);
468 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
469 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
470 EXPECT_GL_ERROR(GL_NO_ERROR);
471
472 glUseProgram(mProgram);
473 glUniform1i(mTexture0UniformLocation, 0);
474 glUniform1i(mTexture1UniformLocation, 1);
475 drawQuad(mProgram, "position", 0.5f);
476 EXPECT_GL_NO_ERROR();
477
478 EXPECT_PIXEL_NEAR(0, 0, 0, 180, 0, 255, 2);
479 }
480
481 GLuint mTexture2DA;
482 GLuint mTexture2DB;
483 GLint mTexture0UniformLocation;
484 GLint mTexture1UniformLocation;
485};
486
487
488class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest
489{
490 protected:
491 SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {}
492
493 std::string getFragmentShaderSource() override
494 {
495 return std::string(SHADER_SOURCE
496 (
497 precision mediump float;
498 uniform highp sampler2D tex2DArray[2];
499 varying vec2 texcoord;
500
501 vec4 computeFragColor(highp sampler2D aTex2DArray[2])
502 {
503 return texture2D(aTex2DArray[0], texcoord) + texture2D(aTex2DArray[1], texcoord);
504 }
505
506 void main()
507 {
508 gl_FragColor = computeFragColor(tex2DArray);
509 }
510 )
511 );
512 }
513};
514
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200515class Texture2DArrayTestES3 : public TexCoordDrawTest
516{
517 protected:
518 Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {}
519
520 std::string getVertexShaderSource() override
521 {
522 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400523 "#version 300 es\n"
524 "out vec2 texcoord;\n"
525 "in vec4 position;\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200526 "void main()\n"
527 "{\n"
528 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
529 " texcoord = (position.xy * 0.5) + 0.5;\n"
530 "}\n");
531 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400532
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200533 std::string getFragmentShaderSource() override
534 {
535 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400536 "#version 300 es\n"
537 "precision highp float;\n"
Olli Etuaho183d7e22015-11-20 15:59:09 +0200538 "uniform highp sampler2DArray tex2DArray;\n"
Jamie Madill2453dbc2015-07-14 11:35:42 -0400539 "in vec2 texcoord;\n"
540 "out vec4 fragColor;\n"
541 "void main()\n"
542 "{\n"
543 " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200544 "}\n");
545 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400546
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200547 void SetUp() override
548 {
549 TexCoordDrawTest::SetUp();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400550
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200551 mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray");
Jamie Madill2453dbc2015-07-14 11:35:42 -0400552 ASSERT_NE(-1, mTextureArrayLocation);
553
554 glGenTextures(1, &m2DArrayTexture);
555 ASSERT_GL_NO_ERROR();
556 }
557
558 void TearDown() override
559 {
560 glDeleteTextures(1, &m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200561 TexCoordDrawTest::TearDown();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400562 }
563
564 GLuint m2DArrayTexture;
Jamie Madill2453dbc2015-07-14 11:35:42 -0400565 GLint mTextureArrayLocation;
566};
567
Olli Etuaho1a679902016-01-14 12:21:47 +0200568class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest
569{
570 protected:
571 ShadowSamplerPlusSampler3DTestES3()
572 : TexCoordDrawTest(),
573 mTextureShadow(0),
574 mTexture3D(0),
575 mTextureShadowUniformLocation(-1),
576 mTexture3DUniformLocation(-1),
577 mDepthRefUniformLocation(-1)
578 {
579 }
580
581 std::string getVertexShaderSource() override
582 {
583 return std::string(
584 "#version 300 es\n"
585 "out vec2 texcoord;\n"
586 "in vec4 position;\n"
587 "void main()\n"
588 "{\n"
589 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
590 " texcoord = (position.xy * 0.5) + 0.5;\n"
591 "}\n");
592 }
593
594 std::string getFragmentShaderSource() override
595 {
596 return std::string(
597 "#version 300 es\n"
598 "precision highp float;\n"
599 "uniform highp sampler2DShadow tex2DShadow;\n"
600 "uniform highp sampler3D tex3D;\n"
601 "in vec2 texcoord;\n"
602 "uniform float depthRef;\n"
603 "out vec4 fragColor;\n"
604 "void main()\n"
605 "{\n"
606 " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n"
607 " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n"
608 "}\n");
609 }
610
611 void SetUp() override
612 {
613 TexCoordDrawTest::SetUp();
614
615 glGenTextures(1, &mTexture3D);
616
617 glGenTextures(1, &mTextureShadow);
618 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
619 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
620
621 mTextureShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
622 ASSERT_NE(-1, mTextureShadowUniformLocation);
623 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
624 ASSERT_NE(-1, mTexture3DUniformLocation);
625 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
626 ASSERT_NE(-1, mDepthRefUniformLocation);
627 }
628
629 void TearDown() override
630 {
631 glDeleteTextures(1, &mTextureShadow);
632 glDeleteTextures(1, &mTexture3D);
633 TexCoordDrawTest::TearDown();
634 }
635
636 GLuint mTextureShadow;
637 GLuint mTexture3D;
638 GLint mTextureShadowUniformLocation;
639 GLint mTexture3DUniformLocation;
640 GLint mDepthRefUniformLocation;
641};
642
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200643TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -0400644{
Jamie Madilld4cfa572014-07-08 10:00:32 -0400645 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -0400646 EXPECT_GL_ERROR(GL_NO_ERROR);
647
648 const GLubyte *pixels[20] = { 0 };
649 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
650 EXPECT_GL_ERROR(GL_INVALID_VALUE);
651}
Geoff Langc41e42d2014-04-28 10:58:16 -0400652
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200653TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -0400654{
Jamie Madilld4cfa572014-07-08 10:00:32 -0400655 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -0400656 EXPECT_GL_ERROR(GL_NO_ERROR);
657
658 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200659 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -0400660 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200661 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -0400662
663 const GLubyte *pixel[4] = { 0 };
664
665 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
666 EXPECT_GL_NO_ERROR();
667
668 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
669 EXPECT_GL_NO_ERROR();
670
671 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
672 EXPECT_GL_NO_ERROR();
673}
Jamie Madilld4cfa572014-07-08 10:00:32 -0400674
675// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200676TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -0400677{
678 glActiveTexture(GL_TEXTURE0);
679 glBindTexture(GL_TEXTURE_2D, mTexture2D);
680 glActiveTexture(GL_TEXTURE1);
681 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
682 EXPECT_GL_ERROR(GL_NO_ERROR);
683
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200684 glUseProgram(mProgram);
685 glUniform1i(mTexture2DUniformLocation, 0);
686 glUniform1i(mTextureCubeUniformLocation, 1);
687 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -0400688 EXPECT_GL_NO_ERROR();
689}
Jamie Madill9aca0592014-10-06 16:26:59 -0400690
Olli Etuaho53a2da12016-01-11 15:43:32 +0200691// Test drawing with two texture types accessed from the same shader and check that the result of
692// drawing is correct.
693TEST_P(TextureCubeTest, CubeMapDraw)
694{
695 GLubyte texData[4];
696 texData[0] = 0;
697 texData[1] = 60;
698 texData[2] = 0;
699 texData[3] = 255;
700
701 glActiveTexture(GL_TEXTURE0);
702 glBindTexture(GL_TEXTURE_2D, mTexture2D);
703 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
704
705 glActiveTexture(GL_TEXTURE1);
706 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
707 texData[1] = 120;
708 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
709 texData);
710 EXPECT_GL_ERROR(GL_NO_ERROR);
711
712 glUseProgram(mProgram);
713 glUniform1i(mTexture2DUniformLocation, 0);
714 glUniform1i(mTextureCubeUniformLocation, 1);
715 drawQuad(mProgram, "position", 0.5f);
716 EXPECT_GL_NO_ERROR();
717
718 int px = getWindowWidth() - 1;
719 int py = 0;
720 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
721}
722
Olli Etuaho4644a202016-01-12 15:12:53 +0200723TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
724{
725 glActiveTexture(GL_TEXTURE0);
726 glBindTexture(GL_TEXTURE_2D, mTexture2D);
727 GLubyte texData[4];
728 texData[0] = 0;
729 texData[1] = 128;
730 texData[2] = 0;
731 texData[3] = 255;
732 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
733 glUseProgram(mProgram);
734 glUniform1i(mTexture2DUniformLocation, 0);
735 drawQuad(mProgram, "position", 0.5f);
736 EXPECT_GL_NO_ERROR();
737
738 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
739}
740
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200741// Test drawing with two textures passed to the shader in a sampler array.
742TEST_P(SamplerArrayTest, SamplerArrayDraw)
743{
744 testSamplerArrayDraw();
745}
746
747// Test drawing with two textures passed to the shader in a sampler array which is passed to a
748// user-defined function in the shader.
749TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
750{
751 testSamplerArrayDraw();
752}
753
Jamie Madill9aca0592014-10-06 16:26:59 -0400754// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200755TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -0400756{
757 int px = getWindowWidth() / 2;
758 int py = getWindowHeight() / 2;
759
760 glActiveTexture(GL_TEXTURE0);
761 glBindTexture(GL_TEXTURE_2D, mTexture2D);
762
763 // Fill with red
764 std::vector<GLubyte> pixels(4 * 16 * 16);
765 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
766 {
767 pixels[pixelId * 4 + 0] = 255;
768 pixels[pixelId * 4 + 1] = 0;
769 pixels[pixelId * 4 + 2] = 0;
770 pixels[pixelId * 4 + 3] = 255;
771 }
772
773 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
774 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
775 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
776 glGenerateMipmap(GL_TEXTURE_2D);
777
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200778 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -0400779 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200780 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
781 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -0400782 EXPECT_GL_NO_ERROR();
783 EXPECT_PIXEL_EQ(px, py, 255, 0, 0, 255);
784
785 // Fill with blue
786 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
787 {
788 pixels[pixelId * 4 + 0] = 0;
789 pixels[pixelId * 4 + 1] = 0;
790 pixels[pixelId * 4 + 2] = 255;
791 pixels[pixelId * 4 + 3] = 255;
792 }
793
794 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
795 glGenerateMipmap(GL_TEXTURE_2D);
796
797 // Fill with green
798 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
799 {
800 pixels[pixelId * 4 + 0] = 0;
801 pixels[pixelId * 4 + 1] = 255;
802 pixels[pixelId * 4 + 2] = 0;
803 pixels[pixelId * 4 + 3] = 255;
804 }
805
806 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
807 glGenerateMipmap(GL_TEXTURE_2D);
808
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200809 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -0400810
811 EXPECT_GL_NO_ERROR();
812 EXPECT_PIXEL_EQ(px, py, 0, 255, 0, 255);
813}
Jamie Madillf8fccb32014-11-12 15:05:26 -0500814
Jamie Madilleb32a2e2014-12-10 14:27:53 -0500815// Test creating a FBO with a cube map render target, to test an ANGLE bug
816// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200817TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -0500818{
819 GLuint fbo;
820 glGenFramebuffers(1, &fbo);
821 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
822
823 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
824 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mTextureCube, 0);
825
Corentin Wallez322653b2015-06-17 18:33:56 +0200826 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -0500827
828 glDeleteFramebuffers(1, &fbo);
829
830 EXPECT_GL_NO_ERROR();
831}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +0000832
833// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200834TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +0000835{
836 int width = getWindowWidth();
837 int height = getWindowHeight();
838
839 GLuint tex2D;
840 glGenTextures(1, &tex2D);
841 glActiveTexture(GL_TEXTURE0);
842 glBindTexture(GL_TEXTURE_2D, tex2D);
843
844 // Fill with red
845 std::vector<GLubyte> pixels(3 * 16 * 16);
846 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
847 {
848 pixels[pixelId * 3 + 0] = 255;
849 pixels[pixelId * 3 + 1] = 0;
850 pixels[pixelId * 3 + 2] = 0;
851 }
852
853 // ANGLE internally uses RGBA as the DirectX format for RGB images
854 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
855 // The data is kept in a CPU-side image and the image is marked as dirty.
856 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
857
858 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
859 // glTexSubImage2D should take into account that the image is dirty.
860 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
861 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
862 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
863
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200864 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +0000865 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200866 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +0000867 glDeleteTextures(1, &tex2D);
868 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +0000869 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -0400870
871 // Validate that the region of the texture without data has an alpha of 1.0
872 GLubyte pixel[4];
873 glReadPixels(3 * width / 4, 3 * height / 4, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
874 EXPECT_EQ(pixel[3], 255);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +0000875}
876
877// 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 +0200878TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +0000879{
880 if (extensionEnabled("NV_pixel_buffer_object"))
881 {
882 int width = getWindowWidth();
883 int height = getWindowHeight();
884
885 GLuint tex2D;
886 glGenTextures(1, &tex2D);
887 glActiveTexture(GL_TEXTURE0);
888 glBindTexture(GL_TEXTURE_2D, tex2D);
889
890 // Fill with red
891 std::vector<GLubyte> pixels(3 * 16 * 16);
892 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
893 {
894 pixels[pixelId * 3 + 0] = 255;
895 pixels[pixelId * 3 + 1] = 0;
896 pixels[pixelId * 3 + 2] = 0;
897 }
898
899 // Read 16x16 region from red backbuffer to PBO
900 GLuint pbo;
901 glGenBuffers(1, &pbo);
902 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
903 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
904
905 // ANGLE internally uses RGBA as the DirectX format for RGB images
906 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
907 // The data is kept in a CPU-side image and the image is marked as dirty.
908 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
909
910 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
911 // glTexSubImage2D should take into account that the image is dirty.
912 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, NULL);
913 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
914 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
915
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200916 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +0000917 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200918 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +0000919 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +0200920 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +0000921 EXPECT_GL_NO_ERROR();
922 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
923 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
924 }
925}
Jamie Madillbc393df2015-01-29 13:46:07 -0500926
927// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200928TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -0500929{
930 testFloatCopySubImage(1, 1);
931}
932
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200933TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -0500934{
935 testFloatCopySubImage(2, 1);
936}
937
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200938TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -0500939{
940 testFloatCopySubImage(2, 2);
941}
942
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200943TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -0500944{
945 testFloatCopySubImage(3, 1);
946}
947
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200948TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -0500949{
950 testFloatCopySubImage(3, 2);
951}
952
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200953TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -0500954{
955 testFloatCopySubImage(3, 3);
956}
957
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200958TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -0500959{
960 testFloatCopySubImage(4, 1);
961}
962
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200963TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -0500964{
965 testFloatCopySubImage(4, 2);
966}
967
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200968TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -0500969{
970 testFloatCopySubImage(4, 3);
971}
972
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200973TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -0500974{
975 testFloatCopySubImage(4, 4);
976}
Austin Kinross07285142015-03-26 11:36:16 -0700977
978// Port of https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
979// 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 +0200980TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -0700981{
982 const int npotTexSize = 5;
983 const int potTexSize = 4; // Should be less than npotTexSize
984 GLuint tex2D;
985
986 if (extensionEnabled("GL_OES_texture_npot"))
987 {
988 // This test isn't applicable if texture_npot is enabled
989 return;
990 }
991
992 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
993
Austin Kinross5faa15b2016-01-11 13:32:48 -0800994 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
995 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
996
Austin Kinross07285142015-03-26 11:36:16 -0700997 glActiveTexture(GL_TEXTURE0);
998 glGenTextures(1, &tex2D);
999 glBindTexture(GL_TEXTURE_2D, tex2D);
1000
1001 std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize);
1002 for (size_t pixelId = 0; pixelId < npotTexSize * npotTexSize; ++pixelId)
1003 {
1004 pixels[pixelId] = 64;
1005 }
1006
1007 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1008 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1009
1010 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
1011 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1012 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1013
1014 // Check that an NPOT texture on level 0 succeeds
1015 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1016 EXPECT_GL_NO_ERROR();
1017
1018 // Check that generateMipmap fails on NPOT
1019 glGenerateMipmap(GL_TEXTURE_2D);
1020 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1021
1022 // Check that nothing is drawn if filtering is not correct for NPOT
1023 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1024 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1025 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1026 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1027 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001028 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001029 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1030
1031 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1032 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1033 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1034 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1035 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001036 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001037 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1038
1039 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1040 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1041 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001042 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001043 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1044
1045 // Check that glTexImage2D for POT texture succeeds
1046 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1047 EXPECT_GL_NO_ERROR();
1048
1049 // Check that generateMipmap for an POT texture succeeds
1050 glGenerateMipmap(GL_TEXTURE_2D);
1051 EXPECT_GL_NO_ERROR();
1052
1053 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1054 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1055 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1056 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1057 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1058 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001059 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001060 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1061 EXPECT_GL_NO_ERROR();
1062}
Jamie Madillfa05f602015-05-07 13:47:11 -04001063
Austin Kinross08528e12015-10-07 16:24:40 -07001064// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1065// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001066TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001067{
1068 glActiveTexture(GL_TEXTURE0);
1069 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1070
1071 // Create an 8x8 (i.e. power-of-two) texture.
1072 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1073 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1074 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1075 glGenerateMipmap(GL_TEXTURE_2D);
1076
1077 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1078 // This should always work, even if GL_OES_texture_npot isn't active.
1079 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1080
1081 EXPECT_GL_NO_ERROR();
1082}
1083
Jamie Madill2453dbc2015-07-14 11:35:42 -04001084// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG RBA->RGBA8, with 1.0
1085// in the alpha channel. This test covers a bug where redefining array textures with these formats does not work as
1086// expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001087TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04001088{
1089 std::vector<GLubyte> pixelData;
1090 for (size_t count = 0; count < 5000; count++)
1091 {
1092 pixelData.push_back(0u);
1093 pixelData.push_back(255u);
1094 pixelData.push_back(0u);
1095 }
1096
1097 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001098 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04001099 glUniform1i(mTextureArrayLocation, 0);
1100
1101 // The first draw worked correctly.
1102 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
1103
1104 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1105 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1106 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
1107 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001108 drawQuad(mProgram, "position", 1.0f);
Jamie Madill2453dbc2015-07-14 11:35:42 -04001109 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
1110
1111 // The dimension of the respecification must match the original exactly to trigger the bug.
1112 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 +02001113 drawQuad(mProgram, "position", 1.0f);
Jamie Madill2453dbc2015-07-14 11:35:42 -04001114 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
1115
1116 ASSERT_GL_NO_ERROR();
1117}
1118
Olli Etuaho1a679902016-01-14 12:21:47 +02001119// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
1120// This test is needed especially to confirm that sampler registers get assigned correctly on
1121// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
1122TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
1123{
1124 glActiveTexture(GL_TEXTURE0);
1125 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1126 GLubyte texData[4];
1127 texData[0] = 0;
1128 texData[1] = 60;
1129 texData[2] = 0;
1130 texData[3] = 255;
1131 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1132
1133 glActiveTexture(GL_TEXTURE1);
1134 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
1135 GLfloat depthTexData[1];
1136 depthTexData[0] = 0.5f;
1137 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
1138 depthTexData);
1139
1140 glUseProgram(mProgram);
1141 glUniform1f(mDepthRefUniformLocation, 0.3f);
1142 glUniform1i(mTexture3DUniformLocation, 0);
1143 glUniform1i(mTextureShadowUniformLocation, 1);
1144
1145 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
1146 drawQuad(mProgram, "position", 0.5f);
1147 EXPECT_GL_NO_ERROR();
1148 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
1149 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
1150
1151 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
1152 drawQuad(mProgram, "position", 0.5f);
1153 EXPECT_GL_NO_ERROR();
1154 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
1155 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
1156}
1157
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001158class TextureLimitsTest : public ANGLETest
1159{
1160 protected:
1161 struct RGBA8
1162 {
1163 uint8_t R, G, B, A;
1164 };
1165
1166 TextureLimitsTest()
1167 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
1168 {
1169 setWindowWidth(128);
1170 setWindowHeight(128);
1171 setConfigRedBits(8);
1172 setConfigGreenBits(8);
1173 setConfigBlueBits(8);
1174 setConfigAlphaBits(8);
1175 }
1176
1177 ~TextureLimitsTest()
1178 {
1179 if (mProgram != 0)
1180 {
1181 glDeleteProgram(mProgram);
1182 mProgram = 0;
1183
1184 if (!mTextures.empty())
1185 {
1186 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
1187 }
1188 }
1189 }
1190
1191 void SetUp() override
1192 {
1193 ANGLETest::SetUp();
1194
1195 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
1196 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
1197 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
1198
1199 ASSERT_GL_NO_ERROR();
1200 }
1201
1202 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
1203 GLint vertexTextureCount,
1204 GLint vertexActiveTextureCount,
1205 const std::string &fragPrefix,
1206 GLint fragmentTextureCount,
1207 GLint fragmentActiveTextureCount)
1208 {
1209 std::stringstream vertexShaderStr;
1210 vertexShaderStr << "attribute vec2 position;\n"
1211 << "varying vec4 color;\n"
1212 << "varying vec2 texCoord;\n";
1213
1214 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
1215 {
1216 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
1217 }
1218
1219 vertexShaderStr << "void main() {\n"
1220 << " gl_Position = vec4(position, 0, 1);\n"
1221 << " texCoord = (position * 0.5) + 0.5;\n"
1222 << " color = vec4(0);\n";
1223
1224 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
1225 {
1226 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
1227 << ", texCoord);\n";
1228 }
1229
1230 vertexShaderStr << "}";
1231
1232 std::stringstream fragmentShaderStr;
1233 fragmentShaderStr << "varying mediump vec4 color;\n"
1234 << "varying mediump vec2 texCoord;\n";
1235
1236 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
1237 {
1238 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
1239 }
1240
1241 fragmentShaderStr << "void main() {\n"
1242 << " gl_FragColor = color;\n";
1243
1244 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
1245 {
1246 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
1247 << ", texCoord);\n";
1248 }
1249
1250 fragmentShaderStr << "}";
1251
1252 const std::string &vertexShaderSource = vertexShaderStr.str();
1253 const std::string &fragmentShaderSource = fragmentShaderStr.str();
1254
1255 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
1256 }
1257
1258 RGBA8 getPixel(GLint texIndex)
1259 {
1260 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
1261 0, 255u};
1262 return pixel;
1263 }
1264
1265 void initTextures(GLint tex2DCount, GLint texCubeCount)
1266 {
1267 GLint totalCount = tex2DCount + texCubeCount;
1268 mTextures.assign(totalCount, 0);
1269 glGenTextures(totalCount, &mTextures[0]);
1270 ASSERT_GL_NO_ERROR();
1271
1272 std::vector<RGBA8> texData(16 * 16);
1273
1274 GLint texIndex = 0;
1275 for (; texIndex < tex2DCount; ++texIndex)
1276 {
1277 texData.assign(texData.size(), getPixel(texIndex));
1278 glActiveTexture(GL_TEXTURE0 + texIndex);
1279 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
1280 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1281 &texData[0]);
1282 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1283 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1284 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1285 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1286 }
1287
1288 ASSERT_GL_NO_ERROR();
1289
1290 for (; texIndex < texCubeCount; ++texIndex)
1291 {
1292 texData.assign(texData.size(), getPixel(texIndex));
1293 glActiveTexture(GL_TEXTURE0 + texIndex);
1294 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
1295 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
1296 GL_UNSIGNED_BYTE, &texData[0]);
1297 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
1298 GL_UNSIGNED_BYTE, &texData[0]);
1299 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
1300 GL_UNSIGNED_BYTE, &texData[0]);
1301 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
1302 GL_UNSIGNED_BYTE, &texData[0]);
1303 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
1304 GL_UNSIGNED_BYTE, &texData[0]);
1305 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
1306 GL_UNSIGNED_BYTE, &texData[0]);
1307 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1308 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1309 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1310 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1311 }
1312
1313 ASSERT_GL_NO_ERROR();
1314 }
1315
1316 void testWithTextures(GLint vertexTextureCount,
1317 const std::string &vertexTexturePrefix,
1318 GLint fragmentTextureCount,
1319 const std::string &fragmentTexturePrefix)
1320 {
1321 // Generate textures
1322 initTextures(vertexTextureCount + fragmentTextureCount, 0);
1323
1324 glUseProgram(mProgram);
1325 RGBA8 expectedSum = {0};
1326 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
1327 {
1328 std::stringstream uniformNameStr;
1329 uniformNameStr << vertexTexturePrefix << texIndex;
1330 const std::string &uniformName = uniformNameStr.str();
1331 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
1332 ASSERT_NE(-1, location);
1333
1334 glUniform1i(location, texIndex);
1335 RGBA8 contribution = getPixel(texIndex);
1336 expectedSum.R += contribution.R;
1337 expectedSum.G += contribution.G;
1338 }
1339
1340 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
1341 {
1342 std::stringstream uniformNameStr;
1343 uniformNameStr << fragmentTexturePrefix << texIndex;
1344 const std::string &uniformName = uniformNameStr.str();
1345 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
1346 ASSERT_NE(-1, location);
1347
1348 glUniform1i(location, texIndex + vertexTextureCount);
1349 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
1350 expectedSum.R += contribution.R;
1351 expectedSum.G += contribution.G;
1352 }
1353
1354 ASSERT_GE(256u, expectedSum.G);
1355
1356 drawQuad(mProgram, "position", 0.5f);
1357 ASSERT_GL_NO_ERROR();
1358 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
1359 }
1360
1361 GLuint mProgram;
1362 std::vector<GLuint> mTextures;
1363 GLint mMaxVertexTextures;
1364 GLint mMaxFragmentTextures;
1365 GLint mMaxCombinedTextures;
1366};
1367
1368// Test rendering with the maximum vertex texture units.
1369TEST_P(TextureLimitsTest, MaxVertexTextures)
1370{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04001371 // TODO(jmadill): Figure out why this fails on Intel.
1372 if (isIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1373 {
1374 std::cout << "Test skipped on Intel." << std::endl;
1375 return;
1376 }
1377
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001378 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
1379 ASSERT_NE(0u, mProgram);
1380 ASSERT_GL_NO_ERROR();
1381
1382 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
1383}
1384
1385// Test rendering with the maximum fragment texture units.
1386TEST_P(TextureLimitsTest, MaxFragmentTextures)
1387{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04001388 // TODO(jmadill): Figure out why this fails on Intel.
1389 if (isIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1390 {
1391 std::cout << "Test skipped on Intel." << std::endl;
1392 return;
1393 }
1394
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001395 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
1396 ASSERT_NE(0u, mProgram);
1397 ASSERT_GL_NO_ERROR();
1398
1399 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
1400}
1401
1402// Test rendering with maximum combined texture units.
1403TEST_P(TextureLimitsTest, MaxCombinedTextures)
1404{
Jamie Madill412f17d2015-09-25 08:43:54 -04001405 // TODO(jmadill): Investigate workaround.
1406 if (isIntel() && GetParam() == ES2_OPENGL())
1407 {
1408 std::cout << "Test skipped on Intel." << std::endl;
1409 return;
1410 }
1411
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001412 GLint vertexTextures = mMaxVertexTextures;
1413
1414 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
1415 {
1416 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
1417 }
1418
1419 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
1420 mMaxFragmentTextures, mMaxFragmentTextures);
1421 ASSERT_NE(0u, mProgram);
1422 ASSERT_GL_NO_ERROR();
1423
1424 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
1425}
1426
1427// Negative test for exceeding the number of vertex textures
1428TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
1429{
1430 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
1431 0);
1432 ASSERT_EQ(0u, mProgram);
1433}
1434
1435// Negative test for exceeding the number of fragment textures
1436TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
1437{
1438 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
1439 mMaxFragmentTextures + 1);
1440 ASSERT_EQ(0u, mProgram);
1441}
1442
1443// Test active vertex textures under the limit, but excessive textures specified.
1444TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
1445{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04001446 // TODO(jmadill): Figure out why this fails on Intel.
1447 if (isIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1448 {
1449 std::cout << "Test skipped on Intel." << std::endl;
1450 return;
1451 }
1452
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001453 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
1454 ASSERT_NE(0u, mProgram);
1455 ASSERT_GL_NO_ERROR();
1456
1457 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
1458}
1459
1460// Test active fragment textures under the limit, but excessive textures specified.
1461TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
1462{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04001463 // TODO(jmadill): Figure out why this fails on Intel.
1464 if (isIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1465 {
1466 std::cout << "Test skipped on Intel." << std::endl;
1467 return;
1468 }
1469
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001470 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
1471 mMaxFragmentTextures);
1472 ASSERT_NE(0u, mProgram);
1473 ASSERT_GL_NO_ERROR();
1474
1475 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
1476}
1477
1478// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001479// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001480TEST_P(TextureLimitsTest, TextureTypeConflict)
1481{
1482 const std::string &vertexShader =
1483 "attribute vec2 position;\n"
1484 "varying float color;\n"
1485 "uniform sampler2D tex2D;\n"
1486 "uniform samplerCube texCube;\n"
1487 "void main() {\n"
1488 " gl_Position = vec4(position, 0, 1);\n"
1489 " vec2 texCoord = (position * 0.5) + 0.5;\n"
1490 " color = texture2D(tex2D, texCoord).x;\n"
1491 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
1492 "}";
1493 const std::string &fragmentShader =
1494 "varying mediump float color;\n"
1495 "void main() {\n"
1496 " gl_FragColor = vec4(color, 0, 0, 1);\n"
1497 "}";
1498
1499 mProgram = CompileProgram(vertexShader, fragmentShader);
1500 ASSERT_NE(0u, mProgram);
1501
1502 initTextures(1, 0);
1503
1504 glUseProgram(mProgram);
1505 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
1506 ASSERT_NE(-1, tex2DLocation);
1507 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
1508 ASSERT_NE(-1, texCubeLocation);
1509
1510 glUniform1i(tex2DLocation, 0);
1511 glUniform1i(texCubeLocation, 0);
1512 ASSERT_GL_NO_ERROR();
1513
1514 drawQuad(mProgram, "position", 0.5f);
1515 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1516}
1517
1518// Negative test for rendering with texture outside the valid range.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001519// TODO(jmadill): Possibly adjust the test according to the spec:
1520// GLES 3.0.4 section 2.12.7 mentions that specifying an out-of-range sampler uniform value
1521// generates an INVALID_VALUE error - GLES 2.0 doesn't yet have this mention.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001522TEST_P(TextureLimitsTest, DrawWithTexturePastMaximum)
1523{
1524 const std::string &vertexShader =
1525 "attribute vec2 position;\n"
1526 "varying float color;\n"
1527 "uniform sampler2D tex2D;\n"
1528 "void main() {\n"
1529 " gl_Position = vec4(position, 0, 1);\n"
1530 " vec2 texCoord = (position * 0.5) + 0.5;\n"
1531 " color = texture2D(tex2D, texCoord).x;\n"
1532 "}";
1533 const std::string &fragmentShader =
1534 "varying mediump float color;\n"
1535 "void main() {\n"
1536 " gl_FragColor = vec4(color, 0, 0, 1);\n"
1537 "}";
1538
1539 mProgram = CompileProgram(vertexShader, fragmentShader);
1540 ASSERT_NE(0u, mProgram);
1541
1542 glUseProgram(mProgram);
1543 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
1544 ASSERT_NE(-1, tex2DLocation);
1545
1546 glUniform1i(tex2DLocation, mMaxCombinedTextures);
1547 ASSERT_GL_NO_ERROR();
1548
1549 drawQuad(mProgram, "position", 0.5f);
1550 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1551}
1552
Jamie Madillfa05f602015-05-07 13:47:11 -04001553// 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 +02001554// TODO(oetuaho): Enable all below tests on OpenGL. Requires a fix for ANGLE bug 1278.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001555ANGLE_INSTANTIATE_TEST(Texture2DTest, ES2_D3D9(), ES2_D3D11(), ES2_D3D11_FL9_3());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02001556ANGLE_INSTANTIATE_TEST(TextureCubeTest, ES2_D3D9(), ES2_D3D11(), ES2_D3D11_FL9_3(), ES2_OPENGL());
1557ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
1558 ES2_D3D9(),
1559 ES2_D3D11(),
1560 ES2_D3D11_FL9_3(),
1561 ES2_OPENGL());
1562ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
1563 ES2_D3D9(),
1564 ES2_D3D11(),
1565 ES2_D3D11_FL9_3(),
1566 ES2_OPENGL());
1567ANGLE_INSTANTIATE_TEST(SamplerArrayTest, ES2_D3D9(), ES2_D3D11(), ES2_D3D11_FL9_3(), ES2_OPENGL());
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001568ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest, ES2_D3D9(), ES2_D3D11(), ES2_D3D11_FL9_3());
Olli Etuaho1a679902016-01-14 12:21:47 +02001569ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001570ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001571ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL());
Jamie Madillfa05f602015-05-07 13:47:11 -04001572
1573} // namespace