blob: d9173436ce02980f5ca7891a70ad4bf092abf358 [file] [log] [blame]
Jamie Madillfa05f602015-05-07 13:47:11 -04001//
2// Copyright 2015 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Jamie Madill14718762016-09-06 15:56:54 -04007#include "common/mathutil.h"
Corentin Wallezd3970de2015-05-14 11:07:48 -04008#include "test_utils/ANGLETest.h"
Olli Etuaho989cac32016-06-08 16:18:49 -07009#include "test_utils/gl_raii.h"
Jamie Madillf67115c2014-04-22 13:14:05 -040010
Jamie Madillfa05f602015-05-07 13:47:11 -040011using namespace angle;
Austin Kinross18b931d2014-09-29 12:58:31 -070012
Jamie Madillfa05f602015-05-07 13:47:11 -040013namespace
14{
15
Vincent Lang25ab4512016-05-13 18:13:59 +020016// Take a pixel, and reset the components not covered by the format to default
Geoff Langf607c602016-09-21 11:46:48 -040017// values. In particular, the default value for the alpha component is 255
Vincent Lang25ab4512016-05-13 18:13:59 +020018// (1.0 as unsigned normalized fixed point value).
Geoff Langf607c602016-09-21 11:46:48 -040019GLColor SliceFormatColor(GLenum format, GLColor full)
Vincent Lang25ab4512016-05-13 18:13:59 +020020{
21 switch (format)
22 {
23 case GL_RED:
Geoff Langf607c602016-09-21 11:46:48 -040024 return GLColor(full.R, 0, 0, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020025 case GL_RG:
Geoff Langf607c602016-09-21 11:46:48 -040026 return GLColor(full.R, full.G, 0, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020027 case GL_RGB:
Geoff Langf607c602016-09-21 11:46:48 -040028 return GLColor(full.R, full.G, full.B, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020029 case GL_RGBA:
30 return full;
31 default:
32 UNREACHABLE();
Geoff Langf607c602016-09-21 11:46:48 -040033 return GLColor::white;
Vincent Lang25ab4512016-05-13 18:13:59 +020034 }
Vincent Lang25ab4512016-05-13 18:13:59 +020035}
36
Olli Etuaho4a8329f2016-01-11 17:12:57 +020037class TexCoordDrawTest : public ANGLETest
Jamie Madillf67115c2014-04-22 13:14:05 -040038{
Jamie Madillbc393df2015-01-29 13:46:07 -050039 protected:
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020040 TexCoordDrawTest() : ANGLETest(), mProgram(0), mFramebuffer(0), mFramebufferColorTexture(0)
Jamie Madillf67115c2014-04-22 13:14:05 -040041 {
42 setWindowWidth(128);
43 setWindowHeight(128);
44 setConfigRedBits(8);
45 setConfigGreenBits(8);
46 setConfigBlueBits(8);
47 setConfigAlphaBits(8);
48 }
49
Olli Etuaho4a8329f2016-01-11 17:12:57 +020050 virtual std::string getVertexShaderSource()
Jamie Madillf67115c2014-04-22 13:14:05 -040051 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +020052 return std::string(SHADER_SOURCE
Geoff Langc41e42d2014-04-28 10:58:16 -040053 (
54 precision highp float;
55 attribute vec4 position;
56 varying vec2 texcoord;
57
58 void main()
59 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +020060 gl_Position = vec4(position.xy, 0.0, 1.0);
Geoff Langc41e42d2014-04-28 10:58:16 -040061 texcoord = (position.xy * 0.5) + 0.5;
62 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +020063 )
Geoff Langc41e42d2014-04-28 10:58:16 -040064 );
Olli Etuaho4a8329f2016-01-11 17:12:57 +020065 }
Geoff Langc41e42d2014-04-28 10:58:16 -040066
Olli Etuaho4a8329f2016-01-11 17:12:57 +020067 virtual std::string getFragmentShaderSource() = 0;
68
Olli Etuahoa1c917f2016-04-06 13:50:03 +030069 virtual void setUpProgram()
Olli Etuaho4a8329f2016-01-11 17:12:57 +020070 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +020071 const std::string vertexShaderSource = getVertexShaderSource();
72 const std::string fragmentShaderSource = getFragmentShaderSource();
73
74 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
75 ASSERT_NE(0u, mProgram);
76 ASSERT_GL_NO_ERROR();
Olli Etuahoa1c917f2016-04-06 13:50:03 +030077 }
78
79 void SetUp() override
80 {
81 ANGLETest::SetUp();
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020082
83 setUpFramebuffer();
Olli Etuaho4a8329f2016-01-11 17:12:57 +020084 }
85
86 void TearDown() override
87 {
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020088 glBindFramebuffer(GL_FRAMEBUFFER, 0);
89 glDeleteFramebuffers(1, &mFramebuffer);
90 glDeleteTextures(1, &mFramebufferColorTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +020091 glDeleteProgram(mProgram);
92 ANGLETest::TearDown();
93 }
94
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020095 void setUpFramebuffer()
96 {
97 // We use an FBO to work around an issue where the default framebuffer applies SRGB
98 // conversion (particularly known to happen incorrectly on Intel GL drivers). It's not
99 // clear whether this issue can even be fixed on all backends. For example GLES 3.0.4 spec
100 // section 4.4 says that the format of the default framebuffer is entirely up to the window
101 // system, so it might be SRGB, and GLES 3.0 doesn't have a "FRAMEBUFFER_SRGB" to turn off
102 // SRGB conversion like desktop GL does.
103 // TODO(oetuaho): Get rid of this if the underlying issue is fixed.
104 glGenFramebuffers(1, &mFramebuffer);
105 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
106
107 glGenTextures(1, &mFramebufferColorTexture);
108 glBindTexture(GL_TEXTURE_2D, mFramebufferColorTexture);
109 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
110 GL_UNSIGNED_BYTE, nullptr);
111 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
112 mFramebufferColorTexture, 0);
113 ASSERT_GL_NO_ERROR();
114 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
115 glBindTexture(GL_TEXTURE_2D, 0);
116 }
117
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200118 // Returns the created texture ID.
119 GLuint create2DTexture()
120 {
121 GLuint texture2D;
122 glGenTextures(1, &texture2D);
123 glBindTexture(GL_TEXTURE_2D, texture2D);
124 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
125 EXPECT_GL_NO_ERROR();
126 return texture2D;
127 }
128
129 GLuint mProgram;
Olli Etuaho51f1c0f2016-01-13 16:16:24 +0200130 GLuint mFramebuffer;
131
132 private:
133 GLuint mFramebufferColorTexture;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200134};
135
136class Texture2DTest : public TexCoordDrawTest
137{
138 protected:
139 Texture2DTest() : TexCoordDrawTest(), mTexture2D(0), mTexture2DUniformLocation(-1) {}
140
141 std::string getFragmentShaderSource() override
142 {
143 return std::string(SHADER_SOURCE
Geoff Langc41e42d2014-04-28 10:58:16 -0400144 (
145 precision highp float;
146 uniform sampler2D tex;
147 varying vec2 texcoord;
148
149 void main()
150 {
151 gl_FragColor = texture2D(tex, texcoord);
152 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200153 )
Geoff Langc41e42d2014-04-28 10:58:16 -0400154 );
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200155 }
Geoff Langc41e42d2014-04-28 10:58:16 -0400156
Olli Etuaho96963162016-03-21 11:54:33 +0200157 virtual const char *getTextureUniformName() { return "tex"; }
158
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300159 void setUpProgram() override
160 {
161 TexCoordDrawTest::setUpProgram();
162 mTexture2DUniformLocation = glGetUniformLocation(mProgram, getTextureUniformName());
163 ASSERT_NE(-1, mTexture2DUniformLocation);
164 }
165
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200166 void SetUp() override
167 {
168 TexCoordDrawTest::SetUp();
169 mTexture2D = create2DTexture();
Jamie Madilld4cfa572014-07-08 10:00:32 -0400170
Jamie Madill9aca0592014-10-06 16:26:59 -0400171 ASSERT_GL_NO_ERROR();
Jamie Madillf67115c2014-04-22 13:14:05 -0400172 }
173
Jamie Madillfa05f602015-05-07 13:47:11 -0400174 void TearDown() override
Jamie Madillf67115c2014-04-22 13:14:05 -0400175 {
Jamie Madilld4cfa572014-07-08 10:00:32 -0400176 glDeleteTextures(1, &mTexture2D);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200177 TexCoordDrawTest::TearDown();
Jamie Madillf67115c2014-04-22 13:14:05 -0400178 }
179
Jamie Madillbc393df2015-01-29 13:46:07 -0500180 // Tests CopyTexSubImage with floating point textures of various formats.
181 void testFloatCopySubImage(int sourceImageChannels, int destImageChannels)
182 {
Geoff Langbde666a2015-04-07 17:17:08 -0400183 // TODO(jmadill): Figure out why this is broken on Intel D3D11
Jamie Madill518b9fa2016-03-02 11:26:02 -0500184 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
Geoff Langbde666a2015-04-07 17:17:08 -0400185 {
186 std::cout << "Test skipped on Intel D3D11." << std::endl;
187 return;
188 }
189
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300190 setUpProgram();
191
Martin Radev1be913c2016-07-11 17:59:16 +0300192 if (getClientMajorVersion() < 3)
Geoff Langfbfa47c2015-03-31 11:26:00 -0400193 {
194 if (!extensionEnabled("GL_OES_texture_float"))
195 {
196 std::cout << "Test skipped due to missing GL_OES_texture_float." << std::endl;
197 return;
198 }
199
200 if ((sourceImageChannels < 3 || destImageChannels < 3) && !extensionEnabled("GL_EXT_texture_rg"))
201 {
202 std::cout << "Test skipped due to missing GL_EXT_texture_rg." << std::endl;
203 return;
204 }
205 }
206
Jamie Madillbc393df2015-01-29 13:46:07 -0500207 GLfloat sourceImageData[4][16] =
208 {
209 { // R
210 1.0f,
211 0.0f,
212 0.0f,
213 1.0f
214 },
215 { // RG
216 1.0f, 0.0f,
217 0.0f, 1.0f,
218 0.0f, 0.0f,
219 1.0f, 1.0f
220 },
221 { // RGB
222 1.0f, 0.0f, 0.0f,
223 0.0f, 1.0f, 0.0f,
224 0.0f, 0.0f, 1.0f,
225 1.0f, 1.0f, 0.0f
226 },
227 { // RGBA
228 1.0f, 0.0f, 0.0f, 1.0f,
229 0.0f, 1.0f, 0.0f, 1.0f,
230 0.0f, 0.0f, 1.0f, 1.0f,
231 1.0f, 1.0f, 0.0f, 1.0f
232 },
233 };
234
235 GLenum imageFormats[] =
236 {
237 GL_R32F,
238 GL_RG32F,
239 GL_RGB32F,
240 GL_RGBA32F,
241 };
242
243 GLenum sourceUnsizedFormats[] =
244 {
245 GL_RED,
246 GL_RG,
247 GL_RGB,
248 GL_RGBA,
249 };
250
251 GLuint textures[2];
252
253 glGenTextures(2, textures);
254
255 GLfloat *imageData = sourceImageData[sourceImageChannels - 1];
256 GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1];
257 GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1];
258 GLenum destImageFormat = imageFormats[destImageChannels - 1];
259
260 glBindTexture(GL_TEXTURE_2D, textures[0]);
261 glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
262 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
263 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
264 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData);
265
hendrikwb27f79a2015-03-04 11:26:46 -0800266 if (sourceImageChannels < 3 && !extensionEnabled("GL_EXT_texture_rg"))
Jamie Madillbc393df2015-01-29 13:46:07 -0500267 {
268 // This is not supported
269 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
270 }
271 else
272 {
273 ASSERT_GL_NO_ERROR();
274 }
275
276 GLuint fbo;
277 glGenFramebuffers(1, &fbo);
278 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
279 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
280
281 glBindTexture(GL_TEXTURE_2D, textures[1]);
282 glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
283 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
284 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
285
286 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
287 ASSERT_GL_NO_ERROR();
288
289 glBindFramebuffer(GL_FRAMEBUFFER, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200290 drawQuad(mProgram, "position", 0.5f);
Jamie Madillbc393df2015-01-29 13:46:07 -0500291
292 int testImageChannels = std::min(sourceImageChannels, destImageChannels);
293
Olli Etuahoa314b612016-03-10 16:43:00 +0200294 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Jamie Madillbc393df2015-01-29 13:46:07 -0500295 if (testImageChannels > 1)
296 {
297 EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255);
298 EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255);
299 if (testImageChannels > 2)
300 {
301 EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255);
302 }
303 }
304
305 glDeleteFramebuffers(1, &fbo);
306 glDeleteTextures(2, textures);
307
308 ASSERT_GL_NO_ERROR();
309 }
310
Jamie Madilld4cfa572014-07-08 10:00:32 -0400311 GLuint mTexture2D;
Jamie Madilld4cfa572014-07-08 10:00:32 -0400312 GLint mTexture2DUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400313};
314
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200315class Texture2DTestES3 : public Texture2DTest
316{
317 protected:
318 Texture2DTestES3() : Texture2DTest() {}
319
320 std::string getVertexShaderSource() override
321 {
322 return std::string(
323 "#version 300 es\n"
324 "out vec2 texcoord;\n"
325 "in vec4 position;\n"
326 "void main()\n"
327 "{\n"
328 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
329 " texcoord = (position.xy * 0.5) + 0.5;\n"
330 "}\n");
331 }
332
333 std::string getFragmentShaderSource() override
334 {
335 return std::string(
336 "#version 300 es\n"
337 "precision highp float;\n"
338 "uniform highp sampler2D tex;\n"
339 "in vec2 texcoord;\n"
340 "out vec4 fragColor;\n"
341 "void main()\n"
342 "{\n"
343 " fragColor = texture(tex, texcoord);\n"
344 "}\n");
345 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300346
347 void SetUp() override
348 {
349 Texture2DTest::SetUp();
350 setUpProgram();
351 }
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200352};
353
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200354class Texture2DIntegerAlpha1TestES3 : public Texture2DTest
355{
356 protected:
357 Texture2DIntegerAlpha1TestES3() : Texture2DTest() {}
358
359 std::string getVertexShaderSource() override
360 {
361 return std::string(
362 "#version 300 es\n"
363 "out vec2 texcoord;\n"
364 "in vec4 position;\n"
365 "void main()\n"
366 "{\n"
367 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
368 " texcoord = (position.xy * 0.5) + 0.5;\n"
369 "}\n");
370 }
371
372 std::string getFragmentShaderSource() override
373 {
374 return std::string(
375 "#version 300 es\n"
376 "precision highp float;\n"
377 "uniform highp isampler2D tex;\n"
378 "in vec2 texcoord;\n"
379 "out vec4 fragColor;\n"
380 "void main()\n"
381 "{\n"
382 " vec4 green = vec4(0, 1, 0, 1);\n"
383 " vec4 black = vec4(0, 0, 0, 0);\n"
384 " fragColor = (texture(tex, texcoord).a == 1) ? green : black;\n"
385 "}\n");
386 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300387
388 void SetUp() override
389 {
390 Texture2DTest::SetUp();
391 setUpProgram();
392 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200393};
394
395class Texture2DUnsignedIntegerAlpha1TestES3 : public Texture2DTest
396{
397 protected:
398 Texture2DUnsignedIntegerAlpha1TestES3() : Texture2DTest() {}
399
400 std::string getVertexShaderSource() override
401 {
402 return std::string(
403 "#version 300 es\n"
404 "out vec2 texcoord;\n"
405 "in vec4 position;\n"
406 "void main()\n"
407 "{\n"
408 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
409 " texcoord = (position.xy * 0.5) + 0.5;\n"
410 "}\n");
411 }
412
413 std::string getFragmentShaderSource() override
414 {
415 return std::string(
416 "#version 300 es\n"
417 "precision highp float;\n"
418 "uniform highp usampler2D tex;\n"
419 "in vec2 texcoord;\n"
420 "out vec4 fragColor;\n"
421 "void main()\n"
422 "{\n"
423 " vec4 green = vec4(0, 1, 0, 1);\n"
424 " vec4 black = vec4(0, 0, 0, 0);\n"
425 " fragColor = (texture(tex, texcoord).a == 1u) ? green : black;\n"
426 "}\n");
427 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300428
429 void SetUp() override
430 {
431 Texture2DTest::SetUp();
432 setUpProgram();
433 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200434};
435
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200436class Texture2DTestWithDrawScale : public Texture2DTest
Jamie Madill2453dbc2015-07-14 11:35:42 -0400437{
438 protected:
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200439 Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {}
440
441 std::string getVertexShaderSource() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400442 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200443 return std::string(SHADER_SOURCE
444 (
445 precision highp float;
446 attribute vec4 position;
447 varying vec2 texcoord;
448
449 uniform vec2 drawScale;
450
451 void main()
452 {
453 gl_Position = vec4(position.xy * drawScale, 0.0, 1.0);
454 texcoord = (position.xy * 0.5) + 0.5;
455 }
456 )
457 );
Jamie Madill2453dbc2015-07-14 11:35:42 -0400458 }
459
460 void SetUp() override
461 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200462 Texture2DTest::SetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300463
464 setUpProgram();
465
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200466 mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale");
467 ASSERT_NE(-1, mDrawScaleUniformLocation);
Jamie Madill2453dbc2015-07-14 11:35:42 -0400468
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200469 glUseProgram(mProgram);
470 glUniform2f(mDrawScaleUniformLocation, 1.0f, 1.0f);
471 glUseProgram(0);
472 ASSERT_GL_NO_ERROR();
473 }
474
475 GLint mDrawScaleUniformLocation;
476};
477
Olli Etuaho4644a202016-01-12 15:12:53 +0200478class Sampler2DAsFunctionParameterTest : public Texture2DTest
479{
480 protected:
481 Sampler2DAsFunctionParameterTest() : Texture2DTest() {}
482
483 std::string getFragmentShaderSource() override
484 {
485 return std::string(SHADER_SOURCE
486 (
487 precision highp float;
488 uniform sampler2D tex;
489 varying vec2 texcoord;
490
491 vec4 computeFragColor(sampler2D aTex)
492 {
493 return texture2D(aTex, texcoord);
494 }
495
496 void main()
497 {
498 gl_FragColor = computeFragColor(tex);
499 }
500 )
501 );
502 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300503
504 void SetUp() override
505 {
506 Texture2DTest::SetUp();
507 setUpProgram();
508 }
Olli Etuaho4644a202016-01-12 15:12:53 +0200509};
510
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200511class TextureCubeTest : public TexCoordDrawTest
512{
513 protected:
514 TextureCubeTest()
515 : TexCoordDrawTest(),
516 mTexture2D(0),
517 mTextureCube(0),
518 mTexture2DUniformLocation(-1),
519 mTextureCubeUniformLocation(-1)
520 {
521 }
522
523 std::string getFragmentShaderSource() override
524 {
525 return std::string(SHADER_SOURCE
526 (
527 precision highp float;
528 uniform sampler2D tex2D;
529 uniform samplerCube texCube;
530 varying vec2 texcoord;
531
532 void main()
533 {
534 gl_FragColor = texture2D(tex2D, texcoord);
535 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
536 }
537 )
538 );
539 }
540
541 void SetUp() override
542 {
543 TexCoordDrawTest::SetUp();
544
545 glGenTextures(1, &mTextureCube);
546 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
547 glTexStorage2DEXT(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
548 EXPECT_GL_NO_ERROR();
549
550 mTexture2D = create2DTexture();
551
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300552 setUpProgram();
553
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200554 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
555 ASSERT_NE(-1, mTexture2DUniformLocation);
556 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
557 ASSERT_NE(-1, mTextureCubeUniformLocation);
558 }
559
560 void TearDown() override
561 {
562 glDeleteTextures(1, &mTextureCube);
563 TexCoordDrawTest::TearDown();
564 }
565
566 GLuint mTexture2D;
567 GLuint mTextureCube;
568 GLint mTexture2DUniformLocation;
569 GLint mTextureCubeUniformLocation;
570};
571
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200572class SamplerArrayTest : public TexCoordDrawTest
573{
574 protected:
575 SamplerArrayTest()
576 : TexCoordDrawTest(),
577 mTexture2DA(0),
578 mTexture2DB(0),
579 mTexture0UniformLocation(-1),
580 mTexture1UniformLocation(-1)
581 {
582 }
583
584 std::string getFragmentShaderSource() override
585 {
586 return std::string(SHADER_SOURCE
587 (
588 precision mediump float;
589 uniform highp sampler2D tex2DArray[2];
590 varying vec2 texcoord;
591 void main()
592 {
593 gl_FragColor = texture2D(tex2DArray[0], texcoord);
594 gl_FragColor += texture2D(tex2DArray[1], texcoord);
595 }
596 )
597 );
598 }
599
600 void SetUp() override
601 {
602 TexCoordDrawTest::SetUp();
603
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300604 setUpProgram();
605
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200606 mTexture0UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[0]");
607 ASSERT_NE(-1, mTexture0UniformLocation);
608 mTexture1UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[1]");
609 ASSERT_NE(-1, mTexture1UniformLocation);
610
611 mTexture2DA = create2DTexture();
612 mTexture2DB = create2DTexture();
613 ASSERT_GL_NO_ERROR();
614 }
615
616 void TearDown() override
617 {
618 glDeleteTextures(1, &mTexture2DA);
619 glDeleteTextures(1, &mTexture2DB);
620 TexCoordDrawTest::TearDown();
621 }
622
623 void testSamplerArrayDraw()
624 {
625 GLubyte texData[4];
626 texData[0] = 0;
627 texData[1] = 60;
628 texData[2] = 0;
629 texData[3] = 255;
630
631 glActiveTexture(GL_TEXTURE0);
632 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
633 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
634
635 texData[1] = 120;
636 glActiveTexture(GL_TEXTURE1);
637 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
638 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
639 EXPECT_GL_ERROR(GL_NO_ERROR);
640
641 glUseProgram(mProgram);
642 glUniform1i(mTexture0UniformLocation, 0);
643 glUniform1i(mTexture1UniformLocation, 1);
644 drawQuad(mProgram, "position", 0.5f);
645 EXPECT_GL_NO_ERROR();
646
647 EXPECT_PIXEL_NEAR(0, 0, 0, 180, 0, 255, 2);
648 }
649
650 GLuint mTexture2DA;
651 GLuint mTexture2DB;
652 GLint mTexture0UniformLocation;
653 GLint mTexture1UniformLocation;
654};
655
656
657class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest
658{
659 protected:
660 SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {}
661
662 std::string getFragmentShaderSource() override
663 {
664 return std::string(SHADER_SOURCE
665 (
666 precision mediump float;
667 uniform highp sampler2D tex2DArray[2];
668 varying vec2 texcoord;
669
670 vec4 computeFragColor(highp sampler2D aTex2DArray[2])
671 {
672 return texture2D(aTex2DArray[0], texcoord) + texture2D(aTex2DArray[1], texcoord);
673 }
674
675 void main()
676 {
677 gl_FragColor = computeFragColor(tex2DArray);
678 }
679 )
680 );
681 }
682};
683
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200684class Texture2DArrayTestES3 : public TexCoordDrawTest
685{
686 protected:
687 Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {}
688
689 std::string getVertexShaderSource() override
690 {
691 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400692 "#version 300 es\n"
693 "out vec2 texcoord;\n"
694 "in vec4 position;\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200695 "void main()\n"
696 "{\n"
697 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
698 " texcoord = (position.xy * 0.5) + 0.5;\n"
699 "}\n");
700 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400701
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200702 std::string getFragmentShaderSource() override
703 {
704 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400705 "#version 300 es\n"
706 "precision highp float;\n"
Olli Etuaho183d7e22015-11-20 15:59:09 +0200707 "uniform highp sampler2DArray tex2DArray;\n"
Jamie Madill2453dbc2015-07-14 11:35:42 -0400708 "in vec2 texcoord;\n"
709 "out vec4 fragColor;\n"
710 "void main()\n"
711 "{\n"
712 " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200713 "}\n");
714 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400715
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200716 void SetUp() override
717 {
718 TexCoordDrawTest::SetUp();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400719
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300720 setUpProgram();
721
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200722 mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray");
Jamie Madill2453dbc2015-07-14 11:35:42 -0400723 ASSERT_NE(-1, mTextureArrayLocation);
724
725 glGenTextures(1, &m2DArrayTexture);
726 ASSERT_GL_NO_ERROR();
727 }
728
729 void TearDown() override
730 {
731 glDeleteTextures(1, &m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200732 TexCoordDrawTest::TearDown();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400733 }
734
735 GLuint m2DArrayTexture;
Jamie Madill2453dbc2015-07-14 11:35:42 -0400736 GLint mTextureArrayLocation;
737};
738
Olli Etuahobce743a2016-01-15 17:18:28 +0200739class TextureSizeTextureArrayTest : public TexCoordDrawTest
740{
741 protected:
742 TextureSizeTextureArrayTest()
743 : TexCoordDrawTest(),
744 mTexture2DA(0),
745 mTexture2DB(0),
746 mTexture0Location(-1),
747 mTexture1Location(-1)
748 {
749 }
750
751 std::string getVertexShaderSource() override
752 {
753 return std::string(
754 "#version 300 es\n"
755 "in vec4 position;\n"
756 "void main()\n"
757 "{\n"
758 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
759 "}\n");
760 }
761
762 std::string getFragmentShaderSource() override
763 {
764 return std::string(
765 "#version 300 es\n"
766 "precision highp float;\n"
767 "uniform highp sampler2D tex2DArray[2];\n"
768 "out vec4 fragColor;\n"
769 "void main()\n"
770 "{\n"
771 " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n"
772 " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n"
773 " fragColor = vec4(red, green, 0.0, 1.0);\n"
774 "}\n");
775 }
776
777 void SetUp() override
778 {
779 TexCoordDrawTest::SetUp();
780
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300781 setUpProgram();
782
Olli Etuahobce743a2016-01-15 17:18:28 +0200783 mTexture0Location = glGetUniformLocation(mProgram, "tex2DArray[0]");
784 ASSERT_NE(-1, mTexture0Location);
785 mTexture1Location = glGetUniformLocation(mProgram, "tex2DArray[1]");
786 ASSERT_NE(-1, mTexture1Location);
787
788 mTexture2DA = create2DTexture();
789 mTexture2DB = create2DTexture();
790 ASSERT_GL_NO_ERROR();
791 }
792
793 void TearDown() override
794 {
795 glDeleteTextures(1, &mTexture2DA);
796 glDeleteTextures(1, &mTexture2DB);
797 TexCoordDrawTest::TearDown();
798 }
799
800 GLuint mTexture2DA;
801 GLuint mTexture2DB;
802 GLint mTexture0Location;
803 GLint mTexture1Location;
804};
805
Olli Etuahoa314b612016-03-10 16:43:00 +0200806class Texture3DTestES3 : public TexCoordDrawTest
807{
808 protected:
809 Texture3DTestES3() : TexCoordDrawTest(), mTexture3D(0), mTexture3DUniformLocation(-1) {}
810
811 std::string getVertexShaderSource() override
812 {
813 return std::string(
814 "#version 300 es\n"
815 "out vec2 texcoord;\n"
816 "in vec4 position;\n"
817 "void main()\n"
818 "{\n"
819 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
820 " texcoord = (position.xy * 0.5) + 0.5;\n"
821 "}\n");
822 }
823
824 std::string getFragmentShaderSource() override
825 {
826 return std::string(
827 "#version 300 es\n"
828 "precision highp float;\n"
829 "uniform highp sampler3D tex3D;\n"
830 "in vec2 texcoord;\n"
831 "out vec4 fragColor;\n"
832 "void main()\n"
833 "{\n"
834 " fragColor = texture(tex3D, vec3(texcoord, 0.0));\n"
835 "}\n");
836 }
837
838 void SetUp() override
839 {
840 TexCoordDrawTest::SetUp();
841
842 glGenTextures(1, &mTexture3D);
843
844 setUpProgram();
845
846 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
847 ASSERT_NE(-1, mTexture3DUniformLocation);
848 }
849
850 void TearDown() override
851 {
852 glDeleteTextures(1, &mTexture3D);
853 TexCoordDrawTest::TearDown();
854 }
855
856 GLuint mTexture3D;
857 GLint mTexture3DUniformLocation;
858};
859
Olli Etuaho1a679902016-01-14 12:21:47 +0200860class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest
861{
862 protected:
863 ShadowSamplerPlusSampler3DTestES3()
864 : TexCoordDrawTest(),
865 mTextureShadow(0),
866 mTexture3D(0),
867 mTextureShadowUniformLocation(-1),
868 mTexture3DUniformLocation(-1),
869 mDepthRefUniformLocation(-1)
870 {
871 }
872
873 std::string getVertexShaderSource() override
874 {
875 return std::string(
876 "#version 300 es\n"
877 "out vec2 texcoord;\n"
878 "in vec4 position;\n"
879 "void main()\n"
880 "{\n"
881 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
882 " texcoord = (position.xy * 0.5) + 0.5;\n"
883 "}\n");
884 }
885
886 std::string getFragmentShaderSource() override
887 {
888 return std::string(
889 "#version 300 es\n"
890 "precision highp float;\n"
891 "uniform highp sampler2DShadow tex2DShadow;\n"
892 "uniform highp sampler3D tex3D;\n"
893 "in vec2 texcoord;\n"
894 "uniform float depthRef;\n"
895 "out vec4 fragColor;\n"
896 "void main()\n"
897 "{\n"
898 " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n"
899 " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n"
900 "}\n");
901 }
902
903 void SetUp() override
904 {
905 TexCoordDrawTest::SetUp();
906
907 glGenTextures(1, &mTexture3D);
908
909 glGenTextures(1, &mTextureShadow);
910 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
911 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
912
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300913 setUpProgram();
914
Olli Etuaho1a679902016-01-14 12:21:47 +0200915 mTextureShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
916 ASSERT_NE(-1, mTextureShadowUniformLocation);
917 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
918 ASSERT_NE(-1, mTexture3DUniformLocation);
919 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
920 ASSERT_NE(-1, mDepthRefUniformLocation);
921 }
922
923 void TearDown() override
924 {
925 glDeleteTextures(1, &mTextureShadow);
926 glDeleteTextures(1, &mTexture3D);
927 TexCoordDrawTest::TearDown();
928 }
929
930 GLuint mTextureShadow;
931 GLuint mTexture3D;
932 GLint mTextureShadowUniformLocation;
933 GLint mTexture3DUniformLocation;
934 GLint mDepthRefUniformLocation;
935};
936
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200937class SamplerTypeMixTestES3 : public TexCoordDrawTest
938{
939 protected:
940 SamplerTypeMixTestES3()
941 : TexCoordDrawTest(),
942 mTexture2D(0),
943 mTextureCube(0),
944 mTexture2DShadow(0),
945 mTextureCubeShadow(0),
946 mTexture2DUniformLocation(-1),
947 mTextureCubeUniformLocation(-1),
948 mTexture2DShadowUniformLocation(-1),
949 mTextureCubeShadowUniformLocation(-1),
950 mDepthRefUniformLocation(-1)
951 {
952 }
953
954 std::string getVertexShaderSource() override
955 {
956 return std::string(
957 "#version 300 es\n"
958 "out vec2 texcoord;\n"
959 "in vec4 position;\n"
960 "void main()\n"
961 "{\n"
962 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
963 " texcoord = (position.xy * 0.5) + 0.5;\n"
964 "}\n");
965 }
966
967 std::string getFragmentShaderSource() override
968 {
969 return std::string(
970 "#version 300 es\n"
971 "precision highp float;\n"
972 "uniform highp sampler2D tex2D;\n"
973 "uniform highp samplerCube texCube;\n"
974 "uniform highp sampler2DShadow tex2DShadow;\n"
975 "uniform highp samplerCubeShadow texCubeShadow;\n"
976 "in vec2 texcoord;\n"
977 "uniform float depthRef;\n"
978 "out vec4 fragColor;\n"
979 "void main()\n"
980 "{\n"
981 " fragColor = texture(tex2D, texcoord);\n"
982 " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n"
983 " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n"
984 " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * "
985 "0.125);\n"
986 "}\n");
987 }
988
989 void SetUp() override
990 {
991 TexCoordDrawTest::SetUp();
992
993 glGenTextures(1, &mTexture2D);
994 glGenTextures(1, &mTextureCube);
995
996 glGenTextures(1, &mTexture2DShadow);
997 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
998 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
999
1000 glGenTextures(1, &mTextureCubeShadow);
1001 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
1002 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
1003
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001004 setUpProgram();
1005
Olli Etuahoc8c99a02016-01-14 16:47:22 +02001006 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
1007 ASSERT_NE(-1, mTexture2DUniformLocation);
1008 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
1009 ASSERT_NE(-1, mTextureCubeUniformLocation);
1010 mTexture2DShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
1011 ASSERT_NE(-1, mTexture2DShadowUniformLocation);
1012 mTextureCubeShadowUniformLocation = glGetUniformLocation(mProgram, "texCubeShadow");
1013 ASSERT_NE(-1, mTextureCubeShadowUniformLocation);
1014 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
1015 ASSERT_NE(-1, mDepthRefUniformLocation);
1016
1017 ASSERT_GL_NO_ERROR();
1018 }
1019
1020 void TearDown() override
1021 {
1022 glDeleteTextures(1, &mTexture2D);
1023 glDeleteTextures(1, &mTextureCube);
1024 glDeleteTextures(1, &mTexture2DShadow);
1025 glDeleteTextures(1, &mTextureCubeShadow);
1026 TexCoordDrawTest::TearDown();
1027 }
1028
1029 GLuint mTexture2D;
1030 GLuint mTextureCube;
1031 GLuint mTexture2DShadow;
1032 GLuint mTextureCubeShadow;
1033 GLint mTexture2DUniformLocation;
1034 GLint mTextureCubeUniformLocation;
1035 GLint mTexture2DShadowUniformLocation;
1036 GLint mTextureCubeShadowUniformLocation;
1037 GLint mDepthRefUniformLocation;
1038};
1039
Olli Etuaho96963162016-03-21 11:54:33 +02001040class SamplerInStructTest : public Texture2DTest
1041{
1042 protected:
1043 SamplerInStructTest() : Texture2DTest() {}
1044
1045 const char *getTextureUniformName() override { return "us.tex"; }
1046
1047 std::string getFragmentShaderSource() override
1048 {
1049 return std::string(
1050 "precision highp float;\n"
1051 "struct S\n"
1052 "{\n"
1053 " vec4 a;\n"
1054 " highp sampler2D tex;\n"
1055 "};\n"
1056 "uniform S us;\n"
1057 "varying vec2 texcoord;\n"
1058 "void main()\n"
1059 "{\n"
1060 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x);\n"
1061 "}\n");
1062 }
1063
1064 void runSamplerInStructTest()
1065 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001066 setUpProgram();
1067
Olli Etuaho96963162016-03-21 11:54:33 +02001068 glActiveTexture(GL_TEXTURE0);
1069 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001070 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1071 &GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001072 drawQuad(mProgram, "position", 0.5f);
Olli Etuahoa314b612016-03-10 16:43:00 +02001073 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001074 }
1075};
1076
1077class SamplerInStructAsFunctionParameterTest : public SamplerInStructTest
1078{
1079 protected:
1080 SamplerInStructAsFunctionParameterTest() : SamplerInStructTest() {}
1081
1082 std::string getFragmentShaderSource() override
1083 {
1084 return std::string(
1085 "precision highp float;\n"
1086 "struct S\n"
1087 "{\n"
1088 " vec4 a;\n"
1089 " highp sampler2D tex;\n"
1090 "};\n"
1091 "uniform S us;\n"
1092 "varying vec2 texcoord;\n"
1093 "vec4 sampleFrom(S s) {\n"
1094 " return texture2D(s.tex, texcoord + s.a.x);\n"
1095 "}\n"
1096 "void main()\n"
1097 "{\n"
1098 " gl_FragColor = sampleFrom(us);\n"
1099 "}\n");
1100 }
1101};
1102
1103class SamplerInStructArrayAsFunctionParameterTest : public SamplerInStructTest
1104{
1105 protected:
1106 SamplerInStructArrayAsFunctionParameterTest() : SamplerInStructTest() {}
1107
1108 const char *getTextureUniformName() override { return "us[0].tex"; }
1109
1110 std::string getFragmentShaderSource() override
1111 {
1112 return std::string(
1113 "precision highp float;\n"
1114 "struct S\n"
1115 "{\n"
1116 " vec4 a;\n"
1117 " highp sampler2D tex;\n"
1118 "};\n"
1119 "uniform S us[1];\n"
1120 "varying vec2 texcoord;\n"
1121 "vec4 sampleFrom(S s) {\n"
1122 " return texture2D(s.tex, texcoord + s.a.x);\n"
1123 "}\n"
1124 "void main()\n"
1125 "{\n"
1126 " gl_FragColor = sampleFrom(us[0]);\n"
1127 "}\n");
1128 }
1129};
1130
1131class SamplerInNestedStructAsFunctionParameterTest : public SamplerInStructTest
1132{
1133 protected:
1134 SamplerInNestedStructAsFunctionParameterTest() : SamplerInStructTest() {}
1135
1136 const char *getTextureUniformName() override { return "us[0].sub.tex"; }
1137
1138 std::string getFragmentShaderSource() override
1139 {
1140 return std::string(
1141 "precision highp float;\n"
1142 "struct SUB\n"
1143 "{\n"
1144 " vec4 a;\n"
1145 " highp sampler2D tex;\n"
1146 "};\n"
1147 "struct S\n"
1148 "{\n"
1149 " SUB sub;\n"
1150 "};\n"
1151 "uniform S us[1];\n"
1152 "varying vec2 texcoord;\n"
1153 "vec4 sampleFrom(SUB s) {\n"
1154 " return texture2D(s.tex, texcoord + s.a.x);\n"
1155 "}\n"
1156 "void main()\n"
1157 "{\n"
1158 " gl_FragColor = sampleFrom(us[0].sub);\n"
1159 "}\n");
1160 }
1161};
1162
1163class SamplerInStructAndOtherVariableTest : public SamplerInStructTest
1164{
1165 protected:
1166 SamplerInStructAndOtherVariableTest() : SamplerInStructTest() {}
1167
1168 std::string getFragmentShaderSource() override
1169 {
1170 return std::string(
1171 "precision highp float;\n"
1172 "struct S\n"
1173 "{\n"
1174 " vec4 a;\n"
1175 " highp sampler2D tex;\n"
1176 "};\n"
1177 "uniform S us;\n"
1178 "uniform float us_tex;\n"
1179 "varying vec2 texcoord;\n"
1180 "void main()\n"
1181 "{\n"
1182 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x + us_tex);\n"
1183 "}\n");
1184 }
1185};
1186
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001187TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001188{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001189 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001190 EXPECT_GL_ERROR(GL_NO_ERROR);
1191
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001192 setUpProgram();
1193
Jamie Madillf67115c2014-04-22 13:14:05 -04001194 const GLubyte *pixels[20] = { 0 };
1195 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1196 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1197}
Geoff Langc41e42d2014-04-28 10:58:16 -04001198
John Bauman18319182016-09-28 14:22:27 -07001199// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1200TEST_P(Texture2DTest, QueryBinding)
1201{
1202 glBindTexture(GL_TEXTURE_2D, 0);
1203 EXPECT_GL_ERROR(GL_NO_ERROR);
1204
1205 GLint textureBinding;
1206 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1207 EXPECT_GL_NO_ERROR();
1208 EXPECT_EQ(0, textureBinding);
1209
1210 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
1211 if (extensionEnabled("GL_OES_EGL_image_external") ||
1212 extensionEnabled("GL_NV_EGL_stream_consumer_external"))
1213 {
1214 EXPECT_GL_NO_ERROR();
1215 EXPECT_EQ(0, textureBinding);
1216 }
1217 else
1218 {
1219 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1220 }
1221}
1222
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001223TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001224{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001225 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001226 EXPECT_GL_ERROR(GL_NO_ERROR);
1227
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001228 setUpProgram();
1229
Geoff Langc41e42d2014-04-28 10:58:16 -04001230 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001231 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001232 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001233 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001234
1235 const GLubyte *pixel[4] = { 0 };
1236
1237 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1238 EXPECT_GL_NO_ERROR();
1239
1240 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1241 EXPECT_GL_NO_ERROR();
1242
1243 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1244 EXPECT_GL_NO_ERROR();
1245}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001246
1247// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001248TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001249{
1250 glActiveTexture(GL_TEXTURE0);
1251 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1252 glActiveTexture(GL_TEXTURE1);
1253 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1254 EXPECT_GL_ERROR(GL_NO_ERROR);
1255
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001256 glUseProgram(mProgram);
1257 glUniform1i(mTexture2DUniformLocation, 0);
1258 glUniform1i(mTextureCubeUniformLocation, 1);
1259 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001260 EXPECT_GL_NO_ERROR();
1261}
Jamie Madill9aca0592014-10-06 16:26:59 -04001262
Olli Etuaho53a2da12016-01-11 15:43:32 +02001263// Test drawing with two texture types accessed from the same shader and check that the result of
1264// drawing is correct.
1265TEST_P(TextureCubeTest, CubeMapDraw)
1266{
1267 GLubyte texData[4];
1268 texData[0] = 0;
1269 texData[1] = 60;
1270 texData[2] = 0;
1271 texData[3] = 255;
1272
1273 glActiveTexture(GL_TEXTURE0);
1274 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1275 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1276
1277 glActiveTexture(GL_TEXTURE1);
1278 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1279 texData[1] = 120;
1280 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1281 texData);
1282 EXPECT_GL_ERROR(GL_NO_ERROR);
1283
1284 glUseProgram(mProgram);
1285 glUniform1i(mTexture2DUniformLocation, 0);
1286 glUniform1i(mTextureCubeUniformLocation, 1);
1287 drawQuad(mProgram, "position", 0.5f);
1288 EXPECT_GL_NO_ERROR();
1289
1290 int px = getWindowWidth() - 1;
1291 int py = 0;
1292 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1293}
1294
Olli Etuaho4644a202016-01-12 15:12:53 +02001295TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1296{
1297 glActiveTexture(GL_TEXTURE0);
1298 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1299 GLubyte texData[4];
1300 texData[0] = 0;
1301 texData[1] = 128;
1302 texData[2] = 0;
1303 texData[3] = 255;
1304 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1305 glUseProgram(mProgram);
1306 glUniform1i(mTexture2DUniformLocation, 0);
1307 drawQuad(mProgram, "position", 0.5f);
1308 EXPECT_GL_NO_ERROR();
1309
1310 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1311}
1312
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001313// Test drawing with two textures passed to the shader in a sampler array.
1314TEST_P(SamplerArrayTest, SamplerArrayDraw)
1315{
1316 testSamplerArrayDraw();
1317}
1318
1319// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1320// user-defined function in the shader.
1321TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1322{
1323 testSamplerArrayDraw();
1324}
1325
Jamie Madill9aca0592014-10-06 16:26:59 -04001326// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001327TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001328{
1329 int px = getWindowWidth() / 2;
1330 int py = getWindowHeight() / 2;
1331
1332 glActiveTexture(GL_TEXTURE0);
1333 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1334
Olli Etuahoa314b612016-03-10 16:43:00 +02001335 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001336
Olli Etuahoa314b612016-03-10 16:43:00 +02001337 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001338 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1339 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1340 glGenerateMipmap(GL_TEXTURE_2D);
1341
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001342 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001343 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001344 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1345 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001346 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001347 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001348
Olli Etuahoa314b612016-03-10 16:43:00 +02001349 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001350
Olli Etuahoa314b612016-03-10 16:43:00 +02001351 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1352 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001353 glGenerateMipmap(GL_TEXTURE_2D);
1354
Olli Etuahoa314b612016-03-10 16:43:00 +02001355 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001356
Olli Etuahoa314b612016-03-10 16:43:00 +02001357 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1358 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001359 glGenerateMipmap(GL_TEXTURE_2D);
1360
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001361 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001362
1363 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001364 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001365}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001366
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001367// Test creating a FBO with a cube map render target, to test an ANGLE bug
1368// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001369TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001370{
1371 GLuint fbo;
1372 glGenFramebuffers(1, &fbo);
1373 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1374
1375 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1376 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mTextureCube, 0);
1377
Corentin Wallez322653b2015-06-17 18:33:56 +02001378 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001379
1380 glDeleteFramebuffers(1, &fbo);
1381
1382 EXPECT_GL_NO_ERROR();
1383}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001384
1385// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001386TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001387{
1388 int width = getWindowWidth();
1389 int height = getWindowHeight();
1390
1391 GLuint tex2D;
1392 glGenTextures(1, &tex2D);
1393 glActiveTexture(GL_TEXTURE0);
1394 glBindTexture(GL_TEXTURE_2D, tex2D);
1395
1396 // Fill with red
1397 std::vector<GLubyte> pixels(3 * 16 * 16);
1398 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1399 {
1400 pixels[pixelId * 3 + 0] = 255;
1401 pixels[pixelId * 3 + 1] = 0;
1402 pixels[pixelId * 3 + 2] = 0;
1403 }
1404
1405 // ANGLE internally uses RGBA as the DirectX format for RGB images
1406 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1407 // The data is kept in a CPU-side image and the image is marked as dirty.
1408 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1409
1410 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1411 // glTexSubImage2D should take into account that the image is dirty.
1412 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1413 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1414 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1415
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001416 setUpProgram();
1417
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001418 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001419 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001420 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001421 glDeleteTextures(1, &tex2D);
1422 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001423 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001424
1425 // Validate that the region of the texture without data has an alpha of 1.0
1426 GLubyte pixel[4];
1427 glReadPixels(3 * width / 4, 3 * height / 4, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1428 EXPECT_EQ(pixel[3], 255);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001429}
1430
1431// 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 +02001432TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001433{
1434 if (extensionEnabled("NV_pixel_buffer_object"))
1435 {
1436 int width = getWindowWidth();
1437 int height = getWindowHeight();
1438
1439 GLuint tex2D;
1440 glGenTextures(1, &tex2D);
1441 glActiveTexture(GL_TEXTURE0);
1442 glBindTexture(GL_TEXTURE_2D, tex2D);
1443
1444 // Fill with red
1445 std::vector<GLubyte> pixels(3 * 16 * 16);
1446 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1447 {
1448 pixels[pixelId * 3 + 0] = 255;
1449 pixels[pixelId * 3 + 1] = 0;
1450 pixels[pixelId * 3 + 2] = 0;
1451 }
1452
1453 // Read 16x16 region from red backbuffer to PBO
1454 GLuint pbo;
1455 glGenBuffers(1, &pbo);
1456 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1457 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1458
1459 // ANGLE internally uses RGBA as the DirectX format for RGB images
1460 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1461 // The data is kept in a CPU-side image and the image is marked as dirty.
1462 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1463
1464 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1465 // glTexSubImage2D should take into account that the image is dirty.
1466 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, NULL);
1467 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1468 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1469
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001470 setUpProgram();
1471
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001472 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001473 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001474 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001475 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001476 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001477 EXPECT_GL_NO_ERROR();
1478 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1479 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1480 }
1481}
Jamie Madillbc393df2015-01-29 13:46:07 -05001482
1483// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001484TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001485{
1486 testFloatCopySubImage(1, 1);
1487}
1488
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001489TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001490{
1491 testFloatCopySubImage(2, 1);
1492}
1493
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001494TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001495{
1496 testFloatCopySubImage(2, 2);
1497}
1498
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001499TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001500{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001501 if (IsIntel() && IsLinux())
1502 {
1503 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1504 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1505 return;
1506 }
1507
Jamie Madillbc393df2015-01-29 13:46:07 -05001508 testFloatCopySubImage(3, 1);
1509}
1510
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001511TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001512{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001513 if (IsIntel() && IsLinux())
1514 {
1515 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1516 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1517 return;
1518 }
1519
Jamie Madillbc393df2015-01-29 13:46:07 -05001520 testFloatCopySubImage(3, 2);
1521}
1522
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001523TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001524{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001525 if (IsIntel() && IsLinux())
1526 {
1527 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1528 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1529 return;
1530 }
1531
Austin Kinrossd544cc92016-01-11 15:26:42 -08001532 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001533 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001534 {
1535 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1536 return;
1537 }
1538
Jamie Madillbc393df2015-01-29 13:46:07 -05001539 testFloatCopySubImage(3, 3);
1540}
1541
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001542TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001543{
1544 testFloatCopySubImage(4, 1);
1545}
1546
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001547TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001548{
1549 testFloatCopySubImage(4, 2);
1550}
1551
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001552TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001553{
Austin Kinrossd544cc92016-01-11 15:26:42 -08001554 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001555 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001556 {
1557 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1558 return;
1559 }
1560
Jamie Madillbc393df2015-01-29 13:46:07 -05001561 testFloatCopySubImage(4, 3);
1562}
1563
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001564TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001565{
Austin Kinrossd544cc92016-01-11 15:26:42 -08001566 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001567 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001568 {
1569 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1570 return;
1571 }
1572
Jamie Madillbc393df2015-01-29 13:46:07 -05001573 testFloatCopySubImage(4, 4);
1574}
Austin Kinross07285142015-03-26 11:36:16 -07001575
1576// Port of https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1577// 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 +02001578TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001579{
1580 const int npotTexSize = 5;
1581 const int potTexSize = 4; // Should be less than npotTexSize
1582 GLuint tex2D;
1583
1584 if (extensionEnabled("GL_OES_texture_npot"))
1585 {
1586 // This test isn't applicable if texture_npot is enabled
1587 return;
1588 }
1589
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001590 setUpProgram();
1591
Austin Kinross07285142015-03-26 11:36:16 -07001592 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1593
Austin Kinross5faa15b2016-01-11 13:32:48 -08001594 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1595 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1596
Austin Kinross07285142015-03-26 11:36:16 -07001597 glActiveTexture(GL_TEXTURE0);
1598 glGenTextures(1, &tex2D);
1599 glBindTexture(GL_TEXTURE_2D, tex2D);
1600
1601 std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize);
1602 for (size_t pixelId = 0; pixelId < npotTexSize * npotTexSize; ++pixelId)
1603 {
1604 pixels[pixelId] = 64;
1605 }
1606
1607 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1608 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1609
1610 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
1611 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1612 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1613
1614 // Check that an NPOT texture on level 0 succeeds
1615 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1616 EXPECT_GL_NO_ERROR();
1617
1618 // Check that generateMipmap fails on NPOT
1619 glGenerateMipmap(GL_TEXTURE_2D);
1620 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1621
1622 // Check that nothing is drawn if filtering is not correct for NPOT
1623 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1624 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1625 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1626 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1627 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001628 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001629 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1630
1631 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1632 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1633 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1634 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1635 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001636 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001637 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1638
1639 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1640 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1641 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001642 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001643 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1644
1645 // Check that glTexImage2D for POT texture succeeds
1646 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1647 EXPECT_GL_NO_ERROR();
1648
1649 // Check that generateMipmap for an POT texture succeeds
1650 glGenerateMipmap(GL_TEXTURE_2D);
1651 EXPECT_GL_NO_ERROR();
1652
1653 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1654 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1655 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1656 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1657 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1658 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001659 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001660 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1661 EXPECT_GL_NO_ERROR();
1662}
Jamie Madillfa05f602015-05-07 13:47:11 -04001663
Austin Kinross08528e12015-10-07 16:24:40 -07001664// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1665// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001666TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001667{
Geoff Lange0cc2a42016-01-20 10:58:17 -05001668 // TODO(geofflang): Allow the GL backend to accept SubImage calls with a null data ptr. (bug
1669 // 1278)
1670 if (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
1671 getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE)
1672 {
1673 std::cout << "Test disabled on OpenGL." << std::endl;
1674 return;
1675 }
1676
Austin Kinross08528e12015-10-07 16:24:40 -07001677 glActiveTexture(GL_TEXTURE0);
1678 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1679
1680 // Create an 8x8 (i.e. power-of-two) texture.
1681 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1682 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1683 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1684 glGenerateMipmap(GL_TEXTURE_2D);
1685
1686 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1687 // This should always work, even if GL_OES_texture_npot isn't active.
1688 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1689
1690 EXPECT_GL_NO_ERROR();
1691}
1692
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001693// Test to check that texture completeness is determined correctly when the texture base level is
1694// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1695TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1696{
1697 glActiveTexture(GL_TEXTURE0);
1698 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001699
1700 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1701 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1702 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1703 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1704 texDataGreen.data());
1705 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1706 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001707 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1708 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1709 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1710
1711 EXPECT_GL_NO_ERROR();
1712
1713 drawQuad(mProgram, "position", 0.5f);
1714
Olli Etuahoa314b612016-03-10 16:43:00 +02001715 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1716}
1717
1718// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1719// have images defined.
1720TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1721{
1722 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1723 {
1724 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1725 std::cout << "Test skipped on AMD OpenGL." << std::endl;
1726 return;
1727 }
1728 if (IsOSX())
1729 {
1730 // Observed incorrect rendering on OSX.
1731 std::cout << "Test skipped on OSX." << std::endl;
1732 return;
1733 }
1734 glActiveTexture(GL_TEXTURE0);
1735 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1736 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1737 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1738 texDataGreen.data());
1739 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1740 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1741 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1742 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1743
1744 EXPECT_GL_NO_ERROR();
1745
1746 drawQuad(mProgram, "position", 0.5f);
1747
1748 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1749}
1750
Olli Etuahoe8528d82016-05-16 17:50:52 +03001751// Test that drawing works correctly when level 0 is undefined and base level is 1.
1752TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1753{
1754 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1755 {
1756 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1757 std::cout << "Test skipped on AMD OpenGL." << std::endl;
1758 return;
1759 }
1760 if (IsOSX())
1761 {
1762 // Observed incorrect rendering on OSX.
1763 std::cout << "Test skipped on OSX." << std::endl;
1764 return;
1765 }
1766 glActiveTexture(GL_TEXTURE0);
1767 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1768 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1769 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1770 texDataGreen.data());
1771 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1772 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1773 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1774 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1775
1776 EXPECT_GL_NO_ERROR();
1777
1778 // Texture is incomplete.
1779 drawQuad(mProgram, "position", 0.5f);
1780 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1781
1782 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1783 texDataGreen.data());
1784
1785 // Texture is now complete.
1786 drawQuad(mProgram, "position", 0.5f);
1787 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1788}
1789
Olli Etuahoa314b612016-03-10 16:43:00 +02001790// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1791// dimensions that don't fit the images inside the range.
1792// GLES 3.0.4 section 3.8.13 Texture completeness
1793TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1794{
1795 if (IsOSX())
1796 {
1797 // Observed incorrect rendering on OSX.
1798 std::cout << "Test skipped on OSX." << std::endl;
1799 return;
1800 }
1801 glActiveTexture(GL_TEXTURE0);
1802 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1803 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1804 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1805 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1806
1807 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1808 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1809
1810 // Two levels that are initially unused.
1811 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1812 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1813 texDataCyan.data());
1814
1815 // One level that is used - only this level should affect completeness.
1816 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1817 texDataGreen.data());
1818
1819 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1820 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1821
1822 EXPECT_GL_NO_ERROR();
1823
1824 drawQuad(mProgram, "position", 0.5f);
1825
1826 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1827
1828 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1829 {
1830 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
1831 // level was changed.
1832 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
1833 return;
1834 }
1835
1836 // Switch the level that is being used to the cyan level 2.
1837 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1838 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1839
1840 EXPECT_GL_NO_ERROR();
1841
1842 drawQuad(mProgram, "position", 0.5f);
1843
1844 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1845}
1846
1847// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1848// have images defined.
1849TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1850{
1851 if (IsOSX())
1852 {
1853 // Observed incorrect rendering on OSX.
1854 std::cout << "Test skipped on OSX." << std::endl;
1855 return;
1856 }
1857 glActiveTexture(GL_TEXTURE0);
1858 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1859 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1860 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1861 texDataGreen.data());
1862 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1863 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1864 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1865 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1866
1867 EXPECT_GL_NO_ERROR();
1868
1869 drawQuad(mProgram, "position", 0.5f);
1870
1871 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1872}
1873
1874// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1875// dimensions that don't fit the images inside the range.
1876// GLES 3.0.4 section 3.8.13 Texture completeness
1877TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1878{
1879 if (IsOSX())
1880 {
1881 // Observed incorrect rendering on OSX.
1882 std::cout << "Test skipped on OSX." << std::endl;
1883 return;
1884 }
1885 glActiveTexture(GL_TEXTURE0);
1886 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1887 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1888 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1889 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1890
1891 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1892 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1893
1894 // Two levels that are initially unused.
1895 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1896 texDataRed.data());
1897 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1898 texDataCyan.data());
1899
1900 // One level that is used - only this level should affect completeness.
1901 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1902 texDataGreen.data());
1903
1904 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1905 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1906
1907 EXPECT_GL_NO_ERROR();
1908
1909 drawQuad(mProgram, "position", 0.5f);
1910
1911 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1912
1913 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1914 {
1915 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
1916 // level was changed.
1917 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
1918 return;
1919 }
1920
1921 // Switch the level that is being used to the cyan level 2.
1922 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
1923 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
1924
1925 EXPECT_GL_NO_ERROR();
1926
1927 drawQuad(mProgram, "position", 0.5f);
1928
1929 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1930}
1931
1932// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1933// have images defined.
1934TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
1935{
1936 if (IsOSX())
1937 {
1938 // Observed incorrect rendering on OSX.
1939 std::cout << "Test skipped on OSX." << std::endl;
1940 return;
1941 }
1942 glActiveTexture(GL_TEXTURE0);
1943 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
1944 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1945 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1946 texDataGreen.data());
1947 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1948 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1949 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1950 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1951
1952 EXPECT_GL_NO_ERROR();
1953
1954 drawQuad(mProgram, "position", 0.5f);
1955
1956 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1957}
1958
1959// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1960// dimensions that don't fit the images inside the range.
1961// GLES 3.0.4 section 3.8.13 Texture completeness
1962TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1963{
1964 if (IsOSX())
1965 {
1966 // Observed incorrect rendering on OSX.
1967 std::cout << "Test skipped on OSX." << std::endl;
1968 return;
1969 }
1970 glActiveTexture(GL_TEXTURE0);
1971 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
1972 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1973 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1974 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1975
1976 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1977 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1978
1979 // Two levels that are initially unused.
1980 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1981 texDataRed.data());
1982 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1983 texDataCyan.data());
1984
1985 // One level that is used - only this level should affect completeness.
1986 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1987 texDataGreen.data());
1988
1989 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1990 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1991
1992 EXPECT_GL_NO_ERROR();
1993
1994 drawQuad(mProgram, "position", 0.5f);
1995
1996 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1997
1998 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1999 {
2000 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
2001 // level was changed.
2002 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
2003 return;
2004 }
2005 if (IsNVIDIA() && (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
2006 getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE))
2007 {
2008 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
2009 // level was changed.
2010 std::cout << "Test partially skipped on NVIDIA OpenGL." << std::endl;
2011 return;
2012 }
2013
2014 // Switch the level that is being used to the cyan level 2.
2015 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2016 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2017
2018 EXPECT_GL_NO_ERROR();
2019
2020 drawQuad(mProgram, "position", 0.5f);
2021
2022 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2023}
2024
2025// Test that texture completeness is updated if texture max level changes.
2026// GLES 3.0.4 section 3.8.13 Texture completeness
2027TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2028{
2029 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2030 {
2031 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2032 // the base level.
2033 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2034 return;
2035 }
2036 if (IsOSX())
2037 {
2038 // Observed incorrect rendering on OSX.
2039 std::cout << "Test skipped on OSX." << std::endl;
2040 return;
2041 }
2042
2043 glActiveTexture(GL_TEXTURE0);
2044 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2045 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2046
2047 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2048 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2049
2050 // A level that is initially unused.
2051 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2052 texDataGreen.data());
2053
2054 // One level that is initially used - only this level should affect completeness.
2055 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2056 texDataGreen.data());
2057
2058 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2059 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2060
2061 EXPECT_GL_NO_ERROR();
2062
2063 drawQuad(mProgram, "position", 0.5f);
2064
2065 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2066
2067 // Switch the max level to level 1. The levels within the used range now have inconsistent
2068 // dimensions and the texture should be incomplete.
2069 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2070
2071 EXPECT_GL_NO_ERROR();
2072
2073 drawQuad(mProgram, "position", 0.5f);
2074
2075 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2076}
2077
2078// Test that 3D texture completeness is updated if texture max level changes.
2079// GLES 3.0.4 section 3.8.13 Texture completeness
2080TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2081{
2082 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2083 {
2084 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2085 // the base level.
2086 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2087 return;
2088 }
2089 if (IsOSX())
2090 {
2091 // Observed incorrect rendering on OSX.
2092 std::cout << "Test skipped on OSX." << std::endl;
2093 return;
2094 }
2095
2096 glActiveTexture(GL_TEXTURE0);
2097 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2098 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2099
2100 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2101 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2102
2103 // A level that is initially unused.
2104 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2105 texDataGreen.data());
2106
2107 // One level that is initially used - only this level should affect completeness.
2108 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2109 texDataGreen.data());
2110
2111 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2112 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2113
2114 EXPECT_GL_NO_ERROR();
2115
2116 drawQuad(mProgram, "position", 0.5f);
2117
2118 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2119
2120 // Switch the max level to level 1. The levels within the used range now have inconsistent
2121 // dimensions and the texture should be incomplete.
2122 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2123
2124 EXPECT_GL_NO_ERROR();
2125
2126 drawQuad(mProgram, "position", 0.5f);
2127
2128 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2129}
2130
2131// Test that texture completeness is updated if texture base level changes.
2132// GLES 3.0.4 section 3.8.13 Texture completeness
2133TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2134{
2135 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2136 {
2137 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2138 // the base level.
2139 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2140 return;
2141 }
2142
2143 glActiveTexture(GL_TEXTURE0);
2144 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2145 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2146
2147 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2148 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2149
2150 // Two levels that are initially unused.
2151 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2152 texDataGreen.data());
2153 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2154 texDataGreen.data());
2155
2156 // One level that is initially used - only this level should affect completeness.
2157 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2158 texDataGreen.data());
2159
2160 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2161 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2162
2163 EXPECT_GL_NO_ERROR();
2164
2165 drawQuad(mProgram, "position", 0.5f);
2166
2167 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2168
2169 // Switch the base level to level 1. The levels within the used range now have inconsistent
2170 // dimensions and the texture should be incomplete.
2171 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2172
2173 EXPECT_GL_NO_ERROR();
2174
2175 drawQuad(mProgram, "position", 0.5f);
2176
2177 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2178}
2179
2180// Test that texture is not complete if base level is greater than max level.
2181// GLES 3.0.4 section 3.8.13 Texture completeness
2182TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2183{
2184 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2185 {
2186 // Intel Windows OpenGL driver crashes if the base level of a non-immutable texture is out
2187 // of range.
2188 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2189 return;
2190 }
2191
2192 glActiveTexture(GL_TEXTURE0);
2193 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2194
2195 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2196 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2197
2198 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2199
2200 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2201 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2202
2203 EXPECT_GL_NO_ERROR();
2204
2205 drawQuad(mProgram, "position", 0.5f);
2206
2207 // Texture should be incomplete.
2208 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2209}
2210
2211// Test that immutable texture base level and max level are clamped.
2212// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2213TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2214{
Olli Etuahoa314b612016-03-10 16:43:00 +02002215 glActiveTexture(GL_TEXTURE0);
2216 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2217
2218 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2219 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2220
2221 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2222
2223 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2224
2225 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2226 // should be clamped to [base_level, levels - 1].
2227 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2228 // In the case of this test, those rules make the effective base level and max level 0.
2229 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2230 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2231
2232 EXPECT_GL_NO_ERROR();
2233
2234 drawQuad(mProgram, "position", 0.5f);
2235
2236 // Texture should be complete.
2237 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2238}
2239
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002240// Test that changing base level works when it affects the format of the texture.
2241TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2242{
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002243 if (IsNVIDIA() && IsOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002244 {
2245 // Observed rendering corruption on NVIDIA OpenGL.
2246 std::cout << "Test skipped on NVIDIA OpenGL." << std::endl;
2247 return;
2248 }
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002249 if (IsIntel() && IsDesktopOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002250 {
2251 // Observed incorrect rendering on Intel OpenGL.
2252 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2253 return;
2254 }
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002255 if (IsAMD() && IsDesktopOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002256 {
2257 // Observed incorrect rendering on AMD OpenGL.
2258 std::cout << "Test skipped on AMD OpenGL." << std::endl;
2259 return;
2260 }
2261
2262 glActiveTexture(GL_TEXTURE0);
2263 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2264 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2265 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2266
2267 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2268 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2269
2270 // RGBA8 level that's initially unused.
2271 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2272 texDataCyan.data());
2273
2274 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2275 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2276
2277 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2278 // format. It reads green channel data from the green and alpha channels of texDataGreen
2279 // (this is a bit hacky but works).
2280 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2281
2282 EXPECT_GL_NO_ERROR();
2283
2284 drawQuad(mProgram, "position", 0.5f);
2285
2286 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2287
2288 // Switch the texture to use the cyan level 0 with the RGBA format.
2289 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2290 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2291
2292 EXPECT_GL_NO_ERROR();
2293
2294 drawQuad(mProgram, "position", 0.5f);
2295
2296 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2297}
2298
Olli Etuahoa314b612016-03-10 16:43:00 +02002299// Test that setting a texture image works when base level is out of range.
2300TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2301{
2302 glActiveTexture(GL_TEXTURE0);
2303 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2304
2305 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2306 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2307
2308 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2309 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2310
2311 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2312
2313 EXPECT_GL_NO_ERROR();
2314
2315 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2316
2317 drawQuad(mProgram, "position", 0.5f);
2318
2319 // Texture should be complete.
2320 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002321}
2322
Jamie Madill2453dbc2015-07-14 11:35:42 -04002323// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG RBA->RGBA8, with 1.0
2324// in the alpha channel. This test covers a bug where redefining array textures with these formats does not work as
2325// expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002326TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002327{
2328 std::vector<GLubyte> pixelData;
2329 for (size_t count = 0; count < 5000; count++)
2330 {
2331 pixelData.push_back(0u);
2332 pixelData.push_back(255u);
2333 pixelData.push_back(0u);
2334 }
2335
2336 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002337 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002338 glUniform1i(mTextureArrayLocation, 0);
2339
2340 // The first draw worked correctly.
2341 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
2342
2343 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2344 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2345 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2346 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002347 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002348 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002349
2350 // The dimension of the respecification must match the original exactly to trigger the bug.
2351 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 +02002352 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002353 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002354
2355 ASSERT_GL_NO_ERROR();
2356}
2357
Olli Etuaho1a679902016-01-14 12:21:47 +02002358// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2359// This test is needed especially to confirm that sampler registers get assigned correctly on
2360// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2361TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2362{
2363 glActiveTexture(GL_TEXTURE0);
2364 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2365 GLubyte texData[4];
2366 texData[0] = 0;
2367 texData[1] = 60;
2368 texData[2] = 0;
2369 texData[3] = 255;
2370 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2371
2372 glActiveTexture(GL_TEXTURE1);
2373 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2374 GLfloat depthTexData[1];
2375 depthTexData[0] = 0.5f;
2376 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2377 depthTexData);
2378
2379 glUseProgram(mProgram);
2380 glUniform1f(mDepthRefUniformLocation, 0.3f);
2381 glUniform1i(mTexture3DUniformLocation, 0);
2382 glUniform1i(mTextureShadowUniformLocation, 1);
2383
2384 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2385 drawQuad(mProgram, "position", 0.5f);
2386 EXPECT_GL_NO_ERROR();
2387 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2388 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2389
2390 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2391 drawQuad(mProgram, "position", 0.5f);
2392 EXPECT_GL_NO_ERROR();
2393 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2394 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2395}
2396
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002397// Test multiple different sampler types in the same shader.
2398// This test makes sure that even if sampler / texture registers get grouped together based on type
2399// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2400// still has the right register index information for each ESSL sampler.
2401// The tested ESSL samplers have the following types in D3D11 HLSL:
2402// sampler2D: Texture2D + SamplerState
2403// samplerCube: TextureCube + SamplerState
2404// sampler2DShadow: Texture2D + SamplerComparisonState
2405// samplerCubeShadow: TextureCube + SamplerComparisonState
2406TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2407{
2408 glActiveTexture(GL_TEXTURE0);
2409 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2410 GLubyte texData[4];
2411 texData[0] = 0;
2412 texData[1] = 0;
2413 texData[2] = 120;
2414 texData[3] = 255;
2415 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2416
2417 glActiveTexture(GL_TEXTURE1);
2418 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2419 texData[0] = 0;
2420 texData[1] = 90;
2421 texData[2] = 0;
2422 texData[3] = 255;
2423 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2424 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2425 texData);
2426
2427 glActiveTexture(GL_TEXTURE2);
2428 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2429 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2430 GLfloat depthTexData[1];
2431 depthTexData[0] = 0.5f;
2432 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2433 depthTexData);
2434
2435 glActiveTexture(GL_TEXTURE3);
2436 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2437 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2438 depthTexData[0] = 0.2f;
2439 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2440 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2441 depthTexData);
2442
2443 EXPECT_GL_NO_ERROR();
2444
2445 glUseProgram(mProgram);
2446 glUniform1f(mDepthRefUniformLocation, 0.3f);
2447 glUniform1i(mTexture2DUniformLocation, 0);
2448 glUniform1i(mTextureCubeUniformLocation, 1);
2449 glUniform1i(mTexture2DShadowUniformLocation, 2);
2450 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2451
2452 drawQuad(mProgram, "position", 0.5f);
2453 EXPECT_GL_NO_ERROR();
2454 // The shader writes:
2455 // <texture 2d color> +
2456 // <cube map color> +
2457 // 0.25 * <comparison result (1.0)> +
2458 // 0.125 * <comparison result (0.0)>
2459 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2460}
2461
Olli Etuahobce743a2016-01-15 17:18:28 +02002462// Test different base levels on textures accessed through the same sampler array.
2463// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2464TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2465{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002466 if ((IsAMD() || IsIntel()) && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
Olli Etuahobce743a2016-01-15 17:18:28 +02002467 {
2468 std::cout << "Test skipped on Intel and AMD D3D." << std::endl;
2469 return;
2470 }
2471 glActiveTexture(GL_TEXTURE0);
2472 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2473 GLsizei size = 64;
2474 for (GLint level = 0; level < 7; ++level)
2475 {
2476 ASSERT_LT(0, size);
2477 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2478 nullptr);
2479 size = size / 2;
2480 }
2481 ASSERT_EQ(0, size);
2482 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2483
2484 glActiveTexture(GL_TEXTURE1);
2485 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2486 size = 128;
2487 for (GLint level = 0; level < 8; ++level)
2488 {
2489 ASSERT_LT(0, size);
2490 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2491 nullptr);
2492 size = size / 2;
2493 }
2494 ASSERT_EQ(0, size);
2495 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2496 EXPECT_GL_NO_ERROR();
2497
2498 glUseProgram(mProgram);
2499 glUniform1i(mTexture0Location, 0);
2500 glUniform1i(mTexture1Location, 1);
2501
2502 drawQuad(mProgram, "position", 0.5f);
2503 EXPECT_GL_NO_ERROR();
2504 // Red channel: width of level 1 of texture A: 32.
2505 // Green channel: width of level 3 of texture B: 16.
2506 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2507}
2508
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002509// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2510// ES 3.0.4 table 3.24
2511TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2512{
2513 glActiveTexture(GL_TEXTURE0);
2514 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2515 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2516 EXPECT_GL_NO_ERROR();
2517
2518 drawQuad(mProgram, "position", 0.5f);
2519
2520 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2521}
2522
2523// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2524// ES 3.0.4 table 3.24
2525TEST_P(Texture2DTestES3, TextureLuminanceImplicitAlpha1)
2526{
2527 glActiveTexture(GL_TEXTURE0);
2528 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2529 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2530 EXPECT_GL_NO_ERROR();
2531
2532 drawQuad(mProgram, "position", 0.5f);
2533
2534 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2535}
2536
2537// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2538// ES 3.0.4 table 3.24
2539TEST_P(Texture2DTestES3, TextureLuminance32ImplicitAlpha1)
2540{
2541 if (extensionEnabled("GL_OES_texture_float"))
2542 {
2543 glActiveTexture(GL_TEXTURE0);
2544 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2545 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2546 EXPECT_GL_NO_ERROR();
2547
2548 drawQuad(mProgram, "position", 0.5f);
2549
2550 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2551 }
2552}
2553
2554// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2555// ES 3.0.4 table 3.24
2556TEST_P(Texture2DTestES3, TextureLuminance16ImplicitAlpha1)
2557{
2558 if (extensionEnabled("GL_OES_texture_half_float"))
2559 {
Yuly Novikovafcec832016-06-21 22:19:51 -04002560 if (IsNVIDIA() && IsOpenGLES())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002561 {
2562 std::cout << "Test skipped on NVIDIA" << std::endl;
2563 return;
2564 }
Yuly Novikovafcec832016-06-21 22:19:51 -04002565 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2566 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2567 {
2568 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2569 return;
2570 }
2571
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002572 glActiveTexture(GL_TEXTURE0);
2573 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2574 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES,
2575 nullptr);
2576 EXPECT_GL_NO_ERROR();
2577
2578 drawQuad(mProgram, "position", 0.5f);
2579
2580 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2581 }
2582}
2583
2584// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2585// ES 3.0.4 table 3.24
2586TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2587{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002588 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002589 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002590 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002591 return;
2592 }
2593 glActiveTexture(GL_TEXTURE0);
2594 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2595 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2596 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2597 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2598 EXPECT_GL_NO_ERROR();
2599
2600 drawQuad(mProgram, "position", 0.5f);
2601
2602 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2603}
2604
2605// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2606// ES 3.0.4 table 3.24
2607TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2608{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002609 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002610 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002611 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002612 return;
2613 }
2614 glActiveTexture(GL_TEXTURE0);
2615 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2616
2617 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2618 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2619 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2620 EXPECT_GL_NO_ERROR();
2621
2622 drawQuad(mProgram, "position", 0.5f);
2623
2624 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2625}
2626
2627// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2628// ES 3.0.4 table 3.24
2629TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2630{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002631 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002632 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002633 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002634 return;
2635 }
2636 glActiveTexture(GL_TEXTURE0);
2637 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2638 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2639 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2640 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2641 EXPECT_GL_NO_ERROR();
2642
2643 drawQuad(mProgram, "position", 0.5f);
2644
2645 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2646}
2647
2648// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2649// ES 3.0.4 table 3.24
2650TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2651{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002652 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002653 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002654 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002655 return;
2656 }
2657 glActiveTexture(GL_TEXTURE0);
2658 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2659 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2660 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2661 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2662 EXPECT_GL_NO_ERROR();
2663
2664 drawQuad(mProgram, "position", 0.5f);
2665
2666 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2667}
2668
2669// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2670// ES 3.0.4 table 3.24
2671TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2672{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002673 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002674 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002675 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002676 return;
2677 }
2678 glActiveTexture(GL_TEXTURE0);
2679 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2680 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2681 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2682 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2683 EXPECT_GL_NO_ERROR();
2684
2685 drawQuad(mProgram, "position", 0.5f);
2686
2687 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2688}
2689
2690// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2691// ES 3.0.4 table 3.24
2692TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2693{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002694 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002695 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002696 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002697 return;
2698 }
2699 glActiveTexture(GL_TEXTURE0);
2700 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2701 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2702 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2703 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2704 EXPECT_GL_NO_ERROR();
2705
2706 drawQuad(mProgram, "position", 0.5f);
2707
2708 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2709}
2710
2711// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2712// ES 3.0.4 table 3.24
2713TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2714{
2715 glActiveTexture(GL_TEXTURE0);
2716 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2717 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2718 EXPECT_GL_NO_ERROR();
2719
2720 drawQuad(mProgram, "position", 0.5f);
2721
2722 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2723}
2724
2725// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2726// ES 3.0.4 table 3.24
2727TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2728{
2729 glActiveTexture(GL_TEXTURE0);
2730 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2731 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2732 nullptr);
2733 EXPECT_GL_NO_ERROR();
2734
2735 drawQuad(mProgram, "position", 0.5f);
2736
2737 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2738}
2739
2740// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2741// ES 3.0.4 table 3.24
2742TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2743{
2744 glActiveTexture(GL_TEXTURE0);
2745 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2746 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2747 EXPECT_GL_NO_ERROR();
2748
2749 drawQuad(mProgram, "position", 0.5f);
2750
2751 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2752}
2753
2754// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2755// ES 3.0.4 table 3.24
2756TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2757{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002758 if (IsIntel() && IsLinux())
2759 {
2760 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
2761 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
2762 return;
2763 }
2764
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002765 glActiveTexture(GL_TEXTURE0);
2766 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2767 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2768 EXPECT_GL_NO_ERROR();
2769
2770 drawQuad(mProgram, "position", 0.5f);
2771
2772 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2773}
2774
Olli Etuaho96963162016-03-21 11:54:33 +02002775// Use a sampler in a uniform struct.
2776TEST_P(SamplerInStructTest, SamplerInStruct)
2777{
2778 runSamplerInStructTest();
2779}
2780
2781// Use a sampler in a uniform struct that's passed as a function parameter.
2782TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2783{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002784 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2785 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2786 {
2787 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2788 return;
2789 }
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002790
2791 if (IsWindows() && IsIntel() && IsOpenGL())
2792 {
2793 std::cout << "Test skipped on Windows OpenGL on Intel." << std::endl;
2794 return;
2795 }
2796
Olli Etuaho96963162016-03-21 11:54:33 +02002797 runSamplerInStructTest();
2798}
2799
2800// Use a sampler in a uniform struct array with a struct from the array passed as a function
2801// parameter.
2802TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2803{
Olli Etuahoa1c917f2016-04-06 13:50:03 +03002804 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2805 {
2806 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2807 return;
2808 }
Yuly Novikovad6c0452016-06-24 22:24:37 -04002809 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2810 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2811 {
2812 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2813 return;
2814 }
Olli Etuaho96963162016-03-21 11:54:33 +02002815 runSamplerInStructTest();
2816}
2817
2818// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2819// parameter.
2820TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2821{
Olli Etuahoa1c917f2016-04-06 13:50:03 +03002822 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2823 {
2824 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2825 return;
2826 }
Yuly Novikovad6c0452016-06-24 22:24:37 -04002827 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2828 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2829 {
2830 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2831 return;
2832 }
Olli Etuaho96963162016-03-21 11:54:33 +02002833 runSamplerInStructTest();
2834}
2835
2836// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2837// similarly named uniform.
2838TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2839{
2840 runSamplerInStructTest();
2841}
2842
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002843class TextureLimitsTest : public ANGLETest
2844{
2845 protected:
2846 struct RGBA8
2847 {
2848 uint8_t R, G, B, A;
2849 };
2850
2851 TextureLimitsTest()
2852 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
2853 {
2854 setWindowWidth(128);
2855 setWindowHeight(128);
2856 setConfigRedBits(8);
2857 setConfigGreenBits(8);
2858 setConfigBlueBits(8);
2859 setConfigAlphaBits(8);
2860 }
2861
2862 ~TextureLimitsTest()
2863 {
2864 if (mProgram != 0)
2865 {
2866 glDeleteProgram(mProgram);
2867 mProgram = 0;
2868
2869 if (!mTextures.empty())
2870 {
2871 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
2872 }
2873 }
2874 }
2875
2876 void SetUp() override
2877 {
2878 ANGLETest::SetUp();
2879
2880 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
2881 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
2882 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
2883
2884 ASSERT_GL_NO_ERROR();
2885 }
2886
2887 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
2888 GLint vertexTextureCount,
2889 GLint vertexActiveTextureCount,
2890 const std::string &fragPrefix,
2891 GLint fragmentTextureCount,
2892 GLint fragmentActiveTextureCount)
2893 {
2894 std::stringstream vertexShaderStr;
2895 vertexShaderStr << "attribute vec2 position;\n"
2896 << "varying vec4 color;\n"
2897 << "varying vec2 texCoord;\n";
2898
2899 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
2900 {
2901 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
2902 }
2903
2904 vertexShaderStr << "void main() {\n"
2905 << " gl_Position = vec4(position, 0, 1);\n"
2906 << " texCoord = (position * 0.5) + 0.5;\n"
2907 << " color = vec4(0);\n";
2908
2909 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
2910 {
2911 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
2912 << ", texCoord);\n";
2913 }
2914
2915 vertexShaderStr << "}";
2916
2917 std::stringstream fragmentShaderStr;
2918 fragmentShaderStr << "varying mediump vec4 color;\n"
2919 << "varying mediump vec2 texCoord;\n";
2920
2921 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
2922 {
2923 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
2924 }
2925
2926 fragmentShaderStr << "void main() {\n"
2927 << " gl_FragColor = color;\n";
2928
2929 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
2930 {
2931 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
2932 << ", texCoord);\n";
2933 }
2934
2935 fragmentShaderStr << "}";
2936
2937 const std::string &vertexShaderSource = vertexShaderStr.str();
2938 const std::string &fragmentShaderSource = fragmentShaderStr.str();
2939
2940 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
2941 }
2942
2943 RGBA8 getPixel(GLint texIndex)
2944 {
2945 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
2946 0, 255u};
2947 return pixel;
2948 }
2949
2950 void initTextures(GLint tex2DCount, GLint texCubeCount)
2951 {
2952 GLint totalCount = tex2DCount + texCubeCount;
2953 mTextures.assign(totalCount, 0);
2954 glGenTextures(totalCount, &mTextures[0]);
2955 ASSERT_GL_NO_ERROR();
2956
2957 std::vector<RGBA8> texData(16 * 16);
2958
2959 GLint texIndex = 0;
2960 for (; texIndex < tex2DCount; ++texIndex)
2961 {
2962 texData.assign(texData.size(), getPixel(texIndex));
2963 glActiveTexture(GL_TEXTURE0 + texIndex);
2964 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
2965 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2966 &texData[0]);
2967 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2968 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2969 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2970 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2971 }
2972
2973 ASSERT_GL_NO_ERROR();
2974
2975 for (; texIndex < texCubeCount; ++texIndex)
2976 {
2977 texData.assign(texData.size(), getPixel(texIndex));
2978 glActiveTexture(GL_TEXTURE0 + texIndex);
2979 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
2980 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2981 GL_UNSIGNED_BYTE, &texData[0]);
2982 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2983 GL_UNSIGNED_BYTE, &texData[0]);
2984 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2985 GL_UNSIGNED_BYTE, &texData[0]);
2986 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2987 GL_UNSIGNED_BYTE, &texData[0]);
2988 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2989 GL_UNSIGNED_BYTE, &texData[0]);
2990 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2991 GL_UNSIGNED_BYTE, &texData[0]);
2992 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2993 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2994 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2995 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2996 }
2997
2998 ASSERT_GL_NO_ERROR();
2999 }
3000
3001 void testWithTextures(GLint vertexTextureCount,
3002 const std::string &vertexTexturePrefix,
3003 GLint fragmentTextureCount,
3004 const std::string &fragmentTexturePrefix)
3005 {
3006 // Generate textures
3007 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3008
3009 glUseProgram(mProgram);
3010 RGBA8 expectedSum = {0};
3011 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3012 {
3013 std::stringstream uniformNameStr;
3014 uniformNameStr << vertexTexturePrefix << texIndex;
3015 const std::string &uniformName = uniformNameStr.str();
3016 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
3017 ASSERT_NE(-1, location);
3018
3019 glUniform1i(location, texIndex);
3020 RGBA8 contribution = getPixel(texIndex);
3021 expectedSum.R += contribution.R;
3022 expectedSum.G += contribution.G;
3023 }
3024
3025 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3026 {
3027 std::stringstream uniformNameStr;
3028 uniformNameStr << fragmentTexturePrefix << texIndex;
3029 const std::string &uniformName = uniformNameStr.str();
3030 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
3031 ASSERT_NE(-1, location);
3032
3033 glUniform1i(location, texIndex + vertexTextureCount);
3034 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3035 expectedSum.R += contribution.R;
3036 expectedSum.G += contribution.G;
3037 }
3038
3039 ASSERT_GE(256u, expectedSum.G);
3040
3041 drawQuad(mProgram, "position", 0.5f);
3042 ASSERT_GL_NO_ERROR();
3043 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3044 }
3045
3046 GLuint mProgram;
3047 std::vector<GLuint> mTextures;
3048 GLint mMaxVertexTextures;
3049 GLint mMaxFragmentTextures;
3050 GLint mMaxCombinedTextures;
3051};
3052
3053// Test rendering with the maximum vertex texture units.
3054TEST_P(TextureLimitsTest, MaxVertexTextures)
3055{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003056 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003057 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003058 {
3059 std::cout << "Test skipped on Intel." << std::endl;
3060 return;
3061 }
3062
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003063 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3064 ASSERT_NE(0u, mProgram);
3065 ASSERT_GL_NO_ERROR();
3066
3067 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3068}
3069
3070// Test rendering with the maximum fragment texture units.
3071TEST_P(TextureLimitsTest, MaxFragmentTextures)
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", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3081 ASSERT_NE(0u, mProgram);
3082 ASSERT_GL_NO_ERROR();
3083
3084 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3085}
3086
3087// Test rendering with maximum combined texture units.
3088TEST_P(TextureLimitsTest, MaxCombinedTextures)
3089{
Jamie Madill412f17d2015-09-25 08:43:54 -04003090 // TODO(jmadill): Investigate workaround.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003091 if (IsIntel() && GetParam() == ES2_OPENGL())
Jamie Madill412f17d2015-09-25 08:43:54 -04003092 {
3093 std::cout << "Test skipped on Intel." << std::endl;
3094 return;
3095 }
3096
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003097 GLint vertexTextures = mMaxVertexTextures;
3098
3099 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3100 {
3101 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3102 }
3103
3104 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3105 mMaxFragmentTextures, mMaxFragmentTextures);
3106 ASSERT_NE(0u, mProgram);
3107 ASSERT_GL_NO_ERROR();
3108
3109 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3110}
3111
3112// Negative test for exceeding the number of vertex textures
3113TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3114{
3115 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3116 0);
3117 ASSERT_EQ(0u, mProgram);
3118}
3119
3120// Negative test for exceeding the number of fragment textures
3121TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3122{
3123 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3124 mMaxFragmentTextures + 1);
3125 ASSERT_EQ(0u, mProgram);
3126}
3127
3128// Test active vertex textures under the limit, but excessive textures specified.
3129TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3130{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003131 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003132 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003133 {
3134 std::cout << "Test skipped on Intel." << std::endl;
3135 return;
3136 }
3137
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003138 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3139 ASSERT_NE(0u, mProgram);
3140 ASSERT_GL_NO_ERROR();
3141
3142 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3143}
3144
3145// Test active fragment textures under the limit, but excessive textures specified.
3146TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3147{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003148 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003149 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003150 {
3151 std::cout << "Test skipped on Intel." << std::endl;
3152 return;
3153 }
3154
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003155 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3156 mMaxFragmentTextures);
3157 ASSERT_NE(0u, mProgram);
3158 ASSERT_GL_NO_ERROR();
3159
3160 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3161}
3162
3163// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003164// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003165TEST_P(TextureLimitsTest, TextureTypeConflict)
3166{
3167 const std::string &vertexShader =
3168 "attribute vec2 position;\n"
3169 "varying float color;\n"
3170 "uniform sampler2D tex2D;\n"
3171 "uniform samplerCube texCube;\n"
3172 "void main() {\n"
3173 " gl_Position = vec4(position, 0, 1);\n"
3174 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3175 " color = texture2D(tex2D, texCoord).x;\n"
3176 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3177 "}";
3178 const std::string &fragmentShader =
3179 "varying mediump float color;\n"
3180 "void main() {\n"
3181 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3182 "}";
3183
3184 mProgram = CompileProgram(vertexShader, fragmentShader);
3185 ASSERT_NE(0u, mProgram);
3186
3187 initTextures(1, 0);
3188
3189 glUseProgram(mProgram);
3190 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3191 ASSERT_NE(-1, tex2DLocation);
3192 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3193 ASSERT_NE(-1, texCubeLocation);
3194
3195 glUniform1i(tex2DLocation, 0);
3196 glUniform1i(texCubeLocation, 0);
3197 ASSERT_GL_NO_ERROR();
3198
3199 drawQuad(mProgram, "position", 0.5f);
3200 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3201}
3202
3203// Negative test for rendering with texture outside the valid range.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003204// TODO(jmadill): Possibly adjust the test according to the spec:
3205// GLES 3.0.4 section 2.12.7 mentions that specifying an out-of-range sampler uniform value
3206// generates an INVALID_VALUE error - GLES 2.0 doesn't yet have this mention.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003207TEST_P(TextureLimitsTest, DrawWithTexturePastMaximum)
3208{
3209 const std::string &vertexShader =
3210 "attribute vec2 position;\n"
3211 "varying float color;\n"
3212 "uniform sampler2D tex2D;\n"
3213 "void main() {\n"
3214 " gl_Position = vec4(position, 0, 1);\n"
3215 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3216 " color = texture2D(tex2D, texCoord).x;\n"
3217 "}";
3218 const std::string &fragmentShader =
3219 "varying mediump float color;\n"
3220 "void main() {\n"
3221 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3222 "}";
3223
3224 mProgram = CompileProgram(vertexShader, fragmentShader);
3225 ASSERT_NE(0u, mProgram);
3226
3227 glUseProgram(mProgram);
3228 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3229 ASSERT_NE(-1, tex2DLocation);
3230
3231 glUniform1i(tex2DLocation, mMaxCombinedTextures);
3232 ASSERT_GL_NO_ERROR();
3233
3234 drawQuad(mProgram, "position", 0.5f);
3235 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3236}
3237
Vincent Lang25ab4512016-05-13 18:13:59 +02003238class Texture2DNorm16TestES3 : public Texture2DTestES3
3239{
3240 protected:
3241 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3242
3243 void SetUp() override
3244 {
3245 Texture2DTestES3::SetUp();
3246
3247 glActiveTexture(GL_TEXTURE0);
3248 glGenTextures(3, mTextures);
3249 glGenFramebuffers(1, &mFBO);
3250 glGenRenderbuffers(1, &mRenderbuffer);
3251
3252 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3253 {
3254 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3255 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3256 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3257 }
3258
3259 glBindTexture(GL_TEXTURE_2D, 0);
3260
3261 ASSERT_GL_NO_ERROR();
3262 }
3263
3264 void TearDown() override
3265 {
3266 glDeleteTextures(3, mTextures);
3267 glDeleteFramebuffers(1, &mFBO);
3268 glDeleteRenderbuffers(1, &mRenderbuffer);
3269
3270 Texture2DTestES3::TearDown();
3271 }
3272
3273 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3274 {
Geoff Langf607c602016-09-21 11:46:48 -04003275 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3276 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003277
3278 setUpProgram();
3279
3280 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3281 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3282 0);
3283
3284 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3285 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3286
3287 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003288 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003289
3290 EXPECT_GL_NO_ERROR();
3291
3292 drawQuad(mProgram, "position", 0.5f);
3293
Geoff Langf607c602016-09-21 11:46:48 -04003294 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003295
Geoff Langf607c602016-09-21 11:46:48 -04003296 EXPECT_PIXEL_COLOR_EQ(
3297 0, 0, SliceFormatColor(
3298 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003299
3300 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3301
3302 ASSERT_GL_NO_ERROR();
3303 }
3304
3305 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3306 {
3307 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003308 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003309
3310 setUpProgram();
3311
3312 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3313 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3314
3315 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3316 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3317 0);
3318
3319 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003320 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003321
3322 EXPECT_GL_NO_ERROR();
3323
3324 drawQuad(mProgram, "position", 0.5f);
3325
Geoff Langf607c602016-09-21 11:46:48 -04003326 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
3327 EXPECT_PIXEL_COLOR_EQ(
3328 0, 0, SliceFormatColor(
3329 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003330
3331 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3332 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3333 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3334 mRenderbuffer);
3335 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3336 EXPECT_GL_NO_ERROR();
3337
3338 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3339 glClear(GL_COLOR_BUFFER_BIT);
3340
3341 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3342
Geoff Langf607c602016-09-21 11:46:48 -04003343 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003344
3345 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3346
3347 ASSERT_GL_NO_ERROR();
3348 }
3349
3350 GLuint mTextures[3];
3351 GLuint mFBO;
3352 GLuint mRenderbuffer;
3353};
3354
3355// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3356TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3357{
3358 if (!extensionEnabled("GL_EXT_texture_norm16"))
3359 {
3360 std::cout << "Test skipped due to missing GL_EXT_texture_norm16." << std::endl;
3361 return;
3362 }
3363
3364 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3365 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3366 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3367 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3368 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3369 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3370 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3371 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3372
3373 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3374 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3375 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3376}
3377
Olli Etuaho95faa232016-06-07 14:01:53 -07003378// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3379// GLES 3.0.4 section 3.8.3.
3380TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3381{
Corentin Wallezc7f59d02016-06-20 10:12:08 -04003382 if (IsIntel() && IsDesktopOpenGL())
Olli Etuaho95faa232016-06-07 14:01:53 -07003383 {
3384 std::cout << "Test skipped on Intel OpenGL." << std::endl;
3385 return;
3386 }
Yuly Novikov3c754192016-06-27 19:36:41 -04003387 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1429 is fixed
3388 if (IsAndroid() && IsAdreno() && IsOpenGLES())
3389 {
3390 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
3391 return;
3392 }
Olli Etuaho95faa232016-06-07 14:01:53 -07003393
3394 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3395 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3396 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3397 ASSERT_GL_NO_ERROR();
3398
3399 // SKIP_IMAGES should not have an effect on uploading 2D textures
3400 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3401 ASSERT_GL_NO_ERROR();
3402
3403 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3404
3405 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3406 pixelsGreen.data());
3407 ASSERT_GL_NO_ERROR();
3408
3409 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3410 pixelsGreen.data());
3411 ASSERT_GL_NO_ERROR();
3412
3413 glUseProgram(mProgram);
3414 drawQuad(mProgram, "position", 0.5f);
3415 ASSERT_GL_NO_ERROR();
3416
3417 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3418}
3419
Olli Etuaho989cac32016-06-08 16:18:49 -07003420// Test that skip defined in unpack parameters is taken into account when determining whether
3421// unpacking source extends outside unpack buffer bounds.
3422TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3423{
3424 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3425 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3426 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3427 ASSERT_GL_NO_ERROR();
3428
3429 GLBuffer buf;
3430 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3431 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3432 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3433 GL_DYNAMIC_COPY);
3434 ASSERT_GL_NO_ERROR();
3435
3436 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3437 ASSERT_GL_NO_ERROR();
3438
3439 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3440 ASSERT_GL_NO_ERROR();
3441
3442 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3443 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3444
3445 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3446 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3447 ASSERT_GL_NO_ERROR();
3448
3449 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3450 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3451}
3452
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003453// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3454TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3455{
3456 if (IsD3D11())
3457 {
3458 std::cout << "Test skipped on D3D." << std::endl;
3459 return;
3460 }
3461 if (IsOSX() && IsAMD())
3462 {
3463 // Incorrect rendering results seen on OSX AMD.
3464 std::cout << "Test skipped on OSX AMD." << std::endl;
3465 return;
3466 }
3467
3468 const GLuint width = 8u;
3469 const GLuint height = 8u;
3470 const GLuint unpackRowLength = 5u;
3471 const GLuint unpackSkipPixels = 1u;
3472
3473 setWindowWidth(width);
3474 setWindowHeight(height);
3475
3476 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3477 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3478 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3479 ASSERT_GL_NO_ERROR();
3480
3481 GLBuffer buf;
3482 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3483 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3484 GLColor::green);
3485
3486 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3487 {
3488 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3489 }
3490
3491 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3492 GL_DYNAMIC_COPY);
3493 ASSERT_GL_NO_ERROR();
3494
3495 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3496 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3497 ASSERT_GL_NO_ERROR();
3498
3499 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3500 ASSERT_GL_NO_ERROR();
3501
3502 glUseProgram(mProgram);
3503 drawQuad(mProgram, "position", 0.5f);
3504 ASSERT_GL_NO_ERROR();
3505
3506 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3507 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3508 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3509 actual.data());
3510 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3511 EXPECT_EQ(expected, actual);
3512}
3513
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003514template <typename T>
3515T UNorm(double value)
3516{
3517 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3518}
3519
3520// Test rendering a depth texture with mipmaps.
3521TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3522{
Corentin Walleze731d8a2016-09-07 10:56:25 -04003523 //TODO(cwallez) this is failing on Intel Win7 OpenGL
3524 if (IsIntel() && IsWindows() && IsOpenGL())
3525 {
3526 std::cout << "Test skipped on Intel OpenGL." << std::endl;
3527 return;
3528 }
3529
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003530 const int size = getWindowWidth();
3531
3532 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003533 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003534
3535 glActiveTexture(GL_TEXTURE0);
3536 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3537 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3538 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3539 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3540 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3541 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3542 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3543 ASSERT_GL_NO_ERROR();
3544
3545 glUseProgram(mProgram);
3546 glUniform1i(mTexture2DUniformLocation, 0);
3547
3548 std::vector<unsigned char> expected;
3549
3550 for (int level = 0; level < levels; ++level)
3551 {
3552 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3553 expected.push_back(UNorm<unsigned char>(value));
3554
3555 int levelDim = dim(level);
3556
3557 ASSERT_GT(levelDim, 0);
3558
3559 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3560 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3561 GL_UNSIGNED_INT, initData.data());
3562 }
3563 ASSERT_GL_NO_ERROR();
3564
3565 for (int level = 0; level < levels; ++level)
3566 {
3567 glViewport(0, 0, dim(level), dim(level));
3568 drawQuad(mProgram, "position", 0.5f);
3569 GLColor actual = ReadColor(0, 0);
3570 EXPECT_NEAR(expected[level], actual.R, 10u);
3571 }
3572
3573 ASSERT_GL_NO_ERROR();
3574}
3575
Jamie Madill7ffdda92016-09-08 13:26:51 -04003576// Tests unpacking into the unsized GL_ALPHA format.
3577TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3578{
3579 // TODO(jmadill): Figure out why this fails on OSX.
3580 ANGLE_SKIP_TEST_IF(IsOSX());
3581
3582 // Initialize the texure.
3583 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3584 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3585 GL_UNSIGNED_BYTE, nullptr);
3586 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3587 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3588
3589 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3590
3591 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04003592 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04003593 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3594 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3595 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
3596 GL_STATIC_DRAW);
3597
3598 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
3599 GL_UNSIGNED_BYTE, nullptr);
3600
3601 // Clear to a weird color to make sure we're drawing something.
3602 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
3603 glClear(GL_COLOR_BUFFER_BIT);
3604
3605 // Draw with the alpha texture and verify.
3606 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04003607
3608 ASSERT_GL_NO_ERROR();
3609 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
3610}
3611
Jamie Madill2e600342016-09-19 13:56:40 -04003612// Ensure stale unpack data doesn't propagate in D3D11.
3613TEST_P(Texture2DTestES3, StaleUnpackData)
3614{
3615 // Init unpack buffer.
3616 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
3617 std::vector<GLColor> pixels(pixelCount, GLColor::red);
3618
3619 GLBuffer unpackBuffer;
3620 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3621 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3622 GLsizei bufferSize = pixelCount * sizeof(GLColor);
3623 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
3624
3625 // Create from unpack buffer.
3626 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3627 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
3628 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3629 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3630 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3631
3632 drawQuad(mProgram, "position", 0.5f);
3633
3634 ASSERT_GL_NO_ERROR();
3635 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3636
3637 // Fill unpack with green, recreating buffer.
3638 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
3639 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
3640 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
3641
3642 // Reinit texture with green.
3643 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
3644 GL_UNSIGNED_BYTE, nullptr);
3645
3646 drawQuad(mProgram, "position", 0.5f);
3647
3648 ASSERT_GL_NO_ERROR();
3649 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3650}
3651
Jamie Madillf097e232016-11-05 00:44:15 -04003652// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
3653// being properly checked, and the texture storage of the previous texture format was persisting.
3654// This would result in an ASSERT in debug and incorrect rendering in release.
3655// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
3656TEST_P(Texture3DTestES3, FormatRedefinitionBug)
3657{
3658 GLTexture tex;
3659 glBindTexture(GL_TEXTURE_3D, tex.get());
3660 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3661
3662 GLFramebuffer framebuffer;
3663 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3664 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
3665
3666 glCheckFramebufferStatus(GL_FRAMEBUFFER);
3667
3668 std::vector<uint8_t> pixelData(100, 0);
3669
3670 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
3671 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
3672 pixelData.data());
3673
3674 ASSERT_GL_NO_ERROR();
3675}
3676
Jamie Madillfa05f602015-05-07 13:47:11 -04003677// 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 +02003678// TODO(oetuaho): Enable all below tests on OpenGL. Requires a fix for ANGLE bug 1278.
Geoff Lange0cc2a42016-01-20 10:58:17 -05003679ANGLE_INSTANTIATE_TEST(Texture2DTest,
3680 ES2_D3D9(),
3681 ES2_D3D11(),
3682 ES2_D3D11_FL9_3(),
3683 ES2_OPENGL(),
3684 ES2_OPENGLES());
3685ANGLE_INSTANTIATE_TEST(TextureCubeTest,
3686 ES2_D3D9(),
3687 ES2_D3D11(),
3688 ES2_D3D11_FL9_3(),
3689 ES2_OPENGL(),
3690 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003691ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
3692 ES2_D3D9(),
3693 ES2_D3D11(),
3694 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003695 ES2_OPENGL(),
3696 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003697ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
3698 ES2_D3D9(),
3699 ES2_D3D11(),
3700 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003701 ES2_OPENGL(),
3702 ES2_OPENGLES());
3703ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
3704 ES2_D3D9(),
3705 ES2_D3D11(),
3706 ES2_D3D11_FL9_3(),
3707 ES2_OPENGL(),
3708 ES2_OPENGLES());
3709ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
3710 ES2_D3D9(),
3711 ES2_D3D11(),
3712 ES2_D3D11_FL9_3(),
3713 ES2_OPENGL(),
3714 ES2_OPENGLES());
3715ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02003716ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003717ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3718ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
3719 ES3_D3D11(),
3720 ES3_OPENGL(),
3721 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003722ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
3723 ES3_D3D11(),
3724 ES3_OPENGL(),
3725 ES3_OPENGLES());
3726ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3727ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02003728ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02003729ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
3730 ES2_D3D11(),
3731 ES2_D3D11_FL9_3(),
3732 ES2_D3D9(),
3733 ES2_OPENGL(),
3734 ES2_OPENGLES());
3735ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
3736 ES2_D3D11(),
3737 ES2_D3D11_FL9_3(),
3738 ES2_D3D9(),
3739 ES2_OPENGL(),
3740 ES2_OPENGLES());
3741ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
3742 ES2_D3D11(),
3743 ES2_D3D11_FL9_3(),
3744 ES2_D3D9(),
3745 ES2_OPENGL(),
3746 ES2_OPENGLES());
3747ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
3748 ES2_D3D11(),
3749 ES2_D3D11_FL9_3(),
3750 ES2_D3D9(),
3751 ES2_OPENGL(),
3752 ES2_OPENGLES());
3753ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
3754 ES2_D3D11(),
3755 ES2_D3D11_FL9_3(),
3756 ES2_D3D9(),
3757 ES2_OPENGL(),
3758 ES2_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003759ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES());
Vincent Lang25ab4512016-05-13 18:13:59 +02003760ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04003761
Jamie Madill7ffdda92016-09-08 13:26:51 -04003762} // anonymous namespace